Documentation ¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Bytecode ¶
type Bytecode struct { Instructions code.Instructions Constants []object.Object }
Bytecode contains the Instructions our Compiler generated and the Constants the Compiler evaluated
type CompilationScope ¶
type CompilationScope struct {
// contains filtered or unexported fields
}
CompilationScope - Before we start compiling a function's body (enter a new scope) we push a new CompilationScope on to the scopes stack. While compiling inside this scope, the emit method of the compiler will modify only the fields of the current CompilationScope. Once we're done compiling the function, we leave the scope by popping it off the scopes stack and putting the instructions in a new *object.CompiledFunction
type Compiler ¶
type Compiler struct {
// contains filtered or unexported fields
}
Compiler defines our compiler with instructions which hold the generated bytecode, constants which serve as our constant pool, and the last and previous instructions
func New ¶
func New() *Compiler
New creates and returns a pointer to a Compiler with initialized instructions & constants
func NewWithState ¶
func NewWithState(s *SymbolTable, constants []object.Object) *Compiler
NewWithState creates a new compiler with the passed in symbol table and constants (needed in REPL)
type EmittedInstruction ¶
EmittedInstruction represents an instruction through an opcode and it's position
type Symbol ¶
type Symbol struct { Name string Scope SymbolScope Index int }
Symbol - Holds all the necessary info about a symbol - Name, Scope, and Index
type SymbolScope ¶
type SymbolScope string
SymbolScope - Type alias for a string. Used in a Symbol to define it's scope.
const ( GlobalScope SymbolScope = "GLOBAL" LocalScope SymbolScope = "LOCAL" BuiltinScope SymbolScope = "BUILTIN" FreeScope SymbolScope = "FREE" FunctionScope SymbolScope = "FUNCTION" )
Define all our scopes
type SymbolTable ¶
type SymbolTable struct { Outer *SymbolTable FreeSymbols []Symbol // contains filtered or unexported fields }
SymbolTable holds a "store" which is a map of strings to Symbols, an int of number of definitions, and "Outer" which defines it's parent scope
func NewEnclosedSymbolTable ¶
func NewEnclosedSymbolTable(outer *SymbolTable) *SymbolTable
NewEnclosedSymbolTable takes an outer parent symbol table and returns a pointer to the new enclosed SymbolTable after attaching the outer parent to the new one
func NewSymbolTable ¶
func NewSymbolTable() *SymbolTable
NewSymbolTable creates and returns a pointer to a symbol table initialized with a "store"
func (*SymbolTable) Define ¶
func (s *SymbolTable) Define(name string) Symbol
Define takes a name and creates a symbol with the name, an index, and assigns scope. It then assigns the symbol to the SymbolTable's store, increases numDefinitions and returns the symbol.
func (*SymbolTable) DefineBuiltin ¶
func (s *SymbolTable) DefineBuiltin(index int, name string) Symbol
DefineBuiltin creates and returns a symbol within builtin scope
func (*SymbolTable) DefineFunctionName ¶
func (s *SymbolTable) DefineFunctionName(name string) Symbol
DefineFunctionName creates a new Symbol with FunctionScope and adds it to the s.store