Commit Graph

1906 Commits

Author SHA1 Message Date
0862a6140b spec: gensym + symbol interning (OCaml + tests)
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 32s
gensym_counter ref + gensym/string->symbol/symbol->string/intern/symbol-interned?
primitives in sx_primitives.ml. Fix ListRef case in seq_to_list on both
sx_ref.ml and sx_primitives.ml. 19 new tests in test-gensym.sx.
OCaml 4450/1080, JS 2205/2497, zero regressions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 10:56:30 +00:00
edf4e525f8 spec: gensym + symbol interning — *gensym-counter*, string->symbol, symbol->string, intern
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 10:28:18 +00:00
130d4d7c18 plan: tick Phase 11 Commit — sequence protocol fully landed
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 20s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 10:22:36 +00:00
ac79328418 plan: tick Phase 11 Tests — 45 sequence tests all passing
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 23s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 10:19:10 +00:00
0fe00bf7ac spec: sequence protocol tests — 45 tests, all passing on JS and OCaml
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 10:18:37 +00:00
06a3eee114 plan: tick Phase 11 JS bootstrapper — already done in Spec step
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 17s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 10:05:47 +00:00
c3d2b9d87d plan: tick Phase 11 OCaml — HO dispatch + sequence-* primitives done
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 17s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 10:01:49 +00:00
7286629cf7 ocaml: sequence protocol — seq_to_list coercion in HO dispatch + sequence-* primitives
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 10:01:22 +00:00
da4b526abb spec: sequence protocol Spec step — seq-to-list + ho polymorphic dispatch
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 15s
- seq-to-list: coerce list/vector/string/nil to list
- ho-setup-dispatch: apply seq-to-list to all collection args so map/filter/
  reduce/for-each/some/every? work over vectors and strings natively
- sequence->list, sequence->vector, sequence-length, sequence-ref,
  sequence-append: full polymorphic sequence helpers
- in-range: list-returning range generator (eager, works with all HO forms)
- Restore 3 accidentally-deleted make-cek-state/make-cek-value/make-cek-suspended
- Fix 8 shorthand define forms (transpiler requires long form)
- Add vector->list/list->vector to transpiler js-renames + platform aliases
- JS: 2137 passing (+28 vs HEAD baseline)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 09:31:28 +00:00
59a835efc3 plan: tick Phase 10 hash tables — complete, Phase 11 next
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 13s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 08:49:14 +00:00
133bdf5295 spec: mutable hash tables (make-hash-table/ref/set!/delete!/etc)
Phase 10 — 11 primitives: make-hash-table, hash-table?, hash-table-set!,
hash-table-ref, hash-table-delete!, hash-table-size, hash-table-keys,
hash-table-values, hash-table->alist, hash-table-for-each, hash-table-merge!.
OCaml HashTable variant; JS Map-based. 28 tests, both hosts green.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 08:48:41 +00:00
2e4502878f plan: tick Phase 9 complete — promises done
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 19s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 08:22:10 +00:00
e44cb89ab4 spec: promises — delay/force/delay-force/make-promise/promise?
25 tests pass on OCaml (4357 total) and JS. Promise represented as
mutable dict {:_promise true :forced :thunk :value}; delay-force
adds :_iterative for chain-following semantics.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 08:21:45 +00:00
835b5314ce plan: tick Phase 8 complete — multiple values done
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 24s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 08:04:08 +00:00
43cc1d9003 spec: multiple values — values/call-with-values/let-values/define-values
25 tests pass on both JS and OCaml hosts. Uses dict marker
{:_values true :_list [...]} for 0/2+ values; 1 value passes
through directly. step-sf-define extended to desugar shorthand
(define (name params) body) forms on both hosts.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-05-01 08:03:17 +00:00
8328e96ff6 primitives-loop: push to origin/architecture after each commit
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 13s
2026-04-26 19:33:27 +00:00
24522902cc plan: tick Phase 7 bitwise — complete, Phase 8 next
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 16s
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 19:06:30 +00:00
a8a79dc902 spec: bitwise operations (bitwise-and/or/xor/not, arithmetic-shift, bit-count, integer-length)
OCaml: land/lor/lxor/lnot/lsl/asr in sx_primitives.ml
JS: & | ^ ~ << >> with Kernighan popcount and Math.clz32 for integer-length
spec/primitives.sx: stdlib.bitwise module with 7 entries
26 tests, 158 assertions, all pass OCaml+JS

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 19:06:09 +00:00
1ad9d63f1b plan: tick Phase 6 JS+Tests+Commit — ADT complete, Phase 7 next
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 18:56:22 +00:00
f63b214726 plan: tick Phase 6 OCaml task — ADT bootstrap implementation done
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 18:52:40 +00:00
5d1913e730 ocaml: ADT support via bootstrap FIXUPS — define-type + match
Hand-write sf_define_type in bootstrap.py FIXUPS (skipped from transpile
because the spec uses &rest params and empty-dict literals the transpiler
can't emit). Registers define-type via register_special_form. Adds
step_limit/step_count to PREAMBLE (referenced by sx_vm.ml/run_tests.ml).

172 assertions pass (test-adt). Full suite: 4280/1080 (was 4243/1117).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 18:52:16 +00:00
0dc7e1599c spec: match special form — ADT constructor pattern matching (20 tests)
Extends match-pattern in spec/evaluator.sx with an ADT case: when the
pattern is (CtorName var...) and the value is an ADT dict (:_adt true),
check :_ctor matches, arity matches, then recursively bind field patterns.
Supports nested patterns, wildcard _, variable binding, and zero-arg ctors.

Changes step-sf-match to route no-clause errors through raise-eval-frame
instead of direct error, allowing guard to catch non-exhaustive matches.

40/40 ADT tests pass (20 define-type + 20 match). Zero regressions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 18:16:16 +00:00
6c87210728 spec: define-type special form — constructors, predicates, accessors (20 tests)
Adds sf-define-type via register-special-form! in spec/evaluator.sx.
ADT values are dicts {:_adt true :_type "T" :_ctor "C" :_fields (list ...)}.
Each define-type call registers: ctor functions with arity checking, Name?
type predicate, Ctor? constructor predicates, Ctor-field positional accessors,
and populates *adt-registry* dict with type→[ctor-names] mapping.
20/20 JS tests pass in spec/tests/test-adt.sx.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 17:56:50 +00:00
3fb0212414 plan: Phase 6 ADT design doc — define-type/match syntax, CEK dispatch, exhaustiveness
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 17:17:14 +00:00
518ad37def plan: tick Phase 5 Tests+Commit tasks — string-buffer complete
17 tests written inline with the implementation step. All 17 pass
on OCaml and JS. Phase 5 fully done as d98b5fa2.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 17:09:30 +00:00
d98b5fa223 spec: string-buffer primitive — make-string-buffer/append!/->string/length
OCaml: StringBuffer of Buffer.t in sx_types.ml; 5 primitives in
sx_primitives.ml (make-string-buffer, string-buffer?, string-buffer-append!,
string-buffer->string, string-buffer-length); inspect case added.

JS: SxStringBuffer with array+join backend; _string_buffer marker for
typeOf dispatch and dict? exclusion (also excludes _vector from dict?).

spec/primitives.sx: 5 define-primitive entries.
17/17 tests pass on both OCaml and JS.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 17:05:05 +00:00
cc0af51921 plan: tick Phase 4 commit task — coroutine primitive complete
All Phase 4 work landed across 4 commits (21cb9cf5, 9eb12c66, b78e06a7,
0ffe208e). Phase 5 (string buffer) is next.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 16:54:22 +00:00
0ffe208e31 spec: coroutine tests — expand to 27 (was 17)
10 new tests: state field transitions (ready/suspended/dead), yield from
nested helper function, initial resume arg ignored by ready coroutine,
mutable closure state via dict-set!, complex yield values (list/dict),
round-robin scheduling, factory creates independent coroutines, resuming
non-coroutine raises error.

27/27 pass on both OCaml and JS.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 16:49:22 +00:00
b78e06a772 js: coroutine JS step — pre-load spec/coroutines.sx in run_tests.js
All CEK primitives (cek-step-loop/cek-resume/make-cek-state/cek-suspended?/
cek-io-request/cek-terminal?/cek-value) were already registered in sx-browser.js.

Root cause of test failure: (import (sx coroutines)) creates an io-suspended
state when the library isn't pre-loaded; overridden cekRun throws on suspension.
Fix: pre-load spec/signals.sx + spec/coroutines.sx before test files run.

17/17 coroutine tests pass in JS. 1965/2500 total (+25 vs 1940 baseline),
zero new failures.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 16:43:02 +00:00
9eb12c66fd ocaml: coroutine OCaml step — verified via existing CEK suspension primitives
No native SxCoroutine type needed. dict-based coroutine identity +
cek-step-loop/cek-resume/perform/make-cek-state primitives already in
run_tests.ml fully implement the coroutine contract. 284/284 pass
(coroutines+vectors+numeric-tower+dynamic-wind), zero regressions.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 16:32:59 +00:00
21cb9cf51a spec: coroutine primitive — make-coroutine/resume/yield via perform/cek-step-loop
spec/coroutines.sx: define-library with make-coroutine, coroutine-resume,
coroutine-yield, coroutine?, coroutine-alive?. Built on existing perform/
cek-step-loop/cek-resume suspension machinery.

spec/tests/test-coroutines.sx: 17 tests — multi-yield, final return,
arg passthrough, alive? predicate, nested coroutines, recursive iteration,
independent coroutine interleaving.

Key: coroutine body must use (define loop (fn…)) not named let — named let
transpiles to cek_call→cek_run which rejects IO suspension. All 17/17 pass.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 16:15:48 +00:00
d84cf1882a plan: tick Phase 3 complete — dynamic-wind OCaml+JS done
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 15:18:07 +00:00
6602ec8cc9 ocaml: wire dynamic-wind through CEK — WindFrame + winders stack
- sx_types.ml: CallccContinuation gains winders depth int field
- sx_runtime.ml: make_callcc_continuation(captured, winders_len),
  callcc_continuation_winders_len accessor; get_val maps after-thunk,
  winders-len, body-result to cf_f/cf_extra/cf_name
- sx_ref.ml: step_limit/step_count restored; make_wind_after_frame and
  make_wind_return_frame now store their args in the CekFrame fields
- transpiler.sx: after-thunk→cf_f, winders-len→cf_extra,
  body-result→cf_name for future bootstrap runs
- 8 new dynamic-wind tests pass (OCaml), 235/235 no regressions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 15:16:56 +00:00
b126d4da76 plan: tick Phase 3 Spec+Tests, update progress log
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 14:19:52 +00:00
a9d5a1082f spec: dynamic-wind — after-thunk fires on normal return, raise, and call/cc escape
- Add make-wind-after-frame / make-wind-return-frame CEK frame types
- Add *winders* global stack tracking active after-thunks
- Add kont-unwind-to-handler (replaces kont-find-handler in raise-eval) — calls
  after-thunks for wind frames encountered while unwinding to handler
- Add wind-escape-to — pops and calls after-thunks down to captured winders-len
- Replace sf-dynamic-wind with step-sf-dynamic-wind (full CEK dispatch)
- Fix "callcc" frame: store winders-len in continuation object
- Fix callcc-continuation? case: call wind-escape-to before escape
- JS platform: extend SxCallccContinuation to store windersLen; add
  callcc-continuation-winders-len accessor
- 8 tests: normal return, raise escape, call/cc escape, nested LIFO, guard ordering
- 1948/2500 (was 1940); zero regressions

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 14:19:17 +00:00
0577f245e2 plan: tick Phase 2 Verify+Commit, mark phase complete
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 12:53:40 +00:00
f5acb31c94 plan: tick Phase 2 JS bootstrapper checkbox, update progress log
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 12:46:32 +00:00
b12a22e68a js: numeric tower — integer?/float?/exact?/inexact? + epoch Integer fix
Add integer?/float?/exact?/inexact? predicates (Number.isInteger check).
Add truncate/remainder/modulo/random-int/exact->inexact/inexact->exact/parse-number.
inexact->exact uses Math.round (rounds to nearest, matching OCaml).
Fix sx_server.ml epoch/blob/io-response protocol to accept Integer as
well as Number — parser now produces Integer for whole-number literals.
JS: 60 new passing tests (1880→1940). OCaml: 4874/394 baseline unchanged.
Note: 6 tests fail in JS due to platform limitation (JS cannot distinguish
float 2.0 from integer 2).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 12:46:17 +00:00
7888fbfd81 plan: tick Phase 2 Spec checkbox, update progress log
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 12:31:13 +00:00
45ec553519 spec: numeric tower primitives — integer?/float? predicates, contagion docs
Add integer? and float? to spec/primitives.sx predicates section.
Update number? doc and body (or-guard for integer? type).
Update / :returns to "float" (always inexact).
Update floor/ceil/truncate :returns to "integer", improve docs.
Update round doc (returns integer at ndigits=0).
Update exact?/inexact?/exact->inexact/inexact->exact docs and returns.
Update +/-/* docs to document float contagion rule.
Fix double-paren :params on truncate/exact?/inexact?/exact->inexact/inexact->exact.
4874 passed, 394 failed (baseline unchanged).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 12:31:01 +00:00
e3e767e434 plan: tick Phase 2 OCaml + Tests checkboxes, update progress log
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 12:11:39 +00:00
c70bbdeb36 ocaml: numeric tower — Integer/Number distinction + float contagion
Add `Integer of int` to sx_types.ml alongside `Number of float`. Parser
produces Integer for whole-number literals. Arithmetic primitives apply
float contagion (int op int → Integer, int op float → Number). Division
always returns Number. Rounding (floor/truncate/round) returns Integer.
Predicates: integer?, float?, exact?, inexact?, exact->inexact,
inexact->exact. run_tests.ml updated for json_of_value, value_of_json,
identical?, random-int mock, DOM accessors, and parser pattern matches.
New spec/tests/test-numeric-tower.sx — 92 tests, all pass (394 unchanged).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 12:10:50 +00:00
8f0fc4ce52 primitives-loop: tick Phase 1 JS + Tests + Verify + Commit steps [x]
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 10:02:49 +00:00
1d85e3a79c js: fix lambda binding (index-of on lists), add vectors + R7RS platform stubs
- Fix PRIMITIVES["index-of"] for arrays: return NIL when not found (matching
  OCaml semantics) so bind-lambda-params correctly detects absent &rest params.
  Previously String(array).indexOf() returned -1, which passed number? check
  and mis-fired the &rest branch, leaving non-&rest params unbound.
- Declare var _lastErrorKont_ and var hostError in IIFE scope (strict mode fix)
- Add PRIMITIVES["host-error"], ["try-catch"], ["without-io-hook"]
- Add env["test-allowed?"] stub in run_tests.js
- Add spec/tests/test-vectors.sx: 42 tests for all vector primitives
- Rebuild sx-browser.js: 1847 standard / 2362 full tests pass (up from 5)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-26 10:02:23 +00:00
5a332fa430 spec: vector primitive — complete type signatures in spec/primitives.sx
All 10 vector primitives now have :as type annotations on every parameter,
:returns types, and :doc strings. make-vector gains optional fill annotation;
vector uses :rest for its variadic args; vector-ref/set! document bounds error.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-25 19:33:39 +00:00
d1a00562a4 spec: vector primitives — bounds-checked ref/set!, vector-copy start/end slice
vector-ref and vector-set! now raise Eval_error on out-of-bounds index instead of
an OCaml array exception. vector-copy accepts optional start and end parameters for
slicing (R7RS §6.8). spec/primitives.sx doc updated to reflect slice params.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-25 19:27:54 +00:00
3759575b29 primitives-loop: Phase 0 done — stop language loops, verify E38/E39
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-25 19:02:12 +00:00
f247cb2898 js: let/const TDZ infrastructure — sentinel + kind threading in transpiler
Some checks failed
Test, Build, and Deploy / test-build-deploy (push) Failing after 11s
Threads declaration kind ("var"/"let"/"const") through js-transpile-var →
js-vardecl-forms so the transpiler knows which kind is being declared.
Infrastructure for full TDZ enforcement: js-tdz-check can wrap let/const
reads to raise TypeError before initialization.

Updates plans/js-on-sx.md: ticks [x] for TDZ, marks regex blocker RESOLVED,
adds progress log entry for 2026-04-25.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-25 18:35:32 +00:00
f8023cf74e js: regex engine (lib/js/regex.sx) — pure-SX recursive backtracker
Adds a full regex engine written in SX, installed via js-regex-platform-override!.
Supports char classes (.  \d\D\w\W\s\S  [abc]  [^abc]  ranges), anchors (^ $ \b \B),
quantifiers (* + ? {n,m} greedy and lazy), capturing/non-capturing groups,
alternation (a|b), flags i/g/m.  exec() returns {:match :index :input :groups}.

Also fixes String.prototype.match to dispatch through the platform engine
(was calling js-regex-stub-exec directly, bypassing regex.sx).
Adds TDZ sentinel infrastructure: __js_tdz_sentinel__, js-tdz?, js-tdz-check.
Updates test.sh (+34 regex tests + 4 TDZ infra tests), conformance.sh,
and test262-runner.py to load regex.sx as epoch 6.

Tests: 559/560 unit (1 pre-existing failure), 148/148 conformance.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-25 18:35:23 +00:00
3316d402fd HS: null-safety piece 1 — eval-hs-error recognizer + helper (+18 tests unlocked)
Add recognizer for expect(await error("HS")).toBe("MSG") pattern in
generate-sx-tests.py, plus eval-hs-error SX helper in the generated
test file. All 18 runtimeErrors tests now generate real test cases
instead of SKIP stubs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-04-25 12:10:19 +00:00