Expand description
Bytecode backend: LIR → StoryData.
Structs§
- Codegen
Error - A defect in the LIR fed to codegen — an invariant that a well-formed
Programis 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’sNopdegradation removed,container.rs’sLogicBreak/LogicContinuehandling had zero codegen-level guard against aloop_stackthat’s empty — a future or refactored LIR producer that ever emitted one outside a loop would silently corrupt bytecode via an unpatchedJump(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 bypassesbrink-ir::lir::lower(which rejects this case at E057, non-suppressibly, before aProgramis ever produced). - Container
Chunk - One container’s codegen output: a
ContainerDefwhose bytecode still carriesUNRESOLVED_NAME_IDplaceholders at everyRelocationsite, plus the relocation table itself.linkresolves the symbols and yields a fully-patchedContainerDef. - Emit
Options - Codegen-facing knobs for one
emitcall.emit_debug_infois the only field today — astruct(not a bare bool parameter) so a future knob (e.g. a D7 “populate locals” toggle) doesn’t need anotheremit_with_*overload. - Relocation
- A patch site in a chunk’s bytecode: the little-endian
u16NameIdoperand at byteoffset(currently always aPushStringoperand) must be overwritten with the link-resolved id ofname.
Enums§
- NameRef
- A symbolic reference to a name, resolved to a final
NameIdby 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::MAXis never a legitimate resolvedNameIdin 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
ProgramintoStoryDatafor the runtime. - emit_
with_ options emitwith explicitEmitOptions— the D6 (docs/debugger-spec.md§2) entry point.options.emit_debug_infogates theDebugInfosection (SectionKind::DebugInfo, tag0x11):falsetakes the exact same code pathemitalways has, byte-for-byte;trueadditionally records(bytecode_offset, source_range)pairs during the same container walk and attaches them asStoryData::debug_info.