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 ()
14 , StablePtr {-a-} -- abstract.
15 , makeStablePtr -- :: a -> IO (StablePtr a)
16 , deRefStablePtr -- :: StablePtr a -> IO a
17 , freeStablePtr -- :: StablePtr a -> IO ()
19 , indexCharOffForeignObj
20 , indexAddrOffForeignObj
21 , indexIntOffForeignObj
22 , indexFloatOffForeignObj
23 , indexDoubleOffForeignObj
24 , readCharOffForeignObj
25 , readAddrOffForeignObj
26 , readIntOffForeignObj
27 , readFloatOffForeignObj
28 , readDoubleOffForeignObj
29 , writeCharOffForeignObj
30 , writeAddrOffForeignObj
31 , writeIntOffForeignObj
32 , writeFloatOffForeignObj
33 , writeDoubleOffForeignObj
35 , indexWord8OffForeignObj
36 , indexWord16OffForeignObj
37 , indexWord32OffForeignObj
38 , indexWord64OffForeignObj
39 , readWord8OffForeignObj
40 , readWord16OffForeignObj
41 , readWord32OffForeignObj
42 , readWord64OffForeignObj
43 , writeWord8OffForeignObj
44 , writeWord16OffForeignObj
45 , writeWord32OffForeignObj
46 , writeWord64OffForeignObj
48 , indexInt8OffForeignObj
49 , indexInt16OffForeignObj
50 , indexInt32OffForeignObj
51 , indexInt64OffForeignObj
52 , readInt8OffForeignObj
53 , readInt16OffForeignObj
54 , readInt32OffForeignObj
55 , readInt64OffForeignObj
56 , writeInt8OffForeignObj
57 , writeInt16OffForeignObj
58 , writeInt32OffForeignObj
59 , writeInt64OffForeignObj
64 import PrelBase ( Int(..), Double(..), Float(..), Char(..) )
65 import PrelGHC ( indexCharOffForeignObj#, indexIntOffForeignObj#,
66 indexAddrOffForeignObj#, indexFloatOffForeignObj#,
67 indexDoubleOffForeignObj#
69 import PrelAddr ( Addr(..) )
72 indexWord8OffForeignObj
73 , indexWord16OffForeignObj
74 , indexWord32OffForeignObj
75 , indexWord64OffForeignObj
76 , readWord8OffForeignObj
77 , readWord16OffForeignObj
78 , readWord32OffForeignObj
79 , readWord64OffForeignObj
80 , writeWord8OffForeignObj
81 , writeWord16OffForeignObj
82 , writeWord32OffForeignObj
83 , writeWord64OffForeignObj
88 indexInt8OffForeignObj
89 , indexInt16OffForeignObj
90 , indexInt32OffForeignObj
91 , indexInt64OffForeignObj
92 , readInt8OffForeignObj
93 , readInt16OffForeignObj
94 , readInt32OffForeignObj
95 , readInt64OffForeignObj
96 , writeInt8OffForeignObj
97 , writeInt16OffForeignObj
98 , writeInt32OffForeignObj
99 , writeInt64OffForeignObj
101 import PrelIOBase ( IO(..), IOResult(..) )
105 indexCharOffForeignObj :: ForeignObj -> Int -> Char
106 indexCharOffForeignObj (ForeignObj fo#) (I# i#) = C# (indexCharOffForeignObj# fo# i#)
108 indexIntOffForeignObj :: ForeignObj -> Int -> Int
109 indexIntOffForeignObj (ForeignObj fo#) (I# i#) = I# (indexIntOffForeignObj# fo# i#)
111 indexAddrOffForeignObj :: ForeignObj -> Int -> Addr
112 indexAddrOffForeignObj (ForeignObj fo#) (I# i#) = A# (indexAddrOffForeignObj# fo# i#)
114 indexFloatOffForeignObj :: ForeignObj -> Int -> Float
115 indexFloatOffForeignObj (ForeignObj fo#) (I# i#) = F# (indexFloatOffForeignObj# fo# i#)
117 indexDoubleOffForeignObj :: ForeignObj -> Int -> Double
118 indexDoubleOffForeignObj (ForeignObj fo#) (I# i#) = D# (indexDoubleOffForeignObj# fo# i#)
120 -- read value out of mutable memory
121 readCharOffForeignObj :: ForeignObj -> Int -> IO Char
122 readCharOffForeignObj fo i = _casm_ `` %r=(StgChar)(((StgChar*)%0)[(StgInt)%1]); '' fo i
124 readIntOffForeignObj :: ForeignObj -> Int -> IO Int
125 readIntOffForeignObj fo i = _casm_ `` %r=(StgInt)(((StgInt*)%0)[(StgInt)%1]); '' fo i
127 readWordOffForeignObj :: ForeignObj -> Int -> IO Word
128 readWordOffForeignObj fo i = _casm_ `` %r=(StgWord)(((StgWord*)%0)[(StgInt)%1]); '' fo i
130 readAddrOffForeignObj :: ForeignObj -> Int -> IO Addr
131 readAddrOffForeignObj fo i = _casm_ `` %r=(StgAddr)(((StgAddr*)%0)[(StgInt)%1]); '' fo i
133 readFloatOffForeignObj :: ForeignObj -> Int -> IO Float
134 readFloatOffForeignObj fo i = _casm_ `` %r=(StgFloat)(((StgFloat*)%0)[(StgInt)%1]); '' fo i
136 readDoubleOffForeignObj :: ForeignObj -> Int -> IO Double
137 readDoubleOffForeignObj fo i = _casm_ `` %r=(StgDouble)(((StgDouble*)%0)[(StgInt)%1]); '' fo i
141 writeCharOffForeignObj :: ForeignObj -> Int -> Char -> IO ()
142 writeCharOffForeignObj fo i e = _casm_ `` (((StgChar*)%0)[(StgInt)%1])=(StgChar)%2; '' fo i e
144 writeIntOffForeignObj :: ForeignObj -> Int -> Int -> IO ()
145 writeIntOffForeignObj fo i e = _casm_ `` (((StgInt*)%0)[(StgInt)%1])=(StgInt)%2; '' fo i e
147 writeWordOffForeignObj :: ForeignObj -> Int -> Word -> IO ()
148 writeWordOffForeignObj fo i e = _casm_ `` (((StgWord*)%0)[(StgInt)%1])=(StgWord)%2; '' fo i e
150 writeAddrOffForeignObj :: ForeignObj -> Int -> Addr -> IO ()
151 writeAddrOffForeignObj fo i e = _casm_ `` (((StgAddr*)%0)[(StgInt)%1])=(StgAddr)%2; ''fo i e
153 writeFloatOffForeignObj :: ForeignObj -> Int -> Float -> IO ()
154 writeFloatOffForeignObj fo i e = _casm_ `` (((StgFloat*)%0)[(StgInt)%1])=(StgFloat)%2; '' fo i e
156 writeDoubleOffForeignObj :: ForeignObj -> Int -> Double -> IO ()
157 writeDoubleOffForeignObj fo i e = _casm_ `` (((StgDouble*)%0)[(StgInt)%1])=(StgDouble)%2; '' fo i e