diff options
author | Damien George <damien@micropython.org> | 2022-03-31 14:27:47 +1100 |
---|---|---|
committer | Damien George <damien@micropython.org> | 2022-04-14 23:52:12 +1000 |
commit | 35c0cff92bea230f8e16a8a7cdd50ea5f6a9df03 (patch) | |
tree | 9cf8caea9ae1567dcf7e4641aea552a6fe2ef731 /py/mpconfig.h | |
parent | 24bc1f61f9c73e922cda2cb429d9ace0a85cff94 (diff) |
py/parse: Add MICROPY_COMP_CONST_TUPLE option to build const tuples.
This commit adds support to the parser so that tuples which contain only
constant elements (bool, int, str, bytes, etc) are immediately converted to
a tuple object. This makes it more efficient to use tuples containing
constant data because they no longer need to be created at runtime by the
bytecode (or native code).
Furthermore, with this improvement constant tuples that are part of frozen
code are now able to be stored fully in ROM (this will be implemented in
later commits).
Code size is increased by about 400 bytes on Cortex-M4 platforms.
See related issue #722.
Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py/mpconfig.h')
-rw-r--r-- | py/mpconfig.h | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/py/mpconfig.h b/py/mpconfig.h index 22dfbb867..c308c31bd 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -441,6 +441,12 @@ #define MICROPY_COMP_CONST_FOLDING (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES) #endif +// Whether to compile constant tuples immediately to their respective objects; eg (1, True) +// Otherwise the tuple will be built at runtime +#ifndef MICROPY_COMP_CONST_TUPLE +#define MICROPY_COMP_CONST_TUPLE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES) +#endif + // Whether to enable optimisations for constant literals, eg OrderedDict #ifndef MICROPY_COMP_CONST_LITERAL #define MICROPY_COMP_CONST_LITERAL (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES) |