py/emit: Combine load/store/delete subscr into one emit function.
Reduces code size by:
bare-arm: -8
minimal x86: -104
unix x64: -312
unix nanbox: -120
stm32: -60
cc3200: -16
esp8266: -92
esp32: -24
diff --git a/py/emitbc.c b/py/emitbc.c
index ed043de..b342c21 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -597,9 +597,18 @@
emit_write_bytecode_byte(emit, MP_BC_LOAD_BUILD_CLASS);
}
-void mp_emit_bc_load_subscr(emit_t *emit) {
- emit_bc_pre(emit, -1);
- emit_write_bytecode_byte(emit, MP_BC_LOAD_SUBSCR);
+void mp_emit_bc_subscr(emit_t *emit, int kind) {
+ if (kind == MP_EMIT_SUBSCR_LOAD) {
+ emit_bc_pre(emit, -1);
+ emit_write_bytecode_byte(emit, MP_BC_LOAD_SUBSCR);
+ } else {
+ if (kind == MP_EMIT_SUBSCR_DELETE) {
+ mp_emit_bc_load_null(emit);
+ mp_emit_bc_rot_three(emit);
+ }
+ emit_bc_pre(emit, -3);
+ emit_write_bytecode_byte(emit, MP_BC_STORE_SUBSCR);
+ }
}
void mp_emit_bc_store_local(emit_t *emit, qstr qst, mp_uint_t local_num, int kind) {
@@ -629,11 +638,6 @@
}
}
-void mp_emit_bc_store_subscr(emit_t *emit) {
- emit_bc_pre(emit, -3);
- emit_write_bytecode_byte(emit, MP_BC_STORE_SUBSCR);
-}
-
void mp_emit_bc_delete_local(emit_t *emit, qstr qst, mp_uint_t local_num, int kind) {
MP_STATIC_ASSERT(MP_BC_DELETE_FAST + MP_EMIT_IDOP_LOCAL_FAST == MP_BC_DELETE_FAST);
MP_STATIC_ASSERT(MP_BC_DELETE_FAST + MP_EMIT_IDOP_LOCAL_DEREF == MP_BC_DELETE_DEREF);
@@ -654,12 +658,6 @@
mp_emit_bc_store_attr(emit, qst);
}
-void mp_emit_bc_delete_subscr(emit_t *emit) {
- mp_emit_bc_load_null(emit);
- mp_emit_bc_rot_three(emit);
- mp_emit_bc_store_subscr(emit);
-}
-
void mp_emit_bc_dup_top(emit_t *emit) {
emit_bc_pre(emit, 1);
emit_write_bytecode_byte(emit, MP_BC_DUP_TOP);
@@ -964,11 +962,9 @@
mp_emit_bc_load_attr,
mp_emit_bc_load_method,
mp_emit_bc_load_build_class,
- mp_emit_bc_load_subscr,
+ mp_emit_bc_subscr,
mp_emit_bc_store_attr,
- mp_emit_bc_store_subscr,
mp_emit_bc_delete_attr,
- mp_emit_bc_delete_subscr,
mp_emit_bc_dup_top,
mp_emit_bc_dup_top_two,
mp_emit_bc_pop_top,