In hyperscript, 'your' refers to the element in a 'tell' scope,
functioning identically to 'my' for property access. Fixes
"Expected into/before/after/at" parse errors in tell commands.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Integration:
- hs-collect-vars: scan compiled SX for set! targets, collect symbols
- hs-handler: pre-declare collected variables in closure let-bindings
so increment/decrement work on first use (variable persists across
event handler calls via closure scope)
Compiler:
- Fix emit-inc/emit-dec: use expr (variable) not tgt-override (element)
- Simplify to plain (set! x (+ x amount)) since vars are pre-declared
Mock DOM:
- Add mock console object to host-global
- Add console handler (no-op) to host-call dispatch
- Override console-log/debug/error as no-op primitives to avoid
str hitting circular refs in mock DOM elements
Fixes 4 log timeouts, 2+ increment/decrement failures.
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>
Tests with _=\"...\" attribute delimiters were garbled because
HTMLParser interpreted the backslash-quote as content, not delimiters.
Now html.replace('\"', '"') normalizes before parsing.
Fixes ~15 tests across toggle, transition, and other categories
that were previously running with corrupted HS source.
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>
Parser:
- `add VALUE to :var` → (add-value) for array append
- `remove VALUE from :var` → (remove-value) for array removal
- `toggle .foo for 10ms` → (toggle-class-for) with duration
- `append VALUE` without `to` → implicit target (it)
- `set {obj} on target` → (set-on) for object property spread
- `repeat in` body: remove spurious nil (body at index 3→2)
- Keywords followed by `(` parsed as function calls (fixes `increment()`)
Compiler:
- Handle add-value, remove-value, toggle-class-for, set-on AST nodes
- Local variables (`set :var`) use `define` instead of `set!`
Runtime:
- hs-add-to!: append value to list
- hs-remove-from!: filter value from list
- hs-set-on!: spread dict properties onto target
- `as String` for lists: comma-join (JS Array.toString compat)
Tests:
- eval-hs/eval-hs-with-me: guard for hs-return exceptions
(return compiles to raise, needs handler to extract value)
Parse errors: 20→12 (8 fixed). Remaining: 6 embedded HTML quotes
(tokenizer), 6 transition template values `(expr)px`.
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>
orchestration.sx process-elements iterates DOM attributes and calls
starts-with? on the name. Some attributes have nil names (e.g. from
malformed elements). Added (string? name) guard before starts-with?.
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>
htmx sends HX-Request header on AJAX calls. The server now detects this
and renders the SX response to HTML via sx_render_to_html before sending.
SX-Request (from SX client navigation) still gets SX wire format.
Also skip response cache for htmx requests (they need fresh HTML renders).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Parser: fetch command consumes {method:"POST"}, with {opts}, and
handles as-format both before and after options.
Mock: Number format case-insensitive, /test route has number field.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Compiler: do-blocks containing IO commands (hs-fetch, hs-wait, perform)
are compiled as (let ((it cmd1)) (let ((it cmd2)) ...)) to chain the
it variable through IO suspensions. Non-IO do-blocks stay as plain
(do cmd1 cmd2). This enables fetch X then put it into me pattern.
Parser: then-separator handled via __then__ markers (stripped in output).
fetch URL /path parsing. Default format "text".
Runtime: hs-fetch simplified to single perform (io-fetch url format).
Test runner: mock fetch routes with format-specific responses.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
guard and cek-try both create CEK frames that don't survive async
perform/resume. Instead, run-action returns nil on success and an
error string on failure. The for-each loop checks the return value
and sets fail-msg. No exceptions cross async boundaries.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The let/it wrapping changed semantics of ALL multi-command sequences,
breaking independent side-effect chains like (do (add-class) (add-class)).
Need a targeted approach — chain it only for then-separated commands.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
When an error occurs during resumed VM execution (after perform/hs-wait),
resume_vm now checks the VM's handler_stack. If a handler exists (from a
compiled guard form's OP_PUSH_HANDLER), it unwinds frames and jumps to
the catch block — exactly like OP_RAISE. This enables try/catch across
async perform/resume boundaries.
The guard form compiles to OP_PUSH_HANDLER which lives on the vm struct
and survives across setTimeout-based async resume. Previously, errors
during resume escaped to the JS console as unhandled exceptions.
Also restored guard in the test runner (was cek-try which doesn't survive
async) and restored error-throwing assertions in run-action.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Compiler: do-blocks now compile to (let ((it cmd1)) (let ((it cmd2)) ...))
instead of (do cmd1 cmd2 ...). This chains the `it` variable through
command sequences, enabling `fetch X then put it into me` pattern.
Each command's result is bound to `it` for the next command.
Runtime: hs-fetch simplified to single perform (io-fetch url format)
instead of two-stage io-fetch + io-parse-text/json.
Parser: fetch URL /path handled by reading /+ident tokens.
Default fetch format changed to "text" (was "json").
Test runner: mock fetch routes with format-specific responses.
io-fetch handler returns content directly based on format param.
Fetch tests still need IO suspension to chain through let continuations.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Logs at every step: run-all start, test name, reload-frame, wait-for-el,
actions done, PASS/FAIL, run-all complete.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The previous insert wrapped reload-frame and wait-for-el in a begin
block instead of making them separate letrec bindings. This made
reload-frame invisible to later bindings. Fixed by inserting
wait-for-el at index 3 in the letrec bindings list.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
wait-for-el polls the iframe doc for a CSS selector up to max-tries
times with 200ms intervals. Used before running test actions to ensure
the target elements exist in the iframe after page load.
Also restores reload-frame timing and keeps cek-try error handling.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The guard form (call/cc + handler-bind expansion) doesn't survive async
IO suspension — the CEK continuation from guard's call/cc captures frames
that become invalid after the VM resumes from hs-wait. Replacing guard
with cek-try (which compiles to VM-native OP_PUSH_HANDLER/OP_POP_HANDLER)
avoids the CEK boundary crossing.
The test runner now executes: suspends on hs-wait, resumes, runs test
actions, and test assertions fire correctly. The "Not callable: nil"
error is eliminated. Remaining: test assertion errors from iframe content
not loading fast enough (timing issue, not a framework bug).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The Not callable: nil error happens on a stub VM (frames=[], sp=0) during
cek_resume with 12 CEK kont frames. The error is from a reactive signal
subscriber (reset! current ...) that triggers during run vm after resume.
The subscriber callback goes through CEK via cek_call_or_suspend and the
CEK continuation tries to call nil.
This is a reactive subscriber notification issue, not a perform/resume
frame management issue. The VM frames are correctly restored — the error
happens during a synchronous reset! call within the resumed VM execution.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Shows pending_cek, reuse_stack count, and frames count in the error.
Also transfers reuse_stack from _active_vm at VmSuspended catch sites.
Finding: the Not callable: nil happens during cek_resume (pending_cek=false,
kont=12 frames). The CEK continuation tries to call a letrec function that
is nil because letrec bindings are in VM local SLOTS, not in the CEK env.
The VM→CEK boundary crossing during suspension loses the local slot values.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Parser: handle /path URLs in fetch command by reading /+ident tokens.
Test runner: mock fetch routes (/test→yay, /test-json→{"foo":1}),
io-parse-text, io-parse-json, io-parse-html handlers in _driveAsync.
Fetch tests still fail (0/23) because the do-block halts after
hs-fetch's perform suspension — the CEK machine doesn't continue
to the next command (put it into me) after IO resume. This needs
the IO suspension model to properly chain do-block continuations.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
bootstrap.py regenerated cek_run as a simple "raise if suspended" without
the _cek_io_resolver and _cek_io_suspend_hook checks. Also lost the
CekPerformRequest catch in cek_step_loop and step_limit checks.
This was the direct cause of "IO suspension in non-IO context" when island
click handlers called perform (via hs-wait). The CEK had no way to propagate
the suspension to the VM/JS boundary.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The callFn suspension returns requests as {op: "io-sleep", args: {items: [100]}}
(dict format) but _driveAsync only handled list format (op-name arg ...).
Result: io-sleep/wait resumes never fired — tests hung after first suspension.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Higher limits (500K, 1M) recover repeat tests but make on-suite
tests run 6-15s each, causing batch timeouts. The IO suspension
kernel needs to be fixed to use fewer steps, not worked around
with higher limits.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Root cause: when perform fires inside a VM closure chain (call_closure_reuse),
the caller frames are saved to reuse_stack on the ACTIVE VM. But the
_cek_io_suspend_hook and _cek_eval_lambda_ref create a NEW stub VM for the
VmSuspended exception. On resume, resume_vm runs on the STUB VM which has
an empty reuse_stack — the caller frames are orphaned on the original VM.
Fix: transfer reuse_stack from _active_vm to the stub VM before raising
VmSuspended. This ensures resume_vm -> restore_reuse can find and restore
the caller's frames after async resume via _driveAsync/setTimeout.
Also restore step_limit/step_count refs dropped by bootstrap.py regeneration.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Root cause: sx_browser.ml registered all HTML tags (a, b, i, p, s, u, g, etc.)
as custom special forms. The evaluator's step_eval_list checked custom special
forms BEFORE checking local env bindings. So (let ((a (fn () 42))) (a))
matched the HTML tag <a> instead of calling the local function a.
Fix: skip custom special forms AND render-check when the symbol is bound in
the local env. Added (not (env-has? env name)) guard to both checks in
step-eval-list (spec/evaluator.sx and transpiled sx_ref.ml).
This was the root cause of "[sx] resume: Not callable: nil" — after hs-wait
resumed, calling letrec-bound functions like wait-boot (which is not an HTML
tag) worked, but any function whose name collided with an HTML tag failed.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The previous commit accidentally lost ~1100 lines from sx_server.ml
due to a git stash conflict resolution that silently deleted the
hash-index, manifest generation, and /sx/h/ route handler code.
Restored from 97818c6d. Only change: added host-* platform primitive
stubs (host-get, host-set!, host-call, etc.) needed because the
callable? fix in boot-helpers.sx now properly loads code paths that
reference these browser-only functions.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
callable? in boot-helpers.sx checked for "native-fn" but type-of returns
"function" for NativeFn — broke make-spread and all native fn dispatch
in aser. Restore 20 behavioral tests replaced with NOT IMPLEMENTED stubs
by the test regeneration commit. Add host-* platform primitive stubs to
sx_server.ml so boot-helpers.sx loads without errors server-side.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- return compiles to (raise (list "hs-return" value)) instead of
silently discarding the return keyword
- def wraps function body in guard that catches hs-return exceptions,
enabling early exit from repeat-forever loops via return
- def params correctly extract name from (ref name) AST nodes
Note: IO suspension kernel changes reduced baseline from 519→487.
The HS parser/compiler/runtime fixes are all intact.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Compiler: return compiles to (raise (list "hs-return" value))
- Compiler: def wraps body in guard to catch hs-return exceptions
- Compiler: def params extract name from (ref name) nodes
- Test generator: extract <script type="text/hyperscript"> blocks
and compile def functions as setup before tests
- Test generator: add eval-hs-with-me for {me: N} opts
The return mechanism enables repeat-forever with early exit via return.
Direct SX guard/raise works (returns correct value), but the compiled
HS repeat-forever thunk body needs further debugging for full coverage.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The _cek_io_suspend_hook creates a stub VM to carry the suspended CEK
state. Previously used empty globals, which caused "Not callable: nil"
when the CEK resume needed platform functions. Now uses _default_vm_globals
(set to _vm_globals by sx_browser.ml) so all platform functions and
definitions are available during resume.
Remaining issue: still getting "resume: Not callable: nil" — the CEK
continuation env may not include letrec bindings from the island body.
The suspension point is inside reload-frame → hs-wait, and the resume
needs to call wait-boot (a letrec binding).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The _cek_io_suspend_hook was only added to cek_run_iterative (line 986)
but the actual code path went through cek_run (line 624). Added the hook
check to both functions.
This fixes the "IO suspension in non-IO context" error that blocked
hs-wait/perform from propagating through event handler → trampoline →
eval_expr call chains. IO suspension now converts to VmSuspended via the
hook, which the value_to_js wrapper catches and drives with _driveAsync.
+42 OCaml test passes (3924→3966). IO suspension verified working in
browser WASM: dom-on click handler → hs-wait → perform → suspend →
_driveAsync → setTimeout → resume.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Root cause: cek_run_iterative (used by eval_expr/trampoline) raised
"IO suspension in non-IO context" when the CEK hit a perform. This
blocked IO suspension from propagating through nested eval_expr calls
(event handler → trampoline → eval_expr → for-each callback → hs-wait).
Fix: added _cek_io_suspend_hook (Sx_types) that converts CEK suspension
to VmSuspended, set by sx_vm.ml at init. cek_run_iterative now calls the
hook instead of erroring. The VmSuspended propagates to the value_to_js
wrapper which has _driveAsync handling.
+42 test passes (3924→3966), zero regressions.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Root cause found: when the click handler calls run-all → for-each → callback → hs-wait → perform,
the perform raises VmSuspended. But the call path goes through sx_apply_cek
(from the call-lambda CALL_PRIM) which converts VmSuspended → CekPerformRequest.
The inner CEK context has no IO handler, so it raises "IO suspension in non-IO context"
instead of propagating the suspension to the outer context.
Fix needed: either (a) make sx_apply_cek NOT convert VmSuspended when in a context
that supports IO suspension, or (b) ensure the inner CEK from call-lambda propagates
perform as a suspension state rather than erroring.
Debug logging still present in sx_browser.ml (js_to_value traces).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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>
runner.sx: Converted define forms inside island body to letrec. Multiple
define forms in a let body cause render-to-dom to fall back to eval-expr
for the whole body, which evaluates (div ...) as a list instead of
rendering it to DOM. letrec keeps the last body expression (div) as the
render target.
sx_browser.ml: js_to_value now stores plain JS functions as host objects
(Dict with __host_handle) instead of wrapping as NativeFn. This preserves
the original JS function identity through the SX→JS round-trip, keeping
_driveAsync wrappers from host-callback intact when passed to
addEventListener via host-call.
Remaining: IO suspension in click handler is caught as "IO suspension in
non-IO context" instead of being driven by _driveAsync. The host-callback
wrapper creates the right JS function, but the event dispatch path doesn't
go through K.callFn.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>