4.7 KiB
Bytecode Specification
all opcodes are uint8_t, and all operands are uint64_t unless marked with an asterisk (*), where it is marked as uint8_t
OP_LOAD_STRING
loads and initialises a string from the constant buffer into the provided register.
this operation 4 operands.
- the register to write to. (*)
- the length of the data in the constant buffer.
- the offset in the constant buffer.
OP_DECLARE
initilises a variable on the current scope with a given value. errors if the variable is already initilises on the current scope.
this operation takes 3 operands.
- the length of the variable name.
- the offset in the constant buffer of the variable name.
- the fixed hash of the variable name.
- the register of the given value (*)
OP_ASSIGN
assigns to a variable in the stack. if the variable doesnt exist on the stack, it is automatically declared on the current scope.
this operation takes 3 operands.
- the length of the variable name.
- the offset in the constant buffer of the variable name.
- the fixed hash of the variable name.
- the register of the given value (*)
OP_LOAD_NULL
sets a given register to null.
this operation takes 1 operand.
- the register to set to null. (*)
OP_LOAD_FUNCTION
initilises a function to a given register.
- the offset of the name of the function.
- the length of the name of the function.
- the number of arguments.
- the offset of the name of the argument.
- the length of the name of the argument.
- instruction 4 and 5 loop for each argument.
- the offset of the bytecode of the function.
- the length of the bytecode of the function.
OP_IDENTIFIER
initilises a function to a given register.
- the length of the identifer.
- the offset of the identifier.
- the fixed hash of the variable name.
OP_BOOL
converts a value in register 0 into true or false depending on the result from __bool__ (using asBool if the object is a primitive)
OP_JUMP_IF_FALSE
jumps when a the value in the given register is false.
- the register to read. (*)
- the index to jump to.
OP_JUMP
jumps unconditionally to an index.
- the index to jump to.
OP_NEW_SCOPE
creates a new stack
OP_EMPTY_SCOPE
empties the current scope so the same memory can be reused.
OP_POP_SCOPE
pops the top scope off the current
OP_INIT_CALL
initialises a call instance struct and arguments buffer.
- the number of objects for the arguments buffer
OP_INSERT_ARG
- index of the argument in the arguments buffer to write the object from the register into.
OP_CALL
call the function at the head of the call instance stack, then pops it off the stack.
OP_SOURCE_LOCATION
sets the source location onto the runtime
- the line
- the column
- the length
OP_LOAD_GETATTRIBUTE_METHOD
loads the __getattribute__ method from the objects class in register 0 and put it into register 0
OP_LOAD_BOOL
loads a boolean into register 0
- byte representing true or false (1 or 0) *
OP_LOAD_NUMBER
loads a mpq_t / int64 number into memory
- the register to write to. (*)
- is int64 (*)
- the size of the numerator in the constant buffer.
- the offset in the constant buffer of the numerator.
- is integer. (*)
- the size of the denominator in the constant buffer.
- the offset in the constant buffer of the denominator.
OP_COPY_TO_REGISTER
copies the value from one register to another
- the register to copy from (*)
- the register to write to (*)
OP_ADDITION
performs an addition between register A and register B, storing the result in register C
- the register A (*)
- the register B (*)
- the register C (*)
OP_SUBTRACTION
performs an subtraction between register A and register B, storing the result in register C
- the register A (*)
- the register B (*)
- the register C (*)
OP_MULTIPLICATION
performs an multiplication between register A and register B, storing the result in register C
- the register A (*)
- the register B (*)
- the register C (*)
OP_DIVISION
performs an division between register A and register B, storing the result in register C
- the register A (*)
- the register B (*)
- the register C (*)
OP_NOT
inverts the boolean value in register 0.
OP_LOAD_SETATTR_METHOD
loads the __setattr__ method from the objects class in register 0 and put it into register 0
OP_CREATE_DICTIONARY
create a dictionary object into register 0.
OP_LOAD_GETITEM_METHOD
loads the __getitem__ method from the objects class in register 0 and put it into register 0
OP_LOAD_SETITEM_METHOD
loads the __setitem__ method from the objects class in register 0 and put it into register 0