From aecc0ad89650873e35e6225d9272c99fd82a8660 Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Fri, 11 Mar 2011 19:24:57 -0500 Subject: [PATCH] call/cc looks like it's starting to work. --- compile.rkt | 2 +- simulator.rkt | 1 + test-compiler.rkt | 11 ++++++----- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/compile.rkt b/compile.rkt index f8a49ed..fd23c75 100644 --- a/compile.rkt +++ b/compile.rkt @@ -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)))))) diff --git a/simulator.rkt b/simulator.rkt index 339d2c0..d07e2c0 100644 --- a/simulator.rkt +++ b/simulator.rkt @@ -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]))) diff --git a/test-compiler.rkt b/test-compiler.rkt index eefb767..64cc05c 100644 --- a/test-compiler.rkt +++ b/test-compiler.rkt @@ -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))