36 #if MICROPY_DEBUG_VERBOSE // print debugging info 37 #define DEBUG_PRINT (1) 38 #define DEBUG_printf DEBUG_printf 39 #else // don't print debugging info 40 #define DEBUG_PRINT (0) 41 #define DEBUG_printf(...) (void)0 65 *last_native_base = type;
75 for (; item < top; ++item) {
121 DEBUG_printf(
"mp_obj_class_lookup: Matched special meth slot (off=%d) for %s\n",
151 printf(
"mp_obj_class_lookup: Returning: ");
178 const mp_obj_t *top = item + parent_tuple->
len - 1;
179 for (; item < top; ++item) {
207 qstr meth = (kind ==
PRINT_STR) ? MP_QSTR___str__ : MP_QSTR___repr__;
219 lookup.
attr = MP_QSTR___repr__;
252 assert(num_native_bases < 2);
268 .attr = MP_QSTR___new__,
282 if (n_args == 0 && n_kw == 0) {
306 lookup.
attr = MP_QSTR___init__;
311 if (n_args == 0 && n_kw == 0) {
315 args2[0] = init_fn[0];
316 args2[1] = init_fn[1];
341 #if MICROPY_PY_ALL_SPECIAL_METHODS 347 #if MICROPY_PY_SYS_GETSIZEOF 355 #if MICROPY_PY_SYS_GETSIZEOF 361 size_t sz =
sizeof(*self) +
sizeof(*
self->subobj) * num_native_bases
362 +
sizeof(*self->members.table) *
self->members.alloc;
393 lookup.
attr = MP_QSTR___eq__;
429 #if MICROPY_PY_ALL_INPLACE_SPECIAL_METHODS 444 #if MICROPY_PY_ALL_SPECIAL_METHODS 458 #if MICROPY_PY_REVERSE_SPECIAL_METHODS 459 [MP_BINARY_OP_REVERSE_ADD] = MP_QSTR___radd__,
460 [MP_BINARY_OP_REVERSE_SUBTRACT] = MP_QSTR___rsub__,
461 #if MICROPY_PY_ALL_SPECIAL_METHODS 462 [MP_BINARY_OP_REVERSE_MULTIPLY] = MP_QSTR___rmul__,
463 [MP_BINARY_OP_REVERSE_FLOOR_DIVIDE] = MP_QSTR___rfloordiv__,
464 [MP_BINARY_OP_REVERSE_TRUE_DIVIDE] = MP_QSTR___rtruediv__,
465 [MP_BINARY_OP_REVERSE_MODULO] = MP_QSTR___rmod__,
466 [MP_BINARY_OP_REVERSE_POWER] = MP_QSTR___rpow__,
467 [MP_BINARY_OP_REVERSE_OR] = MP_QSTR___ror__,
468 [MP_BINARY_OP_REVERSE_XOR] = MP_QSTR___rxor__,
469 [MP_BINARY_OP_REVERSE_AND] = MP_QSTR___rand__,
470 [MP_BINARY_OP_REVERSE_LSHIFT] = MP_QSTR___rlshift__,
471 [MP_BINARY_OP_REVERSE_RSHIFT] = MP_QSTR___rrshift__,
515 #if MICROPY_PY_BUILTINS_NOTIMPLEMENTED 540 #if MICROPY_CPYTHON_COMPAT 541 if (
attr == MP_QSTR___dict__) {
547 for (
size_t i = 0; i < map->
alloc; ++i) {
548 if (MP_MAP_SLOT_IS_FILLED(map, i)) {
566 #if MICROPY_PY_BUILTINS_PROPERTY 585 #if MICROPY_PY_DESCRIPTORS 593 attr_get_method[2] = self_in;
602 if (
attr != MP_QSTR___getattr__) {
603 #if MICROPY_PY_DELATTR_SETATTR 607 if (
attr == MP_QSTR___setattr__ ||
attr == MP_QSTR___delattr__) {
627 #if MICROPY_PY_BUILTINS_PROPERTY || MICROPY_PY_DESCRIPTORS 643 #if MICROPY_PY_BUILTINS_PROPERTY 676 #if MICROPY_PY_DESCRIPTORS 684 attr_delete_method[2] = self_in;
693 attr_set_method[2] = self_in;
694 attr_set_method[3] = value;
705 #if MICROPY_PY_DELATTR_SETATTR 721 #if MICROPY_PY_DELATTR_SETATTR 728 attr_setattr_method[3] = value;
761 lookup.
attr = MP_QSTR___delitem__;
766 lookup.
attr = MP_QSTR___getitem__;
771 lookup.
attr = MP_QSTR___setitem__;
795 .attr = MP_QSTR___call__,
833 .attr = MP_QSTR___iter__,
843 return type->
getiter(self->subobj[0], iter_buf);
877 mp_printf(print,
"<class '%q'>", self->name);
905 if (self->make_new ==
NULL) {
910 "cannot create '%q' instances", self->
name));
927 #if MICROPY_CPYTHON_COMPAT 928 if (
attr == MP_QSTR___name__) {
946 if (self->locals_dict !=
NULL) {
948 mp_map_t *locals_map = &
self->locals_dict->map;
971 .
name = MP_QSTR_type,
989 for (
size_t i = 0; i < len; i++) {
998 "type '%q' is not an acceptable base type", t->
name));
1035 if (num_native_bases > 1) {
1106 size_t len = parent_tuple->
len;
1108 for (
size_t i = 0; i < len; i++) {
1127 .
name = MP_QSTR_super,
1145 if (
object == classinfo) {
1158 if (self->parent ==
NULL) {
1165 const mp_obj_t *top = item + parent_tuple->
len - 1;
1168 for (; item < top; ++item) {
1195 for (
size_t i = 0; i < len; i++) {
1225 return self->subobj[0];
1243 .
name = MP_QSTR_staticmethod,
1249 .
name = MP_QSTR_classmethod,
STATIC mp_obj_t instance_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_in)
qstr mp_obj_str_get_qstr(mp_obj_t self_in)
STATIC mp_obj_t mp_obj_new_instance(const mp_obj_type_t *class, size_t subobjs)
mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg)
#define mp_seq_clear(start, len, alloc_len, item_sz)
NORETURN void mp_raise_msg(const mp_obj_type_t *exc_type, const char *msg)
mp_obj_t mp_instance_cast_to_native_base(mp_const_obj_t self_in, mp_const_obj_t native_type)
STATIC mp_obj_t mp_obj_instance_get_call(mp_obj_t self_in, mp_obj_t *member)
STATIC mp_obj_t type_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
const char * qstr_str(qstr q)
void mp_load_method_maybe(mp_obj_t obj, qstr attr, mp_obj_t *dest)
STATIC mp_obj_t type_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
bool mp_obj_is_subclass_fast(mp_const_obj_t object, mp_const_obj_t classinfo)
#define MICROPY_ERROR_REPORTING_TERSE
STATIC mp_obj_t static_class_method_make_new(const mp_obj_type_t *self_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
STATIC mp_obj_t instance_unary_op(mp_unary_op_t op, mp_obj_t self_in)
mp_make_new_fun_t make_new
const mp_obj_type_t mp_type_TypeError
mp_unary_op_fun_t unary_op
#define MP_OBJ_IS_TYPE(o, t)
STATIC const uint8_t attr[]
#define m_del(type, ptr, num)
const mp_obj_type_t mp_type_classmethod
mp_obj_t mp_obj_new_exception_msg_varg(const mp_obj_type_t *exc_type, const char *fmt,...)
void mp_load_super_method(qstr attr, mp_obj_t *dest)
mp_obj_t mp_generic_unary_op(mp_unary_op_t op, mp_obj_t o_in)
void mp_map_init(mp_map_t *map, size_t n)
bool mp_obj_instance_is_callable(mp_obj_t self_in)
#define DEBUG_printf(...)
STATIC void type_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind)
void mp_obj_print(mp_obj_t o_in, mp_print_kind_t kind)
mp_obj_type_t * mp_obj_get_type(mp_const_obj_t o_in)
int mp_print_str(const mp_print_t *print, const char *str)
#define MP_OBJ_FROM_PTR(p)
const mp_obj_type_t mp_type_type
mp_binary_op_fun_t binary_op
#define MP_OBJ_NEW_QSTR(qst)
mp_int_t(* get_buffer)(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags)
#define offsetof(type, field)
void mp_arg_check_num(size_t n_args, size_t n_kw, size_t n_args_min, size_t n_args_max, bool takes_kw)
#define mp_obj_is_native_type(type)
mp_obj_t mp_obj_instance_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
mp_obj_t mp_obj_new_dict(size_t n_args)
#define mp_const_notimplemented
void mp_load_method(mp_obj_t base, qstr attr, mp_obj_t *dest)
mp_map_elem_t * mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t lookup_kind)
STATIC void super_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest)
STATIC mp_obj_t super_make_new(const mp_obj_type_t *type_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
STATIC mp_int_t instance_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, mp_uint_t flags)
STATIC int instance_count_native_bases(const mp_obj_type_t *type, const mp_obj_type_t **last_native_base)
#define MP_OBJ_NEW_SMALL_INT(small_int)
#define MICROPY_ERROR_REPORTING
STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value)
mp_obj_t mp_call_function_1(mp_obj_t fun, mp_obj_t arg)
STATIC mp_obj_t mp_builtin_isinstance(mp_obj_t object, mp_obj_t classinfo)
STATIC bool mp_obj_instance_store_attr(mp_obj_t self_in, qstr attr, mp_obj_t value)
#define m_new_obj_var(obj_type, var_type, var_num)
STATIC void super_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind)
STATIC mp_obj_t instance_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf)
const byte mp_binary_op_method_name[MP_BINARY_OP_NUM_RUNTIME]
STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo)
mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind)
mp_obj_t mp_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs)
void mp_obj_tuple_get(mp_obj_t self_in, size_t *len, mp_obj_t **items)
struct _mp_obj_static_class_method_t mp_obj_static_class_method_t
const mp_obj_type_t mp_type_staticmethod
MP_DEFINE_CONST_FUN_OBJ_2(mp_builtin_issubclass_obj, mp_builtin_issubclass)
const mp_obj_type_t mp_type_object
STATIC void type_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest)
#define mp_obj_is_native_exception_instance(o)
const mp_obj_type_t mp_type_AttributeError
#define m_new0(type, num)
mp_obj_t mp_call_method_n_kw(size_t n_args, size_t n_kw, const mp_obj_t *args)
mp_obj_t mp_obj_dict_store(mp_obj_t self_in, mp_obj_t key, mp_obj_t value)
const mp_obj_t * mp_obj_property_get(mp_obj_t self_in)
const mp_obj_type_t mp_type_super
void mp_convert_member_lookup(mp_obj_t self, const mp_obj_type_t *type, mp_obj_t member, mp_obj_t *dest)
const mp_obj_type_t mp_type_tuple
const mp_obj_type_t mp_type_dict
mp_obj_t mp_call_method_self_n_kw(mp_obj_t meth, mp_obj_t self, size_t n_args, size_t n_kw, const mp_obj_t *args)
const char * mp_obj_get_type_str(mp_const_obj_t o_in)
struct _mp_obj_super_t mp_obj_super_t
STATIC void instance_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t kind)
STATIC void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_type_t *type)
const byte mp_unary_op_method_name[MP_UNARY_OP_NUM_RUNTIME]
mp_obj_t mp_obj_instance_make_new(const mp_obj_type_t *self, size_t n_args, size_t n_kw, const mp_obj_t *args)
int mp_printf(const mp_print_t *print, const char *fmt,...)
mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, size_t n_args, size_t n_kw, const mp_obj_t *args)
#define mp_obj_is_instance_type(type)
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value)
const mp_obj_type_t mp_type_property
NORETURN void mp_raise_TypeError(const char *msg)
STATIC void mp_obj_instance_load_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest)
mp_int_t mp_obj_get_int_truncated(mp_const_obj_t arg)
STATIC mp_obj_t mp_builtin_issubclass(mp_obj_t object, mp_obj_t classinfo)
void * memcpy(void *dst, const void *src, size_t n)
void mp_obj_instance_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest)
struct _mp_obj_dict_t * locals_dict