go: eval.sx — stmts + function application; recursive fib evaluates + 8 tests [nothing]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 28s

Phase 4 cont. go-eval-stmt dispatches on:
  :return       → wraps value in (:return-value V) sentinel
  :var-decl     → bind each NAME via go-eval-var-decl
  :short-decl   → bind each (:var NAME) lhs to corresponding expr value
  :assign       → immutable-env shadowing (true mutation deferred)
  :block        → run stmts via go-eval-block, propagating :return-value
  :if / :else   → cond-driven dispatch
  :func-decl    → bind name to (list :go-fn PARAMS BODY)
  else          → expression statement, evaluate for side effects

go-eval-call extends the CALLER's env with param-names → arg-values
(dynamic-scope-ish — closures don't capture lexical env yet), runs the
body block, catches :return-value and unwraps.

**Recursive fib(5) = 5 evaluates correctly.** Recursion works because
top-level func bindings are in the calling env before the recursive
call happens.

True lexical closures (let bind sees outer var; assignments visible to
nested funcs) need an env-cell model with mutation; deferred to a
later slice.

eval 33/33, total 410/410.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-27 21:17:26 +00:00
parent ff9abe3ae6
commit 1340c2626b
5 changed files with 329 additions and 33 deletions

View File

@@ -270,19 +270,20 @@ 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 / for / break / continue.
- [/] Statement evaluation: block / return / short-decl / assign /
var-decl / if done; for / break / continue pending.
- [ ] Variables as mutable cells; pointer semantics: `&x` returns the
cell, `*p` dereferences.
- [ ] Slices: triple (length, capacity, backing-vector). `append`
honours capacity-grow per spec.
- [ ] Maps: SX dict + key-type metadata.
- [ ] Structs: SX dict + type tag. Methods looked up via type's table.
- [ ] Functions: closures over enclosing scope; multiple return values.
- [/] Functions: top-level definition + call (incl. recursion via the
calling env). Lexical closures and multiple return values pending.
- [ ] 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: 25/25. No concurrency yet.
- **Acceptance:** eval/ suite at 80+ tests. Current: 33/33. No concurrency yet.
### Phase 5 — Goroutines + channels + select (`lib/go/sched.sx`) ⬜
- **Independent implementation.** Do NOT use lib/guest/scheduler/ — that
@@ -566,6 +567,18 @@ 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.: statements + function application.
`go-eval-stmt` handles `:return` (propagates a `:return-value`
sentinel up through blocks), `:var-decl`, `:short-decl`, `:assign`
(immutable-env shadowing), `:block`, `:if`/`:else`, and `:func-decl`
(binds a `:go-fn` value). `go-eval-call` extends the caller's env
with params → arg values, runs the body block, unwraps the return.
**Recursive `fib(5) = 5` evaluates correctly** — recursion works
because top-level funcs are bound in the calling env before any
recursive call happens; the func value carries no captured env in
v0 (dynamic-scope-ish), so true lexical closures wait for a later
slice. +8 tests, eval 33/33, total 410/410. `[nothing]` — pure eval
composition.
- 2026-05-27 — **Phase 3 ticked; Phase 4 scaffold.** Short-decl `:=`
marked done (was already covered by go-check-short-decl from the
decl-checking iteration). New `lib/go/eval.sx`: env-as-value (same