OverSwarm VM Semantic
Important note! The contents in this page are old and outdated; they do not reflect the actual implementation
The OverSwarm VM is a stack based virtual machine. There is a main stack (herein referred to as “stack”), on which stack frames are pushed and popped. In each stack frame, a stack holds the object values. The top of the stack indicates the topmost value in the topmost frame. Each frame has a variable slot that is used to store local variables; global variables are stored in the lowest frame (index equal to 0).
Notes: cfi indicates the current frame index (the main frame index is 0)
Opcode (Parameters) | Semantic |
---|---|
LOAD offset, index | Pushes the value in frame [cfi - offset] at position [index] on the top of the local stack. If the [offset] value is negative, the global stack frame is accessed. |
STORE offset, index | Pops the value on top of the local stack and stores it in frame [cfi - offset] at position [index]. If the [offset] value is negative, the global stack frame is considered. |
POP | Pops and discards the value on top of the local stack. |
DUP | Duplicates the value on top of the local stack . |
CONST value | Pushes a constant value on the local stack. |
JUMP target | Jumps to the specified [target] label |
FJUMP target | Pops the value on top of the local stack. If the value is nil jumps to [target] |
NOP optional arguments | No operation is performed (can be used for debug purposes) |
LABEL target | Defines a jump target named [target] |
FRAME functionname vcount | Defines the beginning of a function named [functionname]: it allocates [vcount] variable slots then pops [vcount] values from the stack and stores them in the frame slots. |
END | Terminates the execution |
DROP | Drops the current stack frame |
RETURN | Pops the value at the top of the local stack. Drops all local stack frames, and the first found non-local stack frame. Pushes the previously saved value in the new local stack and then jumps to the return target that has been saved in the frame. Deletes the frame. |
LAMBDA target varlist | Creates a lambda object storing the [target] to jump to for execution and the references to values that need to be frozen ([varlist] is in the format offset, index, offset, index,…) |
ICALL functionname argc | Pops [argc] values from the stack . Stores the current execution point. Creates a new stack frame and pushes the previously popped values in inverse order, then jumps to the specified [functionname] entry point (which is a FRAME instruction). |
ECALL functionname argc | Calls an external function. Pops [argc] values from the stack to pass to the latter. When the call ends, the return value of the external function is pushed on the stack |
LOCAL vcount | Creates a new local stack frame and allocates [vcount] variable slots. This frame has not return pc value. |
LIST count | Pops [count] elements from the local stack and creates a list object that is pushed on the local stack. If [count] < 0 then all available elements on the stack are put in the list. |
LCALL argc | Calls a lambda function object. Pops an element from the stack (the lambda object), pops [argc] elements from the local stack (the arguments to be passed to the lambda), creates a new stack frame (with a reference to the lambda object) and pushes those elements in reverse order. Then retrieves the values stored in the lambda environment and accordingly sets the value of the values in the current frame. Finally it jumps to the target specified in the lambda object. |
LRETURN | Returns from a lambda call. Updates the frozen values in the lambda object, drops the environment, and continues execution after the lambda calling point |
ITEM | Pops an integer value from the stack, then pops a list and pushes the item at the former position in the list |
INC | Increases the integer value on the stack by one |
LEN | Pops a list from the stack, and pushes its length |
LT | Pops two values from the stack. Pushes a non nil value on the stack if the second popped value is less than the first one, nil otherwise. |
EQ | Pops two values from the stack. Pushes a non nil value on the stack if the popped values are equal, nil otherwise |
GET, STRING, ADD, DICT, SUB, MUL, DIV, PUT, APPEND, PC, UNWIND, SET