From ceb975cd26d39b4839d6f20b252972fa4756d24c Mon Sep 17 00:00:00 2001 From: sof Date: Tue, 2 Nov 1999 11:55:02 +0000 Subject: [PATCH] [project @ 1999-11-02 11:55:02 by sof] Simple example of callback'ery in action --- ghc/tests/programs/callback/Main.hs | 27 +++++++++++++++++++++++++++ ghc/tests/programs/callback/Makefile | 10 ++++++++++ 2 files changed, 37 insertions(+) create mode 100644 ghc/tests/programs/callback/Main.hs create mode 100644 ghc/tests/programs/callback/Makefile diff --git a/ghc/tests/programs/callback/Main.hs b/ghc/tests/programs/callback/Main.hs new file mode 100644 index 0000000..f86af7c --- /dev/null +++ b/ghc/tests/programs/callback/Main.hs @@ -0,0 +1,27 @@ +-- !!! Testing callbacks +module Main(main) where + +import IOExts +import Addr + +count :: IORef Int -> IO Int +count ref = do + x <- readIORef ref + writeIORef ref (x+1) + return x + +createCounter :: IO Addr +createCounter = do + ref <- newIORef 0 + mkCounter (count ref) + +foreign export dynamic mkCounter :: (IO Int) -> IO Addr + +main :: IO () +main = do + x <- createCounter + v1 <- _casm_GC_ `` do { typedef int (*f)(); %r=(int)((f)%0)();} while (0); '' x + print (v1::Int) + v2 <- _casm_GC_ `` do { typedef int (*f)(); %r=(int)((f)%0)();} while (0); '' x + print (v2::Int) + diff --git a/ghc/tests/programs/callback/Makefile b/ghc/tests/programs/callback/Makefile new file mode 100644 index 0000000..8eb5c96 --- /dev/null +++ b/ghc/tests/programs/callback/Makefile @@ -0,0 +1,10 @@ +TOP = .. +include $(TOP)/mk/boilerplate.mk + +SRC_HC_OPTS += -fglasgow-exts + +CC = $(HC) + +all :: runtest + +include $(TOP)/mk/target.mk -- 1.7.10.4