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