module Metaplug.Loader where import Metaplug.Types import Control.Monad import Data.Typeable import Data.Dynamic import GHC loadFiles :: [String] -> MetaSession -> IO MetaSession loadFiles files s = do let s' = session s forM files $ \f -> do g <- guessTarget f Nothing addTarget s' g let flags = sflags s defaultCleanupHandler flags $ do r <- load s' LoadAllTargets case r of Failed -> error "Metaplug: Loading targets FAILED" Succeeded -> do return $ s{session = s'} compileCall :: (Typeable a) => String -> MetaSession -> IO a compileCall sym s = do let s' = session s r <- dynCompileExpr s' sym case r of Nothing -> error $ "Metaplug: Could not compile symbol '"++sym++"'." Just x -> do let x' = fromDynamic x case x' of Nothing -> error "Metaplug: Could not compile dynamic" Just x'' -> do return x''