-
-
Save cstrahan/3c6144ef6e80aa476d7596f2cb0f45f2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE MagicHash, UnboxedTuples #-} | |
module Main(main) where | |
import GHC.Exts ( addrToAny# ) | |
import GHC.Ptr ( Ptr(..) ) | |
import System.Info ( os, arch ) | |
import Encoding | |
import ObjLink | |
main :: IO () | |
main = do initObjLinker | |
loadObj "plugin.o" | |
_ret <- resolveObjs | |
ptr <- lookupSymbol (mangleSymbol Nothing "Plugin" "f") | |
case ptr of | |
Nothing -> putStrLn "Couldn’t load symbol" | |
Just (Ptr addr) -> case addrToAny# addr of | |
(# hval #) -> putStrLn hval | |
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",_) -> "_" | |
_ -> "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Plugin(f) where | |
f :: String | |
f = "Monads are just monoids in the category of endofunctors, what’s the problem?" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment