From ce8b4e87494a11f389de7629e82043d6fb70284e Mon Sep 17 00:00:00 2001 From: Damien George Date: Thu, 7 Apr 2016 08:50:38 +0100 Subject: [PATCH] py: Combine continuous block of emit steps into with_cleanup emit call. Because different emitters need to handle with-cleanup in different ways. --- py/compile.c | 5 +---- py/emit.h | 4 ++-- py/emitbc.c | 5 ++++- py/emitnative.c | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/py/compile.c b/py/compile.c index 9213fd22f5..aef59fb251 100644 --- a/py/compile.c +++ b/py/compile.c @@ -1640,10 +1640,7 @@ STATIC void compile_with_stmt_helper(compiler_t *comp, int n, mp_parse_node_t *n // compile additional pre-bits and the body compile_with_stmt_helper(comp, n - 1, nodes + 1, body); // finish this with block - EMIT(pop_block); - EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE); - EMIT_ARG(label_assign, l_end); - EMIT(with_cleanup); + EMIT_ARG(with_cleanup, l_end); compile_decrease_except_level(comp); EMIT(end_finally); } diff --git a/py/emit.h b/py/emit.h index 7e8e03393d..9121e719f7 100644 --- a/py/emit.h +++ b/py/emit.h @@ -106,7 +106,7 @@ typedef struct _emit_method_table_t { void (*break_loop)(emit_t *emit, mp_uint_t label, mp_uint_t except_depth); void (*continue_loop)(emit_t *emit, mp_uint_t label, mp_uint_t except_depth); void (*setup_with)(emit_t *emit, mp_uint_t label); - void (*with_cleanup)(emit_t *emit); + void (*with_cleanup)(emit_t *emit, mp_uint_t label); void (*setup_except)(emit_t *emit, mp_uint_t label); void (*setup_finally)(emit_t *emit, mp_uint_t label); void (*end_finally)(emit_t *emit); @@ -227,7 +227,7 @@ void mp_emit_bc_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_dept #define mp_emit_bc_break_loop mp_emit_bc_unwind_jump #define mp_emit_bc_continue_loop mp_emit_bc_unwind_jump void mp_emit_bc_setup_with(emit_t *emit, mp_uint_t label); -void mp_emit_bc_with_cleanup(emit_t *emit); +void mp_emit_bc_with_cleanup(emit_t *emit, mp_uint_t label); void mp_emit_bc_setup_except(emit_t *emit, mp_uint_t label); void mp_emit_bc_setup_finally(emit_t *emit, mp_uint_t label); void mp_emit_bc_end_finally(emit_t *emit); diff --git a/py/emitbc.c b/py/emitbc.c index 14298bad49..d871aa4ce9 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -758,7 +758,10 @@ void mp_emit_bc_setup_with(emit_t *emit, mp_uint_t label) { emit_write_bytecode_byte_unsigned_label(emit, MP_BC_SETUP_WITH, label); } -void mp_emit_bc_with_cleanup(emit_t *emit) { +void mp_emit_bc_with_cleanup(emit_t *emit, mp_uint_t label) { + mp_emit_bc_pop_block(emit); + mp_emit_bc_load_const_tok(emit, MP_TOKEN_KW_NONE); + mp_emit_bc_label_assign(emit, label); emit_bc_pre(emit, -4); emit_write_bytecode_byte(emit, MP_BC_WITH_CLEANUP); } diff --git a/py/emitnative.c b/py/emitnative.c index fc9922c1b0..04b465ba04 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -1990,7 +1990,7 @@ STATIC void emit_native_setup_with(emit_t *emit, mp_uint_t label) { assert(0); } -STATIC void emit_native_with_cleanup(emit_t *emit) { +STATIC void emit_native_with_cleanup(emit_t *emit, mp_uint_t label) { (void)emit; assert(0); }