summaryrefslogtreecommitdiff
path: root/py/emitbc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-05-19 00:11:04 +1000
committerDamien George <damien.p.george@gmail.com>2018-05-23 00:22:20 +1000
commit0a25fff9562e3051d85db9ca773f203620004742 (patch)
tree3b36f17d20598afc44bf24bf26afb7de7fc23df3 /py/emitbc.c
parent400273a799581e5eb86538d8c88fb872705475ab (diff)
py/emit: Combine fast and deref into one function for load/store/delete.
Reduces code size by: bare-arm: -16 minimal x86: -208 unix x64: -408 unix nanbox: -248 stm32: -12 cc3200: -24 esp8266: -96 esp32: -44
Diffstat (limited to 'py/emitbc.c')
-rw-r--r--py/emitbc.c57
1 files changed, 20 insertions, 37 deletions
diff --git a/py/emitbc.c b/py/emitbc.c
index b1b61ba67..28d32d4ea 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -556,22 +556,18 @@ void mp_emit_bc_load_null(emit_t *emit) {
emit_write_bytecode_byte(emit, MP_BC_LOAD_NULL);
}
-void mp_emit_bc_load_fast(emit_t *emit, qstr qst, mp_uint_t local_num) {
+void mp_emit_bc_load_local(emit_t *emit, qstr qst, mp_uint_t local_num, int kind) {
+ MP_STATIC_ASSERT(MP_BC_LOAD_FAST_N + MP_EMIT_IDOP_LOCAL_FAST == MP_BC_LOAD_FAST_N);
+ MP_STATIC_ASSERT(MP_BC_LOAD_FAST_N + MP_EMIT_IDOP_LOCAL_DEREF == MP_BC_LOAD_DEREF);
(void)qst;
emit_bc_pre(emit, 1);
- if (local_num <= 15) {
+ if (kind == MP_EMIT_IDOP_LOCAL_FAST && local_num <= 15) {
emit_write_bytecode_byte(emit, MP_BC_LOAD_FAST_MULTI + local_num);
} else {
- emit_write_bytecode_byte_uint(emit, MP_BC_LOAD_FAST_N, local_num);
+ emit_write_bytecode_byte_uint(emit, MP_BC_LOAD_FAST_N + kind, local_num);
}
}
-void mp_emit_bc_load_deref(emit_t *emit, qstr qst, mp_uint_t local_num) {
- (void)qst;
- emit_bc_pre(emit, 1);
- emit_write_bytecode_byte_uint(emit, MP_BC_LOAD_DEREF, local_num);
-}
-
void mp_emit_bc_load_name(emit_t *emit, qstr qst) {
(void)qst;
emit_bc_pre(emit, 1);
@@ -613,22 +609,18 @@ void mp_emit_bc_load_subscr(emit_t *emit) {
emit_write_bytecode_byte(emit, MP_BC_LOAD_SUBSCR);
}
-void mp_emit_bc_store_fast(emit_t *emit, qstr qst, mp_uint_t local_num) {
+void mp_emit_bc_store_local(emit_t *emit, qstr qst, mp_uint_t local_num, int kind) {
+ MP_STATIC_ASSERT(MP_BC_STORE_FAST_N + MP_EMIT_IDOP_LOCAL_FAST == MP_BC_STORE_FAST_N);
+ MP_STATIC_ASSERT(MP_BC_STORE_FAST_N + MP_EMIT_IDOP_LOCAL_DEREF == MP_BC_STORE_DEREF);
(void)qst;
emit_bc_pre(emit, -1);
- if (local_num <= 15) {
+ if (kind == MP_EMIT_IDOP_LOCAL_FAST && local_num <= 15) {
emit_write_bytecode_byte(emit, MP_BC_STORE_FAST_MULTI + local_num);
} else {
- emit_write_bytecode_byte_uint(emit, MP_BC_STORE_FAST_N, local_num);
+ emit_write_bytecode_byte_uint(emit, MP_BC_STORE_FAST_N + kind, local_num);
}
}
-void mp_emit_bc_store_deref(emit_t *emit, qstr qst, mp_uint_t local_num) {
- (void)qst;
- emit_bc_pre(emit, -1);
- emit_write_bytecode_byte_uint(emit, MP_BC_STORE_DEREF, local_num);
-}
-
void mp_emit_bc_store_name(emit_t *emit, qstr qst) {
emit_bc_pre(emit, -1);
emit_write_bytecode_byte_qstr(emit, MP_BC_STORE_NAME, qst);
@@ -652,14 +644,11 @@ void mp_emit_bc_store_subscr(emit_t *emit) {
emit_write_bytecode_byte(emit, MP_BC_STORE_SUBSCR);
}
-void mp_emit_bc_delete_fast(emit_t *emit, qstr qst, mp_uint_t local_num) {
- (void)qst;
- emit_write_bytecode_byte_uint(emit, MP_BC_DELETE_FAST, local_num);
-}
-
-void mp_emit_bc_delete_deref(emit_t *emit, qstr qst, mp_uint_t local_num) {
+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);
(void)qst;
- emit_write_bytecode_byte_uint(emit, MP_BC_DELETE_DEREF, local_num);
+ emit_write_bytecode_byte_uint(emit, MP_BC_DELETE_FAST + kind, local_num);
}
void mp_emit_bc_delete_name(emit_t *emit, qstr qst) {
@@ -972,20 +961,17 @@ const emit_method_table_t emit_bc_method_table = {
mp_emit_bc_set_source_line,
{
- mp_emit_bc_load_fast,
- mp_emit_bc_load_deref,
+ mp_emit_bc_load_local,
mp_emit_bc_load_name,
mp_emit_bc_load_global,
},
{
- mp_emit_bc_store_fast,
- mp_emit_bc_store_deref,
+ mp_emit_bc_store_local,
mp_emit_bc_store_name,
mp_emit_bc_store_global,
},
{
- mp_emit_bc_delete_fast,
- mp_emit_bc_delete_deref,
+ mp_emit_bc_delete_local,
mp_emit_bc_delete_name,
mp_emit_bc_delete_global,
},
@@ -1056,22 +1042,19 @@ const emit_method_table_t emit_bc_method_table = {
};
#else
const mp_emit_method_table_id_ops_t mp_emit_bc_method_table_load_id_ops = {
- mp_emit_bc_load_fast,
- mp_emit_bc_load_deref,
+ mp_emit_bc_load_local,
mp_emit_bc_load_name,
mp_emit_bc_load_global,
};
const mp_emit_method_table_id_ops_t mp_emit_bc_method_table_store_id_ops = {
- mp_emit_bc_store_fast,
- mp_emit_bc_store_deref,
+ mp_emit_bc_store_local,
mp_emit_bc_store_name,
mp_emit_bc_store_global,
};
const mp_emit_method_table_id_ops_t mp_emit_bc_method_table_delete_id_ops = {
- mp_emit_bc_delete_fast,
- mp_emit_bc_delete_deref,
+ mp_emit_bc_delete_local,
mp_emit_bc_delete_name,
mp_emit_bc_delete_global,
};