% $Id: TestOutput.txt,v 1.5 2009/01/11 00:34:06 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. 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) = {A, B, C, E} FV(if B then skip else skip end) = {B} 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, Div, Plus, Mult} 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) = {AddToEach, Plus} % 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. 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 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} % 3. Output from the testing of my Desugar function, which works, % but I don't think handles patterns that nest more than 1 level deep. Desugar(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) == AddToEach = proc {$ ArgPat Ls Result} case ArgPat of A#B then case Ls of CasePat|T then case CasePat of X#Y then local Unnest in local Unnest1 in {Plus A X Unnest1} local Unnest2 in {Plus B Y Unnest2} Unnest = Unnest1#Unnest2 end end local Unnest1 in local Unnest2 in Unnest2 = A#B {AddToEach Unnest2 T Unnest1} end Result = Unnest|Unnest1 end end else Result = nil end else Result = nil end else local Unnest in Unnest = noElse {Exception.raise Unnest} end end end 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(X Y) then B = X else D = Y end) == case C of foo(X 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 3|nil F}) == local Unnest in local Unnest1 in Unnest1 = 3 local Unnest2 in Unnest2 = nil Unnest = Unnest1|Unnest2 end end {Map Unnest F} end Desugar({Map 3|nil proc {$ X R} {Browse X} R = X end}) == local Unnest in local Unnest1 in Unnest1 = 3 local Unnest2 in Unnest2 = nil Unnest = Unnest1|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(X Y) = Tree in R = {Plus X Y} end) == InTest = proc {$ Tree R} local X in local Y in Tree = node(X 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(noElse())}) == local Unnest in local Unnest1 in Unnest1 = noElse() Unnest = kernel(Unnest1) end {Exception.raise Unnest} end Desugar(fun {First X#Y} X end) == First = proc {$ ArgPat Result} case ArgPat of X#Y then Result = X else local Unnest in Unnest = noElse {Exception.raise Unnest} end end end Desugar(fun {RevPair X#Y} Y#X end) == RevPair = proc {$ ArgPat Result} case ArgPat of X#Y then Result = Y#X else local Unnest in Unnest = noElse {Exception.raise Unnest} end end end Desugar(fun {RevPair P} case P of X#Y then Y#X else error end end) == RevPair = proc {$ P Result} case P of X#Y then Result = Y#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