Expand description
The module system: records, linking, namespaces, and evaluation.
The design follows §16.2 closely but leans on one thing this engine already has.
A module’s top-level bindings compile as closure variables of the module body —
ClosureType::ModuleDecl for its own declarations, ClosureType::ModuleImport for
what it imports — so reading one is an ordinary get_var_ref. What makes modules
interesting is then entirely a question of who fills the cells:
- a declaration gets a fresh cell, created here;
- an import gets the exporting module’s cell, not a copy.
Sharing the cell is what makes bindings live (export let x; x = 1 is visible to the
importer) and what makes cyclic imports work: linking wires cells before anything
evaluates, so a.js importing from a b.js that imports back from a.js resolves to
cells on both sides without either body having run.
The three phases are the spec’s: load (read and compile), link (resolve imports, validate exports), evaluate (run bodies depth-first, once each).
Structs§
- Loaded
Module - A host-supplied module, before it is compiled.
- Module
Inner - Everything a module record holds; see
ModuleRecord. - Module
Record - One loaded module.
Enums§
- Module
Kind - How a module’s source became a module.
- Module
Status - Where a module is in its lifetime.
Traits§
- Module
Loader - How the host turns a specifier into bytes.