summaryrefslogtreecommitdiffstatshomepage
path: root/py
Commit message (Collapse)AuthorAge
* py/emitbc: Remove/refactor unreachable code, to improve coverage.Damien George2016-09-27
|
* py/objstr: Remove unreachable function used only for terse error msgs.Damien George2016-09-27
|
* py/modmicropython: Add micropython.const, alias for identity function.Damien George2016-09-27
| | | | | | | | | Having a micropython.const identity function, and writing "from micropython import const" at the start of scripts that use the const feature, allows to write scripts which are compatible with CPython, and with uPy builds that don't include const optimisation. This patch adds such a function and updates the tests to do the import.
* py/vm: Use MP_OBJ_FROM_PTR to cast a type to an object.Damien George2016-09-27
|
* py: Only store the exception instance on Py stack in bytecode try block.Damien George2016-09-27
| | | | | | | | | | | | | | | | | | | | When an exception is raised and is to be handled by the VM, it is stored on the Python value stack so the bytecode can access it. CPython stores 3 objects on the stack for each exception: exc type, exc instance and traceback. uPy followed this approach, but it turns out not to be necessary. Instead, it is enough to store just the exception instance on the Python value stack. The only place where the 3 values are needed explicitly is for the __exit__ handler of a with-statement context, but for these cases the 3 values can be extracted from the single exception instance. This patch removes the need to store 3 values on the stack, and instead just stores the exception instance. Code size is reduced by about 50-100 bytes, the compiler and VM are slightly simpler, generate bytecode is smaller (by 2 bytes for each try block), and the Python value stack is reduced in size for functions that handle exceptions.
* py/py.mk: Add support for building modussl_mbedtls.Paul Sokolovsky2016-09-23
|
* py/parse: Only replace constants that are standalone identifiers.Damien George2016-09-23
| | | | | | This fixes constant substitution so that only standalone identifiers are replaced with their constant value (if they have one). I.e. don't replace NAME in expressions like obj.NAME or NAME = expr.
* py: Update opcode format table because 3 opcodes were removed, 1 added.Damien George2016-09-23
| | | | | LIST_APPEND, MAP_ADD and SET_ADD have been removed, and STORE_COMP has been added in adaf0d865cd6c81fb352751566460506392ed55f.
* py: Shrink mp_arg_t struct by using reduced-size integer members.Damien George2016-09-23
| | | | | | | | | qstrs ids are restricted to fit within 2 bytes already (eg in persistent bytecode) so it's safe to use a uint16_t to store them in mp_arg_t. And the flags member only needs a maximum of 2 bytes so can also use uint16_t. Savings in code size can be significant when many mp_arg_t structs are used for argument parsing. Eg, this patch reduces stmhal by 480 bytes.
* py/py.mk: Suppress some compiler warnings when building berkeley-db.Damien George2016-09-22
|
* py/stream: Remove unnecessary check for NULL return from vstr_extend.Damien George2016-09-22
| | | | | vstr_extend will now only return NULL if the vstr is a fixed buffer, which in this case it is not.
* all: Remove 'name' member from mp_obj_module_t struct.Damien George2016-09-22
| | | | One can instead lookup __name__ in the modules dict to get the value.
* py/builtinimport: Fix nanbox build after change to better handle -m modules.Paul Sokolovsky2016-09-20
|
* builtinimport: add the module specified by -m to sys.modules as '__main__'Delio Brignoli2016-09-20
|
* py/showbc: Make printf's go to the platform print stream.Damien George2016-09-20
| | | | | | | | | The system printf is no longer used by the core uPy code. Instead, the platform print stream or DEBUG_printf is used. Using DEBUG_printf in the showbc functions would mean that the code can't be tested by the test suite, so use the normal output instead. This patch also fixes parsing of bytecode-line-number mappings.
* py/qstr: Remove a comment.Damien George2016-09-19
| | | | qstrs are always null terminated so qstr_str will stay as part of the API.
* py/objnone: Use mp_generic_unary_op instead of custom one.Damien George2016-09-19
|
* py/vstr: Remove vstr.had_error flag and inline basic vstr functions.Damien George2016-09-19
| | | | | | | | | | | | | | | | | | The vstr.had_error flag was a relic from the very early days which assumed that the malloc functions (eg m_new, m_renew) returned NULL if they failed to allocate. But that's no longer the case: these functions will raise an exception if they fail. Since it was impossible for had_error to be set, this patch introduces no change in behaviour. An alternative option would be to change the malloc calls to the _maybe variants, which return NULL instead of raising, but then a lot of code will need to explicitly check if the vstr had an error and raise if it did. The code-size savings for this patch are, in bytes: bare-arm:188, minimal:456, unix(NDEBUG,x86-64):368, stmhal:228, esp8266:360.
* py: Combine 3 comprehension opcodes (list/dict/set) into 1.Damien George2016-09-19
| | | | | | | | | With the previous patch combining 3 emit functions into 1, it now makes sense to also combine the corresponding VM opcodes, which is what this patch does. This eliminates 2 opcodes which simplifies the VM and reduces code size, in bytes: bare-arm:44, minimal:64, unix(NDEBUG,x86-64):272, stmhal:92, esp8266:200. Profiling (with a simple script that creates many list/dict/set comprehensions) shows no measurable change in performance.
* py: Combine 3 comprehension emit functions (list/dict/set) into 1.Damien George2016-09-19
| | | | | | The 3 kinds of comprehensions are similar enough that merging their emit functions reduces code size. Decreases in code size in bytes are: bare-arm:24, minimal:96, unix(NDEBUG,x86-64):328, stmhal:80, esp8266:76.
* py: Move frozen modules rules from esp8266 port for reuse across ports.Paul Sokolovsky2016-09-17
| | | | | A port now just needs to define FROZEN_DIR var and add $(BUILD)/frozen.c to SRC_C to support frozen modules.
* py/objnone: Remove unnecessary handling of MP_UNARY_OP_BOOL.Damien George2016-09-16
| | | | | | | | | bool(None) has a fast path in mp_obj_is_true so doesn't need to be handled in none_unary_op. The only caveat is that subclassing may bypass the mp_obj_is_true function, but actually you aren't allowed to subclass classes that have singleton instances like NoneType (see https://mail.python.org/pipermail/python-dev/2002-March/020822.html for reference on this point).
* py/makeqstrdefs.py: Use python 2.6 syntax for set creation.Chris Packham2016-09-09
| | | | | | | | | | | | | | py/makeqstrdefs.py declares that it works with python 2.6 however the syntax used to initialise of a set with values was only added in python 2.7. This leads to build failures when the host system doesn't have python 2.7 or newer. Instead of using the new syntax pass a list of initial values through set() to achieve the same result. This should work for python versions from at least 2.6 onwards. Helped-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> Signed-off-by: Chris Packham <judge.packham@gmail.com>
* py/asmthumb: Flush D-cache, and invalidate I-cache on STM32F7.Antonin ENFRUN2016-09-09
| | | | | | Tested on a STM32F7DISCO at 216MHz. All tests generating code (inlineasm, native, viper) now pass, except pybnative/while.py, but that's because there is no LED(2).
* py: Add MICROPY_USE_INTERNAL_PRINTF option, defaults to enabled.Delio Brignoli2016-09-05
| | | | | | | | This new config option allows to control whether MicroPython uses its own internal printf or not (if not, an external one should be linked in). Accompanying this new option is the inclusion of lib/utils/printf.c in the core list of source files, so that ports no longer need to include it themselves.
* py/emitglue.c: provide mp_raw_code_load_file for any unix architectureChris Packham2016-09-04
| | | | Signed-off-by: Chris Packham <chris.packham@alliedtelesis.co.nz>
* py: If str/bytes hash is 0 then explicitly compute it.Damien George2016-09-02
|
* py/makeqstrdata.py: Compute the qstr hash from bytes, not characters.Damien George2016-09-02
|
* py/mpprint: Fail an assertion with unsupported format specifiers.Delio Brignoli2016-09-01
| | | | | | Arguments of an unknown type cannot be skipped and continuing to parse a format string after encountering an unknown format specifier leads to undefined behaviour. This patch helps to find use of unsupported formats.
* extmod: Add machine_spi with generic SPI C-protocol and helper methods.Damien George2016-09-01
| | | | | | | The idea is that all ports can use these helper methods and only need to provide initialisation of the SPI bus, as well as a single transfer function. The coding pattern follows the stream protocol and helper methods.
* py/mkrules.mk: Allow to override name of libmicropython.aPaul Sokolovsky2016-08-30
| | | | | Or alternatively, refer to an exact library file, not just phony target "lib".
* py/bc.h: Rename _mp_code_state to _mp_code_state_t.Damien George2016-08-27
| | | | This rename was missed in the previous patch.
* py: Rename struct mp_code_state to mp_code_state_t.Damien George2016-08-27
| | | | Also at _t to mp_exc_stack pre-declaration in struct typedef.
* py/emitglue: Use more compact mp_raise_ValueError function.Damien George2016-08-26
|
* py/modstruct: Use more compact mp_raise_ValueError function.Damien George2016-08-26
| | | | Saves a few bytes of code size.
* py/compile: Don't compile assert statements when optimisations enabled.Damien George2016-08-26
| | | | As per CPython.
* py/gc: Add MICROPY_GC_CONSERVATIVE_CLEAR option to always zero memory.Damien George2016-08-26
| | | | | | | | | There can be stray pointers in memory blocks that are not properly zero'd after allocation. This patch adds a new config option to always zero all allocated memory (via gc_alloc and gc_realloc) and hence help to eliminate stray pointers. See issue #2195.
* extmod/modubinascii: Make crc32() support configurable.Paul Sokolovsky2016-08-24
| | | | Disable by default, enable in unix port.
* py/stream.c: use mp_obj_get_type in mp_get_stream_raiseKrzysztof Blazewicz2016-08-24
| | | | | | | | | | In current state `mp_get_stream_raise` assumes that `self_in` is an object and always performs a pointer derefence which may cause a segfault. This function shall throw an exception whenever `self_in` does not implement a stream protocol, that includes qstr's and numbers. fixes #2331
* py/sequence: Allow to use bignums as indices in slice objects.Damien George2016-08-15
| | | | See issue #2264.
* py/obj.h: For obj reprs A,B,C use void* explicitly for mp_obj_t typedef.Damien George2016-08-15
| | | | | | | | | The machine_ptr_t type is long obsolete as the type of mp_obj_t is now defined by the object representation, ie by MICROPY_OBJ_REPR. So just use void* explicitly for the typedef of mp_obj_t. If a port wants to use something different then they should define a new object representation.
* py/objstr: Use mp_raise_{Type,Value}Error instead of mp_raise_msg.Damien George2016-08-14
| | | | | This patch does further refactoring using the new mp_raise_TypeError and mp_raise_ValueError functions.
* py/runtime.h: Move comment about mp_not_implemented to correct place.Damien George2016-08-14
|
* py/objtuple: In tuple_cmp_helper, use mp_check_self instead of raising.Damien George2016-08-14
| | | | | | Only tuple, namedtuple and attrtuple use the tuple_cmp_helper function, and they all have getiter=mp_obj_tuple_getiter, so the check here is only to ensure that the self object is consistent. Hence use mp_check_self.
* py: Get rid of assert() in method argument checking functions.Paul Sokolovsky2016-08-12
| | | | | | Checks for number of args removes where guaranteed by function descriptor, self checking is replaced with mp_check_self(). In few cases, exception is raised instead of assert.
* py/objdict: Get rid of asserts (remove/replace with mp_check_self()).Paul Sokolovsky2016-08-12
|
* py/runtime.h: Define mp_check_self(pred) helper macro.Paul Sokolovsky2016-08-12
| | | | | | | Indended to replace raw asserts in bunch of files. Expands to empty if MICROPY_BUILTIN_METHOD_CHECK_SELF_ARG is defined, otehrwise by default still to assert, though a particular port may define it to something else.
* py/runtime: Factor out exception raising helpers.Paul Sokolovsky2016-08-12
| | | | | | Introduce mp_raise_msg(), mp_raise_ValueError(), mp_raise_TypeError() instead of previous pattern nlr_raise(mp_obj_new_exception_msg(...)). Save few bytes on each call, which are many.
* py/mpconfig.h: Define MP_ALWAYSINLINE for reuse.Paul Sokolovsky2016-08-07
| | | | Similar to existing MP_NOINLINE.
* py/objstr,objstrunicode: Fix inconistent #if indentation.Paul Sokolovsky2016-08-07
|