Documentation
¶
Overview ¶
Package encoder provides bytecode encoding
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 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) HasClosure ¶ added in v0.3.0
type Encoder ¶
type Encoder interface {
// Child creates a child encoder, allowing closure resolution
Child() Encoder
// Emit an instruction with the given opcode and operands
Emit(isa.Opcode, ...isa.Operand)
// Encode returns the encoded bytecode
Encode() *Encoded
// Globals returns the global namespace for this Encoder
Globals() env.Namespace
// NewLabel creates a new label for jump instructions
NewLabel() isa.Operand
// AddConstant adds a constant value and returns its index
AddConstant(ale.Value) isa.Operand
// PushParams pushes a new parameter frame
PushParams(data.Locals, bool)
// PopParams pops the current parameter frame
PopParams()
// PushLocals pushes a new local variable frame
PushLocals()
// PopLocals pops the current local variable frame
PopLocals() error
// AddLocal adds a local variable and returns its cell
AddLocal(data.Local, CellType) (*IndexedCell, error)
// ResolveScoped resolves a scoped variable
ResolveScoped(data.Local) (*ScopedCell, bool)
// ResolveClosure resolves a closure variable
ResolveClosure(data.Local) (*IndexedCell, bool)
// ResolveParam resolves a parameter variable
ResolveParam(data.Local) (*IndexedCell, bool)
// ResolveLocal resolves a local variable
ResolveLocal(data.Local) (*IndexedCell, bool)
}
Encoder exposes an interface for stateful compiler encoding
func NewEncoder ¶
NewEncoder instantiates a new Encoder
type IndexedCell ¶
IndexedCell attaches an Index to a Cell
type IndexedCells ¶
type IndexedCells []*IndexedCell
IndexedCells encapsulates a group of IndexedCells
type ScopedCell ¶
ScopedCell attaches a Scope to a Cell
type WrappedEncoder ¶ added in v0.3.0
Click to show internal directories.
Click to hide internal directories.