[svn:parrot] r47043 - in branches/gsoc_past_optimization: config/gen/makefiles runtime/parrot/library/PAST/Walker t/library
tcurtis at svn.parrot.org
tcurtis at svn.parrot.org
Thu May 27 03:42:21 UTC 2010
Author: tcurtis
Date: Thu May 27 03:42:20 2010
New Revision: 47043
URL: https://trac.parrot.org/parrot/changeset/47043
Log:
Add accessors for PAST::Walker::Dynamic attrs and a test for PAST::Walker::Dynamic.
Added:
branches/gsoc_past_optimization/t/library/pastwalkerdynamic.t
Modified:
branches/gsoc_past_optimization/config/gen/makefiles/root.in
branches/gsoc_past_optimization/runtime/parrot/library/PAST/Walker/ (props changed)
branches/gsoc_past_optimization/runtime/parrot/library/PAST/Walker/Dynamic.pir (contents, props changed)
Modified: branches/gsoc_past_optimization/config/gen/makefiles/root.in
==============================================================================
--- branches/gsoc_past_optimization/config/gen/makefiles/root.in Thu May 27 01:51:45 2010 (r47042)
+++ branches/gsoc_past_optimization/config/gen/makefiles/root.in Thu May 27 03:42:20 2010 (r47043)
@@ -287,6 +287,7 @@
$(LIBRARY_DIR)/P6object.pbc \
$(LIBRARY_DIR)/PAST/Transformer.pbc \
$(LIBRARY_DIR)/PAST/Walker.pbc \
+ $(LIBRARY_DIR)/PAST/Walker/Dynamic.pbc \
$(LIBRARY_DIR)/ProfTest.pbc \
$(LIBRARY_DIR)/ProfTest/PIRProfile.pir \
$(LIBRARY_DIR)/ProfTest/NQPProfile.pir \
Modified: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Walker/Dynamic.pir
==============================================================================
--- branches/gsoc_past_optimization/runtime/parrot/library/PAST/Walker/Dynamic.pir Thu May 27 01:51:45 2010 (r47042)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Walker/Dynamic.pir Thu May 27 03:42:20 2010 (r47043)
@@ -11,6 +11,58 @@
addattribute $P0, 'var'
.end
+.namespace ['PAST'; 'Walker'; 'Dynamic']
+
+.sub 'block' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ if has_value goto setter
+ $P0 = getattribute self, 'block'
+ .return ($P0)
+setter:
+ setattribute self, 'block', value
+.end
+
+.sub 'op' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ if has_value goto setter
+ $P0 = getattribute self, 'op'
+ .return ($P0)
+setter:
+ setattribute self, 'op', value
+.end
+
+.sub 'stmts' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ if has_value goto setter
+ $P0 = getattribute self, 'stmts'
+ .return ($P0)
+setter:
+ setattribute self, 'stmts', value
+.end
+
+.sub 'val' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ if has_value goto setter
+ $P0 = getattribute self, 'val'
+ .return ($P0)
+setter:
+ setattribute self, 'val', value
+.end
+
+.sub 'var' :method
+ .param pmc value :optional
+ .param int has_value :opt_flag
+ if has_value goto setter
+ $P0 = getattribute self, 'var'
+ .return ($P0)
+setter:
+ setattribute self, 'var', value
+.end
+
.namespace ['PAST'; 'Walker']
.sub 'walk' :multi(['PAST'; 'Walker'; 'Dynamic'], ['PAST'; 'Block'])
Added: branches/gsoc_past_optimization/t/library/pastwalkerdynamic.t
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/gsoc_past_optimization/t/library/pastwalkerdynamic.t Thu May 27 03:42:20 2010 (r47043)
@@ -0,0 +1,91 @@
+#!./parrot-nqp
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+pir::load_bytecode('PCT.pbc');
+pir::load_bytecode('PAST/Walker/Dynamic.pbc');
+
+plan(5);
+test_count_node_types();
+
+# Tests
+
+# test_count_node_types()
+# Uses PAST::Walker::NodeCounter to count the number of each node type
+# in a PAST. It tests that traversal of all node types does work.
+
+my $blocks;
+my $ops;
+my $stmts;
+my $vals;
+my $vars;
+
+sub walkBlock ($walker, $past) {
+ ++$blocks;
+ PAST::Walker::walkChildren($walker, $past);
+}
+sub walkOp ($walker, $past) {
+ ++$ops;
+ PAST::Walker::walkChildren($walker, $past);
+}
+sub walkStmts ($walker, $past) {
+ ++$stmts;
+ PAST::Walker::walkChildren($walker, $past);
+}
+sub walkVal ($walker, $past) {
+ ++$vals;
+ PAST::Walker::walkChildren($walker, $past);
+}
+sub walkVar ($walker, $past) {
+ ++$vars;
+ PAST::Walker::walkChildren($walker, $past);
+}
+
+sub zeroCounts () {
+ $blocks := 0;
+ $ops := 0;
+ $stmts := 0;
+ $vals := 0;
+ $vars := 0;
+}
+
+sub test_count_node_types() {
+ my $walker := Q:PIR { %r = new ['PAST'; 'Walker'; 'Dynamic']};
+
+ $walker.block(walkBlock);
+ $walker.op(walkOp);
+ $walker.stmts(walkStmts);
+ $walker.val(walkVal);
+ $walker.var(walkVar);
+
+ zeroCounts();
+
+ my $past := build_count_node_types_past();
+
+ $walker.walk($past);
+
+ ok($blocks == 2, "PAST::Block");
+ ok($ops == 3, "PAST::Op");
+ ok($vars == 2, "PAST::Var");
+ ok($vals == 1, "PAST::Val");
+ ok($stmts == 2, "PAST::Stmts");
+}
+
+sub build_count_node_types_past() {
+ my $past :=
+ PAST::Block.new(PAST::Var.new(),
+ PAST::Op.new(PAST::Var.new(),
+ PAST::Val.new(),
+ :pirop<call>),
+ PAST::Stmts.new(PAST::Op.new(),
+ PAST::Op.new(),
+ PAST::Block.new()),
+ PAST::Stmts.new());
+ $past;
+}
+
+# Local Variables:
+# mode: pir
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
More information about the parrot-commits
mailing list