From: Mart Lubbers Date: Wed, 13 Apr 2016 18:06:57 +0000 (+0200) Subject: update' X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=0e3e968f772d6befb4dbe05f864caae4af84ea62;p=cc1516.git update' --- diff --git a/examples/test.spl b/examples/test.spl new file mode 100644 index 0000000..e6a7f05 --- /dev/null +++ b/examples/test.spl @@ -0,0 +1,6 @@ +Bool n = True; + +f(n) :: Int -> Int{ + var m = n+1; + return n; +} 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