encoder

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Oct 11, 2024 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"
)
View Source
const ErrLabelAlreadyAnchored = "label has already been anchored"

ErrLabelAlreadyAnchored is raised when the finalizer identifies that a label has been anchored more than once in the Instructions stream

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 Encoded

type Encoded struct {
	Code      isa.Instructions
	Globals   env.Namespace
	Constants data.Vector
	Closure   data.Locals
}

Encoded is a snapshot of the current Encoder's state. It is used as an intermediate step in the compilation process, particularly as input to the optimizer.

func (*Encoded) Runnable

func (e *Encoded) Runnable() *isa.Runnable

Runnable takes an Encoded and finalizes it into a Runnable that the abstract machine can execute. Jumps are resolved and unused constants are discarded.

func (*Encoded) WithCode

func (e *Encoded) WithCode(c isa.Instructions) *Encoded

func (*Encoded) WithConstants

func (e *Encoded) WithConstants(c data.Vector) *Encoded

type Encoder

type Encoder interface {
	Child() Encoder

	Emit(isa.Opcode, ...isa.Operand)
	Encode() *Encoded
	Globals() env.Namespace
	NewLabel() isa.Operand

	AddConstant(data.Value) isa.Operand

	PushParams(data.Locals, bool)
	PopParams()

	PushLocals()
	PopLocals()
	AddLocal(data.Local, CellType) *IndexedCell

	ResolveScoped(data.Local) (*ScopedCell, bool)
	ResolveClosure(data.Local) (*IndexedCell, bool)
	ResolveParam(data.Local) (*IndexedCell, bool)
	ResolveLocal(data.Local) (*IndexedCell, 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