module Foreign.Hoppy.Generator.Types (
constT,
voidT,
ptrT,
refT,
fnT,
fnT',
boolT,
boolT',
charT,
ucharT,
wcharT,
shortT,
ushortT,
intT,
intT',
uintT,
longT,
ulongT,
llongT,
ullongT,
floatT,
floatT',
doubleT,
doubleT',
int8T,
int16T,
int32T,
int64T,
word8T,
word16T,
word32T,
word64T,
ptrdiffT,
sizeT,
ssizeT,
makeNumericType,
convertByCoercingIntegral,
convertByCoercingFloating,
manualT,
callbackT,
enumT,
objT,
objToHeapT,
toGcT,
) where
import {-# SOURCE #-} qualified Foreign.Hoppy.Generator.Language.Haskell as LH
import {-# SOURCE #-} Foreign.Hoppy.Generator.Spec.Callback (callbackT)
import {-# SOURCE #-} Foreign.Hoppy.Generator.Spec.Class (Class)
import {-# SOURCE #-} Foreign.Hoppy.Generator.Spec.Enum (enumT)
import {-# SOURCE #-} Foreign.Hoppy.Generator.Spec.Function (fnT, fnT')
import Foreign.Hoppy.Generator.Spec.Base
import Language.Haskell.Syntax (
HsName (HsIdent),
HsQName (UnQual),
HsType (HsTyCon),
)
voidT :: Type
voidT = Internal_TVoid
boolT :: Type
boolT =
makeNumericType "bool" mempty
(do LH.addImports hsImportForPrelude
return $ HsTyCon $ UnQual $ HsIdent "HoppyP.Bool")
(Just $ do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CBool")
(CustomConversion $ do
LH.addImports $ mconcat [hsImport1 "Prelude" "(.)",
hsImportForPrelude]
LH.sayLn "\\x -> HoppyP.return $ if x then 1 else 0")
(CustomConversion $ do
LH.addImports $ mconcat [hsImports "Prelude" ["(.)", "(/=)"],
hsImportForPrelude]
LH.sayLn "(HoppyP.return . (/= 0))")
boolT' :: Type
boolT' =
makeNumericType "bool" mempty
(do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CBool")
Nothing BinaryCompatible BinaryCompatible
charT :: Type
charT =
makeNumericType "char" mempty
(do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CChar")
Nothing BinaryCompatible BinaryCompatible
ucharT :: Type
ucharT =
makeNumericType "unsigned char" mempty
(do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CUChar")
Nothing BinaryCompatible BinaryCompatible
wcharT :: Type
wcharT =
makeNumericType "wchar_t" mempty
(do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CWchar")
Nothing BinaryCompatible BinaryCompatible
shortT :: Type
shortT =
makeNumericType "short" mempty
(do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CShort")
Nothing BinaryCompatible BinaryCompatible
ushortT :: Type
ushortT =
makeNumericType "unsigned short" mempty
(do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CUShort")
Nothing BinaryCompatible BinaryCompatible
intT :: Type
intT =
makeNumericType "int" mempty
(do LH.addImports hsImportForPrelude
return $ HsTyCon $ UnQual $ HsIdent "HoppyP.Int")
(Just $ do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CInt")
convertByCoercingIntegral convertByCoercingIntegral
intT' :: Type
intT' =
makeNumericType "int" mempty
(do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CInt")
Nothing BinaryCompatible BinaryCompatible
uintT :: Type
uintT =
makeNumericType "unsigned int" mempty
(do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CUInt")
Nothing BinaryCompatible BinaryCompatible
longT :: Type
longT =
makeNumericType "long" mempty
(do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CLong")
Nothing BinaryCompatible BinaryCompatible
ulongT :: Type
ulongT =
makeNumericType "unsigned long" mempty
(do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CULong")
Nothing BinaryCompatible BinaryCompatible
llongT :: Type
llongT =
makeNumericType "long long" mempty
(do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CLLong")
Nothing BinaryCompatible BinaryCompatible
ullongT :: Type
ullongT =
makeNumericType "unsigned long long" mempty
(do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CULLong")
Nothing BinaryCompatible BinaryCompatible
floatT :: Type
floatT =
makeNumericType "float" mempty
(do LH.addImports hsImportForPrelude
return $ HsTyCon $ UnQual $ HsIdent "HoppyP.Float")
(Just $ do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CFloat")
convertByCoercingFloating convertByCoercingFloating
floatT' :: Type
floatT' =
makeNumericType "float" mempty
(do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "Foreign.C.CFloat")
Nothing BinaryCompatible BinaryCompatible
doubleT :: Type
doubleT =
makeNumericType "double" mempty
(do LH.addImports hsImportForPrelude
return $ HsTyCon $ UnQual $ HsIdent "HoppyP.Double")
(Just $ do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CDouble")
convertByCoercingFloating convertByCoercingFloating
doubleT' :: Type
doubleT' =
makeNumericType "double" mempty
(do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "Foreign.C.CDouble")
Nothing BinaryCompatible BinaryCompatible
int8T :: Type
int8T =
makeNumericType "int8_t" (reqInclude $ includeStd "cstdint")
(do LH.addImports hsImportForInt
return $ HsTyCon $ UnQual $ HsIdent "HoppyDI.Int8")
Nothing BinaryCompatible BinaryCompatible
int16T :: Type
int16T =
makeNumericType "int16_t" (reqInclude $ includeStd "cstdint")
(do LH.addImports hsImportForInt
return $ HsTyCon $ UnQual $ HsIdent "HoppyDI.Int16")
Nothing BinaryCompatible BinaryCompatible
int32T :: Type
int32T =
makeNumericType "int32_t" (reqInclude $ includeStd "cstdint")
(do LH.addImports hsImportForInt
return $ HsTyCon $ UnQual $ HsIdent "HoppyDI.Int32")
Nothing BinaryCompatible BinaryCompatible
int64T :: Type
int64T =
makeNumericType "int64_t" (reqInclude $ includeStd "cstdint")
(do LH.addImports hsImportForInt
return $ HsTyCon $ UnQual $ HsIdent "HoppyDI.Int64")
Nothing BinaryCompatible BinaryCompatible
word8T :: Type
word8T =
makeNumericType "uint8_t" (reqInclude $ includeStd "cstdint")
(do LH.addImports hsImportForWord
return $ HsTyCon $ UnQual $ HsIdent "HoppyDW.Word8")
Nothing BinaryCompatible BinaryCompatible
word16T :: Type
word16T =
makeNumericType "uint16_t" (reqInclude $ includeStd "cstdint")
(do LH.addImports hsImportForWord
return $ HsTyCon $ UnQual $ HsIdent "HoppyDW.Word16")
Nothing BinaryCompatible BinaryCompatible
word32T :: Type
word32T =
makeNumericType "uint32_t" (reqInclude $ includeStd "cstdint")
(do LH.addImports hsImportForWord
return $ HsTyCon $ UnQual $ HsIdent "HoppyDW.Word32")
Nothing BinaryCompatible BinaryCompatible
word64T :: Type
word64T =
makeNumericType "uint64_t" (reqInclude $ includeStd "cstdint")
(do LH.addImports hsImportForWord
return $ HsTyCon $ UnQual $ HsIdent "HoppyDW.Word64")
Nothing BinaryCompatible BinaryCompatible
ptrdiffT :: Type
ptrdiffT =
makeNumericType "ptrdiff_t" (reqInclude $ includeStd "cstddef")
(do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CPtrdiff")
Nothing BinaryCompatible BinaryCompatible
sizeT :: Type
sizeT =
makeNumericType "size_t" (reqInclude $ includeStd "cstddef")
(do LH.addImports hsImportForForeignC
return $ HsTyCon $ UnQual $ HsIdent "HoppyFC.CSize")
Nothing BinaryCompatible BinaryCompatible
ssizeT :: Type
ssizeT =
makeNumericType "ssize_t" (reqInclude $ includeStd "cstddef")
(do LH.addImports hsImportForSystemPosixTypes
return $ HsTyCon $ UnQual $ HsIdent "HoppySPT.CSsize")
Nothing BinaryCompatible BinaryCompatible
makeNumericType ::
String
-> Reqs
-> LH.Generator HsType
-> Maybe (LH.Generator HsType)
-> ConversionMethod (LH.Generator ())
-> ConversionMethod (LH.Generator ())
-> Type
makeNumericType cppName cppReqs hsTypeGen hsCTypeGen convertToCpp convertFromCpp =
Internal_TManual spec
where spec =
(makeConversionSpec cppName $ makeConversionSpecCpp cppName $ return cppReqs)
{ conversionSpecHaskell =
Just $ makeConversionSpecHaskell
hsTypeGen
hsCTypeGen
convertToCpp
convertFromCpp
}
convertByCoercingIntegral :: ConversionMethod (LH.Generator ())
convertByCoercingIntegral = CustomConversion $ do
LH.addImports $ mconcat [hsImport1 "Prelude" "(.)",
hsImportForPrelude,
hsImportForRuntime]
LH.sayLn "HoppyP.return . HoppyFHR.coerceIntegral"
convertByCoercingFloating :: ConversionMethod (LH.Generator ())
convertByCoercingFloating = CustomConversion $ do
LH.addImports $ mconcat [hsImport1 "Prelude" "(.)",
hsImportForPrelude]
LH.sayLn "HoppyP.return . HoppyP.realToFrac"
ptrT :: Type -> Type
ptrT = Internal_TPtr
refT :: Type -> Type
refT = Internal_TRef
objT :: Class -> Type
objT = Internal_TObj
objToHeapT :: Class -> Type
objToHeapT = Internal_TObjToHeap
toGcT :: Type -> Type
toGcT = Internal_TToGc
manualT :: ConversionSpec -> Type
manualT = Internal_TManual
constT :: Type -> Type
constT = Internal_TConst