File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 113113#define MP_BC_LOAD_CONST_SMALL_INT_MULTI (0x70) // + N(64)
114114#define MP_BC_LOAD_FAST_MULTI (0xb0) // + N(16)
115115#define MP_BC_STORE_FAST_MULTI (0xc0) // + N(16)
116- #define MP_BC_UNARY_OP_MULTI (0xd0) // + op(7 )
116+ #define MP_BC_UNARY_OP_MULTI (0xd0) // + op(<MP_UNARY_OP_NON_BYTECODE )
117117#define MP_BC_BINARY_OP_MULTI (0xd7) // + op(36)
118118
119119#endif // MICROPY_INCLUDED_PY_BC0_H
Original file line number Diff line number Diff line change 4242#define MP_NATIVE_TYPE_PTR16 (0x06)
4343#define MP_NATIVE_TYPE_PTR32 (0x07)
4444
45- // Note: the first 7 of these are used in bytecode and changing
46- // them requires changing the bytecode version.
4745typedef enum {
48- MP_UNARY_OP_BOOL , // __bool__
49- MP_UNARY_OP_LEN , // __len__
50- MP_UNARY_OP_HASH , // __hash__; must return a small int
46+ // These ops may appear in the bytecode. Changing this group
47+ // in any way requires changing the bytecode version.
5148 MP_UNARY_OP_POSITIVE ,
5249 MP_UNARY_OP_NEGATIVE ,
5350 MP_UNARY_OP_INVERT ,
5451 MP_UNARY_OP_NOT ,
52+
53+ // Following ops cannot appear in the bytecode
54+ MP_UNARY_OP_NON_BYTECODE ,
55+
56+ MP_UNARY_OP_BOOL = MP_UNARY_OP_NON_BYTECODE , // __bool__
57+ MP_UNARY_OP_LEN , // __len__
58+ MP_UNARY_OP_HASH , // __hash__; must return a small int
5559 MP_UNARY_OP_ABS , // __abs__
5660 MP_UNARY_OP_SIZEOF , // for sys.getsizeof()
5761} mp_unary_op_t ;
Original file line number Diff line number Diff line change @@ -539,7 +539,7 @@ const byte *mp_bytecode_print_str(const byte *ip) {
539539 printf ("LOAD_FAST " UINT_FMT , (mp_uint_t )ip [-1 ] - MP_BC_LOAD_FAST_MULTI );
540540 } else if (ip [-1 ] < MP_BC_STORE_FAST_MULTI + 16 ) {
541541 printf ("STORE_FAST " UINT_FMT , (mp_uint_t )ip [-1 ] - MP_BC_STORE_FAST_MULTI );
542- } else if (ip [-1 ] < MP_BC_UNARY_OP_MULTI + 7 ) {
542+ } else if (ip [-1 ] < MP_BC_UNARY_OP_MULTI + MP_UNARY_OP_NON_BYTECODE ) {
543543 printf ("UNARY_OP " UINT_FMT , (mp_uint_t )ip [-1 ] - MP_BC_UNARY_OP_MULTI );
544544 } else if (ip [-1 ] < MP_BC_BINARY_OP_MULTI + 36 ) {
545545 mp_uint_t op = ip [-1 ] - MP_BC_BINARY_OP_MULTI ;
Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ static const void *const entry_table[256] = {
109109 [MP_BC_LOAD_CONST_SMALL_INT_MULTI ... MP_BC_LOAD_CONST_SMALL_INT_MULTI + 63 ] = & & entry_MP_BC_LOAD_CONST_SMALL_INT_MULTI ,
110110 [MP_BC_LOAD_FAST_MULTI ... MP_BC_LOAD_FAST_MULTI + 15 ] = & & entry_MP_BC_LOAD_FAST_MULTI ,
111111 [MP_BC_STORE_FAST_MULTI ... MP_BC_STORE_FAST_MULTI + 15 ] = & & entry_MP_BC_STORE_FAST_MULTI ,
112- [MP_BC_UNARY_OP_MULTI ... MP_BC_UNARY_OP_MULTI + 6 ] = & & entry_MP_BC_UNARY_OP_MULTI ,
112+ [MP_BC_UNARY_OP_MULTI ... MP_BC_UNARY_OP_MULTI + MP_UNARY_OP_NON_BYTECODE - 1 ] = & & entry_MP_BC_UNARY_OP_MULTI ,
113113 [MP_BC_BINARY_OP_MULTI ... MP_BC_BINARY_OP_MULTI + 35 ] = & & entry_MP_BC_BINARY_OP_MULTI ,
114114};
115115
Original file line number Diff line number Diff line change @@ -87,10 +87,10 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+):
8787\\d\+ BINARY_OP 28 __add__
8888\\d\+ STORE_FAST 8
8989\\d\+ LOAD_FAST 0
90- \\d\+ UNARY_OP 4
90+ \\d\+ UNARY_OP 1
9191\\d\+ STORE_FAST 9
9292\\d\+ LOAD_FAST 0
93- \\d\+ UNARY_OP 6
93+ \\d\+ UNARY_OP 3
9494\\d\+ STORE_FAST 10
9595\\d\+ LOAD_FAST 0
9696\\d\+ LOAD_DEREF 14
@@ -111,7 +111,7 @@ Raw bytecode (code_info_size=\\d\+, bytecode_size=\\d\+):
111111\\d\+ LOAD_DEREF 14
112112\\d\+ LOAD_FAST 1
113113\\d\+ BINARY_OP 2 __eq__
114- \\d\+ UNARY_OP 6
114+ \\d\+ UNARY_OP 3
115115\\d\+ STORE_FAST 10
116116\\d\+ LOAD_DEREF 14
117117\\d\+ LOAD_ATTR c (cache=0)
You can’t perform that action at this time.
0 commit comments