Adds 13 set primitives to stdlib.sets. OCaml: SxSet as (string,value)
Hashtbl keyed by inspect(val); JS: SxSet wrapping Map keyed by
write-to-string. Structural equality — (make-set '(1 2)) contains 1.
Includes union, intersection, difference, for-each, map.
33 tests in test-sets.sx, all pass on both JS and OCaml.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds read, write, display, newline, write-to-string, display-to-string
and current-*-port primitives to both JS and OCaml hosts.
JS: sxReadNormalize (#t/#f→true/false), sxReadConvert (()→nil),
sxEq array comparison, sxWriteVal symbol/keyword name fix,
readerMacroGet/readerMacroSet registry in parser platform.
OCaml: sx_write_val/sx_display_val helpers, read/write/display/newline
primitives on port types; parser extended for #t/#f and N/D rationals.
42 new tests (test-read-write.sx), all passing on JS and OCaml.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
SxRational type in OCaml (Rational of int * int, stored reduced, denom>0)
and JS (SxRational class with _rational marker). n/d reader syntax in
spec/parser.sx. Arithmetic contagion: int op rational → rational, rational
op float → float. JS keeps int/int → float for CSS backward compatibility.
OCaml as_number + safe_eq extended for cross-type rational equality so
(= 2.5 5/2) → true. 62 tests in test-rationals.sx, all pass.
JS: 2232 passed. OCaml: 4532 passed (+11 vs pre-fix baseline).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Eof sentinel and Port{PortInput/PortOutput} in sx_types.ml. All 15 port
primitives in sx_primitives.ml. type_of/inspect updated. 39/39 port tests
pass (4532 total, +39, zero regressions).
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Phase 14: port type + eof-object. Input ports track _pos cursor; output ports
accumulate _buffer. All 15 port primitives in spec/primitives.sx (stdlib.ports
module), platform.py (JS), and 39/39 tests in spec/tests/test-ports.sx.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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>
- 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>
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>
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>
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>
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>
- 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>
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>
- 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>
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>
Adds regex-compile/test/exec/match-all/replace/replace-fn/split/source/flags.
Opaque dict handle {:__regex__ true :id :source :flags}; compiled Re.re
cached in a primitives-local table. Replacement supports $&, $1-$9, $$.
Flags: i (CASELESS), m (MULTILINE), s (DOTALL). g is a runtime flag handled
in replace. u (unicode) skipped for now.
Unblocks js-on-sx's regex-platform-override! hook — the JS RegExp shim can
now delegate to real regex instead of the substring stub.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Shared formatter in sx_types.ml. Small integer-valued floats still print
as plain ints; floats outside safe-int range (|n| >= 1e16) now print as
%.17g (full precision) instead of silently wrapping to negative or 0.
Non-integer values keep %g 6-digit behavior — no existing SX tests regress.
Unblocks Number.MAX_VALUE / Math.pow(2,N) style tests in js-on-sx where
iterative float loops were collapsing to 0 at ~2^63.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- parser `empty` no-target → (ref "me") (was bogus (sym "me"))
- parser `halt` modes distinguish: "all"/"bubbling"/"default" halt execution
(raise hs-return), "the-event"/"the event's" only stop propagation/default.
"'s" now matched as op token, not keyword.
- parser `get` cmd: dispatch + cmd-kw list + parse-get-cmd (parses expr with
optional `as TYPE`). Required for `get result as JSON` in fetch chains.
- compiler empty-target for (local X): emit (set! X (hs-empty-like X)) so
arrays/sets/maps clear the variable, not call DOM empty on the value.
- runtime hs-empty-like: container-of-same-type empty value.
- runtime hs-empty-target!: drop dead FORM branch that was short-circuiting
to innerHTML=""; the querySelectorAll-over-inputs branch now runs.
- runtime hs-halt!: take ev param (was free `event` lookup); raise hs-return
to stop execution unless mode is "the-event".
- runtime hs-reset!: type-aware — FORM → reset, INPUT/TEXTAREA → value/checked
from defaults, SELECT → defaultSelected option.
- runtime hs-open!/hs-close!: toggle `open` attribute on details elements
(not just the prop) so dom-has-attr? assertions work.
- runtime hs-coerce JSON: json-stringify dict/list (was str).
- test-runner mock: host-get on List + "length"/"size" (was only Dict);
dom-set-attr tracks defaultChecked / defaultSelected / defaultValue;
mock_query_all supports comma-separated selector groups.
- generator: emit boolean attrs (checked/selected/etc) even with null value;
drop overcautious "skip HS with bare quotes or embedded HTML" guard so
morph tests (source contains embedded <div>) emit properly.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Load sx/sx/geography/cek/ recursively so content/demo/freeze index.sx
pages bind as ~geography/cek/{content,demo,freeze}. Update docs.sx
cek-page dispatch + test-examples cek:content-pages suite to reference
those real names (were stale ~geography/cek/cek-content etc.).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Update test-examples.sx to reference the real path-derived names
(~geography/<domain>/<stem>) instead of short aliases, drop the
alias chains in run_tests.ml, and add marshes/_islands loading so
the migrated one-per-file islands resolve. Fix the try-rerender-page
stub in boot-helpers.sx to accept the 3 args its callers pass.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Why: the one-per-file migration leaves `defcomp`/`defisland` unnamed in each
file; the test runner now walks `_islands/` recursively and injects a name
derived from the relative path (e.g. `geography/cek/_islands/demo-counter.sx`
→ `~geography/cek/demo-counter`), matching the runtime's path-based naming.
JIT-vs-CEK test parity: both now pass 3938/534 (identical failures).
Three fixes in sx_vm.ml + run_tests.ml:
1. OP_CALL_PRIM: fallback to Sx_primitives.get_primitive when vm.globals
misses. Primitives registered after JIT setup (host-global, host-get,
etc. bound inside run_spec_tests) become resolvable at call time.
2. jit_compile_lambda: early-exit for anonymous lambdas, nested lambdas
(closure has parent — recreated per outer call), and a known-broken
name list: parser combinators, hyperscript parse/compile orchestrators,
test helpers, compile-timeout functions, and hs loop runtime (which
uses guard/raise for break/continue). Lives inside jit_compile_lambda
so both the CEK _jit_try_call_fn hook and VM OP_CALL Lambda path
honor the skip list.
3. run_tests.ml _jit_try_call_fn: catch TIMEOUT during jit_compile_lambda.
Sentinel is set before compile, so subsequent calls skip JIT; this
ensures the first call of a suite also falls back to CEK cleanly when
compile exceeds the 5s test budget.
Also includes run_tests.ml 'reset' form helpers refactor (form-element
reset command) that was pending in the working tree.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
- call: use make-symbol for fn name, rest-rest for args (was string + nth)
- on: extract (ref ...) nodes from body as event.detail let-bindings
- host-set!: add ListRef+Number case for array index mutation
- append!: support index 0 for prepend
- hs-put!: branch on list? for array start/end operations
- hs-reset!: form reset restoring defaultValue/checked/textContent
- 522/793 pass (was 493/754)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Parser:
- halt default/bubbling: match ident type (not just keyword)
- halt the event's: consume possessive marker
Runtime:
- hs-halt! dispatches: default→preventDefault, bubbling→stopPropagation,
event→both
Mock DOM:
- Add event method dispatch: preventDefault, stopPropagation,
stopImmediatePropagation set correct flags on event dict
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
cek_run's resolver → cek_resume doesn't propagate values correctly
(likely a kont frame ordering issue in the transpiled evaluator).
Workaround: use _cek_io_suspend_hook which receives the suspended
state and manually steps to completion, handling further suspensions.
- resolve_io: shared function for IO resolution (sleep, fetch, etc.)
- Suspend hook: manual step loop after cek_resume, handles nested IO
- run_with_io: uses req_list extraction (handles ListRef)
- Fixes fetch tests: 10 now pass (response format correct)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The run_with_io suspension handler wasn't matching IO requests because
SX lists can be ListRef (mutable) not just List (immutable). Fixed by
extracting the underlying list first, then pattern matching on elements.
Also:
- Added io-sleep/io-wait/io-settle/io-fetch handlers to run_with_io
- Rebound try-call inside run_spec_tests to use eval_with_io
- io-fetch returns "yay" for text, {foo:1} for json, response dict
This enables perform-based IO (wait, fetch) to work in test execution,
fixing ~30 tests that previously returned empty strings.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
IO Suspension:
- Set _cek_io_resolver in test runner to handle perform/wait/fetch
- io-sleep/io-wait: instant resume (no real delay in tests)
- io-fetch: returns mock {ok:true, status:200, json:{foo:1}} response
- io-wait-for/io-settle: instant resume
- Fixes ~30 tests that were failing with VmSuspended or timeouts
Append command:
- hs-append (pure): string concat or list append
- hs-append! (effectful): DOM insertAdjacentHTML
- Compiler emits set! wrapper for variable targets
Mock DOM:
- dom_stringify handles List → comma-separated string
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Compiler:
- append to symbol → (set! target (hs-append target value))
- append to DOM → (hs-append! value target)
Runtime:
- hs-append: pure function for string concat and list append
- hs-append!: DOM insertAdjacentHTML for element targets
Mock DOM:
- dom_stringify handles List by joining elements with commas
(matching JS Array.toString() behavior)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Parser:
- Reorder toggle style parsing: target before between clause
- Handle "indexed" keyword, "indexed by" syntax
- Use parse-atom (not parse-expr) for between values to avoid
consuming "and" as boolean operator
- Support 3-4 value cycles via toggle-style-cycle
Compiler:
- Add toggle-style-cycle dispatch → hs-toggle-style-cycle!
Runtime:
- Add hs-toggle-style-between! (2-value toggle)
- Add hs-toggle-style-cycle! (N-value round-robin)
Mock DOM:
- Parse CSS strings from setAttribute "style" into style sub-dict
so dom-get-style/dom-set-style work correctly
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Parser:
- Relax (number? v) to v in parse-one-transition so (expr)unit works
- Add (match-kw "then") before parse-cmd-list in parse-for-cmd
- Handle "indexed by" syntax alongside "index" in for loops
- Add "indexed" to hs-keywords to prevent unit-suffix consumption
Compiler:
- Use map-indexed instead of for-each for indexed for-loops
Test generator:
- Preserve \" escapes in process_hs_val via placeholder/restore
Mock DOM:
- Coerce insertAdjacentHTML values via dom_stringify (match browser)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- inject_path_name: strip _islands/ convention dirs from path-derived names
- page-functions.sx: fix geography (→ ~geography) and isomorphism (→ ~etc/plan/isomorphic)
- request-handler.sx: rewrite sx-eval-page to call page functions explicitly
via env-get+apply, avoiding provide special form intercepting (provide) calls
- sx_server.ml: set expand-components? on AJAX aser paths so server-side
components expand for the browser (islands stay unexpanded for hydration)
- Rename 19 component references in geography/spreads, geography/provide,
geography/scopes to use path-qualified names matching inject_path_name output
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The handler dispatch (api.* paths) now checks for HX-Request header.
If present, the SX aser output is rendered to HTML via sx_render_to_html
before sending. SX-Request (from SX client navigation) still gets SX
wire format. This makes hx-* attributes work like real htmx — the
server returns HTML fragments that htmx can swap into the DOM.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Previously these primitives threw Eval_error if either arg was non-string.
Now they return false, preventing crashes when DOM attributes return nil
values during element processing (e.g. htmx-boot-subtree! iterating
elements with undefined attribute names).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The htmx-boot-subtree! function (defined in lib/hyperscript/htmx.sx)
was never loaded in the browser because hs-htmx.sx wasn't in the
bundle or compile-modules lists. Added to:
- bundle.sh: copy htmx.sx as hs-htmx.sx to dist
- compile-modules.js: compile to hs-htmx.sxbc, add to deps and lazy list
This was the root cause of "Load Content" button not working —
hx-* attributes were never activated because htmx-boot-subtree!
was undefined.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>