Interpreter.hs revision 98890889ffb2e8f6f722b00e265a211f13b5a861
{-# LANGUAGE FlexibleInstances, UndecidableInstances, OverlappingInstances, MultiParamTypeClasses #-}
License : GPLv2 or higher, see LICENSE.txt
module CSL.Interpreter where
import Control.Monad (liftM, forM_, filterM, unless)
import Control.Monad.State (State, MonadState (..))
import Control.Monad.Trans (MonadTrans (..), MonadIO (..))
import Data.Maybe
import qualified Data.Map as Map
import qualified Data.IntMap as IMap
import Data.List (mapAccumL)
import Common.ResultT
import CSL.AS_BASIC_CSL
instance CalculationSystem (State (Map.Map String EXPRESSION)) where
assign n e = liftM (Map.insert n e) get >> return ()
clookup n = liftM (Map.lookup n) get
names = liftM Map.keys get
data BMap = BMap { mThere :: Map.Map String Int
, mBack :: IMap.IntMap String
data BMapDefault = BMapDefault { mThr :: Map.Map String String
, mBck :: Map.Map String String }
defaultLookup bmd s = Map.lookup s $ mThr bmd
defaultRevlookup bmd s = Map.lookup s $ mBck bmd
(mNv', nm) = Map.insertLookupWithKey f k nv $ mThere m
, mBack = IMap.insert nv k $ mBack m
in IMap.findWithDefault err i $ mBack m
in map f $ Map.toList $ mThere m