Author: Ronan Lamy <[email protected]>
Branch: less-stringly-ops
Changeset: r66899:f0d93e1cd108
Date: 2013-09-11 01:31 +0100
http://bitbucket.org/pypy/pypy/changeset/f0d93e1cd108/

Log:    const(<Exception>) returns an instance of Constant

        Create ConstException which subclasses both Constant and
        FSException. This re-allows prebuilt Exception instances to appear
        in graphs.

diff --git a/rpython/flowspace/model.py b/rpython/flowspace/model.py
--- a/rpython/flowspace/model.py
+++ b/rpython/flowspace/model.py
@@ -355,6 +355,18 @@
     def __str__(self):
         return '[%s: %s]' % (self.w_type, self.w_value)
 
+class ConstException(Constant, FSException):
+    def foldable(self):
+        return True
+
+    @property
+    def w_type(self):
+        return Constant(type(self.value))
+
+    @property
+    def w_value(self):
+        return Constant(self.value)
+
 
 class UnwrapException(Exception):
     """Attempted to unwrap a Variable."""
@@ -378,7 +390,7 @@
     if type(obj) is type_with_bad_introspection:
         raise WrapException
     elif isinstance(obj, Exception):
-        return FSException(Constant(type(obj)), Constant(obj))
+        return ConstException(obj)
     return Constant(obj)
 
 class SpaceOperation(object):
diff --git a/rpython/flowspace/test/test_objspace.py 
b/rpython/flowspace/test/test_objspace.py
--- a/rpython/flowspace/test/test_objspace.py
+++ b/rpython/flowspace/test/test_objspace.py
@@ -3,7 +3,8 @@
 import py
 from contextlib import contextmanager
 
-from rpython.flowspace.model import Constant, mkentrymap, c_last_exception
+from rpython.flowspace.model import (
+    Constant, mkentrymap, c_last_exception, const)
 from rpython.translator.simplify import simplify_graph
 from rpython.flowspace.objspace import build_flow
 from rpython.flowspace.flowcontext import FlowingError, FlowSpaceFrame
@@ -397,6 +398,18 @@
         assert ops[0].opname == 'simple_call'
         assert ops[0].args == [Constant(ValueError), Constant('ouch')]
 
+    def test_raise_prebuilt(self):
+        error = ValueError('ouch')
+        def g(x): return x
+        def f():
+            raise g(error)
+        x = self.codetest(f)
+        simplify_graph(x)
+        self.show(x)
+        ops = x.startblock.operations
+        assert ops[0].opname == 'simple_call'
+        assert ops[0].args == [const(g), const(error)]
+
     #__________________________________________________________
     def raise2(msg):
         raise IndexError, msg
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to