mirror of
https://github.com/micropython/micropython.git
synced 2026-01-07 04:30:24 +01:00
py/emit: Combine setup with/except/finally into one emit function.
This patch reduces code size by:
bare-arm: -16
minimal x86: -156
unix x64: -288
unix nanbox: -184
stm32: -48
cc3200: -16
esp8266: -96
esp32: -16
The last 10 patches combined reduce code size by:
bare-arm: -164
minimal x86: -1260
unix x64: -3416
unix nanbox: -1616
stm32: -676
cc3200: -232
esp8266: -1144
esp32: -268
This commit is contained in:
@@ -1617,6 +1617,21 @@ STATIC void emit_native_setup_with(emit_t *emit, mp_uint_t label) {
|
||||
// stack: (..., __exit__, self, as_value, nlr_buf, as_value)
|
||||
}
|
||||
|
||||
STATIC void emit_native_setup_block(emit_t *emit, mp_uint_t label, int kind) {
|
||||
if (kind == MP_EMIT_SETUP_BLOCK_WITH) {
|
||||
emit_native_setup_with(emit, label);
|
||||
} else {
|
||||
// Set up except and finally
|
||||
emit_native_pre(emit);
|
||||
// need to commit stack because we may jump elsewhere
|
||||
need_stack_settled(emit);
|
||||
emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_1, sizeof(nlr_buf_t) / sizeof(mp_uint_t)); // arg1 = pointer to nlr buf
|
||||
emit_call(emit, MP_F_NLR_PUSH);
|
||||
ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label);
|
||||
emit_post(emit);
|
||||
}
|
||||
}
|
||||
|
||||
STATIC void emit_native_with_cleanup(emit_t *emit, mp_uint_t label) {
|
||||
// note: label+1 is available as an auxiliary label
|
||||
|
||||
@@ -1686,20 +1701,6 @@ STATIC void emit_native_with_cleanup(emit_t *emit, mp_uint_t label) {
|
||||
emit_native_label_assign(emit, label + 1);
|
||||
}
|
||||
|
||||
STATIC void emit_native_setup_except(emit_t *emit, mp_uint_t label) {
|
||||
emit_native_pre(emit);
|
||||
// need to commit stack because we may jump elsewhere
|
||||
need_stack_settled(emit);
|
||||
emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_1, sizeof(nlr_buf_t) / sizeof(mp_uint_t)); // arg1 = pointer to nlr buf
|
||||
emit_call(emit, MP_F_NLR_PUSH);
|
||||
ASM_JUMP_IF_REG_NONZERO(emit->as, REG_RET, label);
|
||||
emit_post(emit);
|
||||
}
|
||||
|
||||
STATIC void emit_native_setup_finally(emit_t *emit, mp_uint_t label) {
|
||||
emit_native_setup_except(emit, label);
|
||||
}
|
||||
|
||||
STATIC void emit_native_end_finally(emit_t *emit) {
|
||||
// logic:
|
||||
// exc = pop_stack
|
||||
@@ -2254,10 +2255,8 @@ const emit_method_table_t EXPORT_FUN(method_table) = {
|
||||
emit_native_pop_jump_if,
|
||||
emit_native_jump_if_or_pop,
|
||||
emit_native_unwind_jump,
|
||||
emit_native_setup_with,
|
||||
emit_native_setup_block,
|
||||
emit_native_with_cleanup,
|
||||
emit_native_setup_except,
|
||||
emit_native_setup_finally,
|
||||
emit_native_end_finally,
|
||||
emit_native_get_iter,
|
||||
emit_native_for_iter,
|
||||
|
||||
Reference in New Issue
Block a user