2 % (c) The AQUA Project, Glasgow University, 1994-1996
4 \section[PrelArrExtra]{Module @PrelArrExtra@}
6 The following functions should be in PrelArr, but need -monly-2-regs
7 to compile. So as not to compile the whole of PrelArr with
8 -monly-2-regs, the culprits have been moved out into a separate
12 {-# OPTIONS -fno-implicit-prelude #-}
14 module PrelArrExtra where
22 freezeFloatArray :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix)
23 freezeDoubleArray :: Ix ix => MutableByteArray s ix -> ST s (ByteArray ix)
25 freezeFloatArray (MutableByteArray ixs arr#) = ST $ \ s# ->
26 case rangeSize ixs of { I# n# ->
27 case freeze arr# n# s# of { (# s2#, frozen# #) ->
28 (# s2#, ByteArray ixs frozen# #) }}
30 freeze :: MutableByteArray# s -- the thing
31 -> Int# -- size of thing to be frozen
32 -> State# s -- the Universe and everything
33 -> (# State# s, ByteArray# #)
36 = case (newFloatArray# end# s#) of { (# s2#, newarr1# #) ->
37 case copy 0# arr1# newarr1# s2# of { (# s3#, newarr2# #) ->
38 unsafeFreezeByteArray# newarr2# s3#
42 -> MutableByteArray# s -> MutableByteArray# s
44 -> (# State# s, MutableByteArray# s #)
46 copy cur# from# to# s1#
50 = case (readFloatArray# from# cur# s1#) of { (# s2#, ele #) ->
51 case (writeFloatArray# to# cur# ele s2#) of { s3# ->
52 copy (cur# +# 1#) from# to# s3#
55 freezeDoubleArray (MutableByteArray ixs arr#) = ST $ \ s# ->
56 case rangeSize ixs of { I# n# ->
57 case freeze arr# n# s# of { (# s2#, frozen# #) ->
58 (# s2#, ByteArray ixs frozen# #) }}
60 freeze :: MutableByteArray# s -- the thing
61 -> Int# -- size of thing to be frozen
62 -> State# s -- the Universe and everything
63 -> (# State# s, ByteArray# #)
66 = case (newDoubleArray# n# s1#) of { (# s2#, newarr1# #) ->
67 case copy 0# n# arr1# newarr1# s2# of { (# s3#, newarr2# #) ->
68 unsafeFreezeByteArray# newarr2# s3#
72 -> MutableByteArray# s -> MutableByteArray# s
74 -> (# State# s, MutableByteArray# s #)
76 copy cur# end# from# to# st#
80 = case (readDoubleArray# from# cur# st#) of { (# s2#, ele #) ->
81 case (writeDoubleArray# to# cur# ele s2#) of { s3# ->
82 copy (cur# +# 1#) end# from# to# s3#