LCOV - code coverage report
Current view: top level - py - obj.h (source / functions) Hit Total Coverage
Test: unix_coverage_v1.22.0-335-g9c7f0659e.info Lines: 40 40 100.0 %
Date: 2024-04-24 08:31:58 Functions: 5 9 55.6 %
Branches: 158 176 89.8 %

           Branch data     Line data    Source code
       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 <assert.h>
      30                 :            : 
      31                 :            : #include "py/mpconfig.h"
      32                 :            : #include "py/misc.h"
      33                 :            : #include "py/qstr.h"
      34                 :            : #include "py/mpprint.h"
      35                 :            : #include "py/runtime0.h"
      36                 :            : 
      37                 :            : // This is the definition of the opaque MicroPython object type.
      38                 :            : // All concrete objects have an encoding within this type and the
      39                 :            : // particular encoding is specified by MICROPY_OBJ_REPR.
      40                 :            : #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D
      41                 :            : typedef uint64_t mp_obj_t;
      42                 :            : typedef uint64_t mp_const_obj_t;
      43                 :            : #else
      44                 :            : typedef void *mp_obj_t;
      45                 :            : typedef const void *mp_const_obj_t;
      46                 :            : #endif
      47                 :            : 
      48                 :            : // This mp_obj_type_t struct is a concrete MicroPython object which holds info
      49                 :            : // about a type.  See below for actual definition of the struct.
      50                 :            : typedef struct _mp_obj_type_t mp_obj_type_t;
      51                 :            : 
      52                 :            : // Anything that wants to be a concrete MicroPython object must have mp_obj_base_t
      53                 :            : // as its first member (small ints, qstr objs and inline floats are not concrete).
      54                 :            : struct _mp_obj_base_t {
      55                 :            :     const mp_obj_type_t *type MICROPY_OBJ_BASE_ALIGNMENT;
      56                 :            : };
      57                 :            : typedef struct _mp_obj_base_t mp_obj_base_t;
      58                 :            : 
      59                 :            : // These fake objects are used to indicate certain things in arguments or return
      60                 :            : // values, and should only be used when explicitly allowed.
      61                 :            : //
      62                 :            : //  - MP_OBJ_NULL : used to indicate the absence of an object, or unsupported operation.
      63                 :            : //  - MP_OBJ_STOP_ITERATION : used instead of throwing a StopIteration, for efficiency.
      64                 :            : //  - MP_OBJ_SENTINEL : used for various internal purposes where one needs
      65                 :            : //    an object which is unique from all other objects, including MP_OBJ_NULL.
      66                 :            : //
      67                 :            : // For debugging purposes they are all different.  For non-debug mode, we alias
      68                 :            : // as many as we can to MP_OBJ_NULL because it's cheaper to load/compare 0.
      69                 :            : 
      70                 :            : #if MICROPY_DEBUG_MP_OBJ_SENTINELS
      71                 :            : #define MP_OBJ_NULL             (MP_OBJ_FROM_PTR((void *)0))
      72                 :            : #define MP_OBJ_STOP_ITERATION   (MP_OBJ_FROM_PTR((void *)4))
      73                 :            : #define MP_OBJ_SENTINEL         (MP_OBJ_FROM_PTR((void *)8))
      74                 :            : #else
      75                 :            : #define MP_OBJ_NULL             (MP_OBJ_FROM_PTR((void *)0))
      76                 :            : #define MP_OBJ_STOP_ITERATION   (MP_OBJ_FROM_PTR((void *)0))
      77                 :            : #define MP_OBJ_SENTINEL         (MP_OBJ_FROM_PTR((void *)4))
      78                 :            : #endif
      79                 :            : 
      80                 :            : // These macros/inline functions operate on objects and depend on the
      81                 :            : // particular object representation.  They are used to query, pack and
      82                 :            : // unpack small ints, qstrs and full object pointers.
      83                 :            : 
      84                 :            : #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A
      85                 :            : 
      86                 :  161229261 : static inline bool mp_obj_is_small_int(mp_const_obj_t o) {
      87   [ +  +  +  +  :   98404257 :     return (((mp_int_t)(o)) & 1) != 0;
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
                      + ]
      88                 :            : }
      89                 :            : #define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1)
      90                 :            : #define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 1) | 1))
      91                 :            : 
      92                 :   12952240 : static inline bool mp_obj_is_qstr(mp_const_obj_t o) {
      93   [ +  +  +  +  :   12854100 :     return (((mp_int_t)(o)) & 7) == 2;
          +  +  +  +  +  
          +  +  +  +  +  
          -  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          -  +  +  +  +  
          +  +  +  +  +  
          -  +  -  +  -  
                      + ]
      94                 :            : }
      95                 :            : #define MP_OBJ_QSTR_VALUE(o) (((mp_uint_t)(o)) >> 3)
      96                 :            : #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 3) | 2))
      97                 :            : 
      98                 :            : static inline bool mp_obj_is_immediate_obj(mp_const_obj_t o) {
      99                 :            :     return (((mp_int_t)(o)) & 7) == 6;
     100                 :            : }
     101                 :            : #define MP_OBJ_IMMEDIATE_OBJ_VALUE(o) (((mp_uint_t)(o)) >> 3)
     102                 :            : #define MP_OBJ_NEW_IMMEDIATE_OBJ(val) ((mp_obj_t)(((val) << 3) | 6))
     103                 :            : 
     104                 :            : #if MICROPY_PY_BUILTINS_FLOAT
     105                 :            : #define mp_const_float_e MP_ROM_PTR(&mp_const_float_e_obj)
     106                 :            : #define mp_const_float_pi MP_ROM_PTR(&mp_const_float_pi_obj)
     107                 :            : #if MICROPY_PY_MATH_CONSTANTS
     108                 :            : #define mp_const_float_tau MP_ROM_PTR(&mp_const_float_tau_obj)
     109                 :            : #define mp_const_float_inf MP_ROM_PTR(&mp_const_float_inf_obj)
     110                 :            : #define mp_const_float_nan MP_ROM_PTR(&mp_const_float_nan_obj)
     111                 :            : #endif
     112                 :            : extern const struct _mp_obj_float_t mp_const_float_e_obj;
     113                 :            : extern const struct _mp_obj_float_t mp_const_float_pi_obj;
     114                 :            : #if MICROPY_PY_MATH_CONSTANTS
     115                 :            : extern const struct _mp_obj_float_t mp_const_float_tau_obj;
     116                 :            : extern const struct _mp_obj_float_t mp_const_float_inf_obj;
     117                 :            : extern const struct _mp_obj_float_t mp_const_float_nan_obj;
     118                 :            : #endif
     119                 :            : 
     120                 :            : #define mp_obj_is_float(o) mp_obj_is_type((o), &mp_type_float)
     121                 :            : mp_float_t mp_obj_float_get(mp_obj_t self_in);
     122                 :            : mp_obj_t mp_obj_new_float(mp_float_t value);
     123                 :            : #endif
     124                 :            : 
     125                 :   83962145 : static inline bool mp_obj_is_obj(mp_const_obj_t o) {
     126   [ +  +  +  +  :   83873963 :     return (((mp_int_t)(o)) & 3) == 0;
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  +  +  
          +  +  +  -  +  
          -  +  +  +  -  
             +  -  +  - ]
     127                 :            : }
     128                 :            : 
     129                 :            : #elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_B
     130                 :            : 
     131                 :            : static inline bool mp_obj_is_small_int(mp_const_obj_t o) {
     132                 :            :     return (((mp_int_t)(o)) & 3) == 1;
     133                 :            : }
     134                 :            : #define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 2)
     135                 :            : #define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 2) | 1))
     136                 :            : 
     137                 :            : static inline bool mp_obj_is_qstr(mp_const_obj_t o) {
     138                 :            :     return (((mp_int_t)(o)) & 7) == 3;
     139                 :            : }
     140                 :            : #define MP_OBJ_QSTR_VALUE(o) (((mp_uint_t)(o)) >> 3)
     141                 :            : #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 3) | 3))
     142                 :            : 
     143                 :            : static inline bool mp_obj_is_immediate_obj(mp_const_obj_t o) {
     144                 :            :     return (((mp_int_t)(o)) & 7) == 7;
     145                 :            : }
     146                 :            : #define MP_OBJ_IMMEDIATE_OBJ_VALUE(o) (((mp_uint_t)(o)) >> 3)
     147                 :            : #define MP_OBJ_NEW_IMMEDIATE_OBJ(val) ((mp_obj_t)(((val) << 3) | 7))
     148                 :            : 
     149                 :            : #if MICROPY_PY_BUILTINS_FLOAT
     150                 :            : #define mp_const_float_e MP_ROM_PTR(&mp_const_float_e_obj)
     151                 :            : #define mp_const_float_pi MP_ROM_PTR(&mp_const_float_pi_obj)
     152                 :            : #if MICROPY_PY_MATH_CONSTANTS
     153                 :            : #define mp_const_float_tau MP_ROM_PTR(&mp_const_float_tau_obj)
     154                 :            : #define mp_const_float_inf MP_ROM_PTR(&mp_const_float_inf_obj)
     155                 :            : #define mp_const_float_nan MP_ROM_PTR(&mp_const_float_nan_obj)
     156                 :            : #endif
     157                 :            : extern const struct _mp_obj_float_t mp_const_float_e_obj;
     158                 :            : extern const struct _mp_obj_float_t mp_const_float_pi_obj;
     159                 :            : #if MICROPY_PY_MATH_CONSTANTS
     160                 :            : extern const struct _mp_obj_float_t mp_const_float_tau_obj;
     161                 :            : extern const struct _mp_obj_float_t mp_const_float_inf_obj;
     162                 :            : extern const struct _mp_obj_float_t mp_const_float_nan_obj;
     163                 :            : #endif
     164                 :            : 
     165                 :            : #define mp_obj_is_float(o) mp_obj_is_type((o), &mp_type_float)
     166                 :            : mp_float_t mp_obj_float_get(mp_obj_t self_in);
     167                 :            : mp_obj_t mp_obj_new_float(mp_float_t value);
     168                 :            : #endif
     169                 :            : 
     170                 :            : static inline bool mp_obj_is_obj(mp_const_obj_t o) {
     171                 :            :     return (((mp_int_t)(o)) & 1) == 0;
     172                 :            : }
     173                 :            : 
     174                 :            : #elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C
     175                 :            : 
     176                 :            : #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_NONE
     177                 :            : #error "MICROPY_OBJ_REPR_C requires float to be enabled."
     178                 :            : #endif
     179                 :            : 
     180                 :            : static inline bool mp_obj_is_small_int(mp_const_obj_t o) {
     181                 :            :     return (((mp_int_t)(o)) & 1) != 0;
     182                 :            : }
     183                 :            : #define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1)
     184                 :            : #define MP_OBJ_NEW_SMALL_INT(small_int) ((mp_obj_t)((((mp_uint_t)(small_int)) << 1) | 1))
     185                 :            : 
     186                 :            : #if MICROPY_PY_BUILTINS_FLOAT
     187                 :            : #define mp_const_float_e MP_ROM_PTR((mp_obj_t)(((0x402df854 & ~3) | 2) + 0x80800000))
     188                 :            : #define mp_const_float_pi MP_ROM_PTR((mp_obj_t)(((0x40490fdb & ~3) | 2) + 0x80800000))
     189                 :            : #if MICROPY_PY_MATH_CONSTANTS
     190                 :            : #define mp_const_float_tau MP_ROM_PTR((mp_obj_t)(((0x40c90fdb & ~3) | 2) + 0x80800000))
     191                 :            : #define mp_const_float_inf MP_ROM_PTR((mp_obj_t)(((0x7f800000 & ~3) | 2) + 0x80800000))
     192                 :            : #define mp_const_float_nan MP_ROM_PTR((mp_obj_t)(((0xffc00000 & ~3) | 2) + 0x80800000))
     193                 :            : #endif
     194                 :            : 
     195                 :            : static inline bool mp_obj_is_float(mp_const_obj_t o) {
     196                 :            :     // Ensure that 32-bit arch can only use single precision.
     197                 :            :     MP_STATIC_ASSERT(sizeof(mp_float_t) <= sizeof(mp_obj_t));
     198                 :            : 
     199                 :            :     return (((mp_uint_t)(o)) & 3) == 2 && (((mp_uint_t)(o)) & 0xff800007) != 0x00000006;
     200                 :            : }
     201                 :            : static inline mp_float_t mp_obj_float_get(mp_const_obj_t o) {
     202                 :            :     union {
     203                 :            :         mp_float_t f;
     204                 :            :         mp_uint_t u;
     205                 :            :     } num = {.u = ((mp_uint_t)o - 0x80800000) & ~3};
     206                 :            :     return num.f;
     207                 :            : }
     208                 :            : static inline mp_obj_t mp_obj_new_float(mp_float_t f) {
     209                 :            :     union {
     210                 :            :         mp_float_t f;
     211                 :            :         mp_uint_t u;
     212                 :            :     } num = {.f = f};
     213                 :            :     return (mp_obj_t)(((num.u & ~0x3) | 2) + 0x80800000);
     214                 :            : }
     215                 :            : #endif
     216                 :            : 
     217                 :            : static inline bool mp_obj_is_qstr(mp_const_obj_t o) {
     218                 :            :     return (((mp_uint_t)(o)) & 0xff80000f) == 0x00000006;
     219                 :            : }
     220                 :            : #define MP_OBJ_QSTR_VALUE(o) (((mp_uint_t)(o)) >> 4)
     221                 :            : #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)((((mp_uint_t)(qst)) << 4) | 0x00000006))
     222                 :            : 
     223                 :            : static inline bool mp_obj_is_immediate_obj(mp_const_obj_t o) {
     224                 :            :     return (((mp_uint_t)(o)) & 0xff80000f) == 0x0000000e;
     225                 :            : }
     226                 :            : #define MP_OBJ_IMMEDIATE_OBJ_VALUE(o) (((mp_uint_t)(o)) >> 4)
     227                 :            : #define MP_OBJ_NEW_IMMEDIATE_OBJ(val) ((mp_obj_t)(((val) << 4) | 0xe))
     228                 :            : 
     229                 :            : static inline bool mp_obj_is_obj(mp_const_obj_t o) {
     230                 :            :     return (((mp_int_t)(o)) & 3) == 0;
     231                 :            : }
     232                 :            : 
     233                 :            : #elif MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_D
     234                 :            : 
     235                 :            : static inline bool mp_obj_is_small_int(mp_const_obj_t o) {
     236                 :            :     return (((uint64_t)(o)) & 0xffff000000000000) == 0x0001000000000000;
     237                 :            : }
     238                 :            : #define MP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)((o) << 16)) >> 17)
     239                 :            : #define MP_OBJ_NEW_SMALL_INT(small_int) (((((uint64_t)(small_int)) & 0x7fffffffffff) << 1) | 0x0001000000000001)
     240                 :            : 
     241                 :            : static inline bool mp_obj_is_qstr(mp_const_obj_t o) {
     242                 :            :     return (((uint64_t)(o)) & 0xffff000000000000) == 0x0002000000000000;
     243                 :            : }
     244                 :            : #define MP_OBJ_QSTR_VALUE(o) ((((uint32_t)(o)) >> 1) & 0xffffffff)
     245                 :            : #define MP_OBJ_NEW_QSTR(qst) ((mp_obj_t)(((uint64_t)(((uint32_t)(qst)) << 1)) | 0x0002000000000001))
     246                 :            : 
     247                 :            : static inline bool mp_obj_is_immediate_obj(mp_const_obj_t o) {
     248                 :            :     return (((uint64_t)(o)) & 0xffff000000000000) == 0x0003000000000000;
     249                 :            : }
     250                 :            : #define MP_OBJ_IMMEDIATE_OBJ_VALUE(o) ((((uint32_t)(o)) >> 46) & 3)
     251                 :            : #define MP_OBJ_NEW_IMMEDIATE_OBJ(val) (((uint64_t)(val) << 46) | 0x0003000000000000)
     252                 :            : 
     253                 :            : #if MICROPY_PY_BUILTINS_FLOAT
     254                 :            : 
     255                 :            : #if MICROPY_FLOAT_IMPL != MICROPY_FLOAT_IMPL_DOUBLE
     256                 :            : #error MICROPY_OBJ_REPR_D requires MICROPY_FLOAT_IMPL_DOUBLE
     257                 :            : #endif
     258                 :            : 
     259                 :            : #define mp_const_float_e {((mp_obj_t)((uint64_t)0x4005bf0a8b145769 + 0x8004000000000000))}
     260                 :            : #define mp_const_float_pi {((mp_obj_t)((uint64_t)0x400921fb54442d18 + 0x8004000000000000))}
     261                 :            : #if MICROPY_PY_MATH_CONSTANTS
     262                 :            : #define mp_const_float_tau {((mp_obj_t)((uint64_t)0x401921fb54442d18 + 0x8004000000000000))}
     263                 :            : #define mp_const_float_inf {((mp_obj_t)((uint64_t)0x7ff0000000000000 + 0x8004000000000000))}
     264                 :            : #define mp_const_float_nan {((mp_obj_t)((uint64_t)0xfff8000000000000 + 0x8004000000000000))}
     265                 :            : #endif
     266                 :            : 
     267                 :            : static inline bool mp_obj_is_float(mp_const_obj_t o) {
     268                 :            :     return ((uint64_t)(o) & 0xfffc000000000000) != 0;
     269                 :            : }
     270                 :            : static inline mp_float_t mp_obj_float_get(mp_const_obj_t o) {
     271                 :            :     union {
     272                 :            :         mp_float_t f;
     273                 :            :         uint64_t r;
     274                 :            :     } num = {.r = o - 0x8004000000000000};
     275                 :            :     return num.f;
     276                 :            : }
     277                 :            : static inline mp_obj_t mp_obj_new_float(mp_float_t f) {
     278                 :            :     union {
     279                 :            :         mp_float_t f;
     280                 :            :         uint64_t r;
     281                 :            :     } num = {.f = f};
     282                 :            :     return num.r + 0x8004000000000000;
     283                 :            : }
     284                 :            : #endif
     285                 :            : 
     286                 :            : static inline bool mp_obj_is_obj(mp_const_obj_t o) {
     287                 :            :     return (((uint64_t)(o)) & 0xffff000000000000) == 0x0000000000000000;
     288                 :            : }
     289                 :            : #define MP_OBJ_TO_PTR(o) ((void *)(uintptr_t)(o))
     290                 :            : #define MP_OBJ_FROM_PTR(p) ((mp_obj_t)((uintptr_t)(p)))
     291                 :            : 
     292                 :            : // rom object storage needs special handling to widen 32-bit pointer to 64-bits
     293                 :            : typedef union _mp_rom_obj_t {
     294                 :            :     uint64_t u64;
     295                 :            :     struct {
     296                 :            :         const void *lo, *hi;
     297                 :            :     } u32;
     298                 :            : } mp_rom_obj_t;
     299                 :            : #define MP_ROM_INT(i) {MP_OBJ_NEW_SMALL_INT(i)}
     300                 :            : #define MP_ROM_QSTR(q) {MP_OBJ_NEW_QSTR(q)}
     301                 :            : #if MP_ENDIANNESS_LITTLE
     302                 :            : #define MP_ROM_PTR(p) {.u32 = {.lo = (p), .hi = NULL}}
     303                 :            : #else
     304                 :            : #define MP_ROM_PTR(p) {.u32 = {.lo = NULL, .hi = (p)}}
     305                 :            : #endif
     306                 :            : 
     307                 :            : #endif
     308                 :            : 
     309                 :            : // Macros to convert between mp_obj_t and concrete object types.
     310                 :            : // These are identity operations in MicroPython, but ability to override
     311                 :            : // these operations are provided to experiment with other methods of
     312                 :            : // object representation and memory management.
     313                 :            : 
     314                 :            : // Cast mp_obj_t to object pointer
     315                 :            : #ifndef MP_OBJ_TO_PTR
     316                 :            : #define MP_OBJ_TO_PTR(o) ((void *)(o))
     317                 :            : #endif
     318                 :            : 
     319                 :            : // Cast object pointer to mp_obj_t
     320                 :            : #ifndef MP_OBJ_FROM_PTR
     321                 :            : #define MP_OBJ_FROM_PTR(p) ((mp_obj_t)(p))
     322                 :            : #endif
     323                 :            : 
     324                 :            : // Macros to create objects that are stored in ROM.
     325                 :            : 
     326                 :            : #ifndef MP_ROM_NONE
     327                 :            : #if MICROPY_OBJ_IMMEDIATE_OBJS
     328                 :            : #define MP_ROM_NONE mp_const_none
     329                 :            : #else
     330                 :            : #define MP_ROM_NONE MP_ROM_PTR(&mp_const_none_obj)
     331                 :            : #endif
     332                 :            : #endif
     333                 :            : 
     334                 :            : #ifndef MP_ROM_FALSE
     335                 :            : #if MICROPY_OBJ_IMMEDIATE_OBJS
     336                 :            : #define MP_ROM_FALSE mp_const_false
     337                 :            : #define MP_ROM_TRUE mp_const_true
     338                 :            : #else
     339                 :            : #define MP_ROM_FALSE MP_ROM_PTR(&mp_const_false_obj)
     340                 :            : #define MP_ROM_TRUE MP_ROM_PTR(&mp_const_true_obj)
     341                 :            : #endif
     342                 :            : #endif
     343                 :            : 
     344                 :            : #ifndef MP_ROM_INT
     345                 :            : typedef mp_const_obj_t mp_rom_obj_t;
     346                 :            : #define MP_ROM_INT(i) MP_OBJ_NEW_SMALL_INT(i)
     347                 :            : #define MP_ROM_QSTR(q) MP_OBJ_NEW_QSTR(q)
     348                 :            : #define MP_ROM_PTR(p) (p)
     349                 :            : /* for testing
     350                 :            : typedef struct _mp_rom_obj_t { mp_const_obj_t o; } mp_rom_obj_t;
     351                 :            : #define MP_ROM_INT(i) {MP_OBJ_NEW_SMALL_INT(i)}
     352                 :            : #define MP_ROM_QSTR(q) {MP_OBJ_NEW_QSTR(q)}
     353                 :            : #define MP_ROM_PTR(p) {.o = p}
     354                 :            : */
     355                 :            : #endif
     356                 :            : 
     357                 :            : // These macros are used to declare and define constant function objects
     358                 :            : // You can put "static" in front of the definitions to make them local
     359                 :            : 
     360                 :            : #define MP_DECLARE_CONST_FUN_OBJ_0(obj_name) extern const mp_obj_fun_builtin_fixed_t obj_name
     361                 :            : #define MP_DECLARE_CONST_FUN_OBJ_1(obj_name) extern const mp_obj_fun_builtin_fixed_t obj_name
     362                 :            : #define MP_DECLARE_CONST_FUN_OBJ_2(obj_name) extern const mp_obj_fun_builtin_fixed_t obj_name
     363                 :            : #define MP_DECLARE_CONST_FUN_OBJ_3(obj_name) extern const mp_obj_fun_builtin_fixed_t obj_name
     364                 :            : #define MP_DECLARE_CONST_FUN_OBJ_VAR(obj_name) extern const mp_obj_fun_builtin_var_t obj_name
     365                 :            : #define MP_DECLARE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name) extern const mp_obj_fun_builtin_var_t obj_name
     366                 :            : #define MP_DECLARE_CONST_FUN_OBJ_KW(obj_name) extern const mp_obj_fun_builtin_var_t obj_name
     367                 :            : 
     368                 :            : #define MP_OBJ_FUN_ARGS_MAX (0xffff) // to set maximum value in n_args_max below
     369                 :            : #define MP_OBJ_FUN_MAKE_SIG(n_args_min, n_args_max, takes_kw) ((uint32_t)((((uint32_t)(n_args_min)) << 17) | (((uint32_t)(n_args_max)) << 1) | ((takes_kw) ? 1 : 0)))
     370                 :            : 
     371                 :            : #define MP_DEFINE_CONST_FUN_OBJ_0(obj_name, fun_name) \
     372                 :            :     const mp_obj_fun_builtin_fixed_t obj_name = \
     373                 :            :     {{&mp_type_fun_builtin_0}, .fun._0 = fun_name}
     374                 :            : #define MP_DEFINE_CONST_FUN_OBJ_1(obj_name, fun_name) \
     375                 :            :     const mp_obj_fun_builtin_fixed_t obj_name = \
     376                 :            :     {{&mp_type_fun_builtin_1}, .fun._1 = fun_name}
     377                 :            : #define MP_DEFINE_CONST_FUN_OBJ_2(obj_name, fun_name) \
     378                 :            :     const mp_obj_fun_builtin_fixed_t obj_name = \
     379                 :            :     {{&mp_type_fun_builtin_2}, .fun._2 = fun_name}
     380                 :            : #define MP_DEFINE_CONST_FUN_OBJ_3(obj_name, fun_name) \
     381                 :            :     const mp_obj_fun_builtin_fixed_t obj_name = \
     382                 :            :     {{&mp_type_fun_builtin_3}, .fun._3 = fun_name}
     383                 :            : #define MP_DEFINE_CONST_FUN_OBJ_VAR(obj_name, n_args_min, fun_name) \
     384                 :            :     const mp_obj_fun_builtin_var_t obj_name = \
     385                 :            :     {{&mp_type_fun_builtin_var}, MP_OBJ_FUN_MAKE_SIG(n_args_min, MP_OBJ_FUN_ARGS_MAX, false), .fun.var = fun_name}
     386                 :            : #define MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(obj_name, n_args_min, n_args_max, fun_name) \
     387                 :            :     const mp_obj_fun_builtin_var_t obj_name = \
     388                 :            :     {{&mp_type_fun_builtin_var}, MP_OBJ_FUN_MAKE_SIG(n_args_min, n_args_max, false), .fun.var = fun_name}
     389                 :            : #define MP_DEFINE_CONST_FUN_OBJ_KW(obj_name, n_args_min, fun_name) \
     390                 :            :     const mp_obj_fun_builtin_var_t obj_name = \
     391                 :            :     {{&mp_type_fun_builtin_var}, MP_OBJ_FUN_MAKE_SIG(n_args_min, MP_OBJ_FUN_ARGS_MAX, true), .fun.kw = fun_name}
     392                 :            : 
     393                 :            : // These macros are used to define constant map/dict objects
     394                 :            : // You can put "static" in front of the definition to make it local
     395                 :            : 
     396                 :            : #define MP_DEFINE_CONST_MAP(map_name, table_name) \
     397                 :            :     const mp_map_t map_name = { \
     398                 :            :         .all_keys_are_qstrs = 1, \
     399                 :            :         .is_fixed = 1, \
     400                 :            :         .is_ordered = 1, \
     401                 :            :         .used = MP_ARRAY_SIZE(table_name), \
     402                 :            :         .alloc = MP_ARRAY_SIZE(table_name), \
     403                 :            :         .table = (mp_map_elem_t *)(mp_rom_map_elem_t *)table_name, \
     404                 :            :     }
     405                 :            : 
     406                 :            : #define MP_DEFINE_CONST_DICT_WITH_SIZE(dict_name, table_name, n) \
     407                 :            :     const mp_obj_dict_t dict_name = { \
     408                 :            :         .base = {&mp_type_dict}, \
     409                 :            :         .map = { \
     410                 :            :             .all_keys_are_qstrs = 1, \
     411                 :            :             .is_fixed = 1, \
     412                 :            :             .is_ordered = 1, \
     413                 :            :             .used = n, \
     414                 :            :             .alloc = n, \
     415                 :            :             .table = (mp_map_elem_t *)(mp_rom_map_elem_t *)table_name, \
     416                 :            :         }, \
     417                 :            :     }
     418                 :            : 
     419                 :            : #define MP_DEFINE_CONST_DICT(dict_name, table_name) MP_DEFINE_CONST_DICT_WITH_SIZE(dict_name, table_name, MP_ARRAY_SIZE(table_name))
     420                 :            : 
     421                 :            : // These macros are used to declare and define constant staticmethod and classmethod objects
     422                 :            : // You can put "static" in front of the definitions to make them local
     423                 :            : 
     424                 :            : #define MP_DECLARE_CONST_STATICMETHOD_OBJ(obj_name) extern const mp_rom_obj_static_class_method_t obj_name
     425                 :            : #define MP_DECLARE_CONST_CLASSMETHOD_OBJ(obj_name) extern const mp_rom_obj_static_class_method_t obj_name
     426                 :            : 
     427                 :            : #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}
     428                 :            : #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}
     429                 :            : 
     430                 :            : #ifndef NO_QSTR
     431                 :            : 
     432                 :            : // Declare a module as a builtin, processed by makemoduledefs.py
     433                 :            : // param module_name: MP_QSTR_<module name>
     434                 :            : // param obj_module: mp_obj_module_t instance
     435                 :            : #define MP_REGISTER_MODULE(module_name, obj_module)
     436                 :            : 
     437                 :            : // As above, but allow this module to be extended from the filesystem.
     438                 :            : #define MP_REGISTER_EXTENSIBLE_MODULE(module_name, obj_module)
     439                 :            : 
     440                 :            : // Add a custom handler for a builtin module that will be called to delegate
     441                 :            : // failed attribute lookups.
     442                 :            : #define MP_REGISTER_MODULE_DELEGATION(obj_module, fun_name)
     443                 :            : 
     444                 :            : // Declare a root pointer (to avoid garbage collection of a global static variable).
     445                 :            : // param variable_declaration: a valid C variable declaration
     446                 :            : #define MP_REGISTER_ROOT_POINTER(variable_declaration)
     447                 :            : 
     448                 :            : #endif // NO_QSTR
     449                 :            : 
     450                 :            : // Underlying map/hash table implementation (not dict object or map function)
     451                 :            : 
     452                 :            : typedef struct _mp_map_elem_t {
     453                 :            :     mp_obj_t key;
     454                 :            :     mp_obj_t value;
     455                 :            : } mp_map_elem_t;
     456                 :            : 
     457                 :            : typedef struct _mp_rom_map_elem_t {
     458                 :            :     mp_rom_obj_t key;
     459                 :            :     mp_rom_obj_t value;
     460                 :            : } mp_rom_map_elem_t;
     461                 :            : 
     462                 :            : typedef struct _mp_map_t {
     463                 :            :     size_t all_keys_are_qstrs : 1;
     464                 :            :     size_t is_fixed : 1;    // if set, table is fixed/read-only and can't be modified
     465                 :            :     size_t is_ordered : 1;  // if set, table is an ordered array, not a hash map
     466                 :            :     size_t used : (8 * sizeof(size_t) - 3);
     467                 :            :     size_t alloc;
     468                 :            :     mp_map_elem_t *table;
     469                 :            : } mp_map_t;
     470                 :            : 
     471                 :            : // mp_set_lookup requires these constants to have the values they do
     472                 :            : typedef enum _mp_map_lookup_kind_t {
     473                 :            :     MP_MAP_LOOKUP = 0,
     474                 :            :     MP_MAP_LOOKUP_ADD_IF_NOT_FOUND = 1,
     475                 :            :     MP_MAP_LOOKUP_REMOVE_IF_FOUND = 2,
     476                 :            :     MP_MAP_LOOKUP_ADD_IF_NOT_FOUND_OR_REMOVE_IF_FOUND = 3, // only valid for mp_set_lookup
     477                 :            : } mp_map_lookup_kind_t;
     478                 :            : 
     479                 :     140283 : static inline bool mp_map_slot_is_filled(const mp_map_t *map, size_t pos) {
     480         [ -  + ]:     140283 :     assert(pos < map->alloc);
     481                 :     140283 :     return (map)->table[pos].key != MP_OBJ_NULL && (map)->table[pos].key != MP_OBJ_SENTINEL;
     482                 :            : }
     483                 :            : 
     484                 :            : void mp_map_init(mp_map_t *map, size_t n);
     485                 :            : void mp_map_init_fixed_table(mp_map_t *map, size_t n, const mp_obj_t *table);
     486                 :            : mp_map_t *mp_map_new(size_t n);
     487                 :            : void mp_map_deinit(mp_map_t *map);
     488                 :            : void mp_map_free(mp_map_t *map);
     489                 :            : mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t lookup_kind);
     490                 :            : void mp_map_clear(mp_map_t *map);
     491                 :            : void mp_map_dump(mp_map_t *map);
     492                 :            : 
     493                 :            : // Underlying set implementation (not set object)
     494                 :            : 
     495                 :            : typedef struct _mp_set_t {
     496                 :            :     size_t alloc;
     497                 :            :     size_t used;
     498                 :            :     mp_obj_t *table;
     499                 :            : } mp_set_t;
     500                 :            : 
     501                 :      49907 : static inline bool mp_set_slot_is_filled(const mp_set_t *set, size_t pos) {
     502   [ +  +  +  +  :      49907 :     return (set)->table[pos] != MP_OBJ_NULL && (set)->table[pos] != MP_OBJ_SENTINEL;
                   +  + ]
     503                 :            : }
     504                 :            : 
     505                 :            : void mp_set_init(mp_set_t *set, size_t n);
     506                 :            : mp_obj_t mp_set_lookup(mp_set_t *set, mp_obj_t index, mp_map_lookup_kind_t lookup_kind);
     507                 :            : mp_obj_t mp_set_remove_first(mp_set_t *set);
     508                 :            : void mp_set_clear(mp_set_t *set);
     509                 :            : 
     510                 :            : // Type definitions for methods
     511                 :            : 
     512                 :            : typedef mp_obj_t (*mp_fun_0_t)(void);
     513                 :            : typedef mp_obj_t (*mp_fun_1_t)(mp_obj_t);
     514                 :            : typedef mp_obj_t (*mp_fun_2_t)(mp_obj_t, mp_obj_t);
     515                 :            : typedef mp_obj_t (*mp_fun_3_t)(mp_obj_t, mp_obj_t, mp_obj_t);
     516                 :            : typedef mp_obj_t (*mp_fun_var_t)(size_t n, const mp_obj_t *);
     517                 :            : // mp_fun_kw_t takes mp_map_t* (and not const mp_map_t*) to ease passing
     518                 :            : // this arg to mp_map_lookup().
     519                 :            : typedef mp_obj_t (*mp_fun_kw_t)(size_t n, const mp_obj_t *, mp_map_t *);
     520                 :            : 
     521                 :            : // Flags for type behaviour (mp_obj_type_t.flags)
     522                 :            : // If MP_TYPE_FLAG_EQ_NOT_REFLEXIVE is clear then __eq__ is reflexive (A==A returns True).
     523                 :            : // If MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE is clear then the type can't be equal to an
     524                 :            : //   instance of any different class that also clears this flag.  If this flag is set
     525                 :            : //   then the type may check for equality against a different type.
     526                 :            : // If MP_TYPE_FLAG_EQ_HAS_NEQ_TEST is clear then the type only implements the __eq__
     527                 :            : //   operator and not the __ne__ operator.  If it's set then __ne__ may be implemented.
     528                 :            : // If MP_TYPE_FLAG_BINDS_SELF is set then the type as a method binds self as the first arg.
     529                 :            : // If MP_TYPE_FLAG_BUILTIN_FUN is set then the type is a built-in function type.
     530                 :            : // MP_TYPE_FLAG_ITER_IS_GETITER is a no-op flag that means the default behaviour for the
     531                 :            : //   iter slot and it's the getiter function.
     532                 :            : // If MP_TYPE_FLAG_ITER_IS_ITERNEXT is set then the "iter" slot is the iternext
     533                 :            : //   function and getiter will be automatically implemented as "return self".
     534                 :            : // If MP_TYPE_FLAG_ITER_IS_CUSTOM is set then the "iter" slot is a pointer to a
     535                 :            : //   mp_getiter_iternext_custom_t struct instance (with both .getiter and .iternext set).
     536                 :            : // If MP_TYPE_FLAG_ITER_IS_STREAM is set then the type implicitly gets a "return self"
     537                 :            : //   getiter, and mp_stream_unbuffered_iter for iternext.
     538                 :            : // If MP_TYPE_FLAG_INSTANCE_TYPE is set then this is an instance type (i.e. defined in Python).
     539                 :            : #define MP_TYPE_FLAG_NONE (0x0000)
     540                 :            : #define MP_TYPE_FLAG_IS_SUBCLASSED (0x0001)
     541                 :            : #define MP_TYPE_FLAG_HAS_SPECIAL_ACCESSORS (0x0002)
     542                 :            : #define MP_TYPE_FLAG_EQ_NOT_REFLEXIVE (0x0004)
     543                 :            : #define MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE (0x0008)
     544                 :            : #define MP_TYPE_FLAG_EQ_HAS_NEQ_TEST (0x0010)
     545                 :            : #define MP_TYPE_FLAG_BINDS_SELF (0x0020)
     546                 :            : #define MP_TYPE_FLAG_BUILTIN_FUN (0x0040)
     547                 :            : #define MP_TYPE_FLAG_ITER_IS_GETITER (0x0000)
     548                 :            : #define MP_TYPE_FLAG_ITER_IS_ITERNEXT (0x0080)
     549                 :            : #define MP_TYPE_FLAG_ITER_IS_CUSTOM (0x0100)
     550                 :            : #define MP_TYPE_FLAG_ITER_IS_STREAM (MP_TYPE_FLAG_ITER_IS_ITERNEXT | MP_TYPE_FLAG_ITER_IS_CUSTOM)
     551                 :            : #define MP_TYPE_FLAG_INSTANCE_TYPE (0x0200)
     552                 :            : 
     553                 :            : typedef enum {
     554                 :            :     PRINT_STR = 0,
     555                 :            :     PRINT_REPR = 1,
     556                 :            :     PRINT_EXC = 2, // Special format for printing exception in unhandled exception message
     557                 :            :     PRINT_JSON = 3,
     558                 :            :     PRINT_RAW = 4, // Special format for printing bytes as an undercorated string
     559                 :            :     PRINT_EXC_SUBCLASS = 0x80, // Internal flag for printing exception subclasses
     560                 :            : } mp_print_kind_t;
     561                 :            : 
     562                 :            : typedef struct _mp_obj_iter_buf_t {
     563                 :            :     mp_obj_base_t base;
     564                 :            :     mp_obj_t buf[3];
     565                 :            : } mp_obj_iter_buf_t;
     566                 :            : 
     567                 :            : // The number of slots that an mp_obj_iter_buf_t needs on the Python value stack.
     568                 :            : // It's rounded up in case mp_obj_base_t is smaller than mp_obj_t (eg for OBJ_REPR_D).
     569                 :            : #define MP_OBJ_ITER_BUF_NSLOTS ((sizeof(mp_obj_iter_buf_t) + sizeof(mp_obj_t) - 1) / sizeof(mp_obj_t))
     570                 :            : 
     571                 :            : typedef void (*mp_print_fun_t)(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind);
     572                 :            : 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);
     573                 :            : 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);
     574                 :            : typedef mp_obj_t (*mp_unary_op_fun_t)(mp_unary_op_t op, mp_obj_t);
     575                 :            : typedef mp_obj_t (*mp_binary_op_fun_t)(mp_binary_op_t op, mp_obj_t, mp_obj_t);
     576                 :            : typedef void (*mp_attr_fun_t)(mp_obj_t self_in, qstr attr, mp_obj_t *dest);
     577                 :            : typedef mp_obj_t (*mp_subscr_fun_t)(mp_obj_t self_in, mp_obj_t index, mp_obj_t value);
     578                 :            : typedef mp_obj_t (*mp_getiter_fun_t)(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf);
     579                 :            : typedef mp_fun_1_t mp_iternext_fun_t;
     580                 :            : 
     581                 :            : // For MP_TYPE_FLAG_ITER_IS_CUSTOM, the "getiter" slot points to an instance of this type.
     582                 :            : typedef struct _mp_getiter_iternext_custom_t {
     583                 :            :     mp_getiter_fun_t getiter;
     584                 :            :     mp_iternext_fun_t iternext;
     585                 :            : } mp_getiter_iternext_custom_t;
     586                 :            : 
     587                 :            : // Buffer protocol
     588                 :            : 
     589                 :            : typedef struct _mp_buffer_info_t {
     590                 :            :     void *buf;      // can be NULL if len == 0
     591                 :            :     size_t len;     // in bytes
     592                 :            :     int typecode;   // as per binary.h
     593                 :            : } mp_buffer_info_t;
     594                 :            : 
     595                 :            : #define MP_BUFFER_READ  (1)
     596                 :            : #define MP_BUFFER_WRITE (2)
     597                 :            : #define MP_BUFFER_RW (MP_BUFFER_READ | MP_BUFFER_WRITE)
     598                 :            : #define MP_BUFFER_RAISE_IF_UNSUPPORTED (4)
     599                 :            : 
     600                 :            : typedef mp_int_t (*mp_buffer_fun_t)(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
     601                 :            : 
     602                 :            : bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
     603                 :            : 
     604                 :       8207 : static inline void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
     605                 :       8207 :     mp_get_buffer(obj, bufinfo, flags | MP_BUFFER_RAISE_IF_UNSUPPORTED);
     606                 :         32 : }
     607                 :            : 
     608                 :            : // This struct will be updated to become a variable sized struct. In order to
     609                 :            : // use this as a member, or allocate dynamically, use the mp_obj_empty_type_t
     610                 :            : // or mp_obj_full_type_t structs below (which must be kept in sync).
     611                 :            : struct _mp_obj_type_t {
     612                 :            :     // A type is an object so must start with this entry, which points to mp_type_type.
     613                 :            :     mp_obj_base_t base;
     614                 :            : 
     615                 :            :     // Flags associated with this type.
     616                 :            :     uint16_t flags;
     617                 :            : 
     618                 :            :     // The name of this type, a qstr.
     619                 :            :     uint16_t name;
     620                 :            : 
     621                 :            :     // Slots: For the rest of the fields, the slot index points to the
     622                 :            :     // relevant function in the variable-length "slots" field. Ideally these
     623                 :            :     // would be only 4 bits, but the extra overhead of accessing them adds
     624                 :            :     // more code, and we also need to be able to take the address of them for
     625                 :            :     // mp_obj_class_lookup.
     626                 :            : 
     627                 :            :     // Corresponds to __new__ and __init__ special methods, to make an instance of the type.
     628                 :            :     uint8_t slot_index_make_new;
     629                 :            : 
     630                 :            :     // Corresponds to __repr__ and __str__ special methods.
     631                 :            :     uint8_t slot_index_print;
     632                 :            : 
     633                 :            :     // Corresponds to __call__ special method, ie T(...).
     634                 :            :     uint8_t slot_index_call;
     635                 :            : 
     636                 :            :     // Implements unary and binary operations.
     637                 :            :     // Can return MP_OBJ_NULL if the operation is not supported.
     638                 :            :     uint8_t slot_index_unary_op;
     639                 :            :     uint8_t slot_index_binary_op;
     640                 :            : 
     641                 :            :     // Implements load, store and delete attribute.
     642                 :            :     //
     643                 :            :     // dest[0] = MP_OBJ_NULL means load
     644                 :            :     //  return: for fail, do nothing
     645                 :            :     //          for fail but continue lookup in locals_dict, dest[1] = MP_OBJ_SENTINEL
     646                 :            :     //          for attr, dest[0] = value
     647                 :            :     //          for method, dest[0] = method, dest[1] = self
     648                 :            :     //
     649                 :            :     // dest[0,1] = {MP_OBJ_SENTINEL, MP_OBJ_NULL} means delete
     650                 :            :     // dest[0,1] = {MP_OBJ_SENTINEL, object} means store
     651                 :            :     //  return: for fail, do nothing
     652                 :            :     //          for success set dest[0] = MP_OBJ_NULL
     653                 :            :     uint8_t slot_index_attr;
     654                 :            : 
     655                 :            :     // Implements load, store and delete subscripting:
     656                 :            :     //  - value = MP_OBJ_SENTINEL means load
     657                 :            :     //  - value = MP_OBJ_NULL means delete
     658                 :            :     //  - all other values mean store the value
     659                 :            :     // Can return MP_OBJ_NULL if operation not supported.
     660                 :            :     uint8_t slot_index_subscr;
     661                 :            : 
     662                 :            :     // This slot's behaviour depends on the MP_TYPE_FLAG_ITER_IS_* flags above.
     663                 :            :     // - If MP_TYPE_FLAG_ITER_IS_GETITER flag is set, then this corresponds to the __iter__
     664                 :            :     //   special method (of type mp_getiter_fun_t). Can use the given mp_obj_iter_buf_t
     665                 :            :     //   to store the iterator object, otherwise can return a pointer to an object on the heap.
     666                 :            :     // - If MP_TYPE_FLAG_ITER_IS_ITERNEXT is set, then this corresponds to __next__ special method.
     667                 :            :     //   May return MP_OBJ_STOP_ITERATION as an optimisation instead of raising StopIteration()
     668                 :            :     //   with no args. The type will implicitly implement getiter as "return self".
     669                 :            :     // - If MP_TYPE_FLAG_ITER_IS_CUSTOM is set, then this slot must point to an
     670                 :            :     //   mp_getiter_iternext_custom_t instance with both the getiter and iternext fields set.
     671                 :            :     // - If MP_TYPE_FLAG_ITER_IS_STREAM is set, this this slot should be unset.
     672                 :            :     uint8_t slot_index_iter;
     673                 :            : 
     674                 :            :     // Implements the buffer protocol if supported by this type.
     675                 :            :     uint8_t slot_index_buffer;
     676                 :            : 
     677                 :            :     // One of disjoint protocols (interfaces), like mp_stream_p_t, etc.
     678                 :            :     uint8_t slot_index_protocol;
     679                 :            : 
     680                 :            :     // A pointer to the parents of this type:
     681                 :            :     //  - 0 parents: pointer is NULL (object is implicitly the single parent)
     682                 :            :     //  - 1 parent: a pointer to the type of that parent
     683                 :            :     //  - 2 or more parents: pointer to a tuple object containing the parent types
     684                 :            :     uint8_t slot_index_parent;
     685                 :            : 
     686                 :            :     // A dict mapping qstrs to objects local methods/constants/etc.
     687                 :            :     uint8_t slot_index_locals_dict;
     688                 :            : 
     689                 :            :     const void *slots[];
     690                 :            : };
     691                 :            : 
     692                 :            : // Non-variable sized versions of mp_obj_type_t to be used as a member
     693                 :            : // in other structs or for dynamic allocation. The fields are exactly
     694                 :            : // as in mp_obj_type_t, but with a fixed size for the flexible array
     695                 :            : // members.
     696                 :            : typedef struct _mp_obj_empty_type_t {
     697                 :            :     mp_obj_base_t base;
     698                 :            :     uint16_t flags;
     699                 :            :     uint16_t name;
     700                 :            : 
     701                 :            :     uint8_t slot_index_make_new;
     702                 :            :     uint8_t slot_index_print;
     703                 :            :     uint8_t slot_index_call;
     704                 :            :     uint8_t slot_index_unary_op;
     705                 :            :     uint8_t slot_index_binary_op;
     706                 :            :     uint8_t slot_index_attr;
     707                 :            :     uint8_t slot_index_subscr;
     708                 :            :     uint8_t slot_index_iter;
     709                 :            :     uint8_t slot_index_buffer;
     710                 :            :     uint8_t slot_index_protocol;
     711                 :            :     uint8_t slot_index_parent;
     712                 :            :     uint8_t slot_index_locals_dict;
     713                 :            : 
     714                 :            :     // No slots member.
     715                 :            : } mp_obj_empty_type_t;
     716                 :            : 
     717                 :            : typedef struct _mp_obj_full_type_t {
     718                 :            :     mp_obj_base_t base;
     719                 :            :     uint16_t flags;
     720                 :            :     uint16_t name;
     721                 :            : 
     722                 :            :     uint8_t slot_index_make_new;
     723                 :            :     uint8_t slot_index_print;
     724                 :            :     uint8_t slot_index_call;
     725                 :            :     uint8_t slot_index_unary_op;
     726                 :            :     uint8_t slot_index_binary_op;
     727                 :            :     uint8_t slot_index_attr;
     728                 :            :     uint8_t slot_index_subscr;
     729                 :            :     uint8_t slot_index_iter;
     730                 :            :     uint8_t slot_index_buffer;
     731                 :            :     uint8_t slot_index_protocol;
     732                 :            :     uint8_t slot_index_parent;
     733                 :            :     uint8_t slot_index_locals_dict;
     734                 :            : 
     735                 :            :     // Explicitly add 12 slots.
     736                 :            :     const void *slots[11];
     737                 :            : } mp_obj_full_type_t;
     738                 :            : 
     739                 :            : #define _MP_OBJ_TYPE_SLOT_TYPE_make_new (mp_make_new_fun_t)
     740                 :            : #define _MP_OBJ_TYPE_SLOT_TYPE_print (mp_print_fun_t)
     741                 :            : #define _MP_OBJ_TYPE_SLOT_TYPE_call (mp_call_fun_t)
     742                 :            : #define _MP_OBJ_TYPE_SLOT_TYPE_unary_op (mp_unary_op_fun_t)
     743                 :            : #define _MP_OBJ_TYPE_SLOT_TYPE_binary_op (mp_binary_op_fun_t)
     744                 :            : #define _MP_OBJ_TYPE_SLOT_TYPE_attr (mp_attr_fun_t)
     745                 :            : #define _MP_OBJ_TYPE_SLOT_TYPE_subscr (mp_subscr_fun_t)
     746                 :            : #define _MP_OBJ_TYPE_SLOT_TYPE_iter (const void *)
     747                 :            : #define _MP_OBJ_TYPE_SLOT_TYPE_buffer (mp_buffer_fun_t)
     748                 :            : #define _MP_OBJ_TYPE_SLOT_TYPE_protocol (const void *)
     749                 :            : #define _MP_OBJ_TYPE_SLOT_TYPE_parent (const void *)
     750                 :            : #define _MP_OBJ_TYPE_SLOT_TYPE_locals_dict (struct _mp_obj_dict_t *)
     751                 :            : 
     752                 :            : // Implementation of MP_DEFINE_CONST_OBJ_TYPE for each number of arguments.
     753                 :            : // Do not use these directly, instead use MP_DEFINE_CONST_OBJ_TYPE.
     754                 :            : // Generated with:
     755                 :            : // for i in range(13):
     756                 :            : //     print(f"#define MP_DEFINE_CONST_OBJ_TYPE_NARGS_{i}(_struct_type, _typename, _name, _flags{''.join(f', f{j+1}, v{j+1}' for j in range(i))}) const _struct_type _typename = {{ .base = {{ &mp_type_type }}, .flags = _flags, .name = _name{''.join(f', .slot_index_##f{j+1} = {j+1}' for j in range(i))}{', .slots = { ' + ''.join(f'v{j+1}, ' for j in range(i)) + '}' if i else '' } }}")
     757                 :            : #define MP_DEFINE_CONST_OBJ_TYPE_NARGS_0(_struct_type, _typename, _name, _flags) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name }
     758                 :            : #define MP_DEFINE_CONST_OBJ_TYPE_NARGS_1(_struct_type, _typename, _name, _flags, f1, v1) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slots = { v1, } }
     759                 :            : #define MP_DEFINE_CONST_OBJ_TYPE_NARGS_2(_struct_type, _typename, _name, _flags, f1, v1, f2, v2) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slots = { v1, v2, } }
     760                 :            : #define MP_DEFINE_CONST_OBJ_TYPE_NARGS_3(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slots = { v1, v2, v3, } }
     761                 :            : #define MP_DEFINE_CONST_OBJ_TYPE_NARGS_4(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slots = { v1, v2, v3, v4, } }
     762                 :            : #define MP_DEFINE_CONST_OBJ_TYPE_NARGS_5(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slots = { v1, v2, v3, v4, v5, } }
     763                 :            : #define MP_DEFINE_CONST_OBJ_TYPE_NARGS_6(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slots = { v1, v2, v3, v4, v5, v6, } }
     764                 :            : #define MP_DEFINE_CONST_OBJ_TYPE_NARGS_7(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slots = { v1, v2, v3, v4, v5, v6, v7, } }
     765                 :            : #define MP_DEFINE_CONST_OBJ_TYPE_NARGS_8(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, } }
     766                 :            : #define MP_DEFINE_CONST_OBJ_TYPE_NARGS_9(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, } }
     767                 :            : #define MP_DEFINE_CONST_OBJ_TYPE_NARGS_10(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, } }
     768                 :            : #define MP_DEFINE_CONST_OBJ_TYPE_NARGS_11(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10, f11, v11) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slot_index_##f11 = 11, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, } }
     769                 :            : #define MP_DEFINE_CONST_OBJ_TYPE_NARGS_12(_struct_type, _typename, _name, _flags, f1, v1, f2, v2, f3, v3, f4, v4, f5, v5, f6, v6, f7, v7, f8, v8, f9, v9, f10, v10, f11, v11, f12, v12) const _struct_type _typename = { .base = { &mp_type_type }, .flags = _flags, .name = _name, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slot_index_##f5 = 5, .slot_index_##f6 = 6, .slot_index_##f7 = 7, .slot_index_##f8 = 8, .slot_index_##f9 = 9, .slot_index_##f10 = 10, .slot_index_##f11 = 11, .slot_index_##f12 = 12, .slots = { v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, } }
     770                 :            : 
     771                 :            : // Because the mp_obj_type_t instances are in (zero-initialised) ROM, we take
     772                 :            : // slot_index_foo=0 to mean that the slot is unset. This also simplifies checking
     773                 :            : // if the slot is set. That means that we need to store index+1 in slot_index_foo
     774                 :            : // though and then access it as slots[slot_index_foo - 1]. This is an implementation
     775                 :            : // detail, the user of these macros doesn't need to be aware of it, and when using
     776                 :            : // MP_OBJ_TYPE_OFFSETOF_SLOT you should use zero-based indexing.
     777                 :            : #define MP_OBJ_TYPE_HAS_SLOT(t, f) ((t)->slot_index_##f)
     778                 :            : #define MP_OBJ_TYPE_GET_SLOT(t, f) (_MP_OBJ_TYPE_SLOT_TYPE_##f(t)->slots[(t)->slot_index_##f - 1])
     779                 :            : #define MP_OBJ_TYPE_GET_SLOT_OR_NULL(t, f) (_MP_OBJ_TYPE_SLOT_TYPE_##f(MP_OBJ_TYPE_HAS_SLOT(t, f) ? MP_OBJ_TYPE_GET_SLOT(t, f) : NULL))
     780                 :            : #define MP_OBJ_TYPE_SET_SLOT(t, f, v, n) ((t)->slot_index_##f = (n) + 1, (t)->slots[(n)] = (void *)v)
     781                 :            : #define MP_OBJ_TYPE_OFFSETOF_SLOT(f) (offsetof(mp_obj_type_t, slot_index_##f))
     782                 :            : #define MP_OBJ_TYPE_HAS_SLOT_BY_OFFSET(t, offset) (*(uint8_t *)((char *)(t) + (offset)) != 0)
     783                 :            : 
     784                 :            : // Workaround for https://docs.microsoft.com/en-us/cpp/preprocessor/preprocessor-experimental-overview?view=msvc-160#macro-arguments-are-unpacked
     785                 :            : #define MP_DEFINE_CONST_OBJ_TYPE_EXPAND(x) x
     786                 :            : 
     787                 :            : // This macro evaluates to MP_DEFINE_CONST_OBJ_TYPE_NARGS_##N, where N is the value
     788                 :            : // of the 29th argument (29 is 13*2 + 3).
     789                 :            : #define MP_DEFINE_CONST_OBJ_TYPE_NARGS(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, N, ...) MP_DEFINE_CONST_OBJ_TYPE_NARGS_##N
     790                 :            : 
     791                 :            : // This macros is used to define a object type in ROM.
     792                 :            : // Invoke as MP_DEFINE_CONST_OBJ_TYPE(_typename, _name, _flags, _make_new [, slot, func]*)
     793                 :            : // It uses the number of arguments to select which MP_DEFINE_CONST_OBJ_TYPE_*
     794                 :            : // macro to use based on the number of arguments. It works by shifting the
     795                 :            : // numeric values 12, 11, ... 0 by the number of arguments, such that the
     796                 :            : // 29th argument ends up being the number to use. The _INV values are
     797                 :            : // placeholders because the slot arguments come in pairs.
     798                 :            : #define MP_DEFINE_CONST_OBJ_TYPE(...) MP_DEFINE_CONST_OBJ_TYPE_EXPAND(MP_DEFINE_CONST_OBJ_TYPE_NARGS(__VA_ARGS__, _INV, 12, _INV, 11, _INV, 10, _INV, 9, _INV, 8, _INV, 7, _INV, 6, _INV, 5, _INV, 4, _INV, 3, _INV, 2, _INV, 1, _INV, 0)(mp_obj_type_t, __VA_ARGS__))
     799                 :            : 
     800                 :            : // Constant types, globally accessible
     801                 :            : extern const mp_obj_type_t mp_type_type;
     802                 :            : extern const mp_obj_type_t mp_type_object;
     803                 :            : extern const mp_obj_type_t mp_type_NoneType;
     804                 :            : extern const mp_obj_type_t mp_type_bool;
     805                 :            : extern const mp_obj_type_t mp_type_int;
     806                 :            : extern const mp_obj_type_t mp_type_str;
     807                 :            : extern const mp_obj_type_t mp_type_bytes;
     808                 :            : extern const mp_obj_type_t mp_type_bytearray;
     809                 :            : extern const mp_obj_type_t mp_type_memoryview;
     810                 :            : extern const mp_obj_type_t mp_type_float;
     811                 :            : extern const mp_obj_type_t mp_type_complex;
     812                 :            : extern const mp_obj_type_t mp_type_tuple;
     813                 :            : extern const mp_obj_type_t mp_type_list;
     814                 :            : extern const mp_obj_type_t mp_type_map; // map (the python builtin, not the dict implementation detail)
     815                 :            : extern const mp_obj_type_t mp_type_enumerate;
     816                 :            : extern const mp_obj_type_t mp_type_filter;
     817                 :            : extern const mp_obj_type_t mp_type_deque;
     818                 :            : extern const mp_obj_type_t mp_type_dict;
     819                 :            : extern const mp_obj_type_t mp_type_ordereddict;
     820                 :            : extern const mp_obj_type_t mp_type_range;
     821                 :            : extern const mp_obj_type_t mp_type_set;
     822                 :            : extern const mp_obj_type_t mp_type_frozenset;
     823                 :            : extern const mp_obj_type_t mp_type_slice;
     824                 :            : extern const mp_obj_type_t mp_type_zip;
     825                 :            : extern const mp_obj_type_t mp_type_array;
     826                 :            : extern const mp_obj_type_t mp_type_super;
     827                 :            : extern const mp_obj_type_t mp_type_gen_wrap;
     828                 :            : extern const mp_obj_type_t mp_type_native_gen_wrap;
     829                 :            : extern const mp_obj_type_t mp_type_gen_instance;
     830                 :            : extern const mp_obj_type_t mp_type_fun_builtin_0;
     831                 :            : extern const mp_obj_type_t mp_type_fun_builtin_1;
     832                 :            : extern const mp_obj_type_t mp_type_fun_builtin_2;
     833                 :            : extern const mp_obj_type_t mp_type_fun_builtin_3;
     834                 :            : extern const mp_obj_type_t mp_type_fun_builtin_var;
     835                 :            : extern const mp_obj_type_t mp_type_fun_bc;
     836                 :            : extern const mp_obj_type_t mp_type_fun_native;
     837                 :            : extern const mp_obj_type_t mp_type_fun_viper;
     838                 :            : extern const mp_obj_type_t mp_type_fun_asm;
     839                 :            : extern const mp_obj_type_t mp_type_module;
     840                 :            : extern const mp_obj_type_t mp_type_staticmethod;
     841                 :            : extern const mp_obj_type_t mp_type_classmethod;
     842                 :            : extern const mp_obj_type_t mp_type_bound_meth;
     843                 :            : extern const mp_obj_type_t mp_type_property;
     844                 :            : extern const mp_obj_type_t mp_type_stringio;
     845                 :            : extern const mp_obj_type_t mp_type_bytesio;
     846                 :            : extern const mp_obj_type_t mp_type_reversed;
     847                 :            : extern const mp_obj_type_t mp_type_polymorph_iter;
     848                 :            : #if MICROPY_ENABLE_FINALISER
     849                 :            : extern const mp_obj_type_t mp_type_polymorph_iter_with_finaliser;
     850                 :            : #endif
     851                 :            : 
     852                 :            : // Exceptions
     853                 :            : extern const mp_obj_type_t mp_type_BaseException;
     854                 :            : extern const mp_obj_type_t mp_type_ArithmeticError;
     855                 :            : extern const mp_obj_type_t mp_type_AssertionError;
     856                 :            : extern const mp_obj_type_t mp_type_AttributeError;
     857                 :            : extern const mp_obj_type_t mp_type_EOFError;
     858                 :            : extern const mp_obj_type_t mp_type_Exception;
     859                 :            : extern const mp_obj_type_t mp_type_GeneratorExit;
     860                 :            : extern const mp_obj_type_t mp_type_ImportError;
     861                 :            : extern const mp_obj_type_t mp_type_IndentationError;
     862                 :            : extern const mp_obj_type_t mp_type_IndexError;
     863                 :            : extern const mp_obj_type_t mp_type_KeyboardInterrupt;
     864                 :            : extern const mp_obj_type_t mp_type_KeyError;
     865                 :            : extern const mp_obj_type_t mp_type_LookupError;
     866                 :            : extern const mp_obj_type_t mp_type_MemoryError;
     867                 :            : extern const mp_obj_type_t mp_type_NameError;
     868                 :            : extern const mp_obj_type_t mp_type_NotImplementedError;
     869                 :            : extern const mp_obj_type_t mp_type_OSError;
     870                 :            : extern const mp_obj_type_t mp_type_OverflowError;
     871                 :            : extern const mp_obj_type_t mp_type_RuntimeError;
     872                 :            : extern const mp_obj_type_t mp_type_StopAsyncIteration;
     873                 :            : extern const mp_obj_type_t mp_type_StopIteration;
     874                 :            : extern const mp_obj_type_t mp_type_SyntaxError;
     875                 :            : extern const mp_obj_type_t mp_type_SystemExit;
     876                 :            : extern const mp_obj_type_t mp_type_TypeError;
     877                 :            : extern const mp_obj_type_t mp_type_UnicodeError;
     878                 :            : extern const mp_obj_type_t mp_type_ValueError;
     879                 :            : extern const mp_obj_type_t mp_type_ViperTypeError;
     880                 :            : extern const mp_obj_type_t mp_type_ZeroDivisionError;
     881                 :            : 
     882                 :            : // Constant objects, globally accessible: None, False, True
     883                 :            : // These should always be accessed via the below macros.
     884                 :            : #if MICROPY_OBJ_IMMEDIATE_OBJS
     885                 :            : // None is even while False/True are odd so their types can be distinguished with 1 bit.
     886                 :            : #define mp_const_none MP_OBJ_NEW_IMMEDIATE_OBJ(0)
     887                 :            : #define mp_const_false MP_OBJ_NEW_IMMEDIATE_OBJ(1)
     888                 :            : #define mp_const_true MP_OBJ_NEW_IMMEDIATE_OBJ(3)
     889                 :            : #else
     890                 :            : #define mp_const_none (MP_OBJ_FROM_PTR(&mp_const_none_obj))
     891                 :            : #define mp_const_false (MP_OBJ_FROM_PTR(&mp_const_false_obj))
     892                 :            : #define mp_const_true (MP_OBJ_FROM_PTR(&mp_const_true_obj))
     893                 :            : extern const struct _mp_obj_none_t mp_const_none_obj;
     894                 :            : extern const struct _mp_obj_bool_t mp_const_false_obj;
     895                 :            : extern const struct _mp_obj_bool_t mp_const_true_obj;
     896                 :            : #endif
     897                 :            : 
     898                 :            : // Constant objects, globally accessible: b'', (), {}, Ellipsis, NotImplemented, GeneratorExit()
     899                 :            : // The below macros are for convenience only.
     900                 :            : #define mp_const_empty_bytes (MP_OBJ_FROM_PTR(&mp_const_empty_bytes_obj))
     901                 :            : #define mp_const_empty_tuple (MP_OBJ_FROM_PTR(&mp_const_empty_tuple_obj))
     902                 :            : #define mp_const_notimplemented (MP_OBJ_FROM_PTR(&mp_const_notimplemented_obj))
     903                 :            : extern const struct _mp_obj_str_t mp_const_empty_bytes_obj;
     904                 :            : extern const struct _mp_obj_tuple_t mp_const_empty_tuple_obj;
     905                 :            : extern const struct _mp_obj_dict_t mp_const_empty_dict_obj;
     906                 :            : extern const struct _mp_obj_singleton_t mp_const_ellipsis_obj;
     907                 :            : extern const struct _mp_obj_singleton_t mp_const_notimplemented_obj;
     908                 :            : extern const struct _mp_obj_exception_t mp_const_GeneratorExit_obj;
     909                 :            : 
     910                 :            : // Fixed empty map. Useful when calling keyword-receiving functions
     911                 :            : // without any keywords from C, etc.
     912                 :            : #define mp_const_empty_map (mp_const_empty_dict_obj.map)
     913                 :            : 
     914                 :            : // General API for objects
     915                 :            : 
     916                 :            : // Helper versions of m_new_obj when you need to immediately set base.type.
     917                 :            : // Implementing this as a call rather than inline saves 8 bytes per usage.
     918                 :            : #define mp_obj_malloc(struct_type, obj_type) ((struct_type *)mp_obj_malloc_helper(sizeof(struct_type), obj_type))
     919                 :            : #define mp_obj_malloc_var(struct_type, var_field, var_type, var_num, obj_type) ((struct_type *)mp_obj_malloc_helper(offsetof(struct_type, var_field) + sizeof(var_type) * (var_num), obj_type))
     920                 :            : void *mp_obj_malloc_helper(size_t num_bytes, const mp_obj_type_t *type);
     921                 :            : 
     922                 :            : // Object allocation macros for allocating objects that have a finaliser.
     923                 :            : #if MICROPY_ENABLE_FINALISER
     924                 :            : #define mp_obj_malloc_with_finaliser(struct_type, obj_type) ((struct_type *)mp_obj_malloc_with_finaliser_helper(sizeof(struct_type), obj_type))
     925                 :            : #define mp_obj_malloc_var_with_finaliser(struct_type, var_type, var_num, obj_type) ((struct_type *)mp_obj_malloc_with_finaliser_helper(sizeof(struct_type) + sizeof(var_type) * (var_num), obj_type))
     926                 :            : void *mp_obj_malloc_with_finaliser_helper(size_t num_bytes, const mp_obj_type_t *type);
     927                 :            : #else
     928                 :            : #define mp_obj_malloc_with_finaliser(struct_type, obj_type) mp_obj_malloc(struct_type, obj_type)
     929                 :            : #define mp_obj_malloc_var_with_finaliser(struct_type, var_type, var_num, obj_type) mp_obj_malloc_var(struct_type, var_type, var_num, obj_type)
     930                 :            : #endif
     931                 :            : 
     932                 :            : // These macros are derived from more primitive ones and are used to
     933                 :            : // check for more specific object types.
     934                 :            : // Note: these are kept as macros because inline functions sometimes use much
     935                 :            : // more code space than the equivalent macros, depending on the compiler.
     936                 :            : // don't use mp_obj_is_exact_type directly; use mp_obj_is_type which provides additional safety checks.
     937                 :            : // use the former only if you need to bypass these checks (because you've already checked everything else)
     938                 :            : #define mp_obj_is_exact_type(o, t) (mp_obj_is_obj(o) && (((mp_obj_base_t *)MP_OBJ_TO_PTR(o))->type == (t)))
     939                 :            : 
     940                 :            : // Type checks are split to a separate, constant result macro. This is so it doesn't hinder the compilers's
     941                 :            : // optimizations (other tricks like using ({ expr; exper; }) or (exp, expr, expr) in mp_obj_is_type() result
     942                 :            : // in missed optimizations)
     943                 :            : #define mp_type_assert_not_bool_int_str_nonetype(t) (                                     \
     944                 :            :     MP_STATIC_ASSERT_NONCONSTEXPR((t) != &mp_type_bool), assert((t) != &mp_type_bool),         \
     945                 :            :     MP_STATIC_ASSERT_NONCONSTEXPR((t) != &mp_type_int), assert((t) != &mp_type_int),           \
     946                 :            :     MP_STATIC_ASSERT_NONCONSTEXPR((t) != &mp_type_str), assert((t) != &mp_type_str),           \
     947                 :            :     MP_STATIC_ASSERT_NONCONSTEXPR((t) != &mp_type_NoneType), assert((t) != &mp_type_NoneType), \
     948                 :            :     1)
     949                 :            : 
     950                 :            : #define mp_obj_is_type(o, t) (mp_type_assert_not_bool_int_str_nonetype(t) && mp_obj_is_exact_type(o, t))
     951                 :            : #if MICROPY_OBJ_IMMEDIATE_OBJS
     952                 :            : // bool's are immediates, not real objects, so test for the 2 possible values.
     953                 :            : #define mp_obj_is_bool(o) ((o) == mp_const_false || (o) == mp_const_true)
     954                 :            : #else
     955                 :            : #define mp_obj_is_bool(o) mp_obj_is_exact_type(o, &mp_type_bool)
     956                 :            : #endif
     957                 :            : #define mp_obj_is_int(o) (mp_obj_is_small_int(o) || mp_obj_is_exact_type(o, &mp_type_int))
     958                 :            : #define mp_obj_is_str(o) (mp_obj_is_qstr(o) || mp_obj_is_exact_type(o, &mp_type_str))
     959                 :            : #define mp_obj_is_str_or_bytes(o) (mp_obj_is_qstr(o) || (mp_obj_is_obj(o) && MP_OBJ_TYPE_GET_SLOT_OR_NULL(((mp_obj_base_t *)MP_OBJ_TO_PTR(o))->type, binary_op) == mp_obj_str_binary_op))
     960                 :            : bool mp_obj_is_dict_or_ordereddict(mp_obj_t o);
     961                 :            : #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))
     962                 :            : 
     963                 :            : mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict);
     964                 :   16978959 : static inline mp_obj_t mp_obj_new_bool(mp_int_t x) {
     965   [ +  +  +  +  :   16978959 :     return x ? mp_const_true : mp_const_false;
          +  +  +  +  +  
             +  +  +  +  
                      - ]
     966                 :            : }
     967                 :            : mp_obj_t mp_obj_new_cell(mp_obj_t obj);
     968                 :            : mp_obj_t mp_obj_new_int(mp_int_t value);
     969                 :            : mp_obj_t mp_obj_new_int_from_uint(mp_uint_t value);
     970                 :            : mp_obj_t mp_obj_new_int_from_str_len(const char **str, size_t len, bool neg, unsigned int base);
     971                 :            : 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)
     972                 :            : 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)
     973                 :            : mp_obj_t mp_obj_new_str(const char *data, size_t len); // will check utf-8 (raises UnicodeError)
     974                 :            : mp_obj_t mp_obj_new_str_via_qstr(const char *data, size_t len); // input data must be valid utf-8
     975                 :            : mp_obj_t mp_obj_new_str_from_vstr(vstr_t *vstr); // will check utf-8 (raises UnicodeError)
     976                 :            : #if MICROPY_PY_BUILTINS_STR_UNICODE && MICROPY_PY_BUILTINS_STR_UNICODE_CHECK
     977                 :            : mp_obj_t mp_obj_new_str_from_utf8_vstr(vstr_t *vstr); // input data must be valid utf-8
     978                 :            : #else
     979                 :            : #define mp_obj_new_str_from_utf8_vstr mp_obj_new_str_from_vstr
     980                 :            : #endif
     981                 :            : mp_obj_t mp_obj_new_bytes_from_vstr(vstr_t *vstr);
     982                 :            : mp_obj_t mp_obj_new_bytes(const byte *data, size_t len);
     983                 :            : mp_obj_t mp_obj_new_bytearray(size_t n, const void *items);
     984                 :            : mp_obj_t mp_obj_new_bytearray_by_ref(size_t n, void *items);
     985                 :            : #if MICROPY_PY_BUILTINS_FLOAT
     986                 :            : mp_obj_t mp_obj_new_int_from_float(mp_float_t val);
     987                 :            : mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag);
     988                 :            : #endif
     989                 :            : mp_obj_t mp_obj_new_exception(const mp_obj_type_t *exc_type);
     990                 :            : mp_obj_t mp_obj_new_exception_args(const mp_obj_type_t *exc_type, size_t n_args, const mp_obj_t *args);
     991                 :            : #if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_NONE
     992                 :            : #define mp_obj_new_exception_msg(exc_type, msg) mp_obj_new_exception(exc_type)
     993                 :            : #define mp_obj_new_exception_msg_varg(exc_type, ...) mp_obj_new_exception(exc_type)
     994                 :            : #else
     995                 :            : mp_obj_t mp_obj_new_exception_msg(const mp_obj_type_t *exc_type, mp_rom_error_text_t msg);
     996                 :            : mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, ...); // counts args by number of % symbols in fmt, excluding %%; can only handle void* sizes (ie no float/double!)
     997                 :            : #endif
     998                 :            : #ifdef va_start
     999                 :            : mp_obj_t mp_obj_new_exception_msg_vlist(const mp_obj_type_t *exc_type, mp_rom_error_text_t fmt, va_list arg); // same fmt restrictions as above
    1000                 :            : #endif
    1001                 :            : mp_obj_t mp_obj_new_gen_wrap(mp_obj_t fun);
    1002                 :            : mp_obj_t mp_obj_new_closure(mp_obj_t fun, size_t n_closed, const mp_obj_t *closed);
    1003                 :            : mp_obj_t mp_obj_new_tuple(size_t n, const mp_obj_t *items);
    1004                 :            : mp_obj_t mp_obj_new_list(size_t n, mp_obj_t *items);
    1005                 :            : mp_obj_t mp_obj_new_dict(size_t n_args);
    1006                 :            : mp_obj_t mp_obj_new_set(size_t n_args, mp_obj_t *items);
    1007                 :            : mp_obj_t mp_obj_new_slice(mp_obj_t start, mp_obj_t stop, mp_obj_t step);
    1008                 :            : mp_obj_t mp_obj_new_bound_meth(mp_obj_t meth, mp_obj_t self);
    1009                 :            : mp_obj_t mp_obj_new_getitem_iter(mp_obj_t *args, mp_obj_iter_buf_t *iter_buf);
    1010                 :            : mp_obj_t mp_obj_new_module(qstr module_name);
    1011                 :            : mp_obj_t mp_obj_new_memoryview(byte typecode, size_t nitems, void *items);
    1012                 :            : 
    1013                 :            : const mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in);
    1014                 :            : const char *mp_obj_get_type_str(mp_const_obj_t o_in);
    1015                 :            : bool mp_obj_is_subclass_fast(mp_const_obj_t object, mp_const_obj_t classinfo); // arguments should be type objects
    1016                 :            : mp_obj_t mp_obj_cast_to_native_base(mp_obj_t self_in, mp_const_obj_t native_type);
    1017                 :            : 
    1018                 :            : void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind);
    1019                 :            : void mp_obj_print(mp_obj_t o, mp_print_kind_t kind);
    1020                 :            : void mp_obj_print_exception(const mp_print_t *print, mp_obj_t exc);
    1021                 :            : 
    1022                 :            : bool mp_obj_is_true(mp_obj_t arg);
    1023                 :            : bool mp_obj_is_callable(mp_obj_t o_in);
    1024                 :            : mp_obj_t mp_obj_equal_not_equal(mp_binary_op_t op, mp_obj_t o1, mp_obj_t o2);
    1025                 :            : bool mp_obj_equal(mp_obj_t o1, mp_obj_t o2);
    1026                 :            : 
    1027                 :            : // returns true if o is bool, small int or long int
    1028                 :          4 : static inline bool mp_obj_is_integer(mp_const_obj_t o) {
    1029   [ +  -  +  -  :          6 :     return mp_obj_is_int(o) || mp_obj_is_bool(o);
             +  +  -  + ]
    1030                 :            : }
    1031                 :            : 
    1032                 :            : mp_int_t mp_obj_get_int(mp_const_obj_t arg);
    1033                 :            : mp_int_t mp_obj_get_int_truncated(mp_const_obj_t arg);
    1034                 :            : bool mp_obj_get_int_maybe(mp_const_obj_t arg, mp_int_t *value);
    1035                 :            : #if MICROPY_PY_BUILTINS_FLOAT
    1036                 :            : mp_float_t mp_obj_get_float(mp_obj_t self_in);
    1037                 :            : bool mp_obj_get_float_maybe(mp_obj_t arg, mp_float_t *value);
    1038                 :            : void mp_obj_get_complex(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
    1039                 :            : bool mp_obj_get_complex_maybe(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
    1040                 :            : #endif
    1041                 :            : void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items); // *items may point inside a GC block
    1042                 :            : 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
    1043                 :            : size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool is_slice);
    1044                 :            : mp_obj_t mp_obj_id(mp_obj_t o_in);
    1045                 :            : mp_obj_t mp_obj_len(mp_obj_t o_in);
    1046                 :            : mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); // may return MP_OBJ_NULL
    1047                 :            : mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t val);
    1048                 :            : 
    1049                 :            : // cell
    1050                 :            : 
    1051                 :            : typedef struct _mp_obj_cell_t {
    1052                 :            :     mp_obj_base_t base;
    1053                 :            :     mp_obj_t obj;
    1054                 :            : } mp_obj_cell_t;
    1055                 :            : 
    1056                 :      48596 : static inline mp_obj_t mp_obj_cell_get(mp_obj_t self_in) {
    1057                 :      48596 :     mp_obj_cell_t *self = (mp_obj_cell_t *)MP_OBJ_TO_PTR(self_in);
    1058         [ +  + ]:      48596 :     return self->obj;
    1059                 :            : }
    1060                 :            : 
    1061                 :       1419 : static inline void mp_obj_cell_set(mp_obj_t self_in, mp_obj_t obj) {
    1062                 :       1419 :     mp_obj_cell_t *self = (mp_obj_cell_t *)MP_OBJ_TO_PTR(self_in);
    1063                 :       1419 :     self->obj = obj;
    1064                 :         54 : }
    1065                 :            : 
    1066                 :            : // int
    1067                 :            : // For long int, returns value truncated to mp_int_t
    1068                 :            : mp_int_t mp_obj_int_get_truncated(mp_const_obj_t self_in);
    1069                 :            : // Will raise exception if value doesn't fit into mp_int_t
    1070                 :            : mp_int_t mp_obj_int_get_checked(mp_const_obj_t self_in);
    1071                 :            : // Will raise exception if value is negative or doesn't fit into mp_uint_t
    1072                 :            : mp_uint_t mp_obj_int_get_uint_checked(mp_const_obj_t self_in);
    1073                 :            : 
    1074                 :            : // exception
    1075                 :            : bool mp_obj_is_native_exception_instance(mp_obj_t self_in);
    1076                 :            : bool mp_obj_is_exception_type(mp_obj_t self_in);
    1077                 :            : bool mp_obj_is_exception_instance(mp_obj_t self_in);
    1078                 :            : bool mp_obj_exception_match(mp_obj_t exc, mp_const_obj_t exc_type);
    1079                 :            : void mp_obj_exception_clear_traceback(mp_obj_t self_in);
    1080                 :            : void mp_obj_exception_add_traceback(mp_obj_t self_in, qstr file, size_t line, qstr block);
    1081                 :            : void mp_obj_exception_get_traceback(mp_obj_t self_in, size_t *n, size_t **values);
    1082                 :            : mp_obj_t mp_obj_exception_get_value(mp_obj_t self_in);
    1083                 :            : 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);
    1084                 :            : mp_obj_t mp_alloc_emergency_exception_buf(mp_obj_t size_in);
    1085                 :            : void mp_init_emergency_exception_buf(void);
    1086                 :        632 : static inline mp_obj_t mp_obj_new_exception_arg1(const mp_obj_type_t *exc_type, mp_obj_t arg) {
    1087   [ +  -  -  + ]:        632 :     assert(MP_OBJ_TYPE_GET_SLOT_OR_NULL(exc_type, make_new) == mp_obj_exception_make_new);
    1088                 :        632 :     return mp_obj_exception_make_new(exc_type, 1, 0, &arg);
    1089                 :            : }
    1090                 :            : 
    1091                 :            : // str
    1092                 :            : bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2);
    1093                 :            : qstr mp_obj_str_get_qstr(mp_obj_t self_in); // use this if you will anyway convert the string to a qstr
    1094                 :            : const char *mp_obj_str_get_str(mp_obj_t self_in); // use this only if you need the string to be null terminated
    1095                 :            : const char *mp_obj_str_get_data(mp_obj_t self_in, size_t *len);
    1096                 :            : mp_obj_t mp_obj_str_intern(mp_obj_t str);
    1097                 :            : mp_obj_t mp_obj_str_intern_checked(mp_obj_t obj);
    1098                 :            : void mp_str_print_quoted(const mp_print_t *print, const byte *str_data, size_t str_len, bool is_bytes);
    1099                 :            : 
    1100                 :            : #if MICROPY_PY_BUILTINS_FLOAT
    1101                 :            : // float
    1102                 :            : #if MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_FLOAT
    1103                 :            : static inline float mp_obj_get_float_to_f(mp_obj_t o) {
    1104                 :            :     return mp_obj_get_float(o);
    1105                 :            : }
    1106                 :            : 
    1107                 :            : static inline double mp_obj_get_float_to_d(mp_obj_t o) {
    1108                 :            :     return (double)mp_obj_get_float(o);
    1109                 :            : }
    1110                 :            : 
    1111                 :            : static inline mp_obj_t mp_obj_new_float_from_f(float o) {
    1112                 :            :     return mp_obj_new_float(o);
    1113                 :            : }
    1114                 :            : 
    1115                 :            : static inline mp_obj_t mp_obj_new_float_from_d(double o) {
    1116                 :            :     return mp_obj_new_float((mp_float_t)o);
    1117                 :            : }
    1118                 :            : #elif MICROPY_FLOAT_IMPL == MICROPY_FLOAT_IMPL_DOUBLE
    1119                 :        264 : static inline float mp_obj_get_float_to_f(mp_obj_t o) {
    1120                 :        264 :     return (float)mp_obj_get_float(o);
    1121                 :            : }
    1122                 :            : 
    1123                 :         74 : static inline double mp_obj_get_float_to_d(mp_obj_t o) {
    1124                 :         74 :     return mp_obj_get_float(o);
    1125                 :            : }
    1126                 :            : 
    1127                 :        242 : static inline mp_obj_t mp_obj_new_float_from_f(float o) {
    1128                 :        242 :     return mp_obj_new_float((mp_float_t)o);
    1129                 :            : }
    1130                 :            : 
    1131                 :         76 : static inline mp_obj_t mp_obj_new_float_from_d(double o) {
    1132                 :         76 :     return mp_obj_new_float(o);
    1133                 :            : }
    1134                 :            : #endif
    1135                 :            : #if MICROPY_FLOAT_HIGH_QUALITY_HASH
    1136                 :            : mp_int_t mp_float_hash(mp_float_t val);
    1137                 :            : #else
    1138                 :            : static inline mp_int_t mp_float_hash(mp_float_t val) {
    1139                 :            :     return (mp_int_t)val;
    1140                 :            : }
    1141                 :            : #endif
    1142                 :            : 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
    1143                 :            : 
    1144                 :            : // complex
    1145                 :            : void mp_obj_complex_get(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
    1146                 :            : 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
    1147                 :            : #else
    1148                 :            : #define mp_obj_is_float(o) (false)
    1149                 :            : #endif
    1150                 :            : 
    1151                 :            : // tuple
    1152                 :            : void mp_obj_tuple_get(mp_obj_t self_in, size_t *len, mp_obj_t **items);
    1153                 :            : void mp_obj_tuple_del(mp_obj_t self_in);
    1154                 :            : mp_int_t mp_obj_tuple_hash(mp_obj_t self_in);
    1155                 :            : 
    1156                 :            : // list
    1157                 :            : mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg);
    1158                 :            : mp_obj_t mp_obj_list_remove(mp_obj_t self_in, mp_obj_t value);
    1159                 :            : void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items);
    1160                 :            : void mp_obj_list_set_len(mp_obj_t self_in, size_t len);
    1161                 :            : void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value);
    1162                 :            : mp_obj_t mp_obj_list_sort(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs);
    1163                 :            : 
    1164                 :            : // dict
    1165                 :            : typedef struct _mp_obj_dict_t {
    1166                 :            :     mp_obj_base_t base;
    1167                 :            :     mp_map_t map;
    1168                 :            : } mp_obj_dict_t;
    1169                 :            : mp_obj_t mp_obj_dict_make_new(const mp_obj_type_t *type, size_t n_args, size_t n_kw, const mp_obj_t *args);
    1170                 :            : void mp_obj_dict_init(mp_obj_dict_t *dict, size_t n_args);
    1171                 :            : size_t mp_obj_dict_len(mp_obj_t self_in);
    1172                 :            : mp_obj_t mp_obj_dict_get(mp_obj_t self_in, mp_obj_t index);
    1173                 :            : mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value);
    1174                 :            : mp_obj_t mp_obj_dict_delete(mp_obj_t self_in, mp_obj_t key);
    1175                 :            : mp_obj_t mp_obj_dict_copy(mp_obj_t self_in);
    1176                 :        908 : static inline mp_map_t *mp_obj_dict_get_map(mp_obj_t dict) {
    1177         [ -  + ]:        908 :     return &((mp_obj_dict_t *)MP_OBJ_TO_PTR(dict))->map;
    1178                 :            : }
    1179                 :            : 
    1180                 :            : // set
    1181                 :            : void mp_obj_set_store(mp_obj_t self_in, mp_obj_t item);
    1182                 :            : 
    1183                 :            : // slice indexes resolved to particular sequence
    1184                 :            : typedef struct {
    1185                 :            :     mp_int_t start;
    1186                 :            :     mp_int_t stop;
    1187                 :            :     mp_int_t step;
    1188                 :            : } mp_bound_slice_t;
    1189                 :            : 
    1190                 :            : // slice
    1191                 :            : typedef struct _mp_obj_slice_t {
    1192                 :            :     mp_obj_base_t base;
    1193                 :            :     mp_obj_t start;
    1194                 :            :     mp_obj_t stop;
    1195                 :            :     mp_obj_t step;
    1196                 :            : } mp_obj_slice_t;
    1197                 :            : void mp_obj_slice_indices(mp_obj_t self_in, mp_int_t length, mp_bound_slice_t *result);
    1198                 :            : 
    1199                 :            : // functions
    1200                 :            : 
    1201                 :            : typedef struct _mp_obj_fun_builtin_fixed_t {
    1202                 :            :     mp_obj_base_t base;
    1203                 :            :     union {
    1204                 :            :         mp_fun_0_t _0;
    1205                 :            :         mp_fun_1_t _1;
    1206                 :            :         mp_fun_2_t _2;
    1207                 :            :         mp_fun_3_t _3;
    1208                 :            :     } fun;
    1209                 :            : } mp_obj_fun_builtin_fixed_t;
    1210                 :            : 
    1211                 :            : typedef struct _mp_obj_fun_builtin_var_t {
    1212                 :            :     mp_obj_base_t base;
    1213                 :            :     uint32_t sig; // see MP_OBJ_FUN_MAKE_SIG
    1214                 :            :     union {
    1215                 :            :         mp_fun_var_t var;
    1216                 :            :         mp_fun_kw_t kw;
    1217                 :            :     } fun;
    1218                 :            : } mp_obj_fun_builtin_var_t;
    1219                 :            : 
    1220                 :            : qstr mp_obj_fun_get_name(mp_const_obj_t fun);
    1221                 :            : 
    1222                 :            : mp_obj_t mp_identity(mp_obj_t self);
    1223                 :            : MP_DECLARE_CONST_FUN_OBJ_1(mp_identity_obj);
    1224                 :            : 
    1225                 :            : // module
    1226                 :            : typedef struct _mp_obj_module_t {
    1227                 :            :     mp_obj_base_t base;
    1228                 :            :     mp_obj_dict_t *globals;
    1229                 :            : } mp_obj_module_t;
    1230                 :         88 : static inline mp_obj_dict_t *mp_obj_module_get_globals(mp_obj_t module) {
    1231                 :         88 :     return ((mp_obj_module_t *)MP_OBJ_TO_PTR(module))->globals;
    1232                 :            : }
    1233                 :            : 
    1234                 :            : // staticmethod and classmethod types; defined here so we can make const versions
    1235                 :            : // this structure is used for instances of both staticmethod and classmethod
    1236                 :            : typedef struct _mp_obj_static_class_method_t {
    1237                 :            :     mp_obj_base_t base;
    1238                 :            :     mp_obj_t fun;
    1239                 :            : } mp_obj_static_class_method_t;
    1240                 :            : typedef struct _mp_rom_obj_static_class_method_t {
    1241                 :            :     mp_obj_base_t base;
    1242                 :            :     mp_rom_obj_t fun;
    1243                 :            : } mp_rom_obj_static_class_method_t;
    1244                 :            : 
    1245                 :            : // property
    1246                 :            : const mp_obj_t *mp_obj_property_get(mp_obj_t self_in);
    1247                 :            : 
    1248                 :            : // sequence helpers
    1249                 :            : 
    1250                 :            : void mp_seq_multiply(const void *items, size_t item_sz, size_t len, size_t times, void *dest);
    1251                 :            : #if MICROPY_PY_BUILTINS_SLICE
    1252                 :            : bool mp_seq_get_fast_slice_indexes(mp_uint_t len, mp_obj_t slice, mp_bound_slice_t *indexes);
    1253                 :            : #endif
    1254                 :            : #define mp_seq_copy(dest, src, len, item_t) memcpy(dest, src, len * sizeof(item_t))
    1255                 :            : #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)); }
    1256                 :            : bool mp_seq_cmp_bytes(mp_uint_t op, const byte *data1, size_t len1, const byte *data2, size_t len2);
    1257                 :            : 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);
    1258                 :            : mp_obj_t mp_seq_index_obj(const mp_obj_t *items, size_t len, size_t n_args, const mp_obj_t *args);
    1259                 :            : mp_obj_t mp_seq_count_obj(const mp_obj_t *items, size_t len, mp_obj_t value);
    1260                 :            : mp_obj_t mp_seq_extract_slice(size_t len, const mp_obj_t *seq, mp_bound_slice_t *indexes);
    1261                 :            : 
    1262                 :            : // Helper to clear stale pointers from allocated, but unused memory, to preclude GC problems
    1263                 :            : #define mp_seq_clear(start, len, alloc_len, item_sz) memset((byte *)(start) + (len) * (item_sz), 0, ((alloc_len) - (len)) * (item_sz))
    1264                 :            : 
    1265                 :            : // Note: dest and slice regions may overlap
    1266                 :            : #define mp_seq_replace_slice_no_grow(dest, dest_len, beg, end, slice, slice_len, item_sz) \
    1267                 :            :     memmove(((char *)dest) + (beg) * (item_sz), slice, slice_len * (item_sz)); \
    1268                 :            :     memmove(((char *)dest) + (beg + slice_len) * (item_sz), ((char *)dest) + (end) * (item_sz), (dest_len - end) * (item_sz));
    1269                 :            : 
    1270                 :            : // Note: dest and slice regions may overlap
    1271                 :            : #define mp_seq_replace_slice_grow_inplace(dest, dest_len, beg, end, slice, slice_len, len_adj, item_sz) \
    1272                 :            :     memmove(((char *)dest) + (beg + slice_len) * (item_sz), ((char *)dest) + (end) * (item_sz), ((dest_len) + (len_adj) - ((beg) + (slice_len))) * (item_sz)); \
    1273                 :            :     memmove(((char *)dest) + (beg) * (item_sz), slice, slice_len * (item_sz));
    1274                 :            : 
    1275                 :            : // Provide translation for legacy API
    1276                 :            : #define MP_OBJ_IS_SMALL_INT mp_obj_is_small_int
    1277                 :            : #define MP_OBJ_IS_QSTR mp_obj_is_qstr
    1278                 :            : #define MP_OBJ_IS_OBJ mp_obj_is_obj
    1279                 :            : #define MP_OBJ_IS_INT mp_obj_is_int
    1280                 :            : #define MP_OBJ_IS_TYPE mp_obj_is_type
    1281                 :            : #define MP_OBJ_IS_STR mp_obj_is_str
    1282                 :            : #define MP_OBJ_IS_STR_OR_BYTES mp_obj_is_str_or_bytes
    1283                 :            : #define MP_OBJ_IS_FUN mp_obj_is_fun
    1284                 :            : #define MP_MAP_SLOT_IS_FILLED mp_map_slot_is_filled
    1285                 :            : #define MP_SET_SLOT_IS_FILLED mp_set_slot_is_filled
    1286                 :            : 
    1287                 :            : #endif // MICROPY_INCLUDED_PY_OBJ_H

Generated by: LCOV version 1.15-5-g462f71d