From cfdbbfaeaa1975b64a3699d88ec0f04af0e7783c Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Sat, 2 Apr 2011 00:57:34 -0400 Subject: [PATCH] traced the bug to an off-by-one, as usual... --- runtime.js | 7 ++++--- test-browser-evaluate.rkt | 23 +++++++++++++---------- test-compiler.rkt | 13 ++++++++++++- 3 files changed, 29 insertions(+), 14 deletions(-) diff --git a/runtime.js b/runtime.js index f21ae7c..96ed77b 100644 --- a/runtime.js +++ b/runtime.js @@ -70,9 +70,10 @@ var testArgument = function(expectedTypeName, var captureControl = function(MACHINE, skip, tag) { var i; - for (i = MACHINE.control.length - skip - 1; i >= 0; i--) { + for (i = MACHINE.control.length - 1 - skip; i >= 0; i--) { if (MACHINE.control[i].tag === tag) { - return MACHINE.control.slice(i, MACHINE.control.length - skip); + return MACHINE.control.slice(i + 1, + MACHINE.control.length - skip); } } raise(new Error("captureControl: unable to find tag " + tag)); @@ -85,7 +86,7 @@ var restoreControl = function(MACHINE, tag) { if (MACHINE.control[i].tag === tag) { MACHINE.control = MACHINE.control.slice(0, i+1).concat( - MACHINE.env[MACHINE.env.length - 1].slice(0)); + MACHINE.env[MACHINE.env.length - 1]); return; } } diff --git a/test-browser-evaluate.rkt b/test-browser-evaluate.rkt index 0c9c161..aab63e4 100644 --- a/test-browser-evaluate.rkt +++ b/test-browser-evaluate.rkt @@ -69,16 +69,6 @@ EOF -(test '(begin (define program (lambda () - (let ((y (call/cc (lambda (c) c)))) - (display 1) - (call/cc (lambda (c) (y c))) - (display 2) - (call/cc (lambda (c) (y c))) - (display 3)))) - (program)) - "11213") - (test '(display 42) "42") @@ -228,6 +218,19 @@ EOF (displayln (tak 18 12 6))) "7\n") + + +(test '(begin (displayln (+ 42 (call/cc (lambda (k) 3)))) ) + "45\n") + + +(test '(begin (displayln (+ 42 (call/cc (lambda (k) (k 100) 3)))) ) + "142\n") + +(test '(begin (displayln (+ 42 (call/cc (lambda (k) 100 (k 3))))) ) + "45\n") + + (test '(begin (define program (lambda () (let ((y (call/cc (lambda (c) c)))) (display 1) diff --git a/test-compiler.rkt b/test-compiler.rkt index 4abf689..7e30659 100644 --- a/test-compiler.rkt +++ b/test-compiler.rkt @@ -1001,7 +1001,18 @@ (error 'failure))) - +(test '(begin (define K #f) + (let ([x 3] + [y 4] + [z 5]) + (+ x y z (call/cc (lambda (r) + (set! K r) + 0)))) + (let* ([a 0] + [b 1]) + (+ 1024 (K 17)))) + 29 + #:with-bootstrapping? #t)