[pypy-svn] r10254 - in pypy/dist/pypy/translator: . genc/test
arigo at codespeak.net
arigo at codespeak.net
Sat Apr 2 19:20:39 CEST 2005
Author: arigo
Date: Sat Apr 2 19:20:39 2005
New Revision: 10254
Modified:
pypy/dist/pypy/translator/genc/test/test_ctrans.py
pypy/dist/pypy/translator/unsimplify.py
Log:
remove_direct_loops() still not right... Test and fix.
There is now a general-purpose insert_empty_block() function, as this seems
surprisingly difficult to get right.
Modified: pypy/dist/pypy/translator/genc/test/test_ctrans.py
==============================================================================
--- pypy/dist/pypy/translator/genc/test/test_ctrans.py (original)
+++ pypy/dist/pypy/translator/genc/test/test_ctrans.py Sat Apr 2 19:20:39 2005
@@ -205,14 +205,16 @@
def test_direct_loop(self):
# check that remove_direct_loops() does its job correctly
def direct_loop(n, m):
+ x = False
while 1:
o = n; n = m; m = o
n -= 10
if n < 0:
- return n
+ return n, x
+ x = True
fn = self.build_cfunc(direct_loop)
- assert fn(117, 114) == -6
- assert fn(117, 124) == -3
+ assert fn(117, 114) == (-6, True)
+ assert fn(117, 124) == (-3, True)
class TestAnnotatedTestCase:
Modified: pypy/dist/pypy/translator/unsimplify.py
==============================================================================
--- pypy/dist/pypy/translator/unsimplify.py (original)
+++ pypy/dist/pypy/translator/unsimplify.py Sat Apr 2 19:20:39 2005
@@ -11,6 +11,19 @@
newvar.type_cls = v.type_cls
return newvar
+def insert_empty_block(translator, link):
+ """Insert and return a new block along the given link."""
+ vars = uniqueitems([v for v in link.args if isinstance(v, Variable)])
+ mapping = {}
+ for v in vars:
+ mapping[v] = copyvar(translator, v)
+ newblock = Block(vars)
+ newblock.closeblock(Link(link.args, link.target))
+ newblock.renamevariables(mapping)
+ link.args[:] = vars
+ link.target = newblock
+ return newblock
+
def remove_direct_loops(translator, graph):
"""This is useful for code generators: it ensures that no link has
common input and output variables, which could occur if a block's exit
@@ -19,9 +32,5 @@
variables when generating a sequence of assignments."""
def visit(link):
if isinstance(link, Link) and link.prevblock is link.target:
- # insert an empty block with fresh variables.
- intermediate = [copyvar(translator, a) for a in link.args]
- b = Block(intermediate)
- b.closeblock(Link(intermediate, link.target))
- link.target = b
+ insert_empty_block(translator, link)
traverse(visit, graph)
More information about the Pypy-commit
mailing list