summaryrefslogtreecommitdiffstatshomepage
path: root/py
Commit message (Collapse)AuthorAge
...
| * py/objtype: Use size_t where appropriate, instead of mp_uint_t or uint.Damien George2017-03-24
| |
| * py/modbuiltins: Allow round() to return a big int if necessary.Damien George2017-03-24
| | | | | | | | | | | | | | Previous to this patch, if the result of the round function overflowed a small int, or was inf or nan, then a garbage value was returned. With this patch the correct big-int is returned if necessary and exceptions are raised for inf or nan.
| * py/modbuiltins: For round() builtin use nearbyint instead of round.Damien George2017-03-24
| | | | | | | | | | | | | | | | | | | | | | | | | | | | The C nearbyint function has exactly the semantics that Python's round() requires, whereas C's round() requires extra steps to handle rounding of numbers half way between integers. So using nearbyint reduces code size and potentially eliminates any source of errors in the handling of half-way numbers. Also, bare-metal implementations of nearbyint can be more efficient than round, so further code size is saved (and efficiency improved). nearbyint is provided in the C99 standard so it should be available on all supported platforms.
| * py/objint: Handle special case of -0 when classifying fp as int.Damien George2017-03-23
| | | | | | | | | | Otherwise -0.0 is classified as a bigint, which for builds without bigints will lead unexpectedly to an overflow.
| * py/modmath: Allow trunc/ceil/floor to return a big int if necessary.Damien George2017-03-23
| | | | | | | | | | | | | | Previous to this patch, if the result of the trunc/ceil/floor functions overflowed a small int, or was inf or nan, then a garbage value was returned. With this patch the correct big-int is returned if necessary, and exceptions are raised for inf or nan.
| * py/lexer: Remove obsolete comment, since lexer can now raise exceptions.Damien George2017-03-23
| |
| * py: Define and use MP_OBJ_ITER_BUF_NSLOTS to get size of stack iter buf.Damien George2017-03-23
| | | | | | | | | | | | | | | | It improves readability of code and reduces the chance to make a mistake. This patch also fixes a bug with nan-boxing builds by rounding up the calculation of the new NSLOTS variable, giving the correct number of slots (being 4) even if mp_obj_t is larger than the native machine size.
| * py/sequence: Convert mp_uint_t to size_t where appropriate.Damien George2017-03-23
| |
| * py: Use size_t as len argument and return type of mp_get_index.Damien George2017-03-23
| | | | | | | | | | These values are used to compute memory addresses and so size_t is the more appropriate type to use.
| * py/bc: Provide better error message for an unexpected keyword argument.Damien George2017-03-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | Now, passing a keyword argument that is not expected will correctly report that fact. If normal or detailed error messages are enabled then the name of the unexpected argument will be reported. This patch decreases the code size of bare-arm and stmhal by 12 bytes, and cc3200 by 8 bytes. Other ports (minimal, unix, esp8266) remain the same in code size. For terse error message configuration this is because the new message is shorter than the old one. For normal (and detailed) error message configuration this is because the new error message already exists in py/objnamedtuple.c so there's no extra space in ROM needed for the string.
| * py/vm: Don't release the GIL if the scheduler is locked.Damien George2017-03-20
| | | | | | | | | | | | | | | | | | | | | | | | | | The scheduler being locked general means we are running a scheduled function, and switching to another thread violates that, so don't switch in such a case (even though we technically could). And if we are running a scheduled function then we want to finish it ASAP, so we shouldn't switch to another thread. Furthermore, ports with threading enabled will lock the scheduler during a hard IRQ, and this patch to the VM will make sure that threads are not switched during a hard IRQ (which would crash the VM).
| * py: Add micropython.schedule() function and associated runtime code.Damien George2017-03-20
| |
| * py/objstr: Use better msg in bad implicit str/bytes conversion exceptionstijn2017-03-20
| | | | | | | | | | | | | | | | | | | | Instead of always reporting some object cannot be implicitly be converted to a 'str', even when it is a 'bytes' object, adjust the logic so that when trying to convert str to bytes it is shown like that. This will still report bad implicit conversion from e.g. 'int to bytes' as 'int to str' but it will not result in the confusing 'can't convert 'str' object to str implicitly' anymore for calls like b'somestring'.count('a').
| * py: Provide mp_decode_uint_value to help optimise stack usage.Damien George2017-03-17
| | | | | | | | | | This has a noticeable improvement on x86-64 and Thumb2 archs, where stack usage is reduced by 2 machine words in the VM.
| * py: Reduce size of mp_code_state_t structure.Damien George2017-03-17
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Instead of caching data that is constant (code_info, const_table and n_state), store just a pointer to the underlying function object from which this data can be derived. This helps reduce stack usage for the case when the mp_code_state_t structure is stored on the stack, as well as heap usage when it's stored on the heap. The downside is that the VM becomes a little more complex because it now needs to derive the data from the underlying function object. But this doesn't impact the performance by much (if at all) because most of the decoding of data is done outside the main opcode loop. Measurements using pystone show that little to no performance is lost. This patch also fixes a nasty bug whereby the bytecode can be reclaimed by the GC during execution. With this patch there is always a pointer to the function object held by the VM during execution, since it's stored in the mp_code_state_t structure.
| * py/objstr: Fix eager optimisation of str/bytes addition.Damien George2017-03-16
| | | | | | | | The RHS can only be returned if it is the same type as the LHS.
| * py/mkrules.mk: Remove special check for "-B" in qstr auto generation.Damien George2017-03-15
| | | | | | | | | | | | When make is passed "-B" it seems that everything is considered out-of-date and so $? expands to all prerequisites. Thus there is no need for a special check to see if $? is emtpy.
| * py/mpprint: Fix int formatting so "+" is printed for 0-valued integer.Damien George2017-03-15
| |
| * py/emitnative: Remove obsolete commented out code.Damien George2017-03-15
| |
| * py/emitnative: Use assertions and mp_not_implemented correctly.Damien George2017-03-14
| | | | | | | | | | Assertions are used to check expressions that should always be true, and mp_not_implemented is used for code that can be reached.
| * py/objint: Allow to print long-long ints without using the heap.Damien George2017-03-14
| | | | | | | | | | | | | | Some stack is allocated to format ints, and when the int implementation uses long-long there should be additional stack allocated compared with the other cases. This patch uses the existing "fmt_int_t" type to determine the amount of stack to allocate.
| * 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
| |