RoseDebug.mesa
Copyright © 1985 by Xerox Corporation. All rights reversed.
Barth, August 1, 1985 2:31:39 pm PDT
Spreitzer, October 1, 1985 6:08:24 pm PDT
DIRECTORY Core, CoreFlatten, CoreProperties, IO, PrincOps, PrincOpsUtils, Rope, RoseBehavior, RoseBind, RoseControl, RoseEvents, RosePrivates, RoseSimTypes, RoseWireTwiddling, RoseWireTypes, RoseWiring, StructuredStreams, UnparserBuffer, ViewerIO;
RoseDebug: CEDAR PROGRAM
IMPORTS CoreFlatten, CoreProperties, IO, Rope, RoseEvents, RoseSimTypes, StructuredStreams, UnparserBuffer, ViewerIO
=
BEGIN OPEN RoseWireTypes, RoseSimTypes;
log: IO.STREAM;
driveName: ARRAY Drive OF ROPE = [
test: "test",
see: "see",
none: "none",
chargeWeak: "chargeWeak",
chargeMediumWeak: "chargeMediumWeak",
charge: "charge",
chargeMediumStrong: "chargeMediumStrong",
chargeStrong: "chargeStrong",
chargeVeryStrong: "chargeVeryStrong",
driveWeak: "driveWeak",
driveMediumWeak: "driveMediumWeak",
drive: "drive",
driveMediumStrong: "driveMediumStrong",
driveStrong: "driveStrong",
driveVeryStrong: "driveVeryStrong",
input: "input"
];
NoteAny: PROC [event: ATOM, watched, watcherData, arg: REF ANY] = {
WriteWatched: PROC = {
WITH watched SELECT FROM
rci: RoseCellInstance => log.PutRope[LongName[rci]];
rw: RoseWire => log.PutRope[LongName[rw]];
sim: Simulation => log.PutRope["a simulation"];
ENDCASE => log.Put[ [refAny[watched]] ];
log.PutF[", "];
};
WriteArg: PROC = {ReallyWriteArg[arg]};
log.PutF["%g[", [atom[event]] ];
WritePiece[log, WriteWatched];
WritePiece[log, WriteArg];
log.PutRope["]\n"];
};
NoteSchedule: PROC [event: ATOM, watched, watcherData, arg: REF ANY] = {
WriteWatched: PROC = {
rci: RoseCellInstance = NARROW[watched];
sch: Scheduling = rci.schIn;
log.PutRope[LongName[rci]];
SELECT TRUE FROM
rci.schedNext = notInCellList => log.PutRope[" not in schedule"];
rci = sch.schedFirst => log.PutRope[" at head of schedule"];
ENDCASE => log.PutRope[" somwhere in schedule"];
log.PutF[", "];
};
WriteArg: PROC = {ReallyWriteArg[arg]};
log.PutF["%g[", [atom[event]] ];
WritePiece[log, WriteWatched];
WritePiece[log, WriteArg];
log.PutRope["]\n"];
};
NoteChange: PROC [event: ATOM, watched, watcherData, arg: REF ANY] = {
rw: RoseWire = NARROW[watched];
fmt: Format = rw.type.class.super.GetFormat[rw.type, NIL];
WriteWatched: PROC = {
log.PutRope[LongName[rw]];
log.PutRope[" "];
};
WriteVal: PROC = {
val: ROPE = fmt.FormatValue[rw.type, fmt, rw.valPtr];
log.PutRope["← "];
log.PutRope[val];
log.PutRope[" ("];
log.PutRope[driveName[rw.winnerStrength]];
log.PutRope[") "];
};
WriteArg: PROC = {ReallyWriteArg[arg]};
log.PutF["%g[", [atom[event]] ];
WritePiece[log, WriteWatched];
WritePiece[log, WriteVal];
WritePiece[log, WriteArg];
log.PutRope["]\n"];
};
ReallyWriteArg: PROC [arg: REF ANY] = {
IF arg = NIL THEN RETURN;
WITH arg SELECT FROM
rms: REF ModelSlot => {
IF rms^ = nilModelSlot
THEN log.PutRope["nilModelSlot"]
ELSE log.PutF[
"ModelSlot[%g, %g]",
[rope[LongName[rms.cell]]],
[refAny[rms.portPath]]
];
};
ENDCASE => log.Put[ [refAny[arg]] ];
};
WritePiece: PROC [to: IO.STREAM, write: PROC] = {
StructuredStreams.Bp[to, FALSE, 3];
StructuredStreams.Begin[to];
write[ !UNWIND => StructuredStreams.End[to] ];
StructuredStreams.End[to];
};
LongName: PROC [ra: REF ANY] RETURNS [name: ROPE] = {
IF ra = NIL THEN RETURN ["NIL"];
WITH ra SELECT FROM
rw: RoseWire => name ← LongName[rw.core];
cw: Core.Wire => {
ws: CoreFlatten.WireSource = NARROW [CoreProperties.GetProp [cw.properties, CoreFlatten.wireSource] ];
prefix: ROPE = LongName[ws.instantiationPath];
name ← ws.wire.name;
IF ws.instance # NIL THEN name ← NameCat[ws.instance.name, name];
name ← NameCat[prefix, name];
};
ip: CoreFlatten.InstantiationPath => {
IF ip = NIL THEN name ← NIL ELSE {
name ← ip.first.name;
FOR ip ← ip.rest, ip.rest WHILE ip # NIL DO
name ← NameCat[ip.first.name, name];
ENDLOOP;
name ← name;
};
};
rci: RoseCellInstance => name ← LongName[rci.core];
ci: CellInstance => {
is: CoreFlatten.InstanceSource = NARROW [CoreProperties.GetProp [ci.properties, CoreFlatten.instanceSource] ];
name ← NIL;
IF is.instantiationPath # NIL THEN name ← LongName[is.instantiationPath];
name ← NameCat[name, is.instance.name];
};
ENDCASE => ERROR;
};
NameCat: PROC [n1, n2: ROPE] RETURNS [n: ROPE] = {
IF n1.Length[] = 0 THEN RETURN [n2];
n ← n1.Cat[".", n2];
};
Start: PROC = {
ubh: UnparserBuffer.Handle ← UnparserBuffer.NewHandle[
[stream[ViewerIO.CreateViewerStreams["Rosemary Debug log"].out]]
];
ubh.margin ← 70;
log ← StructuredStreams.Create[ubh];
RoseEvents.AddWatcher[$Settled, [NoteAny], RoseEvents.all];
RoseEvents.AddWatcher[$Eval, [NoteAny], RoseEvents.all];
RoseEvents.AddWatcher[$Schedule, [NoteSchedule], RoseEvents.all];
RoseEvents.AddWatcher[$Found, [NoteAny], RoseEvents.all];
RoseEvents.AddWatcher[$NewNodeQ, [NoteChange], RoseEvents.all];
RoseEvents.AddWatcher[$NewNodeUD, [NoteChange], RoseEvents.all];
RoseEvents.AddWatcher[$Perturbed, [NoteAny], RoseEvents.all];
RoseEvents.AddWatcher[$ChangeEarly, [NoteChange], RoseEvents.all];
};
Start[];
END.