Merge pull request #4903 from jepler/split-type-objects
Split type objects
This commit is contained in:
commit
9fdecacec7
2
Makefile
2
Makefile
|
@ -54,6 +54,8 @@ TRANSLATE_SOURCES_EXC = -path "ports/*/build-*" \
|
|||
-o -path ports/stm/st_driver \
|
||||
-o -path lib/tinyusb \
|
||||
-o -path lib/lwip \
|
||||
-o -path extmod/ulab/circuitpython \
|
||||
-o -path extmod/ulab/micropython \
|
||||
|
||||
.PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest gettext stubs
|
||||
|
||||
|
|
|
@ -295,13 +295,16 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_btree,
|
||||
.print = btree_print,
|
||||
.getiter = btree_getiter,
|
||||
.iternext = btree_iternext,
|
||||
.binary_op = btree_binary_op,
|
||||
.subscr = btree_subscr,
|
||||
.locals_dict = (void *)&btree_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = btree_getiter,
|
||||
.iternext = btree_iternext,
|
||||
.binary_op = btree_binary_op,
|
||||
.subscr = btree_subscr,
|
||||
),
|
||||
};
|
||||
#endif
|
||||
|
||||
|
|
|
@ -602,10 +602,13 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_FrameBuffer,
|
||||
.make_new = framebuf_make_new,
|
||||
.buffer_p = { .get_buffer = framebuf_get_buffer },
|
||||
.locals_dict = (mp_obj_dict_t *)&framebuf_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.buffer_p = { .get_buffer = framebuf_get_buffer },
|
||||
),
|
||||
};
|
||||
#endif
|
||||
|
||||
|
|
|
@ -284,11 +284,14 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_Task,
|
||||
.make_new = task_make_new,
|
||||
.attr = task_attr,
|
||||
.getiter = task_getiter,
|
||||
.iternext = task_iternext,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = task_getiter,
|
||||
.iternext = task_iternext,
|
||||
),
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -622,13 +622,16 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_struct,
|
||||
.print = uctypes_struct_print,
|
||||
.make_new = uctypes_struct_make_new,
|
||||
.attr = uctypes_struct_attr,
|
||||
.subscr = uctypes_struct_subscr,
|
||||
.unary_op = uctypes_struct_unary_op,
|
||||
.buffer_p = { .get_buffer = uctypes_get_buffer },
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.subscr = uctypes_struct_subscr,
|
||||
.unary_op = uctypes_struct_unary_op,
|
||||
.buffer_p = { .get_buffer = uctypes_get_buffer },
|
||||
),
|
||||
};
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_uctypes_globals_table[] = {
|
||||
|
|
|
@ -193,10 +193,13 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_utimeq,
|
||||
.make_new = utimeq_make_new,
|
||||
.unary_op = utimeq_unary_op,
|
||||
.locals_dict = (void *)&utimeq_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = utimeq_unary_op,
|
||||
),
|
||||
};
|
||||
|
||||
STATIC const mp_rom_map_elem_t mp_module_utimeq_globals_table[] = {
|
||||
|
|
|
@ -122,10 +122,13 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_DecompIO,
|
||||
.make_new = decompio_make_new,
|
||||
.protocol = &decompio_stream_p,
|
||||
.locals_dict = (void *)&decompio_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &decompio_stream_p,
|
||||
),
|
||||
};
|
||||
#endif
|
||||
|
||||
|
|
|
@ -1 +1 @@
|
|||
Subproject commit 161a7288482200c884623ed3cb59dd91f53be91a
|
||||
Subproject commit 9b8cd47640304929aa4255560d754b3058ddaa95
|
|
@ -474,10 +474,13 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_VfsFat,
|
||||
.make_new = fat_vfs_make_new,
|
||||
.protocol = &fat_vfs_proto,
|
||||
.locals_dict = (mp_obj_dict_t *)&fat_vfs_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &fat_vfs_proto,
|
||||
),
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -244,13 +244,16 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_FileIO,
|
||||
.print = file_obj_print,
|
||||
.make_new = file_obj_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &vfs_fat_fileio_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t *)&vfs_fat_rawfile_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &vfs_fat_fileio_stream_p,
|
||||
),
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -264,13 +267,16 @@ STATIC const mp_stream_p_t vfs_fat_textio_stream_p = {
|
|||
|
||||
const mp_obj_type_t mp_type_vfs_fat_textio = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_TextIOWrapper,
|
||||
.print = file_obj_print,
|
||||
.make_new = file_obj_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &vfs_fat_textio_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t *)&vfs_fat_rawfile_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &vfs_fat_textio_stream_p,
|
||||
),
|
||||
};
|
||||
|
||||
// Factory function for I/O stream classes
|
||||
|
|
|
@ -484,12 +484,15 @@ 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_EXTENDED,
|
||||
#if LFS_BUILD_VERSION == 1
|
||||
.name = MP_QSTR_VfsLfs1,
|
||||
#else
|
||||
.name = MP_QSTR_VfsLfs2,
|
||||
#endif
|
||||
.make_new = MP_VFS_LFSx(make_new),
|
||||
.protocol = &MP_VFS_LFSx(proto),
|
||||
.locals_dict = (mp_obj_dict_t *)&MP_VFS_LFSx(locals_dict),
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &MP_VFS_LFSx(proto),
|
||||
),
|
||||
};
|
||||
|
|
|
@ -226,12 +226,15 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_FileIO,
|
||||
.print = MP_VFS_LFSx(file_print),
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &MP_VFS_LFSx(fileio_stream_p),
|
||||
.locals_dict = (mp_obj_dict_t *)&MP_VFS_LFSx(file_locals_dict),
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &MP_VFS_LFSx(fileio_stream_p),
|
||||
),
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -245,10 +248,13 @@ STATIC const mp_stream_p_t MP_VFS_LFSx(textio_stream_p) = {
|
|||
|
||||
const mp_obj_type_t MP_TYPE_VFS_LFSx_(_textio) = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_TextIOWrapper,
|
||||
.print = MP_VFS_LFSx(file_print),
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &MP_VFS_LFSx(textio_stream_p),
|
||||
.locals_dict = (mp_obj_dict_t *)&MP_VFS_LFSx(file_locals_dict),
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &MP_VFS_LFSx(textio_stream_p),
|
||||
),
|
||||
};
|
||||
|
|
|
@ -352,10 +352,13 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_VfsPosix,
|
||||
.make_new = vfs_posix_make_new,
|
||||
.protocol = &vfs_posix_proto,
|
||||
.locals_dict = (mp_obj_dict_t *)&vfs_posix_locals_dict,
|
||||
.make_new = vfs_posix_make_new,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &vfs_posix_proto,
|
||||
),
|
||||
};
|
||||
|
||||
#endif // MICROPY_VFS_POSIX
|
||||
|
|
|
@ -213,13 +213,16 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_FileIO,
|
||||
.print = vfs_posix_file_print,
|
||||
.make_new = vfs_posix_file_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &vfs_posix_fileio_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t *)&vfs_posix_rawfile_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &vfs_posix_fileio_stream_p,
|
||||
),
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -233,13 +236,16 @@ STATIC const mp_stream_p_t vfs_posix_textio_stream_p = {
|
|||
|
||||
const mp_obj_type_t mp_type_vfs_posix_textio = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_TextIOWrapper,
|
||||
.print = vfs_posix_file_print,
|
||||
.make_new = vfs_posix_file_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &vfs_posix_textio_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t *)&vfs_posix_rawfile_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &vfs_posix_textio_stream_p,
|
||||
),
|
||||
};
|
||||
|
||||
const mp_obj_vfs_posix_file_t mp_sys_stdin_obj = {{&mp_type_textio}, STDIN_FILENO};
|
||||
|
|
|
@ -129,13 +129,16 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_FileIO,
|
||||
// TODO .make_new?
|
||||
.print = stdio_obj_print,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &stdio_obj_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t *)&stdio_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &stdio_obj_stream_p,
|
||||
),
|
||||
};
|
||||
|
||||
const sys_stdio_obj_t mp_sys_stdin_obj = {{&stdio_obj_type}, .fd = STDIO_FD_IN};
|
||||
|
@ -166,11 +169,14 @@ STATIC const mp_stream_p_t stdio_buffer_obj_stream_p = {
|
|||
STATIC const mp_obj_type_t stdio_buffer_obj_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_FileIO,
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.print = stdio_obj_print,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &stdio_buffer_obj_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t *)&stdio_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &stdio_buffer_obj_stream_p,
|
||||
),
|
||||
};
|
||||
|
||||
STATIC const sys_stdio_obj_t stdio_buffer_obj = {{&stdio_buffer_obj_type}, .fd = 0}; // fd unused
|
||||
|
|
|
@ -4371,7 +4371,7 @@ msgstr ""
|
|||
msgid "wrong input type"
|
||||
msgstr ""
|
||||
|
||||
#: extmod/ulab/code/ulab_create.c py/objstr.c
|
||||
#: extmod/ulab/code/ulab_create.c py/objarray.c py/objstr.c
|
||||
msgid "wrong number of arguments"
|
||||
msgstr ""
|
||||
|
||||
|
|
|
@ -108,8 +108,11 @@ STATIC const mp_stream_p_t fileio_stream_p = {
|
|||
|
||||
STATIC const mp_obj_type_t mp_type_stest_fileio = {
|
||||
{ &mp_type_type },
|
||||
.protocol = &fileio_stream_p,
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.locals_dict = (mp_obj_dict_t *)&rawfile_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &fileio_stream_p,
|
||||
),
|
||||
};
|
||||
|
||||
// stream read returns non-blocking error
|
||||
|
@ -136,8 +139,11 @@ STATIC const mp_stream_p_t textio_stream_p2 = {
|
|||
|
||||
STATIC const mp_obj_type_t mp_type_stest_textio2 = {
|
||||
{ &mp_type_type },
|
||||
.protocol = &textio_stream_p2,
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.locals_dict = (mp_obj_dict_t *)&rawfile_locals_dict2,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &textio_stream_p2,
|
||||
),
|
||||
};
|
||||
|
||||
// str/bytes objects without a valid hash
|
||||
|
|
|
@ -455,19 +455,22 @@ STATIC mp_obj_t ffifunc_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
|
|||
} else if (mp_obj_is_str(a)) {
|
||||
const char *s = mp_obj_str_get_str(a);
|
||||
values[i].ffi = (ffi_arg)(intptr_t)s;
|
||||
} else if (((mp_obj_base_t *)MP_OBJ_TO_PTR(a))->type->buffer_p.get_buffer != NULL) {
|
||||
mp_obj_base_t *o = (mp_obj_base_t *)MP_OBJ_TO_PTR(a);
|
||||
mp_buffer_info_t bufinfo;
|
||||
int ret = o->type->buffer_p.get_buffer(MP_OBJ_FROM_PTR(o), &bufinfo, MP_BUFFER_READ); // TODO: MP_BUFFER_READ?
|
||||
if (ret != 0) {
|
||||
} else {
|
||||
mp_getbuffer_fun_t get_buffer = mp_type_get_getbuffer_slot(((mp_obj_base_t *)MP_OBJ_TO_PTR(a))->type);
|
||||
if (get_buffer != NULL) {
|
||||
mp_obj_base_t *o = (mp_obj_base_t *)MP_OBJ_TO_PTR(a);
|
||||
mp_buffer_info_t bufinfo;
|
||||
int ret = get_buffer(MP_OBJ_FROM_PTR(o), &bufinfo, MP_BUFFER_READ); // TODO: MP_BUFFER_READ?
|
||||
if (ret != 0) {
|
||||
goto error;
|
||||
}
|
||||
values[i].ffi = (ffi_arg)(intptr_t)bufinfo.buf;
|
||||
} else if (mp_obj_is_type(a, &fficallback_type)) {
|
||||
mp_obj_fficallback_t *p = MP_OBJ_TO_PTR(a);
|
||||
values[i].ffi = (ffi_arg)(intptr_t)p->func;
|
||||
} else {
|
||||
goto error;
|
||||
}
|
||||
values[i].ffi = (ffi_arg)(intptr_t)bufinfo.buf;
|
||||
} else if (mp_obj_is_type(a, &fficallback_type)) {
|
||||
mp_obj_fficallback_t *p = MP_OBJ_TO_PTR(a);
|
||||
values[i].ffi = (ffi_arg)(intptr_t)p->func;
|
||||
} else {
|
||||
goto error;
|
||||
}
|
||||
valueptrs[i] = &values[i];
|
||||
}
|
||||
|
@ -482,9 +485,12 @@ error:
|
|||
|
||||
STATIC const mp_obj_type_t ffifunc_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_ffifunc,
|
||||
.print = ffifunc_print,
|
||||
.call = ffifunc_call,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.call = ffifunc_call,
|
||||
),
|
||||
};
|
||||
|
||||
// FFI callback for Python function
|
||||
|
|
|
@ -313,10 +313,13 @@ STATIC MP_DEFINE_CONST_DICT(poll_locals_dict, poll_locals_dict_table);
|
|||
|
||||
STATIC const mp_obj_type_t mp_type_poll = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_poll,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = poll_iternext,
|
||||
.locals_dict = (void *)&poll_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = poll_iternext,
|
||||
),
|
||||
};
|
||||
|
||||
STATIC mp_obj_t select_poll(size_t n_args, const mp_obj_t *args) {
|
||||
|
|
|
@ -140,7 +140,9 @@ static inline mp_obj_t mp_obj_cast_to_native_base_dyn(mp_obj_t self_in, mp_const
|
|||
|
||||
if (MP_OBJ_FROM_PTR(self_type) == native_type) {
|
||||
return self_in;
|
||||
} else if (self_type->parent != native_type) {
|
||||
}
|
||||
mp_parent_t parent = mp_type_get_parent_slot(self_type);
|
||||
if (parent != native_type) {
|
||||
// The self_in object is not a direct descendant of native_type, so fail the cast.
|
||||
// This is a very simple version of mp_obj_is_subclass_fast that could be improved.
|
||||
return MP_OBJ_NULL;
|
||||
|
|
10
py/modio.c
10
py/modio.c
|
@ -103,9 +103,12 @@ STATIC const mp_stream_p_t iobase_p = {
|
|||
|
||||
STATIC const mp_obj_type_t mp_type_iobase = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_IOBase,
|
||||
.make_new = iobase_make_new,
|
||||
.protocol = &iobase_p,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &iobase_p,
|
||||
),
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_IO_IOBASE
|
||||
|
@ -199,10 +202,13 @@ STATIC const mp_stream_p_t bufwriter_stream_p = {
|
|||
|
||||
STATIC const mp_obj_type_t mp_type_bufwriter = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_BufferedWriter,
|
||||
.make_new = bufwriter_make_new,
|
||||
.protocol = &bufwriter_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t *)&bufwriter_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &bufwriter_stream_p,
|
||||
),
|
||||
};
|
||||
#endif // MICROPY_PY_IO_BUFFEREDWRITER
|
||||
|
||||
|
|
120
py/obj.c
120
py/obj.c
|
@ -101,6 +101,12 @@ const mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in) {
|
|||
#endif
|
||||
}
|
||||
|
||||
const mp_obj_full_type_t *mp_obj_get_full_type(mp_const_obj_t o_in) {
|
||||
const mp_obj_type_t *type = mp_obj_get_type(o_in);
|
||||
assert(type->flags & MP_TYPE_FLAG_EXTENDED);
|
||||
return (mp_obj_full_type_t *)type;
|
||||
}
|
||||
|
||||
const char *mp_obj_get_type_str(mp_const_obj_t o_in) {
|
||||
return qstr_str(mp_obj_get_type_qstr(o_in));
|
||||
}
|
||||
|
@ -195,8 +201,9 @@ bool PLACE_IN_ITCM(mp_obj_is_true)(mp_obj_t arg) {
|
|||
}
|
||||
} else {
|
||||
const mp_obj_type_t *type = mp_obj_get_type(arg);
|
||||
if (type->unary_op != NULL) {
|
||||
mp_obj_t result = type->unary_op(MP_UNARY_OP_BOOL, arg);
|
||||
mp_unary_op_fun_t unary_op = mp_type_get_unary_op_slot(type);
|
||||
if (unary_op) {
|
||||
mp_obj_t result = unary_op(MP_UNARY_OP_BOOL, arg);
|
||||
if (result != MP_OBJ_NULL) {
|
||||
return result == mp_const_true;
|
||||
}
|
||||
|
@ -214,7 +221,7 @@ bool PLACE_IN_ITCM(mp_obj_is_true)(mp_obj_t arg) {
|
|||
}
|
||||
|
||||
bool mp_obj_is_callable(mp_obj_t o_in) {
|
||||
const mp_call_fun_t call = mp_obj_get_type(o_in)->call;
|
||||
const mp_call_fun_t call = mp_type_get_call_slot(mp_obj_get_type(o_in));
|
||||
if (call != mp_obj_instance_call) {
|
||||
return call != NULL;
|
||||
}
|
||||
|
@ -281,19 +288,20 @@ mp_obj_t mp_obj_equal_not_equal(mp_binary_op_t op, mp_obj_t o1, mp_obj_t o2) {
|
|||
const mp_obj_type_t *type = mp_obj_get_type(o1);
|
||||
// If a full equality test is not needed and the other object is a different
|
||||
// type then we don't need to bother trying the comparison.
|
||||
if (type->binary_op != NULL &&
|
||||
mp_binary_op_fun_t binary_op = mp_type_get_binary_op_slot(type);
|
||||
if (binary_op != NULL &&
|
||||
((type->flags & MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE) || mp_obj_get_type(o2) == type)) {
|
||||
// CPython is asymmetric: it will try __eq__ if there's no __ne__ but not the
|
||||
// other way around. If the class doesn't need a full test we can skip __ne__.
|
||||
if (op == MP_BINARY_OP_NOT_EQUAL && (type->flags & MP_TYPE_FLAG_EQ_HAS_NEQ_TEST)) {
|
||||
mp_obj_t r = type->binary_op(MP_BINARY_OP_NOT_EQUAL, o1, o2);
|
||||
mp_obj_t r = binary_op(MP_BINARY_OP_NOT_EQUAL, o1, o2);
|
||||
if (r != MP_OBJ_NULL) {
|
||||
return r;
|
||||
}
|
||||
}
|
||||
|
||||
// Try calling __eq__.
|
||||
mp_obj_t r = type->binary_op(MP_BINARY_OP_EQUAL, o1, o2);
|
||||
mp_obj_t r = binary_op(MP_BINARY_OP_EQUAL, o1, o2);
|
||||
if (r != MP_OBJ_NULL) {
|
||||
if (op == MP_BINARY_OP_EQUAL) {
|
||||
return r;
|
||||
|
@ -556,8 +564,9 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
|
|||
return MP_OBJ_NEW_SMALL_INT(l);
|
||||
} else {
|
||||
const mp_obj_type_t *type = mp_obj_get_type(o_in);
|
||||
if (type->unary_op != NULL) {
|
||||
return type->unary_op(MP_UNARY_OP_LEN, o_in);
|
||||
mp_unary_op_fun_t unary_op = mp_type_get_unary_op_slot(type);
|
||||
if (unary_op != NULL) {
|
||||
return unary_op(MP_UNARY_OP_LEN, o_in);
|
||||
} else {
|
||||
return MP_OBJ_NULL;
|
||||
}
|
||||
|
@ -566,8 +575,9 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
|
|||
|
||||
mp_obj_t mp_obj_subscr(mp_obj_t base, mp_obj_t index, mp_obj_t value) {
|
||||
const mp_obj_type_t *type = mp_obj_get_type(base);
|
||||
if (type->subscr != NULL) {
|
||||
mp_obj_t ret = type->subscr(base, index, value);
|
||||
mp_subscr_fun_t subscr = mp_type_get_subscr_slot(type);
|
||||
if (subscr != NULL) {
|
||||
mp_obj_t ret = subscr(base, index, value);
|
||||
// May have called port specific C code. Make sure it didn't mess up the heap.
|
||||
assert_heap_ok();
|
||||
if (ret != MP_OBJ_NULL) {
|
||||
|
@ -619,10 +629,10 @@ typedef struct {
|
|||
|
||||
STATIC mp_obj_t generic_it_iternext(mp_obj_t self_in) {
|
||||
mp_obj_generic_it_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
const mp_obj_type_t *type = mp_obj_get_type(self->obj);
|
||||
mp_obj_t current_length = type->unary_op(MP_UNARY_OP_LEN, self->obj);
|
||||
const mp_obj_full_type_t *type = mp_obj_get_full_type(self->obj);
|
||||
mp_obj_t current_length = type->MP_TYPE_UNARY_OP(MP_UNARY_OP_LEN, self->obj);
|
||||
if (self->cur < MP_OBJ_SMALL_INT_VALUE(current_length)) {
|
||||
mp_obj_t o_out = type->subscr(self->obj, MP_OBJ_NEW_SMALL_INT(self->cur), MP_OBJ_SENTINEL);
|
||||
mp_obj_t o_out = type->ext[0].subscr(self->obj, MP_OBJ_NEW_SMALL_INT(self->cur), MP_OBJ_SENTINEL);
|
||||
self->cur += 1;
|
||||
return o_out;
|
||||
} else {
|
||||
|
@ -642,10 +652,11 @@ mp_obj_t mp_obj_new_generic_iterator(mp_obj_t obj, mp_obj_iter_buf_t *iter_buf)
|
|||
|
||||
bool mp_get_buffer(mp_obj_t obj, mp_buffer_info_t *bufinfo, mp_uint_t flags) {
|
||||
const mp_obj_type_t *type = mp_obj_get_type(obj);
|
||||
if (type->buffer_p.get_buffer == NULL) {
|
||||
const mp_getbuffer_fun_t get_buffer = mp_type_get_getbuffer_slot(type);
|
||||
if (get_buffer == NULL) {
|
||||
return false;
|
||||
}
|
||||
int ret = type->buffer_p.get_buffer(obj, bufinfo, flags);
|
||||
int ret = get_buffer(obj, bufinfo, flags);
|
||||
if (ret != 0) {
|
||||
return false;
|
||||
}
|
||||
|
@ -666,3 +677,82 @@ mp_obj_t mp_generic_unary_op(mp_unary_op_t op, mp_obj_t o_in) {
|
|||
return MP_OBJ_NULL; // op not supported
|
||||
}
|
||||
}
|
||||
|
||||
mp_call_fun_t mp_type_get_call_slot(const mp_obj_type_t *type) {
|
||||
if (!(type->flags & MP_TYPE_FLAG_EXTENDED)) {
|
||||
return NULL;
|
||||
}
|
||||
return type->ext[0].call;
|
||||
}
|
||||
|
||||
mp_unary_op_fun_t mp_type_get_unary_op_slot(const mp_obj_type_t *type) {
|
||||
if (!(type->flags & MP_TYPE_FLAG_EXTENDED)) {
|
||||
return NULL;
|
||||
}
|
||||
return type->ext[0].unary_op;
|
||||
}
|
||||
|
||||
|
||||
mp_binary_op_fun_t mp_type_get_binary_op_slot(const mp_obj_type_t *type) {
|
||||
if (!(type->flags & MP_TYPE_FLAG_EXTENDED)) {
|
||||
return NULL;
|
||||
}
|
||||
return type->ext[0].binary_op;
|
||||
}
|
||||
|
||||
|
||||
mp_attr_fun_t mp_type_get_attr_slot(const mp_obj_type_t *type) {
|
||||
return type->attr;
|
||||
}
|
||||
|
||||
|
||||
mp_subscr_fun_t mp_type_get_subscr_slot(const mp_obj_type_t *type) {
|
||||
if (!(type->flags & MP_TYPE_FLAG_EXTENDED)) {
|
||||
return NULL;
|
||||
}
|
||||
return type->MP_TYPE_SUBSCR;
|
||||
}
|
||||
|
||||
|
||||
mp_getiter_fun_t mp_type_get_getiter_slot(const mp_obj_type_t *type) {
|
||||
if (!(type->flags & MP_TYPE_FLAG_EXTENDED)) {
|
||||
return NULL;
|
||||
}
|
||||
return type->MP_TYPE_GETITER;
|
||||
}
|
||||
|
||||
|
||||
mp_fun_1_t mp_type_get_iternext_slot(const mp_obj_type_t *type) {
|
||||
if (!(type->flags & MP_TYPE_FLAG_EXTENDED)) {
|
||||
return NULL;
|
||||
}
|
||||
return type->MP_TYPE_ITERNEXT;
|
||||
}
|
||||
|
||||
|
||||
mp_getbuffer_fun_t mp_type_get_getbuffer_slot(const mp_obj_type_t *type) {
|
||||
if (!(type->flags & MP_TYPE_FLAG_EXTENDED)) {
|
||||
return NULL;
|
||||
}
|
||||
return type->MP_TYPE_GET_BUFFER;
|
||||
}
|
||||
|
||||
|
||||
const void *mp_type_get_protocol_slot(const mp_obj_type_t *type) {
|
||||
if (!(type->flags & MP_TYPE_FLAG_EXTENDED)) {
|
||||
return NULL;
|
||||
}
|
||||
return type->MP_TYPE_PROTOCOL;
|
||||
}
|
||||
|
||||
|
||||
const void *mp_type_get_parent_slot(const mp_obj_type_t *type) {
|
||||
return type->parent;
|
||||
}
|
||||
|
||||
size_t mp_type_size(const mp_obj_type_t *type) {
|
||||
if (!(type->flags & MP_TYPE_FLAG_EXTENDED)) {
|
||||
return sizeof(mp_obj_type_t);
|
||||
}
|
||||
return sizeof(mp_obj_full_type_t);
|
||||
}
|
||||
|
|
124
py/obj.h
124
py/obj.h
|
@ -50,6 +50,7 @@ typedef const void *mp_const_obj_t;
|
|||
// This mp_obj_type_t struct is a concrete MicroPython object which holds info
|
||||
// about a type. See below for actual definition of the struct.
|
||||
typedef struct _mp_obj_type_t mp_obj_type_t;
|
||||
typedef struct _mp_obj_full_type_t mp_obj_full_type_t;
|
||||
|
||||
// Anything that wants to be a concrete MicroPython object must have mp_obj_base_t
|
||||
// as its first member (small ints, qstr objs and inline floats are not concrete).
|
||||
|
@ -515,6 +516,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_EXTENDED (0x0080) // contains the 'ext' fields
|
||||
|
||||
typedef enum {
|
||||
PRINT_STR = 0,
|
||||
|
@ -534,6 +536,8 @@ typedef struct _mp_obj_iter_buf_t {
|
|||
// It's rounded up in case mp_obj_base_t is smaller than mp_obj_t (eg for OBJ_REPR_D).
|
||||
#define MP_OBJ_ITER_BUF_NSLOTS ((sizeof(mp_obj_iter_buf_t) + sizeof(mp_obj_t) - 1) / sizeof(mp_obj_t))
|
||||
|
||||
struct _mp_buffer_info_t;
|
||||
|
||||
typedef void (*mp_print_fun_t)(const mp_print_t *print, mp_obj_t o, mp_print_kind_t kind);
|
||||
typedef mp_obj_t (*mp_make_new_fun_t)(const mp_obj_type_t *type, size_t n_args, const mp_obj_t *args, mp_map_t *kw_args);
|
||||
typedef mp_obj_t (*mp_call_fun_t)(mp_obj_t fun, size_t n_args, size_t n_kw, const mp_obj_t *args);
|
||||
|
@ -542,6 +546,7 @@ typedef mp_obj_t (*mp_binary_op_fun_t)(mp_binary_op_t op, mp_obj_t, mp_obj_t);
|
|||
typedef void (*mp_attr_fun_t)(mp_obj_t self_in, qstr attr, mp_obj_t *dest);
|
||||
typedef mp_obj_t (*mp_subscr_fun_t)(mp_obj_t self_in, mp_obj_t index, mp_obj_t value);
|
||||
typedef mp_obj_t (*mp_getiter_fun_t)(mp_obj_t self_in, mp_obj_iter_buf_t *iter_buf);
|
||||
typedef mp_int_t (*mp_getbuffer_fun_t)(mp_obj_t obj, struct _mp_buffer_info_t *bufinfo, mp_uint_t flags);
|
||||
|
||||
// Buffer protocol
|
||||
typedef struct _mp_buffer_info_t {
|
||||
|
@ -553,27 +558,12 @@ 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_t {
|
||||
// A type is an object so must start with this entry, which points to mp_type_type.
|
||||
mp_obj_base_t base;
|
||||
|
||||
// Flags associated with this type.
|
||||
uint16_t flags;
|
||||
|
||||
// The name of this type, a qstr.
|
||||
uint16_t name;
|
||||
|
||||
// Corresponds to __repr__ and __str__ special methods.
|
||||
mp_print_fun_t print;
|
||||
|
||||
// Corresponds to __new__ and __init__ special methods, to make an instance of the type.
|
||||
mp_make_new_fun_t make_new;
|
||||
|
||||
struct _mp_obj_type_ext {
|
||||
// Corresponds to __call__ special method, ie T(...).
|
||||
mp_call_fun_t call;
|
||||
|
||||
|
@ -582,19 +572,6 @@ struct _mp_obj_type_t {
|
|||
mp_unary_op_fun_t unary_op;
|
||||
mp_binary_op_fun_t binary_op;
|
||||
|
||||
// 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;
|
||||
|
||||
// Implements load, store and delete subscripting:
|
||||
// - value = MP_OBJ_SENTINEL means load
|
||||
// - value = MP_OBJ_NULL means delete
|
||||
|
@ -616,6 +593,38 @@ struct _mp_obj_type_t {
|
|||
|
||||
// One of disjoint protocols (interfaces), like mp_stream_p_t, etc.
|
||||
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;
|
||||
|
||||
// Flags associated with this type.
|
||||
uint16_t flags;
|
||||
// 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)
|
||||
|
@ -623,10 +632,54 @@ 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;
|
||||
#define MP_TYPE_EXTENDED_FIELDS(...) .ext = {{ __VA_ARGS__ }}
|
||||
struct _mp_obj_type_ext ext[];
|
||||
};
|
||||
|
||||
// _mp_obj_full_type_t must match _mp_obj_type_t exactly, except that the `ext` field
|
||||
// is a 1-element array rather than a flexible array member.
|
||||
struct _mp_obj_full_type_t {
|
||||
mp_obj_base_t base;
|
||||
uint16_t flags;
|
||||
uint16_t name;
|
||||
struct _mp_obj_dict_t *locals_dict;
|
||||
mp_make_new_fun_t make_new;
|
||||
mp_print_fun_t print;
|
||||
mp_attr_fun_t attr;
|
||||
const void *parent;
|
||||
struct _mp_obj_type_ext ext[1];
|
||||
};
|
||||
|
||||
|
||||
// If the type object in question is known to have the extended fields, you can
|
||||
// refer to type->MP_TYPE_CALL. Otherwise, you have to use mp_type_get_call_slot(type)
|
||||
// The same goes for other fields within the extended region.
|
||||
#define MP_TYPE_CALL ext[0].call
|
||||
#define MP_TYPE_UNARY_OP ext[0].unary_op
|
||||
#define MP_TYPE_BINARY_OP ext[0].binary_op
|
||||
#define MP_TYPE_SUBSCR ext[0].subscr
|
||||
#define MP_TYPE_GETITER ext[0].getiter
|
||||
#define MP_TYPE_ITERNEXT ext[0].iternext
|
||||
#define MP_TYPE_GET_BUFFER ext[0].buffer_p.get_buffer
|
||||
#define MP_TYPE_PROTOCOL ext[0].protocol
|
||||
extern mp_call_fun_t mp_type_get_call_slot(const mp_obj_type_t *);
|
||||
extern mp_unary_op_fun_t mp_type_get_unary_op_slot(const mp_obj_type_t *);
|
||||
extern mp_binary_op_fun_t mp_type_get_binary_op_slot(const mp_obj_type_t *);
|
||||
extern mp_subscr_fun_t mp_type_get_subscr_slot(const mp_obj_type_t *);
|
||||
extern mp_getiter_fun_t mp_type_get_getiter_slot(const mp_obj_type_t *);
|
||||
extern mp_fun_1_t mp_type_get_iternext_slot(const mp_obj_type_t *);
|
||||
extern mp_getbuffer_fun_t mp_type_get_getbuffer_slot(const mp_obj_type_t *);
|
||||
extern const void *mp_type_get_protocol_slot(const mp_obj_type_t *);
|
||||
|
||||
// These fields ended up not being placed in the extended area, but accessors
|
||||
// were created for them anyway.
|
||||
extern mp_attr_fun_t mp_type_get_attr_slot(const mp_obj_type_t *);
|
||||
extern const void *mp_type_get_parent_slot(const mp_obj_type_t *);
|
||||
|
||||
// Return the size of a type object, which can be one of two lengths depending whether it has
|
||||
// the extended fields or not.
|
||||
extern size_t mp_type_size(const mp_obj_type_t *);
|
||||
|
||||
// Constant types, globally accessible
|
||||
extern const mp_obj_type_t mp_type_type;
|
||||
extern const mp_obj_type_t mp_type_object;
|
||||
|
@ -752,7 +805,7 @@ extern const struct _mp_obj_exception_t mp_const_GeneratorExit_obj;
|
|||
// check for more specific object types.
|
||||
// Note: these are kept as macros because inline functions sometimes use much
|
||||
// more code space than the equivalent macros, depending on the compiler.
|
||||
#define mp_obj_is_type(o, t) (mp_obj_is_obj(o) && (((mp_obj_base_t *)MP_OBJ_TO_PTR(o))->type == (t))) // this does not work for checking int, str or fun; use below macros for that
|
||||
#define mp_obj_is_type(o, t) (mp_obj_is_obj(o) && (&(((mp_obj_base_t *)MP_OBJ_TO_PTR(o))->type->name) == &((t)->name))) // this does not work for checking int, str or fun; use below macros for that
|
||||
#if MICROPY_OBJ_IMMEDIATE_OBJS
|
||||
// bool's are immediates, not real objects, so test for the 2 possible values.
|
||||
#define mp_obj_is_bool(o) ((o) == mp_const_false || (o) == mp_const_true)
|
||||
|
@ -761,11 +814,11 @@ extern const struct _mp_obj_exception_t mp_const_GeneratorExit_obj;
|
|||
#endif
|
||||
#define mp_obj_is_int(o) (mp_obj_is_small_int(o) || mp_obj_is_type(o, &mp_type_int))
|
||||
#define mp_obj_is_str(o) (mp_obj_is_qstr(o) || mp_obj_is_type(o, &mp_type_str))
|
||||
#define mp_obj_is_str_or_bytes(o) (mp_obj_is_qstr(o) || (mp_obj_is_obj(o) && ((mp_obj_base_t *)MP_OBJ_TO_PTR(o))->type->binary_op == mp_obj_str_binary_op))
|
||||
#define mp_obj_is_str_or_bytes(o) (mp_obj_is_qstr(o) || (mp_obj_is_obj(o) && mp_type_get_binary_op_slot(((mp_obj_base_t *)MP_OBJ_TO_PTR(o))->type) == mp_obj_str_binary_op))
|
||||
#define mp_obj_is_dict_or_ordereddict(o) (mp_obj_is_obj(o) && ((mp_obj_base_t *)MP_OBJ_TO_PTR(o))->type->make_new == mp_obj_dict_make_new)
|
||||
#define mp_obj_is_fun(o) (mp_obj_is_obj(o) && (((mp_obj_base_t *)MP_OBJ_TO_PTR(o))->type->name == MP_QSTR_function))
|
||||
// type check is done on getiter method to allow tuple, namedtuple, attrtuple
|
||||
#define mp_obj_is_tuple_compatible(o) (mp_obj_get_type(o)->getiter == mp_obj_tuple_getiter)
|
||||
#define mp_obj_is_tuple_compatible(o) (mp_type_get_getiter_slot(mp_obj_get_type(o)) == mp_obj_tuple_getiter)
|
||||
|
||||
mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict);
|
||||
static inline mp_obj_t mp_obj_new_bool(mp_int_t x) {
|
||||
|
@ -824,6 +877,7 @@ mp_obj_t mp_obj_new_module(qstr module_name);
|
|||
mp_obj_t mp_obj_new_memoryview(byte typecode, size_t nitems, void *items);
|
||||
|
||||
const mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in);
|
||||
const mp_obj_full_type_t *mp_obj_get_full_type(mp_const_obj_t o_in);
|
||||
const char *mp_obj_get_type_str(mp_const_obj_t o_in);
|
||||
#define mp_obj_get_type_qstr(o_in) (mp_obj_get_type((o_in))->name)
|
||||
bool mp_obj_is_subclass_fast(mp_const_obj_t object, mp_const_obj_t classinfo); // arguments should be type objects
|
||||
|
|
|
@ -564,7 +564,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
|
|||
size_t src_len;
|
||||
void *src_items;
|
||||
size_t item_sz = mp_binary_get_size('@', o->typecode & TYPECODE_MASK, NULL);
|
||||
if (mp_obj_is_obj(value) && ((mp_obj_base_t *)MP_OBJ_TO_PTR(value))->type->subscr == array_subscr) {
|
||||
if (mp_obj_is_obj(value) && mp_type_get_subscr_slot(((mp_obj_base_t *)MP_OBJ_TO_PTR(value))->type) == array_subscr) {
|
||||
// value is array, bytearray or memoryview
|
||||
mp_obj_array_t *src_slice = MP_OBJ_TO_PTR(value);
|
||||
if (item_sz != mp_binary_get_size('@', src_slice->typecode & TYPECODE_MASK, NULL)) {
|
||||
|
@ -744,31 +744,36 @@ STATIC MP_DEFINE_CONST_DICT(bytearray_locals_dict, bytearray_locals_dict_table);
|
|||
#if MICROPY_PY_ARRAY
|
||||
const mp_obj_type_t mp_type_array = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_array,
|
||||
.print = array_print,
|
||||
.make_new = array_make_new,
|
||||
.getiter = array_iterator_new,
|
||||
.unary_op = array_unary_op,
|
||||
.binary_op = array_binary_op,
|
||||
.subscr = array_subscr,
|
||||
.buffer_p = { .get_buffer = array_get_buffer },
|
||||
.locals_dict = (mp_obj_dict_t *)&array_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = array_iterator_new,
|
||||
.unary_op = array_unary_op,
|
||||
.binary_op = array_binary_op,
|
||||
.subscr = array_subscr,
|
||||
.buffer_p = { .get_buffer = array_get_buffer },
|
||||
),
|
||||
};
|
||||
#endif
|
||||
|
||||
#if MICROPY_PY_BUILTINS_BYTEARRAY
|
||||
const mp_obj_type_t mp_type_bytearray = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE,
|
||||
.flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE | MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_bytearray,
|
||||
.print = array_print,
|
||||
.make_new = bytearray_make_new,
|
||||
.getiter = array_iterator_new,
|
||||
.unary_op = array_unary_op,
|
||||
.binary_op = array_binary_op,
|
||||
.subscr = array_subscr,
|
||||
.buffer_p = { .get_buffer = array_get_buffer },
|
||||
.locals_dict = (mp_obj_dict_t *)&bytearray_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = array_iterator_new,
|
||||
.unary_op = array_unary_op,
|
||||
.binary_op = array_binary_op,
|
||||
.subscr = array_subscr,
|
||||
.buffer_p = { .get_buffer = array_get_buffer },
|
||||
),
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -784,20 +789,22 @@ STATIC MP_DEFINE_CONST_DICT(memoryview_locals_dict, memoryview_locals_dict_table
|
|||
|
||||
const mp_obj_type_t mp_type_memoryview = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE,
|
||||
.flags = MP_TYPE_FLAG_EQ_CHECKS_OTHER_TYPE | MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_memoryview,
|
||||
.make_new = memoryview_make_new,
|
||||
.getiter = array_iterator_new,
|
||||
.unary_op = array_unary_op,
|
||||
.binary_op = array_binary_op,
|
||||
#if MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE
|
||||
.attr = memoryview_attr,
|
||||
#endif
|
||||
.subscr = array_subscr,
|
||||
.buffer_p = { .get_buffer = array_get_buffer },
|
||||
#if MICROPY_CPYTHON_COMPAT
|
||||
.locals_dict = (mp_obj_dict_t *)&memoryview_locals_dict,
|
||||
#endif
|
||||
#if MICROPY_PY_BUILTINS_MEMORYVIEW_ITEMSIZE
|
||||
.attr = memoryview_attr,
|
||||
#endif
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = array_iterator_new,
|
||||
.unary_op = array_unary_op,
|
||||
.binary_op = array_binary_op,
|
||||
.subscr = array_subscr,
|
||||
.buffer_p = { .get_buffer = array_get_buffer },
|
||||
),
|
||||
};
|
||||
#endif
|
||||
|
||||
|
@ -853,9 +860,12 @@ STATIC mp_obj_t array_it_iternext(mp_obj_t self_in) {
|
|||
|
||||
STATIC const mp_obj_type_t mp_type_array_it = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_iterator,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = array_it_iternext,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = array_it_iternext,
|
||||
),
|
||||
};
|
||||
|
||||
STATIC mp_obj_t array_iterator_new(mp_obj_t array_in, mp_obj_iter_buf_t *iter_buf) {
|
||||
|
|
|
@ -83,13 +83,16 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_tuple, // reuse tuple to save on a qstr
|
||||
.print = mp_obj_attrtuple_print,
|
||||
.unary_op = mp_obj_tuple_unary_op,
|
||||
.binary_op = mp_obj_tuple_binary_op,
|
||||
.attr = mp_obj_attrtuple_attr,
|
||||
.subscr = mp_obj_tuple_subscr,
|
||||
.getiter = mp_obj_tuple_getiter,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = mp_obj_tuple_unary_op,
|
||||
.binary_op = mp_obj_tuple_binary_op,
|
||||
.subscr = mp_obj_tuple_subscr,
|
||||
.getiter = mp_obj_tuple_getiter,
|
||||
),
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_ATTRTUPLE
|
||||
|
|
|
@ -86,12 +86,14 @@ 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_EXTENDED, // can match all numeric types
|
||||
.name = MP_QSTR_bool,
|
||||
.print = bool_print,
|
||||
.make_new = bool_make_new,
|
||||
.unary_op = bool_unary_op,
|
||||
.binary_op = bool_binary_op,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = bool_unary_op,
|
||||
.binary_op = bool_binary_op,
|
||||
),
|
||||
};
|
||||
|
||||
#if !MICROPY_OBJ_IMMEDIATE_OBJS
|
||||
|
|
|
@ -97,11 +97,14 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_bound_method,
|
||||
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
|
||||
.print = bound_meth_print,
|
||||
#endif
|
||||
.call = bound_meth_call,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.call = bound_meth_call,
|
||||
),
|
||||
#if MICROPY_PY_FUNCTION_ATTRS
|
||||
.attr = bound_meth_attr,
|
||||
#endif
|
||||
|
|
|
@ -80,12 +80,14 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_closure,
|
||||
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_DETAILED
|
||||
.print = closure_print,
|
||||
#endif
|
||||
.call = closure_call,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.call = closure_call,
|
||||
)
|
||||
};
|
||||
|
||||
mp_obj_t mp_obj_new_closure(mp_obj_t fun, size_t n_closed_over, const mp_obj_t *closed) {
|
||||
|
|
|
@ -157,13 +157,15 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_complex,
|
||||
.print = complex_print,
|
||||
.make_new = complex_make_new,
|
||||
.unary_op = complex_unary_op,
|
||||
.binary_op = complex_binary_op,
|
||||
.attr = complex_attr,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = complex_unary_op,
|
||||
.binary_op = complex_binary_op,
|
||||
),
|
||||
};
|
||||
|
||||
mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag) {
|
||||
|
|
|
@ -160,10 +160,13 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_deque,
|
||||
.make_new = deque_make_new,
|
||||
.unary_op = deque_unary_op,
|
||||
.locals_dict = (mp_obj_dict_t *)&deque_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = deque_unary_op,
|
||||
),
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_COLLECTIONS_DEQUE
|
||||
|
|
36
py/objdict.c
36
py/objdict.c
|
@ -459,9 +459,12 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_iterator,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = dict_view_it_iternext,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = dict_view_it_iternext,
|
||||
),
|
||||
};
|
||||
|
||||
STATIC mp_obj_t dict_view_getiter(mp_obj_t view_in, mp_obj_iter_buf_t *iter_buf) {
|
||||
|
@ -510,10 +513,13 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_dict_view,
|
||||
.print = dict_view_print,
|
||||
.binary_op = dict_view_binary_op,
|
||||
.getiter = dict_view_getiter,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.binary_op = dict_view_binary_op,
|
||||
.getiter = dict_view_getiter,
|
||||
),
|
||||
};
|
||||
|
||||
STATIC mp_obj_t mp_obj_new_dict_view(mp_obj_t dict, mp_dict_view_kind_t kind) {
|
||||
|
@ -584,28 +590,34 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_dict,
|
||||
.print = dict_print,
|
||||
.make_new = mp_obj_dict_make_new,
|
||||
.unary_op = dict_unary_op,
|
||||
.binary_op = dict_binary_op,
|
||||
.subscr = dict_subscr,
|
||||
.getiter = dict_getiter,
|
||||
.locals_dict = (mp_obj_dict_t *)&dict_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = dict_unary_op,
|
||||
.binary_op = dict_binary_op,
|
||||
.subscr = dict_subscr,
|
||||
.getiter = dict_getiter,
|
||||
),
|
||||
};
|
||||
|
||||
#if MICROPY_PY_COLLECTIONS_ORDEREDDICT
|
||||
const mp_obj_type_t mp_type_ordereddict = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_OrderedDict,
|
||||
.print = dict_print,
|
||||
.make_new = mp_obj_dict_make_new,
|
||||
.unary_op = dict_unary_op,
|
||||
.binary_op = dict_binary_op,
|
||||
.subscr = dict_subscr,
|
||||
.getiter = dict_getiter,
|
||||
.parent = &mp_type_dict,
|
||||
.locals_dict = (mp_obj_dict_t *)&dict_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = dict_unary_op,
|
||||
.binary_op = dict_binary_op,
|
||||
.subscr = dict_subscr,
|
||||
.getiter = dict_getiter,
|
||||
),
|
||||
};
|
||||
#endif
|
||||
|
||||
|
|
|
@ -71,10 +71,13 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_enumerate,
|
||||
.make_new = enumerate_make_new,
|
||||
.iternext = enumerate_iternext,
|
||||
.getiter = mp_identity_getiter,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.iternext = enumerate_iternext,
|
||||
.getiter = mp_identity_getiter,
|
||||
)
|
||||
};
|
||||
|
||||
STATIC mp_obj_t enumerate_iternext(mp_obj_t self_in) {
|
||||
|
|
|
@ -626,15 +626,18 @@ STATIC const mp_obj_namedtuple_type_t code_type_obj = {
|
|||
.base = {
|
||||
.type = &mp_type_type
|
||||
},
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_code,
|
||||
.print = namedtuple_print,
|
||||
.make_new = namedtuple_make_new,
|
||||
.unary_op = mp_obj_tuple_unary_op,
|
||||
.binary_op = mp_obj_tuple_binary_op,
|
||||
.attr = namedtuple_attr,
|
||||
.subscr = mp_obj_tuple_subscr,
|
||||
.getiter = mp_obj_tuple_getiter,
|
||||
.parent = &mp_type_tuple,
|
||||
.attr = namedtuple_attr,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = mp_obj_tuple_unary_op,
|
||||
.binary_op = mp_obj_tuple_binary_op,
|
||||
.subscr = mp_obj_tuple_subscr,
|
||||
.getiter = mp_obj_tuple_getiter,
|
||||
),
|
||||
},
|
||||
.n_fields = 15,
|
||||
.fields = {
|
||||
|
@ -686,12 +689,14 @@ STATIC const mp_obj_namedtuple_type_t frame_type_obj = {
|
|||
.name = MP_QSTR_frame,
|
||||
.print = namedtuple_print,
|
||||
.make_new = namedtuple_make_new,
|
||||
.unary_op = mp_obj_tuple_unary_op,
|
||||
.binary_op = mp_obj_tuple_binary_op,
|
||||
.attr = namedtuple_attr,
|
||||
.subscr = mp_obj_tuple_subscr,
|
||||
.getiter = mp_obj_tuple_getiter,
|
||||
.parent = &mp_type_tuple,
|
||||
.attr = namedtuple_attr,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = mp_obj_tuple_unary_op,
|
||||
.binary_op = mp_obj_tuple_binary_op,
|
||||
.subscr = mp_obj_tuple_subscr,
|
||||
.getiter = mp_obj_tuple_getiter,
|
||||
),
|
||||
},
|
||||
.n_fields = 8,
|
||||
.fields = {
|
||||
|
@ -726,15 +731,18 @@ STATIC const mp_obj_namedtuple_type_t traceback_type_obj = {
|
|||
.base = {
|
||||
.type = &mp_type_type
|
||||
},
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_traceback,
|
||||
.print = namedtuple_print,
|
||||
.make_new = namedtuple_make_new,
|
||||
.unary_op = mp_obj_tuple_unary_op,
|
||||
.binary_op = mp_obj_tuple_binary_op,
|
||||
.attr = namedtuple_attr,
|
||||
.subscr = mp_obj_tuple_subscr,
|
||||
.getiter = mp_obj_tuple_getiter,
|
||||
.parent = &mp_type_tuple,
|
||||
.attr = namedtuple_attr,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = mp_obj_tuple_unary_op,
|
||||
.binary_op = mp_obj_tuple_binary_op,
|
||||
.subscr = mp_obj_tuple_subscr,
|
||||
.getiter = mp_obj_tuple_getiter,
|
||||
),
|
||||
},
|
||||
.n_fields = 4,
|
||||
.fields = {
|
||||
|
|
|
@ -63,10 +63,13 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_filter,
|
||||
.make_new = filter_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = filter_iternext,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = filter_iternext,
|
||||
),
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_BUILTINS_FILTER
|
||||
|
|
|
@ -181,12 +181,14 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_float,
|
||||
.print = float_print,
|
||||
.make_new = float_make_new,
|
||||
.unary_op = float_unary_op,
|
||||
.binary_op = float_binary_op,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = float_unary_op,
|
||||
.binary_op = float_binary_op,
|
||||
),
|
||||
};
|
||||
|
||||
#if MICROPY_OBJ_REPR != MICROPY_OBJ_REPR_C && MICROPY_OBJ_REPR != MICROPY_OBJ_REPR_D
|
||||
|
|
64
py/objfun.c
64
py/objfun.c
|
@ -60,10 +60,12 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_function,
|
||||
.call = fun_builtin_0_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.call = fun_builtin_0_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
),
|
||||
};
|
||||
|
||||
STATIC mp_obj_t fun_builtin_1_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
|
@ -75,10 +77,12 @@ STATIC mp_obj_t fun_builtin_1_call(mp_obj_t self_in, size_t n_args, size_t n_kw,
|
|||
|
||||
const mp_obj_type_t mp_type_fun_builtin_1 = {
|
||||
{ &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_EXTENDED,
|
||||
.name = MP_QSTR_function,
|
||||
.call = fun_builtin_1_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.call = fun_builtin_1_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
),
|
||||
};
|
||||
|
||||
STATIC mp_obj_t fun_builtin_2_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
|
@ -90,10 +94,12 @@ STATIC mp_obj_t fun_builtin_2_call(mp_obj_t self_in, size_t n_args, size_t n_kw,
|
|||
|
||||
const mp_obj_type_t mp_type_fun_builtin_2 = {
|
||||
{ &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_EXTENDED,
|
||||
.name = MP_QSTR_function,
|
||||
.call = fun_builtin_2_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.call = fun_builtin_2_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
),
|
||||
};
|
||||
|
||||
STATIC mp_obj_t fun_builtin_3_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
|
@ -105,10 +111,12 @@ STATIC mp_obj_t fun_builtin_3_call(mp_obj_t self_in, size_t n_args, size_t n_kw,
|
|||
|
||||
const mp_obj_type_t mp_type_fun_builtin_3 = {
|
||||
{ &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_EXTENDED,
|
||||
.name = MP_QSTR_function,
|
||||
.call = fun_builtin_3_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.call = fun_builtin_3_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
),
|
||||
};
|
||||
|
||||
STATIC mp_obj_t fun_builtin_var_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
|
||||
|
@ -136,10 +144,12 @@ STATIC mp_obj_t fun_builtin_var_call(mp_obj_t self_in, size_t n_args, size_t n_k
|
|||
|
||||
const mp_obj_type_t mp_type_fun_builtin_var = {
|
||||
{ &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_EXTENDED,
|
||||
.name = MP_QSTR_function,
|
||||
.call = fun_builtin_var_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.call = fun_builtin_var_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
),
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
@ -362,16 +372,18 @@ void mp_obj_fun_bc_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
|||
|
||||
const mp_obj_type_t mp_type_fun_bc = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_BINDS_SELF,
|
||||
.flags = MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_function,
|
||||
#if MICROPY_CPYTHON_COMPAT
|
||||
.print = fun_bc_print,
|
||||
#endif
|
||||
.call = fun_bc_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
#if MICROPY_PY_FUNCTION_ATTRS
|
||||
.attr = mp_obj_fun_bc_attr,
|
||||
#endif
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.call = fun_bc_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
),
|
||||
};
|
||||
|
||||
mp_obj_t mp_obj_new_fun_bc(mp_obj_t def_args_in, mp_obj_t def_kw_args, const byte *code, const mp_uint_t *const_table) {
|
||||
|
@ -414,10 +426,12 @@ STATIC mp_obj_t fun_native_call(mp_obj_t self_in, size_t n_args, size_t n_kw, co
|
|||
|
||||
const mp_obj_type_t mp_type_fun_native = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_BINDS_SELF,
|
||||
.flags = MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_function,
|
||||
.call = fun_native_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.call = fun_native_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
),
|
||||
};
|
||||
|
||||
mp_obj_t mp_obj_new_fun_native(mp_obj_t def_args_in, mp_obj_t def_kw_args, const void *fun_data, const mp_uint_t *const_table) {
|
||||
|
@ -522,10 +536,12 @@ STATIC mp_obj_t fun_asm_call(mp_obj_t self_in, size_t n_args, size_t n_kw, const
|
|||
|
||||
STATIC const mp_obj_type_t mp_type_fun_asm = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_BINDS_SELF,
|
||||
.flags = MP_TYPE_FLAG_BINDS_SELF | MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_function,
|
||||
.call = fun_asm_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.call = fun_asm_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
),
|
||||
};
|
||||
|
||||
mp_obj_t mp_obj_new_fun_asm(size_t n_args, const void *fun_data, mp_uint_t type_sig) {
|
||||
|
|
|
@ -157,13 +157,15 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_generator,
|
||||
.call = gen_wrap_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
#if MICROPY_PY_FUNCTION_ATTRS
|
||||
.attr = gen_attr,
|
||||
#endif
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.call = gen_wrap_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
),
|
||||
};
|
||||
|
||||
|
||||
|
@ -412,10 +414,13 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_generator,
|
||||
.print = gen_instance_print,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = gen_instance_iternext,
|
||||
.locals_dict = (mp_obj_dict_t *)&gen_instance_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = mp_generic_unary_op,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = gen_instance_iternext,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -59,9 +59,12 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_iterator,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = it_iternext,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = it_iternext,
|
||||
),
|
||||
};
|
||||
|
||||
// args are those returned from mp_load_method_maybe (ie either an attribute or a method)
|
||||
|
|
|
@ -571,9 +571,12 @@ 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_EXTENDED,
|
||||
.print = mp_obj_int_print,
|
||||
.make_new = mp_obj_int_make_new,
|
||||
.unary_op = mp_obj_int_unary_op,
|
||||
.binary_op = mp_obj_int_binary_op,
|
||||
.locals_dict = (mp_obj_dict_t *)&int_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = mp_obj_int_unary_op,
|
||||
.binary_op = mp_obj_int_binary_op,
|
||||
),
|
||||
};
|
||||
|
|
11
py/objlist.c
11
py/objlist.c
|
@ -461,14 +461,17 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_list,
|
||||
.print = list_print,
|
||||
.make_new = list_make_new,
|
||||
.unary_op = list_unary_op,
|
||||
.binary_op = list_binary_op,
|
||||
.subscr = list_subscr,
|
||||
.getiter = list_getiter,
|
||||
.locals_dict = (mp_obj_dict_t *)&list_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = list_unary_op,
|
||||
.binary_op = list_binary_op,
|
||||
.subscr = list_subscr,
|
||||
.getiter = list_getiter,
|
||||
),
|
||||
};
|
||||
|
||||
void mp_obj_list_init(mp_obj_list_t *o, size_t n) {
|
||||
|
|
|
@ -66,8 +66,11 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_map,
|
||||
.make_new = map_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = map_iternext,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = map_iternext,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -168,15 +168,15 @@ 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_EXTENDED; // can match tuple
|
||||
o->base.name = name;
|
||||
o->base.print = namedtuple_print;
|
||||
o->base.make_new = namedtuple_make_new;
|
||||
o->base.unary_op = mp_obj_tuple_unary_op;
|
||||
o->base.binary_op = mp_obj_tuple_binary_op;
|
||||
o->base.MP_TYPE_UNARY_OP = mp_obj_tuple_unary_op;
|
||||
o->base.MP_TYPE_BINARY_OP = mp_obj_tuple_binary_op;
|
||||
o->base.attr = namedtuple_attr;
|
||||
o->base.subscr = mp_obj_tuple_subscr;
|
||||
o->base.getiter = mp_obj_tuple_getiter;
|
||||
o->base.MP_TYPE_SUBSCR = mp_obj_tuple_subscr;
|
||||
o->base.MP_TYPE_GETITER = mp_obj_tuple_getiter;
|
||||
o->base.parent = &mp_type_tuple;
|
||||
return MP_OBJ_FROM_PTR(o);
|
||||
}
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#if MICROPY_PY_COLLECTIONS
|
||||
|
||||
typedef struct _mp_obj_namedtuple_type_t {
|
||||
mp_obj_type_t base;
|
||||
mp_obj_full_type_t base;
|
||||
size_t n_fields;
|
||||
qstr fields[];
|
||||
} mp_obj_namedtuple_type_t;
|
||||
|
|
|
@ -45,9 +45,12 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_NoneType,
|
||||
.print = none_print,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = mp_generic_unary_op,
|
||||
),
|
||||
};
|
||||
|
||||
#if !MICROPY_OBJ_IMMEDIATE_OBJS
|
||||
|
|
|
@ -47,7 +47,10 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_iterator,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = polymorph_it_iternext,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = polymorph_it_iternext,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -54,9 +54,12 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_iterator,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = range_it_iternext,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = range_it_iternext,
|
||||
),
|
||||
};
|
||||
|
||||
STATIC mp_obj_t mp_obj_new_range_iterator(mp_int_t cur, mp_int_t stop, mp_int_t step, mp_obj_iter_buf_t *iter_buf) {
|
||||
|
@ -214,16 +217,19 @@ STATIC void range_attr(mp_obj_t o_in, qstr attr, mp_obj_t *dest) {
|
|||
|
||||
const mp_obj_type_t mp_type_range = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_range,
|
||||
.print = range_print,
|
||||
.make_new = range_make_new,
|
||||
.unary_op = range_unary_op,
|
||||
#if MICROPY_PY_BUILTINS_RANGE_BINOP
|
||||
.binary_op = range_binary_op,
|
||||
#endif
|
||||
.subscr = range_subscr,
|
||||
.getiter = range_getiter,
|
||||
#if MICROPY_PY_BUILTINS_RANGE_ATTRS
|
||||
.attr = range_attr,
|
||||
#endif
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = range_unary_op,
|
||||
#if MICROPY_PY_BUILTINS_RANGE_BINOP
|
||||
.binary_op = range_binary_op,
|
||||
#endif
|
||||
.subscr = range_subscr,
|
||||
.getiter = range_getiter,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -71,10 +71,13 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_reversed,
|
||||
.make_new = reversed_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = reversed_iternext,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = reversed_iternext,
|
||||
),
|
||||
};
|
||||
|
||||
#endif // MICROPY_PY_BUILTINS_REVERSED
|
||||
|
|
19
py/objset.c
19
py/objset.c
|
@ -545,13 +545,16 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_set,
|
||||
.print = set_print,
|
||||
.make_new = set_make_new,
|
||||
.unary_op = set_unary_op,
|
||||
.binary_op = set_binary_op,
|
||||
.getiter = set_getiter,
|
||||
.locals_dict = (mp_obj_dict_t *)&set_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = set_unary_op,
|
||||
.binary_op = set_binary_op,
|
||||
.getiter = set_getiter,
|
||||
),
|
||||
};
|
||||
|
||||
#if MICROPY_PY_BUILTINS_FROZENSET
|
||||
|
@ -570,14 +573,16 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_frozenset,
|
||||
.print = set_print,
|
||||
.make_new = set_make_new,
|
||||
.unary_op = set_unary_op,
|
||||
.binary_op = set_binary_op,
|
||||
.getiter = set_getiter,
|
||||
.locals_dict = (mp_obj_dict_t *)&frozenset_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = set_unary_op,
|
||||
.binary_op = set_binary_op,
|
||||
.getiter = set_getiter,
|
||||
),
|
||||
};
|
||||
#endif
|
||||
|
||||
|
|
|
@ -45,9 +45,12 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_,
|
||||
.print = singleton_print,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = mp_generic_unary_op,
|
||||
),
|
||||
};
|
||||
|
||||
const mp_obj_singleton_t mp_const_ellipsis_obj = {{&mp_type_singleton}, MP_QSTR_Ellipsis};
|
||||
|
|
11
py/objstr.c
11
py/objstr.c
|
@ -2035,14 +2035,17 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_bytes,
|
||||
.print = str_print,
|
||||
.make_new = bytes_make_new,
|
||||
.binary_op = mp_obj_str_binary_op,
|
||||
.subscr = bytes_subscr,
|
||||
.getiter = mp_obj_new_bytes_iterator,
|
||||
.buffer_p = { .get_buffer = mp_obj_str_get_buffer },
|
||||
.locals_dict = (mp_obj_dict_t *)&str8_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.binary_op = mp_obj_str_binary_op,
|
||||
.subscr = bytes_subscr,
|
||||
.getiter = mp_obj_new_bytes_iterator,
|
||||
.buffer_p = { .get_buffer = mp_obj_str_get_buffer },
|
||||
),
|
||||
};
|
||||
|
||||
// The zero-length bytes object, with data that includes a null-terminating byte
|
||||
|
|
|
@ -246,13 +246,16 @@ STATIC const mp_stream_p_t stringio_stream_p = {
|
|||
|
||||
const mp_obj_type_t mp_type_stringio = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_StringIO,
|
||||
.print = stringio_print,
|
||||
.make_new = stringio_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &stringio_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t *)&stringio_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &stringio_stream_p,
|
||||
),
|
||||
};
|
||||
|
||||
#if MICROPY_PY_IO_BYTESIO
|
||||
|
@ -265,13 +268,16 @@ STATIC const mp_stream_p_t bytesio_stream_p = {
|
|||
|
||||
const mp_obj_type_t mp_type_bytesio = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_BytesIO,
|
||||
.print = stringio_print,
|
||||
.make_new = stringio_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &bytesio_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t *)&stringio_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &bytesio_stream_p,
|
||||
),
|
||||
};
|
||||
#endif
|
||||
|
||||
|
|
|
@ -291,15 +291,18 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_str,
|
||||
.print = uni_print,
|
||||
.make_new = mp_obj_str_make_new,
|
||||
.unary_op = uni_unary_op,
|
||||
.binary_op = mp_obj_str_binary_op,
|
||||
.subscr = str_subscr,
|
||||
.getiter = mp_obj_new_str_iterator,
|
||||
.buffer_p = { .get_buffer = mp_obj_str_get_buffer },
|
||||
.locals_dict = (mp_obj_dict_t *)&struni_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = uni_unary_op,
|
||||
.binary_op = mp_obj_str_binary_op,
|
||||
.subscr = str_subscr,
|
||||
.getiter = mp_obj_new_str_iterator,
|
||||
.buffer_p = { .get_buffer = mp_obj_str_get_buffer },
|
||||
),
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
|
|
@ -108,7 +108,7 @@ STATIC mp_obj_t tuple_cmp_helper(mp_uint_t op, mp_obj_t self_in, mp_obj_t anothe
|
|||
mp_check_self(mp_obj_is_tuple_compatible(self_in));
|
||||
const mp_obj_type_t *another_type = mp_obj_get_type(another_in);
|
||||
mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
if (another_type->getiter != mp_obj_tuple_getiter) {
|
||||
if (mp_type_get_getiter_slot(another_type) != mp_obj_tuple_getiter) {
|
||||
// Slow path for user subclasses
|
||||
another_in = mp_obj_cast_to_native_base(another_in, MP_OBJ_FROM_PTR(&mp_type_tuple));
|
||||
if (another_in == MP_OBJ_NULL) {
|
||||
|
@ -184,7 +184,7 @@ mp_obj_t mp_obj_tuple_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
|
|||
// load
|
||||
mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in);
|
||||
// when called with a native type (eg namedtuple) using mp_obj_tuple_subscr, get the native self
|
||||
if (self->base.type->subscr != &mp_obj_tuple_subscr) {
|
||||
if (mp_type_get_subscr_slot(self->base.type) != &mp_obj_tuple_subscr) {
|
||||
self = mp_obj_cast_to_native_base(self_in, &mp_type_tuple);
|
||||
}
|
||||
|
||||
|
@ -229,14 +229,17 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_tuple,
|
||||
.print = mp_obj_tuple_print,
|
||||
.make_new = mp_obj_tuple_make_new,
|
||||
.unary_op = mp_obj_tuple_unary_op,
|
||||
.binary_op = mp_obj_tuple_binary_op,
|
||||
.subscr = mp_obj_tuple_subscr,
|
||||
.getiter = mp_obj_tuple_getiter,
|
||||
.locals_dict = (mp_obj_dict_t *)&tuple_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = mp_obj_tuple_unary_op,
|
||||
.binary_op = mp_obj_tuple_binary_op,
|
||||
.subscr = mp_obj_tuple_subscr,
|
||||
.getiter = mp_obj_tuple_getiter,
|
||||
),
|
||||
};
|
||||
|
||||
// the zero-length tuple
|
||||
|
|
98
py/objtype.c
98
py/objtype.c
|
@ -59,17 +59,20 @@ STATIC int instance_count_native_bases(const mp_obj_type_t *type, const mp_obj_t
|
|||
if (type == &mp_type_object) {
|
||||
// Not a "real" type, end search here.
|
||||
return count;
|
||||
} else if (mp_obj_is_native_type(type)) {
|
||||
}
|
||||
if (mp_obj_is_native_type(type)) {
|
||||
// Native types don't have parents (at least not from our perspective) so end.
|
||||
*last_native_base = type;
|
||||
return count + 1;
|
||||
} else if (type->parent == NULL) {
|
||||
}
|
||||
const void *parent = mp_type_get_parent_slot(type);
|
||||
if (parent == NULL) {
|
||||
// No parents so end search here.
|
||||
return count;
|
||||
#if MICROPY_MULTIPLE_INHERITANCE
|
||||
} else if (((mp_obj_base_t *)type->parent)->type == &mp_type_tuple) {
|
||||
} else if (((mp_obj_base_t *)parent)->type == &mp_type_tuple) {
|
||||
// Multiple parents, search through them all recursively.
|
||||
const mp_obj_tuple_t *parent_tuple = type->parent;
|
||||
const mp_obj_tuple_t *parent_tuple = parent;
|
||||
const mp_obj_t *item = parent_tuple->items;
|
||||
const mp_obj_t *top = item + parent_tuple->len;
|
||||
for (; item < top; ++item) {
|
||||
|
@ -81,7 +84,7 @@ STATIC int instance_count_native_bases(const mp_obj_type_t *type, const mp_obj_t
|
|||
#endif
|
||||
} else {
|
||||
// A single parent, use iteration to continue the search.
|
||||
type = type->parent;
|
||||
type = parent;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -159,7 +162,8 @@ STATIC void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_t
|
|||
if (lookup->meth_offset != 0 && mp_obj_is_native_type(type)) {
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wcast-align"
|
||||
if (*(void **)((char *)type + lookup->meth_offset) != NULL) {
|
||||
size_t sz = mp_type_size(type);
|
||||
if (lookup->meth_offset < sz && *(void **)((char *)type + lookup->meth_offset) != NULL) {
|
||||
#pragma GCC diagnostic pop
|
||||
DEBUG_printf("mp_obj_class_lookup: Matched special meth slot (off=%d) for %s\n",
|
||||
lookup->meth_offset, qstr_str(lookup->attr));
|
||||
|
@ -211,12 +215,14 @@ STATIC void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_t
|
|||
|
||||
// attribute not found, keep searching base classes
|
||||
|
||||
if (type->parent == NULL) {
|
||||
const void *parent = mp_type_get_parent_slot(type);
|
||||
if (parent == NULL) {
|
||||
DEBUG_printf("mp_obj_class_lookup: No more parents\n");
|
||||
return;
|
||||
}
|
||||
#if MICROPY_MULTIPLE_INHERITANCE
|
||||
} else if (((mp_obj_base_t *)type->parent)->type == &mp_type_tuple) {
|
||||
const mp_obj_tuple_t *parent_tuple = type->parent;
|
||||
if (((mp_obj_base_t *)parent)->type == &mp_type_tuple) {
|
||||
const mp_obj_tuple_t *parent_tuple = parent;
|
||||
const mp_obj_t *item = parent_tuple->items;
|
||||
const mp_obj_t *top = item + parent_tuple->len - 1;
|
||||
for (; item < top; ++item) {
|
||||
|
@ -235,10 +241,10 @@ STATIC void mp_obj_class_lookup(struct class_lookup_data *lookup, const mp_obj_t
|
|||
// search last base (simple tail recursion elimination)
|
||||
assert(mp_obj_is_type(*item, &mp_type_type));
|
||||
type = (mp_obj_type_t *)MP_OBJ_TO_PTR(*item);
|
||||
#endif
|
||||
} else {
|
||||
type = type->parent;
|
||||
continue;
|
||||
}
|
||||
#endif
|
||||
type = parent;
|
||||
if (type == &mp_type_object) {
|
||||
// Not a "real" type
|
||||
return;
|
||||
|
@ -434,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,
|
||||
};
|
||||
|
@ -562,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,
|
||||
};
|
||||
|
@ -833,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,
|
||||
};
|
||||
|
@ -850,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;
|
||||
|
@ -872,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,
|
||||
};
|
||||
|
@ -911,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,
|
||||
};
|
||||
|
@ -923,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);
|
||||
}
|
||||
|
@ -935,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
|
||||
}
|
||||
|
@ -1079,7 +1085,8 @@ STATIC void type_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
|||
dest[0] = mp_const_empty_tuple;
|
||||
return;
|
||||
}
|
||||
mp_obj_t parent_obj = self->parent ? MP_OBJ_FROM_PTR(self->parent) : MP_OBJ_FROM_PTR(&mp_type_object);
|
||||
const void *parent = mp_type_get_parent_slot(self);
|
||||
mp_obj_t parent_obj = parent ? MP_OBJ_FROM_PTR(parent) : MP_OBJ_FROM_PTR(&mp_type_object);
|
||||
#if MICROPY_MULTIPLE_INHERITANCE
|
||||
if (mp_obj_is_type(parent_obj, &mp_type_tuple)) {
|
||||
dest[0] = parent_obj;
|
||||
|
@ -1139,12 +1146,15 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_type,
|
||||
.print = type_print,
|
||||
.make_new = type_make_new,
|
||||
.call = type_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
.attr = type_attr,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.call = type_call,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
),
|
||||
};
|
||||
|
||||
mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict) {
|
||||
|
@ -1160,7 +1170,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_EXTENDED;
|
||||
size_t bases_len;
|
||||
mp_obj_t *bases_items;
|
||||
mp_obj_tuple_get(bases_tuple, &bases_len, &bases_items);
|
||||
|
@ -1186,27 +1196,27 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
|
|||
#endif
|
||||
}
|
||||
|
||||
mp_obj_type_t *o = m_new0_ll(mp_obj_type_t, 1);
|
||||
mp_obj_full_type_t *o = m_new0_ll(mp_obj_full_type_t, 1);
|
||||
o->base.type = &mp_type_type;
|
||||
o->flags = base_flags;
|
||||
o->name = name;
|
||||
o->print = instance_print;
|
||||
o->make_new = mp_obj_instance_make_new;
|
||||
o->call = mp_obj_instance_call;
|
||||
o->unary_op = instance_unary_op;
|
||||
o->binary_op = instance_binary_op;
|
||||
o->attr = mp_obj_instance_attr;
|
||||
o->subscr = instance_subscr;
|
||||
o->getiter = mp_obj_instance_getiter;
|
||||
o->MP_TYPE_CALL = mp_obj_instance_call;
|
||||
o->MP_TYPE_UNARY_OP = instance_unary_op;
|
||||
o->MP_TYPE_BINARY_OP = instance_binary_op;
|
||||
o->MP_TYPE_SUBSCR = instance_subscr;
|
||||
o->MP_TYPE_GETITER = mp_obj_instance_getiter;
|
||||
// o->iternext = ; not implemented
|
||||
o->buffer_p.get_buffer = instance_get_buffer;
|
||||
o->MP_TYPE_GET_BUFFER = instance_get_buffer;
|
||||
|
||||
if (bases_len > 0) {
|
||||
// Inherit protocol from a base class. This allows to define an
|
||||
// abstract base class which would translate C-level protocol to
|
||||
// Python method calls, and any subclass inheriting from it will
|
||||
// support this feature.
|
||||
o->protocol = ((mp_obj_type_t *)MP_OBJ_TO_PTR(bases_items[0]))->protocol;
|
||||
o->MP_TYPE_PROTOCOL = mp_type_get_protocol_slot((mp_obj_type_t *)MP_OBJ_TO_PTR(bases_items[0]));
|
||||
|
||||
if (bases_len >= 2) {
|
||||
#if MICROPY_MULTIPLE_INHERITANCE
|
||||
|
@ -1237,7 +1247,7 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
|
|||
#endif
|
||||
|
||||
const mp_obj_type_t *native_base;
|
||||
size_t num_native_bases = instance_count_native_bases(o, &native_base);
|
||||
size_t num_native_bases = instance_count_native_bases((mp_obj_type_t *)o, &native_base);
|
||||
if (num_native_bases > 1) {
|
||||
mp_raise_TypeError(MP_ERROR_TEXT("multiple bases have instance lay-out conflict"));
|
||||
}
|
||||
|
@ -1324,11 +1334,12 @@ STATIC void super_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
|||
lookup.meth_offset = offsetof(mp_obj_type_t, make_new);
|
||||
}
|
||||
|
||||
if (type->parent == NULL) {
|
||||
const void *parent = mp_type_get_parent_slot(type);
|
||||
if (parent == NULL) {
|
||||
// no parents, do nothing
|
||||
#if MICROPY_MULTIPLE_INHERITANCE
|
||||
} else if (((mp_obj_base_t *)type->parent)->type == &mp_type_tuple) {
|
||||
const mp_obj_tuple_t *parent_tuple = type->parent;
|
||||
} else if (((mp_obj_base_t *)parent)->type == &mp_type_tuple) {
|
||||
const mp_obj_tuple_t *parent_tuple = parent;
|
||||
size_t len = parent_tuple->len;
|
||||
const mp_obj_t *items = parent_tuple->items;
|
||||
for (size_t i = 0; i < len; i++) {
|
||||
|
@ -1344,8 +1355,8 @@ STATIC void super_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
|
|||
}
|
||||
}
|
||||
#endif
|
||||
} else if (type->parent != &mp_type_object) {
|
||||
mp_obj_class_lookup(&lookup, type->parent);
|
||||
} else if (parent != &mp_type_object) {
|
||||
mp_obj_class_lookup(&lookup, parent);
|
||||
}
|
||||
|
||||
if (dest[0] != MP_OBJ_NULL) {
|
||||
|
@ -1419,14 +1430,15 @@ bool mp_obj_is_subclass_fast(mp_const_obj_t object, mp_const_obj_t classinfo) {
|
|||
}
|
||||
|
||||
const mp_obj_type_t *self = MP_OBJ_TO_PTR(object);
|
||||
const void *parent = mp_type_get_parent_slot(self);
|
||||
|
||||
if (self->parent == NULL) {
|
||||
if (parent == NULL) {
|
||||
// type has no parents
|
||||
return false;
|
||||
#if MICROPY_MULTIPLE_INHERITANCE
|
||||
} else if (((mp_obj_base_t *)self->parent)->type == &mp_type_tuple) {
|
||||
} else if (((mp_obj_base_t *)parent)->type == &mp_type_tuple) {
|
||||
// get the base objects (they should be type objects)
|
||||
const mp_obj_tuple_t *parent_tuple = self->parent;
|
||||
const mp_obj_tuple_t *parent_tuple = parent;
|
||||
const mp_obj_t *item = parent_tuple->items;
|
||||
const mp_obj_t *top = item + parent_tuple->len - 1;
|
||||
|
||||
|
@ -1442,7 +1454,7 @@ bool mp_obj_is_subclass_fast(mp_const_obj_t object, mp_const_obj_t classinfo) {
|
|||
#endif
|
||||
} else {
|
||||
// type has 1 parent
|
||||
object = MP_OBJ_FROM_PTR(self->parent);
|
||||
object = MP_OBJ_FROM_PTR(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -69,8 +69,11 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_zip,
|
||||
.make_new = zip_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = zip_iternext,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = zip_iternext,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -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_get_binary_op_slot(type);
|
||||
return binary_op(MP_BINARY_OP_CONTAINS, lhs_in, rhs_in);
|
||||
}
|
||||
MP_DEFINE_CONST_FUN_OBJ_2(mp_op_contains_obj, op_contains);
|
||||
|
|
|
@ -31,12 +31,13 @@
|
|||
#ifndef MICROPY_UNSAFE_PROTO
|
||||
const void *mp_proto_get(uint16_t name, mp_const_obj_t obj) {
|
||||
const mp_obj_type_t *type = mp_obj_get_type(obj);
|
||||
if (!type->protocol) {
|
||||
const void *protocol = mp_type_get_protocol_slot(type);
|
||||
if (!protocol) {
|
||||
return NULL;
|
||||
}
|
||||
uint16_t proto_name = *(const uint16_t *)type->protocol;
|
||||
uint16_t proto_name = *(const uint16_t *)protocol;
|
||||
if (proto_name == name) {
|
||||
return type->protocol;
|
||||
return protocol;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#define MP_PROTOCOL_HEAD /* NOTHING */
|
||||
#define MP_PROTO_IMPLEMENT(name) /* NOTHING */
|
||||
static inline void *mp_proto_get(uint16_t name, mp_const_obj_type_t obj) {
|
||||
return mp_obj_get_type(obj)->protocol;
|
||||
return mp_type_get_protocol_slot(mp_obj_get_type(obj));
|
||||
}
|
||||
#else
|
||||
#define MP_PROTOCOL_HEAD \
|
||||
|
|
66
py/runtime.c
66
py/runtime.c
|
@ -282,8 +282,9 @@ mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg) {
|
|||
return MP_OBJ_NEW_SMALL_INT(h);
|
||||
} else {
|
||||
const mp_obj_type_t *type = mp_obj_get_type(arg);
|
||||
if (type->unary_op != NULL) {
|
||||
mp_obj_t result = type->unary_op(op, arg);
|
||||
mp_unary_op_fun_t unary_op = mp_type_get_unary_op_slot(type);
|
||||
if (unary_op != NULL) {
|
||||
mp_obj_t result = unary_op(op, arg);
|
||||
if (result != MP_OBJ_NULL) {
|
||||
return result;
|
||||
}
|
||||
|
@ -571,8 +572,9 @@ mp_obj_t PLACE_IN_ITCM(mp_binary_op)(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t r
|
|||
const mp_obj_type_t *type;
|
||||
generic_binary_op:
|
||||
type = mp_obj_get_type(lhs);
|
||||
if (type->binary_op != NULL) {
|
||||
mp_obj_t result = type->binary_op(op, lhs, rhs);
|
||||
mp_binary_op_fun_t binary_op = mp_type_get_binary_op_slot(type);
|
||||
if (binary_op != NULL) {
|
||||
mp_obj_t result = binary_op(op, lhs, rhs);
|
||||
if (result != MP_OBJ_NULL) {
|
||||
return result;
|
||||
}
|
||||
|
@ -647,8 +649,9 @@ mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, size_t n_args, size_t n_kw, cons
|
|||
const mp_obj_type_t *type = mp_obj_get_type(fun_in);
|
||||
|
||||
// do the call
|
||||
if (type->call != NULL) {
|
||||
return type->call(fun_in, n_args, n_kw, args);
|
||||
mp_call_fun_t call = mp_type_get_call_slot(type);
|
||||
if (call) {
|
||||
return call(fun_in, n_args, n_kw, args);
|
||||
}
|
||||
|
||||
#if MICROPY_ERROR_REPORTING <= MICROPY_ERROR_REPORTING_TERSE
|
||||
|
@ -1000,9 +1003,11 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_function,
|
||||
.call = checked_fun_call,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.call = checked_fun_call,
|
||||
)
|
||||
};
|
||||
|
||||
STATIC mp_obj_t mp_obj_new_checked_fun(const mp_obj_type_t *type, mp_obj_t fun) {
|
||||
|
@ -1108,15 +1113,18 @@ void mp_load_method_maybe(mp_obj_t obj, qstr attr, mp_obj_t *dest) {
|
|||
}
|
||||
#endif
|
||||
|
||||
if (attr == MP_QSTR___next__ && type->iternext != NULL) {
|
||||
if (attr == MP_QSTR___next__ && mp_type_get_iternext_slot(type) != NULL) {
|
||||
dest[0] = MP_OBJ_FROM_PTR(&mp_builtin_next_obj);
|
||||
dest[1] = obj;
|
||||
|
||||
} else if (type->attr != NULL) {
|
||||
return;
|
||||
}
|
||||
mp_attr_fun_t attr_fun = mp_type_get_attr_slot(type);
|
||||
if (attr_fun != NULL) {
|
||||
// this type can do its own load, so call it
|
||||
type->attr(obj, attr, dest);
|
||||
|
||||
} else if (type->locals_dict != NULL) {
|
||||
attr_fun(obj, attr, dest);
|
||||
return;
|
||||
}
|
||||
if (type->locals_dict != NULL) {
|
||||
// generic method lookup
|
||||
// this is a lookup in the object (ie not class or type)
|
||||
assert(type->locals_dict->base.type == &mp_type_dict); // MicroPython restriction, for now
|
||||
|
@ -1171,9 +1179,10 @@ void mp_load_method_protected(mp_obj_t obj, qstr attr, mp_obj_t *dest, bool catc
|
|||
void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) {
|
||||
DEBUG_OP_printf("store attr %p.%s <- %p\n", base, qstr_str(attr), value);
|
||||
const mp_obj_type_t *type = mp_obj_get_type(base);
|
||||
if (type->attr != NULL) {
|
||||
mp_attr_fun_t attr_fun = mp_type_get_attr_slot(type);
|
||||
if (attr_fun != NULL) {
|
||||
mp_obj_t dest[2] = {MP_OBJ_SENTINEL, value};
|
||||
type->attr(base, attr, dest);
|
||||
attr_fun(base, attr, dest);
|
||||
if (dest[0] == MP_OBJ_NULL) {
|
||||
// success
|
||||
return;
|
||||
|
@ -1221,21 +1230,21 @@ void mp_store_attr(mp_obj_t base, qstr attr, mp_obj_t value) {
|
|||
mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) {
|
||||
assert(o_in);
|
||||
const mp_obj_type_t *type = mp_obj_get_type(o_in);
|
||||
|
||||
mp_getiter_fun_t getiter = mp_type_get_getiter_slot(type);
|
||||
// Check for native getiter which is the identity. We handle this case explicitly
|
||||
// so we don't unnecessarily allocate any RAM for the iter_buf, which won't be used.
|
||||
if (type->getiter == mp_identity_getiter) {
|
||||
if (getiter == mp_identity_getiter) {
|
||||
return o_in;
|
||||
}
|
||||
|
||||
// check for native getiter (corresponds to __iter__)
|
||||
if (type->getiter != NULL) {
|
||||
if (iter_buf == NULL && type->getiter != mp_obj_instance_getiter) {
|
||||
if (getiter != NULL) {
|
||||
if (iter_buf == NULL && getiter != mp_obj_instance_getiter) {
|
||||
// if caller did not provide a buffer then allocate one on the heap
|
||||
// mp_obj_instance_getiter is special, it will allocate only if needed
|
||||
iter_buf = m_new_obj(mp_obj_iter_buf_t);
|
||||
}
|
||||
mp_obj_t iter = type->getiter(o_in, iter_buf);
|
||||
mp_obj_t iter = getiter(o_in, iter_buf);
|
||||
if (iter != MP_OBJ_NULL) {
|
||||
return iter;
|
||||
}
|
||||
|
@ -1266,8 +1275,9 @@ mp_obj_t mp_getiter(mp_obj_t o_in, mp_obj_iter_buf_t *iter_buf) {
|
|||
// may also raise StopIteration()
|
||||
mp_obj_t mp_iternext_allow_raise(mp_obj_t o_in) {
|
||||
const mp_obj_type_t *type = mp_obj_get_type(o_in);
|
||||
if (type->iternext != NULL) {
|
||||
return type->iternext(o_in);
|
||||
mp_fun_1_t iternext = mp_type_get_iternext_slot(type);
|
||||
if (iternext != NULL) {
|
||||
return iternext(o_in);
|
||||
} else {
|
||||
// check for __next__ method
|
||||
mp_obj_t dest[2];
|
||||
|
@ -1291,8 +1301,9 @@ mp_obj_t mp_iternext_allow_raise(mp_obj_t o_in) {
|
|||
mp_obj_t mp_iternext(mp_obj_t o_in) {
|
||||
MP_STACK_CHECK(); // enumerate, filter, map and zip can recursively call mp_iternext
|
||||
const mp_obj_type_t *type = mp_obj_get_type(o_in);
|
||||
if (type->iternext != NULL) {
|
||||
return type->iternext(o_in);
|
||||
mp_fun_1_t iternext = mp_type_get_iternext_slot(type);
|
||||
if (iternext != NULL) {
|
||||
return iternext(o_in);
|
||||
} else {
|
||||
// check for __next__ method
|
||||
mp_obj_t dest[2];
|
||||
|
@ -1331,8 +1342,9 @@ mp_vm_return_kind_t mp_resume(mp_obj_t self_in, mp_obj_t send_value, mp_obj_t th
|
|||
return mp_obj_gen_resume(self_in, send_value, throw_value, ret_val);
|
||||
}
|
||||
|
||||
if (type->iternext != NULL && send_value == mp_const_none) {
|
||||
mp_obj_t ret = type->iternext(self_in);
|
||||
mp_fun_1_t iternext = mp_type_get_iternext_slot(type);
|
||||
if (iternext != NULL && send_value == mp_const_none) {
|
||||
mp_obj_t ret = iternext(self_in);
|
||||
*ret_val = ret;
|
||||
if (ret != MP_OBJ_STOP_ITERATION) {
|
||||
return MP_VM_RETURN_YIELD;
|
||||
|
|
|
@ -215,10 +215,13 @@ STATIC MP_DEFINE_CONST_DICT(bleio_address_locals_dict, bleio_address_locals_dict
|
|||
|
||||
const mp_obj_type_t bleio_address_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_Address,
|
||||
.make_new = bleio_address_make_new,
|
||||
.print = bleio_address_print,
|
||||
.unary_op = bleio_address_unary_op,
|
||||
.binary_op = bleio_address_binary_op,
|
||||
.locals_dict = (mp_obj_dict_t *)&bleio_address_locals_dict
|
||||
.locals_dict = (mp_obj_dict_t *)&bleio_address_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = bleio_address_unary_op,
|
||||
.binary_op = bleio_address_binary_op,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -238,10 +238,13 @@ STATIC const mp_stream_p_t characteristic_buffer_stream_p = {
|
|||
|
||||
const mp_obj_type_t bleio_characteristic_buffer_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_CharacteristicBuffer,
|
||||
.make_new = bleio_characteristic_buffer_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &characteristic_buffer_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t *)&bleio_characteristic_buffer_locals_dict
|
||||
.locals_dict = (mp_obj_dict_t *)&bleio_characteristic_buffer_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &characteristic_buffer_stream_p,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -266,7 +266,10 @@ STATIC MP_DEFINE_CONST_DICT(bleio_connection_locals_dict, bleio_connection_local
|
|||
|
||||
const mp_obj_type_t bleio_connection_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_Connection,
|
||||
.locals_dict = (mp_obj_dict_t *)&bleio_connection_locals_dict,
|
||||
.unary_op = mp_generic_unary_op,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = mp_generic_unary_op,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -62,7 +62,10 @@ STATIC mp_obj_t scanresults_iternext(mp_obj_t self_in) {
|
|||
|
||||
const mp_obj_type_t bleio_scanresults_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_ScanResults,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = scanresults_iternext,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = scanresults_iternext,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -300,10 +300,13 @@ void bleio_uuid_print(const mp_print_t *print, mp_obj_t self_in, mp_print_kind_t
|
|||
|
||||
const mp_obj_type_t bleio_uuid_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_UUID,
|
||||
.print = bleio_uuid_print,
|
||||
.make_new = bleio_uuid_make_new,
|
||||
.unary_op = bleio_uuid_unary_op,
|
||||
.binary_op = bleio_uuid_binary_op,
|
||||
.locals_dict = (mp_obj_dict_t *)&bleio_uuid_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = bleio_uuid_unary_op,
|
||||
.binary_op = bleio_uuid_binary_op,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -381,10 +381,12 @@ STATIC MP_DEFINE_CONST_DICT(pixelbuf_pixelbuf_locals_dict, pixelbuf_pixelbuf_loc
|
|||
const mp_obj_type_t pixelbuf_pixelbuf_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_PixelBuf,
|
||||
.subscr = pixelbuf_pixelbuf_subscr,
|
||||
.make_new = pixelbuf_pixelbuf_make_new,
|
||||
.unary_op = pixelbuf_pixelbuf_unary_op,
|
||||
.getiter = mp_obj_new_generic_iterator,
|
||||
.print = NULL,
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.locals_dict = (mp_obj_t)&pixelbuf_pixelbuf_locals_dict,
|
||||
.make_new = pixelbuf_pixelbuf_make_new,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.subscr = pixelbuf_pixelbuf_subscr,
|
||||
.unary_op = pixelbuf_pixelbuf_unary_op,
|
||||
.getiter = mp_obj_new_generic_iterator,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -175,8 +175,10 @@ STATIC mp_obj_t alarm_sleep_memory_subscr(mp_obj_t self_in, mp_obj_t index_in, m
|
|||
const mp_obj_type_t alarm_sleep_memory_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_SleepMemory,
|
||||
.subscr = alarm_sleep_memory_subscr,
|
||||
.unary_op = alarm_sleep_memory_unary_op,
|
||||
.print = NULL,
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.locals_dict = (mp_obj_t)&alarm_sleep_memory_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.subscr = alarm_sleep_memory_subscr,
|
||||
.unary_op = alarm_sleep_memory_unary_op,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -184,7 +184,10 @@ STATIC const audiosample_p_t audioio_rawsample_proto = {
|
|||
const mp_obj_type_t audioio_rawsample_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_RawSample,
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.make_new = audioio_rawsample_make_new,
|
||||
.locals_dict = (mp_obj_dict_t *)&audioio_rawsample_locals_dict,
|
||||
.protocol = &audioio_rawsample_proto,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &audioio_rawsample_proto,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -213,7 +213,10 @@ STATIC const audiosample_p_t audioio_wavefile_proto = {
|
|||
const mp_obj_type_t audioio_wavefile_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_WaveFile,
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.make_new = audioio_wavefile_make_new,
|
||||
.locals_dict = (mp_obj_dict_t *)&audioio_wavefile_locals_dict,
|
||||
.protocol = &audioio_wavefile_proto,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &audioio_wavefile_proto,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -297,7 +297,10 @@ STATIC const audiosample_p_t audiomixer_mixer_proto = {
|
|||
const mp_obj_type_t audiomixer_mixer_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Mixer,
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.make_new = audiomixer_mixer_make_new,
|
||||
.locals_dict = (mp_obj_dict_t *)&audiomixer_mixer_locals_dict,
|
||||
.protocol = &audiomixer_mixer_proto,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &audiomixer_mixer_proto,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -261,7 +261,10 @@ STATIC const audiosample_p_t audiomp3_mp3file_proto = {
|
|||
const mp_obj_type_t audiomp3_mp3file_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_MP3Decoder,
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.make_new = audiomp3_mp3file_make_new,
|
||||
.locals_dict = (mp_obj_dict_t *)&audiomp3_mp3file_locals_dict,
|
||||
.protocol = &audiomp3_mp3file_proto,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &audiomp3_mp3file_proto,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -422,10 +422,13 @@ STATIC const mp_stream_p_t uart_stream_p = {
|
|||
|
||||
const mp_obj_type_t busio_uart_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_UART,
|
||||
.make_new = busio_uart_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &uart_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t *)&busio_uart_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &uart_stream_p,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -172,7 +172,10 @@ STATIC MP_DEFINE_CONST_DICT(canio_listener_locals_dict, canio_listener_locals_di
|
|||
const mp_obj_type_t canio_listener_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Listener,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = canio_iternext,
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.locals_dict = (mp_obj_dict_t *)&canio_listener_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = canio_iternext,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -368,9 +368,12 @@ STATIC mp_int_t bitmap_get_buffer(mp_obj_t self_in, mp_buffer_info_t *bufinfo, m
|
|||
|
||||
const mp_obj_type_t displayio_bitmap_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_Bitmap,
|
||||
.make_new = displayio_bitmap_make_new,
|
||||
.subscr = bitmap_subscr,
|
||||
.locals_dict = (mp_obj_dict_t *)&displayio_bitmap_locals_dict,
|
||||
.buffer_p = { .get_buffer = bitmap_get_buffer },
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.subscr = bitmap_subscr,
|
||||
.buffer_p = { .get_buffer = bitmap_get_buffer },
|
||||
),
|
||||
};
|
||||
|
|
|
@ -357,10 +357,13 @@ STATIC MP_DEFINE_CONST_DICT(displayio_group_locals_dict, displayio_group_locals_
|
|||
|
||||
const mp_obj_type_t displayio_group_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_Group,
|
||||
.make_new = displayio_group_make_new,
|
||||
.subscr = group_subscr,
|
||||
.unary_op = group_unary_op,
|
||||
.getiter = mp_obj_new_generic_iterator,
|
||||
.locals_dict = (mp_obj_dict_t *)&displayio_group_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.subscr = group_subscr,
|
||||
.unary_op = group_unary_op,
|
||||
.getiter = mp_obj_new_generic_iterator,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -204,10 +204,13 @@ STATIC MP_DEFINE_CONST_DICT(displayio_palette_locals_dict, displayio_palette_loc
|
|||
|
||||
const mp_obj_type_t displayio_palette_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_Palette,
|
||||
.make_new = displayio_palette_make_new,
|
||||
.subscr = palette_subscr,
|
||||
.unary_op = group_unary_op,
|
||||
.getiter = mp_obj_new_generic_iterator,
|
||||
.locals_dict = (mp_obj_dict_t *)&displayio_palette_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.subscr = palette_subscr,
|
||||
.unary_op = group_unary_op,
|
||||
.getiter = mp_obj_new_generic_iterator,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -394,8 +394,11 @@ STATIC MP_DEFINE_CONST_DICT(displayio_tilegrid_locals_dict, displayio_tilegrid_l
|
|||
|
||||
const mp_obj_type_t displayio_tilegrid_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_TileGrid,
|
||||
.make_new = displayio_tilegrid_make_new,
|
||||
.subscr = tilegrid_subscr,
|
||||
.locals_dict = (mp_obj_dict_t *)&displayio_tilegrid_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.subscr = tilegrid_subscr,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -58,14 +58,17 @@ const mp_obj_namedtuple_type_t fontio_glyph_type = {
|
|||
.type = &mp_type_type
|
||||
},
|
||||
.name = MP_QSTR_Glyph,
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.print = namedtuple_print,
|
||||
.make_new = namedtuple_make_new,
|
||||
.unary_op = mp_obj_tuple_unary_op,
|
||||
.binary_op = mp_obj_tuple_binary_op,
|
||||
.attr = namedtuple_attr,
|
||||
.subscr = mp_obj_tuple_subscr,
|
||||
.getiter = mp_obj_tuple_getiter,
|
||||
.parent = &mp_type_tuple,
|
||||
.attr = namedtuple_attr,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = mp_obj_tuple_unary_op,
|
||||
.binary_op = mp_obj_tuple_binary_op,
|
||||
.subscr = mp_obj_tuple_subscr,
|
||||
.getiter = mp_obj_tuple_getiter,
|
||||
),
|
||||
},
|
||||
.n_fields = 8,
|
||||
.fields = {
|
||||
|
|
|
@ -190,10 +190,13 @@ STATIC MP_DEFINE_CONST_DICT(ipaddress_ipv4address_locals_dict, ipaddress_ipv4add
|
|||
|
||||
const mp_obj_type_t ipaddress_ipv4address_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_Address,
|
||||
.make_new = ipaddress_ipv4address_make_new,
|
||||
.locals_dict = (mp_obj_dict_t *)&ipaddress_ipv4address_locals_dict,
|
||||
.print = ipaddress_ipv4address_print,
|
||||
.unary_op = ipaddress_ipv4address_unary_op,
|
||||
.binary_op = ipaddress_ipv4address_binary_op,
|
||||
.locals_dict = (mp_obj_dict_t *)&ipaddress_ipv4address_locals_dict
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = ipaddress_ipv4address_unary_op,
|
||||
.binary_op = ipaddress_ipv4address_binary_op,
|
||||
)
|
||||
};
|
||||
|
|
|
@ -171,10 +171,13 @@ STATIC MP_DEFINE_CONST_DICT(keypad_event_locals_dict, keypad_event_locals_dict_t
|
|||
|
||||
const mp_obj_type_t keypad_event_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_Event,
|
||||
.make_new = keypad_event_make_new,
|
||||
.print = keypad_event_print,
|
||||
.unary_op = keypad_event_unary_op,
|
||||
.binary_op = keypad_event_binary_op,
|
||||
.locals_dict = (mp_obj_dict_t *)&keypad_event_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = keypad_event_unary_op,
|
||||
.binary_op = keypad_event_binary_op,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -146,7 +146,10 @@ STATIC MP_DEFINE_CONST_DICT(keypad_eventqueue_locals_dict, keypad_eventqueue_loc
|
|||
|
||||
const mp_obj_type_t keypad_eventqueue_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_Keys,
|
||||
.unary_op = keypad_eventqueue_unary_op,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = keypad_eventqueue_unary_op,
|
||||
),
|
||||
.locals_dict = (mp_obj_t)&keypad_eventqueue_locals_dict,
|
||||
};
|
||||
|
|
|
@ -168,9 +168,11 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_ByteArray,
|
||||
.subscr = nvm_bytearray_subscr,
|
||||
.unary_op = nvm_bytearray_unary_op,
|
||||
.print = NULL,
|
||||
.locals_dict = (mp_obj_t)&nvm_bytearray_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.subscr = nvm_bytearray_subscr,
|
||||
.unary_op = nvm_bytearray_unary_op,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -238,7 +238,10 @@ STATIC MP_DEFINE_CONST_DICT(ps2io_ps2_locals_dict, ps2io_ps2_locals_dict_table);
|
|||
const mp_obj_type_t ps2io_ps2_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_Ps2,
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.make_new = ps2io_ps2_make_new,
|
||||
.unary_op = ps2_unary_op,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = ps2_unary_op,
|
||||
),
|
||||
.locals_dict = (mp_obj_dict_t *)&ps2io_ps2_locals_dict,
|
||||
};
|
||||
|
|
|
@ -309,9 +309,12 @@ STATIC MP_DEFINE_CONST_DICT(pulseio_pulsein_locals_dict, pulseio_pulsein_locals_
|
|||
|
||||
const mp_obj_type_t pulseio_pulsein_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_PulseIn,
|
||||
.make_new = pulseio_pulsein_make_new,
|
||||
.subscr = pulsein_subscr,
|
||||
.unary_op = pulsein_unary_op,
|
||||
.locals_dict = (mp_obj_dict_t *)&pulseio_pulsein_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.subscr = pulsein_subscr,
|
||||
.unary_op = pulsein_unary_op,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -439,9 +439,12 @@ STATIC mp_int_t rgbmatrix_rgbmatrix_get_buffer(mp_obj_t self_in, mp_buffer_info_
|
|||
|
||||
const mp_obj_type_t rgbmatrix_RGBMatrix_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_RGBMatrix,
|
||||
.buffer_p = { .get_buffer = rgbmatrix_rgbmatrix_get_buffer, },
|
||||
.make_new = rgbmatrix_rgbmatrix_make_new,
|
||||
.protocol = &rgbmatrix_rgbmatrix_proto,
|
||||
.locals_dict = (mp_obj_dict_t *)&rgbmatrix_rgbmatrix_locals_dict,
|
||||
.make_new = rgbmatrix_rgbmatrix_make_new,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.buffer_p = { .get_buffer = rgbmatrix_rgbmatrix_get_buffer, },
|
||||
.protocol = &rgbmatrix_rgbmatrix_proto,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -85,8 +85,11 @@ STATIC MP_DEFINE_CONST_DICT(sharpdisplay_framebuffer_locals_dict, sharpdisplay_f
|
|||
const mp_obj_type_t sharpdisplay_framebuffer_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_SharpMemoryFramebuffer,
|
||||
.buffer_p = { .get_buffer = sharpdisplay_framebuffer_get_buffer, },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.make_new = sharpdisplay_framebuffer_make_new,
|
||||
.protocol = &sharpdisplay_framebuffer_proto,
|
||||
.locals_dict = (mp_obj_dict_t *)&sharpdisplay_framebuffer_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.buffer_p = { .get_buffer = sharpdisplay_framebuffer_get_buffer, },
|
||||
.protocol = &sharpdisplay_framebuffer_proto,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -409,7 +409,10 @@ STATIC MP_DEFINE_CONST_DICT(socketpool_socket_locals_dict, socketpool_socket_loc
|
|||
|
||||
const mp_obj_type_t socketpool_socket_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_Socket,
|
||||
.locals_dict = (mp_obj_dict_t *)&socketpool_socket_locals_dict,
|
||||
.unary_op = socketpool_socket_unary_op,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = socketpool_socket_unary_op,
|
||||
)
|
||||
};
|
||||
|
|
|
@ -320,7 +320,10 @@ STATIC MP_DEFINE_CONST_DICT(ssl_sslsocket_locals_dict, ssl_sslsocket_locals_dict
|
|||
|
||||
const mp_obj_type_t ssl_sslsocket_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_SSLSocket,
|
||||
.locals_dict = (mp_obj_dict_t *)&ssl_sslsocket_locals_dict,
|
||||
.unary_op = ssl_sslsocket_unary_op,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = ssl_sslsocket_unary_op,
|
||||
)
|
||||
};
|
||||
|
|
|
@ -163,7 +163,10 @@ STATIC const audiosample_p_t synthio_miditrack_proto = {
|
|||
const mp_obj_type_t synthio_miditrack_type = {
|
||||
{ &mp_type_type },
|
||||
.name = MP_QSTR_MidiTrack,
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.make_new = synthio_miditrack_make_new,
|
||||
.locals_dict = (mp_obj_dict_t *)&synthio_miditrack_locals_dict,
|
||||
.protocol = &synthio_miditrack_proto,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.protocol = &synthio_miditrack_proto,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -118,10 +118,13 @@ STATIC const mp_stream_p_t terminalio_terminal_stream_p = {
|
|||
|
||||
const mp_obj_type_t terminalio_terminal_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_Terminal,
|
||||
.make_new = terminalio_terminal_make_new,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &terminalio_terminal_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t *)&terminalio_terminal_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &terminalio_terminal_stream_p,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -112,15 +112,18 @@ const mp_obj_namedtuple_type_t struct_time_type_obj = {
|
|||
.base = {
|
||||
.type = &mp_type_type
|
||||
},
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_struct_time,
|
||||
.print = namedtuple_print,
|
||||
.make_new = struct_time_make_new,
|
||||
.unary_op = mp_obj_tuple_unary_op,
|
||||
.binary_op = mp_obj_tuple_binary_op,
|
||||
.attr = namedtuple_attr,
|
||||
.subscr = mp_obj_tuple_subscr,
|
||||
.getiter = mp_obj_tuple_getiter,
|
||||
.parent = &mp_type_tuple,
|
||||
.make_new = struct_time_make_new,
|
||||
.attr = namedtuple_attr,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.unary_op = mp_obj_tuple_unary_op,
|
||||
.binary_op = mp_obj_tuple_binary_op,
|
||||
.subscr = mp_obj_tuple_subscr,
|
||||
.getiter = mp_obj_tuple_getiter,
|
||||
),
|
||||
},
|
||||
.n_fields = 9,
|
||||
.fields = {
|
||||
|
@ -163,7 +166,7 @@ void struct_time_to_tm(mp_obj_t t, timeutils_struct_time_t *tm) {
|
|||
mp_obj_t *elems;
|
||||
size_t len;
|
||||
|
||||
if (!mp_obj_is_type(t, &mp_type_tuple) && !mp_obj_is_type(t, MP_OBJ_FROM_PTR(&struct_time_type_obj))) {
|
||||
if (!mp_obj_is_type(t, &mp_type_tuple) && !mp_obj_is_type(t, &struct_time_type_obj.base)) {
|
||||
mp_raise_TypeError(translate("Tuple or struct_time argument required"));
|
||||
}
|
||||
|
||||
|
@ -272,7 +275,7 @@ STATIC mp_obj_t time_mktime(mp_obj_t t) {
|
|||
mp_obj_t *elem;
|
||||
size_t len;
|
||||
|
||||
if (!mp_obj_is_type(t, &mp_type_tuple) && !mp_obj_is_type(t, MP_OBJ_FROM_PTR(&struct_time_type_obj))) {
|
||||
if (!mp_obj_is_type(t, &mp_type_tuple) && !mp_obj_is_type(t, &struct_time_type_obj.base)) {
|
||||
mp_raise_TypeError(translate("Tuple or struct_time argument required"));
|
||||
}
|
||||
|
||||
|
|
|
@ -310,9 +310,12 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_Serial,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &usb_cdc_serial_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t *)&usb_cdc_serial_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &usb_cdc_serial_stream_p,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -113,9 +113,12 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_PortIn,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &usb_midi_portin_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t *)&usb_midi_portin_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &usb_midi_portin_stream_p,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -94,9 +94,12 @@ 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_EXTENDED,
|
||||
.name = MP_QSTR_PortOut,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &usb_midi_portout_stream_p,
|
||||
.locals_dict = (mp_obj_dict_t *)&usb_midi_portout_locals_dict,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = mp_stream_unbuffered_iter,
|
||||
.protocol = &usb_midi_portout_stream_p,
|
||||
),
|
||||
};
|
||||
|
|
|
@ -63,7 +63,10 @@ STATIC mp_obj_t scannednetworks_iternext(mp_obj_t self_in) {
|
|||
|
||||
const mp_obj_type_t wifi_scannednetworks_type = {
|
||||
{ &mp_type_type },
|
||||
.flags = MP_TYPE_FLAG_EXTENDED,
|
||||
.name = MP_QSTR_ScannedNetworks,
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = scannednetworks_iternext,
|
||||
MP_TYPE_EXTENDED_FIELDS(
|
||||
.getiter = mp_identity_getiter,
|
||||
.iternext = scannednetworks_iternext,
|
||||
)
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue