2 % (c) The GRASP/AQUA Project, Glasgow University, 1993-1994
4 \section[PreludeGlaMisc]{Miscellaneous Glasgow Stuff}
7 module PreludeGlaMisc( PreludeGlaMisc.. {-, PreludePS..-} ) where
14 import PS ( _PackedString, _unpackPS )
15 import TyArray ( Array(..) )
19 Note: the above used to say:
22 module PreludeGlaMisc(
25 #ifndef __PARALLEL_HASKELL__
27 makeStablePtr, deRefStablePtr, freeStablePtr,
30 #endif /* !__PARALLEL_HASKELL__ */
35 But then the names @_MallocPtr@ and @_StablePtr@ get shoved out into
36 the interface file and anyone importing it becomes unhappy about
37 seeing a preludish name.
42 Bad name on a datatype constructor (a Prelude name?): _MallocPtr
47 (Oh, btw, don't try not exporting them either - that just makes the
48 info-tables, etc local to this module so that no-one can get at them.)
54 The next two definitions must match those in
55 @compiler/prelude/TysWiredIn.lhs@ exactly.
58 #ifndef __PARALLEL_HASKELL__
60 -- ** MOVED TO prelude/TysBasic.hs **
61 -- data _MallocPtr = _MallocPtr MallocPtr#
62 -- data _StablePtr a = _StablePtr (StablePtr# a)
66 Nota Bene: it is important {\em not\/} to inline calls to
67 @makeStablePtr#@ since the corresponding macro is very long and we'll
68 get terrible code-bloat.
71 makeStablePtr :: a -> PrimIO (_StablePtr a)
72 deRefStablePtr :: _StablePtr a -> PrimIO a
73 freeStablePtr :: _StablePtr a -> PrimIO ()
75 eqMallocPtr :: _MallocPtr -> _MallocPtr -> Bool
77 performGC :: PrimIO ()
79 {-# INLINE deRefStablePtr #-}
80 {-# INLINE freeStablePtr #-}
81 {-# INLINE performGC #-}
83 makeStablePtr f (S# rw1#) =
84 case makeStablePtr# f rw1# of
85 StateAndStablePtr# rw2# sp# -> (_StablePtr sp#, S# rw2#)
87 deRefStablePtr (_StablePtr sp#) (S# rw1#) =
88 case deRefStablePtr# sp# rw1# of
89 StateAndPtr# rw2# a -> (a, S# rw2#)
91 freeStablePtr sp = _ccall_ freeStablePointer sp
93 eqMallocPtr mp1 mp2 = unsafePerformPrimIO (
94 _ccall_ eqMallocPtr mp1 mp2
98 instance Eq _MallocPtr where
99 p == q = eqMallocPtr p q
100 p /= q = if eqMallocPtr p q then False else True
102 performGC = _ccall_GC_ StgPerformGarbageCollection
104 #endif /* !__PARALLEL_HASKELL__ */
107 Like they say: this is as good a place as any to put it:
110 addr2Int :: _Addr -> Int
111 addr2Int (A# a#) = I# (addr2Int# a#)
113 int2Addr :: Int -> _Addr
114 int2Addr (I# i#) = A# (int2Addr# i#)