Numworks Epsilon  1.4.1
Graphing Calculator Operating System
obj.h
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 #ifndef MICROPY_INCLUDED_PY_OBJ_H
27 #define MICROPY_INCLUDED_PY_OBJ_H
28 
29 #include "py/mpconfig.h"
30 #include "py/misc.h"
31 #include "py/qstr.h"
32 #include "py/mpprint.h"
33 #include "py/runtime0.h"
34 
35 // This is the definition of the opaque MicroPython object type.
36 // All concrete objects have an encoding within this type and the
37 // particular encoding is specified by MICROPY_OBJ_REPR.
38 #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D
41 #else
42 typedef void *mp_obj_t;
43 typedef const void *mp_const_obj_t;
44 #endif
45 
46 // This mp_obj_type_t struct is a concrete MicroPython object which holds info
47 // about a type. See below for actual definition of the struct.
49 
50 // Anything that wants to be a concrete MicroPython object must have mp_obj_base_t
51 // as its first member (small ints, qstr objs and inline floats are not concrete).
54 };
56 
57 // These fake objects are used to indicate certain things in arguments or return
58 // values, and should only be used when explicitly allowed.
59 //
60 // - MP_OBJ_NULL : used to indicate the absence of an object, or unsupported operation.
61 // - MP_OBJ_STOP_ITERATION : used instead of throwing a StopIteration, for efficiency.
62 // - MP_OBJ_SENTINEL : used for various internal purposes where one needs
63 // an object which is unique from all other objects, including MP_OBJ_NULL.
64 //
65 // For debugging purposes they are all different. For non-debug mode, we alias
66 // as many as we can to MP_OBJ_NULL because it's cheaper to load/compare 0.
67 
68 #ifdef NDEBUG
69 #define MP_OBJ_NULL (MP_OBJ_FROM_PTR((void*)0))
70 #define MP_OBJ_STOP_ITERATION (MP_OBJ_FROM_PTR((void*)0))
71 #define MP_OBJ_SENTINEL (MP_OBJ_FROM_PTR((void*)4))
72 #else
73 #define MP_OBJ_NULL (MP_OBJ_FROM_PTR((void*)0))
74 #define MP_OBJ_STOP_ITERATION (MP_OBJ_FROM_PTR((void*)4))
75 #define MP_OBJ_SENTINEL (MP_OBJ_FROM_PTR((void*)8))
76 #endif
77 
78 // These macros/inline functions operate on objects and depend on the
79 // particular object representation. They are used to query, pack and
80 // unpack small ints, qstrs and full object pointers.
81 
82 #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A
83 
84 static inline bool MP_OBJ_IS_SMALL_INT(mp_const_obj_t o)
85  { return ((((mp_int_t)(o)) & 1) != 0); }
86 #define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1)
87 #define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 1) | 1))
88 
89 static inline bool MP_OBJ_IS_QSTR(mp_const_obj_t o)
90  { return ((((mp_int_t)(o)) & 3) == 2); }
91 #define MP_OBJ_QSTR_VALUE(o) (((mp_uint_t)(o)) >> 2)
92 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 2))
93 
94 #if MICROPY_PY_BUILTINS_FLOAT
95 #define mp_const_float_e MP_ROM_PTR(&mp_const_float_e_obj)
96 #define mp_const_float_pi MP_ROM_PTR(&mp_const_float_pi_obj)
97 extern const struct _mp_obj_float_t mp_const_float_e_obj;
98 extern const struct _mp_obj_float_t mp_const_float_pi_obj;
99 
100 #define mp_obj_is_float(o) MP_OBJ_IS_TYPE((o), &mp_type_float)
101 mp_float_t mp_obj_float_get(mp_obj_t self_in);
102 mp_obj_t mp_obj_new_float(mp_float_t value);
103 #endif
104 
105 static inline bool MP_OBJ_IS_OBJ(mp_const_obj_t o)
106  { return ((((mp_int_t)(o)) & 3) == 0); }
107 
108 #elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B
109 
110 static inline bool MP_OBJ_IS_SMALL_INT(mp_const_obj_t o)
111  { return ((((mp_int_t)(o)) & 3) == 1); }
112 #define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 2)
113 #define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 2) | 1))
114 
115 static inline bool MP_OBJ_IS_QSTR(mp_const_obj_t o)
116  { return ((((mp_int_t)(o)) & 3) == 3); }
117 #define MP_OBJ_QSTR_VALUE(o) (((mp_uint_t)(o)) >> 2)
118 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 2) | 3))
119 
120 #if MICROPY_PY_BUILTINS_FLOAT
121 #define mp_const_float_e MP_ROM_PTR(&mp_const_float_e_obj)
122 #define mp_const_float_pi MP_ROM_PTR(&mp_const_float_pi_obj)
123 extern const struct _mp_obj_float_t mp_const_float_e_obj;
124 extern const struct _mp_obj_float_t mp_const_float_pi_obj;
125 
126 #define mp_obj_is_float(o) MP_OBJ_IS_TYPE((o), &mp_type_float)
127 mp_float_t mp_obj_float_get(mp_obj_t self_in);
128 mp_obj_t mp_obj_new_float(mp_float_t value);
129 #endif
130 
131 static inline bool MP_OBJ_IS_OBJ(mp_const_obj_t o)
132  { return ((((mp_int_t)(o)) & 1) == 0); }
133 
134 #elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C
135 
136 static inline bool MP_OBJ_IS_SMALL_INT(mp_const_obj_t o)
137  { return ((((mp_int_t)(o)) & 1) != 0); }
138 #define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1)
139 #define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 1) | 1))
140 
141 #define mp_const_float_e MP_ROM_PTR((mp_obj_t)(((0x402df854 & ~3) | 2) + 0x80800000))
142 #define mp_const_float_pi MP_ROM_PTR((mp_obj_t)(((0x40490fdb & ~3) | 2) + 0x80800000))
143 
144 static inline bool mp_obj_is_float(mp_const_obj_t o)
145  { return (((mp_uint_t)(o)) & 3) == 2 && (((mp_uint_t)(o)) & 0xff800007) != 0x00000006; }
146 static inline mp_float_t mp_obj_float_get(mp_const_obj_t o) {
147  union {
148  mp_float_t f;
149  mp_uint_t u;
150  } num = {.u = ((mp_uint_t)o - 0x80800000) & ~3};
151  return num.f;
152 }
153 static inline mp_obj_t mp_obj_new_float(mp_float_t f) {
154  union {
155  mp_float_t f;
156  mp_uint_t u;
157  } num = {.f = f};
158  return (mp_obj_t)(((num.u & ~0x3) | 2) + 0x80800000);
159 }
160 
161 static inline bool MP_OBJ_IS_QSTR(mp_const_obj_t o)
162  { return (((mp_uint_t)(o)) & 0xff800007) == 0x00000006; }
163 #define MP_OBJ_QSTR_VALUE(o) (((mp_uint_t)(o)) >> 3)
164 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 3) | 0x00000006))
165 
166 static inline bool MP_OBJ_IS_OBJ(mp_const_obj_t o)
167  { return ((((mp_int_t)(o)) & 3) == 0); }
168 
169 #elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D
170 
171 static inline bool MP_OBJ_IS_SMALL_INT(mp_const_obj_t o)
172  { return ((((mp_int_t)(o)) & 0xffff000000000000) == 0x0001000000000000); }
173 #define MP_OBJ_SMALL_INT_VALUE(o) (((intptr_t)(o)) >> 1)
174 #define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)(((uintptr_t)(small_int)) << 1) | 0x0001000000000001)
175 
176 static inline bool MP_OBJ_IS_QSTR(mp_const_obj_t o)
177  { return ((((mp_int_t)(o)) & 0xffff000000000000) == 0x0002000000000000); }
178 #define MP_OBJ_QSTR_VALUE(o) ((((uint32_t)(o)) >> 1) & 0xffffffff)
179 #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 1) | 0x0002000000000001))
180 
181 #if MICROPY_PY_BUILTINS_FLOAT
182 #define mp_const_float_e {((mp_obj_t)((uint64_t)0x4005bf0a8b125769 + 0x8004000000000000))}
183 #define mp_const_float_pi {((mp_obj_t)((uint64_t)0x400921fb54442d18 + 0x8004000000000000))}
184 
185 static inline bool mp_obj_is_float(mp_const_obj_t o) {
186  return ((uint64_t)(o) & 0xfffc000000000000) != 0;
187 }
188 static inline mp_float_t mp_obj_float_get(mp_const_obj_t o) {
189  union {
190  mp_float_t f;
191  uint64_t r;
192  } num = {.r = o - 0x8004000000000000};
193  return num.f;
194 }
195 static inline mp_obj_t mp_obj_new_float(mp_float_t f) {
196  union {
197  mp_float_t f;
198  uint64_t r;
199  } num = {.f = f};
200  return num.r + 0x8004000000000000;
201 }
202 #endif
203 
204 static inline bool MP_OBJ_IS_OBJ(mp_const_obj_t o)
205  { return ((((uint64_t)(o)) & 0xffff000000000000) == 0x0000000000000000); }
206 #define MP_OBJ_TO_PTR(o) ((void*)(uintptr_t)(o))
207 #define MP_OBJ_FROM_PTR(p) ((mp_obj_t)((uintptr_t)(p)))
208 
209 // rom object storage needs special handling to widen 32-bit pointer to 64-bits
210 typedef union _mp_rom_obj_t { uint64_t u64; struct { const void *lo, *hi; } u32; } mp_rom_obj_t;
211 #define MP_ROM_INT(i) {MP_OBJ_NEW_SMALL_INT(i)}
212 #define MP_ROM_QSTR(q) {MP_OBJ_NEW_QSTR(q)}
213 #if MP_ENDIANNESS_LITTLE
214 #define MP_ROM_PTR(p) {.u32 = {.lo = (p), .hi = NULL}}
215 #else
216 #define MP_ROM_PTR(p) {.u32 = {.lo = NULL, .hi = (p)}}
217 #endif
218 
219 #endif
220 
221 // Macros to convert between mp_obj_t and concrete object types.
222 // These are identity operations in MicroPython, but ability to override
223 // these operations are provided to experiment with other methods of
224 // object representation and memory management.
225 
226 // Cast mp_obj_t to object pointer
227 #ifndef MP_OBJ_TO_PTR
228 #define MP_OBJ_TO_PTR(o) ((void*)o)
229 #endif
230 
231 // Cast object pointer to mp_obj_t
232 #ifndef MP_OBJ_FROM_PTR
233 #define MP_OBJ_FROM_PTR(p) ((mp_obj_t)p)
234 #endif
235 
236 // Macros to create objects that are stored in ROM.
237 
238 #ifndef MP_ROM_INT
240 #define MP_ROM_INT(i) MP_OBJ_NEW_SMALL_INT(i)
241 #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
242 #define MP_ROM_PTR(p) (p)
243 /* for testing
244 typedef struct _mp_rom_obj_t { mp_const_obj_t o; } mp_rom_obj_t;
245 #define MP_ROM_INT(i) {MP_OBJ_NEW_SMALL_INT(i)}
246 #define MP_ROM_QSTR(q) {MP_OBJ_NEW_QSTR(q)}
247 #define MP_ROM_PTR(p) {.o = p}
248 */
249 #endif
250 
251 // The macros below are derived from the ones above and are used to
252 // check for more specific object types.
253 
254 #define MP_OBJ_IS_TYPE(o, t) (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)MP_OBJ_TO_PTR(o))->type == (t))) // this does not work for checking int, str or fun; use below macros for that
255 #define MP_OBJ_IS_INT(o) (MP_OBJ_IS_SMALL_INT(o) || MP_OBJ_IS_TYPE(o, &mp_type_int))
256 #define MP_OBJ_IS_STR(o) (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &mp_type_str))
257 #define MP_OBJ_IS_STR_OR_BYTES(o) (MP_OBJ_IS_QSTR(o) || (MP_OBJ_IS_OBJ(o) && ((mp_obj_base_t*)MP_OBJ_TO_PTR(o))->type->binary_op == mp_obj_str_binary_op))
258 #define MP_OBJ_IS_FUN(o) (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)MP_OBJ_TO_PTR(o))->type->name == MP_QSTR_function))
259 
260 // Note: inline functions sometimes use much more code space than the
261 // equivalent macros, depending on the compiler.
262 //static inline bool MP_OBJ_IS_TYPE(mp_const_obj_t o, const mp_obj_type_t *t) { return (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)(o))->type == (t))); } // this does not work for checking a string, use below macro for that
263 //static inline bool MP_OBJ_IS_INT(mp_const_obj_t o) { return (MP_OBJ_IS_SMALL_INT(o) || MP_OBJ_IS_TYPE(o, &mp_type_int)); } // returns true if o is a small int or long int
264 // Need to forward declare these for the inline function to compile.
265 extern const mp_obj_type_t mp_type_int;
266 extern const mp_obj_type_t mp_type_bool;
267 static inline bool mp_obj_is_integer(mp_const_obj_t o) { return MP_OBJ_IS_INT(o) || MP_OBJ_IS_TYPE(o, &mp_type_bool); } // returns true if o is bool, small int or long int
268 //static inline bool MP_OBJ_IS_STR(mp_const_obj_t o) { return (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &mp_type_str)); }
269 
270 
271 // These macros are used to declare and define constant function objects
272 // You can put "static" in front of the definitions to make them local
273 
274 #define MP_DECLARE_CONST_FUN_OBJ_0(obj_name) extern const mp_obj_fun_builtin_fixed_t obj_name
275 #define MP_DECLARE_CONST_FUN_OBJ_1(obj_name) extern const mp_obj_fun_builtin_fixed_t obj_name
276 #define MP_DECLARE_CONST_FUN_OBJ_2(obj_name) extern const mp_obj_fun_builtin_fixed_t obj_name
277 #define MP_DECLARE_CONST_FUN_OBJ_3(obj_name) extern const mp_obj_fun_builtin_fixed_t obj_name
278 #define MP_DECLARE_CONST_FUN_OBJ_VAR(obj_name) extern const mp_obj_fun_builtin_var_t obj_name
279 #define MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name) extern const mp_obj_fun_builtin_var_t obj_name
280 #define MP_DECLARE_CONST_FUN_OBJ_KW(obj_name) extern const mp_obj_fun_builtin_var_t obj_name
281 
282 #define MP_DEFINE_CONST_FUN_OBJ_0(obj_name, fun_name) \
283  const mp_obj_fun_builtin_fixed_t obj_name = \
284  {{&mp_type_fun_builtin_0}, .fun._0 = fun_name}
285 #define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name) \
286  const mp_obj_fun_builtin_fixed_t obj_name = \
287  {{&mp_type_fun_builtin_1}, .fun._1 = fun_name}
288 #define MP_DEFINE_CONST_FUN_OBJ_2(obj_name, fun_name) \
289  const mp_obj_fun_builtin_fixed_t obj_name = \
290  {{&mp_type_fun_builtin_2}, .fun._2 = fun_name}
291 #define MP_DEFINE_CONST_FUN_OBJ_3(obj_name, fun_name) \
292  const mp_obj_fun_builtin_fixed_t obj_name = \
293  {{&mp_type_fun_builtin_3}, .fun._3 = fun_name}
294 #define MP_DEFINE_CONST_FUN_OBJ_VAR(obj_name, n_args_min, fun_name) \
295  const mp_obj_fun_builtin_var_t obj_name = \
296  {{&mp_type_fun_builtin_var}, false, n_args_min, MP_OBJ_FUN_ARGS_MAX, .fun.var = fun_name}
297 #define MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name, n_args_min, n_args_max, fun_name) \
298  const mp_obj_fun_builtin_var_t obj_name = \
299  {{&mp_type_fun_builtin_var}, false, n_args_min, n_args_max, .fun.var = fun_name}
300 #define MP_DEFINE_CONST_FUN_OBJ_KW(obj_name, n_args_min, fun_name) \
301  const mp_obj_fun_builtin_var_t obj_name = \
302  {{&mp_type_fun_builtin_var}, true, n_args_min, MP_OBJ_FUN_ARGS_MAX, .fun.kw = fun_name}
303 
304 // These macros are used to define constant map/dict objects
305 // You can put "static" in front of the definition to make it local
306 
307 #define MP_DEFINE_CONST_MAP(map_name, table_name) \
308  const mp_map_t map_name = { \
309  .all_keys_are_qstrs = 1, \
310  .is_fixed = 1, \
311  .is_ordered = 1, \
312  .used = MP_ARRAY_SIZE(table_name), \
313  .alloc = MP_ARRAY_SIZE(table_name), \
314  .table = (mp_map_elem_t*)(mp_rom_map_elem_t*)table_name, \
315  }
316 
317 #define MP_DEFINE_CONST_DICT(dict_name, table_name) \
318  const mp_obj_dict_t dict_name = { \
319  .base = {&mp_type_dict}, \
320  .map = { \
321  .all_keys_are_qstrs = 1, \
322  .is_fixed = 1, \
323  .is_ordered = 1, \
324  .used = MP_ARRAY_SIZE(table_name), \
325  .alloc = MP_ARRAY_SIZE(table_name), \
326  .table = (mp_map_elem_t*)(mp_rom_map_elem_t*)table_name, \
327  }, \
328  }
329 
330 // These macros are used to declare and define constant staticmethond and classmethod objects
331 // You can put "static" in front of the definitions to make them local
332 
333 #define MP_DECLARE_CONST_STATICMETHOD_OBJ(obj_name) extern const mp_rom_obj_static_class_method_t obj_name
334 #define MP_DECLARE_CONST_CLASSMETHOD_OBJ(obj_name) extern const mp_rom_obj_static_class_method_t obj_name
335 
336 #define MP_DEFINE_CONST_STATICMETHOD_OBJ(obj_name, fun_name) const mp_rom_obj_static_class_method_t obj_name = {{&mp_type_staticmethod}, fun_name}
337 #define MP_DEFINE_CONST_CLASSMETHOD_OBJ(obj_name, fun_name) const mp_rom_obj_static_class_method_t obj_name = {{&mp_type_classmethod}, fun_name}
338 
339 // Underlying map/hash table implementation (not dict object or map function)
340 
341 typedef struct _mp_map_elem_t {
344 } mp_map_elem_t;
345 
346 typedef struct _mp_rom_map_elem_t {
350 
351 // TODO maybe have a truncated mp_map_t for fixed tables, since alloc=used
352 // put alloc last in the structure, so the truncated version does not need it
353 // this would save 1 ROM word for all ROM objects that have a locals_dict
354 // would also need a trucated dict structure
355 
356 typedef struct _mp_map_t {
357  size_t all_keys_are_qstrs : 1;
358  size_t is_fixed : 1; // a fixed array that can't be modified; must also be ordered
359  size_t is_ordered : 1; // an ordered array
360  size_t used : (8 * sizeof(size_t) - 3);
361  size_t alloc;
363 } mp_map_t;
364 
365 // mp_set_lookup requires these constants to have the values they do
366 typedef enum _mp_map_lookup_kind_t {
370  MP_MAP_LOOKUP_ADD_IF_NOT_FOUND_OR_REMOVE_IF_FOUND = 3, // only valid for mp_set_lookup
372 
373 extern const mp_map_t mp_const_empty_map;
374 
375 static inline bool MP_MAP_SLOT_IS_FILLED(const mp_map_t *map, size_t pos) { return ((map)->table[pos].key != MP_OBJ_NULL && (map)->table[pos].key != MP_OBJ_SENTINEL); }
376 
377 void mp_map_init(mp_map_t *map, size_t n);
378 void mp_map_init_fixed_table(mp_map_t *map, size_t n, const mp_obj_t *table);
379 mp_map_t *mp_map_new(size_t n);
380 void mp_map_deinit(mp_map_t *map);
381 void mp_map_free(mp_map_t *map);
383 void mp_map_clear(mp_map_t *map);
384 void mp_map_dump(mp_map_t *map);
385 
386 // Underlying set implementation (not set object)
387 
388 typedef struct _mp_set_t {
389  size_t alloc;
390  size_t used;
392 } mp_set_t;
393 
394 static inline bool MP_SET_SLOT_IS_FILLED(const mp_set_t *set, size_t pos) { return ((set)->table[pos] != MP_OBJ_NULL && (set)->table[pos] != MP_OBJ_SENTINEL); }
395 
396 void mp_set_init(mp_set_t *set, size_t n);
399 void mp_set_clear(mp_set_t *set);
400 
401 // Type definitions for methods
402 
403 typedef mp_obj_t (*mp_fun_0_t)(void);
407 typedef mp_obj_t (*mp_fun_var_t)(size_t n, const mp_obj_t *);
408 // mp_fun_kw_t takes mp_map_t* (and not const mp_map_t*) to ease passing
409 // this arg to mp_map_lookup().
410 typedef mp_obj_t (*mp_fun_kw_t)(size_t n, const mp_obj_t *, mp_map_t *);
411 
412 typedef enum {
415  PRINT_EXC = 2, // Special format for printing exception in unhandled exception message
417  PRINT_RAW = 4, // Special format for printing bytes as an undercorated string
418  PRINT_EXC_SUBCLASS = 0x80, // Internal flag for printing exception subclasses
420 
421 typedef struct _mp_obj_iter_buf_t {
425 
426 // The number of slots that an mp_obj_iter_buf_t needs on the Python value stack.
427 // It's rounded up in case mp_obj_base_t is smaller than mp_obj_t (eg for OBJ_REPR_D).
428 #define MP_OBJ_ITER_BUF_NSLOTS ((sizeof(mp_obj_iter_buf_t) + sizeof(mp_obj_t) - 1) / sizeof(mp_obj_t))
429 
430 typedef void (*mp_print_fun_t)(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind);
431 typedef mp_obj_t (*mp_make_new_fun_t)(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args);
432 typedef mp_obj_t (*mp_call_fun_t)(mp_obj_t fun, size_t n_args, size_t n_kw, const mp_obj_t *args);
435 typedef void (*mp_attr_fun_t)(mp_obj_t self_in, qstr attr, mp_obj_t *dest);
436 typedef mp_obj_t (*mp_subscr_fun_t)(mp_obj_t self_in, mp_obj_t index, mp_obj_t value);
437 typedef mp_obj_t (*mp_getiter_fun_t)(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf);
438 
439 // Buffer protocol
440 typedef struct _mp_buffer_info_t {
441  // if we'd bother to support various versions of structure
442  // (with different number of fields), we can distinguish
443  // them with ver = sizeof(struct). Cons: overkill for *micro*?
444  //int ver; // ?
445 
446  void *buf; // can be NULL if len == 0
447  size_t len; // in bytes
448  int typecode; // as per binary.h
449 
450  // Rationale: to load arbitrary-sized sprites directly to LCD
451  // Cons: a bit adhoc usecase
452  // int stride;
454 #define MP_BUFFER_READ (1)
455 #define MP_BUFFER_WRITE (2)
456 #define MP_BUFFER_RW (MP_BUFFER_READ | MP_BUFFER_WRITE)
457 typedef struct _mp_buffer_p_t {
459 } mp_buffer_p_t;
460 bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
461 void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
462 
463 // Stream protocol
464 typedef struct _mp_stream_p_t {
465  // On error, functions should return MP_STREAM_ERROR and fill in *errcode (values
466  // are implementation-dependent, but will be exposed to user, e.g. via exception).
467  mp_uint_t (*read)(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode);
468  mp_uint_t (*write)(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode);
469  mp_uint_t (*ioctl)(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *errcode);
470  mp_uint_t is_text : 1; // default is bytes, set this for text stream
471 } mp_stream_p_t;
472 
474  // A type is an object so must start with this entry, which points to mp_type_type.
476 
477  // The name of this type.
479 
480  // Corresponds to __repr__ and __str__ special methods.
482 
483  // Corresponds to __new__ and __init__ special methods, to make an instance of the type.
485 
486  // Corresponds to __call__ special method, ie T(...).
488 
489  // Implements unary and binary operations.
490  // Can return MP_OBJ_NULL if the operation is not supported.
493 
494  // Implements load, store and delete attribute.
495  //
496  // dest[0] = MP_OBJ_NULL means load
497  // return: for fail, do nothing
498  // for attr, dest[0] = value
499  // for method, dest[0] = method, dest[1] = self
500  //
501  // dest[0,1] = {MP_OBJ_SENTINEL, MP_OBJ_NULL} means delete
502  // dest[0,1] = {MP_OBJ_SENTINEL, object} means store
503  // return: for fail, do nothing
504  // for success set dest[0] = MP_OBJ_NULL
506 
507  // Implements load, store and delete subscripting:
508  // - value = MP_OBJ_SENTINEL means load
509  // - value = MP_OBJ_NULL means delete
510  // - all other values mean store the value
511  // Can return MP_OBJ_NULL if operation not supported.
513 
514  // Corresponds to __iter__ special method.
515  // Can use the given mp_obj_iter_buf_t to store iterator object,
516  // otherwise can return a pointer to an object on the heap.
518 
519  // Corresponds to __next__ special method. May return MP_OBJ_STOP_ITERATION
520  // as an optimisation instead of raising StopIteration() with no args.
522 
523  // Implements the buffer protocol if supported by this type.
525 
526  // One of disjoint protocols (interfaces), like mp_stream_p_t, etc.
527  const void *protocol;
528 
529  // A pointer to the parents of this type:
530  // - 0 parents: pointer is NULL (object is implicitly the single parent)
531  // - 1 parent: a pointer to the type of that parent
532  // - 2 or more parents: pointer to a tuple object containing the parent types
533  const void *parent;
534 
535  // A dict mapping qstrs to objects local methods/constants/etc.
537 };
538 
539 // Constant types, globally accessible
540 extern const mp_obj_type_t mp_type_type;
541 extern const mp_obj_type_t mp_type_object;
542 extern const mp_obj_type_t mp_type_NoneType;
545 extern const mp_obj_type_t mp_type_str;
546 extern const mp_obj_type_t mp_type_bytes;
547 extern const mp_obj_type_t mp_type_bytearray;
548 extern const mp_obj_type_t mp_type_memoryview;
549 extern const mp_obj_type_t mp_type_float;
550 extern const mp_obj_type_t mp_type_complex;
551 extern const mp_obj_type_t mp_type_tuple;
552 extern const mp_obj_type_t mp_type_list;
553 extern const mp_obj_type_t mp_type_map; // map (the python builtin, not the dict implementation detail)
554 extern const mp_obj_type_t mp_type_enumerate;
555 extern const mp_obj_type_t mp_type_filter;
556 extern const mp_obj_type_t mp_type_dict;
558 extern const mp_obj_type_t mp_type_range;
559 extern const mp_obj_type_t mp_type_set;
560 extern const mp_obj_type_t mp_type_frozenset;
561 extern const mp_obj_type_t mp_type_slice;
562 extern const mp_obj_type_t mp_type_zip;
563 extern const mp_obj_type_t mp_type_array;
564 extern const mp_obj_type_t mp_type_super;
571 extern const mp_obj_type_t mp_type_fun_bc;
572 extern const mp_obj_type_t mp_type_module;
575 extern const mp_obj_type_t mp_type_property;
576 extern const mp_obj_type_t mp_type_stringio;
577 extern const mp_obj_type_t mp_type_bytesio;
578 extern const mp_obj_type_t mp_type_reversed;
580 
581 // Exceptions
586 extern const mp_obj_type_t mp_type_EOFError;
587 extern const mp_obj_type_t mp_type_Exception;
591 extern const mp_obj_type_t mp_type_IndexError;
593 extern const mp_obj_type_t mp_type_KeyError;
596 extern const mp_obj_type_t mp_type_NameError;
598 extern const mp_obj_type_t mp_type_OSError;
605 extern const mp_obj_type_t mp_type_SystemExit;
606 extern const mp_obj_type_t mp_type_TypeError;
608 extern const mp_obj_type_t mp_type_ValueError;
611 
612 // Constant objects, globally accessible
613 // The macros are for convenience only
614 #define mp_const_none (MP_OBJ_FROM_PTR(&mp_const_none_obj))
615 #define mp_const_false (MP_OBJ_FROM_PTR(&mp_const_false_obj))
616 #define mp_const_true (MP_OBJ_FROM_PTR(&mp_const_true_obj))
617 #define mp_const_empty_bytes (MP_OBJ_FROM_PTR(&mp_const_empty_bytes_obj))
618 #define mp_const_empty_tuple (MP_OBJ_FROM_PTR(&mp_const_empty_tuple_obj))
619 #define mp_const_notimplemented (MP_OBJ_FROM_PTR(&mp_const_notimplemented_obj))
620 extern const struct _mp_obj_none_t mp_const_none_obj;
621 extern const struct _mp_obj_bool_t mp_const_false_obj;
622 extern const struct _mp_obj_bool_t mp_const_true_obj;
623 extern const struct _mp_obj_str_t mp_const_empty_bytes_obj;
624 extern const struct _mp_obj_tuple_t mp_const_empty_tuple_obj;
625 extern const struct _mp_obj_singleton_t mp_const_ellipsis_obj;
629 
630 // General API for objects
631 
632 mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict);
633 static inline mp_obj_t mp_obj_new_bool(mp_int_t x) { return x ? mp_const_true : mp_const_false; }
637 mp_obj_t mp_obj_new_int_from_str_len(const char **str, size_t len, bool neg, unsigned int base);
638 mp_obj_t mp_obj_new_int_from_ll(long long val); // this must return a multi-precision integer object (or raise an overflow exception)
639 mp_obj_t mp_obj_new_int_from_ull(unsigned long long val); // this must return a multi-precision integer object (or raise an overflow exception)
640 mp_obj_t mp_obj_new_str(const char* data, size_t len, bool make_qstr_if_not_already);
642 mp_obj_t mp_obj_new_bytes(const byte* data, size_t len);
643 mp_obj_t mp_obj_new_bytearray(size_t n, void *items);
644 mp_obj_t mp_obj_new_bytearray_by_ref(size_t n, void *items);
645 #if MICROPY_PY_BUILTINS_FLOAT
646 mp_obj_t mp_obj_new_int_from_float(mp_float_t val);
647 mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag);
648 #endif
651 mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args, const mp_obj_t *args);
652 mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const char *msg);
653 mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const char *fmt, ...); // counts args by number of % symbols in fmt, excluding %%; can only handle void* sizes (ie no float/double!)
654 mp_obj_t mp_obj_new_fun_bc(mp_obj_t def_args, mp_obj_t def_kw_args, const byte *code, const mp_uint_t *const_table);
655 mp_obj_t mp_obj_new_fun_native(mp_obj_t def_args_in, mp_obj_t def_kw_args, const void *fun_data, const mp_uint_t *const_table);
656 mp_obj_t mp_obj_new_fun_viper(size_t n_args, void *fun_data, mp_uint_t type_sig);
657 mp_obj_t mp_obj_new_fun_asm(size_t n_args, void *fun_data, mp_uint_t type_sig);
659 mp_obj_t mp_obj_new_closure(mp_obj_t fun, size_t n_closed, const mp_obj_t *closed);
660 mp_obj_t mp_obj_new_tuple(size_t n, const mp_obj_t *items);
661 mp_obj_t mp_obj_new_list(size_t n, mp_obj_t *items);
662 mp_obj_t mp_obj_new_dict(size_t n_args);
663 mp_obj_t mp_obj_new_set(size_t n_args, mp_obj_t *items);
667 mp_obj_t mp_obj_new_module(qstr module_name);
668 mp_obj_t mp_obj_new_memoryview(byte typecode, size_t nitems, void *items);
669 
671 const char *mp_obj_get_type_str(mp_const_obj_t o_in);
672 bool mp_obj_is_subclass_fast(mp_const_obj_t object, mp_const_obj_t classinfo); // arguments should be type objects
674 
675 void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind);
677 void mp_obj_print_exception(const mp_print_t *print, mp_obj_t exc);
678 
679 bool mp_obj_is_true(mp_obj_t arg);
680 bool mp_obj_is_callable(mp_obj_t o_in);
681 bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2);
682 
686 #if MICROPY_PY_BUILTINS_FLOAT
687 mp_float_t mp_obj_get_float(mp_obj_t self_in);
688 bool mp_obj_get_float_maybe(mp_obj_t arg, mp_float_t *value);
689 void mp_obj_get_complex(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
690 #endif
691 //qstr mp_obj_get_qstr(mp_obj_t arg);
692 void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items); // *items may point inside a GC block
693 void mp_obj_get_array_fixed_n(mp_obj_t o, size_t len, mp_obj_t **items); // *items may point inside a GC block
694 size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool is_slice);
697 mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); // may return MP_OBJ_NULL
700 
701 // cell
703 void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj);
704 
705 // int
706 // For long int, returns value truncated to mp_int_t
708 // Will raise exception if value doesn't fit into mp_int_t
710 
711 // exception
712 #define mp_obj_is_native_exception_instance(o) (mp_obj_get_type(o)->make_new == mp_obj_exception_make_new)
713 bool mp_obj_is_exception_type(mp_obj_t self_in);
717 void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block);
718 void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values);
720 mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
723 
724 // str
725 bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2);
726 qstr mp_obj_str_get_qstr(mp_obj_t self_in); // use this if you will anyway convert the string to a qstr
727 const char *mp_obj_str_get_str(mp_obj_t self_in); // use this only if you need the string to be null terminated
728 const char *mp_obj_str_get_data(mp_obj_t self_in, size_t *len);
730 void mp_str_print_quoted(const mp_print_t *print, const byte *str_data, size_t str_len, bool is_bytes);
731 
732 #if MICROPY_PY_BUILTINS_FLOAT
733 // float
734 #if MICROPY_FLOAT_HIGH_QUALITY_HASH
735 mp_int_t mp_float_hash(mp_float_t val);
736 #else
737 static inline mp_int_t mp_float_hash(mp_float_t val) { return (mp_int_t)val; }
738 #endif
739 mp_obj_t mp_obj_float_binary_op(mp_binary_op_t op, mp_float_t lhs_val, mp_obj_t rhs); // can return MP_OBJ_NULL if op not supported
740 
741 // complex
742 void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
743 mp_obj_t mp_obj_complex_binary_op(mp_binary_op_t op, mp_float_t lhs_real, mp_float_t lhs_imag, mp_obj_t rhs_in); // can return MP_OBJ_NULL if op not supported
744 #else
745 #define mp_obj_is_float(o) (false)
746 #endif
747 
748 // tuple
749 void mp_obj_tuple_get(mp_obj_t self_in, size_t *len, mp_obj_t **items);
750 void mp_obj_tuple_del(mp_obj_t self_in);
752 
753 // list
754 struct _mp_obj_list_t;
755 void mp_obj_list_init(struct _mp_obj_list_t *o, size_t n);
758 void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items);
759 void mp_obj_list_set_len(mp_obj_t self_in, size_t len);
760 void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value);
761 mp_obj_t mp_obj_list_sort(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs);
762 
763 // dict
764 typedef struct _mp_obj_dict_t {
767 } mp_obj_dict_t;
768 void mp_obj_dict_init(mp_obj_dict_t *dict, size_t n_args);
769 size_t mp_obj_dict_len(mp_obj_t self_in);
770 mp_obj_t mp_obj_dict_get(mp_obj_t self_in, mp_obj_t index);
774 
775 // set
776 void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item);
777 
778 // slice
779 void mp_obj_slice_get(mp_obj_t self_in, mp_obj_t *start, mp_obj_t *stop, mp_obj_t *step);
780 
781 // functions
782 
785  union {
790  } fun;
792 
793 #define MP_OBJ_FUN_ARGS_MAX (0xffff) // to set maximum value in n_args_max below
796  bool is_kw : 1;
797  mp_uint_t n_args_min : 15; // inclusive
798  mp_uint_t n_args_max : 16; // inclusive
799  union {
802  } fun;
804 
806 qstr mp_obj_code_get_name(const byte *code_info);
807 
809 MP_DECLARE_CONST_FUN_OBJ_1(mp_identity_obj);
811 
812 // module
813 typedef struct _mp_obj_module_t {
818 // check if given module object is a package
819 bool mp_obj_is_package(mp_obj_t module);
820 
821 // staticmethod and classmethod types; defined here so we can make const versions
822 // this structure is used for instances of both staticmethod and classmethod
831 
832 // property
833 const mp_obj_t *mp_obj_property_get(mp_obj_t self_in);
834 
835 // sequence helpers
836 
837 // slice indexes resolved to particular sequence
838 typedef struct {
843 
844 void mp_seq_multiply(const void *items, size_t item_sz, size_t len, size_t times, void *dest);
845 #if MICROPY_PY_BUILTINS_SLICE
846 bool mp_seq_get_fast_slice_indexes(mp_uint_t len, mp_obj_t slice, mp_bound_slice_t *indexes);
847 #endif
848 #define mp_seq_copy(dest, src, len, item_t) memcpy(dest, src, len * sizeof(item_t))
849 #define mp_seq_cat(dest, src1, len1, src2, len2, item_t) { memcpy(dest, src1, (len1) * sizeof(item_t)); memcpy(dest + (len1), src2, (len2) * sizeof(item_t)); }
850 bool mp_seq_cmp_bytes(mp_uint_t op, const byte *data1, size_t len1, const byte *data2, size_t len2);
851 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);
852 mp_obj_t mp_seq_index_obj(const mp_obj_t *items, size_t len, size_t n_args, const mp_obj_t *args);
853 mp_obj_t mp_seq_count_obj(const mp_obj_t *items, size_t len, mp_obj_t value);
854 mp_obj_t mp_seq_extract_slice(size_t len, const mp_obj_t *seq, mp_bound_slice_t *indexes);
855 // Helper to clear stale pointers from allocated, but unused memory, to preclude GC problems
856 #define mp_seq_clear(start, len, alloc_len, item_sz) memset((byte*)(start) + (len) * (item_sz), 0, ((alloc_len) - (len)) * (item_sz))
857 #define mp_seq_replace_slice_no_grow(dest, dest_len, beg, end, slice, slice_len, item_sz) \
858  /*printf("memcpy(%p, %p, %d)\n", dest + beg, slice, slice_len * (item_sz));*/ \
859  memcpy(((char*)dest) + (beg) * (item_sz), slice, slice_len * (item_sz)); \
860  /*printf("memmove(%p, %p, %d)\n", dest + (beg + slice_len), dest + end, (dest_len - end) * (item_sz));*/ \
861  memmove(((char*)dest) + (beg + slice_len) * (item_sz), ((char*)dest) + (end) * (item_sz), (dest_len - end) * (item_sz));
862 
863 // Note: dest and slice regions may overlap
864 #define mp_seq_replace_slice_grow_inplace(dest, dest_len, beg, end, slice, slice_len, len_adj, item_sz) \
865  /*printf("memmove(%p, %p, %d)\n", dest + beg + len_adj, dest + beg, (dest_len - beg) * (item_sz));*/ \
866  memmove(((char*)dest) + (beg + slice_len) * (item_sz), ((char*)dest) + (end) * (item_sz), ((dest_len) + (len_adj) - ((beg) + (slice_len))) * (item_sz)); \
867  memmove(((char*)dest) + (beg) * (item_sz), slice, slice_len * (item_sz));
868 
869 #endif // MICROPY_INCLUDED_PY_OBJ_H
mp_obj_t(* mp_binary_op_fun_t)(mp_binary_op_t op, mp_obj_t, mp_obj_t)
Definition: obj.h:434
mp_obj_t mp_instance_cast_to_native_base(mp_const_obj_t self_in, mp_const_obj_t native_type)
Definition: objtype.c:1219
mp_obj_t mp_obj_new_cell(mp_obj_t obj)
Definition: objcell.c:66
mp_obj_t(* mp_make_new_fun_t)(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: obj.h:431
mp_map_t * mp_obj_dict_get_map(mp_obj_t self_in)
Definition: objdict.c:608
qstr mp_obj_str_get_qstr(mp_obj_t self_in)
Definition: objstr.c:2082
const mp_obj_type_t mp_type_reversed
void mp_obj_exception_clear_traceback(mp_obj_t self_in)
Definition: objexcept.c:478
const mp_obj_type_t mp_type_fun_bc
Definition: objfun.c:331
const mp_obj_type_t mp_type_fun_builtin_var
Definition: objfun.c:131
const struct _mp_obj_exception_t mp_const_MemoryError_obj
Definition: objexcept.c:47
mp_obj_t buf[3]
Definition: obj.h:423
intptr_t mp_int_t
Definition: mpconfigport.h:73
uintptr_t mp_uint_t
Definition: mpconfigport.h:74
bool mp_obj_is_exception_instance(mp_obj_t self_in)
Definition: objexcept.c:451
const mp_obj_type_t mp_type_KeyboardInterrupt
const mp_obj_type_t mp_type_set
Definition: misc.h:142
void mp_obj_get_array_fixed_n(mp_obj_t o, size_t len, mp_obj_t **items)
Definition: obj.c:362
mp_obj_t mp_obj_new_closure(mp_obj_t fun, size_t n_closed, const mp_obj_t *closed)
Definition: objclosure.c:90
mp_fun_1_t iternext
Definition: obj.h:521
mp_obj_t mp_obj_new_slice(mp_obj_t start, mp_obj_t stop, mp_obj_t step)
const mp_obj_type_t mp_type_ordereddict
const mp_obj_type_t mp_type_EOFError
qstr mp_obj_code_get_name(const byte *code_info)
Definition: objfun.c:141
mp_obj_t mp_obj_new_tuple(size_t n, const mp_obj_t *items)
Definition: objtuple.c:235
mp_obj_base_t base
Definition: objexcept.h:33
mp_obj_t mp_obj_len_maybe(mp_obj_t o_in)
Definition: obj.c:448
const mp_obj_type_t mp_type_SystemExit
const mp_obj_type_t mp_type_AssertionError
mp_obj_t(* mp_fun_kw_t)(size_t n, const mp_obj_t *, mp_map_t *)
Definition: obj.h:410
size_t used
Definition: obj.h:390
mp_uint_t stop
Definition: obj.h:840
const mp_obj_type_t mp_type_float
const mp_obj_type_t mp_type_bytearray
const mp_obj_type_t mp_type_ZeroDivisionError
mp_subscr_fun_t subscr
Definition: obj.h:512
size_t mp_obj_dict_len(mp_obj_t self_in)
Definition: objdict.c:590
mp_obj_t mp_obj_new_memoryview(byte typecode, size_t nitems, void *items)
mp_obj_t(* mp_fun_3_t)(mp_obj_t, mp_obj_t, mp_obj_t)
Definition: obj.h:406
const struct _mp_obj_bool_t mp_const_true_obj
Definition: objbool.c:87
def data
Definition: i18n.py:176
const void * parent
Definition: obj.h:533
mp_obj_t(* mp_getiter_fun_t)(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf)
Definition: obj.h:437
mp_int_t mp_obj_get_int(mp_const_obj_t arg)
Definition: obj.c:225
const mp_obj_type_t mp_type_memoryview
mp_make_new_fun_t make_new
Definition: obj.h:484
const mp_obj_type_t mp_type_TypeError
size_t len
Definition: objlist.h:34
mp_unary_op_fun_t unary_op
Definition: obj.h:491
const struct _mp_obj_str_t mp_const_empty_bytes_obj
Definition: objstr.c:1977
mp_obj_t mp_alloc_emergency_exception_buf(mp_obj_t size_in)
#define MP_OBJ_IS_TYPE(o, t)
Definition: obj.h:254
STATIC const uint8_t attr[]
Definition: unicode.c:51
void mp_obj_print_exception(const mp_print_t *print, mp_obj_t exc)
Definition: obj.c:81
mp_rom_obj_t key
Definition: obj.h:347
mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const char *fmt,...)
Definition: objexcept.c:380
mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type)
Definition: objexcept.c:329
mp_obj_t mp_obj_id(mp_obj_t o_in)
Definition: obj.c:414
union _mp_obj_fun_builtin_var_t::@20 fun
mp_uint_t(* read)(mp_obj_t obj, void *buf, mp_uint_t size, int *errcode)
Definition: obj.h:467
unsigned int size_t
Definition: stddef.h:7
bool mp_obj_is_callable(mp_obj_t o_in)
Definition: obj.c:141
const mp_obj_type_t mp_type_StopIteration
bool mp_seq_cmp_bytes(mp_uint_t op, const byte *data1, size_t len1, const byte *data2, size_t len2)
Definition: sequence.c:150
const mp_map_t mp_const_empty_map
Definition: map.c:38
#define MP_OBJ_SENTINEL
Definition: obj.h:75
const mp_obj_type_t mp_type_filter
struct _mp_obj_fun_builtin_var_t mp_obj_fun_builtin_var_t
mp_obj_t mp_obj_new_gen_wrap(mp_obj_t fun)
Definition: objgenerator.c:78
const mp_obj_type_t mp_type_NotImplementedError
#define MP_DECLARE_CONST_FUN_OBJ_1(obj_name)
Definition: obj.h:275
unsigned int uintptr_t
Definition: stdint.h:14
mp_obj_base_t base
Definition: obj.h:784
const mp_obj_type_t mp_type_Exception
mp_binary_op_fun_t binary_op
Definition: obj.h:492
mp_int_t(* get_buffer)(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags)
Definition: obj.h:458
const mp_obj_type_t mp_type_ViperTypeError
const mp_obj_type_t mp_type_super
Definition: objtype.c:1125
const mp_obj_type_t mp_type_ImportError
mp_obj_base_t base
Definition: obj.h:475
#define mp_const_true
Definition: obj.h:616
void mp_str_print_quoted(const mp_print_t *print, const byte *str_data, size_t str_len, bool is_bytes)
Definition: objstr.c:45
const mp_obj_type_t mp_type_bytes
Definition: objstr.c:1964
mp_obj_t mp_obj_new_list(size_t n, mp_obj_t *items)
Definition: objlist.c:470
size_t len
Definition: obj.h:447
mp_obj_t key
Definition: obj.h:342
const mp_obj_type_t mp_type_gen_instance
Definition: objgenerator.c:233
mp_call_fun_t call
Definition: obj.h:487
mp_obj_t(* mp_fun_0_t)(void)
Definition: obj.h:403
void(* mp_attr_fun_t)(mp_obj_t self_in, qstr attr, mp_obj_t *dest)
Definition: obj.h:435
mp_obj_base_t base
Definition: obj.h:814
mp_obj_t mp_obj_new_bytearray(size_t n, void *items)
mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args, const mp_obj_t *args)
Definition: objexcept.c:338
const mp_obj_type_t mp_type_LookupError
const mp_obj_type_t mp_type_TimeoutError
mp_unary_op_t
Definition: runtime0.h:45
mp_obj_t mp_obj_len(mp_obj_t o_in)
Definition: obj.c:433
mp_obj_t mp_seq_count_obj(const mp_obj_t *items, size_t len, mp_obj_t value)
Definition: sequence.c:266
size_t alloc
Definition: obj.h:361
mp_obj_t mp_obj_new_int_from_ll(long long val)
Definition: objint.c:332
size_t is_fixed
Definition: obj.h:358
mp_obj_base_t base
Definition: obj.h:765
mp_obj_dict_t * mp_obj_module_get_globals(mp_obj_t self_in)
Definition: objmodule.c:125
mp_obj_t mp_obj_new_int_from_ull(unsigned long long val)
Definition: objint.c:338
struct _mp_rom_map_elem_t mp_rom_map_elem_t
void mp_obj_tuple_del(mp_obj_t self_in)
Definition: objtuple.c:257
const void * protocol
Definition: obj.h:527
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags)
Definition: obj.c:524
mp_obj_t(* mp_fun_2_t)(mp_obj_t, mp_obj_t)
Definition: obj.h:405
mp_uint_t(* ioctl)(mp_obj_t obj, mp_uint_t request, uintptr_t arg, int *errcode)
Definition: obj.h:469
const mp_obj_type_t mp_type_array
mp_int_t mp_obj_int_get_truncated(mp_const_obj_t self_in)
Definition: objint.c:361
mp_obj_t mp_obj_new_dict(size_t n_args)
Definition: objdict.c:584
const mp_obj_type_t mp_type_NameError
mp_obj_t(* mp_fun_1_t)(mp_obj_t)
Definition: obj.h:404
struct _mp_buffer_info_t mp_buffer_info_t
const mp_obj_type_t mp_type_SyntaxError
bool mp_obj_is_subclass_fast(mp_const_obj_t object, mp_const_obj_t classinfo)
Definition: objtype.c:1143
#define mp_obj_is_float(o)
Definition: obj.h:745
void mp_map_init(mp_map_t *map, size_t n)
Definition: map.c:72
mp_uint_t n_args_min
Definition: obj.h:797
struct _mp_obj_iter_buf_t mp_obj_iter_buf_t
const struct _mp_obj_bool_t mp_const_false_obj
Definition: objbool.c:86
const mp_obj_type_t mp_type_stringio
mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg)
Definition: objlist.c:234
void mp_set_init(mp_set_t *set, size_t n)
mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, const char *msg)
Definition: objexcept.c:343
void mp_obj_dict_init(mp_obj_dict_t *dict, size_t n_args)
Definition: objdict.c:579
const mp_obj_type_t mp_type_complex
struct _mp_buffer_p_t mp_buffer_p_t
const mp_obj_type_t mp_type_StopAsyncIteration
mp_print_kind_t
Definition: obj.h:412
void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item)
const mp_obj_type_t mp_type_staticmethod
Definition: objtype.c:1241
mp_obj_t mp_set_remove_first(mp_set_t *set)
const mp_obj_type_t mp_type_fun_builtin_2
Definition: objfun.c:87
const mp_obj_type_t mp_type_polymorph_iter
Definition: objpolyiter.c:48
mp_obj_t mp_obj_new_fun_asm(size_t n_args, void *fun_data, mp_uint_t type_sig)
bool mp_obj_exception_match(mp_obj_t exc, mp_const_obj_t exc_type)
Definition: objexcept.c:458
void mp_map_clear(mp_map_t *map)
Definition: map.c:103
qstr mp_obj_fun_get_name(mp_const_obj_t fun)
Definition: objfun.c:154
void(* mp_print_fun_t)(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind)
Definition: obj.h:430
const char * mp_obj_str_get_data(mp_obj_t self_in, size_t *len)
Definition: objstr.c:2105
mp_obj_t(* mp_call_fun_t)(mp_obj_t fun, size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: obj.h:432
mp_obj_t * table
Definition: obj.h:391
void mp_obj_print(mp_obj_t o, mp_print_kind_t kind)
Definition: obj.c:76
uint64_t mp_const_obj_t
Definition: obj.h:40
mp_int_t step
Definition: obj.h:841
#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
const mp_obj_type_t mp_type_OSError
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
struct _mp_obj_dict_t mp_obj_dict_t
mp_obj_t * items
Definition: objlist.h:35
const mp_obj_type_t mp_type_frozenset
bool mp_obj_get_int_maybe(mp_const_obj_t arg, mp_int_t *value)
Definition: obj.c:258
void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values)
Definition: objexcept.c:537
unsigned long long uint64_t
Definition: stdint.h:7
mp_print_fun_t print
Definition: obj.h:481
void mp_init_emergency_exception_buf(void)
const mp_obj_type_t mp_type_range
Definition: objrange.c:192
void mp_map_free(mp_map_t *map)
void mp_obj_list_init(struct _mp_obj_list_t *o, size_t n)
Definition: objlist.c:456
mp_obj_t mp_obj_str_intern(mp_obj_t str)
Definition: objstr.c:2041
mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, mp_map_lookup_kind_t lookup_kind)
size_t qstr
Definition: qstr.h:48
void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items)
Definition: objlist.c:480
mp_const_obj_t mp_rom_obj_t
Definition: obj.h:239
struct _mp_stream_p_t mp_stream_p_t
mp_obj_t mp_obj_new_bytes(const byte *data, size_t len)
Definition: objstr.c:2046
const mp_obj_type_t mp_type_str
Definition: objstr.c:1950
mp_obj_t mp_obj_new_fun_viper(size_t n_args, void *fun_data, mp_uint_t type_sig)
mp_binary_op_t
Definition: runtime0.h:67
mp_obj_t value
Definition: obj.h:343
mp_obj_t mp_obj_new_set(size_t n_args, mp_obj_t *items)
struct _mp_rom_obj_static_class_method_t mp_rom_obj_static_class_method_t
void mp_obj_tuple_get(mp_obj_t self_in, size_t *len, mp_obj_t **items)
Definition: objtuple.c:250
mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value)
Definition: objint.c:343
const mp_obj_type_t mp_type_ValueError
mp_obj_t mp_obj_new_str(const char *data, size_t len, bool make_qstr_if_not_already)
Definition: objstr.c:2025
const mp_obj_type_t mp_type_MemoryError
mp_obj_t mp_identity_getiter(mp_obj_t self, mp_obj_iter_buf_t *iter_buf)
Definition: obj.c:507
const struct _mp_obj_singleton_t mp_const_notimplemented_obj
mp_obj_t mp_obj_new_int_from_str_len(const char **str, size_t len, bool neg, unsigned int base)
Definition: objint.c:326
struct _mp_obj_static_class_method_t mp_obj_static_class_method_t
const mp_obj_type_t mp_type_GeneratorExit
const struct _mp_obj_none_t mp_const_none_obj
Definition: objnone.c:51
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
_mp_map_lookup_kind_t
Definition: obj.h:366
const mp_obj_type_t mp_type_fun_builtin_0
Definition: objfun.c:59
uint64_t u64
Definition: sqliteInt.h:14
mp_obj_t mp_obj_dict_delete(mp_obj_t self_in, mp_obj_t key)
Definition: objdict.c:602
#define MP_OBJ_IS_INT(o)
Definition: obj.h:255
const mp_obj_type_t mp_type_object
Definition: objobject.c:74
void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block)
Definition: objexcept.c:485
void mp_map_init_fixed_table(mp_map_t *map, size_t n, const mp_obj_t *table)
Definition: map.c:86
Definition: obj.h:417
mp_obj_t mp_obj_new_int(mp_int_t value)
Definition: objint.c:353
struct _mp_map_elem_t mp_map_elem_t
mp_map_t * mp_map_new(size_t n)
mp_uint_t n_args_max
Definition: obj.h:798
mp_obj_dict_t * globals
Definition: obj.h:815
mp_obj_t mp_obj_dict_get(mp_obj_t self_in, mp_obj_t index)
Definition: objdict.c:164
Definition: obj.h:356
unsigned char byte
Definition: misc.h:37
mp_obj_t mp_obj_new_str_from_vstr(const mp_obj_type_t *type, vstr_t *vstr)
Definition: objstr.c:1998
mp_obj_t mp_obj_list_remove(mp_obj_t self_in, mp_obj_t value)
Definition: objlist.c:393
mp_obj_t mp_obj_new_bytearray_by_ref(size_t n, void *items)
const mp_obj_type_t mp_type_UnicodeError
void mp_map_dump(mp_map_t *map)
mp_obj_t(* mp_unary_op_fun_t)(mp_unary_op_t op, mp_obj_t)
Definition: obj.h:433
const mp_obj_type_t mp_type_type
Definition: objtype.c:969
const mp_obj_type_t mp_type_AttributeError
mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
Definition: objtype.c:979
mp_getiter_fun_t getiter
Definition: obj.h:517
const mp_obj_type_t mp_type_bool
Definition: obj.h:543
struct _mp_map_t mp_map_t
void start()
Definition: rt0.cpp:31
mp_buffer_p_t buffer_p
Definition: obj.h:524
const mp_obj_type_t mp_type_ArithmeticError
mp_int_t mp_obj_tuple_hash(mp_obj_t self_in)
const mp_obj_type_t mp_type_IndexError
mp_int_t mp_obj_get_int_truncated(mp_const_obj_t arg)
Definition: obj.c:247
enum _mp_map_lookup_kind_t mp_map_lookup_kind_t
void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj)
Definition: objcell.c:39
mp_uint_t(* write)(mp_obj_t obj, const void *buf, mp_uint_t size, int *errcode)
Definition: obj.h:468
mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value)
Definition: objdict.c:595
size_t alloc
Definition: obj.h:389
const struct _mp_obj_singleton_t mp_const_ellipsis_obj
Definition: objsingleton.c:52
const mp_obj_type_t mp_type_IndentationError
void mp_set_clear(mp_set_t *set)
const char * mp_obj_get_type_str(mp_const_obj_t o_in)
Definition: obj.c:55
mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in)
Definition: objint.c:365
bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags)
Definition: obj.c:512
size_t used
Definition: obj.h:360
const mp_obj_t * mp_obj_property_get(mp_obj_t self_in)
const mp_obj_type_t *type MICROPY_OBJ_BASE_ALIGNMENT
Definition: obj.h:53
Definition: obj.h:388
mp_obj_t mp_obj_new_bound_meth(mp_obj_t meth, mp_obj_t self)
Definition: objboundmeth.c:103
mp_obj_t(* mp_fun_var_t)(size_t n, const mp_obj_t *)
Definition: obj.h:407
struct _mp_set_t mp_set_t
mp_attr_fun_t attr
Definition: obj.h:505
mp_obj_base_t base
Definition: obj.h:422
bool mp_obj_is_true(mp_obj_t arg)
Definition: obj.c:108
mp_uint_t is_text
Definition: obj.h:470
const mp_obj_type_t mp_type_map
Definition: objmap.c:67
const char * mp_obj_str_get_str(mp_obj_t self_in)
Definition: objstr.c:2095
mp_obj_t mp_obj_list_sort(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs)
Definition: objlist.c:315
mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in)
Definition: objexcept.c:183
mp_obj_t mp_obj_new_fun_native(mp_obj_t def_args_in, mp_obj_t def_kw_args, const void *fun_data, const mp_uint_t *const_table)
void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value)
Definition: objlist.c:493
bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2)
Definition: objstr.c:2050
const mp_obj_type_t mp_type_slice
struct _mp_obj_module_t mp_obj_module_t
Definition: obj.h:413
const mp_obj_type_t mp_type_tuple
Definition: objtuple.c:220
mp_obj_t mp_generic_unary_op(mp_unary_op_t op, mp_obj_t o_in)
Definition: obj.c:530
const mp_obj_type_t mp_type_dict
Definition: objdict.c:552
mp_obj_t mp_identity(mp_obj_t self)
Definition: obj.c:502
const mp_obj_type_t mp_type_module
Definition: objmodule.c:94
const mp_obj_type_t mp_type_NoneType
Definition: objnone.c:44
mp_uint_t start
Definition: obj.h:839
void mp_obj_list_set_len(mp_obj_t self_in, size_t len)
Definition: objlist.c:486
void mp_obj_slice_get(mp_obj_t self_in, mp_obj_t *start, mp_obj_t *stop, mp_obj_t *step)
mp_fun_kw_t kw
Definition: obj.h:801
bool mp_obj_is_exception_type(mp_obj_t self_in)
Definition: objexcept.c:439
size_t all_keys_are_qstrs
Definition: obj.h:357
void mp_map_deinit(mp_map_t *map)
Definition: map.c:96
void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items)
Definition: obj.c:346
const mp_obj_type_t mp_type_classmethod
Definition: objtype.c:1247
int typecode
Definition: obj.h:448
const mp_obj_type_t mp_type_bytesio
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val)
Definition: obj.c:467
qstr name
Definition: obj.h:478
mp_fun_var_t var
Definition: obj.h:800
void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind)
Definition: obj.c:59
mp_obj_t mp_obj_exception_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
Definition: objexcept.c:133
mp_obj_t mp_obj_new_getitem_iter(mp_obj_t *args, mp_obj_iter_buf_t *iter_buf)
bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2)
Definition: obj.c:162
mp_map_t map
Definition: obj.h:766
uint32_t u32
Definition: sqliteInt.h:16
uint64_t mp_obj_t
Definition: obj.h:39
mp_obj_t(* mp_subscr_fun_t)(mp_obj_t self_in, mp_obj_t index, mp_obj_t value)
Definition: obj.h:436
mp_map_elem_t * table
Definition: obj.h:362
const mp_obj_type_t mp_type_fun_builtin_3
Definition: objfun.c:101
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
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
const mp_obj_type_t mp_type_int
Definition: obj.h:544
const mp_obj_type_t mp_type_fun_builtin_1
Definition: objfun.c:73
Definition: obj.h:415
const mp_obj_type_t mp_type_property
mp_rom_obj_t value
Definition: obj.h:348
const mp_obj_type_t mp_type_list
Definition: objlist.c:444
struct _mp_obj_fun_builtin_fixed_t mp_obj_fun_builtin_fixed_t
const mp_obj_type_t mp_type_zip
Definition: objzip.c:70
mp_obj_t mp_seq_extract_slice(size_t len, const mp_obj_t *seq, mp_bound_slice_t *indexes)
Definition: sequence.c:126
const mp_obj_type_t mp_type_KeyError
size_t is_ordered
Definition: obj.h:359
mp_obj_base_t base
Definition: obj.h:824
union _mp_obj_fun_builtin_fixed_t::@19 fun
const mp_obj_type_t mp_type_BaseException
Definition: objexcept.c:229
void * buf
Definition: obj.h:446
const struct _mp_obj_tuple_t mp_const_empty_tuple_obj
Definition: objtuple.c:233
mp_obj_t mp_obj_cell_get(mp_obj_t self_in)
Definition: objcell.c:34
const mp_obj_type_t mp_type_OverflowError
mp_obj_t mp_obj_new_module(qstr module_name)
Definition: objmodule.c:101
bool mp_obj_is_package(mp_obj_t module)
Definition: builtinimport.c:49
mp_obj_t mp_obj_new_fun_bc(mp_obj_t def_args, mp_obj_t def_kw_args, const byte *code, const mp_uint_t *const_table)
Definition: objfun.c:344
#define mp_const_false
Definition: obj.h:615
struct _mp_obj_dict_t * locals_dict
Definition: obj.h:536
mp_obj_base_t base
Definition: obj.h:795
const mp_obj_type_t mp_type_RuntimeError
mp_obj_type_t * mp_obj_get_type(mp_const_obj_t o_in)
Definition: obj.c:40
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
const mp_obj_type_t mp_type_enumerate
const struct _mp_obj_exception_t mp_const_GeneratorExit_obj
Definition: objexcept.c:97