Damien George
58bb73e010
py/objint: In int.from_bytes, only create big-int if really needed.
...
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.
2017-05-06 10:29:09 +10:00
Damien George
e31fbd9b41
py/objint: Use unsigned arithmetic when formatting an integer.
...
Otherwise the edge case of the most negative integer value will not convert
correctly.
2017-04-11 15:18:35 +10:00
Damien George
f66df1efc8
py/objint: Extract small int value directly because type is known.
2017-04-11 15:16:09 +10:00
Damien George
fc245d1ca4
py/objint: Consolidate mp_obj_new_int_from_float to one implementation.
...
This reduces code duplication and allows to make mp_classify_fp_as_int
static, which reduces code size.
2017-04-04 16:45:49 +10:00
Damien George
6b34107537
py: Change mp_uint_t to size_t for mp_obj_str_get_data len arg.
2017-03-29 12:56:45 +11:00
Damien George
c073519ec8
py/objint: Handle special case of -0 when classifying fp as int.
...
Otherwise -0.0 is classified as a bigint, which for builds without bigints
will lead unexpectedly to an overflow.
2017-03-23 23:51:35 +11:00
Damien George
d1ae6ae080
py/objint: Allow to print long-long ints without using the heap.
...
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.
2017-03-14 14:54:20 +11:00
Damien George
da36f5232d
py/objint: Convert mp_uint_t to size_t where appropriate.
2017-02-16 16:51:17 +11:00
Damien George
eaa77455c3
py/objint: Fix left-shift overflow in checking for large int.
2017-01-25 14:39:13 +11:00
Paul Sokolovsky
bec7bfb29d
py/objint: from_bytes(): Implement "byteorder" param and arbitrary precision.
...
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().
2017-01-21 20:14:18 +03:00
Damien George
ea6a958393
py/objint: Simplify mp_int_format_size and remove unreachable code.
...
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).
2016-12-28 12:46:20 +11:00
Damien George
e4af712125
py/objint: Rename mp_obj_int_as_float to mp_obj_int_as_float_impl.
...
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.
2016-12-21 11:46:27 +11:00
Paul Sokolovsky
9d787de2a1
py/objint: from_bytes, to_bytes: Require byteorder arg, require "little".
...
CPython requires byteorder arg, make uPy compatible. As we support only
"little", error out on anything else.
2016-12-09 21:15:16 +03:00
Damien George
7d0d7215d2
py: Use mp_raise_msg helper function where appropriate.
...
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.
2016-10-17 12:17:37 +11:00
Damien George
6dff3df501
py/objint: Use size_t for arguments that measure bytes/sizes.
2016-10-11 13:20:11 +11:00
Damien George
8bb7d958f1
py: Factor duplicated function to calculate size of formatted int.
2016-10-11 13:11:32 +11:00
Damien George
9ae51257bd
py: Use MP_SMALL_INT_POSITIVE_MASK to check if uint fits in a small int.
...
Using the original WORD_MSBIT_HIGH-logic resulted in errors when the
object model is not REPR_A or REPR_C.
2016-03-10 21:52:56 +00:00
Damien George
5b3f0b7f39
py: Change first arg of type.make_new from mp_obj_t to mp_obj_type_t*.
...
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.
2016-01-11 00:49:27 +00:00
Damien George
4b72b3a133
py: Change type signature of builtin funs that take variable or kw args.
...
With this patch the n_args parameter is changed type from mp_uint_t to
size_t.
2016-01-11 00:49:27 +00:00
Damien George
a0c97814df
py: Change type of .make_new and .call args: mp_uint_t becomes size_t.
...
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.
2016-01-11 00:48:41 +00:00
Damien George
da3dffa79d
py/objint: Fix classification of float so it works for OBJ_REPR_D.
2016-01-08 17:57:30 +00:00
Damien George
d6b31e4578
py: Change mp_obj_int_is_positive to more general mp_obj_int_sign.
...
This function returns the sign (-1, 0 or 1) of the integer object.
2016-01-07 14:29:12 +00:00
Damien George
999cedb90f
py: Wrap all obj-ptr conversions in MP_OBJ_TO_PTR/MP_OBJ_FROM_PTR.
...
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-11-29 14:25:35 +00:00
Damien George
cbf7674025
py: Add MP_ROM_* macros and mp_rom_* types and use them.
2015-11-29 14:25:04 +00:00
Damien George
aaef1851a7
py: Add mp_obj_is_float function (macro) and use it where appropriate.
2015-10-20 12:35:17 +01:00