[svn:parrot] r47572 - in branches/gsoc_past_optimization/runtime/parrot/library/PAST: . Pattern

tcurtis at svn.parrot.org tcurtis at svn.parrot.org
Sat Jun 12 19:27:31 UTC 2010


Author: tcurtis
Date: Sat Jun 12 19:27:31 2010
New Revision: 47572
URL: https://trac.parrot.org/parrot/changeset/47572

Log:
Move option handling and :g logic of .ACCEPTS into PAST::Pattern.

Modified:
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern.nqp
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Closure.nqp
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Constant.nqp
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Node.nqp

Modified: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern.nqp
==============================================================================
--- branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern.nqp	Sat Jun 12 19:07:25 2010	(r47571)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern.nqp	Sat Jun 12 19:27:31 2010	(r47572)
@@ -41,6 +41,61 @@
           PAST::Pattern::Transformer.new(self, &transSub);
         $transformer.walk($past);
     }
+
+    method ACCEPTS ($node, *%opts) {
+        my $global := ?%opts<g> || ?%opts<global>;
+        return self.ACCEPTSGLOBALLY($node) if $global;
+        my $pos := %opts<p> || %opts<pos>;
+        return self.ACCEPTSEXACTLY($pos) if $pos;
+        my $/ := self.ACCEPTSEXACTLY($node);
+        if (!$/ && ($node ~~ PAST::Node)) {
+            my $index := 0;
+            my $max := pir::elements__IP($node);
+            until ($index == $max) {
+                $/ := $node[$index] ~~ self;
+                return $/ if $/;
+                $index++;
+            }
+            $/ := PAST::Pattern::Match.new(0);
+        }
+        $/;
+    }
+
+    method ACCEPTSGLOBALLY ($node) {
+        my $/;
+        my $first := self.ACCEPTSEXACTLY($node);
+        if ($node ~~ PAST::Node) {
+            my $matches := ?$first;
+            my $index := 0;
+            my $max := pir::elements__IP($node);
+            my $submatch;
+            $/ := PAST::Pattern::Match.new(?$first);
+            $/[0] := $first if $first;
+            until ($index == $max) {
+                $submatch := self.ACCEPTS($node[$index], :g);
+                if ($submatch) {
+                    $/.success(1) unless $matches;
+                    if pir::defined__iP($submatch.from()) {
+                        $/[$matches++] := $submatch;
+                    }
+                    else { # The submatch is a list of multiple matches.
+                        my $subIndex := 0;
+                        my $subMax := pir::elements__IP($submatch);
+                        until ($subIndex == $subMax) {
+                            $/[$matches++] := $submatch[$subIndex];
+                            $subIndex++;
+                        }
+                    }
+                }
+                $index++;
+            }
+            $/ := $/[0] if $matches == 1;
+        }
+        else {
+            $/ := $first;
+        }
+        $/;
+    }
 }
 
 

Modified: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Closure.nqp
==============================================================================
--- branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Closure.nqp	Sat Jun 12 19:07:25 2010	(r47571)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Closure.nqp	Sat Jun 12 19:27:31 2010	(r47572)
@@ -18,7 +18,7 @@
         self.attr("code", &code, pir::defined__IP(&code));
     }
 
-    method ACCEPTS ($node, *%opts) {
+    method ACCEPTSEXACTLY ($node) {
         PAST::Pattern::Match.new(self.code()($node),
                                  $node);
     }

Modified: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Constant.nqp
==============================================================================
--- branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Constant.nqp	Sat Jun 12 19:07:25 2010	(r47571)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Constant.nqp	Sat Jun 12 19:27:31 2010	(r47572)
@@ -17,7 +17,7 @@
         self.attr("value", $value, pir::defined__IP($value));
     }
 
-    method ACCEPTS ($node, *%opts) {
+    method ACCEPTSEXACTLY ($node) {
         PAST::Pattern::Match.new(pir::iseq__IPP(self.value(), $node),
                                  $node);
     }

Modified: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Node.nqp
==============================================================================
--- branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Node.nqp	Sat Jun 12 19:07:25 2010	(r47571)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Node.nqp	Sat Jun 12 19:27:31 2010	(r47572)
@@ -124,61 +124,6 @@
          && check_attribute($pattern, $node, "flat", $/)
          && check_attribute($pattern, $node, "lvalue", $/));
     }
-
-    method ACCEPTS ($node, *%opts) {
-        my $global := ?%opts<g> || ?%opts<global>;
-        return self.ACCEPTSGLOBALLY($node) if $global;
-        my $/ := self.ACCEPTSEXACTLY($node);
-        if (!$/ && ($node ~~ PAST::Node)) {
-            my $index := 0;
-            my $max := pir::elements__IP($node);
-            until ($index == $max) {
-                $/ := $node[$index] ~~ self;
-                return $/ if $/;
-                $index++;
-            }
-            $/ := PAST::Pattern::Match.new(0);
-        }
-        $/;
-    }
-
-    method ACCEPTSGLOBALLY ($node) {
-        say("Accepting globally");
-        my $/;
-        my $first := self.ACCEPTSEXACTLY($node);
-        if ($node ~~ PAST::Node) {
-            say('$node is a node.');
-            my $matches := ?$first;
-            my $index := 0;
-            my $max := pir::elements__IP($node);
-            my $submatch;
-            $/ := PAST::Pattern::Match.new(?$first);
-            $/[0] := $first if $first;
-            until ($index == $max) {
-                $submatch := self.ACCEPTS($node[$index], :g);
-                if ($submatch) {
-                    $/.success(1) unless $matches;
-                    if pir::defined__iP($submatch.from()) {
-                        $/[$matches++] := $submatch;
-                    }
-                    else { # The submatch is a list of multiple matches.
-                        my $subIndex := 0;
-                        my $subMax := pir::elements__IP($submatch);
-                        until ($subIndex == $subMax) {
-                            $/[$matches++] := $submatch[$subIndex];
-                            $subIndex++;
-                        }
-                    }
-                }
-                $index++;
-            }
-            $/ := $/[0] if $matches == 1;
-        }
-        else {
-            $/ := $first;
-        }
-        $/;
-    }
 }
 
 class PAST::Pattern::Block is PAST::Pattern::Node {


More information about the parrot-commits mailing list