WIP
This commit is contained in:
parent
cd119ca3ec
commit
df56ba207f
@ -295,6 +295,7 @@ STATIC MP_DEFINE_CONST_DICT(btree_locals_dict, btree_locals_dict_table);
|
||||
STATIC const mp_obj_type_t btree_type = {
|
||||
{ &mp_type_type },
|
||||
// Save on qstr's, reuse same as for module
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_btree,
|
||||
.print = btree_print,
|
||||
.getiter = btree_getiter,
|
||||
|
@ -602,6 +602,7 @@ STATIC MP_DEFINE_CONST_DICT(framebuf_locals_dict, framebuf_locals_dict_table);
|
||||
|
||||
STATIC const mp_obj_type_t mp_type_framebuf = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_FrameBuffer,
|
||||
.make_new = framebuf_make_new,
|
||||
.buffer_p = { .get_buffer = framebuf_get_buffer },
|
||||
|
@ -284,6 +284,7 @@ STATIC mp_obj_t task_iternext(mp_obj_t self_in) {
|
||||
|
||||
STATIC const mp_obj_type_t task_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_Task,
|
||||
.make_new = task_make_new,
|
||||
.attr = task_attr,
|
||||
|
@ -622,6 +622,7 @@ MP_DEFINE_CONST_FUN_OBJ_2(uctypes_struct_bytes_at_obj, uctypes_struct_bytes_at);
|
||||
|
||||
STATIC const mp_obj_type_t uctypes_struct_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_struct,
|
||||
.print = uctypes_struct_print,
|
||||
.make_new = uctypes_struct_make_new,
|
||||
|
@ -193,6 +193,7 @@ STATIC MP_DEFINE_CONST_DICT(utimeq_locals_dict, utimeq_locals_dict_table);
|
||||
|
||||
STATIC const mp_obj_type_t utimeq_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_utimeq,
|
||||
.make_new = utimeq_make_new,
|
||||
.unary_op = utimeq_unary_op,
|
||||
|
@ -122,6 +122,7 @@ STATIC const mp_stream_p_t decompio_stream_p = {
|
||||
#if !MICROPY_ENABLE_DYNRUNTIME
|
||||
STATIC const mp_obj_type_t decompio_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_DecompIO,
|
||||
.make_new = decompio_make_new,
|
||||
.protocol = &decompio_stream_p,
|
||||
|
@ -474,6 +474,7 @@ STATIC const mp_vfs_proto_t fat_vfs_proto = {
|
||||
|
||||
const mp_obj_type_t mp_fat_vfs_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_VfsFat,
|
||||
.make_new = fat_vfs_make_new,
|
||||
.protocol = &fat_vfs_proto,
|
||||
|
@ -244,6 +244,7 @@ STATIC const mp_stream_p_t vfs_fat_fileio_stream_p = {
|
||||
|
||||
const mp_obj_type_t mp_type_vfs_fat_fileio = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_FileIO,
|
||||
.print = file_obj_print,
|
||||
.make_new = file_obj_make_new,
|
||||
|
@ -484,6 +484,7 @@ STATIC const mp_vfs_proto_t MP_VFS_LFSx(proto) = {
|
||||
|
||||
const mp_obj_type_t MP_TYPE_VFS_LFSx = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
#if LFS_BUILD_VERSION == 1
|
||||
.name = MP_QSTR_VfsLfs1,
|
||||
#else
|
||||
|
@ -226,6 +226,7 @@ STATIC const mp_stream_p_t MP_VFS_LFSx(fileio_stream_p) = {
|
||||
|
||||
const mp_obj_type_t MP_TYPE_VFS_LFSx_(_fileio) = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_FileIO,
|
||||
.print = MP_VFS_LFSx(file_print),
|
||||
.getiter = mp_identity_getiter,
|
||||
|
@ -352,6 +352,7 @@ STATIC const mp_vfs_proto_t vfs_posix_proto = {
|
||||
|
||||
const mp_obj_type_t mp_type_vfs_posix = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_VfsPosix,
|
||||
.make_new = vfs_posix_make_new,
|
||||
.protocol = &vfs_posix_proto,
|
||||
|
@ -213,6 +213,7 @@ STATIC const mp_stream_p_t vfs_posix_fileio_stream_p = {
|
||||
|
||||
const mp_obj_type_t mp_type_vfs_posix_fileio = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_FileIO,
|
||||
.print = vfs_posix_file_print,
|
||||
.make_new = vfs_posix_file_make_new,
|
||||
|
@ -129,6 +129,7 @@ STATIC const mp_stream_p_t stdio_obj_stream_p = {
|
||||
|
||||
STATIC const mp_obj_type_t stdio_obj_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_FileIO,
|
||||
// TODO .make_new?
|
||||
.print = stdio_obj_print,
|
||||
|
113
py/obj.h
113
py/obj.h
@ -515,6 +515,7 @@ typedef mp_obj_t (*mp_fun_kw_t)(size_t n, const mp_obj_t *, mp_map_t *);
|
||||
#define MP_TYPE_FLAG_EQ_HAS_NEQ_TEST (0x0010)
|
||||
#define MP_TYPE_FLAG_BINDS_SELF (0x0020)
|
||||
#define MP_TYPE_FLAG_BUILTIN_FUN (0x0040)
|
||||
#define MP_TYPE_FLAG_FULL (0x0080) // contains the 'ext' fields
|
||||
|
||||
typedef enum {
|
||||
PRINT_STR = 0,
|
||||
@ -556,11 +557,51 @@ typedef struct _mp_buffer_info_t {
|
||||
#define MP_BUFFER_WRITE (2)
|
||||
#define MP_BUFFER_RW (MP_BUFFER_READ | MP_BUFFER_WRITE)
|
||||
typedef struct _mp_buffer_p_t {
|
||||
mp_int_t (*get_buffer)(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
|
||||
mp_getbuffer_fun_t get_buffer;
|
||||
} mp_buffer_p_t;
|
||||
bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
|
||||
void mp_get_buffer_raise(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags);
|
||||
|
||||
struct _mp_obj_type_ext {
|
||||
// Corresponds to __call__ special method, ie T(...).
|
||||
#define MP_TYPE_CALL(o) ext[0].call = o
|
||||
mp_call_fun_t call;
|
||||
|
||||
// Implements unary and binary operations.
|
||||
// Can return MP_OBJ_NULL if the operation is not supported.
|
||||
#define MP_TYPE_UNARY_OP(o) ext[0].unary_op = (o)
|
||||
mp_unary_op_fun_t unary_op;
|
||||
#define MP_TYPE_BINARY_OP(o) ext[0].binary_op = (o)
|
||||
mp_binary_op_fun_t binary_op;
|
||||
|
||||
// Implements load, store and delete subscripting:
|
||||
// - value = MP_OBJ_SENTINEL means load
|
||||
// - value = MP_OBJ_NULL means delete
|
||||
// - all other values mean store the value
|
||||
// Can return MP_OBJ_NULL if operation not supported.
|
||||
#define MP_TYPE_SUBSCR(o) ext[0].subscr = (o)
|
||||
mp_subscr_fun_t subscr;
|
||||
|
||||
// Corresponds to __iter__ special method.
|
||||
// Can use the given mp_obj_iter_buf_t to store iterator object,
|
||||
// otherwise can return a pointer to an object on the heap.
|
||||
#define MP_TYPE_GETITER(o) ext[0].getiter = (o)
|
||||
mp_getiter_fun_t getiter;
|
||||
|
||||
// Corresponds to __next__ special method. May return MP_OBJ_STOP_ITERATION
|
||||
// as an optimisation instead of raising StopIteration() with no args.
|
||||
#define MP_TYPE_ITERNEXT(o) ext[0].iternext = (o)
|
||||
mp_fun_1_t iternext;
|
||||
|
||||
// Implements the buffer protocol if supported by this type.
|
||||
#define MP_TYPE_GETBUFFER(o) ext[0].buffer_p.getbuffer = (o)
|
||||
mp_buffer_p_t buffer_p;
|
||||
|
||||
// One of disjoint protocols (interfaces), like mp_stream_p_t, etc.
|
||||
#define MP_TYPE_PROTOCOL(o) ext[0].protocol = (o)
|
||||
const void *protocol;
|
||||
};
|
||||
|
||||
struct _mp_obj_type_t {
|
||||
// A type is an object so must start with this entry, which points to mp_type_type.
|
||||
mp_obj_base_t base;
|
||||
@ -571,19 +612,14 @@ struct _mp_obj_type_t {
|
||||
// The name of this type, a qstr.
|
||||
uint16_t name;
|
||||
|
||||
// Corresponds to __repr__ and __str__ special methods.
|
||||
mp_print_fun_t print;
|
||||
// A dict mapping qstrs to objects local methods/constants/etc.
|
||||
struct _mp_obj_dict_t *locals_dict;
|
||||
|
||||
// Corresponds to __new__ and __init__ special methods, to make an instance of the type.
|
||||
mp_make_new_fun_t make_new;
|
||||
|
||||
// Corresponds to __call__ special method, ie T(...).
|
||||
mp_call_fun_t call;
|
||||
|
||||
// Implements unary and binary operations.
|
||||
// Can return MP_OBJ_NULL if the operation is not supported.
|
||||
mp_unary_op_fun_t unary_op;
|
||||
mp_binary_op_fun_t binary_op;
|
||||
// Corresponds to __repr__ and __str__ special methods.
|
||||
mp_print_fun_t print;
|
||||
|
||||
// Implements load, store and delete attribute.
|
||||
//
|
||||
@ -598,27 +634,46 @@ struct _mp_obj_type_t {
|
||||
// for success set dest[0] = MP_OBJ_NULL
|
||||
mp_attr_fun_t attr;
|
||||
|
||||
// Implements load, store and delete subscripting:
|
||||
// - value = MP_OBJ_SENTINEL means load
|
||||
// - value = MP_OBJ_NULL means delete
|
||||
// - all other values mean store the value
|
||||
// Can return MP_OBJ_NULL if operation not supported.
|
||||
mp_subscr_fun_t subscr;
|
||||
// A pointer to the parents of this type:
|
||||
// - 0 parents: pointer is NULL (object is implicitly the single parent)
|
||||
// - 1 parent: a pointer to the type of that parent
|
||||
// - 2 or more parents: pointer to a tuple object containing the parent types
|
||||
const void *parent;
|
||||
|
||||
// Corresponds to __iter__ special method.
|
||||
// Can use the given mp_obj_iter_buf_t to store iterator object,
|
||||
// otherwise can return a pointer to an object on the heap.
|
||||
mp_getiter_fun_t getiter;
|
||||
struct _mp_obj_type_ext ext[];
|
||||
};
|
||||
|
||||
// Corresponds to __next__ special method. May return MP_OBJ_STOP_ITERATION
|
||||
// as an optimisation instead of raising StopIteration() with no args.
|
||||
mp_fun_1_t iternext;
|
||||
struct _mp_obj_full_type_t {
|
||||
// A type is an object so must start with this entry, which points to mp_type_type.
|
||||
mp_obj_base_t base;
|
||||
|
||||
// Implements the buffer protocol if supported by this type.
|
||||
mp_buffer_p_t buffer_p;
|
||||
// Flags associated with this type.
|
||||
uint16_t flags;
|
||||
|
||||
// One of disjoint protocols (interfaces), like mp_stream_p_t, etc.
|
||||
const void *protocol;
|
||||
// The name of this type, a qstr.
|
||||
uint16_t name;
|
||||
|
||||
// A dict mapping qstrs to objects local methods/constants/etc.
|
||||
struct _mp_obj_dict_t *locals_dict;
|
||||
|
||||
// Corresponds to __new__ and __init__ special methods, to make an instance of the type.
|
||||
mp_make_new_fun_t make_new;
|
||||
|
||||
// Corresponds to __repr__ and __str__ special methods.
|
||||
mp_print_fun_t print;
|
||||
|
||||
// Implements load, store and delete attribute.
|
||||
//
|
||||
// dest[0] = MP_OBJ_NULL means load
|
||||
// return: for fail, do nothing
|
||||
// for attr, dest[0] = value
|
||||
// for method, dest[0] = method, dest[1] = self
|
||||
//
|
||||
// dest[0,1] = {MP_OBJ_SENTINEL, MP_OBJ_NULL} means delete
|
||||
// dest[0,1] = {MP_OBJ_SENTINEL, object} means store
|
||||
// return: for fail, do nothing
|
||||
// for success set dest[0] = MP_OBJ_NULL
|
||||
mp_attr_fun_t attr;
|
||||
|
||||
// A pointer to the parents of this type:
|
||||
// - 0 parents: pointer is NULL (object is implicitly the single parent)
|
||||
@ -626,10 +681,10 @@ struct _mp_obj_type_t {
|
||||
// - 2 or more parents: pointer to a tuple object containing the parent types
|
||||
const void *parent;
|
||||
|
||||
// A dict mapping qstrs to objects local methods/constants/etc.
|
||||
struct _mp_obj_dict_t *locals_dict;
|
||||
struct _mp_obj_type_ext ext[1];
|
||||
};
|
||||
|
||||
|
||||
extern size_t mp_type_size(const mp_obj_type_t *);
|
||||
extern mp_call_fun_t mp_type_call(const mp_obj_type_t *);
|
||||
extern mp_unary_op_fun_t mp_type_unary_op(const mp_obj_type_t *);
|
||||
|
@ -83,6 +83,7 @@ mp_obj_t mp_obj_new_attrtuple(const qstr *fields, size_t n, const mp_obj_t *item
|
||||
|
||||
const mp_obj_type_t mp_type_attrtuple = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_tuple, // reuse tuple to save on a qstr
|
||||
.print = mp_obj_attrtuple_print,
|
||||
.unary_op = mp_obj_tuple_unary_op,
|
||||
|
@ -86,7 +86,7 @@ STATIC mp_obj_t bool_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs_
|
||||
|
||||
const mp_obj_type_t mp_type_bool = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE, // can match all numeric types
|
||||
.flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE | MP_TYPE_FLAG_FULL, // can match all numeric types
|
||||
.name = MP_QSTR_bool,
|
||||
.print = bool_print,
|
||||
.make_new = bool_make_new,
|
||||
|
@ -97,6 +97,7 @@ STATIC void bound_meth_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
|
||||
STATIC const mp_obj_type_t mp_type_bound_meth = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_bound_method,
|
||||
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
|
||||
.print = bound_meth_print,
|
||||
|
@ -80,7 +80,7 @@ STATIC void closure_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_
|
||||
|
||||
const mp_obj_type_t mp_type_closure = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_BINDS_SELF,
|
||||
.flags = MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_closure,
|
||||
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
|
||||
.print = closure_print,
|
||||
|
@ -157,7 +157,7 @@ STATIC void complex_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
|
||||
const mp_obj_type_t mp_type_complex = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EQ_NOT_REFLEXIVE | MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE,
|
||||
.flags = MP_TYPE_FLAG_EQ_NOT_REFLEXIVE | MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE | MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_complex,
|
||||
.print = complex_print,
|
||||
.make_new = complex_make_new,
|
||||
|
@ -160,6 +160,7 @@ STATIC MP_DEFINE_CONST_DICT(deque_locals_dict, deque_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t mp_type_deque = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_deque,
|
||||
.make_new = deque_make_new,
|
||||
.unary_op = deque_unary_op,
|
||||
|
@ -459,6 +459,7 @@ STATIC mp_obj_t dict_view_it_iternext(mp_obj_t self_in) {
|
||||
|
||||
STATIC const mp_obj_type_t mp_type_dict_view_it = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_iterator,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = dict_view_it_iternext,
|
||||
@ -510,6 +511,7 @@ STATIC mp_obj_t dict_view_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t
|
||||
|
||||
STATIC const mp_obj_type_t mp_type_dict_view = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_dict_view,
|
||||
.print = dict_view_print,
|
||||
.binary_op = dict_view_binary_op,
|
||||
@ -584,6 +586,7 @@ STATIC MP_DEFINE_CONST_DICT(dict_locals_dict, dict_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t mp_type_dict = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_dict,
|
||||
.print = dict_print,
|
||||
.make_new = mp_obj_dict_make_new,
|
||||
@ -597,6 +600,7 @@ const mp_obj_type_t mp_type_dict = {
|
||||
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
||||
const mp_obj_type_t mp_type_ordereddict = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_OrderedDict,
|
||||
.print = dict_print,
|
||||
.make_new = mp_obj_dict_make_new,
|
||||
|
@ -71,6 +71,7 @@ STATIC mp_obj_t enumerate_make_new(const mp_obj_type_t *type, size_t n_args, con
|
||||
|
||||
const mp_obj_type_t mp_type_enumerate = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_enumerate,
|
||||
.make_new = enumerate_make_new,
|
||||
.iternext = enumerate_iternext,
|
||||
|
@ -626,6 +626,7 @@ STATIC const mp_obj_namedtuple_type_t code_type_obj = {
|
||||
.base = {
|
||||
.type = &mp_type_type
|
||||
},
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_code,
|
||||
.print = namedtuple_print,
|
||||
.make_new = namedtuple_make_new,
|
||||
@ -726,6 +727,7 @@ STATIC const mp_obj_namedtuple_type_t traceback_type_obj = {
|
||||
.base = {
|
||||
.type = &mp_type_type
|
||||
},
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_traceback,
|
||||
.print = namedtuple_print,
|
||||
.make_new = namedtuple_make_new,
|
||||
|
@ -63,6 +63,7 @@ STATIC mp_obj_t filter_iternext(mp_obj_t self_in) {
|
||||
|
||||
const mp_obj_type_t mp_type_filter = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_filter,
|
||||
.make_new = filter_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
|
@ -181,7 +181,7 @@ STATIC mp_obj_t float_binary_op(mp_binary_op_t op, mp_obj_t lhs_in, mp_obj_t rhs
|
||||
|
||||
const mp_obj_type_t mp_type_float = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EQ_NOT_REFLEXIVE | MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE,
|
||||
.flags = MP_TYPE_FLAG_EQ_NOT_REFLEXIVE | MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE | MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_float,
|
||||
.print = float_print,
|
||||
.make_new = float_make_new,
|
||||
|
@ -60,7 +60,7 @@ STATIC mp_obj_t fun_builtin_0_call(mp_obj_t self_in, size_t n_args, size_t n_kw,
|
||||
|
||||
const mp_obj_type_t mp_type_fun_builtin_0 = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN,
|
||||
.flags = MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_BUILTIN_FUN | MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_function,
|
||||
.call = fun_builtin_0_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
|
@ -157,7 +157,7 @@ static void gen_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
|
||||
const mp_obj_type_t mp_type_gen_wrap = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_BINDS_SELF,
|
||||
.flags = MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_generator,
|
||||
.call = gen_wrap_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
@ -412,6 +412,7 @@ STATIC MP_DEFINE_CONST_DICT(gen_instance_locals_dict, gen_instance_locals_dict_t
|
||||
|
||||
const mp_obj_type_t mp_type_gen_instance = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_generator,
|
||||
.print = gen_instance_print,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
|
@ -59,6 +59,7 @@ STATIC mp_obj_t it_iternext(mp_obj_t self_in) {
|
||||
|
||||
STATIC const mp_obj_type_t mp_type_it = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_iterator,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = it_iternext,
|
||||
|
@ -571,6 +571,7 @@ STATIC MP_DEFINE_CONST_DICT(int_locals_dict, int_locals_dict_table);
|
||||
const mp_obj_type_t mp_type_int = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_int,
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.print = mp_obj_int_print,
|
||||
.make_new = mp_obj_int_make_new,
|
||||
.unary_op = mp_obj_int_unary_op,
|
||||
|
@ -461,6 +461,7 @@ STATIC MP_DEFINE_CONST_DICT(list_locals_dict, list_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t mp_type_list = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_list,
|
||||
.print = list_print,
|
||||
.make_new = list_make_new,
|
||||
|
@ -66,6 +66,7 @@ STATIC mp_obj_t map_iternext(mp_obj_t self_in) {
|
||||
|
||||
const mp_obj_type_t mp_type_map = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_map,
|
||||
.make_new = map_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
|
@ -168,7 +168,7 @@ mp_obj_namedtuple_type_t *mp_obj_new_namedtuple_base(size_t n_fields, mp_obj_t *
|
||||
STATIC mp_obj_t mp_obj_new_namedtuple_type(qstr name, size_t n_fields, mp_obj_t *fields) {
|
||||
mp_obj_namedtuple_type_t *o = mp_obj_new_namedtuple_base(n_fields, fields);
|
||||
o->base.base.type = &mp_type_type;
|
||||
o->base.flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE; // can match tuple
|
||||
o->base.flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE | MP_TYPE_FLAG_FULL; // can match tuple
|
||||
o->base.name = name;
|
||||
o->base.print = namedtuple_print;
|
||||
o->base.make_new = namedtuple_make_new;
|
||||
|
@ -45,6 +45,7 @@ STATIC void none_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_
|
||||
|
||||
const mp_obj_type_t mp_type_NoneType = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_NoneType,
|
||||
.print = none_print,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
|
@ -47,6 +47,7 @@ STATIC mp_obj_t polymorph_it_iternext(mp_obj_t self_in) {
|
||||
|
||||
const mp_obj_type_t mp_type_polymorph_iter = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_iterator,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = polymorph_it_iternext,
|
||||
|
@ -54,6 +54,7 @@ STATIC mp_obj_t range_it_iternext(mp_obj_t o_in) {
|
||||
|
||||
STATIC const mp_obj_type_t mp_type_range_it = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_iterator,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = range_it_iternext,
|
||||
|
@ -71,6 +71,7 @@ STATIC mp_obj_t reversed_iternext(mp_obj_t self_in) {
|
||||
|
||||
const mp_obj_type_t mp_type_reversed = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_reversed,
|
||||
.make_new = reversed_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
|
@ -545,6 +545,7 @@ STATIC MP_DEFINE_CONST_DICT(set_locals_dict, set_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t mp_type_set = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_set,
|
||||
.print = set_print,
|
||||
.make_new = set_make_new,
|
||||
@ -570,7 +571,7 @@ STATIC MP_DEFINE_CONST_DICT(frozenset_locals_dict, frozenset_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t mp_type_frozenset = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE,
|
||||
.flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE | MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_frozenset,
|
||||
.print = set_print,
|
||||
.make_new = set_make_new,
|
||||
|
@ -45,6 +45,7 @@ STATIC void singleton_print(const mp_print_t *print, mp_obj_t self_in, mp_print_
|
||||
|
||||
const mp_obj_type_t mp_type_singleton = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_,
|
||||
.print = singleton_print,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
|
@ -2035,6 +2035,7 @@ const mp_obj_type_t mp_type_str = {
|
||||
// Reuses most of methods from str
|
||||
const mp_obj_type_t mp_type_bytes = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_bytes,
|
||||
.print = str_print,
|
||||
.make_new = bytes_make_new,
|
||||
|
@ -246,6 +246,7 @@ STATIC const mp_stream_p_t stringio_stream_p = {
|
||||
|
||||
const mp_obj_type_t mp_type_stringio = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_StringIO,
|
||||
.print = stringio_print,
|
||||
.make_new = stringio_make_new,
|
||||
@ -265,6 +266,7 @@ STATIC const mp_stream_p_t bytesio_stream_p = {
|
||||
|
||||
const mp_obj_type_t mp_type_bytesio = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_BytesIO,
|
||||
.print = stringio_print,
|
||||
.make_new = stringio_make_new,
|
||||
|
@ -291,6 +291,7 @@ STATIC MP_DEFINE_CONST_DICT(struni_locals_dict, struni_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t mp_type_str = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_str,
|
||||
.print = uni_print,
|
||||
.make_new = mp_obj_str_make_new,
|
||||
|
@ -229,6 +229,7 @@ STATIC MP_DEFINE_CONST_DICT(tuple_locals_dict, tuple_locals_dict_table);
|
||||
|
||||
const mp_obj_type_t mp_type_tuple = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_tuple,
|
||||
.print = mp_obj_tuple_print,
|
||||
.make_new = mp_obj_tuple_make_new,
|
||||
|
21
py/objtype.c
21
py/objtype.c
@ -440,7 +440,7 @@ STATIC mp_obj_t instance_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
|
||||
struct class_lookup_data lookup = {
|
||||
.obj = self,
|
||||
.attr = op_name,
|
||||
.meth_offset = offsetof(mp_obj_type_t, unary_op),
|
||||
.meth_offset = offsetof(mp_obj_type_t, ext[0].unary_op),
|
||||
.dest = member,
|
||||
.is_type = false,
|
||||
};
|
||||
@ -568,7 +568,7 @@ retry:;
|
||||
struct class_lookup_data lookup = {
|
||||
.obj = lhs,
|
||||
.attr = op_name,
|
||||
.meth_offset = offsetof(mp_obj_type_t, binary_op),
|
||||
.meth_offset = offsetof(mp_obj_type_t, ext[0].binary_op),
|
||||
.dest = dest,
|
||||
.is_type = false,
|
||||
};
|
||||
@ -839,7 +839,7 @@ STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
|
||||
mp_obj_t member[4] = {MP_OBJ_NULL, MP_OBJ_NULL, index, value};
|
||||
struct class_lookup_data lookup = {
|
||||
.obj = self,
|
||||
.meth_offset = offsetof(mp_obj_type_t, subscr),
|
||||
.meth_offset = offsetof(mp_obj_type_t, ext[0].subscr),
|
||||
.dest = member,
|
||||
.is_type = false,
|
||||
};
|
||||
@ -856,7 +856,7 @@ STATIC mp_obj_t instance_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value
|
||||
mp_obj_class_lookup(&lookup, self->base.type);
|
||||
if (member[0] == MP_OBJ_SENTINEL) {
|
||||
const mp_obj_type_t *subobj_type = mp_obj_get_type(self->subobj[0]);
|
||||
mp_obj_t ret = subobj_type->subscr(self_in, index, value);
|
||||
mp_obj_t ret = subobj_type->ext[0].subscr(self_in, index, value);
|
||||
// May have called port specific C code. Make sure it didn't mess up the heap.
|
||||
assert_heap_ok();
|
||||
return ret;
|
||||
@ -878,7 +878,7 @@ STATIC mp_obj_t mp_obj_instance_get_call(mp_obj_t self_in, mp_obj_t *member) {
|
||||
struct class_lookup_data lookup = {
|
||||
.obj = self,
|
||||
.attr = MP_QSTR___call__,
|
||||
.meth_offset = offsetof(mp_obj_type_t, call),
|
||||
.meth_offset = offsetof(mp_obj_type_t, ext[0].call),
|
||||
.dest = member,
|
||||
.is_type = false,
|
||||
};
|
||||
@ -917,7 +917,7 @@ mp_obj_t mp_obj_instance_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf)
|
||||
struct class_lookup_data lookup = {
|
||||
.obj = self,
|
||||
.attr = MP_QSTR___iter__,
|
||||
.meth_offset = offsetof(mp_obj_type_t, getiter),
|
||||
.meth_offset = offsetof(mp_obj_type_t, ext[0].getiter),
|
||||
.dest = member,
|
||||
.is_type = false,
|
||||
};
|
||||
@ -929,7 +929,7 @@ mp_obj_t mp_obj_instance_getiter(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf)
|
||||
if (iter_buf == NULL) {
|
||||
iter_buf = m_new_obj(mp_obj_iter_buf_t);
|
||||
}
|
||||
return type->getiter(self->subobj[0], iter_buf);
|
||||
return type->ext[0].getiter(self->subobj[0], iter_buf);
|
||||
} else {
|
||||
return mp_call_method_n_kw(0, 0, member);
|
||||
}
|
||||
@ -941,14 +941,14 @@ STATIC mp_int_t instance_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo,
|
||||
struct class_lookup_data lookup = {
|
||||
.obj = self,
|
||||
.attr = MP_QSTR_, // don't actually look for a method
|
||||
.meth_offset = offsetof(mp_obj_type_t, buffer_p.get_buffer),
|
||||
.meth_offset = offsetof(mp_obj_type_t, ext[0].buffer_p.get_buffer),
|
||||
.dest = member,
|
||||
.is_type = false,
|
||||
};
|
||||
mp_obj_class_lookup(&lookup, self->base.type);
|
||||
if (member[0] == MP_OBJ_SENTINEL) {
|
||||
const mp_obj_type_t *type = mp_obj_get_type(self->subobj[0]);
|
||||
return type->buffer_p.get_buffer(self->subobj[0], bufinfo, flags);
|
||||
return type->ext[0].buffer_p.get_buffer(self->subobj[0], bufinfo, flags);
|
||||
} else {
|
||||
return 1; // object does not support buffer protocol
|
||||
}
|
||||
@ -1146,6 +1146,7 @@ STATIC void type_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
||||
|
||||
const mp_obj_type_t mp_type_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_type,
|
||||
.print = type_print,
|
||||
.make_new = type_make_new,
|
||||
@ -1167,7 +1168,7 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
|
||||
|
||||
// Basic validation of base classes
|
||||
uint16_t base_flags = MP_TYPE_FLAG_EQ_NOT_REFLEXIVE
|
||||
| MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE | MP_TYPE_FLAG_EQ_HAS_NEQ_TEST;
|
||||
| MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE | MP_TYPE_FLAG_EQ_HAS_NEQ_TEST | MP_TYPE_FLAG_FULL;
|
||||
size_t bases_len;
|
||||
mp_obj_t *bases_items;
|
||||
mp_obj_tuple_get(bases_tuple, &bases_len, &bases_items);
|
||||
|
@ -69,6 +69,7 @@ STATIC mp_obj_t zip_iternext(mp_obj_t self_in) {
|
||||
|
||||
const mp_obj_type_t mp_type_zip = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_zip,
|
||||
.make_new = zip_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
|
@ -29,24 +29,25 @@
|
||||
|
||||
STATIC mp_obj_t op_getitem(mp_obj_t self_in, mp_obj_t key_in) {
|
||||
const mp_obj_type_t *type = mp_obj_get_type(self_in);
|
||||
return type->subscr(self_in, key_in, MP_OBJ_SENTINEL);
|
||||
return type->ext[0].subscr(self_in, key_in, MP_OBJ_SENTINEL);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(mp_op_getitem_obj, op_getitem);
|
||||
|
||||
STATIC mp_obj_t op_setitem(mp_obj_t self_in, mp_obj_t key_in, mp_obj_t value_in) {
|
||||
const mp_obj_type_t *type = mp_obj_get_type(self_in);
|
||||
return type->subscr(self_in, key_in, value_in);
|
||||
return type->ext[0].subscr(self_in, key_in, value_in);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_3(mp_op_setitem_obj, op_setitem);
|
||||
|
||||
STATIC mp_obj_t op_delitem(mp_obj_t self_in, mp_obj_t key_in) {
|
||||
const mp_obj_type_t *type = mp_obj_get_type(self_in);
|
||||
return type->subscr(self_in, key_in, MP_OBJ_NULL);
|
||||
return type->ext[0].subscr(self_in, key_in, MP_OBJ_NULL);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(mp_op_delitem_obj, op_delitem);
|
||||
|
||||
STATIC mp_obj_t op_contains(mp_obj_t lhs_in, mp_obj_t rhs_in) {
|
||||
const mp_obj_type_t *type = mp_obj_get_type(lhs_in);
|
||||
return type->binary_op(MP_BINARY_OP_CONTAINS, lhs_in, rhs_in);
|
||||
mp_binary_op_fun_t binary_op = mp_type_binary_op(type);
|
||||
return binary_op(MP_BINARY_OP_CONTAINS, lhs_in, rhs_in);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(mp_op_contains_obj, op_contains);
|
||||
|
@ -1003,7 +1003,7 @@ STATIC mp_obj_t checked_fun_call(mp_obj_t self_in, size_t n_args, size_t n_kw, c
|
||||
|
||||
STATIC const mp_obj_type_t mp_type_checked_fun = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_BINDS_SELF,
|
||||
.flags = MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_function,
|
||||
.call = checked_fun_call,
|
||||
};
|
||||
|
@ -422,6 +422,7 @@ STATIC const mp_stream_p_t uart_stream_p = {
|
||||
|
||||
const mp_obj_type_t busio_uart_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_UART,
|
||||
.make_new = busio_uart_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
|
@ -168,6 +168,7 @@ STATIC mp_obj_t nvm_bytearray_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj
|
||||
|
||||
const mp_obj_type_t nvm_bytearray_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_ByteArray,
|
||||
.subscr = nvm_bytearray_subscr,
|
||||
.unary_op = nvm_bytearray_unary_op,
|
||||
|
@ -112,6 +112,7 @@ const mp_obj_namedtuple_type_t struct_time_type_obj = {
|
||||
.base = {
|
||||
.type = &mp_type_type
|
||||
},
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_struct_time,
|
||||
.print = namedtuple_print,
|
||||
.make_new = struct_time_make_new,
|
||||
|
@ -310,6 +310,7 @@ STATIC const mp_stream_p_t usb_cdc_serial_stream_p = {
|
||||
|
||||
const mp_obj_type_t usb_cdc_serial_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_Serial,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
|
@ -113,6 +113,7 @@ STATIC const mp_stream_p_t usb_midi_portin_stream_p = {
|
||||
|
||||
const mp_obj_type_t usb_midi_portin_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_PortIn,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
|
@ -94,6 +94,7 @@ STATIC const mp_stream_p_t usb_midi_portout_stream_p = {
|
||||
|
||||
const mp_obj_type_t usb_midi_portout_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_FULL,
|
||||
.name = MP_QSTR_PortOut,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
|
Loading…
Reference in New Issue
Block a user