[pypy-svn] r33118 - in pypy/dist/pypy/translator/cli: . test

antocuni at codespeak.net antocuni at codespeak.net
Tue Oct 10 17:50:34 CEST 2006


Author: antocuni
Date: Tue Oct 10 17:50:33 2006
New Revision: 33118

Modified:
   pypy/dist/pypy/translator/cli/function.py
   pypy/dist/pypy/translator/cli/test/test_exception.py
Log:
(antocuni, arigo)

Only the last operation of the block must be checked against exceptions!



Modified: pypy/dist/pypy/translator/cli/function.py
==============================================================================
--- pypy/dist/pypy/translator/cli/function.py	(original)
+++ pypy/dist/pypy/translator/cli/function.py	Tue Oct 10 17:50:33 2006
@@ -82,13 +82,17 @@
             self.ilasm.label(self._get_block_name(block))
 
             handle_exc = (block.exitswitch == flowmodel.c_last_exception)
-            if handle_exc:
-                self.ilasm.begin_try()
 
-            for op in block.operations:
-                #self._search_for_classes(op)
+            # renders all ops but the last one
+            for op in block.operations[:-1]:
                 self._render_op(op)
 
+            # render the last one (if any!) and prepend a .try if it's needed
+            if block.operations:
+                if handle_exc:
+                    self.ilasm.begin_try()
+                self._render_op(block.operations[-1])
+
             if self._is_raise_block(block):
                 exc = block.inputargs[1]
                 self.load(exc)

Modified: pypy/dist/pypy/translator/cli/test/test_exception.py
==============================================================================
--- pypy/dist/pypy/translator/cli/test/test_exception.py	(original)
+++ pypy/dist/pypy/translator/cli/test/test_exception.py	Tue Oct 10 17:50:33 2006
@@ -19,3 +19,16 @@
                  raise
         
         self.interpret_raises(ValueError, fn, [0])
+
+    def test_exception_not_last(self):
+        def helper(x):
+            if x == 0:
+                raise ValueError
+        def fn(x):
+            helper(x)
+            try:
+                helper(1)
+            finally:
+                return -1
+            return x
+        self.interpret_raises(ValueError, fn, [0])



More information about the Pypy-commit mailing list