compiler

package
v1.4.3 Latest Latest
Warning

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

Go to latest
Published: Nov 2, 2022 License: GPL-3.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ContinuePlaceholder = 9998
	BreakPlaceholder    = 9997
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Bytecode

type Bytecode struct {
	Instructions code.Instructions
	Constants    []obj.Object
}

type Compilable

type Compilable interface {
	Compile(c *Compiler) (int, error)
	IsConstExpression() bool
}

type CompilationScope

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

type Compiler

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

func New

func New() *Compiler

func NewWithState

func NewWithState(s *SymbolTable, constants *[]obj.Object) *Compiler

func (*Compiler) AddConstant

func (c *Compiler) AddConstant(o obj.Object) int

func (*Compiler) AddInstruction

func (c *Compiler) AddInstruction(ins []byte) int

func (*Compiler) Bytecode

func (c *Compiler) Bytecode() *Bytecode

func (*Compiler) Compile

func (c *Compiler) Compile(node Compilable) error

func (*Compiler) Emit

func (c *Compiler) Emit(opcode code.Opcode, operands ...int) int

func (*Compiler) EnterScope

func (c *Compiler) EnterScope()

func (*Compiler) LastIs

func (c *Compiler) LastIs(op code.Opcode) bool

func (*Compiler) LeaveScope

func (c *Compiler) LeaveScope() code.Instructions

func (*Compiler) LoadSymbol

func (c *Compiler) LoadSymbol(s Symbol) int

func (*Compiler) Pos

func (c *Compiler) Pos() int

Returns the position to the last instruction.

func (*Compiler) RemoveLast

func (c *Compiler) RemoveLast()

func (*Compiler) ReplaceBreakOperands

func (c *Compiler) ReplaceBreakOperands(startBody, endBody, operand int) error

func (*Compiler) ReplaceContinueOperands

func (c *Compiler) ReplaceContinueOperands(startBody, endBody, operand int) error

func (*Compiler) ReplaceLastPopWithReturn

func (c *Compiler) ReplaceLastPopWithReturn()

func (*Compiler) ReplaceOperand

func (c *Compiler) ReplaceOperand(opPos, operand int)

func (*Compiler) SetBytecode

func (c *Compiler) SetBytecode(b *Bytecode)

type EmittedInst

type EmittedInst struct {
	Opcode   code.Opcode
	Position int
}

type Symbol

type Symbol struct {
	Name  string
	Scope SymbolScope
	Index int
}

type SymbolScope

type SymbolScope int
const (
	GlobalScope SymbolScope = iota
	LocalScope
	BuiltinScope
	FreeScope
	FunctionScope
)

type SymbolTable

type SymbolTable struct {
	Store       map[string]Symbol
	NumDefs     int
	FreeSymbols []Symbol
	// contains filtered or unexported fields
}

func NewEnclosedSymbolTable

func NewEnclosedSymbolTable(outer *SymbolTable) *SymbolTable

func NewSymbolTable

func NewSymbolTable() *SymbolTable

func (*SymbolTable) Define

func (s *SymbolTable) Define(name string) Symbol

func (*SymbolTable) DefineBuiltin

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

func (*SymbolTable) DefineFree

func (s *SymbolTable) DefineFree(original Symbol) Symbol

func (*SymbolTable) DefineFunctionName

func (s *SymbolTable) DefineFunctionName(n string) Symbol

func (*SymbolTable) Resolve

func (s *SymbolTable) Resolve(name string) (Symbol, bool)

Jump to

Keyboard shortcuts

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