1 #!/usr/bin/env python 2 3 import micropython.cmd 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 # Main program. 24 25 if __name__ == "__main__": 26 args = sys.argv[2:] 27 path = sys.path[:] 28 29 if "--help" in sys.argv: 30 print "Optimisations:" 31 print micropython.cmd.show_optimisations() 32 sys.exit(1) 33 34 if len(sys.argv) > 1: 35 filename = os.path.abspath(sys.argv[1]) 36 path.append(os.path.split(filename)[0]) 37 else: 38 filename = None 39 40 # Make the program. 41 42 try: 43 p = micropython.cmd.get_program(filename, path, args) 44 if filename is None: 45 print "Loading module micropython ..." 46 m = p.get_importer().load("micropython") 47 else: 48 m = p.get_importer().get_module("__main__") 49 50 # Report any errors. 51 52 except micropython.ProcessingError, exc: 53 print repr(exc) 54 if "-tb" in args: 55 raise 56 57 # Provide information to any interactive session. 58 59 else: 60 ot = p.get_object_table() 61 pt = p.get_parameter_table() 62 63 if "-m" in args or "-t" in args: 64 rm = rsvp.machine(p, debug=("-g" in args), abort_upon_exception=("-x" in args)) 65 if "-t" in args: 66 success = rm.test(m) 67 print "Test successful?", success 68 69 # vim: tabstop=4 expandtab shiftwidth=4