go: eval.sx — structs + selector + selector-assign + 8 tests [nothing]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s

Phase 4 cont. Adds runtime support for Go's struct type.

Struct representation: (list :go-struct TYPE-NAME FIELDS) where
FIELDS is an association list of (field-name value) pairs.

`type T struct { ... }` is now significant at eval-time. The new
go-eval-type-decl registers field-name lists in env under
(:go-struct-type FIELD-NAMES) so positional composite literals can
map argument positions to field names. Non-struct type aliases are
silent no-ops in v0.

go-eval-composite extended:
  * If type is (:var TYPE-NAME), look up in env. Must be a
    :go-struct-type entry — error otherwise.
  * go-eval-struct-lit branches on whether the first elem is :kv
    (keyed) or not (positional). Keyed mode reads key-name from each
    :kv's key (which is a :var node). Positional mode arity-checks
    against the field-names list and zips positionally.

go-eval-select handles (:select OBJ FIELD-NAME) — field lookup with
go-map-get on the FIELDS assoc list.

go-eval-assign-pairs gets a new (:select OBJ FIELD) LHS branch:
  - var-rooted only for v0
  - rebuilds the struct via go-map-set, rebinds the var

**Functions taking and returning structs round-trip end-to-end:**

  type Point struct { x, y int }
  func add(a, b Point) Point { return Point{a.x + b.x, a.y + b.y} }
  add(Point{1, 2}, Point{3, 4})  // Point{4, 6}

Method-dispatch (calling p.M() where M is a method on Point's type)
is the next step; needs threading the type checker's #method/T/N
scheme into eval-time so functions can be looked up by receiver type.

eval 66/66, total 443/443.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-27 21:39:06 +00:00
parent 9ed58bd0fc
commit 99f8f37ff8
5 changed files with 219 additions and 7 deletions

View File

@@ -287,13 +287,19 @@ Progress-log line → push `origin/loops/go`.
(nil for missing key, until runtime type info enables zero-value),
`m[k] = v` index-assignment, `len(m)`. Index-assignment for slices
also lands here (`a[i] = v` rebuilds via `go-slice-set`).
- [ ] Structs: SX dict + type tag. Methods looked up via type's table.
- [/] Structs: `(list :go-struct TYPE-NAME FIELDS)` where FIELDS is an
assoc list. `type Point struct {...}` registers field names in
env via `(:go-struct-type FIELD-NAMES)`; positional and keyed
composite literals build struct values; `p.field` selector and
`p.field = v` selector-assignment work. Methods lookup-by-receiver
pending — depends on threading the type checker's method-key
scheme into eval.
- [/] 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: 58/58. No concurrency yet.
- **Acceptance:** eval/ suite at 80+ tests. Current: 66/66. No concurrency yet.
### Phase 5 — Goroutines + channels + select (`lib/go/sched.sx`) ⬜
- **Independent implementation.** Do NOT use lib/guest/scheduler/ — that
@@ -577,6 +583,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 4 cont.: structs + selector access +
selector-assignment. `(:go-struct TYPE-NAME FIELDS)` value, with
FIELDS an assoc list. `type T struct {...}` is now significant at
eval-time too: registers `(:go-struct-type FIELD-NAMES)` in env so
positional composite literals like `Point{1, 2}` can map positions
to field names. Keyed literals `Point{x: 5, y: 10}` also work.
`go-eval-select` does field lookup; LHS `:select` in
`go-eval-assign-pairs` does field update. **`add(Point{1,2},
Point{3,4}) → Point{4,6}` works end-to-end** — functions receiving
and returning structs round-trip through the evaluator. +8 tests,
eval 66/66, total 443/443. Method-dispatch (looking up methods by
receiver type) pending; needs threading the type checker's
`#method/T/N` scheme into eval. `[nothing]`.
- 2026-05-27 — Phase 4 cont.: maps + index-assignment. Maps represented
as `(list :go-map ENTRIES)` where ENTRIES is an assoc list. New
helpers `go-map-get` / `go-map-set` / `go-slice-set`. Composite-lit