Asm gains the file I/O surface Python and C already had, unlocking 9/9 cells of the portal producer×consumer matrix (previously 6/9). asm: - (load "path") — mmaps file, swaps input source, loops scheme_read+eval, restores on exit. Nestable. Uses SYS_LSEEK + SYS_MUNMAP. - Output ports: (open-output-file), (close-port), (port?). Encoded as SPECIAL values ≥ 1000 (fd = (val>>3) − PORT_SPECIAL_BASE), no tag-bit expansion needed. - (display), (write), (newline) accept optional port arg; printer writes via output_fd global, swapped by port-aware builtins. - (write-file path content) / (file->string path) — bytes in/out. c, py: (write-file) / (file->string) added for parity. tests: 131 asm (up 23), 189 functional (up 8, shared py+c), tests/portal-cross-test.sh exercises 3×3 save×load matrix.
20 lines
849 B
Text
20 lines
849 B
Text
;;; portal-cross-save.lsp — write state to /tmp/cross.sexp
|
|
|
|
(define cross-int 777)
|
|
(define cross-list (list 'a 'b 'c 1 2 3))
|
|
(define cross-str "portal was here")
|
|
(define cross-fib
|
|
(let loop ((a 0) (b 1) (i 0))
|
|
(if (= i 20) a (loop b (+ a b) (+ i 1)))))
|
|
|
|
(define (cross-save filename)
|
|
(let ((port (open-output-file filename)))
|
|
(display ";; cross-impl portal (S-expression)\n" port)
|
|
(display "(define cross-int " port) (write cross-int port) (display ")\n" port)
|
|
(display "(define cross-list '" port) (write cross-list port) (display ")\n" port)
|
|
(display "(define cross-str " port) (write cross-str port) (display ")\n" port)
|
|
(display "(define cross-fib " port) (write cross-fib port) (display ")\n" port)
|
|
(close-port port)))
|
|
|
|
(cross-save "/tmp/cross.sexp")
|
|
(display "saved cross-fib=") (display cross-fib) (newline)
|