f86af7c940e230305d99412df604a457ec7aceb0
[ghc-hetmet.git] / ghc / tests / programs / callback / Main.hs
1 -- !!! Testing callbacks
2 module Main(main) where
3
4 import IOExts
5 import Addr
6
7 count :: IORef Int -> IO Int
8 count ref = do
9   x <- readIORef ref
10   writeIORef ref (x+1)
11   return x
12
13 createCounter :: IO Addr
14 createCounter = do
15   ref <- newIORef 0
16   mkCounter (count ref)
17
18 foreign export dynamic mkCounter :: (IO Int) -> IO Addr
19
20 main :: IO ()
21 main = do
22   x  <- createCounter
23   v1 <- _casm_GC_ `` do { typedef int (*f)(); %r=(int)((f)%0)();} while (0); '' x
24   print (v1::Int)
25   v2 <- _casm_GC_ `` do { typedef int (*f)(); %r=(int)((f)%0)();} while (0); '' x
26   print (v2::Int)
27