diff options
author | Damien George <damien.p.george@gmail.com> | 2014-04-05 22:36:42 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-04-05 22:36:42 +0100 |
commit | 7efc5b3f346869cd4177760e6a6b2bb863b425da (patch) | |
tree | 04fbe840f20ab84bee79d28882601812279c8718 /py/objmodule.c | |
parent | 8b0535e23fb1c646103a060a4ae17e9ee6d5e887 (diff) | |
download | micropython-7efc5b3f346869cd4177760e6a6b2bb863b425da.tar.gz micropython-7efc5b3f346869cd4177760e6a6b2bb863b425da.zip |
py: Make globals and locals proper dictionary objects.
Finishes addressing issue #424.
In the end this was a very neat refactor that now makes things a lot
more consistent across the py code base. It allowed some
simplifications in certain places, now that everything is a dict object.
Also converted builtins tables to dictionaries. This will be useful
when we need to turn builtins into a proper module.
Diffstat (limited to 'py/objmodule.c')
-rw-r--r-- | py/objmodule.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/py/objmodule.c b/py/objmodule.c index 783aa8a6fc..df7c991b8c 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -86,14 +86,16 @@ mp_obj_t mp_module_get(qstr module_name) { // lookup module mp_map_elem_t *el = mp_map_lookup(&mp_loaded_modules_map, MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP); - // module found, return it - if (el != NULL) { - return el->value; + if (el == NULL) { + // module not found, look for builtin module names + el = mp_map_lookup((mp_map_t*)&mp_builtin_module_dict_obj.map, MP_OBJ_NEW_QSTR(module_name), MP_MAP_LOOKUP); + if (el == NULL) { + return MP_OBJ_NULL; + } } - // module not found, look for builtin module names - // it will return MP_OBJ_NULL if nothing found - return mp_builtin_tables_lookup_module(module_name); + // module found, return it + return el->value; } void mp_module_register(qstr qstr, mp_obj_t module) { |