summaryrefslogtreecommitdiffstatshomepage
path: root/py/objint.c
diff options
context:
space:
mode:
authorJohn R. Lenton <jlenton@gmail.com>2014-01-05 22:27:11 +0000
committerJohn R. Lenton <jlenton@gmail.com>2014-01-05 22:27:11 +0000
commitd52a0318ce266e1d9ce0d877f64a8fe097cef080 (patch)
tree9c57f2bd169754c56679b25dd41c003a046c1137 /py/objint.c
parent49fb6e53b35f991d79caadbb6320a39452944b4d (diff)
parent12e2656472bf53e467c066eda6f3e177a97210ca (diff)
downloadmicropython-d52a0318ce266e1d9ce0d877f64a8fe097cef080.tar.gz
micropython-d52a0318ce266e1d9ce0d877f64a8fe097cef080.zip
Merge remote-tracking branch 'upstream/master' into list_remove
Diffstat (limited to 'py/objint.c')
-rw-r--r--py/objint.c48
1 files changed, 48 insertions, 0 deletions
diff --git a/py/objint.c b/py/objint.c
new file mode 100644
index 0000000000..5bc747e8f0
--- /dev/null
+++ b/py/objint.c
@@ -0,0 +1,48 @@
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <assert.h>
+
+#include "nlr.h"
+#include "misc.h"
+#include "mpconfig.h"
+#include "mpqstr.h"
+#include "obj.h"
+
+typedef struct _mp_obj_int_t {
+ mp_obj_base_t base;
+} mp_obj_int_t;
+
+static mp_obj_t int_make_new(mp_obj_t type_in, int n_args, const mp_obj_t *args) {
+ switch (n_args) {
+ case 0:
+ return MP_OBJ_NEW_SMALL_INT(0);
+
+ case 1:
+ // TODO allow string as arg and parse it
+ return MP_OBJ_NEW_SMALL_INT(mp_obj_get_int(args[0]));
+
+ //case 2:
+ // TODO, parse with given base
+
+ default:
+ 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));
+ }
+}
+
+const mp_obj_type_t int_type = {
+ { &mp_const_type },
+ "int",
+ NULL,
+ int_make_new, // make_new
+ NULL, // call_n
+ NULL, // unary_op
+ NULL, // binary_op
+ NULL, // getiter
+ NULL, // iternext
+ { { NULL, NULL }, }, // method list
+};
+
+mp_obj_t mp_obj_new_int(machine_int_t value) {
+ return MP_OBJ_NEW_SMALL_INT(value);
+}