diff options
-rw-r--r-- | lab/parser.py | 6 | ||||
-rw-r--r-- | lab/show_pyc.py | 14 |
2 files changed, 15 insertions, 5 deletions
diff --git a/lab/parser.py b/lab/parser.py index 374acea..ce6902a 100644 --- a/lab/parser.py +++ b/lab/parser.py @@ -118,10 +118,14 @@ class ParserMain(object): else: srclines = None print("\n%s: " % bp.code) + upto = None for disline in disgen.disgen(bp.code): if disline.first: if srclines: - print("%100s%s" % ("", srclines[disline.lineno-1])) + upto = upto or disline.lineno-1 + while upto <= disline.lineno-1: + print("%100s%s" % ("", srclines[upto])) + upto += 1 elif disline.offset > 0: print("") line = disgen.format_dis_line(disline) diff --git a/lab/show_pyc.py b/lab/show_pyc.py index a0834e8..7dacc2b 100644 --- a/lab/show_pyc.py +++ b/lab/show_pyc.py @@ -12,6 +12,9 @@ def show_pyc_file(fname): def show_py_file(fname):
text = open(fname).read().replace('\r\n', '\n')
+ show_py_text(text, fname=fname)
+
+def show_py_text(text, fname="<string>"):
code = compile(text, fname, "exec")
show_code(code)
@@ -55,10 +58,13 @@ def show_file(fname): show_py_file(fname)
else:
print "Odd file:", fname
-
+
def main(args):
- for a in args:
- show_file(a)
-
+ if args[0] == '-c':
+ show_py_text(" ".join(args[1:]).replace(";", "\n"))
+ else:
+ for a in args:
+ show_file(a)
+
if __name__ == '__main__':
main(sys.argv[1:])
|