loading code progress
This commit is contained in:
parent
5373ddaf9c
commit
8df4670d80
@ -14,24 +14,29 @@ import Encoding
|
|||||||
|
|
||||||
type PluginSet = M.HashMap String Plugin
|
type PluginSet = M.HashMap String Plugin
|
||||||
|
|
||||||
data Plugin = Plugin { wew :: Int,
|
data Plugin = Plugin { pluginEvent :: String, -- e.g. PRIVMSG
|
||||||
lad :: Int }
|
pluginEntry :: Int }
|
||||||
|
|
||||||
load :: PluginSet -> IO (Either String (IO PluginSet))
|
load :: PluginSet -> String -> IO (Either String PluginSet)
|
||||||
load = do initObjLinker RetainCAFs
|
load set path = do
|
||||||
loadObj "Plugin.o"
|
initObjLinker RetainCAFs
|
||||||
_ret <- resolveObjs
|
loadObj "Plugin.o"
|
||||||
ptr <- lookupSymbol (mangleSymbol Nothing "Plugin" "f")
|
_ret <- resolveObjs
|
||||||
case ptr of
|
ptr <- lookupSymbol (mangleSymbol Nothing "Plugin" "f")
|
||||||
Nothing -> return $ Left "Couldn’t load symbol"
|
case ptr of
|
||||||
Just (Ptr addr) -> case addrToAny# addr of
|
Nothing -> return $ Left "Couldn’t load symbol"
|
||||||
(# f #) -> return $ Right f
|
Just (Ptr addr) -> case addrToAny# addr of
|
||||||
|
(# f #) -> return $ Right f
|
||||||
|
|
||||||
unload :: String -> IO PluginSet
|
unload :: PluginSet -> String -> IO PluginSet
|
||||||
unload plugin = catch (unloadObj $ plugin <> ".o") exceptionHandler
|
unload set plugin = catch unloadPlugin exceptionHandler
|
||||||
|
where exceptionHandler :: ErrorCall -> IO PluginSet
|
||||||
|
exceptionHandler _ = return set
|
||||||
|
|
||||||
exceptionHandler :: ErrorCall -> IO PluginSet
|
unloadPlugin :: IO PluginSet
|
||||||
exceptionHandler _ = return ()
|
unloadPlugin = do
|
||||||
|
unloadObj $ plugin <> ".o"
|
||||||
|
return $ M.delete plugin set
|
||||||
|
|
||||||
mangleSymbol :: Maybe String -> String -> String -> String
|
mangleSymbol :: Maybe String -> String -> String -> String
|
||||||
mangleSymbol pkg module' valsym =
|
mangleSymbol pkg module' valsym =
|
||||||
|
Loading…
Reference in New Issue
Block a user