X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=sem.icl;h=727fc1e1aea1a6eb3c81269aed4e4aca27139401;hb=0e3e968f772d6befb4dbe05f864caae4af84ea62;hp=603d53abfffa1a07b9637d5b0b222d0c6969633e;hpb=da76566f1640467256a8f4e166ebfcd3731aef4b;p=cc1516.git diff --git a/sem.icl b/sem.icl index 603d53a..727fc1e 100644 --- a/sem.icl +++ b/sem.icl @@ -3,6 +3,7 @@ implementation module sem import qualified Data.Map as Map from Data.Func import $ import Data.Maybe +import Data.Void import Data.Either import Data.Functor import Control.Applicative @@ -49,10 +50,17 @@ semFunDecl fd=:(FunDecl p f args mt vds stmts) = (case mt of Nothing = let t = IdType f in putIdent f t >>| pure t Just t = putIdent f t >>| pure t) >>= \ft -> - mapM_ (\a-> freshIdent >>= \fr-> putIdent a (IdType fr)) args >>| - mapM_ semVarDecl vds >>| + matchFunctions args ft >>| + mapM semVarDecl vds >>= \newvds-> mapM_ (checkStmt $ resultType ft) stmts >>| - restoreGamma gamma >>| pure fd + restoreGamma gamma >>| + pure (FunDecl p f args mt newvds stmts) + +matchFunctions :: [String] Type -> Env Void +matchFunctions [] (_ ->> _) = liftT $ Left $ Error "Niet genoeg argumentenerror" +matchFunctions [] t = pure Void +matchFunctions [x:xs] (t1 ->> t2) = + modify (\(st, r)->('Map'.put x t1 st, r)) >>| matchFunctions xs t2 semVarDecl :: VarDecl -> Env VarDecl semVarDecl (VarDecl pos type ident ex) = unify type ex @@ -238,4 +246,4 @@ saveGamma :: Env Gamma saveGamma = get restoreGamma :: Gamma -> Env Void -restoreGamma g = put g \ No newline at end of file +restoreGamma g = put g