on cc5be70 help sign in
93 lines 2.8 kB history raw
1{-# LANGUAGE DeriveDataTypeable #-}
2module SourceSyntax.Module where
4import Data.Data
5import Data.Binary
6import Data.List (intercalate)
7import qualified Data.Map as Map
8import Control.Applicative ((<$>), (<*>))
9import Control.Arrow (second)
11import SourceSyntax.Expression (LExpr)
12import SourceSyntax.Declaration
13import SourceSyntax.Type
14import System.FilePath (joinPath)
15import Control.Monad (liftM)
17import Paths_Elm (version)
18import Data.Version (showVersion)
20data Module tipe var =
21 Module [String] Exports Imports [Declaration tipe var]
22 deriving (Show)
24type Exports = [String]
26type Imports = [(String, ImportMethod)]
27data ImportMethod = As String | Importing [String] | Hiding [String]
28 deriving (Eq, Ord, Show, Data, Typeable)
30instance Binary ImportMethod where
31 put (As s) = do put (0 :: Word8)
32 put s
34 put (Importing ss) = do put (1 :: Word8)
35 put ss
37 put (Hiding ss) = do put (2 :: Word8)
38 put ss
40 get = do tag <- getWord8
41 case tag of
42 0 -> liftM As get
43 1 -> liftM Importing get
44 2 -> liftM Hiding get
45 _ -> error "Error reading valid ImportMethod type from serialized string"
47data MetadataModule t v = MetadataModule {
48 names :: [String],
49 path :: FilePath,
50 exports :: [String],
51 imports :: [(String, ImportMethod)],
52 program :: LExpr t v,
53 types :: Map.Map String Type,
54 fixities :: [(Assoc, Int, String)],
55 aliases :: [(String, [String], Type)],
56 datatypes :: [ (String, [String], [(String,[Type])]) ],
57 foreignImports :: [(String, LExpr t v, String, Type)],
58 foreignExports :: [(String, String, Type)]
59} deriving Show
61type Interfaces = Map.Map String ModuleInterface
62type ADT = (String, [String], [(String,[Type])])
64data ModuleInterface = ModuleInterface {
65 iVersion :: String,
66 iTypes :: Map.Map String Type,
67 iImports :: [(String, ImportMethod)],
68 iAdts :: [ADT],
69 iAliases :: [(String, [String], Type)],
70 iFixities :: [(Assoc, Int, String)]
71} deriving Show
74instance Binary ModuleInterface where
75 get = ModuleInterface <$> get <*> get <*> get <*> get <*> get <*> get
76 put modul = do
77 put (iVersion modul)
78 put (iTypes modul)
79 put (iImports modul)
80 put (iAdts modul)
81 put (iAliases modul)
82 put (iFixities modul)
85instance Binary Assoc where
86 get = do n <- getWord8
87 return $ case n of
88 0 -> L
89 1 -> N
90 2 -> R
91 _ -> error "Error reading valid associativity from serialized string"
93 put assoc = putWord8 $ case assoc of { L -> 0 ; N -> 1 ; R -> 2 }