Skip to content

Instantly share code, notes, and snippets.

@cstrahan
Forked from cocreature/main.hs
Created October 2, 2017 07:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cstrahan/3c6144ef6e80aa476d7596f2cb0f45f2 to your computer and use it in GitHub Desktop.
Save cstrahan/3c6144ef6e80aa476d7596f2cb0f45f2 to your computer and use it in GitHub Desktop.
{-# 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",_) -> "_"
_ -> ""
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