-- This is the actual startup code, however,
-- each thread is spawned off in it's own
-- thread which is started in the dynamically
-- loaded IMain.dynmain
module Main where
import Control.Concurrent
import System.Plugins
import System.Exit
import GHC.Exts
ghcargs = []
main = do
putStrLn "infinity starting..."
m <- makeAll "IMain.hs" ghcargs
(mod,imain) <- case m of
MakeSuccess _ obj -> do
ldstat <- load_ obj ["."] "main" -- pull main first off
case ldstat of
LoadSuccess v m -> return (v,m)
LoadFailure e -> do
putStrLn "Couldn't load IMain.dynmain:"
mapM_ putStrLn e
exitWith $ ExitFailure 127
MakeFailure e -> do
putStrLn "FATAL: Couldn't compile IMain.hs:"
mapM_ putStrLn e
exitWith $ ExitFailure 127
putStrLn "Compiled & Loaded IMain.main..."
imain mod reboot
reboot :: Module -> a -> IO ()
reboot mod st = do
mkstat <- makeAll "IMain.hs" ghcargs
case mkstat of
MakeSuccess _ o -> do
unloadAll mod
ldstat <- load_ "IMain.o" ["."] "main'"
case ldstat of
LoadSuccess v main' -> do
putStrLn "REBOOT: Successful recompilation & reloading, rebooting..."
main' st v
LoadFailure e -> fatality e
MakeFailure e -> fatality e
where
fatality errs = do
putStrLn $ "REBOOT: FATAL: Couldn't reboot thread, err:"
mapM_ putStrLn errs