summaryrefslogtreecommitdiffstatshomepage
path: root/py
Commit message (Collapse)AuthorAge
* py/compile: Simplify syntax-error messages for illegal assignments.Damien George2017-03-29
| | | | | | | | With this patch all illegal assignments are reported as "can't assign to expression". Before the patch there were special cases for a literal on the LHS, and for augmented assignments (eg +=), but it seems a waste of bytes (and there are lots of bytes used in error messages) to spend on distinguishing such errors which a user will rarely encounter.
* py/lexer: Simplify and reduce code size for operator tokenising.Damien George2017-03-29
| | | | | | | | | | | | | | | | | | | | | By removing the 'E' code from the operator token encoding mini-language the tokenising can be simplified. The 'E' code was only used for the != operator which is now handled as a special case; the optimisations for the general case more than make up for the addition of this single, special case. Furthermore, the . and ... operators can be handled in the same way as != which reduces the code size a little further. This simplification also removes a "goto". Changes in code size for this patch are (measured in bytes): bare-arm: -48 minimal x86: -64 unix x86-64: -112 unix nanbox: -64 stmhal: -48 cc3200: -48 esp8266: -76
* py: Use mp_raise_TypeError/mp_raise_ValueError helpers where possible.Damien George2017-03-28
| | | | Saves 168 bytes on bare-arm.
* py/objmap: Convert mp_uint_t to size_t.Damien George2017-03-27
|
* py/compile: When compiling super(), handle closed-over self variable.Damien George2017-03-27
| | | | | | The self variable may be closed-over in the function, and in that case the call to super() should load the contents of the closure cell using LOAD_DEREF (before this patch it would just load the cell directly).
* py/vm: Fix VM opcode tracing to print correct stack pointer.Damien George2017-03-27
| | | | Also const_table is now moved to the code_state->fun_bc structure.
* py/obj: Change mp_uint_t to size_t for mp_obj_get_array_fixed_n len arg.Damien George2017-03-26
|
* py/nlrx86: Better check for Zephyr (requires 1.7).Paul Sokolovsky2017-03-26
|
* py/objarray: Use mp_obj_str_get_str instead of mp_obj_str_get_data.Damien George2017-03-25
|
* py: Remove MP_STATE_CTX, use MP_STATE_THREAD instead (it's an alias).Damien George2017-03-24
| | | | | MP_STATE_CTX was recently aliased to MP_STATE_THREAD and can now be removed.
* py: Use mp_locals/mp_globals accessor funcs instead of MP_STATE_CTX.Damien George2017-03-24
| | | | To improve maintainability of the code.
* py/objnamedtuple: Use size_t where appropriate, instead of mp_uint_t.Damien George2017-03-24
|
* 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.