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