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
This commit is contained in:
parent
6211d979ee
commit
8a513da5a5
@ -950,7 +950,7 @@ STATIC void compile_break_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
|
|||||||
compile_syntax_error(comp, (mp_parse_node_t)pns, "'break' outside loop");
|
compile_syntax_error(comp, (mp_parse_node_t)pns, "'break' outside loop");
|
||||||
}
|
}
|
||||||
assert(comp->cur_except_level >= comp->break_continue_except_level);
|
assert(comp->cur_except_level >= comp->break_continue_except_level);
|
||||||
EMIT_ARG(break_loop, comp->break_label, comp->cur_except_level - comp->break_continue_except_level);
|
EMIT_ARG(unwind_jump, comp->break_label, comp->cur_except_level - comp->break_continue_except_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void compile_continue_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
|
STATIC void compile_continue_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
|
||||||
@ -958,7 +958,7 @@ STATIC void compile_continue_stmt(compiler_t *comp, mp_parse_node_struct_t *pns)
|
|||||||
compile_syntax_error(comp, (mp_parse_node_t)pns, "'continue' outside loop");
|
compile_syntax_error(comp, (mp_parse_node_t)pns, "'continue' outside loop");
|
||||||
}
|
}
|
||||||
assert(comp->cur_except_level >= comp->break_continue_except_level);
|
assert(comp->cur_except_level >= comp->break_continue_except_level);
|
||||||
EMIT_ARG(continue_loop, comp->continue_label, comp->cur_except_level - comp->break_continue_except_level);
|
EMIT_ARG(unwind_jump, comp->continue_label, comp->cur_except_level - comp->break_continue_except_level);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
|
STATIC void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
|
||||||
|
@ -122,8 +122,7 @@ typedef struct _emit_method_table_t {
|
|||||||
void (*jump)(emit_t *emit, mp_uint_t label);
|
void (*jump)(emit_t *emit, mp_uint_t label);
|
||||||
void (*pop_jump_if)(emit_t *emit, bool cond, mp_uint_t label);
|
void (*pop_jump_if)(emit_t *emit, bool cond, mp_uint_t label);
|
||||||
void (*jump_if_or_pop)(emit_t *emit, bool cond, mp_uint_t label);
|
void (*jump_if_or_pop)(emit_t *emit, bool cond, mp_uint_t label);
|
||||||
void (*break_loop)(emit_t *emit, mp_uint_t label, mp_uint_t except_depth);
|
void (*unwind_jump)(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 (*setup_with)(emit_t *emit, mp_uint_t label);
|
||||||
void (*with_cleanup)(emit_t *emit, mp_uint_t label);
|
void (*with_cleanup)(emit_t *emit, mp_uint_t label);
|
||||||
void (*setup_except)(emit_t *emit, mp_uint_t label);
|
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);
|
|||||||
void mp_emit_bc_pop_jump_if(emit_t *emit, bool cond, mp_uint_t label);
|
void mp_emit_bc_pop_jump_if(emit_t *emit, bool cond, mp_uint_t label);
|
||||||
void mp_emit_bc_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label);
|
void mp_emit_bc_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label);
|
||||||
void mp_emit_bc_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_depth);
|
void mp_emit_bc_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_depth);
|
||||||
#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_setup_with(emit_t *emit, mp_uint_t label);
|
||||||
void mp_emit_bc_with_cleanup(emit_t *emit, mp_uint_t label);
|
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_except(emit_t *emit, mp_uint_t label);
|
||||||
|
@ -967,7 +967,6 @@ const emit_method_table_t emit_bc_method_table = {
|
|||||||
mp_emit_bc_pop_jump_if,
|
mp_emit_bc_pop_jump_if,
|
||||||
mp_emit_bc_jump_if_or_pop,
|
mp_emit_bc_jump_if_or_pop,
|
||||||
mp_emit_bc_unwind_jump,
|
mp_emit_bc_unwind_jump,
|
||||||
mp_emit_bc_unwind_jump,
|
|
||||||
mp_emit_bc_setup_with,
|
mp_emit_bc_setup_with,
|
||||||
mp_emit_bc_with_cleanup,
|
mp_emit_bc_with_cleanup,
|
||||||
mp_emit_bc_setup_except,
|
mp_emit_bc_setup_except,
|
||||||
|
@ -1560,16 +1560,11 @@ STATIC void emit_native_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label)
|
|||||||
emit_post(emit);
|
emit_post(emit);
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void emit_native_break_loop(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) {
|
STATIC void emit_native_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) {
|
||||||
(void)except_depth;
|
(void)except_depth;
|
||||||
emit_native_jump(emit, label & ~MP_EMIT_BREAK_FROM_FOR); // TODO properly
|
emit_native_jump(emit, label & ~MP_EMIT_BREAK_FROM_FOR); // TODO properly
|
||||||
}
|
}
|
||||||
|
|
||||||
STATIC void emit_native_continue_loop(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) {
|
|
||||||
(void)except_depth;
|
|
||||||
emit_native_jump(emit, label); // TODO properly
|
|
||||||
}
|
|
||||||
|
|
||||||
STATIC void emit_native_setup_with(emit_t *emit, mp_uint_t label) {
|
STATIC void emit_native_setup_with(emit_t *emit, mp_uint_t label) {
|
||||||
// the context manager is on the top of the stack
|
// the context manager is on the top of the stack
|
||||||
// stack: (..., ctx_mgr)
|
// stack: (..., ctx_mgr)
|
||||||
@ -2248,8 +2243,7 @@ const emit_method_table_t EXPORT_FUN(method_table) = {
|
|||||||
emit_native_jump,
|
emit_native_jump,
|
||||||
emit_native_pop_jump_if,
|
emit_native_pop_jump_if,
|
||||||
emit_native_jump_if_or_pop,
|
emit_native_jump_if_or_pop,
|
||||||
emit_native_break_loop,
|
emit_native_unwind_jump,
|
||||||
emit_native_continue_loop,
|
|
||||||
emit_native_setup_with,
|
emit_native_setup_with,
|
||||||
emit_native_with_cleanup,
|
emit_native_with_cleanup,
|
||||||
emit_native_setup_except,
|
emit_native_setup_except,
|
||||||
|
Loading…
Reference in New Issue
Block a user