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
edbdf71f
Commit
edbdf71f
authored
Feb 1, 2014
by
Paul Sokolovsky
Browse files
Options
Downloads
Patches
Plain Diff
rt_unpack_sequence(): Support generic iterables.
parent
48697f1d
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
py/runtime.c
+21
-5
21 additions, 5 deletions
py/runtime.c
with
21 additions
and
5 deletions
py/runtime.c
+
21
−
5
View file @
edbdf71f
...
@@ -769,8 +769,8 @@ mp_obj_t rt_store_set(mp_obj_t set, mp_obj_t item) {
...
@@ -769,8 +769,8 @@ mp_obj_t rt_store_set(mp_obj_t set, mp_obj_t item) {
// unpacked items are stored in reverse order into the array pointed to by items
// unpacked items are stored in reverse order into the array pointed to by items
void
rt_unpack_sequence
(
mp_obj_t
seq_in
,
uint
num
,
mp_obj_t
*
items
)
{
void
rt_unpack_sequence
(
mp_obj_t
seq_in
,
uint
num
,
mp_obj_t
*
items
)
{
if
(
MP_OBJ_IS_TYPE
(
seq_in
,
&
tuple_type
)
||
MP_OBJ_IS_TYPE
(
seq_in
,
&
list_type
))
{
uint
seq_len
;
uint
seq_len
;
if
(
MP_OBJ_IS_TYPE
(
seq_in
,
&
tuple_type
)
||
MP_OBJ_IS_TYPE
(
seq_in
,
&
list_type
))
{
mp_obj_t
*
seq_items
;
mp_obj_t
*
seq_items
;
if
(
MP_OBJ_IS_TYPE
(
seq_in
,
&
tuple_type
))
{
if
(
MP_OBJ_IS_TYPE
(
seq_in
,
&
tuple_type
))
{
mp_obj_tuple_get
(
seq_in
,
&
seq_len
,
&
seq_items
);
mp_obj_tuple_get
(
seq_in
,
&
seq_len
,
&
seq_items
);
...
@@ -778,17 +778,33 @@ void rt_unpack_sequence(mp_obj_t seq_in, uint num, mp_obj_t *items) {
...
@@ -778,17 +778,33 @@ void rt_unpack_sequence(mp_obj_t seq_in, uint num, mp_obj_t *items) {
mp_obj_list_get
(
seq_in
,
&
seq_len
,
&
seq_items
);
mp_obj_list_get
(
seq_in
,
&
seq_len
,
&
seq_items
);
}
}
if
(
seq_len
<
num
)
{
if
(
seq_len
<
num
)
{
nlr_jump
(
mp_obj_new_exception_msg_varg
(
MP_QSTR_ValueError
,
"need more than %d values to unpack"
,
(
void
*
)(
machine_uint_t
)
seq_len
))
;
goto
too_short
;
}
else
if
(
seq_len
>
num
)
{
}
else
if
(
seq_len
>
num
)
{
nlr_jump
(
mp_obj_new_exception_msg_varg
(
MP_QSTR_ValueError
,
"too many values to unpack (expected %d)"
,
(
void
*
)(
machine_uint_t
)
num
))
;
goto
too_long
;
}
}
for
(
uint
i
=
0
;
i
<
num
;
i
++
)
{
for
(
uint
i
=
0
;
i
<
num
;
i
++
)
{
items
[
i
]
=
seq_items
[
num
-
1
-
i
];
items
[
i
]
=
seq_items
[
num
-
1
-
i
];
}
}
}
else
{
}
else
{
// TODO call rt_getiter and extract via rt_iternext
mp_obj_t
iterable
=
rt_getiter
(
seq_in
);
nlr_jump
(
mp_obj_new_exception_msg_varg
(
MP_QSTR_TypeError
,
"'%s' object is not iterable"
,
mp_obj_get_type_str
(
seq_in
)));
for
(
seq_len
=
0
;
seq_len
<
num
;
seq_len
++
)
{
mp_obj_t
el
=
rt_iternext
(
iterable
);
if
(
el
==
mp_const_stop_iteration
)
{
goto
too_short
;
}
items
[
num
-
1
-
seq_len
]
=
el
;
}
}
if
(
rt_iternext
(
iterable
)
!=
mp_const_stop_iteration
)
{
goto
too_long
;
}
}
return
;
too_short:
nlr_jump
(
mp_obj_new_exception_msg_varg
(
MP_QSTR_ValueError
,
"need more than %d values to unpack"
,
seq_len
));
too_long:
nlr_jump
(
mp_obj_new_exception_msg_varg
(
MP_QSTR_ValueError
,
"too many values to unpack (expected %d)"
,
num
));
}
}
mp_obj_t
rt_build_map
(
int
n_args
)
{
mp_obj_t
rt_build_map
(
int
n_args
)
{
...
...
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