[svn:parrot] r47523 - in branches/gsoc_past_optimization: . examples/library runtime/parrot/library/PAST runtime/parrot/library/PAST/Pattern
tcurtis at svn.parrot.org
tcurtis at svn.parrot.org
Thu Jun 10 03:03:15 UTC 2010
Author: tcurtis
Date: Thu Jun 10 03:03:14 2010
New Revision: 47523
URL: https://trac.parrot.org/parrot/changeset/47523
Log:
Fix a PAST::Pattern.transform bug and add an example of constant folding with PAST::Pattern.
Added:
branches/gsoc_past_optimization/examples/library/pastpattern.nqp (contents, props changed)
Modified:
branches/gsoc_past_optimization/MANIFEST
branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern.nqp
branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Transformer.nqp
Modified: branches/gsoc_past_optimization/MANIFEST
==============================================================================
--- branches/gsoc_past_optimization/MANIFEST Wed Jun 9 22:33:46 2010 (r47522)
+++ branches/gsoc_past_optimization/MANIFEST Thu Jun 10 03:03:14 2010 (r47523)
@@ -1,7 +1,7 @@
# ex: set ro:
# $Id$
#
-# generated by tools/dev/mk_manifest_and_skip.pl Wed Jun 9 18:58:33 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Thu Jun 10 02:56:03 2010 UT
#
# See below for documentation on the format of this file.
#
@@ -644,6 +644,7 @@
examples/library/getopt_demo.pir [examples]
examples/library/md5sum.pir [examples]
examples/library/ncurses_life.pir [examples]
+examples/library/pastpattern.nqp [examples]
examples/library/pasttransformer.pir [examples]
examples/library/pasttransformerdynamic.nqp [examples]
examples/library/pastwalker.pir [examples]
Added: branches/gsoc_past_optimization/examples/library/pastpattern.nqp
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/gsoc_past_optimization/examples/library/pastpattern.nqp Thu Jun 10 03:03:14 2010 (r47523)
@@ -0,0 +1,46 @@
+#!./parrot-nqp
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+pir::load_bytecode('PCT.pbc');
+pir::load_bytecode('PAST/Pattern.pbc');
+pir::load_bytecode('Data/Dumper.pbc');
+
+sub isFoldable ($opName) {
+ $opName eq "add";
+}
+
+sub isInteger ($val) {
+ pir::isa__iPP($val, Integer);
+}
+
+sub fold ($/) {
+ my $value := $/[0].value() + $/[1].value();
+ my $node := PAST::Val.new(:value($value),
+ :returns('Integer'));
+ $node;
+}
+
+my $binaryPattern :=
+ PAST::Pattern::Op.new(:pirop(isFoldable),
+ PAST::Pattern::Val.new(:value(isInteger)),
+ PAST::Pattern::Val.new(:value(isInteger)));
+
+my $dumper := pir::new__Pp(Data::Dumper);
+my $compiler := pir::compreg__PS("NQP-rx");
+my $past := $compiler.compile("say(1+2);", :target<past>);
+
+say("Before:");
+$dumper.dumper($past);
+
+my $result := $binaryPattern.transform($past, fold);
+
+say("After:");
+$dumper.dumper($result);
+
+# Local Variables:
+# mode: cperl
+# cperl-indent-level: 4
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:
Modified: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern.nqp
==============================================================================
--- branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern.nqp Wed Jun 9 22:33:46 2010 (r47522)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern.nqp Thu Jun 10 03:03:14 2010 (r47523)
@@ -27,7 +27,7 @@
method transform ($past, $transform) {
my &transSub;
if ($transform ~~ PAST::Transformer) {
- &transSub := sub ($node) { $transformer.walk($node); };
+ &transSub := sub ($/) { $transformer.walk($/.from()); };
} elsif (pir::does__iPS($transform, 'invokable')) {
&transSub := $transform;
} else {
Modified: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Transformer.nqp
==============================================================================
--- branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Transformer.nqp Wed Jun 9 22:33:46 2010 (r47522)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Pattern/Transformer.nqp Thu Jun 10 03:03:14 2010 (r47523)
@@ -56,7 +56,7 @@
}
my $result;
if ($shouldTransform) {
- $result := $walker.transform()($node);
+ $result := $walker.transform()($shouldTransform);
}
else {
$result := $node;
More information about the parrot-commits
mailing list