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
9ed54350
Commit
9ed54350
authored
Feb 02, 2014
by
Paul Sokolovsky
Browse files
Implement slicing for tuples.
parent
13cfabd1
Changes
2
Hide whitespace changes
Inline
Side-by-side
py/objtuple.c
View file @
9ed54350
#include
<string.h>
#include
<stdlib.h>
#include
<stdint.h>
#include
<assert.h>
...
...
@@ -87,7 +88,15 @@ static mp_obj_t tuple_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
switch
(
op
)
{
case
RT_BINARY_OP_SUBSCR
:
{
// tuple load
#if MICROPY_ENABLE_SLICE
if
(
MP_OBJ_IS_TYPE
(
rhs
,
&
slice_type
))
{
machine_uint_t
start
,
stop
;
assert
(
m_seq_get_fast_slice_indexes
(
o
->
len
,
rhs
,
&
start
,
&
stop
));
mp_obj_tuple_t
*
res
=
mp_obj_new_tuple
(
stop
-
start
,
NULL
);
m_seq_copy
(
res
->
items
,
o
->
items
+
start
,
res
->
len
,
mp_obj_t
);
return
res
;
}
#endif
uint
index
=
mp_get_index
(
o
->
base
.
type
,
o
->
len
,
rhs
);
return
o
->
items
[
index
];
}
...
...
tests/basics/tuple1.py
0 → 100644
View file @
9ed54350
# basic tuple functionality
x
=
(
1
,
2
,
3
*
4
)
print
(
x
)
try
:
x
[
0
]
=
4
except
TypeError
:
print
(
"TypeError"
)
print
(
x
)
try
:
x
.
append
(
5
)
except
AttributeError
:
print
(
"AttributeError"
)
print
(
x
[
1
:])
print
(
x
[:
-
1
])
print
(
x
[
2
:
3
])
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