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
|
|
@ -196,7 +196,7 @@ fn ui_tw(font: int, s: ptr, size: int) -> int {
|
|||
if font >= 0 {
|
||||
if font < tt_n { return rt_text_w(font, s, size) }
|
||||
}
|
||||
let n = 0
|
||||
var n = 0
|
||||
while peek8(s, n) != 0 { n = n + 1 }
|
||||
return n * 6 * max(size / 8, 1)
|
||||
}
|
||||
|
|
@ -219,7 +219,7 @@ fn ui_dir(t: int) -> int {
|
|||
return 1
|
||||
}
|
||||
fn ui_under(i: int, root: int) -> bool {
|
||||
let k = i
|
||||
var k = i
|
||||
while k >= 0 {
|
||||
if k == root { return true }
|
||||
k = peek32(ui_parent, k)
|
||||
|
|
@ -229,7 +229,7 @@ fn ui_under(i: int, root: int) -> bool {
|
|||
|
||||
# ---- measure: content sizes, children before parents ----------------------
|
||||
fn ui_measure() -> void {
|
||||
let i = ui_n - 1
|
||||
var i = ui_n - 1
|
||||
while i >= 0 {
|
||||
if peek32(ui_visible, i) == 0 {
|
||||
poke32(ui_rw, i, 0)
|
||||
|
|
@ -237,8 +237,8 @@ fn ui_measure() -> void {
|
|||
} else {
|
||||
let t = peek32(ui_type, i)
|
||||
let pad = peek32(ui_pad, i)
|
||||
let cw = 0
|
||||
let ch = 0
|
||||
var cw = 0
|
||||
var ch = 0
|
||||
if t == WT_LABEL { cw = 0 - 1 }
|
||||
if t == WT_BUTTON { cw = 0 - 1 }
|
||||
if cw == 0 - 1 {
|
||||
|
|
@ -262,9 +262,9 @@ fn ui_measure() -> void {
|
|||
ch = peek32(ui_h, i)
|
||||
} else {
|
||||
let dir = ui_dir(t)
|
||||
let mainsz = 0
|
||||
let cross = 0
|
||||
let nc = 0
|
||||
var mainsz = 0
|
||||
var cross = 0
|
||||
var nc = 0
|
||||
for c in 0 .. ui_n {
|
||||
if peek32(ui_parent, c) == i {
|
||||
if peek32(ui_visible, c) == 1 {
|
||||
|
|
@ -292,8 +292,8 @@ fn ui_measure() -> void {
|
|||
}
|
||||
}
|
||||
}
|
||||
let rw = peek32(ui_w, i)
|
||||
let rh = peek32(ui_h, i)
|
||||
var rw = peek32(ui_w, i)
|
||||
var rh = peek32(ui_h, i)
|
||||
if rw == 0 { rw = cw }
|
||||
if rh == 0 { rh = ch }
|
||||
poke32(ui_rw, i, rw)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue