% $Id: TestOutput.txt,v 1.7 2012/01/11 22:19:10 leavens Exp leavens $ % 1. Examples of free varaible identifier occurrences. % The function FV computes the set of all identifiers that occur free % in the Oz statement that is its argument. % Howeever, the last several examples test programs (with declare). Testing FreeVarIdsTest $Revision: 1.7 $... FV(skip) == {} FV(local A in skip end) == {} FV(A = B) == {A, B} FV(A = 3) == {A} FV(A = 3 B = C) == {A, B, C} FV(A = 3 B = C E = A) == {B, C, E, A} FV(if B then skip else skip end) == {B} FV(if true then R = true else S = false end) == {R, S} FV(if 3 then skip else skip end) == {} FV(if 3 then A = B else skip end) == {A, B} FV(if X then A = B else skip end) == {X, A, B} FV(if X then A = B else D = Z end) == {X, A, B, D, Z} FV(local A in A = B end) == {B} FV(local A in A = 3 end) == {} FV(local A in A = A end) == {} FV(local A in B = C end) == {B, C} FV(case C of ok then skip else skip end) == {C} FV(case C of X then skip else skip end) == {C} FV(case C of X then B = X else skip end) == {C, B} FV(case C of X then B = X else D = 7 end) == {C, B, D} FV(case C of nowXisFree then B = X else D = 7 end) == {C, B, X, D} FV(case C of Q then B = X else Z = Q end) == {C, B, X, Z, Q} FV(case C of foo() then B = X else D = 7 end) == {C, B, X, D} FV(case C of foo(X Y) then B = X else D = Y end) == {C, B, D, Y} FV(case C of foo(f1:X f2:Y) then B = X else D = Y end) == {C, B, D, Y} FV(case C of foo(f1:bar(f2:X f3:Y f4:Z)) then B = X if Z then D = Y else skip end else skip end) == {C, B, D} FV(case C of foo(f1:bar(f2:X f3:Y f4:Q)) then B = X if Z then D = Y else skip end else skip end) == {C, B, Z, D} FV({P}) == {P} FV({Browse 3}) == {Browse} FV({Map Ls F}) == {Map, Ls, F} FV({Map 3|nil F}) == {Map, F} FV({Map 3|nil proc {$ X R} {Browse X} R = X end}) == {Map, Browse} FV({Map 3|nil proc {$ X R} {Browse X} R = Y end}) == {Map, Browse, Y} FV(Three = proc {$ R} R = 3 end) == {Three} FV(fun {Three} 3 end) == {Three} FV(fun {Add X Y} {Plus X Y} end) == {Add, Plus} FV(fun {Add X Y} {Plus X X Z} end) == {Add, Plus, Z} FV(fun {F X} proc {$ F R} R = {F A} end end) == {F, A} FV(InTest = proc {$ Tree R} node(X Y) = Tree in R = {Plus X Y} end) == {InTest, Plus} FV(fun {First X#Y} X end) == {First} FV(fun {RevPair X#Y} Y#X end) == {RevPair} FV(fun {RevPair P} case P of X#Y then Y#X else error end end) == {RevPair} FV(fun {T N} if {Odd N} then {Div {Plus {Mult 3 N} 1} 2} else {Div N 2} end end) == {T, Odd, Plus, Mult, Div} FV(case nil of X#Y|T then T = X#Y else skip) == {} FV(Res = case Ls of X#Y|T then {Plus A X}#{Plus B Y}|{AddToEach A#B T} else nil end end) == {Res, Ls, Plus, AddToEach, A, B} FV(fun {AddToEach A#B Ls} case Ls of X#Y|T then {Plus A X}#{Plus B Y}|{AddToEach A#B T} else nil end end) == {Plus, AddToEach} FV(thread X = Y end) == {X, Y} FV(X = thread Y end) == {X, Y} ['X'] == ['X'] FV(declare X=Y) == {Y} FV(declare A = nil B = Four|A) == {Four} FV(declare A = nil in B = Four|A) == {B, Four} FV(declare fun{Id X} X end) == {} FV(declare fun{Add X Y} {Plus X Y} end) == {Plus} FV(declare local Foo in fun{Foo X Y} {Plus X Y} end fun{Bar A B} {Foo A B} end end) == {Plus} Finished with 0 failures! % 2. Examples of bound varaible identifier occurrences. % The function BV computes the set of all identifiers that occur bound % in the Oz statement that is its argument. % Again the last several examples (with declare) test programs. Testing BoundVarIdsTest $Revision: 1.7 $... BV(skip) == {} BV(local A in skip end) == {} BV(A = B) == {} BV(A = 3) == {} BV(A = 3 B = C) == {} BV(A = 3 B = C E = A) == {} BV(if B then skip else skip end) == {} BV(if true then R = true else S = false end) == {} BV(if 3 then skip else skip end) == {} BV(if 3 then A = B else skip end) == {} BV(if X then A = B else skip end) == {} BV(if X then A = B else D = Z end) == {} BV(local A in A = B end) == {A} BV(local A in A = 3 end) == {A} BV(local A in A = A end) == {A} BV(local A in B = C end) == {} BV(case C of ok then skip else skip end) == {} BV(case C of X then skip else skip end) == {} BV(case C of X then B = X else skip end) == {X} BV(case C of X then B = X else D = 7 end) == {X} BV(case C of nowXisFree then B = X else D = 7 end) == {} BV(case C of Q then B = X else Z = Q end) == {} BV(case C of foo() then B = X else D = 7 end) == {} BV(case C of foo(X Y) then B = X else D = Y end) == {X} BV(case C of foo(f1:X f2:Y) then B = X else D = Y end) == {X} BV(case C of foo(f1:bar(f2:X f3:Y f4:Z)) then B = X if Z then D = Y else skip end else skip end) == {X, Y, Z} BV(case C of foo(f1:bar(f2:X f3:Y f4:Q)) then B = X if Z then D = Y else skip end else skip end) == {X, Y} BV({P}) == {} BV({Browse 3}) == {} BV({Map Ls F}) == {} BV({Map 3|nil F}) == {} BV({Map 3|nil proc {$ X R} {Browse X} R = X end}) == {X, R} BV({Map 3|nil proc {$ X R} {Browse X} R = Y end}) == {X, R} BV(Three = proc {$ R} R = 3 end) == {R} BV(fun {Three} 3 end) == {} BV(fun {Add X Y} {Plus X Y} end) == {X, Y} BV(fun {Add X Y} {Plus X X Z} end) == {X} BV(fun {F X} proc {$ F R} R = {F A} end end) == {F, R} BV(InTest = proc {$ Tree R} node(X Y) = Tree in R = {Plus X Y} end) == {Tree, R, X, Y} BV(fun {First X#Y} X end) == {X} BV(fun {RevPair X#Y} Y#X end) == {X, Y} BV(fun {RevPair P} case P of X#Y then Y#X else error end end) == {P, X, Y} BV(fun {FirstOnly P} case P of Q then X else Q end end) == {P} BV(fun {T N} if {Odd N} then {Div {Plus {Mult 3 N} 1} 2} else {Div N 2} end end) == {N} BV(fun {AddToEach A#B Ls} case Ls of X#Y|T then {Plus A X}#{Plus B Y}|{AddToEach A#B T} else nil end end) == {A, B, Ls, X, Y, T} BV(thread X = proc {$ Z} Z = 3 end end) == {Z} BV(X = thread proc {$ Z} Z = 3 end end) == {Z} BV(declare X = 3) == {X} BV(declare X = 3 Y = X Z = Y) == {X, Y, Z} BV(declare X = 3 Y = X in Z = Y) == {X, Y} BV(declare fun {Id X} X end) == {X, Id} BV(declare fun {Add X Y} {Plus X Y} end {Plus 3 4}) == {X, Y, Add} Finished with 0 failures! % 3. Output from the testing of my Desugar function. Testing DesugarTest $Revision: 1.7 $... Desugar(skip) == skip Desugar(local A in skip end) == local A in skip end Desugar(A = B) == A = B Desugar(A = 3) == A = 3 Desugar(A = 3 B = C) == A = 3 B = C Desugar(A = 3 B = C E = A) == A = 3 B = C E = A Desugar(if B then skip else skip end) == if B then skip else skip end Desugar(if true then skip else skip end) == local Unnest in Unnest = true if Unnest then skip else skip end end Desugar(if true then R = true else S = false end) == local Unnest in Unnest = true if Unnest then R = true else S = false end end Desugar(if X then A = B else skip end) == if X then A = B else skip end Desugar(if X then A = B else D = Z end) == if X then A = B else D = Z end Desugar(local A in A = B end) == local A in A = B end Desugar(case C of X then skip else skip end) == local X in X = C skip end Desugar(case C of ok then skip else skip end) == case C of ok then skip else skip end Desugar(case C of X then B = X else skip end) == local X in X = C B = X end Desugar(case C of X then B = X else D = 7 end) == local X in X = C B = X end Desugar(case C of nowXisFree then B = X else D = 7 end) == case C of nowXisFree then B = X else D = 7 end Desugar(case C of Q then B = X else Z = Q end) == local Q in Q = C B = X end Desugar(case C of foo() then B = X else D = 7 end) == case C of foo() then B = X else D = 7 end Desugar(case C of foo(1:X 2:Y) then B = X else D = Y end) == case C of foo(1:X 2:Y) then B = X else D = Y end Desugar(case C of foo(f1:X f2:Y) then B = X else D = Y end) == case C of foo(f1:X f2:Y) then B = X else D = Y end Desugar(case C of foo(f1:bar(f2:X f3:Y f4:Z)) then B = X if Z then D = Y else skip end else skip end) == case C of foo(f1:CasePat) then case CasePat of bar(f2:X f3:Y f4:Z) then B = X if Z then D = Y else skip end else skip end else skip end Desugar(case C of foo(f1:bar(f2:X f3:Y f4:Q)) then B = X if Z then D = Y else skip end else skip end) == case C of foo(f1:CasePat) then case CasePat of bar(f2:X f3:Y f4:Q) then B = X if Z then D = Y else skip end else skip end else skip end Desugar({P}) == {P} Desugar({Map Ls F}) == {Map Ls F} Desugar({Browse 3}) == local Unnest in Unnest = 3 {Browse Unnest} end Desugar({Map '|'(1:3 2:nil) F}) == local Unnest in local Unnest1 in Unnest1 = 3 local Unnest2 in Unnest2 = nil Unnest = '|'(1:Unnest1 2:Unnest2) end end {Map Unnest F} end Desugar({Map '|'(1:3 2:nil) proc {$ X R} {Browse X} R = X end}) == local Unnest in local Unnest1 in Unnest1 = 3 local Unnest2 in Unnest2 = nil Unnest = '|'(1:Unnest1 2:Unnest2) end end local Unnest1 in Unnest1 = proc {$ X R} {Browse X} R = X end {Map Unnest Unnest1} end end Desugar(Three = proc {$ R} R = 3 end) == Three = proc {$ R} R = 3 end Desugar(fun {Three} 3 end) == Three = proc {$ Result} Result = 3 end Desugar(fun {Add X Y} {Plus X Y} end) == Add = proc {$ X Y Result} {Plus X Y Result} end Desugar(fun {Add X Y} {Plus X X Z} end) == Add = proc {$ X Y Result} {Plus X X Z Result} end Desugar(fun {F X} proc {$ F R} R = {F A} end end) == F = proc {$ X Result} Result = proc {$ F R} {F A R} end end Desugar(InTest = proc {$ Tree R} node(1:X 2:Y) = Tree in R = {Plus X Y} end) == InTest = proc {$ Tree R} local X in local Y in Tree = node(1:X 2:Y) {Plus X Y R} end end end Desugar({Exception.raise noElse}) == local Unnest in Unnest = noElse {Exception.raise Unnest} end Desugar({Exception.raise kernel(1:noElse())}) == local Unnest in local Unnest1 in Unnest1 = noElse() Unnest = kernel(1:Unnest1) end {Exception.raise Unnest} end Desugar(fun {First '#'(1:X 2:Y)} X end) == First = proc {$ ArgPat Result} case ArgPat of '#'(1:X 2:Y) then Result = X else local Unnest in Unnest = noElse {Exception.raise Unnest} end end end Desugar(fun {RevPair '#'(1:X 2:Y)} '#'(1:Y 2:X) end) == RevPair = proc {$ ArgPat Result} case ArgPat of '#'(1:X 2:Y) then Result = '#'(1:Y 2:X) else local Unnest in Unnest = noElse {Exception.raise Unnest} end end end Desugar(fun {RevPair P} case P of '#'(1:X 2:Y) then '#'(1:Y 2:X) else error end end) == RevPair = proc {$ P Result} case P of '#'(1:X 2:Y) then Result = '#'(1:Y 2:X) else Result = error end end Desugar(fun {T N} if {Odd N} then {Div {Plus {Mult 3 N} 1} 2} else {Div N 2} end end) == T = proc {$ N Result} local Unnest in {Odd N Unnest} if Unnest then local Unnest1 in local Unnest2 in local Unnest3 in Unnest3 = 3 {Mult Unnest3 N Unnest2} end local Unnest3 in Unnest3 = 1 {Plus Unnest2 Unnest3 Unnest1} end end local Unnest2 in Unnest2 = 2 {Div Unnest1 Unnest2 Result} end end else local Unnest1 in Unnest1 = 2 {Div N Unnest1 Result} end end end end Desugar(fun {AddToEach '#'(1:A 2:B) Ls} case Ls of '|'(1:'#'(1:X 2:Y) 2:T) then '|'(1:'#'(1:{Plus A X} 2:{Plus B Y}) 2:{AddToEach '#'(1:A 2:B) T}) else nil end end) == AddToEach = proc {$ ArgPat Ls Result} case ArgPat of '#'(1:A 2:B) then case Ls of '|'(1:CasePat 2:T) then case CasePat of '#'(1:X 2:Y) then local Unnest in local Unnest1 in {Plus A X Unnest1} local Unnest2 in {Plus B Y Unnest2} Unnest = '#'(1:Unnest1 2:Unnest2) end end local Unnest1 in local Unnest2 in Unnest2 = '#'(1:A 2:B) {AddToEach Unnest2 T Unnest1} end Result = '|'(1:Unnest 2:Unnest1) end end else Result = nil end else Result = nil end else local Unnest in Unnest = noElse {Exception.raise Unnest} end end end Desugar(thread skip end) == thread skip end Desugar(thread X = 3 in {P X} end) == thread local Unnest in Unnest = 3 local X in Unnest = X {P X} end end end Desugar(X = thread 7 end) == thread X = 7 end Desugar({P thread 7 end}) == local Unnest in thread Unnest = 7 end {P Unnest} end Finished with 0 failures!