summaryrefslogtreecommitdiffstatshomepage
path: root/py/obj.h
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.
* all: Unify header guard usage.Alexander Steffen2017-07-18
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The code conventions suggest using header guards, but do not define how those should look like and instead point to existing files. However, not all existing files follow the same scheme, sometimes omitting header guards altogether, sometimes using non-standard names, making it easy to accidentally pick a "wrong" example. This commit ensures that all header files of the MicroPython project (that were not simply copied from somewhere else) follow the same pattern, that was already present in the majority of files, especially in the py folder. The rules are as follows. Naming convention: * start with the words MICROPY_INCLUDED * contain the full path to the file * replace special characters with _ In addition, there are no empty lines before #ifndef, between #ifndef and one empty line before #endif. #endif is followed by a comment containing the name of the guard macro. py/grammar.h cannot use header guards by design, since it has to be included multiple times in a single C file. Several other files also do not need header guards as they are only used internally and guaranteed to be included only once: * MICROPY_MPHALPORT_H * mpconfigboard.h * mpconfigport.h * mpthreadport.h * pin_defs_*.h * qstrdefs*.h
* 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.
* 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: Add very simple but correct hashing for float and complex numbers.Damien George2017-04-04
| | | | | | | | | | Hashing of float and complex numbers that are exact (real) integers should return the same integer hash value as hashing the corresponding integer value. Eg hash(1), hash(1.0) and hash(1+0j) should all be the same (this is how Python is specified: if x==y then hash(x)==hash(y)). This patch implements the simplest way of doing float/complex hashing by just converting the value to int and returning that value.
* py/obj.h: Make sequence grow more efficient and support overlapping.Damien George2017-04-02
| | | | | | The first memmove now copies less bytes in some cases (because len_adj <= slice_len), and the memcpy is replaced with memmove to support the possibility that dest and slice regions are overlapping.
* py: Change mp_uint_t to size_t for mp_obj_str_get_data len arg.Damien George2017-03-29
|
* 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/obj: Change mp_uint_t to size_t for mp_obj_get_array_fixed_n len arg.Damien George2017-03-26
|
* py: Define and use MP_OBJ_ITER_BUF_NSLOTS to get size of stack iter buf.Damien George2017-03-23
| | | | | | | | It improves readability of code and reduces the chance to make a mistake. This patch also fixes a bug with nan-boxing builds by rounding up the calculation of the new NSLOTS variable, giving the correct number of slots (being 4) even if mp_obj_t is larger than the native machine size.
* py/sequence: Convert mp_uint_t to size_t where appropriate.Damien George2017-03-23
|
* py: Use size_t as len argument and return type of mp_get_index.Damien George2017-03-23
| | | | | These values are used to compute memory addresses and so size_t is the more appropriate type to use.
* py: Add iter_buf to getiter type method.Damien George2017-02-16
| | | | | | | | | | | | | | | Allows to iterate over the following without allocating on the heap: - tuple - list - string, bytes - bytearray, array - dict (not dict.keys, dict.values, dict.items) - set, frozenset Allows to call the following without heap memory: - all, any, min, max, sum TODO: still need to allocate stack memory in bytecode for iter_buf.
* py/objint: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objexcept: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objclosure: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objfun: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objarray: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objstr: Convert mp_uint_t to size_t (and use int) where appropriate.Damien George2017-02-16
|
* py/objset: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objdict: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objlist: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objtuple: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/map: Change mp_uint_t to size_t where appropriate.Damien George2017-02-08
| | | | | | | | The internal map/set functions now use size_t exclusively for computing addresses. size_t is enough to reach all of available memory when computing addresses so is the right type to use. In particular, for nanbox builds it saves quite a bit of code size and RAM compared to the original use of mp_uint_t (which is 64-bits on nanbox builds).
* py/objint: Rename mp_obj_int_as_float to mp_obj_int_as_float_impl.Damien George2016-12-21
| | | | | | And also simplify it to remove the check for small int. This can be done because this function is only ever called if the argument is not a small int.
* py: Specialise builtin funcs to use separate type for fixed arg count.Damien George2016-10-21
| | | | | | | | | | | | | | | Builtin functions with a fixed number of arguments (0, 1, 2 or 3) are quite common. Before this patch the wrapper for such a function cost 3 machine words. After this patch it only takes 2, which can reduce the code size by quite a bit (and pays off even more, the more functions are added). It also makes function dispatch slightly more efficient in CPU usage, and furthermore reduces stack usage for these cases. On x86 and Thumb archs the dispatch functions are now tail-call optimised by the compiler. The bare-arm port has its code size increase by 76 bytes, but stmhal drops by 904 bytes. Stack usage by these builtin functions is decreased by 48 bytes on Thumb2 archs.
* py: Be more specific with MP_DECLARE_CONST_FUN_OBJ macros.Damien George2016-10-21
| | | | | | | In order to have more fine-grained control over how builtin functions are constructed, the MP_DECLARE_CONST_FUN_OBJ macros are made more specific, with suffix of _0, _1, _2, _3, _VAR, _VAR_BETEEN or _KW. These names now match the MP_DEFINE_CONST_FUN_OBJ macros.
* 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/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.
* all: Rename mp_obj_type_t::stream_p to protocol.Paul Sokolovsky2016-06-18
| | | | | It's now used for more than just stream protocol (e.g. pin protocol), so don't use false names.
* py/obj: Add warning note about get_array return value and GC blocks.Damien George2016-05-04
|
* py/obj.h: When constructing a small-int cast to mp_uint_t for bit-shift.Damien George2016-04-26
| | | | | | The C standard says that left-shifting a signed value (on the LHS of the operator) is undefined. So we cast to an unsigned integer before the shift. gcc does not issue a warning about this, but clang does.
* py: add async/await/async for/async with syntaxpohmelie2016-04-13
| | | | | | | | They are sugar for marking function as generator, "yield from" and pep492 python "semantically equivalents" respectively. @dpgeorge was the original author of this patch, but @pohmelie made changes to implement `async for` and `async with`.
* py: Move stream-related declarations from obj.h to stream.h.Paul Sokolovsky2016-04-05
|
* py/obj.h: Add comment why mp_fun_kw_t takes non-const mp_map_t*.Paul Sokolovsky2016-04-04
| | | | | | mp_fun_kw_t takes mp_map_t* (and not const mp_map_t*) to ease passing this arg to mp_map_lookup(), which may modify its arg, depending on flags.
* py: For mp_buffer_info_t, change len type from mp_uint_t to size_t.Damien George2016-03-15
|
* py/obj.h: If not float support is enabled, define mp_obj_is_float(o) to false.Paul Sokolovsky2016-02-14
| | | | | We have so many configuration options, that finally having shortcuts like this is helpful and cuts on number of ifdef's.
* py/inlineasm: Add ability to specify return type of asm_thumb funcs.Damien George2016-01-27
| | | | | | | | | | Supported return types are: object, bool, int, uint. For example: @micropython.asm_thumb def foo(r0, r1) -> uint: add(r0, r0, r1)
* 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 signature of builtin funs that take variable or kw args.Damien George2016-01-11
| | | | | With this patch the n_args parameter is changed type from mp_uint_t to size_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: Remove long-obsolete mp_method_t typedef.Damien George2016-01-10
|
* py/obj: For OBJ_REPR_D, use uint32_t cast when extracting qstr value.Damien George2016-01-08
|
* py: Change struct and macro for builtin fun so they can be type checked.Damien George2016-01-03
|
* py: Change exception traceback data to use size_t instead of mp_uint_t.Damien George2016-01-02
| | | | | The traceback array stores qstrs and line numbers. qstrs are typed as size_t, and line numbers should safely fit in size_t as well.
* py/objstr: Make sure that b"%s" % b"foo" uses undecorated bytes value.Paul Sokolovsky2015-12-20
| | | | | I.e. the expected result for above is b"foo", whereas previously we got b"b'foo'".
* py/obj: Fix float constants for MICROPY_OBJ_REPR_C.Damien George2015-12-18
|
* py/objpolyiter: Implement instance-polymorphic iterator type.Paul Sokolovsky2015-12-14
| | | | | | | This allows to have single itertaor type for various internal iterator types (save rodata space by not having repeating almost-empty type structures). It works by looking "iternext" method stored in particular object instance (should be first object field after "base").