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.
This commit is contained in:
parent
f008263022
commit
9d836fedbd
2
py/bc0.h
2
py/bc0.h
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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,
|
||||
};
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user