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/builtin.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/builtin.c')
-rw-r--r-- | py/builtin.c | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/py/builtin.c b/py/builtin.c index 11268aed18..a6d14fa48c 100644 --- a/py/builtin.c +++ b/py/builtin.c @@ -20,10 +20,10 @@ STATIC mp_obj_t mp_builtin___build_class__(uint n_args, const mp_obj_t *args) { assert(2 <= n_args); - // we differ from CPython: we set the new __locals__ object here - mp_map_t *old_locals = mp_locals_get(); + // set the new classes __locals__ object + mp_obj_dict_t *old_locals = mp_locals_get(); mp_obj_t class_locals = mp_obj_new_dict(0); - mp_locals_set(mp_obj_dict_get_map(class_locals)); + mp_locals_set(class_locals); // call the class code mp_obj_t cell = mp_call_function_0(args[0]); @@ -150,14 +150,14 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_chr_obj, mp_builtin_chr); STATIC mp_obj_t mp_builtin_dir(uint n_args, const mp_obj_t *args) { // TODO make this function more general and less of a hack - mp_map_t *map = NULL; + mp_obj_dict_t *dict = NULL; if (n_args == 0) { // make a list of names in the local name space - map = mp_locals_get(); + dict = mp_locals_get(); } else { // n_args == 1 // make a list of names in the given object if (MP_OBJ_IS_TYPE(args[0], &mp_type_module)) { - map = mp_obj_dict_get_map(mp_obj_module_get_globals(args[0])); + dict = mp_obj_module_get_globals(args[0]); } else { mp_obj_type_t *type; if (MP_OBJ_IS_TYPE(args[0], &mp_type_type)) { @@ -166,16 +166,16 @@ STATIC mp_obj_t mp_builtin_dir(uint n_args, const mp_obj_t *args) { type = mp_obj_get_type(args[0]); } if (type->locals_dict != MP_OBJ_NULL && MP_OBJ_IS_TYPE(type->locals_dict, &mp_type_dict)) { - map = mp_obj_dict_get_map(type->locals_dict); + dict = type->locals_dict; } } } mp_obj_t dir = mp_obj_new_list(0, NULL); - if (map != NULL) { - for (uint i = 0; i < map->alloc; i++) { - if (MP_MAP_SLOT_IS_FILLED(map, i)) { - mp_obj_list_append(dir, map->table[i].key); + if (dict != NULL) { + for (uint i = 0; i < dict->map.alloc; i++) { + if (MP_MAP_SLOT_IS_FILLED(&dict->map, i)) { + mp_obj_list_append(dir, dict->map.table[i].key); } } } |