[project @ 1999-08-30 09:16:47 by simonpj]
[ghc-hetmet.git] / ghc / lib / std / Time.lhs
index b4adb21..fb6b3fe 100644 (file)
@@ -38,6 +38,7 @@ module Time
 import PreludeBuiltin
 #else
 import PrelBase
+import PrelShow
 import PrelIOBase
 import PrelHandle
 import PrelArr
@@ -95,7 +96,9 @@ we use the C library routines based on 32 bit integers.
 instance Show ClockTime
 #else
 instance Show ClockTime where
-    showsPrec _ (TOD (J# _ s# d#) _nsec) = 
+    showsPrec p (TOD (S# i) _nsec) = 
+      case int2Integer# i of (# s, d #) -> showsPrec p (TOD (J# s d) _nsec)
+    showsPrec _ (TOD (J# s# d#) _nsec) = 
       showString $ unsafePerformIO $ do
            buf <- allocChars 38 -- exactly enough for error message
            str <- _ccall_ showTime (I# s#) d# buf
@@ -215,7 +218,7 @@ getClockTime = do
     --  The C routine fills in an unsigned word.  We don't have 
     -- `unsigned2Integer#,' so we freeze the data bits and use them 
     -- for an MP_INT structure.  Note that zero is still handled specially,
-    -- although (J# 1# 1# (ptr to 0#)) is probably acceptable to gmp.
+    -- although (J# 1# (ptr to 0#)) is probably acceptable to gmp.
 
     cvtUnsigned (MutableByteArray _ arr#) = IO $ \ s# ->
        case readIntArray# arr# 0# s# of 
@@ -224,7 +227,7 @@ getClockTime = do
                then (# s2#, 0 #)
                else case unsafeFreezeByteArray# arr# s2# of
                         (# s3#, frozen# #) -> 
-                               (# s3#, J# 1# 1# frozen# #)
+                               (# s3#, J# 1# frozen# #)
 #endif
 \end{code}
 
@@ -354,7 +357,9 @@ toClockTime (CalendarTime year mon mday hour min sec psec wday yday tzname tz is
      isDst = if isdst then (1::Int) else 0
 #else
 toCalendarTime :: ClockTime -> IO CalendarTime
-toCalendarTime (TOD (J# _ s# d#) psec) = do
+toCalendarTime (TOD (S# i) psec) 
+  = case int2Integer# i of (# s, d #) -> toCalendarTime (TOD (J# s d) psec)
+toCalendarTime (TOD (J# s# d#) psec) = do
     res    <- allocWords (``sizeof(struct tm)''::Int)
     zoneNm <- allocChars 32
     _casm_ ``SETZONE((struct tm *)%0,(char *)%1); '' res zoneNm
@@ -378,7 +383,9 @@ toCalendarTime (TOD (J# _ s# d#) psec) = do
                            (toEnum wday) yday tzname tz (isdst /= (0::Int)))
 
 toUTCTime :: ClockTime -> CalendarTime
-toUTCTime  (TOD (J# _ s# d#) psec) = unsafePerformIO $ do
+toUTCTime (TOD (S# i) psec) 
+  = case int2Integer# i of (# s, d #) -> toUTCTime (TOD (J# s d) psec)
+toUTCTime  (TOD (J# s# d#) psec) = unsafePerformIO $ do
        res    <- allocWords (``sizeof(struct tm)''::Int)
        zoneNm <- allocChars 32
        _casm_ ``SETZONE((struct tm *)%0,(char *)%1); '' res zoneNm
@@ -572,32 +579,32 @@ formatTimeDiff l fmt (TimeDiff year month day hour min sec _)
 
 \begin{code}
 #ifdef __HUGS__
-foreign import stdcall "libHS_cbits.so" "get_tm_sec"   get_tm_sec   :: Bytes -> IO Int
-foreign import stdcall "libHS_cbits.so" "get_tm_min"   get_tm_min   :: Bytes -> IO Int
-foreign import stdcall "libHS_cbits.so" "get_tm_hour"  get_tm_hour  :: Bytes -> IO Int
-foreign import stdcall "libHS_cbits.so" "get_tm_mday"  get_tm_mday  :: Bytes -> IO Int
-foreign import stdcall "libHS_cbits.so" "get_tm_mon"   get_tm_mon   :: Bytes -> IO Int
-foreign import stdcall "libHS_cbits.so" "get_tm_year"  get_tm_year  :: Bytes -> IO Int
-foreign import stdcall "libHS_cbits.so" "get_tm_wday"  get_tm_wday  :: Bytes -> IO Int
-foreign import stdcall "libHS_cbits.so" "get_tm_yday"  get_tm_yday  :: Bytes -> IO Int
-foreign import stdcall "libHS_cbits.so" "get_tm_isdst" get_tm_isdst :: Bytes -> IO Int
+foreign import ccall "libHS_cbits.so" "get_tm_sec"   get_tm_sec   :: Bytes -> IO Int
+foreign import ccall "libHS_cbits.so" "get_tm_min"   get_tm_min   :: Bytes -> IO Int
+foreign import ccall "libHS_cbits.so" "get_tm_hour"  get_tm_hour  :: Bytes -> IO Int
+foreign import ccall "libHS_cbits.so" "get_tm_mday"  get_tm_mday  :: Bytes -> IO Int
+foreign import ccall "libHS_cbits.so" "get_tm_mon"   get_tm_mon   :: Bytes -> IO Int
+foreign import ccall "libHS_cbits.so" "get_tm_year"  get_tm_year  :: Bytes -> IO Int
+foreign import ccall "libHS_cbits.so" "get_tm_wday"  get_tm_wday  :: Bytes -> IO Int
+foreign import ccall "libHS_cbits.so" "get_tm_yday"  get_tm_yday  :: Bytes -> IO Int
+foreign import ccall "libHS_cbits.so" "get_tm_isdst" get_tm_isdst :: Bytes -> IO Int
 
-foreign import stdcall "libHS_cbits.so" "prim_ZONE"    prim_ZONE    :: Bytes -> IO Addr
-foreign import stdcall "libHS_cbits.so" "prim_GMTOFF"  prim_GMTOFF  :: Bytes -> IO Int
+foreign import ccall "libHS_cbits.so" "prim_ZONE"    prim_ZONE    :: Bytes -> IO Addr
+foreign import ccall "libHS_cbits.so" "prim_GMTOFF"  prim_GMTOFF  :: Bytes -> IO Int
 
-foreign import stdcall "libHS_cbits.so" "prim_SETZONE" prim_SETZONE :: Bytes -> Bytes -> IO Int
+foreign import ccall "libHS_cbits.so" "prim_SETZONE" prim_SETZONE :: Bytes -> Bytes -> IO Int
 
-foreign import stdcall "libHS_cbits.so" "sizeof_word"      sizeof_word      :: Int
-foreign import stdcall "libHS_cbits.so" "sizeof_struct_tm" sizeof_struct_tm :: Int
-foreign import stdcall "libHS_cbits.so" "sizeof_time_t"    sizeof_time_t    :: Int
+foreign import ccall "libHS_cbits.so" "sizeof_word"      sizeof_word      :: Int
+foreign import ccall "libHS_cbits.so" "sizeof_struct_tm" sizeof_struct_tm :: Int
+foreign import ccall "libHS_cbits.so" "sizeof_time_t"    sizeof_time_t    :: Int
 
 -- believed to be at least 1 bit (the sign bit!) bigger than sizeof_time_t
 sizeof_int64 :: Int
 sizeof_int64 = 8
 
-foreign import stdcall "libHS_cbits.so" "prim_getClockTime" prim_getClockTime :: Bytes -> Bytes -> IO Int
-foreign import stdcall "libHS_cbits.so" "prim_toClockSec"   prim_toClockSec   :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> Bytes -> IO Int
-foreign import stdcall "libHS_cbits.so" "prim_toLocalTime"  prim_toLocalTime  :: Int64 -> Bytes -> IO Int
-foreign import stdcall "libHS_cbits.so" "prim_toUTCTime"    prim_toUTCTime    :: Int64 -> Bytes -> IO Int
+foreign import ccall "libHS_cbits.so" "prim_getClockTime" prim_getClockTime :: Bytes -> Bytes -> IO Int
+foreign import ccall "libHS_cbits.so" "prim_toClockSec"   prim_toClockSec   :: Int -> Int -> Int -> Int -> Int -> Int -> Int -> Bytes -> IO Int
+foreign import ccall "libHS_cbits.so" "prim_toLocalTime"  prim_toLocalTime  :: Int64 -> Bytes -> IO Int
+foreign import ccall "libHS_cbits.so" "prim_toUTCTime"    prim_toUTCTime    :: Int64 -> Bytes -> IO Int
 #endif
 \end{code}