Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
13cfabd1
Commit
13cfabd1
authored
Feb 2, 2014
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
Implement slicing for lists.
parent
7364af2d
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
py/obj.h
+1
-0
1 addition, 0 deletions
py/obj.h
py/objlist.c
+9
-1
9 additions, 1 deletion
py/objlist.c
tests/basics/list1.py
+4
-0
4 additions, 0 deletions
tests/basics/list1.py
with
14 additions
and
1 deletion
py/obj.h
+
1
−
0
View file @
13cfabd1
...
@@ -396,3 +396,4 @@ typedef struct _mp_obj_classmethod_t {
...
@@ -396,3 +396,4 @@ typedef struct _mp_obj_classmethod_t {
// sequence helpers
// sequence helpers
void
mp_seq_multiply
(
const
void
*
items
,
uint
item_sz
,
uint
len
,
uint
times
,
void
*
dest
);
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
);
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))
This diff is collapsed.
Click to expand it.
py/objlist.c
+
9
−
1
View file @
13cfabd1
...
@@ -136,7 +136,15 @@ static mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
...
@@ -136,7 +136,15 @@ static mp_obj_t list_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
switch
(
op
)
{
switch
(
op
)
{
case
RT_BINARY_OP_SUBSCR
:
case
RT_BINARY_OP_SUBSCR
:
{
{
// list 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_list_t
*
res
=
list_new
(
stop
-
start
);
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
);
uint
index
=
mp_get_index
(
o
->
base
.
type
,
o
->
len
,
rhs
);
return
o
->
items
[
index
];
return
o
->
items
[
index
];
}
}
...
...
This diff is collapsed.
Click to expand it.
tests/basics/list1.py
+
4
−
0
View file @
13cfabd1
...
@@ -16,3 +16,7 @@ print(x)
...
@@ -16,3 +16,7 @@ print(x)
x
+=
[
2
,
1
]
x
+=
[
2
,
1
]
print
(
x
)
print
(
x
)
print
(
x
[
1
:])
print
(
x
[:
-
1
])
print
(
x
[
2
:
3
])
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment