22
22
/******************************************************************************/
23
23
// instance object
24
24
25
- #define is_native_type (type ) ((type)->make_new != class_make_new )
26
- STATIC mp_obj_t class_make_new (mp_obj_t self_in , uint n_args , uint n_kw , const mp_obj_t * args );
25
+ #define is_native_type (type ) ((type)->make_new != instance_make_new )
26
+ STATIC mp_obj_t instance_make_new (mp_obj_t self_in , uint n_args , uint n_kw , const mp_obj_t * args );
27
27
28
- STATIC mp_obj_t mp_obj_new_class (mp_obj_t class , uint subobjs ) {
28
+ STATIC mp_obj_t mp_obj_new_instance (mp_obj_t class , uint subobjs ) {
29
29
mp_obj_instance_t * o = m_new_obj_var (mp_obj_instance_t , mp_obj_t , subobjs );
30
30
o -> base .type = class ;
31
31
mp_map_init (& o -> members , 0 );
32
32
mp_seq_clear (o -> subobj , 0 , subobjs , sizeof (* o -> subobj ));
33
33
return o ;
34
34
}
35
35
36
- STATIC int class_count_native_bases (const mp_obj_type_t * type , const mp_obj_type_t * * last_native_base ) {
36
+ STATIC int instance_count_native_bases (const mp_obj_type_t * type , const mp_obj_type_t * * last_native_base ) {
37
37
uint len ;
38
38
mp_obj_t * items ;
39
39
mp_obj_tuple_get (type -> bases_tuple , & len , & items );
@@ -45,7 +45,7 @@ STATIC int class_count_native_bases(const mp_obj_type_t *type, const mp_obj_type
45
45
* last_native_base = items [i ];
46
46
count ++ ;
47
47
} else {
48
- count += class_count_native_bases (items [i ], last_native_base );
48
+ count += instance_count_native_bases (items [i ], last_native_base );
49
49
}
50
50
}
51
51
@@ -63,7 +63,7 @@ STATIC int class_count_native_bases(const mp_obj_type_t *type, const mp_obj_type
63
63
// applies to instance->subobj[0]. In most cases, we also don't need to know which type
64
64
// it was - because instance->subobj[0] is of that type. The only exception is when
65
65
// object is not yet constructed, then we need to know base native type to construct
66
- // instance->subobj[0]. This case is handled via class_count_native_bases () though.
66
+ // instance->subobj[0]. This case is handled via instance_count_native_bases () though.
67
67
STATIC void mp_obj_class_lookup (mp_obj_instance_t * o , const mp_obj_type_t * type , qstr attr , machine_uint_t meth_offset , mp_obj_t * dest ) {
68
68
assert (dest [0 ] == NULL );
69
69
assert (dest [1 ] == NULL );
@@ -130,7 +130,7 @@ STATIC void mp_obj_class_lookup(mp_obj_instance_t *o, const mp_obj_type_t *type,
130
130
}
131
131
}
132
132
133
- STATIC void class_print (void (* print )(void * env , const char * fmt , ...), void * env , mp_obj_t self_in , mp_print_kind_t kind ) {
133
+ STATIC void instance_print (void (* print )(void * env , const char * fmt , ...), void * env , mp_obj_t self_in , mp_print_kind_t kind ) {
134
134
mp_obj_instance_t * self = self_in ;
135
135
qstr meth = (kind == PRINT_STR ) ? MP_QSTR___str__ : MP_QSTR___repr__ ;
136
136
mp_obj_t member [2 ] = {MP_OBJ_NULL };
@@ -163,15 +163,15 @@ STATIC void class_print(void (*print)(void *env, const char *fmt, ...), void *en
163
163
print (env , "<%s object at %p>" , mp_obj_get_type_str (self_in ), self_in );
164
164
}
165
165
166
- STATIC mp_obj_t class_make_new (mp_obj_t self_in , uint n_args , uint n_kw , const mp_obj_t * args ) {
166
+ STATIC mp_obj_t instance_make_new (mp_obj_t self_in , uint n_args , uint n_kw , const mp_obj_t * args ) {
167
167
assert (MP_OBJ_IS_TYPE (self_in , & mp_type_type ));
168
168
mp_obj_type_t * self = self_in ;
169
169
170
170
const mp_obj_type_t * native_base ;
171
- uint num_native_bases = class_count_native_bases (self , & native_base );
171
+ uint num_native_bases = instance_count_native_bases (self , & native_base );
172
172
assert (num_native_bases < 2 );
173
173
174
- mp_obj_instance_t * o = mp_obj_new_class (self_in , num_native_bases );
174
+ mp_obj_instance_t * o = mp_obj_new_instance (self_in , num_native_bases );
175
175
176
176
// look for __init__ function
177
177
mp_obj_t init_fn [2 ] = {MP_OBJ_NULL };
@@ -219,7 +219,7 @@ STATIC const qstr unary_op_method_name[] = {
219
219
[MP_UNARY_OP_NOT ] = MP_QSTR_ , // don't need to implement this, used to make sure array has full size
220
220
};
221
221
222
- STATIC mp_obj_t class_unary_op (int op , mp_obj_t self_in ) {
222
+ STATIC mp_obj_t instance_unary_op (int op , mp_obj_t self_in ) {
223
223
mp_obj_instance_t * self = self_in ;
224
224
qstr op_name = unary_op_method_name [op ];
225
225
/* Still try to lookup native slot
@@ -282,7 +282,7 @@ STATIC const qstr binary_op_method_name[] = {
282
282
// and put the result in the dest[] array for a possible method call.
283
283
// Conversion means dealing with static/class methods, callables, and values.
284
284
// see http://docs.python.org/3.3/howto/descriptor.html
285
- STATIC void class_convert_return_attr (mp_obj_t self , mp_obj_t member , mp_obj_t * dest ) {
285
+ STATIC void instance_convert_return_attr (mp_obj_t self , mp_obj_t member , mp_obj_t * dest ) {
286
286
assert (dest [1 ] == NULL );
287
287
if (MP_OBJ_IS_TYPE (member , & mp_type_staticmethod )) {
288
288
// return just the function
@@ -301,7 +301,7 @@ STATIC void class_convert_return_attr(mp_obj_t self, mp_obj_t member, mp_obj_t *
301
301
}
302
302
}
303
303
304
- STATIC mp_obj_t class_binary_op (int op , mp_obj_t lhs_in , mp_obj_t rhs_in ) {
304
+ STATIC mp_obj_t instance_binary_op (int op , mp_obj_t lhs_in , mp_obj_t rhs_in ) {
305
305
// Note: For ducktyping, CPython does not look in the instance members or use
306
306
// __getattr__ or __getattribute__. It only looks in the class dictionary.
307
307
mp_obj_instance_t * lhs = lhs_in ;
@@ -318,15 +318,15 @@ STATIC mp_obj_t class_binary_op(int op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
318
318
} else if (member [0 ] != MP_OBJ_NULL ) {
319
319
mp_obj_t dest [3 ];
320
320
dest [1 ] = MP_OBJ_NULL ;
321
- class_convert_return_attr (lhs_in , member [0 ], dest );
321
+ instance_convert_return_attr (lhs_in , member [0 ], dest );
322
322
dest [2 ] = rhs_in ;
323
323
return mp_call_method_n_kw (1 , 0 , dest );
324
324
} else {
325
325
return MP_OBJ_NOT_SUPPORTED ;
326
326
}
327
327
}
328
328
329
- STATIC void class_load_attr (mp_obj_t self_in , qstr attr , mp_obj_t * dest ) {
329
+ STATIC void instance_load_attr (mp_obj_t self_in , qstr attr , mp_obj_t * dest ) {
330
330
// logic: look in obj members then class locals (TODO check this against CPython)
331
331
mp_obj_instance_t * self = self_in ;
332
332
@@ -346,21 +346,21 @@ STATIC void class_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
346
346
} else if (MP_OBJ_IS_TYPE (member , & mp_type_property )) {
347
347
// object member is a property
348
348
// delegate the store to the property
349
- // TODO should this be part of class_convert_return_attr ?
349
+ // TODO should this be part of instance_convert_return_attr ?
350
350
const mp_obj_t * proxy = mp_obj_property_get (member );
351
351
if (proxy [0 ] == mp_const_none ) {
352
352
// TODO
353
353
} else {
354
354
dest [0 ] = mp_call_function_n_kw (proxy [0 ], 1 , 0 , & self_in );
355
- // TODO should we convert the returned value using class_convert_return_attr ?
355
+ // TODO should we convert the returned value using instance_convert_return_attr ?
356
356
}
357
357
#endif
358
358
} else {
359
359
// not a property
360
360
// if we don't yet have bound method (supposedly from native base), go
361
361
// try to convert own attrs.
362
362
if (dest [1 ] == MP_OBJ_NULL ) {
363
- class_convert_return_attr (self_in , member , dest );
363
+ instance_convert_return_attr (self_in , member , dest );
364
364
}
365
365
}
366
366
return ;
@@ -380,7 +380,7 @@ STATIC void class_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
380
380
}
381
381
}
382
382
383
- STATIC bool class_store_attr (mp_obj_t self_in , qstr attr , mp_obj_t value ) {
383
+ STATIC bool instance_store_attr (mp_obj_t self_in , qstr attr , mp_obj_t value ) {
384
384
mp_obj_instance_t * self = self_in ;
385
385
386
386
#if MICROPY_ENABLE_PROPERTY
@@ -414,7 +414,7 @@ STATIC bool class_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) {
414
414
}
415
415
}
416
416
417
- STATIC mp_obj_t class_subscr (mp_obj_t self_in , mp_obj_t index , mp_obj_t value ) {
417
+ STATIC mp_obj_t instance_subscr (mp_obj_t self_in , mp_obj_t index , mp_obj_t value ) {
418
418
mp_obj_instance_t * self = self_in ;
419
419
mp_obj_t member [2 ] = {MP_OBJ_NULL };
420
420
uint meth_args ;
@@ -435,7 +435,7 @@ STATIC mp_obj_t class_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
435
435
return mp_obj_subscr (self -> subobj [0 ], index , value );
436
436
} else if (member [0 ] != MP_OBJ_NULL ) {
437
437
mp_obj_t args [3 ] = {self_in , index , value };
438
- // TODO probably need to call class_convert_return_attr , and use mp_call_method_n_kw
438
+ // TODO probably need to call instance_convert_return_attr , and use mp_call_method_n_kw
439
439
mp_obj_t ret = mp_call_function_n_kw (member [0 ], meth_args , 0 , args );
440
440
if (value == MP_OBJ_SENTINEL ) {
441
441
return ret ;
@@ -447,7 +447,7 @@ STATIC mp_obj_t class_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
447
447
}
448
448
}
449
449
450
- STATIC mp_obj_t class_call (mp_obj_t self_in , uint n_args , uint n_kw , const mp_obj_t * args ) {
450
+ STATIC mp_obj_t instance_call (mp_obj_t self_in , uint n_args , uint n_kw , const mp_obj_t * args ) {
451
451
mp_obj_instance_t * self = self_in ;
452
452
mp_obj_t member [2 ] = {MP_OBJ_NULL };
453
453
mp_obj_class_lookup (self , self -> base .type , MP_QSTR___call__ , offsetof(mp_obj_type_t , call ), member );
@@ -605,19 +605,19 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
605
605
mp_obj_type_t * o = m_new0 (mp_obj_type_t , 1 );
606
606
o -> base .type = & mp_type_type ;
607
607
o -> name = name ;
608
- o -> print = class_print ;
609
- o -> make_new = class_make_new ;
610
- o -> unary_op = class_unary_op ;
611
- o -> binary_op = class_binary_op ;
612
- o -> load_attr = class_load_attr ;
613
- o -> store_attr = class_store_attr ;
614
- o -> subscr = class_subscr ;
615
- o -> call = class_call ;
608
+ o -> print = instance_print ;
609
+ o -> make_new = instance_make_new ;
610
+ o -> unary_op = instance_unary_op ;
611
+ o -> binary_op = instance_binary_op ;
612
+ o -> load_attr = instance_load_attr ;
613
+ o -> store_attr = instance_store_attr ;
614
+ o -> subscr = instance_subscr ;
615
+ o -> call = instance_call ;
616
616
o -> bases_tuple = bases_tuple ;
617
617
o -> locals_dict = locals_dict ;
618
618
619
619
const mp_obj_type_t * native_base ;
620
- uint num_native_bases = class_count_native_bases (o , & native_base );
620
+ uint num_native_bases = instance_count_native_bases (o , & native_base );
621
621
if (num_native_bases > 1 ) {
622
622
nlr_raise (mp_obj_new_exception_msg (& mp_type_TypeError , "multiple bases have instance lay-out conflict" ));
623
623
}
@@ -674,7 +674,7 @@ STATIC void super_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
674
674
mp_obj_t member [2 ] = {MP_OBJ_NULL };
675
675
mp_obj_class_lookup (self -> obj , (mp_obj_type_t * )items [i ], attr , 0 , member );
676
676
if (member [0 ] != MP_OBJ_NULL ) {
677
- class_convert_return_attr (self -> obj , member [0 ], dest );
677
+ instance_convert_return_attr (self -> obj , member [0 ], dest );
678
678
return ;
679
679
}
680
680
}
0 commit comments