Skip to content

Commit d5e8182

Browse files
committed
py: Reduce size of mp_obj_fun_native_t struct by packing ints.
1 parent 5104775 commit d5e8182

2 files changed

Lines changed: 6 additions & 5 deletions

File tree

py/obj.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
5959
#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)
6060
#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)
6161
#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)
62-
#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)
62+
#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)
6363
#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)
64-
#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)
64+
#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)
6565

6666
// These macros are used to declare and define constant staticmethond and classmethod objects
6767
// 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);
372372
mp_obj_t mp_obj_new_bytearray_by_ref(uint n, void *items);
373373

374374
// functions
375+
#define MP_OBJ_FUN_ARGS_MAX (0xffff) // to set maximum value in n_args_max below
375376
typedef struct _mp_obj_fun_native_t { // need this so we can define const objects (to go in ROM)
376377
mp_obj_base_t base;
377378
bool is_kw : 1;
378-
machine_uint_t n_args_min : (8 * sizeof(machine_uint_t) - 1); // inclusive
379-
machine_uint_t n_args_max; // inclusive
379+
uint n_args_min : 15; // inclusive
380+
uint n_args_max : 16; // inclusive
380381
void *fun;
381382
// TODO add mp_map_t *globals
382383
// for const function objects, make an empty, const map

py/objfun.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ mp_obj_t rt_make_function_var(int n_args_min, mp_fun_var_t fun) {
121121
o->base.type = &fun_native_type;
122122
o->is_kw = false;
123123
o->n_args_min = n_args_min;
124-
o->n_args_max = ~((machine_uint_t)0);
124+
o->n_args_max = MP_OBJ_FUN_ARGS_MAX;
125125
o->fun = fun;
126126
return o;
127127
}

0 commit comments

Comments
 (0)