1.1 --- a/lplc Thu Feb 23 16:37:43 2017 +0100
1.2 +++ b/lplc Thu Feb 23 16:39:02 2017 +0100
1.3 @@ -22,8 +22,8 @@
1.4 VERSION = "0.1"
1.5
1.6 from errors import *
1.7 -from os import environ, rename
1.8 -from os.path import abspath, exists, isfile, join, split
1.9 +from os import environ, listdir, remove, rename
1.10 +from os.path import abspath, exists, isdir, isfile, join, split
1.11 from pyparser import error
1.12 from subprocess import Popen, PIPE
1.13 from time import time
1.14 @@ -82,6 +82,17 @@
1.15 else:
1.16 return l, needed
1.17
1.18 +def remove_all(dirname):
1.19 +
1.20 + "Remove 'dirname' and its contents."
1.21 +
1.22 + for filename in listdir(dirname):
1.23 + pathname = join(dirname, filename)
1.24 + if isdir(pathname):
1.25 + remove_all(pathname)
1.26 + else:
1.27 + remove(pathname)
1.28 +
1.29 # Main program.
1.30
1.31 if __name__ == "__main__":
1.32 @@ -98,21 +109,32 @@
1.33 Compile the program whose principal file is given in place of <filename>.
1.34 The following options may be specified:
1.35
1.36 --c Only partially compile the program; do not attempt to build or link it
1.37 --E Ignore environment variables affecting the module search path
1.38 --g Generate debugging information for the built executable
1.39 --P Show the module search path
1.40 --q Silence messages produced when building an executable
1.41 --r Reset (discard) cached program information; inspect the whole program again
1.42 --t Silence timing messages
1.43 --tb Provide a traceback for any internal errors (development only)
1.44 --v Report compiler activities in a verbose fashion (development only)
1.45 +-c Only partially compile the program; do not build or link it
1.46 +--compile Equivalent to -c
1.47 +-E Ignore environment variables affecting the module search path
1.48 +--no-env Equivalent to -E
1.49 +-g Generate debugging information for the built executable
1.50 +--debug Equivalent to -g
1.51 +-P Show the module search path
1.52 +--show-path Equivalent to -P
1.53 +-q Silence messages produced when building an executable
1.54 +--quiet Equivalent to -q
1.55 +-r Reset (discard) cached information; inspect the whole program again
1.56 +--reset Equivalent to -r
1.57 +-R Reset (discard) all program details including translated code
1.58 +--reset-all Equivalent to -R
1.59 +-t Silence timing messages
1.60 +--no-timing Equivalent to -t
1.61 +-tb Provide a traceback for any internal errors (development only)
1.62 +--traceback Equivalent to -tb
1.63 +-v Report compiler activities in a verbose fashion (development only)
1.64 +--verbose Equivalent to -v
1.65
1.66 Some options may be followed by values, either immediately after the option
1.67 (without any space between) or in the arguments that follow them:
1.68
1.69 --o Indicate the output executable name
1.70 --W Show warnings on the topics indicated
1.71 +-o Indicate the output executable name
1.72 +-W Show warnings on the topics indicated
1.73
1.74 Currently, the following warnings are supported:
1.75
1.76 @@ -152,6 +174,7 @@
1.77 make = True
1.78 make_verbose = True
1.79 reset = False
1.80 + reset_all = False
1.81 timings = True
1.82 traceback = False
1.83 verbose = False
1.84 @@ -166,15 +189,16 @@
1.85 needed = None
1.86
1.87 for arg in args:
1.88 - if arg == "-c": make = False
1.89 - elif arg == "-E": ignore_env = True
1.90 - elif arg == "-g": debug = True
1.91 - elif arg == "-q": make_verbose = False
1.92 - elif arg == "-r": reset = True
1.93 - elif arg == "-t": timings = False
1.94 - elif arg == "-tb": traceback = True
1.95 + if arg in ("-c", "--compile"): make = False
1.96 + elif arg in ("-E", "--no-env"): ignore_env = True
1.97 + elif arg in ("-g", "--debug"): debug = True
1.98 + elif arg in ("-q", "--quiet"): make_verbose = False
1.99 + elif arg in ("-r", "--reset"): reset = True
1.100 + elif arg in ("-R", "--reset-all"): reset_all = True
1.101 + elif arg in ("-t", "--no-timing"): timings = False
1.102 + elif arg in ("-tb", "--traceback"): traceback = True
1.103 elif arg.startswith("-o"): l, needed = start_arg_list(outputs, arg, "-o", 1)
1.104 - elif arg == "-v": verbose = True
1.105 + elif arg == ("-v", "--verbose"): verbose = True
1.106 elif arg.startswith("-W"): l, needed = start_arg_list(warnings, arg, "-W", 1)
1.107 else:
1.108 l.append(arg)
1.109 @@ -193,7 +217,7 @@
1.110
1.111 # Show the module search path if requested.
1.112
1.113 - if "-P" in args:
1.114 + if "-P" in args or "--show-path" in args:
1.115 for libdir in libdirs:
1.116 print libdir
1.117 sys.exit(0)
1.118 @@ -227,6 +251,11 @@
1.119 output_dir = join(datadir, "_output")
1.120 generated_dir = join(datadir, "_generated")
1.121
1.122 + # Perform any full reset of the working data.
1.123 +
1.124 + if reset_all:
1.125 + remove_all(datadir)
1.126 +
1.127 # Load the program.
1.128
1.129 try: