Numworks Epsilon  1.4.1
Graphing Calculator Operating System
objlist.c
Go to the documentation of this file.
1 /*
2  * This file is part of the MicroPython project, http://micropython.org/
3  *
4  * The MIT License (MIT)
5  *
6  * Copyright (c) 2013, 2014 Damien P. George
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a copy
9  * of this software and associated documentation files (the "Software"), to deal
10  * in the Software without restriction, including without limitation the rights
11  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12  * copies of the Software, and to permit persons to whom the Software is
13  * furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
18  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24  * THE SOFTWARE.
25  */
26 
27 #include <string.h>
28 #include <assert.h>
29 
30 #include "py/objlist.h"
31 #include "py/runtime.h"
32 #include "py/stackctrl.h"
33 
35 STATIC mp_obj_list_t *list_new(size_t n);
37 STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args);
38 
39 // TODO: Move to mpconfig.h
40 #define LIST_MIN_ALLOC 4
41 
42 /******************************************************************************/
43 /* list */
44 
45 STATIC void list_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
46  mp_obj_list_t *o = MP_OBJ_TO_PTR(o_in);
47  if (!(MICROPY_PY_UJSON && kind == PRINT_JSON)) {
48  kind = PRINT_REPR;
49  }
50  mp_print_str(print, "[");
51  for (size_t i = 0; i < o->len; i++) {
52  if (i > 0) {
53  mp_print_str(print, ", ");
54  }
55  mp_obj_print_helper(print, o->items[i], kind);
56  }
57  mp_print_str(print, "]");
58 }
59 
61  mp_obj_t iter = mp_getiter(iterable, NULL);
62  mp_obj_t item;
63  while ((item = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) {
64  mp_obj_list_append(list, item);
65  }
66  return list;
67 }
68 
69 STATIC mp_obj_t list_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
70  (void)type_in;
71  mp_arg_check_num(n_args, n_kw, 0, 1, false);
72 
73  switch (n_args) {
74  case 0:
75  // return a new, empty list
76  return mp_obj_new_list(0, NULL);
77 
78  case 1:
79  default: {
80  // make list from iterable
81  // TODO: optimize list/tuple
83  return list_extend_from_iter(list, args[0]);
84  }
85  }
86 }
87 
89  mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
90  switch (op) {
91  case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->len != 0);
92  case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->len);
93  #if MICROPY_PY_SYS_GETSIZEOF
94  case MP_UNARY_OP_SIZEOF: {
95  size_t sz = sizeof(*self) + sizeof(mp_obj_t) * self->alloc;
96  return MP_OBJ_NEW_SMALL_INT(sz);
97  }
98  #endif
99  default: return MP_OBJ_NULL; // op not supported
100  }
101 }
102 
104  mp_obj_list_t *o = MP_OBJ_TO_PTR(lhs);
105  switch (op) {
106  case MP_BINARY_OP_ADD: {
107  if (!MP_OBJ_IS_TYPE(rhs, &mp_type_list)) {
108  return MP_OBJ_NULL; // op not supported
109  }
110  mp_obj_list_t *p = MP_OBJ_TO_PTR(rhs);
111  mp_obj_list_t *s = list_new(o->len + p->len);
112  mp_seq_cat(s->items, o->items, o->len, p->items, p->len, mp_obj_t);
113  return MP_OBJ_FROM_PTR(s);
114  }
116  list_extend(lhs, rhs);
117  return lhs;
118  }
119  case MP_BINARY_OP_MULTIPLY: {
120  mp_int_t n;
121  if (!mp_obj_get_int_maybe(rhs, &n)) {
122  return MP_OBJ_NULL; // op not supported
123  }
124  if (n < 0) {
125  n = 0;
126  }
127  mp_obj_list_t *s = list_new(o->len * n);
128  mp_seq_multiply(o->items, sizeof(*o->items), o->len, n, s->items);
129  return MP_OBJ_FROM_PTR(s);
130  }
131  case MP_BINARY_OP_EQUAL:
132  case MP_BINARY_OP_LESS:
134  case MP_BINARY_OP_MORE:
136  if (!MP_OBJ_IS_TYPE(rhs, &mp_type_list)) {
137  if (op == MP_BINARY_OP_EQUAL) {
138  return mp_const_false;
139  }
140  return MP_OBJ_NULL; // op not supported
141  }
142 
143  mp_obj_list_t *another = MP_OBJ_TO_PTR(rhs);
144  bool res = mp_seq_cmp_objs(op, o->items, o->len, another->items, another->len);
145  return mp_obj_new_bool(res);
146  }
147 
148  default:
149  return MP_OBJ_NULL; // op not supported
150  }
151 }
152 
154  if (value == MP_OBJ_NULL) {
155  // delete
156 #if MICROPY_PY_BUILTINS_SLICE
157  if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
158  mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
159  mp_bound_slice_t slice;
160  if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice)) {
162  }
163 
164  mp_int_t len_adj = slice.start - slice.stop;
165  //printf("Len adj: %d\n", len_adj);
166  assert(len_adj <= 0);
167  mp_seq_replace_slice_no_grow(self->items, self->len, slice.start, slice.stop, self->items/*NULL*/, 0, sizeof(*self->items));
168  // Clear "freed" elements at the end of list
169  mp_seq_clear(self->items, self->len + len_adj, self->len, sizeof(*self->items));
170  self->len += len_adj;
171  return mp_const_none;
172  }
173 #endif
174  mp_obj_t args[2] = {self_in, index};
175  list_pop(2, args);
176  return mp_const_none;
177  } else if (value == MP_OBJ_SENTINEL) {
178  // load
179  mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
180 #if MICROPY_PY_BUILTINS_SLICE
181  if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
182  mp_bound_slice_t slice;
183  if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice)) {
184  return mp_seq_extract_slice(self->len, self->items, &slice);
185  }
186  mp_obj_list_t *res = list_new(slice.stop - slice.start);
187  mp_seq_copy(res->items, self->items + slice.start, res->len, mp_obj_t);
188  return MP_OBJ_FROM_PTR(res);
189  }
190 #endif
191  size_t index_val = mp_get_index(self->base.type, self->len, index, false);
192  return self->items[index_val];
193  } else {
194 #if MICROPY_PY_BUILTINS_SLICE
195  if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
196  mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
197  size_t value_len; mp_obj_t *value_items;
198  mp_obj_get_array(value, &value_len, &value_items);
199  mp_bound_slice_t slice_out;
200  if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice_out)) {
202  }
203  mp_int_t len_adj = value_len - (slice_out.stop - slice_out.start);
204  //printf("Len adj: %d\n", len_adj);
205  if (len_adj > 0) {
206  if (self->len + len_adj > self->alloc) {
207  // TODO: Might optimize memory copies here by checking if block can
208  // be grown inplace or not
209  self->items = m_renew(mp_obj_t, self->items, self->alloc, self->len + len_adj);
210  self->alloc = self->len + len_adj;
211  }
212  mp_seq_replace_slice_grow_inplace(self->items, self->len,
213  slice_out.start, slice_out.stop, value_items, value_len, len_adj, sizeof(*self->items));
214  } else {
215  mp_seq_replace_slice_no_grow(self->items, self->len,
216  slice_out.start, slice_out.stop, value_items, value_len, sizeof(*self->items));
217  // Clear "freed" elements at the end of list
218  mp_seq_clear(self->items, self->len + len_adj, self->len, sizeof(*self->items));
219  // TODO: apply allocation policy re: alloc_size
220  }
221  self->len += len_adj;
222  return mp_const_none;
223  }
224 #endif
225  mp_obj_list_store(self_in, index, value);
226  return mp_const_none;
227  }
228 }
229 
231  return mp_obj_new_list_iterator(o_in, 0, iter_buf);
232 }
233 
236  mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
237  if (self->len >= self->alloc) {
238  self->items = m_renew(mp_obj_t, self->items, self->alloc, self->alloc * 2);
239  self->alloc *= 2;
240  mp_seq_clear(self->items, self->len + 1, self->alloc, sizeof(*self->items));
241  }
242  self->items[self->len++] = arg;
243  return mp_const_none; // return None, as per CPython
244 }
245 
248  if (MP_OBJ_IS_TYPE(arg_in, &mp_type_list)) {
249  mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
250  mp_obj_list_t *arg = MP_OBJ_TO_PTR(arg_in);
251 
252  if (self->len + arg->len > self->alloc) {
253  // TODO: use alloc policy for "4"
254  self->items = m_renew(mp_obj_t, self->items, self->alloc, self->len + arg->len + 4);
255  self->alloc = self->len + arg->len + 4;
256  mp_seq_clear(self->items, self->len + arg->len, self->alloc, sizeof(*self->items));
257  }
258 
259  memcpy(self->items + self->len, arg->items, sizeof(mp_obj_t) * arg->len);
260  self->len += arg->len;
261  } else {
262  list_extend_from_iter(self_in, arg_in);
263  }
264  return mp_const_none; // return None, as per CPython
265 }
266 
267 STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args) {
269  mp_obj_list_t *self = MP_OBJ_TO_PTR(args[0]);
270  if (self->len == 0) {
271  mp_raise_msg(&mp_type_IndexError, "pop from empty list");
272  }
273  size_t index = mp_get_index(self->base.type, self->len, n_args == 1 ? MP_OBJ_NEW_SMALL_INT(-1) : args[1], false);
274  mp_obj_t ret = self->items[index];
275  self->len -= 1;
276  memmove(self->items + index, self->items + index + 1, (self->len - index) * sizeof(mp_obj_t));
277  // Clear stale pointer from slot which just got freed to prevent GC issues
278  self->items[self->len] = MP_OBJ_NULL;
279  if (self->alloc > LIST_MIN_ALLOC && self->alloc > 2 * self->len) {
280  self->items = m_renew(mp_obj_t, self->items, self->alloc, self->alloc/2);
281  self->alloc /= 2;
282  }
283  return ret;
284 }
285 
286 STATIC void mp_quicksort(mp_obj_t *head, mp_obj_t *tail, mp_obj_t key_fn, mp_obj_t binop_less_result) {
287  MP_STACK_CHECK();
288  while (head < tail) {
289  mp_obj_t *h = head - 1;
290  mp_obj_t *t = tail;
291  mp_obj_t v = key_fn == MP_OBJ_NULL ? tail[0] : mp_call_function_1(key_fn, tail[0]); // get pivot using key_fn
292  for (;;) {
293  do ++h; while (h < t && mp_binary_op(MP_BINARY_OP_LESS, key_fn == MP_OBJ_NULL ? h[0] : mp_call_function_1(key_fn, h[0]), v) == binop_less_result);
294  do --t; while (h < t && mp_binary_op(MP_BINARY_OP_LESS, v, key_fn == MP_OBJ_NULL ? t[0] : mp_call_function_1(key_fn, t[0])) == binop_less_result);
295  if (h >= t) break;
296  mp_obj_t x = h[0];
297  h[0] = t[0];
298  t[0] = x;
299  }
300  mp_obj_t x = h[0];
301  h[0] = tail[0];
302  tail[0] = x;
303  // do the smaller recursive call first, to keep stack within O(log(N))
304  if (t - head < tail - h - 1) {
305  mp_quicksort(head, t, key_fn, binop_less_result);
306  head = h + 1;
307  } else {
308  mp_quicksort(h + 1, tail, key_fn, binop_less_result);
309  tail = t;
310  }
311  }
312 }
313 
314 // TODO Python defines sort to be stable but ours is not
315 mp_obj_t mp_obj_list_sort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args) {
316  static const mp_arg_t allowed_args[] = {
317  { MP_QSTR_key, MP_ARG_KW_ONLY | MP_ARG_OBJ, {.u_rom_obj = MP_ROM_PTR(&mp_const_none_obj)} },
318  { MP_QSTR_reverse, MP_ARG_KW_ONLY | MP_ARG_BOOL, {.u_bool = false} },
319  };
320 
321  // parse args
322  struct {
323  mp_arg_val_t key, reverse;
324  } args;
325  mp_arg_parse_all(n_args - 1, pos_args + 1, kw_args,
326  MP_ARRAY_SIZE(allowed_args), allowed_args, (mp_arg_val_t*)&args);
327 
328  mp_check_self(MP_OBJ_IS_TYPE(pos_args[0], &mp_type_list));
329  mp_obj_list_t *self = MP_OBJ_TO_PTR(pos_args[0]);
330 
331  if (self->len > 1) {
332  mp_quicksort(self->items, self->items + self->len - 1,
333  args.key.u_obj == mp_const_none ? MP_OBJ_NULL : args.key.u_obj,
334  args.reverse.u_bool ? mp_const_false : mp_const_true);
335  }
336 
337  return mp_const_none;
338 }
339 
342  mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
343  self->len = 0;
344  self->items = m_renew(mp_obj_t, self->items, self->alloc, LIST_MIN_ALLOC);
345  self->alloc = LIST_MIN_ALLOC;
346  mp_seq_clear(self->items, 0, self->alloc, sizeof(*self->items));
347  return mp_const_none;
348 }
349 
352  mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
353  return mp_obj_new_list(self->len, self->items);
354 }
355 
358  mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
359  return mp_seq_count_obj(self->items, self->len, value);
360 }
361 
362 STATIC mp_obj_t list_index(size_t n_args, const mp_obj_t *args) {
364  mp_obj_list_t *self = MP_OBJ_TO_PTR(args[0]);
365  return mp_seq_index_obj(self->items, self->len, n_args, args);
366 }
367 
370  mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
371  // insert has its own strange index logic
372  mp_int_t index = MP_OBJ_SMALL_INT_VALUE(idx);
373  if (index < 0) {
374  index += self->len;
375  }
376  if (index < 0) {
377  index = 0;
378  }
379  if ((size_t)index > self->len) {
380  index = self->len;
381  }
382 
384 
385  for (mp_int_t i = self->len-1; i > index; i--) {
386  self->items[i] = self->items[i-1];
387  }
388  self->items[index] = obj;
389 
390  return mp_const_none;
391 }
392 
395  mp_obj_t args[] = {self_in, value};
396  args[1] = list_index(2, args);
397  list_pop(2, args);
398 
399  return mp_const_none;
400 }
401 
404  mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
405 
406  mp_int_t len = self->len;
407  for (mp_int_t i = 0; i < len/2; i++) {
408  mp_obj_t a = self->items[i];
409  self->items[i] = self->items[len-i-1];
410  self->items[len-i-1] = a;
411  }
412 
413  return mp_const_none;
414 }
415 
427 
429  { MP_ROM_QSTR(MP_QSTR_append), MP_ROM_PTR(&list_append_obj) },
430  { MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&list_clear_obj) },
431  { MP_ROM_QSTR(MP_QSTR_copy), MP_ROM_PTR(&list_copy_obj) },
432  { MP_ROM_QSTR(MP_QSTR_count), MP_ROM_PTR(&list_count_obj) },
433  { MP_ROM_QSTR(MP_QSTR_extend), MP_ROM_PTR(&list_extend_obj) },
434  { MP_ROM_QSTR(MP_QSTR_index), MP_ROM_PTR(&list_index_obj) },
435  { MP_ROM_QSTR(MP_QSTR_insert), MP_ROM_PTR(&list_insert_obj) },
436  { MP_ROM_QSTR(MP_QSTR_pop), MP_ROM_PTR(&list_pop_obj) },
437  { MP_ROM_QSTR(MP_QSTR_remove), MP_ROM_PTR(&list_remove_obj) },
438  { MP_ROM_QSTR(MP_QSTR_reverse), MP_ROM_PTR(&list_reverse_obj) },
439  { MP_ROM_QSTR(MP_QSTR_sort), MP_ROM_PTR(&list_sort_obj) },
440 };
441 
443 
445  { &mp_type_type },
446  .name = MP_QSTR_list,
447  .print = list_print,
448  .make_new = list_make_new,
449  .unary_op = list_unary_op,
450  .binary_op = list_binary_op,
451  .subscr = list_subscr,
452  .getiter = list_getiter,
453  .locals_dict = (mp_obj_dict_t*)&list_locals_dict,
454 };
455 
456 void mp_obj_list_init(mp_obj_list_t *o, size_t n) {
457  o->base.type = &mp_type_list;
458  o->alloc = n < LIST_MIN_ALLOC ? LIST_MIN_ALLOC : n;
459  o->len = n;
460  o->items = m_new(mp_obj_t, o->alloc);
461  mp_seq_clear(o->items, n, o->alloc, sizeof(*o->items));
462 }
463 
466  mp_obj_list_init(o, n);
467  return o;
468 }
469 
470 mp_obj_t mp_obj_new_list(size_t n, mp_obj_t *items) {
471  mp_obj_list_t *o = list_new(n);
472  if (items != NULL) {
473  for (size_t i = 0; i < n; i++) {
474  o->items[i] = items[i];
475  }
476  }
477  return MP_OBJ_FROM_PTR(o);
478 }
479 
480 void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items) {
481  mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
482  *len = self->len;
483  *items = self->items;
484 }
485 
486 void mp_obj_list_set_len(mp_obj_t self_in, size_t len) {
487  // trust that the caller knows what it's doing
488  // TODO realloc if len got much smaller than alloc
489  mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
490  self->len = len;
491 }
492 
493 void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
494  mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
495  size_t i = mp_get_index(self->base.type, self->len, index, false);
496  self->items[i] = value;
497 }
498 
499 /******************************************************************************/
500 /* list iterator */
501 
502 typedef struct _mp_obj_list_it_t {
506  size_t cur;
508 
510  mp_obj_list_it_t *self = MP_OBJ_TO_PTR(self_in);
511  mp_obj_list_t *list = MP_OBJ_TO_PTR(self->list);
512  if (self->cur < list->len) {
513  mp_obj_t o_out = list->items[self->cur];
514  self->cur += 1;
515  return o_out;
516  } else {
517  return MP_OBJ_STOP_ITERATION;
518  }
519 }
520 
522  assert(sizeof(mp_obj_list_it_t) <= sizeof(mp_obj_iter_buf_t));
523  mp_obj_list_it_t *o = (mp_obj_list_it_t*)iter_buf;
524  o->base.type = &mp_type_polymorph_iter;
526  o->list = list;
527  o->cur = cur;
528  return MP_OBJ_FROM_PTR(o);
529 }
STATIC const mp_rom_map_elem_t list_locals_dict_table[]
Definition: objlist.c:428
mp_obj_base_t base
Definition: objlist.h:32
intptr_t mp_int_t
Definition: mpconfigport.h:73
STATIC MP_DEFINE_CONST_FUN_OBJ_3(list_insert_obj, list_insert)
#define mp_seq_clear(start, len, alloc_len, item_sz)
Definition: obj.h:856
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg)
Definition: runtime.c:1448
STATIC void mp_quicksort(mp_obj_t *head, mp_obj_t *tail, mp_obj_t key_fn, mp_obj_t binop_less_result)
Definition: objlist.c:286
mp_uint_t stop
Definition: obj.h:840
#define assert(e)
Definition: assert.h:9
#define mp_const_none
Definition: obj.h:614
NORETURN void mp_raise_NotImplementedError(const char *msg)
Definition: runtime.c:1468
mp_obj_t mp_obj_list_remove(mp_obj_t self_in, mp_obj_t value)
Definition: objlist.c:393
STATIC mp_obj_t list_unary_op(mp_unary_op_t op, mp_obj_t self_in)
Definition: objlist.c:88
const mp_obj_type_t mp_type_list
Definition: objlist.c:444
size_t len
Definition: objlist.h:34
#define MP_OBJ_IS_TYPE(o, t)
Definition: obj.h:254
STATIC mp_obj_t list_index(size_t n_args, const mp_obj_t *args)
Definition: objlist.c:362
#define MP_OBJ_SENTINEL
Definition: obj.h:75
int mp_print_str(const mp_print_t *print, const char *str)
Definition: mpprint.c:53
#define MP_ROM_QSTR(q)
Definition: obj.h:241
#define MP_OBJ_FROM_PTR(p)
Definition: obj.h:233
void mp_arg_parse_all(size_t n_pos, const mp_obj_t *pos, mp_map_t *kws, size_t n_allowed, const mp_arg_t *allowed, mp_arg_val_t *out_vals)
Definition: argcheck.c:74
void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_args_max, bool takes_kw)
Definition: argcheck.c:32
#define MP_ROM_PTR(p)
Definition: obj.h:242
#define mp_const_true
Definition: obj.h:616
STATIC void list_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind)
Definition: objlist.c:45
STATIC mp_obj_t list_count(mp_obj_t self_in, mp_obj_t value)
Definition: objlist.c:356
#define MP_ARRAY_SIZE(a)
Definition: misc.h:106
mp_obj_t mp_obj_new_list(size_t n, mp_obj_t *items)
Definition: objlist.c:470
void mp_obj_list_init(mp_obj_list_t *o, size_t n)
Definition: objlist.c:456
mp_unary_op_t
Definition: runtime0.h:45
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, size_t len, mp_obj_t value)
Definition: sequence.c:266
STATIC mp_obj_t list_extend(mp_obj_t self_in, mp_obj_t arg_in)
Definition: objlist.c:246
#define STATIC
Definition: mpconfig.h:1178
#define MP_OBJ_SMALL_INT_VALUE(o)
Definition: obj.h:86
mp_fun_1_t iternext
Definition: objlist.c:504
mp_obj_t list
Definition: objlist.c:505
mp_obj_t(* mp_fun_1_t)(mp_obj_t)
Definition: obj.h:404
STATIC mp_obj_t list_reverse(mp_obj_t self_in)
Definition: objlist.c:402
void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items)
Definition: obj.c:346
size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool is_slice)
Definition: obj.c:376
#define MICROPY_PY_UJSON
Definition: mpconfig.h:1055
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(list_index_obj, 2, 4, list_index)
mp_print_kind_t
Definition: obj.h:412
#define MP_OBJ_NEW_SMALL_INT(small_int)
Definition: obj.h:87
mp_obj_t mp_call_function_1(mp_obj_t fun, mp_obj_t arg)
Definition: runtime.c:603
const mp_obj_type_t mp_type_polymorph_iter
Definition: objpolyiter.c:48
void mp_obj_list_set_len(mp_obj_t self_in, size_t len)
Definition: objlist.c:486
#define NULL
Definition: stddef.h:4
#define MP_OBJ_NULL
Definition: obj.h:73
#define mp_check_self(pred)
Definition: runtime.h:161
bool mp_seq_cmp_objs(mp_uint_t op, const mp_obj_t *items1, size_t len1, const mp_obj_t *items2, size_t len2)
Definition: sequence.c:194
mp_obj_t * items
Definition: objlist.h:35
size_t alloc
Definition: objlist.h:33
mp_obj_t mp_obj_list_sort(size_t n_args, const mp_obj_t *pos_args, mp_map_t *kw_args)
Definition: objlist.c:315
void * memmove(void *dst, const void *src, size_t n)
Definition: memmove.c:3
void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind)
Definition: obj.c:59
STATIC mp_obj_t list_extend_from_iter(mp_obj_t list, mp_obj_t iterable)
Definition: objlist.c:60
mp_binary_op_t
Definition: runtime0.h:67
mp_obj_t mp_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs)
Definition: runtime.c:277
STATIC mp_obj_list_t * list_new(size_t n)
Definition: objlist.c:464
const struct _mp_obj_none_t mp_const_none_obj
Definition: objnone.c:51
STATIC mp_obj_t list_it_iternext(mp_obj_t self_in)
Definition: objlist.c:509
void mp_seq_multiply(const void *items, size_t item_sz, size_t len, size_t times, void *dest)
Definition: sequence.c:38
args
Definition: i18n.py:175
#define mp_seq_replace_slice_no_grow(dest, dest_len, beg, end, slice, slice_len, item_sz)
Definition: obj.h:857
list
Definition: grammar.h:158
Definition: obj.h:356
STATIC mp_obj_t list_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf)
Definition: objlist.c:230
bool mp_obj_get_int_maybe(mp_const_obj_t arg, mp_int_t *value)
Definition: obj.c:258
const mp_obj_type_t mp_type_type
Definition: objtype.c:969
STATIC mp_obj_t mp_obj_new_list_iterator(mp_obj_t list, size_t cur, mp_obj_iter_buf_t *iter_buf)
Definition: objlist.c:521
#define m_renew(type, ptr, old_num, new_num)
Definition: misc.h:75
const mp_obj_type_t mp_type_IndexError
STATIC mp_obj_t list_copy(mp_obj_t self_in)
Definition: objlist.c:350
STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value)
Definition: objlist.c:153
#define mp_seq_copy(dest, src, len, item_t)
Definition: obj.h:848
STATIC mp_obj_t list_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: objlist.c:69
STATIC MP_DEFINE_CONST_FUN_OBJ_1(list_clear_obj, list_clear)
const mp_obj_type_t mp_type_slice
#define MP_OBJ_TO_PTR(o)
Definition: obj.h:228
#define mp_seq_replace_slice_grow_inplace(dest, dest_len, beg, end, slice, slice_len, len_adj, item_sz)
Definition: obj.h:864
mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg)
Definition: objlist.c:234
STATIC mp_obj_t list_pop(size_t n_args, const mp_obj_t *args)
Definition: objlist.c:267
mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf)
Definition: runtime.c:1120
mp_uint_t start
Definition: obj.h:839
#define MP_STACK_CHECK()
Definition: stackctrl.h:44
qstr name
Definition: obj.h:478
STATIC MP_DEFINE_CONST_DICT(list_locals_dict, list_locals_dict_table)
#define MP_OBJ_STOP_ITERATION
Definition: obj.h:74
mp_obj_base_t base
Definition: objlist.c:503
#define LIST_MIN_ALLOC
Definition: objlist.c:40
uint64_t mp_obj_t
Definition: obj.h:39
mp_obj_t mp_iternext(mp_obj_t o_in)
Definition: runtime.c:1186
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(list_sort_obj, 1, mp_obj_list_sort)
mp_obj_t mp_seq_index_obj(const mp_obj_t *items, size_t len, size_t n_args, const mp_obj_t *args)
Definition: sequence.c:243
void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items)
Definition: objlist.c:480
#define m_new_obj(type)
Definition: misc.h:60
mp_obj_t mp_seq_extract_slice(size_t len, const mp_obj_t *seq, mp_bound_slice_t *indexes)
Definition: sequence.c:126
STATIC mp_obj_t list_clear(mp_obj_t self_in)
Definition: objlist.c:340
STATIC mp_obj_t list_insert(mp_obj_t self_in, mp_obj_t idx, mp_obj_t obj)
Definition: objlist.c:368
STATIC mp_obj_t list_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs)
Definition: objlist.c:103
void * memcpy(void *dst, const void *src, size_t n)
Definition: memcpy.c:3
struct _mp_obj_list_it_t mp_obj_list_it_t
#define m_new(type, num)
Definition: misc.h:57
void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value)
Definition: objlist.c:493
#define mp_const_false
Definition: obj.h:615
STATIC MP_DEFINE_CONST_FUN_OBJ_2(list_append_obj, mp_obj_list_append)
#define mp_seq_cat(dest, src1, len1, src2, len2, item_t)
Definition: obj.h:849