예제 #1
0
def execute(tag, cufn, *v, **k):
    """Call Copperhead function. Invokes compilation if necessary"""

    if len(v) == 0:
        #Functions which take no arguments
        cu_types, cu_inputs = ((),())
    else:
        cu_types, cu_inputs = zip(*map(induct, v))
    #Derive unique hash for function based on inputs and target place
    signature = ','.join([str(tag)]+[str(x) for x in cu_types])
    #Have we executed this function before, in which case it is loaded in cache?
    if signature in cufn.cache:
        return cufn.cache[signature](*cu_inputs)

    #XXX can't we get rid of this circular dependency?
    from . import toolchains
    #Compile function
    ast = cufn.get_ast()
    name = ast[0].name().id
    code, compiled_fn = \
                 passes.compile(ast,
                                globals=cufn.get_globals(),
                                input_types={name : cu_types},
                                tag=tag,
                                code_dir=cufn.code_dir,
                                toolchains=toolchains,
                                **k)
    #Store the binary and the compilation result
    cufn.cache[signature] = compiled_fn
    #Call the function
    return compiled_fn(*cu_inputs)
예제 #2
0
def execute(cufn, *v, **k):
    cu_types, cu_inputs = zip(*map(induct, v))
    signature = ','.join([str(x) for x in cu_types])
    if signature in cufn.cache:
        return cufn.cache[signature](*cu_inputs)

    ast = cufn.get_ast()
    name = ast[0].name().id
    code, compiled_fn = \
                 passes.compile(ast,
                                globals=cufn.get_globals(),
                                input_types={name : cu_types},
                                **k)
    cufn.cache[signature] = compiled_fn
    cufn.code[signature] = code
    return_value = compiled_fn(*cu_inputs)

    return return_value
예제 #3
0
def execute(cufn, *v, **k):
    cu_types, cu_inputs = zip(*map(induct, v))
    signature = ','.join([str(x) for x in cu_types])
    if signature in cufn.cache:
        return cufn.cache[signature](*cu_inputs)

    ast = cufn.get_ast()
    name = ast[0].name().id
    code, compiled_fn = \
                 passes.compile(ast,
                                globals=cufn.get_globals(),
                                input_types={name : cu_types},
                                **k)
    cufn.cache[signature] = compiled_fn
    cufn.code[signature] = code
    return_value = compiled_fn(*cu_inputs)

    return return_value