summaryrefslogtreecommitdiff
path: root/py
AgeCommit message (Collapse)Author
2020-01-31py/modthread: Fix spelling error in comment.David Lechner
2020-01-30py: Support non-boolean results for equality and inequality tests.Nicko van Someren
This commit implements a more complete replication of CPython's behaviour for equality and inequality testing of objects. This addresses the issues discussed in #5382 and a few other inconsistencies. Improvements over the old code include: - Support for returning non-boolean results from comparisons (as used by numpy and others). - Support for non-reflexive equality tests. - Preferential use of __ne__ methods and MP_BINARY_OP_NOT_EQUAL binary operators for inequality tests, when available. - Fallback to op2 == op1 or op2 != op1 when op1 does not implement the (in)equality operators. The scheme here makes use of a new flag, MP_TYPE_FLAG_NEEDS_FULL_EQ_TEST, in the flags word of mp_obj_type_t to indicate if various shortcuts can or cannot be used when performing equality and inequality tests. Currently four built-in classes have the flag set: float and complex are non-reflexive (since nan != nan) while bytearray and frozenszet instances can equal other builtin class instances (bytes and set respectively). The flag is also set for any new class defined by the user. This commit also includes a more comprehensive set of tests for the behaviour of (in)equality operators implemented in special methods.
2020-01-30py/objtype: Make mp_obj_type_t.flags constants public, moved to obj.h.Damien George
2020-01-29py/mpthread.h: Use strong type for mp_thread_set_state() argument.David Lechner
This modifies the signature of mp_thread_set_state() to use mp_state_thread_t* instead of void*. This matches the return type of mp_thread_get_state(), which returns the same value. `struct _mp_state_thread_t;` had to be moved before `#include <mpthreadport.h>` since the stm32 port uses it in its mpthreadport.h file.
2020-01-27py/nativeglue: Fix typo about where the native fun table enum is.Jim Mussared
2020-01-27py/emitnative: Stop after finding an unwind target.Jim Mussared
The loop searches backwards for a target, but doesn't stop after finding the first result, meaning that it'll always end up at the outermost exception handler.
2020-01-27py/emitnative: Use NULL for pending exception (not None).Jim Mussared
This previously made the native emitter incompatible with the bytecode emitter, and mp_resume (and subsequently mp_obj_generator_resume) expects the bytecode emitter behavior (i.e. throw==NULL).
2020-01-26py: Release GIL during syscalls in reader and writer code.David Lechner
This releases the GIL during POSIX system calls that could block.
2020-01-24py/obj.h: Add and use mp_obj_is_bool() helper.Yonatan Goldschmidt
Commit d96cfd13e3a464862cecffb2718c6286b52c77b0 introduced a regression in testing for bool objects, that such objects were in some cases no longer recognised and bools, eg when using mp_obj_is_type(o, &mp_type_bool), or mp_obj_is_integer(o). This commit fixes that problem by adding mp_obj_is_bool(o). Builds with MICROPY_OBJ_IMMEDIATE_OBJS enabled check if the object is any of the const True or False objects. Builds without it use the old method of ->type checking, which compiles to smaller code (compared with the former mentioned method). Fixes #5538.
2020-01-23py/objexcept: Optimise mp_obj_new_exception[_arg1/_args] functions.Damien George
This reduces code size by 10-70 bytes on all ports (except cc3200 which has no change).
2020-01-23py/objgenerator: Use mp_obj_new_exception_arg1 to make StopIteration.Damien George
2020-01-23py/qstr: Don't include or init qstr_mutex when GIL is enabled.David Lechner
When threads and the GIL are enabled, then the qstr mutex is not needed. The qstr_mutex field is never used in this case because of: #if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL #define QSTR_ENTER() mp_thread_mutex_lock(&MP_STATE_VM(qstr_mutex), 1) #define QSTR_EXIT() mp_thread_mutex_unlock(&MP_STATE_VM(qstr_mutex)) #else #define QSTR_ENTER() #define QSTR_EXIT() #endif So, we can completely remove qstr_mutex everywhere when MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL.
2020-01-23py/gc: Don't include or init gc_mutex when GIL is enabled.David Lechner
When threads and the GIL are enabled, then the GC mutex is not needed. The gc_mutex field is never used in this case because of: #if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL #define GC_ENTER() mp_thread_mutex_lock(&MP_STATE_MEM(gc_mutex), 1) #define GC_EXIT() mp_thread_mutex_unlock(&MP_STATE_MEM(gc_mutex)) #else #define GC_ENTER() #define GC_EXIT() #endif So, we can completely remove gc_mutex everywhere when MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL.
2020-01-22py/pairheap: Add generic implementation of pairing heap data structure.Damien George
2020-01-14py/objint: Add mp_obj_int_get_uint_checked() helper.Yonatan Goldschmidt
Can be used where mp_obj_int_get_checked() will overflow due to the sign-bit solely. This returns an mp_uint_t, so it also verifies the given integer is not negative. Currently implemented only for mpz configurations.
2020-01-12py/mpconfig.h: Define BITS_PER_BYTE only if not already defined.Yonatan Goldschmidt
It's a common macro that is possibly defined in headers of systems/SDKs MicroPython is embedded into.
2020-01-13py/obj: Optimise mp_obj_get_type for immediate objs with repr A and C.Damien George
This function is called often and with immediate objects enabled it has more cases, so optimise it for speed. With this optimisation the runtime is now slightly faster with immediate objects enabled than with them disabled.
2020-01-13py/obj: Add MICROPY_OBJ_IMMEDIATE_OBJS option to reduce code size.Damien George
This option (enabled by default for object representation A, B, C) makes None/False/True objects immediate objects, ie they are no longer a concrete object in ROM but are rather just values, eg None=0x6 for representation A. Doing this saves a considerable amount of code size, due to these objects being widely used: bare-arm: -392 -0.591% minimal x86: -252 -0.170% [incl +52(data)] unix x64: -624 -0.125% [incl -128(data)] unix nanbox: +0 +0.000% stm32: -1940 -0.510% PYBV10 cc3200: -1216 -0.659% esp8266: -404 -0.062% GENERIC esp32: -732 -0.064% GENERIC[incl +48(data)] nrf: -988 -0.675% pca10040 samd: -564 -0.556% ADAFRUIT_ITSYBITSY_M4_EXPRESS Thanks go to @Jongy aka Yonatan Goldschmidt for the idea.
2020-01-13py/obj.h: Redefine qstr object encoding to add immediate obj encoding.Damien George
This commit adjusts the definition of qstr encoding in all object representations by taking a single bit from the qstr space and using it to distinguish between qstrs and a new kind of literal object: immediate objects. In other words, the qstr space is divided in two pieces, one half for qstrs and the other half for immediate objects. There is still enough room for qstr values (29 bits in representation A on a 32-bit architecture, and 19 bits in representation C) and the new immediate objects can be used for things like None, False and True.
2020-01-12py/nativeglue: Use mp_const_X instead of &mp_const_X_obj.Damien George
2020-01-12py/runtime: Move MICROPY_PORT_INIT_FUNC near the end of mp_init().David Lechner
This moves the MICROPY_PORT_INIT_FUNC hook to the end of mp_init(), just before MP_THREAD_GIL_ENTER(), so that everything (in particular the GIL mutex) is intialized before the hook is called. MICROPY_PORT_DEINIT_FUNC is also moved to be symmetric (but there is no functional change there). If a port needs to perform initialisation earlier than MICROPY_PORT_INIT_FUNC then it can do it before calling mp_init().
2020-01-12lib/mp-readline: Add word-based move/delete EMACS key sequences.Yonatan Goldschmidt
This commit adds backward-word, backward-kill-word, forward-word, forward-kill-word sequences for the REPL, with bindings to Alt+F, Alt+B, Alt+D and Alt+Backspace respectively. It is disabled by default and can be enabled via MICROPY_REPL_EMACS_WORDS_MOVE. Further enabling MICROPY_REPL_EMACS_EXTRA_WORDS_MOVE adds extra bindings for these new sequences: Ctrl+Right, Ctrl+Left and Ctrl+W. The features are enabled on unix micropython-coverage and micropython-dev.
2020-01-12py/unicode: Add unichar_isalnum().Yonatan Goldschmidt
2020-01-12py/mkenv.mk: Move usage of 32-bit flags to py.mk.Jim Mussared
This allows ports/variants to configure MICROPY_FORCE_32BIT after including mkenv.mk, but before py.mk.
2020-01-09py: Make mp_obj_get_type() return a const ptr to mp_obj_type_t.Damien George
Most types are in rodata/ROM, and mp_obj_base_t.type is a constant pointer, so enforce this const-ness throughout the code base. If a type ever needs to be modified (eg a user type) then a simple cast can be used.
2019-12-29py/objslice: Inline fetching of slice paramters in str_subscr().Nicko van Someren
To reduce code size.
2019-12-28py/objslice: Add support for indices() method on slice objects.Nicko van Someren
Instances of the slice class are passed to __getitem__() on objects when the user indexes them with a slice. In practice the majority of the time (other than passing it on untouched) is to work out what the slice means in the context of an array dimension of a particular length. Since Python 2.3 there has been a method on the slice class, indices(), that takes a dimension length and returns the real start, stop and step, accounting for missing or negative values in the slice spec. This commit implements such a indices() method on the slice class. It is configurable at compile-time via MICROPY_PY_BUILTINS_SLICE_INDICES, disabled by default, enabled on unix, stm32 and esp32 ports. This commit also adds new tests for slice indices and for slicing unicode strings.
2019-12-28py: Clean up commented-out code and comments about exception hierarchy.Damien George
In CPython, EnvironmentError and IOError are now aliases of OSError so no need to have them listed in the code. OverflowError inherits from ArithmeticError because it's intended to be raised "when the result of an arithmetic operation is too large to be represented" (per CPython docs), and MicroPython aims to match the CPython exception hierarchy.
2019-12-28lib/utils/pyexec: Introduce MICROPY_REPL_INFO, wrap debug prints in it.Yonatan Goldschmidt
For the 3 ports that already make use of this feature (stm32, nrf and teensy) this doesn't make any difference, it just allows to disable it from now on. For other ports that use pyexec, this decreases code size because the debug printing code is dead (it can't be enabled) but the compiler can't deduce that, so code is still emitted.
2019-12-27py/obj.h: Use 32-bit shift in MP_OBJ_NEW_QSTR calc for obj-repr D.Damien George
The qst value is always small enough to fit in 31-bits (even less) and using a 32-bit shift rather than a 64-bit shift reduces code size by about 300 bytes.
2019-12-27py/objstr: Don't use inline GET_STR_DATA_LEN for object-repr D.Damien George
Changing to use the helper function mp_obj_str_get_data_no_check() reduces code size of nan-boxing builds by about 1000 bytes.
2019-12-27py/objobject: Fix __setattr__/__delattr__ to build in nanbox mode.Damien George
2019-12-27py: Introduce MP_ROM_FALSE/MP_ROM_TRUE for ROM to refer to bool objects.Damien George
This helps to prevent mistakes, and allows easily changing the ROM value of False/True if needed.
2019-12-27py: Introduce MP_ROM_NONE macro for ROM to refer to None object.Damien George
This helps to prevent mistakes, and allows easily changing the ROM value of None if needed.
2019-12-27py/objsingleton: Use mp_generic_unary_op for singleton objects.Damien George
So these types more closely match NoneType, eg they can be hashed, like in CPython.
2019-12-27py/runtime: Don't allocate iter buf for user-defined types.Damien George
A user-defined type that defines __iter__ doesn't need any memory to be pre-allocated for its iterator (because it can't use such memory). So optimise for this case by not allocating the iter-buf.
2019-12-27py/asmx86: Remove unused 5th argument facility.Damien George
In commit 71a3d6ec3bd02c5bd13334537e1bd146bb643bad mp_setup_code_state was changed from a 5-arg function to a 4-arg function, and at that point 5-arg calls in native code were no longer needed. See also commit 4f9842ad80c235188955fd83317f715033a596c0.
2019-12-27py/asmx86: Fix stack to be 16-byte aligned for entry and sub-call.Damien George
2019-12-23py/nlrx86: Silence possible warnings about unused nlr argument.Damien George
2019-12-21py/objobject: Add object.__delattr__ function.Yonatan Goldschmidt
Similar to object.__setattr__.
2019-12-21py/objobject: Add object.__setattr__ function.Yonatan Goldschmidt
Allows assigning attributes on class instances that implement their own __setattr__. Both object.__setattr__ and super(A, b).__setattr__ will work with this commit.
2019-12-20py/obj.h: Remove comments about additional mp_buffer_info_t entries.Damien George
These entries are unlikely to be needed, so remove them to clean up the struct definition.
2019-12-20py: Remove commented-out debug printf's from emitbc and objlist.Damien George
Any debugging prints should use a macro like DEBUG_printf.
2019-12-20all: Bump version to 1.12.v1.12Damien George
2019-12-20py/profile: Fix debug opcode decoding of MP_BC_RAISE_xxx opcodes.Damien George
2019-12-20py/vm: Fix comment to refer to MP_BC_RAISE_OBJ instead of RAISE_VARARGS.Damien George
2019-12-17py/persistentcode: Move loading of rodata/bss to before obj/raw-code.Damien George
This makes the loading of viper-code-with-relocations a bit neater and easier to understand, by treating the rodata/bss like a special object to be loaded into the constant table (which is how it behaves).
2019-12-13py/dynruntime: Implement uint new/get, mp_obj_len and mp_obj_subscr.Damien George
2019-12-12py/dynruntime: Add support for float API to make/get floats.Damien George
We don't want to add a feature flag to .mpy files that indicate float support because it will get complex and difficult to use. Instead the .mpy is built using whatever precision it chooses (float or double) and the native glue API will convert between this choice and what the host runtime actually uses.
2019-12-12py/nativeglue: Add float new/get functions with both single and double.Damien George