Skip to content

feat(frontend): real statement lowering — let/if/else/while/indexed access + parser skip_declaration fix#199

Merged
hyperpolymath merged 1 commit into
mainfrom
feat/frontend-control-flow
Jul 7, 2026
Merged

feat(frontend): real statement lowering — let/if/else/while/indexed access + parser skip_declaration fix#199
hyperpolymath merged 1 commit into
mainfrom
feat/frontend-control-flow

Conversation

@hyperpolymath

Copy link
Copy Markdown
Owner

Increment 2 of 3 on the independence construction path.

The statement lowerer takes ECS-style bodies (examples 03/04) from representative stubs to real typed loads/stores with pinned access sites: let, assignment, if/else, while, indexed region.get/set $h[i] .f, cast<>, typed expressions with precedence and no implicit promotion. Region params are copied to a base local once in the prologue, so own/&mut discipline survives arbitrarily many accesses under the verifier's per-path use counting.

Also fixes a real parser bug found by the new tests: skip_declaration skipped a balanced {…} and then kept scanning for a ;, so example-04's top-level invariant … { … } blocks swallowed every following declaration — ex04's functions were never parsed at all (its corpus "round-trip" was regions-only). After the fix ex04 parses 4 functions and 3 lower for real.

Verification: all-passes gate (structural validation + L7/L10 + L2 bounds + L2 access-typing on the pinned sites) over both examples, plus a wasmi execution gate proving the lowered control flow computes correct results (both if-branches, loop entry/skip, cast round-trip). 166 workspace tests, 0 failures.

🤖 Generated with Claude Code

…ccess + skip_declaration bug fix

Takes example 03/04 system bodies from representative stubs to REAL
typed loads/stores with pinned access sites, executed correctly in a
real engine.

- parser: general statement lowerer (tried after the exact reader/
  writer shapes; bails to the stub on anything unsupported). Covers
  `let [mut] x: ty = expr`, assignment, `if`/`else`, `while` (block/
  loop/br_if), `return [expr]`, indexed `region.get/set $h[i] .f`
  (base + i*stride), `cast<i32|f32|f64>`, typed expression lowering
  with precedence (cmp > add > mul > primary) and no implicit
  promotion. Each region param is copied to a base local ONCE in the
  prologue so own/&mut discipline holds under per-path use counting
  regardless of how many accesses follow.
- IR: Op gains locals/control-flow/arithmetic/conversion instructions;
  Func gains `locals` (emitted via Function::new_with_locals_types).
- REAL BUG FIX: skip_declaration skipped a balanced `{...}` block and
  then KEPT SCANNING for a `;` — so example-04's top-level
  `invariant ... { ... }` blocks swallowed every following declaration:
  ex04's functions were never parsed at all (its "6/6 corpus
  round-trip" was regions-only). Now returns after a block-shaped
  declaration; ex04 parses 4 functions, 3 lower for real.
- tests/example04.rs: real-lowering assertions for ex03/ex04 bodies
  (pinned sites), all-verifier-passes gate (validate + L7/L10 + L2
  bounds + L2 access-typing), and a wasmi execution gate proving
  while/if-else/indexed/cast lowering COMPUTES correct results
  (sum-abs + f32-scale over a cell array).

Workspace: 166 tests, 0 failures.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@hyperpolymath
hyperpolymath merged commit 7d991a7 into main Jul 7, 2026
16 of 24 checks passed
@hyperpolymath
hyperpolymath deleted the feat/frontend-control-flow branch July 7, 2026 04:53
@sonarqubecloud

sonarqubecloud Bot commented Jul 7, 2026

Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant