Skip to content

Commit ce8b4e8

Browse files
committed
py: Combine continuous block of emit steps into with_cleanup emit call.
Because different emitters need to handle with-cleanup in different ways.
1 parent 2c407bc commit ce8b4e8

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

py/compile.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1640,10 +1640,7 @@ STATIC void compile_with_stmt_helper(compiler_t *comp, int n, mp_parse_node_t *n
16401640
// compile additional pre-bits and the body
16411641
compile_with_stmt_helper(comp, n - 1, nodes + 1, body);
16421642
// finish this with block
1643-
EMIT(pop_block);
1644-
EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE);
1645-
EMIT_ARG(label_assign, l_end);
1646-
EMIT(with_cleanup);
1643+
EMIT_ARG(with_cleanup, l_end);
16471644
compile_decrease_except_level(comp);
16481645
EMIT(end_finally);
16491646
}

py/emit.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ typedef struct _emit_method_table_t {
106106
void (*break_loop)(emit_t *emit, mp_uint_t label, mp_uint_t except_depth);
107107
void (*continue_loop)(emit_t *emit, mp_uint_t label, mp_uint_t except_depth);
108108
void (*setup_with)(emit_t *emit, mp_uint_t label);
109-
void (*with_cleanup)(emit_t *emit);
109+
void (*with_cleanup)(emit_t *emit, mp_uint_t label);
110110
void (*setup_except)(emit_t *emit, mp_uint_t label);
111111
void (*setup_finally)(emit_t *emit, mp_uint_t label);
112112
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
227227
#define mp_emit_bc_break_loop mp_emit_bc_unwind_jump
228228
#define mp_emit_bc_continue_loop mp_emit_bc_unwind_jump
229229
void mp_emit_bc_setup_with(emit_t *emit, mp_uint_t label);
230-
void mp_emit_bc_with_cleanup(emit_t *emit);
230+
void mp_emit_bc_with_cleanup(emit_t *emit, mp_uint_t label);
231231
void mp_emit_bc_setup_except(emit_t *emit, mp_uint_t label);
232232
void mp_emit_bc_setup_finally(emit_t *emit, mp_uint_t label);
233233
void mp_emit_bc_end_finally(emit_t *emit);

py/emitbc.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,7 +758,10 @@ void mp_emit_bc_setup_with(emit_t *emit, mp_uint_t label) {
758758
emit_write_bytecode_byte_unsigned_label(emit, MP_BC_SETUP_WITH, label);
759759
}
760760

761-
void mp_emit_bc_with_cleanup(emit_t *emit) {
761+
void mp_emit_bc_with_cleanup(emit_t *emit, mp_uint_t label) {
762+
mp_emit_bc_pop_block(emit);
763+
mp_emit_bc_load_const_tok(emit, MP_TOKEN_KW_NONE);
764+
mp_emit_bc_label_assign(emit, label);
762765
emit_bc_pre(emit, -4);
763766
emit_write_bytecode_byte(emit, MP_BC_WITH_CLEANUP);
764767
}

py/emitnative.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1990,7 +1990,7 @@ STATIC void emit_native_setup_with(emit_t *emit, mp_uint_t label) {
19901990
assert(0);
19911991
}
19921992

1993-
STATIC void emit_native_with_cleanup(emit_t *emit) {
1993+
STATIC void emit_native_with_cleanup(emit_t *emit, mp_uint_t label) {
19941994
(void)emit;
19951995
assert(0);
19961996
}

0 commit comments

Comments
 (0)