69 lines
2.2 KiB
Haskell
Raw Normal View History

{-# OPTIONS -cpp #-}
2005-04-24 08:51:33 +00:00
--
-- Copyright (c) 2004-5 Don Stewart - http://www.cse.unsw.edu.au/~dons
2005-04-24 08:51:33 +00:00
-- GPL version 2 or later (see http://www.gnu.org/copyleft/gpl.html)
--
2005-04-24 10:05:36 +00:00
--
-- | Runplugs: use hs-plugins to run a Haskell expression under
-- controlled conditions.
--
2005-07-06 04:49:07 +00:00
import System.Eval.Haskell (unsafeEval_)
2005-04-24 08:51:33 +00:00
import Data.Maybe (isJust, fromJust)
import Control.Monad (when)
2005-07-06 04:49:07 +00:00
import Control.Exception (evaluate)
2005-04-24 08:51:33 +00:00
import System.Exit (exitWith, ExitCode(ExitSuccess))
2005-07-06 04:49:07 +00:00
import System.IO (hGetContents, hPutStrLn, putStrLn, hClose, stdin, stdout, stderr)
#if !defined(CYGWIN) && !defined(__MINGW32__)
2005-04-24 08:51:33 +00:00
import System.Posix.Resource (setResourceLimit,
Resource(ResourceCPUTime),
ResourceLimits(ResourceLimits),
ResourceLimit(ResourceLimit))
2005-07-06 04:49:07 +00:00
import Control.Concurrent ( forkIO )
import qualified Control.Exception ( evaluate )
2005-04-24 08:51:33 +00:00
rlimit = ResourceLimit 3
#endif
2005-04-24 08:51:33 +00:00
context = prehier ++ datas ++ controls
prehier = ["Char", "List", "Maybe", "Numeric", "Random" ]
datas = map ("Data." ++) [
"Bits", "Bool", "Char", "Dynamic", "Either",
"Graph", "Int", "Ix", "List", "Maybe",
#if __GLASGOW_HASKELL__ >= 604
"Map",
#else
"FiniteMap",
#endif
2005-04-24 10:05:36 +00:00
"Ratio", "Set", "Tree", "Tuple", "Typeable", "Word"
2005-04-24 08:51:33 +00:00
]
controls = map ("Control." ++) ["Monad", "Arrow"]
2005-07-06 04:49:07 +00:00
--
-- with ghc 6.4, ghc doesn't seem to be able to call gcc, setNoFDBlocking fails.
--
-- *** Assembler
-- gcc -I/tmp -c /tmp/ghc11596.s -o /tmp/MySzQ14137.o
--
-- Failed: gcc -I/tmp -c /tmp/ghc11596.s -o /tmp/MySzQ14137.o
-- gcc: setNonBlockingFD: invalid argument (Bad file descriptor)
--
2005-04-24 08:51:33 +00:00
main = do
#if !defined(CYGWIN) && defined(__MINGW32__)
2005-04-24 08:51:33 +00:00
setResourceLimit ResourceCPUTime (ResourceLimits rlimit rlimit)
#endif
2005-07-06 04:49:07 +00:00
s <- hGetContents stdin
2005-04-24 08:51:33 +00:00
when (not . null $ s) $ do
2005-07-06 04:49:07 +00:00
s <- unsafeEval_ ("(take 2048 (show ("++s++")))") context ["-v"] [] []
case s of
Left errs -> mapM_ putStrLn errs
Right s -> putStrLn s
2005-04-24 08:51:33 +00:00
exitWith ExitSuccess