[svn:parrot] r47115 - in branches/gsoc_past_optimization: runtime/parrot/include t/library

tcurtis at svn.parrot.org tcurtis at svn.parrot.org
Sat May 29 19:27:03 UTC 2010


Author: tcurtis
Date: Sat May 29 19:27:03 2010
New Revision: 47115
URL: https://trac.parrot.org/parrot/changeset/47115

Log:
Fix issue in pastcompare and add test for deleting nodes with PAST::Transformer::Dynamic.

Modified:
   branches/gsoc_past_optimization/runtime/parrot/include/pastcompare.pir
   branches/gsoc_past_optimization/t/library/pasttransformerdynamic.t

Modified: branches/gsoc_past_optimization/runtime/parrot/include/pastcompare.pir
==============================================================================
--- branches/gsoc_past_optimization/runtime/parrot/include/pastcompare.pir	Sat May 29 17:16:09 2010	(r47114)
+++ branches/gsoc_past_optimization/runtime/parrot/include/pastcompare.pir	Sat May 29 19:27:03 2010	(r47115)
@@ -104,6 +104,9 @@
 
 .sub 'is_equal' :vtable :method
     .param pmc value
+    $P0 = class self
+    $I0 = isa value, $P0
+    if $I0 == 0 goto no
     $P0 = self.'pasttype'()
     $P1 = value.'pasttype'()
     unless $P0 == $P1 goto no
@@ -123,6 +126,9 @@
 
 .sub 'is_equal' :vtable :method
     .param pmc value
+    $P0 = class self
+    $I0 = isa value, $P0
+    if $I0 == 0 goto no
     $P0 = self.'blocktype'()
     $P1 = value.'blocktype'()
     unless $P0 == $P1 goto no

Modified: branches/gsoc_past_optimization/t/library/pasttransformerdynamic.t
==============================================================================
--- branches/gsoc_past_optimization/t/library/pasttransformerdynamic.t	Sat May 29 17:16:09 2010	(r47114)
+++ branches/gsoc_past_optimization/t/library/pasttransformerdynamic.t	Sat May 29 19:27:03 2010	(r47115)
@@ -6,9 +6,10 @@
 pir::load_bytecode('PAST/Transformer/Dynamic.pbc');
 pir::load_bytecode('runtime/parrot/include/pastcompare.pbc');
 
-plan(2);
+plan(3);
 test_change_node_attributes();
 test_change_node_types();
+test_delete_nodes();
 
 sub incVals ($walker, $node) {
     my $v := $node.'value'();
@@ -66,11 +67,43 @@
 		      PAST::Val.new(:value(5)),
 		      PAST::Op.new(PAST::Val.new(:value(32)),
 				   :pirop<neg>));
-
     ok(pir::iseq__i_p_p($result, $target),
        "Node types can be changed by PAST::Transformers.")
 }
 
+sub trim ($walker, $node) {
+    my $result;
+    my $length := pir::elements__i_p($node);
+    if ($length <= 1) {
+	$result := $node;
+	my $children := PAST::Walker::walkChildren($walker, $node);
+	PAST::Walker::replaceChildren($result, $children);
+    }
+    else {
+	$result := null;
+    }
+    $result;
+}
+
+sub test_delete_nodes () {
+    my $past :=
+      PAST::Block.new(PAST::Stmts.new(PAST::Var.new(),
+				      PAST::Block.new(PAST::Val.new()),
+				      PAST::Block.new(PAST::Op.new(),
+						      PAST::VarList.new()),
+				      PAST::Block.new(PAST::Val.new(),
+						      PAST::Val.new(),
+						      PAST::Val.new())));
+    my $transformer := PAST::Transformer::Dynamic.new();
+    $transformer.'block'(trim);
+    my $result := $transformer.'walk'($past);
+    my $target :=
+      PAST::Block.new(PAST::Stmts.new(PAST::Var.new(),
+				      PAST::Block.new(PAST::Val.new())));
+    
+    ok(pir::iseq__i_p_p($result, $target),
+       "Nodes can be deleted by PAST::Transformers.");
+}
 
 # Local Variables:
 #   mode: cperl


More information about the parrot-commits mailing list