summaryrefslogtreecommitdiffstatshomepage
path: root/py
Commit message (Collapse)AuthorAge
* py: Allow lexer to raise exceptions during construction.Damien George2017-03-14
| | | | | | | | | | | | | | | | | | | | | | | | This patch refactors the error handling in the lexer, to simplify it (ie reduce code size). A long time ago, when the lexer/parser/compiler were first written, the lexer and parser were designed so they didn't use exceptions (ie nlr) to report errors but rather returned an error code. Over time that has gradually changed, the parser in particular has more and more ways of raising exceptions. Also, the lexer never really handled all errors without raising, eg there were some memory errors which could raise an exception (and in these rare cases one would get a fatal nlr-not-handled fault). This patch accepts the fact that the lexer can raise exceptions in some cases and allows it to raise exceptions to handle all its errors, which are for the most part just out-of-memory errors during construction of the lexer. This makes the lexer a bit simpler, and also the persistent code stuff is simplified. What this means for users of the lexer is that calls to it must be wrapped in a nlr handler. But all uses of the lexer already have such an nlr handler for the parser (and compiler) so that doesn't put any extra burden on the callers.
* py/objint_longlong: Implement mp_obj_int_from_bytes_impl().Paul Sokolovsky2017-03-10
| | | | This makes int.from_bytes() work for MICROPY_LONGINT_IMPL_LONGLONG.
* py/nlrx64: Fixes to support Mac OS.Damien George2017-03-08
| | | | | | Two independent fixes: - need to prefix symbols referenced from asm with underscore; - need to undo the C-function prelude.
* py/nlrx86: Add workaround for Zephyr.Paul Sokolovsky2017-03-07
| | | | Actually, this removes -fno-omit-frame-pointer workaround for Zephyr.
* py: Use mp_obj_get_array where sequence may be a tuple or a list.Krzysztof Blazewicz2017-03-07
|
* py/runtime.c: Remove optimization of '*a,=b', it caused a bug.Krzysztof Blazewicz2017-03-07
| | | | | *a, = b should always make a copy of b, instead, before this patch if b was a list it would copy only a reference to it.
* py/modsys: Use MP_SMALL_INT_MAX for sys.maxsize in case of LONGINT_IMPL_NONE.Paul Sokolovsky2017-03-06
| | | | | | INT_MAX used previosly is indeed max value for int, whereas on LP64 platforms, long is used for mp_int_t. Using MP_SMALL_INT_MAX is the correct way to do it anyway.
* py/py.mk: Force nlr files to be compiled with -Os.Damien George2017-03-06
|
* py/nlrx86: Convert from assembler to C file with inline asm.Damien George2017-03-06
|
* py/nlrx64: Convert from assembler to C file with inline asm.Damien George2017-03-06
|
* py/nlrxtensa: Convert from assembler to C file with inline asm.Damien George2017-03-06
| | | | | nlr_jump is a little bit inefficient because it now saves a register to the stack.
* py/nlr.h: Mark nlr_jump_fail as NORETURN.Damien George2017-03-06
|
* py: Move locals/globals dicts to the thread-specific state.Damien George2017-03-06
| | | | | | Each threads needs to have its own private references to its current locals/globals dicts, otherwise functions running within different contexts (eg imported from different files) can behave very strangely.
* py/map: Fix bugs with deletion of elements from OrderedDict.Damien George2017-03-03
| | | | | | | There were 2 bugs, now fixed by this patch: - after deleting an element the len of the dict did not decrease by 1 - after deleting an element searching through the dict could lead to a seg fault due to there being an MP_OBJ_SENTINEL in the ordered array
* py/objarray: Disallow slice-assignment to read-only memoryview.Damien George2017-02-27
| | | | Also comes with a test for this. Fixes issue #2904.
* py/runtime: mp_raise_msg(): Accept NULL argument for message.Paul Sokolovsky2017-02-24
| | | | | | | | In this case, raise an exception without a message. This would allow to shove few code bytes comparing to currently used mp_raise_msg(..., "") pattern. (Actual savings depend on function code alignment used by a particular platform.)
* py/parse: Simplify handling of errors by raising them directly.Damien George2017-02-24
| | | | | | | | | | | | | | | The parser was originally written to work without raising any exceptions and instead return an error value to the caller. But it's now required that a call to the parser be wrapped in an nlr handler, so we may as well make use of that fact and simplify the parser so that it doesn't need to keep track of any memory errors that it had. The parser anyway explicitly raises an exception at the end if there was an error. This patch simplifies the parser by letting the underlying memory allocation functions raise an exception if they fail to allocate any memory. And if there is an error parsing the "<id> = const(<val>)" pattern then that also raises an exception right away instead of trying to recover gracefully and then raise.
* py: Create str/bytes objects in the parser, not the compiler.Damien George2017-02-24
| | | | | | | | | | | | | | | | | | Previous to this patch any non-interned str/bytes objects would create a special parse node that held a copy of the str/bytes data. Then in the compiler this data would be turned into a str/bytes object. This actually lead to 2 copies of the data, one in the parse node and one in the object. The parse node's copy of the data would be freed at the end of the compile stage but nevertheless it meant that the peak memory usage of the parse/compile stage was higher than it needed to be (by an amount equal to the number of bytes in all the non-interned str/bytes objects). This patch changes the behaviour so that str/bytes objects are created directly in the parser and the object stored in a const-object parse node (which already exists for bignum, float and complex const objects). This reduces peak RAM usage of the parse/compile stage, simplifies the parser and compiler, and reduces code size by about 170 bytes on Thumb2 archs, and by about 300 bytes on Xtensa archs.
* py/parse: Allow parser/compiler consts to be bignums.Damien George2017-02-24
| | | | | | | | | | | This patch allows uPy consts to be bignums, eg: X = const(1 << 100) The infrastructure for consts to be a bignum (rather than restricted to small integers) has been in place for a while, ever since constant folding was upgraded to allow bignums. It just required a small change (in this patch) to enable it.
* py/moduerrno: Make list of errno codes configurable.Damien George2017-02-22
| | | | | It's configurable by defining MICROPY_PY_UERRNO_LIST. If this is not defined then a default is provided.
* py/moduerrno: Make uerrno.errorcode dict configurable.Damien George2017-02-22
| | | | | | | | It's configured by MICROPY_PY_UERRNO_ERRORCODE and enabled by default (since that's the behaviour before this patch). Without this dict the lookup of errno codes to strings must use the uerrno module itself.
* py/objlist: For list slice assignment, allow RHS to be a tuple or list.Damien George2017-02-20
| | | | | Before this patch, assigning anything other than a list would lead to a crash. Fixes issue #2886.
* py/grammar: Remove unused rule.Damien George2017-02-17
| | | | | Since the recent changes to string/bytes literal concatenation, this rule is no longer used.
* py/lexer: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-17
|
* py: Do adjacent str/bytes literal concatenation in lexer, not compiler.Damien George2017-02-17
| | | | | | | | | | | | | | | | | | | | | 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
* py/lexer: Simplify handling of line-continuation error.Damien George2017-02-17
| | | | | | | | | 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.
* py/lexer: Use strcmp to make keyword searching more efficient.Damien George2017-02-17
| | | | | | | | | | | | 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.
* py/lexer: Move check for keyword to name-tokenising block.Damien George2017-02-17
| | | | | | 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.
* py/lexer: Simplify handling of indenting of very first token.Damien George2017-02-17
|
* py/persistentcode: Bump .mpy version due to change in bytecode.Damien George2017-02-17
|
* py/lexer: Don't generate string representation for period or ellipsis.Damien George2017-02-16
| | | | It's not needed.
* py/grammar: Group no-compile grammar rules together to shrink tables.Damien George2017-02-16
| | | | | | | | | | | | | | | | | | | | | | 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.
* py: De-optimise some uses of mp_getiter, so they don't use the C stack.Damien George2017-02-16
| | | | | 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.
* py/compile: Optimise list/dict/set comprehensions to use stack iter.Damien George2017-02-16
|
* py/runtime: Optimise case of identity iterator so it doesn't alloc RAM.Damien George2017-02-16
|
* py: Remove unused "use_stack" argument from for_iter_end emit function.Damien George2017-02-16
|
* py: Optimise storage of iterator so it takes only 4 slots on Py stack.Damien George2017-02-16
|
* py: Make FOR_ITER opcode pop 1+4 slots from the stack when finished.Damien George2017-02-16
| | | | The extra 4 slots correspond to the iterator object stored on the stack.
* py: Allow bytecode/native to put iter_buf on stack for simple for loops.Damien George2017-02-16
| | | | | 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).
* py: Add iter_buf to getiter type method.Damien George2017-02-16
| | | | | | | | | | | | | | | 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.
* py/vm: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objint: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objexcept: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objclosure: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objfun: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objarray: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objstr: Convert mp_uint_t to size_t (and use int) where appropriate.Damien George2017-02-16
|
* py/objset: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objdict: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objlist: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|