go: parse.sx — go/defer/send/for-range + 9 tests [shapes-scheduler]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 28s

Adds Go's concurrency + iteration primitives to the statement parser:

  go EXPR                     →  (list :go EXPR)
  defer EXPR                  →  (list :defer EXPR)
  ch <- v                     →  (list :send CHAN VALUE)
  for range COLL { ... }      →  (list :range-for nil nil nil COLL BODY)
  for k := range C { ... }    →  (list :range-for :short-decl KEY nil COLL BODY)
  for k, v := range C { }     →  (list :range-for :short-decl KEY VAL COLL BODY)
  for k, v = range C { ... }  →  (list :range-for :assign KEY VAL COLL BODY)

gp-for-find-range pre-scans the for-header (to '{' or eof) looking
for the 'range' keyword; if present, dispatches to gp-parse-for-range
which handles the four range shapes. C-style and while-like and
infinite are now in gp-parse-for-c-style — gp-parse-for is just a
dispatcher.

Send statement detection lives in the LHS-list branch of gp-parse-stmt:
after parsing a single LHS expression, '<-' triggers (:send LHS RHS).
Channel-recv (`<-ch`) was already parsed as unary `<-` in the expression
layer, so both directions cover.

This is the **chiselling-relevant iteration** for the scheduler sister
kit: the AST shapes Go-on-SX will eventually feed into the kit's
scheduler primitives (sched-spawn, sched-defer, chan-op) have landed.
Sister-plan diary updated with three design insights:

  * :go / :defer both wrap a single expr — kit's sched-spawn should
    accept a thunk uniformly across Erlang's spawn(M,F,A) and Go's
    go fn().
  * :send carries CHAN+VALUE symmetrically with the unary <- recv —
    both reduce to (chan-op direction chan value) in the kit.
  * `for v := range ch` uses the same :range-for shape as range-over-
    slice; the scheduler kit's range dispatch is where chan-recv ⇄
    iteration polymorphism lives.

parse 161/161, total 290/290.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-27 20:24:23 +00:00
parent ba41f8a580
commit 171a08a2f8
6 changed files with 233 additions and 40 deletions

View File

@@ -196,19 +196,17 @@ Progress-log line → push `origin/loops/go`.
canonical AST kit. Grouped/parenthesized decls (`var (...)`, etc.)
and variadic params deferred. Anonymous param-list disambiguation
(`func(int, string)`) is a known parser-greedy limitation, flagged.
- [/] Statements: `return`, short-decl `:=`, assign `=`, compound assign
(`+=` etc.), expression stmt, block `{...}`, **if/else (with chained
else-if), for (infinite / while-like / C-style), break, continue,
inc-dec (`x++` / `x--`)** all done. **Composite-literal `{`
suppression** active in control-flow conditions via
`gp-no-comp-lit` counter — closes the parser-mode caveat flagged
when composite literals landed. `switch`/`select`/`defer`/`go`/
`for...range`/send `ch<-v` deferred.
- [/] Statements: return, short-decl, assign, compound assign, expr stmt,
block, if/else (chained), for (4 shapes incl. range), break,
continue, inc-dec, **`go EXPR`, `defer EXPR`, send `ch <- v`,
`for k, v := range coll`** all done. Composite-literal `{`
suppression active in control-flow conditions. `switch` and
`select` deferred.
- [ ] End-to-end: hello-world, fibonacci, FizzBuzz, goroutine ping-pong,
struct + method.
- **Acceptance:** parse/ suite at 80+ tests. **Acceptance bar crossed:
152/152.** Remaining sub-items (switch/select/defer/go/range,
end-to-end programs) keep Phase 2 open ⬜.
161/161.** Remaining sub-items (switch/select, end-to-end programs)
keep Phase 2 open ⬜.
### Phase 3 — Bidirectional type checker, MVP (`lib/go/types.sx`) ⬜
- **Independent implementation.** Do NOT use lib/guest/static-types-
@@ -525,6 +523,19 @@ 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 2 cont.: concurrency + iteration statements.
`go EXPR`, `defer EXPR`, channel send `ch <- v`, and the four
`for ... range` shapes (no-kv / k-only / k,v / assign-form). New
`gp-for-find-range` pre-scans the for-header to dispatch between
range and C-style/while forms cleanly. Send-stmt detection added to
the LHS-list branch (after lhs, `<-` → send). +9 tests, parse
161/161, total 290/290. `[shapes-scheduler]` — Go's concurrency-
primitive AST shapes (`:go`, `:defer`, `:send`, `:range-for`) all
landed; sister-plan diary updated with the corresponding kit-API
insights (uniform spawn-thunk shape, channel-recv ⇄ iteration
polymorphism at the range-coll dispatch).
Sister-plan diary update follows.
- 2026-05-27 — Phase 2 cont.: control-flow statements. `if cond { } [else
{ }]` with chained else-if, `for { }` (infinite), `for cond { }`
(while-like), `for init; cond; post { }` (C-style), `break`,