Lunula VM ~OpCodes

Opcodes are represented by 32-bit unsigned integers. The layout is:

13 bits 13 bits 6 bits
B A ~

An opcode can either have a single AX parameter, or an A and B parameter. The parameters depend on the opcode.

!OPCODE !VALUE ! A !B !AX !Description
~SAVE-CONTINUATION 0 index Saves the registers (except VALUE) into a continuation object and clears ~EVAL-STACK
~FETCH-LITERAL 1 index Sets VALUE to the literal located in TEMPLATE at given index
PUSH 2 Pushes VALUE to the ~EVAL-STACK
APPLY 3 Executes the closure or procedure in VALUE. If VALUE is a procedure, ENVT and TEMPLATE are set to the closure's environment and template and PC is set to 0. If VALUE is a native procedure, it is executed with the values in ~EVAL-STACK as parameters and an ''implicit'' RETURN is performed.
BIND 4 n Creates a new lexical environment frame of size ''n'' and binds each slot to the popped values in ~EVAL-STACK. Bindings are set in reverse order. The first value popped from ~EVAL-STACK will be the last binding in the frame.
~MAKE-CLOSURE 5 Sets VALUE to a new closure object created from the template located in VALUE and the environment in ENVT.
~TOPLEVEL-GET 6 Sets VALUE to the toplevel value bound to the symbol located in VALUE
~TOPLEVEL-SET 7 Sets the toplevel value of the symbol located in VALUE to the value located popped from ~EVAL-STACK
~LOCAL-GET 8 f-index v-index Sets VALUE to the lexical variable value located in ENVT at frame index ''f-index'' and slot index ''v-index''.
~LOCAL-SET 9 f-index v-index Sets the lexical variable value located in ENVT at frame index ''f-index'' and slot index ''v-index'' to the value in VALUE.
RETURN 10 Restores the registers saved in CONT
END 11 Terminates the virtual machine.
JUMP 12 index Unconditionally set PC to ''index''
~JUMP-IF-FALSE 13 index Set PC to ''index'' if the value in VALUE is false (#f)
~BIND-VARARGS 14 n Performs a binding operation like BIND but the last binding is set to the remaining contents of ~EVAL-STACK.

Last edited Mar 2, 2010 at 6:42 PM by anthonyf, version 1


No comments yet.