Skip to content

Instructions

Matthias Zenger edited this page May 16, 2016 · 3 revisions

LispKit Bytecode Instructions

Stack management

Instruction Explanation
pop Drops the top element from stack.
dup Duplicates the top element on the stack.
swap Swaps the top two elements on the stack.
alloc n Pushes n undefined values onto the stack.
reset o,n Replaces n values on the stack with the undefined value starting from frame pointer offset o.

Constants

Instruction Explanation
push_undef Pushes the undefined value onto the stack.
push_eof Pushes the EOF value onto the stack.
push_null Pushes value null (empty list) onto the stack.
push_true Pushes value true onto the stack.
push_false Pushes value false onto the stack.
push_fixnum n Pushes the fixnum n onto the stack.
push_bignum bn Pushes the bignum bn onto the stack.
push_rat r Pushes the rational number r onto the stack.
push_bigrat br Pushes the given bigrat number br onto the stack.
push_flonum x Pushes the flonum x onto the stack.
push_complex cx Pushes the complex number cx onto the stack.
push_char ch Pushes the character ch onto the stack.
push_constant c Pushes the constant from the constant pool at index c onto the stack.

Functions

Instruction Explanation
make_closure n,f Creates a new closure from a capture list and a code fragment. The capture list is created from the top n elements on the stack. f is an index into the list of code fragments of the currently executed code.
make_frame Pushes a new stack frame onto the stack.
call n Calls a procedure with n arguments.
tail_call n Calls a procedure with n arguments. This instruction is used for tail calls and does not require a new frame to be pushed.
apply n This instruction expects on the stack a function, n - 1 individual arguments and an additional list of arguments. apply pushes the elements of the list onto the stack as well and then applies the function to all arguments on the stack. The instruction puts the result of the function application onto the stack.
return Returns from the currently executed procedure.
assert_arg_count n Checks that there are exactly n arguments on the stack.
assert_min_arg_count n Checks that there are at least n arguments on the stack.
collect_rest n Collects the arguments exceeding n into a list.
compile Compiles the expression on top of the stack creating a thunk (a procedure without arguments) which is left on top of the stack.

Macros

Instruction Explanation
make_syntax Pops a syntax transformer function off the stack, creates a special form from it and pushes it onto the stack.

Promises

Instruction Explanation
make_promise n,f Creates a promise on the stack whose value will be computed by executing a closure that consists of n captured variables (on the stack), and the code fragment at index f.
force Forces the value of the promise on top of the stack. If the promise has been evaluated already, push the value onto the stack and skip the next instruction (which is typically a store_in_promise instruction).
store_in_promise Stores the value on top of the stack in the promise of the second top-most value on the stack. The promise gets removed from the stack.

Variables

Instruction Explanation
make_local_variable o Creates a new variable, pops an expression from the stack and assignes the variable this expression as its initial value. The variable is then stored at the location specified by the frame pointer offset o.
make_variable_argument n Creates a new variable and assignes the variable the expression at the location specified by the frame pointer offset o. The variable is then stored at the location specified by the frame pointer offset o; i.e. this instruction swaps a value on the stack with a variable with the same value.

Bindings

Instruction Explanation
push_global c TODO
set_global c TODO
define_global c TODO
push_captured d TODO
push_captured_value d TODO
set_captured_value d TODO
push_local o TODO
push_local_value o TODO
set_local_value o TODO

Control flow

Instruction Explanation
branch i TODO
branch_if i TODO
branch_if_not i TODO
and i TODO
or i TODO

Equivalences

Instruction Explanation
eq TODO
eqv TODO
equal TODO

Containers

Instruction Explanation
list n TODO
cons TODO
car TODO
cdr TODO
vector n TODO
list_to_vector TODO
vector_append n TODO
is_vector TODO

Math

Instruction Explanation
fx_plus TODO
fx_minus TODO
fx_mult TODO
fx_div TODO
fl_plus TODO
fl_minus TODO
fl_mult TODO
fl_div TODO

Miscellaneous

Instruction Explanation
noop TODO
push_current_time TODO
display TODO
newline TODO
Clone this wiki locally