Author: Ronan Lamy <[email protected]>
Branch: less-stringly-ops
Changeset: r66769:6209a2e9528e
Date: 2013-09-01 10:48 +0100
http://bitbucket.org/pypy/pypy/changeset/6209a2e9528e/

Log:    Move FSException to flowspace.model

diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -9,7 +9,7 @@
 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,
@@ -34,15 +34,6 @@
     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
 
@@ -655,7 +646,7 @@
                 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
diff --git a/rpython/flowspace/model.py b/rpython/flowspace/model.py
--- a/rpython/flowspace/model.py
+++ b/rpython/flowspace/model.py
@@ -346,6 +346,16 @@
             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."""
 
@@ -367,6 +377,8 @@
     # 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):
diff --git a/rpython/flowspace/objspace.py b/rpython/flowspace/objspace.py
--- a/rpython/flowspace/objspace.py
+++ b/rpython/flowspace/objspace.py
@@ -9,11 +9,11 @@
 
 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
@@ -124,11 +124,6 @@
         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
@@ -175,7 +170,7 @@
         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)
@@ -215,7 +210,7 @@
                 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)
@@ -250,7 +245,7 @@
         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):
@@ -264,8 +259,7 @@
         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))
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to