summaryrefslogtreecommitdiffstatshomepage
path: root/py
Commit message (Collapse)AuthorAge
...
* py/emitnative: Add more DEBUG_printf statements.Damien George2024-06-21
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/emitnative: Emit better load/store sequences for RISC-V RV32IMC.Alessandro Gatti2024-06-21
| | | | | | | Selected load/store code sequences have been optimised for RV32IMC when the chance to use fewer and smaller opcodes was possible. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* mpy-cross: Add RISC-V RV32IMC support in MPY files.Alessandro Gatti2024-06-21
| | | | | | | MPY files can now hold generated RV32IMC native code. This can be accomplished by passing the `-march=rv32imc` flag to mpy-cross. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/asmrv32: Add RISC-V RV32IMC native code emitter.Alessandro Gatti2024-06-21
| | | | | | | This adds a native code generation backend for RISC-V RV32I CPUs, currently limited to the I, M, and C instruction sets. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* py/objdeque: Fix deque type flags based on option settings.Dan Halbert2024-06-21
| | | | | | | | | This fixes a minor issue in the changes made by 7dff38fdc190d7b731fad8319d2ae8aa13fde18a: the type flags for deque were meant to be conditionalized based on MICROPY_PY_COLLECTIONS_DEQUE_ITER, but the computed conditionalized value wasn't used. Signed-off-by: Dan Halbert <halbert@halwitz.org>
* extmod/modasyncio: Add support for a callback on TaskQueue push.Damien George2024-06-20
| | | | | | | Allows passing in a callback to `TaskQueue()` that is called when something is pushed on to the queue. Signed-off-by: Damien George <damien@micropython.org>
* py/lexer: Support raw f-strings.Damien George2024-06-06
| | | | | | | | Support for raw str/bytes already exists, and extending that to raw f-strings is easy. It also reduces code size because it eliminates an error message. Signed-off-by: Damien George <damien@micropython.org>
* py/lexer: Support concatenation of adjacent f-strings.Damien George2024-06-06
| | | | | | | This is quite a simple and small change to support concatenation of adjacent f-strings, and improve compatibility with CPython. Signed-off-by: Damien George <damien@micropython.org>
* py/nlrrv32: Add RISC-V RV32I NLR implementation.Alessandro Gatti2024-06-06
| | | | | | Add custom NLR support for 32 bits RISC-V RV32I targets. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* all: Bump version to 1.24.0-preview.v1.24.0-previewDamien George2024-05-31
| | | | Signed-off-by: Damien George <damien@micropython.org>
* all: Bump version to 1.23.0.v1.23.0Damien George2024-05-31
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/dynruntime: Export mp_load_method_maybe and mp_arg_parse_all* funcs.Brian Pugh2024-05-24
| | | | | | | Also define `mp_type_bytearray`. These all help to write native modules. Signed-off-by: Brian Pugh <bnp117@gmail.com> Signed-off-by: Damien George <damien@micropython.org>
* py/dynruntime: Add mp_obj_exception_init function to create C exception.Damien George2024-05-23
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/nlrthumb: Make non-Thumb2 long-jump workaround opt-in.J. Neuschäfer2024-04-25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Although the original motivation given for the workaround[1] is correct, nlr.o and nlrthumb.o are linked with a small enough distance that the problem does not occur, and the workaround isn't necessary. The distance between the b instruction and its target (nlr_push_tail) is just 64 bytes[2], well within the ±2046 byte range addressable by an unconditional branch instruction in Thumb mode. The workaround induces a relocation in the text section (textrel), which isn't supported everywhere, notably not on musl-libc[3], where it causes a crash on start-up. With the workaround removed, micropython works on an ARMv5T Linux system built with musl-libc. This commit changes nlrthumb.c to use a direct jump by default, but leaves the long jump workaround as an option for those cases where it's actually needed. [1]: commit dd376a239dc4f47b0ee7866810fcda151f3cf6dd Author: Damien George <damien.p.george@gmail.com> Date: Fri Sep 1 15:25:29 2017 +1000 py/nlrthumb: Get working again on standard Thumb arch (ie not Thumb2). "b" on Thumb might not be long enough for the jump to nlr_push_tail so it must be done indirectly. [2]: Excerpt from objdump -d micropython: 000095c4 <nlr_push_tail>: 95c4: b510 push {r4, lr} 95c6: 0004 movs r4, r0 95c8: f02d fd42 bl 37050 <mp_thread_get_state> 95cc: 6943 ldr r3, [r0, #20] 95ce: 6023 str r3, [r4, #0] 95d0: 6144 str r4, [r0, #20] 95d2: 2000 movs r0, #0 95d4: bd10 pop {r4, pc} 000095d6 <nlr_pop>: 95d6: b510 push {r4, lr} 95d8: f02d fd3a bl 37050 <mp_thread_get_state> 95dc: 6943 ldr r3, [r0, #20] 95de: 681b ldr r3, [r3, #0] 95e0: 6143 str r3, [r0, #20] 95e2: bd10 pop {r4, pc} 000095e4 <nlr_push>: 95e4: 60c4 str r4, [r0, #12] 95e6: 6105 str r5, [r0, #16] 95e8: 6146 str r6, [r0, #20] 95ea: 6187 str r7, [r0, #24] 95ec: 4641 mov r1, r8 95ee: 61c1 str r1, [r0, #28] 95f0: 4649 mov r1, r9 95f2: 6201 str r1, [r0, #32] 95f4: 4651 mov r1, sl 95f6: 6241 str r1, [r0, #36] @ 0x24 95f8: 4659 mov r1, fp 95fa: 6281 str r1, [r0, #40] @ 0x28 95fc: 4669 mov r1, sp 95fe: 62c1 str r1, [r0, #44] @ 0x2c 9600: 4671 mov r1, lr 9602: 6081 str r1, [r0, #8] 9604: e7de b.n 95c4 <nlr_push_tail> [3]: https://www.openwall.com/lists/musl/2020/09/25/4 Signed-off-by: J. Neuschäfer <j.ne@posteo.net>
* py/objarray: Fix use-after-free if extending a bytearray from itself.Angus Gratton2024-04-22
| | | | | | | | | | | | | | | | | | | | | | | Two cases, one assigning to a slice. Closes https://github.com/micropython/micropython/issues/13283 Second is extending a slice from itself, similar logic. In both cases the problem occurs when m_renew causes realloc to move the buffer, leaving a dangling pointer behind. There are more complex and hard to fix cases when either argument is a memoryview into the buffer, currently resizing to a new address breaks memoryviews into that object. Reproducing this bug and confirming the fix was done by running the unix port under valgrind with GC-aware extensions. Note in default configurations with GIL this bug exists but has no impact (the free buffer won't be reused while the function is still executing, and is no longer referenced after it returns). Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py/obj: Fix initialiser order in MP_DEFINE_CONST_OBJ_TYPE_NARGS_ macros.Vonasmic2024-04-22
| | | | | | | | | This commit swaps the order of the `flags` and `name` struct initialisers for `mp_obj_type_t`, to fix an incompatibility with C++. The original order of the initialiser didn't match the definition of the type, and although that's still legal C, it's not legal C++. Signed-off-by: Vonasmic <kasarkal123@gmail.com>
* py/objfun: Fix C++ compatibility with casting in inline functions.stijn2024-04-22
| | | | | | | | | Explicit casts are needed. Fixes recent changes from 648a7578da21cc7ddb4046fc59891144e797b983 and 9400229766624e80db6a6f95af287a5542dc1b43. Signed-off-by: stijn <stijn@ignitron.net>
* py/persistentcode: Bump .mpy sub-version to 6.3.Damien George2024-03-28
| | | | | | | | | | | | | This is required because the .mpy native ABI was changed by the introduction of `mp_proto_fun_t`, see commits: - 416465d81e911b088836f4e7c37fac2bc0f67917 - 5e3006f1172d0eabbbefeb3268dfb942ec7cf9cd - e2ff00e81113d7a3f32f860652017644b5d68bf1 And three `mp_binary` functions were added to `mp_fun_table` in commit d2276f0d41c2fa66a224725fdb2411846c91cf1a. Signed-off-by: Damien George <damien@micropython.org>
* py/dynruntime: Add mp_binary_get_size/get_val_array/set_val_array.Damien George2024-03-28
| | | | | | | These are needed to read/write array.array objects, which is useful in native code to provide fast extensions that work with big arrays of data. Signed-off-by: Damien George <damien@micropython.org>
* py/makeqstrdata.py: Ensure that scope names get low qstr values.Jim Mussared2024-03-26
| | | | | | | | Originally implemented in a patch file provided by @ironss-iotec. Fixes issue #14093. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* py/nlr: Add "memory" to asm clobbers list in nlr_jump.Damien George2024-03-25
| | | | | | | | | | | | | Newer versions of gcc (14 and up) have more sophisticated dead-code detection, and the asm clobbers list needs to contain "memory" to inform the compiler that the asm code actually does something. Tested that adding this "memory" line does not change the generated code on ARM Thumb2, x86-64 and Xtensa targets (using gcc 13.2). Fixes issue #14115. Signed-off-by: Damien George <damien@micropython.org>
* py/compile: Add option to allow compiling top-level await.Damien George2024-03-22
| | | | | | | | Enabled by MICROPY_COMPILE_ALLOW_TOP_LEVEL_AWAIT. When enabled, this means that scope such as module-level functions and REPL statements can yield. The outer C code must then handle this yielded generator. Signed-off-by: Damien George <damien@micropython.org>
* py/parse: Zero out dangling parse tree pointer to fix potential GC leak.Angus Gratton2024-03-22
| | | | | | | | | | | | | | | | | | | | | | | | | | This fixes a bug where a random Python object may become un-garbage-collectable until an enclosing Python file (compiled on device) finishes executing. Details: The mp_parse_tree_t structure is stored on the stack in top-level functions such as parse_compile_execute() in pyexec.c (and others). Although it quickly falls out of scope in these functions, it is usually still in the current stack frame when the compiled code executes. (Compiler dependent, but usually it's one stack push per function.) This means if any Python object happens to allocate at the same address as the (freed) root parse tree chunk, it's un-garbage-collectable as there's a (dangling) pointer up the stack referencing this same address. As reported by @GitHubsSilverBullet here: https://github.com/orgs/micropython/discussions/14116#discussioncomment-8837214 This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py/binary: Support half-float 'e' format in struct pack/unpack.Matthias Urlichs2024-03-20
| | | | | | | | | This commit implements the 'e' half-float format: 10-bit mantissa, 5-bit exponent. It uses native _Float16 if supported by the compiler, otherwise uses custom bitshifting encoding/decoding routines. Signed-off-by: Matthias Urlichs <matthias@urlichs.de> Signed-off-by: Damien George <damien@micropython.org>
* py/emitnative: Implement viper unary ops positive, negative and invert.Damien George2024-03-19
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/asmxtensa: Optimise asm_xtensa_mov_reg_i32_optimised() for tiny ints.Damien George2024-03-19
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/asm: Add ASM_NOT_REG and ASM_NEG_REG macros for unary ops.Damien George2024-03-19
| | | | | | | | ASM_NOT_REG is optional, it can be synthesised by xor(reg, -1). ASM_NEG_REG can also be synthesised with a subtraction, but most architectures have a dedicated instruction for it. Signed-off-by: Damien George <damien@micropython.org>
* py/objdeque: Expand implementation to be doubly-ended and support iter.Dash Peters2024-03-18
| | | | | | | | | | | | | Add `pop()`, `appendleft()`, and `extend()` methods, support iteration and indexing, and initializing from an existing sequence. Iteration and indexing (subscription) have independent configuration flags to enable them. They are enabled by default at the same level that collections.deque is enabled (the extra features level). Also add tests for checking new behavior. Signed-off-by: Damien George <damien@micropython.org>
* py/stream: Factor stream implementations.Damien George2024-03-15
| | | | | | So there's only one location that does the ioctl(MP_STREAM_SEEK) call. Signed-off-by: Damien George <damien@micropython.org>
* py/stream: Add mp_stream_seek() helper function.iabdalkader2024-03-15
| | | | Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
* extmod/machine_usb_device: Add support for Python USB devices.Angus Gratton2024-03-15
| | | | | | | | | | | | | This new machine-module driver provides a "USBDevice" singleton object and a shim TinyUSB "runtime" driver that delegates the descriptors and all of the TinyUSB callbacks to Python functions. This allows writing arbitrary USB devices in pure Python. It's also possible to have a base built-in USB device implemented in C (eg CDC, or CDC+MSC) and a Python USB device added on top of that. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py/objstr: Add a macro to define a bytes object at compile time.Angus Gratton2024-03-15
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* extmod/modmachine: Add MICROPY_PY_MACHINE_RESET configuration option.Damien George2024-03-15
| | | | | | | Disabled by default, but enabled on all boards that previously had `MICROPY_PY_MACHINE_BARE_METAL_FUNCS` enabled. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modmachine: Add MICROPY_PY_MACHINE_MEMX configuration option.Damien George2024-03-15
| | | | | | Enabled by default. Signed-off-by: Damien George <damien@micropython.org>
* extmod/modmachine: Add MICROPY_PY_MACHINE_SIGNAL configuration option.Damien George2024-03-15
| | | | | | Enabled by default. Signed-off-by: Damien George <damien@micropython.org>
* all: Remove the "STATIC" macro and just use "static" instead.Angus Gratton2024-03-07
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The STATIC macro was introduced a very long time ago in commit d5df6cd44a433d6253a61cb0f987835fbc06b2de. The original reason for this was to have the option to define it to nothing so that all static functions become global functions and therefore visible to certain debug tools, so one could do function size comparison and other things. This STATIC feature is rarely (if ever) used. And with the use of LTO and heavy inline optimisation, analysing the size of individual functions when they are not static is not a good representation of the size of code when fully optimised. So the macro does not have much use and it's simpler to just remove it. Then you know exactly what it's doing. For example, newcomers don't have to learn what the STATIC macro is and why it exists. Reading the code is also less "loud" with a lowercase static. One other minor point in favour of removing it, is that it stops bugs with `STATIC inline`, which should always be `static inline`. Methodology for this commit was: 1) git ls-files | egrep '\.[ch]$' | \ xargs sed -Ei "s/(^| )STATIC($| )/\1static\2/" 2) Do some manual cleanup in the diff by searching for the word STATIC in comments and changing those back. 3) "git-grep STATIC docs/", manually fixed those cases. 4) "rg -t python STATIC", manually fixed codegen lines that used STATIC. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
* py/emitglue: Add explicit cast of proto_fun to uint8_t pointer.Damien George2024-03-04
| | | | | | | Otherwise C++ compilers may complain when this header is included in an extern "C" block. Signed-off-by: Damien George <damien@micropython.org>
* py/modthread: Move thread state initialisation to shared function.Daniël van de Giessen2024-02-29
| | | | Signed-off-by: Daniël van de Giessen <daniel@dvdgiessen.nl>
* py/mpstate: Don't declare mp_thread_get_state().Damien George2024-02-29
| | | | | | It's instead declared by the include of `py/mpthread.h`. Signed-off-by: Damien George <damien@micropython.org>
* py/emitbc: Remove call to adjust Python stack by 0 entries.Damien George2024-02-29
| | | | | | | | | | This call used to be needed when there was an `emit_bc_pre()` function that needed to be called at the start of each emitted bytecode. But in 8e7745eb315cdaf7dec033891f88e091ab4e016e that function was removed and now the call to `mp_emit_bc_adjust_stack_size()` does nothing when adjusting by 0 entries, so it can be removed. Signed-off-by: Damien George <damien@micropython.org>
* py/mpconfig: Change the default enable level for the vfs module.robert-hh2024-02-26
| | | | | | | | | For boards with MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES and up. This gets samd21 boards working (which need the vfs module in _boot.py), B_L072Z_LRWAN1, and nrf boards with smaller MCUs that use CORE or BASIC feature levels. Signed-off-by: robert-hh <robert@hammelrath.com>
* py/emitglue: Make mp_emit_glue_assign_native's fun_data arg a const ptr.Damien George2024-02-22
| | | | | | | It will only ever be read from, and in some cases (eg on esp8266) can actually be in ROM. Signed-off-by: Damien George <damien@micropython.org>
* py/compile: Remove TODO about name mangling.Damien George2024-02-21
| | | | | | | This TODO is now covered by the tests/cpydiff/core_class_name_mangling.py test. Signed-off-by: Damien George <damien@micropython.org>
* py/builtinevex: Fix setting globals for native functions in compile().Damien George2024-02-20
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/emitglue: Remove n_pos_args from DEBUG_printf.Damien George2024-02-20
| | | | | | This argument was renamed in 39bf055d23be4b0f761af115773c3db1074fc2dd. Signed-off-by: Damien George <damien@micropython.org>
* py/objfun: Inline mp_obj_code_get_name() into mp_obj_fun_get_name().Damien George2024-02-20
| | | | | | The former is static and does not need to be a separate function. Signed-off-by: Damien George <damien@micropython.org>
* py/objfun: Support __name__ on native functions and generators.Damien George2024-02-20
| | | | | | | | This is now easy to support, since the first machine-word of a native function tells how to find the prelude, from which the function name can be extracted in the same way as for bytecode. Signed-off-by: Damien George <damien@micropython.org>
* py/emitnative: Simplify layout and loading of native function prelude.Damien George2024-02-20
| | | | | | | | | | Now native functions and native generators have similar behaviour: the first machine-word of their code is an index to get to the prelude. This simplifies the handling of these types of functions, and also reduces the size of the emitted native machine code by no longer requiring special code at the start of the function to load a pointer to the prelude. Signed-off-by: Damien George <damien@micropython.org>
* py/objfun: Split viper fun type out to separate mp_type_fun_viper type.Damien George2024-02-20
| | | | | | | | Viper functions are quite different to native functions and benefit from being a separate type. For example, viper functions don't have a bytecode- style prelude, and don't support generators or default arguments. Signed-off-by: Damien George <damien@micropython.org>
* py/objfun: Make mp_obj_new_fun_native/mp_obj_new_fun_asm static-inline.Damien George2024-02-20
| | | | | | To reduce code size, since they are only used once by py/emitglue.c. Signed-off-by: Damien George <damien@micropython.org>