Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/TYPE1/code
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Define
env.add(new Binding(sym, new ValRef(rhsExpVal)));
System.out.println(sym + ":" + rhsExpType);
return;
}
}
// the variable has a value, too -- can't redefine it!
throw new PLCCException(sym + ": duplicate variable definition");
}
Expand Down Expand Up @@ -223,7 +223,7 @@ ProcExp

public Type evalType(TypeEnv tenv) {
return proc.evalType(tenv);
}
}

public String toString() {
return " ...ProcExp... ";
Expand Down Expand Up @@ -432,12 +432,22 @@ LetDecls
Iterator<Exp> expIter = expList.iterator();
while (varIter.hasNext()) {
String str = varIter.next().toString();
Type typ = expIter.next().evalType(tenv);
Exp e = expIter.next();
Type typ = null;
if (e instanceof ProcExp) {
typ = ((ProcExp) e).proc.definedType();
} else {
typ = e.evalType(tenv);
}
tenv.add(new TypeBinding(str, typ));
}
expIter = expList.iterator();
while (varIter.hasNext()) {
Type typ = expIter.next().evalType(tenv);
}
return tenv;
}

public String toString() {
return " ...LetDecls... ";
}
Expand Down Expand Up @@ -508,7 +518,7 @@ TypeExps
return paramTypeList;
}
%%%

PrimType
%%%
public abstract Type toType();
Expand Down
1 change: 1 addition & 0 deletions src/TYPE1/tests/letrec/expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true
5 changes: 5 additions & 0 deletions src/TYPE1/tests/letrec/input
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
letrec
odd? = proc(t:int):bool if zero?(t) then false else .even?(sub1(t))
even? = proc(t:int):bool if zero?(t) then true else .odd?(sub1(t))
in
.odd?(1)
14 changes: 14 additions & 0 deletions src/TYPE1/tests/letrec/test.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/usr/bin/env bats

load '../../../../bin/relocate.bash'

@test "TYPE1 letrec" {
relocate
plccmk -c grammar > /dev/null
RESULT="$(rep -n < ./tests/letrec/input)"

expected_output=$(< "./tests/letrec/expected")
[[ "$RESULT" == "$expected_output" ]]


}