[svn:parrot] r46994 - in branches/gsoc_past_optimization: . runtime/parrot/library/PAST t/library

tcurtis at svn.parrot.org tcurtis at svn.parrot.org
Tue May 25 19:26:11 UTC 2010


Author: tcurtis
Date: Tue May 25 19:26:10 2010
New Revision: 46994
URL: https://trac.parrot.org/parrot/changeset/46994

Log:
Add pastcompare.pir for testing the produced PASTs and update
pasttransformer.t to use it.
Also fix a bug in PAST::Transformer regarding deleting nodes.

Added:
   branches/gsoc_past_optimization/t/library/pastcompare.pir   (contents, props changed)
Modified:
   branches/gsoc_past_optimization/MANIFEST
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer.pir
   branches/gsoc_past_optimization/t/library/pasttransformer.t

Modified: branches/gsoc_past_optimization/MANIFEST
==============================================================================
--- branches/gsoc_past_optimization/MANIFEST	Tue May 25 19:11:07 2010	(r46993)
+++ branches/gsoc_past_optimization/MANIFEST	Tue May 25 19:26:10 2010	(r46994)
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Tue May 25 00:10:06 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Tue May 25 18:45:07 2010 UT
 #
 # See below for documentation on the format of this file.
 #
@@ -1674,6 +1674,7 @@
 t/library/osutils.t                                         [test]
 t/library/p6object.t                                        [test]
 t/library/parrotlib.t                                       [test]
+t/library/pastcompare.pir                                   [test]
 t/library/pasttransformer.t                                 [test]
 t/library/pastwalker.t                                      [test]
 t/library/pcre.t                                            [test]

Modified: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer.pir
==============================================================================
--- branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer.pir	Tue May 25 19:11:07 2010	(r46993)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer.pir	Tue May 25 19:26:10 2010	(r46994)
@@ -40,19 +40,25 @@
 .sub 'replaceChildren'
     .param pmc node
     .param pmc newChildren
-    .local int childIndex, resultIndex, max
+    .local int childIndex, max
+    .local pmc ignore
     max = elements newChildren
+    $I0 = elements node
+    unless $I0 > 0 goto clear_done
+clear_loop:
+    ignore = pop node
+    dec $I0
+    if $I0 > 0 goto clear_loop
+clear_done:
     childIndex = 0
-    resultIndex = 0
     ge childIndex, max, end
-loop:
+add_loop:
     $P0 = newChildren[childIndex]
-    if null $P0 goto reloop
-    node[resultIndex] = $P0
-    inc resultIndex
-reloop:
+    if null $P0 goto add_reloop
+    push node, $P0
+add_reloop:
     inc childIndex
-    lt childIndex, max, loop
+    lt childIndex, max, add_loop
 end:
     .return ()
 .end

Added: branches/gsoc_past_optimization/t/library/pastcompare.pir
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/gsoc_past_optimization/t/library/pastcompare.pir	Tue May 25 19:26:10 2010	(r46994)
@@ -0,0 +1,178 @@
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+.namespace ['PAST'; 'Node']
+
+.sub 'is_equal' :vtable :method
+    .param pmc value
+    .tailcall 'compare_node_attrs'(self, value)
+.end
+
+.sub 'compare_node_attrs'
+    .param pmc an
+    .param pmc other
+    $P0 = an.'returns'()
+    $P1 = other.'returns'()
+    unless $P0 == $P1 goto no
+    $P0 = an.'arity'()
+    $P1 = other.'arity'()
+    unless $P0 == $P1 goto no
+    $P0 = an.'name'()
+    $P1 = other.'name'()
+    unless $P0 == $P1 goto no
+    $P0 = an.'named'()
+    $P1 = other.'named'()
+    unless $P0 == $P1 goto no
+    $P0 = an.'flat'()
+    $P1 = other.'flat'()
+    unless $P0 == $P1 goto no
+    $P0 = an.'lvalue'()
+    $P1 = other.'lvalue'()
+    unless $P0 == $P1 goto no
+    .local int lan, lother, i
+    lan = elements an
+    lother = elements other
+    unless lan == lother goto no
+    i = 0
+    unless i < lan goto yes
+elt_cmp_loop:
+    $P0 = an[i]
+    $P1 = other[i]
+    unless $P0 == $P1 goto no
+    inc i
+    if i < lan goto elt_cmp_loop
+yes:
+    .return (1)
+no:
+    .return (0)
+.end
+
+.namespace ['PAST';'Val']
+
+.sub 'is_equal' :vtable :method
+    .param pmc value
+    $P0 = class self
+    $I0 = isa value, $P0
+    if $I0 == 0 goto no
+    $P0 = self.'value'()
+    $P1 = value.'value'()
+    unless $P0 == $P1 goto no
+    $P0 = get_hll_global ['PAST'; 'Node'], 'compare_node_attrs'
+    .tailcall $P0(self, value)
+no:
+    .return (0)
+.end
+
+.namespace ['PAST';'Var']
+
+.sub 'is_equal' :vtable :method
+    .param pmc value
+    $P0 = class self
+    $I0 = isa value, $P0
+    if $I0 == 0 goto no
+    $P0 = self.'scope'()
+    $P1 = value.'scope'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'isdecl'()
+    $P1 = value.'isdecl'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'namespace'()
+    $P1 = value.'namespace'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'slurpy'()
+    $P1 = value.'slurpy'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'call_sig'()
+    $P1 = value.'call_sig'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'viviself'()
+    $P1 = value.'viviself'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'vivibase'()
+    $P1 = value.'vivibase'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'multitype'()
+    $P1 = value.'multitype'()
+    unless $P0 == $P1 goto no
+    $P0 = get_hll_global ['PAST'; 'Node'], 'compare_node_attrs'
+    .tailcall $P0(self, value)
+no:
+    .return (0)
+.end
+
+.namespace ['PAST'; 'Op']
+
+.sub 'is_equal' :vtable :method
+    .param pmc value
+    $P0 = self.'pasttype'()
+    $P1 = value.'pasttype'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'pirop'()
+    $P1 = value.'pirop'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'inline'()
+    $P1 = value.'inline'()
+    unless $P0 == $P1 goto no
+    $P0 = get_hll_global ['PAST'; 'Node'], 'compare_node_attrs'
+    .tailcall $P0(self, value)
+no:
+    .return (0)
+.end
+
+.namespace ['PAST'; 'Block']
+
+.sub 'is_equal' :vtable :method
+    .param pmc value
+    $P0 = self.'blocktype'()
+    $P1 = value.'blocktype'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'closure'()
+    $P1 = value.'closure'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'control'()
+    $P1 = value.'control'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'loadinit'()
+    $P1 = value.'loadinit'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'namespace'()
+    $P1 = value.'namespace'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'multi'()
+    $P1 = value.'multi'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'hll'()
+    $P1 = value.'hll'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'nsentry'()
+    $P1 = value.'nsentry'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'symtable'()
+    $P1 = value.'symtable'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'lexical'()
+    $P1 = value.'lexical'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'compiler'()
+    $P1 = value.'compiler'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'compiler_args'()
+    $P1 = value.'compiler_args'()
+    unless $P0 == $P1 goto no
+#    $P0 = self.'subid'()
+#    $P1 = value.'subid'()
+    unless $P0 == $P1 goto no
+    $P0 = self.'pirflags'()
+    $P1 = value.'pirflags'()
+    unless $P0 == $P1 goto no
+    $P0 = get_hll_global ['PAST'; 'Node'], 'compare_node_attrs'
+    .tailcall $P0(self, value)
+no:
+    .return (0)
+.end
+
+# Local Variables:
+#   mode: pir
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4 ft=pir:

Modified: branches/gsoc_past_optimization/t/library/pasttransformer.t
==============================================================================
--- branches/gsoc_past_optimization/t/library/pasttransformer.t	Tue May 25 19:11:07 2010	(r46993)
+++ branches/gsoc_past_optimization/t/library/pasttransformer.t	Tue May 25 19:26:10 2010	(r46994)
@@ -23,9 +23,10 @@
     load_bytecode 'PAST/Walker.pbc'
     register_classes()
 
-    plan(6)
+    plan(3)
     test_change_node_attributes()
     test_change_node_types()
+    test_delete_nodes()
 .end
 
 =head1 Tests
@@ -34,31 +35,20 @@
 
 =item test_change_node_attributes()
 
-Uses PAST::Transformer::Increment to add 1 to each PAST::Value node. It tests that modifying attributes with a PAST::Transformer works. PAST::Walker::SumVals is used to verify that the transformation has occured correctly.
+Uses PAST::Transformer::Increment to add 1 to each PAST::Value node. It tests that modifying attributes with a PAST::Transformer works.
 
 =cut
 
 .sub test_change_node_attributes
-    .local pmc past, result, summer, transformer
+    .local pmc past, result, target, transformer
     past = build_test_change_node_attributes_past()
-    summer = new ['PAST'; 'Walker'; 'SumVals']
     transformer = new ['PAST'; 'Transformer'; 'Increment']
 
-    summer.'reset'()
-    summer.'walk'(past)
-    $P0 = getattribute summer, 'sum'
-    is($P0, 78, "Initial sum worked correctly.")
-    $P1 = getattribute summer, 'count'
-    is($P1, 4, "Initial count worked correctly.")
-
     result = transformer.'walk'(past)
 
-    summer.'reset'()
-    summer.'walk'(result)
-    $P0 = getattribute summer, 'sum'
-    is($P0, 82, "The sum changed correctly.")
-    $P1 = getattribute summer, 'count'
-    is($P1, 4, "The count stayed the same correctly.")
+    target = build_test_change_node_attrs_target()
+    $S0 = "Node attributes can be changed by PAST::Transformers."
+    is (result, target, $S0)
 .end
 
 .sub build_test_change_node_attributes_past
@@ -83,6 +73,28 @@
     .return (result)
 .end
 
+.sub build_test_change_node_attrs_target
+    .local pmc result
+    result = new ['PAST'; 'Block']
+    $P0 = new ['PAST'; 'Var']
+    $P1 = new ['PAST'; 'Val']
+    $P1.'value'(38)
+    push $P0, $P1
+    push result, $P0
+    $P0 = new ['PAST'; 'Val']
+    $P0.'value'(25)
+    push result, $P0
+    $P0 = new ['PAST'; 'Block']
+    $P1 = new ['PAST'; 'Val']
+    $P1.'value'(6)
+    push $P0, $P1
+    $P1 = new ['PAST'; 'Val']
+    $P1.'value'(13)
+    push $P0, $P1
+    push result, $P0
+    .return (result)
+.end
+
 =item test_change_node_types()
 
 Use PAST::Transformer::Negate to replace negative number Vals with Ops subtracting the positive number from 0. It tests that PAST::Transformers can replace a node with a node of a different type. PAST::Walker::CountOps is used to ensure that the number of PAST::Ops changes correctly.
@@ -90,22 +102,14 @@
 =cut
 
 .sub test_change_node_types
-    .local pmc past, result, counter, transformer
+    .local pmc past, result, target, transformer
     past = build_test_change_node_types_past()
-    counter = new ['PAST'; 'Walker'; 'CountOps']
     transformer = new ['PAST'; 'Transformer'; 'Negate']
 
-    counter.'reset'()
-    counter.'walk'(past)
-    $P0 = getattribute counter, 'count'
-    is($P0, 0, "The initial tree has no PAST::Op nodes.")
-
     result = transformer.'walk'(past)
 
-    counter.'reset'()
-    counter.'walk'(result)
-    $P0 = getattribute counter, 'count'
-    is($P0, 2, "The appropriate nodes were transformed to Ops.")
+    target = build_test_change_node_types_target()
+    is(result, target, "Node types can be changed by PAST::Transformers.")
 .end
 
 .sub build_test_change_node_types_past
@@ -127,33 +131,46 @@
     .return (past)
 .end
 
+.sub build_test_change_node_types_target
+    .local pmc past
+    past = new ['PAST'; 'Block']
+    $P0 = new ['PAST'; 'Val']
+    $P0.'value'(0)
+    push past, $P0
+    $P0 = new ['PAST'; 'Op']
+    $P0.'pirop'('neg')
+    $P1 = new ['PAST'; 'Val']
+    $P1.'value'(7)
+    push $P0, $P1
+    push past, $P0
+    $P0 = new ['PAST'; 'Val']
+    $P0.'value'(5)
+    push past, $P0
+    $P0 = new ['PAST'; 'Op']
+    $P0.'pirop'('neg')
+    $P1 = new ['PAST'; 'Val']
+    $P1.'value'(32)
+    push $P0, $P1
+    push past, $P0
+
+    .return (past)
+.end
+
 =item test_delete_nodes()
 
-Uses PAST::Transformer::DeleteVals to delete PAST::Blocks with multiple children. It tests that deletion works. PAST::Walker::CountBlocks is used to count the PAST::Blocks.
+Uses PAST::Transformer::Trim to delete PAST::Blocks with multiple children. It tests that deletion works. PAST::Walker::CountBlocks is used to count the PAST::Blocks.
 
 =cut
 
 .sub test_delete_nodes
-    .local pmc past, transformer, counter, result
+    .local pmc past, result, target, transformer
     past = build_test_delete_nodes_past()
-    transformer = new ['PAST'; 'Transformer'; 'DeleteVals']
-    counter = new ['PAST'; 'Walker'; 'CountVals']
-
-    counter.'reset'()
-    counter.'walk'(past)
-    $P0 = getattribute counter, 'blocks'
-    is($P0, 4, "The initial block count was correct.")
-    $P0 = getattribute counter, 'nodes'
-    is($P0, 8, "The initial node count was correct.")
+    transformer = new ['PAST'; 'Transformer'; 'Trim']
 
     result = transformer.'walk'(past)
 
-    counter.'reset'()
-    counter.'walk'(past)
-    $P0 = getattribute counter, 'blocks'
-    is($P0, 2, "The block count changed correctly.")
-    $P0 = getattribute counter, 'nodes'
-    is($P0, 3, "The node count changed correctly.")
+    target = build_test_delete_nodes_target()
+    is(result, target, "Nodes can be deleted by PAST::Transformers.")
 .end
 
 .sub build_test_delete_nodes_past
@@ -184,6 +201,20 @@
     .return (past)
 .end
 
+.sub build_test_delete_nodes_target
+    .local pmc past
+    past = new ['PAST';'Block']
+    $P0 = new ['PAST'; 'Stmts']
+    $P1 = new ['PAST'; 'Var']
+    push $P0, $P1
+    $P1 = new ['PAST'; 'Block']
+    $P2 = new ['PAST'; 'Val']
+    push $P1, $P2
+    push $P0, $P1
+    push past, $P0
+    .return (past)
+.end
+
 =back
 
 =head1 Helper classes
@@ -195,16 +226,6 @@
     $P0 = subclass $P1, ['PAST'; 'Transformer'; 'Increment']
     $P0 = subclass $P1, ['PAST'; 'Transformer'; 'Negate']
     $P0 = subclass $P1, ['PAST'; 'Transformer'; 'Trim']
-
-    $P1 = get_class ['PAST'; 'Walker']
-    $P0 = subclass $P1, ['PAST'; 'Walker'; 'SumVals']
-    addattribute $P0, 'count'
-    addattribute $P0, 'sum'
-    $P0 = subclass $P1, ['PAST'; 'Walker'; 'CountOps']
-    addattribute $P0, 'count'
-    $P0 = subclass $P1, ['PAST'; 'Walker'; 'CountBlocks']
-    addattribute $P0, 'blocks'
-    addattribute $P0, 'nodes'
 .end
 
 .namespace ['PAST'; 'Walker']
@@ -220,18 +241,6 @@
     .return (result)
 .end
 
-.sub 'walk' :multi(['PAST'; 'Walker'; 'SumVals'], ['PAST'; 'Val'])
-    .param pmc walker
-    .param pmc node
-    $P0 = getattribute walker, 'sum'
-    $P1 = node.'value'()
-    $P0 = $P0 + $P1
-    setattribute walker, 'sum', $P0
-    $P0 = getattribute walker, 'count'
-    inc $P0
-    setattribute walker, 'count', $P0
-.end
-
 .sub 'walk' :multi(['PAST'; 'Transformer'; 'Negate'], ['PAST'; 'Val'])
     .param pmc walker
     .param pmc node
@@ -250,69 +259,22 @@
     .return (result)
 .end
 
-.sub 'walk' :multi(['PAST'; 'Walker'; 'CountOps'], ['PAST'; 'Op'])
-    .param pmc walker
-    .param pmc node
-    $P0 = getattribute walker, 'count'
-    inc $P0
-    setattribute walker, 'count', $P0
-    .tailcall 'walkChildren'(walker, node)
-.end
-
-.sub 'walk' :multi(['PAST'; 'Transformer'; 'Delete'], ['PAST'; 'Block'])
+.sub 'walk' :multi(['PAST'; 'Transformer'; 'Trim'], ['PAST'; 'Block'])
     .param pmc walker
     .param pmc node
     .local pmc result
     $I0 = elements node
     if $I0 > 1 goto multiple
-    result = clone node
+    result = node
+    $P0 = 'walkChildren'(walker, node)
+    'replaceChildren'(result, $P0)
     .return (result)
 multiple:
     result = null
     .return (result)
 .end
 
-.sub 'walk' :multi(['PAST'; 'Walker'; 'CountBlocks'], ['PAST'; 'Block'])
-    .param pmc walker
-    .param pmc node
-    $P0 = getattribute walker, 'blocks'
-    inc $P0
-    setattribute walker, 'blocks', $P0
-.end
-
-.sub 'walk' :multi(['PAST'; 'Walker'; 'CountBlocks'], ['PAST'; 'Node'])
-    .param pmc walker
-    .param pmc node
-    $P0 = getattribute walker, 'nodes'
-    inc $P0
-    setattribute walker, 'nodes', $P0
-.end
-
-.namespace ['PAST'; 'Walker'; 'SumVals']
-
-.sub 'reset' :method
-    $P0 = new 'Integer'
-    $P0 = 0
-    setattribute self, 'count', $P0
-    setattribute self, 'sum', $P0
-.end
-
-.namespace ['PAST'; 'Walker'; 'CountOps']
-
-.sub 'reset' :method
-    $P0 = new 'Integer'
-    $P0 = 0
-    setattribute self, 'count', $P0
-.end
-
-.namespace ['PAST'; 'Walker'; 'CountBlocks']
-
-.sub 'reset' :method
-    $P0 = new 'Integer'
-    $P0 = 0
-    setattribute self, 'blocks', $P0
-    setattribute self, 'nodes', $P0
-.end
+.include 't/library/pastcompare.pir'
 
 # Local Variables:
 #   mode: pir


More information about the parrot-commits mailing list