Commits

Ronan Lamy committed 6209a2e

Move FSException to flowspace.model

  • Participants
  • Parent commits e059c66
  • Branches less-stringly-ops

Comments (0)

Files changed (3)

rpython/flowspace/flowcontext.py

 from rpython.tool.stdlib_opcode import host_bytecode_spec
 from rpython.flowspace.argument import CallSpec
 from rpython.flowspace.model import (Constant, Variable, Block, Link,
-    c_last_exception, SpaceOperation, const)
+    c_last_exception, SpaceOperation, const, FSException)
 from rpython.flowspace.framestate import (FrameState, recursively_unflatten,
     recursively_flatten)
 from rpython.flowspace.specialcase import (rpython_print_item,
     def __init__(self, value):
         self.value = value
 
-class FSException(Exception):
-    def __init__(self, w_type, w_value):
-        assert w_type is not None
-        self.w_type = w_type
-        self.w_value = w_value
-
-    def __str__(self):
-        return '[%s: %s]' % (self.w_type, self.w_value)
-
 class ImplicitOperationError(FSException):
     pass
 
                 self.last_exception = operr
                 raise operr
             else:
-                raise space.exc_wrap(TypeError(
+                raise const(TypeError(
                     "raise: no active exception to re-raise"))
 
         w_value = space.w_None

rpython/flowspace/model.py

             return False
 
 
+class FSException(Exception):
+    def __init__(self, w_type, w_value):
+        assert w_type is not None
+        self.w_type = w_type
+        self.w_value = w_value
+
+    def __str__(self):
+        return '[%s: %s]' % (self.w_type, self.w_value)
+
+
 class UnwrapException(Exception):
     """Attempted to unwrap a Variable."""
 
     # to appear in a flow graph
     if type(obj) is type_with_bad_introspection:
         raise WrapException
+    elif isinstance(obj, Exception):
+        return FSException(Constant(type(obj)), Constant(obj))
     return Constant(obj)
 
 class SpaceOperation(object):

rpython/flowspace/objspace.py

 
 from rpython.flowspace.argument import CallSpec
 from rpython.flowspace.model import (Constant, Variable, WrapException,
-    UnwrapException, checkgraph, const)
+    UnwrapException, checkgraph, const, FSException)
 from rpython.flowspace.bytecode import HostCode
 from rpython.flowspace.operation import op
 from rpython.flowspace.flowcontext import (FlowSpaceFrame, fixeggblocks,
-    FSException, FlowingError)
+    FlowingError)
 from rpython.flowspace.generator import (tweak_generator_graph,
         bootstrap_generator)
 from rpython.flowspace.pygraph import PyGraph
         fn = types.FunctionType(code, globals, code.co_name, defaults)
         return Constant(fn)
 
-    def exc_wrap(self, exc):
-        w_value = const(exc)
-        w_type = const(type(exc))
-        return FSException(w_type, w_value)
-
     def exception_match(self, w_exc_type, w_check_class):
         """Checks if the given exception type matches 'w_check_class'."""
         frame = self.frame
         else:
             # the only case left here is (inst, None), from a 'raise inst'.
             if not frame.guessbool(self.is_(w_arg2, self.w_None)):
-                raise self.exc_wrap(TypeError(
+                raise const(TypeError(
                     "instance exception may not have a separate value"))
             w_value = w_arg1
         w_type = self.type(w_value)
                 try:
                     v, next_unroller = it.step()
                 except IndexError:
-                    raise self.exc_wrap(StopIteration())
+                    raise const(StopIteration())
                 else:
                     frame.replace_in_stack(it, next_unroller)
                     return const(v)
         try:
             mod = __import__(name, glob, loc, frm, level)
         except ImportError as e:
-            raise self.exc_wrap(e)
+            raise const(e)
         return const(mod)
 
     def import_from(self, w_module, w_name):
         try:
             return const(getattr(w_module.value, w_name.value))
         except AttributeError:
-            raise self.exc_wrap(ImportError(
-                "cannot import name '%s'" % w_name.value))
+            raise const(ImportError("cannot import name '%s'" % w_name.value))
 
     def call_method(self, w_obj, methname, *arg_w):
         w_meth = self.getattr(w_obj, const(methname))