The core evaluator (spec/evaluator.sx) is now the irreducible computational core with zero web, rendering, or type-system knowledge. 2531 → 2313 lines. - Add extensible special form registry (*custom-special-forms* + register-special-form!) - Add render dispatch hooks (*render-check* / *render-fn*) replacing hardcoded render-active?/is-render-expr?/render-expr - Extract freeze scopes → spec/freeze.sx (library, not core) - Extract content addressing → spec/content.sx (library, not core) - Move sf-deftype/sf-defeffect → spec/types.sx (self-registering) - Move sf-defstyle → web/forms.sx (self-registering with all web forms) - Move web tests (defpage, streaming) → web/tests/test-forms.sx - Add is-else-clause? helper (replaces 5 inline patterns) - Make escape-html/escape-attr library functions in render.sx (pure SX, not platform-provided) - Add foundations plan: Step 3.5 (data representations), Step 3.7 (verified components), OCaml for Step 4d - Update all three bootstrappers (JS 957/957, Python 744/744, OCaml 952/952) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
49 lines
1.6 KiB
Plaintext
49 lines
1.6 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 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))))
|