forked from expipiplus1/vulkan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZero.hs
82 lines (63 loc) · 1.48 KB
/
Zero.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
{-# language CPP #-}
module Vulkan.Zero (Zero(..)) where
import GHC.Ptr (nullFunPtr)
import Foreign.Ptr (nullPtr)
import Foreign.C.Types (CChar)
import Foreign.C.Types (CFloat)
import Foreign.C.Types (CInt)
import Foreign.C.Types (CSize)
import Foreign.Storable (Storable)
import Data.Int (Int16)
import Data.Int (Int32)
import Data.Int (Int64)
import Data.Int (Int8)
import Foreign.Ptr (FunPtr)
import Foreign.Ptr (Ptr)
import GHC.TypeNats (KnownNat)
import Data.Word (Word16)
import Data.Word (Word32)
import Data.Word (Word64)
import Data.Word (Word8)
-- | A class for initializing things with all zero data
--
-- Any instance should satisfy the following law:
--
-- @ new zero = calloc @ or @ with zero = withZeroCStruct @
--
-- i.e. Marshaling @zero@ to memory yeilds only zero-valued bytes, except
-- for structs which require a "type" tag
--
class Zero a where
zero :: a
instance Zero Bool where
zero = False
instance Zero (FunPtr a) where
zero = nullFunPtr
instance Zero (Ptr a) where
zero = nullPtr
instance Zero Int8 where
zero = 0
instance Zero Int16 where
zero = 0
instance Zero Int32 where
zero = 0
instance Zero Int64 where
zero = 0
instance Zero Word8 where
zero = 0
instance Zero Word16 where
zero = 0
instance Zero Word32 where
zero = 0
instance Zero Word64 where
zero = 0
instance Zero Float where
zero = 0
instance Zero CFloat where
zero = 0
instance Zero CChar where
zero = 0
instance Zero CSize where
zero = 0
instance Zero CInt where
zero = 0