{-# LANGUAGE CPP #-}moduleAgda.TypeChecking.Monad.MetaVarswhereimportControl.ApplicativeimportControl.Monad.StateimportControl.Monad.ReaderimportqualifiedData.MapasMapimportqualifiedData.SetasSetimportAgda.Syntax.InternalimportAgda.Syntax.PositionimportAgda.Syntax.Scope.BaseimportAgda.TypeChecking.Monad.BaseimportAgda.TypeChecking.Monad.EnvimportAgda.TypeChecking.Monad.SignatureimportAgda.TypeChecking.Monad.StateimportAgda.TypeChecking.Monad.TraceimportAgda.TypeChecking.Monad.ClosureimportAgda.TypeChecking.Monad.OpenimportAgda.TypeChecking.SubstituteimportAgda.Utils.MonadimportAgda.Utils.FreshimportAgda.Utils.Permutation#include "../../undefined.h"importAgda.Utils.Impossible-- | Get the meta store.getMetaStore::MonadTCMtcm=>tcmMetaStoregetMetaStore=getsstMetaStore-- | Lookup a meta variablelookupMeta::MonadTCMtcm=>MetaId->tcmMetaVariablelookupMetam=dommv<-Map.lookupm<$>getMetaStorecasemmvofJustmv->returnmv_->fail$"no such meta variable "++showmupdateMetaVar::MonadTCMtcm=>MetaId->(MetaVariable->MetaVariable)->tcm()updateMetaVarmf=modify$\st->st{stMetaStore=Map.adjustfm$stMetaStorest}getMetaPriority::MonadTCMtcm=>MetaId->tcmMetaPrioritygetMetaPriorityi=mvPriority<$>lookupMetaiisSortMeta::MonadTCMtcm=>MetaId->tcmBoolisSortMetam=domv<-lookupMetamreturn$casemvJudgementmvofHasType{}->FalseIsSort{}->TrueisInstantiatedMeta::MonadTCMtcm=>MetaId->tcmBoolisInstantiatedMetam=domv<-lookupMetamreturn$casemvInstantiationmvofInstV{}->TrueInstS{}->True_->FalsecreateMetaInfo::MonadTCMtcm=>tcmMetaInfocreateMetaInfo=dor<-getCurrentRangebuildClosurerupdateMetaVarRange::MonadTCMtcm=>MetaId->Range->tcm()updateMetaVarRangemir=updateMetaVarmi(setRanger)addInteractionPoint::MonadTCMtcm=>InteractionId->MetaId->tcm()addInteractionPointiimi=modify$\s->s{stInteractionPoints=Map.insertiimi$stInteractionPointss}removeInteractionPoint::MonadTCMtcm=>InteractionId->tcm()removeInteractionPointii=modify$\s->s{stInteractionPoints=Map.deleteii$stInteractionPointss}getInteractionPoints::MonadTCMtcm=>tcm[InteractionId]getInteractionPoints=Map.keys<$>getsstInteractionPointsgetInteractionMetas::MonadTCMtcm=>tcm[MetaId]getInteractionMetas=Map.elems<$>getsstInteractionPoints-- | Does the meta variable correspond to an interaction point?isInteractionMeta::MonadTCMtcm=>MetaId->tcmBoolisInteractionMetam=fmap(m`elem`)getInteractionMetaslookupInteractionId::MonadTCMtcm=>InteractionId->tcmMetaIdlookupInteractionIdii=dommi<-Map.lookupii<$>getsstInteractionPointscasemmiofJustmi->returnmi_->fail$"no such interaction point: "++showiijudgementInteractionId::MonadTCMtcm=>InteractionId->tcm(JudgementTypeMetaId)judgementInteractionIdii=domi<-lookupInteractionIdiimvJudgement<$>lookupMetami-- | Generate new meta variable.newMeta::MonadTCMtcm=>MetaInfo->MetaPriority->Permutation->JudgementTypea->tcmMetaIdnewMeta=newMeta'OpennewMeta'::MonadTCMtcm=>MetaInstantiation->MetaInfo->MetaPriority->Permutation->JudgementTypea->tcmMetaIdnewMeta'instmippermj=dox<-freshletmv=MetaVarmipperm(fmap(constx)j)instSet.emptymodify$\st->st{stMetaStore=Map.insertxmv$stMetaStorest}returnxgetInteractionRange::MonadTCMtcm=>InteractionId->tcmRangegetInteractionRangeii=domi<-lookupInteractionIdiigetMetaRangemigetMetaRange::MonadTCMtcm=>MetaId->tcmRangegetMetaRangemi=getRange<$>lookupMetamigetInteractionScope::MonadTCMtcm=>InteractionId->tcmScopeInfogetInteractionScopeii=domi<-lookupInteractionIdiimv<-lookupMetamireturn$getMetaScopemvwithMetaInfo::MonadTCMtcm=>MetaInfo->tcma->tcmawithMetaInfomIm=enterClosuremI$\r->setCurrentRangermgetInstantiatedMetas::MonadTCMtcm=>tcm[MetaId]getInstantiatedMetas=dostore<-getMetaStorereturn[i|(i,MetaVar{mvInstantiation=mi})<-Map.assocsstore,isInstmi]whereisInstOpen=FalseisInst(BlockedConst_)=FalseisInst(PostponedTypeCheckingProblem_)=FalseisInst(InstV_)=TrueisInst(InstS_)=TruegetOpenMetas::MonadTCMtcm=>tcm[MetaId]getOpenMetas=dostore<-getMetaStorereturn[i|(i,MetaVar{mvInstantiation=mi})<-Map.assocsstore,isOpenmi]whereisOpenOpen=TrueisOpen(BlockedConst_)=TrueisOpen(PostponedTypeCheckingProblem_)=TrueisOpen(InstV_)=FalseisOpen(InstS_)=False-- | @listenToMeta l m@: register @l@ as a listener to @m@. This is done-- when the type of l is blocked by @m@.listenToMeta::MonadTCMtcm=>MetaId->MetaId->tcm()listenToMetalm=updateMetaVarm$\mv->mv{mvListeners=Set.insertl$mvListenersmv}-- | Unregister a listener.unlistenToMeta::MonadTCMtcm=>MetaId->MetaId->tcm()unlistenToMetalm=updateMetaVarm$\mv->mv{mvListeners=Set.deletel$mvListenersmv}-- | Get the listeners to a meta.getMetaListeners::MonadTCMtcm=>MetaId->tcm[MetaId]getMetaListenersm=Set.toList.mvListeners<$>lookupMetamclearMetaListeners::MonadTCMtcm=>MetaId->tcm()clearMetaListenersm=updateMetaVarm$\mv->mv{mvListeners=Set.empty}