[svn:parrot] r47501 - 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
Wed Jun 9 04:25:22 UTC 2010


Author: tcurtis
Date: Wed Jun  9 04:25:22 2010
New Revision: 47501
URL: https://trac.parrot.org/parrot/changeset/47501

Log:
Add .match and .transform methods to PAST::Node when PAST/Pattern.pbc is loaded.

Added:
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/augment-past.pir
Modified:
   branches/gsoc_past_optimization/config/gen/makefiles/root.in
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern.nqp
   branches/gsoc_past_optimization/t/library/pastpattern.t

Modified: branches/gsoc_past_optimization/config/gen/makefiles/root.in
==============================================================================
--- branches/gsoc_past_optimization/config/gen/makefiles/root.in	Wed Jun  9 04:17:24 2010	(r47500)
+++ branches/gsoc_past_optimization/config/gen/makefiles/root.in	Wed Jun  9 04:25:22 2010	(r47501)
@@ -285,6 +285,7 @@
     $(LIBRARY_DIR)/PAST/Pattern/Constant.pbc \
     $(LIBRARY_DIR)/PAST/Pattern/Match.pbc \
     $(LIBRARY_DIR)/PAST/Pattern/Node.pbc \
+    $(LIBRARY_DIR)/PAST/Pattern/augment-node.pbc \
     $(LIBRARY_DIR)/PAST/Transformer.pbc \
     $(LIBRARY_DIR)/PAST/Transformer/Dynamic.pbc \
     $(LIBRARY_DIR)/PAST/Walker.pbc \

Modified: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern.nqp
==============================================================================
--- branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern.nqp	Wed Jun  9 04:17:24 2010	(r47500)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern.nqp	Wed Jun  9 04:25:22 2010	(r47501)
@@ -25,12 +25,16 @@
     }
 }
 
+
+
 INIT {
     pir::load_bytecode('PAST/Pattern/Match.pbc');
 
     pir::load_bytecode('PAST/Pattern/Closure.pbc');
     pir::load_bytecode('PAST/Pattern/Constant.pbc');
     pir::load_bytecode('PAST/Pattern/Node.pbc');
+
+    pir::load_bytecode('PAST/Pattern/augment-past.pbc');
 }
 
 # Local Variables:

Added: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/augment-past.pir
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/augment-past.pir	Wed Jun  9 04:25:22 2010	(r47501)
@@ -0,0 +1,30 @@
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+.namespace ['PAST'; 'Node']
+
+.sub 'match' :method
+    .param pmc pattern
+    .param int global :named('g') :optional
+    .param int has_global :opt_flag
+    if has_global goto have_global
+    .tailcall pattern.'ACCEPTS'(self)
+have_global:
+    .tailcall pattern.'ACCEPTS'(self, 'g' => 1)
+.end
+
+.sub 'subst' :method
+    .param pmc pattern
+    .param int global :named('g') :optional
+    .param int has_global :opt_flag
+    if has_global goto have_global
+    .tailcall pattern.'transform'(self)
+have_global:
+    .tailcall pattern.'transform'(self, 'g' => 1)
+.end
+
+# Local Variables:
+#   mode: pir
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:

Modified: branches/gsoc_past_optimization/t/library/pastpattern.t
==============================================================================
--- branches/gsoc_past_optimization/t/library/pastpattern.t	Wed Jun  9 04:17:24 2010	(r47500)
+++ branches/gsoc_past_optimization/t/library/pastpattern.t	Wed Jun  9 04:25:22 2010	(r47501)
@@ -5,7 +5,7 @@
 pir::load_bytecode('PCT.pbc');
 pir::load_bytecode('PAST/Pattern.pbc');
 
-plan(2051);
+plan(2054);
 
 test_type_matching();
 test_attribute_exact_matching();
@@ -17,6 +17,8 @@
 
 test_match_result();
 
+test_match_method();
+
 sub node_with_attr_set ($class, $attr, $val) {
     my $node := $class.new();
     if (($attr eq "source" || $attr eq "pos")
@@ -721,6 +723,19 @@
        '$/[0] is correct for PAST::Pattern::VarList.');
 }
 
+sub test_match_method () {
+    my $pattern := PAST::Pattern::Block.new();
+    my $past := PAST::Block.new();
+
+    my $/ := $past.match($pattern);
+    ok($/ ~~ PAST::Pattern::Match,
+       'PAST::Node.match returns a PAST::Pattern::Match.');
+    ok(?$/,
+       'PAST::Node.match returns a true match result when it should.');
+    ok($/.from() =:= $past,
+       "PAST::Node.match's return value has the right .from()/");
+}
+
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4


More information about the parrot-commits mailing list