summaryrefslogtreecommitdiff
path: root/py/emitbc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-05-22 21:31:56 +1000
committerDamien George <damien.p.george@gmail.com>2018-05-23 00:22:55 +1000
commita4941a8ba49e3503f1a87f318b79b137a70b803b (patch)
treec154376ee020eb2c5c95db1687a0c0cbaad86f87 /py/emitbc.c
parentd298013939b38fb05961cf05c03ac3aef6a4f00c (diff)
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
Diffstat (limited to 'py/emitbc.c')
-rw-r--r--py/emitbc.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/py/emitbc.c b/py/emitbc.c
index ed043de3a..b342c21a4 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -597,9 +597,18 @@ void mp_emit_bc_load_build_class(emit_t *emit) {
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_attr(emit_t *emit, qstr qst) {
}
}
-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 @@ void mp_emit_bc_delete_attr(emit_t *emit, qstr qst) {
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 @@ const emit_method_table_t emit_bc_method_table = {
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,