Ejemplo n.º 1
0
def substitute(solution, t):
    """
    Substitute bound parameters for the corresponding free variables
    """
    def f(t):
        if isinstance(t, TypeVar):
            return solution.get(t.symbol, t)
        return t

    return ds.tmap(f, t)
Ejemplo n.º 2
0
def substitute(solution, t):
    """
    Substitute bound parameters for the corresponding free variables
    """
    def f(t):
        if isinstance(t, TypeVar):
            return solution.get(t.symbol, t)
        return t

    return ds.tmap(f, t)
Ejemplo n.º 3
0
def resolve_in_scope(ty, scope):
    """
    Resolve a parsed type in the current scope. For example, if we parse
    Foo[X], look up Foo in the current scope and reconstruct it with X.
    """
    def resolve(t):
        if isinstance(type(t), TypeConstructor):
            name = type(t).name

            # Get the @jit class (e.g. Int)
            if hasattr(t, 'impl'):
                impl = t.impl  # already resolved!
            else:
                impl = scope.get(name) or lookup_builtin_type(name)

            if impl is None:
                raise TypeError(
                    "Type constructor %r is not in the current scope" %
                    (name, ))

            # Get the TypeConstructor for the @jit class (e.g.
            # Int[nbits, unsigned])
            ctor = impl.type.__class__

            return ctor(*t.parameters)

        elif isinstance(t, TypeVar) and t.symbol[0].isupper():
            # Resolve bare types, e.g. a name like 'NoneType' is parsed as a
            # TypeVar
            if t.symbol == 'NoneType':
                assert t.symbol in scope
            if scope.get(t.symbol):
                cls = scope[t.symbol]
                return cls[()]
            return t

        return t

    freevars = dict((v.symbol, v) for v in free(ty))
    return ds.tmap(resolve, ty)
Ejemplo n.º 4
0
def resolve_in_scope(ty, scope):
    """
    Resolve a parsed type in the current scope. For example, if we parse
    Foo[X], look up Foo in the current scope and reconstruct it with X.
    """
    def resolve(t):
        if isinstance(type(t), TypeConstructor):
            name = type(t).name

            # Get the @jit class (e.g. Int)
            if hasattr(t, 'impl'):
                impl = t.impl # already resolved!
            else:
                impl = scope.get(name) or lookup_builtin_type(name)

            if impl is None:
                raise TypeError(
                    "Type constructor %r is not in the current scope" % (name,))

            # Get the TypeConstructor for the @jit class (e.g.
            # Int[nbits, unsigned])
            ctor = impl.type.__class__

            return ctor(*t.parameters)

        elif isinstance(t, TypeVar) and t.symbol[0].isupper():
            # Resolve bare types, e.g. a name like 'NoneType' is parsed as a
            # TypeVar
            if t.symbol == 'NoneType':
                assert t.symbol in scope
            if scope.get(t.symbol):
                cls = scope[t.symbol]
                return cls[()]
            return t

        return t

    freevars = dict((v.symbol, v) for v in free(ty))
    return ds.tmap(resolve, ty)
Ejemplo n.º 5
0
def to_blaze(t):
    replacements = dict((v, k) for k, v in typemap().iteritems())
    return ds.tmap(lambda x: replacements.get(x, x), t)
Ejemplo n.º 6
0
def resolve_type(t):
    _blaze2flypy = typemap()
    return ds.tmap(lambda x: _blaze2flypy.get(x, x), t)
Ejemplo n.º 7
0
def to_blaze(t):
    replacements = dict((v, k) for k, v in typemap().iteritems())
    return ds.tmap(lambda x: replacements.get(x, x), t)
Ejemplo n.º 8
0
def resolve_type(t):
    _blaze2flypy = typemap()
    return ds.tmap(lambda x: _blaze2flypy.get(x, x), t)