summaryrefslogtreecommitdiff
path: root/py
AgeCommit message (Collapse)Author
2025-01-24py/persistentcode: Initialize prelude_ptr to prevent compiler warning.IhorNehrutsa
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>
2025-01-17py/mkrules.mk: Move comment about partial clones outside make rule.Damien George
Otherwise the comment is printed each time the rule is run. Follow up to fdd606dd5395d9c474775945fa4458a27199653b. Signed-off-by: Damien George <damien@micropython.org>
2025-01-16py/asmarm: Fix halfword loads with larger offsets.Alessandro Gatti
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>
2025-01-16py/asmarm: Fix locals address loading code generation with large imm.Alessandro Gatti
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>
2025-01-06py/asmarm: Allow function state to be larger than 255.Damien George
Co-authored-by: Alessandro Gatti <a.gatti@frob.it> Signed-off-by: Damien George <damien@micropython.org>
2025-01-06py/asmarm: Fix asm_arm_ldrh_reg_reg_offset to emit correct machine code.Damien George
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>
2025-01-02py/obj: Make literals unsigned in float get/new functions.Yoctopuce
Fixes gcc warning when -Wsign-conversion is on. Signed-off-by: Yoctopuce <dev@yoctopuce.com>
2025-01-02py/obj: Cast float literals to 64-bit to prevent overflow warning.Yoctopuce
Fixes compilation warning C4307: '+': integral constant overflow. Signed-off-by: Yoctopuce <dev@yoctopuce.com>
2025-01-02py/emitinlinerv32: Add inline assembler support for RV32.Alessandro Gatti
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>
2025-01-01py/misc: Add a popcount(uint32_t) implementation.Alessandro Gatti
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>
2024-12-23py/persistentcode: Add support for loading .mpy files from a ROM reader.Damien George
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>
2024-12-23py/reader: Provide mp_reader_try_read_rom() function.Damien George
This allows accessing data directly in ROM if the reader supports it. Signed-off-by: Damien George <damien@micropython.org>
2024-12-23py/qstr: Add qstr_from_strn_static() helper function.Damien George
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>
2024-12-23extmod/vfs_rom: Add VfsRom filesystem object.Damien George
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>
2024-12-23py/dynruntime.mk: Delete compiled module file on clean.Alessandro Gatti
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>
2024-12-23tools/mpy_ld.py: Add native modules support for RV32 code.Alessandro Gatti
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>
2024-12-20extmod/vfs: Guard mutating fs functions with MICROPY_VFS_WRITABLE.Damien George
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>
2024-12-10py/mkrules.mk: Use partial clone for submodules if available.Andrew Leech
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>
2024-12-10py/emitglue: Fix clear cache builtin warning on Clang for AArch32.Alessandro Gatti
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>
2024-12-10py/misc: Fix msvc and C++ compatibility.stijn
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>
2024-12-10esp32: Pass V=1 or BUILD_VERBOSE through to idf.py when building.Angus Gratton
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>
2024-11-28py/objfloat: Workaround non-constant NAN definition on Windows MSVC.Angus Gratton
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>
2024-11-20py/usermod.cmake: If USER_C_MODULES is a folder add micropython.cmake.Andrew Leech
This mirrors how it works when using a Makefile. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2024-11-20py/usermod.cmake: Add check that any specified USER_C_MODULES exists.Andrew Leech
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2024-11-20py/py.mk: Add check that any specified USER_C_MODULES folder exists.Andrew Leech
Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2024-11-04py/objdeque: Fix buffer overflow in deque_subscr.Jan Sturm
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>
2024-10-30pic16bit: Make it build with recent XC16 versions.Alessandro Gatti
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>
2024-10-28all: Bump version to 1.25.0-preview.v1.25.0-previewDamien George
Signed-off-by: Damien George <damien@micropython.org>
2024-10-26all: Bump version to 1.24.0.v1.24.0Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-10-25extmod/modtls_mbedtls: Add a thread-global ptr for current SSL context.iabdalkader
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>
2024-10-16py/objtype: Don't delegate lookup of descriptor methods to __getattr__.Damien George
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>
2024-10-15py/usermod.cmake: Check target exists in usermod_gather_sources.Phil Howard
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>
2024-10-07py/objtype: Allow passing keyword arguments to native base __init__.stijn
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>
2024-10-03py/nlrrv64: Add RISC-V RV64I NLR implementation.Alessandro Gatti
Add custom NLR support for 64 bits RISC-V RV64I targets. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-09-27py/parse: Remove old esp32 compiler workaround.Alessandro Gatti
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>
2024-09-26py/mpz: Skip separators when running out of digits to print.Alessandro Gatti
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>
2024-09-26py/persistentcode: Explicitly track native BSS/rodata when needed.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2024-09-19py/objringio: Add micropython.RingIO() interface for general use.Andrew Leech
This commit adds a new `RingIO` type which exposes the internal ring-buffer code for general use in Python programs. It has the stream interface making it similar to `StringIO` and `BytesIO`, except `RingIO` has a fixed buffer size and is automatically safe when reads and writes are in different threads or an IRQ. This new type is enabled at the "extra features" ROM level. Signed-off-by: Andrew Leech <andrew.leech@planetinnovation.com.au>
2024-09-19py/scheduler: Only run callbacks on the main thread if GIL is disabled.Angus Gratton
Otherwise it's very difficult to reason about thread safety in a scheduler callback, as it can run at any time on any thread - including racing against any bytecode operation on any thread. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-09-02py/objint: Make byteorder argument optional in int.from_bytes() method.Amirreza Hamzavi
This was made optional in CPython 3.11. Signed-off-by: Amirreza Hamzavi <amirrezahamzavi2000@gmail.com>
2024-09-02py/objint: Make length argument optional in int.to_bytes() method.Amirreza Hamzavi
This was made optional in CPython 3.11. Signed-off-by: Amirreza Hamzavi <amirrezahamzavi2000@gmail.com>
2024-09-02py/objint: Make byteorder argument optional in int.to_bytes() method.Amirreza Hamzavi
This was made optional in CPython 3.11. Signed-off-by: Amirreza Hamzavi <amirrezahamzavi2000@gmail.com>
2024-08-26py/mkrules.mk: Fix 'make submodules' when building out-of-tree.Christian Walther
When MicroPython is used as a submodule and built from the containing project, e.g. for the embed port, `make submodules` fails because it goes looking for the sub-sub-module paths in the outer repository instead of in the micropython repository. Fix this by invoking git inside the micropython submodule. Signed-off-by: Christian Walther <cwalther@gmx.ch>
2024-08-19py/asmrv32: Use REG_TEMP2 whenever possible.Alessandro Gatti
The RV32 emitter used an additional temporary register, as certain code sequences required extra storage. This commit removes its usage in all but one case, using REG_TEMP2 instead. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-08-19py/asmrv32: Emit C.LW opcodes only when necessary.Alessandro Gatti
The RV32 emitter sometimes generated short load opcodes even when it was not supposed to. This commit fixes an off-by-one error in its offset eligibility range calculation and corrects one case of offset calculation, operating on the raw label index number rather than its effective offset in the stack (C.LW assumes all loads are word-aligned). Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-08-19py/asmrv32: Fix short/long jumps scheduling.Alessandro Gatti
The RV32 emitter always scheduled short jumps even outside the emit compiler pass. Running the full test suite through the native emitter instead of just the tests that depend on the emitter at runtime (as in, `micropython/native_*` and `micropython/viper_* tests`) uncovered more places where the invalid behaviour was still present. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
2024-08-19py/objstr: Skip whitespace in bytes.fromhex().Glenn Moloney
Skip whitespace characters between pairs of hex numbers. This makes `bytes.fromhex()` compatible with cpython. Includes simple test in `tests/basic/builtin_str_hex.py`. Signed-off-by: Glenn Moloney <glenn.moloney@gmail.com>
2024-08-14py: Add new cstack API for stack checking, with limit margin macro.Angus Gratton
Currently the stack limit margin is hard-coded in each port's call to `mp_stack_set_limit()`, but on threaded ports it's fiddlier and can lead to bugs (such as incorrect thread stack margin on esp32). This commit provides a new API to initialise the C Stack in one function call, with a config macro to set the margin. Where possible the new call is inlined to reduce code size in thread-free ports. Intended replacement for `MP_TASK_STACK_LIMIT_MARGIN` on esp32. The previous `stackctrl.h` API is still present and unmodified apart from a deprecation comment. However it's not available when the `MICROPY_PREVIEW_VERSION_2` macro is set. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-08-14py/obj: Remove the legacy object API for version 2.Angus Gratton
These were changed in v1.11 (2019). Prepare to remove the compatibility macros as part of V2 changes. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-08-07py/modmath: Add option to work around -inf bug in a port's tgamma.Angus Gratton
This is needed for a workaround on esp32 port (in child commit), which produces incorrect results otherwise. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>