Files
rose-ash/lib/serialize.sx
giles bca0d8e4e5 Step 15: bytecode + CEK state serialization — 16 tests
bytecode-serialize/deserialize: sxbc v2 format wrapping compiled code
dicts. cek-serialize/deserialize: cek-state v1 format wrapping suspended
CEK state (phase, request, env, kont). Both use SX s-expression
round-trip via inspect/parse. lib/serialize.sx has pure SX versions.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-11 08:19:16 +00:00

40 lines
1.1 KiB
Plaintext

;; Bytecode + CEK state serialization
;; Uses SX s-expression format for portability across all hosts.
;; ── Bytecode serialization ────────────────────────────────────────
(define
bytecode-serialize
(fn (code) (str "(sxbc 2 " (serialize code) ")")))
(define
bytecode-deserialize
(fn
(s)
(let
((parsed (first (sx-parse s))))
(if
(and (list? parsed) (>= (len parsed) 3) (= (first parsed) "sxbc"))
(nth parsed 2)
(error "bytecode-deserialize: invalid sxbc format")))))
;; ── CEK state serialization ───────────────────────────────────────
(define
cek-serialize
(fn (state) (str "(cek-state 1 " (serialize state) ")")))
(define
cek-deserialize
(fn
(s)
(let
((parsed (first (sx-parse s))))
(if
(and
(list? parsed)
(>= (len parsed) 3)
(= (first parsed) "cek-state"))
(nth parsed 2)
(error "cek-deserialize: invalid cek-state format")))))