summaryrefslogtreecommitdiffstatshomepage
path: root/examples/natmod
Commit message (Collapse)AuthorAge
* py/dynruntime.mk: Enable single-precision float by default on armv6/7m.Damien George2025-06-10
| | | | | | Soft float now works on these ARM targets thanks to the parent commit. Signed-off-by: Damien George <damien@micropython.org>
* examples/natmod/btree: Fix build for Xtensa.Alessandro Gatti2025-06-04
| | | | | | | | | | | | | This commit provides the appropriate external symbol addresses to let the "btree" example natmod build for the Xtensa platform. On the ESP8266, unsigned integer division code isn't provided as part of libgcc.a, libm.a, or libc.a, but it is instead provided by the ROM. Regular builds inject the appropriate symbol addresses as part of the linking process (see eagle.rom.addr.v6.ld), but natmods need this information brought in from somewhere else. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* examples/natmod/deflate: Fix build for Xtensa.Alessandro Gatti2025-06-04
| | | | | | | | | | | | | | | | | | | | This commit provides the appropriate external symbol addresses to let the "deflate" example natmod build for the Xtensa platform. Unlike other natmods that require an external symbol list to build without bringing in the whole runtime libraries set, this natmod is referencing the `__modsi3` symbol which was removed from the ESP8266's SDK but not present in ROM. The latter only has a `__umodsi3` implementation that only operates on unsigned values, and thus unable to handle this natmod. Thus, the extended library resolution process is enabled for this natmod as a `__modsi3` implementation is made available that way (still using ROM symbols whenever possible). This also means that symbols that appear in both ROM and external libraries sort of co-exist in the final MPY file, with ROM symbols being used by natmod code but the implementation from the library still exists in the final MPY file, unused. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* examples/natmod/framebuf: Fix build for Xtensa.Alessandro Gatti2025-06-04
| | | | | | | | | | | | | This commit provides the appropriate external symbol addresses to let the "framebuf" example natmod build for the Xtensa platform. On the ESP8266, integer division code isn't provided as part of libgcc.a, libm.a, or libc.a, but it is instead provided by the ROM. Regular builds inject the appropriate symbol addresses as part of the linking process (see eagle.rom.addr.v6.ld), but natmods need this information brought in from somewhere else. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* examples/natmod/random: Fix build for Xtensa.Alessandro Gatti2025-06-04
| | | | | | | | | | | | | This commit provides the appropriate external symbol addresses to let the "random" example natmod build for the Xtensa platform. On the ESP8266, signed integer division code isn't provided as part of libgcc.a, libm.a, or libc.a, but it is instead provided by the ROM. Regular builds inject the appropriate symbol addresses as part of the linking process (see eagle.rom.addr.v6.ld), but natmods need this information brought in from somewhere else. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
* extmod/modframebuf: Add support for blit'ing read-only data.Damien George2025-06-04
| | | | | | | | | | | | | | | | | | | | | | Currently the `FrameBuffer.blit(buf, x, y)` method requires the `buf` argument to be another `FrameBuffer`, which is quite restrictive because it doesn't allow blit'ing read-only memory/data. This commit extends `blit()` to allow the `buf` argument to be a tuple or list of the form: (buffer, width, height, format[, stride]) where `buffer` can be anything with the buffer protocol and may be read-only, eg `bytes`. Also, the palette argument to `blit()` may be of the same form. The form of this tuple/list was chosen to be the same as the signature of the `FrameBuffer` constructor (that saves quite a bit of code size doing it that way). 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>
* examples/natmod/re: Fix build on RV32 with alloca.Alessandro Gatti2024-12-23
| | | | | | | | | | | | This fixes compilation of the `re` natmod example when built with Picolibc in the CI environment. Ubuntu 22.04's combination of its bare metal RISC-V toolchain and its version of Picolibc makes the `alloca` symbol more elusive than it should be. This commit makes the `re` natmod try harder to get an `alloca` implementation. 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>
* examples/natmod: Fix URL links in README.md.Matt Trentini2024-09-17
| | | | Signed-off-by: Matt Trentini <matt.trentini@gmail.com>
* py: Add new cstack API for stack checking, with limit margin macro.Angus Gratton2024-08-14
| | | | | | | | | | | | | | | | | | | | 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>
* examples/natmod/btree: Make btree.open use mp_arg_parse_all for kwargs.Damien George2024-05-24
| | | | | | | Python code is no longer needed to implement keyword arguments in `btree.open()`, it can now be done in C. Signed-off-by: Damien George <damien@micropython.org>
* examples/natmod/features4: Create custom FactorialError as exc example.Damien George2024-05-23
| | | | Signed-off-by: Damien George <damien@micropython.org>
* examples/natmod/framebuf: Enable FrameBuffer.poly method.Damien George2024-03-28
| | | | Signed-off-by: Damien George <damien@micropython.org>
* all: Update extmod, ports, examples to build with new berkeley-db lib.Damien George2024-03-16
| | | | | | | | | | This provides a MicroPython-specific berkeley-db configuration in extmod/berkeley-db/berkeley_db_config_port.h, and cleans up the include path for this library. Fixes issue #13092. 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>
* extmod/modframebuf: Remove FrameBuffer1 from natmod build.Jim Mussared2023-10-16
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* examples/natmod: Add features4 as a class definition example.Jim Mussared2023-09-02
| | | | | | | | Also provide a basic README.md for dynamic native modules. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* examples: Mark asm, pio, etc. as noqa: F821 (undefined-name).Angus Gratton2023-08-16
| | | | | | | | | | | These files all use decorators (@asm_thumb, @asm_pio) that add names to the function scope, that the linter cannot see. It's useful to clear them in the file not in pyproject.toml as example code will be copied and adapted elsewhere, and those developers may also use Ruff (we hope!) Signed-off-by: Angus Gratton <angus@redyak.com.au>
* examples/natmod/deflate: Add deflate as a dynamic native module.Jim Mussared2023-07-21
| | | | | | | | This replaces the previous zlib version. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Remove the zlib module.Jim Mussared2023-07-21
| | | | | | | | | | | | This will be replaced with a new deflate module providing the same functionality, with an optional frozen Python wrapper providing a replacement zlib module. binascii.crc32 is temporarily disabled. This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* examples/natmod: Rename umodule to module.Jim Mussared2023-06-08
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Rename *umodule*.c to remove the "u" prefix.Jim Mussared2023-06-08
| | | | | | | | | | | Updates any includes, and references from Makefiles/CMake. This essentially reverts what was done long ago in commit 136b5cbd7669e8318f8455fc2706da97a5b7994c This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Rename UMODULE to MODULE in preprocessor/Makefile vars.Jim Mussared2023-06-08
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Rename mod_umodule*, ^umodule* to remove the "u" prefix.Jim Mussared2023-06-08
| | | | | | This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Rename MP_QSTR_umodule to MP_QSTR_module everywhere.Jim Mussared2023-06-08
| | | | | | | | | This renames the builtin-modules, such that help('modules') and printing the module object will show "module" rather than "umodule". This work was funded through GitHub Sponsors. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Fix spelling mistakes based on codespell check.Damien George2023-04-27
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/obj: Convert make_new into a mp_obj_type_t slot.Jim Mussared2022-09-19
| | | | | | | | | | | Instead of being an explicit field, it's now a slot like all the other methods. This is a marginal code size improvement because most types have a make_new (100/138 on PYBV11), however it improves consistency in how types are declared, removing the special case for make_new. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* py/obj: Merge getiter and iternext mp_obj_type_t slots.Jim Mussared2022-09-19
| | | | | | | | | | | | | | | | | | | | | | The goal here is to remove a slot (making way to turn make_new into a slot) as well as reduce code size by the ~40 references to mp_identity_getiter and mp_stream_unbuffered_iter. This introduces two new type flags: - MP_TYPE_FLAG_ITER_IS_ITERNEXT: This means that the "iter" slot in the type is "iternext", and should use the identity getiter. - MP_TYPE_FLAG_ITER_IS_CUSTOM: This means that the "iter" slot is a pointer to a mp_getiter_iternext_custom_t instance, which then defines both getiter and iternext. And a third flag that is the OR of both, MP_TYPE_FLAG_ITER_IS_STREAM: This means that the type should use the identity getiter, and mp_stream_unbuffered_iter as iternext. Finally, MP_TYPE_FLAG_ITER_IS_GETITER is defined as a no-op flag to give the default case where "iter" is "getiter". Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* py/obj: Add accessors for type slots and use everywhere.Jim Mussared2022-09-19
| | | | | | | This is a no-op, but sets the stage for changing the mp_obj_type_t representation. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* py/obj: Add "full" and "empty" non-variable-length mp_obj_type_t.Jim Mussared2022-09-19
| | | | | | | This will always have the maximum/minimum size of a mp_obj_type_t representation and can be used as a member in other structs. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* all: Simplify buffer protocol to just a "get buffer" callback.Jim Mussared2022-09-19
| | | | | | | | | | | | | | The buffer protocol type only has a single member, and this existing layout creates problems for the upcoming split/slot-index mp_obj_type_t layout optimisations. If we need to make the buffer protocol more sophisticated in the future either we can rely on the mp_obj_type_t optimisations to just add additional slots to mp_obj_type_t or re-visit the buffer protocol then. This change is a no-op in terms of generated code. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* extmod/modframebuf: Add ellipse drawing method.Peter Hinch2022-08-19
|
* examples/natmod/features3: Add example to test more natmod features.Damien George2022-06-10
| | | | Signed-off-by: Damien George <damien@micropython.org>
* extmod/ure: Use single function for match/search/sub.stijn2020-06-08
| | | | | Saves about 500 bytes on unix x64 and enables CPython-conform usage of passing a re object to these functions.
* extmod/modbtree: Retain reference to underlying stream so it's not GC'd.Damien George2020-05-02
| | | | | | | | | | | | | | For ports that have a system malloc which is not garbage collected (eg unix, esp32), the stream object for the DB must be retained separately to prevent it from being reclaimed by the MicroPython GC (because the berkeley-db library uses malloc to allocate the DB structure which stores the only reference to the stream). Although in some cases the user code will explicitly retain a reference to the underlying stream because it needs to call close() on it, this is not always the case, eg in cases where the DB is intended to live forever. Fixes issue #5940.
* all: Use MP_ERROR_TEXT for all error messages.Jim Mussared2020-04-05
|
* py/dynruntime.mk: Set MICROPY_ENABLE_DYNRUNTIME instead of per module.Jim Mussared2020-04-05
| | | | So this setting could be used by other source files if needed.
* examples/natmod: Add .gitignore to ignore generated example .mpy files.Damien George2020-03-03
|
* all: Reformat C and Python source code with tools/codeformat.py.Damien George2020-02-28
| | | | This is run with uncrustify 0.70.1, and black 19.10b0.
* examples/natmod: Add very simple features0 example to compute factorial.Damien George2019-12-19
|
* examples/natmod: Add urandom native module example.Damien George2019-12-13
|
* examples/natmod: Add features1 and features2 examples.Damien George2019-12-12
|
* examples/natmod: Add ure example.Damien George2019-12-12
|
* examples/natmod: Add framebuf example.Damien George2019-12-12
|
* examples/natmod: Add uzlib example.Damien George2019-12-12
|
* examples/natmod: Add uheapq example.Damien George2019-12-12
|
* examples/natmod: Add btree example.Damien George2019-12-12