58 lines
1.9 KiB
Haskell
Raw Permalink Normal View History

2005-04-24 08:51:33 +00:00
--
-- Copyright (c) 2004 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.
--
import System.Eval.Haskell (unsafeEval)
2005-04-24 08:51:33 +00:00
2005-12-25 23:11:57 +00:00
import Data.Char (chr)
2005-04-24 08:51:33 +00:00
import Data.Maybe (isJust, fromJust)
2005-12-25 23:11:57 +00:00
import Control.Monad
2005-04-24 08:51:33 +00:00
2005-12-25 23:11:57 +00:00
import System.Random
2005-04-24 08:51:33 +00:00
import System.Exit (exitWith, ExitCode(ExitSuccess))
import System.IO (getContents, putStrLn)
2005-04-24 08:51:33 +00:00
import System.Posix.Resource (setResourceLimit,
Resource(ResourceCPUTime),
ResourceLimits(ResourceLimits),
ResourceLimit(ResourceLimit))
2005-12-25 23:11:57 +00:00
import qualified Control.Exception (catch)
2005-04-24 08:51:33 +00:00
rlimit = ResourceLimit 3
context = prehier ++ datas ++ qualifieds ++ controls
2005-04-24 08:51:33 +00:00
prehier = ["Char", "List", "Maybe", "Numeric", "Random" ]
2005-12-25 23:11:57 +00:00
qualifieds = ["qualified Data.Map as M"
,"qualified Data.Set as S"
,"qualified Data.IntSet as I"]
2005-04-24 08:51:33 +00:00
datas = map ("Data." ++) [
"Bits", "Bool", "Char", "Dynamic", "Either",
2005-12-25 23:11:57 +00:00
"Graph", "Int", "Ix", "List",
"Maybe", "Ratio", "Tree", "Tuple", "Typeable", "Word"
2005-04-24 08:51:33 +00:00
]
controls = map ("Control." ++) ["Monad", "Monad.Reader", "Monad.Fix", "Arrow"]
2005-04-24 08:51:33 +00:00
main = do
2005-12-25 23:11:57 +00:00
setResourceLimit ResourceCPUTime (ResourceLimits rlimit rlimit)
s <- getLine
when (not . null $ s) $ do
x <- sequence (take 3 (repeat $ getStdRandom (randomR (97,122)) >>= return . chr))
s <- unsafeEval ("let { "++x++
" = \n# 1 \"<irc>\"\n"++s++
"\n} in take 2048 (show "++x++
")") context
when (isJust s) $ Control.Exception.catch
(putStrLn $ fromJust s)
(\e -> putStrLn $ "Exception: " ++ show e )
exitWith ExitSuccess
2005-04-24 08:51:33 +00:00