go: eval.sx — for / break / continue / inc-dec + 7 tests [nothing]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 26s
Phase 4 cont. go-eval-for handles all three for-header shapes:
for { ... } — infinite (cond defaults to true)
for cond { ... } — while-like (init=nil, post=nil)
for init ; cond ; post { ... } — C-style
Implementation:
* Run INIT (if any), extending env.
* Loop: eval COND. If false, exit with current env.
Eval body (a :block). Catch sentinels:
:return-value → propagate up
:break → exit loop with pre-break env
:continue → still runs POST, then re-loops
Otherwise: run POST, re-loop.
:break and :continue propagate as keyword sentinels through
go-eval-block alongside the existing :return-value sentinel. The
block returns whichever sentinel hit first; control-flow constructs
(for, switch, select) catch them.
inc-dec (x++ / x--) updates env via the same shadowing model used by
assign — `(go-env-extend env name (+ current 1))`.
**Iterative fact(5) = 120 and the classic sum-to-9 = 45 both
evaluate.** Demonstrates the for-loop machinery is solid enough for
real programs.
eval 40/40, total 417/417.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -270,8 +270,10 @@ Progress-log line → push `origin/loops/go`.
|
||||
- [x] Scaffold: env-as-value, literal decoding (decimal/hex/oct/bin
|
||||
with underscores), variable lookup (incl. predeclared true/false/nil),
|
||||
arithmetic + comparison + logical binops. eval suite at 25/25.
|
||||
- [/] Statement evaluation: block / return / short-decl / assign /
|
||||
var-decl / if done; for / break / continue pending.
|
||||
- [x] Statement evaluation: block / return / short-decl / assign /
|
||||
var-decl / if / for (all three header shapes) / break / continue /
|
||||
inc-dec all done. `:break` and `:continue` propagate as sentinel
|
||||
keywords through `go-eval-block` until `go-for-loop` catches them.
|
||||
- [ ] Variables as mutable cells; pointer semantics: `&x` returns the
|
||||
cell, `*p` dereferences.
|
||||
- [ ] Slices: triple (length, capacity, backing-vector). `append`
|
||||
@@ -283,7 +285,7 @@ Progress-log line → push `origin/loops/go`.
|
||||
- [ ] Channels: stub (Phase 5 wires them).
|
||||
- Tests: arithmetic, control flow, recursion, closures, slices, maps,
|
||||
structs, methods, pointer semantics, multiple-return.
|
||||
- **Acceptance:** eval/ suite at 80+ tests. Current: 33/33. No concurrency yet.
|
||||
- **Acceptance:** eval/ suite at 80+ tests. Current: 40/40. No concurrency yet.
|
||||
|
||||
### Phase 5 — Goroutines + channels + select (`lib/go/sched.sx`) ⬜
|
||||
- **Independent implementation.** Do NOT use lib/guest/scheduler/ — that
|
||||
@@ -567,6 +569,16 @@ Minimal repro: see `lib/go/lex.sx#gl-oct-digit?` and `#gl-match-op`.
|
||||
|
||||
_Newest first. Append one dated entry per commit._
|
||||
|
||||
- 2026-05-27 — Phase 4 cont.: for-loops, break, continue, inc-dec.
|
||||
`go-eval-for` handles all three for-header shapes (infinite, while-
|
||||
like, C-style) including init+post stmts and missing-cond defaulting
|
||||
to true. `:break` and `:continue` propagate as keyword sentinels
|
||||
through `go-eval-block` (alongside the existing `:return-value`
|
||||
sentinel) until `go-for-loop` catches them — break exits, continue
|
||||
runs post and re-loops. Inc-dec `x++`/`x--` updates env via the
|
||||
same shadowing model as assign. **Iterative `fact(5) = 120` and the
|
||||
classic for-loop sum-to-9 (= 45) both evaluate.** +7 tests, eval
|
||||
40/40, total 417/417. `[nothing]`.
|
||||
- 2026-05-27 — Phase 4 cont.: statements + function application.
|
||||
`go-eval-stmt` handles `:return` (propagates a `:return-value`
|
||||
sentinel up through blocks), `:var-decl`, `:short-decl`, `:assign`
|
||||
|
||||
Reference in New Issue
Block a user