diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-09-25 16:35:19 -0700 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2017-09-25 16:35:19 -0700 |
commit | 9d836fedbdb1d28bdfc4ba475bbdfc1adb3f007a (patch) | |
tree | 363d265437890613bbe29e514d7666bd2f61d085 /py | |
parent | f008263022f794c056d8d102deaa62760822761a (diff) | |
download | micropython-9d836fedbdb1d28bdfc4ba475bbdfc1adb3f007a.tar.gz micropython-9d836fedbdb1d28bdfc4ba475bbdfc1adb3f007a.zip |
py: Clarify which mp_unary_op_t's may appear in the bytecode.
Not all can, so we don't need to reserve bytecodes for them, and can
use free slots for something else later.
Diffstat (limited to 'py')
-rw-r--r-- | py/bc0.h | 2 | ||||
-rw-r--r-- | py/runtime0.h | 14 | ||||
-rw-r--r-- | py/showbc.c | 2 | ||||
-rw-r--r-- | py/vmentrytable.h | 2 |
4 files changed, 12 insertions, 8 deletions
@@ -113,7 +113,7 @@ #define MP_BC_LOAD_CONST_SMALL_INT_MULTI (0x70) // + N(64) #define MP_BC_LOAD_FAST_MULTI (0xb0) // + N(16) #define MP_BC_STORE_FAST_MULTI (0xc0) // + N(16) -#define MP_BC_UNARY_OP_MULTI (0xd0) // + op(7) +#define MP_BC_UNARY_OP_MULTI (0xd0) // + op(<MP_UNARY_OP_NON_BYTECODE) #define MP_BC_BINARY_OP_MULTI (0xd7) // + op(36) #endif // MICROPY_INCLUDED_PY_BC0_H diff --git a/py/runtime0.h b/py/runtime0.h index 6d77cce68e..f54f62d2c6 100644 --- a/py/runtime0.h +++ b/py/runtime0.h @@ -42,16 +42,20 @@ #define MP_NATIVE_TYPE_PTR16 (0x06) #define MP_NATIVE_TYPE_PTR32 (0x07) -// Note: the first 7 of these are used in bytecode and changing -// them requires changing the bytecode version. typedef enum { - MP_UNARY_OP_BOOL, // __bool__ - MP_UNARY_OP_LEN, // __len__ - MP_UNARY_OP_HASH, // __hash__; must return a small int + // These ops may appear in the bytecode. Changing this group + // in any way requires changing the bytecode version. MP_UNARY_OP_POSITIVE, MP_UNARY_OP_NEGATIVE, MP_UNARY_OP_INVERT, MP_UNARY_OP_NOT, + + // Following ops cannot appear in the bytecode + MP_UNARY_OP_NON_BYTECODE, + + MP_UNARY_OP_BOOL = MP_UNARY_OP_NON_BYTECODE, // __bool__ + MP_UNARY_OP_LEN, // __len__ + MP_UNARY_OP_HASH, // __hash__; must return a small int MP_UNARY_OP_ABS, // __abs__ MP_UNARY_OP_SIZEOF, // for sys.getsizeof() } mp_unary_op_t; diff --git a/py/showbc.c b/py/showbc.c index bb2b084ed7..728d8d9837 100644 --- a/py/showbc.c +++ b/py/showbc.c @@ -539,7 +539,7 @@ const byte *mp_bytecode_print_str(const byte *ip) { printf("LOAD_FAST " UINT_FMT, (mp_uint_t)ip[-1] - MP_BC_LOAD_FAST_MULTI); } else if (ip[-1] < MP_BC_STORE_FAST_MULTI + 16) { printf("STORE_FAST " UINT_FMT, (mp_uint_t)ip[-1] - MP_BC_STORE_FAST_MULTI); - } else if (ip[-1] < MP_BC_UNARY_OP_MULTI + 7) { + } else if (ip[-1] < MP_BC_UNARY_OP_MULTI + MP_UNARY_OP_NON_BYTECODE) { printf("UNARY_OP " UINT_FMT, (mp_uint_t)ip[-1] - MP_BC_UNARY_OP_MULTI); } else if (ip[-1] < MP_BC_BINARY_OP_MULTI + 36) { mp_uint_t op = ip[-1] - MP_BC_BINARY_OP_MULTI; diff --git a/py/vmentrytable.h b/py/vmentrytable.h index 352a6dc315..e634e2b417 100644 --- a/py/vmentrytable.h +++ b/py/vmentrytable.h @@ -109,7 +109,7 @@ static const void *const entry_table[256] = { [MP_BC_LOAD_CONST_SMALL_INT_MULTI ... MP_BC_LOAD_CONST_SMALL_INT_MULTI + 63] = &&entry_MP_BC_LOAD_CONST_SMALL_INT_MULTI, [MP_BC_LOAD_FAST_MULTI ... MP_BC_LOAD_FAST_MULTI + 15] = &&entry_MP_BC_LOAD_FAST_MULTI, [MP_BC_STORE_FAST_MULTI ... MP_BC_STORE_FAST_MULTI + 15] = &&entry_MP_BC_STORE_FAST_MULTI, - [MP_BC_UNARY_OP_MULTI ... MP_BC_UNARY_OP_MULTI + 6] = &&entry_MP_BC_UNARY_OP_MULTI, + [MP_BC_UNARY_OP_MULTI ... MP_BC_UNARY_OP_MULTI + MP_UNARY_OP_NON_BYTECODE - 1] = &&entry_MP_BC_UNARY_OP_MULTI, [MP_BC_BINARY_OP_MULTI ... MP_BC_BINARY_OP_MULTI + 35] = &&entry_MP_BC_BINARY_OP_MULTI, }; |