repositories
/
cc1516.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
0e3e968
)
Checking assignments
author
pimjager
<pim@pimjager.nl>
Wed, 13 Apr 2016 18:55:00 +0000
(20:55 +0200)
committer
pimjager
<pim@pimjager.nl>
Wed, 13 Apr 2016 18:55:00 +0000
(20:55 +0200)
examples/StmtEx.spl
patch
|
blob
|
history
sem.icl
patch
|
blob
|
history
diff --git
a/examples/StmtEx.spl
b/examples/StmtEx.spl
index
ef8cb88
..
192eca1
100644
(file)
--- 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;
//Int b = test(3);
var f = beep();
var n = True;
+var l = 1:2:[];
facR(n) :: Int -> Int {
test(3);
facR(n) :: Int -> Int {
test(3);
@@
-18,6
+19,10
@@
facR(n) :: Int -> Int {
test(e) :: Int -> Bool {
var i = 0;
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;
facR(z);
while (e < 3) {
return True;
diff --git
a/sem.icl
b/sem.icl
index
727fc1e
..
7af3b20
100644
(file)
--- 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
>>= \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
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