summaryrefslogtreecommitdiffstatshomepage
path: root/py/compile.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-01-21 23:48:04 +0000
committerDamien George <damien.p.george@gmail.com>2014-01-21 23:48:04 +0000
commit600ae734cf3d0ca5274086b897f1ebaf20cf9d20 (patch)
tree5d05831a589eb5dd614a23dfae01c0fae74f0b93 /py/compile.c
parent2c302563820d18be5fcfed406582ea5edaa6b39f (diff)
downloadmicropython-600ae734cf3d0ca5274086b897f1ebaf20cf9d20.tar.gz
micropython-600ae734cf3d0ca5274086b897f1ebaf20cf9d20.zip
py: Implement break and continue byte codes, and add tests.
Also fixes a bug in the for-in-range optimiser. I hope to remove break and continue byte codes in the future and just use jump (if possible).
Diffstat (limited to 'py/compile.c')
-rw-r--r--py/compile.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/py/compile.c b/py/compile.c
index f61c4580c7..2aa98506d1 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -1442,24 +1442,27 @@ void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t pn_var,
comp->continue_label = continue_label;
int top_label = comp_next_label(comp);
+ int entry_label = comp_next_label(comp);
// compile: var = start
compile_node(comp, pn_start);
c_assign(comp, pn_var, ASSIGN_STORE);
- EMIT(jump, continue_label);
+ EMIT(jump, entry_label);
EMIT(label_assign, top_label);
// compile body
compile_node(comp, pn_body);
+ EMIT(label_assign, continue_label);
+
// compile: var += step
c_assign(comp, pn_var, ASSIGN_AUG_LOAD);
compile_node(comp, pn_step);
EMIT(binary_op, RT_BINARY_OP_INPLACE_ADD);
c_assign(comp, pn_var, ASSIGN_AUG_STORE);
- EMIT(label_assign, continue_label);
+ EMIT(label_assign, entry_label);
// compile: if var <cond> end: goto top
compile_node(comp, pn_var);