summaryrefslogtreecommitdiffstatshomepage
path: root/py/emitnative.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-02-15 12:18:59 +1100
committerDamien George <damien.p.george@gmail.com>2019-03-05 16:09:58 +1100
commit5a2599d96299ad37cda954f1de345159f9acf11c (patch)
tree13e82197f7494090b98a72f85f5aec3425d7cfa3 /py/emitnative.c
parent6f9e3ff719917616f163d3d671d6abe9472ba6ff (diff)
downloadmicropython-5a2599d96299ad37cda954f1de345159f9acf11c.tar.gz
micropython-5a2599d96299ad37cda954f1de345159f9acf11c.zip
py: Replace POP_BLOCK and POP_EXCEPT opcodes with POP_EXCEPT_JUMP.
POP_BLOCK and POP_EXCEPT are now the same, and are always followed by a JUMP. So this optimisation reduces code size, and RAM usage of bytecode by two bytes for each try-except handler.
Diffstat (limited to 'py/emitnative.c')
-rw-r--r--py/emitnative.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/py/emitnative.c b/py/emitnative.c
index 8b7ebe5301..c8a1a33d6b 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -1916,7 +1916,7 @@ STATIC void emit_native_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t exc
prev_finally->unwind_label = UNWIND_LABEL_DO_FINAL_UNWIND;
ASM_MOV_REG_PCREL(emit->as, REG_RET, label & ~MP_EMIT_BREAK_FROM_FOR);
ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_EXC_HANDLER_UNWIND(emit), REG_RET);
- // Cancel any active exception (see also emit_native_pop_except)
+ // Cancel any active exception (see also emit_native_pop_except_jump)
emit_native_mov_reg_const(emit, REG_RET, MP_F_CONST_NONE_OBJ);
ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_EXC_VAL(emit), REG_RET);
// Jump to the innermost active finally
@@ -2111,18 +2111,15 @@ STATIC void emit_native_for_iter_end(emit_t *emit) {
emit_post(emit);
}
-STATIC void emit_native_pop_block(emit_t *emit) {
- emit_native_pre(emit);
- if (!emit->exc_stack[emit->exc_stack_size - 1].is_finally) {
+STATIC void emit_native_pop_except_jump(emit_t *emit, mp_uint_t label, bool within_exc_handler) {
+ if (within_exc_handler) {
+ // Cancel any active exception so subsequent handlers don't see it
+ emit_native_mov_reg_const(emit, REG_TEMP0, MP_F_CONST_NONE_OBJ);
+ ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_EXC_VAL(emit), REG_TEMP0);
+ } else {
emit_native_leave_exc_stack(emit, false);
}
- emit_post(emit);
-}
-
-STATIC void emit_native_pop_except(emit_t *emit) {
- // Cancel any active exception so subsequent handlers don't see it
- emit_native_mov_reg_const(emit, REG_TEMP0, MP_F_CONST_NONE_OBJ);
- ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_EXC_VAL(emit), REG_TEMP0);
+ emit_native_jump(emit, label);
}
STATIC void emit_native_unary_op(emit_t *emit, mp_unary_op_t op) {
@@ -2726,8 +2723,7 @@ const emit_method_table_t EXPORT_FUN(method_table) = {
emit_native_get_iter,
emit_native_for_iter,
emit_native_for_iter_end,
- emit_native_pop_block,
- emit_native_pop_except,
+ emit_native_pop_except_jump,
emit_native_unary_op,
emit_native_binary_op,
emit_native_build,