store and resume

Johannes Bruegmann <[email protected]> Fri, 03 Apr 2009 16:10:48 +0200
Newsgroups gmane.comp.java.sisc.user
Message-ID <[email protected]>
Hello,

i am trying to get "store and resume" to work. I want to do some
computation and when a certain point of computation is reached store
the state of *everything* onto disk, in order to resume from thereon
later in a new session/repl.

The toy example looks like this and it works:

      bruegmann@vmax:scm# cat store-and-resume.scm
      (import file-manipulation)
      (import serial-io)
      
      (define (serialize-to-file fname val)
        (if (not (file-exists? fname))
            (call-with-serial-output-file fname (lambda (p) (serialize val p)))
            #f))
      
      (define (deserialize-from-file fname)
        (if (file-exists? fname)
            (call-with-serial-input-file fname deserialize)
            #f))
      
      (define-syntax with-environment
        (lambda (f)
          (syntax-case f ()
            ((_ env exp0 exp1 ...)
             (syntax (begin
                       (eval 'exp0 env)
                       (eval 'exp1 env)
                       ...
                       ))))))
      
      (define *environment*
        (make-child-environment (interaction-environment)))
      
      (let ((fname "foo.env"))
        (putprop 'fname *environment* fname)
        (if (not (file-exists? fname))
            (with-environment *environment*
              (define foo 12345)
              (serialize-to-file fname *environment*))
            (set! *environment* (deserialize-from-file fname))
            ))
      bruegmann@vmax:scm# sisc
      SISC (1.16.6)
      > (load "store-and-resume.scm")
      > (with-environment *environment* foo)
      12345
      > ^D
      bruegmann@vmax:scm# ls -l foo.env
      -rw-r--r--  1 bruegmann  bruegmann  6535  3 Apr 13:50 foo.env
      bruegmann@vmax:scm# sisc
      SISC (1.16.6)
      > (load "store-and-resume.scm")
      > (with-environment *environment* foo)
      12345
      > ^D
      bruegmann@vmax:scm# ls -l foo.env
      -rw-r--r--  1 bruegmann  bruegmann  6535  3 Apr 13:50 foo.env

A little more complex example like the following throws a
JavaNullPointerException:

      (require-library 'sisc/libs/srfi)
      (require-library 'sisc/misc/misc)
      
      (module bar 
          (baz make-frob frob? frob-a frob-b frob-c (color)
           color? colors color-name color-index (color-set)
           color-set? make-color-set color color? colors color-index)
      
        (import srfi-1)
        (import srfi-9)
        (import finite-types)
        (import enum-sets)
      
        (define baz #f)
        (define-record-type :frob 
          (make-frob a b c)
          frob?
          (a frob-a)
          (b frob-b)
          (c frob-c))
      
        (define-enumerated-type color :color
          color?
          colors
          color-name
          color-index
          (black white purple maroon))
        
        (define-enum-set-type color-set :color-set
          color-set?
          make-color-set
          color color? colors color-index)
      
        (set! baz (apply make-frob (fold-right (lambda (x unit) (cons x unit)) '() (list 1 2 3))))
      )
      
      bruegmann@vmax:scm# sisc
      SISC (1.16.6)
      > (load "store-and-resume.scm")
      > (with-environment *environment* (import bar) (color? (color red)))
      Error: invalid syntax (color red)
      ---------------------------
      Some stack trace entries may have been suppressed. To see all entries set the dynamic parameter suppressed-stack-trace-source-kinds to '().
      > (with-environment *environment* (import bar) (color? (color red)))
      Error: invalid syntax (color red)
      > (with-environment *environment* (import bar) (color? (color black)))
      #t
      > ^D
      bruegmann@vmax:scm# ls -l foo.env
      -rw-r--r--  1 bruegmann  bruegmann  997712  3 Apr 15:48 foo.env
      bruegmann@vmax:scm# sisc
      SISC (1.16.6)
      > (load "store-and-resume.scm")
      > (with-environment *environment* (import bar) (color? (color black)))
      java.lang.NullPointerException
              at sisc.io.PortValueWriter.append(Unknown Source)
              at sisc.io.PortValueWriter.displayOrWrite(Unknown Source)
              at sisc.io.PortValueWriter.display(Unknown Source)
              at sisc.modules.io.IO.displayOrWrite(Unknown Source)
              at sisc.modules.io.IO.doApply(Unknown Source)
              at sisc.nativefun.NativeProcedure.apply(Unknown Source)
              at sisc.exprs.AppEval.eval(Unknown Source)
              at sisc.interpreter.Interpreter.next(Unknown Source)
              at sisc.exprs.AppExp.eval(Unknown Source)
              at sisc.interpreter.Interpreter.next(Unknown Source)
              at sisc.exprs.EvalExp.eval(Unknown Source)
              at sisc.interpreter.Interpreter.interpret(Unknown Source)
              at sisc.interpreter.Interpreter.interpret(Unknown Source)
              at sisc.interpreter.Interpreter.interpret(Unknown Source)
              at sisc.interpreter.Interpreter.eval(Unknown Source)
              at sisc.data.SchemeThread.run(Unknown Source)
              at java.lang.Thread.run(Thread.java:595)
      Uncaught error: ((message . <java.lang.NullPointerException>: null) (location . eqv?) (java-exception . #<java java.lang.NullPointerException java.lang.NullPointerException>))
      Please report this error to [email protected]


While the real application i want to work with throwed this here:

      Error in load: evaluation error at file:/home/bruegmann/du/cvs-modules/traffic-nrw-ca/scm/store-and-resume.scm:29:1
      ---------------------------
      console:1:1: <from call to load>
      ---------------------------
      Some stack trace entries may have been suppressed. To see all entries set the dynamic parameter suppressed-stack-trace-source-kinds to '().
      ===========================
      Caused by Error in deserialize: error reading from port 'sisc.io.DeserializerStream@3aa42c31': java.lang.ClassNotFoundException: $Proxy1
      ---------------------------
      file:/home/bruegmann/du/cvs-modules/traffic-nrw-ca/scm/store-and-resume.scm:13:7: <from call to @serial-io::call-with-serial-input-file>
      file:/home/bruegmann/du/cvs-modules/traffic-nrw-ca/scm/store-and-resume.scm:36:27: <from call to deserialize-from-file>

What am i doing wrong? Is there a better way to do it?

Regards,
Johannes

-- 
       Jesus  said:  Unless a grain of wheat falls into the earth and dies, it
       remains alone; but if it dies, it bears much fruit.

                                                 John 12:24 (ESV)

------------------------------------------------------------------------------