@@ -532,12 +532,13 @@ struct _mp_obj_type_t {
532
532
// The name of this type, a qstr.
533
533
uint16_t name ;
534
534
535
- // Corresponds to __repr__ and __str__ special methods.
536
- mp_print_fun_t print ;
537
-
538
535
// Corresponds to __new__ and __init__ special methods, to make an instance of the type.
539
536
mp_make_new_fun_t make_new ;
540
537
538
+ #if MICROPY_OBJ_TYPE_REPR == MICROPY_OBJ_TYPE_REPR_FULL
539
+ // Corresponds to __repr__ and __str__ special methods.
540
+ mp_print_fun_t print ;
541
+
541
542
// Corresponds to __call__ special method, ie T(...).
542
543
mp_call_fun_t call ;
543
544
@@ -589,8 +590,33 @@ struct _mp_obj_type_t {
589
590
590
591
// A dict mapping qstrs to objects local methods/constants/etc.
591
592
struct _mp_obj_dict_t * locals_dict ;
593
+
594
+ #elif MICROPY_OBJ_TYPE_REPR == MICROPY_OBJ_TYPE_REPR_SLOT_INDEX
595
+
596
+ unsigned slot_index_print : MICROPY_OBJ_TYPE_SLOT_INDEX_BITS ;
597
+ unsigned slot_index_call : MICROPY_OBJ_TYPE_SLOT_INDEX_BITS ;
598
+ unsigned slot_index_unary_op : MICROPY_OBJ_TYPE_SLOT_INDEX_BITS ;
599
+ unsigned slot_index_binary_op : MICROPY_OBJ_TYPE_SLOT_INDEX_BITS ;
600
+ unsigned slot_index_attr : MICROPY_OBJ_TYPE_SLOT_INDEX_BITS ;
601
+ unsigned slot_index_subscr : MICROPY_OBJ_TYPE_SLOT_INDEX_BITS ;
602
+ unsigned slot_index_getiter : MICROPY_OBJ_TYPE_SLOT_INDEX_BITS ;
603
+ unsigned slot_index_iternext : MICROPY_OBJ_TYPE_SLOT_INDEX_BITS ;
604
+ unsigned slot_index_buffer : MICROPY_OBJ_TYPE_SLOT_INDEX_BITS ;
605
+ unsigned slot_index_protocol : MICROPY_OBJ_TYPE_SLOT_INDEX_BITS ;
606
+ unsigned slot_index_parent : MICROPY_OBJ_TYPE_SLOT_INDEX_BITS ;
607
+ unsigned slot_index_locals_dict : MICROPY_OBJ_TYPE_SLOT_INDEX_BITS ;
608
+
609
+ const void * slots [];
610
+
611
+ #endif
592
612
};
593
613
614
+ #define MP_TYPE_NULL_MAKE_NEW (NULL)
615
+
616
+ #if MICROPY_OBJ_TYPE_REPR == MICROPY_OBJ_TYPE_REPR_FULL
617
+
618
+ #define MICROPY_OBJ_TYPE_EXTRA_ALLOC (0)
619
+
594
620
#define MP_DEFINE_CONST_OBJ_TYPE_0 (_typename , _name , _flags , _make_new ) const mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new }
595
621
#define MP_DEFINE_CONST_OBJ_TYPE_1 (_typename , _name , _flags , _make_new , f1 , v1 ) const mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new, .f1 = v1 }
596
622
#define MP_DEFINE_CONST_OBJ_TYPE_2 (_typename , _name , _flags , _make_new , f1 , v1 , f2 , v2 ) const mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new, .f1 = v1, .f2 = v2 }
@@ -605,18 +631,57 @@ struct _mp_obj_type_t {
605
631
#define MP_DEFINE_CONST_OBJ_TYPE_11 (_typename , _name , _flags , _make_new , f1 , v1 , f2 , v2 , f3 , v3 , f4 , v4 , f5 , v5 , f6 , v6 , f7 , v7 , f8 , v8 , f9 , v9 , f10 , v10 , f11 , v11 ) const mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new, .f1 = v1, .f2 = v2, .f3 = v3, .f4 = v4, .f5 = v5, .f6 = v6, .f7 = v7, .f8 = v8, .f9 = v9, .f10 = v10, .f11 = v11 }
606
632
#define MP_DEFINE_CONST_OBJ_TYPE_12 (_typename , _name , _flags , _make_new , 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 mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new, .f1 = v1, .f2 = v2, .f3 = v3, .f4 = v4, .f5 = v5, .f6 = v6, .f7 = v7, .f8 = v8, .f9 = v9, .f10 = v10, .f11 = v11, .f12 = v12 }
607
633
608
- #define MP_DEFINE_CONST_OBJ_TYPE_IMPL (_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 , _29 , N , ...) MP_DEFINE_CONST_OBJ_TYPE_##N
609
- #define MP_DEFINE_CONST_OBJ_TYPE (...) MP_DEFINE_CONST_OBJ_TYPE_IMPL(__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, _INV, _INV, _INV)(__VA_ARGS__)
610
-
611
634
// Always safe, checks if the type can and does have this slot.
612
635
#define MP_OBJ_TYPE_HAS_SLOT (t , f ) ((t)->f)
613
636
// Requires you know that this type can have this slot.
614
637
#define MP_OBJ_TYPE_GET_SLOT (t , f ) ((t)->f)
615
638
// Always safe, returns NULL if the type cannot have this slot.
616
639
#define MP_OBJ_TYPE_GET_SLOT_OR_NULL (t , f ) ((t)->f)
617
- #define MP_OBJ_TYPE_SET_SLOT (t , f , v ) ((t)->f = v)
640
+ #define MP_OBJ_TYPE_SET_SLOT (t , f , v , n ) ((t)->f = v)
618
641
#define MP_OBJ_TYPE_OFFSETOF_SLOT (t , f ) (offsetof(mp_obj_type_t, f))
619
642
643
+ #elif MICROPY_OBJ_TYPE_REPR == MICROPY_OBJ_TYPE_REPR_SLOT_INDEX
644
+
645
+ #define MICROPY_OBJ_TYPE_EXTRA_ALLOC (12 * sizeof(void *))
646
+
647
+ #define MP_OBJ_TYPE_SLOT_TYPE_print (mp_print_fun_t)
648
+ #define MP_OBJ_TYPE_SLOT_TYPE_call (mp_call_fun_t)
649
+ #define MP_OBJ_TYPE_SLOT_TYPE_unary_op (mp_unary_op_fun_t)
650
+ #define MP_OBJ_TYPE_SLOT_TYPE_binary_op (mp_binary_op_fun_t)
651
+ #define MP_OBJ_TYPE_SLOT_TYPE_attr (mp_attr_fun_t)
652
+ #define MP_OBJ_TYPE_SLOT_TYPE_subscr (mp_subscr_fun_t)
653
+ #define MP_OBJ_TYPE_SLOT_TYPE_getiter (mp_getiter_fun_t)
654
+ #define MP_OBJ_TYPE_SLOT_TYPE_iternext (mp_fun_1_t)
655
+ #define MP_OBJ_TYPE_SLOT_TYPE_buffer (mp_buffer_fun_t)
656
+ #define MP_OBJ_TYPE_SLOT_TYPE_protocol (const void *)
657
+ #define MP_OBJ_TYPE_SLOT_TYPE_parent (const void *)
658
+ #define MP_OBJ_TYPE_SLOT_TYPE_locals_dict (struct _mp_obj_dict_t *)
659
+
660
+ #define MP_DEFINE_CONST_OBJ_TYPE_0 (_typename , _name , _flags , _make_new ) const mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new, .slots = {} }
661
+ #define MP_DEFINE_CONST_OBJ_TYPE_1 (_typename , _name , _flags , _make_new , f1 , v1 ) const mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new, .slot_index_##f1 = 1, .slots = {v1, } }
662
+ #define MP_DEFINE_CONST_OBJ_TYPE_2 (_typename , _name , _flags , _make_new , f1 , v1 , f2 , v2 ) const mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slots = {v1, v2, } }
663
+ #define MP_DEFINE_CONST_OBJ_TYPE_3 (_typename , _name , _flags , _make_new , f1 , v1 , f2 , v2 , f3 , v3 ) const mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slots = {v1, v2, v3, } }
664
+ #define MP_DEFINE_CONST_OBJ_TYPE_4 (_typename , _name , _flags , _make_new , f1 , v1 , f2 , v2 , f3 , v3 , f4 , v4 ) const mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new, .slot_index_##f1 = 1, .slot_index_##f2 = 2, .slot_index_##f3 = 3, .slot_index_##f4 = 4, .slots = {v1, v2, v3, v4, } }
665
+ #define MP_DEFINE_CONST_OBJ_TYPE_5 (_typename , _name , _flags , _make_new , f1 , v1 , f2 , v2 , f3 , v3 , f4 , v4 , f5 , v5 ) const mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new, .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, } }
666
+ #define MP_DEFINE_CONST_OBJ_TYPE_6 (_typename , _name , _flags , _make_new , f1 , v1 , f2 , v2 , f3 , v3 , f4 , v4 , f5 , v5 , f6 , v6 ) const mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new, .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, } }
667
+ #define MP_DEFINE_CONST_OBJ_TYPE_7 (_typename , _name , _flags , _make_new , f1 , v1 , f2 , v2 , f3 , v3 , f4 , v4 , f5 , v5 , f6 , v6 , f7 , v7 ) const mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new, .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, } }
668
+ #define MP_DEFINE_CONST_OBJ_TYPE_8 (_typename , _name , _flags , _make_new , f1 , v1 , f2 , v2 , f3 , v3 , f4 , v4 , f5 , v5 , f6 , v6 , f7 , v7 , f8 , v8 ) const mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new, .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, } }
669
+ #define MP_DEFINE_CONST_OBJ_TYPE_9 (_typename , _name , _flags , _make_new , f1 , v1 , f2 , v2 , f3 , v3 , f4 , v4 , f5 , v5 , f6 , v6 , f7 , v7 , f8 , v8 , f9 , v9 ) const mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new, .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, } }
670
+ #define MP_DEFINE_CONST_OBJ_TYPE_10 (_typename , _name , _flags , _make_new , f1 , v1 , f2 , v2 , f3 , v3 , f4 , v4 , f5 , v5 , f6 , v6 , f7 , v7 , f8 , v8 , f9 , v9 , f10 , v10 ) const mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new, .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, } }
671
+ #define MP_DEFINE_CONST_OBJ_TYPE_11 (_typename , _name , _flags , _make_new , f1 , v1 , f2 , v2 , f3 , v3 , f4 , v4 , f5 , v5 , f6 , v6 , f7 , v7 , f8 , v8 , f9 , v9 , f10 , v10 , f11 , v11 ) const mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new, .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, } }
672
+ #define MP_DEFINE_CONST_OBJ_TYPE_12 (_typename , _name , _flags , _make_new , 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 mp_obj_type_t _typename = { .base = { &mp_type_type }, .name = _name, .flags = _flags, .make_new = _make_new, .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, } }
673
+
674
+ #define MP_OBJ_TYPE_HAS_SLOT (t , f ) ((t)->slot_index_##f)
675
+ #define MP_OBJ_TYPE_GET_SLOT (t , f ) (MP_OBJ_TYPE_SLOT_TYPE_##f(t)->slots[(t)->slot_index_##f - 1])
676
+ #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))
677
+ #define MP_OBJ_TYPE_SET_SLOT (t , f , v , n ) ((t)->slot_index_##f = n, (t)->slots[(t)->slot_index_##f - 1] = (void *)v)
678
+ #define MP_OBJ_TYPE_OFFSETOF_SLOT (t , f ) (offsetof(mp_obj_type_t, slots) + (t)->slot_index_##f * sizeof(void *))
679
+
680
+ #endif
681
+
682
+ #define MP_DEFINE_CONST_OBJ_TYPE_IMPL (_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 , _29 , N , ...) MP_DEFINE_CONST_OBJ_TYPE_##N
683
+ #define MP_DEFINE_CONST_OBJ_TYPE (...) MP_DEFINE_CONST_OBJ_TYPE_IMPL(__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, _INV, _INV, _INV)(__VA_ARGS__)
684
+
620
685
// Constant types, globally accessible
621
686
extern const mp_obj_type_t mp_type_type ;
622
687
extern const mp_obj_type_t mp_type_object ;
0 commit comments