[pypy-svn] r28506 - in pypy/dist/pypy/translator/stackless: . test

mwh at codespeak.net mwh at codespeak.net
Thu Jun 8 12:29:01 CEST 2006


Author: mwh
Date: Thu Jun  8 12:29:00 2006
New Revision: 28506

Modified:
   pypy/dist/pypy/translator/stackless/test/test_resume_point.py
   pypy/dist/pypy/translator/stackless/transform.py
Log:
(mwh, pedronis)
GAR!  fix the bug in insert_unwind_handling again, in handle_resume_point.
also, an exploding skipped test.


Modified: pypy/dist/pypy/translator/stackless/test/test_resume_point.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/test/test_resume_point.py	(original)
+++ pypy/dist/pypy/translator/stackless/test/test_resume_point.py	Thu Jun  8 12:29:00 2006
@@ -222,3 +222,41 @@
     res = run_stackless_function(example)
     assert res == 141
     
+
+def test_finally():
+    def f(x):
+        rstack.resume_point("rp1", x)        
+        return 1/x
+    def in_finally(x): 
+        rstack.resume_point("rp1.5", x)
+        return 2/x
+    def g(x):
+        r = y = 0
+        r += f(x)
+        try:
+            y = f(x)
+            rstack.resume_point("rp0", x, r, returns=y)
+        finally:
+            r += in_finally(x)
+        return r + y
+    def example():
+        return g(one())
+    transform_stackless_function(example)
+
+def test_except():
+    py.test.skip('in-progress')
+    def f(x):
+        rstack.resume_point("rp1", x)        
+        return 1/x
+    def g(x):
+        r = y = 0
+        r += f(x)
+        try:
+            y = f(x)
+            rstack.resume_point("rp0", x, r, returns=y)
+        except ZeroDivisionError:
+            r += f(x)
+        return r + y
+    def example():
+        return g(one())
+    transform_stackless_function(example)

Modified: pypy/dist/pypy/translator/stackless/transform.py
==============================================================================
--- pypy/dist/pypy/translator/stackless/transform.py	(original)
+++ pypy/dist/pypy/translator/stackless/transform.py	Thu Jun  8 12:29:00 2006
@@ -504,9 +504,11 @@
         op = block.operations[i]
         if i == len(block.operations) - 1:
             link = block.exits[0]
+            nextblock = None
         else:
             link = support.split_block_with_keepalive(block, i+1)
             i = 0
+            nextblock = link.target
         parms = op.args[1:]
         if not isinstance(parms[0], model.Variable):
             assert parms[0].value is None
@@ -547,7 +549,7 @@
             symb = SymbolicRestartNumber(label, restart_number)
             self.symbolic_restart_numbers[label] = symb
 
-        return link.target, i
+        return nextblock
 
     def handle_resume_state_create(self, block, i):
         op = block.operations[i]
@@ -724,9 +726,13 @@
             if (op.opname in ('direct_call', 'indirect_call')
                 or self.analyzer.operation_is_true(op)):
                 if op.opname == 'resume_point':
-                    block, i = self.handle_resume_point(block, i)
-                    continue
-                
+                    block = self.handle_resume_point(block, i)
+                    if block is None:
+                        return
+                    else:
+                        i = 0
+                        continue
+
                 # trap calls to stackless-related suggested primitives
                 if op.opname == 'direct_call':
                     func = getattr(op.args[0].value._obj, '_callable', None)



More information about the Pypy-commit mailing list