hs: query targets, prolog hook, loop scripts, new plans, WASM regen
Hyperscript compiler/runtime:
- query target support in set/fire/put commands
- hs-set-prolog-hook! / hs-prolog-hook / hs-prolog in runtime
- runtime log-capture cleanup
Scripts: sx-loops-up/down, sx-hs-e-up/down, sx-primitives-down
Plans: datalog, elixir, elm, go, koka, minikanren, ocaml, hs-bucket-f,
designs (breakpoint, null-safety, step-limit, tell, cookies, eval,
plugin-system)
lib/prolog/hs-bridge.sx: initial hook-based bridge draft
lib/common-lisp/tests/runtime.sx: CL runtime tests
WASM: regenerate sx_browser.bc.js from updated hs sources
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -41,7 +41,7 @@
|
||||
// =========================================================================
|
||||
|
||||
var NIL = Object.freeze({ _nil: true, toString: function() { return "nil"; } });
|
||||
var SX_VERSION = "2026-05-01T18:54:28Z";
|
||||
var SX_VERSION = "2026-05-01T19:10:01Z";
|
||||
|
||||
function isNil(x) { return x === NIL || x === null || x === undefined; }
|
||||
function isSxTruthy(x) { return x !== false && !isNil(x); }
|
||||
@@ -186,6 +186,7 @@
|
||||
if (x._hash_table) return "hash-table";
|
||||
if (x._sxset) return "set";
|
||||
if (x._regexp) return "regexp";
|
||||
if (x._bytevector) return "bytevector";
|
||||
if (x._rational) return "rational";
|
||||
if (typeof Node !== "undefined" && x instanceof Node) return "dom-node";
|
||||
if (Array.isArray(x)) return "list";
|
||||
@@ -1213,6 +1214,73 @@
|
||||
};
|
||||
|
||||
|
||||
// stdlib.bytevectors — R7RS bytevector type backed by Uint8Array
|
||||
function SxBytevector(size_or_buf) {
|
||||
if (size_or_buf instanceof Uint8Array) {
|
||||
this.data = size_or_buf;
|
||||
} else {
|
||||
this.data = new Uint8Array(typeof size_or_buf === "number" ? size_or_buf : 0);
|
||||
}
|
||||
this._bytevector = true;
|
||||
}
|
||||
SxBytevector.prototype._type = "bytevector";
|
||||
PRIMITIVES["make-bytevector"] = function(n, fill) {
|
||||
var bv = new SxBytevector(n);
|
||||
if (fill !== undefined) bv.data.fill(fill & 0xff);
|
||||
return bv;
|
||||
};
|
||||
PRIMITIVES["bytevector?"] = function(v) { return v instanceof SxBytevector; };
|
||||
PRIMITIVES["bytevector-length"] = function(bv) { return bv.data.length; };
|
||||
PRIMITIVES["bytevector-u8-ref"] = function(bv, i) { return bv.data[i]; };
|
||||
PRIMITIVES["bytevector-u8-set!"] = function(bv, i, byte) { bv.data[i] = byte & 0xff; return NIL; };
|
||||
PRIMITIVES["bytevector-copy"] = function(bv, start, end_) {
|
||||
var s = start === undefined ? 0 : start;
|
||||
var e = end_ === undefined ? bv.data.length : end_;
|
||||
return new SxBytevector(bv.data.slice(s, e));
|
||||
};
|
||||
PRIMITIVES["bytevector-copy!"] = function(dst, at, src, start, end_) {
|
||||
var s = start === undefined ? 0 : start;
|
||||
var e = end_ === undefined ? src.data.length : end_;
|
||||
dst.data.set(src.data.subarray(s, e), at);
|
||||
return NIL;
|
||||
};
|
||||
PRIMITIVES["bytevector-append"] = function() {
|
||||
var total = 0;
|
||||
for (var i = 0; i < arguments.length; i++) total += arguments[i].data.length;
|
||||
var result = new Uint8Array(total);
|
||||
var pos = 0;
|
||||
for (var i = 0; i < arguments.length; i++) {
|
||||
result.set(arguments[i].data, pos);
|
||||
pos += arguments[i].data.length;
|
||||
}
|
||||
return new SxBytevector(result);
|
||||
};
|
||||
PRIMITIVES["utf8->string"] = function(bv, start, end_) {
|
||||
var s = start === undefined ? 0 : start;
|
||||
var e = end_ === undefined ? bv.data.length : end_;
|
||||
var dec = new TextDecoder("utf-8");
|
||||
return dec.decode(bv.data.subarray(s, e));
|
||||
};
|
||||
PRIMITIVES["string->utf8"] = function(str, start, end_) {
|
||||
var enc = new TextEncoder();
|
||||
var full = enc.encode(str);
|
||||
var s = start === undefined ? 0 : start;
|
||||
var e = end_ === undefined ? full.length : end_;
|
||||
return new SxBytevector(full.slice(s, e));
|
||||
};
|
||||
PRIMITIVES["bytevector->list"] = function(bv) {
|
||||
var out = [];
|
||||
for (var i = 0; i < bv.data.length; i++) out.push(bv.data[i]);
|
||||
return out;
|
||||
};
|
||||
PRIMITIVES["list->bytevector"] = function(lst) {
|
||||
if (!Array.isArray(lst)) lst = [];
|
||||
var b = new Uint8Array(lst.length);
|
||||
for (var i = 0; i < lst.length; i++) b[i] = lst[i] & 0xff;
|
||||
return new SxBytevector(b);
|
||||
};
|
||||
|
||||
|
||||
function isPrimitive(name) { return name in PRIMITIVES; }
|
||||
function getPrimitive(name) { return PRIMITIVES[name]; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user