[pypy-svn] r50361 - in pypy/branch/astcompilertests/pypy/interpreter/astcompiler: . test
arigo at codespeak.net
arigo at codespeak.net
Sat Jan 5 21:18:27 CET 2008
Author: arigo
Date: Sat Jan 5 21:18:25 2008
New Revision: 50361
Modified:
pypy/branch/astcompilertests/pypy/interpreter/astcompiler/ast.py
pypy/branch/astcompilertests/pypy/interpreter/astcompiler/astgen.py
pypy/branch/astcompilertests/pypy/interpreter/astcompiler/opt.py
pypy/branch/astcompilertests/pypy/interpreter/astcompiler/test/test_ast.py
Log:
Finally figured out how I'm supposed to use mutate().
The trick is that the default() method of the visitors
is not doing the right thing at all in this case,
leading to completely bogus performance.
Modified: pypy/branch/astcompilertests/pypy/interpreter/astcompiler/ast.py
==============================================================================
--- pypy/branch/astcompilertests/pypy/interpreter/astcompiler/ast.py (original)
+++ pypy/branch/astcompilertests/pypy/interpreter/astcompiler/ast.py Sat Jan 5 21:18:25 2008
@@ -5915,9 +5915,12 @@
"""
def default(self, node):
+ """This method is only suitable for when we use accept(visitor),
+ not mutate(visitor). In the latter case it *must* be overridden
+ by the visitor, typically to just return an unmodified "node".
+ """
for child in node.getChildNodes():
child.accept(self)
- return node
def _mutate_list(self, lst):
i = 0
Modified: pypy/branch/astcompilertests/pypy/interpreter/astcompiler/astgen.py
==============================================================================
--- pypy/branch/astcompilertests/pypy/interpreter/astcompiler/astgen.py (original)
+++ pypy/branch/astcompilertests/pypy/interpreter/astcompiler/astgen.py Sat Jan 5 21:18:25 2008
@@ -596,9 +596,12 @@
"""
def default(self, node):
+ """This method is only suitable for when we use accept(visitor),
+ not mutate(visitor). In the latter case it *must* be overridden
+ by the visitor, typically to just return an unmodified "node".
+ """
for child in node.getChildNodes():
child.accept(self)
- return node
def _mutate_list(self, lst):
i = 0
Modified: pypy/branch/astcompilertests/pypy/interpreter/astcompiler/opt.py
==============================================================================
--- pypy/branch/astcompilertests/pypy/interpreter/astcompiler/opt.py (original)
+++ pypy/branch/astcompilertests/pypy/interpreter/astcompiler/opt.py Sat Jan 5 21:18:25 2008
@@ -84,6 +84,9 @@
def __init__(self, space):
self.space = space
+ def default(self, node):
+ return node
+
def _visitUnaryOp(self, node, constant_fold):
expr = node.expr
if isinstance(expr, ast.Const):
Modified: pypy/branch/astcompilertests/pypy/interpreter/astcompiler/test/test_ast.py
==============================================================================
--- pypy/branch/astcompilertests/pypy/interpreter/astcompiler/test/test_ast.py (original)
+++ pypy/branch/astcompilertests/pypy/interpreter/astcompiler/test/test_ast.py Sat Jan 5 21:18:25 2008
@@ -3,6 +3,8 @@
from pypy.interpreter.pyparser.test.test_astbuilder import FakeSpace
class BaseVisitor(ast.ASTVisitor):
+ def default(self, node):
+ return node
def visitAdd(self, node):
return ast.Const(3)
More information about the pypy-svn
mailing list