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/emitbc.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/emitbc.c')
-rw-r--r-- | py/emitbc.c | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/py/emitbc.c b/py/emitbc.c index 53cae59ee2..60da170fce 100644 --- a/py/emitbc.c +++ b/py/emitbc.c @@ -652,24 +652,22 @@ STATIC void emit_bc_jump(emit_t *emit, mp_uint_t label) { emit_write_bytecode_byte_signed_label(emit, MP_BC_JUMP, label); } -STATIC void emit_bc_pop_jump_if_true(emit_t *emit, mp_uint_t label) { +STATIC void emit_bc_pop_jump_if(emit_t *emit, bool cond, mp_uint_t label) { emit_bc_pre(emit, -1); - emit_write_bytecode_byte_signed_label(emit, MP_BC_POP_JUMP_IF_TRUE, label); -} - -STATIC void emit_bc_pop_jump_if_false(emit_t *emit, mp_uint_t label) { - emit_bc_pre(emit, -1); - emit_write_bytecode_byte_signed_label(emit, MP_BC_POP_JUMP_IF_FALSE, label); -} - -STATIC void emit_bc_jump_if_true_or_pop(emit_t *emit, mp_uint_t label) { - emit_bc_pre(emit, -1); - emit_write_bytecode_byte_signed_label(emit, MP_BC_JUMP_IF_TRUE_OR_POP, label); + if (cond) { + emit_write_bytecode_byte_signed_label(emit, MP_BC_POP_JUMP_IF_TRUE, label); + } else { + emit_write_bytecode_byte_signed_label(emit, MP_BC_POP_JUMP_IF_FALSE, label); + } } -STATIC void emit_bc_jump_if_false_or_pop(emit_t *emit, mp_uint_t label) { +STATIC void emit_bc_jump_if_or_pop(emit_t *emit, bool cond, mp_uint_t label) { emit_bc_pre(emit, -1); - emit_write_bytecode_byte_signed_label(emit, MP_BC_JUMP_IF_FALSE_OR_POP, label); + if (cond) { + emit_write_bytecode_byte_signed_label(emit, MP_BC_JUMP_IF_TRUE_OR_POP, label); + } else { + emit_write_bytecode_byte_signed_label(emit, MP_BC_JUMP_IF_FALSE_OR_POP, label); + } } STATIC void emit_bc_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_depth) { @@ -951,10 +949,8 @@ const emit_method_table_t emit_bc_method_table = { emit_bc_rot_two, emit_bc_rot_three, emit_bc_jump, - emit_bc_pop_jump_if_true, - emit_bc_pop_jump_if_false, - emit_bc_jump_if_true_or_pop, - emit_bc_jump_if_false_or_pop, + emit_bc_pop_jump_if, + emit_bc_jump_if_or_pop, emit_bc_unwind_jump, emit_bc_unwind_jump, emit_bc_setup_with, |