on 0486c90 help sign in
100 lines 3.0 kB history raw
1module SourceSyntax.Module where
3import Data.Binary
4import Data.List (intercalate)
5import qualified Data.Map as Map
6import Control.Applicative ((<$>), (<*>))
7import Control.Arrow (second)
9import SourceSyntax.Expression (LExpr)
10import SourceSyntax.Declaration
11import SourceSyntax.Type
12import System.FilePath (joinPath)
13import Control.Monad (liftM)
15import qualified Elm.Internal.Version as Version
17data Module tipe var =
18 Module [String] Exports Imports [Declaration tipe var]
19 deriving (Show)
21type Exports = [String]
23type Imports = [(String, ImportMethod)]
24data ImportMethod = As String | Importing [String] | Hiding [String]
25 deriving (Eq, Ord, Show)
27instance Binary ImportMethod where
28 put (As s) = do put (0 :: Word8)
29 put s
31 put (Importing ss) = do put (1 :: Word8)
32 put ss
34 put (Hiding ss) = do put (2 :: Word8)
35 put ss
37 get = do tag <- getWord8
38 case tag of
39 0 -> liftM As get
40 1 -> liftM Importing get
41 2 -> liftM Hiding get
42 _ -> error "Error reading valid ImportMethod type from serialized string"
44data MetadataModule t v = MetadataModule {
45 names :: [String],
46 path :: FilePath,
47 exports :: [String],
48 imports :: [(String, ImportMethod)],
49 program :: LExpr t v,
50 types :: Map.Map String Type,
51 fixities :: [(Assoc, Int, String)],
52 aliases :: [Alias],
53 datatypes :: [ADT],
54 foreignImports :: [(String, LExpr t v, String, Type)],
55 foreignExports :: [(String, String, Type)]
56} deriving Show
58type Interfaces = Map.Map String ModuleInterface
59type ADT = (String, [String], [(String,[Type])], [Derivation])
60type Alias = (String, [String], Type, [Derivation])
62data ModuleInterface = ModuleInterface {
63 iVersion :: Version.Version,
64 iTypes :: Map.Map String Type,
65 iImports :: [(String, ImportMethod)],
66 iAdts :: [ADT],
67 iAliases :: [Alias],
68 iFixities :: [(Assoc, Int, String)]
69} deriving Show
71metaToInterface metaModule =
72 ModuleInterface
73 { iVersion = Version.elmVersion
74 , iTypes = types metaModule
75 , iImports = imports metaModule
76 , iAdts = datatypes metaModule
77 , iAliases = aliases metaModule
78 , iFixities = fixities metaModule
79 }
81instance Binary ModuleInterface where
82 get = ModuleInterface <$> get <*> get <*> get <*> get <*> get <*> get
83 put modul = do
84 put (iVersion modul)
85 put (iTypes modul)
86 put (iImports modul)
87 put (iAdts modul)
88 put (iAliases modul)
89 put (iFixities modul)
92instance Binary Assoc where
93 get = do n <- getWord8
94 return $ case n of
95 0 -> L
96 1 -> N
97 2 -> R
98 _ -> error "Error reading valid associativity from serialized string"
100 put assoc = putWord8 $ case assoc of { L -> 0 ; N -> 1 ; R -> 2 }