From 1aa16d867ac9164a2d05ae8450ef506224c8ebb7 Mon Sep 17 00:00:00 2001 From: rrt Date: Wed, 10 May 2000 12:17:35 +0000 Subject: [PATCH] [project @ 2000-05-10 12:17:35 by rrt] Tried to bring this test into the modern age. Failed. I've committed the pieces to be picked up later. --- ghc/tests/io/stable001/Main.hs | 26 ++++++++++++++++++++++++++ ghc/tests/io/stable001/Makefile | 5 +++++ ghc/tests/io/stable001/cbits.c | 20 ++++++++++++++++++++ 3 files changed, 51 insertions(+) create mode 100644 ghc/tests/io/stable001/Main.hs create mode 100644 ghc/tests/io/stable001/cbits.c diff --git a/ghc/tests/io/stable001/Main.hs b/ghc/tests/io/stable001/Main.hs new file mode 100644 index 0000000..d0cb982 --- /dev/null +++ b/ghc/tests/io/stable001/Main.hs @@ -0,0 +1,26 @@ +-- This is a rather exciting experiment in using the new call +-- makeStablePtr# and performIO. It doesn't do much but it took an +-- incredible effort to get it to do it. + +import Stable +import GlaExts +import CString + +-- module Main(main) where + +main = makeStablePtr test >>= \ stablePtr -> + ((_casm_GC_ ``SaveAllStgRegs(); test1(%0); RestoreAllStgRegs();'' stablePtr) + :: PrimIO ()) + >>= \ _ -> + return () + +test :: IO Int +test = + let f x = sum [1..x] + f :: Int -> Int + in + _ccall_ printf + (packString "The stable pointer has just been used to print this number %d\n") (f 100) + >>= \ _ -> + return 5 + diff --git a/ghc/tests/io/stable001/Makefile b/ghc/tests/io/stable001/Makefile index f3b9242..0f67c21 100644 --- a/ghc/tests/io/stable001/Makefile +++ b/ghc/tests/io/stable001/Makefile @@ -1,5 +1,10 @@ TOP = ../.. include $(TOP)/mk/boilerplate.mk SRC_HC_OPTS += -fglasgow-exts +include $(TOP)/mk/should_run.mk + +HC_OPTS += -dcore-lint + +.PRECIOUS: %.o %.bin include $(TOP)/mk/target.mk diff --git a/ghc/tests/io/stable001/cbits.c b/ghc/tests/io/stable001/cbits.c new file mode 100644 index 0000000..dfa8753 --- /dev/null +++ b/ghc/tests/io/stable001/cbits.c @@ -0,0 +1,20 @@ +#define NULL_REG_MAP +#include "../../../includes/Stg.h" + +int +test1( stableIOPtr ) + StgStablePtr stableIOPtr; +{ + int i; + int result; + + printf("Using stable pointer %x\n", stableIOPtr); + + for( i = 0; i != 10; i = i + 1 ) { + printf( "Calling stable pointer for %dth time\n", i ); + performIO( stableIOPtr ); + printf( "Returned after stable pointer\n" ); + } + + return 1; +} -- 1.7.10.4