You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

180 lines
4.9 KiB

Merged revisions 59541-59561 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r59544 | raymond.hettinger | 2007-12-18 01:13:45 +0100 (Tue, 18 Dec 2007) | 1 line Add more namedtuple() test cases. Neaten the code and comments. ........ r59545 | christian.heimes | 2007-12-18 04:38:03 +0100 (Tue, 18 Dec 2007) | 3 lines Fixed for #1601: IDLE not working correctly on Windows (Py30a2/IDLE30a1) Amaury's ideas works great. Should we build the Python core with WINVER=0x0500 and _WIN32_WINNT=0x0500, too? ........ r59546 | christian.heimes | 2007-12-18 10:00:13 +0100 (Tue, 18 Dec 2007) | 1 line Make it a bit easier to test Tcl/Tk and idle from a build dir. ........ r59547 | christian.heimes | 2007-12-18 10:12:10 +0100 (Tue, 18 Dec 2007) | 1 line Removed several unused files from the PCbuild9 directory. They are relics from the past. ........ r59548 | raymond.hettinger | 2007-12-18 19:26:18 +0100 (Tue, 18 Dec 2007) | 29 lines Speed-up dictionary constructor by about 10%. New opcode, STORE_MAP saves the compiler from awkward stack manipulations and specializes for dicts using PyDict_SetItem instead of PyObject_SetItem. Old disassembly: 0 BUILD_MAP 0 3 DUP_TOP 4 LOAD_CONST 1 (1) 7 ROT_TWO 8 LOAD_CONST 2 ('x') 11 STORE_SUBSCR 12 DUP_TOP 13 LOAD_CONST 3 (2) 16 ROT_TWO 17 LOAD_CONST 4 ('y') 20 STORE_SUBSCR New disassembly: 0 BUILD_MAP 0 3 LOAD_CONST 1 (1) 6 LOAD_CONST 2 ('x') 9 STORE_MAP 10 LOAD_CONST 3 (2) 13 LOAD_CONST 4 ('y') 16 STORE_MAP ........ r59549 | thomas.heller | 2007-12-18 20:00:34 +0100 (Tue, 18 Dec 2007) | 2 lines Issue #1642: Fix segfault in ctypes when trying to delete attributes. ........ r59551 | guido.van.rossum | 2007-12-18 21:10:42 +0100 (Tue, 18 Dec 2007) | 2 lines Issue #1645 by Alberto Bertogli. Fix a comment. ........ r59553 | raymond.hettinger | 2007-12-18 22:24:09 +0100 (Tue, 18 Dec 2007) | 12 lines Give meaning to the oparg for BUILD_MAP: estimated size of the dictionary. Allows dictionaries to be pre-sized (upto 255 elements) saving time lost to re-sizes with their attendant mallocs and re-insertions. Has zero effect on small dictionaries (5 elements or fewer), a slight benefit for dicts upto 22 elements (because they had to resize once anyway), and more benefit for dicts upto 255 elements (saving multiple resizes during the build-up and reducing the number of collisions on the first insertions). Beyond 255 elements, there is no addional benefit. ........ r59554 | christian.heimes | 2007-12-18 22:56:09 +0100 (Tue, 18 Dec 2007) | 1 line Fixed #1649: IDLE error: dictionary changed size during iteration ........ r59557 | raymond.hettinger | 2007-12-18 23:21:27 +0100 (Tue, 18 Dec 2007) | 1 line Simplify and speedup _asdict() for named tuples. ........ r59558 | christian.heimes | 2007-12-19 00:22:54 +0100 (Wed, 19 Dec 2007) | 3 lines Applied patch #1635: Float patch for inf and nan on Windows (and other platforms). The patch unifies float("inf") and repr(float("inf")) on all platforms. ........ r59559 | raymond.hettinger | 2007-12-19 00:51:15 +0100 (Wed, 19 Dec 2007) | 1 line Users demand iterable input for named tuples. The author capitulates. ........ r59560 | raymond.hettinger | 2007-12-19 01:21:06 +0100 (Wed, 19 Dec 2007) | 1 line Beef-up tests for dict literals ........ r59561 | raymond.hettinger | 2007-12-19 01:27:21 +0100 (Wed, 19 Dec 2007) | 1 line Zap a duplicate line ........
18 years ago
Merged revisions 59541-59561 via svnmerge from svn+ssh://pythondev@svn.python.org/python/trunk ........ r59544 | raymond.hettinger | 2007-12-18 01:13:45 +0100 (Tue, 18 Dec 2007) | 1 line Add more namedtuple() test cases. Neaten the code and comments. ........ r59545 | christian.heimes | 2007-12-18 04:38:03 +0100 (Tue, 18 Dec 2007) | 3 lines Fixed for #1601: IDLE not working correctly on Windows (Py30a2/IDLE30a1) Amaury's ideas works great. Should we build the Python core with WINVER=0x0500 and _WIN32_WINNT=0x0500, too? ........ r59546 | christian.heimes | 2007-12-18 10:00:13 +0100 (Tue, 18 Dec 2007) | 1 line Make it a bit easier to test Tcl/Tk and idle from a build dir. ........ r59547 | christian.heimes | 2007-12-18 10:12:10 +0100 (Tue, 18 Dec 2007) | 1 line Removed several unused files from the PCbuild9 directory. They are relics from the past. ........ r59548 | raymond.hettinger | 2007-12-18 19:26:18 +0100 (Tue, 18 Dec 2007) | 29 lines Speed-up dictionary constructor by about 10%. New opcode, STORE_MAP saves the compiler from awkward stack manipulations and specializes for dicts using PyDict_SetItem instead of PyObject_SetItem. Old disassembly: 0 BUILD_MAP 0 3 DUP_TOP 4 LOAD_CONST 1 (1) 7 ROT_TWO 8 LOAD_CONST 2 ('x') 11 STORE_SUBSCR 12 DUP_TOP 13 LOAD_CONST 3 (2) 16 ROT_TWO 17 LOAD_CONST 4 ('y') 20 STORE_SUBSCR New disassembly: 0 BUILD_MAP 0 3 LOAD_CONST 1 (1) 6 LOAD_CONST 2 ('x') 9 STORE_MAP 10 LOAD_CONST 3 (2) 13 LOAD_CONST 4 ('y') 16 STORE_MAP ........ r59549 | thomas.heller | 2007-12-18 20:00:34 +0100 (Tue, 18 Dec 2007) | 2 lines Issue #1642: Fix segfault in ctypes when trying to delete attributes. ........ r59551 | guido.van.rossum | 2007-12-18 21:10:42 +0100 (Tue, 18 Dec 2007) | 2 lines Issue #1645 by Alberto Bertogli. Fix a comment. ........ r59553 | raymond.hettinger | 2007-12-18 22:24:09 +0100 (Tue, 18 Dec 2007) | 12 lines Give meaning to the oparg for BUILD_MAP: estimated size of the dictionary. Allows dictionaries to be pre-sized (upto 255 elements) saving time lost to re-sizes with their attendant mallocs and re-insertions. Has zero effect on small dictionaries (5 elements or fewer), a slight benefit for dicts upto 22 elements (because they had to resize once anyway), and more benefit for dicts upto 255 elements (saving multiple resizes during the build-up and reducing the number of collisions on the first insertions). Beyond 255 elements, there is no addional benefit. ........ r59554 | christian.heimes | 2007-12-18 22:56:09 +0100 (Tue, 18 Dec 2007) | 1 line Fixed #1649: IDLE error: dictionary changed size during iteration ........ r59557 | raymond.hettinger | 2007-12-18 23:21:27 +0100 (Tue, 18 Dec 2007) | 1 line Simplify and speedup _asdict() for named tuples. ........ r59558 | christian.heimes | 2007-12-19 00:22:54 +0100 (Wed, 19 Dec 2007) | 3 lines Applied patch #1635: Float patch for inf and nan on Windows (and other platforms). The patch unifies float("inf") and repr(float("inf")) on all platforms. ........ r59559 | raymond.hettinger | 2007-12-19 00:51:15 +0100 (Wed, 19 Dec 2007) | 1 line Users demand iterable input for named tuples. The author capitulates. ........ r59560 | raymond.hettinger | 2007-12-19 01:21:06 +0100 (Wed, 19 Dec 2007) | 1 line Beef-up tests for dict literals ........ r59561 | raymond.hettinger | 2007-12-19 01:27:21 +0100 (Wed, 19 Dec 2007) | 1 line Zap a duplicate line ........
18 years ago
  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"]
  8. cmp_op = ('<', '<=', '==', '!=', '>', '>=', 'in', 'not in', 'is',
  9. 'is not', 'exception match', 'BAD')
  10. hasconst = []
  11. hasname = []
  12. hasjrel = []
  13. hasjabs = []
  14. haslocal = []
  15. hascompare = []
  16. hasfree = []
  17. opmap = {}
  18. opname = [''] * 256
  19. for op in range(256): opname[op] = '<%r>' % (op,)
  20. del op
  21. def def_op(name, op):
  22. opname[op] = name
  23. opmap[name] = op
  24. def name_op(name, op):
  25. def_op(name, op)
  26. hasname.append(op)
  27. def jrel_op(name, op):
  28. def_op(name, op)
  29. hasjrel.append(op)
  30. def jabs_op(name, op):
  31. def_op(name, op)
  32. hasjabs.append(op)
  33. # Instruction opcodes for compiled code
  34. # Blank lines correspond to available opcodes
  35. def_op('STOP_CODE', 0)
  36. def_op('POP_TOP', 1)
  37. def_op('ROT_TWO', 2)
  38. def_op('ROT_THREE', 3)
  39. def_op('DUP_TOP', 4)
  40. def_op('DUP_TOP_TWO', 5)
  41. def_op('NOP', 9)
  42. def_op('UNARY_POSITIVE', 10)
  43. def_op('UNARY_NEGATIVE', 11)
  44. def_op('UNARY_NOT', 12)
  45. def_op('UNARY_INVERT', 15)
  46. def_op('BINARY_POWER', 19)
  47. def_op('BINARY_MULTIPLY', 20)
  48. def_op('BINARY_MODULO', 22)
  49. def_op('BINARY_ADD', 23)
  50. def_op('BINARY_SUBTRACT', 24)
  51. def_op('BINARY_SUBSCR', 25)
  52. def_op('BINARY_FLOOR_DIVIDE', 26)
  53. def_op('BINARY_TRUE_DIVIDE', 27)
  54. def_op('INPLACE_FLOOR_DIVIDE', 28)
  55. def_op('INPLACE_TRUE_DIVIDE', 29)
  56. def_op('STORE_MAP', 54)
  57. def_op('INPLACE_ADD', 55)
  58. def_op('INPLACE_SUBTRACT', 56)
  59. def_op('INPLACE_MULTIPLY', 57)
  60. def_op('INPLACE_MODULO', 59)
  61. def_op('STORE_SUBSCR', 60)
  62. def_op('DELETE_SUBSCR', 61)
  63. def_op('BINARY_LSHIFT', 62)
  64. def_op('BINARY_RSHIFT', 63)
  65. def_op('BINARY_AND', 64)
  66. def_op('BINARY_XOR', 65)
  67. def_op('BINARY_OR', 66)
  68. def_op('INPLACE_POWER', 67)
  69. def_op('GET_ITER', 68)
  70. def_op('STORE_LOCALS', 69)
  71. def_op('PRINT_EXPR', 70)
  72. def_op('LOAD_BUILD_CLASS', 71)
  73. def_op('INPLACE_LSHIFT', 75)
  74. def_op('INPLACE_RSHIFT', 76)
  75. def_op('INPLACE_AND', 77)
  76. def_op('INPLACE_XOR', 78)
  77. def_op('INPLACE_OR', 79)
  78. def_op('BREAK_LOOP', 80)
  79. def_op('WITH_CLEANUP', 81)
  80. def_op('RETURN_VALUE', 83)
  81. def_op('IMPORT_STAR', 84)
  82. def_op('YIELD_VALUE', 86)
  83. def_op('POP_BLOCK', 87)
  84. def_op('END_FINALLY', 88)
  85. def_op('POP_EXCEPT', 89)
  86. HAVE_ARGUMENT = 90 # Opcodes from here have an argument:
  87. name_op('STORE_NAME', 90) # Index in name list
  88. name_op('DELETE_NAME', 91) # ""
  89. def_op('UNPACK_SEQUENCE', 92) # Number of tuple items
  90. jrel_op('FOR_ITER', 93)
  91. def_op('UNPACK_EX', 94)
  92. name_op('STORE_ATTR', 95) # Index in name list
  93. name_op('DELETE_ATTR', 96) # ""
  94. name_op('STORE_GLOBAL', 97) # ""
  95. name_op('DELETE_GLOBAL', 98) # ""
  96. def_op('LOAD_CONST', 100) # Index in const list
  97. hasconst.append(100)
  98. name_op('LOAD_NAME', 101) # Index in name list
  99. def_op('BUILD_TUPLE', 102) # Number of tuple items
  100. def_op('BUILD_LIST', 103) # Number of list items
  101. def_op('BUILD_SET', 104) # Number of set items
  102. def_op('BUILD_MAP', 105) # Number of dict entries (upto 255)
  103. name_op('LOAD_ATTR', 106) # Index in name list
  104. def_op('COMPARE_OP', 107) # Comparison operator
  105. hascompare.append(107)
  106. name_op('IMPORT_NAME', 108) # Index in name list
  107. name_op('IMPORT_FROM', 109) # Index in name list
  108. jrel_op('JUMP_FORWARD', 110) # Number of bytes to skip
  109. jabs_op('JUMP_IF_FALSE_OR_POP', 111) # Target byte offset from beginning of code
  110. jabs_op('JUMP_IF_TRUE_OR_POP', 112) # ""
  111. jabs_op('JUMP_ABSOLUTE', 113) # ""
  112. jabs_op('POP_JUMP_IF_FALSE', 114) # ""
  113. jabs_op('POP_JUMP_IF_TRUE', 115) # ""
  114. name_op('LOAD_GLOBAL', 116) # Index in name list
  115. jabs_op('CONTINUE_LOOP', 119) # Target address
  116. jrel_op('SETUP_LOOP', 120) # Distance to target address
  117. jrel_op('SETUP_EXCEPT', 121) # ""
  118. jrel_op('SETUP_FINALLY', 122) # ""
  119. def_op('LOAD_FAST', 124) # Local variable number
  120. haslocal.append(124)
  121. def_op('STORE_FAST', 125) # Local variable number
  122. haslocal.append(125)
  123. def_op('DELETE_FAST', 126) # Local variable number
  124. haslocal.append(126)
  125. def_op('RAISE_VARARGS', 130) # Number of raise arguments (1, 2, or 3)
  126. def_op('CALL_FUNCTION', 131) # #args + (#kwargs << 8)
  127. def_op('MAKE_FUNCTION', 132) # Number of args with default values
  128. def_op('BUILD_SLICE', 133) # Number of items
  129. def_op('MAKE_CLOSURE', 134)
  130. def_op('LOAD_CLOSURE', 135)
  131. hasfree.append(135)
  132. def_op('LOAD_DEREF', 136)
  133. hasfree.append(136)
  134. def_op('STORE_DEREF', 137)
  135. hasfree.append(137)
  136. def_op('DELETE_DEREF', 138)
  137. hasfree.append(138)
  138. def_op('CALL_FUNCTION_VAR', 140) # #args + (#kwargs << 8)
  139. def_op('CALL_FUNCTION_KW', 141) # #args + (#kwargs << 8)
  140. def_op('CALL_FUNCTION_VAR_KW', 142) # #args + (#kwargs << 8)
  141. jrel_op('SETUP_WITH', 143)
  142. def_op('LIST_APPEND', 145)
  143. def_op('SET_ADD', 146)
  144. def_op('MAP_ADD', 147)
  145. def_op('EXTENDED_ARG', 144)
  146. EXTENDED_ARG = 144
  147. del def_op, name_op, jrel_op, jabs_op