From 7efc5b3f346869cd4177760e6a6b2bb863b425da Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 5 Apr 2014 22:36:42 +0100 Subject: 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. --- py/objmodule.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'py/objmodule.c') diff --git a/py/objmodule.c b/py/objmodule.c index 783aa8a6f..df7c991b8 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) { -- cgit v1.2.3