summaryrefslogtreecommitdiff
path: root/py/builtin.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-08-12 18:33:40 +0100
committerDamien George <damien.p.george@gmail.com>2014-08-12 18:33:40 +0100
commit4c03b3a899d49f0f4f2c54903403aaa9b384c315 (patch)
tree98a086456f0f5ce8a8108522f1e11c64697eda43 /py/builtin.c
parent69c5fe1df676fe5331d5ba9749d84016703e1a59 (diff)
py: Implement builtin reversed() function.
reversed function now implemented, and works for tuple, list, str, bytes and user objects with __len__ and __getitem__. Renamed mp_builtin_len to mp_obj_len to make it publically available (eg for reversed).
Diffstat (limited to 'py/builtin.c')
-rw-r--r--py/builtin.c14
1 files changed, 2 insertions, 12 deletions
diff --git a/py/builtin.c b/py/builtin.c
index 6a4ffdbd9..1924e6080 100644
--- a/py/builtin.c
+++ b/py/builtin.c
@@ -284,17 +284,6 @@ STATIC mp_obj_t mp_builtin_iter(mp_obj_t o_in) {
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_iter_obj, mp_builtin_iter);
-STATIC mp_obj_t mp_builtin_len(mp_obj_t o_in) {
- mp_obj_t len = mp_obj_len_maybe(o_in);
- if (len == MP_OBJ_NULL) {
- nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_TypeError, "object of type '%s' has no len()", mp_obj_get_type_str(o_in)));
- } else {
- return len;
- }
-}
-
-MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_len_obj, mp_builtin_len);
-
STATIC mp_obj_t mp_builtin_max(uint n_args, const mp_obj_t *args) {
if (n_args == 1) {
// given an iterable
@@ -569,6 +558,7 @@ STATIC mp_obj_t mp_builtin_hasattr(mp_obj_t object_in, mp_obj_t attr_in) {
MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_hasattr_obj, mp_builtin_hasattr);
-// These two are defined in terms of MicroPython API functions right away
+// These are defined in terms of MicroPython API functions right away
+MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_len_obj, mp_obj_len);
MP_DEFINE_CONST_FUN_OBJ_0(mp_builtin_globals_obj, mp_globals_get);
MP_DEFINE_CONST_FUN_OBJ_0(mp_builtin_locals_obj, mp_locals_get);