selfhost: port forrange — N_FORRANGE parser + cgen + tuple destructure
This commit is contained in:
@@ -154,6 +154,32 @@ fn resolvewalk(c: *checker, n: *node) void = {
|
||||
};
|
||||
};
|
||||
|
||||
// `for (let x .. slice) body` / `for (let (a, b) .. slice) body` —
|
||||
// each binding name becomes a fresh local. Walk the slice expr first
|
||||
// so its idents resolve before the bindings shadow anything, then
|
||||
// install bindings and walk the body/else.
|
||||
if (k == nkind.N_FORRANGE) {
|
||||
if (n.lhs != nil) { resolvewalk(c, n.lhs); };
|
||||
if (n.list != nil) {
|
||||
let m: *node = n.list;
|
||||
for (m != nil) {
|
||||
let bnm: str = m.str;
|
||||
if (bnm.len > 0) {
|
||||
scopedefine(c.cur, bnm, skind.SK_VAR, nil, m);
|
||||
};
|
||||
m = m.next;
|
||||
};
|
||||
} else {
|
||||
let bnm: str = n.str;
|
||||
if (bnm.len > 0) {
|
||||
scopedefine(c.cur, bnm, skind.SK_VAR, nil, n);
|
||||
};
|
||||
};
|
||||
if (n.body != nil) { resolvewalk(c, n.body); };
|
||||
if (n.els != nil) { resolvewalk(c, n.els); };
|
||||
return;
|
||||
};
|
||||
|
||||
// `match (e) { case let v: T => stmt; ... }` — the binding `v`
|
||||
// is declared by the case arm and visible inside its body.
|
||||
if (k == nkind.N_MCASE) {
|
||||
|
||||
Reference in New Issue
Block a user