summaryrefslogtreecommitdiffstatshomepage
path: root/py/objlist.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-08 21:32:29 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-08 21:32:29 +0100
commitf4c9b33abf0ac6ff97cd39331d125a74fd2bb897 (patch)
tree64bdfb7d6d032d826640e1f9a43956b0b3947591 /py/objlist.c
parent4671392d90e98ea4edf6e9ce7023d21cc9957d8c (diff)
downloadmicropython-f4c9b33abf0ac6ff97cd39331d125a74fd2bb897.tar.gz
micropython-f4c9b33abf0ac6ff97cd39331d125a74fd2bb897.zip
py: Remove DELETE_SUBSCR opcode, combine with STORE_SUBSCR.
This makes the runtime and object APIs more consistent. mp_store_subscr functionality now moved into objects (ie list and dict store_item).
Diffstat (limited to 'py/objlist.c')
-rw-r--r--py/objlist.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/py/objlist.c b/py/objlist.c
index 371d1cb26e..a3b7e79abb 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -19,6 +19,7 @@ typedef struct _mp_obj_list_t {
STATIC mp_obj_t mp_obj_new_list_iterator(mp_obj_list_t *list, int cur);
STATIC mp_obj_list_t *list_new(uint n);
STATIC mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in);
+STATIC mp_obj_t list_pop(uint n_args, const mp_obj_t *args);
// TODO: Move to mpconfig.h
#define LIST_MIN_ALLOC 4
@@ -146,6 +147,16 @@ STATIC mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
}
}
+STATIC bool list_store_item(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
+ if (value == MP_OBJ_NULL) {
+ mp_obj_t args[2] = {self_in, index};
+ list_pop(2, args);
+ } else {
+ mp_obj_list_store(self_in, index, value);
+ }
+ return true;
+}
+
STATIC mp_obj_t list_getiter(mp_obj_t o_in) {
return mp_obj_new_list_iterator(o_in, 0);
}
@@ -349,6 +360,7 @@ const mp_obj_type_t mp_type_list = {
.make_new = list_make_new,
.unary_op = list_unary_op,
.binary_op = list_binary_op,
+ .store_item = list_store_item,
.getiter = list_getiter,
.locals_dict = (mp_obj_t)&list_locals_dict,
};