aboutsummaryrefslogtreecommitdiff
path: root/py/bc0.h
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/bc0.h
parent870e900d02937918187a4e4ef75a1e38880bae62 (diff)
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/bc0.h')
-rw-r--r--py/bc0.h12
1 files changed, 7 insertions, 5 deletions
diff --git a/py/bc0.h b/py/bc0.h
index f3044125b..7cf061fc4 100644
--- a/py/bc0.h
+++ b/py/bc0.h
@@ -46,7 +46,7 @@
#define MP_BC_BASE_VINT_O (0x30) // UUMMCCCC--------
#define MP_BC_BASE_JUMP_E (0x40) // J-JJJJJEEEEF----
#define MP_BC_BASE_BYTE_O (0x50) // LLLLSSDTTTTTEEFF
-#define MP_BC_BASE_BYTE_E (0x60) // E-BRYYI---------
+#define MP_BC_BASE_BYTE_E (0x60) // --BREEEYYI------
#define MP_BC_LOAD_CONST_SMALL_INT_MULTI (0x70) // LLLLLLLLLLLLLLLL
// (0x80) // LLLLLLLLLLLLLLLL
// (0x90) // LLLLLLLLLLLLLLLL
@@ -128,9 +128,11 @@
#define MP_BC_UNPACK_EX (MP_BC_BASE_VINT_O + 0x01) // uint
#define MP_BC_RETURN_VALUE (MP_BC_BASE_BYTE_E + 0x03)
-#define MP_BC_RAISE_VARARGS (MP_BC_BASE_BYTE_E + 0x00) // extra byte
-#define MP_BC_YIELD_VALUE (MP_BC_BASE_BYTE_E + 0x04)
-#define MP_BC_YIELD_FROM (MP_BC_BASE_BYTE_E + 0x05)
+#define MP_BC_RAISE_LAST (MP_BC_BASE_BYTE_E + 0x04)
+#define MP_BC_RAISE_OBJ (MP_BC_BASE_BYTE_E + 0x05)
+#define MP_BC_RAISE_FROM (MP_BC_BASE_BYTE_E + 0x06)
+#define MP_BC_YIELD_VALUE (MP_BC_BASE_BYTE_E + 0x07)
+#define MP_BC_YIELD_FROM (MP_BC_BASE_BYTE_E + 0x08)
#define MP_BC_MAKE_FUNCTION (MP_BC_BASE_VINT_O + 0x02) // uint
#define MP_BC_MAKE_FUNCTION_DEFARGS (MP_BC_BASE_VINT_O + 0x03) // uint
@@ -143,6 +145,6 @@
#define MP_BC_IMPORT_NAME (MP_BC_BASE_QSTR_O + 0x0b) // qstr
#define MP_BC_IMPORT_FROM (MP_BC_BASE_QSTR_O + 0x0c) // qstr
-#define MP_BC_IMPORT_STAR (MP_BC_BASE_BYTE_E + 0x06)
+#define MP_BC_IMPORT_STAR (MP_BC_BASE_BYTE_E + 0x09)
#endif // MICROPY_INCLUDED_PY_BC0_H