aboutsummaryrefslogtreecommitdiff
path: root/py/objtype.c
AgeCommit message (Collapse)Author
2015-11-29py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.Damien George
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.
2015-06-13py: Add MP_BINARY_OP_DIVMOD to simplify and consolidate divmod builtin.Damien George
2015-05-12py: Add mp_obj_get_int_truncated and use it where appropriate.Damien George
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.
2015-05-12py: Convert hash API to use MP_UNARY_OP_HASH instead of ad-hoc function.Damien George
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__".
2015-05-04py: Check that arg to object.__new__ is a user-defined type.Damien George
Addresses issue #1203.
2015-04-16py: Add %q format support to mp_[v]printf, and use it.Damien George
2015-04-16py: Overhaul and simplify printf/pfenv mechanism.Damien George
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.
2015-04-11py: Combine load_attr and store_attr type methods into one (attr).Damien George
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.
2015-04-04py: Implement delete for property and descriptors.Damien George
Without this patch deleting a property, or class with descriptor, will call the setter with a NULL value and lead to a crash.
2015-04-04py: Some trivial cosmetic changes, for code style consistency.Damien George
2015-03-31objtype: Add special unary methods __pos__, __neg__, __invert__.Paul Sokolovsky
Conditional on MICROPY_PY_ALL_SPECIAL_METHODS.
2015-03-26py: Add optional support for descriptors' __get__ and __set__ methods.stijn
Disabled by default. Enabled on unix and windows ports.
2015-03-21py: Combine duplicated code that converts members from a lookup.Damien George
Despite initial guess, this code factoring does not hamper performance. In fact it seems to improve speed by a little: running pystone(1.2) on pyboard (which gives a very stable result) this patch takes pystones from 1729.51 up to 1742.16. Also, pystones on x64 increase by around the same proportion (but it's much noisier). Taking a look at the generated machine code, stack usage with this patch is unchanged, and call is tail-optimised with all arguments in registers. Code size decreases by about 50 bytes on Thumb2 archs.
2015-03-20objtype: More comment clarification for attribute lookup.Paul Sokolovsky
2015-03-17objtype: Clarify comment why we call mp_load_method_maybe() for native sub-obj.Paul Sokolovsky
2015-03-16objtype: Refactor dealing with native sub-objects for clarity.Paul Sokolovsky
2015-03-16objtype: mp_obj_class_lookup: Remove implausible condition.Paul Sokolovsky
We already have branch for lookup->is_type == true, so here it's guaranteed to be false.
2015-03-16objtype: Clarify comment for mp_obj_class_lookup().Paul Sokolovsky
2015-03-16objtype: Clarify code by consistently using common subexpression.Paul Sokolovsky
2015-02-22py: Add few more special methods.Paul Sokolovsky
2015-02-15py: Simplify and remove redundant code for __iter__ method lookup.Damien George
2015-02-14py: Cleanup duplication in instance_is_callable/instance_call.stijn
2015-02-09py: Don't unnecessarily create a bound method.Damien George
2015-02-09py: Allow subclass of native object to delegate to the native buffer_p.Damien George
Addresses issue #1109.
2015-02-08py: Fix instance lookup, since object is not a real type.Damien George
2015-01-31py: Add MICROPY_PY_ALL_SPECIAL_METHODS and __iadd__ special method under it.Paul Sokolovsky
2015-01-27py: Specify unary/binary op name in TypeError error message.Damien George
Eg, "() + 1" now tells you that __add__ is not supported for tuple and int types (before it just said the generic "binary operator"). We reuse the table of names for slot lookup because it would be a waste of code space to store the pretty name for each operator.
2015-01-20py: Use mp_arg_check_num in some _make_new functions.Damien George
Reduces stmhal code size by about 250 bytes.
2015-01-20py, unix: Allow to compile with -Wunused-parameter.Damien George
See issue #699.
2015-01-11py: Remove unnecessary BINARY_OP_EQUAL code that just checks pointers.Damien George
Previous patch c38dc3ccc76d1a9bf867704f43ea5d15da3fea7b allowed any object to be compared with any other, using pointer comparison for a fallback. As such, existing code which checked for this case is no longer needed.
2015-01-08tests: Add test for when instance member overrides class member.Damien George
2015-01-07py: Add option to cache map lookup results in bytecode.Damien George
This is a simple optimisation inspired by JITing technology: we cache in the bytecode (using 1 byte) the offset of the last successful lookup in a map. This allows us next time round to check in that location in the hash table (mp_map_t) for the desired entry, and if it's there use that entry straight away. Otherwise fallback to a normal map lookup. Works for LOAD_NAME, LOAD_GLOBAL, LOAD_ATTR and STORE_ATTR opcodes. On a few tests it gives >90% cache hit and greatly improves speed of code. Disabled by default. Enabled for unix and stmhal ports.
2015-01-01py: Move to guarded includes, everywhere in py/ core.Damien George
Addresses issue #1022.
2014-12-28showbc: Print operation mnemonic in BINARY_OP.Paul Sokolovsky
2014-11-06py: Use shorter, static error msgs when ERROR_REPORTING_TERSE enabled.Damien George
Going from MICROPY_ERROR_REPORTING_NORMAL to MICROPY_ERROR_REPORTING_TERSE now saves 2020 bytes ROM for ARM Thumb2, and 2200 bytes ROM for 32-bit x86. This is about a 2.5% code size reduction for bare-arm.
2014-11-05py: Fix some macros defines; cleanup some includes.Damien George
2014-11-03py: Explicitly set uninitialised struct member to false.Damien George
Uninitialised struct members get a default value of 0/false, so this is not strictly needed. But it actually decreases code size because when all members are initialised the compiler doesn't need to insert a call to memset to clear everything. In other words, setting 1 extra member to 0 uses less code than calling memset. ROM savings in bytes: 32-bit unix: 100; bare-arm: 44; stmhal: 52.
2014-11-03py: Fix builtin callable so it checks user-defined instances correctly.Damien George
Addresses issue #953.
2014-10-23py: Use MP_OBJ_NULL instead of NULL in a few places.Damien George
2014-08-30py: Make tuple and list use mp_int_t/mp_uint_t.Damien George
Part of code cleanup, to resolve issue #50.
2014-08-30Change some parts of the core API to use mp_uint_t instead of uint/int.Damien George
Addressing issue #50, still some way to go yet.
2014-08-26py: Add dispatch for user defined ==, >, <=, >=.Damien George
Addresses issue #827.
2014-08-24py: Fix bug where GC collected native/viper/asm function data.Damien George
Because (for Thumb) a function pointer has the LSB set, pointers to dynamic functions in RAM (eg native, viper or asm functions) were not being traced by the GC. This patch is a comprehensive fix for this. Addresses issue #820.
2014-07-05py: Automatically ake __new__ a staticmethod.Damien George
Addresses issue #622.
2014-07-03Rename machine_(u)int_t to mp_(u)int_t.Damien George
See discussion in issue #50.
2014-06-10py: Implement __contains__ special method.Damien George
2014-06-08objtype: Fix passing of class param to inherited classmethods.Paul Sokolovsky
This is getting more and more tangled, but that's old news.
2014-06-08objtype: Optimize stack usage mp_obj_class_lookup().Paul Sokolovsky
As before, instead of pushing constant values on stack again and again, just pass around pointer to a structure.
2014-06-08objtype: Enable __lt__ method support for instances.Paul Sokolovsky
2014-06-06Change comments (mainly URLs) to no longer specifically say Python 3.3Chris Angelico