Instruction Set
A summary of all Blaze instructions is provided in the table below.
Note
- Stack changes are denoted as
before → after, where stack items are shown from bottom to top. - Instruction parameters are shown using Greek letters (e.g.,
αis the first parameter,βthe second, etc).
Example of a single-parameter instruction:
POP α
Example of a two-parameter instruction:
EXTENDED_ARG β
LDLOCAL α
Stack notation example:
..., x, y → ..., z. This means the instruction pops y and x, and pushes z.
| Type | Name | # Params | Stack | Description |
|---|---|---|---|---|
| 00 | NOP | 0 | → | No operation |
| 01 | POP | 1 | value → | Removes α values from the stack |
| 02 | EXTENDED_ARG | 1 | → | Extend the previous argument with N |
| 03 | LDNULL | 0 | → null | Load null instance onto stack |
| 04 | LDARG | 1 | → value | Load function parameter α onto stack |
| 05 | LDCONST | 1 | → value | Load constant α onto stack |
| 06 | LDLOCAL | 2 | → value | Loads the value from the local slot α with upvalue β onto the stack |
| 07 | LDVAR | 1 | → value | Load a module variable onto the stack, with α representing the string constant which holds the name |
| 08 | LDFUNC | 1 | → func | Loads the function α onto the stack |
| 09 | LDCLASS | 1 | → class | Loads the class α onto the stack |
| 0A | LDBOOL | 1 | → value | Loads a boolean of value α onto the stack |
| 0B | STLOCAL | 2 | value → | Stores the top stack value into local slot α with upvalue β |
| 0C | STVAR | 1 | value → | Stores the top stack value into a module variable, with α representing the string constant which holds the name |
| 0D | STARG | 1 | value → | Store top stack value into function parameter α |
| 0E | CALL | 1 | argn, ..., arg1, callable → result | Calls the top stack value with number of parameters α |
| 0F | RET | 0 | value → | Returns the top stack value |
| 10 | ADD | 0 | left, right → result | Adds two objects |
| 11 | SUB | 0 | left, right → result | Subtracts two objects |
| 12 | MUL | 0 | left, right → result | Multiplies two objects |
| 13 | DIV | 0 | left, right → result | Divides two objects |
| 14 | INTDIV | 0 | left, right → result | Performs integer division on two objects |
| 15 | THROW | 0 | value → | Throws an exception with top stack value |
| 16 | CATCH | 1 | value → | Stores relative position α of the catch block into the exception stack |
| 17 | TRY_END | 0 | → | Indicates the exit of a try block |
| 18 | EQ | 0 | left, right → result | Compares two objects |
| 19 | LT | 0 | left, right → result | Less than comparison |
| 1A | LTE | 0 | left, right → result | Less than or equals comparison |
| 1B | NOT | 0 | value → negated | Negates an object |
| 1C | JMP | 1 | → | Relative jump α instructions ahead |
| 1D | JMPB | 1 | → | Relative jump α instructions back |
| 1E | JMPA | 1 | → | Absolute jump to instruction α |
| 1F | JMPT | 1 | value → | Relative jump α instructions ahead if top stack value is true |
| 20 | JMPF | 1 | value → | Relative jump α instructions ahead if top stack value is false |
| 21 | OR | 0 | left, right → value | Perform a logical OR operation on two objects |
| 22 | AND | 0 | left, right → value | Perform a logical AND operation on two objects |
| 23 | DUP | 1 | value → value * α | Create α copies of the top stack value |
| 24 | VARARGS | 1 | valuen, ..., value1 → | / |
| 25 | LDLIST | 1 | valuen, ..., value1 → list | Create a list from α values from the stack |
| 26 | LDOBJ | 1 | valuen, keyn, ..., value1, key1 → dict | Create a dictionary from α key-value pairs from the stack |
| 27 | LDINDEX | 0 | idx, object → value | Load the value stored at index idx from object |
| 28 | STINDEX | 0 | value, idx, object → | Store a value at index idx in object |
| 29 | LDPROP | 1 | object → value | Load object property α onto stack, with α representing the string constant which holds the name |
| 2A | STPROP | 1 | value, object → | Store value into object property α, with α representing the string constant which holds the name |
| 2B | LDEVENT | 0 | → event | Create and push an event object |
| 2C | ITER | 0 | value → iterator | Create an iterator for an object |
| 2D | NEW | 1 | argn, ... arg1, class → instance | Creates a new instance of a class, with α being the number of constructor parameters |
| 2E | ATTACH | 0 | func, event → | Attaches a callback to an event |