summaryrefslogtreecommitdiffstatshomepage
path: root/py/vm.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-03-25 22:20:37 +0000
committerDamien George <damien.p.george@gmail.com>2015-03-25 22:20:37 +0000
commit5e1d993f5444c4617813943ce8376a69c0fefa8f (patch)
treeca655d332746becf475e49c01ea4b68e65b8e363 /py/vm.c
parentaedf583af27207bc87ebdbf8f1191ac6cbeb1756 (diff)
downloadmicropython-5e1d993f5444c4617813943ce8376a69c0fefa8f.tar.gz
micropython-5e1d993f5444c4617813943ce8376a69c0fefa8f.zip
py: Clean up some logic in VM to remove assert(0)'s.
Saves around 30 bytes code on Thumb2 archs.
Diffstat (limited to 'py/vm.c')
-rw-r--r--py/vm.c43
1 files changed, 17 insertions, 26 deletions
diff --git a/py/vm.c b/py/vm.c
index 3e80b29163..ee218694c4 100644
--- a/py/vm.c
+++ b/py/vm.c
@@ -566,25 +566,20 @@ 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 = TOP();
- switch (MP_OBJ_SMALL_INT_VALUE(cause)) {
- case UNWIND_RETURN:
- mp_call_function_n_kw(sp[-2], 3, 0, no_exc);
- 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
+ mp_int_t cause_val = MP_OBJ_SMALL_INT_VALUE(TOP());
+ if (cause_val == UNWIND_RETURN) {
+ mp_call_function_n_kw(sp[-2], 3, 0, no_exc);
+ } else {
+ assert(cause_val == UNWIND_JUMP);
+ mp_call_function_n_kw(sp[-3], 3, 0, no_exc);
+ // Pop __exit__ boundmethod at sp[-3]
+ sp[-3] = sp[-2];
}
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())) {
+ } else {
+ assert(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
// array because it increases stack footprint of the VM).
@@ -612,8 +607,6 @@ dispatch_loop:
sp[-1] = obj;
sp--;
}
- } else {
- assert(0);
}
DISPATCH();
}
@@ -672,19 +665,17 @@ unwind_jump:;
}
if (TOP() == mp_const_none) {
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
// to our caller, based on TOS value
mp_unwind_reason_t reason = MP_OBJ_SMALL_INT_VALUE(POP());
- switch (reason) {
- case UNWIND_RETURN:
- goto unwind_return;
- case UNWIND_JUMP:
- goto unwind_jump;
+ if (reason == UNWIND_RETURN) {
+ goto unwind_return;
+ } else {
+ assert(reason == UNWIND_JUMP);
+ goto unwind_jump;
}
- assert(0);
- } else {
- assert(0);
}
DISPATCH();