fix(compiler): preserve declared type of const references
A const reference lowered to `val(itoa(g.a.ival), "int")` in emit_call.ludic — the initializer's raw integer bits, hardcoded as `int`. For a fixed const like `const X: fixed = 10.0` that yielded the Q16.16 bits (655360) typed as int, so every fixed comparison/arithmetic against it silently broke (it caused an infinite loop in runtime/native/numeric.ludic, previously worked around with inline literals). Fix: a const reference now emits its initializer expression via emit_expr(g.a), which carries the initializer's real type (E_FLOAT->fixed, E_BOOL->bool, E_STR->string) and even handles computed initializers. Every existing const is an int literal, for which this is byte-identical to the old immediate — the C-free bootstrap fixpoint and all golden renders are unchanged. - selfhost/tests/const.ludic + sh_case pin fixed/int/bool const behaviour. - runtime/native/numeric.ludic restored to named fixed consts (HUGE_TEN etc.), which the workaround had inlined; the numeric example (20 assertions) still passes, validating the fix under runtime splice. All suites green: x selfhost-test 31/31 (fixpoint holds, goldens byte-identical), x test 85/85, x test-tools 30/30. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
790eda6f73
commit
7c91d24595
6 changed files with 3680 additions and 3641 deletions
|
|
@ -925,7 +925,11 @@ function emit_expr(e: Node) -> Val {
|
|||
if li >= 0 { return emit_load_at(loc_reg[li], loc_ty[li]) }
|
||||
let g = find_global(e.s)
|
||||
if (g != null) {
|
||||
if g.kind == N_CONST { return val(itoa(g.a.ival), "int") }
|
||||
# a const reference IS its initializer expression, carrying that
|
||||
# expression's real type — so `const X: fixed = 10.0` yields a `fixed`, not
|
||||
# the raw Q16.16 bits mislabelled `int`. Every existing const is an int
|
||||
# literal, for which this is byte-identical to the old immediate.
|
||||
if g.kind == N_CONST { return emit_expr(g.a) }
|
||||
let r = emit_bind(`load {llty(g.ty)}, ptr @g_{e.s}`)
|
||||
return val(r, g.ty)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue