git.haldean.org del / 30e5126 src / Language / Del / Properties.hs
30e5126

Tree @30e5126 (Download .tar.gz)

Properties.hs @30e5126raw · history · blame

module Language.Del.Properties (checkRoot, checkRootType, checkRecursive) where

import qualified Data.Map.Strict as Map
import           Language.Del.AST
import           Language.Del.AstUtils
import           Language.Del.CompileDefs
import           Language.Del.TypeTable

-- Make sure that a root function is defined
checkRoot :: AST -> Artifact AST
checkRoot a@(AST m _) =
    if Map.member rootKey m
       then return a
       else Failure MissingRootError

-- Make sure the root function returns a color
checkRootType :: AST -> Artifact AST
checkRootType a@(AST m _) =
    let (Def _ ret _ _) = m Map.! rootKey in
    case ret of
         ColorType -> return a
         _ -> Failure (BadRootType ret)

-- Ensure that there are no recursive methods in the workspace
checkRecursive :: AST -> Artifact AST
checkRecursive a@(AST m _) = check (Map.elems m)
    where check l = case l of
            (Def n _ _ e):xs -> if containsName n e
                                      then Failure (RecursionError n)
                                      else check xs
            [] -> return a