summaryrefslogtreecommitdiff
path: root/py
AgeCommit message (Collapse)Author
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
2019-12-12py/persistentcode: Make ARM Thumb archs support multiple sub-archs.Damien George
2019-12-12tools/mpy_ld.py: Add new mpy_ld.py tool and associated build files.Damien George
This commit adds a new tool called mpy_ld.py which is essentially a linker that builds .mpy files directly from .o files. A new header file (dynruntime.h) and makefile fragment (dynruntime.mk) are also included which allow building .mpy files from C source code. Such .mpy files can then be dynamically imported as though they were a normal Python module, even though they are implemented in C. Converting .o files directly (rather than pre-linked .elf files) allows the resulting .mpy to be more efficient because it has more control over the relocations; for example it can skip PLT indirection. Doing it this way also allows supporting more architectures, such as Xtensa which has specific needs for position-independent code and the GOT. The tool supports targets of x86, x86-64, ARM Thumb and Xtensa (windowed and non-windowed). BSS, text and rodata sections are supported, with relocations to all internal sections and symbols, as well as relocations to some external symbols (defined by dynruntime.h), and linking of qstrs.
2019-12-12py/nativeglue: Add funcs/types to native glue table for dynamic runtime.Damien George
These allow discovery of symbols by native code that is loaded dynamically.
2019-12-12py/nativeglue: Add new header file with native function table typedef.Damien George
2019-12-12py/persistentcode: Add ability to relocate loaded native code.Damien George
Implements text, rodata and bss generalised relocations, as well as generic qstr-object linking. This allows importing dynamic native modules on all supported architectures in a unified way.
2019-12-09py/objenumerate: Check for valid args in enumerate constructor.Emil Renner Berthing
For the case where MICROPY_CPYTHON_COMPAT is disabled. This fix makes basics/fun_error2.py pass and not crash the interpreter.
2019-11-26py: Remove 3 obsolete commented-out lines from header files.Damien George
2019-11-26py/objstringio: Slightly optimize stringio_copy_on_write for code size.Yonatan Goldschmidt
With the memcpy() call placed last it avoids the effects of registers clobbering. It's definitely effective in non-inlined functions, but even here it is still making a small difference. For example, on stm32, this saves an extra `ldr` instruction to load `o->vstr` after the memcpy() returns.
2019-11-26py/qstr: Raise exception in qstr_from_strn if str to intern is too long.Léa Saviot
The string length being longer than the allowed qstr length can happen in many locations, for example in the parser with very long variable names. Without an explicit check that the length is within range (as done in this patch) the code would exhibit crashes and strange behaviour with truncated strings.