Commit 1b586f3a authored by Paul Sokolovsky's avatar Paul Sokolovsky
Browse files

py: Rename MP_BOOL() to mp_obj_new_bool() for consistency in naming.

parent 53ca6ae1
...@@ -54,7 +54,7 @@ STATIC mp_obj_t network_server_running(mp_uint_t n_args, const mp_obj_t *args) { ...@@ -54,7 +54,7 @@ STATIC mp_obj_t network_server_running(mp_uint_t n_args, const mp_obj_t *args) {
return mp_const_none; return mp_const_none;
} else { } else {
// get // get
return MP_BOOL(servers_are_enabled()); return mp_obj_new_bool(servers_are_enabled());
} }
} }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_server_running_obj, 0, 1, network_server_running); STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(network_server_running_obj, 0, 1, network_server_running);
......
...@@ -534,7 +534,7 @@ STATIC mp_obj_t mp_builtin_hasattr(mp_obj_t object_in, mp_obj_t attr_in) { ...@@ -534,7 +534,7 @@ STATIC mp_obj_t mp_builtin_hasattr(mp_obj_t object_in, mp_obj_t attr_in) {
// in nlr_push and handle exception. // in nlr_push and handle exception.
mp_load_method_maybe(object_in, MP_OBJ_QSTR_VALUE(attr_in), dest); mp_load_method_maybe(object_in, MP_OBJ_QSTR_VALUE(attr_in), dest);
return MP_BOOL(dest[0] != MP_OBJ_NULL); return mp_obj_new_bool(dest[0] != MP_OBJ_NULL);
} }
MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_hasattr_obj, mp_builtin_hasattr); MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_hasattr_obj, mp_builtin_hasattr);
......
...@@ -63,7 +63,7 @@ STATIC mp_obj_t gc_enable(void) { ...@@ -63,7 +63,7 @@ STATIC mp_obj_t gc_enable(void) {
MP_DEFINE_CONST_FUN_OBJ_0(gc_enable_obj, gc_enable); MP_DEFINE_CONST_FUN_OBJ_0(gc_enable_obj, gc_enable);
STATIC mp_obj_t gc_isenabled(void) { STATIC mp_obj_t gc_isenabled(void) {
return MP_BOOL(MP_STATE_MEM(gc_auto_collect_enabled)); return mp_obj_new_bool(MP_STATE_MEM(gc_auto_collect_enabled));
} }
MP_DEFINE_CONST_FUN_OBJ_0(gc_isenabled_obj, gc_isenabled); MP_DEFINE_CONST_FUN_OBJ_0(gc_isenabled_obj, gc_isenabled);
......
...@@ -45,7 +45,7 @@ ...@@ -45,7 +45,7 @@
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_math_## py_name ## _obj, mp_math_ ## py_name); STATIC MP_DEFINE_CONST_FUN_OBJ_2(mp_math_## py_name ## _obj, mp_math_ ## py_name);
#define MATH_FUN_1_TO_BOOL(py_name, c_name) \ #define MATH_FUN_1_TO_BOOL(py_name, c_name) \
STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return MP_BOOL(c_name(mp_obj_get_float(x_obj))); } \ STATIC mp_obj_t mp_math_ ## py_name(mp_obj_t x_obj) { return mp_obj_new_bool(c_name(mp_obj_get_float(x_obj))); } \
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name); STATIC MP_DEFINE_CONST_FUN_OBJ_1(mp_math_## py_name ## _obj, mp_math_ ## py_name);
#define MATH_FUN_1_TO_INT(py_name, c_name) \ #define MATH_FUN_1_TO_INT(py_name, c_name) \
......
...@@ -67,7 +67,7 @@ mp_obj_t mp_convert_native_to_obj(mp_uint_t val, mp_uint_t type) { ...@@ -67,7 +67,7 @@ mp_obj_t mp_convert_native_to_obj(mp_uint_t val, mp_uint_t type) {
DEBUG_printf("mp_convert_native_to_obj(" UINT_FMT ", " UINT_FMT ")\n", val, type); DEBUG_printf("mp_convert_native_to_obj(" UINT_FMT ", " UINT_FMT ")\n", val, type);
switch (type & 3) { switch (type & 3) {
case MP_NATIVE_TYPE_OBJ: return (mp_obj_t)val; case MP_NATIVE_TYPE_OBJ: return (mp_obj_t)val;
case MP_NATIVE_TYPE_BOOL: return MP_BOOL(val); case MP_NATIVE_TYPE_BOOL: return mp_obj_new_bool(val);
case MP_NATIVE_TYPE_INT: return mp_obj_new_int(val); case MP_NATIVE_TYPE_INT: return mp_obj_new_int(val);
case MP_NATIVE_TYPE_UINT: return mp_obj_new_int_from_uint(val); case MP_NATIVE_TYPE_UINT: return mp_obj_new_int_from_uint(val);
default: assert(0); return mp_const_none; default: assert(0); return mp_const_none;
......
...@@ -459,7 +459,7 @@ extern const struct _mp_obj_exception_t mp_const_GeneratorExit_obj; ...@@ -459,7 +459,7 @@ extern const struct _mp_obj_exception_t mp_const_GeneratorExit_obj;
mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict); mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict);
mp_obj_t mp_obj_new_none(void); mp_obj_t mp_obj_new_none(void);
mp_obj_t mp_obj_new_bool(bool value); static inline mp_obj_t mp_obj_new_bool(mp_int_t x) { return x ? mp_const_true : mp_const_false; }
mp_obj_t mp_obj_new_cell(mp_obj_t obj); mp_obj_t mp_obj_new_cell(mp_obj_t obj);
mp_obj_t mp_obj_new_int(mp_int_t value); mp_obj_t mp_obj_new_int(mp_int_t value);
mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value); mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value);
...@@ -528,10 +528,6 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); // may return MP_OBJ_NULL ...@@ -528,10 +528,6 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); // may return MP_OBJ_NULL
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val); mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val);
mp_obj_t mp_generic_unary_op(mp_uint_t op, mp_obj_t o_in); mp_obj_t mp_generic_unary_op(mp_uint_t op, mp_obj_t o_in);
// bool
// TODO make lower case when it has proven itself
static inline mp_obj_t MP_BOOL(mp_int_t x) { return x ? mp_const_true : mp_const_false; }
// cell // cell
mp_obj_t mp_obj_cell_get(mp_obj_t self_in); mp_obj_t mp_obj_cell_get(mp_obj_t self_in);
void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj); void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj);
......
...@@ -246,7 +246,7 @@ STATIC mp_obj_t memoryview_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_ ...@@ -246,7 +246,7 @@ STATIC mp_obj_t memoryview_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_
STATIC mp_obj_t array_unary_op(mp_uint_t op, mp_obj_t o_in) { STATIC mp_obj_t array_unary_op(mp_uint_t op, mp_obj_t o_in) {
mp_obj_array_t *o = o_in; mp_obj_array_t *o = o_in;
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(o->len != 0); case MP_UNARY_OP_BOOL: return mp_obj_new_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_NULL; // op not supported default: return MP_OBJ_NULL; // op not supported
} }
...@@ -290,7 +290,7 @@ STATIC mp_obj_t array_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) ...@@ -290,7 +290,7 @@ STATIC mp_obj_t array_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in)
if (!mp_get_buffer(rhs_in, &rhs_bufinfo, MP_BUFFER_READ)) { if (!mp_get_buffer(rhs_in, &rhs_bufinfo, MP_BUFFER_READ)) {
return mp_const_false; return mp_const_false;
} }
return MP_BOOL(mp_seq_cmp_bytes(op, lhs_bufinfo.buf, lhs_bufinfo.len, rhs_bufinfo.buf, rhs_bufinfo.len)); return mp_obj_new_bool(mp_seq_cmp_bytes(op, lhs_bufinfo.buf, lhs_bufinfo.len, rhs_bufinfo.buf, rhs_bufinfo.len));
} }
default: default:
......
...@@ -116,7 +116,7 @@ STATIC mp_obj_t complex_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n ...@@ -116,7 +116,7 @@ STATIC mp_obj_t complex_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n
STATIC mp_obj_t complex_unary_op(mp_uint_t op, mp_obj_t o_in) { STATIC mp_obj_t complex_unary_op(mp_uint_t op, mp_obj_t o_in) {
mp_obj_complex_t *o = o_in; mp_obj_complex_t *o = o_in;
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(o->real != 0 || o->imag != 0); case MP_UNARY_OP_BOOL: return mp_obj_new_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_NULL; // op not supported default: return MP_OBJ_NULL; // op not supported
...@@ -240,7 +240,7 @@ mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t ...@@ -240,7 +240,7 @@ mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t
break; break;
} }
case MP_BINARY_OP_EQUAL: return MP_BOOL(lhs_real == rhs_real && lhs_imag == rhs_imag); case MP_BINARY_OP_EQUAL: return mp_obj_new_bool(lhs_real == rhs_real && lhs_imag == rhs_imag);
default: default:
return MP_OBJ_NULL; // op not supported return MP_OBJ_NULL; // op not supported
......
...@@ -103,7 +103,7 @@ STATIC mp_obj_t dict_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw ...@@ -103,7 +103,7 @@ STATIC mp_obj_t dict_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw
STATIC mp_obj_t dict_unary_op(mp_uint_t op, mp_obj_t self_in) { STATIC mp_obj_t dict_unary_op(mp_uint_t op, mp_obj_t self_in) {
mp_obj_dict_t *self = MP_OBJ_CAST(self_in); mp_obj_dict_t *self = MP_OBJ_CAST(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_obj_new_bool(self->map.used != 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->map.used); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->map.used);
default: return MP_OBJ_NULL; // op not supported default: return MP_OBJ_NULL; // op not supported
} }
...@@ -114,7 +114,7 @@ STATIC mp_obj_t dict_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { ...@@ -114,7 +114,7 @@ STATIC mp_obj_t dict_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
switch (op) { switch (op) {
case MP_BINARY_OP_IN: { case MP_BINARY_OP_IN: {
mp_map_elem_t *elem = mp_map_lookup(&o->map, rhs_in, MP_MAP_LOOKUP); mp_map_elem_t *elem = mp_map_lookup(&o->map, rhs_in, MP_MAP_LOOKUP);
return MP_BOOL(elem != NULL); return mp_obj_new_bool(elem != NULL);
} }
case MP_BINARY_OP_EQUAL: { case MP_BINARY_OP_EQUAL: {
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT #if MICROPY_PY_COLLECTIONS_ORDEREDDICT
......
...@@ -85,7 +85,7 @@ STATIC mp_obj_t float_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_k ...@@ -85,7 +85,7 @@ STATIC mp_obj_t float_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_k
STATIC mp_obj_t float_unary_op(mp_uint_t op, mp_obj_t o_in) { STATIC mp_obj_t float_unary_op(mp_uint_t op, mp_obj_t o_in) {
mp_obj_float_t *o = o_in; mp_obj_float_t *o = o_in;
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(o->value != 0); case MP_UNARY_OP_BOOL: return mp_obj_new_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_NULL; // op not supported default: return MP_OBJ_NULL; // op not supported
...@@ -216,11 +216,11 @@ mp_obj_t mp_obj_float_binary_op(mp_uint_t op, mp_float_t lhs_val, mp_obj_t rhs_i ...@@ -216,11 +216,11 @@ mp_obj_t mp_obj_float_binary_op(mp_uint_t op, mp_float_t lhs_val, mp_obj_t rhs_i
}; };
return mp_obj_new_tuple(2, tuple); return mp_obj_new_tuple(2, tuple);
} }
case MP_BINARY_OP_LESS: return MP_BOOL(lhs_val < rhs_val); case MP_BINARY_OP_LESS: return mp_obj_new_bool(lhs_val < rhs_val);
case MP_BINARY_OP_MORE: return MP_BOOL(lhs_val > rhs_val); case MP_BINARY_OP_MORE: return mp_obj_new_bool(lhs_val > rhs_val);
case MP_BINARY_OP_EQUAL: return MP_BOOL(lhs_val == rhs_val); case MP_BINARY_OP_EQUAL: return mp_obj_new_bool(lhs_val == rhs_val);
case MP_BINARY_OP_LESS_EQUAL: return MP_BOOL(lhs_val <= rhs_val); case MP_BINARY_OP_LESS_EQUAL: return mp_obj_new_bool(lhs_val <= rhs_val);
case MP_BINARY_OP_MORE_EQUAL: return MP_BOOL(lhs_val >= rhs_val); case MP_BINARY_OP_MORE_EQUAL: return mp_obj_new_bool(lhs_val >= rhs_val);
default: default:
return MP_OBJ_NULL; // op not supported return MP_OBJ_NULL; // op not supported
......
...@@ -106,7 +106,7 @@ mp_obj_t mp_obj_int_abs(mp_obj_t self_in) { ...@@ -106,7 +106,7 @@ mp_obj_t mp_obj_int_abs(mp_obj_t self_in) {
mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) { mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) {
mp_obj_int_t *o = o_in; mp_obj_int_t *o = o_in;
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(o->val != 0); case MP_UNARY_OP_BOOL: return mp_obj_new_bool(o->val != 0);
// truncate value to fit in mp_int_t, which gives the same hash as // truncate value to fit in mp_int_t, which gives the same hash as
// small int if the value fits without truncation // small int if the value fits without truncation
...@@ -191,15 +191,15 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { ...@@ -191,15 +191,15 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
} }
case MP_BINARY_OP_LESS: case MP_BINARY_OP_LESS:
return MP_BOOL(lhs_val < rhs_val); return mp_obj_new_bool(lhs_val < rhs_val);
case MP_BINARY_OP_MORE: case MP_BINARY_OP_MORE:
return MP_BOOL(lhs_val > rhs_val); return mp_obj_new_bool(lhs_val > rhs_val);
case MP_BINARY_OP_LESS_EQUAL: case MP_BINARY_OP_LESS_EQUAL:
return MP_BOOL(lhs_val <= rhs_val); return mp_obj_new_bool(lhs_val <= rhs_val);
case MP_BINARY_OP_MORE_EQUAL: case MP_BINARY_OP_MORE_EQUAL:
return MP_BOOL(lhs_val >= rhs_val); return mp_obj_new_bool(lhs_val >= rhs_val);
case MP_BINARY_OP_EQUAL: case MP_BINARY_OP_EQUAL:
return MP_BOOL(lhs_val == rhs_val); return mp_obj_new_bool(lhs_val == rhs_val);
default: default:
return MP_OBJ_NULL; // op not supported return MP_OBJ_NULL; // op not supported
......
...@@ -145,7 +145,7 @@ mp_obj_t mp_obj_int_abs(mp_obj_t self_in) { ...@@ -145,7 +145,7 @@ mp_obj_t mp_obj_int_abs(mp_obj_t self_in) {
mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) { mp_obj_t mp_obj_int_unary_op(mp_uint_t op, mp_obj_t o_in) {
mp_obj_int_t *o = o_in; mp_obj_int_t *o = o_in;
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(!mpz_is_zero(&o->mpz)); case MP_UNARY_OP_BOOL: return mp_obj_new_bool(!mpz_is_zero(&o->mpz));
case MP_UNARY_OP_HASH: return MP_OBJ_NEW_SMALL_INT(mpz_hash(&o->mpz)); case MP_UNARY_OP_HASH: return MP_OBJ_NEW_SMALL_INT(mpz_hash(&o->mpz));
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; }
...@@ -308,15 +308,15 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { ...@@ -308,15 +308,15 @@ mp_obj_t mp_obj_int_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
int cmp = mpz_cmp(zlhs, zrhs); int cmp = mpz_cmp(zlhs, zrhs);
switch (op) { switch (op) {
case MP_BINARY_OP_LESS: case MP_BINARY_OP_LESS:
return MP_BOOL(cmp < 0); return mp_obj_new_bool(cmp < 0);
case MP_BINARY_OP_MORE: case MP_BINARY_OP_MORE:
return MP_BOOL(cmp > 0); return mp_obj_new_bool(cmp > 0);
case MP_BINARY_OP_LESS_EQUAL: case MP_BINARY_OP_LESS_EQUAL:
return MP_BOOL(cmp <= 0); return mp_obj_new_bool(cmp <= 0);
case MP_BINARY_OP_MORE_EQUAL: case MP_BINARY_OP_MORE_EQUAL:
return MP_BOOL(cmp >= 0); return mp_obj_new_bool(cmp >= 0);
case MP_BINARY_OP_EQUAL: case MP_BINARY_OP_EQUAL:
return MP_BOOL(cmp == 0); return mp_obj_new_bool(cmp == 0);
default: default:
return MP_OBJ_NULL; // op not supported return MP_OBJ_NULL; // op not supported
......
...@@ -102,7 +102,7 @@ STATIC bool list_cmp_helper(mp_uint_t op, mp_obj_t self_in, mp_obj_t another_in) ...@@ -102,7 +102,7 @@ STATIC bool list_cmp_helper(mp_uint_t op, mp_obj_t self_in, mp_obj_t another_in)
STATIC mp_obj_t list_unary_op(mp_uint_t op, mp_obj_t self_in) { STATIC mp_obj_t list_unary_op(mp_uint_t op, mp_obj_t self_in) {
mp_obj_list_t *self = MP_OBJ_CAST(self_in); mp_obj_list_t *self = MP_OBJ_CAST(self_in);
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(self->len != 0); case MP_UNARY_OP_BOOL: return mp_obj_new_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_NULL; // op not supported default: return MP_OBJ_NULL; // op not supported
} }
...@@ -141,7 +141,7 @@ STATIC mp_obj_t list_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { ...@@ -141,7 +141,7 @@ STATIC mp_obj_t list_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
case MP_BINARY_OP_LESS_EQUAL: case MP_BINARY_OP_LESS_EQUAL:
case MP_BINARY_OP_MORE: case MP_BINARY_OP_MORE:
case MP_BINARY_OP_MORE_EQUAL: case MP_BINARY_OP_MORE_EQUAL:
return MP_BOOL(list_cmp_helper(op, lhs, rhs)); return mp_obj_new_bool(list_cmp_helper(op, lhs, rhs));
default: default:
return MP_OBJ_NULL; // op not supported return MP_OBJ_NULL; // op not supported
......
...@@ -131,7 +131,7 @@ STATIC mp_obj_t range_unary_op(mp_uint_t op, mp_obj_t self_in) { ...@@ -131,7 +131,7 @@ STATIC mp_obj_t range_unary_op(mp_uint_t op, mp_obj_t self_in) {
mp_obj_range_t *self = self_in; mp_obj_range_t *self = self_in;
mp_int_t len = range_len(self); mp_int_t len = range_len(self);
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(len > 0); case MP_UNARY_OP_BOOL: return mp_obj_new_bool(len > 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(len); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(len);
default: return MP_OBJ_NULL; // op not supported default: return MP_OBJ_NULL; // op not supported
} }
......
...@@ -366,7 +366,7 @@ STATIC mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool ...@@ -366,7 +366,7 @@ STATIC mp_obj_t set_issubset_internal(mp_obj_t self_in, mp_obj_t other_in, bool
if (cleanup_other) { if (cleanup_other) {
set_clear(other); set_clear(other);
} }
return MP_BOOL(out); return mp_obj_new_bool(out);
} }
STATIC mp_obj_t set_issubset(mp_obj_t self_in, mp_obj_t other_in) { STATIC mp_obj_t set_issubset(mp_obj_t self_in, mp_obj_t other_in) {
return set_issubset_internal(self_in, other_in, false); return set_issubset_internal(self_in, other_in, false);
...@@ -471,7 +471,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_union_obj, set_union); ...@@ -471,7 +471,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(set_union_obj, set_union);
STATIC mp_obj_t set_unary_op(mp_uint_t op, mp_obj_t self_in) { STATIC mp_obj_t set_unary_op(mp_uint_t op, mp_obj_t self_in) {
mp_obj_set_t *self = self_in; mp_obj_set_t *self = 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_obj_new_bool(self->set.used != 0);
case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->set.used); case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->set.used);
#if MICROPY_PY_BUILTINS_FROZENSET #if MICROPY_PY_BUILTINS_FROZENSET
case MP_UNARY_OP_HASH: case MP_UNARY_OP_HASH:
...@@ -525,7 +525,7 @@ STATIC mp_obj_t set_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { ...@@ -525,7 +525,7 @@ STATIC mp_obj_t set_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
case MP_BINARY_OP_IN: { case MP_BINARY_OP_IN: {
mp_obj_set_t *o = lhs; mp_obj_set_t *o = lhs;
mp_obj_t elem = mp_set_lookup(&o->set, rhs, MP_MAP_LOOKUP); mp_obj_t elem = mp_set_lookup(&o->set, rhs, MP_MAP_LOOKUP);
return MP_BOOL(elem != NULL); return mp_obj_new_bool(elem != NULL);
} }
default: default:
return MP_OBJ_NULL; // op not supported return MP_OBJ_NULL; // op not supported
......
...@@ -360,7 +360,7 @@ mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { ...@@ -360,7 +360,7 @@ mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
case MP_BINARY_OP_IN: case MP_BINARY_OP_IN:
/* NOTE `a in b` is `b.__contains__(a)` */ /* NOTE `a in b` is `b.__contains__(a)` */
return MP_BOOL(find_subbytes(lhs_data, lhs_len, rhs_data, rhs_len, 1) != NULL); return mp_obj_new_bool(find_subbytes(lhs_data, lhs_len, rhs_data, rhs_len, 1) != NULL);
//case MP_BINARY_OP_NOT_EQUAL: // This is never passed here //case MP_BINARY_OP_NOT_EQUAL: // This is never passed here
case MP_BINARY_OP_EQUAL: // This will be passed only for bytes, str is dealt with in mp_obj_equal() case MP_BINARY_OP_EQUAL: // This will be passed only for bytes, str is dealt with in mp_obj_equal()
...@@ -368,7 +368,7 @@ mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) { ...@@ -368,7 +368,7 @@ mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
case MP_BINARY_OP_LESS_EQUAL: case MP_BINARY_OP_LESS_EQUAL:
case MP_BINARY_OP_MORE: case MP_BINARY_OP_MORE:
case MP_BINARY_OP_MORE_EQUAL: case MP_BINARY_OP_MORE_EQUAL:
return MP_BOOL(mp_seq_cmp_bytes(op, lhs_data, lhs_len, rhs_data, rhs_len)); return mp_obj_new_bool(mp_seq_cmp_bytes(op, lhs_data, lhs_len, rhs_data, rhs_len));
} }
return MP_OBJ_NULL; // op not supported return MP_OBJ_NULL; // op not supported
...@@ -695,7 +695,7 @@ STATIC mp_obj_t str_startswith(mp_uint_t n_args, const mp_obj_t *args) { ...@@ -695,7 +695,7 @@ STATIC mp_obj_t str_startswith(mp_uint_t n_args, const mp_obj_t *args) {
if (prefix_len + (start - str) > str_len) { if (prefix_len + (start - str) > str_len) {
return mp_const_false; return mp_const_false;
} }
return MP_BOOL(memcmp(start, prefix, prefix_len) == 0); return mp_obj_new_bool(memcmp(start, prefix, prefix_len) == 0);
} }
STATIC mp_obj_t str_endswith(mp_uint_t n_args, const mp_obj_t *args) { STATIC mp_obj_t str_endswith(mp_uint_t n_args, const mp_obj_t *args) {
...@@ -708,7 +708,7 @@ STATIC mp_obj_t str_endswith(mp_uint_t n_args, const mp_obj_t *args) { ...@@ -708,7 +708,7 @@ STATIC mp_obj_t str_endswith(mp_uint_t n_args, const mp_obj_t *args) {
if (suffix_len > str_len) { if (suffix_len > str_len) {
return mp_const_false; return mp_const_false;
} }
return MP_BOOL(memcmp(str + (str_len - suffix_len), suffix, suffix_len) == 0); return mp_obj_new_bool(memcmp(str + (str_len - suffix_len), suffix, suffix_len) == 0);
} }
enum { LSTRIP, RSTRIP, STRIP }; enum { LSTRIP, RSTRIP, STRIP };
......
...@@ -104,7 +104,7 @@ STATIC mp_obj_t uni_unary_op(mp_uint_t op, mp_obj_t self_in) { ...@@ -104,7 +104,7 @@ STATIC mp_obj_t uni_unary_op(mp_uint_t op, mp_obj_t self_in) {
GET_STR_DATA_LEN(self_in, str_data, str_len); GET_STR_DATA_LEN(self_in, str_data, str_len);
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: case MP_UNARY_OP_BOOL:
return MP_BOOL(str_len != 0); return mp_obj_new_bool(str_len != 0);
case MP_UNARY_OP_LEN: case MP_UNARY_OP_LEN:
return MP_OBJ_NEW_SMALL_INT(unichar_charlen((const char *)str_data, str_len)); return MP_OBJ_NEW_SMALL_INT(unichar_charlen((const char *)str_data, str_len));
default: default:
......
...@@ -125,7 +125,7 @@ STATIC bool tuple_cmp_helper(mp_uint_t op, mp_obj_t self_in, mp_obj_t another_in ...@@ -125,7 +125,7 @@ STATIC bool tuple_cmp_helper(mp_uint_t op, mp_obj_t self_in, mp_obj_t another_in
mp_obj_t mp_obj_tuple_unary_op(mp_uint_t op, mp_obj_t self_in) { mp_obj_t mp_obj_tuple_unary_op(mp_uint_t op, mp_obj_t self_in) {
mp_obj_tuple_t *self = self_in; mp_obj_tuple_t *self = self_in;
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: return MP_BOOL(self->len != 0); case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->len != 0);
case MP_UNARY_OP_HASH: { case MP_UNARY_OP_HASH: {
// start hash with pointer to empty tuple, to make it fairly unique // start hash with pointer to empty tuple, to make it fairly unique
mp_int_t hash = (mp_int_t)mp_const_empty_tuple; mp_int_t hash = (mp_int_t)mp_const_empty_tuple;
...@@ -168,7 +168,7 @@ mp_obj_t mp_obj_tuple_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { ...@@ -168,7 +168,7 @@ mp_obj_t mp_obj_tuple_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
case MP_BINARY_OP_LESS_EQUAL: case MP_BINARY_OP_LESS_EQUAL:
case MP_BINARY_OP_MORE: case MP_BINARY_OP_MORE:
case MP_BINARY_OP_MORE_EQUAL: case MP_BINARY_OP_MORE_EQUAL:
return MP_BOOL(tuple_cmp_helper(op, lhs, rhs)); return mp_obj_new_bool(tuple_cmp_helper(op, lhs, rhs));
default: default:
return MP_OBJ_NULL; // op not supported return MP_OBJ_NULL; // op not supported
......
...@@ -188,7 +188,7 @@ mp_obj_t mp_unary_op(mp_uint_t op, mp_obj_t arg) { ...@@ -188,7 +188,7 @@ mp_obj_t mp_unary_op(mp_uint_t op, mp_obj_t arg) {
mp_int_t val = MP_OBJ_SMALL_INT_VALUE(arg); mp_int_t val = MP_OBJ_SMALL_INT_VALUE(arg);
switch (op) { switch (op) {
case MP_UNARY_OP_BOOL: case MP_UNARY_OP_BOOL:
return MP_BOOL(val != 0); return mp_obj_new_bool(val != 0);
case MP_UNARY_OP_HASH: case MP_UNARY_OP_HASH:
return arg; return arg;
case MP_UNARY_OP_POSITIVE: case MP_UNARY_OP_POSITIVE:
...@@ -243,7 +243,7 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { ...@@ -243,7 +243,7 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
// deal with is // deal with is
if (op == MP_BINARY_OP_IS) { if (op == MP_BINARY_OP_IS) {
return MP_BOOL(lhs == rhs); return mp_obj_new_bool(lhs == rhs);
} }
// deal with == and != for all types // deal with == and != for all types
...@@ -443,10 +443,10 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { ...@@ -443,10 +443,10 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
return tuple; return tuple;
} }
case MP_BINARY_OP_LESS: return MP_BOOL(lhs_val < rhs_val); break; case MP_BINARY_OP_LESS: return mp_obj_new_bool(lhs_val < rhs_val); break;
case MP_BINARY_OP_MORE: return MP_BOOL(lhs_val > rhs_val); break; case MP_BINARY_OP_MORE: return mp_obj_new_bool(lhs_val > rhs_val); break;
case MP_BINARY_OP_LESS_EQUAL: return MP_BOOL(lhs_val <= rhs_val); break; case MP_BINARY_OP_LESS_EQUAL: return mp_obj_new_bool(lhs_val <= rhs_val); break;
case MP_BINARY_OP_MORE_EQUAL: return MP_BOOL(lhs_val >= rhs_val); break; case MP_BINARY_OP_MORE_EQUAL: return mp_obj_new_bool(lhs_val >= rhs_val); break;
default: default:
goto unsupported_op; goto unsupported_op;
......
...@@ -48,7 +48,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(pyb_wfi_obj, pyb_wfi); ...@@ -48,7 +48,7 @@ MP_DEFINE_CONST_FUN_OBJ_0(pyb_wfi_obj, pyb_wfi);
/// respectively. This return value can be passed to enable_irq to restore /// respectively. This return value can be passed to enable_irq to restore
/// the IRQ to its original state. /// the IRQ to its original state.
STATIC mp_obj_t pyb_disable_irq(void) { STATIC mp_obj_t pyb_disable_irq(void) {
return MP_BOOL(disable_irq() == IRQ_STATE_ENABLED); return mp_obj_new_bool(disable_irq() == IRQ_STATE_ENABLED);
} }
MP_DEFINE_CONST_FUN_OBJ_0(pyb_disable_irq_obj, pyb_disable_irq); MP_DEFINE_CONST_FUN_OBJ_0(pyb_disable_irq_obj, pyb_disable_irq);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment