[pypy-commit] pypy translation-cleanup: Create flowspace-specific subclass of OperationError
rlamy
noreply at buildbot.pypy.org
Thu Sep 20 19:39:12 CEST 2012
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57427:e57a0552d2d0
Date: 2012-09-16 04:29 +0100
http://bitbucket.org/pypy/pypy/changeset/e57a0552d2d0/
Log: Create flowspace-specific subclass of OperationError
This is the first step towards reimplementing exception-handling
inside the flow space.
diff --git a/pypy/objspace/flow/flowcontext.py b/pypy/objspace/flow/flowcontext.py
--- a/pypy/objspace/flow/flowcontext.py
+++ b/pypy/objspace/flow/flowcontext.py
@@ -18,10 +18,13 @@
class StopFlowing(Exception):
pass
-class OperationThatShouldNotBePropagatedError(OperationError):
+class FSException(OperationError):
pass
-class ImplicitOperationError(OperationError):
+class OperationThatShouldNotBePropagatedError(FSException):
+ pass
+
+class ImplicitOperationError(FSException):
pass
class SpamBlock(Block):
@@ -289,7 +292,7 @@
assert data[-1] == Constant(None)
self.last_exception = None
else:
- self.last_exception = OperationError(data[-2], data[-1])
+ self.last_exception = FSException(data[-2], data[-1])
blocklist, self.last_instr = state.nonmergeable
self.set_blocklist(blocklist)
@@ -326,7 +329,7 @@
"""
Catch possible exceptions implicitly.
- If the OperationError is not caught in the same function, it will
+ If the FSException is not caught in the same function, it will
produce an exception-raising return block in the flow graph. Note that
even if the interpreter re-raises the exception, it will not be the
same ImplicitOperationError instance internally.
@@ -417,7 +420,7 @@
if isinstance(operr, ImplicitOperationError):
# re-raising an implicit operation makes it an explicit one
w_value = operr.get_w_value(self.space)
- operr = OperationError(operr.w_type, w_value)
+ operr = FSException(operr.w_type, w_value)
return operr
# hack for unrolling iterables, don't use this
@@ -467,11 +470,11 @@
def handle_operation_error(self, operr):
block = self.unrollstack(SApplicationException.kind)
if block is None:
- # no handler found for the OperationError
+ # no handler found for the exception
# try to preserve the CPython-level traceback
import sys
tb = sys.exc_info()[2]
- raise OperationError, operr, tb
+ raise operr, None, tb
else:
unroller = SApplicationException(operr)
next_instr = block.handle(self, unroller)
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -5,12 +5,11 @@
import types
from pypy.tool import error
from pypy.interpreter.baseobjspace import ObjSpace, Wrappable
-from pypy.interpreter.error import OperationError
from pypy.interpreter import pyframe, argument
from pypy.objspace.flow.model import *
from pypy.objspace.flow import operation
from pypy.objspace.flow.flowcontext import (FlowSpaceFrame, fixeggblocks,
- OperationThatShouldNotBePropagatedError)
+ OperationThatShouldNotBePropagatedError, FSException)
from pypy.objspace.flow.specialcase import SPECIAL_CASES
from pypy.rlib.unroll import unrolling_iterable, _unroller
from pypy.rlib import rstackovf, rarithmetic
@@ -259,7 +258,7 @@
w_len = self.len(w_iterable)
w_correct = self.eq(w_len, self.wrap(expected_length))
if not self.is_true(w_correct):
- e = OperationError(self.w_ValueError, self.w_None)
+ e = FSException(self.w_ValueError, self.w_None)
e.normalize_exception(self)
raise e
return [self.do_operation('getitem', w_iterable, self.wrap(i))
@@ -311,7 +310,7 @@
try:
v, next_unroller = it.step()
except IndexError:
- raise OperationError(self.w_StopIteration, self.w_None)
+ raise FSException(self.w_StopIteration, self.w_None)
else:
frame.replace_in_stack(it, next_unroller)
return self.wrap(v)
@@ -360,15 +359,15 @@
try:
mod = __import__(name, glob, loc, frm, level)
except ImportError, e:
- raise OperationError(self.w_ImportError, self.wrap(str(e)))
+ raise FSException(self.w_ImportError, self.wrap(str(e)))
return self.wrap(mod)
def import_from(self, w_module, w_name):
try:
return self.getattr(w_module, w_name)
- except OperationError, e:
+ except FSException, e:
if e.match(self, self.w_AttributeError):
- raise OperationError(self.w_ImportError,
+ raise FSException(self.w_ImportError,
self.wrap("cannot import name '%s'" % w_name.value))
else:
raise
@@ -433,7 +432,7 @@
value = getattr(self.unwrap(self.builtin), varname)
except AttributeError:
message = "global name '%s' is not defined" % varname
- raise OperationError(self.w_NameError, self.wrap(message))
+ raise FSException(self.w_NameError, self.wrap(message))
return self.wrap(value)
def w_KeyboardInterrupt(self):
More information about the pypy-commit
mailing list