3 import Control
.Concurrent
4 import System
.Environment
15 -- | Main entry point, if the bot is dynamically built
16 -- it will load the code appropriately and start, otherwise
17 -- it will just jump to a static main that we will execute with.
18 -- If executed with '-offline' it will go into offline mode where
19 -- you can just experiment with the plugin interface and whatnot.
23 let offline
= if (null av
) then False
24 else (if head av
== "-offline" then True
26 putStrLn "infinity starting..."
28 m
<- makeAll
"Infinity.hs" ghcargs
29 (mod,imain
) <- case m
of
31 -- apparently there's some sort of limitation in regards to having modules
32 -- that re-export other modules and their symbols with hs-plugins. that is,
33 -- we cannot load Infinity.o and get the symbols from there such as imain,
34 -- instead we have to directly load Infinity/Main.o and get the syms from that
35 -- we run makeAll over Infinity.hs since it keeps the project hierarchy nice,
36 -- and it will cause all these modules to be reloaded anyway.
38 stat
<- load_
"Infinity/Main.o" [".","Infinity","Infinity/Plugins"] "offlinemode"
42 putStrLn "Couldn't load Infinity.Main.offlinemode:"
44 exitWith $ ExitFailure
127
45 ldstat
<- load_
"Infinity/Main.o" [".","Infinity","Infinity/Plugins"] "imain"
47 LoadSuccess v m
-> return (v
,m
)
49 putStrLn "Couldn't load Infinity.Main.imain:"
51 exitWith $ ExitFailure
127
53 putStrLn "FATAL: Couldn't compile Infinity.hs:"
55 exitWith $ ExitFailure
127
57 putStrLn "Compiled & Loaded Infinity.Main.imain..."
60 when offline offlinemode
65 -- | Dynamic rebooting function
66 reboot
:: Module
-> a
-> IO ()
68 mkstat
<- makeAll
"Infinity.hs" ghcargs
72 ldstat
<- load_
"Infinity/Main.o" [".","Infinity","Infinity/Plugins"] "imain'"
74 LoadFailure e
-> fatality e
75 LoadSuccess v imain
' -> do
76 putStrLn "REBOOT: Successful recompilation & reloading, rebooting..."
78 MakeFailure e
-> fatality e
81 putStrLn $ "REBOOT: FATAL: Couldn't reboot thread, err:"
84 -- | Dynamic rebooting function
85 -- Note: This is the static build so this
86 -- function does nothing.
87 reboot
:: a
-> a
-> IO ()
88 reboot _ _
= return ()