From 4ff9be7699dc5b15cd2272692d62e89432866d64 Mon Sep 17 00:00:00 2001 From: Miguel Sofer Date: Sat, 21 Mar 2009 03:43:53 +0000 Subject: * generic/tclExecute.c: fix both test and code for tailcall * tests/tailcall.test: from within a compiled [eval] body. --- ChangeLog | 5 ++++- generic/tclExecute.c | 10 +++++++++- tests/tailcall.test | 8 +++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0d95bad..6fec71e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,7 @@ -2009-03-20 Miguel Sofer +2009-03-21 Miguel Sofer + + * generic/tclExecute.c: fix both test and code for tailcall + * tests/tailcall.test: from within a compiled [eval] body. * tests/tailcall.test: slightly improved tests diff --git a/generic/tclExecute.c b/generic/tclExecute.c index 5e8b1a7..56bace2 100644 --- a/generic/tclExecute.c +++ b/generic/tclExecute.c @@ -14,7 +14,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclExecute.c,v 1.430 2009/03/20 14:43:27 dgp Exp $ + * RCS: @(#) $Id: tclExecute.c,v 1.431 2009/03/21 03:43:53 msofer Exp $ */ #include "tclInt.h" @@ -1992,6 +1992,14 @@ TclExecuteByteCode( /*NRE_ASSERT(iPtr->cmdFramePtr == bcFramePtr);*/ iPtr->cmdFramePtr = bcFramePtr->nextPtr; + /* + * If the CallFrame is marked as tailcalling, keep tailcalling + */ + + if (iPtr->varFramePtr->tailcallPtr) { + goto abnormalReturn; + } + if (iPtr->execEnvPtr->rewind) { result = TCL_ERROR; goto abnormalReturn; diff --git a/tests/tailcall.test b/tests/tailcall.test index 0c91488..fb6d662 100644 --- a/tests/tailcall.test +++ b/tests/tailcall.test @@ -9,7 +9,7 @@ # See the file "license.terms" for information on usage and redistribution # of this file, and for a DISCLAIMER OF ALL WARRANTIES. # -# RCS: @(#) $Id: tailcall.test,v 1.2 2009/03/21 01:23:38 msofer Exp $ +# RCS: @(#) $Id: tailcall.test,v 1.3 2009/03/21 03:43:53 msofer Exp $ if {[lsearch [namespace children] ::tcltest] == -1} { package require tcltest @@ -222,6 +222,7 @@ test tailcall-9 {tailcall factorial} -setup { } -result {1 120 3628800 1307674368000} test tailcall-10a {tailcall and eval} -constraints {knownBug} -setup { + set ::x 0 proc a {} { eval [list tailcall lappend ::x 2] set ::x 1 @@ -230,9 +231,10 @@ test tailcall-10a {tailcall and eval} -constraints {knownBug} -setup { list [a] $::x } -cleanup { unset -nocomplain ::x -} -result {{1 2} {1 2}} +} -result {{0 2} {0 2}} test tailcall-10b {tailcall and eval} -setup { + set ::x 0 proc a {} { eval {tailcall lappend ::x 2} set ::x 1 @@ -241,7 +243,7 @@ test tailcall-10b {tailcall and eval} -setup { list [a] $::x } -cleanup { unset -nocomplain ::x -} -result {{1 2} {1 2}} +} -result {{0 2} {0 2}} test tailcall-11a {tailcall and uplevel} -setup { proc a {} { -- cgit v0.12