logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

opcode.py (5902B)


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