COBOLD
Paradigm(s) | imperative |
---|---|
Designed by | User:Glax |
Appeared in | 2024 |
Memory system | Cell-based |
Dimensions | one-dimensional |
Computational class | Turing complete |
Reference implementation | yipyap.py |
File extension(s) | .yip , .yap |
COBOLD (also known as YipYap) is a programming language for Kobolds (who are known to make Yip and Yap noises).
Syntax
A COBOLD program must start with yip yap
followed by whitespace-separated commands.
Comments are prefixed with owo
and they continue until the following newline.
Execution and Memory model
COBOLD memory model consists of three values:
Name | Initial Value | Description |
---|---|---|
Hold Register | 1
|
An 8-bit unsigned integer value, used by most command as operand |
Memory Tape | [0]
|
A one dimensional array of 8 bit unsigned integers, that can grow as needed (new cells will be initialized with 0) |
Memory Pointer | 0
|
A pointer to a cell in the Memory Tape, it can be increased or decreased |
Decreasing the memory pointer below 0 will result in an error.
There is an opaque call stack used to call / return from functions that cannot be modified directly.
Commands
For simplicity the pseudocode column will contain a C-like code referencing the Hold Register as hold
, Memory Tape as memory
, Memory Pointer as ptr
.
Command | Pseudocode | Description |
---|---|---|
yip
|
ptr++
|
Increase tape pointer, adding new empty cells as needed |
yap
|
ptr--
|
Decrease tape pointer |
yip?
|
if (!hold) goto next yap!
|
Jump after the next yip! if hold is zero
|
yap?
|
hold = min(*ptr, hold)
|
Set hold to the current tape cell if it's less than hold |
yip!
|
hold -= *ptr
|
Subtract the current tape cell from hold |
yap!
|
goto prev yip?
|
Jump to the previous yip?
|
Yip
|
print(chr(hold))
|
Output hold as character |
Yap
|
hold += *stack
|
Add stack value to hold |
Yip!
|
print(hold)
|
Output hold as a number |
Yap!
|
return
|
Returns from a function to its invocation. If there is no function being called, terminates the program. |
Yip?
|
void func() {}
|
Defines a function (or label) whose name is the next token |
Yap?
|
func()
|
Invoke the function represented by the next token, pushing the position of the next command into the call stack |
yipyip
|
hold = *ptr
|
Assign the current tape cell to hold |
yipyap
|
swap(hold, *ptr)
|
Swap hold and current tape cell value. This is the only command that can modify the contents of the memory tape. |
yapyip
|
hold++
|
Increase hold value by 1 |
yapyap
|
hold--
|
Decrease hold value by 1 |
Functions
Functions are defined by Yip?
followed by any valid token.
You can call a function by using Yap?
followed by the corresponding function token. Doing so will push the current program location into the call stack.
Yap!
will pop the call stack and resume execution from the invocation point.
Examples
Hello World
yapyip owo increases hold by 1, setting it to 2 (it's initialized with 1)
yipyap owo swaps hold and tape cell
Yap Yap owo adds the tape cell onto hold twice, obtaining 4
yipyap owo swaps again, now the cell has 4 and hold has 2
Yap Yap Yap owo adds the cell onto hold 3 times, gettting 14
yipyap owo swaps, now cell has 14 and hold has 4
Yap Yap Yap Yap Yap owo adds the cell onto hold 5 times, getting 74
yapyap yapyap owo decreases hold twice, getting 72 (ASCII 'H')
Yip owo prints 'H'
Yap Yap yapyip owo adds 14 twice and increases by one to get 'e'
Yip owo prints 'e'
yipyap yipyip owo stores 'e' onto the tape (swap and load)
yip yipyap yip owo copies 'e' onto the next cell and moves
yapyip yapyip yipyap owo stores 2 onto the next cell
Yap Yap Yap yapyip
yap Yap owo gets 'l' into hold
Yip Yip owo prints 'l' twice
yip yip yip yipyap yipyip owo moves two cells right, stores 'l' and moves back
yap yap Yap yapyip Yip owo gets 'o' onto the tape and prints it
yipyap yip yipyap yipyip Yap owo stores 4 onto the tape
yipyap yipyip Yap
yipyap yipyip Yap
yipyap yipyip Yap owo adds 4 multiple times to get 32 on hold (space) and 16 on tape
Yip owo prints the space
yap yap yipyap owo swaps 'e' with 32 from the tape yip yip yip! owo subtracts 10 from 'e' to get 'U' yapyip yapyip owo decreases twice to get 'W' Yip owo prints 'W'
yap yipyap Yip owo get 'o' from the tape and prints it
yapyip yapyip yapyip Yip owo decreases 3 times to get 'r' and prints it
yip yip yipyap Yip owo gets 'l' from the tape and prints it
yap yap yap yap yipyap yapyap owo gets 'e' from the tape, decreases it to get 'd'
Duplicate String
The following example duplicates a NUL-terminated string, and defines some useful string-manipulating functions. Note that the tape would need to be initialized with something for this to work.
owo strlen yip Yap? yap? owo write length yip yipyap yipyip owo while length is != 0 yip? owo move to the next letter yap Yap? yip! owo move cell to the end yipyip Yap? yip yipyap yip Yap? yip owo find the length Yap? yap yip owo decrement length yipyip yapyap yipyap yapyap yap! Yap! owo Swap adjacent cells owo Pre [a<, b] hold=c owo Post: [b<, a] hold=c Yip? yipyap owo perform 3 swaps yipyap yip yipyap yap yipyap Yap! owo Strlen owo Pre [S<, t, r, i, n, g, 00] owo Post[S, t, r, i, n, g, 00<] hold=strlen Yip? yap? owo Clear hold yipyip yip! owo Load first cell yipyap owo while not 0 yip? owo put it back yipyap owo increase size yapyip owo move and load next cell yip yipyap yap! owo swap back yipyap Yap! owo Print nul-terminated string owo Pre [S<, t, r, i, n, g, 00] owo Post[S, t, r, i, n, g, 00<] hold=0, printed String Yip? Yip yipyip yip? Yip yip yipyip yap! Yap! owo Go to previous 00, preserving hold owo Pre [00, ..., xx<] hold=a owo Post [00<, ..., xx] hold=a Yip? yap owo load first cell yipyap owo while not 0 yip? owo swap back and move 1 behind yipyap yap yipyap yap! owo final swap yipyap Yap! owo Move hold to next 00 owo Pre [xx<, ..., 00] hold=aa owo Post [xx, ..., aa<] hold=0 Yip? yip owo load first cell yipyap owo while not 0 yip? owo swap back and move 1 ahead yipyap yip yipyap yap! Yap! owo Move back "hold" spaces owo Pre [b1, ..., bn<] hold=n owo Post [b1<, ..., bn] hold=0 Yip? yip! owo while not 0 yip? owo decrement yapyap owo move 1 behind yap yap! Yap!
External Links
- Glax's site contains a description of the and a web-based interpreter and debugger.
- yipyap.py Python-based interpreter of the language