Skip to content

Commit 8b56beb

Browse files
committed
py: Simplified rt_call_function_n_kw.
1 parent f3b0544 commit 8b56beb

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

py/runtime.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -737,17 +737,14 @@ mp_obj_t rt_call_function_n_kw(mp_obj_t fun_in, uint n_args, uint n_kw, const mp
737737

738738
DEBUG_OP_printf("calling function %p(n_args=%d, n_kw=%d, args=%p)\n", fun_in, n_args, n_kw, args);
739739

740-
if (MP_OBJ_IS_SMALL_INT(fun_in)) {
741-
nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError, "'int' object is not callable"));
742-
} else if(MP_OBJ_IS_STR(fun_in)) {
743-
nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError, "'str' object is not callable"));
740+
// get the type
741+
mp_obj_type_t *type = mp_obj_get_type(fun_in);
742+
743+
// do the call
744+
if (type->call != NULL) {
745+
return type->call(fun_in, n_args, n_kw, args);
744746
} else {
745-
mp_obj_base_t *fun = fun_in;
746-
if (fun->type->call != NULL) {
747-
return fun->type->call(fun_in, n_args, n_kw, args);
748-
} else {
749-
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "'%s' object is not callable", fun->type->name));
750-
}
747+
nlr_jump(mp_obj_new_exception_msg_varg(MP_QSTR_TypeError, "'%s' object is not callable", type->name));
751748
}
752749
}
753750

0 commit comments

Comments
 (0)