X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=sem.icl;h=eb626f6adba979a0f05dfd9f19769b48cd5cf45b;hb=7172bb2d04590a4e2609ca0047cb45d7a2613c7d;hp=727fc1e1aea1a6eb3c81269aed4e4aca27139401;hpb=0e3e968f772d6befb4dbe05f864caae4af84ea62;p=cc1516.git diff --git a/sem.icl b/sem.icl index 727fc1e..eb626f6 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 @@ -102,7 +105,6 @@ typeExpr (VarExpr p (VarDef ident fs)) = gets (\(st, r)->'Map'.get ident st) >>= \mt->case mt of Nothing = liftT $ Left $ UndeclaredVariableError p ident Just t = unify t fs - typeOp2 :: Expr Expr Op2 [Type] Type -> Env Type typeOp2 e1 e2 op ts ret = typeExpr e1 >>= \t1-> typeExpr e2 >>= \t2-> unify t1 t2 >>= \t3->if (isMember t3 ts) (pure ret)