go: eval.sx scaffold — literals + vars + binops + 25 tests; Phase 3 closed [nothing]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s

Phase 3 — bidirectional type checker — is fully ticked (short-decl
was already implemented). Phase 4 starts here.

lib/go/eval.sx single judgment:

  (go-eval ENV EXPR)  →  VALUE | (list :eval-error TAG ...)

ENV is an association list of (NAME VALUE) bindings — same shape as
the type checker's ctx, but the entries are runtime values. Values
are represented directly in SX: integers/floats as SX numbers,
strings as SX strings, booleans as true/false, nil as nil. Composite
values (slices/maps/structs/pointers/channels) arrive in later slices.

First-slice coverage:

  * go-env-empty / -lookup / -extend
  * Literal decoding:
      decimal (with underscores)
      hex (0x.. / 0X..)
      oct (0o.. / 0O..)
      bin (0b.. / 0B..)
    via go-hex-digit-value (explicit char equality — SX's nth on
    strings returns single-char strings, not numeric codes; the
    arithmetic-on-char-codes pattern from the OCaml kernel ports
    doesn't work here).
  * Identifier lookup with predeclared true / false / nil.
  * Binops: + - * / and the six comparison ops and && / ||.
  * Errors as (:eval-error TAG ...) sentinels.

Statements (block / return / short-decl / assign), control flow
(if / for), and function application / closures arrive in subsequent
slices.

eval 25/25, total 402/402.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-27 21:11:20 +00:00
parent 21bb17e4a6
commit ff9abe3ae6
6 changed files with 350 additions and 21 deletions

View File

@@ -213,7 +213,7 @@ Progress-log line → push `origin/loops/go`.
**Phase 2 complete.** Type-switch is the one syntactic shape still
deferred to a follow-up; it doesn't gate Phase 3.
### Phase 3 — Bidirectional type checker, MVP (`lib/go/types.sx`)
### Phase 3 — Bidirectional type checker, MVP (`lib/go/types.sx`)
- [x] Scaffold: `go-synth` / `go-check` skeletons; context-as-value
(`go-ctx-empty` / `-extend` / `-lookup` / `-extend-field`);
predeclared `true`/`false`/`nil`; structural type equality.
@@ -255,7 +255,9 @@ Progress-log line → push `origin/loops/go`.
value and pointer receivers). `go-iface-satisfies?` walks an
interface's `:method` elements and looks each up; partial sets
and arity-mismatches fail. Embedded interfaces deferred.
- [ ] Short variable declaration `:=` (synth RHS into LHS bindings).
- [x] Short variable declaration `:=` (synth RHS into LHS bindings).
Handled inline by `go-check-short-decl` since the decl-checking
slice; works both at top-level and inside `for`/`if` init clauses.
- Defer: generics (Phase 7), full conversion rules, type assertions,
type switches.
- **Acceptance:** types/ suite at 60+ tests. **Bar crossed: 72/72.**
@@ -265,19 +267,22 @@ Progress-log line → push `origin/loops/go`.
cross-language record.
### Phase 4 — Tree-walk evaluator (`lib/go/eval.sx`) ⬜
- AST-walking interpreter over CEK. Each Go statement maps to one step
function (precedent: `step-sf-if` etc. in spec/evaluator.sx).
- Variables: 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 method table.
- Functions: closures over enclosing scope; multiple return values.
- Channels: stub (Phase 5 wires them).
- [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.
- [ ] 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.
- [ ] 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. No concurrency yet.
- **Acceptance:** eval/ suite at 80+ tests. Current: 25/25. No concurrency yet.
### Phase 5 — Goroutines + channels + select (`lib/go/sched.sx`) ⬜
- **Independent implementation.** Do NOT use lib/guest/scheduler/ — that
@@ -561,6 +566,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 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
shape as ctx but bound to runtime values), literal decoding for
decimal/hex/oct/bin int literals (with underscores), variable lookup,
predeclared `true`/`false`/`nil`, and the full set of arithmetic /
comparison / logical binops via `go-eval-binop`. Hex/oct/bin parsing
via `go-hex-digit-value` (explicit char-equality dispatch since SX's
nth-on-string returns single-char strings, not numeric codes —
cleaner than the char-arithmetic the kernel ports use). eval suite
25/25, total 402/402. `[nothing]` — pure Go eval mechanics, the
cross-language insights are about type-checking which is in the
sister-plan diary.
- 2026-05-27 — Phase 3 cont.: **interface satisfaction** — the headline
Go-distinguishing typing feature this loop set out to validate.
Method decls record under `#method/TYPE-NAME/METHOD-NAME` keys in