1 #!/usr/bin/env python 2 3 import micropython 4 from micropython.rsvp import raw 5 import sys 6 7 code = None 8 9 def show(importer, with_builtins=0, optimisations=None): 10 optimisations = optimisations or requested_optimisations 11 global code 12 code = importer.get_image(with_builtins, optimisations) 13 show_code(code) 14 15 def show_code(code): 16 for i, x in enumerate(code): 17 print i, x 18 19 def attrs(obj): 20 for name, attr in obj.items(): 21 print name, attr 22 23 if __name__ == "__main__": 24 args = sys.argv[2:] 25 i = micropython.Importer(sys.path, "-v" in args) 26 27 if "-omax" in args: 28 requested_optimisations = i.supported_optimisations 29 else: 30 requested_optimisations = [] 31 for arg in args: 32 if arg.startswith("-o"): 33 requested_optimisations.append(arg[2:]) 34 35 try: 36 builtins = i.load_from_file("lib/builtins.py", "__builtins__") 37 if len(sys.argv) < 2: 38 m = i.load("micropython") 39 #m = i.load_from_file("micropython/__init__.py") 40 else: 41 m = i.load_from_file(sys.argv[1]) 42 except micropython.ProcessingError, exc: 43 print repr(exc) 44 else: 45 i.vacuum() 46 ot = i.get_object_table() 47 pt = i.get_parameter_table() 48 49 # vim: tabstop=4 expandtab shiftwidth=4