to trade compile speed & flash size
Initially enable the faster mode on rp2040 and espressif, where there's
usually plenty of flash available (these advanced techniques save hundreds
to thousands of bytes, which is important on a lot of old samd21 boards
but is a drop in the lake of a 4MB flash chip)
This way, a bare `-` is never interpreted as an option, even before
`--`. Filenames starting with `-` still need to be put after `--`.
Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
Unless -o is given, output defaults to stdout unless a source file is
given (in which case the source file name is used to derive an output
file name).
Signed-off-by: Armin Brauns <armin.brauns@embedded-solutions.at>
- GCC13 reports the following error when compiling mpy-cross:
main.c:313:6: error: conflicting types for ‘mp_import_stat’ due to enum/integer mismatch; have ‘uint(const char *)’ {aka ‘unsigned int(const char *)’} [-Werror=enum-int-mismatch]
313 | uint mp_import_stat(const char *path) {
| ^~~~~~~~~~~~~~
In file included from ../py/compile.h:29,
from main.c:11:
../py/lexer.h:205:18: note: previous declaration of ‘mp_import_stat’ with type ‘mp_import_stat_t(const char *)’
205 | mp_import_stat_t mp_import_stat(const char *path);
| ^~~~~~~~~~~~~~
cc1: all warnings being treated as errors
make: *** [../py/mkrules.mk:62: build/main.o] Error 1
Code in tools/mpy-tool.py and py/frozenmod.c relies on the source file
path encoded in a .mpy file to have forward slashes (e.g. by searching
for '/__init__.py'). Enforce that when creating these files, thereby
fixing import of .mpy files and frozen modules not working before
because they could have backslashes when built with the windows port.
This change makes it so the compiler and persistent code loader take a
mp_compiled_module_t* as their last argument, instead of returning this
struct. This eliminates a duplicate context variable for all callers of
these functions (because the context is now stored in the
mp_compiled_module_t by the caller), and also eliminates any confusion
about which context to use after the mp_compile_to_raw_code or
mp_raw_code_load function returns (because there is now only one context,
that stored in mp_compiled_module_t.context).
Reduces code size by 16 bytes on ARM Cortex-based ports.
Signed-off-by: Damien George <damien@micropython.org>
If `-march` isn't set then it means the user hasn't thought about it, or in
the case of freezing, MPY_CROSS_FLAGS isn't set. It's almost certainly
going to lead to problems, as there's no reason why the host architecture
is likely to be the right choice.
Compiling regular Python code is unaffected, but if `@native`/`@viper` is
used, the compiler will raise `SyntaxError: invalid arch`.
For situations where you explicitly want to use the host architecture (e.g.
for running tests on the unix port), added -march=host that keeps the old
behavior.
This work was funded through GitHub Sponsors.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This makes it so that all a port needs to do is set the relevant variables
and "include extmod.mk" and doesn't need to worry about adding anything to
OBJ, CFLAGS, SRC_QSTR, etc.
Make all extmod variables (src, flags, etc) private to extmod.mk.
Also move common/shared, extmod-related fragments (e.g. wiznet, cyw43,
bluetooth) into extmod.mk.
Now that SRC_MOD, CFLAGS_MOD, CXXFLAGS_MOD are unused by both extmod.mk
(and user-C-modules in a previous commit), remove all uses of them from
port makefiles.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
My pings go out, and then they come back
```py
import os
import wifi
import ipaddress
wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD'))
ipv4 = ipaddress.ip_address("8.8.4.4")
print("Ping google.com: %f ms" % (wifi.radio.ping(ipv4)*1000))
```
Needed to be updated to use build/mpy-cross.
Also fixes some other issues in the Python wrapper:
- Rename find_mpy_cross_binary to _find_mpy_cross_binary
- Fix passing of -march arg.
- Decode stdout from subprocess.
- Print stdout from mpy-cross in __main__.py.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
The intent is to allow us to make breaking changes to the native ABI (e.g.
changes to dynruntime.h) without needing the bytecode version to increment.
With this commit the two bits previously used for the feature flags (but
now unused as of .mpy version 6) encode a sub-version. A bytecode-only
.mpy file can be loaded as long as MPY_VERSION matches, but a native .mpy
(i.e. one with an arch set) must also match MPY_SUB_VERSION. This allows 3
additional updates to the native ABI per bytecode revision.
The sub-version is set to 1 because the previous commits that changed the
layout of mp_obj_type_t have changed the native ABI.
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
Signed-off-by: Damien George <damien@micropython.org>
Rather than invoking mpy-cross directly via system/subprocess in our build
tools and other tools, this provides a Python interface for it.
Based on https://gitlab.com/alelec/mpy_cross (with the intention of
eventually replacing that as the "official" pypi distribution once setup.py
etc are added).
Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
This allows mpy-cross to dynamically select whether ARMv7-M float
instructions are supported in @micropython.asm_thumb functions.
Signed-off-by: Damien George <damien@micropython.org>
This follows on from a5324a1074 and allows
mpy-cross to dynamically select whether ARMv7-M instructions are supported
in @micropython.asm_thumb functions.
The config option MICROPY_EMIT_INLINE_THUMB_ARMV7M is no longer needed, it
is now controlled by MICROPY_EMIT_THUMB_ARMV7M.
Signed-off-by: Damien George <damien@micropython.org>
The following changes are made:
- If MICROPY_VFS is enabled then mp_vfs_import_stat and mp_vfs_open are
automatically used for mp_import_stat and mp_builtin_open respectively.
- If MICROPY_PY_IO is enabled then "open" is automatically included in the
set of builtins, and points to mp_builtin_open_obj.
This helps to clean up and simplify the most common port configuration.
Signed-off-by: Damien George <damien@micropython.org>
Prior to this commit, even with unicode disabled .py and .mpy files could
contain unicode characters, eg by entering them directly in a string as
utf-8 encoded.
The only thing the compiler disallowed (with unicode disabled) was using
\uxxxx and \Uxxxxxxxx notation to specify a character within a string with
value >= 0x100; that would give a SyntaxError.
With this change mpy-cross will now accept \u and \U notation to insert a
character with value >= 0x100 into a string (because the -mno-unicode
option is now gone, there's no way to forbid this). The runtime will
happily work with strings with such characters, just like it already works
with strings with characters that were utf-8 encoded directly.
This change simplifies things because there are no longer any feature
flags in .mpy files, and any bytecode .mpy will now run on any target.
Signed-off-by: Damien George <damien@micropython.org>