8000 py, objtype.c: Rename class_ to instance_ following change of typedef. · hellcoderz/micropython@9c5fc83 · GitHub
[go: up one dir, main page]

Skip to content

Commit 9c5fc83

Browse files
committed
py, objtype.c: Rename class_ to instance_ following change of typedef.
This follows up 0a7e01a.
1 parent e69b7e8 commit 9c5fc83

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

py/objtype.c

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,18 @@
2222
/******************************************************************************/
2323
// instance object
2424

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);
2727

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) {
2929
mp_obj_instance_t *o = m_new_obj_var(mp_obj_instance_t, mp_obj_t, subobjs);
3030
o->base.type = class;
3131
mp_map_init(&o->members, 0);
3232
mp_seq_clear(o->subobj, 0, subobjs, sizeof(*o->subobj));
3333
return o;
3434
}
3535

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) {
3737
uint len;
3838
mp_obj_t *items;
3939
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
4545
*last_native_base = items[i];
4646
count++;
4747
} else {
48-
count += class_count_native_bases(items[i], last_native_base);
48+
count += instance_count_native_bases(items[i], last_native_base);
4949
}
5050
}
5151

@@ -63,7 +63,7 @@ STATIC int class_count_native_bases(const mp_obj_type_t *type, const mp_obj_type
6363
// applies to instance->subobj[0]. In most cases, we also don't need to know which type
6464
// it was - because instance->subobj[0] is of that type. The only exception is when
6565
// 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.
6767
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) {
6868
assert(dest[0] == NULL);
6969
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,
130130
}
131131
}
132132

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) {
134134
mp_obj_instance_t *self = self_in;
135135
qstr meth = (kind == PRINT_STR) ? MP_QSTR___str__ : MP_QSTR___repr__;
136136
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
163163
print(env, "<%s object at %p>", mp_obj_get_type_str(self_in), self_in);
164164
}
165165

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) {
167167
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_type));
168168
mp_obj_type_t *self = self_in;
169169

170170
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);
172172
assert(num_native_bases < 2);
173173

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);
175175

176176
// look for __init__ function
177177
mp_obj_t init_fn[2] = {MP_OBJ_NULL};
@@ -219,7 +219,7 @@ STATIC const qstr unary_op_method_name[] = {
219219
[MP_UNARY_OP_NOT] = MP_QSTR_, // don't need to implement this, used to make sure array has full size
220220
};
221221

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) {
223223
mp_obj_instance_t *self = self_in;
224224
qstr op_name = unary_op_method_name[op];
225225
/* Still try to lookup native slot
@@ -282,7 +282,7 @@ STATIC const qstr binary_op_method_name[] = {
282282
// and put the result in the dest[] array for a possible method call.
283283
// Conversion means dealing with static/class methods, callables, and values.
284284
// 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) {
286286
assert(dest[1] == NULL);
287287
if (MP_OBJ_IS_TYPE(member, &mp_type_staticmethod)) {
288288
// 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 *
301301
}
302302
}
303303

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) {
305305
// Note: For ducktyping, CPython does not look in the instance members or use
306306
// __getattr__ or __getattribute__. It only looks in the class dictionary.
307307
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) {
318318
} else if (member[0] != MP_OBJ_NULL) {
319319
mp_obj_t dest[3];
320320
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);
322322
dest[2] = rhs_in;
323323
return mp_call_method_n_kw(1, 0, dest);
324324
} else {
325325
return MP_OBJ_NOT_SUPPORTED;
326326
}
327327
}
328328

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) {
330330
// logic: look in obj members then class locals (TODO check this against CPython)
331331
mp_obj_instance_t *self = self_in;
332332

@@ -346,21 +346,21 @@ STATIC void class_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
346346
} else if (MP_OBJ_IS_TYPE(member, &mp_type_property)) {
347347
// object member is a property
348348
// 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?
350350
const mp_obj_t *proxy = mp_obj_property_get(member);
351351
if (proxy[0] == mp_const_none) {
352352
// TODO
353353
} else {
354354
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?
356356
}
357357
#endif
358358
} else {
359359
// not a property
360360
// if we don't yet have bound method (supposedly from native base), go
361361
// try to convert own attrs.
362362
if (dest[1] == MP_OBJ_NULL) {
363-
class_convert_return_attr(self_in, member, dest);
363+
instance_convert_return_attr(self_in, member, dest);
364364
}
365365
}
366366
return;
@@ -380,7 +380,7 @@ STATIC void class_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
380380
}
381381
}
382382

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) {
384384
mp_obj_instance_t *self = self_in;
385385

386386
#if MICROPY_ENABLE_PROPERTY
@@ -414,7 +414,7 @@ STATIC bool class_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value) {
414414
}
415415
}
416416

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) {
418418
mp_obj_instance_t *self = self_in;
419419
mp_obj_t member[2] = {MP_OBJ_NULL};
420420
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) {
435435
return mp_obj_subscr(self->subobj[0], index, value);
436436
} else if (member[0] != MP_OBJ_NULL) {
437437
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
439439
mp_obj_t ret = mp_call_function_n_kw(member[0], meth_args, 0, args);
440440
if (value == MP_OBJ_SENTINEL) {
441441
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) {
447447
}
448448
}
449449

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) {
451451
mp_obj_instance_t *self = self_in;
452452
mp_obj_t member[2] = {MP_OBJ_NULL};
453453
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)
605605
mp_obj_type_t *o = m_new0(mp_obj_type_t, 1);
606606
o->base.type = &mp_type_type;
607607
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;
616616
o->bases_tuple = bases_tuple;
617617
o->locals_dict = locals_dict;
618618

619619
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);
621621
if (num_native_bases > 1) {
622622
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError, "multiple bases have instance lay-out conflict"));
623623
}
@@ -674,7 +674,7 @@ STATIC void super_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
674674
mp_obj_t member[2] = {MP_OBJ_NULL};
675675
mp_obj_class_lookup(self->obj, (mp_obj_type_t*)items[i], attr, 0, member);
676676
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);
678678
return;
679679
}
680680
}

0 commit comments

Comments
 (0)
0