blob: bc363d38fdb5cc21597ed031d1f90d47c44993d5 [file] [log] [blame]
Damiend99b0522013-12-21 18:17:45 +00001#include <stdlib.h>
2#include <stdint.h>
3#include <string.h>
4#include <assert.h>
5
6#include "nlr.h"
7#include "misc.h"
8#include "mpconfig.h"
Damien George55baff42014-01-21 21:40:13 +00009#include "qstr.h"
Damiend99b0522013-12-21 18:17:45 +000010#include "obj.h"
John R. Lentonc06763a2014-01-07 17:29:16 +000011#include "map.h"
Damiend99b0522013-12-21 18:17:45 +000012#include "runtime0.h"
13#include "runtime.h"
14
15typedef struct _mp_obj_list_t {
16 mp_obj_base_t base;
17 machine_uint_t alloc;
18 machine_uint_t len;
19 mp_obj_t *items;
20} mp_obj_list_t;
21
22static mp_obj_t mp_obj_new_list_iterator(mp_obj_list_t *list, int cur);
John R. Lenton4cb80582014-01-03 02:27:08 +000023static mp_obj_list_t *list_new(uint n);
Paul Sokolovskyc698d262014-01-12 00:51:05 +020024static mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in);
Damiend99b0522013-12-21 18:17:45 +000025
26/******************************************************************************/
27/* list */
28
Paul Sokolovsky76d982e2014-01-13 19:19:16 +020029static void list_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
Damiend99b0522013-12-21 18:17:45 +000030 mp_obj_list_t *o = o_in;
31 print(env, "[");
32 for (int i = 0; i < o->len; i++) {
33 if (i > 0) {
34 print(env, ", ");
35 }
Paul Sokolovsky76d982e2014-01-13 19:19:16 +020036 mp_obj_print_helper(print, env, o->items[i], PRINT_REPR);
Damiend99b0522013-12-21 18:17:45 +000037 }
38 print(env, "]");
39}
40
Damien George20006db2014-01-18 14:10:48 +000041static mp_obj_t list_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) {
42 // TODO check n_kw == 0
43
Damien George71c51812014-01-04 20:21:15 +000044 switch (n_args) {
45 case 0:
46 // return a new, empty list
Damien Georgeebde0b82014-01-19 00:47:40 +000047 return mp_obj_new_list(0, NULL);
Damien George71c51812014-01-04 20:21:15 +000048
49 case 1:
50 {
51 // make list from iterable
52 mp_obj_t iterable = rt_getiter(args[0]);
Damien Georgeebde0b82014-01-19 00:47:40 +000053 mp_obj_t list = mp_obj_new_list(0, NULL);
Damien George71c51812014-01-04 20:21:15 +000054 mp_obj_t item;
55 while ((item = rt_iternext(iterable)) != mp_const_stop_iteration) {
Damien Georgeebde0b82014-01-19 00:47:40 +000056 mp_obj_list_append(list, item);
Damien George71c51812014-01-04 20:21:15 +000057 }
58 return list;
59 }
60
61 default:
62 nlr_jump(mp_obj_new_exception_msg_1_arg(MP_QSTR_TypeError, "list takes at most 1 argument, %d given", (void*)(machine_int_t)n_args));
63 }
ian-v5fd8fd22014-01-06 13:51:53 -080064 return NULL;
Damien George71c51812014-01-04 20:21:15 +000065}
66
Paul Sokolovsky1945e602014-01-12 02:01:00 +020067// Don't pass RT_COMPARE_OP_NOT_EQUAL here
68static bool list_cmp_helper(int op, mp_obj_t self_in, mp_obj_t another_in) {
69 assert(MP_OBJ_IS_TYPE(self_in, &list_type));
70 if (!MP_OBJ_IS_TYPE(another_in, &list_type)) {
71 return false;
72 }
73 mp_obj_list_t *self = self_in;
74 mp_obj_list_t *another = another_in;
75 if (op == RT_COMPARE_OP_EQUAL && self->len != another->len) {
76 return false;
77 }
78
79 // Let's deal only with > & >=
80 if (op == RT_COMPARE_OP_LESS || op == RT_COMPARE_OP_LESS_EQUAL) {
81 mp_obj_t t = self;
82 self = another;
83 another = t;
84 if (op == RT_COMPARE_OP_LESS) {
85 op = RT_COMPARE_OP_MORE;
86 } else {
87 op = RT_COMPARE_OP_MORE_EQUAL;
88 }
89 }
90
91 int len = self->len < another->len ? self->len : another->len;
92 bool eq_status = true; // empty lists are equal
93 bool rel_status;
94 for (int i = 0; i < len; i++) {
95 eq_status = mp_obj_equal(self->items[i], another->items[i]);
96 if (op == RT_COMPARE_OP_EQUAL && !eq_status) {
97 return false;
98 }
99 rel_status = (rt_binary_op(op, self->items[i], another->items[i]) == mp_const_true);
100 if (!eq_status && !rel_status) {
101 return false;
102 }
103 }
104
105 // If we had tie in the last element...
106 if (eq_status) {
107 // ... and we have lists of different lengths...
108 if (self->len != another->len) {
109 if (self->len < another->len) {
110 // ... then longer list length wins (we deal only with >)
111 return false;
112 }
113 } else if (op == RT_COMPARE_OP_MORE) {
114 // Otherwise, if we have strict relation, equality means failure
115 return false;
116 }
117 }
118
119 return true;
120}
121
Damiend99b0522013-12-21 18:17:45 +0000122static mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
123 mp_obj_list_t *o = lhs;
124 switch (op) {
125 case RT_BINARY_OP_SUBSCR:
126 {
127 // list load
128 uint index = mp_get_index(o->base.type, o->len, rhs);
129 return o->items[index];
130 }
John R. Lenton4cb80582014-01-03 02:27:08 +0000131 case RT_BINARY_OP_ADD:
132 {
John R. Lenton81ad89c2014-01-03 02:32:40 +0000133 if (!MP_OBJ_IS_TYPE(rhs, &list_type)) {
134 return NULL;
135 }
136 mp_obj_list_t *p = rhs;
137 mp_obj_list_t *s = list_new(o->len + p->len);
John R. Lenton9bc56d92014-01-03 10:13:38 +0000138 memcpy(s->items, o->items, sizeof(mp_obj_t) * o->len);
139 memcpy(s->items + o->len, p->items, sizeof(mp_obj_t) * p->len);
John R. Lenton81ad89c2014-01-03 02:32:40 +0000140 return s;
John R. Lenton4cb80582014-01-03 02:27:08 +0000141 }
Paul Sokolovskyc698d262014-01-12 00:51:05 +0200142 case RT_BINARY_OP_INPLACE_ADD:
143 {
144 if (!MP_OBJ_IS_TYPE(rhs, &list_type)) {
145 return NULL;
146 }
147 list_extend(lhs, rhs);
148 return o;
149 }
Paul Sokolovsky074d3b52014-01-10 18:12:25 +0200150 case RT_BINARY_OP_MULTIPLY:
151 {
152 if (!MP_OBJ_IS_SMALL_INT(rhs)) {
153 return NULL;
154 }
155 int n = MP_OBJ_SMALL_INT_VALUE(rhs);
156 int len = o->len;
157 mp_obj_list_t *s = list_new(len * n);
158 mp_obj_t *dest = s->items;
159 for (int i = 0; i < n; i++) {
160 memcpy(dest, o->items, sizeof(mp_obj_t) * len);
161 dest += len;
162 }
163 return s;
164 }
Paul Sokolovsky1945e602014-01-12 02:01:00 +0200165 case RT_COMPARE_OP_EQUAL:
166 case RT_COMPARE_OP_LESS:
167 case RT_COMPARE_OP_LESS_EQUAL:
168 case RT_COMPARE_OP_MORE:
169 case RT_COMPARE_OP_MORE_EQUAL:
170 return MP_BOOL(list_cmp_helper(op, lhs, rhs));
171 case RT_COMPARE_OP_NOT_EQUAL:
172 return MP_BOOL(!list_cmp_helper(RT_COMPARE_OP_EQUAL, lhs, rhs));
173
Damiend99b0522013-12-21 18:17:45 +0000174 default:
175 // op not supported
176 return NULL;
177 }
178}
179
180static mp_obj_t list_getiter(mp_obj_t o_in) {
181 return mp_obj_new_list_iterator(o_in, 0);
182}
183
184mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg) {
185 assert(MP_OBJ_IS_TYPE(self_in, &list_type));
186 mp_obj_list_t *self = self_in;
187 if (self->len >= self->alloc) {
Damien732407f2013-12-29 19:33:23 +0000188 self->items = m_renew(mp_obj_t, self->items, self->alloc, self->alloc * 2);
Damiend99b0522013-12-21 18:17:45 +0000189 self->alloc *= 2;
Damiend99b0522013-12-21 18:17:45 +0000190 }
191 self->items[self->len++] = arg;
192 return mp_const_none; // return None, as per CPython
193}
194
Paul Sokolovskyc698d262014-01-12 00:51:05 +0200195static mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in) {
196 assert(MP_OBJ_IS_TYPE(self_in, &list_type));
197 assert(MP_OBJ_IS_TYPE(arg_in, &list_type));
198 mp_obj_list_t *self = self_in;
199 mp_obj_list_t *arg = arg_in;
200
201 if (self->len + arg->len > self->alloc) {
202 // TODO: use alloc policy for "4"
203 self->items = m_renew(mp_obj_t, self->items, self->alloc, self->len + arg->len + 4);
204 self->alloc = self->len + arg->len + 4;
205 }
206
207 memcpy(self->items + self->len, arg->items, sizeof(mp_obj_t) * arg->len);
208 self->len += arg->len;
209 return mp_const_none; // return None, as per CPython
210}
211
Damien Georgea11ceca2014-01-19 16:02:09 +0000212static mp_obj_t list_pop(uint n_args, const mp_obj_t *args) {
John R. Lenton25f417c2014-01-03 22:53:18 +0000213 assert(1 <= n_args && n_args <= 2);
214 assert(MP_OBJ_IS_TYPE(args[0], &list_type));
215 mp_obj_list_t *self = args[0];
216 if (self->len == 0) {
Damien Georgeeb7bfcb2014-01-04 15:57:35 +0000217 nlr_jump(mp_obj_new_exception_msg(MP_QSTR_IndexError, "pop from empty list"));
John R. Lenton25f417c2014-01-03 22:53:18 +0000218 }
219 uint index = mp_get_index(self->base.type, self->len, n_args == 1 ? mp_obj_new_int(-1) : args[1]);
Damiend99b0522013-12-21 18:17:45 +0000220 mp_obj_t ret = self->items[index];
221 self->len -= 1;
222 memcpy(self->items + index, self->items + index + 1, (self->len - index) * sizeof(mp_obj_t));
John R. Lenton25f417c2014-01-03 22:53:18 +0000223 if (self->alloc > 2 * self->len) {
224 self->items = m_renew(mp_obj_t, self->items, self->alloc, self->alloc/2);
225 self->alloc /= 2;
226 }
Damiend99b0522013-12-21 18:17:45 +0000227 return ret;
228}
229
230// TODO make this conform to CPython's definition of sort
John R. Lentonc06763a2014-01-07 17:29:16 +0000231static void mp_quicksort(mp_obj_t *head, mp_obj_t *tail, mp_obj_t key_fn, bool reversed) {
232 int op = reversed ? RT_COMPARE_OP_MORE : RT_COMPARE_OP_LESS;
Damiend99b0522013-12-21 18:17:45 +0000233 while (head < tail) {
234 mp_obj_t *h = head - 1;
235 mp_obj_t *t = tail;
John R. Lentonc06763a2014-01-07 17:29:16 +0000236 mp_obj_t v = key_fn == NULL ? tail[0] : rt_call_function_1(key_fn, tail[0]); // get pivot using key_fn
Damiend99b0522013-12-21 18:17:45 +0000237 for (;;) {
John R. Lentonb8698fc2014-01-11 00:58:59 +0000238 do ++h; while (rt_binary_op(op, key_fn == NULL ? h[0] : rt_call_function_1(key_fn, h[0]), v) == mp_const_true);
239 do --t; while (h < t && rt_binary_op(op, v, key_fn == NULL ? t[0] : rt_call_function_1(key_fn, t[0])) == mp_const_true);
Damiend99b0522013-12-21 18:17:45 +0000240 if (h >= t) break;
241 mp_obj_t x = h[0];
242 h[0] = t[0];
243 t[0] = x;
244 }
245 mp_obj_t x = h[0];
246 h[0] = tail[0];
247 tail[0] = x;
John R. Lentonc06763a2014-01-07 17:29:16 +0000248 mp_quicksort(head, t, key_fn, reversed);
Damiend99b0522013-12-21 18:17:45 +0000249 head = h + 1;
250 }
251}
252
Damien George20006db2014-01-18 14:10:48 +0000253mp_obj_t mp_obj_list_sort(uint n_args, const mp_obj_t *args, mp_map_t *kwargs) {
254 assert(n_args >= 1);
255 assert(MP_OBJ_IS_TYPE(args[0], &list_type));
256 if (n_args > 1) {
John R. Lentonc06763a2014-01-07 17:29:16 +0000257 nlr_jump(mp_obj_new_exception_msg(MP_QSTR_TypeError,
258 "list.sort takes no positional arguments"));
259 }
Damien George20006db2014-01-18 14:10:48 +0000260 mp_obj_list_t *self = args[0];
Damiend99b0522013-12-21 18:17:45 +0000261 if (self->len > 1) {
Damien George55baff42014-01-21 21:40:13 +0000262 mp_map_elem_t *keyfun = mp_map_lookup(kwargs, MP_OBJ_NEW_QSTR(QSTR_FROM_STR_STATIC("key")), MP_MAP_LOOKUP);
263 mp_map_elem_t *reverse = mp_map_lookup(kwargs, MP_OBJ_NEW_QSTR(QSTR_FROM_STR_STATIC("reverse")), MP_MAP_LOOKUP);
John R. Lentonc06763a2014-01-07 17:29:16 +0000264 mp_quicksort(self->items, self->items + self->len - 1,
265 keyfun ? keyfun->value : NULL,
266 reverse && reverse->value ? rt_is_true(reverse->value) : false);
Damiend99b0522013-12-21 18:17:45 +0000267 }
268 return mp_const_none; // return None, as per CPython
269}
270
John R. Lenton069ded92014-01-03 23:22:53 +0000271static mp_obj_t list_clear(mp_obj_t self_in) {
272 assert(MP_OBJ_IS_TYPE(self_in, &list_type));
273 mp_obj_list_t *self = self_in;
274 self->len = 0;
275 self->items = m_renew(mp_obj_t, self->items, self->alloc, 4);
276 self->alloc = 4;
277 return mp_const_none;
278}
279
John R. Lenton26c21162014-01-03 23:42:17 +0000280static mp_obj_t list_copy(mp_obj_t self_in) {
281 assert(MP_OBJ_IS_TYPE(self_in, &list_type));
282 mp_obj_list_t *self = self_in;
283 return mp_obj_new_list(self->len, self->items);
284}
285
John R. Lentone241e8c2014-01-03 23:57:28 +0000286static mp_obj_t list_count(mp_obj_t self_in, mp_obj_t value) {
287 assert(MP_OBJ_IS_TYPE(self_in, &list_type));
288 mp_obj_list_t *self = self_in;
289 int count = 0;
290 for (int i = 0; i < self->len; i++) {
291 if (mp_obj_equal(self->items[i], value)) {
292 count++;
293 }
294 }
295
296 return mp_obj_new_int(count);
297}
298
Damien Georgea11ceca2014-01-19 16:02:09 +0000299static mp_obj_t list_index(uint n_args, const mp_obj_t *args) {
John R. Lenton5d4a8212014-01-04 00:26:30 +0000300 assert(2 <= n_args && n_args <= 4);
301 assert(MP_OBJ_IS_TYPE(args[0], &list_type));
302 mp_obj_list_t *self = args[0];
303 mp_obj_t *value = args[1];
John R. Lentonc5531622014-01-05 21:57:27 +0000304 uint start = 0;
305 uint stop = self->len;
John R. Lenton5d4a8212014-01-04 00:26:30 +0000306
John R. Lentonc5531622014-01-05 21:57:27 +0000307 if (n_args >= 3) {
308 start = mp_get_index(self->base.type, self->len, args[2]);
309 if (n_args >= 4) {
310 stop = mp_get_index(self->base.type, self->len, args[3]);
311 }
312 }
John R. Lenton5d4a8212014-01-04 00:26:30 +0000313
John R. Lentonc5531622014-01-05 21:57:27 +0000314 for (uint i = start; i < stop; i++) {
John R. Lenton5d4a8212014-01-04 00:26:30 +0000315 if (mp_obj_equal(self->items[i], value)) {
316 return mp_obj_new_int(i);
317 }
318 }
319
Damien Georgef0691f42014-01-05 13:44:06 +0000320 nlr_jump(mp_obj_new_exception_msg(MP_QSTR_ValueError, "object not in list"));
John R. Lenton5d4a8212014-01-04 00:26:30 +0000321}
322
John R. Lenton45a87442014-01-04 01:15:01 +0000323static mp_obj_t list_insert(mp_obj_t self_in, mp_obj_t idx, mp_obj_t obj) {
324 assert(MP_OBJ_IS_TYPE(self_in, &list_type));
325 mp_obj_list_t *self = self_in;
326 // insert has its own strange index logic
327 int index = MP_OBJ_SMALL_INT_VALUE(idx);
328 if (index < 0) {
329 index += self->len;
330 }
331 if (index < 0) {
332 index = 0;
333 }
334 if (index > self->len) {
335 index = self->len;
336 }
337
338 mp_obj_list_append(self_in, mp_const_none);
339
340 for (int i = self->len-1; i > index; i--) {
341 self->items[i] = self->items[i-1];
342 }
343 self->items[index] = obj;
344
345 return mp_const_none;
346}
347
John R. Lenton49fb6e52014-01-04 01:56:53 +0000348static mp_obj_t list_remove(mp_obj_t self_in, mp_obj_t value) {
349 assert(MP_OBJ_IS_TYPE(self_in, &list_type));
350 mp_obj_t args[] = {self_in, value};
351 args[1] = list_index(2, args);
352 list_pop(2, args);
353
354 return mp_const_none;
355}
356
John R. Lenton6e1e98f2014-01-04 02:10:29 +0000357static mp_obj_t list_reverse(mp_obj_t self_in) {
358 assert(MP_OBJ_IS_TYPE(self_in, &list_type));
359 mp_obj_list_t *self = self_in;
360
361 int len = self->len;
362 for (int i = 0; i < len/2; i++) {
363 mp_obj_t *a = self->items[i];
364 self->items[i] = self->items[len-i-1];
365 self->items[len-i-1] = a;
366 }
367
368 return mp_const_none;
369}
370
Damiend99b0522013-12-21 18:17:45 +0000371static MP_DEFINE_CONST_FUN_OBJ_2(list_append_obj, mp_obj_list_append);
Paul Sokolovskyc698d262014-01-12 00:51:05 +0200372static MP_DEFINE_CONST_FUN_OBJ_2(list_extend_obj, list_extend);
John R. Lenton069ded92014-01-03 23:22:53 +0000373static MP_DEFINE_CONST_FUN_OBJ_1(list_clear_obj, list_clear);
John R. Lenton26c21162014-01-03 23:42:17 +0000374static MP_DEFINE_CONST_FUN_OBJ_1(list_copy_obj, list_copy);
John R. Lentone241e8c2014-01-03 23:57:28 +0000375static MP_DEFINE_CONST_FUN_OBJ_2(list_count_obj, list_count);
John R. Lenton5d4a8212014-01-04 00:26:30 +0000376static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(list_index_obj, 2, 4, list_index);
John R. Lenton45a87442014-01-04 01:15:01 +0000377static MP_DEFINE_CONST_FUN_OBJ_3(list_insert_obj, list_insert);
John R. Lenton25f417c2014-01-03 22:53:18 +0000378static MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(list_pop_obj, 1, 2, list_pop);
John R. Lenton49fb6e52014-01-04 01:56:53 +0000379static MP_DEFINE_CONST_FUN_OBJ_2(list_remove_obj, list_remove);
John R. Lenton6e1e98f2014-01-04 02:10:29 +0000380static MP_DEFINE_CONST_FUN_OBJ_1(list_reverse_obj, list_reverse);
Damien George0f592032014-01-14 23:18:35 +0000381static MP_DEFINE_CONST_FUN_OBJ_KW(list_sort_obj, 0, mp_obj_list_sort);
Damiend99b0522013-12-21 18:17:45 +0000382
ian-va5a01df2014-01-06 14:14:11 -0800383static const mp_method_t list_type_methods[] = {
ian-v7a16fad2014-01-06 09:52:29 -0800384 { "append", &list_append_obj },
385 { "clear", &list_clear_obj },
386 { "copy", &list_copy_obj },
387 { "count", &list_count_obj },
Paul Sokolovskyc698d262014-01-12 00:51:05 +0200388 { "extend", &list_extend_obj },
ian-v7a16fad2014-01-06 09:52:29 -0800389 { "index", &list_index_obj },
ian-v5fd8fd22014-01-06 13:51:53 -0800390 { "insert", &list_insert_obj },
ian-v7a16fad2014-01-06 09:52:29 -0800391 { "pop", &list_pop_obj },
392 { "remove", &list_remove_obj },
393 { "reverse", &list_reverse_obj },
394 { "sort", &list_sort_obj },
395 { NULL, NULL }, // end-of-list sentinel
396};
Damien George97209d32014-01-07 15:58:30 +0000397
Damiend99b0522013-12-21 18:17:45 +0000398const mp_obj_type_t list_type = {
John R. Lenton3391e192014-01-07 18:06:34 +0000399 { &mp_const_type },
400 "list",
Paul Sokolovsky860ffb02014-01-05 22:34:09 +0200401 .print = list_print,
402 .make_new = list_make_new,
Paul Sokolovsky860ffb02014-01-05 22:34:09 +0200403 .binary_op = list_binary_op,
404 .getiter = list_getiter,
ian-v7a16fad2014-01-06 09:52:29 -0800405 .methods = list_type_methods,
Damiend99b0522013-12-21 18:17:45 +0000406};
407
408static mp_obj_list_t *list_new(uint n) {
409 mp_obj_list_t *o = m_new_obj(mp_obj_list_t);
410 o->base.type = &list_type;
411 o->alloc = n < 4 ? 4 : n;
412 o->len = n;
413 o->items = m_new(mp_obj_t, o->alloc);
414 return o;
415}
416
417mp_obj_t mp_obj_new_list(uint n, mp_obj_t *items) {
418 mp_obj_list_t *o = list_new(n);
419 for (int i = 0; i < n; i++) {
420 o->items[i] = items[i];
421 }
422 return o;
423}
424
Damiend99b0522013-12-21 18:17:45 +0000425void mp_obj_list_get(mp_obj_t self_in, uint *len, mp_obj_t **items) {
426 mp_obj_list_t *self = self_in;
427 *len = self->len;
428 *items = self->items;
429}
430
431void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
432 mp_obj_list_t *self = self_in;
433 uint i = mp_get_index(self->base.type, self->len, index);
434 self->items[i] = value;
435}
436
437/******************************************************************************/
438/* list iterator */
439
440typedef struct _mp_obj_list_it_t {
441 mp_obj_base_t base;
442 mp_obj_list_t *list;
443 machine_uint_t cur;
444} mp_obj_list_it_t;
445
446mp_obj_t list_it_iternext(mp_obj_t self_in) {
447 mp_obj_list_it_t *self = self_in;
448 if (self->cur < self->list->len) {
449 mp_obj_t o_out = self->list->items[self->cur];
450 self->cur += 1;
451 return o_out;
452 } else {
453 return mp_const_stop_iteration;
454 }
455}
456
457static const mp_obj_type_t list_it_type = {
John R. Lenton3391e192014-01-07 18:06:34 +0000458 { &mp_const_type },
459 "list_iterator",
Paul Sokolovsky860ffb02014-01-05 22:34:09 +0200460 .iternext = list_it_iternext,
Damiend99b0522013-12-21 18:17:45 +0000461};
462
463mp_obj_t mp_obj_new_list_iterator(mp_obj_list_t *list, int cur) {
464 mp_obj_list_it_t *o = m_new_obj(mp_obj_list_it_t);
465 o->base.type = &list_it_type;
466 o->list = list;
467 o->cur = cur;
468 return o;
469}