Changeset 17042
- Timestamp:
- 07/14/07 03:52:25 (1 year ago)
- Files:
-
- src/Pugs/Compat.hs (modified) (2 diffs)
- src/Pugs/Internals.hs (modified) (2 diffs)
- src/Pugs/Prim.hs (modified) (6 diffs)
- src/Pugs/Prim/FileTest.hs (modified) (1 diff)
- src/Pugs/Run.hs (modified) (1 diff)
- src/perl6/Prelude.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
src/Pugs/Compat.hs
r16498 r17042 58 58 import System.Cmd 59 59 import System.Posix.Types 60 import System.Time60 import Data.Time 61 61 62 62 #ifdef PUGS_HAVE_POSIX … … 336 336 peekCString =<< peekElemOff argv 0 337 337 338 epochY2K :: UTCTime 339 epochY2K = UTCTime 340 { utctDay = fromGregorian 2000 01 01 341 , utctDayTime = 0 342 } 343 338 344 {-| 339 345 Convert an internal @ClockTime@ to a Pugs-style fractional time. 340 346 Used by op0 "time", @Pugs.Run.prepareEnv@, and the file time tests. 341 347 -} 342 pugsTimeSpec :: ClockTime -> Rational 343 pugsTimeSpec clkt = fdiff $ diffClockTimes clkt epochClkT 344 where 345 epochClkT = toClockTime epoch 346 epoch = CalendarTime 2000 January 1 0 0 0 0 Saturday 0 "UTC" 0 False 347 -- 10^12 is expanded because the alternatives tried gave type warnings. 348 fdiff = \d -> (fromInteger $ tdPicosec d) 349 / (clocksPerSecond * clocksPerSecond) 350 + (fromIntegral $ tdSec d) 348 pugsTimeSpec :: UTCTime -> Rational 349 pugsTimeSpec clkt = toRational (diffUTCTime clkt epochY2K) src/Pugs/Internals.hs
r16600 r17042 51 51 import Data.Sequence as X (Seq, singleton) 52 52 import Data.Set as X (Set) 53 import Data.Time as X 54 import Data.Time.Clock.POSIX as X 53 55 import Data.Tree as X 54 56 import Data.Unique as X … … 73 75 import System.Process as X 74 76 import System.Random as X hiding (split) 75 import System.Time as X76 77 77 78 -- Instances. src/Pugs/Prim.hs
r16625 r17042 56 56 import GHC.Unicode 57 57 import qualified Data.HashTable as H 58 import Data.Time.LocalTime 59 import Data.Time.Calendar.OrdinalDate 60 import Data.Time.Calendar.MonthDay 58 61 59 62 constMacro :: Exp -> [Val] -> Eval Val … … 72 75 op0 "False" = constMacro . Val $ VBool False 73 76 op0 "time" = const $ do 74 clkt <- guardIO getC lockTime77 clkt <- guardIO getCurrentTime 75 78 return $ VRat $ pugsTimeSpec clkt 76 79 op0 "times" = const $ do … … 420 423 x <- fromVal v :: Eval VNum 421 424 guardIO $ do 422 TOD t0s t0ps <- getClockTime425 start <- getCurrentTime 423 426 threadDelay (round $ x * clocksPerSecond) 424 TOD t1s t1ps <- getClockTime 425 return $ VRat ((fromInteger $ t1ps - t0ps) 426 / (clocksPerSecond * clocksPerSecond) -- 10^12 427 + (fromInteger $ t1s - t0s)) 427 finish <- getCurrentTime 428 return $ VRat (toRational $ diffUTCTime start finish) 428 429 op1 "mkdir" = guardedIO createDirectory 429 430 op1 "rmdir" = guardedIO removeDirectory … … 699 700 op1 "stat" = \x -> opPerl5 "require File::stat; File::stat::stat" [x] 700 701 op1 "lstat" = \x -> opPerl5 "require File::stat; File::stat::lstat" [x] 702 op1 "Pugs::Internals::localtime" = \x -> do 703 tz <- io getCurrentTimeZone 704 tm <- fromVal x -- seconds since Perl's epoch 705 let utc = posixSecondsToUTCTime (fromInteger tm + offset) 706 local = utcToLocalTime tz utc 707 day = localDay local 708 tod = localTimeOfDay local 709 (year, month, dayOfMonth) = toGregorian day 710 (sec, pico) = properFraction $ todSec tod 711 (_, dayOfWeek) = sundayStartWeek day 712 -- if wantString then return . VStr $ formatTime "%c" (ZonedTime local tz) else 713 retSeq [ vI $ year 714 , vI $ month 715 , vI $ dayOfMonth 716 , vI $ todHour tod 717 , vI $ todMin tod 718 , VInt $ sec 719 , vI $ fromEnum (pico * 1000000000000) 720 , vI $ dayOfWeek + 1 721 , vI $ (monthAndDayToDayOfYear (isLeapYear year) month dayOfMonth) - 1 722 , VStr $ timeZoneName tz 723 , vI $ timeZoneMinutes tz * 60 724 , VBool $ timeZoneSummerOnly tz 725 ] 726 where 727 offset :: NominalDiffTime 728 offset = 946684800 -- diff between Haskell and Perl epochs (seconds) 729 vI :: Integral a => a -> Val 730 vI = VInt . toInteger 701 731 702 732 op1 other = \_ -> fail ("Unimplemented unaryOp: " ++ other) … … 1324 1354 return $ VObject o{ objAttrs = attrs', objId = uniq } 1325 1355 1326 op3 "Pugs::Internals::localtime" = \x y z -> do1327 wantString <- fromVal x1328 sec <- fromVal y1329 pico <- fromVal z1330 c <- guardIO $ toCalendarTime $ TOD (offset + sec) pico1331 if wantString then return $ VStr $ calendarTimeToString c else1332 retSeq $ [ vI $ ctYear c1333 , vI $ (1+) $ fromEnum $ ctMonth c1334 , vI $ ctDay c1335 , vI $ ctHour c1336 , vI $ ctMin c1337 , vI $ ctSec c1338 , VInt $ ctPicosec c1339 , vI $ (1+) $ fromEnum $ ctWDay c1340 , vI $ ctYDay c1341 , VStr $ ctTZName c1342 , vI $ ctTZ c1343 , VBool $ ctIsDST c1344 ]1345 where1346 offset = 946684800 :: Integer -- diff between Haskell and Perl epochs (seconds)1347 vI = VInt . toInteger1348 1356 op3 "Pugs::Internals::hSeek" = \x y z -> do 1349 1357 handle <- fromVal x … … 1971 1979 \\n Num pre time safe ()\ 1972 1980 \\n List pre times safe ()\ 1973 \\n List pre Pugs::Internals::localtime safe ( Bool, Int, Int)\1981 \\n List pre Pugs::Internals::localtime safe (Num)\ 1974 1982 \\n Str pre want safe ()\ 1975 1983 \\n Str pre File::Spec::cwd unsafe ()\ src/Pugs/Prim/FileTest.hs
r15616 r17042 61 61 fileTime :: (FilePath -> IO Integer) -> Val -> Eval Val 62 62 fileTime test f = do 63 t <- fileTestIO (fileTestDo test) f63 t <- fileTestIO (fileTestDo test) f 64 64 if (t == undef) then return VUndef else do 65 t' <- fromVal t66 b <- (readVar $ cast "$*BASETIME") >>= fromVal67 return $ VRat $ (b - (pugsTimeSpec $ TOD t' 0)) / 8640065 t' <- fromVal t :: Eval Integer 66 b <- fromVal =<< readVar (cast "$*BASETIME") 67 return $ VRat $ (b - (pugsTimeSpec . posixSecondsToUTCTime $ fromIntegral t')) / 86400 68 68 69 69 fileTestIO :: (Value n) => (n -> IO Val) -> Val -> Eval Val src/Pugs/Run.hs
r16627 r17042 114 114 autoSV <- newScalar undef 115 115 classes <- initClassObjects (MkObjectId $ -1) [] initTree 116 strictSV <- newScalar $ VBool (name /= "-e")117 baset <- getClockTime116 strictSV<- newScalar $ VBool (name /= "-e") 117 baset <- getCurrentTime 118 118 #if defined(PUGS_HAVE_HSPLUGINS) 119 119 hspluginsSV <- newScalar (VInt 1) src/perl6/Prelude.pm
r16642 r17042 564 564 is primitive is builtin is safe { 565 565 my $res; 566 my $sec = int $when;567 my $pico = ($when - int $when) * 10**12;566 #my $sec = int $when; 567 #my $pico = ($when - int $when) * 10**12; 568 568 # XXX: waiting on a better want 569 569 #if want ~~ rx:P5/^Item/ { 570 570 # $res = Pugs::Internals::localtime(Bool::True, $sec, $pico); 571 571 #} else { 572 my @tm = Pugs::Internals::localtime( Bool::False, $sec, $pico);572 my @tm = Pugs::Internals::localtime($when); # Bool::False, $sec, $pico); 573 573 574 574 # FIXME: this is how it oughta look, with @ids being class level.
