[svn:parrot] r47813 - in branches/gsoc_past_optimization: . config/gen/makefiles runtime/parrot/library/PAST runtime/parrot/library/PAST/Transformer

tcurtis at svn.parrot.org tcurtis at svn.parrot.org
Thu Jun 24 22:34:20 UTC 2010


Author: tcurtis
Date: Thu Jun 24 22:34:19 2010
New Revision: 47813
URL: https://trac.parrot.org/parrot/changeset/47813

Log:
Move PAST::Transformer and PAST::Transformer::Dynamic to NQP prepatory to refactor.

Added:
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer.nqp   (contents, props changed)
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer/Dynamic.nqp   (contents, props changed)
Deleted:
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer.pir
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer/Dynamic.pir
Modified:
   branches/gsoc_past_optimization/MANIFEST
   branches/gsoc_past_optimization/MANIFEST.SKIP
   branches/gsoc_past_optimization/config/gen/makefiles/root.in
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/   (props changed)
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer/   (props changed)

Modified: branches/gsoc_past_optimization/MANIFEST
==============================================================================
--- branches/gsoc_past_optimization/MANIFEST	Thu Jun 24 22:08:57 2010	(r47812)
+++ branches/gsoc_past_optimization/MANIFEST	Thu Jun 24 22:34:19 2010	(r47813)
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Thu Jun 24 05:13:34 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Thu Jun 24 22:30:16 2010 UT
 #
 # See below for documentation on the format of this file.
 #
@@ -1175,8 +1175,8 @@
 runtime/parrot/library/OpenGL/Math.pir                      [library]
 runtime/parrot/library/P6object.pir                         [library]
 runtime/parrot/library/PAST/Pattern.nqp                     [library]
-runtime/parrot/library/PAST/Transformer.pir                 [library]
-runtime/parrot/library/PAST/Transformer/Dynamic.pir         [library]
+runtime/parrot/library/PAST/Transformer.nqp                 [library]
+runtime/parrot/library/PAST/Transformer/Dynamic.nqp         [library]
 runtime/parrot/library/PAST/Walker.nqp                      [library]
 runtime/parrot/library/PAST/Walker/Dynamic.nqp              [library]
 runtime/parrot/library/PCT/Pattern.nqp                      [library]

Modified: branches/gsoc_past_optimization/MANIFEST.SKIP
==============================================================================
--- branches/gsoc_past_optimization/MANIFEST.SKIP	Thu Jun 24 22:08:57 2010	(r47812)
+++ branches/gsoc_past_optimization/MANIFEST.SKIP	Thu Jun 24 22:34:19 2010	(r47813)
@@ -1,6 +1,6 @@
 # ex: set ro:
 # $Id$
-# generated by tools/dev/mk_manifest_and_skip.pl Thu Jun 24 05:09:23 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Thu Jun 24 22:08:19 2010 UT
 #
 # This file should contain a transcript of the svn:ignore properties
 # of the directories in the Parrot subversion repository. (Needed for
@@ -595,11 +595,15 @@
 ^runtime/parrot/library/PAST/.*\.pbc/
 ^runtime/parrot/library/PAST/Pattern\.pir$
 ^runtime/parrot/library/PAST/Pattern\.pir/
+^runtime/parrot/library/PAST/Transformer\.pir$
+^runtime/parrot/library/PAST/Transformer\.pir/
 ^runtime/parrot/library/PAST/Walker\.pir$
 ^runtime/parrot/library/PAST/Walker\.pir/
 # generated from svn:ignore of 'runtime/parrot/library/PAST/Transformer/'
 ^runtime/parrot/library/PAST/Transformer/.*\.pbc$
 ^runtime/parrot/library/PAST/Transformer/.*\.pbc/
+^runtime/parrot/library/PAST/Transformer/Dynamic\.pir$
+^runtime/parrot/library/PAST/Transformer/Dynamic\.pir/
 # generated from svn:ignore of 'runtime/parrot/library/PAST/Walker/'
 ^runtime/parrot/library/PAST/Walker/.*\.pbc$
 ^runtime/parrot/library/PAST/Walker/.*\.pbc/

Modified: branches/gsoc_past_optimization/config/gen/makefiles/root.in
==============================================================================
--- branches/gsoc_past_optimization/config/gen/makefiles/root.in	Thu Jun 24 22:08:57 2010	(r47812)
+++ branches/gsoc_past_optimization/config/gen/makefiles/root.in	Thu Jun 24 22:34:19 2010	(r47813)
@@ -283,7 +283,9 @@
     $(LIBRARY_DIR)/PAST/Pattern.pbc \
     $(LIBRARY_DIR)/PAST/Pattern.pir \
     $(LIBRARY_DIR)/PAST/Transformer.pbc \
+    $(LIBRARY_DIR)/PAST/Transformer.pir \
     $(LIBRARY_DIR)/PAST/Transformer/Dynamic.pbc \
+    $(LIBRARY_DIR)/PAST/Transformer/Dynamic.pir \
     $(LIBRARY_DIR)/PAST/Walker.pbc \
     $(LIBRARY_DIR)/PAST/Walker.pir \
     $(LIBRARY_DIR)/PAST/Walker/Dynamic.pbc \
@@ -1107,6 +1109,20 @@
 $(LIBRARY_DIR)/PAST/Pattern.pir: $(LIBRARY_DIR)/PAST/Pattern.nqp $(NQP_RX)
 	$(NQP_RX) --target=pir $(LIBRARY_DIR)/PAST/Pattern.nqp > $@
 
+$(LIBRARY_DIR)/PAST/Transformer.pbc: $(LIBRARY_DIR)/PAST/Transformer.pir
+	$(PARROT) -o $@ $(LIBRARY_DIR)/PAST/Transformer.pir
+
+$(LIBRARY_DIR)/PAST/Transformer.pir: $(LIBRARY_DIR)/PAST/Transformer.nqp $(NQP_RX)
+	$(NQP_RX) --target=pir $(LIBRARY_DIR)/PAST/Transformer.nqp > $@
+
+$(LIBRARY_DIR)/PAST/Transformer/Dynamic.pbc: \
+	$(LIBRARY_DIR)/PAST/Transformer/Dynamic.pir
+	$(PARROT) -o $@ $(LIBRARY_DIR)/PAST/Transformer/Dynamic.pir
+
+$(LIBRARY_DIR)/PAST/Transformer/Dynamic.pir: \
+	$(LIBRARY_DIR)/PAST/Transformer/Dynamic.nqp $(NQP_RX)
+	$(NQP_RX) --target=pir $(LIBRARY_DIR)/PAST/Transformer/Dynamic.nqp > $@
+
 $(LIBRARY_DIR)/PAST/Walker.pbc: $(LIBRARY_DIR)/PAST/Walker.pir
 	$(PARROT) -o $@ $(LIBRARY_DIR)/PAST/Walker.pir
 

Added: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer.nqp
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer.nqp	Thu Jun 24 22:34:19 2010	(r47813)
@@ -0,0 +1,51 @@
+#!./parrot-nqp
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+INIT {
+    pir::load_bytecode('PAST/Walker.pbc');
+}
+
+class PAST::Transformer is PAST::Walker { }
+
+module PAST::Walker {
+    our multi sub walk (PAST::Transformer $walker, PAST::Node $node) {
+        my $result := $node;
+        replaceChildren($result, walkChildren($walker, $node));
+        $result;
+    }
+
+    our multi sub walkChildren (PAST::Transformer $walker,
+                                PAST::Node $node) {
+        my @results;
+        my $index := 0;
+        my $max := pir::elements__IP($node);
+        while ($index < $max) {
+            @results[$index] := walk($walker, $node[$index]);
+            $index++;
+        }
+        @results;
+    }
+    
+    our sub replaceChildren ($node, $newChildren) {
+        my $index := pir::elements__IP($node);
+        while ($index > 0) {
+            pir::pop__PP($node);
+            $index--;
+        }
+        my $max := pir::elements__IP($newChildren);
+        while ($index < $max) {
+            pir::push($node, $newChildren[$index])
+                if pir::defined__IP($newChildren[$index]);
+            $index++;
+        }
+        null;
+    }
+}
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Deleted: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer.pir
==============================================================================
--- branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer.pir	Thu Jun 24 22:34:19 2010	(r47812)
+++ /dev/null	00:00:00 1970	(deleted)
@@ -1,124 +0,0 @@
-# Copyright (C) 2010, Parrot Foundation.
-# $Id$
-
-=head1 NAME
-
-PAST::Transformer - A tool for traversing and modifying PAST::Nodes.
-
-=head1 DESCRIPTION
-
-A tool for traversing and modifying Parrot Abstract Syntax Trees.
-
-=cut
-
-.sub 'onload' :anon :init :load
-    load_bytecode 'PAST/Walker.pbc'
-    load_bytecode 'P6object.pbc'
-    .local pmc p6meta, base
-    p6meta = new 'P6metaclass'
-    base = get_class ['PAST'; 'Walker']
-    p6meta.'new_class'('PAST::Transformer', 'parent'=> base)
-.end
-
-.namespace ['PAST'; 'Walker']
-
-=head1 PAST::Transformer
-
-=head2 Multi-methods
-
-As a PAST::Walker subclass, PAST::Transformer's interface consists of two multi-methods in the PAST::Walker namespace, 'walk' and 'walkChildren'. It also declares the helper function PAST::Walker::replaceChildren. PAST::Transformer subclasses, unlike PAST::Walker subclasses, should return the desired node to replace the original node. If the original node should be unchanged, return it. If the node should be removed from its parent, return null.
-
-=over 4
-
-=item walk(walker, node)
-
-By default, 'walk' calls 'walkChildren', calls 'replaceChildren' with the node and the result, and returns the node with its children transformed.
-
-Subclasses should override this for specific PAST::Node subclasses in order to transform the node. Subclasses that wish to transform the node's children must remember to call 'walkChildren' and 'replaceChildren' in their specialization of the multi-method.
-
-=cut
-
-.sub 'walk' :multi(['PAST';'Transformer'], ['PAST';'Node'])
-    .param pmc walker
-    .param pmc node
-    .local pmc newChildren, result
-    result = node
-    newChildren = 'walkChildren'(walker, node)
-    'replaceChildren'(result, newChildren)
-    .return (result)
-.end
-
-=item walkChildren(walker, node)
-
-Iterates through the children of node, calling 'walk' with the walker and each child node. This should not generally be overridden.
-
-It returns an array of the results from the children. This should be supplied to 'replaceChildren'.
-
-=cut
-
-.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
-
-=back
-
-=head2 Helper functions
-
-=over 4
-
-=item replaceChildren(node, newChildren)
-
-Replaces the children of node with the nodes in newChildren. This should be called with the result node and the result of 'walkChildren' in speccializations of 'walk' that wish to transform the subtrees of a node.
-
-=cut
-
-.sub 'replaceChildren'
-    .param pmc node
-    .param pmc newChildren
-    .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
-    ge childIndex, max, end
-add_loop:
-    $P0 = newChildren[childIndex]
-    if null $P0 goto add_reloop
-    push node, $P0
-add_reloop:
-    inc childIndex
-    lt childIndex, max, add_loop
-end:
-    .return ()
-.end
-
-=back
-
-=cut
-
-# Local Variables:
-#   mode: pir
-#   fill-column: 100
-# End:
-# vim: expandtab shiftwidth=4 ft=pir:

Added: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer/Dynamic.nqp
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer/Dynamic.nqp	Thu Jun 24 22:34:19 2010	(r47813)
@@ -0,0 +1,106 @@
+#!./parrot-nqp
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+INIT {
+    pir::load_bytecode('PAST/Transformer.pbc');
+    pir::load_bytecode('PAST/Walker/Dynamic.pbc');
+}
+
+class PAST::Transformer::Dynamic is PAST::Transformer {
+    PAST::Transformer::Dynamic.HOW().add_parent(PAST::Transformer::Dynamic,
+                                                PAST::Walker::Dynamic);
+}
+
+module PAST::Walker {
+    our multi sub walk (PAST::Transformer::Dynamic $walker,
+                        PAST::Block $node) {
+        my $result;
+        my &fn := $walker.block();
+        if (pir::defined__IP(&fn)) {
+            $result := &fn($walker, $node);
+        }
+        else {
+            $result := $node;
+            replaceChildren($result, walkChildren($walker, $node));
+        }
+        $result;
+    }
+
+    our multi sub walk (PAST::Transformer::Dynamic $walker,
+                        PAST::Op $node) {
+        my $result;
+        my &fn := $walker.op();
+        if (pir::defined__IP(&fn)) {
+            $result := &fn($walker, $node);
+        }
+        else {
+            $result := $node;
+            replaceChildren($result, walkChildren($walker, $node));
+        }
+        $result;
+    }
+
+    our multi sub walk (PAST::Transformer::Dynamic $walker,
+                        PAST::Stmts $node) {
+        my $result;
+        my &fn := $walker.stmts();
+        if (pir::defined__IP(&fn)) {
+            $result := &fn($walker, $node);
+        }
+        else {
+            $result := $node;
+            replaceChildren($result, walkChildren($walker, $node));
+        }
+        $result;
+    }
+
+    our multi sub walk (PAST::Transformer::Dynamic $walker,
+                        PAST::Val $node) {
+        my $result;
+        my &fn := $walker.val();
+        if (pir::defined__IP(&fn)) {
+            $result := &fn($walker, $node);
+        }
+        else {
+            $result := $node;
+            replaceChildren($result, walkChildren($walker, $node));
+        }
+        $result;
+    }
+
+    our multi sub walk (PAST::Transformer::Dynamic $walker,
+                        PAST::Var $node) {
+        my $result;
+        my &fn := $walker.var();
+        if (pir::defined__IP(&fn)) {
+            $result := &fn($walker, $node);
+        }
+        else {
+            $result := $node;
+            replaceChildren($result, walkChildren($walker, $node));
+        }
+        $result;
+    }
+
+    our multi sub walk (PAST::Transformer::Dynamic $walker,
+                        PAST::VarList $node) {
+        my $result;
+        my &fn := $walker.varlist();
+        if (pir::defined__IP(&fn)) {
+            $result := &fn($walker, $node);
+        }
+        else {
+            $result := $node;
+            replaceChildren($result, walkChildren($walker, $node));
+        }
+        $result;
+    }
+}
+
+# Local Variables:
+#   mode: cperl
+#   cperl-indent-level: 4
+#   fill-column: 100
+# End:
+# vim: expandtab shiftwidth=4:

Deleted: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer/Dynamic.pir
==============================================================================
--- branches/gsoc_past_optimization/runtime/parrot/library/PAST/Transformer/Dynamic.pir	Thu Jun 24 22:34:19 2010	(r47812)
+++ /dev/null	00:00:00 1970	(deleted)
@@ -1,113 +0,0 @@
-# Copyright (C) 2010, Parrot Foundation.
-# $Id$
-
-=head1 NAME
-
-PAST::Transformer::Dynamic - A PAST::Transformer subclass that doesn't require creating a new subclass to change its behavior.
-
-=head1 DESCRIPTION
-
-PAST::Transformer's behavior can only be customized by subclassing. This subclass determines its behavior based on Subs stored in its attributes, allowing modification of its behavior without creating a new class, including at runtime.
-
-=cut
-
-.sub 'onload' :anon :init :load
-    load_bytecode 'PAST/Transformer.pbc'
-    load_bytecode 'PAST/Walker/Dynamic.pbc'
-    load_bytecode 'P6object.pbc'
-    .local pmc p6meta, walkdyn, trans
-    p6meta = new 'P6metaclass'
-    walkdyn = get_class ['PAST'; 'Walker'; 'Dynamic']
-    trans = get_class ['PAST'; 'Transformer']
-    $S0 = 'PAST::Transformer::Dynamic'
-    $P0 = p6meta.'new_class'($S0, 'parent'=> walkdyn)
-    p6meta.'add_parent'($P0, trans)
-.end
-
-=head1 PAST::Transformer::Dynamic
-
-It has the same attributes as PAST::Walker::Dynamic.
-
-They should behave just like specializations of 'walk' for PAST::Transformer subclasses, taking a walker and a PAST::Node and returning the replacement node or null to delete it.
-
-=cut
-
-.namespace ['PAST'; 'Walker']
-
-.sub 'walk' :multi(['PAST'; 'Transformer'; 'Dynamic'], ['PAST'; 'Block'])
-    .param pmc walker
-    .param pmc node
-    $P0 = getattribute walker, 'block'
-    unless null $P0 goto has_handler
-    $P1 = 'walkChildren'(walker, node)
-    'replaceChildren'(node, $P1)
-    .return (node)
-has_handler:
-    .tailcall $P0(walker, node)
-.end
-
-.sub 'walk' :multi(['PAST'; 'Transformer'; 'Dynamic'], ['PAST'; 'Op'])
-    .param pmc walker
-    .param pmc node
-    $P0 = getattribute walker, 'op'
-    unless null $P0 goto has_handler
-    $P1 = 'walkChildren'(walker, node)
-    'replaceChildren'(node, $P1)
-    .return (node)
-has_handler:
-    .tailcall $P0(walker, node)
-.end
-
-.sub 'walk' :multi(['PAST'; 'Transformer'; 'Dynamic'], ['PAST'; 'Stmts'])
-    .param pmc walker
-    .param pmc node
-    $P0 = getattribute walker, 'stmts'
-    unless null $P0 goto has_handler
-    $P1 = 'walkChildren'(walker, node)
-    'replaceChildren'(node, $P1)
-    .return (node)
-has_handler:
-    .tailcall $P0(walker, node)
-.end
-
-.sub 'walk' :multi(['PAST'; 'Transformer'; 'Dynamic'], ['PAST'; 'Val'])
-    .param pmc walker
-    .param pmc node
-    $P0 = getattribute walker, 'val'
-    unless null $P0 goto has_handler
-    $P1 = 'walkChildren'(walker, node)
-    'replaceChildren'(node, $P1)
-    .return (node)
-has_handler:
-    .tailcall $P0(walker, node)
-.end
-
-.sub 'walk' :multi(['PAST'; 'Transformer'; 'Dynamic'], ['PAST'; 'Var'])
-    .param pmc walker
-    .param pmc node
-    $P0 = getattribute walker, 'var'
-    unless null $P0 goto has_handler
-    $P1 = 'walkChildren'(walker, node)
-    'replaceChildren'(node, $P1)
-    .return (node)
-has_handler:
-    .tailcall $P0(walker, node)
-.end
-
-.sub 'walk' :multi(['PAST'; 'Transformer'; 'Dynamic'], ['PAST'; 'VarList'])
-    .param pmc walker
-    .param pmc node
-    $P0 = getattribute walker, 'varlist'
-    unless null $P0 goto has_handler
-    $P1 = 'walkChildren'(walker, node)
-    'replaceChildren'(node, $P1)
-    .return (node)
-has_handler:
-    .tailcall $P0(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