Author: Antonio Cuni <[email protected]>
Branch: py3k
Changeset: r52462:3648ec4ef989
Date: 2012-02-14 12:15 +0100
http://bitbucket.org/pypy/pypy/changeset/3648ec4ef989/

Log:    emit and implement POP_EXCEPT, which is needed for lexical exception
        handlers. This is equivalent to part of the patch at
        http://bugs.python.org/issue3021

diff --git a/pypy/interpreter/astcompiler/assemble.py 
b/pypy/interpreter/astcompiler/assemble.py
--- a/pypy/interpreter/astcompiler/assemble.py
+++ b/pypy/interpreter/astcompiler/assemble.py
@@ -550,7 +550,7 @@
     ops.END_FINALLY : -3,
     ops.SETUP_WITH : 1,
     ops.SETUP_FINALLY : 0,
-    ops.SETUP_EXCEPT : 0,
+    ops.SETUP_EXCEPT : 4,
 
     ops.RETURN_VALUE : -1,
     ops.YIELD_VALUE : 0,
diff --git a/pypy/interpreter/astcompiler/codegen.py 
b/pypy/interpreter/astcompiler/codegen.py
--- a/pypy/interpreter/astcompiler/codegen.py
+++ b/pypy/interpreter/astcompiler/codegen.py
@@ -529,6 +529,7 @@
                 self.emit_op(ops.POP_TOP)
             self.emit_op(ops.POP_TOP)
             self.visit_sequence(handler.body)
+            self.emit_op(ops.POP_EXCEPT)
             self.emit_jump(ops.JUMP_FORWARD, end)
             self.use_next_block(next_except)
         self.emit_op(ops.END_FINALLY)
diff --git a/pypy/interpreter/pyopcode.py b/pypy/interpreter/pyopcode.py
--- a/pypy/interpreter/pyopcode.py
+++ b/pypy/interpreter/pyopcode.py
@@ -174,6 +174,7 @@
                 ec.bytecode_trace(self)
                 next_instr = r_uint(self.last_instr)
             opcode = ord(co_code[next_instr])
+            #print 'executing', self.last_instr, 
bytecode_spec.method_names[opcode]
             next_instr += 1
             if space.config.objspace.logbytecodes:
                 space.bytecodecounts[opcode] += 1
@@ -524,7 +525,9 @@
             self.setdictscope(w_locals)
 
     def POP_EXCEPT(self, oparg, next_instr):
-        raise NotImplementedError
+        # on CPython, POP_EXCEPT also pops the block. Here, the block is
+        # automatically popped by unrollstack()
+        self.last_exception = self.popvalue()
 
     def POP_BLOCK(self, oparg, next_instr):
         block = self.pop_block()
@@ -1268,6 +1271,7 @@
         # the stack setup is slightly different than in CPython:
         # instead of the traceback, we store the unroller object,
         # wrapped.
+        frame.pushvalue(frame.last_exception) # this is popped by POP_EXCEPT
         frame.pushvalue(frame.space.wrap(unroller))
         frame.pushvalue(operationerr.get_w_value(frame.space))
         frame.pushvalue(operationerr.w_type)
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to