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

This commit is contained in:
Paul Sokolovsky 2015-10-11 12:09:43 +03:00
parent 53ca6ae1f3
commit 1b586f3a73
26 changed files with 57 additions and 61 deletions

View File

@ -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;
} else {
// 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);

View File

@ -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.
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);

View File

@ -63,7 +63,7 @@ STATIC mp_obj_t gc_enable(void) {
MP_DEFINE_CONST_FUN_OBJ_0(gc_enable_obj, gc_enable);
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);

View File

@ -45,7 +45,7 @@
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) \
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);
#define MATH_FUN_1_TO_INT(py_name, c_name) \

View File

@ -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);
switch (type & 3) {
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_UINT: return mp_obj_new_int_from_uint(val);
default: assert(0); return mp_const_none;

View File

@ -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_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_int(mp_int_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
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);
// 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
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);

View File

@ -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) {
mp_obj_array_t *o = o_in;
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);
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)
if (!mp_get_buffer(rhs_in, &rhs_bufinfo, MP_BUFFER_READ)) {
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:

View File

@ -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) {
mp_obj_complex_t *o = o_in;
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_NEGATIVE: return mp_obj_new_complex(-o->real, -o->imag);
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
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:
return MP_OBJ_NULL; // op not supported

View File

@ -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) {
mp_obj_dict_t *self = MP_OBJ_CAST(self_in);
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);
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) {
switch (op) {
case MP_BINARY_OP_IN: {
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: {
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT

View File

@ -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) {
mp_obj_float_t *o = o_in;
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_NEGATIVE: return mp_obj_new_float(-o->value);
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
};
return mp_obj_new_tuple(2, tuple);
}
case MP_BINARY_OP_LESS: return MP_BOOL(lhs_val < rhs_val);
case MP_BINARY_OP_MORE: return MP_BOOL(lhs_val > rhs_val);
case MP_BINARY_OP_EQUAL: return MP_BOOL(lhs_val == rhs_val);
case MP_BINARY_OP_LESS_EQUAL: return MP_BOOL(lhs_val <= rhs_val);
case MP_BINARY_OP_MORE_EQUAL: 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_obj_new_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_obj_new_bool(lhs_val <= rhs_val);
case MP_BINARY_OP_MORE_EQUAL: return mp_obj_new_bool(lhs_val >= rhs_val);
default:
return MP_OBJ_NULL; // op not supported

View File

@ -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_int_t *o = o_in;
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
// 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) {
}
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:
return MP_BOOL(lhs_val > rhs_val);
return mp_obj_new_bool(lhs_val > rhs_val);
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:
return MP_BOOL(lhs_val >= rhs_val);
return mp_obj_new_bool(lhs_val >= rhs_val);
case MP_BINARY_OP_EQUAL:
return MP_BOOL(lhs_val == rhs_val);
return mp_obj_new_bool(lhs_val == rhs_val);
default:
return MP_OBJ_NULL; // op not supported

View File

@ -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_int_t *o = o_in;
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_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; }
@ -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);
switch (op) {
case MP_BINARY_OP_LESS:
return MP_BOOL(cmp < 0);
return mp_obj_new_bool(cmp < 0);
case MP_BINARY_OP_MORE:
return MP_BOOL(cmp > 0);
return mp_obj_new_bool(cmp > 0);
case MP_BINARY_OP_LESS_EQUAL:
return MP_BOOL(cmp <= 0);
return mp_obj_new_bool(cmp <= 0);
case MP_BINARY_OP_MORE_EQUAL:
return MP_BOOL(cmp >= 0);
return mp_obj_new_bool(cmp >= 0);
case MP_BINARY_OP_EQUAL:
return MP_BOOL(cmp == 0);
return mp_obj_new_bool(cmp == 0);
default:
return MP_OBJ_NULL; // op not supported

View File

@ -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) {
mp_obj_list_t *self = MP_OBJ_CAST(self_in);
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);
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) {
case MP_BINARY_OP_LESS_EQUAL:
case MP_BINARY_OP_MORE:
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:
return MP_OBJ_NULL; // op not supported

View File

@ -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_int_t len = range_len(self);
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);
default: return MP_OBJ_NULL; // op not supported
}

View File

@ -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) {
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) {
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);
STATIC mp_obj_t set_unary_op(mp_uint_t op, mp_obj_t self_in) {
mp_obj_set_t *self = self_in;
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);
#if MICROPY_PY_BUILTINS_FROZENSET
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) {
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);
return mp_obj_new_bool(elem != NULL);
}
default:
return MP_OBJ_NULL; // op not supported

View File

@ -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:
/* 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_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) {
case MP_BINARY_OP_LESS_EQUAL:
case MP_BINARY_OP_MORE:
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
@ -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) {
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) {
@ -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) {
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 };

View File

@ -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);
switch (op) {
case MP_UNARY_OP_BOOL:
return MP_BOOL(str_len != 0);
return mp_obj_new_bool(str_len != 0);
case MP_UNARY_OP_LEN:
return MP_OBJ_NEW_SMALL_INT(unichar_charlen((const char *)str_data, str_len));
default:

View File

@ -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_tuple_t *self = self_in;
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: {
// start hash with pointer to empty tuple, to make it fairly unique
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) {
case MP_BINARY_OP_LESS_EQUAL:
case MP_BINARY_OP_MORE:
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:
return MP_OBJ_NULL; // op not supported

View File

@ -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);
switch (op) {
case MP_UNARY_OP_BOOL:
return MP_BOOL(val != 0);
return mp_obj_new_bool(val != 0);
case MP_UNARY_OP_HASH:
return arg;
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) {
// deal with 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
@ -443,10 +443,10 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
return tuple;
}
case MP_BINARY_OP_LESS: return MP_BOOL(lhs_val < rhs_val); break;
case MP_BINARY_OP_MORE: return MP_BOOL(lhs_val > rhs_val); break;
case MP_BINARY_OP_LESS_EQUAL: return MP_BOOL(lhs_val <= rhs_val); break;
case MP_BINARY_OP_MORE_EQUAL: 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_obj_new_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_obj_new_bool(lhs_val >= rhs_val); break;
default:
goto unsupported_op;

View File

@ -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
/// the IRQ to its original state.
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);

View File

@ -512,7 +512,7 @@ STATIC mp_obj_t cc3k_disconnect(mp_obj_t self_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(cc3k_disconnect_obj, cc3k_disconnect);
STATIC mp_obj_t cc3k_isconnected(mp_obj_t self_in) {
return MP_BOOL(wlan_connected && ip_obtained);
return mp_obj_new_bool(wlan_connected && ip_obtained);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(cc3k_isconnected_obj, cc3k_isconnected);

View File

@ -305,7 +305,7 @@ STATIC mp_obj_t pin_debug(mp_uint_t n_args, const mp_obj_t *args) {
pin_class_debug = mp_obj_is_true(args[1]);
return mp_const_none;
}
return MP_BOOL(pin_class_debug);
return mp_obj_new_bool(pin_class_debug);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(pin_debug_fun_obj, 1, 2, pin_debug);
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(pin_debug_obj, (mp_obj_t)&pin_debug_fun_obj);

View File

@ -244,7 +244,7 @@ bool sdcard_write_blocks_dma(const uint8_t *src, uint32_t block_num, uint32_t nu
// consistent interface and methods to mount/unmount it.
STATIC mp_obj_t sd_present(mp_obj_t self) {
return MP_BOOL(sdcard_is_present());
return mp_obj_new_bool(sdcard_is_present());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(sd_present_obj, sd_present);
@ -256,7 +256,7 @@ STATIC mp_obj_t sd_power(mp_obj_t self, mp_obj_t state) {
sdcard_power_off();
result = true;
}
return MP_BOOL(result);
return mp_obj_new_bool(result);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_2(sd_power_obj, sd_power);

View File

@ -363,7 +363,7 @@ STATIC mp_obj_t pyb_usb_vcp_setinterrupt(mp_obj_t self_in, mp_obj_t int_chr_in)
STATIC MP_DEFINE_CONST_FUN_OBJ_2(pyb_usb_vcp_setinterrupt_obj, pyb_usb_vcp_setinterrupt);
STATIC mp_obj_t pyb_usb_vcp_isconnected(mp_obj_t self_in) {
return MP_BOOL(USBD_CDC_IsConnected());
return mp_obj_new_bool(USBD_CDC_IsConnected());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(pyb_usb_vcp_isconnected_obj, pyb_usb_vcp_isconnected);

View File

@ -248,7 +248,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_standby_obj, pyb_standby);
/// \function have_cdc()
/// Return True if USB is connected as a serial device, False otherwise.
STATIC mp_obj_t pyb_have_cdc(void ) {
return MP_BOOL(usb_vcp_is_connected());
return mp_obj_new_bool(usb_vcp_is_connected());
}
STATIC MP_DEFINE_CONST_FUN_OBJ_0(pyb_have_cdc_obj, pyb_have_cdc);

View File

@ -265,7 +265,7 @@ STATIC mp_obj_t jobject_unary_op(mp_uint_t op, mp_obj_t self_in) {
case MP_UNARY_OP_LEN: {
jint len = JJ(CallIntMethod, self->obj, List_size_mid);
if (op == MP_UNARY_OP_BOOL) {
return MP_BOOL(len != 0);
return mp_obj_new_bool(len != 0);
}
return MP_OBJ_NEW_SMALL_INT(len);
}