2 % (c) The AQUA Project, Glasgow University, 1994-1996
5 \section[Foreign]{Module @Foreign@}
10 ForeignObj -- abstract, instance of: Eq
11 , makeForeignObj -- :: Addr{-obj-} -> Addr{-finaliser-} -> IO ForeignObj
12 , writeForeignObj -- :: ForeignObj -> Addr{-new obj-} -> IO ()
13 , foreignObjToAddr -- :: ForeignObj -> IO Addr
14 -- the coercion from a foreign obj. to an addr. is unsafe,
15 -- and should not be used unless absolutely necessary.
17 , StablePtr {-a-} -- abstract.
18 , makeStablePtr -- :: a -> IO (StablePtr a)
19 , deRefStablePtr -- :: StablePtr a -> IO a
20 , freeStablePtr -- :: StablePtr a -> IO ()
22 , indexCharOffForeignObj
23 , indexAddrOffForeignObj
24 , indexIntOffForeignObj
25 , indexFloatOffForeignObj
26 , indexDoubleOffForeignObj
27 , readCharOffForeignObj
28 , readAddrOffForeignObj
29 , readIntOffForeignObj
30 , readFloatOffForeignObj
31 , readDoubleOffForeignObj
32 , writeCharOffForeignObj
33 , writeAddrOffForeignObj
34 , writeIntOffForeignObj
35 , writeFloatOffForeignObj
36 , writeDoubleOffForeignObj
38 , indexWord8OffForeignObj
39 , indexWord16OffForeignObj
40 , indexWord32OffForeignObj
41 , indexWord64OffForeignObj
42 , readWord8OffForeignObj
43 , readWord16OffForeignObj
44 , readWord32OffForeignObj
45 , readWord64OffForeignObj
46 , writeWord8OffForeignObj
47 , writeWord16OffForeignObj
48 , writeWord32OffForeignObj
49 , writeWord64OffForeignObj
51 , indexInt8OffForeignObj
52 , indexInt16OffForeignObj
53 , indexInt32OffForeignObj
54 , indexInt64OffForeignObj
55 , readInt8OffForeignObj
56 , readInt16OffForeignObj
57 , readInt32OffForeignObj
58 , readInt64OffForeignObj
59 , writeInt8OffForeignObj
60 , writeInt16OffForeignObj
61 , writeInt32OffForeignObj
62 , writeInt64OffForeignObj
67 import PrelBase ( Int(..), Double(..), Float(..), Char(..) )
68 import PrelGHC ( indexCharOffForeignObj#, indexIntOffForeignObj#,
69 indexAddrOffForeignObj#, indexFloatOffForeignObj#,
70 indexDoubleOffForeignObj#
72 import PrelAddr ( Addr(..) )
73 import PrelCCall ( Word(..) )
76 indexWord8OffForeignObj
77 , indexWord16OffForeignObj
78 , indexWord32OffForeignObj
79 , indexWord64OffForeignObj
80 , readWord8OffForeignObj
81 , readWord16OffForeignObj
82 , readWord32OffForeignObj
83 , readWord64OffForeignObj
84 , writeWord8OffForeignObj
85 , writeWord16OffForeignObj
86 , writeWord32OffForeignObj
87 , writeWord64OffForeignObj
92 indexInt8OffForeignObj
93 , indexInt16OffForeignObj
94 , indexInt32OffForeignObj
95 , indexInt64OffForeignObj
96 , readInt8OffForeignObj
97 , readInt16OffForeignObj
98 , readInt32OffForeignObj
99 , readInt64OffForeignObj
100 , writeInt8OffForeignObj
101 , writeInt16OffForeignObj
102 , writeInt32OffForeignObj
103 , writeInt64OffForeignObj
105 import PrelIOBase ( IO(..), IOResult(..) )
109 foreignObjToAddr :: ForeignObj -> IO Addr
110 foreignObjToAddr fo = _casm_ `` %r=(StgAddr)%0; '' fo
115 indexCharOffForeignObj :: ForeignObj -> Int -> Char
116 indexCharOffForeignObj (ForeignObj fo#) (I# i#) = C# (indexCharOffForeignObj# fo# i#)
118 indexIntOffForeignObj :: ForeignObj -> Int -> Int
119 indexIntOffForeignObj (ForeignObj fo#) (I# i#) = I# (indexIntOffForeignObj# fo# i#)
121 indexAddrOffForeignObj :: ForeignObj -> Int -> Addr
122 indexAddrOffForeignObj (ForeignObj fo#) (I# i#) = A# (indexAddrOffForeignObj# fo# i#)
124 indexFloatOffForeignObj :: ForeignObj -> Int -> Float
125 indexFloatOffForeignObj (ForeignObj fo#) (I# i#) = F# (indexFloatOffForeignObj# fo# i#)
127 indexDoubleOffForeignObj :: ForeignObj -> Int -> Double
128 indexDoubleOffForeignObj (ForeignObj fo#) (I# i#) = D# (indexDoubleOffForeignObj# fo# i#)
130 -- read value out of mutable memory
131 readCharOffForeignObj :: ForeignObj -> Int -> IO Char
132 readCharOffForeignObj fo i = _casm_ `` %r=(StgChar)(((StgChar*)%0)[(StgInt)%1]); '' fo i
134 readIntOffForeignObj :: ForeignObj -> Int -> IO Int
135 readIntOffForeignObj fo i = _casm_ `` %r=(StgInt)(((StgInt*)%0)[(StgInt)%1]); '' fo i
137 readWordOffForeignObj :: ForeignObj -> Int -> IO Word
138 readWordOffForeignObj fo i = _casm_ `` %r=(StgWord)(((StgWord*)%0)[(StgInt)%1]); '' fo i
140 readAddrOffForeignObj :: ForeignObj -> Int -> IO Addr
141 readAddrOffForeignObj fo i = _casm_ `` %r=(StgAddr)(((StgAddr*)%0)[(StgInt)%1]); '' fo i
143 readFloatOffForeignObj :: ForeignObj -> Int -> IO Float
144 readFloatOffForeignObj fo i = _casm_ `` %r=(StgFloat)(((StgFloat*)%0)[(StgInt)%1]); '' fo i
146 readDoubleOffForeignObj :: ForeignObj -> Int -> IO Double
147 readDoubleOffForeignObj fo i = _casm_ `` %r=(StgDouble)(((StgDouble*)%0)[(StgInt)%1]); '' fo i
151 writeCharOffForeignObj :: ForeignObj -> Int -> Char -> IO ()
152 writeCharOffForeignObj fo i e = _casm_ `` (((StgChar*)%0)[(StgInt)%1])=(StgChar)%2; '' fo i e
154 writeIntOffForeignObj :: ForeignObj -> Int -> Int -> IO ()
155 writeIntOffForeignObj fo i e = _casm_ `` (((StgInt*)%0)[(StgInt)%1])=(StgInt)%2; '' fo i e
157 writeWordOffForeignObj :: ForeignObj -> Int -> Word -> IO ()
158 writeWordOffForeignObj fo i e = _casm_ `` (((StgWord*)%0)[(StgInt)%1])=(StgWord)%2; '' fo i e
160 writeAddrOffForeignObj :: ForeignObj -> Int -> Addr -> IO ()
161 writeAddrOffForeignObj fo i e = _casm_ `` (((StgAddr*)%0)[(StgInt)%1])=(StgAddr)%2; ''fo i e
163 writeFloatOffForeignObj :: ForeignObj -> Int -> Float -> IO ()
164 writeFloatOffForeignObj fo i e = _casm_ `` (((StgFloat*)%0)[(StgInt)%1])=(StgFloat)%2; '' fo i e
166 writeDoubleOffForeignObj :: ForeignObj -> Int -> Double -> IO ()
167 writeDoubleOffForeignObj fo i e = _casm_ `` (((StgDouble*)%0)[(StgInt)%1])=(StgDouble)%2; '' fo i e