summaryrefslogtreecommitdiffstatshomepage
path: root/py
Commit message (Collapse)AuthorAge
* py: Make struct-initializing macros compatible with C++.stijn6 days
| | | | | | | | | | | This requires explicitly naming and initializing all members so add that where needed and possible. For MP_DEFINE_NLR_JUMP_CALLBACK_FUNCTION_1 this would require initializing the .callback member, but that's a bit of a waste since the macro is always followed by a call to nlr_push_jump_callback() to initialize exactly that member, so rewrite the macro without initializers. Signed-off-by: stijn <stijn@ignitron.net>
* py/mkrules.cmake: Add CMake support for compressed error messages.Damien George8 days
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/dynruntime.mk: Fix use of musl's libm.a when LINK_RUNTIME=1.dubiousjim8 days
| | | | | | | Like PICOLIBC, MUSL also has its math functions in libc.a. There is a libm.a, but it's empty. Signed-off-by: dubiousjim <dubiousjim@gmail.com>
* py/objstr: Fix handling of OP_MODULO with namedtuple.Yoctopuce dev9 days
| | | | | | | | | This fix handles attrtuple as well, eg. os.uname(). A test case has been added in basics/attrtuple2.py. Fixes issue #16969. Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
* py/objrange: Match CPython range slicing.Jeff Epler9 days
| | | | | | | | | The "index fixing" behavior of get_fast_slice_indexes are not desired here; the underlying behavior of mp_obj_slice_indexes actually is. Fixes issue #17016. Signed-off-by: Jeff Epler <jepler@gmail.com>
* all: Bump version to 1.26.0-preview.v1.26.0-previewDamien George9 days
| | | | Signed-off-by: Damien George <damien@micropython.org>
* all: Bump version to 1.25.0.v1.25.0Damien George2025-04-16
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/emitinlinerv32: Move include of asmrv32.h to within feature guard.Damien George2025-04-14
| | | | | | | | | Otherwise, when compiling on 16-bit systems (where `mp_uint_t` is 16 bits wide) the compiler warns about "left shift count >= width of type", from the static inline functions that have RV32_ENCODE_TYPE_xxx macros which do a lot of bit shifting. Signed-off-by: Damien George <damien@micropython.org>
* rp2,esp32,extmod: Implement UPDATE_SUBMODULES in CMake.Angus Gratton2025-03-27
| | | | | | | | | | | | | | | Rather than having Make calling CMake to generate a list of submodules and then run a Make target (which is complex and prone to masking other errors), implement the submodule update logic in CMake itself. Internal CMake-side changes are that GIT_SUBMODULES is now a CMake list, and the trigger variable name is changed from ECHO_SUBMODULES to UPDATE_SUBMODULES. The run is otherwise 100% a normal CMake run now, so most of the other special casing can be removed. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py/dynruntime: Make malloc functions raise MemoryError on failure.Damien George2025-03-27
| | | | | | Addresses some TODOs in this file. Signed-off-by: Damien George <damien@micropython.org>
* py/mpconfig: Enable 2-argument built-in next() at basic feature level.Damien George2025-03-27
| | | | | | | | | | This is a pretty fundamental built-in and having CPython-compatible behaviour is beneficial. The code size increase is not much, and ports/boards can still disable it if needed to save space. Addresses issue #5384. Signed-off-by: Damien George <damien@micropython.org>
* tools/mpy_ld.py: Allow linking static libraries.Volodymyr Shymanskyy2025-03-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit introduces an additional symbol resolution mechanism to the natmod linking process. This allows the build scripts to look for required symbols into selected libraries that are provided by the compiler installation (libgcc and libm at the moment). For example, using soft-float code in natmods, whilst technically possible, was not an easy process and required some additional work to pull it off. With this addition all the manual (and error-prone) operations have been automated and folded into `tools/mpy_ld.py`. Both newlib and picolibc toolchains are supported, albeit the latter may require a bit of extra configuration depending on the environment the build process runs on. Picolibc's soft-float functions aren't in libm - in fact the shipped libm is nothing but a stub - but they are inside libc. This is usually not a problem as these changes cater for that configuration quirk, but on certain compilers the include paths used to find libraries in may not be updated to take Picolibc's library directory into account. The bare metal RISC-V compiler shipped with the CI OS image (GCC 10.2.0 on Ubuntu 22.04LTS) happens to exhibit this very problem. To work around that for CI builds, the Picolibc libraries' path is hardcoded in the Makefile directives used by the linker, but this can be changed by setting the PICOLIBC_ROOT environment library when building natmods. Signed-off-by: Volodymyr Shymanskyy <vshymanskyi@gmail.com> Co-authored-by: Alessandro Gatti <a.gatti@frob.it>
* py/runtime: Automatically mount ROMFS as part of mp_init.Damien George2025-03-06
| | | | | | This is put in `mp_init()` to make it consistent across all ports. Signed-off-by: Damien George <damien@micropython.org>
* extmod/vfs: Add mp_vfs_mount_romfs_protected() helper.Damien George2025-03-06
| | | | | | | This function will attempt to create a `VfsRom` instance and mount it at location "/rom" in the filesystem. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modvfs: Add vfs.rom_ioctl function and its ioctl constants.Damien George2025-03-06
| | | | | | | This is a generic interface to allow querying and modifying the read-only memory area of a device, if it has such an area. Signed-off-by: Damien George <damien@micropython.org>
* py/objarray: Add MP_DEFINE_MEMORYVIEW_OBJ convenience macro.Damien George2025-03-06
| | | | | | | This allows defining a `memoryview` instance, either statically or on the C stack. Signed-off-by: Damien George <damien@micropython.org>
* py/makeqstrdata.py: Implement MicroPython compatibility.Volodymyr Shymanskyy2025-03-05
| | | | | | | This allows running `py/makeqstrdata.py` with MicroPython itself. Signed-off-by: Volodymyr Shymanskyy <vshymanskyi@gmail.com> Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py/modsys: Add sys.implementation._build entry.Damien George2025-03-05
| | | | | | | | | | | | | | | | | | | For a given MicroPython firmware/executable it can be sometimes important to know how it was built, which variant/board configuration it came from. This commit adds a new field `sys.implementation._build` that can help identify the configuration that MicroPython was built with. For now it's either: * <VARIANT> for unix, webassembly and windows ports * <BOARD>-<VARIANT> for microcontroller ports (the variant is optional) In the future additional elements may be added to this string, separated by a hyphen. Resolves issue #16498. Signed-off-by: Damien George <damien@micropython.org>
* py/objstr: Support tuples and start/end args in startswith and endswith.Glenn Moloney2025-03-02
| | | | | | | | | | | | | | This change allows tuples to be passed as the prefix/suffix argument to the `str.startswith()` and `str.endswith()` methods. The methods will return `True` if the string starts/ends with any of the prefixes/suffixes in the tuple. Also adds full support for the `start` and `end` arguments to both methods for compatibility with CPython. Tests have been updated for the new behaviour. Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
* py/parsenum: Reduce code footprint of mp_parse_num_float.Yoctopuce dev2025-02-28
| | | | | | | | | | | | | The mantissa parsing code uses a floating point variable to accumulate digits. Using an `mp_float_uint_t` variable instead and casting to `mp_float_t` at the very end reduces code size. In some cases, it also improves the rounding behaviour as extra digits are taken into account by the int-to-float conversion code. An extra test case handles the special case where mantissa overflow occurs while processing deferred trailing zeros. Signed-off-by: Yoctopuce dev <dev@yoctopuce.com>
* py/emitinlinextensa: Simplify register name lookup.Alessandro Gatti2025-02-28
| | | | | | | | This commit changes the Xtensa inline assembly parser to use a slightly simpler (and probably a tiny bit more efficient) way to look up register names when decoding instruction parameters. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/emitinlinerv32: Reduce the footprint of compiled code.Alessandro Gatti2025-02-27
| | | | | | | | | | | | | | | | | | This commit introduces a few changes aimed at reducing the amount of space taken by the inline assembler once compiled: * The register string table uses 2 bytes for each qstr rather than the usual 4 * The opcode table uses 2 bytes for each qstr rather than the usual 4 * Opcode masks are not embedded in each opcode entry but looked up via an additional smaller table, reducing the number of bytes taken by an opcode's masks from 12 to 2 (with a fixed overhead of 24 bytes for the the masks themselves stored elsewhere) * Some error messages had a trailing period, now removed * Error messages have been parameterised when possible, and the overall text length is smaller. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/emitinlinerv32: Fix compilation with ESP-IDF v5.2 and later.Alessandro Gatti2025-02-27
| | | | | | | | | This commit fixes a compilation warning (turned error) about a potentially uninitialised variable being used. The warning can be ignored as the variable in question is always written to, but the code has been changed to silence that warning. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* all: Upgrade codespell to v2.4.1.Christian Clauss2025-02-25
| | | | | | | This commit upgrades from codespell==2.2.6 to the current codespell==2.4.1, adding emac to the ignore-words-list. Signed-off-by: Christian Clauss <cclauss@me.com>
* py/mkrules.cmake: Support passing CFLAGS_EXTRA in environment variable.Angus Gratton2025-02-18
| | | | | | | | | | | | | | This works similarly to the existing support in "bare metal" make ports, with the caveat that CMake will only set this value on a clean build and will reuse the previous value otherwise. This is slightly different to the CMake built-in support for CFLAGS, as this variable is used when evaluating source files for qstr generation, etc. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* extmod/modmarshal: Add new marshal module.Damien George2025-02-11
| | | | | | | | | | | | | This commit implements a small subset of the CPython `marshal` module. It implements `marshal.dumps()` and `marshal.loads()`, but only supports (un)marshalling code objects at this stage. The semantics match CPython, except that the actual marshalled bytes is not compatible with CPython's marshalled bytes. The module is enabled at the everything level (only on the unix coverage build at this stage). Signed-off-by: Damien George <damien@micropython.org>
* py/persistentcode: Add mp_raw_code_save_fun_to_bytes.Damien George2025-02-11
| | | | | | Serialises a bytecode function/generator to a valid .mpy as bytes. Signed-off-by: Damien George <damien@micropython.org>
* py/objfun: Implement function.__code__ and function constructor.Damien George2025-02-11
| | | | | | | | | | | This allows retrieving the code object of a function using `function.__code__`, and then reconstructing a function from a code object using `FunctionType(code_object)`. This feature is controlled by `MICROPY_PY_FUNCTION_ATTRS_CODE` and is enabled at the full-features level. Signed-off-by: Damien George <damien@micropython.org>
* py/objcode: Factor code object out into its own file.Damien George2025-02-11
| | | | | | | | | | | | | | | | | | | | | | | | The `mp_obj_code_t` and `mp_type_code` code object was defined internally in both `py/builtinevex.c` and `py/profile.c`, with completely different implementations (the former very minimal, the latter quite complete). This commit factors these implementations into a new, separate source file, and allows the code object to have four different modes, selected at compile-time: - MICROPY_PY_BUILTINS_CODE_NONE: code object not included in the build. - MICROPY_PY_BUILTINS_CODE_MINIMUM: very simple code object that just holds a reference to the function that it represents. This level is used when MICROPY_PY_BUILTINS_COMPILE is enabled. - MICROPY_PY_BUILTINS_CODE_BASIC: simple code object that holds a reference to the proto-function and its constants. - MICROPY_PY_BUILTINS_CODE_FULL: almost complete implementation of the code object. This level is used when MICROPY_PY_SYS_SETTRACE is enabled. Signed-off-by: Damien George <damien@micropython.org>
* py/emitnative: Load and store words just once for Viper code.Alessandro Gatti2025-02-07
| | | | | | | | | | | This commit fixes two Xtensa sequences in order to terminate early when loading and storing word values via an immediate index. This was meant to be part of 55ca3fd67512555707304c6b68b836eb89f09d1c but whilst it was part of the code being tested, it didn't end up in the commit. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/emitnative: Mark condition code tables as const.Alessandro Gatti2025-02-07
| | | | | | | | This commit marks as const the condition code tables used when figuring out which opcode sequence must be emitted depending on the requested comparison type. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/mkrules.mk: Reset USER_C_MODULES when building mpy-cross dependency.Andrew Leech2025-02-07
| | | | | | | | | | | | When a port automatically compiles `mpy-cross`, if `USER_C_MODULES` is provided by the user on the command line then it is also applied to the `mpy-cross` build. That can lead to build errors if the path is relative and not found when building `mpy-cross`. Fix that by explicitly resetting `USER_C_MODULES` when invoking the `mpy-cross` build. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
* py/gc: Reorder static functions for clarity.Angus Gratton2025-02-03
| | | | | | | | | | | | - Renamed gc_sweep to gc_sweep_free_blocks. - Call gc_sweep_run_finalisers from top level. - Reordered the gc static functions to be in approximate runtime sequence (with forward declarations) rather than in declaration order. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py: Add optional support for recursive mutexes, use for gc mutex.Angus Gratton2025-02-03
| | | | | | | | Enabled by default if using threading and no GIL This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py/gc: Allow gc_free from inside a gc_sweep finalizer.Angus Gratton2025-02-03
| | | | | | | | | | | | | | | | | | Do this by tracking being inside gc collection with a separate flag, GC_COLLECT_FLAG. In gc_free(), ignore this flag when determining if the heap is locked. * For finalisers calling gc_free() when heap is otherwise unlocked, this allows memory to be immediately freed (potentially avoiding a MemoryError). * Hard IRQs still can't call gc_free(), as heap will be locked via gc_lock(). * If finalisers are disabled then all of this code can be compiled out to save some code size. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py/gc: Split out running finalizers to a separate pass.Angus Gratton2025-02-03
| | | | | | | | | | | Currently a finalizer may run and access memory which has already been freed. (This happens mostly during gc_sweep_all() but could happen during any garbage collection pass.) Includes some speed improvement tweaks to skip empty FTB blocks. These help compensate for the inherent slowdown of having to walk the heap twice. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py/parsenumbase: Favor clarity of code over manual optimisation.Jeff Epler2025-01-29
| | | | | | | | | Follow up to 13b13d1fdd05549d504eeded0b5aa8871d5e5dcf, based on some testing on godbolt, the manual code optimisation seems unnecessary for code size, at least on gcc x86_64 and ARM, and it's definitely not good for clarity. Signed-off-by: Jeff Epler <jepler@gmail.com>
* py/mkrules: Add GIT_SUBMODULES_FAIL_IF_EMPTY flag for CMake ports.Angus Gratton2025-01-29
| | | | | | | | | The way CMake gathers the submodule list, it can quietly be empty if the previous step fails. This makes it an explicit error. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py/emitnative: Optimise Viper immediate offset load/stores on Xtensa.Alessandro Gatti2025-01-26
| | | | | | | | | | | This commit introduces the ability to emit optimised code paths on Xtensa for load/store operations indexed via an immediate offset. If an immediate offset for a load/store operation is within a certain range that allows it to be embedded into an available opcode then said opcode is emitted instead of the generic code sequence. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/emitnative: Emit shorter exception handler entry code on RV32.Alessandro Gatti2025-01-26
| | | | | | | | | | | | | This commit improves the RV32 code sequence that is emitted if a function needs to set up an exception handler as its prologue. The old code would clear a temporary register and then copy that value to places that needed to be initialised with zero values. On RV32 there's a dedicated register that's hardwired to be equal to zero, which allows us to bypass the extra register clear and use the zero register to initialise values. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/emitnative: Optimise Viper register offset load/stores on Xtensa.Alessandro Gatti2025-01-26
| | | | | | | | | | | | This commit improves the emitted code sequences for address generation in the Viper subsystem when loading/storing 16 and 32 bit values via a register offset. The Xtensa opcodes ADDX2 and ADDX4 are used to avoid performing the extra shifts to align the final operation offset. Those opcodes are available on both xtensa and xtensawin MicroPython architectures. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/parsenum: Throw an exception for invalid int literals like "01".Jeff Epler2025-01-26
| | | | | | | | | | | | | | | This includes making int("01") parse in base 10 like standard Python. When a base of 0 is specified it means auto-detect based on the prefix, and literals begining with 0 (except when the literal is all 0's) like "01" are then invalid and now throw an exception. The new error message is different from CPython. It says e.g., `SyntaxError: invalid syntax for integer with base 0: '09'` Additional test cases were added to cover the changed & added code. Co-authored-by: Damien George <damien@micropython.org> Signed-off-by: Jeff Epler <jepler@gmail.com>
* py/persistentcode: Initialize prelude_ptr to prevent compiler warning.IhorNehrutsa2025-01-24
| | | | | | | | | The esp32 IDF toolchain can give a "may be used uninitialized" warning, at least for ESP32-S3 with gcc 14.2.0. Silence that warning by initializing the variable with NULL. Co-authored-by: Daniel van de Giessen <daniel@dvdgiessen.nl> Signed-off-by: IhorNehrutsa <Ihor.Nehrutsa@gmail.com>
* py/mkrules.mk: Move comment about partial clones outside make rule.Damien George2025-01-17
| | | | | | | | Otherwise the comment is printed each time the rule is run. Follow up to fdd606dd5395d9c474775945fa4458a27199653b. Signed-off-by: Damien George <damien@micropython.org>
* py/asmarm: Fix halfword loads with larger offsets.Alessandro Gatti2025-01-16
| | | | | | | | | | | | | | This commit fixes code generation for loading halfwords using an offset greater than 255. The old code blindly encoded the offset into a `LDRH Rd, [Rn, #imm]` opcode, but only the lowest 8 bits would be put into the opcode itself. This commit instead generates a two-opcodes sequence, a constant load into R8, and then `LDRH Rd, [Rn, R8]`. This fixes `tests/extmod/vfs_rom.py` for the qemu/SABRELITE board. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/asmarm: Fix locals address loading code generation with large imm.Alessandro Gatti2025-01-16
| | | | | | | | | | | | | | This commit fixes code generation for loading a local's address if its index is greater than 63. The old code blindly encoded the offset into an `ADD Rd, Rn, #imm` opcode, but only the lowest 8 bits would be put into the opcode itself. This commit instead generates a two-opcodes sequence, a constant load into R8, and then an `ADD Rd, Rn, R8` opcode. This fixes `tests/float/math_domain.py` for the qemu/SABRELITE board. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/asmarm: Allow function state to be larger than 255.Damien George2025-01-06
| | | | | Co-authored-by: Alessandro Gatti <a.gatti@frob.it> Signed-off-by: Damien George <damien@micropython.org>
* py/asmarm: Fix asm_arm_ldrh_reg_reg_offset to emit correct machine code.Damien George2025-01-06
| | | | | | | | Prior to this fix, the assembler generated `LDRH Rd, [Rn, #imm]!`, so the second `LDRH` from the same origin would load from the wrong base. Co-authored-by: Alessandro Gatti <a.gatti@frob.it> Signed-off-by: Damien George <damien@micropython.org>
* py/obj: Make literals unsigned in float get/new functions.Yoctopuce2025-01-02
| | | | | | Fixes gcc warning when -Wsign-conversion is on. Signed-off-by: Yoctopuce <dev@yoctopuce.com>
* py/obj: Cast float literals to 64-bit to prevent overflow warning.Yoctopuce2025-01-02
| | | | | | Fixes compilation warning C4307: '+': integral constant overflow. Signed-off-by: Yoctopuce <dev@yoctopuce.com>