From cc6c634c82ccfdcc3f2ed0bd619db47a4f38e94b Mon Sep 17 00:00:00 2001 From: Tiago Carvalho Date: Wed, 22 Jul 2020 23:22:44 +0100 Subject: [PATCH] some progress on the plugin system --- IRC/Plugins/Loader.hs | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/IRC/Plugins/Loader.hs b/IRC/Plugins/Loader.hs index 2e1ee60..ea0f3e6 100644 --- a/IRC/Plugins/Loader.hs +++ b/IRC/Plugins/Loader.hs @@ -1,15 +1,23 @@ {-# LANGUAGE MagicHash #-} {-# LANGUAGE UnboxedTuples #-} -module IRC.Plugins.Loader where +module IRC.Plugins.Loader ( load ) where -import GHC.Exts ( addrToAny# ) -import GHC.Ptr ( Ptr(..) ) -import System.Info ( os, arch ) +import qualified Data.HashMap.Lazy as M + +import Control.Exception ( catch, ErrorCall ) +import GHC.Exts ( addrToAny# ) +import GHC.Ptr ( Ptr(..) ) +import System.Info ( os, arch ) import GHCi.ObjLink import Encoding -load :: IO (Either String (IO ())) +type PluginSet = M.HashMap String Plugin + +data Plugin = Plugin { wew :: Int, + lad :: Int } + +load :: PluginSet -> IO (Either String (IO PluginSet)) load = do initObjLinker RetainCAFs loadObj "Plugin.o" _ret <- resolveObjs @@ -19,6 +27,12 @@ load = do initObjLinker RetainCAFs 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 = prefixUnderscore <>