# Path: globs.py
# WRITTEN_MODULES = {}
# RUNTIME_MODULE_OBJS = {
#     'runtime.py': 'ir/z.o',
#     'gc/interface.py': 'ir/gc_runtime.o',
# }


from atom import *
from base import *
from types_builtin import *
from globs import TypeOf, ResultOf
import vat
CType, C, CMeta = ADT(('CType', Type),
        'CMeta', ('cell', MetaCell))

CType.__repr__ = cyclic_check_type_repr

PendingType = new_extrinsic('PendingType', CType)

def CInt(): return C.TPrim(PInt())
def CFloat(): return C.TPrim(PFloat())
def CBool(): return C.TPrim(PBool())
def CStr(): return C.TPrim(PStr())

InstInfo = DT('InstInfo', ('metas', {TypeVar: CType}),
                          ('hintLookup', {TypeVar: Type}))
INST = new_env('INST', {TypeVar: Type})

# direct transformation to C* (hacky reuse of _inst_type)
SUBST = new_env('SUBST', {'*TypeVar': Type})

def fresh():
    return CMeta(Free(Nothing()))

def fresh_from(tv):
    return CMeta(InstVar(tv))

def fresh_monotype():
    return CMeta(Mono())

def inst_tvar(tv):
    if have_env(SUBST):

# Path: globs.py
# WRITTEN_MODULES = {}
# RUNTIME_MODULE_OBJS = {
#     'runtime.py': 'ir/z.o',
#     'gc/interface.py': 'ir/gc_runtime.o',
# }


# Path: prop.py
from atom import *
from base import *
from types_builtin import *
from globs import TypeOf, ResultOf
import vat

CType, C, CMeta = ADT(('CType', Type),
        'CMeta', ('cell', MetaCell))

CType.__repr__ = cyclic_check_type_repr

PendingType = new_extrinsic('PendingType', CType)

def CInt(): return C.TPrim(PInt())
def CFloat(): return C.TPrim(PFloat())
def CBool(): return C.TPrim(PBool())
def CStr(): return C.TPrim(PStr())

InstInfo = DT('InstInfo', ('metas', {TypeVar: CType}),
                          ('hintLookup', {TypeVar: Type}))
INST = new_env('INST', {TypeVar: Type})

# direct transformation to C* (hacky reuse of _inst_type)
SUBST = new_env('SUBST', {'*TypeVar': Type})

def fresh():
    return CMeta(Free(Nothing()))

def fresh_from(tv):
    return CMeta(InstVar(tv))

def fresh_monotype():
    return CMeta(Mono())

def inst_tvar(tv):
    if have_env(SUBST):

        return env(SUBST).get(tv, C.TVar(tv))