summaryrefslogtreecommitdiff
path: root/py
AgeCommit message (Collapse)Author
2019-09-18py/persistentcode: Enable persistent code saving for Windows ports.stijn
2019-09-12py/mkrules.mk: Add QSTR_GLOBAL_REQUIREMENTS variable for qstr auto-gen.Damien George
2019-09-10py/vm: Factor cached map lookup code to inline function.Damien George
To reduce code duplication and allow to more easily modify this function.
2019-09-05py/mkenv.mk: Add GDB variable.Damien George
2019-09-02py/bc: Fix size calculation of UNWIND_JUMP opcode in mp_opcode_format.Damien George
Prior to this patch mp_opcode_format would calculate the incorrect size of the MP_BC_UNWIND_JUMP opcode, missing the additional byte. But, because opcodes below 0x10 are unused and treated as bytes in the .mpy load/save and freezing code, this bug did not show any symptoms, since nested unwind jumps would rarely (if ever) reach a depth of 16 (so the extra byte of this opcode would be between 0x01 and 0x0f and be correctly loaded/saved/frozen simply as an undefined opcode). This patch fixes this bug by correctly accounting for the additional byte. .
2019-09-02py/binary: Change mp_uint_t to size_t for index, size, align args.Damien George
Reduces code size for nan-box builds, otherwise changes nothing.
2019-09-02py/modstruct: Fix struct.pack_into with unaligned offset of native type.Damien George
Following the same fix for unpack.
2019-09-02py/modstruct: Fix struct.unpack with unaligned offset of native type.Tom McDermott
With this patch alignment is done relative to the start of the buffer that is being unpacked, not the raw pointer value, as per CPython. Fixes issue #3314.
2019-08-31py/objtuple: Allow compatible subclasses of tuple in mp_obj_tuple_get.Jeff Epler
As part of this patch a private macro mp_obj_is_tuple_compatible is introduced to encapsulate the check, which is used in two locations. Fixes #5005.
2019-08-30py/profile: Add debugging for sys.settrace feature.Milan Rossa
2019-08-30py: Integrate sys.settrace feature into the VM and runtime.Milan Rossa
This commit adds support for sys.settrace, allowing to install Python handlers to trace execution of Python code. The interface follows CPython as closely as possible. The feature is disabled by default and can be enabled via MICROPY_PY_SYS_SETTRACE.
2019-08-30py/profile: Add initial implementation of sys.settrace feature.Milan Rossa
2019-08-30py/bc: Factor out code to get bytecode line number info into new func.Damien George
2019-08-30py/compile: Improve the line numbering precision for lambdas.Damien George
Prior to this patch the line number for a lambda would be "line 1" if the body of the lambda contained only a simple expression (with no line number stored in the parse node). Now the line number is always reported correctly.
2019-08-28py: Add global default_emit_opt variable to make emit kind persistent.Damien George
mp_compile no longer takes an emit_opt argument, rather this setting is now provided by the global default_emit_opt variable. Now, when -X emit=native is passed as a command-line option, the emitter will be set for all compiled modules (included imports), not just the top-level script. In the future there could be a way to also set this variable from a script. Fixes issue #4267.
2019-08-28py/vm: Don't add traceback info for exceptions that are re-raised.Damien George
With this patch exceptions that are re-raised have improved tracebacks (less confusing, match CPython), and it makes re-raise slightly more efficient (in time and RAM) because they no longer need to add a traceback. Also general VM performance is not measurably affected. Partially fixes issue #2928.
2019-08-28py/vm: Don't add traceback info for exc's propagated through a finally.Damien George
With this patch exception tracebacks that go through a finally are improved (less confusing, match CPython), and it makes finally's slightly more efficient (in time and RAM) because they no longer need to add a traceback. Partially fixes issue #2928.
2019-08-27py/py.mk: Remove trailing spaces at end of line.Damien George
2019-08-22py/vm: Shorten error message for not-implemented opcode.Damien George
It's really an opcode that's not implemented, so use "opcode" instead of "byte code". And remove the redundant "not implemented" text because that is already implied by the exception type. There's no need to have a long error message for an exception that is almost never encountered. Saves about 20 bytes of code size on most ports.
2019-08-22py/bc0.h: Add comment that MP_BC_MAKE_CLOSURE/_DEFARGS take extra byte.Damien George
2019-08-22py/objgenerator: Move defn of mp_const_GeneratorExit_obj here.Damien George
Because the mp_obj_exception_t type is now globally available.
2019-08-22py/runtime: Remove obsolete comment about mp_parse_compile_execute.Damien George
mp_locals_get/set and mp_globals_get/set are now static-inline functions so this comment is no longer correct.
2019-08-22py/emitbc: Make all emit_write_bytecode_* funcs take a stack_adj arg.Damien George
This factoring of code gives significant code-size savings: bare-arm: -456 -0.682% minimal x86: -844 -0.547% unix x64: -472 -0.095% unix nanbox: -1348 -0.303% stm32: -472 -0.130% PYBV10 cc3200: -448 -0.242% esp8266: -708 -0.108% esp32: -400 -0.036% GENERIC nrf: -520 -0.356% pca10040 samd: -456 -0.448% ADAFRUIT_ITSYBITSY_M4_EXPRESS
2019-08-22py/emitbc: Rewrite switch in load_const_tok to reduce code size.Damien George
2019-08-19py/compile: Improve the line numbering precision for comprehensions.Milan Rossa
The line number for comprehensions is now always reported as the correct global location in the script, instead of just "line 1".
2019-08-19extmod/modure: Make regex dump-code debugging feature optional.Damien George
Enabled via MICROPY_PY_URE_DEBUG, disabled by default (but enabled on unix coverage build). This is a rarely used feature that costs a lot of code (500-800 bytes flash). Debugging of regular expressions can be done offline with other tools.
2019-08-19py/nlr: Use MP_UNREACHABLE at the end of arch-specific nlr_jump funcs.Damien George
Recent versions of gcc perform optimisations which can lead to the following code from the MP_NLR_JUMP_HEAD macro being omitted: top->ret_val = val; \ MP_NLR_RESTORE_PYSTACK(top); \ *_top_ptr = top->prev; \ This is noticeable (at least) in the unix coverage on x86-64 built with gcc 9.1.0. This is because the nlr_jump function is marked as no-return, so gcc deduces that the above code has no effect. Adding MP_UNREACHABLE tells the compiler that the asm code may branch elsewhere, and so it cannot optimise away the code.
2019-08-19py: Introduce MP_UNREACHABLE macro to annotate unreachable code.Damien George
And use it to replace the same pattern at the end of nlrthumb.c:nlr_jump.
2019-08-17py/modmath: Implement math.isclose() for non-complex numbers.stijn
As per PEP 485, this function appeared in for Python 3.5. Configured via MICROPY_PY_MATH_ISCLOSE which is disabled by default, but enabled for the ports which already have MICROPY_PY_MATH_SPECIAL_FUNCTIONS enabled.
2019-08-15py/objarray: Fix amount of free space in array when doing slice assign.Damien George
Prior to this patch the amount of free space in an array (including bytearray) was not being maintained correctly for the case of slice assignment which changed the size of the array. Under certain cases (as encoded in the new test) it was possible that the array could grow beyond its allocated memory block and corrupt the heap. Fixes issue #4127.
2019-08-15py: Implement new sys.atexit feature.Milan Rossa
This patch implements a new sys.atexit function which registers a function that is later executed when the main script ends. It is configurable via MICROPY_PY_SYS_ATEXIT, disabled by default. This is not compliant with CPython, rather it can be used to implement a CPython compatible "atexit" module if desired (similar to how sys.print_exception can be used to implement functionality of the "traceback" module).
2019-08-06py/showbc: Fix off-by-one when showing address of unknown opcode.Milan Rossa
2019-08-06py: Allow to pass in read-only buffers to viper and inline-asm funcs.Damien George
Fixes #4936.
2019-07-31py/modio: Call mp_import_name to do resource stream import.Paul m. p. P
So code is not duplicated and it can take advantage of __import__ being overridden.
2019-07-31py/runtime: Allow to override builtins.__import__ with Python func.Paul m. p. P
This patch adds a simple but powerful hook into the import system, in a CPython compatible way, by allowing to override builtins.__import__. This does introduce some overhead to all imports but it's minor: - the dict lookup of __import__ is bypassed if there are no modifications to the builtins module (which is the case at start up); - imports are not performance critical, usually done just at the start of a script; - compared to how much work is done in an import, looking up a value in a dict is a relatively small additional piece of work.
2019-07-31py/builtinimport: Populate __file__ when importing frozen or mpy files.Paul m. p. P
Note that bytecode already includes the source filename as a qstr so there is no additional memory used by the interning operation here.
2019-07-30py/objdict: Quote non-string types when used as keys in JSON output.Eric Poulsen
JSON requires that keys of objects be strings. CPython will therefore automatically quote simple types (NoneType, bool, int, float) when they are used directly as keys in JSON output. To prevent subtle bugs and emit compliant JSON, MicroPython should at least test for such keys so they aren't silently let through. Then doing the actual quoting is a similar cost to raising an exception, so that's what is implemented by this patch. Fixes issue #4790.
2019-07-25py/sequence: Fix grammar in comment about equality.Yonatan Goldschmidt
2019-07-17py/objstringio: Guard bytesio_stream_p struct w/ MICROPY_PY_IO_BYTESIO.Paul m. p. P
It's static and can lead to a compilation warning/error when MICROPY_PY_IO_BYTESIO is disabled.
2019-07-17py/scheduler: Rename sched_stack to sched_queue.Jim Mussared
Behaviour was changed from stack to queue in 8977c7eb581f5d06500edb1ea29aea5cbda04f28, and this updates variable names to match. Also updates other references (docs, error messages).
2019-07-12py/makeqstrdata.py: Allow using \r\n as a qstr if a port requires it.Paul m. p. P
2019-07-12py/asmarm: Use __builtin___clear_cache instead of __clear_cache.David Lechner
__clear_cache causes a compile error when using clang. Instead use __builtin___clear_cache which is available under both gcc and clang. Also replace tabs with spaces in this section of code (introduced by a previous commit).
2019-07-09py/objgenerator: Add missing #if guard for PY_GENERATOR_PEND_THROW.Laurens Valk
Without it, gen_instance_pend_throw_obj is defined but not used when MICROPY_PY_GENERATOR_PEND_THROW is set to 0.
2019-07-03py/nlrthumb: Check __thumb2__ instead of __ARM_ARCH_6M__.David Lechner
This fixes compiling for older architectures (e.g. armv5tej). According to [1], the limit of R0-R7 for the STR and LDR instructions is tied to the Thumb instruction set and not any specific processor architectures. [1]: http://www.keil.com/support/man/docs/armasm/armasm_dom1361289906890.htm
2019-07-03py/asmarm: Use __clear_cache on Linux/GCC when creating new asm code.David Lechner
Comes from https://community.arm.com/developer/ip-products/processors/b/processors-ip-blog/posts/caches-and-self-modifying-code This fixes a crash when running MicroPython using qemu-arm.
2019-07-01py/persistentcode: Ensure prelude_offset is always initialised.Paul m. p. P
2019-07-01lib/utils/sys_stdio_mphal: Add support to poll sys.stdin and sys.stdout.Damien George
A port must provide the following function for this to work: uintptr_t mp_hal_stdio_poll(uintptr_t poll_flags);
2019-06-28py/persistentcode: Fix compilation with load and save both enabled.Jun Wu
With both MICROPY_PERSISTENT_CODE_SAVE and MICROPY_PERSISTENT_CODE_LOAD enabled the code fails to compile, due to undeclared 'n_obj'. If MICROPY_EMIT_NATIVE is disabled there are more errors due to the use of undefined fields in mp_raw_code_t. This patch fixes such compilation by avoiding undefined fields. MICROPY_EMIT_NATIVE was changed to MICROPY_EMIT_MACHINE_CODE in this file to match the mp_raw_code_t definition.
2019-06-28py: Define EMIT_MACHINE_CODE as EMIT_NATIVE || EMIT_INLINE_ASM.Jun Wu
The combination MICROPY_EMIT_NATIVE || MICROPY_EMIT_INLINE_ASM is used in many places, so define a new macro for it.
2019-06-25py/mkrules.mk: Use $(CPP) not $(CC) -E for preprocessor rule.Paul m. p. P