summaryrefslogtreecommitdiff
path: root/py/modsys.c
diff options
context:
space:
mode:
authorJim Mussared <jim.mussared@gmail.com>2023-10-10 16:50:28 +1100
committerDamien George <damien@micropython.org>2023-10-27 15:28:46 +1100
commit3bf70f16e964370475114ff9658f58870ffaf768 (patch)
treea8938107776003bbfd9e8a5ed6a74976d26cd9cb /py/modsys.c
parent3e2706a18dd4071d2d3040549786e659fc3b46b7 (diff)
py/mkrules.mk: Add MICROPY_PREVIEW_VERSION_2.
This provides a way to enable features and changes slated for MicroPython 2.x, by running `make MICROPY_PREVIEW_VERSION_2=1`. Also supported for the cmake ports (except Zephyr). This is an alternative to having a 2.x development branch (or equivalently, keeping a 1.x release branch). Any feature or change that needs to be "hidden" until 2.x can use this flag (either in the Makefile or the preprocessor). A good example is changing function arguments or other public API features, in particular to aid in improving consistency between ports. When `MICROPY_PREVIEW_VERSION_2` is enabled, the REPL banner is amended to say "MicroPython (with v2.0 preview) vX.Y.Z", and sys.implementation gets a new field `_v2` set to `True`. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Diffstat (limited to 'py/modsys.c')
-rw-r--r--py/modsys.c40
1 files changed, 29 insertions, 11 deletions
diff --git a/py/modsys.c b/py/modsys.c
index e40542467..12fa1101b 100644
--- a/py/modsys.c
+++ b/py/modsys.c
@@ -79,19 +79,26 @@ STATIC const mp_rom_obj_tuple_t mp_sys_implementation_version_info_obj = {
}
};
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 \
+#define SYS_IMPLEMENTATION_ELEMS_BASE \
MP_ROM_QSTR(MP_QSTR_micropython), \
MP_ROM_PTR(&mp_sys_implementation_version_info_obj), \
MP_ROM_PTR(&mp_sys_implementation_machine_obj)
+
+#if MICROPY_PERSISTENT_CODE_LOAD
+#define SYS_IMPLEMENTATION_ELEMS__MPY \
+ , MP_ROM_INT(MPY_FILE_HEADER_INT)
+#else
+#define SYS_IMPLEMENTATION_ELEMS__MPY
#endif
+
#if MICROPY_PY_ATTRTUPLE
+#if MICROPY_PREVIEW_VERSION_2
+#define SYS_IMPLEMENTATION_ELEMS__V2 \
+ , MP_ROM_TRUE
+#else
+#define SYS_IMPLEMENTATION_ELEMS__V2
+#endif
+
STATIC const qstr impl_fields[] = {
MP_QSTR_name,
MP_QSTR_version,
@@ -99,19 +106,30 @@ STATIC const qstr impl_fields[] = {
#if MICROPY_PERSISTENT_CODE_LOAD
MP_QSTR__mpy,
#endif
+ #if MICROPY_PREVIEW_VERSION_2
+ MP_QSTR__v2,
+ #endif
};
STATIC MP_DEFINE_ATTRTUPLE(
mp_sys_implementation_obj,
impl_fields,
- 3 + MICROPY_PERSISTENT_CODE_LOAD,
- SYS_IMPLEMENTATION_ELEMS
+ 3 + MICROPY_PERSISTENT_CODE_LOAD + MICROPY_PREVIEW_VERSION_2,
+ SYS_IMPLEMENTATION_ELEMS_BASE
+ SYS_IMPLEMENTATION_ELEMS__MPY
+ SYS_IMPLEMENTATION_ELEMS__V2
);
#else
STATIC const mp_rom_obj_tuple_t mp_sys_implementation_obj = {
{&mp_type_tuple},
3 + MICROPY_PERSISTENT_CODE_LOAD,
+ // Do not include SYS_IMPLEMENTATION_ELEMS__V2 because
+ // SYS_IMPLEMENTATION_ELEMS__MPY may be empty if
+ // MICROPY_PERSISTENT_CODE_LOAD is disabled, which means they'll share
+ // the same index. Cannot query _v2 if MICROPY_PY_ATTRTUPLE is
+ // disabled.
{
- SYS_IMPLEMENTATION_ELEMS
+ SYS_IMPLEMENTATION_ELEMS_BASE
+ SYS_IMPLEMENTATION_ELEMS__MPY
}
};
#endif