Numworks Epsilon  1.4.1
Graphing Calculator Operating System
objdict.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/runtime.h"
31 #include "py/builtin.h"
32 #include "py/objtype.h"
33 
34 #define MP_OBJ_IS_DICT_TYPE(o) (MP_OBJ_IS_OBJ(o) && ((mp_obj_base_t*)MP_OBJ_TO_PTR(o))->type->make_new == dict_make_new)
35 
36 STATIC mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs);
37 
38 // This is a helper function to iterate through a dictionary. The state of
39 // the iteration is held in *cur and should be initialised with zero for the
40 // first call. Will return NULL when no more elements are available.
42  size_t max = dict->map.alloc;
43  mp_map_t *map = &dict->map;
44 
45  for (size_t i = *cur; i < max; i++) {
46  if (MP_MAP_SLOT_IS_FILLED(map, i)) {
47  *cur = i + 1;
48  return &(map->table[i]);
49  }
50  }
51 
52  return NULL;
53 }
54 
55 STATIC void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
56  mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in);
57  bool first = true;
58  if (!(MICROPY_PY_UJSON && kind == PRINT_JSON)) {
59  kind = PRINT_REPR;
60  }
61  if (MICROPY_PY_COLLECTIONS_ORDEREDDICT && self->base.type != &mp_type_dict) {
62  mp_printf(print, "%q(", self->base.type->name);
63  }
64  mp_print_str(print, "{");
65  size_t cur = 0;
66  mp_map_elem_t *next = NULL;
67  while ((next = dict_iter_next(self, &cur)) != NULL) {
68  if (!first) {
69  mp_print_str(print, ", ");
70  }
71  first = false;
72  mp_obj_print_helper(print, next->key, kind);
73  mp_print_str(print, ": ");
74  mp_obj_print_helper(print, next->value, kind);
75  }
76  mp_print_str(print, "}");
77  if (MICROPY_PY_COLLECTIONS_ORDEREDDICT && self->base.type != &mp_type_dict) {
78  mp_print_str(print, ")");
79  }
80 }
81 
82 STATIC mp_obj_t dict_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args) {
83  mp_obj_t dict_out = mp_obj_new_dict(0);
84  mp_obj_dict_t *dict = MP_OBJ_TO_PTR(dict_out);
85  dict->base.type = type;
86  #if MICROPY_PY_COLLECTIONS_ORDEREDDICT
87  if (type == &mp_type_ordereddict) {
88  dict->map.is_ordered = 1;
89  }
90  #endif
91  if (n_args > 0 || n_kw > 0) {
92  mp_obj_t args2[2] = {dict_out, args[0]}; // args[0] is always valid, even if it's not a positional arg
93  mp_map_t kwargs;
94  mp_map_init_fixed_table(&kwargs, n_kw, args + n_args);
95  dict_update(n_args + 1, args2, &kwargs); // dict_update will check that n_args + 1 == 1 or 2
96  }
97  return dict_out;
98 }
99 
101  mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in);
102  switch (op) {
103  case MP_UNARY_OP_BOOL: return mp_obj_new_bool(self->map.used != 0);
104  case MP_UNARY_OP_LEN: return MP_OBJ_NEW_SMALL_INT(self->map.used);
105  #if MICROPY_PY_SYS_GETSIZEOF
106  case MP_UNARY_OP_SIZEOF: {
107  size_t sz = sizeof(*self) + sizeof(*self->map.table) * self->map.alloc;
108  return MP_OBJ_NEW_SMALL_INT(sz);
109  }
110  #endif
111  default: return MP_OBJ_NULL; // op not supported
112  }
113 }
114 
116  mp_obj_dict_t *o = MP_OBJ_TO_PTR(lhs_in);
117  switch (op) {
118  case MP_BINARY_OP_IN: {
119  mp_map_elem_t *elem = mp_map_lookup(&o->map, rhs_in, MP_MAP_LOOKUP);
120  return mp_obj_new_bool(elem != NULL);
121  }
122  case MP_BINARY_OP_EQUAL: {
123  #if MICROPY_PY_COLLECTIONS_ORDEREDDICT
125  // Iterate through both dictionaries simultaneously and compare keys and values.
126  mp_obj_dict_t *rhs = MP_OBJ_TO_PTR(rhs_in);
127  size_t c1 = 0, c2 = 0;
128  mp_map_elem_t *e1 = dict_iter_next(o, &c1), *e2 = dict_iter_next(rhs, &c2);
129  for (; e1 != NULL && e2 != NULL; e1 = dict_iter_next(o, &c1), e2 = dict_iter_next(rhs, &c2)) {
130  if (!mp_obj_equal(e1->key, e2->key) || !mp_obj_equal(e1->value, e2->value)) {
131  return mp_const_false;
132  }
133  }
134  return e1 == NULL && e2 == NULL ? mp_const_true : mp_const_false;
135  } else
136  #endif
137  if (MP_OBJ_IS_TYPE(rhs_in, &mp_type_dict)) {
138  mp_obj_dict_t *rhs = MP_OBJ_TO_PTR(rhs_in);
139  if (o->map.used != rhs->map.used) {
140  return mp_const_false;
141  }
142 
143  size_t cur = 0;
144  mp_map_elem_t *next = NULL;
145  while ((next = dict_iter_next(o, &cur)) != NULL) {
146  mp_map_elem_t *elem = mp_map_lookup(&rhs->map, next->key, MP_MAP_LOOKUP);
147  if (elem == NULL || !mp_obj_equal(next->value, elem->value)) {
148  return mp_const_false;
149  }
150  }
151  return mp_const_true;
152  } else {
153  // dict is not equal to instance of any other type
154  return mp_const_false;
155  }
156  }
157  default:
158  // op not supported
159  return MP_OBJ_NULL;
160  }
161 }
162 
163 // TODO: Make sure this is inlined in dict_subscr() below.
165  mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in);
166  mp_map_elem_t *elem = mp_map_lookup(&self->map, index, MP_MAP_LOOKUP);
167  if (elem == NULL) {
169  } else {
170  return elem->value;
171  }
172 }
173 
175  if (value == MP_OBJ_NULL) {
176  // delete
177  mp_obj_dict_delete(self_in, index);
178  return mp_const_none;
179  } else if (value == MP_OBJ_SENTINEL) {
180  // load
181  mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in);
182  mp_map_elem_t *elem = mp_map_lookup(&self->map, index, MP_MAP_LOOKUP);
183  if (elem == NULL) {
185  } else {
186  return elem->value;
187  }
188  } else {
189  // store
190  mp_obj_dict_store(self_in, index, value);
191  return mp_const_none;
192  }
193 }
194 
195 /******************************************************************************/
196 /* dict iterator */
197 
198 typedef struct _mp_obj_dict_it_t {
202  size_t cur;
204 
206  mp_obj_dict_it_t *self = MP_OBJ_TO_PTR(self_in);
207  mp_map_elem_t *next = dict_iter_next(MP_OBJ_TO_PTR(self->dict), &self->cur);
208 
209  if (next == NULL) {
210  return MP_OBJ_STOP_ITERATION;
211  } else {
212  return next->key;
213  }
214 }
215 
217  assert(sizeof(mp_obj_dict_it_t) <= sizeof(mp_obj_iter_buf_t));
218  mp_obj_dict_it_t *o = (mp_obj_dict_it_t*)iter_buf;
219  o->base.type = &mp_type_polymorph_iter;
221  o->dict = self_in;
222  o->cur = 0;
223  return MP_OBJ_FROM_PTR(o);
224 }
225 
226 /******************************************************************************/
227 /* dict methods */
228 
231  mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in);
232 
233  mp_map_clear(&self->map);
234 
235  return mp_const_none;
236 }
238 
241  mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in);
242  mp_obj_t other_out = mp_obj_new_dict(self->map.alloc);
243  mp_obj_dict_t *other = MP_OBJ_TO_PTR(other_out);
244  other->base.type = self->base.type;
245  other->map.used = self->map.used;
246  other->map.all_keys_are_qstrs = self->map.all_keys_are_qstrs;
247  other->map.is_fixed = 0;
248  other->map.is_ordered = self->map.is_ordered;
249  memcpy(other->map.table, self->map.table, self->map.alloc * sizeof(mp_map_elem_t));
250  return other_out;
251 }
253 
254 // this is a classmethod
255 STATIC mp_obj_t dict_fromkeys(size_t n_args, const mp_obj_t *args) {
256  mp_obj_t iter = mp_getiter(args[1], NULL);
257  mp_obj_t value = mp_const_none;
258  mp_obj_t next = MP_OBJ_NULL;
259 
260  if (n_args > 2) {
261  value = args[2];
262  }
263 
264  // optimisation to allocate result based on len of argument
265  mp_obj_t self_out;
266  mp_obj_t len = mp_obj_len_maybe(args[1]);
267  if (len == MP_OBJ_NULL) {
268  /* object's type doesn't have a __len__ slot */
269  self_out = mp_obj_new_dict(0);
270  } else {
271  self_out = mp_obj_new_dict(MP_OBJ_SMALL_INT_VALUE(len));
272  }
273 
274  mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_out);
275  while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) {
276  mp_map_lookup(&self->map, next, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = value;
277  }
278 
279  return self_out;
280 }
281 STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_fromkeys_fun_obj, 2, 3, dict_fromkeys);
282 STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(dict_fromkeys_obj, MP_ROM_PTR(&dict_fromkeys_fun_obj));
283 
284 STATIC mp_obj_t dict_get_helper(size_t n_args, const mp_obj_t *args, mp_map_lookup_kind_t lookup_kind) {
286  mp_obj_dict_t *self = MP_OBJ_TO_PTR(args[0]);
287  mp_map_elem_t *elem = mp_map_lookup(&self->map, args[1], lookup_kind);
288  mp_obj_t value;
289  if (elem == NULL || elem->value == MP_OBJ_NULL) {
290  if (n_args == 2) {
291  if (lookup_kind == MP_MAP_LOOKUP_REMOVE_IF_FOUND) {
293  } else {
294  value = mp_const_none;
295  }
296  } else {
297  value = args[2];
298  }
299  if (lookup_kind == MP_MAP_LOOKUP_ADD_IF_NOT_FOUND) {
300  elem->value = value;
301  }
302  } else {
303  value = elem->value;
304  if (lookup_kind == MP_MAP_LOOKUP_REMOVE_IF_FOUND) {
305  elem->value = MP_OBJ_NULL; // so that GC can collect the deleted value
306  }
307  }
308  return value;
309 }
310 
311 STATIC mp_obj_t dict_get(size_t n_args, const mp_obj_t *args) {
312  return dict_get_helper(n_args, args, MP_MAP_LOOKUP);
313 }
315 
316 STATIC mp_obj_t dict_pop(size_t n_args, const mp_obj_t *args) {
318 }
320 
321 STATIC mp_obj_t dict_setdefault(size_t n_args, const mp_obj_t *args) {
323 }
325 
328  mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in);
329  size_t cur = 0;
330  mp_map_elem_t *next = dict_iter_next(self, &cur);
331  if (next == NULL) {
332  mp_raise_msg(&mp_type_KeyError, "popitem(): dictionary is empty");
333  }
334  self->map.used--;
335  mp_obj_t items[] = {next->key, next->value};
336  next->key = MP_OBJ_SENTINEL; // must mark key as sentinel to indicate that it was deleted
337  next->value = MP_OBJ_NULL;
338  mp_obj_t tuple = mp_obj_new_tuple(2, items);
339 
340  return tuple;
341 }
343 
344 STATIC mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs) {
346  mp_obj_dict_t *self = MP_OBJ_TO_PTR(args[0]);
347 
348  mp_arg_check_num(n_args, kwargs->used, 1, 2, true);
349 
350  if (n_args == 2) {
351  // given a positional argument
352 
353  if (MP_OBJ_IS_DICT_TYPE(args[1])) {
354  // update from other dictionary (make sure other is not self)
355  if (args[1] != args[0]) {
356  size_t cur = 0;
357  mp_map_elem_t *elem = NULL;
358  while ((elem = dict_iter_next((mp_obj_dict_t*)MP_OBJ_TO_PTR(args[1]), &cur)) != NULL) {
359  mp_map_lookup(&self->map, elem->key, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = elem->value;
360  }
361  }
362  } else {
363  // update from a generic iterable of pairs
364  mp_obj_t iter = mp_getiter(args[1], NULL);
365  mp_obj_t next = MP_OBJ_NULL;
366  while ((next = mp_iternext(iter)) != MP_OBJ_STOP_ITERATION) {
367  mp_obj_t inneriter = mp_getiter(next, NULL);
368  mp_obj_t key = mp_iternext(inneriter);
369  mp_obj_t value = mp_iternext(inneriter);
370  mp_obj_t stop = mp_iternext(inneriter);
371  if (key == MP_OBJ_STOP_ITERATION
372  || value == MP_OBJ_STOP_ITERATION
373  || stop != MP_OBJ_STOP_ITERATION) {
374  mp_raise_ValueError("dict update sequence has wrong length");
375  } else {
376  mp_map_lookup(&self->map, key, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = value;
377  }
378  }
379  }
380  }
381 
382  // update the dict with any keyword args
383  for (size_t i = 0; i < kwargs->alloc; i++) {
384  if (MP_MAP_SLOT_IS_FILLED(kwargs, i)) {
385  mp_map_lookup(&self->map, kwargs->table[i].key, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = kwargs->table[i].value;
386  }
387  }
388 
389  return mp_const_none;
390 }
391 STATIC MP_DEFINE_CONST_FUN_OBJ_KW(dict_update_obj, 1, dict_update);
392 
393 
394 /******************************************************************************/
395 /* dict views */
396 
399 
400 typedef enum _mp_dict_view_kind_t {
405 
406 STATIC const char *const mp_dict_view_names[] = {"dict_items", "dict_keys", "dict_values"};
407 
408 typedef struct _mp_obj_dict_view_it_t {
412  size_t cur;
414 
415 typedef struct _mp_obj_dict_view_t {
420 
423  mp_obj_dict_view_it_t *self = MP_OBJ_TO_PTR(self_in);
424  mp_map_elem_t *next = dict_iter_next(MP_OBJ_TO_PTR(self->dict), &self->cur);
425 
426  if (next == NULL) {
427  return MP_OBJ_STOP_ITERATION;
428  } else {
429  switch (self->kind) {
430  case MP_DICT_VIEW_ITEMS:
431  default: {
432  mp_obj_t items[] = {next->key, next->value};
433  return mp_obj_new_tuple(2, items);
434  }
435  case MP_DICT_VIEW_KEYS:
436  return next->key;
437  case MP_DICT_VIEW_VALUES:
438  return next->value;
439  }
440  }
441 }
442 
444  { &mp_type_type },
445  .name = MP_QSTR_iterator,
446  .getiter = mp_identity_getiter,
447  .iternext = dict_view_it_iternext,
448 };
449 
451  assert(sizeof(mp_obj_dict_view_it_t) <= sizeof(mp_obj_iter_buf_t));
453  mp_obj_dict_view_t *view = MP_OBJ_TO_PTR(view_in);
455  o->base.type = &dict_view_it_type;
456  o->kind = view->kind;
457  o->dict = view->dict;
458  o->cur = 0;
459  return MP_OBJ_FROM_PTR(o);
460 }
461 
462 STATIC void dict_view_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind) {
463  (void)kind;
465  mp_obj_dict_view_t *self = MP_OBJ_TO_PTR(self_in);
466  bool first = true;
467  mp_print_str(print, mp_dict_view_names[self->kind]);
468  mp_print_str(print, "([");
469  mp_obj_iter_buf_t iter_buf;
470  mp_obj_t self_iter = dict_view_getiter(self_in, &iter_buf);
471  mp_obj_t next = MP_OBJ_NULL;
472  while ((next = dict_view_it_iternext(self_iter)) != MP_OBJ_STOP_ITERATION) {
473  if (!first) {
474  mp_print_str(print, ", ");
475  }
476  first = false;
477  mp_obj_print_helper(print, next, PRINT_REPR);
478  }
479  mp_print_str(print, "])");
480 }
481 
483  // only supported for the 'keys' kind until sets and dicts are refactored
484  mp_obj_dict_view_t *o = MP_OBJ_TO_PTR(lhs_in);
485  if (o->kind != MP_DICT_VIEW_KEYS) {
486  return MP_OBJ_NULL; // op not supported
487  }
488  if (op != MP_BINARY_OP_IN) {
489  return MP_OBJ_NULL; // op not supported
490  }
491  return dict_binary_op(op, o->dict, rhs_in);
492 }
493 
495  { &mp_type_type },
496  .name = MP_QSTR_dict_view,
497  .print = dict_view_print,
498  .binary_op = dict_view_binary_op,
499  .getiter = dict_view_getiter,
500 };
501 
504  o->base.type = &dict_view_type;
505  o->dict = dict;
506  o->kind = kind;
507  return MP_OBJ_FROM_PTR(o);
508 }
509 
512  return mp_obj_new_dict_view(self_in, kind);
513 }
514 
516  return dict_view(self_in, MP_DICT_VIEW_ITEMS);
517 }
519 
521  return dict_view(self_in, MP_DICT_VIEW_KEYS);
522 }
524 
526  return dict_view(self_in, MP_DICT_VIEW_VALUES);
527 }
529 
530 /******************************************************************************/
531 /* dict constructors & public C API */
532 
534  { MP_ROM_QSTR(MP_QSTR_clear), MP_ROM_PTR(&dict_clear_obj) },
535  { MP_ROM_QSTR(MP_QSTR_copy), MP_ROM_PTR(&dict_copy_obj) },
536  { MP_ROM_QSTR(MP_QSTR_fromkeys), MP_ROM_PTR(&dict_fromkeys_obj) },
537  { MP_ROM_QSTR(MP_QSTR_get), MP_ROM_PTR(&dict_get_obj) },
538  { MP_ROM_QSTR(MP_QSTR_items), MP_ROM_PTR(&dict_items_obj) },
539  { MP_ROM_QSTR(MP_QSTR_keys), MP_ROM_PTR(&dict_keys_obj) },
540  { MP_ROM_QSTR(MP_QSTR_pop), MP_ROM_PTR(&dict_pop_obj) },
541  { MP_ROM_QSTR(MP_QSTR_popitem), MP_ROM_PTR(&dict_popitem_obj) },
542  { MP_ROM_QSTR(MP_QSTR_setdefault), MP_ROM_PTR(&dict_setdefault_obj) },
543  { MP_ROM_QSTR(MP_QSTR_update), MP_ROM_PTR(&dict_update_obj) },
544  { MP_ROM_QSTR(MP_QSTR_values), MP_ROM_PTR(&dict_values_obj) },
545  { MP_ROM_QSTR(MP_QSTR___getitem__), MP_ROM_PTR(&mp_op_getitem_obj) },
546  { MP_ROM_QSTR(MP_QSTR___setitem__), MP_ROM_PTR(&mp_op_setitem_obj) },
547  { MP_ROM_QSTR(MP_QSTR___delitem__), MP_ROM_PTR(&mp_op_delitem_obj) },
548 };
549 
551 
553  { &mp_type_type },
554  .name = MP_QSTR_dict,
555  .print = dict_print,
556  .make_new = dict_make_new,
557  .unary_op = dict_unary_op,
558  .binary_op = dict_binary_op,
559  .subscr = dict_subscr,
560  .getiter = dict_getiter,
561  .locals_dict = (mp_obj_dict_t*)&dict_locals_dict,
562 };
563 
564 #if MICROPY_PY_COLLECTIONS_ORDEREDDICT
566  { &mp_type_type },
567  .name = MP_QSTR_OrderedDict,
568  .print = dict_print,
569  .make_new = dict_make_new,
570  .unary_op = dict_unary_op,
571  .binary_op = dict_binary_op,
572  .subscr = dict_subscr,
573  .getiter = dict_getiter,
574  .parent = &mp_type_dict,
575  .locals_dict = (mp_obj_dict_t*)&dict_locals_dict,
576 };
577 #endif
578 
579 void mp_obj_dict_init(mp_obj_dict_t *dict, size_t n_args) {
580  dict->base.type = &mp_type_dict;
581  mp_map_init(&dict->map, n_args);
582 }
583 
584 mp_obj_t mp_obj_new_dict(size_t n_args) {
586  mp_obj_dict_init(o, n_args);
587  return MP_OBJ_FROM_PTR(o);
588 }
589 
590 size_t mp_obj_dict_len(mp_obj_t self_in) {
591  mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in);
592  return self->map.used;
593 }
594 
597  mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in);
598  mp_map_lookup(&self->map, key, MP_MAP_LOOKUP_ADD_IF_NOT_FOUND)->value = value;
599  return self_in;
600 }
601 
603  mp_obj_t args[2] = {self_in, key};
605  return self_in;
606 }
607 
610  mp_obj_dict_t *self = MP_OBJ_TO_PTR(self_in);
611  return &self->map;
612 }
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(dict_fromkeys_fun_obj, 2, 3, dict_fromkeys)
mp_obj_base_t base
Definition: objdict.c:416
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg)
Definition: runtime.c:1448
const mp_obj_type_t mp_type_ordereddict
mp_obj_t mp_obj_new_tuple(size_t n, const mp_obj_t *items)
Definition: objtuple.c:235
#define assert(e)
Definition: assert.h:9
#define mp_const_none
Definition: obj.h:614
STATIC const mp_obj_type_t dict_view_it_type
Definition: objdict.c:398
#define MP_OBJ_IS_TYPE(o, t)
Definition: obj.h:254
STATIC mp_obj_t dict_copy(mp_obj_t self_in)
Definition: objdict.c:239
STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_clear_obj, dict_clear)
void mp_map_init_fixed_table(mp_map_t *map, size_t n, const mp_obj_t *table)
Definition: map.c:86
STATIC void dict_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind)
Definition: objdict.c:55
mp_obj_t mp_obj_dict_get(mp_obj_t self_in, mp_obj_t index)
Definition: objdict.c:164
#define MP_OBJ_IS_DICT_TYPE(o)
Definition: objdict.c:34
void mp_map_init(mp_map_t *map, size_t n)
Definition: map.c:72
mp_obj_t mp_obj_new_dict(size_t n_args)
Definition: objdict.c:584
#define MP_OBJ_SENTINEL
Definition: obj.h:75
int mp_print_str(const mp_print_t *print, const char *str)
Definition: mpprint.c:53
STATIC mp_obj_t dict_fromkeys(size_t n_args, const mp_obj_t *args)
Definition: objdict.c:255
#define MP_ROM_QSTR(q)
Definition: obj.h:241
#define MP_UNLIKELY(x)
Definition: mpconfig.h:1293
#define MP_OBJ_FROM_PTR(p)
Definition: obj.h:233
bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2)
Definition: obj.c:162
mp_obj_base_t base
Definition: objdict.c:199
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
const mp_obj_type_t mp_type_dict
Definition: objdict.c:552
#define MP_ROM_PTR(p)
Definition: obj.h:242
STATIC mp_obj_t dict_get(size_t n_args, const mp_obj_t *args)
Definition: objdict.c:311
STATIC mp_obj_t dict_items(mp_obj_t self_in)
Definition: objdict.c:515
#define mp_const_true
Definition: obj.h:616
void mp_map_clear(mp_map_t *map)
Definition: map.c:103
mp_obj_t key
Definition: obj.h:342
STATIC mp_obj_t dict_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in)
Definition: objdict.c:115
mp_dict_view_kind_t kind
Definition: objdict.c:410
mp_unary_op_t
Definition: runtime0.h:45
size_t alloc
Definition: obj.h:361
size_t is_fixed
Definition: obj.h:358
mp_obj_base_t base
Definition: obj.h:765
STATIC mp_obj_t dict_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf)
Definition: objdict.c:216
#define STATIC
Definition: mpconfig.h:1178
#define MP_OBJ_SMALL_INT_VALUE(o)
Definition: obj.h:86
STATIC mp_obj_t dict_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: objdict.c:82
mp_obj_t(* mp_fun_1_t)(mp_obj_t)
Definition: obj.h:404
STATIC MP_DEFINE_CONST_DICT(dict_locals_dict, dict_locals_dict_table)
mp_map_elem_t * mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t lookup_kind)
Definition: map.c:138
#define MICROPY_PY_UJSON
Definition: mpconfig.h:1055
STATIC mp_obj_t dict_clear(mp_obj_t self_in)
Definition: objdict.c:229
STATIC mp_obj_t dict_view_it_iternext(mp_obj_t self_in)
Definition: objdict.c:421
mp_obj_t mp_obj_len_maybe(mp_obj_t o_in)
Definition: obj.c:448
mp_print_kind_t
Definition: obj.h:412
#define MP_OBJ_NEW_SMALL_INT(small_int)
Definition: obj.h:87
const mp_obj_type_t mp_type_polymorph_iter
Definition: objpolyiter.c:48
STATIC mp_obj_t mp_obj_new_dict_view(mp_obj_t dict, mp_dict_view_kind_t kind)
Definition: objdict.c:502
STATIC mp_obj_t dict_get_helper(size_t n_args, const mp_obj_t *args, mp_map_lookup_kind_t lookup_kind)
Definition: objdict.c:284
mp_obj_base_t base
Definition: objdict.c:409
STATIC MP_DEFINE_CONST_CLASSMETHOD_OBJ(dict_fromkeys_obj, MP_ROM_PTR(&dict_fromkeys_fun_obj))
#define NULL
Definition: stddef.h:4
#define MP_OBJ_NULL
Definition: obj.h:73
mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg)
Definition: objexcept.c:334
#define mp_check_self(pred)
Definition: runtime.h:161
mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value)
Definition: objdict.c:595
void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind)
Definition: obj.c:59
void mp_obj_dict_init(mp_obj_dict_t *dict, size_t n_args)
Definition: objdict.c:579
mp_binary_op_t
Definition: runtime0.h:67
mp_obj_t value
Definition: obj.h:343
STATIC mp_map_elem_t * dict_iter_next(mp_obj_dict_t *dict, size_t *cur)
Definition: objdict.c:41
mp_map_t * mp_obj_dict_get_map(mp_obj_t self_in)
Definition: objdict.c:608
STATIC mp_obj_t dict_view_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in)
Definition: objdict.c:482
args
Definition: i18n.py:175
STATIC mp_obj_t dict_view_getiter(mp_obj_t view_in, mp_obj_iter_buf_t *iter_buf)
Definition: objdict.c:450
STATIC mp_obj_t dict_values(mp_obj_t self_in)
Definition: objdict.c:525
mp_obj_t dict
Definition: objdict.c:201
Definition: obj.h:356
size_t mp_obj_dict_len(mp_obj_t self_in)
Definition: objdict.c:590
const mp_obj_type_t mp_type_type
Definition: objtype.c:969
STATIC const char *const mp_dict_view_names[]
Definition: objdict.c:406
mp_fun_1_t iternext
Definition: objdict.c:200
NORETURN void mp_raise_ValueError(const char *msg)
Definition: runtime.c:1456
enum _mp_map_lookup_kind_t mp_map_lookup_kind_t
enum _mp_dict_view_kind_t mp_dict_view_kind_t
STATIC mp_obj_t dict_pop(size_t n_args, const mp_obj_t *args)
Definition: objdict.c:316
mp_obj_t mp_identity_getiter(mp_obj_t self, mp_obj_iter_buf_t *iter_buf)
Definition: obj.c:507
size_t used
Definition: obj.h:360
STATIC const mp_obj_type_t dict_view_type
Definition: objdict.c:397
STATIC mp_obj_t dict_keys(mp_obj_t self_in)
Definition: objdict.c:520
#define MP_OBJ_TO_PTR(o)
Definition: obj.h:228
#define MICROPY_PY_COLLECTIONS_ORDEREDDICT
Definition: mpconfig.h:894
mp_obj_t mp_obj_dict_delete(mp_obj_t self_in, mp_obj_t key)
Definition: objdict.c:602
mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf)
Definition: runtime.c:1120
#define nlr_raise(val)
Definition: nlr.h:89
STATIC mp_obj_t dict_update(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs)
Definition: objdict.c:344
size_t all_keys_are_qstrs
Definition: obj.h:357
_mp_dict_view_kind_t
Definition: objdict.c:400
struct _mp_obj_dict_it_t mp_obj_dict_it_t
qstr name
Definition: obj.h:478
#define MP_OBJ_STOP_ITERATION
Definition: obj.h:74
mp_map_t map
Definition: obj.h:766
uint64_t mp_obj_t
Definition: obj.h:39
mp_obj_t mp_iternext(mp_obj_t o_in)
Definition: runtime.c:1186
mp_map_elem_t * table
Definition: obj.h:362
int mp_printf(const mp_print_t *print, const char *fmt,...)
Definition: mpprint.c:380
STATIC mp_obj_t dict_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value)
Definition: objdict.c:174
mp_dict_view_kind_t kind
Definition: objdict.c:418
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(dict_update_obj, 1, dict_update)
STATIC mp_obj_t dict_popitem(mp_obj_t self_in)
Definition: objdict.c:326
STATIC mp_obj_t dict_unary_op(mp_unary_op_t op, mp_obj_t self_in)
Definition: objdict.c:100
#define m_new_obj(type)
Definition: misc.h:60
STATIC const mp_rom_map_elem_t dict_locals_dict_table[]
Definition: objdict.c:533
const mp_obj_type_t mp_type_KeyError
struct _mp_obj_dict_view_it_t mp_obj_dict_view_it_t
size_t is_ordered
Definition: obj.h:359
STATIC mp_obj_t dict_it_iternext(mp_obj_t self_in)
Definition: objdict.c:205
void * memcpy(void *dst, const void *src, size_t n)
Definition: memcpy.c:3
STATIC void dict_view_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind)
Definition: objdict.c:462
STATIC mp_obj_t dict_setdefault(size_t n_args, const mp_obj_t *args)
Definition: objdict.c:321
STATIC mp_obj_t dict_view(mp_obj_t self_in, mp_dict_view_kind_t kind)
Definition: objdict.c:510
#define mp_const_false
Definition: obj.h:615
struct _mp_obj_dict_t * locals_dict
Definition: obj.h:536
struct _mp_obj_dict_view_t mp_obj_dict_view_t