summaryrefslogtreecommitdiff
path: root/py
AgeCommit message (Collapse)Author
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.
2020-04-18all: Fix implicit conversion from double to float.stijn
These are found when building with -Wfloat-conversion.
2020-04-18py/objarray: Fix sign mismatch in comparison.stijn
Found when compiling with clang and -Wsign-compare.
2020-04-18all: Fix implicit floating point promotion.stijn
Initially some of these were found building the unix coverage variant on MacOS because that build uses clang and has -Wdouble-promotion enabled, and clang performs more vigorous promotion checks than gcc. Additionally the codebase has been compiled with clang and msvc (the latter with warning level 3), and with MICROPY_FLOAT_IMPL_FLOAT to find the rest of the conversions. Fixes are implemented either as explicit casts, or by using the correct type, or by using one of the utility functions to handle floating point casting; these have been moved from nativeglue.c to the public API.
2020-04-18Revert "all: Fix implicit casts of float/double, and signed comparison."stijn
This reverts commit a2110bd3fca59df8b16a2b5fe4645a4af30b06ed. There's nothing inherently wrong with it, but upcoming commits will apply similar fixes in a slightly different way.
2020-04-14py: Always give noop defines when MICROPY_ROM_TEXT_COMPRESSION disabled.Damien George
This commit provides a typedef for mp_rom_error_text_t, and a macro define for MP_COMPRESSED_ROM_TEXT, when MICROPY_ROM_TEXT_COMPRESSION is disabled. This simplifies the configuration (it no longer has a special case for MICROPY_ENABLE_DYNRUNTIME) and makes it work for other cases that don't use compression (eg examples/embedding). This commit also ensures MICROPY_ROM_TEXT_COMPRESSION is defined during qstr processing.
2020-04-13py/scope: Add assert to check that low numbered qstrs do fit in uint8_t.Romain Goyet
2020-04-13py/makecompresseddata.py: Don't prefix str with mark if not compressed.Damien George
2020-04-13all: Clean up error strings to use lowercase and change cannot to can't.Damien George
Now that error string compression is supported it's more important to have consistent error string formatting (eg all lowercase English words, consistent contractions). This commit cleans up some of the strings to make them more consistent.
2020-04-13py/scheduler: Add assert that scheduler is locked when unlocking.Jim Mussared
And add a test that shows how this can happen when multiple threads are accessing the scheduler, which fails if atomic sections are not used.
2020-04-13py/scheduler: Fix race in checking scheduler pending state.Jim Mussared
Because the atomic section starts after checking whether the scheduler state is pending, it's possible it can become a different state by the time the atomic section starts. This is especially likely on ports where MICROPY_BEGIN_ATOMIC_SECTION is implemented with a mutex (i.e. it might block), but the race exists regardless, i.e. if a context switch occurs between those two lines.
2020-04-09py/objexcept: Remove optional TimeoutError exception.Damien George
TimeoutError was added back in 077812b2abe3f5e5325194f9694dad7eb38186dd for the cc3200 port. In f522849a4d5a978ac3d322d71a755f75d07e8ce6 the cc3200 port enabled use of it in the socket module aliased to socket.timeout. So it was never added to the builtins. Then it was replaced by OSError(ETIMEDOUT) in 047af9b10bfc6b0ec412f8450c6bec10ab95254b. The esp32 port enables this exception, since the very beginning of that port, but it could never be accessed because it's not in builtins. It's being removed: 1) to not encourage its use; 2) because there are a lot of other OSError subclasses which are not defined at all, and having TimeoutError is a bit inconsistent. Note that ports can add anything to the builtins via MICROPY_PORT_BUILTINS. And they can also define their own exceptions using the MP_DEFINE_EXCEPTION() macro.
2020-04-09py/parse: Remove unnecessary check in const folding for ** operator.Damien George
In this part of the code there is no way to get the ** operator, so no need to check for it. This commit also adds tests for this, and other related, invalid const operations.
2020-04-05all: Use MP_ERROR_TEXT for all error messages.Jim Mussared