From: pimjager Date: Wed, 13 Apr 2016 18:55:00 +0000 (+0200) Subject: Checking assignments X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=79bfc0933c6ce1f97930053d7a1090e90dd618f1;p=cc1516.git Checking assignments --- diff --git a/examples/StmtEx.spl b/examples/StmtEx.spl index ef8cb88..192eca1 100644 --- a/examples/StmtEx.spl +++ b/examples/StmtEx.spl @@ -5,6 +5,7 @@ Int a = facR(4); //Int b = test(3); var f = beep(); var n = True; +var l = 1:2:[]; facR(n) :: Int -> Int { test(3); @@ -18,6 +19,10 @@ facR(n) :: Int -> Int { test(e) :: Int -> Bool { var i = 0; + i = 1; + l.tl = 4:[]; + l.tl.hd = 3; + //l= 1:3:[] facR(z); while (e < 3) { return True; diff --git a/sem.icl b/sem.icl index 727fc1e..7af3b20 100644 --- a/sem.icl +++ b/sem.icl @@ -71,7 +71,10 @@ checkStmt t (IfStmt c st se) = unify BoolType c >>| mapM (checkStmt t) st >>= \st1-> mapM (checkStmt t) se >>= \se1-> pure (IfStmt c st1 se1) checkStmt t w=:(WhileStmt c et) = unify BoolType c >>| mapM (checkStmt t) et >>= \et1-> pure w -checkStmt t (AssStmt (VarDef ident fs) e) = undef +checkStmt t a=:(AssStmt (VarDef ident fs) e) = gets (\(st, r)->'Map'.get ident st) + >>= \mt->case mt of + Nothing = liftT $ Left $ UndeclaredVariableError zero ident + Just t = unify t fs >>= \t1 -> unify t1 e >>| pure a checkStmt t r=:(FunStmt (FunCall f es)) = typeFun f es >>| pure r checkStmt VoidType r=:(ReturnStmt Nothing) = pure r checkStmt t r=:(ReturnStmt (Just e)) = unify t e >>| pure r