# Path: types_builtin.py
# def app_map(data, appTs):
#     apps = {}
#     for tv, at in ezip(data.tvars, appTs):
#         if isinstance(at, TVar) and at.typeVar is tv:
#             continue
#         apps[tv] = at
#     return apps
# 
# def subst(mapping, t):
#     return map_type_vars(lambda st: mapping.get(st.typeVar, st), t)


from base import *
from globs import *
from types_builtin import app_map, subst
            assert field in self.fts, \
                    "%s is not a field {%s}" % (field, ', '.join(self.fts))
            t = self.fts[field]

            # Catch some stupidity
            if len(path) == 1:
                assert t is not None, "Already visited this field!"
                self.fts[field] = None

            assert not isinstance(t, TWeak), \
                    "%s is weak and won't be visited" % (field,)
            obj = getattr(obj, field)
        return visit_by_type(obj, t, bool(path))

def visit_by_type(obj, t, customVisitors=True):
    cls = t.__class__
    if cls in (TVar, TPrim, TFunc, TWeak):
        pass
    elif cls is TTuple:
        assert isinstance(obj, tuple)
        for v, tt in ezip(obj, t.tupleTypes):
            visit_by_type(v, tt)
    elif cls is TData:
        data = t.data
        assert isinstance(obj, extrinsic(TrueRepresentation, data)), \
                "Expected %s, got %s %s" % (data, type(obj), obj)
        apps = t.appTypes and app_map(data, t.appTypes)
        visitor = env(VISIT)

        ctor = extrinsic(FormSpec, type(obj))

# Path: types_builtin.py
# def app_map(data, appTs):
#     apps = {}
#     for tv, at in ezip(data.tvars, appTs):
#         if isinstance(at, TVar) and at.typeVar is tv:
#             continue
#         apps[tv] = at
#     return apps
# 
# def subst(mapping, t):
#     return map_type_vars(lambda st: mapping.get(st.typeVar, st), t)


# Path: vat.py
from base import *
from globs import *
from types_builtin import app_map, subst

            assert field in self.fts, \
                    "%s is not a field {%s}" % (field, ', '.join(self.fts))
            t = self.fts[field]

            # Catch some stupidity
            if len(path) == 1:
                assert t is not None, "Already visited this field!"
                self.fts[field] = None

            assert not isinstance(t, TWeak), \
                    "%s is weak and won't be visited" % (field,)
            obj = getattr(obj, field)
        return visit_by_type(obj, t, bool(path))

def visit_by_type(obj, t, customVisitors=True):
    cls = t.__class__
    if cls in (TVar, TPrim, TFunc, TWeak):
        pass
    elif cls is TTuple:
        assert isinstance(obj, tuple)
        for v, tt in ezip(obj, t.tupleTypes):
            visit_by_type(v, tt)
    elif cls is TData:
        data = t.data
        assert isinstance(obj, extrinsic(TrueRepresentation, data)), \
                "Expected %s, got %s %s" % (data, type(obj), obj)
        apps = t.appTypes and app_map(data, t.appTypes)
        visitor = env(VISIT)

        ctor = extrinsic(FormSpec, type(obj))

        fts = dict((extrinsic(Name, f), subst(apps,f.type) if apps else f.type)