コード例 #1
0
ファイル: cpp_writer.py プロジェクト: jmlopez-rod/excentury
def fmt_func(func):
    """Given a Function object from .xcpp it will create the a valid
    string with the function. """
    fepi = func.epilog
    if fepi != '':
        fepi = '\n' + fepi
    content = FUNC.format(name=m_name(func.name),
                          body=func.body, doc=func.doc,
                          input=format_input(func.param),
                          output=format_return(func.ret),
                          funcpre=func.preamble, funcepi=fepi)
    return content
コード例 #2
0
ファイル: cpp_writer.py プロジェクト: jmlopez-rod/spp
def _fmt_func(func, cfg):
    """Given a Function object from .xcpp it will create the a valid
    string with the function. """
    epilog = func.epilog
    if epilog != '':
        epilog += '\n'
    return FUNC.format(name=func.name,
                       load=cfg['python']['load'].capitalize(),
                       inputs=format_input(func.param),
                       body=func.body,
                       dump=cfg['python']['dump'].capitalize(),
                       outputs=format_return(func.ret),
                       funcpre=func.preamble, funcepi=epilog)
コード例 #3
0
ファイル: cpp_writer.py プロジェクト: jmlopez-rod/excentury
def write_cpp_function(xcf, func, cfg):
    """Writes the cpp file and compiles it. """
    fepi = func.epilog
    if fepi != '':
        fepi = '\n' + fepi
    if xcf.epilog != '':
        fepi += '\n'
    content = FILE.format(date=date(),
                          preamble=xcf.preamble,
                          load=cfg['matlab']['load'].capitalize(),
                          inputs=format_input(func.param),
                          body=func.body, funcpre=func.preamble,
                          dump=cfg['matlab']['dump'].capitalize(),
                          outputs=format_return(func.ret),
                          funcepi=fepi, epilog=xcf.epilog)
    in_fname = _write_cpp_file(content, func, cfg)
    _compile_cpp_file(in_fname, func, cfg)
コード例 #4
0
ファイル: aux.py プロジェクト: jmlopez-rod/spp
def process_function(xcf, cfg, func):
    """Given a Function object from .xcpp it will create the contents
    of a valid cpp file that can be compiled for a valid executable.
    """
    in_fname = cfg['xcpp']['filename']
    epilog = func.epilog
    if epilog != '':
        epilog += '\n'
    contents = TEMPLATE.format(date=date(), pre_xc=xcf.pre_xc,
                               preamble=xcf.preamble,
                               help=_format_help(func, in_fname),
                               param=_format_input(func.param),
                               doc=func.doc, body=func.body,
                               load=cfg['cpp']['load'].capitalize(),
                               dump=cfg['cpp']['dump'].capitalize(),
                               input=format_input(func.param),
                               output=format_return(func.ret),
                               out=func.out, funcpre=func.preamble,
                               funcepi=epilog, epilog=xcf.epilog)
    in_fname = _write_file(contents, func, cfg)
    out_fname = _get_exec_name(func, cfg)
    force = cfg['cpp']['force']
    make_new = True
    if isinstance(force, list) and (len(force) == 0 or func.num in force):
        pass
    elif force in ['True', 'true']:
        pass
    elif os.path.exists(out_fname):
        date_in = datetime.fromtimestamp(os.path.getmtime(in_fname))
        date_out = datetime.fromtimestamp(os.path.getmtime(out_fname))
        if date_in < date_out:
            make_new = False
            trace('  - skipping compilation\n')
    if make_new:
        cmd = gen_cmd(cfg, 'cpp', int(cfg['cpp']['debug']))
        cmd = '%s%s -o %s' % (cmd, in_fname, out_fname)
        trace('  - compiling %s ... ' % in_fname)
        _, err, _ = exec_cmd(cmd)
        if err != '':
            msg = "\nERROR: The command\n%s\n\nreturned the following " \
                  "error:\n%s" % (str(cmd), str(err))
            error(msg)
        trace('done\n')