summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--py/builtin.c2
-rw-r--r--py/builtintables.c2
-rw-r--r--py/mpconfig.h4
-rw-r--r--py/obj.c2
-rw-r--r--py/objcomplex.c2
-rw-r--r--py/objfloat.c5
-rw-r--r--py/objint_mpz.c2
-rw-r--r--py/parsenum.c6
-rw-r--r--py/runtime.c2
9 files changed, 24 insertions, 3 deletions
diff --git a/py/builtin.c b/py/builtin.c
index b25ca42a14..d4b77d37a8 100644
--- a/py/builtin.c
+++ b/py/builtin.c
@@ -113,11 +113,13 @@ mp_obj_t mp_builtin_abs(mp_obj_t o_in) {
} else {
return o_in;
}
+#if MICROPY_PY_BUILTINS_COMPLEX
} else if (MP_OBJ_IS_TYPE(o_in, &mp_type_complex)) {
mp_float_t real, imag;
mp_obj_complex_get(o_in, &real, &imag);
return mp_obj_new_float(MICROPY_FLOAT_C_FUN(sqrt)(real*real + imag*imag));
#endif
+#endif
} else {
assert(0);
return mp_const_none;
diff --git a/py/builtintables.c b/py/builtintables.c
index af9a9bc25e..66ea4ea446 100644
--- a/py/builtintables.c
+++ b/py/builtintables.c
@@ -44,7 +44,7 @@ STATIC const mp_map_elem_t mp_builtin_object_table[] = {
{ MP_OBJ_NEW_QSTR(MP_QSTR_bool), (mp_obj_t)&mp_type_bool },
{ MP_OBJ_NEW_QSTR(MP_QSTR_bytes), (mp_obj_t)&mp_type_bytes },
{ MP_OBJ_NEW_QSTR(MP_QSTR_bytearray), (mp_obj_t)&mp_type_bytearray },
-#if MICROPY_PY_BUILTINS_FLOAT
+#if MICROPY_PY_BUILTINS_COMPLEX
{ MP_OBJ_NEW_QSTR(MP_QSTR_complex), (mp_obj_t)&mp_type_complex },
#endif
{ MP_OBJ_NEW_QSTR(MP_QSTR_dict), (mp_obj_t)&mp_type_dict },
diff --git a/py/mpconfig.h b/py/mpconfig.h
index 93e98c25b6..4a3288a3d1 100644
--- a/py/mpconfig.h
+++ b/py/mpconfig.h
@@ -223,6 +223,10 @@ typedef double mp_float_t;
#define MICROPY_PY_BUILTINS_FLOAT (0)
#endif
+#ifndef MICROPY_PY_BUILTINS_COMPLEX
+#define MICROPY_PY_BUILTINS_COMPLEX (MICROPY_PY_BUILTINS_FLOAT)
+#endif
+
// Enable features which improve CPython compatibility
// but may lead to more code size/memory usage.
// TODO: Originally intended as generic category to not
diff --git a/py/obj.c b/py/obj.c
index 6d0966db24..a0f55d65db 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -274,6 +274,7 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
}
}
+#if MICROPY_PY_BUILTINS_COMPLEX
void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
if (arg == mp_const_false) {
*real = 0;
@@ -297,6 +298,7 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
}
}
#endif
+#endif
void mp_obj_get_array(mp_obj_t o, uint *len, mp_obj_t **items) {
if (MP_OBJ_IS_TYPE(o, &mp_type_tuple)) {
diff --git a/py/objcomplex.c b/py/objcomplex.c
index d58b53463c..20e7c97d37 100644
--- a/py/objcomplex.c
+++ b/py/objcomplex.c
@@ -36,7 +36,7 @@
#include "runtime0.h"
#include "runtime.h"
-#if MICROPY_PY_BUILTINS_FLOAT
+#if MICROPY_PY_BUILTINS_COMPLEX
#include <math.h>
diff --git a/py/objfloat.c b/py/objfloat.c
index b608b1a3d7..e3fefad8db 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -102,9 +102,12 @@ STATIC mp_obj_t float_unary_op(int op, mp_obj_t o_in) {
STATIC mp_obj_t float_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
mp_obj_float_t *lhs = lhs_in;
+#if MICROPY_PY_BUILTINS_COMPLEX
if (MP_OBJ_IS_TYPE(rhs_in, &mp_type_complex)) {
return mp_obj_complex_binary_op(op, lhs->value, 0, rhs_in);
- } else {
+ } else
+#endif
+ {
return mp_obj_float_binary_op(op, lhs->value, rhs_in);
}
}
diff --git a/py/objint_mpz.c b/py/objint_mpz.c
index 516fb52746..cf7896f9e1 100644
--- a/py/objint_mpz.c
+++ b/py/objint_mpz.c
@@ -121,9 +121,11 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
#if MICROPY_PY_BUILTINS_FLOAT
} else if (MP_OBJ_IS_TYPE(rhs_in, &mp_type_float)) {
return mp_obj_float_binary_op(op, mpz_as_float(zlhs), rhs_in);
+#if MICROPY_PY_BUILTINS_COMPLEX
} else if (MP_OBJ_IS_TYPE(rhs_in, &mp_type_complex)) {
return mp_obj_complex_binary_op(op, mpz_as_float(zlhs), 0, rhs_in);
#endif
+#endif
} else {
// delegate to generic function to check for extra cases
return mp_obj_int_binary_op_extra_cases(op, lhs_in, rhs_in);
diff --git a/py/parsenum.c b/py/parsenum.c
index 1c1868ae0a..36b0690501 100644
--- a/py/parsenum.c
+++ b/py/parsenum.c
@@ -35,6 +35,7 @@
#include "parsenumbase.h"
#include "parsenum.h"
#include "smallint.h"
+#include "runtime.h"
#if MICROPY_PY_BUILTINS_FLOAT
#include <math.h>
@@ -252,10 +253,15 @@ mp_obj_t mp_parse_num_decimal(const char *str, uint len, bool allow_imag, bool f
}
// return the object
+#if MICROPY_PY_BUILTINS_COMPLEX
if (imag) {
return mp_obj_new_complex(0, dec_val);
} else if (force_complex) {
return mp_obj_new_complex(dec_val, 0);
+#else
+ if (imag || force_complex) {
+ mp_not_implemented("complex values not supported");
+#endif
} else {
return mp_obj_new_float(dec_val);
}
diff --git a/py/runtime.c b/py/runtime.c
index d57bb686d1..b539984c0b 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -426,6 +426,7 @@ mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
} else {
return res;
}
+#if MICROPY_PY_BUILTINS_COMPLEX
} else if (MP_OBJ_IS_TYPE(rhs, &mp_type_complex)) {
mp_obj_t res = mp_obj_complex_binary_op(op, lhs_val, 0, rhs);
if (res == MP_OBJ_NULL) {
@@ -434,6 +435,7 @@ mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
return res;
}
#endif
+#endif
}
}