2003-02-28 05:27:52 +08:00
|
|
|
|
|
|
|
"""
|
|
|
|
opcode module - potentially shared between dis and other modules which
|
|
|
|
operate on bytecodes (e.g. peephole optimizers).
|
|
|
|
"""
|
|
|
|
|
|
|
|
__all__ = ["cmp_op", "hasconst", "hasname", "hasjrel", "hasjabs",
|
|
|
|
"haslocal", "hascompare", "hasfree", "opname", "opmap",
|
2012-06-08 02:28:14 +08:00
|
|
|
"HAVE_ARGUMENT", "EXTENDED_ARG", "hasnargs"]
|
2003-02-28 05:27:52 +08:00
|
|
|
|
2013-11-24 06:49:22 +08:00
|
|
|
# It's a chicken-and-egg I'm afraid:
|
|
|
|
# We're imported before _opcode's made.
|
|
|
|
# With exception unheeded
|
|
|
|
# (stack_effect is not needed)
|
|
|
|
# Both our chickens and eggs are allayed.
|
|
|
|
# --Larry Hastings, 2013/11/23
|
|
|
|
|
|
|
|
try:
|
|
|
|
from _opcode import stack_effect
|
|
|
|
__all__.append('stack_effect')
|
|
|
|
except ImportError:
|
|
|
|
pass
|
|
|
|
|
2003-02-28 05:27:52 +08:00
|
|
|
cmp_op = ('<', '<=', '==', '!=', '>', '>=', 'in', 'not in', 'is',
|
|
|
|
'is not', 'exception match', 'BAD')
|
|
|
|
|
|
|
|
hasconst = []
|
|
|
|
hasname = []
|
|
|
|
hasjrel = []
|
|
|
|
hasjabs = []
|
|
|
|
haslocal = []
|
|
|
|
hascompare = []
|
|
|
|
hasfree = []
|
2012-06-08 02:28:14 +08:00
|
|
|
hasnargs = []
|
2003-02-28 05:27:52 +08:00
|
|
|
|
|
|
|
opmap = {}
|
|
|
|
opname = [''] * 256
|
2004-02-13 01:35:32 +08:00
|
|
|
for op in range(256): opname[op] = '<%r>' % (op,)
|
2003-02-28 05:27:52 +08:00
|
|
|
del op
|
|
|
|
|
|
|
|
def def_op(name, op):
|
|
|
|
opname[op] = name
|
|
|
|
opmap[name] = op
|
|
|
|
|
|
|
|
def name_op(name, op):
|
|
|
|
def_op(name, op)
|
|
|
|
hasname.append(op)
|
|
|
|
|
|
|
|
def jrel_op(name, op):
|
|
|
|
def_op(name, op)
|
|
|
|
hasjrel.append(op)
|
|
|
|
|
|
|
|
def jabs_op(name, op):
|
|
|
|
def_op(name, op)
|
|
|
|
hasjabs.append(op)
|
|
|
|
|
|
|
|
# Instruction opcodes for compiled code
|
2006-02-28 06:32:47 +08:00
|
|
|
# Blank lines correspond to available opcodes
|
2003-02-28 05:27:52 +08:00
|
|
|
|
|
|
|
def_op('POP_TOP', 1)
|
|
|
|
def_op('ROT_TWO', 2)
|
|
|
|
def_op('ROT_THREE', 3)
|
|
|
|
def_op('DUP_TOP', 4)
|
2010-09-05 02:43:52 +08:00
|
|
|
def_op('DUP_TOP_TWO', 5)
|
2003-02-28 05:27:52 +08:00
|
|
|
|
2004-06-22 00:31:15 +08:00
|
|
|
def_op('NOP', 9)
|
2003-02-28 05:27:52 +08:00
|
|
|
def_op('UNARY_POSITIVE', 10)
|
|
|
|
def_op('UNARY_NEGATIVE', 11)
|
|
|
|
def_op('UNARY_NOT', 12)
|
|
|
|
|
|
|
|
def_op('UNARY_INVERT', 15)
|
|
|
|
|
2014-04-10 11:55:56 +08:00
|
|
|
def_op('BINARY_MATRIX_MULTIPLY', 16)
|
|
|
|
def_op('INPLACE_MATRIX_MULTIPLY', 17)
|
|
|
|
|
2003-02-28 05:27:52 +08:00
|
|
|
def_op('BINARY_POWER', 19)
|
|
|
|
def_op('BINARY_MULTIPLY', 20)
|
2006-03-16 14:02:10 +08:00
|
|
|
|
2003-02-28 05:27:52 +08:00
|
|
|
def_op('BINARY_MODULO', 22)
|
|
|
|
def_op('BINARY_ADD', 23)
|
|
|
|
def_op('BINARY_SUBTRACT', 24)
|
|
|
|
def_op('BINARY_SUBSCR', 25)
|
|
|
|
def_op('BINARY_FLOOR_DIVIDE', 26)
|
|
|
|
def_op('BINARY_TRUE_DIVIDE', 27)
|
|
|
|
def_op('INPLACE_FLOOR_DIVIDE', 28)
|
|
|
|
def_op('INPLACE_TRUE_DIVIDE', 29)
|
|
|
|
|
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
........
2007-12-19 10:07:34 +08:00
|
|
|
def_op('STORE_MAP', 54)
|
2003-02-28 05:27:52 +08:00
|
|
|
def_op('INPLACE_ADD', 55)
|
|
|
|
def_op('INPLACE_SUBTRACT', 56)
|
|
|
|
def_op('INPLACE_MULTIPLY', 57)
|
2006-03-17 16:59:09 +08:00
|
|
|
|
2003-02-28 05:27:52 +08:00
|
|
|
def_op('INPLACE_MODULO', 59)
|
|
|
|
def_op('STORE_SUBSCR', 60)
|
|
|
|
def_op('DELETE_SUBSCR', 61)
|
|
|
|
def_op('BINARY_LSHIFT', 62)
|
|
|
|
def_op('BINARY_RSHIFT', 63)
|
|
|
|
def_op('BINARY_AND', 64)
|
|
|
|
def_op('BINARY_XOR', 65)
|
|
|
|
def_op('BINARY_OR', 66)
|
|
|
|
def_op('INPLACE_POWER', 67)
|
|
|
|
def_op('GET_ITER', 68)
|
|
|
|
|
|
|
|
def_op('PRINT_EXPR', 70)
|
2007-03-18 23:41:51 +08:00
|
|
|
def_op('LOAD_BUILD_CLASS', 71)
|
2012-01-13 19:43:40 +08:00
|
|
|
def_op('YIELD_FROM', 72)
|
* Remove PRINT_ITEM(_TO), PRINT_NEWLINE(_TO) opcodes.
* Fix some docstrings and one Print -> print.
* Fix test_{class,code,descrtut,dis,extcall,parser,popen,pkg,subprocess,syntax,traceback}.
These were the ones that generated code with a print statement.
In most remaining failing tests there's an issue with the soft space.
2007-02-10 05:28:07 +08:00
|
|
|
|
2003-02-28 05:27:52 +08:00
|
|
|
def_op('INPLACE_LSHIFT', 75)
|
|
|
|
def_op('INPLACE_RSHIFT', 76)
|
|
|
|
def_op('INPLACE_AND', 77)
|
|
|
|
def_op('INPLACE_XOR', 78)
|
|
|
|
def_op('INPLACE_OR', 79)
|
|
|
|
def_op('BREAK_LOOP', 80)
|
2006-02-28 06:32:47 +08:00
|
|
|
def_op('WITH_CLEANUP', 81)
|
2007-03-18 23:41:51 +08:00
|
|
|
|
2003-02-28 05:27:52 +08:00
|
|
|
def_op('RETURN_VALUE', 83)
|
|
|
|
def_op('IMPORT_STAR', 84)
|
2008-07-21 05:38:50 +08:00
|
|
|
|
2003-02-28 05:27:52 +08:00
|
|
|
def_op('YIELD_VALUE', 86)
|
|
|
|
def_op('POP_BLOCK', 87)
|
|
|
|
def_op('END_FINALLY', 88)
|
2008-06-11 23:59:43 +08:00
|
|
|
def_op('POP_EXCEPT', 89)
|
2003-02-28 05:27:52 +08:00
|
|
|
|
|
|
|
HAVE_ARGUMENT = 90 # Opcodes from here have an argument:
|
|
|
|
|
|
|
|
name_op('STORE_NAME', 90) # Index in name list
|
|
|
|
name_op('DELETE_NAME', 91) # ""
|
|
|
|
def_op('UNPACK_SEQUENCE', 92) # Number of tuple items
|
|
|
|
jrel_op('FOR_ITER', 93)
|
2008-03-19 04:13:50 +08:00
|
|
|
def_op('UNPACK_EX', 94)
|
2003-02-28 05:27:52 +08:00
|
|
|
name_op('STORE_ATTR', 95) # Index in name list
|
|
|
|
name_op('DELETE_ATTR', 96) # ""
|
|
|
|
name_op('STORE_GLOBAL', 97) # ""
|
|
|
|
name_op('DELETE_GLOBAL', 98) # ""
|
|
|
|
def_op('LOAD_CONST', 100) # Index in const list
|
|
|
|
hasconst.append(100)
|
|
|
|
name_op('LOAD_NAME', 101) # Index in name list
|
|
|
|
def_op('BUILD_TUPLE', 102) # Number of tuple items
|
|
|
|
def_op('BUILD_LIST', 103) # Number of list items
|
2006-08-28 23:27:34 +08:00
|
|
|
def_op('BUILD_SET', 104) # Number of set items
|
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
........
2007-12-19 10:07:34 +08:00
|
|
|
def_op('BUILD_MAP', 105) # Number of dict entries (upto 255)
|
2006-08-28 23:27:34 +08:00
|
|
|
name_op('LOAD_ATTR', 106) # Index in name list
|
|
|
|
def_op('COMPARE_OP', 107) # Comparison operator
|
|
|
|
hascompare.append(107)
|
|
|
|
name_op('IMPORT_NAME', 108) # Index in name list
|
|
|
|
name_op('IMPORT_FROM', 109) # Index in name list
|
2003-02-28 05:27:52 +08:00
|
|
|
|
|
|
|
jrel_op('JUMP_FORWARD', 110) # Number of bytes to skip
|
2009-02-25 10:25:04 +08:00
|
|
|
jabs_op('JUMP_IF_FALSE_OR_POP', 111) # Target byte offset from beginning of code
|
|
|
|
jabs_op('JUMP_IF_TRUE_OR_POP', 112) # ""
|
|
|
|
jabs_op('JUMP_ABSOLUTE', 113) # ""
|
|
|
|
jabs_op('POP_JUMP_IF_FALSE', 114) # ""
|
|
|
|
jabs_op('POP_JUMP_IF_TRUE', 115) # ""
|
2003-02-28 05:27:52 +08:00
|
|
|
|
|
|
|
name_op('LOAD_GLOBAL', 116) # Index in name list
|
|
|
|
|
|
|
|
jabs_op('CONTINUE_LOOP', 119) # Target address
|
|
|
|
jrel_op('SETUP_LOOP', 120) # Distance to target address
|
|
|
|
jrel_op('SETUP_EXCEPT', 121) # ""
|
|
|
|
jrel_op('SETUP_FINALLY', 122) # ""
|
|
|
|
|
|
|
|
def_op('LOAD_FAST', 124) # Local variable number
|
|
|
|
haslocal.append(124)
|
|
|
|
def_op('STORE_FAST', 125) # Local variable number
|
|
|
|
haslocal.append(125)
|
|
|
|
def_op('DELETE_FAST', 126) # Local variable number
|
|
|
|
haslocal.append(126)
|
|
|
|
|
|
|
|
def_op('RAISE_VARARGS', 130) # Number of raise arguments (1, 2, or 3)
|
|
|
|
def_op('CALL_FUNCTION', 131) # #args + (#kwargs << 8)
|
2012-06-08 02:28:14 +08:00
|
|
|
hasnargs.append(131)
|
2003-02-28 05:27:52 +08:00
|
|
|
def_op('MAKE_FUNCTION', 132) # Number of args with default values
|
|
|
|
def_op('BUILD_SLICE', 133) # Number of items
|
|
|
|
def_op('MAKE_CLOSURE', 134)
|
|
|
|
def_op('LOAD_CLOSURE', 135)
|
|
|
|
hasfree.append(135)
|
|
|
|
def_op('LOAD_DEREF', 136)
|
|
|
|
hasfree.append(136)
|
|
|
|
def_op('STORE_DEREF', 137)
|
|
|
|
hasfree.append(137)
|
2010-09-11 05:39:53 +08:00
|
|
|
def_op('DELETE_DEREF', 138)
|
|
|
|
hasfree.append(138)
|
2003-02-28 05:27:52 +08:00
|
|
|
|
|
|
|
def_op('CALL_FUNCTION_VAR', 140) # #args + (#kwargs << 8)
|
2012-06-08 02:28:14 +08:00
|
|
|
hasnargs.append(140)
|
2003-02-28 05:27:52 +08:00
|
|
|
def_op('CALL_FUNCTION_KW', 141) # #args + (#kwargs << 8)
|
2012-06-08 02:28:14 +08:00
|
|
|
hasnargs.append(141)
|
2003-02-28 05:27:52 +08:00
|
|
|
def_op('CALL_FUNCTION_VAR_KW', 142) # #args + (#kwargs << 8)
|
2012-06-08 02:28:14 +08:00
|
|
|
hasnargs.append(142)
|
2009-06-28 11:18:59 +08:00
|
|
|
|
|
|
|
jrel_op('SETUP_WITH', 143)
|
2003-02-28 05:27:52 +08:00
|
|
|
|
2008-12-18 19:06:25 +08:00
|
|
|
def_op('LIST_APPEND', 145)
|
|
|
|
def_op('SET_ADD', 146)
|
|
|
|
def_op('MAP_ADD', 147)
|
|
|
|
|
2013-04-30 21:41:40 +08:00
|
|
|
def_op('LOAD_CLASSDEREF', 148)
|
|
|
|
hasfree.append(148)
|
|
|
|
|
2009-06-28 11:18:59 +08:00
|
|
|
def_op('EXTENDED_ARG', 144)
|
|
|
|
EXTENDED_ARG = 144
|
2008-12-18 19:06:25 +08:00
|
|
|
|
2003-02-28 05:27:52 +08:00
|
|
|
del def_op, name_op, jrel_op, jabs_op
|