go: eval.sx — slices + index + slice expr + len/append builtins + 10 tests [nothing]
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 25s
Phase 4 cont. Adds runtime support for Go's slice type.
Slice representation: (list :go-slice ELEMS) — a simple wrapper around
a list of element values. v0 deferring the full
(length, capacity, backing-vector) triple from the Go spec until
programs need it.
go-eval-composite → for (:composite TYPE-OR-EXPR ELEMS) where
TYPE is :ty-slice / :ty-array, eval each
element (handling :kv index-keyed
shorthand by taking only the value) and
wrap in :go-slice.
go-eval-index → (:index OBJ IDX). Bounds-checked; out-of-
range returns (:eval-error :index-out-of-range).
go-eval-slice → (:slice OBJ LOW HIGH MAX). Two-index slice
with omitted low → 0, omitted high → len.
Returns a new :go-slice.
go-list-slice → primitive list-slicing helper.
Builtins live in a new starter env go-env-builtins:
len(slice|string) → count
append(slice, ...x) → new slice with x appended
print(...) → no-op in v0
Builtins are bound as (:go-builtin NAME); go-eval-call recognises the
shape and routes to go-eval-builtin instead of go-eval-fn.
**Summing a slice via the canonical Go for-loop works end-to-end:**
a := []int{1, 2, 3, 4, 5}
sum := 0
for i := 0; i < len(a); i++ {
sum = sum + a[i]
}
// sum == 15
eval 50/50, total 427/427.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -276,8 +276,12 @@ Progress-log line → push `origin/loops/go`.
|
||||
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`
|
||||
honours capacity-grow per spec.
|
||||
- [/] Slices: v0 represents a slice as `(list :go-slice ELEMS)` —
|
||||
simpler than the full (length, capacity, backing-vector) triple.
|
||||
Composite-literal `[]T{...}` evaluates to a `:go-slice`; `a[i]`
|
||||
indexes, `a[low:high]` slices, `len(a)` returns count, `append(a, ...)`
|
||||
extends. The full triple with capacity-grow comes in a later
|
||||
slice when programs need it.
|
||||
- [ ] Maps: SX dict + key-type metadata.
|
||||
- [ ] Structs: SX dict + type tag. Methods looked up via type's table.
|
||||
- [/] Functions: top-level definition + call (incl. recursion via the
|
||||
@@ -285,7 +289,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: 40/40. No concurrency yet.
|
||||
- **Acceptance:** eval/ suite at 80+ tests. Current: 50/50. No concurrency yet.
|
||||
|
||||
### Phase 5 — Goroutines + channels + select (`lib/go/sched.sx`) ⬜
|
||||
- **Independent implementation.** Do NOT use lib/guest/scheduler/ — that
|
||||
@@ -569,6 +573,17 @@ 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.: slice values + index/slice exprs + the
|
||||
`len`/`append`/`print` builtins. Slice representation is
|
||||
`(list :go-slice ELEMS)` for v0 (deferring the full length/cap/
|
||||
backing-vector triple). `go-eval-composite` handles `[]T{...}` /
|
||||
`[N]T{...}` literals (maps next). `go-eval-index` returns the i-th
|
||||
element with bounds-check. `go-eval-slice` handles two-index slicing
|
||||
with omitted low/high. New `go-env-builtins` starter env binds the
|
||||
three builtins as `(:go-builtin NAME)` values; `go-eval-call`
|
||||
recognises them and dispatches to `go-eval-builtin`. **Summing a
|
||||
slice via `for i := 0; i < len(a); i++ { sum = sum + a[i] }` works
|
||||
end-to-end.** +10 tests, eval 50/50, total 427/427. `[nothing]`.
|
||||
- 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
|
||||
|
||||
Reference in New Issue
Block a user