Commit 136e0eee authored by simonmar's avatar simonmar
Browse files

[project @ 2001-08-20 14:44:05 by simonmar]

This StablePtr test is old, most of the features it uses are
deprecated and have been replaced by newer mechanisms (eg. foreign
export) which is tested elsewhere.
parent 6184716f
TOP = ..
include $(TOP)/mk/boilerplate.mk
SUBDIRS = should_run
include $(TOP)/mk/target.mk
-- 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
\begin{code}
module Main(main) where
--import PreludeGlaST
--old:import GHCio(stThen)
--old:import PreludeGlaMisc
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
"The stable pointer has just been used to print this number %d\n" (f 100)
>>= \ _ ->
return 5
\end{code}
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.
\begin{code}[C-code]
#define NULL_REG_MAP
#include "stgdefs.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;
}
\end{code}
TOP = ../..
include $(TOP)/mk/boilerplate.mk
SRC_HC_OPTS += -fglasgow-exts
include $(TOP)/mk/should_run.mk
SRC_HC_OPTS += -dcore-lint
.PRECIOUS: %.o %.bin
include $(TOP)/mk/target.mk
#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;
}
#define UpdateStgRegs _SaveStgRegs()
#define ReloadStgRegs _RestoreStgRegs()
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment