3 import Control
.Concurrent
4 import System
.Environment
14 ++ map ("-X"++) ["ExistentialQuantification","GeneralizedNewtypeDeriving","MultiParamTypeClasses","CPP","PatternGuards","FunctionalDependencies"]
16 -- | Main entry point, if the bot is dynamically built
17 -- it will load the code appropriately and start, otherwise
18 -- it will just jump to a static main that we will execute with.
19 -- If executed with '-offline' it will go into offline mode where
20 -- you can just experiment with the plugin interface and whatnot.
24 let offline
= if (null av
) then False
25 else (if head av
== "-offline" then True
27 putStrLn "infinity starting..."
29 m
<- makeAll
"Infinity.hs" ghcargs
30 (mod,imain
) <- case m
of
32 -- apparently there's some sort of limitation in regards to having modules
33 -- that re-export other modules and their symbols with hs-plugins. that is,
34 -- we cannot load Infinity.o and get the symbols from there such as imain,
35 -- instead we have to directly load Infinity/Main.o and get the syms from that
36 -- we run makeAll over Infinity.hs since it keeps the project hierarchy nice,
37 -- and it will cause all these modules to be reloaded anyway.
39 stat
<- load_
"Infinity/Main.o" [".","Infinity","Infinity/Plugins"] "offlinemode"
43 putStrLn "Couldn't load Infinity.Main.offlinemode:"
45 exitWith $ ExitFailure
127
46 ldstat
<- load_
"Infinity/Main.o" [".","Infinity","Infinity/Plugins"] "imain"
48 LoadSuccess v m
-> return (v
,m
)
50 putStrLn "Couldn't load Infinity.Main.imain:"
52 exitWith $ ExitFailure
127
54 putStrLn "FATAL: Couldn't compile Infinity.hs:"
56 exitWith $ ExitFailure
127
58 putStrLn "Compiled & Loaded Infinity.Main.imain..."
61 when offline offlinemode
66 -- | Dynamic rebooting function
67 reboot
:: Module
-> a
-> IO ()
69 mkstat
<- makeAll
"Infinity.hs" ghcargs
73 ldstat
<- load_
"Infinity/Main.o" [".","Infinity","Infinity/Plugins"] "imain'"
75 LoadFailure e
-> fatality e
76 LoadSuccess v imain
' -> do
77 putStrLn "REBOOT: Successful recompilation & reloading, rebooting..."
79 MakeFailure e
-> fatality e
82 putStrLn $ "REBOOT: FATAL: Couldn't reboot thread, err:"
85 -- | Dynamic rebooting function
86 -- Note: This is the static build so this
87 -- function does nothing.
88 reboot
:: a
-> a
-> IO ()
89 reboot _ _
= return ()