Implement and add tests for the id() builtin function.

This commit is contained in:
xbe 2014-02-01 19:00:41 -08:00
parent 9ed5435061
commit 0ebf8534ab
5 changed files with 11 additions and 0 deletions

View File

@ -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);
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);

View File

@ -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_eval_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_issubclass_obj);
MP_DECLARE_CONST_FUN_OBJ(mp_builtin_iter_obj);

View File

@ -57,6 +57,7 @@ Q(eval)
Q(filter)
Q(float)
Q(hash)
Q(id)
Q(int)
Q(isinstance)
Q(issubclass)

View File

@ -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_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_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_issubclass, (mp_obj_t)&mp_builtin_issubclass_obj);
mp_map_add_qstr(&map_builtins, MP_QSTR_iter, (mp_obj_t)&mp_builtin_iter_obj);

View File

@ -0,0 +1,2 @@
print(id(1) == id(2))
print(id(None) == id(None))