vm

package
v0.14.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 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 Run added in v0.14.0

func Run(ctx context.Context, main *compiler.Code, options ...Option) (object.Object, error)

Run the given code in a new Virtual Machine and return the result.

Types

type Option

type Option func(*VirtualMachine)

Option is a configuration function for a Virtual Machine.

func WithGlobals added in v0.14.0

func WithGlobals(globals map[string]any) Option

WithGlobals provides global variables with the given names.

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 VirtualMachine

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

func New

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

New creates a new Virtual Machine.

func (*VirtualMachine) Call added in v0.14.0

func (vm *VirtualMachine) Call(ctx context.Context, functionName string, args []object.Object) (object.Object, error)

Call a named function with the given arguments. The function is expected to be present in the global scope of the active code. If the function can't be found then an error is returned.

func (*VirtualMachine) Get added in v0.14.0

func (vm *VirtualMachine) Get(name string) (object.Object, error)

Get a global variable by name as a Risor Object. Returns an error if the variable can't be found.

func (*VirtualMachine) GlobalNames added in v0.14.0

func (vm *VirtualMachine) GlobalNames() []string

GlobalNames returns the names of all global variables in the active code.

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