Author: allison
Date: Thu Apr 27 23:25:14 2006
New Revision: 12454

Modified:
   trunk/   (props changed)
   trunk/languages/punie/lib/Node.pir
   trunk/languages/punie/lib/past2post.tg
   trunk/languages/punie/lib/post2pir.tg

Log:
Punie: refactor out creation of iterators for node children.

Modified: trunk/languages/punie/lib/Node.pir
==============================================================================
--- trunk/languages/punie/lib/Node.pir  (original)
+++ trunk/languages/punie/lib/Node.pir  Thu Apr 27 23:25:14 2006
@@ -23,7 +23,7 @@
 .sub __init :method
     $P1 = new .Undef
     $P2 = new .Integer
-    $P3 = new .Undef
+    $P3 = new .ResizablePMCArray
 
     setattribute self, "source", $P1
     setattribute self, "pos", $P2
@@ -145,13 +145,11 @@
     # print children for this node
     print indent
     print "'children' => ["
-    $P3 = getattribute self, "children"
-    $I0 = defined $P3
-    unless $I0 goto no_children
-    print "\n"
     .local pmc iter
-    iter = new Iterator, $P3 # loop over the array
-    iter = 0 # start at the beginning
+    iter = self.'child_iter'()
+    unless iter goto no_children
+    print "\n"
+
   loop_start:
     unless iter goto loop_end
     $P1 = shift iter
@@ -177,3 +175,16 @@
     push children, child
     .return()
 .end
+
+=head2 child_iter
+
+Return an iterator for the children of a node.
+
+=cut
+
+.sub 'child_iter' :method
+    $P1 = getattribute self, "children"
+    $P2 = new Iterator, $P1    # setup iterator for node
+    $P2 = 0
+    .return($P2)
+.end

Modified: trunk/languages/punie/lib/past2post.tg
==============================================================================
--- trunk/languages/punie/lib/past2post.tg      (original)
+++ trunk/languages/punie/lib/past2post.tg      Thu Apr 27 23:25:14 2006
@@ -3,10 +3,8 @@
     result = new 'POST::Sub'
     result.'clone_node'(node)
 
-    $P1 = node.children()
     .local pmc iter
-    iter = new Iterator, $P1    # setup iterator for node
-    iter = 0
+    iter = node.'child_iter'()
   iter_loop:
     unless iter, iter_end         # while (entries) ...
       shift $P2, iter
@@ -23,10 +21,8 @@
     result = new 'POST::Ops'
     result.'clone_node'(node)
 
-    $P1 = node.children()
     .local pmc iter
-    iter = new Iterator, $P1    # setup iterator for node
-    iter = 0
+    iter = node.'child_iter'()
   iter_loop:
     unless iter, iter_end         # while (entries) ...
       shift $P2, iter
@@ -92,10 +88,8 @@
     # Create a node to contain the generated ops.
     .local pmc newops
     newops = new 'POST::Ops'
-    $P1 = node.children()
     .local pmc iter
-    iter = new Iterator, $P1    # setup iterator for node
-    iter = 0
+    iter = node.'child_iter'()
   iter_loop:
     unless iter, iter_end         # while (entries) ...
       shift $P2, iter
@@ -164,10 +158,8 @@
     # Add the temporary variable as the destination register of the op
     childop.'add_child'(temp_var)
 
-    $P1 = node.children()
     .local pmc iter
-    iter = new Iterator, $P1    # setup iterator for node
-    iter = 0
+    iter = node.'child_iter'()
   iter_loop:
     unless iter, iter_end         # while (entries) ...
       shift $P2, iter
@@ -223,10 +215,8 @@
     childop.'op'(opname)
 
     # Set up to handle children of Op node.
-    $P1 = node.children()
     .local pmc iter
-    iter = new Iterator, $P1    # setup iterator for node
-    iter = 0
+    iter = node.'child_iter'()
 
     # First, handle the condition, which may be a series of statements
     # resulting in a single value.
@@ -309,7 +299,7 @@
     unless $S3 == 'PAST::Op' goto no_munge
       $S4 = $P4.op()
     unless $S4 == 'O_COMMA' goto no_munge
-      $P1 = $P4.children()
+      $P1 = $P4.'child_iter'()
   no_munge:
      # Done collapsing comma ops
 
@@ -325,10 +315,10 @@
     # Iterate through the children of the node, and generate the result
     # for each child.
     .local pmc iter
-    iter = new Iterator, $P1    # setup iterator for node
+    iter = new Iterator, $P1
     iter = 0
   iter_loop:
-    unless iter, iter_end         # while (entries) ...
+    unless iter goto iter_end         # while (entries) ...
       shift $P2, iter
       $P3 = tree.get('result', $P2)
       $S1 = typeof $P3

Modified: trunk/languages/punie/lib/post2pir.tg
==============================================================================
--- trunk/languages/punie/lib/post2pir.tg       (original)
+++ trunk/languages/punie/lib/post2pir.tg       Thu Apr 27 23:25:14 2006
@@ -4,10 +4,8 @@
 ROOT: result(.) = {
     .local string output
     output = ".sub _main :main\n"
-    $P1 = node.children()
     .local pmc iter
-    iter = new Iterator, $P1    # setup iterator for node
-    iter = 0
+    iter = node.'child_iter'()
   iter_loop:
     unless iter, iter_end         # while (entries) ...
       shift $P2, iter
@@ -22,10 +20,8 @@
 # Flatten out the ops into a simple sequence.
 POST::Ops: result(.) = {
     .local string output
-    $P1 = node.children()
     .local pmc iter
-    iter = new Iterator, $P1    # setup iterator for node
-    iter = 0
+    iter = node.'child_iter'()
   iter_loop:
     unless iter, iter_end         # while (entries) ...
       shift $P2, iter
@@ -44,10 +40,8 @@
     opname = node.op()
     output = "    " . opname
     output .= " "
-    $P1 = node.children()
     .local pmc iter
-    iter = new Iterator, $P1    # setup iterator for node
-    iter = 0
+    iter = node.'child_iter'()
   iter_loop:
     unless iter goto iter_end         # while (entries) ...
       shift $P2, iter

Reply via email to