summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-06-03 13:40:16 +0100
committerDamien George <damien.p.george@gmail.com>2014-06-03 13:40:16 +0100
commit3f5226246517be2f28d4f23d6e4c202047915f83 (patch)
tree2b41b45e06e2b6dd89af217c813021bbdcb1c818
parent65ec33200ada958066bea0914120045acdb5e410 (diff)
downloadmicropython-3f5226246517be2f28d4f23d6e4c202047915f83.tar.gz
micropython-3f5226246517be2f28d4f23d6e4c202047915f83.zip
py: Allow tail call optimisation in mp_call_function_n_kw.
This saves 4 words of stack space per Python call.
-rw-r--r--py/objtype.c2
-rw-r--r--py/runtime.c5
2 files changed, 2 insertions, 5 deletions
diff --git a/py/objtype.c b/py/objtype.c
index ebbb6097dd..a51e12f1fd 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -516,7 +516,7 @@ STATIC mp_obj_t instance_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp
mp_obj_t member[2] = {MP_OBJ_NULL};
mp_obj_class_lookup(self, self->base.type, MP_QSTR___call__, offsetof(mp_obj_type_t, call), member);
if (member[0] == MP_OBJ_NULL) {
- return MP_OBJ_NULL;
+ nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object is not callable", mp_obj_get_type_str(self_in)));
}
if (member[0] == MP_OBJ_SENTINEL) {
return mp_call_function_n_kw(self->subobj[0], n_args, n_kw, args);
diff --git a/py/runtime.c b/py/runtime.c
index 27a5ed5439..f13cc1d892 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -526,10 +526,7 @@ mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, uint n_args, uint n_kw, const mp
// do the call
if (type->call != NULL) {
- mp_obj_t res = type->call(fun_in, n_args, n_kw, args);
- if (res != NULL) {
- return res;
- }
+ return type->call(fun_in, n_args, n_kw, args);
}
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "'%s' object is not callable", mp_obj_get_type_str(fun_in)));