[svn:parrot] r46896 - in branches/gsoc_past_optimization: . config/gen/makefiles examples/library runtime/parrot/library/PAST t/library

tcurtis at svn.parrot.org tcurtis at svn.parrot.org
Sat May 22 20:49:45 UTC 2010


Author: tcurtis
Date: Sat May 22 20:49:44 2010
New Revision: 46896
URL: https://trac.parrot.org/parrot/changeset/46896

Log:
Fixed props and added PAST::Transformer for changing the tree.

Added:
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer.pir   (contents, props changed)
Modified:
   branches/gsoc_past_optimization/MANIFEST
   branches/gsoc_past_optimization/config/gen/makefiles/root.in
   branches/gsoc_past_optimization/examples/library/pastwalker.pir
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/   (props changed)
   branches/gsoc_past_optimization/t/library/pastwalker.t   (contents, props changed)

Modified: branches/gsoc_past_optimization/MANIFEST
==============================================================================
--- branches/gsoc_past_optimization/MANIFEST	Sat May 22 20:30:39 2010	(r46895)
+++ branches/gsoc_past_optimization/MANIFEST	Sat May 22 20:49:44 2010	(r46896)
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Fri May 21 20:49:52 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Sat May 22 19:48:00 2010 UT
 #
 # See below for documentation on the format of this file.
 #
@@ -1154,6 +1154,7 @@
 runtime/parrot/library/OpenGL.pir                           [library]
 runtime/parrot/library/OpenGL/Math.pir                      [library]
 runtime/parrot/library/P6object.pir                         [library]
+runtime/parrot/library/PAST/Transformer.pir                 [library]
 runtime/parrot/library/PAST/Walker.pir                      [library]
 runtime/parrot/library/PCT/README                           []doc
 runtime/parrot/library/PGE/Dumper.pir                       [library]

Modified: branches/gsoc_past_optimization/config/gen/makefiles/root.in
==============================================================================
--- branches/gsoc_past_optimization/config/gen/makefiles/root.in	Sat May 22 20:30:39 2010	(r46895)
+++ branches/gsoc_past_optimization/config/gen/makefiles/root.in	Sat May 22 20:49:44 2010	(r46896)
@@ -285,6 +285,7 @@
 #IF(has_opengl):    $(LIBRARY_DIR)/OpenGL/Math.pbc \
     $(LIBRARY_DIR)/osutils.pbc \
     $(LIBRARY_DIR)/P6object.pbc \
+    $(LIBRARY_DIR)/PAST/Transformer.pbc \
     $(LIBRARY_DIR)/PAST/Walker.pbc \
     $(LIBRARY_DIR)/ProfTest.pbc \
     $(LIBRARY_DIR)/ProfTest/PIRProfile.pir \

Modified: branches/gsoc_past_optimization/examples/library/pastwalker.pir
==============================================================================
--- branches/gsoc_past_optimization/examples/library/pastwalker.pir	Sat May 22 20:30:39 2010	(r46895)
+++ branches/gsoc_past_optimization/examples/library/pastwalker.pir	Sat May 22 20:49:44 2010	(r46896)
@@ -5,11 +5,12 @@
 
 .sub 'onload' :anon :init :load
     load_bytecode 'PCT.pbc'
+    load_bytecode 'PAST/Transformer.pbc'
     load_bytecode 'PAST/Walker.pbc'
     $P0 = subclass ['PAST'; 'Walker'], ['PAST'; 'Walker'; 'Dumper']
-    $P0 = subclass ['PAST'; 'Walker'], ['PAST'; 'Walker'; 'Changer']
+    $P0 = subclass ['PAST'; 'Transformer'], ['PAST'; 'Transformer'; 'Changer']
 .end
-    
+
 .sub 'walk' :multi(['PAST';'Walker';'Dumper'], ['PAST'; 'Val'])
     .param pmc walker
     .param pmc node
@@ -29,34 +30,36 @@
     say "} raV"
 .end
 
-.sub 'walk' :multi(['PAST';'Walker';'Changer'], ['PAST';'Val'])
+.sub 'walk' :multi(['PAST';'Transformer';'Changer'], ['PAST';'Val'])
     .param pmc walker
     .param pmc node
-    node.'value'(5)
+    .local pmc result
+    result = clone node
+    result.'value'(5)
+    $P0 = result.'value'()
+    .return (result)
 .end
 
 .namespace []
 
 .sub 'main' :main
-    .local pmc past, dumper, changer, walk
+    .local pmc past, dumper, changer, changed
     past = new ['PAST';'Var']
     $P0 = new ['PAST';'Val']
     $P0.'value'(0)
     push past, $P0
     $P0 = new ['PAST';'Var']
     push past, $P0
-    
-    walk = get_hll_global ['PAST';'Walker'], 'walk'
-    
+
     dumper = new ['PAST';'Walker';'Dumper']
-    walk(dumper, past)
-    
+    dumper.'walk'(past)
+
     say "\n\nChanging:\n"
-    
-    changer = new ['PAST';'Walker';'Changer']
-    walk(changer, past)
-    
-    walk(dumper, past)
+
+    changer = new ['PAST';'Transformer';'Changer']
+    changed = changer.'walk'(past)
+
+    dumper.'walk'(changed)
 .end
 
 # Local Variables:

Added: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer.pir
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer.pir	Sat May 22 20:49:44 2010	(r46896)
@@ -0,0 +1,62 @@
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+.sub 'onload' :anon :init :load
+    load_bytecode 'PAST/Walker.pbc'
+    $P0 = subclass ['PAST';'Walker'], ['PAST'; 'Transformer']
+.end
+
+.namespace ['PAST'; 'Walker']
+
+.sub 'walk' :multi(['PAST';'Transformer'], ['PAST';'Node'])
+    .param pmc walker
+    .param pmc node
+    .local pmc newChildren, result
+    result = clone node
+    newChildren = 'walkChildren'(walker, node)
+    'replaceChildren'(result, newChildren)
+    .return (result)
+.end
+
+.sub 'walkChildren' :multi(['PAST';'Transformer'], ['PAST';'Node'])
+    .param pmc walker
+    .param pmc node
+    .local pmc result
+    .local int index, max
+    result = new 'ResizablePMCArray'
+    index = 0
+    max = elements node
+    ge index, max, end
+loop:
+    $P0 = node[index]
+    $P1 = 'walk'(walker, $P0)
+    result[index] = $P1
+    inc index
+    lt index, max, loop
+end:
+    .return (result)
+.end
+
+.sub 'replaceChildren'
+    .param pmc node
+    .param pmc newChildren
+    .local int index, max
+    max = elements node
+    index = 0
+    ge index, max, end
+loop:
+    $P0 = newChildren[index]
+    if null $P0 goto reloop
+    node[index] = $P0
+reloop:
+    inc index
+    lt index, max, loop
+end:
+    .return ()
+.end
+
+# Local Variables:
+#   mode: pir
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:

Modified: branches/gsoc_past_optimization/t/library/pastwalker.t
==============================================================================
--- branches/gsoc_past_optimization/t/library/pastwalker.t	Sat May 22 20:30:39 2010	(r46895)
+++ branches/gsoc_past_optimization/t/library/pastwalker.t	Sat May 22 20:49:44 2010	(r46896)
@@ -15,16 +15,16 @@
     % 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()    
+    test_count_node_types()
 .end
 
 =head1 Tests
@@ -46,23 +46,23 @@
     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
@@ -70,7 +70,7 @@
 .sub 'build_count_node_types_past'
     .local pmc past
     past = new ['PAST';'Block']
-    
+
     $P0 = new ['PAST'; 'Var']
     push past, $P0
     $P0 = new ['PAST'; 'Op']
@@ -135,7 +135,7 @@
     $P0['stmts'] = $I0
     'walkChildren'(walker, node)
 .end
-    
+
 .sub 'walk' :multi(['PAST';'Walker';'NodeCounter'], ['PAST';'Val'])
     .param pmc walker
     .param pmc node


More information about the parrot-commits mailing list