Skip to content

Commit

Permalink
implement frozen module changes from support #829
Browse files Browse the repository at this point in the history
  • Loading branch information
Novakasa committed Jan 13, 2023
1 parent 1410c40 commit f29a248
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
14 changes: 14 additions & 0 deletions bricks/_common_stm32/make.mk
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ QSTR_GLOBAL_DEPENDENCIES = ../_common/mpconfigport.h ../_common_stm32/mpconfigpo
# MicroPython feature configurations
MICROPY_ROM_TEXT_COMPRESSION ?= 1

# Frozen Python code
FROZEN_MANIFEST ?= ../_common_stm32/manifest.py

# include py core make definitions
include $(TOP)/py/py.mk

Expand Down Expand Up @@ -353,6 +356,17 @@ SRC_QSTR += $(PY_EXTRA_SRC_C) $(PY_STM32_SRC_C) $(PYBRICKS_PYBRICKS_SRC_C)
# Append any auto-generated sources that are needed by sources listed in SRC_QSTR
SRC_QSTR_AUTO_DEPS +=

ifneq ($(FROZEN_MANIFEST),)
CFLAGS += -DMICROPY_QSTR_EXTRA_POOL=mp_qstr_frozen_const_pool
CFLAGS += -DMICROPY_MODULE_FROZEN_MPY
CFLAGS += -DMPZ_DIG_SIZE=16
MPY_TOOL_FLAGS += -mlongint-impl none
endif

ifneq ($(FROZEN_MANIFEST),)
CFLAGS += -DMICROPY_MODULE_FROZEN_STR
endif

# Main firmware build targets
TARGETS := $(BUILD)/firmware.zip

Expand Down
1 change: 1 addition & 0 deletions bricks/_common_stm32/manifest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
freeze_as_mpy("modules")
2 changes: 2 additions & 0 deletions bricks/_common_stm32/modules/my_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
print("hello, data!")
data = 123
2 changes: 2 additions & 0 deletions pybricks/pybricks.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Copyright (c) 2018-2022 The Pybricks Authors

#include "py/mpconfig.h"
#include "shared/runtime/pyexec.h"
#include "py/obj.h"
#include "py/objmodule.h"
#include "py/objstr.h"
Expand Down Expand Up @@ -105,6 +106,7 @@ void pb_package_pybricks_init(bool import_all) {
if (import_all) {
pb_package_import_all();
}
pyexec_file_if_exists("testmod.py");
nlr_pop();
} else {
// Print initialization or import exception.
Expand Down

0 comments on commit f29a248

Please sign in to comment.