diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-05-10 16:50:45 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-05-10 16:56:21 +0300 |
commit | d99e9083cb7fc854db0ff506caf50d81842aff0e (patch) | |
tree | 5e6c6b8cfcf17e5b039e5368d2b5bae71e721a39 | |
parent | d80e2476c782d7af4d65fb318f6b1bfefa91bb44 (diff) | |
download | micropython-d99e9083cb7fc854db0ff506caf50d81842aff0e.tar.gz micropython-d99e9083cb7fc854db0ff506caf50d81842aff0e.zip |
modsys, unix: Add sys.exit(), should be implemented by a port.
-rw-r--r-- | py/modsys.c | 5 | ||||
-rw-r--r-- | py/qstrdefs.h | 1 | ||||
-rw-r--r-- | unix/main.c | 9 |
3 files changed, 15 insertions, 0 deletions
diff --git a/py/modsys.c b/py/modsys.c index 33bf04ba2c..f2b87a68cf 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -36,6 +36,8 @@ #if MICROPY_ENABLE_MOD_SYS +MP_DECLARE_CONST_FUN_OBJ(mp_sys_exit_obj); + // These should be implemented by ports, specific types don't matter, // only addresses. struct _dummy_t; @@ -53,6 +55,9 @@ STATIC const MP_DEFINE_STR_OBJ(version_obj, "3.4.0"); 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) }, + // Should be implemented by port + { MP_OBJ_NEW_QSTR(MP_QSTR_exit), (mp_obj_t)&mp_sys_exit_obj }, + { 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), (mp_obj_t)&version_obj }, diff --git a/py/qstrdefs.h b/py/qstrdefs.h index 0d883d3870..7de2491fa8 100644 --- a/py/qstrdefs.h +++ b/py/qstrdefs.h @@ -329,6 +329,7 @@ Q(utf-8) Q(argv) Q(byteorder) Q(big) +Q(exit) Q(little) Q(stdin) Q(stdout) diff --git a/unix/main.c b/unix/main.c index cc80811503..de296142b3 100644 --- a/unix/main.c +++ b/unix/main.c @@ -371,6 +371,15 @@ int main(int argc, char **argv) { return 0; } +STATIC mp_obj_t mp_sys_exit(uint n_args, const mp_obj_t *args) { + int rc = 0; + if (n_args > 0) { + rc = mp_obj_get_int(args[0]); + } + exit(rc); +} +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj, 0, 1, mp_sys_exit); + uint mp_import_stat(const char *path) { struct stat st; if (stat(path, &st) == 0) { |