Move `hs-prolog-hook` / `hs-set-prolog-hook!` / `prolog` out of
`lib/hyperscript/runtime.sx` into a self-contained plugin file at
`lib/hyperscript/plugins/prolog.sx`. The API surface is preserved —
`lib/prolog/hs-bridge.sx::pl-install-hs-hook!` still calls
`hs-set-prolog-hook!` exactly as before, just resolved to the plugin
file's binding rather than runtime.sx's.
Move the E39 worker stub registration out of `lib/hyperscript/parser.sx`
into `lib/hyperscript/plugins/worker.sx`. The plugin calls
`(hs-register-feature! "worker" ...)` at file load time. Behaviour is
identical — `worker MyWorker ...` raises the same helpful "plugin not
installed" error, just routed through the registry from a separate
file. The pre-existing `behavioral` test for the helpful error
("raises a helpful error when the worker plugin is not installed")
still passes via the new path.
Wire-up:
- OCaml `bin/run_tests.ml`: load `plugins/worker.sx` and
`plugins/prolog.sx` after `runtime.sx`, before `integration.sx`.
- JS `tests/hs-kernel-eval.js`: extend HS module list with
`hs-worker` / `hs-prolog`; add `HS_PLUGINS` resolver branch so the
`hs-` prefix maps to `lib/hyperscript/plugins/`.
- WASM `hosts/ocaml/browser/bundle.sh`: copy plugin files into
`dist/sx/hs-<name>.sx`.
- WASM `hosts/ocaml/browser/compile-modules.js`: add `hs-worker` /
`hs-prolog` to `FILES`, `HS_DEPS`, and `HS_LAZY` so the lazy loader
resolves them on first reference.
- Worker plugin carries a sentinel `(define hs-worker-loaded? true)`
so `extractDefines` indexes it in the module manifest (the lazy
loader skips files with no defines).
Mirrors `shared/static/wasm/sx/hs-{parser,runtime}.sx` are byte-identical
to source; new mirrors `hs-{prolog,worker}.sx` written via sx_write_file.
OCaml: 4545 passed, 1339 failed — matches baseline.
JS: 2591 passed, 2465 failed — matches baseline.
Smoke tests: `(prolog ...)` raises "prolog hook not installed" cleanly,
`(hs-set-prolog-hook! ...)` then `(prolog ...)` returns the hook result,
`(hs-compile "worker MyWorker def noop() end end")` raises the worker
stub error via the registry path.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
96 lines
2.9 KiB
Bash
Executable File
96 lines
2.9 KiB
Bash
Executable File
#!/bin/bash
|
|
# Bundle the WASM SX kernel + platform + .sx files for serving.
|
|
#
|
|
# Output goes to hosts/ocaml/browser/dist/
|
|
# Serve dist/ at /wasm/ or similar path.
|
|
|
|
set -e
|
|
cd "$(dirname "$0")"
|
|
|
|
BUILD=../_build/default/browser
|
|
DIST=dist
|
|
ROOT=../../..
|
|
|
|
echo "=== Bundling SX WASM browser engine ==="
|
|
|
|
rm -rf "$DIST"
|
|
mkdir -p "$DIST/sx"
|
|
|
|
# 1. WASM kernel
|
|
cp "$BUILD/sx_browser.bc.wasm.js" "$DIST/"
|
|
cp -r "$BUILD/sx_browser.bc.wasm.assets" "$DIST/"
|
|
|
|
# Also copy js_of_ocaml version as fallback
|
|
cp "$BUILD/sx_browser.bc.js" "$DIST/"
|
|
|
|
# 2. Platform JS
|
|
cp sx-platform.js "$DIST/"
|
|
|
|
# 3. Spec modules
|
|
cp "$ROOT/spec/signals.sx" "$DIST/sx/core-signals.sx"
|
|
cp "$ROOT/spec/render.sx" "$DIST/sx/"
|
|
cp "$ROOT/web/web-signals.sx" "$DIST/sx/signals.sx"
|
|
cp "$ROOT/web/deps.sx" "$DIST/sx/"
|
|
cp "$ROOT/web/router.sx" "$DIST/sx/"
|
|
cp "$ROOT/web/page-helpers.sx" "$DIST/sx/"
|
|
|
|
# 3b. Freeze scope (signal persistence) + highlight (syntax coloring)
|
|
cp "$ROOT/lib/freeze.sx" "$DIST/sx/"
|
|
cp "$ROOT/lib/highlight.sx" "$DIST/sx/"
|
|
|
|
# 4. Bytecode compiler + VM
|
|
cp "$ROOT/lib/bytecode.sx" "$DIST/sx/"
|
|
cp "$ROOT/lib/compiler.sx" "$DIST/sx/"
|
|
cp "$ROOT/lib/vm.sx" "$DIST/sx/"
|
|
|
|
# 5. Web libraries (8 FFI primitives)
|
|
cp "$ROOT/web/lib/dom.sx" "$DIST/sx/"
|
|
cp "$ROOT/web/lib/browser.sx" "$DIST/sx/"
|
|
|
|
# 6. Web adapters
|
|
cp "$ROOT/web/adapter-html.sx" "$DIST/sx/"
|
|
cp "$ROOT/web/adapter-sx.sx" "$DIST/sx/"
|
|
cp "$ROOT/web/adapter-dom.sx" "$DIST/sx/"
|
|
|
|
# 7. Boot helpers (platform functions in pure SX)
|
|
cp "$ROOT/web/lib/boot-helpers.sx" "$DIST/sx/"
|
|
cp "$ROOT/web/lib/hypersx.sx" "$DIST/sx/"
|
|
|
|
# 7b. Test harness (for inline test runners)
|
|
cp "$ROOT/spec/harness.sx" "$DIST/sx/"
|
|
cp "$ROOT/web/harness-reactive.sx" "$DIST/sx/"
|
|
cp "$ROOT/web/harness-web.sx" "$DIST/sx/"
|
|
|
|
# 8. Web framework
|
|
cp "$ROOT/web/engine.sx" "$DIST/sx/"
|
|
cp "$ROOT/web/orchestration.sx" "$DIST/sx/"
|
|
cp "$ROOT/web/boot.sx" "$DIST/sx/"
|
|
|
|
# 9. Styling (tw token engine)
|
|
cp "$ROOT/shared/sx/templates/tw-layout.sx" "$DIST/sx/"
|
|
cp "$ROOT/shared/sx/templates/tw-type.sx" "$DIST/sx/"
|
|
cp "$ROOT/shared/sx/templates/tw.sx" "$DIST/sx/"
|
|
|
|
# 10. Hyperscript
|
|
for f in tokenizer parser compiler runtime integration htmx; do
|
|
cp "$ROOT/lib/hyperscript/$f.sx" "$DIST/sx/hs-$f.sx"
|
|
done
|
|
for f in worker prolog; do
|
|
cp "$ROOT/lib/hyperscript/plugins/$f.sx" "$DIST/sx/hs-$f.sx"
|
|
done
|
|
|
|
# Summary
|
|
WASM_SIZE=$(du -sh "$DIST/sx_browser.bc.wasm.assets" | cut -f1)
|
|
JS_SIZE=$(du -sh "$DIST/sx_browser.bc.js" | cut -f1)
|
|
SX_SIZE=$(du -sh "$DIST/sx" | cut -f1)
|
|
echo " WASM kernel: $WASM_SIZE (assets)"
|
|
echo " JS fallback: $JS_SIZE"
|
|
echo " SX sources: $SX_SIZE ($(ls "$DIST/sx/" | wc -l) files)"
|
|
echo " Platform JS: $(du -sh "$DIST/sx-platform.js" | cut -f1)"
|
|
echo ""
|
|
echo " dist/ ready to serve"
|
|
echo ""
|
|
echo " HTML usage:"
|
|
echo ' <script src="/wasm/sx_browser.bc.wasm.js"></script>'
|
|
echo ' <script src="/wasm/sx-platform.js"></script>'
|