0001 0002 """ 0003 opcode module - potentially shared between dis and other modules which 0004 operate on bytecodes (e.g. peephole optimizers). 0005 """ 0006 0007 __all__ = ["cmp_op", "hasconst", "hasname", "hasjrel", "hasjabs", 0008 "haslocal", "hascompare", "hasfree", "opname", "opmap", 0009 "HAVE_ARGUMENT", "EXTENDED_ARG"] 0010 0011 cmp_op = ('<', '<=', '==', '!=', '>', '>=', 'in', 'not in', 'is', 0012 'is not', 'exception match', 'BAD') 0013 0014 hasconst = [] 0015 hasname = [] 0016 hasjrel = [] 0017 hasjabs = [] 0018 haslocal = [] 0019 hascompare = [] 0020 hasfree = [] 0021 0022 opmap = {} 0023 opname = [''] * 256 0024 for op in range(256): opname[op] = '<%r>' % (op,) 0025 del op 0026 0027 def def_op(name, op): 0028 opname[op] = name 0029 opmap[name] = op 0030 0031 def name_op(name, op): 0032 def_op(name, op) 0033 hasname.append(op) 0034 0035 def jrel_op(name, op): 0036 def_op(name, op) 0037 hasjrel.append(op) 0038 0039 def jabs_op(name, op): 0040 def_op(name, op) 0041 hasjabs.append(op) 0042 0043 # Instruction opcodes for compiled code 0044 0045 def_op('STOP_CODE', 0) 0046 def_op('POP_TOP', 1) 0047 def_op('ROT_TWO', 2) 0048 def_op('ROT_THREE', 3) 0049 def_op('DUP_TOP', 4) 0050 def_op('ROT_FOUR', 5) 0051 0052 def_op('NOP', 9) 0053 def_op('UNARY_POSITIVE', 10) 0054 def_op('UNARY_NEGATIVE', 11) 0055 def_op('UNARY_NOT', 12) 0056 def_op('UNARY_CONVERT', 13) 0057 0058 def_op('UNARY_INVERT', 15) 0059 0060 def_op('LIST_APPEND', 18) 0061 def_op('BINARY_POWER', 19) 0062 0063 def_op('BINARY_MULTIPLY', 20) 0064 def_op('BINARY_DIVIDE', 21) 0065 def_op('BINARY_MODULO', 22) 0066 def_op('BINARY_ADD', 23) 0067 def_op('BINARY_SUBTRACT', 24) 0068 def_op('BINARY_SUBSCR', 25) 0069 def_op('BINARY_FLOOR_DIVIDE', 26) 0070 def_op('BINARY_TRUE_DIVIDE', 27) 0071 def_op('INPLACE_FLOOR_DIVIDE', 28) 0072 def_op('INPLACE_TRUE_DIVIDE', 29) 0073 0074 def_op('SLICE+0', 30) 0075 def_op('SLICE+1', 31) 0076 def_op('SLICE+2', 32) 0077 def_op('SLICE+3', 33) 0078 0079 def_op('STORE_SLICE+0', 40) 0080 def_op('STORE_SLICE+1', 41) 0081 def_op('STORE_SLICE+2', 42) 0082 def_op('STORE_SLICE+3', 43) 0083 0084 def_op('DELETE_SLICE+0', 50) 0085 def_op('DELETE_SLICE+1', 51) 0086 def_op('DELETE_SLICE+2', 52) 0087 def_op('DELETE_SLICE+3', 53) 0088 0089 def_op('INPLACE_ADD', 55) 0090 def_op('INPLACE_SUBTRACT', 56) 0091 def_op('INPLACE_MULTIPLY', 57) 0092 def_op('INPLACE_DIVIDE', 58) 0093 def_op('INPLACE_MODULO', 59) 0094 def_op('STORE_SUBSCR', 60) 0095 def_op('DELETE_SUBSCR', 61) 0096 0097 def_op('BINARY_LSHIFT', 62) 0098 def_op('BINARY_RSHIFT', 63) 0099 def_op('BINARY_AND', 64) 0100 def_op('BINARY_XOR', 65) 0101 def_op('BINARY_OR', 66) 0102 def_op('INPLACE_POWER', 67) 0103 def_op('GET_ITER', 68) 0104 0105 def_op('PRINT_EXPR', 70) 0106 def_op('PRINT_ITEM', 71) 0107 def_op('PRINT_NEWLINE', 72) 0108 def_op('PRINT_ITEM_TO', 73) 0109 def_op('PRINT_NEWLINE_TO', 74) 0110 def_op('INPLACE_LSHIFT', 75) 0111 def_op('INPLACE_RSHIFT', 76) 0112 def_op('INPLACE_AND', 77) 0113 def_op('INPLACE_XOR', 78) 0114 def_op('INPLACE_OR', 79) 0115 def_op('BREAK_LOOP', 80) 0116 0117 def_op('LOAD_LOCALS', 82) 0118 def_op('RETURN_VALUE', 83) 0119 def_op('IMPORT_STAR', 84) 0120 def_op('EXEC_STMT', 85) 0121 def_op('YIELD_VALUE', 86) 0122 0123 def_op('POP_BLOCK', 87) 0124 def_op('END_FINALLY', 88) 0125 def_op('BUILD_CLASS', 89) 0126 0127 HAVE_ARGUMENT = 90 # Opcodes from here have an argument: 0128 0129 name_op('STORE_NAME', 90) # Index in name list 0130 name_op('DELETE_NAME', 91) # "" 0131 def_op('UNPACK_SEQUENCE', 92) # Number of tuple items 0132 jrel_op('FOR_ITER', 93) 0133 0134 name_op('STORE_ATTR', 95) # Index in name list 0135 name_op('DELETE_ATTR', 96) # "" 0136 name_op('STORE_GLOBAL', 97) # "" 0137 name_op('DELETE_GLOBAL', 98) # "" 0138 def_op('DUP_TOPX', 99) # number of items to duplicate 0139 def_op('LOAD_CONST', 100) # Index in const list 0140 hasconst.append(100) 0141 name_op('LOAD_NAME', 101) # Index in name list 0142 def_op('BUILD_TUPLE', 102) # Number of tuple items 0143 def_op('BUILD_LIST', 103) # Number of list items 0144 def_op('BUILD_MAP', 104) # Always zero for now 0145 name_op('LOAD_ATTR', 105) # Index in name list 0146 def_op('COMPARE_OP', 106) # Comparison operator 0147 hascompare.append(106) 0148 name_op('IMPORT_NAME', 107) # Index in name list 0149 name_op('IMPORT_FROM', 108) # Index in name list 0150 0151 jrel_op('JUMP_FORWARD', 110) # Number of bytes to skip 0152 jrel_op('JUMP_IF_FALSE', 111) # "" 0153 jrel_op('JUMP_IF_TRUE', 112) # "" 0154 jabs_op('JUMP_ABSOLUTE', 113) # Target byte offset from beginning of code 0155 0156 name_op('LOAD_GLOBAL', 116) # Index in name list 0157 0158 jabs_op('CONTINUE_LOOP', 119) # Target address 0159 jrel_op('SETUP_LOOP', 120) # Distance to target address 0160 jrel_op('SETUP_EXCEPT', 121) # "" 0161 jrel_op('SETUP_FINALLY', 122) # "" 0162 0163 def_op('LOAD_FAST', 124) # Local variable number 0164 haslocal.append(124) 0165 def_op('STORE_FAST', 125) # Local variable number 0166 haslocal.append(125) 0167 def_op('DELETE_FAST', 126) # Local variable number 0168 haslocal.append(126) 0169 0170 def_op('RAISE_VARARGS', 130) # Number of raise arguments (1, 2, or 3) 0171 def_op('CALL_FUNCTION', 131) # #args + (#kwargs << 8) 0172 def_op('MAKE_FUNCTION', 132) # Number of args with default values 0173 def_op('BUILD_SLICE', 133) # Number of items 0174 0175 def_op('MAKE_CLOSURE', 134) 0176 def_op('LOAD_CLOSURE', 135) 0177 hasfree.append(135) 0178 def_op('LOAD_DEREF', 136) 0179 hasfree.append(136) 0180 def_op('STORE_DEREF', 137) 0181 hasfree.append(137) 0182 0183 def_op('CALL_FUNCTION_VAR', 140) # #args + (#kwargs << 8) 0184 def_op('CALL_FUNCTION_KW', 141) # #args + (#kwargs << 8) 0185 def_op('CALL_FUNCTION_VAR_KW', 142) # #args + (#kwargs << 8) 0186 0187 def_op('EXTENDED_ARG', 143) 0188 EXTENDED_ARG = 143 0189 0190 del def_op, name_op, jrel_op, jabs_op 0191
Generated by PyXR 0.9.4