Author: pmichaud
Date: Tue Nov  1 12:22:05 2005
New Revision: 9693

Modified:
   trunk/compilers/pge/PGE/Exp.pir
   trunk/compilers/pge/PGE/Match.pir
   trunk/compilers/pge/PGE/Rule.pir
   trunk/t/p6rules/subrules.t
Log:
Fixed cut operator (:) on subrules (added test in subrules.t),
and added tailcall optimizations for subrules.


Modified: trunk/compilers/pge/PGE/Exp.pir
==============================================================================
--- trunk/compilers/pge/PGE/Exp.pir     (original)
+++ trunk/compilers/pge/PGE/Exp.pir     Tue Nov  1 12:22:05 2005
@@ -355,6 +355,8 @@ register.
     emit(code, "    cutting = 0")
     self.emitsub(code, exp0label, "NOCUT")
     emit(code, "  fail_forever:")
+    emit(code, "    null $P0")
+    emit(code, "    setattribute mob, \"PGE::Match\\x0&:corou\", $P0")
     emit(code, "    mpos = -2")
     emit(code, "    .yield (mob)")
     emit(code, "    goto fail_forever")
@@ -873,10 +875,11 @@ register.
     .local pmc emit
     .local string subname, subargs
     .local string cname, captsave, captback
-    .local int iscapture
+    .local int iscapture, iscut
     emit = find_global "PGE::Exp", "emit"
     subname = self["subname"]
     iscapture = self["iscapture"]
+    iscut = self["iscut"]
     cname = self["cname"]
     emit(code, "\n  %s:  # subrule %s    ##", label, subname)
     subargs = ""
@@ -924,8 +927,14 @@ register.
   subrule_3:
     emit(code, "    unless $P0 goto fail")
     emit(code, captsave, cname)
+    if iscut == 0 goto subrule_4
+    emit(code, "    goto %s", next)
+    goto end
+  subrule_4:
     emit(code, "  %s_sr3:", label)
     emit(code, "    pos = $P0.to()")
+    emit(code, "    $P1 = getattribute $P0, \"PGE::Match\\x0&:corou\"")
+    emit(code, "    if_null $P1, %s", next)
     self.emitsub(code, next, "$P0", "NOCUT")
     emit(code, "    $P0.next()")
     emit(code, "    if $P0 goto %s_sr3", label)

Modified: trunk/compilers/pge/PGE/Match.pir
==============================================================================
--- trunk/compilers/pge/PGE/Match.pir   (original)
+++ trunk/compilers/pge/PGE/Match.pir   Tue Nov  1 12:22:05 2005
@@ -134,9 +134,9 @@ Returns 1 if this object successfully ma
 =cut
 
 .sub "__get_bool" method
-    $P0 = getattribute self, "PGE::Match\x0$:from"
     $P1 = getattribute self, "PGE::Match\x0$:pos"
-    isge $I1, $P1, $P0    
+    $I0 = $P1
+    $I1 = isge $I0, 0
     .return ($I1)
 .end
 

Modified: trunk/compilers/pge/PGE/Rule.pir
==============================================================================
--- trunk/compilers/pge/PGE/Rule.pir    (original)
+++ trunk/compilers/pge/PGE/Rule.pir    Tue Nov  1 12:22:05 2005
@@ -405,16 +405,20 @@ Match whitespace between tokens.
     $P0 = corou
     $P0 = clone $P0
     setattribute mob, "PGE::Match\x0&:corou", $P0
-    $P0(mob, mpos)
+    $P0(mob, mfrom, mpos)
   end:
     .return (mob)
 .end
 .sub "ws_corou" :anon
     .param pmc mob
+    .param pmc mfrom
     .param pmc mpos
   loop:
     .yield (mob)
     dec mpos
+    if mpos > mfrom goto loop
+    null $P0
+    setattribute mob, "PGE::Match\x0&:corou", $P0
     goto loop
 .end
 

Modified: trunk/t/p6rules/subrules.t
==============================================================================
--- trunk/t/p6rules/subrules.t  (original)
+++ trunk/t/p6rules/subrules.t  Tue Nov  1 12:22:05 2005
@@ -1,6 +1,6 @@
 use strict;
 use warnings;
-use Parrot::Test tests => 5;
+use Parrot::Test tests => 6;
 use Parrot::Test::PGE;
 
 
@@ -50,5 +50,6 @@ p6rule_is("ab",
 #    ],
 #    "named and lexical subrules");
 
+p6rule_isnt("   ab", '^ <ws>: \ ab', "cut on subrules");
 
 # Don't forget to change the number of tests :-)

Reply via email to