modsys, unix: Add sys.exit(), should be implemented by a port.

This commit is contained in:
Paul Sokolovsky 2014-05-10 16:50:45 +03:00
parent d80e2476c7
commit d99e9083cb
3 changed files with 15 additions and 0 deletions

View File

@ -36,6 +36,8 @@
#if MICROPY_ENABLE_MOD_SYS #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, // These should be implemented by ports, specific types don't matter,
// only addresses. // only addresses.
struct _dummy_t; 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[] = { 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___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_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_argv), (mp_obj_t)&mp_sys_argv_obj },
{ MP_OBJ_NEW_QSTR(MP_QSTR_version), (mp_obj_t)&version_obj }, { MP_OBJ_NEW_QSTR(MP_QSTR_version), (mp_obj_t)&version_obj },

View File

@ -329,6 +329,7 @@ Q(utf-8)
Q(argv) Q(argv)
Q(byteorder) Q(byteorder)
Q(big) Q(big)
Q(exit)
Q(little) Q(little)
Q(stdin) Q(stdin)
Q(stdout) Q(stdout)

View File

@ -371,6 +371,15 @@ int main(int argc, char **argv) {
return 0; 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) { uint mp_import_stat(const char *path) {
struct stat st; struct stat st;
if (stat(path, &st) == 0) { if (stat(path, &st) == 0) {