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(..) )
20 Note: the above used to say:
23 module PreludeGlaMisc(
26 #ifndef __PARALLEL_HASKELL__
28 makeStablePtr, deRefStablePtr, freeStablePtr,
31 #endif /* !__PARALLEL_HASKELL__ */
36 But then the names @_MallocPtr@ and @_StablePtr@ get shoved out into
37 the interface file and anyone importing it becomes unhappy about
38 seeing a preludish name.
43 Bad name on a datatype constructor (a Prelude name?): _MallocPtr
48 (Oh, btw, don't try not exporting them either - that just makes the
49 info-tables, etc local to this module so that no-one can get at them.)
55 The next two definitions must match those in
56 @compiler/prelude/TysWiredIn.lhs@ exactly.
59 #ifndef __PARALLEL_HASKELL__
61 -- ** MOVED TO prelude/TysBasic.hs **
62 -- data _MallocPtr = _MallocPtr MallocPtr#
63 -- data _StablePtr a = _StablePtr (StablePtr# a)
67 Nota Bene: it is important {\em not\/} to inline calls to
68 @makeStablePtr#@ since the corresponding macro is very long and we'll
69 get terrible code-bloat.
72 makeStablePtr :: a -> PrimIO (_StablePtr a)
73 deRefStablePtr :: _StablePtr a -> PrimIO a
74 freeStablePtr :: _StablePtr a -> PrimIO ()
76 eqMallocPtr :: _MallocPtr -> _MallocPtr -> Bool
78 performGC :: PrimIO ()
80 {-# INLINE deRefStablePtr #-}
81 {-# INLINE freeStablePtr #-}
82 {-# INLINE performGC #-}
84 makeStablePtr f (S# rw1#) =
85 case makeStablePtr# f rw1# of
86 StateAndStablePtr# rw2# sp# -> (_StablePtr sp#, S# rw2#)
88 deRefStablePtr (_StablePtr sp#) (S# rw1#) =
89 case deRefStablePtr# sp# rw1# of
90 StateAndPtr# rw2# a -> (a, S# rw2#)
92 freeStablePtr sp = _ccall_ freeStablePointer sp
94 eqMallocPtr mp1 mp2 = unsafePerformPrimIO (
95 _ccall_ eqMallocPtr mp1 mp2
99 instance Eq _MallocPtr where
100 p == q = eqMallocPtr p q
101 p /= q = if eqMallocPtr p q then False else True
103 performGC = _ccall_GC_ StgPerformGarbageCollection
105 #endif /* !__PARALLEL_HASKELL__ */
108 Like they say: this is as good a place as any to put it:
111 addr2Int :: _Addr -> Int
112 addr2Int (A# a#) = I# (addr2Int# a#)
114 int2Addr :: Int -> _Addr
115 int2Addr (I# i#) = A# (int2Addr# i#)