summaryrefslogtreecommitdiffstatshomepage
path: root/py/obj.c
Commit message (Collapse)AuthorAge
* 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: Use mp_raise_TypeError/mp_raise_ValueError helpers where possible.Damien George2017-03-28
| | | | Saves 168 bytes on bare-arm.
* py/obj: Change mp_uint_t to size_t for mp_obj_get_array_fixed_n len arg.Damien George2017-03-26
|
* 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: 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/{modbuiltins,obj}: Use MP_PYTHON_PRINTER where possible.Paul Sokolovsky2016-10-22
|
* 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.
* unix: Enable MICROPY_PY_STR_BYTES_CMP_WARN.Paul Sokolovsky2016-07-22
| | | | Also, fix a warning text (remove "duplicate" BytesWarning).
* py/obj: Issue a warning when str and bytes objects are compared.Paul Sokolovsky2016-07-22
| | | | | | | | | | Something like: if foo == "bar": will be always false if foo is b"bar". In CPython, warning is issued if interpreter is started as "python3 -b". In MicroPython, MICROPY_PY_STR_BYTES_CMP_WARN setting controls it.
* py/obj: Add warning note about get_array return value and GC blocks.Damien George2016-05-04
|
* 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 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: 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: Make float representation configurable with object representation.Damien George2015-10-20
|
* py: Add mp_obj_is_float function (macro) and use it where appropriate.Damien George2015-10-20
|
* py: Inline single use of mp_obj_str_get_len in mp_obj_len_maybe.Damien George2015-09-03
| | | | | | Gets rid of redundant double check for string type. Also remove obsolete declaration of mp_obj_str_get_hash.
* 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__".
* obj: Handle user instance hash based on Python adhoc rules.Paul Sokolovsky2015-05-05
| | | | | | User instances are hashable by default (using __hash__ inherited from "object"). But if __eq__ is defined and __hash__ not defined in particular class, instance is not hashable.
* objsingleton: New home for Ellipsis and NotImplemented.Paul Sokolovsky2015-05-05
| | | | | | | Having NotImplemented as MP_OBJ_SENTINEL turned out to be problematic (it needs to be checked for in a lot of places, otherwise it'll crash as would pass MP_OBJ_IS_OBJ()), so made a proper singleton value like Ellipsis, both of them sharing the same type.
* modbuiltins: Add NotImplemented builtin constant.Paul Sokolovsky2015-05-04
| | | | | | | | | | | | From https://docs.python.org/3/library/constants.html#NotImplemented : "Special value which should be returned by the binary special methods (e.g. __eq__(), __lt__(), __add__(), __rsub__(), etc.) to indicate that the operation is not implemented with respect to the other type; may be returned by the in-place binary special methods (e.g. __imul__(), __iand__(), etc.) for the same purpose. Its truth value is true." Some people however appear to abuse it to mean "no value" when None is a legitimate value (don't do that).
* py: Add %q format support to mp_[v]printf, and use it.Damien George2015-04-16
|
* py: Make mp_sys_stdout_print object, wrapping sys.stdout for mp_print*.Damien George2015-04-16
| | | | | So now all printing should go via either mp_plat_print or mp_sys_stdout_print.
* 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: Use a dummy type for referring to extern structsstijn2015-04-09
| | | | | Fixes msvc linker warnings about mismatching sizes between the mp_obj_fdfile_t struct defined in file.c and the mp_uint_t declarations found in modsys.c and modbuiltins.c
* py: Fix mp_obj_print() to work when Python streams are not used.Paul Sokolovsky2015-02-17
|
* py: Revamp mp_obj_print() to use Python streams.Paul Sokolovsky2015-02-17
| | | | | | | Most of printing infrastructure now uses streams, but mp_obj_print() used libc's printf(), which led to weird buffering issues in output. So, switch mp_obj_print() to streams too, even though it may make sense to move it to a separate file, as it is purely a debugging function now.
* py: Check for NDEBUG using #ifdef rather than #if.Damien George2015-01-25
| | | | | Defining NDEBUG (to any value, even 0) disables debugging. Otherwise, if it's not defined, debugging is enabled.
* py, unix: Allow to compile with -Wsign-compare.Damien George2015-01-16
| | | | See issue #699.
* py: Can compile with -Wmissing-declarations and -Wmissing-prototypes.Damien George2015-01-12
|
* py: Implement fallback for equality check for all types.Damien George2015-01-11
| | | | | Return "not equal" for objects that don't implement equality check. This is as per Python specs.
* py: Move to guarded includes, everywhere in py/ core.Damien George2015-01-01
| | | | Addresses issue #1022.
* modsys: Add sys.print_exception(exc, file=sys.stdout) function.Paul Sokolovsky2014-12-08
| | | | | | | | | | | | The function is modeled after traceback.print_exception(), but unbloated, and put into existing module to save overhead on adding another module. Compliant traceback.print_exception() is intended to be implemented in micropython-lib in terms of sys.print_exception(). This change required refactoring mp_obj_print_exception() to take pfenv_t interface arguments. Addresses #751.
* py: Rename mp_obj_int_get to mp_obj_int_get_truncated; fix struct.pack.Damien George2014-12-05
| | | | | | | | | | | mp_obj_int_get_truncated is used as a "fast path" int accessor that doesn't check for overflow and returns the int truncated to the machine word size, ie mp_int_t. Use mp_obj_int_get_truncated to fix struct.pack when packing maximum word sized values. Addresses issues #779 and #998.
* py: Use __hash__ method if a type defines itstijn2014-11-15
|
* py: Use shorter, static error msgs when ERROR_REPORTING_TERSE enabled.Damien George2014-11-06
| | | | | | | | 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.
* py: Fix builtin callable so it checks user-defined instances correctly.Damien George2014-11-03
| | | | Addresses issue #953.
* py: Rename mp_builtin_id to mp_obj_id and make it public.Damien George2014-09-07
|
* py: Small simplifications in tuple and list accessors.Damien George2014-08-30
|
* py: Remove use of int type in obj.h.Damien George2014-08-30
| | | | Part of code cleanup, working towards resolving issue #50.
* py: Make tuple and list use mp_int_t/mp_uint_t.Damien George2014-08-30
| | | | Part of code cleanup, to resolve issue #50.
* py: Fix bug where GC collected native/viper/asm function data.Damien George2014-08-24
| | | | | | | | 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.
* py: Implement builtin reversed() function.Damien George2014-08-12
| | | | | | | | reversed function now implemented, and works for tuple, list, str, bytes and user objects with __len__ and __getitem__. Renamed mp_builtin_len to mp_obj_len to make it publically available (eg for reversed).
* py: mp_buffer_info_t::buf may be valid, but NULL for empty objects.Paul Sokolovsky2014-08-10
| | | | | | This happens for example for zero-size arrays. As .get_buffer() method now has explicit return value, it's enough to distinguish success vs failure of getting buffer.
* py: Make MP_OBJ_NEW_SMALL_INT cast arg to mp_int_t itself.Damien George2014-07-31
| | | | Addresses issue #724.
* py: Make long ints hashable.Damien George2014-07-24
| | | | Addresses issue #765.
* Rename machine_(u)int_t to mp_(u)int_t.Damien George2014-07-03
| | | | See discussion in issue #50.
* stackctrl: Add "mp_" prefix.Paul Sokolovsky2014-07-01
|
* Merge branch 'master' into unicodeDamien George2014-06-28
|\ | | | | | | | | Conflicts: py/mpconfig.h