Can save/restore actor table to/from disk. master
authorTim Vaughan <plugd@thelambdalab.xyz>
Thu, 15 Apr 2021 14:27:27 +0000 (16:27 +0200)
committerTim Vaughan <plugd@thelambdalab.xyz>
Thu, 15 Apr 2021 14:27:27 +0000 (16:27 +0200)
actors.scm
testing_factorial1.scm

index fc266a3..1c19346 100644 (file)
@@ -6,12 +6,17 @@
    send-and-run
    restart
    enable-trace
    send-and-run
    restart
    enable-trace
-   disable-trace)
+   disable-trace
+   save-actors
+   save-actors-to
+   load-actors
+   load-actors-from)
 
   (import scheme
           (chicken base)
           srfi-69
 
   (import scheme
           (chicken base)
           srfi-69
-          matchable)
+          matchable
+          s11n)
 
   (define trace-enabled #f) ;used for debugging
 
 
   (define trace-enabled #f) ;used for debugging
 
 
   (define (restart)
     (set! message-queue (make-fifo))
 
   (define (restart)
     (set! message-queue (make-fifo))
-    (set! actor-table (make-hash-table))))
+    (set! actor-table (make-hash-table)))
+
+;;;
+;;; Serialization
+;;;
+
+  (define (save-actors-to filename)
+    (with-output-to-file filename
+      (lambda ()
+        (serialize (hash-table->alist actor-table)))))
+
+  (define (save-actors)
+    (save-actors-to "image"))
+
+  (define (load-actors-from filename)
+    (set! actor-table
+      (alist->hash-table (with-input-from-file filename deserialize))))
+
+  (define (load-actors)
+    load-actors-from "image"))
index aa3d1f0..0041f33 100644 (file)
@@ -1,4 +1,5 @@
-(import actors)
+(import actors
+        matchable)
 
 (enable-trace)
 
 
 (enable-trace)