@@ -1,8 +1,7 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Validate
3module Validate
5− , validate
4+ ( validate
@@ -25,11 +24,11 @@ import qualified Reporting.Result as Result
25-- VALIDATE
24-- VALIDATE
28−type Result warning a =
27+type Result i w a =
29− Result.Result () warning Error.Error a
28+ Result.Result i w Error.Error a
32−validate :: Src.Module [Src.Decl] -> Result w Valid.Module
31+validate :: Src.Module [Src.Decl] -> Result i w Valid.Module
33validate (Src.Module name srcEffects overview exports imports srcDecls) =
32validate (Src.Module name srcEffects overview exports imports srcDecls) =
34 do (Stuff decls unions aliases binops ports docs) <- validateDecls srcDecls
33 do (Stuff decls unions aliases binops ports docs) <- validateDecls srcDecls
35 effects <- validateEffects srcEffects ports
34 effects <- validateEffects srcEffects ports
@@ -51,12 +50,12 @@ data Stuff =
54−validateDecls :: [Src.Decl] -> Result w Stuff
53+validateDecls :: [Src.Decl] -> Result i w Stuff
55validateDecls decls =
54validateDecls decls =
56 vsdHelp decls (Stuff [] [] [] [] [] Map.empty)
55 vsdHelp decls (Stuff [] [] [] [] [] Map.empty)
59−vsdHelp :: [Src.Decl] -> Stuff -> Result w Stuff
58+vsdHelp :: [Src.Decl] -> Stuff -> Result i w Stuff
60vsdHelp decls stuff =
59vsdHelp decls stuff =
61 case decls of
60 case decls of
@@ -96,7 +95,7 @@ vsdHelp decls stuff =
96-- VALIDATE DOCS
95-- VALIDATE DOCS
99−validateDocs :: Text -> [Src.Decl] -> Stuff -> Result w Stuff
98+validateDocs :: Text -> [Src.Decl] -> Stuff -> Result i w Stuff
100validateDocs docs decls stuff =
99validateDocs docs decls stuff =
101 case decls of
100 case decls of
@@ -107,7 +106,7 @@ validateDocs docs decls stuff =
107 vsdHelp decls $ stuff { _docs = Map.insert name docs (_docs stuff) }
106 vsdHelp decls $ stuff { _docs = Map.insert name docs (_docs stuff) }
110−getNameForDocs :: Src.Decl_ -> Result w N.Name
109+getNameForDocs :: Src.Decl_ -> Result i w N.Name
111getNameForDocs decl =
110getNameForDocs decl =
112 case decl of
111 case decl of
113 Src.Union (A.At _ name) _ _ ->
112 Src.Union (A.At _ name) _ _ ->
@@ -136,7 +135,7 @@ getNameForDocs decl =
136-- VALIDATE ANNOTATION
135-- VALIDATE ANNOTATION
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
140validateAnnotation annRegion annotationName tipe decls stuff =
139validateAnnotation annRegion annotationName tipe decls stuff =
141 case decls of
140 case decls of
@@ -162,7 +161,7 @@ validateAnnotation annRegion annotationName tipe decls stuff =
162-- VALIDATE EXPRESSIONS
161-- VALIDATE EXPRESSIONS
165−expression :: Src.Expr -> Result w Valid.Expr
164+expression :: Src.Expr -> Result i w Valid.Expr
166expression (A.At region sourceExpression) =
165expression (A.At region sourceExpression) =
167 A.At region <$>
166 A.At region <$>
168 case sourceExpression of
167 case sourceExpression of
@@ -245,7 +244,7 @@ expression (A.At region sourceExpression) =
245 pure (Valid.Shader uid src gltipe)
244 pure (Valid.Shader uid src gltipe)
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)
249both (a, b) =
248both (a, b) =
250 liftA2 (,) (expression a) (expression b)
249 liftA2 (,) (expression a) (expression b)
@@ -254,7 +253,7 @@ both (a, b) =
254-- VALIDATE DEFINITIONS
253-- VALIDATE DEFINITIONS
257−definitions :: [A.Located Src.Def] -> Result w [Valid.Def]
256+definitions :: [A.Located Src.Def] -> Result i w [Valid.Def]
258definitions sourceDefs =
257definitions sourceDefs =
259 case sourceDefs of
258 case sourceDefs of
@@ -279,16 +278,16 @@ definitions sourceDefs =
279 <*> definitions otherOtherDefs
278 <*> definitions otherOtherDefs
282− Result.throw annRegion (Error.TypeWithoutDefinition annotationName)
281+ Result.throw (Error.TypeWithoutDefinition annRegion annotationName)
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
286validateDefinition region name args expr maybeType =
285validateDefinition region name args expr maybeType =
287 do validExpr <- expression expr
286 do validExpr <- expression expr
288 return $ Valid.Define region name args validExpr maybeType
287 return $ Valid.Define region name args validExpr maybeType
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
292validateDestruct region pattern expr =
291validateDestruct region pattern expr =
293 Valid.Destruct region pattern <$> expression expr
292 Valid.Destruct region pattern <$> expression expr
@@ -297,7 +296,7 @@ validateDestruct region pattern expr =
297-- VALIDATE EFFECTS
296-- VALIDATE EFFECTS
300−validateEffects :: Src.Effects -> [Valid.Port] -> Result w Valid.Effects
299+validateEffects :: Src.Effects -> [Valid.Port] -> Result i w Valid.Effects
301validateEffects effects ports =
300validateEffects effects ports =
302 case effects of
301 case effects of
303 Src.NoEffects ->
302 Src.NoEffects ->
@@ -321,7 +320,7 @@ validateEffects effects ports =
321 Valid.Fx cmd sub
320 Valid.Fx cmd sub
324−noPorts :: [Valid.Port] -> Result w ()
323+noPorts :: [Valid.Port] -> Result i w ()
325noPorts ports =
324noPorts ports =
326 forM_ ports $ \(Valid.Port (A.At region name) _) ->
325 forM_ ports $ \(Valid.Port (A.At region name) _) ->
327− Result.throw region (Error.UnexpectedPort name)
326+ Result.throw (Error.UnexpectedPort region name)