@@ -707,14 +707,14 @@ def register_int_ptr_type(convertor, *types):
707
707
#define LV_OBJ_T {obj_type}
708
708
709
709
typedef struct mp_lv_obj_type_t {{
710
- mp_obj_type_t mp_obj_type;
710
+ mp_obj_full_type_t mp_obj_type;
711
711
const lv_obj_class_t *lv_obj_class;
712
712
}} mp_lv_obj_type_t;
713
713
714
714
STATIC const mp_lv_obj_type_t mp_lv_{base_obj}_type;
715
715
STATIC const mp_lv_obj_type_t *mp_lv_obj_types[];
716
716
717
- STATIC inline const mp_obj_type_t *get_BaseObj_type()
717
+ STATIC inline const mp_obj_full_type_t *get_BaseObj_type()
718
718
{{
719
719
return &mp_lv_{base_obj}_type.mp_obj_type;
720
720
}}
@@ -756,23 +756,23 @@ def register_int_ptr_type(convertor, *types):
756
756
STATIC mp_obj_t lv_fun_builtin_var_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args);
757
757
STATIC mp_int_t mp_func_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags);
758
758
759
- GENMPY_UNUSED STATIC const mp_obj_type_t mp_lv_type_fun_builtin_var = {
760
- { &mp_type_type } ,
761
- .flags = MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN ,
762
- .name = MP_QSTR_function ,
763
- . call = lv_fun_builtin_var_call,
764
- . unary_op = mp_generic_unary_op,
765
- .buffer_p = { .get_buffer = mp_func_get_buffer }
766
- } ;
759
+ GENMPY_UNUSED STATIC MP_DEFINE_CONST_OBJ_TYPE(
760
+ mp_lv_type_fun_builtin_var ,
761
+ MP_QSTR_function ,
762
+ MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN ,
763
+ call, lv_fun_builtin_var_call,
764
+ unary_op, mp_generic_unary_op,
765
+ buffer, mp_func_get_buffer
766
+ ) ;
767
767
768
- GENMPY_UNUSED STATIC const mp_obj_type_t mp_lv_type_fun_builtin_static_var = {
769
- { &mp_type_type } ,
770
- .flags = MP_TYPE_FLAG_BUILTIN_FUN ,
771
- .name = MP_QSTR_function ,
772
- . call = lv_fun_builtin_var_call,
773
- . unary_op = mp_generic_unary_op,
774
- .buffer_p = { .get_buffer = mp_func_get_buffer }
775
- } ;
768
+ GENMPY_UNUSED STATIC MP_DEFINE_CONST_OBJ_TYPE(
769
+ mp_lv_type_fun_builtin_static_var ,
770
+ MP_QSTR_function ,
771
+ MP_TYPE_FLAG_BUILTIN_FUN ,
772
+ call, lv_fun_builtin_var_call,
773
+ unary_op, mp_generic_unary_op,
774
+ buffer, mp_func_get_buffer
775
+ ) ;
776
776
777
777
STATIC mp_obj_t lv_fun_builtin_var_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
778
778
assert(MP_OBJ_IS_TYPE(self_in, &mp_lv_type_fun_builtin_var) ||
@@ -826,11 +826,11 @@ def register_int_ptr_type(convertor, *types):
826
826
const mp_obj_type_t *native_type = ((mp_obj_base_t*)mp_obj)->type;
827
827
if (native_type == NULL)
828
828
return NULL;
829
- if (native_type-> parent == NULL ||
830
- (native_type->buffer_p.get_buffer == mp_blob_get_buffer) ||
831
- (native_type->buffer_p.get_buffer == mp_lv_obj_get_buffer))
829
+ if (MP_OBJ_TYPE_GET_SLOT_OR_NULL( native_type, parent) == NULL ||
830
+ (MP_OBJ_TYPE_GET_SLOT_OR_NULL( native_type, buffer) == mp_blob_get_buffer) ||
831
+ (MP_OBJ_TYPE_GET_SLOT_OR_NULL( native_type, buffer) == mp_lv_obj_get_buffer))
832
832
return mp_obj;
833
- while (native_type-> parent) native_type = native_type-> parent;
833
+ while (MP_OBJ_TYPE_GET_SLOT_OR_NULL( native_type, parent)) native_type = MP_OBJ_TYPE_GET_SLOT( native_type, parent) ;
834
834
return mp_obj_cast_to_native_base(mp_obj, MP_OBJ_FROM_PTR(native_type));
835
835
}
836
836
@@ -845,15 +845,15 @@ def register_int_ptr_type(convertor, *types):
845
845
STATIC mp_obj_t cast(mp_obj_t mp_obj, const mp_obj_type_t *mp_type)
846
846
{
847
847
mp_obj_t res = NULL;
848
- if (mp_obj == mp_const_none && mp_type-> make_new == &make_new_lv_struct) {
848
+ if (mp_obj == mp_const_none && MP_OBJ_TYPE_GET_SLOT_OR_NULL( mp_type, make_new) == &make_new_lv_struct) {
849
849
res = MP_OBJ_FROM_PTR(&mp_lv_null_obj);
850
850
} else if (MP_OBJ_IS_OBJ(mp_obj)) {
851
851
res = get_native_obj(mp_obj);
852
852
if (res){
853
853
const mp_obj_type_t *res_type = ((mp_obj_base_t*)res)->type;
854
854
if (res_type != mp_type){
855
855
if (res_type == &mp_type_dict &&
856
- mp_type-> make_new == &make_new_lv_struct)
856
+ MP_OBJ_TYPE_GET_SLOT_OR_NULL( mp_type, make_new) == &make_new_lv_struct)
857
857
res = dict_to_struct(res, mp_type);
858
858
else res = NULL;
859
859
}
@@ -880,7 +880,7 @@ def register_int_ptr_type(convertor, *types):
880
880
{
881
881
if (mp_obj == NULL || mp_obj == mp_const_none) return NULL;
882
882
mp_obj_t native_obj = get_native_obj(mp_obj);
883
- if (mp_obj_get_type(native_obj)->buffer_p.get_buffer != mp_lv_obj_get_buffer)
883
+ if (MP_OBJ_TYPE_GET_SLOT_OR_NULL( mp_obj_get_type(native_obj), buffer) != mp_lv_obj_get_buffer)
884
884
return NULL;
885
885
mp_lv_obj_t *mp_lv_obj = MP_OBJ_TO_PTR(native_obj);
886
886
if (mp_lv_obj->lv_obj == NULL) {
@@ -903,7 +903,7 @@ def register_int_ptr_type(convertor, *types):
903
903
return mp_lv_obj->callbacks;
904
904
}
905
905
906
- STATIC inline const mp_obj_type_t *get_BaseObj_type();
906
+ STATIC inline const mp_obj_full_type_t *get_BaseObj_type();
907
907
908
908
STATIC void mp_lv_delete_cb(lv_event_t * e)
909
909
{
@@ -923,7 +923,7 @@ def register_int_ptr_type(convertor, *types):
923
923
if (!self)
924
924
{
925
925
// Find the object type
926
- const mp_obj_type_t *mp_obj_type = get_BaseObj_type();
926
+ const mp_obj_full_type_t *mp_obj_type = get_BaseObj_type();
927
927
const lv_obj_class_t *lv_obj_class = lv_obj_get_class(lv_obj);
928
928
const mp_lv_obj_type_t **iter = &mp_lv_obj_types[0];
929
929
for (; *iter; iter++) {
@@ -936,7 +936,7 @@ def register_int_ptr_type(convertor, *types):
936
936
// Create the MP object
937
937
self = m_new_obj(mp_lv_obj_t);
938
938
*self = (mp_lv_obj_t){
939
- .base = {mp_obj_type},
939
+ .base = {(const mp_obj_type_t *) mp_obj_type},
940
940
.lv_obj = lv_obj,
941
941
.callbacks = NULL,
942
942
};
@@ -1026,7 +1026,7 @@ def register_int_ptr_type(convertor, *types):
1026
1026
#else // LV_OBJ_T
1027
1027
1028
1028
typedef struct mp_lv_obj_type_t {
1029
- mp_obj_type_t mp_obj_type;
1029
+ mp_obj_full_type_t mp_obj_type;
1030
1030
} mp_lv_obj_type_t;
1031
1031
1032
1032
#endif
@@ -1063,7 +1063,7 @@ def register_int_ptr_type(convertor, *types):
1063
1063
{
1064
1064
if (mp_obj == NULL || mp_obj == mp_const_none) return NULL;
1065
1065
mp_obj_t native_obj = get_native_obj(mp_obj);
1066
- if ( (!MP_OBJ_IS_OBJ(native_obj)) || (mp_obj_get_type(native_obj)-> make_new != &make_new_lv_struct) ) nlr_raise(
1066
+ if ( (!MP_OBJ_IS_OBJ(native_obj)) || (MP_OBJ_TYPE_GET_SLOT_OR_NULL( mp_obj_get_type(native_obj), make_new) != &make_new_lv_struct) ) nlr_raise(
1067
1067
mp_obj_new_exception_msg(
1068
1068
&mp_type_SyntaxError, MP_ERROR_TEXT("Expected Struct object!")));
1069
1069
mp_lv_struct_t *mp_lv_struct = MP_OBJ_TO_PTR(native_obj);
@@ -1072,7 +1072,7 @@ def register_int_ptr_type(convertor, *types):
1072
1072
1073
1073
STATIC inline size_t get_lv_struct_size(const mp_obj_type_t *type)
1074
1074
{
1075
- mp_obj_t size_obj = mp_obj_dict_get(type-> locals_dict, MP_OBJ_NEW_QSTR(MP_QSTR___SIZE__));
1075
+ mp_obj_t size_obj = mp_obj_dict_get(MP_OBJ_TYPE_GET_SLOT( type, locals_dict) , MP_OBJ_NEW_QSTR(MP_QSTR___SIZE__));
1076
1076
return (size_t)mp_obj_get_int(size_obj);
1077
1077
}
1078
1078
@@ -1082,7 +1082,7 @@ def register_int_ptr_type(convertor, *types):
1082
1082
size_t n_kw,
1083
1083
const mp_obj_t *args)
1084
1084
{
1085
- if ((!MP_OBJ_IS_TYPE(type, &mp_type_type)) || type-> make_new != &make_new_lv_struct)
1085
+ if ((!MP_OBJ_IS_TYPE(type, &mp_type_type)) || MP_OBJ_TYPE_GET_SLOT_OR_NULL( type, make_new) != &make_new_lv_struct)
1086
1086
nlr_raise(
1087
1087
mp_obj_new_exception_msg(
1088
1088
&mp_type_SyntaxError, MP_ERROR_TEXT("Argument is not a struct type!")));
@@ -1181,21 +1181,21 @@ def register_int_ptr_type(convertor, *types):
1181
1181
STATIC void call_parent_methods(mp_obj_t obj, qstr attr, mp_obj_t *dest)
1182
1182
{
1183
1183
const mp_obj_type_t *type = mp_obj_get_type(obj);
1184
- while (type->locals_dict != NULL ) {
1184
+ while (MP_OBJ_TYPE_HAS_SLOT( type, locals_dict) ) {
1185
1185
// generic method lookup
1186
1186
// this is a lookup in the object (ie not class or type)
1187
- assert(type-> locals_dict->base.type == &mp_type_dict); // MicroPython restriction, for now
1188
- mp_map_t *locals_map = &type-> locals_dict->map;
1187
+ assert(MP_OBJ_TYPE_GET_SLOT( type, locals_dict) ->base.type == &mp_type_dict); // MicroPython restriction, for now
1188
+ mp_map_t *locals_map = &MP_OBJ_TYPE_GET_SLOT( type, locals_dict) ->map;
1189
1189
mp_map_elem_t *elem = mp_map_lookup(locals_map, MP_OBJ_NEW_QSTR(attr), MP_MAP_LOOKUP);
1190
1190
if (elem != NULL) {
1191
1191
mp_convert_member_lookup(obj, type, elem->value, dest);
1192
1192
break;
1193
1193
}
1194
- if (type-> parent == NULL) {
1194
+ if (MP_OBJ_TYPE_GET_SLOT_OR_NULL( type, parent) == NULL) {
1195
1195
break;
1196
1196
}
1197
1197
// search parents
1198
- type = type-> parent;
1198
+ type = MP_OBJ_TYPE_GET_SLOT( type, parent) ;
1199
1199
}
1200
1200
}
1201
1201
@@ -1212,7 +1212,7 @@ def register_int_ptr_type(convertor, *types):
1212
1212
mp_obj_t value = map->table[i].value;
1213
1213
if (key != MP_OBJ_NULL) {
1214
1214
mp_obj_t dest[] = {MP_OBJ_SENTINEL, value};
1215
- type-> attr(mp_struct, mp_obj_str_get_qstr(key), dest);
1215
+ MP_OBJ_TYPE_GET_SLOT( type, attr) (mp_struct, mp_obj_str_get_qstr(key), dest);
1216
1216
if (dest[0]) nlr_raise(
1217
1217
mp_obj_new_exception_msg_varg(
1218
1218
&mp_type_SyntaxError, MP_ERROR_TEXT("Cannot set field %s on struct %s!"), qstr_str(mp_obj_str_get_qstr(key)), qstr_str(type->name)));
@@ -1312,15 +1312,15 @@ def register_int_ptr_type(convertor, *types):
1312
1312
1313
1313
STATIC MP_DEFINE_CONST_DICT(mp_blob_locals_dict, mp_blob_locals_dict_table);
1314
1314
1315
- STATIC const mp_obj_type_t mp_blob_type = {
1316
- { &mp_type_type } ,
1317
- .name = MP_QSTR_Blob,
1318
- .binary_op = lv_struct_binary_op ,
1319
- .print = mp_blob_print ,
1320
- //.make_new = make_new_blob ,
1321
- . locals_dict = (mp_obj_dict_t*) &mp_blob_locals_dict,
1322
- .buffer_p = { .get_buffer = mp_blob_get_buffer }
1323
- } ;
1315
+ STATIC MP_DEFINE_CONST_OBJ_TYPE(
1316
+ mp_blob_type ,
1317
+ MP_QSTR_Blob,
1318
+ MP_TYPE_FLAG_NONE ,
1319
+ binary_op, lv_struct_binary_op ,
1320
+ print, mp_blob_print ,
1321
+ locals_dict, &mp_blob_locals_dict,
1322
+ buffer, mp_blob_get_buffer
1323
+ ) ;
1324
1324
1325
1325
STATIC const mp_lv_struct_t mp_lv_null_obj = { {&mp_blob_type}, NULL };
1326
1326
@@ -1512,25 +1512,27 @@ def register_int_ptr_type(convertor, *types):
1512
1512
1513
1513
STATIC MP_DEFINE_CONST_DICT(mp_base_struct_locals_dict, mp_base_struct_locals_dict_table);
1514
1514
1515
- STATIC const mp_obj_type_t mp_lv_base_struct_type = {
1516
- { &mp_type_type },
1517
- .name = MP_QSTR_Struct,
1518
- .binary_op = lv_struct_binary_op,
1519
- .subscr = lv_struct_subscr,
1520
- .locals_dict = (mp_obj_dict_t*)&mp_base_struct_locals_dict,
1521
- .buffer_p = { .get_buffer = mp_blob_get_buffer }
1522
- };
1515
+ MP_DEFINE_CONST_OBJ_TYPE(
1516
+ mp_lv_base_struct_type,
1517
+ MP_QSTR_Struct,
1518
+ MP_TYPE_FLAG_NONE,
1519
+ binary_op, lv_struct_binary_op,
1520
+ subscr, lv_struct_subscr,
1521
+ buffer, mp_blob_get_buffer,
1522
+ locals_dict, &mp_base_struct_locals_dict
1523
+ );
1523
1524
1524
- STATIC const mp_obj_type_t mp_lv_array_type = {
1525
- { &mp_type_type },
1526
- .name = MP_QSTR_C_Array,
1527
- .print = mp_lv_array_print,
1528
- .make_new = NULL, // TODO: provide constructor
1529
- .binary_op = lv_struct_binary_op,
1530
- .subscr = lv_array_subscr,
1531
- .buffer_p = { .get_buffer = mp_blob_get_buffer },
1532
- .locals_dict = (mp_obj_dict_t*)&mp_base_struct_locals_dict,
1533
- };
1525
+ // TODO: provide constructor
1526
+ MP_DEFINE_CONST_OBJ_TYPE(
1527
+ mp_lv_array_type,
1528
+ MP_QSTR_C_Array,
1529
+ MP_TYPE_FLAG_NONE,
1530
+ print, mp_lv_array_print,
1531
+ binary_op, lv_struct_binary_op,
1532
+ subscr, lv_array_subscr,
1533
+ buffer, mp_blob_get_buffer,
1534
+ locals_dict, &mp_base_struct_locals_dict
1535
+ );
1534
1536
1535
1537
GENMPY_UNUSED STATIC mp_obj_t mp_array_from_ptr(void *lv_arr, size_t element_size, bool is_signed)
1536
1538
{
@@ -1894,18 +1896,19 @@ def try_generate_struct(struct_name, struct):
1894
1896
1895
1897
STATIC const mp_obj_dict_t mp_{sanitized_struct_name}_locals_dict;
1896
1898
1897
- STATIC const mp_obj_type_t mp_{sanitized_struct_name}_type = {{
1898
- {{ &mp_type_type }},
1899
- .name = MP_QSTR_{sanitized_struct_name},
1900
- .print = mp_{sanitized_struct_name}_print,
1901
- .make_new = make_new_lv_struct,
1902
- .binary_op = lv_struct_binary_op,
1903
- .subscr = lv_struct_subscr,
1904
- .attr = mp_{sanitized_struct_name}_attr,
1905
- .locals_dict = (mp_obj_dict_t*)&mp_{sanitized_struct_name}_locals_dict,
1906
- .buffer_p = {{ .get_buffer = mp_blob_get_buffer }},
1907
- .parent = &mp_lv_base_struct_type
1908
- }};
1899
+ STATIC MP_DEFINE_CONST_OBJ_TYPE(
1900
+ mp_{sanitized_struct_name}_type,
1901
+ MP_QSTR_{sanitized_struct_name},
1902
+ MP_TYPE_FLAG_NONE,
1903
+ print, mp_{sanitized_struct_name}_print,
1904
+ make_new, make_new_lv_struct,
1905
+ binary_op, lv_struct_binary_op,
1906
+ subscr, lv_struct_subscr,
1907
+ attr, mp_{sanitized_struct_name}_attr,
1908
+ locals_dict, &mp_{sanitized_struct_name}_locals_dict,
1909
+ buffer, mp_blob_get_buffer,
1910
+ parent, &mp_lv_base_struct_type
1911
+ );
1909
1912
1910
1913
STATIC inline const mp_obj_type_t *get_mp_{sanitized_struct_name}_type()
1911
1914
{{
@@ -2558,20 +2561,23 @@ def gen_obj(obj_name):
2558
2561
2559
2562
{ctor}
2560
2563
2561
- STATIC const mp_lv_obj_type_t mp_lv_{obj}_type = {{
2562
- {{
2563
- {{ &mp_type_type } },
2564
- .name = MP_QSTR_{obj} ,
2565
- . print = {obj}_print,
2564
+ STATIC MP_DEFINE_CONST_OBJ_FULL_TYPE(
2565
+ mp_lv_{obj}_type_base,
2566
+ MP_QSTR_{obj },
2567
+ MP_TYPE_FLAG_NONE ,
2568
+ print, {obj}_print,
2566
2569
{make_new}
2567
2570
{binary_op}
2568
- .attr = call_parent_methods,
2569
- .locals_dict = (mp_obj_dict_t*)&{obj}_locals_dict,
2570
- {buffer_p}
2571
- .parent = {parent}
2572
- }},
2571
+ attr, call_parent_methods,
2572
+ {buffer}
2573
+ {parent}
2574
+ locals_dict, &{obj}_locals_dict
2575
+ );
2576
+
2577
+ STATIC const mp_lv_obj_type_t mp_lv_{obj}_type = {{
2578
+ .mp_obj_type = mp_lv_{obj}_type_base,
2573
2579
#ifdef LV_OBJ_T
2574
- {lv_class}
2580
+ .lv_obj_class = {lv_class}
2575
2581
#endif
2576
2582
}};
2577
2583
""" .format (
@@ -2580,10 +2586,10 @@ def gen_obj(obj_name):
2580
2586
base_class = '&mp_%s_type' % base_obj_name if should_add_base_methods else 'NULL' ,
2581
2587
locals_dict_entries = ",\n " .join (gen_obj_methods (obj_name )),
2582
2588
ctor = ctor .format (obj = obj_name , ctor_name = ctor_func .name ) if has_ctor (obj_name ) else '' ,
2583
- make_new = '. make_new = %s_make_new,' % obj_name if is_obj else '' ,
2584
- binary_op = '. binary_op = mp_lv_obj_binary_op,' if is_obj else '' ,
2585
- buffer_p = '.buffer_p = { .get_buffer = mp_lv_obj_get_buffer } ,' if is_obj else '' ,
2586
- parent = '&mp_lv_%s_type.mp_obj_type' % parent_obj_names [obj_name ] if obj_name in parent_obj_names and parent_obj_names [obj_name ] else 'NULL ' ,
2589
+ make_new = 'make_new, %s_make_new,' % obj_name if is_obj else '' ,
2590
+ binary_op = 'binary_op, mp_lv_obj_binary_op,' if is_obj else '' ,
2591
+ buffer = 'buffer, mp_lv_obj_get_buffer,' if is_obj else '' ,
2592
+ parent = 'parent, &mp_lv_%s_type.mp_obj_type, ' % parent_obj_names [obj_name ] if obj_name in parent_obj_names and parent_obj_names [obj_name ] else '' ,
2587
2593
lv_class = '&lv_%s_class' % obj_name if is_obj else 'NULL' ,
2588
2594
))
2589
2595
0 commit comments