% $Id: ReducerTest.oz,v 1.22 2012/01/17 11:50:53 leavens Exp leavens $ % Tests for the Reducer % AUTHOR: Gary T. Leavens \insert 'ReducerPrinting.oz' \insert 'TestingNoStop.oz' %% from the course library {StartTesting 'ReducerTest $Revision: 1.22 $'} %%% Initial tests declare Env0 = {InitEnv} Store0 = {EmptyStore} {TestRed {MakeConfig skipStmt Env0 Store0} 'skip' {SingleThreadConfig runnable(nil) Store0}} {TestRed {MakeConfig seqStmt(skipStmt|skipStmt|nil) Env0 Store0} 'sequence' {SingleThreadConfig runnable(skipStmt#Env0|skipStmt#Env0|nil) Store0}} {TestRed {SingleThreadConfig runnable(localStmt(varId('X') unifyStmt(varId('X') intLit(3)))#Env0|nil) Store0} 'local' local Loc#Store2 = {AllocStore Store0} in {SingleThreadConfig runnable(unifyStmt(varId('X') intLit(3))#{ExtendEnv Env0 'X' Loc}|nil) Store2} end} %% Below records what I did to debug a failure in the above, %% which ended up localizing it to EqualStore, allowing me to debug that... %% % local % RN#C = {Reduce1 {SingleThreadConfig localStmt(varId('X') unifyStmt(varId('X') intLit(3)))#Env0|nil Store0}} % (S#E)|_ = {StackOfConfig C} % Loc#Store2 = {AllocStore Store0} % in % {Test {EqualStore {StoreOfConfig C} Store2} '==' true} % {Test {EqualEnv E {ExtendEnv Env0 'X' Loc}} '==' true} % end {TestRed {SingleThreadConfig runnable(localStmt(varId('X') ifStmt(varId('X') skipStmt skipStmt))#Env0|nil) Store0} 'local' local Loc#Store2 = {AllocStore Store0} in {SingleThreadConfig runnable(ifStmt(varId('X') skipStmt skipStmt)#{ExtendEnv Env0 'X' Loc}|nil) Store2} end} local Loc#Store2 = {AllocStore Store0} in {TestRed {SingleThreadConfig runnable(ifStmt(varId('X') skipStmt skipStmt)#{ExtendEnv Env0 'X' Loc}|nil) Store2} 'if-suspend' {SingleThreadConfig suspended(ifStmt(varId('X') skipStmt skipStmt)#{ExtendEnv Env0 'X' Loc}|nil Loc) Store2} } end local Loc#Store2 = {AllocStore Store0} in {TestRed {SingleThreadConfig runnable(caseStmt(varId('X') varIdPat('_') skipStmt skipStmt)#{ExtendEnv Env0 'X' Loc}|nil) Store2} 'case-suspend' {SingleThreadConfig suspended(caseStmt(varId('X') varIdPat('_') skipStmt skipStmt)#{ExtendEnv Env0 'X' Loc}|nil Loc) Store2} } end local Loc#Store2 = {AllocStore Store0} in {TestRed {SingleThreadConfig runnable(applyStmt(varId('X') nil) #{ExtendEnv Env0 'X' Loc}|nil) Store2} 'application-suspend' {SingleThreadConfig suspended(applyStmt(varId('X') nil) #{ExtendEnv Env0 'X' Loc}|nil Loc) Store2} } end % % Another debugging statement... % local Loc#Store2 = {AllocStore Store0} % C = {SingleThreadConfig % suspended(caseStmt(varId('X') varIdPat('_') skipStmt skipStmt)#{ExtendEnv Env0 'X' Loc}|nil Loc) % Store2} % in % {StartTesting 'starting compare'} % {Test {EqualConfig C C} '==' true} % {PrintConfig C} % local RN#C2 = {Reduce1 {SingleThreadConfig % runnable(caseStmt(varId('X') varIdPat('_') skipStmt skipStmt)#{ExtendEnv Env0 'X' Loc}|nil) % Store2}} % (S#E)|_ = {StackOfThread {SelectedThreadOfConfig C2}} % STO = {StoreOfConfig C2} % in % {PrintConfig C2} % {Test {EqualStore STO Store2} '==' true} % % {Browse {ThreadsOfConfig C2}} % % {Browse {ThreadsOfConfig C}} % {Test {EqualThreadLists {ThreadsOfConfig C2} {ThreadsOfConfig C}} '==' true} % {Test {EqualEnv E {ExtendEnv Env0 'X' Loc}} '==' true} % {Test {EqualConfig C C2} '==' true} % end % {StartTesting 'compare done'} % end local StdEnv#StdStore = {StdEnvStore} Loc#Store2 = {AllocStore StdStore} in {TestRed {SingleThreadConfig runnable(applyStmt(varId('Number.\'+\'') [varId('X') varId('X') varId('X')])#{ExtendEnv StdEnv 'X' Loc}|nil) Store2} 'apply-primitive-suspend' {SingleThreadConfig suspended(applyStmt(varId('Number.\'+\'') [varId('X') varId('X') varId('X')])#{ExtendEnv StdEnv 'X' Loc}|nil Loc) Store2} } end {TestRed {SingleThreadConfig runnable(localStmt(varId('Y') localStmt(varId('X') seqStmt([unifyStmt(varId('X') varId('Y')) unifyStmt(varId('X') intLit(3))]))) #Env0|nil) Store0} 'local' local LocY#StoreY = {AllocStore Store0} in {SingleThreadConfig runnable(localStmt(varId('X') seqStmt([unifyStmt(varId('X') varId('Y')) unifyStmt(varId('X') intLit(3))])) #{ExtendEnv Env0 'Y' LocY}|nil) StoreY} end } local LocY#StoreY = {AllocStore Store0} in {TestRed {SingleThreadConfig runnable(localStmt(varId('X') seqStmt([unifyStmt(varId('X') varId('Y')) unifyStmt(varId('X') intLit(3))])) #{ExtendEnv Env0 'Y' LocY}|nil) StoreY} 'local' local LocX#StoreX = {AllocStore StoreY} in {SingleThreadConfig runnable(seqStmt([unifyStmt(varId('X') varId('Y')) unifyStmt(varId('X') intLit(3))]) #{ExtendEnv {ExtendEnv Env0 'Y' LocY} 'X' LocX}|nil) StoreX} end } end local LocY#StoreY = {AllocStore Store0} LocX#StoreX = {AllocStore StoreY} EnvXY = {ExtendEnv {ExtendEnv Env0 'Y' LocY} 'X' LocX} in {TestRed {SingleThreadConfig runnable(seqStmt([unifyStmt(varId('X') varId('Y')) unifyStmt(varId('X') intLit(3))]) #EnvXY|nil) StoreX} 'sequence' {SingleThreadConfig runnable((unifyStmt(varId('X') varId('Y'))#EnvXY) |(unifyStmt(varId('X') intLit(3))#EnvXY)|nil) StoreX} } end local LocY#StoreY = {AllocStore Store0} LocX#StoreX = {AllocStore StoreY} EnvXY = {ExtendEnv {ExtendEnv Env0 'Y' LocY} 'X' LocX} StoreXY = {UnifyLocs StoreX LocX LocY} in {TestRed {SingleThreadConfig runnable((unifyStmt(varId('X') varId('Y'))#EnvXY) |(unifyStmt(varId('X') intLit(3))#EnvXY)|nil) StoreX} 'var-var binding' {SingleThreadConfig runnable((unifyStmt(varId('X') intLit(3))#EnvXY)|nil) StoreXY} } end local LocY#StoreY = {AllocStore Store0} LocX#StoreX = {AllocStore StoreY} EnvXY = {ExtendEnv {ExtendEnv Env0 'Y' LocY} 'X' LocX} StoreXY = {UnifyLocs StoreX LocX LocY} StoreX3Y3 = {UnifyLocVal StoreXY LocX num(3)} in {TestRed {SingleThreadConfig runnable((unifyStmt(varId('X') intLit(3))#EnvXY)|nil) StoreXY} 'value-creation' {SingleThreadConfig runnable(nil) StoreX3Y3} } end %% Thread tests... {TestRed {MakeConfig seqStmt([threadStmt(skipStmt) skipStmt]) Env0 Store0} 'sequence' {SingleThreadConfig runnable(threadStmt(skipStmt)#Env0|skipStmt#Env0|nil) Store0}} {TestRed {SingleThreadConfig runnable(threadStmt(skipStmt)#Env0|skipStmt#Env0|nil) Store0} 'thread-creation' {MultiThreadConfig 1 [runnable(skipStmt#Env0|nil) runnable(skipStmt#Env0|nil)] Store0}} {TestRed {MultiThreadConfig 1 [runnable(skipStmt#Env0|nil) runnable(skipStmt#Env0|nil)] Store0} 'skip' {MultiThreadConfig 1 [runnable(nil) runnable(skipStmt#Env0|nil)] Store0}} {TestRed {MultiThreadConfig 1 [runnable(nil) runnable(skipStmt#Env0|nil)] Store0} 'thread-finish' {SingleThreadConfig runnable(skipStmt#Env0|nil) Store0}} {TestRed {MakeConfig localStmt(varId('Res') seqStmt([threadStmt(unifyStmt(varId('Res') intLit(7))) threadStmt(skipStmt)])) Env0 Store0} 'local' local Loc#Store2 = {AllocStore Store0} in local Env1 = {ExtendEnv Env0 'Res' Loc} in {SingleThreadConfig runnable(seqStmt([threadStmt(unifyStmt(varId('Res') intLit(7))) threadStmt(skipStmt)])#Env1|nil) Store2} end end} local Loc#Store2 = {AllocStore Store0} in local Env1 = {ExtendEnv Env0 'Res' Loc} in {TestRed {SingleThreadConfig runnable(seqStmt([threadStmt(unifyStmt(varId('Res') intLit(7))) threadStmt(skipStmt)])#Env1|nil) Store2} 'sequence' {SingleThreadConfig runnable(threadStmt(unifyStmt(varId('Res') intLit(7)))#Env1|threadStmt(skipStmt)#Env1|nil) Store2} } end end local Loc#Store2 = {AllocStore Store0} in local Env1 = {ExtendEnv Env0 'Res' Loc} in {TestRed {SingleThreadConfig runnable(threadStmt(unifyStmt(varId('Res') intLit(7)))#Env1|threadStmt(skipStmt)#Env1|nil) Store2} 'thread-creation' {MultiThreadConfig 1 [runnable(threadStmt(skipStmt)#Env1|nil) runnable(unifyStmt(varId('Res') intLit(7))#Env1|nil)] Store2} } end end local Loc#Store2 = {AllocStore Store0} in local Env1 = {ExtendEnv Env0 'Res' Loc} in {TestRed {MultiThreadConfig 1 [runnable(threadStmt(skipStmt)#Env1|nil) runnable(unifyStmt(varId('Res') intLit(7))#Env1|nil)] Store2} 'thread-creation' {MultiThreadConfig 1 [runnable(nil) runnable(unifyStmt(varId('Res') intLit(7))#Env1|nil) runnable(skipStmt#Env1|nil)] Store2} } end end local Loc#Store2 = {AllocStore Store0} in local Env1 = {ExtendEnv Env0 'Res' Loc} in {TestRed {MultiThreadConfig 1 [runnable(nil) runnable(unifyStmt(varId('Res') intLit(7))#Env1|nil) runnable(skipStmt#Env1|nil)] Store2} 'thread-finish' {MultiThreadConfig 1 [runnable(unifyStmt(varId('Res') intLit(7))#Env1|nil) runnable(skipStmt#Env1|nil)] Store2} } end end local Loc#Store2 = {AllocStore Store0} in local Env1 = {ExtendEnv Env0 'Res' Loc} in local Store3 = {UnifyLocVal Store2 Loc num(7)} in {TestRed {MultiThreadConfig 1 [runnable(unifyStmt(varId('Res') intLit(7))#Env1|nil) runnable(skipStmt#Env1|nil)] Store2} 'value-creation' {MultiThreadConfig 1 [runnable(nil) runnable(skipStmt#Env1|nil)] Store3} } end end end local Loc#Store2 = {AllocStore Store0} in local Env1 = {ExtendEnv Env0 'Res' Loc} in local Store3 = {UnifyLocVal Store2 Loc num(7)} in {TestRed {MultiThreadConfig 1 [runnable(nil) runnable(skipStmt#Env1|nil)] Store3} 'thread-finish' {MultiThreadConfig 1 [runnable(skipStmt#Env1|nil)] Store3} } end end end local Loc#Store2 = {AllocStore Store0} in local Env1 = {ExtendEnv Env0 'Res' Loc} in local Store3 = {UnifyLocVal Store2 Loc num(7)} in {TestRed {MultiThreadConfig 1 [runnable(skipStmt#Env1|nil)] Store3} 'skip' {MultiThreadConfig 1 [runnable(nil)] Store3} } end end end {Show {MakeConfig localStmt(varId('Res') seqStmt([threadStmt(unifyStmt(varId('Res') intLit(7))) threadStmt(skipStmt)])) Env0 Store0}} {PrintConfig {MakeConfig localStmt(varId('Res') seqStmt([threadStmt(unifyStmt(varId('Res') intLit(7))) threadStmt(skipStmt)])) Env0 Store0}} %%%%%%%%%%%%%%% Statement Defs for what follows %%%%%%%%%% InnerStmt01 = unifyStmt(varId('Th') intLit(3)) InnerStmt02 = unifyStmt(varId('Rec') recordExp(atomExp(foo) [colonFld(atomExp(val) varId('Th'))])) InnerStmt03 = caseStmt(varId('Rec') recordPat(atomExp(foo) [colonFld(atomExp(val) varIdPat('Z'))]) unifyStmt(varId('Res') recordExp(atomExp(bar) [colonFld(atomExp(baz) varId('Z'))])) unifyStmt(varId('Res') procExp([varIdPat('A') varIdPat('R')] unifyStmt(varId('A') varId('R'))))) InnerStmt0 = seqStmt([InnerStmt01 InnerStmt02 InnerStmt03]) {TestRed {SingleThreadConfig runnable(localStmt(varId('Res') localStmt(varId('Rec') localStmt(varId('Th') InnerStmt0))) #Env0|nil) Store0} 'local' local LocRes#StoreRes = {AllocStore Store0} in {SingleThreadConfig runnable(localStmt(varId('Rec') localStmt(varId('Th') InnerStmt0)) #{ExtendEnv Env0 'Res' LocRes}|nil) StoreRes} end } {TestRed local LocRes#StoreRes = {AllocStore Store0} in {SingleThreadConfig runnable(localStmt(varId('Rec') localStmt(varId('Th') InnerStmt0)) #{ExtendEnv Env0 'Res' LocRes}|nil) StoreRes} end 'local' local LocRes#StoreRes = {AllocStore Store0} LocRec#StoreRec = {AllocStore StoreRes} in {SingleThreadConfig runnable(localStmt(varId('Th') InnerStmt0) #{ExtendEnv {ExtendEnv Env0 'Res' LocRes} 'Rec' LocRec}|nil) StoreRec} end } {TestRed local LocRes#StoreRes = {AllocStore Store0} LocRec#StoreRec = {AllocStore StoreRes} in {SingleThreadConfig runnable(localStmt(varId('Th') InnerStmt0) #{ExtendEnv {ExtendEnv Env0 'Res' LocRes} 'Rec' LocRec}|nil) StoreRec} end 'local' local LocRes#StoreRes = {AllocStore Store0} LocRec#StoreRec = {AllocStore StoreRes} LocTh#StoreTh = {AllocStore StoreRec} EnvTh = {ExtendEnv {ExtendEnv {ExtendEnv Env0 'Res' LocRes} 'Rec' LocRec} 'Th' LocTh} in {SingleThreadConfig runnable(InnerStmt0#EnvTh|nil) StoreTh} end } {TestRed local LocRes#StoreRes = {AllocStore Store0} LocRec#StoreRec = {AllocStore StoreRes} LocTh#StoreTh = {AllocStore StoreRec} EnvTh = {ExtendEnv {ExtendEnv {ExtendEnv Env0 'Res' LocRes} 'Rec' LocRec} 'Th' LocTh} in {SingleThreadConfig runnable(seqStmt([InnerStmt01 InnerStmt02 InnerStmt03])#EnvTh|nil) StoreTh} end 'sequence' local LocRes#StoreRes = {AllocStore Store0} LocRec#StoreRec = {AllocStore StoreRes} LocTh#StoreTh = {AllocStore StoreRec} EnvTh = {ExtendEnv {ExtendEnv {ExtendEnv Env0 'Res' LocRes} 'Rec' LocRec} 'Th' LocTh} in {SingleThreadConfig runnable(InnerStmt01#EnvTh|InnerStmt02#EnvTh|InnerStmt03#EnvTh|nil) StoreTh} end } {TestRed local LocRes#StoreRes = {AllocStore Store0} LocRec#StoreRec = {AllocStore StoreRes} LocTh#StoreTh = {AllocStore StoreRec} EnvTh = {ExtendEnv {ExtendEnv {ExtendEnv Env0 'Res' LocRes} 'Rec' LocRec} 'Th' LocTh} in {SingleThreadConfig runnable(unifyStmt(varId('Th') intLit(3))#EnvTh|InnerStmt02#EnvTh|InnerStmt03#EnvTh|nil) StoreTh} end 'value-creation' local LocRes#StoreRes = {AllocStore Store0} LocRec#StoreRec = {AllocStore StoreRes} LocTh#StoreTh = {AllocStore StoreRec} EnvTh = {ExtendEnv {ExtendEnv {ExtendEnv Env0 'Res' LocRes} 'Rec' LocRec} 'Th' LocTh} StoreTh3 = {UnifyLocVal StoreTh LocTh num(3)} in {SingleThreadConfig runnable(InnerStmt02#EnvTh|InnerStmt03#EnvTh|nil) StoreTh3} end } {TestRed local LocRes#StoreRes = {AllocStore Store0} LocRec#StoreRec = {AllocStore StoreRes} LocTh#StoreTh = {AllocStore StoreRec} EnvTh = {ExtendEnv {ExtendEnv {ExtendEnv Env0 'Res' LocRes} 'Rec' LocRec} 'Th' LocTh} StoreTh3 = {UnifyLocVal StoreTh LocTh num(3)} in {SingleThreadConfig runnable(unifyStmt(varId('Rec') recordExp(atomExp(foo) [colonFld(atomExp(val) varId('Th'))])) #EnvTh|InnerStmt03#EnvTh|nil) StoreTh3} end 'value-creation' local LocRes#StoreRes = {AllocStore Store0} LocRec#StoreRec = {AllocStore StoreRes} LocTh#StoreTh = {AllocStore StoreRec} EnvTh = {ExtendEnv {ExtendEnv {ExtendEnv Env0 'Res' LocRes} 'Rec' LocRec} 'Th' LocTh} StoreTh3 = {UnifyLocVal StoreTh LocTh num(3)} Store3Rec = {UnifyLocVal StoreTh3 LocRec record(foo(val: LocTh))} in {SingleThreadConfig runnable(InnerStmt03#EnvTh|nil) Store3Rec} end } {TestRed local LocRes#StoreRes = {AllocStore Store0} LocRec#StoreRec = {AllocStore StoreRes} LocTh#StoreTh = {AllocStore StoreRec} EnvTh = {ExtendEnv {ExtendEnv {ExtendEnv Env0 'Res' LocRes} 'Rec' LocRec} 'Th' LocTh} StoreTh3 = {UnifyLocVal StoreTh LocTh num(3)} Store3Rec = {UnifyLocVal StoreTh3 LocRec record(foo(val: LocTh))} in {SingleThreadConfig runnable(caseStmt(varId('Rec') recordPat(atomExp(foo) [colonFld(atomExp(val) varIdPat('Z'))]) unifyStmt(varId('Res') recordExp(atomExp(bar) [colonFld(atomExp(baz) varId('Z'))])) unifyStmt(varId('Res') procExp([varIdPat('A') varIdPat('R')] unifyStmt(varId('A') varId('R'))))) #EnvTh|nil) Store3Rec} end 'case-match' local LocRes#StoreRes = {AllocStore Store0} LocRec#StoreRec = {AllocStore StoreRes} LocTh#StoreTh = {AllocStore StoreRec} EnvTh = {ExtendEnv {ExtendEnv {ExtendEnv Env0 'Res' LocRes} 'Rec' LocRec} 'Th' LocTh} StoreTh3 = {UnifyLocVal StoreTh LocTh num(3)} Store3Rec = {UnifyLocVal StoreTh3 LocRec record(foo(val: LocTh))} EnvMatch = {ExtendEnvList EnvTh ['Z'] [LocTh]} in {SingleThreadConfig runnable(unifyStmt(varId('Res') recordExp(atomExp(bar) [colonFld(atomExp(baz) varId('Z'))])) #EnvMatch|nil) Store3Rec} end } {TestRed local LocRes#StoreRes = {AllocStore Store0} LocRec#StoreRec = {AllocStore StoreRes} LocTh#StoreTh = {AllocStore StoreRec} EnvTh = {ExtendEnv {ExtendEnv {ExtendEnv Env0 'Res' LocRes} 'Rec' LocRec} 'Th' LocTh} StoreTh3 = {UnifyLocVal StoreTh LocTh num(3)} Store3Rec = {UnifyLocVal StoreTh3 LocRec record(foo(val: LocTh))} EnvMatch = {ExtendEnvList EnvTh ['Z'] [LocTh]} in {SingleThreadConfig runnable(unifyStmt(varId('Res') recordExp(atomExp(bar) [colonFld(atomExp(baz) varId('Z'))])) #EnvMatch|nil) Store3Rec} end 'value-creation' local LocRes#StoreRes = {AllocStore Store0} LocRec#StoreRec = {AllocStore StoreRes} LocTh#StoreTh = {AllocStore StoreRec} StoreTh3 = {UnifyLocVal StoreTh LocTh num(3)} Store3Rec = {UnifyLocVal StoreTh3 LocRec record(foo(val: LocTh))} StoreResFinal = {UnifyLocVal Store3Rec LocRes record(bar(baz: LocTh))} in {SingleThreadConfig runnable(nil) StoreResFinal} end } %%% An alternative with goes into the else part {TestRed local LocRes#StoreRes = {AllocStore Store0} LocRec#StoreRec = {AllocStore StoreRes} LocTh#StoreTh = {AllocStore StoreRec} EnvTh = {ExtendEnv {ExtendEnv {ExtendEnv Env0 'Res' LocRes} 'Rec' LocRec} 'Th' LocTh} StoreTh3 = {UnifyLocVal StoreTh LocTh num(3)} Store3Rec = {UnifyLocVal StoreTh3 LocRec record(blech(val: LocTh))} in {SingleThreadConfig runnable(caseStmt(varId('Rec') recordPat(atomExp(foo) [colonFld(atomExp(val) varIdPat('Z'))]) unifyStmt(varId('Res') recordExp(atomExp(bar) [colonFld(atomExp(baz) varId('Z'))])) unifyStmt(varId('Res') procExp([varIdPat('A') varIdPat('R')] unifyStmt(varId('A') varId('R'))))) #EnvTh|nil) Store3Rec} end 'case-else' local LocRes#StoreRes = {AllocStore Store0} LocRec#StoreRec = {AllocStore StoreRes} LocTh#StoreTh = {AllocStore StoreRec} EnvTh = {ExtendEnv {ExtendEnv {ExtendEnv Env0 'Res' LocRes} 'Rec' LocRec} 'Th' LocTh} StoreTh3 = {UnifyLocVal StoreTh LocTh num(3)} Store3Rec = {UnifyLocVal StoreTh3 LocRec record(blech(val: LocTh))} in {SingleThreadConfig runnable(unifyStmt(varId('Res') procExp([varIdPat('A') varIdPat('R')] unifyStmt(varId('A') varId('R')))) #EnvTh|nil) Store3Rec} end } {TestRed local LocRes#StoreRes = {AllocStore Store0} LocRec#StoreRec = {AllocStore StoreRes} LocTh#StoreTh = {AllocStore StoreRec} EnvTh = {ExtendEnv {ExtendEnv {ExtendEnv Env0 'Res' LocRes} 'Rec' LocRec} 'Th' LocTh} StoreTh3 = {UnifyLocVal StoreTh LocTh num(3)} Store3Rec = {UnifyLocVal StoreTh3 LocRec record(blech(val: LocTh))} in {SingleThreadConfig runnable(unifyStmt(varId('Res') procExp([varIdPat('A') varIdPat('R')] unifyStmt(varId('A') varId('R')))) #EnvTh|nil) Store3Rec} end 'value-creation' local LocRes#StoreRes = {AllocStore Store0} LocRec#StoreRec = {AllocStore StoreRes} LocTh#StoreTh = {AllocStore StoreRec} EnvTh = {ExtendEnv {ExtendEnv {ExtendEnv Env0 'Res' LocRes} 'Rec' LocRec} 'Th' LocTh} StoreTh3 = {UnifyLocVal StoreTh LocTh num(3)} Store3Rec = {UnifyLocVal StoreTh3 LocRec record(blech(val: LocTh))} StoreClos = {UnifyLocVal Store3Rec LocRes closure(['A' 'R'] unifyStmt(varId('A') varId('R')) EnvTh)} in {SingleThreadConfig runnable(nil) StoreClos} end } %%%%%%%%%%%%%%%%%%%%% Reducer test %%%%%%%%%%%%%%% {ShowReductionsFor 'Same As Above' localStmt(varId('Res') localStmt(varId('Rec') localStmt(varId('Th') InnerStmt0)))} InnerApply0 = unifyStmt(varId('Th') intLit(3)) InnerApply1 = unifyStmt(varId('Id') procExp([varIdPat('X') varIdPat('R')] unifyStmt(varId('R') varId('X')))) InnerApply2 = applyStmt(varId('Id') [varId('Th') varId('Res')]) InnerApply = seqStmt([InnerApply0 InnerApply1 InnerApply2]) {ShowReductionsFor 'An Application' localStmt(varId('Res') localStmt(varId('Id') localStmt(varId('Th') InnerApply)))} InnerIf0 = unifyStmt(varId('X') boolExp(true)) InnerIf13 = unifyStmt(varId('Res') intLit(3)) InnerIf14 = unifyStmt(varId('Res') intLit(4)) InnerIf1 = ifStmt(varId('X') InnerIf13 InnerIf14) InnerIf = seqStmt([InnerIf0 InnerIf1]) {ShowReductionsFor 'With If True' localStmt(varId('Res') localStmt(varId('X') InnerIf))} InnerIfF0 = unifyStmt(varId('X') boolExp(false)) InnerIfF13 = unifyStmt(varId('Res') intLit(3)) InnerIfF14 = unifyStmt(varId('Res') intLit(4)) InnerIfF1 = ifStmt(varId('X') InnerIfF13 InnerIfF14) InnerIfF = seqStmt([InnerIfF0 InnerIfF1]) {ShowReductionsFor 'With If False' localStmt(varId('Res') localStmt(varId('X') InnerIfF))} {ShowReductionsFor 'Locals and Assignments from Notes' localStmt(varId('R') localStmt(varId('X') seqStmt([unifyStmt(varId('X') intLit(2)) unifyStmt(varId('R') varId('X'))])))} NotesS7 = ifStmt(varId('Z') skipStmt unifyStmt(varId('Z') varId('X'))) NotesS6 = localStmt(varId('Z') seqStmt([applyStmt(varId('Y') [varId('Z')]) NotesS7])) NotesS5 = unifyStmt(varId('X') boolExp(false)) NotesS4 = localStmt(varId('X') seqStmt([NotesS5 NotesS6])) NotesS3 = unifyStmt(varId('X') boolExp(true)) NotesS2 = unifyStmt(varId('Y') procExp([varIdPat('R')] unifyStmt(varId('R') varId('X')))) NotesS1 = localStmt(varId('Y') seqStmt([NotesS2 NotesS3 NotesS4])) NotesS0 = localStmt(varId('X') NotesS1) {ShowReductionsFor 'Procedure Application with If from Notes' NotesS0} % local Res in % local K in % K = proc {$ X ?R} R=proc {$ Y ?Z} Z=X end end % local F in % local Three in % Three = 3 % {K Three F} % local Four in % Four = 4 % {F Four Res} % end % end % end % end % end CurriedProc = procExp([varIdPat('X') varIdPat('R')] unifyStmt(varId('R') procExp([varIdPat('Y') varIdPat('Z')] unifyStmt(varId('Z') varId('X'))))) DefiningFour = localStmt(varId('Four') seqStmt([ unifyStmt(varId('Four') intLit(4)) applyStmt(varId('F') [varId('Four') varId('Res')]) ])) DefiningF = localStmt(varId('F') localStmt(varId('Three') seqStmt([unifyStmt(varId('Three') intLit(3)) applyStmt(varId('K') [varId('Three') varId('F')]) DefiningFour ]))) CurriedAppProg = localStmt(varId('Res') localStmt(varId('K') seqStmt([unifyStmt(varId('K') CurriedProc) DefiningF]))) {ShowReductionsFor 'Curried Function Application from Notes' CurriedAppProg } % local Res in % local Length in % Length = proc {$ Lst R} % case Lst of % '|'(1:_ 2:T) then % local Temp in % {Length T Temp} % local One in % One = 1 % {Number.'+' One Temp R} % end % end % else R = 0 % end % end % local Three in % Three = 3 % local Nil in % Nil = nil % local List3 in % List3 = '|'(1: Three 2:Nil) % local MyList in % MyList = '|'(1: Three 2:List3) % {Length MyList Res} % {System.showInfo Res} % end % end % end % end % end % end LengthProc = procExp([varIdPat('Lst') varIdPat('R')] caseStmt(varId('Lst') recordPat(atomExp('|') [colonFld(intLit(1) varIdPat('_')) colonFld(intLit(2) varIdPat('T'))]) localStmt(varId('Temp') seqStmt([applyStmt(varId('Length') [varId('T') varId('Temp')]) localStmt(varId('One') seqStmt([unifyStmt(varId('One') intLit(1)) applyStmt(varId('Number.\'+\'') [varId('One') varId('Temp') varId('R')])])) ])) unifyStmt(varId('R') intLit(0)))) List33 = recordExp(atomExp('|') [colonFld(intLit(1) varId('Three')) colonFld(intLit(2) varId('List3')) ]) MyListLocal = localStmt(varId('MyList') seqStmt([unifyStmt(varId('MyList') List33) applyStmt(varId('Length') [varId('MyList') varId('Res')]) ])) List3 = localStmt(varId('List3') seqStmt([unifyStmt(varId('List3') recordExp(atomExp('|') [colonFld(intLit(1) varId('Three')) colonFld(intLit(2) varId('Nil')) ])) MyListLocal])) LengthProcApp = localStmt(varId('Three') seqStmt([unifyStmt(varId('Three') intLit(3)) localStmt(varId('Nil') seqStmt([unifyStmt(varId('Nil') atomExp(nil)) List3])) ])) ShowStmt = applyStmt(varId('System.showInfo') [varId('Res')]) FullRecurApp = localStmt(varId('Res') localStmt(varId('Length') seqStmt([unifyStmt(varId('Length') LengthProc) LengthProcApp ShowStmt ]))) {ShowStdReductionsFor 'Length Procedure, fully Recursive' FullRecurApp } {ShowStdReductionsFor 'some-threads-1' localStmt(varId('Res') seqStmt([threadStmt(unifyStmt(varId('Res') intLit(7))) threadStmt(skipStmt)])) } {ShowStdReductionsFor 'interacting-threads-1' localStmt(varId('Res') localStmt(varId('X') seqStmt([threadStmt(unifyStmt(varId('X') intLit(7))) threadStmt(localStmt(varId('One') seqStmt( [unifyStmt(varId('One') intLit(1)) applyStmt(varId('Number.\'+\'') [varId('One') varId('X') varId('Res')])]))) ]))) } {ShowStdReductionsFor 'interacting-threads-2' localStmt(varId('Res') localStmt(varId('X') localStmt(varId('One') seqStmt([threadStmt(unifyStmt(varId('X') intLit(7))) threadStmt(applyStmt(varId('Number.\'+\'') [varId('One') varId('X') varId('Res')])) threadStmt(unifyStmt(varId('One') intLit(1))) ])))) } {DoneTesting}