diff options
author | Damien George <damien.p.george@gmail.com> | 2015-02-28 15:04:06 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2015-02-28 15:04:06 +0000 |
commit | 63f3832e813442dcfc88be65d78ce465b053a33b (patch) | |
tree | 1778184b6ce04f808d3d8a068e16cc0848f6b16a /py/emitcpy.c | |
parent | 0b2fd918903509d0a5b368d328a9fa837880ff1c (diff) | |
download | micropython-63f3832e813442dcfc88be65d78ce465b053a33b.tar.gz micropython-63f3832e813442dcfc88be65d78ce465b053a33b.zip |
py: Combine emit functions for jump true/false to reduce code size.
Saves 116 bytes for stmhal and 56 bytes for cc3200 port.
Diffstat (limited to 'py/emitcpy.c')
-rw-r--r-- | py/emitcpy.c | 36 |
1 files changed, 14 insertions, 22 deletions
diff --git a/py/emitcpy.c b/py/emitcpy.c index 355ed10517..be469f45d0 100644 --- a/py/emitcpy.c +++ b/py/emitcpy.c @@ -415,31 +415,25 @@ STATIC void emit_cpy_jump(emit_t *emit, mp_uint_t label) { } } -STATIC void emit_cpy_pop_jump_if_true(emit_t *emit, mp_uint_t label) { +STATIC void emit_cpy_pop_jump_if(emit_t *emit, bool cond, mp_uint_t label) { emit_pre(emit, -1, 3); if (emit->pass == MP_PASS_EMIT) { - printf("POP_JUMP_IF_TRUE " UINT_FMT "\n", emit->label_offsets[label]); - } -} - -STATIC void emit_cpy_pop_jump_if_false(emit_t *emit, mp_uint_t label) { - emit_pre(emit, -1, 3); - if (emit->pass == MP_PASS_EMIT) { - printf("POP_JUMP_IF_FALSE " UINT_FMT "\n", emit->label_offsets[label]); - } -} - -STATIC void emit_cpy_jump_if_true_or_pop(emit_t *emit, mp_uint_t label) { - emit_pre(emit, -1, 3); - if (emit->pass == MP_PASS_EMIT) { - printf("JUMP_IF_TRUE_OR_POP " UINT_FMT "\n", emit->label_offsets[label]); + if (cond) { + printf("POP_JUMP_IF_TRUE " UINT_FMT "\n", emit->label_offsets[label]); + } else { + printf("POP_JUMP_IF_FALSE " UINT_FMT "\n", emit->label_offsets[label]); + } } } -STATIC void emit_cpy_jump_if_false_or_pop(emit_t *emit, mp_uint_t label) { +STATIC void emit_cpy_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label) { emit_pre(emit, -1, 3); if (emit->pass == MP_PASS_EMIT) { - printf("JUMP_IF_FALSE_OR_POP " UINT_FMT "\n", emit->label_offsets[label]); + if (cond) { + printf("JUMP_IF_TRUE_OR_POP " UINT_FMT "\n", emit->label_offsets[label]); + } else { + printf("JUMP_IF_FALSE_OR_POP " UINT_FMT "\n", emit->label_offsets[label]); + } } } @@ -854,10 +848,8 @@ const emit_method_table_t emit_cpython_method_table = { emit_cpy_rot_two, emit_cpy_rot_three, emit_cpy_jump, - emit_cpy_pop_jump_if_true, - emit_cpy_pop_jump_if_false, - emit_cpy_jump_if_true_or_pop, - emit_cpy_jump_if_false_or_pop, + emit_cpy_pop_jump_if, + emit_cpy_jump_if_or_pop, emit_cpy_break_loop, emit_cpy_continue_loop, emit_cpy_setup_with, |