summaryrefslogtreecommitdiffstatshomepage
path: root/py/emitbc.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2019-08-22 12:39:07 +1000
committerDamien George <damien.p.george@gmail.com>2019-09-26 15:39:50 +1000
commit02db91a7a311a96dd82a497cf513137e04191b29 (patch)
tree781991a3b87530077bef6199aea8ff0ede034643 /py/emitbc.c
parent870e900d02937918187a4e4ef75a1e38880bae62 (diff)
downloadmicropython-02db91a7a311a96dd82a497cf513137e04191b29.tar.gz
micropython-02db91a7a311a96dd82a497cf513137e04191b29.zip
py: Split RAISE_VARARGS opcode into 3 separate ones.
From the beginning of this project the RAISE_VARARGS opcode was named and implemented following CPython, where it has an argument (to the opcode) counting how many args the raise takes: raise # 0 args (re-raise previous exception) raise exc # 1 arg raise exc from exc2 # 2 args (chained raise) In the bytecode this operation therefore takes 2 bytes, one for RAISE_VARARGS and one for the number of args. This patch splits this opcode into 3, where each is now a single byte. This reduces bytecode size by 1 byte for each use of raise. Every byte counts! It also has the benefit of reducing code size (on all ports except nanbox).
Diffstat (limited to 'py/emitbc.c')
-rw-r--r--py/emitbc.c11
1 files changed, 3 insertions, 8 deletions
diff --git a/py/emitbc.c b/py/emitbc.c
index 83fcbae415..a8d57d27b0 100644
--- a/py/emitbc.c
+++ b/py/emitbc.c
@@ -193,13 +193,6 @@ STATIC void emit_write_bytecode_byte(emit_t *emit, int stack_adj, byte b1) {
c[0] = b1;
}
-STATIC void emit_write_bytecode_byte_byte(emit_t* emit, int stack_adj, byte b1, byte b2) {
- mp_emit_bc_adjust_stack_size(emit, stack_adj);
- byte *c = emit_get_cur_to_write_bytecode(emit, 2);
- c[0] = b1;
- c[1] = b2;
-}
-
// Similar to emit_write_bytecode_uint(), just some extra handling to encode sign
STATIC void emit_write_bytecode_byte_int(emit_t *emit, int stack_adj, byte b1, mp_int_t num) {
emit_write_bytecode_byte(emit, stack_adj, b1);
@@ -848,8 +841,10 @@ void mp_emit_bc_return_value(emit_t *emit) {
}
void mp_emit_bc_raise_varargs(emit_t *emit, mp_uint_t n_args) {
+ MP_STATIC_ASSERT(MP_BC_RAISE_LAST + 1 == MP_BC_RAISE_OBJ);
+ MP_STATIC_ASSERT(MP_BC_RAISE_LAST + 2 == MP_BC_RAISE_FROM);
assert(n_args <= 2);
- emit_write_bytecode_byte_byte(emit, -n_args, MP_BC_RAISE_VARARGS, n_args);
+ emit_write_bytecode_byte(emit, -n_args, MP_BC_RAISE_LAST + n_args);
}
void mp_emit_bc_yield(emit_t *emit, int kind) {