Author: leo
Date: Tue May  3 07:23:13 2005
New Revision: 7959

Modified:
   trunk/imcc/pcc.c
   trunk/imcc/t/syn/tail.t
Log:
tail calls 2 - and functionality

Modified: trunk/imcc/pcc.c
==============================================================================
--- trunk/imcc/pcc.c    (original)
+++ trunk/imcc/pcc.c    Tue May  3 07:23:13 2005
@@ -862,13 +862,15 @@
     SymReg *s0 = NULL;
     Instruction *get_name;
 
-    tail_call = 0;
+    sub = ins->r[0];
+    tail_call = (sub->pcc_sub->flags & isTAIL_CALL);
 #ifdef CREATE_TAIL_CALLS
-    tail_call = check_tail_call(interp, unit, ins);
-    if (tail_call)
-        IMCC_debug(interp, DEBUG_OPT1, "found tail call %I \n", ins);
+    if (!tail_call) {
+        tail_call = check_tail_call(interp, unit, ins);
+        if (tail_call)
+            IMCC_debug(interp, DEBUG_OPT1, "found tail call %I \n", ins);
+    }
 #endif
-    sub = ins->r[0];
 
     if (sub->pcc_sub->object)
         meth_call = 1;
@@ -977,7 +979,6 @@
         }
     }
 
-#ifdef CREATE_TAIL_CALLS
     /*
      * if we have a tail call then
      * insert a tailcall opcode
@@ -988,7 +989,6 @@
             return;
         }
     }
-#endif
     /*
      * if an explicit return continuation is passed, set it to P1
      */

Modified: trunk/imcc/t/syn/tail.t
==============================================================================
--- trunk/imcc/t/syn/tail.t     (original)
+++ trunk/imcc/t/syn/tail.t     Tue May  3 07:23:13 2005
@@ -3,7 +3,7 @@
 # $Id$
 
 use strict;
-use Parrot::Test tests => 5;
+use Parrot::Test tests => 6;
 
 ##############################
 # Parrot Calling Conventions:  Tail call optimization.
@@ -336,14 +336,15 @@
 _fib_step returned 3 values, 23, 20, and 3.
 OUT
 
-pir_output_is(<<'CODE', <<'OUT', "new tail call syntax parsing");
+pir_output_is(<<'CODE', <<'OUT', "new tail call syntax");
 .sub main @MAIN
-    foo()
-    print "ok\n"
+    $S0 = foo()
+    print $S0
 .end
 
 .sub foo
     .return bar()
+    print "never\n"
 .end
 
 .sub bar
@@ -352,3 +353,32 @@
 CODE
 ok
 OUT
+
+pir_output_is(<<'CODE', <<'OUT', "new tail method call syntax");
+.sub main @MAIN
+    .local pmc cl, o, n
+    cl = newclass "Foo"
+    addattribute cl, "n"
+    o = new "Foo"
+    n = new Integer
+    n = 2000   # beyond recursion limit of 1000
+    setattribute o, "Foo\0n", n
+    o."go"()
+    n = getattribute o, "Foo\0n"
+    print n
+    print "\n"
+.end
+
+.namespace ["Foo"]
+.sub go method
+    .local pmc n
+    n = getattribute self, "Foo\0n"
+    dec n
+    unless n goto done
+    .return self."go"()
+done:
+.end
+
+CODE
+0
+OUT

Reply via email to