vm

package
v0.4.22 Latest Latest
Warning

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

Go to latest
Published: Mar 18, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

pkg/vm/closure.go

pkg/vm/frame.go

pkg/vm/instructions.go Instruction decoder for register-based VM

pkg/vm/module.go Module loading functionality for the VM.

pkg/vm/reg_frame.go

pkg/vm/reg_vm.go Register-based Virtual Machine implementation

pkg/vm/runcode.go Support for dynamic code execution via runCode builtin

pkg/vm/stack.go

pkg/vm/value.go NaN Boxing implementation for efficient value representation

NaN boxing uses the IEEE 754 NaN representation to encode multiple types in a single 64-bit value without heap allocation.

Memory layout: - Floats: stored as native IEEE 754 double (no NaN boxing needed) - Integers: stored in NaN payload (48 bits) - Booleans: stored in NaN payload - Null: special NaN value - Objects: stored as pointer in NaN payload

IMPORTANT: For boxed objects, we maintain a global registry to ensure GC visibility. The Value stores an index into this registry.

pkg/vm/value_frame.go Value-based frame for zero-allocation local variable access

pkg/vm/value_ops.go Value-based execution methods for hot path optimization These methods work directly with Value type, avoiding heap allocation

pkg/vm/value_stack.go Value-based stack implementation optimized for NaN-boxed values

pkg/vm/value_vm.go Value-optimized VM execution for hot paths

pkg/vm/vm.go

Index

Constants

View Source
const (
	GlobalsSize = 65536
	MaxFrames   = 1024
)

Constants

View Source
const InlineCacheSize = 256

InlineCacheSize is the size of the method cache

View Source
const StackSize = 2048

StackSize is the maximum number of elements on the stack

View Source
const ValueStackSize = 2048

ValueStackSize is the maximum number of elements on the stack

Variables

View Source
var (
	ValueNull  = Value(tagNullValue)
	ValueTrue  = Value(tagBoolValue | 1)
	ValueFalse = Value(tagBoolValue)
)

Special values - pre-computed for fast access

Functions

func ClearRegistry added in v0.4.22

func ClearRegistry()

ClearRegistry clears the global object registry This should be called when starting a new execution context

func DecodeBuiltin added in v0.4.21

func DecodeBuiltin(code []byte, ip int) (builtinIdx byte, numArgs byte)

DecodeBuiltin decodes a builtin call instruction

func DecodeCall added in v0.4.21

func DecodeCall(code []byte, ip int) (funcReg byte, numArgs byte)

DecodeCall decodes a call instruction

func DecodeClosure added in v0.4.21

func DecodeClosure(code []byte, ip int) (dstReg byte, funcIdx int, numFree byte)

DecodeClosure decodes a closure creation instruction

func DecodeConst added in v0.4.21

func DecodeConst(code []byte, ip int) (reg byte, constIdx int)

DecodeConst decodes an instruction with register and constant index

func DecodeField added in v0.4.21

func DecodeField(code []byte, ip int) (reg byte, objReg byte, nameIdx int)

DecodeField decodes a field access instruction

func DecodeJump added in v0.4.21

func DecodeJump(code []byte, ip int) (offset int)

DecodeJump decodes a jump instruction with signed 16-bit offset

func DecodeJumpCond added in v0.4.21

func DecodeJumpCond(code []byte, ip int) (condReg byte, offset int)

DecodeJumpCond decodes a conditional jump instruction with signed 16-bit offset

func DecodeMethodCall added in v0.4.21

func DecodeMethodCall(code []byte, ip int) (objReg byte, nameIdx int, numArgs byte)

DecodeMethodCall decodes a method call instruction

func DecodeReg1 added in v0.4.21

func DecodeReg1(code []byte, ip int) (reg byte)

DecodeReg1 decodes a 1-operand register instruction: reg

func DecodeReg2 added in v0.4.21

func DecodeReg2(code []byte, ip int) (dst, src byte)

DecodeReg2 decodes a 2-operand register instruction: dst, src

func DecodeReg3 added in v0.4.21

func DecodeReg3(code []byte, ip int) (dst, src1, src2 byte)

DecodeReg3 decodes a 3-operand register instruction: dst, src1, src2

func ExecuteRunCode added in v0.4.19

func ExecuteRunCode(code string, args *objects.Map) (objects.Object, error)

ExecuteRunCode is called by the runCode builtin

func InstructionLen added in v0.4.21

func InstructionLen(op compiler.Opcode) int

InstructionLen returns the length of an instruction in bytes

func IsRegisterOpcode added in v0.4.21

func IsRegisterOpcode(op compiler.Opcode) bool

IsRegisterOpcode checks if an opcode is a register-based operation

func RegistryStats added in v0.4.22

func RegistryStats() (total, used int)

RegistryStats returns statistics about the object registry

func RunCodeInRegVM added in v0.4.21

func RunCodeInRegVM(code string, args *objects.Map, regVM *RegVM) (objects.Object, error)

RunCodeInRegVM executes code in the register VM context

func RunCodeInVM added in v0.4.19

func RunCodeInVM(code string, args *objects.Map, vm *VM) (objects.Object, error)

RunCodeInVM executes code in the context of the given VM

func SetRunCodeCallback added in v0.4.19

func SetRunCodeCallback(fn RunCodeFunc)

SetRunCodeCallback registers the callback for runCode builtin

Types

type Closure

type Closure struct {
	Fn        *compiler.CompiledFunction
	FreeVars  []objects.Object // Free variables for stack VM
	Constants []objects.Object // Constants from the creating VM
	Globals   []objects.Object // Globals from the creating module (for exported functions)

	// FreeVarsValues is used by register VM for shared mutable free variables
	// When set, register VM uses this instead of FreeVars
	FreeVarsValues []Value
}

Closure represents a function with captured variables

func (*Closure) HashKey

func (c *Closure) HashKey() objects.HashKey

HashKey returns the hash key

func (*Closure) Inspect

func (c *Closure) Inspect() string

Inspect returns a string representation

func (*Closure) ToBool

func (c *Closure) ToBool() *objects.Bool

ToBool returns the boolean value

func (*Closure) Type

func (c *Closure) Type() objects.ObjectType

Type returns the object type

func (*Closure) TypeTag

func (c *Closure) TypeTag() objects.TypeTag

TypeTag returns the type tag for fast type checking

type ExceptionHandler added in v0.4.19

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

ExceptionHandler represents a try-catch-finally handler

type Frame

type Frame struct {
	Fn          *compiler.CompiledFunction
	IP          int              // Instruction pointer (index into Instructions)
	BasePointer int              // Stack base pointer for this frame
	Locals      []objects.Object // Local variables
	FreeVars    []objects.Object // Free variables (captured from closure)
	Constants   []objects.Object // Constants for this frame (from closure or VM)
	Globals     []objects.Object // Globals for this frame (from closure's module or VM)
	This        objects.Object   // 'this' for method calls
}

Frame represents a call frame for function execution

func FrameFromValueFrame added in v0.4.21

func FrameFromValueFrame(vf *ValueFrame) *Frame

FrameFromValueFrame converts a ValueFrame to a regular Frame Used when falling back to Object-based execution

func NewFrame

func NewFrame(fn *compiler.CompiledFunction, basePointer int) *Frame

NewFrame creates a new call frame

func (*Frame) Instructions

func (f *Frame) Instructions() []byte

Instructions returns the compiled function's instructions

func (*Frame) Release

func (f *Frame) Release()

Release returns the frame to the pool for reuse

type InlineCacheEntry

type InlineCacheEntry struct {
	Class  *objects.Class
	Method objects.Object
}

InlineCacheEntry represents a cached method lookup

type InstructionInfo added in v0.4.21

type InstructionInfo struct {
	Opcode   compiler.Opcode
	Dst      byte
	Src1     byte
	Src2     byte
	ConstIdx int
	Offset   int
	NumArgs  byte
}

InstructionInfo holds decoded instruction information

func DecodeInstruction added in v0.4.21

func DecodeInstruction(code []byte, ip int) (InstructionInfo, int)

DecodeInstruction decodes a single instruction from bytecode Returns the instruction info and the number of bytes consumed

type RegFrame added in v0.4.21

type RegFrame struct {
	Fn        *compiler.CompiledFunction
	IP        int                          // Instruction pointer
	Registers [compiler.NumRegisters]Value // Fixed-size register array
	FreeVars  []Value                      // Closure free variables
	Constants []Value                      // Constants for this frame
	Globals   []Value                      // Global variables reference
	This      Value                        // 'this' for method calls
	Locals    []Value                      // Local variables (for spilled values)
}

RegFrame represents a call frame for the register-based VM Each frame has 256 fixed registers (R0-R255)

func NewRegFrame added in v0.4.21

func NewRegFrame(fn *compiler.CompiledFunction) *RegFrame

NewRegFrame creates a new register-based call frame

func (*RegFrame) ClearArgRegisters added in v0.4.21

func (f *RegFrame) ClearArgRegisters()

ClearArgRegisters clears the argument registers

func (*RegFrame) CopyArgRegisters added in v0.4.21

func (f *RegFrame) CopyArgRegisters(src *RegFrame, numArgs int)

CopyArgRegisters copies argument values from source frame's return registers to this frame's argument registers (R0-R7)

func (*RegFrame) GetConstant added in v0.4.21

func (f *RegFrame) GetConstant(idx int) Value

GetConstant returns a constant value

func (*RegFrame) GetFree added in v0.4.21

func (f *RegFrame) GetFree(idx int) Value

GetFree returns a free variable value

func (*RegFrame) GetGlobal added in v0.4.21

func (f *RegFrame) GetGlobal(idx int) Value

GetGlobal returns a global variable value

func (*RegFrame) GetLocal added in v0.4.21

func (f *RegFrame) GetLocal(idx int) Value

GetLocal returns a local variable value

func (*RegFrame) GetReg added in v0.4.21

func (f *RegFrame) GetReg(reg int) Value

GetReg returns the value in a register

func (*RegFrame) Instructions added in v0.4.21

func (f *RegFrame) Instructions() []byte

Instructions returns the compiled function's instructions

func (*RegFrame) Release added in v0.4.21

func (f *RegFrame) Release()

Release returns the frame to the pool for reuse

func (*RegFrame) SetFree added in v0.4.21

func (f *RegFrame) SetFree(idx int, val Value)

SetFree sets a free variable value

func (*RegFrame) SetGlobal added in v0.4.21

func (f *RegFrame) SetGlobal(idx int, val Value)

SetGlobal sets a global variable value

func (*RegFrame) SetLocal added in v0.4.21

func (f *RegFrame) SetLocal(idx int, val Value)

SetLocal sets a local variable value

func (*RegFrame) SetReg added in v0.4.21

func (f *RegFrame) SetReg(reg int, val Value)

SetReg sets the value in a register

type RegVM added in v0.4.21

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

RegVM is a register-based virtual machine

func NewRegVM added in v0.4.21

func NewRegVM(bytecode *compiler.Bytecode) *RegVM

NewRegVM creates a new register-based VM

func NewRegVMWithGlobals added in v0.4.21

func NewRegVMWithGlobals(bytecode *compiler.Bytecode, globals []Value) *RegVM

NewRegVMWithGlobals creates a register VM with custom globals

func NewRegVMWithObjectGlobals added in v0.4.21

func NewRegVMWithObjectGlobals(bytecode *compiler.Bytecode, globals []objects.Object) *RegVM

NewRegVMWithObjectGlobals creates a register VM with globals as objects.Object

func (*RegVM) GetCallStack added in v0.4.21

func (vm *RegVM) GetCallStack() string

GetCallStack returns the current call stack

func (*RegVM) Globals added in v0.4.21

func (vm *RegVM) Globals() []Value

Globals returns the globals array

func (*RegVM) GlobalsAsObjects added in v0.4.21

func (vm *RegVM) GlobalsAsObjects() []objects.Object

GlobalsAsObjects returns the globals as objects.Object slice

func (*RegVM) LastPopped added in v0.4.21

func (vm *RegVM) LastPopped() Value

LastPopped returns the last popped value from temp stack Note: For register VM, prefer LastResult() which returns from ReturnRegister

func (*RegVM) LastPoppedObject added in v0.4.21

func (vm *RegVM) LastPoppedObject() objects.Object

LastPoppedObject returns the result as objects.Object For register VM, this returns the value from ReturnRegister

func (*RegVM) LastResult added in v0.4.21

func (vm *RegVM) LastResult() Value

LastResult returns the value in the ReturnRegister This is the preferred method for getting results from the register VM

func (*RegVM) Run added in v0.4.21

func (vm *RegVM) Run() error

Run executes the bytecode in the register VM

func (*RegVM) SetCurrentModule added in v0.4.21

func (vm *RegVM) SetCurrentModule(mod *objects.Module)

SetCurrentModule sets the current module context

func (*RegVM) SetLoader added in v0.4.21

func (vm *RegVM) SetLoader(loader *module.Loader)

SetLoader sets the module loader

func (*RegVM) SetSourcePath added in v0.4.21

func (vm *RegVM) SetSourcePath(path string)

SetSourcePath sets the source file path

func (*RegVM) StackTop added in v0.4.21

func (vm *RegVM) StackTop() Value

StackTop returns the top of the temp stack

type RunCodeFunc added in v0.4.19

type RunCodeFunc func(code string, args *objects.Map) (objects.Object, error)

RunCodeFunc is the signature for the runCode callback

func GetRunCodeCallback added in v0.4.19

func GetRunCodeCallback() RunCodeFunc

GetRunCodeCallback returns the current callback

type Stack

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

Stack represents the VM operand stack

func NewStack

func NewStack() *Stack

NewStack creates a new stack with the default size

func (*Stack) LastPopped

func (s *Stack) LastPopped() objects.Object

LastPopped returns the last popped element

func (*Stack) Len

func (s *Stack) Len() int

Len returns the number of elements on the stack

func (*Stack) Peek

func (s *Stack) Peek(n int) objects.Object

Peek returns the n-th element from the top (0 = top, 1 = second from top, etc.)

func (*Stack) Pop

func (s *Stack) Pop() objects.Object

Pop pops an object from the stack Optimized: skip nil check when stack is known to be non-empty

func (*Stack) PopSkipGC

func (s *Stack) PopSkipGC() objects.Object

PopSkipGC pops an object without clearing the reference (faster, but may delay GC)

func (*Stack) Push

func (s *Stack) Push(obj objects.Object) error

Push pushes an object onto the stack Optimized: bounds check only when near limit

func (*Stack) SetTop

func (s *Stack) SetTop(obj objects.Object)

SetTop sets the top element without changing stack pointer

func (*Stack) Top

func (s *Stack) Top() objects.Object

Top returns the top element without removing it

type VM

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

VM is the virtual machine that executes bytecode

func New

func New(bytecode *compiler.Bytecode) *VM

New creates a new VM with the given bytecode

func NewWithGlobalsStore

func NewWithGlobalsStore(bytecode *compiler.Bytecode, globals []objects.Object) *VM

NewWithGlobalsStore creates a new VM with a custom globals store

func (*VM) ExecuteValueOp added in v0.4.21

func (vm *VM) ExecuteValueOp(op compiler.Opcode) (bool, error)

ExecuteValueOp executes a Value-based opcode Returns true if the opcode was handled, false to fall back to Object path

func (*VM) GetCallStack

func (vm *VM) GetCallStack() string

GetCallStack returns the current call stack as a formatted string

func (*VM) Globals

func (vm *VM) Globals() []objects.Object

Globals returns the globals array

func (*VM) LastPopped

func (vm *VM) LastPopped() objects.Object

LastPopped returns the last popped element from the stack

func (*VM) Run

func (vm *VM) Run() error

Run executes the bytecode Optimized: caches frame pointer in local variable to reduce method calls

func (*VM) SetCurrentModule

func (vm *VM) SetCurrentModule(mod *objects.Module)

SetCurrentModule sets the current module context

func (*VM) SetLoader

func (vm *VM) SetLoader(loader *module.Loader)

SetLoader sets the module loader (for sharing between VMs)

func (*VM) SetSourcePath

func (vm *VM) SetSourcePath(path string)

SetSourcePath sets the source file path for module resolution

func (*VM) StackTop

func (vm *VM) StackTop() objects.Object

StackTop returns the top of the stack

type Value added in v0.4.21

type Value uint64

Value is a NaN-boxed value that can represent multiple types efficiently

func NewBool added in v0.4.21

func NewBool(b bool) Value

NewBool creates a Value from a boolean

func NewFloat added in v0.4.21

func NewFloat(f float64) Value

NewFloat creates a Value from a float64 Normal floats are stored directly as IEEE 754 doubles

func NewInt added in v0.4.21

func NewInt(n int64) Value

NewInt creates a Value from an integer Stores up to 48 bits of integer data

func NewObject added in v0.4.21

func NewObject(obj objects.Object) Value

NewObject creates a Value from an object pointer

func NewValue added in v0.4.21

func NewValue(obj objects.Object) Value

NewValue creates a Value from any object

func ValueBool added in v0.4.21

func ValueBool(b bool) Value

ValueBool creates a Value from a boolean (alias for NewBool)

func (Value) Add added in v0.4.21

func (v Value) Add(other Value) (Value, bool)

Add adds two values

func (Value) Div added in v0.4.21

func (v Value) Div(other Value) (Value, bool)

Div divides two values

func (Value) Equal added in v0.4.21

func (v Value) Equal(other Value) (bool, bool)

Equal compares if v == other

func (Value) EqualValue added in v0.4.21

func (v Value) EqualValue(other Value) Value

EqualValue returns a Value representing equality comparison

func (Value) GetBool added in v0.4.21

func (v Value) GetBool() bool

GetBool extracts the boolean value

func (Value) GetFloat added in v0.4.21

func (v Value) GetFloat() float64

GetFloat extracts the float value

func (Value) GetInt added in v0.4.21

func (v Value) GetInt() int64

GetInt extracts the integer value

func (Value) GetObject added in v0.4.21

func (v Value) GetObject() objects.Object

GetObject extracts the object from the registry

func (Value) Greater added in v0.4.21

func (v Value) Greater(other Value) (bool, bool)

Greater compares if v > other

func (Value) GreaterEqual added in v0.4.21

func (v Value) GreaterEqual(other Value) Value

GreaterEqual compares if v >= other

func (Value) GreaterValue added in v0.4.21

func (v Value) GreaterValue(other Value) Value

GreaterValue returns a Value representing greater than comparison

func (Value) IsBool added in v0.4.21

func (v Value) IsBool() bool

IsBool returns true if the value is a tagged boolean

func (Value) IsFloat added in v0.4.21

func (v Value) IsFloat() bool

IsFloat returns true if the value is a native float

func (Value) IsInt added in v0.4.21

func (v Value) IsInt() bool

IsInt returns true if the value is a tagged integer

func (Value) IsNull added in v0.4.21

func (v Value) IsNull() bool

IsNull returns true if the value is null

func (Value) IsNumber added in v0.4.21

func (v Value) IsNumber() bool

IsNumber returns true if the value is a number (int or float)

func (Value) IsObject added in v0.4.21

func (v Value) IsObject() bool

IsObject returns true if the value is a tagged object pointer

func (Value) IsTruthy added in v0.4.21

func (v Value) IsTruthy() bool

IsTruthy returns true if the value is truthy

func (Value) Less added in v0.4.21

func (v Value) Less(other Value) (bool, bool)

Less compares if v < other

func (Value) LessEqual added in v0.4.21

func (v Value) LessEqual(other Value) Value

LessEqual compares if v <= other

func (Value) LessValue added in v0.4.21

func (v Value) LessValue(other Value) Value

LessValue returns a Value representing less than comparison

func (Value) Mod added in v0.4.21

func (v Value) Mod(other Value) (Value, bool)

Mod computes modulo

func (Value) Mul added in v0.4.21

func (v Value) Mul(other Value) (Value, bool)

Mul multiplies two values

func (Value) Neg added in v0.4.21

func (v Value) Neg() (Value, bool)

Neg negates a value

func (Value) NotEqual added in v0.4.21

func (v Value) NotEqual(other Value) (bool, bool)

NotEqual compares if v != other

func (Value) NotEqualValue added in v0.4.21

func (v Value) NotEqualValue(other Value) Value

NotEqualValue returns a Value representing inequality comparison

func (Value) String added in v0.4.21

func (v Value) String() string

String returns a string representation for debugging

func (Value) Sub added in v0.4.21

func (v Value) Sub(other Value) (Value, bool)

Sub subtracts two values

func (Value) ToFloat added in v0.4.21

func (v Value) ToFloat() (float64, bool)

ToFloat attempts to convert the value to a float

func (Value) ToInt added in v0.4.21

func (v Value) ToInt() (int64, bool)

ToInt attempts to convert the value to an integer

func (Value) ToObject added in v0.4.21

func (v Value) ToObject() objects.Object

ToObject converts a Value back to an objects.Object

type ValueFrame added in v0.4.21

type ValueFrame struct {
	Fn          *compiler.CompiledFunction
	IP          int     // Instruction pointer
	BasePointer int     // Stack base pointer
	Locals      []Value // Value-based local variables
	FreeVars    []Value // Value-based free variables
	Constants   []Value // Value-based constants
	Globals     []objects.Object
	This        objects.Object
}

ValueFrame represents a call frame optimized for Value-based execution Uses Value type for locals to avoid heap allocation for primitives

func NewValueFrame added in v0.4.21

func NewValueFrame(fn *compiler.CompiledFunction, basePointer int) *ValueFrame

NewValueFrame creates a new Value-based call frame

func ValueFrameFromFrame added in v0.4.21

func ValueFrameFromFrame(of *Frame) *ValueFrame

ValueFrameFromFrame converts a regular Frame to a ValueFrame

func (*ValueFrame) GetFreeVar added in v0.4.21

func (f *ValueFrame) GetFreeVar(idx int) Value

GetFreeVar gets a free variable as Value

func (*ValueFrame) GetLocal added in v0.4.21

func (f *ValueFrame) GetLocal(idx int) Value

GetLocal gets a local variable as Value

func (*ValueFrame) Instructions added in v0.4.21

func (f *ValueFrame) Instructions() []byte

Instructions returns the compiled function's instructions

func (*ValueFrame) Release added in v0.4.21

func (f *ValueFrame) Release()

Release returns the frame to the pool

func (*ValueFrame) SetFreeVar added in v0.4.21

func (f *ValueFrame) SetFreeVar(idx int, v Value)

SetFreeVar sets a free variable

func (*ValueFrame) SetLocal added in v0.4.21

func (f *ValueFrame) SetLocal(idx int, v Value)

SetLocal sets a local variable

type ValueStack added in v0.4.21

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

ValueStack represents the VM operand stack using NaN-boxed values

func NewValueStack added in v0.4.21

func NewValueStack() *ValueStack

NewValueStack creates a new value stack

func (*ValueStack) Drop added in v0.4.21

func (s *ValueStack) Drop(n int)

Drop removes n elements from the top

func (*ValueStack) Dup added in v0.4.21

func (s *ValueStack) Dup() error

Dup duplicates the top element

func (*ValueStack) Get added in v0.4.21

func (s *ValueStack) Get(i int) Value

Get returns the value at index i

func (*ValueStack) LastPopped added in v0.4.21

func (s *ValueStack) LastPopped() Value

LastPopped returns the last popped element

func (*ValueStack) Len added in v0.4.21

func (s *ValueStack) Len() int

Len returns the number of elements on the stack

func (*ValueStack) MustPush added in v0.4.21

func (s *ValueStack) MustPush(v Value)

MustPush pushes without error checking (for hot paths)

func (*ValueStack) Peek added in v0.4.21

func (s *ValueStack) Peek(n int) Value

Peek returns the n-th element from the top (0 = top)

func (*ValueStack) Pop added in v0.4.21

func (s *ValueStack) Pop() Value

Pop pops a value from the stack

func (*ValueStack) PopNoClear added in v0.4.21

func (s *ValueStack) PopNoClear() Value

PopNoClear pops without clearing (slightly faster, delays GC)

func (*ValueStack) Push added in v0.4.21

func (s *ValueStack) Push(v Value) error

Push pushes a value onto the stack Inlined in hot paths for performance

func (*ValueStack) Reset added in v0.4.21

func (s *ValueStack) Reset()

Reset clears the stack

func (*ValueStack) Rot3 added in v0.4.21

func (s *ValueStack) Rot3()

Rot3 rotates the top 3 elements: [a, b, c] -> [b, c, a]

func (*ValueStack) Set added in v0.4.21

func (s *ValueStack) Set(i int, v Value)

Set sets the value at index i

func (*ValueStack) SetTop added in v0.4.21

func (s *ValueStack) SetTop(v Value)

SetTop sets the top element

func (*ValueStack) Swap added in v0.4.21

func (s *ValueStack) Swap()

Swap swaps the top two elements

func (*ValueStack) Top added in v0.4.21

func (s *ValueStack) Top() Value

Top returns the top element without removing it

type ValueVM added in v0.4.21

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

ValueVM is a lightweight VM optimized for numeric operations using Value type It's designed for hot loops and arithmetic-heavy code

func NewValueVM added in v0.4.21

func NewValueVM(bytecode *compiler.Bytecode) *ValueVM

NewValueVM creates a Value-optimized VM from compiled bytecode

func (*ValueVM) Result added in v0.4.21

func (vm *ValueVM) Result() Value

Result returns the last value on the stack

func (*ValueVM) ResultObject added in v0.4.21

func (vm *ValueVM) ResultObject() objects.Object

ResultObject returns the result as an Object

func (*ValueVM) Run added in v0.4.21

func (vm *ValueVM) Run() error

Run executes the bytecode

Jump to

Keyboard shortcuts

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