From 0a75e19cdae3c9fa329cc8c18f8284419a62432b Mon Sep 17 00:00:00 2001 From: pimjager Date: Fri, 6 May 2016 12:02:07 +0200 Subject: [PATCH] Assignments are now typechecked --- examples/Markus/assignment_to_builtin.spl | 4 ++- examples/test.spl | 20 +++++---------- sem.icl | 30 ++++++----------------- 3 files changed, 16 insertions(+), 38 deletions(-) diff --git a/examples/Markus/assignment_to_builtin.spl b/examples/Markus/assignment_to_builtin.spl index dc53a37..ca36030 100644 --- a/examples/Markus/assignment_to_builtin.spl +++ b/examples/Markus/assignment_to_builtin.spl @@ -9,5 +9,7 @@ f() { // This tries to assign to the built-in function isEmpty. // Adapt this line if your isEmpty is called differently. - isEmpty = blaat; + var isEmpty = blaat; } + +main() {return;} diff --git a/examples/test.spl b/examples/test.spl index b33297c..199cb26 100644 --- a/examples/test.spl +++ b/examples/test.spl @@ -1,15 +1,7 @@ -Bool n = True; - -test(x) :: Int -> Int { - var y = test(x+1); - return y; -} - -f(n) :: Int -> Int{ - var m = n+1; - return n; -} - -test2(x) { - return f(x); +test() { + var x = 5; + var y = 6; + x = x + y; + return y; } +main() {return;} \ No newline at end of file diff --git a/sem.icl b/sem.icl index 082cfe9..68b804d 100644 --- a/sem.icl +++ b/sem.icl @@ -270,10 +270,13 @@ instance infer Stmt where pure (compose s3 $ compose s2 s1, subst s3 wht) AssStmt (VarDef k fs) e = - infer e >>= \(s1, et)-> - applySubst s1 >>| - changeGamma (extend k (Forall [] et)) >>| //todo: fieldselectors - pure (s1, VoidType) + lookup k >>= \expected -> + infer e >>= \(s1, given)-> + lift (unify expected given) >>= \s2-> + let s = compose s2 s1 in + applySubst s >>| + changeGamma (extend k (Forall [] given)) >>| //todo: fieldselectors + pure (s, VoidType) FunStmt f es = undef //what is this? @@ -345,25 +348,6 @@ instance type [a] | type a where applySubst (compose s2 s1) >>| pure (compose s2 s1, [v_:vs_]) -// mapM processGamma dcls// - -////add the infered type in Gamma to AST constructs -//class processGamma a :: a -> Typing a// - -//instance processGamma VarDecl where -// processGamma v=:(VarDecl p _ k e) = -// gamma >>= \g -> case 'Map'.member k g of -// False = undef -// True = instantiate ('Map'.find k g) >>= \t-> -// pure (VarDecl p (Just t) k e)// - -//instance processGamma FunDecl where -// processGamma v=:(FunDecl p k args _ vds stmts) = -// gamma >>= \g -> case 'Map'.member k g of -// False = undef -// True = instantiate ('Map'.find k g) >>= \t-> -// pure (FunDecl p k args (Just t) vds stmts) - introduce :: String -> Typing Type introduce k = fresh >>= \tv -> -- 2.20.1