2 % (c) The AQUA Project, Glasgow University, 1994-2000
6 {-# OPTIONS -fno-implicit-prelude #-}
13 hugsprimPmFromInteger,
16 hugsprimRunIO_toplevel,
20 hugsprimCreateAdjThunk,
30 import PrelReal(Integral)
31 import Prelude(fromIntegral)
32 import IO(putStr,hFlush,stdout,stderr)
33 import PrelException(catch)
34 import PrelIOBase(IO,unsafePerformIO)
36 import PrelFloat(Double)
37 import PrelReal(Fractional,fromRational,toRational)
40 import PrelPack(unpackCString)
42 -- Stuff needed by Hugs for desugaring. Do not mess with these!
43 -- They need to correspond exactly to versions written in
44 -- the Hugs standalone Prelude.
46 --hugs doesn't know about RealWorld and so throws this
47 --away if the original type signature is used
48 --hugsprimMkIO :: (RealWorld -> (a,RealWorld)) -> IO a
49 hugsprimMkIO :: (rw -> (a,rw)) -> IO a
51 = error "hugsprimMkIO in combined mode: unimplemented"
53 hugsprimCreateAdjThunk :: (a -> b) -> String -> Char -> IO Addr
54 hugsprimCreateAdjThunk fun typestr callconv
55 = error "hugsprimCreateAdjThunk in combined mode: unimplemented"
57 fromDouble :: Fractional a => Double -> a
58 fromDouble n = fromRational (toRational n)
60 hugsprimEqChar :: Char -> Char -> Bool
61 hugsprimEqChar c1 c2 = c1 == c2
63 hugsprimPmInt :: Num a => Int -> a -> Bool
64 hugsprimPmInt n x = fromInt n == x
66 hugsprimPmInteger :: Num a => Integer -> a -> Bool
67 hugsprimPmInteger n x = fromInteger n == x
69 hugsprimPmDouble :: Fractional a => Double -> a -> Bool
70 hugsprimPmDouble n x = fromDouble n == x
72 -- The following primitives are only needed if (n+k) patterns are enabled:
73 hugsprimPmSub :: Integral a => Int -> a -> a
74 hugsprimPmSub n x = x - fromInt n
76 hugsprimPmFromInteger :: Integral a => Integer -> a
77 hugsprimPmFromInteger = fromIntegral
79 hugsprimPmSubtract :: Integral a => a -> a -> a
80 hugsprimPmSubtract x y = x - y
82 hugsprimPmLe :: Integral a => a -> a -> Bool
83 hugsprimPmLe x y = x <= y
85 hugsprimUnpackString :: Addr -> String
86 hugsprimUnpackString a = unpackCString a
88 -- ToDo: make the message more informative.
90 hugsprimPmFail = error "Pattern Match Failure"
92 hugsprimCompAux :: Ord a => a -> a -> Ordering -> Ordering
93 hugsprimCompAux x y o = case compare x y of EQ -> o; LT -> LT; GT -> GT
95 hugsprimError :: String -> a
96 hugsprimError s = error s
98 -- used when Hugs invokes top level function
100 hugsprimRunIO_toplevel :: IO a -> ()
101 hugsprimRunIO_toplevel m
102 = protect 5 (fst (unST composite_action realWorld))
105 = do writeIORef prelCleanupAfterRunAction Nothing
107 cleanup_handles <- readIORef prelCleanupAfterRunAction
108 case cleanup_handles of
112 realWorld = error "primRunIO: entered the RealWorld"
113 protect :: Int -> () -> ()
117 = primCatch (protect (n-1) comp)
118 (\e -> fst (unST (putStr (show e ++ "\n")) realWorld))
120 hugsprimRunIO_toplevel :: IO a -> ()
121 hugsprimRunIO_toplevel m
123 catch (m >> hFlush stderr >> hFlush stdout)
124 (\e -> putStr (show e ++ "\n"))