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