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 # Load the program. 41 42 try: 43 p = micropython.cmd.get_program(path, args) 44 i = p.get_importer() 45 46 if filename is None: 47 print "Loading module micropython ..." 48 m = i.load("micropython") 49 else: 50 print "Loading from", filename, "..." 51 m = i.load_from_file(filename) 52 53 # Build the program. 54 55 if "-m" in args or "-t" in args: 56 rm = rsvp.machine(p, debug=("-g" in args), abort_upon_exception=("-x" in args)) 57 58 if "-t" in args: 59 success = rm.test(m) 60 print "Test successful?", success 61 62 print "RSVP machine: rm = %r" % rm 63 64 ot = p.get_object_table() 65 pt = p.get_parameter_table() 66 67 print "Object table: ot = %r" % ot 68 print "Parameter table: pt = %r" % pt 69 print "Importer: i = %r" % i 70 print "Program: p = %r" % p 71 print "Module: m = %r" % m 72 73 # Report any errors. 74 75 except micropython.ProcessingError, exc: 76 print repr(exc) 77 if "-tb" in args: 78 raise 79 80 # vim: tabstop=4 expandtab shiftwidth=4