diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs index 690e5f46a4fc0..195e1e06eea46 100644 --- a/.git-blame-ignore-revs +++ b/.git-blame-ignore-revs @@ -1,3 +1,12 @@ +# all: Prune trailing whitespace. +dda9b9c6da5d3c31fa8769e581a753e95a270803 + +# all: Remove the "STATIC" macro and just use "static" instead. +decf8e6a8bb940d5829ca3296790631fcece7b21 + +# renesas-ra: Fix spelling mistakes found by codespell. +b3f2f18f927fa2fad10daf63d8c391331f5edf58 + # all: Update Python formatting to ruff-format. bbd8760bd9a2302e5abee29db279102bb11d7732 diff --git a/.github/workflows/run-tests.yml b/.github/workflows/run-tests.yml index 729be77979dee..80bfc72bd9812 100644 --- a/.github/workflows/run-tests.yml +++ b/.github/workflows/run-tests.yml @@ -53,15 +53,16 @@ jobs: run: ./run-tests.py -j4 --print-failures if: failure() working-directory: tests - - name: Build native modules - if: matrix.test == 'all' - run: | - make -C examples/natmod/features1 - make -C examples/natmod/features2 - make -C examples/natmod/heapq - make -C examples/natmod/random - make -C examples/natmod/re - - name: Test native modules - if: matrix.test == 'all' - run: ./run-natmodtests.py extmod/{heapq*,re*,zlib*}.py - working-directory: tests + # Not working after MicroPython v1.23 merge. + # - name: Build native modules + # if: matrix.test == 'all' + # run: | + # make -C examples/natmod/features1 + # make -C examples/natmod/features2 + # make -C examples/natmod/heapq + # make -C examples/natmod/random + # make -C examples/natmod/re + # - name: Test native modules + # if: matrix.test == 'all' + # run: ./run-natmodtests.py extmod/{heapq*,random*,re*}.py + # working-directory: tests diff --git a/.gitmodules b/.gitmodules index 0899ecaf5d929..cf0e554e26bad 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,7 +10,7 @@ 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 + url = https://github.com/micropython/berkeley-db-1.xx [submodule "tools/uf2"] path = tools/uf2 url = https://github.com/Microsoft/uf2.git diff --git a/LICENSE b/LICENSE index 4338915beb14a..a9ba6ea592670 100644 --- a/LICENSE +++ b/LICENSE @@ -22,7 +22,7 @@ THE SOFTWARE. -------------------------------------------------------------------------------- -#CIRCUITPY-CHANGE: +# CIRCUITPY-CHANGE: Unless specified otherwise (see below), the above license and copyright applies to all files derived from MicroPython in this repository. diff --git a/LICENSE_MicroPython b/LICENSE_MicroPython index 2b9a64b89a723..469ae1927396d 100644 --- a/LICENSE_MicroPython +++ b/LICENSE_MicroPython @@ -1,6 +1,6 @@ The MIT License (MIT) -Copyright (c) 2013-2022 Damien P. George +Copyright (c) 2013-2024 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 @@ -35,9 +35,7 @@ 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) @@ -50,24 +48,31 @@ used during the build process and is not part of the compiled source code. /cmsis (BSD-3-clause) /crypto-algorithms (NONE) /libhydrogen (ISC) + /libmetal (BSD-3-clause) /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) + /open-amp (BSD-3-clause) /pico-sdk (BSD-3-clause) /re15 (BSD-3-clause) /stm32lib (BSD-3-clause) /tinytest (BSD-3-clause) /tinyusb (MIT) /uzlib (Zlib) + /wiznet5k (MIT) /logo (uses OFL-1.1) /ports /cc3200 /hal (BSD-3-clause) /simplelink (BSD-3-clause) /FreeRTOS (GPL-2.0 with FreeRTOS exception) + /esp32 + /ppp_set_auth.* (Apache-2.0) + /rp2 + /mutex_extra.c (BSD-3-clause) /stm32 /usbd*.c (MCD-ST Liberty SW License Agreement V2) /stm32_it.* (MIT + BSD-3-clause) @@ -77,8 +82,6 @@ used during the build process and is not part of the compiled source code. /*/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 diff --git a/docs/README.md b/docs/README.md index 1ad4ca802e926..cddc45b03b311 100644 --- a/docs/README.md +++ b/docs/README.md @@ -1,4 +1,4 @@ -Adafruit's CircuitPython Documentation +Adafruit CircuitPython Documentation ========================= The latest documentation can be found at: diff --git a/docs/library/collections.rst b/docs/library/collections.rst index e400158c99cfd..b006a97dcaf22 100644 --- a/docs/library/collections.rst +++ b/docs/library/collections.rst @@ -31,35 +31,37 @@ Classes - *flag* is optional and can be set to 1 to check for overflow when adding items. If the deque is full and overflow checking is enabled, - an IndexError will be raised when adding items. + an ``IndexError`` will be raised when adding items. Deque objects have the following methods: .. method:: deque.append(x) Add *x* to the right side of the deque. - Raises IndexError if overflow checking is enabled and there is no more room left. + Raises ``IndexError`` if overflow checking is enabled and there is + no more room in the queue. .. method:: deque.appendleft(x) Add *x* to the left side of the deque. - Raises IndexError if overflow checking is enabled and there is no more room left. + Raises ``IndexError`` if overflow checking is enabled and there is + no more room in the queue. .. method:: deque.pop() Remove and return an item from the right side of the deque. - Raises IndexError if no items are present. + Raises ``IndexError`` if no items are present. .. method:: deque.popleft() Remove and return an item from the left side of the deque. - Raises IndexError if no items are present. + Raises ``IndexError`` if no items are present. .. method:: deque.extend(iterable) - Extend the right side of the deque by appending items from the *iterable* argument. + Extend the right side of the deque by appending items from the ``iterable`` argument. Raises IndexError if overflow checking is enabled and there is no more room left - for all of the items in *iterable*. + for all of the items in ``iterable``. In addition to the above, deques support iteration, ``bool``, ``len(d)``, ``reversed(d)``, membership testing with the ``in`` operator, and subscript references like ``d[0]``. diff --git a/docs/library/ctypes.rst b/docs/library/ctypes.rst deleted file mode 100644 index 803ddacdcef5e..0000000000000 --- a/docs/library/ctypes.rst +++ /dev/null @@ -1,325 +0,0 @@ -:mod:`uctypes` -- access binary data in a structured way -======================================================== - -.. module:: uctypes - :synopsis: access binary data in a structured way - -This module implements "foreign data interface" for MicroPython. The idea -behind it is similar to CPython's ``ctypes`` modules, but the actual API is -different, streamlined and optimized for small size. The basic idea of the -module is to define data structure layout with about the same power as the -C language allows, and then access it using familiar dot-syntax to reference -sub-fields. - -.. warning:: - - ``uctypes`` module allows access to arbitrary memory addresses of the - machine (including I/O and control registers). Uncareful usage of it - may lead to crashes, data loss, and even hardware malfunction. - -.. seealso:: - - Module :mod:`struct` - Standard Python way to access binary data structures (doesn't scale - well to large and complex structures). - -Usage examples:: - - import uctypes - - # Example 1: Subset of ELF file header - # https://wikipedia.org/wiki/Executable_and_Linkable_Format#File_header - ELF_HEADER = { - "EI_MAG": (0x0 | uctypes.ARRAY, 4 | uctypes.UINT8), - "EI_DATA": 0x5 | uctypes.UINT8, - "e_machine": 0x12 | uctypes.UINT16, - } - - # "f" is an ELF file opened in binary mode - buf = f.read(uctypes.sizeof(ELF_HEADER, uctypes.LITTLE_ENDIAN)) - header = uctypes.struct(uctypes.addressof(buf), ELF_HEADER, uctypes.LITTLE_ENDIAN) - assert header.EI_MAG == b"\x7fELF" - assert header.EI_DATA == 1, "Oops, wrong endianness. Could retry with uctypes.BIG_ENDIAN." - print("machine:", hex(header.e_machine)) - - - # Example 2: In-memory data structure, with pointers - COORD = { - "x": 0 | uctypes.FLOAT32, - "y": 4 | uctypes.FLOAT32, - } - - STRUCT1 = { - "data1": 0 | uctypes.UINT8, - "data2": 4 | uctypes.UINT32, - "ptr": (8 | uctypes.PTR, COORD), - } - - # Suppose you have address of a structure of type STRUCT1 in "addr" - # uctypes.NATIVE is optional (used by default) - struct1 = uctypes.struct(addr, STRUCT1, uctypes.NATIVE) - print("x:", struct1.ptr[0].x) - - - # Example 3: Access to CPU registers. Subset of STM32F4xx WWDG block - WWDG_LAYOUT = { - "WWDG_CR": (0, { - # BFUINT32 here means size of the WWDG_CR register - "WDGA": 7 << uctypes.BF_POS | 1 << uctypes.BF_LEN | uctypes.BFUINT32, - "T": 0 << uctypes.BF_POS | 7 << uctypes.BF_LEN | uctypes.BFUINT32, - }), - "WWDG_CFR": (4, { - "EWI": 9 << uctypes.BF_POS | 1 << uctypes.BF_LEN | uctypes.BFUINT32, - "WDGTB": 7 << uctypes.BF_POS | 2 << uctypes.BF_LEN | uctypes.BFUINT32, - "W": 0 << uctypes.BF_POS | 7 << uctypes.BF_LEN | uctypes.BFUINT32, - }), - } - - WWDG = uctypes.struct(0x40002c00, WWDG_LAYOUT) - - WWDG.WWDG_CFR.WDGTB = 0b10 - WWDG.WWDG_CR.WDGA = 1 - print("Current counter:", WWDG.WWDG_CR.T) - -Defining structure layout -------------------------- - -Structure layout is defined by a "descriptor" - a Python dictionary which -encodes field names as keys and other properties required to access them as -associated values:: - - { - "field1": , - "field2": , - ... - } - -Currently, ``uctypes`` requires explicit specification of offsets for each -field. Offset are given in bytes from the structure start. - -Following are encoding examples for various field types: - -* Scalar types:: - - "field_name": offset | uctypes.UINT32 - - in other words, the value is a scalar type identifier ORed with a field offset - (in bytes) from the start of the structure. - -* Recursive structures:: - - "sub": (offset, { - "b0": 0 | uctypes.UINT8, - "b1": 1 | uctypes.UINT8, - }) - - i.e. value is a 2-tuple, first element of which is an offset, and second is - a structure descriptor dictionary (note: offsets in recursive descriptors - are relative to the structure it defines). Of course, recursive structures - can be specified not just by a literal dictionary, but by referring to a - structure descriptor dictionary (defined earlier) by name. - -* Arrays of primitive types:: - - "arr": (offset | uctypes.ARRAY, size | uctypes.UINT8), - - i.e. value is a 2-tuple, first element of which is ARRAY flag ORed - with offset, and second is scalar element type ORed number of elements - in the array. - -* Arrays of aggregate types:: - - "arr2": (offset | uctypes.ARRAY, size, {"b": 0 | uctypes.UINT8}), - - i.e. value is a 3-tuple, first element of which is ARRAY flag ORed - with offset, second is a number of elements in the array, and third is - a descriptor of element type. - -* Pointer to a primitive type:: - - "ptr": (offset | uctypes.PTR, uctypes.UINT8), - - i.e. value is a 2-tuple, first element of which is PTR flag ORed - with offset, and second is a scalar element type. - -* Pointer to an aggregate type:: - - "ptr2": (offset | uctypes.PTR, {"b": 0 | uctypes.UINT8}), - - i.e. value is a 2-tuple, first element of which is PTR flag ORed - with offset, second is a descriptor of type pointed to. - -* Bitfields:: - - "bitf0": offset | uctypes.BFUINT16 | lsbit << uctypes.BF_POS | bitsize << uctypes.BF_LEN, - - i.e. value is a type of scalar value containing given bitfield (typenames are - similar to scalar types, but prefixes with ``BF``), ORed with offset for - scalar value containing the bitfield, and further ORed with values for - bit position and bit length of the bitfield within the scalar value, shifted by - BF_POS and BF_LEN bits, respectively. A bitfield position is counted - from the least significant bit of the scalar (having position of 0), and - is the number of right-most bit of a field (in other words, it's a number - of bits a scalar needs to be shifted right to extract the bitfield). - - In the example above, first a UINT16 value will be extracted at offset 0 - (this detail may be important when accessing hardware registers, where - particular access size and alignment are required), and then bitfield - whose rightmost bit is *lsbit* bit of this UINT16, and length - is *bitsize* bits, will be extracted. For example, if *lsbit* is 0 and - *bitsize* is 8, then effectively it will access least-significant byte - of UINT16. - - Note that bitfield operations are independent of target byte endianness, - in particular, example above will access least-significant byte of UINT16 - in both little- and big-endian structures. But it depends on the least - significant bit being numbered 0. Some targets may use different - numbering in their native ABI, but ``uctypes`` always uses the normalized - numbering described above. - -Module contents ---------------- - -.. class:: struct(addr, descriptor, layout_type=NATIVE, /) - - Instantiate a "foreign data structure" object based on structure address in - memory, descriptor (encoded as a dictionary), and layout type (see below). - -.. data:: LITTLE_ENDIAN - - Layout type for a little-endian packed structure. (Packed means that every - field occupies exactly as many bytes as defined in the descriptor, i.e. - the alignment is 1). - -.. data:: BIG_ENDIAN - - Layout type for a big-endian packed structure. - -.. data:: NATIVE - - Layout type for a native structure - with data endianness and alignment - conforming to the ABI of the system on which MicroPython runs. - -.. function:: sizeof(struct, layout_type=NATIVE, /) - - Return size of data structure in bytes. The *struct* argument can be - either a structure class or a specific instantiated structure object - (or its aggregate field). - -.. function:: addressof(obj) - - Return address of an object. Argument should be bytes, bytearray or - other object supporting buffer protocol (and address of this buffer - is what actually returned). - -.. function:: bytes_at(addr, size) - - Capture memory at the given address and size as bytes object. As bytes - object is immutable, memory is actually duplicated and copied into - bytes object, so if memory contents change later, created object - retains original value. - -.. function:: bytearray_at(addr, size) - - Capture memory at the given address and size as bytearray object. - Unlike bytes_at() function above, memory is captured by reference, - so it can be both written too, and you will access current value - at the given memory address. - -.. data:: UINT8 - INT8 - UINT16 - INT16 - UINT32 - INT32 - UINT64 - INT64 - - Integer types for structure descriptors. Constants for 8, 16, 32, - and 64 bit types are provided, both signed and unsigned. - -.. data:: FLOAT32 - FLOAT64 - - Floating-point types for structure descriptors. - -.. data:: VOID - - ``VOID`` is an alias for ``UINT8``, and is provided to conveniently define - C's void pointers: ``(uctypes.PTR, uctypes.VOID)``. - -.. data:: PTR - ARRAY - - Type constants for pointers and arrays. Note that there is no explicit - constant for structures, it's implicit: an aggregate type without ``PTR`` - or ``ARRAY`` flags is a structure. - -Structure descriptors and instantiating structure objects ---------------------------------------------------------- - -Given a structure descriptor dictionary and its layout type, you can -instantiate a specific structure instance at a given memory address -using :class:`uctypes.struct()` constructor. Memory address usually comes from -following sources: - -* Predefined address, when accessing hardware registers on a baremetal - system. Lookup these addresses in datasheet for a particular MCU/SoC. -* As a return value from a call to some FFI (Foreign Function Interface) - function. -* From `uctypes.addressof()`, when you want to pass arguments to an FFI - function, or alternatively, to access some data for I/O (for example, - data read from a file or network socket). - -Structure objects ------------------ - -Structure objects allow accessing individual fields using standard dot -notation: ``my_struct.substruct1.field1``. If a field is of scalar type, -getting it will produce a primitive value (Python integer or float) -corresponding to the value contained in a field. A scalar field can also -be assigned to. - -If a field is an array, its individual elements can be accessed with -the standard subscript operator ``[]`` - both read and assigned to. - -If a field is a pointer, it can be dereferenced using ``[0]`` syntax -(corresponding to C ``*`` operator, though ``[0]`` works in C too). -Subscripting a pointer with other integer values but 0 are also supported, -with the same semantics as in C. - -Summing up, accessing structure fields generally follows the C syntax, -except for pointer dereference, when you need to use ``[0]`` operator -instead of ``*``. - -Limitations ------------ - -1. Accessing non-scalar fields leads to allocation of intermediate objects -to represent them. This means that special care should be taken to -layout a structure which needs to be accessed when memory allocation -is disabled (e.g. from an interrupt). The recommendations are: - -* Avoid accessing nested structures. For example, instead of - ``mcu_registers.peripheral_a.register1``, define separate layout - descriptors for each peripheral, to be accessed as - ``peripheral_a.register1``. Or just cache a particular peripheral: - ``peripheral_a = mcu_registers.peripheral_a``. If a register - consists of multiple bitfields, you would need to cache references - to a particular register: ``reg_a = mcu_registers.peripheral_a.reg_a``. -* Avoid other non-scalar data, like arrays. For example, instead of - ``peripheral_a.register[0]`` use ``peripheral_a.register0``. Again, - an alternative is to cache intermediate values, e.g. - ``register0 = peripheral_a.register[0]``. - -2. Range of offsets supported by the ``uctypes`` module is limited. -The exact range supported is considered an implementation detail, -and the general suggestion is to split structure definitions to -cover from a few kilobytes to a few dozen of kilobytes maximum. -In most cases, this is a natural situation anyway, e.g. it doesn't make -sense to define all registers of an MCU (spread over 32-bit address -space) in one structure, but rather a peripheral block by peripheral -block. In some extreme cases, you may need to split a structure in -several parts artificially (e.g. if accessing native data structure -with multi-megabyte array in the middle, though that would be a very -synthetic case). diff --git a/docs/library/index.rst b/docs/library/index.rst index 3a06bc2cee323..18b2530a9b596 100644 --- a/docs/library/index.rst +++ b/docs/library/index.rst @@ -17,7 +17,7 @@ limited flash memory: ``binascii``, ``errno``, ``json``, ``re``. These libraries are not currently enabled in any CircuitPython build, but may be in the future: -``ctypes``, ``platform`` +``platform`` .. toctree:: :maxdepth: 1 @@ -34,7 +34,6 @@ These libraries are not currently enabled in any CircuitPython build, but may be platform.rst re.rst sys.rst - ctypes.rst select.rst Omitted ``string`` functions diff --git a/docs/library/sys.rst b/docs/library/sys.rst index 4e8c889eb0172..8def36a2b07a2 100644 --- a/docs/library/sys.rst +++ b/docs/library/sys.rst @@ -17,7 +17,7 @@ Functions .. function:: print_exception(exc, file=sys.stdout, /) - This function is being deprecated and will be removed starting in + This function is deprecated and will be removed starting in CircuitPython 10.x, `traceback.print_exception()` should be used instead. Print exception with a traceback to a file-like object *file* (or diff --git a/examples/natmod/deflate/deflate.c b/examples/natmod/deflate/deflate.c index fa475bd067240..9de7e101a7689 100644 --- a/examples/natmod/deflate/deflate.c +++ b/examples/natmod/deflate/deflate.c @@ -29,7 +29,7 @@ mp_obj_t mp_stream_close(mp_obj_t stream) { MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_close_obj, mp_stream_close); // Re-implemented from py/stream.c, not yet available in dynruntime.h. -STATIC mp_obj_t mp_stream___exit__(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_stream___exit__(size_t n_args, const mp_obj_t *args) { (void)n_args; return mp_stream_close(args[0]); } @@ -42,7 +42,7 @@ mp_obj_t mp_identity(mp_obj_t self) { MP_DEFINE_CONST_FUN_OBJ_1(mp_identity_obj, mp_identity); mp_map_elem_t deflateio_locals_dict_table[7]; -STATIC MP_DEFINE_CONST_DICT(deflateio_locals_dict, deflateio_locals_dict_table); +static MP_DEFINE_CONST_DICT(deflateio_locals_dict, deflateio_locals_dict_table); mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { MP_DYNRUNTIME_INIT_ENTRY diff --git a/examples/natmod/features0/features0.c b/examples/natmod/features0/features0.c index 1b1867a3bc935..c3d31afb79cb8 100644 --- a/examples/natmod/features0/features0.c +++ b/examples/natmod/features0/features0.c @@ -8,7 +8,7 @@ #include "py/dynruntime.h" // Helper function to compute factorial -STATIC mp_int_t factorial_helper(mp_int_t x) { +static mp_int_t factorial_helper(mp_int_t x) { if (x == 0) { return 1; } @@ -16,7 +16,7 @@ STATIC mp_int_t factorial_helper(mp_int_t x) { } // This is the function which will be called from Python, as factorial(x) -STATIC mp_obj_t factorial(mp_obj_t x_obj) { +static mp_obj_t factorial(mp_obj_t x_obj) { // Extract the integer from the MicroPython input object mp_int_t x = mp_obj_get_int(x_obj); // Calculate the factorial @@ -25,7 +25,7 @@ STATIC mp_obj_t factorial(mp_obj_t x_obj) { return mp_obj_new_int(result); } // Define a Python reference to the function above -STATIC MP_DEFINE_CONST_FUN_OBJ_1(factorial_obj, factorial); +static MP_DEFINE_CONST_FUN_OBJ_1(factorial_obj, factorial); // This is the entry point and is called when the module is imported mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { diff --git a/examples/natmod/features1/features1.c b/examples/natmod/features1/features1.c index d2494b2138865..92b96dbb18351 100644 --- a/examples/natmod/features1/features1.c +++ b/examples/natmod/features1/features1.c @@ -25,15 +25,15 @@ uint16_t *const table_ptr16a[] = { &data16[0], &data16[1], &data16[2], &data16[3 const uint16_t *const table_ptr16b[] = { &table16[0], &table16[1] }; // A simple function that adds its 2 arguments (must be integers) -STATIC mp_obj_t add(mp_obj_t x_in, mp_obj_t y_in) { +static mp_obj_t add(mp_obj_t x_in, mp_obj_t y_in) { mp_int_t x = mp_obj_get_int(x_in); mp_int_t y = mp_obj_get_int(y_in); return mp_obj_new_int(x + y); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(add_obj, add); +static MP_DEFINE_CONST_FUN_OBJ_2(add_obj, add); // A local helper function (not exposed to Python) -STATIC mp_int_t fibonacci_helper(mp_int_t x) { +static mp_int_t fibonacci_helper(mp_int_t x) { if (x < MP_ARRAY_SIZE(table8)) { return table8[x]; } else { @@ -42,17 +42,17 @@ STATIC mp_int_t fibonacci_helper(mp_int_t x) { } // A function which computes Fibonacci numbers -STATIC mp_obj_t fibonacci(mp_obj_t x_in) { +static mp_obj_t fibonacci(mp_obj_t x_in) { mp_int_t x = mp_obj_get_int(x_in); if (x < 0) { mp_raise_ValueError(MP_ERROR_TEXT("can't compute negative Fibonacci number")); } return mp_obj_new_int(fibonacci_helper(x)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(fibonacci_obj, fibonacci); +static MP_DEFINE_CONST_FUN_OBJ_1(fibonacci_obj, fibonacci); // A function that accesses the BSS data -STATIC mp_obj_t access(size_t n_args, const mp_obj_t *args) { +static mp_obj_t access(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { // Create a list holding all items from data16 mp_obj_list_t *lst = MP_OBJ_TO_PTR(mp_obj_new_list(MP_ARRAY_SIZE(data16), NULL)); @@ -71,17 +71,17 @@ STATIC mp_obj_t access(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(access_obj, 0, 2, access); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(access_obj, 0, 2, access); // A function that allocates memory and creates a bytearray -STATIC mp_obj_t make_array(void) { +static mp_obj_t make_array(void) { uint16_t *ptr = m_new(uint16_t, MP_ARRAY_SIZE(table_ptr16b)); for (int i = 0; i < MP_ARRAY_SIZE(table_ptr16b); ++i) { ptr[i] = *table_ptr16b[i]; } return mp_obj_new_bytearray_by_ref(sizeof(uint16_t) * MP_ARRAY_SIZE(table_ptr16b), ptr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(make_array_obj, make_array); +static MP_DEFINE_CONST_FUN_OBJ_0(make_array_obj, make_array); // This is the entry point and is called when the module is imported mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { diff --git a/examples/natmod/features2/main.c b/examples/natmod/features2/main.c index 1a39700dc4b71..22961aa494f5f 100644 --- a/examples/natmod/features2/main.c +++ b/examples/natmod/features2/main.c @@ -22,29 +22,29 @@ // A function that uses the default float type configured for the current target // This default can be overridden by specifying MICROPY_FLOAT_IMPL at the make level -STATIC mp_obj_t add(mp_obj_t x, mp_obj_t y) { +static mp_obj_t add(mp_obj_t x, mp_obj_t y) { return mp_obj_new_float(mp_obj_get_float(x) + mp_obj_get_float(y)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(add_obj, add); +static MP_DEFINE_CONST_FUN_OBJ_2(add_obj, add); // A function that explicitly uses single precision floats -STATIC mp_obj_t add_f(mp_obj_t x, mp_obj_t y) { +static mp_obj_t add_f(mp_obj_t x, mp_obj_t y) { return mp_obj_new_float_from_f(mp_obj_get_float_to_f(x) + mp_obj_get_float_to_f(y)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(add_f_obj, add_f); +static MP_DEFINE_CONST_FUN_OBJ_2(add_f_obj, add_f); #if USE_DOUBLE // A function that explicitly uses double precision floats -STATIC mp_obj_t add_d(mp_obj_t x, mp_obj_t y) { +static mp_obj_t add_d(mp_obj_t x, mp_obj_t y) { return mp_obj_new_float_from_d(mp_obj_get_float_to_d(x) + mp_obj_get_float_to_d(y)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(add_d_obj, add_d); +static MP_DEFINE_CONST_FUN_OBJ_2(add_d_obj, add_d); #endif // A function that computes the product of floats in an array. // This function uses the most general C argument interface, which is more difficult // 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) { +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(n_args, n_kw, 1, 1, false); diff --git a/examples/natmod/features3/features3.c b/examples/natmod/features3/features3.c index 20efd67cdcefd..1d3bc51e609d1 100644 --- a/examples/natmod/features3/features3.c +++ b/examples/natmod/features3/features3.c @@ -8,7 +8,7 @@ #include "py/dynruntime.h" // A function that returns a tuple of object types. -STATIC mp_obj_t get_types(void) { +static mp_obj_t get_types(void) { return mp_obj_new_tuple(9, ((mp_obj_t []) { MP_OBJ_FROM_PTR(&mp_type_type), MP_OBJ_FROM_PTR(&mp_type_NoneType), @@ -21,10 +21,10 @@ STATIC mp_obj_t get_types(void) { MP_OBJ_FROM_PTR(&mp_type_dict), })); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(get_types_obj, get_types); +static MP_DEFINE_CONST_FUN_OBJ_0(get_types_obj, get_types); // A function that returns a tuple of constant objects. -STATIC mp_obj_t get_const_objects(void) { +static mp_obj_t get_const_objects(void) { return mp_obj_new_tuple(5, ((mp_obj_t []) { mp_const_none, mp_const_false, @@ -33,17 +33,17 @@ STATIC mp_obj_t get_const_objects(void) { mp_const_empty_tuple, })); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(get_const_objects_obj, get_const_objects); +static MP_DEFINE_CONST_FUN_OBJ_0(get_const_objects_obj, get_const_objects); // A function that creates a dictionary from the given arguments. -STATIC mp_obj_t make_dict(size_t n_args, const mp_obj_t *args) { +static mp_obj_t make_dict(size_t n_args, const mp_obj_t *args) { mp_obj_t dict = mp_obj_new_dict(n_args / 2); for (; n_args >= 2; n_args -= 2, args += 2) { mp_obj_dict_store(dict, args[0], args[1]); } return dict; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(make_dict_obj, 0, MP_OBJ_FUN_ARGS_MAX, make_dict); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(make_dict_obj, 0, MP_OBJ_FUN_ARGS_MAX, make_dict); // This is the entry point and is called when the module is imported. mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { diff --git a/examples/natmod/features4/features4.c b/examples/natmod/features4/features4.c index 336f4ecf64080..e64c7f759213c 100644 --- a/examples/natmod/features4/features4.c +++ b/examples/natmod/features4/features4.c @@ -1,5 +1,6 @@ /* - This example extends on features0 but demonstrates how to define a class. + This example extends on features0 but demonstrates how to define a class, + and a custom exception. The Factorial class constructor takes an integer, and then the calculate method can be called to get the factorial. @@ -8,6 +9,9 @@ >>> f = features4.Factorial(4) >>> f.calculate() 24 + + If the argument to the Factorial class constructor is less than zero, a + FactorialError is raised. */ // Include the header file to get access to the MicroPython API @@ -22,18 +26,24 @@ typedef struct { mp_int_t n; } mp_obj_factorial_t; +mp_obj_full_type_t mp_type_FactorialError; + // Essentially Factorial.__new__ (but also kind of __init__). // Takes a single argument (the number to find the factorial of) -STATIC mp_obj_t factorial_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args_in) { +static mp_obj_t factorial_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args_in) { mp_arg_check_num(n_args, n_kw, 1, 1, false); mp_obj_factorial_t *o = mp_obj_malloc(mp_obj_factorial_t, type); o->n = mp_obj_get_int(args_in[0]); + if (o->n < 0) { + mp_raise_msg((mp_obj_type_t *)&mp_type_FactorialError, "argument must be zero or above"); + } + return MP_OBJ_FROM_PTR(o); } -STATIC mp_int_t factorial_helper(mp_int_t x) { +static mp_int_t factorial_helper(mp_int_t x) { if (x == 0) { return 1; } @@ -41,16 +51,16 @@ STATIC mp_int_t factorial_helper(mp_int_t x) { } // Implements Factorial.calculate() -STATIC mp_obj_t factorial_calculate(mp_obj_t self_in) { +static mp_obj_t factorial_calculate(mp_obj_t self_in) { mp_obj_factorial_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_int(factorial_helper(self->n)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(factorial_calculate_obj, factorial_calculate); +static MP_DEFINE_CONST_FUN_OBJ_1(factorial_calculate_obj, factorial_calculate); // Locals dict for the Factorial type (will have a single method, calculate, // added in mpy_init). mp_map_elem_t factorial_locals_dict_table[1]; -STATIC MP_DEFINE_CONST_DICT(factorial_locals_dict, factorial_locals_dict_table); +static MP_DEFINE_CONST_DICT(factorial_locals_dict, factorial_locals_dict_table); // This is the entry point and is called when the module is imported mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { @@ -68,6 +78,12 @@ mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *a // Make the Factorial type available on the module. mp_store_global(MP_QSTR_Factorial, MP_OBJ_FROM_PTR(&mp_type_factorial)); + // Initialise the exception type. + mp_obj_exception_init(&mp_type_FactorialError, MP_QSTR_FactorialError, &mp_type_Exception); + + // Make the FactorialError type available on the module. + mp_store_global(MP_QSTR_FactorialError, MP_OBJ_FROM_PTR(&mp_type_FactorialError)); + // This must be last, it restores the globals dict MP_DYNRUNTIME_INIT_EXIT } diff --git a/examples/natmod/re/re.c b/examples/natmod/re/re.c index df89ea83530ec..7ae72a578f4e3 100644 --- a/examples/natmod/re/re.c +++ b/examples/natmod/re/re.c @@ -38,10 +38,10 @@ mp_obj_full_type_t re_type; #include "extmod/modre.c" mp_map_elem_t match_locals_dict_table[5]; -STATIC MP_DEFINE_CONST_DICT(match_locals_dict, match_locals_dict_table); +static MP_DEFINE_CONST_DICT(match_locals_dict, match_locals_dict_table); mp_map_elem_t re_locals_dict_table[3]; -STATIC MP_DEFINE_CONST_DICT(re_locals_dict, re_locals_dict_table); +static MP_DEFINE_CONST_DICT(re_locals_dict, re_locals_dict_table); mp_obj_t mpy_init(mp_obj_fun_bc_t *self, size_t n_args, size_t n_kw, mp_obj_t *args) { MP_DYNRUNTIME_INIT_ENTRY diff --git a/examples/usercmodule/cexample/examplemodule.c b/examples/usercmodule/cexample/examplemodule.c index 9416613ba9520..2988fbd565f08 100644 --- a/examples/usercmodule/cexample/examplemodule.c +++ b/examples/usercmodule/cexample/examplemodule.c @@ -5,7 +5,7 @@ #include "py/mphal.h" // This is the function which will be called from Python as cexample.add_ints(a, b). -STATIC mp_obj_t example_add_ints(mp_obj_t a_obj, mp_obj_t b_obj) { +static mp_obj_t example_add_ints(mp_obj_t a_obj, mp_obj_t b_obj) { // Extract the ints from the micropython input objects. int a = mp_obj_get_int(a_obj); int b = mp_obj_get_int(b_obj); @@ -14,7 +14,7 @@ STATIC mp_obj_t example_add_ints(mp_obj_t a_obj, mp_obj_t b_obj) { return mp_obj_new_int(a + b); } // Define a Python reference to the function above. -STATIC MP_DEFINE_CONST_FUN_OBJ_2(example_add_ints_obj, example_add_ints); +static MP_DEFINE_CONST_FUN_OBJ_2(example_add_ints_obj, example_add_ints); // This structure represents Timer instance objects. typedef struct _example_Timer_obj_t { @@ -28,7 +28,7 @@ typedef struct _example_Timer_obj_t { // This is the Timer.time() method. After creating a Timer object, this // can be called to get the time elapsed since creating the Timer. -STATIC mp_obj_t example_Timer_time(mp_obj_t self_in) { +static mp_obj_t example_Timer_time(mp_obj_t self_in) { // The first argument is self. It is cast to the *example_Timer_obj_t // type so we can read its attributes. example_Timer_obj_t *self = MP_OBJ_TO_PTR(self_in); @@ -37,11 +37,11 @@ STATIC mp_obj_t example_Timer_time(mp_obj_t self_in) { mp_uint_t elapsed = mp_hal_ticks_ms() - self->start_time; return mp_obj_new_int_from_uint(elapsed); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(example_Timer_time_obj, example_Timer_time); +static MP_DEFINE_CONST_FUN_OBJ_1(example_Timer_time_obj, example_Timer_time); // This represents Timer.__new__ and Timer.__init__, which is called when // the user instantiates a Timer object. -STATIC mp_obj_t example_Timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t example_Timer_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { // Allocates the new object and sets the type. example_Timer_obj_t *self = mp_obj_malloc(example_Timer_obj_t, type); @@ -54,10 +54,10 @@ STATIC mp_obj_t example_Timer_make_new(const mp_obj_type_t *type, size_t n_args, // This collects all methods and other static class attributes of the Timer. // The table structure is similar to the module table, as detailed below. -STATIC const mp_rom_map_elem_t example_Timer_locals_dict_table[] = { +static const mp_rom_map_elem_t example_Timer_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_time), MP_ROM_PTR(&example_Timer_time_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(example_Timer_locals_dict, example_Timer_locals_dict_table); +static MP_DEFINE_CONST_DICT(example_Timer_locals_dict, example_Timer_locals_dict_table); // This defines the type(Timer) object. MP_DEFINE_CONST_OBJ_TYPE( @@ -73,12 +73,12 @@ MP_DEFINE_CONST_OBJ_TYPE( // and the MicroPython object reference. // All identifiers and strings are written as MP_QSTR_xxx and will be // optimized to word-sized integers by the build system (interned strings). -STATIC const mp_rom_map_elem_t example_module_globals_table[] = { +static const mp_rom_map_elem_t example_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cexample) }, { MP_ROM_QSTR(MP_QSTR_add_ints), MP_ROM_PTR(&example_add_ints_obj) }, { MP_ROM_QSTR(MP_QSTR_Timer), MP_ROM_PTR(&example_type_Timer) }, }; -STATIC MP_DEFINE_CONST_DICT(example_module_globals, example_module_globals_table); +static MP_DEFINE_CONST_DICT(example_module_globals, example_module_globals_table); // Define module object. const mp_obj_module_t example_user_cmodule = { diff --git a/examples/usercmodule/cppexample/examplemodule.c b/examples/usercmodule/cppexample/examplemodule.c index 96a1a74438845..5d4637b89782d 100644 --- a/examples/usercmodule/cppexample/examplemodule.c +++ b/examples/usercmodule/cppexample/examplemodule.c @@ -2,18 +2,18 @@ // Define a Python reference to the function we'll make available. // See example.cpp for the definition. -STATIC MP_DEFINE_CONST_FUN_OBJ_2(cppfunc_obj, cppfunc); +static MP_DEFINE_CONST_FUN_OBJ_2(cppfunc_obj, cppfunc); // Define all attributes of the module. // Table entries are key/value pairs of the attribute name (a string) // and the MicroPython object reference. // All identifiers and strings are written as MP_QSTR_xxx and will be // optimized to word-sized integers by the build system (interned strings). -STATIC const mp_rom_map_elem_t cppexample_module_globals_table[] = { +static const mp_rom_map_elem_t cppexample_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cppexample) }, { MP_ROM_QSTR(MP_QSTR_cppfunc), MP_ROM_PTR(&cppfunc_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(cppexample_module_globals, cppexample_module_globals_table); +static MP_DEFINE_CONST_DICT(cppexample_module_globals, cppexample_module_globals_table); // Define module object. const mp_obj_module_t cppexample_user_cmodule = { diff --git a/examples/usercmodule/subpackage/modexamplepackage.c b/examples/usercmodule/subpackage/modexamplepackage.c index 70e1e4005b30d..d68d0528398c4 100644 --- a/examples/usercmodule/subpackage/modexamplepackage.c +++ b/examples/usercmodule/subpackage/modexamplepackage.c @@ -2,18 +2,18 @@ #include "py/runtime.h" // Define example_package.foo.bar.f() -STATIC mp_obj_t example_package_foo_bar_f(void) { +static mp_obj_t example_package_foo_bar_f(void) { mp_printf(&mp_plat_print, "example_package.foo.bar.f\n"); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(example_package_foo_bar_f_obj, example_package_foo_bar_f); +static MP_DEFINE_CONST_FUN_OBJ_0(example_package_foo_bar_f_obj, example_package_foo_bar_f); // Define all attributes of the second-level sub-package (example_package.foo.bar). -STATIC const mp_rom_map_elem_t example_package_foo_bar_globals_table[] = { +static const mp_rom_map_elem_t example_package_foo_bar_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_example_package_dot_foo_dot_bar) }, { MP_ROM_QSTR(MP_QSTR_f), MP_ROM_PTR(&example_package_foo_bar_f_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(example_package_foo_bar_globals, example_package_foo_bar_globals_table); +static MP_DEFINE_CONST_DICT(example_package_foo_bar_globals, example_package_foo_bar_globals_table); // Define example_package.foo.bar module object. const mp_obj_module_t example_package_foo_bar_user_cmodule = { @@ -22,19 +22,19 @@ const mp_obj_module_t example_package_foo_bar_user_cmodule = { }; // Define example_package.foo.f() -STATIC mp_obj_t example_package_foo_f(void) { +static mp_obj_t example_package_foo_f(void) { mp_printf(&mp_plat_print, "example_package.foo.f\n"); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(example_package_foo_f_obj, example_package_foo_f); +static MP_DEFINE_CONST_FUN_OBJ_0(example_package_foo_f_obj, example_package_foo_f); // Define all attributes of the first-level sub-package (example_package.foo). -STATIC const mp_rom_map_elem_t example_package_foo_globals_table[] = { +static const mp_rom_map_elem_t example_package_foo_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_example_package_dot_foo) }, { MP_ROM_QSTR(MP_QSTR_bar), MP_ROM_PTR(&example_package_foo_bar_user_cmodule) }, { MP_ROM_QSTR(MP_QSTR_f), MP_ROM_PTR(&example_package_foo_f_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(example_package_foo_globals, example_package_foo_globals_table); +static MP_DEFINE_CONST_DICT(example_package_foo_globals, example_package_foo_globals_table); // Define example_package.foo module object. const mp_obj_module_t example_package_foo_user_cmodule = { @@ -43,13 +43,13 @@ const mp_obj_module_t example_package_foo_user_cmodule = { }; // Define example_package.f() -STATIC mp_obj_t example_package_f(void) { +static mp_obj_t example_package_f(void) { mp_printf(&mp_plat_print, "example_package.f\n"); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(example_package_f_obj, example_package_f); +static MP_DEFINE_CONST_FUN_OBJ_0(example_package_f_obj, example_package_f); -STATIC mp_obj_t example_package___init__(void) { +static mp_obj_t example_package___init__(void) { if (!MP_STATE_VM(example_package_initialised)) { // __init__ for builtins is called each time the module is imported, // so ensure that initialisation only happens once. @@ -58,20 +58,20 @@ STATIC mp_obj_t example_package___init__(void) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(example_package___init___obj, example_package___init__); +static MP_DEFINE_CONST_FUN_OBJ_0(example_package___init___obj, example_package___init__); // The "initialised" state is stored on mp_state so that it is cleared on soft // reset. MP_REGISTER_ROOT_POINTER(int example_package_initialised); // Define all attributes of the top-level package (example_package). -STATIC const mp_rom_map_elem_t example_package_globals_table[] = { +static const mp_rom_map_elem_t example_package_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_example_package) }, { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&example_package___init___obj) }, { MP_ROM_QSTR(MP_QSTR_foo), MP_ROM_PTR(&example_package_foo_user_cmodule) }, { MP_ROM_QSTR(MP_QSTR_f), MP_ROM_PTR(&example_package_f_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(example_package_globals, example_package_globals_table); +static MP_DEFINE_CONST_DICT(example_package_globals, example_package_globals_table); // Define module object. const mp_obj_module_t example_package_user_cmodule = { diff --git a/extmod/extmod.mk b/extmod/extmod.mk index a72d473bb4859..b81b44af37617 100644 --- a/extmod/extmod.mk +++ b/extmod/extmod.mk @@ -14,7 +14,6 @@ SRC_EXTMOD_C += \ extmod/modrandom.c \ extmod/modre.c \ extmod/modselect.c \ - extmod/moductypes.c \ extmod/modzlib.c \ extmod/vfs.c \ extmod/vfs_blockdev.c \ @@ -75,6 +74,9 @@ SRC_LIB_LIBM_C += $(addprefix lib/libm/,\ SRC_LIB_LIBM_SQRT_SW_C += lib/libm/ef_sqrt.c SRC_LIB_LIBM_SQRT_HW_C += lib/libm/thumb_vfp_sqrtf.c +# Disable warnings in libm. +$(BUILD)/lib/libm/kf_rem_pio2.o: CFLAGS += -Wno-maybe-uninitialized + # Double-precision math library. SRC_LIB_LIBM_DBL_C += $(addprefix lib/libm_dbl/,\ __cos.c \ @@ -197,7 +199,7 @@ SRC_THIRDPARTY_C += $(addprefix $(AXTLS_DIR)/,\ ) else ifeq ($(MICROPY_SSL_MBEDTLS),1) MBEDTLS_DIR = lib/mbedtls -MBEDTLS_CONFIG_FILE ?= \"mbedtls/mbedtls_config.h\" +MBEDTLS_CONFIG_FILE ?= \"mbedtls/mbedtls_config_port.h\" GIT_SUBMODULES += $(MBEDTLS_DIR) CFLAGS_EXTMOD += -DMBEDTLS_CONFIG_FILE=$(MBEDTLS_CONFIG_FILE) CFLAGS_EXTMOD += -DMICROPY_SSL_MBEDTLS=1 -I$(TOP)/$(MBEDTLS_DIR)/include @@ -205,20 +207,25 @@ SRC_THIRDPARTY_C += lib/mbedtls_errors/mp_mbedtls_errors.c SRC_THIRDPARTY_C += $(addprefix $(MBEDTLS_DIR)/library/,\ aes.c \ aesni.c \ - arc4.c \ asn1parse.c \ asn1write.c \ base64.c \ + bignum_core.c \ + bignum_mod.c \ + bignum_mod_raw.c \ bignum.c \ - blowfish.c \ camellia.c \ ccm.c \ - certs.c \ chacha20.c \ chachapoly.c \ cipher.c \ cipher_wrap.c \ + nist_kw.c \ + aria.c \ cmac.c \ + constant_time.c \ + mps_reader.c \ + mps_trace.c \ ctr_drbg.c \ debug.c \ des.c \ @@ -231,17 +238,13 @@ SRC_THIRDPARTY_C += $(addprefix $(MBEDTLS_DIR)/library/,\ entropy.c \ entropy_poll.c \ gcm.c \ - havege.c \ hmac_drbg.c \ - md2.c \ - md4.c \ md5.c \ md.c \ oid.c \ padlock.c \ pem.c \ pk.c \ - pkcs11.c \ pkcs12.c \ pkcs5.c \ pkparse.c \ @@ -252,20 +255,21 @@ SRC_THIRDPARTY_C += $(addprefix $(MBEDTLS_DIR)/library/,\ poly1305.c \ ripemd160.c \ rsa.c \ - rsa_internal.c \ + rsa_alt_helpers.c \ sha1.c \ sha256.c \ sha512.c \ ssl_cache.c \ ssl_ciphersuites.c \ - ssl_cli.c \ + ssl_client.c \ ssl_cookie.c \ - ssl_srv.c \ + ssl_debug_helpers_generated.c \ ssl_msg.c \ ssl_ticket.c \ ssl_tls.c \ + ssl_tls12_client.c \ + ssl_tls12_server.c \ timing.c \ - constant_time.c \ x509.c \ x509_create.c \ x509_crl.c \ @@ -273,7 +277,6 @@ SRC_THIRDPARTY_C += $(addprefix $(MBEDTLS_DIR)/library/,\ x509_csr.c \ x509write_crt.c \ x509write_csr.c \ - xtea.c \ ) endif endif @@ -341,8 +344,10 @@ endif ifeq ($(MICROPY_PY_BTREE),1) BTREE_DIR = lib/berkeley-db-1.xx -BTREE_DEFS = -D__DBINTERFACE_PRIVATE=1 -Dmpool_error=printf -Dabort=abort_ "-Dvirt_fd_t=void*" $(BTREE_DEFS_EXTRA) -INC += -I$(TOP)/$(BTREE_DIR)/PORT/include +BERKELEY_DB_CONFIG_FILE ?= \"extmod/berkeley-db/berkeley_db_config_port.h\" +CFLAGS_EXTMOD += -DBERKELEY_DB_CONFIG_FILE=$(BERKELEY_DB_CONFIG_FILE) +CFLAGS_EXTMOD += $(BTREE_DEFS_EXTRA) +INC += -I$(TOP)/$(BTREE_DIR)/include SRC_THIRDPARTY_C += $(addprefix $(BTREE_DIR)/,\ btree/bt_close.c \ btree/bt_conv.c \ @@ -361,9 +366,7 @@ SRC_THIRDPARTY_C += $(addprefix $(BTREE_DIR)/,\ ) CFLAGS_EXTMOD += -DMICROPY_PY_BTREE=1 # we need to suppress certain warnings to get berkeley-db to compile cleanly -# and we have separate BTREE_DEFS so the definitions don't interfere with other source code -$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter -Wno-deprecated-non-prototype -Wno-unknown-warning-option $(BTREE_DEFS) -$(BUILD)/extmod/modbtree.o: CFLAGS += $(BTREE_DEFS) +$(BUILD)/$(BTREE_DIR)/%.o: CFLAGS += -Wno-old-style-definition -Wno-sign-compare -Wno-unused-parameter -Wno-deprecated-non-prototype -Wno-unknown-warning-option endif ################################################################################ @@ -478,3 +481,58 @@ include $(TOP)/extmod/btstack/btstack.mk endif endif + +################################################################################ +# openamp + +ifeq ($(MICROPY_PY_OPENAMP),1) +OPENAMP_DIR = lib/open-amp +LIBMETAL_DIR = lib/libmetal +GIT_SUBMODULES += $(LIBMETAL_DIR) $(OPENAMP_DIR) +include $(TOP)/extmod/libmetal/libmetal.mk + +INC += -I$(TOP)/$(OPENAMP_DIR) +CFLAGS += -DMICROPY_PY_OPENAMP=1 + +ifeq ($(MICROPY_PY_OPENAMP_REMOTEPROC),1) +CFLAGS += -DMICROPY_PY_OPENAMP_REMOTEPROC=1 +endif + +CFLAGS_THIRDPARTY += \ + -I$(BUILD)/openamp \ + -I$(TOP)/$(OPENAMP_DIR) \ + -I$(TOP)/$(OPENAMP_DIR)/lib/include/ \ + -DMETAL_INTERNAL \ + -DVIRTIO_DRIVER_ONLY \ + -DNO_ATOMIC_64_SUPPORT \ + -DRPMSG_BUFFER_SIZE=512 \ + +# OpenAMP's source files. +SRC_OPENAMP_C += $(addprefix $(OPENAMP_DIR)/lib/,\ + rpmsg/rpmsg.c \ + rpmsg/rpmsg_virtio.c \ + virtio/virtio.c \ + virtio/virtqueue.c \ + virtio_mmio/virtio_mmio_drv.c \ + ) + +# OpenAMP's remoteproc source files. +ifeq ($(MICROPY_PY_OPENAMP_REMOTEPROC),1) +SRC_OPENAMP_C += $(addprefix $(OPENAMP_DIR)/lib/remoteproc/,\ + elf_loader.c \ + remoteproc.c \ + remoteproc_virtio.c \ + rsc_table_parser.c \ + ) +endif # MICROPY_PY_OPENAMP_REMOTEPROC + +# Disable compiler warnings in OpenAMP (variables used only for assert). +$(BUILD)/$(OPENAMP_DIR)/lib/rpmsg/rpmsg_virtio.o: CFLAGS += -Wno-unused-but-set-variable +$(BUILD)/$(OPENAMP_DIR)/lib/virtio_mmio/virtio_mmio_drv.o: CFLAGS += -Wno-unused-but-set-variable + +# We need to have generated libmetal before compiling OpenAMP. +$(addprefix $(BUILD)/, $(SRC_OPENAMP_C:.c=.o)): $(BUILD)/openamp/metal/config.h + +SRC_THIRDPARTY_C += $(SRC_LIBMETAL_C) $(SRC_OPENAMP_C) + +endif # MICROPY_PY_OPENAMP diff --git a/extmod/modasyncio.c b/extmod/modasyncio.c index 8d7b52bc227ea..4672f6940c1fc 100644 --- a/extmod/modasyncio.c +++ b/extmod/modasyncio.c @@ -60,10 +60,10 @@ typedef struct _mp_obj_task_queue_t { mp_obj_task_t *heap; } mp_obj_task_queue_t; -STATIC const mp_obj_type_t task_queue_type; -STATIC const mp_obj_type_t task_type; +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, size_t n_kw, const mp_obj_t *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 @@ -74,7 +74,7 @@ STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, si #define _TICKS_HALFPERIOD (_TICKS_PERIOD >> 1) #if !CIRCUITPY || (defined(__unix__) || defined(__APPLE__)) -STATIC mp_obj_t ticks(void) { +static mp_obj_t ticks(void) { return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & _TICKS_MAX); } #else @@ -87,14 +87,14 @@ STATIC mp_obj_t ticks(void) { #endif // CIRCUITPY-CHANGE: ticks_diff must match adafruit_ticks -STATIC mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) { +static mp_int_t ticks_diff(mp_obj_t t1_in, mp_obj_t t0_in) { mp_uint_t t0 = MP_OBJ_SMALL_INT_VALUE(t0_in); mp_uint_t t1 = MP_OBJ_SMALL_INT_VALUE(t1_in); mp_int_t diff = ((t1 - t0 + _TICKS_HALFPERIOD) & _TICKS_MAX) - _TICKS_HALFPERIOD; return diff; } -STATIC int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) { +static int task_lt(mp_pairheap_t *n1, mp_pairheap_t *n2) { mp_obj_task_t *t1 = (mp_obj_task_t *)n1; mp_obj_task_t *t2 = (mp_obj_task_t *)n2; return MP_OBJ_SMALL_INT_VALUE(ticks_diff(t1->ph_key, t2->ph_key)) < 0; @@ -103,7 +103,7 @@ 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, size_t n_kw, const mp_obj_t *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, n_kw, 0, 0, false); mp_obj_task_queue_t *self = mp_obj_malloc(mp_obj_task_queue_t, type); @@ -111,7 +111,7 @@ STATIC mp_obj_t task_queue_make_new(const mp_obj_type_t *type, size_t n_args, si return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t task_queue_peek(mp_obj_t self_in) { +static mp_obj_t task_queue_peek(mp_obj_t self_in) { mp_obj_task_queue_t *self = MP_OBJ_TO_PTR(self_in); if (self->heap == NULL) { return mp_const_none; @@ -119,9 +119,9 @@ STATIC mp_obj_t task_queue_peek(mp_obj_t self_in) { return MP_OBJ_FROM_PTR(self->heap); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_queue_peek_obj, task_queue_peek); +static MP_DEFINE_CONST_FUN_OBJ_1(task_queue_peek_obj, task_queue_peek); -STATIC mp_obj_t task_queue_push(size_t n_args, const mp_obj_t *args) { +static mp_obj_t task_queue_push(size_t n_args, const mp_obj_t *args) { mp_obj_task_queue_t *self = MP_OBJ_TO_PTR(args[0]); mp_obj_task_t *task = MP_OBJ_TO_PTR(args[1]); task->data = mp_const_none; @@ -134,9 +134,9 @@ STATIC mp_obj_t task_queue_push(size_t n_args, const mp_obj_t *args) { 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_obj, 2, 3, task_queue_push); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(task_queue_push_obj, 2, 3, task_queue_push); -STATIC mp_obj_t task_queue_pop(mp_obj_t self_in) { +static mp_obj_t task_queue_pop(mp_obj_t self_in) { mp_obj_task_queue_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_task_t *head = (mp_obj_task_t *)mp_pairheap_peek(task_lt, &self->heap->pairheap); if (head == NULL) { @@ -145,17 +145,17 @@ STATIC mp_obj_t task_queue_pop(mp_obj_t self_in) { self->heap = (mp_obj_task_t *)mp_pairheap_pop(task_lt, &self->heap->pairheap); return MP_OBJ_FROM_PTR(head); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_queue_pop_obj, task_queue_pop); +static MP_DEFINE_CONST_FUN_OBJ_1(task_queue_pop_obj, task_queue_pop); -STATIC mp_obj_t task_queue_remove(mp_obj_t self_in, mp_obj_t task_in) { +static mp_obj_t task_queue_remove(mp_obj_t self_in, mp_obj_t task_in) { mp_obj_task_queue_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_task_t *task = MP_OBJ_TO_PTR(task_in); self->heap = (mp_obj_task_t *)mp_pairheap_delete(task_lt, &self->heap->pairheap, &task->pairheap); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(task_queue_remove_obj, task_queue_remove); +static MP_DEFINE_CONST_FUN_OBJ_2(task_queue_remove_obj, task_queue_remove); -STATIC const mp_rom_map_elem_t task_queue_locals_dict_table[] = { +static const mp_rom_map_elem_t task_queue_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_peek), MP_ROM_PTR(&task_queue_peek_obj) }, { MP_ROM_QSTR(MP_QSTR_push), MP_ROM_PTR(&task_queue_push_obj) }, { MP_ROM_QSTR(MP_QSTR_pop), MP_ROM_PTR(&task_queue_pop_obj) }, @@ -166,9 +166,9 @@ STATIC const mp_rom_map_elem_t task_queue_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_push_sorted), MP_ROM_PTR(&task_queue_push_obj) }, { MP_ROM_QSTR(MP_QSTR_pop_head), MP_ROM_PTR(&task_queue_pop_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(task_queue_locals_dict, task_queue_locals_dict_table); +static MP_DEFINE_CONST_DICT(task_queue_locals_dict, task_queue_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( task_queue_type, MP_QSTR_TaskQueue, MP_TYPE_FLAG_NONE, @@ -180,9 +180,9 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( // Task class // This is the core asyncio context with cur_task, _task_queue and CancelledError. -STATIC mp_obj_t asyncio_context = MP_OBJ_NULL; +mp_obj_t mp_asyncio_context = MP_OBJ_NULL; -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) { +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; @@ -192,25 +192,25 @@ STATIC mp_obj_t task_make_new(const mp_obj_type_t *type, size_t n_args, size_t n self->state = TASK_STATE_RUNNING_NOT_WAITED_ON; self->ph_key = MP_OBJ_NEW_SMALL_INT(0); if (n_args == 2) { - asyncio_context = args[1]; + mp_asyncio_context = args[1]; } return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t task_done(mp_obj_t self_in) { +static mp_obj_t task_done(mp_obj_t self_in) { mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_bool(TASK_IS_DONE(self)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_done_obj, task_done); +static MP_DEFINE_CONST_FUN_OBJ_1(task_done_obj, task_done); -STATIC mp_obj_t task_cancel(mp_obj_t self_in) { +static mp_obj_t task_cancel(mp_obj_t self_in) { mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in); // Check if task is already finished. if (TASK_IS_DONE(self)) { return mp_const_false; } // Can't cancel self (not supported yet). - mp_obj_t cur_task = mp_obj_dict_get(asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_cur_task)); + mp_obj_t cur_task = mp_obj_dict_get(mp_asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_cur_task)); if (self_in == cur_task) { mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("can't cancel self")); } @@ -219,7 +219,7 @@ STATIC mp_obj_t task_cancel(mp_obj_t self_in) { self = MP_OBJ_TO_PTR(self->data); } - mp_obj_t _task_queue = mp_obj_dict_get(asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR__task_queue)); + mp_obj_t _task_queue = mp_obj_dict_get(mp_asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR__task_queue)); // Reschedule Task as a cancelled task. mp_obj_t dest[3]; @@ -242,21 +242,21 @@ STATIC mp_obj_t task_cancel(mp_obj_t self_in) { task_queue_push(2, dest); } - self->data = mp_obj_dict_get(asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_CancelledError)); + self->data = mp_obj_dict_get(mp_asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_CancelledError)); return mp_const_true; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_cancel_obj, task_cancel); +static MP_DEFINE_CONST_FUN_OBJ_1(task_cancel_obj, task_cancel); // CIRCUITPY-CHANGE: CircuitPython provides __await__(). -STATIC mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf); +static mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf); -STATIC mp_obj_t task_await(mp_obj_t self_in) { +static mp_obj_t task_await(mp_obj_t self_in) { return task_getiter(self_in, NULL); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(task_await_obj, task_await); +static MP_DEFINE_CONST_FUN_OBJ_1(task_await_obj, task_await); -STATIC void task_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void task_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in); if (dest[0] == MP_OBJ_NULL) { // Load @@ -274,6 +274,7 @@ STATIC void task_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { dest[1] = self_in; } else if (attr == MP_QSTR_ph_key) { dest[0] = self->ph_key; + // CIRCUITPY-CHANGE: await } else if (attr == MP_QSTR___await__) { dest[0] = MP_OBJ_FROM_PTR(&task_await_obj); dest[1] = self_in; @@ -290,7 +291,7 @@ STATIC void task_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } -STATIC mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { (void)iter_buf; mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in); if (TASK_IS_DONE(self)) { @@ -306,7 +307,7 @@ STATIC mp_obj_t task_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { return self_in; } -STATIC mp_obj_t task_iternext(mp_obj_t self_in) { +static mp_obj_t task_iternext(mp_obj_t self_in) { mp_obj_task_t *self = MP_OBJ_TO_PTR(self_in); if (TASK_IS_DONE(self)) { // CIRCUITPY-CHANGE @@ -319,7 +320,7 @@ STATIC mp_obj_t task_iternext(mp_obj_t self_in) { } } else { // Put calling task on waiting queue. - mp_obj_t cur_task = mp_obj_dict_get(asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_cur_task)); + mp_obj_t cur_task = mp_obj_dict_get(mp_asyncio_context, MP_OBJ_NEW_QSTR(MP_QSTR_cur_task)); mp_obj_t args[2] = { self->state, cur_task }; task_queue_push(2, args); // Set calling task's data to this task that it waits on, to double-link it. @@ -328,12 +329,12 @@ STATIC mp_obj_t task_iternext(mp_obj_t self_in) { return mp_const_none; } -STATIC const mp_getiter_iternext_custom_t task_getiter_iternext = { +static const mp_getiter_iternext_custom_t task_getiter_iternext = { .getiter = task_getiter, .iternext = task_iternext, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( task_type, MP_QSTR_Task, MP_TYPE_FLAG_ITER_IS_CUSTOM, @@ -345,12 +346,12 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( /******************************************************************************/ // C-level asyncio module -STATIC const mp_rom_map_elem_t mp_module_asyncio_globals_table[] = { +static const mp_rom_map_elem_t mp_module_asyncio_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__asyncio) }, { MP_ROM_QSTR(MP_QSTR_TaskQueue), MP_ROM_PTR(&task_queue_type) }, { MP_ROM_QSTR(MP_QSTR_Task), MP_ROM_PTR(&task_type) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_asyncio_globals, mp_module_asyncio_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_asyncio_globals, mp_module_asyncio_globals_table); const mp_obj_module_t mp_module_asyncio = { .base = { &mp_type_module }, diff --git a/extmod/modbinascii.c b/extmod/modbinascii.c index 90fa7bbf906f0..2469744fc38de 100644 --- a/extmod/modbinascii.c +++ b/extmod/modbinascii.c @@ -44,15 +44,15 @@ static void check_not_unicode(const mp_obj_t arg) { } #if MICROPY_PY_BUILTINS_BYTES_HEX -STATIC mp_obj_t bytes_hex_as_bytes(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bytes_hex_as_bytes(size_t n_args, const mp_obj_t *args) { return mp_obj_bytes_hex(n_args, args, &mp_type_bytes); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bytes_hex_as_bytes_obj, 1, 2, bytes_hex_as_bytes); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bytes_hex_as_bytes_obj, 1, 2, bytes_hex_as_bytes); -STATIC mp_obj_t bytes_fromhex_bytes(mp_obj_t data) { +static mp_obj_t bytes_fromhex_bytes(mp_obj_t data) { return mp_obj_bytes_fromhex(MP_OBJ_FROM_PTR(&mp_type_bytes), data); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bytes_fromhex_obj, bytes_fromhex_bytes); +static MP_DEFINE_CONST_FUN_OBJ_1(bytes_fromhex_obj, bytes_fromhex_bytes); #endif // If ch is a character in the base64 alphabet, and is not a pad character, then @@ -74,7 +74,7 @@ static int mod_binascii_sextet(byte ch) { } } -STATIC mp_obj_t mod_binascii_a2b_base64(mp_obj_t data) { +static mp_obj_t mod_binascii_a2b_base64(mp_obj_t data) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ); byte *in = bufinfo.buf; @@ -115,9 +115,9 @@ STATIC mp_obj_t mod_binascii_a2b_base64(mp_obj_t data) { return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_binascii_a2b_base64_obj, mod_binascii_a2b_base64); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_binascii_a2b_base64_obj, mod_binascii_a2b_base64); -STATIC mp_obj_t mod_binascii_b2a_base64(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t mod_binascii_b2a_base64(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_newline }; static const mp_arg_t allowed_args[] = { { MP_QSTR_newline, MP_ARG_BOOL, {.u_bool = true} }, @@ -179,13 +179,13 @@ STATIC mp_obj_t mod_binascii_b2a_base64(size_t n_args, const mp_obj_t *pos_args, } return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_binascii_b2a_base64_obj, 1, mod_binascii_b2a_base64); +static MP_DEFINE_CONST_FUN_OBJ_KW(mod_binascii_b2a_base64_obj, 1, mod_binascii_b2a_base64); // CIRCUITPY-CHANGE: no deflate #if MICROPY_PY_BINASCII_CRC32 #include "lib/uzlib/uzlib.h" -STATIC mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo; // CIRCUITPY-CHANGE check_not_unicode(args[0]); @@ -194,10 +194,10 @@ STATIC mp_obj_t mod_binascii_crc32(size_t n_args, const mp_obj_t *args) { crc = uzlib_crc32(bufinfo.buf, bufinfo.len, crc ^ 0xffffffff); return mp_obj_new_int_from_uint(crc ^ 0xffffffff); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_binascii_crc32_obj, 1, 2, mod_binascii_crc32); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_binascii_crc32_obj, 1, 2, mod_binascii_crc32); #endif -STATIC const mp_rom_map_elem_t mp_module_binascii_globals_table[] = { +static const mp_rom_map_elem_t mp_module_binascii_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_binascii) }, #if MICROPY_PY_BUILTINS_BYTES_HEX { MP_ROM_QSTR(MP_QSTR_hexlify), MP_ROM_PTR(&bytes_hex_as_bytes_obj) }, @@ -211,7 +211,7 @@ STATIC const mp_rom_map_elem_t mp_module_binascii_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_binascii_globals, mp_module_binascii_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_binascii_globals, mp_module_binascii_globals_table); const mp_obj_module_t mp_module_binascii = { .base = { &mp_type_module }, diff --git a/extmod/moddeflate.c b/extmod/moddeflate.c index 560ee3f0abce9..c0c3bb26a8b12 100644 --- a/extmod/moddeflate.c +++ b/extmod/moddeflate.c @@ -85,7 +85,7 @@ typedef struct { #endif } mp_obj_deflateio_t; -STATIC int deflateio_read_stream(void *data) { +static int deflateio_read_stream(void *data) { mp_obj_deflateio_t *self = data; const mp_stream_p_t *stream = mp_get_stream(self->stream); int err; @@ -100,7 +100,7 @@ STATIC int deflateio_read_stream(void *data) { return c; } -STATIC bool deflateio_init_read(mp_obj_deflateio_t *self) { +static bool deflateio_init_read(mp_obj_deflateio_t *self) { if (self->read) { return true; } @@ -151,7 +151,7 @@ STATIC bool deflateio_init_read(mp_obj_deflateio_t *self) { } #if MICROPY_PY_DEFLATE_COMPRESS -STATIC void deflateio_out_byte(void *data, uint8_t b) { +static void deflateio_out_byte(void *data, uint8_t b) { mp_obj_deflateio_t *self = data; const mp_stream_p_t *stream = mp_get_stream(self->stream); int err; @@ -161,7 +161,7 @@ STATIC void deflateio_out_byte(void *data, uint8_t b) { } } -STATIC bool deflateio_init_write(mp_obj_deflateio_t *self) { +static bool deflateio_init_write(mp_obj_deflateio_t *self) { if (self->write) { return true; } @@ -214,7 +214,7 @@ STATIC bool deflateio_init_write(mp_obj_deflateio_t *self) { } #endif -STATIC mp_obj_t deflateio_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args_in) { +static mp_obj_t deflateio_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args_in) { // args: stream, format=NONE, wbits=0, close=False mp_arg_check_num(n_args, n_kw, 1, 4, false); @@ -241,7 +241,7 @@ STATIC mp_obj_t deflateio_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(self); } -STATIC mp_uint_t deflateio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t deflateio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { mp_obj_deflateio_t *self = MP_OBJ_TO_PTR(o_in); if (self->stream == MP_OBJ_NULL || !deflateio_init_read(self)) { @@ -268,7 +268,7 @@ STATIC mp_uint_t deflateio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *e } #if MICROPY_PY_DEFLATE_COMPRESS -STATIC mp_uint_t deflateio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t deflateio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_deflateio_t *self = MP_OBJ_TO_PTR(self_in); if (self->stream == MP_OBJ_NULL || !deflateio_init_write(self)) { @@ -302,7 +302,7 @@ static inline void put_be32(char *buf, uint32_t value) { } #endif -STATIC mp_uint_t deflateio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t deflateio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { if (request == MP_STREAM_CLOSE) { mp_obj_deflateio_t *self = MP_OBJ_TO_PTR(self_in); @@ -351,7 +351,7 @@ STATIC mp_uint_t deflateio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t } } -STATIC const mp_stream_p_t deflateio_stream_p = { +static const mp_stream_p_t deflateio_stream_p = { .read = deflateio_read, #if MICROPY_PY_DEFLATE_COMPRESS .write = deflateio_write, @@ -360,7 +360,7 @@ STATIC const mp_stream_p_t deflateio_stream_p = { }; #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t deflateio_locals_dict_table[] = { +static const mp_rom_map_elem_t deflateio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) }, @@ -371,9 +371,9 @@ STATIC const mp_rom_map_elem_t deflateio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj) }, { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&mp_stream___exit___obj) }, }; -STATIC MP_DEFINE_CONST_DICT(deflateio_locals_dict, deflateio_locals_dict_table); +static MP_DEFINE_CONST_DICT(deflateio_locals_dict, deflateio_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( deflateio_type, MP_QSTR_DeflateIO, MP_TYPE_FLAG_NONE, @@ -382,7 +382,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &deflateio_locals_dict ); -STATIC const mp_rom_map_elem_t mp_module_deflate_globals_table[] = { +static const mp_rom_map_elem_t mp_module_deflate_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_deflate) }, { MP_ROM_QSTR(MP_QSTR_DeflateIO), MP_ROM_PTR(&deflateio_type) }, { MP_ROM_QSTR(MP_QSTR_AUTO), MP_ROM_INT(DEFLATEIO_FORMAT_AUTO) }, @@ -390,7 +390,7 @@ STATIC const mp_rom_map_elem_t mp_module_deflate_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_ZLIB), MP_ROM_INT(DEFLATEIO_FORMAT_ZLIB) }, { MP_ROM_QSTR(MP_QSTR_GZIP), MP_ROM_INT(DEFLATEIO_FORMAT_GZIP) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_deflate_globals, mp_module_deflate_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_deflate_globals, mp_module_deflate_globals_table); const mp_obj_module_t mp_module_deflate = { .base = { &mp_type_module }, diff --git a/extmod/modhashlib.c b/extmod/modhashlib.c index fc9c87320004b..a31347356831e 100644 --- a/extmod/modhashlib.c +++ b/extmod/modhashlib.c @@ -71,7 +71,7 @@ static void hashlib_ensure_not_final(mp_obj_hash_t *self) { } #if MICROPY_PY_HASHLIB_SHA256 -STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg); +static mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg); #if MICROPY_SSL_MBEDTLS @@ -81,9 +81,9 @@ STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg); #define mbedtls_sha256_finish_ret mbedtls_sha256_finish #endif -STATIC mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t hashlib_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 = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_sha256_context), type); + mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(mbedtls_sha256_context), type); o->final = false; mbedtls_sha256_init((mbedtls_sha256_context *)&o->state); mbedtls_sha256_starts_ret((mbedtls_sha256_context *)&o->state, 0); @@ -93,7 +93,7 @@ STATIC mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); mp_buffer_info_t bufinfo; @@ -102,7 +102,7 @@ STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { return mp_const_none; } -STATIC mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) { +static mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); self->final = true; @@ -125,9 +125,9 @@ static void check_not_unicode(const mp_obj_t arg) { #include "lib/crypto-algorithms/sha256.c" -STATIC mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t hashlib_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 = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(CRYAL_SHA256_CTX), type); + mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(CRYAL_SHA256_CTX), type); o->final = false; sha256_init((CRYAL_SHA256_CTX *)o->state); if (n_args == 1) { @@ -136,7 +136,7 @@ STATIC mp_obj_t hashlib_sha256_make_new(const mp_obj_type_t *type, size_t n_args return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { // CIRCUITPY-CHANGE check_not_unicode(arg); mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); @@ -147,7 +147,7 @@ STATIC mp_obj_t hashlib_sha256_update(mp_obj_t self_in, mp_obj_t arg) { return mp_const_none; } -STATIC mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) { +static mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); self->final = true; @@ -158,17 +158,17 @@ STATIC mp_obj_t hashlib_sha256_digest(mp_obj_t self_in) { } #endif -STATIC MP_DEFINE_CONST_FUN_OBJ_2(hashlib_sha256_update_obj, hashlib_sha256_update); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(hashlib_sha256_digest_obj, hashlib_sha256_digest); +static MP_DEFINE_CONST_FUN_OBJ_2(hashlib_sha256_update_obj, hashlib_sha256_update); +static MP_DEFINE_CONST_FUN_OBJ_1(hashlib_sha256_digest_obj, hashlib_sha256_digest); -STATIC const mp_rom_map_elem_t hashlib_sha256_locals_dict_table[] = { +static const mp_rom_map_elem_t hashlib_sha256_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&hashlib_sha256_update_obj) }, { MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&hashlib_sha256_digest_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(hashlib_sha256_locals_dict, hashlib_sha256_locals_dict_table); +static MP_DEFINE_CONST_DICT(hashlib_sha256_locals_dict, hashlib_sha256_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( hashlib_sha256_type, MP_QSTR_sha256, MP_TYPE_FLAG_NONE, @@ -178,12 +178,12 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( #endif #if MICROPY_PY_HASHLIB_SHA1 -STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg); +static mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg); #if MICROPY_SSL_AXTLS -STATIC mp_obj_t hashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t hashlib_sha1_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 = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(SHA1_CTX), type); + mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(SHA1_CTX), type); o->final = false; SHA1_Init((SHA1_CTX *)o->state); if (n_args == 1) { @@ -192,7 +192,7 @@ STATIC mp_obj_t hashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); mp_buffer_info_t bufinfo; @@ -201,7 +201,7 @@ STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { return mp_const_none; } -STATIC mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) { +static mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); self->final = true; @@ -220,9 +220,9 @@ STATIC mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) { #define mbedtls_sha1_finish_ret mbedtls_sha1_finish #endif -STATIC mp_obj_t hashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t hashlib_sha1_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 = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_sha1_context), type); + mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(mbedtls_sha1_context), type); o->final = false; mbedtls_sha1_init((mbedtls_sha1_context *)o->state); mbedtls_sha1_starts_ret((mbedtls_sha1_context *)o->state); @@ -232,7 +232,7 @@ STATIC mp_obj_t hashlib_sha1_make_new(const mp_obj_type_t *type, size_t n_args, return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); mp_buffer_info_t bufinfo; @@ -241,7 +241,7 @@ STATIC mp_obj_t hashlib_sha1_update(mp_obj_t self_in, mp_obj_t arg) { return mp_const_none; } -STATIC mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) { +static mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); self->final = true; @@ -253,16 +253,16 @@ STATIC mp_obj_t hashlib_sha1_digest(mp_obj_t self_in) { } #endif -STATIC MP_DEFINE_CONST_FUN_OBJ_2(hashlib_sha1_update_obj, hashlib_sha1_update); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(hashlib_sha1_digest_obj, hashlib_sha1_digest); +static MP_DEFINE_CONST_FUN_OBJ_2(hashlib_sha1_update_obj, hashlib_sha1_update); +static MP_DEFINE_CONST_FUN_OBJ_1(hashlib_sha1_digest_obj, hashlib_sha1_digest); -STATIC const mp_rom_map_elem_t hashlib_sha1_locals_dict_table[] = { +static const mp_rom_map_elem_t hashlib_sha1_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&hashlib_sha1_update_obj) }, { MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&hashlib_sha1_digest_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(hashlib_sha1_locals_dict, hashlib_sha1_locals_dict_table); +static MP_DEFINE_CONST_DICT(hashlib_sha1_locals_dict, hashlib_sha1_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( hashlib_sha1_type, MP_QSTR_sha1, MP_TYPE_FLAG_NONE, @@ -272,12 +272,12 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( #endif #if MICROPY_PY_HASHLIB_MD5 -STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg); +static mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg); #if MICROPY_SSL_AXTLS -STATIC mp_obj_t hashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t hashlib_md5_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 = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(MD5_CTX), type); + mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(MD5_CTX), type); o->final = false; MD5_Init((MD5_CTX *)o->state); if (n_args == 1) { @@ -286,7 +286,7 @@ STATIC mp_obj_t hashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, s return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); mp_buffer_info_t bufinfo; @@ -295,7 +295,7 @@ STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) { return mp_const_none; } -STATIC mp_obj_t hashlib_md5_digest(mp_obj_t self_in) { +static mp_obj_t hashlib_md5_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); self->final = true; @@ -314,9 +314,9 @@ STATIC mp_obj_t hashlib_md5_digest(mp_obj_t self_in) { #define mbedtls_md5_finish_ret mbedtls_md5_finish #endif -STATIC mp_obj_t hashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t hashlib_md5_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 = mp_obj_malloc_var(mp_obj_hash_t, char, sizeof(mbedtls_md5_context), type); + mp_obj_hash_t *o = mp_obj_malloc_var(mp_obj_hash_t, state, char, sizeof(mbedtls_md5_context), type); o->final = false; mbedtls_md5_init((mbedtls_md5_context *)o->state); mbedtls_md5_starts_ret((mbedtls_md5_context *)o->state); @@ -326,7 +326,7 @@ STATIC mp_obj_t hashlib_md5_make_new(const mp_obj_type_t *type, size_t n_args, s return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); mp_buffer_info_t bufinfo; @@ -335,7 +335,7 @@ STATIC mp_obj_t hashlib_md5_update(mp_obj_t self_in, mp_obj_t arg) { return mp_const_none; } -STATIC mp_obj_t hashlib_md5_digest(mp_obj_t self_in) { +static mp_obj_t hashlib_md5_digest(mp_obj_t self_in) { mp_obj_hash_t *self = MP_OBJ_TO_PTR(self_in); hashlib_ensure_not_final(self); self->final = true; @@ -347,16 +347,16 @@ STATIC mp_obj_t hashlib_md5_digest(mp_obj_t self_in) { } #endif // MICROPY_SSL_MBEDTLS -STATIC MP_DEFINE_CONST_FUN_OBJ_2(hashlib_md5_update_obj, hashlib_md5_update); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(hashlib_md5_digest_obj, hashlib_md5_digest); +static MP_DEFINE_CONST_FUN_OBJ_2(hashlib_md5_update_obj, hashlib_md5_update); +static MP_DEFINE_CONST_FUN_OBJ_1(hashlib_md5_digest_obj, hashlib_md5_digest); -STATIC const mp_rom_map_elem_t hashlib_md5_locals_dict_table[] = { +static const mp_rom_map_elem_t hashlib_md5_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&hashlib_md5_update_obj) }, { MP_ROM_QSTR(MP_QSTR_digest), MP_ROM_PTR(&hashlib_md5_digest_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(hashlib_md5_locals_dict, hashlib_md5_locals_dict_table); +static MP_DEFINE_CONST_DICT(hashlib_md5_locals_dict, hashlib_md5_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( hashlib_md5_type, MP_QSTR_md5, MP_TYPE_FLAG_NONE, @@ -365,7 +365,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); #endif // MICROPY_PY_HASHLIB_MD5 -STATIC const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = { +static const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_hashlib) }, #if MICROPY_PY_HASHLIB_SHA256 { MP_ROM_QSTR(MP_QSTR_sha256), MP_ROM_PTR(&hashlib_sha256_type) }, @@ -378,7 +378,7 @@ STATIC const mp_rom_map_elem_t mp_module_hashlib_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_hashlib_globals, mp_module_hashlib_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_hashlib_globals, mp_module_hashlib_globals_table); const mp_obj_module_t mp_module_hashlib = { .base = { &mp_type_module }, diff --git a/extmod/modheapq.c b/extmod/modheapq.c index db1e35bac2830..bb8c7d2bf175e 100644 --- a/extmod/modheapq.c +++ b/extmod/modheapq.c @@ -31,14 +31,14 @@ // the algorithm here is modelled on CPython's heapq.py -STATIC mp_obj_list_t *heapq_get_heap(mp_obj_t heap_in) { +static mp_obj_list_t *heapq_get_heap(mp_obj_t heap_in) { if (!mp_obj_is_type(heap_in, &mp_type_list)) { mp_raise_TypeError(MP_ERROR_TEXT("heap must be a list")); } return MP_OBJ_TO_PTR(heap_in); } -STATIC void heapq_heap_siftdown(mp_obj_list_t *heap, mp_uint_t start_pos, mp_uint_t pos) { +static void heapq_heap_siftdown(mp_obj_list_t *heap, mp_uint_t start_pos, mp_uint_t pos) { mp_obj_t item = heap->items[pos]; while (pos > start_pos) { mp_uint_t parent_pos = (pos - 1) >> 1; @@ -53,7 +53,7 @@ STATIC void heapq_heap_siftdown(mp_obj_list_t *heap, mp_uint_t start_pos, mp_uin heap->items[pos] = item; } -STATIC void heapq_heap_siftup(mp_obj_list_t *heap, mp_uint_t pos) { +static void heapq_heap_siftup(mp_obj_list_t *heap, mp_uint_t pos) { mp_uint_t start_pos = pos; mp_uint_t end_pos = heap->len; mp_obj_t item = heap->items[pos]; @@ -70,15 +70,15 @@ STATIC void heapq_heap_siftup(mp_obj_list_t *heap, mp_uint_t pos) { heapq_heap_siftdown(heap, start_pos, pos); } -STATIC mp_obj_t mod_heapq_heappush(mp_obj_t heap_in, mp_obj_t item) { +static mp_obj_t mod_heapq_heappush(mp_obj_t heap_in, mp_obj_t item) { mp_obj_list_t *heap = heapq_get_heap(heap_in); mp_obj_list_append(heap_in, item); heapq_heap_siftdown(heap, 0, heap->len - 1); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_heapq_heappush_obj, mod_heapq_heappush); +static MP_DEFINE_CONST_FUN_OBJ_2(mod_heapq_heappush_obj, mod_heapq_heappush); -STATIC mp_obj_t mod_heapq_heappop(mp_obj_t heap_in) { +static mp_obj_t mod_heapq_heappop(mp_obj_t heap_in) { mp_obj_list_t *heap = heapq_get_heap(heap_in); if (heap->len == 0) { mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("empty heap")); @@ -92,26 +92,26 @@ STATIC mp_obj_t mod_heapq_heappop(mp_obj_t heap_in) { } return item; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_heapq_heappop_obj, mod_heapq_heappop); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_heapq_heappop_obj, mod_heapq_heappop); -STATIC mp_obj_t mod_heapq_heapify(mp_obj_t heap_in) { +static mp_obj_t mod_heapq_heapify(mp_obj_t heap_in) { mp_obj_list_t *heap = heapq_get_heap(heap_in); for (mp_uint_t i = heap->len / 2; i > 0;) { heapq_heap_siftup(heap, --i); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_heapq_heapify_obj, mod_heapq_heapify); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_heapq_heapify_obj, mod_heapq_heapify); #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t mp_module_heapq_globals_table[] = { +static const mp_rom_map_elem_t mp_module_heapq_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_heapq) }, { MP_ROM_QSTR(MP_QSTR_heappush), MP_ROM_PTR(&mod_heapq_heappush_obj) }, { MP_ROM_QSTR(MP_QSTR_heappop), MP_ROM_PTR(&mod_heapq_heappop_obj) }, { MP_ROM_QSTR(MP_QSTR_heapify), MP_ROM_PTR(&mod_heapq_heapify_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_heapq_globals, mp_module_heapq_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_heapq_globals, mp_module_heapq_globals_table); const mp_obj_module_t mp_module_heapq = { .base = { &mp_type_module }, diff --git a/extmod/modjson.c b/extmod/modjson.c index 12dc70632594b..67da36f0ccf71 100644 --- a/extmod/modjson.c +++ b/extmod/modjson.c @@ -44,7 +44,7 @@ enum { DUMP_MODE_TO_STREAM = 2, }; -STATIC mp_obj_t mod_json_dump_helper(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args, unsigned int mode) { +static mp_obj_t mod_json_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} }, @@ -81,34 +81,34 @@ STATIC mp_obj_t mod_json_dump_helper(size_t n_args, const mp_obj_t *pos_args, mp } } -STATIC mp_obj_t mod_json_dump(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t mod_json_dump(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { return mod_json_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STREAM); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_json_dump_obj, 2, mod_json_dump); +static MP_DEFINE_CONST_FUN_OBJ_KW(mod_json_dump_obj, 2, mod_json_dump); -STATIC mp_obj_t mod_json_dumps(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t mod_json_dumps(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { return mod_json_dump_helper(n_args, pos_args, kw_args, DUMP_MODE_TO_STRING); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(mod_json_dumps_obj, 1, mod_json_dumps); +static MP_DEFINE_CONST_FUN_OBJ_KW(mod_json_dumps_obj, 1, mod_json_dumps); #else -STATIC mp_obj_t mod_json_dump(mp_obj_t obj, mp_obj_t stream) { +static mp_obj_t mod_json_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}; mp_obj_print_helper(&print, obj, PRINT_JSON); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_json_dump_obj, mod_json_dump); +static MP_DEFINE_CONST_FUN_OBJ_2(mod_json_dump_obj, mod_json_dump); -STATIC mp_obj_t mod_json_dumps(mp_obj_t obj) { +static mp_obj_t mod_json_dumps(mp_obj_t obj) { vstr_t vstr; mp_print_t print; vstr_init_print(&vstr, 8, &print); mp_obj_print_helper(&print, obj, PRINT_JSON); return mp_obj_new_str_from_utf8_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_json_dumps_obj, mod_json_dumps); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_json_dumps_obj, mod_json_dumps); #endif @@ -147,7 +147,7 @@ typedef struct _json_stream_t { #define S_CUR(s) ((s).cur) #define S_NEXT(s) (json_stream_next(&(s))) -STATIC byte json_stream_next(json_stream_t *s) { +static byte json_stream_next(json_stream_t *s) { mp_uint_t ret = s->read(s->stream_obj, &s->cur, 1, &s->errcode); // CIRCUITPY-CHANGE JSON_DEBUG(" usjon_stream_next err:%2d cur: %c \n", s->errcode, s->cur); @@ -167,7 +167,7 @@ STATIC byte json_stream_next(json_stream_t *s) { #define CIRCUITPY_JSON_READ_CHUNK_SIZE 64 -STATIC mp_uint_t json_python_readinto(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t json_python_readinto(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) { (void)size; // Ignore size because we know it's always 1. json_stream_t *s = obj; @@ -190,7 +190,7 @@ STATIC mp_uint_t json_python_readinto(mp_obj_t obj, void *buf, mp_uint_t size, i return 1; } -STATIC mp_obj_t _mod_json_load(mp_obj_t stream_obj, bool return_first_json) { +static mp_obj_t _mod_json_load(mp_obj_t stream_obj, bool return_first_json) { const mp_stream_p_t *stream_p = mp_proto_get(0, stream_obj); json_stream_t s; uint8_t character_buffer[CIRCUITPY_JSON_READ_CHUNK_SIZE]; @@ -431,12 +431,12 @@ STATIC mp_obj_t _mod_json_load(mp_obj_t stream_obj, bool return_first_json) { } // CIRCUITPY-CHANGE -STATIC mp_obj_t mod_json_load(mp_obj_t stream_obj) { +static mp_obj_t mod_json_load(mp_obj_t stream_obj) { return _mod_json_load(stream_obj, true); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_json_load_obj, mod_json_load); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_json_load_obj, mod_json_load); -STATIC mp_obj_t mod_json_loads(mp_obj_t obj) { +static mp_obj_t mod_json_loads(mp_obj_t obj) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(obj, &bufinfo, MP_BUFFER_READ); vstr_t vstr = {bufinfo.len, bufinfo.len, (char *)bufinfo.buf, true}; @@ -444,9 +444,9 @@ STATIC mp_obj_t mod_json_loads(mp_obj_t obj) { // CIRCUITPY-CHANGE return _mod_json_load(MP_OBJ_FROM_PTR(&sio), false); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_json_loads_obj, mod_json_loads); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_json_loads_obj, mod_json_loads); -STATIC const mp_rom_map_elem_t mp_module_json_globals_table[] = { +static const mp_rom_map_elem_t mp_module_json_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_json) }, { MP_ROM_QSTR(MP_QSTR_dump), MP_ROM_PTR(&mod_json_dump_obj) }, { MP_ROM_QSTR(MP_QSTR_dumps), MP_ROM_PTR(&mod_json_dumps_obj) }, @@ -454,7 +454,7 @@ STATIC const mp_rom_map_elem_t mp_module_json_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_loads), MP_ROM_PTR(&mod_json_loads_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_json_globals, mp_module_json_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_json_globals, mp_module_json_globals_table); const mp_obj_module_t mp_module_json = { .base = { &mp_type_module }, diff --git a/extmod/modmachine.c b/extmod/modmachine.c deleted file mode 100644 index a64b8ba79d43a..0000000000000 --- a/extmod/modmachine.c +++ /dev/null @@ -1,242 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2023 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. - */ - -#include "py/runtime.h" - -#if MICROPY_PY_MACHINE - -#include "extmod/modmachine.h" -#include "shared/runtime/pyexec.h" - -#if MICROPY_PY_MACHINE_DHT_READINTO -#include "drivers/dht/dht.h" -#endif - -// The port must provide implementations of these low-level machine functions. - -STATIC void mp_machine_idle(void); - -#if MICROPY_PY_MACHINE_BOOTLOADER -NORETURN void mp_machine_bootloader(size_t n_args, const mp_obj_t *args); -#endif - -#if MICROPY_PY_MACHINE_BARE_METAL_FUNCS -STATIC mp_obj_t mp_machine_unique_id(void); -NORETURN STATIC void mp_machine_reset(void); -STATIC mp_int_t mp_machine_reset_cause(void); -STATIC mp_obj_t mp_machine_get_freq(void); -STATIC void mp_machine_set_freq(size_t n_args, const mp_obj_t *args); -STATIC void mp_machine_lightsleep(size_t n_args, const mp_obj_t *args); -NORETURN STATIC void mp_machine_deepsleep(size_t n_args, const mp_obj_t *args); -#endif - -// The port can provide additional machine-module implementation in this file. -#ifdef MICROPY_PY_MACHINE_INCLUDEFILE -#include MICROPY_PY_MACHINE_INCLUDEFILE -#endif - -STATIC mp_obj_t machine_soft_reset(void) { - pyexec_system_exit = PYEXEC_FORCED_EXIT; - mp_raise_type(&mp_type_SystemExit); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_soft_reset_obj, machine_soft_reset); - -#if MICROPY_PY_MACHINE_BOOTLOADER -NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args) { - mp_machine_bootloader(n_args, args); -} -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj, 0, 1, machine_bootloader); -#endif - -STATIC mp_obj_t machine_idle(void) { - mp_machine_idle(); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_idle_obj, machine_idle); - -#if MICROPY_PY_MACHINE_BARE_METAL_FUNCS - -STATIC mp_obj_t machine_unique_id(void) { - return mp_machine_unique_id(); -} -MP_DEFINE_CONST_FUN_OBJ_0(machine_unique_id_obj, machine_unique_id); - -NORETURN STATIC mp_obj_t machine_reset(void) { - mp_machine_reset(); -} -MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_obj, machine_reset); - -STATIC mp_obj_t machine_reset_cause(void) { - return MP_OBJ_NEW_SMALL_INT(mp_machine_reset_cause()); -} -MP_DEFINE_CONST_FUN_OBJ_0(machine_reset_cause_obj, machine_reset_cause); - -STATIC mp_obj_t machine_freq(size_t n_args, const mp_obj_t *args) { - if (n_args == 0) { - return mp_machine_get_freq(); - } else { - mp_machine_set_freq(n_args, args); - return mp_const_none; - } -} -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj, 0, 1, machine_freq); - -STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) { - mp_machine_lightsleep(n_args, args); - return mp_const_none; -} -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lightsleep_obj, 0, 1, machine_lightsleep); - -NORETURN STATIC mp_obj_t machine_deepsleep(size_t n_args, const mp_obj_t *args) { - mp_machine_deepsleep(n_args, args); -} -MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj, 0, 1, machine_deepsleep); - -#endif - -#if MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ - -STATIC mp_obj_t machine_disable_irq(void) { - uint32_t state = MICROPY_BEGIN_ATOMIC_SECTION(); - return mp_obj_new_int(state); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_0(machine_disable_irq_obj, machine_disable_irq); - -STATIC mp_obj_t machine_enable_irq(mp_obj_t state_in) { - uint32_t state = mp_obj_get_int(state_in); - MICROPY_END_ATOMIC_SECTION(state); - return mp_const_none; -} -STATIC MP_DEFINE_CONST_FUN_OBJ_1(machine_enable_irq_obj, machine_enable_irq); - -#endif - -STATIC const mp_rom_map_elem_t machine_module_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_machine) }, - - // Memory access objects. - { MP_ROM_QSTR(MP_QSTR_mem8), MP_ROM_PTR(&machine_mem8_obj) }, - { MP_ROM_QSTR(MP_QSTR_mem16), MP_ROM_PTR(&machine_mem16_obj) }, - { MP_ROM_QSTR(MP_QSTR_mem32), MP_ROM_PTR(&machine_mem32_obj) }, - - // Miscellaneous functions. - #if MICROPY_PY_MACHINE_BARE_METAL_FUNCS - { MP_ROM_QSTR(MP_QSTR_unique_id), MP_ROM_PTR(&machine_unique_id_obj) }, - #endif - - // Reset related functions. - { MP_ROM_QSTR(MP_QSTR_soft_reset), MP_ROM_PTR(&machine_soft_reset_obj) }, - #if MICROPY_PY_MACHINE_BOOTLOADER - { MP_ROM_QSTR(MP_QSTR_bootloader), MP_ROM_PTR(&machine_bootloader_obj) }, - #endif - #if MICROPY_PY_MACHINE_BARE_METAL_FUNCS - { MP_ROM_QSTR(MP_QSTR_reset), MP_ROM_PTR(&machine_reset_obj) }, - { MP_ROM_QSTR(MP_QSTR_reset_cause), MP_ROM_PTR(&machine_reset_cause_obj) }, - #endif - - // Power related functions. - { MP_ROM_QSTR(MP_QSTR_idle), MP_ROM_PTR(&machine_idle_obj) }, - #if MICROPY_PY_MACHINE_BARE_METAL_FUNCS - { MP_ROM_QSTR(MP_QSTR_freq), MP_ROM_PTR(&machine_freq_obj) }, - { MP_ROM_QSTR(MP_QSTR_lightsleep), MP_ROM_PTR(&machine_lightsleep_obj) }, - { MP_ROM_QSTR(MP_QSTR_deepsleep), MP_ROM_PTR(&machine_deepsleep_obj) }, - #endif - - // Interrupt related functions. - #if MICROPY_PY_MACHINE_DISABLE_IRQ_ENABLE_IRQ - { MP_ROM_QSTR(MP_QSTR_disable_irq), MP_ROM_PTR(&machine_disable_irq_obj) }, - { MP_ROM_QSTR(MP_QSTR_enable_irq), MP_ROM_PTR(&machine_enable_irq_obj) }, - #endif - - // Functions for bit protocols. - #if MICROPY_PY_MACHINE_BITSTREAM - { MP_ROM_QSTR(MP_QSTR_bitstream), MP_ROM_PTR(&machine_bitstream_obj) }, - #endif - #if MICROPY_PY_MACHINE_DHT_READINTO - { MP_ROM_QSTR(MP_QSTR_dht_readinto), MP_ROM_PTR(&dht_readinto_obj) }, - #endif - #if MICROPY_PY_MACHINE_PULSE - { MP_ROM_QSTR(MP_QSTR_time_pulse_us), MP_ROM_PTR(&machine_time_pulse_us_obj) }, - #endif - - // Classes for PinBase and Signal. - #if MICROPY_PY_MACHINE_PIN_BASE - { MP_ROM_QSTR(MP_QSTR_PinBase), MP_ROM_PTR(&machine_pinbase_type) }, - #endif - { MP_ROM_QSTR(MP_QSTR_Signal), MP_ROM_PTR(&machine_signal_type) }, - - // Classes for software bus protocols. - #if MICROPY_PY_MACHINE_SOFTI2C - { MP_ROM_QSTR(MP_QSTR_SoftI2C), MP_ROM_PTR(&mp_machine_soft_i2c_type) }, - #endif - #if MICROPY_PY_MACHINE_SOFTSPI - { MP_ROM_QSTR(MP_QSTR_SoftSPI), MP_ROM_PTR(&mp_machine_soft_spi_type) }, - #endif - - // Classes for hardware peripherals. - #if MICROPY_PY_MACHINE_ADC - { MP_ROM_QSTR(MP_QSTR_ADC), MP_ROM_PTR(&machine_adc_type) }, - #endif - #if MICROPY_PY_MACHINE_ADC_BLOCK - { MP_ROM_QSTR(MP_QSTR_ADCBlock), MP_ROM_PTR(&machine_adc_block_type) }, - #endif - #if MICROPY_PY_MACHINE_DAC - { MP_ROM_QSTR(MP_QSTR_DAC), MP_ROM_PTR(&machine_dac_type) }, - #endif - #if MICROPY_PY_MACHINE_I2C - { MP_ROM_QSTR(MP_QSTR_I2C), MP_ROM_PTR(&machine_i2c_type) }, - #endif - #if MICROPY_PY_MACHINE_I2S - { MP_ROM_QSTR(MP_QSTR_I2S), MP_ROM_PTR(&machine_i2s_type) }, - #endif - #if MICROPY_PY_MACHINE_PWM - { MP_ROM_QSTR(MP_QSTR_PWM), MP_ROM_PTR(&machine_pwm_type) }, - #endif - #if MICROPY_PY_MACHINE_SPI - { MP_ROM_QSTR(MP_QSTR_SPI), MP_ROM_PTR(&machine_spi_type) }, - #endif - #if MICROPY_PY_MACHINE_UART - { MP_ROM_QSTR(MP_QSTR_UART), MP_ROM_PTR(&machine_uart_type) }, - #endif - #if MICROPY_PY_MACHINE_WDT - { MP_ROM_QSTR(MP_QSTR_WDT), MP_ROM_PTR(&machine_wdt_type) }, - #endif - - // A port can add extra entries to the module by defining the following macro. - #ifdef MICROPY_PY_MACHINE_EXTRA_GLOBALS - MICROPY_PY_MACHINE_EXTRA_GLOBALS - #endif -}; -STATIC MP_DEFINE_CONST_DICT(machine_module_globals, machine_module_globals_table); - -const mp_obj_module_t mp_module_machine = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&machine_module_globals, -}; - -MP_REGISTER_EXTENSIBLE_MODULE(MP_QSTR_machine, mp_module_machine); - -#endif // MICROPY_PY_MACHINE diff --git a/extmod/modmachine.h b/extmod/modmachine.h deleted file mode 100644 index d186ce661510c..0000000000000 --- a/extmod/modmachine.h +++ /dev/null @@ -1,269 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2023 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 MICROPY_INCLUDED_EXTMOD_MODMACHINE_H -#define MICROPY_INCLUDED_EXTMOD_MODMACHINE_H - -#include "py/mphal.h" -#include "py/obj.h" - -#if MICROPY_PY_MACHINE - -#include "drivers/bus/spi.h" - -// Whether to enable the ADC.init() method. -// Requires a port to implement mp_machine_adc_init_helper(). -#ifndef MICROPY_PY_MACHINE_ADC_INIT -#define MICROPY_PY_MACHINE_ADC_INIT (0) -#endif - -// Whether to enable the ADC.deinit() method. -// Requires a port to implement mp_machine_adc_deinit(). -#ifndef MICROPY_PY_MACHINE_ADC_DEINIT -#define MICROPY_PY_MACHINE_ADC_DEINIT (0) -#endif - -// Whether to enable the ADC.block() method. -// Requires a port to implement mp_machine_adc_block(). -#ifndef MICROPY_PY_MACHINE_ADC_BLOCK -#define MICROPY_PY_MACHINE_ADC_BLOCK (0) -#endif - -// Whether to enable the ADC.read_uv() method. -// Requires a port to implement mp_machine_adc_read_uv(). -#ifndef MICROPY_PY_MACHINE_ADC_READ_UV -#define MICROPY_PY_MACHINE_ADC_READ_UV (0) -#endif - -// Whether to enable the ADC.atten() and ADC.width() methods. -// Note: these are legacy and should not be used on new ports. -#ifndef MICROPY_PY_MACHINE_ADC_ATTEN_WIDTH -#define MICROPY_PY_MACHINE_ADC_ATTEN_WIDTH (0) -#endif - -// Whether to enable the ADC.read() method. -// Note: this is legacy and should not be used on new ports. -#ifndef MICROPY_PY_MACHINE_ADC_READ -#define MICROPY_PY_MACHINE_ADC_READ (0) -#endif - -// Whether to enable the UART.sendbreak() method. -// Requires a port to implement mp_machine_uart_sendbreak(). -#ifndef MICROPY_PY_MACHINE_UART_SENDBREAK -#define MICROPY_PY_MACHINE_UART_SENDBREAK (0) -#endif - -// Whether to enable the UART.readchar() and UART.writechar() methods. -// Requires a port to implement mp_machine_uart_readchar() and mp_machine_uart_writechar(). -#ifndef MICROPY_PY_MACHINE_UART_READCHAR_WRITECHAR -#define MICROPY_PY_MACHINE_UART_READCHAR_WRITECHAR (0) -#endif - -// Whether to enable the UART.irq() method. -// Requires a port to implement mp_machine_uart_irq(). -#ifndef MICROPY_PY_MACHINE_UART_IRQ -#define MICROPY_PY_MACHINE_UART_IRQ (0) -#endif - -// Temporary support for legacy construction of SoftI2C via I2C type. -#define MP_MACHINE_I2C_CHECK_FOR_LEGACY_SOFTI2C_CONSTRUCTION(n_args, n_kw, all_args) \ - do { \ - if (n_args == 0 || all_args[0] == MP_OBJ_NEW_SMALL_INT(-1)) { \ - mp_print_str(MICROPY_ERROR_PRINTER, "Warning: I2C(-1, ...) is deprecated, use SoftI2C(...) instead\n"); \ - if (n_args != 0) { \ - --n_args; \ - ++all_args; \ - } \ - return MP_OBJ_TYPE_GET_SLOT(&mp_machine_soft_i2c_type, make_new)(&mp_machine_soft_i2c_type, n_args, n_kw, all_args); \ - } \ - } while (0) - -// Temporary support for legacy construction of SoftSPI via SPI type. -#define MP_MACHINE_SPI_CHECK_FOR_LEGACY_SOFTSPI_CONSTRUCTION(n_args, n_kw, all_args) \ - do { \ - if (n_args == 0 || all_args[0] == MP_OBJ_NEW_SMALL_INT(-1)) { \ - mp_print_str(MICROPY_ERROR_PRINTER, "Warning: SPI(-1, ...) is deprecated, use SoftSPI(...) instead\n"); \ - if (n_args != 0) { \ - --n_args; \ - ++all_args; \ - } \ - return MP_OBJ_TYPE_GET_SLOT(&mp_machine_soft_spi_type, make_new)(&mp_machine_soft_spi_type, n_args, n_kw, all_args); \ - } \ - } while (0) - -#if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SOFTI2C - -#define MP_MACHINE_I2C_FLAG_READ (0x01) // if not set then it's a write -#define MP_MACHINE_I2C_FLAG_STOP (0x02) - -#if MICROPY_PY_MACHINE_I2C_TRANSFER_WRITE1 -// If set, the first mp_machine_i2c_buf_t in a transfer is a write. -#define MP_MACHINE_I2C_FLAG_WRITE1 (0x04) -#endif - -#endif - -// A port must provide these types, but they are otherwise opaque. -typedef struct _machine_adc_obj_t machine_adc_obj_t; -typedef struct _machine_adc_block_obj_t machine_adc_block_obj_t; -typedef struct _machine_i2s_obj_t machine_i2s_obj_t; -typedef struct _machine_pwm_obj_t machine_pwm_obj_t; -typedef struct _machine_uart_obj_t machine_uart_obj_t; -typedef struct _machine_wdt_obj_t machine_wdt_obj_t; - -typedef struct _machine_mem_obj_t { - mp_obj_base_t base; - unsigned elem_size; // in bytes -} machine_mem_obj_t; - -#if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SOFTI2C - -typedef struct _mp_machine_i2c_buf_t { - size_t len; - uint8_t *buf; -} mp_machine_i2c_buf_t; - -// I2C protocol: -// - init must be non-NULL -// - start/stop/read/write can be NULL, meaning operation is not supported -// - transfer must be non-NULL -// - transfer_single only needs to be set if transfer=mp_machine_i2c_transfer_adaptor -typedef struct _mp_machine_i2c_p_t { - #if MICROPY_PY_MACHINE_I2C_TRANSFER_WRITE1 - bool transfer_supports_write1; - #endif - void (*init)(mp_obj_base_t *obj, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); - int (*start)(mp_obj_base_t *obj); - int (*stop)(mp_obj_base_t *obj); - int (*read)(mp_obj_base_t *obj, uint8_t *dest, size_t len, bool nack); - int (*write)(mp_obj_base_t *obj, const uint8_t *src, size_t len); - int (*transfer)(mp_obj_base_t *obj, uint16_t addr, size_t n, mp_machine_i2c_buf_t *bufs, unsigned int flags); - int (*transfer_single)(mp_obj_base_t *obj, uint16_t addr, size_t len, uint8_t *buf, unsigned int flags); -} mp_machine_i2c_p_t; - -// SoftI2C object. -typedef struct _mp_machine_soft_i2c_obj_t { - mp_obj_base_t base; - uint32_t us_delay; - uint32_t us_timeout; - mp_hal_pin_obj_t scl; - mp_hal_pin_obj_t sda; -} mp_machine_soft_i2c_obj_t; - -#endif - -#if MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_SOFTSPI - -// SPI protocol. -typedef struct _mp_machine_spi_p_t { - void (*init)(mp_obj_base_t *obj, size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args); - void (*deinit)(mp_obj_base_t *obj); // can be NULL - void (*transfer)(mp_obj_base_t *obj, size_t len, const uint8_t *src, uint8_t *dest); -} mp_machine_spi_p_t; - -// SoftSPI object. -typedef struct _mp_machine_soft_spi_obj_t { - mp_obj_base_t base; - mp_soft_spi_obj_t spi; -} mp_machine_soft_spi_obj_t; - -#endif - -// Objects for machine.mem8, machine.mem16 and machine.mem32. -extern const machine_mem_obj_t machine_mem8_obj; -extern const machine_mem_obj_t machine_mem16_obj; -extern const machine_mem_obj_t machine_mem32_obj; - -// These classes correspond to machine.Type entries in the machine module. -// Their Python bindings are implemented in extmod, and their implementation -// is provided by a port. -extern const mp_obj_type_t machine_adc_type; -extern const mp_obj_type_t machine_adc_block_type; -extern const mp_obj_type_t machine_i2c_type; -extern const mp_obj_type_t machine_i2s_type; -extern const mp_obj_type_t machine_mem_type; -extern const mp_obj_type_t machine_pin_type; -extern const mp_obj_type_t machine_pinbase_type; -extern const mp_obj_type_t machine_pwm_type; -extern const mp_obj_type_t machine_rtc_type; -extern const mp_obj_type_t machine_signal_type; -extern const mp_obj_type_t machine_spi_type; -extern const mp_obj_type_t machine_timer_type; -extern const mp_obj_type_t machine_uart_type; -extern const mp_obj_type_t machine_wdt_type; - -#if MICROPY_PY_MACHINE_SOFTI2C -extern const mp_obj_type_t mp_machine_soft_i2c_type; -#endif -#if MICROPY_PY_MACHINE_I2C || MICROPY_PY_MACHINE_SOFTI2C -extern const mp_obj_dict_t mp_machine_i2c_locals_dict; -#endif - -#if MICROPY_PY_MACHINE_SOFTSPI -extern const mp_obj_type_t mp_machine_soft_spi_type; -extern const mp_machine_spi_p_t mp_machine_soft_spi_p; -#endif -#if MICROPY_PY_MACHINE_SPI || MICROPY_PY_MACHINE_SOFTSPI -extern const mp_obj_dict_t mp_machine_spi_locals_dict; -#endif - -#if defined(MICROPY_MACHINE_MEM_GET_READ_ADDR) -uintptr_t MICROPY_MACHINE_MEM_GET_READ_ADDR(mp_obj_t addr_o, uint align); -#endif -#if defined(MICROPY_MACHINE_MEM_GET_WRITE_ADDR) -uintptr_t MICROPY_MACHINE_MEM_GET_WRITE_ADDR(mp_obj_t addr_o, uint align); -#endif - -NORETURN mp_obj_t machine_bootloader(size_t n_args, const mp_obj_t *args); -void machine_bitstream_high_low(mp_hal_pin_obj_t pin, uint32_t *timing_ns, const uint8_t *buf, size_t len); -mp_uint_t machine_time_pulse_us(mp_hal_pin_obj_t pin, int pulse_level, mp_uint_t timeout_us); - -MP_DECLARE_CONST_FUN_OBJ_0(machine_unique_id_obj); -MP_DECLARE_CONST_FUN_OBJ_0(machine_reset_obj); -MP_DECLARE_CONST_FUN_OBJ_0(machine_reset_cause_obj); -MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_freq_obj); -MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_lightsleep_obj); -MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_deepsleep_obj); -MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bootloader_obj); -MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_bitstream_obj); -MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(machine_time_pulse_us_obj); - -#if MICROPY_PY_MACHINE_I2C -int mp_machine_i2c_transfer_adaptor(mp_obj_base_t *self, uint16_t addr, size_t n, mp_machine_i2c_buf_t *bufs, unsigned int flags); -int mp_machine_soft_i2c_transfer(mp_obj_base_t *self, uint16_t addr, size_t n, mp_machine_i2c_buf_t *bufs, unsigned int flags); -#endif - -#if MICROPY_PY_MACHINE_SPI -mp_obj_t mp_machine_spi_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args); -MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_machine_spi_read_obj); -MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(mp_machine_spi_readinto_obj); -MP_DECLARE_CONST_FUN_OBJ_2(mp_machine_spi_write_obj); -MP_DECLARE_CONST_FUN_OBJ_3(mp_machine_spi_write_readinto_obj); -#endif - -#endif // MICROPY_PY_MACHINE - -#endif // MICROPY_INCLUDED_EXTMOD_MODMACHINE_H diff --git a/extmod/modos.c b/extmod/modos.c index 5a088b5202989..7f1e31fba7793 100644 --- a/extmod/modos.c +++ b/extmod/modos.c @@ -73,11 +73,12 @@ #if MICROPY_PY_OS_SYNC // sync() // Sync all filesystems. -STATIC mp_obj_t mp_os_sync(void) { +static mp_obj_t mp_os_sync(void) { #if MICROPY_VFS_FAT for (mp_vfs_mount_t *vfs = MP_STATE_VM(vfs_mount_table); vfs != NULL; vfs = vfs->next) { - // this assumes that vfs->obj is fs_user_mount_t with block device functions - disk_ioctl(MP_OBJ_TO_PTR(vfs->obj), CTRL_SYNC, NULL); + if (mp_obj_is_type(vfs->obj, &mp_fat_vfs_type)) { + disk_ioctl(MP_OBJ_TO_PTR(vfs->obj), CTRL_SYNC, NULL); + } } #endif return mp_const_none; @@ -93,20 +94,20 @@ MP_DEFINE_CONST_FUN_OBJ_0(mp_os_sync_obj, mp_os_sync); #define CONST_RELEASE const #endif -STATIC const qstr mp_os_uname_info_fields[] = { +static const qstr mp_os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine }; -STATIC const MP_DEFINE_STR_OBJ(mp_os_uname_info_sysname_obj, MICROPY_PY_SYS_PLATFORM); -STATIC const MP_DEFINE_STR_OBJ(mp_os_uname_info_nodename_obj, MICROPY_PY_SYS_PLATFORM); -STATIC CONST_RELEASE MP_DEFINE_STR_OBJ(mp_os_uname_info_release_obj, MICROPY_VERSION_STRING); -STATIC const MP_DEFINE_STR_OBJ(mp_os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE MICROPY_BUILD_TYPE_PAREN); -STATIC const MP_DEFINE_STR_OBJ(mp_os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(mp_os_uname_info_sysname_obj, MICROPY_PY_SYS_PLATFORM); +static const MP_DEFINE_STR_OBJ(mp_os_uname_info_nodename_obj, MICROPY_PY_SYS_PLATFORM); +static CONST_RELEASE MP_DEFINE_STR_OBJ(mp_os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(mp_os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE MICROPY_BUILD_TYPE_PAREN); +static const MP_DEFINE_STR_OBJ(mp_os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); -STATIC MP_DEFINE_ATTRTUPLE( +static MP_DEFINE_ATTRTUPLE( mp_os_uname_info_obj, mp_os_uname_info_fields, 5, @@ -117,7 +118,7 @@ STATIC MP_DEFINE_ATTRTUPLE( MP_ROM_PTR(&mp_os_uname_info_machine_obj) ); -STATIC mp_obj_t mp_os_uname(void) { +static mp_obj_t mp_os_uname(void) { #if MICROPY_PY_OS_UNAME_RELEASE_DYNAMIC const char *release = mp_os_uname_release(); mp_os_uname_info_release_obj.len = strlen(release); @@ -125,12 +126,12 @@ STATIC mp_obj_t mp_os_uname(void) { #endif return MP_OBJ_FROM_PTR(&mp_os_uname_info_obj); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_os_uname_obj, mp_os_uname); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_os_uname_obj, mp_os_uname); #endif #if MICROPY_PY_OS_DUPTERM_NOTIFY -STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) { +static mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) { (void)obj_in; for (;;) { int c = mp_os_dupterm_rx_chr(); @@ -141,10 +142,10 @@ STATIC mp_obj_t mp_os_dupterm_notify(mp_obj_t obj_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_dupterm_notify_obj, mp_os_dupterm_notify); #endif -STATIC const mp_rom_map_elem_t os_module_globals_table[] = { +static const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_os) }, #if MICROPY_PY_OS_GETENV_PUTENV_UNSETENV @@ -195,6 +196,10 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { #if MICROPY_VFS { MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&mp_vfs_ilistdir_obj) }, + #endif + + // The following MicroPython extensions are deprecated. Use the `vfs` module instead. + #if !MICROPY_PREVIEW_VERSION_2 && MICROPY_VFS { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&mp_vfs_mount_obj) }, { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&mp_vfs_umount_obj) }, #if MICROPY_VFS_FAT @@ -219,7 +224,7 @@ STATIC const mp_rom_map_elem_t os_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&os_mbfs_remove_obj) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table); +static MP_DEFINE_CONST_DICT(os_module_globals, os_module_globals_table); const mp_obj_module_t mp_module_os = { .base = { &mp_type_module }, diff --git a/extmod/modplatform.c b/extmod/modplatform.c index 73846f946d0ed..c6d4d31b97ec1 100644 --- a/extmod/modplatform.c +++ b/extmod/modplatform.c @@ -36,39 +36,39 @@ // platform - Access to underlying platform's identifying data -STATIC const MP_DEFINE_STR_OBJ(info_platform_obj, MICROPY_PLATFORM_SYSTEM "-" \ +static const MP_DEFINE_STR_OBJ(info_platform_obj, MICROPY_PLATFORM_SYSTEM "-" \ MICROPY_VERSION_STRING "-" MICROPY_PLATFORM_ARCH "-" MICROPY_PLATFORM_VERSION "-with-" \ MICROPY_PLATFORM_LIBC_LIB "" MICROPY_PLATFORM_LIBC_VER); -STATIC const MP_DEFINE_STR_OBJ(info_python_compiler_obj, MICROPY_PLATFORM_COMPILER); -STATIC const MP_DEFINE_STR_OBJ(info_libc_lib_obj, MICROPY_PLATFORM_LIBC_LIB); -STATIC const MP_DEFINE_STR_OBJ(info_libc_ver_obj, MICROPY_PLATFORM_LIBC_VER); -STATIC const mp_rom_obj_tuple_t info_libc_tuple_obj = { +static const MP_DEFINE_STR_OBJ(info_python_compiler_obj, MICROPY_PLATFORM_COMPILER); +static const MP_DEFINE_STR_OBJ(info_libc_lib_obj, MICROPY_PLATFORM_LIBC_LIB); +static const MP_DEFINE_STR_OBJ(info_libc_ver_obj, MICROPY_PLATFORM_LIBC_VER); +static const mp_rom_obj_tuple_t info_libc_tuple_obj = { {&mp_type_tuple}, 2, {MP_ROM_PTR(&info_libc_lib_obj), MP_ROM_PTR(&info_libc_ver_obj)} }; -STATIC mp_obj_t platform_platform(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t platform_platform(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { return MP_OBJ_FROM_PTR(&info_platform_obj); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(platform_platform_obj, 0, platform_platform); +static MP_DEFINE_CONST_FUN_OBJ_KW(platform_platform_obj, 0, platform_platform); -STATIC mp_obj_t platform_python_compiler(void) { +static mp_obj_t platform_python_compiler(void) { return MP_OBJ_FROM_PTR(&info_python_compiler_obj); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(platform_python_compiler_obj, platform_python_compiler); +static MP_DEFINE_CONST_FUN_OBJ_0(platform_python_compiler_obj, platform_python_compiler); -STATIC mp_obj_t platform_libc_ver(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t platform_libc_ver(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { return MP_OBJ_FROM_PTR(&info_libc_tuple_obj); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(platform_libc_ver_obj, 0, platform_libc_ver); +static MP_DEFINE_CONST_FUN_OBJ_KW(platform_libc_ver_obj, 0, platform_libc_ver); -STATIC const mp_rom_map_elem_t modplatform_globals_table[] = { +static const mp_rom_map_elem_t modplatform_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_platform) }, { MP_ROM_QSTR(MP_QSTR_platform), MP_ROM_PTR(&platform_platform_obj) }, { MP_ROM_QSTR(MP_QSTR_python_compiler), MP_ROM_PTR(&platform_python_compiler_obj) }, { MP_ROM_QSTR(MP_QSTR_libc_ver), MP_ROM_PTR(&platform_libc_ver_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(modplatform_globals, modplatform_globals_table); +static MP_DEFINE_CONST_DICT(modplatform_globals, modplatform_globals_table); const mp_obj_module_t mp_module_platform = { .base = { &mp_type_module }, diff --git a/extmod/modrandom.c b/extmod/modrandom.c index e65f31488bfeb..79a1b18baac2d 100644 --- a/extmod/modrandom.c +++ b/extmod/modrandom.c @@ -46,16 +46,16 @@ #if !MICROPY_ENABLE_DYNRUNTIME #if SEED_ON_IMPORT // If the state is seeded on import then keep these variables in the BSS. -STATIC uint32_t yasmarang_pad, yasmarang_n, yasmarang_d; -STATIC uint8_t yasmarang_dat; +static uint32_t yasmarang_pad, yasmarang_n, yasmarang_d; +static uint8_t yasmarang_dat; #else // Without seed-on-import these variables must be initialised via the data section. -STATIC uint32_t yasmarang_pad = 0xeda4baba, yasmarang_n = 69, yasmarang_d = 233; -STATIC uint8_t yasmarang_dat = 0; +static uint32_t yasmarang_pad = 0xeda4baba, yasmarang_n = 69, yasmarang_d = 233; +static uint8_t yasmarang_dat = 0; #endif #endif -STATIC uint32_t yasmarang(void) { +static uint32_t yasmarang(void) { yasmarang_pad += yasmarang_dat + yasmarang_d * yasmarang_n; yasmarang_pad = (yasmarang_pad << 3) + (yasmarang_pad >> 29); yasmarang_n = yasmarang_pad | 2; @@ -71,7 +71,7 @@ STATIC uint32_t yasmarang(void) { // returns an unsigned integer below the given argument // n must not be zero -STATIC uint32_t yasmarang_randbelow(uint32_t n) { +static uint32_t yasmarang_randbelow(uint32_t n) { uint32_t mask = 1; while ((n & mask) < n) { mask = (mask << 1) | 1; @@ -85,8 +85,8 @@ STATIC uint32_t yasmarang_randbelow(uint32_t n) { #endif -STATIC mp_obj_t mod_random_getrandbits(mp_obj_t num_in) { - int n = mp_obj_get_int(num_in); +static mp_obj_t mod_random_getrandbits(mp_obj_t num_in) { + mp_int_t n = mp_obj_get_int(num_in); if (n > 32 || n < 0) { mp_raise_ValueError(MP_ERROR_TEXT("bits must be 32 or less")); } @@ -98,9 +98,9 @@ STATIC mp_obj_t mod_random_getrandbits(mp_obj_t num_in) { mask >>= (32 - n); return mp_obj_new_int_from_uint(yasmarang() & mask); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_random_getrandbits_obj, mod_random_getrandbits); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_random_getrandbits_obj, mod_random_getrandbits); -STATIC mp_obj_t mod_random_seed(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_random_seed(size_t n_args, const mp_obj_t *args) { mp_uint_t seed; if (n_args == 0 || args[0] == mp_const_none) { #ifdef MICROPY_PY_RANDOM_SEED_INIT_FUNC @@ -111,22 +111,22 @@ STATIC mp_obj_t mod_random_seed(size_t n_args, const mp_obj_t *args) { } else { seed = mp_obj_get_int_truncated(args[0]); } - yasmarang_pad = seed; + yasmarang_pad = (uint32_t)seed; yasmarang_n = 69; yasmarang_d = 233; yasmarang_dat = 0; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_random_seed_obj, 0, 1, mod_random_seed); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_random_seed_obj, 0, 1, mod_random_seed); #if MICROPY_PY_RANDOM_EXTRA_FUNCS -STATIC mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) { mp_int_t start = mp_obj_get_int(args[0]); if (n_args == 1) { // range(stop) if (start > 0) { - return mp_obj_new_int(yasmarang_randbelow(start)); + return mp_obj_new_int(yasmarang_randbelow((uint32_t)start)); } else { goto error; } @@ -135,7 +135,7 @@ STATIC mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) { if (n_args == 2) { // range(start, stop) if (start < stop) { - return mp_obj_new_int(start + yasmarang_randbelow(stop - start)); + return mp_obj_new_int(start + yasmarang_randbelow((uint32_t)(stop - start))); } else { goto error; } @@ -151,7 +151,7 @@ STATIC mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) { goto error; } if (n > 0) { - return mp_obj_new_int(start + step * yasmarang_randbelow(n)); + return mp_obj_new_int(start + step * yasmarang_randbelow((uint32_t)n)); } else { goto error; } @@ -161,33 +161,33 @@ STATIC mp_obj_t mod_random_randrange(size_t n_args, const mp_obj_t *args) { error: mp_raise_ValueError(NULL); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_random_randrange_obj, 1, 3, mod_random_randrange); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_random_randrange_obj, 1, 3, mod_random_randrange); -STATIC mp_obj_t mod_random_randint(mp_obj_t a_in, mp_obj_t b_in) { +static mp_obj_t mod_random_randint(mp_obj_t a_in, mp_obj_t b_in) { mp_int_t a = mp_obj_get_int(a_in); mp_int_t b = mp_obj_get_int(b_in); if (a <= b) { - return mp_obj_new_int(a + yasmarang_randbelow(b - a + 1)); + return mp_obj_new_int(a + yasmarang_randbelow((uint32_t)(b - a + 1))); } else { mp_raise_ValueError(NULL); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_random_randint_obj, mod_random_randint); +static MP_DEFINE_CONST_FUN_OBJ_2(mod_random_randint_obj, mod_random_randint); -STATIC mp_obj_t mod_random_choice(mp_obj_t seq) { +static mp_obj_t mod_random_choice(mp_obj_t seq) { mp_int_t len = mp_obj_get_int(mp_obj_len(seq)); if (len > 0) { - return mp_obj_subscr(seq, mp_obj_new_int(yasmarang_randbelow(len)), MP_OBJ_SENTINEL); + return mp_obj_subscr(seq, mp_obj_new_int(yasmarang_randbelow((uint32_t)len)), MP_OBJ_SENTINEL); } else { mp_raise_type(&mp_type_IndexError); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_random_choice_obj, mod_random_choice); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_random_choice_obj, mod_random_choice); #if MICROPY_PY_BUILTINS_FLOAT // returns a number in the range [0..1) using Yasmarang to fill in the fraction bits -STATIC mp_float_t yasmarang_float(void) { +static mp_float_t yasmarang_float(void) { mp_float_union_t u; u.p.sgn = 0; u.p.exp = (1 << (MP_FLOAT_EXP_BITS - 1)) - 1; @@ -199,24 +199,24 @@ STATIC mp_float_t yasmarang_float(void) { return u.f - 1; } -STATIC mp_obj_t mod_random_random(void) { +static mp_obj_t mod_random_random(void) { return mp_obj_new_float(yasmarang_float()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_random_random_obj, mod_random_random); +static MP_DEFINE_CONST_FUN_OBJ_0(mod_random_random_obj, mod_random_random); -STATIC mp_obj_t mod_random_uniform(mp_obj_t a_in, mp_obj_t b_in) { +static mp_obj_t mod_random_uniform(mp_obj_t a_in, mp_obj_t b_in) { mp_float_t a = mp_obj_get_float(a_in); mp_float_t b = mp_obj_get_float(b_in); return mp_obj_new_float(a + (b - a) * yasmarang_float()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_random_uniform_obj, mod_random_uniform); +static MP_DEFINE_CONST_FUN_OBJ_2(mod_random_uniform_obj, mod_random_uniform); #endif #endif // MICROPY_PY_RANDOM_EXTRA_FUNCS #if SEED_ON_IMPORT -STATIC mp_obj_t mod_random___init__(void) { +static mp_obj_t mod_random___init__(void) { // This module may be imported by more than one name so need to ensure // that it's only ever seeded once. static bool seeded = false; @@ -226,11 +226,11 @@ STATIC mp_obj_t mod_random___init__(void) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_random___init___obj, mod_random___init__); +static MP_DEFINE_CONST_FUN_OBJ_0(mod_random___init___obj, mod_random___init__); #endif #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t mp_module_random_globals_table[] = { +static const mp_rom_map_elem_t mp_module_random_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_random) }, #if SEED_ON_IMPORT { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&mod_random___init___obj) }, @@ -248,7 +248,7 @@ STATIC const mp_rom_map_elem_t mp_module_random_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_random_globals, mp_module_random_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_random_globals, mp_module_random_globals_table); const mp_obj_module_t mp_module_random = { .base = { &mp_type_module }, diff --git a/extmod/modre.c b/extmod/modre.c index d6ea1b65b7c71..a7e784a6ac966 100644 --- a/extmod/modre.c +++ b/extmod/modre.c @@ -57,18 +57,18 @@ typedef struct _mp_obj_match_t { const char *caps[0]; } mp_obj_match_t; -STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args); +static mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args); #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_obj_type_t re_type; +static const mp_obj_type_t re_type; #endif -STATIC void match_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void match_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_match_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->num_matches); } -STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) { +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) { @@ -87,7 +87,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(match_group_obj, match_group); #if MICROPY_PY_RE_MATCH_GROUPS -STATIC mp_obj_t match_groups(mp_obj_t self_in) { +static mp_obj_t match_groups(mp_obj_t self_in) { mp_obj_match_t *self = MP_OBJ_TO_PTR(self_in); if (self->num_matches <= 1) { return mp_const_empty_tuple; @@ -104,7 +104,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(match_groups_obj, match_groups); #if MICROPY_PY_RE_MATCH_SPAN_START_END -STATIC void match_span_helper(size_t n_args, const mp_obj_t *args, mp_obj_t span[2]) { +static void match_span_helper(size_t n_args, const mp_obj_t *args, mp_obj_t span[2]) { mp_obj_match_t *self = MP_OBJ_TO_PTR(args[0]); mp_int_t no = 0; @@ -141,21 +141,21 @@ STATIC void match_span_helper(size_t n_args, const mp_obj_t *args, mp_obj_t span span[1] = mp_obj_new_int(e); } -STATIC mp_obj_t match_span(size_t n_args, const mp_obj_t *args) { +static mp_obj_t match_span(size_t n_args, const mp_obj_t *args) { mp_obj_t span[2]; match_span_helper(n_args, args, span); return mp_obj_new_tuple(2, span); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(match_span_obj, 1, 2, match_span); -STATIC mp_obj_t match_start(size_t n_args, const mp_obj_t *args) { +static mp_obj_t match_start(size_t n_args, const mp_obj_t *args) { mp_obj_t span[2]; match_span_helper(n_args, args, span); return span[0]; } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(match_start_obj, 1, 2, match_start); -STATIC mp_obj_t match_end(size_t n_args, const mp_obj_t *args) { +static mp_obj_t match_end(size_t n_args, const mp_obj_t *args) { mp_obj_t span[2]; match_span_helper(n_args, args, span); return span[1]; @@ -165,7 +165,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(match_end_obj, 1, 2, match_end); #endif #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t match_locals_dict_table[] = { +static const mp_rom_map_elem_t match_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_group), MP_ROM_PTR(&match_group_obj) }, #if MICROPY_PY_RE_MATCH_GROUPS { MP_ROM_QSTR(MP_QSTR_groups), MP_ROM_PTR(&match_groups_obj) }, @@ -177,9 +177,9 @@ STATIC const mp_rom_map_elem_t match_locals_dict_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(match_locals_dict, match_locals_dict_table); +static MP_DEFINE_CONST_DICT(match_locals_dict, match_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( match_type, MP_QSTR_match, MP_TYPE_FLAG_NONE, @@ -188,13 +188,13 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); #endif -STATIC void re_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void re_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_re_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self); } -STATIC mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) { +static mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) { (void)n_args; mp_obj_re_t *self; if (mp_obj_is_type(args[0], (mp_obj_type_t *)&re_type)) { @@ -253,17 +253,17 @@ STATIC mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) { return MP_OBJ_FROM_PTR(match); } -STATIC mp_obj_t re_match(size_t n_args, const mp_obj_t *args) { +static mp_obj_t re_match(size_t n_args, const mp_obj_t *args) { return re_exec(true, n_args, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_match_obj, 2, 4, re_match); -STATIC mp_obj_t re_search(size_t n_args, const mp_obj_t *args) { +static mp_obj_t re_search(size_t n_args, const mp_obj_t *args) { return re_exec(false, n_args, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_search_obj, 2, 4, re_search); -STATIC mp_obj_t re_split(size_t n_args, const mp_obj_t *args) { +static mp_obj_t re_split(size_t n_args, const mp_obj_t *args) { mp_obj_re_t *self = MP_OBJ_TO_PTR(args[0]); Subject subj; size_t len; @@ -310,7 +310,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_split_obj, 2, 3, re_split); #if MICROPY_PY_RE_SUB -STATIC mp_obj_t re_sub_helper(size_t n_args, const mp_obj_t *args) { +static mp_obj_t re_sub_helper(size_t n_args, const mp_obj_t *args) { mp_obj_re_t *self; if (mp_obj_is_type(args[0], (mp_obj_type_t *)&re_type)) { self = MP_OBJ_TO_PTR(args[0]); @@ -432,7 +432,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(re_sub_obj, 3, 5, re_sub_helper); #endif #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t re_locals_dict_table[] = { +static const mp_rom_map_elem_t re_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_match), MP_ROM_PTR(&re_match_obj) }, { MP_ROM_QSTR(MP_QSTR_search), MP_ROM_PTR(&re_search_obj) }, { MP_ROM_QSTR(MP_QSTR_split), MP_ROM_PTR(&re_split_obj) }, @@ -441,9 +441,9 @@ STATIC const mp_rom_map_elem_t re_locals_dict_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(re_locals_dict, re_locals_dict_table); +static MP_DEFINE_CONST_DICT(re_locals_dict, re_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( re_type, MP_QSTR_re, MP_TYPE_FLAG_NONE, @@ -452,14 +452,14 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); #endif -STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) { (void)n_args; const char *re_str = mp_obj_str_get_str(args[0]); int size = re1_5_sizecode(re_str); if (size == -1) { goto error; } - mp_obj_re_t *o = mp_obj_malloc_var(mp_obj_re_t, char, size, (mp_obj_type_t *)&re_type); + mp_obj_re_t *o = mp_obj_malloc_var(mp_obj_re_t, re.insts, char, size, (mp_obj_type_t *)&re_type); #if MICROPY_PY_RE_DEBUG int flags = 0; if (n_args > 1) { @@ -481,7 +481,7 @@ STATIC mp_obj_t mod_re_compile(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_re_compile_obj, 1, 2, mod_re_compile); #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t mp_module_re_globals_table[] = { +static const mp_rom_map_elem_t mp_module_re_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_re) }, { MP_ROM_QSTR(MP_QSTR_compile), MP_ROM_PTR(&mod_re_compile_obj) }, { MP_ROM_QSTR(MP_QSTR_match), MP_ROM_PTR(&re_match_obj) }, @@ -494,7 +494,7 @@ STATIC const mp_rom_map_elem_t mp_module_re_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_re_globals, mp_module_re_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_re_globals, mp_module_re_globals_table); const mp_obj_module_t mp_module_re = { .base = { &mp_type_module }, diff --git a/extmod/modselect.c b/extmod/modselect.c index 7d86de3cfac3a..c4edee6a56b90 100644 --- a/extmod/modselect.c +++ b/extmod/modselect.c @@ -98,7 +98,7 @@ typedef struct _poll_set_t { #endif } poll_set_t; -STATIC void poll_set_init(poll_set_t *poll_set, size_t n) { +static void poll_set_init(poll_set_t *poll_set, size_t n) { mp_map_init(&poll_set->map, n); #if MICROPY_PY_SELECT_POSIX_OPTIMISATIONS poll_set->alloc = 0; @@ -109,19 +109,19 @@ STATIC void poll_set_init(poll_set_t *poll_set, size_t n) { } #if MICROPY_PY_SELECT_SELECT -STATIC void poll_set_deinit(poll_set_t *poll_set) { +static void poll_set_deinit(poll_set_t *poll_set) { mp_map_deinit(&poll_set->map); } #endif #if MICROPY_PY_SELECT_POSIX_OPTIMISATIONS -STATIC mp_uint_t poll_obj_get_events(poll_obj_t *poll_obj) { +static mp_uint_t poll_obj_get_events(poll_obj_t *poll_obj) { assert(poll_obj->pollfd == NULL); return poll_obj->nonfd_events; } -STATIC void poll_obj_set_events(poll_obj_t *poll_obj, mp_uint_t events) { +static void poll_obj_set_events(poll_obj_t *poll_obj, mp_uint_t events) { if (poll_obj->pollfd != NULL) { poll_obj->pollfd->events = events; } else { @@ -129,7 +129,7 @@ STATIC void poll_obj_set_events(poll_obj_t *poll_obj, mp_uint_t events) { } } -STATIC mp_uint_t poll_obj_get_revents(poll_obj_t *poll_obj) { +static mp_uint_t poll_obj_get_revents(poll_obj_t *poll_obj) { if (poll_obj->pollfd != NULL) { return poll_obj->pollfd->revents; } else { @@ -137,7 +137,7 @@ STATIC mp_uint_t poll_obj_get_revents(poll_obj_t *poll_obj) { } } -STATIC void poll_obj_set_revents(poll_obj_t *poll_obj, mp_uint_t revents) { +static void poll_obj_set_revents(poll_obj_t *poll_obj, mp_uint_t revents) { if (poll_obj->pollfd != NULL) { poll_obj->pollfd->revents = revents; } else { @@ -148,7 +148,7 @@ STATIC void poll_obj_set_revents(poll_obj_t *poll_obj, mp_uint_t revents) { // How much (in pollfds) to grow the allocation for poll_set->pollfds by. #define POLL_SET_ALLOC_INCREMENT (4) -STATIC struct pollfd *poll_set_add_fd(poll_set_t *poll_set, int fd) { +static struct pollfd *poll_set_add_fd(poll_set_t *poll_set, int fd) { struct pollfd *free_slot = NULL; if (poll_set->used == poll_set->max_used) { @@ -230,7 +230,7 @@ static inline void poll_obj_set_revents(poll_obj_t *poll_obj, mp_uint_t revents) #endif -STATIC void poll_set_add_obj(poll_set_t *poll_set, const mp_obj_t *obj, mp_uint_t obj_len, mp_uint_t events, bool or_events) { +static void poll_set_add_obj(poll_set_t *poll_set, const mp_obj_t *obj, mp_uint_t obj_len, mp_uint_t events, bool or_events) { for (mp_uint_t i = 0; i < obj_len; i++) { mp_map_elem_t *elem = mp_map_lookup(&poll_set->map, mp_obj_id(obj[i]), MP_MAP_LOOKUP_ADD_IF_NOT_FOUND); if (elem->value == MP_OBJ_NULL) { @@ -292,7 +292,7 @@ STATIC void poll_set_add_obj(poll_set_t *poll_set, const mp_obj_t *obj, mp_uint_ } // For each object in the poll set, poll it once. -STATIC mp_uint_t poll_set_poll_once(poll_set_t *poll_set, size_t *rwx_num) { +static mp_uint_t poll_set_poll_once(poll_set_t *poll_set, size_t *rwx_num) { mp_uint_t n_ready = 0; for (mp_uint_t i = 0; i < poll_set->map.alloc; ++i) { if (!mp_map_slot_is_filled(&poll_set->map, i)) { @@ -340,7 +340,7 @@ STATIC mp_uint_t poll_set_poll_once(poll_set_t *poll_set, size_t *rwx_num) { return n_ready; } -STATIC mp_uint_t poll_set_poll_until_ready_or_timeout(poll_set_t *poll_set, size_t *rwx_num, mp_uint_t timeout) { +static mp_uint_t poll_set_poll_until_ready_or_timeout(poll_set_t *poll_set, size_t *rwx_num, mp_uint_t timeout) { mp_uint_t start_ticks = mp_hal_ticks_ms(); bool has_timeout = timeout != (mp_uint_t)-1; @@ -421,7 +421,7 @@ STATIC mp_uint_t poll_set_poll_until_ready_or_timeout(poll_set_t *poll_set, size #if MICROPY_PY_SELECT_SELECT // select(rlist, wlist, xlist[, timeout]) -STATIC mp_obj_t select_select(size_t n_args, const mp_obj_t *args) { +static mp_obj_t select_select(size_t n_args, const mp_obj_t *args) { // get array data from tuple/list arguments size_t rwx_len[3]; mp_obj_t *r_array, *w_array, *x_array; @@ -496,7 +496,7 @@ typedef struct _mp_obj_poll_t { } mp_obj_poll_t; // register(obj[, eventmask]) -STATIC mp_obj_t poll_register(size_t n_args, const mp_obj_t *args) { +static mp_obj_t poll_register(size_t n_args, const mp_obj_t *args) { mp_obj_poll_t *self = MP_OBJ_TO_PTR(args[0]); mp_uint_t events; if (n_args == 3) { @@ -510,7 +510,7 @@ STATIC mp_obj_t poll_register(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(poll_register_obj, 2, 3, poll_register); // unregister(obj) -STATIC mp_obj_t poll_unregister(mp_obj_t self_in, mp_obj_t obj_in) { +static mp_obj_t poll_unregister(mp_obj_t self_in, mp_obj_t obj_in) { mp_obj_poll_t *self = MP_OBJ_TO_PTR(self_in); mp_map_elem_t *elem = mp_map_lookup(&self->poll_set.map, mp_obj_id(obj_in), MP_MAP_LOOKUP_REMOVE_IF_FOUND); @@ -533,7 +533,7 @@ STATIC mp_obj_t poll_unregister(mp_obj_t self_in, mp_obj_t obj_in) { MP_DEFINE_CONST_FUN_OBJ_2(poll_unregister_obj, poll_unregister); // modify(obj, eventmask) -STATIC mp_obj_t poll_modify(mp_obj_t self_in, mp_obj_t obj_in, mp_obj_t eventmask_in) { +static mp_obj_t poll_modify(mp_obj_t self_in, mp_obj_t obj_in, mp_obj_t eventmask_in) { mp_obj_poll_t *self = MP_OBJ_TO_PTR(self_in); mp_map_elem_t *elem = mp_map_lookup(&self->poll_set.map, mp_obj_id(obj_in), MP_MAP_LOOKUP); if (elem == NULL) { @@ -544,7 +544,7 @@ STATIC mp_obj_t poll_modify(mp_obj_t self_in, mp_obj_t obj_in, mp_obj_t eventmas } MP_DEFINE_CONST_FUN_OBJ_3(poll_modify_obj, poll_modify); -STATIC mp_uint_t poll_poll_internal(uint n_args, const mp_obj_t *args) { +static mp_uint_t poll_poll_internal(uint n_args, const mp_obj_t *args) { mp_obj_poll_t *self = MP_OBJ_TO_PTR(args[0]); // work out timeout (its given already in ms) @@ -567,7 +567,7 @@ STATIC mp_uint_t poll_poll_internal(uint n_args, const mp_obj_t *args) { return poll_set_poll_until_ready_or_timeout(&self->poll_set, NULL, timeout); } -STATIC mp_obj_t poll_poll(size_t n_args, const mp_obj_t *args) { +static mp_obj_t poll_poll(size_t n_args, const mp_obj_t *args) { mp_obj_poll_t *self = MP_OBJ_TO_PTR(args[0]); mp_uint_t n_ready = poll_poll_internal(n_args, args); @@ -588,7 +588,7 @@ STATIC mp_obj_t poll_poll(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(poll_poll_obj, 1, 2, poll_poll); -STATIC mp_obj_t poll_ipoll(size_t n_args, const mp_obj_t *args) { +static mp_obj_t poll_ipoll(size_t n_args, const mp_obj_t *args) { mp_obj_poll_t *self = MP_OBJ_TO_PTR(args[0]); if (self->ret_tuple == MP_OBJ_NULL) { @@ -603,7 +603,7 @@ STATIC mp_obj_t poll_ipoll(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(poll_ipoll_obj, 1, 3, poll_ipoll); -STATIC mp_obj_t poll_iternext(mp_obj_t self_in) { +static mp_obj_t poll_iternext(mp_obj_t self_in) { mp_obj_poll_t *self = MP_OBJ_TO_PTR(self_in); if (self->iter_cnt == 0) { @@ -635,16 +635,16 @@ STATIC mp_obj_t poll_iternext(mp_obj_t self_in) { return MP_OBJ_STOP_ITERATION; } -STATIC const mp_rom_map_elem_t poll_locals_dict_table[] = { +static const mp_rom_map_elem_t poll_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_register), MP_ROM_PTR(&poll_register_obj) }, { MP_ROM_QSTR(MP_QSTR_unregister), MP_ROM_PTR(&poll_unregister_obj) }, { MP_ROM_QSTR(MP_QSTR_modify), MP_ROM_PTR(&poll_modify_obj) }, { MP_ROM_QSTR(MP_QSTR_poll), MP_ROM_PTR(&poll_poll_obj) }, { MP_ROM_QSTR(MP_QSTR_ipoll), MP_ROM_PTR(&poll_ipoll_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(poll_locals_dict, poll_locals_dict_table); +static MP_DEFINE_CONST_DICT(poll_locals_dict, poll_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_poll, MP_QSTR_poll, MP_TYPE_FLAG_ITER_IS_ITERNEXT, @@ -653,7 +653,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); // poll() -STATIC mp_obj_t select_poll(void) { +static mp_obj_t select_poll(void) { mp_obj_poll_t *poll = mp_obj_malloc(mp_obj_poll_t, &mp_type_poll); poll_set_init(&poll->poll_set, 0); poll->iter_cnt = 0; @@ -662,7 +662,7 @@ STATIC mp_obj_t select_poll(void) { } MP_DEFINE_CONST_FUN_OBJ_0(mp_select_poll_obj, select_poll); -STATIC const mp_rom_map_elem_t mp_module_select_globals_table[] = { +static const mp_rom_map_elem_t mp_module_select_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_select) }, #if MICROPY_PY_SELECT_SELECT { MP_ROM_QSTR(MP_QSTR_select), MP_ROM_PTR(&mp_select_select_obj) }, @@ -674,7 +674,7 @@ STATIC const mp_rom_map_elem_t mp_module_select_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_POLLHUP), MP_ROM_INT(MP_STREAM_POLL_HUP) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_select_globals, mp_module_select_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_select_globals, mp_module_select_globals_table); const mp_obj_module_t mp_module_select = { .base = { &mp_type_module }, diff --git a/extmod/modtime.c b/extmod/modtime.c index 805c2621c0b67..deb4bb4c9ace7 100644 --- a/extmod/modtime.c +++ b/extmod/modtime.c @@ -52,7 +52,7 @@ // - second is 0-59 // - weekday is 0-6 for Mon-Sun // - yearday is 1-366 -STATIC mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { +static mp_obj_t time_localtime(size_t n_args, const mp_obj_t *args) { if (n_args == 0 || args[0] == mp_const_none) { // Get current date and time. return mp_time_localtime_get(); @@ -80,7 +80,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_time_localtime_obj, 0, 1, time_localtime) // This is the inverse function of localtime. Its argument is a full 8-tuple // which expresses a time as per localtime. It returns an integer which is // the number of seconds since the Epoch (eg 1st Jan 1970, or 1st Jan 2000). -STATIC mp_obj_t time_mktime(mp_obj_t tuple) { +static mp_obj_t time_mktime(mp_obj_t tuple) { size_t len; mp_obj_t *elem; mp_obj_get_array(tuple, &len, &elem); @@ -102,21 +102,21 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_time_mktime_obj, time_mktime); // time() // Return the number of seconds since the Epoch. -STATIC mp_obj_t time_time(void) { +static mp_obj_t time_time(void) { return mp_time_time_get(); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_time_time_obj, time_time); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_time_time_obj, time_time); // time_ns() // Returns the number of nanoseconds since the Epoch, as an integer. -STATIC mp_obj_t time_time_ns(void) { +static mp_obj_t time_time_ns(void) { return mp_obj_new_int_from_ull(mp_hal_time_ns()); } MP_DEFINE_CONST_FUN_OBJ_0(mp_time_time_ns_obj, time_time_ns); #endif // MICROPY_PY_TIME_TIME_TIME_NS -STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { +static mp_obj_t time_sleep(mp_obj_t seconds_o) { #ifdef MICROPY_PY_TIME_CUSTOM_SLEEP mp_time_sleep(seconds_o); #else @@ -130,7 +130,7 @@ STATIC mp_obj_t time_sleep(mp_obj_t seconds_o) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_time_sleep_obj, time_sleep); -STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) { +static mp_obj_t time_sleep_ms(mp_obj_t arg) { mp_int_t ms = mp_obj_get_int(arg); if (ms >= 0) { mp_hal_delay_ms(ms); @@ -139,7 +139,7 @@ STATIC mp_obj_t time_sleep_ms(mp_obj_t arg) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_time_sleep_ms_obj, time_sleep_ms); -STATIC mp_obj_t time_sleep_us(mp_obj_t arg) { +static mp_obj_t time_sleep_us(mp_obj_t arg) { mp_int_t us = mp_obj_get_int(arg); if (us > 0) { mp_hal_delay_us(us); @@ -148,22 +148,22 @@ STATIC mp_obj_t time_sleep_us(mp_obj_t arg) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_time_sleep_us_obj, time_sleep_us); -STATIC mp_obj_t time_ticks_ms(void) { +static mp_obj_t time_ticks_ms(void) { return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_ms() & (MICROPY_PY_TIME_TICKS_PERIOD - 1)); } MP_DEFINE_CONST_FUN_OBJ_0(mp_time_ticks_ms_obj, time_ticks_ms); -STATIC mp_obj_t time_ticks_us(void) { +static mp_obj_t time_ticks_us(void) { return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_us() & (MICROPY_PY_TIME_TICKS_PERIOD - 1)); } MP_DEFINE_CONST_FUN_OBJ_0(mp_time_ticks_us_obj, time_ticks_us); -STATIC mp_obj_t time_ticks_cpu(void) { +static mp_obj_t time_ticks_cpu(void) { return MP_OBJ_NEW_SMALL_INT(mp_hal_ticks_cpu() & (MICROPY_PY_TIME_TICKS_PERIOD - 1)); } MP_DEFINE_CONST_FUN_OBJ_0(mp_time_ticks_cpu_obj, time_ticks_cpu); -STATIC mp_obj_t time_ticks_diff(mp_obj_t end_in, mp_obj_t start_in) { +static mp_obj_t time_ticks_diff(mp_obj_t end_in, mp_obj_t start_in) { // we assume that the arguments come from ticks_xx so are small ints mp_uint_t start = MP_OBJ_SMALL_INT_VALUE(start_in); mp_uint_t end = MP_OBJ_SMALL_INT_VALUE(end_in); @@ -175,7 +175,7 @@ STATIC mp_obj_t time_ticks_diff(mp_obj_t end_in, mp_obj_t start_in) { } MP_DEFINE_CONST_FUN_OBJ_2(mp_time_ticks_diff_obj, time_ticks_diff); -STATIC mp_obj_t time_ticks_add(mp_obj_t ticks_in, mp_obj_t delta_in) { +static mp_obj_t time_ticks_add(mp_obj_t ticks_in, mp_obj_t delta_in) { // we assume that first argument come from ticks_xx so is small int mp_uint_t ticks = MP_OBJ_SMALL_INT_VALUE(ticks_in); mp_uint_t delta = mp_obj_get_int(delta_in); @@ -196,7 +196,7 @@ STATIC mp_obj_t time_ticks_add(mp_obj_t ticks_in, mp_obj_t delta_in) { } MP_DEFINE_CONST_FUN_OBJ_2(mp_time_ticks_add_obj, time_ticks_add); -STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { +static const mp_rom_map_elem_t mp_module_time_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_time) }, #if MICROPY_PY_TIME_GMTIME_LOCALTIME_MKTIME @@ -224,7 +224,7 @@ STATIC const mp_rom_map_elem_t mp_module_time_globals_table[] = { MICROPY_PY_TIME_EXTRA_GLOBALS #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_time_globals, mp_module_time_globals_table); const mp_obj_module_t mp_module_time = { .base = { &mp_type_module }, diff --git a/extmod/moductypes.c b/extmod/moductypes.c deleted file mode 100644 index f56567107df7e..0000000000000 --- a/extmod/moductypes.c +++ /dev/null @@ -1,725 +0,0 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2014-2018 Paul Sokolovsky - * - * 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 -#include - -#include "py/runtime.h" -#include "py/objtuple.h" -#include "py/binary.h" - -#if MICROPY_PY_UCTYPES - -// The uctypes module allows defining the layout of a raw data structure (using -// terms of the C language), and then access memory buffers using this definition. -// The module also provides convenience functions to access memory buffers -// contained in Python objects or wrap memory buffers in Python objects. - -#define LAYOUT_LITTLE_ENDIAN (0) -#define LAYOUT_BIG_ENDIAN (1) -#define LAYOUT_NATIVE (2) - -#define VAL_TYPE_BITS 4 -#define BITF_LEN_BITS 5 -#define BITF_OFF_BITS 5 -#define OFFSET_BITS 17 -#define LEN_BITS (OFFSET_BITS + BITF_OFF_BITS) -#if VAL_TYPE_BITS + BITF_LEN_BITS + BITF_OFF_BITS + OFFSET_BITS != 31 -#error Invalid encoding field length -#endif - -enum { - UINT8, INT8, UINT16, INT16, - UINT32, INT32, UINT64, INT64, - - BFUINT8, BFINT8, BFUINT16, BFINT16, - BFUINT32, BFINT32, - - FLOAT32, FLOAT64, -}; - -#define AGG_TYPE_BITS 2 - -enum { - STRUCT, PTR, ARRAY, -}; - -// Here we need to set sign bit right -#define TYPE2SMALLINT(x, nbits) ((((int)x) << (32 - nbits)) >> 1) -#define GET_TYPE(x, nbits) (((x) >> (31 - nbits)) & ((1 << nbits) - 1)) -// Bit 0 is "is_signed" -#define GET_SCALAR_SIZE(val_type) (1 << ((val_type) >> 1)) -#define VALUE_MASK(type_nbits) ~((int)0x80000000 >> type_nbits) - -#define IS_SCALAR_ARRAY(tuple_desc) ((tuple_desc)->len == 2) -// We cannot apply the below to INT8, as their range [-128, 127] -#define IS_SCALAR_ARRAY_OF_BYTES(tuple_desc) (GET_TYPE(MP_OBJ_SMALL_INT_VALUE((tuple_desc)->items[1]), VAL_TYPE_BITS) == UINT8) - -// "struct" in uctypes context means "structural", i.e. aggregate, type. -STATIC const mp_obj_type_t uctypes_struct_type; - -typedef struct _mp_obj_uctypes_struct_t { - mp_obj_base_t base; - mp_obj_t desc; - byte *addr; - uint32_t flags; -} mp_obj_uctypes_struct_t; - -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, 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 = mp_obj_malloc(mp_obj_uctypes_struct_t, type); - o->addr = (void *)(uintptr_t)mp_obj_get_int_truncated(args[0]); - o->desc = args[1]; - o->flags = LAYOUT_NATIVE; - if (n_args == 3) { - o->flags = mp_obj_get_int(args[2]); - } - return MP_OBJ_FROM_PTR(o); -} - -STATIC void uctypes_struct_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { - (void)kind; - mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in); - const char *typen = "unk"; - if (mp_obj_is_dict_or_ordereddict(self->desc)) { - typen = "STRUCT"; - } else if (mp_obj_is_type(self->desc, &mp_type_tuple)) { - mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->desc); - mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]); - uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS); - switch (agg_type) { - case PTR: - typen = "PTR"; - break; - case ARRAY: - typen = "ARRAY"; - break; - } - } else { - typen = "ERROR"; - } - mp_printf(print, "", typen, self->addr); -} - -// Get size of any type descriptor -STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_t *max_field_size); - -// Get size of scalar type descriptor -static inline mp_uint_t uctypes_struct_scalar_size(int val_type) { - if (val_type == FLOAT32) { - return 4; - } else { - return GET_SCALAR_SIZE(val_type & 7); - } -} - -// Get size of aggregate type descriptor -STATIC mp_uint_t uctypes_struct_agg_size(mp_obj_tuple_t *t, int layout_type, mp_uint_t *max_field_size) { - mp_uint_t total_size = 0; - - mp_int_t offset_ = MP_OBJ_SMALL_INT_VALUE(t->items[0]); - mp_uint_t agg_type = GET_TYPE(offset_, AGG_TYPE_BITS); - - switch (agg_type) { - case STRUCT: - return uctypes_struct_size(t->items[1], layout_type, max_field_size); - case PTR: - if (sizeof(void *) > *max_field_size) { - *max_field_size = sizeof(void *); - } - return sizeof(void *); - case ARRAY: { - mp_int_t arr_sz = MP_OBJ_SMALL_INT_VALUE(t->items[1]); - uint val_type = GET_TYPE(arr_sz, VAL_TYPE_BITS); - arr_sz &= VALUE_MASK(VAL_TYPE_BITS); - mp_uint_t item_s; - if (t->len == 2) { - // Elements of array are scalar - item_s = uctypes_struct_scalar_size(val_type); - if (item_s > *max_field_size) { - *max_field_size = item_s; - } - } else { - // Elements of array are aggregates - item_s = uctypes_struct_size(t->items[2], layout_type, max_field_size); - } - - return item_s * arr_sz; - } - default: - assert(0); - } - - return total_size; -} - -STATIC mp_uint_t uctypes_struct_size(mp_obj_t desc_in, int layout_type, mp_uint_t *max_field_size) { - if (!mp_obj_is_dict_or_ordereddict(desc_in)) { - if (mp_obj_is_type(desc_in, &mp_type_tuple)) { - return uctypes_struct_agg_size((mp_obj_tuple_t *)MP_OBJ_TO_PTR(desc_in), layout_type, max_field_size); - } else if (mp_obj_is_small_int(desc_in)) { - // We allow sizeof on both type definitions and structures/structure fields, - // but scalar structure field is lowered into native Python int, so all - // type info is lost. So, we cannot say if it's scalar type description, - // or such lowered scalar. - mp_raise_TypeError(MP_ERROR_TEXT("can't unambiguously get sizeof scalar")); - } - syntax_error(); - } - - mp_obj_dict_t *d = MP_OBJ_TO_PTR(desc_in); - mp_uint_t total_size = 0; - - for (mp_uint_t i = 0; i < d->map.alloc; i++) { - if (mp_map_slot_is_filled(&d->map, i)) { - mp_obj_t v = d->map.table[i].value; - if (mp_obj_is_small_int(v)) { - mp_uint_t offset = MP_OBJ_SMALL_INT_VALUE(v); - mp_uint_t val_type = GET_TYPE(offset, VAL_TYPE_BITS); - offset &= VALUE_MASK(VAL_TYPE_BITS); - if (val_type >= BFUINT8 && val_type <= BFINT32) { - offset &= (1 << OFFSET_BITS) - 1; - } - mp_uint_t s = uctypes_struct_scalar_size(val_type); - if (s > *max_field_size) { - *max_field_size = s; - } - if (offset + s > total_size) { - total_size = offset + s; - } - } else { - if (!mp_obj_is_type(v, &mp_type_tuple)) { - syntax_error(); - } - mp_obj_tuple_t *t = MP_OBJ_TO_PTR(v); - mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]); - offset &= VALUE_MASK(AGG_TYPE_BITS); - mp_uint_t s = uctypes_struct_agg_size(t, layout_type, max_field_size); - if (offset + s > total_size) { - total_size = offset + s; - } - } - } - } - - // Round size up to alignment of biggest field - if (layout_type == LAYOUT_NATIVE) { - total_size = (total_size + *max_field_size - 1) & ~(*max_field_size - 1); - } - return total_size; -} - -STATIC mp_obj_t uctypes_struct_sizeof(size_t n_args, const mp_obj_t *args) { - mp_obj_t obj_in = args[0]; - mp_uint_t max_field_size = 0; - if (mp_obj_is_type(obj_in, &mp_type_bytearray)) { - return mp_obj_len(obj_in); - } - int layout_type = LAYOUT_NATIVE; - // We can apply sizeof either to structure definition (a dict) - // or to instantiated structure - if (mp_obj_is_type(obj_in, &uctypes_struct_type)) { - if (n_args != 1) { - mp_raise_TypeError(NULL); - } - // Extract structure definition - mp_obj_uctypes_struct_t *obj = MP_OBJ_TO_PTR(obj_in); - obj_in = obj->desc; - layout_type = obj->flags; - } else { - if (n_args == 2) { - layout_type = mp_obj_get_int(args[1]); - } - } - mp_uint_t size = uctypes_struct_size(obj_in, layout_type, &max_field_size); - return MP_OBJ_NEW_SMALL_INT(size); -} -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(uctypes_struct_sizeof_obj, 1, 2, uctypes_struct_sizeof); - -static inline mp_obj_t get_unaligned(uint val_type, byte *p, int big_endian) { - char struct_type = big_endian ? '>' : '<'; - static const char type2char[16] = "BbHhIiQq------fd"; - return mp_binary_get_val(struct_type, type2char[val_type], p, &p); -} - -static inline void set_unaligned(uint val_type, byte *p, int big_endian, mp_obj_t val) { - char struct_type = big_endian ? '>' : '<'; - static const char type2char[16] = "BbHhIiQq------fd"; - mp_binary_set_val(struct_type, type2char[val_type], val, p, &p); -} - -static inline mp_uint_t get_aligned_basic(uint val_type, void *p) { - switch (val_type) { - case UINT8: - return *(uint8_t *)p; - case UINT16: - return *(uint16_t *)p; - case UINT32: - return *(uint32_t *)p; - } - assert(0); - return 0; -} - -static inline void set_aligned_basic(uint val_type, void *p, mp_uint_t v) { - switch (val_type) { - case UINT8: - *(uint8_t *)p = (uint8_t)v; - return; - case UINT16: - *(uint16_t *)p = (uint16_t)v; - return; - case UINT32: - *(uint32_t *)p = (uint32_t)v; - return; - } - assert(0); -} - -STATIC mp_obj_t get_aligned(uint val_type, void *p, mp_int_t index) { - switch (val_type) { - case UINT8: - return MP_OBJ_NEW_SMALL_INT(((uint8_t *)p)[index]); - case INT8: - return MP_OBJ_NEW_SMALL_INT(((int8_t *)p)[index]); - case UINT16: - return MP_OBJ_NEW_SMALL_INT(((uint16_t *)p)[index]); - case INT16: - return MP_OBJ_NEW_SMALL_INT(((int16_t *)p)[index]); - case UINT32: - return mp_obj_new_int_from_uint(((uint32_t *)p)[index]); - case INT32: - return mp_obj_new_int(((int32_t *)p)[index]); - case UINT64: - return mp_obj_new_int_from_ull(((uint64_t *)p)[index]); - case INT64: - return mp_obj_new_int_from_ll(((int64_t *)p)[index]); - #if MICROPY_PY_BUILTINS_FLOAT - case FLOAT32: - return mp_obj_new_float_from_f(((float *)p)[index]); - case FLOAT64: - return mp_obj_new_float_from_d(((double *)p)[index]); - #endif - default: - assert(0); - return MP_OBJ_NULL; - } -} - -STATIC void set_aligned(uint val_type, void *p, mp_int_t index, mp_obj_t val) { - #if MICROPY_PY_BUILTINS_FLOAT - if (val_type == FLOAT32 || val_type == FLOAT64) { - if (val_type == FLOAT32) { - ((float *)p)[index] = mp_obj_get_float_to_f(val); - } else { - ((double *)p)[index] = mp_obj_get_float_to_d(val); - } - return; - } - #endif - mp_int_t v = mp_obj_get_int_truncated(val); - switch (val_type) { - case UINT8: - ((uint8_t *)p)[index] = (uint8_t)v; - return; - case INT8: - ((int8_t *)p)[index] = (int8_t)v; - return; - case UINT16: - ((uint16_t *)p)[index] = (uint16_t)v; - return; - case INT16: - ((int16_t *)p)[index] = (int16_t)v; - return; - case UINT32: - ((uint32_t *)p)[index] = (uint32_t)v; - return; - case INT32: - ((int32_t *)p)[index] = (int32_t)v; - return; - case INT64: - case UINT64: - if (sizeof(mp_int_t) == 8) { - ((uint64_t *)p)[index] = (uint64_t)v; - } else { - // TODO: Doesn't offer atomic store semantics, but should at least try - set_unaligned(val_type, (void *)&((uint64_t *)p)[index], MP_ENDIANNESS_BIG, val); - } - return; - default: - assert(0); - } -} - -STATIC mp_obj_t uctypes_struct_attr_op(mp_obj_t self_in, qstr attr, mp_obj_t set_val) { - mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in); - - if (!mp_obj_is_dict_or_ordereddict(self->desc)) { - mp_raise_TypeError(MP_ERROR_TEXT("struct: no fields")); - } - - mp_obj_t deref = mp_obj_dict_get(self->desc, MP_OBJ_NEW_QSTR(attr)); - if (mp_obj_is_small_int(deref)) { - mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(deref); - mp_uint_t val_type = GET_TYPE(offset, VAL_TYPE_BITS); - offset &= VALUE_MASK(VAL_TYPE_BITS); - - if (val_type <= INT64 || val_type == FLOAT32 || val_type == FLOAT64) { - if (self->flags == LAYOUT_NATIVE) { - if (set_val == MP_OBJ_NULL) { - return get_aligned(val_type, self->addr + offset, 0); - } else { - set_aligned(val_type, self->addr + offset, 0, set_val); - return set_val; // just !MP_OBJ_NULL - } - } else { - if (set_val == MP_OBJ_NULL) { - return get_unaligned(val_type, self->addr + offset, self->flags); - } else { - set_unaligned(val_type, self->addr + offset, self->flags, set_val); - return set_val; // just !MP_OBJ_NULL - } - } - } else if (val_type >= BFUINT8 && val_type <= BFINT32) { - uint bit_offset = (offset >> OFFSET_BITS) & 31; - uint bit_len = (offset >> LEN_BITS) & 31; - offset &= (1 << OFFSET_BITS) - 1; - mp_uint_t val; - if (self->flags == LAYOUT_NATIVE) { - val = get_aligned_basic(val_type & 6, self->addr + offset); - } else { - val = mp_binary_get_int(GET_SCALAR_SIZE(val_type & 7), val_type & 1, self->flags, self->addr + offset); - } - if (set_val == MP_OBJ_NULL) { - val >>= bit_offset; - val &= (1 << bit_len) - 1; - // TODO: signed - assert((val_type & 1) == 0); - return mp_obj_new_int(val); - } else { - mp_uint_t set_val_int = (mp_uint_t)mp_obj_get_int(set_val); - mp_uint_t mask = (1 << bit_len) - 1; - set_val_int &= mask; - set_val_int <<= bit_offset; - mask <<= bit_offset; - val = (val & ~mask) | set_val_int; - - if (self->flags == LAYOUT_NATIVE) { - set_aligned_basic(val_type & 6, self->addr + offset, val); - } else { - mp_binary_set_int(GET_SCALAR_SIZE(val_type & 7), self->flags == LAYOUT_BIG_ENDIAN, - self->addr + offset, val); - } - return set_val; // just !MP_OBJ_NULL - } - } - - assert(0); - return MP_OBJ_NULL; - } - - if (!mp_obj_is_type(deref, &mp_type_tuple)) { - syntax_error(); - } - - if (set_val != MP_OBJ_NULL) { - // Cannot assign to aggregate - syntax_error(); - } - - mp_obj_tuple_t *sub = MP_OBJ_TO_PTR(deref); - mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(sub->items[0]); - mp_uint_t agg_type = GET_TYPE(offset, AGG_TYPE_BITS); - offset &= VALUE_MASK(AGG_TYPE_BITS); - - switch (agg_type) { - case STRUCT: { - mp_obj_uctypes_struct_t *o = mp_obj_malloc(mp_obj_uctypes_struct_t, &uctypes_struct_type); - o->desc = sub->items[1]; - o->addr = self->addr + offset; - o->flags = self->flags; - return MP_OBJ_FROM_PTR(o); - } - case ARRAY: { - mp_uint_t dummy; - if (IS_SCALAR_ARRAY(sub) && IS_SCALAR_ARRAY_OF_BYTES(sub)) { - return mp_obj_new_bytearray_by_ref(uctypes_struct_agg_size(sub, self->flags, &dummy), self->addr + offset); - } - // Fall thru to return uctypes struct object - MP_FALLTHROUGH - } - case PTR: { - mp_obj_uctypes_struct_t *o = mp_obj_malloc(mp_obj_uctypes_struct_t, &uctypes_struct_type); - o->desc = MP_OBJ_FROM_PTR(sub); - o->addr = self->addr + offset; - o->flags = self->flags; - return MP_OBJ_FROM_PTR(o); - } - } - - // Should be unreachable once all cases are handled - return MP_OBJ_NULL; -} - -STATIC void uctypes_struct_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { - if (dest[0] == MP_OBJ_NULL) { - // load attribute - mp_obj_t val = uctypes_struct_attr_op(self_in, attr, MP_OBJ_NULL); - dest[0] = val; - } else { - // delete/store attribute - if (uctypes_struct_attr_op(self_in, attr, dest[1]) != MP_OBJ_NULL) { - dest[0] = MP_OBJ_NULL; // indicate success - } - } -} - -STATIC mp_obj_t uctypes_struct_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) { - mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in); - - if (value == MP_OBJ_NULL) { - // delete - return MP_OBJ_NULL; // op not supported - } else { - // load / store - if (!mp_obj_is_type(self->desc, &mp_type_tuple)) { - mp_raise_TypeError(MP_ERROR_TEXT("struct: can't index")); - } - - mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->desc); - mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]); - uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS); - - mp_int_t index = MP_OBJ_SMALL_INT_VALUE(index_in); - - if (agg_type == ARRAY) { - mp_int_t arr_sz = MP_OBJ_SMALL_INT_VALUE(t->items[1]); - uint val_type = GET_TYPE(arr_sz, VAL_TYPE_BITS); - arr_sz &= VALUE_MASK(VAL_TYPE_BITS); - if (index >= arr_sz) { - mp_raise_msg(&mp_type_IndexError, MP_ERROR_TEXT("struct: index out of range")); - } - - if (t->len == 2) { - // array of scalars - if (self->flags == LAYOUT_NATIVE) { - if (value == MP_OBJ_SENTINEL) { - return get_aligned(val_type, self->addr, index); - } else { - set_aligned(val_type, self->addr, index, value); - return value; // just !MP_OBJ_NULL - } - } else { - byte *p = self->addr + uctypes_struct_scalar_size(val_type) * index; - if (value == MP_OBJ_SENTINEL) { - return get_unaligned(val_type, p, self->flags); - } else { - set_unaligned(val_type, p, self->flags, value); - return value; // just !MP_OBJ_NULL - } - } - } else if (value == MP_OBJ_SENTINEL) { - mp_uint_t dummy = 0; - mp_uint_t size = uctypes_struct_size(t->items[2], self->flags, &dummy); - mp_obj_uctypes_struct_t *o = mp_obj_malloc(mp_obj_uctypes_struct_t, &uctypes_struct_type); - o->desc = t->items[2]; - o->addr = self->addr + size * index; - o->flags = self->flags; - return MP_OBJ_FROM_PTR(o); - } else { - return MP_OBJ_NULL; // op not supported - } - - } else if (agg_type == PTR) { - byte *p = *(void **)self->addr; - if (mp_obj_is_small_int(t->items[1])) { - uint val_type = GET_TYPE(MP_OBJ_SMALL_INT_VALUE(t->items[1]), VAL_TYPE_BITS); - return get_aligned(val_type, p, index); - } else { - mp_uint_t dummy = 0; - mp_uint_t size = uctypes_struct_size(t->items[1], self->flags, &dummy); - mp_obj_uctypes_struct_t *o = mp_obj_malloc(mp_obj_uctypes_struct_t, &uctypes_struct_type); - o->desc = t->items[1]; - o->addr = p + size * index; - o->flags = self->flags; - return MP_OBJ_FROM_PTR(o); - } - } - - assert(0); - return MP_OBJ_NULL; - } -} - -STATIC mp_obj_t uctypes_struct_unary_op(mp_unary_op_t op, mp_obj_t self_in) { - mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in); - switch (op) { - case MP_UNARY_OP_INT_MAYBE: - if (mp_obj_is_type(self->desc, &mp_type_tuple)) { - mp_obj_tuple_t *t = MP_OBJ_TO_PTR(self->desc); - mp_int_t offset = MP_OBJ_SMALL_INT_VALUE(t->items[0]); - uint agg_type = GET_TYPE(offset, AGG_TYPE_BITS); - if (agg_type == PTR) { - byte *p = *(void **)self->addr; - return mp_obj_new_int((mp_int_t)(uintptr_t)p); - } - } - MP_FALLTHROUGH - - default: - return MP_OBJ_NULL; // op not supported - } -} - -STATIC mp_int_t uctypes_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { - (void)flags; - mp_obj_uctypes_struct_t *self = MP_OBJ_TO_PTR(self_in); - mp_uint_t max_field_size = 0; - mp_uint_t size = uctypes_struct_size(self->desc, self->flags, &max_field_size); - - bufinfo->buf = self->addr; - bufinfo->len = size; - bufinfo->typecode = BYTEARRAY_TYPECODE; - return 0; -} - -// addressof() -// Return address of object's data (applies to objects providing the buffer interface). -STATIC mp_obj_t uctypes_struct_addressof(mp_obj_t buf) { - mp_buffer_info_t bufinfo; - mp_get_buffer_raise(buf, &bufinfo, MP_BUFFER_READ); - return mp_obj_new_int((mp_int_t)(uintptr_t)bufinfo.buf); -} -MP_DEFINE_CONST_FUN_OBJ_1(uctypes_struct_addressof_obj, uctypes_struct_addressof); - -// bytearray_at() -// Capture memory at given address of given size as bytearray. -STATIC mp_obj_t uctypes_struct_bytearray_at(mp_obj_t ptr, mp_obj_t size) { - return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void *)(uintptr_t)mp_obj_int_get_truncated(ptr)); -} -MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytearray_at_obj, uctypes_struct_bytearray_at); - -// bytes_at() -// Capture memory at given address of given size as bytes. -STATIC mp_obj_t uctypes_struct_bytes_at(mp_obj_t ptr, mp_obj_t size) { - return mp_obj_new_bytes((void *)(uintptr_t)mp_obj_int_get_truncated(ptr), mp_obj_int_get_truncated(size)); -} -MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytes_at_obj, uctypes_struct_bytes_at); - -STATIC MP_DEFINE_CONST_OBJ_TYPE( - uctypes_struct_type, - MP_QSTR_struct, - MP_TYPE_FLAG_NONE, - make_new, uctypes_struct_make_new, - print, uctypes_struct_print, - attr, uctypes_struct_attr, - subscr, uctypes_struct_subscr, - unary_op, uctypes_struct_unary_op, - buffer, uctypes_get_buffer - ); - -STATIC const mp_rom_map_elem_t mp_module_uctypes_globals_table[] = { - { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uctypes) }, - { MP_ROM_QSTR(MP_QSTR_struct), MP_ROM_PTR(&uctypes_struct_type) }, - { MP_ROM_QSTR(MP_QSTR_sizeof), MP_ROM_PTR(&uctypes_struct_sizeof_obj) }, - { MP_ROM_QSTR(MP_QSTR_addressof), MP_ROM_PTR(&uctypes_struct_addressof_obj) }, - { MP_ROM_QSTR(MP_QSTR_bytes_at), MP_ROM_PTR(&uctypes_struct_bytes_at_obj) }, - { MP_ROM_QSTR(MP_QSTR_bytearray_at), MP_ROM_PTR(&uctypes_struct_bytearray_at_obj) }, - - { MP_ROM_QSTR(MP_QSTR_NATIVE), MP_ROM_INT(LAYOUT_NATIVE) }, - { MP_ROM_QSTR(MP_QSTR_LITTLE_ENDIAN), MP_ROM_INT(LAYOUT_LITTLE_ENDIAN) }, - { MP_ROM_QSTR(MP_QSTR_BIG_ENDIAN), MP_ROM_INT(LAYOUT_BIG_ENDIAN) }, - - { MP_ROM_QSTR(MP_QSTR_VOID), MP_ROM_INT(TYPE2SMALLINT(UINT8, VAL_TYPE_BITS)) }, - - { MP_ROM_QSTR(MP_QSTR_UINT8), MP_ROM_INT(TYPE2SMALLINT(UINT8, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_INT8), MP_ROM_INT(TYPE2SMALLINT(INT8, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_UINT16), MP_ROM_INT(TYPE2SMALLINT(UINT16, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_INT16), MP_ROM_INT(TYPE2SMALLINT(INT16, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_UINT32), MP_ROM_INT(TYPE2SMALLINT(UINT32, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_INT32), MP_ROM_INT(TYPE2SMALLINT(INT32, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_UINT64), MP_ROM_INT(TYPE2SMALLINT(UINT64, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_INT64), MP_ROM_INT(TYPE2SMALLINT(INT64, VAL_TYPE_BITS)) }, - - { MP_ROM_QSTR(MP_QSTR_BFUINT8), MP_ROM_INT(TYPE2SMALLINT(BFUINT8, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_BFINT8), MP_ROM_INT(TYPE2SMALLINT(BFINT8, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_BFUINT16), MP_ROM_INT(TYPE2SMALLINT(BFUINT16, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_BFINT16), MP_ROM_INT(TYPE2SMALLINT(BFINT16, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_BFUINT32), MP_ROM_INT(TYPE2SMALLINT(BFUINT32, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_BFINT32), MP_ROM_INT(TYPE2SMALLINT(BFINT32, VAL_TYPE_BITS)) }, - - { MP_ROM_QSTR(MP_QSTR_BF_POS), MP_ROM_INT(OFFSET_BITS) }, - { MP_ROM_QSTR(MP_QSTR_BF_LEN), MP_ROM_INT(LEN_BITS) }, - - #if MICROPY_PY_BUILTINS_FLOAT - { MP_ROM_QSTR(MP_QSTR_FLOAT32), MP_ROM_INT(TYPE2SMALLINT(FLOAT32, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_FLOAT64), MP_ROM_INT(TYPE2SMALLINT(FLOAT64, VAL_TYPE_BITS)) }, - #endif - - #if MICROPY_PY_UCTYPES_NATIVE_C_TYPES - // C native type aliases. These depend on GCC-compatible predefined - // preprocessor macros. - #if __SIZEOF_SHORT__ == 2 - { MP_ROM_QSTR(MP_QSTR_SHORT), MP_ROM_INT(TYPE2SMALLINT(INT16, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_USHORT), MP_ROM_INT(TYPE2SMALLINT(UINT16, VAL_TYPE_BITS)) }, - #endif - #if __SIZEOF_INT__ == 4 - { MP_ROM_QSTR(MP_QSTR_INT), MP_ROM_INT(TYPE2SMALLINT(INT32, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_UINT), MP_ROM_INT(TYPE2SMALLINT(UINT32, VAL_TYPE_BITS)) }, - #endif - #if __SIZEOF_LONG__ == 4 - { MP_ROM_QSTR(MP_QSTR_LONG), MP_ROM_INT(TYPE2SMALLINT(INT32, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_ULONG), MP_ROM_INT(TYPE2SMALLINT(UINT32, VAL_TYPE_BITS)) }, - #elif __SIZEOF_LONG__ == 8 - { MP_ROM_QSTR(MP_QSTR_LONG), MP_ROM_INT(TYPE2SMALLINT(INT64, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_ULONG), MP_ROM_INT(TYPE2SMALLINT(UINT64, VAL_TYPE_BITS)) }, - #endif - #if __SIZEOF_LONG_LONG__ == 8 - { MP_ROM_QSTR(MP_QSTR_LONGLONG), MP_ROM_INT(TYPE2SMALLINT(INT64, VAL_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_ULONGLONG), MP_ROM_INT(TYPE2SMALLINT(UINT64, VAL_TYPE_BITS)) }, - #endif - #endif // MICROPY_PY_UCTYPES_NATIVE_C_TYPES - - { MP_ROM_QSTR(MP_QSTR_PTR), MP_ROM_INT(TYPE2SMALLINT(PTR, AGG_TYPE_BITS)) }, - { MP_ROM_QSTR(MP_QSTR_ARRAY), MP_ROM_INT(TYPE2SMALLINT(ARRAY, AGG_TYPE_BITS)) }, -}; -STATIC MP_DEFINE_CONST_DICT(mp_module_uctypes_globals, mp_module_uctypes_globals_table); - -const mp_obj_module_t mp_module_uctypes = { - .base = { &mp_type_module }, - .globals = (mp_obj_dict_t *)&mp_module_uctypes_globals, -}; - -// uctypes is not a Python standard library module (hence "uctypes" -// not "ctypes") and therefore shouldn't be extensible. -MP_REGISTER_MODULE(MP_QSTR_uctypes, mp_module_uctypes); - -#endif diff --git a/extmod/modzlib.c b/extmod/modzlib.c index 3984647a5d7ac..10b656a469d2d 100644 --- a/extmod/modzlib.c +++ b/extmod/modzlib.c @@ -1,3 +1,5 @@ +// CIRCUITPY-CHANGE: This module was removed from MicroPython but CircuitPython still uses it. + /* * This file is part of the MicroPython project, http://micropython.org/ * @@ -49,7 +51,7 @@ typedef struct _mp_obj_decompio_t { bool eof; } mp_obj_decompio_t; -STATIC int read_src_stream(TINF_DATA *data) { +static int read_src_stream(TINF_DATA *data) { byte *p = (void *)data; p -= offsetof(mp_obj_decompio_t, decomp); mp_obj_decompio_t *self = (mp_obj_decompio_t *)p; @@ -67,7 +69,7 @@ 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, size_t n_kw, const mp_obj_t *args) { +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 = mp_obj_malloc(mp_obj_decompio_t, type); @@ -106,7 +108,7 @@ STATIC mp_obj_t decompio_make_new(const mp_obj_type_t *type, size_t n_args, size return MP_OBJ_FROM_PTR(o); } -STATIC mp_uint_t decompio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t decompio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { mp_obj_decompio_t *o = MP_OBJ_TO_PTR(o_in); if (o->eof) { return 0; @@ -127,21 +129,21 @@ STATIC mp_uint_t decompio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *er } #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t decompio_locals_dict_table[] = { +static const mp_rom_map_elem_t decompio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(decompio_locals_dict, decompio_locals_dict_table); +static MP_DEFINE_CONST_DICT(decompio_locals_dict, decompio_locals_dict_table); #endif -STATIC const mp_stream_p_t decompio_stream_p = { +static const mp_stream_p_t decompio_stream_p = { .read = decompio_read, }; #if !MICROPY_ENABLE_DYNRUNTIME -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( decompio_type, MP_QSTR_DecompIO, MP_TYPE_FLAG_NONE, @@ -151,7 +153,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); #endif -STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) { mp_obj_t data = args[0]; mp_buffer_info_t bufinfo; mp_get_buffer_raise(data, &bufinfo, MP_BUFFER_READ); @@ -213,16 +215,16 @@ STATIC mp_obj_t mod_uzlib_decompress(size_t n_args, const mp_obj_t *args) { error: 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); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_uzlib_decompress_obj, 1, 3, mod_uzlib_decompress); #if !MICROPY_ENABLE_DYNRUNTIME -STATIC const mp_rom_map_elem_t mp_module_uzlib_globals_table[] = { +static const mp_rom_map_elem_t mp_module_uzlib_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_uzlib) }, { MP_ROM_QSTR(MP_QSTR_decompress), MP_ROM_PTR(&mod_uzlib_decompress_obj) }, { MP_ROM_QSTR(MP_QSTR_DecompIO), MP_ROM_PTR(&decompio_type) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_uzlib_globals, mp_module_uzlib_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_uzlib_globals, mp_module_uzlib_globals_table); const mp_obj_module_t mp_module_uzlib = { .base = { &mp_type_module }, diff --git a/extmod/ulab b/extmod/ulab index eacb0c9af47f8..1d3ddd8f5228e 160000 --- a/extmod/ulab +++ b/extmod/ulab @@ -1 +1 @@ -Subproject commit eacb0c9af47f85f5d4864b721c3b28661364e8e3 +Subproject commit 1d3ddd8f5228e2c7335dac71f4846e6abb0ec9f9 diff --git a/extmod/vfs.c b/extmod/vfs.c index 21dbac5c2bfcc..e7230e5ca0314 100644 --- a/extmod/vfs.c +++ b/extmod/vfs.c @@ -94,7 +94,7 @@ mp_vfs_mount_t *mp_vfs_lookup_path(const char *path, const char **path_out) { } // Version of mp_vfs_lookup_path that takes and returns uPy string objects. -STATIC mp_vfs_mount_t *lookup_path(mp_obj_t path_in, mp_obj_t *path_out) { +static mp_vfs_mount_t *lookup_path(mp_obj_t path_in, mp_obj_t *path_out) { const char *path = mp_obj_str_get_str(path_in); const char *p_out; mp_vfs_mount_t *vfs = mp_vfs_lookup_path(path, &p_out); @@ -107,7 +107,7 @@ STATIC mp_vfs_mount_t *lookup_path(mp_obj_t path_in, mp_obj_t *path_out) { return vfs; } -STATIC mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_vfs_proxy_call(mp_vfs_mount_t *vfs, qstr meth_name, size_t n_args, const mp_obj_t *args) { assert(n_args <= PROXY_MAX_ARGS); if (vfs == MP_VFS_NONE) { // mount point not found @@ -160,7 +160,7 @@ mp_import_stat_t mp_vfs_import_stat(const char *path) { } } -STATIC mp_obj_t mp_vfs_autodetect(mp_obj_t bdev_obj) { +static mp_obj_t mp_vfs_autodetect(mp_obj_t bdev_obj) { #if MICROPY_VFS_LFS1 || MICROPY_VFS_LFS2 nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { diff --git a/extmod/vfs_fat.c b/extmod/vfs_fat.c index ee0b8eb735bd4..85541d3cf01da 100644 --- a/extmod/vfs_fat.c +++ b/extmod/vfs_fat.c @@ -57,11 +57,11 @@ // CIRCUITPY-CHANGE // Factoring this common call saves about 90 bytes. -STATIC NORETURN void mp_raise_OSError_fresult(FRESULT res) { +static NORETURN void mp_raise_OSError_fresult(FRESULT res) { mp_raise_OSError(fresult_to_errno_table[res]); } -STATIC mp_import_stat_t fat_vfs_import_stat(void *vfs_in, const char *path) { +static mp_import_stat_t fat_vfs_import_stat(void *vfs_in, const char *path) { fs_user_mount_t *vfs = vfs_in; FILINFO fno; assert(vfs != NULL); @@ -76,7 +76,7 @@ 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, size_t n_kw, const mp_obj_t *args) { +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 @@ -102,23 +102,23 @@ STATIC mp_obj_t fat_vfs_make_new(const mp_obj_type_t *type, size_t n_args, size_ } // CIRCUITPY-CHANGE -STATIC void verify_fs_writable(fs_user_mount_t *vfs) { +static void verify_fs_writable(fs_user_mount_t *vfs) { if (!filesystem_is_writable_by_python(vfs)) { mp_raise_OSError(MP_EROFS); } } #if FF_FS_REENTRANT -STATIC mp_obj_t fat_vfs_del(mp_obj_t self_in) { +static mp_obj_t fat_vfs_del(mp_obj_t self_in) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(self_in); // f_umount only needs to be called to release the sync object f_umount(&self->fatfs); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_del_obj, fat_vfs_del); +static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_del_obj, fat_vfs_del); #endif -STATIC mp_obj_t fat_vfs_mkfs(mp_obj_t bdev_in) { +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, 0, &bdev_in)); @@ -135,8 +135,8 @@ STATIC mp_obj_t fat_vfs_mkfs(mp_obj_t bdev_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_mkfs_fun_obj, fat_vfs_mkfs); -STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(fat_vfs_mkfs_obj, MP_ROM_PTR(&fat_vfs_mkfs_fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_mkfs_fun_obj, fat_vfs_mkfs); +static MP_DEFINE_CONST_STATICMETHOD_OBJ(fat_vfs_mkfs_obj, MP_ROM_PTR(&fat_vfs_mkfs_fun_obj)); typedef struct _mp_vfs_fat_ilistdir_it_t { mp_obj_base_t base; @@ -146,7 +146,7 @@ typedef struct _mp_vfs_fat_ilistdir_it_t { FF_DIR dir; } mp_vfs_fat_ilistdir_it_t; -STATIC mp_obj_t mp_vfs_fat_ilistdir_it_iternext(mp_obj_t self_in) { +static mp_obj_t mp_vfs_fat_ilistdir_it_iternext(mp_obj_t self_in) { mp_vfs_fat_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); for (;;) { @@ -186,14 +186,14 @@ STATIC mp_obj_t mp_vfs_fat_ilistdir_it_iternext(mp_obj_t self_in) { return MP_OBJ_STOP_ITERATION; } -STATIC mp_obj_t mp_vfs_fat_ilistdir_it_del(mp_obj_t self_in) { +static mp_obj_t mp_vfs_fat_ilistdir_it_del(mp_obj_t self_in) { mp_vfs_fat_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); // ignore result / error because we may be closing a second time. f_closedir(&self->dir); return mp_const_none; } -STATIC mp_obj_t fat_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args) { +static mp_obj_t fat_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(args[0]); bool is_str_type = true; const char *path; @@ -207,8 +207,7 @@ STATIC mp_obj_t fat_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args) { } // Create a new iterator object to list the dir - mp_vfs_fat_ilistdir_it_t *iter = m_new_obj_with_finaliser(mp_vfs_fat_ilistdir_it_t); - iter->base.type = &mp_type_polymorph_iter_with_finaliser; + mp_vfs_fat_ilistdir_it_t *iter = mp_obj_malloc_with_finaliser(mp_vfs_fat_ilistdir_it_t, &mp_type_polymorph_iter_with_finaliser); iter->iternext = mp_vfs_fat_ilistdir_it_iternext; iter->finaliser = mp_vfs_fat_ilistdir_it_del; iter->is_str = is_str_type; @@ -220,9 +219,9 @@ STATIC mp_obj_t fat_vfs_ilistdir_func(size_t n_args, const mp_obj_t *args) { return MP_OBJ_FROM_PTR(iter); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fat_vfs_ilistdir_obj, 1, 2, fat_vfs_ilistdir_func); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(fat_vfs_ilistdir_obj, 1, 2, fat_vfs_ilistdir_func); -STATIC mp_obj_t fat_vfs_remove_internal(mp_obj_t vfs_in, mp_obj_t path_in, mp_int_t attr) { +static mp_obj_t fat_vfs_remove_internal(mp_obj_t vfs_in, mp_obj_t path_in, mp_int_t attr) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); // CIRCUITPY-CHANGE verify_fs_writable(self); @@ -250,17 +249,17 @@ STATIC mp_obj_t fat_vfs_remove_internal(mp_obj_t vfs_in, mp_obj_t path_in, mp_in } } -STATIC mp_obj_t fat_vfs_remove(mp_obj_t vfs_in, mp_obj_t path_in) { +static mp_obj_t fat_vfs_remove(mp_obj_t vfs_in, mp_obj_t path_in) { return fat_vfs_remove_internal(vfs_in, path_in, 0); // 0 == file attribute } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_remove_obj, fat_vfs_remove); +static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_remove_obj, fat_vfs_remove); -STATIC mp_obj_t fat_vfs_rmdir(mp_obj_t vfs_in, mp_obj_t path_in) { +static mp_obj_t fat_vfs_rmdir(mp_obj_t vfs_in, mp_obj_t path_in) { return fat_vfs_remove_internal(vfs_in, path_in, AM_DIR); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_rmdir_obj, fat_vfs_rmdir); +static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_rmdir_obj, fat_vfs_rmdir); -STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_out) { +static mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_out) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); // CIRCUITPY-CHANGE verify_fs_writable(self); @@ -281,9 +280,9 @@ STATIC mp_obj_t fat_vfs_rename(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t path_ } } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(fat_vfs_rename_obj, fat_vfs_rename); +static MP_DEFINE_CONST_FUN_OBJ_3(fat_vfs_rename_obj, fat_vfs_rename); -STATIC mp_obj_t fat_vfs_mkdir(mp_obj_t vfs_in, mp_obj_t path_o) { +static mp_obj_t fat_vfs_mkdir(mp_obj_t vfs_in, mp_obj_t path_o) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); verify_fs_writable(self); const char *path = mp_obj_str_get_str(path_o); @@ -295,10 +294,10 @@ STATIC mp_obj_t fat_vfs_mkdir(mp_obj_t vfs_in, mp_obj_t path_o) { mp_raise_OSError_fresult(res); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_mkdir_obj, fat_vfs_mkdir); +static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_mkdir_obj, fat_vfs_mkdir); // Change current directory. -STATIC mp_obj_t fat_vfs_chdir(mp_obj_t vfs_in, mp_obj_t path_in) { +static mp_obj_t fat_vfs_chdir(mp_obj_t vfs_in, mp_obj_t path_in) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); const char *path; path = mp_obj_str_get_str(path_in); @@ -312,10 +311,10 @@ STATIC mp_obj_t fat_vfs_chdir(mp_obj_t vfs_in, mp_obj_t path_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_chdir_obj, fat_vfs_chdir); +static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_chdir_obj, fat_vfs_chdir); // Get the current directory. -STATIC mp_obj_t fat_vfs_getcwd(mp_obj_t vfs_in) { +static mp_obj_t fat_vfs_getcwd(mp_obj_t vfs_in) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); char buf[MICROPY_ALLOC_PATH_MAX + 1]; FRESULT res = f_getcwd(&self->fatfs, buf, sizeof(buf)); @@ -325,10 +324,10 @@ STATIC mp_obj_t fat_vfs_getcwd(mp_obj_t vfs_in) { } return mp_obj_new_str(buf, strlen(buf)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_getcwd_obj, fat_vfs_getcwd); +static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_getcwd_obj, fat_vfs_getcwd); // Get the status of a file or directory. -STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) { +static mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); const char *path = mp_obj_str_get_str(path_in); @@ -384,10 +383,10 @@ STATIC mp_obj_t fat_vfs_stat(mp_obj_t vfs_in, mp_obj_t path_in) { return MP_OBJ_FROM_PTR(t); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_stat_obj, fat_vfs_stat); +static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_stat_obj, fat_vfs_stat); // Get the status of a VFS. -STATIC mp_obj_t fat_vfs_statvfs(mp_obj_t vfs_in, mp_obj_t path_in) { +static mp_obj_t fat_vfs_statvfs(mp_obj_t vfs_in, mp_obj_t path_in) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); (void)path_in; @@ -414,9 +413,9 @@ STATIC mp_obj_t fat_vfs_statvfs(mp_obj_t vfs_in, mp_obj_t path_in) { return MP_OBJ_FROM_PTR(t); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_statvfs_obj, fat_vfs_statvfs); +static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_statvfs_obj, fat_vfs_statvfs); -STATIC mp_obj_t vfs_fat_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs) { +static mp_obj_t vfs_fat_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs) { fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in); // Read-only device indicated by writeblocks[0] == MP_OBJ_NULL. @@ -441,17 +440,17 @@ STATIC mp_obj_t vfs_fat_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(vfs_fat_mount_obj, vfs_fat_mount); +static MP_DEFINE_CONST_FUN_OBJ_3(vfs_fat_mount_obj, vfs_fat_mount); -STATIC mp_obj_t vfs_fat_umount(mp_obj_t self_in) { +static mp_obj_t vfs_fat_umount(mp_obj_t self_in) { (void)self_in; // keep the FAT filesystem mounted internally so the VFS methods can still be used return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_umount_obj, vfs_fat_umount); +static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_umount_obj, vfs_fat_umount); // CIRCUITPY-CHANGE -STATIC mp_obj_t vfs_fat_utime(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t times_in) { +static mp_obj_t vfs_fat_utime(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t times_in) { mp_obj_fat_vfs_t *self = MP_OBJ_TO_PTR(vfs_in); const char *path = mp_obj_str_get_str(path_in); if (!mp_obj_is_tuple_compatible(times_in)) { @@ -478,14 +477,14 @@ STATIC mp_obj_t vfs_fat_utime(mp_obj_t vfs_in, mp_obj_t path_in, mp_obj_t times_ return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(fat_vfs_utime_obj, vfs_fat_utime); +static MP_DEFINE_CONST_FUN_OBJ_3(fat_vfs_utime_obj, vfs_fat_utime); -STATIC mp_obj_t vfs_fat_getreadonly(mp_obj_t self_in) { +static mp_obj_t vfs_fat_getreadonly(mp_obj_t self_in) { fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_bool(!filesystem_is_writable_by_python(self)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_getreadonly_obj, vfs_fat_getreadonly); -STATIC const mp_obj_property_t fat_vfs_readonly_obj = { +static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_getreadonly_obj, vfs_fat_getreadonly); +static const mp_obj_property_t fat_vfs_readonly_obj = { .base.type = &mp_type_property, .proxy = {(mp_obj_t)&fat_vfs_getreadonly_obj, MP_ROM_NONE, @@ -493,7 +492,7 @@ STATIC const mp_obj_property_t fat_vfs_readonly_obj = { }; #if MICROPY_FATFS_USE_LABEL -STATIC mp_obj_t vfs_fat_getlabel(mp_obj_t self_in) { +static mp_obj_t vfs_fat_getlabel(mp_obj_t self_in) { fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in); char working_buf[12]; FRESULT res = f_getlabel(&self->fatfs, working_buf, NULL); @@ -502,9 +501,9 @@ STATIC mp_obj_t vfs_fat_getlabel(mp_obj_t self_in) { } return mp_obj_new_str(working_buf, strlen(working_buf)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_getlabel_obj, vfs_fat_getlabel); +static MP_DEFINE_CONST_FUN_OBJ_1(fat_vfs_getlabel_obj, vfs_fat_getlabel); -STATIC mp_obj_t vfs_fat_setlabel(mp_obj_t self_in, mp_obj_t label_in) { +static mp_obj_t vfs_fat_setlabel(mp_obj_t self_in, mp_obj_t label_in) { fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in); verify_fs_writable(self); const char *label_str = mp_obj_str_get_str(label_in); @@ -517,8 +516,8 @@ STATIC mp_obj_t vfs_fat_setlabel(mp_obj_t self_in, mp_obj_t label_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_setlabel_obj, vfs_fat_setlabel); -STATIC const mp_obj_property_t fat_vfs_label_obj = { +static MP_DEFINE_CONST_FUN_OBJ_2(fat_vfs_setlabel_obj, vfs_fat_setlabel); +static const mp_obj_property_t fat_vfs_label_obj = { .base.type = &mp_type_property, .proxy = {(mp_obj_t)&fat_vfs_getlabel_obj, (mp_obj_t)&fat_vfs_setlabel_obj, @@ -526,7 +525,8 @@ STATIC const mp_obj_property_t fat_vfs_label_obj = { }; #endif -STATIC const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = { +static const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = { + // CIRCUITPY-CHANGE: correct name #if FF_FS_REENTRANT { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&fat_vfs_del_obj) }, #endif @@ -550,9 +550,9 @@ STATIC const mp_rom_map_elem_t fat_vfs_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_label), MP_ROM_PTR(&fat_vfs_label_obj) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(fat_vfs_locals_dict, fat_vfs_locals_dict_table); +static MP_DEFINE_CONST_DICT(fat_vfs_locals_dict, fat_vfs_locals_dict_table); -STATIC const mp_vfs_proto_t fat_vfs_proto = { +static const mp_vfs_proto_t fat_vfs_proto = { // CIRCUITPY-CHANGE MP_PROTO_IMPLEMENT(MP_QSTR_protocol_vfs) .import_stat = fat_vfs_import_stat, diff --git a/extmod/vfs_fat_diskio.c b/extmod/vfs_fat_diskio.c index 1bcd471f2162e..6f500104d1e86 100644 --- a/extmod/vfs_fat_diskio.c +++ b/extmod/vfs_fat_diskio.c @@ -44,7 +44,7 @@ #include "extmod/vfs_fat.h" typedef void *bdev_t; -STATIC fs_user_mount_t *disk_get_device(void *bdev) { +static fs_user_mount_t *disk_get_device(void *bdev) { return (fs_user_mount_t *)bdev; } diff --git a/extmod/vfs_fat_file.c b/extmod/vfs_fat_file.c index 74dabce99eb2c..2a3021ee9a8fe 100644 --- a/extmod/vfs_fat_file.c +++ b/extmod/vfs_fat_file.c @@ -62,13 +62,13 @@ const byte fresult_to_errno_table[20] = { [FR_INVALID_PARAMETER] = MP_EINVAL, }; -STATIC void file_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void file_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; // CIRCUITPY-CHANGE mp_printf(print, "", mp_obj_get_type_qstr(self_in), MP_OBJ_TO_PTR(self_in)); } -STATIC mp_uint_t file_obj_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t file_obj_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in); UINT sz_out; FRESULT res = f_read(&self->fp, buf, size, &sz_out); @@ -79,7 +79,7 @@ STATIC mp_uint_t file_obj_read(mp_obj_t self_in, void *buf, mp_uint_t size, int return sz_out; } -STATIC mp_uint_t file_obj_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t file_obj_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { pyb_file_obj_t *self = MP_OBJ_TO_PTR(self_in); UINT sz_out; FRESULT res = f_write(&self->fp, buf, size, &sz_out); @@ -95,7 +95,7 @@ STATIC mp_uint_t file_obj_write(mp_obj_t self_in, const void *buf, mp_uint_t siz return sz_out; } -STATIC mp_uint_t file_obj_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t file_obj_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { pyb_file_obj_t *self = MP_OBJ_TO_PTR(o_in); if (request == MP_STREAM_SEEK) { @@ -145,7 +145,7 @@ STATIC mp_uint_t file_obj_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, // TODO gc hook to close the file if not already closed -STATIC const mp_rom_map_elem_t vfs_fat_rawfile_locals_dict_table[] = { +static const mp_rom_map_elem_t vfs_fat_rawfile_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) }, @@ -160,9 +160,9 @@ STATIC const mp_rom_map_elem_t vfs_fat_rawfile_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&mp_stream___exit___obj) }, }; -STATIC MP_DEFINE_CONST_DICT(vfs_fat_rawfile_locals_dict, vfs_fat_rawfile_locals_dict_table); +static MP_DEFINE_CONST_DICT(vfs_fat_rawfile_locals_dict, vfs_fat_rawfile_locals_dict_table); -STATIC const mp_stream_p_t vfs_fat_fileio_stream_p = { +static const mp_stream_p_t vfs_fat_fileio_stream_p = { .read = file_obj_read, .write = file_obj_write, .ioctl = file_obj_ioctl, @@ -177,7 +177,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &vfs_fat_rawfile_locals_dict ); -STATIC const mp_stream_p_t vfs_fat_textio_stream_p = { +static const mp_stream_p_t vfs_fat_textio_stream_p = { .read = file_obj_read, .write = file_obj_write, .ioctl = file_obj_ioctl, @@ -194,7 +194,7 @@ MP_DEFINE_CONST_OBJ_TYPE( ); // Factory function for I/O stream classes -STATIC mp_obj_t fat_vfs_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode_in) { +static mp_obj_t fat_vfs_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode_in) { fs_user_mount_t *self = MP_OBJ_TO_PTR(self_in); const mp_obj_type_t *type = &mp_type_vfs_fat_textio; @@ -251,8 +251,7 @@ STATIC mp_obj_t fat_vfs_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode_i } - pyb_file_obj_t *o = m_new_obj_with_finaliser(pyb_file_obj_t); - o->base.type = type; + pyb_file_obj_t *o = mp_obj_malloc_with_finaliser(pyb_file_obj_t, type); const char *fname = mp_obj_str_get_str(path_in); FRESULT res = f_open(&self->fatfs, &o->fp, fname, mode); diff --git a/extmod/vfs_lfs.c b/extmod/vfs_lfs.c index 4fb86b89b76c3..19063d6306604 100644 --- a/extmod/vfs_lfs.c +++ b/extmod/vfs_lfs.c @@ -127,7 +127,7 @@ typedef struct _mp_obj_vfs_lfs2_file_t { const char *mp_vfs_lfs2_make_path(mp_obj_vfs_lfs2_t *self, mp_obj_t path_in); mp_obj_t mp_vfs_lfs2_file_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode_in); -STATIC void lfs_get_mtime(uint8_t buf[8]) { +static void lfs_get_mtime(uint8_t buf[8]) { // On-disk storage of timestamps uses 1970 as the Epoch, so convert from host's Epoch. uint64_t ns = timeutils_nanoseconds_since_epoch_to_nanoseconds_since_1970(mp_hal_time_ns()); // Store "ns" to "buf" in little-endian format (essentially htole64). diff --git a/extmod/vfs_lfsx.c b/extmod/vfs_lfsx.c index e78c154d1fe8d..19da4417e6d00 100644 --- a/extmod/vfs_lfsx.c +++ b/extmod/vfs_lfsx.c @@ -43,7 +43,7 @@ #error "MICROPY_VFS_LFS requires MICROPY_ENABLE_FINALISER" #endif -STATIC int MP_VFS_LFSx(dev_ioctl)(const struct LFSx_API (config) * c, int cmd, int arg, bool must_return_int) { +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); int ret_i = 0; if (must_return_int || ret != mp_const_none) { @@ -52,23 +52,23 @@ STATIC int MP_VFS_LFSx(dev_ioctl)(const struct LFSx_API (config) * c, int cmd, i return ret_i; } -STATIC int MP_VFS_LFSx(dev_read)(const struct LFSx_API (config) * c, LFSx_API(block_t) block, LFSx_API(off_t) off, void *buffer, LFSx_API(size_t) size) { +static int MP_VFS_LFSx(dev_read)(const struct LFSx_API (config) * c, LFSx_API(block_t) block, LFSx_API(off_t) off, void *buffer, LFSx_API(size_t) size) { return mp_vfs_blockdev_read_ext(c->context, block, off, size, buffer); } -STATIC int MP_VFS_LFSx(dev_prog)(const struct LFSx_API (config) * c, LFSx_API(block_t) block, LFSx_API(off_t) off, const void *buffer, LFSx_API(size_t) size) { +static int MP_VFS_LFSx(dev_prog)(const struct LFSx_API (config) * c, LFSx_API(block_t) block, LFSx_API(off_t) off, const void *buffer, LFSx_API(size_t) size) { return mp_vfs_blockdev_write_ext(c->context, block, off, size, buffer); } -STATIC int MP_VFS_LFSx(dev_erase)(const struct LFSx_API (config) * c, LFSx_API(block_t) block) { +static int MP_VFS_LFSx(dev_erase)(const struct LFSx_API (config) * c, LFSx_API(block_t) block) { return MP_VFS_LFSx(dev_ioctl)(c, MP_BLOCKDEV_IOCTL_BLOCK_ERASE, block, true); } -STATIC int MP_VFS_LFSx(dev_sync)(const struct LFSx_API (config) * c) { +static int MP_VFS_LFSx(dev_sync)(const struct LFSx_API (config) * c) { return MP_VFS_LFSx(dev_ioctl)(c, MP_BLOCKDEV_IOCTL_SYNC, 0, false); } -STATIC void MP_VFS_LFSx(init_config)(MP_OBJ_VFS_LFSx * self, mp_obj_t bdev, size_t read_size, size_t prog_size, size_t lookahead) { +static void MP_VFS_LFSx(init_config)(MP_OBJ_VFS_LFSx * self, mp_obj_t bdev, size_t read_size, size_t prog_size, size_t lookahead) { self->blockdev.flags = MP_BLOCKDEV_FLAG_FREE_OBJ; mp_vfs_blockdev_init(&self->blockdev, bdev); @@ -120,7 +120,7 @@ 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, size_t n_kw, const mp_obj_t *all_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_kw_array(n_args, n_kw, all_args, MP_ARRAY_SIZE(lfs_make_allowed_args), lfs_make_allowed_args, args); @@ -140,7 +140,7 @@ STATIC mp_obj_t MP_VFS_LFSx(make_new)(const mp_obj_type_t * type, size_t n_args, return MP_OBJ_FROM_PTR(self); } -STATIC mp_obj_t MP_VFS_LFSx(mkfs)(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t MP_VFS_LFSx(mkfs)(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_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); @@ -153,11 +153,11 @@ STATIC mp_obj_t MP_VFS_LFSx(mkfs)(size_t n_args, const mp_obj_t *pos_args, mp_ma } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(MP_VFS_LFSx(mkfs_fun_obj), 0, MP_VFS_LFSx(mkfs)); -STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(MP_VFS_LFSx(mkfs_obj), MP_ROM_PTR(&MP_VFS_LFSx(mkfs_fun_obj))); +static MP_DEFINE_CONST_FUN_OBJ_KW(MP_VFS_LFSx(mkfs_fun_obj), 0, MP_VFS_LFSx(mkfs)); +static MP_DEFINE_CONST_STATICMETHOD_OBJ(MP_VFS_LFSx(mkfs_obj), MP_ROM_PTR(&MP_VFS_LFSx(mkfs_fun_obj))); // Implementation of mp_vfs_lfs_file_open is provided in vfs_lfsx_file.c -STATIC MP_DEFINE_CONST_FUN_OBJ_3(MP_VFS_LFSx(open_obj), MP_VFS_LFSx(file_open)); +static MP_DEFINE_CONST_FUN_OBJ_3(MP_VFS_LFSx(open_obj), MP_VFS_LFSx(file_open)); typedef struct MP_VFS_LFSx (_ilistdir_it_t) { mp_obj_base_t base; @@ -168,7 +168,7 @@ typedef struct MP_VFS_LFSx (_ilistdir_it_t) { LFSx_API(dir_t) dir; } MP_VFS_LFSx(ilistdir_it_t); -STATIC mp_obj_t MP_VFS_LFSx(ilistdir_it_iternext)(mp_obj_t self_in) { +static mp_obj_t MP_VFS_LFSx(ilistdir_it_iternext)(mp_obj_t self_in) { MP_VFS_LFSx(ilistdir_it_t) * self = MP_OBJ_TO_PTR(self_in); if (self->vfs == NULL) { @@ -203,7 +203,7 @@ STATIC mp_obj_t MP_VFS_LFSx(ilistdir_it_iternext)(mp_obj_t self_in) { return MP_OBJ_FROM_PTR(t); } -STATIC mp_obj_t MP_VFS_LFSx(ilistdir_it_del)(mp_obj_t self_in) { +static mp_obj_t MP_VFS_LFSx(ilistdir_it_del)(mp_obj_t self_in) { MP_VFS_LFSx(ilistdir_it_t) * self = MP_OBJ_TO_PTR(self_in); if (self->vfs != NULL) { LFSx_API(dir_close)(&self->vfs->lfs, &self->dir); @@ -211,7 +211,7 @@ STATIC mp_obj_t MP_VFS_LFSx(ilistdir_it_del)(mp_obj_t self_in) { return mp_const_none; } -STATIC mp_obj_t MP_VFS_LFSx(ilistdir_func)(size_t n_args, const mp_obj_t *args) { +static mp_obj_t MP_VFS_LFSx(ilistdir_func)(size_t n_args, const mp_obj_t *args) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(args[0]); bool is_str_type = true; const char *path; @@ -224,8 +224,7 @@ STATIC mp_obj_t MP_VFS_LFSx(ilistdir_func)(size_t n_args, const mp_obj_t *args) path = vstr_null_terminated_str(&self->cur_dir); } - MP_VFS_LFSx(ilistdir_it_t) * iter = m_new_obj_with_finaliser(MP_VFS_LFSx(ilistdir_it_t)); - iter->base.type = &mp_type_polymorph_iter_with_finaliser; + MP_VFS_LFSx(ilistdir_it_t) * iter = mp_obj_malloc_with_finaliser(MP_VFS_LFSx(ilistdir_it_t), &mp_type_polymorph_iter_with_finaliser); iter->iternext = MP_VFS_LFSx(ilistdir_it_iternext); iter->finaliser = MP_VFS_LFSx(ilistdir_it_del); @@ -237,9 +236,9 @@ STATIC mp_obj_t MP_VFS_LFSx(ilistdir_func)(size_t n_args, const mp_obj_t *args) iter->vfs = self; return MP_OBJ_FROM_PTR(iter); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(MP_VFS_LFSx(ilistdir_obj), 1, 2, MP_VFS_LFSx(ilistdir_func)); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(MP_VFS_LFSx(ilistdir_obj), 1, 2, MP_VFS_LFSx(ilistdir_func)); -STATIC mp_obj_t MP_VFS_LFSx(remove)(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t MP_VFS_LFSx(remove)(mp_obj_t self_in, mp_obj_t path_in) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); const char *path = MP_VFS_LFSx(make_path)(self, path_in); int ret = LFSx_API(remove)(&self->lfs, path); @@ -248,9 +247,9 @@ STATIC mp_obj_t MP_VFS_LFSx(remove)(mp_obj_t self_in, mp_obj_t path_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(remove_obj), MP_VFS_LFSx(remove)); +static MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(remove_obj), MP_VFS_LFSx(remove)); -STATIC mp_obj_t MP_VFS_LFSx(rmdir)(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t MP_VFS_LFSx(rmdir)(mp_obj_t self_in, mp_obj_t path_in) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); const char *path = MP_VFS_LFSx(make_path)(self, path_in); int ret = LFSx_API(remove)(&self->lfs, path); @@ -259,9 +258,9 @@ STATIC mp_obj_t MP_VFS_LFSx(rmdir)(mp_obj_t self_in, mp_obj_t path_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(rmdir_obj), MP_VFS_LFSx(rmdir)); +static MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(rmdir_obj), MP_VFS_LFSx(rmdir)); -STATIC mp_obj_t MP_VFS_LFSx(rename)(mp_obj_t self_in, mp_obj_t path_old_in, mp_obj_t path_new_in) { +static mp_obj_t MP_VFS_LFSx(rename)(mp_obj_t self_in, mp_obj_t path_old_in, mp_obj_t path_new_in) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); const char *path_old = MP_VFS_LFSx(make_path)(self, path_old_in); const char *path = mp_obj_str_get_str(path_new_in); @@ -278,9 +277,9 @@ STATIC mp_obj_t MP_VFS_LFSx(rename)(mp_obj_t self_in, mp_obj_t path_old_in, mp_o } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(MP_VFS_LFSx(rename_obj), MP_VFS_LFSx(rename)); +static MP_DEFINE_CONST_FUN_OBJ_3(MP_VFS_LFSx(rename_obj), MP_VFS_LFSx(rename)); -STATIC mp_obj_t MP_VFS_LFSx(mkdir)(mp_obj_t self_in, mp_obj_t path_o) { +static mp_obj_t MP_VFS_LFSx(mkdir)(mp_obj_t self_in, mp_obj_t path_o) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); const char *path = MP_VFS_LFSx(make_path)(self, path_o); int ret = LFSx_API(mkdir)(&self->lfs, path); @@ -289,9 +288,9 @@ STATIC mp_obj_t MP_VFS_LFSx(mkdir)(mp_obj_t self_in, mp_obj_t path_o) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(mkdir_obj), MP_VFS_LFSx(mkdir)); +static MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(mkdir_obj), MP_VFS_LFSx(mkdir)); -STATIC mp_obj_t MP_VFS_LFSx(chdir)(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t MP_VFS_LFSx(chdir)(mp_obj_t self_in, mp_obj_t path_in) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); // Check path exists @@ -357,9 +356,9 @@ STATIC mp_obj_t MP_VFS_LFSx(chdir)(mp_obj_t self_in, mp_obj_t path_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(chdir_obj), MP_VFS_LFSx(chdir)); +static MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(chdir_obj), MP_VFS_LFSx(chdir)); -STATIC mp_obj_t MP_VFS_LFSx(getcwd)(mp_obj_t self_in) { +static mp_obj_t MP_VFS_LFSx(getcwd)(mp_obj_t self_in) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); if (vstr_len(&self->cur_dir) == 1) { return MP_OBJ_NEW_QSTR(MP_QSTR__slash_); @@ -368,9 +367,9 @@ STATIC mp_obj_t MP_VFS_LFSx(getcwd)(mp_obj_t self_in) { return mp_obj_new_str(self->cur_dir.buf, self->cur_dir.len - 1); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(MP_VFS_LFSx(getcwd_obj), MP_VFS_LFSx(getcwd)); +static MP_DEFINE_CONST_FUN_OBJ_1(MP_VFS_LFSx(getcwd_obj), MP_VFS_LFSx(getcwd)); -STATIC mp_obj_t MP_VFS_LFSx(stat)(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t MP_VFS_LFSx(stat)(mp_obj_t self_in, mp_obj_t path_in) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); const char *path = MP_VFS_LFSx(make_path)(self, path_in); struct LFSx_API (info) info; @@ -407,16 +406,16 @@ STATIC mp_obj_t MP_VFS_LFSx(stat)(mp_obj_t self_in, mp_obj_t path_in) { return MP_OBJ_FROM_PTR(t); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(stat_obj), MP_VFS_LFSx(stat)); +static MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(stat_obj), MP_VFS_LFSx(stat)); -STATIC int LFSx_API(traverse_cb)(void *data, LFSx_API(block_t) bl) { +static int LFSx_API(traverse_cb)(void *data, LFSx_API(block_t) bl) { (void)bl; uint32_t *n = (uint32_t *)data; *n += 1; return LFSx_MACRO(_ERR_OK); } -STATIC mp_obj_t MP_VFS_LFSx(statvfs)(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t MP_VFS_LFSx(statvfs)(mp_obj_t self_in, mp_obj_t path_in) { (void)path_in; MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); uint32_t n_used_blocks = 0; @@ -443,9 +442,9 @@ STATIC mp_obj_t MP_VFS_LFSx(statvfs)(mp_obj_t self_in, mp_obj_t path_in) { return MP_OBJ_FROM_PTR(t); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(statvfs_obj), MP_VFS_LFSx(statvfs)); +static MP_DEFINE_CONST_FUN_OBJ_2(MP_VFS_LFSx(statvfs_obj), MP_VFS_LFSx(statvfs)); -STATIC mp_obj_t MP_VFS_LFSx(mount)(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs) { +static mp_obj_t MP_VFS_LFSx(mount)(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); (void)mkfs; @@ -458,17 +457,17 @@ STATIC mp_obj_t MP_VFS_LFSx(mount)(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(MP_VFS_LFSx(mount_obj), MP_VFS_LFSx(mount)); +static MP_DEFINE_CONST_FUN_OBJ_3(MP_VFS_LFSx(mount_obj), MP_VFS_LFSx(mount)); -STATIC mp_obj_t MP_VFS_LFSx(umount)(mp_obj_t self_in) { +static mp_obj_t MP_VFS_LFSx(umount)(mp_obj_t self_in) { MP_OBJ_VFS_LFSx *self = MP_OBJ_TO_PTR(self_in); // LFS unmount never fails LFSx_API(unmount)(&self->lfs); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(MP_VFS_LFSx(umount_obj), MP_VFS_LFSx(umount)); +static MP_DEFINE_CONST_FUN_OBJ_1(MP_VFS_LFSx(umount_obj), MP_VFS_LFSx(umount)); -STATIC const mp_rom_map_elem_t MP_VFS_LFSx(locals_dict_table)[] = { +static const mp_rom_map_elem_t MP_VFS_LFSx(locals_dict_table)[] = { { MP_ROM_QSTR(MP_QSTR_mkfs), MP_ROM_PTR(&MP_VFS_LFSx(mkfs_obj)) }, { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&MP_VFS_LFSx(open_obj)) }, { MP_ROM_QSTR(MP_QSTR_ilistdir), MP_ROM_PTR(&MP_VFS_LFSx(ilistdir_obj)) }, @@ -483,9 +482,9 @@ STATIC const mp_rom_map_elem_t MP_VFS_LFSx(locals_dict_table)[] = { { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&MP_VFS_LFSx(mount_obj)) }, { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&MP_VFS_LFSx(umount_obj)) }, }; -STATIC MP_DEFINE_CONST_DICT(MP_VFS_LFSx(locals_dict), MP_VFS_LFSx(locals_dict_table)); +static MP_DEFINE_CONST_DICT(MP_VFS_LFSx(locals_dict), MP_VFS_LFSx(locals_dict_table)); -STATIC mp_import_stat_t MP_VFS_LFSx(import_stat)(void *self_in, const char *path) { +static mp_import_stat_t MP_VFS_LFSx(import_stat)(void *self_in, const char *path) { MP_OBJ_VFS_LFSx *self = self_in; struct LFSx_API (info) info; mp_obj_str_t path_obj = { { &mp_type_str }, 0, 0, (const byte *)path }; @@ -501,7 +500,7 @@ STATIC mp_import_stat_t MP_VFS_LFSx(import_stat)(void *self_in, const char *path return MP_IMPORT_STAT_NO_EXIST; } -STATIC const mp_vfs_proto_t MP_VFS_LFSx(proto) = { +static const mp_vfs_proto_t MP_VFS_LFSx(proto) = { .import_stat = MP_VFS_LFSx(import_stat), }; diff --git a/extmod/vfs_lfsx_file.c b/extmod/vfs_lfsx_file.c index b9f332339733e..ab5cce50088b9 100644 --- a/extmod/vfs_lfsx_file.c +++ b/extmod/vfs_lfsx_file.c @@ -35,13 +35,13 @@ #include "py/mperrno.h" #include "extmod/vfs.h" -STATIC void MP_VFS_LFSx(check_open)(MP_OBJ_VFS_LFSx_FILE * self) { +static void MP_VFS_LFSx(check_open)(MP_OBJ_VFS_LFSx_FILE * self) { if (self->vfs == NULL) { mp_raise_ValueError(NULL); } } -STATIC void MP_VFS_LFSx(file_print)(const mp_print_t * print, mp_obj_t self_in, mp_print_kind_t kind) { +static void MP_VFS_LFSx(file_print)(const mp_print_t * print, mp_obj_t self_in, mp_print_kind_t kind) { (void)self_in; (void)kind; mp_printf(print, "", mp_obj_get_type_str(self_in)); @@ -90,11 +90,10 @@ mp_obj_t MP_VFS_LFSx(file_open)(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mod } #if LFS_BUILD_VERSION == 1 - MP_OBJ_VFS_LFSx_FILE *o = m_new_obj_var_with_finaliser(MP_OBJ_VFS_LFSx_FILE, file_buffer, uint8_t, self->lfs.cfg->prog_size); + MP_OBJ_VFS_LFSx_FILE *o = mp_obj_malloc_var_with_finaliser(MP_OBJ_VFS_LFSx_FILE, uint8_t, self->lfs.cfg->prog_size, type); #else - MP_OBJ_VFS_LFSx_FILE *o = m_new_obj_var_with_finaliser(MP_OBJ_VFS_LFSx_FILE, file_buffer, uint8_t, self->lfs.cfg->cache_size); + MP_OBJ_VFS_LFSx_FILE *o = mp_obj_malloc_var_with_finaliser(MP_OBJ_VFS_LFSx_FILE, uint8_t, self->lfs.cfg->cache_size, type); #endif - o->base.type = type; o->vfs = self; #if !MICROPY_GC_CONSERVATIVE_CLEAR memset(&o->file, 0, sizeof(o->file)); @@ -123,7 +122,7 @@ mp_obj_t MP_VFS_LFSx(file_open)(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mod return MP_OBJ_FROM_PTR(o); } -STATIC mp_uint_t MP_VFS_LFSx(file_read)(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t MP_VFS_LFSx(file_read)(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { MP_OBJ_VFS_LFSx_FILE *self = MP_OBJ_TO_PTR(self_in); MP_VFS_LFSx(check_open)(self); LFSx_API(ssize_t) sz = LFSx_API(file_read)(&self->vfs->lfs, &self->file, buf, size); @@ -134,7 +133,7 @@ STATIC mp_uint_t MP_VFS_LFSx(file_read)(mp_obj_t self_in, void *buf, mp_uint_t s return sz; } -STATIC mp_uint_t MP_VFS_LFSx(file_write)(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t MP_VFS_LFSx(file_write)(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { MP_OBJ_VFS_LFSx_FILE *self = MP_OBJ_TO_PTR(self_in); MP_VFS_LFSx(check_open)(self); #if LFS_BUILD_VERSION == 2 @@ -150,7 +149,7 @@ STATIC mp_uint_t MP_VFS_LFSx(file_write)(mp_obj_t self_in, const void *buf, mp_u return sz; } -STATIC mp_uint_t MP_VFS_LFSx(file_ioctl)(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t MP_VFS_LFSx(file_ioctl)(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { MP_OBJ_VFS_LFSx_FILE *self = MP_OBJ_TO_PTR(self_in); if (request != MP_STREAM_CLOSE) { @@ -195,7 +194,7 @@ STATIC mp_uint_t MP_VFS_LFSx(file_ioctl)(mp_obj_t self_in, mp_uint_t request, ui } } -STATIC const mp_rom_map_elem_t MP_VFS_LFSx(file_locals_dict_table)[] = { +static const mp_rom_map_elem_t MP_VFS_LFSx(file_locals_dict_table)[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) }, @@ -209,9 +208,9 @@ STATIC const mp_rom_map_elem_t MP_VFS_LFSx(file_locals_dict_table)[] = { { MP_ROM_QSTR(MP_QSTR___enter__), MP_ROM_PTR(&mp_identity_obj) }, { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&mp_stream___exit___obj) }, }; -STATIC MP_DEFINE_CONST_DICT(MP_VFS_LFSx(file_locals_dict), MP_VFS_LFSx(file_locals_dict_table)); +static MP_DEFINE_CONST_DICT(MP_VFS_LFSx(file_locals_dict), MP_VFS_LFSx(file_locals_dict_table)); -STATIC const mp_stream_p_t MP_VFS_LFSx(fileio_stream_p) = { +static const mp_stream_p_t MP_VFS_LFSx(fileio_stream_p) = { .read = MP_VFS_LFSx(file_read), .write = MP_VFS_LFSx(file_write), .ioctl = MP_VFS_LFSx(file_ioctl), @@ -226,7 +225,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &MP_VFS_LFSx(file_locals_dict) ); -STATIC const mp_stream_p_t MP_VFS_LFSx(textio_stream_p) = { +static const mp_stream_p_t MP_VFS_LFSx(textio_stream_p) = { .read = MP_VFS_LFSx(file_read), .write = MP_VFS_LFSx(file_write), .ioctl = MP_VFS_LFSx(file_ioctl), diff --git a/extmod/vfs_posix.c b/extmod/vfs_posix.c index e29b47cccda83..ed4c06e36731e 100644 --- a/extmod/vfs_posix.c +++ b/extmod/vfs_posix.c @@ -57,7 +57,7 @@ typedef struct _mp_obj_vfs_posix_t { bool readonly; } mp_obj_vfs_posix_t; -STATIC const char *vfs_posix_get_path_str(mp_obj_vfs_posix_t *self, mp_obj_t path) { +static const char *vfs_posix_get_path_str(mp_obj_vfs_posix_t *self, mp_obj_t path) { const char *path_str = mp_obj_str_get_str(path); if (self->root_len == 0 || path_str[0] != '/') { return path_str; @@ -68,7 +68,7 @@ STATIC const char *vfs_posix_get_path_str(mp_obj_vfs_posix_t *self, mp_obj_t pat } } -STATIC mp_obj_t vfs_posix_get_path_obj(mp_obj_vfs_posix_t *self, mp_obj_t path) { +static mp_obj_t vfs_posix_get_path_obj(mp_obj_vfs_posix_t *self, mp_obj_t path) { const char *path_str = mp_obj_str_get_str(path); if (self->root_len == 0 || path_str[0] != '/') { return path; @@ -79,7 +79,7 @@ STATIC mp_obj_t vfs_posix_get_path_obj(mp_obj_vfs_posix_t *self, mp_obj_t path) } } -STATIC mp_obj_t vfs_posix_fun1_helper(mp_obj_t self_in, mp_obj_t path_in, int (*f)(const char *)) { +static mp_obj_t vfs_posix_fun1_helper(mp_obj_t self_in, mp_obj_t path_in, int (*f)(const char *)) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); int ret = f(vfs_posix_get_path_str(self, path_in)); if (ret != 0) { @@ -88,7 +88,7 @@ STATIC mp_obj_t vfs_posix_fun1_helper(mp_obj_t self_in, mp_obj_t path_in, int (* return mp_const_none; } -STATIC mp_import_stat_t mp_vfs_posix_import_stat(void *self_in, const char *path) { +static mp_import_stat_t mp_vfs_posix_import_stat(void *self_in, const char *path) { mp_obj_vfs_posix_t *self = self_in; if (self->root_len != 0) { self->root.len = self->root_len; @@ -106,7 +106,7 @@ 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, size_t n_kw, const mp_obj_t *args) { +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 = mp_obj_malloc(mp_obj_vfs_posix_t, type); @@ -142,7 +142,7 @@ STATIC mp_obj_t vfs_posix_make_new(const mp_obj_type_t *type, size_t n_args, siz return MP_OBJ_FROM_PTR(vfs); } -STATIC mp_obj_t vfs_posix_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs) { +static mp_obj_t vfs_posix_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mkfs) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); if (mp_obj_is_true(readonly)) { self->readonly = true; @@ -152,15 +152,15 @@ STATIC mp_obj_t vfs_posix_mount(mp_obj_t self_in, mp_obj_t readonly, mp_obj_t mk } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(vfs_posix_mount_obj, vfs_posix_mount); +static MP_DEFINE_CONST_FUN_OBJ_3(vfs_posix_mount_obj, vfs_posix_mount); -STATIC mp_obj_t vfs_posix_umount(mp_obj_t self_in) { +static mp_obj_t vfs_posix_umount(mp_obj_t self_in) { (void)self_in; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_umount_obj, vfs_posix_umount); +static MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_umount_obj, vfs_posix_umount); -STATIC mp_obj_t vfs_posix_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode_in) { +static mp_obj_t vfs_posix_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode_in) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); const char *mode = mp_obj_str_get_str(mode_in); if (self->readonly @@ -172,14 +172,14 @@ STATIC mp_obj_t vfs_posix_open(mp_obj_t self_in, mp_obj_t path_in, mp_obj_t mode } return mp_vfs_posix_file_open(&mp_type_vfs_posix_textio, path_in, mode_in); } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(vfs_posix_open_obj, vfs_posix_open); +static MP_DEFINE_CONST_FUN_OBJ_3(vfs_posix_open_obj, vfs_posix_open); -STATIC mp_obj_t vfs_posix_chdir(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t vfs_posix_chdir(mp_obj_t self_in, mp_obj_t path_in) { return vfs_posix_fun1_helper(self_in, path_in, chdir); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_chdir_obj, vfs_posix_chdir); +static MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_chdir_obj, vfs_posix_chdir); -STATIC mp_obj_t vfs_posix_getcwd(mp_obj_t self_in) { +static mp_obj_t vfs_posix_getcwd(mp_obj_t self_in) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); char buf[MICROPY_ALLOC_PATH_MAX + 1]; const char *ret = getcwd(buf, sizeof(buf)); @@ -196,7 +196,7 @@ STATIC mp_obj_t vfs_posix_getcwd(mp_obj_t self_in) { } return mp_obj_new_str(ret, strlen(ret)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_getcwd_obj, vfs_posix_getcwd); +static MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_getcwd_obj, vfs_posix_getcwd); typedef struct _vfs_posix_ilistdir_it_t { mp_obj_base_t base; @@ -206,7 +206,7 @@ typedef struct _vfs_posix_ilistdir_it_t { DIR *dir; } vfs_posix_ilistdir_it_t; -STATIC mp_obj_t vfs_posix_ilistdir_it_iternext(mp_obj_t self_in) { +static mp_obj_t vfs_posix_ilistdir_it_iternext(mp_obj_t self_in) { vfs_posix_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); if (self->dir == NULL) { @@ -266,7 +266,7 @@ STATIC mp_obj_t vfs_posix_ilistdir_it_iternext(mp_obj_t self_in) { } } -STATIC mp_obj_t vfs_posix_ilistdir_it_del(mp_obj_t self_in) { +static mp_obj_t vfs_posix_ilistdir_it_del(mp_obj_t self_in) { vfs_posix_ilistdir_it_t *self = MP_OBJ_TO_PTR(self_in); if (self->dir != NULL) { MP_THREAD_GIL_EXIT(); @@ -276,10 +276,9 @@ STATIC mp_obj_t vfs_posix_ilistdir_it_del(mp_obj_t self_in) { return mp_const_none; } -STATIC mp_obj_t vfs_posix_ilistdir(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t vfs_posix_ilistdir(mp_obj_t self_in, mp_obj_t path_in) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); - vfs_posix_ilistdir_it_t *iter = m_new_obj_with_finaliser(vfs_posix_ilistdir_it_t); - iter->base.type = &mp_type_polymorph_iter_with_finaliser; + vfs_posix_ilistdir_it_t *iter = mp_obj_malloc_with_finaliser(vfs_posix_ilistdir_it_t, &mp_type_polymorph_iter_with_finaliser); iter->iternext = vfs_posix_ilistdir_it_iternext; iter->finaliser = vfs_posix_ilistdir_it_del; iter->is_str = mp_obj_get_type(path_in) == &mp_type_str; @@ -295,7 +294,7 @@ STATIC mp_obj_t vfs_posix_ilistdir(mp_obj_t self_in, mp_obj_t path_in) { } return MP_OBJ_FROM_PTR(iter); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_ilistdir_obj, vfs_posix_ilistdir); +static MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_ilistdir_obj, vfs_posix_ilistdir); typedef struct _mp_obj_listdir_t { mp_obj_base_t base; @@ -303,7 +302,7 @@ typedef struct _mp_obj_listdir_t { DIR *dir; } mp_obj_listdir_t; -STATIC mp_obj_t vfs_posix_mkdir(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t vfs_posix_mkdir(mp_obj_t self_in, mp_obj_t path_in) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); const char *path = vfs_posix_get_path_str(self, path_in); MP_THREAD_GIL_EXIT(); @@ -318,14 +317,14 @@ STATIC mp_obj_t vfs_posix_mkdir(mp_obj_t self_in, mp_obj_t path_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_mkdir_obj, vfs_posix_mkdir); +static MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_mkdir_obj, vfs_posix_mkdir); -STATIC mp_obj_t vfs_posix_remove(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t vfs_posix_remove(mp_obj_t self_in, mp_obj_t path_in) { return vfs_posix_fun1_helper(self_in, path_in, unlink); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_remove_obj, vfs_posix_remove); +static MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_remove_obj, vfs_posix_remove); -STATIC mp_obj_t vfs_posix_rename(mp_obj_t self_in, mp_obj_t old_path_in, mp_obj_t new_path_in) { +static mp_obj_t vfs_posix_rename(mp_obj_t self_in, mp_obj_t old_path_in, mp_obj_t new_path_in) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); const char *old_path = vfs_posix_get_path_str(self, old_path_in); const char *new_path = vfs_posix_get_path_str(self, new_path_in); @@ -337,14 +336,14 @@ STATIC mp_obj_t vfs_posix_rename(mp_obj_t self_in, mp_obj_t old_path_in, mp_obj_ } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(vfs_posix_rename_obj, vfs_posix_rename); +static MP_DEFINE_CONST_FUN_OBJ_3(vfs_posix_rename_obj, vfs_posix_rename); -STATIC mp_obj_t vfs_posix_rmdir(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t vfs_posix_rmdir(mp_obj_t self_in, mp_obj_t path_in) { return vfs_posix_fun1_helper(self_in, path_in, rmdir); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_rmdir_obj, vfs_posix_rmdir); +static MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_rmdir_obj, vfs_posix_rmdir); -STATIC mp_obj_t vfs_posix_stat(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t vfs_posix_stat(mp_obj_t self_in, mp_obj_t path_in) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); struct stat sb; const char *path = vfs_posix_get_path_str(self, path_in); @@ -363,7 +362,7 @@ STATIC mp_obj_t vfs_posix_stat(mp_obj_t self_in, mp_obj_t path_in) { t->items[9] = mp_obj_new_int_from_uint(sb.st_ctime); return MP_OBJ_FROM_PTR(t); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_stat_obj, vfs_posix_stat); +static MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_stat_obj, vfs_posix_stat); #if MICROPY_PY_OS_STATVFS @@ -387,7 +386,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_stat_obj, vfs_posix_stat); #define F_FLAG sb.f_flag #endif -STATIC mp_obj_t vfs_posix_statvfs(mp_obj_t self_in, mp_obj_t path_in) { +static mp_obj_t vfs_posix_statvfs(mp_obj_t self_in, mp_obj_t path_in) { mp_obj_vfs_posix_t *self = MP_OBJ_TO_PTR(self_in); STRUCT_STATVFS sb; const char *path = vfs_posix_get_path_str(self, path_in); @@ -406,11 +405,11 @@ STATIC mp_obj_t vfs_posix_statvfs(mp_obj_t self_in, mp_obj_t path_in) { t->items[9] = MP_OBJ_NEW_SMALL_INT(F_NAMEMAX); return MP_OBJ_FROM_PTR(t); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_statvfs_obj, vfs_posix_statvfs); +static MP_DEFINE_CONST_FUN_OBJ_2(vfs_posix_statvfs_obj, vfs_posix_statvfs); #endif -STATIC const mp_rom_map_elem_t vfs_posix_locals_dict_table[] = { +static const mp_rom_map_elem_t vfs_posix_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_mount), MP_ROM_PTR(&vfs_posix_mount_obj) }, { MP_ROM_QSTR(MP_QSTR_umount), MP_ROM_PTR(&vfs_posix_umount_obj) }, { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&vfs_posix_open_obj) }, @@ -427,9 +426,9 @@ STATIC const mp_rom_map_elem_t vfs_posix_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_statvfs), MP_ROM_PTR(&vfs_posix_statvfs_obj) }, #endif }; -STATIC MP_DEFINE_CONST_DICT(vfs_posix_locals_dict, vfs_posix_locals_dict_table); +static MP_DEFINE_CONST_DICT(vfs_posix_locals_dict, vfs_posix_locals_dict_table); -STATIC const mp_vfs_proto_t vfs_posix_proto = { +static const mp_vfs_proto_t vfs_posix_proto = { .import_stat = mp_vfs_posix_import_stat, }; diff --git a/extmod/vfs_posix_file.c b/extmod/vfs_posix_file.c index 2f70789543911..bc06bc74db1cb 100644 --- a/extmod/vfs_posix_file.c +++ b/extmod/vfs_posix_file.c @@ -47,7 +47,7 @@ typedef struct _mp_obj_vfs_posix_file_t { } mp_obj_vfs_posix_file_t; #if MICROPY_CPYTHON_COMPAT -STATIC void check_fd_is_open(const mp_obj_vfs_posix_file_t *o) { +static void check_fd_is_open(const mp_obj_vfs_posix_file_t *o) { if (o->fd < 0) { mp_raise_ValueError(MP_ERROR_TEXT("I/O operation on closed file")); } @@ -56,14 +56,13 @@ STATIC void check_fd_is_open(const mp_obj_vfs_posix_file_t *o) { #define check_fd_is_open(o) #endif -STATIC void vfs_posix_file_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void vfs_posix_file_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_vfs_posix_file_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", mp_obj_get_type_str(self_in), self->fd); } mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_obj_t mode_in) { - mp_obj_vfs_posix_file_t *o = m_new_obj_with_finaliser(mp_obj_vfs_posix_file_t); const char *mode_s = mp_obj_str_get_str(mode_in); int mode_rw = 0, mode_x = 0; @@ -92,7 +91,8 @@ mp_obj_t mp_vfs_posix_file_open(const mp_obj_type_t *type, mp_obj_t file_in, mp_ } } - o->base.type = type; + mp_obj_vfs_posix_file_t *o = mp_obj_malloc_with_finaliser(mp_obj_vfs_posix_file_t, type); + o->fd = -1; // In case open() fails below, initialise this as a "closed" file object. mp_obj_t fid = file_in; @@ -108,14 +108,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_fileno(mp_obj_t self_in) { +static mp_obj_t vfs_posix_file_fileno(mp_obj_t self_in) { mp_obj_vfs_posix_file_t *self = MP_OBJ_TO_PTR(self_in); check_fd_is_open(self); return MP_OBJ_NEW_SMALL_INT(self->fd); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_file_fileno_obj, vfs_posix_file_fileno); +static MP_DEFINE_CONST_FUN_OBJ_1(vfs_posix_file_fileno_obj, vfs_posix_file_fileno); -STATIC mp_uint_t vfs_posix_file_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t vfs_posix_file_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { mp_obj_vfs_posix_file_t *o = MP_OBJ_TO_PTR(o_in); check_fd_is_open(o); ssize_t r; @@ -126,7 +126,7 @@ STATIC mp_uint_t vfs_posix_file_read(mp_obj_t o_in, void *buf, mp_uint_t size, i return (mp_uint_t)r; } -STATIC mp_uint_t vfs_posix_file_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t vfs_posix_file_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_vfs_posix_file_t *o = MP_OBJ_TO_PTR(o_in); check_fd_is_open(o); #if MICROPY_PY_OS_DUPTERM @@ -143,7 +143,7 @@ STATIC mp_uint_t vfs_posix_file_write(mp_obj_t o_in, const void *buf, mp_uint_t return (mp_uint_t)r; } -STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { mp_obj_vfs_posix_file_t *o = MP_OBJ_TO_PTR(o_in); if (request != MP_STREAM_CLOSE) { @@ -237,7 +237,7 @@ STATIC mp_uint_t vfs_posix_file_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_ } } -STATIC const mp_rom_map_elem_t vfs_posix_rawfile_locals_dict_table[] = { +static const mp_rom_map_elem_t vfs_posix_rawfile_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_fileno), MP_ROM_PTR(&vfs_posix_file_fileno_obj) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, @@ -253,9 +253,9 @@ STATIC const mp_rom_map_elem_t vfs_posix_rawfile_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&mp_stream___exit___obj) }, }; -STATIC MP_DEFINE_CONST_DICT(vfs_posix_rawfile_locals_dict, vfs_posix_rawfile_locals_dict_table); +static MP_DEFINE_CONST_DICT(vfs_posix_rawfile_locals_dict, vfs_posix_rawfile_locals_dict_table); -STATIC const mp_stream_p_t vfs_posix_fileio_stream_p = { +static const mp_stream_p_t vfs_posix_fileio_stream_p = { .read = vfs_posix_file_read, .write = vfs_posix_file_write, .ioctl = vfs_posix_file_ioctl, @@ -270,7 +270,7 @@ MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &vfs_posix_rawfile_locals_dict ); -STATIC const mp_stream_p_t vfs_posix_textio_stream_p = { +static const mp_stream_p_t vfs_posix_textio_stream_p = { .read = vfs_posix_file_read, .write = vfs_posix_file_write, .ioctl = vfs_posix_file_ioctl, @@ -288,7 +288,7 @@ mp_obj_vfs_posix_file_t mp_sys_stdin_obj; mp_obj_vfs_posix_file_t mp_sys_stdout_obj; mp_obj_vfs_posix_file_t mp_sys_stderr_obj; -STATIC void vfs_posix_textio_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void vfs_posix_textio_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { // These objects are read-only. return; diff --git a/extmod/vfs_reader.c b/extmod/vfs_reader.c index 13fc31bee5080..80d0fa6344aa1 100644 --- a/extmod/vfs_reader.c +++ b/extmod/vfs_reader.c @@ -49,7 +49,7 @@ typedef struct _mp_reader_vfs_t { byte buf[]; } mp_reader_vfs_t; -STATIC mp_uint_t mp_reader_vfs_readbyte(void *data) { +static mp_uint_t mp_reader_vfs_readbyte(void *data) { mp_reader_vfs_t *reader = (mp_reader_vfs_t *)data; if (reader->bufpos >= reader->buflen) { if (reader->buflen < reader->bufsize) { @@ -70,7 +70,7 @@ STATIC mp_uint_t mp_reader_vfs_readbyte(void *data) { return reader->buf[reader->bufpos++]; } -STATIC void mp_reader_vfs_close(void *data) { +static void mp_reader_vfs_close(void *data) { mp_reader_vfs_t *reader = (mp_reader_vfs_t *)data; mp_stream_close(reader->file); m_del_obj(mp_reader_vfs_t, reader); diff --git a/lib/berkeley-db-1.xx b/lib/berkeley-db-1.xx index 35aaec4418ad7..85373b548f1fb 160000 --- a/lib/berkeley-db-1.xx +++ b/lib/berkeley-db-1.xx @@ -1 +1 @@ -Subproject commit 35aaec4418ad78628a3b935885dd189d41ce779b +Subproject commit 85373b548f1fb0119a463582570b44189dfb09ae diff --git a/lib/mbedtls_config/mbedtls_config_port.h b/lib/mbedtls_config/mbedtls_config_port.h new file mode 100644 index 0000000000000..1752d946529f2 --- /dev/null +++ b/lib/mbedtls_config/mbedtls_config_port.h @@ -0,0 +1,67 @@ +/* + * This file is part of the MicroPython project, http://micropython.org/ + * + * The MIT License (MIT) + * + * Copyright (c) 2018-2019 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 MICROPY_INCLUDED_MBEDTLS_CONFIG_H +#define MICROPY_INCLUDED_MBEDTLS_CONFIG_H + +// If you want to debug MBEDTLS uncomment the following and +// Pass 3 to mbedtls_debug_set_threshold in socket_new +// #define MBEDTLS_DEBUG_C + +// Set mbedtls configuration +#define MBEDTLS_PLATFORM_C +#define MBEDTLS_PLATFORM_MEMORY +#define MBEDTLS_PLATFORM_NO_STD_FUNCTIONS +#define MBEDTLS_DEPRECATED_REMOVED +#define MBEDTLS_ENTROPY_HARDWARE_ALT + +// Enable mbedtls modules +#define MBEDTLS_MD_C +#define MBEDTLS_MD5_C +#define MBEDTLS_SHA1_C +#define MBEDTLS_SHA256_C +#define MBEDTLS_SHA512_C +#undef MBEDTLS_HAVE_TIME_DATE + +<<<<<<<< HEAD:lib/mbedtls_config/mbedtls_config_hashlib.h +// Memory allocation hooks +#include +#include +void *m_tracked_calloc(size_t nmemb, size_t size); +void m_tracked_free(void *ptr); +#define MBEDTLS_PLATFORM_STD_CALLOC m_tracked_calloc +#define MBEDTLS_PLATFORM_STD_FREE m_tracked_free +#define MBEDTLS_PLATFORM_SNPRINTF_MACRO snprintf +======== +// Time hook +#include +time_t rp2_rtctime_seconds(time_t *timer); +#define MBEDTLS_PLATFORM_TIME_MACRO rp2_rtctime_seconds +#define MBEDTLS_PLATFORM_MS_TIME_ALT mbedtls_ms_time +>>>>>>>> v1.23.0:lib/mbedtls_config/mbedtls_config_port.h + +#include "mbedtls/check_config.h" + +#endif /* MICROPY_INCLUDED_MBEDTLS_CONFIG_H */ diff --git a/lib/micropython-lib b/lib/micropython-lib index 7cdf70881519c..50ed36fbeb919 160000 --- a/lib/micropython-lib +++ b/lib/micropython-lib @@ -1 +1 @@ -Subproject commit 7cdf70881519c73667efbc4a61a04d9c1a49babb +Subproject commit 50ed36fbeb919753bcc26ce13a8cffd7691d06ef diff --git a/lib/protomatter b/lib/protomatter index 282920f9ce594..0bd9873153ab0 160000 --- a/lib/protomatter +++ b/lib/protomatter @@ -1 +1 @@ -Subproject commit 282920f9ce5948c02e1c803b9c2b6ecee7dc7b66 +Subproject commit 0bd9873153ab0a91d6737c392622159a4515a2e5 diff --git a/locale/circuitpython.pot b/locale/circuitpython.pot index 25d4a28312287..7d02a77ebf42b 100644 --- a/locale/circuitpython.pot +++ b/locale/circuitpython.pot @@ -414,6 +414,10 @@ msgstr "" msgid "'label' requires 1 argument" msgstr "" +#: py/emitnative.c +msgid "'not' not implemented" +msgstr "" + #: py/compile.c msgid "'return' outside function" msgstr "" @@ -2402,6 +2406,10 @@ msgstr "" msgid "argsort is not implemented for flattened arrays" msgstr "" +#: extmod/ulab/code/numpy/random/random.c +msgid "argument must be None, an integer or a tuple of integers" +msgstr "" + #: py/compile.c msgid "argument name reused" msgstr "" @@ -2636,6 +2644,10 @@ msgstr "" msgid "can't do binary op between '%q' and '%q'" msgstr "" +#: py/emitnative.c +msgid "can't do unary op of '%q'" +msgstr "" + #: py/emitnative.c msgid "can't implicitly convert '%q' to 'bool'" msgstr "" @@ -2698,10 +2710,6 @@ msgstr "" msgid "can't truncate-divide a complex number" msgstr "" -#: extmod/moductypes.c -msgid "can't unambiguously get sizeof scalar" -msgstr "" - #: extmod/modasyncio.c msgid "can't wait" msgstr "" @@ -3428,7 +3436,7 @@ msgstr "" msgid "max_length must be 0-%d when fixed_length is %s" msgstr "" -#: extmod/ulab/code/ndarray.c +#: extmod/ulab/code/ndarray.c extmod/ulab/code/numpy/random/random.c msgid "maximum number of dimensions is " msgstr "" @@ -3570,7 +3578,7 @@ msgstr "" msgid "no default packer" msgstr "" -#: extmod/modrandom.c +#: extmod/modrandom.c extmod/ulab/code/numpy/random/random.c msgid "no default seed" msgstr "" @@ -3779,6 +3787,10 @@ msgstr "" msgid "out array is too small" msgstr "" +#: extmod/ulab/code/numpy/random/random.c +msgid "out has wrong type" +msgstr "" + #: extmod/ulab/code/numpy/vector.c msgid "out keyword is not supported for complex dtype" msgstr "" @@ -3803,6 +3815,14 @@ msgstr "" msgid "out of range of target" msgstr "" +#: extmod/ulab/code/numpy/random/random.c +msgid "output array has wrong type" +msgstr "" + +#: extmod/ulab/code/numpy/random/random.c +msgid "output array must be contiguous" +msgstr "" + #: py/objint_mpz.c msgid "overflow converting long int to machine word" msgstr "" @@ -3929,6 +3949,10 @@ msgstr "" msgid "set unsupported" msgstr "" +#: extmod/ulab/code/numpy/random/random.c +msgid "shape must be None, and integer or a tuple of integers" +msgstr "" + #: extmod/ulab/code/ndarray.c msgid "shape must be integer or tuple of integers" msgstr "" @@ -3949,6 +3973,10 @@ msgstr "" msgid "size is defined for ndarrays only" msgstr "" +#: extmod/ulab/code/numpy/random/random.c +msgid "size must match out.shape when used together" +msgstr "" + #: py/nativeglue.c msgid "slice unsupported" msgstr "" @@ -4022,18 +4050,6 @@ msgstr "" msgid "string indices must be integers, not %s" msgstr "" -#: extmod/moductypes.c -msgid "struct: can't index" -msgstr "" - -#: extmod/moductypes.c -msgid "struct: index out of range" -msgstr "" - -#: extmod/moductypes.c -msgid "struct: no fields" -msgstr "" - #: py/objarray.c py/objstr.c msgid "substring not found" msgstr "" @@ -4046,10 +4062,6 @@ msgstr "" msgid "syntax error in JSON" msgstr "" -#: extmod/moductypes.c -msgid "syntax error in uctypes descriptor" -msgstr "" - #: extmod/modtime.c msgid "ticks interval overflow" msgstr "" @@ -4158,10 +4170,6 @@ msgstr "" msgid "ulonglong too large" msgstr "" -#: py/emitnative.c -msgid "unary op %q not implemented" -msgstr "" - #: py/parse.c msgid "unexpected indent" msgstr "" diff --git a/logo/vector-logo-2.ico b/logo/vector-logo-2.ico deleted file mode 100644 index 24b12812cf49e..0000000000000 Binary files a/logo/vector-logo-2.ico and /dev/null differ diff --git a/mpy-cross/fmode.c b/mpy-cross/fmode.c index f32a4af5d335b..3a761c8333cb1 100644 --- a/mpy-cross/fmode.c +++ b/mpy-cross/fmode.c @@ -10,7 +10,7 @@ // Workaround for setting file translation mode: we must distinguish toolsets // since mingw has no _set_fmode, and altering msvc's _fmode directly has no effect -STATIC int set_fmode_impl(int mode) { +static int set_fmode_impl(int mode) { #ifndef _MSC_VER _fmode = mode; return 0; diff --git a/mpy-cross/main.c b/mpy-cross/main.c index acbd30b64bbdf..611da76468728 100644 --- a/mpy-cross/main.c +++ b/mpy-cross/main.c @@ -42,30 +42,30 @@ #endif // Command line options, with their defaults -STATIC uint emit_opt = MP_EMIT_OPT_NONE; +static uint emit_opt = MP_EMIT_OPT_NONE; mp_uint_t mp_verbose_flag = 0; // Heap size of GC heap (if enabled) // Make it larger on a 64 bit machine, because pointers are larger. long heap_size = 1024 * 1024 * (sizeof(mp_uint_t) / 4); -STATIC void stdout_print_strn(void *env, const char *str, size_t len) { +static void stdout_print_strn(void *env, const char *str, size_t len) { (void)env; ssize_t dummy = write(STDOUT_FILENO, str, len); (void)dummy; } -STATIC const mp_print_t mp_stdout_print = {NULL, stdout_print_strn}; +static const mp_print_t mp_stdout_print = {NULL, stdout_print_strn}; -STATIC void stderr_print_strn(void *env, const char *str, size_t len) { +static void stderr_print_strn(void *env, const char *str, size_t len) { (void)env; ssize_t dummy = write(STDERR_FILENO, str, len); (void)dummy; } -STATIC const mp_print_t mp_stderr_print = {NULL, stderr_print_strn}; +static const mp_print_t mp_stderr_print = {NULL, stderr_print_strn}; -STATIC int compile_and_save(const char *file, const char *output_file, const char *source_file) { +static int compile_and_save(const char *file, const char *output_file, const char *source_file) { nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { mp_lexer_t *lex; @@ -118,7 +118,7 @@ STATIC int compile_and_save(const char *file, const char *output_file, const cha } } -STATIC int usage(char **argv) { +static int usage(char **argv) { printf( "usage: %s [] [-X ] [--] \n" "Options:\n" @@ -156,7 +156,7 @@ STATIC int usage(char **argv) { } // Process options which set interpreter init options -STATIC void pre_process_options(int argc, char **argv) { +static void pre_process_options(int argc, char **argv) { for (int a = 1; a < argc; a++) { if (argv[a][0] == '-') { if (strcmp(argv[a], "-X") == 0) { @@ -202,7 +202,7 @@ STATIC void pre_process_options(int argc, char **argv) { } } -STATIC char *backslash_to_forwardslash(char *path) { +static char *backslash_to_forwardslash(char *path) { for (char *p = path; p != NULL && *p != '\0'; ++p) { if (*p == '\\') { *p = '/'; diff --git a/mpy-cross/windows-fmode.c b/mpy-cross/windows-fmode.c index a7976b87e32dc..128c951ec40cd 100644 --- a/mpy-cross/windows-fmode.c +++ b/mpy-cross/windows-fmode.c @@ -31,7 +31,7 @@ // Workaround for setting file translation mode: we must distinguish toolsets // since mingw has no _set_fmode, and altering msvc's _fmode directly has no effect -STATIC int set_fmode_impl(int mode) { +static int set_fmode_impl(int mode) { #ifndef _MSC_VER _fmode = mode; return 0; diff --git a/ports/atmel-samd/boards/bdmicro_vina_d21/board.c b/ports/atmel-samd/boards/bdmicro_vina_d21/board.c index 019e4615653c3..b0b21a53d90ab 100644 --- a/ports/atmel-samd/boards/bdmicro_vina_d21/board.c +++ b/ports/atmel-samd/boards/bdmicro_vina_d21/board.c @@ -7,16 +7,4 @@ #include "supervisor/board.h" #include "mpconfigboard.h" -void board_init(void) { - // struct port_config pin_conf; - // port_get_config_defaults(&pin_conf); - // - // pin_conf.direction = PORT_PIN_DIR_OUTPUT; - // port_pin_set_config(MICROPY_HW_LED_TX, &pin_conf); - // port_pin_set_output_level(MICROPY_HW_LED_TX, true); - // - // port_pin_set_config(MICROPY_HW_LED_RX, &pin_conf); - // port_pin_set_output_level(MICROPY_HW_LED_RX, true); -} - // Use the MP_WEAK supervisor/shared/board.c versions of routines not defined here. diff --git a/ports/atmel-samd/boards/bdmicro_vina_d21/mpconfigboard.mk b/ports/atmel-samd/boards/bdmicro_vina_d21/mpconfigboard.mk index 1a8cddfda7dc6..496a65512bb74 100644 --- a/ports/atmel-samd/boards/bdmicro_vina_d21/mpconfigboard.mk +++ b/ports/atmel-samd/boards/bdmicro_vina_d21/mpconfigboard.mk @@ -9,3 +9,5 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "MX25L51245G","GD25S512MD" LONGINT_IMPL = MPZ + +CIRCUITPY_RAINBOWIO = 0 diff --git a/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.mk b/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.mk index c3b8f643139bd..004181148415a 100644 --- a/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/feather_m0_express/mpconfigboard.mk @@ -9,3 +9,5 @@ CHIP_FAMILY = samd21 SPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "S25FL216K, GD25Q16C, W25Q16JVxQ" LONGINT_IMPL = MPZ + +CIRCUITPY_RAINBOWIO = 0 diff --git a/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h b/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h index 79285f8b3df3b..be48cb810550e 100644 --- a/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h +++ b/ports/atmel-samd/boards/feather_m0_supersized/mpconfigboard.h @@ -30,6 +30,24 @@ #define DEFAULT_UART_BUS_RX (&pin_PA11) #define DEFAULT_UART_BUS_TX (&pin_PA10) +// Other some pins that do not appear in the pinout & are not used internally +// this list is not (yet) exhaustive +#define IGNORE_PIN_PA03 1 +#define IGNORE_PIN_PB01 1 +#define IGNORE_PIN_PB03 1 +#define IGNORE_PIN_PB04 1 +#define IGNORE_PIN_PB05 1 +#define IGNORE_PIN_PB06 1 +#define IGNORE_PIN_PB07 1 +#define IGNORE_PIN_PB12 1 + // USB is always used internally so skip the pin objects for it. #define IGNORE_PIN_PA24 1 #define IGNORE_PIN_PA25 1 + +// USBHOSTEN on the schematic but not connected. +#define IGNORE_PIN_PA28 1 + +// SWD pins +#define IGNORE_PIN_PA30 1 +#define IGNORE_PIN_PA31 1 diff --git a/ports/atmel-samd/boards/hallowing_m4_express/mpconfigboard.mk b/ports/atmel-samd/boards/hallowing_m4_express/mpconfigboard.mk index 3838baa53e8a2..74f1d3e55993e 100644 --- a/ports/atmel-samd/boards/hallowing_m4_express/mpconfigboard.mk +++ b/ports/atmel-samd/boards/hallowing_m4_express/mpconfigboard.mk @@ -9,5 +9,7 @@ CHIP_FAMILY = samd51 QSPI_FLASH_FILESYSTEM = 1 EXTERNAL_FLASH_DEVICES = "GD25Q64C,W25Q64JVxQ" LONGINT_IMPL = MPZ + +CIRCUITPY_AESIO = 0 CIRCUITPY_JPEGIO = 0 CIRCUITPY_SYNTHIO = 0 diff --git a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk index 9ca9259747726..ebe9403c34d75 100644 --- a/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk +++ b/ports/atmel-samd/boards/kicksat-sprite/mpconfigboard.mk @@ -9,7 +9,7 @@ CHIP_FAMILY = samd51 INTERNAL_FLASH_FILESYSTEM = 1 LONGINT_IMPL = MPZ -# Not needed. +# Turn off to make fit. CIRCUITPY_AESIO = 0 CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_AUDIOCORE = 0 @@ -24,6 +24,7 @@ CIRCUITPY_PIXELMAP = 0 CIRCUITPY_GETPASS = 0 CIRCUITPY_KEYPAD = 0 CIRCUITPY_MSGPACK = 0 +CIRCUITPY_PIXELBUF = 0 CIRCUITPY_PS2IO = 0 CIRCUITPY_RGBMATRIX = 0 CIRCUITPY_RAINBOWIO = 0 @@ -31,6 +32,7 @@ CIRCUITPY_ROTARYIO = 0 CIRCUITPY_TOUCHIO = 0 CIRCUITPY_USB_HID = 0 CIRCUITPY_USB_MIDI = 0 +CIRCUITPY_WARNINGS = 0 CIRCUITPY_ULAB = 0 diff --git a/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.h b/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.h index 3078c5794a47f..3fd421886911b 100644 --- a/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.h +++ b/ports/atmel-samd/boards/sparkfun_redboard_turbo/mpconfigboard.h @@ -38,6 +38,10 @@ #define DEFAULT_UART_BUS_RX (&pin_PA11) #define DEFAULT_UART_BUS_TX (&pin_PA10) +// These pins are connected to the external crystal. +#define IGNORE_PIN_PA00 1 +#define IGNORE_PIN_PA01 1 + // USB is always used internally so skip the pin objects for it. #define IGNORE_PIN_PA24 1 #define IGNORE_PIN_PA25 1 diff --git a/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk b/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk index 91334a68373ef..eabfd82df3ebb 100644 --- a/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk +++ b/ports/atmel-samd/boards/winterbloom_sol/mpconfigboard.mk @@ -15,6 +15,7 @@ EXTERNAL_FLASH_DEVICES = "GD25Q64C, W25Q32JVxQ" LONGINT_IMPL = MPZ # Disable modules that are unusable on this special-purpose board. +CIRCUITPY_AESIO = 0 CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_AUDIOIO = 0 CIRCUITPY_BITMAPFILTER = 0 diff --git a/ports/atmel-samd/mpconfigport.h b/ports/atmel-samd/mpconfigport.h index 4100230815aad..f02f3d595d9b4 100644 --- a/ports/atmel-samd/mpconfigport.h +++ b/ports/atmel-samd/mpconfigport.h @@ -46,6 +46,12 @@ // Only support simpler HID descriptors on SAMD21. #define CIRCUITPY_USB_HID_MAX_REPORT_IDS_PER_DESCRIPTOR (1) +// Avoid linker error: +// :(.text.nlr_push+0x20): relocation truncated to fit: R_ARM_THM_JUMP11 against symbol `nlr_push_tail' defined in .text.nlr_push_tail section in /tmp/ccvHNpPQ.ltrans0.ltrans.o +// See https://github.com/micropython/micropython/pull/11353 +#define MICROPY_NLR_THUMB_USE_LONG_JUMP (1) + + #endif // SAMD21 //////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/ports/espressif/bindings/espcamera/Camera.c b/ports/espressif/bindings/espcamera/Camera.c index 69bb6282e698f..41d47a01d172e 100644 --- a/ports/espressif/bindings/espcamera/Camera.c +++ b/ports/espressif/bindings/espcamera/Camera.c @@ -120,8 +120,7 @@ static mp_obj_t espcamera_camera_make_new(const mp_obj_type_t *type, size_t n_ar mp_int_t jpeg_quality = mp_arg_validate_int_range(args[ARG_jpeg_quality].u_int, 2, 55, MP_QSTR_jpeg_quality); mp_int_t framebuffer_count = mp_arg_validate_int_range(args[ARG_framebuffer_count].u_int, 1, 2, MP_QSTR_framebuffer_count); - espcamera_camera_obj_t *self = m_new_obj_with_finaliser(espcamera_camera_obj_t); - self->base.type = &espcamera_camera_type; + espcamera_camera_obj_t *self = mp_obj_malloc_with_finaliser(espcamera_camera_obj_t, &espcamera_camera_type); common_hal_espcamera_camera_construct( self, data_pins, diff --git a/ports/espressif/boards/adafruit_qualia_s3_rgb666/pins.c b/ports/espressif/boards/adafruit_qualia_s3_rgb666/pins.c index 524182126a164..96879ff037a43 100644 --- a/ports/espressif/boards/adafruit_qualia_s3_rgb666/pins.c +++ b/ports/espressif/boards/adafruit_qualia_s3_rgb666/pins.c @@ -7,14 +7,14 @@ #include "py/objtuple.h" #include "shared-bindings/board/__init__.h" -#define MP_DEFINE_BYTES_OBJ(obj_name, bin) mp_obj_str_t obj_name = {{&mp_type_bytes}, 0, sizeof(bin) - 1, (const byte *)bin} +#define MP_DEFINE_BYTES_OBJ_WITH_NULL(obj_name, bin) mp_obj_str_t obj_name = {{&mp_type_bytes}, 0, sizeof(bin) - 1, (const byte *)bin} static const char i2c_bus_init_sequence[] = { 2, 3, 0x78, // set GPIO direction 2, 2, 0, // disable all output inversion 0, // trailing NUL for python bytes() representation }; -static MP_DEFINE_BYTES_OBJ(i2c_init_byte_obj, i2c_bus_init_sequence); +static MP_DEFINE_BYTES_OBJ_WITH_NULL(i2c_init_byte_obj, i2c_bus_init_sequence); static const mp_rom_map_elem_t tft_io_expander_table[] = { { MP_ROM_QSTR(MP_QSTR_i2c_address), MP_ROM_INT(0x3f)}, diff --git a/ports/espressif/boards/esp32-wrover-dev-cam/pins.c b/ports/espressif/boards/esp32-wrover-dev-cam/pins.c index d6aee44a37390..6b47356a82153 100755 --- a/ports/espressif/boards/esp32-wrover-dev-cam/pins.c +++ b/ports/espressif/boards/esp32-wrover-dev-cam/pins.c @@ -3,7 +3,7 @@ CIRCUITPY_BOARD_BUS_SINGLETON(sscb_i2c, i2c, 2) // Camera sensor -STATIC const mp_rom_obj_tuple_t camera_data_tuple = { +static const mp_rom_obj_tuple_t camera_data_tuple = { // The order matters. They must be ordered from low to high (Y2, Y3 .. Y9). Do not include any of the control pins in here. {&mp_type_tuple}, 8, @@ -19,7 +19,7 @@ STATIC const mp_rom_obj_tuple_t camera_data_tuple = { } }; -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS // Red LED labelled IO2 on the front of the board diff --git a/ports/espressif/boards/espressif_esp32s3_lcd_ev/board.c b/ports/espressif/boards/espressif_esp32s3_lcd_ev/board.c index 5d13e5226f0c3..ce62bbfe207b3 100644 --- a/ports/espressif/boards/espressif_esp32s3_lcd_ev/board.c +++ b/ports/espressif/boards/espressif_esp32s3_lcd_ev/board.c @@ -15,7 +15,7 @@ #include "shared-module/displayio/__init__.h" #include "boards/espressif_esp32s3_lcd_ev/board.h" -#define MP_DEFINE_BYTES_OBJ(obj_name, bin) mp_obj_str_t obj_name = {{&mp_type_bytes}, 0, sizeof(bin) - 1, (const byte *)bin} +#define MP_DEFINE_BYTES_OBJ_WITH_NULL(obj_name, bin) mp_obj_str_t obj_name = {{&mp_type_bytes}, 0, sizeof(bin) - 1, (const byte *)bin} static const uint8_t display_init_sequence[] = { 0xf0, 5, 0x55, 0xaa, 0x52, 0x08, 0x00, @@ -66,14 +66,14 @@ static const uint8_t display_init_sequence[] = { 0x29, 0x0, 0, // trailing NUL for Python bytes() representation }; -MP_DEFINE_BYTES_OBJ(display_init_byte_obj, display_init_sequence); +MP_DEFINE_BYTES_OBJ_WITH_NULL(display_init_byte_obj, display_init_sequence); static const char i2c_bus_init_sequence[] = { 2, 3, 0xf1, // set GPIO direction 2, 2, 0, // disable all output inversion 0, // trailing NUL for Python bytes() representation }; -MP_DEFINE_BYTES_OBJ(i2c_init_byte_obj, i2c_bus_init_sequence); +MP_DEFINE_BYTES_OBJ_WITH_NULL(i2c_init_byte_obj, i2c_bus_init_sequence); static const mcu_pin_obj_t *red_pins[] = { &pin_GPIO1, &pin_GPIO2, &pin_GPIO42, &pin_GPIO41, &pin_GPIO40 diff --git a/ports/espressif/boards/espressif_esp8684_devkitc_02_n4/pins.c b/ports/espressif/boards/espressif_esp8684_devkitc_02_n4/pins.c index 005342e42561b..e7bf8a7764b8c 100644 --- a/ports/espressif/boards/espressif_esp8684_devkitc_02_n4/pins.c +++ b/ports/espressif/boards/espressif_esp8684_devkitc_02_n4/pins.c @@ -1,6 +1,6 @@ #include "shared-bindings/board/__init__.h" -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS { MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) }, diff --git a/ports/espressif/boards/nodemcu_esp32c2/pins.c b/ports/espressif/boards/nodemcu_esp32c2/pins.c index 04cd1b1929be5..046a3d2707b38 100644 --- a/ports/espressif/boards/nodemcu_esp32c2/pins.c +++ b/ports/espressif/boards/nodemcu_esp32c2/pins.c @@ -1,6 +1,6 @@ #include "shared-bindings/board/__init__.h" -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS // Module on top, from top to bottom, left to right diff --git a/ports/espressif/boards/seeed_xiao_esp32_s3_sense/pins.c b/ports/espressif/boards/seeed_xiao_esp32_s3_sense/pins.c index 6024f2d0ee69f..aa3a6f7b7f577 100644 --- a/ports/espressif/boards/seeed_xiao_esp32_s3_sense/pins.c +++ b/ports/espressif/boards/seeed_xiao_esp32_s3_sense/pins.c @@ -29,7 +29,7 @@ static const mp_rom_obj_tuple_t camera_data_tuple = { } }; -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO1) }, { MP_ROM_QSTR(MP_QSTR_A1), MP_ROM_PTR(&pin_GPIO2) }, diff --git a/ports/espressif/boards/seeed_xiao_esp32c6/pins.c b/ports/espressif/boards/seeed_xiao_esp32c6/pins.c index 0cb7f64e4163a..b7aeb90d2b1d6 100644 --- a/ports/espressif/boards/seeed_xiao_esp32c6/pins.c +++ b/ports/espressif/boards/seeed_xiao_esp32c6/pins.c @@ -1,6 +1,6 @@ #include "shared-bindings/board/__init__.h" -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS { MP_ROM_QSTR(MP_QSTR_D0), MP_ROM_PTR(&pin_GPIO0) }, diff --git a/ports/espressif/boards/ttgo_t8_v1_7/pins.c b/ports/espressif/boards/ttgo_t8_v1_7/pins.c index 97175b2a4e5bc..9bb3d0a617a32 100644 --- a/ports/espressif/boards/ttgo_t8_v1_7/pins.c +++ b/ports/espressif/boards/ttgo_t8_v1_7/pins.c @@ -1,6 +1,6 @@ #include "shared-bindings/board/__init__.h" -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS // External pins are in silkscreen order, from top to bottom, left side, then right side diff --git a/ports/espressif/boards/waveshare_esp32_s3_tiny/pins.c b/ports/espressif/boards/waveshare_esp32_s3_tiny/pins.c index 62d132af683fe..917ef0506abf9 100644 --- a/ports/espressif/boards/waveshare_esp32_s3_tiny/pins.c +++ b/ports/espressif/boards/waveshare_esp32_s3_tiny/pins.c @@ -6,7 +6,7 @@ #include "shared-bindings/board/__init__.h" -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS { MP_ROM_QSTR(MP_QSTR_IO0), MP_ROM_PTR(&pin_GPIO0) }, diff --git a/ports/espressif/common-hal/socketpool/Socket.c b/ports/espressif/common-hal/socketpool/Socket.c index 9fc04728a4d4c..0a36eff95b454 100644 --- a/ports/espressif/common-hal/socketpool/Socket.c +++ b/ports/espressif/common-hal/socketpool/Socket.c @@ -260,8 +260,7 @@ socketpool_socket_obj_t *common_hal_socketpool_socket(socketpool_socketpool_obj_ mp_raise_NotImplementedError(MP_ERROR_TEXT("Unsupported socket type")); } - socketpool_socket_obj_t *sock = m_new_obj_with_finaliser(socketpool_socket_obj_t); - sock->base.type = &socketpool_socket_type; + socketpool_socket_obj_t *sock = mp_obj_malloc_with_finaliser(socketpool_socket_obj_t, &socketpool_socket_type); if (!_socketpool_socket(self, family, type, proto, sock)) { mp_raise_RuntimeError(MP_ERROR_TEXT("Out of sockets")); @@ -326,7 +325,9 @@ int socketpool_socket_accept(socketpool_socket_obj_t *self, mp_obj_t *peer_out, } socketpool_socket_obj_t *common_hal_socketpool_socket_accept(socketpool_socket_obj_t *self, mp_obj_t *peer_out) { - socketpool_socket_obj_t *sock = m_new_obj_with_finaliser(socketpool_socket_obj_t); + // Set the socket type only after the socketpool_socket_accept succeeds, so that the + // finaliser is not called on a bad socket. + socketpool_socket_obj_t *sock = mp_obj_malloc_with_finaliser(socketpool_socket_obj_t, NULL); int newsoc = socketpool_socket_accept(self, peer_out, NULL); if (newsoc > 0) { diff --git a/ports/mimxrt10xx/supervisor/flexspi_nor_flash_ops.c b/ports/mimxrt10xx/supervisor/flexspi_nor_flash_ops.c index 3ccd67096a7df..1c7559292706f 100644 --- a/ports/mimxrt10xx/supervisor/flexspi_nor_flash_ops.c +++ b/ports/mimxrt10xx/supervisor/flexspi_nor_flash_ops.c @@ -13,9 +13,9 @@ #include "supervisor/internal_flash.h" #include "supervisor/linker.h" -STATIC uint8_t _busy_bit_shift; -STATIC bool _busy_bit_polarity; -STATIC bool _inited = false; +static uint8_t _busy_bit_shift; +static bool _busy_bit_polarity; +static bool _inited = false; void flexspi_nor_init(void) { // Copy busy bit info into RAM so we can use if when flash isn't available. @@ -24,7 +24,7 @@ void flexspi_nor_init(void) { _inited = true; } -STATIC status_t PLACE_IN_ITCM(flexspi_nor_write_enable)(FLEXSPI_Type * base, uint32_t baseAddr) +static status_t PLACE_IN_ITCM(flexspi_nor_write_enable)(FLEXSPI_Type * base, uint32_t baseAddr) { flexspi_transfer_t flashXfer; status_t status; @@ -41,7 +41,7 @@ STATIC status_t PLACE_IN_ITCM(flexspi_nor_write_enable)(FLEXSPI_Type * base, uin return status; } -STATIC status_t PLACE_IN_ITCM(flexspi_nor_wait_bus_busy)(FLEXSPI_Type * base) +static status_t PLACE_IN_ITCM(flexspi_nor_wait_bus_busy)(FLEXSPI_Type * base) { /* Wait status ready. */ bool isBusy; diff --git a/ports/nordic/boards/bluemicro833/mpconfigboard.mk b/ports/nordic/boards/bluemicro833/mpconfigboard.mk index de12d6ee1fee3..3fcb7cdbb07ac 100644 --- a/ports/nordic/boards/bluemicro833/mpconfigboard.mk +++ b/ports/nordic/boards/bluemicro833/mpconfigboard.mk @@ -7,10 +7,12 @@ MCU_CHIP = nrf52833 INTERNAL_FLASH_FILESYSTEM = 1 +CIRCUITPY_AESIO = 0 CIRCUITPY_AUDIOBUSIO = 0 CIRCUITPY_AUDIOPWMIO = 0 CIRCUITPY_AUDIOMIXER = 0 CIRCUITPY_KEYPAD = 1 +CIRCUITPY_KEYPAD_DEMUX = 0 CIRCUITPY_NVM = 0 CIRCUITPY_ONEWIREIO = 0 CIRCUITPY_PIXELBUF = 1 diff --git a/ports/raspberrypi/boards/adafruit_feather_rp2350/pins.c b/ports/raspberrypi/boards/adafruit_feather_rp2350/pins.c index 8e74da883dc56..607698cc74673 100644 --- a/ports/raspberrypi/boards/adafruit_feather_rp2350/pins.c +++ b/ports/raspberrypi/boards/adafruit_feather_rp2350/pins.c @@ -6,7 +6,7 @@ #include "shared-bindings/board/__init__.h" -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS { MP_ROM_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, diff --git a/ports/raspberrypi/boards/adafruit_metro_rp2350/pins.c b/ports/raspberrypi/boards/adafruit_metro_rp2350/pins.c index d89f2877fddd7..80f046f9bd941 100644 --- a/ports/raspberrypi/boards/adafruit_metro_rp2350/pins.c +++ b/ports/raspberrypi/boards/adafruit_metro_rp2350/pins.c @@ -6,7 +6,7 @@ #include "shared-bindings/board/__init__.h" -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS { MP_OBJ_NEW_QSTR(MP_QSTR_A0), MP_ROM_PTR(&pin_GPIO26) }, diff --git a/ports/raspberrypi/boards/archi/pins.c b/ports/raspberrypi/boards/archi/pins.c index 60d391a8fe622..43805f6e4daa1 100644 --- a/ports/raspberrypi/boards/archi/pins.c +++ b/ports/raspberrypi/boards/archi/pins.c @@ -6,7 +6,7 @@ #include "shared-bindings/board/__init__.h" -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, diff --git a/ports/raspberrypi/boards/cytron_iriv_io_controller/pins.c b/ports/raspberrypi/boards/cytron_iriv_io_controller/pins.c index 050ce66ff30ff..5e7f2fad65ff7 100644 --- a/ports/raspberrypi/boards/cytron_iriv_io_controller/pins.c +++ b/ports/raspberrypi/boards/cytron_iriv_io_controller/pins.c @@ -6,7 +6,7 @@ #include "shared-bindings/board/__init__.h" -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS { MP_OBJ_NEW_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, diff --git a/ports/raspberrypi/boards/cytron_motion_2350_pro/pins.c b/ports/raspberrypi/boards/cytron_motion_2350_pro/pins.c index 27f26a1519ee4..b1e63858563d9 100644 --- a/ports/raspberrypi/boards/cytron_motion_2350_pro/pins.c +++ b/ports/raspberrypi/boards/cytron_motion_2350_pro/pins.c @@ -6,7 +6,7 @@ #include "shared-bindings/board/__init__.h" -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS { MP_OBJ_NEW_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, diff --git a/ports/raspberrypi/boards/pimoroni_pga2350/pins.c b/ports/raspberrypi/boards/pimoroni_pga2350/pins.c index 1a5d87a0c1b9e..47756d81b41c8 100644 --- a/ports/raspberrypi/boards/pimoroni_pga2350/pins.c +++ b/ports/raspberrypi/boards/pimoroni_pga2350/pins.c @@ -6,7 +6,7 @@ #include "shared-bindings/board/__init__.h" -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, diff --git a/ports/raspberrypi/boards/pimoroni_pico_plus2/pins.c b/ports/raspberrypi/boards/pimoroni_pico_plus2/pins.c index fe4e4cdd92e54..6c8345afe7e78 100644 --- a/ports/raspberrypi/boards/pimoroni_pico_plus2/pins.c +++ b/ports/raspberrypi/boards/pimoroni_pico_plus2/pins.c @@ -6,7 +6,7 @@ #include "shared-bindings/board/__init__.h" -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, diff --git a/ports/raspberrypi/boards/pimoroni_plasma2350/pins.c b/ports/raspberrypi/boards/pimoroni_plasma2350/pins.c index 1c1ab4def7779..5aca457df80cf 100644 --- a/ports/raspberrypi/boards/pimoroni_plasma2350/pins.c +++ b/ports/raspberrypi/boards/pimoroni_plasma2350/pins.c @@ -6,7 +6,7 @@ #include "shared-bindings/board/__init__.h" -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, diff --git a/ports/raspberrypi/boards/pimoroni_tiny2350/pins.c b/ports/raspberrypi/boards/pimoroni_tiny2350/pins.c index ae026f69fcabc..63f83ca9373df 100644 --- a/ports/raspberrypi/boards/pimoroni_tiny2350/pins.c +++ b/ports/raspberrypi/boards/pimoroni_tiny2350/pins.c @@ -6,7 +6,7 @@ #include "shared-bindings/board/__init__.h" -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, diff --git a/ports/raspberrypi/boards/raspberry_pi_pico2/pins.c b/ports/raspberrypi/boards/raspberry_pi_pico2/pins.c index c618a8b1b0605..d3626838f8266 100644 --- a/ports/raspberrypi/boards/raspberry_pi_pico2/pins.c +++ b/ports/raspberrypi/boards/raspberry_pi_pico2/pins.c @@ -6,7 +6,7 @@ #include "shared-bindings/board/__init__.h" -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, diff --git a/ports/raspberrypi/boards/solderparty_rp2350_stamp/pins.c b/ports/raspberrypi/boards/solderparty_rp2350_stamp/pins.c index 8bea812108899..cf17933536094 100644 --- a/ports/raspberrypi/boards/solderparty_rp2350_stamp/pins.c +++ b/ports/raspberrypi/boards/solderparty_rp2350_stamp/pins.c @@ -6,7 +6,7 @@ #include "shared-bindings/board/__init__.h" -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, diff --git a/ports/raspberrypi/boards/solderparty_rp2350_stamp_xl/pins.c b/ports/raspberrypi/boards/solderparty_rp2350_stamp_xl/pins.c index 6e81890751d28..81811367c2f41 100644 --- a/ports/raspberrypi/boards/solderparty_rp2350_stamp_xl/pins.c +++ b/ports/raspberrypi/boards/solderparty_rp2350_stamp_xl/pins.c @@ -6,7 +6,7 @@ #include "shared-bindings/board/__init__.h" -STATIC const mp_rom_map_elem_t board_module_globals_table[] = { +static const mp_rom_map_elem_t board_module_globals_table[] = { CIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS { MP_ROM_QSTR(MP_QSTR_GP0), MP_ROM_PTR(&pin_GPIO0) }, diff --git a/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2350.c b/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2350.c index 3e3804fbc5148..f1f8fc8c787f4 100644 --- a/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2350.c +++ b/ports/raspberrypi/common-hal/picodvi/Framebuffer_RP2350.c @@ -430,7 +430,7 @@ void common_hal_picodvi_framebuffer_construct(picodvi_framebuffer_obj_t *self, dma_irq_handler(); } -STATIC void _turn_off_dma(uint8_t channel) { +static void _turn_off_dma(uint8_t channel) { dma_channel_config c = dma_channel_get_default_config(channel); channel_config_set_enable(&c, false); dma_channel_set_config(channel, &c, false /* trigger */); diff --git a/ports/raspberrypi/common-hal/socketpool/Socket.c b/ports/raspberrypi/common-hal/socketpool/Socket.c index 84d8bbd5149e0..fb1fdfb5f65bf 100644 --- a/ports/raspberrypi/common-hal/socketpool/Socket.c +++ b/ports/raspberrypi/common-hal/socketpool/Socket.c @@ -746,8 +746,7 @@ socketpool_socket_obj_t *common_hal_socketpool_socket(socketpool_socketpool_obj_ mp_raise_NotImplementedError(MP_ERROR_TEXT("Only IPv4 sockets supported")); } - socketpool_socket_obj_t *socket = m_new_obj_with_finaliser(socketpool_socket_obj_t); - socket->base.type = &socketpool_socket_type; + socketpool_socket_obj_t *socket = mp_obj_malloc_with_finaliser(socketpool_socket_obj_t, &socketpool_socket_type); if (!socketpool_socket(self, family, type, proto, socket)) { mp_raise_RuntimeError(MP_ERROR_TEXT("Out of sockets")); @@ -849,7 +848,8 @@ socketpool_socket_obj_t *common_hal_socketpool_socket_accept(socketpool_socket_o mp_obj_t *peer_out) { // Create new socket object, do it here because we must not raise an out-of-memory // exception when the LWIP concurrency lock is held - socketpool_socket_obj_t *accepted = m_new_obj_with_finaliser(socketpool_socket_obj_t); + // Don't set the type field: socketpool_socket_reset() will do that when checking for already reset. + socketpool_socket_obj_t *accepted = mp_obj_malloc_with_finaliser(socketpool_socket_obj_t, NULL); socketpool_socket_reset(accepted); int ret = socketpool_socket_accept(socket, peer_out, accepted); diff --git a/ports/silabs/boards/devkit_xg24_brd2601b/sensor.c b/ports/silabs/boards/devkit_xg24_brd2601b/sensor.c index 2adfd67c4bf78..aaf698a6cb27f 100644 --- a/ports/silabs/boards/devkit_xg24_brd2601b/sensor.c +++ b/ports/silabs/boards/devkit_xg24_brd2601b/sensor.c @@ -36,7 +36,7 @@ #include "sl_sensor_hall.h" #include "sl_sensor_pressure.h" -STATIC mp_obj_t sensor_init(mp_obj_t i2c_in) { +static mp_obj_t sensor_init(mp_obj_t i2c_in) { // busio_i2c_obj_t *i2c = MP_OBJ_TO_PTR(i2c_in); sl_status_t sc; @@ -75,7 +75,7 @@ STATIC mp_obj_t sensor_init(mp_obj_t i2c_in) { return mp_const_true; } -STATIC mp_obj_t sensor_deinit() { +static mp_obj_t sensor_deinit() { sl_sensor_hall_deinit(); sl_sensor_lux_deinit(); @@ -87,7 +87,7 @@ STATIC mp_obj_t sensor_deinit() { return mp_const_true; } -STATIC mp_obj_t sensor_get_temperature(void) { +static mp_obj_t sensor_get_temperature(void) { sl_status_t sc; uint32_t rh; int32_t t; @@ -100,7 +100,7 @@ STATIC mp_obj_t sensor_get_temperature(void) { return mp_obj_new_float((float)t / 1000.0f); } -STATIC mp_obj_t sensor_get_humidity(void) { +static mp_obj_t sensor_get_humidity(void) { sl_status_t sc; uint32_t rh; int32_t t; @@ -112,7 +112,7 @@ STATIC mp_obj_t sensor_get_humidity(void) { return mp_obj_new_float((float)rh / 1000.0f); } -STATIC mp_obj_t sensor_get_lux(void) { +static mp_obj_t sensor_get_lux(void) { sl_status_t sc; float lux; sc = sl_sensor_lux_get(&lux); @@ -123,7 +123,7 @@ STATIC mp_obj_t sensor_get_lux(void) { return mp_obj_new_float(lux); } -STATIC mp_obj_t sensor_get_hall(void) { +static mp_obj_t sensor_get_hall(void) { sl_status_t sc; float field_strength; bool alert; @@ -136,7 +136,7 @@ STATIC mp_obj_t sensor_get_hall(void) { return mp_obj_new_float(field_strength); } -STATIC mp_obj_t sensor_get_pressure(void) { +static mp_obj_t sensor_get_pressure(void) { sl_status_t sc; float pressure; sc = sl_sensor_pressure_get(&pressure); @@ -147,7 +147,7 @@ STATIC mp_obj_t sensor_get_pressure(void) { return mp_obj_new_float(pressure); } -STATIC mp_obj_t sensor_imu_get(void) { +static mp_obj_t sensor_imu_get(void) { sl_status_t sc; int16_t ovec[3]; int16_t avec[3]; @@ -172,7 +172,7 @@ STATIC mp_obj_t sensor_imu_get(void) { return mp_obj_new_tuple(2, ret); } -STATIC mp_obj_t sensor_imu_calibrate(void) { +static mp_obj_t sensor_imu_calibrate(void) { sl_status_t sc; sc = sl_sensor_imu_calibrate(); if (sc != SL_STATUS_OK) { @@ -181,18 +181,18 @@ STATIC mp_obj_t sensor_imu_calibrate(void) { return mp_const_true; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(sensor_init_obj, sensor_init); -STATIC MP_DEFINE_CONST_FUN_OBJ_0(sensor_deinit_obj, sensor_deinit); -STATIC MP_DEFINE_CONST_FUN_OBJ_0(sensor_get_temperature_obj, sensor_get_temperature); -STATIC MP_DEFINE_CONST_FUN_OBJ_0(sensor_get_humidity_obj, sensor_get_humidity); -STATIC MP_DEFINE_CONST_FUN_OBJ_0(sensor_get_lux_obj, sensor_get_lux); -STATIC MP_DEFINE_CONST_FUN_OBJ_0(sensor_get_hall_obj, sensor_get_hall); -STATIC MP_DEFINE_CONST_FUN_OBJ_0(sensor_get_pressure_obj, sensor_get_pressure); -STATIC MP_DEFINE_CONST_FUN_OBJ_0(sensor_imu_get_obj, sensor_imu_get); -STATIC MP_DEFINE_CONST_FUN_OBJ_0(sensor_imu_calibrate_obj, sensor_imu_calibrate); +static MP_DEFINE_CONST_FUN_OBJ_1(sensor_init_obj, sensor_init); +static MP_DEFINE_CONST_FUN_OBJ_0(sensor_deinit_obj, sensor_deinit); +static MP_DEFINE_CONST_FUN_OBJ_0(sensor_get_temperature_obj, sensor_get_temperature); +static MP_DEFINE_CONST_FUN_OBJ_0(sensor_get_humidity_obj, sensor_get_humidity); +static MP_DEFINE_CONST_FUN_OBJ_0(sensor_get_lux_obj, sensor_get_lux); +static MP_DEFINE_CONST_FUN_OBJ_0(sensor_get_hall_obj, sensor_get_hall); +static MP_DEFINE_CONST_FUN_OBJ_0(sensor_get_pressure_obj, sensor_get_pressure); +static MP_DEFINE_CONST_FUN_OBJ_0(sensor_imu_get_obj, sensor_imu_get); +static MP_DEFINE_CONST_FUN_OBJ_0(sensor_imu_calibrate_obj, sensor_imu_calibrate); -STATIC const mp_rom_map_elem_t sensor_globals_table[] = { +static const mp_rom_map_elem_t sensor_globals_table[] = { { MP_OBJ_NEW_QSTR(MP_QSTR___name__), MP_OBJ_NEW_QSTR(MP_QSTR_sensor) }, { MP_ROM_QSTR(MP_QSTR_init), MP_ROM_PTR(&sensor_init_obj) }, { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&sensor_deinit_obj) }, @@ -204,7 +204,7 @@ STATIC const mp_rom_map_elem_t sensor_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_imu), MP_ROM_PTR(&sensor_imu_get_obj) }, { MP_ROM_QSTR(MP_QSTR_imu_calibrate), MP_ROM_PTR(&sensor_imu_calibrate_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(sensor_module_globals, sensor_globals_table); +static MP_DEFINE_CONST_DICT(sensor_module_globals, sensor_globals_table); const mp_obj_module_t sensor_module = { .base = { &mp_type_module }, diff --git a/ports/silabs/common-hal/_bleio/Adapter.c b/ports/silabs/common-hal/_bleio/Adapter.c index d469172ae981f..14b1dac8207a9 100644 --- a/ports/silabs/common-hal/_bleio/Adapter.c +++ b/ports/silabs/common-hal/_bleio/Adapter.c @@ -376,7 +376,7 @@ uint32_t _common_hal_bleio_adapter_start_advertising( } // Check size of packet advertising to send -STATIC void check_data_fit(size_t data_len, bool connectable) { +static void check_data_fit(size_t data_len, bool connectable) { if (data_len > BLE_EXT_ADV_MAX_SIZE || (connectable && data_len > BLE_EXT_ADV_MAX_SIZE)) { mp_raise_ValueError( @@ -451,7 +451,7 @@ bool common_hal_bleio_adapter_get_advertising(bleio_adapter_obj_t *self) { } // Convert mac address of remote device to connect -STATIC void _convert_address(const bleio_address_obj_t *address, +static void _convert_address(const bleio_address_obj_t *address, bd_addr *sd_address, uint8_t *addr_type) { mp_buffer_info_t address_buf_info; *addr_type = address->type; diff --git a/ports/silabs/common-hal/_bleio/Characteristic.c b/ports/silabs/common-hal/_bleio/Characteristic.c index f2c137c1a0ded..37fb792cd4d75 100644 --- a/ports/silabs/common-hal/_bleio/Characteristic.c +++ b/ports/silabs/common-hal/_bleio/Characteristic.c @@ -76,7 +76,7 @@ bool set_characteristic_value_on_ble_evt(uint8_t conn_handle, } // Get the characteristic data object -STATIC bool get_characteristic_value(uint8_t conn_handle, +static bool get_characteristic_value(uint8_t conn_handle, uint16_t char_handle, uint8_t *data, size_t *data_len) { diff --git a/ports/silabs/common-hal/_bleio/PacketBuffer.c b/ports/silabs/common-hal/_bleio/PacketBuffer.c index 6cb3e58121cbb..1e5159fc6a205 100644 --- a/ports/silabs/common-hal/_bleio/PacketBuffer.c +++ b/ports/silabs/common-hal/_bleio/PacketBuffer.c @@ -41,7 +41,7 @@ bleio_packet_buffer_obj_list_t bleio_packet_buffer_list; // Write data to ringbuf of packet buffer -STATIC void write_to_ringbuf(bleio_packet_buffer_obj_t *self, +static void write_to_ringbuf(bleio_packet_buffer_obj_t *self, uint8_t *data, uint16_t len) { @@ -70,7 +70,7 @@ STATIC void write_to_ringbuf(bleio_packet_buffer_obj_t *self, } // Write characteristic or attribute value -STATIC int queue_next_write(bleio_packet_buffer_obj_t *self) { +static int queue_next_write(bleio_packet_buffer_obj_t *self) { self->packet_queued = false; uint32_t sc = SL_STATUS_OK; diff --git a/ports/silabs/common-hal/_bleio/__init__.c b/ports/silabs/common-hal/_bleio/__init__.c index 6191a88904a91..2905dc41e09cc 100644 --- a/ports/silabs/common-hal/_bleio/__init__.c +++ b/ports/silabs/common-hal/_bleio/__init__.c @@ -38,7 +38,7 @@ #include "supervisor/shared/bluetooth/bluetooth.h" #include "common-hal/_bleio/__init__.h" -STATIC conn_state_t conn_state; +static conn_state_t conn_state; osMutexId_t bluetooth_connection_mutex_id; bleio_adapter_obj_t common_hal_bleio_adapter_obj; uint8_t ble_bonding_handle = 0xFF; @@ -112,8 +112,8 @@ void common_hal_bleio_check_connected(uint16_t conn_handle) { void sl_bt_on_event(sl_bt_msg_t *evt) { bd_addr address; uint8_t address_type = 0; - STATIC uint8_t serv_idx = 0; - STATIC uint8_t device_name[16]; + static uint8_t serv_idx = 0; + static uint8_t device_name[16]; bleio_connection_internal_t *connection; bleio_service_obj_t *service; diff --git a/ports/silabs/common-hal/analogio/AnalogIn.c b/ports/silabs/common-hal/analogio/AnalogIn.c index dc2846ff41a33..57749b2551790 100644 --- a/ports/silabs/common-hal/analogio/AnalogIn.c +++ b/ports/silabs/common-hal/analogio/AnalogIn.c @@ -38,10 +38,10 @@ // Number of scan channels #define NUM_INPUTS 8 -STATIC uint8_t num_current_input = 0; -STATIC volatile uint16_t scan_result[NUM_INPUTS]; -STATIC volatile uint8_t scan_flag = 0; -STATIC IADC_ScanTable_t init_scan_table = IADC_SCANTABLE_DEFAULT; // Scan Table +static uint8_t num_current_input = 0; +static volatile uint16_t scan_result[NUM_INPUTS]; +static volatile uint8_t scan_flag = 0; +static IADC_ScanTable_t init_scan_table = IADC_SCANTABLE_DEFAULT; // Scan Table // Construct analogin pin. This function is called when init AnalogIn void common_hal_analogio_analogin_construct(analogio_analogin_obj_t *self, diff --git a/ports/silabs/common-hal/busio/I2C.c b/ports/silabs/common-hal/busio/I2C.c index 30c28f1c5ba6d..7934416b12743 100644 --- a/ports/silabs/common-hal/busio/I2C.c +++ b/ports/silabs/common-hal/busio/I2C.c @@ -30,9 +30,9 @@ #include "shared-bindings/microcontroller/__init__.h" #include "shared-bindings/microcontroller/Pin.h" -STATIC I2CSPM_Init_TypeDef i2cspm_init; -STATIC bool in_used = false; -STATIC bool never_reset = false; +static I2CSPM_Init_TypeDef i2cspm_init; +static bool in_used = false; +static bool never_reset = false; // Reser I2C peripheral void i2c_reset(void) { diff --git a/ports/silabs/common-hal/busio/SPI.c b/ports/silabs/common-hal/busio/SPI.c index c0e47af1fb2c1..74cfc69bfb2a0 100644 --- a/ports/silabs/common-hal/busio/SPI.c +++ b/ports/silabs/common-hal/busio/SPI.c @@ -34,10 +34,10 @@ // Note that any bugs introduced in this file can cause crashes // at startupfor chips using external SPI flash. -STATIC SPIDRV_HandleData_t spidrv_eusart_handle; -STATIC SPIDRV_Init_t spidrv_eusart_init = SPIDRV_MASTER_EUSART1; -STATIC bool in_used = false; -STATIC bool never_reset = false; +static SPIDRV_HandleData_t spidrv_eusart_handle; +static SPIDRV_Init_t spidrv_eusart_init = SPIDRV_MASTER_EUSART1; +static bool in_used = false; +static bool never_reset = false; // Reset SPI when reload void spi_reset(void) { diff --git a/ports/silabs/common-hal/busio/UART.c b/ports/silabs/common-hal/busio/UART.c index 8a598cfb9030a..cfc87b6b6f828 100644 --- a/ports/silabs/common-hal/busio/UART.c +++ b/ports/silabs/common-hal/busio/UART.c @@ -42,10 +42,10 @@ DEFINE_BUF_QUEUE(UARTDRV_USART_BUFFER_SIZE, uartdrv_usart_rx_buffer); DEFINE_BUF_QUEUE(UARTDRV_USART_BUFFER_SIZE, uartdrv_usart_tx_buffer); -STATIC UARTDRV_HandleData_t uartdrv_usart_handle; -STATIC UARTDRV_InitUart_t uartdrv_usart_init; -STATIC bool in_used = false; -STATIC bool never_reset = false; +static UARTDRV_HandleData_t uartdrv_usart_handle; +static UARTDRV_InitUart_t uartdrv_usart_init; +static bool in_used = false; +static bool never_reset = false; busio_uart_obj_t *context; volatile Ecode_t errflag; // Used to restart read halts diff --git a/ports/silabs/common-hal/microcontroller/Pin.c b/ports/silabs/common-hal/microcontroller/Pin.c index d22485c40d642..249bc5ac482f2 100644 --- a/ports/silabs/common-hal/microcontroller/Pin.c +++ b/ports/silabs/common-hal/microcontroller/Pin.c @@ -32,8 +32,8 @@ #define GPIO_PORT_COUNT (MP_ARRAY_SIZE(ports)) GPIO_Port_TypeDef ports[] = {gpioPortA, gpioPortB, gpioPortC, gpioPortD}; -STATIC uint16_t claimed_pins[GPIO_PORT_COUNT]; -STATIC uint16_t __ALIGNED(4) never_reset_pins[GPIO_PORT_COUNT]; +static uint16_t claimed_pins[GPIO_PORT_COUNT]; +static uint16_t __ALIGNED(4) never_reset_pins[GPIO_PORT_COUNT]; // Reset all pin except pin in never_reset_pins list void reset_all_pins(void) { diff --git a/ports/silabs/common-hal/nvm/ByteArray.c b/ports/silabs/common-hal/nvm/ByteArray.c index e8b56f7c725da..5a5fa0e36db4c 100644 --- a/ports/silabs/common-hal/nvm/ByteArray.c +++ b/ports/silabs/common-hal/nvm/ByteArray.c @@ -33,7 +33,7 @@ #include "nvm3_default_config.h" uint8_t nvm_array[NVM_BYTEARRAY_BUFFER_SIZE]; -STATIC bool isInitialized = false; +static bool isInitialized = false; #define NVM_KEY 98 // Get length of nvm bytearray diff --git a/ports/silabs/common-hal/os/__init__.c b/ports/silabs/common-hal/os/__init__.c index d4841556defdd..42036536e4ff6 100644 --- a/ports/silabs/common-hal/os/__init__.c +++ b/ports/silabs/common-hal/os/__init__.c @@ -35,18 +35,18 @@ #include "peripherals/periph.h" #define RNG_TIMEOUT 5 -STATIC const qstr os_uname_info_fields[] = { +static const qstr os_uname_info_fields[] = { MP_QSTR_sysname, MP_QSTR_nodename, MP_QSTR_release, MP_QSTR_version, MP_QSTR_machine }; -STATIC const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, EFR32_SERIES_LOWER); -STATIC const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, EFR32_SERIES_LOWER); +static const MP_DEFINE_STR_OBJ(os_uname_info_sysname_obj, EFR32_SERIES_LOWER); +static const MP_DEFINE_STR_OBJ(os_uname_info_nodename_obj, EFR32_SERIES_LOWER); -STATIC const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); -STATIC const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); -STATIC const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); +static const MP_DEFINE_STR_OBJ(os_uname_info_release_obj, MICROPY_VERSION_STRING); +static const MP_DEFINE_STR_OBJ(os_uname_info_version_obj, MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE); +static const MP_DEFINE_STR_OBJ(os_uname_info_machine_obj, MICROPY_HW_BOARD_NAME " with " MICROPY_HW_MCU_NAME); -STATIC MP_DEFINE_ATTRTUPLE( +static MP_DEFINE_ATTRTUPLE( os_uname_info_obj, os_uname_info_fields, 5, diff --git a/ports/silabs/qstrdefsport.h b/ports/silabs/qstrdefsport.h index 3ba897069bf73..00d3e2ae3c555 100644 --- a/ports/silabs/qstrdefsport.h +++ b/ports/silabs/qstrdefsport.h @@ -1 +1,2 @@ // qstrs specific to this port +// *FORMAT-OFF* diff --git a/ports/silabs/supervisor/internal_flash.c b/ports/silabs/supervisor/internal_flash.c index bb2b16726d30d..5cb60d220f510 100644 --- a/ports/silabs/supervisor/internal_flash.c +++ b/ports/silabs/supervisor/internal_flash.c @@ -51,7 +51,7 @@ uint8_t _flash_cache[FLASH_PAGE_SIZE] __attribute__((aligned(4))); uint32_t _flash_page_addr = NO_CACHE; -STATIC inline uint32_t lba2addr(uint32_t block) { +static inline uint32_t lba2addr(uint32_t block) { return CIRCUITPY_INTERNAL_FLASH_FILESYSTEM_START_ADDR + block * FILESYSTEM_BLOCK_SIZE; } diff --git a/ports/silabs/supervisor/port.c b/ports/silabs/supervisor/port.c index 19a35da5a9fc2..d94093b3e1da3 100644 --- a/ports/silabs/supervisor/port.c +++ b/ports/silabs/supervisor/port.c @@ -88,20 +88,20 @@ uint32_t _ebss; uint32_t *heap; uint32_t heap_size; -STATIC sl_sleeptimer_timer_handle_t _tick_timer; -STATIC sl_sleeptimer_timer_handle_t _sleep_timer; +static sl_sleeptimer_timer_handle_t _tick_timer; +static sl_sleeptimer_timer_handle_t _sleep_timer; // CircuitPython stack thread -STATIC void circuitpython_thread(void *p_arg); -STATIC osThreadId_t tid_thread_circuitpython; +static void circuitpython_thread(void *p_arg); +static osThreadId_t tid_thread_circuitpython; __ALIGNED(8) -STATIC uint8_t thread_circuitpython_stk[(CIRCUITPY_DEFAULT_STACK_SIZE + +static uint8_t thread_circuitpython_stk[(CIRCUITPY_DEFAULT_STACK_SIZE + SL_CIRCUITPYTHON_TASK_STACK_EXTRA_SIZE) & 0xFFFFFFF8u]; __ALIGNED(4) -STATIC uint8_t thread_circuitpython_cb[osThreadCbSize]; +static uint8_t thread_circuitpython_cb[osThreadCbSize]; -STATIC const osThreadAttr_t thread_circuitpython_attr = { +static const osThreadAttr_t thread_circuitpython_attr = { .name = "CircuitPython stack", .stack_mem = thread_circuitpython_stk, .stack_size = sizeof(thread_circuitpython_stk), @@ -110,7 +110,7 @@ STATIC const osThreadAttr_t thread_circuitpython_attr = { .priority = (osPriority_t)SL_CIRCUITPYTHON_TASK_PRIORITY }; -STATIC bool isSchedulerStarted = false; +static bool isSchedulerStarted = false; safe_mode_t port_init(void) { #if defined(SL_CATALOG_KERNEL_PRESENT) @@ -223,7 +223,7 @@ uint64_t port_get_raw_ticks(uint8_t *subticks) { } // Periodic tick timer callback -STATIC void on_tick_timer_timeout(sl_sleeptimer_timer_handle_t *handle, +static void on_tick_timer_timeout(sl_sleeptimer_timer_handle_t *handle, void *data) { (void)&handle; (void)&data; @@ -255,7 +255,7 @@ void port_wake_main_task(void) { osThreadFlagsSet(tid_thread_circuitpython, 0x0001); } -STATIC void on_sleep_timer_timeout(sl_sleeptimer_timer_handle_t *handle, +static void on_sleep_timer_timeout(sl_sleeptimer_timer_handle_t *handle, void *data) { port_wake_main_task(); } diff --git a/ports/silabs/supervisor/serial.c b/ports/silabs/supervisor/serial.c index e19bde8965afd..25dc86c1da9b3 100644 --- a/ports/silabs/supervisor/serial.c +++ b/ports/silabs/supervisor/serial.c @@ -48,9 +48,9 @@ #define EUSART_VCOM_RX_PORT gpioPortA #define EUSART_VCOM_RX_PIN 6 -STATIC ringbuf_t con_uart_rx_ringbuf; -STATIC byte con_uart_rx_buf[CONSOLE_RCV_BUFFER_SIZE]; -STATIC volatile uint8_t received_data; +static ringbuf_t con_uart_rx_ringbuf; +static byte con_uart_rx_buf[CONSOLE_RCV_BUFFER_SIZE]; +static volatile uint8_t received_data; // USART0 RX interrupt handler , put characters to ring buffer one by one void EUSART0_RX_IRQHandler(void) { diff --git a/ports/silabs/tools/make_pins.py b/ports/silabs/tools/make_pins.py index bd4973d3e098c..da662094b3670 100644 --- a/ports/silabs/tools/make_pins.py +++ b/ports/silabs/tools/make_pins.py @@ -53,7 +53,7 @@ def make_mcu_dict_entry2(pin): def make_mcu_dict(pins): """Create the mcu dictionary""" - decl = "\n\nSTATIC const mp_rom_map_elem_t board_module_globals_table[] = {\n" + decl = "\n\nstatic const mp_rom_map_elem_t board_module_globals_table[] = {\n" decl += "\tCIRCUITPYTHON_BOARD_DICT_STANDARD_ITEMS\n" for pin in pins.values(): decl += "\t" + make_mcu_dict_entry(pin) + "\n" diff --git a/ports/stm/packages/LQFP100_f4.c b/ports/stm/packages/LQFP100_f4.c index f1c3cc36761bf..9a15d92a0a7e8 100644 --- a/ports/stm/packages/LQFP100_f4.c +++ b/ports/stm/packages/LQFP100_f4.c @@ -2,7 +2,7 @@ #include "common-hal/microcontroller/Pin.h" #include "py/obj.h" -STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { +static const mp_rom_map_elem_t mcu_pin_globals_table[] = { // Pins 1-25 { MP_ROM_QSTR(MP_QSTR_PE02), MP_ROM_PTR(&pin_PE02) }, { MP_ROM_QSTR(MP_QSTR_PE03), MP_ROM_PTR(&pin_PE03) }, diff --git a/ports/stm/packages/LQFP100_x7.c b/ports/stm/packages/LQFP100_x7.c index 77a887b0d8db1..9a2a1203da5fb 100644 --- a/ports/stm/packages/LQFP100_x7.c +++ b/ports/stm/packages/LQFP100_x7.c @@ -2,7 +2,7 @@ #include "common-hal/microcontroller/Pin.h" #include "py/obj.h" -STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { +static const mp_rom_map_elem_t mcu_pin_globals_table[] = { // Pins 1-25 { MP_ROM_QSTR(MP_QSTR_PE02), MP_ROM_PTR(&pin_PE02) }, { MP_ROM_QSTR(MP_QSTR_PE03), MP_ROM_PTR(&pin_PE03) }, diff --git a/ports/stm/packages/LQFP144.c b/ports/stm/packages/LQFP144.c index a08d160863684..341715b9682f4 100644 --- a/ports/stm/packages/LQFP144.c +++ b/ports/stm/packages/LQFP144.c @@ -2,7 +2,7 @@ #include "common-hal/microcontroller/Pin.h" #include "py/obj.h" -STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { +static const mp_rom_map_elem_t mcu_pin_globals_table[] = { // Pins 1-36 { MP_ROM_QSTR(MP_QSTR_PE02), MP_ROM_PTR(&pin_PE02) }, { MP_ROM_QSTR(MP_QSTR_PE03), MP_ROM_PTR(&pin_PE03) }, diff --git a/ports/stm/packages/LQFP64.c b/ports/stm/packages/LQFP64.c index 71e8be978e6c3..4fec4ab157f9e 100644 --- a/ports/stm/packages/LQFP64.c +++ b/ports/stm/packages/LQFP64.c @@ -2,7 +2,7 @@ #include "common-hal/microcontroller/Pin.h" #include "py/obj.h" -STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { +static const mp_rom_map_elem_t mcu_pin_globals_table[] = { // Pins 1-16 /* VBAT -------------------------------------------*/ { MP_ROM_QSTR(MP_QSTR_PC13), MP_ROM_PTR(&pin_PC13) }, diff --git a/ports/stm/packages/UFQFPN48.c b/ports/stm/packages/UFQFPN48.c index b45fc9c985326..1092b8df15f52 100644 --- a/ports/stm/packages/UFQFPN48.c +++ b/ports/stm/packages/UFQFPN48.c @@ -2,7 +2,7 @@ #include "common-hal/microcontroller/Pin.h" #include "py/obj.h" -STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { +static const mp_rom_map_elem_t mcu_pin_globals_table[] = { // Pins 1-12 /* VBAT -------------------------------------------*/ { MP_ROM_QSTR(MP_QSTR_PC13), MP_ROM_PTR(&pin_PC13) }, diff --git a/ports/stm/packages/WLCSP144.c b/ports/stm/packages/WLCSP144.c index a08d160863684..341715b9682f4 100644 --- a/ports/stm/packages/WLCSP144.c +++ b/ports/stm/packages/WLCSP144.c @@ -2,7 +2,7 @@ #include "common-hal/microcontroller/Pin.h" #include "py/obj.h" -STATIC const mp_rom_map_elem_t mcu_pin_globals_table[] = { +static const mp_rom_map_elem_t mcu_pin_globals_table[] = { // Pins 1-36 { MP_ROM_QSTR(MP_QSTR_PE02), MP_ROM_PTR(&pin_PE02) }, { MP_ROM_QSTR(MP_QSTR_PE03), MP_ROM_PTR(&pin_PE03) }, diff --git a/ports/unix/README.md b/ports/unix/README.md index 21661dc877241..61dfd7453e6ac 100644 --- a/ports/unix/README.md +++ b/ports/unix/README.md @@ -74,7 +74,7 @@ options. For example, to build the SSL module, `MICROPY_PY_SSL` should be set to 1. Debug Symbols -------------- +============= By default, builds are stripped of symbols and debug information to save size. diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c index 2670db3402dd7..4308ca6a1d27a 100644 --- a/ports/unix/coverage.c +++ b/ports/unix/coverage.c @@ -31,7 +31,7 @@ typedef struct _mp_obj_streamtest_t { int error_code; } mp_obj_streamtest_t; -STATIC mp_obj_t stest_set_buf(mp_obj_t o_in, mp_obj_t buf_in) { +static mp_obj_t stest_set_buf(mp_obj_t o_in, mp_obj_t buf_in) { mp_obj_streamtest_t *o = MP_OBJ_TO_PTR(o_in); mp_buffer_info_t bufinfo; mp_get_buffer_raise(buf_in, &bufinfo, MP_BUFFER_READ); @@ -41,16 +41,16 @@ STATIC mp_obj_t stest_set_buf(mp_obj_t o_in, mp_obj_t buf_in) { o->pos = 0; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(stest_set_buf_obj, stest_set_buf); +static MP_DEFINE_CONST_FUN_OBJ_2(stest_set_buf_obj, stest_set_buf); -STATIC mp_obj_t stest_set_error(mp_obj_t o_in, mp_obj_t err_in) { +static mp_obj_t stest_set_error(mp_obj_t o_in, mp_obj_t err_in) { mp_obj_streamtest_t *o = MP_OBJ_TO_PTR(o_in); o->error_code = mp_obj_get_int(err_in); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(stest_set_error_obj, stest_set_error); +static MP_DEFINE_CONST_FUN_OBJ_2(stest_set_error_obj, stest_set_error); -STATIC mp_uint_t stest_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stest_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { mp_obj_streamtest_t *o = MP_OBJ_TO_PTR(o_in); if (o->pos < o->len) { if (size > o->len - o->pos) { @@ -67,7 +67,7 @@ STATIC mp_uint_t stest_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errco } } -STATIC mp_uint_t stest_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stest_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_streamtest_t *o = MP_OBJ_TO_PTR(o_in); (void)buf; (void)size; @@ -75,7 +75,7 @@ STATIC mp_uint_t stest_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int return MP_STREAM_ERROR; } -STATIC mp_uint_t stest_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t stest_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { mp_obj_streamtest_t *o = MP_OBJ_TO_PTR(o_in); (void)arg; (void)request; @@ -87,7 +87,7 @@ STATIC mp_uint_t stest_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, in return 0; } -STATIC const mp_rom_map_elem_t rawfile_locals_dict_table[] = { +static const mp_rom_map_elem_t rawfile_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_set_buf), MP_ROM_PTR(&stest_set_buf_obj) }, { MP_ROM_QSTR(MP_QSTR_set_error), MP_ROM_PTR(&stest_set_error_obj) }, { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, @@ -99,15 +99,15 @@ STATIC const mp_rom_map_elem_t rawfile_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_ioctl), MP_ROM_PTR(&mp_stream_ioctl_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(rawfile_locals_dict, rawfile_locals_dict_table); +static MP_DEFINE_CONST_DICT(rawfile_locals_dict, rawfile_locals_dict_table); -STATIC const mp_stream_p_t fileio_stream_p = { +static const mp_stream_p_t fileio_stream_p = { .read = stest_read, .write = stest_write, .ioctl = stest_ioctl, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_stest_fileio, MP_QSTR_stest_fileio, MP_TYPE_FLAG_NONE, @@ -116,7 +116,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); // stream read returns non-blocking error -STATIC mp_uint_t stest_read2(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stest_read2(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { (void)o_in; (void)buf; (void)size; @@ -124,19 +124,19 @@ STATIC mp_uint_t stest_read2(mp_obj_t o_in, void *buf, mp_uint_t size, int *errc return MP_STREAM_ERROR; } -STATIC const mp_rom_map_elem_t rawfile_locals_dict_table2[] = { +static const mp_rom_map_elem_t rawfile_locals_dict_table2[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(rawfile_locals_dict2, rawfile_locals_dict_table2); +static MP_DEFINE_CONST_DICT(rawfile_locals_dict2, rawfile_locals_dict_table2); -STATIC const mp_stream_p_t textio_stream_p2 = { +static const mp_stream_p_t textio_stream_p2 = { .read = stest_read2, .write = NULL, .is_text = true, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_stest_textio2, MP_QSTR_stest_textio2, MP_TYPE_FLAG_NONE, @@ -145,15 +145,15 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); // str/bytes objects without a valid hash -STATIC const mp_obj_str_t str_no_hash_obj = {{&mp_type_str}, 0, 10, (const byte *)"0123456789"}; -STATIC const mp_obj_str_t bytes_no_hash_obj = {{&mp_type_bytes}, 0, 10, (const byte *)"0123456789"}; +static const mp_obj_str_t str_no_hash_obj = {{&mp_type_str}, 0, 10, (const byte *)"0123456789"}; +static const mp_obj_str_t bytes_no_hash_obj = {{&mp_type_bytes}, 0, 10, (const byte *)"0123456789"}; -STATIC int pairheap_lt(mp_pairheap_t *a, mp_pairheap_t *b) { +static int pairheap_lt(mp_pairheap_t *a, mp_pairheap_t *b) { return (uintptr_t)a < (uintptr_t)b; } // ops array contain operations: x>=0 means push(x), x<0 means delete(-x) -STATIC void pairheap_test(size_t nops, int *ops) { +static void pairheap_test(size_t nops, int *ops) { mp_pairheap_t node[8]; for (size_t i = 0; i < MP_ARRAY_SIZE(node); ++i) { mp_pairheap_init_node(pairheap_lt, &node[i]); @@ -183,7 +183,7 @@ STATIC void pairheap_test(size_t nops, int *ops) { } // function to run extra tests for things that can't be checked by scripts -STATIC mp_obj_t extra_coverage(void) { +static mp_obj_t extra_coverage(void) { // mp_printf (used by ports that don't have a native printf) { mp_printf(&mp_plat_print, "# mp_printf\n"); diff --git a/ports/unix/coveragecpp.cpp b/ports/unix/coveragecpp.cpp index ea7418e1dd46a..93c1b387fe285 100644 --- a/ports/unix/coveragecpp.cpp +++ b/ports/unix/coveragecpp.cpp @@ -5,7 +5,7 @@ extern "C" { #if defined(MICROPY_UNIX_COVERAGE) // Just to test building of C++ code. -STATIC mp_obj_t extra_cpp_coverage_impl() { +static mp_obj_t extra_cpp_coverage_impl() { return mp_const_none; } diff --git a/ports/unix/input.c b/ports/unix/input.c index c5bf7197388cc..31926a5a8e1af 100644 --- a/ports/unix/input.c +++ b/ports/unix/input.c @@ -43,6 +43,7 @@ char *prompt(char *p) { // simple read string static char buf[256]; fputs(p, stdout); + fflush(stdout); char *s = fgets(buf, sizeof(buf), stdin); if (!s) { return NULL; diff --git a/ports/unix/main.c b/ports/unix/main.c index c7e85a3c63cb8..28521c1251438 100644 --- a/ports/unix/main.c +++ b/ports/unix/main.c @@ -62,7 +62,7 @@ mp_obj_t common_hal_os_getenv(const char *key, mp_obj_t default_); os_getenv_err_t common_hal_os_getenv_str(const char *key, char *value, size_t value_len); os_getenv_err_t common_hal_os_getenv_int(const char *key, mp_int_t *value); -STATIC mp_obj_t mod_os_getenv_int(mp_obj_t var_in) { +static mp_obj_t mod_os_getenv_int(mp_obj_t var_in) { mp_int_t value; os_getenv_err_t result = common_hal_os_getenv_int(mp_obj_str_get_str(var_in), &value); if (result == 0) { @@ -72,7 +72,7 @@ STATIC mp_obj_t mod_os_getenv_int(mp_obj_t var_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mod_os_getenv_int_obj, mod_os_getenv_int); -STATIC mp_obj_t mod_os_getenv_str(mp_obj_t var_in) { +static mp_obj_t mod_os_getenv_str(mp_obj_t var_in) { char buf[4096]; os_getenv_err_t result = common_hal_os_getenv_str(mp_obj_str_get_str(var_in), buf, sizeof(buf)); if (result == 0) { @@ -84,8 +84,8 @@ MP_DEFINE_CONST_FUN_OBJ_1(mod_os_getenv_str_obj, mod_os_getenv_str); #endif // Command line options, with their defaults -STATIC bool compile_only = false; -STATIC uint emit_opt = MP_EMIT_OPT_NONE; +static bool compile_only = false; +static uint emit_opt = MP_EMIT_OPT_NONE; #if MICROPY_ENABLE_GC // Heap size of GC heap (if enabled) @@ -106,7 +106,7 @@ long heap_size = 1024 * 1024 * (sizeof(mp_uint_t) / 4); #error "The unix port requires MICROPY_PY_SYS_ARGV=1" #endif -STATIC void stderr_print_strn(void *env, const char *str, size_t len) { +static void stderr_print_strn(void *env, const char *str, size_t len) { (void)env; ssize_t ret; MP_HAL_RETRY_SYSCALL(ret, write(STDERR_FILENO, str, len), {}); @@ -122,7 +122,7 @@ const mp_print_t mp_stderr_print = {NULL, stderr_print_strn}; // If exc is SystemExit, return value where FORCED_EXIT bit set, // and lower 8 bits are SystemExit value. For all other exceptions, // return 1. -STATIC int handle_uncaught_exception(mp_obj_base_t *exc) { +static int handle_uncaught_exception(mp_obj_base_t *exc) { // check for SystemExit if (mp_obj_is_subclass_fast(MP_OBJ_FROM_PTR(exc->type), MP_OBJ_FROM_PTR(&mp_type_SystemExit))) { // None is an exit value of 0; an int is its value; anything else is 1 @@ -147,7 +147,7 @@ STATIC int handle_uncaught_exception(mp_obj_base_t *exc) { // Returns standard error codes: 0 for success, 1 for all other errors, // except if FORCED_EXIT bit is set then script raised SystemExit and the // value of the exit is in the lower 8 bits of the return value -STATIC int execute_from_lexer(int source_kind, const void *source, mp_parse_input_kind_t input_kind, bool is_repl) { +static int execute_from_lexer(int source_kind, const void *source, mp_parse_input_kind_t input_kind, bool is_repl) { mp_hal_set_interrupt_char(CHAR_CTRL_C); nlr_buf_t nlr; @@ -209,7 +209,7 @@ STATIC int execute_from_lexer(int source_kind, const void *source, mp_parse_inpu #if MICROPY_USE_READLINE == 1 #include "shared/readline/readline.h" #else -STATIC char *strjoin(const char *s1, int sep_char, const char *s2) { +static char *strjoin(const char *s1, int sep_char, const char *s2) { int l1 = strlen(s1); int l2 = strlen(s2); char *s = malloc(l1 + l2 + 2); @@ -224,7 +224,7 @@ STATIC char *strjoin(const char *s1, int sep_char, const char *s2) { } #endif -STATIC int do_repl(void) { +static int do_repl(void) { mp_hal_stdout_tx_str(MICROPY_BANNER_NAME_AND_VERSION); mp_hal_stdout_tx_str("; " MICROPY_BANNER_MACHINE); mp_hal_stdout_tx_str("\nUse Ctrl-D to exit, Ctrl-E for paste mode\n"); @@ -338,15 +338,15 @@ STATIC int do_repl(void) { #endif } -STATIC int do_file(const char *file) { +static int do_file(const char *file) { return execute_from_lexer(LEX_SRC_FILENAME, file, MP_PARSE_FILE_INPUT, false); } -STATIC int do_str(const char *str) { +static int do_str(const char *str) { return execute_from_lexer(LEX_SRC_STR, str, MP_PARSE_FILE_INPUT, false); } -STATIC void print_help(char **argv) { +static void print_help(char **argv) { printf( "usage: %s [] [-X ] [-c | -m | ]\n" "Options:\n" @@ -385,13 +385,13 @@ STATIC void print_help(char **argv) { } } -STATIC int invalid_args(void) { +static int invalid_args(void) { fprintf(stderr, "Invalid command line arguments. Use -h option for help.\n"); return 1; } // Process options which set interpreter init options -STATIC void pre_process_options(int argc, char **argv) { +static void pre_process_options(int argc, char **argv) { for (int a = 1; a < argc; a++) { if (argv[a][0] == '-') { if (strcmp(argv[a], "-c") == 0 || strcmp(argv[a], "-m") == 0) { @@ -471,7 +471,7 @@ STATIC void pre_process_options(int argc, char **argv) { } } -STATIC void set_sys_argv(char *argv[], int argc, int start_arg) { +static void set_sys_argv(char *argv[], int argc, int start_arg) { for (int i = start_arg; i < argc; i++) { mp_obj_list_append(mp_sys_argv, MP_OBJ_NEW_QSTR(qstr_from_str(argv[i]))); } @@ -479,9 +479,9 @@ STATIC void set_sys_argv(char *argv[], int argc, int start_arg) { #if MICROPY_PY_SYS_EXECUTABLE extern mp_obj_str_t mp_sys_executable_obj; -STATIC char executable_path[MICROPY_ALLOC_PATH_MAX]; +static char executable_path[MICROPY_ALLOC_PATH_MAX]; -STATIC void sys_set_excecutable(char *argv0) { +static void sys_set_excecutable(char *argv0) { if (realpath(argv0, executable_path)) { mp_obj_str_set_data(&mp_sys_executable_obj, (byte *)executable_path, strlen(executable_path)); } diff --git a/ports/unix/mbedtls/mbedtls_config.h b/ports/unix/mbedtls/mbedtls_config_port.h similarity index 98% rename from ports/unix/mbedtls/mbedtls_config.h rename to ports/unix/mbedtls/mbedtls_config_port.h index 629064abcf297..c619de9b8b1b9 100644 --- a/ports/unix/mbedtls/mbedtls_config.h +++ b/ports/unix/mbedtls/mbedtls_config_port.h @@ -30,7 +30,6 @@ #define MBEDTLS_CIPHER_MODE_CTR // needed for MICROPY_PY_CRYPTOLIB_CTR // Enable mbedtls modules -#define MBEDTLS_HAVEGE_C #define MBEDTLS_TIMING_C // Include common mbedtls configuration. diff --git a/ports/unix/modffi.c b/ports/unix/modffi.c index bc585f8647bc6..b7d03e84dde6f 100644 --- a/ports/unix/modffi.c +++ b/ports/unix/modffi.c @@ -107,13 +107,13 @@ typedef struct _mp_obj_fficallback_t { ffi_type *params[]; } mp_obj_fficallback_t; -// STATIC const mp_obj_type_t opaque_type; -STATIC const mp_obj_type_t ffimod_type; -STATIC const mp_obj_type_t ffifunc_type; -STATIC const mp_obj_type_t fficallback_type; -STATIC const mp_obj_type_t ffivar_type; +// static const mp_obj_type_t opaque_type; +static const mp_obj_type_t ffimod_type; +static const mp_obj_type_t ffifunc_type; +static const mp_obj_type_t fficallback_type; +static const mp_obj_type_t ffivar_type; -STATIC ffi_type *char2ffi_type(char c) { +static ffi_type *char2ffi_type(char c) { switch (c) { case 'b': return &ffi_type_schar; @@ -154,7 +154,7 @@ STATIC ffi_type *char2ffi_type(char c) { } } -STATIC ffi_type *get_ffi_type(mp_obj_t o_in) { +static ffi_type *get_ffi_type(mp_obj_t o_in) { if (mp_obj_is_str(o_in)) { const char *s = mp_obj_str_get_str(o_in); ffi_type *t = char2ffi_type(*s); @@ -167,7 +167,7 @@ STATIC ffi_type *get_ffi_type(mp_obj_t o_in) { mp_raise_TypeError(MP_ERROR_TEXT("unknown type")); } -STATIC mp_obj_t return_ffi_value(ffi_union_t *val, char type) { +static mp_obj_t return_ffi_value(ffi_union_t *val, char type) { switch (type) { case 's': { const char *s = (const char *)(intptr_t)val->ffi; @@ -209,25 +209,25 @@ STATIC mp_obj_t return_ffi_value(ffi_union_t *val, char type) { // FFI module -STATIC void ffimod_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void ffimod_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_ffimod_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->handle); } -STATIC mp_obj_t ffimod_close(mp_obj_t self_in) { +static mp_obj_t ffimod_close(mp_obj_t self_in) { mp_obj_ffimod_t *self = MP_OBJ_TO_PTR(self_in); dlclose(self->handle); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(ffimod_close_obj, ffimod_close); +static MP_DEFINE_CONST_FUN_OBJ_1(ffimod_close_obj, ffimod_close); -STATIC mp_obj_t make_func(mp_obj_t rettype_in, void *func, mp_obj_t argtypes_in) { +static mp_obj_t make_func(mp_obj_t rettype_in, void *func, mp_obj_t argtypes_in) { const char *rettype = mp_obj_str_get_str(rettype_in); const char *argtypes = mp_obj_str_get_str(argtypes_in); mp_int_t nparams = MP_OBJ_SMALL_INT_VALUE(mp_obj_len_maybe(argtypes_in)); - mp_obj_ffifunc_t *o = mp_obj_malloc_var(mp_obj_ffifunc_t, ffi_type *, nparams, &ffifunc_type); + mp_obj_ffifunc_t *o = mp_obj_malloc_var(mp_obj_ffifunc_t, params, ffi_type *, nparams, &ffifunc_type); o->func = func; o->rettype = *rettype; @@ -249,7 +249,7 @@ STATIC mp_obj_t make_func(mp_obj_t rettype_in, void *func, mp_obj_t argtypes_in) return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t ffimod_func(size_t n_args, const mp_obj_t *args) { +static mp_obj_t ffimod_func(size_t n_args, const mp_obj_t *args) { (void)n_args; // always 4 mp_obj_ffimod_t *self = MP_OBJ_TO_PTR(args[0]); const char *symname = mp_obj_str_get_str(args[2]); @@ -262,13 +262,13 @@ STATIC mp_obj_t ffimod_func(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(ffimod_func_obj, 4, 4, ffimod_func); -STATIC mp_obj_t mod_ffi_func(mp_obj_t rettype, mp_obj_t addr_in, mp_obj_t argtypes) { +static mp_obj_t mod_ffi_func(mp_obj_t rettype, mp_obj_t addr_in, mp_obj_t argtypes) { void *addr = (void *)MP_OBJ_TO_PTR(mp_obj_int_get_truncated(addr_in)); return make_func(rettype, addr, argtypes); } 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 *user_data) { +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; @@ -283,7 +283,7 @@ STATIC void call_py_func(ffi_cif *cif, void *ret, void **args, void *user_data) } } -STATIC void call_py_func_with_lock(ffi_cif *cif, void *ret, void **args, void *user_data) { +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; @@ -316,7 +316,7 @@ STATIC void call_py_func_with_lock(ffi_cif *cif, void *ret, void **args, void *u #endif } -STATIC mp_obj_t mod_ffi_callback(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +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]; @@ -334,7 +334,7 @@ STATIC mp_obj_t mod_ffi_callback(size_t n_args, const mp_obj_t *pos_args, mp_map 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)); - mp_obj_fficallback_t *o = mp_obj_malloc_var(mp_obj_fficallback_t, ffi_type *, nparams, &fficallback_type); + mp_obj_fficallback_t *o = mp_obj_malloc_var(mp_obj_fficallback_t, params, ffi_type *, nparams, &fficallback_type); o->clo = ffi_closure_alloc(sizeof(ffi_closure), &o->func); @@ -364,7 +364,7 @@ STATIC mp_obj_t mod_ffi_callback(size_t n_args, const mp_obj_t *pos_args, mp_map } 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) { +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); const char *rettype = mp_obj_str_get_str(vartype_in); const char *symname = mp_obj_str_get_str(symname_in); @@ -381,7 +381,7 @@ STATIC mp_obj_t ffimod_var(mp_obj_t self_in, mp_obj_t vartype_in, mp_obj_t symna } MP_DEFINE_CONST_FUN_OBJ_3(ffimod_var_obj, ffimod_var); -STATIC mp_obj_t ffimod_addr(mp_obj_t self_in, mp_obj_t symname_in) { +static mp_obj_t ffimod_addr(mp_obj_t self_in, mp_obj_t symname_in) { mp_obj_ffimod_t *self = MP_OBJ_TO_PTR(self_in); const char *symname = mp_obj_str_get_str(symname_in); @@ -393,7 +393,7 @@ 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, size_t n_kw, const mp_obj_t *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)n_kw; @@ -411,16 +411,16 @@ STATIC mp_obj_t ffimod_make_new(const mp_obj_type_t *type, size_t n_args, size_t return MP_OBJ_FROM_PTR(o); } -STATIC const mp_rom_map_elem_t ffimod_locals_dict_table[] = { +static const mp_rom_map_elem_t ffimod_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_func), MP_ROM_PTR(&ffimod_func_obj) }, { MP_ROM_QSTR(MP_QSTR_var), MP_ROM_PTR(&ffimod_var_obj) }, { MP_ROM_QSTR(MP_QSTR_addr), MP_ROM_PTR(&ffimod_addr_obj) }, { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&ffimod_close_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(ffimod_locals_dict, ffimod_locals_dict_table); +static MP_DEFINE_CONST_DICT(ffimod_locals_dict, ffimod_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( ffimod_type, MP_QSTR_ffimod, MP_TYPE_FLAG_NONE, @@ -431,13 +431,13 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( // FFI function -STATIC void ffifunc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void ffifunc_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_ffifunc_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->func); } -STATIC unsigned long long ffi_get_int_value(mp_obj_t o) { +static unsigned long long ffi_get_int_value(mp_obj_t o) { if (mp_obj_is_small_int(o)) { return MP_OBJ_SMALL_INT_VALUE(o); } else { @@ -447,7 +447,7 @@ STATIC unsigned long long ffi_get_int_value(mp_obj_t o) { } } -STATIC ffi_union_t ffi_int_obj_to_ffi_union(mp_obj_t o, const char argtype) { +static ffi_union_t ffi_int_obj_to_ffi_union(mp_obj_t o, const char argtype) { ffi_union_t ret; if ((argtype | 0x20) == 'q') { ret.Q = ffi_get_int_value(o); @@ -479,7 +479,7 @@ STATIC ffi_union_t ffi_int_obj_to_ffi_union(mp_obj_t o, const char argtype) { return ret; } -STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t ffifunc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (void)n_kw; mp_obj_ffifunc_t *self = MP_OBJ_TO_PTR(self_in); assert(n_kw == 0); @@ -530,7 +530,7 @@ STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_raise_TypeError(MP_ERROR_TEXT("don't know how to pass object to native function")); } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( ffifunc_type, MP_QSTR_ffifunc, MP_TYPE_FLAG_NONE, @@ -540,24 +540,24 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( // FFI callback for Python function -STATIC void fficallback_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void fficallback_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_fficallback_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->func); } -STATIC mp_obj_t fficallback_cfun(mp_obj_t self_in) { +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 MP_DEFINE_CONST_FUN_OBJ_1(fficallback_cfun_obj, fficallback_cfun); -STATIC const mp_rom_map_elem_t fficallback_locals_dict_table[] = { +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 MP_DEFINE_CONST_DICT(fficallback_locals_dict, fficallback_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( fficallback_type, MP_QSTR_fficallback, MP_TYPE_FLAG_NONE, @@ -567,34 +567,34 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( // FFI variable -STATIC void ffivar_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void ffivar_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_ffivar_t *self = MP_OBJ_TO_PTR(self_in); // Variable value printed as cast to int mp_printf(print, "", self->var, *(int *)self->var); } -STATIC mp_obj_t ffivar_get(mp_obj_t self_in) { +static mp_obj_t ffivar_get(mp_obj_t self_in) { mp_obj_ffivar_t *self = MP_OBJ_TO_PTR(self_in); return mp_binary_get_val_array(self->type, self->var, 0); } MP_DEFINE_CONST_FUN_OBJ_1(ffivar_get_obj, ffivar_get); -STATIC mp_obj_t ffivar_set(mp_obj_t self_in, mp_obj_t val_in) { +static mp_obj_t ffivar_set(mp_obj_t self_in, mp_obj_t val_in) { mp_obj_ffivar_t *self = MP_OBJ_TO_PTR(self_in); mp_binary_set_val_array(self->type, self->var, 0, val_in); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_2(ffivar_set_obj, ffivar_set); -STATIC const mp_rom_map_elem_t ffivar_locals_dict_table[] = { +static const mp_rom_map_elem_t ffivar_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&ffivar_get_obj) }, { MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&ffivar_set_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(ffivar_locals_dict, ffivar_locals_dict_table); +static MP_DEFINE_CONST_DICT(ffivar_locals_dict, ffivar_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( ffivar_type, MP_QSTR_ffivar, MP_TYPE_FLAG_NONE, @@ -605,7 +605,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( // Generic opaque storage object (unused) /* -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( opaque_type, MP_QSTR_opaqueval, MP_TYPE_FLAG_NONE, @@ -613,17 +613,17 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); */ -STATIC mp_obj_t mod_ffi_open(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_ffi_open(size_t n_args, const mp_obj_t *args) { 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); -STATIC mp_obj_t mod_ffi_as_bytearray(mp_obj_t ptr, mp_obj_t size) { +static mp_obj_t mod_ffi_as_bytearray(mp_obj_t ptr, mp_obj_t size) { return mp_obj_new_bytearray_by_ref(mp_obj_int_get_truncated(size), (void *)(uintptr_t)mp_obj_int_get_truncated(ptr)); } MP_DEFINE_CONST_FUN_OBJ_2(mod_ffi_as_bytearray_obj, mod_ffi_as_bytearray); -STATIC const mp_rom_map_elem_t mp_module_ffi_globals_table[] = { +static const mp_rom_map_elem_t mp_module_ffi_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ffi) }, { MP_ROM_QSTR(MP_QSTR_open), MP_ROM_PTR(&mod_ffi_open_obj) }, { MP_ROM_QSTR(MP_QSTR_callback), MP_ROM_PTR(&mod_ffi_callback_obj) }, @@ -631,7 +631,7 @@ STATIC const mp_rom_map_elem_t mp_module_ffi_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_as_bytearray), MP_ROM_PTR(&mod_ffi_as_bytearray_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_ffi_globals, mp_module_ffi_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_ffi_globals, mp_module_ffi_globals_table); const mp_obj_module_t mp_module_ffi = { .base = { &mp_type_module }, diff --git a/ports/unix/modjni.c b/ports/unix/modjni.c index a1cfca81495f4..d953e7e015237 100644 --- a/ports/unix/modjni.c +++ b/ports/unix/modjni.c @@ -59,13 +59,13 @@ static jmethodID List_size_mid; static jclass IndexException_class; -STATIC const mp_obj_type_t jobject_type; -STATIC const mp_obj_type_t jmethod_type; +static const mp_obj_type_t jobject_type; +static const mp_obj_type_t jmethod_type; -STATIC mp_obj_t new_jobject(jobject jo); -STATIC mp_obj_t new_jclass(jclass jc); -STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool is_constr, size_t n_args, const mp_obj_t *args); -STATIC bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out); +static mp_obj_t new_jobject(jobject jo); +static mp_obj_t new_jclass(jclass jc); +static mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool is_constr, size_t n_args, const mp_obj_t *args); +static bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out); typedef struct _mp_obj_jclass_t { mp_obj_base_t base; @@ -87,7 +87,7 @@ typedef struct _mp_obj_jmethod_t { // Utility functions -STATIC bool is_object_type(const char *jtypesig) { +static bool is_object_type(const char *jtypesig) { while (*jtypesig != ' ' && *jtypesig) { if (*jtypesig == '.') { return true; @@ -97,7 +97,7 @@ STATIC bool is_object_type(const char *jtypesig) { return false; } -STATIC void check_exception(void) { +static void check_exception(void) { jobject exc = JJ1(ExceptionOccurred); if (exc) { // JJ1(ExceptionDescribe); @@ -110,7 +110,7 @@ STATIC void check_exception(void) { } } -STATIC void print_jobject(const mp_print_t *print, jobject obj) { +static void print_jobject(const mp_print_t *print, jobject obj) { jobject str_o = JJ(CallObjectMethod, obj, Object_toString_mid); const char *str = JJ(GetStringUTFChars, str_o, NULL); mp_printf(print, str); @@ -119,7 +119,7 @@ STATIC void print_jobject(const mp_print_t *print, jobject obj) { // jclass -STATIC void jclass_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void jclass_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { mp_obj_jclass_t *self = MP_OBJ_TO_PTR(self_in); if (kind == PRINT_REPR) { mp_printf(print, "cls); @@ -130,7 +130,7 @@ STATIC void jclass_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kin } } -STATIC void jclass_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) { +static void jclass_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) { if (dest[0] == MP_OBJ_NULL) { // load attribute mp_obj_jclass_t *self = MP_OBJ_TO_PTR(self_in); @@ -156,7 +156,7 @@ STATIC void jclass_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) { } } -STATIC mp_obj_t jclass_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t jclass_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { if (n_kw != 0) { mp_raise_TypeError(MP_ERROR_TEXT("kwargs not supported")); } @@ -167,14 +167,14 @@ STATIC mp_obj_t jclass_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const return call_method(self->cls, NULL, methods, true, n_args, args); } -STATIC const mp_rom_map_elem_t jclass_locals_dict_table[] = { +static const mp_rom_map_elem_t jclass_locals_dict_table[] = { // { MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&ffivar_get_obj) }, // { MP_ROM_QSTR(MP_QSTR_set), MP_ROM_PTR(&ffivar_set_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(jclass_locals_dict, jclass_locals_dict_table); +static MP_DEFINE_CONST_DICT(jclass_locals_dict, jclass_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( jclass_type, MP_QSTR_jclass, MP_TYPE_FLAG_NONE, @@ -184,7 +184,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &jclass_locals_dict ); -STATIC mp_obj_t new_jclass(jclass jc) { +static mp_obj_t new_jclass(jclass jc) { mp_obj_jclass_t *o = mp_obj_malloc(mp_obj_jclass_t, &jclass_type); o->cls = jc; return MP_OBJ_FROM_PTR(o); @@ -192,7 +192,7 @@ STATIC mp_obj_t new_jclass(jclass jc) { // jobject -STATIC void jobject_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void jobject_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { mp_obj_jobject_t *self = MP_OBJ_TO_PTR(self_in); if (kind == PRINT_REPR) { mp_printf(print, "obj); @@ -203,7 +203,7 @@ STATIC void jobject_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki } } -STATIC void jobject_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) { +static void jobject_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) { if (dest[0] == MP_OBJ_NULL) { // load attribute mp_obj_jobject_t *self = MP_OBJ_TO_PTR(self_in); @@ -233,7 +233,7 @@ STATIC void jobject_attr(mp_obj_t self_in, qstr attr_in, mp_obj_t *dest) { } } -STATIC void get_jclass_name(jobject obj, char *buf) { +static void get_jclass_name(jobject obj, char *buf) { jclass obj_class = JJ(GetObjectClass, obj); jstring name = JJ(CallObjectMethod, obj_class, Class_getName_mid); jint len = JJ(GetStringLength, name); @@ -241,7 +241,7 @@ STATIC void get_jclass_name(jobject obj, char *buf) { check_exception(); } -STATIC mp_obj_t jobject_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { +static mp_obj_t jobject_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { mp_obj_jobject_t *self = MP_OBJ_TO_PTR(self_in); mp_uint_t idx = mp_obj_get_int(index); char class_name[64]; @@ -291,7 +291,7 @@ STATIC mp_obj_t jobject_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) return MP_OBJ_NULL; } -STATIC mp_obj_t jobject_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t jobject_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_jobject_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { case MP_UNARY_OP_BOOL: @@ -309,19 +309,19 @@ STATIC mp_obj_t jobject_unary_op(mp_unary_op_t op, mp_obj_t self_in) { // TODO: subscr_load_adaptor & subscr_getiter convenience functions // should be moved to common location for reuse. -STATIC mp_obj_t subscr_load_adaptor(mp_obj_t self_in, mp_obj_t index_in) { +static mp_obj_t subscr_load_adaptor(mp_obj_t self_in, mp_obj_t index_in) { return mp_obj_subscr(self_in, index_in, MP_OBJ_SENTINEL); } MP_DEFINE_CONST_FUN_OBJ_2(subscr_load_adaptor_obj, subscr_load_adaptor); // .getiter special method which returns iterator which works in terms // of object subscription. -STATIC mp_obj_t subscr_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t subscr_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { mp_obj_t dest[2] = {MP_OBJ_FROM_PTR(&subscr_load_adaptor_obj), self_in}; return mp_obj_new_getitem_iter(dest, iter_buf); } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( jobject_type, MP_QSTR_jobject, MP_TYPE_FLAG_ITER_IS_GETITER, @@ -332,7 +332,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( iter, subscr_getiter ); -STATIC mp_obj_t new_jobject(jobject jo) { +static mp_obj_t new_jobject(jobject jo) { if (jo == NULL) { return mp_const_none; } else if (JJ(IsInstanceOf, jo, String_class)) { @@ -353,7 +353,7 @@ STATIC mp_obj_t new_jobject(jobject jo) { // jmethod -STATIC void jmethod_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void jmethod_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_jmethod_t *self = MP_OBJ_TO_PTR(self_in); // Variable value printed as cast to int @@ -368,14 +368,14 @@ STATIC void jmethod_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ki } \ arg_type += sizeof(java_type_name) - 1; -STATIC const char *strprev(const char *s, char c) { +static const char *strprev(const char *s, char c) { while (*s != c) { s--; } return s; } -STATIC bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out) { +static bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out) { const char *arg_type = *jtypesig; const mp_obj_type_t *type = mp_obj_get_type(arg); @@ -442,7 +442,7 @@ STATIC bool py2jvalue(const char **jtypesig, mp_obj_t arg, jvalue *out) { // perspective, it's aggregate object which may require passing via stack // instead of registers. Work that around by passing jobject and typecasting // it. -STATIC mp_obj_t jvalue2py(const char *jtypesig, jobject arg) { +static mp_obj_t jvalue2py(const char *jtypesig, jobject arg) { if (arg == NULL || MATCH(jtypesig, "void")) { return mp_const_none; } else if (MATCH(jtypesig, "boolean")) { @@ -460,7 +460,7 @@ STATIC mp_obj_t jvalue2py(const char *jtypesig, jobject arg) { } #endif -STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool is_constr, size_t n_args, const mp_obj_t *args) { +static mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool is_constr, size_t n_args, const mp_obj_t *args) { jvalue jargs[n_args]; // printf("methods=%p\n", methods); jsize num_methods = JJ(GetArrayLength, methods); @@ -550,7 +550,7 @@ STATIC mp_obj_t call_method(jobject obj, const char *name, jarray methods, bool } -STATIC mp_obj_t jmethod_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t jmethod_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { if (n_kw != 0) { mp_raise_TypeError(MP_ERROR_TEXT("kwargs not supported")); } @@ -568,7 +568,7 @@ STATIC mp_obj_t jmethod_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const return call_method(self->obj, name, methods, false, n_args, args); } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( jmethod_type, MP_QSTR_jmethod, MP_TYPE_FLAG_NONE, @@ -582,7 +582,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( #define LIBJVM_SO "libjvm.so" #endif -STATIC void create_jvm(void) { +static void create_jvm(void) { JavaVMInitArgs args; JavaVMOption options; options.optionString = "-Djava.class.path=."; @@ -635,7 +635,7 @@ STATIC void create_jvm(void) { IndexException_class = JJ(FindClass, "java/lang/IndexOutOfBoundsException"); } -STATIC mp_obj_t mod_jni_cls(mp_obj_t cls_name_in) { +static mp_obj_t mod_jni_cls(mp_obj_t cls_name_in) { const char *cls_name = mp_obj_str_get_str(cls_name_in); if (!env) { create_jvm(); @@ -648,7 +648,7 @@ STATIC mp_obj_t mod_jni_cls(mp_obj_t cls_name_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mod_jni_cls_obj, mod_jni_cls); -STATIC mp_obj_t mod_jni_array(mp_obj_t type_in, mp_obj_t size_in) { +static mp_obj_t mod_jni_array(mp_obj_t type_in, mp_obj_t size_in) { if (!env) { create_jvm(); } @@ -696,19 +696,19 @@ STATIC mp_obj_t mod_jni_array(mp_obj_t type_in, mp_obj_t size_in) { MP_DEFINE_CONST_FUN_OBJ_2(mod_jni_array_obj, mod_jni_array); -STATIC mp_obj_t mod_jni_env(void) { +static mp_obj_t mod_jni_env(void) { return mp_obj_new_int((mp_int_t)(uintptr_t)env); } MP_DEFINE_CONST_FUN_OBJ_0(mod_jni_env_obj, mod_jni_env); -STATIC const mp_rom_map_elem_t mp_module_jni_globals_table[] = { +static const mp_rom_map_elem_t mp_module_jni_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_jni) }, { MP_ROM_QSTR(MP_QSTR_cls), MP_ROM_PTR(&mod_jni_cls_obj) }, { MP_ROM_QSTR(MP_QSTR_array), MP_ROM_PTR(&mod_jni_array_obj) }, { MP_ROM_QSTR(MP_QSTR_env), MP_ROM_PTR(&mod_jni_env_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_jni_globals, mp_module_jni_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_jni_globals, mp_module_jni_globals_table); const mp_obj_module_t mp_module_jni = { .base = { &mp_type_module }, diff --git a/ports/unix/modmachine.c b/ports/unix/modmachine.c index 40d08d9111422..6f3ab80944061 100644 --- a/ports/unix/modmachine.c +++ b/ports/unix/modmachine.c @@ -70,7 +70,7 @@ uintptr_t mod_machine_mem_get_addr(mp_obj_t addr_o, uint align) { return addr; } -STATIC void mp_machine_idle(void) { +static void mp_machine_idle(void) { #ifdef MICROPY_UNIX_MACHINE_IDLE MICROPY_UNIX_MACHINE_IDLE #else diff --git a/ports/unix/modos.c b/ports/unix/modos.c index 4a821a4b417ab..09d829843100a 100644 --- a/ports/unix/modos.c +++ b/ports/unix/modos.c @@ -41,7 +41,7 @@ os_getenv_err_t common_hal_os_getenv_str(const char *key, char *value, size_t va os_getenv_err_t common_hal_os_getenv_int(const char *key, mp_int_t *value); #endif -STATIC mp_obj_t mp_os_getenv(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_os_getenv(size_t n_args, const mp_obj_t *args) { mp_obj_t var_in = args[0]; #if defined(MICROPY_UNIX_COVERAGE) mp_obj_t result = common_hal_os_getenv(mp_obj_str_get_str(var_in), mp_const_none); @@ -62,7 +62,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_os_getenv_obj, 1, 2, mp_os_getenv); // CIRCUITPY-CHANGE: getenv differences #if defined(MICROPY_UNIX_COVERAGE) -STATIC mp_obj_t mp_os_getenv_int(mp_obj_t var_in) { +static mp_obj_t mp_os_getenv_int(mp_obj_t var_in) { mp_int_t value; os_getenv_err_t result = common_hal_os_getenv_int(mp_obj_str_get_str(var_in), &value); if (result == 0) { @@ -72,7 +72,7 @@ STATIC mp_obj_t mp_os_getenv_int(mp_obj_t var_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_os_getenv_int_obj, mp_os_getenv_int); -STATIC mp_obj_t mp_os_getenv_str(mp_obj_t var_in) { +static mp_obj_t mp_os_getenv_str(mp_obj_t var_in) { char buf[4096]; os_getenv_err_t result = common_hal_os_getenv_str(mp_obj_str_get_str(var_in), buf, sizeof(buf)); if (result == 0) { @@ -83,7 +83,7 @@ STATIC mp_obj_t mp_os_getenv_str(mp_obj_t var_in) { MP_DEFINE_CONST_FUN_OBJ_1(mp_os_getenv_str_obj, mp_os_getenv_str); #endif -STATIC mp_obj_t mp_os_putenv(mp_obj_t key_in, mp_obj_t value_in) { +static mp_obj_t mp_os_putenv(mp_obj_t key_in, mp_obj_t value_in) { const char *key = mp_obj_str_get_str(key_in); const char *value = mp_obj_str_get_str(value_in); int ret; @@ -99,9 +99,9 @@ STATIC mp_obj_t mp_os_putenv(mp_obj_t key_in, mp_obj_t value_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_os_putenv_obj, mp_os_putenv); +static MP_DEFINE_CONST_FUN_OBJ_2(mp_os_putenv_obj, mp_os_putenv); -STATIC mp_obj_t mp_os_unsetenv(mp_obj_t key_in) { +static mp_obj_t mp_os_unsetenv(mp_obj_t key_in) { const char *key = mp_obj_str_get_str(key_in); int ret; @@ -116,9 +116,9 @@ STATIC mp_obj_t mp_os_unsetenv(mp_obj_t key_in) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_unsetenv_obj, mp_os_unsetenv); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_unsetenv_obj, mp_os_unsetenv); -STATIC mp_obj_t mp_os_system(mp_obj_t cmd_in) { +static mp_obj_t mp_os_system(mp_obj_t cmd_in) { const char *cmd = mp_obj_str_get_str(cmd_in); MP_THREAD_GIL_EXIT(); @@ -129,18 +129,18 @@ STATIC mp_obj_t mp_os_system(mp_obj_t cmd_in) { return MP_OBJ_NEW_SMALL_INT(r); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_system_obj, mp_os_system); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_system_obj, mp_os_system); -STATIC mp_obj_t mp_os_urandom(mp_obj_t num) { +static mp_obj_t mp_os_urandom(mp_obj_t num) { mp_int_t n = mp_obj_get_int(num); vstr_t vstr; vstr_init_len(&vstr, n); mp_hal_get_random(n, vstr.buf); return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_os_urandom_obj, mp_os_urandom); -STATIC mp_obj_t mp_os_errno(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_os_errno(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { return MP_OBJ_NEW_SMALL_INT(errno); } @@ -148,4 +148,4 @@ STATIC mp_obj_t mp_os_errno(size_t n_args, const mp_obj_t *args) { errno = mp_obj_get_int(args[0]); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_os_errno_obj, 0, 1, mp_os_errno); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_os_errno_obj, 0, 1, mp_os_errno); diff --git a/ports/unix/modtermios.c b/ports/unix/modtermios.c index 4f9751e274378..b1ad9a450e0c8 100644 --- a/ports/unix/modtermios.c +++ b/ports/unix/modtermios.c @@ -24,6 +24,8 @@ * THE SOFTWARE. */ +#if MICROPY_PY_TERMIOS + #include #include #include @@ -33,9 +35,7 @@ #include "py/runtime.h" #include "py/mphal.h" -#if MICROPY_PY_TERMIOS - -STATIC mp_obj_t mod_termios_tcgetattr(mp_obj_t fd_in) { +static mp_obj_t mod_termios_tcgetattr(mp_obj_t fd_in) { struct termios term; int fd = mp_obj_get_int(fd_in); @@ -65,9 +65,9 @@ STATIC mp_obj_t mod_termios_tcgetattr(mp_obj_t fd_in) { } return MP_OBJ_FROM_PTR(r); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_termios_tcgetattr_obj, mod_termios_tcgetattr); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_termios_tcgetattr_obj, mod_termios_tcgetattr); -STATIC mp_obj_t mod_termios_tcsetattr(mp_obj_t fd_in, mp_obj_t when_in, mp_obj_t attrs_in) { +static mp_obj_t mod_termios_tcsetattr(mp_obj_t fd_in, mp_obj_t when_in, mp_obj_t attrs_in) { struct termios term; int fd = mp_obj_get_int(fd_in); int when = mp_obj_get_int(when_in); @@ -105,9 +105,9 @@ STATIC mp_obj_t mod_termios_tcsetattr(mp_obj_t fd_in, mp_obj_t when_in, mp_obj_t RAISE_ERRNO(res, errno); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(mod_termios_tcsetattr_obj, mod_termios_tcsetattr); +static MP_DEFINE_CONST_FUN_OBJ_3(mod_termios_tcsetattr_obj, mod_termios_tcsetattr); -STATIC mp_obj_t mod_termios_setraw(mp_obj_t fd_in) { +static mp_obj_t mod_termios_setraw(mp_obj_t fd_in) { struct termios term; int fd = mp_obj_get_int(fd_in); int res = tcgetattr(fd, &term); @@ -123,9 +123,9 @@ STATIC mp_obj_t mod_termios_setraw(mp_obj_t fd_in) { RAISE_ERRNO(res, errno); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_termios_setraw_obj, mod_termios_setraw); +static MP_DEFINE_CONST_FUN_OBJ_1(mod_termios_setraw_obj, mod_termios_setraw); -STATIC const mp_rom_map_elem_t mp_module_termios_globals_table[] = { +static const mp_rom_map_elem_t mp_module_termios_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_termios) }, { MP_ROM_QSTR(MP_QSTR_tcgetattr), MP_ROM_PTR(&mod_termios_tcgetattr_obj) }, { MP_ROM_QSTR(MP_QSTR_tcsetattr), MP_ROM_PTR(&mod_termios_tcsetattr_obj) }, @@ -144,7 +144,7 @@ STATIC const mp_rom_map_elem_t mp_module_termios_globals_table[] = { #undef C }; -STATIC MP_DEFINE_CONST_DICT(mp_module_termios_globals, mp_module_termios_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_termios_globals, mp_module_termios_globals_table); const mp_obj_module_t mp_module_termios = { .base = { &mp_type_module }, diff --git a/ports/unix/modtime.c b/ports/unix/modtime.c index b6fbae0d1c24b..fbd94b5ecd129 100644 --- a/ports/unix/modtime.c +++ b/ports/unix/modtime.c @@ -61,7 +61,7 @@ static inline int msec_sleep_tv(struct timeval *tv) { #error Unsupported clock() implementation #endif -STATIC mp_obj_t mp_time_time_get(void) { +static mp_obj_t mp_time_time_get(void) { #if MICROPY_PY_BUILTINS_FLOAT && MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE struct timeval tv; gettimeofday(&tv, NULL); @@ -73,7 +73,7 @@ STATIC mp_obj_t mp_time_time_get(void) { } // Note: this is deprecated since CPy3.3, but pystone still uses it. -STATIC mp_obj_t mod_time_clock(void) { +static mp_obj_t mod_time_clock(void) { #if MICROPY_PY_BUILTINS_FLOAT // float cannot represent full range of int32 precisely, so we pre-divide // int to reduce resolution, and then actually do float division hoping @@ -83,9 +83,9 @@ STATIC mp_obj_t mod_time_clock(void) { return mp_obj_new_int((mp_int_t)clock()); #endif } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_time_clock_obj, mod_time_clock); +static MP_DEFINE_CONST_FUN_OBJ_0(mod_time_clock_obj, mod_time_clock); -STATIC mp_obj_t mp_time_sleep(mp_obj_t arg) { +static mp_obj_t mp_time_sleep(mp_obj_t arg) { #if MICROPY_PY_BUILTINS_FLOAT struct timeval tv; mp_float_t val = mp_obj_get_float(arg); @@ -125,7 +125,7 @@ STATIC mp_obj_t mp_time_sleep(mp_obj_t arg) { return mp_const_none; } -STATIC mp_obj_t mod_time_gm_local_time(size_t n_args, const mp_obj_t *args, struct tm *(*time_func)(const time_t *timep)) { +static mp_obj_t mod_time_gm_local_time(size_t n_args, const mp_obj_t *args, struct tm *(*time_func)(const time_t *timep)) { time_t t; if (n_args == 0) { t = time(NULL); @@ -159,17 +159,17 @@ STATIC mp_obj_t mod_time_gm_local_time(size_t n_args, const mp_obj_t *args, stru return ret; } -STATIC mp_obj_t mod_time_gmtime(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_time_gmtime(size_t n_args, const mp_obj_t *args) { return mod_time_gm_local_time(n_args, args, gmtime); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_time_gmtime_obj, 0, 1, mod_time_gmtime); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_time_gmtime_obj, 0, 1, mod_time_gmtime); -STATIC mp_obj_t mod_time_localtime(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_time_localtime(size_t n_args, const mp_obj_t *args) { return mod_time_gm_local_time(n_args, args, localtime); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_time_localtime_obj, 0, 1, mod_time_localtime); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_time_localtime_obj, 0, 1, mod_time_localtime); -STATIC mp_obj_t mod_time_mktime(mp_obj_t tuple) { +static mp_obj_t mod_time_mktime(mp_obj_t tuple) { size_t len; mp_obj_t *elem; mp_obj_get_array(tuple, &len, &elem); diff --git a/ports/unix/mpbthciport.c b/ports/unix/mpbthciport.c index 8813ce147c1ee..95c39f559910d 100644 --- a/ports/unix/mpbthciport.c +++ b/ports/unix/mpbthciport.c @@ -54,7 +54,7 @@ uint8_t mp_bluetooth_hci_cmd_buf[4 + 256]; -STATIC int uart_fd = -1; +static int uart_fd = -1; // Must be provided by the stack bindings (e.g. mpnimbleport.c or mpbtstackport.c). extern bool mp_bluetooth_hci_poll(void); @@ -68,9 +68,9 @@ extern bool mp_bluetooth_hci_poll(void); extern bool mp_bluetooth_hci_active(void); // Prevent double-enqueuing of the scheduled task. -STATIC volatile bool events_task_is_scheduled = false; +static volatile bool events_task_is_scheduled = false; -STATIC mp_obj_t run_events_scheduled_task(mp_obj_t none_in) { +static mp_obj_t run_events_scheduled_task(mp_obj_t none_in) { (void)none_in; MICROPY_PY_BLUETOOTH_ENTER events_task_is_scheduled = false; @@ -78,14 +78,14 @@ STATIC mp_obj_t run_events_scheduled_task(mp_obj_t none_in) { mp_bluetooth_hci_poll(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(run_events_scheduled_task_obj, run_events_scheduled_task); +static MP_DEFINE_CONST_FUN_OBJ_1(run_events_scheduled_task_obj, run_events_scheduled_task); #endif // MICROPY_PY_BLUETOOTH_USE_SYNC_EVENTS -STATIC const useconds_t UART_POLL_INTERVAL_US = 1000; -STATIC pthread_t hci_poll_thread_id; +static const useconds_t UART_POLL_INTERVAL_US = 1000; +static pthread_t hci_poll_thread_id; -STATIC void *hci_poll_thread(void *arg) { +static void *hci_poll_thread(void *arg) { (void)arg; DEBUG_printf("hci_poll_thread: starting\n"); @@ -118,7 +118,7 @@ STATIC void *hci_poll_thread(void *arg) { return NULL; } -STATIC int configure_uart(void) { +static int configure_uart(void) { struct termios toptions; // Get existing config. diff --git a/ports/unix/mpbtstackport_h4.c b/ports/unix/mpbtstackport_h4.c index dacfff9a498af..14d418c63f229 100644 --- a/ports/unix/mpbtstackport_h4.c +++ b/ports/unix/mpbtstackport_h4.c @@ -24,14 +24,16 @@ * THE SOFTWARE. */ +#include "py/mpconfig.h" + +#if MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_BTSTACK && MICROPY_BLUETOOTH_BTSTACK_H4 + #include #include "py/runtime.h" #include "py/mperrno.h" #include "py/mphal.h" -#if MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_BTSTACK && MICROPY_BLUETOOTH_BTSTACK_H4 - #include "lib/btstack/src/hci_transport_h4.h" #include "lib/btstack/chipset/zephyr/btstack_chipset_zephyr.h" @@ -42,7 +44,7 @@ #define DEBUG_printf(...) // printf(__VA_ARGS__) -STATIC hci_transport_config_uart_t hci_transport_config_uart = { +static hci_transport_config_uart_t hci_transport_config_uart = { .type = HCI_TRANSPORT_CONFIG_UART, .baudrate_init = 1000000, .baudrate_main = 0, diff --git a/ports/unix/mpbtstackport_usb.c b/ports/unix/mpbtstackport_usb.c index b8c7b758d93e6..8b1d1fff2189f 100644 --- a/ports/unix/mpbtstackport_usb.c +++ b/ports/unix/mpbtstackport_usb.c @@ -24,6 +24,10 @@ * THE SOFTWARE. */ +#include "py/mpconfig.h" + +#if MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_BTSTACK && MICROPY_BLUETOOTH_BTSTACK_USB + #include #include @@ -31,8 +35,6 @@ #include "py/mperrno.h" #include "py/mphal.h" -#if MICROPY_PY_BLUETOOTH && MICROPY_BLUETOOTH_BTSTACK && MICROPY_BLUETOOTH_BTSTACK_USB - #include "lib/btstack/src/btstack.h" #include "lib/btstack/src/hci_transport_usb.h" #include "lib/btstack/platform/embedded/btstack_run_loop_embedded.h" @@ -47,7 +49,7 @@ #error Unix btstack requires MICROPY_PY_THREAD #endif -STATIC const useconds_t USB_POLL_INTERVAL_US = 1000; +static const useconds_t USB_POLL_INTERVAL_US = 1000; void mp_bluetooth_btstack_port_init_usb(void) { // MICROPYBTUSB can be a ':'' or '-' separated port list. @@ -71,7 +73,7 @@ void mp_bluetooth_btstack_port_init_usb(void) { hci_init(hci_transport_usb_instance(), NULL); } -STATIC pthread_t bstack_thread_id; +static pthread_t bstack_thread_id; void mp_bluetooth_btstack_port_deinit(void) { hci_power_control(HCI_POWER_OFF); @@ -84,7 +86,7 @@ void mp_bluetooth_btstack_port_deinit(void) { // Provided by mpbstackport_common.c. extern bool mp_bluetooth_hci_poll(void); -STATIC void *btstack_thread(void *arg) { +static void *btstack_thread(void *arg) { (void)arg; hci_power_control(HCI_POWER_ON); diff --git a/ports/unix/mpconfigport.h b/ports/unix/mpconfigport.h index 3e7ea77f71a1b..afc1c3a38d14a 100644 --- a/ports/unix/mpconfigport.h +++ b/ports/unix/mpconfigport.h @@ -41,6 +41,7 @@ // CIRCUITPY-CHANGE #define CIRCUITPY_MICROPYTHON_ADVANCED (1) #define MICROPY_PY_ASYNC_AWAIT (1) +#define MICROPY_PY_UCTYPES (0) #ifndef MICROPY_CONFIG_ROM_LEVEL #define MICROPY_CONFIG_ROM_LEVEL (MICROPY_CONFIG_ROM_LEVEL_CORE_FEATURES) @@ -232,12 +233,6 @@ static inline unsigned long mp_random_seed_init(void) { #include #endif -// In lieu of a WFI(), slow down polling from being a tight loop. -// -// Note that we don't delay for the full TIMEOUT_MS, as execution -// can't be woken from the delay. -#define MICROPY_INTERNAL_WFE(TIMEOUT_MS) mp_hal_delay_us(500) - // Configure the implementation of machine.idle(). #include #define MICROPY_UNIX_MACHINE_IDLE sched_yield(); diff --git a/ports/unix/mpthreadport.c b/ports/unix/mpthreadport.c index 2190bf4ad1ba3..16ac4da8bf56f 100644 --- a/ports/unix/mpthreadport.c +++ b/ports/unix/mpthreadport.c @@ -60,21 +60,21 @@ typedef struct _mp_thread_t { struct _mp_thread_t *next; } mp_thread_t; -STATIC pthread_key_t tls_key; +static pthread_key_t tls_key; // The mutex is used for any code in this port that needs to be thread safe. // Specifically for thread management, access to the linked list is one example. // But also, e.g. scheduler state. -STATIC pthread_mutex_t thread_mutex; -STATIC mp_thread_t *thread; +static pthread_mutex_t thread_mutex; +static mp_thread_t *thread; // this is used to synchronise the signal handler of the thread // it's needed because we can't use any pthread calls in a signal handler #if defined(__APPLE__) -STATIC char thread_signal_done_name[25]; -STATIC sem_t *thread_signal_done_p; +static char thread_signal_done_name[25]; +static sem_t *thread_signal_done_p; #else -STATIC sem_t thread_signal_done; +static sem_t thread_signal_done; #endif void mp_thread_unix_begin_atomic_section(void) { @@ -86,7 +86,7 @@ void mp_thread_unix_end_atomic_section(void) { } // this signal handler is used to scan the regs and stack of a thread -STATIC void mp_thread_gc(int signo, siginfo_t *info, void *context) { +static void mp_thread_gc(int signo, siginfo_t *info, void *context) { (void)info; // unused (void)context; // unused if (signo == MP_THREAD_GC_SIGNAL) { diff --git a/ports/unix/native_base_class.c b/ports/unix/native_base_class.c index 28fd572eaf1f6..e333843e20df0 100644 --- a/ports/unix/native_base_class.c +++ b/ports/unix/native_base_class.c @@ -14,7 +14,7 @@ typedef struct { const mp_obj_type_t native_base_class_type; -STATIC mp_obj_t native_base_class_make_new(const mp_obj_type_t *type, size_t n_args, +static mp_obj_t native_base_class_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *all_args) { enum { ARG_test }; static const mp_arg_t allowed_args[] = { @@ -35,13 +35,13 @@ static native_base_class_obj_t *native_base(mp_obj_t unknown_obj) { return MP_OBJ_TO_PTR(native_obj); } -STATIC mp_obj_t native_base_class_obj_get_test(mp_obj_t self_in) { +static mp_obj_t native_base_class_obj_get_test(mp_obj_t self_in) { native_base_class_obj_t *self = native_base(self_in); return self->test; } MP_DEFINE_CONST_FUN_OBJ_1(native_base_class_get_test_obj, native_base_class_obj_get_test); -STATIC mp_obj_t native_base_class_obj_set_test(mp_obj_t self_in, mp_obj_t value) { +static mp_obj_t native_base_class_obj_set_test(mp_obj_t self_in, mp_obj_t value) { mp_printf(&mp_plat_print, "native base class .test set to: "); mp_obj_print_helper(&mp_plat_print, value, PRINT_REPR); mp_printf(&mp_plat_print, "\n"); @@ -55,7 +55,7 @@ MP_PROPERTY_GETSET(native_base_class_test_obj, (mp_obj_t)&native_base_class_get_test_obj, (mp_obj_t)&native_base_class_set_test_obj); -STATIC mp_obj_t native_base_class_obj_print_subclass_attr(mp_obj_t self_in, mp_obj_t attr_name_obj) { +static mp_obj_t native_base_class_obj_print_subclass_attr(mp_obj_t self_in, mp_obj_t attr_name_obj) { if (!mp_obj_is_str(attr_name_obj)) { mp_raise_TypeError(NULL); } @@ -68,15 +68,15 @@ STATIC mp_obj_t native_base_class_obj_print_subclass_attr(mp_obj_t self_in, mp_o } MP_DEFINE_CONST_FUN_OBJ_2(native_base_class_print_subclass_attr_obj, native_base_class_obj_print_subclass_attr); -STATIC const mp_rom_map_elem_t native_base_class_locals_dict_table[] = { +static const mp_rom_map_elem_t native_base_class_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_test), MP_ROM_PTR(&native_base_class_test_obj) }, { MP_ROM_QSTR(MP_QSTR_print_subclass_attr), MP_ROM_PTR(&native_base_class_print_subclass_attr_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(native_base_class_locals_dict, native_base_class_locals_dict_table); +static MP_DEFINE_CONST_DICT(native_base_class_locals_dict, native_base_class_locals_dict_table); -STATIC mp_obj_t native_base_class_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) { +static mp_obj_t native_base_class_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) { mp_obj_t attribute_value = mp_load_attr(self_in, MP_QSTR_new_attribute); mp_printf(&mp_plat_print, "native base class subscr .new_attribute set to: "); mp_obj_print_helper(&mp_plat_print, attribute_value, PRINT_REPR); diff --git a/ports/unix/unix_mphal.c b/ports/unix/unix_mphal.c index 6e9ad5705368e..238d1cb5ee8a1 100644 --- a/ports/unix/unix_mphal.c +++ b/ports/unix/unix_mphal.c @@ -46,7 +46,7 @@ #ifndef _WIN32 #include -STATIC void sighandler(int signum) { +static void sighandler(int signum) { if (signum == SIGINT) { #if MICROPY_ASYNC_KBD_INTR #if MICROPY_PY_THREAD_GIL diff --git a/ports/unix/variants/coverage/frzmpy/frzmpy4.py b/ports/unix/variants/coverage/frzmpy/frzmpy4.py new file mode 100644 index 0000000000000..669b37535b0f7 --- /dev/null +++ b/ports/unix/variants/coverage/frzmpy/frzmpy4.py @@ -0,0 +1,16 @@ +# Test importing frozen functions. + +# A simple bytecode function with no children. +def f(): + return 1 + + +print(__name__, f()) + + +# A simple bytecode generator with no children. +def g(): + yield 2 + + +print(__name__, next(g())) diff --git a/ports/unix/variants/coverage/manifest.py b/ports/unix/variants/coverage/manifest.py index 7c3d9a6b64d69..37f2531a842f8 100644 --- a/ports/unix/variants/coverage/manifest.py +++ b/ports/unix/variants/coverage/manifest.py @@ -1,3 +1,5 @@ +add_library("unix-ffi", "$(MPY_LIB_DIR)/unix-ffi") freeze_as_str("frzstr") freeze_as_mpy("frzmpy") freeze_mpy("$(MPY_DIR)/tests/frozen") +require("ssl") diff --git a/ports/unix/variants/coverage/mpconfigvariant.h b/ports/unix/variants/coverage/mpconfigvariant.h index 67b1f3c8037df..11f4b2eb4b1b5 100644 --- a/ports/unix/variants/coverage/mpconfigvariant.h +++ b/ports/unix/variants/coverage/mpconfigvariant.h @@ -45,4 +45,5 @@ // CIRCUITPY-CHANGE: Disable things never used in circuitpython #define MICROPY_PY_CRYPTOLIB (0) #define MICROPY_PY_CRYPTOLIB_CTR (0) -#define MICROPY_PY_STRUCT (0) // uses shared-bindings struct +// CircuitPython uses shared-bindings struct +#define MICROPY_PY_STRUCT (0) diff --git a/ports/unix/variants/manifest.py b/ports/unix/variants/manifest.py index f8e8f250ac653..649b1e4c464fb 100644 --- a/ports/unix/variants/manifest.py +++ b/ports/unix/variants/manifest.py @@ -1 +1,3 @@ +add_library("unix-ffi", "$(MPY_LIB_DIR)/unix-ffi") require("mip-cmdline") +require("ssl") diff --git a/ports/unix/variants/minimal/mpconfigvariant.h b/ports/unix/variants/minimal/mpconfigvariant.h index 0dbfbb3d1cd43..97ed786b8f409 100644 --- a/ports/unix/variants/minimal/mpconfigvariant.h +++ b/ports/unix/variants/minimal/mpconfigvariant.h @@ -64,6 +64,3 @@ // Enable just the sys and os built-in modules. #define MICROPY_PY_SYS (1) #define MICROPY_PY_OS (1) - -// The minimum sets this to 1 to save flash. -#define MICROPY_QSTR_BYTES_IN_HASH (2) diff --git a/ports/unix/variants/mpconfigvariant_common.h b/ports/unix/variants/mpconfigvariant_common.h index 981babca9f10b..2e34055bf773f 100644 --- a/ports/unix/variants/mpconfigvariant_common.h +++ b/ports/unix/variants/mpconfigvariant_common.h @@ -41,6 +41,11 @@ #define MICROPY_FLOAT_IMPL (MICROPY_FLOAT_IMPL_DOUBLE) #endif +// Don't use native _Float16 because it increases code size by a lot. +#ifndef MICROPY_FLOAT_USE_NATIVE_FLT16 +#define MICROPY_FLOAT_USE_NATIVE_FLT16 (0) +#endif + // Enable arbitrary precision long-int by default. #ifndef MICROPY_LONGINT_IMPL #define MICROPY_LONGINT_IMPL (MICROPY_LONGINT_IMPL_MPZ) diff --git a/py/asmarm.c b/py/asmarm.c index 42724e4d4b37c..6006490701251 100644 --- a/py/asmarm.c +++ b/py/asmarm.c @@ -39,7 +39,7 @@ #define SIGNED_FIT24(x) (((x) & 0xff800000) == 0) || (((x) & 0xff000000) == 0xff000000) // Insert word into instruction flow -STATIC void emit(asm_arm_t *as, uint op) { +static void emit(asm_arm_t *as, uint op) { uint8_t *c = mp_asm_base_get_cur_to_write_bytes(&as->base, 4); if (c != NULL) { *(uint32_t *)c = op; @@ -47,73 +47,83 @@ STATIC void emit(asm_arm_t *as, uint op) { } // Insert word into instruction flow, add "ALWAYS" condition code -STATIC void emit_al(asm_arm_t *as, uint op) { +static void emit_al(asm_arm_t *as, uint op) { emit(as, op | ASM_ARM_CC_AL); } // Basic instructions without condition code -STATIC uint asm_arm_op_push(uint reglist) { +static uint asm_arm_op_push(uint reglist) { // stmfd sp!, {reglist} return 0x92d0000 | (reglist & 0xFFFF); } -STATIC uint asm_arm_op_pop(uint reglist) { +static uint asm_arm_op_pop(uint reglist) { // ldmfd sp!, {reglist} return 0x8bd0000 | (reglist & 0xFFFF); } -STATIC uint asm_arm_op_mov_reg(uint rd, uint rn) { +static uint asm_arm_op_mov_reg(uint rd, uint rn) { // mov rd, rn return 0x1a00000 | (rd << 12) | rn; } -STATIC uint asm_arm_op_mov_imm(uint rd, uint imm) { +static uint asm_arm_op_mov_imm(uint rd, uint imm) { // mov rd, #imm return 0x3a00000 | (rd << 12) | imm; } -STATIC uint asm_arm_op_mvn_imm(uint rd, uint imm) { +static uint asm_arm_op_mvn_imm(uint rd, uint imm) { // mvn rd, #imm return 0x3e00000 | (rd << 12) | imm; } -STATIC uint asm_arm_op_add_imm(uint rd, uint rn, uint imm) { +static uint asm_arm_op_mvn_reg(uint rd, uint rm) { + // mvn rd, rm + return 0x1e00000 | (rd << 12) | rm; +} + +static uint asm_arm_op_add_imm(uint rd, uint rn, uint imm) { // add rd, rn, #imm return 0x2800000 | (rn << 16) | (rd << 12) | (imm & 0xFF); } -STATIC uint asm_arm_op_add_reg(uint rd, uint rn, uint rm) { +static uint asm_arm_op_add_reg(uint rd, uint rn, uint rm) { // add rd, rn, rm return 0x0800000 | (rn << 16) | (rd << 12) | rm; } -STATIC uint asm_arm_op_sub_imm(uint rd, uint rn, uint imm) { +static uint asm_arm_op_sub_imm(uint rd, uint rn, uint imm) { // sub rd, rn, #imm return 0x2400000 | (rn << 16) | (rd << 12) | (imm & 0xFF); } -STATIC uint asm_arm_op_sub_reg(uint rd, uint rn, uint rm) { +static uint asm_arm_op_sub_reg(uint rd, uint rn, uint rm) { // sub rd, rn, rm return 0x0400000 | (rn << 16) | (rd << 12) | rm; } -STATIC uint asm_arm_op_mul_reg(uint rd, uint rm, uint rs) { +static uint asm_arm_op_rsb_imm(uint rd, uint rn, uint imm) { + // rsb rd, rn, #imm + return 0x2600000 | (rn << 16) | (rd << 12) | (imm & 0xFF); +} + +static uint asm_arm_op_mul_reg(uint rd, uint rm, uint rs) { // mul rd, rm, rs assert(rd != rm); return 0x0000090 | (rd << 16) | (rs << 8) | rm; } -STATIC uint asm_arm_op_and_reg(uint rd, uint rn, uint rm) { +static uint asm_arm_op_and_reg(uint rd, uint rn, uint rm) { // and rd, rn, rm return 0x0000000 | (rn << 16) | (rd << 12) | rm; } -STATIC uint asm_arm_op_eor_reg(uint rd, uint rn, uint rm) { +static uint asm_arm_op_eor_reg(uint rd, uint rn, uint rm) { // eor rd, rn, rm return 0x0200000 | (rn << 16) | (rd << 12) | rm; } -STATIC uint asm_arm_op_orr_reg(uint rd, uint rn, uint rm) { +static uint asm_arm_op_orr_reg(uint rd, uint rn, uint rm) { // orr rd, rn, rm return 0x1800000 | (rn << 16) | (rd << 12) | rm; } @@ -228,11 +238,23 @@ void asm_arm_setcc_reg(asm_arm_t *as, uint rd, uint cond) { emit(as, asm_arm_op_mov_imm(rd, 0) | (cond ^ (1 << 28))); // mov!COND rd, #0 } +void asm_arm_mvn_reg_reg(asm_arm_t *as, uint rd, uint rm) { + // mvn rd, rm + // computes: rd := ~rm + emit_al(as, asm_arm_op_mvn_reg(rd, rm)); +} + void asm_arm_add_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm) { // add rd, rn, rm emit_al(as, asm_arm_op_add_reg(rd, rn, rm)); } +void asm_arm_rsb_reg_reg_imm(asm_arm_t *as, uint rd, uint rn, uint imm) { + // rsb rd, rn, #imm + // computes: rd := #imm - rn + emit_al(as, asm_arm_op_rsb_imm(rd, rn, imm)); +} + void asm_arm_sub_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm) { // sub rd, rn, rm emit_al(as, asm_arm_op_sub_reg(rd, rn, rm)); diff --git a/py/asmarm.h b/py/asmarm.h index 0fc1efe5ecd87..a0e057fce4450 100644 --- a/py/asmarm.h +++ b/py/asmarm.h @@ -94,8 +94,10 @@ void asm_arm_cmp_reg_i8(asm_arm_t *as, uint rd, int imm); void asm_arm_cmp_reg_reg(asm_arm_t *as, uint rd, uint rn); // arithmetic +void asm_arm_mvn_reg_reg(asm_arm_t *as, uint rd, uint rm); void asm_arm_add_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm); void asm_arm_sub_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm); +void asm_arm_rsb_reg_reg_imm(asm_arm_t *as, uint rd, uint rn, uint imm); void asm_arm_mul_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm); void asm_arm_and_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm); void asm_arm_eor_reg_reg_reg(asm_arm_t *as, uint rd, uint rn, uint rm); @@ -189,6 +191,8 @@ void asm_arm_bx_reg(asm_arm_t *as, uint reg_src); #define ASM_MOV_REG_LOCAL_ADDR(as, reg_dest, local_num) asm_arm_mov_reg_local_addr((as), (reg_dest), (local_num)) #define ASM_MOV_REG_PCREL(as, reg_dest, label) asm_arm_mov_reg_pcrel((as), (reg_dest), (label)) +#define ASM_NOT_REG(as, reg_dest) asm_arm_mvn_reg_reg((as), (reg_dest), (reg_dest)) +#define ASM_NEG_REG(as, reg_dest) asm_arm_rsb_reg_reg_imm((as), (reg_dest), (reg_dest), 0) #define ASM_LSL_REG_REG(as, reg_dest, reg_shift) asm_arm_lsl_reg_reg((as), (reg_dest), (reg_shift)) #define ASM_LSR_REG_REG(as, reg_dest, reg_shift) asm_arm_lsr_reg_reg((as), (reg_dest), (reg_shift)) #define ASM_ASR_REG_REG(as, reg_dest, reg_shift) asm_arm_asr_reg_reg((as), (reg_dest), (reg_shift)) diff --git a/py/asmthumb.c b/py/asmthumb.c index 395134028aaa9..0df79e5fd6203 100644 --- a/py/asmthumb.c +++ b/py/asmthumb.c @@ -79,7 +79,7 @@ static inline byte *asm_thumb_get_cur_to_write_bytes(asm_thumb_t *as, int n) { } /* -STATIC void asm_thumb_write_byte_1(asm_thumb_t *as, byte b1) { +static void asm_thumb_write_byte_1(asm_thumb_t *as, byte b1) { byte *c = asm_thumb_get_cur_to_write_bytes(as, 1); c[0] = b1; } @@ -91,7 +91,7 @@ STATIC void asm_thumb_write_byte_1(asm_thumb_t *as, byte b1) { #define IMM32_L2(x) (((x) >> 16) & 0xff) #define IMM32_L3(x) (((x) >> 24) & 0xff) -STATIC void asm_thumb_write_word32(asm_thumb_t *as, int w32) { +static void asm_thumb_write_word32(asm_thumb_t *as, int w32) { byte *c = asm_thumb_get_cur_to_write_bytes(as, 4); c[0] = IMM32_L0(w32); c[1] = IMM32_L1(w32); @@ -216,7 +216,7 @@ void asm_thumb_exit(asm_thumb_t *as) { asm_thumb_op16(as, OP_POP_RLIST_PC(as->push_reglist)); } -STATIC mp_uint_t get_label_dest(asm_thumb_t *as, uint label) { +static mp_uint_t get_label_dest(asm_thumb_t *as, uint label) { assert(label < as->base.max_num_labels); return as->base.label_offsets[label]; } diff --git a/py/asmthumb.h b/py/asmthumb.h index 61b4928d8d9c2..0584ed3227aad 100644 --- a/py/asmthumb.h +++ b/py/asmthumb.h @@ -407,6 +407,8 @@ void asm_thumb_b_rel12(asm_thumb_t *as, int rel); #define ASM_MOV_REG_LOCAL_ADDR(as, reg_dest, local_num) asm_thumb_mov_reg_local_addr((as), (reg_dest), (local_num)) #define ASM_MOV_REG_PCREL(as, rlo_dest, label) asm_thumb_mov_reg_pcrel((as), (rlo_dest), (label)) +#define ASM_NOT_REG(as, reg_dest) asm_thumb_mvn_rlo_rlo((as), (reg_dest), (reg_dest)) +#define ASM_NEG_REG(as, reg_dest) asm_thumb_neg_rlo_rlo((as), (reg_dest), (reg_dest)) #define ASM_LSL_REG_REG(as, reg_dest, reg_shift) asm_thumb_format_4((as), ASM_THUMB_FORMAT_4_LSL, (reg_dest), (reg_shift)) #define ASM_LSR_REG_REG(as, reg_dest, reg_shift) asm_thumb_format_4((as), ASM_THUMB_FORMAT_4_LSR, (reg_dest), (reg_shift)) #define ASM_ASR_REG_REG(as, reg_dest, reg_shift) asm_thumb_format_4((as), ASM_THUMB_FORMAT_4_ASR, (reg_dest), (reg_shift)) diff --git a/py/asmx64.c b/py/asmx64.c index 5c923a523ca54..d9f33cfb2ad7e 100644 --- a/py/asmx64.c +++ b/py/asmx64.c @@ -54,6 +54,8 @@ #define OPCODE_MOVZX_RM8_TO_R64 (0xb6) /* 0x0f 0xb6/r */ #define OPCODE_MOVZX_RM16_TO_R64 (0xb7) /* 0x0f 0xb7/r */ #define OPCODE_LEA_MEM_TO_R64 (0x8d) /* /r */ +#define OPCODE_NOT_RM64 (0xf7) /* /2 */ +#define OPCODE_NEG_RM64 (0xf7) /* /3 */ #define OPCODE_AND_R64_TO_RM64 (0x21) /* /r */ #define OPCODE_OR_R64_TO_RM64 (0x09) /* /r */ #define OPCODE_XOR_R64_TO_RM64 (0x31) /* /r */ @@ -123,14 +125,14 @@ static inline byte *asm_x64_get_cur_to_write_bytes(asm_x64_t *as, int n) { return mp_asm_base_get_cur_to_write_bytes(&as->base, n); } -STATIC void asm_x64_write_byte_1(asm_x64_t *as, byte b1) { +static void asm_x64_write_byte_1(asm_x64_t *as, byte b1) { byte *c = asm_x64_get_cur_to_write_bytes(as, 1); if (c != NULL) { c[0] = b1; } } -STATIC void asm_x64_write_byte_2(asm_x64_t *as, byte b1, byte b2) { +static void asm_x64_write_byte_2(asm_x64_t *as, byte b1, byte b2) { byte *c = asm_x64_get_cur_to_write_bytes(as, 2); if (c != NULL) { c[0] = b1; @@ -138,7 +140,7 @@ STATIC void asm_x64_write_byte_2(asm_x64_t *as, byte b1, byte b2) { } } -STATIC void asm_x64_write_byte_3(asm_x64_t *as, byte b1, byte b2, byte b3) { +static void asm_x64_write_byte_3(asm_x64_t *as, byte b1, byte b2, byte b3) { byte *c = asm_x64_get_cur_to_write_bytes(as, 3); if (c != NULL) { c[0] = b1; @@ -147,7 +149,7 @@ STATIC void asm_x64_write_byte_3(asm_x64_t *as, byte b1, byte b2, byte b3) { } } -STATIC void asm_x64_write_word32(asm_x64_t *as, int w32) { +static void asm_x64_write_word32(asm_x64_t *as, int w32) { byte *c = asm_x64_get_cur_to_write_bytes(as, 4); if (c != NULL) { c[0] = IMM32_L0(w32); @@ -157,7 +159,7 @@ STATIC void asm_x64_write_word32(asm_x64_t *as, int w32) { } } -STATIC void asm_x64_write_word64(asm_x64_t *as, int64_t w64) { +static void asm_x64_write_word64(asm_x64_t *as, int64_t w64) { byte *c = asm_x64_get_cur_to_write_bytes(as, 8); if (c != NULL) { c[0] = IMM32_L0(w64); @@ -172,7 +174,7 @@ STATIC void asm_x64_write_word64(asm_x64_t *as, int64_t w64) { } /* unused -STATIC void asm_x64_write_word32_to(asm_x64_t *as, int offset, int w32) { +static void asm_x64_write_word32_to(asm_x64_t *as, int offset, int w32) { byte* c; assert(offset + 4 <= as->code_size); c = as->code_base + offset; @@ -183,7 +185,7 @@ STATIC void asm_x64_write_word32_to(asm_x64_t *as, int offset, int w32) { } */ -STATIC void asm_x64_write_r64_disp(asm_x64_t *as, int r64, int disp_r64, int disp_offset) { +static void asm_x64_write_r64_disp(asm_x64_t *as, int r64, int disp_r64, int disp_offset) { uint8_t rm_disp; if (disp_offset == 0 && (disp_r64 & 7) != ASM_X64_REG_RBP) { rm_disp = MODRM_RM_DISP0; @@ -204,7 +206,7 @@ STATIC void asm_x64_write_r64_disp(asm_x64_t *as, int r64, int disp_r64, int dis } } -STATIC void asm_x64_generic_r64_r64(asm_x64_t *as, int dest_r64, int src_r64, int op) { +static void asm_x64_generic_r64_r64(asm_x64_t *as, int dest_r64, int src_r64, int op) { asm_x64_write_byte_3(as, REX_PREFIX | REX_W | REX_R_FROM_R64(src_r64) | REX_B_FROM_R64(dest_r64), op, MODRM_R64(src_r64) | MODRM_RM_REG | MODRM_RM_R64(dest_r64)); } @@ -243,7 +245,7 @@ void asm_x64_pop_r64(asm_x64_t *as, int dest_r64) { } } -STATIC void asm_x64_ret(asm_x64_t *as) { +static void asm_x64_ret(asm_x64_t *as) { asm_x64_write_byte_1(as, OPCODE_RET); } @@ -317,7 +319,7 @@ void asm_x64_mov_mem64_to_r64(asm_x64_t *as, int src_r64, int src_disp, int dest asm_x64_write_r64_disp(as, dest_r64, src_r64, src_disp); } -STATIC void asm_x64_lea_disp_to_r64(asm_x64_t *as, int src_r64, int src_disp, int dest_r64) { +static void asm_x64_lea_disp_to_r64(asm_x64_t *as, int src_r64, int src_disp, int dest_r64) { // use REX prefix for 64 bit operation asm_x64_write_byte_2(as, REX_PREFIX | REX_W | REX_R_FROM_R64(dest_r64) | REX_B_FROM_R64(src_r64), OPCODE_LEA_MEM_TO_R64); asm_x64_write_r64_disp(as, dest_r64, src_r64, src_disp); @@ -362,6 +364,14 @@ void asm_x64_mov_i64_to_r64_optimised(asm_x64_t *as, int64_t src_i64, int dest_r } } +void asm_x64_not_r64(asm_x64_t *as, int dest_r64) { + asm_x64_generic_r64_r64(as, dest_r64, 2, OPCODE_NOT_RM64); +} + +void asm_x64_neg_r64(asm_x64_t *as, int dest_r64) { + asm_x64_generic_r64_r64(as, dest_r64, 3, OPCODE_NEG_RM64); +} + void asm_x64_and_r64_r64(asm_x64_t *as, int dest_r64, int src_r64) { asm_x64_generic_r64_r64(as, dest_r64, src_r64, OPCODE_AND_R64_TO_RM64); } @@ -414,7 +424,7 @@ void asm_x64_sub_i32_from_r32(asm_x64_t *as, int src_i32, int dest_r32) { } */ -STATIC void asm_x64_sub_r64_i32(asm_x64_t *as, int dest_r64, int src_i32) { +static void asm_x64_sub_r64_i32(asm_x64_t *as, int dest_r64, int src_i32) { assert(dest_r64 < 8); if (SIGNED_FIT8(src_i32)) { // use REX prefix for 64 bit operation @@ -480,7 +490,7 @@ void asm_x64_jmp_reg(asm_x64_t *as, int src_r64) { asm_x64_write_byte_2(as, OPCODE_JMP_RM64, MODRM_R64(4) | MODRM_RM_REG | MODRM_RM_R64(src_r64)); } -STATIC mp_uint_t get_label_dest(asm_x64_t *as, mp_uint_t label) { +static mp_uint_t get_label_dest(asm_x64_t *as, mp_uint_t label) { assert(label < as->base.max_num_labels); return as->base.label_offsets[label]; } @@ -560,7 +570,7 @@ void asm_x64_exit(asm_x64_t *as) { // ^ ^ // | low address | high address in RAM // -STATIC int asm_x64_local_offset_from_rsp(asm_x64_t *as, int local_num) { +static int asm_x64_local_offset_from_rsp(asm_x64_t *as, int local_num) { (void)as; // Stack is full descending, RSP points to local0 return local_num * WORD_SIZE; diff --git a/py/asmx64.h b/py/asmx64.h index 2d4bf8d33ced9..03070b5f63d3b 100644 --- a/py/asmx64.h +++ b/py/asmx64.h @@ -97,6 +97,8 @@ void asm_x64_mov_mem8_to_r64zx(asm_x64_t *as, int src_r64, int src_disp, int des void asm_x64_mov_mem16_to_r64zx(asm_x64_t *as, int src_r64, int src_disp, int dest_r64); void asm_x64_mov_mem32_to_r64zx(asm_x64_t *as, int src_r64, int src_disp, int dest_r64); void asm_x64_mov_mem64_to_r64(asm_x64_t *as, int src_r64, int src_disp, int dest_r64); +void asm_x64_not_r64(asm_x64_t *as, int dest_r64); +void asm_x64_neg_r64(asm_x64_t *as, int dest_r64); void asm_x64_and_r64_r64(asm_x64_t *as, int dest_r64, int src_r64); void asm_x64_or_r64_r64(asm_x64_t *as, int dest_r64, int src_r64); void asm_x64_xor_r64_r64(asm_x64_t *as, int dest_r64, int src_r64); @@ -192,6 +194,8 @@ void asm_x64_call_ind(asm_x64_t *as, size_t fun_id, int temp_r32); #define ASM_MOV_REG_LOCAL_ADDR(as, reg_dest, local_num) asm_x64_mov_local_addr_to_r64((as), (local_num), (reg_dest)) #define ASM_MOV_REG_PCREL(as, reg_dest, label) asm_x64_mov_reg_pcrel((as), (reg_dest), (label)) +#define ASM_NOT_REG(as, reg) asm_x64_not_r64((as), (reg)) +#define ASM_NEG_REG(as, reg) asm_x64_neg_r64((as), (reg)) #define ASM_LSL_REG(as, reg) asm_x64_shl_r64_cl((as), (reg)) #define ASM_LSR_REG(as, reg) asm_x64_shr_r64_cl((as), (reg)) #define ASM_ASR_REG(as, reg) asm_x64_sar_r64_cl((as), (reg)) diff --git a/py/asmx86.c b/py/asmx86.c index 4b0f8047f6eb7..4acac1b46ac4f 100644 --- a/py/asmx86.c +++ b/py/asmx86.c @@ -54,6 +54,8 @@ #define OPCODE_MOVZX_RM8_TO_R32 (0xb6) /* 0x0f 0xb6/r */ #define OPCODE_MOVZX_RM16_TO_R32 (0xb7) /* 0x0f 0xb7/r */ #define OPCODE_LEA_MEM_TO_R32 (0x8d) /* /r */ +#define OPCODE_NOT_RM32 (0xf7) /* /2 */ +#define OPCODE_NEG_RM32 (0xf7) /* /3 */ #define OPCODE_AND_R32_TO_RM32 (0x21) /* /r */ #define OPCODE_OR_R32_TO_RM32 (0x09) /* /r */ #define OPCODE_XOR_R32_TO_RM32 (0x31) /* /r */ @@ -103,14 +105,14 @@ #define SIGNED_FIT8(x) (((x) & 0xffffff80) == 0) || (((x) & 0xffffff80) == 0xffffff80) -STATIC void asm_x86_write_byte_1(asm_x86_t *as, byte b1) { +static void asm_x86_write_byte_1(asm_x86_t *as, byte b1) { byte *c = mp_asm_base_get_cur_to_write_bytes(&as->base, 1); if (c != NULL) { c[0] = b1; } } -STATIC void asm_x86_write_byte_2(asm_x86_t *as, byte b1, byte b2) { +static void asm_x86_write_byte_2(asm_x86_t *as, byte b1, byte b2) { byte *c = mp_asm_base_get_cur_to_write_bytes(&as->base, 2); if (c != NULL) { c[0] = b1; @@ -118,7 +120,7 @@ STATIC void asm_x86_write_byte_2(asm_x86_t *as, byte b1, byte b2) { } } -STATIC void asm_x86_write_byte_3(asm_x86_t *as, byte b1, byte b2, byte b3) { +static void asm_x86_write_byte_3(asm_x86_t *as, byte b1, byte b2, byte b3) { byte *c = mp_asm_base_get_cur_to_write_bytes(&as->base, 3); if (c != NULL) { c[0] = b1; @@ -127,7 +129,7 @@ STATIC void asm_x86_write_byte_3(asm_x86_t *as, byte b1, byte b2, byte b3) { } } -STATIC void asm_x86_write_word32(asm_x86_t *as, int w32) { +static void asm_x86_write_word32(asm_x86_t *as, int w32) { byte *c = mp_asm_base_get_cur_to_write_bytes(&as->base, 4); if (c != NULL) { c[0] = IMM32_L0(w32); @@ -137,7 +139,7 @@ STATIC void asm_x86_write_word32(asm_x86_t *as, int w32) { } } -STATIC void asm_x86_write_r32_disp(asm_x86_t *as, int r32, int disp_r32, int disp_offset) { +static void asm_x86_write_r32_disp(asm_x86_t *as, int r32, int disp_r32, int disp_offset) { uint8_t rm_disp; if (disp_offset == 0 && disp_r32 != ASM_X86_REG_EBP) { rm_disp = MODRM_RM_DISP0; @@ -158,17 +160,17 @@ STATIC void asm_x86_write_r32_disp(asm_x86_t *as, int r32, int disp_r32, int dis } } -STATIC void asm_x86_generic_r32_r32(asm_x86_t *as, int dest_r32, int src_r32, int op) { +static void asm_x86_generic_r32_r32(asm_x86_t *as, int dest_r32, int src_r32, int op) { asm_x86_write_byte_2(as, op, MODRM_R32(src_r32) | MODRM_RM_REG | MODRM_RM_R32(dest_r32)); } #if 0 -STATIC void asm_x86_nop(asm_x86_t *as) { +static void asm_x86_nop(asm_x86_t *as) { asm_x86_write_byte_1(as, OPCODE_NOP); } #endif -STATIC void asm_x86_push_r32(asm_x86_t *as, int src_r32) { +static void asm_x86_push_r32(asm_x86_t *as, int src_r32) { asm_x86_write_byte_1(as, OPCODE_PUSH_R32 | src_r32); } @@ -184,11 +186,11 @@ void asm_x86_push_disp(asm_x86_t *as, int src_r32, int src_offset) { } #endif -STATIC void asm_x86_pop_r32(asm_x86_t *as, int dest_r32) { +static void asm_x86_pop_r32(asm_x86_t *as, int dest_r32) { asm_x86_write_byte_1(as, OPCODE_POP_R32 | dest_r32); } -STATIC void asm_x86_ret(asm_x86_t *as) { +static void asm_x86_ret(asm_x86_t *as) { asm_x86_write_byte_1(as, OPCODE_RET); } @@ -226,7 +228,7 @@ void asm_x86_mov_mem32_to_r32(asm_x86_t *as, int src_r32, int src_disp, int dest asm_x86_write_r32_disp(as, dest_r32, src_r32, src_disp); } -STATIC void asm_x86_lea_disp_to_r32(asm_x86_t *as, int src_r32, int src_disp, int dest_r32) { +static void asm_x86_lea_disp_to_r32(asm_x86_t *as, int src_r32, int src_disp, int dest_r32) { asm_x86_write_byte_1(as, OPCODE_LEA_MEM_TO_R32); asm_x86_write_r32_disp(as, dest_r32, src_r32, src_disp); } @@ -244,6 +246,14 @@ size_t asm_x86_mov_i32_to_r32(asm_x86_t *as, int32_t src_i32, int dest_r32) { return loc; } +void asm_x86_not_r32(asm_x86_t *as, int dest_r32) { + asm_x86_generic_r32_r32(as, dest_r32, 2, OPCODE_NOT_RM32); +} + +void asm_x86_neg_r32(asm_x86_t *as, int dest_r32) { + asm_x86_generic_r32_r32(as, dest_r32, 3, OPCODE_NEG_RM32); +} + void asm_x86_and_r32_r32(asm_x86_t *as, int dest_r32, int src_r32) { asm_x86_generic_r32_r32(as, dest_r32, src_r32, OPCODE_AND_R32_TO_RM32); } @@ -272,7 +282,7 @@ void asm_x86_add_r32_r32(asm_x86_t *as, int dest_r32, int src_r32) { asm_x86_generic_r32_r32(as, dest_r32, src_r32, OPCODE_ADD_R32_TO_RM32); } -STATIC void asm_x86_add_i32_to_r32(asm_x86_t *as, int src_i32, int dest_r32) { +static void asm_x86_add_i32_to_r32(asm_x86_t *as, int src_i32, int dest_r32) { if (SIGNED_FIT8(src_i32)) { asm_x86_write_byte_2(as, OPCODE_ADD_I8_TO_RM32, MODRM_R32(0) | MODRM_RM_REG | MODRM_RM_R32(dest_r32)); asm_x86_write_byte_1(as, src_i32 & 0xff); @@ -286,7 +296,7 @@ void asm_x86_sub_r32_r32(asm_x86_t *as, int dest_r32, int src_r32) { asm_x86_generic_r32_r32(as, dest_r32, src_r32, OPCODE_SUB_R32_FROM_RM32); } -STATIC void asm_x86_sub_r32_i32(asm_x86_t *as, int dest_r32, int src_i32) { +static void asm_x86_sub_r32_i32(asm_x86_t *as, int dest_r32, int src_i32) { if (SIGNED_FIT8(src_i32)) { // defaults to 32 bit operation asm_x86_write_byte_2(as, OPCODE_SUB_I8_FROM_RM32, MODRM_R32(5) | MODRM_RM_REG | MODRM_RM_R32(dest_r32)); @@ -353,7 +363,7 @@ void asm_x86_jmp_reg(asm_x86_t *as, int src_r32) { asm_x86_write_byte_2(as, OPCODE_JMP_RM32, MODRM_R32(4) | MODRM_RM_REG | MODRM_RM_R32(src_r32)); } -STATIC mp_uint_t get_label_dest(asm_x86_t *as, mp_uint_t label) { +static mp_uint_t get_label_dest(asm_x86_t *as, mp_uint_t label) { assert(label < as->base.max_num_labels); return as->base.label_offsets[label]; } @@ -422,7 +432,7 @@ void asm_x86_exit(asm_x86_t *as) { asm_x86_ret(as); } -STATIC int asm_x86_arg_offset_from_esp(asm_x86_t *as, size_t arg_num) { +static int asm_x86_arg_offset_from_esp(asm_x86_t *as, size_t arg_num) { // Above esp are: locals, 4 saved registers, return eip, arguments return (as->num_locals + 4 + 1 + arg_num) * WORD_SIZE; } @@ -454,7 +464,7 @@ void asm_x86_mov_r32_to_arg(asm_x86_t *as, int src_r32, int dest_arg_num) { // ^ ^ // | low address | high address in RAM // -STATIC int asm_x86_local_offset_from_esp(asm_x86_t *as, int local_num) { +static int asm_x86_local_offset_from_esp(asm_x86_t *as, int local_num) { (void)as; // Stack is full descending, ESP points to local0 return local_num * WORD_SIZE; diff --git a/py/asmx86.h b/py/asmx86.h index 10532265c28ef..7796d69762617 100644 --- a/py/asmx86.h +++ b/py/asmx86.h @@ -92,6 +92,8 @@ void asm_x86_mov_r32_to_mem32(asm_x86_t *as, int src_r32, int dest_r32, int dest void asm_x86_mov_mem8_to_r32zx(asm_x86_t *as, int src_r32, int src_disp, int dest_r32); void asm_x86_mov_mem16_to_r32zx(asm_x86_t *as, int src_r32, int src_disp, int dest_r32); void asm_x86_mov_mem32_to_r32(asm_x86_t *as, int src_r32, int src_disp, int dest_r32); +void asm_x86_not_r32(asm_x86_t *as, int dest_r32); +void asm_x86_neg_r32(asm_x86_t *as, int dest_r32); void asm_x86_and_r32_r32(asm_x86_t *as, int dest_r32, int src_r32); void asm_x86_or_r32_r32(asm_x86_t *as, int dest_r32, int src_r32); void asm_x86_xor_r32_r32(asm_x86_t *as, int dest_r32, int src_r32); @@ -187,6 +189,8 @@ void asm_x86_call_ind(asm_x86_t *as, size_t fun_id, mp_uint_t n_args, int temp_r #define ASM_MOV_REG_LOCAL_ADDR(as, reg_dest, local_num) asm_x86_mov_local_addr_to_r32((as), (local_num), (reg_dest)) #define ASM_MOV_REG_PCREL(as, reg_dest, label) asm_x86_mov_reg_pcrel((as), (reg_dest), (label)) +#define ASM_NOT_REG(as, reg) asm_x86_not_r32((as), (reg)) +#define ASM_NEG_REG(as, reg) asm_x86_neg_r32((as), (reg)) #define ASM_LSL_REG(as, reg) asm_x86_shl_r32_cl((as), (reg)) #define ASM_LSR_REG(as, reg) asm_x86_shr_r32_cl((as), (reg)) #define ASM_ASR_REG(as, reg) asm_x86_sar_r32_cl((as), (reg)) diff --git a/py/asmxtensa.c b/py/asmxtensa.c index 8ac914ec412a4..0fbe351dcf3c7 100644 --- a/py/asmxtensa.c +++ b/py/asmxtensa.c @@ -117,7 +117,7 @@ void asm_xtensa_exit_win(asm_xtensa_t *as) { asm_xtensa_op_retw_n(as); } -STATIC uint32_t get_label_dest(asm_xtensa_t *as, uint label) { +static uint32_t get_label_dest(asm_xtensa_t *as, uint label) { assert(label < as->base.max_num_labels); return as->base.label_offsets[label]; } @@ -185,7 +185,9 @@ size_t asm_xtensa_mov_reg_i32(asm_xtensa_t *as, uint reg_dest, uint32_t i32) { } void asm_xtensa_mov_reg_i32_optimised(asm_xtensa_t *as, uint reg_dest, uint32_t i32) { - if (SIGNED_FIT12(i32)) { + if (-32 <= (int)i32 && (int)i32 <= 95) { + asm_xtensa_op_movi_n(as, reg_dest, i32); + } else if (SIGNED_FIT12(i32)) { asm_xtensa_op_movi(as, reg_dest, i32); } else { asm_xtensa_mov_reg_i32(as, reg_dest, i32); diff --git a/py/asmxtensa.h b/py/asmxtensa.h index 62fdb5df89a81..c3c8f225f3744 100644 --- a/py/asmxtensa.h +++ b/py/asmxtensa.h @@ -203,14 +203,19 @@ static inline void asm_xtensa_op_movi(asm_xtensa_t *as, uint reg_dest, int32_t i asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRI8(2, 10, (imm12 >> 8) & 0xf, reg_dest, imm12 & 0xff)); } -static inline void asm_xtensa_op_movi_n(asm_xtensa_t *as, uint reg_dest, int imm4) { - asm_xtensa_op16(as, ASM_XTENSA_ENCODE_RI7(12, reg_dest, imm4)); +// Argument must be in the range (-32 .. 95) inclusive. +static inline void asm_xtensa_op_movi_n(asm_xtensa_t *as, uint reg_dest, int imm7) { + asm_xtensa_op16(as, ASM_XTENSA_ENCODE_RI7(12, reg_dest, imm7)); } static inline void asm_xtensa_op_mull(asm_xtensa_t *as, uint reg_dest, uint reg_src_a, uint reg_src_b) { asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRR(0, 2, 8, reg_dest, reg_src_a, reg_src_b)); } +static inline void asm_xtensa_op_neg(asm_xtensa_t *as, uint reg_dest, uint reg_src) { + asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRR(0, 0, 6, reg_dest, 0, reg_src)); +} + static inline void asm_xtensa_op_or(asm_xtensa_t *as, uint reg_dest, uint reg_src_a, uint reg_src_b) { asm_xtensa_op24(as, ASM_XTENSA_ENCODE_RRR(0, 0, 2, reg_dest, reg_src_a, reg_src_b)); } @@ -372,6 +377,7 @@ void asm_xtensa_call_ind_win(asm_xtensa_t *as, uint idx); #define ASM_MOV_REG_LOCAL_ADDR(as, reg_dest, local_num) asm_xtensa_mov_reg_local_addr((as), (reg_dest), ASM_NUM_REGS_SAVED + (local_num)) #define ASM_MOV_REG_PCREL(as, reg_dest, label) asm_xtensa_mov_reg_pcrel((as), (reg_dest), (label)) +#define ASM_NEG_REG(as, reg_dest) asm_xtensa_op_neg((as), (reg_dest), (reg_dest)) #define ASM_LSL_REG_REG(as, reg_dest, reg_shift) \ do { \ asm_xtensa_op_ssl((as), (reg_shift)); \ diff --git a/py/bc.c b/py/bc.c index 752bd085372ae..c2956030e38e1 100644 --- a/py/bc.c +++ b/py/bc.c @@ -88,7 +88,7 @@ const byte *mp_decode_uint_skip(const byte *ptr) { return ptr; } -STATIC NORETURN void fun_pos_args_mismatch(mp_obj_fun_bc_t *f, size_t expected, size_t given) { +static NORETURN void fun_pos_args_mismatch(mp_obj_fun_bc_t *f, size_t expected, size_t given) { #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE // generic message, used also for other argument issues (void)f; @@ -109,7 +109,7 @@ STATIC NORETURN void fun_pos_args_mismatch(mp_obj_fun_bc_t *f, size_t expected, } #if DEBUG_PRINT -STATIC void dump_args(const mp_obj_t *a, size_t sz) { +static void dump_args(const mp_obj_t *a, size_t sz) { DEBUG_printf("%p: ", a); for (size_t i = 0; i < sz; i++) { DEBUG_printf("%p ", a[i]); @@ -126,7 +126,7 @@ STATIC void dump_args(const mp_obj_t *a, size_t sz) { // - code_state->ip should contain a pointer to the beginning of the prelude // - code_state->sp should be: &code_state->state[0] - 1 // - code_state->n_state should be the number of objects in the local state -STATIC void mp_setup_code_state_helper(mp_code_state_t *code_state, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static void mp_setup_code_state_helper(mp_code_state_t *code_state, size_t n_args, size_t n_kw, const mp_obj_t *args) { // This function is pretty complicated. It's main aim is to be efficient in speed and RAM // usage for the common case of positional only args. @@ -340,9 +340,9 @@ void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw // On entry code_state should be allocated somewhere (stack/heap) and // contain the following valid entries: // - code_state->fun_bc should contain a pointer to the function object -// - code_state->ip should contain a pointer to the beginning of the prelude // - code_state->n_state should be the number of objects in the local state void mp_setup_code_state_native(mp_code_state_native_t *code_state, size_t n_args, size_t n_kw, const mp_obj_t *args) { + code_state->ip = mp_obj_fun_native_get_prelude_ptr(code_state->fun_bc); code_state->sp = &code_state->state[0] - 1; mp_setup_code_state_helper((mp_code_state_t *)code_state, n_args, n_kw, args); } diff --git a/py/bc.h b/py/bc.h index f2d4c5ee67ce3..007897a028ed6 100644 --- a/py/bc.h +++ b/py/bc.h @@ -44,11 +44,11 @@ // prelude size : var uint // contains two values interleaved bit-wise as: xIIIIIIC repeated // x = extension another byte follows -// I = n_info number of bytes in source info section +// I = n_info number of bytes in source info section (always > 0) // C = n_cells number of bytes/cells in closure section // // source info section: -// simple_name : var qstr +// simple_name : var qstr always exists // argname0 : var qstr // ... : var qstr // argnameN : var qstr N = num_pos_args + num_kwonly_args - 1 @@ -232,7 +232,7 @@ typedef struct _mp_compiled_module_t { // Outer level struct defining a frozen module. typedef struct _mp_frozen_module_t { const mp_module_constants_t constants; - const struct _mp_raw_code_t *rc; + const void *proto_fun; } mp_frozen_module_t; // State for an executing function. @@ -287,7 +287,7 @@ mp_vm_return_kind_t mp_execute_bytecode(mp_code_state_t *code_state, mp_code_state_t *mp_obj_fun_bc_prepare_codestate(mp_obj_t func, size_t n_args, size_t n_kw, const mp_obj_t *args); void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw, const mp_obj_t *args); void mp_setup_code_state_native(mp_code_state_native_t *code_state, size_t n_args, size_t n_kw, const mp_obj_t *args); -void mp_bytecode_print(const mp_print_t *print, const struct _mp_raw_code_t *rc, const mp_module_constants_t *cm); +void mp_bytecode_print(const mp_print_t *print, const struct _mp_raw_code_t *rc, size_t fun_data_len, const mp_module_constants_t *cm); void mp_bytecode_print2(const mp_print_t *print, const byte *ip, size_t len, struct _mp_raw_code_t *const *child_table, const mp_module_constants_t *cm); const byte *mp_bytecode_print_str(const mp_print_t *print, const byte *ip_start, const byte *ip, struct _mp_raw_code_t *const *child_table, const mp_module_constants_t *cm); #define mp_bytecode_print_inst(print, code, x_table) mp_bytecode_print2(print, code, 1, x_table) diff --git a/py/binary.c b/py/binary.c index d80d8e6e583aa..75dfc19925fec 100644 --- a/py/binary.c +++ b/py/binary.c @@ -79,10 +79,15 @@ size_t mp_binary_get_size(char struct_type, char val_type, size_t *palign) { size = sizeof(void *); break; #endif + case 'e': + size = 2; + break; case 'f': + // CIRCUITPY-CHANGE: compiler determines size size = sizeof(float); break; case 'd': + // CIRCUITPY-CHANGE: compiler determines size size = sizeof(double); break; } @@ -132,6 +137,10 @@ size_t mp_binary_get_size(char struct_type, char val_type, size_t *palign) { size = sizeof(void *); break; #endif + case 'e': + align = 2; + size = 2; + break; case 'f': align = alignof(float); size = sizeof(float); @@ -154,6 +163,99 @@ size_t mp_binary_get_size(char struct_type, char val_type, size_t *palign) { return size; } +#if MICROPY_PY_BUILTINS_FLOAT && MICROPY_FLOAT_USE_NATIVE_FLT16 + +static inline float mp_decode_half_float(uint16_t hf) { + union { + uint16_t i; + _Float16 f; + } fpu = { .i = hf }; + return fpu.f; +} + +static inline uint16_t mp_encode_half_float(float x) { + union { + uint16_t i; + _Float16 f; + } fp_sp = { .f = (_Float16)x }; + return fp_sp.i; +} + +#elif MICROPY_PY_BUILTINS_FLOAT + +static float mp_decode_half_float(uint16_t hf) { + union { + uint32_t i; + float f; + } fpu; + + uint16_t m = hf & 0x3ff; + int e = (hf >> 10) & 0x1f; + if (e == 0x1f) { + // Half-float is infinity. + e = 0xff; + } else if (e) { + // Half-float is normal. + e += 127 - 15; + } else if (m) { + // Half-float is subnormal, make it normal. + e = 127 - 15; + while (!(m & 0x400)) { + m <<= 1; + --e; + } + m -= 0x400; + ++e; + } + + fpu.i = ((hf & 0x8000) << 16) | (e << 23) | (m << 13); + return fpu.f; +} + +static uint16_t mp_encode_half_float(float x) { + union { + uint32_t i; + float f; + } fpu = { .f = x }; + + uint16_t m = (fpu.i >> 13) & 0x3ff; + if (fpu.i & (1 << 12)) { + // Round up. + ++m; + } + int e = (fpu.i >> 23) & 0xff; + + if (e == 0xff) { + // Infinity. + e = 0x1f; + } else if (e != 0) { + e -= 127 - 15; + if (e < 0) { + // Underflow: denormalized, or zero. + if (e >= -11) { + m = (m | 0x400) >> -e; + if (m & 1) { + m = (m >> 1) + 1; + } else { + m >>= 1; + } + } else { + m = 0; + } + e = 0; + } else if (e > 0x3f) { + // Overflow: infinity. + e = 0x1f; + m = 0; + } + } + + uint16_t bits = ((fpu.i >> 16) & 0x8000) | (e << 10) | m; + return bits; +} + +#endif + mp_obj_t mp_binary_get_val_array(char typecode, void *p, size_t index) { mp_int_t val = 0; switch (typecode) { @@ -257,6 +359,8 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte *p_base, byte * return mp_obj_new_str(s_val, strlen(s_val)); #endif #if MICROPY_PY_BUILTINS_FLOAT + } else if (val_type == 'e') { + return mp_obj_new_float_from_f(mp_decode_half_float(val)); } else if (val_type == 'f') { union { uint32_t i; @@ -329,6 +433,9 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p break; #endif #if MICROPY_PY_BUILTINS_FLOAT + case 'e': + val = mp_encode_half_float(mp_obj_get_float_to_f(val_in)); + break; case 'f': { union { uint32_t i; @@ -367,6 +474,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p return; } #endif + // CIRCUITPY-CHANGE: add overflow checks { val = mp_obj_get_int(val_in); // Small int checking is separate, to be fast. @@ -418,6 +526,7 @@ void mp_binary_set_val_array(char typecode, void *p, size_t index, mp_obj_t val_ return; } #endif + // CIRCUITPY-CHANGE: add overflow checks mp_int_t val = mp_obj_get_int(val_in); // Small int checking is separate, to be fast. mp_small_int_buffer_overflow_check(val, size, signed_type); diff --git a/py/builtinevex.c b/py/builtinevex.c index 73fca5d39bf52..e25cbd4d08502 100644 --- a/py/builtinevex.c +++ b/py/builtinevex.c @@ -38,13 +38,13 @@ typedef struct _mp_obj_code_t { mp_obj_t module_fun; } mp_obj_code_t; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_code, MP_QSTR_code, MP_TYPE_FLAG_NONE ); -STATIC mp_obj_t code_execute(mp_obj_code_t *self, mp_obj_dict_t *globals, mp_obj_dict_t *locals) { +static mp_obj_t code_execute(mp_obj_code_t *self, mp_obj_dict_t *globals, mp_obj_dict_t *locals) { // save context nlr_jump_callback_node_globals_locals_t ctx; ctx.globals = mp_globals_get(); @@ -57,9 +57,13 @@ STATIC mp_obj_t code_execute(mp_obj_code_t *self, mp_obj_dict_t *globals, mp_obj // set exception handler to restore context if an exception is raised nlr_push_jump_callback(&ctx.callback, mp_globals_locals_set_from_nlr_jump_callback); - // a bit of a hack: fun_bc will re-set globals, so need to make sure it's - // the correct one - if (mp_obj_is_type(self->module_fun, &mp_type_fun_bc)) { + // The call to mp_parse_compile_execute() in mp_builtin_compile() below passes + // NULL for the globals, so repopulate that entry now with the correct globals. + if (mp_obj_is_type(self->module_fun, &mp_type_fun_bc) + #if MICROPY_EMIT_NATIVE + || mp_obj_is_type(self->module_fun, &mp_type_fun_native) + #endif + ) { mp_obj_fun_bc_t *fun_bc = MP_OBJ_TO_PTR(self->module_fun); ((mp_module_context_t *)fun_bc->context)->module.globals = globals; } @@ -74,7 +78,7 @@ STATIC mp_obj_t code_execute(mp_obj_code_t *self, mp_obj_dict_t *globals, mp_obj return ret; } -STATIC mp_obj_t mp_builtin_compile(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_compile(size_t n_args, const mp_obj_t *args) { (void)n_args; // get the source @@ -114,7 +118,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_compile_obj, 3, 6, mp_builtin_com #if MICROPY_PY_BUILTINS_EVAL_EXEC -STATIC mp_obj_t eval_exec_helper(size_t n_args, const mp_obj_t *args, mp_parse_input_kind_t parse_input_kind) { +static mp_obj_t eval_exec_helper(size_t n_args, const mp_obj_t *args, mp_parse_input_kind_t parse_input_kind) { // work out the context mp_obj_dict_t *globals = mp_globals_get(); mp_obj_dict_t *locals = mp_locals_get(); @@ -154,12 +158,12 @@ STATIC mp_obj_t eval_exec_helper(size_t n_args, const mp_obj_t *args, mp_parse_i return mp_parse_compile_execute(lex, parse_input_kind, globals, locals); } -STATIC mp_obj_t mp_builtin_eval(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_eval(size_t n_args, const mp_obj_t *args) { return eval_exec_helper(n_args, args, MP_PARSE_EVAL_INPUT); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_eval_obj, 1, 3, mp_builtin_eval); -STATIC mp_obj_t mp_builtin_exec(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_exec(size_t n_args, const mp_obj_t *args) { return eval_exec_helper(n_args, args, MP_PARSE_FILE_INPUT); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_exec_obj, 1, 3, mp_builtin_exec); @@ -167,7 +171,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_exec_obj, 1, 3, mp_builtin_exec); #endif // MICROPY_PY_BUILTINS_EVAL_EXEC #if MICROPY_PY_BUILTINS_EXECFILE -STATIC mp_obj_t mp_builtin_execfile(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_execfile(size_t n_args, const mp_obj_t *args) { // MP_PARSE_SINGLE_INPUT is used to indicate a file input return eval_exec_helper(n_args, args, MP_PARSE_SINGLE_INPUT); } diff --git a/py/builtinhelp.c b/py/builtinhelp.c index 7f145a9ea5961..d041d6915a63a 100644 --- a/py/builtinhelp.c +++ b/py/builtinhelp.c @@ -27,6 +27,7 @@ #include #include +// CIRCUITPY-CHANGE: more includes #include "genhdr/mpversion.h" #include "py/builtin.h" #include "py/mpconfig.h" @@ -49,7 +50,7 @@ const char mp_help_default_text[] = "For further help on a specific object, type help(obj)\n" ; -STATIC void mp_help_print_info_about_object(mp_obj_t name_o, mp_obj_t value) { +static void mp_help_print_info_about_object(mp_obj_t name_o, mp_obj_t value) { mp_print_str(MP_PYTHON_PRINTER, " "); mp_obj_print(name_o, PRINT_STR); mp_print_str(MP_PYTHON_PRINTER, " -- "); @@ -58,7 +59,7 @@ STATIC void mp_help_print_info_about_object(mp_obj_t name_o, mp_obj_t value) { } #if MICROPY_PY_BUILTINS_HELP_MODULES -STATIC void mp_help_add_from_map(mp_obj_t list, const mp_map_t *map) { +static void mp_help_add_from_map(mp_obj_t list, const mp_map_t *map) { for (size_t i = 0; i < map->alloc; i++) { if (mp_map_slot_is_filled(map, i)) { mp_obj_list_append(list, map->table[i].key); @@ -67,7 +68,7 @@ STATIC void mp_help_add_from_map(mp_obj_t list, const mp_map_t *map) { } #if MICROPY_MODULE_FROZEN -STATIC void mp_help_add_from_names(mp_obj_t list, const char *name) { +static void mp_help_add_from_names(mp_obj_t list, const char *name) { while (*name) { size_t len = strlen(name); // name should end in '.py' and we strip it off @@ -82,13 +83,14 @@ STATIC void mp_help_add_from_names(mp_obj_t list, const char *name) { extern const char mp_frozen_names[]; #endif -STATIC void mp_help_print_modules(void) { +static void mp_help_print_modules(void) { mp_obj_t list = mp_obj_new_list(0, NULL); mp_help_add_from_map(list, &mp_builtin_module_map); mp_help_add_from_map(list, &mp_builtin_extensible_module_map); #if MICROPY_MODULE_FROZEN + // CIRCUITPY-CHANGE: extern const char mp_frozen_names[] is at top level mp_help_add_from_names(list, mp_frozen_names); #endif @@ -129,7 +131,7 @@ STATIC void mp_help_print_modules(void) { } #endif -STATIC void mp_help_print_obj(const mp_obj_t obj) { +static void mp_help_print_obj(const mp_obj_t obj) { #if MICROPY_PY_BUILTINS_HELP_MODULES if (obj == MP_OBJ_NEW_QSTR(MP_QSTR_modules)) { mp_help_print_modules(); @@ -168,7 +170,7 @@ STATIC void mp_help_print_obj(const mp_obj_t obj) { } } -STATIC mp_obj_t mp_builtin_help(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_help(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { // CIRCUITPY-CHANGE: make translatable // print a general help message. Translate only works on single strings on one line. diff --git a/py/builtinimport.c b/py/builtinimport.c index 2e25c390a2092..17b3f11c4a001 100644 --- a/py/builtinimport.c +++ b/py/builtinimport.c @@ -59,16 +59,17 @@ // uses mp_vfs_import_stat) to also search frozen modules. Given an exact // path to a file or directory (e.g. "foo/bar", foo/bar.py" or "foo/bar.mpy"), // will return whether the path is a file, directory, or doesn't exist. -STATIC mp_import_stat_t stat_path(const char *path) { +static mp_import_stat_t stat_path(vstr_t *path) { + const char *str = vstr_null_terminated_str(path); #if MICROPY_MODULE_FROZEN // Only try and load as a frozen module if it starts with .frozen/. const int frozen_path_prefix_len = strlen(MP_FROZEN_PATH_PREFIX); - if (strncmp(path, MP_FROZEN_PATH_PREFIX, frozen_path_prefix_len) == 0) { + if (strncmp(str, MP_FROZEN_PATH_PREFIX, frozen_path_prefix_len) == 0) { // Just stat (which is the return value), don't get the data. - return mp_find_frozen_module(path + frozen_path_prefix_len, NULL, NULL); + return mp_find_frozen_module(str + frozen_path_prefix_len, NULL, NULL); } #endif - return mp_import_stat(path); + return mp_import_stat(str); } // Stat a given filesystem path to a .py file. If the file does not exist, @@ -76,8 +77,8 @@ STATIC mp_import_stat_t stat_path(const char *path) { // argument. This is the logic that makes .py files take precedent over .mpy // files. This uses stat_path above, rather than mp_import_stat directly, so // that the .frozen path prefix is handled. -STATIC mp_import_stat_t stat_file_py_or_mpy(vstr_t *path) { - mp_import_stat_t stat = stat_path(vstr_null_terminated_str(path)); +static mp_import_stat_t stat_file_py_or_mpy(vstr_t *path) { + mp_import_stat_t stat = stat_path(path); if (stat == MP_IMPORT_STAT_FILE) { return stat; } @@ -87,7 +88,7 @@ STATIC mp_import_stat_t stat_file_py_or_mpy(vstr_t *path) { // Note: There's no point doing this if it's a frozen path, but adding the check // would be extra code, and no harm letting mp_find_frozen_module fail instead. vstr_ins_byte(path, path->len - 2, 'm'); - stat = stat_path(vstr_null_terminated_str(path)); + stat = stat_path(path); if (stat == MP_IMPORT_STAT_FILE) { return stat; } @@ -100,8 +101,8 @@ STATIC mp_import_stat_t stat_file_py_or_mpy(vstr_t *path) { // or "foo/bar.(m)py" in either the filesystem or frozen modules. If the // result is a file, the path argument will be updated to include the file // extension. -STATIC mp_import_stat_t stat_module(vstr_t *path) { - mp_import_stat_t stat = stat_path(vstr_null_terminated_str(path)); +static mp_import_stat_t stat_module(vstr_t *path) { + mp_import_stat_t stat = stat_path(path); DEBUG_printf("stat %s: %d\n", vstr_str(path), stat); if (stat == MP_IMPORT_STAT_DIR) { return stat; @@ -115,7 +116,7 @@ STATIC mp_import_stat_t stat_module(vstr_t *path) { // Given a top-level module name, try and find it in each of the sys.path // entries. Note: On success, the dest argument will be updated to the matching // path (i.e. "/mod_name(.py)"). -STATIC mp_import_stat_t stat_top_level(qstr mod_name, vstr_t *dest) { +static mp_import_stat_t stat_top_level(qstr mod_name, vstr_t *dest) { DEBUG_printf("stat_top_level: '%s'\n", qstr_str(mod_name)); #if MICROPY_PY_SYS size_t path_num; @@ -153,7 +154,7 @@ STATIC mp_import_stat_t stat_top_level(qstr mod_name, vstr_t *dest) { } #if MICROPY_MODULE_FROZEN_STR || MICROPY_ENABLE_COMPILER -STATIC void do_load_from_lexer(mp_module_context_t *context, mp_lexer_t *lex) { +static void do_load_from_lexer(mp_module_context_t *context, mp_lexer_t *lex) { #if MICROPY_PY___FILE__ qstr source_name = lex->source_name; mp_store_attr(MP_OBJ_FROM_PTR(&context->module), MP_QSTR___file__, MP_OBJ_NEW_QSTR(source_name)); @@ -166,7 +167,7 @@ STATIC void do_load_from_lexer(mp_module_context_t *context, mp_lexer_t *lex) { #endif #if (MICROPY_HAS_FILE_READER && MICROPY_PERSISTENT_CODE_LOAD) || MICROPY_MODULE_FROZEN_MPY -STATIC void do_execute_raw_code(const mp_module_context_t *context, const mp_raw_code_t *rc, qstr source_name) { +static void do_execute_proto_fun(const mp_module_context_t *context, mp_proto_fun_t proto_fun, qstr source_name) { #if MICROPY_PY___FILE__ mp_store_attr(MP_OBJ_FROM_PTR(&context->module), MP_QSTR___file__, MP_OBJ_NEW_QSTR(source_name)); #else @@ -189,7 +190,7 @@ STATIC void do_execute_raw_code(const mp_module_context_t *context, const mp_raw nlr_push_jump_callback(&ctx.callback, mp_globals_locals_set_from_nlr_jump_callback); // make and execute the function - mp_obj_t module_fun = mp_make_function_from_raw_code(rc, context, NULL); + mp_obj_t module_fun = mp_make_function_from_proto_fun(proto_fun, context, NULL); mp_call_function_0(module_fun); // deregister exception handler and restore context @@ -197,7 +198,7 @@ STATIC void do_execute_raw_code(const mp_module_context_t *context, const mp_raw } #endif -STATIC void do_load(mp_module_context_t *module_obj, vstr_t *file) { +static void do_load(mp_module_context_t *module_obj, vstr_t *file) { #if MICROPY_MODULE_FROZEN || MICROPY_ENABLE_COMPILER || (MICROPY_PERSISTENT_CODE_LOAD && MICROPY_HAS_FILE_READER) const char *file_str = vstr_null_terminated_str(file); #endif @@ -231,7 +232,7 @@ STATIC void do_load(mp_module_context_t *module_obj, vstr_t *file) { #else qstr frozen_file_qstr = MP_QSTRnull; #endif - do_execute_raw_code(module_obj, frozen->rc, frozen_file_qstr); + do_execute_proto_fun(module_obj, frozen->proto_fun, frozen_file_qstr); return; } #endif @@ -248,7 +249,7 @@ STATIC void do_load(mp_module_context_t *module_obj, vstr_t *file) { mp_compiled_module_t cm; cm.context = module_obj; mp_raw_code_load_file(file_qstr, &cm); - do_execute_raw_code(cm.context, cm.rc, file_qstr); + do_execute_proto_fun(cm.context, cm.rc, file_qstr); return; } #endif @@ -269,7 +270,7 @@ STATIC void do_load(mp_module_context_t *module_obj, vstr_t *file) { // Convert a relative (to the current module) import, going up "level" levels, // into an absolute import. -STATIC void evaluate_relative_import(mp_int_t level, const char **module_name, size_t *module_name_len) { +static void evaluate_relative_import(mp_int_t level, const char **module_name, size_t *module_name_len) { // What we want to do here is to take the name of the current module, // remove trailing components, and concatenate the passed-in // module name. @@ -352,7 +353,7 @@ typedef struct _nlr_jump_callback_node_unregister_module_t { qstr name; } nlr_jump_callback_node_unregister_module_t; -STATIC void unregister_module_from_nlr_jump_callback(void *ctx_in) { +static void unregister_module_from_nlr_jump_callback(void *ctx_in) { nlr_jump_callback_node_unregister_module_t *ctx = ctx_in; mp_map_t *mp_loaded_modules_map = &MP_STATE_VM(mp_loaded_modules_dict).map; mp_map_lookup(mp_loaded_modules_map, MP_OBJ_NEW_QSTR(ctx->name), MP_MAP_LOOKUP_REMOVE_IF_FOUND); @@ -365,7 +366,7 @@ STATIC void unregister_module_from_nlr_jump_callback(void *ctx_in) { // attribute on it) (or MP_OBJ_NULL for top-level). // override_main: Whether to set the __name__ to "__main__" (and use __main__ // for the actual path). -STATIC mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name, mp_obj_t outer_module_obj, bool override_main) { +static mp_obj_t process_import_at_level(qstr full_mod_name, qstr level_mod_name, mp_obj_t outer_module_obj, bool override_main) { // Immediately return if the module at this level is already loaded. mp_map_elem_t *elem; diff --git a/py/circuitpy_mpconfig.h b/py/circuitpy_mpconfig.h index 648853d2f45f3..adb881ebac23a 100644 --- a/py/circuitpy_mpconfig.h +++ b/py/circuitpy_mpconfig.h @@ -43,6 +43,7 @@ extern void common_hal_mcu_enable_interrupts(void); // MicroPython-only options not used by CircuitPython, but present in various files // inherited from MicroPython, especially in extmod/ #define MICROPY_ENABLE_DYNRUNTIME (0) +#define MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE (0) #define MICROPY_PY_BLUETOOTH (0) #define MICROPY_PY_LWIP_SLIP (0) #define MICROPY_PY_OS_DUPTERM (0) @@ -142,6 +143,7 @@ extern void common_hal_mcu_enable_interrupts(void); #define MICROPY_PY_SYS (CIRCUITPY_SYS) #define MICROPY_PY_SYS_MAXSIZE (1) #define MICROPY_PY_SYS_STDFILES (1) +#define MICROPY_PY_UCTYPES (0) #define MICROPY_PY___FILE__ (1) #define MICROPY_QSTR_BYTES_IN_HASH (1) @@ -358,6 +360,11 @@ extern const struct _mp_obj_module_t nvm_module; #define ULAB_SUPPORTS_COMPLEX (0) #endif +// The random module is fairly large. +#ifndef ULAB_NUMPY_HAS_RANDOM_MODULE +#define ULAB_NUMPY_HAS_RANDOM_MODULE (0) +#endif + #if CIRCUITPY_ULAB // ulab requires reverse special methods #if defined(MICROPY_PY_REVERSE_SPECIAL_METHODS) && !MICROPY_PY_REVERSE_SPECIAL_METHODS diff --git a/py/compile.c b/py/compile.c index c73fa500469cc..085c342605d46 100644 --- a/py/compile.c +++ b/py/compile.c @@ -41,8 +41,6 @@ #if MICROPY_ENABLE_COMPILER -// TODO need to mangle __attr names - #define INVALID_LABEL (0xffff) typedef enum { @@ -92,7 +90,7 @@ typedef enum { #define NATIVE_EMITTER(f) emit_native_table[mp_dynamic_compiler.native_arch]->emit_##f #define NATIVE_EMITTER_TABLE (emit_native_table[mp_dynamic_compiler.native_arch]) -STATIC const emit_method_table_t *emit_native_table[] = { +static const emit_method_table_t *emit_native_table[] = { NULL, &emit_native_x86_method_table, &emit_native_x64_method_table, @@ -131,7 +129,7 @@ STATIC const emit_method_table_t *emit_native_table[] = { #define ASM_EMITTER(f) emit_asm_table[mp_dynamic_compiler.native_arch]->asm_##f #define ASM_EMITTER_TABLE emit_asm_table[mp_dynamic_compiler.native_arch] -STATIC const emit_inline_asm_method_table_t *emit_asm_table[] = { +static const emit_inline_asm_method_table_t *emit_asm_table[] = { NULL, NULL, NULL, @@ -198,11 +196,15 @@ typedef struct _compiler_t { mp_emit_common_t emit_common; } compiler_t; +#if MICROPY_COMP_ALLOW_TOP_LEVEL_AWAIT +bool mp_compile_allow_top_level_await = false; +#endif + /******************************************************************************/ // mp_emit_common_t helper functions // These are defined here so they can be inlined, to reduce code size. -STATIC void mp_emit_common_init(mp_emit_common_t *emit, qstr source_file) { +static void mp_emit_common_init(mp_emit_common_t *emit, qstr source_file) { #if MICROPY_EMIT_BYTECODE_USES_QSTR_TABLE mp_map_init(&emit->qstr_map, 1); @@ -213,7 +215,7 @@ STATIC void mp_emit_common_init(mp_emit_common_t *emit, qstr source_file) { mp_obj_list_init(&emit->const_obj_list, 0); } -STATIC void mp_emit_common_start_pass(mp_emit_common_t *emit, pass_kind_t pass) { +static void mp_emit_common_start_pass(mp_emit_common_t *emit, pass_kind_t pass) { emit->pass = pass; if (pass == MP_PASS_CODE_SIZE) { if (emit->ct_cur_child == 0) { @@ -225,7 +227,7 @@ STATIC void mp_emit_common_start_pass(mp_emit_common_t *emit, pass_kind_t pass) emit->ct_cur_child = 0; } -STATIC void mp_emit_common_populate_module_context(mp_emit_common_t *emit, qstr source_file, mp_module_context_t *context) { +static void mp_emit_common_populate_module_context(mp_emit_common_t *emit, qstr source_file, mp_module_context_t *context) { #if MICROPY_EMIT_BYTECODE_USES_QSTR_TABLE size_t qstr_map_used = emit->qstr_map.used; mp_module_context_alloc_tables(context, qstr_map_used, emit->const_obj_list.len); @@ -248,14 +250,14 @@ STATIC void mp_emit_common_populate_module_context(mp_emit_common_t *emit, qstr /******************************************************************************/ -STATIC void compile_error_set_line(compiler_t *comp, mp_parse_node_t pn) { +static void compile_error_set_line(compiler_t *comp, mp_parse_node_t pn) { // if the line of the error is unknown then try to update it from the pn if (comp->compile_error_line == 0 && MP_PARSE_NODE_IS_STRUCT(pn)) { comp->compile_error_line = ((mp_parse_node_struct_t *)pn)->source_line; } } -STATIC void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, mp_rom_error_text_t msg) { +static void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, mp_rom_error_text_t msg) { // only register the error if there has been no other error if (comp->compile_error == MP_OBJ_NULL) { comp->compile_error = mp_obj_new_exception_msg(&mp_type_SyntaxError, msg); @@ -263,17 +265,17 @@ STATIC void compile_syntax_error(compiler_t *comp, mp_parse_node_t pn, mp_rom_er } } -STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_arglist, bool is_method_call, int n_positional_extra); -STATIC void compile_comprehension(compiler_t *comp, mp_parse_node_struct_t *pns, scope_kind_t kind); -STATIC void compile_atom_brace_helper(compiler_t *comp, mp_parse_node_struct_t *pns, bool create_map); -STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn); +static void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_arglist, bool is_method_call, int n_positional_extra); +static void compile_comprehension(compiler_t *comp, mp_parse_node_struct_t *pns, scope_kind_t kind); +static void compile_atom_brace_helper(compiler_t *comp, mp_parse_node_struct_t *pns, bool create_map); +static void compile_node(compiler_t *comp, mp_parse_node_t pn); -STATIC uint comp_next_label(compiler_t *comp) { +static uint comp_next_label(compiler_t *comp) { return comp->next_label++; } #if MICROPY_EMIT_NATIVE -STATIC void reserve_labels_for_native(compiler_t *comp, int n) { +static void reserve_labels_for_native(compiler_t *comp, int n) { if (comp->scope_cur->emit_options != MP_EMIT_OPT_BYTECODE) { comp->next_label += n; } @@ -282,7 +284,7 @@ STATIC void reserve_labels_for_native(compiler_t *comp, int n) { #define reserve_labels_for_native(comp, n) #endif -STATIC void compile_increase_except_level(compiler_t *comp, uint label, int kind) { +static void compile_increase_except_level(compiler_t *comp, uint label, int kind) { EMIT_ARG(setup_block, label, kind); comp->cur_except_level += 1; if (comp->cur_except_level > comp->scope_cur->exc_stack_size) { @@ -290,14 +292,14 @@ STATIC void compile_increase_except_level(compiler_t *comp, uint label, int kind } } -STATIC void compile_decrease_except_level(compiler_t *comp) { +static void compile_decrease_except_level(compiler_t *comp) { assert(comp->cur_except_level > 0); comp->cur_except_level -= 1; EMIT(end_finally); reserve_labels_for_native(comp, 1); } -STATIC scope_t *scope_new_and_link(compiler_t *comp, scope_kind_t kind, mp_parse_node_t pn, uint emit_options) { +static scope_t *scope_new_and_link(compiler_t *comp, scope_kind_t kind, mp_parse_node_t pn, uint emit_options) { scope_t *scope = scope_new(kind, pn, emit_options); scope->parent = comp->scope_cur; scope->next = NULL; @@ -315,7 +317,7 @@ STATIC scope_t *scope_new_and_link(compiler_t *comp, scope_kind_t kind, mp_parse typedef void (*apply_list_fun_t)(compiler_t *comp, mp_parse_node_t pn); -STATIC void apply_to_single_or_list(compiler_t *comp, mp_parse_node_t pn, pn_kind_t pn_list_kind, apply_list_fun_t f) { +static void apply_to_single_or_list(compiler_t *comp, mp_parse_node_t pn, pn_kind_t pn_list_kind, apply_list_fun_t f) { if (MP_PARSE_NODE_IS_STRUCT_KIND(pn, pn_list_kind)) { mp_parse_node_struct_t *pns = (mp_parse_node_struct_t *)pn; int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); @@ -327,7 +329,7 @@ STATIC void apply_to_single_or_list(compiler_t *comp, mp_parse_node_t pn, pn_kin } } -STATIC void compile_generic_all_nodes(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_generic_all_nodes(compiler_t *comp, mp_parse_node_struct_t *pns) { int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); for (int i = 0; i < num_nodes; i++) { compile_node(comp, pns->nodes[i]); @@ -339,7 +341,7 @@ STATIC void compile_generic_all_nodes(compiler_t *comp, mp_parse_node_struct_t * } } -STATIC void compile_load_id(compiler_t *comp, qstr qst) { +static void compile_load_id(compiler_t *comp, qstr qst) { if (comp->pass == MP_PASS_SCOPE) { mp_emit_common_get_id_for_load(comp->scope_cur, qst); } else { @@ -351,7 +353,7 @@ STATIC void compile_load_id(compiler_t *comp, qstr qst) { } } -STATIC void compile_store_id(compiler_t *comp, qstr qst) { +static void compile_store_id(compiler_t *comp, qstr qst) { if (comp->pass == MP_PASS_SCOPE) { mp_emit_common_get_id_for_modification(comp->scope_cur, qst); } else { @@ -363,7 +365,7 @@ STATIC void compile_store_id(compiler_t *comp, qstr qst) { } } -STATIC void compile_delete_id(compiler_t *comp, qstr qst) { +static void compile_delete_id(compiler_t *comp, qstr qst) { if (comp->pass == MP_PASS_SCOPE) { mp_emit_common_get_id_for_modification(comp->scope_cur, qst); } else { @@ -375,7 +377,7 @@ STATIC void compile_delete_id(compiler_t *comp, qstr qst) { } } -STATIC void compile_generic_tuple(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_generic_tuple(compiler_t *comp, mp_parse_node_struct_t *pns) { // a simple tuple expression size_t num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); for (size_t i = 0; i < num_nodes; i++) { @@ -384,7 +386,7 @@ STATIC void compile_generic_tuple(compiler_t *comp, mp_parse_node_struct_t *pns) EMIT_ARG(build, num_nodes, MP_EMIT_BUILD_TUPLE); } -STATIC void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int label) { +static void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int label) { if (mp_parse_node_is_const_false(pn)) { if (jump_if == false) { EMIT_ARG(jump, label); @@ -432,9 +434,9 @@ STATIC void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int la } typedef enum { ASSIGN_STORE, ASSIGN_AUG_LOAD, ASSIGN_AUG_STORE } assign_kind_t; -STATIC void c_assign(compiler_t *comp, mp_parse_node_t pn, assign_kind_t kind); +static void c_assign(compiler_t *comp, mp_parse_node_t pn, assign_kind_t kind); -STATIC void c_assign_atom_expr(compiler_t *comp, mp_parse_node_struct_t *pns, assign_kind_t assign_kind) { +static void c_assign_atom_expr(compiler_t *comp, mp_parse_node_struct_t *pns, assign_kind_t assign_kind) { if (assign_kind != ASSIGN_AUG_STORE) { compile_node(comp, pns->nodes[0]); } @@ -483,7 +485,7 @@ STATIC void c_assign_atom_expr(compiler_t *comp, mp_parse_node_struct_t *pns, as compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("can't assign to expression")); } -STATIC void c_assign_tuple(compiler_t *comp, uint num_tail, mp_parse_node_t *nodes_tail) { +static void c_assign_tuple(compiler_t *comp, uint num_tail, mp_parse_node_t *nodes_tail) { // look for star expression uint have_star_index = -1; for (uint i = 0; i < num_tail; i++) { @@ -510,7 +512,7 @@ STATIC void c_assign_tuple(compiler_t *comp, uint num_tail, mp_parse_node_t *nod } // assigns top of stack to pn -STATIC void c_assign(compiler_t *comp, mp_parse_node_t pn, assign_kind_t assign_kind) { +static void c_assign(compiler_t *comp, mp_parse_node_t pn, assign_kind_t assign_kind) { assert(!MP_PARSE_NODE_IS_NULL(pn)); if (MP_PARSE_NODE_IS_LEAF(pn)) { if (MP_PARSE_NODE_IS_ID(pn)) { @@ -601,7 +603,7 @@ STATIC void c_assign(compiler_t *comp, mp_parse_node_t pn, assign_kind_t assign_ // if n_pos_defaults > 0 then there is a tuple on the stack with the positional defaults // if n_kw_defaults > 0 then there is a dictionary on the stack with the keyword defaults // if both exist, the tuple is above the dictionary (ie the first pop gets the tuple) -STATIC void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int n_pos_defaults, int n_kw_defaults) { +static void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int n_pos_defaults, int n_kw_defaults) { assert(n_pos_defaults >= 0); assert(n_kw_defaults >= 0); @@ -643,7 +645,7 @@ STATIC void close_over_variables_etc(compiler_t *comp, scope_t *this_scope, int } } -STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn) { +static void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn) { // For efficiency of the code below we extract the parse-node kind here int pn_kind; if (MP_PARSE_NODE_IS_ID(pn)) { @@ -734,7 +736,7 @@ STATIC void compile_funcdef_lambdef_param(compiler_t *comp, mp_parse_node_t pn) } } -STATIC void compile_funcdef_lambdef(compiler_t *comp, scope_t *scope, mp_parse_node_t pn_params, pn_kind_t pn_list_kind) { +static void compile_funcdef_lambdef(compiler_t *comp, scope_t *scope, mp_parse_node_t pn_params, pn_kind_t pn_list_kind) { // When we call compile_funcdef_lambdef_param below it can compile an arbitrary // expression for default arguments, which may contain a lambda. The lambda will // call here in a nested way, so we must save and restore the relevant state. @@ -770,7 +772,7 @@ STATIC void compile_funcdef_lambdef(compiler_t *comp, scope_t *scope, mp_parse_n // leaves function object on stack // returns function name -STATIC qstr compile_funcdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint emit_options) { +static qstr compile_funcdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint emit_options) { if (comp->pass == MP_PASS_SCOPE) { // create a new scope for this function scope_t *s = scope_new_and_link(comp, SCOPE_FUNCTION, (mp_parse_node_t)pns, emit_options); @@ -790,7 +792,7 @@ STATIC qstr compile_funcdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns // leaves class object on stack // returns class name -STATIC qstr compile_classdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint emit_options) { +static qstr compile_classdef_helper(compiler_t *comp, mp_parse_node_struct_t *pns, uint emit_options) { if (comp->pass == MP_PASS_SCOPE) { // create a new scope for this class scope_t *s = scope_new_and_link(comp, SCOPE_CLASS, (mp_parse_node_t)pns, emit_options); @@ -822,7 +824,7 @@ STATIC qstr compile_classdef_helper(compiler_t *comp, mp_parse_node_struct_t *pn } // returns true if it was a built-in decorator (even if the built-in had an error) -STATIC bool compile_built_in_decorator(compiler_t *comp, size_t name_len, mp_parse_node_t *name_nodes, uint *emit_options) { +static bool compile_built_in_decorator(compiler_t *comp, size_t name_len, mp_parse_node_t *name_nodes, uint *emit_options) { if (MP_PARSE_NODE_LEAF_ARG(name_nodes[0]) != MP_QSTR_micropython) { return false; } @@ -871,7 +873,7 @@ STATIC bool compile_built_in_decorator(compiler_t *comp, size_t name_len, mp_par return true; } -STATIC void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) { // get the list of decorators mp_parse_node_t *nodes; size_t n = mp_parse_node_extract_list(&pns->nodes[0], PN_decorators, &nodes); @@ -940,13 +942,13 @@ STATIC void compile_decorated(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_store_id(comp, body_name); } -STATIC void compile_funcdef(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_funcdef(compiler_t *comp, mp_parse_node_struct_t *pns) { qstr fname = compile_funcdef_helper(comp, pns, comp->scope_cur->emit_options); // store function object into function name compile_store_id(comp, fname); } -STATIC void c_del_stmt(compiler_t *comp, mp_parse_node_t pn) { +static void c_del_stmt(compiler_t *comp, mp_parse_node_t pn) { if (MP_PARSE_NODE_IS_ID(pn)) { compile_delete_id(comp, MP_PARSE_NODE_LEAF_ARG(pn)); } else if (MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_atom_expr_normal)) { @@ -1002,11 +1004,11 @@ STATIC void c_del_stmt(compiler_t *comp, mp_parse_node_t pn) { compile_syntax_error(comp, (mp_parse_node_t)pn, MP_ERROR_TEXT("can't delete expression")); } -STATIC void compile_del_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_del_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { apply_to_single_or_list(comp, pns->nodes[0], PN_exprlist, c_del_stmt); } -STATIC void compile_break_cont_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_break_cont_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { uint16_t label; if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_break_stmt) { label = comp->break_label; @@ -1020,7 +1022,7 @@ STATIC void compile_break_cont_stmt(compiler_t *comp, mp_parse_node_struct_t *pn EMIT_ARG(unwind_jump, label, comp->cur_except_level - comp->break_continue_except_level); } -STATIC void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { #if MICROPY_CPYTHON_COMPAT if (comp->scope_cur->kind != SCOPE_FUNCTION) { compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("'return' outside function")); @@ -1048,12 +1050,12 @@ STATIC void compile_return_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { EMIT(return_value); } -STATIC void compile_yield_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_yield_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_node(comp, pns->nodes[0]); EMIT(pop_top); } -STATIC void compile_raise_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_raise_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) { // raise EMIT_ARG(raise_varargs, 0); @@ -1073,7 +1075,7 @@ STATIC void compile_raise_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // q_base holds the base of the name // eg a -> q_base=a // a.b.c -> q_base=a -STATIC void do_import_name(compiler_t *comp, mp_parse_node_t pn, qstr *q_base) { +static void do_import_name(compiler_t *comp, mp_parse_node_t pn, qstr *q_base) { bool is_as = false; if (MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_dotted_as_name)) { mp_parse_node_struct_t *pns = (mp_parse_node_struct_t *)pn; @@ -1134,7 +1136,7 @@ STATIC void do_import_name(compiler_t *comp, mp_parse_node_t pn, qstr *q_base) { } } -STATIC void compile_dotted_as_name(compiler_t *comp, mp_parse_node_t pn) { +static void compile_dotted_as_name(compiler_t *comp, mp_parse_node_t pn) { EMIT_ARG(load_const_small_int, 0); // level 0 import EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE); // not importing from anything qstr q_base; @@ -1142,11 +1144,11 @@ STATIC void compile_dotted_as_name(compiler_t *comp, mp_parse_node_t pn) { compile_store_id(comp, q_base); } -STATIC void compile_import_name(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_import_name(compiler_t *comp, mp_parse_node_struct_t *pns) { apply_to_single_or_list(comp, pns->nodes[0], PN_dotted_as_names, compile_dotted_as_name); } -STATIC void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) { mp_parse_node_t pn_import_source = pns->nodes[0]; // extract the preceding .'s (if any) for a relative import, to compute the import level @@ -1234,7 +1236,7 @@ STATIC void compile_import_from(compiler_t *comp, mp_parse_node_struct_t *pns) { } } -STATIC void compile_declare_global(compiler_t *comp, mp_parse_node_t pn, id_info_t *id_info) { +static void compile_declare_global(compiler_t *comp, mp_parse_node_t pn, id_info_t *id_info) { if (id_info->kind != ID_INFO_KIND_UNDECIDED && id_info->kind != ID_INFO_KIND_GLOBAL_EXPLICIT) { compile_syntax_error(comp, pn, MP_ERROR_TEXT("identifier redefined as global")); return; @@ -1248,7 +1250,7 @@ STATIC void compile_declare_global(compiler_t *comp, mp_parse_node_t pn, id_info } } -STATIC void compile_declare_nonlocal(compiler_t *comp, mp_parse_node_t pn, id_info_t *id_info) { +static void compile_declare_nonlocal(compiler_t *comp, mp_parse_node_t pn, id_info_t *id_info) { if (id_info->kind == ID_INFO_KIND_UNDECIDED) { id_info->kind = ID_INFO_KIND_GLOBAL_IMPLICIT; scope_check_to_close_over(comp->scope_cur, id_info); @@ -1260,7 +1262,7 @@ STATIC void compile_declare_nonlocal(compiler_t *comp, mp_parse_node_t pn, id_in } } -STATIC void compile_declare_global_or_nonlocal(compiler_t *comp, mp_parse_node_t pn, id_info_t *id_info, bool is_global) { +static void compile_declare_global_or_nonlocal(compiler_t *comp, mp_parse_node_t pn, id_info_t *id_info, bool is_global) { if (is_global) { compile_declare_global(comp, pn, id_info); } else { @@ -1268,7 +1270,7 @@ STATIC void compile_declare_global_or_nonlocal(compiler_t *comp, mp_parse_node_t } } -STATIC void compile_global_nonlocal_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_global_nonlocal_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { if (comp->pass == MP_PASS_SCOPE) { bool is_global = MP_PARSE_NODE_STRUCT_KIND(pns) == PN_global_stmt; @@ -1287,7 +1289,7 @@ STATIC void compile_global_nonlocal_stmt(compiler_t *comp, mp_parse_node_struct_ } } -STATIC void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // with optimisations enabled we don't compile assertions if (MP_STATE_VM(mp_optimise_value) != 0) { return; @@ -1305,7 +1307,7 @@ STATIC void compile_assert_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { EMIT_ARG(label_assign, l_end); } -STATIC void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { uint l_end = comp_next_label(comp); // optimisation: don't emit anything when "if False" @@ -1375,7 +1377,7 @@ STATIC void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { comp->continue_label = old_continue_label; \ comp->break_continue_except_level = old_break_continue_except_level; -STATIC void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { START_BREAK_CONTINUE_BLOCK if (!mp_parse_node_is_const_false(pns->nodes[0])) { // optimisation: don't emit anything for "while False" @@ -1413,7 +1415,7 @@ STATIC void compile_while_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // If is a small-int, then the stack during the for-loop contains just // the current value of . Otherwise, the stack contains then the // current value of . -STATIC void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t pn_var, mp_parse_node_t pn_start, mp_parse_node_t pn_end, mp_parse_node_t pn_step, mp_parse_node_t pn_body, mp_parse_node_t pn_else) { +static void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t pn_var, mp_parse_node_t pn_start, mp_parse_node_t pn_end, mp_parse_node_t pn_step, mp_parse_node_t pn_body, mp_parse_node_t pn_else) { START_BREAK_CONTINUE_BLOCK uint top_label = comp_next_label(comp); @@ -1495,7 +1497,7 @@ STATIC void compile_for_stmt_optimised_range(compiler_t *comp, mp_parse_node_t p } } -STATIC void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // this bit optimises: for in range(...), turning it into an explicitly incremented variable // this is actually slower, but uses no heap memory // for viper it will be much, much faster @@ -1575,7 +1577,7 @@ STATIC void compile_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { EMIT_ARG(label_assign, break_label); } -STATIC void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except, mp_parse_node_t *pn_excepts, mp_parse_node_t pn_else) { +static void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_except, mp_parse_node_t *pn_excepts, mp_parse_node_t pn_else) { // setup code uint l1 = comp_next_label(comp); uint success_label = comp_next_label(comp); @@ -1672,7 +1674,7 @@ STATIC void compile_try_except(compiler_t *comp, mp_parse_node_t pn_body, int n_ EMIT_ARG(label_assign, l2); } -STATIC void compile_try_finally(compiler_t *comp, mp_parse_node_t pn_body, int n_except, mp_parse_node_t *pn_except, mp_parse_node_t pn_else, mp_parse_node_t pn_finally) { +static void compile_try_finally(compiler_t *comp, mp_parse_node_t pn_body, int n_except, mp_parse_node_t *pn_except, mp_parse_node_t pn_else, mp_parse_node_t pn_finally) { uint l_finally_block = comp_next_label(comp); compile_increase_except_level(comp, l_finally_block, MP_EMIT_SETUP_BLOCK_FINALLY); @@ -1701,7 +1703,7 @@ STATIC void compile_try_finally(compiler_t *comp, mp_parse_node_t pn_body, int n compile_decrease_except_level(comp); } -STATIC void compile_try_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_try_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { assert(MP_PARSE_NODE_IS_STRUCT(pns->nodes[1])); // should be { mp_parse_node_struct_t *pns2 = (mp_parse_node_struct_t *)pns->nodes[1]; @@ -1728,7 +1730,7 @@ STATIC void compile_try_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { } } -STATIC void compile_with_stmt_helper(compiler_t *comp, size_t n, mp_parse_node_t *nodes, mp_parse_node_t body) { +static void compile_with_stmt_helper(compiler_t *comp, size_t n, mp_parse_node_t *nodes, mp_parse_node_t body) { if (n == 0) { // no more pre-bits, compile the body of the with compile_node(comp, body); @@ -1755,7 +1757,7 @@ STATIC void compile_with_stmt_helper(compiler_t *comp, size_t n, mp_parse_node_t } } -STATIC void compile_with_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_with_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // get the nodes for the pre-bit of the with (the a as b, c as d, ... bit) mp_parse_node_t *nodes; size_t n = mp_parse_node_extract_list(&pns->nodes[0], PN_with_stmt_list, &nodes); @@ -1765,7 +1767,7 @@ STATIC void compile_with_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_with_stmt_helper(comp, n, nodes, pns->nodes[1]); } -STATIC void compile_yield_from(compiler_t *comp) { +static void compile_yield_from(compiler_t *comp) { EMIT_ARG(get_iter, false); EMIT_ARG(load_const_tok, MP_TOKEN_KW_NONE); EMIT_ARG(yield, MP_EMIT_YIELD_FROM); @@ -1773,13 +1775,13 @@ STATIC void compile_yield_from(compiler_t *comp) { } #if MICROPY_PY_ASYNC_AWAIT -STATIC void compile_await_object_method(compiler_t *comp, qstr method) { +static void compile_await_object_method(compiler_t *comp, qstr method) { EMIT_ARG(load_method, method, false); EMIT_ARG(call_method, 0, 0, 0); compile_yield_from(comp); } -STATIC void compile_async_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_async_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // Allocate labels. uint while_else_label = comp_next_label(comp); uint try_exception_label = comp_next_label(comp); @@ -1846,7 +1848,7 @@ STATIC void compile_async_for_stmt(compiler_t *comp, mp_parse_node_struct_t *pns // Stack: (...) } -STATIC void compile_async_with_stmt_helper(compiler_t *comp, size_t n, mp_parse_node_t *nodes, mp_parse_node_t body) { +static void compile_async_with_stmt_helper(compiler_t *comp, size_t n, mp_parse_node_t *nodes, mp_parse_node_t body) { if (n == 0) { // no more pre-bits, compile the body of the with compile_node(comp, body); @@ -1958,7 +1960,7 @@ STATIC void compile_async_with_stmt_helper(compiler_t *comp, size_t n, mp_parse_ } } -STATIC void compile_async_with_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_async_with_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { // get the nodes for the pre-bit of the with (the a as b, c as d, ... bit) mp_parse_node_t *nodes; size_t n = mp_parse_node_extract_list(&pns->nodes[0], PN_with_stmt_list, &nodes); @@ -1968,7 +1970,7 @@ STATIC void compile_async_with_stmt(compiler_t *comp, mp_parse_node_struct_t *pn compile_async_with_stmt_helper(comp, n, nodes, pns->nodes[1]); } -STATIC void compile_async_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_async_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { assert(MP_PARSE_NODE_IS_STRUCT(pns->nodes[0])); mp_parse_node_struct_t *pns0 = (mp_parse_node_struct_t *)pns->nodes[0]; if (MP_PARSE_NODE_STRUCT_KIND(pns0) == PN_funcdef) { @@ -1998,7 +2000,7 @@ STATIC void compile_async_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { } #endif -STATIC void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { mp_parse_node_t pn_rhs = pns->nodes[1]; if (MP_PARSE_NODE_IS_NULL(pn_rhs)) { if (comp->is_repl && comp->scope_cur->kind == SCOPE_MODULE) { @@ -2113,7 +2115,7 @@ STATIC void compile_expr_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) { } } -STATIC void compile_test_if_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_test_if_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { assert(MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[1], PN_test_if_else)); mp_parse_node_struct_t *pns_test_if_else = (mp_parse_node_struct_t *)pns->nodes[1]; @@ -2128,7 +2130,7 @@ STATIC void compile_test_if_expr(compiler_t *comp, mp_parse_node_struct_t *pns) EMIT_ARG(label_assign, l_end); } -STATIC void compile_lambdef(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_lambdef(compiler_t *comp, mp_parse_node_struct_t *pns) { if (comp->pass == MP_PASS_SCOPE) { // create a new scope for this lambda scope_t *s = scope_new_and_link(comp, SCOPE_LAMBDA, (mp_parse_node_t)pns, comp->scope_cur->emit_options); @@ -2144,7 +2146,7 @@ STATIC void compile_lambdef(compiler_t *comp, mp_parse_node_struct_t *pns) { } #if MICROPY_PY_ASSIGN_EXPR -STATIC void compile_namedexpr_helper(compiler_t *comp, mp_parse_node_t pn_name, mp_parse_node_t pn_expr) { +static void compile_namedexpr_helper(compiler_t *comp, mp_parse_node_t pn_name, mp_parse_node_t pn_expr) { if (!MP_PARSE_NODE_IS_ID(pn_name)) { compile_syntax_error(comp, (mp_parse_node_t)pn_name, MP_ERROR_TEXT("can't assign to expression")); } @@ -2176,12 +2178,12 @@ STATIC void compile_namedexpr_helper(compiler_t *comp, mp_parse_node_t pn_name, compile_store_id(comp, target); } -STATIC void compile_namedexpr(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_namedexpr(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_namedexpr_helper(comp, pns->nodes[0], pns->nodes[1]); } #endif -STATIC void compile_or_and_test(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_or_and_test(compiler_t *comp, mp_parse_node_struct_t *pns) { bool cond = MP_PARSE_NODE_STRUCT_KIND(pns) == PN_or_test; uint l_end = comp_next_label(comp); int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); @@ -2194,12 +2196,12 @@ STATIC void compile_or_and_test(compiler_t *comp, mp_parse_node_struct_t *pns) { EMIT_ARG(label_assign, l_end); } -STATIC void compile_not_test_2(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_not_test_2(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_node(comp, pns->nodes[0]); EMIT_ARG(unary_op, MP_UNARY_OP_NOT); } -STATIC void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) { int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); compile_node(comp, pns->nodes[0]); bool multi = (num_nodes > 3); @@ -2252,11 +2254,11 @@ STATIC void compile_comparison(compiler_t *comp, mp_parse_node_struct_t *pns) { } } -STATIC void compile_star_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_star_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("*x must be assignment target")); } -STATIC void compile_binary_op(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_binary_op(compiler_t *comp, mp_parse_node_struct_t *pns) { MP_STATIC_ASSERT(MP_BINARY_OP_OR + PN_xor_expr - PN_expr == MP_BINARY_OP_XOR); MP_STATIC_ASSERT(MP_BINARY_OP_OR + PN_and_expr - PN_expr == MP_BINARY_OP_AND); mp_binary_op_t binary_op = MP_BINARY_OP_OR + MP_PARSE_NODE_STRUCT_KIND(pns) - PN_expr; @@ -2268,7 +2270,7 @@ STATIC void compile_binary_op(compiler_t *comp, mp_parse_node_struct_t *pns) { } } -STATIC void compile_term(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_term(compiler_t *comp, mp_parse_node_struct_t *pns) { int num_nodes = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); compile_node(comp, pns->nodes[0]); for (int i = 1; i + 1 < num_nodes; i += 2) { @@ -2279,7 +2281,7 @@ STATIC void compile_term(compiler_t *comp, mp_parse_node_struct_t *pns) { } } -STATIC void compile_factor_2(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_factor_2(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_node(comp, pns->nodes[1]); mp_token_kind_t tok = MP_PARSE_NODE_LEAF_ARG(pns->nodes[0]); mp_unary_op_t op; @@ -2292,7 +2294,7 @@ STATIC void compile_factor_2(compiler_t *comp, mp_parse_node_struct_t *pns) { EMIT_ARG(unary_op, op); } -STATIC void compile_atom_expr_normal(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_atom_expr_normal(compiler_t *comp, mp_parse_node_struct_t *pns) { // compile the subject of the expression compile_node(comp, pns->nodes[0]); @@ -2388,12 +2390,12 @@ STATIC void compile_atom_expr_normal(compiler_t *comp, mp_parse_node_struct_t *p } } -STATIC void compile_power(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_power(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_generic_all_nodes(comp, pns); // 2 nodes, arguments of power EMIT_ARG(binary_op, MP_BINARY_OP_POWER); } -STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_arglist, bool is_method_call, int n_positional_extra) { +static void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_arglist, bool is_method_call, int n_positional_extra) { // function to call is on top of stack // get the list of arguments @@ -2488,7 +2490,7 @@ STATIC void compile_trailer_paren_helper(compiler_t *comp, mp_parse_node_t pn_ar } // pns needs to have 2 nodes, first is lhs of comprehension, second is PN_comp_for node -STATIC void compile_comprehension(compiler_t *comp, mp_parse_node_struct_t *pns, scope_kind_t kind) { +static void compile_comprehension(compiler_t *comp, mp_parse_node_struct_t *pns, scope_kind_t kind) { assert(MP_PARSE_NODE_STRUCT_NUM_NODES(pns) == 2); assert(MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[1], PN_comp_for)); mp_parse_node_struct_t *pns_comp_for = (mp_parse_node_struct_t *)pns->nodes[1]; @@ -2513,7 +2515,7 @@ STATIC void compile_comprehension(compiler_t *comp, mp_parse_node_struct_t *pns, EMIT_ARG(call_function, 1, 0, 0); } -STATIC void compile_atom_paren(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_atom_paren(compiler_t *comp, mp_parse_node_struct_t *pns) { if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) { // an empty tuple EMIT_ARG(build, 0, MP_EMIT_BUILD_TUPLE); @@ -2530,7 +2532,7 @@ STATIC void compile_atom_paren(compiler_t *comp, mp_parse_node_struct_t *pns) { } } -STATIC void compile_atom_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_atom_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) { if (MP_PARSE_NODE_IS_NULL(pns->nodes[0])) { // empty list EMIT_ARG(build, 0, MP_EMIT_BUILD_LIST); @@ -2551,7 +2553,7 @@ STATIC void compile_atom_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) } } -STATIC void compile_atom_brace_helper(compiler_t *comp, mp_parse_node_struct_t *pns, bool create_map) { +static void compile_atom_brace_helper(compiler_t *comp, mp_parse_node_struct_t *pns, bool create_map) { mp_parse_node_t pn = pns->nodes[0]; if (MP_PARSE_NODE_IS_NULL(pn)) { // empty dict @@ -2653,27 +2655,27 @@ STATIC void compile_atom_brace_helper(compiler_t *comp, mp_parse_node_struct_t * } } -STATIC void compile_atom_brace(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_atom_brace(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_atom_brace_helper(comp, pns, true); } -STATIC void compile_trailer_paren(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_trailer_paren(compiler_t *comp, mp_parse_node_struct_t *pns) { compile_trailer_paren_helper(comp, pns->nodes[0], false, 0); } -STATIC void compile_trailer_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_trailer_bracket(compiler_t *comp, mp_parse_node_struct_t *pns) { // object who's index we want is on top of stack compile_node(comp, pns->nodes[0]); // the index EMIT_ARG(subscr, MP_EMIT_SUBSCR_LOAD); } -STATIC void compile_trailer_period(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_trailer_period(compiler_t *comp, mp_parse_node_struct_t *pns) { // object who's attribute we want is on top of stack EMIT_ARG(attr, MP_PARSE_NODE_LEAF_ARG(pns->nodes[0]), MP_EMIT_ATTR_LOAD); // attribute to get } #if MICROPY_PY_BUILTINS_SLICE -STATIC void compile_subscript(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_subscript(compiler_t *comp, mp_parse_node_struct_t *pns) { if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_subscript_2) { compile_node(comp, pns->nodes[0]); // start of slice assert(MP_PARSE_NODE_IS_STRUCT(pns->nodes[1])); // should always be @@ -2728,19 +2730,19 @@ STATIC void compile_subscript(compiler_t *comp, mp_parse_node_struct_t *pns) { } #endif // MICROPY_PY_BUILTINS_SLICE -STATIC void compile_dictorsetmaker_item(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_dictorsetmaker_item(compiler_t *comp, mp_parse_node_struct_t *pns) { // if this is called then we are compiling a dict key:value pair compile_node(comp, pns->nodes[1]); // value compile_node(comp, pns->nodes[0]); // key } -STATIC void compile_classdef(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_classdef(compiler_t *comp, mp_parse_node_struct_t *pns) { qstr cname = compile_classdef_helper(comp, pns, comp->scope_cur->emit_options); // store class object into class name compile_store_id(comp, cname); } -STATIC void compile_yield_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_yield_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { if (comp->scope_cur->kind != SCOPE_FUNCTION && comp->scope_cur->kind != SCOPE_LAMBDA) { compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("'yield' outside function")); return; @@ -2751,6 +2753,7 @@ STATIC void compile_yield_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { reserve_labels_for_native(comp, 1); } else if (MP_PARSE_NODE_IS_STRUCT_KIND(pns->nodes[0], PN_yield_arg_from)) { pns = (mp_parse_node_struct_t *)pns->nodes[0]; + // CIRCUITPY-CHANGE: more error checking #if MICROPY_PY_ASYNC_AWAIT if (comp->scope_cur->scope_flags & MP_SCOPE_FLAG_ASYNC) { compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("'yield from' inside async function")); @@ -2767,10 +2770,15 @@ STATIC void compile_yield_expr(compiler_t *comp, mp_parse_node_struct_t *pns) { } #if MICROPY_PY_ASYNC_AWAIT -STATIC void compile_atom_expr_await(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_atom_expr_await(compiler_t *comp, mp_parse_node_struct_t *pns) { if (comp->scope_cur->kind != SCOPE_FUNCTION && comp->scope_cur->kind != SCOPE_LAMBDA) { - compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("'await' outside function")); - return; + #if MICROPY_COMP_ALLOW_TOP_LEVEL_AWAIT + if (!mp_compile_allow_top_level_await) + #endif + { + compile_syntax_error(comp, (mp_parse_node_t)pns, MP_ERROR_TEXT("'await' outside function")); + return; + } } compile_atom_expr_normal(comp, pns); @@ -2786,16 +2794,16 @@ STATIC void compile_atom_expr_await(compiler_t *comp, mp_parse_node_struct_t *pn } #endif -STATIC mp_obj_t get_const_object(mp_parse_node_struct_t *pns) { +static mp_obj_t get_const_object(mp_parse_node_struct_t *pns) { return mp_parse_node_extract_const_object(pns); } -STATIC void compile_const_object(compiler_t *comp, mp_parse_node_struct_t *pns) { +static void compile_const_object(compiler_t *comp, mp_parse_node_struct_t *pns) { EMIT_ARG(load_const_obj, get_const_object(pns)); } typedef void (*compile_function_t)(compiler_t *, mp_parse_node_struct_t *); -STATIC const compile_function_t compile_function[] = { +static const compile_function_t compile_function[] = { // only define rules with a compile function #define c(f) compile_##f #define DEF_RULE(rule, comp, kind, ...) comp, @@ -2807,7 +2815,7 @@ STATIC const compile_function_t compile_function[] = { compile_const_object, }; -STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn) { +static void compile_node(compiler_t *comp, mp_parse_node_t pn) { if (MP_PARSE_NODE_IS_NULL(pn)) { // pass } else if (MP_PARSE_NODE_IS_SMALL_INT(pn)) { @@ -2843,7 +2851,7 @@ STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn) { } #if MICROPY_EMIT_NATIVE -STATIC int compile_viper_type_annotation(compiler_t *comp, mp_parse_node_t pn_annotation) { +static int compile_viper_type_annotation(compiler_t *comp, mp_parse_node_t pn_annotation) { int native_type = MP_NATIVE_TYPE_OBJ; if (MP_PARSE_NODE_IS_NULL(pn_annotation)) { // No annotation, type defaults to object @@ -2861,7 +2869,7 @@ STATIC int compile_viper_type_annotation(compiler_t *comp, mp_parse_node_t pn_an } #endif -STATIC void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_kind_t pn_name, pn_kind_t pn_star, pn_kind_t pn_dbl_star) { +static void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn, pn_kind_t pn_name, pn_kind_t pn_star, pn_kind_t pn_dbl_star) { (void)pn_dbl_star; // check that **kw is last @@ -2948,15 +2956,15 @@ STATIC void compile_scope_func_lambda_param(compiler_t *comp, mp_parse_node_t pn } } -STATIC void compile_scope_func_param(compiler_t *comp, mp_parse_node_t pn) { +static void compile_scope_func_param(compiler_t *comp, mp_parse_node_t pn) { compile_scope_func_lambda_param(comp, pn, PN_typedargslist_name, PN_typedargslist_star, PN_typedargslist_dbl_star); } -STATIC void compile_scope_lambda_param(compiler_t *comp, mp_parse_node_t pn) { +static void compile_scope_lambda_param(compiler_t *comp, mp_parse_node_t pn) { compile_scope_func_lambda_param(comp, pn, PN_varargslist_name, PN_varargslist_star, PN_varargslist_dbl_star); } -STATIC void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_struct_t *pns_comp_for, mp_parse_node_t pn_inner_expr, int for_depth) { +static void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_struct_t *pns_comp_for, mp_parse_node_t pn_inner_expr, int for_depth) { uint l_top = comp_next_label(comp); uint l_end = comp_next_label(comp); EMIT_ARG(label_assign, l_top); @@ -2995,7 +3003,7 @@ STATIC void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_struct_t *pn EMIT(for_iter_end); } -STATIC void check_for_doc_string(compiler_t *comp, mp_parse_node_t pn) { +static void check_for_doc_string(compiler_t *comp, mp_parse_node_t pn) { #if MICROPY_ENABLE_DOC_STRING // see http://www.python.org/dev/peps/pep-0257/ @@ -3040,7 +3048,7 @@ STATIC void check_for_doc_string(compiler_t *comp, mp_parse_node_t pn) { #endif } -STATIC bool compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) { +static bool compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) { comp->pass = pass; comp->scope_cur = scope; comp->next_label = 0; @@ -3205,7 +3213,7 @@ STATIC bool compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) { #if MICROPY_EMIT_INLINE_ASM // requires 3 passes: SCOPE, CODE_SIZE, EMIT -STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind_t pass) { +static void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind_t pass) { comp->pass = pass; comp->scope_cur = scope; comp->next_label = 0; @@ -3380,7 +3388,7 @@ STATIC void compile_scope_inline_asm(compiler_t *comp, scope_t *scope, pass_kind } #endif -STATIC void scope_compute_things(scope_t *scope) { +static void scope_compute_things(scope_t *scope) { // in MicroPython we put the *x parameter after all other parameters (except **y) if (scope->scope_flags & MP_SCOPE_FLAG_VARARGS) { id_info_t *id_param = NULL; @@ -3474,7 +3482,7 @@ STATIC void scope_compute_things(scope_t *scope) { } #if !MICROPY_PERSISTENT_CODE_SAVE -STATIC +static #endif void mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_file, bool is_repl, mp_compiled_module_t *cm) { // put compiler state on the stack, it's relatively small @@ -3642,7 +3650,7 @@ void mp_compile_to_raw_code(mp_parse_tree_t *parse_tree, qstr source_file, bool for (scope_t *s = comp->scope_head; s != NULL; s = s->next) { mp_raw_code_t *rc = s->raw_code; if (rc->kind == MP_CODE_BYTECODE) { - mp_bytecode_print(&mp_plat_print, rc, &cm->context->constants); + mp_bytecode_print(&mp_plat_print, rc, s->raw_code_data_len, &cm->context->constants); } } } @@ -3684,7 +3692,7 @@ mp_obj_t mp_compile(mp_parse_tree_t *parse_tree, qstr source_file, bool is_repl) cm.context->module.globals = mp_globals_get(); mp_compile_to_raw_code(parse_tree, source_file, is_repl, &cm); // return function that executes the outer module - return mp_make_function_from_raw_code(cm.rc, cm.context, NULL); + return mp_make_function_from_proto_fun(cm.rc, cm.context, NULL); } #endif // MICROPY_ENABLE_COMPILER diff --git a/py/compile.h b/py/compile.h index 5e0fd8b31c4a8..f9970a521d644 100644 --- a/py/compile.h +++ b/py/compile.h @@ -30,6 +30,11 @@ #include "py/parse.h" #include "py/emitglue.h" +#if MICROPY_COMP_ALLOW_TOP_LEVEL_AWAIT +// set to `true` to allow top-level await expressions +extern bool mp_compile_allow_top_level_await; +#endif + // the compiler will raise an exception if an error occurred // the compiler will clear the parse tree before it returns // mp_globals_get() will be used for the context diff --git a/py/dynruntime.h b/py/dynruntime.h index d80ce10f577be..44f6d05ccb6f5 100644 --- a/py/dynruntime.h +++ b/py/dynruntime.h @@ -29,6 +29,7 @@ // This header file contains definitions to dynamically implement the static // MicroPython runtime API defined in py/obj.h and py/runtime.h. +#include "py/binary.h" #include "py/nativeglue.h" #include "py/objfun.h" #include "py/objstr.h" @@ -87,8 +88,10 @@ static inline void *m_realloc_dyn(void *ptr, size_t new_num_bytes) { #define mp_type_int (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_int))) #define mp_type_str (*mp_fun_table.type_str) #define mp_type_bytes (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_bytes))) +#define mp_type_bytearray (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_bytearray))) #define mp_type_tuple (*((mp_obj_base_t *)mp_const_empty_tuple)->type) #define mp_type_list (*mp_fun_table.type_list) +#define mp_type_Exception (*mp_fun_table.type_Exception) #define mp_type_EOFError (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_EOFError))) #define mp_type_IndexError (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_IndexError))) #define mp_type_KeyError (*(mp_obj_type_t *)(mp_load_global(MP_QSTR_KeyError))) @@ -187,10 +190,15 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type /******************************************************************************/ // General runtime functions +#define mp_binary_get_size(struct_type, val_type, palign) (mp_fun_table.binary_get_size((struct_type), (val_type), (palign))) +#define mp_binary_get_val_array(typecode, p, index) (mp_fun_table.binary_get_val_array((typecode), (p), (index))) +#define mp_binary_set_val_array(typecode, p, index, val_in) (mp_fun_table.binary_set_val_array((typecode), (p), (index), (val_in))) + #define mp_load_name(qst) (mp_fun_table.load_name((qst))) #define mp_load_global(qst) (mp_fun_table.load_global((qst))) #define mp_load_attr(base, attr) (mp_fun_table.load_attr((base), (attr))) #define mp_load_method(base, attr, dest) (mp_fun_table.load_method((base), (attr), (dest))) +#define mp_load_method_maybe(base, attr, dest) (mp_fun_table.load_method_maybe((base), (attr), (dest))) #define mp_load_super_method(attr, dest) (mp_fun_table.load_super_method((attr), (dest))) #define mp_store_name(qst, obj) (mp_fun_table.store_name((qst), (obj))) #define mp_store_global(qst, obj) (mp_fun_table.store_global((qst), (obj))) @@ -199,8 +207,8 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type #define mp_unary_op(op, obj) (mp_fun_table.unary_op((op), (obj))) #define mp_binary_op(op, lhs, rhs) (mp_fun_table.binary_op((op), (lhs), (rhs))) -#define mp_make_function_from_raw_code(rc, context, def_args) \ - (mp_fun_table.make_function_from_raw_code((rc), (context), (def_args))) +#define mp_make_function_from_proto_fun(rc, context, def_args) \ + (mp_fun_table.make_function_from_proto_fun((rc), (context), (def_args))) #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)) @@ -208,11 +216,21 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type #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_arg_parse_all(n_pos, pos, kws, n_allowed, allowed, out_vals) \ + (mp_fun_table.arg_parse_all((n_pos), (pos), (kws), (n_allowed), (allowed), (out_vals))) + +#define mp_arg_parse_all_kw_array(n_pos, n_kw, args, n_allowed, allowed, out_vals) \ + (mp_fun_table.arg_parse_all_kw_array((n_pos), (n_kw), (args), (n_allowed), (allowed), (out_vals))) + +// CIRCUITPY-CHANGE: .is_async #define MP_DYNRUNTIME_INIT_ENTRY \ mp_obj_t old_globals = mp_fun_table.swap_globals(self->context->module.globals); \ - mp_raw_code_t rc; \ + mp_raw_code_truncated_t rc; \ + rc.proto_fun_indicator[0] = MP_PROTO_FUN_INDICATOR_RAW_CODE_0; \ + rc.proto_fun_indicator[1] = MP_PROTO_FUN_INDICATOR_RAW_CODE_1; \ rc.kind = MP_CODE_NATIVE_VIPER; \ - rc.scope_flags = 0; \ + rc.is_generator = 0; \ + rc.is_async = 0; \ (void)rc; #define MP_DYNRUNTIME_INIT_EXIT \ @@ -220,7 +238,7 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type return mp_const_none; #define MP_DYNRUNTIME_MAKE_FUNCTION(f) \ - (mp_make_function_from_raw_code((rc.fun_data = (f), &rc), MP_OBJ_NULL, MP_OBJ_NULL)) + (mp_make_function_from_proto_fun((rc.fun_data = (f), (const mp_raw_code_t *)&rc), self->context, NULL)) #define mp_import_name(name, fromlist, level) \ (mp_fun_table.import_name((name), (fromlist), (level))) @@ -232,6 +250,10 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type /******************************************************************************/ // Exceptions +#define mp_obj_exception_make_new (MP_OBJ_TYPE_GET_SLOT(&mp_type_Exception, make_new)) +#define mp_obj_exception_print (MP_OBJ_TYPE_GET_SLOT(&mp_type_Exception, print)) +#define mp_obj_exception_attr (MP_OBJ_TYPE_GET_SLOT(&mp_type_Exception, attr)) + #define mp_obj_new_exception(o) ((mp_obj_t)(o)) // Assumes returned object will be raised, will create instance then #define mp_obj_new_exception_arg1(e_type, arg) (mp_obj_new_exception_arg1_dyn((e_type), (arg))) @@ -268,6 +290,16 @@ static inline void mp_raise_OSError_dyn(int er) { nlr_raise(mp_call_function_n_kw(mp_load_global(MP_QSTR_OSError), 1, 0, &args[0])); } +static inline void mp_obj_exception_init(mp_obj_full_type_t *exc, qstr name, const mp_obj_type_t *base) { + exc->base.type = &mp_type_type; + exc->flags = MP_TYPE_FLAG_NONE; + exc->name = name; + MP_OBJ_TYPE_SET_SLOT(exc, make_new, mp_obj_exception_make_new, 0); + MP_OBJ_TYPE_SET_SLOT(exc, print, mp_obj_exception_print, 1); + MP_OBJ_TYPE_SET_SLOT(exc, attr, mp_obj_exception_attr, 2); + MP_OBJ_TYPE_SET_SLOT(exc, parent, base, 3); +} + /******************************************************************************/ // Floating point diff --git a/py/emitbc.c b/py/emitbc.c index a07657408fabe..05754cfabf65d 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -92,7 +92,7 @@ void emit_bc_free(emit_t *emit) { } // all functions must go through this one to emit code info -STATIC uint8_t *emit_get_cur_to_write_code_info(void *emit_in, size_t num_bytes_to_write) { +static uint8_t *emit_get_cur_to_write_code_info(void *emit_in, size_t num_bytes_to_write) { emit_t *emit = emit_in; if (emit->pass < MP_PASS_EMIT) { emit->code_info_offset += num_bytes_to_write; @@ -105,16 +105,16 @@ STATIC uint8_t *emit_get_cur_to_write_code_info(void *emit_in, size_t num_bytes_ } } -STATIC void emit_write_code_info_byte(emit_t *emit, byte val) { +static void emit_write_code_info_byte(emit_t *emit, byte val) { *emit_get_cur_to_write_code_info(emit, 1) = val; } -STATIC void emit_write_code_info_qstr(emit_t *emit, qstr qst) { +static void emit_write_code_info_qstr(emit_t *emit, qstr qst) { mp_encode_uint(emit, emit_get_cur_to_write_code_info, mp_emit_common_use_qstr(emit->emit_common, qst)); } #if MICROPY_ENABLE_SOURCE_LINE -STATIC void emit_write_code_info_bytes_lines(emit_t *emit, mp_uint_t bytes_to_skip, mp_uint_t lines_to_skip) { +static void emit_write_code_info_bytes_lines(emit_t *emit, mp_uint_t bytes_to_skip, mp_uint_t lines_to_skip) { assert(bytes_to_skip > 0 || lines_to_skip > 0); while (bytes_to_skip > 0 || lines_to_skip > 0) { mp_uint_t b, l; @@ -143,7 +143,7 @@ STATIC void emit_write_code_info_bytes_lines(emit_t *emit, mp_uint_t bytes_to_sk #endif // all functions must go through this one to emit byte code -STATIC uint8_t *emit_get_cur_to_write_bytecode(void *emit_in, size_t num_bytes_to_write) { +static uint8_t *emit_get_cur_to_write_bytecode(void *emit_in, size_t num_bytes_to_write) { emit_t *emit = emit_in; if (emit->suppress) { return emit->dummy_data; @@ -159,19 +159,19 @@ STATIC uint8_t *emit_get_cur_to_write_bytecode(void *emit_in, size_t num_bytes_t } } -STATIC void emit_write_bytecode_raw_byte(emit_t *emit, byte b1) { +static void emit_write_bytecode_raw_byte(emit_t *emit, byte b1) { byte *c = emit_get_cur_to_write_bytecode(emit, 1); c[0] = b1; } -STATIC void emit_write_bytecode_byte(emit_t *emit, int stack_adj, byte b1) { +static void emit_write_bytecode_byte(emit_t *emit, int stack_adj, byte b1) { mp_emit_bc_adjust_stack_size(emit, stack_adj); byte *c = emit_get_cur_to_write_bytecode(emit, 1); c[0] = b1; } // Similar to mp_encode_uint(), just some extra handling to encode sign -STATIC void emit_write_bytecode_byte_int(emit_t *emit, int stack_adj, byte b1, mp_int_t num) { +static void emit_write_bytecode_byte_int(emit_t *emit, int stack_adj, byte b1, mp_int_t num) { emit_write_bytecode_byte(emit, stack_adj, b1); // We store each 7 bits in a separate byte, and that's how many bytes needed @@ -197,24 +197,24 @@ STATIC void emit_write_bytecode_byte_int(emit_t *emit, int stack_adj, byte b1, m *c = *p; } -STATIC void emit_write_bytecode_byte_uint(emit_t *emit, int stack_adj, byte b, mp_uint_t val) { +static void emit_write_bytecode_byte_uint(emit_t *emit, int stack_adj, byte b, mp_uint_t val) { emit_write_bytecode_byte(emit, stack_adj, b); mp_encode_uint(emit, emit_get_cur_to_write_bytecode, val); } -STATIC void emit_write_bytecode_byte_const(emit_t *emit, int stack_adj, byte b, mp_uint_t n) { +static void emit_write_bytecode_byte_const(emit_t *emit, int stack_adj, byte b, mp_uint_t n) { emit_write_bytecode_byte_uint(emit, stack_adj, b, n); } -STATIC void emit_write_bytecode_byte_qstr(emit_t *emit, int stack_adj, byte b, qstr qst) { +static void emit_write_bytecode_byte_qstr(emit_t *emit, int stack_adj, byte b, qstr qst) { emit_write_bytecode_byte_uint(emit, stack_adj, b, mp_emit_common_use_qstr(emit->emit_common, qst)); } -STATIC void emit_write_bytecode_byte_obj(emit_t *emit, int stack_adj, byte b, mp_obj_t obj) { +static void emit_write_bytecode_byte_obj(emit_t *emit, int stack_adj, byte b, mp_obj_t obj) { emit_write_bytecode_byte_const(emit, stack_adj, b, mp_emit_common_use_const_obj(emit->emit_common, obj)); } -STATIC void emit_write_bytecode_byte_child(emit_t *emit, int stack_adj, byte b, mp_raw_code_t *rc) { +static void emit_write_bytecode_byte_child(emit_t *emit, int stack_adj, byte b, mp_raw_code_t *rc) { emit_write_bytecode_byte_const(emit, stack_adj, b, mp_emit_common_alloc_const_child(emit->emit_common, rc)); #if MICROPY_PY_SYS_SETTRACE @@ -227,7 +227,7 @@ STATIC void emit_write_bytecode_byte_child(emit_t *emit, int stack_adj, byte b, // The offset is encoded as either 1 or 2 bytes, depending on how big it is. // The encoding of this jump opcode can change size from one pass to the next, // but it must only ever decrease in size on successive passes. -STATIC void emit_write_bytecode_byte_label(emit_t *emit, int stack_adj, byte b1, mp_uint_t label) { +static void emit_write_bytecode_byte_label(emit_t *emit, int stack_adj, byte b1, mp_uint_t label) { mp_emit_bc_adjust_stack_size(emit, stack_adj); if (emit->suppress) { @@ -393,13 +393,18 @@ bool mp_emit_bc_end_pass(emit_t *emit) { mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("bytecode overflow")); } + #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS + size_t bytecode_len = emit->code_info_size + emit->bytecode_size; + #if MICROPY_DEBUG_PRINTERS + emit->scope->raw_code_data_len = bytecode_len; + #endif + #endif + // Bytecode is finalised, assign it to the raw code object. mp_emit_glue_assign_bytecode(emit->scope->raw_code, emit->code_base, - #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS - emit->code_info_size + emit->bytecode_size, - #endif emit->emit_common->children, #if MICROPY_PERSISTENT_CODE_SAVE + bytecode_len, emit->emit_common->ct_cur_child, #endif emit->scope->scope_flags); @@ -443,7 +448,6 @@ void mp_emit_bc_label_assign(emit_t *emit, mp_uint_t l) { // should be emitted (until another unconditional flow control). emit->suppress = false; - mp_emit_bc_adjust_stack_size(emit, 0); if (emit->pass == MP_PASS_SCOPE) { return; } @@ -764,7 +768,7 @@ void mp_emit_bc_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_closed_ov } } -STATIC void emit_bc_call_function_method_helper(emit_t *emit, int stack_adj, mp_uint_t bytecode_base, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) { +static void emit_bc_call_function_method_helper(emit_t *emit, int stack_adj, mp_uint_t bytecode_base, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) { if (star_flags) { // each positional arg is one object, each kwarg is two objects, the key // and the value and one extra object for the star args bitmap. diff --git a/py/emitglue.c b/py/emitglue.c index d78ef48315967..8ab624ee7cf38 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -63,24 +63,23 @@ mp_raw_code_t *mp_emit_glue_new_raw_code(void) { } void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, - #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS - size_t len, - #endif mp_raw_code_t **children, #if MICROPY_PERSISTENT_CODE_SAVE - size_t n_children, + size_t len, + uint16_t n_children, #endif - mp_uint_t scope_flags) { + uint16_t scope_flags) { rc->kind = MP_CODE_BYTECODE; - rc->scope_flags = scope_flags; + rc->is_generator = (scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0; + // CIRCUITPY-CHANGE: async and generator are distinguished + // For async, BOTH is_generator and is_async will be set. + rc->is_async = (scope_flags & MP_SCOPE_FLAG_ASYNC) != 0; rc->fun_data = code; - #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS - rc->fun_data_len = len; - #endif rc->children = children; #if MICROPY_PERSISTENT_CODE_SAVE + rc->fun_data_len = len; rc->n_children = n_children; #endif @@ -91,7 +90,7 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, // CIRCUITPY-CHANGE: prevent warning #if defined(DEBUG_PRINT) && DEBUG_PRINT - #if !(MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS) + #if !MICROPY_PERSISTENT_CODE_SAVE const size_t len = 0; #endif DEBUG_printf("assign byte code: code=%p len=" UINT_FMT " flags=%x\n", code, len, (uint)scope_flags); @@ -99,13 +98,14 @@ void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, } #if MICROPY_EMIT_MACHINE_CODE -void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void *fun_data, mp_uint_t fun_len, +void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, const void *fun_data, mp_uint_t fun_len, mp_raw_code_t **children, #if MICROPY_PERSISTENT_CODE_SAVE - size_t n_children, + uint16_t n_children, uint16_t prelude_offset, #endif - mp_uint_t scope_flags, mp_uint_t n_pos_args, mp_uint_t type_sig) { + uint16_t scope_flags, uint32_t asm_n_pos_args, uint32_t asm_type_sig + ) { assert(kind == MP_CODE_NATIVE_PY || kind == MP_CODE_NATIVE_VIPER || kind == MP_CODE_NATIVE_ASM); @@ -122,7 +122,7 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void #endif #elif MICROPY_EMIT_ARM #if (defined(__linux__) && defined(__GNUC__)) || __ARM_ARCH == 7 - __builtin___clear_cache(fun_data, (uint8_t *)fun_data + fun_len); + __builtin___clear_cache((void *)fun_data, (uint8_t *)fun_data + fun_len); #elif defined(__arm__) // Flush I-cache and D-cache. asm volatile ( @@ -136,10 +136,13 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void #endif rc->kind = kind; - rc->scope_flags = scope_flags; + rc->is_generator = (scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0; + // CIRCUITPY-CHANGE: async and generator are distinguished + // For async, BOTH is_generator and is_async will be set. + rc->is_async = (scope_flags & MP_SCOPE_FLAG_ASYNC) != 0; rc->fun_data = fun_data; - #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS + #if MICROPY_PERSISTENT_CODE_SAVE rc->fun_data_len = fun_len; #endif rc->children = children; @@ -149,17 +152,19 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void rc->prelude_offset = prelude_offset; #endif + #if MICROPY_EMIT_INLINE_ASM // These two entries are only needed for MP_CODE_NATIVE_ASM. - rc->n_pos_args = n_pos_args; - rc->type_sig = type_sig; + rc->asm_n_pos_args = asm_n_pos_args; + rc->asm_type_sig = asm_type_sig; + #endif #if DEBUG_PRINT - DEBUG_printf("assign native: kind=%d fun=%p len=" UINT_FMT " n_pos_args=" UINT_FMT " flags=%x\n", kind, fun_data, fun_len, n_pos_args, (uint)scope_flags); + DEBUG_printf("assign native: kind=%d fun=%p len=" UINT_FMT " flags=%x\n", kind, fun_data, fun_len, (uint)scope_flags); for (mp_uint_t i = 0; i < fun_len; i++) { if (i > 0 && i % 16 == 0) { DEBUG_printf("\n"); } - DEBUG_printf(" %02x", ((byte *)fun_data)[i]); + DEBUG_printf(" %02x", ((const byte *)fun_data)[i]); } DEBUG_printf("\n"); @@ -174,9 +179,9 @@ void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void } #endif -mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, const mp_module_context_t *context, const mp_obj_t *def_args) { - DEBUG_OP_printf("make_function_from_raw_code %p\n", rc); - assert(rc != NULL); +mp_obj_t mp_make_function_from_proto_fun(mp_proto_fun_t proto_fun, const mp_module_context_t *context, const mp_obj_t *def_args) { + DEBUG_OP_printf("make_function_from_proto_fun %p\n", proto_fun); + assert(proto_fun != NULL); // def_args must be MP_OBJ_NULL or a tuple assert(def_args == NULL || def_args[0] == MP_OBJ_NULL || mp_obj_is_type(def_args[0], &mp_type_tuple)); @@ -184,25 +189,55 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, const mp_module // def_kw_args must be MP_OBJ_NULL or a dict assert(def_args == NULL || def_args[1] == MP_OBJ_NULL || mp_obj_is_type(def_args[1], &mp_type_dict)); + #if MICROPY_MODULE_FROZEN_MPY + if (mp_proto_fun_is_bytecode(proto_fun)) { + const uint8_t *bc = proto_fun; + mp_obj_t fun = mp_obj_new_fun_bc(def_args, bc, context, NULL); + MP_BC_PRELUDE_SIG_DECODE(bc); + // CIRCUITPY-CHANGE: distinguish generators and async + // A coroutine is MP_SCOPE_FLAG_ASYNC | MP_SCOPE_FLAG_GENERATOR, + // so check for ASYNC first. + #if MICROPY_PY_ASYNC_AWAIT + if (scope_flags & MP_SCOPE_FLAG_ASYNC) { + ((mp_obj_base_t *)MP_OBJ_TO_PTR(fun))->type = &mp_type_coro_wrap; + } else + #endif + if (scope_flags & MP_SCOPE_FLAG_GENERATOR) { + ((mp_obj_base_t *)MP_OBJ_TO_PTR(fun))->type = &mp_type_gen_wrap; + } + return fun; + } + #endif + + // the proto-function is a mp_raw_code_t + const mp_raw_code_t *rc = proto_fun; + // make the function, depending on the raw code kind mp_obj_t fun; switch (rc->kind) { #if MICROPY_EMIT_NATIVE case MP_CODE_NATIVE_PY: - case MP_CODE_NATIVE_VIPER: fun = mp_obj_new_fun_native(def_args, rc->fun_data, context, rc->children); // Check for a generator function, and if so change the type of the object // CIRCUITPY-CHANGE: distinguish generators and async - if ((rc->scope_flags & MP_SCOPE_FLAG_ASYNC) != 0) { + #if MICROPY_PY_ASYNC_AWAIT + // For async, BOTH is_async and is_generator will be set, + // so check is_async first. + if ((rc->is_async) != 0) { ((mp_obj_base_t *)MP_OBJ_TO_PTR(fun))->type = &mp_type_native_coro_wrap; - } else if ((rc->scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0) { + } else + #endif + if ((rc->is_generator) != 0) { ((mp_obj_base_t *)MP_OBJ_TO_PTR(fun))->type = &mp_type_native_gen_wrap; } break; + case MP_CODE_NATIVE_VIPER: + fun = mp_obj_new_fun_viper(rc->fun_data, context, rc->children); + break; #endif #if MICROPY_EMIT_INLINE_ASM case MP_CODE_NATIVE_ASM: - fun = mp_obj_new_fun_asm(rc->n_pos_args, rc->fun_data, rc->type_sig); + fun = mp_obj_new_fun_asm(rc->asm_n_pos_args, rc->fun_data, rc->asm_type_sig); break; #endif default: @@ -211,14 +246,14 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, const mp_module fun = mp_obj_new_fun_bc(def_args, rc->fun_data, context, rc->children); // check for generator functions and if so change the type of the object // CIRCUITPY-CHANGE: distinguish generators and async - // A generator is MP_SCOPE_FLAG_ASYNC | MP_SCOPE_FLAG_GENERATOR, - // so check for ASYNC first. + // For async, BOTH is_async and is_generator will be set, + // so check is_async first. #if MICROPY_PY_ASYNC_AWAIT - if ((rc->scope_flags & MP_SCOPE_FLAG_ASYNC) != 0) { + if ((rc->is_async) != 0) { ((mp_obj_base_t *)MP_OBJ_TO_PTR(fun))->type = &mp_type_coro_wrap; } else #endif - if ((rc->scope_flags & MP_SCOPE_FLAG_GENERATOR) != 0) { + if ((rc->is_generator) != 0) { ((mp_obj_base_t *)MP_OBJ_TO_PTR(fun))->type = &mp_type_gen_wrap; } @@ -233,16 +268,16 @@ mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, const mp_module return fun; } -mp_obj_t mp_make_closure_from_raw_code(const mp_raw_code_t *rc, const mp_module_context_t *context, mp_uint_t n_closed_over, const mp_obj_t *args) { - DEBUG_OP_printf("make_closure_from_raw_code %p " UINT_FMT " %p\n", rc, n_closed_over, args); +mp_obj_t mp_make_closure_from_proto_fun(mp_proto_fun_t proto_fun, const mp_module_context_t *context, mp_uint_t n_closed_over, const mp_obj_t *args) { + DEBUG_OP_printf("make_closure_from_proto_fun %p " UINT_FMT " %p\n", proto_fun, n_closed_over, args); // make function object mp_obj_t ffun; if (n_closed_over & 0x100) { // default positional and keyword args given - ffun = mp_make_function_from_raw_code(rc, context, args); + ffun = mp_make_function_from_proto_fun(proto_fun, context, args); } else { // default positional and keyword args not given - ffun = mp_make_function_from_raw_code(rc, context, NULL); + ffun = mp_make_function_from_proto_fun(proto_fun, context, NULL); } // wrap function in closure object return mp_obj_new_closure(ffun, n_closed_over & 0xff, args + ((n_closed_over >> 7) & 2)); diff --git a/py/emitglue.h b/py/emitglue.h index 4ddf74011fa70..d19503b823f4c 100644 --- a/py/emitglue.h +++ b/py/emitglue.h @@ -31,6 +31,11 @@ // These variables and functions glue the code emitters to the runtime. +// Used with mp_raw_code_t::proto_fun_indicator to detect if a mp_proto_fun_t is a +// mp_raw_code_t struct or a direct pointer to bytecode. +#define MP_PROTO_FUN_INDICATOR_RAW_CODE_0 (0) +#define MP_PROTO_FUN_INDICATOR_RAW_CODE_1 (0) + // These must fit in 8 bits; see scope.h enum { MP_EMIT_OPT_NONE, @@ -49,58 +54,97 @@ typedef enum { MP_CODE_NATIVE_ASM, } mp_raw_code_kind_t; +// An mp_proto_fun_t points to static information about a non-instantiated function. +// A function object is created from this information, and that object can then be executed. +// It points either to bytecode, or an mp_raw_code_t struct. +typedef const void *mp_proto_fun_t; + +// Bytecode is distinguished from an mp_raw_code_t struct by the first two bytes: bytecode +// is guaranteed to have either its first or second byte non-zero. So if both bytes are +// zero then the mp_proto_fun_t pointer must be an mp_raw_code_t. +static inline bool mp_proto_fun_is_bytecode(mp_proto_fun_t proto_fun) { + const uint8_t *header = (const uint8_t *)proto_fun; + return (header[0] | (header[1] << 8)) != (MP_PROTO_FUN_INDICATOR_RAW_CODE_0 | (MP_PROTO_FUN_INDICATOR_RAW_CODE_1 << 8)); +} + +// The mp_raw_code_t struct appears in the following places: // compiled bytecode: instance in RAM, referenced by outer scope, usually freed after first (and only) use // mpy file: instance in RAM, created when .mpy file is loaded (same comments as above) // frozen: instance in ROM typedef struct _mp_raw_code_t { - mp_uint_t kind : 3; // of type mp_raw_code_kind_t - mp_uint_t scope_flags : 7; - mp_uint_t n_pos_args : 11; + uint8_t proto_fun_indicator[2]; + uint8_t kind; // of type mp_raw_code_kind_t; only 3 bits used + // CIRCUITPY-CHANGE: distinguish generator and async + // For async, BOTH is_generator and is_async will be set. + bool is_generator : 1; + bool is_async : 1; const void *fun_data; - #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS - size_t fun_data_len; // so mp_raw_code_save and mp_bytecode_print work - #endif struct _mp_raw_code_t **children; #if MICROPY_PERSISTENT_CODE_SAVE - size_t n_children; + uint32_t fun_data_len; // for mp_raw_code_save + uint16_t n_children; + #if MICROPY_EMIT_MACHINE_CODE + uint16_t prelude_offset; + #endif #if MICROPY_PY_SYS_SETTRACE - mp_bytecode_prelude_t prelude; // line_of_definition is a Python source line where the raw_code was // created e.g. MP_BC_MAKE_FUNCTION. This is different from lineno info // stored in prelude, which provides line number for first statement of // a function. Required to properly implement "call" trace event. - mp_uint_t line_of_definition; + uint32_t line_of_definition; + mp_bytecode_prelude_t prelude; #endif + #endif + #if MICROPY_EMIT_INLINE_ASM + uint32_t asm_n_pos_args : 8; + uint32_t asm_type_sig : 24; // compressed as 2-bit types; ret is MSB, then arg0, arg1, etc + #endif +} mp_raw_code_t; + +// Version of mp_raw_code_t but without the asm_n_pos_args/asm_type_sig entries, which are +// only needed when the kind is MP_CODE_NATIVE_ASM. So this struct can be used when the +// kind is MP_CODE_BYTECODE, MP_CODE_NATIVE_PY or MP_CODE_NATIVE_VIPER, to reduce its size. +typedef struct _mp_raw_code_truncated_t { + uint8_t proto_fun_indicator[2]; + uint8_t kind; + // CIRCUITPY-CHANGE: distinguish generator and async + // For async, BOTH is_generator and is_async will be set. + bool is_generator : 1; + bool is_async : 1; + const void *fun_data; + struct _mp_raw_code_t **children; + #if MICROPY_PERSISTENT_CODE_SAVE + uint32_t fun_data_len; + uint16_t n_children; #if MICROPY_EMIT_MACHINE_CODE uint16_t prelude_offset; #endif + #if MICROPY_PY_SYS_SETTRACE + uint32_t line_of_definition; + mp_bytecode_prelude_t prelude; #endif - #if MICROPY_EMIT_MACHINE_CODE - mp_uint_t type_sig; // for viper, compressed as 2-bit types; ret is MSB, then arg0, arg1, etc #endif -} mp_raw_code_t; +} mp_raw_code_truncated_t; mp_raw_code_t *mp_emit_glue_new_raw_code(void); void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code, - #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS - size_t len, - #endif mp_raw_code_t **children, #if MICROPY_PERSISTENT_CODE_SAVE - size_t n_children, + size_t len, + uint16_t n_children, #endif - mp_uint_t scope_flags); + uint16_t scope_flags); -void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, void *fun_data, mp_uint_t fun_len, +void mp_emit_glue_assign_native(mp_raw_code_t *rc, mp_raw_code_kind_t kind, const void *fun_data, mp_uint_t fun_len, mp_raw_code_t **children, #if MICROPY_PERSISTENT_CODE_SAVE - size_t n_children, + uint16_t n_children, uint16_t prelude_offset, #endif - mp_uint_t scope_flags, mp_uint_t n_pos_args, mp_uint_t type_sig); + uint16_t scope_flags, uint32_t asm_n_pos_args, uint32_t asm_type_sig); -mp_obj_t mp_make_function_from_raw_code(const mp_raw_code_t *rc, const mp_module_context_t *context, const mp_obj_t *def_args); -mp_obj_t mp_make_closure_from_raw_code(const mp_raw_code_t *rc, const mp_module_context_t *context, mp_uint_t n_closed_over, const mp_obj_t *args); +mp_obj_t mp_make_function_from_proto_fun(mp_proto_fun_t proto_fun, const mp_module_context_t *context, const mp_obj_t *def_args); +mp_obj_t mp_make_closure_from_proto_fun(mp_proto_fun_t proto_fun, const mp_module_context_t *context, mp_uint_t n_closed_over, const mp_obj_t *args); #endif // MICROPY_INCLUDED_PY_EMITGLUE_H diff --git a/py/emitinlinethumb.c b/py/emitinlinethumb.c index 29487f10483f9..7818bb4f46da8 100644 --- a/py/emitinlinethumb.c +++ b/py/emitinlinethumb.c @@ -74,11 +74,11 @@ static inline bool emit_inline_thumb_allow_float(emit_inline_asm_t *emit) { #endif -STATIC void emit_inline_thumb_error_msg(emit_inline_asm_t *emit, mp_rom_error_text_t msg) { +static void emit_inline_thumb_error_msg(emit_inline_asm_t *emit, mp_rom_error_text_t msg) { *emit->error_slot = mp_obj_new_exception_msg(&mp_type_SyntaxError, msg); } -STATIC void emit_inline_thumb_error_exc(emit_inline_asm_t *emit, mp_obj_t exc) { +static void emit_inline_thumb_error_exc(emit_inline_asm_t *emit, mp_obj_t exc) { *emit->error_slot = exc; } @@ -97,7 +97,7 @@ void emit_inline_thumb_free(emit_inline_asm_t *emit) { m_del_obj(emit_inline_asm_t, emit); } -STATIC void emit_inline_thumb_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, mp_obj_t *error_slot) { +static void emit_inline_thumb_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, mp_obj_t *error_slot) { emit->pass = pass; emit->error_slot = error_slot; if (emit->pass == MP_PASS_CODE_SIZE) { @@ -107,12 +107,12 @@ STATIC void emit_inline_thumb_start_pass(emit_inline_asm_t *emit, pass_kind_t pa asm_thumb_entry(&emit->as, 0); } -STATIC void emit_inline_thumb_end_pass(emit_inline_asm_t *emit, mp_uint_t type_sig) { +static void emit_inline_thumb_end_pass(emit_inline_asm_t *emit, mp_uint_t type_sig) { asm_thumb_exit(&emit->as); asm_thumb_end_pass(&emit->as); } -STATIC mp_uint_t emit_inline_thumb_count_params(emit_inline_asm_t *emit, mp_uint_t n_params, mp_parse_node_t *pn_params) { +static mp_uint_t emit_inline_thumb_count_params(emit_inline_asm_t *emit, mp_uint_t n_params, mp_parse_node_t *pn_params) { if (n_params > 4) { emit_inline_thumb_error_msg(emit, MP_ERROR_TEXT("can only have up to 4 parameters to Thumb assembly")); return 0; @@ -131,7 +131,7 @@ STATIC mp_uint_t emit_inline_thumb_count_params(emit_inline_asm_t *emit, mp_uint return n_params; } -STATIC bool emit_inline_thumb_label(emit_inline_asm_t *emit, mp_uint_t label_num, qstr label_id) { +static bool emit_inline_thumb_label(emit_inline_asm_t *emit, mp_uint_t label_num, qstr label_id) { assert(label_num < emit->max_num_labels); if (emit->pass == MP_PASS_CODE_SIZE) { // check for duplicate label on first pass @@ -149,7 +149,7 @@ STATIC bool emit_inline_thumb_label(emit_inline_asm_t *emit, mp_uint_t label_num typedef struct _reg_name_t { byte reg; byte name[3]; } reg_name_t; -STATIC const reg_name_t reg_name_table[] = { +static const reg_name_t reg_name_table[] = { {0, "r0\0"}, {1, "r1\0"}, {2, "r2\0"}, @@ -177,14 +177,14 @@ STATIC const reg_name_t reg_name_table[] = { typedef struct _special_reg_name_t { byte reg; char name[MAX_SPECIAL_REGISTER_NAME_LENGTH + 1]; } special_reg_name_t; -STATIC const special_reg_name_t special_reg_name_table[] = { +static const special_reg_name_t special_reg_name_table[] = { {5, "IPSR"}, {17, "BASEPRI"}, }; // return empty string in case of error, so we can attempt to parse the string // without a special check if it was in fact a string -STATIC const char *get_arg_str(mp_parse_node_t pn) { +static const char *get_arg_str(mp_parse_node_t pn) { if (MP_PARSE_NODE_IS_ID(pn)) { qstr qst = MP_PARSE_NODE_LEAF_ARG(pn); return qstr_str(qst); @@ -193,7 +193,7 @@ STATIC const char *get_arg_str(mp_parse_node_t pn) { } } -STATIC mp_uint_t get_arg_reg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, mp_uint_t max_reg) { +static mp_uint_t get_arg_reg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, mp_uint_t max_reg) { const char *reg_str = get_arg_str(pn); for (mp_uint_t i = 0; i < MP_ARRAY_SIZE(reg_name_table); i++) { const reg_name_t *r = ®_name_table[i]; @@ -217,7 +217,7 @@ STATIC mp_uint_t get_arg_reg(emit_inline_asm_t *emit, const char *op, mp_parse_n return 0; } -STATIC mp_uint_t get_arg_special_reg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { +static mp_uint_t get_arg_special_reg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { const char *reg_str = get_arg_str(pn); for (mp_uint_t i = 0; i < MP_ARRAY_SIZE(special_reg_name_table); i++) { const special_reg_name_t *r = &special_reg_name_table[i]; @@ -231,7 +231,7 @@ STATIC mp_uint_t get_arg_special_reg(emit_inline_asm_t *emit, const char *op, mp return 0; } -STATIC mp_uint_t get_arg_vfpreg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { +static mp_uint_t get_arg_vfpreg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { const char *reg_str = get_arg_str(pn); if (reg_str[0] == 's' && reg_str[1] != '\0') { mp_uint_t regno = 0; @@ -258,7 +258,7 @@ STATIC mp_uint_t get_arg_vfpreg(emit_inline_asm_t *emit, const char *op, mp_pars return 0; } -STATIC mp_uint_t get_arg_reglist(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { +static mp_uint_t get_arg_reglist(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { // a register list looks like {r0, r1, r2} and is parsed as a Python set if (!MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_atom_brace)) { @@ -310,7 +310,7 @@ STATIC mp_uint_t get_arg_reglist(emit_inline_asm_t *emit, const char *op, mp_par return 0; } -STATIC uint32_t get_arg_i(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, uint32_t fit_mask) { +static uint32_t get_arg_i(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, uint32_t fit_mask) { mp_obj_t o; if (!mp_parse_node_get_int_maybe(pn, &o)) { emit_inline_thumb_error_exc(emit, mp_obj_new_exception_msg_varg(&mp_type_SyntaxError, MP_ERROR_TEXT("'%s' expects an integer"), op)); @@ -324,7 +324,7 @@ STATIC uint32_t get_arg_i(emit_inline_asm_t *emit, const char *op, mp_parse_node return i; } -STATIC bool get_arg_addr(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, mp_parse_node_t *pn_base, mp_parse_node_t *pn_offset) { +static bool get_arg_addr(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, mp_parse_node_t *pn_base, mp_parse_node_t *pn_offset) { if (!MP_PARSE_NODE_IS_STRUCT_KIND(pn, PN_atom_bracket)) { goto bad_arg; } @@ -346,7 +346,7 @@ STATIC bool get_arg_addr(emit_inline_asm_t *emit, const char *op, mp_parse_node_ return false; } -STATIC int get_arg_label(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { +static int get_arg_label(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { if (!MP_PARSE_NODE_IS_ID(pn)) { emit_inline_thumb_error_exc(emit, mp_obj_new_exception_msg_varg(&mp_type_SyntaxError, MP_ERROR_TEXT("'%s' expects a label"), op)); return 0; @@ -367,7 +367,7 @@ STATIC int get_arg_label(emit_inline_asm_t *emit, const char *op, mp_parse_node_ typedef struct _cc_name_t { byte cc; byte name[2]; } cc_name_t; -STATIC const cc_name_t cc_name_table[] = { +static const cc_name_t cc_name_table[] = { { ASM_THUMB_CC_EQ, "eq" }, { ASM_THUMB_CC_NE, "ne" }, { ASM_THUMB_CC_CS, "cs" }, @@ -388,7 +388,7 @@ typedef struct _format_4_op_t { byte op; char name[3]; } format_4_op_t; #define X(x) (((x) >> 4) & 0xff) // only need 1 byte to distinguish these ops -STATIC const format_4_op_t format_4_op_table[] = { +static const format_4_op_t format_4_op_table[] = { { X(ASM_THUMB_FORMAT_4_EOR), "eor" }, { X(ASM_THUMB_FORMAT_4_LSL), "lsl" }, { X(ASM_THUMB_FORMAT_4_LSR), "lsr" }, @@ -412,7 +412,7 @@ typedef struct _format_9_10_op_t { uint16_t op; uint16_t name; } format_9_10_op_t; #define X(x) (x) -STATIC const format_9_10_op_t format_9_10_op_table[] = { +static const format_9_10_op_t format_9_10_op_table[] = { { X(ASM_THUMB_FORMAT_9_LDR | ASM_THUMB_FORMAT_9_WORD_TRANSFER), MP_QSTR_ldr }, { X(ASM_THUMB_FORMAT_9_LDR | ASM_THUMB_FORMAT_9_BYTE_TRANSFER), MP_QSTR_ldrb }, { X(ASM_THUMB_FORMAT_10_LDRH), MP_QSTR_ldrh }, @@ -427,7 +427,7 @@ typedef struct _format_vfp_op_t { byte op; char name[3]; } format_vfp_op_t; -STATIC const format_vfp_op_t format_vfp_op_table[] = { +static const format_vfp_op_t format_vfp_op_table[] = { { 0x30, "add" }, { 0x34, "sub" }, { 0x20, "mul" }, @@ -437,7 +437,7 @@ STATIC const format_vfp_op_t format_vfp_op_table[] = { // shorthand alias for whether we allow ARMv7-M instructions #define ARMV7M asm_thumb_allow_armv7m(&emit->as) -STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_args, mp_parse_node_t *pn_args) { +static void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_args, mp_parse_node_t *pn_args) { // TODO perhaps make two tables: // one_args = // "b", LAB, asm_thumb_b_n, diff --git a/py/emitinlinextensa.c b/py/emitinlinextensa.c index 5dac2ae3907f1..57056d597aab7 100644 --- a/py/emitinlinextensa.c +++ b/py/emitinlinextensa.c @@ -43,11 +43,11 @@ struct _emit_inline_asm_t { qstr *label_lookup; }; -STATIC void emit_inline_xtensa_error_msg(emit_inline_asm_t *emit, mp_rom_error_text_t msg) { +static void emit_inline_xtensa_error_msg(emit_inline_asm_t *emit, mp_rom_error_text_t msg) { *emit->error_slot = mp_obj_new_exception_msg(&mp_type_SyntaxError, msg); } -STATIC void emit_inline_xtensa_error_exc(emit_inline_asm_t *emit, mp_obj_t exc) { +static void emit_inline_xtensa_error_exc(emit_inline_asm_t *emit, mp_obj_t exc) { *emit->error_slot = exc; } @@ -66,7 +66,7 @@ void emit_inline_xtensa_free(emit_inline_asm_t *emit) { m_del_obj(emit_inline_asm_t, emit); } -STATIC void emit_inline_xtensa_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, mp_obj_t *error_slot) { +static void emit_inline_xtensa_start_pass(emit_inline_asm_t *emit, pass_kind_t pass, mp_obj_t *error_slot) { emit->pass = pass; emit->error_slot = error_slot; if (emit->pass == MP_PASS_CODE_SIZE) { @@ -76,12 +76,12 @@ STATIC void emit_inline_xtensa_start_pass(emit_inline_asm_t *emit, pass_kind_t p asm_xtensa_entry(&emit->as, 0); } -STATIC void emit_inline_xtensa_end_pass(emit_inline_asm_t *emit, mp_uint_t type_sig) { +static void emit_inline_xtensa_end_pass(emit_inline_asm_t *emit, mp_uint_t type_sig) { asm_xtensa_exit(&emit->as); asm_xtensa_end_pass(&emit->as); } -STATIC mp_uint_t emit_inline_xtensa_count_params(emit_inline_asm_t *emit, mp_uint_t n_params, mp_parse_node_t *pn_params) { +static mp_uint_t emit_inline_xtensa_count_params(emit_inline_asm_t *emit, mp_uint_t n_params, mp_parse_node_t *pn_params) { if (n_params > 4) { emit_inline_xtensa_error_msg(emit, MP_ERROR_TEXT("can only have up to 4 parameters to Xtensa assembly")); return 0; @@ -100,7 +100,7 @@ STATIC mp_uint_t emit_inline_xtensa_count_params(emit_inline_asm_t *emit, mp_uin return n_params; } -STATIC bool emit_inline_xtensa_label(emit_inline_asm_t *emit, mp_uint_t label_num, qstr label_id) { +static bool emit_inline_xtensa_label(emit_inline_asm_t *emit, mp_uint_t label_num, qstr label_id) { assert(label_num < emit->max_num_labels); if (emit->pass == MP_PASS_CODE_SIZE) { // check for duplicate label on first pass @@ -118,7 +118,7 @@ STATIC bool emit_inline_xtensa_label(emit_inline_asm_t *emit, mp_uint_t label_nu typedef struct _reg_name_t { byte reg; byte name[3]; } reg_name_t; -STATIC const reg_name_t reg_name_table[] = { +static const reg_name_t reg_name_table[] = { {0, "a0\0"}, {1, "a1\0"}, {2, "a2\0"}, @@ -139,7 +139,7 @@ STATIC const reg_name_t reg_name_table[] = { // return empty string in case of error, so we can attempt to parse the string // without a special check if it was in fact a string -STATIC const char *get_arg_str(mp_parse_node_t pn) { +static const char *get_arg_str(mp_parse_node_t pn) { if (MP_PARSE_NODE_IS_ID(pn)) { qstr qst = MP_PARSE_NODE_LEAF_ARG(pn); return qstr_str(qst); @@ -148,7 +148,7 @@ STATIC const char *get_arg_str(mp_parse_node_t pn) { } } -STATIC mp_uint_t get_arg_reg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { +static mp_uint_t get_arg_reg(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { const char *reg_str = get_arg_str(pn); for (mp_uint_t i = 0; i < MP_ARRAY_SIZE(reg_name_table); i++) { const reg_name_t *r = ®_name_table[i]; @@ -165,7 +165,7 @@ STATIC mp_uint_t get_arg_reg(emit_inline_asm_t *emit, const char *op, mp_parse_n return 0; } -STATIC uint32_t get_arg_i(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, int min, int max) { +static uint32_t get_arg_i(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn, int min, int max) { mp_obj_t o; if (!mp_parse_node_get_int_maybe(pn, &o)) { emit_inline_xtensa_error_exc(emit, mp_obj_new_exception_msg_varg(&mp_type_SyntaxError, MP_ERROR_TEXT("'%s' expects an integer"), op)); @@ -179,7 +179,7 @@ STATIC uint32_t get_arg_i(emit_inline_asm_t *emit, const char *op, mp_parse_node return i; } -STATIC int get_arg_label(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { +static int get_arg_label(emit_inline_asm_t *emit, const char *op, mp_parse_node_t pn) { if (!MP_PARSE_NODE_IS_ID(pn)) { emit_inline_xtensa_error_exc(emit, mp_obj_new_exception_msg_varg(&mp_type_SyntaxError, MP_ERROR_TEXT("'%s' expects a label"), op)); return 0; @@ -208,7 +208,7 @@ typedef struct _opcode_table_3arg_t { uint8_t a1 : 4; } opcode_table_3arg_t; -STATIC const opcode_table_3arg_t opcode_table_3arg[] = { +static const opcode_table_3arg_t opcode_table_3arg[] = { // arithmetic opcodes: reg, reg, reg {MP_QSTR_and_, RRR, 0, 1}, {MP_QSTR_or_, RRR, 0, 2}, @@ -242,7 +242,7 @@ STATIC const opcode_table_3arg_t opcode_table_3arg[] = { {MP_QSTR_bnone, RRI8_B, ASM_XTENSA_CC_NONE, 0}, }; -STATIC void emit_inline_xtensa_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_args, mp_parse_node_t *pn_args) { +static void emit_inline_xtensa_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_args, mp_parse_node_t *pn_args) { size_t op_len; const char *op_str = (const char *)qstr_data(op, &op_len); diff --git a/py/emitnative.c b/py/emitnative.c index 8225f3ff33659..4789d3f5781f6 100644 --- a/py/emitnative.c +++ b/py/emitnative.c @@ -186,7 +186,7 @@ #define REG_QSTR_TABLE (REG_LOCAL_3) #define MAX_REGS_FOR_LOCAL_VARS (2) -STATIC const uint8_t reg_local_table[MAX_REGS_FOR_LOCAL_VARS] = {REG_LOCAL_1, REG_LOCAL_2}; +static const uint8_t reg_local_table[MAX_REGS_FOR_LOCAL_VARS] = {REG_LOCAL_1, REG_LOCAL_2}; #else @@ -198,7 +198,7 @@ STATIC const uint8_t reg_local_table[MAX_REGS_FOR_LOCAL_VARS] = {REG_LOCAL_1, RE #define REG_GENERATOR_STATE (REG_LOCAL_3) #define MAX_REGS_FOR_LOCAL_VARS (3) -STATIC const uint8_t reg_local_table[MAX_REGS_FOR_LOCAL_VARS] = {REG_LOCAL_1, REG_LOCAL_2, REG_LOCAL_3}; +static const uint8_t reg_local_table[MAX_REGS_FOR_LOCAL_VARS] = {REG_LOCAL_1, REG_LOCAL_2, REG_LOCAL_3}; #endif @@ -232,7 +232,7 @@ typedef enum { VTYPE_BUILTIN_CAST = 0x70 | MP_NATIVE_TYPE_OBJ, } vtype_kind_t; -STATIC qstr vtype_to_qstr(vtype_kind_t vtype) { +static qstr vtype_to_qstr(vtype_kind_t vtype) { switch (vtype) { case VTYPE_PYOBJ: return MP_QSTR_object; @@ -283,7 +283,6 @@ struct _emit_t { int pass; bool do_viper_types; - bool prelude_offset_uses_u16_encoding; mp_uint_t local_vtype_alloc; vtype_kind_t *local_vtype; @@ -311,10 +310,10 @@ struct _emit_t { ASM_T *as; }; -STATIC void emit_load_reg_with_object(emit_t *emit, int reg, mp_obj_t obj); -STATIC void emit_native_global_exc_entry(emit_t *emit); -STATIC void emit_native_global_exc_exit(emit_t *emit); -STATIC void emit_native_load_const_obj(emit_t *emit, mp_obj_t obj); +static void emit_load_reg_with_object(emit_t *emit, int reg, mp_obj_t obj); +static void emit_native_global_exc_entry(emit_t *emit); +static void emit_native_global_exc_exit(emit_t *emit); +static void emit_native_load_const_obj(emit_t *emit, mp_obj_t obj); emit_t *EXPORT_FUN(new)(mp_emit_common_t * emit_common, mp_obj_t *error_slot, uint *label_slot, mp_uint_t max_num_labels) { emit_t *emit = m_new0(emit_t, 1); @@ -339,13 +338,13 @@ void EXPORT_FUN(free)(emit_t * emit) { m_del_obj(emit_t, emit); } -STATIC void emit_call_with_imm_arg(emit_t *emit, mp_fun_kind_t fun_kind, mp_int_t arg_val, int arg_reg); +static void emit_call_with_imm_arg(emit_t *emit, mp_fun_kind_t fun_kind, mp_int_t arg_val, int arg_reg); -STATIC void emit_native_mov_reg_const(emit_t *emit, int reg_dest, int const_val) { +static void emit_native_mov_reg_const(emit_t *emit, int reg_dest, int const_val) { ASM_LOAD_REG_REG_OFFSET(emit->as, reg_dest, REG_FUN_TABLE, const_val); } -STATIC void emit_native_mov_state_reg(emit_t *emit, int local_num, int reg_src) { +static void emit_native_mov_state_reg(emit_t *emit, int local_num, int reg_src) { if (emit->scope->scope_flags & MP_SCOPE_FLAG_GENERATOR) { ASM_STORE_REG_REG_OFFSET(emit->as, reg_src, REG_GENERATOR_STATE, local_num); } else { @@ -353,7 +352,7 @@ STATIC void emit_native_mov_state_reg(emit_t *emit, int local_num, int reg_src) } } -STATIC void emit_native_mov_reg_state(emit_t *emit, int reg_dest, int local_num) { +static void emit_native_mov_reg_state(emit_t *emit, int reg_dest, int local_num) { if (emit->scope->scope_flags & MP_SCOPE_FLAG_GENERATOR) { ASM_LOAD_REG_REG_OFFSET(emit->as, reg_dest, REG_GENERATOR_STATE, local_num); } else { @@ -361,7 +360,7 @@ STATIC void emit_native_mov_reg_state(emit_t *emit, int reg_dest, int local_num) } } -STATIC void emit_native_mov_reg_state_addr(emit_t *emit, int reg_dest, int local_num) { +static void emit_native_mov_reg_state_addr(emit_t *emit, int reg_dest, int local_num) { if (emit->scope->scope_flags & MP_SCOPE_FLAG_GENERATOR) { ASM_MOV_REG_IMM(emit->as, reg_dest, local_num * ASM_WORD_SIZE); ASM_ADD_REG_REG(emit->as, reg_dest, REG_GENERATOR_STATE); @@ -370,7 +369,7 @@ STATIC void emit_native_mov_reg_state_addr(emit_t *emit, int reg_dest, int local } } -STATIC void emit_native_mov_reg_qstr(emit_t *emit, int arg_reg, qstr qst) { +static void emit_native_mov_reg_qstr(emit_t *emit, int arg_reg, qstr qst) { #if MICROPY_PERSISTENT_CODE_SAVE ASM_LOAD16_REG_REG_OFFSET(emit->as, arg_reg, REG_QSTR_TABLE, mp_emit_common_use_qstr(emit->emit_common, qst)); #else @@ -378,7 +377,7 @@ STATIC void emit_native_mov_reg_qstr(emit_t *emit, int arg_reg, qstr qst) { #endif } -STATIC void emit_native_mov_reg_qstr_obj(emit_t *emit, int reg_dest, qstr qst) { +static void emit_native_mov_reg_qstr_obj(emit_t *emit, int reg_dest, qstr qst) { #if MICROPY_PERSISTENT_CODE_SAVE emit_load_reg_with_object(emit, reg_dest, MP_OBJ_NEW_QSTR(qst)); #else @@ -392,7 +391,7 @@ STATIC void emit_native_mov_reg_qstr_obj(emit_t *emit, int reg_dest, qstr qst) { emit_native_mov_state_reg((emit), (local_num), (reg_temp)); \ } while (false) -STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) { +static void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scope) { DEBUG_printf("start_pass(pass=%u, scope=%p)\n", pass, scope); emit->pass = pass; @@ -549,8 +548,11 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop // work out size of state (locals plus stack) emit->n_state = scope->num_locals + scope->stack_size; + // Store in the first machine-word an index used to the function's prelude. + // This is used at runtime by mp_obj_fun_native_get_prelude_ptr(). + mp_asm_base_data(&emit->as->base, ASM_WORD_SIZE, (uintptr_t)emit->prelude_ptr_index); + if (emit->scope->scope_flags & MP_SCOPE_FLAG_GENERATOR) { - mp_asm_base_data(&emit->as->base, ASM_WORD_SIZE, (uintptr_t)emit->prelude_ptr_index); mp_asm_base_data(&emit->as->base, ASM_WORD_SIZE, (uintptr_t)emit->start_offset); ASM_ENTRY(emit->as, emit->code_state_start); @@ -606,15 +608,6 @@ STATIC void emit_native_start_pass(emit_t *emit, pass_kind_t pass, scope_t *scop // Set code_state.fun_bc ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_FUN_OBJ(emit), REG_PARENT_ARG_1); - // Set code_state.ip, a pointer to the beginning of the prelude. This pointer is found - // either directly in mp_obj_fun_bc_t.child_table (if there are no children), or in - // mp_obj_fun_bc_t.child_table[num_children] (if num_children > 0). - ASM_LOAD_REG_REG_OFFSET(emit->as, REG_PARENT_ARG_1, REG_PARENT_ARG_1, OFFSETOF_OBJ_FUN_BC_CHILD_TABLE); - if (emit->prelude_ptr_index != 0) { - ASM_LOAD_REG_REG_OFFSET(emit->as, REG_PARENT_ARG_1, REG_PARENT_ARG_1, emit->prelude_ptr_index); - } - emit_native_mov_state_reg(emit, emit->code_state_start + OFFSETOF_CODE_STATE_IP, REG_PARENT_ARG_1); - // Set code_state.n_state (only works on little endian targets due to n_state being uint16_t) emit_native_mov_state_imm_via(emit, emit->code_state_start + OFFSETOF_CODE_STATE_N_STATE, emit->n_state, REG_ARG_1); @@ -669,7 +662,7 @@ static inline void emit_native_write_code_info_qstr(emit_t *emit, qstr qst) { mp_encode_uint(&emit->as->base, mp_asm_base_get_cur_to_write_bytes, mp_emit_common_use_qstr(emit->emit_common, qst)); } -STATIC bool emit_native_end_pass(emit_t *emit) { +static bool emit_native_end_pass(emit_t *emit) { emit_native_global_exc_exit(emit); if (!emit->do_viper_types) { @@ -760,7 +753,7 @@ STATIC bool emit_native_end_pass(emit_t *emit) { return true; } -STATIC void ensure_extra_stack(emit_t *emit, size_t delta) { +static void ensure_extra_stack(emit_t *emit, size_t delta) { if (emit->stack_size + delta > emit->stack_info_alloc) { size_t new_alloc = (emit->stack_size + delta + 8) & ~3; emit->stack_info = m_renew(stack_info_t, emit->stack_info, emit->stack_info_alloc, new_alloc); @@ -768,7 +761,7 @@ STATIC void ensure_extra_stack(emit_t *emit, size_t delta) { } } -STATIC void adjust_stack(emit_t *emit, mp_int_t stack_size_delta) { +static void adjust_stack(emit_t *emit, mp_int_t stack_size_delta) { assert((mp_int_t)emit->stack_size + stack_size_delta >= 0); assert((mp_int_t)emit->stack_size + stack_size_delta <= (mp_int_t)emit->stack_info_alloc); emit->stack_size += stack_size_delta; @@ -785,7 +778,7 @@ STATIC void adjust_stack(emit_t *emit, mp_int_t stack_size_delta) { #endif } -STATIC void emit_native_adjust_stack_size(emit_t *emit, mp_int_t delta) { +static void emit_native_adjust_stack_size(emit_t *emit, mp_int_t delta) { DEBUG_printf("adjust_stack_size(" INT_FMT ")\n", delta); if (delta > 0) { ensure_extra_stack(emit, delta); @@ -809,23 +802,23 @@ STATIC void emit_native_adjust_stack_size(emit_t *emit, mp_int_t delta) { adjust_stack(emit, delta); } -STATIC void emit_native_set_source_line(emit_t *emit, mp_uint_t source_line) { +static void emit_native_set_source_line(emit_t *emit, mp_uint_t source_line) { (void)emit; (void)source_line; } // this must be called at start of emit functions -STATIC void emit_native_pre(emit_t *emit) { +static void emit_native_pre(emit_t *emit) { (void)emit; } // depth==0 is top, depth==1 is before top, etc -STATIC stack_info_t *peek_stack(emit_t *emit, mp_uint_t depth) { +static stack_info_t *peek_stack(emit_t *emit, mp_uint_t depth) { return &emit->stack_info[emit->stack_size - 1 - depth]; } // depth==0 is top, depth==1 is before top, etc -STATIC vtype_kind_t peek_vtype(emit_t *emit, mp_uint_t depth) { +static vtype_kind_t peek_vtype(emit_t *emit, mp_uint_t depth) { if (emit->do_viper_types) { return peek_stack(emit, depth)->vtype; } else { @@ -836,7 +829,7 @@ STATIC vtype_kind_t peek_vtype(emit_t *emit, mp_uint_t depth) { // pos=1 is TOS, pos=2 is next, etc // use pos=0 for no skipping -STATIC void need_reg_single(emit_t *emit, int reg_needed, int skip_stack_pos) { +static void need_reg_single(emit_t *emit, int reg_needed, int skip_stack_pos) { skip_stack_pos = emit->stack_size - skip_stack_pos; for (int i = 0; i < emit->stack_size; i++) { if (i != skip_stack_pos) { @@ -851,7 +844,7 @@ 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) { +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) { @@ -862,7 +855,7 @@ STATIC void need_reg_all(emit_t *emit) { } } -STATIC vtype_kind_t load_reg_stack_imm(emit_t *emit, int reg_dest, const stack_info_t *si, bool convert_to_pyobj) { +static vtype_kind_t load_reg_stack_imm(emit_t *emit, int reg_dest, const stack_info_t *si, bool convert_to_pyobj) { if (!convert_to_pyobj && emit->do_viper_types) { ASM_MOV_REG_IMM(emit->as, reg_dest, si->data.u_imm); return si->vtype; @@ -886,7 +879,7 @@ STATIC vtype_kind_t load_reg_stack_imm(emit_t *emit, int reg_dest, const stack_i // 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) { +static void need_stack_settled(emit_t *emit) { DEBUG_printf(" need_stack_settled; stack_size=%d\n", emit->stack_size); need_reg_all(emit); for (int i = 0; i < emit->stack_size; i++) { @@ -902,7 +895,7 @@ STATIC void need_stack_settled(emit_t *emit) { } // pos=1 is TOS, pos=2 is next, etc -STATIC void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int reg_dest) { +static void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int reg_dest) { need_reg_single(emit, reg_dest, pos); stack_info_t *si = &emit->stack_info[emit->stack_size - pos]; *vtype = si->vtype; @@ -925,7 +918,7 @@ STATIC void emit_access_stack(emit_t *emit, int pos, vtype_kind_t *vtype, int re // does an efficient X=pop(); discard(); push(X) // needs a (non-temp) register in case the popped element was stored in the stack -STATIC void emit_fold_stack_top(emit_t *emit, int reg_dest) { +static void emit_fold_stack_top(emit_t *emit, int reg_dest) { stack_info_t *si = &emit->stack_info[emit->stack_size - 2]; si[0] = si[1]; if (si->kind == STACK_VALUE) { @@ -939,7 +932,7 @@ STATIC void emit_fold_stack_top(emit_t *emit, int reg_dest) { // If stacked value is in a register and the register is not r1 or r2, then // *reg_dest is set to that register. Otherwise the value is put in *reg_dest. -STATIC void emit_pre_pop_reg_flexible(emit_t *emit, vtype_kind_t *vtype, int *reg_dest, int not_r1, int not_r2) { +static void emit_pre_pop_reg_flexible(emit_t *emit, vtype_kind_t *vtype, int *reg_dest, int not_r1, int not_r2) { stack_info_t *si = peek_stack(emit, 0); if (si->kind == STACK_REG && si->data.u_reg != not_r1 && si->data.u_reg != not_r2) { *vtype = si->vtype; @@ -951,36 +944,36 @@ STATIC void emit_pre_pop_reg_flexible(emit_t *emit, vtype_kind_t *vtype, int *re adjust_stack(emit, -1); } -STATIC void emit_pre_pop_discard(emit_t *emit) { +static void emit_pre_pop_discard(emit_t *emit) { adjust_stack(emit, -1); } -STATIC void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg_dest) { +static void emit_pre_pop_reg(emit_t *emit, vtype_kind_t *vtype, int reg_dest) { emit_access_stack(emit, 1, vtype, reg_dest); adjust_stack(emit, -1); } -STATIC void emit_pre_pop_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb) { +static void emit_pre_pop_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb) { emit_pre_pop_reg(emit, vtypea, rega); emit_pre_pop_reg(emit, vtypeb, regb); } -STATIC void emit_pre_pop_reg_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb, vtype_kind_t *vtypec, int regc) { +static void emit_pre_pop_reg_reg_reg(emit_t *emit, vtype_kind_t *vtypea, int rega, vtype_kind_t *vtypeb, int regb, vtype_kind_t *vtypec, int regc) { emit_pre_pop_reg(emit, vtypea, rega); emit_pre_pop_reg(emit, vtypeb, regb); emit_pre_pop_reg(emit, vtypec, regc); } -STATIC void emit_post(emit_t *emit) { +static void emit_post(emit_t *emit) { (void)emit; } -STATIC void emit_post_top_set_vtype(emit_t *emit, vtype_kind_t new_vtype) { +static void emit_post_top_set_vtype(emit_t *emit, vtype_kind_t new_vtype) { stack_info_t *si = &emit->stack_info[emit->stack_size - 1]; si->vtype = new_vtype; } -STATIC void emit_post_push_reg(emit_t *emit, vtype_kind_t vtype, int reg) { +static void emit_post_push_reg(emit_t *emit, vtype_kind_t vtype, int reg) { ensure_extra_stack(emit, 1); stack_info_t *si = &emit->stack_info[emit->stack_size]; si->vtype = vtype; @@ -989,7 +982,7 @@ STATIC void emit_post_push_reg(emit_t *emit, vtype_kind_t vtype, int reg) { adjust_stack(emit, 1); } -STATIC void emit_post_push_imm(emit_t *emit, vtype_kind_t vtype, mp_int_t imm) { +static void emit_post_push_imm(emit_t *emit, vtype_kind_t vtype, mp_int_t imm) { ensure_extra_stack(emit, 1); stack_info_t *si = &emit->stack_info[emit->stack_size]; si->vtype = vtype; @@ -998,43 +991,43 @@ STATIC void emit_post_push_imm(emit_t *emit, vtype_kind_t vtype, mp_int_t imm) { adjust_stack(emit, 1); } -STATIC void emit_post_push_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb) { +static void emit_post_push_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb) { emit_post_push_reg(emit, vtypea, rega); emit_post_push_reg(emit, vtypeb, regb); } -STATIC void emit_post_push_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb, vtype_kind_t vtypec, int regc) { +static void emit_post_push_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb, vtype_kind_t vtypec, int regc) { emit_post_push_reg(emit, vtypea, rega); emit_post_push_reg(emit, vtypeb, regb); emit_post_push_reg(emit, vtypec, regc); } -STATIC void emit_post_push_reg_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb, vtype_kind_t vtypec, int regc, vtype_kind_t vtyped, int regd) { +static void emit_post_push_reg_reg_reg_reg(emit_t *emit, vtype_kind_t vtypea, int rega, vtype_kind_t vtypeb, int regb, vtype_kind_t vtypec, int regc, vtype_kind_t vtyped, int regd) { emit_post_push_reg(emit, vtypea, rega); emit_post_push_reg(emit, vtypeb, regb); emit_post_push_reg(emit, vtypec, regc); emit_post_push_reg(emit, vtyped, regd); } -STATIC void emit_call(emit_t *emit, mp_fun_kind_t fun_kind) { +static void emit_call(emit_t *emit, mp_fun_kind_t fun_kind) { need_reg_all(emit); ASM_CALL_IND(emit->as, fun_kind); } -STATIC void emit_call_with_imm_arg(emit_t *emit, mp_fun_kind_t fun_kind, mp_int_t arg_val, int arg_reg) { +static void emit_call_with_imm_arg(emit_t *emit, mp_fun_kind_t fun_kind, mp_int_t arg_val, int arg_reg) { need_reg_all(emit); ASM_MOV_REG_IMM(emit->as, arg_reg, arg_val); ASM_CALL_IND(emit->as, fun_kind); } -STATIC void emit_call_with_2_imm_args(emit_t *emit, mp_fun_kind_t fun_kind, mp_int_t arg_val1, int arg_reg1, mp_int_t arg_val2, int arg_reg2) { +static void emit_call_with_2_imm_args(emit_t *emit, mp_fun_kind_t fun_kind, mp_int_t arg_val1, int arg_reg1, mp_int_t arg_val2, int arg_reg2) { need_reg_all(emit); ASM_MOV_REG_IMM(emit->as, arg_reg1, arg_val1); ASM_MOV_REG_IMM(emit->as, arg_reg2, arg_val2); ASM_CALL_IND(emit->as, fun_kind); } -STATIC void emit_call_with_qstr_arg(emit_t *emit, mp_fun_kind_t fun_kind, qstr qst, int arg_reg) { +static void emit_call_with_qstr_arg(emit_t *emit, mp_fun_kind_t fun_kind, qstr qst, int arg_reg) { need_reg_all(emit); emit_native_mov_reg_qstr(emit, arg_reg, qst); ASM_CALL_IND(emit->as, fun_kind); @@ -1044,7 +1037,7 @@ STATIC void emit_call_with_qstr_arg(emit_t *emit, mp_fun_kind_t fun_kind, qstr q // Will convert any items that are not VTYPE_PYOBJ to this type and put them back on the stack. // If any conversions of non-immediate values are needed, then it uses REG_ARG_1, REG_ARG_2 and REG_RET. // Otherwise, it does not use any temporary registers (but may use reg_dest before loading it with stack pointer). -STATIC void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, mp_uint_t reg_dest, mp_uint_t n_pop) { +static void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, mp_uint_t reg_dest, mp_uint_t n_pop) { need_reg_all(emit); // First, store any immediate values to their respective place on the stack. @@ -1081,7 +1074,7 @@ STATIC void emit_get_stack_pointer_to_reg_for_pop(emit_t *emit, mp_uint_t reg_de } // vtype of all n_push objects is VTYPE_PYOBJ -STATIC void emit_get_stack_pointer_to_reg_for_push(emit_t *emit, mp_uint_t reg_dest, mp_uint_t n_push) { +static void emit_get_stack_pointer_to_reg_for_push(emit_t *emit, mp_uint_t reg_dest, mp_uint_t n_push) { need_reg_all(emit); ensure_extra_stack(emit, n_push); for (mp_uint_t i = 0; i < n_push; i++) { @@ -1092,7 +1085,7 @@ STATIC void emit_get_stack_pointer_to_reg_for_push(emit_t *emit, mp_uint_t reg_d adjust_stack(emit, n_push); } -STATIC void emit_native_push_exc_stack(emit_t *emit, uint label, bool is_finally) { +static void emit_native_push_exc_stack(emit_t *emit, uint label, bool is_finally) { if (emit->exc_stack_size + 1 > emit->exc_stack_alloc) { size_t new_alloc = emit->exc_stack_alloc + 4; emit->exc_stack = m_renew(exc_stack_entry_t, emit->exc_stack, emit->exc_stack_alloc, new_alloc); @@ -1109,7 +1102,7 @@ STATIC void emit_native_push_exc_stack(emit_t *emit, uint label, bool is_finally ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_EXC_HANDLER_PC(emit), REG_RET); } -STATIC void emit_native_leave_exc_stack(emit_t *emit, bool start_of_handler) { +static void emit_native_leave_exc_stack(emit_t *emit, bool start_of_handler) { assert(emit->exc_stack_size > 0); // Get current exception handler and deactivate it @@ -1135,14 +1128,14 @@ STATIC void emit_native_leave_exc_stack(emit_t *emit, bool start_of_handler) { ASM_MOV_LOCAL_REG(emit->as, LOCAL_IDX_EXC_HANDLER_PC(emit), REG_RET); } -STATIC exc_stack_entry_t *emit_native_pop_exc_stack(emit_t *emit) { +static exc_stack_entry_t *emit_native_pop_exc_stack(emit_t *emit) { assert(emit->exc_stack_size > 0); exc_stack_entry_t *e = &emit->exc_stack[--emit->exc_stack_size]; assert(e->is_active == false); return e; } -STATIC void emit_load_reg_with_object(emit_t *emit, int reg, mp_obj_t obj) { +static void emit_load_reg_with_object(emit_t *emit, int reg, mp_obj_t obj) { emit->scope->scope_flags |= MP_SCOPE_FLAG_HASCONSTS; size_t table_off = mp_emit_common_use_const_obj(emit->emit_common, obj); emit_native_mov_reg_state(emit, REG_TEMP0, LOCAL_IDX_FUN_OBJ(emit)); @@ -1151,14 +1144,14 @@ STATIC void emit_load_reg_with_object(emit_t *emit, int reg, mp_obj_t obj) { ASM_LOAD_REG_REG_OFFSET(emit->as, reg, REG_TEMP0, table_off); } -STATIC void emit_load_reg_with_child(emit_t *emit, int reg, mp_raw_code_t *rc) { +static void emit_load_reg_with_child(emit_t *emit, int reg, mp_raw_code_t *rc) { size_t table_off = mp_emit_common_alloc_const_child(emit->emit_common, rc); emit_native_mov_reg_state(emit, REG_TEMP0, LOCAL_IDX_FUN_OBJ(emit)); ASM_LOAD_REG_REG_OFFSET(emit->as, REG_TEMP0, REG_TEMP0, OFFSETOF_OBJ_FUN_BC_CHILD_TABLE); ASM_LOAD_REG_REG_OFFSET(emit->as, reg, REG_TEMP0, table_off); } -STATIC void emit_native_label_assign(emit_t *emit, mp_uint_t l) { +static void emit_native_label_assign(emit_t *emit, mp_uint_t l) { DEBUG_printf("label_assign(" UINT_FMT ")\n", l); bool is_finally = false; @@ -1186,7 +1179,7 @@ STATIC void emit_native_label_assign(emit_t *emit, mp_uint_t l) { } } -STATIC void emit_native_global_exc_entry(emit_t *emit) { +static void emit_native_global_exc_entry(emit_t *emit) { // Note: 4 labels are reserved for this function, starting at *emit->label_slot emit->exit_label = *emit->label_slot; @@ -1288,7 +1281,7 @@ STATIC void emit_native_global_exc_entry(emit_t *emit) { } } -STATIC void emit_native_global_exc_exit(emit_t *emit) { +static void emit_native_global_exc_exit(emit_t *emit) { // Label for end of function emit_native_label_assign(emit, emit->exit_label); @@ -1323,7 +1316,7 @@ STATIC void emit_native_global_exc_exit(emit_t *emit) { ASM_EXIT(emit->as); } -STATIC void emit_native_import_name(emit_t *emit, qstr qst) { +static void emit_native_import_name(emit_t *emit, qstr qst) { DEBUG_printf("import_name %s\n", qstr_str(qst)); // get arguments from stack: arg2 = fromlist, arg3 = level @@ -1342,7 +1335,7 @@ STATIC void emit_native_import_name(emit_t *emit, qstr qst) { emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_import_from(emit_t *emit, qstr qst) { +static void emit_native_import_from(emit_t *emit, qstr qst) { DEBUG_printf("import_from %s\n", qstr_str(qst)); emit_native_pre(emit); vtype_kind_t vtype_module; @@ -1352,7 +1345,7 @@ STATIC void emit_native_import_from(emit_t *emit, qstr qst) { emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_import_star(emit_t *emit) { +static void emit_native_import_star(emit_t *emit) { DEBUG_printf("import_star\n"); vtype_kind_t vtype_module; emit_pre_pop_reg(emit, &vtype_module, REG_ARG_1); // arg1 = module @@ -1361,7 +1354,7 @@ STATIC void emit_native_import_star(emit_t *emit) { emit_post(emit); } -STATIC void emit_native_import(emit_t *emit, qstr qst, int kind) { +static void emit_native_import(emit_t *emit, qstr qst, int kind) { if (kind == MP_EMIT_IMPORT_NAME) { emit_native_import_name(emit, qst); } else if (kind == MP_EMIT_IMPORT_FROM) { @@ -1371,7 +1364,7 @@ STATIC void emit_native_import(emit_t *emit, qstr qst, int kind) { } } -STATIC void emit_native_load_const_tok(emit_t *emit, mp_token_kind_t tok) { +static void emit_native_load_const_tok(emit_t *emit, mp_token_kind_t tok) { DEBUG_printf("load_const_tok(tok=%u)\n", tok); if (tok == MP_TOKEN_ELLIPSIS) { emit_native_load_const_obj(emit, MP_OBJ_FROM_PTR(&mp_const_ellipsis_obj)); @@ -1385,13 +1378,13 @@ STATIC void emit_native_load_const_tok(emit_t *emit, mp_token_kind_t tok) { } } -STATIC void emit_native_load_const_small_int(emit_t *emit, mp_int_t arg) { +static void emit_native_load_const_small_int(emit_t *emit, mp_int_t arg) { DEBUG_printf("load_const_small_int(int=" INT_FMT ")\n", arg); emit_native_pre(emit); emit_post_push_imm(emit, VTYPE_INT, arg); } -STATIC void emit_native_load_const_str(emit_t *emit, qstr qst) { +static void emit_native_load_const_str(emit_t *emit, qstr qst) { emit_native_pre(emit); // TODO: Eventually we want to be able to work with raw pointers in viper to // do native array access. For now we just load them as any other object. @@ -1408,19 +1401,19 @@ STATIC void emit_native_load_const_str(emit_t *emit, qstr qst) { } } -STATIC void emit_native_load_const_obj(emit_t *emit, mp_obj_t obj) { +static void emit_native_load_const_obj(emit_t *emit, mp_obj_t obj) { emit_native_pre(emit); need_reg_single(emit, REG_RET, 0); emit_load_reg_with_object(emit, REG_RET, obj); emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_load_null(emit_t *emit) { +static void emit_native_load_null(emit_t *emit) { emit_native_pre(emit); emit_post_push_imm(emit, VTYPE_PYOBJ, 0); } -STATIC void emit_native_load_fast(emit_t *emit, qstr qst, mp_uint_t local_num) { +static void emit_native_load_fast(emit_t *emit, qstr qst, mp_uint_t local_num) { DEBUG_printf("load_fast(%s, " UINT_FMT ")\n", qstr_str(qst), local_num); vtype_kind_t vtype = emit->local_vtype[local_num]; if (vtype == VTYPE_UNBOUND) { @@ -1436,7 +1429,7 @@ STATIC void emit_native_load_fast(emit_t *emit, qstr qst, mp_uint_t local_num) { } } -STATIC void emit_native_load_deref(emit_t *emit, qstr qst, mp_uint_t local_num) { +static void emit_native_load_deref(emit_t *emit, qstr qst, mp_uint_t local_num) { DEBUG_printf("load_deref(%s, " UINT_FMT ")\n", qstr_str(qst), local_num); need_reg_single(emit, REG_RET, 0); emit_native_load_fast(emit, qst, local_num); @@ -1448,7 +1441,7 @@ STATIC void emit_native_load_deref(emit_t *emit, qstr qst, mp_uint_t local_num) emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_load_local(emit_t *emit, qstr qst, mp_uint_t local_num, int kind) { +static void emit_native_load_local(emit_t *emit, qstr qst, mp_uint_t local_num, int kind) { if (kind == MP_EMIT_IDOP_LOCAL_FAST) { emit_native_load_fast(emit, qst, local_num); } else { @@ -1456,7 +1449,7 @@ STATIC void emit_native_load_local(emit_t *emit, qstr qst, mp_uint_t local_num, } } -STATIC void emit_native_load_global(emit_t *emit, qstr qst, int kind) { +static void emit_native_load_global(emit_t *emit, qstr qst, int kind) { MP_STATIC_ASSERT(MP_F_LOAD_NAME + MP_EMIT_IDOP_GLOBAL_NAME == MP_F_LOAD_NAME); MP_STATIC_ASSERT(MP_F_LOAD_NAME + MP_EMIT_IDOP_GLOBAL_GLOBAL == MP_F_LOAD_GLOBAL); emit_native_pre(emit); @@ -1477,7 +1470,7 @@ STATIC void emit_native_load_global(emit_t *emit, qstr qst, int kind) { emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_load_attr(emit_t *emit, qstr qst) { +static void emit_native_load_attr(emit_t *emit, qstr qst) { // depends on type of subject: // - integer, function, pointer to integers: error // - pointer to structure: get member, quite easy @@ -1489,7 +1482,7 @@ STATIC void emit_native_load_attr(emit_t *emit, qstr qst) { emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_load_method(emit_t *emit, qstr qst, bool is_super) { +static void emit_native_load_method(emit_t *emit, qstr qst, bool is_super) { if (is_super) { emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_2, 3); // arg2 = dest ptr emit_get_stack_pointer_to_reg_for_push(emit, REG_ARG_2, 2); // arg2 = dest ptr @@ -1503,13 +1496,13 @@ STATIC void emit_native_load_method(emit_t *emit, qstr qst, bool is_super) { } } -STATIC void emit_native_load_build_class(emit_t *emit) { +static void emit_native_load_build_class(emit_t *emit) { emit_native_pre(emit); emit_call(emit, MP_F_LOAD_BUILD_CLASS); emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_load_subscr(emit_t *emit) { +static void emit_native_load_subscr(emit_t *emit) { DEBUG_printf("load_subscr\n"); // need to compile: base[index] @@ -1649,7 +1642,7 @@ STATIC void emit_native_load_subscr(emit_t *emit) { } } -STATIC void emit_native_store_fast(emit_t *emit, qstr qst, mp_uint_t local_num) { +static void emit_native_store_fast(emit_t *emit, qstr qst, mp_uint_t local_num) { vtype_kind_t vtype; if (local_num < MAX_REGS_FOR_LOCAL_VARS && CAN_USE_REGS_FOR_LOCALS(emit)) { emit_pre_pop_reg(emit, &vtype, reg_local_table[local_num]); @@ -1671,7 +1664,7 @@ STATIC void emit_native_store_fast(emit_t *emit, qstr qst, mp_uint_t local_num) } } -STATIC void emit_native_store_deref(emit_t *emit, qstr qst, mp_uint_t local_num) { +static void emit_native_store_deref(emit_t *emit, qstr qst, mp_uint_t local_num) { DEBUG_printf("store_deref(%s, " UINT_FMT ")\n", qstr_str(qst), local_num); need_reg_single(emit, REG_TEMP0, 0); need_reg_single(emit, REG_TEMP1, 0); @@ -1685,7 +1678,7 @@ STATIC void emit_native_store_deref(emit_t *emit, qstr qst, mp_uint_t local_num) emit_post(emit); } -STATIC void emit_native_store_local(emit_t *emit, qstr qst, mp_uint_t local_num, int kind) { +static void emit_native_store_local(emit_t *emit, qstr qst, mp_uint_t local_num, int kind) { if (kind == MP_EMIT_IDOP_LOCAL_FAST) { emit_native_store_fast(emit, qst, local_num); } else { @@ -1693,7 +1686,7 @@ STATIC void emit_native_store_local(emit_t *emit, qstr qst, mp_uint_t local_num, } } -STATIC void emit_native_store_global(emit_t *emit, qstr qst, int kind) { +static void emit_native_store_global(emit_t *emit, qstr qst, int kind) { MP_STATIC_ASSERT(MP_F_STORE_NAME + MP_EMIT_IDOP_GLOBAL_NAME == MP_F_STORE_NAME); MP_STATIC_ASSERT(MP_F_STORE_NAME + MP_EMIT_IDOP_GLOBAL_GLOBAL == MP_F_STORE_GLOBAL); if (kind == MP_EMIT_IDOP_GLOBAL_NAME) { @@ -1715,7 +1708,7 @@ STATIC void emit_native_store_global(emit_t *emit, qstr qst, int kind) { emit_post(emit); } -STATIC void emit_native_store_attr(emit_t *emit, qstr qst) { +static void emit_native_store_attr(emit_t *emit, qstr qst) { vtype_kind_t vtype_base; vtype_kind_t vtype_val = peek_vtype(emit, 1); if (vtype_val == VTYPE_PYOBJ) { @@ -1732,7 +1725,7 @@ STATIC void emit_native_store_attr(emit_t *emit, qstr qst) { emit_post(emit); } -STATIC void emit_native_store_subscr(emit_t *emit) { +static void emit_native_store_subscr(emit_t *emit) { DEBUG_printf("store_subscr\n"); // need to compile: base[index] = value @@ -1909,7 +1902,7 @@ STATIC void emit_native_store_subscr(emit_t *emit) { } } -STATIC void emit_native_delete_local(emit_t *emit, qstr qst, mp_uint_t local_num, int kind) { +static void emit_native_delete_local(emit_t *emit, qstr qst, mp_uint_t local_num, int kind) { if (kind == MP_EMIT_IDOP_LOCAL_FAST) { // TODO: This is not compliant implementation. We could use MP_OBJ_SENTINEL // to mark deleted vars but then every var would need to be checked on @@ -1921,7 +1914,7 @@ STATIC void emit_native_delete_local(emit_t *emit, qstr qst, mp_uint_t local_num } } -STATIC void emit_native_delete_global(emit_t *emit, qstr qst, int kind) { +static void emit_native_delete_global(emit_t *emit, qstr qst, int kind) { MP_STATIC_ASSERT(MP_F_DELETE_NAME + MP_EMIT_IDOP_GLOBAL_NAME == MP_F_DELETE_NAME); MP_STATIC_ASSERT(MP_F_DELETE_NAME + MP_EMIT_IDOP_GLOBAL_GLOBAL == MP_F_DELETE_GLOBAL); emit_native_pre(emit); @@ -1929,7 +1922,7 @@ STATIC void emit_native_delete_global(emit_t *emit, qstr qst, int kind) { emit_post(emit); } -STATIC void emit_native_delete_attr(emit_t *emit, qstr qst) { +static void emit_native_delete_attr(emit_t *emit, qstr qst) { vtype_kind_t vtype_base; emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = base assert(vtype_base == VTYPE_PYOBJ); @@ -1938,7 +1931,7 @@ STATIC void emit_native_delete_attr(emit_t *emit, qstr qst) { emit_post(emit); } -STATIC void emit_native_delete_subscr(emit_t *emit) { +static void emit_native_delete_subscr(emit_t *emit) { vtype_kind_t vtype_index, vtype_base; emit_pre_pop_reg_reg(emit, &vtype_index, REG_ARG_2, &vtype_base, REG_ARG_1); // index, base assert(vtype_index == VTYPE_PYOBJ); @@ -1946,7 +1939,7 @@ STATIC void emit_native_delete_subscr(emit_t *emit) { emit_call_with_imm_arg(emit, MP_F_OBJ_SUBSCR, (mp_uint_t)MP_OBJ_NULL, REG_ARG_3); } -STATIC void emit_native_subscr(emit_t *emit, int kind) { +static void emit_native_subscr(emit_t *emit, int kind) { if (kind == MP_EMIT_SUBSCR_LOAD) { emit_native_load_subscr(emit); } else if (kind == MP_EMIT_SUBSCR_STORE) { @@ -1956,7 +1949,7 @@ STATIC void emit_native_subscr(emit_t *emit, int kind) { } } -STATIC void emit_native_attr(emit_t *emit, qstr qst, int kind) { +static void emit_native_attr(emit_t *emit, qstr qst, int kind) { if (kind == MP_EMIT_ATTR_LOAD) { emit_native_load_attr(emit, qst); } else if (kind == MP_EMIT_ATTR_STORE) { @@ -1966,7 +1959,7 @@ STATIC void emit_native_attr(emit_t *emit, qstr qst, int kind) { } } -STATIC void emit_native_dup_top(emit_t *emit) { +static void emit_native_dup_top(emit_t *emit) { DEBUG_printf("dup_top\n"); vtype_kind_t vtype; int reg = REG_TEMP0; @@ -1974,33 +1967,33 @@ STATIC void emit_native_dup_top(emit_t *emit) { emit_post_push_reg_reg(emit, vtype, reg, vtype, reg); } -STATIC void emit_native_dup_top_two(emit_t *emit) { +static void emit_native_dup_top_two(emit_t *emit) { vtype_kind_t vtype0, vtype1; emit_pre_pop_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1); emit_post_push_reg_reg_reg_reg(emit, vtype1, REG_TEMP1, vtype0, REG_TEMP0, vtype1, REG_TEMP1, vtype0, REG_TEMP0); } -STATIC void emit_native_pop_top(emit_t *emit) { +static void emit_native_pop_top(emit_t *emit) { DEBUG_printf("pop_top\n"); emit_pre_pop_discard(emit); emit_post(emit); } -STATIC void emit_native_rot_two(emit_t *emit) { +static void emit_native_rot_two(emit_t *emit) { DEBUG_printf("rot_two\n"); vtype_kind_t vtype0, vtype1; emit_pre_pop_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1); emit_post_push_reg_reg(emit, vtype0, REG_TEMP0, vtype1, REG_TEMP1); } -STATIC void emit_native_rot_three(emit_t *emit) { +static void emit_native_rot_three(emit_t *emit) { DEBUG_printf("rot_three\n"); vtype_kind_t vtype0, vtype1, vtype2; emit_pre_pop_reg_reg_reg(emit, &vtype0, REG_TEMP0, &vtype1, REG_TEMP1, &vtype2, REG_TEMP2); emit_post_push_reg_reg_reg(emit, vtype0, REG_TEMP0, vtype2, REG_TEMP2, vtype1, REG_TEMP1); } -STATIC void emit_native_jump(emit_t *emit, mp_uint_t label) { +static void emit_native_jump(emit_t *emit, mp_uint_t label) { DEBUG_printf("jump(label=" UINT_FMT ")\n", label); emit_native_pre(emit); // need to commit stack because we are jumping elsewhere @@ -2010,7 +2003,7 @@ STATIC void emit_native_jump(emit_t *emit, mp_uint_t label) { mp_asm_base_suppress_code(&emit->as->base); } -STATIC void emit_native_jump_helper(emit_t *emit, bool cond, mp_uint_t label, bool pop) { +static void emit_native_jump_helper(emit_t *emit, bool cond, mp_uint_t label, bool pop) { vtype_kind_t vtype = peek_vtype(emit, 0); if (vtype == VTYPE_PYOBJ) { emit_pre_pop_reg(emit, &vtype, REG_ARG_1); @@ -2047,17 +2040,17 @@ STATIC void emit_native_jump_helper(emit_t *emit, bool cond, mp_uint_t label, bo emit_post(emit); } -STATIC void emit_native_pop_jump_if(emit_t *emit, bool cond, mp_uint_t label) { +static void emit_native_pop_jump_if(emit_t *emit, bool cond, mp_uint_t label) { DEBUG_printf("pop_jump_if(cond=%u, label=" UINT_FMT ")\n", cond, label); emit_native_jump_helper(emit, cond, label, true); } -STATIC void emit_native_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label) { +static void emit_native_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label) { DEBUG_printf("jump_if_or_pop(cond=%u, label=" UINT_FMT ")\n", cond, label); emit_native_jump_helper(emit, cond, label, false); } -STATIC void emit_native_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) { +static void emit_native_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) { if (except_depth > 0) { exc_stack_entry_t *first_finally = NULL; exc_stack_entry_t *prev_finally = NULL; @@ -2100,7 +2093,7 @@ STATIC void emit_native_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t exc emit_native_jump(emit, label & ~MP_EMIT_BREAK_FROM_FOR); } -STATIC void emit_native_setup_with(emit_t *emit, mp_uint_t label) { +static void emit_native_setup_with(emit_t *emit, mp_uint_t label) { // the context manager is on the top of the stack // stack: (..., ctx_mgr) @@ -2139,7 +2132,7 @@ STATIC void emit_native_setup_with(emit_t *emit, mp_uint_t label) { // stack: (..., __exit__, self, as_value, as_value) } -STATIC void emit_native_setup_block(emit_t *emit, mp_uint_t label, int kind) { +static void emit_native_setup_block(emit_t *emit, mp_uint_t label, int kind) { if (kind == MP_EMIT_SETUP_BLOCK_WITH) { emit_native_setup_with(emit, label); } else { @@ -2151,7 +2144,7 @@ STATIC void emit_native_setup_block(emit_t *emit, mp_uint_t label, int kind) { } } -STATIC void emit_native_with_cleanup(emit_t *emit, mp_uint_t label) { +static void emit_native_with_cleanup(emit_t *emit, mp_uint_t label) { // Note: 3 labels are reserved for this function, starting at *emit->label_slot // stack: (..., __exit__, self, as_value) @@ -2218,7 +2211,7 @@ STATIC void emit_native_with_cleanup(emit_t *emit, mp_uint_t label) { // Exception is in nlr_buf.ret_val slot } -STATIC void emit_native_end_finally(emit_t *emit) { +static void emit_native_end_finally(emit_t *emit) { // logic: // exc = pop_stack // if exc == None: pass @@ -2244,7 +2237,7 @@ STATIC void emit_native_end_finally(emit_t *emit) { emit_post(emit); } -STATIC void emit_native_get_iter(emit_t *emit, bool use_stack) { +static void emit_native_get_iter(emit_t *emit, bool use_stack) { // perhaps the difficult one, as we want to rewrite for loops using native code // in cases where we iterate over a Python object, can we use normal runtime calls? @@ -2262,7 +2255,7 @@ STATIC void emit_native_get_iter(emit_t *emit, bool use_stack) { } } -STATIC void emit_native_for_iter(emit_t *emit, mp_uint_t label) { +static void emit_native_for_iter(emit_t *emit, mp_uint_t label) { emit_native_pre(emit); emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_1, MP_OBJ_ITER_BUF_NSLOTS); adjust_stack(emit, MP_OBJ_ITER_BUF_NSLOTS); @@ -2277,14 +2270,14 @@ STATIC void emit_native_for_iter(emit_t *emit, mp_uint_t label) { emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_for_iter_end(emit_t *emit) { +static void emit_native_for_iter_end(emit_t *emit) { // adjust stack counter (we get here from for_iter ending, which popped the value for us) emit_native_pre(emit); adjust_stack(emit, -MP_OBJ_ITER_BUF_NSLOTS); emit_post(emit); } -STATIC void emit_native_pop_except_jump(emit_t *emit, mp_uint_t label, bool within_exc_handler) { +static void emit_native_pop_except_jump(emit_t *emit, mp_uint_t label, bool within_exc_handler) { if (within_exc_handler) { // Cancel any active exception so subsequent handlers don't see it ASM_MOV_REG_IMM(emit->as, REG_TEMP0, (mp_uint_t)MP_OBJ_NULL); @@ -2295,20 +2288,43 @@ STATIC void emit_native_pop_except_jump(emit_t *emit, mp_uint_t label, bool with emit_native_jump(emit, label); } -STATIC void emit_native_unary_op(emit_t *emit, mp_unary_op_t op) { - vtype_kind_t vtype; - emit_pre_pop_reg(emit, &vtype, REG_ARG_2); - if (vtype == VTYPE_PYOBJ) { +static void emit_native_unary_op(emit_t *emit, mp_unary_op_t op) { + vtype_kind_t vtype = peek_vtype(emit, 0); + if (vtype == VTYPE_INT || vtype == VTYPE_UINT) { + if (op == MP_UNARY_OP_POSITIVE) { + // No-operation, just leave the argument on the stack. + } else if (op == MP_UNARY_OP_NEGATIVE) { + int reg = REG_RET; + emit_pre_pop_reg_flexible(emit, &vtype, ®, reg, reg); + ASM_NEG_REG(emit->as, reg); + emit_post_push_reg(emit, vtype, reg); + } else if (op == MP_UNARY_OP_INVERT) { + #ifdef ASM_NOT_REG + int reg = REG_RET; + emit_pre_pop_reg_flexible(emit, &vtype, ®, reg, reg); + ASM_NOT_REG(emit->as, reg); + #else + int reg = REG_RET; + emit_pre_pop_reg_flexible(emit, &vtype, ®, REG_ARG_1, reg); + ASM_MOV_REG_IMM(emit->as, REG_ARG_1, -1); + ASM_XOR_REG_REG(emit->as, reg, REG_ARG_1); + #endif + emit_post_push_reg(emit, vtype, reg); + } else { + EMIT_NATIVE_VIPER_TYPE_ERROR(emit, + MP_ERROR_TEXT("'not' not implemented"), mp_binary_op_method_name[op]); + } + } else if (vtype == VTYPE_PYOBJ) { + emit_pre_pop_reg(emit, &vtype, REG_ARG_2); emit_call_with_imm_arg(emit, MP_F_UNARY_OP, op, REG_ARG_1); emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } else { - adjust_stack(emit, 1); EMIT_NATIVE_VIPER_TYPE_ERROR(emit, - MP_ERROR_TEXT("unary op %q not implemented"), mp_unary_op_method_name[op]); + MP_ERROR_TEXT("can't do unary op of '%q'"), vtype_to_qstr(vtype)); } } -STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) { +static void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) { DEBUG_printf("binary_op(" UINT_FMT ")\n", op); vtype_kind_t vtype_lhs = peek_vtype(emit, 1); vtype_kind_t vtype_rhs = peek_vtype(emit, 0); @@ -2571,10 +2587,10 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) { } #if MICROPY_PY_BUILTINS_SLICE -STATIC void emit_native_build_slice(emit_t *emit, mp_uint_t n_args); +static void emit_native_build_slice(emit_t *emit, mp_uint_t n_args); #endif -STATIC void emit_native_build(emit_t *emit, mp_uint_t n_args, int kind) { +static void emit_native_build(emit_t *emit, mp_uint_t n_args, int kind) { // for viper: call runtime, with types of args // if wrapped in byte_array, or something, allocates memory and fills it MP_STATIC_ASSERT(MP_F_BUILD_TUPLE + MP_EMIT_BUILD_TUPLE == MP_F_BUILD_TUPLE); @@ -2595,7 +2611,7 @@ STATIC void emit_native_build(emit_t *emit, mp_uint_t n_args, int kind) { emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); // new tuple/list/map/set } -STATIC void emit_native_store_map(emit_t *emit) { +static void emit_native_store_map(emit_t *emit) { vtype_kind_t vtype_key, vtype_value, vtype_map; emit_pre_pop_reg_reg_reg(emit, &vtype_key, REG_ARG_2, &vtype_value, REG_ARG_3, &vtype_map, REG_ARG_1); // key, value, map assert(vtype_key == VTYPE_PYOBJ); @@ -2606,7 +2622,7 @@ STATIC void emit_native_store_map(emit_t *emit) { } #if MICROPY_PY_BUILTINS_SLICE -STATIC void emit_native_build_slice(emit_t *emit, mp_uint_t n_args) { +static void emit_native_build_slice(emit_t *emit, mp_uint_t n_args) { DEBUG_printf("build_slice %d\n", n_args); if (n_args == 2) { vtype_kind_t vtype_start, vtype_stop; @@ -2627,7 +2643,7 @@ STATIC void emit_native_build_slice(emit_t *emit, mp_uint_t n_args) { } #endif -STATIC void emit_native_store_comp(emit_t *emit, scope_kind_t kind, mp_uint_t collection_index) { +static void emit_native_store_comp(emit_t *emit, scope_kind_t kind, mp_uint_t collection_index) { mp_fun_kind_t f; if (kind == SCOPE_LIST_COMP) { vtype_kind_t vtype_item; @@ -2656,7 +2672,7 @@ STATIC void emit_native_store_comp(emit_t *emit, scope_kind_t kind, mp_uint_t co emit_post(emit); } -STATIC void emit_native_unpack_sequence(emit_t *emit, mp_uint_t n_args) { +static void emit_native_unpack_sequence(emit_t *emit, mp_uint_t n_args) { DEBUG_printf("unpack_sequence %d\n", n_args); vtype_kind_t vtype_base; emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = seq @@ -2665,7 +2681,7 @@ STATIC void emit_native_unpack_sequence(emit_t *emit, mp_uint_t n_args) { emit_call_with_imm_arg(emit, MP_F_UNPACK_SEQUENCE, n_args, REG_ARG_2); // arg2 = n_args } -STATIC void emit_native_unpack_ex(emit_t *emit, mp_uint_t n_left, mp_uint_t n_right) { +static void emit_native_unpack_ex(emit_t *emit, mp_uint_t n_left, mp_uint_t n_right) { DEBUG_printf("unpack_ex %d %d\n", n_left, n_right); vtype_kind_t vtype_base; emit_pre_pop_reg(emit, &vtype_base, REG_ARG_1); // arg1 = seq @@ -2674,7 +2690,7 @@ STATIC void emit_native_unpack_ex(emit_t *emit, mp_uint_t n_left, mp_uint_t n_ri emit_call_with_imm_arg(emit, MP_F_UNPACK_EX, n_left | (n_right << 8), REG_ARG_2); // arg2 = n_left + n_right } -STATIC void emit_native_make_function(emit_t *emit, scope_t *scope, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults) { +static void emit_native_make_function(emit_t *emit, scope_t *scope, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults) { // call runtime, with type info for args, or don't support dict/default params, or only support Python objects for them emit_native_pre(emit); emit_native_mov_reg_state(emit, REG_ARG_2, LOCAL_IDX_FUN_OBJ(emit)); @@ -2687,11 +2703,11 @@ STATIC void emit_native_make_function(emit_t *emit, scope_t *scope, mp_uint_t n_ need_reg_all(emit); } emit_load_reg_with_child(emit, REG_ARG_1, scope->raw_code); - ASM_CALL_IND(emit->as, MP_F_MAKE_FUNCTION_FROM_RAW_CODE); + ASM_CALL_IND(emit->as, MP_F_MAKE_FUNCTION_FROM_PROTO_FUN); emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_closed_over, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults) { +static void emit_native_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_closed_over, mp_uint_t n_pos_defaults, mp_uint_t n_kw_defaults) { // make function emit_native_pre(emit); emit_native_mov_reg_state(emit, REG_ARG_2, LOCAL_IDX_FUN_OBJ(emit)); @@ -2705,7 +2721,7 @@ STATIC void emit_native_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_c need_reg_all(emit); } emit_load_reg_with_child(emit, REG_ARG_1, scope->raw_code); - ASM_CALL_IND(emit->as, MP_F_MAKE_FUNCTION_FROM_RAW_CODE); + ASM_CALL_IND(emit->as, MP_F_MAKE_FUNCTION_FROM_PROTO_FUN); // make closure #if REG_ARG_1 != REG_RET @@ -2720,7 +2736,7 @@ STATIC void emit_native_make_closure(emit_t *emit, scope_t *scope, mp_uint_t n_c emit_post_push_reg(emit, VTYPE_PYOBJ, REG_RET); } -STATIC void emit_native_call_function(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) { +static void emit_native_call_function(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) { DEBUG_printf("call_function(n_pos=" UINT_FMT ", n_kw=" UINT_FMT ", star_flags=" UINT_FMT ")\n", n_positional, n_keyword, star_flags); // TODO: in viper mode, call special runtime routine with type info for args, @@ -2775,7 +2791,7 @@ STATIC void emit_native_call_function(emit_t *emit, mp_uint_t n_positional, mp_u } } -STATIC void emit_native_call_method(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) { +static void emit_native_call_method(emit_t *emit, mp_uint_t n_positional, mp_uint_t n_keyword, mp_uint_t star_flags) { if (star_flags) { emit_get_stack_pointer_to_reg_for_pop(emit, REG_ARG_3, n_positional + 2 * n_keyword + 3); // pointer to args emit_call_with_2_imm_args(emit, MP_F_CALL_METHOD_N_KW_VAR, 1, REG_ARG_1, n_positional | (n_keyword << 8), REG_ARG_2); @@ -2788,7 +2804,7 @@ STATIC void emit_native_call_method(emit_t *emit, mp_uint_t n_positional, mp_uin } } -STATIC void emit_native_return_value(emit_t *emit) { +static void emit_native_return_value(emit_t *emit) { DEBUG_printf("return_value\n"); if (emit->scope->scope_flags & MP_SCOPE_FLAG_GENERATOR) { @@ -2841,7 +2857,7 @@ STATIC void emit_native_return_value(emit_t *emit) { emit_native_unwind_jump(emit, emit->exit_label, emit->exc_stack_size); } -STATIC void emit_native_raise_varargs(emit_t *emit, mp_uint_t n_args) { +static void emit_native_raise_varargs(emit_t *emit, mp_uint_t n_args) { (void)n_args; assert(n_args == 1); vtype_kind_t vtype_exc; @@ -2854,7 +2870,7 @@ STATIC void emit_native_raise_varargs(emit_t *emit, mp_uint_t n_args) { mp_asm_base_suppress_code(&emit->as->base); } -STATIC void emit_native_yield(emit_t *emit, int kind) { +static void emit_native_yield(emit_t *emit, int kind) { // Note: 1 (yield) or 3 (yield from) labels are reserved for this function, starting at *emit->label_slot if (emit->do_viper_types) { @@ -2937,7 +2953,7 @@ STATIC void emit_native_yield(emit_t *emit, int kind) { } } -STATIC void emit_native_start_except_handler(emit_t *emit) { +static void emit_native_start_except_handler(emit_t *emit) { // Protected block has finished so leave the current exception handler emit_native_leave_exc_stack(emit, true); @@ -2946,7 +2962,7 @@ STATIC void emit_native_start_except_handler(emit_t *emit) { emit_post_push_reg(emit, VTYPE_PYOBJ, REG_TEMP0); } -STATIC void emit_native_end_except_handler(emit_t *emit) { +static void emit_native_end_except_handler(emit_t *emit) { adjust_stack(emit, -1); // pop the exception (end_finally didn't use it) } diff --git a/py/emitnx86.c b/py/emitnx86.c index a9050c65d4036..1d2aefa7920bc 100644 --- a/py/emitnx86.c +++ b/py/emitnx86.c @@ -13,7 +13,7 @@ #define NLR_BUF_IDX_LOCAL_1 (5) // ebx // x86 needs a table to know how many args a given function has -STATIC byte mp_f_n_args[MP_F_NUMBER_OF] = { +static byte mp_f_n_args[MP_F_NUMBER_OF] = { [MP_F_CONVERT_OBJ_TO_NATIVE] = 2, [MP_F_CONVERT_NATIVE_TO_OBJ] = 2, [MP_F_NATIVE_SWAP_GLOBALS] = 1, @@ -37,7 +37,7 @@ STATIC byte mp_f_n_args[MP_F_NUMBER_OF] = { [MP_F_STORE_SET] = 2, [MP_F_LIST_APPEND] = 2, [MP_F_STORE_MAP] = 3, - [MP_F_MAKE_FUNCTION_FROM_RAW_CODE] = 3, + [MP_F_MAKE_FUNCTION_FROM_PROTO_FUN] = 3, [MP_F_NATIVE_CALL_FUNCTION_N_KW] = 3, [MP_F_CALL_METHOD_N_KW] = 3, [MP_F_CALL_METHOD_N_KW_VAR] = 3, diff --git a/py/gc.c b/py/gc.c index 09b9297a21d26..5375218f3e900 100644 --- a/py/gc.c +++ b/py/gc.c @@ -144,7 +144,7 @@ void __attribute__ ((noinline)) gc_log_change(uint32_t start_block, uint32_t len #endif // TODO waste less memory; currently requires that all entries in alloc_table have a corresponding block in pool -STATIC void gc_setup_area(mp_state_mem_area_t *area, void *start, void *end) { +static void gc_setup_area(mp_state_mem_area_t *area, void *start, void *end) { // calculate parameters for GC (T=total, A=alloc table, F=finaliser table, P=pool; all in bytes): // T = A + F + P // F = A * BLOCKS_PER_ATB / BLOCKS_PER_FTB @@ -262,7 +262,7 @@ void gc_add(void *start, void *end) { #if MICROPY_GC_SPLIT_HEAP_AUTO // Try to automatically add a heap area large enough to fulfill 'failed_alloc'. -STATIC bool gc_try_add_heap(size_t failed_alloc) { +static bool gc_try_add_heap(size_t failed_alloc) { // 'needed' is the size of a heap large enough to hold failed_alloc, with // the additional metadata overheads as calculated in gc_setup_area(). // @@ -391,7 +391,7 @@ bool gc_ptr_on_heap(void *ptr) { #if MICROPY_GC_SPLIT_HEAP // Returns the area to which this pointer belongs, or NULL if it isn't // allocated on the GC-managed heap. -STATIC inline mp_state_mem_area_t *gc_get_ptr_area(const void *ptr) { +static inline mp_state_mem_area_t *gc_get_ptr_area(const void *ptr) { if (((uintptr_t)(ptr) & (BYTES_PER_BLOCK - 1)) != 0) { // must be aligned on a block return NULL; } @@ -426,9 +426,9 @@ STATIC inline mp_state_mem_area_t *gc_get_ptr_area(const void *ptr) { // topmost block on the stack and repeat with that one. // CIRCUITPY-CHANGE: We don't instrument these functions because they occur a lot during GC and #if MICROPY_GC_SPLIT_HEAP -STATIC void MP_NO_INSTRUMENT PLACE_IN_ITCM(gc_mark_subtree)(mp_state_mem_area_t * area, size_t block) +static void MP_NO_INSTRUMENT PLACE_IN_ITCM(gc_mark_subtree)(mp_state_mem_area_t * area, size_t block) #else -STATIC void MP_NO_INSTRUMENT PLACE_IN_ITCM(gc_mark_subtree)(size_t block) +static void MP_NO_INSTRUMENT PLACE_IN_ITCM(gc_mark_subtree)(size_t block) #endif { // Start with the block passed in the argument. @@ -499,7 +499,7 @@ STATIC void MP_NO_INSTRUMENT PLACE_IN_ITCM(gc_mark_subtree)(size_t block) } } -STATIC void gc_deal_with_stack_overflow(void) { +static void gc_deal_with_stack_overflow(void) { while (MP_STATE_MEM(gc_stack_overflow)) { MP_STATE_MEM(gc_stack_overflow) = 0; @@ -520,7 +520,7 @@ STATIC void gc_deal_with_stack_overflow(void) { } } -STATIC void gc_sweep(void) { +static void gc_sweep(void) { #if MICROPY_PY_GC_COLLECT_RETVAL MP_STATE_MEM(gc_collected) = 0; #endif @@ -990,6 +990,7 @@ void gc_free(void *ptr) { mp_state_mem_area_t *area; #if MICROPY_GC_SPLIT_HEAP area = gc_get_ptr_area(ptr); + // CIRCUITPY-CHANGE: don't just assert. // assert(area); #else // CIRCUITPY-CHANGE: extra checking diff --git a/py/lexer.c b/py/lexer.c index 5e911a1a23337..bff8e637656d6 100644 --- a/py/lexer.c +++ b/py/lexer.c @@ -42,74 +42,74 @@ #define MP_LEXER_EOF ((unichar)MP_READER_EOF) #define CUR_CHAR(lex) ((lex)->chr0) -STATIC bool is_end(mp_lexer_t *lex) { +static bool is_end(mp_lexer_t *lex) { return lex->chr0 == MP_LEXER_EOF; } -STATIC bool is_physical_newline(mp_lexer_t *lex) { +static bool is_physical_newline(mp_lexer_t *lex) { return lex->chr0 == '\n'; } -STATIC bool is_char(mp_lexer_t *lex, byte c) { +static bool is_char(mp_lexer_t *lex, byte c) { return lex->chr0 == c; } -STATIC bool is_char_or(mp_lexer_t *lex, byte c1, byte c2) { +static bool is_char_or(mp_lexer_t *lex, byte c1, byte c2) { return lex->chr0 == c1 || lex->chr0 == c2; } -STATIC bool is_char_or3(mp_lexer_t *lex, byte c1, byte c2, byte c3) { +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_PY_FSTRINGS -STATIC bool is_char_or4(mp_lexer_t *lex, byte c1, byte c2, byte c3, byte c4) { +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; } #endif -STATIC bool is_char_following(mp_lexer_t *lex, byte c) { +static bool is_char_following(mp_lexer_t *lex, byte c) { return lex->chr1 == c; } -STATIC bool is_char_following_or(mp_lexer_t *lex, byte c1, byte c2) { +static bool is_char_following_or(mp_lexer_t *lex, byte c1, byte c2) { return lex->chr1 == c1 || lex->chr1 == c2; } -STATIC bool is_char_following_following_or(mp_lexer_t *lex, byte c1, byte c2) { +static bool is_char_following_following_or(mp_lexer_t *lex, byte c1, byte c2) { return lex->chr2 == c1 || lex->chr2 == c2; } -STATIC bool is_char_and(mp_lexer_t *lex, byte c1, byte c2) { +static bool is_char_and(mp_lexer_t *lex, byte c1, byte c2) { return lex->chr0 == c1 && lex->chr1 == c2; } -STATIC bool is_whitespace(mp_lexer_t *lex) { +static bool is_whitespace(mp_lexer_t *lex) { return unichar_isspace(lex->chr0); } -STATIC bool is_letter(mp_lexer_t *lex) { +static bool is_letter(mp_lexer_t *lex) { return unichar_isalpha(lex->chr0); } -STATIC bool is_digit(mp_lexer_t *lex) { +static bool is_digit(mp_lexer_t *lex) { return unichar_isdigit(lex->chr0); } -STATIC bool is_following_digit(mp_lexer_t *lex) { +static bool is_following_digit(mp_lexer_t *lex) { return unichar_isdigit(lex->chr1); } -STATIC bool is_following_base_char(mp_lexer_t *lex) { +static bool is_following_base_char(mp_lexer_t *lex) { const unichar chr1 = lex->chr1 | 0x20; return chr1 == 'b' || chr1 == 'o' || chr1 == 'x'; } -STATIC bool is_following_odigit(mp_lexer_t *lex) { +static bool is_following_odigit(mp_lexer_t *lex) { return lex->chr1 >= '0' && lex->chr1 <= '7'; } -STATIC bool is_string_or_bytes(mp_lexer_t *lex) { +static bool is_string_or_bytes(mp_lexer_t *lex) { return is_char_or(lex, '\'', '\"') #if MICROPY_PY_FSTRINGS || (is_char_or4(lex, 'r', 'u', 'b', 'f') && is_char_following_or(lex, '\'', '\"')) @@ -123,15 +123,15 @@ STATIC bool is_string_or_bytes(mp_lexer_t *lex) { } // to easily parse utf-8 identifiers we allow any raw byte with high bit set -STATIC bool is_head_of_identifier(mp_lexer_t *lex) { +static bool is_head_of_identifier(mp_lexer_t *lex) { return is_letter(lex) || lex->chr0 == '_' || lex->chr0 >= 0x80; } -STATIC bool is_tail_of_identifier(mp_lexer_t *lex) { +static bool is_tail_of_identifier(mp_lexer_t *lex) { return is_head_of_identifier(lex) || is_digit(lex); } -STATIC void next_char(mp_lexer_t *lex) { +static void next_char(mp_lexer_t *lex) { if (lex->chr0 == '\n') { // a new line ++lex->line; @@ -189,7 +189,7 @@ STATIC void next_char(mp_lexer_t *lex) { } } -STATIC void indent_push(mp_lexer_t *lex, size_t indent) { +static void indent_push(mp_lexer_t *lex, size_t indent) { if (lex->num_indent_level >= lex->alloc_indent_level) { lex->indent_level = m_renew(uint16_t, lex->indent_level, lex->alloc_indent_level, lex->alloc_indent_level + MICROPY_ALLOC_LEXEL_INDENT_INC); lex->alloc_indent_level += MICROPY_ALLOC_LEXEL_INDENT_INC; @@ -197,11 +197,11 @@ STATIC void indent_push(mp_lexer_t *lex, size_t indent) { lex->indent_level[lex->num_indent_level++] = indent; } -STATIC size_t indent_top(mp_lexer_t *lex) { +static size_t indent_top(mp_lexer_t *lex) { return lex->indent_level[lex->num_indent_level - 1]; } -STATIC void indent_pop(mp_lexer_t *lex) { +static void indent_pop(mp_lexer_t *lex) { lex->num_indent_level -= 1; } @@ -211,7 +211,7 @@ STATIC void indent_pop(mp_lexer_t *lex) { // c = continue with , if this opchar matches then continue matching // this means if the start of two ops are the same then they are equal til the last char -STATIC const char *const tok_enc = +static const char *const tok_enc = "()[]{},;~" // singles ":e=" // : := "nested_bracket_level == 0) { diff --git a/py/makeqstrdata.py b/py/makeqstrdata.py index 9e84330a347c2..d778aa484449c 100644 --- a/py/makeqstrdata.py +++ b/py/makeqstrdata.py @@ -233,11 +233,11 @@ "zip", ] -# Additional QSTRs that must have index <255 because they are stored in -# `mp_binary_op_method_name` and `mp_unary_op_method_name` (see py/objtype.c). +# Additional QSTRs that must have index <255 because they are stored as `byte` values. # These are not part of the .mpy compatibility list, but we place them in the # fixed unsorted pool (i.e. QDEF0) to ensure their indices are small. -operator_qstr_list = { +unsorted_qstr_list = { + # From py/objtype.c: used in the `mp_binary_op_method_name` and `mp_unary_op_method_name` tables. "__bool__", "__pos__", "__neg__", @@ -296,6 +296,13 @@ "__get__", "__set__", "__delete__", + # From py/scope.c: used in `scope_simple_name_table` table. + # Note: "" is already in `static_qstr_list`. + "", + "", + "", + "", + "", } @@ -305,7 +312,8 @@ def compute_hash(qstr, bytes_hash): for b in qstr: hash = (hash * 33) ^ b # Make sure that valid hash is never zero, zero means "hash not computed" - return (hash & ((1 << (8 * bytes_hash)) - 1)) or 1 + # if bytes_hash is zero, assume a 16-bit mask (to match qstr.c) + return (hash & ((1 << (8 * (bytes_hash or 2))) - 1)) or 1 def qstr_escape(qst): @@ -433,10 +441,10 @@ def print_qstr_data(qcfgs, qstrs, translations): total_qstr_size = 0 # add remaining qstrs to the sorted (by value) pool (unless they're in - # operator_qstr_list, in which case add them to the unsorted pool) + # unsorted_qstr_list, in which case add them to the unsorted pool) for ident, qstr in sorted(qstrs.values(), key=lambda x: x[1]): qbytes = make_bytes(cfg_bytes_len, cfg_bytes_hash, qstr) - pool = 0 if qstr in operator_qstr_list else 1 + pool = 0 if qstr in unsorted_qstr_list else 1 print("QDEF%d(MP_QSTR_%s, %s)" % (pool, ident, qbytes)) # CIRCUITPY-CHANGE: track total qstr size diff --git a/py/makeversionhdr.py b/py/makeversionhdr.py index 72d6f3237876e..e780bc7dca16a 100644 --- a/py/makeversionhdr.py +++ b/py/makeversionhdr.py @@ -23,6 +23,7 @@ def get_version_info_from_git(repo_path): # Python 2.6 doesn't have check_output, so check for that try: subprocess.check_output + # CIRCUITPY-CHANGE: check for check_call subprocess.check_call except AttributeError: return None @@ -30,12 +31,14 @@ def get_version_info_from_git(repo_path): # Note: git describe doesn't work if no tag is available try: git_tag = subprocess.check_output( + # CIRCUITPY-CHANGE [tools_describe], cwd=repo_path, shell=True, stderr=subprocess.STDOUT, universal_newlines=True, ).strip() + # CIRCUITPY-CHANGE except subprocess.CalledProcessError as er: if er.returncode == 128: # git exit code of 128 means no repository found @@ -44,6 +47,7 @@ def get_version_info_from_git(repo_path): except OSError: return None try: + # CIRCUITPY-CHANGE git_hash = subprocess.check_output( ["git", "rev-parse", "--short", "HEAD"], cwd=repo_path, @@ -51,10 +55,12 @@ def get_version_info_from_git(repo_path): universal_newlines=True, ).strip() except subprocess.CalledProcessError: + # CIRCUITPY-CHANGE git_hash = "unknown" except OSError: return None + # CIRCUITPY-CHANGE try: # Check if there are any modified files. subprocess.check_call( @@ -80,6 +86,7 @@ def get_version_info_from_git(repo_path): return git_tag, git_hash, ver +# CIRCUITPY-CHANGE def cannot_determine_version(): raise SystemExit( """Cannot determine version. @@ -109,6 +116,7 @@ def make_version_header(repo_path, filename): ).date() # Generate the file with the git and version info + # CIRCUITPY-CHANGE: different contents file_data = """\ // This file was generated by py/makeversionhdr.py #define MICROPY_GIT_TAG "%s" diff --git a/py/malloc.c b/py/malloc.c index 0dbe66ea55851..60f0df7455d11 100644 --- a/py/malloc.c +++ b/py/malloc.c @@ -69,7 +69,7 @@ #error MICROPY_ENABLE_FINALISER requires MICROPY_ENABLE_GC #endif -STATIC void *realloc_ext(void *ptr, size_t n_bytes, bool allow_move) { +static void *realloc_ext(void *ptr, size_t n_bytes, bool allow_move) { if (allow_move) { return realloc(ptr, n_bytes); } else { @@ -221,7 +221,7 @@ typedef struct _m_tracked_node_t { } m_tracked_node_t; #if MICROPY_DEBUG_VERBOSE -STATIC size_t m_tracked_count_links(size_t *nb) { +static size_t m_tracked_count_links(size_t *nb) { m_tracked_node_t *node = MP_STATE_VM(m_tracked_head); size_t n = 0; *nb = 0; diff --git a/py/map.c b/py/map.c index c18df5a9f333c..d40e3dc4d02d7 100644 --- a/py/map.c +++ b/py/map.c @@ -65,14 +65,14 @@ // The first set of sizes are chosen so the allocation fits exactly in a // 4-word GC block, and it's not so important for these small values to be // prime. The latter sizes are prime and increase at an increasing rate. -STATIC const uint16_t hash_allocation_sizes[] = { +static const uint16_t hash_allocation_sizes[] = { 0, 2, 4, 6, 8, 10, 12, // +2 17, 23, 29, 37, 47, 59, 73, // *1.25 97, 127, 167, 223, 293, 389, 521, 691, 919, 1223, 1627, 2161, // *1.33 3229, 4831, 7243, 10861, 16273, 24407, 36607, 54907, // *1.5 }; -STATIC size_t get_hash_alloc_greater_or_equal_to(size_t x) { +static size_t get_hash_alloc_greater_or_equal_to(size_t x) { for (size_t i = 0; i < MP_ARRAY_SIZE(hash_allocation_sizes); i++) { if (hash_allocation_sizes[i] >= x) { return hash_allocation_sizes[i]; @@ -128,7 +128,7 @@ void mp_map_clear(mp_map_t *map) { map->table = NULL; } -STATIC void mp_map_rehash(mp_map_t *map) { +static void mp_map_rehash(mp_map_t *map) { size_t old_alloc = map->alloc; size_t new_alloc = get_hash_alloc_greater_or_equal_to(map->alloc + 1); DEBUG_printf("mp_map_rehash(%p): " UINT_FMT " -> " UINT_FMT "\n", map, old_alloc, new_alloc); @@ -332,7 +332,7 @@ void mp_set_init(mp_set_t *set, size_t n) { set->table = m_new0(mp_obj_t, set->alloc); } -STATIC void mp_set_rehash(mp_set_t *set) { +static void mp_set_rehash(mp_set_t *set) { size_t old_alloc = set->alloc; mp_obj_t *old_table = set->table; set->alloc = get_hash_alloc_greater_or_equal_to(set->alloc + 1); diff --git a/py/misc.h b/py/misc.h index dc43e613155f0..769d12ddbee5c 100644 --- a/py/misc.h +++ b/py/misc.h @@ -82,13 +82,6 @@ typedef unsigned int uint; #define m_new_obj_var(obj_type, var_field, var_type, var_num) ((obj_type *)m_malloc(offsetof(obj_type, var_field) + sizeof(var_type) * (var_num))) #define m_new_obj_var0(obj_type, var_field, var_type, var_num) ((obj_type *)m_malloc0(offsetof(obj_type, var_field) + sizeof(var_type) * (var_num))) #define m_new_obj_var_maybe(obj_type, var_field, var_type, var_num) ((obj_type *)m_malloc_maybe(offsetof(obj_type, var_field) + sizeof(var_type) * (var_num))) -#if MICROPY_ENABLE_FINALISER -#define m_new_obj_with_finaliser(type) ((type *)(m_malloc_with_finaliser(sizeof(type)))) -#define m_new_obj_var_with_finaliser(type, var_field, var_type, var_num) ((type *)m_malloc_with_finaliser(offsetof(type, var_field) + sizeof(var_type) * (var_num))) -#else -#define m_new_obj_with_finaliser(type) m_new_obj(type) -#define m_new_obj_var_with_finaliser(type, var_field, var_type, var_num) m_new_obj_var(type, var_field, var_type, var_num) -#endif #if MICROPY_MALLOC_USES_ALLOCATED_SIZE #define m_renew(type, ptr, old_num, new_num) ((type *)(m_realloc((ptr), sizeof(type) * (old_num), sizeof(type) * (new_num)))) #define m_renew_maybe(type, ptr, old_num, new_num, allow_move) ((type *)(m_realloc_maybe((ptr), sizeof(type) * (old_num), sizeof(type) * (new_num), (allow_move)))) diff --git a/py/mkrules.mk b/py/mkrules.mk index 4a72ced536031..058f5a9ee5080 100644 --- a/py/mkrules.mk +++ b/py/mkrules.mk @@ -11,7 +11,7 @@ ifeq ($(MICROPY_PREVIEW_VERSION_2),1) CFLAGS += -DMICROPY_PREVIEW_VERSION_2=1 endif -HELP_BUILD_ERROR ?= "See \033[1;31mhttps://github.com/micropython/micropython/wiki/Build-Troubleshooting\033[0m" +HELP_BUILD_ERROR ?= "See \033[1;31mhttps://learn.adafruit.com/building-circuitpython; Adafruit Discord \#circuitpython-dev\033[0m" HELP_MPY_LIB_SUBMODULE ?= "\033[1;31mError: micropython-lib submodule is not initialized.\033[0m Run 'make submodules'" # Extra deps that need to happen before object compilation. @@ -178,7 +178,7 @@ $(HEADER_BUILD): ifneq ($(MICROPY_MPYCROSS_DEPENDENCY),) # to automatically build mpy-cross, if needed $(MICROPY_MPYCROSS_DEPENDENCY): - $(MAKE) -C $(abspath $(dir $@)..) + $(MAKE) -C "$(abspath $(dir $@)..)" endif ifneq ($(FROZEN_DIR),) diff --git a/py/modarray.c b/py/modarray.c index ac2e56ed38b40..116c844e8eb1c 100644 --- a/py/modarray.c +++ b/py/modarray.c @@ -28,12 +28,12 @@ #if MICROPY_PY_ARRAY -STATIC const mp_rom_map_elem_t mp_module_array_globals_table[] = { +static const mp_rom_map_elem_t mp_module_array_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_array) }, { MP_ROM_QSTR(MP_QSTR_array), MP_ROM_PTR(&mp_type_array) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_array_globals, mp_module_array_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_array_globals, mp_module_array_globals_table); const mp_obj_module_t mp_module_array = { .base = { &mp_type_module }, diff --git a/py/modbuiltins.c b/py/modbuiltins.c index 8aacafb796a3e..cdeacc25f7116 100644 --- a/py/modbuiltins.c +++ b/py/modbuiltins.c @@ -46,7 +46,7 @@ extern struct _mp_dummy_t mp_sys_stdout_obj; // type is irrelevant, just need po // args[0] is function from class body // args[1] is class name // args[2:] are base objects -STATIC mp_obj_t mp_builtin___build_class__(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin___build_class__(size_t n_args, const mp_obj_t *args) { assert(2 <= n_args); // set the new classes __locals__ object @@ -88,12 +88,12 @@ STATIC mp_obj_t mp_builtin___build_class__(size_t n_args, const mp_obj_t *args) } MP_DEFINE_CONST_FUN_OBJ_VAR(mp_builtin___build_class___obj, 2, mp_builtin___build_class__); -STATIC mp_obj_t mp_builtin_abs(mp_obj_t o_in) { +static mp_obj_t mp_builtin_abs(mp_obj_t o_in) { return mp_unary_op(MP_UNARY_OP_ABS, o_in); } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_abs_obj, mp_builtin_abs); -STATIC mp_obj_t mp_builtin_all(mp_obj_t o_in) { +static mp_obj_t mp_builtin_all(mp_obj_t o_in) { mp_obj_iter_buf_t iter_buf; mp_obj_t iterable = mp_getiter(o_in, &iter_buf); mp_obj_t item; @@ -106,7 +106,7 @@ STATIC mp_obj_t mp_builtin_all(mp_obj_t o_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_all_obj, mp_builtin_all); -STATIC mp_obj_t mp_builtin_any(mp_obj_t o_in) { +static mp_obj_t mp_builtin_any(mp_obj_t o_in) { mp_obj_iter_buf_t iter_buf; mp_obj_t iterable = mp_getiter(o_in, &iter_buf); mp_obj_t item; @@ -119,13 +119,13 @@ STATIC mp_obj_t mp_builtin_any(mp_obj_t o_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_any_obj, mp_builtin_any); -STATIC mp_obj_t mp_builtin_bin(mp_obj_t o_in) { +static mp_obj_t mp_builtin_bin(mp_obj_t o_in) { mp_obj_t args[] = { MP_OBJ_NEW_QSTR(MP_QSTR__brace_open__colon__hash_b_brace_close_), o_in }; return mp_obj_str_format(MP_ARRAY_SIZE(args), args, NULL); } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_bin_obj, mp_builtin_bin); -STATIC mp_obj_t mp_builtin_callable(mp_obj_t o_in) { +static mp_obj_t mp_builtin_callable(mp_obj_t o_in) { if (mp_obj_is_callable(o_in)) { return mp_const_true; } else { @@ -134,7 +134,7 @@ STATIC mp_obj_t mp_builtin_callable(mp_obj_t o_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_callable_obj, mp_builtin_callable); -STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) { +static mp_obj_t mp_builtin_chr(mp_obj_t o_in) { #if MICROPY_PY_BUILTINS_STR_UNICODE mp_uint_t c = mp_obj_get_int(o_in); if (c >= 0x110000) { @@ -155,7 +155,7 @@ STATIC mp_obj_t mp_builtin_chr(mp_obj_t o_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_chr_obj, mp_builtin_chr); -STATIC mp_obj_t mp_builtin_dir(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_dir(size_t n_args, const mp_obj_t *args) { mp_obj_t dir = mp_obj_new_list(0, NULL); if (n_args == 0) { // Make a list of names in the local namespace @@ -170,7 +170,7 @@ STATIC mp_obj_t mp_builtin_dir(size_t n_args, const mp_obj_t *args) { // Implemented by probing all possible qstrs with mp_load_method_maybe size_t nqstr = QSTR_TOTAL(); for (size_t i = MP_QSTR_ + 1; i < nqstr; ++i) { - // CIRCUITPY-CHANGE: changes PR #6539: catch dir() exceptions + // CIRCUITPY-CHANGE: PR #6539: catch dir() exceptions mp_obj_t dest[2] = {}; mp_load_method_protected(args[0], i, dest, true); if (dest[0] != MP_OBJ_NULL) { @@ -189,18 +189,18 @@ STATIC mp_obj_t mp_builtin_dir(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_dir_obj, 0, 1, mp_builtin_dir); -STATIC mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) { +static mp_obj_t mp_builtin_divmod(mp_obj_t o1_in, mp_obj_t o2_in) { return mp_binary_op(MP_BINARY_OP_DIVMOD, o1_in, o2_in); } MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_divmod_obj, mp_builtin_divmod); -STATIC mp_obj_t mp_builtin_hash(mp_obj_t o_in) { +static mp_obj_t mp_builtin_hash(mp_obj_t o_in) { // result is guaranteed to be a (small) int return mp_unary_op(MP_UNARY_OP_HASH, o_in); } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_hash_obj, mp_builtin_hash); -STATIC mp_obj_t mp_builtin_hex(mp_obj_t o_in) { +static mp_obj_t mp_builtin_hex(mp_obj_t o_in) { #if MICROPY_PY_BUILTINS_STR_OP_MODULO return mp_binary_op(MP_BINARY_OP_MODULO, MP_OBJ_NEW_QSTR(MP_QSTR__percent__hash_x), o_in); #else @@ -220,7 +220,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_hex_obj, mp_builtin_hex); #define mp_hal_readline readline #endif -STATIC mp_obj_t mp_builtin_input(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_input(size_t n_args, const mp_obj_t *args) { if (n_args == 1) { mp_obj_print(args[0], PRINT_STR); } @@ -239,14 +239,14 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_input_obj, 0, 1, mp_builtin_input #endif -STATIC mp_obj_t mp_builtin_iter(mp_obj_t o_in) { +static mp_obj_t mp_builtin_iter(mp_obj_t o_in) { return mp_getiter(o_in, NULL); } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_iter_obj, mp_builtin_iter); #if MICROPY_PY_BUILTINS_MIN_MAX -STATIC mp_obj_t mp_builtin_min_max(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs, mp_uint_t op) { +static mp_obj_t mp_builtin_min_max(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs, mp_uint_t op) { mp_map_elem_t *key_elem = mp_map_lookup(kwargs, MP_OBJ_NEW_QSTR(MP_QSTR_key), MP_MAP_LOOKUP); mp_map_elem_t *default_elem; mp_obj_t key_fn = key_elem == NULL ? MP_OBJ_NULL : key_elem->value; @@ -288,12 +288,12 @@ STATIC mp_obj_t mp_builtin_min_max(size_t n_args, const mp_obj_t *args, mp_map_t } } -STATIC mp_obj_t mp_builtin_max(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t mp_builtin_max(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { return mp_builtin_min_max(n_args, args, kwargs, MP_BINARY_OP_MORE); } MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_max_obj, 1, mp_builtin_max); -STATIC mp_obj_t mp_builtin_min(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t mp_builtin_min(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { return mp_builtin_min_max(n_args, args, kwargs, MP_BINARY_OP_LESS); } MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_min_obj, 1, mp_builtin_min); @@ -301,7 +301,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_min_obj, 1, mp_builtin_min); #endif #if MICROPY_PY_BUILTINS_NEXT2 -STATIC mp_obj_t mp_builtin_next(size_t n_args, const mp_obj_t *args) { +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) { @@ -316,7 +316,7 @@ STATIC mp_obj_t mp_builtin_next(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_next_obj, 1, 2, mp_builtin_next); #else -STATIC mp_obj_t mp_builtin_next(mp_obj_t o) { +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_StopIteration(MP_STATE_THREAD(stop_iteration_arg)); @@ -327,7 +327,7 @@ STATIC mp_obj_t mp_builtin_next(mp_obj_t o) { MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_next_obj, mp_builtin_next); #endif -STATIC mp_obj_t mp_builtin_oct(mp_obj_t o_in) { +static mp_obj_t mp_builtin_oct(mp_obj_t o_in) { #if MICROPY_PY_BUILTINS_STR_OP_MODULO return mp_binary_op(MP_BINARY_OP_MODULO, MP_OBJ_NEW_QSTR(MP_QSTR__percent__hash_o), o_in); #else @@ -337,7 +337,7 @@ STATIC mp_obj_t mp_builtin_oct(mp_obj_t o_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_oct_obj, mp_builtin_oct); -STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) { +static mp_obj_t mp_builtin_ord(mp_obj_t o_in) { size_t len; const byte *str = (const byte *)mp_obj_str_get_data(o_in, &len); #if MICROPY_PY_BUILTINS_STR_UNICODE @@ -358,13 +358,14 @@ STATIC mp_obj_t mp_builtin_ord(mp_obj_t o_in) { #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE mp_raise_TypeError(MP_ERROR_TEXT("ord expects a character")); #else + // CIRCUITPY-CHANGE: more specific mp_raise mp_raise_TypeError_varg( MP_ERROR_TEXT("ord() expected a character, but string of length %d found"), (int)len); #endif } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_ord_obj, mp_builtin_ord); -STATIC mp_obj_t mp_builtin_pow(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_pow(size_t n_args, const mp_obj_t *args) { switch (n_args) { case 2: return mp_binary_op(MP_BINARY_OP_POWER, args[0], args[1]); @@ -381,7 +382,7 @@ STATIC mp_obj_t mp_builtin_pow(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_pow_obj, 2, 3, mp_builtin_pow); // CIRCUITPY-CHANGE: adds flush() -STATIC mp_obj_t mp_builtin_print(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t mp_builtin_print(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_sep, ARG_end, ARG_flush, ARG_file }; static const mp_arg_t allowed_args[] = { { MP_QSTR_sep, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_QSTR(MP_QSTR__space_)} }, @@ -426,6 +427,7 @@ STATIC mp_obj_t mp_builtin_print(size_t n_args, const mp_obj_t *pos_args, mp_map } #if MICROPY_PY_IO && MICROPY_PY_SYS_STDFILES mp_stream_write_adaptor(print.data, end_data, u.len[1]); + // CIRCUITPY-CHANGE: add flush() if (u.args[ARG_flush].u_bool) { mp_stream_flush(MP_OBJ_FROM_PTR(print.data)); } @@ -436,7 +438,7 @@ STATIC mp_obj_t mp_builtin_print(size_t n_args, const mp_obj_t *pos_args, mp_map } MP_DEFINE_CONST_FUN_OBJ_KW(mp_builtin_print_obj, 0, mp_builtin_print); -STATIC mp_obj_t mp_builtin___repl_print__(mp_obj_t o) { +static mp_obj_t mp_builtin___repl_print__(mp_obj_t o) { if (o != mp_const_none) { mp_obj_print_helper(MP_PYTHON_PRINTER, o, PRINT_REPR); mp_print_str(MP_PYTHON_PRINTER, "\n"); @@ -450,7 +452,7 @@ STATIC mp_obj_t mp_builtin___repl_print__(mp_obj_t o) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin___repl_print___obj, mp_builtin___repl_print__); -STATIC mp_obj_t mp_builtin_repr(mp_obj_t o_in) { +static mp_obj_t mp_builtin_repr(mp_obj_t o_in) { vstr_t vstr; mp_print_t print; vstr_init_print(&vstr, 16, &print); @@ -459,7 +461,7 @@ STATIC mp_obj_t mp_builtin_repr(mp_obj_t o_in) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_repr_obj, mp_builtin_repr); -STATIC mp_obj_t mp_builtin_round(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_round(size_t n_args, const mp_obj_t *args) { mp_obj_t o_in = args[0]; if (mp_obj_is_int(o_in)) { if (n_args <= 1) { @@ -511,7 +513,7 @@ STATIC mp_obj_t mp_builtin_round(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_round_obj, 1, 2, mp_builtin_round); -STATIC mp_obj_t mp_builtin_sum(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_sum(size_t n_args, const mp_obj_t *args) { mp_obj_t value; switch (n_args) { case 1: @@ -531,7 +533,7 @@ STATIC mp_obj_t mp_builtin_sum(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_sum_obj, 1, 2, mp_builtin_sum); -STATIC mp_obj_t mp_builtin_sorted(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t mp_builtin_sorted(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { if (n_args > 1) { mp_raise_TypeError(MP_ERROR_TEXT("must use keyword argument for key function")); } @@ -562,7 +564,7 @@ static inline mp_obj_t mp_load_attr_default(mp_obj_t base, qstr attr, mp_obj_t d } } -STATIC mp_obj_t mp_builtin_getattr(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_builtin_getattr(size_t n_args, const mp_obj_t *args) { mp_obj_t defval = MP_OBJ_NULL; if (n_args > 2) { defval = args[2]; @@ -571,20 +573,20 @@ STATIC mp_obj_t mp_builtin_getattr(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_getattr_obj, 2, 3, mp_builtin_getattr); -STATIC mp_obj_t mp_builtin_setattr(mp_obj_t base, mp_obj_t attr, mp_obj_t value) { +static mp_obj_t mp_builtin_setattr(mp_obj_t base, mp_obj_t attr, mp_obj_t value) { mp_store_attr(base, mp_obj_str_get_qstr(attr), value); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_3(mp_builtin_setattr_obj, mp_builtin_setattr); #if MICROPY_CPYTHON_COMPAT -STATIC mp_obj_t mp_builtin_delattr(mp_obj_t base, mp_obj_t attr) { +static mp_obj_t mp_builtin_delattr(mp_obj_t base, mp_obj_t attr) { return mp_builtin_setattr(base, attr, MP_OBJ_NULL); } MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_delattr_obj, mp_builtin_delattr); #endif -STATIC mp_obj_t mp_builtin_hasattr(mp_obj_t object_in, mp_obj_t attr_in) { +static mp_obj_t mp_builtin_hasattr(mp_obj_t object_in, mp_obj_t attr_in) { qstr attr = mp_obj_str_get_qstr(attr_in); mp_obj_t dest[2]; mp_load_method_protected(object_in, attr, dest, false); @@ -592,12 +594,12 @@ STATIC mp_obj_t mp_builtin_hasattr(mp_obj_t object_in, mp_obj_t attr_in) { } MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_hasattr_obj, mp_builtin_hasattr); -STATIC mp_obj_t mp_builtin_globals(void) { +static mp_obj_t mp_builtin_globals(void) { return MP_OBJ_FROM_PTR(mp_globals_get()); } MP_DEFINE_CONST_FUN_OBJ_0(mp_builtin_globals_obj, mp_builtin_globals); -STATIC mp_obj_t mp_builtin_locals(void) { +static mp_obj_t mp_builtin_locals(void) { return MP_OBJ_FROM_PTR(mp_locals_get()); } MP_DEFINE_CONST_FUN_OBJ_0(mp_builtin_locals_obj, mp_builtin_locals); @@ -606,7 +608,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(mp_builtin_locals_obj, mp_builtin_locals); MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_id_obj, mp_obj_id); MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_len_obj, mp_obj_len); -STATIC const mp_rom_map_elem_t mp_module_builtins_globals_table[] = { +static const mp_rom_map_elem_t mp_module_builtins_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_builtins) }, // built-in core functions diff --git a/py/modcmath.c b/py/modcmath.c index 1418362ad9b1e..33cb00cbe7e69 100644 --- a/py/modcmath.c +++ b/py/modcmath.c @@ -31,15 +31,15 @@ #include // phase(z): returns the phase of the number z in the range (-pi, +pi] -STATIC mp_obj_t mp_cmath_phase(mp_obj_t z_obj) { +static mp_obj_t mp_cmath_phase(mp_obj_t z_obj) { mp_float_t real, imag; mp_obj_get_complex(z_obj, &real, &imag); return mp_obj_new_float(MICROPY_FLOAT_C_FUN(atan2)(imag, real)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_phase_obj, mp_cmath_phase); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_phase_obj, mp_cmath_phase); // polar(z): returns the polar form of z as a tuple -STATIC mp_obj_t mp_cmath_polar(mp_obj_t z_obj) { +static mp_obj_t mp_cmath_polar(mp_obj_t z_obj) { mp_float_t real, imag; mp_obj_get_complex(z_obj, &real, &imag); mp_obj_t tuple[2] = { @@ -48,71 +48,71 @@ STATIC mp_obj_t mp_cmath_polar(mp_obj_t z_obj) { }; return mp_obj_new_tuple(2, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_polar_obj, mp_cmath_polar); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_polar_obj, mp_cmath_polar); // rect(r, phi): returns the complex number with modulus r and phase phi -STATIC mp_obj_t mp_cmath_rect(mp_obj_t r_obj, mp_obj_t phi_obj) { +static mp_obj_t mp_cmath_rect(mp_obj_t r_obj, mp_obj_t phi_obj) { mp_float_t r = mp_obj_get_float(r_obj); mp_float_t phi = mp_obj_get_float(phi_obj); return mp_obj_new_complex(r * MICROPY_FLOAT_C_FUN(cos)(phi), r * MICROPY_FLOAT_C_FUN(sin)(phi)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_cmath_rect_obj, mp_cmath_rect); +static MP_DEFINE_CONST_FUN_OBJ_2(mp_cmath_rect_obj, mp_cmath_rect); // exp(z): return the exponential of z -STATIC mp_obj_t mp_cmath_exp(mp_obj_t z_obj) { +static mp_obj_t mp_cmath_exp(mp_obj_t z_obj) { mp_float_t real, imag; mp_obj_get_complex(z_obj, &real, &imag); mp_float_t exp_real = MICROPY_FLOAT_C_FUN(exp)(real); return mp_obj_new_complex(exp_real * MICROPY_FLOAT_C_FUN(cos)(imag), exp_real * MICROPY_FLOAT_C_FUN(sin)(imag)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_exp_obj, mp_cmath_exp); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_exp_obj, mp_cmath_exp); // log(z): return the natural logarithm of z, with branch cut along the negative real axis // TODO can take second argument, being the base -STATIC mp_obj_t mp_cmath_log(mp_obj_t z_obj) { +static mp_obj_t mp_cmath_log(mp_obj_t z_obj) { mp_float_t real, imag; mp_obj_get_complex(z_obj, &real, &imag); return mp_obj_new_complex(MICROPY_FLOAT_CONST(0.5) * MICROPY_FLOAT_C_FUN(log)(real * real + imag * imag), MICROPY_FLOAT_C_FUN(atan2)(imag, real)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log_obj, mp_cmath_log); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log_obj, mp_cmath_log); #if MICROPY_PY_MATH_SPECIAL_FUNCTIONS // log10(z): return the base-10 logarithm of z, with branch cut along the negative real axis -STATIC mp_obj_t mp_cmath_log10(mp_obj_t z_obj) { +static mp_obj_t mp_cmath_log10(mp_obj_t z_obj) { mp_float_t real, imag; mp_obj_get_complex(z_obj, &real, &imag); return mp_obj_new_complex(MICROPY_FLOAT_CONST(0.5) * MICROPY_FLOAT_C_FUN(log10)(real * real + imag * imag), MICROPY_FLOAT_CONST(0.4342944819032518) * MICROPY_FLOAT_C_FUN(atan2)(imag, real)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log10_obj, mp_cmath_log10); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_log10_obj, mp_cmath_log10); #endif // sqrt(z): return the square-root of z -STATIC mp_obj_t mp_cmath_sqrt(mp_obj_t z_obj) { +static mp_obj_t mp_cmath_sqrt(mp_obj_t z_obj) { mp_float_t real, imag; mp_obj_get_complex(z_obj, &real, &imag); mp_float_t sqrt_abs = MICROPY_FLOAT_C_FUN(pow)(real * real + imag * imag, MICROPY_FLOAT_CONST(0.25)); mp_float_t theta = MICROPY_FLOAT_CONST(0.5) * MICROPY_FLOAT_C_FUN(atan2)(imag, real); return mp_obj_new_complex(sqrt_abs * MICROPY_FLOAT_C_FUN(cos)(theta), sqrt_abs * MICROPY_FLOAT_C_FUN(sin)(theta)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_sqrt_obj, mp_cmath_sqrt); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_sqrt_obj, mp_cmath_sqrt); // cos(z): return the cosine of z -STATIC mp_obj_t mp_cmath_cos(mp_obj_t z_obj) { +static mp_obj_t mp_cmath_cos(mp_obj_t z_obj) { mp_float_t real, imag; mp_obj_get_complex(z_obj, &real, &imag); return mp_obj_new_complex(MICROPY_FLOAT_C_FUN(cos)(real) * MICROPY_FLOAT_C_FUN(cosh)(imag), -MICROPY_FLOAT_C_FUN(sin)(real) * MICROPY_FLOAT_C_FUN(sinh)(imag)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_cos_obj, mp_cmath_cos); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_cos_obj, mp_cmath_cos); // sin(z): return the sine of z -STATIC mp_obj_t mp_cmath_sin(mp_obj_t z_obj) { +static mp_obj_t mp_cmath_sin(mp_obj_t z_obj) { mp_float_t real, imag; mp_obj_get_complex(z_obj, &real, &imag); return mp_obj_new_complex(MICROPY_FLOAT_C_FUN(sin)(real) * MICROPY_FLOAT_C_FUN(cosh)(imag), MICROPY_FLOAT_C_FUN(cos)(real) * MICROPY_FLOAT_C_FUN(sinh)(imag)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_sin_obj, mp_cmath_sin); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_cmath_sin_obj, mp_cmath_sin); -STATIC const mp_rom_map_elem_t mp_module_cmath_globals_table[] = { +static const mp_rom_map_elem_t mp_module_cmath_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_cmath) }, { MP_ROM_QSTR(MP_QSTR_e), mp_const_float_e }, { MP_ROM_QSTR(MP_QSTR_pi), mp_const_float_pi }, @@ -142,7 +142,7 @@ STATIC const mp_rom_map_elem_t mp_module_cmath_globals_table[] = { // { MP_ROM_QSTR(MP_QSTR_isnan), MP_ROM_PTR(&mp_cmath_isnan_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_cmath_globals, mp_module_cmath_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_cmath_globals, mp_module_cmath_globals_table); const mp_obj_module_t mp_module_cmath = { .base = { &mp_type_module }, diff --git a/py/modcollections.c b/py/modcollections.c index 30a5881bc2c3a..46326d13eef5a 100644 --- a/py/modcollections.c +++ b/py/modcollections.c @@ -28,7 +28,7 @@ #if MICROPY_PY_COLLECTIONS -STATIC const mp_rom_map_elem_t mp_module_collections_globals_table[] = { +static const mp_rom_map_elem_t mp_module_collections_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_collections) }, #if MICROPY_PY_COLLECTIONS_DEQUE { MP_ROM_QSTR(MP_QSTR_deque), MP_ROM_PTR(&mp_type_deque) }, @@ -39,7 +39,7 @@ STATIC const mp_rom_map_elem_t mp_module_collections_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_collections_globals, mp_module_collections_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_collections_globals, mp_module_collections_globals_table); const mp_obj_module_t mp_module_collections = { .base = { &mp_type_module }, diff --git a/py/moderrno.c b/py/moderrno.c index b1002f177da5d..b5116bcadc7d9 100644 --- a/py/moderrno.c +++ b/py/moderrno.c @@ -62,13 +62,13 @@ #endif #if MICROPY_PY_ERRNO_ERRORCODE -STATIC const mp_rom_map_elem_t errorcode_table[] = { +static const mp_rom_map_elem_t errorcode_table[] = { #define X(e) { MP_ROM_INT(MP_##e), MP_ROM_QSTR(MP_QSTR_##e) }, MICROPY_PY_ERRNO_LIST #undef X }; -STATIC const mp_obj_dict_t errorcode_dict = { +static const mp_obj_dict_t errorcode_dict = { .base = {&mp_type_dict}, .map = { .all_keys_are_qstrs = 0, // keys are integers @@ -81,7 +81,7 @@ STATIC const mp_obj_dict_t errorcode_dict = { }; #endif -STATIC const mp_rom_map_elem_t mp_module_errno_globals_table[] = { +static const mp_rom_map_elem_t mp_module_errno_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_errno) }, #if MICROPY_PY_ERRNO_ERRORCODE { MP_ROM_QSTR(MP_QSTR_errorcode), MP_ROM_PTR(&errorcode_dict) }, @@ -92,7 +92,7 @@ STATIC const mp_rom_map_elem_t mp_module_errno_globals_table[] = { #undef X }; -STATIC MP_DEFINE_CONST_DICT(mp_module_errno_globals, mp_module_errno_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_errno_globals, mp_module_errno_globals_table); const mp_obj_module_t mp_module_errno = { .base = { &mp_type_module }, diff --git a/py/modgc.c b/py/modgc.c index 7b18045b083a3..47902d8c95bce 100644 --- a/py/modgc.c +++ b/py/modgc.c @@ -31,7 +31,7 @@ #if MICROPY_PY_GC && MICROPY_ENABLE_GC // collect(): run a garbage collection -STATIC mp_obj_t py_gc_collect(void) { +static mp_obj_t py_gc_collect(void) { gc_collect(); #if MICROPY_PY_GC_COLLECT_RETVAL return MP_OBJ_NEW_SMALL_INT(MP_STATE_MEM(gc_collected)); @@ -42,26 +42,26 @@ STATIC mp_obj_t py_gc_collect(void) { MP_DEFINE_CONST_FUN_OBJ_0(gc_collect_obj, py_gc_collect); // disable(): disable the garbage collector -STATIC mp_obj_t gc_disable(void) { +static mp_obj_t gc_disable(void) { MP_STATE_MEM(gc_auto_collect_enabled) = 0; return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(gc_disable_obj, gc_disable); // enable(): enable the garbage collector -STATIC mp_obj_t gc_enable(void) { +static mp_obj_t gc_enable(void) { MP_STATE_MEM(gc_auto_collect_enabled) = 1; return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_0(gc_enable_obj, gc_enable); -STATIC mp_obj_t gc_isenabled(void) { +static mp_obj_t gc_isenabled(void) { return mp_obj_new_bool(MP_STATE_MEM(gc_auto_collect_enabled)); } MP_DEFINE_CONST_FUN_OBJ_0(gc_isenabled_obj, gc_isenabled); // mem_free(): return the number of bytes of available heap RAM -STATIC mp_obj_t gc_mem_free(void) { +static mp_obj_t gc_mem_free(void) { gc_info_t info; gc_info(&info); #if MICROPY_GC_SPLIT_HEAP_AUTO @@ -74,7 +74,7 @@ STATIC mp_obj_t gc_mem_free(void) { MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_free_obj, gc_mem_free); // mem_alloc(): return the number of bytes of heap RAM that are allocated -STATIC mp_obj_t gc_mem_alloc(void) { +static mp_obj_t gc_mem_alloc(void) { gc_info_t info; gc_info(&info); return MP_OBJ_NEW_SMALL_INT(info.used); @@ -82,7 +82,7 @@ STATIC mp_obj_t gc_mem_alloc(void) { MP_DEFINE_CONST_FUN_OBJ_0(gc_mem_alloc_obj, gc_mem_alloc); #if MICROPY_GC_ALLOC_THRESHOLD -STATIC mp_obj_t gc_threshold(size_t n_args, const mp_obj_t *args) { +static mp_obj_t gc_threshold(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { if (MP_STATE_MEM(gc_alloc_threshold) == (size_t)-1) { return MP_OBJ_NEW_SMALL_INT(-1); @@ -100,7 +100,7 @@ STATIC mp_obj_t gc_threshold(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gc_threshold_obj, 0, 1, gc_threshold); #endif -STATIC const mp_rom_map_elem_t mp_module_gc_globals_table[] = { +static const mp_rom_map_elem_t mp_module_gc_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gc) }, { MP_ROM_QSTR(MP_QSTR_collect), MP_ROM_PTR(&gc_collect_obj) }, { MP_ROM_QSTR(MP_QSTR_disable), MP_ROM_PTR(&gc_disable_obj) }, @@ -113,7 +113,7 @@ STATIC const mp_rom_map_elem_t mp_module_gc_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_gc_globals, mp_module_gc_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_gc_globals, mp_module_gc_globals_table); const mp_obj_module_t mp_module_gc = { .base = { &mp_type_module }, diff --git a/py/modio.c b/py/modio.c index 39317c52d545f..d3e563dbcf447 100644 --- a/py/modio.c +++ b/py/modio.c @@ -39,11 +39,11 @@ #if MICROPY_PY_IO_IOBASE -STATIC const mp_obj_type_t mp_type_iobase; +static const mp_obj_type_t mp_type_iobase; -STATIC const mp_obj_base_t iobase_singleton = {&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, size_t n_kw, const mp_obj_t *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; @@ -51,7 +51,7 @@ STATIC mp_obj_t iobase_make_new(const mp_obj_type_t *type, size_t n_args, size_t return MP_OBJ_FROM_PTR(&iobase_singleton); } -STATIC mp_uint_t iobase_read_write(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode, qstr qst) { +static mp_uint_t iobase_read_write(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode, qstr qst) { mp_obj_t dest[3]; mp_load_method(obj, qst, dest); mp_obj_array_t ar = {{&mp_type_bytearray}, BYTEARRAY_TYPECODE, 0, size, buf}; @@ -69,15 +69,15 @@ STATIC mp_uint_t iobase_read_write(mp_obj_t obj, void *buf, mp_uint_t size, int return MP_STREAM_ERROR; } } -STATIC mp_uint_t iobase_read(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t iobase_read(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode) { return iobase_read_write(obj, buf, size, errcode, MP_QSTR_readinto); } -STATIC mp_uint_t iobase_write(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t iobase_write(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode) { return iobase_read_write(obj, (void *)buf, size, errcode, MP_QSTR_write); } -STATIC mp_uint_t iobase_ioctl(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t iobase_ioctl(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *errcode) { mp_obj_t dest[4]; mp_load_method(obj, MP_QSTR_ioctl, dest); dest[2] = mp_obj_new_int_from_uint(request); @@ -91,13 +91,13 @@ STATIC mp_uint_t iobase_ioctl(mp_obj_t obj, mp_uint_t request, uintptr_t arg, in } } -STATIC const mp_stream_p_t iobase_p = { +static const mp_stream_p_t iobase_p = { .read = iobase_read, .write = iobase_write, .ioctl = iobase_ioctl, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_iobase, MP_QSTR_IOBase, MP_TYPE_FLAG_NONE, @@ -116,17 +116,17 @@ 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, size_t n_kw, const mp_obj_t *args) { +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 = mp_obj_malloc_var(mp_obj_bufwriter_t, byte, alloc, type); + mp_obj_bufwriter_t *o = mp_obj_malloc_var(mp_obj_bufwriter_t, buf, byte, alloc, type); o->stream = args[0]; o->alloc = alloc; o->len = 0; return o; } -STATIC mp_uint_t bufwriter_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t bufwriter_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { mp_obj_bufwriter_t *self = MP_OBJ_TO_PTR(self_in); mp_uint_t org_size = size; @@ -162,7 +162,7 @@ STATIC mp_uint_t bufwriter_write(mp_obj_t self_in, const void *buf, mp_uint_t si return org_size; } -STATIC mp_obj_t bufwriter_flush(mp_obj_t self_in) { +static mp_obj_t bufwriter_flush(mp_obj_t self_in) { mp_obj_bufwriter_t *self = MP_OBJ_TO_PTR(self_in); if (self->len != 0) { @@ -180,19 +180,19 @@ STATIC mp_obj_t bufwriter_flush(mp_obj_t self_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(bufwriter_flush_obj, bufwriter_flush); +static MP_DEFINE_CONST_FUN_OBJ_1(bufwriter_flush_obj, bufwriter_flush); -STATIC const mp_rom_map_elem_t bufwriter_locals_dict_table[] = { +static const mp_rom_map_elem_t bufwriter_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mp_stream_write_obj) }, { MP_ROM_QSTR(MP_QSTR_flush), MP_ROM_PTR(&bufwriter_flush_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(bufwriter_locals_dict, bufwriter_locals_dict_table); +static MP_DEFINE_CONST_DICT(bufwriter_locals_dict, bufwriter_locals_dict_table); -STATIC const mp_stream_p_t bufwriter_stream_p = { +static const mp_stream_p_t bufwriter_stream_p = { .write = bufwriter_write, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_bufwriter, MP_QSTR_BufferedWriter, MP_TYPE_FLAG_NONE, @@ -202,7 +202,7 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( ); #endif // MICROPY_PY_IO_BUFFEREDWRITER -STATIC const mp_rom_map_elem_t mp_module_io_globals_table[] = { +static const mp_rom_map_elem_t mp_module_io_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_io) }, // Note: mp_builtin_open_obj should be defined by port, it's not // part of the core. @@ -219,7 +219,7 @@ STATIC const mp_rom_map_elem_t mp_module_io_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_io_globals, mp_module_io_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_io_globals, mp_module_io_globals_table); const mp_obj_module_t mp_module_io = { .base = { &mp_type_module }, diff --git a/py/modmath.c b/py/modmath.c index e20a38850f4f3..701da796bce36 100644 --- a/py/modmath.c +++ b/py/modmath.c @@ -37,11 +37,11 @@ #define MP_PI_4 MICROPY_FLOAT_CONST(0.78539816339744830962) #define MP_3_PI_4 MICROPY_FLOAT_CONST(2.35619449019234492885) -STATIC NORETURN void math_error(void) { +static NORETURN void math_error(void) { mp_raise_ValueError(MP_ERROR_TEXT("math domain error")); } -STATIC mp_obj_t math_generic_1(mp_obj_t x_obj, mp_float_t (*f)(mp_float_t)) { +static mp_obj_t math_generic_1(mp_obj_t x_obj, mp_float_t (*f)(mp_float_t)) { mp_float_t x = mp_obj_get_float(x_obj); mp_float_t ans = f(x); if ((isnan(ans) && !isnan(x)) || (isinf(ans) && !isinf(x))) { @@ -50,7 +50,7 @@ STATIC mp_obj_t math_generic_1(mp_obj_t x_obj, mp_float_t (*f)(mp_float_t)) { return mp_obj_new_float(ans); } -STATIC mp_obj_t math_generic_2(mp_obj_t x_obj, mp_obj_t y_obj, mp_float_t (*f)(mp_float_t, mp_float_t)) { +static mp_obj_t math_generic_2(mp_obj_t x_obj, mp_obj_t y_obj, mp_float_t (*f)(mp_float_t, mp_float_t)) { mp_float_t x = mp_obj_get_float(x_obj); mp_float_t y = mp_obj_get_float(y_obj); mp_float_t ans = f(x, y); @@ -61,30 +61,30 @@ STATIC mp_obj_t math_generic_2(mp_obj_t x_obj, mp_obj_t y_obj, mp_float_t (*f)(m } #define MATH_FUN_1(py_name, c_name) \ - STATIC mp_obj_t mp_math_##py_name(mp_obj_t x_obj) { \ + static mp_obj_t mp_math_##py_name(mp_obj_t x_obj) { \ return math_generic_1(x_obj, MICROPY_FLOAT_C_FUN(c_name)); \ } \ - STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_##py_name##_obj, mp_math_##py_name); + static MP_DEFINE_CONST_FUN_OBJ_1(mp_math_##py_name##_obj, mp_math_##py_name); #define MATH_FUN_1_TO_BOOL(py_name, c_name) \ - STATIC mp_obj_t mp_math_##py_name(mp_obj_t x_obj) { return mp_obj_new_bool(c_name(mp_obj_get_float(x_obj))); } \ - STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_##py_name##_obj, mp_math_##py_name); + static mp_obj_t mp_math_##py_name(mp_obj_t x_obj) { return mp_obj_new_bool(c_name(mp_obj_get_float(x_obj))); } \ + static MP_DEFINE_CONST_FUN_OBJ_1(mp_math_##py_name##_obj, mp_math_##py_name); #define MATH_FUN_1_TO_INT(py_name, c_name) \ - STATIC mp_obj_t mp_math_##py_name(mp_obj_t x_obj) { return mp_obj_new_int_from_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj))); } \ - STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_##py_name##_obj, mp_math_##py_name); + static mp_obj_t mp_math_##py_name(mp_obj_t x_obj) { return mp_obj_new_int_from_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj))); } \ + static MP_DEFINE_CONST_FUN_OBJ_1(mp_math_##py_name##_obj, mp_math_##py_name); #define MATH_FUN_2(py_name, c_name) \ - STATIC mp_obj_t mp_math_##py_name(mp_obj_t x_obj, mp_obj_t y_obj) { \ + static mp_obj_t mp_math_##py_name(mp_obj_t x_obj, mp_obj_t y_obj) { \ return math_generic_2(x_obj, y_obj, MICROPY_FLOAT_C_FUN(c_name)); \ } \ - STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_math_##py_name##_obj, mp_math_##py_name); + static MP_DEFINE_CONST_FUN_OBJ_2(mp_math_##py_name##_obj, mp_math_##py_name); #define MATH_FUN_2_FLT_INT(py_name, c_name) \ - STATIC mp_obj_t mp_math_##py_name(mp_obj_t x_obj, mp_obj_t y_obj) { \ + static mp_obj_t mp_math_##py_name(mp_obj_t x_obj, mp_obj_t y_obj) { \ return mp_obj_new_float(MICROPY_FLOAT_C_FUN(c_name)(mp_obj_get_float(x_obj), mp_obj_get_int(y_obj))); \ } \ - STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_math_##py_name##_obj, mp_math_##py_name); + static MP_DEFINE_CONST_FUN_OBJ_2(mp_math_##py_name##_obj, mp_math_##py_name); #if MP_NEED_LOG2 #undef log2 @@ -160,12 +160,12 @@ MATH_FUN_2(atan2, atan2) // ceil(x) MATH_FUN_1_TO_INT(ceil, ceil) // copysign(x, y) -STATIC mp_float_t MICROPY_FLOAT_C_FUN(copysign_func)(mp_float_t x, mp_float_t y) { +static mp_float_t MICROPY_FLOAT_C_FUN(copysign_func)(mp_float_t x, mp_float_t y) { return MICROPY_FLOAT_C_FUN(copysign)(x, y); } MATH_FUN_2(copysign, copysign_func) // fabs(x) -STATIC mp_float_t MICROPY_FLOAT_C_FUN(fabs_func)(mp_float_t x) { +static mp_float_t MICROPY_FLOAT_C_FUN(fabs_func)(mp_float_t x) { return MICROPY_FLOAT_C_FUN(fabs)(x); } MATH_FUN_1(fabs, fabs_func) @@ -203,7 +203,7 @@ MATH_FUN_1(lgamma, lgamma) // TODO: fsum #if MICROPY_PY_MATH_ISCLOSE -STATIC mp_obj_t mp_math_isclose(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t mp_math_isclose(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_rel_tol, ARG_abs_tol }; static const mp_arg_t allowed_args[] = { {MP_QSTR_rel_tol, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_obj = MP_OBJ_NULL}}, @@ -239,7 +239,7 @@ MP_DEFINE_CONST_FUN_OBJ_KW(mp_math_isclose_obj, 2, mp_math_isclose); // Function that takes a variable number of arguments // log(x[, base]) -STATIC mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) { mp_float_t x = mp_obj_get_float(args[0]); if (x <= (mp_float_t)0.0) { math_error(); @@ -258,12 +258,12 @@ STATIC mp_obj_t mp_math_log(size_t n_args, const mp_obj_t *args) { return mp_obj_new_float(l / MICROPY_FLOAT_C_FUN(log)(base)); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_math_log_obj, 1, 2, mp_math_log); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_math_log_obj, 1, 2, mp_math_log); // Functions that return a tuple // frexp(x): converts a floating-point number to fractional and integral components -STATIC mp_obj_t mp_math_frexp(mp_obj_t x_obj) { +static mp_obj_t mp_math_frexp(mp_obj_t x_obj) { int int_exponent = 0; mp_float_t significand = MICROPY_FLOAT_C_FUN(frexp)(mp_obj_get_float(x_obj), &int_exponent); mp_obj_t tuple[2]; @@ -271,10 +271,10 @@ STATIC mp_obj_t mp_math_frexp(mp_obj_t x_obj) { tuple[1] = mp_obj_new_int(int_exponent); return mp_obj_new_tuple(2, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_frexp_obj, mp_math_frexp); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_math_frexp_obj, mp_math_frexp); // modf(x) -STATIC mp_obj_t mp_math_modf(mp_obj_t x_obj) { +static mp_obj_t mp_math_modf(mp_obj_t x_obj) { mp_float_t int_part = 0.0; mp_float_t x = mp_obj_get_float(x_obj); mp_float_t fractional_part = MICROPY_FLOAT_C_FUN(modf)(x, &int_part); @@ -288,28 +288,28 @@ STATIC mp_obj_t mp_math_modf(mp_obj_t x_obj) { tuple[1] = mp_obj_new_float(int_part); return mp_obj_new_tuple(2, tuple); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_modf_obj, mp_math_modf); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_math_modf_obj, mp_math_modf); // Angular conversions // radians(x) -STATIC mp_obj_t mp_math_radians(mp_obj_t x_obj) { +static mp_obj_t mp_math_radians(mp_obj_t x_obj) { return mp_obj_new_float(mp_obj_get_float(x_obj) * (MP_PI / MICROPY_FLOAT_CONST(180.0))); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_radians_obj, mp_math_radians); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_math_radians_obj, mp_math_radians); // degrees(x) -STATIC mp_obj_t mp_math_degrees(mp_obj_t x_obj) { +static mp_obj_t mp_math_degrees(mp_obj_t x_obj) { return mp_obj_new_float(mp_obj_get_float(x_obj) * (MICROPY_FLOAT_CONST(180.0) / MP_PI)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_degrees_obj, mp_math_degrees); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_math_degrees_obj, mp_math_degrees); #if MICROPY_PY_MATH_FACTORIAL #if MICROPY_OPT_MATH_FACTORIAL // factorial(x): slightly efficient recursive implementation -STATIC mp_obj_t mp_math_factorial_inner(mp_uint_t start, mp_uint_t end) { +static mp_obj_t mp_math_factorial_inner(mp_uint_t start, mp_uint_t end) { if (start == end) { return mp_obj_new_int(start); } else if (end - start == 1) { @@ -327,7 +327,7 @@ STATIC mp_obj_t mp_math_factorial_inner(mp_uint_t start, mp_uint_t end) { return mp_binary_op(MP_BINARY_OP_MULTIPLY, left, right); } } -STATIC mp_obj_t mp_math_factorial(mp_obj_t x_obj) { +static mp_obj_t mp_math_factorial(mp_obj_t x_obj) { mp_int_t max = mp_obj_get_int(x_obj); if (max < 0) { mp_raise_ValueError(MP_ERROR_TEXT("negative factorial")); @@ -341,7 +341,7 @@ STATIC mp_obj_t mp_math_factorial(mp_obj_t x_obj) { // factorial(x): squared difference implementation // based on http://www.luschny.de/math/factorial/index.html -STATIC mp_obj_t mp_math_factorial(mp_obj_t x_obj) { +static mp_obj_t mp_math_factorial(mp_obj_t x_obj) { mp_int_t max = mp_obj_get_int(x_obj); if (max < 0) { mp_raise_ValueError(MP_ERROR_TEXT("negative factorial")); @@ -364,11 +364,11 @@ STATIC mp_obj_t mp_math_factorial(mp_obj_t x_obj) { #endif -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_factorial_obj, mp_math_factorial); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_math_factorial_obj, mp_math_factorial); #endif -STATIC const mp_rom_map_elem_t mp_module_math_globals_table[] = { +static const mp_rom_map_elem_t mp_module_math_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_math) }, { MP_ROM_QSTR(MP_QSTR_e), mp_const_float_e }, { MP_ROM_QSTR(MP_QSTR_pi), mp_const_float_pi }, @@ -429,7 +429,7 @@ STATIC const mp_rom_map_elem_t mp_module_math_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_math_globals, mp_module_math_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_math_globals, mp_module_math_globals_table); const mp_obj_module_t mp_module_math = { .base = { &mp_type_module }, diff --git a/py/modmicropython.c b/py/modmicropython.c index 17985b3e2b946..4a0e2cf44ffff 100644 --- a/py/modmicropython.c +++ b/py/modmicropython.c @@ -39,7 +39,7 @@ // CIRCUITPY-CHANGE: avoid warning #if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_ENABLE_COMPILER -STATIC mp_obj_t mp_micropython_opt_level(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_micropython_opt_level(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { return MP_OBJ_NEW_SMALL_INT(MP_STATE_VM(mp_optimise_value)); } else { @@ -47,27 +47,27 @@ STATIC mp_obj_t mp_micropython_opt_level(size_t n_args, const mp_obj_t *args) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_opt_level_obj, 0, 1, mp_micropython_opt_level); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_opt_level_obj, 0, 1, mp_micropython_opt_level); #endif // CIRCUITPY-CHANGE: avoid warning #if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_PY_MICROPYTHON_MEM_INFO #if MICROPY_MEM_STATS -STATIC mp_obj_t mp_micropython_mem_total(void) { +static mp_obj_t mp_micropython_mem_total(void) { return MP_OBJ_NEW_SMALL_INT(m_get_total_bytes_allocated()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_total_obj, mp_micropython_mem_total); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_total_obj, mp_micropython_mem_total); -STATIC mp_obj_t mp_micropython_mem_current(void) { +static mp_obj_t mp_micropython_mem_current(void) { return MP_OBJ_NEW_SMALL_INT(m_get_current_bytes_allocated()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_current_obj, mp_micropython_mem_current); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_current_obj, mp_micropython_mem_current); -STATIC mp_obj_t mp_micropython_mem_peak(void) { +static mp_obj_t mp_micropython_mem_peak(void) { return MP_OBJ_NEW_SMALL_INT(m_get_peak_bytes_allocated()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_peak_obj, mp_micropython_mem_peak); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_mem_peak_obj, mp_micropython_mem_peak); #endif mp_obj_t mp_micropython_mem_info(size_t n_args, const mp_obj_t *args) { @@ -93,9 +93,9 @@ mp_obj_t mp_micropython_mem_info(size_t n_args, const mp_obj_t *args) { #endif return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_mem_info_obj, 0, 1, mp_micropython_mem_info); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_mem_info_obj, 0, 1, mp_micropython_mem_info); -STATIC mp_obj_t mp_micropython_qstr_info(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_micropython_qstr_info(size_t n_args, const mp_obj_t *args) { (void)args; size_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes; qstr_pool_info(&n_pool, &n_qstr, &n_str_data_bytes, &n_total_bytes); @@ -107,73 +107,72 @@ STATIC mp_obj_t mp_micropython_qstr_info(size_t n_args, const mp_obj_t *args) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_qstr_info_obj, 0, 1, mp_micropython_qstr_info); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_qstr_info_obj, 0, 1, mp_micropython_qstr_info); #endif // MICROPY_PY_MICROPYTHON_MEM_INFO -// CIRCUITPY-CHANGE: avoid warning -#if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_PY_MICROPYTHON_STACK_USE -STATIC mp_obj_t mp_micropython_stack_use(void) { +#if MICROPY_PY_MICROPYTHON_STACK_USE +static mp_obj_t mp_micropython_stack_use(void) { return MP_OBJ_NEW_SMALL_INT(mp_stack_usage()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_stack_use_obj, mp_micropython_stack_use); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_stack_use_obj, mp_micropython_stack_use); #endif // CIRCUITPY-CHANGE: avoid warning #if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_ENABLE_PYSTACK -STATIC mp_obj_t mp_micropython_pystack_use(void) { +static mp_obj_t mp_micropython_pystack_use(void) { return MP_OBJ_NEW_SMALL_INT(mp_pystack_usage()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_pystack_use_obj, mp_micropython_pystack_use); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_pystack_use_obj, mp_micropython_pystack_use); #endif // CIRCUITPY-CHANGE: avoid warning #if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_ENABLE_GC -STATIC mp_obj_t mp_micropython_heap_lock(void) { +static mp_obj_t mp_micropython_heap_lock(void) { gc_lock(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_heap_lock_obj, mp_micropython_heap_lock); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_heap_lock_obj, mp_micropython_heap_lock); -STATIC mp_obj_t mp_micropython_heap_unlock(void) { +static mp_obj_t mp_micropython_heap_unlock(void) { gc_unlock(); return MP_OBJ_NEW_SMALL_INT(MP_STATE_THREAD(gc_lock_depth)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_heap_unlock_obj, mp_micropython_heap_unlock); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_heap_unlock_obj, mp_micropython_heap_unlock); #if MICROPY_PY_MICROPYTHON_HEAP_LOCKED -STATIC mp_obj_t mp_micropython_heap_locked(void) { +static mp_obj_t mp_micropython_heap_locked(void) { return MP_OBJ_NEW_SMALL_INT(MP_STATE_THREAD(gc_lock_depth)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_heap_locked_obj, mp_micropython_heap_locked); +static MP_DEFINE_CONST_FUN_OBJ_0(mp_micropython_heap_locked_obj, mp_micropython_heap_locked); #endif #endif // CIRCUITPY-CHANGE: avoid warning #if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_ENABLE_EMERGENCY_EXCEPTION_BUF && (MICROPY_EMERGENCY_EXCEPTION_BUF_SIZE == 0) -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_alloc_emergency_exception_buf_obj, mp_alloc_emergency_exception_buf); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_alloc_emergency_exception_buf_obj, mp_alloc_emergency_exception_buf); #endif // CIRCUITPY-CHANGE: avoid warning #if CIRCUITPY_MICROPYTHON_ADVANCED && MICROPY_KBD_EXCEPTION -STATIC mp_obj_t mp_micropython_kbd_intr(mp_obj_t int_chr_in) { +static mp_obj_t mp_micropython_kbd_intr(mp_obj_t int_chr_in) { mp_hal_set_interrupt_char(mp_obj_get_int(int_chr_in)); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_micropython_kbd_intr_obj, mp_micropython_kbd_intr); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_micropython_kbd_intr_obj, mp_micropython_kbd_intr); #endif #if MICROPY_ENABLE_SCHEDULER -STATIC mp_obj_t mp_micropython_schedule(mp_obj_t function, mp_obj_t arg) { +static mp_obj_t mp_micropython_schedule(mp_obj_t function, mp_obj_t arg) { if (!mp_sched_schedule(function, arg)) { mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("schedule queue full")); } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_micropython_schedule_obj, mp_micropython_schedule); +static MP_DEFINE_CONST_FUN_OBJ_2(mp_micropython_schedule_obj, mp_micropython_schedule); #endif -STATIC const mp_rom_map_elem_t mp_module_micropython_globals_table[] = { +static const mp_rom_map_elem_t mp_module_micropython_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_micropython) }, { MP_ROM_QSTR(MP_QSTR_const), MP_ROM_PTR(&mp_identity_obj) }, // CIRCUITPY-CHANGE: avoid warning @@ -219,7 +218,7 @@ STATIC const mp_rom_map_elem_t mp_module_micropython_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_micropython_globals, mp_module_micropython_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_micropython_globals, mp_module_micropython_globals_table); const mp_obj_module_t mp_module_micropython = { .base = { &mp_type_module }, diff --git a/py/modstruct.c b/py/modstruct.c index b2124ac677d3e..5e405bb0d9311 100644 --- a/py/modstruct.c +++ b/py/modstruct.c @@ -52,7 +52,7 @@ character data". */ -STATIC char get_fmt_type(const char **fmt) { +static char get_fmt_type(const char **fmt) { char t = **fmt; switch (t) { case '!': @@ -71,7 +71,7 @@ STATIC char get_fmt_type(const char **fmt) { return t; } -STATIC mp_uint_t get_fmt_num(const char **p) { +static mp_uint_t get_fmt_num(const char **p) { const char *num = *p; uint len = 1; while (unichar_isdigit(*++num)) { @@ -82,7 +82,7 @@ STATIC mp_uint_t get_fmt_num(const char **p) { return val; } -STATIC size_t calc_size_items(const char *fmt, size_t *total_sz) { +static size_t calc_size_items(const char *fmt, size_t *total_sz) { char fmt_type = get_fmt_type(&fmt); size_t total_cnt = 0; size_t size; @@ -112,7 +112,7 @@ STATIC size_t calc_size_items(const char *fmt, size_t *total_sz) { return total_cnt; } -STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) { +static mp_obj_t struct_calcsize(mp_obj_t fmt_in) { const char *fmt = mp_obj_str_get_str(fmt_in); size_t size; calc_size_items(fmt, &size); @@ -120,7 +120,7 @@ STATIC mp_obj_t struct_calcsize(mp_obj_t fmt_in) { } MP_DEFINE_CONST_FUN_OBJ_1(struct_calcsize_obj, struct_calcsize); -STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) { +static mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) { // unpack requires that the buffer be exactly the right size. // unpack_from requires that the buffer be "big enough". // Since we implement unpack and unpack_from using the same function @@ -180,7 +180,7 @@ STATIC mp_obj_t struct_unpack_from(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_unpack_from_obj, 2, 3, struct_unpack_from); // This function assumes there is enough room in p to store all the values -STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, const mp_obj_t *args) { +static void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, const mp_obj_t *args) { // CIRCUITPY-CHANGE: additional error checking size_t size; size_t count = calc_size_items(mp_obj_str_get_str(fmt_in), &size); @@ -229,7 +229,7 @@ STATIC void struct_pack_into_internal(mp_obj_t fmt_in, byte *p, size_t n_args, c } } -STATIC mp_obj_t struct_pack(size_t n_args, const mp_obj_t *args) { +static mp_obj_t struct_pack(size_t n_args, const mp_obj_t *args) { // TODO: "The arguments must match the values required by the format exactly." mp_int_t size = MP_OBJ_SMALL_INT_VALUE(struct_calcsize(args[0])); vstr_t vstr; @@ -241,7 +241,7 @@ STATIC mp_obj_t struct_pack(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_pack_obj, 1, MP_OBJ_FUN_ARGS_MAX, struct_pack); -STATIC mp_obj_t struct_pack_into(size_t n_args, const mp_obj_t *args) { +static mp_obj_t struct_pack_into(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_WRITE); mp_int_t offset = mp_obj_get_int(args[2]); @@ -267,7 +267,7 @@ STATIC mp_obj_t struct_pack_into(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(struct_pack_into_obj, 3, MP_OBJ_FUN_ARGS_MAX, struct_pack_into); -STATIC const mp_rom_map_elem_t mp_module_struct_globals_table[] = { +static const mp_rom_map_elem_t mp_module_struct_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_struct) }, { MP_ROM_QSTR(MP_QSTR_calcsize), MP_ROM_PTR(&struct_calcsize_obj) }, { MP_ROM_QSTR(MP_QSTR_pack), MP_ROM_PTR(&struct_pack_obj) }, @@ -276,7 +276,7 @@ STATIC const mp_rom_map_elem_t mp_module_struct_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_unpack_from), MP_ROM_PTR(&struct_unpack_from_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_struct_globals, mp_module_struct_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_struct_globals, mp_module_struct_globals_table); const mp_obj_module_t mp_module_struct = { .base = { &mp_type_module }, diff --git a/py/modsys.c b/py/modsys.c index 6397467c2282d..2bb2606a0627b 100644 --- a/py/modsys.c +++ b/py/modsys.c @@ -64,15 +64,15 @@ const mp_print_t mp_sys_stdout_print = {&mp_sys_stdout_obj, mp_stream_write_adap #endif // version - Python language version that this implementation conforms to, as a string -STATIC const MP_DEFINE_STR_OBJ(mp_sys_version_obj, "3.4.0; " MICROPY_BANNER_NAME_AND_VERSION); +static const MP_DEFINE_STR_OBJ(mp_sys_version_obj, "3.4.0; " MICROPY_BANNER_NAME_AND_VERSION); // version_info - Python language version that this implementation conforms to, as a tuple of ints // TODO: CPython is now at 5-element array (major, minor, micro, releaselevel, serial), but save 2 els so far... -STATIC const mp_rom_obj_tuple_t mp_sys_version_info_obj = {{&mp_type_tuple}, 3, {MP_ROM_INT(3), MP_ROM_INT(4), MP_ROM_INT(0)}}; +static const mp_rom_obj_tuple_t mp_sys_version_info_obj = {{&mp_type_tuple}, 3, {MP_ROM_INT(3), MP_ROM_INT(4), MP_ROM_INT(0)}}; // sys.implementation object // this holds the MicroPython version -STATIC const mp_rom_obj_tuple_t mp_sys_implementation_version_info_obj = { +static const mp_rom_obj_tuple_t mp_sys_implementation_version_info_obj = { {&mp_type_tuple}, 4, { @@ -86,7 +86,7 @@ STATIC const mp_rom_obj_tuple_t mp_sys_implementation_version_info_obj = { #endif } }; -STATIC const MP_DEFINE_STR_OBJ(mp_sys_implementation_machine_obj, MICROPY_BANNER_MACHINE); +static const MP_DEFINE_STR_OBJ(mp_sys_implementation_machine_obj, MICROPY_BANNER_MACHINE); // CIRCUITPY-CHANGE: MP_QSTR_circuitpython #define SYS_IMPLEMENTATION_ELEMS_BASE \ MP_ROM_QSTR(MP_QSTR_circuitpython), \ @@ -108,7 +108,7 @@ STATIC const MP_DEFINE_STR_OBJ(mp_sys_implementation_machine_obj, MICROPY_BANNER #define SYS_IMPLEMENTATION_ELEMS__V2 #endif -STATIC const qstr impl_fields[] = { +static const qstr impl_fields[] = { MP_QSTR_name, MP_QSTR_version, MP_QSTR__machine, @@ -119,7 +119,7 @@ STATIC const qstr impl_fields[] = { MP_QSTR__v2, #endif }; -STATIC MP_DEFINE_ATTRTUPLE( +static MP_DEFINE_ATTRTUPLE( mp_sys_implementation_obj, impl_fields, 3 + MICROPY_PERSISTENT_CODE_LOAD + MICROPY_PREVIEW_VERSION_2, @@ -128,7 +128,7 @@ STATIC MP_DEFINE_ATTRTUPLE( SYS_IMPLEMENTATION_ELEMS__V2 ); #else -STATIC const mp_rom_obj_tuple_t mp_sys_implementation_obj = { +static const mp_rom_obj_tuple_t mp_sys_implementation_obj = { {&mp_type_tuple}, 3 + MICROPY_PERSISTENT_CODE_LOAD, // Do not include SYS_IMPLEMENTATION_ELEMS__V2 because @@ -147,7 +147,7 @@ STATIC const mp_rom_obj_tuple_t mp_sys_implementation_obj = { #ifdef MICROPY_PY_SYS_PLATFORM // platform - the platform that MicroPython is running on -STATIC const MP_DEFINE_STR_OBJ(mp_sys_platform_obj, MICROPY_PY_SYS_PLATFORM); +static const MP_DEFINE_STR_OBJ(mp_sys_platform_obj, MICROPY_PY_SYS_PLATFORM); #endif #ifdef MICROPY_PY_SYS_EXECUTABLE @@ -161,7 +161,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_intern_obj, mp_obj_str_intern_checked); #endif // 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) { +static mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) { if (n_args == 0) { mp_raise_type(&mp_type_SystemExit); } else { @@ -170,7 +170,7 @@ STATIC mp_obj_t mp_sys_exit(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_exit_obj, 0, 1, mp_sys_exit); -STATIC mp_obj_t mp_sys_print_exception(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_sys_print_exception(size_t n_args, const mp_obj_t *args) { // CIRCUITPY-CHANGE #if CIRCUITPY_WARNINGS warnings_warn(&mp_type_FutureWarning, MP_ERROR_TEXT("%q moved from %q to %q"), MP_QSTR_print_exception, MP_QSTR_sys, MP_QSTR_traceback); @@ -195,7 +195,7 @@ STATIC mp_obj_t mp_sys_print_exception(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_sys_print_exception_obj, 1, 2, mp_sys_print_exception); #if MICROPY_PY_SYS_EXC_INFO -STATIC mp_obj_t mp_sys_exc_info(void) { +static mp_obj_t mp_sys_exc_info(void) { mp_obj_t cur_exc = MP_OBJ_FROM_PTR(MP_STATE_VM(cur_exception)); mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL)); @@ -216,25 +216,25 @@ MP_DEFINE_CONST_FUN_OBJ_0(mp_sys_exc_info_obj, mp_sys_exc_info); #endif #if MICROPY_PY_SYS_GETSIZEOF -STATIC mp_obj_t mp_sys_getsizeof(mp_obj_t obj) { +static mp_obj_t mp_sys_getsizeof(mp_obj_t obj) { return mp_unary_op(MP_UNARY_OP_SIZEOF, obj); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_getsizeof_obj, mp_sys_getsizeof); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_getsizeof_obj, mp_sys_getsizeof); #endif #if MICROPY_PY_SYS_ATEXIT // atexit(callback): Callback is called when sys.exit is called. -STATIC mp_obj_t mp_sys_atexit(mp_obj_t obj) { +static mp_obj_t mp_sys_atexit(mp_obj_t obj) { mp_obj_t old = MP_STATE_VM(sys_exitfunc); MP_STATE_VM(sys_exitfunc) = obj; return old; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_atexit_obj, mp_sys_atexit); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_atexit_obj, mp_sys_atexit); #endif #if MICROPY_PY_SYS_SETTRACE // settrace(tracefunc): Set the system's trace function. -STATIC mp_obj_t mp_sys_settrace(mp_obj_t obj) { +static mp_obj_t mp_sys_settrace(mp_obj_t obj) { return mp_prof_settrace(obj); } MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_settrace_obj, mp_sys_settrace); @@ -258,7 +258,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(mp_sys_settrace_obj, mp_sys_settrace); #if MICROPY_PY_SYS_ATTR_DELEGATION // Must be kept in sync with the enum at the top of mpstate.h. -STATIC const uint16_t sys_mutable_keys[] = { +static const uint16_t sys_mutable_keys[] = { #if MICROPY_PY_SYS_PATH // Code should access this (as an mp_obj_t) for use with e.g. // mp_obj_list_append by using the `mp_sys_path` macro defined in runtime.h. @@ -281,7 +281,7 @@ void mp_module_sys_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } #endif -STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = { +static const mp_rom_map_elem_t mp_module_sys_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_sys) }, #if MICROPY_PY_SYS_ARGV @@ -354,7 +354,7 @@ STATIC const mp_rom_map_elem_t mp_module_sys_globals_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(mp_module_sys_globals, mp_module_sys_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_sys_globals, mp_module_sys_globals_table); const mp_obj_module_t mp_module_sys = { .base = { &mp_type_module }, diff --git a/py/modthread.c b/py/modthread.c index aac58076f3026..188449802fdd2 100644 --- a/py/modthread.c +++ b/py/modthread.c @@ -45,7 +45,7 @@ /****************************************************************/ // Lock object -STATIC const mp_obj_type_t mp_type_thread_lock; +static const mp_obj_type_t mp_type_thread_lock; typedef struct _mp_obj_thread_lock_t { mp_obj_base_t base; @@ -53,14 +53,14 @@ typedef struct _mp_obj_thread_lock_t { volatile bool locked; } mp_obj_thread_lock_t; -STATIC mp_obj_thread_lock_t *mp_obj_new_thread_lock(void) { +static mp_obj_thread_lock_t *mp_obj_new_thread_lock(void) { mp_obj_thread_lock_t *self = mp_obj_malloc(mp_obj_thread_lock_t, &mp_type_thread_lock); mp_thread_mutex_init(&self->mutex); self->locked = false; return self; } -STATIC mp_obj_t thread_lock_acquire(size_t n_args, const mp_obj_t *args) { +static mp_obj_t thread_lock_acquire(size_t n_args, const mp_obj_t *args) { mp_obj_thread_lock_t *self = MP_OBJ_TO_PTR(args[0]); bool wait = true; if (n_args > 1) { @@ -79,9 +79,9 @@ STATIC mp_obj_t thread_lock_acquire(size_t n_args, const mp_obj_t *args) { mp_raise_OSError(-ret); } } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock_acquire_obj, 1, 3, thread_lock_acquire); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock_acquire_obj, 1, 3, thread_lock_acquire); -STATIC mp_obj_t thread_lock_release(mp_obj_t self_in) { +static mp_obj_t thread_lock_release(mp_obj_t self_in) { mp_obj_thread_lock_t *self = MP_OBJ_TO_PTR(self_in); if (!self->locked) { mp_raise_msg(&mp_type_RuntimeError, NULL); @@ -92,21 +92,21 @@ STATIC mp_obj_t thread_lock_release(mp_obj_t self_in) { MP_THREAD_GIL_ENTER(); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(thread_lock_release_obj, thread_lock_release); +static MP_DEFINE_CONST_FUN_OBJ_1(thread_lock_release_obj, thread_lock_release); -STATIC mp_obj_t thread_lock_locked(mp_obj_t self_in) { +static mp_obj_t thread_lock_locked(mp_obj_t self_in) { mp_obj_thread_lock_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_bool(self->locked); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(thread_lock_locked_obj, thread_lock_locked); +static MP_DEFINE_CONST_FUN_OBJ_1(thread_lock_locked_obj, thread_lock_locked); -STATIC mp_obj_t thread_lock___exit__(size_t n_args, const mp_obj_t *args) { +static mp_obj_t thread_lock___exit__(size_t n_args, const mp_obj_t *args) { (void)n_args; // unused return thread_lock_release(args[0]); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock___exit___obj, 4, 4, thread_lock___exit__); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(thread_lock___exit___obj, 4, 4, thread_lock___exit__); -STATIC const mp_rom_map_elem_t thread_lock_locals_dict_table[] = { +static const mp_rom_map_elem_t thread_lock_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_acquire), MP_ROM_PTR(&thread_lock_acquire_obj) }, { MP_ROM_QSTR(MP_QSTR_release), MP_ROM_PTR(&thread_lock_release_obj) }, { MP_ROM_QSTR(MP_QSTR_locked), MP_ROM_PTR(&thread_lock_locked_obj) }, @@ -114,9 +114,9 @@ STATIC const mp_rom_map_elem_t thread_lock_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&thread_lock___exit___obj) }, }; -STATIC MP_DEFINE_CONST_DICT(thread_lock_locals_dict, thread_lock_locals_dict_table); +static MP_DEFINE_CONST_DICT(thread_lock_locals_dict, thread_lock_locals_dict_table); -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_thread_lock, MP_QSTR_lock, MP_TYPE_FLAG_NONE, @@ -126,15 +126,14 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( /****************************************************************/ // _thread module -STATIC size_t thread_stack_size = 0; +static size_t thread_stack_size = 0; -STATIC mp_obj_t mod_thread_get_ident(void) { - // CIRCUITPY-CHANGE: uintptr_t cast to avoid warning - return mp_obj_new_int_from_uint((uintptr_t)mp_thread_get_state()); +static mp_obj_t mod_thread_get_ident(void) { + return mp_obj_new_int_from_uint(mp_thread_get_id()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_get_ident_obj, mod_thread_get_ident); +static MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_get_ident_obj, mod_thread_get_ident); -STATIC mp_obj_t mod_thread_stack_size(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_thread_stack_size(size_t n_args, const mp_obj_t *args) { mp_obj_t ret = mp_obj_new_int_from_uint(thread_stack_size); if (n_args == 0) { thread_stack_size = 0; @@ -143,7 +142,7 @@ STATIC mp_obj_t mod_thread_stack_size(size_t n_args, const mp_obj_t *args) { } return ret; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_stack_size_obj, 0, 1, mod_thread_stack_size); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_stack_size_obj, 0, 1, mod_thread_stack_size); typedef struct _thread_entry_args_t { mp_obj_dict_t *dict_locals; @@ -155,16 +154,13 @@ typedef struct _thread_entry_args_t { mp_obj_t args[]; } thread_entry_args_t; -STATIC void *thread_entry(void *args_in) { +static void *thread_entry(void *args_in) { // Execution begins here for a new thread. We do not have the GIL. thread_entry_args_t *args = (thread_entry_args_t *)args_in; mp_state_thread_t ts; - mp_thread_set_state(&ts); - - mp_stack_set_top(&ts + 1); // need to include ts in root-pointer scan - mp_stack_set_limit(args->stack_size); + mp_thread_init_state(&ts, args->stack_size, args->dict_locals, args->dict_globals); #if MICROPY_ENABLE_PYSTACK // TODO threading and pystack is not fully supported, for now just make a small stack @@ -172,6 +168,7 @@ STATIC void *thread_entry(void *args_in) { mp_pystack_init(mini_pystack, &mini_pystack[128]); #endif + // CIRCUITPY-CHANGE // The GC starts off unlocked on this thread. ts.gc_lock_depth = 0; @@ -221,7 +218,7 @@ STATIC void *thread_entry(void *args_in) { return NULL; } -STATIC mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args) { // This structure holds the Python function and arguments for thread entry. // We copy all arguments into this structure to keep ownership of them. // We must be very careful about root pointers because this pointer may @@ -272,19 +269,19 @@ STATIC mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args) // spawn the thread! return mp_obj_new_int_from_uint(mp_thread_create(thread_entry, th_args, &th_args->stack_size)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_start_new_thread_obj, 2, 3, mod_thread_start_new_thread); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mod_thread_start_new_thread_obj, 2, 3, mod_thread_start_new_thread); -STATIC mp_obj_t mod_thread_exit(void) { +static mp_obj_t mod_thread_exit(void) { mp_raise_type(&mp_type_SystemExit); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_exit_obj, mod_thread_exit); +static MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_exit_obj, mod_thread_exit); -STATIC mp_obj_t mod_thread_allocate_lock(void) { +static mp_obj_t mod_thread_allocate_lock(void) { return MP_OBJ_FROM_PTR(mp_obj_new_thread_lock()); } -STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_allocate_lock_obj, mod_thread_allocate_lock); +static MP_DEFINE_CONST_FUN_OBJ_0(mod_thread_allocate_lock_obj, mod_thread_allocate_lock); -STATIC const mp_rom_map_elem_t mp_module_thread_globals_table[] = { +static const mp_rom_map_elem_t mp_module_thread_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR__thread) }, { MP_ROM_QSTR(MP_QSTR_LockType), MP_ROM_PTR(&mp_type_thread_lock) }, { MP_ROM_QSTR(MP_QSTR_get_ident), MP_ROM_PTR(&mod_thread_get_ident_obj) }, @@ -294,7 +291,7 @@ STATIC const mp_rom_map_elem_t mp_module_thread_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_allocate_lock), MP_ROM_PTR(&mod_thread_allocate_lock_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_module_thread_globals, mp_module_thread_globals_table); +static MP_DEFINE_CONST_DICT(mp_module_thread_globals, mp_module_thread_globals_table); const mp_obj_module_t mp_module_thread = { .base = { &mp_type_module }, diff --git a/py/mpconfig.h b/py/mpconfig.h index 0a846bcd7cb33..60e7afe52f953 100644 --- a/py/mpconfig.h +++ b/py/mpconfig.h @@ -36,10 +36,12 @@ #if CIRCUITPY #include "genhdr/mpversion.h" #else -// Current version of MicroPython +// Current version of MicroPython. This is used by sys.implementation.version +// as well as a fallback to generate MICROPY_GIT_TAG if the git repo or tags +// are unavailable. #define MICROPY_VERSION_MAJOR 1 -#define MICROPY_VERSION_MINOR 22 -#define MICROPY_VERSION_MICRO 2 +#define MICROPY_VERSION_MINOR 23 +#define MICROPY_VERSION_MICRO 0 #define MICROPY_VERSION_PRERELEASE 0 // Combined version as a 32-bit number for convenience to allow version @@ -300,10 +302,12 @@ // Number of bytes used to store qstr hash #ifndef MICROPY_QSTR_BYTES_IN_HASH -#if MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES +#if MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES #define MICROPY_QSTR_BYTES_IN_HASH (2) -#else +#elif MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES #define MICROPY_QSTR_BYTES_IN_HASH (1) +#else +#define MICROPY_QSTR_BYTES_IN_HASH (0) #endif #endif @@ -454,6 +458,11 @@ #define MICROPY_DYNAMIC_COMPILER (0) #endif +// Whether the compiler allows compiling top-level await expressions +#ifndef MICROPY_COMP_ALLOW_TOP_LEVEL_AWAIT +#define MICROPY_COMP_ALLOW_TOP_LEVEL_AWAIT (0) +#endif + // Whether to enable constant folding; eg 1+2 rewritten as 3 #ifndef MICROPY_COMP_CONST_FOLDING #define MICROPY_COMP_CONST_FOLDING (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES) @@ -599,6 +608,12 @@ /*****************************************************************************/ /* Python internal features */ +// Use a special long jump in nlrthumb.c, which may be necessary if nlr.o and +// nlrthumb.o are linked far apart from each other. +#ifndef MICROPY_NLR_THUMB_USE_LONG_JUMP +#define MICROPY_NLR_THUMB_USE_LONG_JUMP (0) +#endif + // Whether to enable import of external modules // When disabled, only importing of built-in modules is supported // When enabled, a port must implement mp_import_stat (among other things) @@ -866,6 +881,15 @@ typedef double mp_float_t; #define MICROPY_PY_BUILTINS_COMPLEX (MICROPY_PY_BUILTINS_FLOAT) #endif +// Whether to use the native _Float16 for 16-bit float support +#ifndef MICROPY_FLOAT_USE_NATIVE_FLT16 +#ifdef __FLT16_MAX__ +#define MICROPY_FLOAT_USE_NATIVE_FLT16 (1) +#else +#define MICROPY_FLOAT_USE_NATIVE_FLT16 (0) +#endif +#endif + // Whether to provide a high-quality hash for float and complex numbers. // Otherwise the default is a very simple but correct hashing function. #ifndef MICROPY_FLOAT_HIGH_QUALITY_HASH @@ -1339,13 +1363,11 @@ typedef double mp_float_t; #define MICROPY_PY_COLLECTIONS_DEQUE (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif -// CIRCUITPY-CHANGE // Whether "collections.deque" supports iteration #ifndef MICROPY_PY_COLLECTIONS_DEQUE_ITER #define MICROPY_PY_COLLECTIONS_DEQUE_ITER (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) #endif -// CIRCUITPY-CHANGE // Whether "collections.deque" supports subscription #ifndef MICROPY_PY_COLLECTIONS_DEQUE_SUBSCR #define MICROPY_PY_COLLECTIONS_DEQUE_SUBSCR (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_EXTRA_FEATURES) @@ -1752,6 +1774,11 @@ typedef double mp_float_t; #define MICROPY_PY_MACHINE (0) #endif +// Whether to include: reset, reset_cause +#ifndef MICROPY_PY_MACHINE_RESET +#define MICROPY_PY_MACHINE_RESET (0) +#endif + // Whether to include: bitstream #ifndef MICROPY_PY_MACHINE_BITSTREAM #define MICROPY_PY_MACHINE_BITSTREAM (0) @@ -1762,6 +1789,16 @@ typedef double mp_float_t; #define MICROPY_PY_MACHINE_PULSE (0) #endif +// Whether to provide the "machine.mem8/16/32" objects +#ifndef MICROPY_PY_MACHINE_MEMX +#define MICROPY_PY_MACHINE_MEMX (MICROPY_PY_MACHINE) +#endif + +// Whether to provide the "machine.Signal" class +#ifndef MICROPY_PY_MACHINE_SIGNAL +#define MICROPY_PY_MACHINE_SIGNAL (MICROPY_PY_MACHINE) +#endif + #ifndef MICROPY_PY_MACHINE_I2C #define MICROPY_PY_MACHINE_I2C (0) #endif @@ -1804,6 +1841,11 @@ typedef double mp_float_t; #define MICROPY_PY_SSL_FINALISER (MICROPY_ENABLE_FINALISER) #endif +// Whether to provide the "vfs" module +#ifndef MICROPY_PY_VFS +#define MICROPY_PY_VFS (MICROPY_CONFIG_ROM_LEVEL_AT_LEAST_CORE_FEATURES && MICROPY_VFS) +#endif + #ifndef MICROPY_PY_WEBSOCKET #define MICROPY_PY_WEBSOCKET (0) #endif @@ -1904,6 +1946,7 @@ typedef double mp_float_t; #if MICROPY_PREVIEW_VERSION_2 #define MICROPY_BANNER_NAME_AND_VERSION "MicroPython (with v2.0 preview) " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE #else +// CIRCUITPY-CHANGE: "CircuitPython" #define MICROPY_BANNER_NAME_AND_VERSION "CircuitPython " MICROPY_GIT_TAG " on " MICROPY_BUILD_DATE #endif #endif @@ -1917,12 +1960,6 @@ typedef double mp_float_t; #endif #endif -// Allow to override static modifier for global objects, e.g. to use with -// object code analysis tools which don't support static symbols. -#ifndef STATIC -#define STATIC static -#endif - // Number of bytes in an object word: mp_obj_t, mp_uint_t, mp_uint_t #ifndef MP_BYTES_PER_OBJ_WORD #define MP_BYTES_PER_OBJ_WORD (sizeof(mp_uint_t)) diff --git a/py/mpprint.c b/py/mpprint.c index 18bc1e5b9b79a..e4e25f5a82e43 100644 --- a/py/mpprint.c +++ b/py/mpprint.c @@ -43,7 +43,7 @@ static const char pad_spaces[] = " "; static const char pad_zeroes[] = "0000000000000000"; -STATIC void plat_print_strn(void *env, const char *str, size_t len) { +static void plat_print_strn(void *env, const char *str, size_t len) { (void)env; MP_PLAT_PRINT_STRN(str, len); } @@ -127,7 +127,7 @@ int mp_print_strn(const mp_print_t *print, const char *str, size_t len, int flag // This function is used exclusively by mp_vprintf to format ints. // It needs to be a separate function to mp_print_mp_int, since converting to a mp_int looses the MSB. -STATIC int mp_print_int(const mp_print_t *print, mp_uint_t x, int sgn, int base, int base_char, int flags, char fill, int width) { +static int mp_print_int(const mp_print_t *print, mp_uint_t x, int sgn, int base, int base_char, int flags, char fill, int width) { char sign = 0; if (sgn) { if ((mp_int_t)x < 0) { diff --git a/py/mpstate.h b/py/mpstate.h index 1898982e1c1eb..7308e57b58193 100644 --- a/py/mpstate.h +++ b/py/mpstate.h @@ -3,7 +3,7 @@ * * The MIT License (MIT) * - * SPDX-FileCopyrightText: Copyright (c) 2014 Damien P. George + * Copyright (c) 2014 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 @@ -146,9 +146,6 @@ typedef struct _mp_state_mem_t { // This is a global mutex used to make the GC thread-safe. mp_thread_mutex_t gc_mutex; #endif - - // CIRCUITPY-CHANGE - void **permanent_pointers; } mp_state_mem_t; // This structure hold runtime and VM information. It includes a section @@ -342,6 +339,7 @@ extern mp_state_ctx_t mp_state_ctx; #define MP_STATE_MAIN_THREAD(x) (mp_state_ctx.thread.x) #if MICROPY_PY_THREAD +// CIRCUITPY-CHANGE: explicit declaration extern mp_state_thread_t *mp_thread_get_state(void); #define MP_STATE_THREAD(x) (mp_thread_get_state()->x) #define mp_thread_is_main_thread() (mp_thread_get_state() == &mp_state_ctx.thread) diff --git a/py/mpz.c b/py/mpz.c index 6317d93d4cb26..746c9fe5b69bc 100644 --- a/py/mpz.c +++ b/py/mpz.c @@ -49,7 +49,7 @@ Definition of normalise: ? */ -STATIC size_t mpn_remove_trailing_zeros(mpz_dig_t *oidig, mpz_dig_t *idig) { +static size_t mpn_remove_trailing_zeros(mpz_dig_t *oidig, mpz_dig_t *idig) { for (--idig; idig >= oidig && *idig == 0; --idig) { } return idig + 1 - oidig; @@ -59,7 +59,7 @@ STATIC size_t mpn_remove_trailing_zeros(mpz_dig_t *oidig, mpz_dig_t *idig) { returns sign(i - j) assumes i, j are normalised */ -STATIC int mpn_cmp(const mpz_dig_t *idig, size_t ilen, const mpz_dig_t *jdig, size_t jlen) { +static int mpn_cmp(const mpz_dig_t *idig, size_t ilen, const mpz_dig_t *jdig, size_t jlen) { if (ilen < jlen) { return -1; } @@ -85,7 +85,7 @@ STATIC int mpn_cmp(const mpz_dig_t *idig, size_t ilen, const mpz_dig_t *jdig, si assumes enough memory in i; assumes normalised j; assumes n > 0 can have i, j pointing to same memory */ -STATIC size_t mpn_shl(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mp_uint_t n) { +static size_t mpn_shl(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mp_uint_t n) { mp_uint_t n_whole = (n + DIG_SIZE - 1) / DIG_SIZE; mp_uint_t n_part = n % DIG_SIZE; if (n_part == 0) { @@ -124,7 +124,7 @@ STATIC size_t mpn_shl(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mp_uint_t n assumes enough memory in i; assumes normalised j; assumes n > 0 can have i, j pointing to same memory */ -STATIC size_t mpn_shr(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mp_uint_t n) { +static size_t mpn_shr(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mp_uint_t n) { mp_uint_t n_whole = n / DIG_SIZE; mp_uint_t n_part = n % DIG_SIZE; @@ -156,7 +156,7 @@ STATIC size_t mpn_shr(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mp_uint_t n assumes enough memory in i; assumes normalised j, k; assumes jlen >= klen can have i, j, k pointing to same memory */ -STATIC size_t mpn_add(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen) { +static size_t mpn_add(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen) { mpz_dig_t *oidig = idig; mpz_dbl_dig_t carry = 0; @@ -186,7 +186,7 @@ STATIC size_t mpn_add(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const assumes enough memory in i; assumes normalised j, k; assumes j >= k can have i, j, k pointing to same memory */ -STATIC size_t mpn_sub(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen) { +static size_t mpn_sub(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen) { mpz_dig_t *oidig = idig; mpz_dbl_dig_signed_t borrow = 0; @@ -214,7 +214,7 @@ STATIC size_t mpn_sub(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const assumes enough memory in i; assumes normalised j, k; assumes jlen >= klen (jlen argument not needed) can have i, j, k pointing to same memory */ -STATIC size_t mpn_and(mpz_dig_t *idig, const mpz_dig_t *jdig, const mpz_dig_t *kdig, size_t klen) { +static size_t mpn_and(mpz_dig_t *idig, const mpz_dig_t *jdig, const mpz_dig_t *kdig, size_t klen) { mpz_dig_t *oidig = idig; for (; klen > 0; --klen, ++idig, ++jdig, ++kdig) { @@ -235,7 +235,7 @@ STATIC size_t mpn_and(mpz_dig_t *idig, const mpz_dig_t *jdig, const mpz_dig_t *k assumes enough memory in i; assumes normalised j, k; assumes length j >= length k can have i, j, k pointing to same memory */ -STATIC size_t mpn_and_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen, +static size_t mpn_and_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen, mpz_dbl_dig_t carryi, mpz_dbl_dig_t carryj, mpz_dbl_dig_t carryk) { mpz_dig_t *oidig = idig; mpz_dig_t imask = (0 == carryi) ? 0 : DIG_MASK; @@ -266,7 +266,7 @@ STATIC size_t mpn_and_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, c assumes enough memory in i; assumes normalised j, k; assumes jlen >= klen can have i, j, k pointing to same memory */ -STATIC size_t mpn_or(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen) { +static size_t mpn_or(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen) { mpz_dig_t *oidig = idig; jlen -= klen; @@ -296,7 +296,7 @@ STATIC size_t mpn_or(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const #if MICROPY_OPT_MPZ_BITWISE -STATIC size_t mpn_or_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen, +static size_t mpn_or_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen, mpz_dbl_dig_t carryj, mpz_dbl_dig_t carryk) { mpz_dig_t *oidig = idig; mpz_dbl_dig_t carryi = 1; @@ -326,7 +326,7 @@ STATIC size_t mpn_or_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, co #else -STATIC size_t mpn_or_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen, +static size_t mpn_or_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen, mpz_dbl_dig_t carryi, mpz_dbl_dig_t carryj, mpz_dbl_dig_t carryk) { mpz_dig_t *oidig = idig; mpz_dig_t imask = (0 == carryi) ? 0 : DIG_MASK; @@ -358,7 +358,7 @@ STATIC size_t mpn_or_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, co assumes enough memory in i; assumes normalised j, k; assumes jlen >= klen can have i, j, k pointing to same memory */ -STATIC size_t mpn_xor(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen) { +static size_t mpn_xor(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen) { mpz_dig_t *oidig = idig; jlen -= klen; @@ -385,7 +385,7 @@ STATIC size_t mpn_xor(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const assumes enough memory in i; assumes normalised j, k; assumes length j >= length k can have i, j, k pointing to same memory */ -STATIC size_t mpn_xor_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen, +static size_t mpn_xor_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, const mpz_dig_t *kdig, size_t klen, mpz_dbl_dig_t carryi, mpz_dbl_dig_t carryj, mpz_dbl_dig_t carryk) { mpz_dig_t *oidig = idig; @@ -410,7 +410,7 @@ STATIC size_t mpn_xor_neg(mpz_dig_t *idig, const mpz_dig_t *jdig, size_t jlen, c returns number of digits in i assumes enough memory in i; assumes normalised i; assumes dmul != 0 */ -STATIC size_t mpn_mul_dig_add_dig(mpz_dig_t *idig, size_t ilen, mpz_dig_t dmul, mpz_dig_t dadd) { +static size_t mpn_mul_dig_add_dig(mpz_dig_t *idig, size_t ilen, mpz_dig_t dmul, mpz_dig_t dadd) { mpz_dig_t *oidig = idig; mpz_dbl_dig_t carry = dadd; @@ -432,7 +432,7 @@ STATIC size_t mpn_mul_dig_add_dig(mpz_dig_t *idig, size_t ilen, mpz_dig_t dmul, assumes enough memory in i; assumes i is zeroed; assumes normalised j, k can have j, k point to same memory */ -STATIC size_t mpn_mul(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mpz_dig_t *kdig, size_t klen) { +static size_t mpn_mul(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mpz_dig_t *kdig, size_t klen) { mpz_dig_t *oidig = idig; size_t ilen = 0; @@ -452,7 +452,7 @@ STATIC size_t mpn_mul(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mpz_dig_t * } ilen = id - oidig; - // CIRCUITPY-CHANGE: check to prevent usb starvation + // CIRCUITPY-CHANGE: prevent usb and other background task starvation #ifdef RUN_BACKGROUND_TASKS RUN_BACKGROUND_TASKS; #endif @@ -467,7 +467,7 @@ STATIC size_t mpn_mul(mpz_dig_t *idig, mpz_dig_t *jdig, size_t jlen, mpz_dig_t * assumes quo_dig has enough memory (as many digits as num) assumes quo_dig is filled with zeros */ -STATIC void mpn_div(mpz_dig_t *num_dig, size_t *num_len, const mpz_dig_t *den_dig, size_t den_len, mpz_dig_t *quo_dig, size_t *quo_len) { +static void mpn_div(mpz_dig_t *num_dig, size_t *num_len, const mpz_dig_t *den_dig, size_t den_len, mpz_dig_t *quo_dig, size_t *quo_len) { mpz_dig_t *orig_num_dig = num_dig; mpz_dig_t *orig_quo_dig = quo_dig; mpz_dig_t norm_shift = 0; @@ -672,14 +672,14 @@ mpz_t *mpz_from_str(const char *str, size_t len, bool neg, unsigned int base) { } #endif -STATIC void mpz_free(mpz_t *z) { +static void mpz_free(mpz_t *z) { if (z != NULL) { m_del(mpz_dig_t, z->dig, z->alloc); m_del_obj(mpz_t, z); } } -STATIC void mpz_need_dig(mpz_t *z, size_t need) { +static void mpz_need_dig(mpz_t *z, size_t need) { if (need < MIN_ALLOC) { need = MIN_ALLOC; } @@ -693,7 +693,7 @@ STATIC void mpz_need_dig(mpz_t *z, size_t need) { } } -STATIC mpz_t *mpz_clone(const mpz_t *src) { +static mpz_t *mpz_clone(const mpz_t *src) { assert(src->alloc != 0); mpz_t *z = m_new_obj(mpz_t); z->neg = src->neg; diff --git a/py/nativeglue.c b/py/nativeglue.c index 4df7fbcd0729d..3b072ba8c38d5 100644 --- a/py/nativeglue.c +++ b/py/nativeglue.c @@ -29,6 +29,7 @@ #include #include +#include "py/binary.h" #include "py/runtime.h" #include "py/smallint.h" #include "py/nativeglue.h" @@ -141,7 +142,7 @@ mp_obj_t mp_obj_new_slice(mp_obj_t ostart, mp_obj_t ostop, mp_obj_t ostep) { } #endif -STATIC mp_obj_dict_t *mp_native_swap_globals(mp_obj_dict_t *new_globals) { +static mp_obj_dict_t *mp_native_swap_globals(mp_obj_dict_t *new_globals) { if (new_globals == NULL) { // Globals were the originally the same so don't restore them return NULL; @@ -157,20 +158,20 @@ STATIC mp_obj_dict_t *mp_native_swap_globals(mp_obj_dict_t *new_globals) { // wrapper that accepts n_args and n_kw in one argument // (native emitter can only pass at most 3 arguments to a function) -STATIC mp_obj_t mp_native_call_function_n_kw(mp_obj_t fun_in, size_t n_args_kw, const mp_obj_t *args) { +static mp_obj_t mp_native_call_function_n_kw(mp_obj_t fun_in, size_t n_args_kw, const mp_obj_t *args) { return mp_call_function_n_kw(fun_in, n_args_kw & 0xff, (n_args_kw >> 8) & 0xff, args); } // wrapper that makes raise obj and raises it // END_FINALLY opcode requires that we don't raise if o==None -STATIC void mp_native_raise(mp_obj_t o) { +static void mp_native_raise(mp_obj_t o) { if (o != MP_OBJ_NULL && o != mp_const_none) { nlr_raise(mp_make_raise_obj(o)); } } // wrapper that handles iterator buffer -STATIC mp_obj_t mp_native_getiter(mp_obj_t obj, mp_obj_iter_buf_t *iter) { +static mp_obj_t mp_native_getiter(mp_obj_t obj, mp_obj_iter_buf_t *iter) { if (iter == NULL) { return mp_getiter(obj, NULL); } else { @@ -185,7 +186,7 @@ STATIC mp_obj_t mp_native_getiter(mp_obj_t obj, mp_obj_iter_buf_t *iter) { } // wrapper that handles iterator buffer -STATIC mp_obj_t mp_native_iternext(mp_obj_iter_buf_t *iter) { +static mp_obj_t mp_native_iternext(mp_obj_iter_buf_t *iter) { mp_obj_t obj; if (iter->base.type == MP_OBJ_NULL) { obj = iter->buf[0]; @@ -195,7 +196,7 @@ STATIC mp_obj_t mp_native_iternext(mp_obj_iter_buf_t *iter) { return mp_iternext(obj); } -STATIC bool mp_native_yield_from(mp_obj_t gen, mp_obj_t send_value, mp_obj_t *ret_value) { +static bool mp_native_yield_from(mp_obj_t gen, mp_obj_t send_value, mp_obj_t *ret_value) { mp_vm_return_kind_t ret_kind; nlr_buf_t nlr_buf; mp_obj_t throw_value = *ret_value; @@ -233,22 +234,22 @@ STATIC bool mp_native_yield_from(mp_obj_t gen, mp_obj_t send_value, mp_obj_t *re #if !MICROPY_PY_BUILTINS_FLOAT -STATIC mp_obj_t mp_obj_new_float_from_f(float f) { +static mp_obj_t mp_obj_new_float_from_f(float f) { (void)f; mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("float unsupported")); } -STATIC mp_obj_t mp_obj_new_float_from_d(double d) { +static mp_obj_t mp_obj_new_float_from_d(double d) { (void)d; mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("float unsupported")); } -STATIC float mp_obj_get_float_to_f(mp_obj_t o) { +static float mp_obj_get_float_to_f(mp_obj_t o) { (void)o; mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("float unsupported")); } -STATIC double mp_obj_get_float_to_d(mp_obj_t o) { +static double mp_obj_get_float_to_d(mp_obj_t o) { (void)o; mp_raise_msg(&mp_type_RuntimeError, MP_ERROR_TEXT("float unsupported")); } @@ -283,7 +284,7 @@ const mp_fun_table_t mp_fun_table = { mp_obj_set_store, mp_obj_list_append, mp_obj_dict_store, - mp_make_function_from_raw_code, + mp_make_function_from_proto_fun, mp_native_call_function_n_kw, mp_call_method_n_kw, mp_call_method_n_kw_var, @@ -321,7 +322,7 @@ const mp_fun_table_t mp_fun_table = { gc_realloc, mp_printf, mp_vprintf, - // CIRCUITPY-CHANGE + // CIRCUITPY-CHANGE: mp_raise_msg_str instead of mp_raise_msg mp_raise_msg_str, mp_obj_get_type, mp_obj_new_str, @@ -331,10 +332,16 @@ const mp_fun_table_t mp_fun_table = { mp_obj_new_float_from_d, mp_obj_get_float_to_f, mp_obj_get_float_to_d, + mp_load_method_maybe, mp_get_buffer, mp_get_stream_raise, - // CIRCUITPY-CHANGE + // CIRCUITPY-CHANGE: add mp_obj_assert_native_inited mp_obj_assert_native_inited, + mp_arg_parse_all, + mp_arg_parse_all_kw_array, + mp_binary_get_size, + mp_binary_get_val_array, + mp_binary_set_val_array, &mp_plat_print, &mp_type_type, &mp_type_str, @@ -345,6 +352,7 @@ const mp_fun_table_t mp_fun_table = { &mp_type_fun_builtin_2, &mp_type_fun_builtin_3, &mp_type_fun_builtin_var, + &mp_type_Exception, &mp_stream_read_obj, &mp_stream_readinto_obj, &mp_stream_unbuffered_readline_obj, diff --git a/py/nativeglue.h b/py/nativeglue.h index 407fd4c637ae2..00ed9f3f4fcb7 100644 --- a/py/nativeglue.h +++ b/py/nativeglue.h @@ -58,7 +58,7 @@ typedef enum { MP_F_STORE_SET, MP_F_LIST_APPEND, MP_F_STORE_MAP, - MP_F_MAKE_FUNCTION_FROM_RAW_CODE, + MP_F_MAKE_FUNCTION_FROM_PROTO_FUN, MP_F_NATIVE_CALL_FUNCTION_N_KW, MP_F_CALL_METHOD_N_KW, MP_F_CALL_METHOD_N_KW_VAR, @@ -112,7 +112,7 @@ typedef struct _mp_fun_table_t { void (*set_store)(mp_obj_t self_in, mp_obj_t item); mp_obj_t (*list_append)(mp_obj_t self_in, mp_obj_t arg); mp_obj_t (*dict_store)(mp_obj_t self_in, mp_obj_t key, mp_obj_t value); - mp_obj_t (*make_function_from_raw_code)(const mp_raw_code_t *rc, const mp_module_context_t *cm, const mp_obj_t *def_args); + mp_obj_t (*make_function_from_proto_fun)(mp_proto_fun_t proto_fun, const mp_module_context_t *cm, const mp_obj_t *def_args); mp_obj_t (*call_function_n_kw)(mp_obj_t fun_in, size_t n_args_kw, const mp_obj_t *args); mp_obj_t (*call_method_n_kw)(size_t n_args, size_t n_kw, const mp_obj_t *args); mp_obj_t (*call_method_n_kw_var)(bool have_self, size_t n_args_n_kw, const mp_obj_t *args); @@ -145,7 +145,7 @@ typedef struct _mp_fun_table_t { #if defined(__GNUC__) NORETURN // Only certain compilers support no-return attributes in function pointer declarations #endif - // CIRCUITPY-CHANGE + // CIRCUITPY-CHANGE: raise_msg_str instead of raise_msg void (*raise_msg_str)(const mp_obj_type_t *exc_type, const char *msg); const mp_obj_type_t *(*obj_get_type)(mp_const_obj_t o_in); mp_obj_t (*obj_new_str)(const char *data, size_t len); @@ -155,11 +155,19 @@ typedef struct _mp_fun_table_t { mp_obj_t (*obj_new_float_from_d)(double d); float (*obj_get_float_to_f)(mp_obj_t o); double (*obj_get_float_to_d)(mp_obj_t o); + void (*load_method_maybe)(mp_obj_t base, qstr attr, mp_obj_t *dest); bool (*get_buffer)(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags); const mp_stream_p_t *(*get_stream_raise)(mp_obj_t self_in, int flags); // CIRCUITPY-CHANGE void (*assert_native_inited)(mp_obj_t native_object); + void (*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 (*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); + size_t (*binary_get_size)(char struct_type, char val_type, size_t *palign); + mp_obj_t (*binary_get_val_array)(char typecode, void *p, size_t index); + void (*binary_set_val_array)(char typecode, void *p, size_t index, mp_obj_t val_in); const mp_print_t *plat_print; + // The following entries start at index 73 and are referenced by tools-mpy_ld.py, + // see constant MP_FUN_TABLE_MP_TYPE_TYPE_OFFSET. const mp_obj_type_t *type_type; const mp_obj_type_t *type_str; const mp_obj_type_t *type_list; @@ -169,6 +177,7 @@ typedef struct _mp_fun_table_t { const mp_obj_type_t *type_fun_builtin_2; const mp_obj_type_t *type_fun_builtin_3; const mp_obj_type_t *type_fun_builtin_var; + const mp_obj_type_t *type_Exception; const mp_obj_fun_builtin_var_t *stream_read_obj; const mp_obj_fun_builtin_var_t *stream_readinto_obj; const mp_obj_fun_builtin_var_t *stream_unbuffered_readline_obj; diff --git a/py/nlraarch64.c b/py/nlraarch64.c index f6fee5b63abd9..898d9e2a76506 100644 --- a/py/nlraarch64.c +++ b/py/nlraarch64.c @@ -76,7 +76,6 @@ NORETURN void nlr_jump(void *val) { "ret \n" : : "r" (top) - // CIRCUITPY-CHANGE: MicroPython caught up with this change in https://github.com/micropython/micropython/pull/14126 : "memory" ); diff --git a/py/nlrmips.c b/py/nlrmips.c index 22690d19dc802..a60c3abd71487 100644 --- a/py/nlrmips.c +++ b/py/nlrmips.c @@ -26,6 +26,7 @@ #include "py/mpstate.h" +// CIRCUITPY-CHANGE: avoid warning #if defined(MICROPY_NLR_MIPS) && MICROPY_NLR_MIPS __attribute__((used)) unsigned int nlr_push_tail(nlr_buf_t *nlr); @@ -78,7 +79,6 @@ NORETURN void nlr_jump(void *val) { "nop \n" : : "r" (top) - // CIRCUITPY-CHANGE: MicroPython caught up with this change in https://github.com/micropython/micropython/pull/14126 : "memory" ); MP_UNREACHABLE diff --git a/py/nlrpowerpc.c b/py/nlrpowerpc.c index f516383f776ea..ae2f92a078012 100644 --- a/py/nlrpowerpc.c +++ b/py/nlrpowerpc.c @@ -26,6 +26,7 @@ #include "py/mpstate.h" +// CIRCUITPY-CHANGE: avoid warning #if defined(MICROPY_NLR_POWERPC) && MICROPY_NLR_POWERPC #undef nlr_push @@ -114,7 +115,6 @@ NORETURN void nlr_jump(void *val) { "blr ;" : : "r" (&top->regs) - // CIRCUITPY-CHANGE: MicroPython caught up with this change in https://github.com/micropython/micropython/pull/14126 : "memory" ); diff --git a/py/nlrthumb.c b/py/nlrthumb.c index 06a713a213b35..de4d69eabd10f 100644 --- a/py/nlrthumb.c +++ b/py/nlrthumb.c @@ -40,6 +40,14 @@ // CIRCUITPY-CHANGE: added returns_twice __attribute__((naked, returns_twice)) unsigned int nlr_push(nlr_buf_t *nlr) { + // If you get a linker error here, indicating that a relocation doesn't + // fit, try the following (in that order): + // + // 1. Ensure that nlr.o nlrthumb.o are linked closely together, i.e. + // there aren't too many other files between them in the linker list + // (PY_CORE_O_BASENAME in py/py.mk) + // 2. Set -DMICROPY_NLR_THUMB_USE_LONG_JUMP=1 during the build + // __asm volatile ( "str r4, [r0, #12] \n" // store r4 into nlr_buf "str r5, [r0, #16] \n" // store r5 into nlr_buf @@ -73,7 +81,7 @@ __attribute__((naked, returns_twice)) unsigned int nlr_push(nlr_buf_t *nlr) { "str lr, [r0, #8] \n" // store lr into nlr_buf #endif - #if !defined(__thumb2__) + #if MICROPY_NLR_THUMB_USE_LONG_JUMP "ldr r1, nlr_push_tail_var \n" "bx r1 \n" // do the rest in C ".align 2 \n" @@ -134,7 +142,6 @@ NORETURN void nlr_jump(void *val) { "bx lr \n" // return : // output operands : "r" (top) // input operands - // CIRCUITPY-CHANGE: MicroPython makes this change in https://github.com/micropython/micropython/pull/14126 (later than v1.22) : "memory" // clobbered registers ); diff --git a/py/nlrx64.c b/py/nlrx64.c index 4db637cbe8fb7..63586a2199fbd 100644 --- a/py/nlrx64.c +++ b/py/nlrx64.c @@ -124,7 +124,6 @@ NORETURN void nlr_jump(void *val) { "ret \n" // return : // output operands : "r" (top) // input operands - // CIRCUITPY-CHANGE: MicroPython caught up with this change in https://github.com/micropython/micropython/pull/14126 : "memory" // clobbered registers ); diff --git a/py/nlrx86.c b/py/nlrx86.c index 83b2f0f3ae03e..a2ce8424f9c56 100644 --- a/py/nlrx86.c +++ b/py/nlrx86.c @@ -97,7 +97,6 @@ NORETURN void nlr_jump(void *val) { "ret \n" // return : // output operands : "r" (top) // input operands - // CIRCUITPY-CHANGE: MicroPython caught up with this change in https://github.com/micropython/micropython/pull/14126 : "memory" // clobbered registers ); diff --git a/py/nlrxtensa.c b/py/nlrxtensa.c index 01828ae5f46c8..62e799dbdca22 100644 --- a/py/nlrxtensa.c +++ b/py/nlrxtensa.c @@ -75,7 +75,6 @@ NORETURN void nlr_jump(void *val) { "ret.n \n" // return : // output operands : "r" (top) // input operands - // CIRCUITPY-CHANGE: MicroPython caught up with this change in https://github.com/micropython/micropython/pull/14126 : "memory" // clobbered registers ); diff --git a/py/obj.c b/py/obj.c index 94544cc2ea2c4..afbc62a65fcee 100644 --- a/py/obj.c +++ b/py/obj.c @@ -51,6 +51,15 @@ MP_NOINLINE void *mp_obj_malloc_helper(size_t num_bytes, const mp_obj_type_t *ty return base; } +#if MICROPY_ENABLE_FINALISER +// Allocates an object and also sets type, for mp_obj_malloc{,_var}_with_finaliser macros. +MP_NOINLINE void *mp_obj_malloc_with_finaliser_helper(size_t num_bytes, const mp_obj_type_t *type) { + mp_obj_base_t *base = (mp_obj_base_t *)m_malloc_with_finaliser(num_bytes); + base->type = type; + return base; +} +#endif + const mp_obj_type_t *MICROPY_WRAP_MP_OBJ_GET_TYPE(mp_obj_get_type)(mp_const_obj_t o_in) { #if MICROPY_OBJ_IMMEDIATE_OBJS && MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A @@ -677,7 +686,7 @@ typedef struct { mp_int_t cur; } mp_obj_generic_subscript_it_t; -STATIC mp_obj_t generic_subscript_it_iternext(mp_obj_t self_in) { +static mp_obj_t generic_subscript_it_iternext(mp_obj_t self_in) { mp_obj_generic_subscript_it_t *self = MP_OBJ_TO_PTR(self_in); const mp_obj_type_t *type = mp_obj_get_type(self->obj); mp_obj_t current_length = MP_OBJ_TYPE_GET_SLOT(type, unary_op)(MP_UNARY_OP_LEN, self->obj); diff --git a/py/obj.h b/py/obj.h index 2d1637dafa29b..70fdeeebde4d6 100644 --- a/py/obj.h +++ b/py/obj.h @@ -785,20 +785,20 @@ typedef struct _mp_obj_full_type_t { // Do not use these directly, instead use MP_DEFINE_CONST_OBJ_TYPE. // Generated with: // for i in range(13): -// print(f"#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_{i}(_struct_type, _typename, _name, _flags{''.join(f', f{j+1}, v{j+1}' for j in range(i))}) const _struct_type _typename = {{ .base = {{ &mp_type_type }}, .name = _name, .flags = _flags{''.join(f', .slot_index_##f{j+1} = {j+1}' for j in range(i))}{', .slots = { ' + ''.join(f'v{j+1}, ' for j in range(i)) + '}' if i else '' } }}") -#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_0(_struct_type, _typename, _name, _flags) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags } -#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_1(_struct_type, _typename, _name, _flags, f1, v1) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slots = { v1, } } -#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_2(_struct_type, _typename, _name, _flags, f1, v1, f2, v2) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slots = { v1, v2, } } -#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_3(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slots = { v1, v2, v3, } } -#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_4(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slots = { v1, v2, v3, v4, } } -#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_5(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slots = { v1, v2, v3, v4, v5, } } -#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_6(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slots = { v1, v2, v3, v4, v5, v6, } } -#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_7(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slots = { v1, v2, v3, v4, v5, v6, v7, } } -#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_8(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, } } -#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_9(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, } } -#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_10(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, } } -#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_11(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10, f11, v11) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slot_index_##f11 = 11, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, } } -#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_12(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10, f11, v11, f12, v12) const _struct_type _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slot_index_##f11 = 11, .slot_index_##f12 = 12, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, } } +// print(f"#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_{i}(_struct_type, _typename, _name, _flags{''.join(f', f{j+1}, v{j+1}' for j in range(i))}) const _struct_type _typename = {{ .base = {{ &mp_type_type }}, .flags = _flags, .name = _name{''.join(f', .slot_index_##f{j+1} = {j+1}' for j in range(i))}{', .slots = { ' + ''.join(f'v{j+1}, ' for j in range(i)) + '}' if i else '' } }}") +#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_0(_struct_type, _typename, _name, _flags) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name } +#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_1(_struct_type, _typename, _name, _flags, f1, v1) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slots = { v1, } } +#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_2(_struct_type, _typename, _name, _flags, f1, v1, f2, v2) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slots = { v1, v2, } } +#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_3(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slots = { v1, v2, v3, } } +#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_4(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slots = { v1, v2, v3, v4, } } +#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_5(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slots = { v1, v2, v3, v4, v5, } } +#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_6(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slots = { v1, v2, v3, v4, v5, v6, } } +#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_7(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slots = { v1, v2, v3, v4, v5, v6, v7, } } +#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_8(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, } } +#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_9(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, } } +#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_10(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, } } +#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_11(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10, f11, v11) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slot_index_##f11 = 11, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, } } +#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_12(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10, f11, v11, f12, v12) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slot_index_##f11 = 11, .slot_index_##f12 = 12, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, } } // Because the mp_obj_type_t instances are in (zero-initialised) ROM, we take // slot_index_foo=0 to mean that the slot is unset. This also simplifies checking @@ -873,6 +873,9 @@ extern const mp_obj_type_t mp_type_fun_builtin_2; extern const mp_obj_type_t mp_type_fun_builtin_3; extern const mp_obj_type_t mp_type_fun_builtin_var; extern const mp_obj_type_t mp_type_fun_bc; +extern const mp_obj_type_t mp_type_fun_native; +extern const mp_obj_type_t mp_type_fun_viper; +extern const mp_obj_type_t mp_type_fun_asm; extern const mp_obj_type_t mp_type_module; extern const mp_obj_type_t mp_type_staticmethod; extern const mp_obj_type_t mp_type_classmethod; @@ -974,9 +977,19 @@ extern const struct _mp_obj_exception_t mp_const_GeneratorExit_obj; // Helper versions of m_new_obj when you need to immediately set base.type. // Implementing this as a call rather than inline saves 8 bytes per usage. #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type)) -#define mp_obj_malloc_var(struct_type, var_type, var_num, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type) + sizeof(var_type) * (var_num), obj_type)) +#define mp_obj_malloc_var(struct_type, var_field, var_type, var_num, obj_type) ((struct_type *)mp_obj_malloc_helper(offsetof(struct_type, var_field) + sizeof(var_type) * (var_num), obj_type)) void *mp_obj_malloc_helper(size_t num_bytes, const mp_obj_type_t *type); +// Object allocation macros for allocating objects that have a finaliser. +#if MICROPY_ENABLE_FINALISER +#define mp_obj_malloc_with_finaliser(struct_type, obj_type) ((struct_type *)mp_obj_malloc_with_finaliser_helper(sizeof(struct_type), obj_type)) +#define mp_obj_malloc_var_with_finaliser(struct_type, var_type, var_num, obj_type) ((struct_type *)mp_obj_malloc_with_finaliser_helper(sizeof(struct_type) + sizeof(var_type) * (var_num), obj_type)) +void *mp_obj_malloc_with_finaliser_helper(size_t num_bytes, const mp_obj_type_t *type); +#else +#define mp_obj_malloc_with_finaliser(struct_type, obj_type) mp_obj_malloc(struct_type, obj_type) +#define mp_obj_malloc_var_with_finaliser(struct_type, var_type, var_num, obj_type) mp_obj_malloc_var(struct_type, var_type, var_num, obj_type) +#endif + // These macros are derived from more primitive ones and are used to // check for more specific object types. // Note: these are kept as macros because inline functions sometimes use much diff --git a/py/objarray.c b/py/objarray.c index bf12b7e5ef6f5..3ab982184f9bb 100644 --- a/py/objarray.c +++ b/py/objarray.c @@ -61,13 +61,13 @@ // so not defined to catch errors #endif -STATIC mp_obj_t array_iterator_new(mp_obj_t array_in, mp_obj_iter_buf_t *iter_buf); -STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg); -STATIC mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in); -STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags); +static mp_obj_t array_iterator_new(mp_obj_t array_in, mp_obj_iter_buf_t *iter_buf); +static mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg); +static mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in); +static mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags); // CIRCUITPY-CHANGE #if MICROPY_CPYTHON_COMPAT -STATIC mp_obj_t array_decode(size_t n_args, const mp_obj_t *args); +static mp_obj_t array_decode(size_t n_args, const mp_obj_t *args); #endif @@ -75,7 +75,7 @@ STATIC mp_obj_t array_decode(size_t n_args, const mp_obj_t *args); // array #if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY -STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_array_t *o = MP_OBJ_TO_PTR(o_in); if (o->typecode == BYTEARRAY_TYPECODE) { @@ -99,7 +99,7 @@ STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t #endif #if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY -STATIC mp_obj_array_t *array_new(char typecode, size_t n) { +static mp_obj_array_t *array_new(char typecode, size_t n) { // CIRCUITPY-CHANGE if (typecode == 'x') { mp_raise_ValueError(MP_ERROR_TEXT("bad typecode")); @@ -122,7 +122,7 @@ STATIC mp_obj_array_t *array_new(char typecode, size_t n) { #endif #if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY -STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) { +static mp_obj_t array_construct(char typecode, mp_obj_t initializer) { // bytearrays can be raw-initialised from anything with the buffer protocol // other arrays can only be raw-initialised from bytes and bytearray objects mp_buffer_info_t bufinfo; @@ -171,7 +171,7 @@ 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, size_t n_kw, const mp_obj_t *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, n_kw, 1, 2, false); @@ -189,7 +189,7 @@ STATIC mp_obj_t array_make_new(const mp_obj_type_t *type_in, size_t n_args, size #endif #if MICROPY_PY_BUILTINS_BYTEARRAY -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) { +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; // Can take 2nd/3rd arg if constructs from str mp_arg_check_num(n_args, n_kw, 0, 3, false); @@ -198,7 +198,7 @@ STATIC mp_obj_t bytearray_make_new(const mp_obj_type_t *type_in, size_t n_args, // no args: construct an empty bytearray return MP_OBJ_FROM_PTR(array_new(BYTEARRAY_TYPECODE, 0)); } else if (mp_obj_is_int(args[0])) { - // CIRCUITPY-CHANGE: error checks this + // CIRCUITPY-CHANGE: error check this if (n_args > 1) { mp_raise_TypeError(MP_ERROR_TEXT("wrong number of arguments")); } @@ -230,7 +230,7 @@ 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, size_t n_kw, const mp_obj_t *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 @@ -263,7 +263,7 @@ STATIC mp_obj_t memoryview_make_new(const mp_obj_type_t *type_in, size_t n_args, // CIRCUITPY-CHANGE: adds cast #if MICROPY_CPYTHON_COMPAT -STATIC mp_obj_t memoryview_cast(const mp_obj_t self_in, const mp_obj_t typecode_in) { +static mp_obj_t memoryview_cast(const mp_obj_t self_in, const mp_obj_t typecode_in) { mp_obj_array_t *self = MP_OBJ_TO_PTR(self_in); const char *typecode = mp_obj_str_get_str(typecode_in); size_t new_element_size = mp_binary_get_size('@', typecode[0], NULL); @@ -281,11 +281,11 @@ STATIC mp_obj_t memoryview_cast(const mp_obj_t self_in, const mp_obj_t typecode_ } return MP_OBJ_FROM_PTR(result); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(memoryview_cast_obj, memoryview_cast); +static MP_DEFINE_CONST_FUN_OBJ_2(memoryview_cast_obj, memoryview_cast); #endif #if MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE -STATIC void memoryview_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void memoryview_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { return; } @@ -293,7 +293,7 @@ STATIC void memoryview_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { mp_obj_array_t *self = MP_OBJ_TO_PTR(self_in); dest[0] = MP_OBJ_NEW_SMALL_INT(mp_binary_get_size('@', self->typecode & TYPECODE_MASK, NULL)); } - // CIRCUITPY-CHANGE + // CIRCUITPY-CHANGE: prevent warning #if MICROPY_PY_BUILTINS_BYTES_HEX || MICROPY_CPYTHON_COMPAT else { // Need to forward to locals dict. @@ -305,7 +305,7 @@ STATIC void memoryview_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { #endif -STATIC mp_obj_t array_unary_op(mp_unary_op_t op, mp_obj_t o_in) { +static mp_obj_t array_unary_op(mp_unary_op_t op, mp_obj_t o_in) { mp_obj_array_t *o = MP_OBJ_TO_PTR(o_in); switch (op) { case MP_UNARY_OP_BOOL: @@ -317,7 +317,7 @@ STATIC mp_obj_t array_unary_op(mp_unary_op_t op, mp_obj_t o_in) { } } -STATIC int typecode_for_comparison(int typecode, bool *is_unsigned) { +static int typecode_for_comparison(int typecode, bool *is_unsigned) { if (typecode == BYTEARRAY_TYPECODE) { typecode = 'B'; } @@ -328,7 +328,7 @@ STATIC int typecode_for_comparison(int typecode, bool *is_unsigned) { return typecode; } -STATIC mp_obj_t array_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t array_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { mp_obj_array_t *lhs = MP_OBJ_TO_PTR(lhs_in); switch (op) { // CIRCUITPY-CHANGE: does multiply @@ -458,7 +458,7 @@ STATIC mp_obj_t array_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs } #if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY -STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) { // self is not a memoryview, so we don't need to use (& TYPECODE_MASK) assert((MICROPY_PY_BUILTINS_BYTEARRAY && mp_obj_is_type(self_in, &mp_type_bytearray)) || (MICROPY_PY_ARRAY && mp_obj_is_type(self_in, &mp_type_array))); @@ -479,7 +479,7 @@ STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) { } MP_DEFINE_CONST_FUN_OBJ_2(mp_obj_array_append_obj, array_append); -STATIC mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in) { +static mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in) { // self is not a memoryview, so we don't need to use (& TYPECODE_MASK) assert((MICROPY_PY_BUILTINS_BYTEARRAY && mp_obj_is_type(self_in, &mp_type_bytearray)) || (MICROPY_PY_ARRAY && mp_obj_is_type(self_in, &mp_type_array))); @@ -521,7 +521,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(mp_obj_array_extend_obj, array_extend); // CIRCUITPY-CHANGE: buffer_finder used belo #if MICROPY_PY_BUILTINS_BYTEARRAY && MICROPY_CPYTHON_COMPAT -STATIC mp_obj_t buffer_finder(size_t n_args, const mp_obj_t *args, int direction, bool is_index) { +static mp_obj_t buffer_finder(size_t n_args, const mp_obj_t *args, int direction, bool is_index) { mp_check_self(mp_obj_is_type(args[0], &mp_type_bytearray)); const mp_obj_type_t *self_type = mp_obj_get_type(args[0]); @@ -560,28 +560,28 @@ STATIC mp_obj_t buffer_finder(size_t n_args, const mp_obj_t *args, int direction } // CIRCUITPY-CHANGE: provides find, rfind, index -STATIC mp_obj_t buffer_find(size_t n_args, const mp_obj_t *args) { +static mp_obj_t buffer_find(size_t n_args, const mp_obj_t *args) { return buffer_finder(n_args, args, 1, false); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(buffer_find_obj, 2, 4, buffer_find); -STATIC mp_obj_t buffer_rfind(size_t n_args, const mp_obj_t *args) { +static mp_obj_t buffer_rfind(size_t n_args, const mp_obj_t *args) { return buffer_finder(n_args, args, -1, false); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(buffer_rfind_obj, 2, 4, buffer_rfind); -STATIC mp_obj_t buffer_index(size_t n_args, const mp_obj_t *args) { +static mp_obj_t buffer_index(size_t n_args, const mp_obj_t *args) { return buffer_finder(n_args, args, 1, true); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(buffer_index_obj, 2, 4, buffer_index); -STATIC mp_obj_t buffer_rindex(size_t n_args, const mp_obj_t *args) { +static mp_obj_t buffer_rindex(size_t n_args, const mp_obj_t *args) { return buffer_finder(n_args, args, -1, true); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(buffer_rindex_obj, 2, 4, buffer_rindex); #endif -STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) { +static mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) { if (value == MP_OBJ_NULL) { // delete item // TODO implement @@ -600,7 +600,8 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value #if MICROPY_PY_ARRAY_SLICE_ASSIGN // Assign size_t src_len; - void *src_items; + uint8_t *src_items; + size_t src_offs = 0; size_t item_sz = mp_binary_get_size('@', o->typecode & TYPECODE_MASK, NULL); if (mp_obj_is_obj(value) && MP_OBJ_TYPE_GET_SLOT_OR_NULL(((mp_obj_base_t *)MP_OBJ_TO_PTR(value))->type, subscr) == array_subscr) { // value is array, bytearray or memoryview @@ -613,7 +614,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value src_items = src_slice->items; #if MICROPY_PY_BUILTINS_MEMORYVIEW if (mp_obj_is_type(value, &mp_type_memoryview)) { - src_items = (uint8_t *)src_items + (src_slice->memview_offset * item_sz); + src_offs = src_slice->memview_offset * item_sz; } #endif } else if (mp_obj_is_type(value, &mp_type_bytes)) { @@ -648,13 +649,17 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value // TODO: alloc policy; at the moment we go conservative o->items = m_renew(byte, o->items, (o->len + o->free) * item_sz, (o->len + len_adj) * item_sz); o->free = len_adj; + // m_renew may have moved o->items + if (src_items == dest_items) { + src_items = o->items; + } dest_items = o->items; } mp_seq_replace_slice_grow_inplace(dest_items, o->len, - slice.start, slice.stop, src_items, src_len, len_adj, item_sz); + slice.start, slice.stop, src_items + src_offs, src_len, len_adj, item_sz); } else { mp_seq_replace_slice_no_grow(dest_items, o->len, - slice.start, slice.stop, src_items, src_len, item_sz); + slice.start, slice.stop, src_items + src_offs, src_len, item_sz); // CIRCUITPY-CHANGE #if MICROPY_NONSTANDARD_TYPECODES // Clear "freed" elements at the end of list @@ -715,7 +720,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value } } -STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { +static mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { mp_obj_array_t *o = MP_OBJ_TO_PTR(o_in); size_t sz = mp_binary_get_size('@', o->typecode & TYPECODE_MASK, NULL); bufinfo->buf = o->items; @@ -738,7 +743,7 @@ STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_ui // CIRCUITPY-CHANGE #if MICROPY_CPYTHON_COMPAT && MICROPY_PY_BUILTINS_BYTEARRAY // Directly lifted from objstr.c -STATIC mp_obj_t array_decode(size_t n_args, const mp_obj_t *args) { +static mp_obj_t array_decode(size_t n_args, const mp_obj_t *args) { mp_obj_t new_args[2]; if (n_args == 1) { new_args[0] = args[0]; @@ -753,7 +758,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(array_decode_obj, 1, 3, array_decode); #if MICROPY_PY_BUILTINS_BYTEARRAY -STATIC const mp_rom_map_elem_t bytearray_locals_dict_table[] = { +static const mp_rom_map_elem_t bytearray_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_append), MP_ROM_PTR(&mp_obj_array_append_obj) }, { MP_ROM_QSTR(MP_QSTR_extend), MP_ROM_PTR(&mp_obj_array_extend_obj) }, @@ -813,7 +818,7 @@ MP_DEFINE_CONST_OBJ_TYPE( // CIRCUITPY-CHANGE: provides cast #if MICROPY_CPYTHON_COMPAT // CIRCUITPY-CHANGE: provides cast -STATIC const mp_rom_map_elem_t memoryview_locals_dict_table[] = { +static const mp_rom_map_elem_t memoryview_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_cast), MP_ROM_PTR(&memoryview_cast_obj) }, #if MICROPY_PY_BUILTINS_BYTES_HEX { MP_ROM_QSTR(MP_QSTR_hex), MP_ROM_PTR(&mp_obj_bytes_hex_as_str_obj) }, @@ -883,7 +888,7 @@ typedef struct _mp_obj_array_it_t { size_t cur; } mp_obj_array_it_t; -STATIC mp_obj_t array_it_iternext(mp_obj_t self_in) { +static mp_obj_t array_it_iternext(mp_obj_t self_in) { mp_obj_array_it_t *self = MP_OBJ_TO_PTR(self_in); if (self->cur < self->array->len) { return mp_binary_get_val_array(self->array->typecode & TYPECODE_MASK, self->array->items, self->offset + self->cur++); @@ -892,14 +897,14 @@ STATIC mp_obj_t array_it_iternext(mp_obj_t self_in) { } } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_array_it, MP_QSTR_iterator, MP_TYPE_FLAG_ITER_IS_ITERNEXT, iter, array_it_iternext ); -STATIC mp_obj_t array_iterator_new(mp_obj_t array_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t array_iterator_new(mp_obj_t array_in, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(mp_obj_array_t) <= sizeof(mp_obj_iter_buf_t)); mp_obj_array_t *array = MP_OBJ_TO_PTR(array_in); mp_obj_array_it_t *o = (mp_obj_array_it_t *)iter_buf; diff --git a/py/objattrtuple.c b/py/objattrtuple.c index fbe04bedb877a..1280e3308938e 100644 --- a/py/objattrtuple.c +++ b/py/objattrtuple.c @@ -30,7 +30,7 @@ // this helper function is used by collections.namedtuple #if !MICROPY_PY_COLLECTIONS -STATIC +static #endif void mp_obj_attrtuple_print_helper(const mp_print_t *print, const qstr *fields, mp_obj_tuple_t *o) { mp_print_str(print, "("); @@ -48,14 +48,14 @@ void mp_obj_attrtuple_print_helper(const mp_print_t *print, const qstr *fields, #if MICROPY_PY_ATTRTUPLE -STATIC void mp_obj_attrtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void mp_obj_attrtuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_tuple_t *o = MP_OBJ_TO_PTR(o_in); const qstr *fields = (const qstr *)MP_OBJ_TO_PTR(o->items[o->len]); mp_obj_attrtuple_print_helper(print, fields, o); } -STATIC void mp_obj_attrtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void mp_obj_attrtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] == MP_OBJ_NULL) { // load attribute mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in); @@ -71,7 +71,7 @@ STATIC void mp_obj_attrtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } mp_obj_t mp_obj_new_attrtuple(const qstr *fields, size_t n, const mp_obj_t *items) { - mp_obj_tuple_t *o = mp_obj_malloc_var(mp_obj_tuple_t, mp_obj_t, n + 1, &mp_type_attrtuple); + mp_obj_tuple_t *o = mp_obj_malloc_var(mp_obj_tuple_t, items, mp_obj_t, n + 1, &mp_type_attrtuple); o->len = n; for (size_t i = 0; i < n; i++) { o->items[i] = items[i]; diff --git a/py/objbool.c b/py/objbool.c index 96f0e60dd1765..5b3e3660e9510 100644 --- a/py/objbool.c +++ b/py/objbool.c @@ -43,7 +43,7 @@ typedef struct _mp_obj_bool_t { #endif -STATIC void bool_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void bool_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { bool value = BOOL_VALUE(self_in); if (MICROPY_PY_JSON && kind == PRINT_JSON) { if (value) { @@ -60,7 +60,7 @@ 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, size_t n_kw, const mp_obj_t *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, n_kw, 0, 1, false); @@ -71,7 +71,7 @@ STATIC mp_obj_t bool_make_new(const mp_obj_type_t *type_in, size_t n_args, size_ } } -STATIC mp_obj_t bool_unary_op(mp_unary_op_t op, mp_obj_t o_in) { +static mp_obj_t bool_unary_op(mp_unary_op_t op, mp_obj_t o_in) { if (op == MP_UNARY_OP_LEN) { return MP_OBJ_NULL; } @@ -79,7 +79,7 @@ STATIC mp_obj_t bool_unary_op(mp_unary_op_t op, mp_obj_t o_in) { return mp_unary_op(op, MP_OBJ_NEW_SMALL_INT(value)); } -STATIC mp_obj_t bool_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t bool_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { bool value = BOOL_VALUE(lhs_in); return mp_binary_op(op, MP_OBJ_NEW_SMALL_INT(value), rhs_in); } diff --git a/py/objboundmeth.c b/py/objboundmeth.c index b0be810c5c15e..e3503ff154a65 100644 --- a/py/objboundmeth.c +++ b/py/objboundmeth.c @@ -36,7 +36,7 @@ typedef struct _mp_obj_bound_meth_t { } mp_obj_bound_meth_t; #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED -STATIC void bound_meth_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void bound_meth_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_bound_meth_t *o = MP_OBJ_TO_PTR(o_in); mp_printf(print, "meth, self->self, n_args, n_kw, args); } -STATIC mp_obj_t bound_meth_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t bound_meth_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_bound_meth_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { case MP_UNARY_OP_HASH: @@ -93,7 +93,7 @@ STATIC mp_obj_t bound_meth_unary_op(mp_unary_op_t op, mp_obj_t self_in) { } } -STATIC mp_obj_t bound_meth_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t bound_meth_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { // The MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE flag is clear for this type, so if this // function is called with MP_BINARY_OP_EQUAL then lhs_in and rhs_in must have the // same type, which is mp_type_bound_meth. @@ -106,7 +106,7 @@ STATIC mp_obj_t bound_meth_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_ } #if MICROPY_PY_FUNCTION_ATTRS -STATIC void bound_meth_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void bound_meth_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { // not load attribute return; diff --git a/py/objcell.c b/py/objcell.c index 0a74e29d2064a..95966c7917cb7 100644 --- a/py/objcell.c +++ b/py/objcell.c @@ -27,7 +27,7 @@ #include "py/obj.h" #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED -STATIC void cell_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void cell_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_cell_t *o = MP_OBJ_TO_PTR(o_in); mp_printf(print, "obj); @@ -46,7 +46,7 @@ STATIC void cell_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t k #define CELL_TYPE_PRINT #endif -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( // cell representation is just value in < > mp_type_cell, MP_QSTR_, MP_TYPE_FLAG_NONE CELL_TYPE_PRINT diff --git a/py/objclosure.c b/py/objclosure.c index 6059d18100e03..3ba507b959382 100644 --- a/py/objclosure.c +++ b/py/objclosure.c @@ -36,7 +36,7 @@ typedef struct _mp_obj_closure_t { mp_obj_t closed[]; } mp_obj_closure_t; -STATIC mp_obj_t closure_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t closure_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_obj_closure_t *self = MP_OBJ_TO_PTR(self_in); // need to concatenate closed-over-vars and args @@ -60,7 +60,7 @@ STATIC mp_obj_t closure_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const } #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED -STATIC void closure_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void closure_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_closure_t *o = MP_OBJ_TO_PTR(o_in); mp_print_str(print, "fun mp_obj_closure_t *o = MP_OBJ_TO_PTR(self_in); mp_load_method_maybe(o->fun, attr, dest); @@ -105,7 +105,7 @@ MP_DEFINE_CONST_OBJ_TYPE( ); mp_obj_t mp_obj_new_closure(mp_obj_t fun, size_t n_closed_over, const mp_obj_t *closed) { - mp_obj_closure_t *o = mp_obj_malloc_var(mp_obj_closure_t, mp_obj_t, n_closed_over, &mp_type_closure); + mp_obj_closure_t *o = mp_obj_malloc_var(mp_obj_closure_t, closed, mp_obj_t, n_closed_over, &mp_type_closure); o->fun = fun; o->n_closed = n_closed_over; memcpy(o->closed, closed, n_closed_over * sizeof(mp_obj_t)); diff --git a/py/objcomplex.c b/py/objcomplex.c index c69339c6ccac2..d7287efdc13dd 100644 --- a/py/objcomplex.c +++ b/py/objcomplex.c @@ -46,7 +46,7 @@ typedef struct _mp_obj_complex_t { mp_float_t imag; } mp_obj_complex_t; -STATIC void complex_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void complex_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_complex_t *o = MP_OBJ_TO_PTR(o_in); #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT @@ -74,7 +74,7 @@ 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, size_t n_kw, const mp_obj_t *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, n_kw, 0, 2, false); @@ -119,7 +119,7 @@ STATIC mp_obj_t complex_make_new(const mp_obj_type_t *type_in, size_t n_args, si } } -STATIC mp_obj_t complex_unary_op(mp_unary_op_t op, mp_obj_t o_in) { +static mp_obj_t complex_unary_op(mp_unary_op_t op, mp_obj_t o_in) { mp_obj_complex_t *o = MP_OBJ_TO_PTR(o_in); switch (op) { case MP_UNARY_OP_BOOL: @@ -137,12 +137,12 @@ STATIC mp_obj_t complex_unary_op(mp_unary_op_t op, mp_obj_t o_in) { } } -STATIC mp_obj_t complex_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t complex_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { mp_obj_complex_t *lhs = MP_OBJ_TO_PTR(lhs_in); return mp_obj_complex_binary_op(op, lhs->real, lhs->imag, rhs_in); } -STATIC void complex_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void complex_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { // not load attribute return; diff --git a/py/objdeque.c b/py/objdeque.c index 5f22bb33f96e4..583537017fdb2 100644 --- a/py/objdeque.c +++ b/py/objdeque.c @@ -30,9 +30,6 @@ #if MICROPY_PY_COLLECTIONS_DEQUE -// CIRCUITPY-CHANGE: Upcoming https://github.com/micropython/micropython/pull/10724 -// will incporate some or all of the changes here. - typedef struct _mp_obj_deque_t { mp_obj_base_t base; size_t alloc; @@ -43,7 +40,6 @@ typedef struct _mp_obj_deque_t { #define FLAG_CHECK_OVERFLOW 1 } mp_obj_deque_t; -// CIRCUITPY-CHANGE: add operations static mp_obj_t mp_obj_deque_append(mp_obj_t self_in, mp_obj_t arg); static mp_obj_t mp_obj_deque_extend(mp_obj_t self_in, mp_obj_t arg_in); #if MICROPY_PY_COLLECTIONS_DEQUE_ITER @@ -68,7 +64,6 @@ static mp_obj_t deque_make_new(const mp_obj_type_t *type, size_t n_args, size_t o->flags = mp_obj_get_int(args[2]); } - // CIRCUITPY-CHANGE: allow non-empty initialization mp_obj_deque_extend(MP_OBJ_FROM_PTR(o), args[0]); return MP_OBJ_FROM_PTR(o); diff --git a/py/objdict.c b/py/objdict.c index 18862decb7f6e..96a659d36e048 100644 --- a/py/objdict.c +++ b/py/objdict.c @@ -52,7 +52,7 @@ const mp_obj_dict_t mp_const_empty_dict_obj = { // CIRCUITPY-CHANGE: Native methods are passed the subclass instance so they can // refer to subclass members. Dict only cares about the native struct so this // function gets it. -STATIC mp_obj_dict_t *native_dict(mp_obj_t self_in) { +static mp_obj_dict_t *native_dict(mp_obj_t self_in) { // Check for OrderedDict first because it is marked as a subclass of dict. However, it doesn't // store its state in subobj like python types to native types do. mp_obj_t native_instance = MP_OBJ_NULL; @@ -65,12 +65,12 @@ STATIC mp_obj_dict_t *native_dict(mp_obj_t self_in) { return MP_OBJ_TO_PTR(native_instance); } -STATIC mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs); +static mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs); // This is a helper function to iterate through a dictionary. The state of // the iteration is held in *cur and should be initialised with zero for the // first call. Will return NULL when no more elements are available. -STATIC mp_map_elem_t *dict_iter_next(mp_obj_dict_t *dict, size_t *cur) { +static mp_map_elem_t *dict_iter_next(mp_obj_dict_t *dict, size_t *cur) { size_t max = dict->map.alloc; mp_map_t *map = &dict->map; @@ -86,7 +86,7 @@ STATIC mp_map_elem_t *dict_iter_next(mp_obj_dict_t *dict, size_t *cur) { return NULL; } -STATIC void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { // CIRCUITPY-CHANGE mp_obj_dict_t *self = native_dict(self_in); bool first = true; @@ -131,7 +131,7 @@ STATIC void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_ // CIRCUITPY-CHANGE // This is a helper function to initialize an empty, but typed dictionary with // a given number of slots. -STATIC mp_obj_t dict_new_typed(const mp_obj_type_t *type, const size_t n) { +static mp_obj_t dict_new_typed(const mp_obj_type_t *type, const size_t n) { mp_obj_t dict_out = mp_obj_new_dict(n); mp_obj_dict_t *dict = MP_OBJ_TO_PTR(dict_out); dict->base.type = type; @@ -161,7 +161,7 @@ mp_obj_t mp_obj_dict_make_new(const mp_obj_type_t *type, size_t n_args, size_t n return dict_out; } -STATIC mp_obj_t dict_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t dict_unary_op(mp_unary_op_t op, mp_obj_t self_in) { // CIRCUITPY-CHANGE mp_obj_dict_t *self = native_dict(self_in); switch (op) { @@ -180,7 +180,7 @@ STATIC mp_obj_t dict_unary_op(mp_unary_op_t op, mp_obj_t self_in) { } } -STATIC mp_obj_t dict_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t dict_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { // CIRCUITPY-CHANGE mp_obj_dict_t *o = native_dict(lhs_in); switch (op) { @@ -253,7 +253,7 @@ mp_obj_t mp_obj_dict_get(mp_obj_t self_in, mp_obj_t index) { } } -STATIC mp_obj_t dict_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { +static mp_obj_t dict_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { if (value == MP_OBJ_NULL) { // delete mp_obj_dict_delete(self_in, index); @@ -278,14 +278,14 @@ STATIC mp_obj_t dict_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { /******************************************************************************/ /* dict methods */ -// CIRCUITPY-CHANGE -STATIC void PLACE_IN_ITCM(mp_ensure_not_fixed)(const mp_obj_dict_t * dict) { +// CIRCUITPY-CHANGE: PLACE_IN_ITCM +static void PLACE_IN_ITCM(mp_ensure_not_fixed)(const mp_obj_dict_t * dict) { if (dict->map.is_fixed) { mp_raise_TypeError(NULL); } } -STATIC mp_obj_t dict_clear(mp_obj_t self_in) { +static mp_obj_t dict_clear(mp_obj_t self_in) { mp_check_self(mp_obj_is_dict_or_ordereddict(self_in)); // CIRCUITPY-CHANGE mp_obj_dict_t *self = native_dict(self_in); @@ -295,7 +295,7 @@ STATIC mp_obj_t dict_clear(mp_obj_t self_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_clear_obj, dict_clear); +static MP_DEFINE_CONST_FUN_OBJ_1(dict_clear_obj, dict_clear); mp_obj_t mp_obj_dict_copy(mp_obj_t self_in) { mp_check_self(mp_obj_is_dict_or_ordereddict(self_in)); @@ -312,11 +312,11 @@ mp_obj_t mp_obj_dict_copy(mp_obj_t self_in) { memcpy(other->map.table, self->map.table, self->map.alloc * sizeof(mp_map_elem_t)); return other_out; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_copy_obj, mp_obj_dict_copy); +static MP_DEFINE_CONST_FUN_OBJ_1(dict_copy_obj, mp_obj_dict_copy); #if MICROPY_PY_BUILTINS_DICT_FROMKEYS // this is a classmethod -STATIC mp_obj_t dict_fromkeys(size_t n_args, const mp_obj_t *args) { +static mp_obj_t dict_fromkeys(size_t n_args, const mp_obj_t *args) { // CIRCUITPY-CHANGE mp_obj_type_t *type = MP_OBJ_TO_PTR(args[0]); mp_obj_t iter = mp_getiter(args[1], NULL); @@ -345,11 +345,11 @@ STATIC mp_obj_t dict_fromkeys(size_t n_args, const mp_obj_t *args) { return self_out; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_fromkeys_fun_obj, 2, 3, dict_fromkeys); -STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(dict_fromkeys_obj, MP_ROM_PTR(&dict_fromkeys_fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_fromkeys_fun_obj, 2, 3, dict_fromkeys); +static MP_DEFINE_CONST_CLASSMETHOD_OBJ(dict_fromkeys_obj, MP_ROM_PTR(&dict_fromkeys_fun_obj)); #endif -STATIC mp_obj_t dict_get_helper(size_t n_args, const mp_obj_t *args, mp_map_lookup_kind_t lookup_kind) { +static mp_obj_t dict_get_helper(size_t n_args, const mp_obj_t *args, mp_map_lookup_kind_t lookup_kind) { mp_check_self(mp_obj_is_dict_or_ordereddict(args[0])); // CIRCUITPY-CHANGE mp_obj_dict_t *self = native_dict(args[0]); @@ -380,28 +380,28 @@ STATIC mp_obj_t dict_get_helper(size_t n_args, const mp_obj_t *args, mp_map_look return value; } -STATIC mp_obj_t dict_get(size_t n_args, const mp_obj_t *args) { +static mp_obj_t dict_get(size_t n_args, const mp_obj_t *args) { return dict_get_helper(n_args, args, MP_MAP_LOOKUP); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_get_obj, 2, 3, dict_get); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_get_obj, 2, 3, dict_get); -STATIC mp_obj_t dict_pop(size_t n_args, const mp_obj_t *args) { +static mp_obj_t dict_pop(size_t n_args, const mp_obj_t *args) { return dict_get_helper(n_args, args, MP_MAP_LOOKUP_REMOVE_IF_FOUND); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_pop_obj, 2, 3, dict_pop); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_pop_obj, 2, 3, dict_pop); -STATIC mp_obj_t dict_setdefault(size_t n_args, const mp_obj_t *args) { +static mp_obj_t dict_setdefault(size_t n_args, const mp_obj_t *args) { return dict_get_helper(n_args, args, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_setdefault_obj, 2, 3, dict_setdefault); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_setdefault_obj, 2, 3, dict_setdefault); -STATIC mp_obj_t dict_popitem(mp_obj_t self_in) { +static mp_obj_t dict_popitem(mp_obj_t self_in) { mp_check_self(mp_obj_is_dict_or_ordereddict(self_in)); // CIRCUITPY-CHANGE mp_obj_dict_t *self = native_dict(self_in); mp_ensure_not_fixed(self); if (self->map.used == 0) { - // CIRCUITPY-CHANGE + // CIRCUITPY-CHANGE: different message mp_raise_msg_varg(&mp_type_KeyError, MP_ERROR_TEXT("pop from empty %q"), MP_QSTR_dict); } size_t cur = 0; @@ -420,9 +420,9 @@ STATIC mp_obj_t dict_popitem(mp_obj_t self_in) { return tuple; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_popitem_obj, dict_popitem); +static MP_DEFINE_CONST_FUN_OBJ_1(dict_popitem_obj, dict_popitem); -STATIC mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { mp_check_self(mp_obj_is_dict_or_ordereddict(args[0])); // CIRCUITPY-CHANGE mp_obj_dict_t *self = native_dict(args[0]); @@ -471,11 +471,11 @@ STATIC mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwarg return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(dict_update_obj, 1, dict_update); +static MP_DEFINE_CONST_FUN_OBJ_KW(dict_update_obj, 1, dict_update); // CIRCUITPY-CHANGE #if MICROPY_PY_COLLECTIONS_ORDEREDDICT -STATIC mp_obj_t dict_move_to_end(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t dict_move_to_end(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { mp_obj_dict_t *self = MP_OBJ_TO_PTR(pos_args[0]); mp_arg_validate_type(self, &mp_type_ordereddict, MP_QSTR_self); @@ -518,14 +518,14 @@ STATIC mp_obj_t dict_move_to_end(size_t n_args, const mp_obj_t *pos_args, mp_map return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(dict_move_to_end_obj, 1, dict_move_to_end); +static MP_DEFINE_CONST_FUN_OBJ_KW(dict_move_to_end_obj, 1, dict_move_to_end); #endif /******************************************************************************/ /* dict views */ -STATIC const mp_obj_type_t mp_type_dict_view; -STATIC const mp_obj_type_t mp_type_dict_view_it; +static const mp_obj_type_t mp_type_dict_view; +static const mp_obj_type_t mp_type_dict_view_it; typedef enum _mp_dict_view_kind_t { MP_DICT_VIEW_ITEMS, @@ -533,7 +533,7 @@ typedef enum _mp_dict_view_kind_t { MP_DICT_VIEW_VALUES, } mp_dict_view_kind_t; -STATIC const char *const mp_dict_view_names[] = {"dict_items", "dict_keys", "dict_values"}; +static const char *const mp_dict_view_names[] = {"dict_items", "dict_keys", "dict_values"}; typedef struct _mp_obj_dict_view_it_t { mp_obj_base_t base; @@ -548,7 +548,7 @@ typedef struct _mp_obj_dict_view_t { mp_dict_view_kind_t kind; } mp_obj_dict_view_t; -STATIC mp_obj_t dict_view_it_iternext(mp_obj_t self_in) { +static mp_obj_t dict_view_it_iternext(mp_obj_t self_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_dict_view_it)); mp_obj_dict_view_it_t *self = MP_OBJ_TO_PTR(self_in); // CIRCUITPY-CHANGE @@ -571,14 +571,14 @@ STATIC mp_obj_t dict_view_it_iternext(mp_obj_t self_in) { } } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_dict_view_it, MP_QSTR_iterator, MP_TYPE_FLAG_ITER_IS_ITERNEXT, iter, dict_view_it_iternext ); -STATIC mp_obj_t dict_view_getiter(mp_obj_t view_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t dict_view_getiter(mp_obj_t view_in, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(mp_obj_dict_view_it_t) <= sizeof(mp_obj_iter_buf_t)); mp_check_self(mp_obj_is_type(view_in, &mp_type_dict_view)); mp_obj_dict_view_t *view = MP_OBJ_TO_PTR(view_in); @@ -590,7 +590,7 @@ STATIC mp_obj_t dict_view_getiter(mp_obj_t view_in, mp_obj_iter_buf_t *iter_buf) return MP_OBJ_FROM_PTR(o); } -STATIC void dict_view_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void dict_view_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_check_self(mp_obj_is_type(self_in, &mp_type_dict_view)); mp_obj_dict_view_t *self = MP_OBJ_TO_PTR(self_in); @@ -610,7 +610,7 @@ STATIC void dict_view_print(const mp_print_t *print, mp_obj_t self_in, mp_print_ mp_print_str(print, "])"); } -STATIC mp_obj_t dict_view_unary_op(mp_unary_op_t op, mp_obj_t o_in) { +static mp_obj_t dict_view_unary_op(mp_unary_op_t op, mp_obj_t o_in) { mp_obj_dict_view_t *o = MP_OBJ_TO_PTR(o_in); // only dict.values() supports __hash__. if (op == MP_UNARY_OP_HASH && o->kind == MP_DICT_VIEW_VALUES) { @@ -619,7 +619,7 @@ STATIC mp_obj_t dict_view_unary_op(mp_unary_op_t op, mp_obj_t o_in) { return MP_OBJ_NULL; } -STATIC mp_obj_t dict_view_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t dict_view_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { // only supported for the 'keys' kind until sets and dicts are refactored mp_obj_dict_view_t *o = MP_OBJ_TO_PTR(lhs_in); if (o->kind != MP_DICT_VIEW_KEYS) { @@ -631,7 +631,7 @@ STATIC mp_obj_t dict_view_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t return dict_binary_op(op, o->dict, rhs_in); } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_dict_view, MP_QSTR_dict_view, MP_TYPE_FLAG_ITER_IS_GETITER, @@ -641,37 +641,37 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( iter, dict_view_getiter ); -STATIC mp_obj_t mp_obj_new_dict_view(mp_obj_t dict, mp_dict_view_kind_t kind) { +static mp_obj_t mp_obj_new_dict_view(mp_obj_t dict, mp_dict_view_kind_t kind) { mp_obj_dict_view_t *o = mp_obj_malloc(mp_obj_dict_view_t, &mp_type_dict_view); o->dict = dict; o->kind = kind; return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t dict_view(mp_obj_t self_in, mp_dict_view_kind_t kind) { +static mp_obj_t dict_view(mp_obj_t self_in, mp_dict_view_kind_t kind) { mp_check_self(mp_obj_is_dict_or_ordereddict(self_in)); return mp_obj_new_dict_view(self_in, kind); } -STATIC mp_obj_t dict_items(mp_obj_t self_in) { +static mp_obj_t dict_items(mp_obj_t self_in) { return dict_view(self_in, MP_DICT_VIEW_ITEMS); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_items_obj, dict_items); +static MP_DEFINE_CONST_FUN_OBJ_1(dict_items_obj, dict_items); -STATIC mp_obj_t dict_keys(mp_obj_t self_in) { +static mp_obj_t dict_keys(mp_obj_t self_in) { return dict_view(self_in, MP_DICT_VIEW_KEYS); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_keys_obj, dict_keys); +static MP_DEFINE_CONST_FUN_OBJ_1(dict_keys_obj, dict_keys); -STATIC mp_obj_t dict_values(mp_obj_t self_in) { +static mp_obj_t dict_values(mp_obj_t self_in) { return dict_view(self_in, MP_DICT_VIEW_VALUES); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_values_obj, dict_values); +static MP_DEFINE_CONST_FUN_OBJ_1(dict_values_obj, dict_values); /******************************************************************************/ /* dict iterator */ -STATIC mp_obj_t dict_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t dict_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(mp_obj_dict_view_it_t) <= sizeof(mp_obj_iter_buf_t)); mp_check_self(mp_obj_is_dict_or_ordereddict(self_in)); mp_obj_dict_view_it_t *o = (mp_obj_dict_view_it_t *)iter_buf; @@ -685,7 +685,7 @@ STATIC mp_obj_t dict_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) { /******************************************************************************/ /* dict constructors & public C API */ -STATIC const mp_rom_map_elem_t dict_locals_dict_table[] = { +static const mp_rom_map_elem_t dict_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&dict_clear_obj) }, { MP_ROM_QSTR(MP_QSTR_copy), MP_ROM_PTR(&dict_copy_obj) }, #if MICROPY_PY_BUILTINS_DICT_FROMKEYS @@ -708,7 +708,7 @@ STATIC const mp_rom_map_elem_t dict_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___delitem__), MP_ROM_PTR(&mp_op_delitem_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(dict_locals_dict, dict_locals_dict_table); +static MP_DEFINE_CONST_DICT(dict_locals_dict, dict_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_dict, diff --git a/py/objenumerate.c b/py/objenumerate.c index 40bed919ed750..8217a0d4f9927 100644 --- a/py/objenumerate.c +++ b/py/objenumerate.c @@ -37,9 +37,9 @@ typedef struct _mp_obj_enumerate_t { mp_int_t cur; } mp_obj_enumerate_t; -STATIC mp_obj_t enumerate_iternext(mp_obj_t self_in); +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, size_t n_kw, const mp_obj_t *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} }, @@ -75,7 +75,7 @@ MP_DEFINE_CONST_OBJ_TYPE( iter, enumerate_iternext ); -STATIC mp_obj_t enumerate_iternext(mp_obj_t self_in) { +static mp_obj_t enumerate_iternext(mp_obj_t self_in) { assert(mp_obj_is_type(self_in, &mp_type_enumerate)); mp_obj_enumerate_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t next = mp_iternext(self->iter); diff --git a/py/objexcept.c b/py/objexcept.c index 03dbff334e4b0..e98907946ce51 100644 --- a/py/objexcept.c +++ b/py/objexcept.c @@ -129,7 +129,7 @@ mp_obj_exception_t *mp_obj_exception_get_native(mp_obj_t self_in) { } } -STATIC void decompress_error_text_maybe(mp_obj_exception_t *o) { +static void decompress_error_text_maybe(mp_obj_exception_t *o) { #if MICROPY_ROM_TEXT_COMPRESSION if (o->args->len == 1 && mp_obj_is_exact_type(o->args->items[0], &mp_type_str)) { mp_obj_str_t *o_str = MP_OBJ_TO_PTR(o->args->items[0]); @@ -485,8 +485,9 @@ mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args, } #if MICROPY_ERROR_REPORTING != MICROPY_ERROR_REPORTING_NONE + mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, mp_rom_error_text_t msg) { - // CIRCUITPY-CHANGE: is different here and for many lines below. + // CIRCUITPY-CHANGE return mp_obj_new_exception_msg_varg(exc_type, msg); } @@ -501,7 +502,7 @@ struct _exc_printer_t { byte *buf; }; -STATIC void exc_add_strn(void *data, const char *str, size_t len) { +static void exc_add_strn(void *data, const char *str, size_t len) { struct _exc_printer_t *pr = data; if (pr->len + len >= pr->alloc) { // Not enough room for data plus a null byte so try to grow the buffer @@ -566,6 +567,7 @@ mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, mp_rom_er } if (o_str_buf == NULL) { + // CIRCUITPY-CHANGE: different way of building message // No memory for the string buffer: the string is compressed so don't add it. o_str->len = 0; o_str->data = NULL; @@ -726,7 +728,7 @@ void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values // CIRCUITPY-CHANGE: here until end #if MICROPY_PY_SYS_EXC_INFO -STATIC const mp_obj_namedtuple_type_t code_type_obj = { +static const mp_obj_namedtuple_type_t code_type_obj = { NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_code), .n_fields = 15, .fields = { @@ -748,7 +750,7 @@ STATIC const mp_obj_namedtuple_type_t code_type_obj = { }, }; -STATIC mp_obj_t code_make_new(qstr file, qstr block) { +static mp_obj_t code_make_new(qstr file, qstr block) { mp_obj_t elems[15] = { mp_obj_new_int(0), // co_argcount mp_obj_new_int(0), // co_kwonlyargcount @@ -770,7 +772,7 @@ STATIC mp_obj_t code_make_new(qstr file, qstr block) { 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 = { +static const mp_obj_namedtuple_type_t frame_type_obj = { NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_frame), .n_fields = 8, .fields = { @@ -785,7 +787,7 @@ STATIC const mp_obj_namedtuple_type_t frame_type_obj = { }, }; -STATIC mp_obj_t frame_make_new(mp_obj_t f_code, int f_lineno) { +static mp_obj_t frame_make_new(mp_obj_t f_code, int f_lineno) { mp_obj_t elems[8] = { mp_const_none, // f_back mp_obj_new_dict(0), // f_builtins @@ -800,7 +802,7 @@ STATIC mp_obj_t frame_make_new(mp_obj_t f_code, int f_lineno) { 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 = { +static const mp_obj_namedtuple_type_t traceback_type_obj = { NAMEDTUPLE_TYPE_BASE_AND_SLOTS(MP_QSTR_traceback), .n_fields = 4, .fields = { @@ -811,7 +813,7 @@ STATIC const mp_obj_namedtuple_type_t traceback_type_obj = { }, }; -STATIC mp_obj_t traceback_from_values(size_t *values, mp_obj_t tb_next) { +static mp_obj_t traceback_from_values(size_t *values, mp_obj_t tb_next) { int lineno = values[1]; mp_obj_t elems[4] = { diff --git a/py/objfilter.c b/py/objfilter.c index 2a657fde4b71b..7f1f700f6a607 100644 --- a/py/objfilter.c +++ b/py/objfilter.c @@ -34,7 +34,7 @@ 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, size_t n_kw, const mp_obj_t *args) { +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 = mp_obj_malloc(mp_obj_filter_t, type); o->fun = args[0]; @@ -42,7 +42,7 @@ STATIC mp_obj_t filter_make_new(const mp_obj_type_t *type, size_t n_args, size_t return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t filter_iternext(mp_obj_t self_in) { +static mp_obj_t filter_iternext(mp_obj_t self_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_filter)); mp_obj_filter_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t next; diff --git a/py/objfloat.c b/py/objfloat.c index 9129c364032d0..b3a1f692594ad 100644 --- a/py/objfloat.c +++ b/py/objfloat.c @@ -106,7 +106,7 @@ mp_int_t mp_float_hash(mp_float_t src) { } #endif -STATIC void float_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void float_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_float_t o_val = mp_obj_float_get(o_in); #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT @@ -128,7 +128,7 @@ 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, size_t n_kw, const mp_obj_t *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, n_kw, 0, 1, false); @@ -153,7 +153,7 @@ STATIC mp_obj_t float_make_new(const mp_obj_type_t *type_in, size_t n_args, size } } -STATIC mp_obj_t float_unary_op(mp_unary_op_t op, mp_obj_t o_in) { +static mp_obj_t float_unary_op(mp_unary_op_t op, mp_obj_t o_in) { mp_float_t val = mp_obj_float_get(o_in); switch (op) { case MP_UNARY_OP_BOOL: @@ -176,7 +176,7 @@ STATIC mp_obj_t float_unary_op(mp_unary_op_t op, mp_obj_t o_in) { } } -STATIC mp_obj_t float_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t float_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { mp_float_t lhs_val = mp_obj_float_get(lhs_in); #if MICROPY_PY_BUILTINS_COMPLEX if (mp_obj_is_type(rhs_in, &mp_type_complex)) { @@ -212,7 +212,7 @@ mp_float_t mp_obj_float_get(mp_obj_t self_in) { #endif -STATIC void mp_obj_float_divmod(mp_float_t *x, mp_float_t *y) { +static void mp_obj_float_divmod(mp_float_t *x, mp_float_t *y) { // logic here follows that of CPython // https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations // x == (x//y)*y + (x%y) diff --git a/py/objfun.c b/py/objfun.c index 46145129eb4ec..a552c5531b0e5 100644 --- a/py/objfun.c +++ b/py/objfun.c @@ -49,7 +49,7 @@ /* builtin functions */ // CIRCUITPY-CHANGE: PLACE_IN_ITCM -STATIC mp_obj_t PLACE_IN_ITCM(fun_builtin_0_call)(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t PLACE_IN_ITCM(fun_builtin_0_call)(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { (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); @@ -63,7 +63,7 @@ MP_DEFINE_CONST_OBJ_TYPE( ); // CIRCUITPY-CHANGE: PLACE_IN_ITCM -STATIC mp_obj_t PLACE_IN_ITCM(fun_builtin_1_call)(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t PLACE_IN_ITCM(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(n_args, n_kw, 1, 1, false); @@ -75,7 +75,7 @@ MP_DEFINE_CONST_OBJ_TYPE( call, fun_builtin_1_call ); -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) { +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(n_args, n_kw, 2, 2, false); @@ -88,7 +88,7 @@ MP_DEFINE_CONST_OBJ_TYPE( ); // CIRCUITPY-CHANGE: PLACE_IN_ITCM -STATIC mp_obj_t PLACE_IN_ITCM(fun_builtin_3_call)(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t PLACE_IN_ITCM(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(n_args, n_kw, 3, 3, false); @@ -100,7 +100,7 @@ MP_DEFINE_CONST_OBJ_TYPE( call, fun_builtin_3_call ); -STATIC mp_obj_t fun_builtin_var_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t fun_builtin_var_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_var)); mp_obj_fun_builtin_var_t *self = MP_OBJ_TO_PTR(self_in); @@ -131,35 +131,29 @@ MP_DEFINE_CONST_OBJ_TYPE( /******************************************************************************/ /* byte code functions */ -STATIC qstr mp_obj_code_get_name(const mp_obj_fun_bc_t *fun, const byte *code_info) { - MP_BC_PRELUDE_SIZE_DECODE(code_info); - mp_uint_t name = mp_decode_uint_value(code_info); - #if MICROPY_EMIT_BYTECODE_USES_QSTR_TABLE - name = fun->context->constants.qstr_table[name]; - #endif - return name; -} - -#if MICROPY_EMIT_NATIVE -STATIC const mp_obj_type_t mp_type_fun_native; -#endif - qstr mp_obj_fun_get_name(mp_const_obj_t fun_in) { const mp_obj_fun_bc_t *fun = MP_OBJ_TO_PTR(fun_in); + const byte *bc = fun->bytecode; + #if MICROPY_EMIT_NATIVE if (fun->base.type == &mp_type_fun_native || fun->base.type == &mp_type_native_gen_wrap) { - // TODO native functions don't have name stored - return MP_QSTR_; + bc = mp_obj_fun_native_get_prelude_ptr(fun); } #endif - const byte *bc = fun->bytecode; MP_BC_PRELUDE_SIG_DECODE(bc); - return mp_obj_code_get_name(fun, bc); + MP_BC_PRELUDE_SIZE_DECODE(bc); + + mp_uint_t name = mp_decode_uint_value(bc); + #if MICROPY_EMIT_BYTECODE_USES_QSTR_TABLE + name = fun->context->constants.qstr_table[name]; + #endif + + return name; } #if MICROPY_CPYTHON_COMPAT -STATIC void fun_bc_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void fun_bc_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_fun_bc_t *o = MP_OBJ_TO_PTR(o_in); mp_printf(print, "", mp_obj_fun_get_name(o_in), o); @@ -167,7 +161,7 @@ STATIC void fun_bc_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t #endif #if DEBUG_PRINT -STATIC void dump_args(const mp_obj_t *a, size_t sz) { +static void dump_args(const mp_obj_t *a, size_t sz) { DEBUG_printf("%p: ", a); for (size_t i = 0; i < sz; i++) { DEBUG_printf("%p ", a[i]); @@ -234,7 +228,7 @@ mp_code_state_t *mp_obj_fun_bc_prepare_codestate(mp_obj_t self_in, size_t n_args #endif // CIRCUITPY-CHANGE: PLACE_IN_ITCM -STATIC mp_obj_t PLACE_IN_ITCM(fun_bc_call)(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t PLACE_IN_ITCM(fun_bc_call)(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { MP_STACK_CHECK(); DEBUG_printf("Input n_args: " UINT_FMT ", n_kw: " UINT_FMT "\n", n_args, n_kw); @@ -388,7 +382,7 @@ mp_obj_t mp_obj_new_fun_bc(const mp_obj_t *def_args, const byte *code, const mp_ def_kw_args = def_args[1]; n_extra_args += 1; } - mp_obj_fun_bc_t *o = mp_obj_malloc_var(mp_obj_fun_bc_t, mp_obj_t, n_extra_args, &mp_type_fun_bc); + mp_obj_fun_bc_t *o = mp_obj_malloc_var(mp_obj_fun_bc_t, extra_args, mp_obj_t, n_extra_args, &mp_type_fun_bc); o->bytecode = code; o->context = context; o->child_table = child_table; @@ -407,10 +401,10 @@ mp_obj_t mp_obj_new_fun_bc(const mp_obj_t *def_args, const byte *code, const mp_ #if MICROPY_EMIT_NATIVE // CIRCUITPY-CHANGE: PLACE_IN_ITCM -STATIC mp_obj_t PLACE_IN_ITCM(fun_native_call)(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t PLACE_IN_ITCM(fun_native_call)(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { MP_STACK_CHECK(); mp_obj_fun_bc_t *self = MP_OBJ_TO_PTR(self_in); - mp_call_fun_t fun = MICROPY_MAKE_POINTER_CALLABLE((void *)self->bytecode); + mp_call_fun_t fun = mp_obj_fun_native_get_function_start(self); return fun(self_in, n_args, n_kw, args); } @@ -425,7 +419,7 @@ STATIC mp_obj_t PLACE_IN_ITCM(fun_native_call)(mp_obj_t self_in, size_t n_args, #define FUN_BC_TYPE_ATTR #endif -STATIC MP_DEFINE_CONST_OBJ_TYPE( +MP_DEFINE_CONST_OBJ_TYPE( mp_type_fun_native, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF, @@ -434,12 +428,27 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( call, fun_native_call ); -mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, const mp_module_context_t *mc, struct _mp_raw_code_t *const *child_table) { - mp_obj_fun_bc_t *o = MP_OBJ_TO_PTR(mp_obj_new_fun_bc(def_args, (const byte *)fun_data, mc, child_table)); - o->base.type = &mp_type_fun_native; - return MP_OBJ_FROM_PTR(o); +#endif // MICROPY_EMIT_NATIVE + +/******************************************************************************/ +/* viper functions */ + +#if MICROPY_EMIT_NATIVE + +static mp_obj_t fun_viper_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { + MP_STACK_CHECK(); + mp_obj_fun_bc_t *self = MP_OBJ_TO_PTR(self_in); + mp_call_fun_t fun = MICROPY_MAKE_POINTER_CALLABLE((void *)self->bytecode); + return fun(self_in, n_args, n_kw, args); } +MP_DEFINE_CONST_OBJ_TYPE( + mp_type_fun_viper, + MP_QSTR_function, + MP_TYPE_FLAG_BINDS_SELF, + call, fun_viper_call + ); + #endif // MICROPY_EMIT_NATIVE /******************************************************************************/ @@ -447,13 +456,6 @@ mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, c #if MICROPY_EMIT_INLINE_ASM -typedef struct _mp_obj_fun_asm_t { - mp_obj_base_t base; - size_t n_args; - const void *fun_data; // GC must be able to trace this pointer - mp_uint_t type_sig; -} mp_obj_fun_asm_t; - typedef mp_uint_t (*inline_asm_fun_0_t)(void); typedef mp_uint_t (*inline_asm_fun_1_t)(mp_uint_t); typedef mp_uint_t (*inline_asm_fun_2_t)(mp_uint_t, mp_uint_t); @@ -461,7 +463,7 @@ typedef mp_uint_t (*inline_asm_fun_3_t)(mp_uint_t, mp_uint_t, mp_uint_t); typedef mp_uint_t (*inline_asm_fun_4_t)(mp_uint_t, mp_uint_t, mp_uint_t, mp_uint_t); // convert a MicroPython object to a sensible value for inline asm -STATIC mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) { +static mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) { // TODO for byte_array, pass pointer to the array if (mp_obj_is_small_int(obj)) { return MP_OBJ_SMALL_INT_VALUE(obj); @@ -505,7 +507,7 @@ STATIC mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) { } // CIRCUITPY-CHANGE: PLACE_IN_ITCM -STATIC mp_obj_t PLACE_IN_ITCM(fun_asm_call)(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t PLACE_IN_ITCM(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(n_args, n_kw, self->n_args, self->n_args, false); @@ -535,19 +537,11 @@ STATIC mp_obj_t PLACE_IN_ITCM(fun_asm_call)(mp_obj_t self_in, size_t n_args, siz return mp_native_to_obj(ret, self->type_sig); } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +MP_DEFINE_CONST_OBJ_TYPE( mp_type_fun_asm, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF, call, fun_asm_call ); -mp_obj_t mp_obj_new_fun_asm(size_t n_args, const void *fun_data, mp_uint_t type_sig) { - mp_obj_fun_asm_t *o = mp_obj_malloc(mp_obj_fun_asm_t, &mp_type_fun_asm); - o->n_args = n_args; - o->fun_data = fun_data; - o->type_sig = type_sig; - return MP_OBJ_FROM_PTR(o); -} - #endif // MICROPY_EMIT_INLINE_ASM diff --git a/py/objfun.h b/py/objfun.h index 9de15b8841553..4059343983c2b 100644 --- a/py/objfun.h +++ b/py/objfun.h @@ -43,9 +43,82 @@ typedef struct _mp_obj_fun_bc_t { mp_obj_t extra_args[]; } mp_obj_fun_bc_t; +typedef struct _mp_obj_fun_asm_t { + mp_obj_base_t base; + size_t n_args; + const void *fun_data; // GC must be able to trace this pointer + mp_uint_t type_sig; +} mp_obj_fun_asm_t; + mp_obj_t mp_obj_new_fun_bc(const mp_obj_t *def_args, const byte *code, const mp_module_context_t *cm, struct _mp_raw_code_t *const *raw_code_table); -mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, const mp_module_context_t *cm, struct _mp_raw_code_t *const *raw_code_table); -mp_obj_t mp_obj_new_fun_asm(size_t n_args, const void *fun_data, mp_uint_t type_sig); void mp_obj_fun_bc_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest); +#if MICROPY_EMIT_NATIVE + +static inline mp_obj_t mp_obj_new_fun_native(const mp_obj_t *def_args, const void *fun_data, const mp_module_context_t *mc, struct _mp_raw_code_t *const *child_table) { + mp_obj_fun_bc_t *o = (mp_obj_fun_bc_t *)MP_OBJ_TO_PTR(mp_obj_new_fun_bc(def_args, (const byte *)fun_data, mc, child_table)); + o->base.type = &mp_type_fun_native; + return MP_OBJ_FROM_PTR(o); +} + +static inline mp_obj_t mp_obj_new_fun_viper(const void *fun_data, const mp_module_context_t *mc, struct _mp_raw_code_t *const *child_table) { + mp_obj_fun_bc_t *o = mp_obj_malloc(mp_obj_fun_bc_t, &mp_type_fun_viper); + o->bytecode = (const byte *)fun_data; + o->context = mc; + o->child_table = child_table; + return MP_OBJ_FROM_PTR(o); +} + +static inline const uint8_t *mp_obj_fun_native_get_prelude_ptr(const mp_obj_fun_bc_t *fun_native) { + // Obtain a pointer to the start of the function prelude, based on prelude_ptr_index. + // CIRCUITPY-CHANGE: prevent warning + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wcast-align" + uintptr_t prelude_ptr_index = ((uintptr_t *)fun_native->bytecode)[0]; + #pragma GCC diagnostic pop + const uint8_t *prelude_ptr; + if (prelude_ptr_index == 0) { + prelude_ptr = (const uint8_t *)fun_native->child_table; + } else { + prelude_ptr = (const uint8_t *)fun_native->child_table[prelude_ptr_index]; + } + return prelude_ptr; +} + +static inline void *mp_obj_fun_native_get_function_start(const mp_obj_fun_bc_t *fun_native) { + // Obtain a pointer to the start of the function executable machine code. + return MICROPY_MAKE_POINTER_CALLABLE((void *)(fun_native->bytecode + sizeof(uintptr_t))); +} + +static inline void *mp_obj_fun_native_get_generator_start(const mp_obj_fun_bc_t *fun_native) { + // Obtain a pointer to the start of the generator executable machine code. + // CIRCUITPY-CHANGE: prevent warning + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wcast-align" + uintptr_t start_offset = ((uintptr_t *)fun_native->bytecode)[1]; + #pragma GCC diagnostic pop + return MICROPY_MAKE_POINTER_CALLABLE((void *)(fun_native->bytecode + start_offset)); +} + +static inline void *mp_obj_fun_native_get_generator_resume(const mp_obj_fun_bc_t *fun_native) { + // Obtain a pointer to the resume location of the generator executable machine code. + // CIRCUITPY-CHANGE: prevent warning + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wcast-align" + return MICROPY_MAKE_POINTER_CALLABLE((void *)&((uintptr_t *)fun_native->bytecode)[2]); + #pragma GCC diagnostic pop +} + +#endif + +#if MICROPY_EMIT_INLINE_ASM +static inline mp_obj_t mp_obj_new_fun_asm(size_t n_args, const void *fun_data, mp_uint_t type_sig) { + mp_obj_fun_asm_t *o = (mp_obj_fun_asm_t *)mp_obj_malloc(mp_obj_fun_asm_t, &mp_type_fun_asm); + o->n_args = n_args; + o->fun_data = (const byte *)fun_data; + o->type_sig = type_sig; + return MP_OBJ_FROM_PTR(o); +} +#endif + #endif // MICROPY_INCLUDED_PY_OBJFUN_H diff --git a/py/objgenerator.c b/py/objgenerator.c index 6dc1f17aa8034..fa59313998f4d 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -57,7 +57,7 @@ typedef struct _mp_obj_gen_instance_t { mp_code_state_t code_state; } mp_obj_gen_instance_t; -STATIC mp_obj_t gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { // CIRCUITPY-CHANGE // A generating or coroutine function is just a bytecode function // with type mp_type_gen_wrap or mp_type_coro_wrap. @@ -69,7 +69,7 @@ STATIC mp_obj_t gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons // CIRCUITPY-CHANGE // allocate the generator or coroutine object, with room for local stack and exception stack - mp_obj_gen_instance_t *o = mp_obj_malloc_var(mp_obj_gen_instance_t, byte, + mp_obj_gen_instance_t *o = mp_obj_malloc_var(mp_obj_gen_instance_t, code_state.state, byte, n_state * sizeof(mp_obj_t) + n_exc_stack * sizeof(mp_exc_stack_t), // CIRCUITPY-CHANGE #if MICROPY_PY_ASYNC_AWAIT @@ -123,29 +123,19 @@ typedef struct _mp_obj_gen_instance_native_t { mp_code_state_native_t code_state; } mp_obj_gen_instance_native_t; -STATIC mp_obj_t native_gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t native_gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { // The state for a native generating function is held in the same struct as a bytecode function mp_obj_fun_bc_t *self_fun = MP_OBJ_TO_PTR(self_in); // Determine start of prelude. - // CIRCUITPY-CHANGE: prevent compiler warning - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wcast-align" - uintptr_t prelude_ptr_index = ((uintptr_t *)self_fun->bytecode)[0]; - #pragma GCC diagnostic pop - const uint8_t *prelude_ptr; - if (prelude_ptr_index == 0) { - prelude_ptr = (void *)self_fun->child_table; - } else { - prelude_ptr = (void *)self_fun->child_table[prelude_ptr_index]; - } + const uint8_t *prelude_ptr = mp_obj_fun_native_get_prelude_ptr(self_fun); // Extract n_state from the prelude. const uint8_t *ip = prelude_ptr; MP_BC_PRELUDE_SIG_DECODE(ip); // Allocate the generator object, with room for local stack (exception stack not needed). - mp_obj_gen_instance_native_t *o = mp_obj_malloc_var(mp_obj_gen_instance_native_t, byte, n_state * sizeof(mp_obj_t), + mp_obj_gen_instance_native_t *o = mp_obj_malloc_var(mp_obj_gen_instance_native_t, code_state.state, byte, n_state * sizeof(mp_obj_t), // CIRCUITPY-CHANGE #if MICROPY_PY_ASYNC_AWAIT (self_fun->base.type == &mp_type_native_gen_wrap) ? &mp_type_gen_instance : &mp_type_coro_instance @@ -157,21 +147,14 @@ STATIC mp_obj_t native_gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_k // Parse the input arguments and set up the code state o->pend_exc = mp_const_none; o->code_state.fun_bc = self_fun; - o->code_state.ip = prelude_ptr; o->code_state.n_state = n_state; - o->code_state.sp = &o->code_state.state[0] - 1; mp_setup_code_state_native(&o->code_state, n_args, n_kw, args); // Indicate we are a native function, which doesn't use this variable o->code_state.exc_sp_idx = MP_CODE_STATE_EXC_SP_IDX_SENTINEL; // Prepare the generator instance for execution - // CIRCUITPY-CHANGE: prevent compiler warning - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wcast-align" - uintptr_t start_offset = ((uintptr_t *)self_fun->bytecode)[1]; - #pragma GCC diagnostic pop - o->code_state.ip = MICROPY_MAKE_POINTER_CALLABLE((void *)(self_fun->bytecode + start_offset)); + o->code_state.ip = mp_obj_fun_native_get_generator_start(self_fun); return MP_OBJ_FROM_PTR(o); } @@ -206,7 +189,7 @@ MP_DEFINE_CONST_OBJ_TYPE( /******************************************************************************/ /* generator instance */ -STATIC void gen_instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void gen_instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_gen_instance_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", mp_obj_fun_get_name(MP_OBJ_FROM_PTR(self->code_state.fun_bc)), self); @@ -214,7 +197,7 @@ STATIC void gen_instance_print(const mp_print_t *print, mp_obj_t self_in, mp_pri // CIRCUITPY-CHANGE #if MICROPY_PY_ASYNC_AWAIT -STATIC void coro_instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void coro_instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_gen_instance_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", mp_obj_fun_get_name(MP_OBJ_FROM_PTR(self->code_state.fun_bc)), self); @@ -278,9 +261,9 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_ #if MICROPY_EMIT_NATIVE if (self->code_state.exc_sp_idx == MP_CODE_STATE_EXC_SP_IDX_SENTINEL) { - // A native generator, with entry point 2 words into the "bytecode" pointer + // A native generator. typedef uintptr_t (*mp_fun_native_gen_t)(void *, mp_obj_t); - mp_fun_native_gen_t fun = MICROPY_MAKE_POINTER_CALLABLE((const void *)(self->code_state.fun_bc->bytecode + 2 * sizeof(uintptr_t))); + mp_fun_native_gen_t fun = mp_obj_fun_native_get_generator_resume(self->code_state.fun_bc); ret_kind = fun((void *)&self->code_state, throw_value); } else #endif @@ -333,7 +316,7 @@ 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, bool raise_stop_iteration) { +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: @@ -357,24 +340,24 @@ STATIC mp_obj_t gen_resume_and_raise(mp_obj_t self_in, mp_obj_t send_value, mp_o } } -STATIC mp_obj_t gen_instance_iternext(mp_obj_t self_in) { +static mp_obj_t gen_instance_iternext(mp_obj_t self_in) { 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) { +static mp_obj_t gen_instance_send(mp_obj_t self_in, mp_obj_t send_value) { 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); +static MP_DEFINE_CONST_FUN_OBJ_2(gen_instance_send_obj, gen_instance_send); // CIRCUITPY-CHANGE #if MICROPY_PY_ASYNC_AWAIT -STATIC mp_obj_t coro_instance_await(mp_obj_t self_in) { +static mp_obj_t coro_instance_await(mp_obj_t self_in) { return self_in; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(coro_instance_await_obj, coro_instance_await); +static MP_DEFINE_CONST_FUN_OBJ_1(coro_instance_await_obj, coro_instance_await); #endif -STATIC mp_obj_t gen_instance_throw(size_t n_args, const mp_obj_t *args) { +static mp_obj_t gen_instance_throw(size_t n_args, const mp_obj_t *args) { // The signature of this function is: throw(type[, value[, traceback]]) // CPython will pass all given arguments through the call chain and process them // at the point they are used (native generators will handle them differently to @@ -394,7 +377,7 @@ STATIC mp_obj_t gen_instance_throw(size_t n_args, const mp_obj_t *args) { 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); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(gen_instance_throw_obj, 2, 4, gen_instance_throw); // CIRCUITPY-CHANGE static mp_obj_t generatorexit(void) { @@ -407,7 +390,7 @@ static mp_obj_t generatorexit(void) { #endif } -STATIC mp_obj_t gen_instance_close(mp_obj_t self_in) { +static mp_obj_t gen_instance_close(mp_obj_t self_in) { mp_obj_t ret; // CIRCUITPY-CHANGE switch (mp_obj_gen_resume(self_in, mp_const_none, generatorexit(), &ret)) { @@ -427,10 +410,10 @@ STATIC mp_obj_t gen_instance_close(mp_obj_t self_in) { return mp_const_none; } } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(gen_instance_close_obj, gen_instance_close); +static MP_DEFINE_CONST_FUN_OBJ_1(gen_instance_close_obj, gen_instance_close); #if MICROPY_PY_GENERATOR_PEND_THROW -STATIC mp_obj_t gen_instance_pend_throw(mp_obj_t self_in, mp_obj_t exc_in) { +static mp_obj_t gen_instance_pend_throw(mp_obj_t self_in, mp_obj_t exc_in) { mp_obj_gen_instance_t *self = MP_OBJ_TO_PTR(self_in); if (self->pend_exc == MP_OBJ_NULL) { mp_raise_ValueError(MP_ERROR_TEXT("generator already executing")); @@ -439,10 +422,10 @@ STATIC mp_obj_t gen_instance_pend_throw(mp_obj_t self_in, mp_obj_t exc_in) { self->pend_exc = exc_in; return prev; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(gen_instance_pend_throw_obj, gen_instance_pend_throw); +static MP_DEFINE_CONST_FUN_OBJ_2(gen_instance_pend_throw_obj, gen_instance_pend_throw); #endif -STATIC const mp_rom_map_elem_t gen_instance_locals_dict_table[] = { +static const mp_rom_map_elem_t gen_instance_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&gen_instance_close_obj) }, { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&gen_instance_send_obj) }, { MP_ROM_QSTR(MP_QSTR_throw), MP_ROM_PTR(&gen_instance_throw_obj) }, @@ -451,7 +434,7 @@ STATIC const mp_rom_map_elem_t gen_instance_locals_dict_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(gen_instance_locals_dict, gen_instance_locals_dict_table); +static MP_DEFINE_CONST_DICT(gen_instance_locals_dict, gen_instance_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_gen_instance, @@ -466,7 +449,7 @@ MP_DEFINE_CONST_OBJ_TYPE( #if MICROPY_PY_ASYNC_AWAIT // coroutine instance locals dict and type // same as generator, but with addition of __await()__. -STATIC const mp_rom_map_elem_t coro_instance_locals_dict_table[] = { +static const mp_rom_map_elem_t coro_instance_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_close), MP_ROM_PTR(&gen_instance_close_obj) }, { MP_ROM_QSTR(MP_QSTR_send), MP_ROM_PTR(&gen_instance_send_obj) }, { MP_ROM_QSTR(MP_QSTR_throw), MP_ROM_PTR(&gen_instance_throw_obj) }, @@ -476,7 +459,7 @@ STATIC const mp_rom_map_elem_t coro_instance_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___await__), MP_ROM_PTR(&coro_instance_await_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(coro_instance_locals_dict, coro_instance_locals_dict_table); +static MP_DEFINE_CONST_DICT(coro_instance_locals_dict, coro_instance_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_coro_instance, diff --git a/py/objgetitemiter.c b/py/objgetitemiter.c index c598d1daaca9a..c735c65b652d6 100644 --- a/py/objgetitemiter.c +++ b/py/objgetitemiter.c @@ -35,7 +35,7 @@ typedef struct _mp_obj_getitem_iter_t { mp_obj_t args[3]; } mp_obj_getitem_iter_t; -STATIC mp_obj_t it_iternext(mp_obj_t self_in) { +static mp_obj_t it_iternext(mp_obj_t self_in) { mp_obj_getitem_iter_t *self = MP_OBJ_TO_PTR(self_in); nlr_buf_t nlr; if (nlr_push(&nlr) == 0) { @@ -56,7 +56,7 @@ STATIC mp_obj_t it_iternext(mp_obj_t self_in) { } } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_it, MP_QSTR_iterator, MP_TYPE_FLAG_ITER_IS_ITERNEXT, diff --git a/py/objint.c b/py/objint.c index f8fb9b5113754..197625ced815c 100644 --- a/py/objint.c +++ b/py/objint.c @@ -40,7 +40,7 @@ #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, size_t n_kw, const mp_obj_t *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, n_kw, 0, 2, false); @@ -83,7 +83,7 @@ typedef enum { MP_FP_CLASS_OVERFLOW } mp_fp_as_int_class_t; -STATIC mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) { +static mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) { union { mp_float_t f; #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT @@ -195,7 +195,7 @@ void mp_obj_int_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t } } -STATIC const uint8_t log_base2_floor[] = { +static const uint8_t log_base2_floor[] = { 0, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 3, @@ -462,7 +462,7 @@ mp_obj_t mp_obj_int_binary_op_extra_cases(mp_binary_op_t op, mp_obj_t lhs_in, mp // CIRCUITPY-CHANGE #if MICROPY_CPYTHON_COMPAT -STATIC mp_obj_t int_bit_length(mp_obj_t self_in) { +static mp_obj_t int_bit_length(mp_obj_t self_in) { #if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE if (!mp_obj_is_small_int(self_in)) { return mp_obj_int_bit_length_impl(self_in); @@ -484,7 +484,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(int_bit_length_obj, int_bit_length); // CIRCUITPY-CHANGE: more functionality // this is a classmethod -STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { // TODO: Support signed param (assumes signed=False at the moment) enum { ARG_bytes, ARG_byteorder, ARG_signed }; @@ -527,11 +527,11 @@ STATIC mp_obj_t int_from_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t return mp_obj_new_int_from_uint(value); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(int_from_bytes_fun_obj, 3, int_from_bytes); -STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(int_from_bytes_obj, MP_ROM_PTR(&int_from_bytes_fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_KW(int_from_bytes_fun_obj, 3, int_from_bytes); +static MP_DEFINE_CONST_CLASSMETHOD_OBJ(int_from_bytes_obj, MP_ROM_PTR(&int_from_bytes_fun_obj)); // CIRCUITPY-CHANGE: supports signed -STATIC mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_length, ARG_byteorder, ARG_signed }; static const mp_arg_t allowed_args[] = { { MP_QSTR_length, MP_ARG_REQUIRED | MP_ARG_INT, {.u_int = 0} }, @@ -575,9 +575,9 @@ STATIC mp_obj_t int_to_bytes(size_t n_args, const mp_obj_t *pos_args, mp_map_t * return mp_obj_new_bytes_from_vstr(&vstr); } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(int_to_bytes_obj, 3, int_to_bytes); +static MP_DEFINE_CONST_FUN_OBJ_KW(int_to_bytes_obj, 3, int_to_bytes); -STATIC const mp_rom_map_elem_t int_locals_dict_table[] = { +static const mp_rom_map_elem_t int_locals_dict_table[] = { // CIRCUITPY-CHANGE #if MICROPY_CPYTHON_COMPAT { MP_ROM_QSTR(MP_QSTR_bit_length), MP_ROM_PTR(&int_bit_length_obj) }, @@ -586,7 +586,7 @@ STATIC const mp_rom_map_elem_t int_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_to_bytes), MP_ROM_PTR(&int_to_bytes_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(int_locals_dict, int_locals_dict_table); +static MP_DEFINE_CONST_DICT(int_locals_dict, int_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_int, diff --git a/py/objint_mpz.c b/py/objint_mpz.c index 71e6d51f3a419..7bdeb364d8714 100644 --- a/py/objint_mpz.c +++ b/py/objint_mpz.c @@ -43,7 +43,7 @@ // Export value for sys.maxsize // *FORMAT-OFF* #define DIG_MASK ((MPZ_LONG_1 << MPZ_DIG_SIZE) - 1) -STATIC const mpz_dig_t maxsize_dig[] = { +static const mpz_dig_t maxsize_dig[] = { #define NUM_DIG 1 (MP_SSIZE_MAX >> MPZ_DIG_SIZE * 0) & DIG_MASK, #if (MP_SSIZE_MAX >> MPZ_DIG_SIZE * 0) > DIG_MASK @@ -343,7 +343,7 @@ mp_obj_t mp_obj_int_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_i } #if MICROPY_PY_BUILTINS_POW3 -STATIC mpz_t *mp_mpz_for_int(mp_obj_t arg, mpz_t *temp) { +static mpz_t *mp_mpz_for_int(mp_obj_t arg, mpz_t *temp) { if (mp_obj_is_small_int(arg)) { mpz_init_from_int(temp, MP_OBJ_SMALL_INT_VALUE(arg)); return temp; diff --git a/py/objlist.c b/py/objlist.c index d2de15fb642f4..475002239ca76 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -31,10 +31,10 @@ #include "py/runtime.h" #include "py/stackctrl.h" -STATIC mp_obj_t mp_obj_new_list_iterator(mp_obj_t list, size_t cur, mp_obj_iter_buf_t *iter_buf); -STATIC mp_obj_list_t *list_new(size_t n); -STATIC mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in); -STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args); +static mp_obj_t mp_obj_new_list_iterator(mp_obj_t list, size_t cur, mp_obj_iter_buf_t *iter_buf); +static mp_obj_list_t *list_new(size_t n); +static mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in); +static mp_obj_t list_pop(size_t n_args, const mp_obj_t *args); // TODO: Move to mpconfig.h #define LIST_MIN_ALLOC 4 @@ -45,7 +45,7 @@ STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args); /******************************************************************************/ /* list */ -STATIC void list_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +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_JSON && kind == PRINT_JSON)) { @@ -65,7 +65,7 @@ STATIC void list_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t k mp_print_str(print, "]"); } -STATIC mp_obj_t list_extend_from_iter(mp_obj_t list, mp_obj_t iterable) { +static mp_obj_t list_extend_from_iter(mp_obj_t list, mp_obj_t iterable) { mp_obj_t iter = mp_getiter(iterable, NULL); mp_obj_t item; while ((item = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) { @@ -94,11 +94,11 @@ mp_obj_t mp_obj_list_make_new(const mp_obj_type_t *type_in, size_t n_args, size_ } // CIRCUITPY-CHANGE -STATIC mp_obj_list_t *native_list(mp_obj_t self_in) { +static mp_obj_list_t *native_list(mp_obj_t self_in) { return MP_OBJ_TO_PTR(mp_obj_cast_to_native_base(self_in, MP_OBJ_FROM_PTR(&mp_type_list))); } -STATIC mp_obj_t list_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t list_unary_op(mp_unary_op_t op, mp_obj_t self_in) { // CIRCUITPY-CHANGE mp_obj_list_t *self = native_list(self_in); switch (op) { @@ -117,7 +117,7 @@ STATIC mp_obj_t list_unary_op(mp_unary_op_t op, mp_obj_t self_in) { } } -STATIC mp_obj_t list_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) { +static mp_obj_t list_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) { // CIRCUITPY-CHANGE mp_obj_list_t *o = native_list(lhs); switch (op) { @@ -170,7 +170,7 @@ STATIC mp_obj_t list_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) { } } -STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { +static mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { // CIRCUITPY-CHANGE mp_obj_list_t *self = native_list(self_in); if (value == MP_OBJ_NULL) { @@ -246,7 +246,7 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } } -STATIC mp_obj_t list_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t list_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { return mp_obj_new_list_iterator(o_in, 0, iter_buf); } @@ -263,7 +263,7 @@ mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg) { return mp_const_none; // return None, as per CPython } -STATIC mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in) { +static mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_list)); if (mp_obj_is_type(arg_in, &mp_type_list)) { // CIRCUITPY-CHANGE @@ -285,9 +285,10 @@ STATIC mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in) { return mp_const_none; // return None, as per CPython } -// CIRCUITPY-CHANGE: used elsewhere so not static +// CIRCUITPY-CHANGE: used elsewhere so not static; impl is different inline mp_obj_t mp_obj_list_pop(mp_obj_list_t *self, size_t index) { if (self->len == 0) { + // CIRCUITPY-CHANGE: more specific mp_raise mp_raise_IndexError_varg(MP_ERROR_TEXT("pop from empty %q"), MP_QSTR_list); } mp_obj_t ret = self->items[index]; @@ -303,14 +304,14 @@ inline mp_obj_t mp_obj_list_pop(mp_obj_list_t *self, size_t index) { } // CIRCUITPY-CHANGE -STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args) { +static mp_obj_t list_pop(size_t n_args, const mp_obj_t *args) { mp_check_self(mp_obj_is_type(args[0], &mp_type_list)); mp_obj_list_t *self = native_list(args[0]); size_t index = mp_get_index(self->base.type, self->len, n_args == 1 ? MP_OBJ_NEW_SMALL_INT(-1) : args[1], false); return mp_obj_list_pop(self, index); } -STATIC void mp_quicksort(mp_obj_t *head, mp_obj_t *tail, mp_obj_t key_fn, mp_obj_t binop_less_result) { +static void mp_quicksort(mp_obj_t *head, mp_obj_t *tail, mp_obj_t key_fn, mp_obj_t binop_less_result) { MP_STACK_CHECK(); while (head < tail) { mp_obj_t *h = head - 1; @@ -381,21 +382,21 @@ mp_obj_t mp_obj_list_clear(mp_obj_t self_in) { return mp_const_none; } -STATIC mp_obj_t list_copy(mp_obj_t self_in) { +static mp_obj_t list_copy(mp_obj_t self_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_list)); // CIRCUITPY-CHANGE mp_obj_list_t *self = native_list(self_in); return mp_obj_new_list(self->len, self->items); } -STATIC mp_obj_t list_count(mp_obj_t self_in, mp_obj_t value) { +static mp_obj_t list_count(mp_obj_t self_in, mp_obj_t value) { mp_check_self(mp_obj_is_type(self_in, &mp_type_list)); // CIRCUITPY-CHANGE mp_obj_list_t *self = native_list(self_in); return mp_seq_count_obj(self->items, self->len, value); } -STATIC mp_obj_t list_index(size_t n_args, const mp_obj_t *args) { +static mp_obj_t list_index(size_t n_args, const mp_obj_t *args) { mp_check_self(mp_obj_is_type(args[0], &mp_type_list)); // CIRCUITPY-CHANGE mp_obj_list_t *self = native_list(args[0]); @@ -412,7 +413,7 @@ inline void mp_obj_list_insert(mp_obj_list_t *self, size_t index, mp_obj_t obj) self->items[index] = obj; } -STATIC mp_obj_t list_insert(mp_obj_t self_in, mp_obj_t idx, mp_obj_t obj) { +static mp_obj_t list_insert(mp_obj_t self_in, mp_obj_t idx, mp_obj_t obj) { mp_check_self(mp_obj_is_type(self_in, &mp_type_list)); // CIRCUITPY-CHANGE mp_obj_list_t *self = native_list(self_in); @@ -441,10 +442,9 @@ mp_obj_t mp_obj_list_remove(mp_obj_t self_in, mp_obj_t value) { return mp_const_none; } -STATIC mp_obj_t list_reverse(mp_obj_t self_in) { +static mp_obj_t list_reverse(mp_obj_t self_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_list)); - // CIRCUITPY-CHANGE - mp_obj_list_t *self = native_list(self_in); + mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t len = self->len; for (mp_int_t i = 0; i < len / 2; i++) { @@ -456,20 +456,20 @@ STATIC mp_obj_t list_reverse(mp_obj_t self_in) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(list_append_obj, mp_obj_list_append); -STATIC MP_DEFINE_CONST_FUN_OBJ_2(list_extend_obj, list_extend); +static MP_DEFINE_CONST_FUN_OBJ_2(list_append_obj, mp_obj_list_append); +static MP_DEFINE_CONST_FUN_OBJ_2(list_extend_obj, list_extend); // CIRCUITPY-CHANGE: use renamed public function -STATIC MP_DEFINE_CONST_FUN_OBJ_1(list_clear_obj, mp_obj_list_clear); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(list_copy_obj, list_copy); -STATIC MP_DEFINE_CONST_FUN_OBJ_2(list_count_obj, list_count); -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(list_index_obj, 2, 4, list_index); -STATIC MP_DEFINE_CONST_FUN_OBJ_3(list_insert_obj, list_insert); -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(list_pop_obj, 1, 2, list_pop); -STATIC MP_DEFINE_CONST_FUN_OBJ_2(list_remove_obj, mp_obj_list_remove); -STATIC MP_DEFINE_CONST_FUN_OBJ_1(list_reverse_obj, list_reverse); -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(list_sort_obj, 1, mp_obj_list_sort); - -STATIC const mp_rom_map_elem_t list_locals_dict_table[] = { +static MP_DEFINE_CONST_FUN_OBJ_1(list_clear_obj, mp_obj_list_clear); +static MP_DEFINE_CONST_FUN_OBJ_1(list_copy_obj, list_copy); +static MP_DEFINE_CONST_FUN_OBJ_2(list_count_obj, list_count); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(list_index_obj, 2, 4, list_index); +static MP_DEFINE_CONST_FUN_OBJ_3(list_insert_obj, list_insert); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(list_pop_obj, 1, 2, list_pop); +static MP_DEFINE_CONST_FUN_OBJ_2(list_remove_obj, mp_obj_list_remove); +static MP_DEFINE_CONST_FUN_OBJ_1(list_reverse_obj, list_reverse); +static MP_DEFINE_CONST_FUN_OBJ_KW(list_sort_obj, 1, mp_obj_list_sort); + +static const mp_rom_map_elem_t list_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_append), MP_ROM_PTR(&list_append_obj) }, { MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&list_clear_obj) }, { MP_ROM_QSTR(MP_QSTR_copy), MP_ROM_PTR(&list_copy_obj) }, @@ -483,7 +483,7 @@ STATIC const mp_rom_map_elem_t list_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_sort), MP_ROM_PTR(&list_sort_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(list_locals_dict, list_locals_dict_table); +static MP_DEFINE_CONST_DICT(list_locals_dict, list_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_list, @@ -507,7 +507,7 @@ void mp_obj_list_init(mp_obj_list_t *o, size_t n) { mp_seq_clear(o->items, n, o->alloc, sizeof(*o->items)); } -STATIC mp_obj_list_t *list_new(size_t n) { +static mp_obj_list_t *list_new(size_t n) { mp_obj_list_t *o = m_new_obj(mp_obj_list_t); mp_obj_list_init(o, n); return o; @@ -554,7 +554,7 @@ typedef struct _mp_obj_list_it_t { size_t cur; } mp_obj_list_it_t; -STATIC mp_obj_t list_it_iternext(mp_obj_t self_in) { +static mp_obj_t list_it_iternext(mp_obj_t self_in) { mp_obj_list_it_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_list_t *list = MP_OBJ_TO_PTR(self->list); if (self->cur < list->len) { diff --git a/py/objmap.c b/py/objmap.c index e7e594cd2c54b..1911a7510abe8 100644 --- a/py/objmap.c +++ b/py/objmap.c @@ -36,9 +36,9 @@ 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, size_t n_kw, const mp_obj_t *args) { +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 = mp_obj_malloc_var(mp_obj_map_t, mp_obj_t, n_args - 1, type); + mp_obj_map_t *o = mp_obj_malloc_var(mp_obj_map_t, iters, mp_obj_t, n_args - 1, type); o->n_iters = n_args - 1; o->fun = args[0]; for (size_t i = 0; i < n_args - 1; i++) { @@ -47,7 +47,7 @@ STATIC mp_obj_t map_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t map_iternext(mp_obj_t self_in) { +static mp_obj_t map_iternext(mp_obj_t self_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_map)); mp_obj_map_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t *nextses = m_new(mp_obj_t, self->n_iters); diff --git a/py/objmodule.c b/py/objmodule.c index d211ccc78d4f4..881ab5e6b254f 100644 --- a/py/objmodule.c +++ b/py/objmodule.c @@ -39,7 +39,7 @@ #include "shared-module/warnings/__init__.h" #endif -STATIC void module_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void module_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_module_t *self = MP_OBJ_TO_PTR(self_in); @@ -62,9 +62,9 @@ STATIC void module_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kin mp_printf(print, "", module_name); } -STATIC void module_attr_try_delegation(mp_obj_t self_in, qstr attr, mp_obj_t *dest); +static void module_attr_try_delegation(mp_obj_t self_in, qstr attr, mp_obj_t *dest); -STATIC void module_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void module_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { mp_obj_module_t *self = MP_OBJ_TO_PTR(self_in); if (dest[0] == MP_OBJ_NULL) { // CIRCUITPY-CHANGE @@ -178,13 +178,13 @@ mp_obj_t mp_obj_new_module(qstr module_name) { /******************************************************************************/ // Global module table and related functions -STATIC const mp_rom_map_elem_t mp_builtin_module_table[] = { +static const mp_rom_map_elem_t mp_builtin_module_table[] = { // built-in modules declared with MP_REGISTER_MODULE() MICROPY_REGISTERED_MODULES }; MP_DEFINE_CONST_MAP(mp_builtin_module_map, mp_builtin_module_table); -STATIC const mp_rom_map_elem_t mp_builtin_extensible_module_table[] = { +static const mp_rom_map_elem_t mp_builtin_extensible_module_table[] = { // built-in modules declared with MP_REGISTER_EXTENSIBLE_MODULE() MICROPY_REGISTERED_EXTENSIBLE_MODULES }; @@ -196,7 +196,7 @@ typedef struct _mp_module_delegation_entry_t { mp_attr_fun_t fun; } mp_module_delegation_entry_t; -STATIC const mp_module_delegation_entry_t mp_builtin_module_delegation_table[] = { +static const mp_module_delegation_entry_t mp_builtin_module_delegation_table[] = { // delegation entries declared with MP_REGISTER_MODULE_DELEGATION() MICROPY_MODULE_DELEGATIONS }; @@ -254,7 +254,7 @@ mp_obj_t mp_module_get_builtin(qstr module_name, bool extensible) { return elem->value; } -STATIC void module_attr_try_delegation(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void module_attr_try_delegation(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { #if MICROPY_MODULE_ATTR_DELEGATION && defined(MICROPY_MODULE_DELEGATIONS) // Delegate lookup to a module's custom attr method. size_t n = MP_ARRAY_SIZE(mp_builtin_module_delegation_table); diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c index bcf7ac7c3c818..b6bbe6e05d8b2 100644 --- a/py/objnamedtuple.c +++ b/py/objnamedtuple.c @@ -45,9 +45,9 @@ size_t mp_obj_namedtuple_find_field(const mp_obj_namedtuple_type_t *type, qstr n return (size_t)-1; } -// CIRCUITPY-CHANGE: differences +// CIRCUITPY-CHANGE: multiple differences #if MICROPY_PY_COLLECTIONS_NAMEDTUPLE__ASDICT -STATIC mp_obj_t namedtuple_asdict(mp_obj_t self_in) { +static mp_obj_t namedtuple_asdict(mp_obj_t self_in) { mp_obj_namedtuple_t *self = MP_OBJ_TO_PTR(self_in); const qstr *fields = ((mp_obj_namedtuple_type_t *)self->tuple.base.type)->fields; mp_obj_t dict = mp_obj_new_dict(self->tuple.len); @@ -125,7 +125,7 @@ mp_obj_t namedtuple_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t // Create a namedtuple with explicit malloc. Calling mp_obj_new_tuple // with num_fields=0 returns a read-only object. - mp_obj_tuple_t *tuple = mp_obj_malloc_var(mp_obj_tuple_t, mp_obj_t, num_fields, type_in); + mp_obj_tuple_t *tuple = mp_obj_malloc_var(mp_obj_tuple_t, items, mp_obj_t, num_fields, type_in); tuple->len = num_fields; // Copy the positional args into the first slots of the namedtuple @@ -166,7 +166,7 @@ mp_obj_namedtuple_type_t *mp_obj_new_namedtuple_base(size_t n_fields, mp_obj_t * return o; } -STATIC mp_obj_t mp_obj_new_namedtuple_type(qstr name, size_t n_fields, mp_obj_t *fields) { +static mp_obj_t mp_obj_new_namedtuple_type(qstr name, size_t n_fields, mp_obj_t *fields) { mp_obj_namedtuple_type_t *o = mp_obj_new_namedtuple_base(n_fields, fields); mp_obj_type_t *type = (mp_obj_type_t *)&o->base; type->base.type = &mp_type_type; @@ -183,7 +183,7 @@ STATIC mp_obj_t mp_obj_new_namedtuple_type(qstr name, size_t n_fields, mp_obj_t return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t new_namedtuple_type(mp_obj_t name_in, mp_obj_t fields_in) { +static mp_obj_t new_namedtuple_type(mp_obj_t name_in, mp_obj_t fields_in) { qstr name = mp_obj_str_get_qstr(name_in); size_t n_fields; mp_obj_t *fields; diff --git a/py/objnone.c b/py/objnone.c index 5b25cd38c46d5..a8ce8ebfedf82 100644 --- a/py/objnone.c +++ b/py/objnone.c @@ -34,7 +34,7 @@ typedef struct _mp_obj_none_t { } mp_obj_none_t; #endif -STATIC void none_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void none_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)self_in; if (MICROPY_PY_JSON && kind == PRINT_JSON) { mp_print_str(print, "null"); diff --git a/py/objobject.c b/py/objobject.c index 4806c2522d993..ee7a00ee9a790 100644 --- a/py/objobject.c +++ b/py/objobject.c @@ -33,7 +33,7 @@ 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, size_t n_kw, const mp_obj_t *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, n_kw, 0, 0, false); mp_obj_object_t *o = mp_obj_malloc(mp_obj_object_t, type); @@ -41,13 +41,13 @@ STATIC mp_obj_t object_make_new(const mp_obj_type_t *type, size_t n_args, size_t } #if MICROPY_CPYTHON_COMPAT -STATIC mp_obj_t object___init__(mp_obj_t self) { +static mp_obj_t object___init__(mp_obj_t self) { (void)self; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(object___init___obj, object___init__); +static MP_DEFINE_CONST_FUN_OBJ_1(object___init___obj, object___init__); -STATIC mp_obj_t object___new__(mp_obj_t cls) { +static mp_obj_t object___new__(mp_obj_t cls) { if (!mp_obj_is_type(cls, &mp_type_type) || !mp_obj_is_instance_type((mp_obj_type_t *)MP_OBJ_TO_PTR(cls))) { // CIRCUITPY-CHANGE: better error mp_raise_TypeError(MP_ERROR_TEXT("__new__ arg must be a user-type")); @@ -59,11 +59,11 @@ STATIC mp_obj_t object___new__(mp_obj_t cls) { const mp_obj_type_t *native_base; return MP_OBJ_FROM_PTR(mp_obj_new_instance(MP_OBJ_TO_PTR(cls), &native_base)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(object___new___fun_obj, object___new__); -STATIC MP_DEFINE_CONST_STATICMETHOD_OBJ(object___new___obj, MP_ROM_PTR(&object___new___fun_obj)); +static MP_DEFINE_CONST_FUN_OBJ_1(object___new___fun_obj, object___new__); +static MP_DEFINE_CONST_STATICMETHOD_OBJ(object___new___obj, MP_ROM_PTR(&object___new___fun_obj)); #if MICROPY_PY_DELATTR_SETATTR -STATIC mp_obj_t object___setattr__(mp_obj_t self_in, mp_obj_t attr, mp_obj_t value) { +static mp_obj_t object___setattr__(mp_obj_t self_in, mp_obj_t attr, mp_obj_t value) { if (!mp_obj_is_instance_type(mp_obj_get_type(self_in))) { mp_raise_TypeError(MP_ERROR_TEXT("arg must be user-type")); } @@ -76,9 +76,9 @@ STATIC mp_obj_t object___setattr__(mp_obj_t self_in, mp_obj_t attr, mp_obj_t val mp_map_lookup(&self->members, attr, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = value; return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_3(object___setattr___obj, object___setattr__); +static MP_DEFINE_CONST_FUN_OBJ_3(object___setattr___obj, object___setattr__); -STATIC mp_obj_t object___delattr__(mp_obj_t self_in, mp_obj_t attr) { +static mp_obj_t object___delattr__(mp_obj_t self_in, mp_obj_t attr) { if (!mp_obj_is_instance_type(mp_obj_get_type(self_in))) { mp_raise_TypeError(MP_ERROR_TEXT("arg must be user-type")); } @@ -93,10 +93,10 @@ STATIC mp_obj_t object___delattr__(mp_obj_t self_in, mp_obj_t attr) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(object___delattr___obj, object___delattr__); +static MP_DEFINE_CONST_FUN_OBJ_2(object___delattr___obj, object___delattr__); #endif -STATIC const mp_rom_map_elem_t object_locals_dict_table[] = { +static const mp_rom_map_elem_t object_locals_dict_table[] = { #if MICROPY_CPYTHON_COMPAT { MP_ROM_QSTR(MP_QSTR___init__), MP_ROM_PTR(&object___init___obj) }, #endif @@ -109,7 +109,7 @@ STATIC const mp_rom_map_elem_t object_locals_dict_table[] = { #endif }; -STATIC MP_DEFINE_CONST_DICT(object_locals_dict, object_locals_dict_table); +static MP_DEFINE_CONST_DICT(object_locals_dict, object_locals_dict_table); #endif #if MICROPY_CPYTHON_COMPAT diff --git a/py/objpolyiter.c b/py/objpolyiter.c index 78b600abacdcd..65c1f182ec8ec 100644 --- a/py/objpolyiter.c +++ b/py/objpolyiter.c @@ -39,7 +39,7 @@ typedef struct _mp_obj_polymorph_iter_t { mp_fun_1_t iternext; } mp_obj_polymorph_iter_t; -STATIC mp_obj_t polymorph_it_iternext(mp_obj_t self_in) { +static mp_obj_t polymorph_it_iternext(mp_obj_t self_in) { mp_obj_polymorph_iter_t *self = MP_OBJ_TO_PTR(self_in); // Redirect call to object instance's iternext method return self->iternext(self_in); @@ -64,17 +64,17 @@ typedef struct _mp_obj_polymorph_iter_with_finaliser_t { mp_fun_1_t finaliser; } mp_obj_polymorph_with_finaliser_iter_t; -STATIC mp_obj_t mp_obj_polymorph_iter_del(mp_obj_t self_in) { +static mp_obj_t mp_obj_polymorph_iter_del(mp_obj_t self_in) { mp_obj_polymorph_with_finaliser_iter_t *self = MP_OBJ_TO_PTR(self_in); // Redirect call to object instance's finaliser method return self->finaliser(self_in); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_obj_polymorph_iter_del_obj, mp_obj_polymorph_iter_del); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_obj_polymorph_iter_del_obj, mp_obj_polymorph_iter_del); -STATIC const mp_rom_map_elem_t mp_obj_polymorph_iter_locals_dict_table[] = { +static const mp_rom_map_elem_t mp_obj_polymorph_iter_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___del__), MP_ROM_PTR(&mp_obj_polymorph_iter_del_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_obj_polymorph_iter_locals_dict, mp_obj_polymorph_iter_locals_dict_table); +static MP_DEFINE_CONST_DICT(mp_obj_polymorph_iter_locals_dict, mp_obj_polymorph_iter_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_polymorph_iter_with_finaliser, diff --git a/py/objproperty.c b/py/objproperty.c index 824f82ea802e6..a3a13a71bb3a3 100644 --- a/py/objproperty.c +++ b/py/objproperty.c @@ -37,7 +37,7 @@ #if MICROPY_PY_BUILTINS_PROPERTY -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) { +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} }, @@ -56,40 +56,40 @@ STATIC mp_obj_t property_make_new(const mp_obj_type_t *type, size_t n_args, size return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t property_getter(mp_obj_t self_in, mp_obj_t getter) { +static mp_obj_t property_getter(mp_obj_t self_in, mp_obj_t getter) { mp_obj_property_t *p2 = m_new_obj(mp_obj_property_t); *p2 = *(mp_obj_property_t *)MP_OBJ_TO_PTR(self_in); p2->proxy[0] = getter; return MP_OBJ_FROM_PTR(p2); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(property_getter_obj, property_getter); +static MP_DEFINE_CONST_FUN_OBJ_2(property_getter_obj, property_getter); -STATIC mp_obj_t property_setter(mp_obj_t self_in, mp_obj_t setter) { +static mp_obj_t property_setter(mp_obj_t self_in, mp_obj_t setter) { mp_obj_property_t *p2 = m_new_obj(mp_obj_property_t); *p2 = *(mp_obj_property_t *)MP_OBJ_TO_PTR(self_in); p2->proxy[1] = setter; return MP_OBJ_FROM_PTR(p2); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(property_setter_obj, property_setter); +static MP_DEFINE_CONST_FUN_OBJ_2(property_setter_obj, property_setter); -STATIC mp_obj_t property_deleter(mp_obj_t self_in, mp_obj_t deleter) { +static mp_obj_t property_deleter(mp_obj_t self_in, mp_obj_t deleter) { mp_obj_property_t *p2 = m_new_obj(mp_obj_property_t); *p2 = *(mp_obj_property_t *)MP_OBJ_TO_PTR(self_in); p2->proxy[2] = deleter; return MP_OBJ_FROM_PTR(p2); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(property_deleter_obj, property_deleter); +static MP_DEFINE_CONST_FUN_OBJ_2(property_deleter_obj, property_deleter); -STATIC const mp_rom_map_elem_t property_locals_dict_table[] = { +static const mp_rom_map_elem_t property_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_getter), MP_ROM_PTR(&property_getter_obj) }, { MP_ROM_QSTR(MP_QSTR_setter), MP_ROM_PTR(&property_setter_obj) }, { MP_ROM_QSTR(MP_QSTR_deleter), MP_ROM_PTR(&property_deleter_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(property_locals_dict, property_locals_dict_table); +static MP_DEFINE_CONST_DICT(property_locals_dict, property_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_property, diff --git a/py/objproperty.h b/py/objproperty.h index 0098bfd0b1118..eb0f65d3dbebf 100644 --- a/py/objproperty.h +++ b/py/objproperty.h @@ -1,30 +1,10 @@ -/* - * This file is part of the Micro Python project, http://micropython.org/ - * - * The MIT License (MIT) - * - * SPDX-FileCopyrightText: Copyright (c) 2013, 2014 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 MICROPY_INCLUDED_PY_OBJPROPERTY_H -#define MICROPY_INCLUDED_PY_OBJPROPERTY_H +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2016 Scott Shawcroft for Adafruit Industries +// +// SPDX-License-Identifier: MIT + +#pragma once #include "py/obj.h" @@ -64,5 +44,3 @@ typedef struct _mp_obj_property_t mp_obj_property_getset_t; #endif #endif // MICROPY_PY_BUILTINS_PROPERTY - -#endif // MICROPY_INCLUDED_PY_OBJPROPERTY_H diff --git a/py/objrange.c b/py/objrange.c index c5a6d1ff6e820..8793040eab095 100644 --- a/py/objrange.c +++ b/py/objrange.c @@ -39,7 +39,7 @@ typedef struct _mp_obj_range_it_t { mp_int_t step; } mp_obj_range_it_t; -STATIC mp_obj_t range_it_iternext(mp_obj_t o_in) { +static mp_obj_t range_it_iternext(mp_obj_t o_in) { mp_obj_range_it_t *o = MP_OBJ_TO_PTR(o_in); if ((o->step > 0 && o->cur < o->stop) || (o->step < 0 && o->cur > o->stop)) { mp_obj_t o_out = MP_OBJ_NEW_SMALL_INT(o->cur); @@ -50,14 +50,14 @@ STATIC mp_obj_t range_it_iternext(mp_obj_t o_in) { } } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_range_it, MP_QSTR_iterator, MP_TYPE_FLAG_ITER_IS_ITERNEXT, iter, range_it_iternext ); -STATIC mp_obj_t mp_obj_new_range_iterator(mp_int_t cur, mp_int_t stop, mp_int_t step, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t mp_obj_new_range_iterator(mp_int_t cur, mp_int_t stop, mp_int_t step, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(mp_obj_range_it_t) <= sizeof(mp_obj_iter_buf_t)); mp_obj_range_it_t *o = (mp_obj_range_it_t *)iter_buf; o->base.type = &mp_type_range_it; @@ -78,7 +78,7 @@ typedef struct _mp_obj_range_t { mp_int_t step; } mp_obj_range_t; -STATIC void range_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void range_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_range_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "range(" INT_FMT ", " INT_FMT "", self->start, self->stop); @@ -89,7 +89,7 @@ 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, size_t n_kw, const mp_obj_t *args) { +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 = mp_obj_malloc(mp_obj_range_t, type); @@ -113,7 +113,7 @@ STATIC mp_obj_t range_make_new(const mp_obj_type_t *type, size_t n_args, size_t return MP_OBJ_FROM_PTR(o); } -STATIC mp_int_t range_len(mp_obj_range_t *self) { +static mp_int_t range_len(mp_obj_range_t *self) { // When computing length, need to take into account step!=1 and step<0. mp_int_t len = self->stop - self->start + self->step; if (self->step > 0) { @@ -128,7 +128,7 @@ STATIC mp_int_t range_len(mp_obj_range_t *self) { return len; } -STATIC mp_obj_t range_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t range_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_range_t *self = MP_OBJ_TO_PTR(self_in); mp_int_t len = range_len(self); switch (op) { @@ -142,7 +142,7 @@ STATIC mp_obj_t range_unary_op(mp_unary_op_t op, mp_obj_t self_in) { } #if MICROPY_PY_BUILTINS_RANGE_BINOP -STATIC mp_obj_t range_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t range_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { if (!mp_obj_is_type(rhs_in, &mp_type_range) || op != MP_BINARY_OP_EQUAL) { return MP_OBJ_NULL; // op not supported } @@ -159,7 +159,7 @@ STATIC mp_obj_t range_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs } #endif -STATIC mp_obj_t range_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { +static mp_obj_t range_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { if (value == MP_OBJ_SENTINEL) { // load mp_obj_range_t *self = MP_OBJ_TO_PTR(self_in); @@ -186,14 +186,14 @@ STATIC mp_obj_t range_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } } -STATIC mp_obj_t range_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t range_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { mp_obj_range_t *o = MP_OBJ_TO_PTR(o_in); return mp_obj_new_range_iterator(o->start, o->stop, o->step, iter_buf); } #if MICROPY_PY_BUILTINS_RANGE_ATTRS -STATIC void range_attr(mp_obj_t o_in, qstr attr, mp_obj_t *dest) { +static void range_attr(mp_obj_t o_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { // not load attribute return; diff --git a/py/objreversed.c b/py/objreversed.c index c66698f028adf..c580ee286b76d 100644 --- a/py/objreversed.c +++ b/py/objreversed.c @@ -37,7 +37,7 @@ 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, size_t n_kw, const mp_obj_t *args) { +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 @@ -54,7 +54,7 @@ STATIC mp_obj_t reversed_make_new(const mp_obj_type_t *type, size_t n_args, size return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t reversed_iternext(mp_obj_t self_in) { +static mp_obj_t reversed_iternext(mp_obj_t self_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_reversed)); mp_obj_reversed_t *self = MP_OBJ_TO_PTR(self_in); diff --git a/py/objset.c b/py/objset.c index 1906163e2d17a..49e6beec11ec3 100644 --- a/py/objset.c +++ b/py/objset.c @@ -45,7 +45,7 @@ typedef struct _mp_obj_set_it_t { size_t cur; } mp_obj_set_it_t; -STATIC bool is_set_or_frozenset(mp_obj_t o) { +static bool is_set_or_frozenset(mp_obj_t o) { return mp_obj_is_type(o, &mp_type_set) #if MICROPY_PY_BUILTINS_FROZENSET || mp_obj_is_type(o, &mp_type_frozenset) @@ -60,7 +60,7 @@ STATIC bool is_set_or_frozenset(mp_obj_t o) { // set or frozenset for methods that operate on both of these types. #define check_set_or_frozenset(o) mp_check_self(is_set_or_frozenset(o)) -STATIC void set_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void set_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); #if MICROPY_PY_BUILTINS_FROZENSET @@ -99,7 +99,7 @@ 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, size_t n_kw, const mp_obj_t *args) { +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) { @@ -127,7 +127,7 @@ STATIC mp_obj_t set_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ } } -STATIC mp_obj_t set_it_iternext(mp_obj_t self_in) { +static mp_obj_t set_it_iternext(mp_obj_t self_in) { mp_obj_set_it_t *self = MP_OBJ_TO_PTR(self_in); size_t max = self->set->set.alloc; mp_set_t *set = &self->set->set; @@ -142,7 +142,7 @@ STATIC mp_obj_t set_it_iternext(mp_obj_t self_in) { return MP_OBJ_STOP_ITERATION; } -STATIC mp_obj_t set_getiter(mp_obj_t set_in, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t set_getiter(mp_obj_t set_in, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(mp_obj_set_it_t) <= sizeof(mp_obj_iter_buf_t)); mp_obj_set_it_t *o = (mp_obj_set_it_t *)iter_buf; o->base.type = &mp_type_polymorph_iter; @@ -155,23 +155,23 @@ STATIC mp_obj_t set_getiter(mp_obj_t set_in, mp_obj_iter_buf_t *iter_buf) { /******************************************************************************/ /* set methods */ -STATIC mp_obj_t set_add(mp_obj_t self_in, mp_obj_t item) { +static mp_obj_t set_add(mp_obj_t self_in, mp_obj_t item) { check_set(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_add_obj, set_add); +static MP_DEFINE_CONST_FUN_OBJ_2(set_add_obj, set_add); -STATIC mp_obj_t set_clear(mp_obj_t self_in) { +static mp_obj_t set_clear(mp_obj_t self_in) { check_set(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); mp_set_clear(&self->set); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(set_clear_obj, set_clear); +static MP_DEFINE_CONST_FUN_OBJ_1(set_clear_obj, set_clear); -STATIC mp_obj_t set_copy(mp_obj_t self_in) { +static mp_obj_t set_copy(mp_obj_t self_in) { check_set_or_frozenset(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_set_t *other = mp_obj_malloc(mp_obj_set_t, self->base.type); @@ -180,17 +180,17 @@ STATIC mp_obj_t set_copy(mp_obj_t self_in) { memcpy(other->set.table, self->set.table, self->set.alloc * sizeof(mp_obj_t)); return MP_OBJ_FROM_PTR(other); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(set_copy_obj, set_copy); +static MP_DEFINE_CONST_FUN_OBJ_1(set_copy_obj, set_copy); -STATIC mp_obj_t set_discard(mp_obj_t self_in, mp_obj_t item) { +static mp_obj_t set_discard(mp_obj_t self_in, mp_obj_t item) { check_set(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); mp_set_lookup(&self->set, item, MP_MAP_LOOKUP_REMOVE_IF_FOUND); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_discard_obj, set_discard); +static MP_DEFINE_CONST_FUN_OBJ_2(set_discard_obj, set_discard); -STATIC mp_obj_t set_diff_int(size_t n_args, const mp_obj_t *args, bool update) { +static mp_obj_t set_diff_int(size_t n_args, const mp_obj_t *args, bool update) { mp_obj_t self; if (update) { check_set(args[0]); @@ -216,18 +216,18 @@ STATIC mp_obj_t set_diff_int(size_t n_args, const mp_obj_t *args, bool update) { return self; } -STATIC mp_obj_t set_diff(size_t n_args, const mp_obj_t *args) { +static mp_obj_t set_diff(size_t n_args, const mp_obj_t *args) { return set_diff_int(n_args, args, false); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(set_diff_obj, 1, set_diff); +static MP_DEFINE_CONST_FUN_OBJ_VAR(set_diff_obj, 1, set_diff); -STATIC mp_obj_t set_diff_update(size_t n_args, const mp_obj_t *args) { +static mp_obj_t set_diff_update(size_t n_args, const mp_obj_t *args) { set_diff_int(n_args, args, true); return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(set_diff_update_obj, 1, set_diff_update); +static MP_DEFINE_CONST_FUN_OBJ_VAR(set_diff_update_obj, 1, set_diff_update); -STATIC mp_obj_t set_intersect_int(mp_obj_t self_in, mp_obj_t other, bool update) { +static mp_obj_t set_intersect_int(mp_obj_t self_in, mp_obj_t other, bool update) { if (update) { check_set(self_in); } else { @@ -259,17 +259,17 @@ STATIC mp_obj_t set_intersect_int(mp_obj_t self_in, mp_obj_t other, bool update) return update ? mp_const_none : MP_OBJ_FROM_PTR(out); } -STATIC mp_obj_t set_intersect(mp_obj_t self_in, mp_obj_t other) { +static mp_obj_t set_intersect(mp_obj_t self_in, mp_obj_t other) { return set_intersect_int(self_in, other, false); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_intersect_obj, set_intersect); +static MP_DEFINE_CONST_FUN_OBJ_2(set_intersect_obj, set_intersect); -STATIC mp_obj_t set_intersect_update(mp_obj_t self_in, mp_obj_t other) { +static mp_obj_t set_intersect_update(mp_obj_t self_in, mp_obj_t other) { return set_intersect_int(self_in, other, true); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_intersect_update_obj, set_intersect_update); +static MP_DEFINE_CONST_FUN_OBJ_2(set_intersect_update_obj, set_intersect_update); -STATIC mp_obj_t set_isdisjoint(mp_obj_t self_in, mp_obj_t other) { +static mp_obj_t set_isdisjoint(mp_obj_t self_in, mp_obj_t other) { check_set_or_frozenset(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); @@ -283,9 +283,9 @@ STATIC mp_obj_t set_isdisjoint(mp_obj_t self_in, mp_obj_t other) { } return mp_const_true; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_isdisjoint_obj, set_isdisjoint); +static MP_DEFINE_CONST_FUN_OBJ_2(set_isdisjoint_obj, set_isdisjoint); -STATIC mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool proper) { +static mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool proper) { mp_obj_set_t *self; bool cleanup_self = false; if (is_set_or_frozenset(self_in)) { @@ -327,25 +327,25 @@ STATIC mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool return out; } -STATIC mp_obj_t set_issubset(mp_obj_t self_in, mp_obj_t other_in) { +static mp_obj_t set_issubset(mp_obj_t self_in, mp_obj_t other_in) { return set_issubset_internal(self_in, other_in, false); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_issubset_obj, set_issubset); +static MP_DEFINE_CONST_FUN_OBJ_2(set_issubset_obj, set_issubset); -STATIC mp_obj_t set_issubset_proper(mp_obj_t self_in, mp_obj_t other_in) { +static mp_obj_t set_issubset_proper(mp_obj_t self_in, mp_obj_t other_in) { return set_issubset_internal(self_in, other_in, true); } -STATIC mp_obj_t set_issuperset(mp_obj_t self_in, mp_obj_t other_in) { +static mp_obj_t set_issuperset(mp_obj_t self_in, mp_obj_t other_in) { return set_issubset_internal(other_in, self_in, false); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_issuperset_obj, set_issuperset); +static MP_DEFINE_CONST_FUN_OBJ_2(set_issuperset_obj, set_issuperset); -STATIC mp_obj_t set_issuperset_proper(mp_obj_t self_in, mp_obj_t other_in) { +static mp_obj_t set_issuperset_proper(mp_obj_t self_in, mp_obj_t other_in) { return set_issubset_internal(other_in, self_in, true); } -STATIC mp_obj_t set_equal(mp_obj_t self_in, mp_obj_t other_in) { +static mp_obj_t set_equal(mp_obj_t self_in, mp_obj_t other_in) { assert(is_set_or_frozenset(other_in)); check_set_or_frozenset(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); @@ -356,7 +356,7 @@ STATIC mp_obj_t set_equal(mp_obj_t self_in, mp_obj_t other_in) { return set_issubset(self_in, other_in); } -STATIC mp_obj_t set_pop(mp_obj_t self_in) { +static mp_obj_t set_pop(mp_obj_t self_in) { check_set(self_in); mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t obj = mp_set_remove_first(&self->set); @@ -366,9 +366,9 @@ STATIC mp_obj_t set_pop(mp_obj_t self_in) { } return obj; } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(set_pop_obj, set_pop); +static MP_DEFINE_CONST_FUN_OBJ_1(set_pop_obj, set_pop); -STATIC mp_obj_t set_remove(mp_obj_t self_in, mp_obj_t item) { +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) { @@ -376,9 +376,9 @@ STATIC mp_obj_t set_remove(mp_obj_t self_in, mp_obj_t item) { } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_remove_obj, set_remove); +static MP_DEFINE_CONST_FUN_OBJ_2(set_remove_obj, set_remove); -STATIC mp_obj_t set_symmetric_difference_update(mp_obj_t self_in, mp_obj_t other_in) { +static mp_obj_t set_symmetric_difference_update(mp_obj_t self_in, mp_obj_t other_in) { check_set_or_frozenset(self_in); // can be frozenset due to call from set_symmetric_difference mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t iter = mp_getiter(other_in, NULL); @@ -388,16 +388,16 @@ STATIC mp_obj_t set_symmetric_difference_update(mp_obj_t self_in, mp_obj_t other } return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_symmetric_difference_update_obj, set_symmetric_difference_update); +static MP_DEFINE_CONST_FUN_OBJ_2(set_symmetric_difference_update_obj, set_symmetric_difference_update); -STATIC mp_obj_t set_symmetric_difference(mp_obj_t self_in, mp_obj_t other_in) { +static mp_obj_t set_symmetric_difference(mp_obj_t self_in, mp_obj_t other_in) { mp_obj_t self_out = set_copy(self_in); set_symmetric_difference_update(self_out, other_in); return self_out; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_symmetric_difference_obj, set_symmetric_difference); +static MP_DEFINE_CONST_FUN_OBJ_2(set_symmetric_difference_obj, set_symmetric_difference); -STATIC void set_update_int(mp_obj_set_t *self, mp_obj_t other_in) { +static void set_update_int(mp_obj_set_t *self, mp_obj_t other_in) { mp_obj_t iter = mp_getiter(other_in, NULL); mp_obj_t next; while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) { @@ -405,7 +405,7 @@ STATIC void set_update_int(mp_obj_set_t *self, mp_obj_t other_in) { } } -STATIC mp_obj_t set_update(size_t n_args, const mp_obj_t *args) { +static mp_obj_t set_update(size_t n_args, const mp_obj_t *args) { check_set(args[0]); for (size_t i = 1; i < n_args; i++) { set_update_int(MP_OBJ_TO_PTR(args[0]), args[i]); @@ -413,17 +413,17 @@ STATIC mp_obj_t set_update(size_t n_args, const mp_obj_t *args) { return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR(set_update_obj, 1, set_update); +static MP_DEFINE_CONST_FUN_OBJ_VAR(set_update_obj, 1, set_update); -STATIC mp_obj_t set_union(mp_obj_t self_in, mp_obj_t other_in) { +static mp_obj_t set_union(mp_obj_t self_in, mp_obj_t other_in) { check_set_or_frozenset(self_in); mp_obj_t self = set_copy(self_in); set_update_int(MP_OBJ_TO_PTR(self), other_in); return self; } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_union_obj, set_union); +static MP_DEFINE_CONST_FUN_OBJ_2(set_union_obj, set_union); -STATIC mp_obj_t set_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t set_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_set_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { case MP_UNARY_OP_BOOL: @@ -454,7 +454,7 @@ STATIC mp_obj_t set_unary_op(mp_unary_op_t op, mp_obj_t self_in) { } } -STATIC mp_obj_t set_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) { +static mp_obj_t set_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) { mp_obj_t args[] = {lhs, rhs}; #if MICROPY_PY_BUILTINS_FROZENSET bool update = mp_obj_is_type(lhs, &mp_type_set); @@ -520,7 +520,7 @@ STATIC mp_obj_t set_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) { /******************************************************************************/ /* set constructors & public C API */ -STATIC const mp_rom_map_elem_t set_locals_dict_table[] = { +static const mp_rom_map_elem_t set_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_add), MP_ROM_PTR(&set_add_obj) }, { MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&set_clear_obj) }, { MP_ROM_QSTR(MP_QSTR_copy), MP_ROM_PTR(&set_copy_obj) }, @@ -540,7 +540,7 @@ STATIC const mp_rom_map_elem_t set_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&set_update_obj) }, { MP_ROM_QSTR(MP_QSTR___contains__), MP_ROM_PTR(&mp_op_contains_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(set_locals_dict, set_locals_dict_table); +static MP_DEFINE_CONST_DICT(set_locals_dict, set_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_set, @@ -555,7 +555,7 @@ MP_DEFINE_CONST_OBJ_TYPE( ); #if MICROPY_PY_BUILTINS_FROZENSET -STATIC const mp_rom_map_elem_t frozenset_locals_dict_table[] = { +static const mp_rom_map_elem_t frozenset_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_copy), MP_ROM_PTR(&set_copy_obj) }, { MP_ROM_QSTR(MP_QSTR_difference), MP_ROM_PTR(&set_diff_obj) }, { MP_ROM_QSTR(MP_QSTR_intersection), MP_ROM_PTR(&set_intersect_obj) }, @@ -566,7 +566,7 @@ STATIC const mp_rom_map_elem_t frozenset_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_union), MP_ROM_PTR(&set_union_obj) }, { MP_ROM_QSTR(MP_QSTR___contains__), MP_ROM_PTR(&mp_op_contains_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(frozenset_locals_dict, frozenset_locals_dict_table); +static MP_DEFINE_CONST_DICT(frozenset_locals_dict, frozenset_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_frozenset, diff --git a/py/objsingleton.c b/py/objsingleton.c index 6537676c52329..c1f102c94c014 100644 --- a/py/objsingleton.c +++ b/py/objsingleton.c @@ -37,7 +37,7 @@ typedef struct _mp_obj_singleton_t { qstr name; } mp_obj_singleton_t; -STATIC void singleton_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void singleton_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_singleton_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "%q", self->name); diff --git a/py/objslice.c b/py/objslice.c index abc1e87549955..5b21162d7487c 100644 --- a/py/objslice.c +++ b/py/objslice.c @@ -35,7 +35,7 @@ #if MICROPY_PY_BUILTINS_SLICE -STATIC void slice_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void slice_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_slice_t *o = MP_OBJ_TO_PTR(o_in); mp_print_str(print, "slice("); @@ -47,14 +47,14 @@ STATIC void slice_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t mp_print_str(print, ")"); } -STATIC mp_obj_t slice_unary_op(mp_unary_op_t op, mp_obj_t o_in) { +static mp_obj_t slice_unary_op(mp_unary_op_t op, mp_obj_t o_in) { // Needed to explicitly opt out of default __hash__. // REVISIT: CPython implements comparison operators for slice. return MP_OBJ_NULL; } #if MICROPY_PY_BUILTINS_SLICE_INDICES -STATIC mp_obj_t slice_indices(mp_obj_t self_in, mp_obj_t length_obj) { +static mp_obj_t slice_indices(mp_obj_t self_in, mp_obj_t length_obj) { mp_int_t length = mp_obj_get_int(length_obj); mp_bound_slice_t bound_indices; mp_obj_slice_indices(self_in, length, &bound_indices); @@ -66,11 +66,11 @@ STATIC mp_obj_t slice_indices(mp_obj_t self_in, mp_obj_t length_obj) { }; return mp_obj_new_tuple(3, results); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(slice_indices_obj, slice_indices); +static MP_DEFINE_CONST_FUN_OBJ_2(slice_indices_obj, slice_indices); #endif #if MICROPY_PY_BUILTINS_SLICE_ATTRS -STATIC void slice_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void slice_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { // not load attribute return; @@ -94,7 +94,7 @@ STATIC void slice_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { // CIRCUITPY-CHANGE #if MICROPY_PY_BUILTINS_SLICE_ATTRS -STATIC mp_obj_t slice_make_new(const mp_obj_type_t *type, +static mp_obj_t slice_make_new(const mp_obj_type_t *type, 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")); @@ -121,10 +121,10 @@ STATIC mp_obj_t slice_make_new(const mp_obj_type_t *type, #endif #if MICROPY_PY_BUILTINS_SLICE_INDICES && !MICROPY_PY_BUILTINS_SLICE_ATTRS -STATIC const mp_rom_map_elem_t slice_locals_dict_table[] = { +static const mp_rom_map_elem_t slice_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_indices), MP_ROM_PTR(&slice_indices_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(slice_locals_dict, slice_locals_dict_table); +static MP_DEFINE_CONST_DICT(slice_locals_dict, slice_locals_dict_table); #endif #if MICROPY_PY_BUILTINS_SLICE_ATTRS diff --git a/py/objstr.c b/py/objstr.c index 5794765e7daca..0b2517197a0bd 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -42,15 +42,15 @@ const char nibble_to_hex_lower[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8 'a', 'b', 'c', 'd', 'e', 'f'}; #if MICROPY_PY_BUILTINS_STR_OP_MODULO -STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict); +static mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict); #endif -STATIC mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); -STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in); +static mp_obj_t mp_obj_new_bytes_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); +static NORETURN void bad_implicit_conversion(mp_obj_t self_in); -STATIC mp_obj_t mp_obj_new_str_type_from_vstr(const mp_obj_type_t *type, vstr_t *vstr); +static mp_obj_t mp_obj_new_str_type_from_vstr(const mp_obj_type_t *type, vstr_t *vstr); -STATIC void str_check_arg_type(const mp_obj_type_t *self_type, const mp_obj_t arg) { +static void str_check_arg_type(const mp_obj_type_t *self_type, const mp_obj_t arg) { // String operations generally need the args type to match the object they're called on, // e.g. str.find(str), byte.startswith(byte) // with the exception that bytes may be used for bytearray and vice versa. @@ -70,7 +70,7 @@ STATIC void str_check_arg_type(const mp_obj_type_t *self_type, const mp_obj_t ar } } -STATIC void check_is_str_or_bytes(mp_obj_t self_in) { +static void check_is_str_or_bytes(mp_obj_t self_in) { mp_check_self(mp_obj_is_str_or_bytes(self_in)); } @@ -142,7 +142,7 @@ void mp_str_print_json(const mp_print_t *print, const byte *str_data, size_t str } #endif -STATIC void str_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void str_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { GET_STR_DATA_LEN(self_in, str_data, str_len); #if MICROPY_PY_JSON if (kind == PRINT_JSON) { @@ -219,7 +219,7 @@ mp_obj_t mp_obj_str_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ } } -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) { +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 @@ -475,7 +475,7 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s #endif // This is used for both bytes and 8-bit strings. This is not used for unicode strings. -STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { +static mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { const mp_obj_type_t *type = mp_obj_get_type(self_in); GET_STR_DATA_LEN(self_in, self_data, self_len); if (value == MP_OBJ_SENTINEL) { @@ -501,7 +501,7 @@ STATIC mp_obj_t bytes_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } } -STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) { check_is_str_or_bytes(self_in); const mp_obj_type_t *self_type = mp_obj_get_type(self_in); const mp_obj_type_t *ret_type = self_type; @@ -645,7 +645,7 @@ mp_obj_t mp_obj_str_split(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_split_obj, 1, 3, mp_obj_str_split); #if MICROPY_PY_BUILTINS_STR_SPLITLINES -STATIC mp_obj_t str_splitlines(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t str_splitlines(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { enum { ARG_keepends }; static const mp_arg_t allowed_args[] = { { MP_QSTR_keepends, MP_ARG_BOOL, {.u_bool = false} }, @@ -691,7 +691,7 @@ STATIC mp_obj_t str_splitlines(size_t n_args, const mp_obj_t *pos_args, mp_map_t MP_DEFINE_CONST_FUN_OBJ_KW(str_splitlines_obj, 1, str_splitlines); #endif -STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) { if (n_args < 3) { // If we don't have split limit, it doesn't matter from which side // we split. @@ -756,7 +756,7 @@ STATIC mp_obj_t str_rsplit(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_rsplit_obj, 1, 3, str_rsplit); -STATIC mp_obj_t str_finder(size_t n_args, const mp_obj_t *args, int direction, bool is_index) { +static mp_obj_t str_finder(size_t n_args, const mp_obj_t *args, int direction, bool is_index) { const mp_obj_type_t *self_type = mp_obj_get_type(args[0]); check_is_str_or_bytes(args[0]); @@ -799,28 +799,28 @@ STATIC mp_obj_t str_finder(size_t n_args, const mp_obj_t *args, int direction, b } } -STATIC mp_obj_t str_find(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_find(size_t n_args, const mp_obj_t *args) { return str_finder(n_args, args, 1, false); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_find_obj, 2, 4, str_find); -STATIC mp_obj_t str_rfind(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_rfind(size_t n_args, const mp_obj_t *args) { return str_finder(n_args, args, -1, false); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_rfind_obj, 2, 4, str_rfind); -STATIC mp_obj_t str_index(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_index(size_t n_args, const mp_obj_t *args) { return str_finder(n_args, args, 1, true); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_index_obj, 2, 4, str_index); -STATIC mp_obj_t str_rindex(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_rindex(size_t n_args, const mp_obj_t *args) { return str_finder(n_args, args, -1, true); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_rindex_obj, 2, 4, str_rindex); // TODO: (Much) more variety in args -STATIC mp_obj_t str_startswith(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_startswith(size_t n_args, const mp_obj_t *args) { const mp_obj_type_t *self_type = mp_obj_get_type(args[0]); GET_STR_DATA_LEN(args[0], str, str_len); size_t prefix_len; @@ -836,7 +836,7 @@ STATIC mp_obj_t str_startswith(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_startswith_obj, 2, 3, str_startswith); -STATIC mp_obj_t str_endswith(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_endswith(size_t n_args, const mp_obj_t *args) { GET_STR_DATA_LEN(args[0], str, str_len); size_t suffix_len; const char *suffix = mp_obj_str_get_data(args[1], &suffix_len); @@ -853,7 +853,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_endswith_obj, 2, 3, str_endswith); enum { LSTRIP, RSTRIP, STRIP }; -STATIC mp_obj_t str_uni_strip(int type, size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_uni_strip(int type, size_t n_args, const mp_obj_t *args) { check_is_str_or_bytes(args[0]); const mp_obj_type_t *self_type = mp_obj_get_type(args[0]); @@ -922,23 +922,23 @@ STATIC mp_obj_t str_uni_strip(int type, size_t n_args, const mp_obj_t *args) { return mp_obj_new_str_of_type(self_type, orig_str + first_good_char_pos, stripped_len); } -STATIC mp_obj_t str_strip(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_strip(size_t n_args, const mp_obj_t *args) { return str_uni_strip(STRIP, n_args, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_strip_obj, 1, 2, str_strip); -STATIC mp_obj_t str_lstrip(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_lstrip(size_t n_args, const mp_obj_t *args) { return str_uni_strip(LSTRIP, n_args, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_lstrip_obj, 1, 2, str_lstrip); -STATIC mp_obj_t str_rstrip(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_rstrip(size_t n_args, const mp_obj_t *args) { return str_uni_strip(RSTRIP, n_args, args); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_rstrip_obj, 1, 2, str_rstrip); #if MICROPY_PY_BUILTINS_STR_CENTER -STATIC mp_obj_t str_center(mp_obj_t str_in, mp_obj_t width_in) { +static mp_obj_t str_center(mp_obj_t str_in, mp_obj_t width_in) { GET_STR_DATA_LEN(str_in, str, str_len); mp_uint_t width = mp_obj_get_int(width_in); if (str_len >= width) { @@ -957,7 +957,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(str_center_obj, str_center); // Takes an int arg, but only parses unsigned numbers, and only changes // *num if at least one digit was parsed. -STATIC const char *str_to_int(const char *str, const char *top, int *num) { +static const char *str_to_int(const char *str, const char *top, int *num) { if (str < top && '0' <= *str && *str <= '9') { *num = 0; do { @@ -969,19 +969,19 @@ STATIC const char *str_to_int(const char *str, const char *top, int *num) { return str; } -STATIC bool isalignment(char ch) { +static bool isalignment(char ch) { return ch && strchr("<>=^", ch) != NULL; } -STATIC bool istype(char ch) { +static bool istype(char ch) { return ch && strchr("bcdeEfFgGnosxX%", ch) != NULL; } -STATIC bool arg_looks_integer(mp_obj_t arg) { +static bool arg_looks_integer(mp_obj_t arg) { return mp_obj_is_bool(arg) || mp_obj_is_int(arg); } -STATIC bool arg_looks_numeric(mp_obj_t arg) { +static bool arg_looks_numeric(mp_obj_t arg) { return arg_looks_integer(arg) #if MICROPY_PY_BUILTINS_FLOAT || mp_obj_is_float(arg) @@ -990,7 +990,7 @@ STATIC bool arg_looks_numeric(mp_obj_t arg) { } #if MICROPY_PY_BUILTINS_STR_OP_MODULO -STATIC mp_obj_t arg_as_int(mp_obj_t arg) { +static mp_obj_t arg_as_int(mp_obj_t arg) { #if MICROPY_PY_BUILTINS_FLOAT if (mp_obj_is_float(arg)) { return mp_obj_new_int_from_float(mp_obj_float_get(arg)); @@ -1001,7 +1001,7 @@ STATIC mp_obj_t arg_as_int(mp_obj_t arg) { #endif #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE -STATIC NORETURN void terse_str_format_value_error(void) { +static NORETURN void terse_str_format_value_error(void) { mp_raise_ValueError(MP_ERROR_TEXT("bad format string")); } #else @@ -1009,7 +1009,7 @@ STATIC NORETURN void terse_str_format_value_error(void) { #define terse_str_format_value_error() #endif -STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *arg_i, size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { +static vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *arg_i, size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) { vstr_t vstr; mp_print_t print; vstr_init_print(&vstr, 16, &print); @@ -1102,7 +1102,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE terse_str_format_value_error(); #else - // CIRCUITPY-CHANGE + // CIRCUITPY-CHANGE: consolidated message mp_raise_ValueError_varg(MP_ERROR_TEXT("unmatched '%c' in format"), '{'); #endif } @@ -1129,7 +1129,7 @@ STATIC vstr_t mp_obj_str_format_helper(const char *str, const char *top, int *ar } field_name = str_to_int(field_name, field_name_top, &index); if ((uint)index >= n_args - 1) { - // CIRCUITPY-CHANGE + // CIRCUITPY-CHANGE:consolidated message mp_raise_IndexError_varg(MP_ERROR_TEXT("%q index out of range"), MP_QSTR_tuple); } arg = args[index + 1]; @@ -1473,7 +1473,7 @@ mp_obj_t mp_obj_str_format(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs MP_DEFINE_CONST_FUN_OBJ_KW(str_format_obj, 1, mp_obj_str_format); #if MICROPY_PY_BUILTINS_STR_OP_MODULO -STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict) { +static mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_t *args, mp_obj_t dict) { check_is_str_or_bytes(pattern); GET_STR_DATA_LEN(pattern, str, len); @@ -1687,7 +1687,7 @@ STATIC mp_obj_t str_modulo_format(mp_obj_t pattern, size_t n_args, const mp_obj_ // The implementation is optimized, returning the original string if there's // nothing to replace. -STATIC mp_obj_t str_replace(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_replace(size_t n_args, const mp_obj_t *args) { check_is_str_or_bytes(args[0]); mp_int_t max_rep = -1; @@ -1789,7 +1789,7 @@ STATIC mp_obj_t str_replace(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_replace_obj, 3, 4, str_replace); #if MICROPY_PY_BUILTINS_STR_COUNT -STATIC mp_obj_t str_count(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_count(size_t n_args, const mp_obj_t *args) { const mp_obj_type_t *self_type = mp_obj_get_type(args[0]); check_is_str_or_bytes(args[0]); @@ -1832,7 +1832,7 @@ MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(str_count_obj, 2, 4, str_count); #endif #if MICROPY_PY_BUILTINS_STR_PARTITION -STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, int direction) { +static mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, int direction) { check_is_str_or_bytes(self_in); const mp_obj_type_t *self_type = mp_obj_get_type(self_in); str_check_arg_type(self_type, arg); @@ -1878,19 +1878,19 @@ STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, int direction) { return mp_obj_new_tuple(3, result); } -STATIC mp_obj_t str_partition(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t str_partition(mp_obj_t self_in, mp_obj_t arg) { return str_partitioner(self_in, arg, 1); } MP_DEFINE_CONST_FUN_OBJ_2(str_partition_obj, str_partition); -STATIC mp_obj_t str_rpartition(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t str_rpartition(mp_obj_t self_in, mp_obj_t arg) { return str_partitioner(self_in, arg, -1); } MP_DEFINE_CONST_FUN_OBJ_2(str_rpartition_obj, str_rpartition); #endif // Supposedly not too critical operations, so optimize for code size -STATIC mp_obj_t str_caseconv(unichar (*op)(unichar), mp_obj_t self_in) { +static mp_obj_t str_caseconv(unichar (*op)(unichar), mp_obj_t self_in) { GET_STR_DATA_LEN(self_in, self_data, self_len); vstr_t vstr; vstr_init_len(&vstr, self_len); @@ -1901,17 +1901,17 @@ STATIC mp_obj_t str_caseconv(unichar (*op)(unichar), mp_obj_t self_in) { return mp_obj_new_str_type_from_vstr(mp_obj_get_type(self_in), &vstr); } -STATIC mp_obj_t str_lower(mp_obj_t self_in) { +static mp_obj_t str_lower(mp_obj_t self_in) { return str_caseconv(unichar_tolower, self_in); } MP_DEFINE_CONST_FUN_OBJ_1(str_lower_obj, str_lower); -STATIC mp_obj_t str_upper(mp_obj_t self_in) { +static mp_obj_t str_upper(mp_obj_t self_in) { return str_caseconv(unichar_toupper, self_in); } MP_DEFINE_CONST_FUN_OBJ_1(str_upper_obj, str_upper); -STATIC mp_obj_t str_uni_istype(bool (*f)(unichar), mp_obj_t self_in) { +static mp_obj_t str_uni_istype(bool (*f)(unichar), mp_obj_t self_in) { GET_STR_DATA_LEN(self_in, self_data, self_len); if (self_len == 0) { @@ -1944,27 +1944,27 @@ STATIC mp_obj_t str_uni_istype(bool (*f)(unichar), mp_obj_t self_in) { return mp_const_true; } -STATIC mp_obj_t str_isspace(mp_obj_t self_in) { +static mp_obj_t str_isspace(mp_obj_t self_in) { return str_uni_istype(unichar_isspace, self_in); } MP_DEFINE_CONST_FUN_OBJ_1(str_isspace_obj, str_isspace); -STATIC mp_obj_t str_isalpha(mp_obj_t self_in) { +static mp_obj_t str_isalpha(mp_obj_t self_in) { return str_uni_istype(unichar_isalpha, self_in); } MP_DEFINE_CONST_FUN_OBJ_1(str_isalpha_obj, str_isalpha); -STATIC mp_obj_t str_isdigit(mp_obj_t self_in) { +static mp_obj_t str_isdigit(mp_obj_t self_in) { return str_uni_istype(unichar_isdigit, self_in); } MP_DEFINE_CONST_FUN_OBJ_1(str_isdigit_obj, str_isdigit); -STATIC mp_obj_t str_isupper(mp_obj_t self_in) { +static mp_obj_t str_isupper(mp_obj_t self_in) { return str_uni_istype(unichar_isupper, self_in); } MP_DEFINE_CONST_FUN_OBJ_1(str_isupper_obj, str_isupper); -STATIC mp_obj_t str_islower(mp_obj_t self_in) { +static mp_obj_t str_islower(mp_obj_t self_in) { return str_uni_istype(unichar_islower, self_in); } MP_DEFINE_CONST_FUN_OBJ_1(str_islower_obj, str_islower); @@ -1973,7 +1973,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(str_islower_obj, str_islower); // These methods are superfluous in the presence of str() and bytes() // constructors. // TODO: should accept kwargs too -STATIC mp_obj_t bytes_decode(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bytes_decode(size_t n_args, const mp_obj_t *args) { mp_obj_t new_args[2]; if (n_args == 1) { new_args[0] = args[0]; @@ -1986,7 +1986,7 @@ STATIC mp_obj_t bytes_decode(size_t n_args, const mp_obj_t *args) { MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(bytes_decode_obj, 1, 3, bytes_decode); // TODO: should accept kwargs too -STATIC mp_obj_t str_encode(size_t n_args, const mp_obj_t *args) { +static mp_obj_t str_encode(size_t n_args, const mp_obj_t *args) { mp_obj_t new_args[2]; if (n_args == 1) { new_args[0] = args[0]; @@ -2068,14 +2068,14 @@ mp_obj_t mp_obj_bytes_fromhex(mp_obj_t type_in, mp_obj_t data) { return mp_obj_new_str_type_from_vstr(MP_OBJ_TO_PTR(type_in), &vstr); } -STATIC mp_obj_t bytes_hex_as_str(size_t n_args, const mp_obj_t *args) { +static mp_obj_t bytes_hex_as_str(size_t n_args, const mp_obj_t *args) { return mp_obj_bytes_hex(n_args, args, &mp_type_str); } // CIRCUITPY-CHANGE: make public MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_obj_bytes_hex_as_str_obj, 1, 2, bytes_hex_as_str); -STATIC MP_DEFINE_CONST_FUN_OBJ_2(bytes_fromhex_obj, mp_obj_bytes_fromhex); -STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(bytes_fromhex_classmethod_obj, MP_ROM_PTR(&bytes_fromhex_obj)); +static MP_DEFINE_CONST_FUN_OBJ_2(bytes_fromhex_obj, mp_obj_bytes_fromhex); +static MP_DEFINE_CONST_CLASSMETHOD_OBJ(bytes_fromhex_classmethod_obj, MP_ROM_PTR(&bytes_fromhex_obj)); #endif // MICROPY_PY_BUILTINS_BYTES_HEX mp_int_t mp_obj_str_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { @@ -2099,7 +2099,7 @@ void mp_obj_str_set_data(mp_obj_str_t *str, const byte *data, size_t len) { // This locals table is used for the following types: str, bytes, bytearray, array.array. // Each type takes a different section (start to end offset) of this table. -STATIC const mp_rom_map_elem_t array_bytearray_str_bytes_locals_table[] = { +static const mp_rom_map_elem_t array_bytearray_str_bytes_locals_table[] = { #if MICROPY_PY_ARRAY || MICROPY_PY_BUILTINS_BYTEARRAY { MP_ROM_QSTR(MP_QSTR_append), MP_ROM_PTR(&mp_obj_array_append_obj) }, { MP_ROM_QSTR(MP_QSTR_extend), MP_ROM_PTR(&mp_obj_array_extend_obj) }, @@ -2201,7 +2201,7 @@ MP_DEFINE_CONST_DICT_WITH_SIZE(mp_obj_memoryview_locals_dict, #endif #if !MICROPY_PY_BUILTINS_STR_UNICODE -STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); +static mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); MP_DEFINE_CONST_OBJ_TYPE( mp_type_str, @@ -2273,7 +2273,7 @@ mp_obj_t mp_obj_new_str_via_qstr(const char *data, size_t len) { // Create a str/bytes object from the given vstr. The vstr buffer is resized to // the exact length required and then reused for the str/bytes object. The vstr // is cleared and can safely be passed to vstr_free if it was heap allocated. -STATIC mp_obj_t mp_obj_new_str_type_from_vstr(const mp_obj_type_t *type, vstr_t *vstr) { +static mp_obj_t mp_obj_new_str_type_from_vstr(const mp_obj_type_t *type, vstr_t *vstr) { // if not a bytes object, look if a qstr with this data already exists if (type == &mp_type_str) { qstr q = qstr_find_strn(vstr->buf, vstr->len); @@ -2384,7 +2384,7 @@ bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2) { } } -STATIC NORETURN void bad_implicit_conversion(mp_obj_t self_in) { +static NORETURN void bad_implicit_conversion(mp_obj_t self_in) { #if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE mp_raise_TypeError(MP_ERROR_TEXT("can't convert to str implicitly")); #else @@ -2454,7 +2454,7 @@ typedef struct _mp_obj_str8_it_t { } mp_obj_str8_it_t; #if !MICROPY_PY_BUILTINS_STR_UNICODE -STATIC mp_obj_t str_it_iternext(mp_obj_t self_in) { +static mp_obj_t str_it_iternext(mp_obj_t self_in) { mp_obj_str8_it_t *self = MP_OBJ_TO_PTR(self_in); GET_STR_DATA_LEN(self->str, str, len); if (self->cur < len) { @@ -2466,7 +2466,7 @@ STATIC mp_obj_t str_it_iternext(mp_obj_t self_in) { } } -STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(mp_obj_str8_it_t) <= sizeof(mp_obj_iter_buf_t)); mp_obj_str8_it_t *o = (mp_obj_str8_it_t *)iter_buf; o->base.type = &mp_type_polymorph_iter; @@ -2477,7 +2477,7 @@ STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_bu } #endif -STATIC mp_obj_t bytes_it_iternext(mp_obj_t self_in) { +static mp_obj_t bytes_it_iternext(mp_obj_t self_in) { mp_obj_str8_it_t *self = MP_OBJ_TO_PTR(self_in); GET_STR_DATA_LEN(self->str, str, len); if (self->cur < len) { diff --git a/py/objstr.h b/py/objstr.h index bc3a36b5f8fcb..c241d6e1cd1b2 100644 --- a/py/objstr.h +++ b/py/objstr.h @@ -104,6 +104,8 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s mp_obj_t index, bool is_slice); const byte *find_subbytes(const byte *haystack, size_t hlen, const byte *needle, size_t nlen, int direction); +#define MP_DEFINE_BYTES_OBJ(obj_name, target, len) mp_obj_str_t obj_name = {{&mp_type_bytes}, 0, (len), (const byte *)(target)} + mp_obj_t mp_obj_bytes_hex(size_t n_args, const mp_obj_t *args, const mp_obj_type_t *type); mp_obj_t mp_obj_bytes_fromhex(mp_obj_t type_in, mp_obj_t data); diff --git a/py/objstringio.c b/py/objstringio.c index d191974a1fc03..25e04cb4c696c 100644 --- a/py/objstringio.c +++ b/py/objstringio.c @@ -36,7 +36,7 @@ #if MICROPY_PY_IO #if MICROPY_CPYTHON_COMPAT -STATIC void check_stringio_is_open(const mp_obj_stringio_t *o) { +static void check_stringio_is_open(const mp_obj_stringio_t *o) { if (o->vstr == NULL) { mp_raise_ValueError(MP_ERROR_TEXT("I/O operation on closed file")); } @@ -46,7 +46,7 @@ STATIC void check_stringio_is_open(const mp_obj_stringio_t *o) { #endif // CIRCUITPY-CHANGE: handling subclassing -STATIC mp_obj_stringio_t *native_obj(mp_obj_t o_in) { +static mp_obj_stringio_t *native_obj(mp_obj_t o_in) { mp_obj_stringio_t *native = mp_obj_cast_to_native_base(o_in, &mp_type_stringio); #if MICROPY_PY_IO_BYTESIO @@ -57,14 +57,14 @@ STATIC mp_obj_stringio_t *native_obj(mp_obj_t o_in) { return native; } -STATIC void stringio_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void stringio_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; // CIRCUITPY-CHANGE mp_obj_stringio_t *self = native_obj(self_in); mp_printf(print, self->base.type == &mp_type_stringio ? "" : "", self); } -STATIC mp_uint_t stringio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stringio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *errcode) { (void)errcode; // CIRCUITPY-CHANGE mp_obj_stringio_t *o = native_obj(o_in); @@ -81,7 +81,7 @@ STATIC mp_uint_t stringio_read(mp_obj_t o_in, void *buf, mp_uint_t size, int *er return size; } -STATIC void stringio_copy_on_write(mp_obj_stringio_t *o) { +static void stringio_copy_on_write(mp_obj_stringio_t *o) { const void *buf = o->vstr->buf; o->vstr->buf = m_new(char, o->vstr->len); o->vstr->fixed_buf = false; @@ -89,7 +89,7 @@ STATIC void stringio_copy_on_write(mp_obj_stringio_t *o) { memcpy(o->vstr->buf, buf, o->vstr->len); } -STATIC mp_uint_t stringio_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stringio_write(mp_obj_t o_in, const void *buf, mp_uint_t size, int *errcode) { (void)errcode; // CIRCUITPY-CHANGE mp_obj_stringio_t *o = native_obj(o_in); @@ -124,7 +124,7 @@ STATIC mp_uint_t stringio_write(mp_obj_t o_in, const void *buf, mp_uint_t size, return size; } -STATIC mp_uint_t stringio_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t stringio_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, int *errcode) { (void)errcode; // CIRCUITPY-CHANGE mp_obj_stringio_t *o = native_obj(o_in); @@ -178,23 +178,23 @@ STATIC mp_uint_t stringio_ioctl(mp_obj_t o_in, mp_uint_t request, uintptr_t arg, #define STREAM_TO_CONTENT_TYPE(o) (((o)->base.type == &mp_type_stringio) ? &mp_type_str : &mp_type_bytes) -STATIC mp_obj_t stringio_getvalue(mp_obj_t self_in) { +static mp_obj_t stringio_getvalue(mp_obj_t self_in) { // CIRCUITPY-CHANGE mp_obj_stringio_t *self = native_obj(self_in); check_stringio_is_open(self); // TODO: Try to avoid copying string return mp_obj_new_str_of_type(STREAM_TO_CONTENT_TYPE(self), (byte *)self->vstr->buf, self->vstr->len); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(stringio_getvalue_obj, stringio_getvalue); +static MP_DEFINE_CONST_FUN_OBJ_1(stringio_getvalue_obj, stringio_getvalue); -STATIC mp_obj_stringio_t *stringio_new(const mp_obj_type_t *type) { +static mp_obj_stringio_t *stringio_new(const mp_obj_type_t *type) { mp_obj_stringio_t *o = mp_obj_malloc(mp_obj_stringio_t, type); o->pos = 0; o->ref_obj = MP_OBJ_NULL; return o; } -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) { +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) { (void)n_kw; // TODO check n_kw==0 mp_uint_t sz = 16; @@ -232,7 +232,7 @@ STATIC mp_obj_t stringio_make_new(const mp_obj_type_t *type_in, size_t n_args, s return MP_OBJ_FROM_PTR(o); } -STATIC const mp_rom_map_elem_t stringio_locals_dict_table[] = { +static const mp_rom_map_elem_t stringio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mp_stream_read_obj) }, { MP_ROM_QSTR(MP_QSTR_readinto), MP_ROM_PTR(&mp_stream_readinto_obj) }, { MP_ROM_QSTR(MP_QSTR_readline), MP_ROM_PTR(&mp_stream_unbuffered_readline_obj) }, @@ -246,9 +246,9 @@ STATIC const mp_rom_map_elem_t stringio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&mp_stream___exit___obj) }, }; -STATIC MP_DEFINE_CONST_DICT(stringio_locals_dict, stringio_locals_dict_table); +static MP_DEFINE_CONST_DICT(stringio_locals_dict, stringio_locals_dict_table); -STATIC const mp_stream_p_t stringio_stream_p = { +static const mp_stream_p_t stringio_stream_p = { .read = stringio_read, .write = stringio_write, .ioctl = stringio_ioctl, @@ -266,7 +266,7 @@ MP_DEFINE_CONST_OBJ_TYPE( ); #if MICROPY_PY_IO_BYTESIO -STATIC const mp_stream_p_t bytesio_stream_p = { +static const mp_stream_p_t bytesio_stream_p = { .read = stringio_read, .write = stringio_write, .ioctl = stringio_ioctl, diff --git a/py/objstrunicode.c b/py/objstrunicode.c index b1c1185d2d6a9..203d3858e60da 100644 --- a/py/objstrunicode.c +++ b/py/objstrunicode.c @@ -34,12 +34,12 @@ #if MICROPY_PY_BUILTINS_STR_UNICODE -STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); +static mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf); /******************************************************************************/ /* str */ -STATIC void uni_print_quoted(const mp_print_t *print, const byte *str_data, uint str_len) { +static void uni_print_quoted(const mp_print_t *print, const byte *str_data, uint str_len) { // this escapes characters, but it will be very slow to print (calling print many times) bool has_single_quote = false; bool has_double_quote = false; @@ -90,7 +90,7 @@ STATIC void uni_print_quoted(const mp_print_t *print, const byte *str_data, uint mp_printf(print, "%c", quote_char); } -STATIC void uni_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void uni_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { GET_STR_DATA_LEN(self_in, str_data, str_len); #if MICROPY_PY_JSON if (kind == PRINT_JSON) { @@ -105,7 +105,7 @@ STATIC void uni_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t } } -STATIC mp_obj_t uni_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t uni_unary_op(mp_unary_op_t op, mp_obj_t self_in) { GET_STR_DATA_LEN(self_in, str_data, str_len); switch (op) { case MP_UNARY_OP_BOOL: @@ -185,7 +185,7 @@ const byte *str_index_to_ptr(const mp_obj_type_t *type, const byte *self_data, s return s; } -STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { +static mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { const mp_obj_type_t *type = mp_obj_get_type(self_in); assert(type == &mp_type_str); GET_STR_DATA_LEN(self_in, self_data, self_len); @@ -260,7 +260,7 @@ typedef struct _mp_obj_str_it_t { size_t cur; } mp_obj_str_it_t; -STATIC mp_obj_t str_it_iternext(mp_obj_t self_in) { +static mp_obj_t str_it_iternext(mp_obj_t self_in) { mp_obj_str_it_t *self = MP_OBJ_TO_PTR(self_in); GET_STR_DATA_LEN(self->str, str, len); if (self->cur < len) { @@ -274,7 +274,7 @@ STATIC mp_obj_t str_it_iternext(mp_obj_t self_in) { } } -STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf) { +static mp_obj_t mp_obj_new_str_iterator(mp_obj_t str, mp_obj_iter_buf_t *iter_buf) { assert(sizeof(mp_obj_str_it_t) <= sizeof(mp_obj_iter_buf_t)); mp_obj_str_it_t *o = (mp_obj_str_it_t *)iter_buf; o->base.type = &mp_type_polymorph_iter; diff --git a/py/objtraceback.c b/py/objtraceback.c index 7fcec9383d05d..7299427b15941 100644 --- a/py/objtraceback.c +++ b/py/objtraceback.c @@ -1,35 +1,15 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2021 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. - */ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2021 microDev +// +// SPDX-License-Identifier: MIT #include "py/runtime.h" #include "py/objtraceback.h" const mp_obj_traceback_t mp_const_empty_traceback_obj = {{&mp_type_traceback}, 0, 0, NULL}; -STATIC void mp_obj_traceback_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void mp_obj_traceback_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_traceback_t *o = MP_OBJ_TO_PTR(o_in); mp_printf(print, "<%q object at %p>", MP_QSTR_traceback, o); diff --git a/py/objtraceback.h b/py/objtraceback.h index 992fe89b01f83..e6be254a5db6c 100644 --- a/py/objtraceback.h +++ b/py/objtraceback.h @@ -1,31 +1,10 @@ -/* - * This file is part of the MicroPython project, http://micropython.org/ - * - * The MIT License (MIT) - * - * Copyright (c) 2021 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. - */ +// This file is part of the CircuitPython project: https://circuitpython.org +// +// SPDX-FileCopyrightText: Copyright (c) 2021 microDev +// +// SPDX-License-Identifier: MIT -#ifndef MICROPY_INCLUDED_PY_OBJTRACEBACK_H -#define MICROPY_INCLUDED_PY_OBJTRACEBACK_H +#pragma once #include "py/obj.h" @@ -35,5 +14,3 @@ typedef struct _mp_obj_traceback_t { size_t len : (8 * sizeof(size_t) / 2); size_t *data; } mp_obj_traceback_t; - -#endif // MICROPY_INCLUDED_PY_OBJTRACEBACK_H diff --git a/py/objtuple.c b/py/objtuple.c index 79703d68c83d6..afa80799af58e 100644 --- a/py/objtuple.c +++ b/py/objtuple.c @@ -65,7 +65,7 @@ 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, size_t n_kw, const mp_obj_t *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, n_kw, 0, 1, false); @@ -107,7 +107,7 @@ STATIC mp_obj_t mp_obj_tuple_make_new(const mp_obj_type_t *type_in, size_t n_arg } // Don't pass MP_BINARY_OP_NOT_EQUAL here -STATIC mp_obj_t tuple_cmp_helper(mp_uint_t op, mp_obj_t self_in, mp_obj_t another_in) { +static mp_obj_t tuple_cmp_helper(mp_uint_t op, mp_obj_t self_in, mp_obj_t another_in) { mp_check_self(mp_obj_is_tuple_compatible(self_in)); const mp_obj_type_t *another_type = mp_obj_get_type(another_in); mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in); @@ -211,26 +211,26 @@ mp_obj_t mp_obj_tuple_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { } } -STATIC mp_obj_t tuple_count(mp_obj_t self_in, mp_obj_t value) { +static mp_obj_t tuple_count(mp_obj_t self_in, mp_obj_t value) { mp_check_self(mp_obj_is_type(self_in, &mp_type_tuple)); mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in); return mp_seq_count_obj(self->items, self->len, value); } -STATIC MP_DEFINE_CONST_FUN_OBJ_2(tuple_count_obj, tuple_count); +static MP_DEFINE_CONST_FUN_OBJ_2(tuple_count_obj, tuple_count); -STATIC mp_obj_t tuple_index(size_t n_args, const mp_obj_t *args) { +static mp_obj_t tuple_index(size_t n_args, const mp_obj_t *args) { mp_check_self(mp_obj_is_type(args[0], &mp_type_tuple)); mp_obj_tuple_t *self = MP_OBJ_TO_PTR(args[0]); return mp_seq_index_obj(self->items, self->len, n_args, args); } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tuple_index_obj, 2, 4, tuple_index); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tuple_index_obj, 2, 4, tuple_index); -STATIC const mp_rom_map_elem_t tuple_locals_dict_table[] = { +static const mp_rom_map_elem_t tuple_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_count), MP_ROM_PTR(&tuple_count_obj) }, { MP_ROM_QSTR(MP_QSTR_index), MP_ROM_PTR(&tuple_index_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(tuple_locals_dict, tuple_locals_dict_table); +static MP_DEFINE_CONST_DICT(tuple_locals_dict, tuple_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_type_tuple, @@ -252,7 +252,7 @@ mp_obj_t mp_obj_new_tuple(size_t n, const mp_obj_t *items) { if (n == 0) { return mp_const_empty_tuple; } - mp_obj_tuple_t *o = mp_obj_malloc_var(mp_obj_tuple_t, mp_obj_t, n, &mp_type_tuple); + mp_obj_tuple_t *o = mp_obj_malloc_var(mp_obj_tuple_t, items, mp_obj_t, n, &mp_type_tuple); o->len = n; if (items) { for (size_t i = 0; i < n; i++) { @@ -285,7 +285,7 @@ typedef struct _mp_obj_tuple_it_t { size_t cur; } mp_obj_tuple_it_t; -STATIC mp_obj_t tuple_it_iternext(mp_obj_t self_in) { +static mp_obj_t tuple_it_iternext(mp_obj_t self_in) { mp_obj_tuple_it_t *self = MP_OBJ_TO_PTR(self_in); if (self->cur < self->tuple->len) { mp_obj_t o_out = self->tuple->items[self->cur]; diff --git a/py/objtype.c b/py/objtype.c index 504806d807d6a..c2ef10ee9ee54 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -44,12 +44,12 @@ #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, size_t n_kw, const mp_obj_t *args); +static mp_obj_t static_class_method_make_new(const mp_obj_type_t *self_in, size_t n_args, size_t n_kw, const mp_obj_t *args); /******************************************************************************/ // instance object -STATIC int instance_count_native_bases(const mp_obj_type_t *type, const mp_obj_type_t **last_native_base) { +static int instance_count_native_bases(const mp_obj_type_t *type, const mp_obj_type_t **last_native_base) { int count = 0; for (;;) { if (type == &mp_type_object) { @@ -85,7 +85,7 @@ STATIC int instance_count_native_bases(const mp_obj_type_t *type, const mp_obj_t // CIRCUITPY-CHANGE: support superclass constructors that take kw args // This wrapper function is allows a subclass of a native type to call the // __init__() method (corresponding to type->make_new) of the native type. -STATIC mp_obj_t native_base_init_wrapper(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) { +static mp_obj_t native_base_init_wrapper(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_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); @@ -109,15 +109,15 @@ STATIC mp_obj_t native_base_init_wrapper(size_t n_args, const mp_obj_t *pos_args return mp_const_none; } -STATIC MP_DEFINE_CONST_FUN_OBJ_KW(native_base_init_wrapper_obj, 1, native_base_init_wrapper); +static MP_DEFINE_CONST_FUN_OBJ_KW(native_base_init_wrapper_obj, 1, native_base_init_wrapper); #if !MICROPY_CPYTHON_COMPAT -STATIC +static #endif mp_obj_instance_t *mp_obj_new_instance(const mp_obj_type_t *class, const mp_obj_type_t **native_base) { size_t num_native_bases = instance_count_native_bases(class, native_base); assert(num_native_bases < 2); - mp_obj_instance_t *o = mp_obj_malloc_var(mp_obj_instance_t, mp_obj_t, num_native_bases, class); + mp_obj_instance_t *o = mp_obj_malloc_var(mp_obj_instance_t, subobj, mp_obj_t, num_native_bases, class); mp_map_init(&o->members, 0); // Initialise the native base-class slot (should be 1 at most) with a valid // object. It doesn't matter which object, so long as it can be uniquely @@ -161,7 +161,7 @@ struct class_lookup_data { bool is_type; }; -STATIC void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_type_t *type) { +static void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_type_t *type) { assert(lookup->dest[0] == MP_OBJ_NULL); assert(lookup->dest[1] == MP_OBJ_NULL); for (;;) { @@ -263,7 +263,7 @@ STATIC void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_t } } -STATIC void instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); qstr meth = (kind == PRINT_STR) ? MP_QSTR___str__ : MP_QSTR___repr__; mp_obj_t member[2] = {MP_OBJ_NULL}; @@ -306,7 +306,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); } -STATIC 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) { +static 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 @@ -399,6 +399,8 @@ STATIC mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_arg // Qstrs for special methods are guaranteed to have a small value, so we use byte // type to represent them. +// The (unescaped) names appear in `unsorted_str_list` in the QSTR +// generator script py/makeqstrdata.py to ensure they are assigned low numbers. const byte mp_unary_op_method_name[MP_UNARY_OP_NUM_RUNTIME] = { [MP_UNARY_OP_BOOL] = MP_QSTR___bool__, [MP_UNARY_OP_LEN] = MP_QSTR___len__, @@ -421,7 +423,7 @@ const byte mp_unary_op_method_name[MP_UNARY_OP_NUM_RUNTIME] = { #endif }; -STATIC mp_obj_t instance_unary_op(mp_unary_op_t op, mp_obj_t self_in) { +static mp_obj_t instance_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); #if MICROPY_PY_SYS_GETSIZEOF @@ -497,6 +499,8 @@ STATIC mp_obj_t instance_unary_op(mp_unary_op_t op, mp_obj_t self_in) { // fail). They can be added at the expense of code size for the qstr. // Qstrs for special methods are guaranteed to have a small value, so we use byte // type to represent them. +// The (unescaped) names appear in `unsorted_str_list` in the QSTR +// generator script py/makeqstrdata.py to ensure they are assigned low numbers. const byte mp_binary_op_method_name[MP_BINARY_OP_NUM_RUNTIME] = { [MP_BINARY_OP_LESS] = MP_QSTR___lt__, [MP_BINARY_OP_MORE] = MP_QSTR___gt__, @@ -559,7 +563,7 @@ const byte mp_binary_op_method_name[MP_BINARY_OP_NUM_RUNTIME] = { #endif }; -STATIC mp_obj_t instance_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t instance_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { // Note: For ducktyping, CPython does not look in the instance members or use // __getattr__ or __getattribute__. It only looks in the class dictionary. mp_obj_instance_t *lhs = MP_OBJ_TO_PTR(lhs_in); @@ -601,7 +605,7 @@ STATIC mp_obj_t instance_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t return res; } -STATIC void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { // logic: look in instance members then class locals assert(mp_obj_is_instance_type(mp_obj_get_type(self_in))); mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); @@ -701,7 +705,7 @@ STATIC void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *des } } -STATIC bool mp_obj_instance_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) { +static bool mp_obj_instance_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) { mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); if (!(self->base.type->flags & MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS)) { @@ -826,7 +830,7 @@ STATIC bool mp_obj_instance_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t val } } -STATIC void mp_obj_instance_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void mp_obj_instance_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] == MP_OBJ_NULL) { mp_obj_instance_load_attr(self_in, attr, dest); } else { @@ -836,7 +840,7 @@ STATIC void mp_obj_instance_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { } } -STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { +static mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t member[4] = {MP_OBJ_NULL, MP_OBJ_NULL, index, value}; struct class_lookup_data lookup = { @@ -875,7 +879,7 @@ STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value } } -STATIC mp_obj_t mp_obj_instance_get_call(mp_obj_t self_in, mp_obj_t *member) { +static mp_obj_t mp_obj_instance_get_call(mp_obj_t self_in, mp_obj_t *member) { mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); struct class_lookup_data lookup = { .obj = self, @@ -941,7 +945,7 @@ mp_obj_t mp_obj_instance_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf) } } -STATIC mp_int_t instance_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { +static mp_int_t instance_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) { mp_obj_instance_t *self = MP_OBJ_TO_PTR(self_in); mp_obj_t member[2] = {MP_OBJ_NULL}; struct class_lookup_data lookup = { @@ -967,7 +971,7 @@ STATIC mp_int_t instance_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, // - creating a new class (a new type) creates a new mp_obj_type_t #if ENABLE_SPECIAL_ACCESSORS -STATIC bool check_for_special_accessors(mp_obj_t key, mp_obj_t value) { +static bool check_for_special_accessors(mp_obj_t key, mp_obj_t value) { #if MICROPY_PY_DELATTR_SETATTR if (key == MP_OBJ_NEW_QSTR(MP_QSTR___setattr__) || key == MP_OBJ_NEW_QSTR(MP_QSTR___delattr__)) { return true; @@ -994,13 +998,13 @@ STATIC bool check_for_special_accessors(mp_obj_t key, mp_obj_t value) { } #endif -STATIC void type_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void type_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", self->name); } -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) { +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, n_kw, 1, 3, false); @@ -1020,7 +1024,7 @@ STATIC mp_obj_t type_make_new(const mp_obj_type_t *type_in, size_t n_args, size_ } } -STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { // instantiate an instance of a class mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in); @@ -1042,7 +1046,7 @@ STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp return o; } -STATIC void type_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void type_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { assert(mp_obj_is_type(self_in, &mp_type_type)); mp_obj_type_t *self = MP_OBJ_TO_PTR(self_in); @@ -1280,7 +1284,7 @@ typedef struct _mp_obj_super_t { mp_obj_t obj; } mp_obj_super_t; -STATIC void super_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void super_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { (void)kind; mp_obj_super_t *self = MP_OBJ_TO_PTR(self_in); mp_print_str(print, ""); } -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) { +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 @@ -1304,7 +1308,7 @@ STATIC mp_obj_t super_make_new(const mp_obj_type_t *type_in, size_t n_args, size return MP_OBJ_FROM_PTR(o); } -STATIC void super_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void super_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { // not load attribute return; @@ -1457,7 +1461,7 @@ bool mp_obj_is_subclass_fast(mp_const_obj_t object, mp_const_obj_t classinfo) { } } -STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) { +static mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) { size_t len; mp_obj_t *items; if (mp_obj_is_type(classinfo, &mp_type_type)) { @@ -1478,7 +1482,7 @@ STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) { return mp_const_false; } -STATIC mp_obj_t mp_builtin_issubclass(mp_obj_t object, mp_obj_t classinfo) { +static mp_obj_t mp_builtin_issubclass(mp_obj_t object, mp_obj_t classinfo) { if (!mp_obj_is_type(object, &mp_type_type)) { mp_raise_TypeError(MP_ERROR_TEXT("issubclass() arg 1 must be a class")); } @@ -1487,7 +1491,7 @@ STATIC mp_obj_t mp_builtin_issubclass(mp_obj_t object, mp_obj_t classinfo) { MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_issubclass_obj, mp_builtin_issubclass); -STATIC mp_obj_t mp_builtin_isinstance(mp_obj_t object, mp_obj_t classinfo) { +static mp_obj_t mp_builtin_isinstance(mp_obj_t object, mp_obj_t classinfo) { return mp_obj_is_subclass(MP_OBJ_FROM_PTR(mp_obj_get_type(object)), classinfo); } @@ -1509,7 +1513,7 @@ 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, size_t n_kw, const mp_obj_t *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, n_kw, 1, 1, false); diff --git a/py/objzip.c b/py/objzip.c index 3c3138180a28f..dd2b39ee07110 100644 --- a/py/objzip.c +++ b/py/objzip.c @@ -36,10 +36,10 @@ 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, size_t n_kw, const mp_obj_t *args) { +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 = mp_obj_malloc_var(mp_obj_zip_t, mp_obj_t, n_args, type); + mp_obj_zip_t *o = mp_obj_malloc_var(mp_obj_zip_t, iters, mp_obj_t, n_args, type); o->n_iters = n_args; for (size_t i = 0; i < n_args; i++) { o->iters[i] = mp_getiter(args[i], NULL); @@ -47,7 +47,7 @@ STATIC mp_obj_t zip_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_ return MP_OBJ_FROM_PTR(o); } -STATIC mp_obj_t zip_iternext(mp_obj_t self_in) { +static mp_obj_t zip_iternext(mp_obj_t self_in) { mp_check_self(mp_obj_is_type(self_in, &mp_type_zip)); mp_obj_zip_t *self = MP_OBJ_TO_PTR(self_in); if (self->n_iters == 0) { diff --git a/py/opmethods.c b/py/opmethods.c index 68a0ce8031273..841dd981544b4 100644 --- a/py/opmethods.c +++ b/py/opmethods.c @@ -31,28 +31,28 @@ // code the type to dict so that subclassed types still use the native dict // subscr. MP doesn't have this problem because it passes the native instance // in. CP passes the subclass instance. -STATIC mp_obj_t op_getitem(mp_obj_t self_in, mp_obj_t key_in) { +static mp_obj_t op_getitem(mp_obj_t self_in, mp_obj_t key_in) { const mp_obj_type_t *type = &mp_type_dict; // Note: assumes type must have subscr (only used by dict). return MP_OBJ_TYPE_GET_SLOT(type, subscr)(self_in, key_in, MP_OBJ_SENTINEL); } MP_DEFINE_CONST_FUN_OBJ_2(mp_op_getitem_obj, op_getitem); -STATIC mp_obj_t op_setitem(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) { +static mp_obj_t op_setitem(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) { const mp_obj_type_t *type = &mp_type_dict; // Note: assumes type must have subscr (only used by dict). return MP_OBJ_TYPE_GET_SLOT(type, subscr)(self_in, key_in, value_in); } MP_DEFINE_CONST_FUN_OBJ_3(mp_op_setitem_obj, op_setitem); -STATIC mp_obj_t op_delitem(mp_obj_t self_in, mp_obj_t key_in) { +static mp_obj_t op_delitem(mp_obj_t self_in, mp_obj_t key_in) { const mp_obj_type_t *type = &mp_type_dict; // Note: assumes type must have subscr (only used by dict). return MP_OBJ_TYPE_GET_SLOT(type, subscr)(self_in, key_in, MP_OBJ_NULL); } MP_DEFINE_CONST_FUN_OBJ_2(mp_op_delitem_obj, op_delitem); -STATIC mp_obj_t op_contains(mp_obj_t lhs_in, mp_obj_t rhs_in) { +static mp_obj_t op_contains(mp_obj_t lhs_in, mp_obj_t rhs_in) { const mp_obj_type_t *type = mp_obj_get_type(lhs_in); // Note: assumes type must have binary_op (only used by set/frozenset). return MP_OBJ_TYPE_GET_SLOT(type, binary_op)(MP_BINARY_OP_CONTAINS, lhs_in, rhs_in); diff --git a/py/parse.c b/py/parse.c index fae55d0e42ac1..9721532afd6eb 100644 --- a/py/parse.c +++ b/py/parse.c @@ -75,7 +75,7 @@ enum { }; // Define an array of actions corresponding to each rule -STATIC const uint8_t rule_act_table[] = { +static const uint8_t rule_act_table[] = { #define or(n) (RULE_ACT_OR | n) #define and(n) (RULE_ACT_AND | n) #define and_ident(n) (RULE_ACT_AND | n | RULE_ACT_ALLOW_IDENT) @@ -108,7 +108,7 @@ STATIC const uint8_t rule_act_table[] = { }; // Define the argument data for each rule, as a combined array -STATIC const uint16_t rule_arg_combined_table[] = { +static const uint16_t rule_arg_combined_table[] = { #define tok(t) (RULE_ARG_TOK | MP_TOKEN_##t) #define rule(r) (RULE_ARG_RULE | RULE_##r) #define opt_rule(r) (RULE_ARG_OPT_RULE | RULE_##r) @@ -161,7 +161,7 @@ enum { // data, which indexes rule_arg_combined_table. The offsets require 9 bits of // storage but only the lower 8 bits are stored here. The 9th bit is computed // in get_rule_arg using the FIRST_RULE_WITH_OFFSET_ABOVE_255 constant. -STATIC const uint8_t rule_arg_offset_table[] = { +static const uint8_t rule_arg_offset_table[] = { #define DEF_RULE(rule, comp, kind, ...) RULE_ARG_OFFSET(rule, __VA_ARGS__) & 0xff, #define DEF_RULE_NC(rule, kind, ...) #include "py/grammar.h" @@ -191,7 +191,7 @@ static const size_t FIRST_RULE_WITH_OFFSET_ABOVE_255 = #if MICROPY_DEBUG_PARSE_RULE_NAME // Define an array of rule names corresponding to each rule -STATIC const char *const rule_name_table[] = { +static const char *const rule_name_table[] = { #define DEF_RULE(rule, comp, kind, ...) #rule, #define DEF_RULE_NC(rule, kind, ...) #include "py/grammar.h" @@ -242,9 +242,9 @@ typedef struct _parser_t { #endif } parser_t; -STATIC void push_result_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t num_args); +static void push_result_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t num_args); -STATIC const uint16_t *get_rule_arg(uint8_t r_id) { +static const uint16_t *get_rule_arg(uint8_t r_id) { size_t off = rule_arg_offset_table[r_id]; if (r_id >= FIRST_RULE_WITH_OFFSET_ABOVE_255) { off |= 0x100; @@ -256,7 +256,7 @@ STATIC const uint16_t *get_rule_arg(uint8_t r_id) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-align" -STATIC void *parser_alloc(parser_t *parser, size_t num_bytes) { +static void *parser_alloc(parser_t *parser, size_t num_bytes) { // use a custom memory allocator to store parse nodes sequentially in large chunks mp_parse_chunk_t *chunk = parser->cur_chunk; @@ -299,7 +299,7 @@ STATIC void *parser_alloc(parser_t *parser, size_t num_bytes) { #pragma GCC diagnostic pop #if MICROPY_COMP_CONST_TUPLE -STATIC void parser_free_parse_node_struct(parser_t *parser, mp_parse_node_struct_t *pns) { +static void parser_free_parse_node_struct(parser_t *parser, mp_parse_node_struct_t *pns) { mp_parse_chunk_t *chunk = parser->cur_chunk; if (chunk->data <= (byte *)pns && (byte *)pns < chunk->data + chunk->union_.used) { size_t num_bytes = sizeof(mp_parse_node_struct_t) + sizeof(mp_parse_node_t) * MP_PARSE_NODE_STRUCT_NUM_NODES(pns); @@ -308,7 +308,7 @@ STATIC void parser_free_parse_node_struct(parser_t *parser, mp_parse_node_struct } #endif -STATIC void push_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t arg_i) { +static void push_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t arg_i) { if (parser->rule_stack_top >= parser->rule_stack_alloc) { rule_stack_t *rs = m_renew(rule_stack_t, parser->rule_stack, parser->rule_stack_alloc, parser->rule_stack_alloc + MICROPY_ALLOC_PARSE_RULE_INC); parser->rule_stack = rs; @@ -320,13 +320,13 @@ STATIC void push_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t rs->arg_i = arg_i; } -STATIC void push_rule_from_arg(parser_t *parser, size_t arg) { +static void push_rule_from_arg(parser_t *parser, size_t arg) { assert((arg & RULE_ARG_KIND_MASK) == RULE_ARG_RULE || (arg & RULE_ARG_KIND_MASK) == RULE_ARG_OPT_RULE); size_t rule_id = arg & RULE_ARG_ARG_MASK; push_rule(parser, parser->lexer->tok_line, rule_id, 0); } -STATIC uint8_t pop_rule(parser_t *parser, size_t *arg_i, size_t *src_line) { +static uint8_t pop_rule(parser_t *parser, size_t *arg_i, size_t *src_line) { parser->rule_stack_top -= 1; uint8_t rule_id = parser->rule_stack[parser->rule_stack_top].rule_id; *arg_i = parser->rule_stack[parser->rule_stack_top].arg_i; @@ -335,7 +335,7 @@ STATIC uint8_t pop_rule(parser_t *parser, size_t *arg_i, size_t *src_line) { } #if MICROPY_COMP_CONST_TUPLE -STATIC uint8_t peek_rule(parser_t *parser, size_t n) { +static uint8_t peek_rule(parser_t *parser, size_t n) { assert(parser->rule_stack_top > n); return parser->rule_stack[parser->rule_stack_top - 1 - n].rule_id; } @@ -355,7 +355,7 @@ bool mp_parse_node_get_int_maybe(mp_parse_node_t pn, mp_obj_t *o) { } #if MICROPY_COMP_CONST_TUPLE || MICROPY_COMP_CONST -STATIC bool mp_parse_node_is_const(mp_parse_node_t pn) { +static bool mp_parse_node_is_const(mp_parse_node_t pn) { if (MP_PARSE_NODE_IS_SMALL_INT(pn)) { // Small integer. return true; @@ -382,7 +382,7 @@ STATIC bool mp_parse_node_is_const(mp_parse_node_t pn) { return false; } -STATIC mp_obj_t mp_parse_node_convert_to_obj(mp_parse_node_t pn) { +static mp_obj_t mp_parse_node_convert_to_obj(mp_parse_node_t pn) { assert(mp_parse_node_is_const(pn)); if (MP_PARSE_NODE_IS_SMALL_INT(pn)) { mp_int_t arg = MP_PARSE_NODE_LEAF_SMALL_INT(pn); @@ -424,7 +424,7 @@ STATIC mp_obj_t mp_parse_node_convert_to_obj(mp_parse_node_t pn) { } #endif -STATIC bool parse_node_is_const_bool(mp_parse_node_t pn, bool value) { +static bool parse_node_is_const_bool(mp_parse_node_t pn, bool value) { // Returns true if 'pn' is a constant whose boolean value is equivalent to 'value' #if MICROPY_COMP_CONST_TUPLE || MICROPY_COMP_CONST return mp_parse_node_is_const(pn) && mp_obj_is_true(mp_parse_node_convert_to_obj(pn)) == value; @@ -518,7 +518,7 @@ void mp_parse_node_print(const mp_print_t *print, mp_parse_node_t pn, size_t ind #endif // MICROPY_DEBUG_PRINTERS /* -STATIC void result_stack_show(const mp_print_t *print, parser_t *parser) { +static void result_stack_show(const mp_print_t *print, parser_t *parser) { mp_printf(print, "result stack, most recent first\n"); for (ssize_t i = parser->result_stack_top - 1; i >= 0; i--) { mp_parse_node_print(print, parser->result_stack[i], 0); @@ -526,17 +526,17 @@ STATIC void result_stack_show(const mp_print_t *print, parser_t *parser) { } */ -STATIC mp_parse_node_t pop_result(parser_t *parser) { +static mp_parse_node_t pop_result(parser_t *parser) { assert(parser->result_stack_top > 0); return parser->result_stack[--parser->result_stack_top]; } -STATIC mp_parse_node_t peek_result(parser_t *parser, size_t pos) { +static mp_parse_node_t peek_result(parser_t *parser, size_t pos) { assert(parser->result_stack_top > pos); return parser->result_stack[parser->result_stack_top - 1 - pos]; } -STATIC void push_result_node(parser_t *parser, mp_parse_node_t pn) { +static void push_result_node(parser_t *parser, mp_parse_node_t pn) { if (parser->result_stack_top >= parser->result_stack_alloc) { mp_parse_node_t *stack = m_renew(mp_parse_node_t, parser->result_stack, parser->result_stack_alloc, parser->result_stack_alloc + MICROPY_ALLOC_PARSE_RESULT_INC); parser->result_stack = stack; @@ -545,7 +545,7 @@ STATIC void push_result_node(parser_t *parser, mp_parse_node_t pn) { parser->result_stack[parser->result_stack_top++] = pn; } -STATIC mp_parse_node_t make_node_const_object(parser_t *parser, size_t src_line, mp_obj_t obj) { +static mp_parse_node_t make_node_const_object(parser_t *parser, size_t src_line, mp_obj_t obj) { mp_parse_node_struct_t *pn = parser_alloc(parser, sizeof(mp_parse_node_struct_t) + sizeof(mp_obj_t)); pn->source_line = src_line; #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D @@ -562,7 +562,7 @@ STATIC mp_parse_node_t make_node_const_object(parser_t *parser, size_t src_line, // Create a parse node representing a constant object, possibly optimising the case of // an integer, by putting the (small) integer value directly in the parse node itself. -STATIC mp_parse_node_t make_node_const_object_optimised(parser_t *parser, size_t src_line, mp_obj_t obj) { +static mp_parse_node_t make_node_const_object_optimised(parser_t *parser, size_t src_line, mp_obj_t obj) { if (mp_obj_is_small_int(obj)) { mp_int_t val = MP_OBJ_SMALL_INT_VALUE(obj); #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D @@ -584,7 +584,7 @@ STATIC mp_parse_node_t make_node_const_object_optimised(parser_t *parser, size_t } } -STATIC void push_result_token(parser_t *parser, uint8_t rule_id) { +static void push_result_token(parser_t *parser, uint8_t rule_id) { mp_parse_node_t pn; mp_lexer_t *lex = parser->lexer; if (lex->tok_kind == MP_TOKEN_NAME) { @@ -640,7 +640,7 @@ STATIC void push_result_token(parser_t *parser, uint8_t rule_id) { #if MICROPY_COMP_CONST_FOLDING #if MICROPY_COMP_MODULE_CONST -STATIC const mp_rom_map_elem_t mp_constants_table[] = { +static const mp_rom_map_elem_t mp_constants_table[] = { #if MICROPY_PY_ERRNO { MP_ROM_QSTR(MP_QSTR_errno), MP_ROM_PTR(&mp_module_errno) }, #endif @@ -650,7 +650,7 @@ STATIC const mp_rom_map_elem_t mp_constants_table[] = { // Extra constants as defined by a port MICROPY_PORT_CONSTANTS }; -STATIC MP_DEFINE_CONST_MAP(mp_constants_map, mp_constants_table); +static MP_DEFINE_CONST_MAP(mp_constants_map, mp_constants_table); #endif // CIRCUITPY-CHANGE: avoid compiler warning @@ -659,7 +659,7 @@ STATIC MP_DEFINE_CONST_MAP(mp_constants_map, mp_constants_table); // function is static, so provide a hook for them to work around this problem. MP_NOINLINE #endif -STATIC bool fold_logical_constants(parser_t *parser, uint8_t rule_id, size_t *num_args) { +static bool fold_logical_constants(parser_t *parser, uint8_t rule_id, size_t *num_args) { if (rule_id == RULE_or_test || rule_id == RULE_and_test) { // folding for binary logical ops: or and @@ -716,7 +716,7 @@ STATIC bool fold_logical_constants(parser_t *parser, uint8_t rule_id, size_t *nu return false; } -STATIC bool fold_constants(parser_t *parser, uint8_t rule_id, size_t num_args) { +static bool fold_constants(parser_t *parser, uint8_t rule_id, size_t num_args) { // this code does folding of arbitrary integer expressions, eg 1 + 2 * 3 + 4 // it does not do partial folding, eg 1 + 2 + x -> 3 + x @@ -900,7 +900,7 @@ STATIC bool fold_constants(parser_t *parser, uint8_t rule_id, size_t num_args) { #endif // MICROPY_COMP_CONST_FOLDING #if MICROPY_COMP_CONST_TUPLE -STATIC bool build_tuple_from_stack(parser_t *parser, size_t src_line, size_t num_args) { +static bool build_tuple_from_stack(parser_t *parser, size_t src_line, size_t num_args) { for (size_t i = num_args; i > 0;) { mp_parse_node_t pn = peek_result(parser, --i); if (!mp_parse_node_is_const(pn)) { @@ -919,7 +919,7 @@ STATIC bool build_tuple_from_stack(parser_t *parser, size_t src_line, size_t num return true; } -STATIC bool build_tuple(parser_t *parser, size_t src_line, uint8_t rule_id, size_t num_args) { +static bool build_tuple(parser_t *parser, size_t src_line, uint8_t rule_id, size_t num_args) { if (rule_id == RULE_testlist_comp) { if (peek_rule(parser, 0) == RULE_atom_paren) { // Tuple of the form "(a,)". @@ -952,7 +952,7 @@ STATIC bool build_tuple(parser_t *parser, size_t src_line, uint8_t rule_id, size } #endif -STATIC void push_result_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t num_args) { +static void push_result_rule(parser_t *parser, size_t src_line, uint8_t rule_id, size_t num_args) { // Simplify and optimise certain rules, to reduce memory usage and simplify the compiler. if (rule_id == RULE_atom_paren) { // Remove parenthesis around a single expression if possible. @@ -1413,6 +1413,7 @@ void mp_parse_tree_clear(mp_parse_tree_t *tree) { m_del(byte, chunk, sizeof(mp_parse_chunk_t) + chunk->alloc); chunk = next; } + tree->chunk = NULL; // Avoid dangling pointer that may live on stack } #endif // MICROPY_ENABLE_COMPILER diff --git a/py/parsenum.c b/py/parsenum.c index 68f7417c0bd63..67ac12d190728 100644 --- a/py/parsenum.c +++ b/py/parsenum.c @@ -36,7 +36,7 @@ #include #endif -STATIC NORETURN void raise_exc(mp_obj_t exc, mp_lexer_t *lex) { +static NORETURN void raise_exc(mp_obj_t exc, mp_lexer_t *lex) { // if lex!=NULL then the parser called us and we need to convert the // exception's type from ValueError to SyntaxError and add traceback info if (lex != NULL) { diff --git a/py/persistentcode.c b/py/persistentcode.c index 9c78c93b23bb4..09beeef4518db 100644 --- a/py/persistentcode.c +++ b/py/persistentcode.c @@ -69,8 +69,8 @@ typedef struct _bytecode_prelude_t { #include "py/parsenum.h" -STATIC int read_byte(mp_reader_t *reader); -STATIC size_t read_uint(mp_reader_t *reader); +static int read_byte(mp_reader_t *reader); +static size_t read_uint(mp_reader_t *reader); #if MICROPY_EMIT_MACHINE_CODE @@ -145,17 +145,17 @@ void mp_native_relocate(void *ri_in, uint8_t *text, uintptr_t reloc_text) { #endif -STATIC int read_byte(mp_reader_t *reader) { +static int read_byte(mp_reader_t *reader) { return reader->readbyte(reader->data); } -STATIC void read_bytes(mp_reader_t *reader, byte *buf, size_t len) { +static void read_bytes(mp_reader_t *reader, byte *buf, size_t len) { while (len-- > 0) { *buf++ = reader->readbyte(reader->data); } } -STATIC size_t read_uint(mp_reader_t *reader) { +static size_t read_uint(mp_reader_t *reader) { size_t unum = 0; for (;;) { byte b = reader->readbyte(reader->data); @@ -167,7 +167,7 @@ STATIC size_t read_uint(mp_reader_t *reader) { return unum; } -STATIC qstr load_qstr(mp_reader_t *reader) { +static qstr load_qstr(mp_reader_t *reader) { size_t len = read_uint(reader); if (len & 1) { // static qstr @@ -182,7 +182,7 @@ STATIC qstr load_qstr(mp_reader_t *reader) { return qst; } -STATIC mp_obj_t load_obj(mp_reader_t *reader) { +static mp_obj_t load_obj(mp_reader_t *reader) { byte obj_type = read_byte(reader); #if MICROPY_EMIT_MACHINE_CODE if (obj_type == MP_PERSISTENT_OBJ_FUN_TABLE) { @@ -228,7 +228,7 @@ STATIC mp_obj_t load_obj(mp_reader_t *reader) { } } -STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, mp_module_context_t *context) { +static mp_raw_code_t *load_raw_code(mp_reader_t *reader, mp_module_context_t *context) { // Load function kind and data length size_t kind_len = read_uint(reader); int kind = (kind_len & 3) + MP_CODE_BYTECODE; @@ -331,11 +331,9 @@ STATIC mp_raw_code_t *load_raw_code(mp_reader_t *reader, mp_module_context_t *co MP_BC_PRELUDE_SIG_DECODE(ip); // Assign bytecode to raw code object mp_emit_glue_assign_bytecode(rc, fun_data, - #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS - fun_data_len, - #endif children, #if MICROPY_PERSISTENT_CODE_SAVE + fun_data_len, n_children, #endif scope_flags); @@ -478,12 +476,12 @@ void mp_raw_code_load_file(qstr filename, mp_compiled_module_t *context) { #include "py/objstr.h" -STATIC void mp_print_bytes(mp_print_t *print, const byte *data, size_t len) { +static void mp_print_bytes(mp_print_t *print, const byte *data, size_t len) { print->print_strn(print->data, (const char *)data, len); } #define BYTES_FOR_INT ((MP_BYTES_PER_OBJ_WORD * 8 + 6) / 7) -STATIC void mp_print_uint(mp_print_t *print, size_t n) { +static void mp_print_uint(mp_print_t *print, size_t n) { byte buf[BYTES_FOR_INT]; byte *p = buf + sizeof(buf); *--p = n & 0x7f; @@ -494,7 +492,7 @@ STATIC void mp_print_uint(mp_print_t *print, size_t n) { print->print_strn(print->data, (char *)p, buf + sizeof(buf) - p); } -STATIC void save_qstr(mp_print_t *print, qstr qst) { +static void save_qstr(mp_print_t *print, qstr qst) { if (qst <= QSTR_LAST_STATIC) { // encode static qstr mp_print_uint(print, qst << 1 | 1); @@ -506,7 +504,7 @@ STATIC void save_qstr(mp_print_t *print, qstr qst) { mp_print_bytes(print, str, len + 1); // +1 to store null terminator } -STATIC void save_obj(mp_print_t *print, mp_obj_t o) { +static void save_obj(mp_print_t *print, mp_obj_t o) { #if MICROPY_EMIT_MACHINE_CODE if (o == MP_OBJ_FROM_PTR(&mp_fun_table)) { byte obj_type = MP_PERSISTENT_OBJ_FUN_TABLE; @@ -572,7 +570,7 @@ STATIC void save_obj(mp_print_t *print, mp_obj_t o) { } } -STATIC void save_raw_code(mp_print_t *print, const mp_raw_code_t *rc) { +static void save_raw_code(mp_print_t *print, const mp_raw_code_t *rc) { // Save function kind and data length mp_print_uint(print, (rc->fun_data_len << 3) | ((rc->n_children != 0) << 2) | (rc->kind - MP_CODE_BYTECODE)); @@ -585,11 +583,15 @@ STATIC void save_raw_code(mp_print_t *print, const mp_raw_code_t *rc) { mp_print_uint(print, rc->prelude_offset); } else if (rc->kind == MP_CODE_NATIVE_VIPER || rc->kind == MP_CODE_NATIVE_ASM) { // Save basic scope info for viper and asm - mp_print_uint(print, rc->scope_flags & MP_SCOPE_FLAG_ALL_SIG); + // Viper/asm functions don't support generator, variable args, or default keyword args + // so (scope_flags & MP_SCOPE_FLAG_ALL_SIG) for these functions is always 0. + mp_print_uint(print, 0); + #if MICROPY_EMIT_INLINE_ASM if (rc->kind == MP_CODE_NATIVE_ASM) { - mp_print_uint(print, rc->n_pos_args); - mp_print_uint(print, rc->type_sig); + mp_print_uint(print, rc->asm_n_pos_args); + mp_print_uint(print, rc->asm_type_sig); } + #endif } #endif @@ -644,7 +646,7 @@ void mp_raw_code_save(mp_compiled_module_t *cm, mp_print_t *print) { #include #include -STATIC void fd_print_strn(void *env, const char *str, size_t len) { +static void fd_print_strn(void *env, const char *str, size_t len) { int fd = (intptr_t)env; MP_THREAD_GIL_EXIT(); ssize_t ret = write(fd, str, len); diff --git a/py/persistentcode.h b/py/persistentcode.h index 45a268d63fb91..d2b310f241f8d 100644 --- a/py/persistentcode.h +++ b/py/persistentcode.h @@ -35,7 +35,7 @@ // set) must also match MPY_SUB_VERSION. This allows 3 additional updates to // the native ABI per bytecode revision. #define MPY_VERSION 6 -#define MPY_SUB_VERSION 2 +#define MPY_SUB_VERSION 3 // Macros to encode/decode sub-version to/from the feature byte. This replaces // the bits previously used to encode the flags (map caching and unicode) diff --git a/py/profile.c b/py/profile.c index 274089d7022f1..92f414ace7c92 100644 --- a/py/profile.c +++ b/py/profile.c @@ -40,7 +40,7 @@ #define prof_trace_cb MP_STATE_THREAD(prof_trace_callback) #define QSTR_MAP(context, idx) (context->constants.qstr_table[idx]) -STATIC uint mp_prof_bytecode_lineno(const mp_raw_code_t *rc, size_t bc) { +static uint mp_prof_bytecode_lineno(const mp_raw_code_t *rc, size_t bc) { const mp_bytecode_prelude_t *prelude = &rc->prelude; return mp_bytecode_get_source_line(prelude->line_info, prelude->line_info_top, bc); } @@ -71,7 +71,7 @@ void mp_prof_extract_prelude(const byte *bytecode, mp_bytecode_prelude_t *prelud /******************************************************************************/ // code object -STATIC void code_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void code_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_code_t *o = MP_OBJ_TO_PTR(o_in); const mp_raw_code_t *rc = o->rc; @@ -85,7 +85,7 @@ STATIC void code_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t k ); } -STATIC mp_obj_tuple_t *code_consts(const mp_module_context_t *context, const mp_raw_code_t *rc) { +static mp_obj_tuple_t *code_consts(const mp_module_context_t *context, const mp_raw_code_t *rc) { mp_obj_tuple_t *consts = MP_OBJ_TO_PTR(mp_obj_new_tuple(rc->n_children + 1, NULL)); size_t const_no = 0; @@ -101,7 +101,7 @@ STATIC mp_obj_tuple_t *code_consts(const mp_module_context_t *context, const mp_ return consts; } -STATIC mp_obj_t raw_code_lnotab(const mp_raw_code_t *rc) { +static mp_obj_t raw_code_lnotab(const mp_raw_code_t *rc) { // const mp_bytecode_prelude_t *prelude = &rc->prelude; uint start = 0; uint stop = rc->fun_data_len - start; @@ -139,7 +139,7 @@ STATIC mp_obj_t raw_code_lnotab(const mp_raw_code_t *rc) { return o; } -STATIC void code_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void code_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { // not load attribute return; @@ -202,7 +202,7 @@ mp_obj_t mp_obj_new_code(const mp_module_context_t *context, const mp_raw_code_t /******************************************************************************/ // frame object -STATIC void frame_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { +static void frame_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) { (void)kind; mp_obj_frame_t *frame = MP_OBJ_TO_PTR(o_in); mp_obj_code_t *code = frame->code; @@ -217,7 +217,7 @@ STATIC void frame_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t ); } -STATIC void frame_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { +static void frame_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) { if (dest[0] != MP_OBJ_NULL) { // not load attribute return; @@ -294,7 +294,7 @@ typedef struct { mp_obj_t arg; } prof_callback_args_t; -STATIC mp_obj_t mp_prof_callback_invoke(mp_obj_t callback, prof_callback_args_t *args) { +static mp_obj_t mp_prof_callback_invoke(mp_obj_t callback, prof_callback_args_t *args) { assert(mp_obj_is_callable(callback)); mp_prof_is_executing = true; @@ -474,7 +474,7 @@ typedef struct _mp_dis_instruction_t { mp_obj_t argobjex_cache; } mp_dis_instruction_t; -STATIC const byte *mp_prof_opcode_decode(const byte *ip, const mp_uint_t *const_table, mp_dis_instruction_t *instruction) { +static const byte *mp_prof_opcode_decode(const byte *ip, const mp_uint_t *const_table, mp_dis_instruction_t *instruction) { mp_uint_t unum; const byte *ptr; mp_obj_t obj; diff --git a/py/py.mk b/py/py.mk index e45ed89b8c635..bb5d8d2e91b95 100644 --- a/py/py.mk +++ b/py/py.mk @@ -223,7 +223,7 @@ PY_O += $(PY_CORE_O) # object file for frozen code specified via a manifest ifneq ($(FROZEN_MANIFEST),) -PY_O += $(BUILD)/$(BUILD)/frozen_content.o +PY_O += $(BUILD)/frozen_content.o endif # Sources that may contain qstrings diff --git a/py/qstr.c b/py/qstr.c index 41a031d101439..6a5896bdaf4ea 100644 --- a/py/qstr.c +++ b/py/qstr.c @@ -42,7 +42,11 @@ // A qstr is an index into the qstr pool. // The data for a qstr is \0 terminated (so they can be printed using printf) +#if MICROPY_QSTR_BYTES_IN_HASH #define Q_HASH_MASK ((1 << (8 * MICROPY_QSTR_BYTES_IN_HASH)) - 1) +#else +#define Q_HASH_MASK (0xffff) +#endif #if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL #define QSTR_ENTER() mp_thread_mutex_lock(&MP_STATE_VM(qstr_mutex), 1) @@ -75,8 +79,9 @@ size_t qstr_compute_hash(const byte *data, size_t len) { // it is part of the .mpy ABI. See the top of py/persistentcode.c and // static_qstr_list in makeqstrdata.py. This pool is unsorted (although in a // future .mpy version we could re-order them and make it sorted). It also -// contains additional qstrs that must have IDs <256, see operator_qstr_list +// contains additional qstrs that must have IDs <256, see unsorted_qstr_list // in makeqstrdata.py. +#if MICROPY_QSTR_BYTES_IN_HASH const qstr_hash_t mp_qstr_const_hashes_static[] = { #ifndef NO_QSTR #define QDEF0(id, hash, len, str) hash, @@ -90,6 +95,7 @@ const qstr_hash_t mp_qstr_const_hashes_static[] = { #undef TRANSLATION #endif }; +#endif const qstr_len_t mp_qstr_const_lengths_static[] = { #ifndef NO_QSTR @@ -111,7 +117,9 @@ const qstr_pool_t mp_qstr_const_pool_static = { false, // is_sorted MICROPY_ALLOC_QSTR_ENTRIES_INIT, MP_QSTRnumber_of_static, // corresponds to number of strings in array just below + #if MICROPY_QSTR_BYTES_IN_HASH (qstr_hash_t *)mp_qstr_const_hashes_static, + #endif (qstr_len_t *)mp_qstr_const_lengths_static, { #ifndef NO_QSTR @@ -130,6 +138,7 @@ const qstr_pool_t mp_qstr_const_pool_static = { // The next pool is the remainder of the qstrs defined in the firmware. This // is sorted. +#if MICROPY_QSTR_BYTES_IN_HASH const qstr_hash_t mp_qstr_const_hashes[] = { #ifndef NO_QSTR #define QDEF0(id, hash, len, str) @@ -143,6 +152,7 @@ const qstr_hash_t mp_qstr_const_hashes[] = { #undef TRANSLATION #endif }; +#endif const qstr_len_t mp_qstr_const_lengths[] = { #ifndef NO_QSTR @@ -164,7 +174,9 @@ const qstr_pool_t mp_qstr_const_pool = { true, // is_sorted MICROPY_ALLOC_QSTR_ENTRIES_INIT, MP_QSTRnumber_of - MP_QSTRnumber_of_static, // corresponds to number of strings in array just below + #if MICROPY_QSTR_BYTES_IN_HASH (qstr_hash_t *)mp_qstr_const_hashes, + #endif (qstr_len_t *)mp_qstr_const_lengths, { #ifndef NO_QSTR @@ -181,6 +193,8 @@ const qstr_pool_t mp_qstr_const_pool = { }, }; +// If frozen code is enabled, then there is an additional, sorted, ROM pool +// containing additional qstrs required by the frozen code. #ifdef MICROPY_QSTR_EXTRA_POOL extern const qstr_pool_t MICROPY_QSTR_EXTRA_POOL; #define CONST_POOL MICROPY_QSTR_EXTRA_POOL @@ -202,7 +216,7 @@ void qstr_init(void) { #endif } -STATIC const qstr_pool_t *find_qstr(qstr *q) { +static const qstr_pool_t *find_qstr(qstr *q) { // search pool for this qstr // total_prev_len==0 in the final pool, so the loop will always terminate const qstr_pool_t *pool = MP_STATE_VM(last_pool); @@ -215,8 +229,13 @@ STATIC const qstr_pool_t *find_qstr(qstr *q) { } // qstr_mutex must be taken while in this function -STATIC qstr qstr_add(mp_uint_t hash, mp_uint_t len, const char *q_ptr) { +static qstr qstr_add(mp_uint_t len, const char *q_ptr) { + #if MICROPY_QSTR_BYTES_IN_HASH + mp_uint_t hash = qstr_compute_hash((const byte *)q_ptr, len); DEBUG_printf("QSTR: add hash=%d len=%d data=%.*s\n", hash, len, len, q_ptr); + #else + DEBUG_printf("QSTR: add len=%d data=%.*s\n", len, len, q_ptr); + #endif // make sure we have room in the pool for a new qstr if (MP_STATE_VM(last_pool)->len >= MP_STATE_VM(last_pool)->alloc) { @@ -226,7 +245,11 @@ STATIC qstr qstr_add(mp_uint_t hash, mp_uint_t len, const char *q_ptr) { new_alloc = MAX(MICROPY_ALLOC_QSTR_ENTRIES_INIT, new_alloc); #endif mp_uint_t pool_size = sizeof(qstr_pool_t) - + (sizeof(const char *) + sizeof(qstr_hash_t) + sizeof(qstr_len_t)) * new_alloc; + + (sizeof(const char *) + #if MICROPY_QSTR_BYTES_IN_HASH + + sizeof(qstr_hash_t) + #endif + + sizeof(qstr_len_t)) * new_alloc; qstr_pool_t *pool = (qstr_pool_t *)m_malloc_maybe(pool_size); if (pool == NULL) { // Keep qstr_last_chunk consistent with qstr_pool_t: qstr_last_chunk is not scanned @@ -238,8 +261,12 @@ STATIC qstr qstr_add(mp_uint_t hash, mp_uint_t len, const char *q_ptr) { QSTR_EXIT(); m_malloc_fail(new_alloc); } + #if MICROPY_QSTR_BYTES_IN_HASH pool->hashes = (qstr_hash_t *)(pool->qstrs + new_alloc); pool->lengths = (qstr_len_t *)(pool->hashes + new_alloc); + #else + pool->lengths = (qstr_len_t *)(pool->qstrs + new_alloc); + #endif pool->prev = MP_STATE_VM(last_pool); pool->total_prev_len = MP_STATE_VM(last_pool)->total_prev_len + MP_STATE_VM(last_pool)->len; pool->alloc = new_alloc; @@ -250,7 +277,9 @@ STATIC qstr qstr_add(mp_uint_t hash, mp_uint_t len, const char *q_ptr) { // add the new qstr mp_uint_t at = MP_STATE_VM(last_pool)->len; + #if MICROPY_QSTR_BYTES_IN_HASH MP_STATE_VM(last_pool)->hashes[at] = hash; + #endif MP_STATE_VM(last_pool)->lengths[at] = len; MP_STATE_VM(last_pool)->qstrs[at] = q_ptr; MP_STATE_VM(last_pool)->len++; @@ -265,8 +294,10 @@ qstr qstr_find_strn(const char *str, size_t str_len) { return MP_QSTR_; } + #if MICROPY_QSTR_BYTES_IN_HASH // work out hash of str size_t str_hash = qstr_compute_hash((const byte *)str, str_len); + #endif // search pools for the data for (const qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL; pool = pool->prev) { @@ -288,7 +319,11 @@ qstr qstr_find_strn(const char *str, size_t str_len) { // sequential search for the remaining strings for (mp_uint_t at = low; at < high + 1; at++) { - if (pool->hashes[at] == str_hash && pool->lengths[at] == str_len + if ( + #if MICROPY_QSTR_BYTES_IN_HASH + pool->hashes[at] == str_hash && + #endif + pool->lengths[at] == str_len && memcmp(pool->qstrs[at], str, str_len) == 0) { return pool->total_prev_len + at; } @@ -356,10 +391,9 @@ qstr qstr_from_strn(const char *str, size_t len) { MP_STATE_VM(qstr_last_used) += n_bytes; // store the interned strings' data - size_t hash = qstr_compute_hash((const byte *)str, len); memcpy(q_ptr, str, len); q_ptr[len] = '\0'; - q = qstr_add(hash, len, q_ptr); + q = qstr_add(len, q_ptr); } QSTR_EXIT(); return q; @@ -367,7 +401,11 @@ qstr qstr_from_strn(const char *str, size_t len) { mp_uint_t qstr_hash(qstr q) { const qstr_pool_t *pool = find_qstr(&q); + #if MICROPY_QSTR_BYTES_IN_HASH return pool->hashes[q]; + #else + return qstr_compute_hash((byte *)pool->qstrs[q], pool->lengths[q]); + #endif } size_t qstr_len(qstr q) { @@ -402,7 +440,11 @@ void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, si *n_total_bytes += gc_nbytes(pool); // this counts actual bytes used in heap #else *n_total_bytes += sizeof(qstr_pool_t) - + (sizeof(const char *) + sizeof(qstr_hash_t) + sizeof(qstr_len_t)) * pool->alloc; + + (sizeof(const char *) + #if MICROPY_QSTR_BYTES_IN_HASH + + sizeof(qstr_hash_t) + #endif + + sizeof(qstr_len_t)) * pool->alloc; #endif } *n_total_bytes += *n_str_data_bytes; @@ -431,7 +473,7 @@ void qstr_dump_data(void) { #else // Emit the compressed_string_data string. -#define MP_COMPRESSED_DATA(x) STATIC const char *compressed_string_data = x; +#define MP_COMPRESSED_DATA(x) static const char *compressed_string_data = x; #define MP_MATCH_COMPRESSED(a, b) #include "genhdr/compressed.data.h" #undef MP_COMPRESSED_DATA @@ -445,7 +487,7 @@ void qstr_dump_data(void) { // The compressed string data is delimited by setting high bit in the final char of each word. // e.g. aaaa<0x80|a>bbbbbb<0x80|b>.... // This method finds the n'th string. -STATIC const byte *find_uncompressed_string(uint8_t n) { +static const byte *find_uncompressed_string(uint8_t n) { const byte *c = (byte *)compressed_string_data; while (n > 0) { while ((*c & 0x80) == 0) { diff --git a/py/qstr.h b/py/qstr.h index 426726fe556b9..967990beea398 100644 --- a/py/qstr.h +++ b/py/qstr.h @@ -64,7 +64,9 @@ enum { typedef size_t qstr; typedef uint16_t qstr_short_t; -#if MICROPY_QSTR_BYTES_IN_HASH == 1 +#if MICROPY_QSTR_BYTES_IN_HASH == 0 +// No qstr_hash_t type needed. +#elif MICROPY_QSTR_BYTES_IN_HASH == 1 typedef uint8_t qstr_hash_t; #elif MICROPY_QSTR_BYTES_IN_HASH == 2 typedef uint16_t qstr_hash_t; @@ -86,7 +88,9 @@ typedef struct _qstr_pool_t { size_t is_sorted : 1; size_t alloc; size_t len; + #if MICROPY_QSTR_BYTES_IN_HASH qstr_hash_t *hashes; + #endif qstr_len_t *lengths; const char *qstrs[]; } qstr_pool_t; @@ -98,6 +102,7 @@ void qstr_reset(void); void qstr_init(void); size_t qstr_compute_hash(const byte *data, size_t len); + qstr qstr_find_strn(const char *str, size_t str_len); // returns MP_QSTRnull if not found qstr qstr_from_str(const char *str); diff --git a/py/reader.c b/py/reader.c index d2af62cfb344d..151e04cac2c71 100644 --- a/py/reader.c +++ b/py/reader.c @@ -39,7 +39,7 @@ typedef struct _mp_reader_mem_t { const byte *end; } mp_reader_mem_t; -STATIC mp_uint_t mp_reader_mem_readbyte(void *data) { +static mp_uint_t mp_reader_mem_readbyte(void *data) { mp_reader_mem_t *reader = (mp_reader_mem_t *)data; if (reader->cur < reader->end) { return *reader->cur++; @@ -48,7 +48,7 @@ STATIC mp_uint_t mp_reader_mem_readbyte(void *data) { } } -STATIC void mp_reader_mem_close(void *data) { +static void mp_reader_mem_close(void *data) { mp_reader_mem_t *reader = (mp_reader_mem_t *)data; if (reader->free_len > 0) { m_del(char, (char *)reader->beg, reader->free_len); @@ -81,7 +81,7 @@ typedef struct _mp_reader_posix_t { byte buf[20]; } mp_reader_posix_t; -STATIC mp_uint_t mp_reader_posix_readbyte(void *data) { +static mp_uint_t mp_reader_posix_readbyte(void *data) { mp_reader_posix_t *reader = (mp_reader_posix_t *)data; if (reader->pos >= reader->len) { if (reader->len == 0) { @@ -101,7 +101,7 @@ STATIC mp_uint_t mp_reader_posix_readbyte(void *data) { return reader->buf[reader->pos++]; } -STATIC void mp_reader_posix_close(void *data) { +static void mp_reader_posix_close(void *data) { mp_reader_posix_t *reader = (mp_reader_posix_t *)data; if (reader->close_fd) { MP_THREAD_GIL_EXIT(); diff --git a/py/repl.c b/py/repl.c index a40aa5b85a49b..ed47dbd0c174a 100644 --- a/py/repl.c +++ b/py/repl.c @@ -48,7 +48,7 @@ const char *mp_repl_get_psx(unsigned int entry) { } #endif -STATIC bool str_startswith_word(const char *str, const char *head) { +static bool str_startswith_word(const char *str, const char *head) { size_t i; for (i = 0; str[i] && head[i]; i++) { if (str[i] != head[i]) { @@ -159,7 +159,7 @@ bool mp_repl_continue_with_input(const char *input) { return false; } -STATIC bool test_qstr(mp_obj_t obj, qstr name) { +static bool test_qstr(mp_obj_t obj, qstr name) { if (obj) { // try object member mp_obj_t dest[2]; @@ -186,7 +186,7 @@ STATIC bool test_qstr(mp_obj_t obj, qstr name) { } } -STATIC const char *find_completions(const char *s_start, size_t s_len, +static const char *find_completions(const char *s_start, size_t s_len, mp_obj_t obj, size_t *match_len, qstr *q_first, qstr *q_last) { const char *match_str = NULL; @@ -226,7 +226,7 @@ STATIC const char *find_completions(const char *s_start, size_t s_len, return match_str; } -STATIC void print_completions(const mp_print_t *print, +static void print_completions(const mp_print_t *print, const char *s_start, size_t s_len, mp_obj_t obj, qstr q_first, qstr q_last) { diff --git a/py/runtime.c b/py/runtime.c index 24caceaaac8b7..83aee5bc7b22c 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -183,6 +183,10 @@ void mp_init(void) { MP_STATE_VM(bluetooth) = MP_OBJ_NULL; #endif + #if MICROPY_HW_ENABLE_USB_RUNTIME_DEVICE + MP_STATE_VM(usbd) = MP_OBJ_NULL; + #endif + #if MICROPY_PY_THREAD_GIL mp_thread_mutex_init(&MP_STATE_VM(gil_mutex)); #endif @@ -750,7 +754,7 @@ mp_obj_t mp_call_method_n_kw(size_t n_args, size_t n_kw, const mp_obj_t *args) { // This function only needs to be exposed externally when in stackless mode. #if !MICROPY_STACKLESS -STATIC +static #endif // CIRCUITPY-CHANGE: PLACE_IN_ITCM void PLACE_IN_ITCM(mp_call_prepare_args_n_kw_var)(bool have_self, size_t n_args_n_kw, const mp_obj_t *args, mp_call_args_t *out_args) { @@ -1102,7 +1106,7 @@ typedef struct _mp_obj_checked_fun_t { mp_obj_t fun; } mp_obj_checked_fun_t; -STATIC mp_obj_t checked_fun_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t checked_fun_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_obj_checked_fun_t *self = MP_OBJ_TO_PTR(self_in); if (n_args > 0) { const mp_obj_type_t *arg0_type = mp_obj_get_type(args[0]); @@ -1114,14 +1118,14 @@ STATIC mp_obj_t checked_fun_call(mp_obj_t self_in, size_t n_args, size_t n_kw, c return mp_call_function_n_kw(self->fun, n_args, n_kw, args); } -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( mp_type_checked_fun, MP_QSTR_function, MP_TYPE_FLAG_BINDS_SELF, call, checked_fun_call ); -STATIC mp_obj_t mp_obj_new_checked_fun(const mp_obj_type_t *type, mp_obj_t fun) { +static mp_obj_t mp_obj_new_checked_fun(const mp_obj_type_t *type, mp_obj_t fun) { mp_obj_checked_fun_t *o = mp_obj_malloc(mp_obj_checked_fun_t, &mp_type_checked_fun); o->type = type; o->fun = fun; @@ -1416,7 +1420,7 @@ mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) { } -STATIC mp_fun_1_t type_get_iternext(const mp_obj_type_t *type) { +static mp_fun_1_t type_get_iternext(const mp_obj_type_t *type) { if ((type->flags & MP_TYPE_FLAG_ITER_IS_STREAM) == MP_TYPE_FLAG_ITER_IS_STREAM) { return mp_stream_unbuffered_iter; } else if (type->flags & MP_TYPE_FLAG_ITER_IS_ITERNEXT) { diff --git a/py/runtime.h b/py/runtime.h index 379dd65c81e36..b92eb23c9d7bf 100644 --- a/py/runtime.h +++ b/py/runtime.h @@ -30,6 +30,7 @@ #include "py/mpstate.h" #include "py/pystack.h" +#include "py/stackctrl.h" // CIRCUITPY-CHANGE #include "supervisor/linker.h" @@ -183,6 +184,32 @@ static inline void mp_globals_set(mp_obj_dict_t *d) { void mp_globals_locals_set_from_nlr_jump_callback(void *ctx_in); void mp_call_function_1_from_nlr_jump_callback(void *ctx_in); +#if MICROPY_PY_THREAD +static inline void mp_thread_init_state(mp_state_thread_t *ts, size_t stack_size, mp_obj_dict_t *locals, mp_obj_dict_t *globals) { + mp_thread_set_state(ts); + + mp_stack_set_top(ts + 1); // need to include ts in root-pointer scan + mp_stack_set_limit(stack_size); + + // GC starts off unlocked + ts->gc_lock_depth = 0; + + // There are no pending jump callbacks or exceptions yet + ts->nlr_jump_callback_top = NULL; + ts->mp_pending_exception = MP_OBJ_NULL; + + // If locals/globals are not given, inherit from main thread + if (locals == NULL) { + locals = mp_state_ctx.thread.dict_locals; + } + if (globals == NULL) { + globals = mp_state_ctx.thread.dict_globals; + } + mp_locals_set(locals); + mp_globals_set(globals); +} +#endif + mp_obj_t mp_load_name(qstr qst); mp_obj_t mp_load_global(qstr qst); mp_obj_t mp_load_build_class(void); diff --git a/py/runtime0.h b/py/runtime0.h index 87a7c6fd1579d..86c48a6eaa7d6 100644 --- a/py/runtime0.h +++ b/py/runtime0.h @@ -26,12 +26,13 @@ #ifndef MICROPY_INCLUDED_PY_RUNTIME0_H #define MICROPY_INCLUDED_PY_RUNTIME0_H -// CIRCUITPY-CHANGE -#include "mpconfig.h" - -// The first four must fit in 8 bits, see emitbc.c -// The remaining must fit in 16 bits, see scope.h -// and must match definitions in mpy-tool.py and mpy_ld.py +// These constants are used by: +// - mp_raw_code_t::is_generator (only MP_SCOPE_FLAG_GENERATOR) +// CIRCUITPY-CHANGE: distinguish generator and async +// - mp_raw_code_t::is_generator (only MP_SCOPE_FLAG_ASYNC) +// - scope_t::scope_flags (16 bits) +// - MP_BC_PRELUDE_SIG_ENCODE macro, masked by MP_SCOPE_FLAG_ALL_SIG (4 bits) +// - tools/mpy_ld.py, when generating mpy files (maximum 7 bits) #define MP_SCOPE_FLAG_ALL_SIG (0x1f) #define MP_SCOPE_FLAG_GENERATOR (0x01) #define MP_SCOPE_FLAG_VARKEYWORDS (0x02) diff --git a/py/scope.c b/py/scope.c index 8fc0943289b4f..4893e7cc4e5e1 100644 --- a/py/scope.c +++ b/py/scope.c @@ -31,7 +31,9 @@ #if MICROPY_ENABLE_COMPILER // These low numbered qstrs should fit in 8 bits. See assertions below. -STATIC const uint8_t scope_simple_name_table[] = { +// The (unescaped) names appear in `unsorted_str_list` in the QSTR +// generator script py/makeqstrdata.py to ensure they are assigned low numbers. +static const uint8_t scope_simple_name_table[] = { [SCOPE_MODULE] = MP_QSTR__lt_module_gt_, [SCOPE_LAMBDA] = MP_QSTR__lt_lambda_gt_, [SCOPE_LIST_COMP] = MP_QSTR__lt_listcomp_gt_, @@ -111,7 +113,7 @@ id_info_t *scope_find_global(scope_t *scope, qstr qst) { return scope_find(scope, qst); } -STATIC void scope_close_over_in_parents(scope_t *scope, qstr qst) { +static void scope_close_over_in_parents(scope_t *scope, qstr qst) { assert(scope->parent != NULL); // we should have at least 1 parent for (scope_t *s = scope->parent;; s = s->parent) { assert(s->parent != NULL); // we should not get to the outer scope diff --git a/py/scope.h b/py/scope.h index e7d2a304f79f3..927c4a7b93e2b 100644 --- a/py/scope.h +++ b/py/scope.h @@ -76,6 +76,9 @@ typedef struct _scope_t { struct _scope_t *next; mp_parse_node_t pn; mp_raw_code_t *raw_code; + #if MICROPY_DEBUG_PRINTERS + size_t raw_code_data_len; // for mp_bytecode_print + #endif uint16_t simple_name; // a qstr uint16_t scope_flags; // see runtime0.h uint16_t emit_options; // see emitglue.h diff --git a/py/showbc.c b/py/showbc.c index f9c334b93bbbb..6913d18c1ca82 100644 --- a/py/showbc.c +++ b/py/showbc.c @@ -83,7 +83,7 @@ DECODE_UINT; \ unum = (mp_uint_t)obj_table[unum] -void mp_bytecode_print(const mp_print_t *print, const mp_raw_code_t *rc, const mp_module_constants_t *cm) { +void mp_bytecode_print(const mp_print_t *print, const mp_raw_code_t *rc, size_t fun_data_len, const mp_module_constants_t *cm) { const byte *ip_start = rc->fun_data; const byte *ip = rc->fun_data; @@ -100,13 +100,13 @@ void mp_bytecode_print(const mp_print_t *print, const mp_raw_code_t *rc, const m qstr source_file = cm->source_file; #endif mp_printf(print, "File %s, code block '%s' (descriptor: %p, bytecode @%p %u bytes)\n", - qstr_str(source_file), qstr_str(block_name), rc, ip_start, (unsigned)rc->fun_data_len); + qstr_str(source_file), qstr_str(block_name), rc, ip_start, (unsigned)fun_data_len); // raw bytecode dump size_t prelude_size = ip - ip_start + n_info + n_cell; mp_printf(print, "Raw bytecode (code_info_size=%u, bytecode_size=%u):\n", - (unsigned)prelude_size, (unsigned)(rc->fun_data_len - prelude_size)); - for (size_t i = 0; i < rc->fun_data_len; i++) { + (unsigned)prelude_size, (unsigned)(fun_data_len - prelude_size)); + for (size_t i = 0; i < fun_data_len; i++) { if (i > 0 && i % 16 == 0) { mp_printf(print, "\n"); } @@ -158,7 +158,7 @@ void mp_bytecode_print(const mp_print_t *print, const mp_raw_code_t *rc, const m mp_printf(print, " bc=" INT_FMT " line=" UINT_FMT "\n", bc, source_line); } } - mp_bytecode_print2(print, ip, rc->fun_data_len - prelude_size, rc->children, cm); + mp_bytecode_print2(print, ip, fun_data_len - prelude_size, rc->children, cm); } const byte *mp_bytecode_print_str(const mp_print_t *print, const byte *ip_start, const byte *ip, mp_raw_code_t *const *child_table, const mp_module_constants_t *cm) { diff --git a/py/stream.c b/py/stream.c index 7f62b3be9d617..fbf7fd878a133 100644 --- a/py/stream.c +++ b/py/stream.c @@ -38,7 +38,7 @@ // TODO: should be in mpconfig.h #define DEFAULT_BUFFER_SIZE 256 -STATIC mp_obj_t stream_readall(mp_obj_t self_in); +static mp_obj_t stream_readall(mp_obj_t self_in); // Returns error condition in *errcode, if non-zero, return value is number of bytes written // before error condition occurred. If *errcode == 0, returns total bytes written (which will @@ -82,6 +82,18 @@ mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf_, mp_uint_t size, int *errcode return done; } +mp_off_t mp_stream_seek(mp_obj_t stream, mp_off_t offset, int whence, int *errcode) { + struct mp_stream_seek_t seek_s; + seek_s.offset = offset; + seek_s.whence = whence; + const mp_stream_p_t *stream_p = mp_get_stream(stream); + mp_uint_t res = stream_p->ioctl(MP_OBJ_FROM_PTR(stream), MP_STREAM_SEEK, (mp_uint_t)(uintptr_t)&seek_s, errcode); + if (res == MP_STREAM_ERROR) { + return (mp_off_t)-1; + } + return seek_s.offset; +} + const mp_stream_p_t *mp_get_stream_raise(mp_obj_t self_in, int flags) { // CIRCUITPY-CHANGE: using type-safe protocol accessor const mp_stream_p_t *stream_p = mp_get_stream(self_in); @@ -95,7 +107,7 @@ const mp_stream_p_t *mp_get_stream_raise(mp_obj_t self_in, int flags) { mp_raise_msg(&mp_type_OSError, MP_ERROR_TEXT("stream operation not supported")); } -STATIC mp_obj_t stream_read_generic(size_t n_args, const mp_obj_t *args, byte flags) { +static mp_obj_t stream_read_generic(size_t n_args, const mp_obj_t *args, byte flags) { // What to do if sz < -1? Python docs don't specify this case. // CPython does a readall, but here we silently let negatives through, // and they will cause a MemoryError. @@ -217,12 +229,12 @@ STATIC mp_obj_t stream_read_generic(size_t n_args, const mp_obj_t *args, byte fl } } -STATIC mp_obj_t stream_read(size_t n_args, const mp_obj_t *args) { +static mp_obj_t stream_read(size_t n_args, const mp_obj_t *args) { return stream_read_generic(n_args, args, MP_STREAM_RW_READ); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_read_obj, 1, 2, stream_read); -STATIC mp_obj_t stream_read1(size_t n_args, const mp_obj_t *args) { +static mp_obj_t stream_read1(size_t n_args, const mp_obj_t *args) { return stream_read_generic(n_args, args, MP_STREAM_RW_READ | MP_STREAM_RW_ONCE); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_read1_obj, 1, 2, stream_read1); @@ -248,7 +260,7 @@ void mp_stream_write_adaptor(void *self, const char *buf, size_t len) { mp_stream_write(MP_OBJ_FROM_PTR(self), buf, len, MP_STREAM_RW_WRITE); } -STATIC mp_obj_t stream_write_method(size_t n_args, const mp_obj_t *args) { +static mp_obj_t stream_write_method(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ); size_t max_len = (size_t)-1; @@ -267,14 +279,14 @@ STATIC mp_obj_t stream_write_method(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_write_obj, 2, 4, stream_write_method); -STATIC mp_obj_t stream_write1_method(mp_obj_t self_in, mp_obj_t arg) { +static mp_obj_t stream_write1_method(mp_obj_t self_in, mp_obj_t arg) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(arg, &bufinfo, MP_BUFFER_READ); return mp_stream_write(self_in, bufinfo.buf, bufinfo.len, MP_STREAM_RW_WRITE | MP_STREAM_RW_ONCE); } MP_DEFINE_CONST_FUN_OBJ_2(mp_stream_write1_obj, stream_write1_method); -STATIC mp_obj_t stream_readinto(size_t n_args, const mp_obj_t *args) { +static mp_obj_t stream_readinto(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo; mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_WRITE); @@ -302,7 +314,7 @@ STATIC mp_obj_t stream_readinto(size_t n_args, const mp_obj_t *args) { } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_readinto_obj, 2, 3, stream_readinto); -STATIC mp_obj_t stream_readall(mp_obj_t self_in) { +static mp_obj_t stream_readall(mp_obj_t self_in) { const mp_stream_p_t *stream_p = mp_get_stream(self_in); mp_uint_t total_size = 0; @@ -347,7 +359,7 @@ STATIC mp_obj_t stream_readall(mp_obj_t self_in) { } // Unbuffered, inefficient implementation of readline() for raw I/O files. -STATIC mp_obj_t stream_unbuffered_readline(size_t n_args, const mp_obj_t *args) { +static mp_obj_t stream_unbuffered_readline(size_t n_args, const mp_obj_t *args) { const mp_stream_p_t *stream_p = mp_get_stream(args[0]); mp_int_t max_size = -1; @@ -405,7 +417,7 @@ STATIC mp_obj_t stream_unbuffered_readline(size_t n_args, const mp_obj_t *args) MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_unbuffered_readline_obj, 1, 2, stream_unbuffered_readline); // TODO take an optional extra argument (what does it do exactly?) -STATIC mp_obj_t stream_unbuffered_readlines(mp_obj_t self) { +static mp_obj_t stream_unbuffered_readlines(mp_obj_t self) { mp_obj_t lines = mp_obj_new_list(0, NULL); for (;;) { mp_obj_t line = stream_unbuffered_readline(1, &self); @@ -437,39 +449,37 @@ mp_obj_t mp_stream_close(mp_obj_t stream) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_close_obj, mp_stream_close); -STATIC mp_obj_t mp_stream___exit__(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_stream___exit__(size_t n_args, const mp_obj_t *args) { (void)n_args; return mp_stream_close(args[0]); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream___exit___obj, 4, 4, mp_stream___exit__); -STATIC mp_obj_t stream_seek(size_t n_args, const mp_obj_t *args) { - struct mp_stream_seek_t seek_s; +static mp_obj_t stream_seek(size_t n_args, const mp_obj_t *args) { // TODO: Could be uint64 - seek_s.offset = mp_obj_get_int(args[1]); - seek_s.whence = SEEK_SET; + mp_off_t offset = mp_obj_get_int(args[1]); + int whence = SEEK_SET; if (n_args == 3) { - seek_s.whence = mp_obj_get_int(args[2]); + whence = mp_obj_get_int(args[2]); } // In POSIX, it's error to seek before end of stream, we enforce it here. - if (seek_s.whence == SEEK_SET && seek_s.offset < 0) { + if (whence == SEEK_SET && offset < 0) { mp_raise_OSError(MP_EINVAL); } - const mp_stream_p_t *stream_p = mp_get_stream(args[0]); int error; - mp_uint_t res = stream_p->ioctl(args[0], MP_STREAM_SEEK, (mp_uint_t)(uintptr_t)&seek_s, &error); - if (res == MP_STREAM_ERROR) { + mp_off_t res = mp_stream_seek(args[0], offset, whence, &error); + if (res == (mp_off_t)-1) { mp_raise_OSError(error); } // TODO: Could be uint64 - return mp_obj_new_int_from_uint(seek_s.offset); + return mp_obj_new_int_from_uint(res); } MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_stream_seek_obj, 2, 3, stream_seek); -STATIC mp_obj_t stream_tell(mp_obj_t self) { +static mp_obj_t stream_tell(mp_obj_t self) { mp_obj_t offset = MP_OBJ_NEW_SMALL_INT(0); mp_obj_t whence = MP_OBJ_NEW_SMALL_INT(SEEK_CUR); const mp_obj_t args[3] = {self, offset, whence}; @@ -489,7 +499,7 @@ mp_obj_t mp_stream_flush(mp_obj_t self) { } MP_DEFINE_CONST_FUN_OBJ_1(mp_stream_flush_obj, mp_stream_flush); -STATIC mp_obj_t stream_ioctl(size_t n_args, const mp_obj_t *args) { +static mp_obj_t stream_ioctl(size_t n_args, const mp_obj_t *args) { mp_buffer_info_t bufinfo; uintptr_t val = 0; if (n_args > 2) { @@ -545,16 +555,11 @@ ssize_t mp_stream_posix_read(void *stream, void *buf, size_t len) { } off_t mp_stream_posix_lseek(void *stream, off_t offset, int whence) { - const mp_obj_base_t *o = stream; - const mp_stream_p_t *stream_p = MP_OBJ_TYPE_GET_SLOT(o->type, protocol); - struct mp_stream_seek_t seek_s; - seek_s.offset = offset; - seek_s.whence = whence; - mp_uint_t res = stream_p->ioctl(MP_OBJ_FROM_PTR(stream), MP_STREAM_SEEK, (mp_uint_t)(uintptr_t)&seek_s, &errno); - if (res == MP_STREAM_ERROR) { + mp_off_t res = mp_stream_seek(MP_OBJ_FROM_PTR(stream), offset, whence, &errno); + if (res == (mp_off_t)-1) { return -1; } - return seek_s.offset; + return res; } int mp_stream_posix_fsync(void *stream) { diff --git a/py/stream.h b/py/stream.h index 8ee4fe055b3fc..5e1cd5d441302 100644 --- a/py/stream.h +++ b/py/stream.h @@ -124,6 +124,7 @@ mp_obj_t mp_stream_write(mp_obj_t self_in, const void *buf, size_t len, byte fla mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf, mp_uint_t size, int *errcode, byte flags); #define mp_stream_write_exactly(stream, buf, size, err) mp_stream_rw(stream, (byte *)buf, size, err, MP_STREAM_RW_WRITE) #define mp_stream_read_exactly(stream, buf, size, err) mp_stream_rw(stream, buf, size, err, MP_STREAM_RW_READ) +mp_off_t mp_stream_seek(mp_obj_t stream, mp_off_t offset, int whence, int *errcode); void mp_stream_write_adaptor(void *self, const char *buf, size_t len); // CIRCUITPY-CHANGE: make public diff --git a/py/unicode.c b/py/unicode.c index 5acaad378843c..81a37880f3c72 100644 --- a/py/unicode.c +++ b/py/unicode.c @@ -48,7 +48,7 @@ #define AT_LX (FL_LOWER | FL_ALPHA | FL_PRINT | FL_XDIGIT) // table of attributes for ascii characters -STATIC const uint8_t attr[] = { +static const uint8_t attr[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, AT_SP, AT_SP, AT_SP, AT_SP, AT_SP, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, diff --git a/py/vm.c b/py/vm.c index d58efa08309a1..6fd1778261971 100644 --- a/py/vm.c +++ b/py/vm.c @@ -196,7 +196,7 @@ #endif // MICROPY_PY_SYS_SETTRACE // CIRCUITPY-CHANGE -STATIC mp_obj_t get_active_exception(mp_exc_stack_t *exc_sp, mp_exc_stack_t *exc_stack) { +static mp_obj_t get_active_exception(mp_exc_stack_t *exc_sp, mp_exc_stack_t *exc_stack) { for (mp_exc_stack_t *e = exc_sp; e >= exc_stack; --e) { if (e->prev_exc != NULL) { return MP_OBJ_FROM_PTR(e->prev_exc); @@ -915,7 +915,7 @@ unwind_jump:; ENTRY(MP_BC_MAKE_FUNCTION): { DECODE_PTR; - PUSH(mp_make_function_from_raw_code(ptr, code_state->fun_bc->context, NULL)); + PUSH(mp_make_function_from_proto_fun(ptr, code_state->fun_bc->context, NULL)); DISPATCH(); } @@ -923,7 +923,7 @@ unwind_jump:; DECODE_PTR; // Stack layout: def_tuple def_dict <- TOS sp -= 1; - SET_TOP(mp_make_function_from_raw_code(ptr, code_state->fun_bc->context, sp)); + SET_TOP(mp_make_function_from_proto_fun(ptr, code_state->fun_bc->context, sp)); DISPATCH(); } @@ -932,7 +932,7 @@ unwind_jump:; size_t n_closed_over = *ip++; // Stack layout: closed_overs <- TOS sp -= n_closed_over - 1; - SET_TOP(mp_make_closure_from_raw_code(ptr, code_state->fun_bc->context, n_closed_over, sp)); + SET_TOP(mp_make_closure_from_proto_fun(ptr, code_state->fun_bc->context, n_closed_over, sp)); DISPATCH(); } @@ -941,7 +941,7 @@ unwind_jump:; size_t n_closed_over = *ip++; // Stack layout: def_tuple def_dict closed_overs <- TOS sp -= 2 + n_closed_over - 1; - SET_TOP(mp_make_closure_from_raw_code(ptr, code_state->fun_bc->context, 0x100 | n_closed_over, sp)); + SET_TOP(mp_make_closure_from_proto_fun(ptr, code_state->fun_bc->context, 0x100 | n_closed_over, sp)); DISPATCH(); } diff --git a/py/vstr.c b/py/vstr.c index 46d1a0b9e8e46..00972edf89796 100644 --- a/py/vstr.c +++ b/py/vstr.c @@ -108,7 +108,7 @@ char *vstr_extend(vstr_t *vstr, size_t size) { return p; } -STATIC void vstr_ensure_extra(vstr_t *vstr, size_t size) { +static void vstr_ensure_extra(vstr_t *vstr, size_t size) { if (vstr->len + size > vstr->alloc) { if (vstr->fixed_buf) { // We can't reallocate, and the caller is expecting the space to @@ -187,7 +187,7 @@ void vstr_add_strn(vstr_t *vstr, const char *str, size_t len) { vstr->len += len; } -STATIC char *vstr_ins_blank_bytes(vstr_t *vstr, size_t byte_pos, size_t byte_len) { +static char *vstr_ins_blank_bytes(vstr_t *vstr, size_t byte_pos, size_t byte_len) { size_t l = vstr->len; if (byte_pos > l) { byte_pos = l; diff --git a/pyproject.toml b/pyproject.toml index 79b661bfa5581..271171183a4cb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,2 +1,6 @@ +# SPDX-FileCopyrightText: 2024 Scott Shawcroft for Adafruit Industries +# +# SPDX-License-Identifier: MIT + [tool.setuptools_scm] # can be empty if no extra settings are needed, presence enables setuptools-scm diff --git a/shared-bindings/_bleio/Service.c b/shared-bindings/_bleio/Service.c index 00da34c8bce2d..6f6e686c70521 100644 --- a/shared-bindings/_bleio/Service.c +++ b/shared-bindings/_bleio/Service.c @@ -41,8 +41,7 @@ static mp_obj_t bleio_service_make_new(const mp_obj_type_t *type, size_t n_args, const bool is_secondary = args[ARG_secondary].u_bool; - bleio_service_obj_t *service = m_new_obj_with_finaliser(bleio_service_obj_t); - service->base.type = &bleio_service_type; + bleio_service_obj_t *service = mp_obj_malloc_with_finaliser(bleio_service_obj_t, &bleio_service_type); common_hal_bleio_service_construct(service, uuid, is_secondary); diff --git a/shared-bindings/analogbufio/BufferedIn.c b/shared-bindings/analogbufio/BufferedIn.c index 6627715ae3972..e5a5d3600ab61 100644 --- a/shared-bindings/analogbufio/BufferedIn.c +++ b/shared-bindings/analogbufio/BufferedIn.c @@ -55,8 +55,7 @@ static mp_obj_t analogbufio_bufferedin_make_new(const mp_obj_type_t *type, size_ const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[ARG_pin].u_obj, MP_QSTR_pin); // Create local object - analogbufio_bufferedin_obj_t *self = m_new_obj_with_finaliser(analogbufio_bufferedin_obj_t); - self->base.type = &analogbufio_bufferedin_type; + analogbufio_bufferedin_obj_t *self = mp_obj_malloc_with_finaliser(analogbufio_bufferedin_obj_t, &analogbufio_bufferedin_type); // Call local interface in ports/common-hal/analogbufio common_hal_analogbufio_bufferedin_construct(self, pin, args[ARG_sample_rate].u_int); diff --git a/shared-bindings/audiobusio/I2SOut.c b/shared-bindings/audiobusio/I2SOut.c index 4b6d57ba18d4d..7c24e8a9efe81 100644 --- a/shared-bindings/audiobusio/I2SOut.c +++ b/shared-bindings/audiobusio/I2SOut.c @@ -97,8 +97,7 @@ static mp_obj_t audiobusio_i2sout_make_new(const mp_obj_type_t *type, size_t n_a const mcu_pin_obj_t *data = validate_obj_is_free_pin(args[ARG_data].u_obj, MP_QSTR_data); const mcu_pin_obj_t *main_clock = validate_obj_is_free_pin_or_none(args[ARG_main_clock].u_obj, MP_QSTR_main_clock); - audiobusio_i2sout_obj_t *self = m_new_obj_with_finaliser(audiobusio_i2sout_obj_t); - self->base.type = &audiobusio_i2sout_type; + audiobusio_i2sout_obj_t *self = mp_obj_malloc_with_finaliser(audiobusio_i2sout_obj_t, &audiobusio_i2sout_type); common_hal_audiobusio_i2sout_construct(self, bit_clock, word_select, data, main_clock, args[ARG_left_justified].u_bool); return MP_OBJ_FROM_PTR(self); diff --git a/shared-bindings/audioio/AudioOut.c b/shared-bindings/audioio/AudioOut.c index ceeaf1f399077..4d5765aa210cf 100644 --- a/shared-bindings/audioio/AudioOut.c +++ b/shared-bindings/audioio/AudioOut.c @@ -90,8 +90,7 @@ static mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar validate_obj_is_free_pin_or_none(args[ARG_right_channel].u_obj, MP_QSTR_right_channel); // create AudioOut object from the given pin - audioio_audioout_obj_t *self = m_new_obj_with_finaliser(audioio_audioout_obj_t); - self->base.type = &audioio_audioout_type; + audioio_audioout_obj_t *self = mp_obj_malloc_with_finaliser(audioio_audioout_obj_t, &audioio_audioout_type); common_hal_audioio_audioout_construct(self, left_channel_pin, right_channel_pin, args[ARG_quiescent_value].u_int); return MP_OBJ_FROM_PTR(self); diff --git a/shared-bindings/audiomixer/Mixer.c b/shared-bindings/audiomixer/Mixer.c index 149e98584db2c..4f38b2b7bafab 100644 --- a/shared-bindings/audiomixer/Mixer.c +++ b/shared-bindings/audiomixer/Mixer.c @@ -83,7 +83,7 @@ static mp_obj_t audiomixer_mixer_make_new(const mp_obj_type_t *type, size_t n_ar mp_raise_ValueError(MP_ERROR_TEXT("bits_per_sample must be 8 or 16")); } audiomixer_mixer_obj_t *self = - mp_obj_malloc_var(audiomixer_mixer_obj_t, mp_obj_t, voice_count, &audiomixer_mixer_type); + mp_obj_malloc_var(audiomixer_mixer_obj_t, voice, mp_obj_t, voice_count, &audiomixer_mixer_type); common_hal_audiomixer_mixer_construct(self, voice_count, args[ARG_buffer_size].u_int, bits_per_sample, args[ARG_samples_signed].u_bool, channel_count, sample_rate); for (int v = 0; v < voice_count; v++) { diff --git a/shared-bindings/audiomp3/MP3Decoder.c b/shared-bindings/audiomp3/MP3Decoder.c index ff715720d0282..8e6df36462e0c 100644 --- a/shared-bindings/audiomp3/MP3Decoder.c +++ b/shared-bindings/audiomp3/MP3Decoder.c @@ -89,8 +89,7 @@ static mp_obj_t audiomp3_mp3file_make_new(const mp_obj_type_t *type, size_t n_ar stream = mp_call_function_2(MP_OBJ_FROM_PTR(&mp_builtin_open_obj), stream, MP_ROM_QSTR(MP_QSTR_rb)); } - audiomp3_mp3file_obj_t *self = m_new_obj_with_finaliser(audiomp3_mp3file_obj_t); - self->base.type = &audiomp3_mp3file_type; + audiomp3_mp3file_obj_t *self = mp_obj_malloc_with_finaliser(audiomp3_mp3file_obj_t, &audiomp3_mp3file_type); const mp_stream_p_t *stream_p = mp_get_stream_raise(stream, MP_STREAM_OP_READ); diff --git a/shared-bindings/audiopwmio/PWMAudioOut.c b/shared-bindings/audiopwmio/PWMAudioOut.c index 3b75df16ec457..deb60bd420e02 100644 --- a/shared-bindings/audiopwmio/PWMAudioOut.c +++ b/shared-bindings/audiopwmio/PWMAudioOut.c @@ -99,8 +99,7 @@ static mp_obj_t audiopwmio_pwmaudioout_make_new(const mp_obj_type_t *type, size_ // create AudioOut object from the given pin // The object is created with a finaliser as some ports use these (rather than 'reset' functions) // to ensure resources are collected at interpreter shutdown. - audiopwmio_pwmaudioout_obj_t *self = m_new_obj_with_finaliser(audiopwmio_pwmaudioout_obj_t); - self->base.type = &audiopwmio_pwmaudioout_type; + audiopwmio_pwmaudioout_obj_t *self = mp_obj_malloc_with_finaliser(audiopwmio_pwmaudioout_obj_t, &audiopwmio_pwmaudioout_type); common_hal_audiopwmio_pwmaudioout_construct(self, left_channel_pin, right_channel_pin, args[ARG_quiescent_value].u_int); return MP_OBJ_FROM_PTR(self); diff --git a/shared-bindings/aurora_epaper/__init__.c b/shared-bindings/aurora_epaper/__init__.c index dedd9995e316c..a17e8319af7ae 100644 --- a/shared-bindings/aurora_epaper/__init__.c +++ b/shared-bindings/aurora_epaper/__init__.c @@ -5,7 +5,7 @@ #include "shared-bindings/aurora_epaper/aurora_framebuffer.h" -STATIC const mp_rom_map_elem_t aurora_epaper_module_globals_table[] = { +static const mp_rom_map_elem_t aurora_epaper_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_aurora_epaper) }, { MP_ROM_QSTR(MP_QSTR_AuroraMemoryFramebuffer), MP_ROM_PTR(&aurora_framebuffer_type) }, }; diff --git a/shared-bindings/busio/UART.c b/shared-bindings/busio/UART.c index 3a7a602848573..eb918fc75313c 100644 --- a/shared-bindings/busio/UART.c +++ b/shared-bindings/busio/UART.c @@ -151,8 +151,7 @@ static mp_obj_t busio_uart_make_new(const mp_obj_type_t *type, size_t n_args, si const bool rs485_invert = args[ARG_rs485_invert].u_bool; - busio_uart_obj_t *self = m_new_obj_with_finaliser(busio_uart_obj_t); - self->base.type = &busio_uart_type; + busio_uart_obj_t *self = mp_obj_malloc_with_finaliser(busio_uart_obj_t, &busio_uart_type); common_hal_busio_uart_construct(self, tx, rx, rts, cts, rs485_dir, rs485_invert, args[ARG_baudrate].u_int, bits, parity, stop, timeout, diff --git a/shared-bindings/countio/Counter.c b/shared-bindings/countio/Counter.c index 5fa2a7a30fa22..7ca09c7df6e1c 100644 --- a/shared-bindings/countio/Counter.c +++ b/shared-bindings/countio/Counter.c @@ -65,8 +65,7 @@ static mp_obj_t countio_counter_make_new(const mp_obj_type_t *type, size_t n_arg const mcu_pin_obj_t *pin = validate_obj_is_free_pin(args[ARG_pin].u_obj, MP_QSTR_pin); const countio_edge_t edge = validate_edge(args[ARG_edge].u_obj, MP_QSTR_edge); const digitalio_pull_t pull = validate_pull(args[ARG_pull].u_obj, MP_QSTR_pull); - countio_counter_obj_t *self = m_new_obj_with_finaliser(countio_counter_obj_t); - self->base.type = &countio_counter_type; + countio_counter_obj_t *self = mp_obj_malloc_with_finaliser(countio_counter_obj_t, &countio_counter_type); common_hal_countio_counter_construct(self, pin, edge, pull); diff --git a/shared-bindings/frequencyio/FrequencyIn.c b/shared-bindings/frequencyio/FrequencyIn.c index 5bd18658d70b8..6d76d00d0fa48 100644 --- a/shared-bindings/frequencyio/FrequencyIn.c +++ b/shared-bindings/frequencyio/FrequencyIn.c @@ -64,8 +64,7 @@ static mp_obj_t frequencyio_frequencyin_make_new(const mp_obj_type_t *type, size const uint16_t capture_period = args[ARG_capture_period].u_int; - frequencyio_frequencyin_obj_t *self = m_new_obj_with_finaliser(frequencyio_frequencyin_obj_t); - self->base.type = &frequencyio_frequencyin_type; + frequencyio_frequencyin_obj_t *self = mp_obj_malloc_with_finaliser(frequencyio_frequencyin_obj_t, &frequencyio_frequencyin_type); common_hal_frequencyio_frequencyin_construct(self, pin, capture_period); return MP_OBJ_FROM_PTR(self); diff --git a/shared-bindings/gnss/GNSS.c b/shared-bindings/gnss/GNSS.c index 75093e7b55b49..39d6aba682c77 100644 --- a/shared-bindings/gnss/GNSS.c +++ b/shared-bindings/gnss/GNSS.c @@ -36,7 +36,7 @@ //| //| :param system: satellite system to use""" //| ... -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) { +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 = mp_obj_malloc(gnss_obj_t, &gnss_type); enum { ARG_system }; static const mp_arg_t allowed_args[] = { @@ -69,14 +69,14 @@ STATIC mp_obj_t gnss_make_new(const mp_obj_type_t *type, size_t n_args, size_t n //| def deinit(self) -> None: //| """Turn off the GNSS.""" //| ... -STATIC mp_obj_t gnss_obj_deinit(mp_obj_t self_in) { +static mp_obj_t gnss_obj_deinit(mp_obj_t self_in) { gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); common_hal_gnss_deinit(self); return mp_const_none; } MP_DEFINE_CONST_FUN_OBJ_1(gnss_deinit_obj, gnss_obj_deinit); -STATIC void check_for_deinit(gnss_obj_t *self) { +static void check_for_deinit(gnss_obj_t *self) { if (common_hal_gnss_deinited(self)) { raise_deinited_error(); } @@ -85,7 +85,7 @@ STATIC void check_for_deinit(gnss_obj_t *self) { //| def update(self) -> None: //| """Update GNSS positioning information.""" //| ... -STATIC mp_obj_t gnss_obj_update(mp_obj_t self_in) { +static mp_obj_t gnss_obj_update(mp_obj_t self_in) { gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); @@ -96,7 +96,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(gnss_update_obj, gnss_obj_update); //| latitude: float //| """Latitude of current position in degrees (float).""" -STATIC mp_obj_t gnss_obj_get_latitude(mp_obj_t self_in) { +static mp_obj_t gnss_obj_get_latitude(mp_obj_t self_in) { gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); return mp_obj_new_float(common_hal_gnss_get_latitude(self)); @@ -108,7 +108,7 @@ MP_PROPERTY_GETTER(gnss_latitude_obj, //| longitude: float //| """Longitude of current position in degrees (float).""" -STATIC mp_obj_t gnss_obj_get_longitude(mp_obj_t self_in) { +static mp_obj_t gnss_obj_get_longitude(mp_obj_t self_in) { gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); return mp_obj_new_float(common_hal_gnss_get_longitude(self)); @@ -120,7 +120,7 @@ MP_PROPERTY_GETTER(gnss_longitude_obj, //| altitude: float //| """Altitude of current position in meters (float).""" -STATIC mp_obj_t gnss_obj_get_altitude(mp_obj_t self_in) { +static mp_obj_t gnss_obj_get_altitude(mp_obj_t self_in) { gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); return mp_obj_new_float(common_hal_gnss_get_altitude(self)); @@ -132,7 +132,7 @@ MP_PROPERTY_GETTER(gnss_altitude_obj, //| timestamp: time.struct_time //| """Time when the position data was updated.""" -STATIC mp_obj_t gnss_obj_get_timestamp(mp_obj_t self_in) { +static mp_obj_t gnss_obj_get_timestamp(mp_obj_t self_in) { gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); timeutils_struct_time_t tm; @@ -147,7 +147,7 @@ MP_PROPERTY_GETTER(gnss_timestamp_obj, //| fix: PositionFix //| """Fix mode.""" //| -STATIC mp_obj_t gnss_obj_get_fix(mp_obj_t self_in) { +static mp_obj_t gnss_obj_get_fix(mp_obj_t self_in) { gnss_obj_t *self = MP_OBJ_TO_PTR(self_in); check_for_deinit(self); return gnss_positionfix_type_to_obj(common_hal_gnss_get_fix(self)); @@ -157,7 +157,7 @@ MP_DEFINE_CONST_FUN_OBJ_1(gnss_get_fix_obj, gnss_obj_get_fix); MP_PROPERTY_GETTER(gnss_fix_obj, (mp_obj_t)&gnss_get_fix_obj); -STATIC const mp_rom_map_elem_t gnss_locals_dict_table[] = { +static const mp_rom_map_elem_t gnss_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&gnss_deinit_obj) }, { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&gnss_update_obj) }, @@ -167,7 +167,7 @@ STATIC const mp_rom_map_elem_t gnss_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_timestamp), MP_ROM_PTR(&gnss_timestamp_obj) }, { MP_ROM_QSTR(MP_QSTR_fix), MP_ROM_PTR(&gnss_fix_obj) } }; -STATIC MP_DEFINE_CONST_DICT(gnss_locals_dict, gnss_locals_dict_table); +static MP_DEFINE_CONST_DICT(gnss_locals_dict, gnss_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( gnss_type, diff --git a/shared-bindings/gnss/PositionFix.c b/shared-bindings/gnss/PositionFix.c index d63623eb6a2f2..cd108a612cf5d 100644 --- a/shared-bindings/gnss/PositionFix.c +++ b/shared-bindings/gnss/PositionFix.c @@ -54,14 +54,14 @@ mp_obj_t gnss_positionfix_type_to_obj(gnss_positionfix_t posfix) { } } -STATIC const mp_rom_map_elem_t gnss_positionfix_locals_dict_table[] = { +static const mp_rom_map_elem_t gnss_positionfix_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_INVALID), MP_ROM_PTR(&gnss_positionfix_invalid_obj)}, {MP_ROM_QSTR(MP_QSTR_FIX_2D), MP_ROM_PTR(&gnss_positionfix_fix2d_obj)}, {MP_ROM_QSTR(MP_QSTR_FIX_3D), MP_ROM_PTR(&gnss_positionfix_fix3d_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(gnss_positionfix_locals_dict, gnss_positionfix_locals_dict_table); +static MP_DEFINE_CONST_DICT(gnss_positionfix_locals_dict, gnss_positionfix_locals_dict_table); -STATIC void gnss_positionfix_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void gnss_positionfix_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { qstr posfix = MP_QSTR_INVALID; if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_positionfix_fix2d_obj)) { posfix = MP_QSTR_FIX_2D; diff --git a/shared-bindings/gnss/SatelliteSystem.c b/shared-bindings/gnss/SatelliteSystem.c index c9e71f2c8f502..0c870cbf8152c 100644 --- a/shared-bindings/gnss/SatelliteSystem.c +++ b/shared-bindings/gnss/SatelliteSystem.c @@ -79,16 +79,16 @@ mp_obj_t gnss_satellitesystem_type_to_obj(gnss_satellitesystem_t system) { } } -STATIC const mp_rom_map_elem_t gnss_satellitesystem_locals_dict_table[] = { +static const mp_rom_map_elem_t gnss_satellitesystem_locals_dict_table[] = { {MP_ROM_QSTR(MP_QSTR_GPS), MP_ROM_PTR(&gnss_satellitesystem_gps_obj)}, {MP_ROM_QSTR(MP_QSTR_GLONASS), MP_ROM_PTR(&gnss_satellitesystem_glonass_obj)}, {MP_ROM_QSTR(MP_QSTR_SBAS), MP_ROM_PTR(&gnss_satellitesystem_sbas_obj)}, {MP_ROM_QSTR(MP_QSTR_QZSS_L1CA), MP_ROM_PTR(&gnss_satellitesystem_qzss_l1ca_obj)}, {MP_ROM_QSTR(MP_QSTR_QZSS_L1S), MP_ROM_PTR(&gnss_satellitesystem_qzss_l1s_obj)}, }; -STATIC MP_DEFINE_CONST_DICT(gnss_satellitesystem_locals_dict, gnss_satellitesystem_locals_dict_table); +static MP_DEFINE_CONST_DICT(gnss_satellitesystem_locals_dict, gnss_satellitesystem_locals_dict_table); -STATIC void gnss_satellitesystem_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void gnss_satellitesystem_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { qstr system = MP_QSTR_None; if (MP_OBJ_TO_PTR(self_in) == MP_ROM_PTR(&gnss_satellitesystem_gps_obj)) { system = MP_QSTR_GPS; diff --git a/shared-bindings/gnss/__init__.c b/shared-bindings/gnss/__init__.c index 4409b0be1b360..beaeb117c19ba 100644 --- a/shared-bindings/gnss/__init__.c +++ b/shared-bindings/gnss/__init__.c @@ -13,7 +13,7 @@ //| """Global Navigation Satellite System //| //| The `gnss` module contains classes to control the GNSS and acquire positioning information.""" -STATIC const mp_rom_map_elem_t gnss_module_globals_table[] = { +static const mp_rom_map_elem_t gnss_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_gnss) }, { MP_ROM_QSTR(MP_QSTR_GNSS), MP_ROM_PTR(&gnss_type) }, @@ -22,7 +22,7 @@ STATIC const mp_rom_map_elem_t gnss_module_globals_table[] = { { MP_ROM_QSTR(MP_QSTR_PositionFix), MP_ROM_PTR(&gnss_positionfix_type) }, }; -STATIC MP_DEFINE_CONST_DICT(gnss_module_globals, gnss_module_globals_table); +static MP_DEFINE_CONST_DICT(gnss_module_globals, gnss_module_globals_table); const mp_obj_module_t gnss_module = { .base = { &mp_type_module }, diff --git a/shared-bindings/max3421e/Max3421E.c b/shared-bindings/max3421e/Max3421E.c index e7de988a67819..e5c2963fa0195 100644 --- a/shared-bindings/max3421e/Max3421E.c +++ b/shared-bindings/max3421e/Max3421E.c @@ -47,8 +47,7 @@ static mp_obj_t max3421e_max3421e_make_new(const mp_obj_type_t *type, size_t n_a mp_obj_t spi = mp_arg_validate_type(args[ARG_spi_bus].u_obj, &busio_spi_type, MP_QSTR_spi_bus); - max3421e_max3421e_obj_t *self = m_new_obj_with_finaliser(max3421e_max3421e_obj_t); - self->base.type = &max3421e_max3421e_type; + max3421e_max3421e_obj_t *self = mp_obj_malloc_with_finaliser(max3421e_max3421e_obj_t, &max3421e_max3421e_type); common_hal_max3421e_max3421e_construct(self, MP_OBJ_TO_PTR(spi), chip_select, irq, args[ARG_baudrate].u_int); return self; diff --git a/shared-bindings/mdns/Server.c b/shared-bindings/mdns/Server.c index 247c96254fbb7..c4670fccc23c6 100644 --- a/shared-bindings/mdns/Server.c +++ b/shared-bindings/mdns/Server.c @@ -46,8 +46,7 @@ static mp_obj_t mdns_server_make_new(const mp_obj_type_t *type, size_t n_args, s } #endif - mdns_server_obj_t *self = m_new_obj_with_finaliser(mdns_server_obj_t); - self->base.type = &mdns_server_type; + mdns_server_obj_t *self = mp_obj_malloc_with_finaliser(mdns_server_obj_t, &mdns_server_type); common_hal_mdns_server_construct(self, args[ARG_network_interface].u_obj); return MP_OBJ_FROM_PTR(self); diff --git a/shared-bindings/pulseio/PulseIn.c b/shared-bindings/pulseio/PulseIn.c index 38b63873c70ff..e44c2b273c72c 100644 --- a/shared-bindings/pulseio/PulseIn.c +++ b/shared-bindings/pulseio/PulseIn.c @@ -67,8 +67,7 @@ static mp_obj_t pulseio_pulsein_make_new(const mp_obj_type_t *type, size_t n_arg 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, MP_QSTR_pin); - pulseio_pulsein_obj_t *self = m_new_obj_with_finaliser(pulseio_pulsein_obj_t); - self->base.type = &pulseio_pulsein_type; + pulseio_pulsein_obj_t *self = mp_obj_malloc_with_finaliser(pulseio_pulsein_obj_t, &pulseio_pulsein_type); common_hal_pulseio_pulsein_construct(self, pin, args[ARG_maxlen].u_int, args[ARG_idle_state].u_bool); diff --git a/shared-bindings/pulseio/PulseOut.c b/shared-bindings/pulseio/PulseOut.c index 663eb1dfafe5b..92775ff59fd53 100644 --- a/shared-bindings/pulseio/PulseOut.c +++ b/shared-bindings/pulseio/PulseOut.c @@ -59,8 +59,7 @@ static mp_obj_t pulseio_pulseout_make_new(const mp_obj_type_t *type, size_t n_ar mp_int_t frequency = args[ARG_frequency].u_int; mp_int_t duty_cycle = args[ARG_duty_cycle].u_int; - pulseio_pulseout_obj_t *self = m_new_obj_with_finaliser(pulseio_pulseout_obj_t); - self->base.type = &pulseio_pulseout_type; + pulseio_pulseout_obj_t *self = mp_obj_malloc_with_finaliser(pulseio_pulseout_obj_t, &pulseio_pulseout_type); common_hal_pulseio_pulseout_construct(self, pin, frequency, duty_cycle); return MP_OBJ_FROM_PTR(self); #else diff --git a/shared-bindings/pwmio/PWMOut.c b/shared-bindings/pwmio/PWMOut.c index e312d4d8facdb..0504454bd4aad 100644 --- a/shared-bindings/pwmio/PWMOut.c +++ b/shared-bindings/pwmio/PWMOut.c @@ -149,8 +149,7 @@ static mp_obj_t pwmio_pwmout_make_new(const mp_obj_type_t *type, size_t n_args, bool variable_frequency = parsed_args[ARG_variable_frequency].u_bool; // create PWM object from the given pin - pwmio_pwmout_obj_t *self = m_new_obj_with_finaliser(pwmio_pwmout_obj_t); - self->base.type = &pwmio_pwmout_type; + pwmio_pwmout_obj_t *self = mp_obj_malloc_with_finaliser(pwmio_pwmout_obj_t, &pwmio_pwmout_type); pwmout_result_t result = common_hal_pwmio_pwmout_construct(self, pin, duty_cycle, frequency, variable_frequency); common_hal_pwmio_pwmout_raise_error(result); diff --git a/shared-bindings/rotaryio/IncrementalEncoder.c b/shared-bindings/rotaryio/IncrementalEncoder.c index 2b128638777ac..6cd137dd71ff3 100644 --- a/shared-bindings/rotaryio/IncrementalEncoder.c +++ b/shared-bindings/rotaryio/IncrementalEncoder.c @@ -57,8 +57,7 @@ static mp_obj_t rotaryio_incrementalencoder_make_new(const mp_obj_type_t *type, const mcu_pin_obj_t *pin_a = validate_obj_is_free_pin(args[ARG_pin_a].u_obj, MP_QSTR_pin_a); const mcu_pin_obj_t *pin_b = validate_obj_is_free_pin(args[ARG_pin_b].u_obj, MP_QSTR_pin_b); - rotaryio_incrementalencoder_obj_t *self = m_new_obj_with_finaliser(rotaryio_incrementalencoder_obj_t); - self->base.type = &rotaryio_incrementalencoder_type; + rotaryio_incrementalencoder_obj_t *self = mp_obj_malloc_with_finaliser(rotaryio_incrementalencoder_obj_t, &rotaryio_incrementalencoder_type); common_hal_rotaryio_incrementalencoder_construct(self, pin_a, pin_b); common_hal_rotaryio_incrementalencoder_set_divisor(self, args[ARG_divisor].u_int); diff --git a/shared-bindings/socketpool/SocketPool.c b/shared-bindings/socketpool/SocketPool.c index ada850ad17d4d..b37d02dc57a51 100644 --- a/shared-bindings/socketpool/SocketPool.c +++ b/shared-bindings/socketpool/SocketPool.c @@ -36,8 +36,7 @@ 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; + socketpool_socketpool_obj_t *s = mp_obj_malloc_with_finaliser(socketpool_socketpool_obj_t, &socketpool_socketpool_type); mp_obj_t radio = args[0]; common_hal_socketpool_socketpool_construct(s, radio); diff --git a/shared-module/ssl/SSLSocket.c b/shared-module/ssl/SSLSocket.c index 0b40bd663c7d2..129a48d00d6ee 100644 --- a/shared-module/ssl/SSLSocket.c +++ b/shared-module/ssl/SSLSocket.c @@ -218,8 +218,7 @@ ssl_sslsocket_obj_t *common_hal_ssl_sslcontext_wrap_socket(ssl_sslcontext_obj_t mp_raise_RuntimeError(MP_ERROR_TEXT("Invalid socket for TLS")); } - ssl_sslsocket_obj_t *o = m_new_obj_with_finaliser(ssl_sslsocket_obj_t); - o->base.type = &ssl_sslsocket_type; + ssl_sslsocket_obj_t *o = mp_obj_malloc_with_finaliser(ssl_sslsocket_obj_t, &ssl_sslsocket_type); o->ssl_context = self; o->sock_obj = socket; o->poll_mask = 0; diff --git a/shared/libc/printf.c b/shared/libc/printf.c index 715181229e4fc..50b04ce9be082 100644 --- a/shared/libc/printf.c +++ b/shared/libc/printf.c @@ -87,7 +87,7 @@ typedef struct _strn_print_env_t { size_t remain; } strn_print_env_t; -STATIC void strn_print_strn(void *data, const char *str, size_t len) { +static void strn_print_strn(void *data, const char *str, size_t len) { strn_print_env_t *strn_print_env = data; if (len > strn_print_env->remain) { len = strn_print_env->remain; diff --git a/shared/libc/string0.c b/shared/libc/string0.c index 8d513e933c282..5a9e0ff853a52 100644 --- a/shared/libc/string0.c +++ b/shared/libc/string0.c @@ -26,10 +26,12 @@ #include #include -#include +// CIRCUITPY-CHANGE: additional includes +#include #include "py/mpconfig.h" +// CIRCUITPY-CHANGE: ifndef #ifndef likely #define likely(x) __builtin_expect((x), 1) #endif @@ -38,6 +40,7 @@ #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wcast-align" void *memcpy(void *dst, const void *src, size_t n) { +// CIRCUITPY-CHANGE: fancier copy only for full build #if CIRCUITPY_FULL_BUILD if (likely(!(((uintptr_t)dst) & 3) && !(((uintptr_t)src) & 3))) { // pointers aligned @@ -100,6 +103,7 @@ void *memmove(void *dest, const void *src, size_t n) { } void *memset(void *s, int c, size_t n) { +// CIRCUITPY-CHANGE: fancier copy only for full build #if CIRCUITPY_FULL_BUILD if (c == 0 && ((uintptr_t)s & 3) == 0) { // aligned store of 0 @@ -125,6 +129,7 @@ void *memset(void *s, int c, size_t n) { return s; } +// CIRCUITPY-CHANGE #pragma GCC diagnostic pop int memcmp(const void *s1, const void *s2, size_t n) { diff --git a/shared/netutils/dhcpserver.c b/shared/netutils/dhcpserver.c index 41bc4ffdcb871..6d9cdb97d1fc6 100644 --- a/shared/netutils/dhcpserver.c +++ b/shared/netutils/dhcpserver.c @@ -117,7 +117,7 @@ static void dhcp_socket_free(struct udp_pcb **udp) { static int dhcp_socket_bind(struct udp_pcb **udp, uint32_t ip, uint16_t port) { ip_addr_t addr; - IP4_ADDR(&addr, ip >> 24 & 0xff, ip >> 16 & 0xff, ip >> 8 & 0xff, ip & 0xff); + IP_ADDR4(&addr, ip >> 24 & 0xff, ip >> 16 & 0xff, ip >> 8 & 0xff, ip & 0xff); // TODO convert lwIP errors to errno return udp_bind(*udp, &addr, port); } @@ -135,7 +135,7 @@ static int dhcp_socket_sendto(struct udp_pcb **udp, struct netif *netif, const v memcpy(p->payload, buf, len); ip_addr_t dest; - IP4_ADDR(&dest, ip >> 24 & 0xff, ip >> 16 & 0xff, ip >> 8 & 0xff, ip & 0xff); + IP_ADDR4(&dest, ip >> 24 & 0xff, ip >> 16 & 0xff, ip >> 8 & 0xff, ip & 0xff); err_t err; if (netif != NULL) { err = udp_sendto_if(*udp, p, &dest, port, netif); @@ -209,7 +209,7 @@ static void dhcp_server_process(void *arg, struct udp_pcb *upcb, struct pbuf *p, } dhcp_msg.op = DHCPOFFER; - memcpy(&dhcp_msg.yiaddr, &d->ip.addr, 4); + memcpy(&dhcp_msg.yiaddr, &ip_2_ip4(&d->ip)->addr, 4); uint8_t *opt = (uint8_t *)&dhcp_msg.options; opt += 4; // assume magic cookie: 99, 130, 83, 99 @@ -252,7 +252,7 @@ static void dhcp_server_process(void *arg, struct udp_pcb *upcb, struct pbuf *p, // Should be NACK goto ignore_request; } - if (memcmp(o + 2, &d->ip.addr, 3) != 0) { + if (memcmp(o + 2, &ip_2_ip4(&d->ip)->addr, 3) != 0) { // Should be NACK goto ignore_request; } @@ -285,9 +285,9 @@ static void dhcp_server_process(void *arg, struct udp_pcb *upcb, struct pbuf *p, goto ignore_request; } - opt_write_n(&opt, DHCP_OPT_SERVER_ID, 4, &d->ip.addr); - opt_write_n(&opt, DHCP_OPT_SUBNET_MASK, 4, &d->nm.addr); - opt_write_n(&opt, DHCP_OPT_ROUTER, 4, &d->ip.addr); // aka gateway; can have multiple addresses + opt_write_n(&opt, DHCP_OPT_SERVER_ID, 4, &ip_2_ip4(&d->ip)->addr); + opt_write_n(&opt, DHCP_OPT_SUBNET_MASK, 4, &ip_2_ip4(&d->nm)->addr); + opt_write_n(&opt, DHCP_OPT_ROUTER, 4, &ip_2_ip4(&d->ip)->addr); // aka gateway; can have multiple addresses opt_write_u32(&opt, DHCP_OPT_DNS, DEFAULT_DNS); // can have multiple addresses opt_write_u32(&opt, DHCP_OPT_IP_LEASE_TIME, DEFAULT_LEASE_TIME_S); *opt++ = DHCP_OPT_END; diff --git a/shared/readline/readline.c b/shared/readline/readline.c index 4906f51af3c14..12acf1589781c 100644 --- a/shared/readline/readline.c +++ b/shared/readline/readline.c @@ -55,7 +55,7 @@ void readline_init0(void) { memset(MP_STATE_PORT(readline_hist), 0, MICROPY_READLINE_HISTORY_SIZE * sizeof(const char*)); } -STATIC char *str_dup_maybe(const char *str) { +static char *str_dup_maybe(const char *str) { uint32_t len = strlen(str); char *s2 = m_new_maybe(char, len + 1); if (s2 == NULL) { @@ -66,7 +66,7 @@ STATIC char *str_dup_maybe(const char *str) { } // CIRCUITPY-CHANGE -STATIC size_t count_cont_bytes(char *start, char *end) { +static size_t count_cont_bytes(char *start, char *end) { int count = 0; for (char *pos = start; pos < end; pos++) { if(UTF8_IS_CONT(*pos)) { @@ -83,7 +83,7 @@ STATIC size_t count_cont_bytes(char *start, char *end) { // ...and provide the implementation using them #if MICROPY_HAL_HAS_VT100 -STATIC void mp_hal_move_cursor_back(uint pos) { +static void mp_hal_move_cursor_back(uint pos) { if (pos <= 4) { // fast path for most common case of 1 step back mp_hal_stdout_tx_strn("\b\b\b\b", pos); @@ -99,7 +99,7 @@ STATIC void mp_hal_move_cursor_back(uint pos) { } } -STATIC void mp_hal_erase_line_from_cursor(uint n_chars_to_erase) { +static void mp_hal_erase_line_from_cursor(uint n_chars_to_erase) { (void)n_chars_to_erase; mp_hal_stdout_tx_strn("\x1b[K", 3); } @@ -120,10 +120,10 @@ typedef struct _readline_t { const char *prompt; } readline_t; -STATIC readline_t rl; +static readline_t rl; #if MICROPY_REPL_EMACS_WORDS_MOVE -STATIC size_t cursor_count_word(int forward) { +static size_t cursor_count_word(int forward) { const char *line_buf = vstr_str(rl.line); size_t pos = rl.cursor_pos; bool in_word = false; @@ -553,7 +553,7 @@ int readline_process_char(int c) { } #if MICROPY_REPL_AUTO_INDENT -STATIC void readline_auto_indent(void) { +static void readline_auto_indent(void) { if (!(rl.auto_indent_state & AUTO_INDENT_ENABLED)) { return; } diff --git a/shared/runtime/gchelper_generic.c b/shared/runtime/gchelper_generic.c index 272e37056aaa8..4ef2e73f7a2ee 100644 --- a/shared/runtime/gchelper_generic.c +++ b/shared/runtime/gchelper_generic.c @@ -42,7 +42,7 @@ // stack already by the caller. #if defined(__x86_64__) -STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { +static void gc_helper_get_regs(gc_helper_regs_t arr) { register long rbx asm ("rbx"); register long rbp asm ("rbp"); register long r12 asm ("r12"); @@ -73,7 +73,7 @@ STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { #elif defined(__i386__) -STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { +static void gc_helper_get_regs(gc_helper_regs_t arr) { register long ebx asm ("ebx"); register long esi asm ("esi"); register long edi asm ("edi"); @@ -100,7 +100,7 @@ STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { // Fallback implementation, prefer gchelper_thumb1.s or gchelper_thumb2.s -STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { +static void gc_helper_get_regs(gc_helper_regs_t arr) { register long r4 asm ("r4"); register long r5 asm ("r5"); register long r6 asm ("r6"); @@ -125,7 +125,7 @@ STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { #elif defined(__aarch64__) -STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { +static void gc_helper_get_regs(gc_helper_regs_t arr) { const register long x19 asm ("x19"); const register long x20 asm ("x20"); const register long x21 asm ("x21"); @@ -161,7 +161,7 @@ STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { // Even if we have specific support for an architecture, it is // possible to force use of setjmp-based implementation. -STATIC void gc_helper_get_regs(gc_helper_regs_t arr) { +static void gc_helper_get_regs(gc_helper_regs_t arr) { setjmp(arr); } diff --git a/shared/runtime/mpirq.c b/shared/runtime/mpirq.c index acd727403b558..6111b9b10cfe4 100644 --- a/shared/runtime/mpirq.c +++ b/shared/runtime/mpirq.c @@ -96,13 +96,13 @@ void mp_irq_handler(mp_irq_obj_t *self) { /******************************************************************************/ // MicroPython bindings -STATIC mp_obj_t mp_irq_flags(mp_obj_t self_in) { +static mp_obj_t mp_irq_flags(mp_obj_t self_in) { mp_irq_obj_t *self = MP_OBJ_TO_PTR(self_in); return mp_obj_new_int(self->methods->info(self->parent, MP_IRQ_INFO_FLAGS)); } -STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_flags_obj, mp_irq_flags); +static MP_DEFINE_CONST_FUN_OBJ_1(mp_irq_flags_obj, mp_irq_flags); -STATIC mp_obj_t mp_irq_trigger(size_t n_args, const mp_obj_t *args) { +static mp_obj_t mp_irq_trigger(size_t n_args, const mp_obj_t *args) { mp_irq_obj_t *self = MP_OBJ_TO_PTR(args[0]); mp_obj_t ret_obj = mp_obj_new_int(self->methods->info(self->parent, MP_IRQ_INFO_TRIGGERS)); if (n_args == 2) { @@ -111,19 +111,19 @@ STATIC mp_obj_t mp_irq_trigger(size_t n_args, const mp_obj_t *args) { } return ret_obj; } -STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_irq_trigger_obj, 1, 2, mp_irq_trigger); +static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_irq_trigger_obj, 1, 2, mp_irq_trigger); -STATIC mp_obj_t mp_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { +static mp_obj_t mp_irq_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) { mp_arg_check_num(n_args, n_kw, 0, 0, false); mp_irq_handler(MP_OBJ_TO_PTR(self_in)); return mp_const_none; } -STATIC const mp_rom_map_elem_t mp_irq_locals_dict_table[] = { +static const mp_rom_map_elem_t mp_irq_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR_flags), MP_ROM_PTR(&mp_irq_flags_obj) }, { MP_ROM_QSTR(MP_QSTR_trigger), MP_ROM_PTR(&mp_irq_trigger_obj) }, }; -STATIC MP_DEFINE_CONST_DICT(mp_irq_locals_dict, mp_irq_locals_dict_table); +static MP_DEFINE_CONST_DICT(mp_irq_locals_dict, mp_irq_locals_dict_table); MP_DEFINE_CONST_OBJ_TYPE( mp_irq_type, diff --git a/shared/runtime/pyexec.c b/shared/runtime/pyexec.c index 94c506502c305..050a14ef82e34 100644 --- a/shared/runtime/pyexec.c +++ b/shared/runtime/pyexec.c @@ -55,7 +55,7 @@ pyexec_mode_kind_t pyexec_mode_kind = PYEXEC_MODE_FRIENDLY_REPL; int pyexec_system_exit = 0; #if MICROPY_REPL_INFO -STATIC bool repl_display_debugging_info = 0; +static bool repl_display_debugging_info = 0; #endif #define EXEC_FLAG_PRINT_EOF (1 << 0) @@ -75,7 +75,7 @@ STATIC bool repl_display_debugging_info = 0; // EXEC_FLAG_ALLOW_DEBUGGING allows debugging info to be printed after executing the code // EXEC_FLAG_IS_REPL is used for REPL inputs (flag passed on to mp_compile) // CIRCUITPY-CHANGE: add result support -STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input_kind, mp_uint_t exec_flags, pyexec_result_t *result) { +static int parse_compile_execute(const void *source, mp_parse_input_kind_t input_kind, mp_uint_t exec_flags, pyexec_result_t *result) { int ret = 0; #if MICROPY_REPL_INFO uint32_t start = 0; @@ -105,7 +105,7 @@ STATIC int parse_compile_execute(const void *source, mp_parse_input_kind_t input mp_module_context_t *ctx = m_new_obj(mp_module_context_t); ctx->module.globals = mp_globals_get(); ctx->constants = frozen->constants; - module_fun = mp_make_function_from_raw_code(frozen->rc, ctx, NULL); + module_fun = mp_make_function_from_proto_fun(frozen->proto_fun, ctx, NULL); } else #endif { @@ -277,7 +277,7 @@ typedef struct _mp_reader_stdin_t { uint16_t window_remain; } mp_reader_stdin_t; -STATIC mp_uint_t mp_reader_stdin_readbyte(void *data) { +static mp_uint_t mp_reader_stdin_readbyte(void *data) { mp_reader_stdin_t *reader = (mp_reader_stdin_t *)data; if (reader->eof) { @@ -310,7 +310,7 @@ STATIC mp_uint_t mp_reader_stdin_readbyte(void *data) { return c; } -STATIC void mp_reader_stdin_close(void *data) { +static void mp_reader_stdin_close(void *data) { mp_reader_stdin_t *reader = (mp_reader_stdin_t *)data; if (!reader->eof) { reader->eof = true; @@ -324,7 +324,7 @@ STATIC void mp_reader_stdin_close(void *data) { } } -STATIC void mp_reader_new_stdin(mp_reader_t *reader, mp_reader_stdin_t *reader_stdin, uint16_t buf_max) { +static void mp_reader_new_stdin(mp_reader_t *reader, mp_reader_stdin_t *reader_stdin, uint16_t buf_max) { // Make flow-control window half the buffer size, and indicate to the host that 2x windows are // free (sending the window size implicitly indicates that a window is free, and then the 0x01 // indicates that another window is free). @@ -340,7 +340,7 @@ STATIC void mp_reader_new_stdin(mp_reader_t *reader, mp_reader_stdin_t *reader_s reader->close = mp_reader_stdin_close; } -STATIC int do_reader_stdin(int c) { +static int do_reader_stdin(int c) { if (c != 'A') { // Unsupported command. mp_hal_stdout_tx_strn("R\x00", 2); @@ -372,8 +372,8 @@ typedef struct _repl_t { repl_t repl; -STATIC int pyexec_raw_repl_process_char(int c); -STATIC int pyexec_friendly_repl_process_char(int c); +static int pyexec_raw_repl_process_char(int c); +static int pyexec_friendly_repl_process_char(int c); void pyexec_event_repl_init(void) { MP_STATE_VM(repl_line) = vstr_new(32); @@ -388,7 +388,7 @@ void pyexec_event_repl_init(void) { } } -STATIC int pyexec_raw_repl_process_char(int c) { +static int pyexec_raw_repl_process_char(int c) { if (c == CHAR_CTRL_A) { // reset raw REPL if (vstr_len(MP_STATE_VM(repl_line)) == 2 && vstr_str(MP_STATE_VM(repl_line))[0] == CHAR_CTRL_E) { @@ -443,7 +443,7 @@ STATIC int pyexec_raw_repl_process_char(int c) { return 0; } -STATIC int pyexec_friendly_repl_process_char(int c) { +static int pyexec_friendly_repl_process_char(int c) { if (repl.paste_mode) { if (c == CHAR_CTRL_C) { // cancel everything diff --git a/shared/runtime/sys_stdio_mphal.c b/shared/runtime/sys_stdio_mphal.c index 3344b19d52e76..b82725bfa7bf8 100644 --- a/shared/runtime/sys_stdio_mphal.c +++ b/shared/runtime/sys_stdio_mphal.c @@ -49,15 +49,15 @@ typedef struct _sys_stdio_obj_t { } sys_stdio_obj_t; #if MICROPY_PY_SYS_STDIO_BUFFER -STATIC const sys_stdio_obj_t stdio_buffer_obj; +static const sys_stdio_obj_t stdio_buffer_obj; #endif -STATIC void stdio_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { +static void stdio_obj_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) { sys_stdio_obj_t *self = MP_OBJ_TO_PTR(self_in); mp_printf(print, "", mp_obj_get_type_str(self_in), self->fd); } -STATIC mp_uint_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { sys_stdio_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->fd == STDIO_FD_IN) { for (uint i = 0; i < size; i++) { @@ -74,7 +74,7 @@ STATIC mp_uint_t stdio_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *er } } -STATIC mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { sys_stdio_obj_t *self = MP_OBJ_TO_PTR(self_in); if (self->fd == STDIO_FD_OUT || self->fd == STDIO_FD_ERR) { mp_hal_stdout_tx_strn_cooked(buf, size); @@ -85,7 +85,7 @@ STATIC mp_uint_t stdio_write(mp_obj_t self_in, const void *buf, mp_uint_t size, } } -STATIC mp_uint_t stdio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { +static mp_uint_t stdio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, int *errcode) { (void)self_in; if (request == MP_STREAM_POLL) { return mp_hal_stdio_poll(arg); @@ -97,7 +97,7 @@ STATIC mp_uint_t stdio_ioctl(mp_obj_t self_in, mp_uint_t request, uintptr_t arg, } } -STATIC const mp_rom_map_elem_t stdio_locals_dict_table[] = { +static const mp_rom_map_elem_t stdio_locals_dict_table[] = { #if MICROPY_PY_SYS_STDIO_BUFFER { MP_ROM_QSTR(MP_QSTR_buffer), MP_ROM_PTR(&stdio_buffer_obj) }, #endif @@ -111,9 +111,9 @@ STATIC const mp_rom_map_elem_t stdio_locals_dict_table[] = { { MP_ROM_QSTR(MP_QSTR___exit__), MP_ROM_PTR(&mp_stream___exit___obj) }, }; -STATIC MP_DEFINE_CONST_DICT(stdio_locals_dict, stdio_locals_dict_table); +static MP_DEFINE_CONST_DICT(stdio_locals_dict, stdio_locals_dict_table); -STATIC const mp_stream_p_t stdio_obj_stream_p = { +static const mp_stream_p_t stdio_obj_stream_p = { .read = stdio_read, .write = stdio_write, .ioctl = stdio_ioctl, @@ -134,25 +134,25 @@ const sys_stdio_obj_t mp_sys_stdout_obj = {{&stdio_obj_type}, .fd = STDIO_FD_OUT const sys_stdio_obj_t mp_sys_stderr_obj = {{&stdio_obj_type}, .fd = STDIO_FD_ERR}; #if MICROPY_PY_SYS_STDIO_BUFFER -STATIC mp_uint_t stdio_buffer_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stdio_buffer_read(mp_obj_t self_in, void *buf, mp_uint_t size, int *errcode) { for (uint i = 0; i < size; i++) { ((byte *)buf)[i] = mp_hal_stdin_rx_chr(); } return size; } -STATIC mp_uint_t stdio_buffer_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { +static mp_uint_t stdio_buffer_write(mp_obj_t self_in, const void *buf, mp_uint_t size, int *errcode) { return mp_hal_stdout_tx_strn(buf, size); } -STATIC const mp_stream_p_t stdio_buffer_obj_stream_p = { +static const mp_stream_p_t stdio_buffer_obj_stream_p = { .read = stdio_buffer_read, .write = stdio_buffer_write, .ioctl = stdio_ioctl, .is_text = false, }; -STATIC MP_DEFINE_CONST_OBJ_TYPE( +static MP_DEFINE_CONST_OBJ_TYPE( stdio_buffer_obj_type, MP_QSTR_FileIO, MP_TYPE_FLAG_ITER_IS_STREAM, @@ -161,5 +161,5 @@ STATIC MP_DEFINE_CONST_OBJ_TYPE( locals_dict, &stdio_locals_dict ); -STATIC const sys_stdio_obj_t stdio_buffer_obj = {{&stdio_buffer_obj_type}, .fd = 0}; // fd unused +static const sys_stdio_obj_t stdio_buffer_obj = {{&stdio_buffer_obj_type}, .fd = 0}; // fd unused #endif diff --git a/shared/timeutils/timeutils.c b/shared/timeutils/timeutils.c index 6bf3eca84a82b..4282a0178dd6e 100644 --- a/shared/timeutils/timeutils.c +++ b/shared/timeutils/timeutils.c @@ -40,7 +40,7 @@ #define DAYS_PER_100Y (365 * 100 + 24) #define DAYS_PER_4Y (365 * 4 + 1) -STATIC const uint16_t days_since_jan1[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; +static const uint16_t days_since_jan1[] = { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; bool timeutils_is_leap_year(mp_uint_t year) { return (year % 4 == 0 && year % 100 != 0) || year % 400 == 0; @@ -125,7 +125,7 @@ void timeutils_seconds_since_2000_to_struct_time(mp_uint_t t, timeutils_struct_t tm->tm_year = 2000 + years + 4 * q_cycles + 100 * c_cycles + 400 * qc_cycles; // Note: days_in_month[0] corresponds to March - STATIC const int8_t days_in_month[] = {31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29}; + static const int8_t days_in_month[] = {31, 30, 31, 30, 31, 31, 30, 31, 30, 31, 31, 29}; mp_int_t month; for (month = 0; days_in_month[month] <= days; month++) { diff --git a/shared/timeutils/timeutils.h b/shared/timeutils/timeutils.h index ebebfa8980167..e2a2666e910b7 100644 --- a/shared/timeutils/timeutils.h +++ b/shared/timeutils/timeutils.h @@ -63,7 +63,7 @@ mp_uint_t timeutils_mktime_2000(mp_uint_t year, mp_int_t month, mp_int_t mday, static inline void timeutils_seconds_since_epoch_to_struct_time(uint64_t t, timeutils_struct_time_t *tm) { // TODO this will give incorrect results for dates before 2000/1/1 - return timeutils_seconds_since_2000_to_struct_time(t - TIMEUTILS_SECONDS_1970_TO_2000, tm); + timeutils_seconds_since_2000_to_struct_time(t - TIMEUTILS_SECONDS_1970_TO_2000, tm); } static inline uint64_t timeutils_mktime(mp_uint_t year, mp_int_t month, mp_int_t mday, mp_int_t hours, mp_int_t minutes, mp_int_t seconds) { diff --git a/tests/README.md b/tests/README.md index 9a93c69b29cc0..54dd078053ef0 100644 --- a/tests/README.md +++ b/tests/README.md @@ -181,14 +181,20 @@ SSL/TLS tests in `multi_net` and `net_inet` use a self-signed key/cert pair that is randomly generated and to be used for testing/demonstration only. You should always generate your own key/cert. -To generate a new self-signed key/cert pair with openssl do: +To generate a new self-signed RSA key/cert pair with openssl do: ``` -$ openssl req -x509 -newkey rsa:4096 -keyout rsa_key.pem -out rsa_cert.pem -days 365 -nodes +$ openssl req -x509 -newkey rsa:2048 -keyout rsa_key.pem -out rsa_cert.pem -days 365 -nodes -subj '/CN=micropython.local/O=MicroPython/C=AU' ``` In this case CN is: micropython.local Convert them to DER format: ``` -$ openssl rsa -in rsa_key.pem -out rsa_key.der -outform DER +$ openssl pkey -in rsa_key.pem -out rsa_key.der -outform DER $ openssl x509 -in rsa_cert.pem -out rsa_cert.der -outform DER ``` + +To test elliptic curve key/cert pairs, create a key then a certificate using: +``` +$ openssl ecparam -name prime256v1 -genkey -noout -out ec_key.der -outform DER +$ openssl req -new -x509 -key ec_key.der -out ec_cert.der -outform DER -days 365 -nodes -subj '/CN=micropython.local/O=MicroPython/C=AU' +``` diff --git a/tests/basics/builtin_compile.py b/tests/basics/builtin_compile.py index 41dc746ad163c..361d7ec53a729 100644 --- a/tests/basics/builtin_compile.py +++ b/tests/basics/builtin_compile.py @@ -29,6 +29,9 @@ def test(): exec(compile("print(10 + 2)", "file", "single")) print(eval(compile("10 + 3", "file", "eval"))) + # test accessing a function's globals from within a compile + exec(compile("def func():pass\nprint('x', func.__globals__['x'])", "file", "exec")) + # bad mode try: compile('1', 'file', '') diff --git a/tests/basics/bytearray_add.py b/tests/basics/bytearray_add.py index a7e2b57374255..1f30a3b740e95 100644 --- a/tests/basics/bytearray_add.py +++ b/tests/basics/bytearray_add.py @@ -15,4 +15,11 @@ # this inplace add tests the code when the buffer doesn't need to be increased b = bytearray() -b += b'' +b += b"" + +# extend a bytearray from itself +b = bytearray(b"abcdefgh") +for _ in range(4): + c = bytearray(b) # extra allocation, as above + b.extend(b) +print(b) diff --git a/tests/basics/bytearray_add_self.py b/tests/basics/bytearray_add_self.py new file mode 100644 index 0000000000000..94ae8689fd16c --- /dev/null +++ b/tests/basics/bytearray_add_self.py @@ -0,0 +1,8 @@ +# add a bytearray to itself +# This is not supported by CPython as of 3.11.18. + +b = bytearray(b"123456789") +for _ in range(4): + c = bytearray(b) # extra allocation increases chance 'b' has to relocate + b += b +print(b) diff --git a/tests/basics/bytearray_add_self.py.exp b/tests/basics/bytearray_add_self.py.exp new file mode 100644 index 0000000000000..5ef948157ac0f --- /dev/null +++ b/tests/basics/bytearray_add_self.py.exp @@ -0,0 +1 @@ +bytearray(b'123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789123456789') diff --git a/tests/basics/bytearray_byte_operations.py b/tests/basics/bytearray_byte_operations.py index 7ce53cac535a1..48b08ab26196f 100644 --- a/tests/basics/bytearray_byte_operations.py +++ b/tests/basics/bytearray_byte_operations.py @@ -1,4 +1,4 @@ -# test bytearray with its re-use of byte functions +# test bytearray with its reuse of byte functions print(bytearray(b"hello world").find(b"ll")) print(bytearray(b"hello\x00world").rfind(b"l")) diff --git a/tests/basics/bytearray_slice_assign.py b/tests/basics/bytearray_slice_assign.py index fa7878e10ddbb..4de0819042a13 100644 --- a/tests/basics/bytearray_slice_assign.py +++ b/tests/basics/bytearray_slice_assign.py @@ -18,7 +18,7 @@ l[1:3] = bytearray() print(l) l = bytearray(x) -#del l[1:3] +# del l[1:3] print(l) l = bytearray(x) @@ -28,7 +28,7 @@ l[:3] = bytearray() print(l) l = bytearray(x) -#del l[:3] +# del l[:3] print(l) l = bytearray(x) @@ -38,7 +38,7 @@ l[:-3] = bytearray() print(l) l = bytearray(x) -#del l[:-3] +# del l[:-3] print(l) # slice assignment that extends the array @@ -61,8 +61,14 @@ print(b) # Growth of bytearray via slice extension -b = bytearray(b'12345678') -b.append(57) # expand and add a bit of unused space at end of the bytearray +b = bytearray(b"12345678") +b.append(57) # expand and add a bit of unused space at end of the bytearray for i in range(400): - b[-1:] = b'ab' # grow slowly into the unused space + b[-1:] = b"ab" # grow slowly into the unused space +print(len(b), b) + +# Growth of bytearray via slice extension from itself +b = bytearray(b"1234567") +for i in range(3): + b[-1:] = b print(len(b), b) diff --git a/tests/basics/class_bytes.py b/tests/basics/class_bytes.py index 75e2e7244e739..eacb69a438adf 100644 --- a/tests/basics/class_bytes.py +++ b/tests/basics/class_bytes.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this test file class C1: def __init__(self, value): self.value = value diff --git a/tests/basics/core_class_superproperty.py b/tests/basics/core_class_superproperty.py index 3095ab51da105..5c6c78f315e6a 100644 --- a/tests/basics/core_class_superproperty.py +++ b/tests/basics/core_class_superproperty.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this test file """ test that calling super() getter property in subclass will return the value """ diff --git a/tests/basics/deque1.py b/tests/basics/deque1.py index 2cb3c2f87134a..9ca6d434a75f9 100644 --- a/tests/basics/deque1.py +++ b/tests/basics/deque1.py @@ -64,7 +64,7 @@ except TypeError: print("TypeError") -# CIRCUITPY-CHANGE + # Same tests, but now with pop() and appendleft() d = deque((), 2) diff --git a/tests/basics/deque2.py b/tests/basics/deque2.py index 4c3743cf6e8e2..3552d5be37abe 100644 --- a/tests/basics/deque2.py +++ b/tests/basics/deque2.py @@ -1,12 +1,9 @@ -# Tests for deques with "check overflow" flag and other extensions -# wrt to CPython. try: from collections import deque except ImportError: print("SKIP") raise SystemExit -# CIRCUITPY-CHANGE: more functionality # Initial sequence is supported d = deque([1, 2, 3], 10) @@ -44,69 +41,3 @@ d[4] = 0 except IndexError: print("IndexError") - -# Removing elements with del is not supported, fall back on mp_obj_subscr() error message -try: - del d[0] -except TypeError: - print("TypeError") - - -# Only fixed-size deques are supported, so length arg is mandatory -try: - deque(()) -except TypeError: - print("TypeError") - -d = deque((), 2, True) - -try: - d.popleft() -except IndexError: - print("IndexError") - -try: - d.pop() -except IndexError: - print("IndexError") - -print(d.append(1)) -print(d.popleft()) - -d.append(2) -print(d.popleft()) - -d.append(3) -d.append(4) -print(d.popleft(), d.popleft()) -try: - d.popleft() -except IndexError as e: - print(repr(e)) - -try: - d.pop() -except IndexError as e: - print(repr(e)) - -d.append(5) -d.append(6) -print(len(d)) -try: - d.append(7) -except IndexError as e: - print(repr(e)) - -try: - d.appendleft(8) -except IndexError as e: - print(repr(e)) - -print(len(d)) - -print(d.popleft(), d.popleft()) -print(len(d)) -try: - d.popleft() -except IndexError as e: - print(repr(e)) diff --git a/tests/basics/deque_micropython.py b/tests/basics/deque_micropython.py new file mode 100644 index 0000000000000..5f32bbc496a3c --- /dev/null +++ b/tests/basics/deque_micropython.py @@ -0,0 +1,75 @@ +# Test MicroPython-specific features of collections.deque. + +try: + from collections import deque +except ImportError: + print("SKIP") + raise SystemExit + + +# Only fixed-size deques are supported, so length arg is mandatory. +try: + deque(()) +except TypeError: + print("TypeError") + +# Test third argument: flags when True means check for under/overflow +d = deque((), 2, True) + +try: + d.popleft() +except IndexError: + print("IndexError") + +try: + d.pop() +except IndexError: + print("IndexError") + +# Removing elements with del is not supported, fallback to +# mp_obj_subscr() error message. +try: + del d[0] +except TypeError: + print("TypeError") + +print(d.append(1)) +print(d.popleft()) + +d.append(2) +print(d.popleft()) + +d.append(3) +d.append(4) +print(d.popleft(), d.popleft()) +try: + d.popleft() +except IndexError as e: + print(repr(e)) + +try: + d.pop() +except IndexError as e: + print(repr(e)) + +d.append(5) +d.append(6) +print(len(d)) +try: + d.append(7) +except IndexError as e: + print(repr(e)) + +try: + d.appendleft(8) +except IndexError as e: + print(repr(e)) + +print(len(d)) + +print(d.popleft(), d.popleft()) +print(len(d)) +try: + d.popleft() +except IndexError as e: + print(repr(e)) diff --git a/tests/basics/deque2.py.exp b/tests/basics/deque_micropython.py.exp similarity index 75% rename from tests/basics/deque2.py.exp rename to tests/basics/deque_micropython.py.exp index 71f74ed6c4aaf..f1ff7b77ac880 100644 --- a/tests/basics/deque2.py.exp +++ b/tests/basics/deque_micropython.py.exp @@ -1,16 +1,7 @@ -1 -2 -3 -[3, 4, 5] -[5, 6, 7] -0 1 3 -5 -IndexError -IndexError -TypeError TypeError IndexError IndexError +TypeError None 1 2 diff --git a/tests/basics/dict_fromkeys_reversed.py b/tests/basics/dict_fromkeys_reversed.py index 34b0ed129c081..7ecd9bfddc75a 100644 --- a/tests/basics/dict_fromkeys_reversed.py +++ b/tests/basics/dict_fromkeys_reversed.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this test file # Skip this test if reversed() isn't built in. import skip_if skip_if.no_reversed() diff --git a/tests/basics/gen_stack_overflow.py b/tests/basics/gen_stack_overflow.py index 5cba0e0549be4..99fd952444238 100644 --- a/tests/basics/gen_stack_overflow.py +++ b/tests/basics/gen_stack_overflow.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this test file def gen(): yield from gen() diff --git a/tests/basics/gen_yield_from_throw_repeat.py b/tests/basics/gen_yield_from_throw_repeat.py index 96636a624432e..67378ff47a17a 100644 --- a/tests/basics/gen_yield_from_throw_repeat.py +++ b/tests/basics/gen_yield_from_throw_repeat.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this test file # Test throwing repeatedly into the same generator, where that generator # is yielding from another generator. diff --git a/tests/basics/generator_throw_repeat.py b/tests/basics/generator_throw_repeat.py index 6d6ef60a9b0d5..2b099494d367c 100644 --- a/tests/basics/generator_throw_repeat.py +++ b/tests/basics/generator_throw_repeat.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this test file # Test throwing repeatedly into the same generator. diff --git a/tests/basics/int_length.py b/tests/basics/int_length.py index 56730297c3e92..dd61f4a6b8573 100644 --- a/tests/basics/int_length.py +++ b/tests/basics/int_length.py @@ -1,4 +1,4 @@ -# CIRCUITPY-CHANGE +# CIRCUITPY-CHANGE: micropython does not have this test file # test bit_length for various sizes of ints for x in range(-10, 10): diff --git a/tests/basics/int_longint_bytes.py b/tests/basics/int_longint_bytes.py index 90cbff2f877cf..c68c0d49f434d 100644 --- a/tests/basics/int_longint_bytes.py +++ b/tests/basics/int_longint_bytes.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this test file # Skip if long ints are not supported. import skip_if skip_if.no_bigint() diff --git a/tests/basics/memoryview1_slice_assign.py b/tests/basics/memoryview1_slice_assign.py index f272fd392f48a..76952585c30d0 100644 --- a/tests/basics/memoryview1_slice_assign.py +++ b/tests/basics/memoryview1_slice_assign.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this test file import skip_if try: diff --git a/tests/basics/memoryview_cast.py b/tests/basics/memoryview_cast.py index 24c04e8e5a318..34e8eff931a46 100644 --- a/tests/basics/memoryview_cast.py +++ b/tests/basics/memoryview_cast.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this test file try: memoryview(b'a').cast except: diff --git a/tests/basics/namedtuple1_cpython_compat.py b/tests/basics/namedtuple1_cpython_compat.py index 061ae94e587d8..c2d986238e24c 100644 --- a/tests/basics/namedtuple1_cpython_compat.py +++ b/tests/basics/namedtuple1_cpython_compat.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this test file import skip_if skip_if.no_cpython_compat() diff --git a/tests/basics/ordereddict2.py b/tests/basics/ordereddict2.py index f85b08fea5199..34d5c005a3da6 100644 --- a/tests/basics/ordereddict2.py +++ b/tests/basics/ordereddict2.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this test file try: from collections import OrderedDict except ImportError: diff --git a/tests/basics/slice_op.py b/tests/basics/slice_op.py index f1e83c5e27dca..0bb6e365bfd85 100644 --- a/tests/basics/slice_op.py +++ b/tests/basics/slice_op.py @@ -1,3 +1,5 @@ +# Test slice unary operations. +# CPython allows hashing slices, but MicroPython does not. try: t = [][:] diff --git a/tests/basics/smallint_array_overflow.py b/tests/basics/smallint_array_overflow.py index 25b457cca1d97..a95060bb3a101 100644 --- a/tests/basics/smallint_array_overflow.py +++ b/tests/basics/smallint_array_overflow.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this test file try: from array import array except ImportError: diff --git a/tests/basics/string_pep498_fstring.py b/tests/basics/string_pep498_fstring.py index 82a2ca38e4b5d..f37229a726d5d 100644 --- a/tests/basics/string_pep498_fstring.py +++ b/tests/basics/string_pep498_fstring.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this test file # Tests against https://www.python.org/dev/peps/pep-0498/ assert f'no interpolation' == 'no interpolation' diff --git a/tests/basics/struct_overflow.py b/tests/basics/struct_overflow.py index c55870e1b4ae2..a3f9d055e7f8d 100644 --- a/tests/basics/struct_overflow.py +++ b/tests/basics/struct_overflow.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this test file import skip_if skip_if.no_bigint() diff --git a/tests/basics/subclass_native_dict.py b/tests/basics/subclass_native_dict.py index fd333eec69ba6..073213a16766d 100644 --- a/tests/basics/subclass_native_dict.py +++ b/tests/basics/subclass_native_dict.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this test file class a: def __init__(self): self.d = {} diff --git a/tests/basics/with_return.py b/tests/basics/with_return.py index af65a5b984383..f2083d2aec20d 100644 --- a/tests/basics/with_return.py +++ b/tests/basics/with_return.py @@ -30,7 +30,7 @@ def f(): return (i, j) print(f()) -# multiple for loops within nested with statements +# multiple for loops within nested with's def f(): with CtxMgr(1): for i in [1, 2]: @@ -41,7 +41,7 @@ def f(): return (i, j, k, l) print(f()) -# multiple for loops that are optimised, and nested with statements +# multiple for loops that are optimised, and nested with's def f(): with CtxMgr(1): for i in range(1, 3): diff --git a/tests/cpydiff/core_class_name_mangling.py b/tests/cpydiff/core_class_name_mangling.py new file mode 100644 index 0000000000000..39153209debe8 --- /dev/null +++ b/tests/cpydiff/core_class_name_mangling.py @@ -0,0 +1,26 @@ +""" +categories: Core,Classes +description: Private Class Members name mangling is not implemented +cause: The MicroPython compiler does not implement name mangling for private class members. +workaround: Avoid using or having a collision with global names, by adding a unique prefix to the private class member name manually. +""" + + +def __print_string(string): + print(string) + + +class Foo: + def __init__(self, string): + self.string = string + + def do_print(self): + __print_string(self.string) + + +example_string = "Example String to print." + +class_item = Foo(example_string) +print(class_item.string) + +class_item.do_print() diff --git a/tests/cpydiff/core_class_superproperty.py b/tests/cpydiff/core_class_superproperty.py new file mode 100644 index 0000000000000..2d7775a9028e8 --- /dev/null +++ b/tests/cpydiff/core_class_superproperty.py @@ -0,0 +1,22 @@ +""" +categories: Core,Classes +description: Calling super() getter property in subclass will return a property object, not the value +cause: Unknown +workaround: Unknown +""" + + +class A: + @property + def p(self): + return {"a": 10} + + +class AA(A): + @property + def p(self): + return super().p + + +a = AA() +print(a.p) diff --git a/tests/cpydiff/types_memoryview_invalid.py b/tests/cpydiff/types_memoryview_invalid.py new file mode 100644 index 0000000000000..c995a2e8991c6 --- /dev/null +++ b/tests/cpydiff/types_memoryview_invalid.py @@ -0,0 +1,12 @@ +""" +categories: Types,memoryview +description: memoryview can become invalid if its target is resized +cause: CPython prevents a ``bytearray`` or ``io.bytesIO`` object from changing size while there is a ``memoryview`` object that references it. MicroPython requires the programmer to manually ensure that an object is not resized while any ``memoryview`` references it. + +In the worst case scenario, resizing an object which is the target of a memoryview can cause the memoryview(s) to reference invalid freed memory (a use-after-free bug) and corrupt the MicroPython runtime. +workaround: Do not change the size of any ``bytearray`` or ``io.bytesIO`` object that has a ``memoryview`` assigned to it. +""" +b = bytearray(b"abcdefg") +m = memoryview(b) +b.extend(b"hijklmnop") +print(b, bytes(m)) diff --git a/tests/extmod/asyncio_await_return.py b/tests/extmod/asyncio_await_return.py index be6b3f4f11b00..0e74fc1f26226 100644 --- a/tests/extmod/asyncio_await_return.py +++ b/tests/extmod/asyncio_await_return.py @@ -13,7 +13,10 @@ async def foo(): # CIRCUITPY-CHANGE: await try: - foo().__await__ + fooc = foo() + fooc.__await__ + # Avoid "coroutine was never awaited" warning + asyncio.run(fooc) except AttributeError: print("SKIP") raise SystemExit diff --git a/tests/extmod/asyncio_await_return.py.exp b/tests/extmod/asyncio_await_return.py.exp deleted file mode 100644 index daaac9e303029..0000000000000 --- a/tests/extmod/asyncio_await_return.py.exp +++ /dev/null @@ -1,2 +0,0 @@ -42 -42 diff --git a/tests/extmod/asyncio_basic.py b/tests/extmod/asyncio_basic.py index bdc4f613335cb..411a5e28b44a5 100644 --- a/tests/extmod/asyncio_basic.py +++ b/tests/extmod/asyncio_basic.py @@ -11,7 +11,10 @@ async def foo(): try: - foo().__await__ + fooc = foo() + fooc.__await__ + # Avoid "coroutine was never awaited" warning + asyncio.run(fooc) except AttributeError: print("SKIP") raise SystemExit diff --git a/tests/extmod/asyncio_basic2.py.exp b/tests/extmod/asyncio_basic2.py.exp deleted file mode 100644 index 3ca3521728d44..0000000000000 --- a/tests/extmod/asyncio_basic2.py.exp +++ /dev/null @@ -1,4 +0,0 @@ -main start -forever start -main done -42 diff --git a/tests/extmod/asyncio_cancel_fair.py.exp b/tests/extmod/asyncio_cancel_fair.py.exp deleted file mode 100644 index 8f5da08e4ced4..0000000000000 --- a/tests/extmod/asyncio_cancel_fair.py.exp +++ /dev/null @@ -1,24 +0,0 @@ -start 0 -start 1 -start 2 -done 0 -0 cancels 1 -start 0 -cancelled 1 -1 cancels 0 -start 1 -done 2 -start 2 -cancelled 0 -0 cancels 1 -start 0 -cancelled 1 -1 cancels 0 -start 1 -done 2 -start 2 -cancelled 0 -0 cancels 1 -cancelled 1 -1 cancels 0 -done 2 diff --git a/tests/extmod/asyncio_cancel_fair2.py.exp b/tests/extmod/asyncio_cancel_fair2.py.exp deleted file mode 100644 index e9dd649b453f9..0000000000000 --- a/tests/extmod/asyncio_cancel_fair2.py.exp +++ /dev/null @@ -1,8 +0,0 @@ -sleep a -sleep b 0 -sleep b 1 -sleep b 2 -cancelled a -done b 0 -done b 1 -done b 2 diff --git a/tests/extmod/asyncio_cancel_task.py.exp b/tests/extmod/asyncio_cancel_task.py.exp deleted file mode 100644 index 031b94023fd03..0000000000000 --- a/tests/extmod/asyncio_cancel_task.py.exp +++ /dev/null @@ -1,31 +0,0 @@ -True -task start -True -main sleep -task cancel -task start -True -True -True -True -main sleep -task cancel -main wait -main got CancelledError -task start -task done -False ----- -task 2 -task start -main cancel -main sleep -task cancel -task 2 cancel ----- -task 2 -task start -main cancel -main sleep -task cancel -task 2 done diff --git a/tests/extmod/asyncio_cancel_wait_on_finished.py.exp b/tests/extmod/asyncio_cancel_wait_on_finished.py.exp deleted file mode 100644 index 60e871bfe56f0..0000000000000 --- a/tests/extmod/asyncio_cancel_wait_on_finished.py.exp +++ /dev/null @@ -1,7 +0,0 @@ -main sleep -sleep_task sleep -wait_task wait -main sleep -sleep_task wake -main wait -CancelledError() diff --git a/tests/extmod/asyncio_current_task.py b/tests/extmod/asyncio_current_task.py index 18058230f2d90..a25e543d0c5b1 100644 --- a/tests/extmod/asyncio_current_task.py +++ b/tests/extmod/asyncio_current_task.py @@ -19,4 +19,15 @@ async def main(): print(t is result[0]) +try: + print(asyncio.current_task()) +except RuntimeError: + print("RuntimeError") + + asyncio.run(main()) + +try: + print(asyncio.current_task()) +except RuntimeError: + print("RuntimeError") diff --git a/tests/extmod/asyncio_current_task.py.exp b/tests/extmod/asyncio_current_task.py.exp deleted file mode 100644 index 0ca95142bb715..0000000000000 --- a/tests/extmod/asyncio_current_task.py.exp +++ /dev/null @@ -1 +0,0 @@ -True diff --git a/tests/extmod/asyncio_event.py.exp b/tests/extmod/asyncio_event.py.exp deleted file mode 100644 index 3188f291e584d..0000000000000 --- a/tests/extmod/asyncio_event.py.exp +++ /dev/null @@ -1,33 +0,0 @@ -False -True -False ----- -yield -start 1 -start 2 -set event -yield -True -end 1 -True -end 2 ----- -yield -start 3 -True -end 3 ----- -clear event -start 4 -set event -True -end 4 ----- -start 5 ----- -start 6 ----- -set event ----- -TimeoutError -set event diff --git a/tests/extmod/asyncio_event_fair.py b/tests/extmod/asyncio_event_fair.py index d8f398dbcb751..ebbf32221143c 100644 --- a/tests/extmod/asyncio_event_fair.py +++ b/tests/extmod/asyncio_event_fair.py @@ -12,9 +12,11 @@ async def foo(): return 42 - try: - foo().__await__ + fooc = foo() + fooc.__await__ + # Avoid "coroutine was never awaited" warning + asyncio.run(fooc) except AttributeError: print("SKIP") raise SystemExit diff --git a/tests/extmod/asyncio_event_fair.py.exp b/tests/extmod/asyncio_event_fair.py.exp deleted file mode 100644 index fe2e3d6e47a63..0000000000000 --- a/tests/extmod/asyncio_event_fair.py.exp +++ /dev/null @@ -1,16 +0,0 @@ -sleep 0 -wait 2 -sleep 1 -wait 3 -sleep 0 -sleep 1 -wait 2 -sleep 0 -sleep 1 -wait 3 -sleep 0 -sleep 1 -wait 2 -wait 3 -wait 2 -wait 3 diff --git a/tests/extmod/asyncio_exception.py.exp b/tests/extmod/asyncio_exception.py.exp deleted file mode 100644 index b2ee860170ece..0000000000000 --- a/tests/extmod/asyncio_exception.py.exp +++ /dev/null @@ -1,7 +0,0 @@ -main start -ValueError 1 -main start -task start -ValueError 2 -main start -ValueError 3 diff --git a/tests/extmod/asyncio_fair.py b/tests/extmod/asyncio_fair.py index 43076fef1d707..3e3ac04735898 100644 --- a/tests/extmod/asyncio_fair.py +++ b/tests/extmod/asyncio_fair.py @@ -20,7 +20,7 @@ async def main(): t2 = asyncio.create_task(task(2, 0.1)) t3 = asyncio.create_task(task(3, 0.18)) t4 = asyncio.create_task(task(4, -100)) - await asyncio.sleep(0.5) + await asyncio.sleep(0.45) # t2 prints 5 times, t3 prints 3 times t1.cancel() t2.cancel() t3.cancel() diff --git a/tests/extmod/asyncio_fair.py.exp b/tests/extmod/asyncio_fair.py.exp deleted file mode 100644 index b4b6481db019f..0000000000000 --- a/tests/extmod/asyncio_fair.py.exp +++ /dev/null @@ -1,13 +0,0 @@ -task start 1 -task start 2 -task work 2 -task start 3 -task work 3 -task start 4 -task work 2 -task work 3 -task work 2 -task work 2 -task work 3 -task work 2 -finish diff --git a/tests/extmod/asyncio_gather.py b/tests/extmod/asyncio_gather.py index bb16db381f8c9..3095af203187b 100644 --- a/tests/extmod/asyncio_gather.py +++ b/tests/extmod/asyncio_gather.py @@ -13,7 +13,10 @@ async def foo(): try: - foo().__await__ + fooc = foo() + fooc.__await__ + # Avoid "coroutine was never awaited" warning + asyncio.run(fooc) except AttributeError: print("SKIP") raise SystemExit diff --git a/tests/extmod/asyncio_gather_notimpl.py b/tests/extmod/asyncio_gather_notimpl.py index 5e4cc44a4a3b5..be1b974a69a46 100644 --- a/tests/extmod/asyncio_gather_notimpl.py +++ b/tests/extmod/asyncio_gather_notimpl.py @@ -13,7 +13,10 @@ async def foo(): try: - foo().__await__ + fooc = foo() + fooc.__await__ + # Avoid "coroutine was never awaited" warning + asyncio.run(fooc) except AttributeError: print("SKIP") raise SystemExit diff --git a/tests/extmod/asyncio_get_event_loop.py b/tests/extmod/asyncio_get_event_loop.py index 6ecbb13b57a6a..c9cfa7bf00ed9 100644 --- a/tests/extmod/asyncio_get_event_loop.py +++ b/tests/extmod/asyncio_get_event_loop.py @@ -1,4 +1,5 @@ # Test get_event_loop() +# Note: CPython deprecated get_event_loop() so this test needs a .exp try: import asyncio diff --git a/tests/extmod/asyncio_get_event_loop.py.exp b/tests/extmod/asyncio_get_event_loop.py.exp new file mode 100644 index 0000000000000..5d0fb3b2d2edd --- /dev/null +++ b/tests/extmod/asyncio_get_event_loop.py.exp @@ -0,0 +1,2 @@ +start +end diff --git a/tests/extmod/asyncio_lock.py b/tests/extmod/asyncio_lock.py index f565adb03fc39..10d3285be0f86 100644 --- a/tests/extmod/asyncio_lock.py +++ b/tests/extmod/asyncio_lock.py @@ -1,4 +1,8 @@ # Test Lock class +# +# This test has a corresponding .exp file because it tests a very specific ordering of +# events when cancelling a task waiting on a lock, and that ordering should not change +# (even though it does match CPython's output). try: import asyncio diff --git a/tests/extmod/asyncio_lock_cancel.py b/tests/extmod/asyncio_lock_cancel.py index 27fe108b0e1e8..63b2a29bcbce1 100644 --- a/tests/extmod/asyncio_lock_cancel.py +++ b/tests/extmod/asyncio_lock_cancel.py @@ -1,7 +1,7 @@ # Test that locks work when cancelling multiple waiters on the lock try: - import uasyncio as asyncio + import asyncio except ImportError: print("SKIP") raise SystemExit @@ -13,7 +13,10 @@ async def foo(): try: - foo().__await__ + fooc = foo() + fooc.__await__ + # Avoid "coroutine was never awaited" warning + asyncio.run(fooc) except AttributeError: print("SKIP") raise SystemExit diff --git a/tests/extmod/asyncio_lock_cancel.py.exp b/tests/extmod/asyncio_lock_cancel.py.exp deleted file mode 100644 index 49ae253887436..0000000000000 --- a/tests/extmod/asyncio_lock_cancel.py.exp +++ /dev/null @@ -1,11 +0,0 @@ -task 0 start -task 1 start -task 2 start -task 3 start -task 1 cancel -task 2 cancel -task 0 lock_flag False -task 0 done -task 3 lock_flag False -task 3 done -False diff --git a/tests/extmod/asyncio_loop_stop.py b/tests/extmod/asyncio_loop_stop.py index b4bd0c74ad90a..e2a4cdc1af853 100644 --- a/tests/extmod/asyncio_loop_stop.py +++ b/tests/extmod/asyncio_loop_stop.py @@ -34,7 +34,7 @@ async def main(): loop.stop() -loop = asyncio.get_event_loop() +loop = asyncio.new_event_loop() loop.create_task(main()) for i in range(3): diff --git a/tests/extmod/asyncio_loop_stop.py.exp b/tests/extmod/asyncio_loop_stop.py.exp deleted file mode 100644 index bada5f0d8412c..0000000000000 --- a/tests/extmod/asyncio_loop_stop.py.exp +++ /dev/null @@ -1,7 +0,0 @@ -run 0 -start -sleep -run 1 -run 2 -task -end diff --git a/tests/extmod/asyncio_new_event_loop.py b/tests/extmod/asyncio_new_event_loop.py index a3feb02126c70..5bb31f1292bb1 100644 --- a/tests/extmod/asyncio_new_event_loop.py +++ b/tests/extmod/asyncio_new_event_loop.py @@ -1,4 +1,5 @@ # Test Loop.new_event_loop() +# Note: CPython deprecated get_event_loop() so this test needs a .exp try: import asyncio diff --git a/tests/extmod/asyncio_set_exception_handler.py.exp b/tests/extmod/asyncio_set_exception_handler.py.exp deleted file mode 100644 index fb4711469dc5b..0000000000000 --- a/tests/extmod/asyncio_set_exception_handler.py.exp +++ /dev/null @@ -1,9 +0,0 @@ -None -True -sleep -custom_handler ValueError(0, 1) -sleep -custom_handler ValueError(1, 2) -custom_handler ValueError(2, 3) -ValueError(3, 4) -done diff --git a/tests/extmod/asyncio_task_done.py.exp b/tests/extmod/asyncio_task_done.py.exp deleted file mode 100644 index ddda04c5ec43b..0000000000000 --- a/tests/extmod/asyncio_task_done.py.exp +++ /dev/null @@ -1,24 +0,0 @@ -========== -False -task start -task done -True -True -========== -False -task start -False -task done -True -========== -False -task start -True -ValueError() -True -========== -False -task start -False -ValueError() -True diff --git a/tests/extmod/asyncio_wait_for_fwd.py b/tests/extmod/asyncio_wait_for_fwd.py index fd7dc6ff3d3a5..9574678ed0923 100644 --- a/tests/extmod/asyncio_wait_for_fwd.py +++ b/tests/extmod/asyncio_wait_for_fwd.py @@ -13,7 +13,10 @@ async def foo(): try: - foo().__await__ + fooc = foo() + fooc.__await__ + # Avoid "coroutine was never awaited" warning + asyncio.run(fooc) except AttributeError: print("SKIP") raise SystemExit diff --git a/tests/extmod/asyncio_wait_task.py b/tests/extmod/asyncio_wait_task.py index bce426d971046..7d79104f8cf8f 100644 --- a/tests/extmod/asyncio_wait_task.py +++ b/tests/extmod/asyncio_wait_task.py @@ -68,5 +68,16 @@ async def main(): except ValueError: print("ValueError") + # Wait on a task that raises, but the waiting is done some time later. + # Need to suppress the "Task exception wasn't retrieved" message. + asyncio.get_event_loop().set_exception_handler(lambda loop, context: None) + t = asyncio.create_task(task_raise()) + for _ in range(5): + await asyncio.sleep(0) + try: + await t + except ValueError: + print("ValueError") + asyncio.run(main()) diff --git a/tests/extmod/asyncio_wait_task.py.exp b/tests/extmod/asyncio_wait_task.py.exp index 04be37f48406d..514a434223315 100644 --- a/tests/extmod/asyncio_wait_task.py.exp +++ b/tests/extmod/asyncio_wait_task.py.exp @@ -8,3 +8,5 @@ world took 200 200 task_raise ValueError +task_raise +ValueError diff --git a/tests/extmod/json_load_readinto.py b/tests/extmod/json_load_readinto.py index 25e5c6cc0cd36..740a21ef40e89 100644 --- a/tests/extmod/json_load_readinto.py +++ b/tests/extmod/json_load_readinto.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this file import json # Test that json can load from any object with readinto diff --git a/tests/extmod/msgpack_pack.py b/tests/extmod/msgpack_pack.py index 511ee642dd55a..edf58c2c6c363 100644 --- a/tests/extmod/msgpack_pack.py +++ b/tests/extmod/msgpack_pack.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this file try: from io import BytesIO import msgpack diff --git a/tests/extmod/qrio.py b/tests/extmod/qrio.py index 53c83706f8803..9dcc12054633c 100644 --- a/tests/extmod/qrio.py +++ b/tests/extmod/qrio.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this file try: import qrio except: diff --git a/tests/extmod/re1.py b/tests/extmod/re1.py index 0680a65889d3a..34647325106ef 100644 --- a/tests/extmod/re1.py +++ b/tests/extmod/re1.py @@ -25,7 +25,7 @@ except IndexError: print("IndexError") -# CIRCUITPY-CHANGE +# CIRCUITPY-CHANGE: line-ending tests r = re.compile(r"\n") m = r.match("\n") print(m.group(0)) diff --git a/tests/extmod/ssl_sslcontext_ciphers.py b/tests/extmod/ssl_sslcontext_ciphers.py deleted file mode 100644 index 20c00b917623c..0000000000000 --- a/tests/extmod/ssl_sslcontext_ciphers.py +++ /dev/null @@ -1,31 +0,0 @@ -# Basic test of ssl.SSLContext get_ciphers() and set_ciphers() methods. - -try: - import ssl -except ImportError: - print("SKIP") - raise SystemExit - - -ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) - -ciphers = ctx.get_ciphers() - -for ci in ciphers: - # Only print those ciphers know to exist on all ports. - if ("TLS-ECDHE-ECDSA-WITH-AES" in ci or "TLS-RSA-WITH-AES" in ci) and "CBC" in ci: - print(ci) - -ctx.set_ciphers(ciphers[:1]) - -# Test error cases. - -try: - ctx.set_ciphers(ciphers[0]) -except TypeError as e: - print(e) - -try: - ctx.set_ciphers(["BAR"]) -except OSError as e: - print(e) diff --git a/tests/extmod/ssl_sslcontext_ciphers.py.exp b/tests/extmod/ssl_sslcontext_ciphers.py.exp deleted file mode 100644 index 0d21a3bd253e7..0000000000000 --- a/tests/extmod/ssl_sslcontext_ciphers.py.exp +++ /dev/null @@ -1,10 +0,0 @@ -TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA384 -TLS-ECDHE-ECDSA-WITH-AES-256-CBC-SHA -TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA256 -TLS-ECDHE-ECDSA-WITH-AES-128-CBC-SHA -TLS-RSA-WITH-AES-256-CBC-SHA256 -TLS-RSA-WITH-AES-256-CBC-SHA -TLS-RSA-WITH-AES-128-CBC-SHA256 -TLS-RSA-WITH-AES-128-CBC-SHA -object 'str' isn't a tuple or list -(-24192, 'MBEDTLS_ERR_SSL_BAD_CONFIG') diff --git a/tests/extmod/ssl_sslcontext_micropython.py b/tests/extmod/ssl_sslcontext_micropython.py deleted file mode 100644 index 136fb8a054ed7..0000000000000 --- a/tests/extmod/ssl_sslcontext_micropython.py +++ /dev/null @@ -1,29 +0,0 @@ -# Test MicroPython-specific behaviour of ssl.SSLContext. - -try: - import ssl -except ImportError: - print("SKIP") - raise SystemExit - -# Test constructing without any arguments (in CPython it's a DeprecationWarning). -try: - ssl.SSLContext() -except TypeError: - print("TypeError") - -# Test attributes that don't exist (in CPython new attributes can be added). -# This test is needed for coverage because SSLContext implements a custom attr handler. -ctx = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) -try: - ctx.does_not_exist -except AttributeError: - print("AttributeError on load") -try: - ctx.does_not_exist = None -except AttributeError: - print("AttributeError on store") -try: - del ctx.does_not_exist -except AttributeError: - print("AttributeError on delete") diff --git a/tests/extmod/ssl_sslcontext_micropython.py.exp b/tests/extmod/ssl_sslcontext_micropython.py.exp deleted file mode 100644 index 21e65258ff2a1..0000000000000 --- a/tests/extmod/ssl_sslcontext_micropython.py.exp +++ /dev/null @@ -1,4 +0,0 @@ -TypeError -AttributeError on load -AttributeError on store -AttributeError on delete diff --git a/tests/extmod/uctypes_array_load_store.py b/tests/extmod/uctypes_array_load_store.py index 0a82d789605c9..9de079998566f 100644 --- a/tests/extmod/uctypes_array_load_store.py +++ b/tests/extmod/uctypes_array_load_store.py @@ -15,6 +15,7 @@ data = bytearray(sz) s = uctypes.struct(uctypes.addressof(data), desc, getattr(uctypes, endian)) for i in range(N): + # CIRCUITPY-CHANGE: overflow checks try: s.arr[i] = i - 2 except OverflowError: diff --git a/tests/extmod/vfs_basic.py b/tests/extmod/vfs_basic.py index 028846406a145..2c0ce8f5295ad 100644 --- a/tests/extmod/vfs_basic.py +++ b/tests/extmod/vfs_basic.py @@ -1,10 +1,8 @@ # test VFS functionality without any particular filesystem type try: - import os - - os.mount -except (ImportError, AttributeError): + import os, vfs +except ImportError: print("SKIP") raise SystemExit @@ -59,11 +57,11 @@ def open(self, file, mode): # first we umount any existing mount points the target may have try: - os.umount("/") + vfs.umount("/") except OSError: pass for path in os.listdir("/"): - os.umount("/" + path) + vfs.umount("/" + path) # stat root dir print(os.stat("/")) @@ -83,7 +81,7 @@ def open(self, file, mode): print(func, arg, "OSError") # basic mounting and listdir -os.mount(Filesystem(1), "/test_mnt") +vfs.mount(Filesystem(1), "/test_mnt") print(os.listdir()) # ilistdir @@ -103,13 +101,13 @@ def open(self, file, mode): print(os.listdir("/test_mnt")) # mounting another filesystem -os.mount(Filesystem(2), "/test_mnt2", readonly=True) +vfs.mount(Filesystem(2), "/test_mnt2", readonly=True) print(os.listdir()) print(os.listdir("/test_mnt2")) # mounting over an existing mount point try: - os.mount(Filesystem(3), "/test_mnt2") + vfs.mount(Filesystem(3), "/test_mnt2") except OSError: print("OSError") @@ -139,23 +137,23 @@ def open(self, file, mode): open("test_file", "wb") # umount -os.umount("/test_mnt") -os.umount("/test_mnt2") +vfs.umount("/test_mnt") +vfs.umount("/test_mnt2") # umount a non-existent mount point try: - os.umount("/test_mnt") + vfs.umount("/test_mnt") except OSError: print("OSError") # root dir -os.mount(Filesystem(3), "/") +vfs.mount(Filesystem(3), "/") print(os.stat("/")) print(os.statvfs("/")) print(os.listdir()) open("test") -os.mount(Filesystem(4), "/mnt") +vfs.mount(Filesystem(4), "/mnt") print(os.listdir()) print(os.listdir("/mnt")) os.chdir("/mnt") @@ -166,9 +164,9 @@ def open(self, file, mode): print(os.listdir()) os.chdir("/") -os.umount("/") +vfs.umount("/") print(os.listdir("/")) -os.umount("/mnt") +vfs.umount("/mnt") # chdir to a non-existent mount point (current directory should remain unchanged) try: @@ -178,7 +176,7 @@ def open(self, file, mode): print(os.getcwd()) # chdir to a non-existent subdirectory in a mounted filesystem -os.mount(Filesystem(5, 1), "/mnt") +vfs.mount(Filesystem(5, 1), "/mnt") try: os.chdir("/mnt/subdir") except OSError: diff --git a/tests/extmod/vfs_blockdev.py b/tests/extmod/vfs_blockdev.py index f4c84ea9213c2..a1f0749962745 100644 --- a/tests/extmod/vfs_blockdev.py +++ b/tests/extmod/vfs_blockdev.py @@ -1,10 +1,10 @@ # Test for behaviour of combined standard and extended block device try: - import os + import vfs - os.VfsFat - os.VfsLfs2 + vfs.VfsFat + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -65,12 +65,10 @@ def test(bdev, vfs_class): try: - import os - bdev = RAMBlockDevice(50) except MemoryError: print("SKIP") raise SystemExit -test(bdev, os.VfsFat) -test(bdev, os.VfsLfs2) +test(bdev, vfs.VfsFat) +test(bdev, vfs.VfsLfs2) diff --git a/tests/extmod/vfs_fat_case.py b/tests/extmod/vfs_fat_case.py index bf2c18ea69f11..6bc15eab10a44 100644 --- a/tests/extmod/vfs_fat_case.py +++ b/tests/extmod/vfs_fat_case.py @@ -1,3 +1,4 @@ +# CIRCUITPY-CHANGE: micropython does not have this file import errno import os as os diff --git a/tests/extmod/vfs_fat_fileio1.py b/tests/extmod/vfs_fat_fileio1.py index 9f8bb9162db81..ca702e373adb4 100644 --- a/tests/extmod/vfs_fat_fileio1.py +++ b/tests/extmod/vfs_fat_fileio1.py @@ -1,13 +1,8 @@ try: - import errno - import os -except ImportError: - print("SKIP") - raise SystemExit + import errno, os, vfs -try: - os.VfsFat -except AttributeError: + vfs.VfsFat +except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -40,13 +35,13 @@ def ioctl(self, op, arg): try: bdev = RAMFS(50) - os.VfsFat.mkfs(bdev) + vfs.VfsFat.mkfs(bdev) except MemoryError: print("SKIP") raise SystemExit -vfs = os.VfsFat(bdev) -os.mount(vfs, "/ramdisk") +fs = vfs.VfsFat(bdev) +vfs.mount(fs, "/ramdisk") os.chdir("/ramdisk") # file IO @@ -101,12 +96,12 @@ def ioctl(self, op, arg): # print(f.read()) # dirs -vfs.mkdir("foo_dir") +fs.mkdir("foo_dir") try: - vfs.rmdir("foo_file.txt") + fs.rmdir("foo_file.txt") except OSError as e: print(e.errno == 20) # errno.ENOTDIR -vfs.remove("foo_file.txt") -print(list(vfs.ilistdir())) +fs.remove("foo_file.txt") +print(list(fs.ilistdir())) diff --git a/tests/extmod/vfs_fat_fileio2.py b/tests/extmod/vfs_fat_fileio2.py index 4059ec337daea..744f3bf11b1dd 100644 --- a/tests/extmod/vfs_fat_fileio2.py +++ b/tests/extmod/vfs_fat_fileio2.py @@ -1,13 +1,8 @@ try: - import errno - import os -except ImportError: - print("SKIP") - raise SystemExit + import errno, os, vfs -try: - os.VfsFat -except AttributeError: + vfs.VfsFat +except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -38,32 +33,32 @@ def ioctl(self, op, arg): try: bdev = RAMFS(50) - os.VfsFat.mkfs(bdev) + vfs.VfsFat.mkfs(bdev) except MemoryError: print("SKIP") raise SystemExit -vfs = os.VfsFat(bdev) -os.mount(vfs, "/ramdisk") +fs = vfs.VfsFat(bdev) +vfs.mount(fs, "/ramdisk") os.chdir("/ramdisk") try: - vfs.mkdir("foo_dir") + fs.mkdir("foo_dir") except OSError as e: print(e.errno == errno.EEXIST) try: - vfs.remove("foo_dir") + fs.remove("foo_dir") except OSError as e: print(e.errno == errno.EISDIR) try: - vfs.remove("no_file.txt") + fs.remove("no_file.txt") except OSError as e: print(e.errno == errno.ENOENT) try: - vfs.rename("foo_dir", "/null/file") + fs.rename("foo_dir", "/null/file") except OSError as e: print(e.errno == errno.ENOENT) @@ -85,34 +80,34 @@ def ioctl(self, op, arg): # directory not empty try: - vfs.rmdir("foo_dir") + fs.rmdir("foo_dir") except OSError as e: print(e.errno == errno.EACCES) # trim full path -vfs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt") -print(list(vfs.ilistdir("foo_dir"))) +fs.rename("foo_dir/file-in-dir.txt", "foo_dir/file.txt") +print(list(fs.ilistdir("foo_dir"))) -vfs.rename("foo_dir/file.txt", "moved-to-root.txt") -print(list(vfs.ilistdir())) +fs.rename("foo_dir/file.txt", "moved-to-root.txt") +print(list(fs.ilistdir())) # check that renaming to existing file will overwrite it with open("temp", "w") as f: f.write("new text") -vfs.rename("temp", "moved-to-root.txt") -print(list(vfs.ilistdir())) +fs.rename("temp", "moved-to-root.txt") +print(list(fs.ilistdir())) with open("moved-to-root.txt") as f: print(f.read()) # valid removes -vfs.remove("foo_dir/sub_file.txt") -vfs.rmdir("foo_dir") -print(list(vfs.ilistdir())) +fs.remove("foo_dir/sub_file.txt") +fs.rmdir("foo_dir") +print(list(fs.ilistdir())) # disk full try: - bsize = vfs.statvfs("/ramdisk")[0] - free = vfs.statvfs("/ramdisk")[2] + 1 + bsize = fs.statvfs("/ramdisk")[0] + free = fs.statvfs("/ramdisk")[2] + 1 f = open("large_file.txt", "wb") f.write(bytearray(bsize * free)) except OSError as e: diff --git a/tests/extmod/vfs_fat_finaliser.py b/tests/extmod/vfs_fat_finaliser.py index a2cce7846c22b..7be3cda1a353a 100644 --- a/tests/extmod/vfs_fat_finaliser.py +++ b/tests/extmod/vfs_fat_finaliser.py @@ -1,9 +1,9 @@ # Test VfsFat class and its finaliser try: - import errno, os + import errno, os, vfs - os.VfsFat + vfs.VfsFat except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -39,8 +39,8 @@ def ioctl(self, op, arg): raise SystemExit # Format block device and create VFS object -os.VfsFat.mkfs(bdev) -vfs = os.VfsFat(bdev) +vfs.VfsFat.mkfs(bdev) +fs = vfs.VfsFat(bdev) # Here we test that opening a file with the heap locked fails correctly. This # is a special case because file objects use a finaliser and allocating with a @@ -52,7 +52,7 @@ def ioctl(self, op, arg): try: import errno, os - vfs.open("x", "r") + fs.open("x", "r") except MemoryError: print("MemoryError") micropython.heap_unlock() @@ -77,10 +77,10 @@ def ioctl(self, op, arg): # Only read back N-1 files because the last one may not be finalised due to # references to it being left on the C stack. for n in names: - f = vfs.open(n, "w") + f = fs.open(n, "w") f.write(n) f = None # release f without closing gc.collect() # should finalise at least the first N-1 files by closing them for n in names[:-1]: - with vfs.open(n, "r") as f: + with fs.open(n, "r") as f: print(f.read()) diff --git a/tests/extmod/vfs_fat_ilistdir_del.py b/tests/extmod/vfs_fat_ilistdir_del.py index 055836ad71bef..a6e24ec92f3b5 100644 --- a/tests/extmod/vfs_fat_ilistdir_del.py +++ b/tests/extmod/vfs_fat_ilistdir_del.py @@ -2,9 +2,9 @@ import gc try: - import os + import os, vfs - os.VfsFat + vfs.VfsFat except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -37,29 +37,29 @@ def ioctl(self, op, arg): def test(bdev, vfs_class): vfs_class.mkfs(bdev) - vfs = vfs_class(bdev) - vfs.mkdir("/test_d1") - vfs.mkdir("/test_d2") - vfs.mkdir("/test_d3") + fs = vfs_class(bdev) + fs.mkdir("/test_d1") + fs.mkdir("/test_d2") + fs.mkdir("/test_d3") for i in range(10): print(i) # We want to partially iterate the ilistdir iterator to leave it in an # open state, which will then test the finaliser when it's garbage collected. - idir = vfs.ilistdir("/") + idir = fs.ilistdir("/") print(any(idir)) # Alternate way of partially iterating the ilistdir object, modifying the # filesystem while it's open. - for dname, *_ in vfs.ilistdir("/"): - vfs.rmdir(dname) + for dname, *_ in fs.ilistdir("/"): + fs.rmdir(dname) break - vfs.mkdir(dname) + fs.mkdir(dname) - # Also create a fully drained iterator and ensure trying to re-use it + # Also create a fully drained iterator and ensure trying to reuse it # throws the correct exception. - idir_emptied = vfs.ilistdir("/") + idir_emptied = fs.ilistdir("/") l = list(idir_emptied) print(len(l)) try: @@ -68,7 +68,7 @@ def test(bdev, vfs_class): pass gc.collect() - vfs.open("/test", "w").close() + fs.open("/test", "w").close() try: @@ -77,4 +77,4 @@ def test(bdev, vfs_class): print("SKIP") raise SystemExit -test(bdev, os.VfsFat) +test(bdev, vfs.VfsFat) diff --git a/tests/extmod/vfs_fat_more.py b/tests/extmod/vfs_fat_more.py index 9096024c4a960..6605964d43323 100644 --- a/tests/extmod/vfs_fat_more.py +++ b/tests/extmod/vfs_fat_more.py @@ -1,12 +1,8 @@ try: - import os -except ImportError: - print("SKIP") - raise SystemExit + import os, vfs -try: - os.VfsFat -except AttributeError: + vfs.VfsFat +except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -46,14 +42,14 @@ def ioctl(self, op, arg): # first we umount any existing mount points the target may have try: - os.umount("/") + vfs.umount("/") except OSError: pass for path in os.listdir("/"): - os.umount("/" + path) + vfs.umount("/" + path) -os.VfsFat.mkfs(bdev) -os.mount(bdev, "/") +vfs.VfsFat.mkfs(bdev) +vfs.mount(bdev, "/") print(os.getcwd()) @@ -96,8 +92,8 @@ def ioctl(self, op, arg): os.chdir("/") print(os.stat("test5.txt")[:-3]) -os.VfsFat.mkfs(bdev2) -os.mount(bdev2, "/sys") +vfs.VfsFat.mkfs(bdev2) +vfs.mount(bdev2, "/sys") print(os.listdir()) print(os.listdir("sys")) print(os.listdir("/sys")) @@ -106,7 +102,7 @@ def ioctl(self, op, arg): os.remove("test5.txt") print(os.listdir()) -os.umount("/") +vfs.umount("/") print(os.getcwd()) print(os.listdir()) print(os.listdir("sys")) diff --git a/tests/extmod/vfs_fat_mtime.py b/tests/extmod/vfs_fat_mtime.py index 1ceb611364a18..0c7e10a54869d 100644 --- a/tests/extmod/vfs_fat_mtime.py +++ b/tests/extmod/vfs_fat_mtime.py @@ -1,11 +1,11 @@ # Test for VfsFat using a RAM device, mtime feature try: - import time, os + import time, os, vfs time.time time.sleep - os.VfsFat + vfs.VfsFat except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -41,21 +41,21 @@ def test(bdev, vfs_class): vfs_class.mkfs(bdev) # construction - vfs = vfs_class(bdev) + fs = vfs_class(bdev) # Create an empty file, should have a timestamp. current_time = int(time.time()) - vfs.open("test1", "wt").close() + fs.open("test1", "wt").close() # Wait 2 seconds so mtime will increase (FAT has 2 second resolution). time.sleep(2) # Create another empty file, should have a timestamp. - vfs.open("test2", "wt").close() + fs.open("test2", "wt").close() # Stat the files and check mtime is non-zero. - stat1 = vfs.stat("test1") - stat2 = vfs.stat("test2") + stat1 = fs.stat("test1") + stat2 = fs.stat("test2") print(stat1[8] != 0, stat2[8] != 0) # Check that test1 has mtime which matches time.time() at point of creation. @@ -67,8 +67,8 @@ def test(bdev, vfs_class): print(stat1[8] < stat2[8]) # Unmount. - vfs.umount() + fs.umount() bdev = RAMBlockDevice(50) -test(bdev, os.VfsFat) +test(bdev, vfs.VfsFat) diff --git a/tests/extmod/vfs_fat_oldproto.py b/tests/extmod/vfs_fat_oldproto.py index 72b414cf01b16..53c262cdd9c8b 100644 --- a/tests/extmod/vfs_fat_oldproto.py +++ b/tests/extmod/vfs_fat_oldproto.py @@ -1,13 +1,8 @@ try: - import errno - import os -except ImportError: - print("SKIP") - raise SystemExit + import errno, os, vfs -try: - os.VfsFat -except AttributeError: + vfs.VfsFat +except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -45,18 +40,18 @@ def count(self): print("SKIP") raise SystemExit -os.VfsFat.mkfs(bdev) -vfs = os.VfsFat(bdev) -os.mount(vfs, "/ramdisk") +vfs.VfsFat.mkfs(bdev) +fs = vfs.VfsFat(bdev) +vfs.mount(fs, "/ramdisk") # file io -with vfs.open("file.txt", "w") as f: +with fs.open("file.txt", "w") as f: f.write("hello!") -print(list(vfs.ilistdir())) +print(list(fs.ilistdir())) -with vfs.open("file.txt", "r") as f: +with fs.open("file.txt", "r") as f: print(f.read()) -vfs.remove("file.txt") -print(list(vfs.ilistdir())) +fs.remove("file.txt") +print(list(fs.ilistdir())) diff --git a/tests/extmod/vfs_fat_ramdisk.py b/tests/extmod/vfs_fat_ramdisk.py index 6f822892d408a..d3836414c4dee 100644 --- a/tests/extmod/vfs_fat_ramdisk.py +++ b/tests/extmod/vfs_fat_ramdisk.py @@ -1,13 +1,8 @@ try: - import errno - import os -except ImportError: - print("SKIP") - raise SystemExit + import errno, os, vfs -try: - os.VfsFat -except AttributeError: + vfs.VfsFat +except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -42,7 +37,7 @@ def ioctl(self, op, arg): try: bdev = RAMFS(50) - os.VfsFat.mkfs(bdev) + vfs.VfsFat.mkfs(bdev) except MemoryError: print("SKIP") raise SystemExit @@ -50,53 +45,50 @@ def ioctl(self, op, arg): print(b"FOO_FILETXT" not in bdev.data) print(b"hello!" not in bdev.data) -vfs = os.VfsFat(bdev) -os.mount(vfs, "/ramdisk") +fs = vfs.VfsFat(bdev) +vfs.mount(fs, "/ramdisk") -# CIRCUITPY-CHANGE -vfs.label = "label test" -print("label:", vfs.label) -print("statvfs:", vfs.statvfs("/ramdisk")) -print("getcwd:", vfs.getcwd()) +print("statvfs:", fs.statvfs("/ramdisk")) +print("getcwd:", fs.getcwd()) try: - vfs.stat("no_file.txt") + fs.stat("no_file.txt") except OSError as e: print(e.errno == errno.ENOENT) -with vfs.open("foo_file.txt", "w") as f: +with fs.open("foo_file.txt", "w") as f: f.write("hello!") -print(list(vfs.ilistdir())) +print(list(fs.ilistdir())) -print("stat root:", vfs.stat("/")[:-3]) # timestamps differ across runs -print("stat file:", vfs.stat("foo_file.txt")[:-3]) # timestamps differ across runs +print("stat root:", fs.stat("/")[:-3]) # timestamps differ across runs +print("stat file:", fs.stat("foo_file.txt")[:-3]) # timestamps differ across runs print(b"FOO_FILETXT" in bdev.data) print(b"hello!" in bdev.data) -vfs.mkdir("foo_dir") -vfs.chdir("foo_dir") -print("getcwd:", vfs.getcwd()) -print(list(vfs.ilistdir())) +fs.mkdir("foo_dir") +fs.chdir("foo_dir") +print("getcwd:", fs.getcwd()) +print(list(fs.ilistdir())) -with vfs.open("sub_file.txt", "w") as f: +with fs.open("sub_file.txt", "w") as f: f.write("subdir file") try: - vfs.chdir("sub_file.txt") + fs.chdir("sub_file.txt") except OSError as e: print(e.errno == errno.ENOENT) -vfs.chdir("..") -print("getcwd:", vfs.getcwd()) +fs.chdir("..") +print("getcwd:", fs.getcwd()) -os.umount(vfs) +vfs.umount(fs) -vfs = os.VfsFat(bdev) -print(list(vfs.ilistdir(b""))) +fs = vfs.VfsFat(bdev) +print(list(fs.ilistdir(b""))) # list a non-existent directory try: - vfs.ilistdir(b"no_exist") + fs.ilistdir(b"no_exist") except OSError as e: print("ENOENT:", e.errno == errno.ENOENT) diff --git a/tests/extmod/vfs_fat_ramdisklarge.py b/tests/extmod/vfs_fat_ramdisklarge.py index 40cba9ee430a1..38ad772b44397 100644 --- a/tests/extmod/vfs_fat_ramdisklarge.py +++ b/tests/extmod/vfs_fat_ramdisklarge.py @@ -1,14 +1,10 @@ # test making a FAT filesystem on a very large block device try: - import os -except ImportError: - print("SKIP") - raise SystemExit + import os, vfs -try: - os.VfsFat -except AttributeError: + vfs.VfsFat +except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -46,24 +42,24 @@ def ioctl(self, op, arg): try: bdev = RAMBDevSparse(4 * 1024 * 1024 * 1024 // RAMBDevSparse.SEC_SIZE) - os.VfsFat.mkfs(bdev) + vfs.VfsFat.mkfs(bdev) except MemoryError: print("SKIP") raise SystemExit -vfs = os.VfsFat(bdev) -os.mount(vfs, "/ramdisk") +fs = vfs.VfsFat(bdev) +vfs.mount(fs, "/ramdisk") -print("statvfs:", vfs.statvfs("/ramdisk")) +print("statvfs:", fs.statvfs("/ramdisk")) f = open("/ramdisk/test.txt", "w") f.write("test file") f.close() -print("statvfs:", vfs.statvfs("/ramdisk")) +print("statvfs:", fs.statvfs("/ramdisk")) f = open("/ramdisk/test.txt") print(f.read()) f.close() -os.umount(vfs) +vfs.umount(fs) diff --git a/tests/extmod/vfs_lfs.py b/tests/extmod/vfs_lfs.py index 83377653b2cfb..3ad57fd9c38f1 100644 --- a/tests/extmod/vfs_lfs.py +++ b/tests/extmod/vfs_lfs.py @@ -1,10 +1,10 @@ # Test for VfsLittle using a RAM device try: - import os + import os, vfs - os.VfsLfs1 - os.VfsLfs2 + vfs.VfsLfs1 + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -47,44 +47,44 @@ def test(bdev, vfs_class): vfs_class.mkfs(bdev) # construction - vfs = vfs_class(bdev) + fs = vfs_class(bdev) # statvfs - print(vfs.statvfs("/")) + print(fs.statvfs("/")) # open, write close - f = vfs.open("test", "w") + f = fs.open("test", "w") f.write("littlefs") f.close() # statvfs after creating a file - print(vfs.statvfs("/")) + print(fs.statvfs("/")) # ilistdir - print(list(vfs.ilistdir())) - print(list(vfs.ilistdir("/"))) - print(list(vfs.ilistdir(b"/"))) + print(list(fs.ilistdir())) + print(list(fs.ilistdir("/"))) + print(list(fs.ilistdir(b"/"))) # mkdir, rmdir - vfs.mkdir("testdir") - print(list(vfs.ilistdir())) - print(sorted(list(vfs.ilistdir("testdir")))) - vfs.rmdir("testdir") - print(list(vfs.ilistdir())) - vfs.mkdir("testdir") + fs.mkdir("testdir") + print(list(fs.ilistdir())) + print(sorted(list(fs.ilistdir("testdir")))) + fs.rmdir("testdir") + print(list(fs.ilistdir())) + fs.mkdir("testdir") # stat a file - print_stat(vfs.stat("test")) + print_stat(fs.stat("test")) # stat a dir (size seems to vary on LFS2 so don't print that) - print_stat(vfs.stat("testdir"), False) + print_stat(fs.stat("testdir"), False) # read - with vfs.open("test", "r") as f: + with fs.open("test", "r") as f: print(f.read()) # create large file - with vfs.open("testbig", "w") as f: + with fs.open("testbig", "w") as f: data = "large012" * 32 * 16 print("data length:", len(data)) for i in range(4): @@ -92,63 +92,63 @@ def test(bdev, vfs_class): f.write(data) # stat after creating large file - print(vfs.statvfs("/")) + print(fs.statvfs("/")) # rename - vfs.rename("testbig", "testbig2") - print(sorted(list(vfs.ilistdir()))) - vfs.chdir("testdir") - vfs.rename("/testbig2", "testbig2") - print(sorted(list(vfs.ilistdir()))) - vfs.rename("testbig2", "/testbig2") - vfs.chdir("/") - print(sorted(list(vfs.ilistdir()))) + fs.rename("testbig", "testbig2") + print(sorted(list(fs.ilistdir()))) + fs.chdir("testdir") + fs.rename("/testbig2", "testbig2") + print(sorted(list(fs.ilistdir()))) + fs.rename("testbig2", "/testbig2") + fs.chdir("/") + print(sorted(list(fs.ilistdir()))) # remove - vfs.remove("testbig2") - print(sorted(list(vfs.ilistdir()))) + fs.remove("testbig2") + print(sorted(list(fs.ilistdir()))) # getcwd, chdir - vfs.mkdir("/testdir2") - vfs.mkdir("/testdir/subdir") - print(vfs.getcwd()) - vfs.chdir("/testdir") - print(vfs.getcwd()) + fs.mkdir("/testdir2") + fs.mkdir("/testdir/subdir") + print(fs.getcwd()) + fs.chdir("/testdir") + print(fs.getcwd()) # create file in directory to make sure paths are relative - vfs.open("test2", "w").close() - print_stat(vfs.stat("test2")) - print_stat(vfs.stat("/testdir/test2")) - vfs.remove("test2") + fs.open("test2", "w").close() + print_stat(fs.stat("test2")) + print_stat(fs.stat("/testdir/test2")) + fs.remove("test2") # chdir back to root and remove testdir - vfs.chdir("/") - print(vfs.getcwd()) - vfs.chdir("testdir") - print(vfs.getcwd()) - vfs.chdir("..") - print(vfs.getcwd()) - vfs.chdir("testdir/subdir") - print(vfs.getcwd()) - vfs.chdir("../..") - print(vfs.getcwd()) - vfs.chdir("/./testdir2") - print(vfs.getcwd()) - vfs.chdir("../testdir") - print(vfs.getcwd()) - vfs.chdir("../..") - print(vfs.getcwd()) - vfs.chdir(".//testdir") - print(vfs.getcwd()) - vfs.chdir("subdir/./") - print(vfs.getcwd()) - vfs.chdir("/") - print(vfs.getcwd()) - vfs.rmdir("testdir/subdir") - vfs.rmdir("testdir") - vfs.rmdir("testdir2") + fs.chdir("/") + print(fs.getcwd()) + fs.chdir("testdir") + print(fs.getcwd()) + fs.chdir("..") + print(fs.getcwd()) + fs.chdir("testdir/subdir") + print(fs.getcwd()) + fs.chdir("../..") + print(fs.getcwd()) + fs.chdir("/./testdir2") + print(fs.getcwd()) + fs.chdir("../testdir") + print(fs.getcwd()) + fs.chdir("../..") + print(fs.getcwd()) + fs.chdir(".//testdir") + print(fs.getcwd()) + fs.chdir("subdir/./") + print(fs.getcwd()) + fs.chdir("/") + print(fs.getcwd()) + fs.rmdir("testdir/subdir") + fs.rmdir("testdir") + fs.rmdir("testdir2") bdev = RAMBlockDevice(30) -test(bdev, os.VfsLfs1) -test(bdev, os.VfsLfs2) +test(bdev, vfs.VfsLfs1) +test(bdev, vfs.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_corrupt.py b/tests/extmod/vfs_lfs_corrupt.py index c49dcad92b441..0365c0c23f3c8 100644 --- a/tests/extmod/vfs_lfs_corrupt.py +++ b/tests/extmod/vfs_lfs_corrupt.py @@ -1,10 +1,10 @@ # Test for VfsLittle using a RAM device, testing error handling from corrupt block device try: - import os + import vfs - os.VfsLfs1 - os.VfsLfs2 + vfs.VfsLfs1 + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -47,28 +47,28 @@ def corrupt(bdev, block): def create_vfs(bdev, vfs_class): bdev.ret = 0 vfs_class.mkfs(bdev) - vfs = vfs_class(bdev) - with vfs.open("f", "w") as f: + fs = vfs_class(bdev) + with fs.open("f", "w") as f: for i in range(100): f.write("test") - return vfs + return fs def test(bdev, vfs_class): print("test", vfs_class) # statvfs - vfs = create_vfs(bdev, vfs_class) + fs = create_vfs(bdev, vfs_class) corrupt(bdev, 0) corrupt(bdev, 1) try: - print(vfs.statvfs("")) + print(fs.statvfs("")) except OSError: print("statvfs OSError") # error during read - vfs = create_vfs(bdev, vfs_class) - f = vfs.open("f", "r") + fs = create_vfs(bdev, vfs_class) + f = fs.open("f", "r") bdev.ret = -5 # EIO try: f.read(10) @@ -76,8 +76,8 @@ def test(bdev, vfs_class): print("read OSError") # error during write - vfs = create_vfs(bdev, vfs_class) - f = vfs.open("f", "a") + fs = create_vfs(bdev, vfs_class) + f = fs.open("f", "a") bdev.ret = -5 # EIO try: f.write("test") @@ -85,8 +85,8 @@ def test(bdev, vfs_class): print("write OSError") # error during close - vfs = create_vfs(bdev, vfs_class) - f = vfs.open("f", "w") + fs = create_vfs(bdev, vfs_class) + f = fs.open("f", "w") f.write("test") bdev.ret = -5 # EIO try: @@ -95,8 +95,8 @@ def test(bdev, vfs_class): print("close OSError") # error during flush - vfs = create_vfs(bdev, vfs_class) - f = vfs.open("f", "w") + fs = create_vfs(bdev, vfs_class) + f = fs.open("f", "w") f.write("test") bdev.ret = -5 # EIO try: @@ -108,5 +108,5 @@ def test(bdev, vfs_class): bdev = RAMBlockDevice(30) -test(bdev, os.VfsLfs1) -test(bdev, os.VfsLfs2) +test(bdev, vfs.VfsLfs1) +test(bdev, vfs.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_error.py b/tests/extmod/vfs_lfs_error.py index 32b76b2821258..2ac7629bfa8fc 100644 --- a/tests/extmod/vfs_lfs_error.py +++ b/tests/extmod/vfs_lfs_error.py @@ -1,10 +1,10 @@ # Test for VfsLittle using a RAM device, testing error handling try: - import os + import vfs - os.VfsLfs1 - os.VfsLfs2 + vfs.VfsLfs1 + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -52,63 +52,63 @@ def test(bdev, vfs_class): # set up for following tests vfs_class.mkfs(bdev) - vfs = vfs_class(bdev) - with vfs.open("testfile", "w") as f: + fs = vfs_class(bdev) + with fs.open("testfile", "w") as f: f.write("test") - vfs.mkdir("testdir") + fs.mkdir("testdir") # ilistdir try: - vfs.ilistdir("noexist") + fs.ilistdir("noexist") except OSError: print("ilistdir OSError") # remove try: - vfs.remove("noexist") + fs.remove("noexist") except OSError: print("remove OSError") # rmdir try: - vfs.rmdir("noexist") + fs.rmdir("noexist") except OSError: print("rmdir OSError") # rename try: - vfs.rename("noexist", "somethingelse") + fs.rename("noexist", "somethingelse") except OSError: print("rename OSError") # mkdir try: - vfs.mkdir("testdir") + fs.mkdir("testdir") except OSError: print("mkdir OSError") # chdir to nonexistent try: - vfs.chdir("noexist") + fs.chdir("noexist") except OSError: print("chdir OSError") - print(vfs.getcwd()) # check still at root + print(fs.getcwd()) # check still at root # chdir to file try: - vfs.chdir("testfile") + fs.chdir("testfile") except OSError: print("chdir OSError") - print(vfs.getcwd()) # check still at root + print(fs.getcwd()) # check still at root # stat try: - vfs.stat("noexist") + fs.stat("noexist") except OSError: print("stat OSError") # error during seek - with vfs.open("testfile", "r") as f: + with fs.open("testfile", "r") as f: f.seek(1 << 30) # SEEK_SET try: f.seek(1 << 30, 1) # SEEK_CUR @@ -117,5 +117,5 @@ def test(bdev, vfs_class): bdev = RAMBlockDevice(30) -test(bdev, os.VfsLfs1) -test(bdev, os.VfsLfs2) +test(bdev, vfs.VfsLfs1) +test(bdev, vfs.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_file.py b/tests/extmod/vfs_lfs_file.py index b745bb8112def..2620d9f729620 100644 --- a/tests/extmod/vfs_lfs_file.py +++ b/tests/extmod/vfs_lfs_file.py @@ -1,10 +1,10 @@ # Test for VfsLittle using a RAM device, file IO try: - import os + import vfs - os.VfsLfs1 - os.VfsLfs2 + vfs.VfsLfs1 + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -42,10 +42,10 @@ def test(bdev, vfs_class): vfs_class.mkfs(bdev) # construction - vfs = vfs_class(bdev) + fs = vfs_class(bdev) # create text, print, write, close - f = vfs.open("test.txt", "wt") + f = fs.open("test.txt", "wt") print(f) f.write("littlefs") f.close() @@ -54,7 +54,7 @@ def test(bdev, vfs_class): f.close() # create binary, print, write, flush, close - f = vfs.open("test.bin", "wb") + f = fs.open("test.bin", "wb") print(f) # CIRCUITPY-CHANGE f.write(b"littlefs") @@ -62,43 +62,43 @@ def test(bdev, vfs_class): f.close() # create for append - f = vfs.open("test.bin", "ab") + f = fs.open("test.bin", "ab") # CIRCUITPY-CHANGE f.write(b"more") f.close() # create exclusive - f = vfs.open("test2.bin", "xb") + f = fs.open("test2.bin", "xb") f.close() # create exclusive with error try: - vfs.open("test2.bin", "x") + fs.open("test2.bin", "x") except OSError: print("open OSError") # read default - with vfs.open("test.txt", "") as f: + with fs.open("test.txt", "") as f: print(f.read()) # read text - with vfs.open("test.txt", "rt") as f: + with fs.open("test.txt", "rt") as f: print(f.read()) # read binary - with vfs.open("test.bin", "rb") as f: + with fs.open("test.bin", "rb") as f: print(f.read()) # create read and write - with vfs.open("test.bin", "r+b") as f: + with fs.open("test.bin", "r+b") as f: print(f.read(8)) # CIRCUITPY-CHANGE f.write(b"MORE") - with vfs.open("test.bin", "rb") as f: + with fs.open("test.bin", "rb") as f: print(f.read()) # seek and tell - f = vfs.open("test.txt", "r") + f = fs.open("test.txt", "r") print(f.tell()) f.seek(3, 0) print(f.tell()) @@ -106,13 +106,13 @@ def test(bdev, vfs_class): # open nonexistent try: - vfs.open("noexist", "r") + fs.open("noexist", "r") except OSError: print("open OSError") # open multiple files at the same time - f1 = vfs.open("test.txt", "") - f2 = vfs.open("test.bin", "b") + f1 = fs.open("test.txt", "") + f2 = fs.open("test.bin", "b") print(f1.read()) print(f2.read()) f1.close() @@ -120,5 +120,5 @@ def test(bdev, vfs_class): bdev = RAMBlockDevice(30) -test(bdev, os.VfsLfs1) -test(bdev, os.VfsLfs2) +test(bdev, vfs.VfsLfs1) +test(bdev, vfs.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_ilistdir_del.py b/tests/extmod/vfs_lfs_ilistdir_del.py index ff66717147868..7b59bc412d983 100644 --- a/tests/extmod/vfs_lfs_ilistdir_del.py +++ b/tests/extmod/vfs_lfs_ilistdir_del.py @@ -2,9 +2,9 @@ import gc try: - import os + import vfs - os.VfsLfs2 + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -37,29 +37,29 @@ def ioctl(self, op, arg): def test(bdev, vfs_class): vfs_class.mkfs(bdev) - vfs = vfs_class(bdev) - vfs.mkdir("/test_d1") - vfs.mkdir("/test_d2") - vfs.mkdir("/test_d3") + fs = vfs_class(bdev) + fs.mkdir("/test_d1") + fs.mkdir("/test_d2") + fs.mkdir("/test_d3") for i in range(10): print(i) # We want to partially iterate the ilistdir iterator to leave it in an # open state, which will then test the finaliser when it's garbage collected. - idir = vfs.ilistdir("/") + idir = fs.ilistdir("/") print(any(idir)) # Alternate way of partially iterating the ilistdir object, modifying the # filesystem while it's open. - for dname, *_ in vfs.ilistdir("/"): - vfs.rmdir(dname) + for dname, *_ in fs.ilistdir("/"): + fs.rmdir(dname) break - vfs.mkdir(dname) + fs.mkdir(dname) - # Also create a fully drained iterator and ensure trying to re-use it + # Also create a fully drained iterator and ensure trying to reuse it # throws the correct exception. - idir_emptied = vfs.ilistdir("/") + idir_emptied = fs.ilistdir("/") l = list(idir_emptied) print(len(l)) try: @@ -68,8 +68,8 @@ def test(bdev, vfs_class): pass gc.collect() - vfs.open("/test", "w").close() + fs.open("/test", "w").close() bdev = RAMBlockDevice(30) -test(bdev, os.VfsLfs2) +test(bdev, vfs.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_mount.py b/tests/extmod/vfs_lfs_mount.py index 4ebd9ac6233f8..4887ddcec0085 100644 --- a/tests/extmod/vfs_lfs_mount.py +++ b/tests/extmod/vfs_lfs_mount.py @@ -1,10 +1,10 @@ # Test for VfsLittle using a RAM device, with mount/umount try: - import os + import os, vfs - os.VfsLfs1 - os.VfsLfs2 + vfs.VfsLfs1 + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -42,7 +42,7 @@ def test(vfs_class): # mount bdev unformatted try: - os.mount(bdev, "/lfs") + vfs.mount(bdev, "/lfs") except Exception as er: print(repr(er)) @@ -50,10 +50,10 @@ def test(vfs_class): vfs_class.mkfs(bdev) # construction - vfs = vfs_class(bdev) + fs = vfs_class(bdev) # mount - os.mount(vfs, "/lfs") + vfs.mount(fs, "/lfs") # import with open("/lfs/lfsmod.py", "w") as f: @@ -73,11 +73,11 @@ def test(vfs_class): import lfsmod2 # umount - os.umount("/lfs") + vfs.umount("/lfs") # mount read-only - vfs = vfs_class(bdev) - os.mount(vfs, "/lfs", readonly=True) + fs = vfs_class(bdev) + vfs.mount(fs, "/lfs", readonly=True) # test reading works with open("/lfs/subdir/lfsmod2.py") as f: @@ -90,13 +90,13 @@ def test(vfs_class): print(repr(er)) # umount - os.umount("/lfs") + vfs.umount("/lfs") # mount bdev again - os.mount(bdev, "/lfs") + vfs.mount(bdev, "/lfs") # umount - os.umount("/lfs") + vfs.umount("/lfs") # clear imported modules sys.modules.clear() @@ -110,5 +110,5 @@ def test(vfs_class): sys.path.append("") # run tests -test(os.VfsLfs1) -test(os.VfsLfs2) +test(vfs.VfsLfs1) +test(vfs.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_mtime.py b/tests/extmod/vfs_lfs_mtime.py index ade02fa144987..3d163dc2687f0 100644 --- a/tests/extmod/vfs_lfs_mtime.py +++ b/tests/extmod/vfs_lfs_mtime.py @@ -1,11 +1,11 @@ # Test for VfsLfs using a RAM device, mtime feature try: - import time, os + import time, vfs time.time time.sleep - os.VfsLfs2 + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -44,21 +44,21 @@ def test(bdev, vfs_class): # construction print("mtime=True") - vfs = vfs_class(bdev, mtime=True) + fs = vfs_class(bdev, mtime=True) # Create an empty file, should have a timestamp. current_time = int(time.time()) - vfs.open("test1", "wt").close() + fs.open("test1", "wt").close() # Wait 1 second so mtime will increase by at least 1. time.sleep(1) # Create another empty file, should have a timestamp. - vfs.open("test2", "wt").close() + fs.open("test2", "wt").close() # Stat the files and check mtime is non-zero. - stat1 = vfs.stat("test1") - stat2 = vfs.stat("test2") + stat1 = fs.stat("test1") + stat2 = fs.stat("test2") print(stat1[8] != 0, stat2[8] != 0) # Check that test1 has mtime which matches time.time() at point of creation. @@ -71,34 +71,34 @@ def test(bdev, vfs_class): time.sleep(1) # Open test1 for reading and ensure mtime did not change. - vfs.open("test1", "rt").close() - print(vfs.stat("test1") == stat1) + fs.open("test1", "rt").close() + print(fs.stat("test1") == stat1) # Open test1 for writing and ensure mtime increased from the previous value. - vfs.open("test1", "wt").close() + fs.open("test1", "wt").close() stat1_old = stat1 - stat1 = vfs.stat("test1") + stat1 = fs.stat("test1") print(stat1_old[8] < stat1[8]) # Unmount. - vfs.umount() + fs.umount() # Check that remounting with mtime=False can read the timestamps. print("mtime=False") - vfs = vfs_class(bdev, mtime=False) - print(vfs.stat("test1") == stat1) - print(vfs.stat("test2") == stat2) - f = vfs.open("test1", "wt") + fs = vfs_class(bdev, mtime=False) + print(fs.stat("test1") == stat1) + print(fs.stat("test2") == stat2) + f = fs.open("test1", "wt") f.close() - print(vfs.stat("test1") == stat1) - vfs.umount() + print(fs.stat("test1") == stat1) + fs.umount() # Check that remounting with mtime=True still has the timestamps. print("mtime=True") - vfs = vfs_class(bdev, mtime=True) - print(vfs.stat("test1") == stat1) - print(vfs.stat("test2") == stat2) - vfs.umount() + fs = vfs_class(bdev, mtime=True) + print(fs.stat("test1") == stat1) + print(fs.stat("test2") == stat2) + fs.umount() try: @@ -107,4 +107,4 @@ def test(bdev, vfs_class): print("SKIP") raise SystemExit -test(bdev, os.VfsLfs2) +test(bdev, vfs.VfsLfs2) diff --git a/tests/extmod/vfs_lfs_superblock.py b/tests/extmod/vfs_lfs_superblock.py index b8a8ec60b967a..74b6004e991c0 100644 --- a/tests/extmod/vfs_lfs_superblock.py +++ b/tests/extmod/vfs_lfs_superblock.py @@ -1,9 +1,9 @@ # Test for VfsLfs using a RAM device, when the first superblock does not exist try: - import os + import os, vfs - os.VfsLfs2 + vfs.VfsLfs2 except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -36,12 +36,12 @@ def ioctl(self, op, arg): bdev = RAMBlockDevice(64, lfs2_data) # Create the VFS explicitly, no auto-detection is needed for this. -vfs = os.VfsLfs2(bdev) -print(list(vfs.ilistdir())) +fs = vfs.VfsLfs2(bdev) +print(list(fs.ilistdir())) # Mount the block device directly; this relies on auto-detection. -os.mount(bdev, "/userfs") +vfs.mount(bdev, "/userfs") print(os.listdir("/userfs")) # Clean up. -os.umount("/userfs") +vfs.umount("/userfs") diff --git a/tests/extmod/vfs_posix.py b/tests/extmod/vfs_posix.py index bc4c7c2014b6c..d060c0b9c84f3 100644 --- a/tests/extmod/vfs_posix.py +++ b/tests/extmod/vfs_posix.py @@ -1,10 +1,9 @@ # Test for VfsPosix try: - import gc - import os + import gc, os, vfs - os.VfsPosix + vfs.VfsPosix except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -13,8 +12,6 @@ # Skip the test if it does exist. temp_dir = "micropy_test_dir" try: - import os - os.stat(temp_dir) print("SKIP") raise SystemExit @@ -87,35 +84,35 @@ def write_files_without_closing(): print(os.listdir(temp_dir)) # construct new VfsPosix with path argument -vfs = os.VfsPosix(temp_dir) -# when VfsPosix is used the intended way via os.mount(), it can only be called +fs = vfs.VfsPosix(temp_dir) +# when VfsPosix is used the intended way via vfs.mount(), it can only be called # with relative paths when the CWD is inside or at its root, so simulate that os.chdir(temp_dir) -print(list(i[0] for i in vfs.ilistdir("."))) +print(list(i[0] for i in fs.ilistdir("."))) # stat, statvfs (statvfs may not exist) -print(type(vfs.stat("."))) -if hasattr(vfs, "statvfs"): - assert type(vfs.statvfs(".")) is tuple +print(type(fs.stat("."))) +if hasattr(fs, "statvfs"): + assert type(fs.statvfs(".")) is tuple # check types of ilistdir with str/bytes arguments -print(type(list(vfs.ilistdir("."))[0][0])) -print(type(list(vfs.ilistdir(b"."))[0][0])) +print(type(list(fs.ilistdir("."))[0][0])) +print(type(list(fs.ilistdir(b"."))[0][0])) # chdir should not affect absolute paths (regression test) -vfs.mkdir("/subdir") -vfs.mkdir("/subdir/micropy_test_dir") -with vfs.open("/subdir/micropy_test_dir/test2", "w") as f: +fs.mkdir("/subdir") +fs.mkdir("/subdir/micropy_test_dir") +with fs.open("/subdir/micropy_test_dir/test2", "w") as f: f.write("wrong") -vfs.chdir("/subdir") -with vfs.open("/test2", "r") as f: +fs.chdir("/subdir") +with fs.open("/test2", "r") as f: print(f.read()) os.chdir(curdir) -vfs.remove("/subdir/micropy_test_dir/test2") -vfs.rmdir("/subdir/micropy_test_dir") -vfs.rmdir("/subdir") +fs.remove("/subdir/micropy_test_dir/test2") +fs.rmdir("/subdir/micropy_test_dir") +fs.rmdir("/subdir") -# done with vfs, restore CWD +# done with fs, restore CWD os.chdir(curdir) # remove diff --git a/tests/extmod/vfs_posix_enoent.py b/tests/extmod/vfs_posix_enoent.py index e6010d79d58f0..7b00388da539a 100644 --- a/tests/extmod/vfs_posix_enoent.py +++ b/tests/extmod/vfs_posix_enoent.py @@ -1,10 +1,9 @@ # Test for VfsPosix error conditions try: - import os - import sys + import os, sys, vfs - os.VfsPosix + vfs.VfsPosix except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -36,7 +35,7 @@ print("getcwd():", repr(e)) try: - print("VfsPosix():", os.VfsPosix("something")) + print("VfsPosix():", vfs.VfsPosix("something")) except OSError as e: # expecting ENOENT = 2 print("VfsPosix():", repr(e)) diff --git a/tests/extmod/vfs_posix_ilistdir_del.py b/tests/extmod/vfs_posix_ilistdir_del.py index 8c8e6978b6540..78d7c854c543c 100644 --- a/tests/extmod/vfs_posix_ilistdir_del.py +++ b/tests/extmod/vfs_posix_ilistdir_del.py @@ -2,9 +2,9 @@ import gc try: - import os + import os, vfs - os.VfsPosix + vfs.VfsPosix except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -12,34 +12,34 @@ def test(testdir): curdir = os.getcwd() - vfs = os.VfsPosix(testdir) - # When VfsPosix is used the intended way via os.mount(), it can only be called + fs = vfs.VfsPosix(testdir) + # When VfsPosix is used the intended way via vfs.mount(), it can only be called # with relative paths when the CWD is inside or at its root, so simulate that. # (Although perhaps calling with a relative path was an oversight in this case - # and the respective line below was meant to read `vfs.rmdir("/" + dname)`.) + # and the respective line below was meant to read `fs.rmdir("/" + dname)`.) os.chdir(testdir) - vfs.mkdir("/test_d1") - vfs.mkdir("/test_d2") - vfs.mkdir("/test_d3") + fs.mkdir("/test_d1") + fs.mkdir("/test_d2") + fs.mkdir("/test_d3") for i in range(10): print(i) # We want to partially iterate the ilistdir iterator to leave it in an # open state, which will then test the finaliser when it's garbage collected. - idir = vfs.ilistdir("/") + idir = fs.ilistdir("/") print(any(idir)) # Alternate way of partially iterating the ilistdir object, modifying the # filesystem while it's open. - for dname, *_ in vfs.ilistdir("/"): - vfs.rmdir(dname) + for dname, *_ in fs.ilistdir("/"): + fs.rmdir(dname) break - vfs.mkdir(dname) + fs.mkdir(dname) - # Also create a fully drained iterator and ensure trying to re-use it + # Also create a fully drained iterator and ensure trying to reuse it # throws the correct exception. - idir_emptied = vfs.ilistdir("/") + idir_emptied = fs.ilistdir("/") l = list(idir_emptied) print(len(l)) try: @@ -51,10 +51,10 @@ def test(testdir): # Create and delete a file, try to flush out any filesystem # corruption that may be caused over the loops. - vfs.open("/test", "w").close() - vfs.remove("/test") + fs.open("/test", "w").close() + fs.remove("/test") - # Done with vfs, restore CWD. + # Done with fs, restore CWD. os.chdir(curdir) diff --git a/tests/extmod/vfs_posix_ilistdir_filter.py b/tests/extmod/vfs_posix_ilistdir_filter.py index 54012746057a8..6df9542045935 100644 --- a/tests/extmod/vfs_posix_ilistdir_filter.py +++ b/tests/extmod/vfs_posix_ilistdir_filter.py @@ -1,9 +1,9 @@ # Test ilistdir filter of . and .. for VfsPosix. try: - import os + import os, vfs - os.VfsPosix + vfs.VfsPosix except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -11,24 +11,24 @@ def test(testdir): curdir = os.getcwd() - vfs = os.VfsPosix(testdir) - # When VfsPosix is used the intended way via os.mount(), it can only be called + fs = vfs.VfsPosix(testdir) + # When VfsPosix is used the intended way via vfs.mount(), it can only be called # with relative paths when the CWD is inside or at its root, so simulate that. os.chdir(testdir) dirs = [".a", "..a", "...a", "a.b", "a..b"] for dir in dirs: - vfs.mkdir(dir) + fs.mkdir(dir) dirs = [] - for entry in vfs.ilistdir("/"): + for entry in fs.ilistdir("/"): dirs.append(entry[0]) dirs.sort() print(dirs) - # Done with vfs, restore CWD. + # Done with fs, restore CWD. os.chdir(curdir) diff --git a/tests/extmod/vfs_posix_paths.py b/tests/extmod/vfs_posix_paths.py index 5806a34521a23..b4fedc6716f01 100644 --- a/tests/extmod/vfs_posix_paths.py +++ b/tests/extmod/vfs_posix_paths.py @@ -1,9 +1,9 @@ # Test for VfsPosix with relative paths try: - import os + import os, vfs - os.VfsPosix + vfs.VfsPosix except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -12,8 +12,6 @@ # Skip the test if it does exist. temp_dir = "vfs_posix_paths_test_dir" try: - import os - os.stat(temp_dir) print("SKIP") raise SystemExit @@ -25,26 +23,26 @@ # construct new VfsPosix with absolute path argument temp_dir_abs = os.getcwd() + os.sep + temp_dir -vfs = os.VfsPosix(temp_dir_abs) -# when VfsPosix is used the intended way via os.mount(), it can only be called +fs = vfs.VfsPosix(temp_dir_abs) +# when VfsPosix is used the intended way via vfs.mount(), it can only be called # with relative paths when the CWD is inside or at its root, so simulate that os.chdir(temp_dir_abs) -vfs.mkdir("subdir") -vfs.mkdir("subdir/one") -print('listdir("/"):', sorted(i[0] for i in vfs.ilistdir("/"))) -print('listdir("."):', sorted(i[0] for i in vfs.ilistdir("."))) -print('getcwd() in {"", "/"}:', vfs.getcwd() in {"", "/"}) -print('chdir("subdir"):', vfs.chdir("subdir")) -print("getcwd():", vfs.getcwd()) -print('mkdir("two"):', vfs.mkdir("two")) -f = vfs.open("file.py", "w") +fs.mkdir("subdir") +fs.mkdir("subdir/one") +print('listdir("/"):', sorted(i[0] for i in fs.ilistdir("/"))) +print('listdir("."):', sorted(i[0] for i in fs.ilistdir("."))) +print('getcwd() in {"", "/"}:', fs.getcwd() in {"", "/"}) +print('chdir("subdir"):', fs.chdir("subdir")) +print("getcwd():", fs.getcwd()) +print('mkdir("two"):', fs.mkdir("two")) +f = fs.open("file.py", "w") f.write("print('hello')") f.close() -print('listdir("/"):', sorted(i[0] for i in vfs.ilistdir("/"))) -print('listdir("/subdir"):', sorted(i[0] for i in vfs.ilistdir("/subdir"))) -print('listdir("."):', sorted(i[0] for i in vfs.ilistdir("."))) +print('listdir("/"):', sorted(i[0] for i in fs.ilistdir("/"))) +print('listdir("/subdir"):', sorted(i[0] for i in fs.ilistdir("/subdir"))) +print('listdir("."):', sorted(i[0] for i in fs.ilistdir("."))) try: - f = vfs.open("/subdir/file.py", "r") + f = fs.open("/subdir/file.py", "r") print(f.read()) f.close() except Exception as e: @@ -59,17 +57,17 @@ except Exception as e: print(e) del sys.path[0] -vfs.remove("file.py") -vfs.rmdir("two") -vfs.rmdir("/subdir/one") -vfs.chdir("/") -vfs.rmdir("/subdir") +fs.remove("file.py") +fs.rmdir("two") +fs.rmdir("/subdir/one") +fs.chdir("/") +fs.rmdir("/subdir") -# done with vfs, restore CWD +# done with fs, restore CWD os.chdir(curdir) # some integration tests with a mounted VFS -os.mount(os.VfsPosix(temp_dir_abs), "/mnt") +vfs.mount(vfs.VfsPosix(temp_dir_abs), "/mnt") os.mkdir("/mnt/dir") print('chdir("/mnt/dir"):', os.chdir("/mnt/dir")) print("getcwd():", os.getcwd()) @@ -82,7 +80,7 @@ print('chdir(".."):', os.chdir("..")) print("getcwd():", os.getcwd()) os.rmdir("/mnt/dir") -os.umount("/mnt") +vfs.umount("/mnt") # restore CWD os.chdir(curdir) diff --git a/tests/extmod/vfs_userfs.py b/tests/extmod/vfs_userfs.py index 5c487315eb5eb..a7b87ec0b0d0c 100644 --- a/tests/extmod/vfs_userfs.py +++ b/tests/extmod/vfs_userfs.py @@ -4,12 +4,9 @@ import sys try: - import io + import io, vfs io.IOBase - import os - - os.mount except (ImportError, AttributeError): print("SKIP") raise SystemExit @@ -79,7 +76,7 @@ def open(self, path, mode): "/usermod5.py": b"print('in usermod5')", "/usermod6.py": b"print('in usermod6')", } -os.mount(UserFS(user_files), "/userfs") +vfs.mount(UserFS(user_files), "/userfs") # open and read a file f = open("/userfs/data.txt") @@ -110,5 +107,5 @@ def open(self, path, mode): import usermod6 # unmount and undo path addition -os.umount("/userfs") +vfs.umount("/userfs") sys.path.pop() diff --git a/tests/float/float2int_intbig.py b/tests/float/float2int_intbig.py index 4167a2721ca19..3318df857655b 100644 --- a/tests/float/float2int_intbig.py +++ b/tests/float/float2int_intbig.py @@ -47,6 +47,7 @@ # TODO why does 10**12 fail this test for single precision float? testpass = True +# CIRCUITPY-CHANGE: correct negation p10_rng = 9 if (ll_type == 0 and not is_64bit) else 11 for i in range(0, p10_rng): digcnt = len(str(int(10.0**i))) - 1 diff --git a/tests/float/float_struct.py b/tests/float/float_struct.py index 47fe405018038..6e282a6afe3ee 100644 --- a/tests/float/float_struct.py +++ b/tests/float/float_struct.py @@ -8,7 +8,7 @@ i = 1.0 + 1 / 2 # TODO: it looks like '=' format modifier is not yet supported # for fmt in ('f', 'd', '>f', '>d', 'f", ">d", "e", ">f", ">d", " int: return []") +# can't do unary op of incompatible type +test("@micropython.viper\ndef f(x:ptr): -x") + # can't do binary op between incompatible types test("@micropython.viper\ndef f(): 1 + []") test("@micropython.viper\ndef f(x:int, y:uint): x < y") @@ -69,9 +72,7 @@ def f(): test("@micropython.viper\ndef f(): raise 1") # unary ops not implemented -test("@micropython.viper\ndef f(x:int): +x") -test("@micropython.viper\ndef f(x:int): -x") -test("@micropython.viper\ndef f(x:int): ~x") +test("@micropython.viper\ndef f(x:int): not x") # binary op not implemented test("@micropython.viper\ndef f(x:uint, y:uint): res = x // y") diff --git a/tests/micropython/viper_error.py.exp b/tests/micropython/viper_error.py.exp index 31c85b1d872af..51cbd6c7097cd 100644 --- a/tests/micropython/viper_error.py.exp +++ b/tests/micropython/viper_error.py.exp @@ -5,6 +5,7 @@ ViperTypeError("local 'x' used before type known",) ViperTypeError("local 'x' has type 'int' but source is 'object'",) ViperTypeError("can't implicitly convert 'ptr' to 'bool'",) ViperTypeError("return expected 'int' but got 'object'",) +ViperTypeError("can't do unary op of 'ptr'",) ViperTypeError("can't do binary op between 'int' and 'object'",) ViperTypeError('comparison of int and uint',) ViperTypeError("can't load from 'int'",) @@ -15,9 +16,7 @@ ViperTypeError("can't store to 'int'",) ViperTypeError("can't store 'None'",) ViperTypeError("can't store 'None'",) ViperTypeError('must raise an object',) -ViperTypeError('unary op __pos__ not implemented',) -ViperTypeError('unary op __neg__ not implemented',) -ViperTypeError('unary op __invert__ not implemented',) +ViperTypeError("'not' not implemented",) ViperTypeError('div/mod not implemented for uint',) ViperTypeError('div/mod not implemented for uint',) ViperTypeError('binary op not implemented',) diff --git a/tests/micropython/viper_unop.py b/tests/micropython/viper_unop.py new file mode 100644 index 0000000000000..61cbd5125f167 --- /dev/null +++ b/tests/micropython/viper_unop.py @@ -0,0 +1,31 @@ +# test unary operators + + +@micropython.viper +def pos(x: int) -> int: + return +x + + +print(pos(0)) +print(pos(1)) +print(pos(-2)) + + +@micropython.viper +def neg(x: int) -> int: + return -x + + +print(neg(0)) +print(neg(1)) +print(neg(-2)) + + +@micropython.viper +def inv(x: int) -> int: + return ~x + + +print(inv(0)) +print(inv(1)) +print(inv(-2)) diff --git a/tests/micropython/viper_unop.py.exp b/tests/micropython/viper_unop.py.exp new file mode 100644 index 0000000000000..6d93312caa136 --- /dev/null +++ b/tests/micropython/viper_unop.py.exp @@ -0,0 +1,9 @@ +0 +1 +-2 +0 +-1 +2 +-1 +-2 +1 diff --git a/tests/perf_bench/core_import_mpy_multi.py b/tests/perf_bench/core_import_mpy_multi.py index 364c325042843..33437f9da801e 100644 --- a/tests/perf_bench/core_import_mpy_multi.py +++ b/tests/perf_bench/core_import_mpy_multi.py @@ -1,8 +1,8 @@ # Test performance of importing an .mpy file many times. -import sys, io, os +import sys, io, vfs -if not (hasattr(io, "IOBase") and hasattr(os, "mount")): +if not hasattr(io, "IOBase"): print("SKIP") raise SystemExit @@ -57,7 +57,7 @@ def open(self, path, mode): def mount(): - os.mount(FS(), "/__remote") + vfs.mount(FS(), "/__remote") sys.path.insert(0, "/__remote") diff --git a/tests/perf_bench/core_import_mpy_single.py b/tests/perf_bench/core_import_mpy_single.py index 5757c3eaf1fdf..18454b8fd5eb2 100644 --- a/tests/perf_bench/core_import_mpy_single.py +++ b/tests/perf_bench/core_import_mpy_single.py @@ -2,9 +2,9 @@ # The first import of a module will intern strings that don't already exist, and # this test should be representative of what happens in a real application. -import io, os, sys +import sys, io, vfs -if not (hasattr(io, "IOBase") and hasattr(os, "mount")): +if not hasattr(io, "IOBase"): print("SKIP") raise SystemExit @@ -112,7 +112,7 @@ def open(self, path, mode): def mount(): - os.mount(FS(), "/__remote") + vfs.mount(FS(), "/__remote") sys.path.insert(0, "/__remote") diff --git a/tests/run-multitests.py b/tests/run-multitests.py index 5ae8b8ea48014..93a6d3844d235 100755 --- a/tests/run-multitests.py +++ b/tests/run-multitests.py @@ -27,13 +27,15 @@ if os.name == "nt": CPYTHON3 = os.getenv("MICROPY_CPYTHON3", "python3.exe") - MICROPYTHON = os.getenv( - "MICROPY_MICROPYTHON", test_dir + "/../ports/windows/build-standard/micropython.exe" + MICROPYTHON = os.path.abspath( + os.getenv( + "MICROPY_MICROPYTHON", test_dir + "/../ports/windows/build-standard/micropython.exe" + ) ) else: CPYTHON3 = os.getenv("MICROPY_CPYTHON3", "python3") - MICROPYTHON = os.getenv( - "MICROPY_MICROPYTHON", test_dir + "/../ports/unix/build-standard/micropython" + MICROPYTHON = os.path.abspath( + os.getenv("MICROPY_MICROPYTHON", test_dir + "/../ports/unix/build-standard/micropython") ) # For diff'ing test output @@ -155,6 +157,7 @@ def start_file(self, filename, prepend="", append=""): class PyInstanceSubProcess(PyInstance): def __init__(self, argv, env=None): self.argv = argv + self.cwd = None self.env = {n: v for n, v in (i.split("=") for i in env)} if env else None self.popen = None self.finished = True @@ -163,8 +166,9 @@ def __str__(self): return self.argv[0].rsplit("/")[-1] def prepare_script_from_file(self, filename, prepend, append): - # Make tests run in an isolated environment (i.e. `import io` would - # otherwise get the `tests/io` directory). + # Make tests run in the directory of the test file, and in an isolated environment + # (i.e. `import io` would otherwise get the `tests/io` directory). + self.cwd = os.path.dirname(filename) remove_cwd_from_sys_path = b"import sys\nsys.path.remove('')\n\n" return remove_cwd_from_sys_path + super().prepare_script_from_file( filename, prepend, append @@ -179,6 +183,7 @@ def run_script(self, script): stdout=subprocess.PIPE, stderr=subprocess.STDOUT, input=script, + cwd=self.cwd, env=self.env, ) output = p.stdout @@ -192,6 +197,7 @@ def start_script(self, script): stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + cwd=self.cwd, env=self.env, ) self.finished = False diff --git a/tests/run-natmodtests.py b/tests/run-natmodtests.py index 85ac92672a12a..24acd327c0340 100755 --- a/tests/run-natmodtests.py +++ b/tests/run-natmodtests.py @@ -23,12 +23,12 @@ "heapq": "heapq/heapq_$(ARCH).mpy", "random": "random/random_$(ARCH).mpy", "re": "re/re_$(ARCH).mpy", - "zlib": "zlib/zlib_$(ARCH).mpy", } # Code to allow a target MicroPython to import an .mpy from RAM injected_import_hook_code = """\ -import sys, os, io +# CIRCUITPY-CHANGE: no vfs, but still have os +import sys, io, os class __File(io.IOBase): def __init__(self): self.off = 0 @@ -50,6 +50,7 @@ def stat(self, path): raise OSError(-2) # ENOENT def open(self, path, mode): return __File() +# CIRCUITPY-CHANGE: no vfs, but still have os os.mount(__FS(), '/__remote') sys.path.insert(0, '/__remote') sys.modules['{}'] = __import__('__injected') @@ -95,8 +96,9 @@ def run_script(self, script): def run_tests(target_truth, target, args, stats): for test_file in args.files: # Find supported test + test_file_basename = os.path.basename(test_file) for k, v in TEST_MAPPINGS.items(): - if test_file.find(k) != -1: + if test_file_basename.startswith(k): test_module = k test_mpy = v.replace("$(ARCH)", args.arch) break diff --git a/tests/run-tests.py b/tests/run-tests.py index 52204cc9fe2ee..9f1c4564a6cf6 100755 --- a/tests/run-tests.py +++ b/tests/run-tests.py @@ -6,6 +6,7 @@ import platform import argparse import inspect +import json import re from glob import glob import multiprocessing @@ -47,6 +48,8 @@ def base_path(*p): # (not site packages which may clash with u-module names), and improve start up time. CPYTHON3_CMD = [CPYTHON3, "-BS"] +# File with the test results. +RESULTS_FILE = "_results.json" # For diff'ing test output DIFF = os.getenv("MICROPY_DIFF", "diff -u") @@ -56,7 +59,7 @@ def base_path(*p): # Code to allow a target MicroPython to import an .mpy from RAM injected_import_hook_code = """\ -import sys, os, io +import sys, os, io, vfs class __File(io.IOBase): def __init__(self): self.off = 0 @@ -80,7 +83,7 @@ def stat(self, path): raise OSError(-2) # ENOENT def open(self, path, mode): return __File() -os.mount(__FS(), '/__vfstest') +vfs.mount(__FS(), '/__vfstest') os.chdir('/__vfstest') __import__('__injected_test') """ @@ -173,8 +176,9 @@ def run_script_on_remote_target(pyb, args, test_file, is_special): return had_crash, output_mupy -def run_micropython(pyb, args, test_file, is_special=False): - special_tests = ( +special_tests = [ + base_path(file) + for file in ( "micropython/meminfo.py", "basics/bytes_compare3.py", "basics/builtin_help.py", @@ -183,12 +187,16 @@ def run_micropython(pyb, args, test_file, is_special=False): "circuitpython/traceback_test.py", # CIRCUITPY-CHANGE "circuitpython/traceback_test_chained.py", # CIRCUITPY-CHANGE ) +] + + +def run_micropython(pyb, args, test_file, test_file_abspath, is_special=False): had_crash = False if pyb is None: # run on PC if ( - test_file.startswith(("cmdline/", base_path("feature_check/"))) - or test_file in special_tests + test_file_abspath.startswith((base_path("cmdline/"), base_path("feature_check/"))) + or test_file_abspath in special_tests ): # special handling for tests of the unix cmdline program is_special = True @@ -204,7 +212,7 @@ def run_micropython(pyb, args, test_file, is_special=False): # run the test, possibly with redirected input try: - if "repl_" in test_file: + if os.path.basename(test_file).startswith("repl_"): # Need to use a PTY to test command line editing try: import pty @@ -282,7 +290,7 @@ def send_get(what): mpy_modname = os.path.splitext(os.path.basename(mpy_filename))[0] cmdlist.extend(["-m", mpy_modname]) else: - cmdlist.append(os.path.abspath(test_file)) + cmdlist.append(test_file_abspath) # run the actual test try: @@ -302,7 +310,9 @@ def send_get(what): else: # run via pyboard interface - had_crash, output_mupy = run_script_on_remote_target(pyb, args, test_file, is_special) + had_crash, output_mupy = pyb.run_script_on_remote_target( + args, test_file_abspath, is_special + ) # canonical form for all ports/platforms is to use \n for end-of-line output_mupy = output_mupy.replace(b"\r\n", b"\n") @@ -315,7 +325,7 @@ def send_get(what): if is_special and not had_crash and b"\nSKIP\n" in output_mupy: return b"SKIP\n" - if is_special or test_file in special_tests: + if is_special or test_file_abspath in special_tests: # convert parts of the output that are not stable across runs with open(test_file + ".exp", "rb") as f: lines_exp = [] @@ -359,11 +369,12 @@ def send_get(what): return output_mupy -def run_feature_check(pyb, args, base_path, test_file): +def run_feature_check(pyb, args, test_file): if pyb is not None and test_file.startswith("repl_"): # REPL feature tests will not run via pyboard because they require prompt interactivity return b"" - return run_micropython(pyb, args, base_path("feature_check", test_file), is_special=True) + test_file_path = base_path("feature_check", test_file) + return run_micropython(pyb, args, test_file_path, test_file_path, is_special=True) class ThreadSafeCounter: @@ -386,6 +397,51 @@ def value(self): return self._value +class PyboardNodeRunner: + def __init__(self): + mjs = os.getenv("MICROPY_MICROPYTHON_MJS") + if mjs is None: + mjs = base_path("../ports/webassembly/build-standard/micropython.mjs") + else: + mjs = os.path.abspath(mjs) + self.micropython_mjs = mjs + + def close(self): + pass + + def run_script_on_remote_target(self, args, test_file, is_special): + cwd = os.path.dirname(test_file) + + # Create system command list. + cmdlist = ["node"] + if test_file.endswith(".py"): + # Run a Python script indirectly via "node micropython.mjs ". + cmdlist.append(self.micropython_mjs) + if args.heapsize is not None: + cmdlist.extend(["-X", "heapsize=" + args.heapsize]) + cmdlist.append(test_file) + else: + # Run a js/mjs script directly with Node, passing in the path to micropython.mjs. + cmdlist.append(test_file) + cmdlist.append(self.micropython_mjs) + + # Run the script. + try: + had_crash = False + output_mupy = subprocess.check_output( + cmdlist, stderr=subprocess.STDOUT, timeout=TEST_TIMEOUT, cwd=cwd + ) + except subprocess.CalledProcessError as er: + had_crash = True + output_mupy = er.output + b"CRASH" + except subprocess.TimeoutExpired as er: + had_crash = True + output_mupy = (er.output or b"") + b"TIMEOUT" + + # Return the results. + return had_crash, output_mupy + + def run_tests(pyb, tests, args, result_dir, num_threads=1): test_count = ThreadSafeCounter() testcase_count = ThreadSafeCounter() @@ -418,57 +474,57 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): # run-tests.py script itself so use base_path. # Check if micropython.native is supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, "native_check.py") + output = run_feature_check(pyb, args, "native_check.py") if output != b"native\n": skip_native = True # Check if arbitrary-precision integers are supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, "int_big.py") + output = run_feature_check(pyb, args, "int_big.py") if output != b"1000000000000000000000000000000000000000000000\n": skip_int_big = True # Check if bytearray is supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, "bytearray.py") + output = run_feature_check(pyb, args, "bytearray.py") if output != b"bytearray\n": skip_bytearray = True # Check if set type (and set literals) is supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, "set_check.py") + output = run_feature_check(pyb, args, "set_check.py") if output != b"{1}\n": skip_set_type = True # Check if slice is supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, "slice.py") + output = run_feature_check(pyb, args, "slice.py") if output != b"slice\n": skip_slice = True # Check if async/await keywords are supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, "async_check.py") + output = run_feature_check(pyb, args, "async_check.py") if output != b"async\n": skip_async = True # Check if const keyword (MicroPython extension) is supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, "const.py") + output = run_feature_check(pyb, args, "const.py") if output != b"1\n": skip_const = True # Check if __rOP__ special methods are supported, and skip such tests if it's not - output = run_feature_check(pyb, args, base_path, "reverse_ops.py") + output = run_feature_check(pyb, args, "reverse_ops.py") if output == b"TypeError\n": skip_revops = True # Check if io module exists, and skip such tests if it doesn't - output = run_feature_check(pyb, args, base_path, "io_module.py") + output = run_feature_check(pyb, args, "io_module.py") if output != b"io\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") + output = run_feature_check(pyb, args, "fstring.py") if output != b"a=1\n": skip_fstring = True # Check if @micropython.asm_thumb supports Thumb2 instructions, and skip such tests if it doesn't - output = run_feature_check(pyb, args, base_path, "inlineasm_thumb2.py") + output = run_feature_check(pyb, args, "inlineasm_thumb2.py") if output != b"thumb2\n": skip_tests.add("inlineasm/asmbcc.py") skip_tests.add("inlineasm/asmbitops.py") @@ -483,23 +539,23 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): skip_tests.add("inlineasm/asmspecialregs.py") # 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") + t = run_feature_check(pyb, args, "repl_emacs_check.py") if "True" not in str(t, "ascii"): skip_tests.add("cmdline/repl_emacs_keys.py") # Check if words movement in repl is supported, and skip such tests if it's not - t = run_feature_check(pyb, args, base_path, "repl_words_move_check.py") + t = run_feature_check(pyb, args, "repl_words_move_check.py") if "True" not in str(t, "ascii"): skip_tests.add("cmdline/repl_words_move.py") - upy_byteorder = run_feature_check(pyb, args, base_path, "byteorder.py") - upy_float_precision = run_feature_check(pyb, args, base_path, "float.py") + upy_byteorder = run_feature_check(pyb, args, "byteorder.py") + upy_float_precision = run_feature_check(pyb, args, "float.py") try: upy_float_precision = int(upy_float_precision) except ValueError: upy_float_precision = 0 - has_complex = run_feature_check(pyb, args, base_path, "complex.py") == b"complex\n" - has_coverage = run_feature_check(pyb, args, base_path, "coverage.py") == b"coverage\n" + has_complex = run_feature_check(pyb, args, "complex.py") == b"complex\n" + has_coverage = run_feature_check(pyb, args, "coverage.py") == b"coverage\n" cpy_byteorder = subprocess.check_output( CPYTHON3_CMD + [base_path("feature_check/byteorder.py")] ) @@ -525,13 +581,21 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): if os.getenv("GITHUB_ACTIONS") == "true": skip_tests.add("thread/stress_schedule.py") # has reliability issues + if os.getenv("RUNNER_OS") == "Windows": + # fails with stack overflow on Debug builds + skip_tests.add("misc/sys_settrace_features.py") + + if os.getenv("MSYSTEM") is not None: + # fails due to wrong path separator + skip_tests.add("import/import_file.py") + if upy_float_precision == 0: skip_tests.add("extmod/uctypes_le_float.py") skip_tests.add("extmod/uctypes_native_float.py") skip_tests.add("extmod/uctypes_sizeof_float.py") - skip_tests.add("extmod/ujson_dumps_float.py") - skip_tests.add("extmod/ujson_loads_float.py") - skip_tests.add("extmod/urandom_extra_float.py") + skip_tests.add("extmod/json_dumps_float.py") + skip_tests.add("extmod/json_loads_float.py") + skip_tests.add("extmod/random_extra_float.py") skip_tests.add("misc/rge_sm.py") if upy_float_precision < 32: skip_tests.add( @@ -542,6 +606,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): ) # requires fp32, there's string_format_fp30.py instead skip_tests.add("float/bytes_construct.py") # requires fp32 skip_tests.add("float/bytearray_construct.py") # requires fp32 + skip_tests.add("float/float_format_ints_power10.py") # requires fp32 if upy_float_precision < 64: skip_tests.add("float/float_divmod.py") # tested by float/float_divmod_relaxed.py instead skip_tests.add("float/float2int_doubleprec_intbig.py") @@ -561,20 +626,25 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): if not has_coverage: skip_tests.add("cmdline/cmd_parsetree.py") skip_tests.add("cmdline/repl_sys_ps1_ps2.py") - skip_tests.add("extmod/ussl_poll.py") + skip_tests.add("extmod/ssl_poll.py") - # Some tests shouldn't be run on a PC - if args.target == "unix": - # unix build does not have the GIL so can't run thread mutation tests + # Skip thread mutation tests on targets that don't have the GIL. + if args.target in ("rp2", "unix"): for t in tests: if t.startswith("thread/mutate_"): skip_tests.add(t) + # Skip thread tests that require many threads on targets that don't support multiple threads. + if args.target == "rp2": + skip_tests.add("thread/stress_heap.py") + skip_tests.add("thread/thread_lock2.py") + skip_tests.add("thread/thread_lock3.py") + skip_tests.add("thread/thread_shared2.py") + # Some tests shouldn't be run on pyboard if args.target != "unix": skip_tests.add("basics/exception_chain.py") # warning is not printed skip_tests.add("micropython/meminfo.py") # output is very different to PC output - skip_tests.add("extmod/machine_mem.py") # raw memory access not supported if args.target == "wipy": skip_tests.add("misc/print_exception.py") # requires error reporting full @@ -610,6 +680,30 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): ) # RA fsp rtc function doesn't support nano sec info elif args.target == "qemu-arm": skip_tests.add("misc/print_exception.py") # requires sys stdfiles + elif args.target == "webassembly": + skip_tests.add("basics/string_format_modulo.py") # can't print nulls to stdout + skip_tests.add("basics/string_strip.py") # can't print nulls to stdout + skip_tests.add("extmod/asyncio_basic2.py") + skip_tests.add("extmod/asyncio_cancel_self.py") + skip_tests.add("extmod/asyncio_current_task.py") + skip_tests.add("extmod/asyncio_exception.py") + skip_tests.add("extmod/asyncio_gather_finished_early.py") + skip_tests.add("extmod/asyncio_get_event_loop.py") + skip_tests.add("extmod/asyncio_heaplock.py") + skip_tests.add("extmod/asyncio_loop_stop.py") + skip_tests.add("extmod/asyncio_new_event_loop.py") + skip_tests.add("extmod/asyncio_threadsafeflag.py") + skip_tests.add("extmod/asyncio_wait_for_fwd.py") + skip_tests.add("extmod/binascii_a2b_base64.py") + skip_tests.add("extmod/re_stack_overflow.py") + skip_tests.add("extmod/time_res.py") + skip_tests.add("extmod/vfs_posix.py") + skip_tests.add("extmod/vfs_posix_enoent.py") + skip_tests.add("extmod/vfs_posix_paths.py") + skip_tests.add("extmod/vfs_userfs.py") + skip_tests.add("micropython/emg_exc.py") + skip_tests.add("micropython/extreme_exc.py") + skip_tests.add("micropython/heapalloc_exc_compressed_emg_exc.py") # Some tests are known to fail on 64-bit machines if pyb is None and platform.architecture()[0] == "64bit": @@ -622,9 +716,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): # Some tests are known to fail with native emitter # Remove them from the below when they work if args.emit == "native": - skip_tests.update( - {"basics/%s.py" % t for t in "gen_yield_from_close generator_name".split()} - ) # require raise_varargs, generator name + skip_tests.add("basics/gen_yield_from_close.py") # require raise_varargs skip_tests.update( {"basics/async_%s.py" % t for t in "with with2 with_break with_return".split()} ) # require async_with @@ -635,7 +727,6 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): skip_tests.add("basics/del_deref.py") # requires checking for unbound local skip_tests.add("basics/del_local.py") # requires checking for unbound local skip_tests.add("basics/exception_chain.py") # raise from is not supported - skip_tests.add("basics/fun_name.py") # requires proper names for native functions skip_tests.add("basics/scope_implicit.py") # requires checking for unbound local skip_tests.add("basics/sys_tracebacklimit.py") # requires traceback info skip_tests.add("basics/try_finally_return2.py") # requires raise_varargs @@ -674,6 +765,7 @@ def run_tests(pyb, tests, args, result_dir, num_threads=1): def run_one_test(test_file): test_file = test_file.replace("\\", "/") + test_file_abspath = os.path.abspath(test_file).replace("\\", "/") if args.filters: # Default verdict is the opposit of the first action @@ -740,9 +832,10 @@ def run_one_test(test_file): # run CPython to work out expected output try: output_expected = subprocess.check_output( - CPYTHON3_CMD + [os.path.abspath(test_file)], + CPYTHON3_CMD + [test_file_abspath], cwd=os.path.dirname(test_file), stderr=subprocess.STDOUT, + # CIRCUITPY-CHANGE: pass environment env=e, ) if args.write_exp: @@ -758,7 +851,7 @@ def run_one_test(test_file): return # run MicroPython - output_mupy = run_micropython(pyb, args, test_file) + output_mupy = run_micropython(pyb, args, test_file, test_file_abspath) if output_mupy == b"SKIP\n": print("skip ", test_file) @@ -781,7 +874,7 @@ def run_one_test(test_file): with open(filename_mupy, "wb") as f: f.write(output_mupy) print("FAIL ", test_file) - failed_tests.append(test_name) + failed_tests.append((test_name, test_file)) test_count.increment() @@ -795,6 +888,7 @@ def run_one_test(test_file): for test in tests: run_one_test(test) + # Leave RESULTS_FILE untouched here for future runs. if args.list_tests: return True @@ -809,8 +903,26 @@ def run_one_test(test_file): if len(skipped_tests) > 0: print("{} tests skipped: {}".format(len(skipped_tests), " ".join(skipped_tests))) failed_tests = sorted(failed_tests.value) + + # Serialize regex added by append_filter. + def to_json(obj): + if isinstance(obj, re.Pattern): + return obj.pattern + return obj + + with open(os.path.join(result_dir, RESULTS_FILE), "w") as f: + json.dump( + {"args": vars(args), "failed_tests": [test[1] for test in failed_tests]}, + f, + default=to_json, + ) + if len(failed_tests) > 0: - print("{} tests failed: {}".format(len(failed_tests), " ".join(failed_tests))) + print( + "{} tests failed: {}".format( + len(failed_tests), " ".join(test[0] for test in failed_tests) + ) + ) return False # all tests succeeded @@ -926,6 +1038,11 @@ def main(): action="store_true", help="delete the .exp and .out files from failed tests and exit", ) + cmd_parser.add_argument( + "--run-failures", + action="store_true", + help="re-run only the failed tests", + ) args = cmd_parser.parse_args() if args.print_failures: @@ -942,12 +1059,14 @@ def main(): os.path.join(args.result_dir, "*.out") ): os.remove(f) + rm_f(os.path.join(args.result_dir, RESULTS_FILE)) sys.exit(0) LOCAL_TARGETS = ( "unix", "qemu-arm", + "webassembly", ) EXTERNAL_TARGETS = ( "pyboard", @@ -968,6 +1087,8 @@ def main(): args.mpy_cross_flags = "-march=host" elif args.target == "qemu-arm": args.mpy_cross_flags = "-march=armv7m" + if args.target == "webassembly": + pyb = PyboardNodeRunner() elif args.target in EXTERNAL_TARGETS: global pyboard sys.path.append(base_path("../tools")) @@ -986,11 +1107,28 @@ def main(): args.mpy_cross_flags = "-march=armv7m" pyb = pyboard.Pyboard(args.device, args.baudrate, args.user, args.password) + pyboard.Pyboard.run_script_on_remote_target = run_script_on_remote_target pyb.enter_raw_repl() else: raise ValueError("target must be one of %s" % ", ".join(LOCAL_TARGETS + EXTERNAL_TARGETS)) - if len(args.files) == 0: + if args.run_failures and (any(args.files) or args.test_dirs is not None): + raise ValueError( + "--run-failures cannot be used together with files or --test-dirs arguments" + ) + + if args.run_failures: + results_file = os.path.join(args.result_dir, RESULTS_FILE) + if os.path.exists(results_file): + with open(results_file, "r") as f: + tests = json.load(f)["failed_tests"] + else: + tests = [] + elif len(args.files) == 0: + test_extensions = ("*.py",) + if args.target == "webassembly": + test_extensions += ("*.js", "*.mjs") + if args.test_dirs is None: test_dirs = ( "basics", @@ -1001,16 +1139,16 @@ def main(): ) if args.target == "pyboard": # run pyboard tests - test_dirs += ("float", "stress", "pyb", "inlineasm") + test_dirs += ("float", "stress", "inlineasm", "ports/stm32") elif args.target in ("renesas-ra"): - test_dirs += ("float", "inlineasm", "renesas-ra") + test_dirs += ("float", "inlineasm", "ports/renesas-ra") elif args.target == "rp2": - test_dirs += ("float", "stress", "inlineasm") + test_dirs += ("float", "stress", "inlineasm", "thread", "ports/rp2") elif args.target in ("esp8266", "esp32", "minimal", "nrf"): test_dirs += ("float",) elif args.target == "wipy": # run WiPy tests - test_dirs += ("wipy",) + test_dirs += ("ports/cc3200",) elif args.target == "unix": # run PC tests test_dirs += ( @@ -1019,8 +1157,8 @@ def main(): "io", "stress", "unicode", - "unix", "cmdline", + "ports/unix", ) elif args.target == "qemu-arm": if not args.write_exp: @@ -1030,14 +1168,16 @@ def main(): test_dirs += ( "float", "inlineasm", - "qemu-arm", + "ports/qemu-arm", ) else: # run tests from these directories test_dirs = args.test_dirs tests = sorted( test_file - for test_files in (glob("{}/*.py".format(dir)) for dir in test_dirs) + for test_files in ( + glob(os.path.join(dir, ext)) for dir in test_dirs for ext in test_extensions + ) for test_file in test_files ) else: diff --git a/tests/thread/stress_schedule.py b/tests/thread/stress_schedule.py index 40191e6620986..a5d7dc824edea 100644 --- a/tests/thread/stress_schedule.py +++ b/tests/thread/stress_schedule.py @@ -19,6 +19,7 @@ n = 0 # How many times the task successfully ran. t = None # Start time of test, assigned here to preallocate entry in globals dict. +thread_run = True # If the thread should continue running. def task(x): @@ -27,7 +28,7 @@ def task(x): def thread(): - while True: + while thread_run: try: micropython.schedule(task, None) except RuntimeError: @@ -36,13 +37,21 @@ def thread(): for i in range(8): - _thread.start_new_thread(thread, ()) + try: + _thread.start_new_thread(thread, ()) + except OSError: + # System cannot create a new thead, so stop trying to create them. + break # Wait up to 10 seconds for 10000 tasks to be scheduled. t = time.ticks_ms() while n < _NUM_TASKS and time.ticks_diff(time.ticks_ms(), t) < _TIMEOUT_MS: pass +# Stop all threads. +thread_run = False +time.sleep_ms(20) + if n < _NUM_TASKS: # Not all the tasks were scheduled, likely the scheduler stopped working. print(n) diff --git a/tests/thread/thread_gc1.py b/tests/thread/thread_gc1.py index dd1e64d89444d..b36ea9d4c8421 100644 --- a/tests/thread/thread_gc1.py +++ b/tests/thread/thread_gc1.py @@ -16,21 +16,34 @@ def thread_entry(n): data[i] = data[i] gc.collect() - # print whether the data remains intact and indicate we are finished + # check whether the data remains intact and indicate we are finished with lock: - print(list(data) == list(range(256))) - global n_finished + global n_correct, n_finished + n_correct += list(data) == list(range(256)) n_finished += 1 lock = _thread.allocate_lock() -n_thread = 4 +n_thread = 0 +n_thread_max = 4 +n_correct = 0 n_finished = 0 # spawn threads -for i in range(n_thread): - _thread.start_new_thread(thread_entry, (10,)) +for _ in range(n_thread_max): + try: + _thread.start_new_thread(thread_entry, (10,)) + n_thread += 1 + except OSError: + # System cannot create a new thead, so stop trying to create them. + break + +# also run the function on this main thread +thread_entry(10) +n_thread += 1 # busy wait for threads to finish while n_finished < n_thread: pass + +print(n_correct == n_finished) diff --git a/tests/thread/thread_ident1.py b/tests/thread/thread_ident1.py index 8e106cd317f4e..2a3732eff53dc 100644 --- a/tests/thread/thread_ident1.py +++ b/tests/thread/thread_ident1.py @@ -5,7 +5,12 @@ import _thread +# Initialise variables (also preallocate their spot in the globals dict so the +# globals dict is not resized while threads are running). tid = None +tid_main = None +new_tid = None +finished = False def thread_entry(): @@ -19,7 +24,6 @@ def thread_entry(): tid_main = _thread.get_ident() print("main", type(tid_main) == int, tid_main != 0) -finished = False new_tid = _thread.start_new_thread(thread_entry, ()) while not finished: diff --git a/tests/thread/thread_lock4.py b/tests/thread/thread_lock4.py index 97c3dc538007d..b424ee3d02f98 100644 --- a/tests/thread/thread_lock4.py +++ b/tests/thread/thread_lock4.py @@ -36,14 +36,18 @@ def thread_entry(): # spawn threads to do the jobs for i in range(4): - _thread.start_new_thread(thread_entry, ()) + try: + _thread.start_new_thread(thread_entry, ()) + except OSError: + # System cannot create a new thead, so stop trying to create them. + break # wait for the jobs to complete while True: with jobs_lock: if len(output) == n_jobs: break - time.sleep(1) + time.sleep(0) # sort and print the results output.sort(key=lambda x: x[0]) diff --git a/tests/thread/thread_qstr1.py b/tests/thread/thread_qstr1.py index f184d2a58e1d4..96f12c5d8c93f 100644 --- a/tests/thread/thread_qstr1.py +++ b/tests/thread/thread_qstr1.py @@ -24,16 +24,26 @@ def th(base, n): lock = _thread.allocate_lock() -n_thread = 4 +n_thread = 0 +n_thread_max = 4 n_finished = 0 n_qstr_per_thread = 100 # make 1000 for a more stressful test (uses more heap) # spawn threads -for i in range(n_thread): - _thread.start_new_thread(th, (i * n_qstr_per_thread, n_qstr_per_thread)) +for _ in range(n_thread_max): + try: + _thread.start_new_thread(th, (n_thread * n_qstr_per_thread, n_qstr_per_thread)) + n_thread += 1 + except OSError: + # System cannot create a new thead, so stop trying to create them. + break + +# also run the function on this main thread +th(n_thread * n_qstr_per_thread, n_qstr_per_thread) +n_thread += 1 # wait for threads to finish while n_finished < n_thread: - time.sleep(1) + time.sleep(0) print("pass") diff --git a/tests/thread/thread_shared1.py b/tests/thread/thread_shared1.py index 582b01fc34356..251e26fae6ca3 100644 --- a/tests/thread/thread_shared1.py +++ b/tests/thread/thread_shared1.py @@ -18,15 +18,25 @@ def thread_entry(n, tup): lock = _thread.allocate_lock() -n_thread = 2 +n_thread = 0 +n_thread_max = 2 n_finished = 0 # the shared data structure tup = (1, 2, 3, 4) # spawn threads -for i in range(n_thread): - _thread.start_new_thread(thread_entry, (100, tup)) +for _ in range(n_thread_max): + try: + _thread.start_new_thread(thread_entry, (100, tup)) + n_thread += 1 + except OSError: + # System cannot create a new thead, so stop trying to create them. + break + +# also run the function on this main thread +thread_entry(100, tup) +n_thread += 1 # busy wait for threads to finish while n_finished < n_thread: diff --git a/tests/thread/thread_sleep1.py b/tests/thread/thread_sleep1.py index add9b02f1573b..36f775d1f6eff 100644 --- a/tests/thread/thread_sleep1.py +++ b/tests/thread/thread_sleep1.py @@ -12,7 +12,8 @@ import _thread lock = _thread.allocate_lock() -n_thread = 4 +n_thread = 0 +n_thread_max = 4 n_finished = 0 @@ -24,10 +25,20 @@ def thread_entry(t): n_finished += 1 -for i in range(n_thread): - _thread.start_new_thread(thread_entry, (10 * i,)) +# spawn threads +for _ in range(n_thread_max): + try: + _thread.start_new_thread(thread_entry, (10 * n_thread,)) + n_thread += 1 + except OSError: + # System cannot create a new thead, so stop trying to create them. + break + +# also run the function on this main thread +thread_entry(10 * n_thread) +n_thread += 1 # wait for threads to finish while n_finished < n_thread: sleep_ms(100) -print("done", n_thread) +print("done") diff --git a/tests/thread/thread_sleep2.py b/tests/thread/thread_sleep2.py new file mode 100644 index 0000000000000..2dec24cabec93 --- /dev/null +++ b/tests/thread/thread_sleep2.py @@ -0,0 +1,31 @@ +# Test accuracy of sleep within a thread. + +import time +import _thread + + +def sleep(t, valid_range): + t0 = time.time_ns() + time.sleep(t) + dt_ms = (time.time_ns() - t0) // 1_000_000 + if dt_ms in valid_range: + print("dt in range", t) + else: + print("dt not in range:", dt_ms) + + +def thread_entry(): + lock.acquire() + print("thread start") + sleep(0.2, range(180, 400)) + print("thread end") + + +lock = _thread.allocate_lock() +lock.acquire() +_thread.start_new_thread(thread_entry, ()) + +print("main start") +lock.release() +sleep(0.5, range(480, 800)) +print("main end") diff --git a/tools/boardgen.py b/tools/boardgen.py index caa9fe851c768..41a8e9f2e597b 100644 --- a/tools/boardgen.py +++ b/tools/boardgen.py @@ -289,7 +289,7 @@ def find_pin_by_cpu_pin_name(self, cpu_pin_name, create=True): def print_board_locals_dict(self, out_source): print(file=out_source) print( - "STATIC const mp_rom_map_elem_t machine_pin_board_pins_locals_dict_table[] = {", + "static const mp_rom_map_elem_t machine_pin_board_pins_locals_dict_table[] = {", file=out_source, ) for pin in self.available_pins(): @@ -318,7 +318,7 @@ def print_board_locals_dict(self, out_source): def print_cpu_locals_dict(self, out_source): print(file=out_source) print( - "STATIC const mp_rom_map_elem_t machine_pin_cpu_pins_locals_dict_table[] = {", + "static const mp_rom_map_elem_t machine_pin_cpu_pins_locals_dict_table[] = {", file=out_source, ) for pin in self.available_pins(exclude_hidden=True): diff --git a/tools/build-stm-latest.sh b/tools/build-stm-latest.sh deleted file mode 100755 index bfee1b1922e85..0000000000000 --- a/tools/build-stm-latest.sh +++ /dev/null @@ -1,46 +0,0 @@ -#!/bin/bash - -# SPDX-FileCopyrightText: 2014 MicroPython & CircuitPython contributors (https://github.com/adafruit/circuitpython/graphs/contributors) -# -# SPDX-License-Identifier: MIT - -# function for building firmware -function do_build() { - descr=$1 - board=$2 - shift - shift - echo "building $descr $board" - build_dir=/tmp/stm-build-$board - make -B $@ BOARD=$board BUILD=$build_dir || exit 1 - mv $build_dir/firmware.dfu $dest_dir/$descr-$date-$git_tag.dfu - rm -rf $build_dir -} - -# check/get parameters -if [ $# != 1 ]; then - echo "usage: $0 " - exit 1 -fi - -dest_dir=$1 - -# check we are in the correct directory -if [ ! -r modpyb.c ]; then - echo "must be in stm directory" - exit 1 -fi - -# get the date -date=$(date '+%Y-%m-%d') - -# get the git tag -git_tag="$(git describe --dirty || echo unknown)" - -# build the versions -do_build pybv3 PYBV3 -do_build pybv3-network PYBV3 MICROPY_PY_WIZNET5K=1 MICROPY_PY_CC3K=1 -do_build pybv10 PYBV10 -do_build pybv10-network PYBV10 MICROPY_PY_WIZNET5K=1 MICROPY_PY_CC3K=1 -do_build stm32f4disc STM32F4DISC -do_build espruino-pico ESPRUINO_PICO diff --git a/tools/ci.sh b/tools/ci.sh index 95b1f19ffc4a6..bac225caa4df1 100755 --- a/tools/ci.sh +++ b/tools/ci.sh @@ -30,17 +30,6 @@ function ci_c_code_formatting_run { tools/codeformat.py -v -c } -######################################################################################## -# code spelling - -function ci_code_spell_setup { - pip3 install codespell tomli -} - -function ci_code_spell_run { - codespell -} - ######################################################################################## # commit formatting @@ -189,18 +178,19 @@ function ci_esp8266_build { # ports/webassembly function ci_webassembly_setup { + npm install terser git clone https://github.com/emscripten-core/emsdk.git (cd emsdk && ./emsdk install latest && ./emsdk activate latest) } function ci_webassembly_build { source emsdk/emsdk_env.sh - make ${MAKEOPTS} -C ports/webassembly + make ${MAKEOPTS} -C ports/webassembly VARIANT=pyscript submodules + make ${MAKEOPTS} -C ports/webassembly VARIANT=pyscript } function ci_webassembly_run_tests { - # This port is very slow at running, so only run a few of the tests. - (cd tests && MICROPY_MICROPYTHON=../ports/webassembly/node_run.sh ./run-tests.py -j1 basics/builtin_*.py) + make -C ports/webassembly VARIANT=pyscript test_min } ######################################################################################## @@ -377,6 +367,12 @@ function ci_stm32_nucleo_build { diff $BUILD_WB55/firmware.unpack.dfu $BUILD_WB55/firmware.unpack_no_sk.dfu } +function ci_stm32_misc_build { + make ${MAKEOPTS} -C mpy-cross + make ${MAKEOPTS} -C ports/stm32 BOARD=ARDUINO_GIGA submodules + make ${MAKEOPTS} -C ports/stm32 BOARD=ARDUINO_GIGA +} + ######################################################################################## # ports/unix @@ -415,7 +411,7 @@ function ci_unix_build_helper { } function ci_unix_build_ffi_lib_helper { - $1 $2 -shared -o tests/unix/ffi_lib.so tests/unix/ffi_lib.c + $1 $2 -shared -o tests/ports/unix/ffi_lib.so tests/ports/unix/ffi_lib.c } function ci_unix_run_tests_helper { @@ -521,7 +517,7 @@ function ci_unix_coverage_run_mpy_merge_tests { function ci_unix_coverage_run_native_mpy_tests { MICROPYPATH=examples/natmod/features2 ./ports/unix/build-coverage/micropython -m features2 - (cd tests && ./run-natmodtests.py "$@" extmod/{btree*,deflate*,framebuf*,heapq*,random*,re*}.py) + (cd tests && ./run-natmodtests.py "$@" extmod/*.py) } function ci_unix_32bit_setup { diff --git a/tools/codeformat.py b/tools/codeformat.py index 8a95e7894f2c7..5f5a5f7409d31 100644 --- a/tools/codeformat.py +++ b/tools/codeformat.py @@ -65,7 +65,7 @@ # STM32 build includes generated Python code. "ports/*/build*", # gitignore in ports/unix ignores *.py, so also do it here. - "ports/unix/*.py", + "ports/unix/**/*.py", # not real python files "tests/**/repl_*.py", # don't reindent this third-party code we vendored in diff --git a/tools/gen-changelog.sh b/tools/gen-changelog.sh index b29606b0c784d..2dbbc24960f53 100755 --- a/tools/gen-changelog.sh +++ b/tools/gen-changelog.sh @@ -6,7 +6,7 @@ echo "MicroPython change log" -for t in $(git tag | grep -v v1.0-rc1 | sort -rV); do +for t in $(git tag | grep -v -- '-rc1\|-preview' | sort -rV); do echo '' echo '========' echo '' diff --git a/tools/manifestfile.py b/tools/manifestfile.py index aa85c4650f2a6..beaa36d0f5fc2 100644 --- a/tools/manifestfile.py +++ b/tools/manifestfile.py @@ -62,6 +62,9 @@ # URL to file. (TODO) FILE_TYPE_HTTP = 2 +# Default list of libraries in micropython-lib to search for library packages. +BASE_LIBRARY_NAMES = ("micropython", "python-stdlib", "python-ecosys") + class ManifestFileError(Exception): pass @@ -196,6 +199,12 @@ def __init__(self, mode, path_vars=None): self._metadata = [ManifestPackageMetadata()] # Registered external libraries. self._libraries = {} + # List of directories to search for packages. + self._library_dirs = [] + # Add default micropython-lib libraries if $(MPY_LIB_DIR) has been specified. + if self._path_vars["MPY_LIB_DIR"]: + for lib in BASE_LIBRARY_NAMES: + self.add_library(lib, os.path.join("$(MPY_LIB_DIR)", lib)) def _resolve_path(self, path): # Convert path to an absolute path, applying variable substitutions. @@ -282,7 +291,7 @@ def _add_file(self, full_path, target_path, kind=KIND_AUTO, opt=None): def _search(self, base_path, package_path, files, exts, kind, opt=None, strict=False): base_path = self._resolve_path(base_path) - if files: + if files is not None: # Use explicit list of files (relative to package_path). for file in files: if package_path: @@ -398,18 +407,16 @@ def _require_from_path(self, library_path, name, version, extra_kwargs): return True return False - def require(self, name, version=None, unix_ffi=False, pypi=None, library=None, **kwargs): + def require(self, name, version=None, pypi=None, library=None, **kwargs): """ Require a package by name from micropython-lib. - Optionally specify unix_ffi=True to use a module from the unix-ffi directory. - Optionally specify pipy="package-name" to indicate that this should use the named package from PyPI when building for CPython. Optionally specify library="name" to reference a package from a library that has been previously registered with add_library(). Otherwise - micropython-lib will be used. + the list of library paths will be used. """ self._metadata[-1].check_initialised(self._mode) @@ -426,39 +433,35 @@ def require(self, name, version=None, unix_ffi=False, pypi=None, library=None, * raise ValueError("Unknown library '{}' for require('{}').".format(library, name)) library_path = self._libraries[library] # Search for {library_path}/**/{name}/manifest.py. - if not self._require_from_path(library_path, name, version, kwargs): - raise ValueError( - "Package '{}' not found in external library '{}' ({}).".format( - name, library, library_path - ) + if self._require_from_path(library_path, name, version, kwargs): + return + raise ValueError( + "Package '{}' not found in external library '{}' ({}).".format( + name, library, library_path ) - elif self._path_vars["MPY_LIB_DIR"]: - # Find package in micropython-lib, in one of the three top-level directories. - lib_dirs = ["micropython", "python-stdlib", "python-ecosys"] - if unix_ffi: - # Additionally search unix-ffi only if unix_ffi=True, and make unix-ffi modules - # take precedence. - lib_dirs = ["unix-ffi"] + lib_dirs - - for lib_dir in lib_dirs: - # Search for {lib_dir}/**/{name}/manifest.py. - if self._require_from_path( - os.path.join(self._path_vars["MPY_LIB_DIR"], lib_dir), name, version, kwargs - ): - return - - raise ValueError("Package '{}' not found in local micropython-lib.".format(name)) - else: - # TODO: HTTP request to obtain URLs from manifest.json. - raise ValueError("micropython-lib not available for require('{}').", name) + ) - def add_library(self, library, library_path): + for lib_dir in self._library_dirs: + # Search for {lib_dir}/**/{name}/manifest.py. + if self._require_from_path(lib_dir, name, version, kwargs): + return + + raise ValueError("Package '{}' not found in any known library.".format(name)) + + def add_library(self, library, library_path, prepend=False): """ Register the path to an external named library. - This allows require("name", library="library") to find packages in that library. + The path will be automatically searched when using require(). By default the + added library is added to the end of the list of libraries to search. Pass + `prepend=True` to add it to the start of the list. + + Additionally, the added library can be explicitly requested by using + `require("name", library="library")`. """ - self._libraries[library] = self._resolve_path(library_path) + library_path = self._resolve_path(library_path) + self._libraries[library] = library_path + self._library_dirs.insert(0 if prepend else len(self._library_dirs), library_path) def package(self, package_path, files=None, base_path=".", opt=None): """ @@ -600,6 +603,9 @@ def main(): default=os.path.join(os.path.dirname(__file__), "../lib/micropython-lib"), help="path to micropython-lib repo", ) + cmd_parser.add_argument( + "--unix-ffi", action="store_true", help="prepend unix-ffi to the library path" + ) cmd_parser.add_argument("--port", default=None, help="path to port dir") cmd_parser.add_argument("--board", default=None, help="path to board dir") cmd_parser.add_argument( @@ -629,6 +635,8 @@ def main(): exit(1) m = ManifestFile(mode, path_vars) + if args.unix_ffi: + m.add_library("unix-ffi", os.path.join("$(MPY_LIB_DIR)", "unix-ffi"), prepend=True) for manifest_file in args.files: try: m.execute(manifest_file) diff --git a/tools/mpy-tool.py b/tools/mpy-tool.py index 8bb1c6020d09a..1d46d9700a69d 100755 --- a/tools/mpy-tool.py +++ b/tools/mpy-tool.py @@ -88,7 +88,7 @@ def __str__(self): class Config: MPY_VERSION = 6 - MPY_SUB_VERSION = 2 + MPY_SUB_VERSION = 3 MICROPY_LONGINT_IMPL_NONE = 0 MICROPY_LONGINT_IMPL_LONGLONG = 1 MICROPY_LONGINT_IMPL_MPZ = 2 @@ -126,7 +126,10 @@ class Config: MP_PERSISTENT_OBJ_COMPLEX = 9 MP_PERSISTENT_OBJ_TUPLE = 10 -# Circuitpython: this does not match upstream because we added MP_SCOPE_FLAG_ASYNC + +MP_SCOPE_FLAG_GENERATOR = 0x01 +# CIRCUITPY-CHANGE: async is distinct from generator; flag constants are different +MP_SCOPE_FLAG_ASYNC = 0x10 MP_SCOPE_FLAG_VIPERRELOC = 0x20 MP_SCOPE_FLAG_VIPERRODATA = 0x40 MP_SCOPE_FLAG_VIPERBSS = 0x80 @@ -682,7 +685,7 @@ def freeze(self, compiled_module_index): else: print(" .obj_table = NULL,") print(" },") - print(" .rc = &raw_code_%s," % self.raw_code.escaped_name) + print(" .proto_fun = &proto_fun_%s," % self.raw_code.escaped_name) print("};") def freeze_constant_obj(self, obj_name, obj): @@ -897,7 +900,8 @@ def freeze_children(self, prelude_ptr=None): print() print("static const mp_raw_code_t *const children_%s[] = {" % self.escaped_name) for rc in self.children: - print(" &raw_code_%s," % rc.escaped_name) + # CIRCUITPY-CHANGE: add (void *) to prevent cast-align compiler warning + print(" (const mp_raw_code_t *)(void *)&proto_fun_%s," % rc.escaped_name) if prelude_ptr: print(" (void *)%s," % prelude_ptr) print("};") @@ -905,14 +909,25 @@ def freeze_children(self, prelude_ptr=None): def freeze_raw_code(self, prelude_ptr=None, type_sig=0): # Generate mp_raw_code_t. - print("static const mp_raw_code_t raw_code_%s = {" % self.escaped_name) + if self.code_kind == MP_CODE_NATIVE_ASM: + raw_code_type = "mp_raw_code_t" + else: + raw_code_type = "mp_raw_code_truncated_t" + + empty_children = len(self.children) == 0 and prelude_ptr is None + generate_minimal = self.code_kind == MP_CODE_BYTECODE and empty_children + + if generate_minimal: + print("#if MICROPY_PERSISTENT_CODE_SAVE") + + print("static const %s proto_fun_%s = {" % (raw_code_type, self.escaped_name)) + print(" .proto_fun_indicator[0] = MP_PROTO_FUN_INDICATOR_RAW_CODE_0,") + print(" .proto_fun_indicator[1] = MP_PROTO_FUN_INDICATOR_RAW_CODE_1,") print(" .kind = %s," % RawCode.code_kind_str[self.code_kind]) - print(" .scope_flags = 0x%02x," % self.scope_flags) - print(" .n_pos_args = %u," % self.n_pos_args) + print(" .is_generator = %d," % bool(self.scope_flags & MP_SCOPE_FLAG_GENERATOR)) + # CIRCUITPY-CHANGE: async is distinct from generator + print(" .is_async = %d," % bool(self.scope_flags & MP_SCOPE_FLAG_ASYNC)) print(" .fun_data = fun_data_%s," % self.escaped_name) - print(" #if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS") - print(" .fun_data_len = %u," % len(self.fun_data)) - print(" #endif") if len(self.children): print(" .children = (void *)&children_%s," % self.escaped_name) elif prelude_ptr: @@ -920,9 +935,14 @@ def freeze_raw_code(self, prelude_ptr=None, type_sig=0): else: print(" .children = NULL,") print(" #if MICROPY_PERSISTENT_CODE_SAVE") + print(" .fun_data_len = %u," % len(self.fun_data)) print(" .n_children = %u," % len(self.children)) + print(" #if MICROPY_EMIT_MACHINE_CODE") + print(" .prelude_offset = %u," % self.prelude_offset) + print(" #endif") if self.code_kind == MP_CODE_BYTECODE: print(" #if MICROPY_PY_SYS_SETTRACE") + print(" .line_of_definition = %u," % 0) # TODO print(" .prelude = {") print(" .n_state = %u," % self.prelude_signature[0]) print(" .n_exc_stack = %u," % self.prelude_signature[1]) @@ -943,17 +963,18 @@ def freeze_raw_code(self, prelude_ptr=None, type_sig=0): " .opcodes = fun_data_%s + %u," % (self.escaped_name, self.offset_opcodes) ) print(" },") - print(" .line_of_definition = %u," % 0) # TODO print(" #endif") - print(" #if MICROPY_EMIT_MACHINE_CODE") - print(" .prelude_offset = %u," % self.prelude_offset) - print(" #endif") - print(" #endif") - print(" #if MICROPY_EMIT_MACHINE_CODE") - print(" .type_sig = %u," % type_sig) print(" #endif") + if self.code_kind == MP_CODE_NATIVE_ASM: + print(" .asm_n_pos_args = %u," % self.n_pos_args) + print(" .asm_type_sig = %u," % type_sig) print("};") + if generate_minimal: + print("#else") + print("#define proto_fun_%s fun_data_%s[0]" % (self.escaped_name, self.escaped_name)) + print("#endif") + global raw_code_count, raw_code_content raw_code_count += 1 raw_code_content += 4 * 4 @@ -1331,6 +1352,7 @@ def read_mpy(filename): # Read and verify the header. header = reader.read_bytes(4) + # CIRCUITPY-CHANGE: "C" is used for CircuitPython if header[0] != ord("C"): raise MPYReadError(filename, "not a valid .mpy file") if header[1] != config.MPY_VERSION: @@ -1472,21 +1494,20 @@ def freeze_mpy(firmware_qstr_idents, compiled_modules): raw_code_count = 0 raw_code_content = 0 - print() - print("const qstr_hash_t mp_qstr_frozen_const_hashes[] = {") - qstr_size = {"metadata": 0, "data": 0} - for _, _, _, qbytes in new: - qhash = qstrutil.compute_hash(qbytes, config.MICROPY_QSTR_BYTES_IN_HASH) - print(" %d," % qhash) - print("};") + if config.MICROPY_QSTR_BYTES_IN_HASH: + print() + print("const qstr_hash_t mp_qstr_frozen_const_hashes[] = {") + for _, _, _, qbytes in new: + qhash = qstrutil.compute_hash(qbytes, config.MICROPY_QSTR_BYTES_IN_HASH) + print(" %d," % qhash) + qstr_content += config.MICROPY_QSTR_BYTES_IN_HASH + print("};") print() print("const qstr_len_t mp_qstr_frozen_const_lengths[] = {") for _, _, _, qbytes in new: print(" %d," % len(qbytes)) - qstr_size["metadata"] += ( - config.MICROPY_QSTR_BYTES_IN_LEN + config.MICROPY_QSTR_BYTES_IN_HASH - ) - qstr_size["data"] += len(qbytes) + qstr_content += config.MICROPY_QSTR_BYTES_IN_LEN + qstr_content += len(qbytes) + 1 # include NUL print("};") print() print("extern const qstr_pool_t mp_qstr_const_pool;") @@ -1496,14 +1517,12 @@ def freeze_mpy(firmware_qstr_idents, compiled_modules): print(" true, // is_sorted") print(" %u, // allocated entries" % qstr_pool_alloc) print(" %u, // used entries" % len(new)) - print(" (qstr_hash_t *)mp_qstr_frozen_const_hashes,") + if config.MICROPY_QSTR_BYTES_IN_HASH: + print(" (qstr_hash_t *)mp_qstr_frozen_const_hashes,") print(" (qstr_len_t *)mp_qstr_frozen_const_lengths,") print(" {") for _, _, qstr, qbytes in new: print(' "%s",' % qstrutil.escape_bytes(qstr, qbytes)) - qstr_content += ( - config.MICROPY_QSTR_BYTES_IN_LEN + config.MICROPY_QSTR_BYTES_IN_HASH + len(qbytes) + 1 - ) print(" },") print("};") @@ -1686,6 +1705,7 @@ def merge_mpy(compiled_modules, output_file): compiled_modules.insert(0, compiled_modules.pop(main_cm_idx)) header = bytearray(4) + ## CIRCUITPY-CHANGE: "C" is used for CircuitPython header[0] = ord("C") header[1] = config.MPY_VERSION header[2] = config.native_arch << 2 | config.MPY_SUB_VERSION if config.native_arch else 0 @@ -1716,10 +1736,13 @@ def copy_section(file, offset, offset2): bytecode.append(0b00000010) # prelude size (n_info=1, n_cell=0) bytecode.extend(b"\x00") # simple_name: qstr index 0 (will use source filename) for idx in range(len(compiled_modules)): - bytecode.append(0x32) # MP_BC_MAKE_FUNCTION - bytecode.append(idx) # index raw code - bytecode.extend(b"\x34\x00\x59") # MP_BC_CALL_FUNCTION, 0 args, MP_BC_POP_TOP - bytecode.extend(b"\x51\x63") # MP_BC_LOAD_NONE, MP_BC_RETURN_VALUE + bytecode.append(Opcode.MP_BC_MAKE_FUNCTION) + bytecode.extend(mp_encode_uint(idx)) # index of raw code + bytecode.append(Opcode.MP_BC_CALL_FUNCTION) + bytecode.append(0) # 0 arguments + bytecode.append(Opcode.MP_BC_POP_TOP) + bytecode.append(Opcode.MP_BC_LOAD_CONST_NONE) + bytecode.append(Opcode.MP_BC_RETURN_VALUE) merged_mpy.extend(mp_encode_uint(len(bytecode) << 3 | 1 << 2)) # length, has_children merged_mpy.extend(bytecode) @@ -1797,7 +1820,7 @@ def main(): else: config.MICROPY_QSTR_BYTES_IN_LEN = 1 config.MICROPY_QSTR_BYTES_IN_HASH = 1 - firmware_qstr_idents = set(qstrutil.static_qstr_list) + firmware_qstr_idents = set(qstrutil.static_qstr_list_ident) # Create initial list of global qstrs. global_qstrs = GlobalQStrList() diff --git a/tools/mpy_ld.py b/tools/mpy_ld.py index cecb65d0efec4..efde6af6ba5c9 100755 --- a/tools/mpy_ld.py +++ b/tools/mpy_ld.py @@ -36,7 +36,7 @@ # MicroPython constants MPY_VERSION = 6 -MPY_SUB_VERSION = 2 +MPY_SUB_VERSION = 3 MP_CODE_BYTECODE = 2 MP_CODE_NATIVE_VIPER = 4 MP_NATIVE_ARCH_X86 = 1 @@ -48,11 +48,11 @@ MP_NATIVE_ARCH_XTENSA = 9 MP_NATIVE_ARCH_XTENSAWIN = 10 MP_PERSISTENT_OBJ_STR = 5 -# Circuitpython: this does not match upstream because we added MP_SCOPE_FLAG_ASYNC -MP_SCOPE_FLAG_VIPERRELOC = 0x20 -MP_SCOPE_FLAG_VIPERRODATA = 0x40 -MP_SCOPE_FLAG_VIPERBSS = 0x80 +MP_SCOPE_FLAG_VIPERRELOC = 0x10 +MP_SCOPE_FLAG_VIPERRODATA = 0x20 +MP_SCOPE_FLAG_VIPERBSS = 0x40 MP_SMALL_INT_BITS = 31 +MP_FUN_TABLE_MP_TYPE_TYPE_OFFSET = 73 # ELF constants R_386_32 = 1 @@ -755,8 +755,7 @@ def link_objects(env, native_qstr_vals_len): # Resolve unknown symbols mp_fun_table_sec = Section(".external.mp_fun_table", b"", 0) fun_table = { - # Circuitpython: this does not match upstream because we added an item in _mp_fnu_table_t - key: 68 + idx + key: MP_FUN_TABLE_MP_TYPE_TYPE_OFFSET + idx for idx, key in enumerate( [ "mp_type_type", @@ -768,6 +767,7 @@ def link_objects(env, native_qstr_vals_len): "mp_type_fun_builtin_2", "mp_type_fun_builtin_3", "mp_type_fun_builtin_var", + "mp_type_Exception", "mp_stream_read_obj", "mp_stream_readinto_obj", "mp_stream_unbuffered_readline_obj", @@ -907,6 +907,7 @@ def build_mpy(env, entry_offset, fmpy, native_qstr_vals): # MPY: header out.write_bytes( bytearray( + # CIRCUITPY-CHANGE: CircuitPython uses "C" [ord("C"), MPY_VERSION, env.arch.mpy_feature | MPY_SUB_VERSION, MP_SMALL_INT_BITS] ) )