diff options
author | Damien George <damien.p.george@gmail.com> | 2014-01-21 23:48:04 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-01-21 23:48:04 +0000 |
commit | 600ae734cf3d0ca5274086b897f1ebaf20cf9d20 (patch) | |
tree | 5d05831a589eb5dd614a23dfae01c0fae74f0b93 /py/compile.c | |
parent | 2c302563820d18be5fcfed406582ea5edaa6b39f (diff) | |
download | micropython-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.c | 7 |
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); |