encoder

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 20, 2023 License: MIT Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ErrNoLocalScope is raised when no local scope has been created
	ErrNoLocalScope = "no local scopes have been pushed"

	// ErrDuplicateName is raised when an attempt is made to register a
	// duplicated name within the same local scope
	ErrDuplicateName = "name duplicated in scope: %s"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Cell

type Cell struct {
	Name data.Local
	Type CellType
}

Cell attaches a name to a type/disposition

type CellType

type CellType int

CellType marks a cell as having a certain disposition

const (
	ValueCell CellType = iota
	ReferenceCell
	RestCell
)

Cell dispositions

type Encoder

type Encoder interface {
	Child() Encoder

	Emit(isa.Opcode, ...isa.Operand)
	Code() isa.Instructions
	StackSize() isa.Operand

	NewLabel() isa.Operand

	Globals() env.Namespace
	Constants() data.Vector
	AddConstant(data.Value) isa.Operand

	Closure() IndexedCells
	ResolveClosure(data.Local) (*IndexedCell, bool)

	PushParams(data.Locals, bool)
	PopParams()
	ResolveParam(data.Local) (*IndexedCell, bool)

	LocalCount() isa.Operand
	PushLocals()
	PopLocals()
	AddLocal(data.Local, CellType) *IndexedCell
	ResolveLocal(data.Local) (*IndexedCell, bool)

	ResolveScoped(data.Local) (*ScopedCell, bool)
}

Encoder exposes an interface for stateful compiler encoding

func NewEncoder

func NewEncoder(globals env.Namespace) Encoder

NewEncoder instantiates a new Encoder

type IndexedCell

type IndexedCell struct {
	*Cell
	Index isa.Operand
}

IndexedCell attaches an Index to a Cell

type IndexedCells

type IndexedCells []*IndexedCell

IndexedCells encapsulates a group of IndexedCells

type Locals

type Locals map[data.Local]*IndexedCell

Locals track local variable assignments

type Scope

type Scope int

Scope describes the scope of a name

const (
	LocalScope Scope = iota
	ArgScope
	ClosureScope
)

Scope locations

type ScopedCell

type ScopedCell struct {
	*Cell
	Scope
}

ScopedCell attaches a Scope to a Cell

Jump to

Keyboard shortcuts

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