aboutsummaryrefslogtreecommitdiff
path: root/py/emitbc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-05-22 22:33:26 +1000
committerDamien George <damien.p.george@gmail.com>2018-05-23 00:35:16 +1000
commit18e6358480e640fd94a9383d5fa7d9b8cc2b9f73 (patch)
tree8fa4f37c9d5d072f8486b674b5038922d1cb25c0 /py/emitbc.c
parent436e0d4c54ab22050072d392f0822e555bcc70f1 (diff)
py/emit: Combine setup with/except/finally into one emit function.
This patch reduces code size by: bare-arm: -16 minimal x86: -156 unix x64: -288 unix nanbox: -184 stm32: -48 cc3200: -16 esp8266: -96 esp32: -16 The last 10 patches combined reduce code size by: bare-arm: -164 minimal x86: -1260 unix x64: -3416 unix nanbox: -1616 stm32: -676 cc3200: -232 esp8266: -1144 esp32: -268
Diffstat (limited to 'py/emitbc.c')
-rw-r--r--py/emitbc.c29
1 files changed, 12 insertions, 17 deletions
diff --git a/py/emitbc.c b/py/emitbc.c
index 4c587c72e..f3951e9cb 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -719,11 +719,18 @@ void mp_emit_bc_unwind_jump(emit_t *emit, mp_uint_t label, mp_uint_t except_dept
}
}
-void mp_emit_bc_setup_with(emit_t *emit, mp_uint_t label) {
+void mp_emit_bc_setup_block(emit_t *emit, mp_uint_t label, int kind) {
+ MP_STATIC_ASSERT(MP_BC_SETUP_WITH + MP_EMIT_SETUP_BLOCK_WITH == MP_BC_SETUP_WITH);
+ MP_STATIC_ASSERT(MP_BC_SETUP_WITH + MP_EMIT_SETUP_BLOCK_EXCEPT == MP_BC_SETUP_EXCEPT);
+ MP_STATIC_ASSERT(MP_BC_SETUP_WITH + MP_EMIT_SETUP_BLOCK_FINALLY == MP_BC_SETUP_FINALLY);
+ if (kind == MP_EMIT_SETUP_BLOCK_WITH) {
// The SETUP_WITH opcode pops ctx_mgr from the top of the stack
// and then pushes 3 entries: __exit__, ctx_mgr, as_value.
- emit_bc_pre(emit, 2);
- emit_write_bytecode_byte_unsigned_label(emit, MP_BC_SETUP_WITH, label);
+ emit_bc_pre(emit, 2);
+ } else {
+ emit_bc_pre(emit, 0);
+ }
+ emit_write_bytecode_byte_unsigned_label(emit, MP_BC_SETUP_WITH + kind, label);
}
void mp_emit_bc_with_cleanup(emit_t *emit, mp_uint_t label) {
@@ -732,17 +739,7 @@ void mp_emit_bc_with_cleanup(emit_t *emit, mp_uint_t label) {
mp_emit_bc_label_assign(emit, label);
emit_bc_pre(emit, 2); // ensure we have enough stack space to call the __exit__ method
emit_write_bytecode_byte(emit, MP_BC_WITH_CLEANUP);
- emit_bc_pre(emit, -4); // cancel the 2 above, plus the 2 from mp_emit_bc_setup_with
-}
-
-void mp_emit_bc_setup_except(emit_t *emit, mp_uint_t label) {
- emit_bc_pre(emit, 0);
- emit_write_bytecode_byte_unsigned_label(emit, MP_BC_SETUP_EXCEPT, label);
-}
-
-void mp_emit_bc_setup_finally(emit_t *emit, mp_uint_t label) {
- emit_bc_pre(emit, 0);
- emit_write_bytecode_byte_unsigned_label(emit, MP_BC_SETUP_FINALLY, label);
+ emit_bc_pre(emit, -4); // cancel the 2 above, plus the 2 from mp_emit_bc_setup_block(MP_EMIT_SETUP_BLOCK_WITH)
}
void mp_emit_bc_end_finally(emit_t *emit) {
@@ -953,10 +950,8 @@ const emit_method_table_t emit_bc_method_table = {
mp_emit_bc_pop_jump_if,
mp_emit_bc_jump_if_or_pop,
mp_emit_bc_unwind_jump,
- mp_emit_bc_setup_with,
+ mp_emit_bc_setup_block,
mp_emit_bc_with_cleanup,
- mp_emit_bc_setup_except,
- mp_emit_bc_setup_finally,
mp_emit_bc_end_finally,
mp_emit_bc_get_iter,
mp_emit_bc_for_iter,