Documentation
¶
Overview ¶
Package vm provides a VirtualMachine that executes compiled Risor code.
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, fn *object.Function, args []object.Object) (object.Object, error)
- func (vm *VirtualMachine) Clone() (*VirtualMachine, 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, fn *object.Function, args []object.Object) (object.Object, error)
Call a function with the supplied arguments. If isolation between VMs is important to you, do not provide a function here that was obtained from another VM, since it could be a closure over variables in that VM. This method should only be called after this VM stops running. Otherwise, an error is returned.
func (*VirtualMachine) Clone ¶ added in v0.15.0
func (vm *VirtualMachine) Clone() (*VirtualMachine, error)
Clone a stopped Virtual Machine. An error is returned if the Virtual Machine is running. The returned clone will have the same code, globals, modules, stack, and limits as the original. Any Risor objects present as global variables will be carried over to the clone. And since multiple clones can be created, the caller is responsible for ensuring that the global variables are not mutated, or that the mutations are safe for concurrent use. Do not use this function if you need isolation between clones, as this is not provided.
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.