Changeset 14599

Show
Ignore:
Timestamp:
11/03/06 05:30:51 (2 years ago)
Author:
allbery_b
svk:copy_cache_prev:
41990
Message:

AUTHORS: hello, world\n :)
src/Pugs/Compat.hs: added file time tests
src/Pugs/Internals.hs, src/Pugs/Prim.hs: abstract out guts of "time" for

use in $*BASETIME and file tests

src/Pugs/Run.hs: add $*BASETIME
src/Pugs/AST.hs: document _reserved and filterUserDefinedPad; add $*BASETIME

to _reserved

src/Pugs/Prim.hs: add file time operators -M, -C, -A
src/Pugs/Prim/FileTest.hs: add implementation of file time operators
t/operators/filetest.t: correct existing file time operator tests, add a few

more, add all of them to the plan

Files:
8 modified

Legend:

Unmodified
Added
Removed
  • AUTHORS

    r14530 r14599  
    3535Brad "bsb" Bowman                (BOWMANBS) 
    3636Brandon Michael "skew" Moore 
     37Brandon S Allbery KF8NH 
    3738Bryan Donlan                     (BDONLAN) 
    3839Bryan "mrborisguy" Burgers 
  • src/Pugs/AST.hs

    r14303 r14599  
    342342    isPrimVal _ = False 
    343343 
     344{-| 
     345Filter out reserved symbols from the specified Pad. 
     346-} 
    344347filterUserDefinedPad :: Pad -> Pad 
    345348filterUserDefinedPad (MkPad pad) = MkPad $ Map.filterWithKey doFilter pad 
     
    347350    doFilter key _ = (not . Set.member key) _reserved 
    348351 
     352{-| 
     353Symbols which are reserved for the current interpreter/compiler instance and 
     354should not be set from the preamble or other sources.  See 
     355@Pugs.AST.filterUserDefinedPad@. 
     356-} 
    349357_reserved :: Set Var 
    350358_reserved = Set.fromList . cast . words $ 
     
    352360    "$*PROGRAM_NAME $*PID $*UID $*EUID $*GID $*EGID @*CHECK @*INIT $*IN " ++ 
    353361    "$*OUT $*ERR $*ARGS $/ %*ENV $*CWD @=POD $=POD $?PUGS_VERSION " ++ 
    354     "$*OS %?CONFIG $*_ $*AUTOLOAD $*PUGS_VERSION" 
     362    "$*OS %?CONFIG $*_ $*AUTOLOAD $*PUGS_VERSION $*BASETIME" 
    355363 
    356364typeOfParam :: Param -> Type 
  • src/Pugs/Compat.hs

    r13464 r14599  
    2525    getArg0, 
    2626    statFileSize, 
     27    statFileMTime, 
     28    statFileCTime, 
     29    statFileATime, 
    2730    getProcessID, 
    2831    getRealUserID, 
     
    97100    return (toInteger (fileSize s)) 
    98101 
     102statFileTime :: (FileStatus -> EpochTime) -> FilePath -> IO Integer 
     103statFileTime op f = do 
     104    s <- getFileStatus f 
     105    return (toInteger $ fromEnum $ op s) 
     106 
     107statFileMTime :: FilePath -> IO Integer 
     108statFileMTime f = statFileTime modificationTime f >>= return 
     109 
     110statFileCTime :: FilePath -> IO Integer 
     111statFileCTime f = statFileTime statusChangeTime f >>= return 
     112 
     113statFileATime :: FilePath -> IO Integer 
     114statFileATime f = statFileTime accessTime f >>= return 
     115 
    99116type Signal = System.Posix.Signals.Signal 
    100117signalProcess :: Signal -> ProcessID -> IO () 
  • src/Pugs/Internals.hs

    r14467 r14599  
    9292    __, (+++), nullID, addressOf, showAddressOf, 
    9393 
    94     hashNew, hashList 
     94    hashNew, hashList, 
     95    pugsTimeSpec, 
    9596) where 
    9697 
     
    575576    where 
    576577    addr = addressOf x 
     578 
     579{-| 
     580Convert an internal @ClockTime@ to a Pugs-style fractional time. 
     581Used by op0 "time", @Pugs.Run.prepareEnv@, and the file time tests. 
     582-} 
     583pugsTimeSpec :: ClockTime -> Rational 
     584pugsTimeSpec clkt = fdiff $ diffClockTimes clkt epochClkT 
     585    where 
     586       epochClkT = toClockTime epoch 
     587       epoch = CalendarTime 2000 January 1 0 0 0 0 Saturday 0 "UTC" 0 False 
     588       -- 10^12 is expanded because the alternatives tried gave type warnings. 
     589       fdiff = \d -> (fromInteger $ tdPicosec d) 
     590                   / (clocksPerSecond * clocksPerSecond) 
     591                   + (fromIntegral $ tdSec d) 
  • src/Pugs/Prim.hs

    r14574 r14599  
    7373op0 "time"  = const $ do 
    7474    clkt <- guardIO getClockTime 
    75     return $ VRat $ fdiff $ diffClockTimes clkt epochClkT 
    76     where 
    77        epochClkT = toClockTime epoch 
    78        epoch = CalendarTime 2000 January 1 0 0 0 0 Saturday 0 "UTC" 0 False 
    79        -- 10^12 is expanded because the alternatives tried gave type warnings. 
    80        fdiff = \d -> (fromInteger $ tdPicosec d) 
    81                    / (clocksPerSecond * clocksPerSecond) 
    82                    + (fromIntegral $ tdSec d) 
     75    return $ VRat $ pugsTimeSpec clkt 
    8376op0 "times"  = const $ do 
    8477    ProcessTimes _ u s cu cs <- guardIO getProcessTimes 
     
    430423op1 "-z"    = FileTest.sizeIsZero 
    431424op1 "-s"    = FileTest.fileSize 
     425op1 "-M"    = FileTest.fileMTime 
     426op1 "-A"    = FileTest.fileATime 
     427op1 "-C"    = FileTest.fileCTime 
    432428op1 "-f"    = FileTest.isFile 
    433429op1 "-d"    = FileTest.isDirectory 
     
    18241820\\n   Bool      spre    -e      unsafe (Str)\ 
    18251821\\n   Int       spre    -s      unsafe (Str)\ 
     1822\\n   Num       spre    -M      unsafe (Str)\ 
     1823\\n   Num       spre    -A      unsafe (Str)\ 
     1824\\n   Num       spre    -C      unsafe (Str)\ 
    18261825\\n   Bool      spre    -f      unsafe (Str)\ 
    18271826\\n   Bool      spre    -d      unsafe (Str)\ 
  • src/Pugs/Prim/FileTest.hs

    r10466 r14599  
    33    exists, isFile, isDirectory, 
    44    fileSize, sizeIsZero, 
     5    fileMTime, fileCTime, fileATime, 
    56) where 
    67import Pugs.Internals 
     
    3435sizeIsZero   :: Val -> Eval Val 
    3536sizeIsZero   = fileTestIO fileTestSizeIsZero 
     37fileMTime    :: Val -> Eval Val 
     38fileMTime    = fileTime statFileMTime 
     39fileCTime    :: Val -> Eval Val 
     40fileCTime    = fileTime statFileCTime 
     41fileATime    :: Val -> Eval Val 
     42fileATime    = fileTime statFileATime 
     43 
     44fileTime :: (FilePath -> IO Integer) -> Val -> Eval Val 
     45fileTime test f = do 
     46    t <- fileTestIO (fileTestDo test) f 
     47    if (t == undef) then return VUndef else do 
     48    t' <- fromVal t 
     49    b <- (readVar $ cast "$*BASETIME") >>= fromVal 
     50    return $ VRat $ (b - (pugsTimeSpec $ TOD t' 0)) / 86400 
    3651 
    3752fileTestIO :: (Value n) => (n -> IO Val) -> Val -> Eval Val 
     
    7489    n <- statFileSize f 
    7590    return $ if n == 0 then VBool True else VBool False 
     91 
     92fileTestDo :: (FilePath -> IO Integer) -> FilePath -> IO Val 
     93fileTestDo test f = test f >>= return . VInt 
  • src/Pugs/Run.hs

    r14438 r14599  
    3636import System.IO 
    3737import System.FilePath (joinFileName) 
     38import System.Posix.Time 
    3839 
    3940 
     
    115116    classes <- initClassObjects (MkObjectId $ -1) [] initTree 
    116117    strictSV <- newScalar $ VBool (name /= "-e") 
     118    -- XXX factor "time" and use it here and in filetime tests 
     119    baset <- getClockTime 
    117120#if defined(PUGS_HAVE_HSPLUGINS) 
    118121    hspluginsSV <- newScalar (VInt 1) 
     
    164167        , gen "$*AUTOLOAD" $ MkRef autoSV 
    165168        , gen "$*STRICT" $ MkRef strictSV 
     169        -- XXX do we want hideInSafemode? 
     170        , gen "$*BASETIME" $ MkRef $ constScalar (VRat $ pugsTimeSpec baset) 
    166171        ] ++ classes 
    167172    -- defSVcell <- (gen "$_" . MkRef) =<< newScalar undef 
  • t/operators/filetest.t

    r14516 r14599  
    99=cut 
    1010 
    11 plan 41; 
     11plan 50; 
    1212 
    1313#if $*OS eq any <MSWin32 mingw msys cygwin> { 
     
    118118my $fh = open("test_file", :w); 
    119119close $fh; 
    120 ok (-M "test_file") > 0,      "-M works"; 
    121 ok (-C "test_file") > 0,      "-C works"; 
    122 ok (-A "test_file") > 0,      "-A works"; 
     120sleep 1; # just to make sure 
     121ok (-M "test_file") < 0,      "-M works on new file"; 
     122ok (-C "test_file") < 0,      "-C works on new file"; 
     123ok (-A "test_file") < 0,      "-A works on new file"; 
    123124unlink "test_file"; 
    124125 
     126if (! -f "README") { 
     127  skip 3, "no file README"; 
     128} else { 
     129  ok (-M "README") > 0, "-M works on existing file"; 
     130  ok (-C "README") > 0, "-C works on existing file"; 
     131  ok (-A "README") > 0, "-A works on existing file"; 
     132} 
     133 
     134ok not -M "xyzzy", "-M returns undef when no file"; 
     135ok not -C "xyzzy", "-C returns undef when no file"; 
     136ok not -A "xyzzy", "-A returns undef when no file";