PrintS:
PUBLIC
PROCEDURE [s:
LONG
STRING] = {
FOR i:
CARDINAL
IN [0..s.length)
DO
Char[s[i]];
ENDLOOP;
};
PrintCR:
PUBLIC
PROCEDURE = {
Char[12C]};
PutFailMessage:
PUBLIC
PROCEDURE [x, modname:
LONG
STRING] = {
PrintS["Test "];
PrintS[x];
PrintS[" in module "];
PrintS[modname];
PrintS[" failed; "L];
PrintCR[];
};
XMesaCall7: PROCEDURE = {
PrintCR;
PrintS[filename];
PrintCR;
XMesa7a[]; -- UNWIND,implicit REJECT, REJECT,GOTO
XMesa7b[]; -- CONTINUE
XMesa7c[]; -- RETRY
XMesa7d[]; -- CONTINUE revisited in LOOPS
XMesa7e[]; -- RETRY revisited in LOOPs
XMesa7f[]; -- RESUME
XMesa7g[]; -- Unix Trap
PrintS["Done"L];
PrintCR;
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 PutFailMessage["3610", filename];
IF unwindCnt # 2 THEN PutFailMessage["3630", filename];
IF flag1 # state1 THEN PutFailMessage["3650", filename];
IF flag2 # state2 THEN PutFailMessage["3651", filename];
IF flag3 # nostate THEN PutFailMessage["3652", filename];
IF flag4 # state4 THEN 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 PutFailMessage["3660", filename];
IF flag1 # TRUE THEN 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 PutFailMessage["3690", filename];
p1 ¬ state3;
answer ¬ GetReply[p1 ! NoAnswer => {p1 ¬ nostate; CONTINUE}];
flag1 ¬ TRUE;
IF flag1 # TRUE THEN PutFailMessage["3700", filename];
IF p1 # nostate THEN 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 PutFailMessage["3730", filename];
IF flag1 # TRUE THEN PutFailMessage["3731", filename];
IF flag2 # TRUE THEN PutFailMessage["3732", filename];
IF p # nostate THEN 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 PutFailMessage["3740", filename];
IF retryCnt # 3 THEN PutFailMessage["3741", filename];
};
XMesa7f:
PROCEDURE = {
--RESUME
sum, num1, num2: INTEGER ¬ 0;
NumBoundsFault: SIGNAL [num: INTEGER] RETURNS [newnum: INTEGER];
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]; };
num2 ¬ AddNum[
sum, num1 !
NumBoundsFault => BEGIN newnum ¬ FixValue[num]; RESUME [num1 ¬ newnum]; END];
IF num2 # 35 THEN PutFailMessage["3770", filename];
num2 ¬ AddNum[
sum, num1 !
NumBoundsFault => BEGIN newnum ¬ FixValue[num]; RESUME [num1 ¬ newnum]; END];
IF num2 # 35 THEN PutFailMessage["3790", filename];
XMesa7g:
PROCEDURE = {
Rec:
TYPE ~
RECORD [
a, b: INT
];
num1: INT ¬ 0;
num2: INT ¬ 0;
r: REF Rec ¬ NIL;
{
ENABLE
VM.AddressFault =>
IF address=
NIL
THEN {
num1 ¬ 1;
CONTINUE
}
ELSE
{
num2 ¬ 1;
CONTINUE;
};
i: INT ¬ r.a;
};
IF num1 # 1 THEN PutFailMessage["3795", filename];
IF num2 # 0 THEN PutFailMessage["3796", filename];
};
mainline
XMesaCall7[];