module Vectorise.Monad.Local (
readLEnv,
setLEnv,
updLEnv,
localV,
closedV,
getBindName,
inBind,
lookupTyVarPA,
defLocalTyVar,
defLocalTyVarWithPA,
localTyVars
) where
import Vectorise.Monad.Base
import Vectorise.Env
import CoreSyn
import Name
import VarEnv
import Var
import FastString
readLEnv :: (LocalEnv -> a) -> VM a
readLEnv f = VM $ \_ genv lenv -> return (Yes genv lenv (f lenv))
setLEnv :: LocalEnv -> VM ()
setLEnv lenv = VM $ \_ genv _ -> return (Yes genv lenv ())
updLEnv :: (LocalEnv -> LocalEnv) -> VM ()
updLEnv f = VM $ \_ genv lenv -> return (Yes genv (f lenv) ())
localV :: VM a -> VM a
localV p
= do env <- readLEnv id
x <- p
setLEnv env
return x
closedV :: VM a -> VM a
closedV p
= do env <- readLEnv id
setLEnv (emptyLocalEnv { local_bind_name = local_bind_name env })
x <- p
setLEnv env
return x
getBindName :: VM FastString
getBindName = readLEnv local_bind_name
inBind :: Id -> VM a -> VM a
inBind id p
= do updLEnv $ \env -> env { local_bind_name = occNameFS (getOccName id) }
p
lookupTyVarPA :: Var -> VM (Maybe CoreExpr)
lookupTyVarPA tv
= readLEnv $ \env -> lookupVarEnv (local_tyvar_pa env) tv
defLocalTyVar :: TyVar -> VM ()
defLocalTyVar tv = updLEnv $ \env ->
env { local_tyvars = tv : local_tyvars env
, local_tyvar_pa = local_tyvar_pa env `delVarEnv` tv
}
defLocalTyVarWithPA :: TyVar -> CoreExpr -> VM ()
defLocalTyVarWithPA tv pa = updLEnv $ \env ->
env { local_tyvars = tv : local_tyvars env
, local_tyvar_pa = extendVarEnv (local_tyvar_pa env) tv pa
}
localTyVars :: VM [TyVar]
localTyVars = readLEnv (reverse . local_tyvars)