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