예제 #1
0
파일: ui.py 프로젝트: cartazio/distalgo
def dafile_to_pseudofile(filename, outname=None):
    """Compiles a DistAlgo source file to Python file.

    'filename' is the input DistAlgo source file. Optional parameter 'outname'
    specifies the file to write the result to. If 'outname' is None the
    filename is inferred by replacing the suffix of 'filename' with '.py'.

    """
    purename, _, suffix = filename.rpartition(".")
    if len(purename) == 0:
        purename = suffix
        suffix = ""
    if suffix == "py":
        stderr.write("Warning: skipping '.py' file %s\n" % filename)
        return
    elif suffix != DA_SUFFIX:
        stderr.write("Warning: unknown suffix '%s' in filename '%s'\n" %
                      (suffix, filename))

    daast = daast_from_file(filename)
    if daast:
        if outname is None:
            outname = purename + ".dap"
        with open(outname, "w") as outfd:
            DastUnparser(daast, outfd)
            stderr.write("Written pseudo code file %s.\n"% outname)
예제 #2
0
파일: ui.py 프로젝트: avee137/coursework
def dafile_to_pseudofile(filename, outname=None):
    """Compiles a DistAlgo source file to Python file.

    'filename' is the input DistAlgo source file. Optional parameter 'outname'
    specifies the file to write the result to. If 'outname' is None the
    filename is inferred by replacing the suffix of 'filename' with '.py'.

    """
    purename, _, suffix = filename.rpartition(".")
    if len(purename) == 0:
        purename = suffix
        suffix = ""
    if suffix == "py":
        stderr.write("Warning: skipping '.py' file %s\n" % filename)
        return
    elif suffix != DA_SUFFIX:
        stderr.write("Warning: unknown suffix '%s' in filename '%s'\n" %
                      (suffix, filename))

    daast = daast_from_file(filename)
    if daast:
        if outname is None:
            outname = purename + ".dap"
        with open(outname, "w") as outfd:
            DastUnparser(daast, outfd)
            stderr.write("Written pseudo code file %s.\n"% outname)
예제 #3
0
파일: ui.py 프로젝트: cartazio/distalgo
def dafile_to_pyast(filename, args=None):
    """Translates DistAlgo source file into executable Python AST.

    'filename' is the filename of source file. Optional argument 'args' is a
    Namespace object containing the command line parameters for the compiler.
    Returns the generated Python AST.

    """
    daast = daast_from_file(filename, args)
    if daast is not None:
        pyast = PythonGenerator(filename, args).visit(daast)
        if pyast is None:
            print("Error: unable to generate Python AST from DistAlgo AST"
                  " for file ", filename, file=stderr)
        return pyast
    else:
        return None
예제 #4
0
파일: ui.py 프로젝트: cartazio/distalgo
def dafile_to_incfiles(args):
    """Compiles a DistAlgo source file to Python file and generate an interface
    file for incrementalization.

    'args' is the object generated by argparse from the command line
    arguments, and should contain the following properties:

    'filename' is the input DistAlgo source file. Optional property 'outname'
    specifies the file to write the result to. If 'outname' is None the
    filename is inferred by replacing the suffix of 'filename' with '.py'.
    Optional property 'incname' is the file to write the incrementalization
    module to. If 'incname' is None it defaults to the base of 'filename'
    plus '_inc.py'.

    """

    filename = args.infile
    outname = args.outfile
    incname = args.incfile
    purename, _, suffix = filename.rpartition(".")
    if len(purename) == 0:
        purename = suffix
        suffix = ""
    if suffix == "py":
        stderr.write("Warning: skipping '.py' file %s\n" % filename)
        return
    elif suffix != DA_SUFFIX:
        stderr.write("Warning: unknown suffix '%s' in filename '%s'\n" %
                      (suffix, filename))
    daast = daast_from_file(filename, args)
    if outname is None:
        outname = purename + ".py"
    if incname is None:
        incname = purename + "_inc.py" 
    if daast is not None:
        global OutputSize
        inc, ast = gen_inc_module(daast, args, filename=incname)
        with open(outname, "w") as outfd:
            OutputSize += Unparser(ast, outfd).counter
            stderr.write("Written compiled file %s.\n"% outname)
        with open(incname, "w") as outfd:
            OutputSize += Unparser(inc, outfd).counter
            stderr.write("Written interface file %s.\n" % incname)
        return 0
    else:
        return 1
예제 #5
0
파일: ui.py 프로젝트: avee137/coursework
def dafile_to_pyast(filename, args=None):
    """Translates DistAlgo source file into executable Python AST.

    'filename' is the filename of source file. Optional argument 'args' is a
    Namespace object containing the command line parameters for the compiler.
    Returns the generated Python AST.

    """
    daast = daast_from_file(filename, args)
    if daast is not None:
        pyast = PythonGenerator(filename, args).visit(daast)
        if pyast is None:
            print("Error: unable to generate Python AST from DistAlgo AST"
                  " for file ", filename, file=stderr)
        return pyast
    else:
        return None
예제 #6
0
파일: ui.py 프로젝트: avee137/coursework
def dafile_to_incfiles(args):
    """Compiles a DistAlgo source file to Python file and generate an interface
    file for incrementalization.

    'args' is the object generated by argparse from the command line
    arguments, and should contain the following properties:

    'filename' is the input DistAlgo source file. Optional property 'outname'
    specifies the file to write the result to. If 'outname' is None the
    filename is inferred by replacing the suffix of 'filename' with '.py'.
    Optional property 'incname' is the file to write the incrementalization
    module to. If 'incname' is None it defaults to the base of 'filename'
    plus '_inc.py'.

    """

    filename = args.infile
    outname = args.outfile
    incname = args.incfile
    purename, _, suffix = filename.rpartition(".")
    if len(purename) == 0:
        purename = suffix
        suffix = ""
    if suffix == "py":
        stderr.write("Warning: skipping '.py' file %s\n" % filename)
        return
    elif suffix != DA_SUFFIX:
        stderr.write("Warning: unknown suffix '%s' in filename '%s'\n" %
                      (suffix, filename))
    daast = daast_from_file(filename, args)
    if outname is None:
        outname = purename + ".py"
    if incname is None:
        incname = purename + "_inc.py" 
    if daast is not None:
        global OutputSize
        inc, ast = gen_inc_module(daast, args, filename=incname)
        with open(outname, "w") as outfd:
            OutputSize += to_file(ast, outfd)
            stderr.write("Written compiled file %s.\n"% outname)
        with open(incname, "w") as outfd:
            OutputSize += to_file(inc, outfd)
            stderr.write("Written interface file %s.\n" % incname)
        return 0
    else:
        return 1
예제 #7
0
            self.dispatch(t.name)

    def _callargs(self, t):
        print(self.fill() + 'CALLARGS:', file=self.f, flush=True)
        for e in t.args:
            self.dispatch(e)
        for key, value in t.keywords:
            self.dispatch(key)
            self.dispatch(value)
        if t.starargs:
            self.dispatch(t.starargs)
        if t.kwargs:
            self.dispatch(t.kwargs)

    def _withitem(self, t):
        print(self.fill() + 'WITHITEM:', file=self.f, flush=True)
        self.dispatch(t.context_expr)
        if t.optional_vars:
            self.dispatch(t.optional_vars)


if __name__ == '__main__':
    #recurse_count = 20
    if len(sys.argv) > 1:
        in_fn = sys.argv[1]
        the_daast = daast_from_file(in_fn, parse_all_args([]))
        dp = DastNest(the_daast)
    else:
        print('An input file name must be provided.', flush=True)
#end main()
예제 #8
0
        else:
            self.dispatch(t.name)

    def _callargs(self, t):
        print(self.fill() + 'CALLARGS:', file = self.f, flush = True)
        for e in t.args:
            self.dispatch(e)
        for key, value in t.keywords:
            self.dispatch(key)
            self.dispatch(value)
        if t.starargs:
            self.dispatch(t.starargs)
        if t.kwargs:
            self.dispatch(t.kwargs)

    def _withitem(self, t):
        print(self.fill() + 'WITHITEM:', file = self.f, flush = True)
        self.dispatch(t.context_expr)
        if t.optional_vars:
            self.dispatch(t.optional_vars)

if __name__ == '__main__':
    #recurse_count = 20
    if len(sys.argv) > 1:
        in_fn = sys.argv[1]
        the_daast = daast_from_file(in_fn, parse_all_args([]))
        dp = DastNest(the_daast)
    else:
        print('An input file name must be provided.', flush = True)
#end main()