diff options
author | Damien George <damien.p.george@gmail.com> | 2014-05-30 15:20:41 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-05-30 15:20:41 +0100 |
commit | 25c84643b6c4da169cdb11de54f027e3c477c301 (patch) | |
tree | ae25e8618ebcf421c0e711fd51807e32dd366041 /py/compile.c | |
parent | 8827682b35f6fefb4604f28447b77e8443cbf1cb (diff) |
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/compile.c')
-rw-r--r-- | py/compile.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/py/compile.c b/py/compile.c index 31ecbf0b9..c90772a7e 100644 --- a/py/compile.c +++ b/py/compile.c @@ -73,8 +73,8 @@ typedef struct _compiler_t { uint next_label; - uint break_label; - uint continue_label; + uint16_t break_label; // highest bit set indicates we are breaking out of a for loop + uint16_t continue_label; int break_continue_except_level; uint16_t cur_except_level; // increased for SETUP_EXCEPT, SETUP_FINALLY; decreased for POP_BLOCK, POP_EXCEPT @@ -1745,6 +1745,7 @@ void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // And, if the loop never runs, the loop variable should never be assigned void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t pn_var, mp_parse_node_t pn_start, mp_parse_node_t pn_end, mp_parse_node_t pn_step, mp_parse_node_t pn_body, mp_parse_node_t pn_else) { START_BREAK_CONTINUE_BLOCK + comp->break_label |= MP_EMIT_BREAK_FROM_FOR; uint top_label = comp_next_label(comp); uint entry_label = comp_next_label(comp); @@ -1843,6 +1844,7 @@ void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { #endif START_BREAK_CONTINUE_BLOCK + comp->break_label |= MP_EMIT_BREAK_FROM_FOR; uint pop_label = comp_next_label(comp); uint end_label = comp_next_label(comp); |