|
| 1 | +# Baa Bootstrap Contract |
| 2 | + |
| 3 | +> **Version:** v0.5.1 freeze contract (bootstrap-facing) | [Language Spec →](LANGUAGE.md) |
| 4 | +
|
| 5 | +This document freezes the current Baa language, stdlib, ABI, and IR contracts that later |
| 6 | +bootstrap work must treat as stable inputs. |
| 7 | + |
| 8 | +It is intentionally conservative: |
| 9 | + |
| 10 | +- no new syntax is introduced here, |
| 11 | +- no ABI behavior is widened here, |
| 12 | +- no IR guarantees are promised beyond what the current compiler already implements and verifies. |
| 13 | + |
| 14 | +## Canonical Sources |
| 15 | + |
| 16 | +The freeze is defined by these sources of truth: |
| 17 | + |
| 18 | +- Language surface: `docs/LANGUAGE.md` |
| 19 | +- Standard library callable signatures: `stdlib/baalib.baahd` |
| 20 | +- IR semantics and verifier-backed invariants: `docs/BAA_IR_SPECIFICATION.md` |
| 21 | +- Target/ABI implementation contract: `src/backend/target.h` and `src/backend/target.c` |
| 22 | + |
| 23 | +If detailed docs drift from these surfaces, this document and the files above win for bootstrap |
| 24 | +planning. |
| 25 | + |
| 26 | +## Frozen Language Surface |
| 27 | + |
| 28 | +The following source-language surface is frozen for bootstrap readiness: |
| 29 | + |
| 30 | +- UTF-8 source files with `.baa` extension |
| 31 | +- `الرئيسية` as the only program entry-point name |
| 32 | +- current preprocessor directives: |
| 33 | + - `#تضمين` |
| 34 | + - `#تعريف` |
| 35 | + - `#إذا_عرف` |
| 36 | + - `#وإلا` |
| 37 | + - `#نهاية` |
| 38 | + - `#الغاء_تعريف` |
| 39 | + - `#خطأ` |
| 40 | +- current core type spellings, including: |
| 41 | + - signed/unsigned integer families |
| 42 | + - `منطقي` |
| 43 | + - `حرف` |
| 44 | + - `نص` |
| 45 | + - `عشري` |
| 46 | + - `عشري٣٢` as a source-level alias that still lowers as `f64` |
| 47 | + - `عدم` |
| 48 | + - function-pointer syntax `دالة(...) -> ...` |
| 49 | +- current control-flow and declaration syntax |
| 50 | +- current function-pointer syntax and semantics |
| 51 | +- current variadic function syntax with `...` |
| 52 | +- current inline-assembly syntax through `مجمع` |
| 53 | + |
| 54 | +The only frozen entry-point signatures are: |
| 55 | + |
| 56 | +```baa |
| 57 | +صحيح الرئيسية() |
| 58 | +صحيح الرئيسية(صحيح عدد، نص[] معاملات) |
| 59 | +``` |
| 60 | + |
| 61 | +Bootstrap work must not assume additional accepted entry-point shapes. |
| 62 | + |
| 63 | +## Frozen Standard Library Surface |
| 64 | + |
| 65 | +`stdlib/baalib.baahd` is the canonical stdlib signature surface for bootstrap work. |
| 66 | + |
| 67 | +The current frozen modules are: |
| 68 | + |
| 69 | +- string APIs |
| 70 | +- dynamic memory APIs |
| 71 | +- file I/O APIs |
| 72 | +- math APIs |
| 73 | +- system APIs |
| 74 | +- time APIs |
| 75 | +- error-handling APIs |
| 76 | +- variadic intrinsics |
| 77 | + |
| 78 | +Freeze rules: |
| 79 | + |
| 80 | +- exact callable signatures come from `stdlib/baalib.baahd` |
| 81 | +- ownership rules documented there are part of the contract |
| 82 | +- heap-returning APIs remain heap-returning APIs and must be freed by the caller as documented |
| 83 | +- no new stdlib signatures should be introduced under the bootstrap freeze without explicitly |
| 84 | + revising this contract |
| 85 | + |
| 86 | +## Frozen Target / ABI Surface |
| 87 | + |
| 88 | +Only these targets are in scope for the freeze: |
| 89 | + |
| 90 | +- `x86_64-windows` |
| 91 | +- `x86_64-linux` |
| 92 | + |
| 93 | +Windows x64 ABI contract: |
| 94 | + |
| 95 | +- integer/pointer argument registers: `RCX`, `RDX`, `R8`, `R9` |
| 96 | +- return register: `RAX` |
| 97 | +- 32-byte shadow space at call boundaries |
| 98 | +- object format: COFF/PE |
| 99 | +- executable suffix default: `.exe` |
| 100 | + |
| 101 | +SystemV AMD64 ABI contract: |
| 102 | + |
| 103 | +- integer/pointer argument registers: `RDI`, `RSI`, `RDX`, `RCX`, `R8`, `R9` |
| 104 | +- return register: `RAX` |
| 105 | +- no shadow space |
| 106 | +- varargs path currently emits `AL=0` when no XMM arguments are used |
| 107 | +- object format: ELF |
| 108 | +- executable suffix default: empty |
| 109 | + |
| 110 | +Shared target limits: |
| 111 | + |
| 112 | +- x86-64 only |
| 113 | +- current data layout stays 64-bit and identical across the two supported x86-64 targets |
| 114 | +- cross-target assembly generation is supported; bootstrap work must not assume broader host/toolchain |
| 115 | + guarantees than the current compiler documents |
| 116 | + |
| 117 | +## Frozen IR / Verifier Surface |
| 118 | + |
| 119 | +The bootstrap freeze relies on the current Baa IR contract, not a future generalized IR. |
| 120 | + |
| 121 | +Frozen guarantees: |
| 122 | + |
| 123 | +- SSA-form IR before Out-of-SSA |
| 124 | +- verifier-backed single-definition SSA discipline |
| 125 | +- verifier-backed dominance and phi incoming-edge checks |
| 126 | +- verifier-backed well-formedness for: |
| 127 | + - operand counts |
| 128 | + - type consistency |
| 129 | + - terminator rules |
| 130 | + - phi placement |
| 131 | + - intra-module call signature checks |
| 132 | +- current x86-64 data-layout assumptions |
| 133 | +- current typed-memory model for `حجز` / `حمل` / `خزن` |
| 134 | + |
| 135 | +Non-guarantees: |
| 136 | + |
| 137 | +- no promise of new IR opcodes for bootstrap |
| 138 | +- no promise of new alias-analysis precision |
| 139 | +- no promise of non-x86-64 data layouts in this freeze |
| 140 | + |
| 141 | +## Frozen Unsupported Surface |
| 142 | + |
| 143 | +The following remain intentionally unsupported under the freeze and must stay unsupported unless a |
| 144 | +later milestone explicitly reopens them: |
| 145 | + |
| 146 | +- variadic function-pointer calls |
| 147 | +- advanced inline-assembly constraints and clobber lists beyond the currently documented subset |
| 148 | +- additional entry-point signatures beyond the two frozen forms |
| 149 | +- new bootstrap-relevant syntax churn in grammar/type spelling |
| 150 | +- new target families or ABI contracts beyond current Windows x64 and SystemV AMD64 support |
| 151 | + |
| 152 | +## Enforcement Expectations |
| 153 | + |
| 154 | +The freeze is locked by: |
| 155 | + |
| 156 | +- documentation synchronization against the canonical sources above |
| 157 | +- existing verifier paths: `--verify-ir`, `--verify-ssa`, and `--verify` |
| 158 | +- focused integration tests that lock: |
| 159 | + - stdlib short include behavior |
| 160 | + - entry-point argument lowering |
| 161 | + - SysV register-argument behavior |
| 162 | + - Windows shadow-space/register-call behavior |
| 163 | + - verifier-safe CFG/phi compilation |
| 164 | + |
| 165 | +This document is the bootstrap-facing summary, but it does not replace the detailed language, |
| 166 | +stdlib, ABI, and IR references that define exact syntax and declarations. |
0 commit comments