summaryrefslogtreecommitdiffstatshomepage
path: root/py/obj.c
Commit message (Collapse)AuthorAge
* 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
| * py: Add protection against printing too nested or recursive data structures.Paul Sokolovsky2014-06-28
| | | | | | | | With a test which cannot be automatically validated so far.
* | objstrunicode: Revamp len() handling for unicode, and optimize bool().Paul Sokolovsky2014-06-27
|/
* py: Separate MICROPY_PY_BUILTINS_COMPLEX from MICROPY_PY_BUILTINS_FLOAT.Paul Sokolovsky2014-06-20
| | | | | One thing is wanting to do 1 / 2 and get something else but 0, and quite another - doing rocket science ;-).
* Rename bultins config variables to MICROPY_PY_BUILTINS_*.Damien George2014-06-01
| | | | | | | | | | This renames: MICROPY_PY_FROZENSET -> MICROPY_PY_BUILTINS_FROZENSET MICROPY_PY_PROPERTY -> MICROPY_PY_BUILTINS_PROPERTY MICROPY_PY_SLICE -> MICROPY_PY_BUILTINS_SLICE MICROPY_ENABLE_FLOAT -> MICROPY_PY_BUILTINS_FLOAT See issue #35 for discussion.
* py: Rename MP_OBJ_NOT_SUPPORTED to MP_OBJ_NULL.Damien George2014-05-21
| | | | See issue #608 for justification.
* py: More const usage.Paul Sokolovsky2014-05-17
|
* py: Fix __len__ special method result handling.Paul Sokolovsky2014-05-11
| | | | Having both MP_OBJ_NOT_SUPPORTED and MP_OBJ_NULL is arguably confusing.
* py: Start making good use of mp_const_obj_t.Paul Sokolovsky2014-05-11
|
* py: Make mp_obj_print() handle null object w/o segfault if debug build.Paul Sokolovsky2014-05-10
| | | | Happens regularly when used for debugging.
* 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.