py/persistentcode: Support saving functions with children.

This adds support to `mp_raw_code_save_fun_to_bytes()` so that it can
handle saving functions that have children.  It does this by inspecting
the MP_BC_MAKE_FUNCTION/etc opcodes to work out how many children there
are, and creating a tree of simplified raw code information.

Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
Damien George
2026-01-15 11:42:04 +11:00
parent 03f50d39da
commit 384cc627bc
2 changed files with 97 additions and 34 deletions

View File

@@ -139,7 +139,7 @@ void mp_raw_code_load_file(qstr filename, mp_compiled_module_t *ctx);
void mp_raw_code_save(mp_compiled_module_t *cm, mp_print_t *print);
void mp_raw_code_save_file(mp_compiled_module_t *cm, qstr filename);
mp_obj_t mp_raw_code_save_fun_to_bytes(const mp_module_constants_t *consts, const uint8_t *bytecode);
mp_obj_t mp_raw_code_save_fun_to_bytes(const mp_module_constants_t *consts, mp_proto_fun_t proto_fun);
void mp_native_relocate(void *reloc, uint8_t *text, uintptr_t reloc_text);