PipalMutateImpl.mesa 
Copyright Ó 1988 by Xerox Corporation. All rights reserved.
Bertrand Serlet May 12, 1988 10:30:27 pm PDT
Louis Monier January 29, 1988 9:10:26 pm PST
Barth, January 29, 1988 6:24:02 pm PST
DIRECTORY IO, Pipal, PipalInt, PipalMutate, PipalOps, RefTab, TerminalIO;
PipalMutateImpl: CEDAR MONITOR
IMPORTS IO, Pipal, PipalOps, RefTab, TerminalIO
EXPORTS PipalMutate =
BEGIN OPEN PipalMutate;
Mutation Method
mutationMethod: PUBLIC Pipal.Method ← Pipal.RegisterMethod["Mutation"];
HasMutationProc: PUBLIC PROC [object: Pipal.Object] RETURNS [BOOL] = {
RETURN [Pipal.ObjectMethod[object, mutationMethod]#NIL];
};
Mutation: PUBLIC MutationProc = {
mutant ← (NARROW [Pipal.ObjectMethod[object, mutationMethod], REF MutationProc]^)[object];
};
RecursiveEnumerateMutantChildren: PROC [root: Pipal.Object, each: EachChildProc, initialPath: PipalOps.Path] RETURNS [path: PipalOps.Path, quit: BOOLFALSE] = {
count: NAT ← 0;
EachChild: PipalOps.EachChildProc = {
[path, quit] ← RecursiveEnumerateMutantChildren[child, each, PipalOps.ExtendPath[initialPath, ops, count]];
count ← count+1;
};
path ← initialPath;
IF HasMutationProc[root] THEN RETURN [path, each[path, root]];
IF NOT PipalOps.HasEnumerate[root] THEN RETURN;
quit ← PipalOps.Enumerate[root, EachChild];
};
EnumerateMutantChildren: PUBLIC PROC [root: Pipal.Object, each: EachChildProc] RETURNS [quit: BOOLFALSE] = {
quit ← RecursiveEnumerateMutantChildren[root, each, NIL].quit;
};
Pop Event
popEvent: PUBLIC ATOM ← $Pop;
BroadcastPop: PUBLIC PROC [mutant: Pipal.Object] = {
PipalOps.Broadcast[popEvent, mutant, mutant.object];
};
Commands
commandTableMethod: Pipal.Method = Pipal.RegisterMethod["CommandTable"];
For a given mutant this table maps the name of the command to a CommandData record.
CommandData: TYPE = REF CommandDataRec;
CommandDataRec: TYPE = RECORD [command: CommandProc, registrationData: REFNIL];
RegisterCommand: PUBLIC ENTRY PROC [class: Pipal.Class, name: ATOM, command: CommandProc, registrationData: REFNIL] = {
commandData: CommandData ← NEW [CommandDataRec ← [command, registrationData]];
commandTable: RefTab.Ref ← NARROW [Pipal.GetClassMethod[class, commandTableMethod]];
IF commandTable=NIL THEN {
commandTable ← RefTab.Create[];
Pipal.PutClassMethod[class, commandTableMethod, commandTable];
};
IF NOT RefTab.Store[commandTable, name, commandData] THEN TerminalIO.PutF["*** Command %g for mutant %g overwritten.\n", IO.atom[name], IO.rope[Pipal.ClassName[class]]];
};
FetchCommand: PUBLIC PROC [mutant: Pipal.Object, name: ATOM] RETURNS [command: CommandProc ← NIL, registrationData: REFNIL] = {
commandData: CommandData;
commandTable: RefTab.Ref ← NARROW [Pipal.ObjectMethod[mutant, commandTableMethod]];
commandData ← NARROW [RefTab.Fetch[commandTable, name].val];
IF commandData=NIL
THEN RETURN
ELSE RETURN [commandData.command, commandData.registrationData];
};
ApplyCommand: PUBLIC PROC [mutant: Pipal.Object, name: ATOM, arguments: LIST OF REFNIL, issuer: REFNIL] RETURNS [resultType: ResultType ← none, result: Pipal.Object ← NIL, new: Pipal.Object] = {
command: CommandProc;
registrationData: REF;
[command, registrationData] ← FetchCommand[mutant, name];
[resultType, result, new] ← command[mutant, name, arguments, issuer, registrationData];
};
END.