import PrelNum ( Num(..), Integral(..) ) -- To get fromInt/toInt
import Ratio
-#ifdef __HUGS__
-#define cat2(x,y) x/**/y
-#define CCALL(fun) cat2(prim_,fun)
-#define stToIO id
-#define sizeof_int64 8
-#else
-#define CCALL(fun) _ccall_ fun
-#define const_BUFSIZ ``BUFSIZ''
-#define primPackString
-#endif
-
\end{code}
Computation @getCPUTime@ returns the number of picoseconds CPU time
getCPUTime :: IO Integer
getCPUTime = do
marr <- primNewByteArray (sizeof_int * 4)
- ptr <- CCALL(getCPUTime) marr
+ ptr <- getCPUTime marr
if (ptr /= nullAddr) then do
x0 <- primReadIntArray marr 0
x1 <- primReadIntArray marr 1
getCPUTime =
stToIO (newIntArray ((0::Int),3)) >>= \ marr ->
stToIO (unsafeFreezeByteArray marr) >>= \ barr@(ByteArray _ frozen#) ->
- _ccall_ getCPUTime barr >>= \ ptr ->
- if (ptr::Addr) /= ``NULL'' then
+ primGetCPUTime barr >>= \ ptr ->
+ if (ptr::Addr) /= nullAddr then
return ((fromIntegral (I# (indexIntArray# frozen# 0#)) * 1000000000 +
fromIntegral (I# (indexIntArray# frozen# 1#)) +
fromIntegral (I# (indexIntArray# frozen# 2#)) * 1000000000 +
cpuTimePrecision :: Integer
cpuTimePrecision = round ((1000000000000::Integer) %
- fromInt (unsafePerformIO (CCALL(clockTicks) )))
+ fromInt (unsafePerformIO clockTicks))
\end{code}
\begin{code}
-#ifdef __HUGS__
-
+sizeof_int :: Int
sizeof_int = 4
-foreign import stdcall "libHS_cbits.so" "getCPUTime" prim_getCPUTime :: Bytes -> IO Addr
-foreign import stdcall "libHS_cbits.so" "clockTicks" prim_clockTicks :: IO Int
-#endif
+foreign import "libHS_cbits" "getCPUTime" primGetCPUTime :: ByteArray Int -> IO Addr
+foreign import "libHS_cbits" "clockTicks" clockTicks :: IO Int
+
\end{code}