Paul Sokolovsky
9dce823cfd
py/modbuiltins: Implement abs() by dispatching to MP_UNARY_OP_ABS.
...
This allows user classes to implement __abs__ special method, and saves
code size (104 bytes for x86_64), even though during refactor, an issue
was fixed and few optimizations were made:
* abs() of minimum (negative) small int value is calculated properly.
* objint_longlong and objint_mpz avoid allocating new object is the
argument is already non-negative.
2017-09-18 00:06:43 +03:00
Damien George
58321dd985
all: Convert mp_uint_t to mp_unary_op_t/mp_binary_op_t where appropriate
...
The unary-op/binary-op enums are already defined, and there are no
arithmetic tricks used with these types, so it makes sense to use the
correct enum type for arguments that take these values. It also reduces
code size quite a bit for nan-boxing builds.
2017-08-29 13:16:30 +10:00
Alexander Steffen
55f33240f3
all: Use the name MicroPython consistently in comments
...
There were several different spellings of MicroPython present in comments,
when there should be only one.
2017-07-31 18:35:40 +10:00
Tom Collins
145796f037
py,extmod: Some casts and minor refactors to quiet compiler warnings.
2017-07-07 11:32:22 +10:00
Damien George
e269cabe3e
py/objint: In to_bytes(), allow length arg to be any int and check sign.
2017-06-15 14:21:02 +10:00
Damien George
8c5632a869
py/objint: Support "big" byte-order in int.to_bytes().
2017-06-15 13:56:21 +10:00
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