diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 90cf8954d3..eb20569030 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -145,6 +145,10 @@ jobs: run: | git describe --dirty --tags echo >>$GITHUB_ENV CP_VERSION=$(git describe --dirty --tags) + - name: Set up Python 3.8 + uses: actions/setup-python@v1 + with: + python-version: 3.8 - name: Install dependencies run: | brew install gettext diff --git a/.gitmodules b/.gitmodules index b261d8f408..e26d3dd76b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -4,17 +4,13 @@ [submodule "lib/axtls"] path = lib/axtls - url = https://github.com/pfalcon/axtls - branch = micropython + url = https://github.com/micropython/axtls.git [submodule "lib/libffi"] path = lib/libffi url = https://github.com/atgreen/libffi [submodule "lib/berkeley-db-1.xx"] path = lib/berkeley-db-1.xx url = https://github.com/pfalcon/berkeley-db-1.xx -[submodule "lib/uzlib"] - path = lib/uzlib - url = https://github.com/pfalcon/uzlib [submodule "tools/uf2"] path = tools/uf2 url = https://github.com/Microsoft/uf2.git diff --git a/LICENSE b/LICENSE index 3193eb8cec..5b5c37f7d1 100644 --- a/LICENSE +++ b/LICENSE @@ -19,3 +19,67 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +-------------------------------------------------------------------------------- + +Unless specified otherwise (see below), the above license and copyright applies +to all files in this repository. + +Individual files may include additional copyright holders. + +The various ports of MicroPython may include third-party software that is +licensed under different terms. These licenses are summarised in the tree +below, please refer to these files and directories for further license and +copyright information. Note that (L)GPL-licensed code listed below is only +used during the build process and is not part of the compiled source code. + +/ (MIT) + /drivers + /cc3000 (BSD-3-clause) + /cc3100 (BSD-3-clause) + /wiznet5k (BSD-3-clause) + /lib + /asf4 (Apache-2.0) + /axtls (BSD-3-clause) + /config + /scripts + /config (GPL-2.0-or-later) + /Rules.mak (GPL-2.0) + /berkeley-db-1xx (BSD-4-clause) + /btstack (See btstack/LICENSE) + /cmsis (BSD-3-clause) + /crypto-algorithms (NONE) + /libhydrogen (ISC) + /littlefs (BSD-3-clause) + /lwip (BSD-3-clause) + /mynewt-nimble (Apache-2.0) + /nrfx (BSD-3-clause) + /nxp_driver (BSD-3-Clause) + /oofatfs (BSD-1-clause) + /pico-sdk (BSD-3-clause) + /re15 (BSD-3-clause) + /stm32lib (BSD-3-clause) + /tinytest (BSD-3-clause) + /tinyusb (MIT) + /uzlib (Zlib) + /logo (uses OFL-1.1) + /ports + /cc3200 + /hal (BSD-3-clause) + /simplelink (BSD-3-clause) + /FreeRTOS (GPL-2.0 with FreeRTOS exception) + /stm32 + /usbd*.c (MCD-ST Liberty SW License Agreement V2) + /stm32_it.* (MIT + BSD-3-clause) + /system_stm32*.c (MIT + BSD-3-clause) + /boards + /startup_stm32*.s (BSD-3-clause) + /*/stm32*.h (BSD-3-clause) + /usbdev (MCD-ST Liberty SW License Agreement V2) + /usbhost (MCD-ST Liberty SW License Agreement V2) + /teensy + /core (PJRC.COM) + /zephyr + /src (Apache-2.0) + /tools + /dfu.py (LGPL-3.0-only) diff --git a/conf.py b/conf.py index 0dac441b0d..80b031ce05 100644 --- a/conf.py +++ b/conf.py @@ -209,6 +209,7 @@ exclude_patterns = ["**/build*", "ports/stm/ref", "ports/unix", "py", + "shared/*", "shared-bindings/util.*", "shared-module", "supervisor", diff --git a/devices/ble_hci/common-hal/_bleio/CharacteristicBuffer.c b/devices/ble_hci/common-hal/_bleio/CharacteristicBuffer.c index 8be1abef1f..bb6b8788b6 100644 --- a/devices/ble_hci/common-hal/_bleio/CharacteristicBuffer.c +++ b/devices/ble_hci/common-hal/_bleio/CharacteristicBuffer.c @@ -27,7 +27,7 @@ #include #include -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/runtime.h" #include "py/stream.h" diff --git a/devices/ble_hci/common-hal/_bleio/Connection.c b/devices/ble_hci/common-hal/_bleio/Connection.c index fd041ca002..9531231506 100644 --- a/devices/ble_hci/common-hal/_bleio/Connection.c +++ b/devices/ble_hci/common-hal/_bleio/Connection.c @@ -32,7 +32,7 @@ #include #include -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/gc.h" #include "py/objlist.h" #include "py/objstr.h" diff --git a/devices/ble_hci/common-hal/_bleio/PacketBuffer.c b/devices/ble_hci/common-hal/_bleio/PacketBuffer.c index 2c1989b4e0..7380d7ed4f 100644 --- a/devices/ble_hci/common-hal/_bleio/PacketBuffer.c +++ b/devices/ble_hci/common-hal/_bleio/PacketBuffer.c @@ -27,7 +27,7 @@ #include #include -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/runtime.h" #include "py/stream.h" diff --git a/docs/README.md b/docs/README.md index 19c81a2fa3..1ad4ca802e 100644 --- a/docs/README.md +++ b/docs/README.md @@ -13,12 +13,9 @@ Building the documentation locally If you're making changes to the documentation, you should build the documentation locally so that you can preview your changes. -Install Sphinx, recommonmark, and optionally (for the RTD-styling), sphinx_rtd_theme, -preferably in a virtualenv: +Install the necessary packages, preferably in a virtualenv, in `circuitpython/`: - pip install sphinx - pip install recommonmark - pip install sphinx_rtd_theme + pip install -r requirements-doc.txt In `circuitpython/`, build the docs: diff --git a/docs/library/uasyncio.rst b/docs/library/asyncio.rst similarity index 97% rename from docs/library/uasyncio.rst rename to docs/library/asyncio.rst index 10170fee85..87417f55e2 100644 --- a/docs/library/uasyncio.rst +++ b/docs/library/asyncio.rst @@ -222,6 +222,14 @@ TCP stream connections This is a coroutine, and a MicroPython extension. +.. method:: Stream.readexactly(n) + + Read exactly *n* bytes and return them as a bytes object. + + Raises an ``EOFError`` exception if the stream ends before reading *n* bytes. + + This is a coroutine. + .. method:: Stream.readline() Read a line and return it. diff --git a/docs/library/btree.rst b/docs/library/btree.rst index 66a3c0e34b..e160ebe13d 100644 --- a/docs/library/btree.rst +++ b/docs/library/btree.rst @@ -24,7 +24,7 @@ Example:: # First, we need to open a stream which holds a database # This is usually a file, but can be in-memory database - # using uio.BytesIO, a raw flash partition, etc. + # using io.BytesIO, a raw flash partition, etc. # Oftentimes, you want to create a database file if it doesn't # exist and open if it exists. Idiom below takes care of this. # DO NOT open database with "a+b" access mode. diff --git a/docs/library/builtins.rst b/docs/library/builtins.rst index c7f983010e..8532dc2531 100644 --- a/docs/library/builtins.rst +++ b/docs/library/builtins.rst @@ -1,5 +1,5 @@ -Builtin functions and exceptions -================================ +:mod:`builtins` -- builtin functions and exceptions +=================================================== All builtin functions and exceptions are described here. They are also available via ``builtins`` module. diff --git a/docs/library/uctypes.rst b/docs/library/ctypes.rst similarity index 99% rename from docs/library/uctypes.rst rename to docs/library/ctypes.rst index 9e15c4c178..803ddacdce 100644 --- a/docs/library/uctypes.rst +++ b/docs/library/ctypes.rst @@ -1,8 +1,6 @@ :mod:`uctypes` -- access binary data in a structured way ======================================================== -.. include:: ../templates/unsupported_in_circuitpython.inc - .. module:: uctypes :synopsis: access binary data in a structured way diff --git a/docs/library/framebuf.rst b/docs/library/framebuf.rst index a9cbc2fc47..42b5c9e732 100644 --- a/docs/library/framebuf.rst +++ b/docs/library/framebuf.rst @@ -105,16 +105,23 @@ Other methods Shift the contents of the FrameBuffer by the given vector. This may leave a footprint of the previous colors in the FrameBuffer. -.. method:: FrameBuffer.blit(fbuf, x, y[, key]) +.. method:: FrameBuffer.blit(fbuf, x, y, key=-1, palette=None) Draw another FrameBuffer on top of the current one at the given coordinates. If *key* is specified then it should be a color integer and the corresponding color will be considered transparent: all pixels with that color value will not be drawn. - This method works between FrameBuffer instances utilising different formats, - but the resulting colors may be unexpected due to the mismatch in color - formats. + The *palette* argument enables blitting between FrameBuffers with differing + formats. Typical usage is to render a monochrome or grayscale glyph/icon to + a color display. The *palette* is a FrameBuffer instance whose format is + that of the current FrameBuffer. The *palette* height is one pixel and its + pixel width is the number of colors in the source FrameBuffer. The *palette* + for an N-bit source needs 2**N pixels; the *palette* for a monochrome source + would have 2 pixels representing background and foreground colors. The + application assigns a color to each pixel in the *palette*. The color of the + current pixel will be that of that *palette* pixel whose x position is the + color of the corresponding source pixel. Constants --------- diff --git a/docs/library/uheapq.rst b/docs/library/heapq.rst similarity index 89% rename from docs/library/uheapq.rst rename to docs/library/heapq.rst index 6ee79fcc19..7269422847 100644 --- a/docs/library/uheapq.rst +++ b/docs/library/heapq.rst @@ -1,9 +1,9 @@ -:mod:`uheapq` -- heap queue algorithm -===================================== +:mod:`heapq` -- heap queue algorithm +==================================== .. include:: ../templates/unsupported_in_circuitpython.inc -.. module:: uheapq +.. module:: heapq :synopsis: heap queue algorithm |see_cpython_module| :mod:`cpython:heapq`. diff --git a/docs/library/index.rst b/docs/library/index.rst index 9a7f9afd84..5d8dd3118f 100644 --- a/docs/library/index.rst +++ b/docs/library/index.rst @@ -18,15 +18,14 @@ These libraries are not enabled on CircuitPython builds with limited flash memory, usually on non-Express builds: ``binascii``, ``errno``, ``json``, ``re``. -These libraries are not currently enabled in any CircuitPython build, but may be in the future, -with the ``u`` prefix dropped: -``uctypes``, ``uhashlib``, ``uzlib``. +These libraries are not currently enabled in any CircuitPython build, but may be in the future: +``ctypes``, ``hashlib``, ``zlib``. .. toctree:: :maxdepth: 1 builtins.rst - uheapq.rst + heapq.rst array.rst binascii.rst collections.rst @@ -37,10 +36,10 @@ with the ``u`` prefix dropped: json.rst re.rst sys.rst - uasyncio.rst - uctypes.rst - uselect.rst - uzlib.rst + asyncio.rst + ctypes.rst + select.rst + zlib.rst Omitted functions in the ``string`` library ------------------------------------------- diff --git a/docs/library/uselect.rst b/docs/library/select.rst similarity index 84% rename from docs/library/uselect.rst rename to docs/library/select.rst index cb7818dc06..84792bc53a 100644 --- a/docs/library/uselect.rst +++ b/docs/library/select.rst @@ -1,9 +1,9 @@ -:mod:`uselect` -- wait for events on a set of streams -======================================================================== +:mod:`select` -- wait for events on a set of streams +==================================================== .. include:: ../templates/unsupported_in_circuitpython.inc -.. module:: uselect +.. module:: select :synopsis: wait for events on a set of streams |see_cpython_module| :mod:`cpython:select`. @@ -37,15 +37,15 @@ Methods Register ``stream`` *obj* for polling. *eventmask* is logical OR of: - * ``uselect.POLLIN`` - data available for reading - * ``uselect.POLLOUT`` - more data can be written + * ``select.POLLIN`` - data available for reading + * ``select.POLLOUT`` - more data can be written - Note that flags like ``uselect.POLLHUP`` and ``uselect.POLLERR`` are + Note that flags like ``select.POLLHUP`` and ``select.POLLERR`` are *not* valid as input eventmask (these are unsolicited events which will be returned from `poll()` regardless of whether they are asked for). This semantics is per POSIX. - *eventmask* defaults to ``uselect.POLLIN | uselect.POLLOUT``. + *eventmask* defaults to ``select.POLLIN | select.POLLOUT``. It is OK to call this function multiple times for the same *obj*. Successive calls will update *obj*'s eventmask to the value of @@ -69,8 +69,8 @@ Methods Returns list of (``obj``, ``event``, ...) tuples. There may be other elements in tuple, depending on a platform and version, so don't assume that its size is 2. The ``event`` element specifies which events happened with a stream and - is a combination of ``uselect.POLL*`` constants described above. Note that - flags ``uselect.POLLHUP`` and ``uselect.POLLERR`` can be returned at any time + is a combination of ``select.POLL*`` constants described above. Note that + flags ``select.POLLHUP`` and ``select.POLLERR`` can be returned at any time (even if were not asked for), and must be acted on accordingly (the corresponding stream unregistered from poll and likely closed), because otherwise all further invocations of `poll()` may return immediately with diff --git a/docs/library/uzlib.rst b/docs/library/zlib.rst similarity index 94% rename from docs/library/uzlib.rst rename to docs/library/zlib.rst index 9a6c471f76..8f69f4b7c8 100644 --- a/docs/library/uzlib.rst +++ b/docs/library/zlib.rst @@ -1,9 +1,9 @@ -:mod:`uzlib` -- zlib decompression -================================== +:mod:`zlib` -- zlib decompression +================================= .. include:: ../templates/unsupported_in_circuitpython.inc -.. module:: uzlib +.. module:: zlib :synopsis: zlib decompression |see_cpython_module| :mod:`cpython:zlib`. diff --git a/examples/natmod/btree/btree_c.c b/examples/natmod/btree/btree_c.c index a58a38e11e..5e8a34ac40 100644 --- a/examples/natmod/btree/btree_c.c +++ b/examples/natmod/btree/btree_c.c @@ -18,7 +18,7 @@ void *memmove(void *dest, const void *src, size_t n) { } void *malloc(size_t n) { - void *ptr = m_malloc(n, false); + void *ptr = m_malloc(n); return ptr; } void *realloc(void *ptr, size_t n) { @@ -26,7 +26,7 @@ void *realloc(void *ptr, size_t n) { return NULL; } void *calloc(size_t n, size_t m) { - void *ptr = m_malloc(n * m, false); + void *ptr = m_malloc(n * m); // memory already cleared by conservative GC return ptr; } diff --git a/examples/natmod/features2/main.c b/examples/natmod/features2/main.c index 60c48b0f72..1a39700dc4 100644 --- a/examples/natmod/features2/main.c +++ b/examples/natmod/features2/main.c @@ -46,7 +46,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(add_d_obj, add_d); // to use but has access to the globals dict of the module via self->globals. STATIC mp_obj_t productf(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { // Check number of arguments is valid - mp_arg_check_num_mp(n_args, n_kw, 1, 1, false); + mp_arg_check_num(n_args, n_kw, 1, 1, false); // Extract buffer pointer and verify typecode mp_buffer_info_t bufinfo; diff --git a/examples/usercmodule/cexample/examplemodule.c b/examples/usercmodule/cexample/examplemodule.c index f608823c9e..49ebc7aaaf 100644 --- a/examples/usercmodule/cexample/examplemodule.c +++ b/examples/usercmodule/cexample/examplemodule.c @@ -31,4 +31,7 @@ const mp_obj_module_t example_user_cmodule = { }; // Register the module to make it available in Python. -MP_REGISTER_MODULE(MP_QSTR_cexample, example_user_cmodule, MODULE_CEXAMPLE_ENABLED); +// Note: the "1" in the third argument means this module is always enabled. +// This "1" can be optionally replaced with a macro like MODULE_CEXAMPLE_ENABLED +// which can then be used to conditionally enable this module. +MP_REGISTER_MODULE(MP_QSTR_cexample, example_user_cmodule, 1); diff --git a/examples/usercmodule/cexample/micropython.cmake b/examples/usercmodule/cexample/micropython.cmake new file mode 100644 index 0000000000..ba076a16b2 --- /dev/null +++ b/examples/usercmodule/cexample/micropython.cmake @@ -0,0 +1,15 @@ +# Create an INTERFACE library for our C module. +add_library(usermod_cexample INTERFACE) + +# Add our source files to the lib +target_sources(usermod_cexample INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/examplemodule.c +) + +# Add the current directory as an include directory. +target_include_directories(usermod_cexample INTERFACE + ${CMAKE_CURRENT_LIST_DIR} +) + +# Link our INTERFACE library to the usermod target. +target_link_libraries(usermod INTERFACE usermod_cexample) diff --git a/examples/usercmodule/cppexample/examplemodule.c b/examples/usercmodule/cppexample/examplemodule.c index ceb588bef6..dfb7856837 100644 --- a/examples/usercmodule/cppexample/examplemodule.c +++ b/examples/usercmodule/cppexample/examplemodule.c @@ -22,4 +22,7 @@ const mp_obj_module_t cppexample_user_cmodule = { }; // Register the module to make it available in Python. -MP_REGISTER_MODULE(MP_QSTR_cppexample, cppexample_user_cmodule, MODULE_CPPEXAMPLE_ENABLED); +// Note: the "1" in the third argument means this module is always enabled. +// This "1" can be optionally replaced with a macro like MODULE_CPPEXAMPLE_ENABLED +// which can then be used to conditionally enable this module. +MP_REGISTER_MODULE(MP_QSTR_cppexample, cppexample_user_cmodule, 1); diff --git a/examples/usercmodule/cppexample/micropython.cmake b/examples/usercmodule/cppexample/micropython.cmake new file mode 100644 index 0000000000..6da972c94e --- /dev/null +++ b/examples/usercmodule/cppexample/micropython.cmake @@ -0,0 +1,16 @@ +# Create an INTERFACE library for our CPP module. +add_library(usermod_cppexample INTERFACE) + +# Add our source files to the library. +target_sources(usermod_cppexample INTERFACE + ${CMAKE_CURRENT_LIST_DIR}/example.cpp + ${CMAKE_CURRENT_LIST_DIR}/examplemodule.c +) + +# Add the current directory as an include directory. +target_include_directories(usermod_cppexample INTERFACE + ${CMAKE_CURRENT_LIST_DIR} +) + +# Link our INTERFACE library to the usermod target. +target_link_libraries(usermod INTERFACE usermod_cppexample) diff --git a/examples/usercmodule/micropython.cmake b/examples/usercmodule/micropython.cmake new file mode 100644 index 0000000000..b9802401fa --- /dev/null +++ b/examples/usercmodule/micropython.cmake @@ -0,0 +1,10 @@ +# This top-level micropython.cmake is responsible for listing +# the individual modules we want to include. +# Paths are absolute, and ${CMAKE_CURRENT_LIST_DIR} can be +# used to prefix subdirectories. + +# Add the C example. +include(${CMAKE_CURRENT_LIST_DIR}/cexample/micropython.cmake) + +# Add the CPP example. +include(${CMAKE_CURRENT_LIST_DIR}/cppexample/micropython.cmake) diff --git a/extmod/axtls-include/axtls_os_port.h b/extmod/axtls-include/axtls_os_port.h new file mode 100644 index 0000000000..ef2683acfc --- /dev/null +++ b/extmod/axtls-include/axtls_os_port.h @@ -0,0 +1,55 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Damien P. George + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef AXTLS_OS_PORT_H +#define AXTLS_OS_PORT_H + +#include +#include "py/stream.h" +#include "lib/crypto-algorithms/sha256.h" + +#define SSL_CTX_MUTEX_INIT(mutex) +#define SSL_CTX_MUTEX_DESTROY(mutex) +#define SSL_CTX_LOCK(mutex) +#define SSL_CTX_UNLOCK(mutex) + +#define SOCKET_READ(s, buf, size) mp_stream_posix_read((void *)s, buf, size) +#define SOCKET_WRITE(s, buf, size) mp_stream_posix_write((void *)s, buf, size) +#define SOCKET_CLOSE(A) UNUSED +#define SOCKET_ERRNO() errno + +#define SHA256_CTX CRYAL_SHA256_CTX +#define SHA256_Init(ctx) sha256_init(ctx) +#define SHA256_Update(ctx, buf, size) sha256_update(ctx, buf, size) +#define SHA256_Final(hash, ctx) sha256_final(ctx, hash) + +#define TTY_FLUSH() + +#ifdef WDEV_HWRNG +// For esp8266 port: use the hardware RNG. +#define PLATFORM_RNG_U8() (*WDEV_HWRNG) +#endif + +#endif // AXTLS_OS_PORT_H diff --git a/extmod/extmod.cmake b/extmod/extmod.cmake index a54047519d..c6b45b0d3e 100644 --- a/extmod/extmod.cmake +++ b/extmod/extmod.cmake @@ -4,8 +4,9 @@ set(MICROPY_EXTMOD_DIR "${MICROPY_DIR}/extmod") set(MICROPY_OOFATFS_DIR "${MICROPY_DIR}/lib/oofatfs") set(MICROPY_SOURCE_EXTMOD - ${MICROPY_DIR}/lib/embed/abort_.c - ${MICROPY_DIR}/lib/utils/printf.c + ${MICROPY_DIR}/shared/libc/abort_.c + ${MICROPY_DIR}/shared/libc/printf.c + ${MICROPY_EXTMOD_DIR}/machine_bitstream.c ${MICROPY_EXTMOD_DIR}/machine_i2c.c ${MICROPY_EXTMOD_DIR}/machine_mem.c ${MICROPY_EXTMOD_DIR}/machine_pulse.c diff --git a/extmod/extmod.mk b/extmod/extmod.mk index 5e12ee75d4..4cdeaedaf9 100644 --- a/extmod/extmod.mk +++ b/extmod/extmod.mk @@ -157,7 +157,7 @@ LWIP_DIR = lib/lwip/src INC += -I$(TOP)/$(LWIP_DIR)/include CFLAGS_MOD += -DMICROPY_PY_LWIP=1 $(BUILD)/$(LWIP_DIR)/core/ipv4/dhcp.o: CFLAGS_MOD += -Wno-address -SRC_MOD += extmod/modlwip.c lib/netutils/netutils.c +SRC_MOD += extmod/modlwip.c shared/netutils/netutils.c SRC_MOD += $(addprefix $(LWIP_DIR)/,\ apps/mdns/mdns.c \ core/def.c \ diff --git a/extmod/modframebuf.c b/extmod/modframebuf.c index 6168e86843..fa07b69522 100644 --- a/extmod/modframebuf.c +++ b/extmod/modframebuf.c @@ -244,8 +244,8 @@ STATIC void fill_rect(const mp_obj_framebuf_t *fb, int x, int y, int w, int h, u formats[fb->format].fill_rect(fb, x, y, xend - x, yend - y, col); } -STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 4, 5, false); +STATIC mp_obj_t framebuf_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 4, 5, false); mp_obj_framebuf_t *o = m_new_obj(mp_obj_framebuf_t); o->base.type = type; @@ -481,6 +481,10 @@ STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) { if (n_args > 4) { key = mp_obj_get_int(args[4]); } + mp_obj_framebuf_t *palette = NULL; + if (n_args > 5 && args[5] != mp_const_none) { + palette = MP_OBJ_TO_PTR(mp_obj_cast_to_native_base(args[5], MP_OBJ_FROM_PTR(&mp_type_framebuf))); + } if ( (x >= self->width) || @@ -504,6 +508,9 @@ STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) { int cx1 = x1; for (int cx0 = x0; cx0 < x0end; ++cx0) { uint32_t col = getpixel(source, cx1, y1); + if (palette) { + col = getpixel(palette, col, 0); + } if (col != (uint32_t)key) { setpixel(self, cx0, y0, col); } @@ -513,7 +520,7 @@ STATIC mp_obj_t framebuf_blit(size_t n_args, const mp_obj_t *args) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_blit_obj, 4, 5, framebuf_blit); +STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(framebuf_blit_obj, 4, 6, framebuf_blit); STATIC mp_obj_t framebuf_scroll(mp_obj_t self_in, mp_obj_t xstep_in, mp_obj_t ystep_in) { mp_obj_framebuf_t *self = native_framebuf(self_in); diff --git a/extmod/moduasyncio.c b/extmod/moduasyncio.c index ff1558fae6..1f5cc618d0 100644 --- a/extmod/moduasyncio.c +++ b/extmod/moduasyncio.c @@ -31,6 +31,9 @@ #if MICROPY_PY_UASYNCIO +// Used when task cannot be guaranteed to be non-NULL. +#define TASK_PAIRHEAP(task) ((task) ? &(task)->pairheap : NULL) + #define TASK_STATE_RUNNING_NOT_WAITED_ON (mp_const_true) #define TASK_STATE_DONE_NOT_WAITED_ON (mp_const_none) #define TASK_STATE_DONE_WAS_WAITED_ON (mp_const_false) @@ -55,7 +58,7 @@ typedef struct _mp_obj_task_queue_t { STATIC const mp_obj_type_t task_queue_type; STATIC const mp_obj_type_t task_type; -STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args); +STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); /******************************************************************************/ // Ticks for task ordering in pairing heap @@ -81,9 +84,9 @@ STATIC int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) { /******************************************************************************/ // TaskQueue class -STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)args; - mp_arg_check_num(n_args, kw_args, 0, 0, false); + mp_arg_check_num(n_args, n_kw, 0, 0, false); mp_obj_task_queue_t *self = m_new_obj(mp_obj_task_queue_t); self->base.type = type; self->heap = (mp_obj_task_t *)mp_pairheap_new(task_lt); @@ -110,7 +113,7 @@ STATIC mp_obj_t task_queue_push_sorted(size_t n_args, const mp_obj_t *args) { assert(mp_obj_is_small_int(args[2])); task->ph_key = args[2]; } - self->heap = (mp_obj_task_t *)mp_pairheap_push(task_lt, &self->heap->pairheap, &task->pairheap); + self->heap = (mp_obj_task_t *)mp_pairheap_push(task_lt, TASK_PAIRHEAP(self->heap), TASK_PAIRHEAP(task)); return mp_const_none; } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(task_queue_push_sorted_obj, 2, 3, task_queue_push_sorted); @@ -156,8 +159,8 @@ STATIC const mp_obj_type_t task_queue_type = { // This is the core uasyncio context with cur_task, _task_queue and CancelledError. STATIC mp_obj_t uasyncio_context = MP_OBJ_NULL; -STATIC mp_obj_t task_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, 2, false); +STATIC mp_obj_t task_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 1, 2, false); mp_obj_task_t *self = m_new_obj(mp_obj_task_t); self->pairheap.base.type = type; mp_pairheap_init_node(task_lt, &self->pairheap); diff --git a/extmod/modubinascii.c b/extmod/modubinascii.c index c21ae8bc80..b11b8bf8a8 100644 --- a/extmod/modubinascii.c +++ b/extmod/modubinascii.c @@ -205,7 +205,7 @@ STATIC mp_obj_t mod_binascii_b2a_base64(mp_obj_t data) { STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_binascii_b2a_base64_obj, mod_binascii_b2a_base64); #if MICROPY_PY_UBINASCII_CRC32 -#include "../../lib/uzlib/src/tinf.h" +#include "lib/uzlib/tinf.h" STATIC mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo; diff --git a/extmod/moductypes.c b/extmod/moductypes.c index 3f7d543a72..265cbd6d5d 100644 --- a/extmod/moductypes.c +++ b/extmod/moductypes.c @@ -74,8 +74,8 @@ STATIC NORETURN void syntax_error(void) { mp_raise_TypeError(MP_ERROR_TEXT("syntax error in uctypes descriptor")); } -STATIC mp_obj_t uctypes_struct_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 2, 3, false); +STATIC mp_obj_t uctypes_struct_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 2, 3, false); mp_obj_uctypes_struct_t *o = m_new_obj(mp_obj_uctypes_struct_t); o->base.type = type; o->addr = (void *)(uintptr_t)mp_obj_int_get_truncated(args[0]); diff --git a/extmod/moduhashlib.c b/extmod/moduhashlib.c index 0dfd2c790a..741f43c74c 100644 --- a/extmod/moduhashlib.c +++ b/extmod/moduhashlib.c @@ -21,7 +21,7 @@ #if MICROPY_SSL_MBEDTLS #include "mbedtls/sha256.h" #else -#include "crypto-algorithms/sha256.h" +#include "lib/crypto-algorithms/sha256.h" #endif #endif @@ -106,11 +106,10 @@ static void check_not_unicode(const mp_obj_t arg) { } #if MICROPY_PY_UHASHLIB_SHA256 -#include "crypto-algorithms/sha256.c" -#endif +#include "lib/crypto-algorithms/sha256.c" -STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 0, 1, false); +STATIC mp_obj_t uhashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_hash_t *o = m_new_obj_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX)); o->base.type = type; o->final = false; @@ -160,6 +159,8 @@ STATIC const mp_obj_type_t uhashlib_sha256_type = { }; #endif +#endif + #if MICROPY_PY_UHASHLIB_SHA1 STATIC mp_obj_t uhashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg); diff --git a/extmod/modujson.c b/extmod/modujson.c index 57d72b3bea..9a4db7c273 100644 --- a/extmod/modujson.c +++ b/extmod/modujson.c @@ -17,6 +17,62 @@ #if MICROPY_PY_UJSON +#if MICROPY_PY_UJSON_SEPARATORS + +enum { + DUMP_MODE_TO_STRING = 1, + DUMP_MODE_TO_STREAM = 2, +}; + +STATIC mp_obj_t mod_ujson_dump_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, unsigned int mode) { + enum { ARG_separators }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_separators, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, + }; + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - mode, pos_args + mode, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_print_ext_t print_ext; + + if (args[ARG_separators].u_obj == mp_const_none) { + print_ext.item_separator = ", "; + print_ext.key_separator = ": "; + } else { + mp_obj_t *items; + mp_obj_get_array_fixed_n(args[ARG_separators].u_obj, 2, &items); + print_ext.item_separator = mp_obj_str_get_str(items[0]); + print_ext.key_separator = mp_obj_str_get_str(items[1]); + } + + if (mode == DUMP_MODE_TO_STRING) { + // dumps(obj) + vstr_t vstr; + vstr_init_print(&vstr, 8, &print_ext.base); + mp_obj_print_helper(&print_ext.base, pos_args[0], PRINT_JSON); + return mp_obj_new_str_from_vstr(&mp_type_str, &vstr); + } else { + // dump(obj, stream) + print_ext.base.data = MP_OBJ_TO_PTR(pos_args[1]); + print_ext.base.print_strn = mp_stream_write_adaptor; + mp_get_stream_raise(pos_args[1], MP_STREAM_OP_WRITE); + mp_obj_print_helper(&print_ext.base, pos_args[0], PRINT_JSON); + return mp_const_none; + } +} + +STATIC mp_obj_t mod_ujson_dump(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + return mod_ujson_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STREAM); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ujson_dump_obj, 2, mod_ujson_dump); + +STATIC mp_obj_t mod_ujson_dumps(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + return mod_ujson_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STRING); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_ujson_dumps_obj, 1, mod_ujson_dumps); + +#else + STATIC mp_obj_t mod_ujson_dump(mp_obj_t obj, mp_obj_t stream) { mp_get_stream_raise(stream, MP_STREAM_OP_WRITE); mp_print_t print = {MP_OBJ_TO_PTR(stream), mp_stream_write_adaptor}; @@ -33,6 +89,7 @@ STATIC mp_obj_t mod_ujson_dumps(mp_obj_t obj) { return mp_obj_new_str_from_vstr(&mp_type_str, &vstr); } STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_ujson_dumps_obj, mod_ujson_dumps); +#endif #define JSON_DEBUG(...) (void)0 // #define JSON_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__) diff --git a/extmod/modure.c b/extmod/modure.c index 18a28d3628..cca74a7267 100644 --- a/extmod/modure.c +++ b/extmod/modure.c @@ -16,7 +16,7 @@ #define re1_5_stack_chk() MP_STACK_CHECK() -#include "re1.5/re1.5.h" +#include "lib/re1.5/re1.5.h" #if MICROPY_PY_URE_DEBUG #define FLAG_DEBUG 0x1000 @@ -49,7 +49,7 @@ STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) { mp_obj_match_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t no = mp_obj_get_int(no_in); if (no < 0 || no >= self->num_matches) { - mp_raise_arg1(&mp_type_IndexError, no_in); + mp_raise_type_arg(&mp_type_IndexError, no_in); } const char *start = self->caps[no * 2]; @@ -88,7 +88,7 @@ STATIC void match_span_helper(size_t n_args, const mp_obj_t *args, mp_obj_t span if (n_args == 2) { no = mp_obj_get_int(args[1]); if (no < 0 || no >= self->num_matches) { - mp_raise_arg1(&mp_type_IndexError, args[1]); + mp_raise_type_arg(&mp_type_IndexError, args[1]); } } @@ -345,7 +345,7 @@ STATIC mp_obj_t re_sub_helper(size_t n_args, const mp_obj_t *args) { } if (match_no >= (unsigned int)match->num_matches) { - mp_raise_arg1(&mp_type_IndexError, MP_OBJ_NEW_SMALL_INT(match_no)); + mp_raise_type_arg(&mp_type_IndexError, MP_OBJ_NEW_SMALL_INT(match_no)); } const char *start_match = match->caps[match_no * 2]; @@ -477,11 +477,11 @@ MP_REGISTER_MODULE(MP_QSTR_re, mp_module_ure, MICROPY_PY_URE); // only if module is enabled by config setting. #define re1_5_fatal(x) assert(!x) -#include "re1.5/compilecode.c" +#include "lib/re1.5/compilecode.c" #if MICROPY_PY_URE_DEBUG -#include "re1.5/dumpcode.c" +#include "lib/re1.5/dumpcode.c" #endif -#include "re1.5/recursiveloop.c" -#include "re1.5/charclass.c" +#include "lib/re1.5/recursiveloop.c" +#include "lib/re1.5/charclass.c" #endif // MICROPY_PY_URE diff --git a/extmod/moduselect.c b/extmod/moduselect.c index 3c66d69e32..1b9617fca9 100644 --- a/extmod/moduselect.c +++ b/extmod/moduselect.c @@ -87,6 +87,7 @@ STATIC mp_uint_t poll_map_poll(mp_map_t *poll_map, size_t *rwx_num) { return n_ready; } +#if MICROPY_PY_USELECT_SELECT // select(rlist, wlist, xlist[, timeout]) STATIC mp_obj_t select_select(size_t n_args, const mp_obj_t *args) { // get array data from tuple/list arguments @@ -153,6 +154,7 @@ STATIC mp_obj_t select_select(size_t n_args, const mp_obj_t *args) { } } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_select_select_obj, 3, 4, select_select); +#endif // MICROPY_PY_USELECT_SELECT typedef struct _mp_obj_poll_t { mp_obj_base_t base; @@ -335,7 +337,9 @@ MP_DEFINE_CONST_FUN_OBJ_0(mp_select_poll_obj, select_poll); STATIC const mp_rom_map_elem_t mp_module_select_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uselect) }, + #if MICROPY_PY_USELECT_SELECT { MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mp_select_select_obj) }, + #endif { MP_ROM_QSTR(MP_QSTR_poll), MP_ROM_PTR(&mp_select_poll_obj) }, { MP_ROM_QSTR(MP_QSTR_POLLIN), MP_ROM_INT(MP_STREAM_POLL_RD) }, { MP_ROM_QSTR(MP_QSTR_POLLOUT), MP_ROM_INT(MP_STREAM_POLL_WR) }, diff --git a/extmod/modutimeq.c b/extmod/modutimeq.c index b6b9fa44b5..495675ad1d 100644 --- a/extmod/modutimeq.c +++ b/extmod/modutimeq.c @@ -55,8 +55,8 @@ STATIC bool time_less_than(struct qentry *item, struct qentry *parent) { return res && res < (MODULO / 2); } -STATIC mp_obj_t utimeq_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, 1, false); +STATIC mp_obj_t utimeq_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 1, 1, false); mp_uint_t alloc = mp_obj_get_int(args[0]); mp_obj_utimeq_t *o = m_new_obj_var(mp_obj_utimeq_t, struct qentry, alloc); o->base.type = type; diff --git a/extmod/moduzlib.c b/extmod/moduzlib.c index fe6faf6d04..7f2dad476f 100644 --- a/extmod/moduzlib.c +++ b/extmod/moduzlib.c @@ -15,7 +15,7 @@ #if MICROPY_PY_UZLIB #define UZLIB_CONF_PARANOID_CHECKS (1) -#include "../lib/uzlib/src/tinf.h" +#include "lib/uzlib/tinf.h" #if 0 // print debugging info #define DEBUG_printf DEBUG_printf @@ -48,8 +48,8 @@ STATIC int read_src_stream(TINF_DATA *data) { return c; } -STATIC mp_obj_t decompio_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, 2, false); +STATIC mp_obj_t decompio_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 1, 2, false); mp_get_stream_raise(args[0], MP_STREAM_OP_READ); mp_obj_decompio_t *o = m_new_obj(mp_obj_decompio_t); o->base.type = type; @@ -186,7 +186,7 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) { return res; error: - mp_raise_arg1(&mp_type_ValueError, MP_OBJ_NEW_SMALL_INT(st)); + mp_raise_type_arg(&mp_type_ValueError, MP_OBJ_NEW_SMALL_INT(st)); } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_uzlib_decompress_obj, 1, 3, mod_uzlib_decompress); @@ -209,10 +209,10 @@ const mp_obj_module_t mp_module_uzlib = { // only if module is enabled by config setting. #pragma GCC diagnostic ignored "-Wsign-compare" -#include "../lib/uzlib/src/tinflate.c" -#include "../lib/uzlib/src/tinfzlib.c" -#include "../lib/uzlib/src/tinfgzip.c" -#include "../lib/uzlib/src/adler32.c" -#include "../lib/uzlib/src/crc32.c" +#include "lib/uzlib/tinflate.c" +#include "lib/uzlib/tinfzlib.c" +#include "lib/uzlib/tinfgzip.c" +#include "lib/uzlib/adler32.c" +#include "lib/uzlib/crc32.c" #endif // MICROPY_PY_UZLIB diff --git a/extmod/uasyncio/stream.py b/extmod/uasyncio/stream.py index 3a68881da3..af3b8feab3 100644 --- a/extmod/uasyncio/stream.py +++ b/extmod/uasyncio/stream.py @@ -79,8 +79,8 @@ async def open_connection(host, port): from uerrno import EINPROGRESS import usocket as socket - ai = socket.getaddrinfo(host, port)[0] # TODO this is blocking! - s = socket.socket() + ai = socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM)[0] # TODO this is blocking! + s = socket.socket(ai[0], ai[1], ai[2]) s.setblocking(False) ss = Stream(s) try: @@ -107,15 +107,7 @@ class Server: async def wait_closed(self): await self.task - async def _serve(self, cb, host, port, backlog): - import usocket as socket - - ai = socket.getaddrinfo(host, port)[0] # TODO this is blocking! - s = socket.socket() - s.setblocking(False) - s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - s.bind(ai[-1]) - s.listen(backlog) + async def _serve(self, s, cb): # Accept incoming connections while True: try: @@ -137,9 +129,20 @@ class Server: # Helper function to start a TCP stream server, running as a new task # TODO could use an accept-callback on socket read activity instead of creating a task async def start_server(cb, host, port, backlog=5): - s = Server() - s.task = core.create_task(s._serve(cb, host, port, backlog)) - return s + import usocket as socket + + # Create and bind server socket. + host = socket.getaddrinfo(host, port)[0] # TODO this is blocking! + s = socket.socket() + s.setblocking(False) + s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + s.bind(host[-1]) + s.listen(backlog) + + # Create and return server object and task. + srv = Server() + srv.task = core.create_task(srv._serve(s, cb)) + return srv ################################################################################ diff --git a/extmod/ulab b/extmod/ulab index 8d93ddeaf3..b913d064e5 160000 --- a/extmod/ulab +++ b/extmod/ulab @@ -1 +1 @@ -Subproject commit 8d93ddeaf3548d5466cee0a392a4ee89f07ce2e5 +Subproject commit b913d064e525f674d0219524988e6d9d834fe09c diff --git a/extmod/utime_mphal.c b/extmod/utime_mphal.c index 0501724a67..0d6437a920 100644 --- a/extmod/utime_mphal.c +++ b/extmod/utime_mphal.c @@ -27,7 +27,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_utime_sleep_obj, time_sleep); STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) { mp_int_t ms = mp_obj_get_int(arg); - if (ms > 0) { + if (ms >= 0) { mp_hal_delay_ms(ms); } return mp_const_none; diff --git a/extmod/vfs.c b/extmod/vfs.c index b3eeb4e4cf..7aa82a6082 100644 --- a/extmod/vfs.c +++ b/extmod/vfs.c @@ -150,7 +150,7 @@ STATIC mp_obj_t mp_vfs_autodetect(mp_obj_t bdev_obj) { #if MICROPY_VFS_LFS1 if (memcmp(&buf[32], "littlefs", 8) == 0) { // LFS1 - mp_obj_t vfs = mp_type_vfs_lfs1.make_new(&mp_type_vfs_lfs1, 1, &bdev_obj, NULL); + mp_obj_t vfs = mp_type_vfs_lfs1.make_new(&mp_type_vfs_lfs1, 1, 0, &bdev_obj); nlr_pop(); return vfs; } @@ -158,7 +158,7 @@ STATIC mp_obj_t mp_vfs_autodetect(mp_obj_t bdev_obj) { #if MICROPY_VFS_LFS2 if (memcmp(&buf[0], "littlefs", 8) == 0) { // LFS2 - mp_obj_t vfs = mp_type_vfs_lfs2.make_new(&mp_type_vfs_lfs2, 1, &bdev_obj, NULL); + mp_obj_t vfs = mp_type_vfs_lfs2.make_new(&mp_type_vfs_lfs2, 1, 0, &bdev_obj); nlr_pop(); return vfs; } @@ -171,7 +171,7 @@ STATIC mp_obj_t mp_vfs_autodetect(mp_obj_t bdev_obj) { #endif #if MICROPY_VFS_FAT - return mp_fat_vfs_type.make_new(&mp_fat_vfs_type, 1, &bdev_obj, NULL); + return mp_fat_vfs_type.make_new(&mp_fat_vfs_type, 1, 0, &bdev_obj); #endif // no filesystem found diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index f232fd6a80..208cf101f9 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -18,7 +18,7 @@ #include "py/mperrno.h" #include "lib/oofatfs/ff.h" #include "extmod/vfs_fat.h" -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" #include "supervisor/filesystem.h" #include "supervisor/shared/translate.h" @@ -45,8 +45,8 @@ STATIC mp_import_stat_t fat_vfs_import_stat(void *vfs_in, const char *path) { return MP_IMPORT_STAT_NO_EXIST; } -STATIC mp_obj_t fat_vfs_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, 1, false); +STATIC mp_obj_t fat_vfs_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 1, 1, false); // create new object fs_user_mount_t *vfs = m_new_obj(fs_user_mount_t); @@ -88,7 +88,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_del_obj, fat_vfs_del); STATIC mp_obj_t fat_vfs_mkfs(mp_obj_t bdev_in) { // create new object - fs_user_mount_t *vfs = MP_OBJ_TO_PTR(fat_vfs_make_new(&mp_fat_vfs_type, 1, &bdev_in, NULL)); + fs_user_mount_t *vfs = MP_OBJ_TO_PTR(fat_vfs_make_new(&mp_fat_vfs_type, 1, 0, &bdev_in)); // make the filesystem uint8_t working_buf[FF_MAX_SS]; diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index 2f005e4d15..17b142b95a 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -209,9 +209,9 @@ STATIC mp_obj_t file_open(fs_user_mount_t *vfs, const mp_obj_type_t *type, mp_ar return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t file_obj_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t file_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_val_t arg_vals[FILE_OPEN_NUM_ARGS]; - mp_arg_parse_all(n_args, args, kw_args, FILE_OPEN_NUM_ARGS, file_open_args, arg_vals); + mp_arg_parse_all_kw_array(n_args, n_kw, args, FILE_OPEN_NUM_ARGS, file_open_args, arg_vals); return file_open(NULL, type, arg_vals); } diff --git a/extmod/vfs_lfs.c b/extmod/vfs_lfs.c index dd78269a46..f6a9a24623 100644 --- a/extmod/vfs_lfs.c +++ b/extmod/vfs_lfs.c @@ -26,7 +26,7 @@ #include "py/runtime.h" #include "py/mphal.h" -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" #include "extmod/vfs.h" #include "extmod/vfs_lfs.h" diff --git a/extmod/vfs_lfsx.c b/extmod/vfs_lfsx.c index 38a1daea20..872d7f8428 100644 --- a/extmod/vfs_lfsx.c +++ b/extmod/vfs_lfsx.c @@ -34,7 +34,7 @@ #include "py/objstr.h" #include "py/mperrno.h" #include "extmod/vfs.h" -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" STATIC int MP_VFS_LFSx(dev_ioctl)(const struct LFSx_API (config) * c, int cmd, int arg, bool must_return_int) { mp_obj_t ret = mp_vfs_blockdev_ioctl(c->context, cmd, arg); @@ -113,9 +113,9 @@ const char *MP_VFS_LFSx(make_path)(MP_OBJ_VFS_LFSx * self, mp_obj_t path_in) { return path; } -STATIC mp_obj_t MP_VFS_LFSx(make_new)(const mp_obj_type_t * type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t MP_VFS_LFSx(make_new)(const mp_obj_type_t * type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { mp_arg_val_t args[MP_ARRAY_SIZE(lfs_make_allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(lfs_make_allowed_args), lfs_make_allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(lfs_make_allowed_args), lfs_make_allowed_args, args); MP_OBJ_VFS_LFSx *self = m_new0(MP_OBJ_VFS_LFSx, 1); self->base.type = type; diff --git a/extmod/vfs_posix.c b/extmod/vfs_posix.c index f885e126ff..1d0aa09664 100644 --- a/extmod/vfs_posix.c +++ b/extmod/vfs_posix.c @@ -71,8 +71,8 @@ STATIC mp_import_stat_t mp_vfs_posix_import_stat(void *self_in, const char *path return MP_IMPORT_STAT_NO_EXIST; } -STATIC mp_obj_t vfs_posix_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 0, 1, false); +STATIC mp_obj_t vfs_posix_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_obj_vfs_posix_t *vfs = m_new_obj(mp_obj_vfs_posix_t); vfs->base.type = type; diff --git a/extmod/vfs_posix_file.c b/extmod/vfs_posix_file.c index 17aac97e15..8837fdbbd6 100644 --- a/extmod/vfs_posix_file.c +++ b/extmod/vfs_posix_file.c @@ -89,14 +89,14 @@ mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_ return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t vfs_posix_file_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t vfs_posix_file_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { static const mp_arg_t allowed_args[] = { { MP_QSTR_file, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_rom_obj = MP_ROM_NONE} }, { MP_QSTR_mode, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_QSTR(MP_QSTR_r)} }, }; mp_arg_val_t arg_vals[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, arg_vals); + mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args), allowed_args, arg_vals); return mp_vfs_posix_file_open(type, arg_vals[0].u_obj, arg_vals[1].u_obj); } diff --git a/lib/README.md b/lib/README.md index e719821bfc..fd7cba910a 100644 --- a/lib/README.md +++ b/lib/README.md @@ -1,2 +1,3 @@ -This directory contains standard, low-level C libraries with emphasis on -being independent and efficient. They can be used by any port. +This directory contains third-party, low-level C libraries and SDKs. +Libraries that do not target any specific platform are generally chosen +based on them being independent and efficient. diff --git a/lib/axtls b/lib/axtls index 43a6e6bd3b..531cab9c27 160000 --- a/lib/axtls +++ b/lib/axtls @@ -1 +1 @@ -Subproject commit 43a6e6bd3bbc03dc501e16b89fba0ef042ed3ea0 +Subproject commit 531cab9c278c947d268bd4c94ecab9153a961b43 diff --git a/extmod/crypto-algorithms/sha256.c b/lib/crypto-algorithms/sha256.c similarity index 97% rename from extmod/crypto-algorithms/sha256.c rename to lib/crypto-algorithms/sha256.c index 4960589000..1d9484586b 100644 --- a/extmod/crypto-algorithms/sha256.c +++ b/lib/crypto-algorithms/sha256.c @@ -15,6 +15,7 @@ /*************************** HEADER FILES ***************************/ #include +#include #include #include "sha256.h" @@ -47,7 +48,7 @@ static void sha256_transform(CRYAL_SHA256_CTX *ctx, const BYTE data[]) WORD a, b, c, d, e, f, g, h, i, j, t1, t2, m[64]; for (i = 0, j = 0; i < 16; ++i, j += 4) - m[i] = (data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) | (data[j + 3]); + m[i] = ((uint32_t)data[j] << 24) | (data[j + 1] << 16) | (data[j + 2] << 8) | (data[j + 3]); for ( ; i < 64; ++i) m[i] = SIG1(m[i - 2]) + m[i - 7] + SIG0(m[i - 15]) + m[i - 16]; diff --git a/extmod/crypto-algorithms/sha256.h b/lib/crypto-algorithms/sha256.h similarity index 100% rename from extmod/crypto-algorithms/sha256.h rename to lib/crypto-algorithms/sha256.h diff --git a/extmod/re1.5/charclass.c b/lib/re1.5/charclass.c similarity index 100% rename from extmod/re1.5/charclass.c rename to lib/re1.5/charclass.c diff --git a/extmod/re1.5/compilecode.c b/lib/re1.5/compilecode.c similarity index 100% rename from extmod/re1.5/compilecode.c rename to lib/re1.5/compilecode.c diff --git a/extmod/re1.5/dumpcode.c b/lib/re1.5/dumpcode.c similarity index 100% rename from extmod/re1.5/dumpcode.c rename to lib/re1.5/dumpcode.c diff --git a/extmod/re1.5/re1.5.h b/lib/re1.5/re1.5.h similarity index 100% rename from extmod/re1.5/re1.5.h rename to lib/re1.5/re1.5.h diff --git a/extmod/re1.5/recursiveloop.c b/lib/re1.5/recursiveloop.c similarity index 100% rename from extmod/re1.5/recursiveloop.c rename to lib/re1.5/recursiveloop.c diff --git a/lib/uzlib b/lib/uzlib deleted file mode 160000 index 27e4f4c15b..0000000000 --- a/lib/uzlib +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 27e4f4c15ba30c2cfc89575159e8efb50f95037e diff --git a/lib/uzlib/adler32.c b/lib/uzlib/adler32.c new file mode 100644 index 0000000000..1f1759493b --- /dev/null +++ b/lib/uzlib/adler32.c @@ -0,0 +1,78 @@ +/* + * Adler-32 checksum + * + * Copyright (c) 2003 by Joergen Ibsen / Jibz + * All Rights Reserved + * + * http://www.ibsensoftware.com/ + * + * This software is provided 'as-is', without any express + * or implied warranty. In no event will the authors be + * held liable for any damages arising from the use of + * this software. + * + * Permission is granted to anyone to use this software + * for any purpose, including commercial applications, + * and to alter it and redistribute it freely, subject to + * the following restrictions: + * + * 1. The origin of this software must not be + * misrepresented; you must not claim that you + * wrote the original software. If you use this + * software in a product, an acknowledgment in + * the product documentation would be appreciated + * but is not required. + * + * 2. Altered source versions must be plainly marked + * as such, and must not be misrepresented as + * being the original software. + * + * 3. This notice may not be removed or altered from + * any source distribution. + */ + +/* + * Adler-32 algorithm taken from the zlib source, which is + * Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler + */ + +#include "tinf.h" + +#define A32_BASE 65521 +#define A32_NMAX 5552 + +uint32_t uzlib_adler32(const void *data, unsigned int length, uint32_t prev_sum /* 1 */) +{ + const unsigned char *buf = (const unsigned char *)data; + + unsigned int s1 = prev_sum & 0xffff; + unsigned int s2 = prev_sum >> 16; + + while (length > 0) + { + int k = length < A32_NMAX ? length : A32_NMAX; + int i; + + for (i = k / 16; i; --i, buf += 16) + { + s1 += buf[0]; s2 += s1; s1 += buf[1]; s2 += s1; + s1 += buf[2]; s2 += s1; s1 += buf[3]; s2 += s1; + s1 += buf[4]; s2 += s1; s1 += buf[5]; s2 += s1; + s1 += buf[6]; s2 += s1; s1 += buf[7]; s2 += s1; + + s1 += buf[8]; s2 += s1; s1 += buf[9]; s2 += s1; + s1 += buf[10]; s2 += s1; s1 += buf[11]; s2 += s1; + s1 += buf[12]; s2 += s1; s1 += buf[13]; s2 += s1; + s1 += buf[14]; s2 += s1; s1 += buf[15]; s2 += s1; + } + + for (i = k % 16; i; --i) { s1 += *buf++; s2 += s1; } + + s1 %= A32_BASE; + s2 %= A32_BASE; + + length -= k; + } + + return (s2 << 16) | s1; +} diff --git a/lib/uzlib/crc32.c b/lib/uzlib/crc32.c new file mode 100644 index 0000000000..e24c643b6a --- /dev/null +++ b/lib/uzlib/crc32.c @@ -0,0 +1,63 @@ +/* + * CRC32 checksum + * + * Copyright (c) 1998-2003 by Joergen Ibsen / Jibz + * All Rights Reserved + * + * http://www.ibsensoftware.com/ + * + * This software is provided 'as-is', without any express + * or implied warranty. In no event will the authors be + * held liable for any damages arising from the use of + * this software. + * + * Permission is granted to anyone to use this software + * for any purpose, including commercial applications, + * and to alter it and redistribute it freely, subject to + * the following restrictions: + * + * 1. The origin of this software must not be + * misrepresented; you must not claim that you + * wrote the original software. If you use this + * software in a product, an acknowledgment in + * the product documentation would be appreciated + * but is not required. + * + * 2. Altered source versions must be plainly marked + * as such, and must not be misrepresented as + * being the original software. + * + * 3. This notice may not be removed or altered from + * any source distribution. + */ + +/* + * CRC32 algorithm taken from the zlib source, which is + * Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler + */ + +#include "tinf.h" + +static const unsigned int tinf_crc32tab[16] = { + 0x00000000, 0x1db71064, 0x3b6e20c8, 0x26d930ac, 0x76dc4190, + 0x6b6b51f4, 0x4db26158, 0x5005713c, 0xedb88320, 0xf00f9344, + 0xd6d6a3e8, 0xcb61b38c, 0x9b64c2b0, 0x86d3d2d4, 0xa00ae278, + 0xbdbdf21c +}; + +/* crc is previous value for incremental computation, 0xffffffff initially */ +uint32_t uzlib_crc32(const void *data, unsigned int length, uint32_t crc) +{ + const unsigned char *buf = (const unsigned char *)data; + unsigned int i; + + for (i = 0; i < length; ++i) + { + crc ^= buf[i]; + crc = tinf_crc32tab[crc & 0x0f] ^ (crc >> 4); + crc = tinf_crc32tab[crc & 0x0f] ^ (crc >> 4); + } + + // return value suitable for passing in next time, for final value invert it + return crc/* ^ 0xffffffff*/; +} diff --git a/lib/uzlib/defl_static.h b/lib/uzlib/defl_static.h new file mode 100644 index 0000000000..292734d773 --- /dev/null +++ b/lib/uzlib/defl_static.h @@ -0,0 +1,45 @@ +/* + * Copyright (c) uzlib authors + * + * This software is provided 'as-is', without any express + * or implied warranty. In no event will the authors be + * held liable for any damages arising from the use of + * this software. + * + * Permission is granted to anyone to use this software + * for any purpose, including commercial applications, + * and to alter it and redistribute it freely, subject to + * the following restrictions: + * + * 1. The origin of this software must not be + * misrepresented; you must not claim that you + * wrote the original software. If you use this + * software in a product, an acknowledgment in + * the product documentation would be appreciated + * but is not required. + * + * 2. Altered source versions must be plainly marked + * as such, and must not be misrepresented as + * being the original software. + * + * 3. This notice may not be removed or altered from + * any source distribution. + */ + +/* This files contains type declaration and prototypes for defl_static.c. + They may be altered/distinct from the originals used in PuTTY source + code. */ + +struct Outbuf { + unsigned char *outbuf; + int outlen, outsize; + unsigned long outbits; + int noutbits; + int comp_disabled; +}; + +void outbits(struct Outbuf *out, unsigned long bits, int nbits); +void zlib_start_block(struct Outbuf *ctx); +void zlib_finish_block(struct Outbuf *ctx); +void zlib_literal(struct Outbuf *ectx, unsigned char c); +void zlib_match(struct Outbuf *ectx, int distance, int len); diff --git a/lib/uzlib/tinf.h b/lib/uzlib/tinf.h new file mode 100644 index 0000000000..ae6e1c4073 --- /dev/null +++ b/lib/uzlib/tinf.h @@ -0,0 +1,3 @@ +/* Compatibility header for the original tinf lib/older versions of uzlib. + Note: may be removed in the future, please migrate to uzlib.h. */ +#include "uzlib.h" diff --git a/lib/uzlib/tinf_compat.h b/lib/uzlib/tinf_compat.h new file mode 100644 index 0000000000..f763804bd9 --- /dev/null +++ b/lib/uzlib/tinf_compat.h @@ -0,0 +1,9 @@ +/* This header contains compatibility defines for the original tinf API + and uzlib 2.x and below API. These defines are deprecated and going + to be removed in the future, so applications should migrate to new + uzlib API. */ +#define TINF_DATA struct uzlib_uncomp + +#define destSize dest_size +#define destStart dest_start +#define readSource source_read_cb diff --git a/lib/uzlib/tinfgzip.c b/lib/uzlib/tinfgzip.c new file mode 100644 index 0000000000..22b000df9a --- /dev/null +++ b/lib/uzlib/tinfgzip.c @@ -0,0 +1,110 @@ +/* + * uzlib - tiny deflate/inflate library (deflate, gzip, zlib) + * + * Copyright (c) 2003 by Joergen Ibsen / Jibz + * All Rights Reserved + * + * http://www.ibsensoftware.com/ + * + * Copyright (c) 2014-2018 by Paul Sokolovsky + * + * This software is provided 'as-is', without any express + * or implied warranty. In no event will the authors be + * held liable for any damages arising from the use of + * this software. + * + * Permission is granted to anyone to use this software + * for any purpose, including commercial applications, + * and to alter it and redistribute it freely, subject to + * the following restrictions: + * + * 1. The origin of this software must not be + * misrepresented; you must not claim that you + * wrote the original software. If you use this + * software in a product, an acknowledgment in + * the product documentation would be appreciated + * but is not required. + * + * 2. Altered source versions must be plainly marked + * as such, and must not be misrepresented as + * being the original software. + * + * 3. This notice may not be removed or altered from + * any source distribution. + */ + +#include "tinf.h" + +#define FTEXT 1 +#define FHCRC 2 +#define FEXTRA 4 +#define FNAME 8 +#define FCOMMENT 16 + +void tinf_skip_bytes(TINF_DATA *d, int num); +uint16_t tinf_get_uint16(TINF_DATA *d); + +void tinf_skip_bytes(TINF_DATA *d, int num) +{ + while (num--) uzlib_get_byte(d); +} + +uint16_t tinf_get_uint16(TINF_DATA *d) +{ + unsigned int v = uzlib_get_byte(d); + v = (uzlib_get_byte(d) << 8) | v; + return v; +} + +int uzlib_gzip_parse_header(TINF_DATA *d) +{ + unsigned char flg; + + /* -- check format -- */ + + /* check id bytes */ + if (uzlib_get_byte(d) != 0x1f || uzlib_get_byte(d) != 0x8b) return TINF_DATA_ERROR; + + /* check method is deflate */ + if (uzlib_get_byte(d) != 8) return TINF_DATA_ERROR; + + /* get flag byte */ + flg = uzlib_get_byte(d); + + /* check that reserved bits are zero */ + if (flg & 0xe0) return TINF_DATA_ERROR; + + /* -- find start of compressed data -- */ + + /* skip rest of base header of 10 bytes */ + tinf_skip_bytes(d, 6); + + /* skip extra data if present */ + if (flg & FEXTRA) + { + unsigned int xlen = tinf_get_uint16(d); + tinf_skip_bytes(d, xlen); + } + + /* skip file name if present */ + if (flg & FNAME) { while (uzlib_get_byte(d)); } + + /* skip file comment if present */ + if (flg & FCOMMENT) { while (uzlib_get_byte(d)); } + + /* check header crc if present */ + if (flg & FHCRC) + { + /*unsigned int hcrc =*/ tinf_get_uint16(d); + + // TODO: Check! +// if (hcrc != (tinf_crc32(src, start - src) & 0x0000ffff)) +// return TINF_DATA_ERROR; + } + + /* initialize for crc32 checksum */ + d->checksum_type = TINF_CHKSUM_CRC; + d->checksum = ~0; + + return TINF_OK; +} diff --git a/lib/uzlib/tinflate.c b/lib/uzlib/tinflate.c new file mode 100644 index 0000000000..045952c755 --- /dev/null +++ b/lib/uzlib/tinflate.c @@ -0,0 +1,659 @@ +/* + * uzlib - tiny deflate/inflate library (deflate, gzip, zlib) + * + * Copyright (c) 2003 by Joergen Ibsen / Jibz + * All Rights Reserved + * http://www.ibsensoftware.com/ + * + * Copyright (c) 2014-2018 by Paul Sokolovsky + * + * This software is provided 'as-is', without any express + * or implied warranty. In no event will the authors be + * held liable for any damages arising from the use of + * this software. + * + * Permission is granted to anyone to use this software + * for any purpose, including commercial applications, + * and to alter it and redistribute it freely, subject to + * the following restrictions: + * + * 1. The origin of this software must not be + * misrepresented; you must not claim that you + * wrote the original software. If you use this + * software in a product, an acknowledgment in + * the product documentation would be appreciated + * but is not required. + * + * 2. Altered source versions must be plainly marked + * as such, and must not be misrepresented as + * being the original software. + * + * 3. This notice may not be removed or altered from + * any source distribution. + */ + +#include +#include "tinf.h" + +#define UZLIB_DUMP_ARRAY(heading, arr, size) \ + { \ + printf("%s", heading); \ + for (int i = 0; i < size; ++i) { \ + printf(" %d", (arr)[i]); \ + } \ + printf("\n"); \ + } + +uint32_t tinf_get_le_uint32(TINF_DATA *d); +uint32_t tinf_get_be_uint32(TINF_DATA *d); + +/* --------------------------------------------------- * + * -- uninitialized global data (static structures) -- * + * --------------------------------------------------- */ + +#ifdef RUNTIME_BITS_TABLES + +/* extra bits and base tables for length codes */ +unsigned char length_bits[30]; +unsigned short length_base[30]; + +/* extra bits and base tables for distance codes */ +unsigned char dist_bits[30]; +unsigned short dist_base[30]; + +#else + +const unsigned char length_bits[30] = { + 0, 0, 0, 0, 0, 0, 0, 0, + 1, 1, 1, 1, 2, 2, 2, 2, + 3, 3, 3, 3, 4, 4, 4, 4, + 5, 5, 5, 5 +}; +const unsigned short length_base[30] = { + 3, 4, 5, 6, 7, 8, 9, 10, + 11, 13, 15, 17, 19, 23, 27, 31, + 35, 43, 51, 59, 67, 83, 99, 115, + 131, 163, 195, 227, 258 +}; + +const unsigned char dist_bits[30] = { + 0, 0, 0, 0, 1, 1, 2, 2, + 3, 3, 4, 4, 5, 5, 6, 6, + 7, 7, 8, 8, 9, 9, 10, 10, + 11, 11, 12, 12, 13, 13 +}; +const unsigned short dist_base[30] = { + 1, 2, 3, 4, 5, 7, 9, 13, + 17, 25, 33, 49, 65, 97, 129, 193, + 257, 385, 513, 769, 1025, 1537, 2049, 3073, + 4097, 6145, 8193, 12289, 16385, 24577 +}; + +#endif + +/* special ordering of code length codes */ +const unsigned char clcidx[] = { + 16, 17, 18, 0, 8, 7, 9, 6, + 10, 5, 11, 4, 12, 3, 13, 2, + 14, 1, 15 +}; + +/* ----------------------- * + * -- utility functions -- * + * ----------------------- */ + +#ifdef RUNTIME_BITS_TABLES +/* build extra bits and base tables */ +static void tinf_build_bits_base(unsigned char *bits, unsigned short *base, int delta, int first) +{ + int i, sum; + + /* build bits table */ + for (i = 0; i < delta; ++i) bits[i] = 0; + for (i = 0; i < 30 - delta; ++i) bits[i + delta] = i / delta; + + /* build base table */ + for (sum = first, i = 0; i < 30; ++i) + { + base[i] = sum; + sum += 1 << bits[i]; + } +} +#endif + +/* build the fixed huffman trees */ +static void tinf_build_fixed_trees(TINF_TREE *lt, TINF_TREE *dt) +{ + int i; + + /* build fixed length tree */ + for (i = 0; i < 7; ++i) lt->table[i] = 0; + + lt->table[7] = 24; + lt->table[8] = 152; + lt->table[9] = 112; + + for (i = 0; i < 24; ++i) lt->trans[i] = 256 + i; + for (i = 0; i < 144; ++i) lt->trans[24 + i] = i; + for (i = 0; i < 8; ++i) lt->trans[24 + 144 + i] = 280 + i; + for (i = 0; i < 112; ++i) lt->trans[24 + 144 + 8 + i] = 144 + i; + + /* build fixed distance tree */ + for (i = 0; i < 5; ++i) dt->table[i] = 0; + + dt->table[5] = 32; + + for (i = 0; i < 32; ++i) dt->trans[i] = i; +} + +/* given an array of code lengths, build a tree */ +static void tinf_build_tree(TINF_TREE *t, const unsigned char *lengths, unsigned int num) +{ + unsigned short offs[16]; + unsigned int i, sum; + + /* clear code length count table */ + for (i = 0; i < 16; ++i) t->table[i] = 0; + + /* scan symbol lengths, and sum code length counts */ + for (i = 0; i < num; ++i) t->table[lengths[i]]++; + + #if UZLIB_CONF_DEBUG_LOG >= 2 + UZLIB_DUMP_ARRAY("codelen counts:", t->table, TINF_ARRAY_SIZE(t->table)); + #endif + + /* In the lengths array, 0 means unused code. So, t->table[0] now contains + number of unused codes. But table's purpose is to contain # of codes of + particular length, and there're 0 codes of length 0. */ + t->table[0] = 0; + + /* compute offset table for distribution sort */ + for (sum = 0, i = 0; i < 16; ++i) + { + offs[i] = sum; + sum += t->table[i]; + } + + #if UZLIB_CONF_DEBUG_LOG >= 2 + UZLIB_DUMP_ARRAY("codelen offsets:", offs, TINF_ARRAY_SIZE(offs)); + #endif + + /* create code->symbol translation table (symbols sorted by code) */ + for (i = 0; i < num; ++i) + { + if (lengths[i]) t->trans[offs[lengths[i]]++] = i; + } +} + +/* ---------------------- * + * -- decode functions -- * + * ---------------------- */ + +unsigned char uzlib_get_byte(TINF_DATA *d) +{ + /* If end of source buffer is not reached, return next byte from source + buffer. */ + if (d->source < d->source_limit) { + return *d->source++; + } + + /* Otherwise if there's callback and we haven't seen EOF yet, try to + read next byte using it. (Note: the callback can also update ->source + and ->source_limit). */ + if (d->readSource && !d->eof) { + int val = d->readSource(d); + if (val >= 0) { + return (unsigned char)val; + } + } + + /* Otherwise, we hit EOF (either from ->readSource() or from exhaustion + of the buffer), and it will be "sticky", i.e. further calls to this + function will end up here too. */ + d->eof = true; + + return 0; +} + +uint32_t tinf_get_le_uint32(TINF_DATA *d) +{ + uint32_t val = 0; + int i; + for (i = 4; i--;) { + val = val >> 8 | ((uint32_t)uzlib_get_byte(d)) << 24; + } + return val; +} + +uint32_t tinf_get_be_uint32(TINF_DATA *d) +{ + uint32_t val = 0; + int i; + for (i = 4; i--;) { + val = val << 8 | uzlib_get_byte(d); + } + return val; +} + +/* get one bit from source stream */ +static int tinf_getbit(TINF_DATA *d) +{ + unsigned int bit; + + /* check if tag is empty */ + if (!d->bitcount--) + { + /* load next tag */ + d->tag = uzlib_get_byte(d); + d->bitcount = 7; + } + + /* shift bit out of tag */ + bit = d->tag & 0x01; + d->tag >>= 1; + + return bit; +} + +/* read a num bit value from a stream and add base */ +static unsigned int tinf_read_bits(TINF_DATA *d, int num, int base) +{ + unsigned int val = 0; + + /* read num bits */ + if (num) + { + unsigned int limit = 1 << (num); + unsigned int mask; + + for (mask = 1; mask < limit; mask *= 2) + if (tinf_getbit(d)) val += mask; + } + + return val + base; +} + +/* given a data stream and a tree, decode a symbol */ +static int tinf_decode_symbol(TINF_DATA *d, TINF_TREE *t) +{ + int sum = 0, cur = 0, len = 0; + + /* get more bits while code value is above sum */ + do { + + cur = 2*cur + tinf_getbit(d); + + if (++len == TINF_ARRAY_SIZE(t->table)) { + return TINF_DATA_ERROR; + } + + sum += t->table[len]; + cur -= t->table[len]; + + } while (cur >= 0); + + sum += cur; + #if UZLIB_CONF_PARANOID_CHECKS + if (sum < 0 || sum >= TINF_ARRAY_SIZE(t->trans)) { + return TINF_DATA_ERROR; + } + #endif + + return t->trans[sum]; +} + +/* given a data stream, decode dynamic trees from it */ +static int tinf_decode_trees(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) +{ + /* code lengths for 288 literal/len symbols and 32 dist symbols */ + unsigned char lengths[288+32]; + unsigned int hlit, hdist, hclen, hlimit; + unsigned int i, num, length; + + /* get 5 bits HLIT (257-286) */ + hlit = tinf_read_bits(d, 5, 257); + + /* get 5 bits HDIST (1-32) */ + hdist = tinf_read_bits(d, 5, 1); + + /* get 4 bits HCLEN (4-19) */ + hclen = tinf_read_bits(d, 4, 4); + + for (i = 0; i < 19; ++i) lengths[i] = 0; + + /* read code lengths for code length alphabet */ + for (i = 0; i < hclen; ++i) + { + /* get 3 bits code length (0-7) */ + unsigned int clen = tinf_read_bits(d, 3, 0); + + lengths[clcidx[i]] = clen; + } + + /* build code length tree, temporarily use length tree */ + tinf_build_tree(lt, lengths, 19); + + /* decode code lengths for the dynamic trees */ + hlimit = hlit + hdist; + for (num = 0; num < hlimit; ) + { + int sym = tinf_decode_symbol(d, lt); + unsigned char fill_value = 0; + int lbits, lbase = 3; + + /* error decoding */ + if (sym < 0) return sym; + + switch (sym) + { + case 16: + /* copy previous code length 3-6 times (read 2 bits) */ + if (num == 0) return TINF_DATA_ERROR; + fill_value = lengths[num - 1]; + lbits = 2; + break; + case 17: + /* repeat code length 0 for 3-10 times (read 3 bits) */ + lbits = 3; + break; + case 18: + /* repeat code length 0 for 11-138 times (read 7 bits) */ + lbits = 7; + lbase = 11; + break; + default: + /* values 0-15 represent the actual code lengths */ + lengths[num++] = sym; + /* continue the for loop */ + continue; + } + + /* special code length 16-18 are handled here */ + length = tinf_read_bits(d, lbits, lbase); + if (num + length > hlimit) return TINF_DATA_ERROR; + for (; length; --length) + { + lengths[num++] = fill_value; + } + } + + #if UZLIB_CONF_DEBUG_LOG >= 2 + printf("lit code lengths (%d):", hlit); + UZLIB_DUMP_ARRAY("", lengths, hlit); + printf("dist code lengths (%d):", hdist); + UZLIB_DUMP_ARRAY("", lengths + hlit, hdist); + #endif + + #if UZLIB_CONF_PARANOID_CHECKS + /* Check that there's "end of block" symbol */ + if (lengths[256] == 0) { + return TINF_DATA_ERROR; + } + #endif + + /* build dynamic trees */ + tinf_build_tree(lt, lengths, hlit); + tinf_build_tree(dt, lengths + hlit, hdist); + + return TINF_OK; +} + +/* ----------------------------- * + * -- block inflate functions -- * + * ----------------------------- */ + +/* given a stream and two trees, inflate next byte of output */ +static int tinf_inflate_block_data(TINF_DATA *d, TINF_TREE *lt, TINF_TREE *dt) +{ + if (d->curlen == 0) { + unsigned int offs; + int dist; + int sym = tinf_decode_symbol(d, lt); + //printf("huff sym: %02x\n", sym); + + if (d->eof) { + return TINF_DATA_ERROR; + } + + /* literal byte */ + if (sym < 256) { + TINF_PUT(d, sym); + return TINF_OK; + } + + /* end of block */ + if (sym == 256) { + return TINF_DONE; + } + + /* substring from sliding dictionary */ + sym -= 257; + if (sym >= 29) { + return TINF_DATA_ERROR; + } + + /* possibly get more bits from length code */ + d->curlen = tinf_read_bits(d, length_bits[sym], length_base[sym]); + + dist = tinf_decode_symbol(d, dt); + if (dist >= 30) { + return TINF_DATA_ERROR; + } + + /* possibly get more bits from distance code */ + offs = tinf_read_bits(d, dist_bits[dist], dist_base[dist]); + + /* calculate and validate actual LZ offset to use */ + if (d->dict_ring) { + if (offs > d->dict_size) { + return TINF_DICT_ERROR; + } + /* Note: unlike full-dest-in-memory case below, we don't + try to catch offset which points to not yet filled + part of the dictionary here. Doing so would require + keeping another variable to track "filled in" size + of the dictionary. Appearance of such an offset cannot + lead to accessing memory outside of the dictionary + buffer, and clients which don't want to leak unrelated + information, should explicitly initialize dictionary + buffer passed to uzlib. */ + + d->lzOff = d->dict_idx - offs; + if (d->lzOff < 0) { + d->lzOff += d->dict_size; + } + } else { + /* catch trying to point before the start of dest buffer */ + if (offs > (unsigned int)(d->dest - d->destStart)) { + return TINF_DATA_ERROR; + } + d->lzOff = -offs; + } + } + + /* copy next byte from dict substring */ + if (d->dict_ring) { + TINF_PUT(d, d->dict_ring[d->lzOff]); + if ((unsigned)++d->lzOff == d->dict_size) { + d->lzOff = 0; + } + } else { + d->dest[0] = d->dest[d->lzOff]; + d->dest++; + } + d->curlen--; + return TINF_OK; +} + +/* inflate next byte from uncompressed block of data */ +static int tinf_inflate_uncompressed_block(TINF_DATA *d) +{ + if (d->curlen == 0) { + unsigned int length, invlength; + + /* get length */ + length = uzlib_get_byte(d); + length += 256 * uzlib_get_byte(d); + /* get one's complement of length */ + invlength = uzlib_get_byte(d); + invlength += 256 * uzlib_get_byte(d); + /* check length */ + if (length != (~invlength & 0x0000ffff)) return TINF_DATA_ERROR; + + /* increment length to properly return TINF_DONE below, without + producing data at the same time */ + d->curlen = length + 1; + + /* make sure we start next block on a byte boundary */ + d->bitcount = 0; + } + + if (--d->curlen == 0) { + return TINF_DONE; + } + + unsigned char c = uzlib_get_byte(d); + TINF_PUT(d, c); + return TINF_OK; +} + +/* ---------------------- * + * -- public functions -- * + * ---------------------- */ + +/* initialize global (static) data */ +void uzlib_init(void) +{ +#ifdef RUNTIME_BITS_TABLES + /* build extra bits and base tables */ + tinf_build_bits_base(length_bits, length_base, 4, 3); + tinf_build_bits_base(dist_bits, dist_base, 2, 1); + + /* fix a special case */ + length_bits[28] = 0; + length_base[28] = 258; +#endif +} + +/* initialize decompression structure */ +void uzlib_uncompress_init(TINF_DATA *d, void *dict, unsigned int dictLen) +{ + d->eof = 0; + d->bitcount = 0; + d->bfinal = 0; + d->btype = -1; + d->dict_size = dictLen; + d->dict_ring = dict; + d->dict_idx = 0; + d->curlen = 0; +} + +/* inflate next output bytes from compressed stream */ +int uzlib_uncompress(TINF_DATA *d) +{ + do { + int res; + + /* start a new block */ + if (d->btype == -1) { +next_blk: + /* read final block flag */ + d->bfinal = tinf_getbit(d); + /* read block type (2 bits) */ + d->btype = tinf_read_bits(d, 2, 0); + + #if UZLIB_CONF_DEBUG_LOG >= 1 + printf("Started new block: type=%d final=%d\n", d->btype, d->bfinal); + #endif + + if (d->btype == 1) { + /* build fixed huffman trees */ + tinf_build_fixed_trees(&d->ltree, &d->dtree); + } else if (d->btype == 2) { + /* decode trees from stream */ + res = tinf_decode_trees(d, &d->ltree, &d->dtree); + if (res != TINF_OK) { + return res; + } + } + } + + /* process current block */ + switch (d->btype) + { + case 0: + /* decompress uncompressed block */ + res = tinf_inflate_uncompressed_block(d); + break; + case 1: + case 2: + /* decompress block with fixed/dynamic huffman trees */ + /* trees were decoded previously, so it's the same routine for both */ + res = tinf_inflate_block_data(d, &d->ltree, &d->dtree); + break; + default: + return TINF_DATA_ERROR; + } + + if (res == TINF_DONE && !d->bfinal) { + /* the block has ended (without producing more data), but we + can't return without data, so start procesing next block */ + goto next_blk; + } + + if (res != TINF_OK) { + return res; + } + + } while (d->dest < d->dest_limit); + + return TINF_OK; +} + +/* inflate next output bytes from compressed stream, updating + checksum, and at the end of stream, verify it */ +int uzlib_uncompress_chksum(TINF_DATA *d) +{ + int res; + unsigned char *data = d->dest; + + res = uzlib_uncompress(d); + + if (res < 0) return res; + + switch (d->checksum_type) { + + case TINF_CHKSUM_ADLER: + d->checksum = uzlib_adler32(data, d->dest - data, d->checksum); + break; + + case TINF_CHKSUM_CRC: + d->checksum = uzlib_crc32(data, d->dest - data, d->checksum); + break; + } + + if (res == TINF_DONE) { + unsigned int val; + + switch (d->checksum_type) { + + case TINF_CHKSUM_ADLER: + val = tinf_get_be_uint32(d); + if (d->checksum != val) { + return TINF_CHKSUM_ERROR; + } + break; + + case TINF_CHKSUM_CRC: + val = tinf_get_le_uint32(d); + if (~d->checksum != val) { + return TINF_CHKSUM_ERROR; + } + // Uncompressed size. TODO: Check + val = tinf_get_le_uint32(d); + break; + } + } + + return res; +} diff --git a/lib/uzlib/tinfzlib.c b/lib/uzlib/tinfzlib.c new file mode 100644 index 0000000000..5cb8852fcc --- /dev/null +++ b/lib/uzlib/tinfzlib.c @@ -0,0 +1,66 @@ +/* + * uzlib - tiny deflate/inflate library (deflate, gzip, zlib) + * + * Copyright (c) 2003 by Joergen Ibsen / Jibz + * All Rights Reserved + * + * http://www.ibsensoftware.com/ + * + * Copyright (c) 2014-2018 by Paul Sokolovsky + * + * This software is provided 'as-is', without any express + * or implied warranty. In no event will the authors be + * held liable for any damages arising from the use of + * this software. + * + * Permission is granted to anyone to use this software + * for any purpose, including commercial applications, + * and to alter it and redistribute it freely, subject to + * the following restrictions: + * + * 1. The origin of this software must not be + * misrepresented; you must not claim that you + * wrote the original software. If you use this + * software in a product, an acknowledgment in + * the product documentation would be appreciated + * but is not required. + * + * 2. Altered source versions must be plainly marked + * as such, and must not be misrepresented as + * being the original software. + * + * 3. This notice may not be removed or altered from + * any source distribution. + */ + +#include "tinf.h" + +int uzlib_zlib_parse_header(TINF_DATA *d) +{ + unsigned char cmf, flg; + + /* -- get header bytes -- */ + + cmf = uzlib_get_byte(d); + flg = uzlib_get_byte(d); + + /* -- check format -- */ + + /* check checksum */ + if ((256*cmf + flg) % 31) return TINF_DATA_ERROR; + + /* check method is deflate */ + if ((cmf & 0x0f) != 8) return TINF_DATA_ERROR; + + /* check window size is valid */ + if ((cmf >> 4) > 7) return TINF_DATA_ERROR; + + /* check there is no preset dictionary */ + if (flg & 0x20) return TINF_DATA_ERROR; + + /* initialize for adler32 checksum */ + d->checksum_type = TINF_CHKSUM_ADLER; + d->checksum = 1; + + return cmf >> 4; +} diff --git a/lib/uzlib/uzlib.h b/lib/uzlib/uzlib.h new file mode 100644 index 0000000000..3a4a1ad160 --- /dev/null +++ b/lib/uzlib/uzlib.h @@ -0,0 +1,169 @@ +/* + * uzlib - tiny deflate/inflate library (deflate, gzip, zlib) + * + * Copyright (c) 2003 by Joergen Ibsen / Jibz + * All Rights Reserved + * http://www.ibsensoftware.com/ + * + * Copyright (c) 2014-2018 by Paul Sokolovsky + * + * This software is provided 'as-is', without any express + * or implied warranty. In no event will the authors be + * held liable for any damages arising from the use of + * this software. + * + * Permission is granted to anyone to use this software + * for any purpose, including commercial applications, + * and to alter it and redistribute it freely, subject to + * the following restrictions: + * + * 1. The origin of this software must not be + * misrepresented; you must not claim that you + * wrote the original software. If you use this + * software in a product, an acknowledgment in + * the product documentation would be appreciated + * but is not required. + * + * 2. Altered source versions must be plainly marked + * as such, and must not be misrepresented as + * being the original software. + * + * 3. This notice may not be removed or altered from + * any source distribution. + */ + +#ifndef UZLIB_H_INCLUDED +#define UZLIB_H_INCLUDED + +#include +#include +#include + +#include "defl_static.h" + +#include "uzlib_conf.h" +#if UZLIB_CONF_DEBUG_LOG +#include +#endif + +/* calling convention */ +#ifndef TINFCC + #ifdef __WATCOMC__ + #define TINFCC __cdecl + #else + #define TINFCC + #endif +#endif + +#ifdef __cplusplus +extern "C" { +#endif + +/* ok status, more data produced */ +#define TINF_OK 0 +/* end of compressed stream reached */ +#define TINF_DONE 1 +#define TINF_DATA_ERROR (-3) +#define TINF_CHKSUM_ERROR (-4) +#define TINF_DICT_ERROR (-5) + +/* checksum types */ +#define TINF_CHKSUM_NONE 0 +#define TINF_CHKSUM_ADLER 1 +#define TINF_CHKSUM_CRC 2 + +/* helper macros */ +#define TINF_ARRAY_SIZE(arr) (sizeof(arr) / sizeof(*(arr))) + +/* data structures */ + +typedef struct { + unsigned short table[16]; /* table of code length counts */ + unsigned short trans[288]; /* code -> symbol translation table */ +} TINF_TREE; + +struct uzlib_uncomp { + /* Pointer to the next byte in the input buffer */ + const unsigned char *source; + /* Pointer to the next byte past the input buffer (source_limit = source + len) */ + const unsigned char *source_limit; + /* If source_limit == NULL, or source >= source_limit, this function + will be used to read next byte from source stream. The function may + also return -1 in case of EOF (or irrecoverable error). Note that + besides returning the next byte, it may also update source and + source_limit fields, thus allowing for buffered operation. */ + int (*source_read_cb)(struct uzlib_uncomp *uncomp); + + unsigned int tag; + unsigned int bitcount; + + /* Destination (output) buffer start */ + unsigned char *dest_start; + /* Current pointer in dest buffer */ + unsigned char *dest; + /* Pointer past the end of the dest buffer, similar to source_limit */ + unsigned char *dest_limit; + + /* Accumulating checksum */ + unsigned int checksum; + char checksum_type; + bool eof; + + int btype; + int bfinal; + unsigned int curlen; + int lzOff; + unsigned char *dict_ring; + unsigned int dict_size; + unsigned int dict_idx; + + TINF_TREE ltree; /* dynamic length/symbol tree */ + TINF_TREE dtree; /* dynamic distance tree */ +}; + +#include "tinf_compat.h" + +#define TINF_PUT(d, c) \ + { \ + *d->dest++ = c; \ + if (d->dict_ring) { d->dict_ring[d->dict_idx++] = c; if (d->dict_idx == d->dict_size) d->dict_idx = 0; } \ + } + +unsigned char TINFCC uzlib_get_byte(TINF_DATA *d); + +/* Decompression API */ + +void TINFCC uzlib_init(void); +void TINFCC uzlib_uncompress_init(TINF_DATA *d, void *dict, unsigned int dictLen); +int TINFCC uzlib_uncompress(TINF_DATA *d); +int TINFCC uzlib_uncompress_chksum(TINF_DATA *d); + +int TINFCC uzlib_zlib_parse_header(TINF_DATA *d); +int TINFCC uzlib_gzip_parse_header(TINF_DATA *d); + +/* Compression API */ + +typedef const uint8_t *uzlib_hash_entry_t; + +struct uzlib_comp { + struct Outbuf out; + + uzlib_hash_entry_t *hash_table; + unsigned int hash_bits; + unsigned int dict_size; +}; + +void TINFCC uzlib_compress(struct uzlib_comp *c, const uint8_t *src, unsigned slen); + +/* Checksum API */ + +/* prev_sum is previous value for incremental computation, 1 initially */ +uint32_t TINFCC uzlib_adler32(const void *data, unsigned int length, uint32_t prev_sum); +/* crc is previous value for incremental computation, 0xffffffff initially */ +uint32_t TINFCC uzlib_crc32(const void *data, unsigned int length, uint32_t crc); + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /* UZLIB_H_INCLUDED */ diff --git a/lib/uzlib/uzlib_conf.h b/lib/uzlib/uzlib_conf.h new file mode 100644 index 0000000000..d6c9407157 --- /dev/null +++ b/lib/uzlib/uzlib_conf.h @@ -0,0 +1,22 @@ +/* + * uzlib - tiny deflate/inflate library (deflate, gzip, zlib) + * + * Copyright (c) 2014-2018 by Paul Sokolovsky + */ + +#ifndef UZLIB_CONF_H_INCLUDED +#define UZLIB_CONF_H_INCLUDED + +#ifndef UZLIB_CONF_DEBUG_LOG +/* Debug logging level 0, 1, 2, etc. */ +#define UZLIB_CONF_DEBUG_LOG 0 +#endif + +#ifndef UZLIB_CONF_PARANOID_CHECKS +/* Perform extra checks on the input stream, even if they aren't proven + to be strictly required (== lack of them wasn't proven to lead to + crashes). */ +#define UZLIB_CONF_PARANOID_CHECKS 0 +#endif + +#endif /* UZLIB_CONF_H_INCLUDED */ diff --git a/locale/ID.po b/locale/ID.po index e561abaa5f..e0941d05bd 100644 --- a/locale/ID.po +++ b/locale/ID.po @@ -560,6 +560,10 @@ msgstr "" msgid "Bit depth must be multiple of 8." msgstr "Kedalaman bit harus kelipatan 8." +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "" @@ -2523,10 +2527,6 @@ msgstr "__new__ arg harus berupa user-type" msgid "a bytes-like object is required" msgstr "sebuah objek menyerupai byte (bytes-like) dibutuhkan" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "abort() dipanggil" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "alamat di luar batas" @@ -3022,6 +3022,10 @@ msgstr "" msgid "division by zero" msgstr "" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "" + #: py/objdeque.c msgid "empty" msgstr "" @@ -3103,26 +3107,6 @@ msgstr "argumen keyword ekstra telah diberikan" msgid "extra positional arguments given" msgstr "argumen posisi ekstra telah diberikan" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3400,10 +3384,6 @@ msgstr "" msgid "invalid architecture" msgstr "" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "argumen-argumen tidak valid" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -4009,7 +3989,7 @@ msgid "queue overflow" msgstr "antrian meluap (overflow)" #: py/parse.c -msgid "raw f-strings are not implemented" +msgid "raw f-strings are not supported" msgstr "" #: extmod/ulab/code/numpy/fft/fft_tools.c @@ -4070,7 +4050,7 @@ msgstr "nilai sampling keluar dari jangkauan" msgid "schedule queue full" msgstr "" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "kompilasi script tidak didukung" @@ -4346,7 +4326,7 @@ msgid "unicode name escapes" msgstr "" #: py/parse.c -msgid "unindent does not match any outer indentation level" +msgid "unindent doesn't match any outer indent level" msgstr "" #: py/objstr.c @@ -4500,6 +4480,12 @@ msgstr "zi harus berjenis float" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "abort() called" +#~ msgstr "abort() dipanggil" + +#~ msgid "invalid arguments" +#~ msgstr "argumen-argumen tidak valid" + #~ msgid "%q list must be a list" #~ msgstr "daftar %q harus berupa daftar" diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 59fe6d91b8..75a340bbee 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -551,6 +551,10 @@ msgstr "" msgid "Bit depth must be multiple of 8." msgstr "" +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "" @@ -2485,10 +2489,6 @@ msgstr "" msgid "a bytes-like object is required" msgstr "" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "" @@ -2984,6 +2984,10 @@ msgstr "" msgid "division by zero" msgstr "" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "" + #: py/objdeque.c msgid "empty" msgstr "" @@ -3065,26 +3069,6 @@ msgstr "" msgid "extra positional arguments given" msgstr "" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3362,10 +3346,6 @@ msgstr "" msgid "invalid architecture" msgstr "" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -3970,7 +3950,7 @@ msgid "queue overflow" msgstr "" #: py/parse.c -msgid "raw f-strings are not implemented" +msgid "raw f-strings are not supported" msgstr "" #: extmod/ulab/code/numpy/fft/fft_tools.c @@ -4031,7 +4011,7 @@ msgstr "" msgid "schedule queue full" msgstr "" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "" @@ -4307,7 +4287,7 @@ msgid "unicode name escapes" msgstr "" #: py/parse.c -msgid "unindent does not match any outer indentation level" +msgid "unindent doesn't match any outer indent level" msgstr "" #: py/objstr.c diff --git a/locale/cs.po b/locale/cs.po index 92cced362b..2fd94df764 100644 --- a/locale/cs.po +++ b/locale/cs.po @@ -554,6 +554,10 @@ msgstr "" msgid "Bit depth must be multiple of 8." msgstr "" +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "" @@ -2484,10 +2488,6 @@ msgstr "" msgid "a bytes-like object is required" msgstr "" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "" @@ -2983,6 +2983,10 @@ msgstr "" msgid "division by zero" msgstr "" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "" + #: py/objdeque.c msgid "empty" msgstr "" @@ -3064,26 +3068,6 @@ msgstr "" msgid "extra positional arguments given" msgstr "" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3361,10 +3345,6 @@ msgstr "" msgid "invalid architecture" msgstr "" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -3969,7 +3949,7 @@ msgid "queue overflow" msgstr "" #: py/parse.c -msgid "raw f-strings are not implemented" +msgid "raw f-strings are not supported" msgstr "" #: extmod/ulab/code/numpy/fft/fft_tools.c @@ -4030,7 +4010,7 @@ msgstr "" msgid "schedule queue full" msgstr "" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "" @@ -4306,7 +4286,7 @@ msgid "unicode name escapes" msgstr "" #: py/parse.c -msgid "unindent does not match any outer indentation level" +msgid "unindent doesn't match any outer indent level" msgstr "" #: py/objstr.c diff --git a/locale/de_DE.po b/locale/de_DE.po index 12b8503a28..eb0f845325 100644 --- a/locale/de_DE.po +++ b/locale/de_DE.po @@ -562,6 +562,10 @@ msgstr "Bittiefe muss zwischen 1 und 6 liegen, nicht %d" msgid "Bit depth must be multiple of 8." msgstr "Bit depth muss ein Vielfaches von 8 sein." +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "Sowohl RX als auch TX sind zu Flusssteuerung erforderlich" @@ -2529,10 +2533,6 @@ msgstr "__new__ arg muss user-type sein" msgid "a bytes-like object is required" msgstr "ein Byte-ähnliches Objekt ist erforderlich" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "abort() wurde aufgerufen" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "Adresse außerhalb der Grenzen" @@ -3040,6 +3040,10 @@ msgstr "" msgid "division by zero" msgstr "Division durch Null" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "" + #: py/objdeque.c msgid "empty" msgstr "leer" @@ -3121,26 +3125,6 @@ msgstr "Es wurden zusätzliche Schlüsselwort-Argumente angegeben" msgid "extra positional arguments given" msgstr "Es wurden zusätzliche Argumente ohne Schlüsselwort angegeben" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "f-string expression Teil kann kein '#' beinhalten" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "Die f-String expression darf keinen Backslash enthalten" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "f-string: leere expression nicht erlaubt" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "f-string: erwartet '}'" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "f-string: einzelne '}' nicht erlaubt" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3420,10 +3404,6 @@ msgstr "Das Intervall muss im Bereich %s-%s sein" msgid "invalid architecture" msgstr "" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "ungültige argumente" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -4038,8 +4018,8 @@ msgid "queue overflow" msgstr "Warteschlangenüberlauf" #: py/parse.c -msgid "raw f-strings are not implemented" -msgstr "rohe F-Strings sind nicht implementiert" +msgid "raw f-strings are not supported" +msgstr "" #: extmod/ulab/code/numpy/fft/fft_tools.c msgid "real and imaginary parts must be of equal length" @@ -4101,7 +4081,7 @@ msgstr "Abtastrate außerhalb der Reichweite" msgid "schedule queue full" msgstr "" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "kompilieren von Skripten nicht unterstützt" @@ -4380,10 +4360,8 @@ msgid "unicode name escapes" msgstr "Unicode Name ausgebrochen (escaped)" #: py/parse.c -msgid "unindent does not match any outer indentation level" +msgid "unindent doesn't match any outer indent level" msgstr "" -"Einrückung entspricht keiner äußeren Einrückungsebene. Bitte Leerzeichen am " -"Zeilenanfang kontrollieren" #: py/objstr.c #, c-format @@ -4536,6 +4514,35 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "abort() called" +#~ msgstr "abort() wurde aufgerufen" + +#~ msgid "f-string expression part cannot include a '#'" +#~ msgstr "f-string expression Teil kann kein '#' beinhalten" + +#~ msgid "f-string expression part cannot include a backslash" +#~ msgstr "Die f-String expression darf keinen Backslash enthalten" + +#~ msgid "f-string: empty expression not allowed" +#~ msgstr "f-string: leere expression nicht erlaubt" + +#~ msgid "f-string: expecting '}'" +#~ msgstr "f-string: erwartet '}'" + +#~ msgid "f-string: single '}' is not allowed" +#~ msgstr "f-string: einzelne '}' nicht erlaubt" + +#~ msgid "invalid arguments" +#~ msgstr "ungültige argumente" + +#~ msgid "raw f-strings are not implemented" +#~ msgstr "rohe F-Strings sind nicht implementiert" + +#~ msgid "unindent does not match any outer indentation level" +#~ msgstr "" +#~ "Einrückung entspricht keiner äußeren Einrückungsebene. Bitte Leerzeichen " +#~ "am Zeilenanfang kontrollieren" + #~ msgid "%q list must be a list" #~ msgstr "%q Liste muss eine Liste sein" diff --git a/locale/el.po b/locale/el.po index 8aafbf5874..fe3ea79e41 100644 --- a/locale/el.po +++ b/locale/el.po @@ -551,6 +551,10 @@ msgstr "" msgid "Bit depth must be multiple of 8." msgstr "" +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "" @@ -2481,10 +2485,6 @@ msgstr "" msgid "a bytes-like object is required" msgstr "" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "" @@ -2980,6 +2980,10 @@ msgstr "" msgid "division by zero" msgstr "" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "" + #: py/objdeque.c msgid "empty" msgstr "" @@ -3061,26 +3065,6 @@ msgstr "" msgid "extra positional arguments given" msgstr "" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3358,10 +3342,6 @@ msgstr "" msgid "invalid architecture" msgstr "" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -3966,7 +3946,7 @@ msgid "queue overflow" msgstr "" #: py/parse.c -msgid "raw f-strings are not implemented" +msgid "raw f-strings are not supported" msgstr "" #: extmod/ulab/code/numpy/fft/fft_tools.c @@ -4027,7 +4007,7 @@ msgstr "" msgid "schedule queue full" msgstr "" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "" @@ -4303,7 +4283,7 @@ msgid "unicode name escapes" msgstr "" #: py/parse.c -msgid "unindent does not match any outer indentation level" +msgid "unindent doesn't match any outer indent level" msgstr "" #: py/objstr.c diff --git a/locale/en_GB.po b/locale/en_GB.po index 7df5afcf03..39e1d73f99 100644 --- a/locale/en_GB.po +++ b/locale/en_GB.po @@ -562,6 +562,10 @@ msgstr "Bit depth must be from 1 to 6 inclusive, not %d" msgid "Bit depth must be multiple of 8." msgstr "Bit depth must be multiple of 8." +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "Both RX and TX required for flow control" @@ -2520,10 +2524,6 @@ msgstr "__new__ arg must be a user-type" msgid "a bytes-like object is required" msgstr "a bytes-like object is required" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "abort() called" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "address out of bounds" @@ -3022,6 +3022,10 @@ msgstr "divide by zero" msgid "division by zero" msgstr "division by zero" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "" + #: py/objdeque.c msgid "empty" msgstr "empty" @@ -3103,26 +3107,6 @@ msgstr "extra keyword arguments given" msgid "extra positional arguments given" msgstr "extra positional arguments given" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "f-string expression part cannot include a '#'" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "f-string expression part cannot include a backslash" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "f-string: empty expression not allowed" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "f-string: expecting '}'" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "f-string: single '}' is not allowed" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3400,10 +3384,6 @@ msgstr "interval must be in range %s-%s" msgid "invalid architecture" msgstr "invalid architecture" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "invalid arguments" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -4008,8 +3988,8 @@ msgid "queue overflow" msgstr "queue overflow" #: py/parse.c -msgid "raw f-strings are not implemented" -msgstr "raw f-strings are not implemented" +msgid "raw f-strings are not supported" +msgstr "" #: extmod/ulab/code/numpy/fft/fft_tools.c msgid "real and imaginary parts must be of equal length" @@ -4071,7 +4051,7 @@ msgstr "sampling rate out of range" msgid "schedule queue full" msgstr "schedule queue full" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "script compilation not supported" @@ -4347,8 +4327,8 @@ msgid "unicode name escapes" msgstr "unicode name escapes" #: py/parse.c -msgid "unindent does not match any outer indentation level" -msgstr "unindent does not match any outer indentation level" +msgid "unindent doesn't match any outer indent level" +msgstr "" #: py/objstr.c #, c-format @@ -4501,6 +4481,33 @@ msgstr "zi must be of float type" msgid "zi must be of shape (n_section, 2)" msgstr "zi must be of shape (n_section, 2)" +#~ msgid "abort() called" +#~ msgstr "abort() called" + +#~ msgid "f-string expression part cannot include a '#'" +#~ msgstr "f-string expression part cannot include a '#'" + +#~ msgid "f-string expression part cannot include a backslash" +#~ msgstr "f-string expression part cannot include a backslash" + +#~ msgid "f-string: empty expression not allowed" +#~ msgstr "f-string: empty expression not allowed" + +#~ msgid "f-string: expecting '}'" +#~ msgstr "f-string: expecting '}'" + +#~ msgid "f-string: single '}' is not allowed" +#~ msgstr "f-string: single '}' is not allowed" + +#~ msgid "invalid arguments" +#~ msgstr "invalid arguments" + +#~ msgid "raw f-strings are not implemented" +#~ msgstr "raw f-strings are not implemented" + +#~ msgid "unindent does not match any outer indentation level" +#~ msgstr "unindent does not match any outer indentation level" + #~ msgid "%q list must be a list" #~ msgstr "%q list must be a list" diff --git a/locale/en_US.po b/locale/en_US.po index de9fa6347d..f17de07148 100644 --- a/locale/en_US.po +++ b/locale/en_US.po @@ -2943,7 +2943,7 @@ msgstr "" msgid "schedule stack full" msgstr "" -#: lib/utils/pyexec.c py/builtinimport.c +#: shared/runtime/pyexec.c py/builtinimport.c msgid "script compilation not supported" msgstr "" diff --git a/locale/en_x_pirate.po b/locale/en_x_pirate.po index 40b0b314c4..09ad3c890f 100644 --- a/locale/en_x_pirate.po +++ b/locale/en_x_pirate.po @@ -2950,7 +2950,7 @@ msgstr "" msgid "schedule stack full" msgstr "" -#: lib/utils/pyexec.c py/builtinimport.c +#: shared/runtime/pyexec.c py/builtinimport.c msgid "script compilation not supported" msgstr "" diff --git a/locale/es.po b/locale/es.po index 037d56889e..1eb113750a 100644 --- a/locale/es.po +++ b/locale/es.po @@ -566,6 +566,10 @@ msgstr "Bit depth tiene que ser de 1 a 6 inclusivo, no %d" msgid "Bit depth must be multiple of 8." msgstr "Bits depth debe ser múltiplo de 8." +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "Ambos RX y TX requeridos para control de flujo" @@ -2556,10 +2560,6 @@ msgstr "__new__ arg debe ser un user-type" msgid "a bytes-like object is required" msgstr "se requiere un objeto bytes-like" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "se llamó abort()" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "address fuera de límites" @@ -3062,6 +3062,10 @@ msgstr "divide por cero" msgid "division by zero" msgstr "división por cero" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "" + #: py/objdeque.c msgid "empty" msgstr "vacío" @@ -3143,26 +3147,6 @@ msgstr "argumento(s) por palabra clave adicionales fueron dados" msgid "extra positional arguments given" msgstr "argumento posicional adicional dado" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "La parte de expresión f-string no puede incluir un '#'" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "La parte de expresión f-string no puede incluir una barra invertida" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "cadena-f: expresión vacía no permitida" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "f-string: esperando '}'" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "cadena-f: solo '}' no está permitido" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3440,10 +3424,6 @@ msgstr "el intervalo debe ser der rango %s-%s" msgid "invalid architecture" msgstr "arquitectura inválida" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "argumentos inválidos" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -4055,8 +4035,8 @@ msgid "queue overflow" msgstr "desbordamiento de cola(queue)" #: py/parse.c -msgid "raw f-strings are not implemented" -msgstr "no está implementado cadenas-f sin procesar" +msgid "raw f-strings are not supported" +msgstr "" #: extmod/ulab/code/numpy/fft/fft_tools.c msgid "real and imaginary parts must be of equal length" @@ -4118,7 +4098,7 @@ msgstr "frecuencia de muestreo fuera de rango" msgid "schedule queue full" msgstr "cola de planificación llena" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "script de compilación no soportado" @@ -4395,8 +4375,8 @@ msgid "unicode name escapes" msgstr "nombre en unicode escapa" #: py/parse.c -msgid "unindent does not match any outer indentation level" -msgstr "sangría no coincide con ningún nivel exterior" +msgid "unindent doesn't match any outer indent level" +msgstr "" #: py/objstr.c #, c-format @@ -4549,6 +4529,33 @@ msgstr "zi debe ser de tipo flotante" msgid "zi must be of shape (n_section, 2)" msgstr "zi debe ser una forma (n_section,2)" +#~ msgid "abort() called" +#~ msgstr "se llamó abort()" + +#~ msgid "f-string expression part cannot include a '#'" +#~ msgstr "La parte de expresión f-string no puede incluir un '#'" + +#~ msgid "f-string expression part cannot include a backslash" +#~ msgstr "La parte de expresión f-string no puede incluir una barra invertida" + +#~ msgid "f-string: empty expression not allowed" +#~ msgstr "cadena-f: expresión vacía no permitida" + +#~ msgid "f-string: expecting '}'" +#~ msgstr "f-string: esperando '}'" + +#~ msgid "f-string: single '}' is not allowed" +#~ msgstr "cadena-f: solo '}' no está permitido" + +#~ msgid "invalid arguments" +#~ msgstr "argumentos inválidos" + +#~ msgid "raw f-strings are not implemented" +#~ msgstr "no está implementado cadenas-f sin procesar" + +#~ msgid "unindent does not match any outer indentation level" +#~ msgstr "sangría no coincide con ningún nivel exterior" + #~ msgid "%q list must be a list" #~ msgstr "%q lista debe ser una lista" diff --git a/locale/fil.po b/locale/fil.po index 98555ff294..14c59cf758 100644 --- a/locale/fil.po +++ b/locale/fil.po @@ -558,6 +558,10 @@ msgstr "" msgid "Bit depth must be multiple of 8." msgstr "Bit depth ay dapat multiple ng 8." +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "" @@ -2509,10 +2513,6 @@ msgstr "__new__ arg ay dapat na user-type" msgid "a bytes-like object is required" msgstr "a bytes-like object ay kailangan" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "abort() tinawag" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "wala sa sakop ang address" @@ -3019,6 +3019,10 @@ msgstr "" msgid "division by zero" msgstr "dibisyon ng zero" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "" + #: py/objdeque.c msgid "empty" msgstr "walang laman" @@ -3101,26 +3105,6 @@ msgstr "dagdag na keyword argument na ibinigay" msgid "extra positional arguments given" msgstr "dagdag na positional argument na ibinigay" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3399,10 +3383,6 @@ msgstr "" msgid "invalid architecture" msgstr "" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "mali ang mga argumento" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -4013,7 +3993,7 @@ msgid "queue overflow" msgstr "puno na ang pila (overflow)" #: py/parse.c -msgid "raw f-strings are not implemented" +msgid "raw f-strings are not supported" msgstr "" #: extmod/ulab/code/numpy/fft/fft_tools.c @@ -4076,7 +4056,7 @@ msgstr "pagpili ng rate wala sa sakop" msgid "schedule queue full" msgstr "" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "script kompilasyon hindi supportado" @@ -4354,8 +4334,8 @@ msgid "unicode name escapes" msgstr "unicode name escapes" #: py/parse.c -msgid "unindent does not match any outer indentation level" -msgstr "unindent hindi tugma sa indentation level sa labas" +msgid "unindent doesn't match any outer indent level" +msgstr "" #: py/objstr.c #, c-format @@ -4510,6 +4490,15 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "abort() called" +#~ msgstr "abort() tinawag" + +#~ msgid "invalid arguments" +#~ msgstr "mali ang mga argumento" + +#~ msgid "unindent does not match any outer indentation level" +#~ msgstr "unindent hindi tugma sa indentation level sa labas" + #, fuzzy #~ msgid "Expected a Characteristic" #~ msgstr "Hindi mabasa and Characteristic." diff --git a/locale/fr.po b/locale/fr.po index cfba937dbc..638ebdd1d6 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -568,6 +568,10 @@ msgstr "Bit depth doit être entre 1 et 6 inclusivement, et non %d" msgid "Bit depth must be multiple of 8." msgstr "La profondeur de bit doit être un multiple de 8." +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "RX et TX requis pour le contrôle de flux" @@ -2558,10 +2562,6 @@ msgstr "l'argument __new__ doit être d'un type défini par l'utilisateur" msgid "a bytes-like object is required" msgstr "un objet 'bytes-like' est requis" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "abort() appelé" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "adresse hors limites" @@ -3068,6 +3068,10 @@ msgstr "" msgid "division by zero" msgstr "division par zéro" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "" + #: py/objdeque.c msgid "empty" msgstr "vide" @@ -3149,28 +3153,6 @@ msgstr "argument(s) nommé(s) supplémentaire(s) donné(s)" msgid "extra positional arguments given" msgstr "argument(s) positionnel(s) supplémentaire(s) donné(s)" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "La partie d'expression de chaîne f ne peut pas inclure de '#'" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "" -"La partie d'expression de chaîne f ne peut pas inclure de barre oblique " -"inverse" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "f-string : expression vide non autorisée" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "f-string : attend '}'" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "f-string : single '}' n'est pas autorisé" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3449,10 +3431,6 @@ msgstr "interval doit être dans la portée %s-%s" msgid "invalid architecture" msgstr "architecture invalide" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "arguments invalides" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -4066,8 +4044,8 @@ msgid "queue overflow" msgstr "dépassement de file" #: py/parse.c -msgid "raw f-strings are not implemented" -msgstr "les chaînes f brutes ne sont pas implémentées" +msgid "raw f-strings are not supported" +msgstr "" #: extmod/ulab/code/numpy/fft/fft_tools.c msgid "real and imaginary parts must be of equal length" @@ -4129,7 +4107,7 @@ msgstr "taux d'échantillonage hors bornes" msgid "schedule queue full" msgstr "file de schédule pleine" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "compilation de script non supportée" @@ -4406,8 +4384,8 @@ msgid "unicode name escapes" msgstr "échappements de nom unicode" #: py/parse.c -msgid "unindent does not match any outer indentation level" -msgstr "la désindentation ne correspond à aucune indentation précédente" +msgid "unindent doesn't match any outer indent level" +msgstr "" #: py/objstr.c #, c-format @@ -4560,6 +4538,35 @@ msgstr "zi doit être de type float" msgid "zi must be of shape (n_section, 2)" msgstr "zi doit être de forme (n_section, 2)" +#~ msgid "abort() called" +#~ msgstr "abort() appelé" + +#~ msgid "f-string expression part cannot include a '#'" +#~ msgstr "La partie d'expression de chaîne f ne peut pas inclure de '#'" + +#~ msgid "f-string expression part cannot include a backslash" +#~ msgstr "" +#~ "La partie d'expression de chaîne f ne peut pas inclure de barre oblique " +#~ "inverse" + +#~ msgid "f-string: empty expression not allowed" +#~ msgstr "f-string : expression vide non autorisée" + +#~ msgid "f-string: expecting '}'" +#~ msgstr "f-string : attend '}'" + +#~ msgid "f-string: single '}' is not allowed" +#~ msgstr "f-string : single '}' n'est pas autorisé" + +#~ msgid "invalid arguments" +#~ msgstr "arguments invalides" + +#~ msgid "raw f-strings are not implemented" +#~ msgstr "les chaînes f brutes ne sont pas implémentées" + +#~ msgid "unindent does not match any outer indentation level" +#~ msgstr "la désindentation ne correspond à aucune indentation précédente" + #~ msgid "%q list must be a list" #~ msgstr "La liste %q doit être une liste" diff --git a/locale/hi.po b/locale/hi.po index 588aea7ac5..daf2cdb43a 100644 --- a/locale/hi.po +++ b/locale/hi.po @@ -551,6 +551,10 @@ msgstr "" msgid "Bit depth must be multiple of 8." msgstr "" +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "" @@ -2481,10 +2485,6 @@ msgstr "" msgid "a bytes-like object is required" msgstr "" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "" @@ -2980,6 +2980,10 @@ msgstr "" msgid "division by zero" msgstr "" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "" + #: py/objdeque.c msgid "empty" msgstr "" @@ -3061,26 +3065,6 @@ msgstr "" msgid "extra positional arguments given" msgstr "" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3358,10 +3342,6 @@ msgstr "" msgid "invalid architecture" msgstr "" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -3966,7 +3946,7 @@ msgid "queue overflow" msgstr "" #: py/parse.c -msgid "raw f-strings are not implemented" +msgid "raw f-strings are not supported" msgstr "" #: extmod/ulab/code/numpy/fft/fft_tools.c @@ -4027,7 +4007,7 @@ msgstr "" msgid "schedule queue full" msgstr "" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "" @@ -4303,7 +4283,7 @@ msgid "unicode name escapes" msgstr "" #: py/parse.c -msgid "unindent does not match any outer indentation level" +msgid "unindent doesn't match any outer indent level" msgstr "" #: py/objstr.c diff --git a/locale/it_IT.po b/locale/it_IT.po index 56b5820a85..31efc53249 100644 --- a/locale/it_IT.po +++ b/locale/it_IT.po @@ -566,6 +566,10 @@ msgstr "La profondità dei bit deve essere inclusiva da 1 a 6, non %d" msgid "Bit depth must be multiple of 8." msgstr "La profondità di bit deve essere un multiplo di 8." +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "Sia RX che TX richiedono il controllo del flow" @@ -2522,10 +2526,6 @@ msgstr "" msgid "a bytes-like object is required" msgstr "un oggetto byte-like è richiesto" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "abort() chiamato" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "indirizzo fuori limite" @@ -3030,6 +3030,10 @@ msgstr "" msgid "division by zero" msgstr "divisione per zero" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "" + #: py/objdeque.c msgid "empty" msgstr "vuoto" @@ -3112,26 +3116,6 @@ msgstr "argomento nominato aggiuntivo fornito" msgid "extra positional arguments given" msgstr "argomenti posizonali extra dati" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3410,10 +3394,6 @@ msgstr "" msgid "invalid architecture" msgstr "" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "argomenti non validi" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -4029,7 +4009,7 @@ msgid "queue overflow" msgstr "overflow della coda" #: py/parse.c -msgid "raw f-strings are not implemented" +msgid "raw f-strings are not supported" msgstr "" #: extmod/ulab/code/numpy/fft/fft_tools.c @@ -4092,7 +4072,7 @@ msgstr "frequenza di campionamento fuori intervallo" msgid "schedule queue full" msgstr "" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "compilazione dello scrip non suportata" @@ -4370,7 +4350,7 @@ msgid "unicode name escapes" msgstr "" #: py/parse.c -msgid "unindent does not match any outer indentation level" +msgid "unindent doesn't match any outer indent level" msgstr "" #: py/objstr.c @@ -4526,6 +4506,12 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "abort() called" +#~ msgstr "abort() chiamato" + +#~ msgid "invalid arguments" +#~ msgstr "argomenti non validi" + #~ msgid "%q list must be a list" #~ msgstr "lista %q deve essere una lista" diff --git a/locale/ja.po b/locale/ja.po index 728ee98c68..0c742748ad 100644 --- a/locale/ja.po +++ b/locale/ja.po @@ -558,6 +558,10 @@ msgstr "" msgid "Bit depth must be multiple of 8." msgstr "ビット深度は8の倍数でなければなりません" +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "フロー制御のためRXとTXの両方が必要" @@ -2496,10 +2500,6 @@ msgstr "__new__の引数はユーザ型でなければなりません" msgid "a bytes-like object is required" msgstr "bytes-likeオブジェクトが必要" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "abort()が呼ばれました" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "アドレスが範囲外" @@ -2999,6 +2999,10 @@ msgstr "" msgid "division by zero" msgstr "ゼロ除算 (division by zero)" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "" + #: py/objdeque.c msgid "empty" msgstr "" @@ -3080,26 +3084,6 @@ msgstr "余分なキーワード引数があります" msgid "extra positional arguments given" msgstr "余分な位置引数が与えられました" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "f-文字列の表現部は '#' を持てません" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "f-文字列の表現部はバックスラッシュを持てません" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "f-文字列: 空の表現は許されません" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "f-string: '}'が必要" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "f-string: 1つだけの'}'は許されません" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3378,10 +3362,6 @@ msgstr "intervalは%s-%sの範囲でなければなりません" msgid "invalid architecture" msgstr "" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "不正な引数" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -3988,8 +3968,8 @@ msgid "queue overflow" msgstr "キューがオーバーフローしました" #: py/parse.c -msgid "raw f-strings are not implemented" -msgstr "raw f-文字列は実装されていません" +msgid "raw f-strings are not supported" +msgstr "" #: extmod/ulab/code/numpy/fft/fft_tools.c msgid "real and imaginary parts must be of equal length" @@ -4050,7 +4030,7 @@ msgstr "サンプリングレートが範囲外" msgid "schedule queue full" msgstr "" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "スクリプトのコンパイルは非対応" @@ -4326,8 +4306,8 @@ msgid "unicode name escapes" msgstr "" #: py/parse.c -msgid "unindent does not match any outer indentation level" -msgstr "インデントの解除が、外側のどのインデントにも一致していません" +msgid "unindent doesn't match any outer indent level" +msgstr "" #: py/objstr.c #, c-format @@ -4480,6 +4460,33 @@ msgstr "ziはfloat値でなければなりません" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "abort() called" +#~ msgstr "abort()が呼ばれました" + +#~ msgid "f-string expression part cannot include a '#'" +#~ msgstr "f-文字列の表現部は '#' を持てません" + +#~ msgid "f-string expression part cannot include a backslash" +#~ msgstr "f-文字列の表現部はバックスラッシュを持てません" + +#~ msgid "f-string: empty expression not allowed" +#~ msgstr "f-文字列: 空の表現は許されません" + +#~ msgid "f-string: expecting '}'" +#~ msgstr "f-string: '}'が必要" + +#~ msgid "f-string: single '}' is not allowed" +#~ msgstr "f-string: 1つだけの'}'は許されません" + +#~ msgid "invalid arguments" +#~ msgstr "不正な引数" + +#~ msgid "raw f-strings are not implemented" +#~ msgstr "raw f-文字列は実装されていません" + +#~ msgid "unindent does not match any outer indentation level" +#~ msgstr "インデントの解除が、外側のどのインデントにも一致していません" + #~ msgid "%q list must be a list" #~ msgstr "%q リストはリストでなければなりません" diff --git a/locale/ko.po b/locale/ko.po index 49a79dbda6..59fb3978eb 100644 --- a/locale/ko.po +++ b/locale/ko.po @@ -554,6 +554,10 @@ msgstr "" msgid "Bit depth must be multiple of 8." msgstr "" +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "" @@ -2485,10 +2489,6 @@ msgstr "" msgid "a bytes-like object is required" msgstr "" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "" @@ -2984,6 +2984,10 @@ msgstr "" msgid "division by zero" msgstr "" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "" + #: py/objdeque.c msgid "empty" msgstr "" @@ -3065,26 +3069,6 @@ msgstr "" msgid "extra positional arguments given" msgstr "" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3362,10 +3346,6 @@ msgstr "" msgid "invalid architecture" msgstr "" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -3970,7 +3950,7 @@ msgid "queue overflow" msgstr "" #: py/parse.c -msgid "raw f-strings are not implemented" +msgid "raw f-strings are not supported" msgstr "" #: extmod/ulab/code/numpy/fft/fft_tools.c @@ -4031,7 +4011,7 @@ msgstr "" msgid "schedule queue full" msgstr "" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "" @@ -4307,7 +4287,7 @@ msgid "unicode name escapes" msgstr "" #: py/parse.c -msgid "unindent does not match any outer indentation level" +msgid "unindent doesn't match any outer indent level" msgstr "" #: py/objstr.c diff --git a/locale/nl.po b/locale/nl.po index 1a59aae9aa..3ea8b01790 100644 --- a/locale/nl.po +++ b/locale/nl.po @@ -556,6 +556,10 @@ msgstr "Bitdiepte moet tussen 1 en 6 liggen, niet %d" msgid "Bit depth must be multiple of 8." msgstr "Bit diepte moet een meervoud van 8 zijn." +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "RX en TX zijn beide vereist voor stroomregeling" @@ -2518,10 +2522,6 @@ msgstr "__new__ arg moet een user-type zijn" msgid "a bytes-like object is required" msgstr "een bytes-achtig object is vereist" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "abort() aangeroepen" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "adres buiten bereik" @@ -3021,6 +3021,10 @@ msgstr "" msgid "division by zero" msgstr "deling door nul" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "" + #: py/objdeque.c msgid "empty" msgstr "leeg" @@ -3102,26 +3106,6 @@ msgstr "extra keyword argumenten gegeven" msgid "extra positional arguments given" msgstr "extra positionele argumenten gegeven" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "f-string expressie deel kan geen '#' bevatten" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "f-string expressie deel kan geen backslash bevatten" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "f-string: lege expressie niet toegestaan" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "f-string: verwacht '}'" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "f-string: enkele '}' is niet toegestaan" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3400,10 +3384,6 @@ msgstr "interval moet binnen bereik %s-%s vallen" msgid "invalid architecture" msgstr "" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "ongeldige argumenten" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -4012,8 +3992,8 @@ msgid "queue overflow" msgstr "wachtrij overloop" #: py/parse.c -msgid "raw f-strings are not implemented" -msgstr "ruwe f-strings zijn niet geïmplementeerd" +msgid "raw f-strings are not supported" +msgstr "" #: extmod/ulab/code/numpy/fft/fft_tools.c msgid "real and imaginary parts must be of equal length" @@ -4075,7 +4055,7 @@ msgstr "bemonsteringssnelheid buiten bereik" msgid "schedule queue full" msgstr "" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "scriptcompilatie wordt niet ondersteund" @@ -4351,8 +4331,8 @@ msgid "unicode name escapes" msgstr "op naam gebaseerde unicode escapes zijn niet geïmplementeerd" #: py/parse.c -msgid "unindent does not match any outer indentation level" -msgstr "inspringing komt niet overeen met hoger gelegen inspringingsniveaus" +msgid "unindent doesn't match any outer indent level" +msgstr "" #: py/objstr.c #, c-format @@ -4505,6 +4485,33 @@ msgstr "zi moet van type float zijn" msgid "zi must be of shape (n_section, 2)" msgstr "zi moet vorm (n_section, 2) hebben" +#~ msgid "abort() called" +#~ msgstr "abort() aangeroepen" + +#~ msgid "f-string expression part cannot include a '#'" +#~ msgstr "f-string expressie deel kan geen '#' bevatten" + +#~ msgid "f-string expression part cannot include a backslash" +#~ msgstr "f-string expressie deel kan geen backslash bevatten" + +#~ msgid "f-string: empty expression not allowed" +#~ msgstr "f-string: lege expressie niet toegestaan" + +#~ msgid "f-string: expecting '}'" +#~ msgstr "f-string: verwacht '}'" + +#~ msgid "f-string: single '}' is not allowed" +#~ msgstr "f-string: enkele '}' is niet toegestaan" + +#~ msgid "invalid arguments" +#~ msgstr "ongeldige argumenten" + +#~ msgid "raw f-strings are not implemented" +#~ msgstr "ruwe f-strings zijn niet geïmplementeerd" + +#~ msgid "unindent does not match any outer indentation level" +#~ msgstr "inspringing komt niet overeen met hoger gelegen inspringingsniveaus" + #~ msgid "%q list must be a list" #~ msgstr "%q lijst moet een lijst zijn" diff --git a/locale/pl.po b/locale/pl.po index 5314be208b..623f72a89d 100644 --- a/locale/pl.po +++ b/locale/pl.po @@ -558,6 +558,10 @@ msgstr "" msgid "Bit depth must be multiple of 8." msgstr "Głębia musi być wielokrotnością 8." +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "Do kontroli przepływu wymagane są zarówno RX, jak i TX" @@ -2498,10 +2502,6 @@ msgstr "Argument __new__ musi być typu użytkownika" msgid "a bytes-like object is required" msgstr "wymagany obiekt typu bytes" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "Wywołano abort()" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "adres poza zakresem" @@ -2998,6 +2998,10 @@ msgstr "" msgid "division by zero" msgstr "dzielenie przez zero" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "" + #: py/objdeque.c msgid "empty" msgstr "puste" @@ -3079,26 +3083,6 @@ msgstr "nadmiarowe argumenty nazwane" msgid "extra positional arguments given" msgstr "nadmiarowe argumenty pozycyjne" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3376,10 +3360,6 @@ msgstr "interwał musi mieścić się w zakresie %s-%s" msgid "invalid architecture" msgstr "" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "złe arguemnty" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -3985,7 +3965,7 @@ msgid "queue overflow" msgstr "przepełnienie kolejki" #: py/parse.c -msgid "raw f-strings are not implemented" +msgid "raw f-strings are not supported" msgstr "" #: extmod/ulab/code/numpy/fft/fft_tools.c @@ -4047,7 +4027,7 @@ msgstr "częstotliwość próbkowania poza zakresem" msgid "schedule queue full" msgstr "" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "kompilowanie skryptów nieobsługiwane" @@ -4323,8 +4303,8 @@ msgid "unicode name escapes" msgstr "nazwy unicode" #: py/parse.c -msgid "unindent does not match any outer indentation level" -msgstr "wcięcie nie pasuje do żadnego wcześniejszego wcięcia" +msgid "unindent doesn't match any outer indent level" +msgstr "" #: py/objstr.c #, c-format @@ -4477,6 +4457,15 @@ msgstr "" msgid "zi must be of shape (n_section, 2)" msgstr "" +#~ msgid "abort() called" +#~ msgstr "Wywołano abort()" + +#~ msgid "invalid arguments" +#~ msgstr "złe arguemnty" + +#~ msgid "unindent does not match any outer indentation level" +#~ msgstr "wcięcie nie pasuje do żadnego wcześniejszego wcięcia" + #~ msgid "Column entry must be digitalio.DigitalInOut" #~ msgstr "Kolumny muszą być typu digitalio.DigitalInOut" diff --git a/locale/pt_BR.po b/locale/pt_BR.po index b1223a0bd1..cec87f2b5e 100644 --- a/locale/pt_BR.po +++ b/locale/pt_BR.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-10-08 16:30+0000\n" +"PO-Revision-Date: 2021-10-20 07:36+0000\n" "Last-Translator: Wellington Terumi Uemura \n" "Language-Team: \n" "Language: pt_BR\n" @@ -151,7 +151,7 @@ msgstr "%q deve estar entre %d e %d" #: py/argcheck.c msgid "%q must be of type %q" -msgstr "" +msgstr "%q deve ser do tipo %q" #: ports/atmel-samd/common-hal/busio/UART.c msgid "%q must be power of 2" @@ -569,6 +569,12 @@ msgstr "A profundidade dos bits deve ser de 1 até 6 inclusive, porém não %d" msgid "Bit depth must be multiple of 8." msgstr "A profundidade de bits deve ser o múltiplo de 8." +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "" +"O dispositivo de inicialização deve ser o primeiro dispositivo (interface " +"#0)." + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "Ambos os RX e TX são necessários para o controle do fluxo" @@ -2563,10 +2569,6 @@ msgstr "O argumento __new__ deve ser um tipo usuário" msgid "a bytes-like object is required" msgstr "é necessário objetos tipo bytes" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "abort() chamado" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "endereço fora dos limites" @@ -3071,6 +3073,10 @@ msgstr "divido por zero" msgid "division by zero" msgstr "divisão por zero" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "o divisor deve ser 4" + #: py/objdeque.c msgid "empty" msgstr "vazio" @@ -3152,26 +3158,6 @@ msgstr "argumentos extras de palavras-chave passados" msgid "extra positional arguments given" msgstr "argumentos extra posicionais passados" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "A parte da expressão f-string não pode incluir um '#'" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "A parte da expressão f-string não pode incluir uma barra invertida" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "f-string: expressão vazia não é permitida" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "f-string: esperando '}'" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "f-string: um único '}' não é permitido" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3450,10 +3436,6 @@ msgstr "o intervalo deve estar entre %s-%s" msgid "invalid architecture" msgstr "arquitetura inválida" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "argumentos inválidos" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -4068,8 +4050,8 @@ msgid "queue overflow" msgstr "estouro de fila" #: py/parse.c -msgid "raw f-strings are not implemented" -msgstr "o f-strings bruto não estão implementados" +msgid "raw f-strings are not supported" +msgstr "os f-strings brutos não são suportados" #: extmod/ulab/code/numpy/fft/fft_tools.c msgid "real and imaginary parts must be of equal length" @@ -4131,7 +4113,7 @@ msgstr "Taxa de amostragem fora do intervalo" msgid "schedule queue full" msgstr "fila de espera cheia" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "compilação de script não suportada" @@ -4407,8 +4389,8 @@ msgid "unicode name escapes" msgstr "escapar o nome unicode" #: py/parse.c -msgid "unindent does not match any outer indentation level" -msgstr "o unindent não coincide com nenhum nível de recuo externo" +msgid "unindent doesn't match any outer indent level" +msgstr "sem indentação não corresponde com nenhum nível de indentação exterior" #: py/objstr.c #, c-format @@ -4561,6 +4543,33 @@ msgstr "zi deve ser de um tipo float" msgid "zi must be of shape (n_section, 2)" msgstr "zi deve estar na forma (n_section, 2)" +#~ msgid "abort() called" +#~ msgstr "abort() chamado" + +#~ msgid "f-string expression part cannot include a '#'" +#~ msgstr "A parte da expressão f-string não pode incluir um '#'" + +#~ msgid "f-string expression part cannot include a backslash" +#~ msgstr "A parte da expressão f-string não pode incluir uma barra invertida" + +#~ msgid "f-string: empty expression not allowed" +#~ msgstr "f-string: expressão vazia não é permitida" + +#~ msgid "f-string: expecting '}'" +#~ msgstr "f-string: esperando '}'" + +#~ msgid "f-string: single '}' is not allowed" +#~ msgstr "f-string: um único '}' não é permitido" + +#~ msgid "invalid arguments" +#~ msgstr "argumentos inválidos" + +#~ msgid "raw f-strings are not implemented" +#~ msgstr "o f-strings bruto não estão implementados" + +#~ msgid "unindent does not match any outer indentation level" +#~ msgstr "o unindent não coincide com nenhum nível de recuo externo" + #~ msgid "%q list must be a list" #~ msgstr "A lista %q deve ser uma lista" diff --git a/locale/sv.po b/locale/sv.po index 0377b78f7c..1011bbe933 100644 --- a/locale/sv.po +++ b/locale/sv.po @@ -6,7 +6,7 @@ msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" "POT-Creation-Date: 2021-01-04 12:55-0600\n" -"PO-Revision-Date: 2021-10-11 09:40+0000\n" +"PO-Revision-Date: 2021-10-20 07:36+0000\n" "Last-Translator: Jonny Bergdahl \n" "Language-Team: LANGUAGE \n" "Language: sv\n" @@ -561,6 +561,10 @@ msgstr "Bitdjup måste vara inom 1 till 6, inte %d" msgid "Bit depth must be multiple of 8." msgstr "Bitdjup måste vara multipel av 8." +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "Startenheten måste vara den första enheten (gränssnitt #0)." + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "Både RX och TX krävs för handskakning" @@ -2533,10 +2537,6 @@ msgstr "__new__ arg måste vara en användartyp" msgid "a bytes-like object is required" msgstr "ett bytesliknande objekt krävs" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "abort() anropad" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "adress utanför gränsen" @@ -3037,6 +3037,10 @@ msgstr "division med noll" msgid "division by zero" msgstr "division med noll" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "divisor måste vara 4" + #: py/objdeque.c msgid "empty" msgstr "tom" @@ -3118,26 +3122,6 @@ msgstr "extra keyword-argument angivna" msgid "extra positional arguments given" msgstr "extra positions-argument angivna" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "f-stränguttrycksdelen kan inte innehålla en '#'" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "f-string-uttrycksdelen kan inte innehålla ett omvänt snedstreck" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "f-sträng: tomt uttryck inte tillåten" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "f-string: förväntat '}'" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "f-string: singel '}' är inte tillåten" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3415,10 +3399,6 @@ msgstr "interval måste vara i intervallet %s-%s" msgid "invalid architecture" msgstr "ogiltig arkitektur" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "ogiltiga argument" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -4027,8 +4007,8 @@ msgid "queue overflow" msgstr "köstorlek överskreds" #: py/parse.c -msgid "raw f-strings are not implemented" -msgstr "råa f-strängar inte implementerade" +msgid "raw f-strings are not supported" +msgstr "råa f-strängar stöds inte" #: extmod/ulab/code/numpy/fft/fft_tools.c msgid "real and imaginary parts must be of equal length" @@ -4090,7 +4070,7 @@ msgstr "samplingsfrekvens utanför räckvidden" msgid "schedule queue full" msgstr "schemakön full" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "skriptkompilering stöds inte" @@ -4366,8 +4346,8 @@ msgid "unicode name escapes" msgstr "unicode-namn flyr" #: py/parse.c -msgid "unindent does not match any outer indentation level" -msgstr "indentering inte matchar någon yttre indenteringsnivå" +msgid "unindent doesn't match any outer indent level" +msgstr "avindentering matchar inte någon yttre indentering" #: py/objstr.c #, c-format @@ -4520,6 +4500,33 @@ msgstr "zi måste vara av typ float" msgid "zi must be of shape (n_section, 2)" msgstr "zi måste vara i formen (n_section, 2)" +#~ msgid "abort() called" +#~ msgstr "abort() anropad" + +#~ msgid "f-string expression part cannot include a '#'" +#~ msgstr "f-stränguttrycksdelen kan inte innehålla en '#'" + +#~ msgid "f-string expression part cannot include a backslash" +#~ msgstr "f-string-uttrycksdelen kan inte innehålla ett omvänt snedstreck" + +#~ msgid "f-string: empty expression not allowed" +#~ msgstr "f-sträng: tomt uttryck inte tillåten" + +#~ msgid "f-string: expecting '}'" +#~ msgstr "f-string: förväntat '}'" + +#~ msgid "f-string: single '}' is not allowed" +#~ msgstr "f-string: singel '}' är inte tillåten" + +#~ msgid "invalid arguments" +#~ msgstr "ogiltiga argument" + +#~ msgid "raw f-strings are not implemented" +#~ msgstr "råa f-strängar inte implementerade" + +#~ msgid "unindent does not match any outer indentation level" +#~ msgstr "indentering inte matchar någon yttre indenteringsnivå" + #~ msgid "%q list must be a list" #~ msgstr "%q-listan måste vara en lista" diff --git a/locale/zh_Latn_pinyin.po b/locale/zh_Latn_pinyin.po index dc59f7be20..2775f10c5f 100644 --- a/locale/zh_Latn_pinyin.po +++ b/locale/zh_Latn_pinyin.po @@ -563,6 +563,10 @@ msgstr "wèi shēn dù bì xū bāo hán 1 dào 6, ér bù shì %d" msgid "Bit depth must be multiple of 8." msgstr "Bǐtè shēndù bìxū shì 8 bèi yǐshàng." +#: supervisor/shared/safe_mode.c +msgid "Boot device must be first device (interface #0)." +msgstr "" + #: ports/mimxrt10xx/common-hal/busio/UART.c msgid "Both RX and TX required for flow control" msgstr "liú liàng kòng zhì suǒ xū de RX hé TX" @@ -2535,10 +2539,6 @@ msgstr "__new__ cānshù bìxū shì yònghù lèixíng" msgid "a bytes-like object is required" msgstr "xūyào yīgè zì jié lèi duìxiàng" -#: lib/embed/abort_.c -msgid "abort() called" -msgstr "abort() diàoyòng" - #: shared-bindings/i2cperipheral/I2CPeripheral.c msgid "address out of bounds" msgstr "dìzhǐ chāochū biānjiè" @@ -3040,6 +3040,10 @@ msgstr "chú yǐ líng" msgid "division by zero" msgstr "bèi líng chú" +#: ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +msgid "divisor must be 4" +msgstr "" + #: py/objdeque.c msgid "empty" msgstr "kòngxián" @@ -3121,26 +3125,6 @@ msgstr "éwài de guānjiàn cí cānshù" msgid "extra positional arguments given" msgstr "gěi chūle éwài de wèizhì cānshù" -#: py/parse.c -msgid "f-string expression part cannot include a '#'" -msgstr "f-string biǎodá shì bùfèn bùnéng bāohán '#'" - -#: py/parse.c -msgid "f-string expression part cannot include a backslash" -msgstr "f-string biǎodá shì bùfèn bùnéng bāohán fǎn xié gāng" - -#: py/parse.c -msgid "f-string: empty expression not allowed" -msgstr "f-string: bù yǔnxǔ shǐyòng kōng biǎodá shì" - -#: py/parse.c -msgid "f-string: expecting '}'" -msgstr "f-string: qídài '}'" - -#: py/parse.c -msgid "f-string: single '}' is not allowed" -msgstr "f-string: bù yǔnxǔ shǐyòng dāngè '}'" - #: shared-bindings/audiocore/WaveFile.c shared-bindings/audiomp3/MP3Decoder.c #: shared-bindings/displayio/OnDiskBitmap.c shared-bindings/synthio/__init__.c msgid "file must be a file opened in byte mode" @@ -3418,10 +3402,6 @@ msgstr "Jiàngé bìxū zài %s-%s fànwéi nèi" msgid "invalid architecture" msgstr "wú xiào de jià gòu" -#: lib/netutils/netutils.c -msgid "invalid arguments" -msgstr "wúxiào de cānshù" - #: shared-bindings/bitmaptools/__init__.c #, c-format msgid "invalid bits_per_pixel %d, must be, 1, 2, 4, 8, 16, 24, or 32" @@ -4027,8 +4007,8 @@ msgid "queue overflow" msgstr "duìliè yìchū" #: py/parse.c -msgid "raw f-strings are not implemented" -msgstr "wèi zhíxíng yuánshǐ f-strings" +msgid "raw f-strings are not supported" +msgstr "" #: extmod/ulab/code/numpy/fft/fft_tools.c msgid "real and imaginary parts must be of equal length" @@ -4090,7 +4070,7 @@ msgstr "qǔyàng lǜ chāochū fànwéi" msgid "schedule queue full" msgstr "shí jiān biǎo duì liè yǐ mǎn" -#: lib/utils/pyexec.c py/builtinimport.c +#: py/builtinimport.c msgid "script compilation not supported" msgstr "bù zhīchí jiǎoběn biānyì" @@ -4366,8 +4346,8 @@ msgid "unicode name escapes" msgstr "unicode míngchēng táoyì" #: py/parse.c -msgid "unindent does not match any outer indentation level" -msgstr "bùsuō jìn yǔ rènhé wàibù suō jìn jíbié dōu bù pǐpèi" +msgid "unindent doesn't match any outer indent level" +msgstr "" #: py/objstr.c #, c-format @@ -4520,6 +4500,33 @@ msgstr "zi bìxū wèi fú diǎn xíng" msgid "zi must be of shape (n_section, 2)" msgstr "zi bìxū jùyǒu xíngzhuàng (n_section,2)" +#~ msgid "abort() called" +#~ msgstr "abort() diàoyòng" + +#~ msgid "f-string expression part cannot include a '#'" +#~ msgstr "f-string biǎodá shì bùfèn bùnéng bāohán '#'" + +#~ msgid "f-string expression part cannot include a backslash" +#~ msgstr "f-string biǎodá shì bùfèn bùnéng bāohán fǎn xié gāng" + +#~ msgid "f-string: empty expression not allowed" +#~ msgstr "f-string: bù yǔnxǔ shǐyòng kōng biǎodá shì" + +#~ msgid "f-string: expecting '}'" +#~ msgstr "f-string: qídài '}'" + +#~ msgid "f-string: single '}' is not allowed" +#~ msgstr "f-string: bù yǔnxǔ shǐyòng dāngè '}'" + +#~ msgid "invalid arguments" +#~ msgstr "wúxiào de cānshù" + +#~ msgid "raw f-strings are not implemented" +#~ msgstr "wèi zhíxíng yuánshǐ f-strings" + +#~ msgid "unindent does not match any outer indentation level" +#~ msgstr "bùsuō jìn yǔ rènhé wàibù suō jìn jíbié dōu bù pǐpèi" + #~ msgid "%q list must be a list" #~ msgstr "%q lièbiǎo bìxū shì lièbiǎo" diff --git a/main.c b/main.c index 2f39b0eb37..9f3bead9c2 100755 --- a/main.c +++ b/main.c @@ -40,8 +40,8 @@ #include "py/gc.h" #include "py/stackctrl.h" -#include "lib/mp-readline/readline.h" -#include "lib/utils/pyexec.h" +#include "shared/readline/readline.h" +#include "shared/runtime/pyexec.h" #include "background.h" #include "mpconfigboard.h" diff --git a/mpy-cross/Makefile.static-mingw b/mpy-cross/Makefile.static-mingw index f5bc861779..bcd2b6a9f2 100644 --- a/mpy-cross/Makefile.static-mingw +++ b/mpy-cross/Makefile.static-mingw @@ -2,7 +2,7 @@ # # SPDX-License-Identifier: MIT -PROG=mpy-cross.static.exe +PROG=mpy-cross.static CROSS_COMPILE = x86_64-w64-mingw32- BUILD=build-static-mingw STATIC_BUILD=1 diff --git a/mpy-cross/gccollect.c b/mpy-cross/gccollect.c index 2172bb36b7..79c47f3b68 100644 --- a/mpy-cross/gccollect.c +++ b/mpy-cross/gccollect.c @@ -8,7 +8,7 @@ #include "py/mpstate.h" #include "py/gc.h" -#include "lib/utils/gchelper.h" +#include "shared/runtime/gchelper.h" #if MICROPY_ENABLE_GC diff --git a/mpy-cross/mpconfigport.h b/mpy-cross/mpconfigport.h index aacfeabdda..50c77a1186 100644 --- a/mpy-cross/mpconfigport.h +++ b/mpy-cross/mpconfigport.h @@ -41,7 +41,9 @@ #define MICROPY_READER_POSIX (1) #define MICROPY_ENABLE_RUNTIME (0) #define MICROPY_ENABLE_GC (1) +#ifndef __EMSCRIPTEN__ #define MICROPY_STACK_CHECK (1) +#endif #define MICROPY_HELPER_LEXER_UNIX (1) #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) #define MICROPY_ENABLE_SOURCE_LINE (1) @@ -54,6 +56,7 @@ #define MICROPY_PY_ASYNC_AWAIT (1) #define MICROPY_USE_INTERNAL_PRINTF (0) +#define MICROPY_PY_FSTRINGS (1) #define MICROPY_PY_BUILTINS_STR_UNICODE (1) #if !(defined(MICROPY_GCREGS_SETJMP) || defined(__x86_64__) || defined(__i386__) || defined(__thumb2__) || defined(__thumb__) || defined(__arm__)) diff --git a/mpy-cross/mpy-cross.mk b/mpy-cross/mpy-cross.mk index f84afef1da..642fe9b5aa 100644 --- a/mpy-cross/mpy-cross.mk +++ b/mpy-cross/mpy-cross.mk @@ -69,7 +69,7 @@ endif SRC_C += \ main.c \ gccollect.c \ - lib/utils/gchelper_generic.c \ + shared/runtime/gchelper_generic.c \ supervisor/stub/safe_mode.c \ supervisor/stub/stack.c \ supervisor/shared/translate.c diff --git a/mpy-cross/mpy-cross.vcxproj b/mpy-cross/mpy-cross.vcxproj index 7151ab5e99..e70b29ae14 100644 --- a/mpy-cross/mpy-cross.vcxproj +++ b/mpy-cross/mpy-cross.vcxproj @@ -89,7 +89,7 @@ - + MICROPY_GCREGS_SETJMP diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index 810d86581b..7b61bae267 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -60,7 +60,7 @@ HAL_DIR=hal/$(MCU_SERIES) INC += -I. \ -I../.. \ -I../lib/mp-readline \ - -I../lib/timeutils \ + -I../shared/timeutils \ -Iasf4/$(CHIP_FAMILY) \ -Iasf4/$(CHIP_FAMILY)/hal/include \ -Iasf4/$(CHIP_FAMILY)/hal/utils/include \ @@ -364,11 +364,11 @@ OBJ += $(addprefix $(BUILD)/, $(SRC_MOD:.c=.o)) SRC_QSTR += $(HEADER_BUILD)/sdiodata.h $(HEADER_BUILD)/sdiodata.h: tools/mksdiodata.py | $(HEADER_BUILD) - $(Q)$(PYTHON3) $< > $@ + $(Q)$(PYTHON) $< > $@ SRC_QSTR += $(HEADER_BUILD)/candata.h $(HEADER_BUILD)/candata.h: tools/mkcandata.py | $(HEADER_BUILD) - $(Q)$(PYTHON3) $< > $@ + $(Q)$(PYTHON) $< > $@ SRC_QSTR += $(SRC_C) $(SRC_SUPERVISOR) $(SRC_COMMON_HAL_EXPANDED) $(SRC_SHARED_MODULE_EXPANDED) # Sources that only hold QSTRs after pre-processing. @@ -380,7 +380,7 @@ $(BUILD)/firmware.elf: $(OBJ) $(GENERATED_LD_FILE) $(STEPECHO) "LINK $@" $(Q)echo $(OBJ) > $(BUILD)/firmware.objs $(Q)$(CC) -o $@ $(LDFLAGS) @$(BUILD)/firmware.objs -Wl,--start-group $(LIBS) -Wl,--end-group - $(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(GENERATED_LD_FILE) + $(Q)$(SIZE) $@ | $(PYTHON) $(TOP)/tools/build_memory_info.py $(GENERATED_LD_FILE) $(BUILD)/firmware.bin: $(BUILD)/firmware.elf $(STEPECHO) "Create $@" @@ -388,7 +388,7 @@ $(BUILD)/firmware.bin: $(BUILD)/firmware.elf $(BUILD)/firmware.uf2: $(BUILD)/firmware.bin $(STEPECHO) "Create $@" - $(Q)$(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -b $(BOOTLOADER_SIZE) -c -o $@ $^ + $(Q)$(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -b $(BOOTLOADER_SIZE) -c -o $@ $^ include $(TOP)/py/mkrules.mk diff --git a/ports/atmel-samd/audio_dma.c b/ports/atmel-samd/audio_dma.c index d7ec9dcd07..4dbb0a0006 100644 --- a/ports/atmel-samd/audio_dma.c +++ b/ports/atmel-samd/audio_dma.c @@ -396,7 +396,7 @@ STATIC void dma_callback_fun(void *arg) { } } -void audio_evsys_handler(void) { +void audio_dma_evsys_handler(void) { for (uint8_t i = 0; i < AUDIO_DMA_CHANNEL_COUNT; i++) { audio_dma_t *dma = audio_dma_state[i]; if (dma == NULL) { diff --git a/ports/atmel-samd/audio_dma.h b/ports/atmel-samd/audio_dma.h index 0b5f35c71b..cc41b0ae78 100644 --- a/ports/atmel-samd/audio_dma.h +++ b/ports/atmel-samd/audio_dma.h @@ -101,6 +101,6 @@ void audio_dma_background(void); uint8_t find_sync_event_channel_raise(void); -void audio_evsys_handler(void); +void audio_dma_evsys_handler(void); #endif // MICROPY_INCLUDED_ATMEL_SAMD_AUDIO_DMA_H diff --git a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c index 6ea70e39dc..e00d69c848 100644 --- a/ports/atmel-samd/common-hal/audiobusio/PDMIn.c +++ b/ports/atmel-samd/common-hal/audiobusio/PDMIn.c @@ -35,6 +35,7 @@ #include "common-hal/audiobusio/PDMIn.h" #include "shared-bindings/analogio/AnalogOut.h" #include "shared-bindings/audiobusio/PDMIn.h" +#include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" #include "supervisor/shared/translate.h" @@ -64,7 +65,20 @@ #define SERCTRL(name) I2S_RXCTRL_ ## name #endif +// Set by interrupt handler when DMA block has finished transferring. +static bool pdmin_dma_block_done; +// Event channel used to trigger interrupt. Set to invalid value EVSYS_SYNCH_NUM when not in use. +static uint8_t pdmin_event_channel; + +void pdmin_evsys_handler(void) { + if (pdmin_event_channel < EVSYS_SYNCH_NUM && event_interrupt_active(pdmin_event_channel)) { + pdmin_dma_block_done = true; + } +} + void pdmin_reset(void) { + pdmin_event_channel = EVSYS_SYNCH_NUM; + while (I2S->SYNCBUSY.reg & I2S_SYNCBUSY_ENABLE) {} I2S->INTENCLR.reg = I2S_INTENCLR_MASK; I2S->INTFLAG.reg = I2S_INTFLAG_MASK; @@ -368,7 +382,8 @@ static uint16_t filter_sample(uint32_t pdm_samples[4]) { uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* self, uint16_t* output_buffer, uint32_t output_buffer_length) { uint8_t dma_channel = dma_allocate_channel(); - uint8_t event_channel = find_sync_event_channel_raise(); + pdmin_event_channel = find_sync_event_channel_raise(); + pdmin_dma_block_done = false; // We allocate two buffers on the stack to use for double buffering. const uint8_t samples_per_buffer = SAMPLES_PER_BUFFER; @@ -391,7 +406,7 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se #endif dma_configure(dma_channel, trigger_source, true); - init_event_channel_interrupt(event_channel, CORE_GCLK, EVSYS_ID_GEN_DMAC_CH_0 + dma_channel); + init_event_channel_interrupt(pdmin_event_channel, CORE_GCLK, EVSYS_ID_GEN_DMAC_CH_0 + dma_channel); // Turn on serializer now to get it in sync with DMA. i2s_set_serializer_enable(self->serializer, true); audio_dma_enable_channel(dma_channel); @@ -402,23 +417,12 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se uint32_t remaining_samples_needed = output_buffer_length; while (values_output < output_buffer_length) { - if (event_interrupt_overflow(event_channel)) { - // Looks like we aren't keeping up. We shouldn't skip a buffer so stop early. - break; - } - // Wait for the next buffer to fill - uint32_t wait_counts = 0; - #ifdef SAMD21 - #define MAX_WAIT_COUNTS 1000 - #endif - #ifdef SAM_D5X_E5X - #define MAX_WAIT_COUNTS 6000 - #endif - // If wait_counts exceeds the max count, buffer has probably stopped filling; - // DMA may have missed an I2S trigger event. - while (!event_interrupt_active(event_channel) && ++wait_counts < MAX_WAIT_COUNTS) { + while (!pdmin_dma_block_done) { RUN_BACKGROUND_TASKS; } + common_hal_mcu_disable_interrupts(); + pdmin_dma_block_done = false; + common_hal_mcu_enable_interrupts(); // The mic is running all the time, so we don't need to wait the usual 10msec or 100msec // for it to start up. @@ -430,6 +434,7 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se buffer = second_buffer; descriptor = &second_descriptor; } + // Decimate and filter the buffer that was just filled. uint32_t samples_gathered = descriptor->BTCNT.reg / words_per_sample; // Don't run off the end of output buffer. Process only as many as needed. @@ -472,7 +477,8 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se } } - disable_event_channel(event_channel); + disable_event_channel(pdmin_event_channel); + pdmin_event_channel = EVSYS_SYNCH_NUM; // Invalid event_channel. dma_free_channel(dma_channel); // Turn off serializer, but leave clock on, to avoid mic startup delay. i2s_set_serializer_enable(self->serializer, false); @@ -481,5 +487,4 @@ uint32_t common_hal_audiobusio_pdmin_record_to_buffer(audiobusio_pdmin_obj_t* se } void common_hal_audiobusio_pdmin_record_to_file(audiobusio_pdmin_obj_t* self, uint8_t* buffer, uint32_t length) { - } diff --git a/ports/atmel-samd/common-hal/audiobusio/PDMIn.h b/ports/atmel-samd/common-hal/audiobusio/PDMIn.h index 5c4d4feea0..7f00886d29 100644 --- a/ports/atmel-samd/common-hal/audiobusio/PDMIn.h +++ b/ports/atmel-samd/common-hal/audiobusio/PDMIn.h @@ -46,6 +46,8 @@ typedef struct { void pdmin_reset(void); +void pdmin_evsys_handler(void); + void pdmin_background(void); #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_AUDIOBUSIO_AUDIOOUT_H diff --git a/ports/atmel-samd/common-hal/busio/I2C.c b/ports/atmel-samd/common-hal/busio/I2C.c index 39aa6c9e97..7d77c0d43a 100644 --- a/ports/atmel-samd/common-hal/busio/I2C.c +++ b/ports/atmel-samd/common-hal/busio/I2C.c @@ -36,7 +36,7 @@ #include "shared-bindings/microcontroller/__init__.h" #include "supervisor/shared/translate.h" -#include "common-hal/busio/SPI.h" // for never_reset_sercom +#include "common-hal/busio/__init__.h" // Number of times to try to send packet if failed. #define ATTEMPTS 2 diff --git a/ports/atmel-samd/common-hal/busio/SPI.c b/ports/atmel-samd/common-hal/busio/SPI.c index 884c3e0414..3b60c1d2b4 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.c +++ b/ports/atmel-samd/common-hal/busio/SPI.c @@ -32,7 +32,9 @@ #include "peripheral_clk_config.h" #include "supervisor/board.h" +#include "common-hal/busio/__init__.h" #include "common-hal/microcontroller/Pin.h" + #include "hal/include/hal_gpio.h" #include "hal/include/hal_spi_m_sync.h" #include "hal/include/hpl_spi_m_sync.h" @@ -40,43 +42,6 @@ #include "samd/dma.h" #include "samd/sercom.h" -bool never_reset_sercoms[SERCOM_INST_NUM]; - -void never_reset_sercom(Sercom *sercom) { - // Reset all SERCOMs except the ones being used by on-board devices. - Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS; - for (int i = 0; i < SERCOM_INST_NUM; i++) { - if (sercom_instances[i] == sercom) { - never_reset_sercoms[i] = true; - break; - } - } -} - -void allow_reset_sercom(Sercom *sercom) { - // Reset all SERCOMs except the ones being used by on-board devices. - Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS; - for (int i = 0; i < SERCOM_INST_NUM; i++) { - if (sercom_instances[i] == sercom) { - never_reset_sercoms[i] = false; - break; - } - } -} - -void reset_sercoms(void) { - // Reset all SERCOMs except the ones being used by on-board devices. - Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS; - for (int i = 0; i < SERCOM_INST_NUM; i++) { - if (never_reset_sercoms[i]) { - continue; - } - // SWRST is same for all modes of SERCOMs. - sercom_instances[i]->SPI.CTRLA.bit.SWRST = 1; - } -} - - void common_hal_busio_spi_construct(busio_spi_obj_t *self, const mcu_pin_obj_t *clock, const mcu_pin_obj_t *mosi, const mcu_pin_obj_t *miso) { diff --git a/ports/atmel-samd/common-hal/busio/SPI.h b/ports/atmel-samd/common-hal/busio/SPI.h index 27bbfdeb3a..2fced6d642 100644 --- a/ports/atmel-samd/common-hal/busio/SPI.h +++ b/ports/atmel-samd/common-hal/busio/SPI.h @@ -42,8 +42,4 @@ typedef struct { uint8_t MISO_pin; } busio_spi_obj_t; -void reset_sercoms(void); -void never_reset_sercom(Sercom *sercom); - - #endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_SPI_H diff --git a/ports/atmel-samd/common-hal/busio/UART.c b/ports/atmel-samd/common-hal/busio/UART.c index c33bf6f440..194f1c0217 100644 --- a/ports/atmel-samd/common-hal/busio/UART.c +++ b/ports/atmel-samd/common-hal/busio/UART.c @@ -28,7 +28,7 @@ #include "shared-bindings/busio/UART.h" #include "mpconfigport.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/gc.h" #include "py/mperrno.h" #include "py/runtime.h" @@ -45,7 +45,7 @@ #include "samd/sercom.h" -#include "common-hal/busio/SPI.h" // for never_reset_sercom +#include "common-hal/busio/__init__.h" #define UART_DEBUG(...) (void)0 // #define UART_DEBUG(...) mp_printf(&mp_plat_print __VA_OPT__(,) __VA_ARGS__) diff --git a/ports/atmel-samd/common-hal/busio/__init__.c b/ports/atmel-samd/common-hal/busio/__init__.c index 41761b6743..8ec549e931 100644 --- a/ports/atmel-samd/common-hal/busio/__init__.c +++ b/ports/atmel-samd/common-hal/busio/__init__.c @@ -1 +1,63 @@ -// No busio module functions. +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "samd/sercom.h" + +static bool never_reset_sercoms[SERCOM_INST_NUM]; + +void never_reset_sercom(Sercom *sercom) { + // Reset all SERCOMs except the ones being used by on-board devices. + Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS; + for (int i = 0; i < SERCOM_INST_NUM; i++) { + if (sercom_instances[i] == sercom) { + never_reset_sercoms[i] = true; + break; + } + } +} + +void allow_reset_sercom(Sercom *sercom) { + // Reset all SERCOMs except the ones being used by on-board devices. + Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS; + for (int i = 0; i < SERCOM_INST_NUM; i++) { + if (sercom_instances[i] == sercom) { + never_reset_sercoms[i] = false; + break; + } + } +} + +void reset_sercoms(void) { + // Reset all SERCOMs except the ones being used by on-board devices. + Sercom *sercom_instances[SERCOM_INST_NUM] = SERCOM_INSTS; + for (int i = 0; i < SERCOM_INST_NUM; i++) { + if (never_reset_sercoms[i]) { + continue; + } + // SWRST is same for all modes of SERCOMs. + sercom_instances[i]->SPI.CTRLA.bit.SWRST = 1; + } +} diff --git a/ports/atmel-samd/common-hal/busio/__init__.h b/ports/atmel-samd/common-hal/busio/__init__.h new file mode 100644 index 0000000000..ded88f113d --- /dev/null +++ b/ports/atmel-samd/common-hal/busio/__init__.h @@ -0,0 +1,35 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2016 Scott Shawcroft + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_INIT_H +#define MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_INIT_H + +void reset_sercoms(void); +void allow_reset_sercom(Sercom *sercom); +void never_reset_sercom(Sercom *sercom); + + +#endif // MICROPY_INCLUDED_ATMEL_SAMD_COMMON_HAL_BUSIO_INIT_H diff --git a/ports/atmel-samd/common-hal/canio/Listener.c b/ports/atmel-samd/common-hal/canio/Listener.c index ce09764757..e171ae5193 100644 --- a/ports/atmel-samd/common-hal/canio/Listener.c +++ b/ports/atmel-samd/common-hal/canio/Listener.c @@ -30,7 +30,7 @@ #include "py/obj.h" #include "py/runtime.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "common-hal/canio/__init__.h" #include "common-hal/canio/Listener.h" diff --git a/ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.c b/ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.c index 961fde8439..e1849a6b15 100644 --- a/ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.c +++ b/ports/atmel-samd/common-hal/i2cperipheral/I2CPeripheral.c @@ -27,7 +27,7 @@ #include "shared-bindings/i2cperipheral/I2CPeripheral.h" #include "common-hal/busio/I2C.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/mperrno.h" #include "py/mphal.h" #include "py/runtime.h" diff --git a/ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c b/ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c index f3284f0c32..acc172fa22 100644 --- a/ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c +++ b/ports/atmel-samd/common-hal/imagecapture/ParallelImageCapture.c @@ -27,8 +27,8 @@ #include "py/obj.h" #include "py/runtime.h" -#include "lib/utils/context_manager_helpers.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/context_manager_helpers.h" +#include "shared/runtime/interrupt_char.h" #include "shared-bindings/imagecapture/ParallelImageCapture.h" #include "shared-bindings/microcontroller/__init__.h" diff --git a/ports/atmel-samd/common-hal/microcontroller/__init__.c b/ports/atmel-samd/common-hal/microcontroller/__init__.c index 751f4dcab7..983af7a647 100644 --- a/ports/atmel-samd/common-hal/microcontroller/__init__.c +++ b/ports/atmel-samd/common-hal/microcontroller/__init__.c @@ -103,6 +103,17 @@ const nvm_bytearray_obj_t common_hal_mcu_nvm_obj = { }; #endif +#if CIRCUITPY_WATCHDOG +// The singleton watchdog.WatchDogTimer object. +watchdog_watchdogtimer_obj_t common_hal_mcu_watchdogtimer_obj = { + .base = { + .type = &watchdog_watchdogtimer_type, + }, + .timeout = 0.0f, + .mode = WATCHDOGMODE_NONE, +}; +#endif + // This maps MCU pin names to pin objects. STATIC const mp_rom_map_elem_t mcu_pin_global_dict_table[] = { #if defined(PIN_PA00) && !defined(IGNORE_PIN_PA00) diff --git a/ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c b/ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c index 2a30142ab3..dc9cf65334 100644 --- a/ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c +++ b/ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.c @@ -67,7 +67,7 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode set_eic_channel_data(self->eic_channel_b, (void *)self); self->position = 0; - self->quarter_count = 0; + self->sub_count = 0; shared_module_softencoder_state_init(self, ((uint8_t)gpio_get_pin_level(self->pin_a) << 1) | diff --git a/ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.h b/ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.h index 2560997a97..f9223ddc7c 100644 --- a/ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.h +++ b/ports/atmel-samd/common-hal/rotaryio/IncrementalEncoder.h @@ -38,7 +38,8 @@ typedef struct { uint8_t eic_channel_a; uint8_t eic_channel_b; uint8_t state; // - int8_t quarter_count; // count intermediate transitions between detents + int8_t sub_count; // count intermediate transitions between detents + int8_t divisor; // Number of quadrature edges required per count mp_int_t position; } rotaryio_incrementalencoder_obj_t; diff --git a/ports/atmel-samd/common-hal/rtc/RTC.c b/ports/atmel-samd/common-hal/rtc/RTC.c index 3517f31aa5..65d7d94220 100644 --- a/ports/atmel-samd/common-hal/rtc/RTC.c +++ b/ports/atmel-samd/common-hal/rtc/RTC.c @@ -33,7 +33,7 @@ #include "py/obj.h" #include "py/runtime.h" -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" #include "shared-bindings/rtc/__init__.h" #include "supervisor/port.h" #include "supervisor/shared/translate.h" diff --git a/ports/atmel-samd/common-hal/watchdog/WatchDogMode.c b/ports/atmel-samd/common-hal/watchdog/WatchDogMode.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ports/atmel-samd/common-hal/watchdog/WatchDogTimer.c b/ports/atmel-samd/common-hal/watchdog/WatchDogTimer.c new file mode 100644 index 0000000000..29ac643d1c --- /dev/null +++ b/ports/atmel-samd/common-hal/watchdog/WatchDogTimer.c @@ -0,0 +1,105 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2021 Jeff Epler for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include + +#include "py/runtime.h" + +#include "shared-bindings/watchdog/__init__.h" +#include "shared-bindings/watchdog/WatchDogTimer.h" +#include "common-hal/watchdog/WatchDogTimer.h" + +#include "component/wdt.h" + +void common_hal_watchdog_feed(watchdog_watchdogtimer_obj_t *self) { + WDT->CLEAR.reg = WDT_CLEAR_CLEAR_KEY; +} + +void common_hal_watchdog_deinit(watchdog_watchdogtimer_obj_t *self) { + if (self->mode == WATCHDOGMODE_RESET) { + mp_raise_RuntimeError(translate("WatchDogTimer cannot be deinitialized once mode is set to RESET")); + } else { + self->mode = WATCHDOGMODE_NONE; + } +} + +mp_float_t common_hal_watchdog_get_timeout(watchdog_watchdogtimer_obj_t *self) { + return self->timeout; +} + +void setup_wdt(watchdog_watchdogtimer_obj_t *self, int setting) { + OSC32KCTRL->OSCULP32K.bit.EN1K = 1; // Enable out 1K (for WDT) + + // disable watchdog for config + WDT->CTRLA.reg = 0; + while (WDT->SYNCBUSY.reg) { // Sync CTRL write + } + + WDT->INTENCLR.bit.EW = 1; // Disable early warning interrupt + WDT->CONFIG.bit.PER = setting; // Set period for chip reset + WDT->CTRLA.bit.WEN = 0; // Disable window mode + while (WDT->SYNCBUSY.reg) { // Sync CTRL write + } + common_hal_watchdog_feed(self); // Clear watchdog interval + WDT->CTRLA.bit.ENABLE = 1; // Start watchdog now! + while (WDT->SYNCBUSY.reg) { + } +} + +void common_hal_watchdog_set_timeout(watchdog_watchdogtimer_obj_t *self, mp_float_t new_timeout) { + int wdt_cycles = (int)(new_timeout * 1000); + if (wdt_cycles < 8) { + wdt_cycles = 8; + } + if (wdt_cycles > 16384) { + mp_raise_ValueError(translate("timeout duration exceeded the maximum supported value")); + } + // ceil(log2(n)) = 32 - __builtin_clz(n - 1) when n > 1 (if int is 32 bits) + int log2_wdt_cycles = (sizeof(int) * CHAR_BIT) - __builtin_clz(wdt_cycles - 1); + int setting = log2_wdt_cycles - 3; // CYC8_Val is 0 + float timeout = (8 << setting) / 1024.f; + + if (self->mode == WATCHDOGMODE_RESET) { + setup_wdt(self, setting); + } + self->timeout = timeout; +} + +watchdog_watchdogmode_t common_hal_watchdog_get_mode(watchdog_watchdogtimer_obj_t *self) { + return self->mode; +} + +void common_hal_watchdog_set_mode(watchdog_watchdogtimer_obj_t *self, watchdog_watchdogmode_t new_mode) { + if (self->mode != new_mode) { + if (new_mode == WATCHDOGMODE_RAISE) { + mp_raise_NotImplementedError(translate("RAISE mode is not implemented")); + } else if (new_mode == WATCHDOGMODE_NONE) { + common_hal_watchdog_deinit(self); + } + self->mode = new_mode; + common_hal_watchdog_set_timeout(self, self->timeout); + } +} diff --git a/ports/atmel-samd/common-hal/watchdog/WatchDogTimer.h b/ports/atmel-samd/common-hal/watchdog/WatchDogTimer.h new file mode 100644 index 0000000000..ce34f0b8ab --- /dev/null +++ b/ports/atmel-samd/common-hal/watchdog/WatchDogTimer.h @@ -0,0 +1,43 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 microDev + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_WATCHDOG_WATCHDOGTIMER_H +#define MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_WATCHDOG_WATCHDOGTIMER_H + +#include "py/obj.h" +#include "shared-bindings/watchdog/WatchDogMode.h" +#include "shared-bindings/watchdog/WatchDogTimer.h" + +struct _watchdog_watchdogtimer_obj_t { + mp_obj_base_t base; + mp_float_t timeout; + watchdog_watchdogmode_t mode; +}; + +// This needs to be called in order to disable the watchdog +// void watchdog_reset(void); + +#endif // MICROPY_INCLUDED_RASPBERRYPI_COMMON_HAL_WATCHDOG_WATCHDOGTIMER_H diff --git a/ports/atmel-samd/common-hal/watchdog/__init__.c b/ports/atmel-samd/common-hal/watchdog/__init__.c new file mode 100644 index 0000000000..e69de29bb2 diff --git a/ports/atmel-samd/fatfs_port.c b/ports/atmel-samd/fatfs_port.c index e6eee20495..58a0ef0d72 100644 --- a/ports/atmel-samd/fatfs_port.c +++ b/ports/atmel-samd/fatfs_port.c @@ -28,7 +28,7 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" /* FatFs lower layer API */ #include "lib/oofatfs/diskio.h" /* FatFs lower layer API */ -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" #if CIRCUITPY_RTC #include "shared-bindings/rtc/RTC.h" diff --git a/ports/atmel-samd/mpconfigport.mk b/ports/atmel-samd/mpconfigport.mk index d8773e5c88..818c9f111a 100644 --- a/ports/atmel-samd/mpconfigport.mk +++ b/ports/atmel-samd/mpconfigport.mk @@ -104,6 +104,7 @@ CIRCUITPY_PS2IO ?= 1 CIRCUITPY_SAMD ?= 1 CIRCUITPY_RGBMATRIX ?= $(CIRCUITPY_FULL_BUILD) CIRCUITPY_FRAMEBUFFERIO ?= $(CIRCUITPY_FULL_BUILD) +CIRCUITPY_WATCHDOG ?= 1 endif # samd51 ###################################################################### diff --git a/ports/atmel-samd/mphalport.c b/ports/atmel-samd/mphalport.c index 5ebce1a857..e196312ca3 100644 --- a/ports/atmel-samd/mphalport.c +++ b/ports/atmel-samd/mphalport.c @@ -26,8 +26,8 @@ #include -#include "lib/mp-readline/readline.h" -#include "lib/utils/interrupt_char.h" +#include "shared/readline/readline.h" +#include "shared/runtime/interrupt_char.h" #include "py/mphal.h" #include "py/mpstate.h" #include "py/runtime.h" diff --git a/ports/atmel-samd/supervisor/port.c b/ports/atmel-samd/supervisor/port.c index 9980baa4df..d2211d4c8f 100644 --- a/ports/atmel-samd/supervisor/port.c +++ b/ports/atmel-samd/supervisor/port.c @@ -53,18 +53,42 @@ #error Unknown chip family #endif +#if CIRCUITPY_ANALOGIO #include "common-hal/analogio/AnalogIn.h" #include "common-hal/analogio/AnalogOut.h" +#endif + +#if CIRCUITPY_AUDIOBUSIO #include "common-hal/audiobusio/PDMIn.h" #include "common-hal/audiobusio/I2SOut.h" +#endif + +#if CIRCUITPY_AUDIOIO #include "common-hal/audioio/AudioOut.h" -#include "common-hal/busio/SPI.h" +#endif + +#if CIRCUITPY_BUSIO +#include "common-hal/busio/__init__.h" +#endif + #include "common-hal/microcontroller/Pin.h" + +#if CIRCUITPY_PULSEIO #include "common-hal/pulseio/PulseIn.h" #include "common-hal/pulseio/PulseOut.h" +#endif + +#if CIRCUITPY_PWMIO #include "common-hal/pwmio/PWMOut.h" +#endif + +#if CIRCUITPY_PS2IO #include "common-hal/ps2io/Ps2.h" +#endif + +#if CIRCUITPY_RTC #include "common-hal/rtc/RTC.h" +#endif #if CIRCUITPY_ALARM #include "common-hal/alarm/__init__.h" @@ -538,8 +562,13 @@ void evsyshandler_common(void) { supervisor_tick(); } #endif + #if CIRCUITPY_AUDIOIO || CIRCUITPY_AUDIOBUSIO - audio_evsys_handler(); + audio_dma_evsys_handler(); + #endif + + #if CIRCUITPY_AUDIOBUSIO + pdmin_evsys_handler(); #endif } diff --git a/ports/cxd56/Makefile b/ports/cxd56/Makefile index 73c9fe5822..073d2d59ce 100644 --- a/ports/cxd56/Makefile +++ b/ports/cxd56/Makefile @@ -89,7 +89,7 @@ INC += \ -I. \ -I../.. \ -I../lib/mp-readline \ - -I../lib/timeutils \ + -I../shared/timeutils \ -I../../lib/tinyusb/src \ -I../../supervisor/shared/usb \ -Iboards/$(BOARD) \ diff --git a/ports/cxd56/fatfs_port.c b/ports/cxd56/fatfs_port.c index a58465b983..e672b095b7 100644 --- a/ports/cxd56/fatfs_port.c +++ b/ports/cxd56/fatfs_port.c @@ -28,7 +28,7 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" /* FatFs lower layer API */ #include "lib/oofatfs/diskio.h" /* FatFs lower layer API */ -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" #if CIRCUITPY_RTC #include "shared-bindings/rtc/RTC.h" diff --git a/ports/cxd56/mphalport.h b/ports/cxd56/mphalport.h index ba5ca39b97..3327b523fa 100644 --- a/ports/cxd56/mphalport.h +++ b/ports/cxd56/mphalport.h @@ -29,7 +29,7 @@ #include -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "supervisor/shared/tick.h" #define mp_hal_ticks_ms() ((mp_uint_t)supervisor_ticks_ms32()) diff --git a/ports/espressif/Makefile b/ports/espressif/Makefile index c26f2ebffb..9a928b40f4 100644 --- a/ports/espressif/Makefile +++ b/ports/espressif/Makefile @@ -218,7 +218,7 @@ SRC_C += \ boards/$(BOARD)/board.c \ boards/$(BOARD)/pins.c \ modules/$(CIRCUITPY_MODULE).c \ - lib/netutils/netutils.c \ + shared/netutils/netutils.c \ peripherals/i2c.c \ peripherals/rmt.c \ peripherals/timer.c \ @@ -400,14 +400,14 @@ $(BUILD)/firmware.elf: $(OBJ) | esp-idf-stamp $(BUILD)/circuitpython-firmware.bin: $(BUILD)/firmware.elf | tools/build_memory_info.py $(STEPECHO) "Create $@" $(Q)esptool.py --chip $(IDF_TARGET) elf2image $(FLASH_FLAGS) --elf-sha256-offset 0xb0 -o $@ $^ - $(Q)$(PYTHON3) tools/build_memory_info.py $< $(BUILD)/esp-idf/sdkconfig $@ + $(Q)$(PYTHON) tools/build_memory_info.py $< $(BUILD)/esp-idf/sdkconfig $@ $(BUILD)/firmware.bin: $(BUILD)/circuitpython-firmware.bin | esp-idf-stamp $(Q)$(PYTHON) ../../tools/join_bins.py $@ $(BOOTLOADER_OFFSET) $(BUILD)/esp-idf/bootloader/bootloader.bin $(PARTITION_TABLE_OFFSET) $(BUILD)/esp-idf/partition_table/partition-table.bin $(FIRMWARE_OFFSET) $(BUILD)/circuitpython-firmware.bin $(BUILD)/firmware.uf2: $(BUILD)/circuitpython-firmware.bin $(STEPECHO) "Create $@" - $(Q)$(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -f 0xbfdd4eee -b 0x0000 -c -o $@ $^ + $(Q)$(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f 0xbfdd4eee -b 0x0000 -c -o $@ $^ flash: $(BUILD)/firmware.bin esptool.py --chip $(IDF_TARGET) -p $(PORT) $(ESPTOOL_FLAGS) write_flash $(FLASH_FLAGS) 0x0000 $^ diff --git a/ports/espressif/boards/lolin_s2_mini/pins.c b/ports/espressif/boards/lolin_s2_mini/pins.c index c73149597d..a4b18c4e9b 100644 --- a/ports/espressif/boards/lolin_s2_mini/pins.c +++ b/ports/espressif/boards/lolin_s2_mini/pins.c @@ -86,5 +86,6 @@ STATIC const mp_rom_map_elem_t board_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_IO45), MP_ROM_PTR(&pin_GPIO45) },// GPIO45 { MP_ROM_QSTR(MP_QSTR_IO46), MP_ROM_PTR(&pin_GPIO46) },// GPIO46 */ + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, // board singleton implicit from schematic/shield standard }; MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/lolin_s2_pico/board.c b/ports/espressif/boards/lolin_s2_pico/board.c new file mode 100644 index 0000000000..a0e399b1ef --- /dev/null +++ b/ports/espressif/boards/lolin_s2_pico/board.c @@ -0,0 +1,61 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2020 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#include "supervisor/board.h" +#include "mpconfigboard.h" +#include "shared-bindings/microcontroller/Pin.h" + +void board_init(void) { + // USB + common_hal_never_reset_pin(&pin_GPIO19); + common_hal_never_reset_pin(&pin_GPIO20); + + // Debug UART + #ifdef DEBUG + common_hal_never_reset_pin(&pin_GPIO43); + common_hal_never_reset_pin(&pin_GPIO44); + #endif /* DEBUG */ + + // SPI Flash and RAM + common_hal_never_reset_pin(&pin_GPIO26); + common_hal_never_reset_pin(&pin_GPIO27); + common_hal_never_reset_pin(&pin_GPIO28); + common_hal_never_reset_pin(&pin_GPIO29); + common_hal_never_reset_pin(&pin_GPIO30); + common_hal_never_reset_pin(&pin_GPIO31); + common_hal_never_reset_pin(&pin_GPIO32); +} + +bool board_requests_safe_mode(void) { + return false; +} + +void reset_board(void) { + +} + +void board_deinit(void) { +} diff --git a/ports/espressif/boards/lolin_s2_pico/mpconfigboard.h b/ports/espressif/boards/lolin_s2_pico/mpconfigboard.h new file mode 100644 index 0000000000..408b15ac16 --- /dev/null +++ b/ports/espressif/boards/lolin_s2_pico/mpconfigboard.h @@ -0,0 +1,42 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2019 Scott Shawcroft for Adafruit Industries + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +// Micropython setup + +#define MICROPY_HW_BOARD_NAME "S2Pico" +#define MICROPY_HW_MCU_NAME "ESP32S2-S2FN4R2" // from Wemos MP + +#define CIRCUITPY_BOOT_BUTTON (&pin_GPIO0) +#define BOARD_USER_SAFE_MODE_ACTION translate("pressing boot button at start up.\n") + +#define AUTORESET_DELAY_MS 500 + +#define DEFAULT_I2C_BUS_SCL (&pin_GPIO9) // JST SH Connector Pin 3 NOT STEMMA QT / Feather pinout +#define DEFAULT_I2C_BUS_SDA (&pin_GPIO8) // JST SH Connector Pin 2 NOT STEMMA QT / Feather pinout + +#define DEFAULT_SPI_BUS_SCK (&pin_GPIO36) // no SPI labels on S2 Pico, def from schematic +#define DEFAULT_SPI_BUS_MOSI (&pin_GPIO35) // no SPI labels on S2 Pico, def from schematic +#define DEFAULT_SPI_BUS_MISO (&pin_GPIO37) // no SPI labels on S2 Pico, def from schematic diff --git a/ports/espressif/boards/lolin_s2_pico/mpconfigboard.mk b/ports/espressif/boards/lolin_s2_pico/mpconfigboard.mk new file mode 100644 index 0000000000..b060be0261 --- /dev/null +++ b/ports/espressif/boards/lolin_s2_pico/mpconfigboard.mk @@ -0,0 +1,21 @@ +USB_VID = 0x303A +USB_PID = 0x80C6 +USB_PRODUCT = "S2 Pico" +USB_MANUFACTURER = "Lolin" + +IDF_TARGET = esp32s2 + +INTERNAL_FLASH_FILESYSTEM = 1 +LONGINT_IMPL = MPZ + +# The default queue depth of 16 overflows on release builds, +# so increase it to 32. +CFLAGS += -DCFG_TUD_TASK_QUEUE_SZ=32 + +CIRCUITPY_ESP_FLASH_MODE=qio +CIRCUITPY_ESP_FLASH_FREQ=80m +CIRCUITPY_ESP_FLASH_SIZE=4MB + + +# Include these Python libraries in firmware. +FROZEN_MPY_DIRS += $(TOP)/frozen/Adafruit_CircuitPython_NeoPixel diff --git a/ports/espressif/boards/lolin_s2_pico/pins.c b/ports/espressif/boards/lolin_s2_pico/pins.c new file mode 100644 index 0000000000..5c3f1f4db5 --- /dev/null +++ b/ports/espressif/boards/lolin_s2_pico/pins.c @@ -0,0 +1,56 @@ +#include "shared-bindings/board/__init__.h" + +STATIC const mp_rom_map_elem_t board_module_globals_table[] = { + CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS + + // Not broken out - Button + { MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) }, // RTC_GPIO0,GPIO0 + + // S2 Pico Board top, left, top-bottom + { MP_ROM_QSTR(MP_QSTR_IO1), MP_ROM_PTR(&pin_GPIO1) }, // RTC_GPIO1,GPIO1,TOUCH1,ADC1_CH0 + { MP_ROM_QSTR(MP_QSTR_IO2), MP_ROM_PTR(&pin_GPIO2) }, // RTC_GPIO2,GPIO2,TOUCH2,ADC1_CH1 + { MP_ROM_QSTR(MP_QSTR_IO3), MP_ROM_PTR(&pin_GPIO3) }, // RTC_GPIO3,GPIO3,TOUCH3,ADC1_CH2 + { MP_ROM_QSTR(MP_QSTR_IO4), MP_ROM_PTR(&pin_GPIO4) }, // RTC_GPIO4,GPIO4,TOUCH4,ADC1_CH3 + { MP_ROM_QSTR(MP_QSTR_IO5), MP_ROM_PTR(&pin_GPIO5) }, // RTC_GPIO5,GPIO5,TOUCH5,ADC1_CH4 + { MP_ROM_QSTR(MP_QSTR_IO6), MP_ROM_PTR(&pin_GPIO6) }, // RTC_GPIO6,GPIO6,TOUCH6,ADC1_CH5 + { MP_ROM_QSTR(MP_QSTR_IO7), MP_ROM_PTR(&pin_GPIO7) }, // RTC_GPIO7,GPIO7,TOUCH7,ADC1_CH6 + + // JST SH Connector + { MP_ROM_QSTR(MP_QSTR_IO8), MP_ROM_PTR(&pin_GPIO8) }, // RTC_GPIO8,GPIO8,TOUCH8,ADC1_CH7 + { MP_ROM_QSTR(MP_QSTR_IO9), MP_ROM_PTR(&pin_GPIO9) }, // RTC_GPIO8,GPIO8,TOUCH8,ADC1_CH7 + + // Not broken out - LED + { MP_ROM_QSTR(MP_QSTR_IO10), MP_ROM_PTR(&pin_GPIO10) },// RTC_GPIO10,GPIO10,TOUCH10,ADC1_CH9,FSPICS0,FSPIIO4 + + // S2 Pico Board top, right, bottom-top + { MP_ROM_QSTR(MP_QSTR_IO11), MP_ROM_PTR(&pin_GPIO11) },// RTC_GPIO11,GPIO11,TOUCH11,ADC2_CH0,FSPID,FSPIIO5 + { MP_ROM_QSTR(MP_QSTR_IO12), MP_ROM_PTR(&pin_GPIO12) },// RTC_GPIO12,GPIO12,TOUCH12,ADC2_CH1,FSPICLK,FSPIIO6 + { MP_ROM_QSTR(MP_QSTR_IO13), MP_ROM_PTR(&pin_GPIO13) },// RTC_GPIO13,GPIO13,TOUCH13,ADC2_CH2,FSPIQ,FSPIIO7 + { MP_ROM_QSTR(MP_QSTR_IO14), MP_ROM_PTR(&pin_GPIO14) },// RTC_GPIO14,GPIO14,TOUCH14,ADC2_CH3,FSPIWP,FSPIDQS + { MP_ROM_QSTR(MP_QSTR_IO15), MP_ROM_PTR(&pin_GPIO15) },// XTAL_32K_P: RTC_GPIO15,GPIO15,U0RTS,ADC2_CH4,XTAL_32K_P + { MP_ROM_QSTR(MP_QSTR_IO16), MP_ROM_PTR(&pin_GPIO16) },// XTAL_32K_N: RTC_GPIO16,GPIO16,U0CTS,ADC2_CH5,XTAL_32K_N + { MP_ROM_QSTR(MP_QSTR_IO17), MP_ROM_PTR(&pin_GPIO17) },// DAC_1: RTC_GPIO17,GPIO17,U1TXD,ADC2_CH6,DAC_1 + + // Not broken out - SSD1306 reset + { MP_ROM_QSTR(MP_QSTR_IO18), MP_ROM_PTR(&pin_GPIO18) },// DAC_2: RTC_GPIO18,GPIO18,U1RXD,ADC2_CH7,DAC_2,CLK_OUT3 + + { MP_ROM_QSTR(MP_QSTR_IO21), MP_ROM_PTR(&pin_GPIO21) },// RTC_GPIO21,GPIO21 + { MP_ROM_QSTR(MP_QSTR_IO33), MP_ROM_PTR(&pin_GPIO33) },// SPIIO4,GPIO33,FSPIHD + { MP_ROM_QSTR(MP_QSTR_IO34), MP_ROM_PTR(&pin_GPIO34) },// SPIIO5,GPIO34,FSPICS0 + { MP_ROM_QSTR(MP_QSTR_IO35), MP_ROM_PTR(&pin_GPIO35) },// SPIIO6,GPIO35,FSPID + { MP_ROM_QSTR(MP_QSTR_IO36), MP_ROM_PTR(&pin_GPIO36) },// SPIIO7,GPIO36,FSPICLK + { MP_ROM_QSTR(MP_QSTR_IO37), MP_ROM_PTR(&pin_GPIO37) },// SPIDQS,GPIO37,FSPIQ + { MP_ROM_QSTR(MP_QSTR_IO38), MP_ROM_PTR(&pin_GPIO38) },// GPIO38,FSPIWP + + { MP_ROM_QSTR(MP_QSTR_BUTTON), MP_ROM_PTR(&pin_GPIO0) }, + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO10) }, + { MP_ROM_QSTR(MP_QSTR_SDA), MP_ROM_PTR(&pin_GPIO8) }, + { MP_ROM_QSTR(MP_QSTR_SCL), MP_ROM_PTR(&pin_GPIO9) }, + { MP_ROM_QSTR(MP_QSTR_LCD_RST), MP_ROM_PTR(&pin_GPIO18) }, + { MP_ROM_QSTR(MP_QSTR_SS), MP_ROM_PTR(&pin_GPIO34) }, // Not labelled on booard, on schematic + { MP_ROM_QSTR(MP_QSTR_MOSI), MP_ROM_PTR(&pin_GPIO35) },// Not labelled on booard, on schematic + { MP_ROM_QSTR(MP_QSTR_SCK), MP_ROM_PTR(&pin_GPIO36) }, // Not labelled on booard, on schematic + { MP_ROM_QSTR(MP_QSTR_MISO), MP_ROM_PTR(&pin_GPIO37) },// Not labelled on booard, on schematic + { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&board_i2c_obj) }, +}; +MP_DEFINE_CONST_DICT(board_module_globals, board_module_globals_table); diff --git a/ports/espressif/boards/lolin_s2_pico/sdkconfig b/ports/espressif/boards/lolin_s2_pico/sdkconfig new file mode 100644 index 0000000000..36e83d7fb5 --- /dev/null +++ b/ports/espressif/boards/lolin_s2_pico/sdkconfig @@ -0,0 +1,39 @@ +CONFIG_ESP32S2_SPIRAM_SUPPORT=y + +# +# SPI RAM config +# +# CONFIG_SPIRAM_TYPE_AUTO=y +CONFIG_SPIRAM_TYPE_ESPPSRAM16=y +# CONFIG_SPIRAM_TYPE_ESPPSRAM32 is not set +# CONFIG_SPIRAM_TYPE_ESPPSRAM64=y +CONFIG_SPIRAM_SIZE=2097152 + +# +# PSRAM clock and cs IO for ESP32S2 +# +CONFIG_DEFAULT_PSRAM_CLK_IO=30 +CONFIG_DEFAULT_PSRAM_CS_IO=26 +# end of PSRAM clock and cs IO for ESP32S2 + +# CONFIG_SPIRAM_FETCH_INSTRUCTIONS is not set +# CONFIG_SPIRAM_RODATA is not set +# CONFIG_SPIRAM_SPEED_80M=y +CONFIG_SPIRAM_SPEED_40M=y +# CONFIG_SPIRAM_SPEED_26M is not set +# CONFIG_SPIRAM_SPEED_20M is not set +CONFIG_SPIRAM=y +CONFIG_SPIRAM_BOOT_INIT=y +# CONFIG_SPIRAM_IGNORE_NOTFOUND is not set +CONFIG_SPIRAM_USE_MEMMAP=y +# CONFIG_SPIRAM_USE_CAPS_ALLOC is not set +# CONFIG_SPIRAM_USE_MALLOC is not set +CONFIG_SPIRAM_MEMTEST=y +# CONFIG_SPIRAM_ALLOW_BSS_SEG_EXTERNAL_MEMORY is not set +# end of SPI RAM config + +# +# LWIP +# +CONFIG_LWIP_LOCAL_HOSTNAME="Lolin-S2Pico" +# end of LWIP diff --git a/ports/espressif/common-hal/busio/UART.c b/ports/espressif/common-hal/busio/UART.c index 52cf5cfa3b..5aac1635af 100644 --- a/ports/espressif/common-hal/busio/UART.c +++ b/ports/espressif/common-hal/busio/UART.c @@ -30,7 +30,7 @@ #include "components/driver/include/driver/uart.h" #include "mpconfigport.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/gc.h" #include "py/mperrno.h" #include "py/runtime.h" diff --git a/ports/espressif/common-hal/imagecapture/ParallelImageCapture.c b/ports/espressif/common-hal/imagecapture/ParallelImageCapture.c index 67932804f7..6d347080bd 100644 --- a/ports/espressif/common-hal/imagecapture/ParallelImageCapture.c +++ b/ports/espressif/common-hal/imagecapture/ParallelImageCapture.c @@ -110,10 +110,10 @@ void common_hal_imagecapture_parallelimagecapture_capture(imagecapture_paralleli self->config.frame1_buffer = buffer; cam_init(&self->config); + cam_start(); } else { cam_give(buffer); } - cam_start(); while (!cam_ready()) { RUN_BACKGROUND_TASKS; @@ -126,6 +126,4 @@ void common_hal_imagecapture_parallelimagecapture_capture(imagecapture_paralleli uint8_t *unused; cam_take(&unused); // this just "returns" buffer - - cam_stop(); } diff --git a/ports/espressif/common-hal/rotaryio/IncrementalEncoder.c b/ports/espressif/common-hal/rotaryio/IncrementalEncoder.c index 59fa54880a..b36c79b4f6 100644 --- a/ports/espressif/common-hal/rotaryio/IncrementalEncoder.c +++ b/ports/espressif/common-hal/rotaryio/IncrementalEncoder.c @@ -84,3 +84,13 @@ void common_hal_rotaryio_incrementalencoder_set_position(rotaryio_incrementalenc self->position = new_position; pcnt_counter_clear(self->unit); } + +mp_int_t common_hal_rotaryio_incrementalencoder_get_divisor(rotaryio_incrementalencoder_obj_t *self) { + return 4; +} + +void common_hal_rotaryio_incrementalencoder_set_divisor(rotaryio_incrementalencoder_obj_t *self, mp_int_t divisor) { + if (divisor != 4) { + mp_raise_ValueError(translate("divisor must be 4")); + } +} diff --git a/ports/espressif/common-hal/socketpool/Socket.c b/ports/espressif/common-hal/socketpool/Socket.c index 0ffc311229..c16be01998 100644 --- a/ports/espressif/common-hal/socketpool/Socket.c +++ b/ports/espressif/common-hal/socketpool/Socket.c @@ -27,7 +27,7 @@ #include "shared-bindings/socketpool/Socket.h" #include "bindings/espidf/__init__.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/mperrno.h" #include "py/runtime.h" #include "supervisor/shared/tick.h" diff --git a/ports/espressif/common-hal/ssl/SSLSocket.c b/ports/espressif/common-hal/ssl/SSLSocket.c index d24e3bb145..f9e13029cc 100644 --- a/ports/espressif/common-hal/ssl/SSLSocket.c +++ b/ports/espressif/common-hal/ssl/SSLSocket.c @@ -30,7 +30,7 @@ #include "shared-bindings/ssl/SSLContext.h" #include "bindings/espidf/__init__.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/mperrno.h" #include "py/runtime.h" #include "supervisor/shared/tick.h" diff --git a/ports/espressif/common-hal/watchdog/WatchDogTimer.c b/ports/espressif/common-hal/watchdog/WatchDogTimer.c index f17a037ff4..729ab5815a 100644 --- a/ports/espressif/common-hal/watchdog/WatchDogTimer.c +++ b/ports/espressif/common-hal/watchdog/WatchDogTimer.c @@ -34,7 +34,7 @@ void esp_task_wdt_isr_user_handler(void) { mp_obj_exception_clear_traceback(MP_OBJ_FROM_PTR(&mp_watchdog_timeout_exception)); - MP_STATE_VM(mp_pending_exception) = &mp_watchdog_timeout_exception; + MP_STATE_THREAD(mp_pending_exception) = &mp_watchdog_timeout_exception; #if MICROPY_ENABLE_SCHEDULER if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) { MP_STATE_VM(sched_state) = MP_SCHED_PENDING; diff --git a/ports/espressif/common-hal/wifi/Radio.c b/ports/espressif/common-hal/wifi/Radio.c index 9d48ff1257..d3849b28b2 100644 --- a/ports/espressif/common-hal/wifi/Radio.c +++ b/ports/espressif/common-hal/wifi/Radio.c @@ -30,7 +30,7 @@ #include #include "common-hal/wifi/__init__.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/gc.h" #include "py/runtime.h" #include "shared-bindings/ipaddress/IPv4Address.h" diff --git a/ports/espressif/common-hal/wifi/ScannedNetworks.c b/ports/espressif/common-hal/wifi/ScannedNetworks.c index 62ef62b7f5..25c2da0473 100644 --- a/ports/espressif/common-hal/wifi/ScannedNetworks.c +++ b/ports/espressif/common-hal/wifi/ScannedNetworks.c @@ -28,7 +28,7 @@ #include -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/gc.h" #include "py/objstr.h" #include "py/runtime.h" diff --git a/ports/espressif/mphalport.h b/ports/espressif/mphalport.h index 6550b8c212..7ff8129903 100644 --- a/ports/espressif/mphalport.h +++ b/ports/espressif/mphalport.h @@ -30,7 +30,7 @@ #include #include -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/mpconfig.h" #include "supervisor/shared/tick.h" diff --git a/ports/espressif/supervisor/usb.c b/ports/espressif/supervisor/usb.c index c55c209b4a..fa9d09fa44 100644 --- a/ports/espressif/supervisor/usb.c +++ b/ports/espressif/supervisor/usb.c @@ -29,8 +29,8 @@ #include "supervisor/usb.h" #include "supervisor/esp_port.h" #include "supervisor/port.h" -#include "lib/utils/interrupt_char.h" -#include "lib/mp-readline/readline.h" +#include "shared/runtime/interrupt_char.h" +#include "shared/readline/readline.h" #include "hal/gpio_ll.h" #include "soc/usb_periph.h" @@ -127,7 +127,7 @@ void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char) { // CircuitPython's VM is run in a separate FreeRTOS task from TinyUSB. // So, we must notify the other task when a CTRL-C is received. port_wake_main_task(); - // Workaround for using lib/utils/interrupt_char.c + // Workaround for using shared/runtime/interrupt_char.c // Compare mp_interrupt_char with wanted_char and ignore if not matched if (mp_interrupt_char == wanted_char) { tud_cdc_read_flush(); // flush read fifo diff --git a/ports/litex/Makefile b/ports/litex/Makefile index b4bc135dca..e483832fc1 100644 --- a/ports/litex/Makefile +++ b/ports/litex/Makefile @@ -169,7 +169,7 @@ all: $(BUILD)/firmware.bin $(BUILD)/firmware.dfu $(BUILD)/firmware.elf: $(OBJ) $(STEPECHO) "LINK $@" $(Q)$(CC) -o $@ $(LDFLAGS) $^ -Wl,--start-group $(LIBS) -Wl,--end-group - $(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(LD_FILE) + $(Q)$(SIZE) $@ | $(PYTHON) $(TOP)/tools/build_memory_info.py $(LD_FILE) $(BUILD)/firmware.bin: $(BUILD)/firmware.elf $(STEPECHO) "Create $@" @@ -183,7 +183,7 @@ $(BUILD)/firmware.hex: $(BUILD)/firmware.elf $(BUILD)/firmware.dfu: $(BUILD)/firmware.bin $(ECHO) "Create $@" - $(PYTHON3) $(TOP)/tools/dfu.py -b $^ -D 0x1209:0x5bf0 "$(BUILD)/firmware.dfu" + $(PYTHON) $(TOP)/tools/dfu.py -b $^ -D 0x1209:0x5bf0 "$(BUILD)/firmware.dfu" include $(TOP)/py/mkrules.mk diff --git a/ports/litex/mphalport.h b/ports/litex/mphalport.h index 62c8e0bab3..780bd25f9a 100644 --- a/ports/litex/mphalport.h +++ b/ports/litex/mphalport.h @@ -30,7 +30,7 @@ #include #include -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/mpconfig.h" #include "supervisor/shared/tick.h" diff --git a/ports/litex/supervisor/usb.c b/ports/litex/supervisor/usb.c index b626aaf496..87c9f6dee4 100644 --- a/ports/litex/supervisor/usb.c +++ b/ports/litex/supervisor/usb.c @@ -26,8 +26,8 @@ */ #include "supervisor/usb.h" -#include "lib/utils/interrupt_char.h" -#include "lib/mp-readline/readline.h" +#include "shared/runtime/interrupt_char.h" +#include "shared/readline/readline.h" void init_usb_hardware(void) { diff --git a/ports/mimxrt10xx/Makefile b/ports/mimxrt10xx/Makefile index 310b5d6f31..f330cddf14 100644 --- a/ports/mimxrt10xx/Makefile +++ b/ports/mimxrt10xx/Makefile @@ -60,7 +60,7 @@ INC += \ -I. \ -I../.. \ -I../lib/mp-readline \ - -I../lib/timeutils \ + -I../shared/timeutils \ -I../../lib/tinyusb/src \ -I../../supervisor/shared/usb \ -I$(BUILD) \ @@ -207,7 +207,7 @@ $(BUILD)/firmware.bin: $(BUILD)/firmware.elf $(BUILD)/firmware.uf2: $(BUILD)/firmware.elf $(STEPECHO) "Create $@" $(Q)$(OBJCOPY) -O binary -j .text -j .ARM.exidx -j .data -j .itcm -j .dtcm_data $^ $@-binpart - $(Q)$(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -b $(BOOTLOADER_SIZE) -f MIMXRT10XX -c -o $@ $@-binpart + $(Q)$(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -b $(BOOTLOADER_SIZE) -f MIMXRT10XX -c -o $@ $@-binpart $(Q)rm $@-binpart $(BUILD)/firmware.hex: $(BUILD)/firmware.elf diff --git a/ports/mimxrt10xx/common-hal/busio/UART.c b/ports/mimxrt10xx/common-hal/busio/UART.c index ec0296156a..2a6a3110cb 100644 --- a/ports/mimxrt10xx/common-hal/busio/UART.c +++ b/ports/mimxrt10xx/common-hal/busio/UART.c @@ -30,7 +30,7 @@ #include "shared-bindings/busio/UART.h" #include "mpconfigport.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "supervisor/shared/tick.h" #include "py/gc.h" #include "py/mperrno.h" diff --git a/ports/mimxrt10xx/common-hal/rtc/RTC.c b/ports/mimxrt10xx/common-hal/rtc/RTC.c index aabe2b09f2..8619a7eaec 100644 --- a/ports/mimxrt10xx/common-hal/rtc/RTC.c +++ b/ports/mimxrt10xx/common-hal/rtc/RTC.c @@ -29,7 +29,7 @@ #include "py/obj.h" #include "py/runtime.h" -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" #include "shared-bindings/rtc/__init__.h" #include "supervisor/shared/translate.h" diff --git a/ports/mimxrt10xx/fatfs_port.c b/ports/mimxrt10xx/fatfs_port.c index e6eee20495..58a0ef0d72 100644 --- a/ports/mimxrt10xx/fatfs_port.c +++ b/ports/mimxrt10xx/fatfs_port.c @@ -28,7 +28,7 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" /* FatFs lower layer API */ #include "lib/oofatfs/diskio.h" /* FatFs lower layer API */ -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" #if CIRCUITPY_RTC #include "shared-bindings/rtc/RTC.h" diff --git a/ports/nrf/Makefile b/ports/nrf/Makefile index 01050324f5..acd1509297 100755 --- a/ports/nrf/Makefile +++ b/ports/nrf/Makefile @@ -239,7 +239,7 @@ $(BUILD)/firmware.elf: $(OBJ) $(GENERATED_LD_FILE) $(STEPECHO) "LINK $@" $(Q)echo $(OBJ) > $(BUILD)/firmware.objs $(Q)$(CC) -o $@ $(LDFLAGS) @$(BUILD)/firmware.objs -Wl,--start-group $(LIBS) -Wl,--end-group - $(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(GENERATED_LD_FILE) + $(Q)$(SIZE) $@ | $(PYTHON) $(TOP)/tools/build_memory_info.py $(GENERATED_LD_FILE) $(BUILD)/firmware.bin: $(BUILD)/firmware.elf $(STEPECHO) "Create $@" @@ -257,7 +257,7 @@ $(BUILD)/firmware.combined.hex: $(BUILD)/firmware.hex $(SOFTDEV_HEX) $(BUILD)/firmware.uf2: $(BUILD)/firmware.hex $(ECHO) "Create $@" - $(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -f 0xADA52840 -c -o "$(BUILD)/firmware.uf2" $^ + $(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f 0xADA52840 -c -o "$(BUILD)/firmware.uf2" $^ diff --git a/ports/nrf/common-hal/_bleio/CharacteristicBuffer.c b/ports/nrf/common-hal/_bleio/CharacteristicBuffer.c index ca37f41c1a..d45bd89f3d 100644 --- a/ports/nrf/common-hal/_bleio/CharacteristicBuffer.c +++ b/ports/nrf/common-hal/_bleio/CharacteristicBuffer.c @@ -31,7 +31,7 @@ #include "ble_gatts.h" #include "nrf_nvic.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/runtime.h" #include "py/stream.h" diff --git a/ports/nrf/common-hal/_bleio/Connection.c b/ports/nrf/common-hal/_bleio/Connection.c index b94ad09e6a..0d8d8c32f0 100644 --- a/ports/nrf/common-hal/_bleio/Connection.c +++ b/ports/nrf/common-hal/_bleio/Connection.c @@ -34,7 +34,7 @@ #include "ble_drv.h" #include "ble_hci.h" #include "nrf_soc.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/gc.h" #include "py/objlist.h" #include "py/objstr.h" diff --git a/ports/nrf/common-hal/_bleio/PacketBuffer.c b/ports/nrf/common-hal/_bleio/PacketBuffer.c index ee786c8292..6f53fb96aa 100644 --- a/ports/nrf/common-hal/_bleio/PacketBuffer.c +++ b/ports/nrf/common-hal/_bleio/PacketBuffer.c @@ -31,7 +31,7 @@ #include "ble_gatts.h" #include "nrf_nvic.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/runtime.h" #include "py/stream.h" diff --git a/ports/nrf/common-hal/busio/UART.c b/ports/nrf/common-hal/busio/UART.c index 4e7fd3079e..132f5d9272 100644 --- a/ports/nrf/common-hal/busio/UART.c +++ b/ports/nrf/common-hal/busio/UART.c @@ -27,7 +27,7 @@ #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/busio/UART.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/mpconfig.h" #include "py/gc.h" #include "py/mperrno.h" diff --git a/ports/nrf/common-hal/rotaryio/IncrementalEncoder.h b/ports/nrf/common-hal/rotaryio/IncrementalEncoder.h index 3693131056..86fbe5475f 100644 --- a/ports/nrf/common-hal/rotaryio/IncrementalEncoder.h +++ b/ports/nrf/common-hal/rotaryio/IncrementalEncoder.h @@ -36,7 +36,8 @@ typedef struct { uint8_t pin_a; uint8_t pin_b; uint8_t state; // - int8_t quarter_count; // count intermediate transitions between detents + int8_t sub_count; // count intermediate transitions between detents + int8_t divisor; // Number of quadrature edges required per count mp_int_t position; } rotaryio_incrementalencoder_obj_t; diff --git a/ports/nrf/common-hal/rtc/RTC.c b/ports/nrf/common-hal/rtc/RTC.c index 24825a979f..074079cd6b 100644 --- a/ports/nrf/common-hal/rtc/RTC.c +++ b/ports/nrf/common-hal/rtc/RTC.c @@ -28,7 +28,7 @@ #include "py/obj.h" #include "py/runtime.h" -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" #include "shared-bindings/rtc/__init__.h" #include "supervisor/port.h" #include "supervisor/shared/translate.h" diff --git a/ports/nrf/common-hal/watchdog/WatchDogTimer.c b/ports/nrf/common-hal/watchdog/WatchDogTimer.c index 1798c52609..cd7aa449bf 100644 --- a/ports/nrf/common-hal/watchdog/WatchDogTimer.c +++ b/ports/nrf/common-hal/watchdog/WatchDogTimer.c @@ -62,7 +62,7 @@ STATIC void watchdogtimer_timer_event_handler(nrf_timer_event_t event_type, void nrfx_timer_pause(timer); self->mode = WATCHDOGMODE_NONE; mp_obj_exception_clear_traceback(MP_OBJ_FROM_PTR(&mp_watchdog_timeout_exception)); - MP_STATE_VM(mp_pending_exception) = &mp_watchdog_timeout_exception; + MP_STATE_THREAD(mp_pending_exception) = &mp_watchdog_timeout_exception; #if MICROPY_ENABLE_SCHEDULER if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) { MP_STATE_VM(sched_state) = MP_SCHED_PENDING; diff --git a/ports/nrf/fatfs_port.c b/ports/nrf/fatfs_port.c index f2644adbd3..5882864bbe 100644 --- a/ports/nrf/fatfs_port.c +++ b/ports/nrf/fatfs_port.c @@ -26,7 +26,7 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" #include "shared-bindings/rtc/RTC.h" #include "shared-bindings/time/__init__.h" diff --git a/ports/nrf/mphalport.h b/ports/nrf/mphalport.h index 2b13f82db1..a93d998855 100644 --- a/ports/nrf/mphalport.h +++ b/ports/nrf/mphalport.h @@ -30,7 +30,7 @@ #include #include -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "nrfx_uarte.h" #include "py/mpconfig.h" #include "supervisor/shared/tick.h" diff --git a/ports/nrf/supervisor/usb.c b/ports/nrf/supervisor/usb.c index 3ca9b8365d..6031cced50 100644 --- a/ports/nrf/supervisor/usb.c +++ b/ports/nrf/supervisor/usb.c @@ -27,8 +27,8 @@ #include "nrfx.h" #include "nrfx_power.h" #include "supervisor/usb.h" -#include "lib/utils/interrupt_char.h" -#include "lib/mp-readline/readline.h" +#include "shared/runtime/interrupt_char.h" +#include "shared/readline/readline.h" #include "lib/tinyusb/src/device/usbd.h" #include "supervisor/background_callback.h" diff --git a/ports/raspberrypi/Makefile b/ports/raspberrypi/Makefile index ffab1fbcd0..2739bf6547 100644 --- a/ports/raspberrypi/Makefile +++ b/ports/raspberrypi/Makefile @@ -60,7 +60,7 @@ HAL_DIR=hal/$(MCU_SERIES) INC += -I. \ -I../.. \ -I../lib/mp-readline \ - -I../lib/timeutils \ + -I../shared/timeutils \ -Iboards/$(BOARD) \ -Iboards/ \ -isystem sdk/ \ @@ -198,7 +198,7 @@ SRC_C += \ audio_dma.c \ background.c \ peripherals/pins.c \ - extmod/crypto-algorithms/sha256.c \ + lib/crypto-algorithms/sha256.c \ fatfs_port.c \ lib/tinyusb/src/portable/raspberrypi/rp2040/dcd_rp2040.c \ lib/tinyusb/src/portable/raspberrypi/rp2040/rp2040_usb.c \ @@ -249,7 +249,7 @@ $(BUILD)/boot2_padded_checksummed.o: $(BUILD)/boot2_padded_checksummed.S $(BUILD)/boot2_padded_checksummed.S: $(BUILD)/boot2.bin $(STEPECHO) "PAD_CHECKSUM $<" - $(Q)$(PYTHON3) sdk/src/rp2_common/boot_stage2/pad_checksum -s 0xffffffff $< $@ + $(Q)$(PYTHON) sdk/src/rp2_common/boot_stage2/pad_checksum -s 0xffffffff $< $@ $(BUILD)/boot2.bin: $(BUILD)/boot2.elf $(STEPECHO) "OBJCOPY $<" @@ -258,11 +258,11 @@ $(BUILD)/boot2.bin: $(BUILD)/boot2.elf $(BUILD)/stage2.c: stage2.c.jinja gen_stage2.py | $(BUILD)/ $(STEPECHO) "GEN $<" - $(Q)$(PYTHON3) gen_stage2.py $< $@ $(EXTERNAL_FLASH_DEVICES) + $(Q)$(PYTHON) gen_stage2.py $< $@ $(EXTERNAL_FLASH_DEVICES) $(HEADER_BUILD)/flash_info.h: flash_info.h.jinja gen_stage2.py | $(HEADER_BUILD)/ $(STEPECHO) "GEN $<" - $(Q)$(PYTHON3) gen_stage2.py $< $@ $(EXTERNAL_FLASH_DEVICES) + $(Q)$(PYTHON) gen_stage2.py $< $@ $(EXTERNAL_FLASH_DEVICES) $(BUILD)/supervisor/internal_flash.o: $(HEADER_BUILD)/flash_info.h @@ -280,7 +280,7 @@ $(BUILD)/firmware.elf: $(OBJ) link.ld $(Q)echo $(OBJ) > $(BUILD)/firmware.objs $(Q)echo $(PICO_LDFLAGS) > $(BUILD)/firmware.ldflags $(Q)$(CC) -o $@ $(CFLAGS) @$(BUILD)/firmware.ldflags -Wl,-T,link.ld -Wl,-Map=$@.map -Wl,-cref -Wl,--gc-sections @$(BUILD)/firmware.objs - $(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py link.ld + $(Q)$(SIZE) $@ | $(PYTHON) $(TOP)/tools/build_memory_info.py link.ld $(BUILD)/firmware.bin: $(BUILD)/firmware.elf $(STEPECHO) "Create $@" @@ -288,7 +288,7 @@ $(BUILD)/firmware.bin: $(BUILD)/firmware.elf $(BUILD)/firmware.uf2: $(BUILD)/firmware.bin $(STEPECHO) "Create $@" - $(Q)$(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -f 0xe48bff56 -b 0x10000000 -c -o $@ $^ + $(Q)$(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f 0xe48bff56 -b 0x10000000 -c -o $@ $^ include $(TOP)/py/mkrules.mk diff --git a/ports/raspberrypi/bindings/rp2pio/StateMachine.c b/ports/raspberrypi/bindings/rp2pio/StateMachine.c index 3dffc39363..39b975ff8d 100644 --- a/ports/raspberrypi/bindings/rp2pio/StateMachine.c +++ b/ports/raspberrypi/bindings/rp2pio/StateMachine.c @@ -33,9 +33,9 @@ #include "bindings/rp2pio/StateMachine.h" #include "shared-bindings/util.h" -#include "lib/utils/buffer_helper.h" -#include "lib/utils/context_manager_helpers.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/buffer_helper.h" +#include "shared/runtime/context_manager_helpers.h" +#include "shared/runtime/interrupt_char.h" #include "py/binary.h" #include "py/mperrno.h" #include "py/objproperty.h" @@ -138,7 +138,7 @@ //| ... //| -STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { rp2pio_statemachine_obj_t *self = m_new_obj(rp2pio_statemachine_obj_t); self->base.type = &rp2pio_statemachine_type; enum { ARG_program, ARG_frequency, ARG_init, @@ -191,7 +191,7 @@ STATIC mp_obj_t rp2pio_statemachine_make_new(const mp_obj_type_t *type, size_t n { MP_QSTR_user_interruptible, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = true} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[ARG_program].u_obj, &bufinfo, MP_BUFFER_READ); diff --git a/ports/raspberrypi/boards/melopero_shake_rp2040/pins.c b/ports/raspberrypi/boards/melopero_shake_rp2040/pins.c index 8d5be961e0..76ab220216 100644 --- a/ports/raspberrypi/boards/melopero_shake_rp2040/pins.c +++ b/ports/raspberrypi/boards/melopero_shake_rp2040/pins.c @@ -25,6 +25,10 @@ STATIC const mp_rom_map_elem_t board_global_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_D11), MP_ROM_PTR(&pin_GPIO11) }, { MP_ROM_QSTR(MP_QSTR_D12), MP_ROM_PTR(&pin_GPIO12) }, { MP_ROM_QSTR(MP_QSTR_D13), MP_ROM_PTR(&pin_GPIO13) }, + { MP_ROM_QSTR(MP_QSTR_D17), MP_ROM_PTR(&pin_GPIO17) }, + + { MP_ROM_QSTR(MP_QSTR_BATTERY), MP_ROM_PTR(&pin_GPIO17) }, + { MP_ROM_QSTR(MP_QSTR_LED), MP_ROM_PTR(&pin_GPIO13) }, { MP_ROM_QSTR(MP_QSTR_NEOPIXEL), MP_ROM_PTR(&pin_GPIO16) }, diff --git a/ports/raspberrypi/common-hal/alarm/__init__.c b/ports/raspberrypi/common-hal/alarm/__init__.c index 7f22242e9f..0d6734568b 100644 --- a/ports/raspberrypi/common-hal/alarm/__init__.c +++ b/ports/raspberrypi/common-hal/alarm/__init__.c @@ -28,7 +28,7 @@ #include "py/obj.h" #include "py/objtuple.h" #include "py/runtime.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "shared-bindings/alarm/__init__.h" #include "shared-bindings/alarm/SleepMemory.h" diff --git a/ports/raspberrypi/common-hal/alarm/time/TimeAlarm.c b/ports/raspberrypi/common-hal/alarm/time/TimeAlarm.c index 4302e9e8cd..65c2b680d8 100644 --- a/ports/raspberrypi/common-hal/alarm/time/TimeAlarm.c +++ b/ports/raspberrypi/common-hal/alarm/time/TimeAlarm.c @@ -29,7 +29,7 @@ #include "shared-bindings/alarm/time/TimeAlarm.h" #include "shared-bindings/time/__init__.h" -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" #include "hardware/gpio.h" #include "hardware/rtc.h" diff --git a/ports/raspberrypi/common-hal/busio/SPI.c b/ports/raspberrypi/common-hal/busio/SPI.c index ab295c4ff1..766807f5a9 100644 --- a/ports/raspberrypi/common-hal/busio/SPI.c +++ b/ports/raspberrypi/common-hal/busio/SPI.c @@ -26,7 +26,7 @@ #include "shared-bindings/busio/SPI.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/mperrno.h" #include "py/runtime.h" diff --git a/ports/raspberrypi/common-hal/busio/UART.c b/ports/raspberrypi/common-hal/busio/UART.c index e7ba64b098..14935f4046 100644 --- a/ports/raspberrypi/common-hal/busio/UART.c +++ b/ports/raspberrypi/common-hal/busio/UART.c @@ -30,7 +30,7 @@ #include "py/mperrno.h" #include "py/runtime.h" #include "supervisor/shared/tick.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "common-hal/microcontroller/Pin.h" #include "src/rp2_common/hardware_irq/include/hardware/irq.h" diff --git a/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c b/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c index 1d0355d1c0..1a294f6886 100644 --- a/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c +++ b/ports/raspberrypi/common-hal/imagecapture/ParallelImageCapture.c @@ -27,8 +27,8 @@ #include "py/obj.h" #include "py/runtime.h" -#include "lib/utils/context_manager_helpers.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/context_manager_helpers.h" +#include "shared/runtime/interrupt_char.h" #include "bindings/rp2pio/StateMachine.h" #include "bindings/rp2pio/__init__.h" diff --git a/ports/raspberrypi/common-hal/os/__init__.c b/ports/raspberrypi/common-hal/os/__init__.c index 3352cef122..25fe317abe 100644 --- a/ports/raspberrypi/common-hal/os/__init__.c +++ b/ports/raspberrypi/common-hal/os/__init__.c @@ -30,7 +30,7 @@ #include "py/objtuple.h" #include "py/qstr.h" -#include "extmod/crypto-algorithms/sha256.h" +#include "lib/crypto-algorithms/sha256.h" #include "hardware/structs/rosc.h" diff --git a/ports/raspberrypi/common-hal/pwmio/PWMOut.c b/ports/raspberrypi/common-hal/pwmio/PWMOut.c index 25590a1332..27e9bd4d03 100644 --- a/ports/raspberrypi/common-hal/pwmio/PWMOut.c +++ b/ports/raspberrypi/common-hal/pwmio/PWMOut.c @@ -26,7 +26,7 @@ #include -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/runtime.h" #include "common-hal/pwmio/PWMOut.h" #include "shared-bindings/pwmio/PWMOut.h" diff --git a/ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c b/ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c index 00cf54b221..649c9421e0 100644 --- a/ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c +++ b/ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.c @@ -73,7 +73,7 @@ void common_hal_rotaryio_incrementalencoder_construct(rotaryio_incrementalencode } self->position = 0; - self->quarter_count = 0; + self->sub_count = 0; common_hal_rp2pio_statemachine_construct(&self->state_machine, encoder, MP_ARRAY_SIZE(encoder), diff --git a/ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.h b/ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.h index 6745d95a1c..812ba09821 100644 --- a/ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.h +++ b/ports/raspberrypi/common-hal/rotaryio/IncrementalEncoder.h @@ -35,7 +35,8 @@ typedef struct { mp_obj_base_t base; rp2pio_statemachine_obj_t state_machine; uint8_t state; // - int8_t quarter_count; // count intermediate transitions between detents + int8_t sub_count; // count intermediate transitions between detents + int8_t divisor; // Number of quadrature edges required per count bool swapped; // Did the pins need to be swapped to be sequential? mp_int_t position; } rotaryio_incrementalencoder_obj_t; diff --git a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c index c35adc21e2..27672f0de0 100644 --- a/ports/raspberrypi/common-hal/rp2pio/StateMachine.c +++ b/ports/raspberrypi/common-hal/rp2pio/StateMachine.c @@ -37,7 +37,7 @@ #include "src/rp2040/hardware_structs/include/hardware/structs/iobank0.h" #include "src/rp2_common/hardware_irq/include/hardware/irq.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/obj.h" #include "py/objproperty.h" #include "py/runtime.h" diff --git a/ports/raspberrypi/fatfs_port.c b/ports/raspberrypi/fatfs_port.c index e6eee20495..58a0ef0d72 100644 --- a/ports/raspberrypi/fatfs_port.c +++ b/ports/raspberrypi/fatfs_port.c @@ -28,7 +28,7 @@ #include "py/runtime.h" #include "lib/oofatfs/ff.h" /* FatFs lower layer API */ #include "lib/oofatfs/diskio.h" /* FatFs lower layer API */ -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" #if CIRCUITPY_RTC #include "shared-bindings/rtc/RTC.h" diff --git a/ports/raspberrypi/mphalport.c b/ports/raspberrypi/mphalport.c index 89b597bc74..51d82a0514 100644 --- a/ports/raspberrypi/mphalport.c +++ b/ports/raspberrypi/mphalport.c @@ -26,8 +26,8 @@ #include -#include "lib/mp-readline/readline.h" -#include "lib/utils/interrupt_char.h" +#include "shared/readline/readline.h" +#include "shared/runtime/interrupt_char.h" #include "py/mphal.h" #include "py/mpstate.h" #include "py/runtime.h" diff --git a/ports/stm/Makefile b/ports/stm/Makefile index c691044f27..b5423b62c0 100755 --- a/ports/stm/Makefile +++ b/ports/stm/Makefile @@ -290,7 +290,7 @@ $(BUILD)/firmware.elf: $(OBJ) $(STEPECHO) "LINK $@" $(Q)echo $^ > $(BUILD)/firmware.objs $(Q)$(CC) -o $@ $(LDFLAGS) @$(BUILD)/firmware.objs -Wl,--start-group $(LIBS) -Wl,--end-group - $(Q)$(SIZE) $@ | $(PYTHON3) $(TOP)/tools/build_memory_info.py $(LD_FILE) + $(Q)$(SIZE) $@ | $(PYTHON) $(TOP)/tools/build_memory_info.py $(LD_FILE) $(BUILD)/firmware.bin: $(BUILD)/firmware.elf $(STEPECHO) "Create $@" @@ -302,7 +302,7 @@ $(BUILD)/firmware.hex: $(BUILD)/firmware.elf $(BUILD)/firmware.uf2: $(BUILD)/firmware.hex $(ECHO) "Create $@" - $(PYTHON3) $(TOP)/tools/uf2/utils/uf2conv.py -f 0x57755a57 -b $(BOOTLOADER_OFFSET) -c -o "$(BUILD)/firmware.uf2" $^ + $(PYTHON) $(TOP)/tools/uf2/utils/uf2conv.py -f 0x57755a57 -b $(BOOTLOADER_OFFSET) -c -o "$(BUILD)/firmware.uf2" $^ flash: $(BUILD)/firmware.bin $(ECHO) "Writing $< to the board" diff --git a/ports/stm/common-hal/alarm/__init__.c b/ports/stm/common-hal/alarm/__init__.c index 3ec546f52b..466c2d5199 100644 --- a/ports/stm/common-hal/alarm/__init__.c +++ b/ports/stm/common-hal/alarm/__init__.c @@ -28,7 +28,7 @@ #include "py/obj.h" #include "py/objtuple.h" #include "py/runtime.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "shared-bindings/alarm/__init__.h" #include "shared-bindings/alarm/SleepMemory.h" diff --git a/ports/stm/common-hal/busio/UART.c b/ports/stm/common-hal/busio/UART.c index 621cce6cfd..d8677126ef 100644 --- a/ports/stm/common-hal/busio/UART.c +++ b/ports/stm/common-hal/busio/UART.c @@ -29,8 +29,8 @@ #include "shared-bindings/busio/UART.h" #include "mpconfigport.h" -#include "lib/mp-readline/readline.h" -#include "lib/utils/interrupt_char.h" +#include "shared/readline/readline.h" +#include "shared/runtime/interrupt_char.h" #include "py/gc.h" #include "py/mperrno.h" #include "py/runtime.h" diff --git a/ports/stm/common-hal/canio/Listener.c b/ports/stm/common-hal/canio/Listener.c index dc819180f9..69c196b78d 100644 --- a/ports/stm/common-hal/canio/Listener.c +++ b/ports/stm/common-hal/canio/Listener.c @@ -30,7 +30,7 @@ #include "py/obj.h" #include "py/runtime.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "common-hal/canio/__init__.h" #include "common-hal/canio/Listener.h" diff --git a/ports/stm/peripherals/rtc.c b/ports/stm/peripherals/rtc.c index 5f8f05b2bf..13cda1aac8 100644 --- a/ports/stm/peripherals/rtc.c +++ b/ports/stm/peripherals/rtc.c @@ -31,7 +31,7 @@ #include "py/gc.h" #include "py/obj.h" #include "py/runtime.h" -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" // Default period for ticks is 1/1024 second #define TICK_DIVISOR 1024 diff --git a/ports/stm/supervisor/port.c b/ports/stm/supervisor/port.c index 3b487d38ab..a158ade6eb 100644 --- a/ports/stm/supervisor/port.c +++ b/ports/stm/supervisor/port.c @@ -29,7 +29,7 @@ #include "supervisor/background_callback.h" #include "supervisor/board.h" #include "supervisor/port.h" -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" #include "common-hal/microcontroller/Pin.h" #include "shared-bindings/microcontroller/__init__.h" diff --git a/ports/stm/supervisor/usb.c b/ports/stm/supervisor/usb.c index d58eaba7b2..882f74e8bc 100644 --- a/ports/stm/supervisor/usb.c +++ b/ports/stm/supervisor/usb.c @@ -27,8 +27,8 @@ #include "supervisor/usb.h" -#include "lib/utils/interrupt_char.h" -#include "lib/mp-readline/readline.h" +#include "shared/runtime/interrupt_char.h" +#include "shared/readline/readline.h" #include "lib/tinyusb/src/device/usbd.h" #include "py/mpconfig.h" diff --git a/ports/unix/Makefile b/ports/unix/Makefile index ec60d8d2ad..344ebdb423 100644 --- a/ports/unix/Makefile +++ b/ports/unix/Makefile @@ -112,9 +112,9 @@ endif endif ifeq ($(MICROPY_USE_READLINE),1) -INC += -I$(TOP)/lib/mp-readline +INC += -I$(TOP)/shared/readline CFLAGS_MOD += -DMICROPY_USE_READLINE=1 -LIB_SRC_C_EXTRA += mp-readline/readline.c +SHARED_SRC_C_EXTRA += readline/readline.c endif ifeq ($(MICROPY_PY_TERMIOS),1) CFLAGS_MOD += -DMICROPY_PY_TERMIOS=1 @@ -129,6 +129,62 @@ CFLAGS_MOD += -DMICROPY_PY_THREAD=1 -DMICROPY_PY_THREAD_GIL=0 LDFLAGS_MOD += $(LIBPTHREAD) endif +# If the variant enables it, enable modbluetooth. +ifeq ($(MICROPY_PY_BLUETOOTH),1) + +HAVE_LIBUSB := $(shell (which pkg-config > /dev/null && pkg-config --exists libusb-1.0) 2>/dev/null && echo '1') + +# Only one stack can be enabled. +ifeq ($(MICROPY_BLUETOOTH_NIMBLE),1) +ifeq ($(MICROPY_BLUETOOTH_BTSTACK),1) +$(error Cannot enable both NimBLE and BTstack at the same time) +endif +endif + +# Default to btstack, but a variant (or make command line) can set NimBLE +# explicitly (which is always via H4 UART). +ifneq ($(MICROPY_BLUETOOTH_NIMBLE),1) +ifneq ($(MICROPY_BLUETOOTH_BTSTACK),1) +MICROPY_BLUETOOTH_BTSTACK ?= 1 +endif +endif + +CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH=1 +CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH_ENABLE_CENTRAL_MODE=1 + +ifeq ($(MICROPY_BLUETOOTH_BTSTACK),1) + +# Figure out which BTstack transport to use. +ifeq ($(MICROPY_BLUETOOTH_BTSTACK_H4),1) +ifeq ($(MICROPY_BLUETOOTH_BTSTACK_USB),1) +$(error Cannot enable BTstack support for USB and H4 UART at the same time) +endif +else +ifeq ($(HAVE_LIBUSB),1) +# Default to btstack-over-usb. +MICROPY_BLUETOOTH_BTSTACK_USB ?= 1 +else +# Fallback to HCI controller via a H4 UART (e.g. Zephyr on nRF) over a /dev/tty serial port. +MICROPY_BLUETOOTH_BTSTACK_H4 ?= 1 +endif +endif + +# BTstack is enabled. +GIT_SUBMODULES += lib/btstack +include $(TOP)/extmod/btstack/btstack.mk +SRC_BTSTACK += lib/btstack/platform/embedded/btstack_run_loop_embedded.c + +else + +# NimBLE is enabled. +GIT_SUBMODULES += lib/mynewt-nimble +CFLAGS_MOD += -DMICROPY_PY_BLUETOOTH_ENABLE_L2CAP_CHANNELS=1 +include $(TOP)/extmod/nimble/nimble.mk + +endif + +endif + ifeq ($(MICROPY_PY_FFI),1) ifeq ($(MICROPY_STANDALONE),1) @@ -178,10 +234,10 @@ SRC_C += \ $(SRC_MOD) \ $(wildcard $(VARIANT_DIR)/*.c) -LIB_SRC_C += $(addprefix lib/,\ - $(LIB_SRC_C_EXTRA) \ +SHARED_SRC_C += $(addprefix shared/,\ + runtime/gchelper_generic.c \ timeutils/timeutils.c \ - utils/gchelper_generic.c \ + $(SHARED_SRC_C_EXTRA) \ ) SRC_CXX += \ @@ -190,11 +246,12 @@ SRC_CXX += \ OBJ = $(PY_O) OBJ += $(addprefix $(BUILD)/, $(SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(SRC_CXX:.cpp=.o)) -OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o)) +OBJ += $(addprefix $(BUILD)/, $(SHARED_SRC_C:.c=.o)) OBJ += $(addprefix $(BUILD)/, $(EXTMOD_SRC_C:.c=.o)) +OBJ += $(addprefix $(BUILD)/, $(LIB_SRC_C:.c=.o)) # List of sources for qstr extraction -SRC_QSTR += $(SRC_C) $(SRC_CXX) $(LIB_SRC_C) $(EXTMOD_SRC_C) +SRC_QSTR += $(SRC_C) $(SRC_CXX) $(SHARED_SRC_C) $(EXTMOD_SRC_C) # Append any auto-generated sources that are needed by sources listed in # SRC_QSTR SRC_QSTR_AUTO_DEPS += @@ -221,6 +278,17 @@ else RUN_TESTS_MPY_CROSS_FLAGS = --mpy-cross-flags='-mcache-lookup-bc' endif +ifeq ($(CROSS_COMPILE),arm-linux-gnueabi-) +# Force disable error text compression when compiling for ARM as the compiler +# cannot optimise out the giant strcmp list generated for MP_MATCH_COMPRESSED. +# Checked on: +# arm-linux-gnueabi-gcc (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04) 7.5.0 +# arm-linux-gnueabi-gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0 +# See https://github.com/micropython/micropython/pull/7659 for details. +$(info Detected arm-linux-gnueabi-gcc. Disabling error message compression.) +MICROPY_ROM_TEXT_COMPRESSION = 0 +endif + include $(TOP)/py/mkrules.mk .PHONY: test test_full diff --git a/ports/unix/gccollect.c b/ports/unix/gccollect.c index 5e438b258b..d9ac53d7f8 100644 --- a/ports/unix/gccollect.c +++ b/ports/unix/gccollect.c @@ -29,7 +29,7 @@ #include "py/mpstate.h" #include "py/gc.h" -#include "lib/utils/gchelper.h" +#include "shared/runtime/gchelper.h" #if MICROPY_ENABLE_GC diff --git a/ports/unix/input.c b/ports/unix/input.c index f85bb177f0..d66487a7af 100644 --- a/ports/unix/input.c +++ b/ports/unix/input.c @@ -35,7 +35,7 @@ #include "input.h" #if MICROPY_USE_READLINE == 1 -#include "lib/mp-readline/readline.h" +#include "shared/readline/readline.h" #endif #if MICROPY_USE_READLINE == 0 diff --git a/ports/unix/main.c b/ports/unix/main.c index 55bdc22082..c1cf6a7ffa 100644 --- a/ports/unix/main.c +++ b/ports/unix/main.c @@ -158,7 +158,7 @@ STATIC int execute_from_lexer(int source_kind, const void *source, mp_parse_inpu } #if MICROPY_USE_READLINE == 1 -#include "lib/mp-readline/readline.h" +#include "shared/readline/readline.h" #else STATIC char *strjoin(const char *s1, int sep_char, const char *s2) { int l1 = strlen(s1); diff --git a/ports/unix/modffi.c b/ports/unix/modffi.c index 81dcb57d5d..d1966c51f0 100644 --- a/ports/unix/modffi.c +++ b/ports/unix/modffi.c @@ -36,6 +36,7 @@ #include "py/binary.h" #include "py/mperrno.h" #include "py/objint.h" +#include "py/gc.h" #include "supervisor/shared/translate.h" @@ -102,6 +103,7 @@ typedef struct _mp_obj_fficallback_t { void *func; ffi_closure *clo; char rettype; + mp_obj_t pyfunc; ffi_cif cif; ffi_type *params[]; } mp_obj_fficallback_t; @@ -268,19 +270,69 @@ STATIC mp_obj_t mod_ffi_func(mp_obj_t rettype, mp_obj_t addr_in, mp_obj_t argtyp } MP_DEFINE_CONST_FUN_OBJ_3(mod_ffi_func_obj, mod_ffi_func); -STATIC void call_py_func(ffi_cif *cif, void *ret, void **args, void *func) { +STATIC void call_py_func(ffi_cif *cif, void *ret, void **args, void *user_data) { mp_obj_t pyargs[cif->nargs]; + mp_obj_fficallback_t *o = user_data; + mp_obj_t pyfunc = o->pyfunc; + for (uint i = 0; i < cif->nargs; i++) { pyargs[i] = mp_obj_new_int(*(mp_int_t *)args[i]); } - mp_obj_t res = mp_call_function_n_kw(MP_OBJ_FROM_PTR(func), cif->nargs, 0, pyargs); + mp_obj_t res = mp_call_function_n_kw(pyfunc, cif->nargs, 0, pyargs); if (res != mp_const_none) { *(ffi_arg *)ret = mp_obj_int_get_truncated(res); } } -STATIC mp_obj_t mod_ffi_callback(mp_obj_t rettype_in, mp_obj_t func_in, mp_obj_t paramtypes_in) { +STATIC void call_py_func_with_lock(ffi_cif *cif, void *ret, void **args, void *user_data) { + mp_obj_t pyargs[cif->nargs]; + mp_obj_fficallback_t *o = user_data; + mp_obj_t pyfunc = o->pyfunc; + nlr_buf_t nlr; + + #if MICROPY_ENABLE_SCHEDULER + mp_sched_lock(); + #endif + gc_lock(); + + if (nlr_push(&nlr) == 0) { + for (uint i = 0; i < cif->nargs; i++) { + pyargs[i] = mp_obj_new_int(*(mp_int_t *)args[i]); + } + mp_obj_t res = mp_call_function_n_kw(pyfunc, cif->nargs, 0, pyargs); + + if (res != mp_const_none) { + *(ffi_arg *)ret = mp_obj_int_get_truncated(res); + } + nlr_pop(); + } else { + // Uncaught exception + mp_printf(MICROPY_ERROR_PRINTER, "Uncaught exception in FFI callback\n"); + mp_obj_print_exception(MICROPY_ERROR_PRINTER, MP_OBJ_FROM_PTR(nlr.ret_val)); + } + + gc_unlock(); + #if MICROPY_ENABLE_SCHEDULER + mp_sched_unlock(); + #endif +} + +STATIC mp_obj_t mod_ffi_callback(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + // first 3 args are positional: retttype, func, paramtypes. + mp_obj_t rettype_in = pos_args[0]; + mp_obj_t func_in = pos_args[1]; + mp_obj_t paramtypes_in = pos_args[2]; + + // arg parsing is used only for additional kwargs + enum { ARG_lock }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_lock, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, + }; + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args - 3, pos_args + 3, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + bool lock_in = args[ARG_lock].u_bool; + const char *rettype = mp_obj_str_get_str(rettype_in); mp_int_t nparams = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(paramtypes_in)); @@ -290,6 +342,7 @@ STATIC mp_obj_t mod_ffi_callback(mp_obj_t rettype_in, mp_obj_t func_in, mp_obj_t o->clo = ffi_closure_alloc(sizeof(ffi_closure), &o->func); o->rettype = *rettype; + o->pyfunc = func_in; mp_obj_iter_buf_t iter_buf; mp_obj_t iterable = mp_getiter(paramtypes_in, &iter_buf); @@ -304,14 +357,15 @@ STATIC mp_obj_t mod_ffi_callback(mp_obj_t rettype_in, mp_obj_t func_in, mp_obj_t mp_raise_ValueError(MP_ERROR_TEXT("Error in ffi_prep_cif")); } - res = ffi_prep_closure_loc(o->clo, &o->cif, call_py_func, MP_OBJ_TO_PTR(func_in), o->func); + res = ffi_prep_closure_loc(o->clo, &o->cif, + lock_in? call_py_func_with_lock: call_py_func, o, o->func); if (res != FFI_OK) { mp_raise_ValueError(MP_ERROR_TEXT("ffi_prep_closure_loc")); } return MP_OBJ_FROM_PTR(o); } -MP_DEFINE_CONST_FUN_OBJ_3(mod_ffi_callback_obj, mod_ffi_callback); +MP_DEFINE_CONST_FUN_OBJ_KW(mod_ffi_callback_obj, 3, mod_ffi_callback); STATIC mp_obj_t ffimod_var(mp_obj_t self_in, mp_obj_t vartype_in, mp_obj_t symname_in) { mp_obj_ffimod_t *self = MP_OBJ_TO_PTR(self_in); @@ -343,9 +397,9 @@ STATIC mp_obj_t ffimod_addr(mp_obj_t self_in, mp_obj_t symname_in) { } MP_DEFINE_CONST_FUN_OBJ_2(ffimod_addr_obj, ffimod_addr); -STATIC mp_obj_t ffimod_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t ffimod_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)n_args; - (void)kw_args; + (void)n_kw; const char *fname = NULL; if (args[0] != mp_const_none) { @@ -501,10 +555,22 @@ STATIC void fficallback_print(const mp_print_t *print, mp_obj_t self_in, mp_prin mp_printf(print, "", self->func); } +STATIC mp_obj_t fficallback_cfun(mp_obj_t self_in) { + mp_obj_fficallback_t *self = MP_OBJ_TO_PTR(self_in); + return mp_obj_new_int_from_ull((uintptr_t)self->func); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_1(fficallback_cfun_obj, fficallback_cfun); + +STATIC const mp_rom_map_elem_t fficallback_locals_dict_table[] = { + { MP_ROM_QSTR(MP_QSTR_cfun), MP_ROM_PTR(&fficallback_cfun_obj) } +}; +STATIC MP_DEFINE_CONST_DICT(fficallback_locals_dict, fficallback_locals_dict_table); + STATIC const mp_obj_type_t fficallback_type = { { &mp_type_type }, .name = MP_QSTR_fficallback, .print = fficallback_print, + .locals_dict = (mp_obj_dict_t *)&fficallback_locals_dict }; // FFI variable @@ -554,7 +620,7 @@ STATIC const mp_obj_type_t opaque_type = { */ STATIC mp_obj_t mod_ffi_open(size_t n_args, const mp_obj_t *args) { - return ffimod_make_new(&ffimod_type, n_args, args, NULL); + return ffimod_make_new(&ffimod_type, n_args, 0, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_ffi_open_obj, 1, 2, mod_ffi_open); diff --git a/ports/unix/modjni.c b/ports/unix/modjni.c index bf039c0b71..bd151050ea 100644 --- a/ports/unix/modjni.c +++ b/ports/unix/modjni.c @@ -102,9 +102,9 @@ STATIC void check_exception(void) { mp_obj_t py_e = new_jobject(exc); JJ1(ExceptionClear); if (JJ(IsInstanceOf, exc, IndexException_class)) { - mp_raise_arg1(&mp_type_IndexError, py_e); + mp_raise_type_arg(&mp_type_IndexError, py_e); } - mp_raise_arg1(&mp_type_Exception, py_e); + mp_raise_type_arg(&mp_type_Exception, py_e); } } diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h index 166825ab81..da3c71d776 100644 --- a/ports/unix/mpconfigport.h +++ b/ports/unix/mpconfigport.h @@ -89,6 +89,7 @@ #define MICROPY_PY_FUNCTION_ATTRS (1) #define MICROPY_PY_DESCRIPTORS (1) #define MICROPY_PY_DELATTR_SETATTR (1) +#define MICROPY_PY_FSTRINGS (1) #define MICROPY_PY_BUILTINS_STR_UNICODE (1) #define MICROPY_PY_BUILTINS_STR_CENTER (1) #define MICROPY_PY_BUILTINS_STR_PARTITION (1) diff --git a/ports/unix/mphalport.h b/ports/unix/mphalport.h index 5d3e2a2482..9242bef1ad 100644 --- a/ports/unix/mphalport.h +++ b/ports/unix/mphalport.h @@ -54,7 +54,7 @@ static inline int mp_hal_readline(vstr_t *vstr, const char *p) { #elif MICROPY_PY_BUILTINS_INPUT && MICROPY_USE_READLINE == 1 #include "py/misc.h" -#include "lib/mp-readline/readline.h" +#include "shared/readline/readline.h" // For built-in input() we need to wrap the standard readline() to enable raw mode #define mp_hal_readline mp_hal_readline static inline int mp_hal_readline(vstr_t *vstr, const char *p) { diff --git a/ports/unix/mpthreadport.c b/ports/unix/mpthreadport.c index fe4030f08d..6a0ce59377 100644 --- a/ports/unix/mpthreadport.c +++ b/ports/unix/mpthreadport.c @@ -39,7 +39,7 @@ #include #include -#include "lib/utils/gchelper.h" +#include "shared/runtime/gchelper.h" // Some platforms don't have SIGRTMIN but if we do have it, use it to avoid // potential conflict with other uses of the more commonly used SIGUSR1. diff --git a/ports/unix/unix_mphal.c b/ports/unix/unix_mphal.c index fceff68284..9d50652e39 100644 --- a/ports/unix/unix_mphal.c +++ b/ports/unix/unix_mphal.c @@ -53,7 +53,7 @@ STATIC void sighandler(int signum) { sigprocmask(SIG_SETMASK, &mask, NULL); nlr_raise(MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))); #else - if (MP_STATE_VM(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))) { + if (MP_STATE_MAIN_THREAD(mp_pending_exception) == MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_kbd_exception))) { // this is the second time we are called, so die straight away exit(1); } diff --git a/ports/unix/variants/dev/mpconfigvariant.h b/ports/unix/variants/dev/mpconfigvariant.h index 7c3e84cc44..54ad993236 100644 --- a/ports/unix/variants/dev/mpconfigvariant.h +++ b/ports/unix/variants/dev/mpconfigvariant.h @@ -31,6 +31,8 @@ #define MICROPY_VFS (1) #define MICROPY_VFS_POSIX (1) +#define MICROPY_PY_BUILTINS_HELP (1) +#define MICROPY_PY_BUILTINS_HELP_MODULES (1) #define MICROPY_PY_SYS_SETTRACE (1) #define MICROPY_PY_UOS_VFS (1) #define MICROPY_PY_URANDOM_EXTRA_FUNCS (1) diff --git a/ports/unix/variants/standard/mpconfigvariant.h b/ports/unix/variants/standard/mpconfigvariant.h index 2868f949cc..3cdcfa8e9b 100644 --- a/ports/unix/variants/standard/mpconfigvariant.h +++ b/ports/unix/variants/standard/mpconfigvariant.h @@ -23,3 +23,6 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ + +#define MICROPY_PY_BUILTINS_HELP (1) +#define MICROPY_PY_BUILTINS_HELP_MODULES (1) diff --git a/py/argcheck.c b/py/argcheck.c index af7a3a020e..aa88eeed6c 100644 --- a/py/argcheck.c +++ b/py/argcheck.c @@ -77,14 +77,6 @@ void mp_arg_check_num_sig(size_t n_args, size_t n_kw, uint32_t sig) { } } -inline void mp_arg_check_num(size_t n_args, mp_map_t *kw_args, size_t n_args_min, size_t n_args_max, bool takes_kw) { - size_t n_kw = 0; - if (kw_args != NULL) { - n_kw = kw_args->used; - } - mp_arg_check_num_sig(n_args, n_kw, MP_OBJ_FUN_MAKE_SIG(n_args_min, n_args_max, takes_kw)); -} - inline void mp_arg_check_num_kw_array(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_args_max, bool takes_kw) { mp_arg_check_num_sig(n_args, n_kw, MP_OBJ_FUN_MAKE_SIG(n_args_min, n_args_max, takes_kw)); } diff --git a/py/bc.h b/py/bc.h index 410ca800c8..e901f7bb34 100644 --- a/py/bc.h +++ b/py/bc.h @@ -128,7 +128,9 @@ #define MP_BC_PRELUDE_SIG_DECODE(ip) \ size_t n_state, n_exc_stack, scope_flags, n_pos_args, n_kwonly_args, n_def_pos_args; \ - MP_BC_PRELUDE_SIG_DECODE_INTO(ip, n_state, n_exc_stack, scope_flags, n_pos_args, n_kwonly_args, n_def_pos_args) + MP_BC_PRELUDE_SIG_DECODE_INTO(ip, n_state, n_exc_stack, scope_flags, n_pos_args, n_kwonly_args, n_def_pos_args); \ + (void)n_state; (void)n_exc_stack; (void)scope_flags; \ + (void)n_pos_args; (void)n_kwonly_args; (void)n_def_pos_args #define MP_BC_PRELUDE_SIZE_ENCODE(I, C, out_byte, out_env) \ do { \ @@ -163,7 +165,8 @@ #define MP_BC_PRELUDE_SIZE_DECODE(ip) \ size_t n_info, n_cell; \ - MP_BC_PRELUDE_SIZE_DECODE_INTO(ip, n_info, n_cell) + MP_BC_PRELUDE_SIZE_DECODE_INTO(ip, n_info, n_cell); \ + (void)n_info; (void)n_cell // Sentinel value for mp_code_state_t.exc_sp_idx #define MP_CODE_STATE_EXC_SP_IDX_SENTINEL ((uint16_t)-1) diff --git a/py/binary.c b/py/binary.c index d700ab3848..06f0157567 100644 --- a/py/binary.c +++ b/py/binary.c @@ -212,7 +212,7 @@ long long mp_binary_get_int(size_t size, bool is_signed, bool big_endian, const delta = 1; } - long long val = 0; + unsigned long long val = 0; if (is_signed && *src & 0x80) { val = -1; } diff --git a/py/builtinimport.c b/py/builtinimport.c index d49ef2a9d5..5baef16d86 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -153,7 +153,7 @@ STATIC void do_load_from_lexer(mp_obj_t module_obj, mp_lexer_t *lex) { } #endif -#if MICROPY_PERSISTENT_CODE_LOAD || MICROPY_MODULE_FROZEN_MPY +#if (MICROPY_HAS_FILE_READER && MICROPY_PERSISTENT_CODE_LOAD) || MICROPY_MODULE_FROZEN_MPY STATIC void do_execute_raw_code(mp_obj_t module_obj, mp_raw_code_t *raw_code, const char *source_name) { (void)source_name; #if MICROPY_PY___FILE__ diff --git a/py/circuitpy_defns.mk b/py/circuitpy_defns.mk index 836f3c7af1..7d2d128a73 100644 --- a/py/circuitpy_defns.mk +++ b/py/circuitpy_defns.mk @@ -680,17 +680,17 @@ endif endif SRC_CIRCUITPY_COMMON = \ - lib/libc/string0.c \ - lib/mp-readline/readline.c \ + shared/libc/string0.c \ + shared/readline/readline.c \ lib/oofatfs/ff.c \ lib/oofatfs/ffunicode.c \ - lib/timeutils/timeutils.c \ - lib/utils/buffer_helper.c \ - lib/utils/context_manager_helpers.c \ - lib/utils/interrupt_char.c \ - lib/utils/pyexec.c \ - lib/utils/stdout_helpers.c \ - lib/utils/sys_stdio_mphal.c + shared/timeutils/timeutils.c \ + shared/runtime/buffer_helper.c \ + shared/runtime/context_manager_helpers.c \ + shared/runtime/interrupt_char.c \ + shared/runtime/pyexec.c \ + shared/runtime/stdout_helpers.c \ + shared/runtime/sys_stdio_mphal.c ifeq ($(CIRCUITPY_QRIO),1) SRC_CIRCUITPY_COMMON += lib/quirc/lib/decode.c lib/quirc/lib/identify.c lib/quirc/lib/quirc.c lib/quirc/lib/version_db.c @@ -706,7 +706,7 @@ GENERATED_LD_FILE = $(BUILD)/$(notdir $(patsubst %.template.ld,%.ld,$(LD_TEMPLAT # because it may include other template files. $(GENERATED_LD_FILE): $(BUILD)/ld_defines.pp boards/*.template.ld $(STEPECHO) "GEN $@" - $(Q)$(PYTHON3) $(TOP)/tools/gen_ld_files.py --defines $< --out_dir $(BUILD) boards/*.template.ld + $(Q)$(PYTHON) $(TOP)/tools/gen_ld_files.py --defines $< --out_dir $(BUILD) boards/*.template.ld endif .PHONY: check-release-needs-clean-build diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 3608b9c71d..3c6d5c6110 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -77,6 +77,8 @@ #define MICROPY_NONSTANDARD_TYPECODES (0) #define MICROPY_OPT_COMPUTED_GOTO (1) #define MICROPY_OPT_COMPUTED_GOTO_SAVE_SPACE (CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE) +#define MICROPY_OPT_LOAD_ATTR_FAST_PATH (CIRCUITPY_OPT_LOAD_ATTR_FAST_PATH) +#define MICROPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE (CIRCUITPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE) #define MICROPY_PERSISTENT_CODE_LOAD (1) #define MICROPY_PY_ARRAY (1) @@ -194,7 +196,7 @@ typedef long mp_off_t; #define MICROPY_CPYTHON_COMPAT (CIRCUITPY_FULL_BUILD) #endif #define MICROPY_PY_BUILTINS_POW3 (CIRCUITPY_BUILTINS_POW3) -#define MICROPY_COMP_FSTRING_LITERAL (MICROPY_CPYTHON_COMPAT) +#define MICROPY_PY_FSTRINGS (MICROPY_CPYTHON_COMPAT) #define MICROPY_MODULE_WEAK_LINKS (0) #define MICROPY_PY_ALL_SPECIAL_METHODS (CIRCUITPY_FULL_BUILD) #ifndef MICROPY_PY_BUILTINS_COMPLEX diff --git a/py/circuitpy_mpconfig.mk b/py/circuitpy_mpconfig.mk index 51e6fb8a11..be373b78a2 100644 --- a/py/circuitpy_mpconfig.mk +++ b/py/circuitpy_mpconfig.mk @@ -145,6 +145,17 @@ CFLAGS += -DCIRCUITPY_DIGITALIO=$(CIRCUITPY_DIGITALIO) CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE ?= 0 CFLAGS += -DCIRCUITPY_COMPUTED_GOTO_SAVE_SPACE=$(CIRCUITPY_COMPUTED_GOTO_SAVE_SPACE) +CIRCUITPY_OPT_LOAD_ATTR_FAST_PATH ?= 1 +CFLAGS += -DCIRCUITPY_OPT_LOAD_ATTR_FAST_PATH=$(CIRCUITPY_OPT_LOAD_ATTR_FAST_PATH) + +# This is disabled because it changes the bytecode format. We could choose to enable it +# when we go to 8.x, but probably not for 7.1. +CIRCUITPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE ?= 0 +CFLAGS += -DCIRCUITPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE=$(CIRCUITPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE) +ifeq ($(CIRCUITPY_OPT_CACHE_MAP_LOOKUP_IN_BYTECODE),1) +MPY_CROSS_FLAGS += -mcache-lookup-bc +endif + CIRCUITPY_CONSOLE_UART ?= 0 CFLAGS += -DCIRCUITPY_CONSOLE_UART=$(CIRCUITPY_CONSOLE_UART) diff --git a/py/dynruntime.h b/py/dynruntime.h index 2ba344e6c8..0a7eb20397 100644 --- a/py/dynruntime.h +++ b/py/dynruntime.h @@ -188,10 +188,7 @@ static inline mp_obj_t mp_obj_len_dyn(mp_obj_t o) { #define mp_call_function_n_kw(fun, n_args, n_kw, args) \ (mp_fun_table.call_function_n_kw((fun), (n_args) | ((n_kw) << 8), args)) -#define mp_arg_check_num(n_args, kw_args, n_args_min, n_args_max, takes_kw) \ - (mp_fun_table.arg_check_num_sig((n_args), (kw_args) ? kw_args->used : 0, MP_OBJ_FUN_MAKE_SIG((n_args_min), (n_args_max), (takes_kw)))) - -#define mp_arg_check_num_mp(n_args, n_kw, n_args_min, n_args_max, takes_kw) \ +#define mp_arg_check_num(n_args, n_kw, n_args_min, n_args_max, takes_kw) \ (mp_fun_table.arg_check_num_sig((n_args), (n_kw), MP_OBJ_FUN_MAKE_SIG((n_args_min), (n_args_max), (takes_kw)))) #define MP_DYNRUNTIME_INIT_ENTRY \ @@ -223,6 +220,7 @@ static inline mp_obj_t mp_obj_len_dyn(mp_obj_t o) { #define mp_obj_new_exception_arg1(e_type, arg) (mp_obj_new_exception_arg1_dyn((e_type), (arg))) #define nlr_raise(o) (mp_raise_dyn(o)) +#define mp_raise_type_arg(type, arg) (mp_raise_dyn(mp_obj_new_exception_arg1_dyn((type), (arg)))) #define mp_raise_msg(type, msg) (mp_fun_table.raise_msg_str((type), (msg))) #define mp_raise_OSError(er) (mp_raise_OSError_dyn(er)) #define mp_raise_NotImplementedError(msg) (mp_raise_msg(&mp_type_NotImplementedError, (msg))) diff --git a/py/emitnative.c b/py/emitnative.c index 1fa8c631e4..c5d9fecb4c 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -869,10 +869,13 @@ STATIC void need_reg_single(emit_t *emit, int reg_needed, int skip_stack_pos) { } } +// Ensures all unsettled registers that hold Python values are copied to the +// concrete Python stack. All registers are then free to use. STATIC void need_reg_all(emit_t *emit) { for (int i = 0; i < emit->stack_size; i++) { stack_info_t *si = &emit->stack_info[i]; if (si->kind == STACK_REG) { + DEBUG_printf(" reg(%u) to local(%u)\n", si->data.u_reg, emit->stack_start + i); si->kind = STACK_VALUE; emit_native_mov_state_reg(emit, emit->stack_start + i, si->data.u_reg); } @@ -899,23 +902,21 @@ STATIC vtype_kind_t load_reg_stack_imm(emit_t *emit, int reg_dest, const stack_i } } +// Copies all unsettled registers and immediates that are Python values into the +// concrete Python stack. This ensures the concrete Python stack holds valid +// values for the current stack_size. +// This function may clobber REG_TEMP1. STATIC void need_stack_settled(emit_t *emit) { DEBUG_printf(" need_stack_settled; stack_size=%d\n", emit->stack_size); - for (int i = 0; i < emit->stack_size; i++) { - stack_info_t *si = &emit->stack_info[i]; - if (si->kind == STACK_REG) { - DEBUG_printf(" reg(%u) to local(%u)\n", si->data.u_reg, emit->stack_start + i); - si->kind = STACK_VALUE; - emit_native_mov_state_reg(emit, emit->stack_start + i, si->data.u_reg); - } - } + need_reg_all(emit); for (int i = 0; i < emit->stack_size; i++) { stack_info_t *si = &emit->stack_info[i]; if (si->kind == STACK_IMM) { DEBUG_printf(" imm(" INT_FMT ") to local(%u)\n", si->data.u_imm, emit->stack_start + i); si->kind = STACK_VALUE; - si->vtype = load_reg_stack_imm(emit, REG_TEMP0, si, false); - emit_native_mov_state_reg(emit, emit->stack_start + i, REG_TEMP0); + // using REG_TEMP1 to avoid clobbering REG_TEMP0 (aka REG_RET) + si->vtype = load_reg_stack_imm(emit, REG_TEMP1, si, false); + emit_native_mov_state_reg(emit, emit->stack_start + i, REG_TEMP1); } } } diff --git a/py/lexer.c b/py/lexer.c index c6506ebcee..ce48adbfa5 100644 --- a/py/lexer.c +++ b/py/lexer.c @@ -64,7 +64,7 @@ STATIC bool is_char_or3(mp_lexer_t *lex, byte c1, byte c2, byte c3) { return lex->chr0 == c1 || lex->chr0 == c2 || lex->chr0 == c3; } -#if MICROPY_COMP_FSTRING_LITERAL +#if MICROPY_PY_FSTRINGS STATIC bool is_char_or4(mp_lexer_t *lex, byte c1, byte c2, byte c3, byte c4) { return lex->chr0 == c1 || lex->chr0 == c2 || lex->chr0 == c3 || lex->chr0 == c4; } @@ -113,10 +113,10 @@ STATIC bool is_following_odigit(mp_lexer_t *lex) { STATIC bool is_string_or_bytes(mp_lexer_t *lex) { return is_char_or(lex, '\'', '\"') - #if MICROPY_COMP_FSTRING_LITERAL + #if MICROPY_PY_FSTRINGS || (is_char_or4(lex, 'r', 'u', 'b', 'f') && is_char_following_or(lex, '\'', '\"')) - || ((is_char_and(lex, 'r', 'f') || is_char_and(lex, 'f', 'r')) - && is_char_following_following_or(lex, '\'', '\"')) + || (((is_char_and(lex, 'r', 'f') || is_char_and(lex, 'f', 'r')) + && is_char_following_following_or(lex, '\'', '\"'))) #else || (is_char_or3(lex, 'r', 'u', 'b') && is_char_following_or(lex, '\'', '\"')) #endif @@ -133,31 +133,6 @@ STATIC bool is_tail_of_identifier(mp_lexer_t *lex) { return is_head_of_identifier(lex) || is_digit(lex); } -#if MICROPY_COMP_FSTRING_LITERAL -STATIC void swap_char_banks(mp_lexer_t *lex) { - if (lex->vstr_postfix_processing) { - lex->chr3 = lex->chr0; - lex->chr4 = lex->chr1; - lex->chr5 = lex->chr2; - lex->chr0 = lex->vstr_postfix.buf[0]; - lex->chr1 = lex->vstr_postfix.buf[1]; - lex->chr2 = lex->vstr_postfix.buf[2]; - - lex->vstr_postfix_idx = 3; - } else { - // blindly reset to the "backup" bank when done postfix processing - // this restores control to the mp_reader - lex->chr0 = lex->chr3; - lex->chr1 = lex->chr4; - lex->chr2 = lex->chr5; - // willfully ignoring setting chr3-5 here - WARNING consider those garbage data now - - vstr_reset(&lex->vstr_postfix); - lex->vstr_postfix_idx = 0; - } -} -#endif - STATIC void next_char(mp_lexer_t *lex) { if (lex->chr0 == '\n') { // a new line @@ -171,15 +146,29 @@ STATIC void next_char(mp_lexer_t *lex) { ++lex->column; } + // shift the input queue forward lex->chr0 = lex->chr1; lex->chr1 = lex->chr2; - #if MICROPY_COMP_FSTRING_LITERAL - if (lex->vstr_postfix_processing) { - if (lex->vstr_postfix_idx == lex->vstr_postfix.len) { - lex->chr2 = '\0'; + // and add the next byte from either the fstring args or the reader + #if MICROPY_PY_FSTRINGS + if (lex->fstring_args_idx) { + // if there are saved chars, then we're currently injecting fstring args + if (lex->fstring_args_idx < lex->fstring_args.len) { + lex->chr2 = lex->fstring_args.buf[lex->fstring_args_idx++]; } else { - lex->chr2 = lex->vstr_postfix.buf[lex->vstr_postfix_idx++]; + // no more fstring arg bytes + lex->chr2 = '\0'; + } + + if (lex->chr0 == '\0') { + // consumed all fstring data, restore saved input queue + lex->chr0 = lex->chr0_saved; + lex->chr1 = lex->chr1_saved; + lex->chr2 = lex->chr2_saved; + // stop consuming fstring arg data + vstr_reset(&lex->fstring_args); + lex->fstring_args_idx = 0; } } else #endif @@ -200,13 +189,6 @@ STATIC void next_char(mp_lexer_t *lex) { if (lex->chr2 == MP_LEXER_EOF && lex->chr1 != MP_LEXER_EOF && lex->chr1 != '\n') { lex->chr2 = '\n'; } - - #if MICROPY_COMP_FSTRING_LITERAL - if (lex->vstr_postfix_processing && lex->chr0 == '\0') { - lex->vstr_postfix_processing = false; - swap_char_banks(lex); - } - #endif } STATIC void indent_push(mp_lexer_t *lex, size_t indent) { @@ -351,9 +333,14 @@ STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw, bool is_fstring) } size_t n_closing = 0; - #if MICROPY_COMP_FSTRING_LITERAL - bool in_expression = false; - bool expression_eat = true; + #if MICROPY_PY_FSTRINGS + if (is_fstring) { + // assume there's going to be interpolation, so prep the injection data + // fstring_args_idx==0 && len(fstring_args)>0 means we're extracting the args. + // only when fstring_args_idx>0 will we consume the arg data + // note: lex->fstring_args will be empty already (it's reset when finished) + vstr_add_str(&lex->fstring_args, ".format("); + } #endif while (!is_end(lex) && (num_quotes > 1 || !is_char(lex, '\n')) && n_closing < num_quotes) { @@ -362,53 +349,38 @@ STATIC void parse_string_literal(mp_lexer_t *lex, bool is_raw, bool is_fstring) vstr_add_char(&lex->vstr, CUR_CHAR(lex)); } else { n_closing = 0; - #if MICROPY_COMP_FSTRING_LITERAL - if (is_fstring && is_char(lex, '{')) { - vstr_add_char(&lex->vstr, CUR_CHAR(lex)); - in_expression = !in_expression; - expression_eat = in_expression; - - if (lex->vstr_postfix.len == 0) { - vstr_add_str(&lex->vstr_postfix, ".format("); - } + #if MICROPY_PY_FSTRINGS + while (is_fstring && is_char(lex, '{')) { next_char(lex); - continue; - } - - if (is_fstring && is_char(lex, '}')) { - vstr_add_char(&lex->vstr, CUR_CHAR(lex)); - - if (in_expression) { - in_expression = false; - vstr_add_char(&lex->vstr_postfix, ','); - } - - next_char(lex); - continue; - } - - if (in_expression) { - // throw errors for illegal chars inside f-string expressions - if (is_char(lex, '#')) { - lex->tok_kind = MP_TOKEN_FSTRING_COMMENT; - return; - } else if (is_char(lex, '\\')) { - lex->tok_kind = MP_TOKEN_FSTRING_BACKSLASH; - return; - } else if (is_char(lex, ':')) { - expression_eat = false; - } - - unichar c = CUR_CHAR(lex); - if (expression_eat) { - vstr_add_char(&lex->vstr_postfix, c); + if (is_char(lex, '{')) { + // "{{" is passed through unchanged to be handled by str.format + vstr_add_byte(&lex->vstr, '{'); + next_char(lex); } else { - vstr_add_char(&lex->vstr, c); + // remember the start of this argument (if we need it for f'{a=}'). + size_t i = lex->fstring_args.len; + // extract characters inside the { until we reach the + // format specifier or closing }. + // (MicroPython limitation) note: this is completely unaware of + // Python syntax and will not handle any expression containing '}' or ':'. + // e.g. f'{"}"}' or f'{foo({})}'. + while (!is_end(lex) && !is_char_or(lex, ':', '}')) { + // like the default case at the end of this function, stay 8-bit clean + vstr_add_byte(&lex->fstring_args, CUR_CHAR(lex)); + next_char(lex); + } + if (lex->fstring_args.buf[lex->fstring_args.len - 1] == '=') { + // if the last character of the arg was '=', then inject "arg=" before the '{'. + // f'{a=}' --> 'a={}'.format(a) + vstr_add_strn(&lex->vstr, lex->fstring_args.buf + i, lex->fstring_args.len - i); + // remove the trailing '=' + lex->fstring_args.len--; + } + // comma-separate args + vstr_add_byte(&lex->fstring_args, ','); } - - next_char(lex); - continue; + vstr_add_byte(&lex->vstr, '{'); } #endif @@ -565,12 +537,20 @@ STATIC bool skip_whitespace(mp_lexer_t *lex, bool stop_at_newline) { } void mp_lexer_to_next(mp_lexer_t *lex) { - #if MICROPY_COMP_FSTRING_LITERAL - if (lex->vstr_postfix.len && !lex->vstr_postfix_processing) { - // end format call injection - vstr_add_char(&lex->vstr_postfix, ')'); - lex->vstr_postfix_processing = true; - swap_char_banks(lex); + #if MICROPY_PY_FSTRINGS + if (lex->fstring_args.len && lex->fstring_args_idx == 0) { + // moving onto the next token means the literal string is complete. + // switch into injecting the format args. + vstr_add_byte(&lex->fstring_args, ')'); + lex->chr0_saved = lex->chr0; + lex->chr1_saved = lex->chr1; + lex->chr2_saved = lex->chr2; + lex->chr0 = lex->fstring_args.buf[0]; + lex->chr1 = lex->fstring_args.buf[1]; + lex->chr2 = lex->fstring_args.buf[2]; + // we've already extracted 3 chars, but setting this non-zero also + // means we'll start consuming the fstring data + lex->fstring_args_idx = 3; } #endif @@ -625,19 +605,11 @@ void mp_lexer_to_next(mp_lexer_t *lex) { // MP_TOKEN_END is used to indicate that this is the first string token lex->tok_kind = MP_TOKEN_END; - #if MICROPY_COMP_FSTRING_LITERAL - bool saw_normal = false, saw_fstring = false; - #endif - // Loop to accumulate string/bytes literals do { // parse type codes bool is_raw = false; - #if MICROPY_COMP_FSTRING_LITERAL bool is_fstring = false; - #else - const bool is_fstring = false; - #endif mp_token_kind_t kind = MP_TOKEN_STRING; int n_char = 0; if (is_char(lex, 'u')) { @@ -656,31 +628,23 @@ void mp_lexer_to_next(mp_lexer_t *lex) { kind = MP_TOKEN_BYTES; n_char = 2; } - #if MICROPY_COMP_FSTRING_LITERAL + #if MICROPY_PY_FSTRINGS if (is_char_following(lex, 'f')) { + // raw-f-strings unsupported, immediately return (invalid) token. lex->tok_kind = MP_TOKEN_FSTRING_RAW; break; } - } else if (is_char(lex, 'f')) { + #endif + } + #if MICROPY_PY_FSTRINGS + else if (is_char(lex, 'f')) { if (is_char_following(lex, 'r')) { + // raw-f-strings unsupported, immediately return (invalid) token. lex->tok_kind = MP_TOKEN_FSTRING_RAW; break; } n_char = 1; is_fstring = true; - #endif - } - - #if MICROPY_COMP_FSTRING_LITERAL - if (is_fstring) { - saw_fstring = true; - } else { - saw_normal = true; - } - - if (saw_fstring && saw_normal) { - // Can't concatenate f-string with normal string - break; } #endif @@ -860,8 +824,8 @@ mp_lexer_t *mp_lexer_new(qstr src_name, mp_reader_t reader) { lex->num_indent_level = 1; lex->indent_level = m_new(uint16_t, lex->alloc_indent_level); vstr_init(&lex->vstr, 32); - #if MICROPY_COMP_FSTRING_LITERAL - vstr_init(&lex->vstr_postfix, 0); + #if MICROPY_PY_FSTRINGS + vstr_init(&lex->fstring_args, 0); #endif // store sentinel for first indentation level @@ -916,6 +880,9 @@ void mp_lexer_free(mp_lexer_t *lex) { if (lex) { lex->reader.close(lex->reader.data); vstr_clear(&lex->vstr); + #if MICROPY_PY_FSTRINGS + vstr_clear(&lex->fstring_args); + #endif m_del(uint16_t, lex->indent_level, lex->alloc_indent_level); m_del_obj(mp_lexer_t, lex); } diff --git a/py/lexer.h b/py/lexer.h index 8f9960877c..bcc1c04a68 100644 --- a/py/lexer.h +++ b/py/lexer.h @@ -44,12 +44,8 @@ typedef enum _mp_token_kind_t { MP_TOKEN_INVALID, MP_TOKEN_DEDENT_MISMATCH, MP_TOKEN_LONELY_STRING_OPEN, - #if MICROPY_COMP_FSTRING_LITERAL - MP_TOKEN_FSTRING_BACKSLASH, - MP_TOKEN_FSTRING_COMMENT, - MP_TOKEN_FSTRING_UNCLOSED, - MP_TOKEN_FSTRING_UNOPENED, - MP_TOKEN_FSTRING_EMPTY_EXP, + #if MICROPY_PY_FSTRINGS + MP_TOKEN_MALFORMED_FSTRING, MP_TOKEN_FSTRING_RAW, #endif @@ -166,8 +162,8 @@ typedef struct _mp_lexer_t { mp_reader_t reader; // stream source unichar chr0, chr1, chr2; // current cached characters from source - #if MICROPY_COMP_FSTRING_LITERAL - unichar chr3, chr4, chr5; // current cached characters from alt source + #if MICROPY_PY_FSTRINGS + unichar chr0_saved, chr1_saved, chr2_saved; // current cached characters from alt source #endif size_t line; // current source line @@ -184,10 +180,9 @@ typedef struct _mp_lexer_t { size_t tok_column; // token source column mp_token_kind_t tok_kind; // token kind vstr_t vstr; // token data - #if MICROPY_COMP_FSTRING_LITERAL - vstr_t vstr_postfix; // postfix to apply to string - bool vstr_postfix_processing; - uint16_t vstr_postfix_idx; + #if MICROPY_PY_FSTRINGS + vstr_t fstring_args; // extracted arguments to pass to .format() + size_t fstring_args_idx; // how many bytes of fstring_args have been read #endif } mp_lexer_t; diff --git a/py/makeqstrdefs.py b/py/makeqstrdefs.py index bebbebab20..f035ed5745 100644 --- a/py/makeqstrdefs.py +++ b/py/makeqstrdefs.py @@ -79,7 +79,7 @@ def preprocess(): for source in sources: if source.endswith(".cpp"): cxxsources.append(source) - else: + elif source.endswith(".c"): csources.append(source) try: os.makedirs(os.path.dirname(args.output[0])) diff --git a/py/makeversionhdr.py b/py/makeversionhdr.py index a89eb35e15..9eca9525b2 100644 --- a/py/makeversionhdr.py +++ b/py/makeversionhdr.py @@ -23,7 +23,7 @@ def get_version_info_from_git(): # Note: git describe doesn't work if no tag is available try: git_tag = subprocess.check_output( - ["git", "describe", "--dirty", "--always", "--tags", "--match", "[1-9].*"], + ["git", "describe", "--tags", "--dirty", "--always", "--match", "[1-9].*"], stderr=subprocess.STDOUT, universal_newlines=True, ).strip() diff --git a/py/misc.h b/py/misc.h index 99fadde696..8f2d3a187a 100644 --- a/py/misc.h +++ b/py/misc.h @@ -57,6 +57,7 @@ typedef unsigned int uint; // Round-up integer division #define MP_CEIL_DIVIDE(a, b) (((a) + (b) - 1) / (b)) +#define MP_ROUND_DIVIDE(a, b) (((a) + (b) / 2) / (b)) /** memory allocation ******************************************/ diff --git a/py/mkenv.mk b/py/mkenv.mk index ab17a98f67..e2cdb2ddb6 100644 --- a/py/mkenv.mk +++ b/py/mkenv.mk @@ -46,16 +46,13 @@ CD = cd CP = cp FIND = find MKDIR = mkdir -PYTHON = python -# Set default python interpreters -PYTHON2 ?= $(which python2 || which python2.7) -PYTHON3 ?= python3 +PYTHON = python3 RM = rm RSYNC = rsync SED = sed TOUCH = touch # Linux has 'nproc', macOS has 'sysctl -n hw.logicalcpu', this is cross-platform -NPROC = $(PYTHON3) -c 'import multiprocessing as mp; print(mp.cpu_count())' +NPROC = $(PYTHON) -c 'import multiprocessing as mp; print(mp.cpu_count())' AS = $(CROSS_COMPILE)as CC = $(CROSS_COMPILE)gcc @@ -67,14 +64,17 @@ SIZE = $(CROSS_COMPILE)size STRIP = $(CROSS_COMPILE)strip AR = $(CROSS_COMPILE)ar -MAKE_FROZEN = $(PYTHON3) $(TOP)/tools/make-frozen.py -MPY_CROSS = $(TOP)/mpy-cross/mpy-cross -MPY_TOOL = $(PYTHON3) $(TOP)/tools/mpy-tool.py +MAKE_MANIFEST = $(PYTHON) $(TOP)/tools/makemanifest.py +MAKE_FROZEN = $(PYTHON) $(TOP)/tools/make-frozen.py +MPY_TOOL = $(PYTHON) $(TOP)/tools/mpy-tool.py PREPROCESS_FROZEN_MODULES = PYTHONPATH=$(TOP)/tools/python-semver $(TOP)/tools/preprocess_frozen_modules.py MPY_LIB_DIR = $(TOP)/../micropython-lib -MPY_LIB_DIR = $(TOP)/../micropython-lib +ifeq ($(MICROPY_MPYCROSS),) +MICROPY_MPYCROSS = $(TOP)/mpy-cross/mpy-cross +MICROPY_MPYCROSS_DEPENDENCY = $(MICROPY_MPYCROSS) +endif all: .PHONY: all diff --git a/py/mkrules.cmake b/py/mkrules.cmake index 7589255b20..9d08017931 100644 --- a/py/mkrules.cmake +++ b/py/mkrules.cmake @@ -129,11 +129,27 @@ if(MICROPY_FROZEN_MANIFEST) set(MICROPY_LIB_DIR ${MICROPY_DIR}/../micropython-lib) endif() + # If MICROPY_MPYCROSS is not explicitly defined in the environment (which + # is what makemanifest.py will use) then create an mpy-cross dependency + # to automatically build mpy-cross if needed. + set(MICROPY_MPYCROSS $ENV{MICROPY_MPYCROSS}) + if(NOT MICROPY_MPYCROSS) + set(MICROPY_MPYCROSS_DEPENDENCY ${MICROPY_DIR}/mpy-cross/mpy-cross) + if(NOT MICROPY_MAKE_EXECUTABLE) + set(MICROPY_MAKE_EXECUTABLE make) + endif() + add_custom_command( + OUTPUT ${MICROPY_MPYCROSS_DEPENDENCY} + COMMAND ${MICROPY_MAKE_EXECUTABLE} -C ${MICROPY_DIR}/mpy-cross + ) + endif() + add_custom_command( OUTPUT ${MICROPY_FROZEN_CONTENT} COMMAND ${Python3_EXECUTABLE} ${MICROPY_DIR}/tools/makemanifest.py -o ${MICROPY_FROZEN_CONTENT} -v "MPY_DIR=${MICROPY_DIR}" -v "MPY_LIB_DIR=${MICROPY_LIB_DIR}" -v "PORT_DIR=${MICROPY_PORT_DIR}" -v "BOARD_DIR=${MICROPY_BOARD_DIR}" -b "${CMAKE_BINARY_DIR}" -f${MICROPY_CROSS_FLAGS} ${MICROPY_FROZEN_MANIFEST} DEPENDS MICROPY_FORCE_BUILD ${MICROPY_QSTRDEFS_GENERATED} + ${MICROPY_MPYCROSS_DEPENDENCY} VERBATIM ) endif() diff --git a/py/mkrules.mk b/py/mkrules.mk index 50f35ffb22..b121260c07 100644 --- a/py/mkrules.mk +++ b/py/mkrules.mk @@ -95,14 +95,14 @@ $(OBJ): | $(HEADER_BUILD)/qstrdefs.enum.h $(HEADER_BUILD)/mpversion.h # - if anything in QSTR_GLOBAL_DEPENDENCIES is newer, then process all source files ($^) # - else, if list of newer prerequisites ($?) is not empty, then process just these ($?) # - else, process all source files ($^) [this covers "make -B" which can set $? to empty] -$(HEADER_BUILD)/qstr.split: $(SRC_QSTR) $(SRC_QSTR_PREPROCESSOR) $(QSTR_GLOBAL_DEPENDENCIES) | $(HEADER_BUILD)/mpversion.h $(PY_SRC)/genlast.py +$(HEADER_BUILD)/qstr.split: $(SRC_QSTR) $(SRC_QSTR_PREPROCESSOR) $(QSTR_GLOBAL_DEPENDENCIES) $(HEADER_BUILD)/moduledefs.h | $(HEADER_BUILD)/mpversion.h $(PY_SRC)/genlast.py $(STEPECHO) "GEN $@" - $(Q)$(PYTHON3) $(PY_SRC)/genlast.py $(HEADER_BUILD)/qstr $(if $(filter $?,$(QSTR_GLOBAL_DEPENDENCIES)),$^,$(if $?,$?,$^)) -- $(SRC_QSTR_PREPROCESSOR) -- $(CPP) $(QSTR_GEN_EXTRA_CFLAGS) $(CFLAGS) + $(Q)$(PYTHON) $(PY_SRC)/genlast.py $(HEADER_BUILD)/qstr $(if $(filter $?,$(QSTR_GLOBAL_DEPENDENCIES)),$^,$(if $?,$?,$^)) -- $(SRC_QSTR_PREPROCESSOR) -- $(CPP) $(QSTR_GEN_EXTRA_CFLAGS) $(CFLAGS) $(Q)$(TOUCH) $@ $(QSTR_DEFS_COLLECTED): $(HEADER_BUILD)/qstr.split $(PY_SRC)/makeqstrdefs.py $(STEPECHO) "GEN $@" - $(Q)$(PYTHON3) $(PY_SRC)/makeqstrdefs.py cat - $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED) + $(Q)$(PYTHON) $(PY_SRC)/makeqstrdefs.py cat - $(HEADER_BUILD)/qstr $(QSTR_DEFS_COLLECTED) # $(sort $(var)) removes duplicates # @@ -117,6 +117,28 @@ $(OBJ_DIRS): $(HEADER_BUILD): $(Q)$(MKDIR) -p $@ + $(MKDIR) -p $@ + +ifneq ($(MICROPY_MPYCROSS_DEPENDENCY),) +# to automatically build mpy-cross, if needed +$(MICROPY_MPYCROSS_DEPENDENCY): + $(MAKE) -C $(dir $@) +endif + +ifneq ($(FROZEN_MANIFEST),) +# to build frozen_content.c from a manifest +$(BUILD)/frozen_content.c: FORCE $(BUILD)/genhdr/qstrdefs.generated.h | $(MICROPY_MPYCROSS_DEPENDENCY) + $(Q)$(MAKE_MANIFEST) -o $@ -v "MPY_DIR=$(TOP)" -v "MPY_LIB_DIR=$(MPY_LIB_DIR)" -v "PORT_DIR=$(shell pwd)" -v "BOARD_DIR=$(BOARD_DIR)" -b "$(BUILD)" $(if $(MPY_CROSS_FLAGS),-f"$(MPY_CROSS_FLAGS)",) --mpy-tool-flags="$(MPY_TOOL_FLAGS)" $(FROZEN_MANIFEST) + +ifneq ($(FROZEN_DIR),) +$(error FROZEN_DIR cannot be used in conjunction with FROZEN_MANIFEST) +endif + +ifneq ($(FROZEN_MPY_DIR),) +$(error FROZEN_MPY_DIR cannot be used in conjunction with FROZEN_MANIFEST) +endif +endif + ifneq ($(FROZEN_DIR),) $(info Warning: FROZEN_DIR is deprecated in favour of FROZEN_MANIFEST) $(BUILD)/frozen.c: $(wildcard $(FROZEN_DIR)/*) $(HEADER_BUILD) $(FROZEN_EXTRA_DEPS) @@ -125,11 +147,6 @@ $(BUILD)/frozen.c: $(wildcard $(FROZEN_DIR)/*) $(HEADER_BUILD) $(FROZEN_EXTRA_DE endif ifneq ($(FROZEN_MPY_DIRS),) -# to build the MicroPython cross compiler -# Currently not used, because the wrong mpy-cross may be left over from a previous build. Build by hand to make sure. -$(MPY_CROSS): $(TOP)/py/*.[ch] $(TOP)/mpy-cross/*.[ch] $(TOP)/mpy-cross/fmode.c - $(Q)$(MAKE) -C $(TOP)/mpy-cross - # Copy all the modules and single python files to freeze to a common area, omitting top-level dirs (the repo names). # Do any preprocessing necessary: currently, this adds version information, removes examples, and # non-library .py files in the modules (setup.py and conf.py) @@ -140,7 +157,7 @@ $(BUILD)/frozen_mpy: $(FROZEN_MPY_DIRS) $(Q)$(PREPROCESS_FROZEN_MODULES) -o $@ $(FROZEN_MPY_DIRS) $(Q)$(CD) $@ && \ $(FIND) -L . -type f -name '*.py' | sed 's=^\./==' | \ -xargs -n1 "$(abspath $(MPY_CROSS))" $(MPY_CROSS_FLAGS) +xargs -n1 "$(abspath $(MICROPY_MPYCROSS_DEPENDENCY))" $(MPY_CROSS_FLAGS) # to build frozen_mpy.c from all .mpy files # You need to define MPY_TOOL_LONGINT_IMPL in mpconfigport.mk @@ -153,6 +170,13 @@ endif ifneq ($(PROG),) # Build a standalone executable (unix does this) +# The executable should have an .exe extension for builds targetting 'pure' +# Windows, i.e. msvc or mingw builds, but not when using msys or cygwin's gcc. +COMPILER_TARGET := $(shell $(CC) -dumpmachine) +ifneq (,$(findstring mingw,$(COMPILER_TARGET))) +PROG := $(PROG).exe +endif + all: $(PROG) $(PROG): $(OBJ) @@ -161,9 +185,9 @@ $(PROG): $(OBJ) # we may want to compile using Thumb, but link with non-Thumb libc. $(Q)$(CC) -o $@ $^ $(LIB) $(LDFLAGS) ifdef STRIP_CIRCUITPYTHON - $(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $(PROG) + $(Q)$(STRIP) $(STRIPFLAGS_EXTRA) $@ endif - $(Q)$(SIZE) $$(find $(BUILD) -path "$(BUILD)/build/frozen*.o") $(PROG) + $(Q)$(SIZE) $$(find $(BUILD) -path "$(BUILD)/build/frozen*.o") $@ clean: clean-prog clean-prog: @@ -176,6 +200,7 @@ endif submodules: $(ECHO) "Updating submodules: $(GIT_SUBMODULES)" ifneq ($(GIT_SUBMODULES),) + $(Q)git submodule sync $(addprefix $(TOP)/,$(GIT_SUBMODULES)) $(Q)git submodule update --init $(addprefix $(TOP)/,$(GIT_SUBMODULES)) endif .PHONY: submodules diff --git a/py/modbuiltins.c b/py/modbuiltins.c index f5ab07c404..e56b43047a 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -232,7 +232,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_hex_obj, mp_builtin_hex); #if MICROPY_PY_BUILTINS_INPUT #include "py/mphal.h" -#include "lib/mp-readline/readline.h" +#include "shared/readline/readline.h" // A port can define mp_hal_readline if they want to use a custom function here #ifndef mp_hal_readline @@ -324,7 +324,7 @@ STATIC mp_obj_t mp_builtin_next(size_t n_args, const mp_obj_t *args) { if (n_args == 1) { mp_obj_t ret = mp_iternext_allow_raise(args[0]); if (ret == MP_OBJ_STOP_ITERATION) { - mp_raise_type(&mp_type_StopIteration); + mp_raise_StopIteration(MP_STATE_THREAD(stop_iteration_arg)); } else { return ret; } @@ -338,7 +338,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_next_obj, 1, 2, mp_builtin_next); STATIC mp_obj_t mp_builtin_next(mp_obj_t o) { mp_obj_t ret = mp_iternext_allow_raise(o); if (ret == MP_OBJ_STOP_ITERATION) { - mp_raise_type(&mp_type_StopIteration); + mp_raise_StopIteration(MP_STATE_THREAD(stop_iteration_arg)); } else { return ret; } @@ -553,7 +553,7 @@ STATIC mp_obj_t mp_builtin_sorted(size_t n_args, const mp_obj_t *args, mp_map_t if (n_args > 1) { mp_raise_TypeError(MP_ERROR_TEXT("must use keyword argument for key function")); } - mp_obj_t self = mp_type_list.make_new(&mp_type_list, 1, args, NULL); + mp_obj_t self = mp_type_list.make_new(&mp_type_list, 1, 0, args); mp_obj_list_sort(1, &self, kwargs); return self; diff --git a/py/modio.c b/py/modio.c index a5a565955d..18918cf3ce 100644 --- a/py/modio.c +++ b/py/modio.c @@ -46,11 +46,11 @@ STATIC const mp_obj_type_t mp_type_iobase; STATIC const mp_obj_base_t iobase_singleton = {&mp_type_iobase}; -STATIC mp_obj_t iobase_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t iobase_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type; (void)n_args; + (void)n_kw; (void)args; - (void)kw_args; return MP_OBJ_FROM_PTR(&iobase_singleton); } @@ -122,8 +122,8 @@ typedef struct _mp_obj_bufwriter_t { byte buf[0]; } mp_obj_bufwriter_t; -STATIC mp_obj_t bufwriter_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 2, 2, false); +STATIC mp_obj_t bufwriter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 2, 2, false); size_t alloc = mp_obj_get_int(args[1]); mp_obj_bufwriter_t *o = m_new_obj_var(mp_obj_bufwriter_t, byte, alloc); o->base.type = type; diff --git a/py/modsys.c b/py/modsys.c index 484e29f411..6016570933 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -113,9 +113,9 @@ STATIC const MP_DEFINE_STR_OBJ(mp_sys_platform_obj, MICROPY_PY_SYS_PLATFORM); // exit([retval]): raise SystemExit, with optional argument given to the exception STATIC mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { - nlr_raise(mp_obj_new_exception(&mp_type_SystemExit)); + mp_raise_type(&mp_type_SystemExit); } else { - mp_raise_arg1(&mp_type_SystemExit, args[0]); + mp_raise_type_arg(&mp_type_SystemExit, args[0]); } } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj, 0, 1, mp_sys_exit); diff --git a/py/modthread.c b/py/modthread.c index fd52b9dfb5..333d750a36 100644 --- a/py/modthread.c +++ b/py/modthread.c @@ -176,6 +176,8 @@ STATIC void *thread_entry(void *args_in) { // The GC starts off unlocked on this thread. ts.gc_lock_depth = 0; + ts.mp_pending_exception = MP_OBJ_NULL; + // set locals and globals from the calling context mp_locals_set(args->dict_locals); mp_globals_set(args->dict_globals); @@ -186,7 +188,6 @@ STATIC void *thread_entry(void *args_in) { mp_thread_start(); // TODO set more thread-specific state here: - // mp_pending_exception? (root pointer) // cur_exception (root pointer) DEBUG_printf("[thread] start ts=%p args=%p stack=%p\n", &ts, &args, MP_STATE_THREAD(stack_top)); diff --git a/py/mpconfig.h b/py/mpconfig.h index 973900053f..98a11c15ad 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -495,7 +495,8 @@ /* Optimisations */ // Whether to use computed gotos in the VM, or a switch -// Computed gotos are roughly 10% faster, and increase VM code size by a little +// Computed gotos are roughly 10% faster, and increase VM code size by a little, +// e.g. ~1kiB on Cortex M4. // Note: enabling this will use the gcc-specific extensions of ranged designated // initialisers and addresses of labels, which are not part of the C99 standard. #ifndef MICROPY_OPT_COMPUTED_GOTO @@ -910,6 +911,11 @@ typedef double mp_float_t; #define MICROPY_PY_ASYNC_AWAIT (1) #endif +// Support for literal string interpolation, f-strings (see PEP 498, Python 3.6+) +#ifndef MICROPY_PY_FSTRINGS +#define MICROPY_PY_FSTRINGS (0) +#endif + // Support for assignment expressions with := (see PEP 572, Python 3.8+) #ifndef MICROPY_PY_ASSIGN_EXPR #define MICROPY_PY_ASSIGN_EXPR (1) @@ -1098,7 +1104,7 @@ typedef double mp_float_t; #endif // Whether to provide the built-in input() function. The implementation of this -// uses mp-readline, so can only be enabled if the port uses this readline. +// uses shared/readline, so can only be enabled if the port uses this readline. #ifndef MICROPY_PY_BUILTINS_INPUT #define MICROPY_PY_BUILTINS_INPUT (0) #endif @@ -1357,6 +1363,13 @@ typedef double mp_float_t; #define MICROPY_PY_USELECT (0) #endif +// Whether to enable the select() function in the "uselect" module (baremetal +// implementation). This is present for compatibility but can be disabled to +// save space. +#ifndef MICROPY_PY_USELECT_SELECT +#define MICROPY_PY_USELECT_SELECT (1) +#endif + // Whether to provide "utime" module functions implementation // in terms of mp_hal_* functions. #ifndef MICROPY_PY_UTIME_MP_HAL @@ -1414,6 +1427,11 @@ typedef double mp_float_t; #define MICROPY_PY_UJSON (0) #endif +// Whether to support the "separators" argument to dump, dumps +#ifndef MICROPY_PY_UJSON_SEPARATORS +#define MICROPY_PY_UJSON_SEPARATORS (1) +#endif + #ifndef CIRCUITPY_ULAB #define CIRCUITPY_ULAB (0) #endif diff --git a/py/mperrno.h b/py/mperrno.h index 0c25b6329c..f9819169e0 100644 --- a/py/mperrno.h +++ b/py/mperrno.h @@ -82,6 +82,7 @@ #define MP_EHOSTUNREACH (113) // No route to host #define MP_EALREADY (114) // Operation already in progress #define MP_EINPROGRESS (115) // Operation now in progress +#define MP_ECANCELED (125) // Operation canceled #else @@ -137,6 +138,7 @@ #define MP_EHOSTUNREACH EHOSTUNREACH #define MP_EALREADY EALREADY #define MP_EINPROGRESS EINPROGRESS +#define MP_ECANCELED ECANCELED #endif diff --git a/py/mpprint.h b/py/mpprint.h index 9284935f96..616f21a91e 100644 --- a/py/mpprint.h +++ b/py/mpprint.h @@ -52,6 +52,14 @@ typedef struct _mp_print_t { mp_print_strn_t print_strn; } mp_print_t; +typedef struct _mp_print_ext_t { + mp_print_t base; + const char *item_separator; + const char *key_separator; +}mp_print_ext_t; + +#define MP_PRINT_GET_EXT(print) ((mp_print_ext_t *)print) + // All (non-debug) prints go through one of the two interfaces below. // 1) Wrapper for platform print function, which wraps MP_PLAT_PRINT_STRN. extern const mp_print_t mp_plat_print; diff --git a/py/mpstate.h b/py/mpstate.h index 38f1f5188d..2f9dafd925 100644 --- a/py/mpstate.h +++ b/py/mpstate.h @@ -152,9 +152,6 @@ typedef struct _mp_state_vm_t { // dictionary with loaded modules (may be exposed as sys.modules) mp_obj_dict_t mp_loaded_modules_dict; - // pending exception object (MP_OBJ_NULL if not pending) - volatile mp_obj_t mp_pending_exception; - #if MICROPY_ENABLE_SCHEDULER mp_sched_item_t sched_queue[MICROPY_SCHEDULER_DEPTH]; #endif @@ -273,6 +270,12 @@ typedef struct _mp_state_thread_t { nlr_buf_t *nlr_top; + // pending exception object (MP_OBJ_NULL if not pending) + volatile mp_obj_t mp_pending_exception; + + // If MP_OBJ_STOP_ITERATION is propagated then this holds its argument. + mp_obj_t stop_iteration_arg; + #if MICROPY_PY_SYS_SETTRACE mp_obj_t prof_trace_callback; bool prof_callback_is_executing; @@ -292,12 +295,13 @@ extern mp_state_ctx_t mp_state_ctx; #define MP_STATE_VM(x) (mp_state_ctx.vm.x) #define MP_STATE_MEM(x) (mp_state_ctx.mem.x) +#define MP_STATE_MAIN_THREAD(x) (mp_state_ctx.thread.x) #if MICROPY_PY_THREAD extern mp_state_thread_t *mp_thread_get_state(void); #define MP_STATE_THREAD(x) (mp_thread_get_state()->x) #else -#define MP_STATE_THREAD(x) (mp_state_ctx.thread.x) +#define MP_STATE_THREAD(x) MP_STATE_MAIN_THREAD(x) #endif #endif // MICROPY_INCLUDED_PY_MPSTATE_H diff --git a/py/mpz.c b/py/mpz.c index d7a19f65c4..b871b76b7c 100644 --- a/py/mpz.c +++ b/py/mpz.c @@ -745,7 +745,7 @@ void mpz_set_from_ll(mpz_t *z, long long val, bool is_signed) { unsigned long long uval; if (is_signed && val < 0) { z->neg = 1; - uval = -val; + uval = -(unsigned long long)val; } else { z->neg = 0; uval = val; diff --git a/py/obj.c b/py/obj.c index fa3cd0c51c..45f8c96859 100644 --- a/py/obj.c +++ b/py/obj.c @@ -29,7 +29,7 @@ #include #include -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/obj.h" #include "py/objtype.h" #include "py/objint.h" diff --git a/py/obj.h b/py/obj.h index a043154ada..823922ad1a 100644 --- a/py/obj.h +++ b/py/obj.h @@ -539,7 +539,7 @@ typedef struct _mp_obj_iter_buf_t { struct _mp_buffer_info_t; typedef void (*mp_print_fun_t)(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind); -typedef mp_obj_t (*mp_make_new_fun_t)(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args); +typedef mp_obj_t (*mp_make_new_fun_t)(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); typedef mp_obj_t (*mp_call_fun_t)(mp_obj_t fun, size_t n_args, size_t n_kw, const mp_obj_t *args); typedef mp_obj_t (*mp_unary_op_fun_t)(mp_unary_op_t op, mp_obj_t); typedef mp_obj_t (*mp_binary_op_fun_t)(mp_binary_op_t op, mp_obj_t, mp_obj_t); @@ -847,7 +847,6 @@ extern mp_float_t uint64_to_float(uint64_t ui64); extern uint64_t float_to_uint64(float f); #endif mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type); -mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg); mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args, const mp_obj_t *args); #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NONE #define mp_obj_new_exception_msg(exc_type, msg) mp_obj_new_exception(exc_type) @@ -895,9 +894,11 @@ bool mp_obj_is_callable(mp_obj_t o_in); mp_obj_t mp_obj_equal_not_equal(mp_binary_op_t op, mp_obj_t o1, mp_obj_t o2); bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2); +// returns true if o is bool, small int or long int static inline bool mp_obj_is_integer(mp_const_obj_t o) { return mp_obj_is_int(o) || mp_obj_is_bool(o); -} // returns true if o is bool, small int or long int +} + mp_int_t mp_obj_get_int(mp_const_obj_t arg); mp_int_t mp_obj_get_int_truncated(mp_const_obj_t arg); bool mp_obj_get_int_maybe(mp_const_obj_t arg, mp_int_t *value); @@ -938,9 +939,13 @@ void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qs void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values); mp_obj_t mp_obj_exception_get_traceback_obj(mp_obj_t self_in); mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in); -mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args); +mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args); mp_obj_t mp_alloc_emergency_exception_buf(mp_obj_t size_in); void mp_init_emergency_exception_buf(void); +static inline mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg) { + assert(exc_type->make_new == mp_obj_exception_make_new); + return mp_obj_exception_make_new(exc_type, 1, 0, &arg); +} // str bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2); @@ -1021,7 +1026,7 @@ typedef struct _mp_obj_dict_t { mp_obj_base_t base; mp_map_t map; } mp_obj_dict_t; -mp_obj_t mp_obj_dict_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args); +mp_obj_t mp_obj_dict_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); void mp_obj_dict_init(mp_obj_dict_t *dict, size_t n_args); size_t mp_obj_dict_len(mp_obj_t self_in); mp_obj_t mp_obj_dict_get(mp_obj_t self_in, mp_obj_t index); diff --git a/py/objarray.c b/py/objarray.c index eea1a97c1d..b71687fb35 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -169,9 +169,9 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) { #endif #if MICROPY_PY_ARRAY -STATIC mp_obj_t array_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t array_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; - mp_arg_check_num(n_args, kw_args, 1, 2, false); + mp_arg_check_num(n_args, n_kw, 1, 2, false); // get typecode const char *typecode = mp_obj_str_get_str(args[0]); @@ -187,9 +187,9 @@ STATIC mp_obj_t array_make_new(const mp_obj_type_t *type_in, size_t n_args, cons #endif #if MICROPY_PY_BUILTINS_BYTEARRAY -STATIC mp_obj_t bytearray_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t bytearray_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; - mp_arg_check_num(n_args, kw_args, 0, 3, false); + mp_arg_check_num(n_args, n_kw, 0, 3, false); if (n_args == 0) { // no args: construct an empty bytearray @@ -218,13 +218,13 @@ mp_obj_t mp_obj_new_memoryview(byte typecode, size_t nitems, void *items) { return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t memoryview_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t memoryview_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; // TODO possibly allow memoryview constructor to take start/stop so that one // can do memoryview(b, 4, 8) instead of memoryview(b)[4:8] (uses less RAM) - mp_arg_check_num(n_args, kw_args, 1, 1, false); + mp_arg_check_num(n_args, n_kw, 1, 1, false); mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[0], &bufinfo, MP_BUFFER_READ); @@ -704,7 +704,7 @@ STATIC mp_obj_t array_decode(size_t n_args, const mp_obj_t *args) { args = new_args; n_args++; } - return mp_obj_str_make_new(&mp_type_str, n_args, args, NULL); + return mp_obj_str_make_new(&mp_type_str, n_args, 0, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(array_decode_obj, 1, 3, array_decode); #endif diff --git a/py/objbool.c b/py/objbool.c index c1f1d8f359..13d10ffae3 100644 --- a/py/objbool.c +++ b/py/objbool.c @@ -60,9 +60,9 @@ STATIC void bool_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ } } -STATIC mp_obj_t bool_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t bool_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; - mp_arg_check_num(n_args, kw_args, 0, 1, false); + mp_arg_check_num(n_args, n_kw, 0, 1, false); if (n_args == 0) { return mp_const_false; diff --git a/py/objcomplex.c b/py/objcomplex.c index f8f8c5807d..b37b059d59 100644 --- a/py/objcomplex.c +++ b/py/objcomplex.c @@ -75,9 +75,9 @@ STATIC void complex_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_ } } -STATIC mp_obj_t complex_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t complex_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; - mp_arg_check_num(n_args, kw_args, 0, 2, false); + mp_arg_check_num(n_args, n_kw, 0, 2, false); switch (n_args) { case 0: diff --git a/py/objdeque.c b/py/objdeque.c index ae0bde4578..2d29d71e3b 100644 --- a/py/objdeque.c +++ b/py/objdeque.c @@ -44,8 +44,8 @@ typedef struct _mp_obj_deque_t { #define FLAG_CHECK_OVERFLOW 1 } mp_obj_deque_t; -STATIC mp_obj_t deque_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 2, 3, false); +STATIC mp_obj_t deque_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 2, 3, false); /* Initialization from existing sequence is not supported, so an empty tuple must be passed as such. */ diff --git a/py/objdict.c b/py/objdict.c index bb06989b90..5f233741fa 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -72,8 +72,15 @@ STATIC mp_map_elem_t *dict_iter_next(mp_obj_dict_t *dict, size_t *cur) { STATIC void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in); bool first = true; + const char *item_separator = ", "; + const char *key_separator = ": "; if (!(MICROPY_PY_UJSON && kind == PRINT_JSON)) { kind = PRINT_REPR; + } else { + #if MICROPY_PY_UJSON_SEPARATORS + item_separator = MP_PRINT_GET_EXT(print)->item_separator; + key_separator = MP_PRINT_GET_EXT(print)->key_separator; + #endif } if (MICROPY_PY_COLLECTIONS_ORDEREDDICT && self->base.type != &mp_type_dict && kind != PRINT_JSON) { mp_printf(print, "%q(", self->base.type->name); @@ -83,7 +90,7 @@ STATIC void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ mp_map_elem_t *next = NULL; while ((next = dict_iter_next(self, &cur)) != NULL) { if (!first) { - mp_print_str(print, ", "); + mp_print_str(print, item_separator); } first = false; bool add_quote = MICROPY_PY_UJSON && kind == PRINT_JSON && !mp_obj_is_str_or_bytes(next->key); @@ -94,7 +101,7 @@ STATIC void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ if (add_quote) { mp_print_str(print, "\""); } - mp_print_str(print, ": "); + mp_print_str(print, key_separator); mp_obj_print_helper(print, next->value, kind); } mp_print_str(print, "}"); @@ -103,7 +110,7 @@ STATIC void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ } } -mp_obj_t mp_obj_dict_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +mp_obj_t mp_obj_dict_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_obj_t dict_out = mp_obj_new_dict(0); mp_obj_dict_t *dict = MP_OBJ_TO_PTR(dict_out); dict->base.type = type; @@ -112,12 +119,11 @@ mp_obj_t mp_obj_dict_make_new(const mp_obj_type_t *type, size_t n_args, const mp dict->map.is_ordered = 1; } #endif - if (n_args > 0 || kw_args != NULL) { - mp_obj_t args2[2] = {dict_out, NULL}; // args[0] is always valid, even if it's not a positional arg - if (n_args > 0) { - args2[1] = args[0]; - } - dict_update(n_args + 1, args2, kw_args); // dict_update will check that n_args + 1 == 1 or 2 + if (n_args > 0 || n_kw > 0) { + mp_obj_t args2[2] = {dict_out, args[0]}; // args[0] is always valid, even if it's not a positional arg + mp_map_t kwargs; + mp_map_init_fixed_table(&kwargs, n_kw, args + n_args); + dict_update(n_args + 1, args2, &kwargs); // dict_update will check that n_args + 1 == 1 or 2 } return dict_out; } @@ -193,7 +199,7 @@ mp_obj_t mp_obj_dict_get(mp_obj_t self_in, mp_obj_t index) { mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in); mp_map_elem_t *elem = mp_map_lookup(&self->map, index, MP_MAP_LOOKUP); if (elem == NULL) { - mp_raise_arg1(&mp_type_KeyError, index); + mp_raise_type_arg(&mp_type_KeyError, index); } else { return elem->value; } @@ -209,7 +215,7 @@ STATIC mp_obj_t dict_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in); mp_map_elem_t *elem = mp_map_lookup(&self->map, index, MP_MAP_LOOKUP); if (elem == NULL) { - mp_raise_arg1(&mp_type_KeyError, index); + mp_raise_type_arg(&mp_type_KeyError, index); } else { return elem->value; } @@ -298,7 +304,7 @@ STATIC mp_obj_t dict_get_helper(size_t n_args, const mp_obj_t *args, mp_map_look if (elem == NULL || elem->value == MP_OBJ_NULL) { if (n_args == 2) { if (lookup_kind == MP_MAP_LOOKUP_REMOVE_IF_FOUND) { - mp_raise_arg1(&mp_type_KeyError, args[1]); + mp_raise_type_arg(&mp_type_KeyError, args[1]); } else { value = mp_const_none; } @@ -362,7 +368,7 @@ STATIC mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwarg mp_obj_dict_t *self = MP_OBJ_TO_PTR(args[0]); mp_ensure_not_fixed(self); - mp_arg_check_num(n_args, kwargs, 1, 2, true); + mp_arg_check_num(n_args, kwargs->used, 1, 2, true); if (n_args == 2) { // given a positional argument diff --git a/py/objenumerate.c b/py/objenumerate.c index a79d81f2be..c18ac1dd80 100644 --- a/py/objenumerate.c +++ b/py/objenumerate.c @@ -39,7 +39,7 @@ typedef struct _mp_obj_enumerate_t { STATIC mp_obj_t enumerate_iternext(mp_obj_t self_in); -STATIC mp_obj_t enumerate_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t enumerate_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { #if MICROPY_CPYTHON_COMPAT static const mp_arg_t allowed_args[] = { { MP_QSTR_iterable, MP_ARG_REQUIRED | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL} }, @@ -50,7 +50,7 @@ STATIC mp_obj_t enumerate_make_new(const mp_obj_type_t *type, size_t n_args, con struct { mp_arg_val_t iterable, start; } arg_vals; - mp_arg_parse_all(n_args, args, kw_args, + mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t *)&arg_vals); // create enumerate object @@ -59,7 +59,7 @@ STATIC mp_obj_t enumerate_make_new(const mp_obj_type_t *type, size_t n_args, con o->iter = mp_getiter(arg_vals.iterable.u_obj, NULL); o->cur = arg_vals.start.u_int; #else - (void)kw_args; + (void)n_kw; mp_obj_enumerate_t *o = m_new_obj(mp_obj_enumerate_t); o->base.type = type; o->iter = mp_getiter(args[0], NULL); diff --git a/py/objexcept.c b/py/objexcept.c index e572225bbc..c7e5cb7675 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -104,6 +104,15 @@ mp_obj_t mp_alloc_emergency_exception_buf(mp_obj_t size_in) { #endif #endif // MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF +STATIC mp_obj_exception_t *get_native_exception(mp_obj_t self_in) { + assert(mp_obj_is_exception_instance(self_in)); + if (mp_obj_is_native_exception_instance(self_in)) { + return MP_OBJ_TO_PTR(self_in); + } else { + return MP_OBJ_TO_PTR(((mp_obj_instance_t *)MP_OBJ_TO_PTR(self_in))->subobj[0]); + } +} + void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { mp_obj_exception_t *o = MP_OBJ_TO_PTR(o_in); mp_print_kind_t k = kind & ~PRINT_EXC_SUBCLASS; @@ -121,21 +130,22 @@ void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kin mp_print_str(print, ""); return; } - if (mp_obj_is_small_int(o->args->items[0]) && - mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(o->base.type), MP_OBJ_FROM_PTR(&mp_type_OSError)) && - o->args->len <= 2) { - // try to provide a nice OSError error message + #if MICROPY_PY_UERRNO + // try to provide a nice OSError error message + if (o->base.type == &mp_type_OSError && o->args->len > 0 && o->args->len < 3 && mp_obj_is_small_int(o->args->items[0])) { char decompressed[50]; const char *msg = mp_common_errno_to_str(o->args->items[0], decompressed, sizeof(decompressed)); if (msg != NULL) { mp_printf(print, "[Errno " INT_FMT "] %s", MP_OBJ_SMALL_INT_VALUE(o->args->items[0]), msg); - // if second arg exists, it is filename. - if (o->args->len == 2) { - mp_printf(print, ": '%s'", mp_obj_str_get_str(o->args->items[1])); + if (o->args->len > 1) { + mp_print_str(print, ": "); + mp_obj_print_helper(print, o->args->items[1], PRINT_STR); } return; } } + #endif + if (o->args->len == 1) { mp_obj_print_helper(print, o->args->items[0], PRINT_STR); return; @@ -145,8 +155,8 @@ void mp_obj_exception_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kin mp_obj_tuple_print(print, MP_OBJ_FROM_PTR(o->args), kind); } -mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 0, MP_OBJ_FUN_ARGS_MAX, false); +mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, false); // Try to allocate memory for the exception, with fallback to emergency exception object mp_obj_exception_t *o_exc = m_new_obj_maybe(mp_obj_exception_t); @@ -204,7 +214,7 @@ mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type, size_t n_args, con // Get exception "value" - that is, first argument, or None mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in) { - mp_obj_exception_t *self = MP_OBJ_TO_PTR(self_in); + mp_obj_exception_t *self = get_native_exception(self_in); if (self->args->len == 0) { return mp_const_none; } else { @@ -367,15 +377,9 @@ mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type) { return mp_obj_exception_make_new(exc_type, 0, 0, NULL); } -// "Optimized" version for common(?) case of having 1 exception arg -mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg) { - assert(exc_type->make_new == mp_obj_exception_make_new); - return mp_obj_exception_make_new(exc_type, 1, &arg, NULL); -} - mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args, const mp_obj_t *args) { assert(exc_type->make_new == mp_obj_exception_make_new); - return exc_type->make_new(exc_type, n_args, args, NULL); + return exc_type->make_new(exc_type, n_args, 0, args); } #if MICROPY_ERROR_REPORTING != MICROPY_ERROR_REPORTING_NONE @@ -477,7 +481,7 @@ mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, const com o_str->base.type = &mp_type_str; o_str->hash = qstr_compute_hash(o_str->data, o_str->len); mp_obj_t arg = MP_OBJ_FROM_PTR(o_str); - return mp_obj_exception_make_new(exc_type, 1, &arg, NULL); + return mp_obj_exception_make_new(exc_type, 1, 0, &arg); } mp_obj_t mp_obj_new_exception_msg_str(const mp_obj_type_t *exc_type, const char *msg) { @@ -513,7 +517,7 @@ mp_obj_t mp_obj_new_exception_msg_str(const mp_obj_type_t *exc_type, const char o_str->base.type = &mp_type_str; o_str->hash = qstr_compute_hash(o_str->data, o_str->len); mp_obj_t arg = MP_OBJ_FROM_PTR(o_str); - return mp_obj_exception_make_new(exc_type, 1, &arg, NULL); + return mp_obj_exception_make_new(exc_type, 1, 0, &arg); } // return true if the given object is an exception type @@ -546,25 +550,15 @@ bool mp_obj_exception_match(mp_obj_t exc, mp_const_obj_t exc_type) { // traceback handling functions -#define GET_NATIVE_EXCEPTION(self, self_in) \ - /* make sure self_in is an exception instance */ \ - assert(mp_obj_is_exception_instance(self_in)); \ - mp_obj_exception_t *self; \ - if (mp_obj_is_native_exception_instance(self_in)) { \ - self = MP_OBJ_TO_PTR(self_in); \ - } else { \ - self = MP_OBJ_TO_PTR(((mp_obj_instance_t *)MP_OBJ_TO_PTR(self_in))->subobj[0]); \ - } - void mp_obj_exception_clear_traceback(mp_obj_t self_in) { - GET_NATIVE_EXCEPTION(self, self_in); + mp_obj_exception_t *self = get_native_exception(self_in); // just set the traceback to the null object // we don't want to call any memory management functions here self->traceback->data = NULL; } void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block) { - GET_NATIVE_EXCEPTION(self, self_in); + mp_obj_exception_t *self = get_native_exception(self_in); // append this traceback info to traceback data // if memory allocation fails (eg because gc is locked), just return @@ -617,7 +611,7 @@ void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qs } void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values) { - GET_NATIVE_EXCEPTION(self, self_in); + mp_obj_exception_t *self = get_native_exception(self_in); if (self->traceback->data == NULL) { *n = 0; @@ -686,7 +680,7 @@ STATIC mp_obj_t code_make_new(qstr file, qstr block) { mp_obj_new_bytearray(0, NULL), // co_lnotab }; - return namedtuple_make_new((const mp_obj_type_t *)&code_type_obj, 15, elems, NULL); + return namedtuple_make_new((const mp_obj_type_t *)&code_type_obj, 15, 0, elems); } STATIC const mp_obj_namedtuple_type_t frame_type_obj = { @@ -731,7 +725,7 @@ STATIC mp_obj_t frame_make_new(mp_obj_t f_code, int f_lineno) { mp_const_none, // f_trace }; - return namedtuple_make_new((const mp_obj_type_t *)&frame_type_obj, 8, elems, NULL); + return namedtuple_make_new((const mp_obj_type_t *)&frame_type_obj, 8, 0, elems); } STATIC const mp_obj_namedtuple_type_t traceback_type_obj = { @@ -771,7 +765,7 @@ STATIC mp_obj_t traceback_from_values(size_t *values, mp_obj_t tb_next) { tb_next, }; - return namedtuple_make_new((const mp_obj_type_t *)&traceback_type_obj, 4, elems, NULL); + return namedtuple_make_new((const mp_obj_type_t *)&traceback_type_obj, 4, 0, elems); }; mp_obj_t mp_obj_exception_get_traceback_obj(mp_obj_t self_in) { diff --git a/py/objfilter.c b/py/objfilter.c index a06a71bf01..c034df28e6 100644 --- a/py/objfilter.c +++ b/py/objfilter.c @@ -34,8 +34,8 @@ typedef struct _mp_obj_filter_t { mp_obj_t iter; } mp_obj_filter_t; -STATIC mp_obj_t filter_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 2, 2, false); +STATIC mp_obj_t filter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 2, 2, false); mp_obj_filter_t *o = m_new_obj(mp_obj_filter_t); o->base.type = type; o->fun = args[0]; diff --git a/py/objfloat.c b/py/objfloat.c index 7ca89d9176..6d1d10188c 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -121,9 +121,9 @@ STATIC void float_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t } } -STATIC mp_obj_t float_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t float_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; - mp_arg_check_num(n_args, kw_args, 0, 1, false); + mp_arg_check_num(n_args, n_kw, 0, 1, false); switch (n_args) { case 0: diff --git a/py/objfun.c b/py/objfun.c index 23698ad95c..55c3fbbb06 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -54,7 +54,7 @@ STATIC mp_obj_t fun_builtin_0_call(mp_obj_t self_in, size_t n_args, size_t n_kw, (void)args; assert(mp_obj_is_type(self_in, &mp_type_fun_builtin_0)); mp_obj_fun_builtin_fixed_t *self = MP_OBJ_TO_PTR(self_in); - mp_arg_check_num_kw_array(n_args, n_kw, 0, 0, false); + mp_arg_check_num(n_args, n_kw, 0, 0, false); return self->fun._0(); } @@ -71,7 +71,7 @@ const mp_obj_type_t mp_type_fun_builtin_0 = { STATIC mp_obj_t fun_builtin_1_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { assert(mp_obj_is_type(self_in, &mp_type_fun_builtin_1)); mp_obj_fun_builtin_fixed_t *self = MP_OBJ_TO_PTR(self_in); - mp_arg_check_num_kw_array(n_args, n_kw, 1, 1, false); + mp_arg_check_num(n_args, n_kw, 1, 1, false); return self->fun._1(args[0]); } @@ -88,7 +88,7 @@ const mp_obj_type_t mp_type_fun_builtin_1 = { STATIC mp_obj_t fun_builtin_2_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { assert(mp_obj_is_type(self_in, &mp_type_fun_builtin_2)); mp_obj_fun_builtin_fixed_t *self = MP_OBJ_TO_PTR(self_in); - mp_arg_check_num_kw_array(n_args, n_kw, 2, 2, false); + mp_arg_check_num(n_args, n_kw, 2, 2, false); return self->fun._2(args[0], args[1]); } @@ -105,7 +105,7 @@ const mp_obj_type_t mp_type_fun_builtin_2 = { STATIC mp_obj_t fun_builtin_3_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { assert(mp_obj_is_type(self_in, &mp_type_fun_builtin_3)); mp_obj_fun_builtin_fixed_t *self = MP_OBJ_TO_PTR(self_in); - mp_arg_check_num_kw_array(n_args, n_kw, 3, 3, false); + mp_arg_check_num(n_args, n_kw, 3, 3, false); return self->fun._3(args[0], args[1], args[2]); } @@ -208,7 +208,8 @@ STATIC void dump_args(const mp_obj_t *a, size_t sz) { const uint8_t *ip = bytecode; \ size_t n_exc_stack, scope_flags, n_pos_args, n_kwonly_args, n_def_args; \ MP_BC_PRELUDE_SIG_DECODE_INTO(ip, n_state_out_var, n_exc_stack, scope_flags, n_pos_args, n_kwonly_args, n_def_args); \ - \ + (void)scope_flags; (void)n_pos_args; (void)n_kwonly_args; (void)n_def_args; \ + \ /* state size in bytes */ \ state_size_out_var = n_state_out_var * sizeof(mp_obj_t) \ + n_exc_stack * sizeof(mp_exc_stack_t); \ @@ -507,7 +508,7 @@ STATIC mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) { STATIC mp_obj_t fun_asm_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_obj_fun_asm_t *self = self_in; - mp_arg_check_num_kw_array(n_args, n_kw, self->n_args, self->n_args, false); + mp_arg_check_num(n_args, n_kw, self->n_args, self->n_args, false); const void *fun = MICROPY_MAKE_POINTER_CALLABLE(self->fun_data); diff --git a/py/objgenerator.c b/py/objgenerator.c index f7bf235848..4066c1c566 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -199,8 +199,9 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_ mp_check_self(mp_obj_is_type(self_in, &mp_type_gen_instance)); mp_obj_gen_instance_t *self = MP_OBJ_TO_PTR(self_in); if (self->code_state.ip == 0) { - // Trying to resume already stopped generator - *ret_val = MP_OBJ_STOP_ITERATION; + // Trying to resume an already stopped generator. + // This is an optimised "raise StopIteration(None)". + *ret_val = mp_const_none; return MP_VM_RETURN_NORMAL; } @@ -259,6 +260,7 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_ // subsequent next() may re-execute statements after last yield // again and again, leading to side effects. self->code_state.ip = 0; + // This is an optimised "raise StopIteration(*ret_val)". *ret_val = *self->code_state.sp; break; @@ -283,16 +285,20 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_ return ret_kind; } -STATIC mp_obj_t gen_resume_and_raise(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value) { +STATIC mp_obj_t gen_resume_and_raise(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value, bool raise_stop_iteration) { mp_obj_t ret; switch (mp_obj_gen_resume(self_in, send_value, throw_value, &ret)) { case MP_VM_RETURN_NORMAL: default: - // Optimize return w/o value in case generator is used in for loop - if (ret == mp_const_none || ret == MP_OBJ_STOP_ITERATION) { - return MP_OBJ_STOP_ITERATION; + // A normal return is a StopIteration, either raise it or return + // MP_OBJ_STOP_ITERATION as an optimisation. + if (ret == mp_const_none) { + ret = MP_OBJ_NULL; + } + if (raise_stop_iteration) { + mp_raise_StopIteration(ret); } else { - nlr_raise(mp_obj_new_exception_arg1(&mp_type_StopIteration, ret)); + return mp_make_stop_iteration(ret); } case MP_VM_RETURN_YIELD: @@ -311,16 +317,11 @@ STATIC mp_obj_t gen_instance_iternext(mp_obj_t self_in) { mp_raise_TypeError(MP_ERROR_TEXT("'coroutine' object is not an iterator")); } #endif - return gen_resume_and_raise(self_in, mp_const_none, MP_OBJ_NULL); + return gen_resume_and_raise(self_in, mp_const_none, MP_OBJ_NULL, false); } STATIC mp_obj_t gen_instance_send(mp_obj_t self_in, mp_obj_t send_value) { - mp_obj_t ret = gen_resume_and_raise(self_in, send_value, MP_OBJ_NULL); - if (ret == MP_OBJ_STOP_ITERATION) { - mp_raise_type(&mp_type_StopIteration); - } else { - return ret; - } + return gen_resume_and_raise(self_in, send_value, MP_OBJ_NULL, true); } STATIC MP_DEFINE_CONST_FUN_OBJ_2(gen_instance_send_obj, gen_instance_send); @@ -357,12 +358,7 @@ STATIC mp_obj_t gen_instance_throw(size_t n_args, const mp_obj_t *args) { exc = args[2]; } - mp_obj_t ret = gen_resume_and_raise(args[0], mp_const_none, exc); - if (ret == MP_OBJ_STOP_ITERATION) { - mp_raise_type(&mp_type_StopIteration); - } else { - return ret; - } + return gen_resume_and_raise(args[0], mp_const_none, exc, true); } STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gen_instance_throw_obj, 2, 4, gen_instance_throw); diff --git a/py/objgetitemiter.c b/py/objgetitemiter.c index d41767b4a2..098e7da557 100644 --- a/py/objgetitemiter.c +++ b/py/objgetitemiter.c @@ -48,7 +48,6 @@ STATIC mp_obj_t it_iternext(mp_obj_t self_in) { // an exception was raised mp_obj_type_t *t = (mp_obj_type_t *)((mp_obj_base_t *)nlr.ret_val)->type; if (t == &mp_type_StopIteration || t == &mp_type_IndexError) { - // return MP_OBJ_STOP_ITERATION instead of raising return MP_OBJ_STOP_ITERATION; } else { // re-raise exception diff --git a/py/objint.c b/py/objint.c index fd7b74a14a..50bcbf56f8 100644 --- a/py/objint.c +++ b/py/objint.c @@ -42,9 +42,9 @@ #endif // This dispatcher function is expected to be independent of the implementation of long int -STATIC mp_obj_t mp_obj_int_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t mp_obj_int_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; - mp_arg_check_num(n_args, kw_args, 0, 2, false); + mp_arg_check_num(n_args, n_kw, 0, 2, false); switch (n_args) { case 0: @@ -108,14 +108,14 @@ STATIC mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) { #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE e |= u.i[MP_ENDIANNESS_BIG] != 0; #endif - if ((e & ~(1 << MP_FLOAT_SIGN_SHIFT_I32)) == 0) { + if ((e & ~(1U << MP_FLOAT_SIGN_SHIFT_I32)) == 0) { // handle case of -0 (when sign is set but rest of bits are zero) e = 0; } else { - e += ((1 << MP_FLOAT_EXP_BITS) - 1) << MP_FLOAT_EXP_SHIFT_I32; + e += ((1U << MP_FLOAT_EXP_BITS) - 1) << MP_FLOAT_EXP_SHIFT_I32; } } else { - e &= ~((1 << MP_FLOAT_EXP_SHIFT_I32) - 1); + e &= ~((1U << MP_FLOAT_EXP_SHIFT_I32) - 1); } // 8 * sizeof(uintptr_t) counts the number of bits for a small int // TODO provide a way to configure this properly diff --git a/py/objlist.c b/py/objlist.c index 41e4a5ef16..9b0e0edaa7 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -46,13 +46,18 @@ STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args); STATIC void list_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { mp_obj_list_t *o = MP_OBJ_TO_PTR(o_in); + const char *item_separator = ", "; if (!(MICROPY_PY_UJSON && kind == PRINT_JSON)) { kind = PRINT_REPR; + } else { + #if MICROPY_PY_UJSON_SEPARATORS + item_separator = MP_PRINT_GET_EXT(print)->item_separator; + #endif } mp_print_str(print, "["); for (size_t i = 0; i < o->len; i++) { if (i > 0) { - mp_print_str(print, ", "); + mp_print_str(print, item_separator); } mp_obj_print_helper(print, o->items[i], kind); } @@ -73,9 +78,9 @@ mp_obj_t mp_obj_new_list_from_iter(mp_obj_t iterable) { return list_extend_from_iter(list, iterable); } -STATIC mp_obj_t list_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t list_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; - mp_arg_check_num(n_args, kw_args, 0, 1, false); + mp_arg_check_num(n_args, n_kw, 0, 1, false); switch (n_args) { case 0: diff --git a/py/objmap.c b/py/objmap.c index 262c32bf7d..dc1dc1387d 100644 --- a/py/objmap.c +++ b/py/objmap.c @@ -36,8 +36,8 @@ typedef struct _mp_obj_map_t { mp_obj_t iters[]; } mp_obj_map_t; -STATIC mp_obj_t map_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 2, MP_OBJ_FUN_ARGS_MAX, false); +STATIC mp_obj_t map_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 2, MP_OBJ_FUN_ARGS_MAX, false); mp_obj_map_t *o = m_new_obj_var(mp_obj_map_t, mp_obj_t, n_args - 1); o->base.type = type; o->n_iters = n_args - 1; diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c index 9c21c4dd0a..c970d1afba 100644 --- a/py/objnamedtuple.c +++ b/py/objnamedtuple.c @@ -100,13 +100,9 @@ void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } -mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { const mp_obj_namedtuple_type_t *type = (const mp_obj_namedtuple_type_t *)type_in; size_t num_fields = type->n_fields; - size_t n_kw = 0; - if (kw_args != NULL) { - n_kw = kw_args->used; - } if (n_args + n_kw != num_fields) { #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE mp_arg_error_terse_mismatch(); @@ -130,26 +126,25 @@ mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, const // Fill in the remaining slots with the keyword args memset(&tuple->items[n_args], 0, sizeof(mp_obj_t) * n_kw); - for (size_t i = 0; i < n_kw; i++) { - qstr kw = mp_obj_str_get_qstr(kw_args->table[i].key); + for (size_t i = n_args; i < n_args + 2 * n_kw; i += 2) { + qstr kw = mp_obj_str_get_qstr(args[i]); size_t id = mp_obj_namedtuple_find_field(type, kw); if (id == (size_t)-1) { #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE mp_arg_error_terse_mismatch(); #else - mp_raise_TypeError_varg( - MP_ERROR_TEXT("unexpected keyword argument '%q'"), kw); + mp_raise_msg_varg(&mp_type_TypeError, MP_ERROR_TEXT("unexpected keyword argument '%q'"), kw); #endif } if (tuple->items[id] != MP_OBJ_NULL) { #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE mp_arg_error_terse_mismatch(); #else - mp_raise_TypeError_varg( + mp_raise_msg_varg(&mp_type_TypeError, MP_ERROR_TEXT("function got multiple values for argument '%q'"), kw); #endif } - tuple->items[id] = kw_args->table[i].value; + tuple->items[id] = args[i + 1]; } return MP_OBJ_FROM_PTR(tuple); diff --git a/py/objnamedtuple.h b/py/objnamedtuple.h index e39f569908..4ebefb9d3a 100644 --- a/py/objnamedtuple.h +++ b/py/objnamedtuple.h @@ -51,7 +51,7 @@ void namedtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t ki size_t mp_obj_namedtuple_find_field(const mp_obj_namedtuple_type_t *type, qstr name); void namedtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest); mp_obj_namedtuple_type_t *mp_obj_new_namedtuple_base(size_t n_fields, mp_obj_t *fields); -mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args); +mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args); #endif // MICROPY_PY_COLLECTIONS diff --git a/py/objobject.c b/py/objobject.c index 0fdaf0f2b3..d9c75faff9 100644 --- a/py/objobject.c +++ b/py/objobject.c @@ -35,9 +35,9 @@ typedef struct _mp_obj_object_t { mp_obj_base_t base; } mp_obj_object_t; -STATIC mp_obj_t object_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t object_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)args; - mp_arg_check_num(n_args, kw_args, 0, 0, false); + mp_arg_check_num(n_args, n_kw, 0, 0, false); mp_obj_object_t *o = m_new_obj(mp_obj_object_t); o->base.type = type; return MP_OBJ_FROM_PTR(o); diff --git a/py/objproperty.c b/py/objproperty.c index 32c50f5b94..ebb70014a4 100644 --- a/py/objproperty.c +++ b/py/objproperty.c @@ -33,7 +33,7 @@ #if MICROPY_PY_BUILTINS_PROPERTY -STATIC mp_obj_t property_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t property_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { enum { ARG_fget, ARG_fset, ARG_fdel, ARG_doc }; static const mp_arg_t allowed_args[] = { { MP_QSTR_, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, @@ -42,7 +42,7 @@ STATIC mp_obj_t property_make_new(const mp_obj_type_t *type, size_t n_args, cons { MP_QSTR_doc, MP_ARG_OBJ, {.u_rom_obj = MP_ROM_NONE} }, }; mp_arg_val_t vals[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, vals); + mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args), allowed_args, vals); mp_obj_property_t *o = m_new_obj(mp_obj_property_t); o->base.type = type; diff --git a/py/objrange.c b/py/objrange.c index 331b9b8bd9..b23ab23bd7 100644 --- a/py/objrange.c +++ b/py/objrange.c @@ -94,8 +94,8 @@ STATIC void range_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind } } -STATIC mp_obj_t range_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, 3, false); +STATIC mp_obj_t range_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 1, 3, false); mp_obj_range_t *o = m_new_obj(mp_obj_range_t); o->base.type = type; diff --git a/py/objreversed.c b/py/objreversed.c index 6226c50f8a..fe517cc37f 100644 --- a/py/objreversed.c +++ b/py/objreversed.c @@ -37,8 +37,8 @@ typedef struct _mp_obj_reversed_t { mp_uint_t cur_index; // current index, plus 1; 0=no more, 1=last one (index 0) } mp_obj_reversed_t; -STATIC mp_obj_t reversed_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, 1, false); +STATIC mp_obj_t reversed_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 1, 1, false); // check if __reversed__ exists, and if so delegate to it mp_obj_t dest[2]; diff --git a/py/objset.c b/py/objset.c index 064cbc8d55..d7dda6ba59 100644 --- a/py/objset.c +++ b/py/objset.c @@ -101,8 +101,8 @@ STATIC void set_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t #endif } -STATIC mp_obj_t set_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 0, 1, false); +STATIC mp_obj_t set_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 0, 1, false); switch (n_args) { case 0: { @@ -294,7 +294,7 @@ STATIC mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool if (is_set_or_frozenset(self_in)) { self = MP_OBJ_TO_PTR(self_in); } else { - self = MP_OBJ_TO_PTR(set_make_new(&mp_type_set, 1, &self_in, NULL)); + self = MP_OBJ_TO_PTR(set_make_new(&mp_type_set, 1, 0, &self_in)); cleanup_self = true; } @@ -303,7 +303,7 @@ STATIC mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool if (is_set_or_frozenset(other_in)) { other = MP_OBJ_TO_PTR(other_in); } else { - other = MP_OBJ_TO_PTR(set_make_new(&mp_type_set, 1, &other_in, NULL)); + other = MP_OBJ_TO_PTR(set_make_new(&mp_type_set, 1, 0, &other_in)); cleanup_other = true; } mp_obj_t out = mp_const_true; @@ -374,7 +374,7 @@ STATIC mp_obj_t set_remove(mp_obj_t self_in, mp_obj_t item) { check_set(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); if (mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_REMOVE_IF_FOUND) == MP_OBJ_NULL) { - mp_raise_arg1(&mp_type_KeyError, item); + mp_raise_type_arg(&mp_type_KeyError, item); } return mp_const_none; } diff --git a/py/objslice.c b/py/objslice.c index 0b214c4c1a..142f62fdac 100644 --- a/py/objslice.c +++ b/py/objslice.c @@ -90,12 +90,12 @@ STATIC void slice_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { #if MICROPY_PY_BUILTINS_SLICE_ATTRS STATIC mp_obj_t slice_make_new(const mp_obj_type_t *type, - size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { + size_t n_args, size_t n_kw, const mp_obj_t *args) { if (type != &mp_type_slice) { mp_raise_NotImplementedError(MP_ERROR_TEXT("Cannot subclass slice")); } // check number of arguments - mp_arg_check_num(n_args, kw_args, 1, 3, false); + mp_arg_check_num(n_args, n_kw, 1, 3, false); // 1st argument is the pin mp_obj_t start = mp_const_none; diff --git a/py/objstr.c b/py/objstr.c index ed49eba172..3d45383bb3 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -141,14 +141,8 @@ STATIC void str_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t } } -mp_obj_t mp_obj_str_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - #if MICROPY_CPYTHON_COMPAT - if (kw_args != NULL && kw_args->used != 0) { - mp_arg_error_unimpl_kw(); - } - #endif - - mp_arg_check_num(n_args, kw_args, 0, 3, false); +mp_obj_t mp_obj_str_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 0, 3, false); switch (n_args) { case 0: @@ -199,15 +193,15 @@ mp_obj_t mp_obj_str_make_new(const mp_obj_type_t *type, size_t n_args, const mp_ } } -STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t bytes_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; #if MICROPY_CPYTHON_COMPAT - if (kw_args != NULL && kw_args->used != 0) { + if (n_kw) { mp_arg_error_unimpl_kw(); } #else - (void)kw_args; + (void)n_kw; #endif if (n_args == 0) { @@ -489,7 +483,7 @@ STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) { if (!mp_obj_is_type(arg, &mp_type_list) && !mp_obj_is_type(arg, &mp_type_tuple)) { // arg is not a list nor a tuple, try to convert it to a list // TODO: Try to optimize? - arg = mp_type_list.make_new(&mp_type_list, 1, &arg, NULL); + arg = mp_type_list.make_new(&mp_type_list, 1, 0, &arg); } mp_obj_get_array(arg, &seq_len, &seq_items); @@ -1107,7 +1101,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar field_name = lookup; mp_map_elem_t *key_elem = mp_map_lookup(kwargs, field_q, MP_MAP_LOOKUP); if (key_elem == NULL) { - mp_raise_arg1(&mp_type_KeyError, field_q); + mp_raise_type_arg(&mp_type_KeyError, field_q); } arg = key_elem->value; } @@ -1562,7 +1556,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_ char ch = mp_obj_get_int(arg); mp_print_strn(&print, &ch, 1, flags, ' ', width); } else { - mp_raise_TypeError(MP_ERROR_TEXT("integer required")); + mp_raise_TypeError(MP_ERROR_TEXT("%%c requires int or char")); } break; @@ -1935,7 +1929,7 @@ STATIC mp_obj_t bytes_decode(size_t n_args, const mp_obj_t *args) { args = new_args; n_args++; } - return mp_obj_str_make_new(&mp_type_str, n_args, args, NULL); + return mp_obj_str_make_new(&mp_type_str, n_args, 0, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bytes_decode_obj, 1, 3, bytes_decode); @@ -1948,7 +1942,7 @@ STATIC mp_obj_t str_encode(size_t n_args, const mp_obj_t *args) { args = new_args; n_args++; } - return bytes_make_new(NULL, n_args, args, NULL); + return bytes_make_new(NULL, n_args, 0, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_encode_obj, 1, 3, str_encode); #endif diff --git a/py/objstr.h b/py/objstr.h index 74b48c1c71..8031839146 100644 --- a/py/objstr.h +++ b/py/objstr.h @@ -61,7 +61,7 @@ const byte *mp_obj_str_get_data_no_check(mp_obj_t self_in, size_t *len); else { str_len = ((mp_obj_str_t *)MP_OBJ_TO_PTR(str_obj_in))->len; str_data = ((mp_obj_str_t *)MP_OBJ_TO_PTR(str_obj_in))->data; } #endif -mp_obj_t mp_obj_str_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args); +mp_obj_t mp_obj_str_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args); void mp_str_print_json(const mp_print_t *print, const byte *str_data, size_t str_len); mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs); mp_obj_t mp_obj_str_split(size_t n_args, const mp_obj_t *args); diff --git a/py/objstringio.c b/py/objstringio.c index 9bf95440ba..336a041baf 100644 --- a/py/objstringio.c +++ b/py/objstringio.c @@ -186,8 +186,8 @@ STATIC mp_obj_stringio_t *stringio_new(const mp_obj_type_t *type) { return o; } -STATIC mp_obj_t stringio_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - (void)kw_args; // TODO check kw_args->used == 0 +STATIC mp_obj_t stringio_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 0, 1, false); mp_uint_t sz = 16; bool initdata = false; diff --git a/py/objtuple.c b/py/objtuple.c index 0fc50c53fd..55957b68bf 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -40,15 +40,19 @@ void mp_obj_tuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { mp_obj_tuple_t *o = MP_OBJ_TO_PTR(o_in); + const char *item_separator = ", "; if (MICROPY_PY_UJSON && kind == PRINT_JSON) { mp_print_str(print, "["); + #if MICROPY_PY_UJSON_SEPARATORS + item_separator = MP_PRINT_GET_EXT(print)->item_separator; + #endif } else { mp_print_str(print, "("); kind = PRINT_REPR; } for (size_t i = 0; i < o->len; i++) { if (i > 0) { - mp_print_str(print, ", "); + mp_print_str(print, item_separator); } mp_obj_print_helper(print, o->items[i], kind); } @@ -62,10 +66,10 @@ void mp_obj_tuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t } } -STATIC mp_obj_t mp_obj_tuple_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t mp_obj_tuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; - mp_arg_check_num(n_args, kw_args, 0, 1, false); + mp_arg_check_num(n_args, n_kw, 0, 1, false); switch (n_args) { case 0: diff --git a/py/objtype.c b/py/objtype.c index b692760997..962f59eb55 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -48,7 +48,7 @@ #define ENABLE_SPECIAL_ACCESSORS \ (MICROPY_PY_DESCRIPTORS || MICROPY_PY_DELATTR_SETATTR || MICROPY_PY_BUILTINS_PROPERTY) -STATIC mp_obj_t static_class_method_make_new(const mp_obj_type_t *self_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args); +STATIC mp_obj_t static_class_method_make_new(const mp_obj_type_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args); /******************************************************************************/ // instance object @@ -95,9 +95,24 @@ STATIC mp_obj_t native_base_init_wrapper(size_t n_args, const mp_obj_t *pos_args mp_obj_instance_t *self = MP_OBJ_TO_PTR(pos_args[0]); const mp_obj_type_t *native_base = NULL; instance_count_native_bases(self->base.type, &native_base); - self->subobj[0] = native_base->make_new(native_base, n_args - 1, pos_args + 1, kw_args); + + size_t n_kw = kw_args ? kw_args->used : 0; + + // consume the type object + pos_args++; + n_args--; + + mp_obj_t *args2 = m_new(mp_obj_t, n_args + 2 * n_kw); + // copy in args + memcpy(args2, pos_args, n_args * sizeof(mp_obj_t)); + // copy in kwargs + memcpy(args2 + n_args, kw_args->table, 2 * n_kw * sizeof(mp_obj_t)); + self->subobj[0] = native_base->make_new(native_base, n_args, n_kw, args2); + m_del(mp_obj_t, args2, n_args + 2 * n_kw); + return mp_const_none; } + STATIC MP_DEFINE_CONST_FUN_OBJ_KW(native_base_init_wrapper_obj, 1, native_base_init_wrapper); #if !MICROPY_CPYTHON_COMPAT @@ -294,7 +309,7 @@ STATIC void instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_k mp_printf(print, "<%q object at %p>", mp_obj_get_type_qstr(self_in), self); } -mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args) { assert(mp_obj_is_instance_type(self)); // look for __new__ function @@ -310,10 +325,6 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, cons const mp_obj_type_t *native_base = NULL; mp_obj_instance_t *o; - size_t n_kw = 0; - if (kw_args != 0) { - n_kw = kw_args->used; - } if (init_fn[0] == MP_OBJ_NULL || init_fn[0] == MP_OBJ_SENTINEL) { // Either there is no __new__() method defined or there is a native // constructor. In both cases create a blank instance. @@ -335,11 +346,7 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, cons // TODO(tannewt): Could this be on the stack? It's deleted below. mp_obj_t *args2 = m_new(mp_obj_t, 1 + n_args + 2 * n_kw); args2[0] = MP_OBJ_FROM_PTR(self); - memcpy(args2 + 1, args, n_args * sizeof(mp_obj_t)); - if (kw_args) { - // copy in kwargs - memcpy(args2 + 1 + n_args, kw_args->table, 2 * n_kw * sizeof(mp_obj_t)); - } + memcpy(args2 + 1, args, (n_args + 2 * n_kw) * sizeof(mp_obj_t)); new_ret = mp_call_function_n_kw(init_fn[0], n_args + 1, n_kw, args2); m_del(mp_obj_t, args2, 1 + n_args + 2 * n_kw); } @@ -365,7 +372,7 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, cons mp_obj_class_lookup(&lookup, self); if (init_fn[0] != MP_OBJ_NULL) { mp_obj_t init_ret; - if (n_args == 0 && kw_args == NULL) { + if (n_args == 0 && n_kw == 0) { init_ret = mp_call_method_n_kw(0, 0, init_fn); } else { // TODO(tannewt): Could this be on the stack? It's deleted below. @@ -373,8 +380,7 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, cons args2[0] = init_fn[0]; args2[1] = init_fn[1]; // copy in kwargs - memcpy(args2 + 2, args, n_args * sizeof(mp_obj_t)); - memcpy(args2 + 2 + n_args, kw_args->table, 2 * n_kw * sizeof(mp_obj_t)); + memcpy(args2 + 2, args, (n_args + 2 * n_kw) * sizeof(mp_obj_t)); init_ret = mp_call_method_n_kw(n_args, n_kw, args2); m_del(mp_obj_t, args2, 2 + n_args + 2 * n_kw); } @@ -391,7 +397,7 @@ mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, cons // If the type had a native base that was not explicitly initialised // (constructed) by the Python __init__() method then construct it now. if (native_base != NULL && o->subobj[0] == MP_OBJ_FROM_PTR(&native_base_init_wrapper_obj)) { - o->subobj[0] = native_base->make_new(native_base, n_args, args, kw_args); + o->subobj[0] = native_base->make_new(native_base, n_args, n_kw, args); } return MP_OBJ_FROM_PTR(o); @@ -1009,10 +1015,10 @@ STATIC void type_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ mp_printf(print, "", self->name); } -STATIC mp_obj_t type_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t type_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; - mp_arg_check_num(n_args, kw_args, 1, 3, false); + mp_arg_check_num(n_args, n_kw, 1, 3, false); switch (n_args) { case 1: @@ -1042,10 +1048,7 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp #endif } - // create a map directly from the given args array and make a new instance - mp_map_t kw_args; - mp_map_init_fixed_table(&kw_args, n_kw, args + n_args); - mp_obj_t o = self->make_new(self, n_args, args, &kw_args); + mp_obj_t o = self->make_new(self, n_args, n_kw, args); // return new instance return o; @@ -1269,7 +1272,7 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) // __new__ slot exists; check if it is a function if (mp_obj_is_fun(elem->value)) { // __new__ is a function, wrap it in a staticmethod decorator - elem->value = static_class_method_make_new(&mp_type_staticmethod, 1, &elem->value, NULL); + elem->value = static_class_method_make_new(&mp_type_staticmethod, 1, 0, &elem->value); } } @@ -1295,11 +1298,11 @@ STATIC void super_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind mp_print_str(print, ">"); } -STATIC mp_obj_t super_make_new(const mp_obj_type_t *type_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t super_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)type_in; // 0 arguments are turned into 2 in the compiler // 1 argument is not yet implemented - mp_arg_check_num(n_args, kw_args, 2, 2, false); + mp_arg_check_num(n_args, n_kw, 2, 2, false); if (!mp_obj_is_type(args[0], &mp_type_type)) { mp_raise_TypeError(MP_ERROR_TEXT("first argument to super() must be type")); } @@ -1511,10 +1514,10 @@ mp_obj_t mp_obj_cast_to_native_base(mp_obj_t self_in, mp_const_obj_t native_type /******************************************************************************/ // staticmethod and classmethod types (probably should go in a different file) -STATIC mp_obj_t static_class_method_make_new(const mp_obj_type_t *self, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t static_class_method_make_new(const mp_obj_type_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args) { assert(self == &mp_type_staticmethod || self == &mp_type_classmethod); - mp_arg_check_num(n_args, kw_args, 1, 1, false); + mp_arg_check_num(n_args, n_kw, 1, 1, false); mp_obj_static_class_method_t *o = m_new_obj(mp_obj_static_class_method_t); *o = (mp_obj_static_class_method_t) {{self}, args[0]}; diff --git a/py/objtype.h b/py/objtype.h index 072c39d3e7..17b8048c19 100644 --- a/py/objtype.h +++ b/py/objtype.h @@ -51,7 +51,7 @@ mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons #define mp_obj_is_instance_type(type) ((type)->make_new == mp_obj_instance_make_new) #define mp_obj_is_native_type(type) ((type)->make_new != mp_obj_instance_make_new) // this needs to be exposed for the above macros to work correctly -mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self_in, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args); +mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); // this needs to be exposed for mp_getiter mp_obj_t mp_obj_instance_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf); diff --git a/py/objzip.c b/py/objzip.c index 111f6bf5ec..91716493d6 100644 --- a/py/objzip.c +++ b/py/objzip.c @@ -36,8 +36,8 @@ typedef struct _mp_obj_zip_t { mp_obj_t iters[]; } mp_obj_zip_t; -STATIC mp_obj_t zip_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 0, MP_OBJ_FUN_ARGS_MAX, false); +STATIC mp_obj_t zip_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 0, MP_OBJ_FUN_ARGS_MAX, false); mp_obj_zip_t *o = m_new_obj_var(mp_obj_zip_t, mp_obj_t, n_args); o->base.type = type; diff --git a/py/parse.c b/py/parse.c index 689125f117..f5f3e774da 100644 --- a/py/parse.c +++ b/py/parse.c @@ -1172,57 +1172,23 @@ mp_parse_tree_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind) { ) { syntax_error:; mp_obj_t exc; - switch (lex->tok_kind) { - case MP_TOKEN_INDENT: - exc = mp_obj_new_exception_msg(&mp_type_IndentationError, - MP_ERROR_TEXT("unexpected indent")); - break; - case MP_TOKEN_DEDENT_MISMATCH: - exc = mp_obj_new_exception_msg(&mp_type_IndentationError, - MP_ERROR_TEXT("unindent does not match any outer indentation level")); - break; - #if MICROPY_COMP_FSTRING_LITERAL - #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED - case MP_TOKEN_FSTRING_BACKSLASH: - exc = mp_obj_new_exception_msg(&mp_type_SyntaxError, - MP_ERROR_TEXT("f-string expression part cannot include a backslash")); - break; - case MP_TOKEN_FSTRING_COMMENT: - exc = mp_obj_new_exception_msg(&mp_type_SyntaxError, - MP_ERROR_TEXT("f-string expression part cannot include a '#'")); - break; - case MP_TOKEN_FSTRING_UNCLOSED: - exc = mp_obj_new_exception_msg(&mp_type_SyntaxError, - MP_ERROR_TEXT("f-string: expecting '}'")); - break; - case MP_TOKEN_FSTRING_UNOPENED: - exc = mp_obj_new_exception_msg(&mp_type_SyntaxError, - MP_ERROR_TEXT("f-string: single '}' is not allowed")); - break; - case MP_TOKEN_FSTRING_EMPTY_EXP: - exc = mp_obj_new_exception_msg(&mp_type_SyntaxError, - MP_ERROR_TEXT("f-string: empty expression not allowed")); - break; - case MP_TOKEN_FSTRING_RAW: - exc = mp_obj_new_exception_msg(&mp_type_NotImplementedError, - MP_ERROR_TEXT("raw f-strings are not implemented")); - break; - #else - case MP_TOKEN_FSTRING_BACKSLASH: - case MP_TOKEN_FSTRING_COMMENT: - case MP_TOKEN_FSTRING_UNCLOSED: - case MP_TOKEN_FSTRING_UNOPENED: - case MP_TOKEN_FSTRING_EMPTY_EXP: - case MP_TOKEN_FSTRING_RAW: - exc = mp_obj_new_exception_msg(&mp_type_SyntaxError, - MP_ERROR_TEXT("malformed f-string")); - break; - #endif - #endif - default: - exc = mp_obj_new_exception_msg(&mp_type_SyntaxError, - MP_ERROR_TEXT("invalid syntax")); - break; + if (lex->tok_kind == MP_TOKEN_INDENT) { + exc = mp_obj_new_exception_msg(&mp_type_IndentationError, + MP_ERROR_TEXT("unexpected indent")); + } else if (lex->tok_kind == MP_TOKEN_DEDENT_MISMATCH) { + exc = mp_obj_new_exception_msg(&mp_type_IndentationError, + MP_ERROR_TEXT("unindent doesn't match any outer indent level")); + #if MICROPY_PY_FSTRINGS + } else if (lex->tok_kind == MP_TOKEN_MALFORMED_FSTRING) { + exc = mp_obj_new_exception_msg(&mp_type_SyntaxError, + MP_ERROR_TEXT("malformed f-string")); + } else if (lex->tok_kind == MP_TOKEN_FSTRING_RAW) { + exc = mp_obj_new_exception_msg(&mp_type_SyntaxError, + MP_ERROR_TEXT("raw f-strings are not supported")); + #endif + } else { + exc = mp_obj_new_exception_msg(&mp_type_SyntaxError, + MP_ERROR_TEXT("invalid syntax")); } // add traceback to give info about file name and location // we don't have a 'block' name, so just pass the NULL qstr to indicate this diff --git a/py/profile.c b/py/profile.c index 2e59b97703..7d1d7ed659 100644 --- a/py/profile.c +++ b/py/profile.c @@ -297,7 +297,7 @@ STATIC mp_obj_t mp_prof_callback_invoke(mp_obj_t callback, prof_callback_args_t mp_prof_is_executing = false; - if (MP_STATE_VM(mp_pending_exception) != MP_OBJ_NULL) { + if (MP_STATE_THREAD(mp_pending_exception) != MP_OBJ_NULL) { mp_handle_pending(true); } return top; diff --git a/py/py.mk b/py/py.mk index 7c3eaf4f46..0db1d43cfe 100644 --- a/py/py.mk +++ b/py/py.mk @@ -210,8 +210,8 @@ PY_EXTMOD_O_BASENAME = \ extmod/vfs_fat_file.o \ extmod/vfs_lfs.o \ extmod/utime_mphal.o \ - lib/embed/abort_.o \ - lib/utils/printf.o \ + shared/libc/abort_.o \ + shared/libc/printf.o \ # prepend the build destination prefix to the py object files PY_CORE_O = $(addprefix $(BUILD)/, $(PY_CORE_O_BASENAME)) @@ -251,14 +251,7 @@ FORCE: $(HEADER_BUILD)/mpversion.h: FORCE | $(HEADER_BUILD) $(STEPECHO) "GEN $@" - $(Q)$(PYTHON3) $(PY_SRC)/makeversionhdr.py $@ - -# build a list of registered modules for py/objmodule.c. -$(HEADER_BUILD)/moduledefs.h: $(SRC_QSTR) $(QSTR_GLOBAL_DEPENDENCIES) | $(HEADER_BUILD)/mpversion.h - @$(STEPECHO) "GEN $@" - $(Q)$(PYTHON3) $(PY_SRC)/makemoduledefs.py --vpath="., $(TOP), $(USER_C_MODULES)" $(SRC_QSTR) > $@ - -SRC_QSTR += $(HEADER_BUILD)/moduledefs.h + $(Q)$(PYTHON) $(PY_SRC)/makeversionhdr.py $@ # mpconfigport.mk is optional, but changes to it may drastically change # overall config, so they need to be caught @@ -274,7 +267,7 @@ $(HEADER_BUILD)/qstrdefs.preprocessed.h: $(PY_QSTR_DEFS) $(QSTR_DEFS) $(QSTR_DEF # qstr data $(HEADER_BUILD)/qstrdefs.enum.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h $(STEPECHO) "GEN $@" - $(Q)$(PYTHON3) $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ + $(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ # Adding an order only dependency on $(HEADER_BUILD) causes $(HEADER_BUILD) to get # created before we run the script to generate the .h @@ -282,19 +275,20 @@ $(HEADER_BUILD)/qstrdefs.enum.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/qstrd # the lines in "" and then unwrap after the preprocessor is finished. $(HEADER_BUILD)/qstrdefs.generated.h: $(PY_SRC)/makeqstrdata.py $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h $(STEPECHO) "GEN $@" - $(Q)$(PYTHON3) $(PY_SRC)/makeqstrdata.py --compression_filename $(HEADER_BUILD)/compression.generated.h --translation $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ + $(Q)$(PYTHON) $(PY_SRC)/makeqstrdata.py --compression_filename $(HEADER_BUILD)/compression.generated.h --translation $(HEADER_BUILD)/$(TRANSLATION).mo $(HEADER_BUILD)/qstrdefs.preprocessed.h > $@ $(PY_BUILD)/qstr.o: $(HEADER_BUILD)/qstrdefs.generated.h -# Standard C functions like memset need to be compiled with special flags so -# the compiler does not optimise these functions in terms of themselves. -CFLAGS_BUILTIN ?= -ffreestanding -fno-builtin -fno-lto -$(BUILD)/lib/libc/string0.o: CFLAGS += $(CFLAGS_BUILTIN) + +# build a list of registered modules for py/objmodule.c. +$(HEADER_BUILD)/moduledefs.h: $(SRC_QSTR) $(QSTR_GLOBAL_DEPENDENCIES) | $(HEADER_BUILD)/mpversion.h + @$(ECHO) "GEN $@" + $(Q)$(PYTHON) $(PY_SRC)/makemoduledefs.py --vpath="., $(TOP), $(USER_C_MODULES)" $(SRC_QSTR) > $@ # Standard C functions like memset need to be compiled with special flags so # the compiler does not optimise these functions in terms of themselves. CFLAGS_BUILTIN ?= -ffreestanding -fno-builtin -fno-lto -$(BUILD)/lib/libc/string0.o: CFLAGS += $(CFLAGS_BUILTIN) +$(BUILD)/shared/libc/string0.o: CFLAGS += $(CFLAGS_BUILTIN) # Force nlr code to always be compiled with space-saving optimisation so # that the function preludes are of a minimal and predictable form. diff --git a/py/pystack.c b/py/pystack.c index c48437aa74..43dfd4ed6c 100644 --- a/py/pystack.c +++ b/py/pystack.c @@ -43,8 +43,7 @@ void *mp_pystack_alloc(size_t n_bytes) { #endif if (MP_STATE_THREAD(pystack_cur) + n_bytes > MP_STATE_THREAD(pystack_end)) { // out of memory in the pystack - mp_raise_arg1(&mp_type_RuntimeError, - MP_OBJ_NEW_QSTR(MP_QSTR_pystack_space_exhausted)); + mp_raise_type_arg(&mp_type_RuntimeError, MP_OBJ_NEW_QSTR(MP_QSTR_pystack_space_exhausted)); } void *ptr = MP_STATE_THREAD(pystack_cur); MP_STATE_THREAD(pystack_cur) += n_bytes; diff --git a/py/reload.c b/py/reload.c index 9f20004690..996826b930 100644 --- a/py/reload.c +++ b/py/reload.c @@ -22,7 +22,7 @@ #include "py/mpstate.h" void mp_raise_reload_exception(void) { - MP_STATE_VM(mp_pending_exception) = MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception)); + MP_STATE_THREAD(mp_pending_exception) = MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_reload_exception)); #if MICROPY_ENABLE_SCHEDULER if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) { MP_STATE_VM(sched_state) = MP_SCHED_PENDING; diff --git a/py/runtime.c b/py/runtime.c index 55f26021ab..ac02f7074c 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -65,7 +65,7 @@ void mp_init(void) { qstr_init(); // no pending exceptions to start with - MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL; + MP_STATE_THREAD(mp_pending_exception) = MP_OBJ_NULL; #if MICROPY_ENABLE_SCHEDULER MP_STATE_VM(sched_state) = MP_SCHED_IDLE; MP_STATE_VM(sched_idx) = 0; @@ -287,6 +287,12 @@ mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg) { return result; } } + if (op == MP_UNARY_OP_BOOL) { + // Type doesn't have unary_op (or didn't handle MP_UNARY_OP_BOOL), + // so is implicitly True as this code path is impossible to reach + // if arg==mp_const_none. + return mp_const_true; + } // With MP_UNARY_OP_INT, mp_unary_op() becomes a fallback for mp_obj_get_int(). // In this case provide a more focused error message to not confuse, e.g. chr(1.0) #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE @@ -393,7 +399,7 @@ mp_obj_t PLACE_IN_ITCM(mp_binary_op)(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t r goto generic_binary_op; } else { // use standard precision - lhs_val <<= rhs_val; + lhs_val = (mp_uint_t)lhs_val << rhs_val; } break; } @@ -1275,6 +1281,7 @@ mp_obj_t mp_iternext_allow_raise(mp_obj_t o_in) { const mp_obj_type_t *type = mp_obj_get_type(o_in); mp_fun_1_t iternext = mp_type_get_iternext_slot(type); if (iternext != NULL) { + MP_STATE_THREAD(stop_iteration_arg) = MP_OBJ_NULL; return iternext(o_in); } else { // check for __next__ method @@ -1301,6 +1308,7 @@ mp_obj_t mp_iternext(mp_obj_t o_in) { const mp_obj_type_t *type = mp_obj_get_type(o_in); mp_fun_1_t iternext = mp_type_get_iternext_slot(type); if (iternext != NULL) { + MP_STATE_THREAD(stop_iteration_arg) = MP_OBJ_NULL; return iternext(o_in); } else { // check for __next__ method @@ -1315,7 +1323,7 @@ mp_obj_t mp_iternext(mp_obj_t o_in) { return ret; } else { if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(((mp_obj_base_t *)nlr.ret_val)->type), MP_OBJ_FROM_PTR(&mp_type_StopIteration))) { - return MP_OBJ_STOP_ITERATION; + return mp_make_stop_iteration(mp_obj_exception_get_value(MP_OBJ_FROM_PTR(nlr.ret_val))); } else { nlr_jump(nlr.ret_val); } @@ -1331,7 +1339,6 @@ mp_obj_t mp_iternext(mp_obj_t o_in) { } } -// TODO: Unclear what to do with StopIterarion exception here. mp_vm_return_kind_t mp_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value, mp_obj_t *ret_val) { assert((send_value != MP_OBJ_NULL) ^ (throw_value != MP_OBJ_NULL)); const mp_obj_type_t *type = mp_obj_get_type(self_in); @@ -1342,13 +1349,18 @@ mp_vm_return_kind_t mp_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t th mp_fun_1_t iternext = mp_type_get_iternext_slot(type); if (iternext != NULL && send_value == mp_const_none) { + MP_STATE_THREAD(stop_iteration_arg) = MP_OBJ_NULL; mp_obj_t ret = iternext(self_in); *ret_val = ret; if (ret != MP_OBJ_STOP_ITERATION) { return MP_VM_RETURN_YIELD; } else { - // Emulate raise StopIteration() - // Special case, handled in vm.c + // The generator is finished. + // This is an optimised "raise StopIteration(*ret_val)". + *ret_val = MP_STATE_THREAD(stop_iteration_arg); + if (*ret_val == MP_OBJ_NULL) { + *ret_val = mp_const_none; + } return MP_VM_RETURN_NORMAL; } } @@ -1568,10 +1580,6 @@ NORETURN void m_malloc_fail(size_t num_bytes) { MP_ERROR_TEXT("memory allocation failed, allocating %u bytes"), (uint)num_bytes); } -NORETURN void mp_raise_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg) { - nlr_raise(mp_obj_new_exception_arg1(exc_type, arg)); -} - #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NONE NORETURN void mp_raise_type(const mp_obj_type_t *exc_type) { @@ -1665,10 +1673,6 @@ NORETURN void mp_raise_TypeError_varg(const compressed_string_t *fmt, ...) { va_end(argptr); } -NORETURN void mp_raise_OSError(int errno_) { - mp_raise_arg1(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno_)); -} - NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg) { mp_raise_msg(&mp_type_OSError, msg); } @@ -1693,7 +1697,7 @@ NORETURN void mp_raise_ConnectionError(const compressed_string_t *msg) { } NORETURN void mp_raise_BrokenPipeError(void) { - mp_raise_arg1(&mp_type_BrokenPipeError, MP_OBJ_NEW_SMALL_INT(MP_EPIPE)); + mp_raise_type_arg(&mp_type_BrokenPipeError, MP_OBJ_NEW_SMALL_INT(MP_EPIPE)); } NORETURN void mp_raise_NotImplementedError(const compressed_string_t *msg) { @@ -1707,6 +1711,7 @@ NORETURN void mp_raise_NotImplementedError_varg(const compressed_string_t *fmt, va_end(argptr); } + NORETURN void mp_raise_OverflowError_varg(const compressed_string_t *fmt, ...) { va_list argptr; va_start(argptr,fmt); @@ -1718,6 +1723,22 @@ NORETURN void mp_raise_MpyError(const compressed_string_t *msg) { mp_raise_msg(&mp_type_MpyError, msg); } +NORETURN void mp_raise_type_arg(const mp_obj_type_t *exc_type, mp_obj_t arg) { + nlr_raise(mp_obj_new_exception_arg1(exc_type, arg)); +} + +NORETURN void mp_raise_StopIteration(mp_obj_t arg) { + if (arg == MP_OBJ_NULL) { + mp_raise_type(&mp_type_StopIteration); + } else { + mp_raise_type_arg(&mp_type_StopIteration, arg); + } +} + +NORETURN void mp_raise_OSError(int errno_) { + mp_raise_type_arg(&mp_type_OSError, MP_OBJ_NEW_SMALL_INT(errno_)); +} + #endif #if MICROPY_STACK_CHECK || MICROPY_ENABLE_PYSTACK diff --git a/py/runtime.h b/py/runtime.h index b93f484ec8..f610a04f8a 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -84,8 +84,9 @@ bool mp_sched_schedule(mp_obj_t function, mp_obj_t arg); int mp_print_mp_int(const mp_print_t *print, mp_obj_t x, int base, int base_char, int flags, char fill, int width, int prec); void mp_arg_check_num_sig(size_t n_args, size_t n_kw, uint32_t sig); -void mp_arg_check_num(size_t n_args, mp_map_t *kw_args, size_t n_args_min, size_t n_args_max, bool takes_kw); -void mp_arg_check_num_kw_array(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_args_max, bool takes_kw); +static inline void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_args_max, bool takes_kw) { + mp_arg_check_num_sig(n_args, n_kw, MP_OBJ_FUN_MAKE_SIG(n_args_min, n_args_max, takes_kw)); +} void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n_allowed, const mp_arg_t *allowed, mp_arg_val_t *out_vals); void mp_arg_parse_all_kw_array(size_t n_pos, size_t n_kw, const mp_obj_t *args, size_t n_allowed, const mp_arg_t *allowed, mp_arg_val_t *out_vals); NORETURN void mp_arg_error_terse_mismatch(void); @@ -165,6 +166,11 @@ mp_obj_t mp_iternext_allow_raise(mp_obj_t o); // may return MP_OBJ_STOP_ITERATIO mp_obj_t mp_iternext(mp_obj_t o); // will always return MP_OBJ_STOP_ITERATION instead of raising StopIteration(...) mp_vm_return_kind_t mp_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t throw_value, mp_obj_t *ret_val); +static inline mp_obj_t mp_make_stop_iteration(mp_obj_t o) { + MP_STATE_THREAD(stop_iteration_arg) = o; + return MP_OBJ_STOP_ITERATION; +} + mp_obj_t mp_make_raise_obj(mp_obj_t o); mp_obj_t mp_import_name(qstr name, mp_obj_t fromlist, mp_obj_t level); @@ -183,9 +189,7 @@ NORETURN void mp_raise_NotImplementedError_no_msg(void); #define mp_raise_NotImplementedError(msg) mp_raise_NotImplementedError_no_msg() #else #define mp_raise_type(exc_type) mp_raise_msg(exc_type, NULL) -#if !(defined(MICROPY_ENABLE_DYNRUNTIME) && MICROPY_ENABLE_DYNRUNTIME) -NORETURN void mp_raise_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg); -#endif +NORETURN void mp_raise_type_arg(const mp_obj_type_t *exc_type, mp_obj_t arg); NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const compressed_string_t *msg); NORETURN void mp_raise_msg_varg(const mp_obj_type_t *exc_type, const compressed_string_t *fmt, ...); NORETURN void mp_raise_msg_vlist(const mp_obj_type_t *exc_type, const compressed_string_t *fmt, va_list argptr); @@ -200,6 +204,7 @@ NORETURN void mp_raise_RuntimeError(const compressed_string_t *msg); NORETURN void mp_raise_ImportError(const compressed_string_t *msg); NORETURN void mp_raise_IndexError(const compressed_string_t *msg); NORETURN void mp_raise_IndexError_varg(const compressed_string_t *msg, ...); +NORETURN void mp_raise_StopIteration(mp_obj_t arg); NORETURN void mp_raise_OSError(int errno_); NORETURN void mp_raise_OSError_errno_str(int errno_, mp_obj_t str); NORETURN void mp_raise_OSError_msg(const compressed_string_t *msg); diff --git a/py/scheduler.c b/py/scheduler.c index 733722e46a..8e150f41ed 100644 --- a/py/scheduler.c +++ b/py/scheduler.c @@ -28,8 +28,10 @@ #include "py/runtime.h" +// Schedules an exception on the main thread (for exceptions "thrown" by async +// sources such as interrupts and UNIX signal handlers). void MICROPY_WRAP_MP_SCHED_EXCEPTION(mp_sched_exception)(mp_obj_t exc) { - MP_STATE_VM(mp_pending_exception) = exc; + MP_STATE_MAIN_THREAD(mp_pending_exception) = exc; #if MICROPY_ENABLE_SCHEDULER if (MP_STATE_VM(sched_state) == MP_SCHED_IDLE) { MP_STATE_VM(sched_state) = MP_SCHED_PENDING; @@ -66,9 +68,9 @@ void mp_handle_pending(bool raise_exc) { mp_uint_t atomic_state = MICROPY_BEGIN_ATOMIC_SECTION(); // Re-check state is still pending now that we're in the atomic section. if (MP_STATE_VM(sched_state) == MP_SCHED_PENDING) { - mp_obj_t obj = MP_STATE_VM(mp_pending_exception); + mp_obj_t obj = MP_STATE_THREAD(mp_pending_exception); if (obj != MP_OBJ_NULL) { - MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL; + MP_STATE_THREAD(mp_pending_exception) = MP_OBJ_NULL; if (!mp_sched_num_pending()) { MP_STATE_VM(sched_state) = MP_SCHED_IDLE; } @@ -115,7 +117,7 @@ void mp_sched_unlock(void) { assert(MP_STATE_VM(sched_state) < 0); if (++MP_STATE_VM(sched_state) == 0) { // vm became unlocked - if (MP_STATE_VM(mp_pending_exception) != MP_OBJ_NULL || mp_sched_num_pending()) { + if (MP_STATE_THREAD(mp_pending_exception) != MP_OBJ_NULL || mp_sched_num_pending()) { MP_STATE_VM(sched_state) = MP_SCHED_PENDING; } else { MP_STATE_VM(sched_state) = MP_SCHED_IDLE; @@ -148,9 +150,9 @@ bool MICROPY_WRAP_MP_SCHED_SCHEDULE(mp_sched_schedule)(mp_obj_t function, mp_obj // A variant of this is inlined in the VM at the pending exception check void mp_handle_pending(bool raise_exc) { - if (MP_STATE_VM(mp_pending_exception) != MP_OBJ_NULL) { - mp_obj_t obj = MP_STATE_VM(mp_pending_exception); - MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL; + if (MP_STATE_THREAD(mp_pending_exception) != MP_OBJ_NULL) { + mp_obj_t obj = MP_STATE_THREAD(mp_pending_exception); + MP_STATE_THREAD(mp_pending_exception) = MP_OBJ_NULL; if (raise_exc) { nlr_raise(obj); } diff --git a/py/showbc.c b/py/showbc.c index 284f134433..e9b43c29e3 100644 --- a/py/showbc.c +++ b/py/showbc.c @@ -174,7 +174,7 @@ const byte *mp_bytecode_print_str(const mp_print_t *print, const byte *ip) { num--; } do { - num = (num * 128) | (*ip & 0x7f); + num = ((mp_uint_t)num << 7) | (*ip & 0x7f); } while ((*ip++ & 0x80) != 0); mp_printf(print, "LOAD_CONST_SMALL_INT " INT_FMT, num); break; diff --git a/py/smallint.h b/py/smallint.h index be70cc78b9..2fcd3fb296 100644 --- a/py/smallint.h +++ b/py/smallint.h @@ -37,7 +37,7 @@ #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A || MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C #define MP_SMALL_INT_MIN ((mp_int_t)(((mp_int_t)MP_OBJ_WORD_MSBIT_HIGH) >> 1)) -#define MP_SMALL_INT_FITS(n) ((((n) ^ ((n) << 1)) & MP_OBJ_WORD_MSBIT_HIGH) == 0) +#define MP_SMALL_INT_FITS(n) ((((n) ^ ((mp_uint_t)(n) << 1)) & MP_OBJ_WORD_MSBIT_HIGH) == 0) // Mask to truncate mp_int_t to positive value #define MP_SMALL_INT_POSITIVE_MASK ~(MP_OBJ_WORD_MSBIT_HIGH | (MP_OBJ_WORD_MSBIT_HIGH >> 1)) diff --git a/py/vm.c b/py/vm.c index b3919a493c..9ad67bb2e0 100644 --- a/py/vm.c +++ b/py/vm.c @@ -324,7 +324,7 @@ dispatch_loop: DISPATCH(); ENTRY(MP_BC_LOAD_CONST_SMALL_INT): { - mp_int_t num = 0; + mp_uint_t num = 0; if ((ip[0] & 0x40) != 0) { // Number is negative num--; @@ -1269,16 +1269,9 @@ yield: PUSH(ret_value); goto yield; } else if (ret_kind == MP_VM_RETURN_NORMAL) { - // Pop exhausted gen - sp--; - if (ret_value == MP_OBJ_STOP_ITERATION) { - // Optimize StopIteration - // TODO: get StopIteration's value - PUSH(mp_const_none); - } else { - PUSH(ret_value); - } - + // The generator has finished, and returned a value via StopIteration + // Replace exhausted generator with the returned value + SET_TOP(ret_value); // If we injected GeneratorExit downstream, then even // if it was swallowed, we re-raise GeneratorExit GENERATOR_EXIT_IF_NEEDED(t_exc); @@ -1387,9 +1380,9 @@ pending_exception_check: // Re-check state is still pending now that we're in the atomic section. if (MP_STATE_VM(sched_state) == MP_SCHED_PENDING) { MARK_EXC_IP_SELECTIVE(); - mp_obj_t obj = MP_STATE_VM(mp_pending_exception); + mp_obj_t obj = MP_STATE_THREAD(mp_pending_exception); if (obj != MP_OBJ_NULL) { - MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL; + MP_STATE_THREAD(mp_pending_exception) = MP_OBJ_NULL; if (!mp_sched_num_pending()) { MP_STATE_VM(sched_state) = MP_SCHED_IDLE; } @@ -1403,10 +1396,10 @@ pending_exception_check: } #else // This is an inlined variant of mp_handle_pending - if (MP_STATE_VM(mp_pending_exception) != MP_OBJ_NULL) { + if (MP_STATE_THREAD(mp_pending_exception) != MP_OBJ_NULL) { MARK_EXC_IP_SELECTIVE(); - mp_obj_t obj = MP_STATE_VM(mp_pending_exception); - MP_STATE_VM(mp_pending_exception) = MP_OBJ_NULL; + mp_obj_t obj = MP_STATE_THREAD(mp_pending_exception); + MP_STATE_THREAD(mp_pending_exception) = MP_OBJ_NULL; RAISE(obj); } #endif diff --git a/shared-bindings/_bleio/Adapter.c b/shared-bindings/_bleio/Adapter.c index 2413e6e019..b2425a7405 100644 --- a/shared-bindings/_bleio/Adapter.c +++ b/shared-bindings/_bleio/Adapter.c @@ -81,7 +81,7 @@ //| """ //| ... //| -STATIC mp_obj_t bleio_adapter_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t bleio_adapter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { #if CIRCUITPY_BLEIO_HCI bleio_adapter_obj_t *self = common_hal_bleio_allocate_adapter_or_raise(); @@ -93,7 +93,7 @@ STATIC mp_obj_t bleio_adapter_make_new(const mp_obj_type_t *type, size_t n_args, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); busio_uart_obj_t *uart = mp_arg_validate_type(args[ARG_uart].u_obj, &busio_uart_type, MP_QSTR_uart); diff --git a/shared-bindings/_bleio/Address.c b/shared-bindings/_bleio/Address.c index 73bf0119c6..93345d95b0 100644 --- a/shared-bindings/_bleio/Address.c +++ b/shared-bindings/_bleio/Address.c @@ -47,7 +47,7 @@ //| `RANDOM_PRIVATE_RESOLVABLE`, or `RANDOM_PRIVATE_NON_RESOLVABLE`.""" //| ... //| -STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_address, ARG_address_type }; static const mp_arg_t allowed_args[] = { { MP_QSTR_address, MP_ARG_OBJ | MP_ARG_REQUIRED }, @@ -55,7 +55,7 @@ STATIC mp_obj_t bleio_address_make_new(const mp_obj_type_t *type, size_t n_args, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); bleio_address_obj_t *self = m_new_obj(bleio_address_obj_t); self->base.type = &bleio_address_type; diff --git a/shared-bindings/_bleio/CharacteristicBuffer.c b/shared-bindings/_bleio/CharacteristicBuffer.c index 79537288cc..81562028e7 100644 --- a/shared-bindings/_bleio/CharacteristicBuffer.c +++ b/shared-bindings/_bleio/CharacteristicBuffer.c @@ -57,7 +57,7 @@ STATIC void raise_error_if_not_connected(bleio_characteristic_buffer_obj_t *self //| Must be >= 1.""" //| ... //| -STATIC mp_obj_t bleio_characteristic_buffer_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t bleio_characteristic_buffer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_characteristic, ARG_timeout, ARG_buffer_size, }; static const mp_arg_t allowed_args[] = { { MP_QSTR_characteristic, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -66,7 +66,7 @@ STATIC mp_obj_t bleio_characteristic_buffer_make_new(const mp_obj_type_t *type, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); bleio_characteristic_obj_t *characteristic = mp_arg_validate_type(args[ARG_characteristic].u_obj, &bleio_characteristic_type, MP_QSTR_characteristic); diff --git a/shared-bindings/_bleio/PacketBuffer.c b/shared-bindings/_bleio/PacketBuffer.c index 801d8e152a..aa6c860a60 100644 --- a/shared-bindings/_bleio/PacketBuffer.c +++ b/shared-bindings/_bleio/PacketBuffer.c @@ -60,7 +60,7 @@ //| (Remote characteristics may not have the correct length.)""" //| ... //| -STATIC mp_obj_t bleio_packet_buffer_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t bleio_packet_buffer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_characteristic, ARG_buffer_size, ARG_max_packet_size }; static const mp_arg_t allowed_args[] = { { MP_QSTR_characteristic, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -69,7 +69,7 @@ STATIC mp_obj_t bleio_packet_buffer_make_new(const mp_obj_type_t *type, size_t n }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); bleio_characteristic_obj_t *characteristic = mp_arg_validate_type(args[ARG_characteristic].u_obj, &bleio_characteristic_type, MP_QSTR_characteristic); diff --git a/shared-bindings/_bleio/Service.c b/shared-bindings/_bleio/Service.c index 30389c9e10..ff1d8c9e21 100644 --- a/shared-bindings/_bleio/Service.c +++ b/shared-bindings/_bleio/Service.c @@ -48,7 +48,7 @@ //| :return: the new Service""" //| ... //| -STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_uuid, ARG_secondary }; static const mp_arg_t allowed_args[] = { { MP_QSTR_uuid, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -56,7 +56,7 @@ STATIC mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); bleio_uuid_obj_t *uuid = mp_arg_validate_type(args[ARG_uuid].u_obj, &bleio_uuid_type, MP_QSTR_uuid); diff --git a/shared-bindings/_bleio/UUID.c b/shared-bindings/_bleio/UUID.c index 90ee0c82b0..028d21d9d5 100644 --- a/shared-bindings/_bleio/UUID.c +++ b/shared-bindings/_bleio/UUID.c @@ -51,13 +51,13 @@ //| :type value: int, ~_typing.ReadableBuffer or str""" //| ... //| -STATIC mp_obj_t bleio_uuid_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, 1, false); +STATIC mp_obj_t bleio_uuid_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + mp_arg_check_num(n_args, n_kw, 1, 1, false); bleio_uuid_obj_t *self = m_new_obj(bleio_uuid_obj_t); self->base.type = type; - const mp_obj_t value = pos_args[0]; + const mp_obj_t value = all_args[0]; uint8_t uuid128[16]; if (mp_obj_is_int(value)) { diff --git a/shared-bindings/_eve/__init__.c b/shared-bindings/_eve/__init__.c index 001c1d3197..69300e47e4 100644 --- a/shared-bindings/_eve/__init__.c +++ b/shared-bindings/_eve/__init__.c @@ -1078,7 +1078,7 @@ STATIC const mp_rom_map_elem_t _EVE_locals_dict_table[] = { }; STATIC MP_DEFINE_CONST_DICT(_EVE_locals_dict, _EVE_locals_dict_table); -STATIC mp_obj_t _EVE_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t _EVE_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // mp_arg_check_num(n_args, kw_args, 1, 1, false); mp_obj__EVE_t *o = m_new_obj(mp_obj__EVE_t); o->base.type = &_EVE_type; diff --git a/shared-bindings/_pew/PewPew.c b/shared-bindings/_pew/PewPew.c index 60f5ec89b7..4015d31161 100644 --- a/shared-bindings/_pew/PewPew.c +++ b/shared-bindings/_pew/PewPew.c @@ -62,9 +62,7 @@ //| buttons are connected to rows of the matrix).""" //| ... //| -STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, - const mp_obj_t *pos_args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 4, 4, true); +STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_buffer, ARG_rows, ARG_cols, ARG_buttons }; static const mp_arg_t allowed_args[] = { { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED }, @@ -73,7 +71,7 @@ STATIC mp_obj_t pewpew_make_new(const mp_obj_type_t *type, size_t n_args, { MP_QSTR_buttons, MP_ARG_OBJ | MP_ARG_REQUIRED }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_buffer_info_t bufinfo; diff --git a/shared-bindings/_stage/Layer.c b/shared-bindings/_stage/Layer.c index 51ed5c3bf6..a040ee9ab0 100644 --- a/shared-bindings/_stage/Layer.c +++ b/shared-bindings/_stage/Layer.c @@ -49,8 +49,8 @@ //| ... //| STATIC mp_obj_t layer_make_new(const mp_obj_type_t *type, size_t n_args, - const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 4, 5, false); + size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 4, 5, false); layer_obj_t *self = m_new_obj(layer_obj_t); self->base.type = type; diff --git a/shared-bindings/_stage/Text.c b/shared-bindings/_stage/Text.c index 55b60953b6..b57f4f0b6a 100644 --- a/shared-bindings/_stage/Text.c +++ b/shared-bindings/_stage/Text.c @@ -49,8 +49,8 @@ //| ... //| STATIC mp_obj_t text_make_new(const mp_obj_type_t *type, size_t n_args, - const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 5, 5, false); + size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 5, 5, false); text_obj_t *self = m_new_obj(text_obj_t); self->base.type = type; diff --git a/shared-bindings/adafruit_bus_device/I2CDevice.c b/shared-bindings/adafruit_bus_device/I2CDevice.c index a6ec8a2dfb..98f2640483 100644 --- a/shared-bindings/adafruit_bus_device/I2CDevice.c +++ b/shared-bindings/adafruit_bus_device/I2CDevice.c @@ -32,8 +32,8 @@ #include "shared-bindings/util.h" #include "shared-module/adafruit_bus_device/I2CDevice.h" -#include "lib/utils/buffer_helper.h" -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/buffer_helper.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/runtime.h" #include "py/smallint.h" #include "supervisor/shared/translate.h" @@ -67,7 +67,7 @@ //| """ //| ... //| -STATIC mp_obj_t adafruit_bus_device_i2cdevice_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t adafruit_bus_device_i2cdevice_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { adafruit_bus_device_i2cdevice_obj_t *self = m_new_obj(adafruit_bus_device_i2cdevice_obj_t); self->base.type = &adafruit_bus_device_i2cdevice_type; enum { ARG_i2c, ARG_device_address, ARG_probe }; @@ -77,7 +77,7 @@ STATIC mp_obj_t adafruit_bus_device_i2cdevice_make_new(const mp_obj_type_t *type { MP_QSTR_probe, MP_ARG_BOOL, {.u_bool = true} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_obj_t *i2c = args[ARG_i2c].u_obj; diff --git a/shared-bindings/adafruit_bus_device/SPIDevice.c b/shared-bindings/adafruit_bus_device/SPIDevice.c index 3fc308f583..aee8882940 100644 --- a/shared-bindings/adafruit_bus_device/SPIDevice.c +++ b/shared-bindings/adafruit_bus_device/SPIDevice.c @@ -32,8 +32,8 @@ #include "shared-bindings/digitalio/DigitalInOut.h" -#include "lib/utils/buffer_helper.h" -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/buffer_helper.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/runtime.h" #include "supervisor/shared/translate.h" @@ -71,7 +71,7 @@ //| spi.write(bytes_read)""" //| ... //| -STATIC mp_obj_t adafruit_bus_device_spidevice_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t adafruit_bus_device_spidevice_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { adafruit_bus_device_spidevice_obj_t *self = m_new_obj(adafruit_bus_device_spidevice_obj_t); self->base.type = &adafruit_bus_device_spidevice_type; enum { ARG_spi, ARG_chip_select, ARG_cs_active_value, ARG_baudrate, ARG_polarity, ARG_phase, ARG_extra_clocks }; @@ -85,7 +85,7 @@ STATIC mp_obj_t adafruit_bus_device_spidevice_make_new(const mp_obj_type_t *type { MP_QSTR_extra_clocks, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); busio_spi_obj_t *spi = args[ARG_spi].u_obj; diff --git a/shared-bindings/adafruit_pixelbuf/PixelBuf.c b/shared-bindings/adafruit_pixelbuf/PixelBuf.c index 930f758b30..db9f1c01a8 100644 --- a/shared-bindings/adafruit_pixelbuf/PixelBuf.c +++ b/shared-bindings/adafruit_pixelbuf/PixelBuf.c @@ -68,8 +68,7 @@ static void parse_byteorder(mp_obj_t byteorder_obj, pixelbuf_byteorder_details_t //| :param ~_typing.ReadableBuffer trailer: Sequence of bytes to always send after pixel values.""" //| ... //| -STATIC mp_obj_t pixelbuf_pixelbuf_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, MP_OBJ_FUN_ARGS_MAX, true); +STATIC mp_obj_t pixelbuf_pixelbuf_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_size, ARG_byteorder, ARG_brightness, ARG_auto_write, ARG_header, ARG_trailer }; static const mp_arg_t allowed_args[] = { { MP_QSTR_size, MP_ARG_REQUIRED | MP_ARG_INT }, @@ -80,7 +79,7 @@ STATIC mp_obj_t pixelbuf_pixelbuf_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_trailer, MP_ARG_KW_ONLY | MP_ARG_OBJ, { .u_obj = mp_const_none } }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); pixelbuf_byteorder_details_t byteorder_details; parse_byteorder(args[ARG_byteorder].u_obj, &byteorder_details); diff --git a/shared-bindings/aesio/aes.c b/shared-bindings/aesio/aes.c index f39e99d943..152785c584 100644 --- a/shared-bindings/aesio/aes.c +++ b/shared-bindings/aesio/aes.c @@ -37,8 +37,7 @@ //| STATIC mp_obj_t aesio_aes_make_new(const mp_obj_type_t *type, size_t n_args, - const mp_obj_t *pos_args, - mp_map_t *kw_args) { + size_t n_kw, const mp_obj_t *all_args) { (void)type; enum { ARG_key, ARG_mode, ARG_IV, ARG_counter, ARG_segment_size }; static const mp_arg_t allowed_args[] = { @@ -50,7 +49,7 @@ STATIC mp_obj_t aesio_aes_make_new(const mp_obj_type_t *type, size_t n_args, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); aesio_aes_obj_t *self = m_new_obj(aesio_aes_obj_t); diff --git a/shared-bindings/alarm/__init__.c b/shared-bindings/alarm/__init__.c index 2f5e36148b..5d3c1a15f0 100644 --- a/shared-bindings/alarm/__init__.c +++ b/shared-bindings/alarm/__init__.c @@ -151,7 +151,7 @@ STATIC mp_obj_t alarm_exit_and_deep_sleep_until_alarms(size_t n_args, const mp_o common_hal_alarm_set_deep_sleep_alarms(n_args, args); // Raise an exception, which will be processed in main.c. - mp_raise_arg1(&mp_type_DeepSleepRequest, NULL); + mp_raise_type_arg(&mp_type_DeepSleepRequest, NULL); // Doesn't get here. return mp_const_none; diff --git a/shared-bindings/alarm/pin/PinAlarm.c b/shared-bindings/alarm/pin/PinAlarm.c index 3fe7a2bd59..50bdfa00de 100644 --- a/shared-bindings/alarm/pin/PinAlarm.c +++ b/shared-bindings/alarm/pin/PinAlarm.c @@ -60,7 +60,7 @@ //| """ //| ... //| -STATIC mp_obj_t alarm_pin_pinalarm_make_new(const mp_obj_type_t *type, mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t alarm_pin_pinalarm_make_new(const mp_obj_type_t *type, mp_uint_t n_args, size_t n_kw, const mp_obj_t *all_args) { alarm_pin_pinalarm_obj_t *self = m_new_obj(alarm_pin_pinalarm_obj_t); self->base.type = &alarm_pin_pinalarm_type; enum { ARG_pin, ARG_value, ARG_edge, ARG_pull }; @@ -71,7 +71,7 @@ STATIC mp_obj_t alarm_pin_pinalarm_make_new(const mp_obj_type_t *type, mp_uint_t { MP_QSTR_pull, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(0, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[ARG_pin].u_obj); diff --git a/shared-bindings/alarm/time/TimeAlarm.c b/shared-bindings/alarm/time/TimeAlarm.c index be2d8d0409..2fdd6218bb 100644 --- a/shared-bindings/alarm/time/TimeAlarm.c +++ b/shared-bindings/alarm/time/TimeAlarm.c @@ -57,7 +57,7 @@ mp_obj_t MP_WEAK rtc_get_time_source_time(void) { //| ... //| STATIC mp_obj_t alarm_time_timealarm_make_new(const mp_obj_type_t *type, - mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + size_t n_args, size_t n_kw, const mp_obj_t *all_args) { alarm_time_timealarm_obj_t *self = m_new_obj(alarm_time_timealarm_obj_t); self->base.type = &alarm_time_timealarm_type; @@ -68,7 +68,7 @@ STATIC mp_obj_t alarm_time_timealarm_make_new(const mp_obj_type_t *type, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); bool have_monotonic = args[ARG_monotonic_time].u_obj != mp_const_none; bool have_epoch = args[ARG_epoch_time].u_obj != mp_const_none; diff --git a/shared-bindings/alarm/touch/TouchAlarm.c b/shared-bindings/alarm/touch/TouchAlarm.c index 827c175089..60b3f97c18 100644 --- a/shared-bindings/alarm/touch/TouchAlarm.c +++ b/shared-bindings/alarm/touch/TouchAlarm.c @@ -43,7 +43,7 @@ //| ... //| STATIC mp_obj_t alarm_touch_touchalarm_make_new(const mp_obj_type_t *type, - mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + size_t n_args, size_t n_kw, const mp_obj_t *all_args) { alarm_touch_touchalarm_obj_t *self = m_new_obj(alarm_touch_touchalarm_obj_t); self->base.type = &alarm_touch_touchalarm_type; @@ -53,7 +53,7 @@ STATIC mp_obj_t alarm_touch_touchalarm_make_new(const mp_obj_type_t *type, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[ARG_pin].u_obj); diff --git a/shared-bindings/analogio/AnalogIn.c b/shared-bindings/analogio/AnalogIn.c index 6a92447d60..e1f9f195c8 100644 --- a/shared-bindings/analogio/AnalogIn.c +++ b/shared-bindings/analogio/AnalogIn.c @@ -26,7 +26,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/mphal.h" #include "py/nlr.h" @@ -56,9 +56,9 @@ //| ... //| STATIC mp_obj_t analogio_analogin_make_new(const mp_obj_type_t *type, - mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { + mp_uint_t n_args, size_t n_kw, const mp_obj_t *args) { // check number of arguments - mp_arg_check_num(n_args, kw_args, 1, 1, false); + mp_arg_check_num(n_args, n_kw, 1, 1, false); // 1st argument is the pin const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0]); diff --git a/shared-bindings/analogio/AnalogOut.c b/shared-bindings/analogio/AnalogOut.c index 5af04d3ee6..aad298ba07 100644 --- a/shared-bindings/analogio/AnalogOut.c +++ b/shared-bindings/analogio/AnalogOut.c @@ -27,7 +27,7 @@ #include #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -53,9 +53,9 @@ //| :param ~microcontroller.Pin pin: the pin to output to""" //| ... //| -STATIC mp_obj_t analogio_analogout_make_new(const mp_obj_type_t *type, mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t analogio_analogout_make_new(const mp_obj_type_t *type, mp_uint_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments - mp_arg_check_num(n_args, kw_args, 1, 1, false); + mp_arg_check_num(n_args, n_kw, 1, 1, false); const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0]); diff --git a/shared-bindings/audiobusio/I2SOut.c b/shared-bindings/audiobusio/I2SOut.c index bad178cfd2..c343df242c 100644 --- a/shared-bindings/audiobusio/I2SOut.c +++ b/shared-bindings/audiobusio/I2SOut.c @@ -26,7 +26,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -90,7 +90,7 @@ //| print("stopped")""" //| ... //| -STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { #if !CIRCUITPY_AUDIOBUSIO_I2SOUT mp_raise_NotImplementedError(translate("I2SOut not available")); return NULL; // Not reachable. @@ -103,7 +103,7 @@ STATIC mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_left_justified, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *bit_clock = validate_obj_is_free_pin(args[ARG_bit_clock].u_obj); const mcu_pin_obj_t *word_select = validate_obj_is_free_pin(args[ARG_word_select].u_obj); diff --git a/shared-bindings/audiobusio/PDMIn.c b/shared-bindings/audiobusio/PDMIn.c index f18ed4dd70..201b6abcec 100644 --- a/shared-bindings/audiobusio/PDMIn.c +++ b/shared-bindings/audiobusio/PDMIn.c @@ -26,7 +26,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/mphal.h" #include "py/objproperty.h" @@ -83,7 +83,7 @@ //| mic.record(b, len(b))""" //| ... //| -STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { #if !CIRCUITPY_AUDIOBUSIO_PDMIN mp_raise_NotImplementedError(translate("PDMIn not available")); #else @@ -101,7 +101,7 @@ STATIC mp_obj_t audiobusio_pdmin_make_new(const mp_obj_type_t *type, size_t n_ar static const float STARTUP_DELAY_DEFAULT = 0.110F; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *clock_pin = validate_obj_is_free_pin(args[ARG_clock_pin].u_obj); const mcu_pin_obj_t *data_pin = validate_obj_is_free_pin(args[ARG_data_pin].u_obj); diff --git a/shared-bindings/audiocore/RawSample.c b/shared-bindings/audiocore/RawSample.c index cc1904ea30..c3af2f30f0 100644 --- a/shared-bindings/audiocore/RawSample.c +++ b/shared-bindings/audiocore/RawSample.c @@ -26,7 +26,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -69,7 +69,7 @@ //| dac.stop()""" //| ... //| -STATIC mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_buffer, ARG_channel_count, ARG_sample_rate }; static const mp_arg_t allowed_args[] = { { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED }, @@ -77,7 +77,7 @@ STATIC mp_obj_t audioio_rawsample_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); audioio_rawsample_obj_t *self = m_new_obj(audioio_rawsample_obj_t); self->base.type = &audioio_rawsample_type; diff --git a/shared-bindings/audiocore/WaveFile.c b/shared-bindings/audiocore/WaveFile.c index c46976229e..74ea9fda9f 100644 --- a/shared-bindings/audiocore/WaveFile.c +++ b/shared-bindings/audiocore/WaveFile.c @@ -26,7 +26,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/objproperty.h" #include "py/runtime.h" #include "shared-bindings/audiocore/WaveFile.h" @@ -72,8 +72,8 @@ //| print("stopped")""" //| ... //| -STATIC mp_obj_t audioio_wavefile_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, 2, false); +STATIC mp_obj_t audioio_wavefile_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 1, 2, false); audioio_wavefile_obj_t *self = m_new_obj(audioio_wavefile_obj_t); self->base.type = &audioio_wavefile_type; diff --git a/shared-bindings/audioio/AudioOut.c b/shared-bindings/audioio/AudioOut.c index 1dcfaaf618..80072e9128 100644 --- a/shared-bindings/audioio/AudioOut.c +++ b/shared-bindings/audioio/AudioOut.c @@ -26,7 +26,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -90,7 +90,7 @@ //| print("stopped")""" //| ... //| -STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_left_channel, ARG_right_channel, ARG_quiescent_value }; static const mp_arg_t allowed_args[] = { { MP_QSTR_left_channel, MP_ARG_OBJ | MP_ARG_REQUIRED }, @@ -98,7 +98,7 @@ STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar { MP_QSTR_quiescent_value, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x8000} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *left_channel_pin = validate_obj_is_free_pin(args[ARG_left_channel].u_obj); const mcu_pin_obj_t *right_channel_pin = validate_obj_is_free_pin_or_none(args[ARG_right_channel].u_obj); diff --git a/shared-bindings/audiomixer/Mixer.c b/shared-bindings/audiomixer/Mixer.c index f603671620..619e2c095c 100644 --- a/shared-bindings/audiomixer/Mixer.c +++ b/shared-bindings/audiomixer/Mixer.c @@ -29,7 +29,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -78,7 +78,7 @@ //| print("stopped")""" //| ... //| -STATIC mp_obj_t audiomixer_mixer_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t audiomixer_mixer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_voice_count, ARG_buffer_size, ARG_channel_count, ARG_bits_per_sample, ARG_samples_signed, ARG_sample_rate }; static const mp_arg_t allowed_args[] = { { MP_QSTR_voice_count, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 2} }, @@ -89,7 +89,7 @@ STATIC mp_obj_t audiomixer_mixer_make_new(const mp_obj_type_t *type, size_t n_ar { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 8000} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_int_t voice_count = args[ARG_voice_count].u_int; if (voice_count < 1 || voice_count > 255) { diff --git a/shared-bindings/audiomixer/MixerVoice.c b/shared-bindings/audiomixer/MixerVoice.c index 10548f51ef..d3bac8c3de 100644 --- a/shared-bindings/audiomixer/MixerVoice.c +++ b/shared-bindings/audiomixer/MixerVoice.c @@ -28,7 +28,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -47,7 +47,8 @@ //| ... //| // TODO: support mono or stereo voices -STATIC mp_obj_t audiomixer_mixervoice_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t audiomixer_mixervoice_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + mp_arg_check_num(n_args, n_kw, 0, 0, false); audiomixer_mixervoice_obj_t *self = m_new_obj(audiomixer_mixervoice_obj_t); self->base.type = &audiomixer_mixervoice_type; diff --git a/shared-bindings/audiomp3/MP3Decoder.c b/shared-bindings/audiomp3/MP3Decoder.c index 1b89b87a5c..589751821d 100644 --- a/shared-bindings/audiomp3/MP3Decoder.c +++ b/shared-bindings/audiomp3/MP3Decoder.c @@ -27,7 +27,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/objproperty.h" #include "py/runtime.h" #include "shared-bindings/audiomp3/MP3Decoder.h" @@ -67,8 +67,8 @@ //| print("stopped")""" //| ... //| -STATIC mp_obj_t audiomp3_mp3file_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, 2, false); +STATIC mp_obj_t audiomp3_mp3file_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 1, 2, false); audiomp3_mp3file_obj_t *self = m_new_obj(audiomp3_mp3file_obj_t); self->base.type = &audiomp3_mp3file_type; diff --git a/shared-bindings/audiopwmio/PWMAudioOut.c b/shared-bindings/audiopwmio/PWMAudioOut.c index adb29f8f78..cded4a634f 100644 --- a/shared-bindings/audiopwmio/PWMAudioOut.c +++ b/shared-bindings/audiopwmio/PWMAudioOut.c @@ -26,7 +26,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -93,7 +93,7 @@ //| print("stopped")""" //| ... //| -STATIC mp_obj_t audiopwmio_pwmaudioout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t audiopwmio_pwmaudioout_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_left_channel, ARG_right_channel, ARG_quiescent_value }; static const mp_arg_t allowed_args[] = { { MP_QSTR_left_channel, MP_ARG_OBJ | MP_ARG_REQUIRED }, @@ -101,7 +101,7 @@ STATIC mp_obj_t audiopwmio_pwmaudioout_make_new(const mp_obj_type_t *type, size_ { MP_QSTR_quiescent_value, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0x8000} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *left_channel_pin = validate_obj_is_free_pin(args[ARG_left_channel].u_obj); const mcu_pin_obj_t *right_channel_pin = validate_obj_is_free_pin_or_none(args[ARG_right_channel].u_obj); diff --git a/shared-bindings/bitbangio/I2C.c b/shared-bindings/bitbangio/I2C.c index 3599cad48f..b47ace149f 100644 --- a/shared-bindings/bitbangio/I2C.c +++ b/shared-bindings/bitbangio/I2C.c @@ -31,8 +31,8 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/util.h" -#include "lib/utils/buffer_helper.h" -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/buffer_helper.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/mperrno.h" #include "py/runtime.h" #include "supervisor/shared/translate.h" @@ -59,7 +59,7 @@ //| :param int timeout: The maximum clock stretching timeout in microseconds""" //| ... //| -STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_scl, ARG_sda, ARG_frequency, ARG_timeout }; static const mp_arg_t allowed_args[] = { { MP_QSTR_scl, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -68,7 +68,7 @@ STATIC mp_obj_t bitbangio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 255} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *scl = validate_obj_is_free_pin(args[ARG_scl].u_obj); const mcu_pin_obj_t *sda = validate_obj_is_free_pin(args[ARG_sda].u_obj); diff --git a/shared-bindings/bitbangio/SPI.c b/shared-bindings/bitbangio/SPI.c index 0f453b3807..1f8f3ac136 100644 --- a/shared-bindings/bitbangio/SPI.c +++ b/shared-bindings/bitbangio/SPI.c @@ -33,8 +33,8 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/util.h" -#include "lib/utils/buffer_helper.h" -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/buffer_helper.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/mperrno.h" #include "py/runtime.h" #include "supervisor/shared/translate.h" @@ -70,7 +70,7 @@ //| // TODO(tannewt): Support LSB SPI. -STATIC mp_obj_t bitbangio_spi_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t bitbangio_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_clock, ARG_MOSI, ARG_MISO, ARG_baudrate, ARG_polarity, ARG_phase, ARG_bits, ARG_firstbit }; static const mp_arg_t allowed_args[] = { { MP_QSTR_clock, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -78,7 +78,7 @@ STATIC mp_obj_t bitbangio_spi_make_new(const mp_obj_type_t *type, size_t n_args, { MP_QSTR_MISO, MP_ARG_OBJ, {.u_obj = mp_const_none} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *clock = validate_obj_is_free_pin(args[ARG_clock].u_obj); const mcu_pin_obj_t *mosi = validate_obj_is_free_pin_or_none(args[ARG_MOSI].u_obj); diff --git a/shared-bindings/busio/I2C.c b/shared-bindings/busio/I2C.c index 740bd7cca4..d8951cb565 100644 --- a/shared-bindings/busio/I2C.c +++ b/shared-bindings/busio/I2C.c @@ -31,8 +31,8 @@ #include "shared-bindings/busio/I2C.h" #include "shared-bindings/util.h" -#include "lib/utils/buffer_helper.h" -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/buffer_helper.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/runtime.h" #include "supervisor/shared/translate.h" @@ -64,7 +64,7 @@ //| one for the onboard accelerometer, and one for offboard use.""" //| ... //| -STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { busio_i2c_obj_t *self = m_new_obj(busio_i2c_obj_t); self->base.type = &busio_i2c_type; enum { ARG_scl, ARG_sda, ARG_frequency, ARG_timeout }; @@ -75,7 +75,7 @@ STATIC mp_obj_t busio_i2c_make_new(const mp_obj_type_t *type, size_t n_args, con { MP_QSTR_timeout, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 255} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *scl = validate_obj_is_free_pin(args[ARG_scl].u_obj); const mcu_pin_obj_t *sda = validate_obj_is_free_pin(args[ARG_sda].u_obj); diff --git a/shared-bindings/busio/SPI.c b/shared-bindings/busio/SPI.c index ceebce974b..b2cf90f2cc 100644 --- a/shared-bindings/busio/SPI.c +++ b/shared-bindings/busio/SPI.c @@ -33,8 +33,8 @@ #include "shared-bindings/busio/SPI.h" #include "shared-bindings/util.h" -#include "lib/utils/buffer_helper.h" -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/buffer_helper.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/mperrno.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -80,7 +80,7 @@ // TODO(tannewt): Support LSB SPI. -STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { #if CIRCUITPY_BUSIO_SPI busio_spi_obj_t *self = m_new_obj(busio_spi_obj_t); self->base.type = &busio_spi_type; @@ -91,7 +91,7 @@ STATIC mp_obj_t busio_spi_make_new(const mp_obj_type_t *type, size_t n_args, con { MP_QSTR_MISO, MP_ARG_OBJ, {.u_obj = mp_const_none} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *clock = validate_obj_is_free_pin(args[ARG_clock].u_obj); const mcu_pin_obj_t *mosi = validate_obj_is_free_pin_or_none(args[ARG_MOSI].u_obj); diff --git a/shared-bindings/busio/UART.c b/shared-bindings/busio/UART.c index efb0643d0b..a46ab6826e 100644 --- a/shared-bindings/busio/UART.c +++ b/shared-bindings/busio/UART.c @@ -30,8 +30,8 @@ #include "shared-bindings/microcontroller/Pin.h" #include "shared-bindings/util.h" -#include "lib/utils/context_manager_helpers.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/context_manager_helpers.h" +#include "shared/runtime/interrupt_char.h" #include "py/ioctl.h" #include "py/objproperty.h" @@ -80,7 +80,7 @@ STATIC void validate_timeout(mp_float_t timeout) { } #endif // CIRCUITPY_BUSIO_UART -STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { #if CIRCUITPY_BUSIO_UART // Always initially allocate the UART object within the long-lived heap. // This is needed to avoid crashes with certain UART implementations which @@ -105,7 +105,7 @@ STATIC mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, co { MP_QSTR_rs485_invert, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false } }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *rx = validate_obj_is_free_pin_or_none(args[ARG_rx].u_obj); const mcu_pin_obj_t *tx = validate_obj_is_free_pin_or_none(args[ARG_tx].u_obj); diff --git a/shared-bindings/camera/Camera.c b/shared-bindings/camera/Camera.c index 2e84f702cf..b7187ecbbf 100644 --- a/shared-bindings/camera/Camera.c +++ b/shared-bindings/camera/Camera.c @@ -61,7 +61,7 @@ //| """Initialize camera.""" //| ... //| -STATIC mp_obj_t camera_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t camera_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *all_args, mp_map_t *kw_args) { camera_obj_t *self = m_new_obj(camera_obj_t); self->base.type = &camera_type; // No arguments diff --git a/shared-bindings/canio/CAN.c b/shared-bindings/canio/CAN.c index a6f78b2b50..1efd3a0930 100644 --- a/shared-bindings/canio/CAN.c +++ b/shared-bindings/canio/CAN.c @@ -63,7 +63,7 @@ //| """ //| ... //| -STATIC mp_obj_t canio_can_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t canio_can_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_tx, ARG_rx, ARG_baudrate, ARG_loopback, ARG_silent, ARG_auto_restart, NUM_ARGS }; static const mp_arg_t allowed_args[] = { { MP_QSTR_tx, MP_ARG_OBJ | MP_ARG_REQUIRED }, @@ -76,7 +76,7 @@ STATIC mp_obj_t canio_can_make_new(const mp_obj_type_t *type, size_t n_args, con mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; MP_STATIC_ASSERT(MP_ARRAY_SIZE(allowed_args) == NUM_ARGS); - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mcu_pin_obj_t *rx_pin = validate_obj_is_free_pin_or_none(args[ARG_rx].u_obj); mcu_pin_obj_t *tx_pin = validate_obj_is_free_pin_or_none(args[ARG_tx].u_obj); diff --git a/shared-bindings/canio/Match.c b/shared-bindings/canio/Match.c index 7e9e137127..e8379d3eda 100644 --- a/shared-bindings/canio/Match.c +++ b/shared-bindings/canio/Match.c @@ -42,7 +42,7 @@ //| only standard ids are matched.""" //| -STATIC mp_obj_t canio_match_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t canio_match_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_id, ARG_mask, ARG_extended, NUM_ARGS }; static const mp_arg_t allowed_args[] = { { MP_QSTR_id, MP_ARG_INT | MP_ARG_REQUIRED }, @@ -52,7 +52,7 @@ STATIC mp_obj_t canio_match_make_new(const mp_obj_type_t *type, size_t n_args, c mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; MP_STATIC_ASSERT(MP_ARRAY_SIZE(allowed_args) == NUM_ARGS); - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); int id_bits = args[ARG_extended].u_bool ? 0x1fffffff : 0x7ff; int id = args[ARG_id].u_int; diff --git a/shared-bindings/canio/Message.c b/shared-bindings/canio/Message.c index e773b8d3a4..8ed1352dcc 100644 --- a/shared-bindings/canio/Message.c +++ b/shared-bindings/canio/Message.c @@ -42,7 +42,7 @@ //| """ //| ... //| -STATIC mp_obj_t canio_message_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t canio_message_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_id, ARG_data, ARG_extended, NUM_ARGS }; static const mp_arg_t allowed_args[] = { { MP_QSTR_id, MP_ARG_INT | MP_ARG_REQUIRED }, @@ -52,7 +52,7 @@ STATIC mp_obj_t canio_message_make_new(const mp_obj_type_t *type, size_t n_args, mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; MP_STATIC_ASSERT(MP_ARRAY_SIZE(allowed_args) == NUM_ARGS); - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_buffer_info_t data; mp_get_buffer_raise(args[ARG_data].u_obj, &data, MP_BUFFER_READ); diff --git a/shared-bindings/canio/RemoteTransmissionRequest.c b/shared-bindings/canio/RemoteTransmissionRequest.c index 7d12063a0d..3267cf914d 100644 --- a/shared-bindings/canio/RemoteTransmissionRequest.c +++ b/shared-bindings/canio/RemoteTransmissionRequest.c @@ -42,7 +42,7 @@ //| """ //| ... //| -STATIC mp_obj_t canio_remote_transmission_request_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t canio_remote_transmission_request_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_id, ARG_length, ARG_extended, NUM_ARGS }; static const mp_arg_t allowed_args[] = { { MP_QSTR_id, MP_ARG_INT | MP_ARG_REQUIRED }, @@ -52,7 +52,7 @@ STATIC mp_obj_t canio_remote_transmission_request_make_new(const mp_obj_type_t * mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; MP_STATIC_ASSERT(MP_ARRAY_SIZE(allowed_args) == NUM_ARGS); - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); int length = args[ARG_length].u_int; if (length < 0 || length > 8) { diff --git a/shared-bindings/countio/Counter.c b/shared-bindings/countio/Counter.c index 8d84cfb70f..873da912a6 100644 --- a/shared-bindings/countio/Counter.c +++ b/shared-bindings/countio/Counter.c @@ -1,7 +1,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/objproperty.h" #include "py/runtime.h" #include "py/runtime0.h" @@ -32,14 +32,14 @@ //| pin_counter.reset() //| print(pin_counter.count)""" //| -STATIC mp_obj_t countio_counter_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t countio_counter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_pin_a }; static const mp_arg_t allowed_args[] = { { MP_QSTR_pin_a, MP_ARG_REQUIRED | MP_ARG_OBJ } }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *pin_a = validate_obj_is_free_pin(args[ARG_pin_a].u_obj); diff --git a/shared-bindings/digitalio/DigitalInOut.c b/shared-bindings/digitalio/DigitalInOut.c index fc9e0362cd..ff5c494ea8 100644 --- a/shared-bindings/digitalio/DigitalInOut.c +++ b/shared-bindings/digitalio/DigitalInOut.c @@ -27,7 +27,7 @@ #include #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/nlr.h" #include "py/objtype.h" @@ -59,8 +59,8 @@ //| ... //| STATIC mp_obj_t digitalio_digitalinout_make_new(const mp_obj_type_t *type, - mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, 1, false); + size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 1, 1, false); digitalio_digitalinout_obj_t *self = m_new_obj(digitalio_digitalinout_obj_t); self->base.type = &digitalio_digitalinout_type; diff --git a/shared-bindings/digitalio/Direction.c b/shared-bindings/digitalio/Direction.c index 0c2448ca9a..e7ebd0cfcc 100644 --- a/shared-bindings/digitalio/Direction.c +++ b/shared-bindings/digitalio/Direction.c @@ -27,7 +27,7 @@ #include #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/nlr.h" #include "py/objtype.h" diff --git a/shared-bindings/displayio/Bitmap.c b/shared-bindings/displayio/Bitmap.c index de2be6d637..5a1e12189a 100644 --- a/shared-bindings/displayio/Bitmap.c +++ b/shared-bindings/displayio/Bitmap.c @@ -29,7 +29,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -63,11 +63,11 @@ //| :param int value_count: The number of possible pixel values.""" //| ... //| -STATIC mp_obj_t displayio_bitmap_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 3, 3, false); - uint32_t width = mp_obj_get_int(pos_args[0]); - uint32_t height = mp_obj_get_int(pos_args[1]); - uint32_t value_count = mp_obj_get_int(pos_args[2]); +STATIC mp_obj_t displayio_bitmap_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + mp_arg_check_num(n_args, n_kw, 3, 3, false); + uint32_t width = mp_obj_get_int(all_args[0]); + uint32_t height = mp_obj_get_int(all_args[1]); + uint32_t value_count = mp_obj_get_int(all_args[2]); uint32_t bits = 1; if (value_count == 0) { diff --git a/shared-bindings/displayio/ColorConverter.c b/shared-bindings/displayio/ColorConverter.c index 7c1e87efeb..c093c70128 100644 --- a/shared-bindings/displayio/ColorConverter.c +++ b/shared-bindings/displayio/ColorConverter.c @@ -28,7 +28,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/enum.h" #include "py/objproperty.h" @@ -48,7 +48,7 @@ //| ... //| -STATIC mp_obj_t displayio_colorconverter_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t displayio_colorconverter_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_dither, ARG_input_colorspace }; static const mp_arg_t allowed_args[] = { @@ -56,7 +56,7 @@ STATIC mp_obj_t displayio_colorconverter_make_new(const mp_obj_type_t *type, siz { MP_QSTR_input_colorspace, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = (void *)&displayio_colorspace_RGB888_obj} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); displayio_colorconverter_t *self = m_new_obj(displayio_colorconverter_t); self->base.type = &displayio_colorconverter_type; diff --git a/shared-bindings/displayio/Display.c b/shared-bindings/displayio/Display.c index 9796c1c4d7..ca98f9339c 100644 --- a/shared-bindings/displayio/Display.c +++ b/shared-bindings/displayio/Display.c @@ -28,7 +28,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/objtype.h" @@ -115,7 +115,7 @@ //| ... //| STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_args, - const mp_obj_t *pos_args, mp_map_t *kw_args) { + size_t n_kw, const mp_obj_t *all_args) { enum { ARG_display_bus, ARG_init_sequence, ARG_width, ARG_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_color_depth, ARG_grayscale, ARG_pixels_in_byte_share_row, ARG_bytes_per_cell, ARG_reverse_pixels_in_byte, ARG_reverse_bytes_in_word, @@ -154,7 +154,7 @@ STATIC mp_obj_t displayio_display_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_SH1107_addressing, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} } }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_obj_t display_bus = args[ARG_display_bus].u_obj; diff --git a/shared-bindings/displayio/EPaperDisplay.c b/shared-bindings/displayio/EPaperDisplay.c index 8d9b68f2b0..06245c90ae 100644 --- a/shared-bindings/displayio/EPaperDisplay.c +++ b/shared-bindings/displayio/EPaperDisplay.c @@ -28,7 +28,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/objtype.h" @@ -103,7 +103,7 @@ //| :param bool grayscale: When true, the color ram is the low bit of 2-bit grayscale""" //| ... //| -STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_display_bus, ARG_start_sequence, ARG_stop_sequence, ARG_width, ARG_height, ARG_ram_width, ARG_ram_height, ARG_colstart, ARG_rowstart, ARG_rotation, ARG_set_column_window_command, ARG_set_row_window_command, ARG_set_current_column_command, @@ -140,7 +140,7 @@ STATIC mp_obj_t displayio_epaperdisplay_make_new(const mp_obj_type_t *type, size { MP_QSTR_grayscale, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_obj_t display_bus = args[ARG_display_bus].u_obj; diff --git a/shared-bindings/displayio/FourWire.c b/shared-bindings/displayio/FourWire.c index d7d058fe07..801b988a8a 100644 --- a/shared-bindings/displayio/FourWire.c +++ b/shared-bindings/displayio/FourWire.c @@ -28,7 +28,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -61,7 +61,7 @@ //| or second (1). Rising or falling depends on clock polarity.""" //| ... //| -STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_spi_bus, ARG_command, ARG_chip_select, ARG_reset, ARG_baudrate, ARG_polarity, ARG_phase }; static const mp_arg_t allowed_args[] = { { MP_QSTR_spi_bus, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -73,7 +73,7 @@ STATIC mp_obj_t displayio_fourwire_make_new(const mp_obj_type_t *type, size_t n_ { MP_QSTR_phase, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 0} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mcu_pin_obj_t *command = validate_obj_is_free_pin(args[ARG_command].u_obj); mcu_pin_obj_t *chip_select = validate_obj_is_free_pin(args[ARG_chip_select].u_obj); diff --git a/shared-bindings/displayio/Group.c b/shared-bindings/displayio/Group.c index b706b627c4..33329e5ece 100644 --- a/shared-bindings/displayio/Group.c +++ b/shared-bindings/displayio/Group.c @@ -28,7 +28,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/objtype.h" @@ -47,7 +47,7 @@ //| :param int y: Initial y position within the parent.""" //| ... //| -STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_scale, ARG_x, ARG_y }; static const mp_arg_t allowed_args[] = { { MP_QSTR_scale, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 1} }, @@ -55,7 +55,7 @@ STATIC mp_obj_t displayio_group_make_new(const mp_obj_type_t *type, size_t n_arg { MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_int_t scale = args[ARG_scale].u_int; if (scale < 1) { diff --git a/shared-bindings/displayio/I2CDisplay.c b/shared-bindings/displayio/I2CDisplay.c index 18773aba0d..d87b5f8bb0 100644 --- a/shared-bindings/displayio/I2CDisplay.c +++ b/shared-bindings/displayio/I2CDisplay.c @@ -29,7 +29,7 @@ #include #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -56,7 +56,7 @@ //| :param microcontroller.Pin reset: Reset pin. When None only software reset can be used""" //| ... //| -STATIC mp_obj_t displayio_i2cdisplay_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t displayio_i2cdisplay_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_i2c_bus, ARG_device_address, ARG_reset }; static const mp_arg_t allowed_args[] = { { MP_QSTR_i2c_bus, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -64,7 +64,7 @@ STATIC mp_obj_t displayio_i2cdisplay_make_new(const mp_obj_type_t *type, size_t { MP_QSTR_reset, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mcu_pin_obj_t *reset = validate_obj_is_free_pin_or_none(args[ARG_reset].u_obj); diff --git a/shared-bindings/displayio/OnDiskBitmap.c b/shared-bindings/displayio/OnDiskBitmap.c index 32249a3ddf..b68fbef992 100644 --- a/shared-bindings/displayio/OnDiskBitmap.c +++ b/shared-bindings/displayio/OnDiskBitmap.c @@ -80,9 +80,9 @@ //| """ //| ... //| -STATIC mp_obj_t displayio_ondiskbitmap_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, 1, false); - mp_obj_t arg = pos_args[0]; +STATIC mp_obj_t displayio_ondiskbitmap_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + mp_arg_check_num(n_args, n_kw, 1, 1, false); + mp_obj_t arg = all_args[0]; if (mp_obj_is_str(arg)) { arg = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), arg, MP_ROM_QSTR(MP_QSTR_rb)); diff --git a/shared-bindings/displayio/Palette.c b/shared-bindings/displayio/Palette.c index 1834341daf..ad6d7c319a 100644 --- a/shared-bindings/displayio/Palette.c +++ b/shared-bindings/displayio/Palette.c @@ -28,7 +28,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -49,13 +49,13 @@ // TODO(tannewt): Add support for other color formats. // TODO(tannewt): Add support for 8-bit alpha blending. //| -STATIC mp_obj_t displayio_palette_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t displayio_palette_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_color_count }; static const mp_arg_t allowed_args[] = { { MP_QSTR_color_count, MP_ARG_REQUIRED | MP_ARG_INT }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); displayio_palette_t *self = m_new_obj(displayio_palette_t); self->base.type = &displayio_palette_type; @@ -122,7 +122,7 @@ STATIC mp_obj_t palette_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t val // Convert a tuple or list to a bytearray. if (mp_obj_is_type(value, &mp_type_tuple) || mp_obj_is_type(value, &mp_type_list)) { - value = mp_type_bytes.make_new(&mp_type_bytes, 1, &value, NULL); + value = mp_type_bytes.make_new(&mp_type_bytes, 1, 0, &value); } uint32_t color; diff --git a/shared-bindings/displayio/Shape.c b/shared-bindings/displayio/Shape.c index 0126df8858..f39e7820a9 100644 --- a/shared-bindings/displayio/Shape.c +++ b/shared-bindings/displayio/Shape.c @@ -47,7 +47,7 @@ //| :param bool mirror_y: When true the top boundary is mirrored to the bottom.""" //| ... //| -STATIC mp_obj_t displayio_shape_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t displayio_shape_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_width, ARG_height, ARG_mirror_x, ARG_mirror_y }; static const mp_arg_t allowed_args[] = { { MP_QSTR_width, MP_ARG_REQUIRED | MP_ARG_INT }, @@ -56,7 +56,7 @@ STATIC mp_obj_t displayio_shape_make_new(const mp_obj_type_t *type, size_t n_arg { MP_QSTR_mirror_y, MP_ARG_BOOL | MP_ARG_KW_ONLY, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_int_t width = args[ARG_width].u_int; if (width < 1) { diff --git a/shared-bindings/displayio/TileGrid.c b/shared-bindings/displayio/TileGrid.c index 1c6e6efda3..f031842e3b 100644 --- a/shared-bindings/displayio/TileGrid.c +++ b/shared-bindings/displayio/TileGrid.c @@ -28,7 +28,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/objtype.h" @@ -65,7 +65,7 @@ //| :param int x: Initial x position of the left edge within the parent. //| :param int y: Initial y position of the top edge within the parent.""" //| -STATIC mp_obj_t displayio_tilegrid_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t displayio_tilegrid_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_bitmap, ARG_pixel_shader, ARG_width, ARG_height, ARG_tile_width, ARG_tile_height, ARG_default_tile, ARG_x, ARG_y }; static const mp_arg_t allowed_args[] = { { MP_QSTR_bitmap, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -79,7 +79,7 @@ STATIC mp_obj_t displayio_tilegrid_make_new(const mp_obj_type_t *type, size_t n_ { MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_obj_t bitmap = args[ARG_bitmap].u_obj; diff --git a/shared-bindings/fontio/BuiltinFont.c b/shared-bindings/fontio/BuiltinFont.c index e8b66c5e5c..171a50dab3 100644 --- a/shared-bindings/fontio/BuiltinFont.c +++ b/shared-bindings/fontio/BuiltinFont.c @@ -28,7 +28,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" diff --git a/shared-bindings/framebufferio/FramebufferDisplay.c b/shared-bindings/framebufferio/FramebufferDisplay.c index 9ffb25ba6e..683e512b3e 100644 --- a/shared-bindings/framebufferio/FramebufferDisplay.c +++ b/shared-bindings/framebufferio/FramebufferDisplay.c @@ -29,7 +29,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/objtype.h" @@ -55,7 +55,7 @@ //| :param int rotation: The rotation of the display in degrees clockwise. Must be in 90 degree increments (0, 90, 180, 270)""" //| ... //| -STATIC mp_obj_t framebufferio_framebufferdisplay_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t framebufferio_framebufferdisplay_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_framebuffer, ARG_rotation, ARG_auto_refresh, NUM_ARGS }; static const mp_arg_t allowed_args[] = { { MP_QSTR_framebuffer, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -64,7 +64,7 @@ STATIC mp_obj_t framebufferio_framebufferdisplay_make_new(const mp_obj_type_t *t }; MP_STATIC_ASSERT(MP_ARRAY_SIZE(allowed_args) == NUM_ARGS); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_obj_t framebuffer = args[ARG_framebuffer].u_obj; diff --git a/shared-bindings/frequencyio/FrequencyIn.c b/shared-bindings/frequencyio/FrequencyIn.c index 43c1738da8..f8ab1b955e 100644 --- a/shared-bindings/frequencyio/FrequencyIn.c +++ b/shared-bindings/frequencyio/FrequencyIn.c @@ -26,7 +26,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/objproperty.h" #include "py/runtime.h" #include "py/runtime0.h" @@ -71,9 +71,8 @@ //| frequency.clear()""" //| ... //| -STATIC mp_obj_t frequencyio_frequencyin_make_new(const mp_obj_type_t *type, size_t n_args, - const mp_obj_t *pos_args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, 1, true); +STATIC mp_obj_t frequencyio_frequencyin_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + mp_arg_check_num(n_args, n_kw, 1, 1, true); frequencyio_frequencyin_obj_t *self = m_new_obj(frequencyio_frequencyin_obj_t); self->base.type = &frequencyio_frequencyin_type; @@ -83,7 +82,7 @@ STATIC mp_obj_t frequencyio_frequencyin_make_new(const mp_obj_type_t *type, size { MP_QSTR_capture_period, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 10} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[ARG_pin].u_obj); diff --git a/shared-bindings/gamepadshift/GamePadShift.c b/shared-bindings/gamepadshift/GamePadShift.c index a232683c96..1c43eeac7b 100644 --- a/shared-bindings/gamepadshift/GamePadShift.c +++ b/shared-bindings/gamepadshift/GamePadShift.c @@ -50,7 +50,7 @@ //| ... //| STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args, - const mp_obj_t *pos_args, mp_map_t *kw_args) { + size_t n_kw, const mp_obj_t *all_args) { enum { ARG_clock, ARG_data, ARG_latch }; static const mp_arg_t allowed_args[] = { @@ -59,7 +59,7 @@ STATIC mp_obj_t gamepadshift_make_new(const mp_obj_type_t *type, size_t n_args, { MP_QSTR_latch, MP_ARG_REQUIRED | MP_ARG_OBJ}, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); digitalio_digitalinout_obj_t *clock_pin = assert_digitalinout(args[ARG_clock].u_obj); diff --git a/shared-bindings/gnss/GNSS.c b/shared-bindings/gnss/GNSS.c index cd4b097bcf..e304f0a0a2 100644 --- a/shared-bindings/gnss/GNSS.c +++ b/shared-bindings/gnss/GNSS.c @@ -37,7 +37,7 @@ //| :param system: satellite system to use""" //| ... //| -STATIC mp_obj_t gnss_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t gnss_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { gnss_obj_t *self = m_new_obj(gnss_obj_t); self->base.type = &gnss_type; enum { ARG_system }; @@ -45,7 +45,7 @@ STATIC mp_obj_t gnss_make_new(const mp_obj_type_t *type, size_t n_args, const mp { MP_QSTR_system, MP_ARG_REQUIRED | MP_ARG_OBJ }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); unsigned long selection = 0; if (mp_obj_is_type(args[ARG_system].u_obj, &gnss_satellitesystem_type)) { diff --git a/shared-bindings/gnss/GNSS.h b/shared-bindings/gnss/GNSS.h index 60069a90a9..dca640b690 100644 --- a/shared-bindings/gnss/GNSS.h +++ b/shared-bindings/gnss/GNSS.h @@ -9,7 +9,7 @@ #include "shared-bindings/gnss/SatelliteSystem.h" #include "shared-bindings/gnss/PositionFix.h" -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" extern const mp_obj_type_t gnss_type; diff --git a/shared-bindings/i2cperipheral/I2CPeripheral.c b/shared-bindings/i2cperipheral/I2CPeripheral.c index ac136d7e18..f697646146 100644 --- a/shared-bindings/i2cperipheral/I2CPeripheral.c +++ b/shared-bindings/i2cperipheral/I2CPeripheral.c @@ -29,9 +29,9 @@ #include "shared-bindings/time/__init__.h" #include "shared-bindings/util.h" -#include "lib/utils/buffer_helper.h" -#include "lib/utils/context_manager_helpers.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/buffer_helper.h" +#include "shared/runtime/context_manager_helpers.h" +#include "shared/runtime/interrupt_char.h" #include "py/mperrno.h" #include "py/mphal.h" @@ -63,7 +63,7 @@ STATIC mp_obj_t mp_obj_new_i2cperipheral_i2c_peripheral_request(i2cperipheral_i2 //| :param bool smbus: Use SMBUS timings if the hardware supports it""" //| ... //| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t i2cperipheral_i2c_peripheral_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { i2cperipheral_i2c_peripheral_obj_t *self = m_new_obj(i2cperipheral_i2c_peripheral_obj_t); self->base.type = &i2cperipheral_i2c_peripheral_type; enum { ARG_scl, ARG_sda, ARG_addresses, ARG_smbus }; @@ -74,7 +74,7 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_make_new(const mp_obj_type_t *type, { MP_QSTR_smbus, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *scl = validate_obj_is_free_pin(args[ARG_scl].u_obj); const mcu_pin_obj_t *sda = validate_obj_is_free_pin(args[ARG_sda].u_obj); @@ -237,8 +237,8 @@ const mp_obj_type_t i2cperipheral_i2c_peripheral_type = { //| :param is_read: True if the main peripheral is requesting data //| :param is_restart: Repeated Start Condition""" //| -STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 4, 4, false); +STATIC mp_obj_t i2cperipheral_i2c_peripheral_request_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 4, 4, false); return mp_obj_new_i2cperipheral_i2c_peripheral_request(args[0], mp_obj_get_int(args[1]), mp_obj_is_true(args[2]), mp_obj_is_true(args[3])); } diff --git a/shared-bindings/imagecapture/ParallelImageCapture.c b/shared-bindings/imagecapture/ParallelImageCapture.c index 59a6f256e6..e999fba850 100644 --- a/shared-bindings/imagecapture/ParallelImageCapture.c +++ b/shared-bindings/imagecapture/ParallelImageCapture.c @@ -27,7 +27,7 @@ #include "py/obj.h" #include "py/runtime.h" -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "shared-bindings/imagecapture/ParallelImageCapture.h" #include "shared-bindings/microcontroller/Pin.h" @@ -53,7 +53,7 @@ //| """ //| ... //| -STATIC mp_obj_t imagecapture_parallelimagecapture_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t imagecapture_parallelimagecapture_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_data_pins, ARG_clock, ARG_vsync, ARG_href, NUM_ARGS }; static const mp_arg_t allowed_args[] = { @@ -64,7 +64,7 @@ STATIC mp_obj_t imagecapture_parallelimagecapture_make_new(const mp_obj_type_t * }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; MP_STATIC_ASSERT(MP_ARRAY_SIZE(allowed_args) == NUM_ARGS); - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); uint8_t pins[32]; uint8_t pin_count; diff --git a/shared-bindings/ipaddress/IPv4Address.c b/shared-bindings/ipaddress/IPv4Address.c index 213df1704a..f62e373937 100644 --- a/shared-bindings/ipaddress/IPv4Address.c +++ b/shared-bindings/ipaddress/IPv4Address.c @@ -45,14 +45,14 @@ //| The value itself can either be bytes or a string formatted address.""" //| ... //| -STATIC mp_obj_t ipaddress_ipv4address_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t ipaddress_ipv4address_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_address }; static const mp_arg_t allowed_args[] = { { MP_QSTR_address, MP_ARG_OBJ | MP_ARG_REQUIRED }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mp_obj_t address = args[ARG_address].u_obj; diff --git a/shared-bindings/keypad/Event.c b/shared-bindings/keypad/Event.c index 9218f76ccd..fda44d3521 100644 --- a/shared-bindings/keypad/Event.c +++ b/shared-bindings/keypad/Event.c @@ -42,7 +42,7 @@ //| """ //| ... //| -STATIC mp_obj_t keypad_event_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t keypad_event_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { keypad_event_obj_t *self = m_new_obj(keypad_event_obj_t); self->base.type = &keypad_event_type; enum { ARG_key_number, ARG_pressed, ARG_timestamp }; @@ -52,7 +52,7 @@ STATIC mp_obj_t keypad_event_make_new(const mp_obj_type_t *type, size_t n_args, { MP_QSTR_timestamp, MP_ARG_OBJ, {.u_obj = mp_const_none} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mp_uint_t key_number = (mp_uint_t)mp_arg_validate_int_min(args[ARG_key_number].u_int, 0, MP_QSTR_key_number); @@ -171,7 +171,7 @@ STATIC mp_obj_t keypad_event_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_ob //| ... //| STATIC mp_obj_t keypad_event_unary_op(mp_unary_op_t op, mp_obj_t self_in) { - keypad_event_obj_t *self = MP_OBJ_TO_PTR(self); + keypad_event_obj_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { case MP_UNARY_OP_HASH: { const mp_int_t key_number = common_hal_keypad_event_get_key_number(self); diff --git a/shared-bindings/keypad/KeyMatrix.c b/shared-bindings/keypad/KeyMatrix.c index dbb4ac6822..61462464c5 100644 --- a/shared-bindings/keypad/KeyMatrix.c +++ b/shared-bindings/keypad/KeyMatrix.c @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -62,7 +62,7 @@ //| """ //| ... -STATIC mp_obj_t keypad_keymatrix_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t keypad_keymatrix_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { keypad_keymatrix_obj_t *self = m_new_obj(keypad_keymatrix_obj_t); self->base.type = &keypad_keymatrix_type; enum { ARG_row_pins, ARG_column_pins, ARG_columns_to_anodes, ARG_interval, ARG_max_events }; @@ -74,7 +74,7 @@ STATIC mp_obj_t keypad_keymatrix_make_new(const mp_obj_type_t *type, size_t n_ar { MP_QSTR_max_events, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 64} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_obj_t row_pins = args[ARG_row_pins].u_obj; // mp_obj_len() will be >= 0. diff --git a/shared-bindings/keypad/Keys.c b/shared-bindings/keypad/Keys.c index dc533a2e2b..47a906a144 100644 --- a/shared-bindings/keypad/Keys.c +++ b/shared-bindings/keypad/Keys.c @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -63,7 +63,7 @@ //| """ //| ... -STATIC mp_obj_t keypad_keys_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t keypad_keys_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { keypad_keys_obj_t *self = m_new_obj(keypad_keys_obj_t); self->base.type = &keypad_keys_type; enum { ARG_pins, ARG_value_when_pressed, ARG_pull, ARG_interval, ARG_max_events }; @@ -75,7 +75,7 @@ STATIC mp_obj_t keypad_keys_make_new(const mp_obj_type_t *type, size_t n_args, c { MP_QSTR_max_events, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 64} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_obj_t pins = args[ARG_pins].u_obj; validate_no_duplicate_pins(pins, MP_QSTR_row_pins); diff --git a/shared-bindings/keypad/ShiftRegisterKeys.c b/shared-bindings/keypad/ShiftRegisterKeys.c index c81e127601..68d7e27673 100644 --- a/shared-bindings/keypad/ShiftRegisterKeys.c +++ b/shared-bindings/keypad/ShiftRegisterKeys.c @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -69,7 +69,7 @@ //| """ //| ... -STATIC mp_obj_t keypad_shiftregisterkeys_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t keypad_shiftregisterkeys_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { keypad_shiftregisterkeys_obj_t *self = m_new_obj(keypad_shiftregisterkeys_obj_t); self->base.type = &keypad_shiftregisterkeys_type; enum { ARG_clock, ARG_data, ARG_latch, ARG_value_to_latch, ARG_key_count, ARG_value_when_pressed, ARG_interval, ARG_max_events }; @@ -84,7 +84,7 @@ STATIC mp_obj_t keypad_shiftregisterkeys_make_new(const mp_obj_type_t *type, siz { MP_QSTR_max_events, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 64} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mcu_pin_obj_t *clock = validate_obj_is_free_pin(args[ARG_clock].u_obj); mcu_pin_obj_t *data = validate_obj_is_free_pin(args[ARG_data].u_obj); diff --git a/shared-bindings/memorymonitor/AllocationAlarm.c b/shared-bindings/memorymonitor/AllocationAlarm.c index f7684b51a7..b54645225a 100644 --- a/shared-bindings/memorymonitor/AllocationAlarm.c +++ b/shared-bindings/memorymonitor/AllocationAlarm.c @@ -56,13 +56,13 @@ //| """ //| ... //| -STATIC mp_obj_t memorymonitor_allocationalarm_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t memorymonitor_allocationalarm_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *all_args, mp_map_t *kw_args) { enum { ARG_minimum_block_count }; static const mp_arg_t allowed_args[] = { { MP_QSTR_minimum_block_count, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_int_t minimum_block_count = args[ARG_minimum_block_count].u_int; if (minimum_block_count < 1) { mp_raise_ValueError_varg(translate("%q must be >= 1"), MP_QSTR_minimum_block_count); diff --git a/shared-bindings/memorymonitor/AllocationSize.c b/shared-bindings/memorymonitor/AllocationSize.c index 642dc49d34..5679b30c3f 100644 --- a/shared-bindings/memorymonitor/AllocationSize.c +++ b/shared-bindings/memorymonitor/AllocationSize.c @@ -63,7 +63,7 @@ //| """ //| ... //| -STATIC mp_obj_t memorymonitor_allocationsize_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t memorymonitor_allocationsize_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *all_args, mp_map_t *kw_args) { memorymonitor_allocationsize_obj_t *self = m_new_obj(memorymonitor_allocationsize_obj_t); self->base.type = &memorymonitor_allocationsize_type; diff --git a/shared-bindings/msgpack/ExtType.c b/shared-bindings/msgpack/ExtType.c index 236b977424..892dd91696 100644 --- a/shared-bindings/msgpack/ExtType.c +++ b/shared-bindings/msgpack/ExtType.c @@ -36,7 +36,7 @@ //| :param int code: type code in range 0~127. //| :param bytes data: representation.""" //| -STATIC mp_obj_t mod_msgpack_exttype_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t mod_msgpack_exttype_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { mod_msgpack_extype_obj_t *self = m_new_obj(mod_msgpack_extype_obj_t); self->base.type = &mod_msgpack_exttype_type; enum { ARG_code, ARG_data }; @@ -45,7 +45,7 @@ STATIC mp_obj_t mod_msgpack_exttype_make_new(const mp_obj_type_t *type, size_t n { MP_QSTR_data, MP_ARG_OBJ | MP_ARG_REQUIRED }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); int code = args[ARG_code].u_int; if (code < 0 || code > 127) { diff --git a/shared-bindings/onewireio/OneWire.c b/shared-bindings/onewireio/OneWire.c index 406b421fd1..a167c86cc8 100644 --- a/shared-bindings/onewireio/OneWire.c +++ b/shared-bindings/onewireio/OneWire.c @@ -26,7 +26,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/objproperty.h" #include "py/runtime.h" #include "py/runtime0.h" @@ -57,13 +57,13 @@ //| print(onewire.read_bit())""" //| ... //| -STATIC mp_obj_t onewireio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t onewireio_onewire_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_pin }; static const mp_arg_t allowed_args[] = { { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[ARG_pin].u_obj); onewireio_onewire_obj_t *self = m_new_obj(onewireio_onewire_obj_t); diff --git a/shared-bindings/paralleldisplay/ParallelBus.c b/shared-bindings/paralleldisplay/ParallelBus.c index 57bf0974bf..782848d9b6 100644 --- a/shared-bindings/paralleldisplay/ParallelBus.c +++ b/shared-bindings/paralleldisplay/ParallelBus.c @@ -28,7 +28,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -61,7 +61,7 @@ //| :param int frequency: The communication frequency in Hz for the display on the bus""" //| ... //| -STATIC mp_obj_t paralleldisplay_parallelbus_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t paralleldisplay_parallelbus_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_data0, ARG_data_pins, ARG_command, ARG_chip_select, ARG_write, ARG_read, ARG_reset, ARG_frequency }; static const mp_arg_t allowed_args[] = { { MP_QSTR_data0, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_obj = mp_const_none } }, @@ -74,7 +74,7 @@ STATIC mp_obj_t paralleldisplay_parallelbus_make_new(const mp_obj_type_t *type, { MP_QSTR_frequency, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 30000000 } }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mcu_pin_obj_t *command = validate_obj_is_free_pin(args[ARG_command].u_obj); mcu_pin_obj_t *chip_select = validate_obj_is_free_pin(args[ARG_chip_select].u_obj); diff --git a/shared-bindings/ps2io/Ps2.c b/shared-bindings/ps2io/Ps2.c index 7f6f910726..a0fb6d607b 100644 --- a/shared-bindings/ps2io/Ps2.c +++ b/shared-bindings/ps2io/Ps2.c @@ -27,7 +27,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/objproperty.h" #include "py/runtime.h" #include "py/runtime0.h" @@ -67,14 +67,14 @@ //| print(kbd.sendcmd(0x01))""" //| ... //| -STATIC mp_obj_t ps2io_ps2_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t ps2io_ps2_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_datapin, ARG_clkpin }; static const mp_arg_t allowed_args[] = { { MP_QSTR_datapin, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_clkpin, MP_ARG_REQUIRED | MP_ARG_OBJ }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *clkpin = validate_obj_is_free_pin(args[ARG_clkpin].u_obj); const mcu_pin_obj_t *datapin = validate_obj_is_free_pin(args[ARG_datapin].u_obj); diff --git a/shared-bindings/pulseio/PulseIn.c b/shared-bindings/pulseio/PulseIn.c index eb7a24927a..13721c8106 100644 --- a/shared-bindings/pulseio/PulseIn.c +++ b/shared-bindings/pulseio/PulseIn.c @@ -26,7 +26,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/objproperty.h" #include "py/runtime.h" #include "py/runtime0.h" @@ -76,7 +76,7 @@ //| pulses.resume(80)""" //| ... //| -STATIC mp_obj_t pulseio_pulsein_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t pulseio_pulsein_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_pin, ARG_maxlen, ARG_idle_state }; static const mp_arg_t allowed_args[] = { { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -84,7 +84,7 @@ STATIC mp_obj_t pulseio_pulsein_make_new(const mp_obj_type_t *type, size_t n_arg { MP_QSTR_idle_state, MP_ARG_BOOL, {.u_bool = false} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[ARG_pin].u_obj); pulseio_pulsein_obj_t *self = m_new_obj(pulseio_pulsein_obj_t); diff --git a/shared-bindings/pulseio/PulseOut.c b/shared-bindings/pulseio/PulseOut.c index 88d7eb40e0..90564fce89 100644 --- a/shared-bindings/pulseio/PulseOut.c +++ b/shared-bindings/pulseio/PulseOut.c @@ -26,7 +26,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -69,7 +69,7 @@ //| pulse.send(pulses)""" //| ... //| -STATIC mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_pin, ARG_frequency, ARG_duty_cycle}; static const mp_arg_t allowed_args[] = { { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ }, @@ -77,7 +77,7 @@ STATIC mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_ar { MP_QSTR_duty_cycle, MP_ARG_KW_ONLY | MP_ARG_INT, {.u_int = 1 << 15} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *pin = args[ARG_pin].u_obj; mp_int_t frequency = args[ARG_frequency].u_int; diff --git a/shared-bindings/pwmio/PWMOut.c b/shared-bindings/pwmio/PWMOut.c index e34b27ad4a..e59605200a 100644 --- a/shared-bindings/pwmio/PWMOut.c +++ b/shared-bindings/pwmio/PWMOut.c @@ -26,7 +26,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -114,7 +114,7 @@ void common_hal_pwmio_pwmout_raise_error(pwmout_result_t result) { //| time.sleep(0.1)""" //| ... //| -STATIC mp_obj_t pwmio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t pwmio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { enum { ARG_pin, ARG_duty_cycle, ARG_frequency, ARG_variable_frequency }; static const mp_arg_t allowed_args[] = { { MP_QSTR_pin, MP_ARG_REQUIRED | MP_ARG_OBJ, }, @@ -123,7 +123,7 @@ STATIC mp_obj_t pwmio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args, { MP_QSTR_variable_frequency, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} }, }; mp_arg_val_t parsed_args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, parsed_args); + mp_arg_parse_all_kw_array(n_args, n_kw, args, MP_ARRAY_SIZE(allowed_args), allowed_args, parsed_args); const mcu_pin_obj_t *pin = validate_obj_is_free_pin(parsed_args[ARG_pin].u_obj); diff --git a/shared-bindings/qrio/QRDecoder.c b/shared-bindings/qrio/QRDecoder.c index 689c1c6884..c8382de42e 100644 --- a/shared-bindings/qrio/QRDecoder.c +++ b/shared-bindings/qrio/QRDecoder.c @@ -42,14 +42,14 @@ //| """ //| ... -STATIC mp_obj_t qrio_qrdecoder_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t qrio_qrdecoder_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args_in) { enum { ARG_width, ARG_height }; static const mp_arg_t allowed_args[] = { { MP_QSTR_width, MP_ARG_INT | MP_ARG_REQUIRED, {.u_int = 0} }, { MP_QSTR_height, MP_ARG_INT | MP_ARG_REQUIRED, {.u_int = 0} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, args_in, MP_ARRAY_SIZE(allowed_args), allowed_args, args); qrio_qrdecoder_obj_t *self = m_new_obj(qrio_qrdecoder_obj_t); self->base.type = &qrio_qrdecoder_type_obj; diff --git a/shared-bindings/rgbmatrix/RGBMatrix.c b/shared-bindings/rgbmatrix/RGBMatrix.c index 0db1a5ebbc..12fd1e15cc 100644 --- a/shared-bindings/rgbmatrix/RGBMatrix.c +++ b/shared-bindings/rgbmatrix/RGBMatrix.c @@ -170,7 +170,7 @@ STATIC void preflight_pins_or_throw(uint8_t clock_pin, uint8_t *rgb_pins, uint8_ //| `framebufferio.FramebufferDisplay`.""" //| -STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_width, ARG_bit_depth, ARG_rgb_list, ARG_addr_list, ARG_clock_pin, ARG_latch_pin, ARG_output_enable_pin, ARG_doublebuffer, ARG_framebuffer, ARG_height, ARG_tile, ARG_serpentine }; static const mp_arg_t allowed_args[] = { @@ -188,7 +188,7 @@ STATIC mp_obj_t rgbmatrix_rgbmatrix_make_new(const mp_obj_type_t *type, size_t n { MP_QSTR_serpentine, MP_ARG_BOOL | MP_ARG_KW_ONLY, { .u_bool = true } }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); rgbmatrix_rgbmatrix_obj_t *self = &allocate_display_bus_or_raise()->rgbmatrix; self->base.type = &rgbmatrix_RGBMatrix_type; diff --git a/shared-bindings/rotaryio/IncrementalEncoder.c b/shared-bindings/rotaryio/IncrementalEncoder.c index cf9814df24..ef218ba024 100644 --- a/shared-bindings/rotaryio/IncrementalEncoder.c +++ b/shared-bindings/rotaryio/IncrementalEncoder.c @@ -26,7 +26,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/objproperty.h" #include "py/runtime.h" #include "py/runtime0.h" @@ -37,13 +37,14 @@ //| class IncrementalEncoder: //| """IncrementalEncoder determines the relative rotational position based on two series of pulses.""" //| -//| def __init__(self, pin_a: microcontroller.Pin, pin_b: microcontroller.Pin) -> None: +//| def __init__(self, pin_a: microcontroller.Pin, pin_b: microcontroller.Pin, divisor: int = 4) -> None: //| """Create an IncrementalEncoder object associated with the given pins. It tracks the positional //| state of an incremental rotary encoder (also known as a quadrature encoder.) Position is //| relative to the position when the object is contructed. //| //| :param ~microcontroller.Pin pin_a: First pin to read pulses from. //| :param ~microcontroller.Pin pin_b: Second pin to read pulses from. +//| :param int divisor: The divisor of the quadrature signal. //| //| For example:: //| @@ -60,14 +61,15 @@ //| last_position = position""" //| ... //| -STATIC mp_obj_t rotaryio_incrementalencoder_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { - enum { ARG_pin_a, ARG_pin_b }; +STATIC mp_obj_t rotaryio_incrementalencoder_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { + enum { ARG_pin_a, ARG_pin_b, ARG_divisor }; static const mp_arg_t allowed_args[] = { { MP_QSTR_pin_a, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_pin_b, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_divisor, MP_ARG_INT, { .u_int = 4 } }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *pin_a = validate_obj_is_free_pin(args[ARG_pin_a].u_obj); const mcu_pin_obj_t *pin_b = validate_obj_is_free_pin(args[ARG_pin_b].u_obj); @@ -77,6 +79,7 @@ STATIC mp_obj_t rotaryio_incrementalencoder_make_new(const mp_obj_type_t *type, common_hal_rotaryio_incrementalencoder_construct(self, pin_a, pin_b); + common_hal_rotaryio_incrementalencoder_set_divisor(self, args[ARG_divisor].u_int); return MP_OBJ_FROM_PTR(self); } @@ -116,9 +119,38 @@ STATIC mp_obj_t rotaryio_incrementalencoder_obj___exit__(size_t n_args, const mp STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(rotaryio_incrementalencoder___exit___obj, 4, 4, rotaryio_incrementalencoder_obj___exit__); +//| divisor: int +//| """The divisor of the quadrature signal. Use 1 for encoders without +//| detents, or encoders with 4 detents per cycle. Use 2 for encoders with 2 +//| detents per cycle. Use 4 for encoders with 1 detent per cycle.""" +//| +STATIC mp_obj_t rotaryio_incrementalencoder_obj_get_divisor(mp_obj_t self_in) { + rotaryio_incrementalencoder_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + + return mp_obj_new_int(common_hal_rotaryio_incrementalencoder_get_divisor(self)); +} +MP_DEFINE_CONST_FUN_OBJ_1(rotaryio_incrementalencoder_get_divisor_obj, rotaryio_incrementalencoder_obj_get_divisor); + +STATIC mp_obj_t rotaryio_incrementalencoder_obj_set_divisor(mp_obj_t self_in, mp_obj_t new_divisor) { + rotaryio_incrementalencoder_obj_t *self = MP_OBJ_TO_PTR(self_in); + check_for_deinit(self); + + common_hal_rotaryio_incrementalencoder_set_divisor(self, mp_obj_get_int(new_divisor)); + return mp_const_none; +} +MP_DEFINE_CONST_FUN_OBJ_2(rotaryio_incrementalencoder_set_divisor_obj, rotaryio_incrementalencoder_obj_set_divisor); + +const mp_obj_property_t rotaryio_incrementalencoder_divisor_obj = { + .base.type = &mp_type_property, + .proxy = {(mp_obj_t)&rotaryio_incrementalencoder_get_divisor_obj, + (mp_obj_t)&rotaryio_incrementalencoder_set_divisor_obj, + MP_ROM_NONE}, +}; + //| position: int //| """The current position in terms of pulses. The number of pulses per rotation is defined by the -//| specific hardware.""" +//| specific hardware and by the divisor.""" //| STATIC mp_obj_t rotaryio_incrementalencoder_obj_get_position(mp_obj_t self_in) { rotaryio_incrementalencoder_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -150,6 +182,7 @@ STATIC const mp_rom_map_elem_t rotaryio_incrementalencoder_locals_dict_table[] = { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&default___enter___obj) }, { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&rotaryio_incrementalencoder___exit___obj) }, { MP_ROM_QSTR(MP_QSTR_position), MP_ROM_PTR(&rotaryio_incrementalencoder_position_obj) }, + { MP_ROM_QSTR(MP_QSTR_divisor), MP_ROM_PTR(&rotaryio_incrementalencoder_divisor_obj) }, }; STATIC MP_DEFINE_CONST_DICT(rotaryio_incrementalencoder_locals_dict, rotaryio_incrementalencoder_locals_dict_table); diff --git a/shared-bindings/rotaryio/IncrementalEncoder.h b/shared-bindings/rotaryio/IncrementalEncoder.h index 51bf7bd9f6..45551c3e41 100644 --- a/shared-bindings/rotaryio/IncrementalEncoder.h +++ b/shared-bindings/rotaryio/IncrementalEncoder.h @@ -39,5 +39,8 @@ extern bool common_hal_rotaryio_incrementalencoder_deinited(rotaryio_incremental extern mp_int_t common_hal_rotaryio_incrementalencoder_get_position(rotaryio_incrementalencoder_obj_t *self); extern void common_hal_rotaryio_incrementalencoder_set_position(rotaryio_incrementalencoder_obj_t *self, mp_int_t new_position); +extern mp_int_t common_hal_rotaryio_incrementalencoder_get_divisor(rotaryio_incrementalencoder_obj_t *self); +extern void common_hal_rotaryio_incrementalencoder_set_divisor(rotaryio_incrementalencoder_obj_t *self, + mp_int_t new_divisor); #endif // MICROPY_INCLUDED_SHARED_BINDINGS_ROTARYIO_INCREMENTALENCODER_H diff --git a/shared-bindings/rtc/RTC.c b/shared-bindings/rtc/RTC.c index 9247cbb16c..f52871c7da 100644 --- a/shared-bindings/rtc/RTC.c +++ b/shared-bindings/rtc/RTC.c @@ -30,7 +30,7 @@ #include "py/obj.h" #include "py/objproperty.h" #include "py/runtime.h" -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" #include "shared-bindings/rtc/__init__.h" #include "shared-bindings/rtc/RTC.h" #include "shared-bindings/time/__init__.h" @@ -45,9 +45,9 @@ const rtc_rtc_obj_t rtc_rtc_obj = {{&rtc_rtc_type}}; //| """This class represents the onboard Real Time Clock. It is a singleton and will always return the same instance.""" //| ... //| -STATIC mp_obj_t rtc_rtc_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t rtc_rtc_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // No arguments - mp_arg_check_num(n_args, kw_args, 0, 0, false); + mp_arg_check_num(n_args, n_kw, 0, 0, false); // return constant object return (mp_obj_t)&rtc_rtc_obj; diff --git a/shared-bindings/rtc/RTC.h b/shared-bindings/rtc/RTC.h index 02bf54f501..ede824fa2a 100644 --- a/shared-bindings/rtc/RTC.h +++ b/shared-bindings/rtc/RTC.h @@ -31,7 +31,7 @@ #include #include "py/obj.h" -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" extern void common_hal_rtc_get_time(timeutils_struct_time_t *tm); extern void common_hal_rtc_set_time(timeutils_struct_time_t *tm); diff --git a/shared-bindings/sdcardio/SDCard.c b/shared-bindings/sdcardio/SDCard.c index 612203b56d..393323f2b9 100644 --- a/shared-bindings/sdcardio/SDCard.c +++ b/shared-bindings/sdcardio/SDCard.c @@ -76,7 +76,7 @@ //| storage.mount(vfs, '/sd') //| os.listdir('/sd')""" -STATIC mp_obj_t sdcardio_sdcard_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t sdcardio_sdcard_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_spi, ARG_cs, ARG_baudrate, ARG_sdio, NUM_ARGS }; static const mp_arg_t allowed_args[] = { { MP_QSTR_spi, MP_ARG_OBJ, {.u_obj = mp_const_none } }, @@ -86,7 +86,7 @@ STATIC mp_obj_t sdcardio_sdcard_make_new(const mp_obj_type_t *type, size_t n_arg }; MP_STATIC_ASSERT(MP_ARRAY_SIZE(allowed_args) == NUM_ARGS); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); busio_spi_obj_t *spi = validate_obj_is_spi_bus(args[ARG_spi].u_obj); mcu_pin_obj_t *cs = validate_obj_is_free_pin(args[ARG_cs].u_obj); diff --git a/shared-bindings/sdioio/SDCard.c b/shared-bindings/sdioio/SDCard.c index aab43b54bd..e03d180d7a 100644 --- a/shared-bindings/sdioio/SDCard.c +++ b/shared-bindings/sdioio/SDCard.c @@ -33,8 +33,8 @@ #include "shared-bindings/sdioio/SDCard.h" #include "shared-bindings/util.h" -#include "lib/utils/buffer_helper.h" -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/buffer_helper.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/mperrno.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -78,7 +78,7 @@ //| ... //| -STATIC mp_obj_t sdioio_sdcard_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t sdioio_sdcard_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { sdioio_sdcard_obj_t *self = m_new_obj(sdioio_sdcard_obj_t); self->base.type = &sdioio_SDCard_type; enum { ARG_clock, ARG_command, ARG_data, ARG_frequency, NUM_ARGS }; @@ -91,7 +91,7 @@ STATIC mp_obj_t sdioio_sdcard_make_new(const mp_obj_type_t *type, size_t n_args, MP_STATIC_ASSERT(MP_ARRAY_SIZE(allowed_args) == NUM_ARGS); mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); const mcu_pin_obj_t *clock = validate_obj_is_free_pin(args[ARG_clock].u_obj); const mcu_pin_obj_t *command = validate_obj_is_free_pin(args[ARG_command].u_obj); diff --git a/shared-bindings/sharpdisplay/SharpMemoryFramebuffer.c b/shared-bindings/sharpdisplay/SharpMemoryFramebuffer.c index a9aed31970..8e9050d018 100644 --- a/shared-bindings/sharpdisplay/SharpMemoryFramebuffer.c +++ b/shared-bindings/sharpdisplay/SharpMemoryFramebuffer.c @@ -33,7 +33,7 @@ #include "shared-module/displayio/__init__.h" #include "shared-module/sharpdisplay/SharpMemoryFramebuffer.h" -STATIC mp_obj_t sharpdisplay_framebuffer_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t sharpdisplay_framebuffer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_spi_bus, ARG_chip_select, ARG_width, ARG_height, ARG_baudrate, NUM_ARGS }; static const mp_arg_t allowed_args[] = { { MP_QSTR_spi_bus, MP_ARG_OBJ | MP_ARG_REQUIRED, {.u_obj = MP_OBJ_NULL} }, @@ -45,7 +45,7 @@ STATIC mp_obj_t sharpdisplay_framebuffer_make_new(const mp_obj_type_t *type, siz mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; MP_STATIC_ASSERT(MP_ARRAY_SIZE(allowed_args) == NUM_ARGS); - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mcu_pin_obj_t *chip_select = validate_obj_is_free_pin(args[ARG_chip_select].u_obj); busio_spi_obj_t *spi = validate_obj_is_spi_bus(args[ARG_spi_bus].u_obj); diff --git a/shared-bindings/socketpool/Socket.c b/shared-bindings/socketpool/Socket.c index 4ab4f2de4d..2dd832f490 100644 --- a/shared-bindings/socketpool/Socket.c +++ b/shared-bindings/socketpool/Socket.c @@ -30,13 +30,13 @@ #include #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/objtuple.h" #include "py/objlist.h" #include "py/runtime.h" #include "py/mperrno.h" -#include "lib/netutils/netutils.h" +#include "shared/netutils/netutils.h" //| class Socket: //| """TCP, UDP and RAW socket. Cannot be created directly. Instead, call diff --git a/shared-bindings/socketpool/SocketPool.c b/shared-bindings/socketpool/SocketPool.c index 90f4fb8d75..f2e986150e 100644 --- a/shared-bindings/socketpool/SocketPool.c +++ b/shared-bindings/socketpool/SocketPool.c @@ -44,8 +44,8 @@ //| a pool of sockets provided by the underlying OS.""" //| -STATIC mp_obj_t socketpool_socketpool_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, 1, false); +STATIC mp_obj_t socketpool_socketpool_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 1, 1, false); socketpool_socketpool_obj_t *s = m_new_obj_with_finaliser(socketpool_socketpool_obj_t); s->base.type = &socketpool_socketpool_type; diff --git a/shared-bindings/ssl/SSLContext.c b/shared-bindings/ssl/SSLContext.c index f90365054a..885a156edd 100644 --- a/shared-bindings/ssl/SSLContext.c +++ b/shared-bindings/ssl/SSLContext.c @@ -40,8 +40,8 @@ //| rather than all of them.""" //| -STATIC mp_obj_t ssl_sslcontext_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 0, 1, false); +STATIC mp_obj_t ssl_sslcontext_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 0, 1, false); ssl_sslcontext_obj_t *s = m_new_obj(ssl_sslcontext_obj_t); s->base.type = &ssl_sslcontext_type; diff --git a/shared-bindings/ssl/SSLSocket.c b/shared-bindings/ssl/SSLSocket.c index 341033d09e..9e25d7f25f 100644 --- a/shared-bindings/ssl/SSLSocket.c +++ b/shared-bindings/ssl/SSLSocket.c @@ -29,13 +29,13 @@ #include #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/objtuple.h" #include "py/objlist.h" #include "py/runtime.h" #include "py/mperrno.h" -#include "lib/netutils/netutils.h" +#include "shared/netutils/netutils.h" //| class SSLSocket: //| """Implements TLS security on a subset of `socketpool.Socket` functions. Cannot be created diff --git a/shared-bindings/supervisor/__init__.c b/shared-bindings/supervisor/__init__.c index 28565fd2ea..35ae63c03d 100644 --- a/shared-bindings/supervisor/__init__.c +++ b/shared-bindings/supervisor/__init__.c @@ -30,7 +30,7 @@ #include "py/reload.h" #include "py/objstr.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "supervisor/shared/autoreload.h" #include "supervisor/shared/bluetooth/bluetooth.h" #include "supervisor/shared/status_leds.h" diff --git a/shared-bindings/synthio/MidiTrack.c b/shared-bindings/synthio/MidiTrack.c index 81d53b6b82..6ffefd4713 100644 --- a/shared-bindings/synthio/MidiTrack.c +++ b/shared-bindings/synthio/MidiTrack.c @@ -26,7 +26,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" #include "py/runtime.h" @@ -63,7 +63,7 @@ //| print("stopped")""" //| ... //| -STATIC mp_obj_t synthio_miditrack_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t synthio_miditrack_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_buffer, ARG_tempo, ARG_sample_rate }; static const mp_arg_t allowed_args[] = { { MP_QSTR_buffer, MP_ARG_OBJ | MP_ARG_REQUIRED }, @@ -71,7 +71,7 @@ STATIC mp_obj_t synthio_miditrack_make_new(const mp_obj_type_t *type, size_t n_a { MP_QSTR_sample_rate, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 11025} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[ARG_buffer].u_obj, &bufinfo, MP_BUFFER_READ); diff --git a/shared-bindings/terminalio/Terminal.c b/shared-bindings/terminalio/Terminal.c index 19b75c9459..cdeca59164 100644 --- a/shared-bindings/terminalio/Terminal.c +++ b/shared-bindings/terminalio/Terminal.c @@ -46,14 +46,14 @@ //| ... //| -STATIC mp_obj_t terminalio_terminal_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t terminalio_terminal_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_tilegrid, ARG_font }; static const mp_arg_t allowed_args[] = { { MP_QSTR_tilegrid, MP_ARG_REQUIRED | MP_ARG_OBJ }, { MP_QSTR_font, MP_ARG_REQUIRED | MP_ARG_OBJ }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); displayio_tilegrid_t *tilegrid = mp_arg_validate_type(args[ARG_tilegrid].u_obj, &displayio_tilegrid_type, MP_QSTR_tilegrid); diff --git a/shared-bindings/time/__init__.c b/shared-bindings/time/__init__.c index 3aa9b11b6f..971d381ede 100644 --- a/shared-bindings/time/__init__.c +++ b/shared-bindings/time/__init__.c @@ -31,7 +31,7 @@ #include "py/obj.h" #include "py/objnamedtuple.h" #include "py/runtime.h" -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" #include "shared-bindings/rtc/__init__.h" #include "shared-bindings/time/__init__.h" #include "supervisor/shared/translate.h" @@ -93,15 +93,15 @@ STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { MP_DEFINE_CONST_FUN_OBJ_1(time_sleep_obj, time_sleep); #if MICROPY_PY_COLLECTIONS -mp_obj_t struct_time_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { - mp_arg_check_num(n_args, kw_args, 1, 1, false); +mp_obj_t struct_time_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { + mp_arg_check_num(n_args, n_kw, 1, 1, false); size_t len; mp_obj_t *items; mp_obj_get_array(args[0], &len, &items); if (len != 9) { mp_raise_TypeError(translate("time.struct_time() takes a 9-sequence")); } - return namedtuple_make_new(type, len, items, NULL); + return namedtuple_make_new(type, len, 0, items); } //| class struct_time: @@ -173,7 +173,7 @@ mp_obj_t struct_time_from_tm(timeutils_struct_time_t *tm) { mp_obj_new_int(-1), // tm_isdst is not supported }; - return namedtuple_make_new((const mp_obj_type_t *)&struct_time_type_obj, 9, elems, NULL); + return namedtuple_make_new((const mp_obj_type_t *)&struct_time_type_obj, 9, 0, elems); }; void struct_time_to_tm(mp_obj_t t, timeutils_struct_time_t *tm) { diff --git a/shared-bindings/time/__init__.h b/shared-bindings/time/__init__.h index 4e716e9dfd..dba8229f26 100644 --- a/shared-bindings/time/__init__.h +++ b/shared-bindings/time/__init__.h @@ -30,7 +30,7 @@ #include #include -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" extern mp_obj_t struct_time_from_tm(timeutils_struct_time_t *tm); extern void struct_time_to_tm(mp_obj_t t, timeutils_struct_time_t *tm); diff --git a/shared-bindings/touchio/TouchIn.c b/shared-bindings/touchio/TouchIn.c index 1879e80077..537ae29776 100644 --- a/shared-bindings/touchio/TouchIn.c +++ b/shared-bindings/touchio/TouchIn.c @@ -27,7 +27,7 @@ #include #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/mphal.h" #include "py/nlr.h" @@ -59,9 +59,9 @@ //| ... //| STATIC mp_obj_t touchio_touchin_make_new(const mp_obj_type_t *type, - mp_uint_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { + size_t n_args, size_t n_kw, const mp_obj_t *args) { // check number of arguments - mp_arg_check_num(n_args, kw_args, 1, 1, false); + mp_arg_check_num(n_args, n_kw, 1, 1, false); // 1st argument is the pin const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[0]); diff --git a/shared-bindings/usb_hid/Device.c b/shared-bindings/usb_hid/Device.c index 30379a25e9..fe490091d7 100644 --- a/shared-bindings/usb_hid/Device.c +++ b/shared-bindings/usb_hid/Device.c @@ -50,7 +50,8 @@ //| Use a size of ``0`` for a report that is not an OUT report. //| "OUT" is with respect to the host. //| -//| ``report_ids``, ``in_report_lengths``, and ``out_report_lengths`` must all be the same length. +//| ``report_ids``, ``in_report_lengths``, and ``out_report_lengths`` must all have the +//| same number of elements. //| //| Here is an example of a `Device` with a descriptor that specifies two report IDs, 3 and 4. //| Report ID 3 sends an IN report of length 5, and receives an OUT report of length 6. @@ -81,7 +82,7 @@ //| Uses Report ID 3 for its IN report.""" //| -STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { usb_hid_device_obj_t *self = m_new_obj(usb_hid_device_obj_t); self->base.type = &usb_hid_device_type; enum { ARG_report_descriptor, ARG_usage_page, ARG_usage, ARG_report_ids, ARG_in_report_lengths, ARG_out_report_lengths }; @@ -95,7 +96,7 @@ STATIC mp_obj_t usb_hid_device_make_new(const mp_obj_type_t *type, size_t n_args }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_buffer_info_t descriptor_bufinfo; mp_get_buffer_raise(args[ARG_report_descriptor].u_obj, &descriptor_bufinfo, MP_BUFFER_READ); @@ -192,7 +193,7 @@ STATIC mp_obj_t usb_hid_device_send_report(size_t n_args, const mp_obj_t *pos_ar MP_DEFINE_CONST_FUN_OBJ_KW(usb_hid_device_send_report_obj, 1, usb_hid_device_send_report); //| def get_last_received_report(self, report_id: Optional[int] = None) -> bytes: -//| """Get the last received HID OUT report for the given report ID. +//| """Get the last received HID OUT or feature report for the given report ID. //| The report ID may be omitted if there is no report ID, or only one report ID. //| Return `None` if nothing received. //| """ diff --git a/shared-bindings/usb_hid/__init__.c b/shared-bindings/usb_hid/__init__.c index d1b4357dc1..3922ded03c 100644 --- a/shared-bindings/usb_hid/__init__.c +++ b/shared-bindings/usb_hid/__init__.c @@ -40,6 +40,11 @@ //| """Tuple of all active HID device interfaces. //| The default set of devices is ``Device.KEYBOARD, Device.MOUSE, Device.CONSUMER_CONTROL``, //| On boards where `usb_hid` is disabled by default, `devices` is an empty tuple. +//| +//| If a boot device is enabled by `usb_hid.enable()`, *and* the host has requested a boot device, +//| the `devices` tuple is **replaced** when ``code.py`` starts with a single-element tuple +//| containing a `Device` that describes the boot device chosen (keyboard or mouse). +//| The request for a boot device overrides any other HID devices. //| """ //| @@ -60,7 +65,7 @@ STATIC mp_obj_t usb_hid_disable(void) { } MP_DEFINE_CONST_FUN_OBJ_0(usb_hid_disable_obj, usb_hid_disable); -//| def enable(devices: Optional[Sequence[Device]]) -> None: +//| def enable(devices: Optional[Sequence[Device]], boot_device: int = 0) -> None: //| """Specify which USB HID devices that will be available. //| Can be called in ``boot.py``, before USB is connected. //| @@ -68,15 +73,53 @@ MP_DEFINE_CONST_FUN_OBJ_0(usb_hid_disable_obj, usb_hid_disable); //| If `devices` is empty, HID is disabled. The order of the ``Devices`` //| may matter to the host. For instance, for MacOS, put the mouse device //| before any Gamepad or Digitizer HID device or else it will not work. +//| :param int boot_device: If non-zero, inform the host that support for a +//| a boot HID device is available. +//| If ``boot_device=1``, a boot keyboard is available. +//| If ``boot_device=2``, a boot mouse is available. No other values are allowed. +//| See below. //| //| If you enable too many devices at once, you will run out of USB endpoints. //| The number of available endpoints varies by microcontroller. //| CircuitPython will go into safe mode after running ``boot.py`` to inform you if //| not enough endpoints are available. +//| +//| **Boot Devices** +//| +//| Boot devices implement a fixed, predefined report descriptor, defined in +//| https://www.usb.org/sites/default/files/hid1_12.pdf, Appendix B. A USB host +//| can request to use the boot device if the USB device says it is available. +//| Usually only a BIOS or other kind of limited-functionality +//| host needs boot keyboard support. +//| +//| For example, to make a boot keyboard available, you can use this code:: +//| +//| usb_hid.enable((Device.KEYBOARD), boot_device=1) # 1 for a keyboard +//| +//| If the host requests the boot keyboard, the report descriptor provided by `Device.KEYBOARD` +//| will be ignored, and the predefined report descriptor will be used. +//| But if the host does not request the boot keyboard, +//| the descriptor provided by `Device.KEYBOARD` will be used. +//| +//| The HID boot device must usually be the first or only device presented by CircuitPython. +//| The HID device will be USB interface number 0. +//| To make sure it is the first device, disable other USB devices, including CDC and MSC (CIRCUITPY). +//| If you specify a non-zero ``boot_device``, and it is not the first device, CircuitPython +//| will enter safe mode to report this error. //| """ //| ... //| -STATIC mp_obj_t usb_hid_enable(mp_obj_t devices) { +STATIC mp_obj_t usb_hid_enable(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { + enum { ARG_devices, ARG_boot_device }; + static const mp_arg_t allowed_args[] = { + { MP_QSTR_devices, MP_ARG_REQUIRED | MP_ARG_OBJ }, + { MP_QSTR_boot_device, MP_ARG_INT, {.u_int = 0} }, + }; + + mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; + mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + + mp_obj_t devices = args[ARG_devices].u_obj; const mp_int_t len = mp_obj_get_int(mp_obj_len(devices)); for (mp_int_t i = 0; i < len; i++) { mp_obj_t item = mp_obj_subscr(devices, MP_OBJ_NEW_SMALL_INT(i), MP_OBJ_SENTINEL); @@ -85,21 +128,44 @@ STATIC mp_obj_t usb_hid_enable(mp_obj_t devices) { } } - if (!common_hal_usb_hid_enable(devices)) { + uint8_t boot_device = + (uint8_t)mp_arg_validate_int_range(args[ARG_boot_device].u_int, 0, 2, MP_QSTR_boot_device); + + if (!common_hal_usb_hid_enable(devices, boot_device)) { mp_raise_RuntimeError(translate("Cannot change USB devices now")); } return mp_const_none; } -MP_DEFINE_CONST_FUN_OBJ_1(usb_hid_enable_obj, usb_hid_enable); +MP_DEFINE_CONST_FUN_OBJ_KW(usb_hid_enable_obj, 1, usb_hid_enable); + +//| def get_boot_device() -> int: +//| """ +//| :return: the boot device requested by the host, if any. +//| Returns 0 if the host did not request a boot device, or if `usb_hid.enable()` +//| was called with ``boot_device=0``, the default, which disables boot device support. +//| If the host did request a boot device, +//| returns the value of ``boot_device`` set in `usb_hid.enable()`: +//| ``1`` for a boot keyboard, or ``2`` for boot mouse. +//| However, the standard devices provided by CircuitPython, `Device.KEYBOARD` and `Device.MOUSE`, +//| describe reports that match the boot device reports, so you don't need to check this +//| if you are using those devices. +//| :rtype int: +//| """ +//| +STATIC mp_obj_t usb_hid_get_boot_device(void) { + return MP_OBJ_NEW_SMALL_INT(common_hal_usb_hid_get_boot_device()); +} +MP_DEFINE_CONST_FUN_OBJ_0(usb_hid_get_boot_device_obj, usb_hid_get_boot_device); // usb_hid.devices is set once the usb devices are determined, after boot.py runs. STATIC mp_map_elem_t usb_hid_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_usb_hid) }, - { MP_ROM_QSTR(MP_QSTR_Device), MP_OBJ_FROM_PTR(&usb_hid_device_type) }, - { MP_ROM_QSTR(MP_QSTR_devices), mp_const_none }, - { MP_ROM_QSTR(MP_QSTR_disable), MP_OBJ_FROM_PTR(&usb_hid_disable_obj) }, - { MP_ROM_QSTR(MP_QSTR_enable), MP_OBJ_FROM_PTR(&usb_hid_enable_obj) }, + { MP_ROM_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_usb_hid) }, + { MP_ROM_QSTR(MP_QSTR_Device), MP_OBJ_FROM_PTR(&usb_hid_device_type) }, + { MP_ROM_QSTR(MP_QSTR_devices), mp_const_none }, + { MP_ROM_QSTR(MP_QSTR_disable), MP_OBJ_FROM_PTR(&usb_hid_disable_obj) }, + { MP_ROM_QSTR(MP_QSTR_enable), MP_OBJ_FROM_PTR(&usb_hid_enable_obj) }, + { MP_ROM_QSTR(MP_QSTR_get_boot_device), MP_OBJ_FROM_PTR(&usb_hid_get_boot_device_obj) }, }; STATIC MP_DEFINE_MUTABLE_DICT(usb_hid_module_globals, usb_hid_module_globals_table); diff --git a/shared-bindings/usb_hid/__init__.h b/shared-bindings/usb_hid/__init__.h index d5fc7743a3..feaeed2545 100644 --- a/shared-bindings/usb_hid/__init__.h +++ b/shared-bindings/usb_hid/__init__.h @@ -36,6 +36,7 @@ extern mp_obj_tuple_t common_hal_usb_hid_devices; void usb_hid_set_devices(mp_obj_t devices); bool common_hal_usb_hid_disable(void); -bool common_hal_usb_hid_enable(const mp_obj_t devices_seq); +bool common_hal_usb_hid_enable(const mp_obj_t devices_seq, uint8_t boot_device); +uint8_t common_hal_usb_hid_get_boot_device(void); #endif // SHARED_BINDINGS_USB_HID_H diff --git a/shared-bindings/vectorio/Circle.c b/shared-bindings/vectorio/Circle.c index abcbccd856..43845937c4 100644 --- a/shared-bindings/vectorio/Circle.c +++ b/shared-bindings/vectorio/Circle.c @@ -20,7 +20,7 @@ //| :param int x: Initial x position of the axis. //| :param int y: Initial y position of the axis.""" //| -static mp_obj_t vectorio_circle_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t vectorio_circle_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_pixel_shader, ARG_radius, ARG_x, ARG_y }; static const mp_arg_t allowed_args[] = { { MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, @@ -29,7 +29,7 @@ static mp_obj_t vectorio_circle_make_new(const mp_obj_type_t *type, size_t n_arg { MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_int_t radius = args[ARG_radius].u_int; if (radius < 1) { diff --git a/shared-bindings/vectorio/Polygon.c b/shared-bindings/vectorio/Polygon.c index 53c40d1f73..d1078b2d2d 100644 --- a/shared-bindings/vectorio/Polygon.c +++ b/shared-bindings/vectorio/Polygon.c @@ -27,7 +27,7 @@ //| :param int x: Initial screen x position of the 0,0 origin in the points list. //| :param int y: Initial screen y position of the 0,0 origin in the points list.""" //| -static mp_obj_t vectorio_polygon_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t vectorio_polygon_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_pixel_shader, ARG_points_list, ARG_x, ARG_y }; static const mp_arg_t allowed_args[] = { { MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, @@ -36,7 +36,7 @@ static mp_obj_t vectorio_polygon_make_new(const mp_obj_type_t *type, size_t n_ar { MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_obj_t points_list = mp_arg_validate_type(args[ARG_points_list].u_obj, &mp_type_list, MP_QSTR_points); diff --git a/shared-bindings/vectorio/Rectangle.c b/shared-bindings/vectorio/Rectangle.c index 176cbaba7c..287ae9d408 100644 --- a/shared-bindings/vectorio/Rectangle.c +++ b/shared-bindings/vectorio/Rectangle.c @@ -19,7 +19,7 @@ //| :param int x: Initial x position of the top left corner. //| :param int y: Initial y position of the top left corner.""" //| -static mp_obj_t vectorio_rectangle_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t vectorio_rectangle_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_pixel_shader, ARG_width, ARG_height, ARG_x, ARG_y }; static const mp_arg_t allowed_args[] = { { MP_QSTR_pixel_shader, MP_ARG_OBJ | MP_ARG_KW_ONLY | MP_ARG_REQUIRED }, @@ -29,7 +29,7 @@ static mp_obj_t vectorio_rectangle_make_new(const mp_obj_type_t *type, size_t n_ { MP_QSTR_y, MP_ARG_INT | MP_ARG_KW_ONLY, {.u_int = 0} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; - mp_arg_parse_all(n_args, pos_args, kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); + mp_arg_parse_all_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); mp_int_t width = args[ARG_width].u_int; if (width < 1) { diff --git a/shared-bindings/vectorio/VectorShape.c b/shared-bindings/vectorio/VectorShape.c index c9cbf0a114..d5d12ec1cd 100644 --- a/shared-bindings/vectorio/VectorShape.c +++ b/shared-bindings/vectorio/VectorShape.c @@ -10,7 +10,7 @@ #include -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/binary.h" #include "py/objproperty.h" diff --git a/shared-bindings/watchdog/__init__.h b/shared-bindings/watchdog/__init__.h index b5a0ad71d1..0921141129 100644 --- a/shared-bindings/watchdog/__init__.h +++ b/shared-bindings/watchdog/__init__.h @@ -27,6 +27,9 @@ #ifndef MICROPY_INCLUDED_SHARED_BINDINGS_WATCHDOG___INIT___H #define MICROPY_INCLUDED_SHARED_BINDINGS_WATCHDOG___INIT___H +#include "py/obj.h" +#include "py/objexcept.h" + extern const mp_obj_module_t watchdog_module; extern mp_obj_exception_t mp_watchdog_timeout_exception; extern const mp_obj_type_t mp_type_WatchDogTimeout; diff --git a/shared-module/_bleio/ScanResults.c b/shared-module/_bleio/ScanResults.c index 25ce387d07..e5b5525579 100644 --- a/shared-module/_bleio/ScanResults.c +++ b/shared-module/_bleio/ScanResults.c @@ -28,7 +28,7 @@ #include -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/objstr.h" #include "py/runtime.h" #include "shared-bindings/_bleio/ScanEntry.h" diff --git a/shared-module/adafruit_bus_device/I2CDevice.c b/shared-module/adafruit_bus_device/I2CDevice.c index 51c5073a74..942b132c3e 100644 --- a/shared-module/adafruit_bus_device/I2CDevice.c +++ b/shared-module/adafruit_bus_device/I2CDevice.c @@ -29,7 +29,7 @@ #include "py/mperrno.h" #include "py/nlr.h" #include "py/runtime.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" void common_hal_adafruit_bus_device_i2cdevice_construct(adafruit_bus_device_i2cdevice_obj_t *self, mp_obj_t *i2c, uint8_t device_address) { self->i2c = i2c; diff --git a/shared-module/atexit/__init__.h b/shared-module/atexit/__init__.h index befccb3ea8..d88d066ded 100644 --- a/shared-module/atexit/__init__.h +++ b/shared-module/atexit/__init__.h @@ -28,7 +28,7 @@ #define MICROPY_INCLUDED_SHARED_MODULE_ATEXIT___INIT___H #include "py/obj.h" -#include "lib/utils/pyexec.h" +#include "shared/runtime/pyexec.h" typedef struct _atexit_callback_t { size_t n_pos, n_kw; diff --git a/shared-module/displayio/__init__.c b/shared-module/displayio/__init__.c index d264531c99..e4a4965368 100644 --- a/shared-module/displayio/__init__.c +++ b/shared-module/displayio/__init__.c @@ -3,7 +3,7 @@ #include "shared-module/displayio/__init__.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/reload.h" #include "py/runtime.h" #include "shared-bindings/board/__init__.h" diff --git a/shared-module/fontio/BuiltinFont.c b/shared-module/fontio/BuiltinFont.c index b77a6a1c8b..cb5b7f9cb1 100644 --- a/shared-module/fontio/BuiltinFont.c +++ b/shared-module/fontio/BuiltinFont.c @@ -75,5 +75,5 @@ mp_obj_t common_hal_fontio_builtinfont_get_glyph(const fontio_builtinfont_t *sel MP_OBJ_NEW_SMALL_INT(self->width), MP_OBJ_NEW_SMALL_INT(0) }; - return namedtuple_make_new((const mp_obj_type_t *)&fontio_glyph_type, 8, field_values, NULL); + return namedtuple_make_new((const mp_obj_type_t *)&fontio_glyph_type, 8, 0, field_values); } diff --git a/shared-module/getpass/__init__.c b/shared-module/getpass/__init__.c index f7ab96c378..8f16d75b53 100644 --- a/shared-module/getpass/__init__.c +++ b/shared-module/getpass/__init__.c @@ -25,7 +25,7 @@ */ #include "py/mphal.h" -#include "lib/mp-readline/readline.h" +#include "shared/readline/readline.h" #include "shared-module/getpass/__init__.h" mp_obj_t shared_module_getpass_getpass(const char *prompt, mp_print_t *print) { diff --git a/shared-module/qrio/QRDecoder.c b/shared-module/qrio/QRDecoder.c index 227f3b39b4..26a609f215 100644 --- a/shared-module/qrio/QRDecoder.c +++ b/shared-module/qrio/QRDecoder.c @@ -130,7 +130,7 @@ mp_obj_t shared_module_qrio_qrdecoder_decode(qrdecoder_qrdecoder_obj_t *self, co mp_obj_new_bytes(self->data.payload, self->data.payload_len), data_type(self->data.data_type), }; - mp_obj_t code_obj = namedtuple_make_new((const mp_obj_type_t *)&qrio_qrinfo_type_obj, 2, elems, NULL); + mp_obj_t code_obj = namedtuple_make_new((const mp_obj_type_t *)&qrio_qrinfo_type_obj, 2, 0, elems); mp_obj_list_append(result, code_obj); } return result; diff --git a/shared-module/rotaryio/IncrementalEncoder.c b/shared-module/rotaryio/IncrementalEncoder.c index 330895606e..89dea01cfe 100644 --- a/shared-module/rotaryio/IncrementalEncoder.c +++ b/shared-module/rotaryio/IncrementalEncoder.c @@ -30,26 +30,25 @@ void shared_module_softencoder_state_init(rotaryio_incrementalencoder_obj_t *self, uint8_t quiescent_state) { self->state = quiescent_state; - self->quarter_count = 0; + self->sub_count = 0; common_hal_rotaryio_incrementalencoder_set_position(self, 0); } void shared_module_softencoder_state_update(rotaryio_incrementalencoder_obj_t *self, uint8_t new_state) { - #define BAD 7 static const int8_t transitions[16] = { 0, // 00 -> 00 no movement -1, // 00 -> 01 3/4 ccw (11 detent) or 1/4 ccw (00 at detent) +1, // 00 -> 10 3/4 cw or 1/4 cw - BAD, // 00 -> 11 non-Gray-code transition + 0, // 00 -> 11 non-Gray-code transition +1, // 01 -> 00 2/4 or 4/4 cw 0, // 01 -> 01 no movement - BAD, // 01 -> 10 non-Gray-code transition + 0, // 01 -> 10 non-Gray-code transition -1, // 01 -> 11 4/4 or 2/4 ccw -1, // 10 -> 00 2/4 or 4/4 ccw - BAD, // 10 -> 01 non-Gray-code transition + 0, // 10 -> 01 non-Gray-code transition 0, // 10 -> 10 no movement +1, // 10 -> 11 4/4 or 2/4 cw - BAD, // 11 -> 00 non-Gray-code transition + 0, // 11 -> 00 non-Gray-code transition +1, // 11 -> 01 1/4 or 3/4 cw -1, // 11 -> 10 1/4 or 3/4 ccw 0, // 11 -> 11 no movement @@ -59,20 +58,16 @@ void shared_module_softencoder_state_update(rotaryio_incrementalencoder_obj_t *s int idx = (self->state << 2) | new_state; self->state = new_state; - int8_t quarter_incr = transitions[idx]; - if (quarter_incr == BAD) { - // Missed a transition. We don't know which way we're going, so do nothing. - return; - } + int8_t sub_incr = transitions[idx]; - self->quarter_count += quarter_incr; + self->sub_count += sub_incr; - if (self->quarter_count >= 4) { + if (self->sub_count >= self->divisor) { self->position += 1; - self->quarter_count = 0; - } else if (self->quarter_count <= -4) { + self->sub_count = 0; + } else if (self->sub_count <= -self->divisor) { self->position -= 1; - self->quarter_count = 0; + self->sub_count = 0; } } @@ -83,4 +78,12 @@ mp_int_t common_hal_rotaryio_incrementalencoder_get_position(rotaryio_incrementa void common_hal_rotaryio_incrementalencoder_set_position(rotaryio_incrementalencoder_obj_t *self, mp_int_t position) { self->position = position; } + +mp_int_t common_hal_rotaryio_incrementalencoder_get_divisor(rotaryio_incrementalencoder_obj_t *self) { + return self->divisor; +} + +void common_hal_rotaryio_incrementalencoder_set_divisor(rotaryio_incrementalencoder_obj_t *self, mp_int_t divisor) { + self->divisor = divisor; +} #endif diff --git a/shared-module/usb_cdc/Serial.c b/shared-module/usb_cdc/Serial.c index 3ffb22cc3d..3b402bf70c 100644 --- a/shared-module/usb_cdc/Serial.c +++ b/shared-module/usb_cdc/Serial.c @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "shared-module/usb_cdc/Serial.h" #include "supervisor/shared/tick.h" diff --git a/shared-module/usb_hid/Device.c b/shared-module/usb_hid/Device.c index 71c6dea7af..de34d60d0a 100644 --- a/shared-module/usb_hid/Device.c +++ b/shared-module/usb_hid/Device.c @@ -244,7 +244,7 @@ void common_hal_usb_hid_device_send_report(usb_hid_device_obj_t *self, uint8_t * } mp_obj_t common_hal_usb_hid_device_get_last_received_report(usb_hid_device_obj_t *self, uint8_t report_id) { - // report_id has already been validated for this deveice. + // report_id has already been validated for this device. size_t id_idx = get_report_id_idx(self, report_id); return mp_obj_new_bytes(self->out_report_buffers[id_idx], self->out_report_lengths[id_idx]); } @@ -266,11 +266,11 @@ void usb_hid_device_create_report_buffers(usb_hid_device_obj_t *self) { } -// Callbacks invoked when we received Get_Report request through control endpoint +// Callback invoked when we receive Get_Report request through control endpoint uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t *buffer, uint16_t reqlen) { (void)itf; - // only support Input Report - if (report_type != HID_REPORT_TYPE_INPUT) { + // Support Input Report and Feature Report + if (report_type != HID_REPORT_TYPE_INPUT && report_type != HID_REPORT_TYPE_FEATURE) { return 0; } @@ -289,14 +289,14 @@ uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t return 0; } -// Callbacks invoked when we received Set_Report request through control endpoint +// Callback invoked when we receive Set_Report request through control endpoint void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize) { (void)itf; if (report_type == HID_REPORT_TYPE_INVALID) { report_id = buffer[0]; buffer++; bufsize--; - } else if (report_type != HID_REPORT_TYPE_OUTPUT) { + } else if (report_type != HID_REPORT_TYPE_OUTPUT && report_type != HID_REPORT_TYPE_FEATURE) { return; } diff --git a/shared-module/usb_hid/__init__.c b/shared-module/usb_hid/__init__.c index efe37662ee..89a05c77b3 100644 --- a/shared-module/usb_hid/__init__.c +++ b/shared-module/usb_hid/__init__.c @@ -31,7 +31,7 @@ #include "py/gc.h" #include "py/runtime.h" #include "shared-bindings/usb_hid/__init__.h" -#include "shared-module/usb_hid/Device.h" +#include "shared-bindings/usb_hid/Device.h" #include "supervisor/memory.h" #include "supervisor/usb.h" @@ -44,7 +44,9 @@ static const uint8_t usb_hid_descriptor_template[] = { 0x02, // 4 bNumEndpoints 2 0x03, // 5 bInterfaceClass: HID 0x00, // 6 bInterfaceSubClass: NOBOOT +#define HID_DESCRIPTOR_SUBCLASS_INDEX (6) 0x00, // 7 bInterfaceProtocol: NONE +#define HID_DESCRIPTOR_INTERFACE_PROTOCOL_INDEX (7) 0xFF, // 8 iInterface (String Index) [SET AT RUNTIME] #define HID_DESCRIPTOR_INTERFACE_STRING_INDEX (8) @@ -81,6 +83,14 @@ static usb_hid_device_obj_t hid_devices[MAX_HID_DEVICES]; // If 0, USB HID is disabled. static mp_int_t num_hid_devices; +// Which boot device is available? 0: no boot devices, 1: boot keyboard, 2: boot mouse. +// This value is set by usb_hid.enable(), and used to build the HID interface descriptor. +// The value is remembered here from boot.py to code.py. +static uint8_t hid_boot_device; + +// Whether a boot device was requested by a SET_PROTOCOL request from the host. +static bool hid_boot_device_requested; + // This tuple is store in usb_hid.devices. static mp_obj_tuple_t *hid_devices_tuple; @@ -96,13 +106,56 @@ static mp_obj_tuple_t default_hid_devices_tuple = { }, }; +// These describe the standard descriptors used for boot keyboard and mouse, which don't use report IDs. +// When the host requests a boot device, replace whatever HID devices were enabled with a tuple +// containing just one of these, since the host is uninterested in other devices. +// The driver code will then use the proper report length and send_report() will not send a report ID. +static const usb_hid_device_obj_t boot_keyboard_obj = { + .base = { + .type = &usb_hid_device_type, + }, + .report_descriptor = NULL, + .report_descriptor_length = 0, + .usage_page = 0x01, + .usage = 0x06, + .num_report_ids = 1, + .report_ids = { 0, }, + .in_report_lengths = { 8, }, + .out_report_lengths = { 1, }, +}; + +static const usb_hid_device_obj_t boot_mouse_obj = { + .base = { + .type = &usb_hid_device_type, + }, + .report_descriptor = NULL, + .report_descriptor_length = 0, + .usage_page = 0x01, + .usage = 0x02, + .num_report_ids = 1, + .report_ids = { 0, }, + .in_report_lengths = { 4, }, + .out_report_lengths = { 0, }, +}; + bool usb_hid_enabled(void) { return num_hid_devices > 0; } +uint8_t usb_hid_boot_device(void) { + return hid_boot_device; +} + +// Returns 1 or 2 if host requested a boot device and boot protocol was enabled in the interface descriptor. +uint8_t common_hal_usb_hid_get_boot_device(void) { + return hid_boot_device_requested ? hid_boot_device : 0; +} + void usb_hid_set_defaults(void) { + hid_boot_device = 0; + hid_boot_device_requested = false; common_hal_usb_hid_enable( - CIRCUITPY_USB_HID_ENABLED_DEFAULT ? &default_hid_devices_tuple : mp_const_empty_tuple); + CIRCUITPY_USB_HID_ENABLED_DEFAULT ? &default_hid_devices_tuple : mp_const_empty_tuple, 0); } // This is the interface descriptor, not the report descriptor. @@ -113,12 +166,17 @@ size_t usb_hid_descriptor_length(void) { static const char usb_hid_interface_name[] = USB_INTERFACE_NAME " HID"; // This is the interface descriptor, not the report descriptor. -size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *descriptor_counts, uint8_t *current_interface_string, uint16_t report_descriptor_length) { +size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *descriptor_counts, uint8_t *current_interface_string, uint16_t report_descriptor_length, uint8_t boot_device) { memcpy(descriptor_buf, usb_hid_descriptor_template, sizeof(usb_hid_descriptor_template)); descriptor_buf[HID_DESCRIPTOR_INTERFACE_INDEX] = descriptor_counts->current_interface; descriptor_counts->current_interface++; + if (boot_device > 0) { + descriptor_buf[HID_DESCRIPTOR_SUBCLASS_INDEX] = 1; // BOOT protocol (device) available. + descriptor_buf[HID_DESCRIPTOR_INTERFACE_PROTOCOL_INDEX] = boot_device; // 1: keyboard, 2: mouse + } + usb_add_interface_string(*current_interface_string, usb_hid_interface_name); descriptor_buf[HID_DESCRIPTOR_INTERFACE_STRING_INDEX] = *current_interface_string; (*current_interface_string)++; @@ -151,10 +209,10 @@ static void usb_hid_set_devices_from_hid_devices(void) { } bool common_hal_usb_hid_disable(void) { - return common_hal_usb_hid_enable(mp_const_empty_tuple); + return common_hal_usb_hid_enable(mp_const_empty_tuple, 0); } -bool common_hal_usb_hid_enable(const mp_obj_t devices) { +bool common_hal_usb_hid_enable(const mp_obj_t devices, uint8_t boot_device) { // We can't change the devices once we're connected. if (tud_connected()) { return false; @@ -167,6 +225,8 @@ bool common_hal_usb_hid_enable(const mp_obj_t devices) { num_hid_devices = num_devices; + hid_boot_device = boot_device; + // Remember the devices in static storage so they live across VMs. for (mp_int_t i = 0; i < num_hid_devices; i++) { // devices has already been validated to contain only usb_hid_device_obj_t objects. @@ -182,6 +242,17 @@ bool common_hal_usb_hid_enable(const mp_obj_t devices) { // Called when HID devices are ready to be used, when code.py or the REPL starts running. void usb_hid_setup_devices(void) { + + // If the host requested a boot device, replace the current list of devices + // with a single-element tuple containing the proper boot device. + if (hid_boot_device_requested) { + memcpy(&hid_devices[0], + // Will be 1 (keyboard) or 2 (mouse). + hid_boot_device == 1 ? &boot_keyboard_obj : &boot_mouse_obj, + sizeof(usb_hid_device_obj_t)); + num_hid_devices = 1; + } + usb_hid_set_devices_from_hid_devices(); // Create report buffers on the heap. @@ -272,9 +343,15 @@ bool usb_hid_get_device_with_report_id(uint8_t report_id, usb_hid_device_obj_t * return false; } -// Invoked when GET HID REPORT DESCRIPTOR is received. -// Application return pointer to descriptor +// Callback invoked when we receive a GET HID REPORT DESCRIPTOR +// Application returns pointer to descriptor // Descriptor contents must exist long enough for transfer to complete uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf) { return (uint8_t *)hid_report_descriptor_allocation->ptr; } + +// Callback invoked when we receive a SET_PROTOCOL request. +// Protocol is either HID_PROTOCOL_BOOT (0) or HID_PROTOCOL_REPORT (1) +void tud_hid_set_protocol_cb(uint8_t instance, uint8_t protocol) { + hid_boot_device_requested = (protocol == HID_PROTOCOL_BOOT); +} diff --git a/shared-module/usb_hid/__init__.h b/shared-module/usb_hid/__init__.h index 6d85b50e9f..1a33540321 100644 --- a/shared-module/usb_hid/__init__.h +++ b/shared-module/usb_hid/__init__.h @@ -33,9 +33,10 @@ extern usb_hid_device_obj_t usb_hid_devices[]; bool usb_hid_enabled(void); +uint8_t usb_hid_boot_device(void); void usb_hid_set_defaults(void); -size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *descriptor_counts, uint8_t *current_interface_string, uint16_t report_descriptor_length); +size_t usb_hid_add_descriptor(uint8_t *descriptor_buf, descriptor_counts_t *descriptor_counts, uint8_t *current_interface_string, uint16_t report_descriptor_length, uint8_t boot_device); size_t usb_hid_descriptor_length(void); size_t usb_hid_report_descriptor_length(void); diff --git a/shared/README.md b/shared/README.md new file mode 100644 index 0000000000..073187b249 --- /dev/null +++ b/shared/README.md @@ -0,0 +1,3 @@ +This directory contains libraries, utilities and helper code developed +specifically for this project. The code is intended to be portable and +usable by any port. diff --git a/lib/embed/__errno.c b/shared/libc/__errno.c similarity index 100% rename from lib/embed/__errno.c rename to shared/libc/__errno.c diff --git a/lib/embed/abort_.c b/shared/libc/abort_.c similarity index 100% rename from lib/embed/abort_.c rename to shared/libc/abort_.c diff --git a/lib/utils/printf.c b/shared/libc/printf.c similarity index 100% rename from lib/utils/printf.c rename to shared/libc/printf.c diff --git a/lib/libc/string0.c b/shared/libc/string0.c similarity index 100% rename from lib/libc/string0.c rename to shared/libc/string0.c diff --git a/lib/memzip/README.md b/shared/memzip/README.md similarity index 84% rename from lib/memzip/README.md rename to shared/memzip/README.md index c4e31a1170..9aa12a94c8 100644 --- a/lib/memzip/README.md +++ b/shared/memzip/README.md @@ -10,13 +10,13 @@ a C file which contains the data from the zip file. A typical addition to a makefile would look like: ``` SRC_C += \ - lib/memzip/import.c \ - lib/memzip/lexermemzip.c \ - lib/memzip/memzip.c \ + shared/memzip/import.c \ + shared/memzip/lexermemzip.c \ + shared/memzip/memzip.c \ OBJ += $(BUILD)/memzip-files.o -MAKE_MEMZIP = ../lib/memzip/make-memzip.py +MAKE_MEMZIP = ../shared/memzip/make-memzip.py $(BUILD)/memzip-files.o: $(BUILD)/memzip-files.c $(call compile_c) diff --git a/lib/memzip/import.c b/shared/memzip/import.c similarity index 100% rename from lib/memzip/import.c rename to shared/memzip/import.c diff --git a/lib/memzip/lexermemzip.c b/shared/memzip/lexermemzip.c similarity index 100% rename from lib/memzip/lexermemzip.c rename to shared/memzip/lexermemzip.c diff --git a/lib/memzip/make-memzip.py b/shared/memzip/make-memzip.py similarity index 100% rename from lib/memzip/make-memzip.py rename to shared/memzip/make-memzip.py diff --git a/lib/memzip/memzip.c b/shared/memzip/memzip.c similarity index 100% rename from lib/memzip/memzip.c rename to shared/memzip/memzip.c diff --git a/lib/memzip/memzip.h b/shared/memzip/memzip.h similarity index 100% rename from lib/memzip/memzip.h rename to shared/memzip/memzip.h diff --git a/lib/netutils/dhcpserver.c b/shared/netutils/dhcpserver.c similarity index 99% rename from lib/netutils/dhcpserver.c rename to shared/netutils/dhcpserver.c index 7f97ee6e46..9db42b3fd9 100644 --- a/lib/netutils/dhcpserver.c +++ b/shared/netutils/dhcpserver.c @@ -35,7 +35,7 @@ #if MICROPY_PY_LWIP -#include "lib/netutils/dhcpserver.h" +#include "shared/netutils/dhcpserver.h" #include "lwip/udp.h" #define DHCPDISCOVER (1) diff --git a/lib/netutils/dhcpserver.h b/shared/netutils/dhcpserver.h similarity index 100% rename from lib/netutils/dhcpserver.h rename to shared/netutils/dhcpserver.h diff --git a/lib/netutils/netutils.c b/shared/netutils/netutils.c similarity index 98% rename from lib/netutils/netutils.c rename to shared/netutils/netutils.c index 24a6fac99a..fe92e8bafb 100644 --- a/lib/netutils/netutils.c +++ b/shared/netutils/netutils.c @@ -30,7 +30,7 @@ #include #include "py/runtime.h" -#include "lib/netutils/netutils.h" +#include "shared/netutils/netutils.h" #include "supervisor/shared/translate.h" // Takes an array with a raw IPv4 address and returns something like '192.168.0.1'. diff --git a/lib/netutils/netutils.h b/shared/netutils/netutils.h similarity index 100% rename from lib/netutils/netutils.h rename to shared/netutils/netutils.h diff --git a/lib/netutils/trace.c b/shared/netutils/trace.c similarity index 99% rename from lib/netutils/trace.c rename to shared/netutils/trace.c index 1610966c2d..a6dfb42c28 100644 --- a/lib/netutils/trace.c +++ b/shared/netutils/trace.c @@ -25,7 +25,7 @@ */ #include "py/mphal.h" -#include "lib/netutils/netutils.h" +#include "shared/netutils/netutils.h" static uint32_t get_be16(const uint8_t *buf) { return buf[0] << 8 | buf[1]; diff --git a/lib/mp-readline/readline.c b/shared/readline/readline.c similarity index 99% rename from lib/mp-readline/readline.c rename to shared/readline/readline.c index b47204abac..23183342a7 100644 --- a/lib/mp-readline/readline.c +++ b/shared/readline/readline.c @@ -31,7 +31,7 @@ #include "py/mpstate.h" #include "py/repl.h" #include "py/mphal.h" -#include "lib/mp-readline/readline.h" +#include "shared/readline/readline.h" #if 0 // print debugging info #define DEBUG_PRINT (1) diff --git a/lib/mp-readline/readline.h b/shared/readline/readline.h similarity index 100% rename from lib/mp-readline/readline.h rename to shared/readline/readline.h diff --git a/lib/utils/buffer_helper.c b/shared/runtime/buffer_helper.c similarity index 97% rename from lib/utils/buffer_helper.c rename to shared/runtime/buffer_helper.c index a4008225d6..facd05eaf0 100644 --- a/lib/utils/buffer_helper.c +++ b/shared/runtime/buffer_helper.c @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -#include "lib/utils/buffer_helper.h" +#include "shared/runtime/buffer_helper.h" void normalize_buffer_bounds(int32_t *start, int32_t end, size_t *length) { if (end < 0) { diff --git a/lib/utils/buffer_helper.h b/shared/runtime/buffer_helper.h similarity index 100% rename from lib/utils/buffer_helper.h rename to shared/runtime/buffer_helper.h diff --git a/lib/utils/context_manager_helpers.c b/shared/runtime/context_manager_helpers.c similarity index 96% rename from lib/utils/context_manager_helpers.c rename to shared/runtime/context_manager_helpers.c index 2614856160..d489ce994b 100644 --- a/lib/utils/context_manager_helpers.c +++ b/shared/runtime/context_manager_helpers.c @@ -24,7 +24,7 @@ * THE SOFTWARE. */ -#include "lib/utils/context_manager_helpers.h" +#include "shared/runtime/context_manager_helpers.h" #include "py/obj.h" diff --git a/lib/utils/context_manager_helpers.h b/shared/runtime/context_manager_helpers.h similarity index 100% rename from lib/utils/context_manager_helpers.h rename to shared/runtime/context_manager_helpers.h diff --git a/lib/utils/gchelper.h b/shared/runtime/gchelper.h similarity index 100% rename from lib/utils/gchelper.h rename to shared/runtime/gchelper.h diff --git a/lib/utils/gchelper_generic.c b/shared/runtime/gchelper_generic.c similarity index 99% rename from lib/utils/gchelper_generic.c rename to shared/runtime/gchelper_generic.c index 3e7e33ab18..dcd35f9c7e 100644 --- a/lib/utils/gchelper_generic.c +++ b/shared/runtime/gchelper_generic.c @@ -28,7 +28,7 @@ #include "py/mpstate.h" #include "py/gc.h" -#include "lib/utils/gchelper.h" +#include "shared/runtime/gchelper.h" #if MICROPY_ENABLE_GC diff --git a/lib/utils/gchelper_m0.s b/shared/runtime/gchelper_m0.s similarity index 100% rename from lib/utils/gchelper_m0.s rename to shared/runtime/gchelper_m0.s diff --git a/lib/utils/gchelper_m3.s b/shared/runtime/gchelper_m3.s similarity index 100% rename from lib/utils/gchelper_m3.s rename to shared/runtime/gchelper_m3.s diff --git a/lib/utils/gchelper_native.c b/shared/runtime/gchelper_native.c similarity index 97% rename from lib/utils/gchelper_native.c rename to shared/runtime/gchelper_native.c index 6bf386b519..1e4af9c844 100644 --- a/lib/utils/gchelper_native.c +++ b/shared/runtime/gchelper_native.c @@ -28,7 +28,7 @@ #include "py/mpstate.h" #include "py/gc.h" -#include "lib/utils/gchelper.h" +#include "shared/runtime/gchelper.h" #if MICROPY_ENABLE_GC diff --git a/lib/utils/interrupt_char.c b/shared/runtime/interrupt_char.c similarity index 96% rename from lib/utils/interrupt_char.c rename to shared/runtime/interrupt_char.c index c751c4e52c..4ac099f41e 100644 --- a/lib/utils/interrupt_char.c +++ b/shared/runtime/interrupt_char.c @@ -37,7 +37,7 @@ void mp_hal_set_interrupt_char(int c) { // Check to see if we've been CTRL-C'ed by autoreload or the user. bool mp_hal_is_interrupted(void) { - return MP_STATE_VM(mp_pending_exception) != NULL; + return MP_STATE_THREAD(mp_pending_exception) != NULL; } #endif diff --git a/lib/utils/interrupt_char.h b/shared/runtime/interrupt_char.h similarity index 100% rename from lib/utils/interrupt_char.h rename to shared/runtime/interrupt_char.h diff --git a/lib/utils/mpirq.c b/shared/runtime/mpirq.c similarity index 99% rename from lib/utils/mpirq.c rename to shared/runtime/mpirq.c index 02139f24dc..8e474bf5a2 100644 --- a/lib/utils/mpirq.c +++ b/shared/runtime/mpirq.c @@ -29,7 +29,7 @@ #include "py/runtime.h" #include "py/gc.h" -#include "lib/utils/mpirq.h" +#include "shared/runtime/mpirq.h" #if MICROPY_ENABLE_SCHEDULER diff --git a/lib/utils/mpirq.h b/shared/runtime/mpirq.h similarity index 100% rename from lib/utils/mpirq.h rename to shared/runtime/mpirq.h diff --git a/lib/utils/pyexec.c b/shared/runtime/pyexec.c similarity index 99% rename from lib/utils/pyexec.c rename to shared/runtime/pyexec.c index fe52fc645b..e611131f6b 100644 --- a/lib/utils/pyexec.c +++ b/shared/runtime/pyexec.c @@ -40,8 +40,8 @@ #include "irq.h" #include "usb.h" #endif -#include "lib/mp-readline/readline.h" -#include "lib/utils/pyexec.h" +#include "shared/readline/readline.h" +#include "shared/runtime/pyexec.h" #include "genhdr/mpversion.h" #if CIRCUITPY_ATEXIT diff --git a/lib/utils/pyexec.h b/shared/runtime/pyexec.h similarity index 100% rename from lib/utils/pyexec.h rename to shared/runtime/pyexec.h diff --git a/lib/utils/semihosting.c b/shared/runtime/semihosting.c similarity index 100% rename from lib/utils/semihosting.c rename to shared/runtime/semihosting.c diff --git a/shared/runtime/semihosting.h b/shared/runtime/semihosting.h new file mode 100644 index 0000000000..d053a03eda --- /dev/null +++ b/shared/runtime/semihosting.h @@ -0,0 +1,51 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018 Ayke van Laethem + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ +#ifndef MICROPY_INCLUDED_LIB_UTILS_SEMIHOSTING_H +#define MICROPY_INCLUDED_LIB_UTILS_SEMIHOSTING_H + +/* + +To use semi-hosting for a replacement UART: +- Add lib/semihosting/semihosting.c to the Makefile sources. +- Call mp_semihosting_init() in main(), around the time UART is initialized. +- Replace mp_hal_stdin_rx_chr and similar in mphalport.c with the semihosting equivalent. +- Include lib/semihosting/semihosting.h in the relevant files. + +Then make sure the debugger is attached and enables semihosting. In OpenOCD this is +done with ARM semihosting enable followed by reset. The terminal will need further +configuration to work with MicroPython (bash: stty raw -echo). + +*/ + +#include +#include + +void mp_semihosting_init(); +int mp_semihosting_rx_char(); +uint32_t mp_semihosting_tx_strn(const char *str, size_t len); +uint32_t mp_semihosting_tx_strn_cooked(const char *str, size_t len); + +#endif // MICROPY_INCLUDED_LIB_UTILS_SEMIHOSTING_H diff --git a/lib/utils/stdout_helpers.c b/shared/runtime/stdout_helpers.c similarity index 100% rename from lib/utils/stdout_helpers.c rename to shared/runtime/stdout_helpers.c diff --git a/lib/utils/sys_stdio_mphal.c b/shared/runtime/sys_stdio_mphal.c similarity index 100% rename from lib/utils/sys_stdio_mphal.c rename to shared/runtime/sys_stdio_mphal.c diff --git a/lib/timeutils/timeutils.c b/shared/timeutils/timeutils.c similarity index 95% rename from lib/timeutils/timeutils.c rename to shared/timeutils/timeutils.c index e77daeb707..d1a10a4c93 100644 --- a/lib/timeutils/timeutils.c +++ b/shared/timeutils/timeutils.c @@ -27,7 +27,7 @@ #include "py/obj.h" -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" // LEAPOCH corresponds to 2000-03-01, which is a mod-400 year, immediately // after Feb 29. We calculate seconds as a signed integer relative to that. @@ -213,3 +213,10 @@ mp_uint_t timeutils_mktime_2000(mp_uint_t year, mp_int_t month, mp_int_t mday, } return timeutils_seconds_since_2000(year, month, mday, hours, minutes, seconds); } + +// Calculate the weekday from the date. +// The result is zero based with 0 = Monday. +// by Michael Keith and Tom Craver, 1990. +int timeutils_calc_weekday(int y, int m, int d) { + return ((d += m < 3 ? y-- : y - 2, 23 * m / 9 + d + 4 + y / 4 - y / 100 + y / 400) + 6) % 7; +} diff --git a/lib/timeutils/timeutils.h b/shared/timeutils/timeutils.h similarity index 98% rename from lib/timeutils/timeutils.h rename to shared/timeutils/timeutils.h index ac93e108a3..bfed13d3a4 100644 --- a/lib/timeutils/timeutils.h +++ b/shared/timeutils/timeutils.h @@ -100,4 +100,6 @@ static inline int64_t timeutils_nanoseconds_since_epoch_to_nanoseconds_since_197 #endif +int timeutils_calc_weekday(int y, int m, int d); + #endif // MICROPY_INCLUDED_LIB_TIMEUTILS_TIMEUTILS_H diff --git a/lib/upytesthelper/upytesthelper.c b/shared/upytesthelper/upytesthelper.c similarity index 100% rename from lib/upytesthelper/upytesthelper.c rename to shared/upytesthelper/upytesthelper.c diff --git a/lib/upytesthelper/upytesthelper.h b/shared/upytesthelper/upytesthelper.h similarity index 100% rename from lib/upytesthelper/upytesthelper.h rename to shared/upytesthelper/upytesthelper.h diff --git a/supervisor/shared/bluetooth/file_transfer.c b/supervisor/shared/bluetooth/file_transfer.c index 03806ca5e1..de05c7fbf9 100644 --- a/supervisor/shared/bluetooth/file_transfer.c +++ b/supervisor/shared/bluetooth/file_transfer.c @@ -28,7 +28,7 @@ #include "extmod/vfs.h" #include "extmod/vfs_fat.h" -#include "lib/timeutils/timeutils.h" +#include "shared/timeutils/timeutils.h" #include "shared-bindings/_bleio/__init__.h" #include "shared-bindings/_bleio/Adapter.h" diff --git a/supervisor/shared/flash.c b/supervisor/shared/flash.c index 0e5dd0f200..bc7c1876dc 100644 --- a/supervisor/shared/flash.c +++ b/supervisor/shared/flash.c @@ -38,9 +38,9 @@ const mp_obj_type_t supervisor_flash_type; STATIC const mp_obj_base_t supervisor_flash_obj = {&supervisor_flash_type}; -STATIC mp_obj_t supervisor_flash_obj_make_new(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args) { +STATIC mp_obj_t supervisor_flash_obj_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // check arguments - mp_arg_check_num(n_args, kw_args, 0, 0, false); + mp_arg_check_num(n_args, n_kw, 0, 0, false); // return singleton object return (mp_obj_t)&supervisor_flash_obj; diff --git a/supervisor/shared/safe_mode.c b/supervisor/shared/safe_mode.c index 646467ce39..59b5ab838d 100644 --- a/supervisor/shared/safe_mode.c +++ b/supervisor/shared/safe_mode.c @@ -169,6 +169,9 @@ void print_safe_mode_message(safe_mode_t reason) { case USB_TOO_MANY_INTERFACE_NAMES: message = translate("USB devices specify too many interface names."); break; + case USB_BOOT_DEVICE_NOT_INTERFACE_ZERO: + message = translate("Boot device must be first device (interface #0)."); + break; case WATCHDOG_RESET: message = translate("Watchdog timer expired."); break; diff --git a/supervisor/shared/safe_mode.h b/supervisor/shared/safe_mode.h index 01aed37d63..600abd7672 100644 --- a/supervisor/shared/safe_mode.h +++ b/supervisor/shared/safe_mode.h @@ -46,6 +46,7 @@ typedef enum { WATCHDOG_RESET, USB_TOO_MANY_ENDPOINTS, USB_TOO_MANY_INTERFACE_NAMES, + USB_BOOT_DEVICE_NOT_INTERFACE_ZERO, NO_HEAP, } safe_mode_t; diff --git a/supervisor/shared/status_leds.h b/supervisor/shared/status_leds.h index 4a55922845..f41ff71c68 100644 --- a/supervisor/shared/status_leds.h +++ b/supervisor/shared/status_leds.h @@ -30,7 +30,7 @@ #include #include -#include "lib/utils/pyexec.h" +#include "shared/runtime/pyexec.h" #include "supervisor/port.h" #include "py/mpconfig.h" diff --git a/supervisor/shared/tick.c b/supervisor/shared/tick.c index 397151ccc8..4ce884d7e1 100644 --- a/supervisor/shared/tick.c +++ b/supervisor/shared/tick.c @@ -26,7 +26,7 @@ #include "supervisor/shared/tick.h" -#include "lib/utils/interrupt_char.h" +#include "shared/runtime/interrupt_char.h" #include "py/mpstate.h" #include "py/runtime.h" #include "supervisor/linker.h" diff --git a/supervisor/shared/usb/usb.c b/supervisor/shared/usb/usb.c index 9a8b6cd1b6..815773fa2c 100644 --- a/supervisor/shared/usb/usb.c +++ b/supervisor/shared/usb/usb.c @@ -32,8 +32,8 @@ #include "supervisor/serial.h" #include "supervisor/usb.h" #include "supervisor/shared/workflow.h" -#include "lib/utils/interrupt_char.h" -#include "lib/mp-readline/readline.h" +#include "shared/runtime/interrupt_char.h" +#include "shared/readline/readline.h" #if CIRCUITPY_STORAGE #include "shared-module/storage/__init__.h" @@ -300,7 +300,7 @@ bool tud_vendor_control_xfer_cb(uint8_t rhport, uint8_t stage, tusb_control_requ // Only called when console is enabled. void tud_cdc_rx_wanted_cb(uint8_t itf, char wanted_char) { - // Workaround for using lib/utils/interrupt_char.c + // Workaround for using shared/runtime/interrupt_char.c // Compare mp_interrupt_char with wanted_char and ignore if not matched if (mp_interrupt_char == wanted_char) { tud_cdc_n_read_flush(itf); // flush read fifo diff --git a/supervisor/shared/usb/usb_desc.c b/supervisor/shared/usb/usb_desc.c index 6a0b7ab851..9fe1eadd4e 100644 --- a/supervisor/shared/usb/usb_desc.c +++ b/supervisor/shared/usb/usb_desc.c @@ -228,9 +228,14 @@ static void usb_build_configuration_descriptor(void) { #if CIRCUITPY_USB_HID if (usb_hid_enabled()) { + if (usb_hid_boot_device() > 0 && descriptor_counts.current_interface > 0) { + // Hosts using boot devices generally to expect them to be at interface zero, + // and will not work properly otherwise. + reset_into_safe_mode(USB_BOOT_DEVICE_NOT_INTERFACE_ZERO); + } descriptor_buf_remaining += usb_hid_add_descriptor( descriptor_buf_remaining, &descriptor_counts, ¤t_interface_string, - usb_hid_report_descriptor_length()); + usb_hid_report_descriptor_length(), usb_hid_boot_device()); } #endif diff --git a/supervisor/supervisor.mk b/supervisor/supervisor.mk index 7484c56092..6789ab32ea 100644 --- a/supervisor/supervisor.mk +++ b/supervisor/supervisor.mk @@ -65,7 +65,7 @@ else $(HEADER_BUILD)/devices.h : ../../supervisor/shared/external_flash/devices.h.jinja ../../tools/gen_nvm_devices.py | $(HEADER_BUILD) $(STEPECHO) "GEN $@" $(Q)install -d $(BUILD)/genhdr - $(Q)$(PYTHON3) ../../tools/gen_nvm_devices.py $< $@ + $(Q)$(PYTHON) ../../tools/gen_nvm_devices.py $< $@ $(BUILD)/supervisor/shared/external_flash/external_flash.o: $(HEADER_BUILD)/devices.h @@ -185,7 +185,7 @@ CIRCUITPY_DISPLAY_FONT ?= "../../tools/fonts/ter-u12n.bdf" $(BUILD)/autogen_display_resources.c: ../../tools/gen_display_resources.py $(HEADER_BUILD)/qstrdefs.generated.h Makefile | $(HEADER_BUILD) $(STEPECHO) "GEN $@" $(Q)install -d $(BUILD)/genhdr - $(Q)$(PYTHON3) ../../tools/gen_display_resources.py \ + $(Q)$(PYTHON) ../../tools/gen_display_resources.py \ --font $(CIRCUITPY_DISPLAY_FONT) \ --sample_file $(HEADER_BUILD)/qstrdefs.generated.h \ --output_c_file $(BUILD)/autogen_display_resources.c diff --git a/tests/basics/errno1.py b/tests/basics/errno1.py index cef5326b4a..d9a895a972 100644 --- a/tests/basics/errno1.py +++ b/tests/basics/errno1.py @@ -11,10 +11,11 @@ print(type(uerrno.EIO)) # check that errors are rendered in a nice way msg = str(OSError(uerrno.EIO)) -print(msg[:7], msg[msg.find(']'):]) - -msg = str(OSError(uerrno.ENOBUFS)) -print(msg[:7], msg[msg.find(']'):]) +print(msg[:7], msg[-5:]) +msg = str(OSError(uerrno.EIO, "details")) +print(msg[:7], msg[-14:]) +msg = str(OSError(uerrno.EIO, "details", "more details")) +print(msg[:1], msg[-28:]) # check that unknown errno is still rendered print(str(OSError(9999))) diff --git a/tests/basics/errno1.py.exp b/tests/basics/errno1.py.exp index b550468985..ac3619161f 100644 --- a/tests/basics/errno1.py.exp +++ b/tests/basics/errno1.py.exp @@ -1,5 +1,6 @@ -[Errno ] Input/output error -[Errno ] ENOBUFS +[Errno error +[Errno error: details +( , 'details', 'more details') 9999 uerrno diff --git a/tests/basics/gen_yield_from_stopped.py b/tests/basics/gen_yield_from_stopped.py index 468679b615..82feefed08 100644 --- a/tests/basics/gen_yield_from_stopped.py +++ b/tests/basics/gen_yield_from_stopped.py @@ -16,3 +16,15 @@ try: next(run()) except StopIteration: print("StopIteration") + + +# Where "f" is a native generator +def run(): + print((yield from f)) + + +f = zip() +try: + next(run()) +except StopIteration: + print("StopIteration") diff --git a/tests/basics/stopiteration.py b/tests/basics/stopiteration.py new file mode 100644 index 0000000000..d4719c9bc3 --- /dev/null +++ b/tests/basics/stopiteration.py @@ -0,0 +1,63 @@ +# test StopIteration interaction with generators + +try: + enumerate, exec +except: + print("SKIP") + raise SystemExit + + +def get_stop_iter_arg(msg, code): + try: + exec(code) + print("FAIL") + except StopIteration as er: + print(msg, er.args) + + +class A: + def __iter__(self): + return self + + def __next__(self): + raise StopIteration(42) + + +class B: + def __getitem__(self, index): + # argument to StopIteration should get ignored + raise StopIteration(42) + + +def gen(x): + return x + yield + + +def gen2(x): + try: + yield + except ValueError: + pass + return x + + +get_stop_iter_arg("next", "next(A())") +get_stop_iter_arg("iter", "next(iter(B()))") +get_stop_iter_arg("enumerate", "next(enumerate(A()))") +get_stop_iter_arg("map", "next(map(lambda x:x, A()))") +get_stop_iter_arg("zip", "next(zip(A()))") +g = gen(None) +get_stop_iter_arg("generator0", "next(g)") +get_stop_iter_arg("generator1", "next(g)") +g = gen(42) +get_stop_iter_arg("generator0", "next(g)") +get_stop_iter_arg("generator1", "next(g)") +get_stop_iter_arg("send", "gen(None).send(None)") +get_stop_iter_arg("send", "gen(42).send(None)") +g = gen2(None) +next(g) +get_stop_iter_arg("throw", "g.throw(ValueError)") +g = gen2(42) +next(g) +get_stop_iter_arg("throw", "g.throw(ValueError)") diff --git a/tests/basics/string_fstring.py b/tests/basics/string_fstring.py new file mode 100644 index 0000000000..4f7225fcad --- /dev/null +++ b/tests/basics/string_fstring.py @@ -0,0 +1,51 @@ +def f(): + return 4 +def g(_): + return 5 +def h(): + return 6 + +print(f'no interpolation') +print(f"no interpolation") +print(f"""no interpolation""") + +x, y = 1, 2 +print(f'{x}') +print(f'{x:08x}') +print(f'a {x} b {y} c') +print(f'a {x:08x} b {y} c') + +print(f'a {"hello"} b') +print(f'a {f() + g("foo") + h()} b') + +def foo(a, b): + return f'{x}{y}{a}{b}' +print(foo(7, 8)) + +# PEP-0498 specifies that '\\' and '#' must be disallowed explicitly, whereas +# MicroPython relies on the syntax error as a result of the substitution. + +print(f"\\") +print(f'#') +try: + eval("f'{\}'") +except SyntaxError: + print('SyntaxError') +try: + eval("f'{#}'") +except SyntaxError: + print('SyntaxError') + + +# PEP-0498 specifies that handling of double braces '{{' or '}}' should +# behave like str.format. +print(f'{{}}') +print(f'{{{4*10}}}', '{40}') + +# A single closing brace, unlike str.format should raise a syntax error. +# MicroPython instead raises ValueError at runtime from the substitution. +try: + eval("f'{{}'") +except (ValueError, SyntaxError): + # MicroPython incorrectly raises ValueError here. + print('SyntaxError') diff --git a/tests/basics/string_fstring_debug.py b/tests/basics/string_fstring_debug.py new file mode 100644 index 0000000000..76a448ca06 --- /dev/null +++ b/tests/basics/string_fstring_debug.py @@ -0,0 +1,23 @@ +# test f-string debug feature {x=} + + +def f(): + return 4 + + +def g(_): + return 5 + + +def h(): + return 6 + + +x, y = 1, 2 +print(f"{x=}") +print(f"{x=:08x}") +print(f"a {x=} b {y} c") +print(f"a {x=:08x} b {y} c") + +print(f'a {f() + g("foo") + h()=} b') +print(f'a {f() + g("foo") + h()=:08x} b') diff --git a/tests/basics/string_fstring_debug.py.exp b/tests/basics/string_fstring_debug.py.exp new file mode 100644 index 0000000000..563030f400 --- /dev/null +++ b/tests/basics/string_fstring_debug.py.exp @@ -0,0 +1,6 @@ +x=1 +x=00000001 +a x=1 b 2 c +a x=00000001 b 2 c +a f() + g("foo") + h()=15 b +a f() + g("foo") + h()=0000000f b diff --git a/tests/basics/string_pep498_fstring.py b/tests/basics/string_pep498_fstring.py index c645a730c6..82a2ca38e4 100644 --- a/tests/basics/string_pep498_fstring.py +++ b/tests/basics/string_pep498_fstring.py @@ -103,7 +103,7 @@ assert f'result={foo()}' == 'result={result}'.format(result=foo()) x = 10 y = 'hi' -assert (f'h' f'i') == 'hi' +#assert (f'h' f'i') == 'hi' #assert (f'h' 'i') == 'hi' #assert ('h' f'i') == 'hi' assert f'{x:^4}' == ' 10 ' diff --git a/tests/basics/subclass_native3.py b/tests/basics/subclass_native3.py index ac5aabfed7..0c45c4924f 100644 --- a/tests/basics/subclass_native3.py +++ b/tests/basics/subclass_native3.py @@ -34,6 +34,26 @@ print(MyStopIteration().value) print(MyStopIteration(1).value) +class Iter: + def __iter__(self): + return self + + def __next__(self): + # This exception will stop the "yield from", with a value of 3 + raise MyStopIteration(3) + + +def gen(): + print((yield from Iter())) + return 4 + + +try: + next(gen()) +except StopIteration as er: + print(er.args) + + class MyOSError(OSError): pass diff --git a/tests/basics/unary_op.py b/tests/basics/unary_op.py index bd78a20d0d..2239e2b206 100644 --- a/tests/basics/unary_op.py +++ b/tests/basics/unary_op.py @@ -23,5 +23,12 @@ print(not A()) # check user instances derived from builtins class B(int): pass print(not B()) +print(True if B() else False) class C(list): pass print(not C()) +print(True if C() else False) +# type doesn't define unary_op +class D(type): pass +d = D("foo", (), {}) +print(not d) +print(True if d else False) diff --git a/tests/cmdline/cmd_parsetree.py b/tests/cmdline/cmd_parsetree.py index 50da369543..483ea89373 100644 --- a/tests/cmdline/cmd_parsetree.py +++ b/tests/cmdline/cmd_parsetree.py @@ -10,3 +10,4 @@ d = b"bytes" e = b"a very long bytes that will not be interned" f = 123456789012345678901234567890 g = 123 +h = f"fstring: '{b}'" diff --git a/tests/cmdline/cmd_parsetree.py.exp b/tests/cmdline/cmd_parsetree.py.exp index abf547bc03..cc8ba82c05 100644 --- a/tests/cmdline/cmd_parsetree.py.exp +++ b/tests/cmdline/cmd_parsetree.py.exp @@ -1,6 +1,6 @@ ---------------- -[ 4] \(rule\|file_input_2\)(1) (n=9) - tok(10) +[ 4] \(rule\|file_input_2\)(1) (n=10) + tok(6) [ 4] \(rule\|for_stmt\)(22) (n=4) id(i) [ 4] \(rule\|atom_paren\)(45) (n=1) @@ -9,7 +9,7 @@ NULL [ 6] \(rule\|expr_stmt\)(5) (n=2) id(a) - tok(20) + tok(16) [ 7] \(rule\|expr_stmt\)(5) (n=2) id(b) str(str) @@ -28,6 +28,16 @@ [ 12] \(rule\|expr_stmt\)(5) (n=2) id(g) int(123) +[ 13] \(rule\|expr_stmt\)(5) (n=2) + id(h) +[ 13] \(rule\|atom_expr_normal\)(44) (n=2) +[ 13] literal const(\.\+) +[ 13] \(rule\|atom_expr_trailers\)(142) (n=2) +[ 13] \(rule\|trailer_period\)(50) (n=1) + id(format) +[ 13] \(rule\|trailer_paren\)(48) (n=1) +[ 13] \(rule\|arglist\)(164) (n=1) + id(b) ---------------- File cmdline/cmd_parsetree.py, code block '' (descriptor: \.\+, bytecode @\.\+ bytes) Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+): @@ -46,6 +56,7 @@ arg names: bc=32 line=10 bc=37 line=11 bc=42 line=12 + bc=48 line=13 00 BUILD_TUPLE 0 02 GET_ITER_STACK 03 FOR_ITER 12 @@ -65,8 +76,13 @@ arg names: 39 STORE_NAME f 42 LOAD_CONST_SMALL_INT 123 45 STORE_NAME g -48 LOAD_CONST_NONE -49 RETURN_VALUE +48 LOAD_CONST_OBJ \.\+ +50 LOAD_METHOD format +53 LOAD_NAME b (cache=0) +57 CALL_METHOD n=1 nkw=0 +59 STORE_NAME h +62 LOAD_CONST_NONE +63 RETURN_VALUE mem: total=\\d\+, current=\\d\+, peak=\\d\+ stack: \\d\+ out of \\d\+ GC: total: \\d\+, used: \\d\+, free: \\d\+ diff --git a/tests/cpydiff/core_fstring_concat.py b/tests/cpydiff/core_fstring_concat.py new file mode 100644 index 0000000000..fd83527b5c --- /dev/null +++ b/tests/cpydiff/core_fstring_concat.py @@ -0,0 +1,12 @@ +""" +categories: Core +description: f-strings don't support concatenation with adjacent literals if the adjacent literals contain braces +cause: MicroPython is optimised for code space. +workaround: Use the + operator between literal strings when either is an f-string +""" + +x = 1 +print("aa" f"{x}") +print(f"{x}" "ab") +print("a{}a" f"{x}") +print(f"{x}" "a{}b") diff --git a/tests/cpydiff/core_fstring_parser.py b/tests/cpydiff/core_fstring_parser.py new file mode 100644 index 0000000000..6917f3cfa4 --- /dev/null +++ b/tests/cpydiff/core_fstring_parser.py @@ -0,0 +1,9 @@ +""" +categories: Core +description: f-strings cannot support expressions that require parsing to resolve nested braces +cause: MicroPython is optimised for code space. +workaround: Only use simple expressions inside f-strings +""" + +f'{"hello {} world"}' +f"{repr({})}" diff --git a/tests/cpydiff/core_fstring_raw.py b/tests/cpydiff/core_fstring_raw.py new file mode 100644 index 0000000000..84e265f70f --- /dev/null +++ b/tests/cpydiff/core_fstring_raw.py @@ -0,0 +1,8 @@ +""" +categories: Core +description: Raw f-strings are not supported +cause: MicroPython is optimised for code space. +workaround: Unknown +""" + +rf"hello" diff --git a/tests/cpydiff/core_fstring_repr.py b/tests/cpydiff/core_fstring_repr.py new file mode 100644 index 0000000000..fcadcbf1b9 --- /dev/null +++ b/tests/cpydiff/core_fstring_repr.py @@ -0,0 +1,18 @@ +""" +categories: Core +description: f-strings don't support the !r, !s, and !a conversions +cause: MicroPython is optimised for code space. +workaround: Use repr(), str(), and ascii() explictly. +""" + + +class X: + def __repr__(self): + return "repr" + + def __str__(self): + return "str" + + +print(f"{X()!r}") +print(f"{X()!s}") diff --git a/tests/cpydiff/modules_struct_whitespace_in_format.py b/tests/cpydiff/modules_struct_whitespace_in_format.py new file mode 100644 index 0000000000..a882b38569 --- /dev/null +++ b/tests/cpydiff/modules_struct_whitespace_in_format.py @@ -0,0 +1,13 @@ +""" +categories: Modules,struct +description: Struct pack with whitespace in format, whitespace ignored by CPython, error on uPy +cause: MicroPython is optimised for code size. +workaround: Don't use spaces in format strings. +""" +import struct + +try: + print(struct.pack("b b", 1, 2)) + print("Should have worked") +except: + print("struct.error") diff --git a/tests/extmod/framebuf_palette.py b/tests/extmod/framebuf_palette.py new file mode 100644 index 0000000000..84db834c15 --- /dev/null +++ b/tests/extmod/framebuf_palette.py @@ -0,0 +1,35 @@ +# Test blit between different color spaces +try: + import framebuf, usys +except ImportError: + print("SKIP") + raise SystemExit + +# Monochrome glyph/icon +w = 8 +h = 8 +cbuf = bytearray(w * h // 8) +fbc = framebuf.FrameBuffer(cbuf, w, h, framebuf.MONO_HLSB) +fbc.line(0, 0, 7, 7, 1) + +# RGB565 destination +wd = 16 +hd = 16 +dest = bytearray(wd * hd * 2) +fbd = framebuf.FrameBuffer(dest, wd, hd, framebuf.RGB565) + +wp = 2 +bg = 0x1234 +fg = 0xF800 +pal = bytearray(wp * 2) +palette = framebuf.FrameBuffer(pal, wp, 1, framebuf.RGB565) +palette.pixel(0, 0, bg) +palette.pixel(1, 0, fg) + +fbd.blit(fbc, 0, 0, -1, palette) + +print(fbd.pixel(0, 0) == fg) +print(fbd.pixel(7, 7) == fg) +print(fbd.pixel(8, 8) == 0) # Ouside blit +print(fbd.pixel(0, 1) == bg) +print(fbd.pixel(1, 0) == bg) diff --git a/tests/extmod/framebuf_palette.py.exp b/tests/extmod/framebuf_palette.py.exp new file mode 100644 index 0000000000..2e883c51de --- /dev/null +++ b/tests/extmod/framebuf_palette.py.exp @@ -0,0 +1,5 @@ +True +True +True +True +True diff --git a/tests/extmod/uasyncio_heaplock.py b/tests/extmod/uasyncio_heaplock.py index 771d3f0d97..3a92d36c9f 100644 --- a/tests/extmod/uasyncio_heaplock.py +++ b/tests/extmod/uasyncio_heaplock.py @@ -29,15 +29,15 @@ async def task(id, n, t): async def main(): - t1 = asyncio.create_task(task(1, 4, 10)) - t2 = asyncio.create_task(task(2, 4, 25)) + t1 = asyncio.create_task(task(1, 4, 20)) + t2 = asyncio.create_task(task(2, 2, 50)) micropython.heap_lock() print("start") await asyncio.sleep_ms(1) print("sleep") - await asyncio.sleep_ms(100) + await asyncio.sleep_ms(70) print("finish") micropython.heap_unlock() diff --git a/tests/extmod/uasyncio_heaplock.py.exp b/tests/extmod/uasyncio_heaplock.py.exp index a967cc3197..68c6366c6f 100644 --- a/tests/extmod/uasyncio_heaplock.py.exp +++ b/tests/extmod/uasyncio_heaplock.py.exp @@ -6,6 +6,4 @@ sleep 1 2 2 1 1 3 -2 2 -2 3 finish diff --git a/tests/extmod/ujson_dump_separators.py b/tests/extmod/ujson_dump_separators.py new file mode 100644 index 0000000000..e19b99a26d --- /dev/null +++ b/tests/extmod/ujson_dump_separators.py @@ -0,0 +1,62 @@ +try: + from uio import StringIO + import ujson as json +except: + try: + from io import StringIO + import json + except ImportError: + print("SKIP") + raise SystemExit + +for sep in [ + None, + (", ", ": "), + (",", ": "), + (",", ":"), + [", ", ": "], + [",", ": "], + [",", ":"], +]: + s = StringIO() + json.dump(False, s, separators=sep) + print(s.getvalue()) + + s = StringIO() + json.dump({"a": (2, [3, None])}, s, separators=sep) + print(s.getvalue()) + + # dump to a small-int not allowed + try: + json.dump(123, 1, separators=sep) + except (AttributeError, OSError): # CPython and uPy have different errors + print("Exception") + + # dump to an object not allowed + try: + json.dump(123, {}, separators=sep) + except (AttributeError, OSError): # CPython and uPy have different errors + print("Exception") + + +try: + s = StringIO() + json.dump(False, s, separators={"a": 1}) +except (TypeError, ValueError): # CPython and uPy have different errors + print("Exception") + +# invalid separator types +for sep in [1, object()]: + try: + s = StringIO() + json.dump(False, s, separators=sep) + except TypeError: + print("Exception") + +# too many/ not enough separators +for sep in [(), (",", ":", "?"), (",",), []]: + try: + s = StringIO() + json.dump(False, s, separators=sep) + except ValueError: + print("Exception") diff --git a/tests/extmod/ujson_dumps_separators.py b/tests/extmod/ujson_dumps_separators.py new file mode 100644 index 0000000000..efb541fe8b --- /dev/null +++ b/tests/extmod/ujson_dumps_separators.py @@ -0,0 +1,60 @@ +try: + import ujson as json +except ImportError: + try: + import json + except ImportError: + print("SKIP") + raise SystemExit + +for sep in [ + None, + (", ", ": "), + (",", ": "), + (",", ":"), + [", ", ": "], + [",", ": "], + [",", ":"], +]: + print(json.dumps(False, separators=sep)) + print(json.dumps(True, separators=sep)) + print(json.dumps(None, separators=sep)) + print(json.dumps(1, separators=sep)) + print(json.dumps("abc", separators=sep)) + print(json.dumps("\x00\x01\x7e", separators=sep)) + print(json.dumps([], separators=sep)) + print(json.dumps([1], separators=sep)) + print(json.dumps([1, 2], separators=sep)) + print(json.dumps([1, True], separators=sep)) + print(json.dumps((), separators=sep)) + print(json.dumps((1,), separators=sep)) + print(json.dumps((1, 2), separators=sep)) + print(json.dumps((1, (2, 3)), separators=sep)) + print(json.dumps({}, separators=sep)) + print(json.dumps({"a": 1}, separators=sep)) + print(json.dumps({"a": (2, [3, None])}, separators=sep)) + print(json.dumps('"quoted"', separators=sep)) + print(json.dumps("space\n\r\tspace", separators=sep)) + print(json.dumps({None: -1}, separators=sep)) + print(json.dumps({False: 0}, separators=sep)) + print(json.dumps({True: 1}, separators=sep)) + print(json.dumps({1: 2}, separators=sep)) + +try: + json.dumps(False, separators={"a": 1}) +except (TypeError, ValueError): # CPython and uPy have different errors + print("Exception") + +# invalid separator types +for sep in [1, object()]: + try: + json.dumps(False, separators=sep) + except TypeError: + print("Exception") + +# too many/ not enough separators +for sep in [(), (",", ":", "?"), (",",), []]: + try: + json.dumps(False, separators=sep) + except ValueError: + print("Exception") diff --git a/tests/extmod/vfs_fat_finaliser.py b/tests/extmod/vfs_fat_finaliser.py index b4ec8f89d2..c2f5966963 100644 --- a/tests/extmod/vfs_fat_finaliser.py +++ b/tests/extmod/vfs_fat_finaliser.py @@ -56,6 +56,13 @@ micropython.heap_unlock() # Here we test that the finaliser is actually called during a garbage collection. import gc +# Do a large number of single-block allocations to move the GC head forwards, +# ensuring that the files are allocated from never-before-used blocks and +# therefore couldn't possibly have any references to them left behind on +# the stack. +for i in range(1024): + [] + N = 4 for i in range(N): n = "x%d" % i diff --git a/tests/feature_check/fstring.py b/tests/feature_check/fstring.py new file mode 100644 index 0000000000..14792bce0a --- /dev/null +++ b/tests/feature_check/fstring.py @@ -0,0 +1,3 @@ +# check whether f-strings (PEP-498) are supported +a = 1 +print(f"a={a}") diff --git a/tests/feature_check/fstring.py.exp b/tests/feature_check/fstring.py.exp new file mode 100644 index 0000000000..73cdb8bcc8 --- /dev/null +++ b/tests/feature_check/fstring.py.exp @@ -0,0 +1 @@ +a=1 diff --git a/tests/micropython/native_misc.py b/tests/micropython/native_misc.py index 7c5415375e..f5ef807fe1 100644 --- a/tests/micropython/native_misc.py +++ b/tests/micropython/native_misc.py @@ -38,3 +38,13 @@ def f(a): f(False) f(True) + + +# stack settling in branch +@micropython.native +def f(a): + print(1, 2, 3, 4 if a else 5) + + +f(False) +f(True) diff --git a/tests/micropython/native_misc.py.exp b/tests/micropython/native_misc.py.exp index b3e1389ef7..8eec04228f 100644 --- a/tests/micropython/native_misc.py.exp +++ b/tests/micropython/native_misc.py.exp @@ -4,3 +4,5 @@ 6 True False +1 2 3 5 +1 2 3 4 diff --git a/tests/pybnative/while.py b/tests/pybnative/while.py index 0f397dd377..10625e8717 100644 --- a/tests/pybnative/while.py +++ b/tests/pybnative/while.py @@ -1,4 +1,4 @@ -import pyb +import time, pyb @micropython.native @@ -8,7 +8,7 @@ def f(led, n, d): while i < n: print(i) led.toggle() - pyb.delay(d) + time.sleep_ms(d) i += 1 led.off() diff --git a/tests/run-multitests.py b/tests/run-multitests.py index b4afc1e526..34389e4292 100755 --- a/tests/run-multitests.py +++ b/tests/run-multitests.py @@ -46,6 +46,16 @@ class multitest: print("NEXT") multitest.flush() @staticmethod + def broadcast(msg): + print("BROADCAST", msg) + multitest.flush() + @staticmethod + def wait(msg): + msg = "BROADCAST " + msg + while True: + if sys.stdin.readline().rstrip() == msg: + return + @staticmethod def globals(**gs): for g in gs: print("SET {{}} = {{!r}}".format(g, gs[g])) @@ -126,14 +136,12 @@ class PyInstanceSubProcess(PyInstance): def start_script(self, script): self.popen = subprocess.Popen( - self.argv, + self.argv + ["-c", script], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, env=self.env, ) - self.popen.stdin.write(script) - self.popen.stdin.close() self.finished = False def stop(self): @@ -141,7 +149,7 @@ class PyInstanceSubProcess(PyInstance): self.popen.terminate() def readline(self): - sel = select.select([self.popen.stdout.raw], [], [], 0.1) + sel = select.select([self.popen.stdout.raw], [], [], 0.001) if not sel[0]: self.finished = self.popen.poll() is not None return None, None @@ -152,6 +160,10 @@ class PyInstanceSubProcess(PyInstance): else: return str(out.rstrip(), "ascii"), None + def write(self, data): + self.popen.stdin.write(data) + self.popen.stdin.flush() + def is_finished(self): return self.finished @@ -220,6 +232,9 @@ class PyInstancePyboard(PyInstance): err = None return str(out.rstrip(), "ascii"), err + def write(self, data): + self.pyb.serial.write(data) + def is_finished(self): return self.finished @@ -318,7 +333,12 @@ def run_test_on_instances(test_file, num_instances, instances): last_read_time[idx] = time.time() if out is not None and not any(m in out for m in IGNORE_OUTPUT_MATCHES): trace_instance_output(idx, out) - output[idx].append(out) + if out.startswith("BROADCAST "): + for instance2 in instances: + if instance2 is not instance: + instance2.write(bytes(out, "ascii") + b"\r\n") + else: + output[idx].append(out) if err is not None: trace_instance_output(idx, err) output[idx].append(err) diff --git a/tests/run-tests.py b/tests/run-tests.py index f33822cb9b..4315b5eaaf 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -299,6 +299,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): skip_const = False skip_revops = False skip_io_module = False + skip_fstring = False skip_endian = False has_complex = True has_coverage = False @@ -357,6 +358,11 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): if output != b"uio\n": skip_io_module = True + # Check if fstring feature is enabled, and skip such tests if it doesn't + output = run_feature_check(pyb, args, base_path, "fstring.py") + if output != b"a=1\n": + skip_fstring = True + # Check if emacs repl is supported, and skip such tests if it's not t = run_feature_check(pyb, args, base_path, "repl_emacs_check.py") if "True" not in str(t, "ascii"): @@ -552,6 +558,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): is_async = test_name.startswith(("async_", "uasyncio_")) is_const = test_name.startswith("const") is_io_module = test_name.startswith("io_") + is_fstring = test_name.startswith("string_fstring") skip_it = test_file in skip_tests skip_it |= skip_native and is_native @@ -564,6 +571,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): skip_it |= skip_const and is_const skip_it |= skip_revops and "reverse_op" in test_name skip_it |= skip_io_module and is_io_module + skip_it |= skip_fstring and is_fstring if args.list_tests: if not skip_it: diff --git a/tools/codeformat.py b/tools/codeformat.py index 863c27fdf5..1a7ea14c09 100644 --- a/tools/codeformat.py +++ b/tools/codeformat.py @@ -41,9 +41,9 @@ PATHS = [ "devices/**/*.[ch]", "drivers/bus/*.[ch]", "extmod/*.[ch]", - "lib/netutils/*.[ch]", - "lib/timeutils/*.[ch]", - "lib/utils/*.[ch]", + "shared/netutils/*.[ch]", + "shared/timeutils/*.[ch]", + "shared/runtime/*.[ch]", "mpy-cross/**/*.[ch]", "ports/**/*.[ch]", "py/**/*.[ch]", diff --git a/tools/gc_activity.md b/tools/gc_activity.md index 686d9b6b7b..b9fcb94188 100644 --- a/tools/gc_activity.md +++ b/tools/gc_activity.md @@ -45,7 +45,7 @@ main.c:298 main 5 blocks main.c:311 main 289 blocks main.c:211 start_mp 14 blocks main.c:196 maybe_run 14 blocks - ../lib/utils/pyexec.c:501 pyexec_file 14 blocks + ../shared/runtime/pyexec.c:501 pyexec_file 14 blocks main.c:352 mp_lexer_new_from_file 14 blocks ../py/../extmod/vfs_fat_lexer.c:80 fat_vfs_lexer_new_from_file 14 blocks ../py/qstr.c:184 qstr_from_str 14 blocks @@ -54,8 +54,8 @@ main.c:311 main 289 blocks ../py/qstr.c:146 qstr_add 6 blocks main.c:220 start_mp 275 blocks main.c:196 maybe_run 275 blocks - ../lib/utils/pyexec.c:508 pyexec_file 275 blocks - ../lib/utils/pyexec.c:82 parse_compile_execute 4 blocks + ../shared/runtime/pyexec.c:508 pyexec_file 275 blocks + ../shared/runtime/pyexec.c:82 parse_compile_execute 4 blocks ../py/compile.c:3511 mp_compile 3 blocks ../py/compile.c:3451 mp_compile_to_raw_code 3 blocks ../py/compile.c:3092 compile_scope 3 blocks @@ -63,7 +63,7 @@ main.c:311 main 289 blocks ../py/compile.c:3513 mp_compile 1 blocks ../py/emitglue.c:131 mp_make_function_from_raw_code 1 blocks ../py/objfun.c:364 mp_obj_new_fun_bc 1 blocks - ../lib/utils/pyexec.c:88 parse_compile_execute 271 blocks + ../shared/runtime/pyexec.c:88 parse_compile_execute 271 blocks ../py/runtime.c:551 mp_call_function_0 271 blocks ../py/runtime.c:577 mp_call_function_n_kw 271 blocks ../py/objfun.c:275 fun_bc_call 271 blocks @@ -185,7 +185,7 @@ main.c:311 main 289 blocks ../py/map.c:283 mp_map_lookup 2 blocks ../py/map.c:130 mp_map_rehash 2 blocks main.c:321 main 2 blocks - ../lib/utils/pyexec.c:374 pyexec_friendly_repl 2 blocks + ../shared/runtime/pyexec.c:374 pyexec_friendly_repl 2 blocks ../py/vstr.c:46 vstr_init 2 blocks 296 total blocks ``` diff --git a/tools/insert-usb-ids.py b/tools/insert-usb-ids.py index f63059ca1b..b0843ab3ee 100644 --- a/tools/insert-usb-ids.py +++ b/tools/insert-usb-ids.py @@ -12,6 +12,7 @@ import sys import re import string +config_prefix = "MICROPY_HW_USB_" needed_keys = ("USB_PID_CDC_MSC", "USB_PID_CDC_HID", "USB_PID_CDC", "USB_VID") @@ -20,10 +21,10 @@ def parse_usb_ids(filename): for line in open(filename).readlines(): line = line.rstrip("\r\n") match = re.match("^#define\s+(\w+)\s+\(0x([0-9A-Fa-f]+)\)$", line) - if match and match.group(1).startswith("USBD_"): - key = match.group(1).replace("USBD", "USB") + if match and match.group(1).startswith(config_prefix): + key = match.group(1).replace(config_prefix, "USB_") val = match.group(2) - print("key =", key, "val =", val) + # print("key =", key, "val =", val) if key in needed_keys: rv[key] = val for k in needed_keys: diff --git a/tools/makemanifest.py b/tools/makemanifest.py index 51de01dd8a..7897a83c6e 100644 --- a/tools/makemanifest.py +++ b/tools/makemanifest.py @@ -248,6 +248,7 @@ def main(): "-f", "--mpy-cross-flags", default="", help="flags to pass to mpy-cross" ) cmd_parser.add_argument("-v", "--var", action="append", help="variables to substitute") + cmd_parser.add_argument("--mpy-tool-flags", default="", help="flags to pass to mpy-tool") cmd_parser.add_argument("files", nargs="+", help="input manifest list") args = cmd_parser.parse_args() @@ -341,6 +342,7 @@ def main(): "-q", args.build_dir + "/genhdr/qstrdefs.preprocessed.h", ] + + args.mpy_tool_flags.split() + mpy_files ) if res != 0: diff --git a/tools/pyboard.py b/tools/pyboard.py index 3fca47b0b7..a43a4d0574 100755 --- a/tools/pyboard.py +++ b/tools/pyboard.py @@ -637,20 +637,40 @@ def main(): help="seconds to wait for USB connected board to become available", ) group = cmd_parser.add_mutually_exclusive_group() + group.add_argument( + "--soft-reset", + default=True, + action="store_true", + help="Whether to perform a soft reset when connecting to the board [default]", + ) + group.add_argument( + "--no-soft-reset", + action="store_false", + dest="soft_reset", + ) + group = cmd_parser.add_mutually_exclusive_group() group.add_argument( "--follow", action="store_true", + default=None, help="follow the output after running the scripts [default if no scripts given]", ) group.add_argument( "--no-follow", + action="store_false", + dest="follow", + ) + group = cmd_parser.add_mutually_exclusive_group() + group.add_argument( + "--exclusive", action="store_true", - help="Do not follow the output after running the scripts.", + default=True, + help="Open the serial device for exclusive access [default]", ) group.add_argument( "--no-exclusive", - action="store_true", - help="Do not try to open the serial device for exclusive access.", + action="store_false", + dest="exclusive", ) cmd_parser.add_argument( "-f", @@ -665,7 +685,7 @@ def main(): # open the connection to the pyboard try: pyb = Pyboard( - args.device, args.baudrate, args.user, args.password, args.wait, not args.no_exclusive + args.device, args.baudrate, args.user, args.password, args.wait, args.exclusive ) except PyboardError as er: print(er) @@ -676,7 +696,7 @@ def main(): # we must enter raw-REPL mode to execute commands # this will do a soft-reset of the board try: - pyb.enter_raw_repl() + pyb.enter_raw_repl(args.soft_reset) except PyboardError as er: print(er) pyb.close() @@ -684,13 +704,13 @@ def main(): def execbuffer(buf): try: - if args.no_follow: - pyb.exec_raw_no_follow(buf) - ret_err = None - else: + if args.follow is None or args.follow: ret, ret_err = pyb.exec_raw( buf, timeout=None, data_consumer=stdout_write_bytes ) + else: + pyb.exec_raw_no_follow(buf) + ret_err = None except PyboardError as er: print(er) pyb.close() diff --git a/tools/tinytest-codegen.py b/tools/tinytest-codegen.py index 2000c6a566..5c14bf2d5b 100755 --- a/tools/tinytest-codegen.py +++ b/tools/tinytest-codegen.py @@ -120,6 +120,9 @@ exclude_tests = ( "misc/sys_settrace_loop.py", "misc/sys_settrace_generator.py", "misc/sys_settrace_features.py", + # don't have f-string + "basics/string_fstring.py", + "basics/string_fstring_debug.py", ) output = [] diff --git a/tools/uncrustify.cfg b/tools/uncrustify.cfg index 80542b903e..88127112e8 100644 --- a/tools/uncrustify.cfg +++ b/tools/uncrustify.cfg @@ -1409,11 +1409,11 @@ nl_start_of_file = ignore # ignore/add/remove/force nl_start_of_file_min = 0 # unsigned number # Add or remove newline at the end of the file. -nl_end_of_file = ignore # ignore/add/remove/force +nl_end_of_file = force # ignore/add/remove/force # The minimum number of newlines at the end of the file (only used if # nl_end_of_file is 'add' or 'force'). -nl_end_of_file_min = 0 # unsigned number +nl_end_of_file_min = 1 # unsigned number # Add or remove newline between '=' and '{'. nl_assign_brace = ignore # ignore/add/remove/force