summaryrefslogtreecommitdiffstatshomepage
path: root/py/runtime.c
diff options
context:
space:
mode:
authorPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-01-12 17:06:25 +0200
committerPaul Sokolovsky <pfalcon@users.sourceforge.net>2014-01-12 22:04:21 +0200
commit757ac81a69cc2143a6b170367b18c75ac60249e4 (patch)
tree13302ead4c84e367f99435c067a5a96c41e11091 /py/runtime.c
parentc260bc58e66f5fefc03b59c80c91a550282fb47c (diff)
downloadmicropython-757ac81a69cc2143a6b170367b18c75ac60249e4.tar.gz
micropython-757ac81a69cc2143a6b170367b18c75ac60249e4.zip
Add proper checks for fits-in-small-int. Make it reusable.
We likely should make mp_obj_new_int() inline, and rely on its encapsulated check rather than inline checks everywhere explicitly. Also, parser for big small int values is still broken.
Diffstat (limited to 'py/runtime.c')
-rw-r--r--py/runtime.c17
1 files changed, 5 insertions, 12 deletions
diff --git a/py/runtime.c b/py/runtime.c
index 8d3e900286..2af86b6abd 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -268,10 +268,6 @@ void rt_assign_inline_asm_code(int unique_code_id, void *fun, uint len, int n_ar
#endif
}
-static bool fit_small_int(mp_small_int_t o) {
- return true;
-}
-
int rt_is_true(mp_obj_t arg) {
DEBUG_OP_printf("is true %p\n", arg);
if (MP_OBJ_IS_SMALL_INT(arg)) {
@@ -436,13 +432,10 @@ mp_obj_t rt_unary_op(int op, mp_obj_t arg) {
case RT_UNARY_OP_INVERT: val = ~val; break;
default: assert(0); val = 0;
}
- if (fit_small_int(val)) {
+ if (MP_OBJ_FITS_SMALL_INT(val)) {
return MP_OBJ_NEW_SMALL_INT(val);
- } else {
- // TODO make a bignum
- assert(0);
- return mp_const_none;
}
+ return mp_obj_new_int(val);
} else { // will be an object (small ints are caught in previous if)
mp_obj_base_t *o = arg;
if (o->type->unary_op != NULL) {
@@ -551,11 +544,11 @@ mp_obj_t rt_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
default: assert(0);
}
- if (fit_small_int(lhs_val)) {
+ // TODO: We just should make mp_obj_new_int() inline and use that
+ if (MP_OBJ_FITS_SMALL_INT(lhs_val)) {
return MP_OBJ_NEW_SMALL_INT(lhs_val);
}
- // TODO: return long int
- assert(0);
+ return mp_obj_new_int(lhs_val);
} else if (MP_OBJ_IS_TYPE(rhs, &float_type)) {
return mp_obj_float_binary_op(op, lhs_val, rhs);
} else if (MP_OBJ_IS_TYPE(rhs, &complex_type)) {