diff --git a/src/TYPE1/code b/src/TYPE1/code index 4cf2fc4..ace6631 100644 --- a/src/TYPE1/code +++ b/src/TYPE1/code @@ -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"); } @@ -223,7 +223,7 @@ ProcExp public Type evalType(TypeEnv tenv) { return proc.evalType(tenv); - } + } public String toString() { return " ...ProcExp... "; @@ -432,12 +432,22 @@ LetDecls Iterator 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... "; } @@ -508,7 +518,7 @@ TypeExps return paramTypeList; } %%% - + PrimType %%% public abstract Type toType(); diff --git a/src/TYPE1/tests/letrec/expected b/src/TYPE1/tests/letrec/expected new file mode 100644 index 0000000..f32a580 --- /dev/null +++ b/src/TYPE1/tests/letrec/expected @@ -0,0 +1 @@ +true \ No newline at end of file diff --git a/src/TYPE1/tests/letrec/input b/src/TYPE1/tests/letrec/input new file mode 100644 index 0000000..d191b8c --- /dev/null +++ b/src/TYPE1/tests/letrec/input @@ -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) diff --git a/src/TYPE1/tests/letrec/test.bats b/src/TYPE1/tests/letrec/test.bats new file mode 100644 index 0000000..89629a3 --- /dev/null +++ b/src/TYPE1/tests/letrec/test.bats @@ -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" ]] + + +}