Skip to content

Commit

Permalink
Added a simple test program to disassemble a file, invoked as __main__.
Browse files Browse the repository at this point in the history
  • Loading branch information
gvanrossum committed Feb 4, 2000
1 parent 4b8c6ea commit 1fdae12
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions Lib/dis.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,30 @@ def jabs_op(name, op):
def_op('CALL_FUNCTION', 131)
def_op('MAKE_FUNCTION', 132)
def_op('BUILD_SLICE', 133)


def _test():
"""Simple test program to disassemble a file."""
if sys.argv[1:]:
if sys.argv[2:]:
sys.stderr.write("usage: python dis.py [-|file]\n")
sys.exit(2)
fn = sys.argv[1]
if not fn or fn == "-":
fn = None
else:
fn = None
if not fn:
f = sys.stdin
else:
f = open(fn)
source = f.read()
if fn:
f.close()
else:
fn = "<stdin>"
code = compile(source, fn, "exec")
dis(code)

if __name__ == "__main__":
_test()

0 comments on commit 1fdae12

Please sign in to comment.