vm

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const ErrBadInstruction = "unknown instruction encountered: %s"

ErrBadInstruction is raised when the VM encounters an Opcode that has not been properly mapped

Variables

This section is empty.

Functions

This section is empty.

Types

type Closure

type Closure struct {
	*Procedure
	Captured data.Vector
	// contains filtered or unexported fields
}

func (*Closure) Call

func (c *Closure) Call(args ...data.Value) data.Value

Call turns Closure into a Procedure, and serves as the virtual machine

func (*Closure) CheckArity

func (c *Closure) CheckArity(i int) error

CheckArity performs a compile-time arity check for the Closure

func (*Closure) Equal

func (c *Closure) Equal(other data.Value) bool

func (*Closure) HashCode

func (c *Closure) HashCode() uint64

type Procedure

type Procedure struct {
	Globals      env.Namespace
	Constants    data.Vector
	Code         isa.Instructions
	StackSize    int
	LocalCount   int
	ArityChecker data.ArityChecker
	// contains filtered or unexported fields
}

Procedure encapsulates the initial environment of an abstract machine

func (*Procedure) Call

func (p *Procedure) Call(values ...data.Value) data.Value

Call allows an abstract machine Procedure to be called for the purpose of instantiating a Closure. Only the compiler invokes this calling interface.

func (*Procedure) CheckArity

func (p *Procedure) CheckArity(int) error

CheckArity performs a compile-time arity check for the Procedure

func (*Procedure) Equal

func (p *Procedure) Equal(other data.Value) bool

Equal compares this Procedure to another for equality

func (*Procedure) Get

func (p *Procedure) Get(key data.Value) (data.Value, bool)

func (*Procedure) HashCode

func (p *Procedure) HashCode() uint64

func (*Procedure) Type

func (p *Procedure) Type() types.Type

Type makes Procedure a typed value

type Ref

type Ref struct {
	data.Value
}

Ref encapsulates a reference to a Value

func (*Ref) Equal

func (r *Ref) Equal(other data.Value) bool

type State

type State int
const (
	FAILURE State = iota - 1
	RUNNING
	SUCCESS
)

type VM

type VM struct {
	CL   *Closure
	ST   State
	PC   int
	LP   int
	SP   int
	INST isa.Instruction
	CODE isa.Instructions
	MEM  data.Vector
	ARGS data.Vector
	RES  data.Value
}

func (*VM) Run

func (vm *VM) Run() data.Value

Jump to

Keyboard shortcuts

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