summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--py/obj.h10
-rw-r--r--py/objdict.c9
-rw-r--r--py/objfloat.c2
-rw-r--r--py/objfun.c2
-rw-r--r--py/objint_mpz.c2
-rw-r--r--py/objlist.c7
-rw-r--r--py/objset.c68
-rw-r--r--py/objstr.c5
-rw-r--r--py/objtuple.c12
-rw-r--r--py/objtype.c4
10 files changed, 60 insertions, 61 deletions
diff --git a/py/obj.h b/py/obj.h
index 4797856ad8..0e254b258a 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -255,8 +255,8 @@ struct _mp_obj_type_t {
mp_make_new_fun_t make_new; // to make an instance of the type
mp_call_fun_t call;
- mp_unary_op_fun_t unary_op; // can return NULL if op not supported
- mp_binary_op_fun_t binary_op; // can return NULL if op not supported
+ mp_unary_op_fun_t unary_op; // can return MP_OBJ_NOT_SUPPORTED if op not supported
+ mp_binary_op_fun_t binary_op; // can return MP_OBJ_NOT_SUPPORTED if op not supported
mp_load_attr_fun_t load_attr;
mp_store_attr_fun_t store_attr; // if value is MP_OBJ_NULL, then delete that attribute
@@ -266,7 +266,7 @@ struct _mp_obj_type_t {
// can return MP_OBJ_NOT_SUPPORTED
mp_fun_1_t getiter;
- mp_fun_1_t iternext; // may return MP_OBJ_NULL as an optimisation instead of raising StopIteration() (with no args)
+ mp_fun_1_t iternext; // may return MP_OBJ_STOP_ITERATION as an optimisation instead of raising StopIteration() (with no args)
mp_buffer_p_t buffer_p;
const mp_stream_p_t *stream_p;
@@ -479,11 +479,11 @@ typedef struct _mp_obj_float_t {
mp_float_t value;
} mp_obj_float_t;
mp_float_t mp_obj_float_get(mp_obj_t self_in);
-mp_obj_t mp_obj_float_binary_op(int op, mp_float_t lhs_val, mp_obj_t rhs); // can return MP_OBJ_NULL
+mp_obj_t mp_obj_float_binary_op(int op, mp_float_t lhs_val, mp_obj_t rhs); // can return MP_OBJ_NOT_SUPPORTED
// complex
void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
-mp_obj_t mp_obj_complex_binary_op(int op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in); // can return MP_OBJ_NULL
+mp_obj_t mp_obj_complex_binary_op(int op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in); // can return MP_OBJ_NOT_SUPPORTED
#endif
// tuple
diff --git a/py/objdict.c b/py/objdict.c
index 6a6fff2a9f..9d4ebb6279 100644
--- a/py/objdict.c
+++ b/py/objdict.c
@@ -465,12 +465,15 @@ STATIC void dict_view_print(void (*print)(void *env, const char *fmt, ...), void
STATIC mp_obj_t dict_view_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
/* only supported for the 'keys' kind until sets and dicts are refactored */
mp_obj_dict_view_t *o = lhs_in;
- if (o->kind != MP_DICT_VIEW_KEYS) return NULL;
- if (op != MP_BINARY_OP_IN) return NULL;
+ if (o->kind != MP_DICT_VIEW_KEYS) {
+ return MP_OBJ_NOT_SUPPORTED;
+ }
+ if (op != MP_BINARY_OP_IN) {
+ return MP_OBJ_NOT_SUPPORTED;
+ }
return dict_binary_op(op, o->dict, rhs_in);
}
-
STATIC const mp_obj_type_t dict_view_type = {
{ &mp_type_type },
.name = MP_QSTR_dict_view,
diff --git a/py/objfloat.c b/py/objfloat.c
index d5cbe18fb0..5260fadc1c 100644
--- a/py/objfloat.c
+++ b/py/objfloat.c
@@ -97,7 +97,7 @@ STATIC mp_obj_t float_unary_op(int op, mp_obj_t o_in) {
case MP_UNARY_OP_BOOL: return MP_BOOL(o->value != 0);
case MP_UNARY_OP_POSITIVE: return o_in;
case MP_UNARY_OP_NEGATIVE: return mp_obj_new_float(-o->value);
- default: return NULL; // op not supported
+ default: return MP_OBJ_NOT_SUPPORTED;
}
}
diff --git a/py/objfun.c b/py/objfun.c
index 8994486c85..732009376d 100644
--- a/py/objfun.c
+++ b/py/objfun.c
@@ -58,7 +58,7 @@ STATIC mp_obj_t fun_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
// we don't even need to check for 2nd arg type.
return MP_BOOL(lhs_in == rhs_in);
}
- return NULL;
+ return MP_OBJ_NOT_SUPPORTED;
}
STATIC mp_obj_t fun_native_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *args) {
diff --git a/py/objint_mpz.c b/py/objint_mpz.c
index a7fcac9f28..8e72782d66 100644
--- a/py/objint_mpz.c
+++ b/py/objint_mpz.c
@@ -90,7 +90,7 @@ mp_obj_t mp_obj_int_unary_op(int op, mp_obj_t o_in) {
case MP_UNARY_OP_POSITIVE: return o_in;
case MP_UNARY_OP_NEGATIVE: { mp_obj_int_t *o2 = mp_obj_int_new_mpz(); mpz_neg_inpl(&o2->mpz, &o->mpz); return o2; }
case MP_UNARY_OP_INVERT: { mp_obj_int_t *o2 = mp_obj_int_new_mpz(); mpz_not_inpl(&o2->mpz, &o->mpz); return o2; }
- default: return NULL; // op not supported
+ default: return MP_OBJ_NOT_SUPPORTED;
}
}
diff --git a/py/objlist.c b/py/objlist.c
index d2d6f068d8..2a5de35051 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -87,7 +87,6 @@ STATIC mp_obj_t list_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp
default:
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "list takes at most 1 argument, %d given", n_args));
}
- return NULL;
}
// Don't pass MP_BINARY_OP_NOT_EQUAL here
@@ -116,7 +115,7 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
switch (op) {
case MP_BINARY_OP_ADD: {
if (!MP_OBJ_IS_TYPE(rhs, &mp_type_list)) {
- return NULL;
+ return MP_OBJ_NOT_SUPPORTED;
}
mp_obj_list_t *p = rhs;
mp_obj_list_t *s = list_new(o->len + p->len);
@@ -125,7 +124,7 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
}
case MP_BINARY_OP_INPLACE_ADD: {
if (!MP_OBJ_IS_TYPE(rhs, &mp_type_list)) {
- return NULL;
+ return MP_OBJ_NOT_SUPPORTED;
}
list_extend(lhs, rhs);
return o;
@@ -133,7 +132,7 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
case MP_BINARY_OP_MULTIPLY: {
machine_int_t n;
if (!mp_obj_get_int_maybe(rhs, &n)) {
- return NULL;
+ return MP_OBJ_NOT_SUPPORTED;
}
mp_obj_list_t *s = list_new(o->len * n);
mp_seq_multiply(o->items, sizeof(*o->items), o->len, n, s->items);
diff --git a/py/objset.c b/py/objset.c
index 8b1be26857..3e56fd79ef 100644
--- a/py/objset.c
+++ b/py/objset.c
@@ -412,41 +412,39 @@ STATIC mp_obj_t set_unary_op(int op, mp_obj_t self_in) {
STATIC mp_obj_t set_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
mp_obj_t args[] = {lhs, rhs};
switch (op) {
- case MP_BINARY_OP_OR:
- return set_union(lhs, rhs);
- case MP_BINARY_OP_XOR:
- return set_symmetric_difference(lhs, rhs);
- case MP_BINARY_OP_AND:
- return set_intersect(lhs, rhs);
- case MP_BINARY_OP_SUBTRACT:
- return set_diff(2, args);
- case MP_BINARY_OP_INPLACE_OR:
- return set_union(lhs, rhs);
- case MP_BINARY_OP_INPLACE_XOR:
- return set_symmetric_difference(lhs, rhs);
- case MP_BINARY_OP_INPLACE_AND:
- return set_intersect(lhs, rhs);
- case MP_BINARY_OP_INPLACE_SUBTRACT:
- return set_diff(2, args);
- case MP_BINARY_OP_LESS:
- return set_issubset_proper(lhs, rhs);
- case MP_BINARY_OP_MORE:
- return set_issuperset_proper(lhs, rhs);
- case MP_BINARY_OP_EQUAL:
- return set_equal(lhs, rhs);
- case MP_BINARY_OP_LESS_EQUAL:
- return set_issubset(lhs, rhs);
- case MP_BINARY_OP_MORE_EQUAL:
- return set_issuperset(lhs, rhs);
- case MP_BINARY_OP_IN:
- {
- mp_obj_set_t *o = lhs;
- mp_obj_t elem = mp_set_lookup(&o->set, rhs, MP_MAP_LOOKUP);
- return MP_BOOL(elem != NULL);
- }
- default:
- // op not supported
- return NULL;
+ case MP_BINARY_OP_OR:
+ return set_union(lhs, rhs);
+ case MP_BINARY_OP_XOR:
+ return set_symmetric_difference(lhs, rhs);
+ case MP_BINARY_OP_AND:
+ return set_intersect(lhs, rhs);
+ case MP_BINARY_OP_SUBTRACT:
+ return set_diff(2, args);
+ case MP_BINARY_OP_INPLACE_OR:
+ return set_union(lhs, rhs);
+ case MP_BINARY_OP_INPLACE_XOR:
+ return set_symmetric_difference(lhs, rhs);
+ case MP_BINARY_OP_INPLACE_AND:
+ return set_intersect(lhs, rhs);
+ case MP_BINARY_OP_INPLACE_SUBTRACT:
+ return set_diff(2, args);
+ case MP_BINARY_OP_LESS:
+ return set_issubset_proper(lhs, rhs);
+ case MP_BINARY_OP_MORE:
+ return set_issuperset_proper(lhs, rhs);
+ case MP_BINARY_OP_EQUAL:
+ return set_equal(lhs, rhs);
+ case MP_BINARY_OP_LESS_EQUAL:
+ return set_issubset(lhs, rhs);
+ case MP_BINARY_OP_MORE_EQUAL:
+ return set_issuperset(lhs, rhs);
+ case MP_BINARY_OP_IN: {
+ mp_obj_set_t *o = lhs;
+ mp_obj_t elem = mp_set_lookup(&o->set, rhs, MP_MAP_LOOKUP);
+ return MP_BOOL(elem != NULL);
+ }
+ default:
+ return MP_OBJ_NOT_SUPPORTED;
}
}
diff --git a/py/objstr.c b/py/objstr.c
index 7ca8afc6ba..e42b21fc6c 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -287,10 +287,9 @@ STATIC mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
}
break;
- case MP_BINARY_OP_MULTIPLY:
- {
+ case MP_BINARY_OP_MULTIPLY: {
if (!MP_OBJ_IS_SMALL_INT(rhs_in)) {
- return NULL;
+ return MP_OBJ_NOT_SUPPORTED;
}
int n = MP_OBJ_SMALL_INT_VALUE(rhs_in);
byte *data;
diff --git a/py/objtuple.c b/py/objtuple.c
index 9434b418cd..bb0ce65868 100644
--- a/py/objtuple.c
+++ b/py/objtuple.c
@@ -121,20 +121,18 @@ mp_obj_t tuple_unary_op(int op, mp_obj_t self_in) {
mp_obj_t tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
mp_obj_tuple_t *o = lhs;
switch (op) {
- case MP_BINARY_OP_ADD:
- {
+ case MP_BINARY_OP_ADD: {
if (!mp_obj_is_subclass_fast(mp_obj_get_type(rhs), (mp_obj_t)&mp_type_tuple)) {
- return NULL;
+ return MP_OBJ_NOT_SUPPORTED;
}
mp_obj_tuple_t *p = rhs;
mp_obj_tuple_t *s = mp_obj_new_tuple(o->len + p->len, NULL);
m_seq_cat(s->items, o->items, o->len, p->items, p->len, mp_obj_t);
return s;
}
- case MP_BINARY_OP_MULTIPLY:
- {
+ case MP_BINARY_OP_MULTIPLY: {
if (!MP_OBJ_IS_SMALL_INT(rhs)) {
- return NULL;
+ return MP_OBJ_NOT_SUPPORTED;
}
int n = MP_OBJ_SMALL_INT_VALUE(rhs);
mp_obj_tuple_t *s = mp_obj_new_tuple(o->len * n, NULL);
@@ -150,7 +148,7 @@ mp_obj_t tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
default:
// op not supported
- return NULL;
+ return MP_OBJ_NOT_SUPPORTED;
}
}
diff --git a/py/objtype.c b/py/objtype.c
index 7a7d758429..5324e7cdfb 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -596,8 +596,10 @@ STATIC mp_obj_t type_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
// Types can be equal only if it's the same type structure,
// we don't even need to check for 2nd arg type.
return MP_BOOL(lhs_in == rhs_in);
+
+ default:
+ return MP_OBJ_NOT_SUPPORTED;
}
- return NULL;
}
const mp_obj_type_t mp_type_type = {