on master help sign in
Rename `Foreign` to `Port` across the codebase
72da9daEvan Czaplicki
src/AST/Declaration.hs+1−1
@@ -28,7 +28,7 @@ data Raw
28 | Union (Union Type.Raw)
28 | Union (Union Type.Raw)
29 | Alias (Alias Type.Raw)
29 | Alias (Alias Type.Raw)
30 | Fixity Infix
30 | Fixity Infix
31− | Foreign String Type.Raw
31+ | Port String Type.Raw
32
32
33
33
34
34
src/AST/Effects.hs+10−10
@@ -10,18 +10,18 @@ import qualified Reporting.Region as R
10-- EFFECTS
10-- EFFECTS
11
11
12
12
13−data Effects pkg foreigns
13+data Effects pkg ports
14 = None
14 = None
15 | Manager pkg Info
15 | Manager pkg Info
16− | Foreign foreigns
16+ | Port ports
17
17
18
18
19type Raw =
19type Raw =
20− Effects () [A.Commented ForeignRaw]
20+ Effects () [A.Commented PortRaw]
21
21
22
22
23type Canonical =
23type Canonical =
24− Effects Pkg.Name [A.Commented ForeignCanonical]
24+ Effects Pkg.Name [A.Commented PortCanonical]
25
25
26
26
27
27
@@ -48,15 +48,15 @@ data ManagerType
48-- FOREIGN EFFECTS
48-- FOREIGN EFFECTS
49
49
50
50
51−data ForeignRaw =
51+data PortRaw =
52− ForeignRaw
52+ PortRaw
53 { _rawName :: String
53 { _rawName :: String
54 , _rawType :: Type.Raw
54 , _rawType :: Type.Raw
55 }
55 }
56
56
57
57
58−data ForeignCanonical =
58+data PortCanonical =
59− ForeignCanonical
59+ PortCanonical
60 { _name :: String
60 { _name :: String
61 , _kind :: Kind
61 , _kind :: Kind
62 , _type :: Type.Canonical
62 , _type :: Type.Canonical
@@ -64,5 +64,5 @@ data ForeignCanonical =
64
64
65
65
66data Kind
66data Kind
67− = Cmd Type.Canonical
67+ = Outgoing Type.Canonical
68− | Sub Type.Canonical
68+ | Incoming Type.Canonical
src/AST/Expression/General.hs+2−2
@@ -57,8 +57,8 @@ data Expr' ann def var typ
57 -- for type checking and code gen only
57 -- for type checking and code gen only
58 | Cmd ModuleName.Canonical
58 | Cmd ModuleName.Canonical
59 | Sub ModuleName.Canonical
59 | Sub ModuleName.Canonical
60− | ForeignCmd String typ
60+ | OutgoingPort String typ
61− | ForeignSub String typ
61+ | IncomingPort String typ
62 | Program (Main typ) (Expr ann def var typ)
62 | Program (Main typ) (Expr ann def var typ)
63 | SaveEnv ModuleName.Canonical Effects.Canonical
63 | SaveEnv ModuleName.Canonical Effects.Canonical
64 | GLShader String String Literal.GLShaderTipe
64 | GLShader String String Literal.GLShaderTipe
src/AST/Expression/Optimized.hs+2−2
@@ -54,8 +54,8 @@ data Expr
54 | Record [(String, Expr)]
54 | Record [(String, Expr)]
55 | Cmd ModuleName.Canonical
55 | Cmd ModuleName.Canonical
56 | Sub ModuleName.Canonical
56 | Sub ModuleName.Canonical
57− | ForeignCmd String Type.Canonical
57+ | OutgoingPort String Type.Canonical
58− | ForeignSub String Type.Canonical
58+ | IncomingPort String Type.Canonical
59 | Program (Expr.Main Type.Canonical) Expr
59 | Program (Expr.Main Type.Canonical) Expr
60 | GLShader String String Literal.GLShaderTipe
60 | GLShader String String Literal.GLShaderTipe
61 | Crash ModuleName.Canonical R.Region (Maybe Expr)
61 | Crash ModuleName.Canonical R.Region (Maybe Expr)
src/AST/Module.hs+1−1
@@ -78,7 +78,7 @@ data SourceInfo =
78data SourceTag
78data SourceTag
79 = Normal
79 = Normal
80 | Effect R.Region
80 | Effect R.Region
81− | Foreign R.Region
81+ | Port R.Region
82
82
83
83
84type SourceSettings =
84type SourceSettings =
src/Canonicalize.hs+4−4
@@ -440,11 +440,11 @@ canonicalizeExpr env (A.A region validExpr) =
440 Sub moduleName ->
440 Sub moduleName ->
441 Result.ok (Sub moduleName)
441 Result.ok (Sub moduleName)
442
442
443− ForeignCmd name tipe ->
443+ OutgoingPort name tipe ->
444− ForeignCmd name <$> Canon.tipe env tipe
444+ OutgoingPort name <$> Canon.tipe env tipe
445
445
446− ForeignSub name tipe ->
446+ IncomingPort name tipe ->
447− ForeignSub name <$> Canon.tipe env tipe
447+ IncomingPort name <$> Canon.tipe env tipe
448
448
449 Program _ _ ->
449 Program _ _ ->
450 error "DANGER - Program AST nodes should not be in canonicalization."
450 error "DANGER - Program AST nodes should not be in canonicalization."
src/Canonicalize/Body.hs+11−11
@@ -120,8 +120,8 @@ effectsToDefs moduleName effects =
120 Effects.None ->
120 Effects.None ->
121 []
121 []
122
122
123− Effects.Foreign foreigns ->
123+ Effects.Port ports ->
124− map foreignToDef foreigns
124+ map portToDef ports
125
125
126 Effects.Manager _ info ->
126 Effects.Manager _ info ->
127 let
127 let
@@ -154,17 +154,17 @@ effectsToDefs moduleName effects =
154 ]
154 ]
155
155
156
156
157−foreignToDef :: A.Commented Effects.ForeignCanonical -> Canonical.Def
157+portToDef :: A.Commented Effects.PortCanonical -> Canonical.Def
158−foreignToDef (A.A (region, _) (Effects.ForeignCanonical name kind tipe)) =
158+portToDef (A.A (region, _) (Effects.PortCanonical name kind tipe)) =
159− definition name (A.A region (toForeignExpr name kind)) region tipe
159+ definition name (A.A region (toPortExpr name kind)) region tipe
160
160
161
161
162−toForeignExpr :: String -> Effects.Kind -> Canonical.Expr'
162+toPortExpr :: String -> Effects.Kind -> Canonical.Expr'
163−toForeignExpr name kind =
163+toPortExpr name kind =
164 case kind of
164 case kind of
165− Effects.Cmd tipe ->
165+ Effects.Outgoing tipe ->
166− E.ForeignCmd name tipe
166+ E.OutgoingPort name tipe
167
167
168− Effects.Sub tipe ->
168+ Effects.Incoming tipe ->
169− E.ForeignSub name tipe
169+ E.IncomingPort name tipe
170
170
src/Canonicalize/Effects.hs+20−20
@@ -1,4 +1,4 @@
1−module Canonicalize.Effects (canonicalize, toValues, checkForeignType) where
1+module Canonicalize.Effects (canonicalize, toValues, checkPortType) where
2
2
3import qualified Data.Foldable as F
3import qualified Data.Foldable as F
4import qualified Data.Traversable as T
4import qualified Data.Traversable as T
@@ -28,8 +28,8 @@ toValues effects =
28 Effects.Manager _ _ ->
28 Effects.Manager _ _ ->
29 []
29 []
30
30
31− Effects.Foreign foreigns ->
31+ Effects.Port ports ->
32− map (Var.Value . Effects._rawName . A.drop) foreigns
32+ map (Var.Value . Effects._rawName . A.drop) ports
33
33
34
34
35
35
@@ -45,18 +45,18 @@ canonicalize env effects =
45 Effects.Manager _ info ->
45 Effects.Manager _ info ->
46 Result.ok (Effects.Manager (Env.getPackage env) info)
46 Result.ok (Effects.Manager (Env.getPackage env) info)
47
47
48− Effects.Foreign rawForeigns ->
48+ Effects.Port rawPorts ->
49− Effects.Foreign <$> T.traverse (canonicalizeRawForeign env) rawForeigns
49+ Effects.Port <$> T.traverse (canonicalizeRawPort env) rawPorts
50
50
51
51
52−canonicalizeRawForeign
52+canonicalizeRawPort
53 :: Env.Environment
53 :: Env.Environment
54− -> A.Commented Effects.ForeignRaw
54+ -> A.Commented Effects.PortRaw
55− -> Result (A.Commented Effects.ForeignCanonical)
55+ -> Result (A.Commented Effects.PortCanonical)
56−canonicalizeRawForeign env (A.A ann (Effects.ForeignRaw name rawType)) =
56+canonicalizeRawPort env (A.A ann (Effects.PortRaw name rawType)) =
57 do tipe <- Canonicalize.tipe env rawType
57 do tipe <- Canonicalize.tipe env rawType
58 kind <- figureOutKind (fst ann) name tipe
58 kind <- figureOutKind (fst ann) name tipe
59− Result.ok (A.A ann (Effects.ForeignCanonical name kind tipe))
59+ Result.ok (A.A ann (Effects.PortCanonical name kind tipe))
60
60
61
61
62figureOutKind :: R.Region -> String -> T.Canonical -> Result Effects.Kind
62figureOutKind :: R.Region -> String -> T.Canonical -> Result Effects.Kind
@@ -64,36 +64,36 @@ figureOutKind region name rootType =
64 case T.deepDealias rootType of
64 case T.deepDealias rootType of
65 T.Lambda outgoingType (T.App (T.Type effect) [T.Var _])
65 T.Lambda outgoingType (T.App (T.Type effect) [T.Var _])
66 | effect == Var.cmd ->
66 | effect == Var.cmd ->
67− pure (Effects.Cmd outgoingType)
67+ pure (Effects.Outgoing outgoingType)
68− <* checkForeignType (makeError region name "command") outgoingType
68+ <* checkPortType (makeError region name) outgoingType
69
69
70 T.Lambda (T.Lambda incomingType (T.Var msg1)) (T.App (T.Type effect) [T.Var msg2])
70 T.Lambda (T.Lambda incomingType (T.Var msg1)) (T.App (T.Type effect) [T.Var msg2])
71 | effect == Var.sub && msg1 == msg2 ->
71 | effect == Var.sub && msg1 == msg2 ->
72− pure (Effects.Sub incomingType)
72+ pure (Effects.Incoming incomingType)
73− <* checkForeignType (makeError region name "subscription") incomingType
73+ <* checkPortType (makeError region name) incomingType
74
74
75 _ ->
75 _ ->
76 Result.throw region (error "TODO - bad overall type")
76 Result.throw region (error "TODO - bad overall type")
77
77
78
78
79−makeError :: R.Region -> String -> String -> T.Canonical -> Maybe String -> A.Located Error.Error
79+makeError :: R.Region -> String -> T.Canonical -> Maybe String -> A.Located Error.Error
80−makeError region name kind tipe maybeMessage =
80+makeError region name tipe maybeMessage =
81− A.A region (Error.foreign name kind tipe maybeMessage)
81+ A.A region (Error.port name tipe maybeMessage)
82
82
83
83
84
84
85-- CHECK INCOMING AND OUTGOING TYPES
85-- CHECK INCOMING AND OUTGOING TYPES
86
86
87
87
88−checkForeignType
88+checkPortType
89 :: (Monoid i)
89 :: (Monoid i)
90 => (T.Canonical -> Maybe String -> A.Located e)
90 => (T.Canonical -> Maybe String -> A.Located e)
91 -> T.Canonical
91 -> T.Canonical
92 -> Result.Result i w e ()
92 -> Result.Result i w e ()
93−checkForeignType makeError tipe =
93+checkPortType makeError tipe =
94 let
94 let
95 check =
95 check =
96− checkForeignType makeError
96+ checkPortType makeError
97
97
98 throw maybeMsg =
98 throw maybeMsg =
99 Result.throwMany [makeError tipe maybeMsg]
99 Result.throwMany [makeError tipe maybeMsg]
src/Canonicalize/Setup.hs+3−3
@@ -368,12 +368,12 @@ effectsToPatches moduleName effects =
368 Effects.None ->
368 Effects.None ->
369 []
369 []
370
370
371− Effects.Foreign foreigns ->
371+ Effects.Port ports ->
372 let
372 let
373− toPatch (A.A _ (Effects.ForeignRaw name _)) =
373+ toPatch (A.A _ (Effects.PortRaw name _)) =
374 Env.Value name (Var.topLevel moduleName name)
374 Env.Value name (Var.topLevel moduleName name)
375 in
375 in
376− map toPatch foreigns
376+ map toPatch ports
377
377
378 Effects.Manager _ info ->
378 Effects.Manager _ info ->
379 map (\name -> Env.Value name (Var.topLevel moduleName name)) $
379 map (\name -> Env.Value name (Var.topLevel moduleName name)) $
src/Canonicalize/Sort.hs+2−2
@@ -102,10 +102,10 @@ reorder (A.A ann expression) =
102 Sub _ ->
102 Sub _ ->
103 return expression
103 return expression
104
104
105− ForeignCmd _ _ ->
105+ OutgoingPort _ _ ->
106 return expression
106 return expression
107
107
108− ForeignSub _ _ ->
108+ IncomingPort _ _ ->
109 return expression
109 return expression
110
110
111 Program _ _ ->
111 Program _ _ ->
src/Generate/JavaScript.hs+1−1
@@ -42,7 +42,7 @@ generateEffectManager moduleName effects =
42 Effects.None ->
42 Effects.None ->
43 []
43 []
44
44
45− Effects.Foreign _ ->
45+ Effects.Port _ ->
46 []
46 []
47
47
48 Effects.Manager pkgName (Effects.Info _ _ _ _ managerType) ->
48 Effects.Manager pkgName (Effects.Info _ _ _ _ managerType) ->
src/Generate/JavaScript/Expression.hs+2−2
@@ -209,10 +209,10 @@ generateCode expr =
209 Sub moduleName ->
209 Sub moduleName ->
210 jsExpr $ BuiltIn.effect moduleName
210 jsExpr $ BuiltIn.effect moduleName
211
211
212− ForeignCmd name tipe ->
212+ OutgoingPort name tipe ->
213 jsExpr $ BuiltIn.outgoingPort name (Foreign.encode tipe)
213 jsExpr $ BuiltIn.outgoingPort name (Foreign.encode tipe)
214
214
215− ForeignSub name tipe ->
215+ IncomingPort name tipe ->
216 do jsDecoder <- generateJsExpr (Foreign.decode tipe)
216 do jsDecoder <- generateJsExpr (Foreign.decode tipe)
217 jsExpr $ BuiltIn.incomingPort name jsDecoder
217 jsExpr $ BuiltIn.incomingPort name jsDecoder
218
218
src/Nitpick/PatternMatches.hs+2−2
@@ -187,10 +187,10 @@ checkExpression tagDict (A.A region expression) =
187 E.Sub _ ->
187 E.Sub _ ->
188 Result.ok ()
188 Result.ok ()
189
189
190− E.ForeignCmd _ _ ->
190+ E.OutgoingPort _ _ ->
191 Result.ok ()
191 Result.ok ()
192
192
193− E.ForeignSub _ _ ->
193+ E.IncomingPort _ _ ->
194 Result.ok ()
194 Result.ok ()
195
195
196 E.Program _ _ ->
196 E.Program _ _ ->
src/Nitpick/TopLevelTypes.hs+1−1
@@ -95,7 +95,7 @@ checkMain typeEnv (Can.Def facts pattern@(A.A region _) body maybeType) =
95
95
96 | name == program ->
96 | name == program ->
97 return (Expr.Flags arg)
97 return (Expr.Flags arg)
98− <* Effects.checkForeignType makeError arg
98+ <* Effects.checkPortType makeError arg
99
99
100 _ ->
100 _ ->
101 Result.throw region (Error.BadMain mainType)
101 Result.throw region (Error.BadMain mainType)
src/Optimize.hs+4−4
@@ -288,11 +288,11 @@ optimizeExpr context annExpr@(A.A region expression) =
288 Expr.Sub moduleName ->
288 Expr.Sub moduleName ->
289 pure (Opt.Sub moduleName)
289 pure (Opt.Sub moduleName)
290
290
291− Expr.ForeignCmd name tipe ->
291+ Expr.OutgoingPort name tipe ->
292− pure (Opt.ForeignCmd name tipe)
292+ pure (Opt.OutgoingPort name tipe)
293
293
294− Expr.ForeignSub name tipe ->
294+ Expr.IncomingPort name tipe ->
295− pure (Opt.ForeignSub name tipe)
295+ pure (Opt.IncomingPort name tipe)
296
296
297 Expr.Program kind expr ->
297 Expr.Program kind expr ->
298 Opt.Program kind <$> justConvert expr
298 Opt.Program kind <$> justConvert expr
src/Optimize/Inline.hs+4−4
@@ -175,10 +175,10 @@ count expression =
175 Sub _ ->
175 Sub _ ->
176 Map.empty
176 Map.empty
177
177
178− ForeignCmd _ _ ->
178+ OutgoingPort _ _ ->
179 Map.empty
179 Map.empty
180
180
181− ForeignSub _ _ ->
181+ IncomingPort _ _ ->
182 Map.empty
182 Map.empty
183
183
184 Program _ expr ->
184 Program _ expr ->
@@ -289,10 +289,10 @@ replace substitutions expression =
289 Sub _ ->
289 Sub _ ->
290 expression
290 expression
291
291
292− ForeignCmd _ _ ->
292+ OutgoingPort _ _ ->
293 expression
293 expression
294
294
295− ForeignSub _ _ ->
295+ IncomingPort _ _ ->
296 expression
296 expression
297
297
298 Program kind expr ->
298 Program kind expr ->
src/Parse/Declaration.hs+1−1
@@ -95,5 +95,5 @@ portDecl =
95 name <- Help.lowVar
95 name <- Help.lowVar
96 padded hasType
96 padded hasType
97 tipe <- Type.expr
97 tipe <- Type.expr
98− return $ Decl.Foreign name tipe
98+ return $ Decl.Port name tipe
99
99
src/Parse/Module.hs+1−1
@@ -100,7 +100,7 @@ parseTag =
100 whitespace
100 whitespace
101 reserved "module"
101 reserved "module"
102 end <- getMyPosition
102 end <- getMyPosition
103− return (Module.Foreign (R.Region start end))
103+ return (Module.Port (R.Region start end))
104 ]
104 ]
105
105
106
106
src/Reporting/Error/Canonicalize.hs+13−15
@@ -22,7 +22,7 @@ data Error
22 | Import ModuleName.Raw ImportError
22 | Import ModuleName.Raw ImportError
23 | Export String [String]
23 | Export String [String]
24 | DuplicateExport String
24 | DuplicateExport String
25− | Foreign ForeignError
25+ | Port PortError
26
26
27
27
28
28
@@ -100,18 +100,17 @@ alias name expected actual =
100-- PORTS
100-- PORTS
101
101
102
102
103−data ForeignError =
103+data PortError =
104− ForeignError
104+ PortError
105− { foreignName :: String
105+ { portName :: String
106− , foreignKind :: String
107− , foreignType :: Type.Canonical
106+ , portType :: Type.Canonical
108− , foreignMessage :: Maybe String
107+ , portMessage :: Maybe String
109 }
108 }
110
109
111
110
112−foreign :: String -> String -> Type.Canonical -> Maybe String -> Error
111+port :: String -> Type.Canonical -> Maybe String -> Error
113−foreign name kind tipe maybeMessage =
112+port name tipe maybeMessage =
114− Foreign (ForeignError name kind tipe maybeMessage)
113+ Port (PortError name tipe maybeMessage)
115
114
116
115
117
116
@@ -222,16 +221,15 @@ toReport localizer err =
222 ("You are trying to export `" ++ name ++ "` multiple times!")
221 ("You are trying to export `" ++ name ++ "` multiple times!")
223 "Remove duplicates until there is only one listed."
222 "Remove duplicates until there is only one listed."
224
223
225− Foreign (ForeignError name kind tipe maybeMessage) ->
224+ Port (PortError name tipe maybeMessage) ->
226 let
225 let
227 context =
226 context =
228 maybe "" (" the following " ++ ) maybeMessage
227 maybe "" (" the following " ++ ) maybeMessage
229 in
228 in
230 Report.report
229 Report.report
231− "FOREIGN ERROR"
230+ "PORT ERROR"
232 Nothing
231 Nothing
233− ("Only certain types can flow in and out of Elm. The `"
234− ++ name ++ "` " ++ kind ++ " is trying to communicate an unsupported type."
232+ ("Port `" ++ name ++ "` is trying to communicate an unsupported type."
235 )
233 )
236 ( Help.stack
234 ( Help.stack
237 [ text ("The specific unsupported type is" ++ context ++ ":")
235 [ text ("The specific unsupported type is" ++ context ++ ":")
@@ -287,7 +285,7 @@ extractSuggestions err =
287 DuplicateExport _ ->
285 DuplicateExport _ ->
288 Nothing
286 Nothing
289
287
290− Foreign _ ->
288+ Port _ ->
291 Nothing
289 Nothing
292
290
293
291
src/Reporting/Error/Syntax.hs+12−12
@@ -19,12 +19,12 @@ data Error
19 | CommentOnNothing
19 | CommentOnNothing
20
20
21 | SettingsOnNormalModule
21 | SettingsOnNormalModule
22− | SettingsOnForeignModule
22+ | SettingsOnPortModule
23 | DuplicateSettingOnEffectModule String
23 | DuplicateSettingOnEffectModule String
24 | BadSettingOnEffectModule String
24 | BadSettingOnEffectModule String
25 | NoSettingsOnEffectModule
25 | NoSettingsOnEffectModule
26 | MissingManagerOnEffectModule String
26 | MissingManagerOnEffectModule String
27− | UnexpectedForeign String
27+ | UnexpectedPort String
28
28
29 | InfixDuplicate String
29 | InfixDuplicate String
30 | TypeWithoutDefinition String
30 | TypeWithoutDefinition String
@@ -96,14 +96,14 @@ toReport _localizer err =
96 \ the right direction!"
96 \ the right direction!"
97 )
97 )
98
98
99− SettingsOnForeignModule ->
99+ SettingsOnPortModule ->
100 Report.report
100 Report.report
101 "BAD MODULE DECLARATION"
101 "BAD MODULE DECLARATION"
102 Nothing
102 Nothing
103− "A foreign effect module can expose values, but not have settings like this."
103+ "A port module can expose values, but not have settings like this."
104 ( Help.reflowParagraph $
104 ( Help.reflowParagraph $
105− "If you want a foreign effect module, just remove this stuff. If you want\
105+ "If you want a port module, just remove this stuff. If you want to create\
106− \ to create an `effect module` instead, just change `foreign effect module`\
106+ \ a custom effect module instead (which is rare) just change `port module`\
107 \ to `effect module` and you should be headed in the right direction!"
107 \ to `effect module` and you should be headed in the right direction!"
108 )
108 )
109
109
@@ -150,15 +150,15 @@ toReport _localizer err =
150 \ <TODO> (please forgive me if I forgot to fill this in!)"
150 \ <TODO> (please forgive me if I forgot to fill this in!)"
151 )
151 )
152
152
153− UnexpectedForeign name ->
153+ UnexpectedPort name ->
154 Report.report
154 Report.report
155− "BAD FOREIGN"
155+ "BAD PORT"
156 Nothing
156 Nothing
157− ("You are declaring foreign effect " ++ Help.functionName name ++ " in a normal module.")
157+ ("You are declaring port " ++ Help.functionName name ++ " in a normal module.")
158 ( Help.reflowParagraph $
158 ( Help.reflowParagraph $
159− "All foreign effects must be defined in a `foreign effect module`. You should\
159+ "All ports must be defined in a `port module`. You should probably have just\
160− \ probably have just one of these for your project. This way all of your foreign\
160+ \ one of these for your project. This way all of your foreign interactions\
161− \ interactions stay relatively organized."
161+ \ stay relatively organized."
162 )
162 )
163
163
164 InfixDuplicate opName ->
164 InfixDuplicate opName ->
src/Type/Constrain/Effects.hs+1−1
@@ -24,7 +24,7 @@ constrain env moduleName effects =
24 Effects.None ->
24 Effects.None ->
25 return CSaveEnv
25 return CSaveEnv
26
26
27− Effects.Foreign _ ->
27+ Effects.Port _ ->
28 return CSaveEnv
28 return CSaveEnv
29
29
30 Effects.Manager _ info ->
30 Effects.Manager _ info ->
src/Type/Constrain/Expression.hs+2−2
@@ -43,10 +43,10 @@ constrain env annotatedExpr@(A.A region expression) tipe =
43 E.Sub _ ->
43 E.Sub _ ->
44 return CTrue
44 return CTrue
45
45
46− E.ForeignCmd _ _ ->
46+ E.OutgoingPort _ _ ->
47 return CTrue
47 return CTrue
48
48
49− E.ForeignSub _ _ ->
49+ E.IncomingPort _ _ ->
50 return CTrue
50 return CTrue
51
51
52 E.Program _ _ ->
52 E.Program _ _ ->
src/Validate.hs+41−41
@@ -45,9 +45,9 @@ module' (Module.Module name path info) =
45 (Module.Source tag settings docs exports imports decls) =
45 (Module.Source tag settings docs exports imports decls) =
46 info
46 info
47 in
47 in
48− do (ValidStuff foreigns structure) <- validateDecls decls
48+ do (ValidStuff ports structure) <- validateDecls decls
49
49
50− validEffects <- validateEffects tag settings foreigns (D._defs structure)
50+ validEffects <- validateEffects tag settings ports (D._defs structure)
51
51
52 return $ Module.Module name path $
52 return $ Module.Module name path $
53 Module.Valid docs exports (addDefaults pkgName imports) structure validEffects
53 Module.Valid docs exports (addDefaults pkgName imports) structure validEffects
@@ -77,19 +77,19 @@ addDefaults pkgName imports =
77validateEffects
77validateEffects
78 :: Module.SourceTag
78 :: Module.SourceTag
79 -> Module.SourceSettings
79 -> Module.SourceSettings
80− -> [A.Commented Effects.ForeignRaw]
80+ -> [A.Commented Effects.PortRaw]
81 -> [A.Commented Valid.Def]
81 -> [A.Commented Valid.Def]
82 -> Result wrn Effects.Raw
82 -> Result wrn Effects.Raw
83−validateEffects tag settings@(A.A _ pairs) foreigns validDefs =
83+validateEffects tag settings@(A.A _ pairs) ports validDefs =
84 case tag of
84 case tag of
85 Module.Normal ->
85 Module.Normal ->
86 do noSettings Error.SettingsOnNormalModule settings
86 do noSettings Error.SettingsOnNormalModule settings
87− noForeigns foreigns
87+ noPorts ports
88 return Effects.None
88 return Effects.None
89
89
90− Module.Foreign _ ->
90+ Module.Port _ ->
91− do noSettings Error.SettingsOnForeignModule settings
91+ do noSettings Error.SettingsOnPortModule settings
92− return (Effects.Foreign foreigns)
92+ return (Effects.Port ports)
93
93
94 Module.Effect tagRegion ->
94 Module.Effect tagRegion ->
95 let
95 let
@@ -99,7 +99,7 @@ validateEffects tag settings@(A.A _ pairs) foreigns validDefs =
99 settingsDict =
99 settingsDict =
100 foldr collectSettings Map.empty pairs
100 foldr collectSettings Map.empty pairs
101 in
101 in
102− do noForeigns foreigns
102+ do noPorts ports
103 managerType <- toManagerType tagRegion settingsDict
103 managerType <- toManagerType tagRegion settingsDict
104 (r0, r1, r2) <- checkManager tagRegion managerType validDefs
104 (r0, r1, r2) <- checkManager tagRegion managerType validDefs
105 return (Effects.Manager () (Effects.Info tagRegion r0 r1 r2 managerType))
105 return (Effects.Manager () (Effects.Info tagRegion r0 r1 r2 managerType))
@@ -115,18 +115,18 @@ noSettings errorMsg (A.A region settings) =
115 Result.throw region errorMsg
115 Result.throw region errorMsg
116
116
117
117
118−noForeigns :: [A.Commented Effects.ForeignRaw] -> Result wrn ()
118+noPorts :: [A.Commented Effects.PortRaw] -> Result wrn ()
119−noForeigns foreigns =
119+noPorts ports =
120− case foreigns of
120+ case ports of
121 [] ->
121 [] ->
122 Result.ok ()
122 Result.ok ()
123
123
124 _ : _ ->
124 _ : _ ->
125 let
125 let
126− toError (A.A (region, _) (Effects.ForeignRaw name _)) =
126+ toError (A.A (region, _) (Effects.PortRaw name _)) =
127− A.A region (Error.UnexpectedForeign name)
127+ A.A region (Error.UnexpectedPort name)
128 in
128 in
129− Result.throwMany (map toError foreigns)
129+ Result.throwMany (map toError ports)
130
130
131
131
132toManagerType
132toManagerType
@@ -302,7 +302,7 @@ validateDecls sourceDecls =
302
302
303data ValidStuff =
303data ValidStuff =
304 ValidStuff
304 ValidStuff
305− { _foreigns :: [A.Commented Effects.ForeignRaw]
305+ { _ports :: [A.Commented Effects.PortRaw]
306 , _structure :: D.Valid
306 , _structure :: D.Valid
307 }
307 }
308
308
@@ -314,48 +314,48 @@ validateRawDecls commentedDecls =
314
314
315vrdHelp
315vrdHelp
316 :: [A.Commented D.Raw]
316 :: [A.Commented D.Raw]
317− -> [A.Commented Effects.ForeignRaw]
317+ -> [A.Commented Effects.PortRaw]
318 -> D.Valid
318 -> D.Valid
319 -> Result wrn ValidStuff
319 -> Result wrn ValidStuff
320−vrdHelp commentedDecls foreigns structure =
320+vrdHelp commentedDecls ports structure =
321 case commentedDecls of
321 case commentedDecls of
322 [] ->
322 [] ->
323− Result.ok (ValidStuff foreigns structure)
323+ Result.ok (ValidStuff ports structure)
324
324
325 A.A ann decl : rest ->
325 A.A ann decl : rest ->
326 case decl of
326 case decl of
327 D.Union (D.Type name tvars ctors) ->
327 D.Union (D.Type name tvars ctors) ->
328− vrdHelp rest foreigns (D.addUnion (A.A ann (D.Type name tvars ctors)) structure)
328+ vrdHelp rest ports (D.addUnion (A.A ann (D.Type name tvars ctors)) structure)
329
329
330 D.Alias (D.Type name tvars alias) ->
330 D.Alias (D.Type name tvars alias) ->
331− vrdHelp rest foreigns (D.addAlias (A.A ann (D.Type name tvars alias)) structure)
331+ vrdHelp rest ports (D.addAlias (A.A ann (D.Type name tvars alias)) structure)
332
332
333 D.Fixity fixity ->
333 D.Fixity fixity ->
334− vrdHelp rest foreigns (D.addInfix fixity structure)
334+ vrdHelp rest ports (D.addInfix fixity structure)
335
335
336 D.Def (A.A region def) ->
336 D.Def (A.A region def) ->
337− vrdDefHelp rest (A.A (region, snd ann) def) foreigns structure
337+ vrdDefHelp rest (A.A (region, snd ann) def) ports structure
338
338
339− D.Foreign name tipe ->
339+ D.Port name tipe ->
340− vrdHelp rest (A.A ann (Effects.ForeignRaw name tipe) : foreigns) structure
340+ vrdHelp rest (A.A ann (Effects.PortRaw name tipe) : ports) structure
341
341
342
342
343vrdDefHelp
343vrdDefHelp
344 :: [A.Commented D.Raw]
344 :: [A.Commented D.Raw]
345 -> A.Commented Source.Def'
345 -> A.Commented Source.Def'
346− -> [A.Commented Effects.ForeignRaw]
346+ -> [A.Commented Effects.PortRaw]
347 -> D.Valid
347 -> D.Valid
348 -> Result wrn ValidStuff
348 -> Result wrn ValidStuff
349−vrdDefHelp remainingDecls (A.A ann def) foreigns structure =
349+vrdDefHelp remainingDecls (A.A ann def) ports structure =
350 let
350 let
351− addDef validDef (ValidStuff finalForeigns struct) =
351+ addDef validDef (ValidStuff finalPorts struct) =
352− ValidStuff finalForeigns (D.addDef (A.A ann validDef) struct)
352+ ValidStuff finalPorts (D.addDef (A.A ann validDef) struct)
353 in
353 in
354 case def of
354 case def of
355 Source.Definition pat expr ->
355 Source.Definition pat expr ->
356 addDef
356 addDef
357 <$> validateDef pat expr Nothing
357 <$> validateDef pat expr Nothing
358− <*> vrdHelp remainingDecls foreigns structure
358+ <*> vrdHelp remainingDecls ports structure
359
359
360 Source.Annotation name tipe ->
360 Source.Annotation name tipe ->
361 case remainingDecls of
361 case remainingDecls of
@@ -363,10 +363,10 @@ vrdDefHelp remainingDecls (A.A ann def) foreigns structure =
363 | Pattern.isVar name pat ->
363 | Pattern.isVar name pat ->
364 addDef
364 addDef
365 <$> validateDef pat expr (Just tipe)
365 <$> validateDef pat expr (Just tipe)
366− <*> vrdHelp rest foreigns structure
366+ <*> vrdHelp rest ports structure
367
367
368 _ ->
368 _ ->
369− vrdHelp remainingDecls foreigns structure
369+ vrdHelp remainingDecls ports structure
370 <* Result.throw (fst ann) (Error.TypeWithoutDefinition name)
370 <* Result.throw (fst ann) (Error.TypeWithoutDefinition name)
371
371
372
372
@@ -523,11 +523,11 @@ expression (A.A ann sourceExpression) =
523 Sub moduleName ->
523 Sub moduleName ->
524 return (Sub moduleName)
524 return (Sub moduleName)
525
525
526− ForeignCmd name tipe ->
526+ OutgoingPort name tipe ->
527− return (ForeignCmd name tipe)
527+ return (OutgoingPort name tipe)
528
528
529− ForeignSub name tipe ->
529+ IncomingPort name tipe ->
530− return (ForeignSub name tipe)
530+ return (IncomingPort name tipe)
531
531
532 Program _ _ ->
532 Program _ _ ->
533 error "DANGER - Program AST nodes should not be in validation phase."
533 error "DANGER - Program AST nodes should not be in validation phase."
@@ -564,17 +564,17 @@ validatePattern pattern =
564
564
565
565
566checkDuplicates :: ValidStuff -> Result wrn ()
566checkDuplicates :: ValidStuff -> Result wrn ()
567−checkDuplicates (ValidStuff foreigns (D.Decls defs unions aliases _)) =
567+checkDuplicates (ValidStuff ports (D.Decls defs unions aliases _)) =
568 let
568 let
569 -- SIMPLE NAMES
569 -- SIMPLE NAMES
570
570
571 defValues =
571 defValues =
572 concatMap (Pattern.boundVars . Valid.getPattern . A.drop) defs
572 concatMap (Pattern.boundVars . Valid.getPattern . A.drop) defs
573
573
574− foreignValues =
574+ portValues =
575− map fromForeign foreigns
575+ map fromPort ports
576
576
577− fromForeign (A.A (region, _) (Effects.ForeignRaw name _)) =
577+ fromPort (A.A (region, _) (Effects.PortRaw name _)) =
578 A.A region name
578 A.A region name
579
579
580 -- TYPE NAMES
580 -- TYPE NAMES
@@ -597,7 +597,7 @@ checkDuplicates (ValidStuff foreigns (D.Decls defs unions aliases _)) =
597 []
597 []
598 in
598 in
599 F.sequenceA_
599 F.sequenceA_
600− [ detectDuplicates Error.DuplicateValueDeclaration (foreignValues ++ defValues)
600+ [ detectDuplicates Error.DuplicateValueDeclaration (portValues ++ defValues)
601 , detectDuplicates Error.DuplicateValueDeclaration (concat typeValues)
601 , detectDuplicates Error.DuplicateValueDeclaration (concat typeValues)
602 , detectDuplicates Error.DuplicateTypeDeclaration types
602 , detectDuplicates Error.DuplicateTypeDeclaration types
603 ]
603 ]