blob: e8d86ad7ec03c72eacc9e72629ebe6135441ef3c [file] [log] [blame]
Damien George04b91472014-05-03 23:27:38 +01001/*
2 * This file is part of the Micro Python project, http://micropython.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2013, 2014 Damien P. George
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a copy
9 * of this software and associated documentation files (the "Software"), to deal
10 * in the Software without restriction, including without limitation the rights
11 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the Software is
13 * furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 * THE SOFTWARE.
25 */
26
Damien George660aef62014-04-02 12:22:07 +010027#include <stdlib.h>
Damien George45b43c22014-01-05 01:50:45 +000028#include <assert.h>
Dave Hylandsc4029e52014-04-07 11:19:51 -070029#include <string.h>
Damien George45b43c22014-01-05 01:50:45 +000030
Damien George51dfcb42015-01-01 20:27:54 +000031#include "py/nlr.h"
32#include "py/parsenum.h"
33#include "py/smallint.h"
34#include "py/objint.h"
35#include "py/objstr.h"
36#include "py/runtime0.h"
37#include "py/runtime.h"
Paul Sokolovsky48b35722014-01-12 17:30:48 +020038
Damien Georgefb510b32014-06-01 13:32:54 +010039#if MICROPY_PY_BUILTINS_FLOAT
Damien George6433bd92014-03-30 23:13:16 +010040#include <math.h>
41#endif
42
Damien Georgee8208a72014-04-04 15:08:23 +010043// This dispatcher function is expected to be independent of the implementation of long int
Damien Georgeecc88e92014-08-30 00:35:11 +010044STATIC mp_obj_t mp_obj_int_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
Damien Georgeff8dd3f2015-01-20 12:47:20 +000045 (void)type_in;
Damien Georgeee7a8802014-05-11 18:37:21 +010046 mp_arg_check_num(n_args, n_kw, 0, 2, false);
Damien George20006db2014-01-18 14:10:48 +000047
Damien George45b43c22014-01-05 01:50:45 +000048 switch (n_args) {
49 case 0:
50 return MP_OBJ_NEW_SMALL_INT(0);
51
52 case 1:
Damien George813ed3b2014-05-28 14:09:46 +010053 if (MP_OBJ_IS_INT(args[0])) {
54 // already an int (small or long), just return it
55 return args[0];
Dave Hylandsb7f7c652014-08-26 12:44:46 -070056 } else if (MP_OBJ_IS_STR_OR_BYTES(args[0])) {
Damien George5573f9f2014-01-15 22:58:39 +000057 // a string, parse it
Damien Georged182b982014-08-30 14:19:41 +010058 mp_uint_t l;
Damien George698ec212014-02-08 18:17:23 +000059 const char *s = mp_obj_str_get_data(args[0], &l);
Damien George20773972014-02-22 18:12:43 +000060 return mp_parse_num_integer(s, l, 0);
Damien Georgefb510b32014-06-01 13:32:54 +010061#if MICROPY_PY_BUILTINS_FLOAT
Damien George6433bd92014-03-30 23:13:16 +010062 } else if (MP_OBJ_IS_TYPE(args[0], &mp_type_float)) {
Paul Sokolovsky12033df2014-12-30 00:22:10 +020063 return mp_obj_new_int_from_float(mp_obj_float_get(args[0]));
Damien George6433bd92014-03-30 23:13:16 +010064#endif
Damien George5573f9f2014-01-15 22:58:39 +000065 } else {
Damien George813ed3b2014-05-28 14:09:46 +010066 // try to convert to small int (eg from bool)
Damien George5573f9f2014-01-15 22:58:39 +000067 return MP_OBJ_NEW_SMALL_INT(mp_obj_get_int(args[0]));
68 }
Damien George45b43c22014-01-05 01:50:45 +000069
xybc178ea42014-01-14 21:39:05 +080070 case 2:
Damien Georgeee7a8802014-05-11 18:37:21 +010071 default: {
Damien George5573f9f2014-01-15 22:58:39 +000072 // should be a string, parse it
73 // TODO proper error checking of argument types
Damien Georged182b982014-08-30 14:19:41 +010074 mp_uint_t l;
Damien George698ec212014-02-08 18:17:23 +000075 const char *s = mp_obj_str_get_data(args[0], &l);
Damien George20773972014-02-22 18:12:43 +000076 return mp_parse_num_integer(s, l, mp_obj_get_int(args[1]));
Damien George5fa93b62014-01-22 14:35:10 +000077 }
Damien George45b43c22014-01-05 01:50:45 +000078 }
79}
80
Damien Georgee8208a72014-04-04 15:08:23 +010081void mp_obj_int_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
Damien Georgeff8dd3f2015-01-20 12:47:20 +000082 (void)kind;
Dave Hylandsc4029e52014-04-07 11:19:51 -070083 // The size of this buffer is rather arbitrary. If it's not large
84 // enough, a dynamic one will be allocated.
Damien George40f3c022014-07-03 13:25:24 +010085 char stack_buf[sizeof(mp_int_t) * 4];
Dave Hylandsc4029e52014-04-07 11:19:51 -070086 char *buf = stack_buf;
Damien George42f3de92014-10-03 17:44:14 +000087 mp_uint_t buf_size = sizeof(stack_buf);
88 mp_uint_t fmt_size;
Dave Hylandsc4029e52014-04-07 11:19:51 -070089
90 char *str = mp_obj_int_formatted(&buf, &buf_size, &fmt_size, self_in, 10, NULL, '\0', '\0');
91 print(env, "%s", str);
92
93 if (buf != stack_buf) {
94 m_free(buf, buf_size);
Damien George5fa93b62014-01-22 14:35:10 +000095 }
Damien George45b43c22014-01-05 01:50:45 +000096}
Paul Sokolovsky48b35722014-01-12 17:30:48 +020097
Dave Hylandsc4029e52014-04-07 11:19:51 -070098#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
Damien George88d7bba2014-04-08 23:30:46 +010099typedef mp_longint_impl_t fmt_int_t;
Dave Hylandsc4029e52014-04-07 11:19:51 -0700100#else
Damien George40f3c022014-07-03 13:25:24 +0100101typedef mp_int_t fmt_int_t;
Dave Hylandsc4029e52014-04-07 11:19:51 -0700102#endif
103
Damien George1c70cbf2014-08-30 00:38:16 +0100104STATIC const uint8_t log_base2_floor[] = {
Dave Hylandsc4029e52014-04-07 11:19:51 -0700105 0,
106 0, 1, 1, 2,
107 2, 2, 2, 3,
108 3, 3, 3, 3,
109 3, 3, 3, 4,
110 4, 4, 4, 4,
111 4, 4, 4, 4,
112 4, 4, 4, 4,
113 4, 4, 4, 5
114};
115
Damien George88d7bba2014-04-08 23:30:46 +0100116STATIC uint int_as_str_size_formatted(uint base, const char *prefix, char comma) {
Dave Hylandsc4029e52014-04-07 11:19:51 -0700117 if (base < 2 || base > 32) {
118 return 0;
119 }
120
121 uint num_digits = sizeof(fmt_int_t) * 8 / log_base2_floor[base] + 1;
122 uint num_commas = comma ? num_digits / 3: 0;
123 uint prefix_len = prefix ? strlen(prefix) : 0;
124 return num_digits + num_commas + prefix_len + 2; // +1 for sign, +1 for null byte
125}
126
Paul Sokolovskyd72bc272014-06-06 23:08:37 +0300127// This routine expects you to pass in a buffer and size (in *buf and *buf_size).
Dave Hylandsc4029e52014-04-07 11:19:51 -0700128// If, for some reason, this buffer is too small, then it will allocate a
129// buffer and return the allocated buffer and size in *buf and *buf_size. It
130// is the callers responsibility to free this allocated buffer.
131//
132// The resulting formatted string will be returned from this function and the
133// formatted size will be in *fmt_size.
Damien George42f3de92014-10-03 17:44:14 +0000134char *mp_obj_int_formatted(char **buf, mp_uint_t *buf_size, mp_uint_t *fmt_size, mp_const_obj_t self_in,
Dave Hylandsc4029e52014-04-07 11:19:51 -0700135 int base, const char *prefix, char base_char, char comma) {
Damien George88d7bba2014-04-08 23:30:46 +0100136 fmt_int_t num;
137 if (MP_OBJ_IS_SMALL_INT(self_in)) {
138 // A small int; get the integer value to format.
139 num = mp_obj_get_int(self_in);
140#if MICROPY_LONGINT_IMPL != MICROPY_LONGINT_IMPL_NONE
141 } else if (MP_OBJ_IS_TYPE(self_in, &mp_type_int)) {
142 // Not a small int.
143#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_LONGLONG
Damien George503d6112014-05-28 14:07:21 +0100144 const mp_obj_int_t *self = self_in;
Damien George40f3c022014-07-03 13:25:24 +0100145 // Get the value to format; mp_obj_get_int truncates to mp_int_t.
Damien George88d7bba2014-04-08 23:30:46 +0100146 num = self->val;
147#else
148 // Delegate to the implementation for the long int.
149 return mp_obj_int_formatted_impl(buf, buf_size, fmt_size, self_in, base, prefix, base_char, comma);
150#endif
151#endif
152 } else {
153 // Not an int.
Paul Sokolovskyd72bc272014-06-06 23:08:37 +0300154 **buf = '\0';
Dave Hylandsc4029e52014-04-07 11:19:51 -0700155 *fmt_size = 0;
156 return *buf;
157 }
Damien George88d7bba2014-04-08 23:30:46 +0100158
Dave Hylandsc4029e52014-04-07 11:19:51 -0700159 char sign = '\0';
160 if (num < 0) {
161 num = -num;
162 sign = '-';
163 }
164
165 uint needed_size = int_as_str_size_formatted(base, prefix, comma);
166 if (needed_size > *buf_size) {
167 *buf = m_new(char, needed_size);
168 *buf_size = needed_size;
169 }
170 char *str = *buf;
171
172 char *b = str + needed_size;
173 *(--b) = '\0';
174 char *last_comma = b;
175
176 if (num == 0) {
177 *(--b) = '0';
178 } else {
179 do {
180 int c = num % base;
181 num /= base;
182 if (c >= 10) {
183 c += base_char - 10;
184 } else {
185 c += '0';
186 }
187 *(--b) = c;
188 if (comma && num != 0 && b > str && (last_comma - b) == 3) {
189 *(--b) = comma;
190 last_comma = b;
191 }
192 }
193 while (b > str && num != 0);
194 }
195 if (prefix) {
196 size_t prefix_len = strlen(prefix);
197 char *p = b - prefix_len;
198 if (p > str) {
199 b = p;
200 while (*prefix) {
201 *p++ = *prefix++;
202 }
203 }
204 }
205 if (sign && b > str) {
206 *(--b) = sign;
207 }
208 *fmt_size = *buf + needed_size - b - 1;
209
210 return b;
211}
212
Damien George88d7bba2014-04-08 23:30:46 +0100213#if MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
214
Damien Georgeffe911d2014-07-24 14:21:37 +0100215mp_int_t mp_obj_int_hash(mp_obj_t self_in) {
216 return MP_OBJ_SMALL_INT_VALUE(self_in);
217}
218
Dave Hylandsc4029e52014-04-07 11:19:51 -0700219bool mp_obj_int_is_positive(mp_obj_t self_in) {
220 return mp_obj_get_int(self_in) >= 0;
221}
Dave Hylandsc4029e52014-04-07 11:19:51 -0700222
Damien George660aef62014-04-02 12:22:07 +0100223// This is called for operations on SMALL_INT that are not handled by mp_unary_op
Damien Georgeecc88e92014-08-30 00:35:11 +0100224mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) {
Damien George6ac5dce2014-05-21 19:42:43 +0100225 return MP_OBJ_NULL; // op not supported
Paul Sokolovsky9b00dad2014-01-27 09:05:50 +0200226}
227
Damien George660aef62014-04-02 12:22:07 +0100228// This is called for operations on SMALL_INT that are not handled by mp_binary_op
Damien Georgeecc88e92014-08-30 00:35:11 +0100229mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
Damien Georgee8208a72014-04-04 15:08:23 +0100230 return mp_obj_int_binary_op_extra_cases(op, lhs_in, rhs_in);
Paul Sokolovsky48b35722014-01-12 17:30:48 +0200231}
232
233// This is called only with strings whose value doesn't fit in SMALL_INT
Damien George4abff752014-08-30 14:59:21 +0100234mp_obj_t mp_obj_new_int_from_str_len(const char **str, mp_uint_t len, bool neg, mp_uint_t base) {
Damien Georgeea13f402014-04-05 18:32:08 +0100235 nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "long int not supported in this build"));
Damien George23005372014-01-13 19:39:01 +0000236 return mp_const_none;
Paul Sokolovsky48b35722014-01-12 17:30:48 +0200237}
238
Damien George9d68e9c2014-03-12 15:38:15 +0000239// This is called when an integer larger than a SMALL_INT is needed (although val might still fit in a SMALL_INT)
240mp_obj_t mp_obj_new_int_from_ll(long long val) {
Damien Georgeea13f402014-04-05 18:32:08 +0100241 nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "small int overflow"));
Damien George9d68e9c2014-03-12 15:38:15 +0000242 return mp_const_none;
243}
244
Damien George95307432014-09-10 22:10:33 +0100245// This is called when an integer larger than a SMALL_INT is needed (although val might still fit in a SMALL_INT)
246mp_obj_t mp_obj_new_int_from_ull(unsigned long long val) {
247 nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "small int overflow"));
248 return mp_const_none;
249}
250
Damien George40f3c022014-07-03 13:25:24 +0100251mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value) {
Paul Sokolovsky48b35722014-01-12 17:30:48 +0200252 // SMALL_INT accepts only signed numbers, of one bit less size
253 // then word size, which totals 2 bits less for unsigned numbers.
254 if ((value & (WORD_MSBIT_HIGH | (WORD_MSBIT_HIGH >> 1))) == 0) {
255 return MP_OBJ_NEW_SMALL_INT(value);
256 }
Damien Georgeea13f402014-04-05 18:32:08 +0100257 nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "small int overflow"));
Damien George23005372014-01-13 19:39:01 +0000258 return mp_const_none;
Paul Sokolovsky48b35722014-01-12 17:30:48 +0200259}
260
Paul Sokolovskyf79cd6a2014-12-30 00:33:32 +0200261#if MICROPY_PY_BUILTINS_FLOAT
262mp_obj_t mp_obj_new_int_from_float(mp_float_t val) {
263 // TODO raise an exception if the int won't fit
264 mp_int_t i = MICROPY_FLOAT_C_FUN(trunc)(val);
265 return mp_obj_new_int(i);
266}
267#endif
268
Damien George40f3c022014-07-03 13:25:24 +0100269mp_obj_t mp_obj_new_int(mp_int_t value) {
Damien Georged1e355e2014-05-28 14:51:12 +0100270 if (MP_SMALL_INT_FITS(value)) {
Paul Sokolovsky48b35722014-01-12 17:30:48 +0200271 return MP_OBJ_NEW_SMALL_INT(value);
272 }
Damien Georgeea13f402014-04-05 18:32:08 +0100273 nlr_raise(mp_obj_new_exception_msg(&mp_type_OverflowError, "small int overflow"));
Damien George23005372014-01-13 19:39:01 +0000274 return mp_const_none;
Paul Sokolovsky48b35722014-01-12 17:30:48 +0200275}
Paul Sokolovskyd26b3792014-01-18 16:07:16 +0200276
Damien Georgebe6d8be2014-12-05 23:13:52 +0000277mp_int_t mp_obj_int_get_truncated(mp_const_obj_t self_in) {
Paul Sokolovskyd26b3792014-01-18 16:07:16 +0200278 return MP_OBJ_SMALL_INT_VALUE(self_in);
279}
280
Damien George40f3c022014-07-03 13:25:24 +0100281mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in) {
Paul Sokolovskyd26b3792014-01-18 16:07:16 +0200282 return MP_OBJ_SMALL_INT_VALUE(self_in);
283}
284
Damien Georgefb510b32014-06-01 13:32:54 +0100285#if MICROPY_PY_BUILTINS_FLOAT
Damien Georgeeabdf672014-03-22 20:54:01 +0000286mp_float_t mp_obj_int_as_float(mp_obj_t self_in) {
287 return MP_OBJ_SMALL_INT_VALUE(self_in);
288}
289#endif
290
Damien George5fa93b62014-01-22 14:35:10 +0000291#endif // MICROPY_LONGINT_IMPL == MICROPY_LONGINT_IMPL_NONE
292
Damien Georgee8208a72014-04-04 15:08:23 +0100293// This dispatcher function is expected to be independent of the implementation of long int
294// It handles the extra cases for integer-like arithmetic
Damien Georgeecc88e92014-08-30 00:35:11 +0100295mp_obj_t mp_obj_int_binary_op_extra_cases(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
Damien Georgee8208a72014-04-04 15:08:23 +0100296 if (rhs_in == mp_const_false) {
297 // false acts as 0
298 return mp_binary_op(op, lhs_in, MP_OBJ_NEW_SMALL_INT(0));
299 } else if (rhs_in == mp_const_true) {
300 // true acts as 0
301 return mp_binary_op(op, lhs_in, MP_OBJ_NEW_SMALL_INT(1));
302 } else if (op == MP_BINARY_OP_MULTIPLY) {
Damien George9b7a8ee2014-08-13 13:22:24 +0100303 if (MP_OBJ_IS_STR(rhs_in) || MP_OBJ_IS_TYPE(rhs_in, &mp_type_bytes) || MP_OBJ_IS_TYPE(rhs_in, &mp_type_tuple) || MP_OBJ_IS_TYPE(rhs_in, &mp_type_list)) {
Damien Georgee8208a72014-04-04 15:08:23 +0100304 // multiply is commutative for these types, so delegate to them
305 return mp_binary_op(op, rhs_in, lhs_in);
306 }
307 }
Damien George6ac5dce2014-05-21 19:42:43 +0100308 return MP_OBJ_NULL; // op not supported
Damien Georgee8208a72014-04-04 15:08:23 +0100309}
310
Damien George5213eb32014-04-13 12:24:13 +0100311// this is a classmethod
Damien Georgeecc88e92014-08-30 00:35:11 +0100312STATIC mp_obj_t int_from_bytes(mp_uint_t n_args, const mp_obj_t *args) {
Paul Sokolovskya985b452014-04-09 00:40:58 +0300313 // TODO: Support long ints
Damien George5213eb32014-04-13 12:24:13 +0100314 // TODO: Support byteorder param (assumes 'little' at the moment)
315 // TODO: Support signed param (assumes signed=False at the moment)
Damien Georgeff8dd3f2015-01-20 12:47:20 +0000316 (void)n_args;
Damien George5213eb32014-04-13 12:24:13 +0100317
318 // get the buffer info
Damien George57a4b4f2014-04-18 22:29:21 +0100319 mp_buffer_info_t bufinfo;
Damien Georgeb11b85a2014-04-18 22:59:24 +0100320 mp_get_buffer_raise(args[1], &bufinfo, MP_BUFFER_READ);
Damien George5213eb32014-04-13 12:24:13 +0100321
322 // convert the bytes to an integer
Damien George40f3c022014-07-03 13:25:24 +0100323 mp_uint_t value = 0;
stijn01d6be42014-05-05 12:18:27 +0200324 for (const byte* buf = (const byte*)bufinfo.buf + bufinfo.len - 1; buf >= (byte*)bufinfo.buf; buf--) {
Damien Georgeb9e7ed42014-04-13 12:40:50 +0100325 value = (value << 8) | *buf;
Damien George5213eb32014-04-13 12:24:13 +0100326 }
327
328 return mp_obj_new_int_from_uint(value);
Paul Sokolovskya985b452014-04-09 00:40:58 +0300329}
330
Damien George5213eb32014-04-13 12:24:13 +0100331STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_from_bytes_fun_obj, 2, 3, int_from_bytes);
332STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(int_from_bytes_obj, (const mp_obj_t)&int_from_bytes_fun_obj);
Paul Sokolovskya985b452014-04-09 00:40:58 +0300333
Damien Georgeecc88e92014-08-30 00:35:11 +0100334STATIC mp_obj_t int_to_bytes(mp_uint_t n_args, const mp_obj_t *args) {
Paul Sokolovskya985b452014-04-09 00:40:58 +0300335 // TODO: Support long ints
Damien Georgefcdb2392014-10-06 13:45:34 +0000336 // TODO: Support byteorder param (assumes 'little')
337 // TODO: Support signed param (assumes signed=False)
Damien Georgeff8dd3f2015-01-20 12:47:20 +0000338 (void)n_args;
Damien Georgefcdb2392014-10-06 13:45:34 +0000339
340 mp_int_t val = mp_obj_int_get_checked(args[0]);
Damien George963a5a32015-01-16 17:47:07 +0000341 mp_uint_t len = MP_OBJ_SMALL_INT_VALUE(args[1]);
Damien Georgefcdb2392014-10-06 13:45:34 +0000342
Damien George05005f62015-01-21 22:48:37 +0000343 vstr_t vstr;
344 vstr_init_len(&vstr, len);
345 byte *data = (byte*)vstr.buf;
Paul Sokolovskya985b452014-04-09 00:40:58 +0300346 memset(data, 0, len);
Damien Georgefcdb2392014-10-06 13:45:34 +0000347
348 if (MP_ENDIANNESS_LITTLE) {
349 memcpy(data, &val, len < sizeof(mp_int_t) ? len : sizeof(mp_int_t));
350 } else {
351 while (len--) {
352 *data++ = val;
353 val >>= 8;
354 }
355 }
356
Damien George05005f62015-01-21 22:48:37 +0000357 return mp_obj_new_str_from_vstr(&mp_type_bytes, &vstr);
Paul Sokolovskya985b452014-04-09 00:40:58 +0300358}
Paul Sokolovskya985b452014-04-09 00:40:58 +0300359STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(int_to_bytes_obj, 2, 4, int_to_bytes);
360
361STATIC const mp_map_elem_t int_locals_dict_table[] = {
362 { MP_OBJ_NEW_QSTR(MP_QSTR_from_bytes), (mp_obj_t)&int_from_bytes_obj },
363 { MP_OBJ_NEW_QSTR(MP_QSTR_to_bytes), (mp_obj_t)&int_to_bytes_obj },
364};
365
366STATIC MP_DEFINE_CONST_DICT(int_locals_dict, int_locals_dict_table);
367
Damien George3e1a5c12014-03-29 13:43:38 +0000368const mp_obj_type_t mp_type_int = {
Damien Georgec5966122014-02-15 16:10:44 +0000369 { &mp_type_type },
Damien Georgea71c83a2014-02-15 11:34:50 +0000370 .name = MP_QSTR_int,
Damien Georgee8208a72014-04-04 15:08:23 +0100371 .print = mp_obj_int_print,
372 .make_new = mp_obj_int_make_new,
373 .unary_op = mp_obj_int_unary_op,
374 .binary_op = mp_obj_int_binary_op,
Paul Sokolovskya985b452014-04-09 00:40:58 +0300375 .locals_dict = (mp_obj_t)&int_locals_dict,
Damien George5fa93b62014-01-22 14:35:10 +0000376};