Lichen

lplc

291:afa2a255d1e5
2016-12-01 Paul Boddie Omit __newdata_mapping when dictionaries are not used in programs, thus eliminating dependencies on the missing dict initialiser.
     1 #!/usr/bin/env python     2      3 from errors import *     4 from os.path import abspath, exists, join, split     5 from time import time     6 import importer, deducer, optimiser, generator, translator     7 import sys     8      9 libdirs = [    10     join(split(__file__)[0], "lib"),    11     "/usr/share/lichen/lib"    12     ]    13     14 def load_module(filename, module_name):    15     for libdir in libdirs:    16         path = join(libdir, filename)    17         if exists(path):    18             return i.load_from_file(path, module_name)    19     return None    20     21 def show_missing(missing):    22     missing = list(missing)    23     missing.sort()    24     for module_name, name in missing:    25         print >>sys.stderr, "Module %s references an unknown object: %s" % (module_name, name)    26     27 def stopwatch(activity, now):    28     print >>sys.stderr, "%s took %.2f seconds" % (activity, time() - now)    29     return time()    30     31 # Main program.    32     33 if __name__ == "__main__":    34     args = sys.argv[2:]    35     path = libdirs + sys.path[:]    36     37     filename = abspath(sys.argv[1])    38     path.append(split(filename)[0])    39     40     verbose = "-v" in args    41     reset = "-r" in args    42     debug = "-g" in args    43     44     # Load the program.    45     46     try:    47         start = now = time()    48     49         i = importer.Importer(path, "_cache", verbose)    50         m = i.initialise(filename, reset)    51         success = i.finalise()    52     53         now = stopwatch("Inspection", now)    54     55         # Check for success, indicating missing references otherwise.    56     57         if not success:    58             show_missing(i.missing)    59             sys.exit(1)    60     61         d = deducer.Deducer(i, "_deduced")    62         d.to_output()    63     64         now = stopwatch("Deduction", now)    65     66         o = optimiser.Optimiser(i, d, "_output")    67         o.to_output()    68     69         now = stopwatch("Optimisation", now)    70     71         g = generator.Generator(i, o, "_generated")    72         g.to_output(debug)    73     74         now = stopwatch("Generation", now)    75     76         t = translator.Translator(i, d, o, "_generated")    77         t.to_output()    78     79         stopwatch("Translation", now)    80     81     # Report any errors.    82     83     except ProcessingError, exc:    84         print exc    85         if "-tb" in args:    86             raise    87         sys.exit(1)    88     89     else:    90         sys.exit(0)    91     92 # vim: tabstop=4 expandtab shiftwidth=4