Skip to content

Commit

Permalink
Use MP_DEFINE_CONST_DICT macro to define module dicts.
Browse files Browse the repository at this point in the history
This is just a clean-up of the code.  Generated code is exactly the
same.
  • Loading branch information
dpgeorge committed Nov 29, 2014
1 parent e636279 commit 3b603f2
Show file tree
Hide file tree
Showing 32 changed files with 34 additions and 313 deletions.
11 changes: 1 addition & 10 deletions esp8266/modpyb.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_sync), (mp_obj_t)&pyb_sync_obj },
};

STATIC const mp_obj_dict_t pyb_module_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(pyb_module_globals_table),
.alloc = MP_ARRAY_SIZE(pyb_module_globals_table),
.table = (mp_map_elem_t*)pyb_module_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table);

const mp_obj_module_t pyb_module = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions extmod/modubinascii.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,7 @@ STATIC const mp_map_elem_t mp_module_binascii_globals_table[] = {
// { MP_OBJ_NEW_QSTR(MP_QSTR_b2a_base64), (mp_obj_t)&mod_binascii_b2a_base64_obj },
};

STATIC const mp_obj_dict_t mp_module_binascii_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(mp_module_binascii_globals_table),
.alloc = MP_ARRAY_SIZE(mp_module_binascii_globals_table),
.table = (mp_map_elem_t*)mp_module_binascii_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_binascii_globals, mp_module_binascii_globals_table);

const mp_obj_module_t mp_module_ubinascii = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions extmod/moductypes.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,16 +649,7 @@ STATIC const mp_map_elem_t mp_module_uctypes_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_ARRAY), MP_OBJ_NEW_SMALL_INT(TYPE2SMALLINT(ARRAY, AGG_TYPE_BITS)) },
};

STATIC const mp_obj_dict_t mp_module_uctypes_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(mp_module_uctypes_globals_table),
.alloc = MP_ARRAY_SIZE(mp_module_uctypes_globals_table),
.table = (mp_map_elem_t*)mp_module_uctypes_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_uctypes_globals, mp_module_uctypes_globals_table);

const mp_obj_module_t mp_module_uctypes = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions extmod/moduhashlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,16 +105,7 @@ STATIC const mp_map_elem_t mp_module_hashlib_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_sha256), (mp_obj_t)&sha256_type },
};

STATIC const mp_obj_dict_t mp_module_hashlib_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(mp_module_hashlib_globals_table),
.alloc = MP_ARRAY_SIZE(mp_module_hashlib_globals_table),
.table = (mp_map_elem_t*)mp_module_hashlib_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_hashlib_globals, mp_module_hashlib_globals_table);

const mp_obj_module_t mp_module_uhashlib = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions extmod/moduheapq.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,7 @@ STATIC const mp_map_elem_t mp_module_uheapq_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_heapify), (mp_obj_t)&mod_uheapq_heapify_obj },
};

STATIC const mp_obj_dict_t mp_module_uheapq_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(mp_module_uheapq_globals_table),
.alloc = MP_ARRAY_SIZE(mp_module_uheapq_globals_table),
.table = (mp_map_elem_t*)mp_module_uheapq_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_uheapq_globals, mp_module_uheapq_globals_table);

const mp_obj_module_t mp_module_uheapq = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions extmod/modujson.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,16 +259,7 @@ STATIC const mp_map_elem_t mp_module_ujson_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_loads), (mp_obj_t)&mod_ujson_loads_obj },
};

STATIC const mp_obj_dict_t mp_module_ujson_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(mp_module_ujson_globals_table),
.alloc = MP_ARRAY_SIZE(mp_module_ujson_globals_table),
.table = (mp_map_elem_t*)mp_module_ujson_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_ujson_globals, mp_module_ujson_globals_table);

const mp_obj_module_t mp_module_ujson = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions extmod/modure.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,7 @@ STATIC const mp_map_elem_t mp_module_re_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_DEBUG), MP_OBJ_NEW_SMALL_INT(FLAG_DEBUG) },
};

STATIC const mp_obj_dict_t mp_module_re_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(mp_module_re_globals_table),
.alloc = MP_ARRAY_SIZE(mp_module_re_globals_table),
.table = (mp_map_elem_t*)mp_module_re_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_re_globals, mp_module_re_globals_table);

const mp_obj_module_t mp_module_ure = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions extmod/moduzlib.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,7 @@ STATIC const mp_map_elem_t mp_module_uzlib_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_decompress), (mp_obj_t)&mod_uzlib_decompress_obj },
};

STATIC const mp_obj_dict_t mp_module_uzlib_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(mp_module_uzlib_globals_table),
.alloc = MP_ARRAY_SIZE(mp_module_uzlib_globals_table),
.table = (mp_map_elem_t*)mp_module_uzlib_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_uzlib_globals, mp_module_uzlib_globals_table);

const mp_obj_module_t mp_module_uzlib = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions py/modarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,7 @@ STATIC const mp_map_elem_t mp_module_array_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_array), (mp_obj_t)&mp_type_array },
};

STATIC const mp_obj_dict_t mp_module_array_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(mp_module_array_globals_table),
.alloc = MP_ARRAY_SIZE(mp_module_array_globals_table),
.table = (mp_map_elem_t*)mp_module_array_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_array_globals, mp_module_array_globals_table);

const mp_obj_module_t mp_module_array = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions py/modcmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,7 @@ STATIC const mp_map_elem_t mp_module_cmath_globals_table[] = {
//{ MP_OBJ_NEW_QSTR(MP_QSTR_isnan), (mp_obj_t)&mp_cmath_isnan_obj },
};

STATIC const mp_obj_dict_t mp_module_cmath_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(mp_module_cmath_globals_table),
.alloc = MP_ARRAY_SIZE(mp_module_cmath_globals_table),
.table = (mp_map_elem_t*)mp_module_cmath_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_cmath_globals, mp_module_cmath_globals_table);

const mp_obj_module_t mp_module_cmath = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions py/modcollections.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,7 @@ STATIC const mp_map_elem_t mp_module_collections_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_namedtuple), (mp_obj_t)&mp_namedtuple_obj },
};

STATIC const mp_obj_dict_t mp_module_collections_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(mp_module_collections_globals_table),
.alloc = MP_ARRAY_SIZE(mp_module_collections_globals_table),
.table = (mp_map_elem_t*)mp_module_collections_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_collections_globals, mp_module_collections_globals_table);

const mp_obj_module_t mp_module_collections = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions py/modgc.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,16 +100,7 @@ STATIC const mp_map_elem_t mp_module_gc_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_mem_alloc), (mp_obj_t)&gc_mem_alloc_obj },
};

STATIC const mp_obj_dict_t mp_module_gc_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(mp_module_gc_globals_table),
.alloc = MP_ARRAY_SIZE(mp_module_gc_globals_table),
.table = (mp_map_elem_t*)mp_module_gc_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_gc_globals, mp_module_gc_globals_table);

const mp_obj_module_t mp_module_gc = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions py/modio.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,7 @@ STATIC const mp_map_elem_t mp_module_io_globals_table[] = {
#endif
};

STATIC const mp_obj_dict_t mp_module_io_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(mp_module_io_globals_table),
.alloc = MP_ARRAY_SIZE(mp_module_io_globals_table),
.table = (mp_map_elem_t*)mp_module_io_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_io_globals, mp_module_io_globals_table);

const mp_obj_module_t mp_module_io = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions py/modmath.c
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,7 @@ STATIC const mp_map_elem_t mp_module_math_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_lgamma), (mp_obj_t)&mp_math_lgamma_obj },
};

STATIC const mp_obj_dict_t mp_module_math_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(mp_module_math_globals_table),
.alloc = MP_ARRAY_SIZE(mp_module_math_globals_table),
.table = (mp_map_elem_t*)mp_module_math_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_math_globals, mp_module_math_globals_table);

const mp_obj_module_t mp_module_math = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions py/modmicropython.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,7 @@ STATIC const mp_map_elem_t mp_module_micropython_globals_table[] = {
#endif
};

STATIC const mp_obj_dict_t mp_module_micropython_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(mp_module_micropython_globals_table),
.alloc = MP_ARRAY_SIZE(mp_module_micropython_globals_table),
.table = (mp_map_elem_t*)mp_module_micropython_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_micropython_globals, mp_module_micropython_globals_table);

const mp_obj_module_t mp_module_micropython = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions py/modstruct.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,7 @@ STATIC const mp_map_elem_t mp_module_struct_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_unpack), (mp_obj_t)&struct_unpack_obj },
};

STATIC const mp_obj_dict_t mp_module_struct_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(mp_module_struct_globals_table),
.alloc = MP_ARRAY_SIZE(mp_module_struct_globals_table),
.table = (mp_map_elem_t*)mp_module_struct_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_struct_globals, mp_module_struct_globals_table);

const mp_obj_module_t mp_module_struct = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions py/modsys.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,16 +120,7 @@ STATIC const mp_map_elem_t mp_module_sys_globals_table[] = {
#endif
};

STATIC const mp_obj_dict_t mp_module_sys_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(mp_module_sys_globals_table),
.alloc = MP_ARRAY_SIZE(mp_module_sys_globals_table),
.table = (mp_map_elem_t*)mp_module_sys_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_sys_globals, mp_module_sys_globals_table);

const mp_obj_module_t mp_module_sys = {
.base = { &mp_type_module },
Expand Down
4 changes: 2 additions & 2 deletions py/obj.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
.map = { \
.all_keys_are_qstrs = 1, \
.table_is_fixed_array = 1, \
.used = sizeof(table_name) / sizeof(mp_map_elem_t), \
.alloc = sizeof(table_name) / sizeof(mp_map_elem_t), \
.used = MP_ARRAY_SIZE(table_name), \
.alloc = MP_ARRAY_SIZE(table_name), \
.table = (mp_map_elem_t*)table_name, \
}, \
}
Expand Down
13 changes: 2 additions & 11 deletions stmhal/make-stmconst.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,14 @@ def print_regs_as_submodules(reg_name, reg_defs, modules, needed_qstrs):

print("""};
STATIC const mp_obj_dict_t stm_%s_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = sizeof(stm_%s_globals_table) / sizeof(mp_map_elem_t),
.alloc = sizeof(stm_%s_globals_table) / sizeof(mp_map_elem_t),
.table = (mp_map_elem_t*)stm_%s_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(stm_%s_globals, stm_%s_globals_table);
const mp_obj_module_t stm_%s_obj = {
.base = { &mp_type_module },
.name = MP_QSTR_%s,
.globals = (mp_obj_dict_t*)&stm_%s_globals,
};
""" % (mod_name_lower, mod_name_lower, mod_name_lower, mod_name_lower, mod_name_lower, mod_name_upper, mod_name_lower))
""" % (mod_name_lower, mod_name_lower, mod_name_lower, mod_name_upper, mod_name_lower))

def main():
cmd_parser = argparse.ArgumentParser(description='Extract ST constants from a C header file.')
Expand Down
11 changes: 1 addition & 10 deletions stmhal/modnetwork.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,16 +79,7 @@ STATIC const mp_map_elem_t mp_module_network_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_route), (mp_obj_t)&network_route_obj },
};

STATIC const mp_obj_dict_t mp_module_network_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(mp_module_network_globals_table),
.alloc = MP_ARRAY_SIZE(mp_module_network_globals_table),
.table = (mp_map_elem_t*)mp_module_network_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(mp_module_network_globals, mp_module_network_globals_table);

const mp_obj_module_t mp_module_network = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions stmhal/modpyb.c
Original file line number Diff line number Diff line change
Expand Up @@ -574,16 +574,7 @@ STATIC const mp_map_elem_t pyb_module_globals_table[] = {
#endif
};

STATIC const mp_obj_dict_t pyb_module_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(pyb_module_globals_table),
.alloc = MP_ARRAY_SIZE(pyb_module_globals_table),
.table = (mp_map_elem_t*)pyb_module_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table);

const mp_obj_module_t pyb_module = {
.base = { &mp_type_module },
Expand Down
11 changes: 1 addition & 10 deletions stmhal/modstm.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,16 +126,7 @@ STATIC const mp_map_elem_t stm_module_globals_table[] = {
#include "modstmconst.gen.c"
};

STATIC const mp_obj_dict_t stm_module_globals = {
.base = {&mp_type_dict},
.map = {
.all_keys_are_qstrs = 1,
.table_is_fixed_array = 1,
.used = MP_ARRAY_SIZE(stm_module_globals_table),
.alloc = MP_ARRAY_SIZE(stm_module_globals_table),
.table = (mp_map_elem_t*)stm_module_globals_table,
},
};
STATIC MP_DEFINE_CONST_DICT(stm_module_globals, stm_module_globals_table);

const mp_obj_module_t stm_module = {
.base = { &mp_type_module },
Expand Down
Loading

0 comments on commit 3b603f2

Please sign in to comment.