Fix platform JS: load .sxbc text format, not .sxbc.json
The bytecode compiler generates .sxbc (SX text format), not .sxbc.json. Updated loadBytecodeFile to fetch .sxbc and use load-sxbc for parsing. Eliminates 404s for non-existent .sxbc.json files. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -234,35 +234,28 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Try loading a pre-compiled .sxbc.json bytecode module.
|
* Try loading a pre-compiled .sxbc bytecode module (SX text format).
|
||||||
* Returns true on success, null on failure (caller falls back to .sx source).
|
* Returns true on success, null on failure (caller falls back to .sx source).
|
||||||
*/
|
*/
|
||||||
function loadBytecodeFile(path) {
|
function loadBytecodeFile(path) {
|
||||||
var bcPath = path.replace(/\.sx$/, '.sxbc.json');
|
var sxbcPath = path.replace(/\.sx$/, '.sxbc');
|
||||||
var url = _baseUrl + bcPath + _sxbcCacheBust;
|
var url = _baseUrl + sxbcPath + _sxbcCacheBust;
|
||||||
try {
|
try {
|
||||||
var xhr = new XMLHttpRequest();
|
var xhr = new XMLHttpRequest();
|
||||||
xhr.open("GET", url, false);
|
xhr.open("GET", url, false);
|
||||||
xhr.send();
|
xhr.send();
|
||||||
if (xhr.status !== 200) return null;
|
if (xhr.status !== 200) return null;
|
||||||
|
|
||||||
var json = JSON.parse(xhr.responseText);
|
window.__sxbcText = xhr.responseText;
|
||||||
if (!json.module || json.magic !== 'SXBC') return null;
|
var result = K.eval('(load-sxbc (first (parse (host-global "__sxbcText"))))');
|
||||||
|
delete window.__sxbcText;
|
||||||
var module = {
|
|
||||||
_type: 'dict',
|
|
||||||
bytecode: { _type: 'list', items: json.module.bytecode },
|
|
||||||
constants: { _type: 'list', items: json.module.constants.map(deserializeConstant) },
|
|
||||||
};
|
|
||||||
|
|
||||||
var result = K.loadModule(module);
|
|
||||||
if (typeof result === 'string' && result.indexOf('Error') === 0) {
|
if (typeof result === 'string' && result.indexOf('Error') === 0) {
|
||||||
console.warn("[sx-platform] bytecode FAIL " + path + ":", result);
|
console.warn("[sx-platform] bytecode FAIL " + path + ":", result);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
console.log("[sx-platform] ok " + path + " (bytecode)");
|
|
||||||
return true;
|
return true;
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
|
delete window.__sxbcText;
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -339,9 +339,11 @@
|
|||||||
for (var i = 0; i < files.length; i++) {
|
for (var i = 0; i < files.length; i++) {
|
||||||
var r = loadBytecodeFile(files[i]);
|
var r = loadBytecodeFile(files[i]);
|
||||||
if (r) { bcCount++; continue; }
|
if (r) { bcCount++; continue; }
|
||||||
// Bytecode not available — load source inside the batch (don't break it)
|
// Bytecode not available — end batch, load source, restart batch
|
||||||
|
if (K.endModuleLoad) K.endModuleLoad();
|
||||||
r = loadSxFile(files[i]);
|
r = loadSxFile(files[i]);
|
||||||
if (typeof r === "number") { loaded += r; srcCount++; }
|
if (typeof r === "number") { loaded += r; srcCount++; }
|
||||||
|
if (K.beginModuleLoad) K.beginModuleLoad();
|
||||||
}
|
}
|
||||||
if (K.endModuleLoad) K.endModuleLoad();
|
if (K.endModuleLoad) K.endModuleLoad();
|
||||||
console.log("[sx-platform] Loaded " + files.length + " files (" + bcCount + " bytecode, " + srcCount + " source, " + loaded + " exprs)");
|
console.log("[sx-platform] Loaded " + files.length + " files (" + bcCount + " bytecode, " + srcCount + " source, " + loaded + " exprs)");
|
||||||
|
|||||||
Reference in New Issue
Block a user