RadioStates.mesa
Copyright Ó 1987 by Xerox Corporation. All rights reserved.
Barth, October 26, 1989 3:20:49 pm PDT
DIRECTORY
Basics, IO, Process, TerminalIO;
RadioStates: CEDAR PROGRAM
IMPORTS Basics, IO, Process, TerminalIO = BEGIN
stateCount: CARDINAL = 8;
log2stateCount: CARDINAL = 3;
StateRange: TYPE = [0..stateCount);
states: ARRAY StateRange OF WORDALL[0];
adjacent: ARRAY StateRange OF ARRAY StateRange OF BOOL;
ScanHack: PROC = {
DO
DO
stateIndex: INT;
FOR stateIndex IN StateRange DO
IF states[stateIndex]=stateCount-1 THEN states[stateIndex] ← 0
ELSE {
states[stateIndex] ← states[stateIndex] + 1;
EXIT;
};
REPEAT FINISHED => GOTO noneFound;
ENDLOOP;
FOR stateIndex IN StateRange DO
FOR scanIndex: CARDINAL IN StateRange DO
IF states[stateIndex]=states[scanIndex] AND stateIndex#scanIndex THEN GOTO notDistinct;
ENDLOOP;
REPEAT
notDistinct => LOOP;
ENDLOOP;
EXIT;
ENDLOOP;
Process.CheckForAbort[];
IF states[0]=7 THEN {
TerminalIO.PutRope["\n Current state assignments: "];
FOR stateIndex: INT IN StateRange DO
TerminalIO.PutF[" %g", IO.card[states[stateIndex]]];
ENDLOOP;
};
FOR stateIndex: CARDINAL IN StateRange DO
FOR scanIndex: CARDINAL IN [0..stateIndex) DO
IF adjacent[stateIndex][scanIndex] THEN {
foundOne: BOOLFALSE;
compatible: WORD ← Basics.BITXOR[states[stateIndex], states[scanIndex]];
FOR bitIndex: CARDINAL IN [0..log2stateCount) DO
one: BOOL ← Basics.BITAND[compatible, 1]#0;
compatible ← Basics.BITSHIFT[compatible, -1];
IF NOT one THEN LOOP;
IF foundOne THEN GOTO incompatible;
foundOne ← TRUE;
ENDLOOP;
};
ENDLOOP;
REPEAT
incompatible => NULL;
FINISHED => {
TerminalIO.PutRope["\n Compatible state assignments: "];
FOR stateIndex: INT IN StateRange DO
TerminalIO.PutF[" %g", IO.card[states[stateIndex]]];
ENDLOOP;
};
ENDLOOP;
REPEAT noneFound => TerminalIO.PutRope["\nNo compatible assignments"];
ENDLOOP;
};
A: PROC [a, b: INT] = {
adjacent[a][b] ← TRUE;
adjacent[b][a] ← TRUE;
};
FOR stateIndex: INT IN StateRange DO
FOR scanIndex: CARDINAL IN StateRange DO
adjacent[stateIndex][scanIndex] ← FALSE;
ENDLOOP;
ENDLOOP;
A[0, 1];
A[0, 2];
A[0, 5];
A[0, 3];
A[1, 2];
A[1, 5];
A[2, 3];
A[2, 5];
A[3, 4];
A[3, 6];
A[3, 7];
A[4, 5];
A[4, 6];
A[4, 7];
A[5, 6];
A[6, 7];
machine: BoolEx.Expression ← NIL;
resetTrue:  IO.ROPE  ← "Reset";
resetFalse:  IO.ROPE  ← "NOTReset";
resetFalseExpr: LIST OF REF ← LIST[BoolEx.OpNm[not], resetTrue];
resetFalseDef: LIST OF REF ← LIST[BoolEx.OpNm[var], resetFalse, resetFalseExpr];
machine ← CONS[resetFalseDef, machine];
machine ← CONS[BoolEx.OpNm[machine], CONS["SlipClock", machine]];
machine ← PLAOps.CompressExpression[machine, TRUE];
machine ← PLAOps.FactorExpression[machine];
END.