1 #!/usr/bin/env python 2 3 import micropython 4 from micropython.graph import get_graph 5 import rsvp 6 import sys 7 import os 8 9 def show_code(code): 10 for i, x in enumerate(code): 11 print i, x 12 13 def show_table_usage(raw_table, slice_size=100): 14 for x in xrange(0, len(raw_table), slice_size): 15 table_slice = raw_table[x:x+slice_size] 16 print "%6d" % (len(table_slice) - table_slice.count(None)), \ 17 "".join(entry and "#" or "_" for entry in table_slice) 18 19 def attrs(obj): 20 for name, attr in obj.items(): 21 print name, attr 22 23 # Command option processing. 24 25 def parse_optimisations(args): 26 27 "Parse 'args' for optimisation flags." 28 29 if "-omax" in args: 30 requested_optimisations = micropython.Program.supported_optimisations 31 else: 32 requested_optimisations = [] 33 for arg in args: 34 if arg.startswith("-o"): 35 for arg_part in arg[2:].split(","): 36 requested_optimisations.append(arg_part) 37 38 return requested_optimisations 39 40 # Main program. 41 42 if __name__ == "__main__": 43 args = sys.argv[2:] 44 path = sys.path[:] 45 46 if len(sys.argv) > 1: 47 filename = os.path.abspath(sys.argv[1]) 48 path.append(os.path.split(filename)[0]) 49 else: 50 filename = None 51 52 requested_optimisations = parse_optimisations(args) 53 54 # Make the program. 55 56 try: 57 p = micropython.program(filename, path, requested_optimisations, "-v" in args) 58 if filename is None: 59 print "Loading module micropython ..." 60 m = p.get_importer().load("micropython") 61 else: 62 m = p.get_importer().get_module("__main__") 63 64 # Report any errors. 65 66 except micropython.ProcessingError, exc: 67 print repr(exc) 68 if "-tb" in args: 69 raise 70 71 # Provide information to any interactive session. 72 73 else: 74 ot = p.get_object_table() 75 pt = p.get_parameter_table() 76 77 if "-m" in args or "-t" in args: 78 rm = rsvp.machine(p) 79 if "-t" in args: 80 success = rm.test(m) 81 print "Test successful?", success 82 83 # vim: tabstop=4 expandtab shiftwidth=4