Expand description
The bytecode compiler.
Compilation is a single walk over the AST that emits symbolic instructions (jump targets are label ids, variable references are names), followed by a resolution pass that turns them into final bytecode. Splitting it this way keeps the emitter readable: nothing has to know slot indices or byte offsets while it is still discovering them.
Variable resolution follows the reference implementation’s model:
- every function has a flat table of arguments and locals;
- block scopes form a chain through
VarDef::scope_next, which is what makeslet/constbindings visible only inside their block and lets the runtime put them back into the temporal dead zone on entry; - a name that is not in the current function is looked up in the enclosing ones; if found, the variable is marked captured and reached through a closure reference;
- a name found nowhere is a global, reached through a closure entry as well.
Emission order and instruction choice deliberately mirror quickjs.c: the
differential test compares disassembly with the reference opcode by opcode, so
an unnecessary dup or a differently chosen short form shows up immediately.
Structs§
Functions§
- compile_
module - Compile a module.
- compile_
script - Compile a script.
- disassemble
- Disassemble a compiled function.