| 1 | n/a | |
|---|
| 2 | n/a | """ |
|---|
| 3 | n/a | opcode module - potentially shared between dis and other modules which |
|---|
| 4 | n/a | operate on bytecodes (e.g. peephole optimizers). |
|---|
| 5 | n/a | """ |
|---|
| 6 | n/a | |
|---|
| 7 | n/a | __all__ = ["cmp_op", "hasconst", "hasname", "hasjrel", "hasjabs", |
|---|
| 8 | n/a | "haslocal", "hascompare", "hasfree", "opname", "opmap", |
|---|
| 9 | n/a | "HAVE_ARGUMENT", "EXTENDED_ARG", "hasnargs"] |
|---|
| 10 | n/a | |
|---|
| 11 | n/a | # It's a chicken-and-egg I'm afraid: |
|---|
| 12 | n/a | # We're imported before _opcode's made. |
|---|
| 13 | n/a | # With exception unheeded |
|---|
| 14 | n/a | # (stack_effect is not needed) |
|---|
| 15 | n/a | # Both our chickens and eggs are allayed. |
|---|
| 16 | n/a | # --Larry Hastings, 2013/11/23 |
|---|
| 17 | n/a | |
|---|
| 18 | n/a | try: |
|---|
| 19 | n/a | from _opcode import stack_effect |
|---|
| 20 | n/a | __all__.append('stack_effect') |
|---|
| 21 | n/a | except ImportError: |
|---|
| 22 | n/a | pass |
|---|
| 23 | n/a | |
|---|
| 24 | n/a | cmp_op = ('<', '<=', '==', '!=', '>', '>=', 'in', 'not in', 'is', |
|---|
| 25 | n/a | 'is not', 'exception match', 'BAD') |
|---|
| 26 | n/a | |
|---|
| 27 | n/a | hasconst = [] |
|---|
| 28 | n/a | hasname = [] |
|---|
| 29 | n/a | hasjrel = [] |
|---|
| 30 | n/a | hasjabs = [] |
|---|
| 31 | n/a | haslocal = [] |
|---|
| 32 | n/a | hascompare = [] |
|---|
| 33 | n/a | hasfree = [] |
|---|
| 34 | n/a | hasnargs = [] # unused |
|---|
| 35 | n/a | |
|---|
| 36 | n/a | opmap = {} |
|---|
| 37 | n/a | opname = ['<%r>' % (op,) for op in range(256)] |
|---|
| 38 | n/a | |
|---|
| 39 | n/a | def def_op(name, op): |
|---|
| 40 | n/a | opname[op] = name |
|---|
| 41 | n/a | opmap[name] = op |
|---|
| 42 | n/a | |
|---|
| 43 | n/a | def name_op(name, op): |
|---|
| 44 | n/a | def_op(name, op) |
|---|
| 45 | n/a | hasname.append(op) |
|---|
| 46 | n/a | |
|---|
| 47 | n/a | def jrel_op(name, op): |
|---|
| 48 | n/a | def_op(name, op) |
|---|
| 49 | n/a | hasjrel.append(op) |
|---|
| 50 | n/a | |
|---|
| 51 | n/a | def jabs_op(name, op): |
|---|
| 52 | n/a | def_op(name, op) |
|---|
| 53 | n/a | hasjabs.append(op) |
|---|
| 54 | n/a | |
|---|
| 55 | n/a | # Instruction opcodes for compiled code |
|---|
| 56 | n/a | # Blank lines correspond to available opcodes |
|---|
| 57 | n/a | |
|---|
| 58 | n/a | def_op('POP_TOP', 1) |
|---|
| 59 | n/a | def_op('ROT_TWO', 2) |
|---|
| 60 | n/a | def_op('ROT_THREE', 3) |
|---|
| 61 | n/a | def_op('DUP_TOP', 4) |
|---|
| 62 | n/a | def_op('DUP_TOP_TWO', 5) |
|---|
| 63 | n/a | |
|---|
| 64 | n/a | def_op('NOP', 9) |
|---|
| 65 | n/a | def_op('UNARY_POSITIVE', 10) |
|---|
| 66 | n/a | def_op('UNARY_NEGATIVE', 11) |
|---|
| 67 | n/a | def_op('UNARY_NOT', 12) |
|---|
| 68 | n/a | |
|---|
| 69 | n/a | def_op('UNARY_INVERT', 15) |
|---|
| 70 | n/a | |
|---|
| 71 | n/a | def_op('BINARY_MATRIX_MULTIPLY', 16) |
|---|
| 72 | n/a | def_op('INPLACE_MATRIX_MULTIPLY', 17) |
|---|
| 73 | n/a | |
|---|
| 74 | n/a | def_op('BINARY_POWER', 19) |
|---|
| 75 | n/a | def_op('BINARY_MULTIPLY', 20) |
|---|
| 76 | n/a | |
|---|
| 77 | n/a | def_op('BINARY_MODULO', 22) |
|---|
| 78 | n/a | def_op('BINARY_ADD', 23) |
|---|
| 79 | n/a | def_op('BINARY_SUBTRACT', 24) |
|---|
| 80 | n/a | def_op('BINARY_SUBSCR', 25) |
|---|
| 81 | n/a | def_op('BINARY_FLOOR_DIVIDE', 26) |
|---|
| 82 | n/a | def_op('BINARY_TRUE_DIVIDE', 27) |
|---|
| 83 | n/a | def_op('INPLACE_FLOOR_DIVIDE', 28) |
|---|
| 84 | n/a | def_op('INPLACE_TRUE_DIVIDE', 29) |
|---|
| 85 | n/a | |
|---|
| 86 | n/a | def_op('GET_AITER', 50) |
|---|
| 87 | n/a | def_op('GET_ANEXT', 51) |
|---|
| 88 | n/a | def_op('BEFORE_ASYNC_WITH', 52) |
|---|
| 89 | n/a | |
|---|
| 90 | n/a | def_op('INPLACE_ADD', 55) |
|---|
| 91 | n/a | def_op('INPLACE_SUBTRACT', 56) |
|---|
| 92 | n/a | def_op('INPLACE_MULTIPLY', 57) |
|---|
| 93 | n/a | |
|---|
| 94 | n/a | def_op('INPLACE_MODULO', 59) |
|---|
| 95 | n/a | def_op('STORE_SUBSCR', 60) |
|---|
| 96 | n/a | def_op('DELETE_SUBSCR', 61) |
|---|
| 97 | n/a | def_op('BINARY_LSHIFT', 62) |
|---|
| 98 | n/a | def_op('BINARY_RSHIFT', 63) |
|---|
| 99 | n/a | def_op('BINARY_AND', 64) |
|---|
| 100 | n/a | def_op('BINARY_XOR', 65) |
|---|
| 101 | n/a | def_op('BINARY_OR', 66) |
|---|
| 102 | n/a | def_op('INPLACE_POWER', 67) |
|---|
| 103 | n/a | def_op('GET_ITER', 68) |
|---|
| 104 | n/a | def_op('GET_YIELD_FROM_ITER', 69) |
|---|
| 105 | n/a | |
|---|
| 106 | n/a | def_op('PRINT_EXPR', 70) |
|---|
| 107 | n/a | def_op('LOAD_BUILD_CLASS', 71) |
|---|
| 108 | n/a | def_op('YIELD_FROM', 72) |
|---|
| 109 | n/a | def_op('GET_AWAITABLE', 73) |
|---|
| 110 | n/a | |
|---|
| 111 | n/a | def_op('INPLACE_LSHIFT', 75) |
|---|
| 112 | n/a | def_op('INPLACE_RSHIFT', 76) |
|---|
| 113 | n/a | def_op('INPLACE_AND', 77) |
|---|
| 114 | n/a | def_op('INPLACE_XOR', 78) |
|---|
| 115 | n/a | def_op('INPLACE_OR', 79) |
|---|
| 116 | n/a | def_op('BREAK_LOOP', 80) |
|---|
| 117 | n/a | def_op('WITH_CLEANUP_START', 81) |
|---|
| 118 | n/a | def_op('WITH_CLEANUP_FINISH', 82) |
|---|
| 119 | n/a | |
|---|
| 120 | n/a | def_op('RETURN_VALUE', 83) |
|---|
| 121 | n/a | def_op('IMPORT_STAR', 84) |
|---|
| 122 | n/a | def_op('SETUP_ANNOTATIONS', 85) |
|---|
| 123 | n/a | def_op('YIELD_VALUE', 86) |
|---|
| 124 | n/a | def_op('POP_BLOCK', 87) |
|---|
| 125 | n/a | def_op('END_FINALLY', 88) |
|---|
| 126 | n/a | def_op('POP_EXCEPT', 89) |
|---|
| 127 | n/a | |
|---|
| 128 | n/a | HAVE_ARGUMENT = 90 # Opcodes from here have an argument: |
|---|
| 129 | n/a | |
|---|
| 130 | n/a | name_op('STORE_NAME', 90) # Index in name list |
|---|
| 131 | n/a | name_op('DELETE_NAME', 91) # "" |
|---|
| 132 | n/a | def_op('UNPACK_SEQUENCE', 92) # Number of tuple items |
|---|
| 133 | n/a | jrel_op('FOR_ITER', 93) |
|---|
| 134 | n/a | def_op('UNPACK_EX', 94) |
|---|
| 135 | n/a | name_op('STORE_ATTR', 95) # Index in name list |
|---|
| 136 | n/a | name_op('DELETE_ATTR', 96) # "" |
|---|
| 137 | n/a | name_op('STORE_GLOBAL', 97) # "" |
|---|
| 138 | n/a | name_op('DELETE_GLOBAL', 98) # "" |
|---|
| 139 | n/a | def_op('LOAD_CONST', 100) # Index in const list |
|---|
| 140 | n/a | hasconst.append(100) |
|---|
| 141 | n/a | name_op('LOAD_NAME', 101) # Index in name list |
|---|
| 142 | n/a | def_op('BUILD_TUPLE', 102) # Number of tuple items |
|---|
| 143 | n/a | def_op('BUILD_LIST', 103) # Number of list items |
|---|
| 144 | n/a | def_op('BUILD_SET', 104) # Number of set items |
|---|
| 145 | n/a | def_op('BUILD_MAP', 105) # Number of dict entries (upto 255) |
|---|
| 146 | n/a | name_op('LOAD_ATTR', 106) # Index in name list |
|---|
| 147 | n/a | def_op('COMPARE_OP', 107) # Comparison operator |
|---|
| 148 | n/a | hascompare.append(107) |
|---|
| 149 | n/a | name_op('IMPORT_NAME', 108) # Index in name list |
|---|
| 150 | n/a | name_op('IMPORT_FROM', 109) # Index in name list |
|---|
| 151 | n/a | |
|---|
| 152 | n/a | jrel_op('JUMP_FORWARD', 110) # Number of bytes to skip |
|---|
| 153 | n/a | jabs_op('JUMP_IF_FALSE_OR_POP', 111) # Target byte offset from beginning of code |
|---|
| 154 | n/a | jabs_op('JUMP_IF_TRUE_OR_POP', 112) # "" |
|---|
| 155 | n/a | jabs_op('JUMP_ABSOLUTE', 113) # "" |
|---|
| 156 | n/a | jabs_op('POP_JUMP_IF_FALSE', 114) # "" |
|---|
| 157 | n/a | jabs_op('POP_JUMP_IF_TRUE', 115) # "" |
|---|
| 158 | n/a | |
|---|
| 159 | n/a | name_op('LOAD_GLOBAL', 116) # Index in name list |
|---|
| 160 | n/a | |
|---|
| 161 | n/a | jabs_op('CONTINUE_LOOP', 119) # Target address |
|---|
| 162 | n/a | jrel_op('SETUP_LOOP', 120) # Distance to target address |
|---|
| 163 | n/a | jrel_op('SETUP_EXCEPT', 121) # "" |
|---|
| 164 | n/a | jrel_op('SETUP_FINALLY', 122) # "" |
|---|
| 165 | n/a | |
|---|
| 166 | n/a | def_op('LOAD_FAST', 124) # Local variable number |
|---|
| 167 | n/a | haslocal.append(124) |
|---|
| 168 | n/a | def_op('STORE_FAST', 125) # Local variable number |
|---|
| 169 | n/a | haslocal.append(125) |
|---|
| 170 | n/a | def_op('DELETE_FAST', 126) # Local variable number |
|---|
| 171 | n/a | haslocal.append(126) |
|---|
| 172 | n/a | name_op('STORE_ANNOTATION', 127) # Index in name list |
|---|
| 173 | n/a | |
|---|
| 174 | n/a | def_op('RAISE_VARARGS', 130) # Number of raise arguments (1, 2, or 3) |
|---|
| 175 | n/a | def_op('CALL_FUNCTION', 131) # #args |
|---|
| 176 | n/a | def_op('MAKE_FUNCTION', 132) # Flags |
|---|
| 177 | n/a | def_op('BUILD_SLICE', 133) # Number of items |
|---|
| 178 | n/a | def_op('LOAD_CLOSURE', 135) |
|---|
| 179 | n/a | hasfree.append(135) |
|---|
| 180 | n/a | def_op('LOAD_DEREF', 136) |
|---|
| 181 | n/a | hasfree.append(136) |
|---|
| 182 | n/a | def_op('STORE_DEREF', 137) |
|---|
| 183 | n/a | hasfree.append(137) |
|---|
| 184 | n/a | def_op('DELETE_DEREF', 138) |
|---|
| 185 | n/a | hasfree.append(138) |
|---|
| 186 | n/a | |
|---|
| 187 | n/a | def_op('CALL_FUNCTION_KW', 141) # #args + #kwargs |
|---|
| 188 | n/a | def_op('CALL_FUNCTION_EX', 142) # Flags |
|---|
| 189 | n/a | |
|---|
| 190 | n/a | jrel_op('SETUP_WITH', 143) |
|---|
| 191 | n/a | |
|---|
| 192 | n/a | def_op('LIST_APPEND', 145) |
|---|
| 193 | n/a | def_op('SET_ADD', 146) |
|---|
| 194 | n/a | def_op('MAP_ADD', 147) |
|---|
| 195 | n/a | |
|---|
| 196 | n/a | def_op('LOAD_CLASSDEREF', 148) |
|---|
| 197 | n/a | hasfree.append(148) |
|---|
| 198 | n/a | |
|---|
| 199 | n/a | def_op('EXTENDED_ARG', 144) |
|---|
| 200 | n/a | EXTENDED_ARG = 144 |
|---|
| 201 | n/a | |
|---|
| 202 | n/a | def_op('BUILD_LIST_UNPACK', 149) |
|---|
| 203 | n/a | def_op('BUILD_MAP_UNPACK', 150) |
|---|
| 204 | n/a | def_op('BUILD_MAP_UNPACK_WITH_CALL', 151) |
|---|
| 205 | n/a | def_op('BUILD_TUPLE_UNPACK', 152) |
|---|
| 206 | n/a | def_op('BUILD_SET_UNPACK', 153) |
|---|
| 207 | n/a | |
|---|
| 208 | n/a | jrel_op('SETUP_ASYNC_WITH', 154) |
|---|
| 209 | n/a | |
|---|
| 210 | n/a | def_op('FORMAT_VALUE', 155) |
|---|
| 211 | n/a | def_op('BUILD_CONST_KEY_MAP', 156) |
|---|
| 212 | n/a | def_op('BUILD_STRING', 157) |
|---|
| 213 | n/a | def_op('BUILD_TUPLE_UNPACK_WITH_CALL', 158) |
|---|
| 214 | n/a | |
|---|
| 215 | n/a | name_op('LOAD_METHOD', 160) |
|---|
| 216 | n/a | def_op('CALL_METHOD', 161) |
|---|
| 217 | n/a | |
|---|
| 218 | n/a | del def_op, name_op, jrel_op, jabs_op |
|---|