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.
This commit is contained in:
@@ -73,6 +73,7 @@ MP_DECLARE_CONST_FUN_OBJ(mp_op_setitem_obj);
|
||||
MP_DECLARE_CONST_FUN_OBJ(mp_op_delitem_obj);
|
||||
|
||||
extern const mp_obj_module_t mp_module___main__;
|
||||
extern const mp_obj_module_t mp_module_builtins;
|
||||
extern const mp_obj_module_t mp_module_array;
|
||||
extern const mp_obj_module_t mp_module_collections;
|
||||
extern const mp_obj_module_t mp_module_io;
|
||||
@@ -83,6 +84,9 @@ extern const mp_obj_module_t mp_module_struct;
|
||||
extern const mp_obj_module_t mp_module_sys;
|
||||
extern const mp_obj_module_t mp_module_gc;
|
||||
|
||||
extern const mp_obj_dict_t mp_module_builtins_globals;
|
||||
extern mp_obj_dict_t *mp_module_builtins_override_dict;
|
||||
|
||||
struct _dummy_t;
|
||||
extern struct _dummy_t mp_sys_stdin_obj;
|
||||
extern struct _dummy_t mp_sys_stdout_obj;
|
||||
|
||||
Reference in New Issue
Block a user