X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=sem.icl;h=7af3b20316a292d89e8e4205ff760d862808fd62;hb=79bfc0933c6ce1f97930053d7a1090e90dd618f1;hp=727fc1e1aea1a6eb3c81269aed4e4aca27139401;hpb=0e3e968f772d6befb4dbe05f864caae4af84ea62;p=cc1516.git 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