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
4b57fac1
Commit
4b57fac1
authored
Jan 03, 2014
by
Damien George
Browse files
Merge pull request #43 from chipaca/master
Implement list addition.
parents
c2e21bb7
9bc56d93
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/objlist.c
View file @
4b57fac1
...
...
@@ -18,6 +18,7 @@ typedef struct _mp_obj_list_t {
}
mp_obj_list_t
;
static
mp_obj_t
mp_obj_new_list_iterator
(
mp_obj_list_t
*
list
,
int
cur
);
static
mp_obj_list_t
*
list_new
(
uint
n
);
/******************************************************************************/
/* list */
...
...
@@ -43,6 +44,17 @@ static mp_obj_t list_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_ADD
:
{
if
(
!
MP_OBJ_IS_TYPE
(
rhs
,
&
list_type
))
{
return
NULL
;
}
mp_obj_list_t
*
p
=
rhs
;
mp_obj_list_t
*
s
=
list_new
(
o
->
len
+
p
->
len
);
memcpy
(
s
->
items
,
o
->
items
,
sizeof
(
mp_obj_t
)
*
o
->
len
);
memcpy
(
s
->
items
+
o
->
len
,
p
->
items
,
sizeof
(
mp_obj_t
)
*
p
->
len
);
return
s
;
}
default:
// op not supported
return
NULL
;
...
...
tests/basics/tests/list2.py
0 → 100644
View file @
4b57fac1
# list addition
a
=
[
1
,
2
,
3
]
b
=
[
4
,
5
,
6
]
c
=
a
+
b
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