summaryrefslogtreecommitdiff
path: root/py
AgeCommit message (Collapse)Author
2018-05-18py/compile: Change comment about ITER_BUF_NSLOTS to a static assertion.Damien George
2018-05-18py/misc.h: Add MP_STATIC_ASSERT macro to do static assertions.Damien George
2018-05-18py/repl: Fix handling of unmatched brackets and unfinished quotes.Li Weiwei
Before this patch: >>> print(') ... ') Traceback (most recent call last): File "<stdin>", line 1 SyntaxError: invalid syntax After this patch: >>> print(') Traceback (most recent call last): File "<stdin>", line 1 SyntaxError: invalid syntax This matches CPython and prevents getting stuck in REPL continuation when a 1-quote is unmatched.
2018-05-18py/vm: Improve performance of opcode dispatch when using switch stmt.Damien George
Before this patch, when using the switch statement for dispatch in the VM (not computed goto) a pending exception check was done after each opcode. This is not necessary and this patch makes the pending exception check only happen when explicitly requested by certain opcodes, like jump. This improves performance of the VM by about 2.5% when using the switch.
2018-05-18py/vm: Use enum names instead of magic numbers in multi-opcode dispatch.Damien George
2018-05-17py/objfun: Fix variable name in DECODE_CODESTATE_SIZE() macro.Tom Collins
This patch fixes the macro so you can pass any name in, and the macro will make more sense if you're reading it on its own. It worked previously because n_state is always passed in as n_state_out_var.
2018-05-16py/vm: Adjust #if logic for gil_divisor so braces are balanced.Damien George
Having balanced braces { and } makes it easier to navigate the function.
2018-05-15py/nlrx86: Use naked attribute on nlr_push for gcc 8.0 and higher.Damien George
gcc 8.0 supports the naked attribute for x86 systems so it can now be used here. And in fact it is necessary to use this for nlr_push because gcc 8.0 no longer generates a prelude for this function (even without the naked attribute).
2018-05-13py/mpstate.h: Adjust start of root pointer section to exclude non-ptrs.Damien George
This patch moves the start of the root pointer section in mp_state_ctx_t so that it skips entries that are not pointers and don't need scanning. Previously, the start of the root pointer section was at the very beginning of the mp_state_ctx_t struct (which is the beginning of mp_state_thread_t). This was the original assembler version of the NLR code was hard-coded to have the nlr_top pointer at the start of this state structure. But now that the NLR code is partially written in C there is no longer this restriction on the location of nlr_top (and a comment to this effect has been removed in this patch). So now the root pointer section starts part way through the mp_state_thread_t structure, after the entries which are not root pointers. This patch also moves the non-pointer entries for MICROPY_ENABLE_SCHEDULER outside the root pointer section. Moving non-pointer entries out of the root pointer section helps to make the GC more precise and should help to prevent some cases of collectable garbage being kept. This patch also has a measurable improvement in performance of the pystone.py benchmark: on unix x86-64 and stm32 there was an improvement of roughly 0.6% (tested with both gcc 7.3 and gcc 8.1).
2018-05-11py/mpconfig.h: Be stricter when autodetecting machine endianness.Damien George
This patch changes 2 things in the endianness detection: 1. Don't assume that __BYTE_ORDER__ not being __ORDER_LITTLE_ENDIAN__ means that the machine is big endian, so add an explicit check that this macro is indeed __ORDER_BIG_ENDIAN__ (same with __BYTE_ORDER, __LITTLE_ENDIAN and __BIG_ENDIAN). A machine could have PDP endianness. 2. Remove the checks which base their autodetection decision on whether any little or big endian macros are defined (eg __LITTLE_ENDIAN__ or __BIG_ENDIAN__). Just because a system defines these does not mean it has that endianness. See issue #3760.
2018-05-11py/repl: Initialise q_last variable to prevent compiler warnings.Damien George
Some older compilers cannot deduce that q_last is always written to before being read.
2018-05-11py/objdeque: Fix sign extension bug when computing len of deque object.Damien George
For cases where size_t is smaller than mp_int_t (eg nan-boxing builds) the difference between two size_t's is not sign extended into mp_int_t and so the result is never negative. This patch fixes this bug by using ssize_t for the type of the result.
2018-05-10py/modbuiltins: Make built-in dir support the __dir__ special method.Damien George
If MICROPY_PY_ALL_SPECIAL_METHODS is enabled then dir() will now delegate to the special method __dir__ if the object it is listing has this method.
2018-05-10py/modbuiltins: In built-in dir make use of mp_load_method_protected.Damien George
This gives dir() better behaviour when listing the attributes of a user type that defines __getattr__: it will now not list those attributes for which __getattr__ raises AttributeError (meaning the attribute is not supported by the object).
2018-05-10py/repl: Use mp_load_method_protected to prevent leaking of exceptions.Damien George
This patch fixes the possibility of a crash of the REPL when tab-completing an object which raises an exception when its attributes are accessed. See issue #3729.
2018-05-10py/modbuiltins: Make built-in hasattr work properly for user types.Damien George
It now allows __getattr__ in a user type to raise AttributeError when the attribute does not exist.
2018-05-10py/runtime: Add mp_load_method_protected helper which catches exceptionsDamien George
This new helper function acts like mp_load_method_maybe but is wrapped in an NLR handler so it can catch exceptions. It prevents AttributeError from propagating out, and optionally all other exceptions. This helper can be used to fully implement hasattr (see follow-up commit), and also for cases where mp_load_method_maybe is used but it must now raise an exception.
2018-05-09py/{modbuiltins,repl}: Start qstr probing from after empty qstr.Damien George
The list of qstrs starts with MP_QSTR_NULL followed by MP_QSTR_, and these should never appear in dir() or REPL tab completion, so skip them.
2018-05-04py/emitnx86: Fix 32-bit x86 native emitter build by including header.Damien George
2018-05-02py/builtinhelp: Change occurrence of mp_uint_t to size_t.Damien George
2018-05-01py/obj.h: Fix math.e constant for nan-boxing builds.Damien George
Due to a typo, math.e was too small by around 6e-11.
2018-05-01py/stream: Use uPy errno instead of system's for non-blocking check.Ayke van Laethem
This is a more consistent use of errno codes. For example, it may be that a stream returns MP_EAGAIN but the mp_is_nonblocking_error() macro doesn't catch this value because it checks for EAGAIN instead (which may have a different value than MP_EAGAIN when MICROPY_USE_INTERNAL_ERRNO is enabled).
2018-05-01py/mperrno: Define MP_EWOULDBLOCK as EWOULDBLOCK, not EAGAIN.Damien George
Most modern systems have EWOULDBLOCK aliased to EAGAIN, ie they have the same value. But some systems use different values for these errnos and if a uPy port is using the system errno values (ie not the internal uPy values) then it's important to be able to distinguish EWOULDBLOCK from EAGAIN. Eg if a system call returned EWOULDBLOCK it must be possible to check for this return value, and this patch makes this now possible.
2018-04-27py/nlrthumb: Fix Clang support wrt use of "return 0".Ayke van Laethem
Clang defines __GNUC__ so we have to check for it specifically.
2018-04-10py: Refactor how native emitter code is compiled with a file per arch.Damien George
Instead of emitnative.c having configuration code for each supported architecture, and then compiling this file multiple times with different macros defined, this patch adds a file per architecture with the necessary code to configure the native emitter. These files then #include the emitnative.c file. This simplifies emitnative.c (which is already very large), and simplifies the build system because emitnative.c no longer needs special handling for compilation and qstr extraction.
2018-04-10py/objgenerator: Check stack before resuming a generator.Jeff Epler
This turns a hard crash in a recursive generator into a 'maximum recursion depth exceeded' exception.
2018-04-10py/stream: Switch stream close operation from method to ioctl.Damien George
This patch moves the implementation of stream closure from a dedicated method to the ioctl of the stream protocol, for each type that implements closing. The benefits of this are: 1. Rounds out the stream ioctl function, which already includes flush, seek and poll (among other things). 2. Makes calling mp_stream_close() on an object slightly more efficient because it now no longer needs to lookup the close method and call it, rather it just delegates straight to the ioctl function (if it exists). 3. Reduces code size and allows future types that implement the stream protocol to be smaller because they don't need a dedicated close method. Code size reduction is around 200 bytes smaller for x86 archs and around 30 bytes smaller for the bare-metal archs.
2018-04-05py/objstr: In find/rfind, don't crash when end < start.Jeff Epler
2018-04-05py/objint: Simplify LHS arg type checking in int binary op functions.Damien George
The LHS passed to mp_obj_int_binary_op() will always be an integer, either a small int or a big int, so the test for this type doesn't need to include an "other, unsupported type" case.
2018-04-04py: Don't include mp_optimise_value or opt_level() if compiler disabled.Damien George
Without the compiler enabled the mp_optimise_value is unused, and the micropython.opt_level() function is not useful, so exclude these from the build to save RAM and code size.
2018-04-04py/modsys: Don't compile getsizeof function if feature is disabled.Damien George
2018-04-04py/vm: Optimise handling of stackless mode when pystack is enabled.Damien George
When pystack is enabled mp_obj_fun_bc_prepare_codestate() will always return a valid pointer, and if there is no more pystack available then it will raise an exception (a RuntimeError). So having pystack enabled with stackless enabled automatically gives strict stackless mode. There is therefore no need to have code for strict stackless mode when pystack is enabled, and this patch optimises the VM for such a case.
2018-04-04py/vm: Don't do unnecessary updates of ip and sp variables.Damien George
Neither the ip nor sp variables are used again after the execution of the RAISE_VARARGS opcode, so they don't need to be updated.
2018-03-30py/runtime: Be sure that non-intercepted thrown object is an exception.Damien George
The VM expects that, if mp_resume() returns MP_VM_RETURN_EXCEPTION, then the returned value is an exception instance (eg to add a traceback to it). It's possible that a value passed to a generator's throw() is not an exception so must be explicitly checked for if the thrown value is not intercepted by the generator. Thanks to @jepler for finding the bug.
2018-03-30py/runtime: Check that keys in dicts passed as ** args are strings.Damien George
Prior to this patch the code would crash if a key in a ** dict was anything other than a str or qstr. This is because mp_setup_code_state() assumes that keys in kwargs are qstrs (for efficiency). Thanks to @jepler for finding the bug.
2018-03-17py/objexcept: Make MP_DEFINE_EXCEPTION public so ports can define excs.Damien George
2018-03-16py/makeqstrdefs.py: Optimise by using compiled re's so it runs faster.Damien George
By using pre-compiled regexs, using startswith(), and explicitly checking for empty lines (of which around 30% of the input lines are), automatic qstr extraction is speed up by about 10%.
2018-03-13py/obj.h: Move declaration of mp_obj_list_init to objlist.h.Damien George
If this function is used then objlist.h is already included to get the definition of mp_obj_list_t.
2018-03-13py/obj.h: Clean up by removing commented-out inline versions of macros.Damien George
2018-03-13py/misc.h: Remove unused count_lead_ones() inline function.Damien George
This function was never used for unicode/utf8 handling code, or anything else, so remove it to keep things clean.
2018-03-02py/objint: Remove unreachable code checking for int type in format func.Damien George
All callers of mp_obj_int_formatted() are expected to pass in a valid int object, and they do: - mp_obj_int_print() should always pass through an int object because it is the print special method for int instances. - mp_print_mp_int() checks that the argument is an int, and if not converts it to a small int. This patch saves around 20-50 bytes of code space.
2018-03-01py/formatfloat: Fix case where floats could render with negative digits.Damien George
Prior to this patch, some architectures (eg unix x86) could render floats with "negative" digits, like ")". For example, '%.23e' % 1e-80 would come out as "1.0000000000000000/)/(,*0e-80". This patch fixes the known cases.
2018-03-01py/formatfloat: Fix case where floats could render with a ":" character.Damien George
Prior to this patch, some architectures (eg unix x86) could render floats with a ":" character in them, eg 1e+39 would come out as ":e+38" (":" is just after "9" in ASCII so this is like 10e+38). This patch fixes some of these cases.
2018-03-01py/formatfloat: Fix rounding of %f format with edge-case FP values.Damien George
Prior to this patch the %f formatting of some FP values could be off by up to 1, eg '%.0f' % 123 would return "122" (unix x64). Depending on the FP precision (single vs double) certain numbers would format correctly, but others wolud not. This patch should fix all cases of rounding for %f.
2018-02-27py/vm: Simplify handling of special-case STOP_ITERATION in yield from.Damien George
There's no need to have MP_OBJ_NULL a special case, the code can re-use the MP_OBJ_STOP_ITERATION value to signal the special case and the VM can detect this with only one check (for MP_OBJ_STOP_ITERATION).
2018-02-27py/vm: Fix case of handling raised StopIteration within yield from.Damien George
This patch concerns the handling of an NLR-raised StopIteration, raised during a call to mp_resume() which is handling the yield from opcode. Previously, commit 6738c1dded8e436686f85008ec0a4fc47406ab7a introduced code to handle this case, along with a test. It seems that it was lucky that the test worked because the code did not correctly handle the stack pointer (sp). Furthermore, commit 79d996a57b351e0ef354eb1e2f644b194433cc73 improved the way mp_resume() propagated certain exceptions: it changed raising an NLR value to returning MP_VM_RETURN_EXCEPTION. This change meant that the test introduced in gen_yield_from_ducktype.py was no longer hitting the code introduced in 6738c1dded8e436686f85008ec0a4fc47406ab7a. The patch here does two things: 1. Fixes the handling of sp in the VM for the case that yield from is interrupted by a StopIteration raised via NLR. 2. Introduces a new test to check this handling of sp and re-covers the code in the VM.
2018-02-26py/mpstate.h: Add repl_line state for MICROPY_REPL_EVENT_DRIVEN.Damien George
2018-02-25py/mpz: In mpz_clone, remove unused check for NULL dig.Damien George
This path for src->deg==NULL is never used because mpz_clone() is always called with an argument that has a non-zero integer value, and hence has some digits allocated to it (mpz_clone() is a static function private to mpz.c all callers of this function first check if the integer value is zero and if so take a special-case path, bypassing the call to mpz_clone()). There is some unused and commented-out functions that may actually pass a zero-valued mpz to mpz_clone(), so some TODOs are added to these function in case they are needed in the future.
2018-02-24py/asm*.c: Remove unnecessary check for num_locals<0 in asm entry func.Damien George
All callers of the asm entry function guarantee that num_locals>=0, so no need to add an explicit check for it. Use an assertion instead. Also, the signature of asm_x86_entry is changed to match the other asm entry functions.
2018-02-24py/compile: Adjust c_assign_atom_expr() to use return instead of goto.Damien George
Makes the flow of the function a little more obvious, and allows to reach 100% coverage of compile.c when using gcov.