summaryrefslogtreecommitdiffstatshomepage
path: root/py/vm.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-05-30 15:20:41 +0100
committerDamien George <damien.p.george@gmail.com>2014-05-30 15:20:41 +0100
commit25c84643b6c4da169cdb11de54f027e3c477c301 (patch)
treeae25e8618ebcf421c0e711fd51807e32dd366041 /py/vm.c
parent8827682b35f6fefb4604f28447b77e8443cbf1cb (diff)
downloadmicropython-25c84643b6c4da169cdb11de54f027e3c477c301.tar.gz
micropython-25c84643b6c4da169cdb11de54f027e3c477c301.zip
py: Fix break from within a for loop.
Needed to pop the iterator object when breaking out of a for loop. Need also to be careful to unwind exception handler before popping iterator. Addresses issue #635.
Diffstat (limited to 'py/vm.c')
-rw-r--r--py/vm.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/py/vm.c b/py/vm.c
index bd94ade541..74f821e9ec 100644
--- a/py/vm.c
+++ b/py/vm.c
@@ -618,10 +618,10 @@ dispatch_loop:
ENTRY(MP_BC_UNWIND_JUMP):
DECODE_SLABEL;
PUSH((void*)(ip + unum)); // push destination ip for jump
- PUSH((void*)(machine_uint_t)(*ip)); // push number of exception handlers to unwind
+ PUSH((void*)(machine_uint_t)(*ip)); // push number of exception handlers to unwind (0x80 bit set if we also need to pop stack)
unwind_jump:
unum = (machine_uint_t)POP(); // get number of exception handlers to unwind
- while (unum > 0) {
+ while ((unum & 0x7f) > 0) {
unum -= 1;
assert(exc_sp >= exc_stack);
if (exc_sp->opcode == MP_BC_SETUP_FINALLY || exc_sp->opcode == MP_BC_SETUP_WITH) {
@@ -638,6 +638,9 @@ unwind_jump:
exc_sp--;
}
ip = (const byte*)POP(); // pop destination ip for jump
+ if (unum != 0) {
+ sp--;
+ }
DISPATCH();
// matched against: POP_BLOCK or POP_EXCEPT (anything else?)