call/cc looks like it's starting to work.

This commit is contained in:
Danny Yoo 2011-03-11 19:24:57 -05:00
parent fc866634cf
commit aecc0ad896
3 changed files with 8 additions and 6 deletions

View File

@ -599,9 +599,9 @@
;; abandon the current continuation, initialize the control and environment, and then jump.
(make-instruction-sequence `(,call/cc-closure-entry
,(make-AssignImmediateStatement 'val (make-EnvLexicalReference 0))
,(make-PerformStatement (make-InstallClosureValues!))
,(make-PerformStatement (make-RestoreControl!))
,(make-PerformStatement (make-RestoreEnvironment!))
,(make-AssignPrimOpStatement 'proc (make-GetControlStackLabel))
,(make-PopControlFrame)
,(make-GotoStatement (make-Reg 'proc))))))

View File

@ -198,6 +198,7 @@
[(RestoreEnvironment!? op)
(set-machine-env! m (CapturedEnvironment-vals (ensure-CapturedEnvironment (env-ref m 1))))
(set-machine-stack-size! m (length (machine-env m)))
'ok])))

View File

@ -26,6 +26,7 @@
#'stx))
(unless (= (machine-stack-size a-machine) 1)
(raise-syntax-error #f (format "Stack is not back to the prefix as expected!")
#'stx))
(unless (null? (machine-control a-machine))
(raise-syntax-error #f (format "Control is not empty as expected!")
@ -536,11 +537,11 @@
32)
(test (let ([x 16])
(call/cc (lambda (k)
(k "escape!")
(+ x x))))
"escape!")
(test (add1 (let ([x 16])
(call/cc (lambda (k)
(k 0)
(+ x x)))))
1)
;(simulate (compile (parse '42) 'val 'next))