[project @ 2000-11-20 16:28:29 by simonmar]
[ghc-hetmet.git] / ghc / compiler / utils / Util.lhs
index ba730e9..78aec40 100644 (file)
@@ -24,6 +24,9 @@ module Util (
        -- for-loop
        nTimes,
 
+       -- maybe-ish
+       unJust,
+
        -- sorting
        IF_NOT_GHC(quicksort COMMA stableSortLt COMMA mergesort COMMA)
        sortLt,
@@ -53,15 +56,29 @@ module Util (
 #endif
 
        , global
+       , myGetProcessID
+
+#if __GLASGOW_HASKELL__ <= 408
+       , catchJust
+       , ioErrors
+       , throwTo
+#endif
 
     ) where
 
 #include "HsVersions.h"
 
 import List            ( zipWith4 )
+import Maybe           ( Maybe(..) )
 import Panic           ( panic )
 import IOExts          ( IORef, newIORef, unsafePerformIO )
-
+import FastTypes
+#if __GLASGOW_HASKELL__ <= 408
+import Exception       ( catchIO, justIoErrors, raiseInThread )
+#endif
+#ifndef mingw32_TARGET_OS
+import Posix
+#endif
 infixr 9 `thenCmp`
 \end{code}
 
@@ -114,6 +131,17 @@ nTimes 1 f = f
 nTimes n f = f . nTimes (n-1) f
 \end{code}
 
+%************************************************************************
+%*                                                                     *
+\subsection{Maybe-ery}
+%*                                                                     *
+%************************************************************************
+
+\begin{code}
+unJust :: String -> Maybe a -> a
+unJust who (Just x) = x
+unJust who Nothing  = panic ("unJust of Nothing, called by " ++ who)
+\end{code}
 
 %************************************************************************
 %*                                                                     *
@@ -249,20 +277,20 @@ notElem__ x (y:ys) =  x /= y && notElem__ x ys
 
 # else {- DEBUG -}
 isIn msg x ys
-  = elem ILIT(0) x ys
+  = elem (_ILIT 0) x ys
   where
     elem i _ []            = False
     elem i x (y:ys)
-      | i _GE_ ILIT(100) = panic ("Over-long elem in: " ++ msg)
-      | otherwise       = x == y || elem (i _ADD_ ILIT(1)) x ys
+      | i ># _ILIT 100 = panic ("Over-long elem in: " ++ msg)
+      | otherwise       = x == y || elem (i +# _ILIT(1)) x ys
 
 isn'tIn msg x ys
-  = notElem ILIT(0) x ys
+  = notElem (_ILIT 0) x ys
   where
     notElem i x [] =  True
     notElem i x (y:ys)
-      | i _GE_ ILIT(100) = panic ("Over-long notElem in: " ++ msg)
-      | otherwise       =  x /= y && notElem (i _ADD_ ILIT(1)) x ys
+      | i ># _ILIT 100 = panic ("Over-long notElem in: " ++ msg)
+      | otherwise       =  x /= y && notElem (i +# _ILIT(1)) x ys
 
 # endif {- DEBUG -}
 
@@ -703,3 +731,19 @@ global :: a -> IORef a
 global a = unsafePerformIO (newIORef a)
 \end{code}
 
+Compatibility stuff:
+
+\begin{code}
+#if __GLASGOW_HASKELL__ <= 408
+catchJust = catchIO
+ioErrors  = justIoErrors
+throwTo   = raiseInThread
+#endif
+
+#ifdef mingw32_TARGET_OS
+foreign import "_getpid" myGetProcessID :: IO Int 
+#else
+myGetProcessID :: IO Int
+myGetProcessID = Posix.getProcessID
+#endif
+\end{code}