summaryrefslogtreecommitdiff
path: root/py
AgeCommit message (Collapse)Author
2021-05-23py/mkrules.cmake: Add MPY_LIB_DIR and BOARD_DIR to makemanifest call.Damien George
So that the FROZEN_MANIFEST option in cmake works the same as make. Signed-off-by: Damien George <damien@micropython.org>
2021-05-20py/emitnative: Fix x86-64 emitter to generate correct 8/16-bit stores.Damien George
Fixes issue #6643. Signed-off-by: Damien George <damien@micropython.org>
2021-05-20py/asmx64: Support use of top 8 regs in src_r64 argument.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-05-18py/nlrx64: Correct the detection of Darwin ABI.Bob Abeles
__APPLE__ tests for an Apple OS and __MACH__ tests that it is based on CMU Mach. Using both tests ensures that just Darwin is recognized.
2021-05-18py/nlraarch64: Add underscore prefix to function symbols for Darwin ABI.Bob Abeles
The proper way to do this is to test for __APPLE__ and __MACH__, where __APPLE__ tests for an Apple OS and __MACH__ tests that it is based on CMU Mach. Using both tests ensures that just Darwin (Apple's open source base for MacOS, iOS, etc.) is recognized. __APPLE__ by itself will test for any Apple OS, which can include older OS 7-9 and any future Apple OS. __MACH__ tests for any OS based on CMU Mach, including Darwin and GNU Hurd. Fixes #7232.
2021-05-18py/objarray: Fix constructing a memoryview from a memoryview.Damien George
Fixes issue #7261. Signed-off-by: Damien George <damien@micropython.org>
2021-05-18py/objarray: Use mp_obj_memoryview_init helper in mp_obj_new_memoryview.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-05-13py/objarray: Implement more/less comparisons for array.stijn
2021-05-13py/objarray: Prohibit comparison of mismatching types.stijn
Array equality is defined as each element being equal but to keep code size down MicroPython implements a binary comparison. This can only be used correctly for elements with the same binary layout though so turn it into an NotImplementedError when comparing types for which the binary comparison yielded incorrect results: types with different sizes, and floating point numbers because nan != nan.
2021-05-12py/mkenv.mk: Don't emit info about BUILD_VERBOSE if it's set.Damien George
If the user sets V or BUILD_VERBOSE then they don't need to see this message. Signed-off-by: Damien George <damien@micropython.org>
2021-05-10py/gc: Make gc_lock_depth have a count per thread.Damien George
This commit makes gc_lock_depth have one counter per thread, instead of one global counter. This makes threads properly independent with respect to the GC, in particular threads can now independently lock the GC for themselves without locking it for other threads. It also means a given thread can run a hard IRQ without temporarily locking the GC for all other threads and potentially making them have MemoryError exceptions at random locations (this really only occurs on MCUs with multiple cores and no GIL, eg on the rp2 port). The commit also removes protection of the GC lock/unlock functions, which is no longer needed when the counter is per thread (and this also fixes the cas where a hard IRQ calling gc_lock() may stall waiting for the mutex). It also puts the check for `gc_lock_depth > 0` outside the GC mutex in gc_alloc, gc_realloc and gc_free, to potentially prevent a hard IRQ from waiting on a mutex if it does attempt to allocate heap memory (and putting the check outside the GC mutex is now safe now that there is a gc_lock_depth per thread). Signed-off-by: Damien George <damien@micropython.org>
2021-05-02py/repl: Autocomplete builtin modules.Artyom Skrobov
Doing "import <tab>" will now complete/list built-in modules. Originally at adafruit#4548 and adafruit#4608 Signed-off-by: Artyom Skrobov <tyomitch@gmail.com>
2021-05-02py/repl: Refactor autocomplete, extracting reusable parts.Artyom Skrobov
Originally at adafruit#4548 Signed-off-by: Artyom Skrobov <tyomitch@gmail.com>
2021-05-02py/repl: Refactor autocomplete to reduce nesting.Artyom Skrobov
Originally at adafruit#4548 Signed-off-by: Artyom Skrobov <tyomitch@gmail.com>
2021-05-02py/repl: Enter four spaces when there are no matches.scottbelden
Originally at adafruit#1859 Signed-off-by: scottbelden <scottabelden@gmail.com>
2021-05-02py/repl: Filter private methods from tab completion.Kathryn Lingel
Anything beginning with "_" will now only be tab-completed if there is already a partial match for such an entry. In other words, entering foo.<tab> will no longer complete/list anything beginning with "_". Originally at adafruit#1850 Signed-off-by: Kathryn Lingel <kathryn@lingel.net>
2021-05-01py/scheduler: Add missing MICROPY_WRAP_MP_SCHED_EXCEPTION usage.Damien George
This was missed in commit 7cbf826a9575e18ce1b7fe11b0f0997509153260. Signed-off-by: Damien George <damien@micropython.org>
2021-04-30py/runtime: Remove commented-out code from mp_deinit().Damien George
These commented-out lines of code have been unused for a long time, so remove them to avoid confusion as to why they are there. mp_obj_dict_free() never existed, this line was converted from mp_map_deinit() and commented out as soon as it was added. The call to mp_map_deinit(mp_loaded_modules_map) was commented in 1a1d11fa32ba043d22995d28cbc039cfa5f3cc46. Fixes issue #3507. Signed-off-by: Damien George <damien@micropython.org>
2021-04-30py/scheduler: Add optional port hook for when something is scheduled.Damien George
So that a port can "wake up" when there is work to do. Signed-off-by: Damien George <damien@micropython.org>
2021-04-30all: Rename mp_keyboard_interrupt to mp_sched_keyboard_interrupt.Damien George
To match mp_sched_exception() and mp_sched_schedule(). Signed-off-by: Damien George <damien@micropython.org>
2021-04-30py/scheduler: Add mp_sched_exception() to schedule a pending exception.Damien George
This helper is added to properly set a pending exception, to mirror mp_sched_schedule(), which schedules a function. Signed-off-by: Damien George <damien@micropython.org>
2021-04-30py/profile: Use mp_handle_pending() to raise pending exception.Damien George
If MICROPY_ENABLE_SCHEDULER is enabled then MP_STATE_VM(sched_state) must be updated after handling the pending exception, which is done by the mp_handle_pending() function. Signed-off-by: Damien George <damien@micropython.org>
2021-04-28py/dynruntime.h: Add mp_obj_get_array() function.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-04-27py: Add option to compile without any error messages at all.Damien George
This introduces a new option, MICROPY_ERROR_REPORTING_NONE, which completely disables all error messages. To be used in cases where MicroPython needs to fit in very limited systems. Signed-off-by: Damien George <damien@micropython.org>
2021-04-23py/objexcept: Support errno attribute on OSError exceptions.Damien George
This commit adds the errno attribute to exceptions, so code can retrieve errno codes from an OSError using exc.errno. The implementation here simply lets `errno` (and the existing `value`) attributes work on any exception instance (they both alias args[0]). This is for efficiency and to keep code size down. The pros and cons of this are: Pros: - more compatible with CPython, less difference to document and learn - OSError().errno will correctly return None, whereas the current way of doing it via OSError().args[0] will raise an IndexError - it reduces code size on most bare-metal ports (because they already have the errno qstr) - for Python code that uses exc.errno the generated bytecode is 2 bytes smaller and more efficient to execute (compared with exc.args[0]); so bytecode loaded to RAM saves 2 bytes RAM for each use of this attribute, and bytecode that is frozen saves 2 bytes flash/ROM for each use - it's easier/shorter to type, and saves 2 bytes of space in .py files that use it (for each use) Cons: - increases code size by 4-8 bytes on minimal ports that don't already have the `errno` qstr - all exceptions now have .errno and .value attributes (a cpydiff test is added to address this) See also #2407. Signed-off-by: Damien George <damien@micropython.org>
2021-04-19all: Bump version to 1.15.v1.15Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-04-12py/runtime: Make sys.modules preallocate to a configurable size.matejcik
This allows configuring the pre-allocated size of sys.modules dict, in order to prevent unwanted reallocations at run-time (3 sys-modules is really not quite enough for a larger project).
2021-04-12py/profile: Resolve name collision with STATIC unset.matejcik
When building with STATIC undefined (e.g., -DSTATIC=), there are two instances of mp_type_code that collide at link time: in profile.c and in builtinevex.c. This patch resolves the collision by renaming one of them.
2021-04-09py/py.cmake: Introduce MICROPY_INC_CORE as a list with core includes.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-04-09py/py.cmake: Move qstr helper code to micropy_gather_target_properties.Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-03-31rp2: Add support for USER_C_MODULES to CMake build system.Phil Howard
The parts that are generic are added to py/ so they can be used by other ports that use CMake. py/usermod.cmake: * Creates a usermod target to hang user C/CXX modules from. * Gathers sources from user C/CXX modules and libs for QSTR scan. ports/rp2/CMakeLists.txt: * Includes py/usermod.cmake. * Links the resulting usermod library to the MicroPython target. py/mkrules.cmake: Add cxxflags to qstr.i.last custom command for CXX modules: * MICROPY_CPP_FLAGS so CXX modules will find includes. * -DNO_QSTR to fix fatal error missing "genhdr/qstrdefs.generated.h". Usage: The rp2 port can be linked against user C modules by running: make USER_C_MODULES=/path/to/module/micropython.cmake CMake will print a list of included modules. Co-authored-by: Graham Sanderson <graham.sanderson@raspberrypi.org> Co-authored-by: Michael O'Cleirigh <michael.ocleirigh@rivulet.ca> Signed-off-by: Phil Howard <phil@pimoroni.com>
2021-03-26py: Rename remaining object types to be of the form mp_type_xxx.Damien George
For consistency with all other object types in the core. Signed-off-by: Damien George <damien@micropython.org>
2021-03-17py/vm: For tracing use mp_printf, and print state when thread enabled.Damien George
mp_printf should be used to print the prefix because it's also used in mp_bytecode_print2 (otherwise, depending on the system, different output streams may be used). Also print the current thread state when threading is enabled to easily see which thread executes what opcode. Signed-off-by: Damien George <damien@micropython.org>
2021-03-11py/nlrx64: Fix typo in comment.Yonatan Goldschmidt
2021-03-11py/nlr: Implement NLR for AArch64.Yonatan Goldschmidt
2021-02-21py/mkrules.cmake: Add MICROPY_QSTRDEFS_PORT to qstr build process.Damien George
This allows a port to specify a custom qstrdefsport.h file, the same as the QSTR_DEFS variable in a Makefile. Signed-off-by: Damien George <damien@micropython.org>
2021-02-21py/mkrules.cmake: Rename QSTR_DEFS variables to QSTRDEFS.Damien George
And also MICROPY_PY_QSTRDEFS to MICROPY_QSTRDEFS_PY. These variables are all related. Signed-off-by: Damien George <damien@micropython.org>
2021-02-16py: Expand lists in core cmake custom commands.Maureen Helm
The core cmake rules use custom commands to invoke qstr processing scripts. For the zephyr port, it's possible that list arguments to these commands may contain generator expressions, therefore we need to expand them properly. Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2021-02-15py,extmod: Add core cmake rule files.Damien George
These allow a port to use cmake natively instead of make. Signed-off-by: Damien George <damien@micropython.org>
2021-02-08py/mpz: Fix overflow of borrow in mpn_div.Damien George
For certain operands to mpn_div, the existing code path for `DIG_SIZE == MPZ_DBL_DIG_SIZE / 2` had a bug in it where borrow could still overflow in the `(x >= *n || *n - x <= borrow)` branch, ie `borrow + x - (mpz_dbl_dig_t)*n` overflows the borrow variable. In such cases the subsequent right-shift of borrow would not bring in the overflow bit, leading to an error in the result. An example division that had overflow when MPZ_DIG_SIZE = 16 is `(2 ** 48 - 1) ** 2 // (2 ** 48 - 1)`. This is fixed in this commit by simplifying the code and handling the low digits of borrow first, and then the upper bits (to shift down) separately. There is no longer a distinction between `DIG_SIZE < MPZ_DBL_DIG_SIZE / 2` and `DIG_SIZE == MPZ_DBL_DIG_SIZE / 2`. This commit also simplifies the second part of the calculation so that borrow does not need to be negated (instead the code just works knowing that borrow is negative and using + instead of - in calculations involving borrow). Fixes #6777. Signed-off-by: Damien George <damien@micropython.org>
2021-02-05py/gc: Change include of stdint.h to stddef.h.Damien George
No std-int types are used in gc.h, but size_t is which needs stddef.h. Signed-off-by: Damien George <damien@micropython.org>
2021-02-04py: Rename WORD_MSBIT_HIGH to MP_OBJ_WORD_MSBIT_HIGH.Damien George
To make it clear it is for mp_obj_t/mp_uint_t "word" types, and to prefix this macro with MP_. Signed-off-by: Damien George <damien@micropython.org>
2021-02-04all: Rename BYTES_PER_WORD to MP_BYTES_PER_OBJ_WORD.Damien George
The "word" referred to by BYTES_PER_WORD is actually the size of mp_obj_t which is not always the same as the size of a pointer on the target architecture. So rename this config value to better reflect what it measures, and also prefix it with MP_. For uses of BYTES_PER_WORD in setting the stack limit this has been changed to sizeof(void *), because the stack usually grows with machine-word sized values (eg an nlr_buf_t has many machine words in it). Signed-off-by: Damien George <damien@micropython.org>
2021-02-04py: Rename BITS_PER_BYTE to MP_BITS_PER_BYTE.Damien George
To give this macro a standard MP_ prefix. Signed-off-by: Damien George <damien@micropython.org>
2021-02-04py: Remove BITS_PER_WORD definition.Damien George
It's only used in one location, to test if << or >> will overflow when shifting mp_uint_t. For such a test it's clearer to use sizeof(lhs_val), which will be valid even if the type of lhs_val changes. Signed-off-by: Damien George <damien@micropython.org>
2021-02-04py/gc: Don't include mpconfig.h and misc.h in gc.h.Xiang Xiao
Because gc.h doesn't reference any symbol from these header files. Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-02-03all: Bump version to 1.14.v1.14Damien George
Signed-off-by: Damien George <damien@micropython.org>
2021-01-31py/makeversionhdr: Honor SOURCE_DATE_EPOCH if present.iTitou
This environment variable, if defined during the build process, indicates a fixed time that should be used in place of "now" when such a time is explicitely referenced. This allows for reproducible builds of micropython. See https://reproducible-builds.org/specs/source-date-epoch/ Signed-off-by: iTitou <moiandme@gmail.com>
2021-01-30py/persistentcode: Introduce MICROPY_PERSISTENT_CODE_SAVE_FILE option.David CARLIER
This should be enabled when the mp_raw_code_save_file function is needed. It is enabled for mpy-cross, and a check for defined(__APPLE__) is added to cover Mac M1 systems.
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.