blob: 9cd5ebae295a9156a30e47872e1d39a59b95b850 [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",
Paul Sokolovsky860ffb02014-01-05 22:34:09 +020036 .make_new = int_make_new,
Damien George45b43c22014-01-05 01:50:45 +000037};
38
39mp_obj_t mp_obj_new_int(machine_int_t value) {
40 return MP_OBJ_NEW_SMALL_INT(value);
41}