File: XMesaCmplr4.mesa - created by MW. Last edit:
JKF 23-Jul-87 13:07:39
MW 31-Mar-87 9:36:35
Jim Foote January 22, 1988 1:52:46 pm PST
Mna, April 17, 1991 3:30 pm PDT
Copyright (C) 1987 by Xerox Corporation. All rights reserved.
Procedures
DIRECTORY
RunRegressions,
XMesaProcs;
XMesaCmplr4: PROGRAM IMPORTS RunRegressions, XMesaProcs =
BEGIN
filename: LONG STRING ¬ "XMesaCmplr4"L;
XMesaCall4: PROCEDURE = {
XMesaProcs.PrintS[filename];
XMesaProcs.PrintCR;
XMesa4a[]; -- procedure types
XMesa4b[]; -- variable declaration
XMesa4c[]; -- procedure values and compatibility
XMesa4d[]; -- defaults
XMesa4e[]; -- procedure calls
XMesa4f[]; -- procedure variables operation
XMesa4g[]; --return options, named/unnamed
XMesa4h[]; --more RETURN options
XMesaProcs.PrintS["Done"L];
XMesaProcs.PrintCR;
}; --end of XMesaCall4
XMesa4a: PROCEDURE = { -- procedure types
ma: INTEGER ¬ 0;
mb: BOOL ¬ TRUE;
example1: PROCEDURE [a: INTEGER, b: BOOL] = { -- takes two args returns none
XMesaProcs.Isequal[a, 0, 2180, filename];
XMesaProcs.Isboolequal[b, TRUE, 2190, filename];
a ¬ 1;
b ¬ FALSE;
};
example2: PROCEDURE RETURNS [i: INTEGER] = {i ¬ 10; RETURN[i]; };
example3: PROCEDURE RETURNS [i: INTEGER, b: BOOL] = {i ¬ 20; b ¬ TRUE; };
example4: PROCEDURE [i: INTEGER] RETURNS [b: BOOL] = {
IF i = 10 THEN b ¬ FALSE ELSE b ¬ TRUE; RETURN[b]; };
example1[ma, mb];
XMesaProcs.Isnotequal[ma, 1, 2200, filename];
XMesaProcs.Isnotboolequal[mb, FALSE, 2210, filename];
ma ¬ example2[];
XMesaProcs.Isequal[ma, 10, 2220, filename];
[ma, mb] ¬ example3[];
XMesaProcs.Isequal[ma, 20, 2230, filename];
XMesaProcs.Isboolequal[mb, TRUE, 2240, filename];
ma ¬ 10;
mb ¬ example4[ma];
XMesaProcs.Isboolequal[mb, FALSE, 2250, filename];
};
XMesa4b: PROCEDURE = { -- variable versus type declaration,field list
T: TYPE = RECORD [md: INTEGER, me: BOOL];
Listproc: TYPE = PROCEDURE [in: INTEGER] RETURNS [out: INTEGER];
aT, bT: T;
ma, mb, mc: INTEGER;
First: Listproc = {IF in = 20 THEN out ¬ 40 ELSE out ¬ 20; RETURN[out]; };
Last: Listproc = {IF in = 20 THEN out ¬ 0 ELSE out ¬ 40; RETURN[out]; };
Rest: PROCEDURE [
one, two: INTEGER, Less: Listproc,
More: PROCEDURE [i: INTEGER, j: INTEGER] RETURNS [INTEGER]]
RETURNS [INTEGER] = {
IF one = 1 AND two = 2 THEN RETURN[Less[one]] ELSE RETURN[More[one, two]];
};
Lessproc: Listproc = {IF in = 1 THEN out ¬ 0 ELSE out ¬ 40; RETURN[out]; };
Moreproc: PROCEDURE [i: INTEGER, j: INTEGER] RETURNS [INTEGER] = {
RETURN[i + j]; };
ma ¬ 20;
mb ¬ First[ma];
XMesaProcs.Isequal[mb, 40, 2260, filename];
ma ¬ 0;
mb ¬ Last[ma];
XMesaProcs.Isequal[mb, 40, 2270, filename];
ma ¬ 1;
mb ¬ 2;
mc ¬ Rest[ma, mb, Lessproc, Moreproc];
XMesaProcs.Isequal[mc, 0, 2280, filename];
ma ¬ 3;
mb ¬ 4;
mc ¬ Rest[ma, mb, Lessproc, Moreproc];
XMesaProcs.Isequal[mc, 7, 2290, filename];
aT ¬ T[1, FALSE];
bT ¬ T[2, TRUE];
};
XMesa4c: PROCEDURE = { -- procedure values and compatibility
Person: TYPE = RECORD [age: CARDINAL, sex: {male, female}];
Handle: TYPE = POINTER TO Person;
ma: INTEGER;
mb: INTEGER ¬ 1;
SignedNumber: TYPE = INTEGER;
Int: TYPE = INTEGER;
ProcA: PROCEDURE [h: Handle, v: SignedNumber];
ProcB: PROCEDURE [h: Handle, v: Int] ← NIL;
ProcC: PROCEDURE [POINTER TO Person, INTEGER] ← NIL;
ProcX: PROCEDURE [in: INTEGER] RETURNS [out: Handle ← NIL] = {
pHandle: POINTER TO Person;
personA: Person ¬ Person[20, female];
personB: Person ¬ Person[25, male];
IF in = 1 THEN pHandle ¬ @personA ELSE pHandle ¬ @personB;
RETURN[pHandle];
};
ProcZ: PROCEDURE [in: Handle] RETURNS [out: INTEGER ← 0] = {
IF in.age = 20 AND in.sex = female THEN RETURN[1];
IF in.age = 25 AND in.sex = male THEN RETURN[2];
};
ProcA ¬ ProcB;
XMesaProcs.Isboolequal[(ProcA = ProcB), TRUE, 2320, filename];
ProcA ¬ ProcC;
XMesaProcs.Isboolequal[(ProcA = ProcC), TRUE, 2330, filename];
ma ¬ ProcZ[ProcX[mb]];
XMesaProcs.Isequal[ma, 1, 2340, filename];
};
XMesa4d: PROCEDURE = { -- defaults
Value: TYPE = {one, two, three, four};
Flag: TYPE = {true, false, null, indif};
flag: Flag ← null;
Proc1: PROCEDURE [p: Value ¬ one] = {
SELECT p FROM
one => flag ¬ true;
two => flag ¬ false;
three => flag ¬ null;
ENDCASE => flag ¬ indif;
};
Proc2: PROCEDURE [p: Value ¬ two] = {
SELECT p FROM
one => flag ¬ false;
two => flag ¬ true;
three => flag ¬ indif;
ENDCASE => flag ¬ null;
};
Proc3: PROCEDURE [p: Value] = {
SELECT p FROM
one => flag ¬ null;
two => flag ¬ indif;
three => flag ¬ true;
ENDCASE => flag ¬ false;
};
Proc1[];
XMesaProcs.Isboolequal[flag = true, TRUE, 2350, filename];
Proc2[];
XMesaProcs.Isboolequal[flag = true, TRUE, 2360, filename];
Proc3[four];
XMesaProcs.Isboolequal[flag = false, TRUE, 2370, filename];
Proc3[three];
XMesaProcs.Isboolequal[flag = true, TRUE, 2380, filename];
Proc2[three];
XMesaProcs.Isboolequal[flag = indif, TRUE, 2390, filename];
};
XMesa4e: PROCEDURE = { -- procedure call formats
x, y: INTEGER;
z: INTEGER;
Gcd: PROCEDURE [m, n: INTEGER] RETURNS [CARDINAL] = {
r: INTEGER;
UNTIL n = 0 DO r ¬ m MOD n; m ¬ n; n ¬ r; ENDLOOP;
RETURN[ABS[m]]};
x ¬ 254;
y ¬ 55;
z ¬ Gcd[x + 1, y];
XMesaProcs.Isequal[z, 5, 2400, filename];
x ¬ 253;
y ¬ 55;
z ¬ Gcd[m: x + 1, n: y];
XMesaProcs.Isequal[z, 1, 2410, filename];
x ¬ 254;
y ¬ 55;
z ¬ Gcd[n: y, m: x + 1];
XMesaProcs.Isequal[z, 5, 2420, filename];
};
XMesa4f: PROCEDURE = { -- procedure variables operation
ma: INTEGER;
mb: INTEGER;
T: TYPE = RECORD [x, y: INTEGER];
flag: BOOL ¬ FALSE;
F: PROCEDURE [in: T] = {IF in.x = 1 AND in.y = 2 THEN flag ¬ TRUE};
G: PROCEDURE [i: INTEGER] RETURNS [out: T ← [0, 0]] = {
IF i = 10 THEN RETURN[T[1, 2]]};
Proc1: PROCEDURE RETURNS [INTEGER] ¬ {i: INTEGER ¬ 10; RETURN[i]};
Proc2: PROCEDURE RETURNS [INTEGER] ¬ {i: INTEGER ¬ 20; RETURN[i]};
Proc3: PROCEDURE RETURNS [INTEGER] ¬ {i: INTEGER ¬ 30; RETURN[i]};
ma ¬ Proc2[];
XMesaProcs.Isequal[ma, 20, 2462, filename];
Proc2 ¬ Proc1;
IF Proc2 # Proc1 THEN XMesaProcs.PutFailMessage[2440, filename];
IF Proc2[] # Proc1[] THEN XMesaProcs.PutFailMessage[2450, filename];
ma ¬ Proc2[];
XMesaProcs.Isequal[ma, 10, 2462, filename];
mb ¬ Proc1[];
XMesaProcs.Isequal[mb, 10, 2464, filename];
ma ¬ Proc3[];
IF ma # 30 THEN XMesaProcs.PutFailMessage[2466, filename];
Proc3 ¬ Proc1;
ma ¬ Proc3[];
IF ma # 10 THEN XMesaProcs.PutFailMessage[2469, filename];
F[G[10]];
XMesaProcs.Isboolequal[flag, TRUE, 2470, filename];
};
XMesa4g: PROCEDURE = { -- return options, named/unnamed/default
ma, mb, mc: INTEGER ¬ 100;
ReturnExample1: PROCEDURE [option: [1..4]] RETURNS [a, b, c: INTEGER] =
BEGIN
a ¬ b ¬ c ¬ 0;
SELECT option FROM
1 => RETURN[a: 1, b: 2, c: 3];
2 => RETURN[1, 2, 3];
3 => RETURN;
ENDCASE => b ¬ 4;
c ¬ 9;
END;
ReturnExample2: PROCEDURE [g: INTEGER] RETURNS [INTEGER ¬ 3, INTEGER ¬ 4] =
BEGIN
SELECT g FROM
0 => RETURN[, 2];
1 => RETURN[8, ];
2 => RETURN[, ];
3 => RETURN[5];
5 => RETURN[];
ENDCASE;
END;
[ma, mb, mc] ¬ ReturnExample1[1];
XMesaProcs.Isequal[ma, 1, 2480, filename];
XMesaProcs.Isequal[mb, 2, 2482, filename];
XMesaProcs.Isequal[mc, 3, 2484, filename];
ma ¬ mb ¬ mc ¬ 100;
[ma, mb, mc] ¬ ReturnExample1[2];
XMesaProcs.Isequal[ma, 1, 2490, filename];
XMesaProcs.Isequal[mb, 2, 2492, filename];
XMesaProcs.Isequal[mc, 3, 2494, filename];
ma ¬ mb ¬ mc ¬ 100;
[ma, mb, mc] ¬ ReturnExample1[3];
XMesaProcs.Isequal[ma, 0, 2500, filename];
XMesaProcs.Isequal[mb, 0, 2502, filename];
XMesaProcs.Isequal[mc, 0, 2504, filename];
ma ¬ mb ¬ mc ¬ 100;
[ma, mb, mc] ¬ ReturnExample1[4];
XMesaProcs.Isequal[ma, 0, 2510, filename];
XMesaProcs.Isequal[mb, 4, 2512, filename];
XMesaProcs.Isequal[mc, 9, 2514, filename];
ma ¬ mb ¬ mc ¬ 100;
[ma, mb] ¬ ReturnExample2[0];
XMesaProcs.Isequal[ma, 3, 2520, filename];
XMesaProcs.Isequal[mb, 2, 2522, filename];
[ma, mb] ¬ ReturnExample2[1];
XMesaProcs.Isequal[ma, 8, 2530, filename];
XMesaProcs.Isequal[mb, 4, 2532, filename];
[ma, mb] ¬ ReturnExample2[2];
XMesaProcs.Isequal[ma, 3, 2540, filename];
XMesaProcs.Isequal[mb, 4, 2542, filename];
[ma, mb] ¬ ReturnExample2[3];
XMesaProcs.Isequal[ma, 5, 2550, filename];
XMesaProcs.Isequal[mb, 4, 2552, filename];
[ma, mb] ¬ ReturnExample2[5];
XMesaProcs.Isequal[ma, 3, 2560, filename];
IF ma # 3 THEN XMesaProcs.PutFailMessage[2563, filename];
XMesaProcs.Isequal[mb, 4, 2562, filename];
};
XMesa4h: PROCEDURE = { --more RETURn options
T1: TYPE = RECORD [i: INTEGER, j: INTEGER];
T2: TYPE = RECORD [i: BOOL, j: BOOL];
c: T1 ¬ [0, 0];
d: T2 ¬ [TRUE, TRUE];
e: INTEGER;
Proc1: PROCEDURE [x: CARDINAL] RETURNS [a: T1, b: T2] = {
a ¬ T1[1, 2]; b ¬ T2[TRUE, FALSE]; IF x = 1 THEN RETURN Proc2[]; };
Proc2: PROCEDURE RETURNS [a: T1 ← [0, 0], b: T2 ← [TRUE, TRUE]] = {
a ¬ T1[0, 3]; b ¬ T2[FALSE, FALSE]; RETURN[a, b]; };
Proc3: PROCEDURE [x: CARDINAL] RETURNS [a: T1 ← [0, 0], b: INTEGER ¬ 2] = {
SELECT x FROM 1 => RETURN[T1[4, 5]]; 2 => RETURN[T1[6, 7], 5]; ENDCASE; };
[c, d] ¬ Proc1[1];
XMesaProcs.Isequal[c.i, 0, 2570, filename];
XMesaProcs.Isequal[c.j, 3, 2580, filename];
XMesaProcs.Isnotboolequal[d.i, TRUE, 2590, filename];
XMesaProcs.Isnotboolequal[d.j, TRUE, 2600, filename];
[c, e] ¬ Proc3[1];
XMesaProcs.Isequal[c.i, 4, 2610, filename];
XMesaProcs.Isequal[c.j, 5, 2620, filename];
XMesaProcs.Isequal[e, 2, 2630, filename];
[c, e] ¬ Proc3[2];
XMesaProcs.Isequal[c.i, 6, 2610, filename];
XMesaProcs.Isequal[c.j, 7, 2620, filename];
XMesaProcs.Isequal[e, 5, 2630, filename];
};
mainline
RunRegressions.RegisterTest[XMesaCall4, "test4"];
END...