DragonRosemaryImpl.mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Auxiliary functions for Dragon Rosemary simulations
last edited by E. McCreight, March 31, 1986 3:16:42 pm PST
last edited by Curry, September 8, 1985 7:12:34 pm PDT
DragonRosemaryImpl:
CEDAR
PROGRAM
IMPORTS AMBridge, AMTypes, Commander,
IO, Rope
EXPORTS DragonRosemary =
BEGIN
Assert:
PUBLIC
PROC [ condition:
BOOL, message: Rope.
ROPE ←
NIL ] =
{IF NOT condition THEN SIGNAL AssertionFailed[message]};
AssertionFailed:
PUBLIC
SIGNAL [ message: Rope.
ROPE ] =
CODE;
OpName: PUBLIC ARRAY Dragon.Opcode OF Rope.ROPE = GenOpNames[];
OpLength:
PUBLIC
PROC [ op: Dragon.Opcode ]
RETURNS [ length: [0..5] ] =
{RETURN[instructionLengths[op/16]]};
instructionLengths:
ARRAY [0..16)
OF [0..5] = [
-- see /Indigo/Dragon/Doc/DragOps
1, 1, -- [ 0.. 1]
5, 5, -- [ 2.. 3]
1, 1, 1, 1, -- [ 4.. 7]
2, 2, 2, 2, -- [ 8..11]
3, 3, 3, 3 -- [12..15]
];
OneOf:
PUBLIC
PROC [ a, b, c, d, e, f, g, h, i, j:
BOOL ←
FALSE ]
RETURNS[
BOOL ] =
{RETURN[Count[a,b,c,d,e,f,g,h,i,j]=1]};
MoreThanOneOf:
PUBLIC
PROC [ a, b, c, d, e, f, g, h, i, j:
BOOL ←
FALSE ]
RETURNS[
BOOL ] =
{RETURN[Count[a,b,c,d,e,f,g,h,i,j]>1]};
Count:
PUBLIC
PROC [ a, b, c, d, e, f, g, h, i, j:
BOOL ←
FALSE ]
RETURNS[
NAT ] = {
RETURN[
(IF a THEN 1 ELSE 0) +
(IF b THEN 1 ELSE 0) +
(IF c THEN 1 ELSE 0) +
(IF d THEN 1 ELSE 0) +
(IF e THEN 1 ELSE 0) +
(IF f THEN 1 ELSE 0) +
(IF g THEN 1 ELSE 0) +
(IF h THEN 1 ELSE 0) +
(IF i THEN 1 ELSE 0) +
(IF j THEN 1 ELSE 0) ]};
GenOpNames:
PUBLIC
PROC
RETURNS[names:
ARRAY Dragon.Opcode
OF Rope.
ROPE] =
TRUSTED{
instRef: REF DragOpsCross.Inst ← NEW[DragOpsCross.Inst];
tv: AMTypes.TV ← AMBridge.TVForReferent[instRef];
type: AMTypes.Type ← AMTypes.UnderType[AMTypes.TVType[tv]];
FOR tv: AMTypes.
TV ← AMTypes.First[type], AMTypes.Next[tv]
WHILE tv#
NIL
DO
card: CARDINAL ← AMBridge.TVToCardinal[tv];
op: Dragon.Opcode ← card MOD 256;
IF op # card THEN ERROR;
names[op] ← NIL;
names[op] ← AMTypes.TVToName[tv ! AMTypes.Error => CONTINUE];
IF names[op] =
NIL
THEN
names[op] ← IO.PutFR["dxop%02", [cardinal[op]]]; -- remove H at end
names[op] ← Rope.Substr[names[op],1];
ENDLOOP };
DragonCmdProc:
PROC [cmd: Commander.Handle]
RETURNS [result:
REF ←
NIL, msg: Rope.
ROPE ←
NIL]
-- Commander.CommandProc -- =
{NULL};
Commander.Register["Dragon", DragonCmdProc];
END.