summaryrefslogtreecommitdiffstatshomepage
path: root/py
Commit message (Collapse)AuthorAge
* tools/makeqstrdefs.py: Run qstr preprocessing in parallel.Jim Mussared2020-11-12
| | | | | | | | | | | | | This gives a substantial speedup of the preprocessing step, i.e. the generation of qstr.i.last. For example on a clean build, making qstr.i.last: 21s -> 4s on STM32 (WB55) 8.9 -> 1.8s on Unix (dev). Done in collaboration with @stinos. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
* py/binary: Fix sign extension setting wide integer on 32-bit archs.Damien George2020-11-11
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/mpz: Do sign extension in mpz_as_bytes for negative values.Damien George2020-11-11
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/py.mk: Support C++ code for user C modules.stijn2020-10-29
| | | | | | | Support C++ code in .cpp files by providing CXX counterparts of the _USERMOD_ flags we have for C already. This merely enables the Makefile of user C modules to use variables specific to C++ compilation, it is still up to each port's main Makefile to also include these in the build.
* py: Workaround clang error when building misc.h with C++ compiler.stijn2020-10-29
|
* py/makeqstrdefs.py: Support preprocessing C++ files for QSTR generation.stijn2020-10-29
| | | | | | | | | | | When SCR_QSTR contains C++ files they should be preprocessed with the same compiler flags (CXXFLAGS) as they will be compiled with, to make sure code scanned for QSTR occurrences is effectively the code used in the rest of the build. The 'split SCR_QSTR in .c and .cpp files and process each with different flags' logic isn't trivial to express in a Makefile and the existing principle for deciding which files to preprocess was already rather complicated, so the actual preprocessing is moved into makeqstrdefs.py completely.
* py/mkrules.mk: Add target for compiling C++ files.stijn2020-10-29
| | | | | | Move the target from the ESP32 Makefile since that does what is needed already, but also include files from user C modules as is done for the C files.
* py/makeqstrdefs.py: Process C++ files as well.stijn2020-10-29
| | | | | Preprocessed C++ code isn't different from C code when it comes to QSTR instances so process it as well.
* py/makeqstrdefs.py: Fix beaviour when scanning non-C preprocessed files.stijn2020-10-29
| | | | | | When process_file() is passed a preprocessed C++ file for instance it won't find any lines containing .c files and the last_fname variable remains None, so handle that gracefully.
* py, extmod: Introduce and use MP_FALLTHROUGH macro.Emil Renner Berthing2020-10-22
| | | | | | | Newer GCC versions are able to warn about switch cases that fall through. This is usually a sign of a forgotten break statement, but in the few cases where a fall through is intended we annotate it with this macro to avoid the warning.
* py/vmentrytable: Ignore GCC -Woverride-init.Emil Renner Berthing2020-10-22
| | | | | | Like Clang, GCC warns about this file, but only with -Woverride-init which is enabled by -Wextra. Disable the warnings for this file just like we do for Clang to make -Wextra happy.
* py, extmod: Add explicit initializers for default values.Emil Renner Berthing2020-10-22
| | | | | | | | | When compiling with -Wextra which includes -Wmissing-field-initializers GCC will warn that the defval field of mp_arg_val_t is not initialized. This is just a warning as it is defined to be zero initialized, but since it is a union it makes sense to be explicit about which member we're going to use, so add the explicit initializers and get rid of the warning.
* py: Use unsigned comparison of chars.Emil Renner Berthing2020-10-22
| | | | | | On x86 chars are signed, but we're comparing a char to '0' + unsigned int, which is promoted to an unsigned int. Let's promote the char to unsigned before doing the comparison to avoid weird corner cases.
* py/objexcept: Compare mp_emergency_exception_buf_size signed.Emil Renner Berthing2020-10-22
| | | | | mp_emergency_exception_buf_size is signed, so let's make sure we compare it as such.
* py/scope: Name and use id_kind_type_t.Emil Renner Berthing2020-10-22
| | | | | | | | | | | The function scope_find_or_add_id used to take a scope_kind_t enum and save it in an uint8_t. Saving an enum in a uint8_t is fine, but everywhere this function is called it is not actually given a scope_kind_t but an anonymous enum instead. Let's give this enum a name and use that as the argument type. This doesn't change the generated code, but is a C type mismatch that unfortunately doesn't show up unless you enable -Wenum-conversion.
* py/objtype: Handle __dict__ attribute when type has no locals.Jim Mussared2020-10-10
|
* py/objdict: Add mp_const_empty_dict_obj, use it for mp_const_empty_map.Jim Mussared2020-10-10
|
* py/parse: Expose rule-name printing as MICROPY_DEBUG_PARSE_RULE_NAME.Damien George2020-10-01
| | | | | | So it can be enabled without modifying the source. Signed-off-by: Damien George <damien@micropython.org>
* py/makeversionhdr.py: Match only git tags which look like versions.Mike Wadsten2020-10-01
| | | | | | | | Some downstream projects may use tags in their repositories for more than just designating MicroPython releases. In those cases, the makeversionhdr.py script would end up using a different tag than intended. So tell `git describe` to only match tags that look like a MicroPython version tag, such as `v1.12` or `v2.0`.
* py/objarray.h: Add mp_obj_memoryview_init() helper function.Damien George2020-09-25
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/objstr: Make bytes(bytes_obj) return bytes_obj.Iyassou Shimels2020-09-24
| | | | | | | Calling the bytes constructor on a bytes object returns the original bytes object. This saves allocating a new instance, and matches CPython. Signed-off-by: Iyassou Shimels <s.iyassou@gmail.com>
* py/dynruntime.h: Add mp_import_* and mp_load/store_*.Jim Mussared2020-09-18
| | | | | These functions already exist in the fun table, and this commit just adds convenience macros for them.
* all: Rename absolute time-based functions to include "epoch".Damien George2020-09-18
| | | | | | | | | | | | | | | | | | | | | | | | | For time-based functions that work with absolute time there is the need for an Epoch, to set the zero-point at which the absolute time starts counting. Such functions include time.time() and filesystem stat return values. And different ports may use a different Epoch. To make it clearer what functions use the Epoch (whatever it may be), and make the ports more consistent with their use of the Epoch, this commit renames all Epoch related functions to include the word "epoch" in their name (and remove references to "2000"). Along with this rename, the following things have changed: - mp_hal_time_ns() is now specified to return the number of nanoseconds since the Epoch, rather than since 1970 (but since this is an internal function it doesn't change anything for the user). - littlefs timestamps on the esp8266 have been fixed (they were previously off by 30 years in nanoseconds). Otherwise, there is no functional change made by this commit. Signed-off-by: Damien George <damien@micropython.org>
* py/parse: Pass in an mp_print_t to mp_parse_node_print.Damien George2020-09-11
| | | | | | So the output can be redirected if needed. Signed-off-by: Damien George <damien@micropython.org>
* py/showbc: Pass in an mp_print_t struct to all bytecode-print functions.Damien George2020-09-11
| | | | | | So the output can be redirected if needed. Signed-off-by: Damien George <damien@micropython.org>
* py: Fix handling of NaN in certain pow implementations.stijn2020-09-11
| | | | | Adds a new compile-time option MICROPY_PY_MATH_POW_FIX_NAN for use with toolchains that don't handle pow-of-NaN correctly.
* py/objfloat: Fix handling of negative float to power of nan.Damien George2020-09-11
| | | | | | | | Prior to this commit, pow(-2, float('nan')) would return (nan+nanj), or raise an exception on targets that don't support complex numbers. This is fixed to return simply nan, as CPython does. Signed-off-by: Damien George <damien@micropython.org>
* all: Rename "sys" module to "usys".stijn2020-09-04
| | | | | | | | | This is consistent with the other 'micro' modules and allows implementing additional features in Python via e.g. micropython-lib's sys. Note this is a breaking change (not backwards compatible) for ports which do not enable weak links, as "import sys" must now be replaced with "import usys".
* all: Bump version to 1.13.v1.13Damien George2020-09-02
| | | | Signed-off-by: Damien George <damien@micropython.org>
* all: Update Python code to conform to latest black formatting.Damien George2020-08-29
| | | | | | | | | | | | | Updating to Black v20.8b1 there are two changes that affect the code in this repository: - If there is a trailing comma in a list (eg [], () or function call) then that list is now written out with one line per element. So remove such trailing commas where the list should stay on one line. - Spaces at the start of """ doc strings are removed. Signed-off-by: Damien George <damien@micropython.org>
* py/mphal.h: Introduce mp_hal_time_ns and implement on various ports.Damien George2020-08-22
| | | | | | | This should return a 64-bit value being the number of nanoseconds since 1970/1/1. Signed-off-by: Damien George <damien@micropython.org>
* py/runtime: Fix builtin compile() in "single" mode so it prints exprs.Damien George2020-08-22
| | | | | | | | As per CPython behaviour, compile(stmt, "file", "single") should create code which prints to stdout (via __repl_print__) the results of any expressions in stmt. Signed-off-by: Damien George <damien@micropython.org>
* py/persistentcode: Maintain root ptr list of imported native .mpy code.Damien George2020-08-02
| | | | | | | | | | | | | | | | | | | | | | | On ports where normal heap memory can contain executable code (eg ARM-based ports such as stm32), native code loaded from an .mpy file may be reclaimed by the GC because there's no reference to the very start of the native machine code block that is reachable from root pointers (only pointers to internal parts of the machine code block are reachable, but that doesn't help the GC find the memory). This commit fixes this issue by maintaining an explicit list of root pointers pointing to native code that is loaded from an .mpy file. This is not needed for all ports so is selectable by the new configuration option MICROPY_PERSISTENT_CODE_TRACK_RELOC_CODE. It's enabled by default if a port does not specify any special functions to allocate or commit executable memory. A test is included to test that native code loaded from an .mpy file does not get reclaimed by the GC. Fixes #6045. Signed-off-by: Damien George <damien@micropython.org>
* py/compile: Don't await __aiter__ special method in async-for.Jonathan Hogg2020-07-25
| | | | | | | | | | | | | | | | | | | | MicroPython's original implementation of __aiter__ was correct for an earlier (provisional) version of PEP492 (CPython 3.5), where __aiter__ was an async-def function. But that changed in the final version of PEP492 (in CPython 3.5.2) where the function was changed to a normal one. See https://www.python.org/dev/peps/pep-0492/#why-aiter-does-not-return-an-awaitable See also the note at the end of this subsection in the docs: https://docs.python.org/3.5/reference/datamodel.html#asynchronous-iterators And for completeness the BPO: https://bugs.python.org/issue27243 To be consistent with the Python spec as it stands today (and now that PEP492 is final) this commit changes MicroPython's behaviour to match CPython: __aiter__ should return an async-iterable object, but is not itself awaitable. The relevant tests are updated to match. See #6267.
* py/obj.h: Fix mp_seq_replace_slice_no_grow to use memmove not memcpy.Damien George2020-07-21
| | | | | | | | | | | | | Because the argument arrays may overlap, as show by the new tests in this commit. Also remove the debugging comments for these macros, add a new comment about overlapping regions, and separate the macros by blank lines to make them easier to read. Fixes issue #6244. Signed-off-by: Damien George <damien@micropython.org>
* py: Rework mp_convert_member_lookup to properly handle built-ins.Damien George2020-06-30
| | | | | | | | | | | | | | | | | | | | | | | | | | | This commit fixes lookups of class members to make it so that built-in functions that are used as methods/functions of a class work correctly. The mp_convert_member_lookup() function is pretty much completely changed by this commit, but for the most part it's just reorganised and the indenting changed. The functional changes are: - staticmethod and classmethod checks moved to later in the if-logic, because they are less common and so should be checked after the more common cases. - The explicit mp_obj_is_type(member, &mp_type_type) check is removed because it's now subsumed by other, more general tests in this function. - MP_TYPE_FLAG_BINDS_SELF and MP_TYPE_FLAG_BUILTIN_FUN type flags added to make the checks in this function much simpler (now they just test this bit in type->flags). - An extra check is made for mp_obj_is_instance_type(type) to fix lookup of built-in functions. Fixes #1326 and #6198. Signed-off-by: Damien George <damien@micropython.org>
* py/obj.h: Make existing MP_TYPE_FLAG_xxx macros sequential.Damien George2020-06-30
| | | | | | | There's no reason to have them non-sequential, this was likely a typo from commit 9ec1caf42e7733b5141b7aecf1b6e58834a94bf7. Signed-off-by: Damien George <damien@micropython.org>
* py/objcomplex: Add mp_obj_get_complex_maybe for use in complex bin-op.Damien George2020-06-27
| | | | | | | | This allows complex binary operations to fail gracefully with unsupported operation rather than raising an exception, so that special methods work correctly. Signed-off-by: Damien George <damien@micropython.org>
* py/emitnative: Implement binary operations for viper uint operands.Damien George2020-06-27
| | | | | | | | | uint types in viper mode can now be used for all binary operators except floor-divide and modulo. Fixes issue #1847 and issue #6177. Signed-off-by: Damien George <damien@micropython.org>
* py/asm: Add condition codes for signed comparisons.Damien George2020-06-27
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/asm: Add funcs/macros to emit machine code for logical-shift-right.Damien George2020-06-27
| | | | Signed-off-by: Damien George <damien@micropython.org>
* py/objtype: Support passing in an OrderedDict to type() as the locals.Damien George2020-06-24
| | | | | | | An OrderedDict can now be used for the locals when creating a type explicitly via type(name, bases, locals). Signed-off-by: Damien George <damien@micropython.org>
* py/obj.h: Add public mp_obj_is_dict_or_ordereddict() helper macro.Damien George2020-06-24
| | | | | | And use it in py/objdict.c instead of mp_obj_is_dict_type. Signed-off-by: Damien George <damien@micropython.org>
* py/misc.h: Add missing semi-colon in mp_float_union_t for big-endian.Damien George2020-06-22
| | | | | | Fixes issue #6161. Signed-off-by: Damien George <damien@micropython.org>
* py/compile: Implement PEP 526, syntax for variable annotations.Damien George2020-06-16
| | | | | | | | | | | | | | | | | | This addition to the grammar was introduced in Python 3.6. It allows annotating the type of a varilable, like: x: int = 123 s: str The implementation in this commit is quite simple and just ignores the annotation (the int and str bits above). The reason to implement this is to allow Python 3.6+ code that uses this feature to compile under MicroPython without change, and for users to use type checkers. In the future viper could use this syntax as a way to give types to variables, which is currently done in a bit of an ad-hoc way, eg x = int(123). And this syntax could potentially be used in the inline assembler to define labels in an way that's easier to read.
* py/grammar.h: Consolidate duplicate sub-rules for :test and =test.Damien George2020-06-16
|
* py/compile: Implement PEP 572, assignment expressions with := operator.Damien George2020-06-16
| | | | | | | | | | The syntax matches CPython and the semantics are equivalent except that, unlike CPython, MicroPython allows using := to assign to comprehension iteration variables, because disallowing this would take a lot of code to check for it. The new compile-time option MICROPY_PY_ASSIGN_EXPR selects this feature and is enabled by default, following MICROPY_PY_ASYNC_AWAIT.
* py/compile: Convert scope test to SCOPE_IS_COMP_LIKE macro.Damien George2020-06-16
| | | | This macro can be used elsewhere.
* tools/codeformat.py: Remove sizeof fixup.David Lechner2020-06-14
| | | | | | | | | Formatting for `* sizeof` was fixed in uncrustify v0.71, so we no longer need the fixups for it. Also, there was one file where the updated uncrustify caught a problem that the regex didn't pick up, which is updated in this commit. Signed-off-by: David Lechner <david@pybricks.com>
* py/obj.h: Clarify comments about mp_map_t is_fixed and is_ordered.Damien George2020-06-10
| | | | | | | | Long ago, prior to 0ef01d0a75b8b2f48a72f0041e048a390b9e75b6, fixed and ordered maps were the same setting with the "table_is_fixed_array" member of mp_map_t. But these settings are actually independent, and it is possible to have is_fixed=1, is_ordered=0 (although this can currently only be done by tools/cc1). So update the comments to reflect this.