Author: pmichaud
Date: Thu Jul 28 17:19:32 2005
New Revision: 8727

Modified:
   trunk/compilers/pge/PGE/Exp.pir
   trunk/compilers/pge/PGE/Match.pir
   trunk/compilers/pge/PGE/P6Rule.pir
   trunk/compilers/pge/PGE/Rule.pir
   trunk/compilers/pge/PGE/TokenHash.pir
   trunk/compilers/pge/demo.pir
Log:
Merged small bugfixes from leo-ctx5 branch.


Modified: trunk/compilers/pge/PGE/Exp.pir
==============================================================================
--- trunk/compilers/pge/PGE/Exp.pir     (original)
+++ trunk/compilers/pge/PGE/Exp.pir     Thu Jul 28 17:19:32 2005
@@ -33,14 +33,13 @@ functionality and correctness at the mom
 .include "errors.pasm"
 .include "interpinfo.pasm"
 
-.namespace [ "PGE::Exp" ]
-
 .const int PGE_INF = 2147483647                    # XXX: arbitrary limit
-.const int PGE_MATCH_FAIL = 1                      # pos of failed match
-.const int PGE_CUT_GROUP = -1                      # cutting current group
-.const int PGE_CUT_RULE = -2                       # cutting current rule
+.const int PGE_CUT_GROUP = -1                      # cut current alt/group
+.const int PGE_CUT_RULE = -2                       # cut current rule
+
+.namespace [ "PGE::Exp" ]
 
-.sub __onload 
+.sub __onload
     .local pmc hashclass
     .local pmc expclass
     .local pmc hash
@@ -71,21 +70,23 @@ functionality and correctness at the mom
     hash['\W'] = "$I0=is_wordchar target, pos \n if $I0 goto %s_f"
     $P0 = new Integer
     store_global "PGE::Exp", "$_serno", $P0
+    .return ()
 .end
 
 =head2 Functions
 
 =item C<new(STR class [, PMC exp1 [, PMC exp2]])>
 
-Creates and returns  a new C<Exp> object of C<class>, initializing 
+Creates and returns  a new C<Exp> object of C<class>, initializing
 min/max/greedy/etc.  values and C<exp1> and C<exp2> objects if provided.
 
 =cut
 
 .sub "new"
-    .param string expclass                         # class from find_type
-    .param pmc exp1                                # left expression
-    .param pmc exp2                                # right expression
+    .param string expclass     #:optional           # class from find_type
+    .param pmc exp1            #:optional           # left expression
+    .param pmc exp2            #:optional           # right expression
+    #.param int argc            :opt_count
     .local pmc me                                  # new expression object
 
     if argcS > 0 goto buildme
@@ -163,11 +164,14 @@ Typical entries in the pad include:
 =cut
 
 .sub "analyze" method
+    .param pmc next
+    .param pmc pad
     self["firstchars"] = ""
+    .return ()
 .end
 
 
-=item C<firstchars(PMC exp1, PMC exp2)>
+=item C<firstchars([PMC exp1 [, PMC exp2]])>
 
 The firstchars method sets the "firstchars" optimization hint
 based on the concatenation of the firstchars of any expressions
@@ -177,8 +181,10 @@ hint, then we have have no firstchars ei
 =cut
 
 .sub "firstchars" method
-    .param pmc exp1
-    .param pmc exp2
+    .param pmc exp1            #:optional
+    .param pmc exp2            #:optional
+    #.param int argc            :opt_count
+
     if argcP < 1 goto exp_1
     $S0 = exp1["firstchars"]
     unless $S0 > "" goto exp_1
@@ -191,114 +197,175 @@ hint, then we have have no firstchars ei
     $S0 = ""
   end:
     self["firstchars"] = $S0
+    .return ()
 .end
 
-=item C<(INT, STR) = serno(INT start, STR prefix)>
+=item C<(STR, INT) = serno([STR prefix [, INT start]])>
 
-This method simply returns integers and labels usable for 
-serialization, e.g., for generating unique labels and identifiers 
+This method simply returns integers and labels usable for
+serialization, e.g., for generating unique labels and identifiers
 within generated code.  The C<start> parameter allows the serial
 number to be set to a given value.  XXX: I'm assuming overflow
-won't be a problem, but is the use of the start parameter thread-safe?  
+won't be a problem, but is the use of the start parameter thread-safe?
 
 =cut
 
 .sub "serno" method
-    .param int start
-    .param string prefix
-    unless argcS < 1 goto serno_1
+    .param string prefix       #:optional
+    .param int start           #:optional
+    #.param int argc            :opt_count
+
+    if argcS > 0 goto serno_1
     prefix = "R"
   serno_1:
     $P0 = find_global "PGE::Exp", "$_serno"
     inc $P0
-    unless argcI > 0 goto serno_2
+    if argcI < 1 goto serno_2
     $P0 = start
   serno_2:
     $I0 = $P0
     $S0 = $I0
     concat prefix, $S0
-    .return ($I0, prefix)
+    .return (prefix, $I0)
 .end
 
 
-=item C<emit(PMC code, STR fmt, STR str1, STR str2, INT int1)>
+=item C<emit(PMC code, STR fmt [, STR str1 [, STR str2]])>
 
-Adds to the current code string, replacing %s by str1/str2 and %d
-by int1 as needed.
+Adds to the current code string, replacing %s by str1/str2.
 
 =cut
 
 .sub "emit" method
-    .param pmc code
-    .param string out
-    .param string str1
-    .param string str2
-    .param int int1
-    concat out, "\n"
-    $I0 = index out, "%s"
-    if $I0 < 1 goto emit_1
-    substr out, $I0, 2, str1
-    $I0 = index out, "%s"
-    if $I0 < 1 goto emit_1
-    substr out, $I0, 2, str2
+    .param pmc code                                # append to code
+    .param string fmt                              # string to output
+    .param string str1         #:optional           # first %s substitution
+    .param string str2         #:optional           # second %s substitution
+    .param string str3         #:optional           # third %s substitution
+    .param int int1                                # first %d substitution
+
+    concat fmt, "\n"
+    $I0 = index fmt, "%s"
+    if $I0 < 0 goto emit_1
+    substr fmt, $I0, 2, str1
+    $I0 = index fmt, "%s"
+    if $I0 < 0 goto emit_1
+    substr fmt, $I0, 2, str2
+    $I0 = index fmt, "%s"
+    if $I0 < 0 goto emit_1
+    substr fmt, $I0, 2, str3
   emit_1:
-    $I0 = index out, "%d"
-    if $I0 < 1 goto emit_2
+    $I0 = index fmt, "%d"
+    if $I0 < 0 goto emit_2
     $S0 = int1
-    substr out, $I0, 2, $S0
+    substr fmt, $I0, 2, $S0
   emit_2:
-    concat code, out
+    concat code, fmt
+    .return ()
 .end
 
-=item C<emitsub(PMC code, STR next, STR str1, STR str2, STR str3, STR str4)>
+=item C<emitsub(PMC code, STR next, [STR save [, ...]])
 
 Generate a subroutine call to C<next>, preserving and restoring
-the values of C<str1> through C<str4> in the process.
+any save parameters in the process.  The special parameter "NOCUT"
+says not to intercept cutting operations.
 
 =cut
 
-.sub "emitsub" method
-    .param pmc code
-    .param string next
-    .param string str1
-    .param string str2
-    .param string str3
-    .param string str4
-    .param int docut
-    .local pmc emit
+.sub "emitsub-newcc" method
+    .param pmc code                                # append to code
+    .param string next                             # sub label
+    .param pmc save         #:slurpy                # registers to save
+    .local int nocut                               # flag for "NOCUT"
+    .local pmc emit                                # emit subroutine
+    .local int savec                               # number of save items
 
-    unless argcI < 1 goto emitsub_0
-    docut = 1
+    emit = find_global "PGE::Exp", "emit"
+    nocut = 0
+    savec = elements save
+    $I0 = 0
+  saveregs_0:
+    if $I0 >= savec goto emitsub_0
+    $S0 = save[$I0]
+    inc $I0
+    if $S0 == "NOCUT" goto set_nocut
+    emit(code, "    save %s", $S0)
+    goto saveregs_0
+  set_nocut:
+    nocut = 1
+    goto saveregs_0
   emitsub_0:
+    emit(code, "    bsr %s", next)
+    $I0 = savec - 1
+  restoreregs_0:
+    if $I0 < 0 goto generate_cut
+    $S0 = save[$I0]
+    dec $I0
+    if $S0 == "NOCUT" goto restoreregs_0
+    emit(code, "    restore %s", $S0)
+    goto restoreregs_0
+  generate_cut:
+    if nocut goto end
+    emit(code, "    if cutting != 0 goto fail")
+  end:
+    .return ()
+.end
+
+.sub "emitsub" method    # old calling conventions
+    .param pmc code                                # append to code
+    .param string next                             # sub label
+    .param string save2                            # string 1
+    .param string save3                            # string 2
+    .param string save4                            # string 3
+    .param string save5                            # string 4
+    .local int nocut                               # flag for "NOCUT"
+    .local pmc emit                                # emit subroutine
+    .local int argc
+
+    argc = argcS
+
     emit = find_global "PGE::Exp", "emit"
-    $I0 = argcS
-    if $I0 < 2 goto emitsub_1
-    emit(code, "    save %s", str1)
-    if $I0 < 3 goto emitsub_1
-    emit(code, "    save %s", str2)
-    if $I0 < 4 goto emitsub_1
-    emit(code, "    save %s", str3)
-    if $I0 < 5 goto emitsub_1
-    emit(code, "    save %s", str4)
-  emitsub_1:
+    nocut = 0
+    if argc < 2 goto emitsub_0
+    if save2 == "NOCUT" goto set_nocut
+    emit(code, "    save %s", save2)
+    if argc < 3 goto emitsub_0
+    if save3 == "NOCUT" goto set_nocut
+    emit(code, "    save %s", save3)
+    if argc < 4 goto emitsub_0
+    if save4 == "NOCUT" goto set_nocut
+    emit(code, "    save %s", save4)
+    if argc < 5 goto emitsub_0
+    if save5 == "NOCUT" goto set_nocut
+    emit(code, "    save %s", save5)
+    goto emitsub_0
+  set_nocut:
+    nocut = 1
+  emitsub_0:
     emit(code, "    bsr %s", next)
-    if $I0 < 5 goto emitsub_5
-    emit(code, "    restore %s", str4)
-  emitsub_5:
-    if $I0 < 4 goto emitsub_4
-    emit(code, "    restore %s", str3)
-  emitsub_4:
-    if $I0 < 3 goto emitsub_3
-    emit(code, "    restore %s", str2)
-  emitsub_3:
-    if $I0 < 2 goto emitsub_2
-    emit(code, "    restore %s", str1)
-  emitsub_2:
-    unless docut goto end
+    if argc < 5 goto res4
+    if save5 == "NOCUT" goto res4
+    emit(code, "    restore %s", save5)
+  res4:
+    if argc < 4 goto res3
+    if save4 == "NOCUT" goto res3
+    emit(code, "    restore %s", save4)
+  res3:
+    if argc < 3 goto res2
+    if save3 == "NOCUT" goto res2
+    emit(code, "    restore %s", save3)
+  res2:
+    if argc < 2 goto generate_cut
+    if save2 == "NOCUT" goto generate_cut
+    emit(code, "    restore %s", save2)
+  generate_cut:
+    if nocut goto end
     emit(code, "    if cutting != 0 goto fail")
   end:
+    .return ()
 .end
 
+
 =item C<genliteral(PMC code, STR label, STR next)>
 
 Generate code to match literal strings, quantified as necessary.
@@ -309,7 +376,7 @@ literal to be matched has already been p
 register.
 
 =cut
-    
+
 .sub "genliteral" method
     .param pmc code
     .param string label
@@ -346,7 +413,7 @@ register.
     emit(code, "    dec rep")
     emit(code, "    pos -= litlen")
     emit(code, "    goto %s_lit2", label)
-    .return()
+    .return ()
 
   lazy:
     emit(code, "  %s_lit1:", label)
@@ -364,6 +431,7 @@ register.
     emit(code, "    inc rep")
     emit(code, "    pos += litlen")
     emit(code, "    goto %s_lit1", label)
+    .return ()
 .end
 
 .namespace [ "PGE::Exp::Start" ]
@@ -375,6 +443,7 @@ register.
     $P0 = self["exp1"]
     $P0.analyze(self, pad)                         # analyze our subexp
     self.firstchars($P0)                           # set firstchars
+    .return ()
 .end
 
 .sub "gen" method
@@ -387,24 +456,36 @@ register.
 
     emit = find_global "PGE::Exp", "emit"
     emit(code, ".sub _pge_rule")
-    emit(code, "    .param string target")
+    emit(code, "    .param pmc pmc1")
+    emit(code, "    .param string str1")                
     emit(code, "    .param int pos")
-    emit(code, "    .param pmc mob")
+    emit(code, "    .local pmc mob")
     emit(code, "    .local pmc yield")
-    emit(code, "    if argcP > 0 goto start_match")
+    emit(code, "    if argcP < 1 goto new_match")
+    emit(code, "    $I0 = isa pmc1, \"PGE::Match\"")
+    emit(code, "    unless $I0 goto new_match")
+    emit(code, "    mob = pmc1")
+    emit(code, "    goto init_pos")
     emit(code, "  new_match:")
     emit(code, "    $I0 = find_type \"PGE::Rule\"")
     emit(code, "    mob = new $I0")
     emit(code, "    $P0 = new String")
-    emit(code, "    $P0 = target")
+    emit(code, "    if argcP > 0 goto from_pmc")
+    emit(code, "    assign $P0, str1")
+    emit(code, "    goto init_match")
+    emit(code, "  from_pmc:")
+    emit(code, "    assign $P0, pmc1")
+    emit(code, "  init_match:")
     emit(code, "    setattribute mob, \"PGE::Match\\x0$:target\", $P0")
     emit(code, "    $P0 = new PerlInt")
     emit(code, "    setattribute mob, \"PGE::Match\\x0$:from\", $P0")
     emit(code, "    $P0 = new PerlInt")
     emit(code, "    $P0 = -1")
     emit(code, "    setattribute mob, \"PGE::Match\\x0$:pos\", $P0")
-    emit(code, "    unless argcI < 1 goto rule_2")
-    emit(code, "    pos = -1")
+    emit(code, "  init_pos:")
+    emit(code, "    if argcI > 0 goto start_match")
+    emit(code, "    $P0 = getattribute mob, \"PGE::Match\\x0$:pos\"")
+    emit(code, "    pos = $P0")
     emit(code, "  start_match:")
     emit(code, "    newsub yield, .Coroutine, _pge_rule_coroutine")
     emit(code, "    setattribute mob, \"PGE::Match\\x0&:yield\", yield")
@@ -450,15 +531,16 @@ register.
     emit(code, "    if $I0 < 0 goto try_again")
   gen_1:
     emit(code, "    from = pos")
-    self.emitsub(code, label, "pos", "from", "lastpos", 0)
-    emit(code, "    if cutting == %d goto fail_forever", PGE_CUT_RULE)
+    self.emitsub(code, label, "pos", "from", "lastpos", "NOCUT")
+    #emit(code, "    if cutting == %d goto fail_forever", PGE_CUT_RULE)
+    emit(code, "    if cutting == %d goto fail_forever", -2)  # XXX
     emit(code, "  try_again:")
     emit(code, "    inc pos")
     emit(code, "    goto try_match")
     emit(code, "  try_at_pos:")
     emit(code, "    cutting = 0")
     emit(code, "    from = pos")
-    self.emitsub(code, label, 0)
+    self.emitsub(code, label, "NOCUT")
     emit(code, "  fail_forever:")
     emit(code, "    .yield(-2)")
     emit(code, "    goto fail_forever")
@@ -467,6 +549,7 @@ register.
     exp1.gen(code, label, next)
 
     emit(code, ".end")
+    .return ()
 .end
 
 .namespace [ "PGE::Exp::End" ]
@@ -484,8 +567,9 @@ register.
     emit(code, "    $P0 = -1")
     emit(code, "  fail:")
     emit(code, "    ret")
+    .return ()
 .end
-    
+
 .namespace [ "PGE::Exp::Literal" ]
 
 .sub "analyze" method
@@ -498,6 +582,7 @@ register.
     unless $I0 < 1 goto end                        # then add firstchars
     self.firstchars(self, next)                    # of the following exp
   end:
+    .return ()
 .end
 
 .sub "gen" method
@@ -513,6 +598,7 @@ register.
     emit(code, "\n  %s:  # literal %s", label, $S0)
     emit(code, "    lit = \"%s\"", $S1)
     self.genliteral(code, label, next)
+    .return ()
 .end
 
 
@@ -595,7 +681,7 @@ register.
     emit(code, "    dec rep")
     emit(code, "    dec pos")
     emit(code, "    goto %s_2", label)
-    .return()
+    .return ()
   lazy:
     emit(code, "    rep = %d", min)
     emit(code, "    pos += rep", min)
@@ -603,13 +689,14 @@ register.
     emit(code, "    if rep > maxrep goto fail")
     unless iscut goto lazy_1
     emit(code, "    goto %s", next)
-    .return()
+    .return ()
   lazy_1:
     emit(code, "    if rep == maxrep goto %s", next)
     self.emitsub(code, next, "pos", "rep", "maxrep")
     emit(code, "    inc rep")
     emit(code, "    inc pos")
     emit(code, "    goto %s_3", label)
+    .return ()
 .end
 
 .namespace [ "PGE::Exp::CCShortcut" ]
@@ -668,6 +755,7 @@ register.
     emit(code, "    goto %s_0", label)
     emit(code, "  %s_f:", label)
     emit(code, "    goto fail")
+    .return ()
 .end
 
 .namespace [ "PGE::Exp::CharClass" ]
@@ -731,7 +819,8 @@ register.
     emit(code, "    %s $I0 == -1 goto fail", charmatch)
     emit(code, "    inc rep")
     emit(code, "    inc pos")
-    emit(code, "    goto %s_0", label) 
+    emit(code, "    goto %s_0", label)
+    .return ()
 .end
 
 .namespace [ "PGE::Exp::WS" ]
@@ -748,6 +837,7 @@ register.
     unless $I0 == $I1 goto end
     self["iscut"] = 1
   end:
+    .return ()
 .end
 
 .sub "gen" method
@@ -781,6 +871,7 @@ register.
     emit(code, "    dec pos")
     emit(code, "    goto %s_2", label)
   end:
+    .return ()
 .end
 
 
@@ -790,6 +881,7 @@ register.
     .param pmc next
     .param pmc pad
     self.firstchars(next)
+    .return ()
 .end
 
 .sub "gen" method
@@ -834,6 +926,7 @@ register.
     emit(code, "    if $I0 == $I1 goto %s", next)
   end:
     emit(code, "    goto fail")
+    .return ()
 .end
 
 
@@ -848,8 +941,9 @@ register.
     exp1 = self["exp1"]
     exp1.analyze(exp2, pad)
     self.firstchars(exp1)
+    .return ()
 .end
-   
+
 .sub "gen" method
     .param pmc code
     .param string label
@@ -858,12 +952,13 @@ register.
     .local pmc exp1, exp2
     emit = find_global "PGE::Exp", "emit"
     emit(code, "\n  %s:", label)
-    $S0 = self.serno()
-    $S1 = self.serno()
+    ($S0, $I0) = self.serno()
+    ($S1, $I1) = self.serno()
     exp1 = self["exp1"]
     exp1.gen(code, $S0, $S1)
     exp2 = self["exp2"]
     exp2.gen(code, $S1, next)
+    .return ()
 .end
 
 .namespace [ "PGE::Exp::Cut" ]
@@ -872,6 +967,7 @@ register.
     .param pmc next
     .param int pad
     self.firstchars(next)
+    .return ()
 .end
 
 .sub "gen" method
@@ -888,9 +984,10 @@ register.
   cut_1:
     emit = find_global "PGE::Exp", "emit"
     emit(code, "\n  %s:", label)
-    self.emitsub(code, next, 0)
+    self.emitsub(code, next, "NOCUT")
     emit(code, "    cutting = %s", cutting)
     emit(code, "    goto fail")
+    .return ()
 .end
 
 .namespace [ "PGE::Exp::Alt" ]
@@ -914,6 +1011,7 @@ register.
     pad["creps"] = creps
     exp1.analyze(next, pad)
     self.firstchars(exp1, exp2)
+    .return ()
 .end
 
 .sub "gen" method
@@ -923,17 +1021,18 @@ register.
     .local pmc emit
     .local pmc exp1, exp2
     emit = find_global "PGE::Exp", "emit"
-    emit(code, "\n  %s:", label)
-    $S0 = self.serno()
-    $S1 = self.serno()
+    emit(code, "\n  %s:  # alt", label)
+    ($S0, $I0) = self.serno()
+    ($S1, $I1) = self.serno()
     self.emitsub(code, $S0, "pos")
     emit(code, "    goto %s", $S1)
     exp1 = self["exp1"]
     exp1.gen(code, $S0, next)
     exp2 = self["exp2"]
     exp2.gen(code, $S1, next)
+    .return ()
 .end
-    
+
 
 .namespace [ "PGE::Exp::Group" ]
 
@@ -963,7 +1062,7 @@ register.
   creps_2:
     $I0 = exists creps[cname]                      # have seen capture name?
     unless $I0 goto creps_3                        #
-    $P0 = creps[cname]                             # yes, so prev is now 
+    $P0 = creps[cname]                             # yes, so prev is now
     $P0["isarray"] = 1                             # an array capture
     self["isarray"] = 1                            # and so is self
   creps_3:
@@ -972,7 +1071,7 @@ register.
   isarray_0:
     psave = pad["isarray"]                         # get current isarray status
     isarray = self["isarray"]                      # combine with group's
-    isarray |= psave                               # 
+    isarray |= psave                               #
     self["isarray"] = isarray                      # and pass to nested
     pad["isarray"] = isarray
     $I0 = self["cscope"]                           # new scope resets
@@ -996,8 +1095,9 @@ register.
     self.firstchars(exp1)
   end:
     pad["creps"] = creps
+    .return ()
 .end
- 
+
 .sub "gen" method
     .param pmc code
     .param string label
@@ -1011,7 +1111,7 @@ register.
     .local int myserno
     emit = find_global "PGE::Exp", "emit"
     (min, max, isgreedy, iscut) = self."_getattributes"()
-    (myserno, sublabel) = self.serno()
+    (sublabel, myserno) = self.serno()
     iscapture = defined self["cname"]
     isarray = self["isarray"]
     rname = self["rname"]
@@ -1104,7 +1204,7 @@ register.
     emit(code, "    $I0 = pop gpad")
     emit(code, "    $P0 = pop gpad")
     emit(code, "    $P0 = pop cpad")
-    self.emitsub(code, next, "capt", "rep", "$P0", 0)
+    self.emitsub(code, next, "capt", "rep", "$P0", "NOCUT")
     emit(code, "    push cpad, $P0")
     emit(code, "    push gpad, capt")
     emit(code, "    push gpad, rep")
@@ -1120,7 +1220,7 @@ register.
     emit(code, "    $I0 = pop gpad")
     emit(code, "    $P0 = pop gpad")
     emit(code, "    $P0 = pop cpad")
-    self.emitsub(code, next, "capt", "rep", "pos", "$P0", 0)
+    self.emitsub(code, next, "capt", "rep", "pos", "$P0", "NOCUT")
     emit(code, "    push cpad, $P0")
     emit(code, "    push gpad, capt")
     emit(code, "    push gpad, rep")
@@ -1203,7 +1303,7 @@ register.
     emit(code, "    push capt, $P0")
   subrule_3:
     emit(code, "  %s_s2:", label)
-    self.emitsub(code, label, "pos", "$P0", 0)
+    self.emitsub(code, label, "pos", "$P0", "NOCUT")
     emit(code, "    unless cutting == 0 goto %s_s3", label)
     emit(code, "    saveall")
     emit(code, "    $P0.next()")
@@ -1219,8 +1319,9 @@ register.
     emit(code, "  %s_s4:", label)
     emit(code, "    ret")
   end:
+    .return ()
 .end
-   
+
 =head1 AUTHOR
 
 Patrick Michaud ([EMAIL PROTECTED]) is the author and maintainer.
@@ -1228,4 +1329,4 @@ Patches and suggestions should be sent t
 ([email protected]).
 
 =cut
- 
+

Modified: trunk/compilers/pge/PGE/Match.pir
==============================================================================
--- trunk/compilers/pge/PGE/Match.pir   (original)
+++ trunk/compilers/pge/PGE/Match.pir   Thu Jul 28 17:19:32 2005
@@ -10,7 +10,7 @@ This file implements match objects retur
 
 .namespace [ "PGE::Match" ]
 
-.sub "__onload" 
+.sub "__onload"
     .local pmc base
     newclass base, "PGE::Match"
     addattribute base, "$:target"                  # target
@@ -19,6 +19,7 @@ This file implements match objects retur
     addattribute base, "&:yield"                   # match's yield
     addattribute base, "@:capt"                    # subpattern captures
     addattribute base, "%:capt"                    # subpattern captures
+    .return ()
 .end
 
 =head2 Methods
@@ -48,12 +49,12 @@ C<pos>.
     setattribute me, "PGE::Match\x0$:pos", $P0
     .return (me)
 .end
-    
+
 =head2 Methods
 
 =item C<next()>
 
-Tell a Match object to continue the previous match from where 
+Tell a Match object to continue the previous match from where
 it left off.
 
 =cut
@@ -73,6 +74,7 @@ it left off.
     .pcc_call yield
     .pcc_end
   end:
+    .return ()
 .end
 
 =item C<from()>
@@ -163,10 +165,10 @@ Returns the portion of the target string
 
 =item C<__get_pmc_keyed(PMC key)>
 
-Returns the subpattern or subrule capture associated with C<key>.  
+Returns the subpattern or subrule capture associated with C<key>.
 If the first character of C<key> is a digit then return the
-subpattern, otherwise return the subrule.  Note that this will 
-return either a single Match object or an array of match objects 
+subpattern, otherwise return the subrule.  Note that this will
+return either a single Match object or an array of match objects
 depending on the rule.
 
 =cut
@@ -219,18 +221,20 @@ Returns the array component of the match
 Produces a data dump of the match object and all of its subcaptures.
 
 =cut
-   
+
 .sub "dump" method
-    .param string prefix
-    .param string b1
-    .param string b2
+    .param string prefix       #:optional           # name of match variable
+    .param string b1           #:optional           # bracket open
+    .param string b2           #:optional           # bracket close
+    #.param int argc            :opt_count
     .local pmc capt
     .local int spi, spc
     .local pmc iter
     .local string prefix1, prefix2
-    unless argcS < 3 goto start
+
+    if argcS > 2 goto start
     b2 = "]"
-    unless argcS < 2 goto start
+    if argcS > 1 goto start
     b1 = "["
   start:
     print prefix
@@ -303,6 +307,7 @@ Produces a data dump of the match object
     inc $I0
     goto dumper_2
   end:
+    .return ()
 .end
 
 =head1 AUTHOR

Modified: trunk/compilers/pge/PGE/P6Rule.pir
==============================================================================
--- trunk/compilers/pge/PGE/P6Rule.pir  (original)
+++ trunk/compilers/pge/PGE/P6Rule.pir  Thu Jul 28 17:19:32 2005
@@ -7,7 +7,7 @@ PGE::P6Rule - Parse and compile Perl 6 r
 This file implements the Perl 6 rules compiler -- it parses strings
 using Perl 6 rules syntax into a rule expression tree (see L<PGE::Exp>),
 generates the PIR code from the expression tree, and compiles the
-PIR code into a subroutine object.  
+PIR code into a subroutine object.
 
 The parser here is implemented as a hybrid top-down parser, with a
 token lookup table for individual pattern terms.  This parser is
@@ -20,7 +20,7 @@ will be to use Perl 6 to write and compi
 
 .namespace [ "PGE::P6Rule" ]
 
-.const int PGE_INF    = 2147483647                # XXX: arbitrary limit
+.const int PGE_INF = 2147483647                # XXX: arbitrary limit
 
 .sub "__onload"
     .local pmc p6meta
@@ -68,7 +68,7 @@ will be to use Perl 6 to write and compi
     p6meta['$7'] = $P0
     p6meta['$8'] = $P0
     p6meta['$9'] = $P0
-    $P0 = find_global "PGE::P6Rule", "p6rule_parse_subrule" 
+    $P0 = find_global "PGE::P6Rule", "p6rule_parse_subrule"
     p6meta['<'] = $P0
     p6meta['<?'] = $P0
     p6meta['>'] = u
@@ -85,12 +85,13 @@ will be to use Perl 6 to write and compi
     p6meta['<['] = $P0
     p6meta['<-['] = $P0
     p6meta['<+['] = $P0
+    .return ()
 .end
 
 =item C<p6rule_parse_skip(STR pattern, PMC lex, INT skip)>
 
-Advance the lexical context over the next C<skip> characters and 
-scan until the next token is found in C<pattern>.  
+Advance the lexical context over the next C<skip> characters and
+scan until the next token is found in C<pattern>.
 
 =cut
 
@@ -103,14 +104,14 @@ scan until the next token is found in C<
 
     plen = lex["plen"]
     pos = lex["pos"]
-    pos += skip                      
+    pos += skip
     lex["ws"] = 0
     unless pos < plen goto end
     $I0 = is_whitespace pattern, pos
     lex["ws"] = $I0
   skipws:
     unless pos < plen goto end
-    $I0 = is_whitespace pattern, pos 
+    $I0 = is_whitespace pattern, pos
     unless $I0 goto skipcomments
     inc pos
     goto skipws
@@ -165,7 +166,7 @@ the C<lex["pos"]> pointer as it goes.
     lex["pos"] = pos
     .return (val)
 .end
-    
+
 =item C<p6rule_parse_error(STR pattern, PMC lex, STR message)>
 
 Generates error messages during parsing.  Gracefully recovering
@@ -192,6 +193,7 @@ from errors in rule expressions still ne
     $S0 .= ">>)\n"
     $P0["_message"] = $S0
     throw $P0
+    .return ()
 .end
 
 =item C<p6rule_parse_literal(STR pattern, PMC lex)>
@@ -259,7 +261,7 @@ Parse a dot (.) token and return a C<PGE
 
 =item C<p6rule_parse_anchor(STR pattern, PMC lex)>
 
-Parse one of the ^, ^^, $, or $$ anchors and return a 
+Parse one of the ^, ^^, $, or $$ anchors and return a
 C<PGE::Exp::Anchor> object for it.  Note that $ will be
 a little tricky here, because it can also be used to represent
 backreferences or variables.
@@ -311,7 +313,7 @@ subcaptures.
     delete lex["cname"]                            # and then remove it
   group_1:
     subp = lex["subp"]                             # current subpattern count
-    unless token == '(' goto group_2               
+    unless token == '(' goto group_2
     exp["cscope"] = 1                              # '(' == scoped capture
     lex["subp"] = 0                                # restart subpattern #'s
     if isaliased goto group_2                      # if not aliased
@@ -328,7 +330,7 @@ subcaptures.
     p6rule_parse_error(pattern, lex, "group missing ')'")
     goto end
   group_3:                                         # unscoped capture
-    if $S0 == ']' goto group_4                     
+    if $S0 == ']' goto group_4
     p6rule_parse_error(pattern, lex, "group missing ']'")
     goto end
   group_4:
@@ -354,7 +356,7 @@ Parses subrules.
     pos = lex["pos"]
     $I0 = pos
   subrule_1:
-    $I1 = is_wordchar pattern, pos 
+    $I1 = is_wordchar pattern, pos
     unless $I1 goto subrule_1b
   subrule_1_inc:
     inc pos
@@ -414,7 +416,7 @@ Parse an alias or backreference.
     $I0 = pos                                      # aha, numeric capture
     plen = lex["plen"]                             # now let's scan for digits
   num_0:
-    if $I0 >= plen goto num_1            
+    if $I0 >= plen goto num_1
     $I1 = is_digit pattern, $I0
     unless $I1 goto num_1
     inc $I0
@@ -426,7 +428,7 @@ Parse an alias or backreference.
     subp = $S0                                     # convert to integer
     lex["cname"] = subp                            # this capture
     inc subp                                       # store next subpattern #
-    lex["subp"] = subp                             # 
+    lex["subp"] = subp                             #
     p6rule_parse_skip(pattern, lex, 0)             # skip ws
     goto alias
   name:
@@ -438,7 +440,7 @@ Parse an alias or backreference.
   alias:
     pos = lex["pos"]                               # get current pos
     $S0 = substr pattern, pos, 2                   # check for ':='
-    unless $S0 == ':=' goto backref                
+    unless $S0 == ':=' goto backref
     p6rule_parse_skip(pattern, lex, 2)             # skip ':='
     exp = p6rule_parse_term(pattern, lex)          # parse a term to capture
     goto end
@@ -587,7 +589,7 @@ handled as a special quantifier.
 Parse a single term in a rule expression, such as a literal,
 anchor, assertion, backslash sequence, etc.  We use a TokenHash
 here as a lookup table to find the longest sequence of matching
-characters.  
+characters.
 
 =cut
 
@@ -612,7 +614,7 @@ characters.  
 =item C<p6rule_parse_quant(STR pattern, PMC lex)>
 
 Parse a quantified term expressions, as well as the C<:> backtracking
-control.  Currently does not handle **{m..n} quantifiers, but that 
+control.  Currently does not handle **{m..n} quantifiers, but that
 will be coming soon.
 
 =cut
@@ -634,13 +636,13 @@ will be coming soon.
     if $I0 < 0 goto end
     $I0 = isa exp, "PGE::Exp::Literal"             # break multichar literals
     unless $I0 goto quant                          # not a literal
-    $S0 = exp["literal"]                           
-    $I0 = length $S0                          
+    $S0 = exp["literal"]
+    $I0 = length $S0
     unless $I0 > 1 goto quant                      # not multichar
     $S1 = substr $S0, -1, 1                        # split off last char
     chopn $S0, 1                                   # else split off last char
     exp["literal"] = $S0                           # save shorter literal
-    $P1 = find_global "PGE::Exp", "new"            
+    $P1 = find_global "PGE::Exp", "new"
     qexp = $P1("PGE::Exp::Literal")                # create quantified literal
     qexp["literal"] = $S1
     exp = $P1("PGE::Exp::Concat", exp, qexp)       # and concat
@@ -754,7 +756,7 @@ terminate the expression.
     (exp) = $P0("PGE::Exp::WS")
     lex["ws"] = 0
     goto concat_2
-  concat_1:  
+  concat_1:
     (exp) = "p6rule_parse_quant"(pattern, lex)
     unless words goto concat_2
     $I0 = lex["ws"]
@@ -805,7 +807,7 @@ to adjust the subpattern counts here.
   end:
     .return (exp)
 .end
-   
+
 =item C<p6rule_parse_exp(STR pattern, PMC lex)>
 
 Parse a complete rule expression and return its expression object.
@@ -846,7 +848,7 @@ C<p6rule_parse_group> above.
     .return (exp)
 .end
 
-=item C<(PMC rule, PMC code, PMC expr) = p6rule(STR pattern, STR gmr, STR 
name)>
+=item C<(rule, code, expr) = p6rule(STR pattern [, STR gmr, STR name])>
 
 Compile C<pattern> containing a Perl 6 rule expression into
 a subroutine that can match that expression, returned as C<rule>.
@@ -862,19 +864,17 @@ needed).
 .namespace [ "PGE" ]
 
 .sub "p6rule"
-    .param string pattern
-    .param string grammar
-    .param string name
+    .param string pattern                          # pattern to compile
+    .param string grammar      #:optional           # grammar to store in
+    .param string name         #:optional           # name of rule
+    #.param int    opt_argc     :opt_count
+    .local int argc
     .local pmc lex
     .local pmc exp
     .local pmc code
     .local pmc rule
-    .local int install
 
-    install = 0
-    if argcS < 3 goto p6rule_1
-    install = 1
-  p6rule_1:
+    argc = argcS
     lex = new Hash
     lex["pos"] = 0
     lex["subp"] = 0
@@ -895,10 +895,10 @@ needed).
 
     code = new String
     exp.gen(code, "R", "fail")
-    compreg $P0, "PIR"
+    $P0 = compreg "PIR"
     $S0 = code
-    rule = compile $P0, $S0
-    unless install goto p6rule_3
+    rule = compile $P0, $S0 
+    if argc < 3 goto p6rule_3
     $I0 = findclass grammar
     if $I0 goto p6rule_2
     $P0 = getclass "PGE::Rule"

Modified: trunk/compilers/pge/PGE/Rule.pir
==============================================================================
--- trunk/compilers/pge/PGE/Rule.pir    (original)
+++ trunk/compilers/pge/PGE/Rule.pir    Thu Jul 28 17:19:32 2005
@@ -21,6 +21,7 @@ a number of built-in rules.
     p6rule = find_global "PGE", "p6rule"
     p6rule("[_ | <?alpha>] \w*", "PGE::Rule", "ident")
     p6rule("<ident> [ \: \: <ident> ]*", "PGE::Rule", "name")
+    .return ()
 .end
 
 =head2 Built-in rules

Modified: trunk/compilers/pge/PGE/TokenHash.pir
==============================================================================
--- trunk/compilers/pge/PGE/TokenHash.pir       (original)
+++ trunk/compilers/pge/PGE/TokenHash.pir       Thu Jul 28 17:19:32 2005
@@ -11,6 +11,7 @@ PGE::TokenHash - hash implementation to 
     class = newclass "PGE::TokenHash"
     addattribute class, ".ihash"
     addattribute class, ".vhash"
+    .return ()
 .end
 
 .sub "__init" method
@@ -19,6 +20,7 @@ PGE::TokenHash - hash implementation to 
     vhash = new Hash
     setattribute self, "PGE::TokenHash\x0.ihash", ihash
     setattribute self, "PGE::TokenHash\x0.vhash", vhash
+    .return ()
 .end
 
 .sub "__get_pmc_keyed" method
@@ -48,6 +50,7 @@ PGE::TokenHash - hash implementation to 
     if $I0 >= len goto end
     ihash[c] = len
   end:
+    .return ()
 .end
 
 .sub "__exists_keyed" method

Modified: trunk/compilers/pge/demo.pir
==============================================================================
--- trunk/compilers/pge/demo.pir        (original)
+++ trunk/compilers/pge/demo.pir        Thu Jul 28 17:19:32 2005
@@ -23,7 +23,6 @@
 
     gparse = p6rule_compile(":w ( (grammar) <ident> ; | (rule) <ident> 
\{$<rulex>:=[<-[{]>*]\} )*")
 
-
   read_loop:
     print "\ninput \"rule <pattern>\", \"glob <pattern>\", \"save <name>\",\n"
     print "target string, \"pir\", \"exp\", \"trace\", \"next\", or \"use 
<file>\"\n"

Reply via email to