Ticket #1408: suspension.diff

File suspension.diff, 1.4 KB (added by felix winkelmann, 4 years ago)
  • suspension.scm

     
    55                    continuation-drop
    66                    continuation-suspend
    77                    continuation-resume)
    8   (import scheme chicken ports)
     8  (import scheme chicken ports foreign)
    99
    1010(use srfi-18 s11n)
    1111
     
    5353         (lambda () (store (get-output-string o)))
    5454         continuation-drop) ) ) ) ) )
    5555
     56(define direct-return
     57  (foreign-lambda* void ((scheme-object dk) (scheme-object x))
     58    "C_kontinue(dk, x);"))
     59
    5660(define (continuation-resume k . results)
    57   (##sys#direct-return (with-input-from-string k deserialize) results) )
     61  (direct-return (with-input-from-string k deserialize) results) )
    5862
    5963)
  • tests/simple-test.scm

     
    44
    55(let ((args (command-line-arguments)))
    66  (cond ((member "store" args)
    7          (print "saving ...")
    87         (with-limited-continuation
    98          (lambda ()
    109            (let ((r (continuation-suspend
    1110                      (lambda (k)
     11                        (print "saving ...")
    1212                        (with-output-to-file "k.data" (cut display k))))))
    1313              (print "reenter: " r)
    1414              (exit)))))
     
    1616         (print "loading ...")
    1717         (continuation-resume
    1818          (with-input-from-file "k.data" read-string)
    19           #f))
     19          123))
    2020        (else (print "load or store?"))))