summaryrefslogtreecommitdiffstatshomepage
path: root/py/compile.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2015-02-28 15:10:18 +0000
committerDamien George <damien.p.george@gmail.com>2015-02-28 15:10:18 +0000
commit7711afbb4a0bb4f250ec550591cbfa685af6ff9c (patch)
tree1d91e99f9d46682b674f25fd918ba3fd0d91b705 /py/compile.c
parent63f3832e813442dcfc88be65d78ce465b053a33b (diff)
downloadmicropython-7711afbb4a0bb4f250ec550591cbfa685af6ff9c.tar.gz
micropython-7711afbb4a0bb4f250ec550591cbfa685af6ff9c.zip
py: Combine complie functions for or_test/and_test to reduce code size.
Saves around 60 bytes code on Thumb2 archs.
Diffstat (limited to 'py/compile.c')
-rw-r--r--py/compile.c18
1 files changed, 7 insertions, 11 deletions
diff --git a/py/compile.c b/py/compile.c
index 7245ff0a34..41e2610c04 100644
--- a/py/compile.c
+++ b/py/compile.c
@@ -2253,28 +2253,24 @@ STATIC void compile_lambdef(compiler_t *comp, mp_parse_node_struct_t *pns) {
close_over_variables_etc(comp, this_scope, 0, 0);
}
-STATIC void compile_or_test(compiler_t *comp, mp_parse_node_struct_t *pns) {
+STATIC void compile_or_and_test(compiler_t *comp, mp_parse_node_struct_t *pns, bool cond) {
uint l_end = comp_next_label(comp);
int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
for (int i = 0; i < n; i += 1) {
compile_node(comp, pns->nodes[i]);
if (i + 1 < n) {
- EMIT_ARG(jump_if_or_pop, true, l_end);
+ EMIT_ARG(jump_if_or_pop, cond, l_end);
}
}
EMIT_ARG(label_assign, l_end);
}
+STATIC void compile_or_test(compiler_t *comp, mp_parse_node_struct_t *pns) {
+ compile_or_and_test(comp, pns, true);
+}
+
STATIC void compile_and_test(compiler_t *comp, mp_parse_node_struct_t *pns) {
- uint l_end = comp_next_label(comp);
- int n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns);
- for (int i = 0; i < n; i += 1) {
- compile_node(comp, pns->nodes[i]);
- if (i + 1 < n) {
- EMIT_ARG(jump_if_or_pop, false, l_end);
- }
- }
- EMIT_ARG(label_assign, l_end);
+ compile_or_and_test(comp, pns, false);
}
STATIC void compile_not_test_2(compiler_t *comp, mp_parse_node_struct_t *pns) {