diff options
author | Damien George <damien.p.george@gmail.com> | 2014-12-09 16:19:48 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-12-09 16:19:48 +0000 |
commit | 78d702c300ae9f175e6f47f805a37cdfe5b81898 (patch) | |
tree | 034b42ea789dc38c629a2f0dd8a48001a32cd838 /py/obj.h | |
parent | e6e8ad8ab238cd596a3eedf8f4dd635e2e84f46e (diff) |
py: Allow builtins to be overridden.
This patch adds a configuration option (MICROPY_CAN_OVERRIDE_BUILTINS)
which, when enabled, allows to override all names within the builtins
module. A builtins override dict is created the first time the user
assigns to a name in the builtins model, and then that dict is searched
first on subsequent lookups. Note that this implementation doesn't
allow deleting of names.
This patch also does some refactoring of builtins code, creating the
modbuiltins.c file.
Addresses issue #959.
Diffstat (limited to 'py/obj.h')
-rw-r--r-- | py/obj.h | 11 |
1 files changed, 10 insertions, 1 deletions
@@ -97,9 +97,18 @@ typedef struct _mp_obj_base_t mp_obj_base_t; #define MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name, n_args_min, n_args_max, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, false, n_args_min, n_args_max, (mp_fun_var_t)fun_name) #define MP_DEFINE_CONST_FUN_OBJ_KW(obj_name, n_args_min, fun_name) MP_DEFINE_CONST_FUN_OBJ_VOID_PTR(obj_name, true, n_args_min, MP_OBJ_FUN_ARGS_MAX, (mp_fun_kw_t)fun_name) -// This macro is used to define constant dict objects +// These macros are used to define constant map/dict objects // You can put "static" in front of the definition to make it local +#define MP_DEFINE_CONST_MAP(map_name, table_name) \ + const mp_map_t map_name = { \ + .all_keys_are_qstrs = 1, \ + .table_is_fixed_array = 1, \ + .used = MP_ARRAY_SIZE(table_name), \ + .alloc = MP_ARRAY_SIZE(table_name), \ + .table = (mp_map_elem_t*)table_name, \ + } + #define MP_DEFINE_CONST_DICT(dict_name, table_name) \ const mp_obj_dict_t dict_name = { \ .base = {&mp_type_dict}, \ |