aboutsummaryrefslogtreecommitdiff
path: root/tests/tailcall.test
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2014-01-03 09:46:40 +1000
committerSteve Bennett <steveb@workware.net.au>2014-01-03 11:02:57 +1000
commit381cd0bed1a0ed9421eb1f5a0d368ec95024fd23 (patch)
treec4a79855f960c2d6dcd96d23f82f5cb2bb339bdd /tests/tailcall.test
parentc07febeefdee3e620d61152574267107d59a1d6b (diff)
downloadjimtcl-381cd0bed1a0ed9421eb1f5a0d368ec95024fd23.zip
jimtcl-381cd0bed1a0ed9421eb1f5a0d368ec95024fd23.tar.gz
jimtcl-381cd0bed1a0ed9421eb1f5a0d368ec95024fd23.tar.bz2
tailcall: properly merge tailcall frames
Resolve the tailcall command immediately in [tailcall] and stash it. If a tailcall is currently being evaluated, new tailcalls in the same frame are merged/deferred to evaluate in the same C stack frame. Can't merge tailcall evaluations across uplevel. Add some tests for these cases Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'tests/tailcall.test')
-rw-r--r--tests/tailcall.test44
1 files changed, 43 insertions, 1 deletions
diff --git a/tests/tailcall.test b/tests/tailcall.test
index 4657947..eaa48cc 100644
--- a/tests/tailcall.test
+++ b/tests/tailcall.test
@@ -1,3 +1,5 @@
+# vim:se syntax=tcl:
+
source [file dirname [info script]]/testing.tcl
needs cmd tailcall
@@ -58,7 +60,7 @@ test tailcall-1.6 {tailcall pass through return} {
b
} {ok}
-test tailcall-1.7 {tailcall with namespaces} {
+test tailcall-1.7 {tailcall with namespaces} jim {
proc a::b {} {
proc c {} {
return 1
@@ -70,4 +72,44 @@ test tailcall-1.7 {tailcall with namespaces} {
a::b
} 1
+test tailcall-1.8 {tailcall with local} jim {
+ proc a {} {
+ tailcall [local proc b {} { return c }]
+ }
+ a
+} {c}
+
+test tailcall-1.9 {tailcall with large number of invocations} {
+ proc a {n} {
+ if {$n == 0} {
+ return 1
+ }
+ incr n -1
+ tailcall a $n
+ }
+ a 1000
+} 1
+
+test tailcall-1.10 {tailcall through uplevel} {
+ proc a {} { tailcall b }
+ proc b {} { uplevel 1 c }
+ proc c {} { tailcall d }
+ proc d {} { return [info level] }
+ a
+} 1
+
+test tailcall-1.11 {chained tailcall} {
+ proc a {} { b }
+ proc b {} { tailcall tailcall c }
+ proc c {} { return [info level] }
+ a
+} 1
+
+test tailcall-1.12 {uplevel tailcall} {
+ proc a {} { b }
+ proc b {} { uplevel 1 tailcall c }
+ proc c {} { return [info level] }
+ a
+} 1
+
testreport