Documentation
¶
Overview ¶
pkg/compiler/compiler.go
pkg/compiler/liveness.go
pkg/compiler/opcode.go
pkg/compiler/optimizer.go Bytecode optimizer for compile-time transformations
pkg/compiler/options.go Configuration options for compiler optimizations
pkg/compiler/reg_compiler.go Register-based bytecode compiler
pkg/compiler/regalloc.go
pkg/compiler/serialize.go Bytecode serialization for saving and loading compiled code.
pkg/compiler/sourcemap.go Source map for mapping bytecode positions to source locations
Index ¶
- Constants
- func GetDefinitions() map[Opcode]*Definition
- func IsRegisterOpcode(op Opcode) bool
- func Make(op Opcode, operands ...int) []byte
- func MakeRegInstruction(op Opcode, dst, src1, src2 int) []byte
- func MakeRegInstruction1(op Opcode, reg int) []byte
- func MakeRegInstruction2(op Opcode, reg1, reg2 int) []byte
- func MakeRegInstructionConst(op Opcode, reg, constIdx int) []byte
- func MakeRegJump(op Opcode, offset int) []byte
- func MakeRegJumpCond(op Opcode, condReg, offset int) []byte
- func ReadOperands(def *Definition, ins []byte) ([]int, int)
- func String(ins []byte) string
- type Bytecode
- type CompilationScope
- type CompiledFunction
- type Compiler
- type Definition
- type EmittedInstruction
- type InlineableFuncInfo
- type LiveInterval
- type LivenessAnalyzer
- type Opcode
- type OptimizationFlags
- type Optimizer
- type RegAllocStats
- type RegAllocator
- func (ra *RegAllocator) AddInterval(v *Symbol, start, end int) *LiveInterval
- func (ra *RegAllocator) Allocate() int
- func (ra *RegAllocator) AllocateTemp() int
- func (ra *RegAllocator) FreeTemp(reg int)
- func (ra *RegAllocator) GetInterval(varName string) *LiveInterval
- func (ra *RegAllocator) GetRegister(varName string) int
- func (ra *RegAllocator) Reset()
- func (ra *RegAllocator) SpillCount() int
- func (ra *RegAllocator) Stats() RegAllocStats
- type RegCompiler
- func (c *RegCompiler) Bytecode() *Bytecode
- func (c *RegCompiler) Compile(node parser.Node) (int, error)
- func (c *RegCompiler) Constants() []objects.Object
- func (c *RegCompiler) DefineGlobal(name string)
- func (c *RegCompiler) ResolveSymbol(name string) (Symbol, bool)
- func (c *RegCompiler) SetConstants(constants []objects.Object)
- func (c *RegCompiler) SetSourceFile(filename string)
- func (c *RegCompiler) SetSymbolTable(st *SymbolTable)
- func (c *RegCompiler) SymbolTable() *SymbolTable
- type SourceLocation
- type SourceMap
- func (sm *SourceMap) Add(offset int, loc SourceLocation)
- func (sm *SourceMap) FormatError(offset int, message string) string
- func (sm *SourceMap) Get(offset int) (SourceLocation, bool)
- func (sm *SourceMap) GetLine(lineNum int) string
- func (sm *SourceMap) Serialize(w io.Writer) error
- func (sm *SourceMap) SetSourceFile(path string, source string)
- type Symbol
- type SymbolScope
- type SymbolTable
Constants ¶
const ( // NumRegisters is the number of registers per frame NumRegisters = 256 // NumArgRegisters is the number of argument registers (R0-R7) NumArgRegisters = 8 // ReturnRegister is the register index for return values ReturnRegister = 255 // FirstLocalRegister is the first register available for local variables // R0-R7 are reserved for arguments FirstLocalRegister = 8 )
const ( MagicHeader = "XXLB" // Xxlang Bytecode CurrentVersion = 1 )
Magic header for bytecode files
const GlobalsSize = 65536
GlobalsSize is the maximum number of global variables
Variables ¶
This section is empty.
Functions ¶
func GetDefinitions ¶ added in v0.4.21
func GetDefinitions() map[Opcode]*Definition
GetDefinitions returns the opcode definitions map
func IsRegisterOpcode ¶ added in v0.4.21
IsRegisterOpcode returns true if the opcode is a register-based operation
func MakeRegInstruction ¶ added in v0.4.21
MakeRegInstruction creates a fixed 4-byte register instruction Format: opcode(1) | dst(1) | src1(1) | src2(1)
func MakeRegInstruction1 ¶ added in v0.4.21
MakeRegInstruction1 creates a register instruction with 1 operand
func MakeRegInstruction2 ¶ added in v0.4.21
MakeRegInstruction2 creates a register instruction with 2 operands
func MakeRegInstructionConst ¶ added in v0.4.21
MakeRegInstructionConst creates a register instruction with a 16-bit constant index Format: opcode(1) | reg(1) | const_idx(2)
func MakeRegJump ¶ added in v0.4.21
MakeRegJump creates a jump instruction with 16-bit offset Format: opcode(1) | unused(1) | offset(2)
func MakeRegJumpCond ¶ added in v0.4.21
MakeRegJumpCond creates a conditional jump instruction Format: opcode(1) | cond_reg(1) | offset(2)
func ReadOperands ¶
func ReadOperands(def *Definition, ins []byte) ([]int, int)
ReadOperands reads operands from bytecode
Types ¶
type Bytecode ¶
type Bytecode struct {
Instructions []byte
Constants []objects.Object
SourceMap *SourceMap // Maps instruction positions to source locations
InlineableGlobals map[int]*InlineableFuncInfo // Global index -> inlineable function info
}
Bytecode represents compiled bytecode
func CompileReg ¶ added in v0.4.21
CompileReg compiles a program using the register-based compiler
func Deserialize ¶
Deserialize decodes binary data to bytecode. Returns the bytecode or an error.
func DeserializeFromFile ¶
DeserializeFromFile reads bytecode from a file.
func (*Bytecode) Serialize ¶
Serialize encodes bytecode to a binary format. Returns the serialized bytes or an error.
func (*Bytecode) SerializeToFile ¶
SerializeToFile writes bytecode to a file. The format is: magic(4) + version(4) + gob-encoded data
type CompilationScope ¶
type CompilationScope struct {
// contains filtered or unexported fields
}
CompilationScope represents a compilation scope
type CompiledFunction ¶
type CompiledFunction struct {
Instructions []byte
NumLocals int
NumParameters int
FreeVariables []Symbol // Free variables captured from outer scope
// Inlining support
IsInlineable bool // True if function body is a single return expression
InlineBody []byte // Inlined bytecode (without return)
}
CompiledFunction represents a compiled function
func (*CompiledFunction) HashKey ¶
func (cf *CompiledFunction) HashKey() objects.HashKey
HashKey returns the hash key
func (*CompiledFunction) Inspect ¶
func (cf *CompiledFunction) Inspect() string
Inspect returns the string representation
func (*CompiledFunction) ToBool ¶
func (cf *CompiledFunction) ToBool() *objects.Bool
ToBool converts to boolean
func (*CompiledFunction) Type ¶
func (cf *CompiledFunction) Type() objects.ObjectType
Type returns the object type
func (*CompiledFunction) TypeTag ¶
func (cf *CompiledFunction) TypeTag() objects.TypeTag
TypeTag returns the type tag for fast type checking
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
Compiler transforms AST into bytecode
func NewWithOptions ¶
func NewWithOptions(opts OptimizationFlags) *Compiler
NewWithOptions creates a new compiler with custom optimization settings
func NewWithState ¶
func NewWithState(s *SymbolTable, constants []objects.Object) *Compiler
NewWithState creates a new compiler with existing state
func (*Compiler) DefineGlobal ¶ added in v0.4.19
DefineGlobal defines a global variable in the symbol table This is used by runCode to pre-define arguments before compilation
func (*Compiler) ResolveSymbol ¶ added in v0.4.19
ResolveSymbol resolves a symbol by name This is used by runCode to find argument indices after compilation
type Definition ¶
type Definition struct {
Name string // Human-readable name
OperandWidths []int // Width in bytes of each operand
}
Definition describes an opcode's format
type EmittedInstruction ¶
EmittedInstruction represents the last emitted instruction
type InlineableFuncInfo ¶
type InlineableFuncInfo struct {
ConstIndex int // Index in constants pool
NumParams int
Body []byte
}
InlineableFuncInfo stores information about an inlineable function
type LiveInterval ¶ added in v0.4.21
type LiveInterval struct {
Var *Symbol // The variable this interval represents
Start int // Definition point (instruction index)
End int // Last use point (instruction index)
Reg int // Assigned register (-1 if not assigned, -2 if spilled)
Spill int // Spill slot index if spilled
Active bool // Whether this interval is currently active
}
LiveInterval represents the lifetime of a variable in the code
type LivenessAnalyzer ¶ added in v0.4.21
type LivenessAnalyzer struct {
// contains filtered or unexported fields
}
LivenessAnalyzer computes live intervals for variables in a function
func NewLivenessAnalyzer ¶ added in v0.4.21
func NewLivenessAnalyzer() *LivenessAnalyzer
NewLivenessAnalyzer creates a new liveness analyzer
func (*LivenessAnalyzer) Analyze ¶ added in v0.4.21
func (la *LivenessAnalyzer) Analyze(fn *parser.FunctionLiteral, st *SymbolTable) map[string]*LiveInterval
Analyze performs liveness analysis on a function body Returns a map from variable name to its live interval
func (*LivenessAnalyzer) GetIntervals ¶ added in v0.4.21
func (la *LivenessAnalyzer) GetIntervals() []*LiveInterval
GetIntervals returns all live intervals as a slice
type Opcode ¶
type Opcode byte
Opcode represents a single bytecode instruction
const ( // Stack operations OpConstant Opcode = iota // Load constant from constant pool OpPop // Pop value from stack OpDup // Duplicate top of stack // Arithmetic operations OpAdd // Addition OpSub // Subtraction OpMul // Multiplication OpDiv // Division OpMod // Modulo OpNeg // Unary minus (negation) // Comparison operations OpEqual // Equality check OpNotEqual // Inequality check OpLess // Less than OpGreater // Greater than OpLessEqual // Less than or equal OpGreaterEqual // Greater than or equal // Logical operations OpAnd // Logical AND OpOr // Logical OR OpNot // Logical NOT // Variable operations OpGetLocal // Get local variable OpSetLocal // Set local variable OpDefineLocal // Define local variable OpGetGlobal // Get global variable OpSetGlobal // Set global variable OpGetFree // Get free variable (from closure) OpSetFree // Set free variable (in closure) // Scope operations OpPushScope // Push new scope OpPopScope // Pop scope // Superinstructions (combined operations for performance) OpGetLocalAdd // Get two locals and add OpGetLocalSub // Get two locals and subtract OpGetLocalMul // Get two locals and multiply OpConstantAdd // Load two constants and add OpConstantSub // Load two constants and subtract OpConstantMul // Load two constants and multiply OpGetLocalLess // Get two locals and compare less OpGetLocalGreater // Get two locals and compare greater OpGetLocalEqual // Get two locals and compare equal OpGetLocalNotEqual // Get two locals and compare not equal // Type-specialized instructions (for hot path optimization) OpIncLocal // Increment local variable by 1 (optimized for loop counters) OpDecLocal // Decrement local variable by 1 OpAddLocalConst // Add constant to local variable OpSubLocalConst // Subtract constant from local variable OpMulLocalConst // Multiply local variable by constant // Control flow operations OpJump // Unconditional jump OpJumpIfFalse // Jump if top of stack is false OpJumpIfTrue // Jump if top of stack is true OpCall // Call function OpTailCall // Tail call (reuse current frame) OpReturn // Return from function OpClosure // Create closure with captured variables // Collection operations OpArray // Create array from stack elements OpMap // Create map from stack elements OpIndex // Index into array/map OpSetIndex // Set index in array/map OpIndexSafe // Index into array without bounds check (safe context) // Method/Field operations OpGetMethod // Get method from object OpCallMethod // Call method on object // Built-in operations OpBuiltin // Call built-in function // Literal operations OpNull // Push null onto stack OpTrue // Push true onto stack OpFalse // Push false onto stack // Loop control OpBreak // Break from loop OpContinue // Continue to next iteration // Module operations OpLoadModule // Load module and push onto stack OpGetExport // Get export from module OpModule // Create module from exports OpSetExport // Set export in current module // Class operations OpClass // Create class object OpNew // Create instance OpGetField // Get instance field OpSetField // Set instance field OpSuper // Get superclass method // Exception handling OpThrow // Throw exception (value on stack) OpPushHandler // Push exception handler (catchAddr, finallyAddr) OpPopHandler // Pop exception handler // Value-based operations (NaN boxing optimized - zero allocation) // These are the fast path for numeric operations OpValueAdd // Add two Values (no type check, direct numeric) OpValueSub // Subtract two Values OpValueMul // Multiply two Values OpValueDiv // Divide two Values OpValueMod // Modulo two Values OpValueNeg // Negate a Value // Value-based comparisons OpValueLess // Compare two Values for less than OpValueGreater // Compare two Values for greater than OpValueEqual // Compare two Values for equality OpValueNotEqual // Compare two Values for inequality OpValueLessEqual // Compare two Values for less or equal OpValueGreaterEqual // Compare two Values for greater or equal // Value-based local operations (combined for zero allocation) OpValueGetLocal // Get local as Value (push to value stack) OpValueSetLocal // Set local from Value (pop from value stack) OpValueIncLocal // Increment local by 1 OpValueDecLocal // Decrement local by 1 OpValueAddLocalConst // Add constant to local OpValueSubLocalConst // Subtract constant from local OpValueMulLocalConst // Multiply local by constant // Value-based superinstructions (maximum optimization) OpValueGetLocalAdd // Get two locals and add (Value path) OpValueGetLocalSub // Get two locals and subtract (Value path) OpValueGetLocalMul // Get two locals and multiply (Value path) OpValueGetLocalLess // Get two locals and compare less (Value path) OpValueGetLocalGreater // Get two locals and compare greater (Value path) OpValueGetLocalEqual // Get two locals and compare equal (Value path) // Register arithmetic: R[dst] = R[src1] op R[src2] OpRegAdd // R[dst] = R[src1] + R[src2] OpRegSub // R[dst] = R[src1] - R[src2] OpRegMul // R[dst] = R[src1] * R[src2] OpRegDiv // R[dst] = R[src1] / R[src2] OpRegMod // R[dst] = R[src1] % R[src2] OpRegNeg // R[dst] = -R[src1] (src2 unused) OpRegAnd // R[dst] = R[src1] && R[src2] OpRegOr // R[dst] = R[src1] || R[src2] OpRegNot // R[dst] = !R[src1] (src2 unused) // Register comparison: R[dst] = R[src1] op R[src2] (result is boolean) OpRegLess // R[dst] = R[src1] < R[src2] OpRegLessEqual // R[dst] = R[src1] <= R[src2] OpRegGreater // R[dst] = R[src1] > R[src2] OpRegGreaterEqual // R[dst] = R[src1] >= R[src2] OpRegEqual // R[dst] = R[src1] == R[src2] OpRegNotEqual // R[dst] = R[src1] != R[src2] // Register data movement (extended format: opcode | reg(8) | idx(16)) OpRegLoadConst // R[dst] = Constants[idx] OpRegLoadGlobal // R[dst] = Globals[idx] OpRegStoreGlobal // Globals[idx] = R[src] OpRegMove // R[dst] = R[src] (src2 unused, but format consistent) // Register local variable operations OpRegLoadLocal // R[dst] = Locals[idx] OpRegStoreLocal // Locals[idx] = R[src] OpRegLoadFree // R[dst] = FreeVars[idx] OpRegStoreFree // FreeVars[idx] = R[src] // Register control flow (extended format for jump offsets) OpRegJump // IP += offset (signed 16-bit) OpRegJumpIfTrue // if R[cond] then IP += offset OpRegJumpIfFalse // if !R[cond] then IP += offset // Register function call convention // R0-R7: argument registers // RRet (255): return value register OpRegCall // Call function, args in R0-R7, result in RRet OpRegReturn // Return value in R[reg] // Register closure and function operations OpRegClosure // Create closure from constant function OpRegLoadFunc // Load function from constant pool into register // Register collection operations OpRegArray // R[dst] = Array from R[src1..src1+src2-1] OpRegMap // R[dst] = Map from pairs starting at R[src1] OpRegIndex // R[dst] = R[obj][R[key]] OpRegSetIndex // R[obj][R[key]] = R[val] OpRegPush // Push R[src] to temp stack (for complex exprs) OpRegPop // Pop to R[dst] from temp stack // Register method/field operations (extended format for name index) OpRegGetMethod // R[dst] = R[obj].method(name_idx) OpRegCallMethod // Call method, args in R1-R7, result in RRet OpRegGetField // R[dst] = R[obj].field(name_idx) OpRegSetField // R[obj].field(name_idx) = R[src] // Register class operations OpRegClass // Create class OpRegNew // Create instance, args in R0-R7, result in RRet // Register built-in call OpRegBuiltin // Call builtin, args in R0-R7, result in RRet // Register null/true/false literals OpRegNull // R[dst] = null OpRegTrue // R[dst] = true OpRegFalse // R[dst] = false // Register exception handling OpRegThrow // throw R[src] OpRegPushHandler // push exception handler OpRegPopHandler // pop exception handler // Register superinstructions for common patterns OpRegAddConst // R[dst] = R[src1] + Constants[idx] OpRegSubConst // R[dst] = R[src1] - Constants[idx] OpRegMulConst // R[dst] = R[src1] * Constants[idx] OpRegIncLocal // Locals[idx]++ OpRegDecLocal // Locals[idx]-- )
func DecodeRegInstruction ¶ added in v0.4.21
DecodeRegInstruction decodes a fixed 4-byte register instruction
func DecodeRegInstructionConst ¶ added in v0.4.21
DecodeRegInstructionConst decodes a register instruction with 16-bit constant
func DecodeRegJump ¶ added in v0.4.21
DecodeRegJump decodes a jump instruction
type OptimizationFlags ¶
type OptimizationFlags struct {
BytecodeOptimizer bool
InlineFunctions bool // Function inlining at call sites
InlineCache bool
ClosurePool bool
TypeSpecialization bool
Superinstructions bool // Combine common instruction sequences
}
OptimizationFlags controls which optimizations are enabled
func DefaultOptimizations ¶
func DefaultOptimizations() OptimizationFlags
DefaultOptimizations returns flags with all optimizations enabled
func NoInliningOptimizations ¶
func NoInliningOptimizations() OptimizationFlags
NoInliningOptimizations returns flags with inlining disabled (for benchmarking)
type Optimizer ¶
type Optimizer struct {
// contains filtered or unexported fields
}
Optimizer transforms bytecode to reduce instruction count and improve execution patterns
func NewOptimizer ¶
NewOptimizer creates a new optimizer for given bytecode
func NewOptimizerWithFlags ¶
func NewOptimizerWithFlags(bytecode *Bytecode, flags OptimizationFlags) *Optimizer
NewOptimizerWithFlags creates an optimizer with custom flags
func (*Optimizer) FoldConstants ¶
FoldConstants evaluates constant expressions at compile time Pattern: Constant; Constant; BinaryOp → replace with single Constant
func (*Optimizer) GenerateSuperinstructions ¶
GenerateSuperinstructions combines common instruction sequences into single instructions
func (*Optimizer) GenerateTypeSpecializations ¶
GenerateTypeSpecializations creates type-specialized instructions for common patterns that can be optimized
func (*Optimizer) InlineFunctions ¶
InlineFunctions inlines small functions at call sites to reduce call overhead Pattern: OpGetGlobal/OpConstant (callee), args..., OpCall -> inlined body
type RegAllocStats ¶ added in v0.4.21
RegAllocStats holds statistics about register allocation
type RegAllocator ¶ added in v0.4.21
type RegAllocator struct {
// contains filtered or unexported fields
}
RegAllocator performs linear scan register allocation
func NewRegAllocator ¶ added in v0.4.21
func NewRegAllocator(numRegs int) *RegAllocator
NewRegAllocator creates a new register allocator
func (*RegAllocator) AddInterval ¶ added in v0.4.21
func (ra *RegAllocator) AddInterval(v *Symbol, start, end int) *LiveInterval
AddInterval adds a new live interval for a variable
func (*RegAllocator) Allocate ¶ added in v0.4.21
func (ra *RegAllocator) Allocate() int
Allocate performs linear scan register allocation Returns the number of spilled intervals
func (*RegAllocator) AllocateTemp ¶ added in v0.4.21
func (ra *RegAllocator) AllocateTemp() int
AllocateTemp allocates a temporary register
func (*RegAllocator) FreeTemp ¶ added in v0.4.21
func (ra *RegAllocator) FreeTemp(reg int)
FreeTemp frees a temporary register
func (*RegAllocator) GetInterval ¶ added in v0.4.21
func (ra *RegAllocator) GetInterval(varName string) *LiveInterval
GetInterval returns the live interval for a variable
func (*RegAllocator) GetRegister ¶ added in v0.4.21
func (ra *RegAllocator) GetRegister(varName string) int
GetRegister returns the register assigned to a variable, or -1 if not found
func (*RegAllocator) Reset ¶ added in v0.4.21
func (ra *RegAllocator) Reset()
Reset clears the allocator for reuse
func (*RegAllocator) SpillCount ¶ added in v0.4.21
func (ra *RegAllocator) SpillCount() int
SpillCount returns the number of spill slots used
func (*RegAllocator) Stats ¶ added in v0.4.21
func (ra *RegAllocator) Stats() RegAllocStats
Stats returns statistics about the allocation
type RegCompiler ¶ added in v0.4.21
type RegCompiler struct {
// contains filtered or unexported fields
}
RegCompiler compiles AST to register-based bytecode
func NewRegCompiler ¶ added in v0.4.21
func NewRegCompiler() *RegCompiler
NewRegCompiler creates a new register-based compiler
func (*RegCompiler) Bytecode ¶ added in v0.4.21
func (c *RegCompiler) Bytecode() *Bytecode
Bytecode returns the compiled bytecode
func (*RegCompiler) Compile ¶ added in v0.4.21
func (c *RegCompiler) Compile(node parser.Node) (int, error)
Compile compiles an AST node and returns the register containing the result
func (*RegCompiler) Constants ¶ added in v0.4.21
func (c *RegCompiler) Constants() []objects.Object
Constants returns the current constants pool
func (*RegCompiler) DefineGlobal ¶ added in v0.4.21
func (c *RegCompiler) DefineGlobal(name string)
DefineGlobal defines a global variable
func (*RegCompiler) ResolveSymbol ¶ added in v0.4.21
func (c *RegCompiler) ResolveSymbol(name string) (Symbol, bool)
ResolveSymbol resolves a symbol
func (*RegCompiler) SetConstants ¶ added in v0.4.21
func (c *RegCompiler) SetConstants(constants []objects.Object)
SetConstants sets the constants pool for persistent compilation
func (*RegCompiler) SetSourceFile ¶ added in v0.4.21
func (c *RegCompiler) SetSourceFile(filename string)
SetSourceFile sets the source file for error reporting
func (*RegCompiler) SetSymbolTable ¶ added in v0.4.21
func (c *RegCompiler) SetSymbolTable(st *SymbolTable)
SetSymbolTable sets the symbol table for persistent compilation
func (*RegCompiler) SymbolTable ¶ added in v0.4.21
func (c *RegCompiler) SymbolTable() *SymbolTable
SymbolTable returns the current symbol table
type SourceLocation ¶
SourceLocation represents a position in source code
type SourceMap ¶
type SourceMap struct {
// Maps instruction offset -> source location
Locations map[int]SourceLocation
// Source file path (if available)
SourceFile string
// Source code lines (for error display)
SourceLines []string
}
SourceMap maps bytecode instruction positions to source locations
func DeserializeSourceMap ¶
Deserialize reads the source map from a binary format
func (*SourceMap) Add ¶
func (sm *SourceMap) Add(offset int, loc SourceLocation)
Add maps an instruction offset to a source location
func (*SourceMap) FormatError ¶
FormatError creates a formatted error message with source context
func (*SourceMap) Get ¶
func (sm *SourceMap) Get(offset int) (SourceLocation, bool)
Get returns the source location for an instruction offset Returns the closest location if exact match not found
func (*SourceMap) SetSourceFile ¶
SetSourceFile sets the source file path and loads source lines
type Symbol ¶
type Symbol struct {
Name string
Scope SymbolScope
Index int
}
Symbol represents a named variable in a scope
type SymbolScope ¶
type SymbolScope string
SymbolScope represents the scope of a symbol
const ( GlobalScope SymbolScope = "GLOBAL" LocalScope SymbolScope = "LOCAL" BuiltinScope SymbolScope = "BUILTIN" FreeScope SymbolScope = "FREE" )
type SymbolTable ¶
type SymbolTable struct {
Outer *SymbolTable
Store map[string]Symbol
NumDefinitions int
FreeSymbols []Symbol
}
SymbolTable manages symbol definitions and resolution
func NewEnclosedSymbolTable ¶
func NewEnclosedSymbolTable(outer *SymbolTable) *SymbolTable
NewEnclosedSymbolTable creates a new symbol table with an outer scope
func (*SymbolTable) Define ¶
func (s *SymbolTable) Define(name string) Symbol
Define adds a new symbol to the symbol table
func (*SymbolTable) DefineBuiltin ¶
func (s *SymbolTable) DefineBuiltin(index int, name string) Symbol
DefineBuiltin adds a built-in function symbol