summaryrefslogtreecommitdiffstatshomepage
path: root/py
Commit message (Collapse)AuthorAge
* py/objstringio: If created from immutable object, follow copy on write policy.Paul Sokolovsky2017-06-09
| | | | | Don't create copy of immutable object's contents until .write() is called on BytesIO.
* py/makeqstrdefs.py: Make script run correctly with Python 2.6.Damien George2017-06-09
|
* py: Provide mp_decode_uint_skip() to help reduce stack usage.Damien George2017-06-09
| | | | | | | | | Taking the address of a local variable leads to increased stack usage, so the mp_decode_uint_skip() function is added to reduce the need for taking addresses. The changes in this patch reduce stack usage of a Python call by 8 bytes on ARM Thumb, by 16 bytes on non-windowing Xtensa archs, and by 16 bytes on x86-64. Code size is also slightly reduced on most archs by around 32 bytes.
* py/modsys: Allow to compile with obj-repr D and PY_ATTRTUPLE disabled.Damien George2017-06-08
|
* py/objstr: Allow to compile with obj-repr D, and unicode disabled.Damien George2017-06-08
|
* py/persistentcode: Allow to compile with complex numbers disabled.Damien George2017-06-08
|
* extmod/modlwip: Fix error codes for duplicate calls to connect().Paul Sokolovsky2017-06-04
| | | | | | | | If socket is already connected, POSIX requires returning EISCONN. If connection was requested, but not yet complete (for non-blocking socket), error code is EALREADY. http://pubs.opengroup.org/onlinepubs/7908799/xns/connect.html
* py/objstr: Catch case of negative "maxsplit" arg to str.rsplit().Damien George2017-06-02
| | | | | Negative values mean no limit on the number of splits so should delegate to the .split() method.
* py/modbuiltins: Add core-provided version of input() function.Damien George2017-06-01
| | | | | | | The implementation is taken from stmhal/input.c, with code added to handle ctrl-C. This built-in is controlled by MICROPY_PY_BUILTINS_INPUT and is disabled by default. It uses readline() to capture input but this can be overridden by defining the mp_hal_readline macro.
* various: Spelling fixesVille Skyttä2017-05-29
|
* py/objstringio: Catch mp_uint_t overflow of stream position in write().Tom Collins2017-05-26
|
* py/mkrules.mk: Fix auto-qstr generation when "make -B" is used.Damien George2017-05-26
| | | | | | | | | | | | For make v3.81, using "make -B" can set $? to empty and in this case the auto-qstr generation needs to pass all args (ie $^) to cpp. The previous fix for this (which was removed in 23a693ec2d8c2a194f61482dc0e1adb070fb6ad4) used if statements in the shell command, which gave very long lines that didn't work on certain systems (eg cygwin). The fix in this patch is to use an $if(...) expression, which will evaluate to $? (only newer prerequisites) if it's non empty, otherwise it will use $^ (all prerequisites).
* py/emitbc: Fix bug with BC emitter computing Python stack size.Damien George2017-05-25
| | | | | | | | | | | Previous to this patch the mp_emit_bc_adjust_stack_size function would adjust the current stack size but would not increase the maximum stack size if the current size went above it. This meant that certain Python code (eg a try-finally block with no statements inside it) would not have enough Python stack allocated to it. This patch fixes the problem by always checking if the current stack size goes above the maximum, and adjusting the latter if it does.
* py/vm: Fix bug with unwind jump popping the iterator from a for loop.Damien George2017-05-25
| | | | | This patch fixes a regression introduced by 088740ecc40476fd0796a3ef6a68ee7c677eae64
* py/vm: Fix bug with stackless mode and unwinding of exceptions.Damien George2017-05-25
| | | | | | | | | This patch fixes a regression introduced by 71a3d6ec3bd02c5bd13334537e1bd146bb643bad Previous to this patch the n_state variable was referring to that computed at the very start of the mp_execute_bytecode function. This patch fixes it so that n_state is recomputed when the code_state changes.
* py/mkenv.mk: Use $(TOP) instead of ".." to reference tools, mpy-cross.Damien George2017-05-19
|
* py/objrange: Fix slicing of range when step of slice is negative.Damien George2017-05-18
|
* py/sequence: Fix boundary errors when slicing with a negative step.Damien George2017-05-18
|
* py/objstringio: Fix StringIO reads at or beyond EOF.Tom Collins2017-05-15
| | | | Existing code failed if seek() went past EOF (which is acceptable when writing).
* py/modsys: update conditionals for code referencing sys.stdoutTom Collins2017-05-14
| | | | Working on a build with PY_IO enabled (for PY_UJSON support) but PY_SYS_STDFILES disabled (no filesystem). There are multiple references to mp_sys_stdout_obj that should only be enabled if both PY_IO and PY_SYS_STDFILES are enabled.
* py/lexer: Process CR earlier to allow newlines checks on chr1.Tom Collins2017-05-12
| | | | | Resolves an issue where lexer failed to accept CR after line continuation character. It also simplifies the code.
* py/mkrules.mk: Add dependency of .mpy files upon mpy-cross.Damien George2017-05-11
| | | | | | This ensures that mpy-cross is automatically built (and is up-to-date) for ports that use frozen bytecode. It also makes sure that .mpy files are re-built if mpy-cross is changed.
* unix/main: Implement -m option for packages.Paul Sokolovsky2017-05-09
|
* py/lexer: Simplify lexer startup by using dummy bytes and next_char().Tom Collins2017-05-09
| | | | | | | Now consistently uses the EOL processing ("\r" and "\r\n" convert to "\n") and EOF processing (ensure "\n" before EOF) provided by next_char(). In particular the lexer can now correctly handle input that starts with CR.
* py/binary: Handle storing big-ints to all arrays types.Damien George2017-05-09
| | | | | | | Prior to this patch only 'q' and 'Q' type arrays could store big-int values. With this patch any big int that is stored to an array is handled by the big-int implementation, regardless of the typecode of the array. This allows arrays to work with all type sizes on all architectures.
* py/modio: resource_stream: Implement "package" param handling.Paul Sokolovsky2017-05-06
|
* py/objint: In int.from_bytes, only create big-int if really needed.Damien George2017-05-06
| | | | | This patch ensures that int.from_bytes only creates a big-int if necessary, by checking the value for a small-int overflow as it's being parsed.
* py/modio: Implement uio.resource_stream(package, resource_path).Paul Sokolovsky2017-05-03
| | | | | | | | | | | | | | The with semantics of this function is close to pkg_resources.resource_stream() function from setuptools, which is the canonical way to access non-source files belonging to a package (resources), regardless of what medium the package uses (e.g. individual source files vs zip archive). In the case of MicroPython, this function allows to access resources which are frozen into the executable, besides accessing resources in the file system. This is initial stage of the implementation, which actually doesn't implement "package" part of the semantics, just accesses frozen resources from "root", or filesystem resource - from current dir.
* py: Cleanup use of global DEBUG preprocessor definitionstijn2017-04-30
| | | | | | | | | The standard preprocessor definition to differentiate debug and non-debug builds is NDEBUG, not DEBUG, so don't rely on the latter: - just delete the use of it in objint_longlong.c as it has been stale code for years anyway (since commit [c4029e5]): SUFFIX isn't used anywhere. - replace DEBUG with MICROPY_DEBUG_NLR in nlr.h: it is rarely used anymore so can be off by default
* py/mpz: In mpn_sub, use existing function to remove trailing zeros.Damien George2017-04-25
|
* py/mpz: Strip trailing zeros from mpz value when set from bytes.Damien George2017-04-25
|
* py: Add LOAD_SUPER_METHOD bytecode to allow heap-free super meth calls.Damien George2017-04-22
| | | | | | | | | | | | | | | | | | | | | | This patch allows the following code to run without allocating on the heap: super().foo(...) Before this patch such a call would allocate a super object on the heap and then load the foo method and call it right away. The super object is only needed to perform the lookup of the method and not needed after that. This patch makes an optimisation to allocate the super object on the C stack and discard it right after use. Changes in code size due to this patch are: bare-arm: +128 minimal: +232 unix x64: +416 unix nanbox: +364 stmhal: +184 esp8266: +340 cc3200: +128
* py/compile: Refactor handling of special super() call.Damien George2017-04-22
| | | | | | | | | | | | | | | | | | | This patch refactors the handling of the special super() call within the compiler. It removes the need for a global (to the compiler) state variable which keeps track of whether the subject of an expression is super. The handling of super() is now done entirely within one function, which makes the compiler a bit cleaner and allows to easily add more optimisations to super calls. Changes to the code size are: bare-arm: +12 minimal: +0 unix x64: +48 unix nanbox: -16 stmhal: +4 cc3200: +0 esp8266: -56
* py/compile: Don't do unnecessary check if iter parse node is a struct.Damien George2017-04-22
| | | | | If we get to this point in the code then pn_iter is guaranteed to be a struct.
* py/compile: Add COMP_RETURN_IF_EXPR option to enable return-if-else opt.Damien George2017-04-22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | With this optimisation enabled the compiler optimises the if-else expression within a return statement. The optimisation reduces bytecode size by 2 bytes for each use of such a return-if-else statement. Since such a statement is not often used, and costs bytes for the code, the feature is disabled by default. For example the following code: def f(x): return 1 if x else 2 compiles to this bytecode with the optimisation disabled (left column is bytecode offset in bytes): 00 LOAD_FAST 0 01 POP_JUMP_IF_FALSE 8 04 LOAD_CONST_SMALL_INT 1 05 JUMP 9 08 LOAD_CONST_SMALL_INT 2 09 RETURN_VALUE and to this bytecode with the optimisation enabled: 00 LOAD_FAST 0 01 POP_JUMP_IF_FALSE 6 04 LOAD_CONST_SMALL_INT 1 05 RETURN_VALUE 06 LOAD_CONST_SMALL_INT 2 07 RETURN_VALUE So the JUMP to RETURN_VALUE is optimised and replaced by RETURN_VALUE, saving 2 bytes and making the code a bit faster.
* py/compile: Extract parse-node kind at start of func for efficiency.Damien George2017-04-22
| | | | | | Otherwise the type of parse-node and its kind has to be re-extracted multiple times. This optimisation reduces code size by a bit (16 bytes on bare-arm).
* py/compile: Don't do unnecessary check if parse node is a struct.Damien George2017-04-22
| | | | | PN_atom_expr_normal parse nodes always have structs for their second sub-node, so simplify the check for the sub-node kind to save code size.
* py/objtype: mp_obj_new_super doesn't need to be public, so inline it.Damien George2017-04-22
| | | | | Saves code size (20 bytes on bare-arm) and makes it a tiny bit more efficient.
* extmod/moductypes: Fix bigint handling for 32-bit ports.Paul Sokolovsky2017-04-21
|
* py: Reduce str/repr precision of float numbers when floats are 30-bit.Damien George2017-04-21
| | | | | With 30-bit floats there aren't enough bits to faithfully print 7 decimal digits, so reduce the precision to 6 digits.
* py/modmicropython: Add micropython.kbd_intr() function.Damien George2017-04-18
| | | | | | | It controls the character that's used to (asynchronously) raise a KeyboardInterrupt exception. Passing "-1" allows to disable the interception of the interrupt character (as long as a port allows such a behaviour).
* py/gc: Execute finaliser code in a protected environment.Damien George2017-04-12
| | | | | | | | | | | | If a finaliser raises an exception then it must not propagate through the GC sweep function. This patch protects against such a thing by running finaliser code via the mp_call_function_1_protected call. This patch also adds scheduler lock/unlock calls around the finaliser execution to further protect against any possible reentrancy issues: the memory manager is already locked when doing a collection, but we also don't want to allow any scheduled code to run, KeyboardInterrupts to interupt the code, nor threads to switch.
* py/nlrsetjmp: Add check for failed NLR jump.Damien George2017-04-12
| | | | | Also optimise the function so it only needs to call the MP_STATE_THREAD macro once (following how other nlr code is written).
* py/objfloat: Add implementation of high-quality float hashing.Damien George2017-04-12
| | | | Disabled by default.
* py: Optimise types for common case where type has a single parent type.Damien George2017-04-12
| | | | | | | | | | | | | | | | | | | | | | | | The common cases for inheritance are 0 or 1 parent types, for both built-in types (eg built-in exceptions) as well as user defined types. So it makes sense to optimise the case of 1 parent type by storing just the type and not a tuple of 1 value (that value being the single parent type). This patch makes such an optimisation. Even though there is a bit more code to handle the two cases (either a single type or a tuple with 2 or more values) it helps reduce overall code size because it eliminates the need to create a static tuple to hold single parents (eg for the built-in exceptions). It also helps reduce RAM usage for user defined types that only derive from a single parent. Changes in code size (in bytes) due to this patch: bare-arm: -16 minimal (x86): -176 unix (x86-64): -320 unix nanbox: -384 stmhal: -64 cc3200: -32 esp8266: -108
* py/obj: Clean up and add comments describing mp_obj_type_t struct.Damien George2017-04-12
|
* py/objint: Use unsigned arithmetic when formatting an integer.Damien George2017-04-11
| | | | | Otherwise the edge case of the most negative integer value will not convert correctly.
* py/objint: Extract small int value directly because type is known.Damien George2017-04-11
|
* py/runtime: When init'ing kbd intr exc, use tuple ptr instead of object.Damien George2017-04-10
|
* py: Make sure that static emg-exc-buffer is aligned to size of mp_obj_t.Damien George2017-04-10
| | | | | | | | | | | | This buffer is used to allocate objects temporarily, and such objects require that their underlying memory be correctly aligned for their data type. Aligning for mp_obj_t should be sufficient for emergency exceptions, but in general the memory buffer should aligned to the maximum alignment of the machine (eg on a 32-bit machine with mp_obj_t being 4 bytes, a double may not be correctly aligned). This patch fixes a bug for certain nan-boxing builds, where mp_obj_t is 8 bytes and must be aligned to 8 bytes (even though the machine is 32 bit).