RoseDeciders.Mesa
Last Edited by: Spreitzer, September 6, 1984 3:32:28 pm PDT
Last Edited by: Gasbarro, August 16, 1984 4:53:51 pm PDT
DIRECTORY AssertingIO, Atom, Convert, FS, IO, MessageWindow, OrderedSymbolTableRef, Pausers, Rope, RoseCreate, RoseTypes, ViewerOps, ViewRec;
RoseDeciders:
CEDAR
PROGRAM
IMPORTS AssertingIO, Atom, Convert, FS, IO, MessageWindow, OrderedSymbolTableRef, Pausers, Rope, RoseCreate, RoseTypes, ViewerOps, ViewRec
EXPORTS RoseCreate =
BEGIN OPEN RoseCreate, RoseTypes;
Name: TYPE = LIST OF ROPE;
LORA: TYPE = LIST OF REF ANY;
ExpandDecisionRef: TYPE = REF ExpandDecision;
decisionProp: ATOM ← Atom.MakeAtom["Spreitzer January 6, 1984 8:33 pm"];
ExpandQuery: TYPE = REF ExpandQueryRep;
ExpandQueryRep:
TYPE =
RECORD [
instanceName, typeName: ROPE ← NIL,
whatToDo: ExpandDecision ← Nested];
qp: Pausers.Pauser ← NIL;
eq: ExpandQuery ← NEW [ExpandQueryRep ← []];
qerv: ViewRec.RecordViewer;
qv: ViewRec.Viewer ← NIL;
AssertionsFromFile:
PUBLIC
PROC [fileName:
ROPE]
RETURNS [assertions: Assertions] =
BEGIN
from: STREAM ← FS.StreamOpen[fileName];
assertions ← AssertingIO.Read[from];
list: LORA ← NARROW[from.GetRefAny[]];
assertions ← NIL;
FOR list ← list, list.rest WHILE list # NIL DO
assertion: LORA ← NARROW[list.first];
assertions ← CONS[assertion, assertions];
ENDLOOP;
from.Close[];
END;
LookupCell:
PUBLIC
PROC [path:
LIST
OF
REF
ANY, from: Cell ←
NIL]
RETURNS [cell: Cell] =
BEGIN
sofar: LIST OF ROPE ← NIL;
cell ← from;
WHILE path #
NIL
DO
link:
ROPE ←
WITH path.first
SELECT
FROM
r: ROPE => r,
rt: REF TEXT => Rope.FromRefText[rt],
ENDCASE => ERROR;
next: Cell ← NARROW[(IF cell = NIL THEN roots ELSE cell.components). Lookup[link]];
IF next =
NIL
THEN
{SIGNAL Warning[IO.PutFR["Not found: %g %g %g", IO.refAny[sofar], IO.rope[Convert.RopeFromRope[link]], IO.refAny[path.rest]]]; RETURN [NIL]};
sofar ← CONS[link, sofar];
path ← path.rest;
cell ← next;
ENDLOOP;
END;
LookupNode:
PUBLIC
PROC [path:
LIST
OF
REF
ANY, from: Cell ←
NIL]
RETURNS [node: Node] =
BEGIN
sofar: LIST OF ROPE ← NIL;
cell: Cell ← from;
WHILE path #
NIL
DO
link:
ROPE ←
WITH path.first
SELECT
FROM
r: ROPE => r,
rt: REF TEXT => Rope.FromRefText[rt],
ENDCASE => ERROR;
next: Cell;
IF path.rest = NIL THEN RETURN [LookupCellNode[cell, link]];
next ← NARROW[(IF cell = NIL THEN roots ELSE cell.components). Lookup[link]];
IF next =
NIL
THEN
{SIGNAL Warning[IO.PutFR["Not found: %g %g %g", IO.refAny[sofar], IO.rope[Convert.RopeFromRope[link]], IO.refAny[path.rest]]]; RETURN [NIL]};
sofar ← CONS[link, sofar];
path ← path.rest;
cell ← next;
ENDLOOP;
ERROR;
END;
LookupCellNode:
PUBLIC
PROC [cell: Cell, name:
ROPE]
RETURNS [node: Node] =
BEGIN
index: CARDINAL;
IF (node ← NARROW[cell.internalNodes.Lookup[name]]) # NIL THEN RETURN [node];
IF (index ← GetIndex[cell.type.ports, name]) # notFound THEN RETURN [cell.interfaceNodes[index]];
node ← NIL;
END;
LongNodeName:
PUBLIC
PROC [n: Node]
RETURNS [name:
ROPE] =
{name ← LongCellName[n.cellIn].Cat[".", n.name]};
LongCellName:
PUBLIC
PROC [c: Cell]
RETURNS [name:
ROPE] = {
name ← c.name;
FOR c ← c.parent, c.parent
WHILE c #
NIL
DO
name ← c.name.Cat[".", name]
ENDLOOP};
DecideFromFile:
PUBLIC
PROC [fileName:
ROPE]
RETURNS [dff: ExpandDeciderClosure] =
BEGIN
file: IO.STREAM ← NIL;
top: LORA;
file ← FS.StreamOpen[fileName: fileName];
top ← LIST[NIL, NIL, IO.GetRefAny[file]];
file.Close[];
dff ← NEW [ExpandDeciderClosureRep ← [Decide: DecideByName, otherData: top]];
END;
Ask: ExpandDecider
--PROC [cell: Cell, otherData: REF ANY] RETURNS [ExpandDecision]-- =
BEGIN
first: BOOLEAN ← TRUE;
eq.instanceName ← cell.name;
eq.typeName ← cell.type.name;
IF qv # NIL AND qv.iconic THEN ViewerOps.OpenIcon[qv];
WHILE first OR NOT Possible[cell, eq.whatToDo] DO qp.Pause[]; first ← FALSE ENDLOOP;
RETURN [eq.whatToDo];
END;
DecideByName: ExpandDecider =
BEGIN
Yelp:
PROC [problem:
ROPE]
RETURNS [ExpandDecision] =
TRUSTED
BEGIN
RETURN [Ask[cell, problem]];
END;
decisionsByName: LORA ← NARROW[otherData];
name: Name ← GetName[cell];
descr: LORA ← GetDescr[name, decisionsByName];
decAt: ATOM;
asAny: REF ANY;
IF descr = NIL THEN RETURN [Yelp["no decision given"]];
IF descr.rest =
NIL
THEN
BEGIN
IF Possible[cell, Leaf] THEN RETURN [Leaf];
RETURN [Yelp["cant make it a Leaf"]];
END;
IF NOT ISTYPE[descr.rest.first, ATOM] THEN RETURN [Yelp["decision not an Atom"]];
IF (asAny ← Atom.GetProp[atom: (decAt ← NARROW[descr.rest.first]), prop: decisionProp]) = NIL THEN RETURN [Yelp["atom not a decision"]];
IF (IF asAny = NIL THEN TRUE ELSE NOT ISTYPE[asAny, ExpandDecisionRef]) THEN RETURN [Yelp["atom not a decision"]];
RETURN [NARROW[asAny, ExpandDecisionRef]^];
END;
GetName:
PROC [cell: Cell]
RETURNS [name: Name] =
BEGIN
name ← NIL;
WHILE cell #
NIL
DO
name ← CONS[cell.name, name];
cell ← cell.parent;
ENDLOOP;
END;
GetDescr:
PROC [name: Name, dbn:
LORA]
RETURNS [
LORA] =
BEGIN
Matches:
PROC [name:
ROPE, asAny:
REF
ANY]
RETURNS [
BOOLEAN] =
BEGIN
dbn: LORA;
s2: ROPE;
IF
NOT
ISTYPE[asAny,
LORA]
THEN
TRUSTED
BEGIN
MessageWindow.Append[message: "Ill formed decisions!", clearFirst: TRUE];
RETURN [FALSE];
END;
dbn ← NARROW[asAny];
IF (
IF dbn =
NIL
THEN
TRUE
ELSE (
IF dbn.first =
NIL
THEN
TRUE
ELSE (
NOT
ISTYPE[dbn.first,
ROPE]
AND
NOT
ISTYPE[dbn.first,
ATOM])))
THEN
TRUSTED
BEGIN
MessageWindow.Append[message: "Ill formed decisions!", clearFirst: TRUE];
RETURN [FALSE];
END;
s2 ←
WITH dbn.first
SELECT
FROM
r: ROPE => r,
a: ATOM => Atom.GetPName[a],
ENDCASE => ERROR;
RETURN [Rope.Equal[s1: name, s2: s2, case: FALSE]];
END;
WHILE name #
NIL
DO
tail: LORA;
IF (
IF dbn =
NIL
THEN
TRUE
ELSE dbn.rest =
NIL)
THEN
TRUSTED
BEGIN
MessageWindow.Append[message: "Ill formed decisions!", clearFirst: TRUE];
RETURN [NIL];
END;
FOR tail ← dbn.rest.rest, tail.rest
WHILE tail #
NIL
DO
IF Matches[name.first, tail.first] THEN EXIT;
ENDLOOP;
IF tail =
NIL
THEN
TRUSTED
BEGIN
MessageWindow.Append[message: "No decsion", clearFirst: TRUE];
RETURN [NIL];
END;
name ← name.rest;
dbn ← NARROW[tail.first];
ENDLOOP;
RETURN [dbn];
END;
MakeQueryPauser: ViewRec.OtherStuffProc =
BEGIN
v: ViewRec.Viewer;
[qp, v] ← Pausers.CreatePauser[enabledName: "Answer Query", disabledName: "", viewerInit: [parent: in, border: FALSE], paint: FALSE];
RETURN [LIST[v]];
END;
Setup:
PROC =
BEGIN
Atom.PutProp[atom: $N, prop: decisionProp, val: NEW [ExpandDecision ← Nested]];
Atom.PutProp[atom: $I, prop: decisionProp, val: NEW [ExpandDecision ← Inline]];
Atom.PutProp[atom: $L, prop: decisionProp, val: NEW [ExpandDecision ← Leaf]];
qerv ← ViewRec.ViewRef[
agg: eq,
otherStuff: MakeQueryPauser,
viewerInit: [iconic: TRUE, column: right, name: "ExpandQuery"]];
qv ← qerv.RVQuaViewer[];
END;
Setup[];
END.