Documentation
¶
Overview ¶
pkg/vm/closure.go
pkg/vm/frame.go
pkg/vm/module.go Module loading functionality for the VM.
pkg/vm/stack.go
pkg/vm/vm.go
Index ¶
- Constants
- type Closure
- type Frame
- type InlineCacheEntry
- type Stack
- func (s *Stack) LastPopped() objects.Object
- func (s *Stack) Len() int
- func (s *Stack) Peek(n int) objects.Object
- func (s *Stack) Pop() objects.Object
- func (s *Stack) PopSkipGC() objects.Object
- func (s *Stack) Push(obj objects.Object) error
- func (s *Stack) SetTop(obj objects.Object)
- func (s *Stack) Top() objects.Object
- type VM
- func (vm *VM) GetCallStack() string
- func (vm *VM) Globals() []objects.Object
- func (vm *VM) LastPopped() objects.Object
- func (vm *VM) Run() error
- func (vm *VM) SetCurrentModule(mod *objects.Module)
- func (vm *VM) SetLoader(loader *module.Loader)
- func (vm *VM) SetSourcePath(path string)
- func (vm *VM) StackTop() objects.Object
Constants ¶
const ( GlobalsSize = 65536 MaxFrames = 1024 )
Constants
const InlineCacheSize = 256
InlineCacheSize is the size of the method cache
const StackSize = 2048
StackSize is the maximum number of elements on the stack
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Closure ¶
type Closure struct {
Fn *compiler.CompiledFunction
FreeVars []objects.Object
Constants []objects.Object // Constants from the creating VM
Globals []objects.Object // Globals from the creating module (for exported functions)
}
Closure represents a function with captured variables
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 NewFrame ¶
func NewFrame(fn *compiler.CompiledFunction, basePointer int) *Frame
NewFrame creates a new call frame
func (*Frame) Instructions ¶
Instructions returns the compiled function's instructions
type InlineCacheEntry ¶
InlineCacheEntry represents a cached method lookup
type Stack ¶
type Stack struct {
// contains filtered or unexported fields
}
Stack represents the VM operand stack
func (*Stack) LastPopped ¶
LastPopped returns the last popped element
func (*Stack) Peek ¶
Peek returns the n-th element from the top (0 = top, 1 = second from top, etc.)
func (*Stack) Pop ¶
Pop pops an object from the stack Optimized: skip nil check when stack is known to be non-empty
func (*Stack) PopSkipGC ¶
PopSkipGC pops an object without clearing the reference (faster, but may delay GC)
func (*Stack) Push ¶
Push pushes an object onto the stack Optimized: bounds check only when near limit
type VM ¶
type VM struct {
// contains filtered or unexported fields
}
VM is the virtual machine that executes bytecode
func NewWithGlobalsStore ¶
NewWithGlobalsStore creates a new VM with a custom globals store
func (*VM) GetCallStack ¶
GetCallStack returns the current call stack as a formatted string
func (*VM) LastPopped ¶
LastPopped returns the last popped element from the stack
func (*VM) Run ¶
Run executes the bytecode Optimized: caches frame pointer in local variable to reduce method calls
func (*VM) SetCurrentModule ¶
SetCurrentModule sets the current module context
func (*VM) SetSourcePath ¶
SetSourcePath sets the source file path for module resolution