2 % (c) The AQUA Project, Glasgow University, 1994-1996
5 \section[Foreign]{Module @Foreign@}
10 ForeignObj -- abstract, instance of: Eq
11 , makeForeignObj -- :: Addr{-obj-} -> IO ForeignObj
12 , writeForeignObj -- :: ForeignObj -> Addr{-new obj-} -> IO ()
13 , addForeignFinaliser -- :: ForeignObj -> IO () -> IO ()
14 , foreignObjToAddr -- :: ForeignObj -> IO Addr
15 -- the coercion from a foreign obj. to an addr. is unsafe,
16 -- and should not be used unless absolutely necessary.
18 , StablePtr {-a-} -- abstract.
19 , makeStablePtr -- :: a -> IO (StablePtr a)
20 , deRefStablePtr -- :: StablePtr a -> IO a
21 , freeStablePtr -- :: StablePtr a -> IO ()
25 import PrelBase ( Int(..), Double(..), Float(..), Char(..) )
26 import PrelGHC ( indexCharOffForeignObj#, indexIntOffForeignObj#,
27 indexAddrOffForeignObj#, indexFloatOffForeignObj#,
28 indexDoubleOffForeignObj#
30 import PrelAddr ( Addr(..), Word(..) )
31 import PrelWeak ( addForeignFinaliser )
34 indexWord8OffForeignObj
35 , indexWord16OffForeignObj
36 , indexWord32OffForeignObj
37 , indexWord64OffForeignObj
38 , readWord8OffForeignObj
39 , readWord16OffForeignObj
40 , readWord32OffForeignObj
41 , readWord64OffForeignObj
42 , writeWord8OffForeignObj
43 , writeWord16OffForeignObj
44 , writeWord32OffForeignObj
45 , writeWord64OffForeignObj
50 indexInt8OffForeignObj
51 , indexInt16OffForeignObj
52 , indexInt32OffForeignObj
53 , indexInt64OffForeignObj
54 , readInt8OffForeignObj
55 , readInt16OffForeignObj
56 , readInt32OffForeignObj
57 , readInt64OffForeignObj
58 , writeInt8OffForeignObj
59 , writeInt16OffForeignObj
60 , writeInt32OffForeignObj
61 , writeInt64OffForeignObj
63 import PrelIOBase ( IO(..) )
67 foreignObjToAddr :: ForeignObj -> IO Addr
68 foreignObjToAddr fo = _casm_ `` %r=(StgAddr)%0; '' fo
73 indexCharOffForeignObj :: ForeignObj -> Int -> Char
74 indexCharOffForeignObj (ForeignObj fo#) (I# i#) = C# (indexCharOffForeignObj# fo# i#)
76 indexIntOffForeignObj :: ForeignObj -> Int -> Int
77 indexIntOffForeignObj (ForeignObj fo#) (I# i#) = I# (indexIntOffForeignObj# fo# i#)
79 indexAddrOffForeignObj :: ForeignObj -> Int -> Addr
80 indexAddrOffForeignObj (ForeignObj fo#) (I# i#) = A# (indexAddrOffForeignObj# fo# i#)
82 indexFloatOffForeignObj :: ForeignObj -> Int -> Float
83 indexFloatOffForeignObj (ForeignObj fo#) (I# i#) = F# (indexFloatOffForeignObj# fo# i#)
85 indexDoubleOffForeignObj :: ForeignObj -> Int -> Double
86 indexDoubleOffForeignObj (ForeignObj fo#) (I# i#) = D# (indexDoubleOffForeignObj# fo# i#)
88 -- read value out of mutable memory
89 readCharOffForeignObj :: ForeignObj -> Int -> IO Char
90 readCharOffForeignObj fo i = _casm_ `` %r=(StgChar)(((StgChar*)%0)[(StgInt)%1]); '' fo i
92 readIntOffForeignObj :: ForeignObj -> Int -> IO Int
93 readIntOffForeignObj fo i = _casm_ `` %r=(StgInt)(((StgInt*)%0)[(StgInt)%1]); '' fo i
95 readWordOffForeignObj :: ForeignObj -> Int -> IO Word
96 readWordOffForeignObj fo i = _casm_ `` %r=(StgWord)(((StgWord*)%0)[(StgInt)%1]); '' fo i
98 readAddrOffForeignObj :: ForeignObj -> Int -> IO Addr
99 readAddrOffForeignObj fo i = _casm_ `` %r=(StgAddr)(((StgAddr*)%0)[(StgInt)%1]); '' fo i
101 readFloatOffForeignObj :: ForeignObj -> Int -> IO Float
102 readFloatOffForeignObj fo i = _casm_ `` %r=(StgFloat)(((StgFloat*)%0)[(StgInt)%1]); '' fo i
104 readDoubleOffForeignObj :: ForeignObj -> Int -> IO Double
105 readDoubleOffForeignObj fo i = _casm_ `` %r=(StgDouble)(((StgDouble*)%0)[(StgInt)%1]); '' fo i
109 writeCharOffForeignObj :: ForeignObj -> Int -> Char -> IO ()
110 writeCharOffForeignObj fo i e = _casm_ `` (((StgChar*)%0)[(StgInt)%1])=(StgChar)%2; '' fo i e
112 writeIntOffForeignObj :: ForeignObj -> Int -> Int -> IO ()
113 writeIntOffForeignObj fo i e = _casm_ `` (((StgInt*)%0)[(StgInt)%1])=(StgInt)%2; '' fo i e
115 writeWordOffForeignObj :: ForeignObj -> Int -> Word -> IO ()
116 writeWordOffForeignObj fo i e = _casm_ `` (((StgWord*)%0)[(StgInt)%1])=(StgWord)%2; '' fo i e
118 writeAddrOffForeignObj :: ForeignObj -> Int -> Addr -> IO ()
119 writeAddrOffForeignObj fo i e = _casm_ `` (((StgAddr*)%0)[(StgInt)%1])=(StgAddr)%2; ''fo i e
121 writeFloatOffForeignObj :: ForeignObj -> Int -> Float -> IO ()
122 writeFloatOffForeignObj fo i e = _casm_ `` (((StgFloat*)%0)[(StgInt)%1])=(StgFloat)%2; '' fo i e
124 writeDoubleOffForeignObj :: ForeignObj -> Int -> Double -> IO ()
125 writeDoubleOffForeignObj fo i e = _casm_ `` (((StgDouble*)%0)[(StgInt)%1])=(StgDouble)%2; '' fo i e