From: pimjager Date: Fri, 20 May 2016 14:55:50 +0000 (+0200) Subject: blabla X-Git-Url: https://git.martlubbers.net/?a=commitdiff_plain;h=5e99736dffcbeace758f9a7bda5a51f44d34f032;p=cc1516.git blabla --- diff --git a/examples/codeGen.spl b/examples/codeGen.spl index 77b02a1..1f76056 100644 --- a/examples/codeGen.spl +++ b/examples/codeGen.spl @@ -38,7 +38,8 @@ main() { var x = (True, 5) : (False,0) : []; var sdaf = isE(x1); var z = isEmpty(x1); - Char c = read(); + //char c = read(); x.hd.snd = 8; + isE(x1, 8); return; } diff --git a/sem.icl b/sem.icl index 0c5b552..29b89af 100644 --- a/sem.icl +++ b/sem.icl @@ -292,7 +292,17 @@ instance infer Stmt where changeGamma (extend k (Forall [] (subst s varType))) >>| pure (s, VoidType) - FunStmt f es _ = pure (zero, VoidType) + FunStmt f es _ = pure (zero, VoidType) //Fix for print & check number of args + FunStmt f args fs = + lookup f >>= \expected -> + let accST = (\(s,ts) e->infer e >>= \(s_,et)->pure (compose s_ s,ts++[et])) in + foldM accST (zero,[]) args >>= \(s1, argTs)-> + fresh >>= \tv-> + let given = foldr (->>) tv argTs in + lift (unify expected given) >>= \s2-> + let fReturnType = subst s2 tv in + foldM foldFieldSelectors fReturnType fs >>= \_ -> + pure (compose s2 s1, VoidType) ReturnStmt Nothing = pure (zero, VoidType) ReturnStmt (Just e) = infer e @@ -347,7 +357,6 @@ instance type FunDecl where infer stmts >>= \(s2, result)-> applySubst s1 >>| let argTs_ = map (subst $ compose s2 s1) argTs in - //abort (concat $ intersperse "\n" $ map toString argTs_) >>| let given = foldr (->>) result argTs_ in (case expected of Nothing = pure zero