Implement and add tests for the id() builtin function.
This commit is contained in:
parent
9ed5435061
commit
0ebf8534ab
@ -364,3 +364,9 @@ static mp_obj_t mp_builtin_bytes(uint n_args, const mp_obj_t *args) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_bytes_obj, 1, 3, mp_builtin_bytes);
|
MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_builtin_bytes_obj, 1, 3, mp_builtin_bytes);
|
||||||
|
|
||||||
|
static mp_obj_t mp_builtin_id(mp_obj_t o_in) {
|
||||||
|
return mp_obj_new_int_from_uint((machine_uint_t)o_in);
|
||||||
|
}
|
||||||
|
|
||||||
|
MP_DEFINE_CONST_FUN_OBJ_1(mp_builtin_id_obj, mp_builtin_id);
|
||||||
|
@ -11,6 +11,7 @@ MP_DECLARE_CONST_FUN_OBJ(mp_builtin_chr_obj);
|
|||||||
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_divmod_obj);
|
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_divmod_obj);
|
||||||
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_eval_obj);
|
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_eval_obj);
|
||||||
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_hash_obj);
|
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_hash_obj);
|
||||||
|
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_id_obj);
|
||||||
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_isinstance_obj);
|
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_isinstance_obj);
|
||||||
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_issubclass_obj);
|
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_issubclass_obj);
|
||||||
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_iter_obj);
|
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_iter_obj);
|
||||||
|
@ -57,6 +57,7 @@ Q(eval)
|
|||||||
Q(filter)
|
Q(filter)
|
||||||
Q(float)
|
Q(float)
|
||||||
Q(hash)
|
Q(hash)
|
||||||
|
Q(id)
|
||||||
Q(int)
|
Q(int)
|
||||||
Q(isinstance)
|
Q(isinstance)
|
||||||
Q(issubclass)
|
Q(issubclass)
|
||||||
|
@ -144,6 +144,7 @@ void rt_init(void) {
|
|||||||
mp_map_add_qstr(&map_builtins, MP_QSTR_divmod, (mp_obj_t)&mp_builtin_divmod_obj);
|
mp_map_add_qstr(&map_builtins, MP_QSTR_divmod, (mp_obj_t)&mp_builtin_divmod_obj);
|
||||||
mp_map_add_qstr(&map_builtins, MP_QSTR_eval, (mp_obj_t)&mp_builtin_eval_obj);
|
mp_map_add_qstr(&map_builtins, MP_QSTR_eval, (mp_obj_t)&mp_builtin_eval_obj);
|
||||||
mp_map_add_qstr(&map_builtins, MP_QSTR_hash, (mp_obj_t)&mp_builtin_hash_obj);
|
mp_map_add_qstr(&map_builtins, MP_QSTR_hash, (mp_obj_t)&mp_builtin_hash_obj);
|
||||||
|
mp_map_add_qstr(&map_builtins, MP_QSTR_id, (mp_obj_t)&mp_builtin_id_obj);
|
||||||
mp_map_add_qstr(&map_builtins, MP_QSTR_isinstance, (mp_obj_t)&mp_builtin_isinstance_obj);
|
mp_map_add_qstr(&map_builtins, MP_QSTR_isinstance, (mp_obj_t)&mp_builtin_isinstance_obj);
|
||||||
mp_map_add_qstr(&map_builtins, MP_QSTR_issubclass, (mp_obj_t)&mp_builtin_issubclass_obj);
|
mp_map_add_qstr(&map_builtins, MP_QSTR_issubclass, (mp_obj_t)&mp_builtin_issubclass_obj);
|
||||||
mp_map_add_qstr(&map_builtins, MP_QSTR_iter, (mp_obj_t)&mp_builtin_iter_obj);
|
mp_map_add_qstr(&map_builtins, MP_QSTR_iter, (mp_obj_t)&mp_builtin_iter_obj);
|
||||||
|
2
tests/basics/builtin_id.py
Normal file
2
tests/basics/builtin_id.py
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
print(id(1) == id(2))
|
||||||
|
print(id(None) == id(None))
|
Loading…
Reference in New Issue
Block a user