summaryrefslogtreecommitdiffstatshomepage
path: root/py/objint.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,extmod: Some casts and minor refactors to quiet compiler warnings.Tom Collins2017-07-07
|
* py/objint: In to_bytes(), allow length arg to be any int and check sign.Damien George2017-06-15
|
* py/objint: Support "big" byte-order in int.to_bytes().Damien George2017-06-15
|
* py/objint: In int.from_bytes, only create big-int if really needed.Damien George2017-05-06
| | | | | This patch ensures that int.from_bytes only creates a big-int if necessary, by checking the value for a small-int overflow as it's being parsed.
* py/objint: Use unsigned arithmetic when formatting an integer.Damien George2017-04-11
| | | | | Otherwise the edge case of the most negative integer value will not convert correctly.
* py/objint: Extract small int value directly because type is known.Damien George2017-04-11
|
* py/objint: Consolidate mp_obj_new_int_from_float to one implementation.Damien George2017-04-04
| | | | | This reduces code duplication and allows to make mp_classify_fp_as_int static, which reduces code size.
* py: Change mp_uint_t to size_t for mp_obj_str_get_data len arg.Damien George2017-03-29
|
* py/objint: Handle special case of -0 when classifying fp as int.Damien George2017-03-23
| | | | | Otherwise -0.0 is classified as a bigint, which for builds without bigints will lead unexpectedly to an overflow.
* py/objint: Allow to print long-long ints without using the heap.Damien George2017-03-14
| | | | | | | Some stack is allocated to format ints, and when the int implementation uses long-long there should be additional stack allocated compared with the other cases. This patch uses the existing "fmt_int_t" type to determine the amount of stack to allocate.
* py/objint: Convert mp_uint_t to size_t where appropriate.Damien George2017-02-16
|
* py/objint: Fix left-shift overflow in checking for large int.Damien George2017-01-25
|
* py/objint: from_bytes(): Implement "byteorder" param and arbitrary precision.Paul Sokolovsky2017-01-21
| | | | | | | If result guaranteedly fits in a small int, it is handled in objint.c. Otherwise, it is delegated to mp_obj_int_from_bytes_impl(), which should be implemented by individual objint_*.c, similar to mp_obj_int_to_bytes_impl().
* py/objint: Simplify mp_int_format_size and remove unreachable code.Damien George2016-12-28
| | | | | One never needs to format integers with a base larger than 16 (but code can be easily extended beyond this value if needed in the future).
* 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/objint: from_bytes, to_bytes: Require byteorder arg, require "little".Paul Sokolovsky2016-12-09
| | | | | CPython requires byteorder arg, make uPy compatible. As we support only "little", error out on anything else.
* 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/objint: Use size_t for arguments that measure bytes/sizes.Damien George2016-10-11
|
* py: Factor duplicated function to calculate size of formatted int.Damien George2016-10-11
|
* py: Use MP_SMALL_INT_POSITIVE_MASK to check if uint fits in a small int.Damien George2016-03-10
| | | | | Using the original WORD_MSBIT_HIGH-logic resulted in errors when the object model is not REPR_A or REPR_C.
* 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/objint: Fix classification of float so it works for OBJ_REPR_D.Damien George2016-01-08
|
* py: Change mp_obj_int_is_positive to more general mp_obj_int_sign.Damien George2016-01-07
| | | | This function returns the sign (-1, 0 or 1) of the integer object.
* 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 mp_obj_is_float function (macro) and use it where appropriate.Damien George2015-10-20
|
* 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__".
* py: Support conversion of bignum to bytes.Damien George2015-04-25
| | | | | | | This gets int.to_bytes working for bignum, and also struct.pack with 'q' and 'Q' args on 32-bit machines. Addresses issue #1155.
* 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: Fix builtin abs so it works for bools and bignum.Damien George2015-03-14
|
* py: Use m_{new,renew,del} consistently.Damien George2015-02-27
| | | | This is so all memory requests go through the same interface.
* py: Parse big-int/float/imag constants directly in parser.Damien George2015-02-08
| | | | | | | | | Previous to this patch, a big-int, float or imag constant was interned (made into a qstr) and then parsed at runtime to create an object each time it was needed. This is wasteful in RAM and not efficient. Now, these constants are parsed straight away in the parser and turned into objects. This allows constants with large numbers of digits (so addresses issue #1103) and takes us a step closer to #722.
* py: Use float-to-int classifications for mp_obj_new_int_from_float() functionsDavid Steinberg2015-01-24
|
* py: Add float-to-int classification functionDavid Steinberg2015-01-24
|
* py: Remove mp_obj_str_builder and use vstr instead.Damien George2015-01-21
| | | | | | | | | | | | With this patch str/bytes construction is streamlined. Always use a vstr to build a str/bytes object. If the size is known beforehand then use vstr_init_len to allocate only required memory. Otherwise use vstr_init and the vstr will grow as needed. Then use mp_obj_new_str_from_vstr to create a str/bytes object using the vstr memory. Saves code ROM: 68 bytes on stmhal, 108 bytes on bare-arm, and 336 bytes on unix x64.
* py, unix: Allow to compile with -Wunused-parameter.Damien George2015-01-20
| | | | See issue #699.
* py, unix: Allow to compile with -Wsign-compare.Damien George2015-01-16
| | | | See issue #699.
* py: Move to guarded includes, everywhere in py/ core.Damien George2015-01-01
| | | | Addresses issue #1022.
* py: Implement mp_obj_new_int_from_float() for MICROPY_LONGINT_IMPL_NONE.Paul Sokolovsky2014-12-30
|
* py: Partially fix float to int conversion.Paul Sokolovsky2014-12-30
| | | | | | | This fixes conversion when float type has more mantissa bits than small int, and float value has small exponent. This is for example the case of 32-bit platform using doubles, and converting value of time.time(). Conversion of floats with larg exponnet is still not handled correctly.
* 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: Make int.to_bytes work on big endian machine.Damien George2014-10-06
| | | | Partly addresses issue #856.
* py: Convert [u]int to mp_[u]int_t where appropriate.Damien George2014-10-03
| | | | Addressing issue #50.
* py: Enable struct/binary-helper to parse q and Q sized ints.Damien George2014-09-10
| | | | Addresses issue #848.
* py: Change uint to mp_uint_t in runtime.h, stackctrl.h, binary.h.Damien George2014-08-30
| | | | Part of code cleanup, working towards resolving issue #50.
* py: Change all uint to mp_uint_t in obj.h.Damien George2014-08-30
| | | | Part of code cleanup, working towards resolving issue #50.
* py: Save about 200 bytes of ROM by using smaller type for static table.Damien George2014-08-30
|