Language docs

Core primitives

VM primitive words, opcode table, stack effects, and runtime implementation coverage.

This page lists the VM primitive words.

Core primitives

SyntaxMnemonicOpcodeStack effectDescription
nopNOP0… nop == …No operation; does nothing.
evalEVAL1[A] eval == a*Evaluates a quotation, executing its contents.
putcPUTC2n putc == {prints char(n)}Prints a character given by its numeric code.
getcGETC3getc == n {reads char}Reads a single character from input and pushes its code.
putnPUTN5n putn == {prints n}Prints a number to output.
clockCLOCK6clock == n {reads clock}Returns the current time as a Unix timestamp.
dropDROP8a drop ==Removes the top value from the stack.
q<PUSHR14a q< == | …aPushes a value onto the return stack.
q>PULLR15q> == a | a…Pops a value from the return stack onto the main stack.
<<SHIFTL16a b << == nLeft-shifts a by b bits.
>>SHIFTR17a b >> == nRight-shifts a by b bits.
clrCLR24… clr ==Clears the entire stack.
randRAND26n rand == r {0 <= r < n}Generates a random number between 0 and n-1.
exitEXIT27n exit == {exits with code n}Exits the program with the given exit code.
dupDUP33a dup == a aDuplicates the top value on the stack.
depthDEPTH35… depth == … nPushes the current stack depth.
swapSWAP36a b swap == b aSwaps the top two values on the stack.
%MOD37a b % == a%bComputes the remainder of a divided by b.*
&AND38a b & == a&bBitwise AND of a and b.
(STASH40… ( == {moves stack to queue}Moves values from the stack to the queue.
)FETCH41) == … {restores stack from queue}Moves values from the queue back to the stack.
*MUL42a b * == a*bMultiplies a by b.
+ADD43a b + == a+bAdds a and b together.
consCONS44x y cons == qBuilds an anonymous quotation from two stack values.
-SUB45a b - == a-bSubtracts b from a.
.DUMP46… . == … {prints stack}Prints the entire stack to output.
/DIV47a b / == ⌊a/b⌋₀Divides a by b using integer division.*
:MARK58n : == {begin definition(n)}Begins a new word definition with name n.
;DEF59; == {end definition}Ends the current word definition.
<LT60a b < == flagPushes true if a is less than b.
=EQ61a b = == flagPushes true if a equals b.
>GT62a b > == flagPushes true if a is greater than b.
?WHEN63flag [A] ? == a*Executes the quotation if flag is true.
[BRA91[ == {begin quotation}Begins a quotation (anonymous code block).
]KET93] == [A] {end quotation}Ends a quotation and pushes it to the stack.
^POW94a b ^ == a^bComputes a raised to the power of b.
|OR124a b | == a|bBitwise OR of a and b.
~NOT126a ~ == ~aBitwise NOT of a.

* Division note: the language docs define / as integer division truncated toward zero, with % as the matching remainder. That means -3 2 / is -1, not -2, and -3 2 % is -1.