diff options
author | Damien George <damien.p.george@gmail.com> | 2014-09-15 15:53:09 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-09-15 15:53:09 +0100 |
commit | b92cbe612913a7c9d066c34912a3f77fe6392b2b (patch) | |
tree | ea267ba0d0d13a2dd7c4ef9ccb4b039bd993d328 /py | |
parent | 83695596ed4fe3ad990b68cc5ff52c26caf2174d (diff) | |
download | micropython-b92cbe612913a7c9d066c34912a3f77fe6392b2b.tar.gz micropython-b92cbe612913a7c9d066c34912a3f77fe6392b2b.zip |
py: Move definition of mp_sys_exit to core.
sys.exit always raises SystemExit so doesn't need a special
implementation for each port. If C exit() is really needed, use the
standard os._exit function.
Also initialise mp_sys_path and mp_sys_argv in teensy port.
Diffstat (limited to 'py')
-rw-r--r-- | py/modsys.c | 25 | ||||
-rw-r--r-- | py/objint.h | 2 |
2 files changed, 19 insertions, 8 deletions
diff --git a/py/modsys.c b/py/modsys.c index 4ce20f5c57..8ef66af052 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -25,8 +25,9 @@ */ #include <stdint.h> -#include <limits.h> + #include "mpconfig.h" +#include "nlr.h" #include "misc.h" #include "qstr.h" #include "obj.h" @@ -42,13 +43,7 @@ /// \module sys - system specific functions -// These should be implemented by ports, specific types don't matter, -// only addresses. -struct _dummy_t; -extern struct _dummy_t mp_sys_exit_obj; - -extern mp_obj_int_t mp_maxsize_obj; - +// These two lists must be initialised per port (after the call to mp_init). // TODO document these properly, they aren't constants or functions... /// \constant path - a mutable list of directories to search for imported modules mp_obj_list_t mp_sys_path_obj; @@ -69,6 +64,20 @@ STATIC const mp_obj_tuple_t mp_sys_version_info_obj = {{&mp_type_tuple}, 3, {I(3 STATIC const MP_DEFINE_STR_OBJ(platform_obj, MICROPY_PY_SYS_PLATFORM); #endif +/// \function exit([retval]) +/// Raise a `SystemExit` exception. If an argument is given, it is the +/// value given to `SystemExit`. +STATIC mp_obj_t mp_sys_exit(mp_uint_t n_args, const mp_obj_t *args) { + mp_obj_t exc; + if (n_args == 0) { + exc = mp_obj_new_exception(&mp_type_SystemExit); + } else { + exc = mp_obj_new_exception_arg1(&mp_type_SystemExit, args[0]); + } + nlr_raise(exc); +} +MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj, 0, 1, mp_sys_exit); + 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) }, diff --git a/py/objint.h b/py/objint.h index 50f36df4d0..638742a850 100644 --- a/py/objint.h +++ b/py/objint.h @@ -33,6 +33,8 @@ typedef struct _mp_obj_int_t { #endif } mp_obj_int_t; +extern const mp_obj_int_t mp_maxsize_obj; + void mp_obj_int_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind); char *mp_obj_int_formatted(char **buf, int *buf_size, int *fmt_size, mp_const_obj_t self_in, int base, const char *prefix, char base_char, char comma); |