Exemple #1
0
def can_coerce(src_type, dst_type):
    """
    Check whether we can coerce a value of type `src_type` to a value
    of type `dst_type`
    """
    from flypy.compiler.overloading import best_match

    try:
        best_match(coerce, [src_type, Type[dst_type]])
    except TypeError:
        return False
    else:
        return True
Exemple #2
0
def can_coerce(src_type, dst_type):
    """
    Check whether we can coerce a value of type `src_type` to a value
    of type `dst_type`
    """
    from flypy.compiler.overloading import best_match

    try:
        best_match(coerce, [src_type, Type[dst_type]])
    except TypeError:
        return False
    else:
        return True
Exemple #3
0
def setup(func, env):
    """
    Set up function's environment. Very first pass that runs in the pipeline.
    """
    from flypy.compiler.overloading import best_match

    # -------------------------------------------------
    # Find Python function implementation

    argtypes = simplify_argtypes(func, env)
    try:
        py_func, signature, kwds = best_match(func, list(argtypes))
    except TypeError:
        print("type error", func, list(argtypes))
        raise

    # -------------------------------------------------
    # Update environment
    env["flypy.state.func_name"] = py_func.__name__
    env["flypy.state.function_wrapper"] = func
    env["flypy.state.opaque"] = func.opaque
    env["flypy.typing.restype"] = signature.restype
    env["flypy.typing.argtypes"] = signature.argtypes
    env["flypy.state.crnt_func"] = func
    env["flypy.state.options"] = dict(kwds)
    env["flypy.state.copies"] = {}

    if kwds.get("infer_restype"):
        env["flypy.typing.restype"] = kwds["infer_restype"](argtypes)

    return py_func, env
Exemple #4
0
def setup(func, env):
    """
    Set up function's environment. Very first pass that runs in the pipeline.
    """
    from flypy.compiler.overloading import best_match

    # -------------------------------------------------
    # Find Python function implementation

    argtypes = simplify_argtypes(func, env)
    py_func, signature, kwds = best_match(func, list(argtypes))

    # -------------------------------------------------
    # Update environment
    env["flypy.state.func_name"] = py_func.__name__
    env["flypy.state.function_wrapper"] = func
    env["flypy.state.opaque"] = func.opaque
    env["flypy.typing.restype"] = signature.restype
    env["flypy.typing.argtypes"] = signature.argtypes
    env["flypy.state.crnt_func"] = func
    env["flypy.state.options"] = dict(kwds)
    env["flypy.state.copies"] = {}

    if kwds.get("infer_restype"):
        env["flypy.typing.restype"] = kwds["infer_restype"](argtypes)

    return py_func, env