Author: Ronan Lamy <[email protected]>
Branch: less-stringly-ops
Changeset: r66847:e78d34c539f7
Date: 2013-09-06 19:45 +0100
http://bitbucket.org/pypy/pypy/changeset/e78d34c539f7/
Log: Turn FSException into a normal object, not an exception.
FSException now unambiguously represents RPython-level exception
objects, and is separate from the internal translator-level
exceptions used by flowspace to implement control flow.
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -34,10 +34,13 @@
def __init__(self, value):
self.value = value
-class RaiseImplicit(Exception):
+class Raise(Exception):
def __init__(self, value):
self.value = value
+class RaiseImplicit(Raise):
+ pass
+
class BytecodeCorruption(Exception):
pass
@@ -486,11 +489,12 @@
link = Link([w_type, w_value], self.graph.exceptblock)
self.recorder.crnt_block.closeblock(link)
- except FSException, e:
- if e.w_type == self.space.w_ImportError:
+ except Raise as e:
+ w_exc = e.value
+ if w_exc.w_type == self.space.w_ImportError:
msg = 'import statement always raises %s' % e
raise ImportError(msg)
- link = Link([e.w_type, e.w_value], self.graph.exceptblock)
+ link = Link([w_exc.w_type, w_exc.w_value], self.graph.exceptblock)
self.recorder.crnt_block.closeblock(link)
except StopFlowing:
@@ -566,12 +570,8 @@
return res if res is not None else next_instr
except RaiseImplicit as e:
return SImplicitException(e.value).unroll(self)
- except FSException, operr:
- return self.handle_operation_error(operr)
-
- def handle_operation_error(self, operr):
- unroller = SApplicationException(operr)
- return unroller.unroll(self)
+ except Raise as e:
+ return SApplicationException(e.value).unroll(self)
def getlocalvarname(self, index):
return self.pycode.co_varnames[index]
@@ -638,10 +638,11 @@
space = self.space
if nbargs == 0:
if self.last_exception is not None:
- raise self.last_exception
+ w_exc = self.last_exception
else:
- raise const(TypeError(
+ w_exc = const(TypeError(
"raise: no active exception to re-raise"))
+ raise Raise(w_exc)
if nbargs >= 3:
self.popvalue()
@@ -655,7 +656,7 @@
operror = w_type
else:
operror = space.exc_from_raise(w_type, space.w_None)
- raise operror
+ raise Raise(operror)
def IMPORT_NAME(self, nameindex):
space = self.space
@@ -775,7 +776,7 @@
w_iterator = self.peekvalue()
try:
w_nextitem = self.space.next(w_iterator)
- except RaiseImplicit as e:
+ except Raise as e:
w_exc = e.value
if not self.space.exception_match(w_exc.w_type,
self.space.w_StopIteration):
@@ -783,12 +784,6 @@
# iterator exhausted
self.popvalue()
return target
- except FSException as e:
- if not self.space.exception_match(e.w_type,
self.space.w_StopIteration):
- raise
- # iterator exhausted
- self.popvalue()
- return target
else:
self.pushvalue(w_nextitem)
@@ -1187,7 +1182,7 @@
self.operr = operr
def nomoreblocks(self):
- raise self.operr
+ raise Raise(self.operr)
def state_unpack_variables(self):
return [self.operr.w_type, self.operr.w_value]
diff --git a/rpython/flowspace/model.py b/rpython/flowspace/model.py
--- a/rpython/flowspace/model.py
+++ b/rpython/flowspace/model.py
@@ -346,7 +346,7 @@
return False
-class FSException(Exception):
+class FSException(object):
def __init__(self, w_type, w_value):
assert w_type is not None
self.w_type = w_type
diff --git a/rpython/flowspace/objspace.py b/rpython/flowspace/objspace.py
--- a/rpython/flowspace/objspace.py
+++ b/rpython/flowspace/objspace.py
@@ -13,7 +13,7 @@
from rpython.flowspace.bytecode import HostCode
from rpython.flowspace.operation import op, NOT_REALLY_CONST
from rpython.flowspace.flowcontext import (FlowSpaceFrame, fixeggblocks,
- FlowingError)
+ FlowingError, Raise)
from rpython.flowspace.generator import (tweak_generator_graph,
bootstrap_generator)
from rpython.flowspace.pygraph import PyGraph
@@ -150,8 +150,9 @@
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 const(TypeError(
- "instance exception may not have a separate value"))
+ exc = TypeError("instance exception may not have a "
+ "separate value")
+ raise Raise(const(exc))
w_value = w_arg1
w_type = self.type(w_value)
return FSException(w_type, w_value)
@@ -173,8 +174,8 @@
w_len = self.len(w_iterable)
w_correct = self.eq(w_len, const(expected_length))
if not self.frame.guessbool(self.bool(w_correct)):
- e = self.exc_from_raise(self.w_ValueError, self.w_None)
- raise e
+ w_exc = self.exc_from_raise(self.w_ValueError, self.w_None)
+ raise Raise(w_exc)
return [self.frame.do_operation('getitem', w_iterable, const(i))
for i in range(expected_length)]
@@ -187,7 +188,7 @@
try:
mod = __import__(name, glob, loc, frm, level)
except ImportError as e:
- raise const(e)
+ raise Raise(const(e))
return const(mod)
def import_from(self, w_module, w_name):
@@ -201,7 +202,8 @@
try:
return const(getattr(w_module.value, w_name.value))
except AttributeError:
- raise const(ImportError("cannot import name '%s'" % w_name.value))
+ exc = ImportError("cannot import name '%s'" % w_name.value)
+ raise Raise(const(exc))
def call_method(self, w_obj, methname, *arg_w):
w_meth = self.getattr(w_obj, const(methname))
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -330,7 +330,8 @@
try:
v, next_unroller = it.step()
except IndexError:
- raise const(StopIteration())
+ from rpython.flowspace.flowcontext import Raise
+ raise Raise(const(StopIteration()))
else:
frame.replace_in_stack(it, next_unroller)
return const(v)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit