Expand description
Bytecode compiler: takes the AST and produces the bytecode of a function.
The pipeline matches the reference implementation:
- [
compile] walks the AST once and emits unresolved bytecode, where every variable reference is a slot in a flat table of arguments, locals and closure variables, and every jump is a label rather than an offset. - [
Function::resolve] turns those into the final bytecode: variables becomeget_loc/get_arg/get_var_ref/get_var, jumps become byte offsets, and the stack size is computed. serializewrites the result in a self-describing format with a magic number and a version.
Keeping steps 1 and 2 apart is what makes the compiler testable: step 1 can be compared against the reference’s pass-1 dump, and step 2 against its pass-3 dump.
Re-exports§
pub use bytecode::Function;pub use bytecode::FunctionKind;pub use bytecode::LineCol;pub use bytecode::VarDef;pub use bytecode::VarKind;pub use compiler::Compiler;pub use compiler::compile_module;pub use compiler::compile_script;pub use compiler::disassemble;pub use opcode::OpFormat;pub use opcode::OpInfo;pub use opcode::Opcode;