summaryrefslogtreecommitdiffstatshomepage
path: root/py/emitglue.c
diff options
context:
space:
mode:
authorDamien George <damien@micropython.org>2024-02-09 17:41:48 +1100
committerDamien George <damien@micropython.org>2024-02-16 14:17:01 +1100
commita3a73b64a3be5b5cc2b50444c819d81f8347d52f (patch)
tree20b1663339655490360b9f609d22074a366b0cca /py/emitglue.c
parente2ff00e81113d7a3f32f860652017644b5d68bf1 (diff)
downloadmicropython-a3a73b64a3be5b5cc2b50444c819d81f8347d52f.tar.gz
micropython-a3a73b64a3be5b5cc2b50444c819d81f8347d52f.zip
tools/mpy-tool.py: Skip generating frozen mp_raw_code_t when possible.
This reduces frozen code size by using the bytecode directly as the `mp_proto_fun_t`. Signed-off-by: Damien George <damien@micropython.org>
Diffstat (limited to 'py/emitglue.c')
-rw-r--r--py/emitglue.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/py/emitglue.c b/py/emitglue.c
index 1c7e013294..9d671b710e 100644
--- a/py/emitglue.c
+++ b/py/emitglue.c
@@ -183,6 +183,18 @@ mp_obj_t mp_make_function_from_proto_fun(mp_proto_fun_t proto_fun, const mp_modu
// def_kw_args must be MP_OBJ_NULL or a dict
assert(def_args == NULL || def_args[1] == MP_OBJ_NULL || mp_obj_is_type(def_args[1], &mp_type_dict));
+ #if MICROPY_MODULE_FROZEN_MPY
+ if (mp_proto_fun_is_bytecode(proto_fun)) {
+ const uint8_t *bc = proto_fun;
+ mp_obj_t fun = mp_obj_new_fun_bc(def_args, bc, context, NULL);
+ MP_BC_PRELUDE_SIG_DECODE(bc);
+ if (scope_flags & MP_SCOPE_FLAG_GENERATOR) {
+ ((mp_obj_base_t *)MP_OBJ_TO_PTR(fun))->type = &mp_type_gen_wrap;
+ }
+ return fun;
+ }
+ #endif
+
// the proto-function is a mp_raw_code_t
const mp_raw_code_t *rc = proto_fun;