diff --git a/py/builtin.c b/py/builtin.c index 96a9fa328b..2b94163f16 100644 --- a/py/builtin.c +++ b/py/builtin.c @@ -410,3 +410,16 @@ mp_obj_t mp_builtin_sum(int n_args, const mp_obj_t *args) { } return value; } + +static mp_obj_t mp_builtin_type(mp_obj_t o_in) { + // TODO implement the 3 argument version of type() + if (MP_OBJ_IS_SMALL_INT(o_in)) { + // TODO implement int-type + return mp_const_none; + } else { + mp_obj_base_t *o = o_in; + return (mp_obj_t)o->type; + } +} + +MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_type_obj, mp_builtin_type); diff --git a/py/builtin.h b/py/builtin.h index 2d95e3a913..9806624206 100644 --- a/py/builtin.h +++ b/py/builtin.h @@ -31,3 +31,4 @@ mp_obj_t mp_builtin_print(int n_args, const mp_obj_t *args); mp_obj_t mp_builtin_range(int n_args, const mp_obj_t *args); MP_DECLARE_CONST_FUN_OBJ(mp_builtin_set_obj); mp_obj_t mp_builtin_sum(int n_args, const mp_obj_t *args); +MP_DECLARE_CONST_FUN_OBJ(mp_builtin_type_obj); diff --git a/py/objtype.c b/py/objtype.c index 4358148c04..83ae48d2d1 100644 --- a/py/objtype.c +++ b/py/objtype.c @@ -7,12 +7,12 @@ #include "obj.h" void type_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in) { - print(env, "type?"); + print(env, ""); } const mp_obj_type_t mp_const_type = { { &mp_const_type }, - "type?", + "", type_print, // print NULL, // call_n NULL, // unary_op diff --git a/py/runtime.c b/py/runtime.c index 372cdd8656..c3b3d74259 100644 --- a/py/runtime.c +++ b/py/runtime.c @@ -147,6 +147,7 @@ void rt_init(void) { mp_qstr_map_lookup(&map_builtins, qstr_from_str_static("range"), true)->value = rt_make_function_var(1, mp_builtin_range); mp_qstr_map_lookup(&map_builtins, qstr_from_str_static("set"), true)->value = (mp_obj_t)&mp_builtin_set_obj; mp_qstr_map_lookup(&map_builtins, qstr_from_str_static("sum"), true)->value = rt_make_function_var(1, mp_builtin_sum); + mp_qstr_map_lookup(&map_builtins, qstr_from_str_static("type"), true)->value = (mp_obj_t)&mp_builtin_type_obj; next_unique_code_id = 2; // 1 is reserved for the __main__ module scope