code

package
v0.0.0-...-6ec744d Latest Latest
Warning

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

Go to latest
Published: Feb 20, 2021 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Encode

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

Encode produces a raw instruction

func ReadOperands

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

ReadOperands disassembles a single instruction

func ReadUint16

func ReadUint16(ins []byte) uint16

ReadUint16 reads the next two bytes in the instructions as a 16 bit number

Types

type Definition

type Definition struct {
	// The name of the opcode
	Name string
	// The length of the entire instruction
	TotalLength int
	// Lengths of all the operands
	OperandWidths []int
}

Definition defines a single instruction - opcode and operand widths

func Lookup

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

Lookup gets the definition of an Opcode

type Instructions

type Instructions []byte

Instructions = the program

func (Instructions) String

func (ins Instructions) String() string

type Opcode

type Opcode byte

Opcode represents a single instruction carried out by the VM

const (
	// OpPush - retrieves a constant via its operand and pushes it
	OpPush Opcode = iota
	// OpPop - Pops the topmost element off the stack
	OpPop
	// OpAdd - Pops the top two values off the stack, adds them and pushes the result
	OpAdd
	// OpSub - Does the same thing as OpAdd, but performs subtraction
	OpSub
	// OpMul - OpSub but multiplication
	OpMul
	// OpDiv - OpMul but division
	OpDiv
	// OpBWAnd - Bitwise And
	OpBWAnd
	// OpBWOr - Bitwise Or
	OpBWOr
	// OpBWXOR - Bitwise XOR
	OpBWXOR
	// OpBWNOT - Bitwise NOT
	OpBWNOT
	// OpTrue - Pushes true to the stack
	OpTrue
	// OpFalse - Pushes false to the stack
	OpFalse
	// OpEq - Tells the vm to test two objects for equality
	OpEq
	// OpNE - Tells the vm to test for inequality
	OpNE
	// OpGT - Tells the vm to test for greater than
	OpGT
	// OpGE - Tells the vm to test for greater than or equal to
	OpGE
	// OpMinus - For prefix negation
	OpMinus
	// OpBang - For boolean negation
	OpBang
)

Jump to

Keyboard shortcuts

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