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

tcurtis at svn.parrot.org tcurtis at svn.parrot.org
Thu Jun 24 05:41:09 UTC 2010


Author: tcurtis
Date: Thu Jun 24 05:41:08 2010
New Revision: 47798
URL: https://trac.parrot.org/parrot/changeset/47798

Log:
Rewrite PAST::Walker and PAST::Walker::Dynamic in NQP. Preparing for refactor.

Added:
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Walker.nqp   (contents, props changed)
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Walker/Dynamic.nqp   (contents, props changed)
Deleted:
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Walker.pir
   branches/gsoc_past_optimization/runtime/parrot/library/PAST/Walker/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/Walker/   (props changed)

Modified: branches/gsoc_past_optimization/MANIFEST
==============================================================================
--- branches/gsoc_past_optimization/MANIFEST	Thu Jun 24 05:27:53 2010	(r47797)
+++ branches/gsoc_past_optimization/MANIFEST	Thu Jun 24 05:41:08 2010	(r47798)
@@ -1,7 +1,7 @@
 # ex: set ro:
 # $Id$
 #
-# generated by tools/dev/mk_manifest_and_skip.pl Wed Jun 23 23:41:33 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Thu Jun 24 05:13:34 2010 UT
 #
 # See below for documentation on the format of this file.
 #
@@ -1177,8 +1177,8 @@
 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/Walker.pir                      [library]
-runtime/parrot/library/PAST/Walker/Dynamic.pir              [library]
+runtime/parrot/library/PAST/Walker.nqp                      [library]
+runtime/parrot/library/PAST/Walker/Dynamic.nqp              [library]
 runtime/parrot/library/PCT/Pattern.nqp                      [library]
 runtime/parrot/library/PCT/README                           []doc
 runtime/parrot/library/PGE/Dumper.pir                       [library]

Modified: branches/gsoc_past_optimization/MANIFEST.SKIP
==============================================================================
--- branches/gsoc_past_optimization/MANIFEST.SKIP	Thu Jun 24 05:27:53 2010	(r47797)
+++ branches/gsoc_past_optimization/MANIFEST.SKIP	Thu Jun 24 05:41:08 2010	(r47798)
@@ -1,6 +1,6 @@
 # ex: set ro:
 # $Id$
-# generated by tools/dev/mk_manifest_and_skip.pl Wed Jun 23 23:42:18 2010 UT
+# generated by tools/dev/mk_manifest_and_skip.pl Thu Jun 24 05:09:23 2010 UT
 #
 # This file should contain a transcript of the svn:ignore properties
 # of the directories in the Parrot subversion repository. (Needed for
@@ -595,12 +595,16 @@
 ^runtime/parrot/library/PAST/.*\.pbc/
 ^runtime/parrot/library/PAST/Pattern\.pir$
 ^runtime/parrot/library/PAST/Pattern\.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/
 # generated from svn:ignore of 'runtime/parrot/library/PAST/Walker/'
 ^runtime/parrot/library/PAST/Walker/.*\.pbc$
 ^runtime/parrot/library/PAST/Walker/.*\.pbc/
+^runtime/parrot/library/PAST/Walker/Dynamic\.pir$
+^runtime/parrot/library/PAST/Walker/Dynamic\.pir/
 # generated from svn:ignore of 'runtime/parrot/library/PCT/'
 ^runtime/parrot/library/PCT/.*\.pbc$
 ^runtime/parrot/library/PCT/.*\.pbc/

Modified: branches/gsoc_past_optimization/config/gen/makefiles/root.in
==============================================================================
--- branches/gsoc_past_optimization/config/gen/makefiles/root.in	Thu Jun 24 05:27:53 2010	(r47797)
+++ branches/gsoc_past_optimization/config/gen/makefiles/root.in	Thu Jun 24 05:41:08 2010	(r47798)
@@ -285,7 +285,9 @@
     $(LIBRARY_DIR)/PAST/Transformer.pbc \
     $(LIBRARY_DIR)/PAST/Transformer/Dynamic.pbc \
     $(LIBRARY_DIR)/PAST/Walker.pbc \
+    $(LIBRARY_DIR)/PAST/Walker.pir \
     $(LIBRARY_DIR)/PAST/Walker/Dynamic.pbc \
+    $(LIBRARY_DIR)/PAST/Walker/Dynamic.pir \
     $(LIBRARY_DIR)/PCT/Pattern.pbc \
     $(LIBRARY_DIR)/PCT/Pattern.pir \
     $(LIBRARY_DIR)/POST/Pattern.pbc \
@@ -1105,6 +1107,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/Walker.pbc: $(LIBRARY_DIR)/PAST/Walker.pir
+	$(PARROT) -o $@ $(LIBRARY_DIR)/PAST/Walker.pir
+
+$(LIBRARY_DIR)/PAST/Walker.pir: $(LIBRARY_DIR)/PAST/Walker.nqp $(NQP_RX)
+	$(NQP_RX) --target=pir $(LIBRARY_DIR)/PAST/Walker.nqp > $@
+
+$(LIBRARY_DIR)/PAST/Walker/Dynamic.pbc: \
+	$(LIBRARY_DIR)/PAST/Walker/Dynamic.pir
+	$(PARROT) -o $@ $(LIBRARY_DIR)/PAST/Walker/Dynamic.pir
+
+$(LIBRARY_DIR)/PAST/Walker/Dynamic.pir: \
+	$(LIBRARY_DIR)/PAST/Walker/Dynamic.nqp $(NQP_RX)
+	$(NQP_RX) --target=pir $(LIBRARY_DIR)/PAST/Walker/Dynamic.nqp > $@
+
 $(LIBRARY_DIR)/PCT/Pattern.pbc: $(LIBRARY_DIR)/PCT/Pattern.pir
 	$(PARROT) -o $@ $(LIBRARY_DIR)/PCT/Pattern.pir
 

Added: branches/gsoc_past_optimization/runtime/parrot/library/PAST/Walker.nqp
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Walker.nqp	Thu Jun 24 05:41:08 2010	(r47798)
@@ -0,0 +1,40 @@
+#!./parrot-nqp
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+INIT {
+    pir::load_bytecode('PCT.pbc');
+}
+
+class PAST::Walker {
+    our multi sub walk (PAST::Walker $walker, PAST::Node $node) {
+        walkChildren($walker, $node);
+    }
+
+    our multi sub walk (PAST::Walker $walker, $node) {
+        $node;
+    }
+
+    our multi sub walkChildren (PAST::Walker $walker, PAST::Node $node) {
+        my $index := 0;
+        my $max := pir::elements__IP($node);
+        while ($index < $max) {
+            walk($walker, $node[$index++]);
+        }
+    }
+
+    method walk ($node) {
+        walk(self, $node);
+    }
+
+    method walkChildren ($node) {
+        walkChildren(self, $node);
+    }
+}
+
+# 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/Walker.pir
==============================================================================
--- branches/gsoc_past_optimization/runtime/parrot/library/PAST/Walker.pir	Thu Jun 24 05:41:08 2010	(r47797)
+++ /dev/null	00:00:00 1970	(deleted)
@@ -1,112 +0,0 @@
-# Copyright (C) 2010, Parrot Foundation.
-# $Id$
-
-=head1 NAME
-
-PAST::Walker - A tool for traversing PAST::Nodes.
-
-=head1 DESCRIPTION
-
-A tool for traversing Parrot Abstract Syntax Trees.
-
-=cut
-
-.sub 'onload' :anon :init :load
-    load_bytecode 'P6object.pbc'
-    .local pmc p6meta
-    p6meta = new 'P6metaclass'
-    p6meta.'new_class'('PAST::Walker')
-.end
-
-.namespace ['PAST'; 'Walker']
-
-=head1 PAST::Walker
-
-=head2 Multi-methods
-
-The PAST::Walker interface is specified by a pair of multi-methods. Each of these takes a PAST::Walker and a PAST::Node. In addition, there are PAST::Walker methods of the same name as each multi-method that take a PAST::Node argument and call the appropriate multi-method with the invocant and the argument.
-
-=over 4
-
-=item walk(walker, node)
-
-By default, 'walk' simply calls 'walkChildren'.
-
-Subclasses should override this for specific PAST::Node subclasses in order to perform useful actions on the node. Subclasses that wish to traverse on the node's children must remember to call 'walkChildren' in their specialization of the multi-method.
-
-=cut
-
-.sub 'walk' :multi(['PAST';'Walker'], ['PAST';'Node'])
-    .param pmc walker
-    .param pmc node
-    .tailcall 'walkChildren'(walker, node)
-.end
-
-.sub 'walk' :multi(['PAST';'Walker'], _)
-    .param pmc walker
-    .param pmc node
-    .return  (node)
-.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.
-
-=cut
-
-.sub 'walkChildren' :multi(_, ['PAST';'Node'])
-    .param pmc walker
-    .param pmc node
-    .local int max, curr
-    .local pmc child
-    max = elements node
-    curr = 0
-
-loop:
-    ge curr, max, end
-    child = node[curr]
-    'walk'(walker, child)
-    inc curr
-    branch loop
-end:
-.end
-
-=back
-
-=head2 Convenience methods
-
-Convenience methods on PAST::Walker objects are provided to make traversing PASTs more convenient in code outside of the PAST::Walker namespace.
-
-=over 4
-
-=item walk(node)
-
-walker->walk(node) is equivalent to PAST::Walker::walk(walker, node).
-
-=cut
-
-.sub 'walk' :method
-    .param pmc node
-    .tailcall 'walk'(self, node)
-.end
-
-=item walkChildren(node)
-
-walker->walkChildren(node) is equivalent to PAST::Walker::walkChildren(walker, node).
-
-=cut
-
-.sub 'walkChildren' :method
-    .param pmc node
-    .tailcall 'walkChildren'(self, node)
-.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/Walker/Dynamic.nqp
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ branches/gsoc_past_optimization/runtime/parrot/library/PAST/Walker/Dynamic.nqp	Thu Jun 24 05:41:08 2010	(r47798)
@@ -0,0 +1,104 @@
+#!./parrot-nqp
+# Copyright (C) 2010, Parrot Foundation.
+# $Id$
+
+INIT {
+    pir::load_bytecode('PAST/Walker.pbc');
+}
+
+my sub gen_accessor ($class, $meth, $attr) {
+    $class.HOW().add_method($class, $meth, 
+                             method ($val?) {
+                                 my $result;
+                                 if (pir::defined__IP($val)) {
+                                     pir::setattribute(self, ~$attr, $val);
+                                 }
+                                 else {
+                                     $result := 
+                                       pir::getattribute__PPS(self, $attr);
+                                 }
+                                 $result;
+                             });
+}
+
+class PAST::Walker::Dynamic is PAST::Walker {
+    has $block;
+    has $op;
+    has $stmts;
+    has $val;
+    has $var;
+    has $varlist;
+
+    for (<block op stmts val var varlist>) {
+        gen_accessor(PAST::Walker::Dynamic, $_, "\$" ~ $_);
+    }
+}
+
+module PAST::Walker {
+    our multi sub walk (PAST::Walker::Dynamic $walker, PAST::Block $node) {
+        my &fn := $walker.block();
+        if &fn {
+            &fn($walker, $node);
+        }
+        else {
+            walkChildren($walker, $node);
+        }
+    }
+
+    our multi sub walk (PAST::Walker::Dynamic $walker, PAST::Op $node) {
+        my &fn := $walker.op();
+        if &fn {
+            &fn($walker, $node);
+        }
+        else {
+            walkChildren($walker, $node);
+        }
+    }
+
+    our multi sub walk (PAST::Walker::Dynamic $walker, PAST::Stmts $node) {
+        my &fn := $walker.stmts();
+        if &fn {
+            &fn($walker, $node);
+        }
+        else {
+            walkChildren($walker, $node);
+        }
+    }
+
+    our multi sub walk (PAST::Walker::Dynamic $walker, PAST::Val $node) {
+        my &fn := $walker.val();
+        if &fn {
+            &fn($walker, $node);
+        }
+        else {
+            walkChildren($walker, $node);
+        }
+    }
+
+    our multi sub walk (PAST::Walker::Dynamic $walker, PAST::Var $node) {
+        my &fn := $walker.var();
+        if &fn {
+            &fn($walker, $node);
+        }
+        else {
+            walkChildren($walker, $node);
+        }
+    }
+
+    our multi sub walk (PAST::Walker::Dynamic $walker, PAST::VarList $node) {
+        my &fn := $walker.varlist();
+        if &fn {
+            &fn($walker, $node);
+        }
+        else {
+            walkChildren($walker, $node);
+        }
+    }
+}
+
+# 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/Walker/Dynamic.pir
==============================================================================
--- branches/gsoc_past_optimization/runtime/parrot/library/PAST/Walker/Dynamic.pir	Thu Jun 24 05:41:08 2010	(r47797)
+++ /dev/null	00:00:00 1970	(deleted)
@@ -1,206 +0,0 @@
-# Copyright (C) 2010, Parrot Foundation.
-# $Id$
-
-=head1 NAME
-
-PAST::Walker::Dynamic - A PAST::Walker subclass that doesn't require creating a new subclass to change its behavior.
-
-=head1 DESCRIPTION
-
-PAST::Walker'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/Walker.pbc'
-    load_bytecode 'P6object.pbc'
-    .local pmc p6meta, base
-    .local string name, attrs
-    p6meta = new 'P6metaclass'
-    base = get_class ['PAST'; 'Walker']
-    name = 'PAST::Walker::Dynamic'
-    attrs = 'block op stmts val var varlist'
-    p6meta.'new_class'(name, 'parent'=>base, 'attr'=>attrs)
-.end
-
-.namespace ['PAST'; 'Walker'; 'Dynamic']
-
-=head1 PAST::Walker::Dynamic
-
-=head2 Attribute accessors
-
-Each attribute should hold a sub that takes a walker and a PAST::Node.
-
-It will be called when the appropriate node type is traversed.
-
-As with PAST::Walker, the sub must explicitly call 'walkChildren' in order to traverse the children.
-
-=over 4
-
-=item block([sub])
-
-Gets/sets the sub to be called when traversing a PAST::Block node.
-
-=cut
-
-.sub 'block' :method
-    .param pmc value :optional
-    .param int has_value :opt_flag
-    if has_value goto setter
-    $P0 = getattribute self, 'block'
-    .return ($P0)
-setter:
-    setattribute self, 'block', value
-.end
-
-=item op([sub])
-
-Gets/sets the sub to be called when traversing a PAST::Op node.
-
-=cut
-
-.sub 'op' :method
-    .param pmc value :optional
-    .param int has_value :opt_flag
-    if has_value goto setter
-    $P0 = getattribute self, 'op'
-    .return ($P0)
-setter:
-    setattribute self, 'op', value
-.end
-
-=item stmts([sub])
-
-Gets/sets the sub to be called when traversing a PAST::Stmts node.
-
-=cut
-
-.sub 'stmts' :method
-    .param pmc value :optional
-    .param int has_value :opt_flag
-    if has_value goto setter
-    $P0 = getattribute self, 'stmts'
-    .return ($P0)
-setter:
-    setattribute self, 'stmts', value
-.end
-
-=item val([sub])
-
-Gets/sets the sub to be called when traversing a PAST::Val node.
-
-=cut
-
-.sub 'val' :method
-    .param pmc value :optional
-    .param int has_value :opt_flag
-    if has_value goto setter
-    $P0 = getattribute self, 'val'
-    .return ($P0)
-setter:
-    setattribute self, 'val', value
-.end
-
-=item var([sub])
-
-Gets/sets the sub to be called when traversing a PAST::Var node.
-
-=cut
-
-.sub 'var' :method
-    .param pmc value :optional
-    .param int has_value :opt_flag
-    if has_value goto setter
-    $P0 = getattribute self, 'var'
-    .return ($P0)
-setter:
-    setattribute self, 'var', value
-.end
-
-=item varlist([sub])
-
-Gets/sets the sub to be called when traversing a PAST::VarList node.
-
-=cut
-
-.sub 'varlist' :method
-    .param pmc value :optional
-    .param int has_value :opt_flag
-    if has_value goto setter
-    $P0 = getattribute self, 'varlist'
-    .return ($P0)
-setter:
-    setattribute self, 'varlist', value
-.end
-
-.namespace ['PAST'; 'Walker']
-
-.sub 'walk' :multi(['PAST'; 'Walker'; 'Dynamic'], ['PAST'; 'Block'])
-    .param pmc walker
-    .param pmc node
-    $P0 = getattribute walker, 'block'
-    unless null $P0 goto has_handler
-    .tailcall 'walkChildren'(walker, node)
-has_handler:
-    .tailcall $P0(walker, node)
-.end
-
-.sub 'walk' :multi(['PAST'; 'Walker'; 'Dynamic'], ['PAST'; 'Op'])
-    .param pmc walker
-    .param pmc node
-    $P0 = getattribute walker, 'op'
-    unless null $P0 goto has_handler
-    .tailcall 'walkChildren'(walker, node)
-has_handler:
-    .tailcall $P0(walker, node)
-.end
-
-.sub 'walk' :multi(['PAST'; 'Walker'; 'Dynamic'], ['PAST'; 'Stmts'])
-    .param pmc walker
-    .param pmc node
-    $P0 = getattribute walker, 'stmts'
-    unless null $P0 goto has_handler
-    .tailcall 'walkChildren'(walker, node)
-has_handler:
-    .tailcall $P0(walker, node)
-.end
-
-.sub 'walk' :multi(['PAST'; 'Walker'; 'Dynamic'], ['PAST'; 'Val'])
-    .param pmc walker
-    .param pmc node
-    $P0 = getattribute walker, 'val'
-    unless null $P0 goto has_handler
-    .tailcall 'walkChildren'(walker, node)
-has_handler:
-    .tailcall $P0(walker, node)
-.end
-
-.sub 'walk' :multi(['PAST'; 'Walker'; 'Dynamic'], ['PAST'; 'Var'])
-    .param pmc walker
-    .param pmc node
-    $P0 = getattribute walker, 'var'
-    unless null $P0 goto has_handler
-    .tailcall 'walkChildren'(walker, node)
-has_handler:
-    .tailcall $P0(walker, node)
-.end
-
-.sub 'walk' :multi(['PAST'; 'Walker'; 'Dynamic'], ['PAST'; 'VarList'])
-    .param pmc walker
-    .param pmc node
-    $P0 = getattribute walker, 'varlist'
-    unless null $P0 goto has_handler
-    .tailcall 'walkChildren'(walker, node)
-has_handler:
-    .tailcall $P0(walker, node)
-.end
-
-=back
-
-=cut
-
-# Local Variables:
-#   mode: pir
-#   fill-column: 100
-# End:
-# vim: expandtab shiftwidth=4 ft=pir:


More information about the parrot-commits mailing list