[pypy-svn] r70818 - in pypy/branch/lazy-operr-format/pypy: interpreter objspace/flow

arigo at codespeak.net arigo at codespeak.net
Mon Jan 25 10:46:15 CET 2010


Author: arigo
Date: Mon Jan 25 10:46:15 2010
New Revision: 70818

Modified:
   pypy/branch/lazy-operr-format/pypy/interpreter/baseobjspace.py
   pypy/branch/lazy-operr-format/pypy/interpreter/error.py
   pypy/branch/lazy-operr-format/pypy/interpreter/executioncontext.py
   pypy/branch/lazy-operr-format/pypy/interpreter/main.py
   pypy/branch/lazy-operr-format/pypy/interpreter/typedef.py
   pypy/branch/lazy-operr-format/pypy/objspace/flow/flowcontext.py
Log:
In-progress.


Modified: pypy/branch/lazy-operr-format/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/branch/lazy-operr-format/pypy/interpreter/baseobjspace.py	(original)
+++ pypy/branch/lazy-operr-format/pypy/interpreter/baseobjspace.py	Mon Jan 25 10:46:15 2010
@@ -825,7 +825,8 @@
         try:
             w_res = self.call_args(w_func, args)
         except OperationError, e:
-            ec.c_exception_trace(frame, e.w_value)
+            w_value = e.get_w_value(self)
+            ec.c_exception_trace(frame, w_value)
             raise
         ec.c_return_trace(frame, w_func)
         return w_res

Modified: pypy/branch/lazy-operr-format/pypy/interpreter/error.py
==============================================================================
--- pypy/branch/lazy-operr-format/pypy/interpreter/error.py	(original)
+++ pypy/branch/lazy-operr-format/pypy/interpreter/error.py	Mon Jan 25 10:46:15 2010
@@ -16,6 +16,9 @@
     PyTraceback objects making the application-level traceback.
     """
 
+    __slots__ = ('w_type', '_w_value', 'application_traceback',
+                 'debug_excs')
+
     def __init__(self, w_type, w_value, tb=None):
         if w_type is None:
             from pypy.tool.error import FlowingError
@@ -234,10 +237,10 @@
             pass   # ignored
 
     def get_w_value(self, space):
-        w_value = self.w_value
+        w_value = self._w_value
         if w_value is None:
             value = self._compute_value()
-            self.w_value = w_value = space.wrap(value)
+            self._w_value = w_value = space.wrap(value)
         return w_value
 
     def _compute_value(self):
@@ -305,6 +308,9 @@
 get_operationerr_class._annspecialcase_ = 'specialize:memo'
 
 def operationerrfmt(w_type, valuefmt, *args):
+    """Equivalent to OperationError(w_type, space.wrap(valuefmt % args)).
+    More efficient in the (common) case where the value is not actually
+    needed."""
     OpErrFmt, strings = get_operationerr_class(valuefmt)
     return OpErrFmt(w_type, strings, *args)
 

Modified: pypy/branch/lazy-operr-format/pypy/interpreter/executioncontext.py
==============================================================================
--- pypy/branch/lazy-operr-format/pypy/interpreter/executioncontext.py	(original)
+++ pypy/branch/lazy-operr-format/pypy/interpreter/executioncontext.py	Mon Jan 25 10:46:15 2010
@@ -265,7 +265,8 @@
 
         if w_callback is not None and event != "leaveframe":
             if operr is not None:
-                w_arg =  space.newtuple([operr.w_type, operr.w_value,
+                w_value = operr.get_w_value(space)
+                w_arg = space.newtuple([operr.w_type, w_value,
                                      space.wrap(operr.application_traceback)])
 
             frame.fast2locals()

Modified: pypy/branch/lazy-operr-format/pypy/interpreter/main.py
==============================================================================
--- pypy/branch/lazy-operr-format/pypy/interpreter/main.py	(original)
+++ pypy/branch/lazy-operr-format/pypy/interpreter/main.py	Mon Jan 25 10:46:15 2010
@@ -117,7 +117,7 @@
     except OperationError, operationerr:
         operationerr.normalize_exception(space)
         w_type = operationerr.w_type
-        w_value = operationerr.w_value
+        w_value = operationerr.get_w_value(space)
         w_traceback = space.wrap(operationerr.application_traceback)
 
         # for debugging convenience we also insert the exception into
@@ -128,7 +128,7 @@
         try:
             # exit if we catch a w_SystemExit
             if operationerr.match(space, space.w_SystemExit):
-                w_exitcode = space.getattr(operationerr.w_value,
+                w_exitcode = space.getattr(w_value,
                                            space.wrap('code'))
                 if space.is_w(w_exitcode, space.w_None):
                     exitcode = 0

Modified: pypy/branch/lazy-operr-format/pypy/interpreter/typedef.py
==============================================================================
--- pypy/branch/lazy-operr-format/pypy/interpreter/typedef.py	(original)
+++ pypy/branch/lazy-operr-format/pypy/interpreter/typedef.py	Mon Jan 25 10:46:15 2010
@@ -7,7 +7,7 @@
 from pypy.interpreter.argument import Arguments
 from pypy.interpreter.baseobjspace import Wrappable, W_Root, ObjSpace, \
     DescrMismatch
-from pypy.interpreter.error import OperationError
+from pypy.interpreter.error import OperationError, operationerrfmt
 from pypy.tool.sourcetools import compile2, func_with_new_name
 from pypy.rlib.objectmodel import instantiate, compute_identity_hash
 from pypy.rlib.jit import hint
@@ -52,8 +52,8 @@
 
 def descr__hash__unhashable(space, w_obj):
     typename = space.type(w_obj).getname(space, '?')
-    msg = "%s objects are unhashable" % (typename,)
-    raise OperationError(space.w_TypeError,space.wrap(msg))
+    raise operationerrfmt(space.w_TypeError,
+                          "%s objects are unhashable", typename)
 
 no_hash_descr = interp2app(descr__hash__unhashable)
 

Modified: pypy/branch/lazy-operr-format/pypy/objspace/flow/flowcontext.py
==============================================================================
--- pypy/branch/lazy-operr-format/pypy/objspace/flow/flowcontext.py	(original)
+++ pypy/branch/lazy-operr-format/pypy/objspace/flow/flowcontext.py	Mon Jan 25 10:46:15 2010
@@ -276,7 +276,7 @@
                 raise Exception(
                     'found an operation that always raises %s: %s' % (
                         self.space.unwrap(e.w_type).__name__,
-                        self.space.unwrap(e.w_value)))
+                        self.space.unwrap(e.get_w_value(self.space))))
 
             except ImplicitOperationError, e:
                 if isinstance(e.w_type, Constant):
@@ -295,7 +295,8 @@
                     e.w_type is self.space.w_ImportError):
                     raise ImportError('import statement always raises %s' % (
                         e,))
-                link = self.make_link([e.w_type, e.w_value], self.graph.exceptblock)
+                w_value = e.get_w_value(self.space)
+                link = self.make_link([e.w_type, w_value], self.graph.exceptblock)
                 self.recorder.crnt_block.closeblock(link)
 
             except StopFlowing:
@@ -382,7 +383,8 @@
         operr = ExecutionContext.sys_exc_info(self)
         if isinstance(operr, ImplicitOperationError):
             # re-raising an implicit operation makes it an explicit one
-            operr = OperationError(operr.w_type, operr.w_value)
+            w_value = operr.get_w_value(self.space)
+            operr = OperationError(operr.w_type, w_value)
         return operr
 
     def exception_trace(self, frame, operationerr):



More information about the Pypy-commit mailing list