Skip to main content

Crate brink_codegen_inkb

Crate brink_codegen_inkb 

Source
Expand description

Bytecode backend: LIR → StoryData.

Structs§

CodegenError
A defect in the LIR fed to codegen — an invariant that a well-formed Program is guaranteed to satisfy by earlier, non-suppressible compiler stages, which codegen has no independent way to verify structurally beyond this checkpoint. See #586: with #577’s Nop degradation removed, container.rs’s LogicBreak/LogicContinue handling had zero codegen-level guard against a loop_stack that’s empty — a future or refactored LIR producer that ever emitted one outside a loop would silently corrupt bytecode via an unpatched Jump(0) that looks well-formed, rather than fail. This is the hard error that replaces that silent corruption; today it can only fire on hand-assembled LIR that bypasses brink-ir::lir::lower (which rejects this case at E057, non-suppressibly, before a Program is ever produced).
ContainerChunk
One container’s codegen output: a ContainerDef whose bytecode still carries UNRESOLVED_NAME_ID placeholders at every Relocation site, plus the relocation table itself. link resolves the symbols and yields a fully-patched ContainerDef.
EmitOptions
Codegen-facing knobs for one emit call. emit_debug_info is the only field today — a struct (not a bare bool parameter) so a future knob (e.g. a D7 “populate locals” toggle) doesn’t need another emit_with_* overload.
Relocation
A patch site in a chunk’s bytecode: the little-endian u16 NameId operand at byte offset (currently always a PushString operand) must be overwritten with the link-resolved id of name.

Enums§

NameRef
A symbolic reference to a name, resolved to a final NameId by the link phase. Owns its string so the record is self-contained (the FG-4 appendix’s “no transient pointers, serializable in principle”).

Constants§

UNRESOLVED_NAME_ID
The placeholder written into a chunk’s bytecode at every name-reference operand before linking. u16::MAX is never a legitimate resolved NameId in the stories this backend emits (name tables stay far below 65 535 entries at game-corpus sizes), so an un-patched site is detectable rather than silently valid.

Functions§

emit
Compile a resolved LIR Program into StoryData for the runtime.
emit_with_options
emit with explicit EmitOptions — the D6 (docs/debugger-spec.md §2) entry point. options.emit_debug_info gates the DebugInfo section (SectionKind::DebugInfo, tag 0x11): false takes the exact same code path emit always has, byte-for-byte; true additionally records (bytecode_offset, source_range) pairs during the same container walk and attaches them as StoryData::debug_info.