summaryrefslogtreecommitdiff
path: root/AttributeData.hs
diff options
context:
space:
mode:
authorJoe Crayne <joe@jerkface.net>2019-05-19 17:44:28 -0400
committerJoe Crayne <joe@jerkface.net>2019-05-19 17:44:28 -0400
commit268aaced12086ed8376affdf62711abcb651277e (patch)
tree5dbba3fd4192be3579bdf359e880d6ed6c0773bc /AttributeData.hs
parentccf714a691a95be84ba168a725b6f0187bb903ea (diff)
Experiment: use Data.Data to generate AttributeKeys.
Diffstat (limited to 'AttributeData.hs')
-rw-r--r--AttributeData.hs91
1 files changed, 91 insertions, 0 deletions
diff --git a/AttributeData.hs b/AttributeData.hs
new file mode 100644
index 0000000..2b2bc96
--- /dev/null
+++ b/AttributeData.hs
@@ -0,0 +1,91 @@
1{-# LANGUAGE DataKinds #-}
2{-# LANGUAGE DeriveDataTypeable #-}
3{-# LANGUAGE GADTs #-}
4{-# LANGUAGE LambdaCase #-}
5{-# LANGUAGE PartialTypeSignatures #-}
6{-# LANGUAGE RecordWildCards #-}
7{-# LANGUAGE ScopedTypeVariables #-}
8{-# LANGUAGE TypeOperators #-}
9{-# LANGUAGE ConstraintKinds #-}
10
11module AttributeData where
12
13import Control.Monad
14import Data.Data
15import Data.Foldable
16import Data.Function
17import Data.Int
18import Data.IORef
19import Data.Maybe
20import Data.Some
21import Data.Word
22import qualified Data.Map.Strict as Map
23import qualified Data.Vector as V
24 ;import Data.Vector as V ((!),(//))
25import Foreign.C.Types (CPtrdiff)
26import Foreign.Marshal
27import Foreign.Ptr
28import Foreign.Storable
29
30import LambdaCube.GL as LC
31import LambdaCube.GL.Data -- (uploadCubeMapToGPU,uploadTextureBufferToGPU,updateTextureBuffer)
32import LambdaCube.GL.Mesh as LC
33import LambdaCube.GL.Type
34import LambdaCube.IR as LC
35import LambdaCube.GL.Util
36import LambdaCube.GL.Input.Type
37import LambdaCube.GL.Input hiding (createObjectCommands)
38
39
40import MaskableStream
41
42data Witness c = c => Witness
43
44tagTypable :: TypeTag c -> Witness (Typeable c)
45tagTypable TypeBool = Witness
46tagTypable TypeV2B = Witness
47tagTypable TypeV3B = Witness
48tagTypable TypeV4B = Witness
49tagTypable TypeWord = Witness
50tagTypable TypeV2U = Witness
51tagTypable TypeV3U = Witness
52tagTypable TypeV4U = Witness
53tagTypable TypeInt = Witness
54tagTypable TypeV2I = Witness
55tagTypable TypeV3I = Witness
56tagTypable TypeV4I = Witness
57tagTypable TypeFloat = Witness
58tagTypable TypeV2F = Witness
59tagTypable TypeV3F = Witness
60tagTypable TypeV4F = Witness
61tagTypable TypeM22F = Witness
62tagTypable TypeM23F = Witness
63tagTypable TypeM24F = Witness
64tagTypable TypeM32F = Witness
65tagTypable TypeM33F = Witness
66tagTypable TypeM34F = Witness
67tagTypable TypeM42F = Witness
68tagTypable TypeM43F = Witness
69tagTypable TypeM44F = Witness
70
71
72foo :: forall attrkeys. Data attrkeys => (String -> Maybe (Some AttributeKey)) -> Maybe attrkeys
73foo lookupA = do
74 let dt = dataTypeOf (error "dataTypeOf attrkeys" :: attrkeys)
75 case dataTypeRep dt of
76 AlgRep (c:_) -> do
77 let fields = constrFields c
78 mkb :: Data k => String -> k
79 mkb n = fix $ \v ->
80 fromMaybe (error $ "mkb " ++ n) $ case lookupA n of
81 Just (This k@(AttributeKey tt _ _)) -> case tagTypable tt of
82 Witness -> cast k
83 _ -> Nothing
84 z :: x -> (,) [String] x
85 z r = (fields, r)
86 k :: Data b => (,) [String] (b -> r) -> (,) [String] r
87 k (n:ns,btor) = (ns,btor (mkb n))
88 (_,ks) = gunfold k z c :: (,) [String] attrkeys
89 Just ks
90 _ -> Nothing
91