microbit: Enable loading of .mpy files.#579
microbit: Enable loading of .mpy files.#579dpgeorge wants to merge 1 commit intobbcmicrobit:masterfrom
Conversation
Code size is increased by about 1k bytes. Heap usage is similar to before this commit: on a test suite of large example programs, those that could run before can still run, and those that couldn't run still can't run. But all those that couldn't run before can now run if they are precompiled to a .mpy.
|
Note that this will execute upon boot a main.mpy file if it finds that (but main.py takes preference over main.mpy, and main.mpy over any appended script). To compile .py to .mpy requires v1.9.2 of mpy-cross, which can be build from the upstream repository by checking out v1.9.2 of that repo. The icing on the cake would be to provide an in-browser version of mpy-cross built with Emscripten, so users can compile .py to .mpy via their browser. But that is a fair bit of extra work. |
|
@dpgeorge - in my fork of this bbcmicrobit/micropython repo, I've rebased this PR onto the current tip of master and compiled the new runtime to include mpy support. I've also built v1.9.2 of mpy-cross as noted above and converted our modules for testing. All works well (thank you so much!) except using the new mpy-capable runtime with two .py modules (not their .mpy form) in the filesystem causes an error: I've boiled the problem down to the simplest code I could: 7 statements total across 3 scripts/modules. Everything is available in our release post and explained below. userscript.pyref.py (module)mod.py (module)The above causes (upon entering REPL): The same code does not cause errors when one or both of The same code does not cause errors when using a MicroPython binary without support for .mpy modules (ie: the tip of master: a92ca9b). If you If you use all 3 (as given above) but simply remove If you use all 3 (as given above) but simply remove from |
This allows to load .mpy files from the filesystem on the micro:bit.
With this commit code size is increased by about 1k bytes. Heap usage is similar to before this commit: on a test suite of large example programs, those that could run before can still run, and those that couldn't run still can't run. But all those that couldn't run before can now run if they are precompiled to a .mpy.