{-# LANGUAGE CPP #-}
module Foreign.Hoppy.Generator.Spec.Conversion (
classSetConversionToHeap,
classSetConversionToGc,
) where
#if !MIN_VERSION_base(4,8,0)
import Data.Monoid (mconcat)
#endif
import Foreign.Hoppy.Generator.Language.Haskell
import Foreign.Hoppy.Generator.Spec.Base
import Foreign.Hoppy.Generator.Types
classSetConversionToHeap :: Class -> Class
classSetConversionToHeap cls = case classFindCopyCtor cls of
Just _ ->
flip classModifyConversion cls $ \c ->
c { classHaskellConversion = classHaskellConversionToHeap cls
}
Nothing -> error $ "classSetConversionToHeap: " ++ show cls ++ " must be copyable."
classSetConversionToGc :: Class -> Class
classSetConversionToGc cls = case classFindCopyCtor cls of
Just _ ->
flip classModifyConversion cls $ \c ->
c { classHaskellConversion = classHaskellConversionToGc cls
}
Nothing -> error $ "classSetConversionToGc: " ++ show cls ++ " must be copyable."
classHaskellConversionToHeap :: Class -> ClassHaskellConversion
classHaskellConversionToHeap cls =
ClassHaskellConversion
{ classHaskellConversionType = Just $ cppTypeToHsTypeAndUse HsHsSide $ ptrT $ objT cls
, classHaskellConversionToCppFn = Nothing
, classHaskellConversionFromCppFn = Just $ do
addImports hsImportForRuntime
sayLn "HoppyFHR.copy"
}
classHaskellConversionToGc :: Class -> ClassHaskellConversion
classHaskellConversionToGc cls =
ClassHaskellConversion
{ classHaskellConversionType = Just $ cppTypeToHsTypeAndUse HsHsSide $ ptrT $ objT cls
, classHaskellConversionToCppFn = Nothing
, classHaskellConversionFromCppFn = Just $ do
addImports $ mconcat [hsImport1 "Control.Monad" "(>=>)", hsImportForRuntime]
sayLn "HoppyFHR.copy >=> HoppyFHR.toGc"
}