[svn:parrot] r47699 - in branches/gsoc_past_optimization: . config/gen/makefiles runtime/parrot/library/PAST runtime/parrot/library/PAST/Pattern t/library

tcurtis at svn.parrot.org tcurtis at svn.parrot.org
Sat Jun 19 04:55:30 UTC 2010


Author: tcurtis
Date: Sat Jun 19 04:55:29 2010
New Revision: 47699
URL: https://trac.parrot.org/parrot/changeset/47699

Log:
Add PAST::Pattern::Any.

Added:
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Any.nqp   (contents, props changed)
Modified:
   branches/gsoc_past_optimization/MANIFEST
   branches/gsoc_past_optimization/config/gen/makefiles/root.in
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/   (props changed)
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern.nqp
   branches/gsoc_past_optimization/t/library/pastpattern.t

Modified: branches/gsoc_past_optimization/MANIFEST
==============================================================================
--- branches/gsoc_past_optimization/MANIFEST	Sat Jun 19 02:08:01 2010	(r47698)
+++ branches/gsoc_past_optimization/MANIFEST	Sat Jun 19 04:55:29 2010	(r47699)
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Sat Jun 19 01:35:35 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Sat Jun 19 02:30:23 2010 UT
 #
 # See below for documentation on the format of this file.
 #
@@ -1175,6 +1175,7 @@
 runtime/parrot/library/OpenGL/Math.pir                      [library]
 runtime/parrot/library/P6object.pir                         [library]
 runtime/parrot/library/PAST/Pattern.nqp                     [library]
+runtime/parrot/library/PAST/Pattern/Any.nqp                 [library]
 runtime/parrot/library/PAST/Pattern/Closure.nqp             [library]
 runtime/parrot/library/PAST/Pattern/Constant.nqp            [library]
 runtime/parrot/library/PAST/Pattern/Match.nqp               [library]

Modified: branches/gsoc_past_optimization/config/gen/makefiles/root.in
==============================================================================
--- branches/gsoc_past_optimization/config/gen/makefiles/root.in	Sat Jun 19 02:08:01 2010	(r47698)
+++ branches/gsoc_past_optimization/config/gen/makefiles/root.in	Sat Jun 19 04:55:29 2010	(r47699)
@@ -281,6 +281,7 @@
     $(LIBRARY_DIR)/osutils.pbc \
     $(LIBRARY_DIR)/P6object.pbc \
     $(LIBRARY_DIR)/PAST/Pattern.pbc \
+    $(LIBRARY_DIR)/PAST/Pattern/Any.pbc \
     $(LIBRARY_DIR)/PAST/Pattern/Closure.pbc \
     $(LIBRARY_DIR)/PAST/Pattern/Constant.pbc \
     $(LIBRARY_DIR)/PAST/Pattern/Match.pbc \
@@ -1091,6 +1092,15 @@
 $(LIBRARY_DIR)/PAST/Pattern.pir: $(LIBRARY_DIR)/PAST/Pattern.nqp $(NQP_RX)
 	$(NQP_RX) --target=pir $(LIBRARY_DIR)/PAST/Pattern.nqp > $@
 
+$(LIBRARY_DIR)/PAST/Pattern/Any.pbc: \
+	$(LIBRARY_DIR)/PAST/Pattern/Any.pir
+	$(PARROT) -o $@ $(LIBRARY_DIR)/PAST/Pattern/Any.pir
+
+$(LIBRARY_DIR)/PAST/Pattern/Any.pir: \
+	$(LIBRARY_DIR)/PAST/Pattern/Any.nqp $(NQP_RX)
+	$(NQP_RX) --target=pir $(LIBRARY_DIR)/PAST/Pattern/Any.nqp \
+	> $@
+
 $(LIBRARY_DIR)/PAST/Pattern/Constant.pbc: \
 	$(LIBRARY_DIR)/PAST/Pattern/Constant.pir
 	$(PARROT) -o $@ $(LIBRARY_DIR)/PAST/Pattern/Constant.pir

Modified: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern.nqp
==============================================================================
--- branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern.nqp	Sat Jun 19 02:08:01 2010	(r47698)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern.nqp	Sat Jun 19 04:55:29 2010	(r47699)
@@ -117,6 +117,8 @@
     pir::load_bytecode('PAST/Pattern/Constant.pbc');
     pir::load_bytecode('PAST/Pattern/Node.pbc');
 
+    pir::load_bytecode('PAST/Pattern/Any.pbc');
+
     pir::load_bytecode('PAST/Pattern/Transformer.pbc');
 }
 

Added: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Any.nqp
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Any.nqp	Sat Jun 19 04:55:29 2010	(r47699)
@@ -0,0 +1,38 @@
+#!./parrot-nqp
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+class PAST::Pattern::Any is PAST::Pattern {
+    method new (*@_) {
+        my $self := Q:PIR {
+            $P0 = self.'HOW'()
+            $P0 = getattribute $P0, 'parrotclass'
+            %r = new $P0
+        };
+        my $index := 0;
+        for @_ {
+            $self[$index++] := PAST::Pattern::patternize($_);
+        }
+        $self;
+    }
+
+    method ACCEPTSEXACTLY ($node) {
+        my $index := 0;
+        my $max := pir::elements(self);
+        my $/;
+        while ($index < $max) {
+            if ($/ := self[$index].ACCEPTS($node, :p($node))) {
+                return $/;
+            }
+            $index++;
+        }
+        PAST::Pattern::Match.new(0);
+    }
+}
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Modified: branches/gsoc_past_optimization/t/library/pastpattern.t
==============================================================================
--- branches/gsoc_past_optimization/t/library/pastpattern.t	Sat Jun 19 02:08:01 2010	(r47698)
+++ branches/gsoc_past_optimization/t/library/pastpattern.t	Sat Jun 19 04:55:29 2010	(r47699)
@@ -5,7 +5,7 @@
 pir::load_bytecode('PCT.pbc');
 pir::load_bytecode('PAST/Pattern.pbc');
 
-plan(2101);
+plan(2109);
 
 test_type_matching();
 test_attribute_exact_matching();
@@ -13,6 +13,8 @@
 test_attribute_smart_matching();
 test_child_smart_matching();
 
+test_any_matching();
+
 test_deep_matching_in_children();
 test_global_matching();
 
@@ -485,6 +487,35 @@
     }
 }
 
+sub test_any_matching () {
+    my $pattern := PAST::Pattern::Any.new(PAST::Pattern::Val.new(),
+                                          PAST::Pattern::Var.new());
+    my $past := PAST::Val.new();
+    my $/ := $past ~~ $pattern;
+    ok($/ ~~ PAST::Pattern::Match,
+       'PAST::Pattern::Any: Matching 1st option produces a match result.');
+    ok(?$/,
+       'PAST::Pattern::Any: Matching 1st option matches.');
+    ok($/.from() =:= $past,
+       'PAST::Pattern::Any: Matching 1st option has correct .from.');
+
+    $past := PAST::Var.new();
+    $/ := $past ~~ $pattern;
+    ok($/ ~~ PAST::Pattern::Match,
+       'PAST::Pattern::Any: Matching 2nd option produces a match result.');
+    ok(?$/,
+       'PAST::Pattern::Any: Matching 2nd option matches.');
+    ok($/.from() =:= $past,
+       'PAST::Pattern::Any: Matching 2nd option has correct .from.');
+
+    $past := PAST::Block.new();
+    $/ := $past ~~ $pattern;
+    ok($/ ~~ PAST::Pattern::Match,
+       'PAST::Pattern::Any: None matching produces a match result.');
+    ok(!$/,
+       'PAST::Pattern::Any: None matching does not match.');
+}
+
 sub test_deep_matching_in_children () {
     my @classes := [ [ PAST::Block, PAST::Pattern::Block],
                      [ PAST::Op, PAST::Pattern::Op],


More information about the parrot-commits mailing list