Skip to content

Commit 8a513da

Browse files
committed
py/emit: Combine break_loop and continue_loop into one emit function.
Reduces code size by: bare-arm: +0 minimal x86: +0 unix x64: -80 unix nanbox: +0 stm32: -12 cc3200: +0 esp8266: -28 esp32: +0
1 parent 6211d97 commit 8a513da

4 files changed

Lines changed: 5 additions & 15 deletions

File tree

py/compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -950,15 +950,15 @@ STATIC void compile_break_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
950950
compile_syntax_error(comp, (mp_parse_node_t)pns, "'break' outside loop");
951951
}
952952
assert(comp->cur_except_level >= comp->break_continue_except_level);
953-
EMIT_ARG(break_loop, comp->break_label, comp->cur_except_level - comp->break_continue_except_level);
953+
EMIT_ARG(unwind_jump, comp->break_label, comp->cur_except_level - comp->break_continue_except_level);
954954
}
955955

956956
STATIC void compile_continue_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
957957
if (comp->continue_label == INVALID_LABEL) {
958958
compile_syntax_error(comp, (mp_parse_node_t)pns, "'continue' outside loop");
959959
}
960960
assert(comp->cur_except_level >= comp->break_continue_except_level);
961-
EMIT_ARG(continue_loop, comp->continue_label, comp->cur_except_level - comp->break_continue_except_level);
961+
EMIT_ARG(unwind_jump, comp->continue_label, comp->cur_except_level - comp->break_continue_except_level);
962962
}
963963

964964
STATIC void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {

py/emit.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ typedef struct _emit_method_table_t {
122122
void (*jump)(emit_t *emit, mp_uint_t label);
123123
void (*pop_jump_if)(emit_t *emit, bool cond, mp_uint_t label);
124124
void (*jump_if_or_pop)(emit_t *emit, bool cond, mp_uint_t label);
125-
void (*break_loop)(emit_t *emit, mp_uint_t label, mp_uint_t except_depth);
126-
void (*continue_loop)(emit_t *emit, mp_uint_t label, mp_uint_t except_depth);
125+
void (*unwind_jump)(emit_t *emit, mp_uint_t label, mp_uint_t except_depth);
127126
void (*setup_with)(emit_t *emit, mp_uint_t label);
128127
void (*with_cleanup)(emit_t *emit, mp_uint_t label);
129128
void (*setup_except)(emit_t *emit, mp_uint_t label);
@@ -227,8 +226,6 @@ void mp_emit_bc_jump(emit_t *emit, mp_uint_t label);
227226
void mp_emit_bc_pop_jump_if(emit_t *emit, bool cond, mp_uint_t label);
228227
void mp_emit_bc_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label);
229228
void mp_emit_bc_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_depth);
230-
#define mp_emit_bc_break_loop mp_emit_bc_unwind_jump
231-
#define mp_emit_bc_continue_loop mp_emit_bc_unwind_jump
232229
void mp_emit_bc_setup_with(emit_t *emit, mp_uint_t label);
233230
void mp_emit_bc_with_cleanup(emit_t *emit, mp_uint_t label);
234231
void mp_emit_bc_setup_except(emit_t *emit, mp_uint_t label);

py/emitbc.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -967,7 +967,6 @@ const emit_method_table_t emit_bc_method_table = {
967967
mp_emit_bc_pop_jump_if,
968968
mp_emit_bc_jump_if_or_pop,
969969
mp_emit_bc_unwind_jump,
970-
mp_emit_bc_unwind_jump,
971970
mp_emit_bc_setup_with,
972971
mp_emit_bc_with_cleanup,
973972
mp_emit_bc_setup_except,

py/emitnative.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1560,16 +1560,11 @@ STATIC void emit_native_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label)
15601560
emit_post(emit);
15611561
}
15621562

1563-
STATIC void emit_native_break_loop(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) {
1563+
STATIC void emit_native_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) {
15641564
(void)except_depth;
15651565
emit_native_jump(emit, label & ~MP_EMIT_BREAK_FROM_FOR); // TODO properly
15661566
}
15671567

1568-
STATIC void emit_native_continue_loop(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) {
1569-
(void)except_depth;
1570-
emit_native_jump(emit, label); // TODO properly
1571-
}
1572-
15731568
STATIC void emit_native_setup_with(emit_t *emit, mp_uint_t label) {
15741569
// the context manager is on the top of the stack
15751570
// stack: (..., ctx_mgr)
@@ -2248,8 +2243,7 @@ const emit_method_table_t EXPORT_FUN(method_table) = {
22482243
emit_native_jump,
22492244
emit_native_pop_jump_if,
22502245
emit_native_jump_if_or_pop,
2251-
emit_native_break_loop,
2252-
emit_native_continue_loop,
2246+
emit_native_unwind_jump,
22532247
emit_native_setup_with,
22542248
emit_native_with_cleanup,
22552249
emit_native_setup_except,

0 commit comments

Comments
 (0)