FILE: ViewRecSample.Mesa
last edited by Spreitzer November 12, 1983 1:57 pm
DIRECTORY
AMTypes, BasicTime, Process, Real, ViewRec, ViewRecInsides;
ViewRecSample: CEDAR MONITOR
IMPORTS AMTypes, BasicTime, Process, Real, ViewRecInsides
EXPORTS ViewRec, ViewRecInsides =
BEGIN OPEN ViewRecInsides;
behavior: PUBLIC ViewRec.BehaviorOptions ← [];
delayed: PUBLIC REAL ← 0;
z: PUBLIC REAL ← 0;
roots: PUBLIC DataList ← NIL;
activeCount, extantCount, eltCount: CARDINAL ← 0;
SetBehavior: PUBLIC PROC [newBehavior: ViewRec.BehaviorOptions ← []] =
{behavior ← newBehavior};
Sample: PROCEDURE =
BEGIN
oldPriority: ViewRec.DelayPriority ← behavior.delayParms.priority;
TRUSTED {Process.SetPriority[DPToP[oldPriority]]};
WHILE TRUE DO
parm: REAL;
asCard: CARDINAL;
start: BasicTime.Pulses ← BasicTime.GetClockPulses[];
last: DataList ← NIL;
IF behavior.delayParms.priority # oldPriority THEN TRUSTED {Process.SetPriority[DPToP[oldPriority ← behavior.delayParms.priority]]};
activeCount ← extantCount ← eltCount ← 0;
FOR r: DataList ← roots, r.rest WHILE r # NIL DO
IF r.first.v.destroyed THEN
BEGIN
IF last # NIL THEN last.rest ← r.rest ELSE roots ← r.rest;
END
ELSE
BEGIN
SampleData[r.first];
last ← r;
END;
ENDLOOP;
BEGIN OPEN behavior.delayParms;
parm ← MIN[max, MAX[min,
offset + dActive * activeCount + dExtant * extantCount +
dElt * eltCount + dMicroseconds * BasicTime.PulsesToMicroseconds[BasicTime.GetClockPulses[] - start] ]];
END;
IF (z > 0) AND (z < 1) THEN
delayed ← (parm*(1-z) + delayed*z)
ELSE delayed ← parm;
asCard ← Real.RoundC[ABS[parm]];
Process.Pause[Process.MsecToTicks[asCard]]
ENDLOOP;
END;
DPToP: PROC [dp: ViewRec.DelayPriority] RETURNS [Process.Priority] = INLINE
{RETURN [SELECT dp FROM
Normal => Process.priorityNormal,
Background => Process.priorityBackground,
Foreground => Process.priorityForeground,
ENDCASE => ERROR]};
RedisplayElt: PUBLIC PROC [eh: REF ANY] =
BEGIN
ed: EltData ← NARROW[eh];
IF ed.update # NIL THEN ed.update[ed, TRUE];
END;
SampleData: PUBLIC PROC [d: Data] =
BEGIN
IF d.v.destroyed OR d.v.iconic THEN {extantCount ← extantCount + 1; RETURN};
activeCount ← activeCount + 1;
FOR ed: EltData ← d.last, ed.prev WHILE ed # NIL DO
IF ed.update # NIL THEN {eltCount ← eltCount + 1; ed.update[ed, FALSE]};
ENDLOOP;
END;
SampleRV: PUBLIC PROC [rv: RecordViewer] =
{SampleData[RVToData[rv]]};
OKProc: PUBLIC PROC [pt: Type, argSpecs, retSpecs: BindingList, createOptions: CreateOptions] RETURNS [ok, hasDom, hasRange: BOOLEAN] =
BEGIN
dom: Type ← AMTypes.Domain[pt];
range: Type ← AMTypes.Range[pt];
domArgs, rangeArgs: CARDINAL;
SELECT AMTypes.TypeClass[dom] FROM
structure, record => [ok, domArgs] ←
SimpleEnough[dom, argSpecs, createOptions];
nil => {ok ← TRUE; domArgs ← 0};
ENDCASE => ok ← FALSE;
IF NOT ok THEN RETURN [FALSE, FALSE, FALSE];
SELECT AMTypes.TypeClass[range] FROM
structure, record => [ok, rangeArgs] ←
SimpleEnough[range, retSpecs, createOptions];
nil => {ok ← TRUE; rangeArgs ← 0};
ENDCASE => ok ← FALSE;
IF NOT ok THEN RETURN [FALSE, FALSE, FALSE];
RETURN [ok, domArgs > 0, rangeArgs > 0];
END;
SimpleEnough: PUBLIC PROC [rt: Type, specs: BindingList, createOptions: CreateOptions] RETURNS [ok: BOOLEAN, count: CARDINAL] =
BEGIN
len: CARDINAL;
tc: AMTypes.Class ← AMTypes.TypeClass[rt];
count ← 0;
SELECT tc FROM
record, structure => len ← AMTypes.NComponents[rt];
sequence, array => len ← 1;
ENDCASE => ERROR NotAnAggregate;
FOR i: CARDINAL IN [1 .. len] DO
tt, t: Type;
val: TypedVariable;
sublist: BindingList;
ok, visible: BOOLEAN;
recers: RList;
name: ROPE;
SELECT tc FROM
record, structure => BEGIN
tt ← AMTypes.IndexToType[rt, i];
name ← AMTypes.IndexToName[rt, i];
END;
sequence, array => BEGIN
tt ← AMTypes.Range[rt];
name ← NIL;
END;
ENDCASE => ERROR;
t ← AMTypes.GroundStar[tt];
[sublist, ,val, ok, visible, , , , recers] ← SelectBindings[specs, name, i];
count ← count + 1;
IF ok AND NOT visible THEN count ← count - 1
ELSE BEGIN
exception: BOOLEANFALSE;
IF Recognize[t: t, specials: recers, onlyRecognize: TRUE, specs: sublist, createOptions: createOptions].recognized THEN ok ← TRUE
ELSE ok ← FALSE;
IF createOptions.doAllRecords THEN
{IF exception OR NOT ok THEN count ← count - 1}
ELSE IF NOT ok THEN RETURN [FALSE, 0]
ELSE IF exception THEN count ← count - 1;
END;
ENDLOOP;
ok ← TRUE;
END;
Setup: PROC =
BEGIN
TRUSTED {Process.Detach[FORK Sample[]]};
END;
Setup[];
END.