From d5e81826ecc20ae3f862b7a6ae469990fd4c5b38 Mon Sep 17 00:00:00 2001 From: Damien George Date: Wed, 26 Feb 2014 17:47:05 +0000 Subject: [PATCH] py: Reduce size of mp_obj_fun_native_t struct by packing ints. --- py/obj.h | 9 +++++---- py/objfun.c | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/py/obj.h b/py/obj.h index b664b09443..c7ffb4619c 100644 --- a/py/obj.h +++ b/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 diff --git a/py/objfun.c b/py/objfun.c index 6cdc97cc6d..fa6a734d04 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -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; }