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.
This commit is contained in:
Damien George 2014-12-11 17:35:23 +00:00
parent f905145c6d
commit c33ce606cf
1 changed files with 2 additions and 2 deletions

View File

@ -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 // at this point we actually have 1 less element on the stack
EMIT_ARG(adjust_stack_size, -1); 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); c_assign(comp, pn_var, ASSIGN_STORE);
// compile body // 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); EMIT_ARG(label_assign, continue_label);
// compile: var + step, duplicated on stack // compile: var + step, duplicated on stack
compile_node(comp, pn_var);
compile_node(comp, pn_step); compile_node(comp, pn_step);
EMIT_ARG(binary_op, MP_BINARY_OP_INPLACE_ADD); EMIT_ARG(binary_op, MP_BINARY_OP_INPLACE_ADD);
EMIT(dup_top); EMIT(dup_top);