Struct passerine::compiler::gen::Compiler [−][src]
pub struct Compiler { /* fields omitted */ }
Expand description
Compiler is a bytecode generator that walks an SST and produces (unoptimized) Bytecode.
There are plans to add a bytecode optimizer in the future.
Note that this struct should not be controlled manually,
use the gen
function instead.
Implementations
Replace the current compiler with a fresh one,
keeping a reference to the old one in self.enclosing
,
and moving the FFI into the current compiler.
Restore the enclosing compiler, returning the nested one for data (Lambda) extraction, and moving the FFI mappings back into the enclosing compiler.
Walks an SST to generate bytecode. At this stage, the SST should’ve been verified, pruned, typechecked, etc. A malformed SST will cause a panic, as SSTs should be correct at this stage, and for them to be incorrect is an error in the compiler itself.
Resovles a symbol lookup, e.g. something like x
.
Takes a Data
leaf and and produces some code to load the constant
A block is a series of expressions where the last is returned. Each sup-expression is walked, the last value is left on the stack.
Generates a print expression Note that currently printing is a baked-in language feature, but the second the FFI becomes a thing it’ll no longer be one.
Generates a Label construction that loads the variant, then wraps some data
Generates a Tuple construction that loads all fields in the tuple then rips them off the stack into a vec.
Makes a Rust function callable from Passerine, by keeping a reference to that function.
Resolves the assignment of a variable returns true if the variable was declared.
Destructures a pattern into a series of unpack and assign instructions. Instructions match against the topmost stack item. Does delete the data that is matched against.
Assign a value to a variable.
Recursively compiles a lambda declaration in a new scope.