Unit
A staged compilation unit.
Provides diagnostics and document nodes for one source file before emitting
bytecode. A unit borrows and pins the source passed to
compile.
Example
let unit = compile "example.dol" "pub let answer = 42\n" document: true
for id node = unit.nodes()
echo $id $node.span
let bytecode = unit.emit()
Methods
diagnostics() -> Iter[Diagnostic]
Returns a fresh iterator of diagnostics.
emit() -> Bin
Consumes the unit and returns its bytecode.
Errors
| Exception | Condition |
|---|---|
std.CompileError |
Compilation failed |
std.StateError |
The unit, its node iterators, or its nodes are used after emission |
node id -> (Node | nil)
Looks up a node by NodeId.
Parameters
| Name | Type | Description |
|---|---|---|
id |
NodeId |
The ID to look up. |
Returns
nil when the ID belongs to another unit.
nodes() -> Iter[Tuple[NodeId, Node]]
Returns a fresh iterator of node IDs paired with their nodes.
Empty unless the unit was compiled with document: true. An enabled unit
always contains one Root, even for empty source.
Example
tokens() -> Iter[Token]
Returns a fresh iterator of tokens covering the whole source, in source order.