Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func ReadOperands ¶
func ReadOperands(def *Definition, insns Instructions) (operands []int, offset int)
ReadOperands reads operands from bytecode instructions based on the definition of an opcode. It returns operands read and the offset describing the starting position of next opcode.
func ReadUint16 ¶
func ReadUint16(insns Instructions) uint16
ReadUint16 reads a single uint16 value from bytecode instruction sequence.
func ReadUint8 ¶
func ReadUint8(insns Instructions) uint8
ReadUint8 reads a single uint8 value from bytecode instruction sequence.
Types ¶
type Definition ¶
Definition represents the definition of an opcode.
func Lookup ¶
func Lookup(op byte) (*Definition, error)
Lookup performs a lookup for `op` in the definitions of opcodes.
type Instructions ¶
type Instructions []byte
Instructions represents a sequence of instructions.
func (Instructions) String ¶
func (insns Instructions) String() string
type Opcode ¶
type Opcode byte
Opcode represents an opcode.
const ( // OpConstant is an opcode to push a constant value on to the stack. OpConstant Opcode = iota // OpPop is an opcode to pop the topmost element off the stack. OpPop // OpAdd is an opcode for addition (+). OpAdd // OpSub is an opcode for subtraction (-). OpSub // OpMul is an opcode for multiplication (*). OpMul // OpDiv is an opcode for division (/). OpDiv // OpTrue is an opcode to push `true` value on to the stack. OpTrue // OpFalse is an opcode to push `false` value on to the stack. OpFalse // OpEqual is an opcode to check the equality of the two topmost elements on the stack. OpEqual // OpNotEqual is an opcode to check the inequality of the two topmost elements on the stack. OpNotEqual // OpGreaterThan is an opcode to check the second topmost element is greater than the first. OpGreaterThan // OpGreaterThanOrEqual is an opcode to check the second topmost element is greater than or // equal to the first. OpGreaterThanOrEqual // OpAnd is an opcode for logical AND. OpAnd // OpOr is an opcode for logical OR. OpOr // OpMinus is an opcode to negate integers. OpMinus // OpBang is an opcode to negate booleans. OpBang // OpJumpNotTruthy is an opcode to jump if the condition is not truthy. OpJumpNotTruthy // OpJump is an opcode to jump. OpJump // OpNil is an opcode to push `nil` value on to the stack. OpNil // OpSetGlobal is an opcode to create a global binding. OpSetGlobal // OpGetGlobal is an opcode to retrieve a value of a global binding. OpGetGlobal // OpArray is an opcode to create an array. OpArray // OpHash is an opcode to create a hash map. OpHash // OpSetIndex is an opcode to set a value into the place at the index in an indexed data // structure. OpSetIndex // OpGetIndex is an opcode to get an element at the index from an indexed data structure. OpGetIndex // OpCall is an opcode to call compiled functions. OpCall // OpReturnValue is an opcode to return a value from a function. OpReturnValue // OpReturn is an opcode to return from a function without return value. OpReturn // OpSetLocal is an opcode to create a local binding. OpSetLocal // OpGetLocal is an opcode to retrieve a value of a local binding. OpGetLocal // OpGetBuiltin is an opcode to get a built-in function. OpGetBuiltin // OpClosure is an opcode to create a closure. OpClosure // OpGetFree is an opcode to retrieve a free variable on to the stack. OpGetFree // OpCurrentClosure is an opcode to self-reference the current closure. OpCurrentClosure )
Click to show internal directories.
Click to hide internal directories.