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>
This commit is contained in:
39
lib/serialize.sx
Normal file
39
lib/serialize.sx
Normal file
@@ -0,0 +1,39 @@
|
||||
;; 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")))))
|
||||
Reference in New Issue
Block a user