py: Clean up some logic in VM to remove assert(0)'s.
Saves around 30 bytes code on Thumb2 archs.
This commit is contained in:
parent
aedf583af2
commit
5e1d993f54
31
py/vm.c
31
py/vm.c
@ -566,25 +566,20 @@ dispatch_loop:
|
|||||||
SET_TOP(mp_const_none);
|
SET_TOP(mp_const_none);
|
||||||
mp_call_function_n_kw(obj, 3, 0, no_exc);
|
mp_call_function_n_kw(obj, 3, 0, no_exc);
|
||||||
} else if (MP_OBJ_IS_SMALL_INT(TOP())) {
|
} else if (MP_OBJ_IS_SMALL_INT(TOP())) {
|
||||||
mp_obj_t cause = TOP();
|
mp_int_t cause_val = MP_OBJ_SMALL_INT_VALUE(TOP());
|
||||||
switch (MP_OBJ_SMALL_INT_VALUE(cause)) {
|
if (cause_val == UNWIND_RETURN) {
|
||||||
case UNWIND_RETURN:
|
|
||||||
mp_call_function_n_kw(sp[-2], 3, 0, no_exc);
|
mp_call_function_n_kw(sp[-2], 3, 0, no_exc);
|
||||||
break;
|
} else {
|
||||||
case UNWIND_JUMP:
|
assert(cause_val == UNWIND_JUMP);
|
||||||
with_cleanup_no_other_choice:
|
|
||||||
mp_call_function_n_kw(sp[-3], 3, 0, no_exc);
|
mp_call_function_n_kw(sp[-3], 3, 0, no_exc);
|
||||||
// Pop __exit__ boundmethod at sp[-3]
|
// Pop __exit__ boundmethod at sp[-3]
|
||||||
sp[-3] = sp[-2];
|
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[-2] = sp[-1]; // copy retval down
|
||||||
sp[-1] = sp[0]; // copy cause down
|
sp[-1] = sp[0]; // copy cause down
|
||||||
sp--; // discard top value (was cause)
|
sp--; // discard top value (was cause)
|
||||||
} else if (mp_obj_is_exception_type(TOP())) {
|
} else {
|
||||||
|
assert(mp_obj_is_exception_type(TOP()));
|
||||||
// Need to pass (sp[0], sp[-1], sp[-2]) as arguments so must reverse the
|
// 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
|
// order of these on the value stack (don't want to create a temporary
|
||||||
// array because it increases stack footprint of the VM).
|
// array because it increases stack footprint of the VM).
|
||||||
@ -612,8 +607,6 @@ dispatch_loop:
|
|||||||
sp[-1] = obj;
|
sp[-1] = obj;
|
||||||
sp--;
|
sp--;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
assert(0);
|
|
||||||
}
|
}
|
||||||
DISPATCH();
|
DISPATCH();
|
||||||
}
|
}
|
||||||
@ -672,19 +665,17 @@ unwind_jump:;
|
|||||||
}
|
}
|
||||||
if (TOP() == mp_const_none) {
|
if (TOP() == mp_const_none) {
|
||||||
sp--;
|
sp--;
|
||||||
} else if (MP_OBJ_IS_SMALL_INT(TOP())) {
|
} else {
|
||||||
|
assert(MP_OBJ_IS_SMALL_INT(TOP()));
|
||||||
// We finished "finally" coroutine and now dispatch back
|
// We finished "finally" coroutine and now dispatch back
|
||||||
// to our caller, based on TOS value
|
// to our caller, based on TOS value
|
||||||
mp_unwind_reason_t reason = MP_OBJ_SMALL_INT_VALUE(POP());
|
mp_unwind_reason_t reason = MP_OBJ_SMALL_INT_VALUE(POP());
|
||||||
switch (reason) {
|
if (reason == UNWIND_RETURN) {
|
||||||
case UNWIND_RETURN:
|
|
||||||
goto unwind_return;
|
goto unwind_return;
|
||||||
case UNWIND_JUMP:
|
} else {
|
||||||
|
assert(reason == UNWIND_JUMP);
|
||||||
goto unwind_jump;
|
goto unwind_jump;
|
||||||
}
|
}
|
||||||
assert(0);
|
|
||||||
} else {
|
|
||||||
assert(0);
|
|
||||||
}
|
}
|
||||||
DISPATCH();
|
DISPATCH();
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user