summaryrefslogtreecommitdiff
path: root/py
AgeCommit message (Collapse)Author
2017-07-24py/mperrno: Allow mperrno.h to be correctly included before other hdrs.Damien George
Before this patch the mperrno.h file could be included and would silently succeed with incorrect config settings, because mpconfig.h was not yet included.
2017-07-24py/py.mk: Make berkeley-db C-defs apply only to relevant source files.Damien George
Otherwise they can interfere (eg redefinition of "abort") with other source files in a given uPy port.
2017-07-21py/builtinevex: Add typechecking of globals/locals args to eval/exec.Tom Collins
2017-07-19all: Remove trailing spaces, per coding conventions.Damien George
2017-07-18py/modmicropython: Cast stack_limit value so it prints correctly.Damien George
Without this cast the print will give a wrong result on nan-boxing builds.
2017-07-18py/asmx64: Support moving a 64-bit immediate to one of top 8 registers.Damien George
If constants (eg mp_const_none_obj) are placed in very high memory locations that require 64-bits for the pointer then the assembler must be able to emit instructions to move such pointers to one of the top 8 registers (ie r8-r15).
2017-07-18py/vm: Make n_state variable local to just set-up part of VM.Damien George
It's not used anywhere else in the VM loop, and clashes with (is shadowed by) the n_state variable that's redeclared towards the end of the mp_execute_bytecode function. Code size is unchanged.
2017-07-18all: Unify header guard usage.Alexander Steffen
The code conventions suggest using header guards, but do not define how those should look like and instead point to existing files. However, not all existing files follow the same scheme, sometimes omitting header guards altogether, sometimes using non-standard names, making it easy to accidentally pick a "wrong" example. This commit ensures that all header files of the MicroPython project (that were not simply copied from somewhere else) follow the same pattern, that was already present in the majority of files, especially in the py folder. The rules are as follows. Naming convention: * start with the words MICROPY_INCLUDED * contain the full path to the file * replace special characters with _ In addition, there are no empty lines before #ifndef, between #ifndef and one empty line before #endif. #endif is followed by a comment containing the name of the guard macro. py/grammar.h cannot use header guards by design, since it has to be included multiple times in a single C file. Several other files also do not need header guards as they are only used internally and guaranteed to be included only once: * MICROPY_MPHALPORT_H * mpconfigboard.h * mpconfigport.h * mpthreadport.h * pin_defs_*.h * qstrdefs*.h
2017-07-12py/gc: Refactor assertions in gc_free function.Damien George
gc_free() expects either NULL or a valid pointer into the heap, so the checks for a valid pointer can be turned into assertions.
2017-07-09py/compile: Fix enum variable declaration.Damien George
2017-07-07py/objgenerator: Allow to hash generators and generator instances.Damien George
Adds nothing to the code size, since it uses existing empty slots in the type structures.
2017-07-07py,extmod: Some casts and minor refactors to quiet compiler warnings.Tom Collins
2017-07-05py/compile: Use switch-case to match token and operator.Krzysztof Blazewicz
Reduces code size.
2017-07-05py/compile: Combine arith and bit-shift ops into 1 compile routine.Krzysztof Blazewicz
This refactoring saves code space.
2017-07-04py/repl: Change mp_uint_t to size_t in repl helpers.Damien George
2017-07-04py: Change mp_uint_t to size_t in builtins code.Damien George
2017-07-04py/objdict: Factorise dict accessor helper to reduce code size.Damien George
Code size change in bytes for this patch is: bare-arm: -72 minimal x86: -48 unix x64: -32 unix nanbox: -120 stmhal: -68 cc3200: -64 esp8266: -56
2017-07-04py/makeversionhdr.py: Update to parse new release line in docs/conf.py.Damien George
The line in docs/conf.py with the release/version number was recently changed and this patch makes the makeversionhdr.py script work again.
2017-07-04py/modmath: Check for zero division in log with 2 args.Damien George
2017-07-04py/vm: Make "if" control flow more obvious in YIELD_FROM opcode.Damien George
2017-07-04py/objstr: Remove unnecessary "sign" variable in formatting code.Damien George
2017-07-04py/runtime: Mark m_malloc_fail() as NORETURN.Damien George
2017-07-04py/binary: Add missing "break" statements.Damien George
2017-07-02py/objstr: Move uPy function wrappers to just after the C function.Damien George
This matches the coding/layout style of all the other objects.
2017-06-30py/mpprint: Remove unreachable check for neg return of mp_format_float.Damien George
2017-06-29py/objnamedtuple: Simplify and remove use of alloca building namedtuple.Damien George
Prior to this patch there were 2 paths for creating the namedtuple, one for when no keyword args were passed, and one when there were keyword args. And alloca was used in the keyword-arg path to temporarily create the array of elements for the namedtuple, which would then be copied to a heap-allocated object (the namedtuple itself). This patch simplifies the code by combining the no-keyword and keyword paths, and removing the need for the alloca by constructing the namedtuple on the heap before populating it. Heap usage in unchanged, stack usage is reduced, use of alloca is removed, and code size is not increased and is actually reduced by between 20-30 bytes for most ports.
2017-06-28py/builtinimport: Remove unreachable code for relative imports.Damien George
The while-loop that calls chop_component will guarantee that level==-1 at the end of the loop. Hence the code following it is unnecessary. The check for p==this_name will catch imports that are beyond the top-level, and also covers the case of new_mod_q==MP_QSTR_ (equivalent to new_mod_l==0) so that check is removed. There is also a new check at the start for level>=0 to guard against __import__ being called with bad level values.
2017-06-28py/frozenmod.h: Add missing header guardsAlexander Steffen
2017-06-26py/mpconfig.h: Remove spaces in "Micro Python" and remove blank line.Damien George
2017-06-22py/compile: Optimise emitter label indices to save a word of heap.Damien George
Previous to this patch, a label with value "0" was used to indicate an invalid label, but that meant a wasted word (at slot 0) in the array of label offsets. This patch adjusts the label indices so the first one starts at 0, and the maximum value indicates an invalid label.
2017-06-22py/compile: Fix bug with break/continue in else of optimised for-range.Damien George
This patch fixes a bug whereby the Python stack was not correctly reset if there was a break/continue statement in the else black of an optimised for-range loop. For example, in the following code the "j" variable from the inner for loop was not being popped off the Python stack: for i in range(4): for j in range(4): pass else: continue This is now fixed with this patch.
2017-06-15py/objint: In to_bytes(), allow length arg to be any int and check sign.Damien George
2017-06-15py/objint: Support "big" byte-order in int.to_bytes().Damien George
2017-06-15all: Make more use of mp_raise_{msg,TypeError,ValueError} helpers.Damien George
2017-06-14py/compile: Raise SyntaxError if positional args are given after */**.Damien George
In CPython 3.4 this raises a SyntaxError. In CPython 3.5+ having a positional after * is allowed but uPy has the wrong semantics and passes the arguments in the incorrect order. To prevent incorrect use of a function going unnoticed it is important to raise the SyntaxError in uPy, until the behaviour is fixed to follow CPython 3.5+.
2017-06-14py/modthread: Raise RuntimeError in release() if lock is not acquired.Damien George
2017-06-13py/formatfloat: Fix number of digits and exponent sign when rounding.Damien George
This patch fixes 2 things when printing a floating-point number that requires rounding up of the mantissa: - retain the correct precision; eg 0.99 becomes 1.0, not 1.00 - if the exponent goes from -1 to 0 then render it as +0, not -0
2017-06-09py/objstringio: If created from immutable object, follow copy on write policy.Paul Sokolovsky
Don't create copy of immutable object's contents until .write() is called on BytesIO.
2017-06-09py/makeqstrdefs.py: Make script run correctly with Python 2.6.Damien George
2017-06-09py: Provide mp_decode_uint_skip() to help reduce stack usage.Damien George
Taking the address of a local variable leads to increased stack usage, so the mp_decode_uint_skip() function is added to reduce the need for taking addresses. The changes in this patch reduce stack usage of a Python call by 8 bytes on ARM Thumb, by 16 bytes on non-windowing Xtensa archs, and by 16 bytes on x86-64. Code size is also slightly reduced on most archs by around 32 bytes.
2017-06-08py/modsys: Allow to compile with obj-repr D and PY_ATTRTUPLE disabled.Damien George
2017-06-08py/objstr: Allow to compile with obj-repr D, and unicode disabled.Damien George
2017-06-08py/persistentcode: Allow to compile with complex numbers disabled.Damien George
2017-06-04extmod/modlwip: Fix error codes for duplicate calls to connect().Paul Sokolovsky
If socket is already connected, POSIX requires returning EISCONN. If connection was requested, but not yet complete (for non-blocking socket), error code is EALREADY. http://pubs.opengroup.org/onlinepubs/7908799/xns/connect.html
2017-06-02py/objstr: Catch case of negative "maxsplit" arg to str.rsplit().Damien George
Negative values mean no limit on the number of splits so should delegate to the .split() method.
2017-06-01py/modbuiltins: Add core-provided version of input() function.Damien George
The implementation is taken from stmhal/input.c, with code added to handle ctrl-C. This built-in is controlled by MICROPY_PY_BUILTINS_INPUT and is disabled by default. It uses readline() to capture input but this can be overridden by defining the mp_hal_readline macro.
2017-05-29various: Spelling fixesVille Skyttä
2017-05-26py/objstringio: Catch mp_uint_t overflow of stream position in write().Tom Collins
2017-05-26py/mkrules.mk: Fix auto-qstr generation when "make -B" is used.Damien George
For make v3.81, using "make -B" can set $? to empty and in this case the auto-qstr generation needs to pass all args (ie $^) to cpp. The previous fix for this (which was removed in 23a693ec2d8c2a194f61482dc0e1adb070fb6ad4) used if statements in the shell command, which gave very long lines that didn't work on certain systems (eg cygwin). The fix in this patch is to use an $if(...) expression, which will evaluate to $? (only newer prerequisites) if it's non empty, otherwise it will use $^ (all prerequisites).
2017-05-25py/emitbc: Fix bug with BC emitter computing Python stack size.Damien George
Previous to this patch the mp_emit_bc_adjust_stack_size function would adjust the current stack size but would not increase the maximum stack size if the current size went above it. This meant that certain Python code (eg a try-finally block with no statements inside it) would not have enough Python stack allocated to it. This patch fixes the problem by always checking if the current stack size goes above the maximum, and adjusting the latter if it does.