py: Add MICROPY_PERSISTENT_CODE so code can persist beyond the runtime.
Main changes when MICROPY_PERSISTENT_CODE is enabled are:
- qstrs are encoded as 2-byte fixed width in the bytecode
- all pointers are removed from bytecode and put in const_table (this
includes const objects and raw code pointers)
Ultimately this option will enable persistence for not just bytecode but
also native code.
diff --git a/py/emitnative.c b/py/emitnative.c
index d8f1640..2abc46c 100644
--- a/py/emitnative.c
+++ b/py/emitnative.c
@@ -830,10 +830,16 @@
ASM_DATA(emit->as, 1, emit->scope->num_kwonly_args);
ASM_DATA(emit->as, 1, emit->scope->num_def_pos_args);
- // write code info (just contains block name and source file)
+ // write code info
+ #if MICROPY_PERSISTENT_CODE
ASM_DATA(emit->as, 1, 5);
- ASM_DATA(emit->as, 2, emit->scope->simple_name);
- ASM_DATA(emit->as, 2, emit->scope->source_file);
+ ASM_DATA(emit->as, 1, emit->scope->simple_name);
+ ASM_DATA(emit->as, 1, emit->scope->simple_name >> 8);
+ ASM_DATA(emit->as, 1, emit->scope->source_file);
+ ASM_DATA(emit->as, 1, emit->scope->source_file >> 8);
+ #else
+ ASM_DATA(emit->as, 1, 1);
+ #endif
// bytecode prelude: initialise closed over variables
for (int i = 0; i < emit->scope->id_info_len; i++) {