diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-04-13 06:17:29 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-04-13 07:02:56 +0300 |
commit | 18bef25a0cd99029ebfaa92a29187c56ea96a835 (patch) | |
tree | 281ded10656b4947b0e8c8c373f2876ca1bb8634 /py | |
parent | f130ca1f60fbbca95516b722ce0119e5f3ca2767 (diff) | |
download | micropython-18bef25a0cd99029ebfaa92a29187c56ea96a835.tar.gz micropython-18bef25a0cd99029ebfaa92a29187c56ea96a835.zip |
objlist: Add support for statically allocated lists.
Similar to similar support for lists.
Diffstat (limited to 'py')
-rw-r--r-- | py/obj.h | 2 | ||||
-rw-r--r-- | py/objlist.c | 16 | ||||
-rw-r--r-- | py/objlist.h | 6 |
3 files changed, 15 insertions, 9 deletions
@@ -454,6 +454,8 @@ machine_int_t mp_obj_tuple_hash(mp_obj_t self_in); mp_obj_t mp_obj_tuple_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args); // list +struct _mp_obj_list_t; +void mp_obj_list_init(struct _mp_obj_list_t *o, uint n); mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg); void mp_obj_list_get(mp_obj_t self_in, uint *len, mp_obj_t **items); void mp_obj_list_set_len(mp_obj_t self_in, uint len); diff --git a/py/objlist.c b/py/objlist.c index 531e4b85bb..538cba71fd 100644 --- a/py/objlist.c +++ b/py/objlist.c @@ -8,13 +8,7 @@ #include "obj.h" #include "runtime0.h" #include "runtime.h" - -typedef struct _mp_obj_list_t { - mp_obj_base_t base; - machine_uint_t alloc; - machine_uint_t len; - mp_obj_t *items; -} mp_obj_list_t; +#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); @@ -363,12 +357,16 @@ const mp_obj_type_t mp_type_list = { .locals_dict = (mp_obj_t)&list_locals_dict, }; -STATIC mp_obj_list_t *list_new(uint n) { - mp_obj_list_t *o = m_new_obj(mp_obj_list_t); +void mp_obj_list_init(mp_obj_list_t *o, uint n) { o->base.type = &mp_type_list; o->alloc = n < LIST_MIN_ALLOC ? LIST_MIN_ALLOC : n; o->len = n; o->items = m_new(mp_obj_t, o->alloc); +} + +STATIC mp_obj_list_t *list_new(uint n) { + mp_obj_list_t *o = m_new_obj(mp_obj_list_t); + mp_obj_list_init(o, n); return o; } diff --git a/py/objlist.h b/py/objlist.h new file mode 100644 index 0000000000..cc8d7de26e --- /dev/null +++ b/py/objlist.h @@ -0,0 +1,6 @@ +typedef struct _mp_obj_list_t { + mp_obj_base_t base; + machine_uint_t alloc; + machine_uint_t len; + mp_obj_t *items; +} mp_obj_list_t; |