Compare commits
No commits in common. "d2378812ce6e8c27ae02a7ca707c6ffa537858b1" and "5373ddaf9cfd531bbf49a1021c2c46e47cc605c9" have entirely different histories.
d2378812ce
...
5373ddaf9c
@ -5,8 +5,6 @@ module IRC.Plugins.Loader ( load ) where
|
||||
|
||||
import qualified Data.HashMap.Lazy as M
|
||||
|
||||
import IRC.Plugins.Plugin
|
||||
|
||||
import Control.Exception ( catch, ErrorCall )
|
||||
import GHC.Exts ( addrToAny# )
|
||||
import GHC.Ptr ( Ptr(..) )
|
||||
@ -14,26 +12,26 @@ import System.Info ( os, arch )
|
||||
import GHCi.ObjLink
|
||||
import Encoding
|
||||
|
||||
load :: PluginSet -> String -> IO (Either String PluginSet)
|
||||
load set path = do
|
||||
initObjLinker RetainCAFs
|
||||
loadObj "Plugin.o"
|
||||
_ret <- resolveObjs
|
||||
ptr <- lookupSymbol (mangleSymbol Nothing "Plugin" "f")
|
||||
case ptr of
|
||||
Nothing -> return $ Left "Couldn’t load symbol"
|
||||
Just (Ptr addr) -> case addrToAny# addr of
|
||||
(# f #) -> return $ Right f
|
||||
type PluginSet = M.HashMap String Plugin
|
||||
|
||||
unload :: PluginSet -> String -> IO PluginSet
|
||||
unload set plugin = catch unloadPlugin exceptionHandler
|
||||
where exceptionHandler :: ErrorCall -> IO PluginSet
|
||||
exceptionHandler _ = return set
|
||||
data Plugin = Plugin { wew :: Int,
|
||||
lad :: Int }
|
||||
|
||||
unloadPlugin :: IO PluginSet
|
||||
unloadPlugin = do
|
||||
unloadObj $ plugin <> ".o"
|
||||
return $ M.delete plugin set
|
||||
load :: PluginSet -> IO (Either String (IO PluginSet))
|
||||
load = do initObjLinker RetainCAFs
|
||||
loadObj "Plugin.o"
|
||||
_ret <- resolveObjs
|
||||
ptr <- lookupSymbol (mangleSymbol Nothing "Plugin" "f")
|
||||
case ptr of
|
||||
Nothing -> return $ Left "Couldn’t load symbol"
|
||||
Just (Ptr addr) -> case addrToAny# addr of
|
||||
(# f #) -> return $ Right f
|
||||
|
||||
unload :: String -> IO PluginSet
|
||||
unload plugin = catch (unloadObj $ plugin <> ".o") exceptionHandler
|
||||
|
||||
exceptionHandler :: ErrorCall -> IO PluginSet
|
||||
exceptionHandler _ = return ()
|
||||
|
||||
mangleSymbol :: Maybe String -> String -> String -> String
|
||||
mangleSymbol pkg module' valsym =
|
||||
|
||||
@ -1,8 +0,0 @@
|
||||
module IRC.Plugins.Plugin ( PluginSet, Plugin(..) ) where
|
||||
|
||||
import qualified Data.HashMap.Lazy as M
|
||||
|
||||
type PluginSet = M.HashMap String Plugin
|
||||
|
||||
data Plugin = Plugin { pluginEvent :: String, -- e.g. PRIVMSG
|
||||
pluginEntry :: Int }
|
||||
@ -1,4 +1,3 @@
|
||||
include_rules
|
||||
|
||||
: Plugin.hs |> ghc $(GHCFLAGS) -c %f |> %B.o %B.hi
|
||||
: Loader.hs | Plugin.hi |> ghc $(GHCFLAGS) -c %f |> %B.o %B.hi
|
||||
: foreach *.hs |> ghc $(GHCFLAGS) -c %f |> %B.o %B.hi
|
||||
|
||||
4
Tupfile
4
Tupfile
@ -1,4 +1,4 @@
|
||||
include_rules
|
||||
|
||||
: foreach *.hs | IRC/*.hi IRC/Plugins/*.hi |> ghc $(GHCFLAGS) -c %f |> %B.o %B.hi
|
||||
: *.o IRC/*.o IRC/Plugins/*.o |> ghc -o Main %f |> Main
|
||||
: foreach *.hs | IRC/*.hi |> ghc $(GHCFLAGS) -c %f |> %B.o %B.hi
|
||||
: *.o IRC/*.o |> ghc -o Main %f |> Main
|
||||
|
||||
@ -1 +1 @@
|
||||
GHCFLAGS += -i$(CWD) -Wall -O3
|
||||
GHCFLAGS += -Wall -O3
|
||||
|
||||
4
make.sh
4
make.sh
@ -9,8 +9,6 @@ if ! command -v tup >/dev/null; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
export CWD="$(readlink -f .)"
|
||||
|
||||
case $1 in
|
||||
run)
|
||||
$0 build >&2 || exit 1
|
||||
@ -24,7 +22,7 @@ case $1 in
|
||||
tup >&2
|
||||
;;
|
||||
clean)
|
||||
rm -f Main *.o *.hi IRC/*.o IRC/*.hi IRC/Plugins/*.o IRC/Plugins/*.hi
|
||||
rm -f Main *.o *.hi IRC/*.o IRC/*.hi
|
||||
;;
|
||||
*)
|
||||
usage
|
||||
|
||||
Loading…
Reference in New Issue
Block a user