|
26 | 26 | #ifndef MICROPY_INCLUDED_PY_BC0_H |
27 | 27 | #define MICROPY_INCLUDED_PY_BC0_H |
28 | 28 |
|
29 | | -// MicroPython byte-codes. |
30 | | -// The comment at the end of the line (if it exists) tells the arguments to the byte-code. |
| 29 | +// MicroPython bytecode opcodes, grouped based on the format of the opcode |
31 | 30 |
|
32 | | -#define MP_BC_LOAD_CONST_FALSE (0x10) |
33 | | -#define MP_BC_LOAD_CONST_NONE (0x11) |
34 | | -#define MP_BC_LOAD_CONST_TRUE (0x12) |
35 | | -#define MP_BC_LOAD_CONST_SMALL_INT (0x14) // signed var-int |
36 | | -#define MP_BC_LOAD_CONST_STRING (0x16) // qstr |
37 | | -#define MP_BC_LOAD_CONST_OBJ (0x17) // ptr |
38 | | -#define MP_BC_LOAD_NULL (0x18) |
| 31 | +#define MP_BC_MASK_FORMAT (0xf0) |
| 32 | +#define MP_BC_MASK_EXTRA_BYTE (0x9e) |
39 | 33 |
|
40 | | -#define MP_BC_LOAD_FAST_N (0x19) // uint |
41 | | -#define MP_BC_LOAD_DEREF (0x1a) // uint |
42 | | -#define MP_BC_LOAD_NAME (0x1b) // qstr |
43 | | -#define MP_BC_LOAD_GLOBAL (0x1c) // qstr |
44 | | -#define MP_BC_LOAD_ATTR (0x1d) // qstr |
45 | | -#define MP_BC_LOAD_METHOD (0x1e) // qstr |
46 | | -#define MP_BC_LOAD_SUPER_METHOD (0x1f) // qstr |
47 | | -#define MP_BC_LOAD_BUILD_CLASS (0x20) |
48 | | -#define MP_BC_LOAD_SUBSCR (0x21) |
| 34 | +// Load, Store, Delete, Import, Make, Build, Unpack, Call, Jump, Exception, For, sTack, Return, Yield, Op |
| 35 | +#define MP_BC_BASE_RESERVED (0x00) // ---------------- |
| 36 | +#define MP_BC_BASE_QSTR_O (0x10) // LLLLLLSSSDDII--- |
| 37 | +#define MP_BC_BASE_VINT_E (0x20) // MMLLLLSSDDBBBBBB |
| 38 | +#define MP_BC_BASE_VINT_O (0x30) // UUMMCCCC-------- |
| 39 | +#define MP_BC_BASE_JUMP_E (0x40) // J-JJJJJEEEEF---- |
| 40 | +#define MP_BC_BASE_BYTE_O (0x50) // LLLLSSDTTTTTEEFF |
| 41 | +#define MP_BC_BASE_BYTE_E (0x60) // E-BRYYI--------- |
| 42 | +#define MP_BC_LOAD_CONST_SMALL_INT_MULTI (0x70) // LLLLLLLLLLLLLLLL |
| 43 | + // (0x80) // LLLLLLLLLLLLLLLL |
| 44 | + // (0x90) // LLLLLLLLLLLLLLLL |
| 45 | + // (0xa0) // LLLLLLLLLLLLLLLL |
| 46 | +#define MP_BC_LOAD_FAST_MULTI (0xb0) // LLLLLLLLLLLLLLLL |
| 47 | +#define MP_BC_STORE_FAST_MULTI (0xc0) // SSSSSSSSSSSSSSSS |
| 48 | +#define MP_BC_UNARY_OP_MULTI (0xd0) // OOOOOOO |
| 49 | +#define MP_BC_BINARY_OP_MULTI (0xd7) // OOOOOOOOO |
| 50 | + // (0xe0) // OOOOOOOOOOOOOOOO |
| 51 | + // (0xf0) // OOOOOOOOOO------ |
49 | 52 |
|
50 | | -#define MP_BC_STORE_FAST_N (0x22) // uint |
51 | | -#define MP_BC_STORE_DEREF (0x23) // uint |
52 | | -#define MP_BC_STORE_NAME (0x24) // qstr |
53 | | -#define MP_BC_STORE_GLOBAL (0x25) // qstr |
54 | | -#define MP_BC_STORE_ATTR (0x26) // qstr |
55 | | -#define MP_BC_STORE_SUBSCR (0x27) |
| 53 | +#define MP_BC_LOAD_CONST_FALSE (MP_BC_BASE_BYTE_O + 0x00) |
| 54 | +#define MP_BC_LOAD_CONST_NONE (MP_BC_BASE_BYTE_O + 0x01) |
| 55 | +#define MP_BC_LOAD_CONST_TRUE (MP_BC_BASE_BYTE_O + 0x02) |
| 56 | +#define MP_BC_LOAD_CONST_SMALL_INT (MP_BC_BASE_VINT_E + 0x02) // signed var-int |
| 57 | +#define MP_BC_LOAD_CONST_STRING (MP_BC_BASE_QSTR_O + 0x00) // qstr |
| 58 | +#define MP_BC_LOAD_CONST_OBJ (MP_BC_BASE_VINT_E + 0x03) // ptr |
| 59 | +#define MP_BC_LOAD_NULL (MP_BC_BASE_BYTE_O + 0x03) |
56 | 60 |
|
57 | | -#define MP_BC_DELETE_FAST (0x28) // uint |
58 | | -#define MP_BC_DELETE_DEREF (0x29) // uint |
59 | | -#define MP_BC_DELETE_NAME (0x2a) // qstr |
60 | | -#define MP_BC_DELETE_GLOBAL (0x2b) // qstr |
| 61 | +#define MP_BC_LOAD_FAST_N (MP_BC_BASE_VINT_E + 0x04) // uint |
| 62 | +#define MP_BC_LOAD_DEREF (MP_BC_BASE_VINT_E + 0x05) // uint |
| 63 | +#define MP_BC_LOAD_NAME (MP_BC_BASE_QSTR_O + 0x01) // qstr |
| 64 | +#define MP_BC_LOAD_GLOBAL (MP_BC_BASE_QSTR_O + 0x02) // qstr |
| 65 | +#define MP_BC_LOAD_ATTR (MP_BC_BASE_QSTR_O + 0x03) // qstr |
| 66 | +#define MP_BC_LOAD_METHOD (MP_BC_BASE_QSTR_O + 0x04) // qstr |
| 67 | +#define MP_BC_LOAD_SUPER_METHOD (MP_BC_BASE_QSTR_O + 0x05) // qstr |
| 68 | +#define MP_BC_LOAD_BUILD_CLASS (MP_BC_BASE_BYTE_O + 0x04) |
| 69 | +#define MP_BC_LOAD_SUBSCR (MP_BC_BASE_BYTE_O + 0x05) |
61 | 70 |
|
62 | | -#define MP_BC_DUP_TOP (0x30) |
63 | | -#define MP_BC_DUP_TOP_TWO (0x31) |
64 | | -#define MP_BC_POP_TOP (0x32) |
65 | | -#define MP_BC_ROT_TWO (0x33) |
66 | | -#define MP_BC_ROT_THREE (0x34) |
| 71 | +#define MP_BC_STORE_FAST_N (MP_BC_BASE_VINT_E + 0x06) // uint |
| 72 | +#define MP_BC_STORE_DEREF (MP_BC_BASE_VINT_E + 0x07) // uint |
| 73 | +#define MP_BC_STORE_NAME (MP_BC_BASE_QSTR_O + 0x06) // qstr |
| 74 | +#define MP_BC_STORE_GLOBAL (MP_BC_BASE_QSTR_O + 0x07) // qstr |
| 75 | +#define MP_BC_STORE_ATTR (MP_BC_BASE_QSTR_O + 0x08) // qstr |
| 76 | +#define MP_BC_STORE_SUBSCR (MP_BC_BASE_BYTE_O + 0x06) |
67 | 77 |
|
68 | | -#define MP_BC_JUMP (0x35) // rel byte code offset, 16-bit signed, in excess |
69 | | -#define MP_BC_POP_JUMP_IF_TRUE (0x36) // rel byte code offset, 16-bit signed, in excess |
70 | | -#define MP_BC_POP_JUMP_IF_FALSE (0x37) // rel byte code offset, 16-bit signed, in excess |
71 | | -#define MP_BC_JUMP_IF_TRUE_OR_POP (0x38) // rel byte code offset, 16-bit signed, in excess |
72 | | -#define MP_BC_JUMP_IF_FALSE_OR_POP (0x39) // rel byte code offset, 16-bit signed, in excess |
73 | | -#define MP_BC_SETUP_WITH (0x3d) // rel byte code offset, 16-bit unsigned |
74 | | -#define MP_BC_WITH_CLEANUP (0x3e) |
75 | | -#define MP_BC_SETUP_EXCEPT (0x3f) // rel byte code offset, 16-bit unsigned |
76 | | -#define MP_BC_SETUP_FINALLY (0x40) // rel byte code offset, 16-bit unsigned |
77 | | -#define MP_BC_END_FINALLY (0x41) |
78 | | -#define MP_BC_GET_ITER (0x42) |
79 | | -#define MP_BC_FOR_ITER (0x43) // rel byte code offset, 16-bit unsigned |
80 | | -#define MP_BC_POP_EXCEPT_JUMP (0x44) // rel byte code offset, 16-bit unsigned |
81 | | -#define MP_BC_UNWIND_JUMP (0x46) // rel byte code offset, 16-bit signed, in excess; then a byte |
82 | | -#define MP_BC_GET_ITER_STACK (0x47) |
| 78 | +#define MP_BC_DELETE_FAST (MP_BC_BASE_VINT_E + 0x08) // uint |
| 79 | +#define MP_BC_DELETE_DEREF (MP_BC_BASE_VINT_E + 0x09) // uint |
| 80 | +#define MP_BC_DELETE_NAME (MP_BC_BASE_QSTR_O + 0x09) // qstr |
| 81 | +#define MP_BC_DELETE_GLOBAL (MP_BC_BASE_QSTR_O + 0x0a) // qstr |
83 | 82 |
|
84 | | -#define MP_BC_BUILD_TUPLE (0x50) // uint |
85 | | -#define MP_BC_BUILD_LIST (0x51) // uint |
86 | | -#define MP_BC_BUILD_MAP (0x53) // uint |
87 | | -#define MP_BC_STORE_MAP (0x54) |
88 | | -#define MP_BC_BUILD_SET (0x56) // uint |
89 | | -#define MP_BC_BUILD_SLICE (0x58) // uint |
90 | | -#define MP_BC_STORE_COMP (0x57) // uint |
91 | | -#define MP_BC_UNPACK_SEQUENCE (0x59) // uint |
92 | | -#define MP_BC_UNPACK_EX (0x5a) // uint |
| 83 | +#define MP_BC_DUP_TOP (MP_BC_BASE_BYTE_O + 0x07) |
| 84 | +#define MP_BC_DUP_TOP_TWO (MP_BC_BASE_BYTE_O + 0x08) |
| 85 | +#define MP_BC_POP_TOP (MP_BC_BASE_BYTE_O + 0x09) |
| 86 | +#define MP_BC_ROT_TWO (MP_BC_BASE_BYTE_O + 0x0a) |
| 87 | +#define MP_BC_ROT_THREE (MP_BC_BASE_BYTE_O + 0x0b) |
93 | 88 |
|
94 | | -#define MP_BC_RETURN_VALUE (0x5b) |
95 | | -#define MP_BC_RAISE_VARARGS (0x5c) // byte |
96 | | -#define MP_BC_YIELD_VALUE (0x5d) |
97 | | -#define MP_BC_YIELD_FROM (0x5e) |
| 89 | +#define MP_BC_JUMP (MP_BC_BASE_JUMP_E + 0x02) // rel byte code offset, 16-bit signed, in excess |
| 90 | +#define MP_BC_POP_JUMP_IF_TRUE (MP_BC_BASE_JUMP_E + 0x03) // rel byte code offset, 16-bit signed, in excess |
| 91 | +#define MP_BC_POP_JUMP_IF_FALSE (MP_BC_BASE_JUMP_E + 0x04) // rel byte code offset, 16-bit signed, in excess |
| 92 | +#define MP_BC_JUMP_IF_TRUE_OR_POP (MP_BC_BASE_JUMP_E + 0x05) // rel byte code offset, 16-bit signed, in excess |
| 93 | +#define MP_BC_JUMP_IF_FALSE_OR_POP (MP_BC_BASE_JUMP_E + 0x06) // rel byte code offset, 16-bit signed, in excess |
| 94 | +#define MP_BC_UNWIND_JUMP (MP_BC_BASE_JUMP_E + 0x00) // rel byte code offset, 16-bit signed, in excess; then a byte |
| 95 | +#define MP_BC_SETUP_WITH (MP_BC_BASE_JUMP_E + 0x07) // rel byte code offset, 16-bit unsigned |
| 96 | +#define MP_BC_SETUP_EXCEPT (MP_BC_BASE_JUMP_E + 0x08) // rel byte code offset, 16-bit unsigned |
| 97 | +#define MP_BC_SETUP_FINALLY (MP_BC_BASE_JUMP_E + 0x09) // rel byte code offset, 16-bit unsigned |
| 98 | +#define MP_BC_POP_EXCEPT_JUMP (MP_BC_BASE_JUMP_E + 0x0a) // rel byte code offset, 16-bit unsigned |
| 99 | +#define MP_BC_FOR_ITER (MP_BC_BASE_JUMP_E + 0x0b) // rel byte code offset, 16-bit unsigned |
| 100 | +#define MP_BC_WITH_CLEANUP (MP_BC_BASE_BYTE_O + 0x0c) |
| 101 | +#define MP_BC_END_FINALLY (MP_BC_BASE_BYTE_O + 0x0d) |
| 102 | +#define MP_BC_GET_ITER (MP_BC_BASE_BYTE_O + 0x0e) |
| 103 | +#define MP_BC_GET_ITER_STACK (MP_BC_BASE_BYTE_O + 0x0f) |
98 | 104 |
|
99 | | -#define MP_BC_MAKE_FUNCTION (0x60) // uint |
100 | | -#define MP_BC_MAKE_FUNCTION_DEFARGS (0x61) // uint |
101 | | -#define MP_BC_MAKE_CLOSURE (0x62) // uint; byte |
102 | | -#define MP_BC_MAKE_CLOSURE_DEFARGS (0x63) // uint; byte |
103 | | -#define MP_BC_CALL_FUNCTION (0x64) // uint |
104 | | -#define MP_BC_CALL_FUNCTION_VAR_KW (0x65) // uint |
105 | | -#define MP_BC_CALL_METHOD (0x66) // uint |
106 | | -#define MP_BC_CALL_METHOD_VAR_KW (0x67) // uint |
| 105 | +#define MP_BC_BUILD_TUPLE (MP_BC_BASE_VINT_E + 0x0a) // uint |
| 106 | +#define MP_BC_BUILD_LIST (MP_BC_BASE_VINT_E + 0x0b) // uint |
| 107 | +#define MP_BC_BUILD_MAP (MP_BC_BASE_VINT_E + 0x0c) // uint |
| 108 | +#define MP_BC_STORE_MAP (MP_BC_BASE_BYTE_E + 0x02) |
| 109 | +#define MP_BC_BUILD_SET (MP_BC_BASE_VINT_E + 0x0d) // uint |
| 110 | +#define MP_BC_BUILD_SLICE (MP_BC_BASE_VINT_E + 0x0e) // uint |
| 111 | +#define MP_BC_STORE_COMP (MP_BC_BASE_VINT_E + 0x0f) // uint |
| 112 | +#define MP_BC_UNPACK_SEQUENCE (MP_BC_BASE_VINT_O + 0x00) // uint |
| 113 | +#define MP_BC_UNPACK_EX (MP_BC_BASE_VINT_O + 0x01) // uint |
107 | 114 |
|
108 | | -#define MP_BC_IMPORT_NAME (0x68) // qstr |
109 | | -#define MP_BC_IMPORT_FROM (0x69) // qstr |
110 | | -#define MP_BC_IMPORT_STAR (0x6a) |
| 115 | +#define MP_BC_RETURN_VALUE (MP_BC_BASE_BYTE_E + 0x03) |
| 116 | +#define MP_BC_RAISE_VARARGS (MP_BC_BASE_BYTE_E + 0x00) // extra byte |
| 117 | +#define MP_BC_YIELD_VALUE (MP_BC_BASE_BYTE_E + 0x04) |
| 118 | +#define MP_BC_YIELD_FROM (MP_BC_BASE_BYTE_E + 0x05) |
111 | 119 |
|
112 | | -#define MP_BC_LOAD_CONST_SMALL_INT_MULTI (0x70) // + N(64) |
113 | | -#define MP_BC_LOAD_FAST_MULTI (0xb0) // + N(16) |
114 | | -#define MP_BC_STORE_FAST_MULTI (0xc0) // + N(16) |
115 | | -#define MP_BC_UNARY_OP_MULTI (0xd0) // + op(<MP_UNARY_OP_NUM_BYTECODE) |
116 | | -#define MP_BC_BINARY_OP_MULTI (0xd7) // + op(<MP_BINARY_OP_NUM_BYTECODE) |
| 120 | +#define MP_BC_MAKE_FUNCTION (MP_BC_BASE_VINT_O + 0x02) // uint |
| 121 | +#define MP_BC_MAKE_FUNCTION_DEFARGS (MP_BC_BASE_VINT_O + 0x03) // uint |
| 122 | +#define MP_BC_MAKE_CLOSURE (MP_BC_BASE_VINT_E + 0x00) // uint; extra byte |
| 123 | +#define MP_BC_MAKE_CLOSURE_DEFARGS (MP_BC_BASE_VINT_E + 0x01) // uint; extra byte |
| 124 | +#define MP_BC_CALL_FUNCTION (MP_BC_BASE_VINT_O + 0x04) // uint |
| 125 | +#define MP_BC_CALL_FUNCTION_VAR_KW (MP_BC_BASE_VINT_O + 0x05) // uint |
| 126 | +#define MP_BC_CALL_METHOD (MP_BC_BASE_VINT_O + 0x06) // uint |
| 127 | +#define MP_BC_CALL_METHOD_VAR_KW (MP_BC_BASE_VINT_O + 0x07) // uint |
| 128 | + |
| 129 | +#define MP_BC_IMPORT_NAME (MP_BC_BASE_QSTR_O + 0x0b) // qstr |
| 130 | +#define MP_BC_IMPORT_FROM (MP_BC_BASE_QSTR_O + 0x0c) // qstr |
| 131 | +#define MP_BC_IMPORT_STAR (MP_BC_BASE_BYTE_E + 0x06) |
117 | 132 |
|
118 | 133 | #endif // MICROPY_INCLUDED_PY_BC0_H |
0 commit comments