ยปCore Development>Code coverage>Lib/opcode.py

Python code coverage for Lib/opcode.py

#countcontent
1n/a
2n/a"""
3n/aopcode module - potentially shared between dis and other modules which
4n/aoperate on bytecodes (e.g. peephole optimizers).
5n/a"""
6n/a
7n/a__all__ = ["cmp_op", "hasconst", "hasname", "hasjrel", "hasjabs",
8n/a "haslocal", "hascompare", "hasfree", "opname", "opmap",
9n/a "HAVE_ARGUMENT", "EXTENDED_ARG", "hasnargs"]
10n/a
11n/a# It's a chicken-and-egg I'm afraid:
12n/a# We're imported before _opcode's made.
13n/a# With exception unheeded
14n/a# (stack_effect is not needed)
15n/a# Both our chickens and eggs are allayed.
16n/a# --Larry Hastings, 2013/11/23
17n/a
18n/atry:
19n/a from _opcode import stack_effect
20n/a __all__.append('stack_effect')
21n/aexcept ImportError:
22n/a pass
23n/a
24n/acmp_op = ('<', '<=', '==', '!=', '>', '>=', 'in', 'not in', 'is',
25n/a 'is not', 'exception match', 'BAD')
26n/a
27n/ahasconst = []
28n/ahasname = []
29n/ahasjrel = []
30n/ahasjabs = []
31n/ahaslocal = []
32n/ahascompare = []
33n/ahasfree = []
34n/ahasnargs = [] # unused
35n/a
36n/aopmap = {}
37n/aopname = ['<%r>' % (op,) for op in range(256)]
38n/a
39n/adef def_op(name, op):
40n/a opname[op] = name
41n/a opmap[name] = op
42n/a
43n/adef name_op(name, op):
44n/a def_op(name, op)
45n/a hasname.append(op)
46n/a
47n/adef jrel_op(name, op):
48n/a def_op(name, op)
49n/a hasjrel.append(op)
50n/a
51n/adef jabs_op(name, op):
52n/a def_op(name, op)
53n/a hasjabs.append(op)
54n/a
55n/a# Instruction opcodes for compiled code
56n/a# Blank lines correspond to available opcodes
57n/a
58n/adef_op('POP_TOP', 1)
59n/adef_op('ROT_TWO', 2)
60n/adef_op('ROT_THREE', 3)
61n/adef_op('DUP_TOP', 4)
62n/adef_op('DUP_TOP_TWO', 5)
63n/a
64n/adef_op('NOP', 9)
65n/adef_op('UNARY_POSITIVE', 10)
66n/adef_op('UNARY_NEGATIVE', 11)
67n/adef_op('UNARY_NOT', 12)
68n/a
69n/adef_op('UNARY_INVERT', 15)
70n/a
71n/adef_op('BINARY_MATRIX_MULTIPLY', 16)
72n/adef_op('INPLACE_MATRIX_MULTIPLY', 17)
73n/a
74n/adef_op('BINARY_POWER', 19)
75n/adef_op('BINARY_MULTIPLY', 20)
76n/a
77n/adef_op('BINARY_MODULO', 22)
78n/adef_op('BINARY_ADD', 23)
79n/adef_op('BINARY_SUBTRACT', 24)
80n/adef_op('BINARY_SUBSCR', 25)
81n/adef_op('BINARY_FLOOR_DIVIDE', 26)
82n/adef_op('BINARY_TRUE_DIVIDE', 27)
83n/adef_op('INPLACE_FLOOR_DIVIDE', 28)
84n/adef_op('INPLACE_TRUE_DIVIDE', 29)
85n/a
86n/adef_op('GET_AITER', 50)
87n/adef_op('GET_ANEXT', 51)
88n/adef_op('BEFORE_ASYNC_WITH', 52)
89n/a
90n/adef_op('INPLACE_ADD', 55)
91n/adef_op('INPLACE_SUBTRACT', 56)
92n/adef_op('INPLACE_MULTIPLY', 57)
93n/a
94n/adef_op('INPLACE_MODULO', 59)
95n/adef_op('STORE_SUBSCR', 60)
96n/adef_op('DELETE_SUBSCR', 61)
97n/adef_op('BINARY_LSHIFT', 62)
98n/adef_op('BINARY_RSHIFT', 63)
99n/adef_op('BINARY_AND', 64)
100n/adef_op('BINARY_XOR', 65)
101n/adef_op('BINARY_OR', 66)
102n/adef_op('INPLACE_POWER', 67)
103n/adef_op('GET_ITER', 68)
104n/adef_op('GET_YIELD_FROM_ITER', 69)
105n/a
106n/adef_op('PRINT_EXPR', 70)
107n/adef_op('LOAD_BUILD_CLASS', 71)
108n/adef_op('YIELD_FROM', 72)
109n/adef_op('GET_AWAITABLE', 73)
110n/a
111n/adef_op('INPLACE_LSHIFT', 75)
112n/adef_op('INPLACE_RSHIFT', 76)
113n/adef_op('INPLACE_AND', 77)
114n/adef_op('INPLACE_XOR', 78)
115n/adef_op('INPLACE_OR', 79)
116n/adef_op('BREAK_LOOP', 80)
117n/adef_op('WITH_CLEANUP_START', 81)
118n/adef_op('WITH_CLEANUP_FINISH', 82)
119n/a
120n/adef_op('RETURN_VALUE', 83)
121n/adef_op('IMPORT_STAR', 84)
122n/adef_op('SETUP_ANNOTATIONS', 85)
123n/adef_op('YIELD_VALUE', 86)
124n/adef_op('POP_BLOCK', 87)
125n/adef_op('END_FINALLY', 88)
126n/adef_op('POP_EXCEPT', 89)
127n/a
128n/aHAVE_ARGUMENT = 90 # Opcodes from here have an argument:
129n/a
130n/aname_op('STORE_NAME', 90) # Index in name list
131n/aname_op('DELETE_NAME', 91) # ""
132n/adef_op('UNPACK_SEQUENCE', 92) # Number of tuple items
133n/ajrel_op('FOR_ITER', 93)
134n/adef_op('UNPACK_EX', 94)
135n/aname_op('STORE_ATTR', 95) # Index in name list
136n/aname_op('DELETE_ATTR', 96) # ""
137n/aname_op('STORE_GLOBAL', 97) # ""
138n/aname_op('DELETE_GLOBAL', 98) # ""
139n/adef_op('LOAD_CONST', 100) # Index in const list
140n/ahasconst.append(100)
141n/aname_op('LOAD_NAME', 101) # Index in name list
142n/adef_op('BUILD_TUPLE', 102) # Number of tuple items
143n/adef_op('BUILD_LIST', 103) # Number of list items
144n/adef_op('BUILD_SET', 104) # Number of set items
145n/adef_op('BUILD_MAP', 105) # Number of dict entries (upto 255)
146n/aname_op('LOAD_ATTR', 106) # Index in name list
147n/adef_op('COMPARE_OP', 107) # Comparison operator
148n/ahascompare.append(107)
149n/aname_op('IMPORT_NAME', 108) # Index in name list
150n/aname_op('IMPORT_FROM', 109) # Index in name list
151n/a
152n/ajrel_op('JUMP_FORWARD', 110) # Number of bytes to skip
153n/ajabs_op('JUMP_IF_FALSE_OR_POP', 111) # Target byte offset from beginning of code
154n/ajabs_op('JUMP_IF_TRUE_OR_POP', 112) # ""
155n/ajabs_op('JUMP_ABSOLUTE', 113) # ""
156n/ajabs_op('POP_JUMP_IF_FALSE', 114) # ""
157n/ajabs_op('POP_JUMP_IF_TRUE', 115) # ""
158n/a
159n/aname_op('LOAD_GLOBAL', 116) # Index in name list
160n/a
161n/ajabs_op('CONTINUE_LOOP', 119) # Target address
162n/ajrel_op('SETUP_LOOP', 120) # Distance to target address
163n/ajrel_op('SETUP_EXCEPT', 121) # ""
164n/ajrel_op('SETUP_FINALLY', 122) # ""
165n/a
166n/adef_op('LOAD_FAST', 124) # Local variable number
167n/ahaslocal.append(124)
168n/adef_op('STORE_FAST', 125) # Local variable number
169n/ahaslocal.append(125)
170n/adef_op('DELETE_FAST', 126) # Local variable number
171n/ahaslocal.append(126)
172n/aname_op('STORE_ANNOTATION', 127) # Index in name list
173n/a
174n/adef_op('RAISE_VARARGS', 130) # Number of raise arguments (1, 2, or 3)
175n/adef_op('CALL_FUNCTION', 131) # #args
176n/adef_op('MAKE_FUNCTION', 132) # Flags
177n/adef_op('BUILD_SLICE', 133) # Number of items
178n/adef_op('LOAD_CLOSURE', 135)
179n/ahasfree.append(135)
180n/adef_op('LOAD_DEREF', 136)
181n/ahasfree.append(136)
182n/adef_op('STORE_DEREF', 137)
183n/ahasfree.append(137)
184n/adef_op('DELETE_DEREF', 138)
185n/ahasfree.append(138)
186n/a
187n/adef_op('CALL_FUNCTION_KW', 141) # #args + #kwargs
188n/adef_op('CALL_FUNCTION_EX', 142) # Flags
189n/a
190n/ajrel_op('SETUP_WITH', 143)
191n/a
192n/adef_op('LIST_APPEND', 145)
193n/adef_op('SET_ADD', 146)
194n/adef_op('MAP_ADD', 147)
195n/a
196n/adef_op('LOAD_CLASSDEREF', 148)
197n/ahasfree.append(148)
198n/a
199n/adef_op('EXTENDED_ARG', 144)
200n/aEXTENDED_ARG = 144
201n/a
202n/adef_op('BUILD_LIST_UNPACK', 149)
203n/adef_op('BUILD_MAP_UNPACK', 150)
204n/adef_op('BUILD_MAP_UNPACK_WITH_CALL', 151)
205n/adef_op('BUILD_TUPLE_UNPACK', 152)
206n/adef_op('BUILD_SET_UNPACK', 153)
207n/a
208n/ajrel_op('SETUP_ASYNC_WITH', 154)
209n/a
210n/adef_op('FORMAT_VALUE', 155)
211n/adef_op('BUILD_CONST_KEY_MAP', 156)
212n/adef_op('BUILD_STRING', 157)
213n/adef_op('BUILD_TUPLE_UNPACK_WITH_CALL', 158)
214n/a
215n/aname_op('LOAD_METHOD', 160)
216n/adef_op('CALL_METHOD', 161)
217n/a
218n/adel def_op, name_op, jrel_op, jabs_op