VM import suspension for browser lazy loading

Bytecode compiler now emits OP_PERFORM for (import ...) and compiles
(define-library ...) bodies. The VM stores the import request in
globals["__io_request"] and stops the run loop — no exceptions needed.
vm-execute-module returns a suspension dict, vm-resume-module continues.

Browser: sx_browser.ml detects suspension dicts from execute_module and
returns JS {suspended, op, request, resume} objects. The sx-platform.js
while loop handles cascading suspensions via handleImportSuspension.

13 modules load via .sxbc bytecode in 226ms (manifest-driven), both
islands hydrate, all handlers wired. 2650/2650 tests pass including
6 new vm-import-suspension tests.

Also: consolidated sx-platform-2.js → sx-platform.js, fixed
vm-execute-module missing code-from-value call, fixed bootstrap.py
protocol registry transpiler issues.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-04 17:11:12 +00:00
parent efd0d9168f
commit 2727577702
43 changed files with 4672 additions and 3991 deletions

View File

@@ -884,7 +884,7 @@ def _get_shell_static() -> dict[str, Any]:
sx_css=sx_css,
sx_css_classes=sx_css_classes,
wasm_hash=_wasm_hash("sx_browser.bc.wasm.js"),
platform_hash=_wasm_hash("sx-platform-2.js"),
platform_hash=_wasm_hash("sx-platform.js"),
sxbc_hash=_sxbc_hash(),
asset_url=_ca.config.get("ASSET_URL", "/static"),
inline_css=_shell_cfg.get("inline_css"),
@@ -1035,7 +1035,7 @@ def sx_page_streaming_parts(ctx: dict, page_html: str, *,
pages_sx = _build_pages_sx(current_app.name)
wasm_hash = _wasm_hash("sx_browser.bc.wasm.js")
platform_hash = _wasm_hash("sx-platform-2.js")
platform_hash = _wasm_hash("sx-platform.js")
sxbc_hash = _sxbc_hash()
# Shell: head + body with server-rendered HTML (not SX mount script)
@@ -1078,7 +1078,7 @@ def sx_page_streaming_parts(ctx: dict, page_html: str, *,
tail = (
_SX_STREAMING_BOOTSTRAP + '\n'
+ f'<script src="{asset_url}/wasm/sx_browser.bc.wasm.js?v={wasm_hash}"></script>\n'
f'<script src="{asset_url}/wasm/sx-platform-2.js?v={platform_hash}" data-sxbc-hash="{sxbc_hash}"></script>\n'
f'<script src="{asset_url}/wasm/sx-platform.js?v={platform_hash}" data-sxbc-hash="{sxbc_hash}"></script>\n'
)
return shell, tail

View File

@@ -81,5 +81,5 @@
"/wasm/sx_browser.bc.wasm.js?v="
(or wasm-hash "0")))
(script
:src (str asset-url "/wasm/sx-platform-2.js?v=" (or platform-hash "0"))
:src (str asset-url "/wasm/sx-platform.js?v=" (or platform-hash "0"))
:data-sxbc-hash (or sxbc-hash "0")))))))