docs: const-aggregate semantics + unchecked-pointer contract (PLAN-CONST-AGG step 6)

This commit is contained in:
agra
2026-06-11 13:54:35 +03:00
parent 40a94c4734
commit c229f697bd
3 changed files with 148 additions and 6 deletions

View File

@@ -126,6 +126,27 @@ int+float arithmetic promotes to the float in either operand order (`n + 0.5` an
`0.5 + n` are both `f64`), so `C : s64 : M + 0.5` is rejected regardless of order
while `F : f64 : M + 0.5` folds to `2.5`.
**Aggregate constants.** Array- and struct-typed `::` constants are immutable
globals — one storage, reads index into it directly, whole-value uses copy by
value, and unused tables are dropped from the binary. `::` is the one and only
const spelling (`const` is not a keyword):
```sx
K : [4]s64 : .[11, 22, 33, 44]; // typed array const
A :: .[1, 2, 3]; // untyped — infers [3]s64
M :: .[1, 2.2, 3]; // numeric mix promotes — [3]f64
LIT :: Color.{ r = 255, g = 0, b = 0 }; // struct const — also one global
N :: K[0] + K[3]; // 55 — const element reads fold at compile time
D : [K.len]u8 = ---; // [4]u8 — .len and LIT.r fold in dimensions too
K[0] = 5; // error: cannot assign through constant 'K'
```
Writes through any constant's name — element, field, compound — are compile
errors; a local copy (`k := K`) stays writable. A struct constant whose
initializer calls a function (`CALL :: Color.{ r = bump(), … }`) is re-evaluated
at each use (documented contract); use `NAME :: #run f();` for evaluate-once.
**Float → integer narrowing (unified rule).** A float flowing into an
integer-typed binding *without* a cast follows the same integral-fold rule an
array dimension uses: an **integral** compile-time float folds to its integer, a