on d57762e help sign in
83 lines 2.4 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)
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, Data, Typeable)
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
43data MetadataModule t v = MetadataModule {
44 names :: [String],
45 path :: FilePath,
46 exports :: [String],
47 imports :: [(String, ImportMethod)],
48 program :: LExpr t v,
49 types :: Map.Map String Type,
50 fixities :: [(Assoc, Int, String)],
51 aliases :: [(String, [String], Type)],
52 datatypes :: [ (String, [String], [(String,[Type])]) ],
53 foreignImports :: [(String, LExpr t v, String, Type)],
54 foreignExports :: [(String, String, Type)]
57type Interfaces = Map.Map String ModuleInterface
58type ADT = (String, [String], [(String,[Type])])
60data ModuleInterface = ModuleInterface {
61 iTypes :: Map.Map String Type,
62 iImports :: [(String, ImportMethod)],
63 iAdts :: [ADT],
64 iAliases :: [(String, [String], Type)],
65 iFixities :: [(Assoc, Int, String)]
66} deriving Show
69instance Binary ModuleInterface where
70 get = ModuleInterface <$> get <*> get <*> get <*> get <*> get
71 put modul = do
72 put (iTypes modul)
73 put (iImports modul)
74 put (iAdts modul)
75 put (iAliases modul)
76 put (iFixities modul)
79instance Binary Assoc where
80 get = do n <- getWord8
81 return $ case n of { 0 -> L ; 1 -> N ; 2 -> R }
83 put assoc = putWord8 $ case assoc of { L -> 0 ; N -> 1 ; R -> 2 }