Documentation
¶
Index ¶
- Constants
- type LineInfo
- type LineInfoList
- func (l *LineInfoList) AddBytesToLastLine(bytes int)
- func (l *LineInfoList) AddLineNumber(lineNumber int, bytes int)
- func (l LineInfoList) First() *LineInfo
- func (l LineInfoList) GetLineInfo(instructionIndex int) *LineInfo
- func (l LineInfoList) GetLineNumber(instructionIndex int) int
- func (l LineInfoList) Last() *LineInfo
- func (l *LineInfoList) RemoveByte()
- func (l *LineInfoList) RemoveBytes(count int)
- type OpCode
Constants ¶
View Source
const ( UINT8_SIZE = iota // The integer fits in a uint8 UINT16_SIZE // The integer fits in a uint16 UINT32_SIZE // The integer fits in a uint32 UINT64_SIZE // The integer fits in a uint64 )
View Source
const ( CLOSED_RANGE_FLAG byte = iota OPEN_RANGE_FLAG LEFT_OPEN_RANGE_FLAG RIGHT_OPEN_RANGE_FLAG BEGINLESS_CLOSED_RANGE_FLAG BEGINLESS_OPEN_RANGE_FLAG ENDLESS_CLOSED_RANGE_FLAG ENDLESS_OPEN_RANGE_FLAG )
View Source
const ( DEF_MODULE_FLAG byte = iota DEF_CLASS_FLAG DEF_MIXIN_FLAG DEF_INTERFACE_FLAG )
View Source
const MaxInstructionByteCount = 6
The maximum number of bytes a single instruction can take up.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type LineInfo ¶
type LineInfo struct {
LineNumber int // Number of the line of source code that the instructions were generated from
InstructionCount int // Number of consecutive bytecode instructions that share a single line of source code
}
Contains a source code line number with the count of bytecode instructions that were generated from that line
func NewLineInfo ¶
Create a new LineInfo. LineNumber and InstructionCount should be greater than 0.
type LineInfoList ¶
type LineInfoList []*LineInfo
func (*LineInfoList) AddBytesToLastLine ¶
func (l *LineInfoList) AddBytesToLastLine(bytes int)
func (*LineInfoList) AddLineNumber ¶
func (l *LineInfoList) AddLineNumber(lineNumber int, bytes int)
Set the source code line number for the next bytecode instruction.
func (LineInfoList) GetLineInfo ¶
func (l LineInfoList) GetLineInfo(instructionIndex int) *LineInfo
func (LineInfoList) GetLineNumber ¶
func (l LineInfoList) GetLineNumber(instructionIndex int) int
Get the source code line number for the given bytecode instruction index. Returns -1 when the line number couldn't be found.
func (*LineInfoList) RemoveByte ¶
func (l *LineInfoList) RemoveByte()
func (*LineInfoList) RemoveBytes ¶
func (l *LineInfoList) RemoveBytes(count int)
type OpCode ¶
type OpCode byte
Represents Operation Codes used by the Elk Virtual Machine.
const ( NOOP OpCode = iota // Does not perform any operation, placeholder. RETURN // Return from the current frame LOAD_VALUE_0 // Push a value with index 0 onto the value stack LOAD_VALUE_1 // Push a value with index 1 onto the value stack LOAD_VALUE_2 // Push a value with index 2 onto the value stack LOAD_VALUE_3 // Push a value with index 3 onto the value stack LOAD_VALUE8 // Push a value with a single byte index onto the value stack LOAD_VALUE16 // Push a value with a two byte index onto the value stack ADD // Take two values from the stack, add them together (or call the + method) and push the result ADD_INT // Take an Int and another value from the stack, add them together (or call the + method) and push the result ADD_FLOAT // Take a Float and another value from the stack, add them together (or call the + method) and push the result SUBTRACT // Take two values from the stack, subtract them (or call the - method) and push the result SUBTRACT_INT // Take an Int and another value from the stack, subtract them (or call the - method) and push the result SUBTRACT_FLOAT // Take a Float and another value from the stack, subtract them (or call the - method) and push the result MULTIPLY // Take two values from the stack, multiply them (or call the * method) and push the result MULTIPLY_INT // Take an Int and another value from the stack, multiply them (or call the * method) and push the result MULTIPLY_FLOAT // Take a Float and another value from the stack, multiply them (or call the * method) and push the result DIVIDE // Take two values from the stack, divide them (or call the / method) and push the result DIVIDE_INT // Take an Int and Take two values from the stack, divide them (or call the / method) and push the result DIVIDE_FLOAT // Take a Float and Take two values from the stack, divide them (or call the / method) and push the result EXPONENTIATE // Take two values from the stack, raise one to the power signified by the other EXPONENTIATE_INT // Take an Int and another value from the stack, raise one to the power signified by the other NEGATE // Take a value off the stack and negate it NEGATE_INT // Take an Int off the stack and negate it NEGATE_FLOAT // Take a Float off the stack and negate it NOT // Take a value off the stack and perform boolean negation (converting it to a Bool) BITWISE_NOT // Take a value off the stack and perform bitwise negation TRUE // Push true onto the stack FALSE // Push false onto the stack NIL // Push nil onto the stack POP // Pop an element off the stack. POP_2 // Pop two elements off the stack PREP_LOCALS8 // Prepare slots for local variables and values (8 bit operand) PREP_LOCALS16 // Prepare slots for local variables and values (16 bit operand) SET_LOCAL_1 // Assign the value on top of the stack to the local variable with index 1 SET_LOCAL_2 // Assign the value on top of the stack to the local variable with index 2 SET_LOCAL_3 // Assign the value on top of the stack to the local variable with index 3 SET_LOCAL_4 // Assign the value on top of the stack to the local variable with index 4 SET_LOCAL8 // Assign the value on top of the stack to the local variable with the given index (8 bit operand) SET_LOCAL16 // Assign the value on top of the stack to the local variable with the given index (16 bit operand) GET_LOCAL_1 // Push the value of the local variable with index 1 GET_LOCAL_2 // Push the value of the local variable with index 2 GET_LOCAL_3 // Push the value of the local variable with index 3 GET_LOCAL_4 // Push the value of the local variable with index 4 GET_LOCAL8 // Push the value of the local variable with the given index onto the stack (8 bit operand) GET_LOCAL16 // Push the value of the local variable with the given index onto the stack (16 bit operand) BOX_LOCAL8 // Create a box that points to the local with the given index and push it onto the stack (8 bit operand) BOX_LOCAL16 // Create a box that points to the local with the given index and push it onto the stack (16 bit operand) JUMP_UNLESS_LE // Jump n bytes forward if the the value on the stack is not less than or equal to the second value JUMP_UNLESS_LT // Jump n bytes forward if the the value on the stack is not less than the second value JUMP_UNLESS_GE // Jump n bytes forward if the the value on the stack is not greater than or equal to the second value JUMP_UNLESS_GT // Jump n bytes forward if the the value on the stack is not greater than the second value JUMP_UNLESS_EQ // Jump n bytes forward if the the value on the stack is not equal to the second value JUMP_UNLESS_ILE // Jump n bytes forward if the the Int on the stack is not less than or equal to the second value JUMP_UNLESS_ILT // Jump n bytes forward if the the Int on the stack is not less than the second value JUMP_UNLESS_IGE // Jump n bytes forward if the the Int on the stack is not greater than or equal to the second value JUMP_UNLESS_IGT // Jump n bytes forward if the the Int on the stack is not greater than the second value JUMP_UNLESS_IEQ // Jump n bytes forward if the the Int on the stack is not equal to the second value JUMP_UNLESS_NIL // Jump n bytes forward if the value on the stack is not nil JUMP_UNLESS_NNP // Jump n bytes forward if the value on the stack is not nil, does not pop the value JUMP_UNLESS_UNP // Jump n bytes forward unless the value on the stack is undefined, does not pop the value JUMP_UNLESS_UNDEF // Jump n bytes forward unless the value on the stack is undefined JUMP_UNLESS // Jump n bytes forward if the value on the stack is falsy JUMP_UNLESS_NP // Jump n bytes forward if the value on the stack is falsy, does not pop the value JUMP // Jump n bytes forward JUMP_IF // Jump n bytes forward if the value on the stack is truthy JUMP_IF_NP // Jump n bytes forward if the value on the stack is truthy, does not pop the value JUMP_IF_IEQ // Jump n bytes forward if the the Int on the stack is equal to the second value JUMP_IF_EQ // Jump n bytes forward if the the value on the stack is equal to the second value LOOP // Jump n bytes backward JUMP_IF_NIL // Jump n bytes forward if the value on the stack is nil JUMP_IF_NIL_NP // Jump n bytes forward if the value on the stack is nil, does not pop the value RBITSHIFT // Take two values from the stack, perform a right bitshift and push the result RBITSHIFT_INT // Take an Int and another value from the stack, perform a right bitshift and push the result LOGIC_RBITSHIFT // Take two values from the stack, perform a logical right bitshift and push the result LBITSHIFT // Take two values from the stack, perform a left bitshift and push the result LBITSHIFT_INT // Take an Int and another value from the stack, perform a left bitshift and push the result LOGIC_LBITSHIFT // Take two values from the stack, perform a logical left bitshift and push the result BITWISE_AND // Take two values from the stack, perform a bitwise AND and push the result BITWISE_AND_INT // Take an Int and another value from the stack, perform a bitwise AND and push the result BITWISE_OR // Take two values from the stack, perform a bitwise OR and push the result BITWISE_OR_INT // Take an Int and another value from the stack, perform a bitwise OR and push the result BITWISE_XOR // Take two values from the stack, perform a bitwise XOR and push the result BITWISE_XOR_INT // Take an Int and another value from the stack, perform a bitwise XOR and push the result MODULO // Take two values from the stack, perform modulo and push the result MODULO_INT // Take an Int and another value from the stack, perform modulo and push the result MODULO_FLOAT // Take a Float and another value from the stack, perform modulo and push the result EQUAL // Take two values from the stack, check if they're equal and push the result EQUAL_INT // Take an Int and another value from the stack, check if they're equal and push the result EQUAL_FLOAT // Take a Float and another value from the stack, check if they're equal and push the result STRICT_EQUAL // Take two values from the stack, check if they're strictly equal and push the result GREATER // Take two values from the stack, check if the first value is greater than the second and push the result GREATER_INT // Take an Int and another value from the stack, check if the first value is greater than the second and push the result GREATER_FLOAT // Take a Float and another value from the stack, check if the first value is greater than the second and push the result GREATER_EQUAL // Take two values from the stack, check if the first value is greater than or equal to the second and push the result GREATER_EQUAL_I // Take an Int and another value from the stack, check if the first value is greater than or equal to the second and push the result GREATER_EQUAL_F // Take a Float and another value from the stack, check if the first value is greater than or equal to the second and push the result LESS // Take two values from the stack, check if the first value is less than the second and push the result LESS_INT // Take an Int and another value from the stack, check if the first value is less than the second and push the result LESS_FLOAT // Take a Float and another value from the stack, check if the first value is less than the second and push the result LESS_EQUAL // Take two values from the stack, check if the first value is less than or equal to the second and push the result LESS_EQUAL_INT // Take an Int and another value from the stack, check if the first value is less than or equal to the second and push the result LESS_EQUAL_FLOAT // Take a Float and another value from the stack, check if the first value is less than or equal to the second and push the result NOT_EQUAL // Take two values from the stack, check if they're not equal and push the result NOT_EQUAL_INT // Take an Int and another value from the stack, check if they're not equal and push the result NOT_EQUAL_FLOAT // Take a Float and another value from the stack, check if they're not equal and push the result STRICT_NOT_EQUAL // Take two values from the stack, check if they're strictly not equal and push the result INIT_NAMESPACE // Initialise a namespace SELF // Push `self` onto the stack DEF_METHOD // Define a new method UNDEFINED // Push the undefined value onto the stack GET_CLASS // Pop one value off the stack push its class CALL_METHOD_TCO8 // Call a method with an explicit receiver with tail call optimisation eg. `foo.bar(2)` (8 bit operand) CALL_METHOD_TCO16 // Call a method with an explicit receiver with tail call optimisation eg. `foo.bar(2)` (16 bit operand) CALL_METHOD8 // Call a method with an explicit receiver eg. `foo.bar(2)` (8 bit operand) CALL_METHOD16 // Call a method with an explicit receiver eg. `foo.bar(2)` (16 bit operand) CALL_SELF_TCO8 // Call a method with an implicit receiver with tail call optimisation eg. `bar(2)` (8 bit operand) CALL_SELF_TCO16 // Call a method with an implicit receiver with tail call optimisation eg. `bar(2)` (16 bit operand) CALL_SELF8 // Call a method with an implicit receiver eg. `bar(2)` (8 bit operand) CALL_SELF16 // Call a method with an implicit receiver eg. `bar(2)` (16 bit operand) CALL8 // Call the `call` method with an explicit receiver eg. `foo.call(2)` (8 bit operand) CALL16 // Call the `call` method with an explicit receiver eg. `foo.call(2)` (16 bit operand) INCLUDE // Include a mixin in a class/mixin GET_SINGLETON // Pop one value off the stack push its singleton class COMPARE // Pop two values, compare them using `<=>` and push the result DOC_COMMENT // Attach a doc comment to an Elk object DEF_GETTER // Define a getter method DEF_SETTER // Define a setter method RETURN_FIRST_ARG // Push the first given argument (constant container for modules, classes etc) and return INSTANTIATE8 // Create a new instance of a class (8 bit operand) INSTANTIATE16 // Create a new instance of a class (16 bit operand) RETURN_SELF // Push self and return GET_IVAR_0 // Get the value of an instance variable with index 0 GET_IVAR_1 // Get the value of an instance variable with index 1 GET_IVAR_2 // Get the value of an instance variable with index 2 GET_IVAR8 // Get the value of an instance variable (8 bit operand) GET_IVAR16 // Get the value of an instance variable (16 bit operand) GET_IVAR_NAME16 // Get the value of an instance variable by name (16 bit operand) SET_IVAR_0 // Set the value of an instance variable with index 0 SET_IVAR_1 // Set the value of an instance variable with index 1 SET_IVAR_2 // Set the value of an instance variable with index 2 SET_IVAR8 // Set the value of an instance variable (8 bit operand) SET_IVAR16 // Set the value of an instance variable (16 bit operand) SET_IVAR_NAME16 // Set the value of an instance variable by name (16 bit operand) NEW_ARRAY_TUPLE8 // Create a new arrayTuple (8 bit operand) NEW_ARRAY_TUPLE16 // Create a new arrayTuple (16 bit operand) APPEND // Append an element to a list or arrayTuple, pops the element and leaves the collection on the stack COPY // Create a copy of the value on top of the stack and replace it on the stack. SUBSCRIPT // Pops 2 values off the stack. Get the element in a ArrayList, ArrayTuple or HashMap under the given key. SUBSCRIPT_SET // Pops 3 values off the stack. Set the element in a ArrayList, ArrayTuple or HashMap under the given key. APPEND_AT // Set an element at the given index in the ArrayTuple or ArrayList, if the index is out of range, expand the collection, filling the empty slots with `nil` NEW_ARRAY_LIST8 // Create a new list (8 bit operand) NEW_ARRAY_LIST16 // Create a new list (16 bit operand) GET_ITERATOR // Get the iterator of the value on top of the stack. FOR_IN_BUILTIN // Drives the for..in loop, for builtin iterable types FOR_IN // Drives the for..in loop NEXT8 // Call the `next` method on a builtin iterator type (8 bit operand) NEXT16 // Call the `next` method on a builtin iterator type (16 bit operand) NEW_STRING8 // Create a new string (8 bit operand) NEW_STRING16 // Create a new string (16 bit operand) NEW_HASH_MAP8 // Create a new hashmap (8 bit operand) NEW_HASH_MAP16 // Create a new hashmap (16 bit operand) MAP_SET // Set a value under the given key in a hash record or hashmap, pops the key and value and leaves the collection on the stack NEW_HASH_RECORD8 // Create a new hash record (8 bit operand) NEW_HASH_RECORD16 // Create a new hash record (16 bit operand) LAX_EQUAL // Take two values from the stack, check if they are equal and push the result LAX_NOT_EQUAL // Take two values from the stack, check if they are not equal and push the result NEW_REGEX8 // Create a new regex (8 bit operand) NEW_REGEX16 // Create a new regex (16 bit operand) BITWISE_AND_NOT // Take two values from the stack, perform a bitwise AND NOT and push the result UNARY_PLUS // Perform unary plus on the value on top of the stack like `+a` INCREMENT // Increment the value on top of the stack INCREMENT_INT // Increment the Int on top of the stack DECREMENT // Decrement the value on top of the stack DECREMENT_INT // Decrement the Int on top of the stack DUP // Duplicate the value on top of the stack DUP_2 // Duplicate the top 2 values on top of the stack DUP_SECOND // Duplicate the second value on the stack (from the top) POP_2_SKIP_ONE // Pop the top 2 values on top of the stack skipping the first one NEW_SYMBOL8 // Create a new symbol (8 bit operand) NEW_SYMBOL16 // Create a new symbol (16 bit operand) SWAP // Swap the top two values on the stack NEW_RANGE // Create a new range SET_SUPERCLASS // Sets the superclass/parent of a class AS // Throw an error if the second value on the stack is not an instance of the class/mixin on top of the stack MUST // Throw an error if the value on top of the stack is `nil` INSTANCE_OF // Pop two values of the stack, check whether one is an instance of the other IS_A // Pop two values of the stack, check whether one is an instance of the subclass of the other POP_SKIP_ONE // Pop the value on top of the stack skipping the first one INSPECT_STACK // Prints the stack, for debugging NEW_HASH_SET8 // Create a new hashset (8 bit operand) NEW_HASH_SET16 // Create a new hashset (16 bit operand) THROW // Throw a value/error RETHROW // Rethrow a value/error RETURN_FINALLY // Execute all finally blocks this line is nested in and return from the current frame JUMP_TO_FINALLY // Jump to the specified instruction after executing finally blocks CLOSURE // Wrap the function on top of the stack in a closure CLOSED_CLOSURE // Wrap the function on top of the stack in a closed closure (all upvalues are detached and closed) SET_UPVALUE_0 // Assign the value on top of the stack to the upvalue with index 0 SET_UPVALUE_1 // Assign the value on top of the stack to the upvalue with index 1 SET_UPVALUE8 // Assign the value on top of the stack to the upvalue with the given index (8 bit operand) SET_UPVALUE16 // Assign the value on top of the stack to the upvalue with the given index (16 bit operand) GET_UPVALUE_0 // Push the value of the upvalue with index 0 GET_UPVALUE_1 // Push the value of the upvalue with index 1 GET_UPVALUE8 // Push the value of the upvalue with the given index onto the stack (8 bit operand) GET_UPVALUE16 // Push the value of the upvalue with the given index onto the stack (16 bit operand) CLOSE_UPVALUES_TO_1 // Close upvalues down to index 1 CLOSE_UPVALUES_TO_2 // Close upvalues down to index 2 CLOSE_UPVALUES_TO_3 // Close upvalues down to index 3 CLOSE_UPVALUES_TO8 // Close upvalues down to the given index, moving them from the stack to the heap (8 bit operand) CLOSE_UPVALUES_TO16 // Close upvalues down to the given index, moving them from the stack to the heap (16 bit operand) DEF_NAMESPACE // Define a new namespace GET_CONST8 // Get the value of the constant with the name stored under the given index in the value pool (8 bit operand) GET_CONST16 // Get the value of the constant with the name stored under the given index in the value pool (16 bit operand) DEF_CONST // Define a new constant EXEC // Execute a chunk of bytecode INT_M1 // Push -1 onto the stack INT_0 // Push 0 onto the stack INT_1 // Push 1 onto the stack INT_2 // Push 2 onto the stack INT_3 // Push 3 onto the stack INT_4 // Push 4 onto the stack INT_5 // Push 5 onto the stack LOAD_INT_8 // Push an 8 bit Int onto the stack LOAD_INT_16 // Push a 16 bit Int onto the stack LOAD_INT64_8 // Push an 8 bit Int64 onto the stack LOAD_UINT64_8 // Push an 8 bit UInt64 onto the stack LOAD_INT32_8 // Push an 8 bit Int32 onto the stack LOAD_UINT32_8 // Push an 8 bit UInt32 onto the stack LOAD_INT16_8 // Push an 8 bit Int16 onto the stack LOAD_UINT16_8 // Push an 8 bit UInt16 onto the stack LOAD_INT8 // Push an Int8 onto the stack LOAD_UINT8 // Push a UInt8 onto the stack LOAD_CHAR_8 // Push an 8 bit Char onto the stack FLOAT_0 // Push 0.0 onto the stack FLOAT_1 // Push 1.0 onto the stack FLOAT_2 // Push 2.0 onto the stack GENERATOR // Create a new generator from the current function and push it onto the stack YIELD // Yield a value from a generator STOP_ITERATION // Throw `:stop_iteration` in a generator GO // Start a new thread PROMISE // Create a new promise from the current function and push it onto the stack AWAIT // Await the promise on top of the stack AWAIT_RESULT // Handle the result of an awaited promise AWAIT_SYNC // Await the promise on top of the stack synchronously DEF_IVARS // Define instance variables in a class )
Click to show internal directories.
Click to hide internal directories.