This project is read-only.

Language Reference

Program Format

Programs follow this basic format:
# This is a line comment

# Constant definition formats
integerConstant: 1234
hexConstant: 0x5678
charConstant: '0'

# Function definition format
functionName: {
    # Push a series of constant values to the stack.
    1234 0x5678 '0'

    # Do it again with the defined constants.
    integerConstant hexConstant charConstant
}

# Main function definition
# This is the program's entry point.
main: {
    # Call the defined function.
    functionName
}

Note that the order of definitions is unimportant; the above program would work equally well if the order of all the definitions was reversed. Every program must have a main function defined.

Built-In Functions

All built-in function references use the following format:

function name (popped -> pushed)
Description of function.

(popped -> pushed) indicate how many items are popped from the stack as input, and how many items are pushed to the stack as output.

Math


add (2 -> 1)
Adds the top two items of the stack, pushing the result.

sub (2 -> 1)
Subtracts the top of the stack from the second item on the stack, pushing the result.

mul (2 -> 1)
Multiplies the top two items of the stack, pushing the result.

div (2 -> 1)
Divides the second item on the stack by the top of the stack, pushing the result.

mod (2 -> 1)
Divides the second item on the stack by the top of the stack, pushing the remainder.

shl (2 -> 1)
Left-shifts the second item on the stack a number of times equal to the top of the stack, pushing the result.

shr (2 -> 1)
Right-shifts (binary) the second item on the stack a number of times equal to the top of the stack, pushing the result.

Stack


toss (1 -> 0)
Throws the top item of the stack away.

dup (1 -> 2)
Duplicates the top of the stack.

swap (2 -> 2)
Swaps the top two items on the stack.

trot (n+? -> ?)
Rotates the top n items towards the top of the stack, putting the top of the stack at the nth position, where n is the top of the stack. Note that calling swap is faster than 2 trot.

brot (n+? -> ?)
Rotates the top n items towards the bottom of the stack, putting the nth item of the stack at the top, where n is the top of the stack. Note that calling swap is faster than 2 brot.

reverse (n+? -> ?)
Reverses order of the top n items, where n is the top of the stack. Note that calling swap is faster than 2 reverse.

Conditionals


=? {} {} (1 -> 0)
Pops the top item of the stack, then compares it to the next item. If they are equal, the first block of instructions will be executed. Otherwise, the second block will be executed.

!=? {} {} (1 -> 0)
Pops the top item of the stack, then compares it to the next item. If they are not equal, the first block of instructions will be executed. Otherwise, the second block will be executed.

>? {} {} (1 -> 0)
Pops the top item of the stack, then compares it to the next item. If the second item is greater than the first, the first block of instructions will be executed. Otherwise, the second block will be executed.

<? {} {} (1 -> 0)
Pops the top item of the stack, then compares it to the next item. If the second item is less than the first, the first block of instructions will be executed. Otherwise, the second block will be executed.

Loops


while=? {} (1 -> 0)
Pops the top value off the stack, then executes the block as long as the top value is equal to the popped value.

while!=? {} (1 -> 0)
Pops the top value off the stack, then executes the block as long as the top value is not equal to the popped value.

while>? {} (1 -> 0)
Pops the top value off the stack, then executes the block as long as the top value is greater than the popped value.

while<? {} (1 -> 0)
Pops the top value off the stack, then executes the block as long as the top value is less than the popped value.

times {} (1 -> 0)
Pops the top value off the stack, then executes the block that many times.

I/O


printchar (1 -> 0)
Prints the top of the stack as a character.

printint (1 -> 0)
Prints the top of the stack as a decimal integer.

printhexint (1 -> 0)
Prints the top of the stack as a hexadecimal integer. (Does not include a 0x prefix.)

printstring (? -> 0)
Executes printchar until the top of the stack is zero. Note that this will output in "reverse", meaning that the first item of the string must be the top of the stack.

readchar (0 -> 1)
Reads an input character, pushing it to the top of the stack.

readint (0 -> 1)
Reads a decimal integer from input, pushing it to the top of the stack. This will read until a non-decimal digit is encountered. That final input will be tossed.

readhexint (0 -> 1)
Reads a hexadecimal integer from input, pushing it to the top of the stack. This will read until a non-hexadecimal digit is encountered. That final input will be tossed.

readstring (0 -> ?)
Pushes a zero (0), then executes readchar until a line feed (0x11) character is read.

Last edited May 16, 2012 at 6:16 AM by jdmichal, version 6

Comments

No comments yet.