mirror of
https://github.com/licsber/micropython.git
synced 2024-09-20 00:50:24 +08:00
py/modsys: Implement optional sys.intern.
Signed-off-by: stijn <stijn@ignitron.net>
This commit is contained in:
parent
05d3b22301
commit
85c02166ca
@ -147,6 +147,10 @@ STATIC const MP_DEFINE_STR_OBJ(mp_sys_platform_obj, MICROPY_PY_SYS_PLATFORM);
|
|||||||
MP_DEFINE_STR_OBJ(mp_sys_executable_obj, "");
|
MP_DEFINE_STR_OBJ(mp_sys_executable_obj, "");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MICROPY_PY_SYS_INTERN
|
||||||
|
MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_intern_obj, mp_obj_str_intern_checked);
|
||||||
|
#endif
|
||||||
|
|
||||||
// exit([retval]): raise SystemExit, with optional argument given to the exception
|
// exit([retval]): raise SystemExit, with optional argument given to the exception
|
||||||
STATIC mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) {
|
STATIC mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) {
|
||||||
if (n_args == 0) {
|
if (n_args == 0) {
|
||||||
@ -293,6 +297,10 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = {
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MICROPY_PY_SYS_INTERN
|
||||||
|
{ MP_ROM_QSTR(MP_QSTR_intern), MP_ROM_PTR(&mp_sys_intern_obj) },
|
||||||
|
#endif
|
||||||
|
|
||||||
#if MICROPY_PY_SYS_EXIT
|
#if MICROPY_PY_SYS_EXIT
|
||||||
{ MP_ROM_QSTR(MP_QSTR_exit), MP_ROM_PTR(&mp_sys_exit_obj) },
|
{ MP_ROM_QSTR(MP_QSTR_exit), MP_ROM_PTR(&mp_sys_exit_obj) },
|
||||||
#endif
|
#endif
|
||||||
|
@ -1434,6 +1434,11 @@ typedef double mp_float_t;
|
|||||||
#define MICROPY_PY_SYS_EXECUTABLE (0)
|
#define MICROPY_PY_SYS_EXECUTABLE (0)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// Whether to provide "sys.intern"
|
||||||
|
#ifndef MICROPY_PY_SYS_INTERN
|
||||||
|
#define MICROPY_PY_SYS_INTERN (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EVERYTHING)
|
||||||
|
#endif
|
||||||
|
|
||||||
// Whether to provide "sys.exit" function
|
// Whether to provide "sys.exit" function
|
||||||
#ifndef MICROPY_PY_SYS_EXIT
|
#ifndef MICROPY_PY_SYS_EXIT
|
||||||
#define MICROPY_PY_SYS_EXIT (1)
|
#define MICROPY_PY_SYS_EXIT (1)
|
||||||
|
@ -23,3 +23,18 @@ if hasattr(sys.implementation, '_mpy'):
|
|||||||
else:
|
else:
|
||||||
# Effectively skip subtests
|
# Effectively skip subtests
|
||||||
print(int)
|
print(int)
|
||||||
|
|
||||||
|
try:
|
||||||
|
print(sys.intern('micropython') == 'micropython')
|
||||||
|
has_intern = True
|
||||||
|
except AttributeError:
|
||||||
|
has_intern = False
|
||||||
|
print(True)
|
||||||
|
|
||||||
|
if has_intern:
|
||||||
|
try:
|
||||||
|
print(sys.intern(0))
|
||||||
|
except TypeError:
|
||||||
|
print(True)
|
||||||
|
else:
|
||||||
|
print(True)
|
||||||
|
@ -66,10 +66,10 @@ micropython machine math
|
|||||||
|
|
||||||
argv atexit byteorder exc_info
|
argv atexit byteorder exc_info
|
||||||
executable exit getsizeof implementation
|
executable exit getsizeof implementation
|
||||||
maxsize modules path platform
|
intern maxsize modules path
|
||||||
print_exception ps1 ps2
|
platform print_exception ps1
|
||||||
stderr stdin stdout tracebacklimit
|
ps2 stderr stdin stdout
|
||||||
version version_info
|
tracebacklimit version version_info
|
||||||
ementation
|
ementation
|
||||||
# attrtuple
|
# attrtuple
|
||||||
(start=1, stop=2, step=3)
|
(start=1, stop=2, step=3)
|
||||||
|
Loading…
Reference in New Issue
Block a user