vm

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 22, 2023 License: Apache-2.0 Imports: 20 Imported by: 4

Documentation

Index

Constants

View Source
const (
	MaxArgs       = 255
	MaxFrameDepth = 1024
	MaxStackDepth = 1024
	StopSignal    = -1
	MB            = 1024 * 1024
)
View Source
const DefaultFrameLocals = 8

Variables

This section is empty.

Functions

func CompileModule

func CompileModule(ctx context.Context, name, code string, builtins map[string]object.Object) (*object.Module, error)

Types

type Frame

type Frame struct {
	// contains filtered or unexported fields
}

func (*Frame) ActivateCode

func (f *Frame) ActivateCode(code *object.Code)

func (*Frame) ActivateFunction

func (f *Frame) ActivateFunction(fn *object.Function, returnAddr int, localValues []object.Object)

func (*Frame) CaptureLocals

func (f *Frame) CaptureLocals() []object.Object

func (*Frame) Code

func (f *Frame) Code() *object.Code

func (*Frame) Function

func (f *Frame) Function() *object.Function

func (*Frame) Locals

func (f *Frame) Locals() []object.Object

func (*Frame) SetReturnAddr

func (f *Frame) SetReturnAddr(addr int)

type Option

type Option func(*VirtualMachine)

Option is a configuration function for a Virtual Machine.

func WithImporter

func WithImporter(importer importer.Importer) Option

WithImporter is used to supply an Importer to the Virtual Machine.

func WithInstructionOffset

func WithInstructionOffset(offset int) Option

WithInstructionOffset sets the initial instruction offset.

func WithLimits

func WithLimits(limits limits.Limits) Option

WithLimits sets the limits for the Virtual Machine.

type Options

type Options struct {
	Main              *object.Code
	InstructionOffset int
	Importer          importer.Importer
}

type SimpleImporter

type SimpleImporter struct {
	// contains filtered or unexported fields
}

func NewSimpleImporter

func NewSimpleImporter(moduleSource map[string]string, builtins map[string]object.Object) *SimpleImporter

func (*SimpleImporter) Import

func (i *SimpleImporter) Import(ctx context.Context, name string) (*object.Module, error)

type VirtualMachine

type VirtualMachine struct {
	// contains filtered or unexported fields
}

func New

func New(main *object.Code, options ...Option) *VirtualMachine

New creates a new Virtual Machine.

func (*VirtualMachine) Run

func (vm *VirtualMachine) Run(ctx context.Context) (err error)

func (*VirtualMachine) TOS

func (vm *VirtualMachine) TOS() (object.Object, bool)

Jump to

Keyboard shortcuts

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