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(code, code_location): 24 rc = raw(code) 25 rm = rsvp.RSVPMachine(rc) 26 rm.pc = 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 requested_optimisations.append(arg[2:]) 44 45 try: 46 builtins = i.load_from_file("lib/builtins.py", "__builtins__") 47 if len(sys.argv) < 2: 48 m = i.load("micropython") 49 #m = i.load_from_file("micropython/__init__.py") 50 else: 51 m = i.load_from_file(sys.argv[1]) 52 except micropython.ProcessingError, exc: 53 print repr(exc) 54 else: 55 i.vacuum() 56 ot = i.get_object_table() 57 pt = i.get_parameter_table() 58 59 # vim: tabstop=4 expandtab shiftwidth=4