diff options
author | Damien George <damien.p.george@gmail.com> | 2014-08-22 21:48:30 +0100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-09-07 20:41:09 +0100 |
commit | c7687ad7e6969bd72751741c5d8a5673d40fa51c (patch) | |
tree | dae91cbe8426b799add8ec2bd8d521d683010f76 /py/obj.c | |
parent | a2f55fe12bac3e33d0c97f834b7f0a0382e969f5 (diff) | |
download | micropython-c7687ad7e6969bd72751741c5d8a5673d40fa51c.tar.gz micropython-c7687ad7e6969bd72751741c5d8a5673d40fa51c.zip |
py: Rename mp_builtin_id to mp_obj_id and make it public.
Diffstat (limited to 'py/obj.c')
-rw-r--r-- | py/obj.c | 18 |
1 files changed, 18 insertions, 0 deletions
@@ -352,6 +352,24 @@ mp_uint_t mp_get_index(const mp_obj_type_t *type, mp_uint_t len, mp_obj_t index, return i; } +mp_obj_t mp_obj_id(mp_obj_t o_in) { + mp_int_t id = (mp_int_t)o_in; + if (!MP_OBJ_IS_OBJ(o_in)) { + return mp_obj_new_int(id); + } else if (id >= 0) { + // Many OSes and CPUs have affinity for putting "user" memories + // into low half of address space, and "system" into upper half. + // We're going to take advantage of that and return small int + // (signed) for such "user" addresses. + return MP_OBJ_NEW_SMALL_INT(id); + } else { + // If that didn't work, well, let's return long int, just as + // a (big) positve value, so it will never clash with the range + // of small int returned in previous case. + return mp_obj_new_int_from_uint((mp_uint_t)id); + } +} + // will raise a TypeError if object has no length mp_obj_t mp_obj_len(mp_obj_t o_in) { mp_obj_t len = mp_obj_len_maybe(o_in); |