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_eval_with_private;pub use compiler::compile_module;pub use compiler::compile_module_with_source;pub use compiler::compile_script;pub use compiler::compile_script_suspensible;pub use compiler::compile_script_with_source;pub use compiler::disassemble;pub use number::number_to_string;pub use opcode::OpFormat;pub use opcode::OpInfo;pub use opcode::Opcode;
Modules§
- bytecode
- The bytecode representation of a function.
- compiler
- The bytecode compiler.
- disasm
- Text disassembly, in exactly the format the reference implementation prints.
- number
Number::toString, the one spelling of a number that both halves of the engine need.- opcode
- The instruction set, transcribed from the reference
quickjs-opcode.h. - serialize
- Serialisation of compiled bytecode.