on f0b38ae help sign in
63 lines 1.9 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)
16data Module tipe var =
17 Module [String] Exports Imports [Declaration tipe var]
18 deriving (Show)
20type Exports = [String]
22type Imports = [(String, ImportMethod)]
23data ImportMethod = As String | Importing [String] | Hiding [String]
24 deriving (Eq, Ord, Show, Data, Typeable)
26data MetadataModule t v = MetadataModule {
27 names :: [String],
28 path :: FilePath,
29 exports :: [String],
30 imports :: [(String, ImportMethod)],
31 program :: LExpr t v,
32 types :: Map.Map String Type,
33 fixities :: [(Assoc, Int, String)],
34 aliases :: [(String, [String], Type)],
35 datatypes :: [ (String, [String], [(String,[Type])]) ],
36 foreignImports :: [(String, LExpr t v, String, Type)],
37 foreignExports :: [(String, String, Type)]
40type Interfaces = Map.Map String ModuleInterface
41type ADT = (String, [String], [(String,[Type])])
43data ModuleInterface = ModuleInterface {
44 iTypes :: Map.Map String Type,
45 iAdts :: [ADT],
46 iAliases :: [(String, [String], Type)],
47 iFixities :: [(Assoc, Int, String)]
48} deriving Show
50instance Binary ModuleInterface where
51 get = ModuleInterface <$> get <*> get <*> get <*> get
52 put modul = do
53 put (iTypes modul)
54 put (iAdts modul)
55 put (iAliases modul)
56 put (iFixities modul)
59instance Binary Assoc where
60 get = do n <- getWord8
61 return $ case n of { 0 -> L ; 1 -> N ; 2 -> R }
63 put assoc = putWord8 $ case assoc of { L -> 0 ; N -> 1 ; R -> 2 }