py: Add 'object' object.
This commit is contained in:
parent
eabdf6718a
commit
3ec0a1a32d
3
py/obj.h
3
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;
|
||||
|
||||
|
30
py/objobject.c
Normal file
30
py/objobject.c
Normal file
@ -0,0 +1,30 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#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,
|
||||
};
|
1
py/py.mk
1
py/py.mk
@ -58,6 +58,7 @@ PY_O_BASENAME = \
|
||||
objlist.o \
|
||||
objmap.o \
|
||||
objmodule.o \
|
||||
objobject.o \
|
||||
objnone.o \
|
||||
objnamedtuple.o \
|
||||
objrange.o \
|
||||
|
@ -91,6 +91,10 @@ Q(ValueError)
|
||||
Q(Warning)
|
||||
Q(ZeroDivisionError)
|
||||
|
||||
Q(None)
|
||||
Q(False)
|
||||
Q(True)
|
||||
Q(object)
|
||||
|
||||
Q(NoneType)
|
||||
|
||||
|
@ -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 },
|
||||
|
Loading…
Reference in New Issue
Block a user