summaryrefslogtreecommitdiffstatshomepage
path: root/py/objlist.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-08-30 14:04:14 +0100
committerDamien George <damien.p.george@gmail.com>2014-08-30 14:04:14 +0100
commit9c4cbe2ac0ae4c51270f21ba9c974dd24f6b9d55 (patch)
treeff5df738435c6e6734a235aeb6d383457623dc6b /py/objlist.c
parent93965e726fb307739c31b0fc61d972391ffba677 (diff)
downloadmicropython-9c4cbe2ac0ae4c51270f21ba9c974dd24f6b9d55.tar.gz
micropython-9c4cbe2ac0ae4c51270f21ba9c974dd24f6b9d55.zip
py: Make tuple and list use mp_int_t/mp_uint_t.
Part of code cleanup, to resolve issue #50.
Diffstat (limited to 'py/objlist.c')
-rw-r--r--py/objlist.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/py/objlist.c b/py/objlist.c
index fb151f80ed..59390f371f 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -36,8 +36,8 @@
#include "runtime.h"
#include "objlist.h"
-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 mp_obj_new_list_iterator(mp_obj_list_t *list, mp_uint_t cur);
+STATIC mp_obj_list_t *list_new(mp_uint_t n);
STATIC mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in);
STATIC mp_obj_t list_pop(mp_uint_t n_args, const mp_obj_t *args);
@@ -50,7 +50,7 @@ STATIC mp_obj_t list_pop(mp_uint_t n_args, const mp_obj_t *args);
STATIC void list_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
mp_obj_list_t *o = o_in;
print(env, "[");
- for (int i = 0; i < o->len; i++) {
+ for (mp_uint_t i = 0; i < o->len; i++) {
if (i > 0) {
print(env, ", ");
}
@@ -188,7 +188,7 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
return res;
}
#endif
- uint index_val = mp_get_index(self->base.type, self->len, index, false);
+ mp_uint_t index_val = mp_get_index(self->base.type, self->len, index, false);
return self->items[index_val];
} else {
#if MICROPY_PY_BUILTINS_SLICE
@@ -271,7 +271,7 @@ STATIC mp_obj_t list_pop(mp_uint_t n_args, const mp_obj_t *args) {
if (self->len == 0) {
nlr_raise(mp_obj_new_exception_msg(&mp_type_IndexError, "pop from empty list"));
}
- uint index = mp_get_index(self->base.type, self->len, n_args == 1 ? MP_OBJ_NEW_SMALL_INT(-1) : args[1], false);
+ mp_uint_t index = mp_get_index(self->base.type, self->len, n_args == 1 ? MP_OBJ_NEW_SMALL_INT(-1) : args[1], false);
mp_obj_t ret = self->items[index];
self->len -= 1;
memmove(self->items + index, self->items + index + 1, (self->len - index) * sizeof(mp_obj_t));
@@ -286,7 +286,7 @@ STATIC mp_obj_t list_pop(mp_uint_t n_args, const mp_obj_t *args) {
// TODO make this conform to CPython's definition of sort
STATIC void mp_quicksort(mp_obj_t *head, mp_obj_t *tail, mp_obj_t key_fn, bool reversed) {
- int op = reversed ? MP_BINARY_OP_MORE : MP_BINARY_OP_LESS;
+ mp_uint_t op = reversed ? MP_BINARY_OP_MORE : MP_BINARY_OP_LESS;
while (head < tail) {
mp_obj_t *h = head - 1;
mp_obj_t *t = tail;
@@ -442,7 +442,7 @@ const mp_obj_type_t mp_type_list = {
.locals_dict = (mp_obj_t)&list_locals_dict,
};
-void mp_obj_list_init(mp_obj_list_t *o, uint n) {
+void mp_obj_list_init(mp_obj_list_t *o, mp_uint_t n) {
o->base.type = &mp_type_list;
o->alloc = n < LIST_MIN_ALLOC ? LIST_MIN_ALLOC : n;
o->len = n;
@@ -450,29 +450,29 @@ void mp_obj_list_init(mp_obj_list_t *o, uint n) {
mp_seq_clear(o->items, n, o->alloc, sizeof(*o->items));
}
-STATIC mp_obj_list_t *list_new(uint n) {
+STATIC mp_obj_list_t *list_new(mp_uint_t n) {
mp_obj_list_t *o = m_new_obj(mp_obj_list_t);
mp_obj_list_init(o, n);
return o;
}
-mp_obj_t mp_obj_new_list(uint n, mp_obj_t *items) {
+mp_obj_t mp_obj_new_list(mp_uint_t n, mp_obj_t *items) {
mp_obj_list_t *o = list_new(n);
if (items != NULL) {
- for (int i = 0; i < n; i++) {
+ for (mp_uint_t i = 0; i < n; i++) {
o->items[i] = items[i];
}
}
return o;
}
-void mp_obj_list_get(mp_obj_t self_in, uint *len, mp_obj_t **items) {
+void mp_obj_list_get(mp_obj_t self_in, mp_uint_t *len, mp_obj_t **items) {
mp_obj_list_t *self = self_in;
*len = self->len;
*items = self->items;
}
-void mp_obj_list_set_len(mp_obj_t self_in, uint len) {
+void mp_obj_list_set_len(mp_obj_t self_in, mp_uint_t len) {
// trust that the caller knows what it's doing
// TODO realloc if len got much smaller than alloc
mp_obj_list_t *self = self_in;
@@ -481,7 +481,7 @@ void mp_obj_list_set_len(mp_obj_t self_in, uint len) {
void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
mp_obj_list_t *self = self_in;
- uint i = mp_get_index(self->base.type, self->len, index, false);
+ mp_uint_t i = mp_get_index(self->base.type, self->len, index, false);
self->items[i] = value;
}
@@ -512,7 +512,7 @@ STATIC const mp_obj_type_t mp_type_list_it = {
.iternext = list_it_iternext,
};
-mp_obj_t mp_obj_new_list_iterator(mp_obj_list_t *list, int cur) {
+mp_obj_t mp_obj_new_list_iterator(mp_obj_list_t *list, mp_uint_t cur) {
mp_obj_list_it_t *o = m_new_obj(mp_obj_list_it_t);
o->base.type = &mp_type_list_it;
o->list = list;