0N/ACopyright : (c) Klaus L�ttich, C. Maeder, Uni Bremen 2002-2006
0N/AMaintainer : maeder@tzi.de
0N/AStability : provisional
0N/Adata types and utilities for shared ATerms and the ATermTable
0N/A getATerm, toReadonlyATT,
1472N/A getATerm', setATerm', getShATerm,
1472N/A Key, newATermTable, getKey, setKey, mkKey,
0N/A getATermByIndex1, str2Char, integer2Int
data ShATerm = ShAAppl String [Int] [Int]
data IntMap = Updateable !(
IntMap.Map Int ShATerm)
| Readonly !(Array Int ShATerm)
insert :: Int -> ShATerm -> IntMap -> IntMap
find :: Int -> IntMap -> ShATerm
data EqKey = EqKey (StableName ()) TypeRep deriving Eq
mkKey :: Typeable a => a -> IO Key
return $ Key (hashStableName s) $ EqKey (unsafeCoerce# s) $ typeOf t
toReadonlyATT :: ATermTable -> ATermTable
toReadonlyATT (ATT h s t i dM) = ATT h s
Updateable m -> Readonly $ listArray (0, i) $
IntMap.elems m
emptyATermTable :: ATermTable
newATermTable :: IO ATermTable
newATermTable = return $ emptyATermTable
addATermNoFullSharing :: ShATerm -> ATermTable -> (ATermTable, Int)
addATermNoFullSharing t (ATT h a_iDFM i_aDFM i1 dM) = let j = i1 + 1 in
(ATT h (
Map.insert t j a_iDFM) (insert j t i_aDFM) j dM, j)
addATerm :: ShATerm -> ATermTable -> (ATermTable, Int)
addATerm t at@(ATT _ a_iDFM _ _ _) =
Nothing -> addATermNoFullSharing t at
setKey :: Key -> Int -> ATermTable -> IO (ATermTable, Int)
setKey (Key h e) i (ATT t s l m d) =
getKey :: Key -> ATermTable -> IO (Maybe Int)
getKey (Key h k) (ATT t _ _ _ _) =
getATerm :: ATermTable -> ShATerm
getATerm (ATT _ _ i_aFM i _) = find i i_aFM
getShATerm :: Int -> ATermTable -> ShATerm
getShATerm i (ATT _ _ i_aFM _ _) = find i i_aFM
getTopIndex :: ATermTable -> Int
getTopIndex (ATT _ _ _ i _) = i
getATermByIndex1 :: Int -> ATermTable -> ATermTable
getATermByIndex1 i (ATT h a_iDFM i_aDFM _ dM) = ATT h a_iDFM i_aDFM i dM
getATerm' :: Typeable t => Int -> ATermTable -> Maybe t
getATerm' i (ATT _ _ _ _ dM) =
setATerm' :: Typeable t => Int -> t -> ATermTable -> ATermTable
setATerm' i t (ATT h a_iDFM i_aDFM m dM) =
-- | conversion of a string in double quotes to a character
str2Char :: String -> Char
str2Char ('\"' : sr) = conv' (init sr) where
conv' ['\\', x] = case x of
conv' _ = error "String not convertible to char"
str2Char _ = error "String doesn't begin with '\"'"
-- | conversion of an unlimited integer to a machine int
integer2Int :: Integer -> Int
integer2Int x = if toInteger ((fromInteger :: Integer -> Int) x) == x
else error $ "Integer to big for Int: " ++ show x