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
ee4aaf7c
Commit
ee4aaf7c
authored
Feb 08, 2014
by
Paul Sokolovsky
Browse files
Implement tuple addition.
parent
e827e98a
Changes
4
Hide whitespace changes
Inline
Side-by-side
py/obj.h
View file @
ee4aaf7c
...
...
@@ -398,6 +398,7 @@ typedef struct _mp_obj_static_class_method_t {
// sequence helpers
void
mp_seq_multiply
(
const
void
*
items
,
uint
item_sz
,
uint
len
,
uint
times
,
void
*
dest
);
bool
m_seq_get_fast_slice_indexes
(
machine_uint_t
len
,
mp_obj_t
slice
,
machine_uint_t
*
begin
,
machine_uint_t
*
end
);
#define m_seq_copy(dest, src, len, item_sz) memcpy(dest, src, len * sizeof(item_sz))
#define m_seq_copy(dest, src, len, item_t) memcpy(dest, src, len * sizeof(item_t))
#define m_seq_cat(dest, src1, len1, src2, len2, item_t) { memcpy(dest, src1, len1 * sizeof(item_t)); memcpy(dest + len1, src2, len2 * sizeof(item_t)); }
bool
mp_seq_cmp_bytes
(
int
op
,
const
byte
*
data1
,
uint
len1
,
const
byte
*
data2
,
uint
len2
);
bool
mp_seq_cmp_objs
(
int
op
,
const
mp_obj_t
*
items1
,
uint
len1
,
const
mp_obj_t
*
items2
,
uint
len2
);
py/objlist.c
View file @
ee4aaf7c
...
...
@@ -114,8 +114,7 @@ static mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
}
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
);
m_seq_cat
(
s
->
items
,
o
->
items
,
o
->
len
,
p
->
items
,
p
->
len
,
mp_obj_t
);
return
s
;
}
case
RT_BINARY_OP_INPLACE_ADD
:
...
...
py/objtuple.c
View file @
ee4aaf7c
...
...
@@ -114,6 +114,16 @@ 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_ADD
:
{
if
(
!
MP_OBJ_IS_TYPE
(
rhs
,
&
tuple_type
))
{
return
NULL
;
}
mp_obj_tuple_t
*
p
=
rhs
;
mp_obj_tuple_t
*
s
=
mp_obj_new_tuple
(
o
->
len
+
p
->
len
,
NULL
);
m_seq_cat
(
s
->
items
,
o
->
items
,
o
->
len
,
p
->
items
,
p
->
len
,
mp_obj_t
);
return
s
;
}
case
RT_BINARY_OP_EQUAL
:
case
RT_BINARY_OP_LESS
:
case
RT_BINARY_OP_LESS_EQUAL
:
...
...
tests/basics/tuple1.py
View file @
ee4aaf7c
...
...
@@ -14,3 +14,5 @@ except AttributeError:
print
(
x
[
1
:])
print
(
x
[:
-
1
])
print
(
x
[
2
:
3
])
print
(
x
+
(
10
,
100
,
10000
))
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