summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2014-04-02 16:12:28 +0100
committerDamien George <damien.p.george@gmail.com>2014-04-02 16:12:28 +0100
commitaf6edc61bd51b58c2cac4411bd471e7cf4649a3c (patch)
treea15843d37f581e268ebc0485899e229646d79320
parent882b363564b64204c12726d5d2cd7f596322729f (diff)
downloadmicropython-af6edc61bd51b58c2cac4411bd471e7cf4649a3c.tar.gz
micropython-af6edc61bd51b58c2cac4411bd471e7cf4649a3c.zip
py: Enable a jump optimisation in the compiler.
-rw-r--r--py/compile.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/py/compile.c b/py/compile.c
index a27561334a..08125b716b 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -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])) {