blob: c35fcbb0d8df8ec1f61e4d717625e32a2cc3b08d [file] [log] [blame]
Damien George04b91472014-05-03 23:27:38 +01001/*
2 * This file is part of the Micro Python project, http://micropython.org/
3 *
4 * The MIT License (MIT)
5 *
6 * Copyright (c) 2013, 2014 Damien P. George
Paul Sokolovskyda9f0922014-05-13 08:44:45 +03007 * Copyright (c) 2014 Paul Sokolovsky
Damien George04b91472014-05-03 23:27:38 +01008 *
9 * Permission is hereby granted, free of charge, to any person obtaining a copy
10 * of this software and associated documentation files (the "Software"), to deal
11 * in the Software without restriction, including without limitation the rights
12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 * copies of the Software, and to permit persons to whom the Software is
14 * furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included in
17 * all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 * THE SOFTWARE.
26 */
27
Paul Sokolovsky427905c2014-01-18 19:24:47 +020028#include <string.h>
Paul Sokolovsky427905c2014-01-18 19:24:47 +020029#include <assert.h>
30
Paul Sokolovskyf54bcbf2014-05-02 17:47:01 +030031#include "mpconfig.h"
Paul Sokolovsky427905c2014-01-18 19:24:47 +020032#include "nlr.h"
33#include "misc.h"
Damien George55baff42014-01-21 21:40:13 +000034#include "qstr.h"
Paul Sokolovsky427905c2014-01-18 19:24:47 +020035#include "obj.h"
Paul Sokolovsky427905c2014-01-18 19:24:47 +020036#include "runtime0.h"
37#include "runtime.h"
Paul Sokolovskyc2033242014-02-14 20:21:50 +020038#include "binary.h"
Paul Sokolovsky427905c2014-01-18 19:24:47 +020039
Paul Sokolovskycb78f862014-06-27 20:39:09 +030040#if MICROPY_PY_ARRAY || MICROPY_PY_BUILTINS_BYTEARRAY
41
Paul Sokolovsky427905c2014-01-18 19:24:47 +020042typedef struct _mp_obj_array_t {
43 mp_obj_base_t base;
Damien George40f3c022014-07-03 13:25:24 +010044 mp_uint_t typecode : 8;
Damien George51047752014-02-26 17:40:52 +000045 // free is number of unused elements after len used elements
46 // alloc size = len + free
Damien George40f3c022014-07-03 13:25:24 +010047 mp_uint_t free : (8 * sizeof(mp_uint_t) - 8);
48 mp_uint_t len; // in elements
Paul Sokolovsky427905c2014-01-18 19:24:47 +020049 void *items;
50} mp_obj_array_t;
51
Paul Sokolovskyd5df6cd2014-02-12 18:15:40 +020052STATIC mp_obj_t array_iterator_new(mp_obj_t array_in);
53STATIC mp_obj_array_t *array_new(char typecode, uint n);
54STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg);
Damien George4d917232014-08-30 14:28:06 +010055STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags);
Paul Sokolovsky427905c2014-01-18 19:24:47 +020056
57/******************************************************************************/
58/* array */
59
Paul Sokolovskyd5df6cd2014-02-12 18:15:40 +020060STATIC void array_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
Paul Sokolovsky427905c2014-01-18 19:24:47 +020061 mp_obj_array_t *o = o_in;
62 if (o->typecode == BYTEARRAY_TYPECODE) {
Damien George54671862014-07-17 21:56:32 +010063 print(env, "bytearray(b");
Paul Sokolovsky2ec38a12014-06-13 21:23:00 +030064 mp_str_print_quoted(print, env, o->items, o->len, true);
Paul Sokolovsky427905c2014-01-18 19:24:47 +020065 } else {
Paul Sokolovsky7e652af2014-01-28 03:14:20 +020066 print(env, "array('%c'", o->typecode);
Paul Sokolovsky18014212014-01-28 03:40:48 +020067 if (o->len > 0) {
Damien George32ca1642014-04-18 22:04:06 +010068 print(env, ", [");
Paul Sokolovsky18014212014-01-28 03:40:48 +020069 for (int i = 0; i < o->len; i++) {
70 if (i > 0) {
71 print(env, ", ");
72 }
Paul Sokolovskyef9124f2014-04-11 03:46:09 +030073 mp_obj_print_helper(print, env, mp_binary_get_val_array(o->typecode, o->items, i), PRINT_REPR);
Paul Sokolovsky7e652af2014-01-28 03:14:20 +020074 }
Paul Sokolovsky18014212014-01-28 03:40:48 +020075 print(env, "]");
Paul Sokolovsky427905c2014-01-18 19:24:47 +020076 }
Paul Sokolovsky427905c2014-01-18 19:24:47 +020077 }
Paul Sokolovsky7e652af2014-01-28 03:14:20 +020078 print(env, ")");
Paul Sokolovsky427905c2014-01-18 19:24:47 +020079}
80
Paul Sokolovskyd5df6cd2014-02-12 18:15:40 +020081STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
Paul Sokolovsky427905c2014-01-18 19:24:47 +020082 uint len;
83 // Try to create array of exact len if initializer len is known
84 mp_obj_t len_in = mp_obj_len_maybe(initializer);
85 if (len_in == MP_OBJ_NULL) {
86 len = 0;
87 } else {
88 len = MP_OBJ_SMALL_INT_VALUE(len_in);
89 }
90
91 mp_obj_array_t *array = array_new(typecode, len);
92
Damien Georged17926d2014-03-30 13:35:08 +010093 mp_obj_t iterable = mp_getiter(initializer);
Paul Sokolovsky427905c2014-01-18 19:24:47 +020094 mp_obj_t item;
95 int i = 0;
Damien Georgeea8d06c2014-04-17 23:19:36 +010096 while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
Paul Sokolovsky427905c2014-01-18 19:24:47 +020097 if (len == 0) {
98 array_append(array, item);
99 } else {
Paul Sokolovskyef9124f2014-04-11 03:46:09 +0300100 mp_binary_set_val_array(typecode, array->items, i++, item);
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200101 }
102 }
103
104 return array;
105}
106
Damien Georgeecc88e92014-08-30 00:35:11 +0100107STATIC mp_obj_t array_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
Damien Georgea3f94e02014-04-20 00:13:22 +0100108 mp_arg_check_num(n_args, n_kw, 1, 2, false);
Damien George32ca1642014-04-18 22:04:06 +0100109
110 // get typecode
Damien Georged182b982014-08-30 14:19:41 +0100111 mp_uint_t l;
Damien George698ec212014-02-08 18:17:23 +0000112 const char *typecode = mp_obj_str_get_data(args[0], &l);
Paul Sokolovsky11973b42014-01-28 02:31:52 +0200113
Damien George32ca1642014-04-18 22:04:06 +0100114 if (n_args == 1) {
115 // 1 arg: make an empty array
116 return array_new(*typecode, 0);
117 } else {
118 // 2 args: construct the array from the given iterator
119 return array_construct(*typecode, args[1]);
120 }
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200121}
122
Damien Georgeecc88e92014-08-30 00:35:11 +0100123STATIC mp_obj_t bytearray_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
Damien Georgea3f94e02014-04-20 00:13:22 +0100124 mp_arg_check_num(n_args, n_kw, 0, 1, false);
Paul Sokolovsky4dcb6052014-04-08 22:09:14 +0300125
Damien George32ca1642014-04-18 22:04:06 +0100126 if (n_args == 0) {
127 // no args: construct an empty bytearray
128 return array_new(BYTEARRAY_TYPECODE, 0);
129 } else if (MP_OBJ_IS_SMALL_INT(args[0])) {
130 // 1 arg, an integer: construct a blank bytearray of that length
Paul Sokolovsky4dcb6052014-04-08 22:09:14 +0300131 uint len = MP_OBJ_SMALL_INT_VALUE(args[0]);
Paul Sokolovskyb9cf3d32014-04-08 04:42:44 +0300132 mp_obj_array_t *o = array_new(BYTEARRAY_TYPECODE, len);
133 memset(o->items, 0, len);
134 return o;
Damien George32ca1642014-04-18 22:04:06 +0100135 } else {
136 // 1 arg, an iterator: construct the bytearray from that
137 return array_construct(BYTEARRAY_TYPECODE, args[0]);
Paul Sokolovskyb9cf3d32014-04-08 04:42:44 +0300138 }
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200139}
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200140
Damien Georgeecc88e92014-08-30 00:35:11 +0100141STATIC mp_obj_t array_unary_op(mp_uint_t op, mp_obj_t o_in) {
Paul Sokolovskyc1d9bbc2014-01-30 04:37:19 +0200142 mp_obj_array_t *o = o_in;
143 switch (op) {
Damien Georged17926d2014-03-30 13:35:08 +0100144 case MP_UNARY_OP_BOOL: return MP_BOOL(o->len != 0);
145 case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(o->len);
Damien George6ac5dce2014-05-21 19:42:43 +0100146 default: return MP_OBJ_NULL; // op not supported
Paul Sokolovskyc1d9bbc2014-01-30 04:37:19 +0200147 }
148}
149
Damien Georgeecc88e92014-08-30 00:35:11 +0100150STATIC mp_obj_t array_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
Paul Sokolovsky5f930332014-08-10 11:49:23 +0300151 switch (op) {
152 case MP_BINARY_OP_EQUAL: {
153 mp_buffer_info_t lhs_bufinfo;
154 mp_buffer_info_t rhs_bufinfo;
155 array_get_buffer(lhs_in, &lhs_bufinfo, MP_BUFFER_READ);
156 if (!mp_get_buffer(rhs_in, &rhs_bufinfo, MP_BUFFER_READ)) {
157 return mp_const_false;
158 }
159 return MP_BOOL(mp_seq_cmp_bytes(op, lhs_bufinfo.buf, lhs_bufinfo.len, rhs_bufinfo.buf, rhs_bufinfo.len));
160 }
161 default:
162 return MP_OBJ_NULL; // op not supported
163 }
164}
165
Paul Sokolovskyd5df6cd2014-02-12 18:15:40 +0200166STATIC mp_obj_t array_append(mp_obj_t self_in, mp_obj_t arg) {
Paul Sokolovsky4dcb6052014-04-08 22:09:14 +0300167 assert(MP_OBJ_IS_TYPE(self_in, &mp_type_array) || MP_OBJ_IS_TYPE(self_in, &mp_type_bytearray));
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200168 mp_obj_array_t *self = self_in;
169 if (self->free == 0) {
Paul Sokolovsky1355cf42014-04-19 01:25:49 +0300170 int item_sz = mp_binary_get_size('@', self->typecode, NULL);
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200171 // TODO: alloc policy
172 self->free = 8;
173 self->items = m_realloc(self->items, item_sz * self->len, item_sz * (self->len + self->free));
Paul Sokolovskya2240672014-04-28 00:16:57 +0300174 mp_seq_clear(self->items, self->len + 1, self->len + self->free, item_sz);
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200175 }
Paul Sokolovskyef9124f2014-04-11 03:46:09 +0300176 mp_binary_set_val_array(self->typecode, self->items, self->len++, arg);
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200177 self->free--;
178 return mp_const_none; // return None, as per CPython
179}
Paul Sokolovskyd5df6cd2014-02-12 18:15:40 +0200180STATIC MP_DEFINE_CONST_FUN_OBJ_2(array_append_obj, array_append);
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200181
Damien George729f7b42014-04-17 22:10:53 +0100182STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value) {
Damien Georgef4c9b332014-04-08 21:32:29 +0100183 if (value == MP_OBJ_NULL) {
Damien George32ca1642014-04-18 22:04:06 +0100184 // delete item
185 // TODO implement
Paul Sokolovsky26905252014-04-20 20:58:33 +0300186 // TODO: confirmed that both bytearray and array.array support
187 // slice deletion
Damien George6ac5dce2014-05-21 19:42:43 +0100188 return MP_OBJ_NULL; // op not supported
Damien George729f7b42014-04-17 22:10:53 +0100189 } else {
190 mp_obj_array_t *o = self_in;
Damien Georgec49ddb92014-06-01 13:49:35 +0100191 if (0) {
192#if MICROPY_PY_BUILTINS_SLICE
193 } else if (MP_OBJ_IS_TYPE(index_in, &mp_type_slice)) {
Paul Sokolovsky26905252014-04-20 20:58:33 +0300194 if (value != MP_OBJ_SENTINEL) {
195 // Only getting a slice is suported so far, not assignment
196 // TODO: confirmed that both bytearray and array.array support
197 // slice assignment (incl. of different size)
Damien George6ac5dce2014-05-21 19:42:43 +0100198 return MP_OBJ_NULL; // op not supported
Paul Sokolovsky26905252014-04-20 20:58:33 +0300199 }
Paul Sokolovskyde4b9322014-05-25 21:21:57 +0300200 mp_bound_slice_t slice;
201 if (!mp_seq_get_fast_slice_indexes(o->len, index_in, &slice)) {
Paul Sokolovsky5fd5af92014-05-25 22:12:56 +0300202 nlr_raise(mp_obj_new_exception_msg(&mp_type_NotImplementedError,
Damien George11de8392014-06-05 18:57:38 +0100203 "only slices with step=1 (aka None) are supported"));
Paul Sokolovskyd6e12722014-04-19 20:06:57 +0300204 }
Paul Sokolovskyde4b9322014-05-25 21:21:57 +0300205 mp_obj_array_t *res = array_new(o->typecode, slice.stop - slice.start);
Paul Sokolovskyd6e12722014-04-19 20:06:57 +0300206 int sz = mp_binary_get_size('@', o->typecode, NULL);
207 assert(sz > 0);
208 byte *p = o->items;
Paul Sokolovskyde4b9322014-05-25 21:21:57 +0300209 memcpy(res->items, p + slice.start * sz, (slice.stop - slice.start) * sz);
Paul Sokolovskyd6e12722014-04-19 20:06:57 +0300210 return res;
Damien Georgec49ddb92014-06-01 13:49:35 +0100211#endif
Damien George729f7b42014-04-17 22:10:53 +0100212 } else {
Paul Sokolovskyd6e12722014-04-19 20:06:57 +0300213 uint index = mp_get_index(o->base.type, o->len, index_in, false);
214 if (value == MP_OBJ_SENTINEL) {
215 // load
216 return mp_binary_get_val_array(o->typecode, o->items, index);
217 } else {
218 // store
219 mp_binary_set_val_array(o->typecode, o->items, index, value);
220 return mp_const_none;
221 }
Damien George729f7b42014-04-17 22:10:53 +0100222 }
Damien Georgef4c9b332014-04-08 21:32:29 +0100223 }
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200224}
225
Damien George4d917232014-08-30 14:28:06 +0100226STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200227 mp_obj_array_t *o = o_in;
228 bufinfo->buf = o->items;
Paul Sokolovsky1355cf42014-04-19 01:25:49 +0300229 bufinfo->len = o->len * mp_binary_get_size('@', o->typecode, NULL);
Damien George57a4b4f2014-04-18 22:29:21 +0100230 bufinfo->typecode = o->typecode;
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200231 return 0;
232}
233
Damien George9b196cd2014-03-26 21:47:19 +0000234STATIC const mp_map_elem_t array_locals_dict_table[] = {
235 { MP_OBJ_NEW_QSTR(MP_QSTR_append), (mp_obj_t)&array_append_obj },
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200236};
237
Damien George9b196cd2014-03-26 21:47:19 +0000238STATIC MP_DEFINE_CONST_DICT(array_locals_dict, array_locals_dict_table);
239
Damien Georgecaac5422014-03-25 14:18:18 +0000240const mp_obj_type_t mp_type_array = {
Damien Georgec5966122014-02-15 16:10:44 +0000241 { &mp_type_type },
Damien Georgea71c83a2014-02-15 11:34:50 +0000242 .name = MP_QSTR_array,
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200243 .print = array_print,
244 .make_new = array_make_new,
Paul Sokolovsky09ce0592014-01-21 23:45:19 +0200245 .getiter = array_iterator_new,
Paul Sokolovskyc1d9bbc2014-01-30 04:37:19 +0200246 .unary_op = array_unary_op,
Paul Sokolovsky5f930332014-08-10 11:49:23 +0300247 .binary_op = array_binary_op,
Damien George729f7b42014-04-17 22:10:53 +0100248 .subscr = array_subscr,
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200249 .buffer_p = { .get_buffer = array_get_buffer },
Damien George9b196cd2014-03-26 21:47:19 +0000250 .locals_dict = (mp_obj_t)&array_locals_dict,
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200251};
252
Paul Sokolovsky4dcb6052014-04-08 22:09:14 +0300253const mp_obj_type_t mp_type_bytearray = {
254 { &mp_type_type },
255 .name = MP_QSTR_bytearray,
256 .print = array_print,
257 .make_new = bytearray_make_new,
258 .getiter = array_iterator_new,
259 .unary_op = array_unary_op,
Paul Sokolovsky5f930332014-08-10 11:49:23 +0300260 .binary_op = array_binary_op,
Damien George729f7b42014-04-17 22:10:53 +0100261 .subscr = array_subscr,
Paul Sokolovsky4dcb6052014-04-08 22:09:14 +0300262 .buffer_p = { .get_buffer = array_get_buffer },
263 .locals_dict = (mp_obj_t)&array_locals_dict,
264};
265
Paul Sokolovskyd5df6cd2014-02-12 18:15:40 +0200266STATIC mp_obj_array_t *array_new(char typecode, uint n) {
Paul Sokolovsky1355cf42014-04-19 01:25:49 +0300267 int typecode_size = mp_binary_get_size('@', typecode, NULL);
Damien George32ca1642014-04-18 22:04:06 +0100268 if (typecode_size <= 0) {
269 nlr_raise(mp_obj_new_exception_msg(&mp_type_ValueError, "bad typecode"));
270 }
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200271 mp_obj_array_t *o = m_new_obj(mp_obj_array_t);
Paul Sokolovsky4dcb6052014-04-08 22:09:14 +0300272 o->base.type = (typecode == BYTEARRAY_TYPECODE) ? &mp_type_bytearray : &mp_type_array;
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200273 o->typecode = typecode;
274 o->free = 0;
275 o->len = n;
Damien George32ca1642014-04-18 22:04:06 +0100276 o->items = m_malloc(typecode_size * o->len);
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200277 return o;
278}
279
Damien Georged182b982014-08-30 14:19:41 +0100280mp_uint_t mp_obj_array_len(mp_obj_t self_in) {
Paul Sokolovsky33996682014-01-21 23:30:10 +0200281 return ((mp_obj_array_t *)self_in)->len;
282}
283
Paul Sokolovsky427905c2014-01-18 19:24:47 +0200284mp_obj_t mp_obj_new_bytearray(uint n, void *items) {
285 mp_obj_array_t *o = array_new(BYTEARRAY_TYPECODE, n);
286 memcpy(o->items, items, n);
287 return o;
288}
Paul Sokolovsky09ce0592014-01-21 23:45:19 +0200289
Paul Sokolovsky7f11c792014-01-29 00:21:41 +0200290// Create bytearray which references specified memory area
Damien Georged182b982014-08-30 14:19:41 +0100291mp_obj_t mp_obj_new_bytearray_by_ref(mp_uint_t n, void *items) {
Paul Sokolovsky7f11c792014-01-29 00:21:41 +0200292 mp_obj_array_t *o = m_new_obj(mp_obj_array_t);
Damien Georgecaac5422014-03-25 14:18:18 +0000293 o->base.type = &mp_type_array;
Paul Sokolovsky7f11c792014-01-29 00:21:41 +0200294 o->typecode = BYTEARRAY_TYPECODE;
295 o->free = 0;
296 o->len = n;
297 o->items = items;
298 return o;
299}
300
Paul Sokolovsky09ce0592014-01-21 23:45:19 +0200301/******************************************************************************/
302/* array iterator */
303
304typedef struct _mp_obj_array_it_t {
305 mp_obj_base_t base;
306 mp_obj_array_t *array;
Damien George40f3c022014-07-03 13:25:24 +0100307 mp_uint_t cur;
Paul Sokolovsky09ce0592014-01-21 23:45:19 +0200308} mp_obj_array_it_t;
309
Damien Georgecaac5422014-03-25 14:18:18 +0000310STATIC mp_obj_t array_it_iternext(mp_obj_t self_in) {
Paul Sokolovsky09ce0592014-01-21 23:45:19 +0200311 mp_obj_array_it_t *self = self_in;
312 if (self->cur < self->array->len) {
Paul Sokolovskyef9124f2014-04-11 03:46:09 +0300313 return mp_binary_get_val_array(self->array->typecode, self->array->items, self->cur++);
Paul Sokolovsky09ce0592014-01-21 23:45:19 +0200314 } else {
Damien Georgeea8d06c2014-04-17 23:19:36 +0100315 return MP_OBJ_STOP_ITERATION;
Paul Sokolovsky09ce0592014-01-21 23:45:19 +0200316 }
317}
318
Paul Sokolovskyd5df6cd2014-02-12 18:15:40 +0200319STATIC const mp_obj_type_t array_it_type = {
Damien Georgec5966122014-02-15 16:10:44 +0000320 { &mp_type_type },
Damien Georgea71c83a2014-02-15 11:34:50 +0000321 .name = MP_QSTR_iterator,
Paul Sokolovskyf7eaf602014-03-30 22:00:12 +0300322 .getiter = mp_identity,
Paul Sokolovsky09ce0592014-01-21 23:45:19 +0200323 .iternext = array_it_iternext,
324};
325
Damien Georgecaac5422014-03-25 14:18:18 +0000326STATIC mp_obj_t array_iterator_new(mp_obj_t array_in) {
Paul Sokolovsky09ce0592014-01-21 23:45:19 +0200327 mp_obj_array_t *array = array_in;
328 mp_obj_array_it_t *o = m_new_obj(mp_obj_array_it_t);
329 o->base.type = &array_it_type;
330 o->array = array;
331 o->cur = 0;
332 return o;
333}
Paul Sokolovskycb78f862014-06-27 20:39:09 +0300334
335#endif // MICROPY_PY_ARRAY || MICROPY_PY_BUILTINS_BYTEARRAY