# HG changeset patch # User Paul Boddie # Date 1267922969 -3600 # Node ID 54cb8a2fff313e7910c7c0feb1b7fcb1d92ec538 # Parent 12bf807e1e08357150b4e59bae3f446ffdee5485 Attempted to make the API more regular. diff -r 12bf807e1e08 -r 54cb8a2fff31 micropython/cmd.py --- a/micropython/cmd.py Wed Mar 03 00:26:00 2010 +0100 +++ b/micropython/cmd.py Sun Mar 07 01:49:29 2010 +0100 @@ -43,33 +43,29 @@ return ",".join(micropython.Program.supported_optimisations) -def program(filename, path, requested_optimisations, verbose=0): +def program(path, requested_optimisations, verbose=0): """ - Return the program object for the program specified by the given 'filename', - module search 'path' and 'requested_optimisations'. + Return a program object for the given module search 'path' and + 'requested_optimisations'. """ i = micropython.Importer(path, verbose, requested_optimisations) p = micropython.Program(i, requested_optimisations) i.load_from_file("lib/builtins.py", "__builtins__") - - if filename is not None: - i.load_from_file(filename) - return p # Convenience functions. -def get_program(filename, path, args): +def get_program(path, args): """ - Return the program object for the program specified by the given 'filename', - module search 'path' and command 'args'. + Return the program object for the given module search 'path' and command + 'args'. """ requested_optimisations = parse_optimisations(args) - return program(filename, path, requested_optimisations, "-v" in args) + return program(path, requested_optimisations, "-v" in args) # vim: tabstop=4 expandtab shiftwidth=4 diff -r 12bf807e1e08 -r 54cb8a2fff31 micropython/inspect.py --- a/micropython/inspect.py Wed Mar 03 00:26:00 2010 +0100 +++ b/micropython/inspect.py Sun Mar 07 01:49:29 2010 +0100 @@ -383,6 +383,8 @@ self.dispatch(n) return Instance() + # Generic support for classes of operations. + def _visitUnary(self, node): "Accounting method for the unary operator 'node'." diff -r 12bf807e1e08 -r 54cb8a2fff31 test.py --- a/test.py Wed Mar 03 00:26:00 2010 +0100 +++ b/test.py Sun Mar 07 01:49:29 2010 +0100 @@ -40,12 +40,15 @@ # Load the program. try: - p = micropython.cmd.get_program(filename, path, args) + p = micropython.cmd.get_program(path, args) + i = p.get_importer() + if filename is None: print "Loading module micropython ..." - m = p.get_importer().load("micropython") + m = i.load("micropython") else: - m = p.get_importer().get_module("__main__") + print "Loading from", filename, "..." + m = i.load_from_file(filename) # Build the program. @@ -60,7 +63,6 @@ ot = p.get_object_table() pt = p.get_parameter_table() - i = p.get_importer() print "Object table: ot = %r" % ot print "Parameter table: pt = %r" % pt