Documentation
¶
Index ¶
- Constants
- func Run(ctx context.Context, main *compiler.Code, options ...Option) (object.Object, error)
- type Option
- type VirtualMachine
- func (vm *VirtualMachine) Call(ctx context.Context, functionName string, args []object.Object) (object.Object, error)
- func (vm *VirtualMachine) Get(name string) (object.Object, error)
- func (vm *VirtualMachine) GlobalNames() []string
- func (vm *VirtualMachine) Run(ctx context.Context) (err error)
- func (vm *VirtualMachine) TOS() (object.Object, bool)
Constants ¶
const ( MaxArgs = 255 MaxFrameDepth = 1024 MaxStackDepth = 1024 StopSignal = -1 MB = 1024 * 1024 )
const DefaultFrameLocals = 8
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Option ¶
type Option func(*VirtualMachine)
Option is a configuration function for a Virtual Machine.
func WithGlobals ¶ added in v0.14.0
WithGlobals provides global variables with the given names.
func WithImporter ¶
WithImporter is used to supply an Importer to the Virtual Machine.
func WithInstructionOffset ¶
WithInstructionOffset sets the initial instruction offset.
func WithLimits ¶
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.