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
e827e98a
Commit
e827e98a
authored
Feb 08, 2014
by
Paul Sokolovsky
Browse files
Implement tuple comparison.
parent
1a996c48
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/objtuple.c
View file @
e827e98a
...
...
@@ -74,6 +74,18 @@ static mp_obj_t tuple_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m
}
}
// Don't pass RT_BINARY_OP_NOT_EQUAL here
static
bool
tuple_cmp_helper
(
int
op
,
mp_obj_t
self_in
,
mp_obj_t
another_in
)
{
assert
(
MP_OBJ_IS_TYPE
(
self_in
,
&
tuple_type
));
if
(
!
MP_OBJ_IS_TYPE
(
another_in
,
&
tuple_type
))
{
return
false
;
}
mp_obj_tuple_t
*
self
=
self_in
;
mp_obj_tuple_t
*
another
=
another_in
;
return
mp_seq_cmp_objs
(
op
,
self
->
items
,
self
->
len
,
another
->
items
,
another
->
len
);
}
static
mp_obj_t
tuple_unary_op
(
int
op
,
mp_obj_t
self_in
)
{
mp_obj_tuple_t
*
self
=
self_in
;
switch
(
op
)
{
...
...
@@ -102,6 +114,15 @@ static mp_obj_t tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
uint
index
=
mp_get_index
(
o
->
base
.
type
,
o
->
len
,
rhs
);
return
o
->
items
[
index
];
}
case
RT_BINARY_OP_EQUAL
:
case
RT_BINARY_OP_LESS
:
case
RT_BINARY_OP_LESS_EQUAL
:
case
RT_BINARY_OP_MORE
:
case
RT_BINARY_OP_MORE_EQUAL
:
return
MP_BOOL
(
tuple_cmp_helper
(
op
,
lhs
,
rhs
));
case
RT_BINARY_OP_NOT_EQUAL
:
return
MP_BOOL
(
!
tuple_cmp_helper
(
RT_BINARY_OP_EQUAL
,
lhs
,
rhs
));
default:
// op not supported
return
NULL
;
...
...
tests/basics/tuple_compare.py
0 → 100644
View file @
e827e98a
print
(()
==
())
print
(()
>
())
print
(()
<
())
print
(()
==
(
1
,))
print
((
1
,)
==
())
print
(()
>
(
1
,))
print
((
1
,)
>
())
print
(()
<
(
1
,))
print
((
1
,)
<
())
print
(()
>=
(
1
,))
print
((
1
,)
>=
())
print
(()
<=
(
1
,))
print
((
1
,)
<=
())
print
((
1
,)
==
(
1
,))
print
((
1
,)
!=
(
1
,))
print
((
1
,)
==
(
2
,))
print
((
1
,)
==
(
1
,
0
,))
print
((
1
,)
>
(
1
,))
print
((
1
,)
>
(
2
,))
print
((
2
,)
>
(
1
,))
print
((
1
,
0
,)
>
(
1
,))
print
((
1
,
-
1
,)
>
(
1
,))
print
((
1
,)
>
(
1
,
0
,))
print
((
1
,)
>
(
1
,
-
1
,))
print
((
1
,)
<
(
1
,))
print
((
2
,)
<
(
1
,))
print
((
1
,)
<
(
2
,))
print
((
1
,)
<
(
1
,
0
,))
print
((
1
,)
<
(
1
,
-
1
,))
print
((
1
,
0
,)
<
(
1
,))
print
((
1
,
-
1
,)
<
(
1
,))
print
((
1
,)
>=
(
1
,))
print
((
1
,)
>=
(
2
,))
print
((
2
,)
>=
(
1
,))
print
((
1
,
0
,)
>=
(
1
,))
print
((
1
,
-
1
,)
>=
(
1
,))
print
((
1
,)
>=
(
1
,
0
,))
print
((
1
,)
>=
(
1
,
-
1
,))
print
((
1
,)
<=
(
1
,))
print
((
2
,)
<=
(
1
,))
print
((
1
,)
<=
(
2
,))
print
((
1
,)
<=
(
1
,
0
,))
print
((
1
,)
<=
(
1
,
-
1
,))
print
((
1
,
0
,)
<=
(
1
,))
print
((
1
,
-
1
,)
<=
(
1
,))
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