Mercurial > cpython-lru_cache-weakref
annotate Lib/dis.py @ 27998:e27f58a50737 legacy-trunk
SF bug #690377: Dud footnote reference in distutils docs
| author | Raymond Hettinger <python@rcn.com> |
|---|---|
| date | Fri, 21 Feb 2003 02:47:09 +0000 |
| parents | be2868a63ed5 |
| children | 12bab87a3dd2 |
| rev | line source |
|---|---|
|
6592
14025a4f793e
Added docstrings (contributed by Martin von Loewis).
Guido van Rossum <guido@python.org>
parents:
5475
diff
changeset
|
1 """Disassembler of Python byte code into mnemonics.""" |
| 103 | 2 |
| 3 import sys | |
|
5189
bab9196a8f30
Support disassembly of a variety of objects through dis.dis().
Guido van Rossum <guido@python.org>
parents:
4989
diff
changeset
|
4 import types |
| 103 | 5 |
|
16070
b5345e99596b
added __all__ lists to a number of Python modules
Skip Montanaro <skip@pobox.com>
parents:
16012
diff
changeset
|
6 __all__ = ["dis","disassemble","distb","disco","opname","cmp_op", |
|
b5345e99596b
added __all__ lists to a number of Python modules
Skip Montanaro <skip@pobox.com>
parents:
16012
diff
changeset
|
7 "hasconst","hasname","hasjrel","hasjabs","haslocal", |
|
16260
20ef849ec877
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
8 "hascompare", "hasfree"] |
|
16070
b5345e99596b
added __all__ lists to a number of Python modules
Skip Montanaro <skip@pobox.com>
parents:
16012
diff
changeset
|
9 |
|
4988
df385cc0d2e3
More user friedly interface:
Guido van Rossum <guido@python.org>
parents:
4974
diff
changeset
|
10 def dis(x=None): |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
11 """Disassemble classes, methods, functions, or code. |
|
6592
14025a4f793e
Added docstrings (contributed by Martin von Loewis).
Guido van Rossum <guido@python.org>
parents:
5475
diff
changeset
|
12 |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
13 With no argument, disassemble the last traceback. |
|
6592
14025a4f793e
Added docstrings (contributed by Martin von Loewis).
Guido van Rossum <guido@python.org>
parents:
5475
diff
changeset
|
14 |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
15 """ |
|
23611
21b1d742e4a7
Replaced boolean test with 'is None'
Raymond Hettinger <python@rcn.com>
parents:
21924
diff
changeset
|
16 if x is None: |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
17 distb() |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
18 return |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
19 if type(x) is types.InstanceType: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
20 x = x.__class__ |
|
16012
8e4dfb681689
Checking in a slight variation of Barry's patch 103303.
Guido van Rossum <guido@python.org>
parents:
15867
diff
changeset
|
21 if hasattr(x, 'im_func'): |
|
8e4dfb681689
Checking in a slight variation of Barry's patch 103303.
Guido van Rossum <guido@python.org>
parents:
15867
diff
changeset
|
22 x = x.im_func |
|
8e4dfb681689
Checking in a slight variation of Barry's patch 103303.
Guido van Rossum <guido@python.org>
parents:
15867
diff
changeset
|
23 if hasattr(x, 'func_code'): |
|
8e4dfb681689
Checking in a slight variation of Barry's patch 103303.
Guido van Rossum <guido@python.org>
parents:
15867
diff
changeset
|
24 x = x.func_code |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
25 if hasattr(x, '__dict__'): |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
26 items = x.__dict__.items() |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
27 items.sort() |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
28 for name, x1 in items: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
29 if type(x1) in (types.MethodType, |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
30 types.FunctionType, |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
31 types.CodeType): |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
32 print "Disassembly of %s:" % name |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
33 try: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
34 dis(x1) |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
35 except TypeError, msg: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
36 print "Sorry:", msg |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
37 print |
|
16012
8e4dfb681689
Checking in a slight variation of Barry's patch 103303.
Guido van Rossum <guido@python.org>
parents:
15867
diff
changeset
|
38 elif hasattr(x, 'co_code'): |
|
8e4dfb681689
Checking in a slight variation of Barry's patch 103303.
Guido van Rossum <guido@python.org>
parents:
15867
diff
changeset
|
39 disassemble(x) |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
40 else: |
|
16012
8e4dfb681689
Checking in a slight variation of Barry's patch 103303.
Guido van Rossum <guido@python.org>
parents:
15867
diff
changeset
|
41 raise TypeError, \ |
|
8e4dfb681689
Checking in a slight variation of Barry's patch 103303.
Guido van Rossum <guido@python.org>
parents:
15867
diff
changeset
|
42 "don't know how to disassemble %s objects" % \ |
|
8e4dfb681689
Checking in a slight variation of Barry's patch 103303.
Guido van Rossum <guido@python.org>
parents:
15867
diff
changeset
|
43 type(x).__name__ |
| 103 | 44 |
|
4988
df385cc0d2e3
More user friedly interface:
Guido van Rossum <guido@python.org>
parents:
4974
diff
changeset
|
45 def distb(tb=None): |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
46 """Disassemble a traceback (default: last traceback).""" |
|
23611
21b1d742e4a7
Replaced boolean test with 'is None'
Raymond Hettinger <python@rcn.com>
parents:
21924
diff
changeset
|
47 if tb is None: |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
48 try: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
49 tb = sys.last_traceback |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
50 except AttributeError: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
51 raise RuntimeError, "no last traceback to disassemble" |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
52 while tb.tb_next: tb = tb.tb_next |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
53 disassemble(tb.tb_frame.f_code, tb.tb_lasti) |
| 103 | 54 |
|
4988
df385cc0d2e3
More user friedly interface:
Guido van Rossum <guido@python.org>
parents:
4974
diff
changeset
|
55 def disassemble(co, lasti=-1): |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
56 """Disassemble a code object.""" |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
57 code = co.co_code |
| 24844 | 58 |
| 59 byte_increments = [ord(c) for c in co.co_lnotab[0::2]] | |
| 60 line_increments = [ord(c) for c in co.co_lnotab[1::2]] | |
| 61 table_length = len(byte_increments) # == len(line_increments) | |
| 62 | |
| 63 lineno = co.co_firstlineno | |
| 64 table_index = 0 | |
| 65 while (table_index < table_length | |
| 66 and byte_increments[table_index] == 0): | |
| 67 lineno += line_increments[table_index] | |
| 68 table_index += 1 | |
| 69 addr = 0 | |
| 70 line_incr = 0 | |
|
25003
c744144c4049
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
24844
diff
changeset
|
71 |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
72 labels = findlabels(code) |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
73 n = len(code) |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
74 i = 0 |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
75 extended_arg = 0 |
|
16260
20ef849ec877
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
76 free = None |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
77 while i < n: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
78 c = code[i] |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
79 op = ord(c) |
| 24844 | 80 |
| 81 if i >= addr: | |
| 82 lineno += line_incr | |
| 83 while table_index < table_length: | |
| 84 addr += byte_increments[table_index] | |
| 85 line_incr = line_increments[table_index] | |
| 86 table_index += 1 | |
| 87 if line_incr: | |
| 88 break | |
| 89 else: | |
| 90 addr = sys.maxint | |
| 91 if i > 0: | |
| 92 print | |
| 93 print "%3d"%lineno, | |
| 94 else: | |
| 95 print ' ', | |
| 96 | |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
97 if i == lasti: print '-->', |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
98 else: print ' ', |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
99 if i in labels: print '>>', |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
100 else: print ' ', |
|
16492
fc4ace0242cb
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16398
diff
changeset
|
101 print `i`.rjust(4), |
|
fc4ace0242cb
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16398
diff
changeset
|
102 print opname[op].ljust(20), |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
103 i = i+1 |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
104 if op >= HAVE_ARGUMENT: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
105 oparg = ord(code[i]) + ord(code[i+1])*256 + extended_arg |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
106 extended_arg = 0 |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
107 i = i+2 |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
108 if op == EXTENDED_ARG: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
109 extended_arg = oparg*65536L |
|
16492
fc4ace0242cb
String method conversion.
Eric S. Raymond <esr@thyrsus.com>
parents:
16398
diff
changeset
|
110 print `oparg`.rjust(5), |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
111 if op in hasconst: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
112 print '(' + `co.co_consts[oparg]` + ')', |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
113 elif op in hasname: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
114 print '(' + co.co_names[oparg] + ')', |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
115 elif op in hasjrel: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
116 print '(to ' + `i + oparg` + ')', |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
117 elif op in haslocal: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
118 print '(' + co.co_varnames[oparg] + ')', |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
119 elif op in hascompare: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
120 print '(' + cmp_op[oparg] + ')', |
|
16260
20ef849ec877
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
121 elif op in hasfree: |
|
20ef849ec877
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
122 if free is None: |
|
20ef849ec877
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
123 free = co.co_cellvars + co.co_freevars |
|
20ef849ec877
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
124 print '(' + free[oparg] + ')', |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
125 print |
| 103 | 126 |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
127 disco = disassemble # XXX For backwards compatibility |
|
4988
df385cc0d2e3
More user friedly interface:
Guido van Rossum <guido@python.org>
parents:
4974
diff
changeset
|
128 |
| 103 | 129 def findlabels(code): |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
130 """Detect all offsets in a byte code which are jump targets. |
|
6592
14025a4f793e
Added docstrings (contributed by Martin von Loewis).
Guido van Rossum <guido@python.org>
parents:
5475
diff
changeset
|
131 |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
132 Return the list of offsets. |
|
6592
14025a4f793e
Added docstrings (contributed by Martin von Loewis).
Guido van Rossum <guido@python.org>
parents:
5475
diff
changeset
|
133 |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
134 """ |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
135 labels = [] |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
136 n = len(code) |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
137 i = 0 |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
138 while i < n: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
139 c = code[i] |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
140 op = ord(c) |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
141 i = i+1 |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
142 if op >= HAVE_ARGUMENT: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
143 oparg = ord(code[i]) + ord(code[i+1])*256 |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
144 i = i+2 |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
145 label = -1 |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
146 if op in hasjrel: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
147 label = i+oparg |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
148 elif op in hasjabs: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
149 label = oparg |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
150 if label >= 0: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
151 if label not in labels: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
152 labels.append(label) |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
153 return labels |
| 103 | 154 |
| 4974 | 155 cmp_op = ('<', '<=', '==', '!=', '>', '>=', 'in', 'not in', 'is', |
| 156 'is not', 'exception match', 'BAD') | |
| 157 | |
| 103 | 158 hasconst = [] |
| 159 hasname = [] | |
| 160 hasjrel = [] | |
| 161 hasjabs = [] | |
|
4303
388f9c2220ce
Show names of locals in disco (Ka-Ping Yee)
Guido van Rossum <guido@python.org>
parents:
4271
diff
changeset
|
162 haslocal = [] |
| 4974 | 163 hascompare = [] |
|
16260
20ef849ec877
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
164 hasfree = [] |
| 103 | 165 |
|
1403
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1264
diff
changeset
|
166 opname = [''] * 256 |
|
6278933d02e3
* string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents:
1264
diff
changeset
|
167 for op in range(256): opname[op] = '<' + `op` + '>' |
|
21924
87aff648d994
SF #515009, delete global variable that was apparently used only
Neal Norwitz <nnorwitz@gmail.com>
parents:
19556
diff
changeset
|
168 del op |
| 103 | 169 |
| 170 def def_op(name, op): | |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
171 opname[op] = name |
| 103 | 172 |
| 173 def name_op(name, op): | |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
174 opname[op] = name |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
175 hasname.append(op) |
| 103 | 176 |
| 177 def jrel_op(name, op): | |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
178 opname[op] = name |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
179 hasjrel.append(op) |
| 103 | 180 |
| 181 def jabs_op(name, op): | |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
182 opname[op] = name |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
183 hasjabs.append(op) |
| 103 | 184 |
| 185 # Instruction opcodes for compiled code | |
| 186 | |
| 187 def_op('STOP_CODE', 0) | |
| 188 def_op('POP_TOP', 1) | |
| 189 def_op('ROT_TWO', 2) | |
| 190 def_op('ROT_THREE', 3) | |
| 191 def_op('DUP_TOP', 4) | |
|
14171
c56372ad9343
Add missing opcodes. Thanx to jeremy for reminding me ;)
Thomas Wouters <thomas@python.org>
parents:
14164
diff
changeset
|
192 def_op('ROT_FOUR', 5) |
| 103 | 193 |
| 194 def_op('UNARY_POSITIVE', 10) | |
| 195 def_op('UNARY_NEGATIVE', 11) | |
| 196 def_op('UNARY_NOT', 12) | |
| 197 def_op('UNARY_CONVERT', 13) | |
| 5475 | 198 |
|
1264
6c58dc1d2f9d
Updated because of new opcodes introduced for "fast" local variables.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
199 def_op('UNARY_INVERT', 15) |
| 103 | 200 |
|
3753
97d2278a331b
New opcodes BINARY_POWER, RAISE_VARARGS, CALL_FUNCTION, MAKE_FUNCTION
Guido van Rossum <guido@python.org>
parents:
1746
diff
changeset
|
201 def_op('BINARY_POWER', 19) |
| 5475 | 202 |
| 103 | 203 def_op('BINARY_MULTIPLY', 20) |
| 204 def_op('BINARY_DIVIDE', 21) | |
| 205 def_op('BINARY_MODULO', 22) | |
| 206 def_op('BINARY_ADD', 23) | |
| 207 def_op('BINARY_SUBTRACT', 24) | |
| 208 def_op('BINARY_SUBSCR', 25) | |
|
19556
37e0b0fcca54
Add opcodes for floor division and true division (PEP 238)
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19530
diff
changeset
|
209 def_op('BINARY_FLOOR_DIVIDE', 26) |
|
37e0b0fcca54
Add opcodes for floor division and true division (PEP 238)
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19530
diff
changeset
|
210 def_op('BINARY_TRUE_DIVIDE', 27) |
|
37e0b0fcca54
Add opcodes for floor division and true division (PEP 238)
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19530
diff
changeset
|
211 def_op('INPLACE_FLOOR_DIVIDE', 28) |
|
37e0b0fcca54
Add opcodes for floor division and true division (PEP 238)
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
19530
diff
changeset
|
212 def_op('INPLACE_TRUE_DIVIDE', 29) |
| 103 | 213 |
| 214 def_op('SLICE+0', 30) | |
| 215 def_op('SLICE+1', 31) | |
| 216 def_op('SLICE+2', 32) | |
| 217 def_op('SLICE+3', 33) | |
| 218 | |
| 219 def_op('STORE_SLICE+0', 40) | |
| 220 def_op('STORE_SLICE+1', 41) | |
| 221 def_op('STORE_SLICE+2', 42) | |
| 222 def_op('STORE_SLICE+3', 43) | |
| 223 | |
| 224 def_op('DELETE_SLICE+0', 50) | |
| 225 def_op('DELETE_SLICE+1', 51) | |
| 226 def_op('DELETE_SLICE+2', 52) | |
| 227 def_op('DELETE_SLICE+3', 53) | |
| 228 | |
|
14164
dba4aec970e6
Support for augmented assignment in the UserList, UserDict, UserString and
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
229 def_op('INPLACE_ADD', 55) |
|
dba4aec970e6
Support for augmented assignment in the UserList, UserDict, UserString and
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
230 def_op('INPLACE_SUBTRACT', 56) |
|
dba4aec970e6
Support for augmented assignment in the UserList, UserDict, UserString and
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
231 def_op('INPLACE_MULTIPLY', 57) |
|
dba4aec970e6
Support for augmented assignment in the UserList, UserDict, UserString and
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
232 def_op('INPLACE_DIVIDE', 58) |
|
dba4aec970e6
Support for augmented assignment in the UserList, UserDict, UserString and
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
233 def_op('INPLACE_MODULO', 59) |
| 103 | 234 def_op('STORE_SUBSCR', 60) |
| 235 def_op('DELETE_SUBSCR', 61) | |
| 5475 | 236 |
| 4974 | 237 def_op('BINARY_LSHIFT', 62) |
| 238 def_op('BINARY_RSHIFT', 63) | |
| 239 def_op('BINARY_AND', 64) | |
| 240 def_op('BINARY_XOR', 65) | |
| 241 def_op('BINARY_OR', 66) | |
|
14164
dba4aec970e6
Support for augmented assignment in the UserList, UserDict, UserString and
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
242 def_op('INPLACE_POWER', 67) |
|
17597
32e7d0898eab
Iterators phase 1. This comprises:
Guido van Rossum <guido@python.org>
parents:
16492
diff
changeset
|
243 def_op('GET_ITER', 68) |
| 103 | 244 |
| 245 def_op('PRINT_EXPR', 70) | |
| 246 def_op('PRINT_ITEM', 71) | |
| 247 def_op('PRINT_NEWLINE', 72) | |
|
14106
4dac9e3149be
Add the new PRINT_ITEM_TO and PRINT_NEWLINE_TO opcodes.
Barry Warsaw <barry@python.org>
parents:
14038
diff
changeset
|
248 def_op('PRINT_ITEM_TO', 73) |
|
4dac9e3149be
Add the new PRINT_ITEM_TO and PRINT_NEWLINE_TO opcodes.
Barry Warsaw <barry@python.org>
parents:
14038
diff
changeset
|
249 def_op('PRINT_NEWLINE_TO', 74) |
|
14164
dba4aec970e6
Support for augmented assignment in the UserList, UserDict, UserString and
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
250 def_op('INPLACE_LSHIFT', 75) |
|
dba4aec970e6
Support for augmented assignment in the UserList, UserDict, UserString and
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
251 def_op('INPLACE_RSHIFT', 76) |
|
dba4aec970e6
Support for augmented assignment in the UserList, UserDict, UserString and
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
252 def_op('INPLACE_AND', 77) |
|
dba4aec970e6
Support for augmented assignment in the UserList, UserDict, UserString and
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
253 def_op('INPLACE_XOR', 78) |
|
dba4aec970e6
Support for augmented assignment in the UserList, UserDict, UserString and
Thomas Wouters <thomas@python.org>
parents:
14147
diff
changeset
|
254 def_op('INPLACE_OR', 79) |
| 103 | 255 def_op('BREAK_LOOP', 80) |
| 5475 | 256 |
| 103 | 257 def_op('LOAD_LOCALS', 82) |
| 258 def_op('RETURN_VALUE', 83) | |
|
14038
18385172fac0
Apply SF patch #101135, adding 'import module as m' and 'from module import
Thomas Wouters <thomas@python.org>
parents:
13930
diff
changeset
|
259 def_op('IMPORT_STAR', 84) |
|
1746
1940892d2fe3
Merge alpha100 branch back to main trunk
Guido van Rossum <guido@python.org>
parents:
1403
diff
changeset
|
260 def_op('EXEC_STMT', 85) |
|
23783
0dab8ba1d298
The opcode YIELD_STMT was accidentally called YIELD_VALUE here.
Guido van Rossum <guido@python.org>
parents:
23611
diff
changeset
|
261 def_op('YIELD_VALUE', 86) |
| 5475 | 262 |
| 103 | 263 def_op('POP_BLOCK', 87) |
| 264 def_op('END_FINALLY', 88) | |
| 265 def_op('BUILD_CLASS', 89) | |
| 266 | |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
267 HAVE_ARGUMENT = 90 # Opcodes from here have an argument: |
| 103 | 268 |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
269 name_op('STORE_NAME', 90) # Index in name list |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
270 name_op('DELETE_NAME', 91) # "" |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
271 def_op('UNPACK_SEQUENCE', 92) # Number of tuple items |
|
19530
ede7fcb8b0b2
FOR_ITER is a jrel_op() not a plain old def_op()
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
18148
diff
changeset
|
272 jrel_op('FOR_ITER', 93) |
|
13930
4eaa463c031a
Merge UNPACK_LIST and UNPACK_TUPLE into a single UNPACK_SEQUENCE, since they
Thomas Wouters <thomas@python.org>
parents:
12115
diff
changeset
|
273 |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
274 name_op('STORE_ATTR', 95) # Index in name list |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
275 name_op('DELETE_ATTR', 96) # "" |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
276 name_op('STORE_GLOBAL', 97) # "" |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
277 name_op('DELETE_GLOBAL', 98) # "" |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
278 def_op('DUP_TOPX', 99) # number of items to duplicate |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
279 def_op('LOAD_CONST', 100) # Index in const list |
| 103 | 280 hasconst.append(100) |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
281 name_op('LOAD_NAME', 101) # Index in name list |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
282 def_op('BUILD_TUPLE', 102) # Number of tuple items |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
283 def_op('BUILD_LIST', 103) # Number of list items |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
284 def_op('BUILD_MAP', 104) # Always zero for now |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
285 name_op('LOAD_ATTR', 105) # Index in name list |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
286 def_op('COMPARE_OP', 106) # Comparison operator |
| 5475 | 287 hascompare.append(106) |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
288 name_op('IMPORT_NAME', 107) # Index in name list |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
289 name_op('IMPORT_FROM', 108) # Index in name list |
| 103 | 290 |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
291 jrel_op('JUMP_FORWARD', 110) # Number of bytes to skip |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
292 jrel_op('JUMP_IF_FALSE', 111) # "" |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
293 jrel_op('JUMP_IF_TRUE', 112) # "" |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
294 jabs_op('JUMP_ABSOLUTE', 113) # Target byte offset from beginning of code |
| 103 | 295 |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
296 name_op('LOAD_GLOBAL', 116) # Index in name list |
| 5475 | 297 |
|
16398
80c0b280a4f9
Allow 'continue' inside 'try' clause
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16260
diff
changeset
|
298 jabs_op('CONTINUE_LOOP', 119) # Target address |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
299 jrel_op('SETUP_LOOP', 120) # Distance to target address |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
300 jrel_op('SETUP_EXCEPT', 121) # "" |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
301 jrel_op('SETUP_FINALLY', 122) # "" |
| 103 | 302 |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
303 def_op('LOAD_FAST', 124) # Local variable number |
|
4303
388f9c2220ce
Show names of locals in disco (Ka-Ping Yee)
Guido van Rossum <guido@python.org>
parents:
4271
diff
changeset
|
304 haslocal.append(124) |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
305 def_op('STORE_FAST', 125) # Local variable number |
|
4303
388f9c2220ce
Show names of locals in disco (Ka-Ping Yee)
Guido van Rossum <guido@python.org>
parents:
4271
diff
changeset
|
306 haslocal.append(125) |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
307 def_op('DELETE_FAST', 126) # Local variable number |
|
4303
388f9c2220ce
Show names of locals in disco (Ka-Ping Yee)
Guido van Rossum <guido@python.org>
parents:
4271
diff
changeset
|
308 haslocal.append(126) |
|
1264
6c58dc1d2f9d
Updated because of new opcodes introduced for "fast" local variables.
Guido van Rossum <guido@python.org>
parents:
559
diff
changeset
|
309 |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11709
diff
changeset
|
310 def_op('RAISE_VARARGS', 130) # Number of raise arguments (1, 2, or 3) |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11709
diff
changeset
|
311 def_op('CALL_FUNCTION', 131) # #args + (#kwargs << 8) |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11709
diff
changeset
|
312 def_op('MAKE_FUNCTION', 132) # Number of args with default values |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11709
diff
changeset
|
313 def_op('BUILD_SLICE', 133) # Number of items |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11709
diff
changeset
|
314 |
|
16260
20ef849ec877
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
315 def_op('MAKE_CLOSURE', 134) |
|
20ef849ec877
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
316 def_op('LOAD_CLOSURE', 135) |
|
20ef849ec877
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
317 hasfree.append(135) |
|
20ef849ec877
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
318 def_op('LOAD_DEREF', 136) |
|
20ef849ec877
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
319 hasfree.append(136) |
|
20ef849ec877
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
320 def_op('STORE_DEREF', 137) |
|
20ef849ec877
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
321 hasfree.append(137) |
|
20ef849ec877
PEP 227 implementation
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
16070
diff
changeset
|
322 |
|
12082
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11709
diff
changeset
|
323 def_op('CALL_FUNCTION_VAR', 140) # #args + (#kwargs << 8) |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11709
diff
changeset
|
324 def_op('CALL_FUNCTION_KW', 141) # #args + (#kwargs << 8) |
|
603db0d0aed1
slightly modified version of Greg Ewing's extended call syntax patch
Jeremy Hylton <jeremy@alum.mit.edu>
parents:
11709
diff
changeset
|
325 def_op('CALL_FUNCTION_VAR_KW', 142) # #args + (#kwargs << 8) |
|
11709
5d625a365e76
Added a simple test program to disassemble a file, invoked as __main__.
Guido van Rossum <guido@python.org>
parents:
10822
diff
changeset
|
326 |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
327 def_op('EXTENDED_ARG', 143) |
|
14147
21ec69a56228
Charles G. Waldman <cgw@fnal.gov>:
Fred Drake <fdrake@acm.org>
parents:
14106
diff
changeset
|
328 EXTENDED_ARG = 143 |
|
11709
5d625a365e76
Added a simple test program to disassemble a file, invoked as __main__.
Guido van Rossum <guido@python.org>
parents:
10822
diff
changeset
|
329 |
|
5d625a365e76
Added a simple test program to disassemble a file, invoked as __main__.
Guido van Rossum <guido@python.org>
parents:
10822
diff
changeset
|
330 def _test(): |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
331 """Simple test program to disassemble a file.""" |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
332 if sys.argv[1:]: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
333 if sys.argv[2:]: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
334 sys.stderr.write("usage: python dis.py [-|file]\n") |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
335 sys.exit(2) |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
336 fn = sys.argv[1] |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
337 if not fn or fn == "-": |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
338 fn = None |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
339 else: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
340 fn = None |
|
23611
21b1d742e4a7
Replaced boolean test with 'is None'
Raymond Hettinger <python@rcn.com>
parents:
21924
diff
changeset
|
341 if fn is None: |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
342 f = sys.stdin |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
343 else: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
344 f = open(fn) |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
345 source = f.read() |
|
23611
21b1d742e4a7
Replaced boolean test with 'is None'
Raymond Hettinger <python@rcn.com>
parents:
21924
diff
changeset
|
346 if fn is not None: |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
347 f.close() |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
348 else: |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
349 fn = "<stdin>" |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
350 code = compile(source, fn, "exec") |
|
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
351 dis(code) |
|
11709
5d625a365e76
Added a simple test program to disassemble a file, invoked as __main__.
Guido van Rossum <guido@python.org>
parents:
10822
diff
changeset
|
352 |
|
5d625a365e76
Added a simple test program to disassemble a file, invoked as __main__.
Guido van Rossum <guido@python.org>
parents:
10822
diff
changeset
|
353 if __name__ == "__main__": |
|
15867
f5a3d98a35bc
Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents:
14171
diff
changeset
|
354 _test() |
