Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
46c9e971
Commit
46c9e971
authored
Jan 10, 2014
by
Damien George
Browse files
Merge pull request #134 from pfalcon/list-mul
list: Implement list multiplication.
parents
745ce4c2
074d3b5f
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/objlist.c
View file @
46c9e971
...
...
@@ -81,6 +81,21 @@ static mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
memcpy
(
s
->
items
+
o
->
len
,
p
->
items
,
sizeof
(
mp_obj_t
)
*
p
->
len
);
return
s
;
}
case
RT_BINARY_OP_MULTIPLY
:
{
if
(
!
MP_OBJ_IS_SMALL_INT
(
rhs
))
{
return
NULL
;
}
int
n
=
MP_OBJ_SMALL_INT_VALUE
(
rhs
);
int
len
=
o
->
len
;
mp_obj_list_t
*
s
=
list_new
(
len
*
n
);
mp_obj_t
*
dest
=
s
->
items
;
for
(
int
i
=
0
;
i
<
n
;
i
++
)
{
memcpy
(
dest
,
o
->
items
,
sizeof
(
mp_obj_t
)
*
len
);
dest
+=
len
;
}
return
s
;
}
default:
// op not supported
return
NULL
;
...
...
tests/basics/tests/list_mult.py
0 → 100644
View file @
46c9e971
print
([
0
]
*
5
)
a
=
[
1
,
2
,
3
]
c
=
a
*
3
print
(
c
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a 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