diff --git a/py/modbuiltins.c b/py/modbuiltins.c index 26a84f57b3..5631798fb6 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -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); diff --git a/py/modcmath.c b/py/modcmath.c index fb1f2a8fc2..44a4736e09 100644 --- a/py/modcmath.c +++ b/py/modcmath.c @@ -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 diff --git a/py/modcollections.c b/py/modcollections.c index c145f12cc6..0c008579f8 100644 --- a/py/modcollections.c +++ b/py/modcollections.c @@ -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 diff --git a/py/modgc.c b/py/modgc.c index 534a711c16..0ae3a84ae8 100644 --- a/py/modgc.c +++ b/py/modgc.c @@ -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 diff --git a/py/modio.c b/py/modio.c index 3e37231f23..72e633bd9f 100644 --- a/py/modio.c +++ b/py/modio.c @@ -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 diff --git a/py/modmath.c b/py/modmath.c index 8fc821c9d5..764f59e1cb 100644 --- a/py/modmath.c +++ b/py/modmath.c @@ -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 diff --git a/py/modmicropython.c b/py/modmicropython.c index 180f7f186c..a2faa9a9f0 100644 --- a/py/modmicropython.c +++ b/py/modmicropython.c @@ -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); diff --git a/py/modstruct.c b/py/modstruct.c index 4cbcad6d49..2cbf691afb 100644 --- a/py/modstruct.c +++ b/py/modstruct.c @@ -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 diff --git a/py/modsys.c b/py/modsys.c index 4ddc27fc51..e3fb697eb1 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -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 diff --git a/py/modthread.c b/py/modthread.c index d22b1854cd..11d0405e71 100644 --- a/py/modthread.c +++ b/py/modthread.c @@ -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 diff --git a/py/objmodule.c b/py/objmodule.c index d550e77556..f93669a11c 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -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 diff --git a/py/runtime.c b/py/runtime.c index 184de7bc96..8c857fec27 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -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();