source: vendor/python/2.5/Lib/opcode.py@ 3393

Last change on this file since 3393 was 3225, checked in by bird, 19 years ago

Python 2.5

File size: 5.1 KB
RevLine 
[3225]1
2"""
3opcode module - potentially shared between dis and other modules which
4operate on bytecodes (e.g. peephole optimizers).
5"""
6
7__all__ = ["cmp_op", "hasconst", "hasname", "hasjrel", "hasjabs",
8 "haslocal", "hascompare", "hasfree", "opname", "opmap",
9 "HAVE_ARGUMENT", "EXTENDED_ARG"]
10
11cmp_op = ('<', '<=', '==', '!=', '>', '>=', 'in', 'not in', 'is',
12 'is not', 'exception match', 'BAD')
13
14hasconst = []
15hasname = []
16hasjrel = []
17hasjabs = []
18haslocal = []
19hascompare = []
20hasfree = []
21
22opmap = {}
23opname = [''] * 256
24for op in range(256): opname[op] = '<%r>' % (op,)
25del op
26
27def def_op(name, op):
28 opname[op] = name
29 opmap[name] = op
30
31def name_op(name, op):
32 def_op(name, op)
33 hasname.append(op)
34
35def jrel_op(name, op):
36 def_op(name, op)
37 hasjrel.append(op)
38
39def jabs_op(name, op):
40 def_op(name, op)
41 hasjabs.append(op)
42
43# Instruction opcodes for compiled code
44# Blank lines correspond to available opcodes
45
46def_op('STOP_CODE', 0)
47def_op('POP_TOP', 1)
48def_op('ROT_TWO', 2)
49def_op('ROT_THREE', 3)
50def_op('DUP_TOP', 4)
51def_op('ROT_FOUR', 5)
52
53def_op('NOP', 9)
54def_op('UNARY_POSITIVE', 10)
55def_op('UNARY_NEGATIVE', 11)
56def_op('UNARY_NOT', 12)
57def_op('UNARY_CONVERT', 13)
58
59def_op('UNARY_INVERT', 15)
60
61def_op('LIST_APPEND', 18)
62def_op('BINARY_POWER', 19)
63def_op('BINARY_MULTIPLY', 20)
64def_op('BINARY_DIVIDE', 21)
65def_op('BINARY_MODULO', 22)
66def_op('BINARY_ADD', 23)
67def_op('BINARY_SUBTRACT', 24)
68def_op('BINARY_SUBSCR', 25)
69def_op('BINARY_FLOOR_DIVIDE', 26)
70def_op('BINARY_TRUE_DIVIDE', 27)
71def_op('INPLACE_FLOOR_DIVIDE', 28)
72def_op('INPLACE_TRUE_DIVIDE', 29)
73def_op('SLICE+0', 30)
74def_op('SLICE+1', 31)
75def_op('SLICE+2', 32)
76def_op('SLICE+3', 33)
77
78def_op('STORE_SLICE+0', 40)
79def_op('STORE_SLICE+1', 41)
80def_op('STORE_SLICE+2', 42)
81def_op('STORE_SLICE+3', 43)
82
83def_op('DELETE_SLICE+0', 50)
84def_op('DELETE_SLICE+1', 51)
85def_op('DELETE_SLICE+2', 52)
86def_op('DELETE_SLICE+3', 53)
87
88def_op('INPLACE_ADD', 55)
89def_op('INPLACE_SUBTRACT', 56)
90def_op('INPLACE_MULTIPLY', 57)
91def_op('INPLACE_DIVIDE', 58)
92def_op('INPLACE_MODULO', 59)
93def_op('STORE_SUBSCR', 60)
94def_op('DELETE_SUBSCR', 61)
95def_op('BINARY_LSHIFT', 62)
96def_op('BINARY_RSHIFT', 63)
97def_op('BINARY_AND', 64)