py: Reduce size of mp_obj_fun_native_t struct by packing ints.
This commit is contained in:
parent
510477557d
commit
d5e81826ec
9
py/obj.h
9
py/obj.h
|
@ -59,9 +59,9 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
|
|||
#define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, 1, 1, (mp_fun_1_t)fun_name)
|
||||
#define MP_DEFINE_CONST_FUN_OBJ_2(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, 2, 2, (mp_fun_2_t)fun_name)
|
||||
#define MP_DEFINE_CONST_FUN_OBJ_3(obj_name, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, 3, 3, (mp_fun_3_t)fun_name)
|
||||
#define MP_DEFINE_CONST_FUN_OBJ_VAR(obj_name, n_args_min, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, n_args_min, (~((machine_uint_t)0)), (mp_fun_var_t)fun_name)
|
||||
#define MP_DEFINE_CONST_FUN_OBJ_VAR(obj_name, n_args_min, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, n_args_min, MP_OBJ_FUN_ARGS_MAX, (mp_fun_var_t)fun_name)
|
||||
#define MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name, n_args_min, n_args_max, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, n_args_min, n_args_max, (mp_fun_var_t)fun_name)
|
||||
#define MP_DEFINE_CONST_FUN_OBJ_KW(obj_name, n_args_min, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, true, n_args_min, (~((machine_uint_t)0)), (mp_fun_kw_t)fun_name)
|
||||
#define MP_DEFINE_CONST_FUN_OBJ_KW(obj_name, n_args_min, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, true, n_args_min, MP_OBJ_FUN_ARGS_MAX, (mp_fun_kw_t)fun_name)
|
||||
|
||||
// These macros are used to declare and define constant staticmethond and classmethod objects
|
||||
// You can put "static" in front of the definitions to make them local
|
||||
|
@ -372,11 +372,12 @@ uint mp_obj_array_len(mp_obj_t self_in);
|
|||
mp_obj_t mp_obj_new_bytearray_by_ref(uint n, void *items);
|
||||
|
||||
// functions
|
||||
#define MP_OBJ_FUN_ARGS_MAX (0xffff) // to set maximum value in n_args_max below
|
||||
typedef struct _mp_obj_fun_native_t { // need this so we can define const objects (to go in ROM)
|
||||
mp_obj_base_t base;
|
||||
bool is_kw : 1;
|
||||
machine_uint_t n_args_min : (8 * sizeof(machine_uint_t) - 1); // inclusive
|
||||
machine_uint_t n_args_max; // inclusive
|
||||
uint n_args_min : 15; // inclusive
|
||||
uint n_args_max : 16; // inclusive
|
||||
void *fun;
|
||||
// TODO add mp_map_t *globals
|
||||
// for const function objects, make an empty, const map
|
||||
|
|
|
@ -121,7 +121,7 @@ mp_obj_t rt_make_function_var(int n_args_min, mp_fun_var_t fun) {
|
|||
o->base.type = &fun_native_type;
|
||||
o->is_kw = false;
|
||||
o->n_args_min = n_args_min;
|
||||
o->n_args_max = ~((machine_uint_t)0);
|
||||
o->n_args_max = MP_OBJ_FUN_ARGS_MAX;
|
||||
o->fun = fun;
|
||||
return o;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue