From baaaf65eaaeed7d7db56985c5093d4d07966afad Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 13 Apr 2014 09:46:58 +0300 Subject: [PATCH 1/2] modsys: Implement basic sys.version_info. --- py/modsys.c | 6 ++++++ py/qstrdefs.h | 1 + 2 files changed, 7 insertions(+) diff --git a/py/modsys.c b/py/modsys.c index 59539b3b90..1411c964dd 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -5,6 +5,7 @@ #include "builtin.h" #include "runtime.h" #include "objlist.h" +#include "objtuple.h" #if MICROPY_ENABLE_MOD_SYS @@ -17,11 +18,16 @@ extern struct _dummy_t mp_sys_stderr_obj; mp_obj_list_t mp_sys_path_obj; mp_obj_list_t mp_sys_argv_obj; +#define I(n) MP_OBJ_NEW_SMALL_INT(n) +// TODO: CPython is now at 5-element array, but save 2 els so far... +STATIC const mp_obj_tuple_t mp_sys_version_info_obj = {{&mp_type_tuple}, 3, {I(3), I(3), I(5)}}; +#undef I STATIC const mp_map_elem_t mp_module_sys_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_sys) }, { MP_OBJ_NEW_QSTR(MP_QSTR_path), (mp_obj_t)&mp_sys_path_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_argv), (mp_obj_t)&mp_sys_argv_obj }, + { MP_OBJ_NEW_QSTR(MP_QSTR_version_info), (mp_obj_t)&mp_sys_version_info_obj }, #if MICROPY_MOD_SYS_STDFILES { MP_OBJ_NEW_QSTR(MP_QSTR_stdin), (mp_obj_t)&mp_sys_stdin_obj }, diff --git a/py/qstrdefs.h b/py/qstrdefs.h index b332e22fa2..ad44f84fe9 100644 --- a/py/qstrdefs.h +++ b/py/qstrdefs.h @@ -276,4 +276,5 @@ Q(argv) Q(stdin) Q(stdout) Q(stderr) +Q(version_info) #endif From 978d2c02672ef222a7409798ecfc15081212e3f7 Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 13 Apr 2014 09:53:52 +0300 Subject: [PATCH 2/2] modsys: Implement sys.byteorder. --- py/modsys.c | 5 +++++ py/qstrdefs.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/py/modsys.c b/py/modsys.c index 1411c964dd..10efd6004d 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -28,6 +28,11 @@ STATIC const mp_map_elem_t mp_module_sys_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR_path), (mp_obj_t)&mp_sys_path_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_argv), (mp_obj_t)&mp_sys_argv_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_version_info), (mp_obj_t)&mp_sys_version_info_obj }, +#if MP_ENDIANNESS_LITTLE + { MP_OBJ_NEW_QSTR(MP_QSTR_byteorder), MP_OBJ_NEW_QSTR(MP_QSTR_little) }, +#else + { MP_OBJ_NEW_QSTR(MP_QSTR_byteorder), MP_OBJ_NEW_QSTR(MP_QSTR_big) }, +#endif #if MICROPY_MOD_SYS_STDFILES { MP_OBJ_NEW_QSTR(MP_QSTR_stdin), (mp_obj_t)&mp_sys_stdin_obj }, diff --git a/py/qstrdefs.h b/py/qstrdefs.h index ad44f84fe9..a08af5a5ed 100644 --- a/py/qstrdefs.h +++ b/py/qstrdefs.h @@ -273,6 +273,9 @@ Q(utf-8) #if MICROPY_ENABLE_MOD_SYS Q(argv) +Q(byteorder) +Q(big) +Q(little) Q(stdin) Q(stdout) Q(stderr)