[Indigo]<Cedar>Top>ViewRec.DF=>VBug.Mesa
Last Edited by: Spreitzer, December 12, 1983 10:47 pm
DIRECTORY AMBridge, AMModel, AMModelBridge, AMTypes, Atom, EvalQuote, Buttons, Interpreter, IO, Menus, Rope, ViewerOps, ViewerTools, ViewRec, WorldVM;
VBug:
CEDAR
PROGRAM
IMPORTS AMBridge, AMModel, AMModelBridge, AMTypes, Atom, EvalQuote, Buttons, Interpreter, IO, Rope, ViewerOps, ViewerTools, ViewRec, WorldVM =
BEGIN
ROPE: TYPE = Rope.ROPE;
Viewer: TYPE = ViewRec.Viewer;
sep: ROPE ← ".";
Start:
PROC [ra:
REF
ANY, name:
ROPE ←
NIL] =
BEGIN
tv, rtv: AMTypes.TypedVariable;
rv: ViewRec.RecordViewer;
rep: ROPE;
TRUSTED {
tv ← AMBridge.TVForReferent[NEW [REF ANY ← ra]];
rtv ← AMBridge.TVForReferent[ra]};
IF name = NIL THEN [rep, name] ← Format[tv] ELSE [rep, ] ← Format[tv];
rv ← ViewRec.ViewTV[
agg: rtv,
createOptions: [doAllRecords: TRUE],
viewerInit: [iconic: FALSE, name: name],
paint: TRUE];
NoteName[rv, name];
END;
Frames:
PROC [name:
ROPE] =
TRUSTED
BEGIN
Found:
UNSAFE
PROC [c: AMModel.Context]
RETURNS [stop:
BOOL] =
BEGIN
gf: AMTypes.TypedVariable ← AMModelBridge.FrameFromContext[c];
rv: ViewRec.RecordViewer;
rv ← ViewRec.ViewTV[
agg: AMTypes.Globals[gf],
createOptions: [doAllRecords: TRUE],
viewerInit: [iconic: FALSE, name: name],
paint: TRUE];
NoteName[rv, name];
stop ← FALSE;
END;
[] ← AMModel.NamedContexts[context: AMModel.RootContext[WorldVM.LocalWorld[]], name: name, proc: Found];
END;
RecognizeAggRef: ViewRec.Recognizer
--PROC [t: Type, onlyRecognize: BOOLEAN, specs: BindingList, createOptions: CreateOptions] RETURNS [IKnowYou: BOOLEAN, handler: Handler, handlerData: REF ANY ← NIL]-- =
BEGIN
ut: AMTypes.Type ← t;
utc: AMTypes.Class ← AMTypes.TypeClass[ut];
IF utc = definition
THEN
utc ← AMTypes.TypeClass[ut ← AMTypes.UnderType[ut]];
SELECT utc
FROM
ref, list, pointer, longPointer => RETURN [TRUE, arHandler];
ENDCASE;
IKnowYou ← FALSE;
END;
arHandler: ViewRec.ComplexHandler ←
NEW [ViewRec.ComplexHandlerRep ← [
producer: ARProduce,
updater: ARUpdate]];
ARData: TYPE = REF ARDataRep;
ARDataRep:
TYPE =
RECORD [
name: ROPE,
tv: AMTypes.TypedVariable,
rv: ViewRec.RecordViewer];
ARProduce: ViewRec.ComplexProducer
--PROC [tv: TypedVariable, context: Context, handlerData: REF ANY] RETURNS [v: Viewer, clientData: REF ANY, sampleable: BOOLEAN ← TRUE]-- =
BEGIN
name: ROPE ← context.name.Cat[": ", Format[tv].rope];
ard: ARData ← NEW [ARDataRep ← [context.name, tv, context.for]];
v ← Buttons.Create[
info: [
parent: context.main,
name: name.Cat["1234567"],
border: FALSE],
proc: ARProc,
clientData: ard,
fork: FALSE,
paint: FALSE];
Buttons.ReLabel[button: v, newName: name, paint: FALSE];
clientData ← ard;
END;
ARUpdate: ViewRec.Updater
--PROC [tv: TypedVariable, v: Viewer, handlerData, clientData: REF ANY]-- =
BEGIN
ard: ARData ← NARROW[clientData];
label: ROPE ← ard.name.Cat[": ", Format[tv].rope];
Buttons.ReLabel[button: v, newName: label];
END;
ARProc: Menus.ClickProc
--PROC [parent: REF ANY, clientData: REF ANY ← NIL, mouseButton: MouseButton ← red, shift, control: BOOL ← FALSE]-- =
BEGIN
ard: ARData ← NARROW[clientData];
rtv: AMTypes.TypedVariable;
rut: AMTypes.Type;
rutc: AMTypes.Class;
ard.rv.DisplayMessage[ViewRec.clearMessagePlace];
IF NOT ViewRec.FinishPendingBusiness[] THEN RETURN;
IF control
THEN
BEGIN
ard.rv.DisplayMessage["Left Clicking this button creates a new Record Viewer on the referent of this address.
Middle Clicking evaluates the current Tioga selection, and assigns.
Right Clicking selects current value to be result of &FromVBug[].
Control clicking displays this message"];
RETURN;
END;
SELECT mouseButton
FROM
red =>
BEGIN
IF AMTypes.IsNil[ard.tv]
THEN
{ard.rv.DisplayMessage["Can't dereference NIL"]; RETURN};
IF
NOT (AMTypes.IsAtom[ard.tv]
OR AMTypes.IsRope[ard.tv])
THEN
BEGIN
rtv ← AMTypes.Referent[ard.tv];
rut ← AMTypes.TVType[rtv];
rutc ← AMTypes.TypeClass[rut];
IF rutc = definition THEN rutc ← AMTypes.TypeClass[rut ← AMTypes.UnderType[rut]];
SELECT rutc
FROM
record, structure, array, sequence =>
BEGIN
rep, name: ROPE;
rv: ViewRec.RecordViewer;
[rep, name] ← Format[ard.tv];
IF name =
NIL
THEN
BEGIN
IF (name ← GetName[ard.rv]).Length[] > 0
THEN
rep ← Rope.Cat[name ← name.Cat[".", ard.name], sep, rep];
END;
rv ← ViewRec.ViewTV[
agg: rtv,
createOptions: [doAllRecords: TRUE],
viewerInit: [iconic: FALSE, name: rep],
paint: TRUE];
NoteName[rv, name];
RETURN;
END;
ENDCASE;
END;
ard.rv.DisplayMessage["Not referencing an aggregate"];
END;
yellow =>
BEGIN
asRope: ROPE ← ViewerTools.GetSelectionContents[];
val: AMTypes.TypedVariable;
errMess: ROPE ← NIL;
noResult: BOOLEAN ← TRUE;
[val, errMess, noResult] ← Interpreter.Evaluate[asRope];
IF errMess.Length[] > 0 THEN ard.rv.DisplayMessage[errMess]
ELSE IF noResult THEN ard.rv.DisplayMessage["No result"]
ELSE AMTypes.Assign[ard.tv, val !AMTypes.Error => {
ard.rv.DisplayMessage["Assign failed"];
CONTINUE}];
END;
blue =>
BEGIN
toExec ← ard.tv;
UserExec.DoIt[" ← &FromVBug[]", exec];
END;
ENDCASE => ERROR;
END;
toExec: AMTypes.TypedVariable ← NIL;
Format:
PROC [tv: AMTypes.TypedVariable]
RETURNS [rope, name:
ROPE] =
TRUSTED {
name ← NIL;
IF AMTypes.IsNil[tv] THEN rope ← "NIL"
ELSE IF AMTypes.IsRope[tv]
THEN rope ← IO.PutFR["%g", IO.refAny[AMTypes.TVToName[tv]]]
ELSE
IF AMTypes.IsAtom[tv]
THEN rope ← IO.PutFR["%g", IO.refAny[AMBridge.TVToATOM[tv]]]
ELSE {
referent: AMTypes.TypedVariable ← AMTypes.Referent[tv];
SELECT AMTypes.TypeClass[AMTypes.UnderType[AMTypes.TVType[referent]]]
FROM
record, structure => name ← ViewRec.GetName[referent];
ENDCASE => name ← NIL;
rope ← IF name # NIL THEN Rope.Cat[name, sep] ELSE NIL;
rope ← rope.Concat[IO.PutFR["%b^", IO.card[AMBridge.TVToLC[tv]]]];
}
};
nameProp: ATOM ← Atom.MakeAtom["Mike Spreitzer December 12, 1983 10:45 pm"];
NoteName:
PROC [rv: ViewRec.RecordViewer, name:
ROPE] =
BEGIN
v: Viewer ← rv.RVQuaViewer[];
ViewerOps.AddProp[v, nameProp, name];
END;
GetName:
PROC [rv: ViewRec.RecordViewer]
RETURNS [name:
ROPE] =
BEGIN
v: Viewer ← rv.RVQuaViewer[];
name ← NARROW[ViewerOps.FetchProp[v, nameProp]];
END;
FromVBug: EvalQuote.EvalQuoteProc
--PROC [head: EvalHead, tree: Tree, target: Type ← nullType, data: REF ← NIL] RETURNS [return: TV]-- =
BEGIN
return ← toExec;
END;
Setup:
PROC =
BEGIN
ViewRec.RegisterRecognizerByType[RecognizeAggRef, Back, CODE[REF BOOL], TypeClass];
ViewRec.RegisterRecognizerByType[RecognizeAggRef, Back, CODE[POINTER TO BOOL], TypeClass];
ViewRec.RegisterRecognizerByType[RecognizeAggRef, Back, CODE[LONG POINTER TO BOOL], TypeClass];
ViewRec.RegisterRecognizerByType[RecognizeAggRef, Back, CODE[LIST OF CARDINAL], TypeClass];
EvalQuote.Register[name: "&FromVBug", proc: FromVBug, symTab: NIL];
END;
Setup[];
END.