Rebuild WASM: bytecode with pending_cek snapshot fix
All .sxbc recompiled with fixed sx_vm.ml. 32/32 WASM tests, 4/4 bytecode regression tests. hs-repeat-times correctly does 6 io-sleep suspensions in bytecode mode. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -81,18 +81,62 @@
|
||||
|
||||
K.registerNative("host-callback", function(args) {
|
||||
var fn = args[0];
|
||||
// Native JS function — pass through
|
||||
if (typeof fn === "function") return fn;
|
||||
// SX callable (has __sx_handle) — wrap as JS function
|
||||
// Native JS function (not SX-origin) — pass through
|
||||
if (typeof fn === "function" && fn.__sx_handle === undefined) return fn;
|
||||
// SX callable (has __sx_handle) — wrap as JS function with suspension handling
|
||||
if (fn && fn.__sx_handle !== undefined) {
|
||||
return function() {
|
||||
var a = Array.prototype.slice.call(arguments);
|
||||
return K.callFn(fn, a);
|
||||
var result = K.callFn(fn, a);
|
||||
// Handle IO suspension chain (e.g. wait, fetch, navigate)
|
||||
_driveAsync(result);
|
||||
return result;
|
||||
};
|
||||
}
|
||||
return function() {};
|
||||
});
|
||||
|
||||
/**
|
||||
* Drive an async suspension chain to completion.
|
||||
* When K.callFn returns {suspended: true, request: ..., resume: fn},
|
||||
* handle the IO operation and resume the VM.
|
||||
*/
|
||||
function _driveAsync(result) {
|
||||
if (!result || !result.suspended) return;
|
||||
console.log("[sx] IO suspension:", JSON.stringify(result.request, null, 2));
|
||||
var req = result.request;
|
||||
if (!req) return;
|
||||
|
||||
// req is an SX list — extract items. K returns SX values.
|
||||
var items = req.items || req;
|
||||
var op = (items && items[0]) || req;
|
||||
// Normalize: op might be a string or {name: "..."} symbol
|
||||
var opName = (typeof op === "string") ? op : (op && op.name) || String(op);
|
||||
|
||||
if (opName === "wait" || opName === "io-sleep") {
|
||||
// (wait ms) or (io-sleep ms) — resume after timeout
|
||||
var ms = (items && items[1]) || 0;
|
||||
if (typeof ms !== "number") ms = parseFloat(ms) || 0;
|
||||
console.log("[sx] IO wait: " + ms + "ms, resuming after timeout");
|
||||
setTimeout(function() {
|
||||
try {
|
||||
var resumed = result.resume(null);
|
||||
console.log("[sx] IO resumed:", typeof resumed, resumed && resumed.suspended ? "suspended-again" : "done", JSON.stringify(resumed));
|
||||
_driveAsync(resumed);
|
||||
} catch(e) {
|
||||
console.error("[sx] IO resume error:", e);
|
||||
}
|
||||
}, ms);
|
||||
} else if (opName === "navigate") {
|
||||
// (navigate url) — browser navigation
|
||||
var url = (items && items[1]) || "/";
|
||||
if (typeof url !== "string") url = String(url);
|
||||
window.location.href = url;
|
||||
} else {
|
||||
console.warn("[sx] Unhandled IO suspension in callback:", opName, req);
|
||||
}
|
||||
}
|
||||
|
||||
K.registerNative("host-typeof", function(args) {
|
||||
var obj = args[0];
|
||||
if (obj == null) return "nil";
|
||||
@@ -526,7 +570,10 @@
|
||||
"sx/adapter-html.sx", "sx/adapter-sx.sx", "sx/adapter-dom.sx",
|
||||
"sx/boot-helpers.sx", "sx/hypersx.sx", "sx/harness.sx",
|
||||
"sx/harness-reactive.sx", "sx/harness-web.sx",
|
||||
"sx/engine.sx", "sx/orchestration.sx", "sx/boot.sx",
|
||||
"sx/engine.sx", "sx/orchestration.sx",
|
||||
"sx/hs-tokenizer.sx", "sx/hs-parser.sx", "sx/hs-compiler.sx",
|
||||
"sx/hs-runtime.sx", "sx/hs-integration.sx",
|
||||
"sx/boot.sx",
|
||||
];
|
||||
if (K.beginModuleLoad) K.beginModuleLoad();
|
||||
for (var i = 0; i < files.length; i++) {
|
||||
@@ -644,6 +691,13 @@
|
||||
"hydrated:", !!islands[j]._sxBoundislandhydrated || !!islands[j]["_sxBound" + "island-hydrated"],
|
||||
"children:", islands[j].children.length);
|
||||
}
|
||||
// Activate _hyperscript compat on elements with _ attribute
|
||||
if (document.querySelector('[_]')) {
|
||||
if (K.beginModuleLoad) K.beginModuleLoad();
|
||||
loadLibrary("hyperscript integration", {});
|
||||
if (K.endModuleLoad) K.endModuleLoad();
|
||||
K.eval("(hs-boot!)");
|
||||
}
|
||||
// Register popstate handler for back/forward navigation
|
||||
window.addEventListener("popstate", function(e) {
|
||||
var state = e.state;
|
||||
|
||||
Reference in New Issue
Block a user