vm

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Mar 10, 2026 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const MaxCallStackDepth = 1024 // Maximum depth of call stack (prevents stack overflow from infinite recursion)
View Source
const MaxStackSize = 1024 * 1024 // 1MB stack

Variables

This section is empty.

Functions

func RunFunction

func RunFunction(fn *types.Function, args []types.Object, globals map[string]types.Object) error

RunFunction executes a function with the given arguments in a new VM This is used for thread execution with isolated state

func RunFunctionInNewVM

func RunFunctionInNewVM(fn *types.Function, args []types.Object, parentVM *VM) error

RunFunctionInNewVM creates a new VM and executes the function with the given arguments This is used for isolated thread execution

Types

type DeferredCall

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

DeferredCall represents a function call to be executed later

type Frame

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

Frame represents a call frame (activation record) for a function execution

func NewFrame

func NewFrame(fn *bytecode.FunctionConstant, basePointer int) *Frame

NewFrame creates a new call frame for a function

func NewFrameFromFunction

func NewFrameFromFunction(fn *types.Function, basePointer int, args []types.Object) *Frame

NewFrameFromFunction creates a new frame from a runtime Function object

func (*Frame) CurrentInstruction

func (f *Frame) CurrentInstruction() byte

CurrentInstruction returns the opcode at the current IP

func (*Frame) Instructions

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

Instructions returns the bytecode instructions of the function

func (*Frame) Name

func (f *Frame) Name() string

Name returns the name of the function

func (*Frame) ReadUint8

func (f *Frame) ReadUint8() uint8

ReadUint8 reads an 8-bit operand from the instruction stream and advances IP

func (*Frame) ReadUint16

func (f *Frame) ReadUint16() uint16

ReadUint16 reads a 16-bit operand from the instruction stream and advances IP

type HTTPResponse

type HTTPResponse struct {
	StatusCode int
	Headers    map[string]string
	Body       string
}

HTTPResponse represents an HTTP response

func (*HTTPResponse) Equals

func (r *HTTPResponse) Equals(other types.Object) bool

func (*HTTPResponse) ToStr

func (r *HTTPResponse) ToStr() string

func (*HTTPResponse) TypeCode

func (r *HTTPResponse) TypeCode() uint8

func (*HTTPResponse) TypeName

func (r *HTTPResponse) TypeName() string

type Module

type Module struct {
	Name    string
	Path    string
	Exports map[string]types.Object // Exported symbols from the module
}

Module represents a loaded Nxlang module

type Stack

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

Stack represents the operand stack used by the VM

func NewStack

func NewStack() *Stack

NewStack creates a new empty stack

func (*Stack) Clear

func (s *Stack) Clear()

Clear removes all elements from the stack

func (*Stack) Peek

func (s *Stack) Peek() types.Object

Peek returns the top element without removing it

func (*Stack) PeekN

func (s *Stack) PeekN(n int) types.Object

PeekN returns the nth element from the top (0 = top) without removing it

func (*Stack) PeekNSafe

func (s *Stack) PeekNSafe(n int) (types.Object, error)

PeekNSafe peeks nth element with error instead of panic

func (*Stack) PeekSafe

func (s *Stack) PeekSafe() (types.Object, error)

PeekSafe peeks element with error instead of panic

func (*Stack) Pop

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

Pop removes and returns the top element from the stack

func (*Stack) PopN

func (s *Stack) PopN(n int) []types.Object

PopN removes and returns the top n elements (in reverse order: top first)

func (*Stack) PopSafe

func (s *Stack) PopSafe() (types.Object, error)

PopSafe pops element with error instead of panic

func (*Stack) Push

func (s *Stack) Push(o types.Object) error

Push adds an element to the top of the stack

func (*Stack) SetSize

func (s *Stack) SetSize(size int)

SetSize sets the stack size to the specified value

func (*Stack) Size

func (s *Stack) Size() int

Size returns the number of elements on the stack

type StackOverflowError

type StackOverflowError struct{}

StackOverflowError is returned when the stack exceeds its maximum size

func (*StackOverflowError) Error

func (e *StackOverflowError) Error() string

type StackUnderflowError

type StackUnderflowError struct{}

StackUnderflowError is returned when trying to pop from an empty stack

func (*StackUnderflowError) Error

func (e *StackUnderflowError) Error() string

type TryFrame

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

TryFrame represents an active try/catch/finally block

type VM

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

VM represents the Nxlang virtual machine

func NewVM

func NewVM(bc *bytecode.Bytecode) *VM

NewVM creates a new virtual machine instance

func (*VM) Constants

func (vm *VM) Constants() []bytecode.Constant

Constants returns the constant pool

func (*VM) CopyGlobals

func (vm *VM) CopyGlobals() map[string]types.Object

CopyGlobals returns a copy of the global variables map

func (*VM) GetModuleExport

func (vm *VM) GetModuleExport(module *Module, exportName string) (types.Object, bool)

GetModuleExport gets an exported value from a module

func (*VM) Globals

func (vm *VM) Globals() map[string]types.Object

Globals returns the global variables map

func (*VM) LoadModule

func (vm *VM) LoadModule(modulePath string) (*Module, error)

LoadModule loads a module by path

func (*VM) NewVMWithSharedGlobals

func (vm *VM) NewVMWithSharedGlobals(parent *VM) *VM

NewVMWithSharedGlobals creates a new VM that shares globals with the parent VM Used for shared mode thread execution

func (*VM) Run

func (vm *VM) Run() error

Run executes the bytecode

func (*VM) RunFunctionShared

func (vm *VM) RunFunctionShared(fn *types.Function, args []types.Object) error

RunFunctionShared executes a function with the given arguments sharing the VM's globals This is used for thread execution with shared state

func (*VM) SetArgs

func (vm *VM) SetArgs(args []string)

SetArgs sets the command-line arguments for the script

func (*VM) SetGlobals

func (vm *VM) SetGlobals(globals map[string]types.Object)

SetGlobals sets the global variables map

func (*VM) Stack

func (vm *VM) Stack() *Stack

Stack returns the operand stack

Jump to

Keyboard shortcuts

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