code

package
v0.0.0-...-45d7913 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2025 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Make

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

Make returns the instruction given an opcode and it's operands

func ReadOperands

func ReadOperands(def *Definition, ins Instructions) ([]int, int)

func ReadUint16

func ReadUint16(ins Instructions) uint16

ReadUint16 reads the next 2 bytes from the given instructions slice and interprets them as a uint16

Types

type Definition

type Definition struct {
	Name          string
	OperandWidths []int
}

Definition provides a readable name for the Opcode and number of bytes each operand takes up

func Lookup

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

Lookup returns the definition of operation

type Instructions

type Instructions []byte

func (Instructions) String

func (ins Instructions) String() string

Disassembler for Instructions

type Opcode

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

Byte size operation codes with incrementing values

Jump to

Keyboard shortcuts

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