Bit is an esoteric programming language created by me, read the specification for details, and feel free to write some programs with it using the interpreter in this repository (java -jar bit.jar filename.bit
)
First off, there are two built in stacks: the bitstack and the stack.
Second, throughout this specification, the letter 'b' will be used to indicate a value in binary, and [x]
will indicate that x is an optional argument. An overriding operation is one that sets a variable, overriding it if it already exists. (most operations are overriding unless explicitly stated, for any questions feel free to open an issue)
$$
- A commentBIT 0
- Pushes a 0 to the bottom of the bitstackBIT 1
- Pushes a 1 to the bottom of the bitstackBYTE
- Converts the bitstack into a byte (bitstack: 1, 0 = 10b or 2), clears it, then pushes the byte to the top of the normal stackBYTE varname
- Converts the bitstack into a byte, clears it, then sets the specified variable to that byte (overriding operation)BYTES n [var]
Iterates through the bitstack, splitting it every n bits. Then, it takes each one of the split parts and converts them to a byte, then stores the bytes in the stack as a single element or invar
if specified (bitstack: 1,0,1,0,1,0,1,0 = [1010b, 1010b] if n = 4)ADD
- Pops 2 values from the stack, adds them, and pushes the result to the stack (Errors if a non-number value is popped, like that of callingBYTES
orSTORE
)ADD a
- Pops a value from the stack, adds it toa
, and pushes the result to the stackADD a b
- Adds a and b, and pushes the result to the stackADD a b var
- Adds a and b, and stores the result invar
(ifvar
is an array created byBYTES
orSTORE
, it pushes the result tovar
instead of setting it)SUBTRACT [a] [b] [var]
- Same as above 3, but with subtraction.MULTIPLY [a] [b] [var]
- Same as above 3, but with multiplication.LOG a
- Pops b, pushes log a of bLOG a b
- Pushes log a of bLOG a b var
- Stores log a of b invar
(Ifvar
us an array, push instead of setting)POWER [a] [b] [var]
- Same as above 3, but with exponents.TRUNC
- Pops a and b, pushesa
truncated to theb
th decimalTRUNC a
- Pops b, pushesb
truncated to thea
th decimalTRUNC a b
- Pushesa
truncated to theb
th decimalTRUNC a b var
- Storesa
truncated to theb
th decimal invar
(Ifvar
us an array, push instead of setting)DUMP_ARRAY a [b]
- If b is specified, add all contents of b to a, otherwise add all contents of a to the stackDUMP_STACK
- Clears the stackDUMP_STACK a
- For an array a, override it with the stack (unless the stack is 1 element long in which a is overridden with that element) and clear the stack, for a non-array a, override it with a popped valueDUMP var
- Push var to the stackDUP
- Push the contents of the stack to the stack itselfDUP var
- Push the contents ofvar
tovar
FLIP [var]
- Flip the contents ofvar
or the stackIMPORT var
- Runs the code inside the file with pathvar
(stringified) as if theIMPORT
statement were replaced by the code inside the file (aka: it isn't sandboxes). If the file doesn't exist, the statement silently exits and does nothingIN [prompt] [var]
- Ifprompt
is not specified, prompt = "" (empty), then stringify prompt (see below) and print it with no newline, then read from STDIN. Take each character's ASCII value and push it to the stack as a single element OR overridevar
with that list of values. Example:IN somevar othervar
, othervar = [65, 65, 67] if user typed ABCINTO
- Pops a value from the stack, and sets the stack to that value if it is an array, otherwise throw an error.OUTOF
- Set stack to a new stack containing the old stack,stack = [stack]
POP [n]
- If n is not specified, pop a value from the stack, otherwise pop n values from the stackPRINT [var]
- Ifvar
is not specified, add a popped value to the printing queue, otherwise ifvar
is an array, add all elements of it to the printing queue, otherwise ifvar
is a number, add it to the printing queuePRINTLN
- Stringify the printing queue, then print it to STDOUT with a trailing newline, then clear the printing queuePUSH var
- Pop a value from the stack, and overridevar
with itSHIFT
- Rotates the stack byamount
or 1 (stack: [1, 2, 3] -> [3, 1, 2])SHIFT var
- Same as above but with varSTORE
- Behaves exactly likeBYTES
, but has a fixed amount of elements, so elements pushed to it override others ([0, 1,2,3] PUSH 4 = [1,2,3,4] removing 0), and if any are popped/missing, they are replaced with zeroes (This even works withIN
, if the user doesn't type enough characters, zeroes will be inserted at the start of the stack)
Stringification is the process of turning an array (created by BYTES
or STORE
) into a string, to do this, iterate over the array, and convert each ASCII value to a character, concatenate all the characters and that is the result of the stringification
For example, BYTES 0
or dividing by 0, the interpreter will stop with an error
Program that prints 'A':
BIT 1 $$ Add the bits of 65
BIT 0
BIT 0
BIT 0
BIT 0
BIT 0
BIT 1 $$ Most significant bits are here!
BYTE
PRINT
PRINTLN
Cat program:
IN $$ Takes input and pushes it to the stack
PRINT $$ Pops an item, which is an array of character codes in this case, and puts the characters in the printing queue
PRINTLN $$ Print the printing queue