Phase 6f: let = immutable, var = mutable (binding-only)
Bindings now signal mutability the way Rust/Swift do, instead of `let` meaning
"local" and `var` meaning "module-level":
- `let x = e` -> immutable binding; a later `x = …` is a compile error
(`cannot assign to immutable 'x' … use var`).
- `var x = e` -> mutable binding, at local OR module scope (position decides
scope; the keyword decides mutability).
- `const` -> unchanged (compile-time).
Immutability is of the *binding*, not the object: `let n = new Node; n.kind = 1`
is fine (mutation through the reference); only rebinding `n` is rejected. The
check lives in emit_assign — a direct `name =` whose target is a `let` local
(loc_mut == 0) errors; field/index targets and `var`/param/loop bindings are
unaffected.
Delivered as three reseeds so the self-hosting compiler never had to compile
source its own rules would reject:
A) add `var` as a local statement + per-local mutability tracking (loc_mut),
no enforcement;
B) migrate every reassigned `let` -> `var` across the compiler, runtime and
examples (337 declarations), driven by a per-function, string/comment-aware
scan (binding targets only, never `x.f =` / `x[i] =`);
C) turn on the check. bootstrap-cfree (compiler vs its own source) and every
golden build (which splices the runtime) then proved zero reassigned `let`
was missed anywhere.
Also folded in: removed leftover debug instrumentation in block() (a `cur=` /
print_int(777…) trace on the separator-error path) and fixed parse.ludic's stale
header comment (no more `struct`). Reseeded (21711 lines); C-free fixpoint holds;
goldens identical; 17/17; vocab + doc-fences clean.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
parent
573813609c
commit
e1d7797e29
38 changed files with 2909 additions and 2778 deletions
|
|
@ -5,8 +5,8 @@ handler Draw phase Render {
|
|||
clear(0x101018)
|
||||
|
||||
if m == 0 {
|
||||
let cx = 0
|
||||
let cy = 0
|
||||
var cx = 0
|
||||
var cy = 0
|
||||
for (p) in query [Pos, {Player}] {
|
||||
cx = clamp(p.x * 16 - 152, 0, MW * 16 - 320)
|
||||
cy = clamp(p.y * 16 - 112, 0, MH * 16 - 240)
|
||||
|
|
@ -18,7 +18,7 @@ handler Draw phase Render {
|
|||
let c = tile(tx, ty)
|
||||
let sx = tx * 16 - cx
|
||||
let sy = ty * 16 - cy
|
||||
let base = SPR_GRASS
|
||||
var base = SPR_GRASS
|
||||
match c {
|
||||
'r' => base = SPR_PATH
|
||||
',', 'S', 'B' => base = SPR_FLOOR
|
||||
|
|
@ -57,7 +57,7 @@ handler Draw phase Render {
|
|||
if m == 1 {
|
||||
fill_rect(0, 0, 320, 176, 0x241a2e)
|
||||
for (e, a) in query [Stats, Actor, {Enemy}] {
|
||||
let bs = 5
|
||||
var bs = 5
|
||||
if reg(R_ETYPE) == 2 { bs = 7 }
|
||||
draw_sprite_scaled(a.kind, 160 - bs * 8, 44, bs)
|
||||
text(100, 20, enemy_name(reg(R_ETYPE)), 0xffffff, 1)
|
||||
|
|
@ -65,14 +65,14 @@ handler Draw phase Render {
|
|||
fill_rect(100, 30, e.hp * 120 / e.maxhp, 8, 0xe04040)
|
||||
}
|
||||
let ph = reg(R_PHASE)
|
||||
let act = 0
|
||||
var act = 0
|
||||
if ph >= 2 { act = 1 }
|
||||
if ph >= 4 { act = 2 }
|
||||
fill_rect(0, 176, 320, 64, 0x0c0c16)
|
||||
frame_rect(0, 176, 320, 64, 0x3a3a55)
|
||||
for (st, pt) in query [Stats, Party] {
|
||||
let hx = 6 + pt.slot * 92
|
||||
let spr = 5
|
||||
var spr = 5
|
||||
if pt.slot == 1 { spr = 9 }
|
||||
if pt.slot == act { frame_rect(hx - 2, 180, 88, 44, 0xffff00) }
|
||||
draw_sprite_scaled(spr, hx, 184, 2)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue