summaryrefslogtreecommitdiffstatshomepage
path: root/py/objnamedtuple.c
Commit message (Collapse)AuthorAge
* all: Use the name MicroPython consistently in commentsAlexander Steffen2017-07-31
| | | | | There were several different spellings of MicroPython present in comments, when there should be only one.
* py/objnamedtuple: Simplify and remove use of alloca building namedtuple.Damien George2017-06-29
| | | | | | | | | | | | | | | | Prior to this patch there were 2 paths for creating the namedtuple, one for when no keyword args were passed, and one when there were keyword args. And alloca was used in the keyword-arg path to temporarily create the array of elements for the namedtuple, which would then be copied to a heap-allocated object (the namedtuple itself). This patch simplifies the code by combining the no-keyword and keyword paths, and removing the need for the alloca by constructing the namedtuple on the heap before populating it. Heap usage in unchanged, stack usage is reduced, use of alloca is removed, and code size is not increased and is actually reduced by between 20-30 bytes for most ports.
* 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: Convert mp_uint_t to size_t for tuple/list accessors.Damien George2017-03-29
| | | | | | | | | | | | | | | | | | | | This patch changes mp_uint_t to size_t for the len argument of the following public facing C functions: mp_obj_tuple_get mp_obj_list_get mp_obj_get_array These functions take a pointer to the len argument (to be filled in by the function) and callers of these functions should update their code so the type of len is changed to size_t. For ports that don't use nan-boxing there should be no change in generate code because the size of the type remains the same (word sized), and in a lot of cases there won't even be a compiler warning if the type remains as mp_uint_t. The reason for this change is to standardise on the use of size_t for variables that count memory (or memory related) sizes/lengths. It helps builds that use nan-boxing.
* py/objnamedtuple: Use size_t where appropriate, instead of mp_uint_t.Damien George2017-03-24
|
* py: Use mp_raise_msg helper function where appropriate.Damien George2016-10-17
| | | | | Saves the following number of bytes of code space: 176 for bare-arm, 352 for minimal, 272 for unix x86-64, 140 for stmhal, 120 for esp8266.
* py/objnamedtuple: Allow passing field names as a tuple.Antonin ENFRUN2016-05-23
| | | | | So the documentation's example works. Besides, a tuple can be more memory efficient.
* py: Fix passing of some wide int types to printf varg format list.Damien George2016-03-14
| | | | | | Passing an mp_uint_t to a %d printf format is incorrect for builds where mp_uint_t is larger than word size (eg a nanboxing build). This patch adds some simple casting to int in these cases.
* py: Change first arg of type.make_new from mp_obj_t to mp_obj_type_t*.Damien George2016-01-11
| | | | | | | | The first argument to the type.make_new method is naturally a uPy type, and all uses of this argument cast it directly to a pointer to a type structure. So it makes sense to just have it a pointer to a type from the very beginning (and a const pointer at that). This patch makes such a change, and removes all unnecessary casting to/from mp_obj_t.
* py: Change type of .make_new and .call args: mp_uint_t becomes size_t.Damien George2016-01-11
| | | | | | | This patch changes the type signature of .make_new and .call object method slots to use size_t for n_args and n_kw (was mp_uint_t. Makes code more efficient when mp_uint_t is larger than a machine word. Doesn't affect ports when size_t and mp_uint_t have the same size.
* py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.Damien George2015-11-29
| | | | | | | | | This allows the mp_obj_t type to be configured to something other than a pointer-sized primitive type. This patch also includes additional changes to allow the code to compile when sizeof(mp_uint_t) != sizeof(void*), such as using size_t instead of mp_uint_t, and various casts.
* py: Add MP_ROM_* macros and mp_rom_* types and use them.Damien George2015-11-29
|
* py: Add attrtuple object, for space-efficient tuples with attr access.Damien George2015-04-21
| | | | | If you need the functionality of a namedtuple but will only make 1 or a few instances, then use an attrtuple instead.
* py: Add %q format support to mp_[v]printf, and use it.Damien George2015-04-16
|
* py: Overhaul and simplify printf/pfenv mechanism.Damien George2015-04-16
| | | | | | | | | | | | | | | | | | | | | | Previous to this patch the printing mechanism was a bit of a tangled mess. This patch attempts to consolidate printing into one interface. All (non-debug) printing now uses the mp_print* family of functions, mainly mp_printf. All these functions take an mp_print_t structure as their first argument, and this structure defines the printing backend through the "print_strn" function of said structure. Printing from the uPy core can reach the platform-defined print code via two paths: either through mp_sys_stdout_obj (defined pert port) in conjunction with mp_stream_write; or through the mp_plat_print structure which uses the MP_PLAT_PRINT_STRN macro to define how string are printed on the platform. The former is only used when MICROPY_PY_IO is defined. With this new scheme printing is generally more efficient (less layers to go through, less arguments to pass), and, given an mp_print_t* structure, one can call mp_print_str for efficiency instead of mp_printf("%s", ...). Code size is also reduced by around 200 bytes on Thumb2 archs.
* py: Combine load_attr and store_attr type methods into one (attr).Damien George2015-04-11
| | | | | | This simplifies the API for objects and reduces code size (by around 400 bytes on Thumb2, and around 2k on x86). Performance impact was measured with Pystone score, but change was barely noticeable.
* objnamedtuple: Accept field list as a string.Paul Sokolovsky2015-03-23
| | | | | This change is required to unbreak some CPython stdlib modules (as included into micropython-lib).
* objnamedtuple: Check that 2nd arg to namedtuple() is a list.Paul Sokolovsky2015-03-22
|
* py: Fix segfault in namedtuple when name is a non-interned stringstijn2015-01-24
| | | | | | | | - namedtuple was wrongly using MP_OBJ_QSTR_VALUE instead of mp_obj_str_get_qstr, so when passed a non-interned string it would segfault; fix this by using mp_obj_str_get_qstr - store the namedtuple field names as qstrs so it is not needed to use mp_obj_str_get_qstr everytime the field name has to be accessed. This also slighty increases performance when fetching attributes
* py, unix: Allow to compile with -Wunused-parameter.Damien George2015-01-20
| | | | See issue #699.
* py: Move to guarded includes, everywhere in py/ core.Damien George2015-01-01
| | | | Addresses issue #1022.
* py: Change namedtuple error messages to reduce code size.Damien George2015-01-01
| | | | | | We are not word-for-word compatible with CPython exceptions, so we are free to make them short but informative in order to reduce code size. Also, try to make messages the same as existing ones where possible.
* py: Make terse_arg_mismatch a global function and use it elsewhere.Damien George2015-01-01
| | | | Reduces code size when MICROPY_ERROR_REPORTING_TERSE is selected.
* objnamedtuple: Make sure to initialize type structure completely.Paul Sokolovsky2015-01-01
|
* py: Allow keyword arguments for namedtuplestijn2015-01-01
|
* py: Use sequence of strings for named tuple initializationstijn2015-01-01
| | | | | | - remove single string initialization style - take list of strings instead - store list in the type for fast lookup
* py: Make functions static where appropriate.Damien George2014-12-10
|
* py: Convert [u]int to mp_[u]int_t where appropriate.Damien George2014-10-03
| | | | Addressing issue #50.
* Change some parts of the core API to use mp_uint_t instead of uint/int.Damien George2014-08-30
| | | | Addressing issue #50, still some way to go yet.
* Rename configuration variables controling Python features.Damien George2014-05-24
| | | | Now of the form MICROPY_PY_*. See issue #35.
* py, unix: Add copyright for modules I worked closely on.Paul Sokolovsky2014-05-13
|
* py: Rename globally-accessible tuple functions, prefix with mp_obj_.Damien George2014-05-11
| | | | | Likely there are other functions that should be renamed, but this is a start.
* objnamedtuple: Support iteration.Paul Sokolovsky2014-05-10
|
* Add license header to (almost) all files.Damien George2014-05-03
| | | | | | | Blanket wide to all .c and .h files. Some files originating from ST are difficult to deal with (license wise) so it was left out of those. Also merged modpyb.h, modos.h, modstm.h and modtime.h in stmhal/.
* py, unix: Make "mpconfig.h" be first included, as other headers depend on it.Paul Sokolovsky2014-05-02
| | | | Specifically, nlr.h does.
* py: Make collections module configurable, enabled by default.Damien George2014-04-26
|
* py: Merge BINARY_OP_SUBSCR and store_subscr (w/ delete) into subscr.Damien George2014-04-17
| | | | mp_obj_t->subscr now does load/store/delete.
* py: Change nlr_jump to nlr_raise, to aid in debugging.Damien George2014-04-05
| | | | | | This does not affect code size or performance when debugging turned off. To address issue #420.
* py: Change mp_const_* objects to macros.Damien George2014-03-29
| | | | Addresses issue #388.
* namedtuple: Inherit unary/binary ops from tuple base class.Paul Sokolovsky2014-03-03
|
* Add basic collections.namedtuple implementation.Paul Sokolovsky2014-03-03