summaryrefslogtreecommitdiff
path: root/py
AgeCommit message (Collapse)Author
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.
2019-11-26py/builtinimport: Raise exception on empty module name.Léa Saviot
To prevent a crash returning MP_OBJ_NULL. A test is added for this case.
2019-11-21py/compile: Coalesce error message for break/continue outside loop.Petr Viktorin
To reduce code size.
2019-11-21py/ringbuf: Add peek16 method.Jim Mussared
2019-11-13py/objdict: Support ujson.dump() of OrderedDict objects.Andrew Leech
Following CPython, OrderedDict are dumped with the syntax of dict.
2019-11-07py/emitnx86: Make mp_f_n_args table match order of mp_fun_kind_t.Damien George
2019-11-07py/emitnative: Fix typo, REG_PARENT_ARG_RET should be REG_PARENT_RET.Thea Flowers
2019-11-05all: Convert nlr_raise(mp_obj_new_exception_msg(x)) to mp_raise_msg(x).Damien George
This helper function was added a while ago and these are the remaining cases to convert, to save a bit of code size.
2019-11-04py/modsys: Report .mpy version in sys.implementation.Damien George
This commit adds a sys.implementation.mpy entry when the system supports importing .mpy files. This entry is a 16-bit integer which encodes two bytes of information from the header of .mpy files that are supported by the system being run: the second and third bytes, .mpy version, and flags and native architecture. This allows determining the supported .mpy file dynamically by code, and also for the user to find it out by inspecting this value. It's further possible to dynamically detect if the system supports importing .mpy files by `hasattr(sys.implementation, 'mpy')`.
2019-11-04py/persistentcode: Move declarations for .mpy header from .c to .h file.Damien George
2019-11-04py/objgenerator: Allow pend_throw to an unstarted generator.Jim Mussared
Replace the is_running field with a tri-state variable to indicate running/not-running/pending-exception. Update tests to cover the various cases. This allows cancellation in uasyncio even if the coroutine hasn't been executed yet. Fixes #5242
2019-11-04py/objgenerator: Remove globals from mp_obj_gen_instance_t.Jim Mussared
This wasn't necessary as the wrapped function already has a reference to its globals. But it had a dual purpose of tracking whether the function was currently running, so replace it with a bool.
2019-11-01py/nativeglue: Remove unused mp_obj_new_cell from mp_fun_table.Damien George
It has been unused since 9988618e0e0f5c319e31b135d993e22efb593093
2019-10-31py/stream.h: Add MP_STREAM_POLL_NVAL constant.Damien George
2019-10-29py/runtime: Reorder some binary ops so they don't require conditionals.Damien George
runtime0.h is part of the MicroPython ABI so it's simpler if it's independent of config options, like MICROPY_PY_REVERSE_SPECIAL_METHODS. What's effectively done here is to move MP_BINARY_OP_DIVMOD and MP_BINARY_OP_CONTAINS up in the enum, then remove the #if MICROPY_PY_REVERSE_SPECIAL_METHODS conditional. Without this change .mpy files would need to have a feature flag for MICROPY_PY_REVERSE_SPECIAL_METHODS (when embedding native code that uses this enum). This commit has no effect when MICROPY_PY_REVERSE_SPECIAL_METHODS is disabled. With this option enabled this commit reduces code size by about 60 bytes.
2019-10-29extmod: Add VFS littlefs bindings.Damien George
Both LFS1 and LFS2 are supported at the same time.
2019-10-29extmod/vfs_blockdev: Factor out block device interface code.Damien George
2019-10-22powerpc: Add initial port to bare metal PowerPC arch.Michael Neuling
Runs in microwatt (GHDL and FPGA) and qemu. Port done initially by Michael Neuling, with help from Anton Blanchard and Jordan Niethe.
2019-10-22extmod/modbluetooth: Rename module to "ubluetooth".Jim Mussared
For consistency with "umachine". Now that weak links are enabled by default for built-in modules, this should be a no-op, but allows extension of the bluetooth module by user code. Also move registration of ubluetooth to objmodule rather than port-specific.
2019-10-22py/modarray: Rename "array" module to "uarray".Damien George
Following the other modules like ustruct, ucollections. See issues #4370 and #4449.
2019-10-22py: Automatically provide weak links from "foo" to "ufoo" module name.Damien George
This commit implements automatic module weak links for all built-in modules, by searching for "ufoo" in the built-in module list if "foo" cannot be found. This means that all modules named "ufoo" are always available as "foo". Also, a port can no longer add any other weak links, which makes strict the definition of a weak link. It saves some code size (about 100-200 bytes) on ports that previously had lots of weak links. Some changes from the previous behaviour: - It doesn't intern the non-u module names (eg "foo" is not interned), which saves code size, but will mean that "import foo" creates a new qstr (namely "foo") in RAM (unless the importing module is frozen). - help('modules') no longer lists non-u module names, only the u-variants; this reduces duplication in the help listing. Weak links are effectively the same as having a set of symbolic links on the filesystem that is searched last. So an "import foo" will search built-in modules first, then all paths in sys.path, then weak links last, importing "ufoo" if it exists. Thus a file called "foo.py" somewhere in sys.path will still have precedence over the weak link of "foo" to "ufoo". See issues: #1740, #4449, #5229, #5241.
2019-10-22py/objstr: Size-optimise failure path for mp_obj_str_get_buffer.Jim Mussared
These fields are never looked at if the function returns non-zero.
2019-10-21py/mkrules.mk: Add warning/error for invalid frozen config.Jim Mussared
2019-10-21tools/makemanifest.py: Eval relative paths w.r.t. current manifest file.Jim Mussared
When loading a manifest file, e.g. by include(), it will chdir first to the directory of that manifest. This means that all file operations within a manifest are relative to that manifest's location. As a consequence of this, additional environment variables are needed to find absolute paths, so the following are added: $(MPY_LIB_DIR), $(PORT_DIR), $(BOARD_DIR). And rename $(MPY) to $(MPY_DIR) to be consistent. Existing manifests are updated to match.
2019-10-18py/objtype: Add type.__bases__ attribute.Josh Lloyd
Enabled as part of MICROPY_CPYTHON_COMPAT.
2019-10-15tools: Add mechanism to provide a manifest of frozen files.Damien George
This introduces a new build variable FROZEN_MANIFEST which can be set to a manifest listing (written in Python) that describes the set of files to be frozen in to the firmware.
2019-10-15ports: Add new make target "submodules" which inits required modules.Damien George
2019-10-15py/persistentcode: Make .mpy more compact with qstr directly in prelude.Damien George
Instead of encoding 4 zero bytes as placeholders for the simple_name and source_file qstrs, and storing the qstrs after the bytecode, store the qstrs at the location of these 4 bytes. This saves 4 bytes per bytecode function stored in a .mpy file (for example lcd160cr.mpy drops by 232 bytes, 4x 58 functions). And resulting code size is slightly reduced on ports that use this feature.
2019-10-05py: Add new Xtensa-Windowed arch for native emitter.Damien George
Enabled via the configuration MICROPY_EMIT_XTENSAWIN.
2019-10-05py/asmxtensa: Add support for Xtensa with windowed registers.Damien George
Window-specific asm emit functions are added, along with a new macro option GENERIC_ASM_API_WIN.
2019-10-05py/emitnative: Add support for archs that cannot read executable data.Damien George
In which case place the native function prelude in a bytes object, linked from the const_table of that function. An architecture should define N_PRELUDE_AS_BYTES_OBJ to 1 before including py/emitnative.c to emit correct machine code, then enable MICROPY_EMIT_NATIVE_PRELUDE_AS_BYTES_OBJ so the runtime can correctly handle the prelude being in a bytes object.
2019-10-05py/emitnative: Add support for using setjmp with native emitter.Damien George
To enable this feature the N_NLR_SETJMP macro should be set to 1 before including py/emitnative.c.
2019-10-05py/emitnative: Add support for archs with windowed registers.Damien George
Such that args/return regs for the parent are different to args/return regs for child calls. For an architecture to use this feature it should define the REG_PARENT_xxx macros before including py/emitnative.c.
2019-10-04py/runtime: Fix PEP479 behaviour throwing StopIteration into yield from.Damien George
Commit 3f6ffe059f64b3ebc44dc0bbc63452cb8850702b implemented PEP479 but did not catch the case fixed in this commit. Found by coverage analysis, that the VM had uncovered code.
2019-10-04py/vm: Fix handling of unwind jump out of active finally.Damien George
Prior to this commit, when unwinding through an active finally the stack was not being correctly popped/folded, which resulting in the VM crashing for complicated unwinding of nested finallys. This should be fixed with this commit, and more tests for return/break/ continue within a finally have been added to exercise this.
2019-10-04py/makeqstrdefs.py: Remove unused blacklist.Jim Mussared
As of 7d58a197cffa7c0dd3686402d2e381812bb8ddeb, `NULL` should no longer be here because it's allowed (MP_QSTRnull took its place). This entry was preventing the use of MP_QSTR_NULL to mean "NULL" (although this is not currently used). A blacklist should not be needed because it should be possible to intern all strings. Fixes issue #5140.
2019-10-04docs/develop/qstr.rst: Add documentation for string interning.Jim Mussared
2019-10-04py/compile: Disallow 'import *' outside module level.Petr Viktorin
This check follows CPython's behaviour, because 'import *' always populates the globals with the imported names, not locals. Since it's safe to do this (doesn't lead to a crash or undefined behaviour) the check is only enabled for MICROPY_CPYTHON_COMPAT. Fixes issue #5121.
2019-10-01py/bc: Don't include mp_decode_uint funcs when not needed.Damien George
These are now only needed when persistent code is disabled.