[svn:parrot] r47846 - in branches/gsoc_past_optimization: . config/gen/makefiles runtime/parrot/library/Tree
tcurtis at svn.parrot.org
tcurtis at svn.parrot.org
Sat Jun 26 00:18:00 UTC 2010
Author: tcurtis
Date: Sat Jun 26 00:17:59 2010
New Revision: 47846
URL: https://trac.parrot.org/parrot/changeset/47846
Log:
Add Tree::Transformer base class for various transformer subclasses.
Added:
branches/gsoc_past_optimization/runtime/parrot/library/Tree/Transformer.nqp (contents, props changed)
Modified:
branches/gsoc_past_optimization/MANIFEST
branches/gsoc_past_optimization/MANIFEST.SKIP
branches/gsoc_past_optimization/config/gen/makefiles/root.in
branches/gsoc_past_optimization/runtime/parrot/library/Tree/ (props changed)
Modified: branches/gsoc_past_optimization/MANIFEST
==============================================================================
--- branches/gsoc_past_optimization/MANIFEST Fri Jun 25 23:38:48 2010 (r47845)
+++ branches/gsoc_past_optimization/MANIFEST Sat Jun 26 00:17:59 2010 (r47846)
@@ -1,7 +1,7 @@
# ex: set ro:
# $Id$
#
-# generated by tools/dev/mk_manifest_and_skip.pl Fri Jun 25 05:50:21 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Fri Jun 25 23:44:21 2010 UT
#
# See below for documentation on the format of this file.
#
@@ -1241,6 +1241,7 @@
runtime/parrot/library/Tree/Pattern/Constant.nqp [library]
runtime/parrot/library/Tree/Pattern/Match.nqp [library]
runtime/parrot/library/Tree/Pattern/Transformer.nqp [library]
+runtime/parrot/library/Tree/Transformer.nqp [library]
runtime/parrot/library/Tree/Walker.nqp [library]
runtime/parrot/library/URI.pir [library]
runtime/parrot/library/URI/Escape.pir [library]
Modified: branches/gsoc_past_optimization/MANIFEST.SKIP
==============================================================================
--- branches/gsoc_past_optimization/MANIFEST.SKIP Fri Jun 25 23:38:48 2010 (r47845)
+++ branches/gsoc_past_optimization/MANIFEST.SKIP Sat Jun 26 00:17:59 2010 (r47846)
@@ -1,6 +1,6 @@
# ex: set ro:
# $Id$
-# generated by tools/dev/mk_manifest_and_skip.pl Fri Jun 25 05:50:21 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Fri Jun 25 23:44:21 2010 UT
#
# This file should contain a transcript of the svn:ignore properties
# of the directories in the Parrot subversion repository. (Needed for
@@ -653,6 +653,8 @@
^runtime/parrot/library/Tree/.*\.pbc/
^runtime/parrot/library/Tree/Pattern\.pir$
^runtime/parrot/library/Tree/Pattern\.pir/
+^runtime/parrot/library/Tree/Transformer\.pir$
+^runtime/parrot/library/Tree/Transformer\.pir/
^runtime/parrot/library/Tree/Walker\.pir$
^runtime/parrot/library/Tree/Walker\.pir/
# generated from svn:ignore of 'runtime/parrot/library/Tree/Pattern/'
Modified: branches/gsoc_past_optimization/config/gen/makefiles/root.in
==============================================================================
--- branches/gsoc_past_optimization/config/gen/makefiles/root.in Fri Jun 25 23:38:48 2010 (r47845)
+++ branches/gsoc_past_optimization/config/gen/makefiles/root.in Sat Jun 26 00:17:59 2010 (r47846)
@@ -345,6 +345,8 @@
$(LIBRARY_DIR)/Tree/Pattern/Match.pir \
$(LIBRARY_DIR)/Tree/Pattern/Transformer.pbc \
$(LIBRARY_DIR)/Tree/Pattern/Transformer.pir \
+ $(LIBRARY_DIR)/Tree/Transformer.pbc \
+ $(LIBRARY_DIR)/Tree/Transformer.pir \
$(LIBRARY_DIR)/Tree/Walker.pbc \
$(LIBRARY_DIR)/Tree/Walker.pir \
$(LIBRARY_DIR)/URI.pbc \
@@ -1244,6 +1246,15 @@
$(NQP_RX) --target=pir $(LIBRARY_DIR)/Tree/Pattern/Transformer.nqp \
> $@
+$(LIBRARY_DIR)/Tree/Transformer.pbc: \
+ $(LIBRARY_DIR)/Tree/Transformer.pir
+ $(PARROT) -o $@ $(LIBRARY_DIR)/Tree/Transformer.pir
+
+$(LIBRARY_DIR)/Tree/Transformer.pir: \
+ $(LIBRARY_DIR)/Tree/Transformer.nqp $(NQP_RX)
+ $(NQP_RX) --target=pir $(LIBRARY_DIR)/Tree/Transformer.nqp \
+ > $@
+
$(LIBRARY_DIR)/Tree/Walker.pbc: $(LIBRARY_DIR)/Tree/Walker.pir
$(PARROT) -o $@ $(LIBRARY_DIR)/Tree/Walker.pir
Added: branches/gsoc_past_optimization/runtime/parrot/library/Tree/Transformer.nqp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/gsoc_past_optimization/runtime/parrot/library/Tree/Transformer.nqp Sat Jun 26 00:17:59 2010 (r47846)
@@ -0,0 +1,55 @@
+#!./parrot-nqp
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+INIT {
+pir::load_bytecode('Tree/Walker.pbc');
+}
+
+class Tree::Transformer is Tree::Walker { }
+
+module Tree::Walker {
+ our multi sub walk (Tree::Transformer $walker, Capture $node) {
+ my $result := $node;
+ replaceChildren($result, walkChildren($walker, $node));
+ $result;
+ }
+
+ our multi sub walk (Tree::Transformer $walker, $node) {
+ $node; # Don't touch things that we don't know what to do with.
+ }
+
+ our multi sub walkChildren (Tree::Transformer $walker,
+ Capture $node) {
+ my @results;
+ my $index := 0;
+ my $max := pir::elements__IP($node);
+ while ($index < $max) {
+ @results[$index] := walk($walker, $node[$index]);
+ $index++;
+ }
+ @results;
+ }
+
+ our sub replaceChildren ($node, $newChildren) {
+ my $index := pir::elements__IP($node);
+ while ($index > 0) {
+ pir::pop__PP($node);
+ $index--;
+ }
+ my $max := pir::elements__IP($newChildren);
+ while ($index < $max) {
+ pir::push($node, $newChildren[$index])
+ if pir::defined__IP($newChildren[$index]);
+ $index++;
+ }
+ null;
+ }
+}
+
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:
More information about the parrot-commits
mailing list