Commit Graph

448 Commits

Author SHA1 Message Date
98fbd5cf40 HS parser: possessive 's style property access (517→519/831)
parse-poss-tail now handles style token type after 's operator.
#div2's *color, #foo's *width etc. now correctly produce
(style prop owner) AST which compiles to dom-set/get-style.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 16:07:52 +00:00
4981e9a32f HS runtime: add Set/Map coercions to hs-coerce
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 15:28:29 +00:00
6f374fabce WASM rebuild: VM reuse_stack fix + boot.sxbc hydration + island preload
Recompiled WASM kernel (wasm_of_ocaml) to include the VM reuse_stack
fix from sx_vm.ml. Recompiled boot.sxbc with the clear-and-replace
hydration (replaceChildren + nil hydrating scope + dom-append).

sx-platform.js deployed with island preload, isMultiDefine fix, and
K.load error checking.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 15:21:11 +00:00
fc76a42403 HS: take attr semantics fix, +6 tests (509→515/831)
- Parser: take @attr=value with replacement restored (was reverted)
- Runtime: take @attr bare doesn't remove from scope (hyperscript keeps
  source attr, only sets on target). Only take @attr=val with replacement
  modifies scope elements.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 14:11:18 +00:00
6bd45daed6 hydrate-island: clear SSR children, render fresh DOM, append to island
Islands now: (1) clear SSR children via replaceChildren, (2) push nil
hydrating scope (disables hydration cursor walk that causes mismatch
errors), (3) render-to-dom creates fresh DOM with live event handlers,
(4) dom-append attaches the rendered DOM to the island element.

This fixes the hydrate-mismatch:div error caused by SSR/client attribute
differences (~tw generates different class strings server vs client).

NOTE: needs WASM rebuild (sx_build target=wasm) to compile boot.sxbc.
The .sx source is updated but the bytecoded module is stale.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 14:00:12 +00:00
8819d7cbd1 HS fixes: multi-property transition, take attr with-val, empty form, css-value parsing
- Parser: multi-property transition (width from 0px to 100px height from...)
  with collect-transitions loop. CSS value parsing uses parse-atom + manual
  number+unit concat to avoid greedy string-postfix chaining.
- Compiler: take! passes attr-val and with-val (restored from revert)
- Runtime: hs-empty-target! handles FORM by iterating child inputs,
  hs-starts-with-ic/hs-ends-with-ic for case-insensitive comparison

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 13:44:59 +00:00
faa65e15d8 Revert "hydrate-island: clear-and-replace instead of hydration walk"
This reverts commit ca077b429b.
2026-04-16 13:44:54 +00:00
ca077b429b hydrate-island: clear-and-replace instead of hydration walk
Islands now clear SSR children before render-to-dom and append the
fresh DOM result. Avoids hydrate-mismatch errors from SSR/client
attribute differences (~tw generates different class strings).

The hydrating scope is set to nil (no cursor walk) so render-to-dom
creates new DOM nodes instead of trying to reuse SSR elements.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 13:35:45 +00:00
c9634ba649 VM: fix nested IO suspension frame corruption, island hydration preload
VM frame merging bug: call_closure_reuse now saves caller continuations
on a reuse_stack instead of merging frames. resume_vm restores them in
innermost-first order. Fixes frame count corruption when nested closures
suspend via OP_PERFORM. Zero test regressions (3924/3924).

Island hydration: hydrate-island now looks up components from (global-env)
instead of render-env, triggering the symbol resolve hook. Added JS-level
preload-island-defs that scans DOM for data-sx-island and loads definitions
from the content-addressed manifest BEFORE hydration — avoids K.load
reentrancy when the resolve hook fires inside env_get.

loadDefinitionByHash: fixed isMultiDefine check — defcomp/defisland bodies
containing nested (define ...) forms no longer suppress name insertion.
Added K.load return value checking for silent error string returns.

sx_browser.ml: resolve hook falls back to global_env.bindings when
_vm_globals miss (sync gap). Snapshot reuse_stack alongside pending_cek.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 13:23:35 +00:00
684a46297d HS behavioral tests: 478→509/831 (57%→61%), parser/compiler/runtime fixes
Parser: am-a/am-not-a type checks, transition element/selector targeting,
take @attr=value with replacement, toggle my/the possessive, <selector/>
syntax in parse-atom, the-of for style/attr/class/selector, when-clause
filtering for add, starts/ends-with ignoring case.

Compiler: take attr passthrough, toggle-style nil→me default, scoped
querySelectorAll for add/remove/toggle-class, has-class? entry, matches?
extracts selector from (query sel), add-class-when with for-each filter,
starts/ends-with-ic entries, hs-add replaces + for polymorphic add.

Runtime: hs-take! proper attr values, hs-type-check Element/Node via
host-typeof, hs-toggle-style! opacity 0↔1, hs-coerce +8 coercions
(Keys/Values/Entries/Reversed/Unique/Flat/JSON/Object), hs-query-all
bypasses broken dom-query-all (WASM auto-converts arrays), hs-matches?
handles DOM el.matches(selector), hs-add list+string+number polymorphic,
hs-starts/ends-with-ic for case-insensitive comparison.

DOM mock: mkStyle() with setProperty/getPropertyValue, fndAll.item().

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-16 12:53:43 +00:00
4aa49e42e8 htmx demos working: activation, fetch, swap, OOB filtering, test runner page
- htmx-boot-subtree! wired into process-elements for auto-activation
- Fixed cond compilation bug in hx-verb-info (Clojure-style flat cond)
- Platform io-fetch upgraded: method/body/headers support, full response dict
- Replaced perform IO ops with browser primitives (set-timeout, browser-confirm, etc)
- SX→HTML rendering in hx-do-swap with OOB section filtering
- hx-collect-params: collects input name/value for all methods
- Handler naming: ex-{slug} convention, removed perform IO dependencies
- Test runner page at (test.(applications.(htmx))) with iframe-based runner
- Header "test" link on every page linking to test URL
- Page file restructure: 285 files moved to URL-matching paths (a/b/c/index.sx)
- page-functions.sx: ~100 component name references updated
- _test added to skip_dirs, test- file prefix convention for test files

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 11:56:15 +00:00
4f02f82f4e HS parser: fix number+comparison keyword collision, eval-hs uses hs-compile
Parser: skip unit suffix when next ident is a comparison keyword
(starts, ends, contains, matches, is, does, in, precedes, follows).
Fixes "123 starts with '12'" returning "123starts" instead of true.

eval-hs: use hs-compile directly instead of hs-to-sx-from-source with
"return " prefix, which was causing the parser to consume the comparison
as a string suffix.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-15 11:29:01 +00:00
745e78ab05 HS parser: 'does not start/end with' negation support
Parser now handles 'does not start with' and 'does not end with'
comparison operators, compiling to (not (starts-with? ...)) and
(not (ends-with? ...)) respectively.

Test runner: host-set!/host-get stringify innerHTML/textContent.

437/831 (52.6%) — parser fix doesn't change count yet (comparison tests
use 'is a' type checks which need separate fix).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 20:19:33 +00:00
e5e3e90ee7 HS compiler: emit-set handles @attr of target expressions
Adds attribute reference case to the 'of' branch in emit-set:
(set @bar of #div2 to "foo") now compiles to (dom-set-attr target "bar" "foo")
instead of falling through to the broken (set! (host-get ...)) catchall.

417/831 (50.2%), +2 from attr-of fix.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 19:47:30 +00:00
b1666a5fe2 HS tests: VM step limit fix, callFn error propagation, compiler emit-set fixes
- sx_vm.ml: VM timeout now compares vm_insn_count > step_limit instead of
  unconditionally throwing after 65536 instructions when limit > 0
- sx_browser.ml: Expose setStepLimit/resetStepCount APIs on SxKernel;
  callFn now returns {__sx_error, message} on Eval_error instead of null
- compiler.sx: emit-set handles array-index targets (host-set! instead of
  nth) and 'of' property chains (dom-set-prop with chain navigation)
- hs-run-fast.js: New Node.js test runner with step-limit timeouts,
  SX-level guard for error detection, insertAdjacentHTML mock,
  range selection (HS_START/HS_END), wall-clock timeout in driveAsync
- hs-debug-test.js: Single-test debugger with DOM state inspection
- hs-verify.js: Assertion verification (proves pass/fail detection works)

Test results: 415/831 (50%), up from 408/831 (49%) baseline.
Fixes: set my style["color"], set X of Y, put at end of (insertAdjacentHTML).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 19:27:03 +00:00
1d83ccba3c Content-addressed on-demand loading: Merkle DAG for all browser assets
Replace the monolithic 500KB <script data-components> block with a 25KB
JSON manifest mapping names to content hashes. Every definition —
components, islands, macros, client libraries, bytecode modules, and
WASM binaries — is now content-addressed and loaded on demand.

Server (sx_server.ml):
- build_hash_index: Merkle DAG over all definitions — topological sort,
  hash leaves first, component refs become @h:{hash} in instantiated form
- /sx/h/{hash} endpoint: serves definitions with Cache-Control: immutable
- Per-page manifest in <script data-sx-manifest> with defs + modules + boot
- Client library .sx files hashed as whole units (tw.sx, tw-layout.sx, etc.)
- .sxbc modules and WASM kernel hashed individually

Browser (sx-platform.js):
- Content-addressed boot: inline script loads kernel + platform by hash
- loadDefinitionByHash: recursive dep resolution with @h: rewriting
- resolveHash: 3-tier cache (memory → localStorage → fetch /sx/h/{hash})
- __resolve-symbol extended for manifest-based component + library loading
- Cache API wrapper intercepts .wasm fetches for offline caching
- Eager pre-loading of plain symbol deps for CEK evaluator compatibility

Shell template (shell.sx):
- Monolithic <script data-components> removed
- data-sx-manifest script with full hash manifest
- Inline bootstrap replaces <script src="...?v="> with CID-based loading

Second visit loads zero bytes from network. Changed content gets a new
hash — only that item refetched (Merkle propagation).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 10:14:39 +00:00
4cac08d56f HS: contains/matches ignoring case support — 425→426
- Parser: contains/matches with ignoring case modifier
- Compiler: contains-ignore-case? → hs-contains-ignore-case?
- Compiler: matches-ignore-case? → hs-matches-ignore-case?
- Runtime: downcase-based case-insensitive contains/matches

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 09:45:57 +00:00
c05d8788c7 HS parser: is/is-not ignoring case, eq-ignore-case runtime — 423→425
- Parse `is X ignoring case` → (eq-ignore-case left right)
- Parse `is not X ignoring case` → (not (eq-ignore-case left right))
- Compiler: eq-ignore-case → hs-eq-ignore-case
- Runtime: hs-eq-ignore-case using downcase/str

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 09:38:12 +00:00
eaf3c88a36 HS runtime: empty/swap/compound events, host-set! fix — 403→423 (51%)
- Fix host-set → host-set! in emit-inc/emit-dec (increment/decrement properties)
- Implement empty/clear command: parser dispatch, compiler, polymorphic runtime
- Implement swap command: parser dispatch, compiler (let+do temp swap pattern)
- Add parse-compound-event-name: joins dot/colon tokens (example.event, htmx:load)
- Add hs-compile to source parser (was only in WASM deploy copy)
- Add clear/swap to tokenizer keywords and cmd-kw? list
- Generator: fix run() with extra args, String.raw support

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 09:17:43 +00:00
e2fe070dd4 Fix :ref callback bug in adapter-dom — Pretext island fully working
Root cause: adapter-dom.sx line 345 handled :ref by calling
(dict-set! attr-val "current" el), assuming React-style ref objects.
Callback-style refs (fn (el) ...) passed a function, not a dict,
causing dict-set! to fail with "dict key val" error.

Fix: (if (callable? attr-val) (attr-val el) (dict-set! attr-val "current" el))
Supports both callback refs and dict refs.

Pretext island now fully working:
- 3 controls: width slider, font size slider, algorithm toggle
- Knuth-Plass + greedy line breaking via bytecode-compiled library
- canvas.measureText for pixel-perfect browser font metrics
- Effect-based imperative DOM rendering (createElement + appendChild)
- Reactive: slider drag → re-measure → re-break → re-render

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-13 08:26:48 +00:00
429c2b59f9 Hyperscript test generator: repeat loop fix, assert= arg order, quote handling
- Don't insert 'then' inside for-in loop bodies or after 'repeat N times'
  (fixes repeat from 1/30 → 5/30)
- Allow HS sources ending with " when they don't contain embedded HTML
  (fixes set from 6/25 → 10/25, enables 18 previously-skipped tests)
- Fix assert= argument order: (actual expected), not (expected actual)
  (error messages now correctly report Expected/Got)

395 → 402/831 (+7)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 22:51:20 +00:00
1884c28763 Fix browser compat: sublist replaces 3-arg slice, manual sum replaces reduce
- Added sublist helper (portable list extraction, avoids 3-arg slice
  which fails in browser WASM kernel)
- Replaced reduce + 0 lwid with manual sum loop (reduce has browser
  compat issues with dict-set! error in call stack)
- Imperative DOM update via effect for clean paragraph re-rendering
  on signal changes (clear container, create new spans)
- String slice in hyphenate-word kept (works on strings)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 18:31:34 +00:00
7ec42386fb Fix Pretext island: library functions inside define-library begin block
Root cause: sx_insert_near placed break-lines-greedy, pretext-position-line,
pretext-layout-lines OUTSIDE the define-library begin block. The bytecode
compiler only compiles forms inside begin as STORE_GLOBAL — forms outside
are invisible to the browser VM.

Fix: moved all function definitions inside (begin ...) of (define-library).
Bytecode now includes all 17 functions (11K compiled, was 9K).

Browser load-sxbc: simplified VmSuspended handling — just catch and
continue, since STORE_GLOBAL ops already ran before the import OP_PERFORM.
sync_vm_to_env copies them to global_env.

Island now calls break-lines and pretext-layout-lines from bytecode-compiled
library — runs on VM, not CEK interpreter.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 17:53:50 +00:00
45209caf73 Fix Pretext client island: inlined greedy layout, avoid slice/import issues
- Greedy line breaking inlined (avoids 3-arg slice browser issue)
- Manual word extraction via for-each+append! instead of slice
- Browser load-sxbc: handle VmSuspended + copy library registry exports
- TODO: Knuth-Plass on bytecode VM when define-library export propagation
  is fixed (compiler strips library wrapper → STORE_GLOBAL works, but
  import OP_PERFORM suspends before sync_vm_to_env copies globals)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 17:09:39 +00:00
699dd5ad69 Step 17b: bytecode-compiled text-layout, WASM library import fix
- text-layout.sx added to WASM bytecode pipeline (9K compiled)
- Fix multi-list map calls (map-indexed + nth instead of map fn list1 list2)
- pretext-layout-lines and pretext-position-line moved to library exports
- Browser load-sxbc: handle VmSuspended for import, copy library exports
  to global_env after module load (define-library export fix)
- compile-modules.js: text-layout in SOURCE_MAP, FILES, and entry deps
- Island uses library functions (break-lines, pretext-layout-lines)
  instead of inlining — runs on bytecode VM when exports resolve

Known issue: define-library exports don't propagate to browser global env
yet. The load-sxbc import suspension handler resumes correctly but
bind_import_set doesn't fire. Needs deeper investigation into how the
WASM kernel's define-library registers exports vs how other libraries
(adapter-html, tw) make their exports available.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 16:37:04 +00:00
1eadefd0c1 Step 17b: Pretext — DOM-free text layout with otfm font measurement
Pure SX text layout library with one IO boundary (text-measure perform).
Knuth-Plass optimal line breaking, Liang's hyphenation, position calculation.

Library (lib/text-layout.sx):
- break-lines: Knuth-Plass DP over word widths
- break-lines-greedy: simple word-wrap for comparison
- hyphenate-word: Liang's trie algorithm
- position-line/position-lines: running x/y sums
- measure-text: single perform (text-measure IO)

Server font measurement (otfm):
- Reads OpenType cmap + hmtx tables from .ttf files
- DejaVu Serif/Sans bundled in shared/static/fonts/
- _cek_io_resolver hook: perform works inside aser/eval_expr
- JIT VM suspension inline resolution for IO in compiled code

~font component (shared/sx/templates/font.sx):
- Works like ~tw: emits @font-face CSS via cssx scope
- Sets font-family on parent via spread
- Deduplicates font declarations

Infrastructure fixes:
- stdin load command: per-expression error handling (was aborting on first error)
- cek_run IO hook: _cek_io_resolver in sx_types.ml
- JIT VmSuspended: inline IO resolution when resolver installed
- ListRef handling in IO resolver (perform creates ListRef, not List)

Demo page at /sx/(applications.(pretext)):
- Hero: justified paragraph with otfm-measured proportional widths
- Greedy vs Knuth-Plass side-by-side comparison
- Badness scoring visualization
- Hyphenation syllable decomposition

25 new tests (spec/tests/test-text-layout.sx), 3201/3201 passing.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 15:13:00 +00:00
f60d22e86e Hyperscript: focus command, diagnostic test output, blur keyword
Parser/compiler/runtime for focus command. Tokenizer: focus, blur,
precedes, follows, ignoring, case keywords. Test spec: per-test
failure output for diagnosis.

374/831 (45%)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 12:38:05 +00:00
1783f4805a Fix streaming resolveSuspense: use callFn instead of eval string interpolation
The previous K.eval() approach double-escaped backslashes in SX source
strings, breaking the \/ → / unescaping that the server serializer adds
for HTML safety. Using K.callFn() passes strings directly as arguments,
bypassing the escaping problem entirely.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 12:35:37 +00:00
7d798be14f Hyperscript: precedes/follows comparisons, tokenizer keywords
Parser: precedes/follows comparison operators in parse-cmp.
Tokenizer: precedes, follows, ignoring, case keywords.
Runtime: precedes?, follows? string comparison functions.

372/831 (45%)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 12:20:13 +00:00
ae32254dfb Hyperscript: hide/show strategy (opacity/visibility), add/remove query-all
Parser: hide/show handle `with opacity/visibility/display` strategy
and properly detect target vs command boundaries. Compiler: emit
correct CSS property per strategy, add-class/remove-class use
for-each+query-all for class selectors. Runtime: hs-query-all uses
dom-body, hs-each helper for collection iteration.

Generator: inline run().toEqual() pattern for eval-only tests.

372/831 (45%)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 12:07:06 +00:00
854ed9c027 Hyperscript conformance: 372→373 — hide/show strategy, generator toEqual
Parser: hide/show handle `with opacity/visibility/display` strategy,
target detection for then-less chaining (add/remove/set/put as boundary).
Generator: inline run().toEqual([...]) pattern for eval-only tests.
Compiler: hide/show emit correct CSS property per strategy.

373/831 (45%)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 11:42:28 +00:00
56855eee7f Fix streaming resolve: color dict keys + defer resolveSuspense until after boot
stream-colors dict had green/blue keys but data used emerald/violet — all three
slots now render with correct Tailwind color classes. Platform: resolveSuspense
must not exist on Sx until boot completes, otherwise bootstrap __sxResolve calls
it before web stack loads and resolves silently fail. Moved to post-boot setup
so all pre-boot resolves queue in __sxPending and drain correctly.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 09:58:18 +00:00
6e27442d57 Step 17: streaming render — hyperscript enhancements, WASM builds, live server tests
Streaming chunked transfer with shell-first suspense and resolve scripts.
Hyperscript parser/compiler/runtime expanded for conformance. WASM static
assets added to OCaml host. Playwright streaming and page-level test suites.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-12 08:41:38 +00:00
eaf5af4cd8 Step 17: streaming render — chunked transfer, shell-first suspense, resolve scripts
Server (sx_server.ml):
- Chunked HTTP transport (Transfer-Encoding: chunked)
- Streaming page detection via scan_defpages (:stream true)
- Shell-first render: outer layout + shell AST → aser → SSR → flush
- Data resolution: evaluate :data, render :content per slot, flush __sxResolve scripts
- AJAX streaming: synchronous eval + OOB swaps for SPA navigation
- SX URL → flat path conversion for defpage matching
- Error boundaries per resolve section
- streaming-demo-data helper for the demo page

Client (sx-platform.js):
- Sx.resolveSuspense: finds [data-suspense] element, parses SX, renders to DOM
- Fallback define for resolve-suspense when boot.sx imports fail in WASM
- __sxPending drain on boot (queued resolves from before sx.js loads)
- __sxResolve direct dispatch after boot

Tests (streaming.spec.js):
- 5 sandbox tests using real WASM kernel
- Suspense placeholder rendering, __sxResolve replacement, independent slot resolution
- Full layout with gutters, end-to-end resolve with streaming-demo/chunk components

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 16:12:28 +00:00
55a4fba58f Guard batch-begin!/batch-end! with (client?) — server-only platform ops
These are OCaml-side bookkeeping for the Python async bridge. The browser
WASM kernel registers them in the CEK env but not the VM global table,
so bytecode-compiled batch() crashed with "VM undefined: batch-begin!".
The SX-level *batch-depth*/*batch-queue* already handle batching correctly.

Verified in Playwright sandbox: signal, deref, reset!, batch, computed
all work with source fallback (sxbc load-format issue is pre-existing).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 12:49:57 +00:00
fc9c90b7b1 Fix core-signals bytecode: letrec for self-ref, explicit get for dict destructuring
Two issues prevented core-signals.sx from working as bytecode:

1. computed/effect used (let) for self-referencing bindings (recompute,
   run-effect). Changed to (letrec) so the VM pre-allocates slots before
   compiling the lambda bodies — required for self-reference in bytecode.

2. deref used dict destructuring (let {:notify n :deps d} ctx ...) which
   the transpiled OCaml compiler doesn't support. Rewrote to explicit
   (get ctx "notify") / (get ctx "deps") calls.

Also fixed compile-let dict destructuring opcodes (OP_CONST=1 not 2,
OP_CALL_PRIM=52 not 10) for future use when compiler is retranspiled.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 12:38:07 +00:00
ef8f8b7c03 Compiler: dict destructuring in let, paren-aware library stripping — 31/31 sxbc
compile-let now handles dict destructuring patterns:
(let {:key1 var1 :key2 var2} source body). This unblocked core-signals.sx
(deref uses dict destructuring) which was the sole bytecode skip.

Rewrote stripLibraryWrapper from line-based to paren-aware extraction.
The old regex missed (define-library on its own line (no trailing space),
silently passing the full wrapper to the compiler.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 08:52:36 +00:00
6e38a2e1e1 Parser: between, starts with, ends with — 297/831 (36%)
- is between X and Y / is not between X and Y: uses parse-atom for
  bounds to avoid consuming 'and' as logical operator
- starts with / ends with: comparison operators mapping to
  starts-with? / ends-with? primitives
- comparisonOperator: 12→17/40

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 22:52:28 +00:00
5fe97d8481 Multi-class add/remove, async IO in test runner — 280/831 (34%)
- Parser: add .foo .bar collects multiple class refs into multi-add-class AST
- Compiler: multi-add-class/multi-remove-class emit (do (dom-add-class...) ...)
- Test runner: drives IO suspension chains (wait/fetch/settle) via _driveAsync
  so async HS tests (wait 100ms, settle, fetch) can complete
- Assertion failed: 51→49

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 22:24:16 +00:00
08cd82ed65 Parser: catch/finally in on handlers, cmd terminators — 279/831 (34%)
- parse-cmd: catch/finally/end/else/otherwise are now terminators that
  stop parse-cmd-list (return nil from parse-cmd)
- parse-on-feat: optional catch var handler / finally handler clauses
  after the command body, before 'end'
- emit-on: scan-on passes catch-info/finally-info through recursion,
  wraps compiled body in (guard (var (true catch-body)) body) when
  catch clause is present
- Runtime: hs-put! handles "start" (afterbegin) and "end" (beforeend)
- Removed duplicate conformance-dev.sx (all 110 tests already in behavioral)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 21:51:43 +00:00
e85de7d5cc Parser: put at start/end of, take for — 309/941 (33%)
- put parser: added 'at start of' and 'at end of' positional syntax
- take parser: added 'for' as alternative to 'from' for target clause
- runtime: hs-put! handles "start" (afterbegin) and "end" (beforeend)
- eval-hs: smart wrapping for commands vs expressions

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 16:19:46 +00:00
ab50c4516e Fix DOM-preserving hydration: text node mismatch + conditional markers
Two issues with the initial hydration implementation:

1. Text node mismatch: SSR merges adjacent text into one node
   ("0 / 16") but client renders three separate children. When the
   cursor ran out, new nodes were created but dom-append was
   unconditionally skipped. Fix: only skip append when the child
   already has a parent (existing SSR node). New nodes (nil parent)
   get appended even during hydration.

2. Conditional markers: dispatch-render-form for if/when/cond in
   island scope was injecting comment markers during hydration,
   corrupting the DOM. Fix: skip the reactive conditional machinery
   during hydration — just evaluate and render the active branch
   normally, walking the cursor. Reactivity for conditionals
   activates after the first user-triggered re-render.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 14:27:37 +00:00
a2a4d17d53 DOM-preserving hydration — SSR DOM stays, event listeners attach in place
Scope-based cursor walks the existing SSR DOM during island hydration
instead of creating new elements and calling replaceChildren. The
hydration scope (sx-hydrating) propagates through define-library via
scope-push!/peek/pop!, solving the env isolation that broke the
previous set!-based approach.

Changes:
- adapter-dom.sx: hydrating?, hydrate-next-node, hydrate-enter/exit-element
  helpers. render-to-dom reuses text nodes. render-dom-element reuses
  elements by tag match, skips dom-append. reactive-text/cek-reactive-text
  reuse existing text nodes. render-dom-fragment/lake/marsh skip append.
  dispatch-render-form (if/when/cond) injects markers into existing DOM.
- boot.sx: hydrate-island pushes cursor scope, skips replaceChildren.
  On mismatch error, falls back to full re-render.

Result: zero DOM destruction, zero visual flash, event listeners
attached to original SSR elements. Stepper clicks verified working.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 11:46:41 +00:00
89ffb02b20 Revert WIP hydration commit — undefined hydrate-start!/stop! broke all islands
The WIP commit (0044f17e) added calls to hydrate-start!, hydrate-stop!,
hydrate-push!, hydrate-pop!, and hydrate-next-*! — none of which were
ever defined. This crashed hydrate-island silently (cek-try swallowed
the error), preventing event listener attachment on every island.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 11:21:57 +00:00
0044f17e4c WIP: DOM-preserving hydration — SSR DOM stays, no visual flash
Adds hydration cursor to render pipeline:
- boot.sx: *hydrating* flag, hydrate-start!/stop!, cursor stack helpers
- adapter-dom.sx: render-dom-element uses existing SSR elements when
  *hydrating* is true. Text nodes reused. dom-append skipped.
- hydrate-island: calls hydrate-start! before render-to-dom, no
  replaceChildren. SSR DOM stays in place.

Status: screenshots identical (no visual flash), but event listeners
not attaching — the cursor/set! interaction between CEK and VM needs
debugging. The hydrate-start! set! on *hydrating* may not propagate
to the bytecoded adapter-dom render path.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 10:40:09 +00:00
23c88cd1e5 Atomic island hydration: replaceChildren instead of clear+append
The hydrate-island function was doing:
  (dom-set-text-content el "")  ;; clears SSR content — visible flash
  (dom-append el body-dom)       ;; adds reactive DOM

Now uses:
  (host-call el "replaceChildren" body-dom)  ;; atomic swap, no empty state

Per DOM spec, replaceChildren is a single synchronous operation — the
browser never renders the intermediate empty state. The MutationObserver
test now checks for content going to zero (visible gap), not mutation
count (mutations are expected during any swap).

Test: "No clobber: clean" — island never goes empty during hydration.
All 8 home features pass: no-flash, no-clobber, boot, islands, stepper,
smoke, no-errors.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 07:51:37 +00:00
42a7747d02 Fix HS put-into and query: compiler emits hs-query-first, runtime uses real DOM
Two bugs found by automated test suite:
1. compiler.sx: query → hs-query-first (was dom-query, a deleted stub)
2. compiler.sx: emit-set with query target → dom-set-inner-html (was set!)
3. runtime.sx: hs-query-first uses real document.querySelector
4. runtime.sx: delete hs-dom-query stub (returned empty list)

All 8/8 HS elements pass: toggle, bounce+wait, count, add-class,
toggle-between, set-innerHTML-eval, put-into-target, repeat-3-times.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-10 06:50:57 +00:00
0bed9e3664 Fix repeat timing: don't double-drive IO suspensions
The value_to_js resume handler was calling _driveAsync on re-suspension,
but the JS driveAsync caller also processes the returned suspension.
This caused the second wait in each iteration to fire immediately (0ms)
instead of respecting the delay.

Fix: resume handler just returns the suspension object, lets the JS
driveAsync handle scheduling via setTimeout.

Verified: repeat 3 times add/wait 300ms/remove/wait 300ms produces
6 transitions at correct 300ms intervals (1504ms total).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 21:47:48 +00:00
9982cd5926 Fix chained IO suspensions in value_to_js callback wrapper
The resume callback in the value_to_js VmSuspended handler now catches
VmSuspended recursively, building a new suspension object and calling
_driveAsync for each iteration. Fixes repeat N times ... wait ... end
which produces N sequential suspensions.

Bounce works on repeated clicks. 4/4 regression tests pass.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 21:37:52 +00:00
cf10e9a2d6 Fix: load HS modules as bytecode, not source — restores IO suspension chain
Reverts the source-loading workaround. Bytecode modules go through the
VM which handles IO suspension (perform/wait/fetch) correctly. The
endModuleLoad sync copies VM globals to CEK env, so eval-expr-cek in
hs-handler can find hs-on/hs-toggle-class!/etc.

All three HS examples fully working on live site:
  Toggle Color — toggle classes on click
  Bounce — add class, wait 1s (IO suspend+resume), remove class
  Count Clicks — increment counter, update innerHTML

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-09 21:28:58 +00:00