@@ -16,24 +16,6 @@ MLC_REGISTER_FUNC("mlc.testing.cxx_raw_str").set_body([](const char *x) { return
16
16
17
17
/* *************** Reflection ****************/
18
18
19
- struct ReflectionTestObj : public Object {
20
- Str x_mutable;
21
- int32_t y_immutable;
22
-
23
- ReflectionTestObj (std::string x, int32_t y) : x_mutable(x), y_immutable(y) {}
24
- int32_t YPlusOne () { return y_immutable + 1 ; }
25
-
26
- MLC_DEF_DYN_TYPE (ReflectionTestObj, Object, " mlc.testing.ReflectionTestObj" );
27
- };
28
-
29
- struct ReflectionTest : public ObjectRef {
30
- MLC_DEF_OBJ_REF (ReflectionTest, ReflectionTestObj, ObjectRef)
31
- .Field(" x_mutable" , &ReflectionTestObj::x_mutable)
32
- .FieldReadOnly(" y_immutable" , &ReflectionTestObj::y_immutable)
33
- .StaticFn(" __init__" , InitOf<ReflectionTestObj, std::string, int32_t >)
34
- .MemFn(" YPlusOne" , &ReflectionTestObj::YPlusOne);
35
- };
36
-
37
19
struct TestingCClassObj : public Object {
38
20
int8_t i8 ;
39
21
int16_t i16 ;
@@ -49,13 +31,64 @@ struct TestingCClassObj : public Object {
49
31
UList ulist;
50
32
UDict udict;
51
33
Str str_;
34
+ Str str_readonly;
35
+
36
+ List<Any> list_any;
37
+ List<List<int >> list_list_int;
38
+ Dict<Any, Any> dict_any_any;
39
+ Dict<Str, Any> dict_str_any;
40
+ Dict<Any, Str> dict_any_str;
41
+ Dict<Str, List<int >> dict_str_list_int;
42
+
43
+ Optional<int64_t > opt_i64;
44
+ Optional<double > opt_f64;
45
+ Optional<void *> opt_raw_ptr;
46
+ Optional<DLDataType> opt_dtype;
47
+ Optional<DLDevice> opt_device;
48
+ Optional<Func> opt_func;
49
+ Optional<UList> opt_ulist;
50
+ Optional<UDict> opt_udict;
51
+ Optional<Str> opt_str;
52
+
53
+ Optional<List<Any>> opt_list_any;
54
+ Optional<List<List<int >>> opt_list_list_int;
55
+ Optional<Dict<Any, Any>> opt_dict_any_any;
56
+ Optional<Dict<Str, Any>> opt_dict_str_any;
57
+ Optional<Dict<Any, Str>> opt_dict_any_str;
58
+ Optional<Dict<Str, List<int >>> opt_dict_str_list_int;
52
59
53
60
explicit TestingCClassObj (int8_t i8 , int16_t i16 , int32_t i32 , int64_t i64 , float f32 , double f64 , void *raw_ptr,
54
- DLDataType dtype, DLDevice device, Any any, Func func, UList ulist, UDict udict, Str str_)
61
+ DLDataType dtype, DLDevice device, Any any, Func func, UList ulist, UDict udict, Str str_,
62
+ Str str_readonly,
63
+ //
64
+ List<Any> list_any, List<List<int >> list_list_int, Dict<Any, Any> dict_any_any,
65
+ Dict<Str, Any> dict_str_any, Dict<Any, Str> dict_any_str,
66
+ Dict<Str, List<int >> dict_str_list_int,
67
+ //
68
+ Optional<int64_t > opt_i64, Optional<double > opt_f64, Optional<void *> opt_raw_ptr,
69
+ Optional<DLDataType> opt_dtype, Optional<DLDevice> opt_device, Optional<Func> opt_func,
70
+ Optional<UList> opt_ulist, Optional<UDict> opt_udict, Optional<Str> opt_str,
71
+ //
72
+ Optional<List<Any>> opt_list_any, Optional<List<List<int >>> opt_list_list_int,
73
+ Optional<Dict<Any, Any>> opt_dict_any_any, Optional<Dict<Str, Any>> opt_dict_str_any,
74
+ Optional<Dict<Any, Str>> opt_dict_any_str,
75
+ Optional<Dict<Str, List<int >>> opt_dict_str_list_int)
55
76
: i8(i8 ), i16(i16 ), i32(i32 ), i64(i64 ), f32(f32 ), f64(f64 ), raw_ptr(raw_ptr), dtype(dtype), device(device),
56
- any(any), func(func), ulist(ulist), udict(udict), str_(str_) {}
57
-
58
- MLC_DEF_DYN_TYPE (ReflectionTestObj, Object, " mlc.testing.c_class" );
77
+ any(any), func(func), ulist(ulist), udict(udict), str_(str_), str_readonly(str_readonly),
78
+ //
79
+ list_any(list_any), list_list_int(list_list_int), dict_any_any(dict_any_any), dict_str_any(dict_str_any),
80
+ dict_any_str(dict_any_str), dict_str_list_int(dict_str_list_int),
81
+ //
82
+ opt_i64(opt_i64), opt_f64(opt_f64), opt_raw_ptr(opt_raw_ptr), opt_dtype(opt_dtype), opt_device(opt_device),
83
+ opt_func(opt_func), opt_ulist(opt_ulist), opt_udict(opt_udict), opt_str(opt_str),
84
+ //
85
+ opt_list_any(opt_list_any), opt_list_list_int(opt_list_list_int), opt_dict_any_any(opt_dict_any_any),
86
+ opt_dict_str_any(opt_dict_str_any), opt_dict_any_str(opt_dict_any_str),
87
+ opt_dict_str_list_int(opt_dict_str_list_int) {}
88
+
89
+ int64_t i64_plus_one () const { return i64 + 1 ; }
90
+
91
+ MLC_DEF_DYN_TYPE (TestingCClassObj, Object, " mlc.testing.c_class" );
59
92
};
60
93
61
94
struct TestingCClass : public ObjectRef {
@@ -74,8 +107,44 @@ struct TestingCClass : public ObjectRef {
74
107
.Field(" ulist" , &TestingCClassObj::ulist)
75
108
.Field(" udict" , &TestingCClassObj::udict)
76
109
.Field(" str_" , &TestingCClassObj::str_)
77
- .StaticFn(" __init__" , InitOf<TestingCClassObj, int8_t , int16_t , int32_t , int64_t , float , double , void *,
78
- DLDataType, DLDevice, Any, Func, UList, UDict, Str>);
110
+ .FieldReadOnly(" str_readonly" , &TestingCClassObj::str_readonly)
111
+ //
112
+ .Field(" list_any" , &TestingCClassObj::list_any)
113
+ .Field(" list_list_int" , &TestingCClassObj::list_list_int)
114
+ .Field(" dict_any_any" , &TestingCClassObj::dict_any_any)
115
+ .Field(" dict_str_any" , &TestingCClassObj::dict_str_any)
116
+ .Field(" dict_any_str" , &TestingCClassObj::dict_any_str)
117
+ .Field(" dict_str_list_int" , &TestingCClassObj::dict_str_list_int)
118
+ //
119
+ .Field(" opt_i64" , &TestingCClassObj::opt_i64)
120
+ .Field(" opt_f64" , &TestingCClassObj::opt_f64)
121
+ .Field(" opt_raw_ptr" , &TestingCClassObj::opt_raw_ptr)
122
+ .Field(" opt_dtype" , &TestingCClassObj::opt_dtype)
123
+ .Field(" opt_device" , &TestingCClassObj::opt_device)
124
+ .Field(" opt_func" , &TestingCClassObj::opt_func)
125
+ .Field(" opt_ulist" , &TestingCClassObj::opt_ulist)
126
+ .Field(" opt_udict" , &TestingCClassObj::opt_udict)
127
+ .Field(" opt_str" , &TestingCClassObj::opt_str)
128
+ //
129
+ .Field(" opt_list_any" , &TestingCClassObj::opt_list_any)
130
+ .Field(" opt_list_list_int" , &TestingCClassObj::opt_list_list_int)
131
+ .Field(" opt_dict_any_any" , &TestingCClassObj::opt_dict_any_any)
132
+ .Field(" opt_dict_str_any" , &TestingCClassObj::opt_dict_str_any)
133
+ .Field(" opt_dict_any_str" , &TestingCClassObj::opt_dict_any_str)
134
+ .Field(" opt_dict_str_list_int" , &TestingCClassObj::opt_dict_str_list_int)
135
+ //
136
+ .MemFn(" i64_plus_one" , &TestingCClassObj::i64_plus_one)
137
+ .StaticFn(" __init__" ,
138
+ InitOf<TestingCClassObj, int8_t , int16_t , int32_t , int64_t , float , double , void *, DLDataType, DLDevice,
139
+ Any, Func, UList, UDict, Str, Str,
140
+ //
141
+ List<Any>, List<List<int >>, Dict<Any, Any>, Dict<Str, Any>, Dict<Any, Str>, Dict<Str, List<int >>,
142
+ //
143
+ Optional<int64_t >, Optional<double >, Optional<void *>, Optional<DLDataType>, Optional<DLDevice>,
144
+ Optional<Func>, Optional<UList>, Optional<UDict>, Optional<Str>,
145
+ //
146
+ Optional<List<Any>>, Optional<List<List<int >>>, Optional<Dict<Any, Any>>,
147
+ Optional<Dict<Str, Any>>, Optional<Dict<Any, Str>>, Optional<Dict<Str, List<int >>>>);
79
148
};
80
149
81
150
/* *************** Traceback ****************/
0 commit comments