From 652a58698edadfe9b587324197e6f922790cf05f Mon Sep 17 00:00:00 2001 From: Damien George Date: Mon, 6 Aug 2018 14:44:33 +1000 Subject: [PATCH] py/emitnative: Simplify handling of exception objects from nlr_buf_t. There is no need to have three copies of the exception object on the top of the native value stack. Instead, the values on the stack should be the first two items in an nlr_buf_t: the prev pointer and the ret_val pointer. This is all that is needed and is what the rest of the native emitter expects is on the stack. This patch is essentially an optimisation. Behaviour is unchanged, although the stack layout for native exception handling now makes more sense. --- py/emitnative.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/py/emitnative.c b/py/emitnative.c index 5b16990feb..cb653cee43 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -2205,18 +2205,14 @@ STATIC void emit_native_yield(emit_t *emit, int kind) { } STATIC void emit_native_start_except_handler(emit_t *emit) { - // This instruction follows an nlr_pop, so the stack counter is back to zero, when really + // This instruction follows a pop_block call, so the stack counter is up by one when really // it should be up by a whole nlr_buf_t. We then want to pop the nlr_buf_t here, but save // the first 2 elements, so we can get the thrown value. adjust_stack(emit, 1); - vtype_kind_t vtype_nlr; - emit_pre_pop_reg(emit, &vtype_nlr, REG_ARG_1); // get the thrown value - emit_pre_pop_discard(emit); // discard the linked-list pointer in the nlr_buf - emit_post_push_reg_reg_reg(emit, VTYPE_PYOBJ, REG_ARG_1, VTYPE_PYOBJ, REG_ARG_1, VTYPE_PYOBJ, REG_ARG_1); // push the 3 exception items } STATIC void emit_native_end_except_handler(emit_t *emit) { - adjust_stack(emit, -1); + (void)emit; } const emit_method_table_t EXPORT_FUN(method_table) = {