summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-12-11 17:35:23 +0000
committerDamien George <damien.p.george@gmail.com>2014-12-11 17:35:23 +0000
commitc33ce606cf9c374b6cbe97fe39461ad7d500bb7f (patch)
treeb02775ca5d41c02a01cf132531782a5a57bd92ba
parentf905145c6d93f6e8ae01c1addc818ecc0a96ac1c (diff)
downloadmicropython-c33ce606cf9c374b6cbe97fe39461ad7d500bb7f.tar.gz
micropython-c33ce606cf9c374b6cbe97fe39461ad7d500bb7f.zip
py: Fix a semantic issue with range optimisation.
Now you can assign to the range variable within the for loop and it will still work. Partially addresses issue #565.
-rw-r--r--py/compile.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/py/compile.c b/py/compile.c
index 25a4c960e7..dfc3e01af5 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -1796,7 +1796,8 @@ STATIC void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t p
// at this point we actually have 1 less element on the stack
EMIT_ARG(adjust_stack_size, -1);
- // store next value to var
+ // duplicate next value and store it to var
+ EMIT(dup_top);
c_assign(comp, pn_var, ASSIGN_STORE);
// compile body
@@ -1805,7 +1806,6 @@ STATIC void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t p
EMIT_ARG(label_assign, continue_label);
// compile: var + step, duplicated on stack
- compile_node(comp, pn_var);
compile_node(comp, pn_step);
EMIT_ARG(binary_op, MP_BINARY_OP_INPLACE_ADD);
EMIT(dup_top);