blob: 5bc747e8f0f475ddd8ef90b1a2fdce1e61465166 [file] [log] [blame]
Damien George45b43c22014-01-05 01:50:45 +00001#include <stdlib.h>
2#include <stdint.h>
3#include <string.h>
4#include <assert.h>
5
6#include "nlr.h"
7#include "misc.h"
8#include "mpconfig.h"
9#include "mpqstr.h"
10#include "obj.h"
11
12typedef struct _mp_obj_int_t {
13 mp_obj_base_t base;
14} mp_obj_int_t;
15
16static mp_obj_t int_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args) {
17 switch (n_args) {
18 case 0:
19 return MP_OBJ_NEW_SMALL_INT(0);
20
21 case 1:
22 // TODO allow string as arg and parse it
23 return MP_OBJ_NEW_SMALL_INT(mp_obj_get_int(args[0]));
24
25 //case 2:
26 // TODO, parse with given base
27
28 default:
29 nlr_jump(mp_obj_new_exception_msg_1_arg(MP_QSTR_TypeError, "int takes at most 2 arguments, %d given", (void*)(machine_int_t)n_args));
30 }
31}
32
33const mp_obj_type_t int_type = {
34 { &mp_const_type },
35 "int",
36 NULL,
37 int_make_new, // make_new
38 NULL, // call_n
39 NULL, // unary_op
40 NULL, // binary_op
41 NULL, // getiter
42 NULL, // iternext
43 { { NULL, NULL }, }, // method list
44};
45
46mp_obj_t mp_obj_new_int(machine_int_t value) {
47 return MP_OBJ_NEW_SMALL_INT(value);
48}