@@ -1,8 +1,7 @@
11{-# OPTIONS_GHC -Wall #-}
22{-# LANGUAGE OverloadedStrings #-}
33module Validate
4− ( Result
5− , validate
4+ ( validate
65 )
76 where
87
@@ -25,11 +24,11 @@ import qualified Reporting.Result as Result
2524-- VALIDATE
2625
2726
28−type Result warning a =
29− Result.Result () warning Error.Error a
27+type Result i w a =
28+ Result.Result i w Error.Error a
3029
3130
32−validate :: Src.Module [Src.Decl] -> Result w Valid.Module
31+validate :: Src.Module [Src.Decl] -> Result i w Valid.Module
3332validate (Src.Module name srcEffects overview exports imports srcDecls) =
3433 do (Stuff decls unions aliases binops ports docs) <- validateDecls srcDecls
3534 effects <- validateEffects srcEffects ports
@@ -51,12 +50,12 @@ data Stuff =
5150 }
5251
5352
54−validateDecls :: [Src.Decl] -> Result w Stuff
53+validateDecls :: [Src.Decl] -> Result i w Stuff
5554validateDecls decls =
5655 vsdHelp decls (Stuff [] [] [] [] [] Map.empty)
5756
5857
59−vsdHelp :: [Src.Decl] -> Stuff -> Result w Stuff
58+vsdHelp :: [Src.Decl] -> Stuff -> Result i w Stuff
6059vsdHelp decls stuff =
6160 case decls of
6261 [] ->
@@ -96,7 +95,7 @@ vsdHelp decls stuff =
9695-- VALIDATE DOCS
9796
9897
99−validateDocs :: Text -> [Src.Decl] -> Stuff -> Result w Stuff
98+validateDocs :: Text -> [Src.Decl] -> Stuff -> Result i w Stuff
10099validateDocs docs decls stuff =
101100 case decls of
102101 [] ->
@@ -107,7 +106,7 @@ validateDocs docs decls stuff =
107106 vsdHelp decls $ stuff { _docs = Map.insert name docs (_docs stuff) }
108107
109108
110−getNameForDocs :: Src.Decl_ -> Result w N.Name
109+getNameForDocs :: Src.Decl_ -> Result i w N.Name
111110getNameForDocs decl =
112111 case decl of
113112 Src.Union (A.At _ name) _ _ ->
@@ -136,7 +135,7 @@ getNameForDocs decl =
136135-- VALIDATE ANNOTATION
137136
138137
139−validateAnnotation :: R.Region -> N.Name -> Src.Type -> [Src.Decl] -> Stuff -> Result w Stuff
138+validateAnnotation :: R.Region -> N.Name -> Src.Type -> [Src.Decl] -> Stuff -> Result i w Stuff
140139validateAnnotation annRegion annotationName tipe decls stuff =
141140 case decls of
142141 [] ->
@@ -162,7 +161,7 @@ validateAnnotation annRegion annotationName tipe decls stuff =
162161-- VALIDATE EXPRESSIONS
163162
164163
165−expression :: Src.Expr -> Result w Valid.Expr
164+expression :: Src.Expr -> Result i w Valid.Expr
166165expression (A.At region sourceExpression) =
167166 A.At region <$>
168167 case sourceExpression of
@@ -245,7 +244,7 @@ expression (A.At region sourceExpression) =
245244 pure (Valid.Shader uid src gltipe)
246245
247246
248−both :: (Src.Expr, Src.Expr) -> Result w (Valid.Expr, Valid.Expr)
247+both :: (Src.Expr, Src.Expr) -> Result i w (Valid.Expr, Valid.Expr)
249248both (a, b) =
250249 liftA2 (,) (expression a) (expression b)
251250
@@ -254,7 +253,7 @@ both (a, b) =
254253-- VALIDATE DEFINITIONS
255254
256255
257−definitions :: [A.Located Src.Def] -> Result w [Valid.Def]
256+definitions :: [A.Located Src.Def] -> Result i w [Valid.Def]
258257definitions sourceDefs =
259258 case sourceDefs of
260259 [] ->
@@ -279,16 +278,16 @@ definitions sourceDefs =
279278 <*> definitions otherOtherDefs
280279
281280 _ ->
282− Result.throw annRegion (Error.TypeWithoutDefinition annotationName)
281+ Result.throw (Error.TypeWithoutDefinition annRegion annotationName)
283282
284283
285−validateDefinition :: R.Region -> A.Located Text -> [Src.Pattern] -> Src.Expr -> Maybe Src.Type -> Result w Valid.Def
284+validateDefinition :: R.Region -> A.Located Text -> [Src.Pattern] -> Src.Expr -> Maybe Src.Type -> Result i w Valid.Def
286285validateDefinition region name args expr maybeType =
287286 do validExpr <- expression expr
288287 return $ Valid.Define region name args validExpr maybeType
289288
290289
291−validateDestruct :: R.Region -> Src.Pattern -> Src.Expr -> Result w Valid.Def
290+validateDestruct :: R.Region -> Src.Pattern -> Src.Expr -> Result i w Valid.Def
292291validateDestruct region pattern expr =
293292 Valid.Destruct region pattern <$> expression expr
294293
@@ -297,7 +296,7 @@ validateDestruct region pattern expr =
297296-- VALIDATE EFFECTS
298297
299298
300−validateEffects :: Src.Effects -> [Valid.Port] -> Result w Valid.Effects
299+validateEffects :: Src.Effects -> [Valid.Port] -> Result i w Valid.Effects
301300validateEffects effects ports =
302301 case effects of
303302 Src.NoEffects ->
@@ -321,7 +320,7 @@ validateEffects effects ports =
321320 Valid.Fx cmd sub
322321
323322
324−noPorts :: [Valid.Port] -> Result w ()
323+noPorts :: [Valid.Port] -> Result i w ()
325324noPorts ports =
326325 forM_ ports $ \(Valid.Port (A.At region name) _) ->
327− Result.throw region (Error.UnexpectedPort name)
326+ Result.throw (Error.UnexpectedPort region name)