vm: Implement "with" statement (SETUP_WITH and WITH_CLEANUP bytecodes).

This commit is contained in:
Paul Sokolovsky
2014-03-29 04:10:11 +02:00
parent 682f9e639d
commit 44307d5ef8
3 changed files with 73 additions and 2 deletions

View File

@@ -1798,6 +1798,7 @@ void compile_with_stmt_helper(compiler_t *comp, int n, mp_parse_node_t *nodes, m
EMIT_ARG(setup_with, l_end);
EMIT(pop_top);
}
compile_increase_except_level(comp);
// compile additional pre-bits and the body
compile_with_stmt_helper(comp, n - 1, nodes + 1, body);
// finish this with block
@@ -1805,6 +1806,7 @@ void compile_with_stmt_helper(compiler_t *comp, int n, mp_parse_node_t *nodes, m
EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE);
EMIT_ARG(label_assign, l_end);
EMIT(with_cleanup);
compile_decrease_except_level(comp);
EMIT(end_finally);
}
}