[pypy-svn] r21178 - in pypy/dist/pypy: rpython translator/backendopt/test

cfbolz at codespeak.net cfbolz at codespeak.net
Thu Dec 15 15:41:18 CET 2005


Author: cfbolz
Date: Thu Dec 15 15:41:16 2005
New Revision: 21178

Modified:
   pypy/dist/pypy/rpython/llinterp.py
   pypy/dist/pypy/translator/backendopt/test/test_merge_if_blocks.py
Log:
fixes to llinterp to be able to cope with the switches. make the tests use
llinterp


Modified: pypy/dist/pypy/rpython/llinterp.py
==============================================================================
--- pypy/dist/pypy/rpython/llinterp.py	(original)
+++ pypy/dist/pypy/rpython/llinterp.py	Thu Dec 15 15:41:16 2005
@@ -213,8 +213,12 @@
                 if link.llexitcase == llexitvalue:
                     break   # found -- the result is in 'link'
             else:
-                raise ValueError("exit case %r not found in the exit links "
-                                 "of %r" % (llexitvalue, block))
+                if block.exits[-1].exitcase == "default":
+                    assert block.exits[-1].llexitcase is None
+                    link = block.exits[-1]
+                else:
+                    raise ValueError("exit case %r not found in the exit links "
+                                     "of %r" % (llexitvalue, block))
         return link.target, [self.getval(x) for x in link.args]
 
     def eval_operation(self, operation):

Modified: pypy/dist/pypy/translator/backendopt/test/test_merge_if_blocks.py
==============================================================================
--- pypy/dist/pypy/translator/backendopt/test/test_merge_if_blocks.py	(original)
+++ pypy/dist/pypy/translator/backendopt/test/test_merge_if_blocks.py	Thu Dec 15 15:41:16 2005
@@ -2,6 +2,7 @@
 from pypy.translator.translator import TranslationContext, graphof as tgraphof
 from pypy.objspace.flow.model import flatten, Block
 from pypy.translator.backendopt.removenoops import remove_same_as
+from pypy.rpython.llinterp import LLInterpreter
 
 def test_merge1():
     def merge1(n):
@@ -24,6 +25,10 @@
     merge_if_blocks_once(graph)
     assert len(graph.startblock.exits) == 4
     assert len(list(graph.iterblocks())) == 2 #startblock, returnblock
+    interp = LLInterpreter(rtyper)
+    for i in range(4):
+        res = interp.eval_graph(graph, [i])
+        assert res == i + 1
 
 def test_merge_passonvars():
     def merge(n, m):
@@ -44,6 +49,10 @@
     remove_same_as(graph)
     merge_if_blocks_once(graph)
     assert len(graph.startblock.exits) == 4
+    interp = LLInterpreter(rtyper)
+    for i in range(1, 5):
+        res = interp.eval_graph(graph, [i, 1])
+        assert res == i + 1
 
 def test_merge_several():
     def merge(n, m):
@@ -70,6 +79,16 @@
     merge_if_blocks(graph)
     assert len(graph.startblock.exits) == 3
     assert len(list(graph.iterblocks())) == 3
+    interp = LLInterpreter(rtyper)
+    for m in range(3):
+        res = interp.eval_graph(graph, [0, m])
+        assert res == m
+    res = interp.eval_graph(graph, [1, 0])
+    assert res == 4
+    res = interp.eval_graph(graph, [2, 0])
+    assert res == 6
+
+
 
 def test_dont_merge():
     def merge(n, m):
@@ -91,3 +110,4 @@
     blocknum = len(list(graph.iterblocks()))
     merge_if_blocks(graph)
     assert blocknum == len(list(graph.iterblocks()))
+



More information about the Pypy-commit mailing list