[svn:parrot] r46869 - in branches/gsoc_past_optimization: . t/library
tcurtis at svn.parrot.org
tcurtis at svn.parrot.org
Fri May 21 20:50:56 UTC 2010
Author: tcurtis
Date: Fri May 21 20:50:55 2010
New Revision: 46869
URL: https://trac.parrot.org/parrot/changeset/46869
Log:
Add some tests for non-modifying traversal with PAST::Walker.
Added:
branches/gsoc_past_optimization/t/library/pastwalker.t
Modified:
branches/gsoc_past_optimization/MANIFEST
Modified: branches/gsoc_past_optimization/MANIFEST
==============================================================================
--- branches/gsoc_past_optimization/MANIFEST Fri May 21 20:05:18 2010 (r46868)
+++ branches/gsoc_past_optimization/MANIFEST Fri May 21 20:50:55 2010 (r46869)
@@ -1,7 +1,7 @@
# ex: set ro:
# $Id$
#
-# generated by tools/dev/mk_manifest_and_skip.pl Thu May 20 08:04:31 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Fri May 21 20:49:52 2010 UT
#
# See below for documentation on the format of this file.
#
@@ -1672,6 +1672,7 @@
t/library/osutils.t [test]
t/library/p6object.t [test]
t/library/parrotlib.t [test]
+t/library/pastwalker.t [test]
t/library/pcre.t [test]
t/library/perlhist.txt [test]
t/library/pg.t [test]
Added: branches/gsoc_past_optimization/t/library/pastwalker.t
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ branches/gsoc_past_optimization/t/library/pastwalker.t Fri May 21 20:50:55 2010 (r46869)
@@ -0,0 +1,165 @@
+#!./parrot
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+=head1 NAME
+
+t/library/pastwalker.t
+
+=head1 DESCRIPTION
+
+Test PAST::Walker.
+
+=head1 SYNOPSIS
+
+ % prove t/library/configure.t
+
+=cut
+
+.sub 'main' :main
+ .include 'test_more.pir'
+
+ load_bytecode 'PCT.pbc'
+ load_bytecode 'PAST/Walker.pbc'
+ register_classes()
+
+ plan(5)
+ test_count_node_types()
+.end
+
+=head1 Tests
+
+=cut
+
+=over 4
+
+=item 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.
+
+=cut
+
+.sub 'test_count_node_types'
+ .local pmc walker, past
+ $P0 = new 'Hash'
+ walker = new ['PAST';'Walker';'NodeCounter']
+ setattribute walker, 'counts', $P0
+
+ past = 'build_count_node_types_past'()
+
+ walker.'walk'(past)
+
+ $P2 = getattribute walker, 'counts'
+
+ $P3 = $P2['blocks']
+ is($P3, 2, "PAST::Block")
+
+ $P3 = $P2['ops']
+ is($P3, 3, "PAST::Op")
+
+ $P3 = $P2['vars']
+ is($P3, 2, "PAST::Var")
+
+ $P3 = $P2['vals']
+ is($P3, 1, "PAST::Val")
+
+ $P3 = $P2['stmts']
+ is($P3, 2, "PAST::Stmts")
+.end
+
+.sub 'build_count_node_types_past'
+ .local pmc past
+ past = new ['PAST';'Block']
+
+ $P0 = new ['PAST'; 'Var']
+ push past, $P0
+ $P0 = new ['PAST'; 'Op']
+ $P0.'pirop'("call")
+ $P1 = new ['PAST'; 'Var']
+ push $P0, $P1
+ $P1 = new ['PAST'; 'Val']
+ push $P0, $P1
+ push past, $P0
+ $P0 = new ['PAST'; 'Stmts']
+ $P1 = new ['PAST'; 'Op']
+ push $P0, $P1
+ $P1 = new ['PAST'; 'Op']
+ push $P0, $P1
+ $P1 = new ['PAST'; 'Block']
+ push $P0, $P1
+ push past, $P0
+ $P0 = new ['PAST'; 'Stmts']
+ push past, $P0
+ .return (past)
+.end
+
+=back
+
+=head1 Helper classes
+
+=cut
+
+.sub 'register_classes'
+ $P0 = subclass ['PAST'; 'Walker'], ['PAST'; 'Walker'; 'NodeCounter']
+ addattribute $P0, 'counts'
+.end
+
+.namespace ['PAST'; 'Walker']
+
+.sub 'walk' :multi(['PAST';'Walker';'NodeCounter'], ['PAST';'Block'])
+ .param pmc walker
+ .param pmc node
+ $P0 = getattribute walker, 'counts'
+ $I0 = $P0['blocks']
+ inc $I0
+ $P0['blocks'] = $I0
+ 'walkChildren'(walker, node)
+.end
+
+.sub 'walk' :multi(['PAST';'Walker';'NodeCounter'], ['PAST';'Op'])
+ .param pmc walker
+ .param pmc node
+ $P0 = getattribute walker, 'counts'
+ $I0 = $P0['ops']
+ inc $I0
+ $P0['ops'] = $I0
+ 'walkChildren'(walker, node)
+.end
+
+.sub 'walk' :multi(['PAST';'Walker';'NodeCounter'], ['PAST';'Stmts'])
+ .param pmc walker
+ .param pmc node
+ $P0 = getattribute walker, 'counts'
+ $I0 = $P0['stmts']
+ inc $I0
+ $P0['stmts'] = $I0
+ 'walkChildren'(walker, node)
+.end
+
+.sub 'walk' :multi(['PAST';'Walker';'NodeCounter'], ['PAST';'Val'])
+ .param pmc walker
+ .param pmc node
+ $P0 = getattribute walker, 'counts'
+ $I0 = $P0['vals']
+ inc $I0
+ $P0['vals'] = $I0
+ 'walkChildren'(walker, node)
+.end
+
+.sub 'walk' :multi(['PAST';'Walker';'NodeCounter'], ['PAST';'Var'])
+ .param pmc walker
+ .param pmc node
+ $P0 = getattribute walker, 'counts'
+ $I0 = $P0['vars']
+ inc $I0
+ $P0['vars'] = $I0
+ 'walkChildren'(walker, node)
+.end
+
+
+
+# Local Variables:
+# mode: pir
+# fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:
More information about the parrot-commits
mailing list