Content-addressed computation: freeze → hash → CID → thaw
Some checks failed
Build and Deploy / build-and-deploy (push) Has been cancelled
Some checks failed
Build and Deploy / build-and-deploy (push) Has been cancelled
Hash frozen SX to a content identifier (djb2 → hex). Same state always produces the same CID. Store by CID, retrieve by CID. - content-hash: djb2 hash of SX text → hex string - content-put/get: in-memory content store - freeze-to-cid: freeze scope → store → return CID - thaw-from-cid: look up CID → thaw signals - char-code-at / to-hex primitives for both platforms - Live demo: counter + name widget, content-address button, CID display, restore from CID input, CID history Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,7 @@
|
||||
// =========================================================================
|
||||
|
||||
var NIL = Object.freeze({ _nil: true, toString: function() { return "nil"; } });
|
||||
var SX_VERSION = "2026-03-15T00:04:32Z";
|
||||
var SX_VERSION = "2026-03-15T00:16:30Z";
|
||||
|
||||
function isNil(x) { return x === NIL || x === null || x === undefined; }
|
||||
function isSxTruthy(x) { return x !== false && !isNil(x); }
|
||||
@@ -5359,6 +5359,44 @@ PRIMITIVES["freeze-to-sx"] = freezeToSx;
|
||||
})(); };
|
||||
PRIMITIVES["thaw-from-sx"] = thawFromSx;
|
||||
|
||||
// content-store
|
||||
var contentStore = {};
|
||||
PRIMITIVES["content-store"] = contentStore;
|
||||
|
||||
// content-hash
|
||||
var contentHash = function(sxText) { return (function() {
|
||||
var hash = 5381;
|
||||
{ var _c = range(0, len(sxText)); for (var _i = 0; _i < _c.length; _i++) { var i = _c[_i]; hash = (((hash * 33) + charCodeAt(sxText, i)) % 4294967296); } }
|
||||
return toHex(hash);
|
||||
})(); };
|
||||
PRIMITIVES["content-hash"] = contentHash;
|
||||
|
||||
// content-put
|
||||
var contentPut = function(sxText) { return (function() {
|
||||
var cid = contentHash(sxText);
|
||||
contentStore[cid] = sxText;
|
||||
return cid;
|
||||
})(); };
|
||||
PRIMITIVES["content-put"] = contentPut;
|
||||
|
||||
// content-get
|
||||
var contentGet = function(cid) { return get(contentStore, cid); };
|
||||
PRIMITIVES["content-get"] = contentGet;
|
||||
|
||||
// freeze-to-cid
|
||||
var freezeToCid = function(scopeName) { return (function() {
|
||||
var sxText = freezeToSx(scopeName);
|
||||
return contentPut(sxText);
|
||||
})(); };
|
||||
PRIMITIVES["freeze-to-cid"] = freezeToCid;
|
||||
|
||||
// thaw-from-cid
|
||||
var thawFromCid = function(cid) { return (function() {
|
||||
var sxText = contentGet(cid);
|
||||
return (isSxTruthy(sxText) ? (thawFromSx(sxText), true) : NIL);
|
||||
})(); };
|
||||
PRIMITIVES["thaw-from-cid"] = thawFromCid;
|
||||
|
||||
|
||||
// === Transpiled from signals (reactive signal runtime) ===
|
||||
|
||||
@@ -5757,6 +5795,10 @@ PRIMITIVES["resource"] = resource;
|
||||
PRIMITIVES["is-html-tag?"] = function(n) { return HTML_TAGS.indexOf(n) >= 0; };
|
||||
PRIMITIVES["make-env"] = function() { return merge(componentEnv, PRIMITIVES); };
|
||||
|
||||
// String/number utilities for content addressing
|
||||
PRIMITIVES["char-code-at"] = function(s, i) { return s.charCodeAt(i); };
|
||||
PRIMITIVES["to-hex"] = function(n) { return (n >>> 0).toString(16); };
|
||||
|
||||
// localStorage — defined here (before boot) so islands can use at hydration
|
||||
PRIMITIVES["local-storage-get"] = function(key) {
|
||||
try { var v = localStorage.getItem(key); return v === null ? NIL : v; }
|
||||
|
||||
Reference in New Issue
Block a user