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
f7c2410e
Commit
f7c2410e
authored
Feb 08, 2014
by
Paul Sokolovsky
Browse files
Implement tuple multiplication.
parent
ee4aaf7c
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/objtuple.c
View file @
f7c2410e
...
...
@@ -124,6 +124,16 @@ static mp_obj_t tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
m_seq_cat
(
s
->
items
,
o
->
items
,
o
->
len
,
p
->
items
,
p
->
len
,
mp_obj_t
);
return
s
;
}
case
RT_BINARY_OP_MULTIPLY
:
{
if
(
!
MP_OBJ_IS_SMALL_INT
(
rhs
))
{
return
NULL
;
}
int
n
=
MP_OBJ_SMALL_INT_VALUE
(
rhs
);
mp_obj_tuple_t
*
s
=
mp_obj_new_tuple
(
o
->
len
*
n
,
NULL
);
mp_seq_multiply
(
o
->
items
,
sizeof
(
*
o
->
items
),
o
->
len
,
n
,
s
->
items
);
return
s
;
}
case
RT_BINARY_OP_EQUAL
:
case
RT_BINARY_OP_LESS
:
case
RT_BINARY_OP_LESS_EQUAL
:
...
...
tests/basics/tuple_mult.py
0 → 100644
View file @
f7c2410e
print
((
0
,)
*
5
)
a
=
(
1
,
2
,
3
)
c
=
a
*
3
print
(
c
)
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