Documentation ¶
Overview ¶
Package op implements all the operation codes that can be created during compilation and used to drive what to execute during run time within the VM. Provide within the package are the abilities to know how many operands each op code has and their widths aiding in the reading of a given set of instructions that have been created from compilation
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Make ¶
Make allows a Code and it's operands to be converted into a slice of bytes which is to be used to represent them as an instruction
func ReadOperands ¶
func ReadOperands(def *Definition, ins Instructions) ([]int, int)
ReadOperands gives back the operands set against a given op code within the instructions. It requires the definition in order to know the operand widths of each operand. Not only does the function return the operands but the offset after all operands for a given op code has been read. This offset helps assist with knowing how far the instructions has been read to which can be utilise to move forward something like instruction pointers
Types ¶
type Code ¶
type Code byte
Code is the main representation of the P code used in lemur
const ( Constant Code = iota Add Sub Mul Div Pop Minus True False Equal NotEqual GreaterThan GreaterThanEqual And Or Bang Jump JumpBreak JumpNotTruthy JumpTable Null SetGlobal GetGlobal GetLocal SetLocal GetFree AssignGlobal AssignLocal Array Map Index Closure CurrentClosure Return ReturnValue Call GetBuiltin IteratorCurrentKey PushIteratorPointer PopIteratorPointer IncrementIteratorPointer IteratorLenComparison )
type Definition ¶
Definition encapsulates the name of a P code and it's maximum possible widths for each operand it has available
func Lookup ¶
func Lookup(op byte) (*Definition, error)
Lookup provides a convenient way to obtain the Definition from a Code
type Instructions ¶
type Instructions []byte
Instructions represents each instruction (Code and operands) of a program along with it's position
func (Instructions) String ¶
func (ins Instructions) String() string