Author: Ronan Lamy <[email protected]>
Branch: framestate
Changeset: r75840:8349857a3478
Date: 2015-02-12 06:58 +0000
http://bitbucket.org/pypy/pypy/changeset/8349857a3478/
Log: move END_FINALLY to bytecode.py
diff --git a/rpython/flowspace/bytecode.py b/rpython/flowspace/bytecode.py
--- a/rpython/flowspace/bytecode.py
+++ b/rpython/flowspace/bytecode.py
@@ -585,6 +585,33 @@
from rpython.flowspace.flowcontext import Continue
return ctx.unroll(Continue(self.target))
+@bc_reader.register_opcode
+class END_FINALLY(BCInstruction):
+ def eval(self, ctx):
+ # unlike CPython, there are two statically distinct cases: the
+ # END_FINALLY might be closing an 'except' block or a 'finally'
+ # block. In the first case, the stack contains three items:
+ # [exception type we are now handling]
+ # [exception value we are now handling]
+ # [Raise]
+ # In the case of a finally: block, the stack contains only one
+ # item (unlike CPython which can have 1, 2 or 3 items):
+ # [subclass of FlowSignal]
+ from rpython.flowspace.flowcontext import FlowSignal
+ w_top = ctx.popvalue()
+ if w_top == const(None):
+ # finally: block with no unroller active
+ return
+ elif isinstance(w_top, FlowSignal):
+ # case of a finally: block
+ raise w_top
+ else:
+ # case of an except: block. We popped the exception type
+ ctx.popvalue() # Now we pop the exception value
+ signal = ctx.popvalue()
+ raise signal
+
+
class SetupInstruction(BCInstruction):
def bc_flow(self, reader):
reader.curr_block.operations.append(self)
diff --git a/rpython/flowspace/flowcontext.py b/rpython/flowspace/flowcontext.py
--- a/rpython/flowspace/flowcontext.py
+++ b/rpython/flowspace/flowcontext.py
@@ -610,29 +610,6 @@
w_returnvalue = self.popvalue()
raise Return(w_returnvalue)
- def END_FINALLY(self, oparg):
- # unlike CPython, there are two statically distinct cases: the
- # END_FINALLY might be closing an 'except' block or a 'finally'
- # block. In the first case, the stack contains three items:
- # [exception type we are now handling]
- # [exception value we are now handling]
- # [Raise]
- # In the case of a finally: block, the stack contains only one
- # item (unlike CPython which can have 1, 2 or 3 items):
- # [subclass of FlowSignal]
- w_top = self.popvalue()
- if w_top == w_None:
- # finally: block with no unroller active
- return
- elif isinstance(w_top, FlowSignal):
- # case of a finally: block
- raise w_top
- else:
- # case of an except: block. We popped the exception type
- self.popvalue() # Now we pop the exception value
- signal = self.popvalue()
- raise signal
-
def YIELD_VALUE(self, _):
assert self.pycode.is_generator
w_result = self.popvalue()
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit