Wraps all core .sx files in R7RS define-library with explicit export lists, plus (import ...) at end for backward-compatible global re-export. Libraries registered: (sx bytecode) — 83 opcode constants (sx render) — 15 tag registries + render helpers (sx signals) — 23 reactive signal primitives (sx r7rs) — 21 R7RS aliases (sx compiler) — 42 compiler functions (sx vm) — 32 VM functions (sx freeze) — 9 freeze/thaw functions (sx content) — 6 content store functions (sx callcc) — 1 call/cc wrapper (sx highlight) — 13 syntax highlighting functions (sx stdlib) — 47 stdlib functions (sx swap) — 13 swap algebra functions (sx render-trace) — 8 render trace functions (sx harness) — 21 test harness functions (sx canonical) — 12 canonical serialization functions (web adapter-html) — 13 HTML renderer functions (web adapter-sx) — 13 SX wire format functions (web engine) — 33 hypermedia engine functions (web request-handler) — 4 request handling functions (web page-helpers) — 12 page helper functions (web router) — 36 routing functions (web deps) — 19 dependency analysis functions (web orchestration) — 59 page orchestration functions Key changes: - define-library now inherits parent env (env-extend env instead of env-extend make-env) so library bodies can access platform primitives - sx_server.ml: added resolve_library_path + load_library_file for import resolution (maps library specs to file paths) - cek_run_with_io: handles "import" locally instead of sending to Python bridge 2608/2608 tests passing. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
66 lines
1.8 KiB
Plaintext
66 lines
1.8 KiB
Plaintext
;; ==========================================================================
|
|
;; content.sx — Content-addressed computation
|
|
;;
|
|
;; Hash frozen SX to a content identifier. Store and retrieve by CID.
|
|
;; The content IS the address — same SX always produces the same CID.
|
|
;;
|
|
;; This is a library built on top of freeze.sx. It is NOT part of the
|
|
;; core evaluator. Load order: evaluator.sx → freeze.sx → content.sx
|
|
;;
|
|
;; Uses an in-memory content store. Applications can persist to
|
|
;; localStorage or IPFS by providing their own store backend.
|
|
;; ==========================================================================
|
|
|
|
|
|
(define-library (sx content)
|
|
(export
|
|
content-store
|
|
content-hash
|
|
content-put
|
|
content-get
|
|
freeze-to-cid
|
|
thaw-from-cid)
|
|
(begin
|
|
|
|
(define content-store (dict))
|
|
|
|
(define content-hash :effects []
|
|
(fn (sx-text)
|
|
;; djb2 hash → hex string. Simple, deterministic, fast.
|
|
;; Real deployment would use SHA-256 / multihash.
|
|
(let ((hash 5381))
|
|
(for-each (fn (i)
|
|
(set! hash (mod (+ (* hash 33) (char-code-at sx-text i)) 4294967296)))
|
|
(range 0 (len sx-text)))
|
|
(to-hex hash))))
|
|
|
|
(define content-put :effects [mutation]
|
|
(fn (sx-text)
|
|
(let ((cid (content-hash sx-text)))
|
|
(dict-set! content-store cid sx-text)
|
|
cid)))
|
|
|
|
(define content-get :effects []
|
|
(fn (cid)
|
|
(get content-store cid)))
|
|
|
|
;; Freeze a scope → store → return CID
|
|
(define freeze-to-cid :effects [mutation]
|
|
(fn (scope-name)
|
|
(let ((sx-text (freeze-to-sx scope-name)))
|
|
(content-put sx-text))))
|
|
|
|
;; Thaw from CID → look up → restore
|
|
(define thaw-from-cid :effects [mutation]
|
|
(fn (cid)
|
|
(let ((sx-text (content-get cid)))
|
|
(when sx-text
|
|
(thaw-from-sx sx-text)
|
|
true))))
|
|
|
|
|
|
)) ;; end define-library
|
|
|
|
;; Re-export to global namespace for backward compatibility
|
|
(import (sx content))
|