diff options
| author | Scott Shawcroft <scott.shawcroft@gmail.com> | 2017-10-24 22:31:16 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott.shawcroft@gmail.com> | 2017-10-24 22:31:16 -0700 |
| commit | 73c15dcf8b1b927757a595a867334b38355ddb8f (patch) | |
| tree | b1727518e47219b995611aa7e5c9da66e3df5075 /py/objlist.c | |
| parent | d43564f854a6a1202dfff550986b9343952d5d32 (diff) | |
| parent | f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c (diff) | |
Merge commit 'f869d6b2e339c04469c6c9ea3fb2fabd7bbb2d8c' into nrf2_merge
This is prep for merging in the NRF5 pull request.
Diffstat (limited to 'py/objlist.c')
| -rw-r--r-- | py/objlist.c | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/py/objlist.c b/py/objlist.c index 212240c76..c6e85f2c8 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -27,9 +27,7 @@ #include <string.h> #include <assert.h> -#include "py/nlr.h" #include "py/objlist.h" -#include "py/runtime0.h" #include "py/runtime.h" #include "py/stackctrl.h" @@ -87,19 +85,7 @@ STATIC mp_obj_t list_make_new(const mp_obj_type_t *type_in, size_t n_args, size_ } } -// Don't pass MP_BINARY_OP_NOT_EQUAL here -STATIC bool list_cmp_helper(mp_uint_t op, mp_obj_t self_in, mp_obj_t another_in) { - mp_check_self(MP_OBJ_IS_TYPE(self_in, &mp_type_list)); - if (!MP_OBJ_IS_TYPE(another_in, &mp_type_list)) { - return false; - } - mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in); - mp_obj_list_t *another = MP_OBJ_TO_PTR(another_in); - - return mp_seq_cmp_objs(op, self->items, self->len, another->items, another->len); -} - -STATIC mp_obj_t list_unary_op(mp_uint_t op, mp_obj_t self_in) { +STATIC mp_obj_t list_unary_op(mp_unary_op_t op, mp_obj_t self_in) { mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in); switch (op) { case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->len != 0); @@ -114,7 +100,7 @@ STATIC mp_obj_t list_unary_op(mp_uint_t op, mp_obj_t self_in) { } } -STATIC mp_obj_t list_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { +STATIC mp_obj_t list_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) { mp_obj_list_t *o = MP_OBJ_TO_PTR(lhs); switch (op) { case MP_BINARY_OP_ADD: { @@ -146,8 +132,18 @@ STATIC mp_obj_t list_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) { case MP_BINARY_OP_LESS: case MP_BINARY_OP_LESS_EQUAL: case MP_BINARY_OP_MORE: - case MP_BINARY_OP_MORE_EQUAL: - return mp_obj_new_bool(list_cmp_helper(op, lhs, rhs)); + case MP_BINARY_OP_MORE_EQUAL: { + if (!MP_OBJ_IS_TYPE(rhs, &mp_type_list)) { + if (op == MP_BINARY_OP_EQUAL) { + return mp_const_false; + } + return MP_OBJ_NULL; // op not supported + } + + mp_obj_list_t *another = MP_OBJ_TO_PTR(rhs); + bool res = mp_seq_cmp_objs(op, o->items, o->len, another->items, another->len); + return mp_obj_new_bool(res); + } default: return MP_OBJ_NULL; // op not supported |
