Author: Ronan Lamy <[email protected]>
Branch:
Changeset: r76331:dd46b08a538f
Date: 2015-03-11 03:19 +0000
http://bitbucket.org/pypy/pypy/changeset/dd46b08a538f/
Log: Regularise implementations of FOR_ITER and op.next
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -772,15 +772,10 @@
def FOR_ITER(self, target):
w_iterator = self.peekvalue()
- try:
- w_nextitem = op.next(w_iterator).eval(self)
- self.pushvalue(w_nextitem)
- except Raise as e:
- if self.exception_match(e.w_exc.w_type, const(StopIteration)):
- self.popvalue()
- return target
- else:
- raise
+ self.blockstack.append(IterBlock(self, target))
+ w_nextitem = op.next(w_iterator).eval(self)
+ self.blockstack.pop()
+ self.pushvalue(w_nextitem)
def SETUP_LOOP(self, target):
block = LoopBlock(self, target)
@@ -1333,6 +1328,16 @@
ctx.last_exception = w_exc
return self.handlerposition # jump to the handler
+class IterBlock(ExceptBlock):
+ """A pseudo-block to catch the StopIteration inside FOR_ITER"""
+ def handle(self, ctx, unroller):
+ w_exc = unroller.w_exc
+ if ctx.exception_match(w_exc.w_type, const(StopIteration)):
+ ctx.popvalue()
+ return self.handlerposition
+ else:
+ return ctx.unroll(unroller)
+
class FinallyBlock(FrameBlock):
"""A try:finally: block. Stores the position of the exception handler."""
diff --git a/rpython/flowspace/operation.py b/rpython/flowspace/operation.py
--- a/rpython/flowspace/operation.py
+++ b/rpython/flowspace/operation.py
@@ -555,7 +555,7 @@
opname = 'next'
arity = 1
can_overflow = False
- canraise = []
+ canraise = [StopIteration, RuntimeError]
pyfunc = staticmethod(next)
def eval(self, ctx):
@@ -571,9 +571,7 @@
else:
ctx.replace_in_stack(it, next_unroller)
return const(v)
- w_item = ctx.do_op(self)
- ctx.recorder.guessexception(ctx, StopIteration, RuntimeError)
- return w_item
+ return HLOperation.eval(self, ctx)
class GetAttr(SingleDispatchMixin, HLOperation):
opname = 'getattr'
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit