summaryrefslogtreecommitdiff
path: root/Generate.hs
diff options
context:
space:
mode:
authorCsaba Hruska <csaba.hruska@gmail.com>2015-12-21 13:48:22 +0100
committerCsaba Hruska <csaba.hruska@gmail.com>2015-12-21 13:48:22 +0100
commitbefc5afb22b36d744c403d103d591c5d190d394f (patch)
tree05e390bef55b0662a9a919b886322b66b113ff21 /Generate.hs
parentdc8e31235fccbe5ea54d94b0ca69e005ca88c7ea (diff)
add lambdacube-ir haskell lib
Diffstat (limited to 'Generate.hs')
-rw-r--r--Generate.hs72
1 files changed, 0 insertions, 72 deletions
diff --git a/Generate.hs b/Generate.hs
deleted file mode 100644
index 5f5c0d0..0000000
--- a/Generate.hs
+++ /dev/null
@@ -1,72 +0,0 @@
1{-# LANGUAGE OverloadedStrings, FlexibleInstances #-}
2import qualified Data.Text.Lazy as LText
3import Text.EDE
4import Text.EDE.Filters
5
6import Data.HashMap.Strict (HashMap)
7import qualified Data.HashMap.Strict as HashMap
8import Data.Text (Text)
9import qualified Data.Map as Map
10
11import Data.Time.Clock
12import Control.Monad.Writer
13
14import Definitions
15import Language
16
17instance Unquote [Field]
18instance Unquote [Char]
19instance Quote [Char]
20instance Unquote DataDef
21instance Unquote Type
22
23main :: IO ()
24main = do
25 dataSwift <- eitherParseFile "templates/data.swift.ede"
26 dataJava <- eitherParseFile "templates/data.java.ede"
27 dataHpp <- eitherParseFile "templates/data.hpp.ede"
28 dataHpp2 <- eitherParseFile "templates/data.hpp2.ede"
29 dataCpp <- eitherParseFile "templates/data.cpp.ede"
30 dataCs <- eitherParseFile "templates/data.cs.ede"
31 dataHs <- eitherParseFile "templates/data.hs.ede"
32 dataPs <- eitherParseFile "templates/data.purs.ede"
33 let generate (ModuleDef name imports def) = do
34 dt <- getCurrentTime
35 let env = fromPairs
36 [ "dataAndType" .= def
37 , "definitions" .= [a | a@DataDef{} <- def ]
38 , "moduleName" .= name
39 , "dateTime" .= dt
40 , "imports" .= imports
41 ]
42 aliasMap = Map.fromList [(n,t) | TypeAlias n t <- def]
43 mylib :: HashMap Text Term
44 mylib = HashMap.fromList
45 [ "hasFieldNames" @: hasFieldNames
46 , "parens" @: parens
47 , "constType" @: constType
48 , "hsType" @: hsType aliasMap
49 , "psType" @: psType aliasMap
50 , "cppType" @: cppType aliasMap
51 , "csType" @: csType aliasMap
52 , "javaType" @: javaType aliasMap
53 , "swiftType" @: swiftType aliasMap
54 ]
55
56 -- Haskell
57 either error (\x -> writeFile ("out/" ++ name ++ ".hs") $ LText.unpack x) $ dataHs >>= (\t -> eitherRenderWith mylib t env)
58 -- Purescript
59 either error (\x -> writeFile ("out/" ++ name ++ ".purs") $ LText.unpack x) $ dataPs >>= (\t -> eitherRenderWith mylib t env)
60 -- C++
61 either error (\x -> writeFile ("out/" ++ name ++ "2.hpp") $ LText.unpack x) $ dataHpp2 >>= (\t -> eitherRenderWith mylib t env)
62 either error (\x -> writeFile ("out/" ++ name ++ ".hpp") $ LText.unpack x) $ dataHpp >>= (\t -> eitherRenderWith mylib t env)
63 either error (\x -> writeFile ("out/" ++ name ++ ".cpp") $ LText.unpack x) $ dataCpp >>= (\t -> eitherRenderWith mylib t env)
64 {-
65 -- Java
66 either error (\x -> writeFile ("out/" ++ name ++ ".java") $ LText.unpack x) $ dataJava >>= (\t -> eitherRenderWith mylib t env)
67 -- C#
68 either error (\x -> writeFile ("out/" ++ name ++ ".cs") $ LText.unpack x) $ dataCs >>= (\t -> eitherRenderWith mylib t env)
69 -}
70 -- Swift
71 either error (\x -> writeFile ("out/" ++ name ++ ".swift") $ LText.unpack x) $ dataSwift >>= (\t -> eitherRenderWith mylib t env)
72 mapM_ generate $ execWriter modules