summaryrefslogtreecommitdiff
path: root/py
AgeCommit message (Collapse)Author
2017-02-20py/objlist: For list slice assignment, allow RHS to be a tuple or list.Damien George
Before this patch, assigning anything other than a list would lead to a crash. Fixes issue #2886.
2017-02-17py/grammar: Remove unused rule.Damien George
Since the recent changes to string/bytes literal concatenation, this rule is no longer used.
2017-02-17py/lexer: Convert mp_uint_t to size_t where appropriate.Damien George
2017-02-17py: Do adjacent str/bytes literal concatenation in lexer, not compiler.Damien George
It's much more efficient in RAM and code size to do implicit literal string concatenation in the lexer, as opposed to the compiler. RAM usage is reduced because the concatenation can be done right away in the tokeniser by just accumulating the string/bytes literals into the lexer's vstr. Prior to this patch adjacent strings/bytes would create a parse tree (one node per string/bytes) and then in the compiler a whole new chunk of memory was allocated to store the concatenated string, which used more than double the memory compared to just accumulating in the lexer. This patch also significantly reduces code size: bare-arm: -204 minimal: -204 unix x64: -328 stmhal: -208 esp8266: -284 cc3200: -224
2017-02-17py/lexer: Simplify handling of line-continuation error.Damien George
Previous to this patch there was an explicit check for errors with line continuation (where backslash was not immediately followed by a newline). But this check is not necessary: if there is an error then the remaining logic of the tokeniser will reject the backslash and correctly produce a syntax error.
2017-02-17py/lexer: Use strcmp to make keyword searching more efficient.Damien George
Since the table of keywords is sorted, we can use strcmp to do the search and stop part way through the search if the comparison is less-than. Because all tokens that are names are subject to this search, this optimisation will improve the overall speed of the lexer when processing a script. The change also decreases code size by a little bit because we now use strcmp instead of the custom str_strn_equal function.
2017-02-17py/lexer: Move check for keyword to name-tokenising block.Damien George
Keywords only needs to be searched for if the token is a MP_TOKEN_NAME, so we can move the seach to the part of the code that does the tokenising for MP_TOKEN_NAME.
2017-02-17py/lexer: Simplify handling of indenting of very first token.Damien George
2017-02-17py/persistentcode: Bump .mpy version due to change in bytecode.Damien George
2017-02-16py/lexer: Don't generate string representation for period or ellipsis.Damien George
It's not needed.
2017-02-16py/grammar: Group no-compile grammar rules together to shrink tables.Damien George
Grammar rules have 2 variants: ones that are attached to a specific compile function which is called to compile that grammar node, and ones that don't have a compile function and are instead just inspected to see what form they take. In the compiler there is a table of all grammar rules, with each entry having a pointer to the associated compile function. Those rules with no compile function have a null pointer. There are 120 such rules, so that's 120 words of essentially wasted code space. By grouping together the compile vs no-compile rules we can put all the no-compile rules at the end of the list of rules, and then we don't need to store the null pointers. We just have a truncated table and it's guaranteed that when indexing this table we only index the first half, the half with populated pointers. This patch implements such a grouping by having a specific macro for the compile vs no-compile grammar rules (DEF_RULE vs DEF_RULE_NC). It saves around 460 bytes of code on 32-bit archs.
2017-02-16py: De-optimise some uses of mp_getiter, so they don't use the C stack.Damien George
In these cases the heap is anyway used to create a new object so no real need to use the C stack for iterating. It saves a few bytes of code size.
2017-02-16py/compile: Optimise list/dict/set comprehensions to use stack iter.Damien George
2017-02-16py/runtime: Optimise case of identity iterator so it doesn't alloc RAM.Damien George
2017-02-16py: Remove unused "use_stack" argument from for_iter_end emit function.Damien George
2017-02-16py: Optimise storage of iterator so it takes only 4 slots on Py stack.Damien George
2017-02-16py: Make FOR_ITER opcode pop 1+4 slots from the stack when finished.Damien George
The extra 4 slots correspond to the iterator object stored on the stack.
2017-02-16py: Allow bytecode/native to put iter_buf on stack for simple for loops.Damien George
So that the "for x in it: ..." statement can now work without using the heap (so long as the iterator argument fits in an iter_buf structure).
2017-02-16py: Add iter_buf to getiter type method.Damien George
Allows to iterate over the following without allocating on the heap: - tuple - list - string, bytes - bytearray, array - dict (not dict.keys, dict.values, dict.items) - set, frozenset Allows to call the following without heap memory: - all, any, min, max, sum TODO: still need to allocate stack memory in bytecode for iter_buf.
2017-02-16py/vm: Convert mp_uint_t to size_t where appropriate.Damien George
2017-02-16py/objint: Convert mp_uint_t to size_t where appropriate.Damien George
2017-02-16py/objexcept: Convert mp_uint_t to size_t where appropriate.Damien George
2017-02-16py/objclosure: Convert mp_uint_t to size_t where appropriate.Damien George
2017-02-16py/objfun: Convert mp_uint_t to size_t where appropriate.Damien George
2017-02-16py/objarray: Convert mp_uint_t to size_t where appropriate.Damien George
2017-02-16py/objstr: Convert mp_uint_t to size_t (and use int) where appropriate.Damien George
2017-02-16py/objset: Convert mp_uint_t to size_t where appropriate.Damien George
2017-02-16py/objdict: Convert mp_uint_t to size_t where appropriate.Damien George
2017-02-16py/objlist: Convert mp_uint_t to size_t where appropriate.Damien George
2017-02-16py/objtuple: Convert mp_uint_t to size_t where appropriate.Damien George
2017-02-16py/persistentcode: Replace mp_uint_t with size_t where appropriate.Damien George
2017-02-16py/mpz: Change type of "base" args from mp_uint_t to unsigned int.Damien George
2017-02-16py/mpz: Remove obsolete declaration of mpz_as_str_size.Damien George
2017-02-16py/mpz: Convert mp_uint_t to size_t where appropriate.Damien George
2017-02-16py/runtime: Convert mp_uint_t to size_t where appropriate.Damien George
2017-02-15py/vm: Add MICROPY_PY_THREAD_GIL_VM_DIVISOR option.Damien George
This improves efficiency of GIL release within the VM, by only doing the release after a fixed number of jump-opcodes have executed in the current thread.
2017-02-15py/modthread: Use system-provided mutexs for _thread locks.Damien George
It's more efficient using the system mutexs instead of synthetic ones with a busy-wait loop. The system can do proper scheduling and blocking of the threads waiting on the mutex.
2017-02-14py/objtype: Replace non-ASCII single-quote char with ASCII version.Damien George
2017-02-10py/emitbc: Produce correct line number info for large bytecode chunks.Damien George
Previous to this patch, for large chunks of bytecode that originated from a single source-code line, the bytecode-line mapping would generate something like (for 42 bytecode bytes and 1 line): BC_SKIP=31 LINE_SKIP=1 BC_SKIP=11 LINE_SKIP=0 This would mean that any errors in the last 11 bytecode bytes would be reported on the following line. This patch fixes it to generate instead: BC_SKIP=31 LINE_SKIP=0 BC_SKIP=11 LINE_SKIP=1
2017-02-09py/objtype: Implement __delattr__ and __setattr__.dmazzella
This patch implements support for class methods __delattr__ and __setattr__ for customising attribute access. It is controlled by the config option MICROPY_PY_DELATTR_SETATTR and is disabled by default.
2017-02-08py/nlr: Fix execstack builds for ARM.Dave Hylands
It seems that the gcc toolchain on the RaspberryPi likes %progbits instead of @progbits. I verified that %progbits also works under x86, so this should fix #2848 and fix #2842 I verified that unix and mpy-cross both compile on my RaspberryPi and on my x64 machine.
2017-02-08py/map: Change mp_uint_t to size_t where appropriate.Damien George
The internal map/set functions now use size_t exclusively for computing addresses. size_t is enough to reach all of available memory when computing addresses so is the right type to use. In particular, for nanbox builds it saves quite a bit of code size and RAM compared to the original use of mp_uint_t (which is 64-bits on nanbox builds).
2017-02-08py/asmxtensa.h: Explicitly cast args to 32-bits so left-shift is legal.Damien George
For archs that have 16-bit pointers, the asmxtensa.h file can give compiler warnings about left-shift being greater than the width of the type (due to the inline functions in this header file). Explicitly casting the constants to uint32_t stops these warnings.
2017-02-04py/objcomplex: Fix typo in ternary expression.Damien George
This typo actually did the correct thing, but it was very obscure (came about from think in terms of Python's "x if cond else y" expression).
2017-02-03py/objstr: Convert some instances of mp_uint_t to size_t.Damien George
2017-02-03py/mpconfig.h: Move PY_BUILTINS_POW3 config option to diff part of file.Damien George
With so many config options it's good to (at least try to) keep them grouped into logical sections.
2017-02-03py/objstr: Give correct behaviour when passing a dict to %-formatting.Damien George
This patch fixes two main things: - dicts can be printed directly using '%s' % dict - %-formatting should not crash when passed a non-dict to, eg, '%(foo)s'
2017-02-02py: Added optimised support for 3-argument calls to builtin.pow()Nicko van Someren
Updated modbuiltin.c to add conditional support for 3-arg calls to pow() using MICROPY_PY_BUILTINS_POW3 config parameter. Added support in objint_mpz.c for for optimised implementation.
2017-02-03py/objset: Fix inplace binary ops so frozensets are not modified.Damien George
2017-02-03py/objcomplex: Correctly handle case of 0j to power of something.Damien George
0j to the power of negative now raises ZeroDivisionError, and 0j to the power of positive returns 0.