5.2 KiB
PBS Bytecode and PBX Mapping Specification
Status: Draft v0 (Skeleton)
Applies to: mapping from lowered PBS programs into PBX sections, bytecode-facing artifacts, and related source-to-artifact invariants
1. Purpose
This document will define the normative mapping between lowered PBS semantics and emitted PBX/bytecode-facing artifacts.
2. Scope
This document is intended to define:
- artifact-level obligations after lowering,
- mapping of semantic constructs into PBX-visible structures,
- source-to-artifact invariants required by verifier and loader stages,
- interaction points with host-binding metadata such as
SYSC, - interaction points with VM-owned builtin and intrinsic metadata.
This document does not define:
- the full bytecode ISA,
- UI/tooling presentation,
- one compiler's internal IR representation.
3. Authority and Precedence
Normative precedence:
- Runtime authority (
docs/specs/hardware/topics/chapter-2.md,chapter-3.md,chapter-9.md,chapter-12.md,chapter-16.md) - Bytecode authority (
docs/specs/bytecode/ISA_CORE.md) 6.1. Intrinsics and Builtin Types Specification.md6.2. Host ABI Binding and Loader Resolution Specification.md13. Lowering IRBackend Specification.md- This document
If a rule here conflicts with higher-precedence authorities, it is invalid.
4. Normative Inputs
This document depends on, at minimum:
6.1. Intrinsics and Builtin Types Specification.md6.2. Host ABI Binding and Loader Resolution Specification.md13. Lowering IRBackend Specification.md
5. Already-Settled Inputs
The following inputs are already fixed elsewhere and must not be contradicted here:
- The compiler emits host-binding declarations into PBX
SYSC. - Host-backed callsites are emitted in pre-load form as
HOSTCALL <sysc_index>. SYSCentries are deduplicated by canonical identity and ordered by first occurrence.- The loader resolves host bindings and rewrites
HOSTCALLintoSYSCALL. - VM-owned builtin projections, builtin constants, and intrinsic callsites do not emit host-binding metadata.
- VM-owned intrinsic artifacts are distinct from
SYSC,HOSTCALL, andSYSCALL. - V1 source-attribution hooks for diagnostics/conformance need only support recovery of at least one source location for source-attributable backend failures; one exact source-map format is not yet required.
6. Current Conformance-Facing Mapping Baseline
The current boundary across backend-facing specs is:
13. Lowering IRBackend Specification.mddefines what facts must be preserved by lowering,- this document defines how the PBS-facing artifact facts appear in PBX/bytecode-visible form,
- and
19. Verification and Safety Checks Specification.mddefines later validity checks after the artifact is formed and, where relevant, patched by the loader.
The current conformance-facing artifact baseline is invariant-based.
At minimum, the PBS-facing artifact contract currently includes:
- canonical host-binding declarations in
SYSCfor admitted host-backed uses; SYSCdeduplication by canonical identity and ordering by first occurrence;- host-backed callsites emitted in pre-load form as
HOSTCALL <sysc_index>; - no host-binding metadata emission for VM-owned builtin projections, builtin constants, or intrinsic callsites;
- no executable bytecode emission for stdlib interface modules by themselves;
- enough source-attribution information to recover at least one source location for backend failures that remain in the PBS-facing diagnostics/conformance surface.
This baseline does not require one full-image PBX golden.
7. Initial Section Targets
At minimum, the completed document should contain normative sections for:
- artifact mapping goals,
- section-level invariants,
- callsite and control-flow mapping invariants,
- metadata mapping obligations,
- intrinsic and builtin artifact obligations,
- source-attribution hooks for diagnostics/conformance.
8. TODO
The following items remain to be closed in future agenda discussion.
- Which PBX sections beyond
SYSCare part of the PBS-facing contract. - Whether a distinct intrinsic declaration section is part of the PBS-facing contract in v1.
- Which source-level constructs require dedicated artifact patterns versus implementation freedom.
- How much of artifact ordering, numbering, and layout is normative at PBS level versus owned purely by PBX authority.
- Whether compilers should emit final
INTRINSIC <id>directly for a selected VM line or may emit a declaration-based preload form such asINTRCALL <decl_index>. - Which richer debug/source-map surfaces, if any, are added beyond the minimum attribution hooks already sufficient for v1 diagnostics and conformance.
9. Non-Goals
- Repeating the full PBX or ISA documentation.
- Mandating one binary-emitter implementation strategy.
- Defining loader patching internals already owned elsewhere.
10. Exit Criteria
This document is ready to move beyond skeleton status only when:
- the PBS-to-artifact boundary is explicit,
- artifact-level invariants needed by verifier and loader are normative,
- the document no longer relies on unresolved
TODOitems for ordinary v1 artifact mapping behavior.