|
3 | 3 | {-# LANGUAGE TupleSections #-} |
4 | 4 |
|
5 | 5 | -- | Template Haskell functions used internally |
6 | | -module Raylib.Internal.TH (genLenses, genNative) where |
7 | | - |
8 | | -import Control.Lens (makeLensesFor) |
9 | | -import Control.Monad (zipWithM) |
| 6 | +module Raylib.Internal.TH (genNative) where |
10 | 7 |
|
11 | 8 | #ifdef WEB_FFI |
12 | 9 |
|
13 | 10 | import Language.Haskell.TH |
14 | 11 | ( Body (NormalB), |
15 | 12 | Clause (Clause), |
16 | | - Con (RecC), |
17 | | - Dec (DataD, FunD, SigD), |
| 13 | + Dec (FunD, SigD), |
18 | 14 | DecsQ, |
19 | 15 | Exp (AppE, LitE, VarE), |
20 | | - Info (TyConI), |
21 | 16 | Lit (StringL), |
22 | | - Name, |
23 | 17 | TypeQ, |
24 | 18 | mkName, |
25 | | - nameBase, |
26 | | - reify, |
27 | 19 | ) |
28 | 20 | import Raylib.Internal.Web.Native (callRaylibFunction) |
29 | 21 |
|
30 | 22 | #else |
31 | 23 |
|
32 | 24 | import Language.Haskell.TH |
33 | | - ( Con (RecC), |
34 | | - Dec (DataD, ForeignD), |
| 25 | + ( Dec (ForeignD), |
35 | 26 | DecsQ, |
36 | | - Info (TyConI), |
37 | | - Name, |
38 | 27 | TypeQ, |
39 | | - mkName, |
40 | | - nameBase, |
41 | | - reify, Foreign (ImportF), Callconv (CCall), Safety (Safe), |
| 28 | + mkName, Foreign (ImportF), Callconv (CCall), Safety (Safe), |
42 | 29 | ) |
43 | 30 |
|
44 | 31 | #endif |
45 | 32 |
|
46 | | --- | Creates lenses with an underscore before field names; e.g. @vector2'x@ |
47 | | --- becomes the lens @_vector2'x@ |
48 | | -genLenses :: [Name] -> DecsQ |
49 | | -genLenses names = do |
50 | | - infos <- mapM reify names |
51 | | - concat <$> zipWithM genLensesForType names infos |
52 | | - where |
53 | | - genLensesForType name (TyConI (DataD _ _ _ _ [RecC _ ctors] _)) = |
54 | | - makeLensesFor mapping name |
55 | | - where |
56 | | - mapping = map (\(a, _, _) -> let fName = nameBase a in (fName, '_' : fName)) ctors |
57 | | - genLensesForType _ _ = error "(genLenses) Received a name that does not refer to a valid type!" |
58 | | - |
59 | 33 | -- | Generates native code for the given functions. On non-web platforms, this |
60 | 34 | -- means @foreign import@ statements. On web platforms, this means |
61 | 35 | -- `callRaylibFunction` calls. |
|
0 commit comments