summaryrefslogtreecommitdiffstatshomepage
path: root/py
Commit message (Collapse)AuthorAge
* py: Prevent many extra vstr allocations.Dave Hylands2015-07-06
| | | | | | | | | | | | | | | | | | | | | | | | | I checked the entire codebase, and every place that vstr_init_len was called, there was a call to mp_obj_new_str_from_vstr after it. mp_obj_new_str_from_vstr always tries to reallocate a new buffer 1 byte larger than the original to store the terminating null character. In many cases, if we allocated the initial buffer to be 1 byte longer, we can prevent this extra allocation, and just reuse the originally allocated buffer. Asking to read 256 bytes and only getting 100 will still cause the extra allocation, but if you ask to read 256 and get 256 then the extra allocation will be optimized away. Yes - the reallocation is optimized in the heap to try and reuse the buffer if it can, but it takes quite a few cycles to figure this out. Note by Damien: vstr_init_len should now be considered as a string-init convenience function and used only when creating null-terminated objects.
* py/repl: Fix case where shorter names are shadowed by longer names.Damien George2015-07-06
| | | | | | Previous to this patch, if "abcd" and "ab" were possible completions to tab-completing "a", then tab would expand to "abcd" straight away if this identifier appeared first in the dict.
* modstruct: Raise NotImplementedError for unsupported repeat specification.Paul Sokolovsky2015-07-05
|
* extmod: Add a2b_base64 and b2a_base64 functions to ubinascii.Galen Hazelwood2015-07-04
|
* py/objarray.c: Allow to build with debugging and bytearray but no array.Damien George2015-07-02
|
* py: Add TimeoutError exception subclassed from OSError.Daniel Campora2015-07-02
| | | | | | | The TimeoutError is useful for some modules, specially the the socket module. TimeoutError can then be alised to socket.timeout and then Python code can differentiate between socket.error and socket.timeout.
* builtinimport: Fix running package submodule with -m.Paul Sokolovsky2015-06-29
| | | | | | | When "micropython -m pkg.mod" command was used, relative imports in pkg.mod didn't work, because pkg.mod.__name__ was set to __main__, and the fact that it's a package submodule was missed. This is an original workaround to this issue. TODO: investigate and compare how CPython deals with this issue.
* builtinimport: Catch case when relative import happens without active package.Paul Sokolovsky2015-06-27
| | | | | CPython raises SystemError in this case, but we don't have that enabled, so raise ImportError.
* runtime: Improve mp_import_name() debug logging.Paul Sokolovsky2015-06-27
|
* objstr: Add note that replace() is nicely optimized.Paul Sokolovsky2015-06-26
| | | | | Doesn't allocate memory and returns original string if no replacements are to be made.
* py: Remove mp_load_const_bytes and instead load precreated bytes object.Damien George2015-06-25
| | | | | | | | | | | | | | | | Previous to this patch each time a bytes object was referenced a new instance (with the same data) was created. With this patch a single bytes object is created in the compiler and is loaded directly at execute time as a true constant (similar to loading bignum and float objects). This saves on allocating RAM and means that bytes objects can now be used when the memory manager is locked (eg in interrupts). The MP_BC_LOAD_CONST_BYTES bytecode was removed as part of this. Generated bytecode is slightly larger due to storing a pointer to the bytes object instead of the qstr identifier. Code size is reduced by about 60 bytes on Thumb2 architectures.
* py: Remove mp_load_const_str and replace uses with inlined version.Damien George2015-06-25
|
* py: Clarify comment in parsenum.c about ValueError vs SyntaxError.Damien George2015-06-23
|
* py: Change exception type to ValueError when error reporting is terse.Daniel Campora2015-06-23
| | | | Addresses issue #1347
* py: Cast argument for printf to int, to be compatible with more ports.Damien George2015-06-22
| | | | This allows stmhal to be compiled with MICROPY_DEBUG_PRINTERS.
* py: Use a wrapper to explicitly check self argument of builtin methods.Damien George2015-06-20
| | | | | | | | | | | | | | | Previous to this patch a call such as list.append(1, 2) would lead to a seg fault. This is because list.append is a builtin method and the first argument to such methods is always assumed to have the correct type. Now, when a builtin method is extracted like this it is wrapped in a checker object which checks the the type of the first argument before calling the builtin function. This feature is contrelled by MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG and is enabled by default. See issue #1216.
* py: Make showbc decode UNPACK_EX, and use correct range for unop/binop.Damien George2015-06-18
|
* py: Implement divmod for mpz bignum.Damien George2015-06-13
|
* py: Add MP_BINARY_OP_DIVMOD to simplify and consolidate divmod builtin.Damien George2015-06-13
|
* py: Implement second arg for math.log (optional value for base).Damien George2015-06-13
|
* py: Rebuild port if mpconfigport.mk changed (if any).Paul Sokolovsky2015-06-11
| | | | | | | | mpconfigport.mk contains configuration options which affect the way MicroPython is linked. In this regard, it's "stronger" configuration dependency than even mpconfigport.h, so if we rebuild everything on mpconfigport.h change, we certianly should of that on mpconfigport.mk change too.
* py: Support unicode (utf-8 encoded) identifiers in Python source.Damien George2015-06-09
| | | | Enabled simply by making the identifier lexing code 8-bit clean.
* py: Fallback to stack alloca for Python-stack if heap alloc fails.Damien George2015-06-08
| | | | | | If heap allocation for the Python-stack of a function fails then we may as well allocate the Python-stack on the C stack. This will allow to run more code without using the heap.
* unix: Make micropython -m <module> work for frozen modules.Paul Sokolovsky2015-06-06
| | | | | This requires some special handling, which was previosuly applied only to the main code path.
* py: Expose KeyboardInterrupt in builtins module.Damien George2015-06-05
|
* unix: Allow to cat a script into stdin from the command line.Damien George2015-06-04
| | | | See issue #1306.
* py: Implement native multiply operation in viper emitter.Damien George2015-06-04
|
* py: Implement implicit cast to obj for viper load/store index/value.Damien George2015-06-04
| | | | | | | This allows to do "ar[i]" and "ar[i] = val" in viper when ar is a Python object and i and/or val are native viper types (eg ints). Patch also includes tests for this feature.
* py: Add stack check to mp_iternext, since it can be called recursively.Damien George2015-06-03
| | | | | | Eg, builtin map can map over a map, etc, and call iternext deeply. Addresses issue #1294.
* frozenmod: Include header with function prototypes.Paul Sokolovsky2015-05-31
|
* py: Wrap qstr defs in quotes to protect from C preprocessor.Damien George2015-05-30
| | | | | | | | | This patch converts Q(abc) to "Q(abc)" to protect the abc from the C preprocessor, then converts back after the preprocessor is finished. So now we can safely put includes in mpconfig(port).h, and also preprocess qstrdefsport.h (latter is now done also in this patch). Addresses issue #1252.
* py/parsenum.c: Rename "raise" func to "raise_exc" to avoid name clash.Damien George2015-05-30
| | | | "raise" is a common word that was found to exist in a vendor's stdlib.
* py: Add further autodetection of endianess in mpconfig.h.Damien George2015-05-30
| | | | This patch was needed for gcc 4.4.
* py: Get makeqstrdata.py and makeversionhdr.py running under Python 2.6.Damien George2015-05-30
| | | | | These scripts should run under as wide a range of Python versions as possible.
* py: Remove unnecessary extra handling of padding of nan/inf.Damien George2015-05-28
| | | | | | | C's printf will pad nan/inf differently to CPython. Our implementation originally conformed to C, now it conforms to CPython's way. Tests for this are also added in this patch.
* py: Reduce size of mp_printf by eliminating unnecessary code.Damien George2015-05-28
| | | | Saves around 120 bytes on Thumb2 archs.
* py: Make makeversionhdr.py extract version from docs/conf.py if no git.Damien George2015-05-25
| | | | Addresses issue #1285.
* stmhal: Implement sys.std{in,out,err}.buffer, for raw byte mode.Damien George2015-05-24
| | | | It's configurable and only enabled for stmhal port.
* py: Remove hexdigest QSTR since the method has been removed as well.Daniel Campora2015-05-21
|
* py: Minor improvement to unichar_isxdigitDave Hylands2015-05-20
| | | | | | This drops the size of unicode_isxdigit from 0x1e + 0x02 filler to 0x14 bytes (so net code reduction of 12 bytes) and will make unicode_is_xdigit perform slightly faster.
* extmod: Add ubinascii.unhexlifyDave Hylands2015-05-20
| | | | This also pulls out hex_digit from py/lexer.c and makes unichar_hex_digit
* py: Implement mp_format_float for doubles and use where appropriatestijn2015-05-17
| | | | | | | This allows using (almost) the same code for printing floats everywhere, removes the dependency on sprintf and uses just snprintf and applies an msvc-specific fix for snprintf in a single place so nan/inf are now printed correctly.
* py/binary: Make return type of mp_binary_get_size size_t instead of int.Kaspar Schleiser2015-05-17
| | | | Fixes sign-compare warning.
* py/objobject: Don't make locals_dict if there's nothing to go in it.Kaspar Schleiser2015-05-17
|
* py: Change _mp_obj_fun_builtin_t.fun to function pointer.Kaspar Schleiser2015-05-17
| | | | | ISO C forbids conversion between function pointers and void*, gcc -pedantic triggers a warning.
* py: Clean up declarations of str type/funcs that are also in unicode.Damien George2015-05-17
| | | | | Background: trying to make an amalgamation of all the code gave some errors with redefined types and inconsistent use of static.
* py: Fix printing of complex number when imaginary part is nanstijn2015-05-13
|
* py: Add mp_obj_get_int_truncated and use it where appropriate.Damien George2015-05-12
| | | | | | mp_obj_get_int_truncated will raise a TypeError if the argument is not an integral type. Use mp_obj_int_get_truncated only when you know the argument is a small or big int.
* py: Convert hash API to use MP_UNARY_OP_HASH instead of ad-hoc function.Damien George2015-05-12
| | | | | | | | | | | | | | Hashing is now done using mp_unary_op function with MP_UNARY_OP_HASH as the operator argument. Hashing for int, str and bytes still go via fast-path in mp_unary_op since they are the most common objects which need to be hashed. This lead to quite a bit of code cleanup, and should be more efficient if anything. It saves 176 bytes code space on Thumb2, and 360 bytes on x86. The only loss is that the error message "unhashable type" is now the more generic "unsupported type for __hash__".
* vm: Properly handle StopIteration raised in user instance iterator.Paul Sokolovsky2015-05-11
| | | | I.e. in bytecode Python functions.