summaryrefslogtreecommitdiffstatshomepage
path: root/py/compile.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-02-28 14:37:54 +0000
committerDamien George <damien.p.george@gmail.com>2015-02-28 14:37:54 +0000
commit0b2fd918903509d0a5b368d328a9fa837880ff1c (patch)
treed94c7f88a9c1d47bc7c029ebb3f34aa47b4f77a3 /py/compile.c
parent562fa575a67a6f2e84fdeb5303c1ac42934015ce (diff)
downloadmicropython-0b2fd918903509d0a5b368d328a9fa837880ff1c.tar.gz
micropython-0b2fd918903509d0a5b368d328a9fa837880ff1c.zip
py: Combine logic for compiling and/or tests, to reduce code size.
Reduces code size by 72 bytes on Thumb2 archs.
Diffstat (limited to 'py/compile.c')
-rw-r--r--py/compile.c20
1 files changed, 7 insertions, 13 deletions
diff --git a/py/compile.c b/py/compile.c
index c3502521ba..7b46a4c42b 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -666,32 +666,26 @@ STATIC void c_if_cond(compiler_t *comp, mp_parse_node_t pn, bool jump_if, int la
int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_or_test) {
if (jump_if == false) {
+ and_or_logic1:;
uint label2 = comp_next_label(comp);
for (int i = 0; i < n - 1; i++) {
- c_if_cond(comp, pns->nodes[i], true, label2);
+ c_if_cond(comp, pns->nodes[i], !jump_if, label2);
}
- c_if_cond(comp, pns->nodes[n - 1], false, label);
+ c_if_cond(comp, pns->nodes[n - 1], jump_if, label);
EMIT_ARG(label_assign, label2);
} else {
+ and_or_logic2:
for (int i = 0; i < n; i++) {
- c_if_cond(comp, pns->nodes[i], true, label);
+ c_if_cond(comp, pns->nodes[i], jump_if, label);
}
}
return;
} else if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_and_test) {
if (jump_if == false) {
- for (int i = 0; i < n; i++) {
- c_if_cond(comp, pns->nodes[i], false, label);
- }
+ goto and_or_logic2;
} else {
- uint label2 = comp_next_label(comp);
- for (int i = 0; i < n - 1; i++) {
- c_if_cond(comp, pns->nodes[i], false, label2);
- }
- c_if_cond(comp, pns->nodes[n - 1], true, label);
- EMIT_ARG(label_assign, label2);
+ goto and_or_logic1;
}
- return;
} else if (MP_PARSE_NODE_STRUCT_KIND(pns) == PN_not_test_2) {
c_if_cond(comp, pns->nodes[0], !jump_if, label);
return;