# 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 bedrock import *
from globs import *
from hashlib import sha256
from os import system
from types_builtin import app_map, subst
                _serialize_node(item, et)
    else:
        assert False, "Can't serialize %r" % (node,)

InspectState = DT('InspectState', ('module', '*Module'), ('count', int))

Inspection = new_env('Inspection', InspectState)

def _inspect_node(node, t):
    if isinstance(node, Structured):
        dtform, appTs = match(t, ("TData(dt, apps)", tuple2))
        # Collect instantiations
        apps = app_map(dtform, appTs)
        adt = extrinsic(TrueRepresentation, dtform)
        assert isinstance(node, adt), "%s %r is not a %s" % (
                type(node), node, adt)
        # If this is not a value type, record its index
        if not dtform.opts.valueType:
            assert not has_extrinsic(Location, node), \
                    "Multiply used %r" % (node,)
            state = env(Inspection)
            state.count += 1
            add_extrinsic(Location, node, Pos(state.module, state.count))

        # Inspect fields
        form = dtform.ctors[node._ctor_ix if len(dtform.ctors) > 1 else 0]
        ctor = extrinsic(TrueRepresentation, form)
        assert isinstance(node, ctor), "%r is not a %s" % (node, ctor)
        for field in form.fields:
            sub = getattr(node, extrinsic(Name, field))

# 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: native.py
from base import *
from bedrock import *
from globs import *
from hashlib import sha256
from os import system
from types_builtin import app_map, subst

                _serialize_node(item, et)
    else:
        assert False, "Can't serialize %r" % (node,)

InspectState = DT('InspectState', ('module', '*Module'), ('count', int))

Inspection = new_env('Inspection', InspectState)

def _inspect_node(node, t):
    if isinstance(node, Structured):
        dtform, appTs = match(t, ("TData(dt, apps)", tuple2))
        # Collect instantiations
        apps = app_map(dtform, appTs)
        adt = extrinsic(TrueRepresentation, dtform)
        assert isinstance(node, adt), "%s %r is not a %s" % (
                type(node), node, adt)
        # If this is not a value type, record its index
        if not dtform.opts.valueType:
            assert not has_extrinsic(Location, node), \
                    "Multiply used %r" % (node,)
            state = env(Inspection)
            state.count += 1
            add_extrinsic(Location, node, Pos(state.module, state.count))

        # Inspect fields
        form = dtform.ctors[node._ctor_ix if len(dtform.ctors) > 1 else 0]
        ctor = extrinsic(TrueRepresentation, form)
        assert isinstance(node, ctor), "%r is not a %s" % (node, ctor)
        for field in form.fields:
            sub = getattr(node, extrinsic(Name, field))

            ft = subst(apps, field.type)