1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/micropython/cmd.py Mon Jun 01 02:41:57 2009 +0200
1.3 @@ -0,0 +1,54 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +Command option processing and other utilities for compiling and testing
1.8 +programs.
1.9 +"""
1.10 +
1.11 +import micropython
1.12 +
1.13 +def parse_optimisations(args):
1.14 +
1.15 + "Parse 'args' for optimisation flags."
1.16 +
1.17 + if "-omax" in args:
1.18 + requested_optimisations = micropython.Program.supported_optimisations
1.19 + else:
1.20 + requested_optimisations = []
1.21 + for arg in args:
1.22 + if arg.startswith("-o"):
1.23 + for arg_part in arg[2:].split(","):
1.24 + requested_optimisations.append(arg_part)
1.25 +
1.26 + return requested_optimisations
1.27 +
1.28 +def program(filename, path, requested_optimisations, verbose=0):
1.29 +
1.30 + """
1.31 + Return the program object for the program specified by the given 'filename',
1.32 + module search 'path' and 'requested_optimisations'.
1.33 + """
1.34 +
1.35 + i = micropython.Importer(path, verbose, requested_optimisations)
1.36 + p = micropython.Program(i, requested_optimisations)
1.37 +
1.38 + i.load_from_file("lib/builtins.py", "__builtins__")
1.39 +
1.40 + if filename is not None:
1.41 + i.load_from_file(filename)
1.42 +
1.43 + return p
1.44 +
1.45 +# Convenience functions.
1.46 +
1.47 +def get_program(filename, path, args):
1.48 +
1.49 + """
1.50 + Return the program object for the program specified by the given 'filename',
1.51 + module search 'path' and command 'args'.
1.52 + """
1.53 +
1.54 + requested_optimisations = parse_optimisations(args)
1.55 + return program(filename, path, requested_optimisations, "-v" in args)
1.56 +
1.57 +# vim: tabstop=4 expandtab shiftwidth=4