mirror of
https://github.com/micropython/micropython.git
synced 2026-01-08 05:00:26 +01:00
py/modsys: Introduce sys.implementation._machine constant.
This contains a string useful for identifying the underlying machine. This string is kept consistent with the second part of the REPL banner via the new config option MICROPY_BANNER_MACHINE. This makes os.uname() more or less redundant, as all the information in os.uname() is now available in the sys module. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
11
py/modsys.c
11
py/modsys.c
@@ -36,6 +36,7 @@
|
||||
#include "py/smallint.h"
|
||||
#include "py/runtime.h"
|
||||
#include "py/persistentcode.h"
|
||||
#include "extmod/moduplatform.h"
|
||||
#include "genhdr/mpversion.h"
|
||||
|
||||
#if MICROPY_PY_SYS_SETTRACE
|
||||
@@ -69,20 +70,24 @@ STATIC const mp_obj_tuple_t mp_sys_implementation_version_info_obj = {
|
||||
3,
|
||||
{ I(MICROPY_VERSION_MAJOR), I(MICROPY_VERSION_MINOR), I(MICROPY_VERSION_MICRO) }
|
||||
};
|
||||
STATIC const MP_DEFINE_STR_OBJ(mp_sys_implementation_machine_obj, MICROPY_BANNER_MACHINE);
|
||||
#if MICROPY_PERSISTENT_CODE_LOAD
|
||||
#define SYS_IMPLEMENTATION_ELEMS \
|
||||
MP_ROM_QSTR(MP_QSTR_micropython), \
|
||||
MP_ROM_PTR(&mp_sys_implementation_version_info_obj), \
|
||||
MP_ROM_PTR(&mp_sys_implementation_machine_obj), \
|
||||
MP_ROM_INT(MPY_FILE_HEADER_INT)
|
||||
#else
|
||||
#define SYS_IMPLEMENTATION_ELEMS \
|
||||
MP_ROM_QSTR(MP_QSTR_micropython), \
|
||||
MP_ROM_PTR(&mp_sys_implementation_version_info_obj)
|
||||
MP_ROM_PTR(&mp_sys_implementation_version_info_obj), \
|
||||
MP_ROM_PTR(&mp_sys_implementation_machine_obj)
|
||||
#endif
|
||||
#if MICROPY_PY_ATTRTUPLE
|
||||
STATIC const qstr impl_fields[] = {
|
||||
MP_QSTR_name,
|
||||
MP_QSTR_version,
|
||||
MP_QSTR__machine,
|
||||
#if MICROPY_PERSISTENT_CODE_LOAD
|
||||
MP_QSTR__mpy,
|
||||
#endif
|
||||
@@ -90,13 +95,13 @@ STATIC const qstr impl_fields[] = {
|
||||
STATIC MP_DEFINE_ATTRTUPLE(
|
||||
mp_sys_implementation_obj,
|
||||
impl_fields,
|
||||
2 + MICROPY_PERSISTENT_CODE_LOAD,
|
||||
3 + MICROPY_PERSISTENT_CODE_LOAD,
|
||||
SYS_IMPLEMENTATION_ELEMS
|
||||
);
|
||||
#else
|
||||
STATIC const mp_rom_obj_tuple_t mp_sys_implementation_obj = {
|
||||
{&mp_type_tuple},
|
||||
2 + MICROPY_PERSISTENT_CODE_LOAD,
|
||||
3 + MICROPY_PERSISTENT_CODE_LOAD,
|
||||
{
|
||||
SYS_IMPLEMENTATION_ELEMS
|
||||
}
|
||||
|
||||
@@ -1719,6 +1719,15 @@ typedef double mp_float_t;
|
||||
#define MICROPY_BANNER_NAME_AND_VERSION "MicroPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE
|
||||
#endif
|
||||
|
||||
// String used for the second part of the banner, and sys.implementation._machine
|
||||
#ifndef MICROPY_BANNER_MACHINE
|
||||
#ifdef MICROPY_HW_BOARD_NAME
|
||||
#define MICROPY_BANNER_MACHINE MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME
|
||||
#else
|
||||
#define MICROPY_BANNER_MACHINE MICROPY_PY_SYS_PLATFORM " [" MICROPY_PLATFORM_COMPILER "] version"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// On embedded platforms, these will typically enable/disable irqs.
|
||||
#ifndef MICROPY_BEGIN_ATOMIC_SECTION
|
||||
#define MICROPY_BEGIN_ATOMIC_SECTION() (0)
|
||||
|
||||
Reference in New Issue
Block a user