Skip to content

Commit 0c595fa

Browse files
committed
py/objfun: Use if instead of switch to check return value of VM execute.
It's simpler and improves code coverage.
1 parent c71edae commit 0c595fa

1 file changed

Lines changed: 8 additions & 17 deletions

File tree

py/objfun.c

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -266,23 +266,14 @@ STATIC mp_obj_t fun_bc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
266266
#endif
267267

268268
mp_obj_t result;
269-
switch (vm_return_kind) {
270-
case MP_VM_RETURN_NORMAL:
271-
// return value is in *sp
272-
result = *code_state->sp;
273-
break;
274-
275-
case MP_VM_RETURN_EXCEPTION:
276-
// return value is in state[n_state - 1]
277-
result = code_state->state[n_state - 1];
278-
break;
279-
280-
case MP_VM_RETURN_YIELD: // byte-code shouldn't yield
281-
default:
282-
assert(0);
283-
result = mp_const_none;
284-
vm_return_kind = MP_VM_RETURN_NORMAL;
285-
break;
269+
if (vm_return_kind == MP_VM_RETURN_NORMAL) {
270+
// return value is in *sp
271+
result = *code_state->sp;
272+
} else {
273+
// must be an exception because normal functions can't yield
274+
assert(vm_return_kind == MP_VM_RETURN_EXCEPTION);
275+
// return value is in fastn[0]==state[n_state - 1]
276+
result = code_state->state[n_state - 1];
286277
}
287278

288279
// free the state if it was allocated on the heap

0 commit comments

Comments
 (0)