on master help sign in
cosmetic: switch to modern indentation
b551630Evan Czaplicki
src/AST/Module.hs+67−33
@@ -24,20 +24,38 @@ import qualified Elm.Compiler.Version as Compiler
24import qualified Reporting.Annotation as A
24import qualified Reporting.Annotation as A
25
25
26
26
27+
27-- HELPFUL TYPE ALIASES
28-- HELPFUL TYPE ALIASES
28
29
29−type Interfaces = Map.Map Name.Canonical Interface
30
30
31+type Interfaces =
32+ Map.Map Name.Canonical Interface
33+
34+
35+type Types =
31−type Types = Map.Map String Type.Canonical
36+ Map.Map String Type.Canonical
37+
38+
39+type Aliases =
32−type Aliases = Map.Map String ([String], Type.Canonical)
40+ Map.Map String ([String], Type.Canonical)
41+
42+
43+type ADTs =
33−type ADTs = Map.Map String (AdtInfo String)
44+ Map.Map String (AdtInfo String)
45+
46+
47+type AdtInfo v =
48+ ( [String], [(v, [Type.Canonical])] )
49+
50+
51+type CanonicalAdt =
52+ ( Var.Canonical, AdtInfo Var.Canonical )
34
53
35−type AdtInfo v = ( [String], [(v, [Type.Canonical])] )
36−type CanonicalAdt = (Var.Canonical, AdtInfo Var.Canonical)
37
54
38
55
39-- MODULES
56-- MODULES
40
57
58+
41type SourceModule =
59type SourceModule =
42 Module
60 Module
43 String
61 String
@@ -62,7 +80,8 @@ type Optimized =
62 Module Docs.Centralized [Name.Raw] [Var.Value] (Body [Optimized.Def])
80 Module Docs.Centralized [Name.Raw] [Var.Value] (Body [Optimized.Def])
63
81
64
82
65−data Module docs imports exports body = Module
83+data Module docs imports exports body =
84+ Module
66 { name :: Name.Canonical
85 { name :: Name.Canonical
67 , path :: FilePath
86 , path :: FilePath
68 , docs :: A.Located (Maybe docs)
87 , docs :: A.Located (Maybe docs)
@@ -72,7 +91,8 @@ data Module docs imports exports body = Module
72 }
91 }
73
92
74
93
75−data Body expr = Body
94+data Body expr =
95+ Body
76 { program :: expr
96 { program :: expr
77 , types :: Types
97 , types :: Types
78 , fixities :: [(Decl.Assoc, Int, String)]
98 , fixities :: [(Decl.Assoc, Int, String)]
@@ -82,10 +102,13 @@ data Body expr = Body
82 }
102 }
83
103
84
104
105+
85-- HEADERS
106-- HEADERS
86
107
108+
87{-| Basic info needed to identify modules and determine dependencies. -}
109{-| Basic info needed to identify modules and determine dependencies. -}
88−data Header imports = Header
110+data Header imports =
111+ Header
89 { _name :: Name.Raw
112 { _name :: Name.Raw
90 , _docs :: A.Located (Maybe String)
113 , _docs :: A.Located (Maybe String)
91 , _exports :: Var.Listing (A.Located Var.Value)
114 , _exports :: Var.Listing (A.Located Var.Value)
@@ -93,24 +116,30 @@ data Header imports = Header
93 }
116 }
94
117
95
118
119+
96-- IMPORTs
120-- IMPORTs
97
121
122+
98type UserImport = A.Located (Name.Raw, ImportMethod)
123type UserImport = A.Located (Name.Raw, ImportMethod)
99
124
100
125
101type DefaultImport = (Name.Raw, ImportMethod)
126type DefaultImport = (Name.Raw, ImportMethod)
102
127
103
128
104−data ImportMethod = ImportMethod
129+data ImportMethod =
130+ ImportMethod
105 { alias :: Maybe String
131 { alias :: Maybe String
106 , exposedVars :: !(Var.Listing Var.Value)
132 , exposedVars :: !(Var.Listing Var.Value)
107 }
133 }
108
134
109
135
136+
110-- INTERFACES
137-- INTERFACES
111
138
139+
112{-| Key facts about a module, used when reading info from .elmi files. -}
140{-| Key facts about a module, used when reading info from .elmi files. -}
113−data Interface = Interface
141+data Interface =
142+ Interface
114 { iVersion :: Package.Version
143 { iVersion :: Package.Version
115 , iPackage :: Package.Name
144 , iPackage :: Package.Name
116 , iExports :: [Var.Value]
145 , iExports :: [Var.Value]
@@ -125,29 +154,34 @@ data Interface = Interface
125
154
126toInterface :: Package.Name -> Optimized -> Interface
155toInterface :: Package.Name -> Optimized -> Interface
127toInterface pkgName modul =
156toInterface pkgName modul =
157+ let
158+ body' =
128− let body' = body modul in
159+ body modul
160+ in
129 Interface
161 Interface
130− { iVersion = Compiler.version
162+ { iVersion = Compiler.version
131− , iPackage = pkgName
163+ , iPackage = pkgName
132− , iExports = exports modul
164+ , iExports = exports modul
133− , iTypes = types body'
165+ , iTypes = types body'
134− , iImports = imports modul
166+ , iImports = imports modul
135− , iAdts = datatypes body'
167+ , iAdts = datatypes body'
136− , iAliases = aliases body'
168+ , iAliases = aliases body'
137− , iFixities = fixities body'
169+ , iFixities = fixities body'
138− , iPorts = ports body'
170+ , iPorts = ports body'
139− }
171+ }
140
172
141
173
142instance Binary Interface where
174instance Binary Interface where
175+ get =
143− get = Interface <$> get <*> get <*> get <*> get <*> get <*> get <*> get <*> get <*> get
176+ Interface <$> get <*> get <*> get <*> get <*> get <*> get <*> get <*> get <*> get
177+
144− put modul = do
178+ put modul =
145− put (iVersion modul)
179+ do put (iVersion modul)
146− put (iPackage modul)
180+ put (iPackage modul)
147− put (iExports modul)
181+ put (iExports modul)
148− put (iTypes modul)
182+ put (iTypes modul)
149− put (iImports modul)
183+ put (iImports modul)
150− put (iAdts modul)
184+ put (iAdts modul)
151− put (iAliases modul)
185+ put (iAliases modul)
152− put (iFixities modul)
186+ put (iFixities modul)
153− put (iPorts modul)
187+ put (iPorts modul)