summaryrefslogtreecommitdiff
path: root/py
AgeCommit message (Collapse)Author
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.
2019-10-01py: Rework and compress second part of bytecode prelude.Damien George
This patch compresses the second part of the bytecode prelude which contains the source file name, function name, source-line-number mapping and cell closure information. This part of the prelude now begins with a single varible length unsigned integer which encodes 2 numbers, being the byte-size of the following 2 sections in the header: the "source info section" and the "closure section". After decoding this variable unsigned integer it's possible to skip over one or both of these sections very easily. This scheme saves about 2 bytes for most functions compared to the original format: one in the case that there are no closure cells, and one because padding was eliminated.
2019-10-01py: Compress first part of bytecode prelude.Damien George
The start of the bytecode prelude contains 6 numbers telling the amount of stack needed for the Python values and exceptions, and the signature of the function. Prior to this patch these numbers were all encoded one after the other (2x variable unsigned integers, then 4x bytes), but using so many bytes is unnecessary. An entropy analysis of around 150,000 bytecode functions from the CPython standard library showed that the optimal Shannon coding would need about 7.1 bits on average to encode these 6 numbers, compared to the existing 48 bits. This patch attempts to get close to this optimal value by packing the 6 numbers into a single, varible-length unsigned integer via bit-wise interleaving. The interleaving scheme is chosen to minimise the average number of bytes needed, and at the same time keep the scheme simple enough so it can be implemented without too much overhead in code size or speed. The scheme requires about 10.5 bits on average to store the 6 numbers. As a result most functions which originally took 6 bytes to encode these 6 numbers now need only 1 byte (in 80% of cases).
2019-10-01py: Add n_state to mp_code_state_t struct.Damien George
This value is used often enough that it is better to cache it instead of decode it each time.
2019-10-01py/bc: Change mp_code_state_t.exc_sp to exc_sp_idx.Damien George
Change from a pointer to an index, to make space in mp_code_state_t.
2019-10-01py/bc: Remove comments referring to obsolete currently_in_except_block.Damien George
It was made obsolete in 6f9e3ff719917616f163d3d671d6abe9472ba6ff
2019-10-01extmod/modbluetooth: Add low-level Python BLE API.Jim Mussared
2019-10-01py/ringbuf: Add helpers for put16/get16.Jim Mussared
2019-09-26py/persistentcode: Bump .mpy version to 5.Damien George
The bytecode opcodes have changed (there are more, and they have been reordered).
2019-09-26py/nativeglue: Make mp_fun_table fixed size regardless of config.Damien George
So that mpy files with native code will always work correctly, and raise an exception if a feature is used that is not supported by the runtime.
2019-09-26py: Rename MP_QSTR_NULL to MP_QSTRnull to avoid intern collisions.Josh Lloyd
Fixes #5140.
2019-09-26mpy-cross: Set number of registers in nlr_buf_t based on native arch.Damien George
Fixes #5059. Done in collaboration with Jim Mussared.
2019-09-26py/emitnative: Factor sizeof/offsetof calculations to macros.Damien George
2019-09-26py/nlr.h: Factor out constants to specific macros.Damien George
2019-09-26py: Split RAISE_VARARGS opcode into 3 separate ones.Damien George
From the beginning of this project the RAISE_VARARGS opcode was named and implemented following CPython, where it has an argument (to the opcode) counting how many args the raise takes: raise # 0 args (re-raise previous exception) raise exc # 1 arg raise exc from exc2 # 2 args (chained raise) In the bytecode this operation therefore takes 2 bytes, one for RAISE_VARARGS and one for the number of args. This patch splits this opcode into 3, where each is now a single byte. This reduces bytecode size by 1 byte for each use of raise. Every byte counts! It also has the benefit of reducing code size (on all ports except nanbox).
2019-09-26py: Introduce and use constants for multi-opcode sizes.Damien George
2019-09-26py/bc: Replace big opcode format table with simple macro.Damien George
2019-09-26py/bc0: Order opcodes into groups based on their size and format.Damien George
2019-09-26py: Add support for matmul operator @ as per PEP 465.Damien George
To make progress towards MicroPython supporting Python 3.5, adding the matmul operator is important because it's a really "low level" part of the language, being a new token and modifications to the grammar. It doesn't make sense to make it configurable because 1) it would make the grammar and lexer complicated/messy; 2) no other operators are configurable; 3) it's not a feature that can be "dynamically plugged in" via an import. And matmul can be useful as a general purpose user-defined operator, it doesn't have to be just for numpy use. Based on work done by Jim Mussared.
2019-09-26py/compile: Use calculation instead of switch to convert token to op.Damien George
2019-09-26py/parse: Use calculation instead of table to convert token to operator.Damien George
2019-09-26py/lexer: Reorder operator tokens to match corresponding binary ops.Damien George
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.