micropython

test.py

136:9fdd2c13dbac
2008-08-27 Paul Boddie Added another test of method invocation, explicitly testing instance/class compatibility for supplied contexts.
     1 #!/usr/bin/env python     2      3 import micropython     4 from micropython.rsvp import raw     5 import rsvp     6 import sys     7 import os     8      9 code = None    10     11 def show(importer, with_builtins=0, optimisations=None):    12     make(importer, with_builtins, optimisations)    13     show_code(code)    14     15 def make(importer, with_builtins=0, optimisations=None):    16     optimisations = optimisations or requested_optimisations    17     global code    18     code = importer.get_image(with_builtins, optimisations)    19     20 def show_code(code):    21     for i, x in enumerate(code):    22         print i, x    23     24 def show_table_usage(raw_table, slice_size=100):    25     for x in xrange(0, len(raw_table), slice_size):    26         table_slice = raw_table[x:x+slice_size]    27         print "%6d" % (len(table_slice) - table_slice.count(None)), \    28             "".join(entry and "#" or "_" for entry in table_slice)    29     30 def machine(importer):    31     rc = raw(importer.code)    32     rm = rsvp.RSVPMachine(rc)    33     rm.pc = importer.code_location    34     return rm    35     36 def attrs(obj):    37     for name, attr in obj.items():    38         print name, attr    39     40 if __name__ == "__main__":    41     args = sys.argv[2:]    42     path = sys.path[:]    43     44     if len(sys.argv) > 1:    45         program = os.path.abspath(sys.argv[1])    46         path.append(os.path.split(program)[0])    47     else:    48         program = None    49     50     i = micropython.Importer(path, "-v" in args)    51     52     if "-omax" in args:    53         requested_optimisations = i.supported_optimisations    54     else:    55         requested_optimisations = []    56         for arg in args:    57             if arg.startswith("-o"):    58                 for arg_part in arg[2:].split(","):    59                     requested_optimisations.append(arg_part)    60     61     try:    62         builtins = i.load_from_file("lib/builtins.py", "__builtins__")    63         if program is None:    64             print "Loading module micropython ..."    65             m = i.load("micropython")    66         else:    67             print "Loading program", program, "..."    68             m = i.load_from_file(program)    69     except micropython.ProcessingError, exc:    70         print repr(exc)    71         if "-tb" in args:    72             raise    73     else:    74         i.vacuum()    75         ot = i.get_object_table()    76         pt = i.get_parameter_table()    77     78 # vim: tabstop=4 expandtab shiftwidth=4