py: Rename MP_OBJ_NOT_SUPPORTED to MP_OBJ_NULL.

See issue #608 for justification.
This commit is contained in:
Damien George 2014-05-21 19:42:43 +01:00
parent 6d197740cf
commit 6ac5dced24
19 changed files with 61 additions and 70 deletions

View File

@ -122,7 +122,7 @@ int mp_obj_is_true(mp_obj_t arg) {
mp_obj_type_t *type = mp_obj_get_type(arg); mp_obj_type_t *type = mp_obj_get_type(arg);
if (type->unary_op != NULL) { if (type->unary_op != NULL) {
mp_obj_t result = type->unary_op(MP_UNARY_OP_BOOL, arg); mp_obj_t result = type->unary_op(MP_UNARY_OP_BOOL, arg);
if (result != MP_OBJ_NOT_SUPPORTED) { if (result != MP_OBJ_NULL) {
return result == mp_const_true; return result == mp_const_true;
} }
} }
@ -212,7 +212,7 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) {
mp_obj_type_t *type = mp_obj_get_type(o1); mp_obj_type_t *type = mp_obj_get_type(o1);
if (type->binary_op != NULL) { if (type->binary_op != NULL) {
mp_obj_t r = type->binary_op(MP_BINARY_OP_EQUAL, o1, o2); mp_obj_t r = type->binary_op(MP_BINARY_OP_EQUAL, o1, o2);
if (r != MP_OBJ_NOT_SUPPORTED) { if (r != MP_OBJ_NULL) {
return r == mp_const_true ? true : false; return r == mp_const_true ? true : false;
} }
} }
@ -357,12 +357,7 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
} else { } else {
mp_obj_type_t *type = mp_obj_get_type(o_in); mp_obj_type_t *type = mp_obj_get_type(o_in);
if (type->unary_op != NULL) { if (type->unary_op != NULL) {
mp_obj_t val = type->unary_op(MP_UNARY_OP_LEN, o_in); return type->unary_op(MP_UNARY_OP_LEN, o_in);
// TODO: Here's the case of having MP_OBJ_NOT_SUPPORTED is confusing
if (val == MP_OBJ_NOT_SUPPORTED) {
return MP_OBJ_NULL;
}
return val;
} else { } else {
return MP_OBJ_NULL; return MP_OBJ_NULL;
} }
@ -373,7 +368,7 @@ mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
mp_obj_type_t *type = mp_obj_get_type(base); mp_obj_type_t *type = mp_obj_get_type(base);
if (type->subscr != NULL) { if (type->subscr != NULL) {
mp_obj_t ret = type->subscr(base, index, value); mp_obj_t ret = type->subscr(base, index, value);
if (ret != MP_OBJ_NOT_SUPPORTED) { if (ret != MP_OBJ_NULL) {
return ret; return ret;
} }
// TODO: call base classes here? // TODO: call base classes here?

View File

@ -52,8 +52,7 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
// These fake objects are used to indicate certain things in arguments or return // These fake objects are used to indicate certain things in arguments or return
// values, and should only be used when explicitly allowed. // values, and should only be used when explicitly allowed.
// //
// - MP_OBJ_NULL : used to indicate the absence of an object. // - MP_OBJ_NULL : used to indicate the absence of an object, or unsupported operation.
// - MP_OBJ_NOT_SUPPORTED : a return value that indicates an unsupported operation.
// - MP_OBJ_STOP_ITERATION : used instead of throwing a StopIteration, for efficiency. // - MP_OBJ_STOP_ITERATION : used instead of throwing a StopIteration, for efficiency.
// - MP_OBJ_SENTINEL : used for various internal purposes where one needs // - MP_OBJ_SENTINEL : used for various internal purposes where one needs
// an object which is unique from all other objects, including MP_OBJ_NULL. // an object which is unique from all other objects, including MP_OBJ_NULL.
@ -63,14 +62,12 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
#if NDEBUG #if NDEBUG
#define MP_OBJ_NULL ((mp_obj_t)0) #define MP_OBJ_NULL ((mp_obj_t)0)
#define MP_OBJ_NOT_SUPPORTED ((mp_obj_t)0)
#define MP_OBJ_STOP_ITERATION ((mp_obj_t)0) #define MP_OBJ_STOP_ITERATION ((mp_obj_t)0)
#define MP_OBJ_SENTINEL ((mp_obj_t)4) #define MP_OBJ_SENTINEL ((mp_obj_t)4)
#else #else
#define MP_OBJ_NULL ((mp_obj_t)0) #define MP_OBJ_NULL ((mp_obj_t)0)
#define MP_OBJ_NOT_SUPPORTED ((mp_obj_t)4) #define MP_OBJ_STOP_ITERATION ((mp_obj_t)4)
#define MP_OBJ_STOP_ITERATION ((mp_obj_t)8) #define MP_OBJ_SENTINEL ((mp_obj_t)8)
#define MP_OBJ_SENTINEL ((mp_obj_t)12)
#endif #endif
// These macros check for small int, qstr or object, and access small int and qstr values // These macros check for small int, qstr or object, and access small int and qstr values
@ -256,15 +253,15 @@ struct _mp_obj_type_t {
mp_make_new_fun_t make_new; // to make an instance of the type mp_make_new_fun_t make_new; // to make an instance of the type
mp_call_fun_t call; mp_call_fun_t call;
mp_unary_op_fun_t unary_op; // can return MP_OBJ_NOT_SUPPORTED if op not supported mp_unary_op_fun_t unary_op; // can return MP_OBJ_NULL if op not supported
mp_binary_op_fun_t binary_op; // can return MP_OBJ_NOT_SUPPORTED if op not supported mp_binary_op_fun_t binary_op; // can return MP_OBJ_NULL if op not supported
mp_load_attr_fun_t load_attr; mp_load_attr_fun_t load_attr;
mp_store_attr_fun_t store_attr; // if value is MP_OBJ_NULL, then delete that attribute mp_store_attr_fun_t store_attr; // if value is MP_OBJ_NULL, then delete that attribute
mp_subscr_fun_t subscr; // implements load, store, delete subscripting mp_subscr_fun_t subscr; // implements load, store, delete subscripting
// value=MP_OBJ_NULL means delete, value=MP_OBJ_SENTINEL means load, else store // value=MP_OBJ_NULL means delete, value=MP_OBJ_SENTINEL means load, else store
// can return MP_OBJ_NOT_SUPPORTED // can return MP_OBJ_NULL if op not supported
mp_fun_1_t getiter; mp_fun_1_t getiter;
mp_fun_1_t iternext; // may return MP_OBJ_STOP_ITERATION 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)
@ -483,11 +480,11 @@ typedef struct _mp_obj_float_t {
mp_float_t value; mp_float_t value;
} mp_obj_float_t; } mp_obj_float_t;
mp_float_t mp_obj_float_get(mp_obj_t self_in); 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_NOT_SUPPORTED mp_obj_t mp_obj_float_binary_op(int op, mp_float_t lhs_val, mp_obj_t rhs); // can return MP_OBJ_NULL if op not supported
// complex // complex
void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag); 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_NOT_SUPPORTED 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 if op not supported
#endif #endif
// tuple // tuple

View File

@ -140,7 +140,7 @@ STATIC mp_obj_t array_unary_op(int op, mp_obj_t o_in) {
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(o->len != 0); case MP_UNARY_OP_BOOL: return MP_BOOL(o->len != 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(o->len); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(o->len);
default: return MP_OBJ_NOT_SUPPORTED; default: return MP_OBJ_NULL; // op not supported
} }
} }
@ -166,7 +166,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
// TODO implement // TODO implement
// TODO: confirmed that both bytearray and array.array support // TODO: confirmed that both bytearray and array.array support
// slice deletion // slice deletion
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} else { } else {
mp_obj_array_t *o = self_in; mp_obj_array_t *o = self_in;
if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) { if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) {
@ -174,7 +174,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
// Only getting a slice is suported so far, not assignment // Only getting a slice is suported so far, not assignment
// TODO: confirmed that both bytearray and array.array support // TODO: confirmed that both bytearray and array.array support
// slice assignment (incl. of different size) // slice assignment (incl. of different size)
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
machine_uint_t start, stop; machine_uint_t start, stop;
if (!mp_seq_get_fast_slice_indexes(o->len, index_in, &start, &stop)) { if (!mp_seq_get_fast_slice_indexes(o->len, index_in, &start, &stop)) {

View File

@ -76,7 +76,7 @@ STATIC mp_obj_t bool_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
if (MP_BINARY_OP_OR <= op && op <= MP_BINARY_OP_NOT_EQUAL) { if (MP_BINARY_OP_OR <= op && op <= MP_BINARY_OP_NOT_EQUAL) {
return mp_binary_op(op, MP_OBJ_NEW_SMALL_INT((machine_int_t)mp_obj_is_true(lhs_in)), rhs_in); return mp_binary_op(op, MP_OBJ_NEW_SMALL_INT((machine_int_t)mp_obj_is_true(lhs_in)), rhs_in);
} }
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
const mp_obj_type_t mp_type_bool = { const mp_obj_type_t mp_type_bool = {

View File

@ -123,7 +123,7 @@ STATIC mp_obj_t complex_unary_op(int op, mp_obj_t o_in) {
case MP_UNARY_OP_BOOL: return MP_BOOL(o->real != 0 || o->imag != 0); case MP_UNARY_OP_BOOL: return MP_BOOL(o->real != 0 || o->imag != 0);
case MP_UNARY_OP_POSITIVE: return o_in; case MP_UNARY_OP_POSITIVE: return o_in;
case MP_UNARY_OP_NEGATIVE: return mp_obj_new_complex(-o->real, -o->imag); case MP_UNARY_OP_NEGATIVE: return mp_obj_new_complex(-o->real, -o->imag);
default: return MP_OBJ_NOT_SUPPORTED; default: return MP_OBJ_NULL; // op not supported
} }
} }
@ -233,7 +233,7 @@ mp_obj_t mp_obj_complex_binary_op(int op, mp_float_t lhs_real, mp_float_t lhs_im
case MP_BINARY_OP_EQUAL: return MP_BOOL(lhs_real == rhs_real && lhs_imag == rhs_imag); case MP_BINARY_OP_EQUAL: return MP_BOOL(lhs_real == rhs_real && lhs_imag == rhs_imag);
default: default:
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
return mp_obj_new_complex(lhs_real, lhs_imag); return mp_obj_new_complex(lhs_real, lhs_imag);
} }

View File

@ -103,7 +103,7 @@ STATIC mp_obj_t dict_unary_op(int op, mp_obj_t self_in) {
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(self->map.used != 0); case MP_UNARY_OP_BOOL: return MP_BOOL(self->map.used != 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT((machine_int_t)self->map.used); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT((machine_int_t)self->map.used);
default: return MP_OBJ_NOT_SUPPORTED; default: return MP_OBJ_NULL; // op not supported
} }
} }
@ -140,7 +140,7 @@ STATIC mp_obj_t dict_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
} }
default: default:
// op not supported // op not supported
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL;
} }
} }
@ -463,13 +463,13 @@ 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) { 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 */ // only supported for the 'keys' kind until sets and dicts are refactored
mp_obj_dict_view_t *o = lhs_in; mp_obj_dict_view_t *o = lhs_in;
if (o->kind != MP_DICT_VIEW_KEYS) { if (o->kind != MP_DICT_VIEW_KEYS) {
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
if (op != MP_BINARY_OP_IN) { if (op != MP_BINARY_OP_IN) {
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
return dict_binary_op(op, o->dict, rhs_in); return dict_binary_op(op, o->dict, rhs_in);
} }

View File

@ -96,7 +96,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_BOOL: return MP_BOOL(o->value != 0);
case MP_UNARY_OP_POSITIVE: return o_in; case MP_UNARY_OP_POSITIVE: return o_in;
case MP_UNARY_OP_NEGATIVE: return mp_obj_new_float(-o->value); case MP_UNARY_OP_NEGATIVE: return mp_obj_new_float(-o->value);
default: return MP_OBJ_NOT_SUPPORTED; default: return MP_OBJ_NULL; // op not supported
} }
} }
@ -165,7 +165,7 @@ mp_obj_t mp_obj_float_binary_op(int op, mp_float_t lhs_val, mp_obj_t rhs_in) {
case MP_BINARY_OP_MORE_EQUAL: return MP_BOOL(lhs_val >= rhs_val); case MP_BINARY_OP_MORE_EQUAL: return MP_BOOL(lhs_val >= rhs_val);
default: default:
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
return mp_obj_new_float(lhs_val); return mp_obj_new_float(lhs_val);
} }

View File

@ -59,7 +59,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. // we don't even need to check for 2nd arg type.
return MP_BOOL(lhs_in == rhs_in); return MP_BOOL(lhs_in == rhs_in);
} }
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op 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) { STATIC mp_obj_t fun_native_call(mp_obj_t self_in, uint n_args, uint n_kw, const mp_obj_t *args) {

View File

@ -216,7 +216,7 @@ bool mp_obj_int_is_positive(mp_obj_t self_in) {
// This is called for operations on SMALL_INT that are not handled by mp_unary_op // This is called for operations on SMALL_INT that are not handled by mp_unary_op
mp_obj_t mp_obj_int_unary_op(int op, mp_obj_t o_in) { mp_obj_t mp_obj_int_unary_op(int op, mp_obj_t o_in) {
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
// This is called for operations on SMALL_INT that are not handled by mp_binary_op // This is called for operations on SMALL_INT that are not handled by mp_binary_op
@ -285,7 +285,7 @@ mp_obj_t mp_obj_int_binary_op_extra_cases(int op, mp_obj_t lhs_in, mp_obj_t rhs_
return mp_binary_op(op, rhs_in, lhs_in); return mp_binary_op(op, rhs_in, lhs_in);
} }
} }
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
// this is a classmethod // this is a classmethod

View File

@ -64,7 +64,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_POSITIVE: return o_in;
case MP_UNARY_OP_NEGATIVE: return mp_obj_new_int_from_ll(-o->val); case MP_UNARY_OP_NEGATIVE: return mp_obj_new_int_from_ll(-o->val);
case MP_UNARY_OP_INVERT: return mp_obj_new_int_from_ll(~o->val); case MP_UNARY_OP_INVERT: return mp_obj_new_int_from_ll(~o->val);
default: return MP_OBJ_NOT_SUPPORTED; default: return MP_OBJ_NULL; // op not supported
} }
} }
@ -77,7 +77,7 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
} else if (MP_OBJ_IS_TYPE(lhs_in, &mp_type_int)) { } else if (MP_OBJ_IS_TYPE(lhs_in, &mp_type_int)) {
lhs_val = ((mp_obj_int_t*)lhs_in)->val; lhs_val = ((mp_obj_int_t*)lhs_in)->val;
} else { } else {
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
if (MP_OBJ_IS_SMALL_INT(rhs_in)) { if (MP_OBJ_IS_SMALL_INT(rhs_in)) {
@ -135,7 +135,7 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return MP_BOOL(lhs_val == rhs_val); return MP_BOOL(lhs_val == rhs_val);
default: default:
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
} }

View File

@ -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_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_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; } 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 MP_OBJ_NOT_SUPPORTED; default: return MP_OBJ_NULL; // op not supported
} }
} }
@ -108,7 +108,7 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
zlhs = &((mp_obj_int_t*)lhs_in)->mpz; zlhs = &((mp_obj_int_t*)lhs_in)->mpz;
} else { } else {
// unsupported type // unsupported type
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL;
} }
// if rhs is small int, then lhs was not (otherwise mp_binary_op handles it) // if rhs is small int, then lhs was not (otherwise mp_binary_op handles it)
@ -213,7 +213,7 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
break; break;
default: default:
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
return res; return res;
@ -233,7 +233,7 @@ mp_obj_t mp_obj_int_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return MP_BOOL(cmp == 0); return MP_BOOL(cmp == 0);
default: default:
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
} }
} }

View File

@ -103,7 +103,7 @@ STATIC mp_obj_t list_unary_op(int op, mp_obj_t self_in) {
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(self->len != 0); case MP_UNARY_OP_BOOL: return MP_BOOL(self->len != 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->len); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->len);
default: return MP_OBJ_NOT_SUPPORTED; default: return MP_OBJ_NULL; // op not supported
} }
} }
@ -112,7 +112,7 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
switch (op) { switch (op) {
case MP_BINARY_OP_ADD: { case MP_BINARY_OP_ADD: {
if (!MP_OBJ_IS_TYPE(rhs, &mp_type_list)) { if (!MP_OBJ_IS_TYPE(rhs, &mp_type_list)) {
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
mp_obj_list_t *p = rhs; mp_obj_list_t *p = rhs;
mp_obj_list_t *s = list_new(o->len + p->len); mp_obj_list_t *s = list_new(o->len + p->len);
@ -121,7 +121,7 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
} }
case MP_BINARY_OP_INPLACE_ADD: { case MP_BINARY_OP_INPLACE_ADD: {
if (!MP_OBJ_IS_TYPE(rhs, &mp_type_list)) { if (!MP_OBJ_IS_TYPE(rhs, &mp_type_list)) {
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
list_extend(lhs, rhs); list_extend(lhs, rhs);
return o; return o;
@ -129,7 +129,7 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
case MP_BINARY_OP_MULTIPLY: { case MP_BINARY_OP_MULTIPLY: {
machine_int_t n; machine_int_t n;
if (!mp_obj_get_int_maybe(rhs, &n)) { if (!mp_obj_get_int_maybe(rhs, &n)) {
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
mp_obj_list_t *s = list_new(o->len * n); mp_obj_list_t *s = list_new(o->len * n);
mp_seq_multiply(o->items, sizeof(*o->items), o->len, n, s->items); mp_seq_multiply(o->items, sizeof(*o->items), o->len, n, s->items);
@ -143,7 +143,7 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
return MP_BOOL(list_cmp_helper(op, lhs, rhs)); return MP_BOOL(list_cmp_helper(op, lhs, rhs));
default: default:
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
} }

View File

@ -44,7 +44,7 @@ STATIC void none_print(void (*print)(void *env, const char *fmt, ...), void *env
STATIC mp_obj_t none_unary_op(int op, mp_obj_t o_in) { STATIC mp_obj_t none_unary_op(int op, mp_obj_t o_in) {
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: return mp_const_false; case MP_UNARY_OP_BOOL: return mp_const_false;
default: return MP_OBJ_NOT_SUPPORTED; default: return MP_OBJ_NULL; // op not supported
} }
} }

View File

@ -475,7 +475,7 @@ STATIC mp_obj_t set_unary_op(int op, mp_obj_t self_in) {
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(self->set.used != 0); case MP_UNARY_OP_BOOL: return MP_BOOL(self->set.used != 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT((machine_int_t)self->set.used); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT((machine_int_t)self->set.used);
default: return MP_OBJ_NOT_SUPPORTED; default: return MP_OBJ_NULL; // op not supported
} }
} }
@ -514,7 +514,7 @@ STATIC mp_obj_t set_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
return MP_BOOL(elem != NULL); return MP_BOOL(elem != NULL);
} }
default: default:
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
} }

View File

@ -296,7 +296,7 @@ STATIC mp_obj_t str_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
case MP_BINARY_OP_MULTIPLY: { case MP_BINARY_OP_MULTIPLY: {
if (!MP_OBJ_IS_SMALL_INT(rhs_in)) { if (!MP_OBJ_IS_SMALL_INT(rhs_in)) {
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
int n = MP_OBJ_SMALL_INT_VALUE(rhs_in); int n = MP_OBJ_SMALL_INT_VALUE(rhs_in);
byte *data; byte *data;
@ -341,7 +341,7 @@ uncomparable:
} }
} }
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) { STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
@ -365,7 +365,7 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
return mp_obj_new_str(self_data + index_val, 1, true); return mp_obj_new_str(self_data + index_val, 1, true);
} }
} else { } else {
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
} }

View File

@ -120,7 +120,7 @@ mp_obj_t mp_obj_tuple_unary_op(int op, mp_obj_t self_in) {
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(self->len != 0); case MP_UNARY_OP_BOOL: return MP_BOOL(self->len != 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->len); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->len);
default: return MP_OBJ_NOT_SUPPORTED; default: return MP_OBJ_NULL; // op not supported
} }
} }
@ -129,7 +129,7 @@ mp_obj_t mp_obj_tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
switch (op) { 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)) { if (!mp_obj_is_subclass_fast(mp_obj_get_type(rhs), (mp_obj_t)&mp_type_tuple)) {
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
mp_obj_tuple_t *p = rhs; mp_obj_tuple_t *p = rhs;
mp_obj_tuple_t *s = mp_obj_new_tuple(o->len + p->len, NULL); mp_obj_tuple_t *s = mp_obj_new_tuple(o->len + p->len, NULL);
@ -138,7 +138,7 @@ mp_obj_t mp_obj_tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
} }
case MP_BINARY_OP_MULTIPLY: { case MP_BINARY_OP_MULTIPLY: {
if (!MP_OBJ_IS_SMALL_INT(rhs)) { if (!MP_OBJ_IS_SMALL_INT(rhs)) {
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
int n = MP_OBJ_SMALL_INT_VALUE(rhs); int n = MP_OBJ_SMALL_INT_VALUE(rhs);
mp_obj_tuple_t *s = mp_obj_new_tuple(o->len * n, NULL); mp_obj_tuple_t *s = mp_obj_new_tuple(o->len * n, NULL);
@ -153,8 +153,7 @@ mp_obj_t mp_obj_tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
return MP_BOOL(tuple_cmp_helper(op, lhs, rhs)); return MP_BOOL(tuple_cmp_helper(op, lhs, rhs));
default: default:
// op not supported return MP_OBJ_NULL; // op not supported
return MP_OBJ_NOT_SUPPORTED;
} }
} }
@ -176,7 +175,7 @@ mp_obj_t mp_obj_tuple_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
uint index_value = mp_get_index(self->base.type, self->len, index, false); uint index_value = mp_get_index(self->base.type, self->len, index, false);
return self->items[index_value]; return self->items[index_value];
} else { } else {
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
} }

View File

@ -287,7 +287,7 @@ STATIC mp_obj_t instance_unary_op(int op, mp_obj_t self_in) {
qstr op_name = unary_op_method_name[op]; qstr op_name = unary_op_method_name[op];
/* Still try to lookup native slot /* Still try to lookup native slot
if (op_name == 0) { if (op_name == 0) {
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL;
} }
*/ */
mp_obj_t member[2] = {MP_OBJ_NULL}; mp_obj_t member[2] = {MP_OBJ_NULL};
@ -297,7 +297,7 @@ STATIC mp_obj_t instance_unary_op(int op, mp_obj_t self_in) {
} else if (member[0] != MP_OBJ_NULL) { } else if (member[0] != MP_OBJ_NULL) {
return mp_call_function_1(member[0], self_in); return mp_call_function_1(member[0], self_in);
} else { } else {
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
} }
@ -374,7 +374,7 @@ STATIC mp_obj_t instance_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
qstr op_name = binary_op_method_name[op]; qstr op_name = binary_op_method_name[op];
/* Still try to lookup native slot /* Still try to lookup native slot
if (op_name == 0) { if (op_name == 0) {
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL;
} }
*/ */
mp_obj_t dest[3] = {MP_OBJ_NULL}; mp_obj_t dest[3] = {MP_OBJ_NULL};
@ -385,7 +385,7 @@ STATIC mp_obj_t instance_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
dest[2] = rhs_in; dest[2] = rhs_in;
return mp_call_method_n_kw(1, 0, dest); return mp_call_method_n_kw(1, 0, dest);
} else { } else {
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
} }
@ -499,7 +499,7 @@ STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
return mp_const_none; return mp_const_none;
} }
} else { } else {
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
} }
@ -632,7 +632,7 @@ STATIC mp_obj_t type_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
return MP_BOOL(lhs_in == rhs_in); return MP_BOOL(lhs_in == rhs_in);
default: default:
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} }
} }

View File

@ -200,7 +200,7 @@ mp_obj_t mp_unary_op(int op, mp_obj_t arg) {
mp_obj_type_t *type = mp_obj_get_type(arg); mp_obj_type_t *type = mp_obj_get_type(arg);
if (type->unary_op != NULL) { if (type->unary_op != NULL) {
mp_obj_t result = type->unary_op(op, arg); mp_obj_t result = type->unary_op(op, arg);
if (result != MP_OBJ_NOT_SUPPORTED) { if (result != MP_OBJ_NULL) {
return result; return result;
} }
} }
@ -439,7 +439,7 @@ mp_obj_t mp_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
mp_obj_type_t *type = mp_obj_get_type(rhs); mp_obj_type_t *type = mp_obj_get_type(rhs);
if (type->binary_op != NULL) { if (type->binary_op != NULL) {
mp_obj_t res = type->binary_op(op, rhs, lhs); mp_obj_t res = type->binary_op(op, rhs, lhs);
if (res != MP_OBJ_NOT_SUPPORTED) { if (res != MP_OBJ_NULL) {
return res; return res;
} }
} }
@ -467,7 +467,7 @@ generic_binary_op:
type = mp_obj_get_type(lhs); type = mp_obj_get_type(lhs);
if (type->binary_op != NULL) { if (type->binary_op != NULL) {
mp_obj_t result = type->binary_op(op, lhs, rhs); mp_obj_t result = type->binary_op(op, lhs, rhs);
if (result != MP_OBJ_NOT_SUPPORTED) { if (result != MP_OBJ_NULL) {
return result; return result;
} }
} }

View File

@ -81,7 +81,7 @@ STATIC mp_obj_t stm_mem_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value)
stm_mem_obj_t *self = self_in; stm_mem_obj_t *self = self_in;
if (value == MP_OBJ_NULL) { if (value == MP_OBJ_NULL) {
// delete // delete
return MP_OBJ_NOT_SUPPORTED; return MP_OBJ_NULL; // op not supported
} else if (value == MP_OBJ_SENTINEL) { } else if (value == MP_OBJ_SENTINEL) {
// load // load
uint32_t addr = get_read_addr(index, self->elem_size); uint32_t addr = get_read_addr(index, self->elem_size);