Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
c7687ad7
Commit
c7687ad7
authored
Aug 22, 2014
by
Damien George
Browse files
py: Rename mp_builtin_id to mp_obj_id and make it public.
parent
a2f55fe1
Changes
3
Hide whitespace changes
Inline
Side-by-side
py/builtin.c
View file @
c7687ad7
...
...
@@ -458,25 +458,6 @@ STATIC mp_obj_t mp_builtin_sorted(mp_uint_t n_args, const mp_obj_t *args, mp_map
}
MP_DEFINE_CONST_FUN_OBJ_KW
(
mp_builtin_sorted_obj
,
1
,
mp_builtin_sorted
);
STATIC
mp_obj_t
mp_builtin_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
);
}
}
MP_DEFINE_CONST_FUN_OBJ_1
(
mp_builtin_id_obj
,
mp_builtin_id
);
// See mp_load_attr() if making any changes
STATIC
inline
mp_obj_t
mp_load_attr_default
(
mp_obj_t
base
,
qstr
attr
,
mp_obj_t
defval
)
{
mp_obj_t
dest
[
2
];
...
...
@@ -523,6 +504,7 @@ STATIC mp_obj_t mp_builtin_hasattr(mp_obj_t object_in, mp_obj_t attr_in) {
MP_DEFINE_CONST_FUN_OBJ_2
(
mp_builtin_hasattr_obj
,
mp_builtin_hasattr
);
// These are defined in terms of MicroPython API functions right away
MP_DEFINE_CONST_FUN_OBJ_1
(
mp_builtin_id_obj
,
mp_obj_id
);
MP_DEFINE_CONST_FUN_OBJ_1
(
mp_builtin_len_obj
,
mp_obj_len
);
MP_DEFINE_CONST_FUN_OBJ_0
(
mp_builtin_globals_obj
,
mp_globals_get
);
MP_DEFINE_CONST_FUN_OBJ_0
(
mp_builtin_locals_obj
,
mp_locals_get
);
py/obj.c
View file @
c7687ad7
...
...
@@ -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
);
...
...
py/obj.h
View file @
c7687ad7
...
...
@@ -430,6 +430,7 @@ void mp_obj_get_complex(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
void
mp_obj_get_array
(
mp_obj_t
o
,
mp_uint_t
*
len
,
mp_obj_t
**
items
);
void
mp_obj_get_array_fixed_n
(
mp_obj_t
o
,
mp_uint_t
len
,
mp_obj_t
**
items
);
mp_uint_t
mp_get_index
(
const
mp_obj_type_t
*
type
,
mp_uint_t
len
,
mp_obj_t
index
,
bool
is_slice
);
mp_obj_t
mp_obj_id
(
mp_obj_t
o_in
);
mp_obj_t
mp_obj_len
(
mp_obj_t
o_in
);
mp_obj_t
mp_obj_len_maybe
(
mp_obj_t
o_in
);
/* may return MP_OBJ_NULL */
mp_obj_t
mp_obj_subscr
(
mp_obj_t
base
,
mp_obj_t
index
,
mp_obj_t
val
);
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment