Author: Ronan Lamy <[email protected]>
Branch: translation-cleanup
Changeset: r57425:5a65e5908564
Date: 2012-09-15 19:29 +0100
http://bitbucket.org/pypy/pypy/changeset/5a65e5908564/
Log: Move handle_implicit_exceptions() to FSFrame
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
@@ -187,14 +187,12 @@
assert self.index == len(self.listtoreplay)
frame.recorder = self.nextreplayer
outcome = self.booloutcome
- if outcome is None:
- w_exc_cls, w_exc_value = None, None
- else:
+ if outcome is not None:
egg = self.nextreplayer.crnt_block
w_exc_cls, w_exc_value = egg.inputargs[-2:]
if isinstance(egg.last_exception, Constant):
w_exc_cls = egg.last_exception
- return outcome, w_exc_cls, w_exc_value
+ raise ImplicitOperationError(w_exc_cls, w_exc_value)
# ____________________________________________________________
@@ -320,8 +318,18 @@
def guessbool(self, w_condition, **kwds):
return self.recorder.guessbool(self, w_condition, **kwds)
- def guessexception(self, *classes):
- return self.recorder.guessexception(self, *classes)
+ def handle_implicit_exceptions(self, exceptions):
+ """
+ Catch possible exceptions implicitly.
+
+ If the OperationError 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.
+ """
+ if not exceptions:
+ return
+ return self.recorder.guessexception(self, *exceptions)
def build_flow(self):
while self.pendingblocks:
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
@@ -274,7 +274,8 @@
def do_operation_with_implicit_exceptions(self, name, *args_w):
w_result = self.do_operation(name, *args_w)
-
self.handle_implicit_exceptions(operation.implicit_exceptions.get(name))
+ self.frame.handle_implicit_exceptions(
+ operation.implicit_exceptions.get(name))
return w_result
def is_true(self, w_obj):
@@ -314,15 +315,8 @@
frame.replace_in_stack(it, next_unroller)
return self.wrap(v)
w_item = self.do_operation("next", w_iter)
- outcome, w_exc_cls, w_exc_value = frame.guessexception(StopIteration,
- RuntimeError)
- if outcome is StopIteration:
- raise OperationError(self.w_StopIteration, w_exc_value)
- elif outcome is RuntimeError:
- raise operation.ImplicitOperationError(Constant(RuntimeError),
- w_exc_value)
- else:
- return w_item
+ frame.handle_implicit_exceptions([StopIteration, RuntimeError])
+ return w_item
def setitem(self, w_obj, w_key, w_val):
# protect us from globals write access
@@ -426,27 +420,9 @@
types.TypeType)) and
c.__module__ in ['__builtin__', 'exceptions']):
exceptions = operation.implicit_exceptions.get(c)
- self.handle_implicit_exceptions(exceptions)
+ self.frame.handle_implicit_exceptions(exceptions)
return w_res
- def handle_implicit_exceptions(self, exceptions):
- if not exceptions:
- return
- # catch possible exceptions implicitly. If the OperationError
- # below 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.
- outcome, w_exc_cls, w_exc_value =
self.frame.guessexception(*exceptions)
- if outcome is not None:
- # we assume that the caught exc_cls will be exactly the
- # one specified by 'outcome', and not a subclass of it,
- # unless 'outcome' is Exception.
- #if outcome is not Exception:
- #w_exc_cls = Constant(outcome) Now done by guessexception
itself
- #pass
- raise operation.ImplicitOperationError(w_exc_cls, w_exc_value)
-
def find_global(self, w_globals, varname):
try:
value = self.unwrap(w_globals)[varname]
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit