Wykres commitów

15833 Commity (master)

Autor SHA1 Wiadomość Data
Damien George 35f3f0a87d py/nlr: Add "memory" to asm clobbers list in nlr_jump.
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>
2024-03-25 11:52:26 +11:00
Damien George 35b2edfc24 github/workflows: Add Biome workflow for JavaScript formatting/linting.
Enable Biome on all of webassembly port and tests.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 14:31:25 +11:00
Damien George badc0106bd tools/ci.sh: Update webassembly CI tests.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 14:31:25 +11:00
Damien George c1513a078d tests/ports/webassembly: Add webassembly JS tests.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 14:31:25 +11:00
Damien George e41b571a29 tests/run-tests.py: Support running webassembly tests via node.
This allows running tests with a .js/.mjs suffix, and also .py tests using
node and the webassembly port.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 14:31:25 +11:00
Damien George c2cf58befc webassembly/library: Fix formatting and style for Biome.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 14:31:25 +11:00
Damien George 26d6969fef webassembly: Update README.md to describe latest changes.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 14:31:25 +11:00
Damien George b9eb74e73b webassembly/variants/pyscript: Add pyscript variant.
This commit adds a pyscript variant for use in https://pyscript.net/.

The configuration is:
- No ASYNCIFY, in order to keep the WASM size down and have good
  performance.
- MICROPY_CONFIG_ROM_LEVEL_FULL_FEATURES to enable most features.
- Custom manifest that includes many of the python-stdlib libraries.
- MICROPY_GC_SPLIT_HEAP_AUTO to increase GC heap size instead of doing a
  collection when memory is exhausted.  This is needed because ASYNCIFY is
  disabled.  Instead the GC collection is run at the top-level before
  executing any Python code.
- No MICROPY_VARIANT_ENABLE_JS_HOOK because there is no asynchronous
  keyboard input to interrupt a running script.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 14:31:25 +11:00
Damien George 6ff3e356e2 webassembly: Implement replInit() and replProcessChar().
This is the JavaScript API for starting and running a REPL.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 14:31:25 +11:00
Damien George 625b17a410 webassembly: Implement runCLI() for a Node-based CLI.
This allows running MicroPython webassembly from the command line using:

    node micropython.mjs

Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 14:31:25 +11:00
Damien George 9b090603a0 webassembly: Implement runPythonAsync() for top-level async code.
With this commit, `interpreter.runPythonAsync(code)` can now be used to run
Python code that uses `await` at the top level.  That will yield up to
JavaScript and produce a thenable, which the JavaScript runtime can then
resume.  Also implemented is the ability for Python code to await on
JavaScript promises/thenables.  For example, outer JavaScript code can
await on `runPythonAsync(code)` which then runs Python code that does
`await js.fetch(url)`.  The entire chain of calls will be suspended until
the fetch completes.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 13:37:47 +11:00
Damien George 39bd0b8a0a webassembly: Add JavaScript proxying, and js and jsffi modules.
This commit improves the webassembly port by adding:

- Proxying of Python objects to JavaScript with a PyProxy type that lives
  on the JavaScript side.  PyProxy implements JavaScript Proxy traps such
  as has, get, set and ownKeys, to make Python objects have functionality
  on the JavaScript side.

- Proxying of JavaScript objects to Python with a JsProxy type that lives
  on the Python side.  JsProxy passes through calls, attributes,
  subscription and iteration from Python to JavaScript.

- A top-level API on the JavaScript side to construct a MicroPython
  interpreter instance via `loadMicroPython()`.  That function returns an
  object that can be used to execute Python code, access the Python globals
  dict, access the Emscripten filesystem, and other things.  This API is
  based on the API provided by Pyodide (https://pyodide.org/).  As part of
  this, the top-level file is changed from `micropython.js` to
  `micropython.mjs`.

- A Python `js` module which can be used to access all JavaScript-side
  symbols, for example the DOM when run within a browser.

- A Python `jsffi` module with various helper functions like
  `create_proxy()` and `to_js()`.

- A dedenting lexer which automatically dedents Python source code if every
  non-empty line in that source starts with a common whitespace prefix.
  This is very helpful when Python source code is indented within a string
  within HTML or JavaScript for formatting reasons.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 13:37:47 +11:00
Damien George 691cd3a56d webassembly: Clean up Makefile and add variant support.
This commit cleans up and generalises the Makefile, adds support for
variants (following the unix port) and adds the "standard" variant as the
default variant.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 13:37:09 +11:00
Damien George 98a8ff7a1a webassembly: Add support for enabling MICROPY_GC_SPLIT_HEAP_AUTO.
When enabled the GC will not reclaim any memory on a call to
`gc_collect()`.  Instead it will grow the heap.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 13:10:05 +11:00
Damien George ae6bcc9d23 webassembly: Use POSIX write for output and add stderr.
All output is now handled by Emscripten's stdio facility.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 13:06:39 +11:00
Damien George 8e3b701dee webassembly: Enable time localtime, gmtime, time, time_ns.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 13:05:54 +11:00
Damien George 76898cbfa1 webassembly: Implement MICROPY_PY_RANDOM_SEED_INIT_FUNC.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 13:05:54 +11:00
Damien George 8282bd93a2 webassembly: Move MP_JS_EPOCH init to library postset.
This eliminates the need for wrapper.js to run to set up the time.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 13:05:54 +11:00
Damien George ff15dfcaa8 webassembly: Include lib in sys.path.
Following other ports.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-22 13:05:54 +11:00
Damien George 2b8e88c563 py/compile: Add option to allow compiling top-level await.
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>
2024-03-22 13:05:25 +11:00
Jim Mussared acbdbcd95e esp32: Workaround IDF issue placing ISR ringbuf functions in IRAM.
This workaround makes sure that all ringbuf functions that may be called
from an ISR are placed in IRAM.  See
https://github.com/espressif/esp-idf/issues/13378

Note that this means that all esp32-og builds get non-ISR ringbuf functions
placed in flash now, whereas previously it was just the spiram variant.
This might be a good thing (e.g. free up some IRAM for native/viper).

Fixes issue #14005.

This work was funded through GitHub Sponsors.

Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2024-03-22 12:14:27 +11:00
Angus Gratton 71044a4186 py/parse: Zero out dangling parse tree pointer to fix potential GC leak.
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>
2024-03-22 10:49:20 +11:00
Damien George 9d27183bde tests/float/float_struct_e.py: Add specific test for struct 'e' type.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-20 14:13:49 +11:00
Damien George b80607ecaf unix/variants: Don't use native _Float16 type.
Using it increases code size by about 2k.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-20 14:13:49 +11:00
Damien George 0c800cefea stm32/stm32.mk: Enable _Float16 support on MCUs with hardware floats.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-20 14:13:49 +11:00
Matthias Urlichs e520fa2e0f py/binary: Support half-float 'e' format in struct pack/unpack.
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>
2024-03-20 14:13:49 +11:00
Nicko van Someren 77f08b72ca docs/library/rp2.DMA: Add documentation for rp2 DMA support.
Signed-off-by: Nicko van Someren <nicko@nicko.org>
2024-03-19 17:10:54 +11:00
Felix Dörre 1c6012b0b5 extmod/modnetwork: Implement IPv6 API to set and get NIC configuration.
This commit implements a new <AbstractNIC>.ipconfig() function for the NIC
classes that use lwIP, to set and retrieve network configuration for a NIC.
Currently this method supports:
- ipconfig("addr4"): obtain a tuple (addr, netmask) of the currently
  configured ipv4 address
- ipconfig("addr6"): obtain a list of tuples (addr, state,
  prefered_lifetime, valid_lifetime) of all currently active ipv6
  addresses; this includes static, slaac and link-local addresses
- ipconfig("has_dhcp4"): whether ipv4 dhcp has supplied an address
- ipconfig("has_autoconf6"): if there is a valid, non-static ipv6 address
- ipconfig(addr4="1.2.3.4/24"): to set the ipv4 address and netmask
- ipconfig(addr6="2a01::2"): to set a static ipv6 address; note that this
  does not configure an interface route, as this does not seem supported by
  lwIP
- ipconfig(autoconf6=True): to enable ipv6 network configuration with slaac
- ipconfig(gw4="1.2.3.1"): to set the ipv4 gateway
- ipconfig(dhcp4=True): enable ipv4 dhcp; this sets ipv4 address, netmask,
  gateway and a dns server
- ipconfig(dhcp4=False): stops dhcp, releases the ip, and clears the
  configured ipv4 address.
- ipconfig(dhcp6=True): enable stateless dhcpv6 to obtain a dns server

There is also a new global configuration function network.ipconfig() that
supports the following:
- network.ipconfig(dns="2a01::2"): set the primary dns server (can be a
  ipv4 or ipv6 address)
- network.ipconfig(prefer=6): to prefer ipv6 addresses to be returned as
  dns responses (falling back to ipv4 if the host does not have an ipv6
  address); note that this does not flush the dns cache, so if a host is
  already in the dns cache with its v4 address, subsequent lookups will
  return that address even if prefer=6 is set

This interface replaces NIC.ifconfig() completely, and ifconfig() should be
marked as deprecated and removed in a future version.

Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-03-19 16:42:10 +11:00
Damien George 52c678c6f8 stm32/boards/LEGO_HUB_NO6: Use a raw filesystem for mboot to update fw.
The C-based SPI flash driver is needed because the
`_copy_file_to_raw_filesystem()` function must copy from a filesystem (eg
FAT) to another part of flash, and the same C code must be used for both
reading (from FAT) and writing (to flash).

Signed-off-by: Damien George <damien@micropython.org>
2024-03-19 11:41:55 +11:00
Damien George 899592ac34 stm32/boards/LEGO_HUB_NO6: Move robust logic to mboot.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-19 11:40:14 +11:00
Damien George 9651046edd stm32/mboot: Add support for a raw filesystem.
This is enabled by default if MBOOT_FSLOAD is enabled, although a board
can explicitly disable it by `#define MBOOT_VFS_RAW (0)`.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-19 11:38:36 +11:00
Damien George 3c445f6636 py/emitnative: Implement viper unary ops positive, negative and invert.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-19 10:31:36 +11:00
Damien George b50efbd0e3 py/asmxtensa: Optimise asm_xtensa_mov_reg_i32_optimised() for tiny ints.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-19 10:31:36 +11:00
Damien George f52b0d0ff1 py/asm: Add ASM_NOT_REG and ASM_NEG_REG macros for unary ops.
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>
2024-03-19 10:31:36 +11:00
Damien George d92dff881c docs/library/collections: Update deque docs to describe new features.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-19 10:09:11 +11:00
Damien George c9016b4979 tests/basics: Split MicroPython-specific deque tests to separate file.
So that the MicroPython-specific behaviour can be isolated, and the CPython
compatible test don't need a .exp file.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-19 10:08:32 +11:00
Damien George bf18ddd989 tools/mpy-tool.py: Fix merging of more than 128 mpy files.
The argument to MP_BC_MAKE_FUNCTION (raw code index) was being encoded as a
byte instead of a variable unsigned int.  That meant that if there were
more than 128 merged mpy files the encoding would be invalid.

Fix that by using `mp_encode_uint(idx)` to encode the raw code index.  And
also use `Opcode` constants for the opcode values to make it easier to
understand the code.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-19 10:08:05 +11:00
Dash Peters 7dff38fdc1 py/objdeque: Expand implementation to be doubly-ended and support iter.
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>
2024-03-18 14:10:14 +11:00
Damien George cd8eea2ae9 all: Update extmod, ports, examples to build with new berkeley-db lib.
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>
2024-03-16 12:19:12 +11:00
Damien George 305707b281 lib/berkeley-db-1.xx: Update submodule URL and version.
This updates the berkeley-db-1.xx submodule URL to a repository hosted
under the micropython organisation, and makes the following changes:

- Moves the berkeley-db header files to a single directory within the
  submodule, and references all these headers with a much fuller path,
  which prevents symbol clashes (eg with esp32 and queue.h).

- Removes unused/non-working files from berkeley-db, which removes all
  symlinks in that repo (symlinks don't play well under Windows).

- Allows injecting an external configuration header into berkeley-db, so
  the configuration doesn't have to be provided by -Dxx=yy flags to the
  compiler (and possibly clashing with other symbols).

- Removes the advertising clause from the BSD 4-clause license of
  berkeley-db (see relevant commit and README.Impt.License.Change for
  details).

Signed-off-by: Damien George <damien@micropython.org>
2024-03-16 12:12:48 +11:00
Felix Dörre 01c31ea804 extmod/os_dupterm: Handle exception properly when it occurs in parallel.
When an exception is handled and the stream is closed, but while this
happens, another exception occurs or dupterm is deactivated for another
reason, the initial deactivation crashes, because its dupterm is removed.

Co-authored-by: Damien George <damien@micropython.org>

Signed-off-by: Felix Dörre <felix@dogcraft.de>
2024-03-16 10:59:03 +11:00
Damien George fb3820e3d6 nrf/boards: Enable MICROPY_HW_ENABLE_USBDEV on boards with USB CDC.
These boards were broken by 9d0d262be0.

Signed-off-by: Damien George <damien@micropython.org>
2024-03-16 00:40:39 +11:00
Damien George df2ff0c355 LICENSE: Add libmetal and open-amp to 3rd-party license list.
Signed-off-by: Damien George <damien@micropython.org>
2024-03-15 18:11:28 +11:00
iabdalkader 486ca3a688 tools/ci.sh: Add Arduino GIGA to stm32 CI build.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-03-15 18:11:28 +11:00
iabdalkader e5ca06a06f docs/library/openamp: Document the new openamp module.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-03-15 18:11:28 +11:00
iabdalkader 864e4596bf stm32/boards/ARDUINO_PORTENTA_H7: Enable OpenAMP.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-03-15 18:11:28 +11:00
iabdalkader fc97343639 stm32/boards/ARDUINO_NICLA_VISION: Enable OpenAMP.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-03-15 18:11:28 +11:00
iabdalkader c859978da3 stm32/boards/ARDUINO_GIGA: Enable OpenAMP.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-03-15 18:11:28 +11:00
iabdalkader 09eb4caccb stm32: Implement port backend for OpenAMP's remoteproc.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-03-15 18:11:28 +11:00
iabdalkader 13297d8c3a stm32: Implement port backend for libmetal.
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2024-03-15 18:11:28 +11:00