diff options
-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 | ||||
-rw-r--r-- | tests/cmdline/cmd_showbc.py.exp | 6 |
5 files changed, 15 insertions, 11 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 6d77cce68..f54f62d2c 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 bb2b084ed..728d8d983 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 352a6dc31..e634e2b41 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, }; diff --git a/tests/cmdline/cmd_showbc.py.exp b/tests/cmdline/cmd_showbc.py.exp index 0e66a013d..09fbff6fa 100644 --- a/tests/cmdline/cmd_showbc.py.exp +++ b/tests/cmdline/cmd_showbc.py.exp @@ -87,10 +87,10 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+): \\d\+ BINARY_OP 28 __add__ \\d\+ STORE_FAST 8 \\d\+ LOAD_FAST 0 -\\d\+ UNARY_OP 4 +\\d\+ UNARY_OP 1 \\d\+ STORE_FAST 9 \\d\+ LOAD_FAST 0 -\\d\+ UNARY_OP 6 +\\d\+ UNARY_OP 3 \\d\+ STORE_FAST 10 \\d\+ LOAD_FAST 0 \\d\+ LOAD_DEREF 14 @@ -111,7 +111,7 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+): \\d\+ LOAD_DEREF 14 \\d\+ LOAD_FAST 1 \\d\+ BINARY_OP 2 __eq__ -\\d\+ UNARY_OP 6 +\\d\+ UNARY_OP 3 \\d\+ STORE_FAST 10 \\d\+ LOAD_DEREF 14 \\d\+ LOAD_ATTR c (cache=0) |