{-# LANGUAGE ForeignFunctionInterface #-} module MLP.Runtime where import Foreign.Ptr import Foreign.C.Types import Foreign.C.String import qualified MLP import qualified MLP.Context foreign import ccall unsafe "mlp.h mlp_runtime_new" c_new :: Ptr MLP.C_context -> Ptr MLP.C_language -> IO (Ptr MLP.C_runtime) new :: MLP.Context -> MLP.Language -> IO MLP.Runtime new ctx@(MLP.Context c_ctx) lang@(MLP.Language c_lang) = do MLP.withFuncDebug "Runtime new" $ MLP.Context.try ctx $ do c_rt <- c_new c_ctx c_lang return $ MLP.Runtime c_rt foreign import ccall unsafe "mlp.h mlp_runtime_delete" c_delete :: Ptr MLP.C_context -> Ptr MLP.C_runtime -> IO () delete :: MLP.Context -> MLP.Runtime -> IO () delete ctx@(MLP.Context c_ctx) rt@(MLP.Runtime c_rt) = do MLP.withFuncDebug "Runtime delete" $ MLP.Context.try ctx $ c_delete c_ctx c_rt foreign import ccall unsafe "mlp.h mlp_runtime_load_library" c_load_library :: Ptr MLP.C_context -> Ptr MLP.C_runtime -> CString -> IO () loadLibrary :: MLP.Context -> MLP.Runtime -> String -> IO () loadLibrary ctx@(MLP.Context c_ctx) rt@(MLP.Runtime c_rt) l = do MLP.withFuncDebug "Runtime load_library" $ MLP.Context.try ctx $ withCString l $ \c_lib -> c_load_library c_ctx c_rt c_lib