summaryrefslogtreecommitdiffstatshomepage
path: root/py
Commit message (Collapse)AuthorAge
* 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>
* py/emitinlinerv32: Add inline assembler support for RV32.Alessandro Gatti2025-01-02
| | | | | | | | | | | | This commit adds support for writing inline assembler functions when targeting a RV32IMC processor. Given that this takes up a bit of rodata space due to its large instruction decoding table and its extensive error messages, it is enabled by default only on offline targets such as mpy-cross and the qemu port. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/misc: Add a popcount(uint32_t) implementation.Alessandro Gatti2025-01-01
| | | | | | | | | | This makes the existing popcount(uint32_t) implementation found in the RV32 emitter available to the rest of the codebase. This version of popcount will use intrinsic or builtin implementations if they are available, falling back to a generic implementation if that is not the case. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/persistentcode: Add support for loading .mpy files from a ROM reader.Damien George2024-12-23
| | | | | | | | This adds an optimisation for loading .mpy files from a reader that points to ROM. In such a case qstr, str and bytes data, along with bytecode, are all referenced in-place in ROM. Signed-off-by: Damien George <damien@micropython.org>
* py/reader: Provide mp_reader_try_read_rom() function.Damien George2024-12-23
| | | | | | This allows accessing data directly in ROM if the reader supports it. Signed-off-by: Damien George <damien@micropython.org>
* py/qstr: Add qstr_from_strn_static() helper function.Damien George2024-12-23
| | | | | | | Allows an interned string to reference static/ROM data, instead of allocating it on the GC heap. Signed-off-by: Damien George <damien@micropython.org>
* extmod/vfs_rom: Add VfsRom filesystem object.Damien George2024-12-23
| | | | | | | | | | | | | | | | This commit defines a new ROMFS filesystem for storing read-only files that can be memory mapped, and a new VfsRom driver. Files opened from this filesystem support the buffer protocol. This allows naturally getting the memory-mapped address of the file using: - memoryview(file) - uctypes.addressof(file) Furthermore, if these files are .mpy files then their content can be referenced in-place when importing. Such imports take up a lot less RAM than importing from a normal filesystem. This is essentially dynamically frozen .mpy files, building on the revamped v6 .mpy file format. Signed-off-by: Damien George <damien@micropython.org>
* py/dynruntime.mk: Delete compiled module file on clean.Alessandro Gatti2024-12-23
| | | | | | | This commit adds the compiled native module file to the list of files to remove when `make clean` is issued in a native module source directory. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* tools/mpy_ld.py: Add native modules support for RV32 code.Alessandro Gatti2024-12-23
| | | | | | | | This commit adds support for RV32IMC native modules, as in embedding native code into a self-contained MPY module and and make its exported functions available to the MicroPython environment. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* extmod/vfs: Guard mutating fs functions with MICROPY_VFS_WRITABLE.Damien George2024-12-20
| | | | | | | Enabled by default. Useful for ports that need the VFS but don't have any writable filesystems. Signed-off-by: Damien George <damien@micropython.org>
* py/mkrules.mk: Use partial clone for submodules if available.Andrew Leech2024-12-10
| | | | | | | | | | | | | | | MicroPython relies on a number of submodules for third party and chip vendor libraries. Users need to check these out before building their desired ports and Github Actions CI here needs to clone them all multiple times for every build. Many of these are getting significantly larger over time, slowing down usage and consuming more disk space. Newer versions of git have features to avoid pulling all historic / blob data which can have a significant impact of total data use. This commit uses a standard feature of git to do a partial clone, with automatic fallback to previous behavior on error. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
* py/emitglue: Fix clear cache builtin warning on Clang for AArch32.Alessandro Gatti2024-12-10
| | | | | | | | | This commit fixes a warning occurring on Clang when calling `__builtin___clear_cache` with non-void pointers for its start and end memory area locations. The code now uses a char pointer for the end location, and it still builds without warnings on GCC. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/misc: Fix msvc and C++ compatibility.stijn2024-12-10
| | | | | | | Use an explicit cast to suppress the implicit conversion which started popping up in recent compiler versions (and wasn't there yet in 07bf3179). Signed-off-by: stijn <stijn@ignitron.net>
* esp32: Pass V=1 or BUILD_VERBOSE through to idf.py when building.Angus Gratton2024-12-10
| | | | | | | | | Allows verbose build to work the same on esp32 port as other ports. To minimise copy/paste, split the BUILD_VERBOSE section of mkenv.mk out to its own verbose.mk and include this in the port Makefile. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py/objfloat: Workaround non-constant NAN definition on Windows MSVC.Angus Gratton2024-11-28
| | | | | | | | | | | Recent MSVC versions have changed the definition of NAN to a non-constant expression! This is a bug, C standard says it should be a constant. Good explanation and workaround at: https://stackoverflow.com/a/79199887 This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py/usermod.cmake: If USER_C_MODULES is a folder add micropython.cmake.Andrew Leech2024-11-20
| | | | | | This mirrors how it works when using a Makefile. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
* py/usermod.cmake: Add check that any specified USER_C_MODULES exists.Andrew Leech2024-11-20
| | | | Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
* py/py.mk: Add check that any specified USER_C_MODULES folder exists.Andrew Leech2024-11-20
| | | | Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
* py/objdeque: Fix buffer overflow in deque_subscr.Jan Sturm2024-11-04
| | | | | | | | | | | | In `deque_subscr()`, if `index_val` equals `self->alloc`, the index correction `index_val -= self->alloc` does not execute, leading to an out-of-bounds access in `self->items[index_val]`. The fix in this commit ensures that the index correction is applied whenever `index_val >= self->alloc`, preventing access beyond the allocated buffer size. Signed-off-by: Jan Sturm <jansturm92@googlemail.com>
* pic16bit: Make it build with recent XC16 versions.Alessandro Gatti2024-10-30
| | | | | | | The PIC16 port didn't catch up with the other ports, so it required a bit of work to make it build with the latest version of XC16. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* all: Bump version to 1.25.0-preview.v1.25.0-previewDamien George2024-10-28
| | | | Signed-off-by: Damien George <damien@micropython.org>
* all: Bump version to 1.24.0.v1.24.0Damien George2024-10-26
| | | | Signed-off-by: Damien George <damien@micropython.org>
* extmod/modtls_mbedtls: Add a thread-global ptr for current SSL context.iabdalkader2024-10-25
| | | | | | | This is necessary for mbedTLS callbacks that do not carry any user state, so those callbacks can be customised per SSL context. Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* py/objtype: Don't delegate lookup of descriptor methods to __getattr__.Damien George2024-10-16
| | | | | | | | When descriptors are enabled, lookup of the `__get__`, `__set__` and `__delete__` descriptor methods should not be delegated to `__getattr__`. That follows CPython behaviour. Signed-off-by: Damien George <damien@micropython.org>
* py/usermod.cmake: Check target exists in usermod_gather_sources.Phil Howard2024-10-15
| | | | | | | Check a target exists before accessing properties. Otherwise usermod_gather_sources would recurse into garbage property names and break. Signed-off-by: Phil Howard <phil@gadgetoid.com>
* py/objtype: Allow passing keyword arguments to native base __init__.stijn2024-10-07
| | | | | | | | | | | | | | | Allowing passing keyword arguments to a native base's __init__, i.e. `make_new` in the C code. Previously only positional arguments were allowed. The main trade-off in this commit is that every call to the native base's `make_new` is now going to be preceded by a call to `mp_map_init_fixed_table` even though most of what that does is unused and instead it merely serves as a way to pass the number of keyword arguments. Fixes issue #15465. Signed-off-by: stijn <stijn@ignitron.net>
* py/nlrrv64: Add RISC-V RV64I NLR implementation.Alessandro Gatti2024-10-03
| | | | | | Add custom NLR support for 64 bits RISC-V RV64I targets. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/parse: Remove old esp32 compiler workaround.Alessandro Gatti2024-09-27
| | | | | | | | | | | | The ESP32 port contains a workaround to avoid having a certain function in `py/parse.c` being generated incorrectly. The compiler in question is not part of any currently supported version of ESP-IDF anymore, and the problem inside the compiler (well, assembler in this case) has been corrected a few years ago. This commit removes all traces of that workaround from the source tree. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/mpz: Skip separators when running out of digits to print.Alessandro Gatti2024-09-26
| | | | | | | | | | This commit fixes the addition of a stray separator before the number when printing an MPZ-backed integer and the first group is three digits long. This fixes #8984. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/persistentcode: Explicitly track native BSS/rodata when needed.Damien George2024-09-26
| | | | Signed-off-by: Damien George <damien@micropython.org>