diff options
author | Damien George <damien.p.george@gmail.com> | 2015-02-26 17:54:50 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-02-26 17:54:50 +0000 |
commit | 12d6d777e1d4bfc08e25def72cc8783ad2e6cd14 (patch) | |
tree | fc63eff8c147c4c3518a828708fb553119171543 /py | |
parent | 74589cbeebf78018e73825db6c2b171ba41ca7cf (diff) | |
download | micropython-12d6d777e1d4bfc08e25def72cc8783ad2e6cd14.tar.gz micropython-12d6d777e1d4bfc08e25def72cc8783ad2e6cd14.zip |
py: Small optimisation of logic flow in BC_WITH_CLEANUP bytecode.
Slightly smaller code, and does not need to use C stack to save
temporaries.
Diffstat (limited to 'py')
-rw-r--r-- | py/vm.c | 26 |
1 files changed, 12 insertions, 14 deletions
@@ -566,26 +566,24 @@ dispatch_loop: SET_TOP(mp_const_none); mp_call_function_n_kw(obj, 3, 0, no_exc); } else if (MP_OBJ_IS_SMALL_INT(TOP())) { - mp_obj_t cause = POP(); + mp_obj_t cause = TOP(); switch (MP_OBJ_SMALL_INT_VALUE(cause)) { - case UNWIND_RETURN: { - mp_obj_t retval = POP(); - mp_call_function_n_kw(TOP(), 3, 0, no_exc); - SET_TOP(retval); - PUSH(cause); - break; - } - case UNWIND_JUMP: { + case UNWIND_RETURN: mp_call_function_n_kw(sp[-2], 3, 0, no_exc); - // Pop __exit__ boundmethod at sp[-2] - sp[-2] = sp[-1]; - sp[-1] = sp[0]; - SET_TOP(cause); break; - } + case UNWIND_JUMP: + with_cleanup_no_other_choice: + mp_call_function_n_kw(sp[-3], 3, 0, no_exc); + // Pop __exit__ boundmethod at sp[-3] + sp[-3] = sp[-2]; + break; default: assert(0); + goto with_cleanup_no_other_choice; // to help flow control analysis } + sp[-2] = sp[-1]; // copy retval down + sp[-1] = sp[0]; // copy cause down + sp--; // discard top value (was cause) } else if (mp_obj_is_exception_type(TOP())) { // Need to pass (sp[0], sp[-1], sp[-2]) as arguments so must reverse the // order of these on the value stack (don't want to create a temporary |