code

package
v0.0.0-...-21f6697 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	OperandWidth1
	OperandWidth2
)

OperandWidth is the number of bytes an operand takes up

Variables

This section is empty.

Functions

func Make

func Make(op Opcode, operands ...int) []byte

Make creates a single bytecode instruction which includes the Opcode and it's operands

func ReadOperands

func ReadOperands(def *Definition, ins []byte) (operandsRead []int, n uint)

ReadOperands reverses a bytecode instruction and reads its operands. Returning the operands in the instruction and n number of bytes read.

func ReadUint16

func ReadUint16(ins Instructions) uint16

func ReadUint8

func ReadUint8(ins Instructions) uint8

Types

type Definition

type Definition struct {
	// Name of Opcode
	Name string
	// OperandWidths contains the OperandWidth for each operand
	OperandWidths []uint
}

Definition helps make an Opcode readable

func Lookup

func Lookup(op Opcode) (*Definition, error)

type Instructions

type Instructions []byte

func (Instructions) String

func (ins Instructions) String() string

type Opcode

type Opcode byte
const (
	OpConstant Opcode = iota
	OpPop
	OpAdd
	OpSub
	OpMul
	OpDiv
	OpTrue
	OpFalse
	OpEqual
	OpNotEqual
	OpGreaterThan
	OpBang
	OpMinus
	OpJump
	OpJumpNotTruthy
	OpNull
	OpGetGlobal
	OpSetGlobal
	OpArray
	OpHash
	OpIndex
	OpCall
	OpReturn
	OpReturnValue
	OpGetLocal
	OpSetLocal
	OpGetBuiltin
	OpClosure
	OpGetFree
	OpCurrentClosure
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL