[pypy-commit] pypy translation-cleanup: Clarify logic of FSFrame.END_FINALLY

rlamy noreply at buildbot.pypy.org
Mon Sep 24 22:35:55 CEST 2012


Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57521:3bfdd3313aaf
Date: 2012-09-24 21:35 +0100
http://bitbucket.org/pypy/pypy/changeset/3bfdd3313aaf/

Log:	Clarify logic of FSFrame.END_FINALLY

diff --git a/pypy/objspace/flow/flowcontext.py b/pypy/objspace/flow/flowcontext.py
--- a/pypy/objspace/flow/flowcontext.py
+++ b/pypy/objspace/flow/flowcontext.py
@@ -527,27 +527,31 @@
         # item (unlike CPython which can have 1, 2 or 3 items):
         #   [wrapped subclass of SuspendedUnroller]
         w_top = self.popvalue()
-        # the following logic is a mess for the flow objspace,
-        # so we hide it specially in the space :-/
-        if self.space._check_constant_interp_w_or_w_None(SuspendedUnroller, w_top):
-            # case of a finally: block
-            unroller = self.space.interpclass_w(w_top)
+        if w_top == self.space.w_None:
+            # finally: block with no unroller active
+            return
+        try:
+            unroller = self.space.unwrap(w_top)
+        except UnwrapException:
+            pass
         else:
-            # case of an except: block.  We popped the exception type
-            self.popvalue()        #     Now we pop the exception value
-            unroller = self.space.interpclass_w(self.popvalue())
-            assert unroller is not None
+            if isinstance(unroller, SuspendedUnroller):
+                # case of a finally: block
+                return self.unroll_finally(unroller)
+        # case of an except: block.  We popped the exception type
+        self.popvalue()        #     Now we pop the exception value
+        unroller = self.space.unwrap(self.popvalue())
+        return self.unroll_finally(unroller)
 
-        if isinstance(unroller, SuspendedUnroller):
-            # go on unrolling the stack
-            block = self.unrollstack(unroller.kind)
-            if block is None:
-                w_result = unroller.nomoreblocks()
-                self.pushvalue(w_result)
-                raise Return
-            else:
-                next_instr = block.handle(self, unroller)
-        return next_instr
+    def unroll_finally(self, unroller):
+        # go on unrolling the stack
+        block = self.unrollstack(unroller.kind)
+        if block is None:
+            w_result = unroller.nomoreblocks()
+            self.pushvalue(w_result)
+            raise Return
+        else:
+            return block.handle(self, unroller)
 
     def JUMP_ABSOLUTE(self, jumpto, next_instr):
         return jumpto
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -173,14 +173,6 @@
             return obj
         return None
 
-    def _check_constant_interp_w_or_w_None(self, RequiredClass, w_obj):
-        """
-        WARNING: this implementation is not complete at all. It's just enough
-        to be used by end_finally() inside pyopcode.py.
-        """
-        return w_obj == self.w_None or (isinstance(w_obj, Constant) and
-                                        isinstance(w_obj.value, RequiredClass))
-
     def getexecutioncontext(self):
         return self.frame
 


More information about the pypy-commit mailing list