opcode.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. #ifndef Py_OPCODE_H
  2. #define Py_OPCODE_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. /* Instruction opcodes for compiled code */
  7. #define STOP_CODE 0
  8. #define POP_TOP 1
  9. #define ROT_TWO 2
  10. #define ROT_THREE 3
  11. #define DUP_TOP 4
  12. #define ROT_FOUR 5
  13. #define NOP 9
  14. #define UNARY_POSITIVE 10
  15. #define UNARY_NEGATIVE 11
  16. #define UNARY_NOT 12
  17. #define UNARY_CONVERT 13
  18. #define UNARY_INVERT 15
  19. #define BINARY_POWER 19
  20. #define BINARY_MULTIPLY 20
  21. #define BINARY_DIVIDE 21
  22. #define BINARY_MODULO 22
  23. #define BINARY_ADD 23
  24. #define BINARY_SUBTRACT 24
  25. #define BINARY_SUBSCR 25
  26. #define BINARY_FLOOR_DIVIDE 26
  27. #define BINARY_TRUE_DIVIDE 27
  28. #define INPLACE_FLOOR_DIVIDE 28
  29. #define INPLACE_TRUE_DIVIDE 29
  30. #define SLICE 30
  31. /* Also uses 31-33 */
  32. #define SLICE_1 31
  33. #define SLICE_2 32
  34. #define SLICE_3 33
  35. #define STORE_SLICE 40
  36. /* Also uses 41-43 */
  37. #define STORE_SLICE_1 41
  38. #define STORE_SLICE_2 42
  39. #define STORE_SLICE_3 43
  40. #define DELETE_SLICE 50
  41. /* Also uses 51-53 */
  42. #define DELETE_SLICE_1 51
  43. #define DELETE_SLICE_2 52
  44. #define DELETE_SLICE_3 53
  45. #define STORE_MAP 54
  46. #define INPLACE_ADD 55
  47. #define INPLACE_SUBTRACT 56
  48. #define INPLACE_MULTIPLY 57
  49. #define INPLACE_DIVIDE 58
  50. #define INPLACE_MODULO 59
  51. #define STORE_SUBSCR 60
  52. #define DELETE_SUBSCR 61
  53. #define BINARY_LSHIFT 62
  54. #define BINARY_RSHIFT 63
  55. #define BINARY_AND 64
  56. #define BINARY_XOR 65
  57. #define BINARY_OR 66
  58. #define INPLACE_POWER 67
  59. #define GET_ITER 68
  60. #define PRINT_EXPR 70
  61. #define PRINT_ITEM 71
  62. #define PRINT_NEWLINE 72
  63. #define PRINT_ITEM_TO 73
  64. #define PRINT_NEWLINE_TO 74
  65. #define INPLACE_LSHIFT 75
  66. #define INPLACE_RSHIFT 76
  67. #define INPLACE_AND 77
  68. #define INPLACE_XOR 78
  69. #define INPLACE_OR 79
  70. #define BREAK_LOOP 80
  71. #define WITH_CLEANUP 81
  72. #define LOAD_LOCALS 82
  73. #define RETURN_VALUE 83
  74. #define IMPORT_STAR 84
  75. #define EXEC_STMT 85
  76. #define YIELD_VALUE 86
  77. #define POP_BLOCK 87
  78. #define END_FINALLY 88
  79. #define BUILD_CLASS 89
  80. #define HAVE_ARGUMENT 90 /* Opcodes from here have an argument: */
  81. #define STORE_NAME 90 /* Index in name list */
  82. #define DELETE_NAME 91 /* "" */
  83. #define UNPACK_SEQUENCE 92 /* Number of sequence items */
  84. #define FOR_ITER 93
  85. #define LIST_APPEND 94
  86. #define STORE_ATTR 95 /* Index in name list */
  87. #define DELETE_ATTR 96 /* "" */
  88. #define STORE_GLOBAL 97 /* "" */
  89. #define DELETE_GLOBAL 98 /* "" */
  90. #define DUP_TOPX 99 /* number of items to duplicate */
  91. #define LOAD_CONST 100 /* Index in const list */
  92. #define LOAD_NAME 101 /* Index in name list */
  93. #define BUILD_TUPLE 102 /* Number of tuple items */
  94. #define BUILD_LIST 103 /* Number of list items */
  95. #define BUILD_SET 104 /* Number of set items */
  96. #define BUILD_MAP 105 /* Always zero for now */
  97. #define LOAD_ATTR 106 /* Index in name list */
  98. #define COMPARE_OP 107 /* Comparison operator */
  99. #define IMPORT_NAME 108 /* Index in name list */
  100. #define IMPORT_FROM 109 /* Index in name list */
  101. #define JUMP_FORWARD 110 /* Number of bytes to skip */
  102. #define JUMP_IF_FALSE_OR_POP 111 /* Target byte offset from beginning
  103. of code */
  104. #define JUMP_IF_TRUE_OR_POP 112 /* "" */
  105. #define JUMP_ABSOLUTE 113 /* "" */
  106. #define POP_JUMP_IF_FALSE 114 /* "" */
  107. #define POP_JUMP_IF_TRUE 115 /* "" */
  108. #define LOAD_GLOBAL 116 /* Index in name list */
  109. #define CONTINUE_LOOP 119 /* Start of loop (absolute) */
  110. #define SETUP_LOOP 120 /* Target address (relative) */
  111. #define SETUP_EXCEPT 121 /* "" */
  112. #define SETUP_FINALLY 122 /* "" */
  113. #define LOAD_FAST 124 /* Local variable number */
  114. #define STORE_FAST 125 /* Local variable number */
  115. #define DELETE_FAST 126 /* Local variable number */
  116. #define RAISE_VARARGS 130 /* Number of raise arguments (1, 2 or 3) */
  117. /* CALL_FUNCTION_XXX opcodes defined below depend on this definition */
  118. #define CALL_FUNCTION 131 /* #args + (#kwargs<<8) */
  119. #define MAKE_FUNCTION 132 /* #defaults */
  120. #define BUILD_SLICE 133 /* Number of items */
  121. #define MAKE_CLOSURE 134 /* #free vars */
  122. #define LOAD_CLOSURE 135 /* Load free variable from closure */
  123. #define LOAD_DEREF 136 /* Load and dereference from closure cell */
  124. #define STORE_DEREF 137 /* Store into cell */
  125. /* The next 3 opcodes must be contiguous and satisfy
  126. (CALL_FUNCTION_VAR - CALL_FUNCTION) & 3 == 1 */
  127. #define CALL_FUNCTION_VAR 140 /* #args + (#kwargs<<8) */
  128. #define CALL_FUNCTION_KW 141 /* #args + (#kwargs<<8) */
  129. #define CALL_FUNCTION_VAR_KW 142 /* #args + (#kwargs<<8) */
  130. #define SETUP_WITH 143
  131. /* Support for opargs more than 16 bits long */
  132. #define EXTENDED_ARG 145
  133. #define SET_ADD 146
  134. #define MAP_ADD 147
  135. enum cmp_op {PyCmp_LT=Py_LT, PyCmp_LE=Py_LE, PyCmp_EQ=Py_EQ, PyCmp_NE=Py_NE, PyCmp_GT=Py_GT, PyCmp_GE=Py_GE,
  136. PyCmp_IN, PyCmp_NOT_IN, PyCmp_IS, PyCmp_IS_NOT, PyCmp_EXC_MATCH, PyCmp_BAD};
  137. #define HAS_ARG(op) ((op) >= HAVE_ARGUMENT)
  138. #ifdef __cplusplus
  139. }
  140. #endif
  141. #endif /* !Py_OPCODE_H */