Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
micropython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
micropython
Commits
a8312436
Commit
a8312436
authored
Dec 18, 2015
by
Damien George
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
py/compile: Simplify compilation of comprehension iterators.
Saves 88 bytes on Thumb2, and 200 bytes on x86-64 archs.
parent
2eb844e0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
19 deletions
+14
-19
py/compile.c
py/compile.c
+14
-19
No files found.
py/compile.c
View file @
a8312436
...
...
@@ -2660,7 +2660,14 @@ STATIC void compile_scope_func_annotations(compiler_t *comp, mp_parse_node_t pn)
}
#endif // MICROPY_EMIT_NATIVE
STATIC
void
compile_scope_comp_iter
(
compiler_t
*
comp
,
mp_parse_node_t
pn_iter
,
mp_parse_node_t
pn_inner_expr
,
int
l_top
,
int
for_depth
)
{
STATIC
void
compile_scope_comp_iter
(
compiler_t
*
comp
,
mp_parse_node_struct_t
*
pns_comp_for
,
mp_parse_node_t
pn_inner_expr
,
int
for_depth
)
{
uint
l_top
=
comp_next_label
(
comp
);
uint
l_end
=
comp_next_label
(
comp
);
EMIT_ARG
(
label_assign
,
l_top
);
EMIT_ARG
(
for_iter
,
l_end
);
c_assign
(
comp
,
pns_comp_for
->
nodes
[
0
],
ASSIGN_STORE
);
mp_parse_node_t
pn_iter
=
pns_comp_for
->
nodes
[
2
];
tail_recursion:
if
(
MP_PARSE_NODE_IS_NULL
(
pn_iter
))
{
// no more nested if/for; compile inner expression
...
...
@@ -2688,17 +2695,13 @@ STATIC void compile_scope_comp_iter(compiler_t *comp, mp_parse_node_t pn_iter, m
// for loop
mp_parse_node_struct_t
*
pns_comp_for2
=
(
mp_parse_node_struct_t
*
)
pn_iter
;
compile_node
(
comp
,
pns_comp_for2
->
nodes
[
1
]);
uint
l_end2
=
comp_next_label
(
comp
);
uint
l_top2
=
comp_next_label
(
comp
);
EMIT
(
get_iter
);
EMIT_ARG
(
label_assign
,
l_top2
);
EMIT_ARG
(
for_iter
,
l_end2
);
c_assign
(
comp
,
pns_comp_for2
->
nodes
[
0
],
ASSIGN_STORE
);
compile_scope_comp_iter
(
comp
,
pns_comp_for2
->
nodes
[
2
],
pn_inner_expr
,
l_top2
,
for_depth
+
1
);
EMIT_ARG
(
jump
,
l_top2
);
EMIT_ARG
(
label_assign
,
l_end2
);
EMIT
(
for_iter_end
);
compile_scope_comp_iter
(
comp
,
pns_comp_for2
,
pn_inner_expr
,
for_depth
+
1
);
}
EMIT_ARG
(
jump
,
l_top
);
EMIT_ARG
(
label_assign
,
l_end
);
EMIT
(
for_iter_end
);
}
STATIC
void
check_for_doc_string
(
compiler_t
*
comp
,
mp_parse_node_t
pn
)
{
...
...
@@ -2862,16 +2865,8 @@ STATIC void compile_scope(compiler_t *comp, scope_t *scope, pass_kind_t pass) {
#endif
}
uint
l_end
=
comp_next_label
(
comp
);
uint
l_top
=
comp_next_label
(
comp
);
compile_load_id
(
comp
,
qstr_arg
);
EMIT_ARG
(
label_assign
,
l_top
);
EMIT_ARG
(
for_iter
,
l_end
);
c_assign
(
comp
,
pns_comp_for
->
nodes
[
0
],
ASSIGN_STORE
);
compile_scope_comp_iter
(
comp
,
pns_comp_for
->
nodes
[
2
],
pns
->
nodes
[
0
],
l_top
,
0
);
EMIT_ARG
(
jump
,
l_top
);
EMIT_ARG
(
label_assign
,
l_end
);
EMIT
(
for_iter_end
);
compile_scope_comp_iter
(
comp
,
pns_comp_for
,
pns
->
nodes
[
0
],
0
);
if
(
scope
->
kind
==
SCOPE_GEN_EXPR
)
{
EMIT_ARG
(
load_const_tok
,
MP_TOKEN_KW_NONE
);
...
...
Write
Preview
Markdown
is supported
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