diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-04-13 06:43:18 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-04-13 07:02:56 +0300 |
commit | 5500cdeec76e5be33f03fe63063a6d0fca40d133 (patch) | |
tree | 1c6caf066491d5f33699d598e26f42d10d4a8585 /unix | |
parent | 18bef25a0cd99029ebfaa92a29187c56ea96a835 (diff) | |
download | micropython-5500cdeec76e5be33f03fe63063a6d0fca40d133.tar.gz micropython-5500cdeec76e5be33f03fe63063a6d0fca40d133.zip |
py, unix: Convert sys module to static representation.
Diffstat (limited to 'unix')
-rw-r--r-- | unix/file.c | 9 | ||||
-rw-r--r-- | unix/main.c | 11 |
2 files changed, 6 insertions, 14 deletions
diff --git a/unix/file.c b/unix/file.c index fa7be791a4..a0a865a263 100644 --- a/unix/file.c +++ b/unix/file.c @@ -146,9 +146,6 @@ mp_obj_t mp_builtin_open(uint n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_open_obj, 1, 2, mp_builtin_open); -void file_init() { - mp_obj_t m_sys = mp_obj_new_module(MP_QSTR_sys); - mp_store_attr(m_sys, MP_QSTR_stdin, fdfile_new(STDIN_FILENO)); - mp_store_attr(m_sys, MP_QSTR_stdout, fdfile_new(STDOUT_FILENO)); - mp_store_attr(m_sys, MP_QSTR_stderr, fdfile_new(STDERR_FILENO)); -} +const mp_obj_fdfile_t mp_sys_stdin_obj = { .base = {&rawfile_type}, .fd = STDIN_FILENO }; +const mp_obj_fdfile_t mp_sys_stdout_obj = { .base = {&rawfile_type}, .fd = STDOUT_FILENO }; +const mp_obj_fdfile_t mp_sys_stderr_obj = { .base = {&rawfile_type}, .fd = STDERR_FILENO }; diff --git a/unix/main.c b/unix/main.c index f18e40a7fa..e582244b39 100644 --- a/unix/main.c +++ b/unix/main.c @@ -42,7 +42,6 @@ long heap_size = 128*1024 * (sizeof(machine_uint_t) / 4); // Stack top at the start of program void *stack_top; -void file_init(); void microsocket_init(); void time_init(); void ffi_init(); @@ -326,7 +325,7 @@ int main(int argc, char **argv) { p++; } } - mp_sys_path = mp_obj_new_list(path_num, NULL); + mp_obj_list_init(mp_sys_path, path_num); mp_obj_t *path_items; mp_obj_list_get(mp_sys_path, &path_num, &path_items); path_items[0] = MP_OBJ_NEW_QSTR(MP_QSTR_); @@ -348,10 +347,7 @@ int main(int argc, char **argv) { p = p1 + 1; } - mp_obj_t m_sys = mp_obj_new_module(MP_QSTR_sys); - mp_store_attr(m_sys, MP_QSTR_path, mp_sys_path); - mp_obj_t py_argv = mp_obj_new_list(0, NULL); - mp_store_attr(m_sys, MP_QSTR_argv, py_argv); + mp_obj_list_init(mp_sys_argv, 0); mp_store_name(qstr_from_str("test"), test_obj_new(42)); mp_store_name(qstr_from_str("mem_info"), mp_make_function_n(0, mem_info)); @@ -360,7 +356,6 @@ int main(int argc, char **argv) { mp_store_name(qstr_from_str("gc"), (mp_obj_t)&pyb_gc_obj); #endif - file_init(); microsocket_init(); #if MICROPY_MOD_TIME time_init(); @@ -418,7 +413,7 @@ int main(int argc, char **argv) { free(basedir); for (int i = a; i < argc; i++) { - mp_obj_list_append(py_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i]))); + mp_obj_list_append(mp_sys_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i]))); } do_file(argv[a]); executed = true; |