From eae16445d5f6ca4bcd693422fc93ccf4fd7e215e Mon Sep 17 00:00:00 2001 From: Damien George Date: Sat, 11 Jan 2014 19:22:29 +0000 Subject: py: Implement staticmethod and classmethod (internally). Still need to make built-ins by these names, and write tests. --- py/obj.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'py/obj.c') diff --git a/py/obj.c b/py/obj.c index dfb450fb8d..81b5c69f7a 100644 --- a/py/obj.c +++ b/py/obj.c @@ -231,7 +231,7 @@ uint mp_get_index(const mp_obj_type_t *type, machine_uint_t len, mp_obj_t index) } } -// may return NULL +// may return MP_OBJ_NULL mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) { mp_small_int_t len = 0; if (MP_OBJ_IS_TYPE(o_in, &str_type)) { @@ -249,7 +249,7 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) { } else if (MP_OBJ_IS_TYPE(o_in, &dict_type)) { len = mp_obj_dict_len(o_in); } else { - return NULL; + return MP_OBJ_NULL; } return MP_OBJ_NEW_SMALL_INT(len); } -- cgit v1.2.3 From cc57bd2663fb742770a56f205488dbb2c757fb8f Mon Sep 17 00:00:00 2001 From: Paul Sokolovsky Date: Sun, 12 Jan 2014 01:55:50 +0200 Subject: mp_obj_equal(): For non-trivial types, call out to type's special method. --- py/obj.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'py/obj.c') diff --git a/py/obj.c b/py/obj.c index 81b5c69f7a..2759437fd7 100644 --- a/py/obj.c +++ b/py/obj.c @@ -117,6 +117,13 @@ bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2) { } else if (MP_OBJ_IS_TYPE(o1, &str_type) && MP_OBJ_IS_TYPE(o2, &str_type)) { return mp_obj_str_get(o1) == mp_obj_str_get(o2); } else { + mp_obj_base_t *o = o1; + if (o->type->binary_op != NULL) { + mp_obj_t r = o->type->binary_op(RT_COMPARE_OP_EQUAL, o1, o2); + if (r != MP_OBJ_NULL) { + return r == mp_const_true ? true : false; + } + } // TODO: Debugging helper printf("Equality for '%s' and '%s' types not yet implemented\n", mp_obj_get_type_str(o1), mp_obj_get_type_str(o2)); assert(0); -- cgit v1.2.3