py: Add MICROPY_DYNAMIC_COMPILER option to config compiler at runtime.
This new compile-time option allows to make the bytecode compiler
configurable at runtime by setting the fields in the mp_dynamic_compiler
structure. By using this feature, the compiler can generate bytecode
that targets any MicroPython runtime/VM, regardless of the host and
target compile-time settings.
Options so far that fall under this dynamic setting are:
- maximum number of bits that a small int can hold;
- whether caching of lookups is used in the bytecode;
- whether to use unicode strings or not (lexer behaviour differs, and
therefore generated string constants differ).
diff --git a/py/mpstate.h b/py/mpstate.h
index 7f8325b..0e77e65 100644
--- a/py/mpstate.h
+++ b/py/mpstate.h
@@ -39,6 +39,16 @@
// memory system, runtime and virtual machine. The state is a global
// variable, but in the future it is hoped that the state can become local.
+// This structure contains dynamic configuration for the compiler.
+#if MICROPY_DYNAMIC_COMPILER
+typedef struct mp_dynamic_compiler_t {
+ uint8_t small_int_bits; // must be <= host small_int_bits
+ bool opt_cache_map_lookup_in_bytecode;
+ bool py_builtins_str_unicode;
+} mp_dynamic_compiler_t;
+extern mp_dynamic_compiler_t mp_dynamic_compiler;
+#endif
+
// This structure hold information about the memory allocation system.
typedef struct _mp_state_mem_t {
#if MICROPY_MEM_STATS