py: Make builtin modules use MP_REGISTER_MODULE.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This commit is contained in:
Jim Mussared 2022-04-20 16:14:22 +10:00
parent 4eab44a1ec
commit d8d3e6ae78
12 changed files with 23 additions and 33 deletions

View File

@ -784,3 +784,5 @@ const mp_obj_module_t mp_module_builtins = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&mp_module_builtins_globals,
};
MP_REGISTER_MODULE(MP_QSTR_builtins, mp_module_builtins, 1);

View File

@ -149,4 +149,6 @@ const mp_obj_module_t mp_module_cmath = {
.globals = (mp_obj_dict_t *)&mp_module_cmath_globals,
};
#endif // MICROPY_PY_BUILTINS_FLOAT && MICROPY_PY_CMATH
MP_REGISTER_MODULE(MP_QSTR_cmath, mp_module_cmath, MICROPY_PY_BUILTINS_FLOAT && MICROPY_PY_BUILTINS_COMPLEX && MICROPY_PY_CMATH);
#endif // MICROPY_PY_BUILTINS_FLOAT && MICROPY_PY_BUILTINS_COMPLEX && MICROPY_PY_CMATH

View File

@ -46,4 +46,6 @@ const mp_obj_module_t mp_module_collections = {
.globals = (mp_obj_dict_t *)&mp_module_collections_globals,
};
MP_REGISTER_MODULE(MP_QSTR_ucollections, mp_module_collections, MICROPY_PY_COLLECTIONS);
#endif // MICROPY_PY_COLLECTIONS

View File

@ -115,4 +115,6 @@ const mp_obj_module_t mp_module_gc = {
.globals = (mp_obj_dict_t *)&mp_module_gc_globals,
};
MP_REGISTER_MODULE(MP_QSTR_gc, mp_module_gc, MICROPY_PY_GC && MICROPY_ENABLE_GC);
#endif

View File

@ -233,4 +233,6 @@ const mp_obj_module_t mp_module_io = {
.globals = (mp_obj_dict_t *)&mp_module_io_globals,
};
MP_REGISTER_MODULE(MP_QSTR_uio, mp_module_io, MICROPY_PY_IO);
#endif

View File

@ -435,4 +435,6 @@ const mp_obj_module_t mp_module_math = {
.globals = (mp_obj_dict_t *)&mp_module_math_globals,
};
MP_REGISTER_MODULE(MP_QSTR_math, mp_module_math, MICROPY_PY_BUILTINS_FLOAT && MICROPY_PY_MATH);
#endif // MICROPY_PY_BUILTINS_FLOAT && MICROPY_PY_MATH

View File

@ -209,3 +209,5 @@ const mp_obj_module_t mp_module_micropython = {
.base = { &mp_type_module },
.globals = (mp_obj_dict_t *)&mp_module_micropython_globals,
};
MP_REGISTER_MODULE(MP_QSTR_micropython, mp_module_micropython, 1);

View File

@ -266,4 +266,6 @@ const mp_obj_module_t mp_module_ustruct = {
.globals = (mp_obj_dict_t *)&mp_module_struct_globals,
};
MP_REGISTER_MODULE(MP_QSTR_ustruct, mp_module_ustruct, MICROPY_PY_STRUCT);
#endif

View File

@ -284,4 +284,6 @@ const mp_obj_module_t mp_module_sys = {
.globals = (mp_obj_dict_t *)&mp_module_sys_globals,
};
MP_REGISTER_MODULE(MP_QSTR_usys, mp_module_sys, MICROPY_PY_SYS);
#endif

View File

@ -300,4 +300,6 @@ const mp_obj_module_t mp_module_thread = {
.globals = (mp_obj_dict_t *)&mp_module_thread_globals,
};
MP_REGISTER_MODULE(MP_QSTR__thread, mp_module_thread, MICROPY_PY_THREAD);
#endif // MICROPY_PY_THREAD

View File

@ -161,38 +161,6 @@ mp_obj_t mp_obj_new_module(qstr module_name) {
// Global module table and related functions
STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = {
{ MP_ROM_QSTR(MP_QSTR___main__), MP_ROM_PTR(&mp_module___main__) },
{ MP_ROM_QSTR(MP_QSTR_builtins), MP_ROM_PTR(&mp_module_builtins) },
{ MP_ROM_QSTR(MP_QSTR_micropython), MP_ROM_PTR(&mp_module_micropython) },
#if MICROPY_PY_IO
{ MP_ROM_QSTR(MP_QSTR_uio), MP_ROM_PTR(&mp_module_io) },
#endif
#if MICROPY_PY_COLLECTIONS
{ MP_ROM_QSTR(MP_QSTR_ucollections), MP_ROM_PTR(&mp_module_collections) },
#endif
#if MICROPY_PY_STRUCT
{ MP_ROM_QSTR(MP_QSTR_ustruct), MP_ROM_PTR(&mp_module_ustruct) },
#endif
#if MICROPY_PY_BUILTINS_FLOAT
#if MICROPY_PY_MATH
{ MP_ROM_QSTR(MP_QSTR_math), MP_ROM_PTR(&mp_module_math) },
#endif
#if MICROPY_PY_BUILTINS_COMPLEX && MICROPY_PY_CMATH
{ MP_ROM_QSTR(MP_QSTR_cmath), MP_ROM_PTR(&mp_module_cmath) },
#endif
#endif
#if MICROPY_PY_SYS
{ MP_ROM_QSTR(MP_QSTR_usys), MP_ROM_PTR(&mp_module_sys) },
#endif
#if MICROPY_PY_GC && MICROPY_ENABLE_GC
{ MP_ROM_QSTR(MP_QSTR_gc), MP_ROM_PTR(&mp_module_gc) },
#endif
#if MICROPY_PY_THREAD
{ MP_ROM_QSTR(MP_QSTR__thread), MP_ROM_PTR(&mp_module_thread) },
#endif
// extra builtin modules as defined by a port
MICROPY_PORT_BUILTIN_MODULES

View File

@ -59,6 +59,8 @@ const mp_obj_module_t mp_module___main__ = {
.globals = (mp_obj_dict_t *)&MP_STATE_VM(dict_main),
};
MP_REGISTER_MODULE(MP_QSTR___main__, mp_module___main__, 1);
void mp_init(void) {
qstr_init();