summaryrefslogtreecommitdiff
path: root/py
AgeCommit message (Collapse)Author
2021-01-30py/gc: Fix debug printing of pointer.stijn
When DEBUG_printf is the standard printf, compilers require the value for %p to be an actual pointer instead of an integer.
2021-01-30py/qstr.h: Remove QSTR_FROM_STR_STATIC macro.stijn
It practically does the same as qstr_from_str and was only used in one place, which should actually use the compile-time MP_QSTR_XXX form for consistency; qstr_from_str is for runtime strings only.
2021-01-29py/emitnative: Support binary ops on ARMv6M without use of ite instr.graham sanderson
2021-01-29py/emitinlinethumb: Exclude code using #if when ARMV7M disabled.Damien George
So there are no references to undeclared asm_thumb_mov_reg_i16(). Signed-off-by: Damien George <damien@micropython.org>
2021-01-29py/emitnative: Ensure encoding to load prelude_offset doesn't change sz.Damien George
Based on change made by Graham Sanderson. Signed-off-by: Damien George <damien@micropython.org>
2021-01-29py/asmthumb: Add support for ARMv6M in native emitter.graham sanderson
Adds a new compile-time option MICROPY_EMIT_THUMB_ARMV7M which is enabled by default (to get existing behaviour) and which should be disabled (set to 0) when building native emitter support (@micropython.native) on ARMv6M targets.
2021-01-29py/objfun: Support fun.__globals__ attribute.Damien George
This returns a reference to the globals dict associated with the function, ie the global scope that the function was defined in. This attribute is read-only but the dict itself is modifiable, per CPython behaviour. Signed-off-by: Damien George <damien@micropython.org>
2020-12-14py/mkrules.mk: Remove stray vpath and unused -Itmp, add $(Q) for $(AR).Damien George
Signed-off-by: Damien George <damien@micropython.org>
2020-12-14py/modmath: Simplify handling of positional args to reduce code size.Damien George
As a general pattern, required positional arguments that are not named do not need to be parsed using mp_arg_parse_all(). Signed-off-by: Damien George <damien@micropython.org>
2020-12-07py/mpprint: Fix length calculation for strings with precision-modifier.Joris Peeraer
Two issues are tackled: 1. The calculation of the correct length to print is fixed to treat the precision as a maximum length instead as the exact length. This is done for both qstr (%q) and for regular str (%s). 2. Fix the incorrect use of mp_printf("%.*s") to mp_print_strn(). Because of the fix of above issue, some testcases that would print an embedded null-byte (^@ in test-output) would now fail. The bug here is that "%s" was used to print null-bytes. Instead, mp_print_strn is used to make sure all bytes are outputted and the exact length is respected. Test-cases are added for both %s and %q with a combination of precision and padding specifiers.
2020-11-29py/mpprint: Prevent case fall-through when assert is disabled.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2020-11-24extmod/modbluetooth: Add API for L2CAP channels.Jim Mussared
Also known as L2CAP "connection oriented channels". This provides a socket-like data transfer mechanism for BLE. Currently only implemented for NimBLE on STM32 / Unix. Signed-off-by: Jim Mussared <jim.mussared@gmail.com>
2020-11-12tools/makeqstrdefs.py: Run qstr preprocessing in parallel.Jim Mussared
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>
2020-11-11py/binary: Fix sign extension setting wide integer on 32-bit archs.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2020-11-11py/mpz: Do sign extension in mpz_as_bytes for negative values.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2020-10-29py/py.mk: Support C++ code for user C modules.stijn
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.
2020-10-29py: Workaround clang error when building misc.h with C++ compiler.stijn
2020-10-29py/makeqstrdefs.py: Support preprocessing C++ files for QSTR generation.stijn
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.
2020-10-29py/mkrules.mk: Add target for compiling C++ files.stijn
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.
2020-10-29py/makeqstrdefs.py: Process C++ files as well.stijn
Preprocessed C++ code isn't different from C code when it comes to QSTR instances so process it as well.
2020-10-29py/makeqstrdefs.py: Fix beaviour when scanning non-C preprocessed files.stijn
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.
2020-10-22py, extmod: Introduce and use MP_FALLTHROUGH macro.Emil Renner Berthing
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.
2020-10-22py/vmentrytable: Ignore GCC -Woverride-init.Emil Renner Berthing
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.
2020-10-22py, extmod: Add explicit initializers for default values.Emil Renner Berthing
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.
2020-10-22py: Use unsigned comparison of chars.Emil Renner Berthing
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.
2020-10-22py/objexcept: Compare mp_emergency_exception_buf_size signed.Emil Renner Berthing
mp_emergency_exception_buf_size is signed, so let's make sure we compare it as such.
2020-10-22py/scope: Name and use id_kind_type_t.Emil Renner Berthing
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.
2020-10-10py/objtype: Handle __dict__ attribute when type has no locals.Jim Mussared
2020-10-10py/objdict: Add mp_const_empty_dict_obj, use it for mp_const_empty_map.Jim Mussared
2020-10-01py/parse: Expose rule-name printing as MICROPY_DEBUG_PARSE_RULE_NAME.Damien George
So it can be enabled without modifying the source. Signed-off-by: Damien George <damien@micropython.org>
2020-10-01py/makeversionhdr.py: Match only git tags which look like versions.Mike Wadsten
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`.
2020-09-25py/objarray.h: Add mp_obj_memoryview_init() helper function.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2020-09-24py/objstr: Make bytes(bytes_obj) return bytes_obj.Iyassou Shimels
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>
2020-09-18py/dynruntime.h: Add mp_import_* and mp_load/store_*.Jim Mussared
These functions already exist in the fun table, and this commit just adds convenience macros for them.
2020-09-18all: Rename absolute time-based functions to include "epoch".Damien George
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>
2020-09-11py/parse: Pass in an mp_print_t to mp_parse_node_print.Damien George
So the output can be redirected if needed. Signed-off-by: Damien George <damien@micropython.org>
2020-09-11py/showbc: Pass in an mp_print_t struct to all bytecode-print functions.Damien George
So the output can be redirected if needed. Signed-off-by: Damien George <damien@micropython.org>
2020-09-11py: Fix handling of NaN in certain pow implementations.stijn
Adds a new compile-time option MICROPY_PY_MATH_POW_FIX_NAN for use with toolchains that don't handle pow-of-NaN correctly.
2020-09-11py/objfloat: Fix handling of negative float to power of nan.Damien George
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>
2020-09-04all: Rename "sys" module to "usys".stijn
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".
2020-09-02all: Bump version to 1.13.v1.13Damien George
Signed-off-by: Damien George <damien@micropython.org>
2020-08-29all: Update Python code to conform to latest black formatting.Damien George
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>
2020-08-22py/mphal.h: Introduce mp_hal_time_ns and implement on various ports.Damien George
This should return a 64-bit value being the number of nanoseconds since 1970/1/1. Signed-off-by: Damien George <damien@micropython.org>
2020-08-22py/runtime: Fix builtin compile() in "single" mode so it prints exprs.Damien George
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>
2020-08-02py/persistentcode: Maintain root ptr list of imported native .mpy code.Damien George
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>
2020-07-25py/compile: Don't await __aiter__ special method in async-for.Jonathan Hogg
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.
2020-07-21py/obj.h: Fix mp_seq_replace_slice_no_grow to use memmove not memcpy.Damien George
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>
2020-06-30py: Rework mp_convert_member_lookup to properly handle built-ins.Damien George
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>
2020-06-30py/obj.h: Make existing MP_TYPE_FLAG_xxx macros sequential.Damien George
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>
2020-06-27py/objcomplex: Add mp_obj_get_complex_maybe for use in complex bin-op.Damien George
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>