compiler

package
v1.6.4 Latest Latest
Warning

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

Go to latest
Published: Jan 14, 2024 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GenericPlaceholder  = 9999
	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
	Bookmarks    []tauerr.Bookmark
	NumDefs      int
}

func Decode added in v1.6.0

func Decode(b []byte) *Bytecode

func (Bytecode) Encode added in v1.6.0

func (b Bytecode) Encode() (data []byte, err error)

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 NewImport added in v1.6.0

func NewImport(numDefs int, constants *[]obj.Object) *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) Bookmark added in v1.5.0

func (c *Compiler) Bookmark(pos 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, []tauerr.Bookmark)

func (*Compiler) LoadSymbol

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

func (*Compiler) NewError added in v1.5.0

func (c *Compiler) NewError(pos int, s string, a ...any) error

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)

func (*Compiler) SetFileInfo added in v1.5.0

func (c *Compiler) SetFileInfo(name, content string)

func (*Compiler) UnresolvedError added in v1.5.0

func (c *Compiler) UnresolvedError(name string, pos int) error

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
	FreeSymbols []Symbol
	NumDefs     int
	// 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