diff --git a/compile.rkt b/compile.rkt index cedab8f..752769a 100644 --- a/compile.rkt +++ b/compile.rkt @@ -395,7 +395,7 @@ ;; This case happens for set!, which may install the results of an ;; application directly into the environment. (let ([proc-return (make-label 'procReturn)]) - (end-with-linkage linkage + (end-with-linkage linkage cenv-without-args (make-instruction-sequence `(,(make-PushControlFrame proc-return) diff --git a/simulator.rkt b/simulator.rkt index c67b30f..9d73a74 100644 --- a/simulator.rkt +++ b/simulator.rkt @@ -309,6 +309,7 @@ [(GetControlStackLabel? op) (target-updater! m (frame-return (first (machine-control m))))] + [(CaptureEnvironment? op) (target-updater! m (make-CapturedEnvironment (drop (machine-env m) (CaptureEnvironment-skip op))))] diff --git a/test-compiler.rkt b/test-compiler.rkt index 8528561..90653ed 100644 --- a/test-compiler.rkt +++ b/test-compiler.rkt @@ -663,6 +663,57 @@ +(test '(begin (define a '(hello)) + (define b '(world)) + (define reset! + (lambda () + (set! a '()) + (reset!))) + (list a b)) + '(() (world))) + + +(test '(begin (define a '(hello)) + (define b '(world)) + (define reset! + (lambda () + (set! b '()))) + (reset!) + (list a b)) + '((hello) ())) + +(test '(begin (define a '(hello)) + (define b '(world)) + (define reset! + (lambda () + (set! a '()) + 'ok)) + (reset!) + (list a b)) + '(()(world))) + +(test '(begin (define a '(hello)) + (define b '(world)) + (define reset! + (lambda () + (set! b '()) + 'ok)) + (reset!) + (list a b)) + '((hello)())) + + +(test '(begin (define a '(hello)) + (define b '(world)) + (define reset! + (lambda () + (set! a '()) + (set! b '()))) + (reset!) + (list a b)) + '(()())) + + #;(test (read (open-input-file "tests/conform/program0.sch")) (port->string (open-input-file "tests/conform/expected0.txt")))