summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
Diffstat (limited to 'py')
-rw-r--r--py/objfun.c37
-rw-r--r--py/objstr.c1
-rw-r--r--py/runtime.c7
-rw-r--r--py/runtime.h6
4 files changed, 7 insertions, 44 deletions
diff --git a/py/objfun.c b/py/objfun.c
index b8ebce7a39..ba3ce6279f 100644
--- a/py/objfun.c
+++ b/py/objfun.c
@@ -98,42 +98,13 @@ const mp_obj_type_t fun_native_type = {
.call_n_kw = fun_native_call_n_kw,
};
-mp_obj_t rt_make_function_0(mp_fun_0_t fun) {
+// fun must have the correct signature for n_args fixed arguments
+mp_obj_t rt_make_function_n(int n_args, void *fun) {
mp_obj_fun_native_t *o = m_new_obj(mp_obj_fun_native_t);
o->base.type = &fun_native_type;
o->is_kw = false;
- o->n_args_min = 0;
- o->n_args_max = 0;
- o->fun = fun;
- return o;
-}
-
-mp_obj_t rt_make_function_1(mp_fun_1_t fun) {
- mp_obj_fun_native_t *o = m_new_obj(mp_obj_fun_native_t);
- o->base.type = &fun_native_type;
- o->is_kw = false;
- o->n_args_min = 1;
- o->n_args_max = 1;
- o->fun = fun;
- return o;
-}
-
-mp_obj_t rt_make_function_2(mp_fun_2_t fun) {
- mp_obj_fun_native_t *o = m_new_obj(mp_obj_fun_native_t);
- o->base.type = &fun_native_type;
- o->is_kw = false;
- o->n_args_min = 2;
- o->n_args_max = 2;
- o->fun = fun;
- return o;
-}
-
-mp_obj_t rt_make_function_3(mp_fun_3_t fun) {
- mp_obj_fun_native_t *o = m_new_obj(mp_obj_fun_native_t);
- o->base.type = &fun_native_type;
- o->is_kw = false;
- o->n_args_min = 3;
- o->n_args_max = 3;
+ o->n_args_min = n_args;
+ o->n_args_max = n_args;
o->fun = fun;
return o;
}
diff --git a/py/objstr.c b/py/objstr.c
index a1c35bad3b..f48bde6001 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -3,7 +3,6 @@
#include <stdarg.h>
#include <string.h>
#include <assert.h>
-#include <sys/types.h>
#include "nlr.h"
#include "misc.h"
diff --git a/py/runtime.c b/py/runtime.c
index 766a321bc4..f43e804b40 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -587,12 +587,7 @@ mp_obj_t rt_make_function_from_id(int unique_code_id) {
fun = mp_obj_new_fun_bc(c->n_args, c->n_locals + c->n_stack, c->u_byte.code);
break;
case MP_CODE_NATIVE:
- switch (c->n_args) {
- case 0: fun = rt_make_function_0(c->u_native.fun); break;
- case 1: fun = rt_make_function_1((mp_fun_1_t)c->u_native.fun); break;
- case 2: fun = rt_make_function_2((mp_fun_2_t)c->u_native.fun); break;
- default: assert(0); fun = mp_const_none;
- }
+ fun = rt_make_function_n(c->n_args, c->u_native.fun);
break;
case MP_CODE_INLINE_ASM:
fun = mp_obj_new_fun_asm(c->n_args, c->u_inline_asm.fun);
diff --git a/py/runtime.h b/py/runtime.h
index ac53e14110..32cb47684f 100644
--- a/py/runtime.h
+++ b/py/runtime.h
@@ -12,10 +12,8 @@ void rt_store_global(qstr qstr, mp_obj_t obj);
mp_obj_t rt_unary_op(int op, mp_obj_t arg);
mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs);
mp_obj_t rt_make_function_from_id(int unique_code_id);
-mp_obj_t rt_make_function_0(mp_fun_0_t f);
-mp_obj_t rt_make_function_1(mp_fun_1_t f);
-mp_obj_t rt_make_function_2(mp_fun_2_t f);
-mp_obj_t rt_make_function_var(int n_args_min, mp_fun_var_t f);
+mp_obj_t rt_make_function_n(int n_args, void *fun); // fun must have the correct signature for n_args fixed arguments
+mp_obj_t rt_make_function_var(int n_args_min, mp_fun_var_t fun);
mp_obj_t rt_make_function_var_between(int n_args_min, int n_args_max, mp_fun_var_t fun); // min and max are inclusive
mp_obj_t rt_make_closure_from_id(int unique_code_id, mp_obj_t closure_tuple);
mp_obj_t rt_call_function_0(mp_obj_t fun);