XMesaCmplr7:
PROGRAM
IMPORTS RunRegressions, XMesaProcs =
BEGIN
filename: LONG STRING ¬ "XMesaCmplr7"L;
XMesaCall7: PROCEDURE = {
XMesaProcs.PrintCR;
XMesaProcs.PrintS[filename];
XMesaProcs.PrintCR;
XMesa7a[]; -- UNWIND,implicit REJECT, REJECT,GOTO
XMesa7b[]; -- CONTINUE
XMesa7c[]; -- RETRY
XMesa7d[]; -- CONTINUE revisited in LOOPS
XMesa7e[]; -- RETRY revisited in LOOPs
XMesa7f[]; -- RESUME
XMesaProcs.PrintS["Done"L];
XMesaProcs.PrintCR;
}; --end of XMesaCall7
XMesa7a:
PROCEDURE = {
--UNWIND,implicit REJECT, REJECT,GOTO
Sig1: ERROR = CODE;
Sig2: ERROR = CODE;
FlagType: TYPE = {nostate, state1, state2, state3, state4};
sig2Cnt, sig1Cnt, unwindCnt: CARDINAL ¬ 0;
flag1, flag2, flag3, flag4: FlagType ¬ nostate;
Proc1:
PROCEDURE [x:
CARDINAL] =
BEGIN
ENABLE
BEGIN
Sig1 => GOTO exit;
Sig2 => sig2Cnt ¬ sig2Cnt + 1;
UNWIND => unwindCnt ¬ unwindCnt + 1;
END;
flag1 ¬ state1;
BEGIN
ENABLE Sig1 => sig1Cnt ¬ sig1Cnt + 1;
flag2 ¬ state2;
Proc2[
x ! Sig2 => sig2Cnt ¬ sig2Cnt + 1; UNWIND => unwindCnt ¬ unwindCnt + 1; ];
END;
flag3 ¬ state3;
EXITS exit => flag4 ¬ state4;
END;
Proc2:
PROCEDURE [x:
CARDINAL] =
BEGIN
Proc3[
x ! Sig1 => sig1Cnt ¬ sig1Cnt + 1; Sig2 => sig2Cnt ¬ sig2Cnt + 1;
UNWIND => unwindCnt ¬ unwindCnt + 1];
END;
Proc3:
PROCEDURE [x:
CARDINAL] =
BEGIN IF x = 0 THEN ERROR Sig1 ELSE ERROR Sig2; END;
Proc1[0];
IF sig1Cnt # 2 THEN XMesaProcs.PutFailMessage[3610, filename];
IF unwindCnt # 2 THEN XMesaProcs.PutFailMessage[3630, filename];
IF flag1 # state1 THEN XMesaProcs.PutFailMessage[3650, filename];
IF flag2 # state2 THEN XMesaProcs.PutFailMessage[3651, filename];
IF flag3 # nostate THEN XMesaProcs.PutFailMessage[3652, filename];
IF flag4 # state4 THEN XMesaProcs.PutFailMessage[3653, filename];
};
XMesa7b:
PROCEDURE = {
--CONTINUE
Color: TYPE = {red, orange, yellow, green, blue, violet};
button: [0..2];
invalidButtonColor: ERROR = CODE;
errFlag, flag1: BOOL ¬ FALSE;
Proc1:
PROCEDURE [c1: Color] = {
button ¬
SELECT c1
FROM
red => 0,
yellow => 1,
green => 2,
ENDCASE => ERROR invalidButtonColor;
};
BEGIN
ENABLE invalidButtonColor => {errFlag ¬ TRUE; CONTINUE};
Proc1[orange];
END;
flag1 ¬ TRUE;
IF errFlag # TRUE THEN XMesaProcs.PutFailMessage[3660, filename];
IF flag1 # TRUE THEN XMesaProcs.PutFailMessage[3661, filename];
};
XMesa7c:
PROCEDURE = {
--RETRY
answer: INTEGER ¬ 0;
PType: TYPE = {nostate, state1, state2, state3};
NoAnswer: SIGNAL = CODE;
p1: PType ¬ state3;
flag1: BOOL ¬ FALSE;
GetReply:
PROCEDURE [p: PType]
RETURNS [a:
INTEGER] = {
SELECT p
FROM
nostate => a ¬ 0;
state1 => a ¬ 1;
state2 => a ¬ 2;
ENDCASE => SIGNAL NoAnswer;
};
answer ¬ GetReply[p1 ! NoAnswer => {p1 ¬ nostate; RETRY}];
IF answer # 0 THEN XMesaProcs.PutFailMessage[3690, filename];
p1 ¬ state3;
answer ¬ GetReply[p1 ! NoAnswer => {p1 ¬ nostate; CONTINUE}];
flag1 ¬ TRUE;
IF flag1 # TRUE THEN XMesaProcs.PutFailMessage[3700, filename];
IF p1 # nostate THEN XMesaProcs.PutFailMessage[3701, filename];
};
XMesa7d:
PROCEDURE = {
--CONTINUE revisited in LOOPS
Sig1: SIGNAL = CODE;
int: INTEGER ¬ 0;
PType: TYPE = {nostate, state1, state2, state3};
p: PType ¬ state2;
flag1, flag2: BOOL ¬ FALSE;
UNTIL p = nostate
DO
BEGIN
ENABLE
Sig1 => {
int ¬ int + 1; IF int = 1 THEN p ¬ state1 ELSE p ¬ nostate; CONTINUE};
flag1 ¬ TRUE;
SIGNAL Sig1;
END
ENDLOOP;
flag2 ¬ TRUE;
IF int # 2 THEN XMesaProcs.PutFailMessage[3730, filename];
IF flag1 # TRUE THEN XMesaProcs.PutFailMessage[3731, filename];
IF flag2 # TRUE THEN XMesaProcs.PutFailMessage[3732, filename];
IF p # nostate THEN XMesaProcs.PutFailMessage[3733, filename];
};
XMesa7e:
PROCEDURE = {
--RETRY revisited in LOOPs
Sig1: SIGNAL = CODE;
int, retryCnt: INTEGER ¬ 0;
PType: TYPE = {nostate, state1, state2, state3};
p: PType ¬ state2;
flag1, flag2: BOOL ¬ FALSE;
UNTIL p = nostate
DO
BEGIN
ENABLE Sig1 => {retryCnt ¬ retryCnt + 1; RETRY};
int ¬ int + 1;
IF int <= 3 THEN SIGNAL Sig1 ELSE EXIT;
END
ENDLOOP;
flag1 ¬ TRUE;
IF int # 4 THEN XMesaProcs.PutFailMessage[3740, filename];
IF retryCnt # 3 THEN XMesaProcs.PutFailMessage[3741, filename];
};
XMesa7f:
PROCEDURE = {
--RESUME
sum, num1, num2: INTEGER ¬ 0;
NumBoundsFault: SIGNAL [num: INTEGER] RETURNS [newnum: INTEGER] = CODE;
AddNum:
PROCEDURE [total, elem:
INTEGER]
RETURNS [newtot:
INTEGER] = {
IF elem > total THEN elem ¬ SIGNAL NumBoundsFault[elem];
RETURN[total + elem];
};
FixValue:
PROCEDURE [elem:
INTEGER]
RETURNS [
INTEGER] = {
elem ¬ elem - 10; RETURN[elem]; };
sum ¬ 20;
num1 ¬ 15;
num2 ¬ AddNum[
sum, num1 !
NumBoundsFault => BEGIN newnum ¬ FixValue[num]; RESUME [num1 ¬ newnum]; END];
IF num2 # 35 THEN XMesaProcs.PutFailMessage[3770, filename];
sum ¬ 20;
num1 ¬ 25;
num2 ¬ AddNum[
sum, num1 !
NumBoundsFault => BEGIN newnum ¬ FixValue[num]; RESUME [num1 ¬ newnum]; END];
IF num2 # 35 THEN XMesaProcs.PutFailMessage[3790, filename];
};
XMesa9g:
PROCEDURE = {
--Expressions and operators
i: INTEGER;
li: LONG INTEGER;
c: CARDINAL;
signalRaised: BOOLEAN ¬ FALSE;
Bounds checking/if \b switch is specifed "Bounds fault" must be generated
BEGIN
ENABLE ANY => {signalRaised ¬ TRUE; CONTINUE};
c ¬ 40000;
i ¬ c;
END;
XMesaProcs.Isboolequal[signalRaised, TRUE, 800, filename];
signalRaised ¬ FALSE;
BEGIN
ENABLE ANY => {signalRaised ¬ TRUE; CONTINUE};
i ¬ -1;
c ¬ i;
END;
XMesaProcs.Isboolequal[signalRaised, TRUE, 810, filename];
signalRaised ¬ FALSE;
BEGIN
ENABLE ANY => {signalRaised ¬ TRUE; CONTINUE};
li ¬ -1;
c ¬ CARDINAL[li];
END;
XMesaProcs.Isboolequal[signalRaised, TRUE, 830, filename];
signalRaised ¬ FALSE;
};
mainline
RunRegressions.RegisterTest[XMesaCall7, "test7"];
END...