diff --git a/py/obj.h b/py/obj.h index ec343fddae..f80bd43523 100644 --- a/py/obj.h +++ b/py/obj.h @@ -315,6 +315,9 @@ mp_obj_t *mp_obj_get_array_fixed_n(mp_obj_t o, machine_int_t n); uint mp_get_index(const mp_obj_type_t *type, machine_uint_t len, mp_obj_t index, bool is_slice); mp_obj_t mp_obj_len_maybe(mp_obj_t o_in); /* may return NULL */ +// object +extern const mp_obj_type_t mp_type_object; + // none extern const mp_obj_type_t none_type; diff --git a/py/objobject.c b/py/objobject.c new file mode 100644 index 0000000000..274135c6c9 --- /dev/null +++ b/py/objobject.c @@ -0,0 +1,30 @@ +#include + +#include "nlr.h" +#include "misc.h" +#include "mpconfig.h" +#include "qstr.h" +#include "obj.h" +#include "runtime0.h" + +typedef struct _mp_obj_object_t { + mp_obj_base_t base; +} mp_obj_object_t; + +const mp_obj_type_t mp_type_object; + +STATIC mp_obj_t object_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_obj_t *args) { + if (n_args != 0 || n_kw != 0) { + nlr_jump(mp_obj_new_exception_msg(&mp_type_TypeError, "object takes no arguments")); + } + + mp_obj_object_t *o = m_new_obj(mp_obj_object_t); + o->base.type = &mp_type_object; + return o; +} + +const mp_obj_type_t mp_type_object = { + { &mp_type_type }, + .name = MP_QSTR_object, + .make_new = object_make_new, +}; diff --git a/py/py.mk b/py/py.mk index add871632f..624797d823 100644 --- a/py/py.mk +++ b/py/py.mk @@ -58,6 +58,7 @@ PY_O_BASENAME = \ objlist.o \ objmap.o \ objmodule.o \ + objobject.o \ objnone.o \ objnamedtuple.o \ objrange.o \ diff --git a/py/qstrdefs.h b/py/qstrdefs.h index 96d94d937d..b30177acf8 100644 --- a/py/qstrdefs.h +++ b/py/qstrdefs.h @@ -91,6 +91,10 @@ Q(ValueError) Q(Warning) Q(ZeroDivisionError) +Q(None) +Q(False) +Q(True) +Q(object) Q(NoneType) diff --git a/py/runtime.c b/py/runtime.c index 94f3190566..03b662798e 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -104,6 +104,7 @@ STATIC const mp_builtin_elem_t builtin_table[] = { { MP_QSTR_int, (mp_obj_t)&int_type }, { MP_QSTR_list, (mp_obj_t)&list_type }, { MP_QSTR_map, (mp_obj_t)&map_type }, + { MP_QSTR_object, (mp_obj_t)&mp_type_object }, { MP_QSTR_set, (mp_obj_t)&set_type }, { MP_QSTR_str, (mp_obj_t)&str_type }, { MP_QSTR_super, (mp_obj_t)&super_type },