stmhal: Enable module weak links.

os, time, select modules are now prefixed with u, but are still
available (via weak links) as their original names.

ure and ujson now available as re and json via weak links.
This commit is contained in:
Damien George 2014-10-12 20:23:47 +01:00
parent c14a81662c
commit 0107e90328
6 changed files with 36 additions and 19 deletions

View File

@ -330,7 +330,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(os_urandom_obj, os_urandom);
#endif
STATIC const mp_map_elem_t os_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_os) },
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_uos) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_chdir), (mp_obj_t)&os_chdir_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_getcwd), (mp_obj_t)&os_getcwd_obj },
@ -362,8 +362,8 @@ STATIC const mp_obj_dict_t os_module_globals = {
},
};
const mp_obj_module_t os_module = {
const mp_obj_module_t mp_module_uos = {
.base = { &mp_type_module },
.name = MP_QSTR_os,
.name = MP_QSTR_uos,
.globals = (mp_obj_dict_t*)&os_module_globals,
};

View File

@ -287,7 +287,7 @@ STATIC mp_obj_t select_poll(void) {
MP_DEFINE_CONST_FUN_OBJ_0(mp_select_poll_obj, select_poll);
STATIC const mp_map_elem_t mp_module_select_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_select) },
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_uselect) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_select), (mp_obj_t)&mp_select_select_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_poll), (mp_obj_t)&mp_select_poll_obj },
};
@ -303,8 +303,8 @@ STATIC const mp_obj_dict_t mp_module_select_globals = {
},
};
const mp_obj_module_t mp_module_select = {
const mp_obj_module_t mp_module_uselect = {
.base = { &mp_type_module },
.name = MP_QSTR_select,
.name = MP_QSTR_uselect,
.globals = (mp_obj_dict_t*)&mp_module_select_globals,
};

View File

@ -336,7 +336,7 @@ STATIC mp_obj_t time_time(void) {
MP_DEFINE_CONST_FUN_OBJ_0(time_time_obj, time_time);
STATIC const mp_map_elem_t time_module_globals_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_time) },
{ MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_utime) },
{ MP_OBJ_NEW_QSTR(MP_QSTR_localtime), (mp_obj_t)&time_localtime_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_mktime), (mp_obj_t)&time_mktime_obj },
@ -355,8 +355,8 @@ STATIC const mp_obj_dict_t time_module_globals = {
},
};
const mp_obj_module_t time_module = {
const mp_obj_module_t mp_module_utime = {
.base = { &mp_type_module },
.name = MP_QSTR_time,
.name = MP_QSTR_utime,
.globals = (mp_obj_dict_t*)&time_module_globals,
};

View File

@ -48,6 +48,7 @@
*/
#define MICROPY_ENABLE_LFN (1)
#define MICROPY_LFN_CODE_PAGE (437) /* 1=SFN/ANSI 437=LFN/U.S.(OEM) */
#define MICROPY_MODULE_WEAK_LINKS (1)
#define MICROPY_PY_BUILTINS_STR_UNICODE (1)
#define MICROPY_PY_BUILTINS_FROZENSET (1)
#define MICROPY_PY_SYS_EXIT (1)
@ -73,24 +74,33 @@ extern const struct _mp_obj_fun_builtin_t mp_builtin_open_obj;
{ MP_OBJ_NEW_QSTR(MP_QSTR_open), (mp_obj_t)&mp_builtin_open_obj },
// extra built in modules to add to the list of known ones
extern const struct _mp_obj_module_t os_module;
extern const struct _mp_obj_module_t pyb_module;
extern const struct _mp_obj_module_t stm_module;
extern const struct _mp_obj_module_t time_module;
extern const struct _mp_obj_module_t mp_module_select;
extern const struct _mp_obj_module_t mp_module_ure;
extern const struct _mp_obj_module_t mp_module_ujson;
extern const struct _mp_obj_module_t mp_module_uos;
extern const struct _mp_obj_module_t mp_module_utime;
extern const struct _mp_obj_module_t mp_module_uselect;
extern const struct _mp_obj_module_t mp_module_usocket;
extern const struct _mp_obj_module_t mp_module_network;
#define MICROPY_PORT_BUILTIN_MODULES \
{ MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&os_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_pyb), (mp_obj_t)&pyb_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_stm), (mp_obj_t)&stm_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&time_module }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_select), (mp_obj_t)&mp_module_select }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_uos), (mp_obj_t)&mp_module_uos }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_utime), (mp_obj_t)&mp_module_utime }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_uselect), (mp_obj_t)&mp_module_uselect }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_usocket), (mp_obj_t)&mp_module_usocket }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_usocket }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_network), (mp_obj_t)&mp_module_network }, \
#define MICROPY_PORT_BUILTIN_MODULE_WEAK_LINKS \
{ MP_OBJ_NEW_QSTR(MP_QSTR_re), (mp_obj_t)&mp_module_ure }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_json), (mp_obj_t)&mp_module_ujson }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_os), (mp_obj_t)&mp_module_uos }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_time), (mp_obj_t)&mp_module_utime }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_select), (mp_obj_t)&mp_module_uselect }, \
{ MP_OBJ_NEW_QSTR(MP_QSTR_socket), (mp_obj_t)&mp_module_usocket }, \
// extra constants
#define MICROPY_PORT_CONSTANTS \
{ MP_OBJ_NEW_QSTR(MP_QSTR_pyb), (mp_obj_t)&pyb_module }, \

View File

@ -24,11 +24,11 @@
* THE SOFTWARE.
*/
extern const mp_obj_module_t os_module;
extern const mp_obj_module_t pyb_module;
extern const mp_obj_module_t stm_module;
extern const mp_obj_module_t time_module;
extern const mp_obj_module_t mp_module_select;
extern const mp_obj_module_t mp_module_uos;
extern const mp_obj_module_t mp_module_utime;
extern const mp_obj_module_t mp_module_uselect;
extern const mp_obj_module_t mp_module_usocket;
// additional helper functions exported by the modules

View File

@ -71,6 +71,10 @@ Q(micros)
Q(elapsed_millis)
Q(elapsed_micros)
// for module weak links
Q(re)
Q(json)
// for file class
Q(seek)
Q(tell)
@ -296,6 +300,7 @@ Q(angle)
Q(speed)
// for os module
Q(uos)
Q(os)
Q(/)
Q(flash)
@ -312,12 +317,14 @@ Q(stat)
Q(urandom)
// for time module
Q(utime)
Q(time)
Q(localtime)
Q(mktime)
Q(sleep)
// for select module
Q(uselect)
Q(select)
Q(poll)
Q(register)