diff options
author | Csaba Hruska <csaba.hruska@gmail.com> | 2015-12-21 13:48:22 +0100 |
---|---|---|
committer | Csaba Hruska <csaba.hruska@gmail.com> | 2015-12-21 13:48:22 +0100 |
commit | befc5afb22b36d744c403d103d591c5d190d394f (patch) | |
tree | 05e390bef55b0662a9a919b886322b66b113ff21 /lambdacube-ir.haskell/src | |
parent | dc8e31235fccbe5ea54d94b0ca69e005ca88c7ea (diff) |
add lambdacube-ir haskell lib
Diffstat (limited to 'lambdacube-ir.haskell/src')
l--------- | lambdacube-ir.haskell/src/IR.hs | 1 | ||||
-rw-r--r-- | lambdacube-ir.haskell/src/Linear.hs | 60 |
2 files changed, 61 insertions, 0 deletions
diff --git a/lambdacube-ir.haskell/src/IR.hs b/lambdacube-ir.haskell/src/IR.hs new file mode 120000 index 0000000..e256d2b --- /dev/null +++ b/lambdacube-ir.haskell/src/IR.hs | |||
@@ -0,0 +1 @@ | |||
../../ddl/out/IR.hs \ No newline at end of file | |||
diff --git a/lambdacube-ir.haskell/src/Linear.hs b/lambdacube-ir.haskell/src/Linear.hs new file mode 100644 index 0000000..1329841 --- /dev/null +++ b/lambdacube-ir.haskell/src/Linear.hs | |||
@@ -0,0 +1,60 @@ | |||
1 | {-# LANGUAGE DeriveFunctor, OverloadedStrings #-} | ||
2 | module Linear where | ||
3 | |||
4 | import Data.Int | ||
5 | import Data.Word | ||
6 | import Data.Map | ||
7 | |||
8 | import Data.Text | ||
9 | import Data.Aeson | ||
10 | import Control.Monad | ||
11 | |||
12 | data V2 a = V2 !a !a deriving (Eq,Ord,Show,Read,Functor) | ||
13 | data V3 a = V3 !a !a !a deriving (Eq,Ord,Show,Read,Functor) | ||
14 | data V4 a = V4 !a !a !a !a deriving (Eq,Ord,Show,Read,Functor) | ||
15 | |||
16 | -- matrices are stored in column major order | ||
17 | type M22F = V2 V2F | ||
18 | type M23F = V3 V2F | ||
19 | type M24F = V4 V2F | ||
20 | type M32F = V2 V3F | ||
21 | type M33F = V3 V3F | ||
22 | type M34F = V4 V3F | ||
23 | type M42F = V2 V4F | ||
24 | type M43F = V3 V4F | ||
25 | type M44F = V4 V4F | ||
26 | |||
27 | type V2F = V2 Float | ||
28 | type V3F = V3 Float | ||
29 | type V4F = V4 Float | ||
30 | type V2I = V2 Int32 | ||
31 | type V3I = V3 Int32 | ||
32 | type V4I = V4 Int32 | ||
33 | type V2U = V2 Word32 | ||
34 | type V3U = V3 Word32 | ||
35 | type V4U = V4 Word32 | ||
36 | type V2B = V2 Bool | ||
37 | type V3B = V3 Bool | ||
38 | type V4B = V4 Bool | ||
39 | |||
40 | instance ToJSON a => ToJSON (V2 a) where | ||
41 | toJSON (V2 x y) = object ["x" .= x, "y" .= y] | ||
42 | |||
43 | instance ToJSON a => ToJSON (V3 a) where | ||
44 | toJSON (V3 x y z) = object ["x" .= x, "y" .= y, "z" .= z] | ||
45 | |||
46 | instance ToJSON a => ToJSON (V4 a) where | ||
47 | toJSON (V4 x y z w) = object ["x" .= x, "y" .= y, "z" .= z, "w" .= w] | ||
48 | |||
49 | instance FromJSON a => FromJSON (V2 a) where | ||
50 | parseJSON (Object obj) = V2 <$> obj .: "x" <*> obj .: "y" | ||
51 | parseJSON _ = mzero | ||
52 | |||
53 | instance FromJSON a => FromJSON (V3 a) where | ||
54 | parseJSON (Object obj) = V3 <$> obj .: "x" <*> obj .: "y" <*> obj .: "z" | ||
55 | parseJSON _ = mzero | ||
56 | |||
57 | instance FromJSON a => FromJSON (V4 a) where | ||
58 | parseJSON (Object obj) = V4 <$> obj .: "x" <*> obj .: "y" <*> obj .: "z" <*> obj .: "w" | ||
59 | parseJSON _ = mzero | ||
60 | |||