summaryrefslogtreecommitdiff
path: root/py
AgeCommit message (Collapse)Author
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>
2020-06-27py/emitnative: Implement binary operations for viper uint operands.Damien George
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>
2020-06-27py/asm: Add condition codes for signed comparisons.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2020-06-27py/asm: Add funcs/macros to emit machine code for logical-shift-right.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2020-06-24py/objtype: Support passing in an OrderedDict to type() as the locals.Damien George
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>
2020-06-24py/obj.h: Add public mp_obj_is_dict_or_ordereddict() helper macro.Damien George
And use it in py/objdict.c instead of mp_obj_is_dict_type. Signed-off-by: Damien George <damien@micropython.org>
2020-06-22py/misc.h: Add missing semi-colon in mp_float_union_t for big-endian.Damien George
Fixes issue #6161. Signed-off-by: Damien George <damien@micropython.org>
2020-06-16py/compile: Implement PEP 526, syntax for variable annotations.Damien George
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.
2020-06-16py/grammar.h: Consolidate duplicate sub-rules for :test and =test.Damien George
2020-06-16py/compile: Implement PEP 572, assignment expressions with := operator.Damien George
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.
2020-06-16py/compile: Convert scope test to SCOPE_IS_COMP_LIKE macro.Damien George
This macro can be used elsewhere.
2020-06-14tools/codeformat.py: Remove sizeof fixup.David Lechner
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>
2020-06-10py/obj.h: Clarify comments about mp_map_t is_fixed and is_ordered.Damien George
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.
2020-06-10py/objtype: Use mp_obj_dict_copy() for creating obj.__dict__ attribute.Andrew Leech
The resulting dict is now marked as read-only (is_fixed=1) to enforce the fact that changes to this dict will not be reflected in the class instance. This commit reduces code size by about 20 bytes, and should be more efficient because it creates a direct copy of the dict rather than reinserting all elements.
2020-06-10py/objtype: Add __dict__ attribute for class objects.Andrew Leech
The behavior mirrors the instance object dict attribute where a copy of the local attributes are provided (unless the dict is read-only, then that dict itself is returned, as an optimisation). MicroPython does not support modifying this dict because the changes will not be reflected in the class. The feature is only enabled if MICROPY_CPYTHON_COMPAT is set, the same as the instance version.
2020-06-08py/dynruntime.h: Make mp_obj_str_get_str raise if arg not a str/bytes.Damien George
2020-06-05extmod/modbluetooth: Make modbluetooth event not a bitfield.Jim Mussared
There doesn't appear to be any use for only triggering on specific events, so it's just easier to number them sequentially. This makes them smaller values so they take up only 1 byte in the ringbuf, only 1 byte for the opcode in the bytecode, and makes room for more events. Also add a couple of new event types that need to be implemented (to avoid re-numbering later). And rename _COMPLETE and _STATUS to _DONE for consistency. In the future the "trigger" keyword argument can be reinstated by requiring the user to compute the bitmask, eg: ble.irq(handler, 1 << _IRQ_SCAN_RESULT | 1 << _IRQ_SCAN_DONE)
2020-06-02py/modbuiltins: Fix getattr to work with class raising AttributeError.Damien George
Fixes issue #6089.
2020-05-28py/modsys: Use consistent naming pattern for module-level const objects.David Lechner
This renames a few identifiers to follow the usual naming convention of mp_<module>_<name>. This makes them easier to find, e.g. when grep'ing.
2020-05-28py/ringbuf: Fix compilation with msvc.stijn
Older versions do not have "inline" so fetch the definition from mpconfigport.h.
2020-05-28py/modmath: Work around msvc float bugs in atan2, fmod and modf.stijn
Older implementations deal with infinity/negative zero incorrectly. This commit adds generic fixes that can be enabled by any port that needs them, along with new tests cases.
2020-05-27py/py.mk: Use additional CFLAGS to compile string0.c.Damien George
Otherwise functions like memset might get optimised to call themselves (eg with gcc 10). And provide CFLAGS_BUILTIN so these options can be changed by a port if needed. Fixes issue #6053.
2020-05-14py/nativeglue.h: Rename "setjmp" entry to "setjmp_" to avoid any clash.Damien George
Because some compilers may define setjmp to something. Fixes issue #6032.
2020-05-09py/parse: Make mp_parse_node_extract_list return size_t instead of int.Damien George
Because this function can only return non-negative values, and having the correct return type gives more information to the caller.
2020-05-08py/scheduler: Convert mp_sched_full and mp_sched_num_pending to macros.Damien George
So they are guaranteed to be inlined within functions like mp_sched_schedule which may be located in a special memory region.
2020-05-03py/parse: Support constant folding of power operator for integers.Damien George
Constant expression like "2 ** 3" will now be folded, and the special form "X = const(2 ** 3)" will now compile because the argument to the const is now a constant. Fixes issue #5865.
2020-04-30py/scheduler: Add option to wrap mp_sched_schedule in arbitrary attr.Damien George
So ports can put it in a special memory section if needed.
2020-04-27py/modio: Allow uio.IOBase streams to return errno for read/write error.Damien George
This allows user code that inherits from uio.IOBase to return an errno error code from the user readinto/write function, by returning a negative value. Eg returning -123 means an errno of 123. This is already how the custom ioctl works.
2020-04-27py/stream: Remove mp_stream_errno and use system errno instead.Damien George
This change is made for two reasons: 1. A 3rd-party library (eg berkeley-db-1.xx, axtls) may use the system provided errno for certain errors, and yet MicroPython stream objects that it calls will be using the internal mp_stream_errno. So if the library returns an error it is not known whether the corresponding errno code is stored in the system errno or mp_stream_errno. Using the system errno in all cases (eg in the mp_stream_posix_XXX wrappers) fixes this ambiguity. 2. For systems that have threading the system-provided errno should always be used because the errno value is thread-local. For systems that do not have an errno, the new lib/embed/__errno.c file is provided.
2020-04-27py/objdict: Fix popitem for ordered dicts.Jim Mussared
The popitem method wasn't implemented for ordered dicts and would result in an invalid state. Fixes issue #5956.
2020-04-23all: Format code to add space after C++-style comment start.stijn
Note: the uncrustify configuration is explicitly set to 'add' instead of 'force' in order not to alter the comments which use extra spaces after // as a means of indenting text for clarity.
2020-04-20py/makecompresseddata.py: Make compression deterministic.Damien George
Error string compression is not deterministic in certain cases: it depends on the Python version (whether dicts are ordered by default or not) and probably also the order files are passed to this script, leading to a difference in which words are included in the top 128 most common. The changes in this commit use OrderedDict to keep parsed lines in a known order, and, when computing how many bytes are saved by a given word, it uses the word itself to break ties (which would otherwise be "random").
2020-04-18py/objint: Do not use fpclassify.stijn
For combinations of certain versions of glibc and gcc the definition of fpclassify always takes float as argument instead of adapting itself to float/double/long double as required by the C99 standard. At the time of writing this happens for instance for glibc 2.27 with gcc 7.5.0 when compiled with -Os and glibc 3.0.7 with gcc 9.3.0. When calling fpclassify with double as argument, as in objint.c, this results in an implicit narrowing conversion which is not really correct plus results in a warning when compiled with -Wfloat-conversion. So fix this by spelling out the logic manually.
2020-04-18all: Fix implicit floating point to integer conversions.stijn
These are found when building with -Wfloat-conversion.