compile

package
v0.0.0-...-21f6697 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2022 License: MIT Imports: 6 Imported by: 0

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
	SymbolTable  *SymbolTable
}

type CompilationScope

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

type Compiler

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

Compiler wraps the bytecode instructions and constants pool.

func New

func New(symbolTable *SymbolTable, constants []object.Object) *Compiler

New returns a new instance of the Compiler

func NewCompilerWithBuiltins

func NewCompilerWithBuiltins(constants []object.Object) *Compiler

NewCompilerWithBuiltins returns a new instance of the Compiler, with builtin functions defined.

func (*Compiler) Bytecode

func (c *Compiler) Bytecode() *Bytecode

func (*Compiler) Compile

func (c *Compiler) Compile(node ast.Node) error

Compile compiles the AST into Bytecode. It fills the compiler instructions and constant pool with compiled bytecode instructions and evaluated constants.

type EmittedInstruction

type EmittedInstruction struct {
	Opcode   code.Opcode
	Position int
}

type Symbol

type Symbol struct {
	Name  string
	Scope SymbolScope
	Index int
}

type SymbolScope

type SymbolScope string
const (
	// BuiltinScope is used for builtins functions
	BuiltinScope SymbolScope = "BUILTIN"
	// GlobalScope is used to for global variables
	GlobalScope SymbolScope = "GLOBAL"
	// LocalScope is used to for local variables
	LocalScope SymbolScope = "LOCAL"
	// FreeScope is used to for free variables(used in closures)
	FreeScope SymbolScope = "FREE"
	// FunctionScope is used to for function names
	FunctionScope SymbolScope = "FUNCTION"
)

type SymbolTable

type SymbolTable struct {
	FreeSymbols []Symbol
	// contains filtered or unexported fields
}

func NewEnclosedSymbolTable

func NewEnclosedSymbolTable(parent *SymbolTable) *SymbolTable

func NewSymbolTable

func NewSymbolTable() *SymbolTable

func (*SymbolTable) Define

func (st *SymbolTable) Define(ident string) Symbol

func (*SymbolTable) DefineBuiltin

func (st *SymbolTable) DefineBuiltin(index int, name string) Symbol

func (*SymbolTable) DefineFunctionName

func (st *SymbolTable) DefineFunctionName(name string) Symbol

func (*SymbolTable) Resolve

func (st *SymbolTable) Resolve(ident string) (sym Symbol, ok bool)

Jump to

Keyboard shortcuts

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