Ronan Lamy avatar Ronan Lamy committed e48d83d

Merge Return/Raise exceptions with FlowSignal classes

Comments (0)

Files changed (1)


 class StopFlowing(Exception):
-class Return(Exception):
-    def __init__(self, value):
-        self.value = value
-class Raise(Exception):
-    def __init__(self, value):
-        self.value = value
-class RaiseImplicit(Raise):
-    pass
 class BytecodeCorruption(Exception):
                 self.recorder.final_state = self.getstate(next_pos)
         except RaiseImplicit as e:
-            w_exc = e.value
+            w_exc = e.operr
             if isinstance(w_exc.w_type, Constant):
                 exc_cls = w_exc.w_type.value
         except Raise as e:
-            w_exc = e.value
+            w_exc = e.operr
             if w_exc.w_type ==
                 msg = 'import statement always raises %s' % e
                 raise ImportError(msg)
         except Return as exc:
-            w_result = exc.value
+            w_result = exc.w_returnvalue
             link = Link([w_result], self.graph.returnblock)
             res = getattr(self, methodname)(oparg)
             return res if res is not None else next_instr
-        except RaiseImplicit as e:
-            return self.unroll(SImplicitException(e.value))
         except Raise as e:
-            return self.unroll(SApplicationException(e.value))
+            return self.unroll(e)
     def unroll(self, signal):
         while self.blockstack:
     def RETURN_VALUE(self, oparg):
         w_returnvalue = self.popvalue()
-        return self.unroll(SReturnValue(w_returnvalue))
+        return self.unroll(Return(w_returnvalue))
     def END_FINALLY(self, oparg):
         # unlike CPython, there are two statically distinct cases: the
         # block.  In the first case, the stack contains three items:
         #   [exception type we are now handling]
         #   [exception value we are now handling]
-        #   [SApplicationException]
+        #   [Raise]
         # In the case of a finally: block, the stack contains only one
         # item (unlike CPython which can have 1, 2 or 3 items):
         #   [wrapped subclass of FlowSignal]
             w_nextitem =
         except Raise as e:
-            w_exc = e.value
+            w_exc = e.operr
             if not,
             unroller = self.peekvalue(0)
         w_None =
-        if isinstance(unroller, SApplicationException):
+        if isinstance(unroller, Raise):
             operr = unroller.operr
             # The annotator won't allow to merge exception types with None.
             # Replace it with the exception value...
 ### Frame blocks ###
-class FlowSignal(object):
+class FlowSignal(Exception):
     """Abstract base class for translator-level objects that instruct the
     interpreter to change the control flow and the block stack.
     values of the why_code enumeration in ceval.c:
                 WHY_NOT,        OK, not this one :-)
-                WHY_EXCEPTION,  SApplicationException
+                WHY_EXCEPTION,  Raise
                 WHY_RERAISE,    implemented differently, see Reraise
-                WHY_RETURN,     SReturnValue
+                WHY_RETURN,     Return
                 WHY_BREAK,      SBreakLoop
                 WHY_CONTINUE,   SContinueLoop
                 WHY_YIELD       not needed
         raise BytecodeCorruption("misplaced bytecode - should not return")
-class SReturnValue(FlowSignal):
+class Return(FlowSignal):
     """Signals a 'return' statement.
     Argument is the wrapped object to return."""
     def state_pack_variables(w_returnvalue):
-        return SReturnValue(w_returnvalue)
+        return Return(w_returnvalue)
-class SApplicationException(FlowSignal):
+class Raise(FlowSignal):
     """Signals an application-level exception
     (i.e. an OperationException)."""
         self.operr = operr
     def nomoreblocks(self):
-        raise Raise(self.operr)
+        raise self
     def state_unpack_variables(self):
         return [self.operr.w_type, self.operr.w_value]
     def state_pack_variables(w_type, w_value):
-        return SApplicationException(FSException(w_type, w_value))
+        return Raise(FSException(w_type, w_value))
-class SImplicitException(SApplicationException):
+class RaiseImplicit(Raise):
     """Signals an exception raised implicitly"""
-    def nomoreblocks(self):
-        raise RaiseImplicit(self.operr)
 class SBreakLoop(FlowSignal):
     """Signals a 'break' statement."""
 class ExceptBlock(FrameBlock):
     """An try:except: block.  Stores the position of the exception handler."""
-    handles = SApplicationException
+    handles = Raise
     def handle(self, frame, unroller):
         # push the exception to the value stack for inspection by the
         # exception handler (the code after the except:)
-        assert isinstance(unroller, SApplicationException)
+        assert isinstance(unroller, Raise)
         operationerr = unroller.operr
         # the stack setup is slightly different than in CPython:
         # instead of the traceback, we store the unroller object,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.