getting shit to build

This commit is contained in:
Tiago Carvalho 2020-07-22 16:06:47 +01:00
parent 4d7b2b15fe
commit c07bc5eda0
2 changed files with 39 additions and 7 deletions

View File

@ -4,9 +4,9 @@ import Data.Word (Word16)
import qualified Network.Socket as S
data Connection = Connection { connSocket :: S.Socket,
connNick :: String,
}
--data Connection = Connection { connSocket :: S.Socket,
-- connNick :: String,
-- }
-- The host to connect to.
type Host = String
@ -14,5 +14,5 @@ type Host = String
-- The port to connect to.
type Port = Word16
connect :: Host -> Port
connect = error "unimplemented"
--connect :: Host -> Port
--connect = error "unimplemented"

View File

@ -1,4 +1,36 @@
{-# LANGUAGE MagicHash #-}
{-# LANGUAGE UnboxedTuples #-}
module IRC.Plugins.Loader where
test :: Int
test = 1
import GHC.Exts ( addrToAny# )
import GHC.Ptr ( Ptr(..) )
import System.Info ( os, arch )
import GHCi.ObjLink
import Encoding
load :: IO (Either String (IO ()))
load = do initObjLinker RetainCAFs
loadObj "Plugin.o"
_ret <- resolveObjs
ptr <- lookupSymbol (mangleSymbol Nothing "Plugin" "f")
case ptr of
Nothing -> return $ Left "Couldnt load symbol"
Just (Ptr addr) -> case addrToAny# addr of
(# f #) -> return $ Right f
mangleSymbol :: Maybe String -> String -> String -> String
mangleSymbol pkg module' valsym =
prefixUnderscore <>
maybe "" (\p -> zEncodeString p <> "_") pkg <>
zEncodeString module' <> "_" <> zEncodeString valsym <> "_closure"
prefixUnderscore :: String
prefixUnderscore =
case (os,arch) of
("mingw32","x86_64") -> ""
("cygwin","x86_64") -> ""
("mingw32",_) -> "_"
("darwin",_) -> "_"
("cygwin",_) -> "_"
_ -> ""