Beispiel #1
0
def _best_match(func_wrapper, argtypes):
    overloaded = func_wrapper.resolve_dispatcher()
    argtypes = [to_blaze(t) for t in argtypes]

    overload = overloading.best_match(overloaded, argtypes)
    scope = determine_scope(overload.func)
    signature = resolve(overload.resolved_sig, scope, {})
    return (overload.func, signature, overload.kwds)
Beispiel #2
0
def _best_match(func_wrapper, argtypes):
    overloaded = func_wrapper.resolve_dispatcher()
    argtypes = [to_blaze(t) for t in argtypes]

    overload = overloading.best_match(overloaded, argtypes)
    scope = determine_scope(overload.func)
    signature = resolve(overload.resolved_sig, scope, {})
    return (overload.func, signature, overload.kwds)
Beispiel #3
0
def promote(type1, type2):
    """Promote two types to a common type"""
    from flypy.compiler.typing import inference

    if type1 == type2:
        return type1
    elif (type(type1), type(type2)) == (inference.Method, inference.Method):
        # promote Method types
        # TODO: Bit of a hack, do this better
        func1, obj1 = type1.parameters
        func2, obj2 = type2.parameters
        result = promote(obj1, obj2)
        if result == obj1:
            return type1
        elif result == obj2:
            return type2
        else:
            raise TypeError("Cannot promote methods %s and %s" % (type1, type2))
    else:
        t1, t2 = to_blaze(type1), to_blaze(type2)
        result = ds.promote(t1, t2)
        return resolve_type(result)
Beispiel #4
0
def promote(type1, type2):
    """Promote two types to a common type"""
    from flypy.compiler.typing import inference

    if type1 == type2:
        return type1
    elif (type(type1), type(type2)) == (inference.Method, inference.Method):
        # promote Method types
        # TODO: Bit of a hack, do this better
        func1, obj1 = type1.parameters
        func2, obj2 = type2.parameters
        result = promote(obj1, obj2)
        if result == obj1:
            return type1
        elif result == obj2:
            return type2
        else:
            raise TypeError("Cannot promote methods %s and %s" %
                            (type1, type2))
    else:
        t1, t2 = to_blaze(type1), to_blaze(type2)
        result = ds.promote(t1, t2)
        return resolve_type(result)
Beispiel #5
0
def populate_dispatcher(dispatcher, overloads):
    """
    Populate dispatcher with the given overloads.
    """
    from flypy.typing import resolve, to_blaze

    for py_func, signature, kwds in overloads:
        if not signature:
            signature = dummy_signature(py_func)
        else:
            # Resolve the signature in its scope, that is resolve any dummy
            # blaze TypeConstructor objects to the types from the scope
            scope = determine_scope(py_func)
            bound = {} # TODO:
            signature = resolve(signature, scope, bound)
            # Use blaze's coercion rules for now
            signature = to_blaze(signature)

        overload(signature, dispatcher=dispatcher, **kwds)(py_func)
Beispiel #6
0
def populate_dispatcher(dispatcher, overloads):
    """
    Populate dispatcher with the given overloads.
    """
    from flypy.typing import resolve, to_blaze

    for py_func, signature, kwds in overloads:
        if not signature:
            signature = dummy_signature(py_func)
        else:
            # Resolve the signature in its scope, that is resolve any dummy
            # blaze TypeConstructor objects to the types from the scope
            scope = determine_scope(py_func)
            bound = {}  # TODO:
            signature = resolve(signature, scope, bound)
            # Use blaze's coercion rules for now
            signature = to_blaze(signature)

        overload(signature, dispatcher=dispatcher, **kwds)(py_func)