module Environment
(
Environment
, context
, defaultEnv
, emptyContext
, getVerbose
, getColor
, getSki
, getTypes
, getExpressionName
, getTopo
, addBind
, changeColor
, changeVerbose
, changeSkioutput
, changeTypes
, changeTopo
, Filename
, Modulename
)
where
import Data.List
import MultiBimap
import Lambda
type Filename = String
type Modulename = String
data Environment = Environment
{ context :: Context
, loadedFiles :: [Filename]
, verbose :: Bool
, color :: Bool
, skioutput :: Bool
, types :: Bool
, topo :: Bool
}
defaultEnv :: Environment
defaultEnv = Environment
{ context = emptyContext
, loadedFiles = []
, verbose = False
, color = True
, skioutput = False
, types = False
, topo = False
}
getColor, getVerbose, getSki, getTypes, getTopo :: Environment -> Bool
getColor = color
getVerbose = verbose
getSki = skioutput
getTypes = types
getTopo = topo
addBind :: Environment -> String -> Exp -> Environment
addBind env s e =
if s `elem` MultiBimap.lookup e (context env)
then env
else env {context = MultiBimap.insert e s (context env)}
changeVerbose :: Environment -> Bool -> Environment
changeVerbose options setting = options {verbose = setting}
changeColor :: Environment -> Bool -> Environment
changeColor options setting = options {color = setting}
changeSkioutput :: Environment -> Bool -> Environment
changeSkioutput options setting = options {skioutput = setting}
changeTypes :: Environment -> Bool -> Environment
changeTypes options setting = options {types = setting}
changeTopo :: Environment -> Bool -> Environment
changeTopo options setting = options {topo = setting}
getExpressionName :: Environment -> Exp -> Maybe String
getExpressionName environment expr = case MultiBimap.lookup expr (context environment) of
[] -> Nothing
xs -> Just $ intercalate ", " xs
type Context = MultiBimap Exp String
emptyContext :: Context
emptyContext = MultiBimap.empty