Commit 93c4a6a3 authored by Damien George's avatar Damien George
Browse files

all: Remove 'name' member from mp_obj_module_t struct.

One can instead lookup __name__ in the modules dict to get the value.
parent b0a46900
...@@ -294,7 +294,6 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_thread_globals, mp_module_thread_globals_t ...@@ -294,7 +294,6 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_thread_globals, mp_module_thread_globals_t
const mp_obj_module_t mp_module_thread = { const mp_obj_module_t mp_module_thread = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR__thread,
.globals = (mp_obj_dict_t*)&mp_module_thread_globals, .globals = (mp_obj_dict_t*)&mp_module_thread_globals,
}; };
......
...@@ -89,7 +89,6 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_uerrno_globals, mp_module_uerrno_globals_t ...@@ -89,7 +89,6 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_uerrno_globals, mp_module_uerrno_globals_t
const mp_obj_module_t mp_module_uerrno = { const mp_obj_module_t mp_module_uerrno = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR_uerrno,
.globals = (mp_obj_dict_t*)&mp_module_uerrno_globals, .globals = (mp_obj_dict_t*)&mp_module_uerrno_globals,
}; };
......
...@@ -765,7 +765,6 @@ MP_DECLARE_CONST_FUN_OBJ(mp_identity_obj); ...@@ -765,7 +765,6 @@ MP_DECLARE_CONST_FUN_OBJ(mp_identity_obj);
// module // module
typedef struct _mp_obj_module_t { typedef struct _mp_obj_module_t {
mp_obj_base_t base; mp_obj_base_t base;
qstr name;
mp_obj_dict_t *globals; mp_obj_dict_t *globals;
} mp_obj_module_t; } mp_obj_module_t;
mp_obj_dict_t *mp_obj_module_get_globals(mp_obj_t self_in); mp_obj_dict_t *mp_obj_module_get_globals(mp_obj_t self_in);
......
...@@ -37,17 +37,23 @@ STATIC void module_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kin ...@@ -37,17 +37,23 @@ STATIC void module_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kin
(void)kind; (void)kind;
mp_obj_module_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_module_t *self = MP_OBJ_TO_PTR(self_in);
const char *module_name = "";
mp_map_elem_t *elem = mp_map_lookup(&self->globals->map, MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_MAP_LOOKUP);
if (elem != NULL) {
module_name = mp_obj_str_get_str(elem->value);
}
#if MICROPY_PY___FILE__ #if MICROPY_PY___FILE__
// If we store __file__ to imported modules then try to lookup this // If we store __file__ to imported modules then try to lookup this
// symbol to give more information about the module. // symbol to give more information about the module.
mp_map_elem_t *elem = mp_map_lookup(&self->globals->map, MP_OBJ_NEW_QSTR(MP_QSTR___file__), MP_MAP_LOOKUP); elem = mp_map_lookup(&self->globals->map, MP_OBJ_NEW_QSTR(MP_QSTR___file__), MP_MAP_LOOKUP);
if (elem != NULL) { if (elem != NULL) {
mp_printf(print, "<module '%q' from '%s'>", self->name, mp_obj_str_get_str(elem->value)); mp_printf(print, "<module '%s' from '%s'>", module_name, mp_obj_str_get_str(elem->value));
return; return;
} }
#endif #endif
mp_printf(print, "<module '%q'>", self->name); mp_printf(print, "<module '%s'>", module_name);
} }
STATIC void module_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { STATIC void module_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
...@@ -106,7 +112,6 @@ mp_obj_t mp_obj_new_module(qstr module_name) { ...@@ -106,7 +112,6 @@ mp_obj_t mp_obj_new_module(qstr module_name) {
// create new module object // create new module object
mp_obj_module_t *o = m_new_obj(mp_obj_module_t); mp_obj_module_t *o = m_new_obj(mp_obj_module_t);
o->base.type = &mp_type_module; o->base.type = &mp_type_module;
o->name = module_name;
o->globals = MP_OBJ_TO_PTR(mp_obj_new_dict(MICROPY_MODULE_DICT_SIZE)); o->globals = MP_OBJ_TO_PTR(mp_obj_new_dict(MICROPY_MODULE_DICT_SIZE));
// store __name__ entry in the module // store __name__ entry in the module
......
...@@ -55,7 +55,6 @@ ...@@ -55,7 +55,6 @@
const mp_obj_module_t mp_module___main__ = { const mp_obj_module_t mp_module___main__ = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR___main__,
.globals = (mp_obj_dict_t*)&MP_STATE_VM(dict_main), .globals = (mp_obj_dict_t*)&MP_STATE_VM(dict_main),
}; };
......
...@@ -559,7 +559,6 @@ STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table ...@@ -559,7 +559,6 @@ STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table
const mp_obj_module_t machine_module = { const mp_obj_module_t machine_module = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR_umachine,
.globals = (mp_obj_dict_t*)&machine_module_globals, .globals = (mp_obj_dict_t*)&machine_module_globals,
}; };
...@@ -86,6 +86,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_network_globals, mp_module_network_globals ...@@ -86,6 +86,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_network_globals, mp_module_network_globals
const mp_obj_module_t mp_module_network = { const mp_obj_module_t mp_module_network = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR_network,
.globals = (mp_obj_dict_t*)&mp_module_network_globals, .globals = (mp_obj_dict_t*)&mp_module_network_globals,
}; };
...@@ -229,6 +229,5 @@ STATIC MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table); ...@@ -229,6 +229,5 @@ STATIC MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table);
const mp_obj_module_t pyb_module = { const mp_obj_module_t pyb_module = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR_pyb,
.globals = (mp_obj_dict_t*)&pyb_module_globals, .globals = (mp_obj_dict_t*)&pyb_module_globals,
}; };
...@@ -51,6 +51,5 @@ STATIC MP_DEFINE_CONST_DICT(stm_module_globals, stm_module_globals_table); ...@@ -51,6 +51,5 @@ STATIC MP_DEFINE_CONST_DICT(stm_module_globals, stm_module_globals_table);
const mp_obj_module_t stm_module = { const mp_obj_module_t stm_module = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR_stm,
.globals = (mp_obj_dict_t*)&stm_module_globals, .globals = (mp_obj_dict_t*)&stm_module_globals,
}; };
...@@ -407,6 +407,5 @@ STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table); ...@@ -407,6 +407,5 @@ STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table);
const mp_obj_module_t mp_module_uos = { const mp_obj_module_t mp_module_uos = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR_uos,
.globals = (mp_obj_dict_t*)&os_module_globals, .globals = (mp_obj_dict_t*)&os_module_globals,
}; };
...@@ -307,6 +307,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_select_globals, mp_module_select_globals_t ...@@ -307,6 +307,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_select_globals, mp_module_select_globals_t
const mp_obj_module_t mp_module_uselect = { const mp_obj_module_t mp_module_uselect = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR_uselect,
.globals = (mp_obj_dict_t*)&mp_module_select_globals, .globals = (mp_obj_dict_t*)&mp_module_select_globals,
}; };
...@@ -444,6 +444,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_usocket_globals, mp_module_usocket_globals ...@@ -444,6 +444,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_usocket_globals, mp_module_usocket_globals
const mp_obj_module_t mp_module_usocket = { const mp_obj_module_t mp_module_usocket = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR_usocket,
.globals = (mp_obj_dict_t*)&mp_module_usocket_globals, .globals = (mp_obj_dict_t*)&mp_module_usocket_globals,
}; };
...@@ -213,6 +213,5 @@ STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table); ...@@ -213,6 +213,5 @@ STATIC MP_DEFINE_CONST_DICT(time_module_globals, time_module_globals_table);
const mp_obj_module_t mp_module_utime = { const mp_obj_module_t mp_module_utime = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR_utime,
.globals = (mp_obj_dict_t*)&time_module_globals, .globals = (mp_obj_dict_t*)&time_module_globals,
}; };
...@@ -354,6 +354,5 @@ STATIC MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table); ...@@ -354,6 +354,5 @@ STATIC MP_DEFINE_CONST_DICT(pyb_module_globals, pyb_module_globals_table);
const mp_obj_module_t pyb_module = { const mp_obj_module_t pyb_module = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR_pyb,
.globals = (mp_obj_dict_t*)&pyb_module_globals, .globals = (mp_obj_dict_t*)&pyb_module_globals,
}; };
...@@ -499,6 +499,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_ffi_globals, mp_module_ffi_globals_table); ...@@ -499,6 +499,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_ffi_globals, mp_module_ffi_globals_table);
const mp_obj_module_t mp_module_ffi = { const mp_obj_module_t mp_module_ffi = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR_ffi,
.globals = (mp_obj_dict_t*)&mp_module_ffi_globals, .globals = (mp_obj_dict_t*)&mp_module_ffi_globals,
}; };
...@@ -718,6 +718,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_jni_globals, mp_module_jni_globals_table); ...@@ -718,6 +718,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_jni_globals, mp_module_jni_globals_table);
const mp_obj_module_t mp_module_jni = { const mp_obj_module_t mp_module_jni = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR_jni,
.globals = (mp_obj_dict_t*)&mp_module_jni_globals, .globals = (mp_obj_dict_t*)&mp_module_jni_globals,
}; };
...@@ -91,7 +91,6 @@ STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table ...@@ -91,7 +91,6 @@ STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table
const mp_obj_module_t mp_module_machine = { const mp_obj_module_t mp_module_machine = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR_umachine,
.globals = (mp_obj_dict_t*)&machine_module_globals, .globals = (mp_obj_dict_t*)&machine_module_globals,
}; };
......
...@@ -253,6 +253,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_os_globals, mp_module_os_globals_table); ...@@ -253,6 +253,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_os_globals, mp_module_os_globals_table);
const mp_obj_module_t mp_module_os = { const mp_obj_module_t mp_module_os = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR_uos,
.globals = (mp_obj_dict_t*)&mp_module_os_globals, .globals = (mp_obj_dict_t*)&mp_module_os_globals,
}; };
...@@ -586,6 +586,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_t ...@@ -586,6 +586,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_socket_globals, mp_module_socket_globals_t
const mp_obj_module_t mp_module_socket = { const mp_obj_module_t mp_module_socket = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR_usocket,
.globals = (mp_obj_dict_t*)&mp_module_socket_globals, .globals = (mp_obj_dict_t*)&mp_module_socket_globals,
}; };
...@@ -151,6 +151,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_termios_globals, mp_module_termios_globals ...@@ -151,6 +151,5 @@ STATIC MP_DEFINE_CONST_DICT(mp_module_termios_globals, mp_module_termios_globals
const mp_obj_module_t mp_module_termios = { const mp_obj_module_t mp_module_termios = {
.base = { &mp_type_module }, .base = { &mp_type_module },
.name = MP_QSTR_termios,
.globals = (mp_obj_dict_t*)&mp_module_termios_globals, .globals = (mp_obj_dict_t*)&mp_module_termios_globals,
}; };
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment