Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
TASTE
uPython-mirror
Commits
af6edc61
Commit
af6edc61
authored
Apr 02, 2014
by
Damien George
Browse files
py: Enable a jump optimisation in the compiler.
parent
882b3635
Changes
1
Hide whitespace changes
Inline
Side-by-side
py/compile.c
View file @
af6edc61
...
...
@@ -1434,12 +1434,19 @@ void compile_if_stmt(compiler_t *comp, mp_parse_node_struct_t *pns) {
c_if_cond
(
comp
,
pns
->
nodes
[
0
],
false
,
l_fail
);
// if condition
compile_node
(
comp
,
pns
->
nodes
[
1
]);
// if block
//if (!(MP_PARSE_NODE_IS_NULL(pns->nodes[2]) && MP_PARSE_NODE_IS_NULL(pns->nodes[3]))) { // optimisation; doesn't align with CPython
// jump over elif/else blocks if they exist
if
(
!
EMIT
(
last_emit_was_return_value
))
{
// simple optimisation to align with CPython
EMIT_ARG
(
jump
,
l_end
);
}
//}
if
(
#if !MICROPY_EMIT_CPYTHON
// optimisation to not jump over non-existent elif/else blocks (this optimisation is not in CPython)
!
(
MP_PARSE_NODE_IS_NULL
(
pns
->
nodes
[
2
])
&&
MP_PARSE_NODE_IS_NULL
(
pns
->
nodes
[
3
]))
&&
#endif
// optimisation to not jump if last instruction was return
!
EMIT
(
last_emit_was_return_value
)
)
{
// jump over elif/else blocks
EMIT_ARG
(
jump
,
l_end
);
}
EMIT_ARG
(
label_assign
,
l_fail
);
if
(
!
MP_PARSE_NODE_IS_NULL
(
pns
->
nodes
[
2
]))
{
...
...
Write
Preview
Supports
Markdown
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