Skip to main content

js_compile/
lib.rs

1//! Bytecode compiler: takes the AST and produces the bytecode of a function.
2//!
3//! The pipeline matches the reference implementation:
4//!
5//! 1. [`compile`] walks the AST once and emits *unresolved* bytecode, where
6//!    every variable reference is a slot in a flat table of arguments, locals
7//!    and closure variables, and every jump is a label rather than an offset.
8//! 2. [`Function::resolve`] turns those into the final bytecode: variables become
9//!    `get_loc`/`get_arg`/`get_var_ref`/`get_var`, jumps become byte offsets, and
10//!    the stack size is computed.
11//! 3. [`serialize`] writes the result in a self-describing format with a magic
12//!    number and a version.
13//!
14//! Keeping steps 1 and 2 apart is what makes the compiler testable: step 1 can be
15//! compared against the reference's pass-1 dump, and step 2 against its pass-3
16//! dump.
17
18pub mod bytecode;
19pub mod compiler;
20pub mod disasm;
21pub mod opcode;
22pub mod serialize;
23
24pub use bytecode::{Function, FunctionKind, LineCol, VarDef, VarKind};
25pub use compiler::{
26    Compiler, compile_module, compile_script, compile_script_suspensible, disassemble,
27};
28pub use opcode::{OpFormat, OpInfo, Opcode};