DIRECTORY AMBridge, AMTypes, Atom, Buttons, Cucumber, Pausers, ViewerClasses, ViewRec, FileIO, IO, MessageWindow, OrderedSymbolTableRef, Rope, Rosemary, RosemaryExtras, RoseHelp; RoseHelpImpl: CEDAR PROGRAM IMPORTS AMBridge, AMTypes, Atom, --Buttons,-- Cucumber, MessageWindow, OrderedSymbolTableRef, Pausers, Rope, FIO: FileIO, IO, ViewRec, Rosemary, RosemaryExtras EXPORTS RoseHelp = BEGIN OPEN Rosemary, RosemaryExtras; NoHelpForAnything: PUBLIC ERROR = CODE; LORA: TYPE = LIST OF REF ANY; Viewer: TYPE = ViewerClasses.Viewer; Type: TYPE = AMTypes.Type; TypedVariable: TYPE = AMTypes.TypedVariable; Name: TYPE = LIST OF ROPE; StartData: TYPE = REF StartDataRep; StartDataRep: TYPE = RECORD [ instanceName: ROPE, class: CellClass, initData: REF ANY _ NIL]; InitData: TYPE = REF InitDataRep; InitDataRep: TYPE = RECORD [ name: ROPE, ioTemplate: REF ANY]; ProviderData: TYPE = REF ProviderDataRep; ProviderDataRep: TYPE = RECORD [ cell: Cell, pauser: Pausers.Pauser _ NIL, armed: BOOLEAN _ FALSE]; ExpandQuery: TYPE = REF ExpandQueryRep; ExpandQueryRep: TYPE = RECORD [ instanceName, className: ROPE _ NIL, whatToDo: Rosemary.ExpandDecision _ Nested]; providerHandler: Cucumber.Handler _ NEW [Cucumber.HandlerRep _ [ PartTransfer: TransferProvider]]; qp: Pausers.Pauser _ NIL; eq: ExpandQuery _ NEW [ExpandQueryRep _ []]; ask: PUBLIC Rosemary.ExpandDeciderClosure _ NEW [Rosemary.ExpandDeciderClosureRep _ [ Decide: Ask, otherData: NIL]]; decisionProp: ATOM _ Atom.Gensym[]; TransferProvider: Cucumber.PartTransferProc = {}; GiveItAnything: PUBLIC PROC [topInstanceName, instanceName, className: ROPE, initData: REF ANY _ NIL, decider: ExpandDeciderClosure] RETURNS [topCell: Cell] = BEGIN sd: StartData _ NEW [StartDataRep _ [ instanceName: instanceName, class: NIL, initData: initData]]; sd.class _ NARROW[cellClasses.Lookup[className]]; IF sd.class = NIL THEN ERROR Error[IO.PutFR["No such class (%g)", IO.rope[className]]]; topCell _ CreateTopCell[instanceName: topInstanceName, className: "GiveItAnything", initData: sd, decider: decider]; END; ExpandAnything: ExpandProc = BEGIN sd: StartData _ NARROW[initData]; usersCell: Cell; providerClassName: ROPE; ioTemplate: REF ANY _ NIL; usersInterface: ROPE _ NIL; FOR index: CARDINAL IN [0 .. sd.class.ports.length) DO name: ROPE _ sd.class.ports[index].name; step: ROPE _ name.Cat[": ", name]; [] _ CreateNode[within: thisCell, name: name, type: sd.class.ports[index].type]; usersInterface _ IF usersInterface = NIL THEN step ELSE usersInterface.Cat[", ", step]; ENDLOOP; providerClassName _ GetProvider[sd.class]; usersCell _ CreateCell[within: thisCell, instanceName: sd.instanceName, className: sd.class.name, interfaceNodes: usersInterface, initData: sd.initData]; ioTemplate _ SELECT usersCell.type FROM Real => usersCell.realCellStuff.newIO, Shadow => sd.class.ioTemplate, ENDCASE => ERROR; IF ioTemplate = Unspecified THEN ERROR NoHelpForAnything; [] _ CreateCell[within: thisCell, instanceName: sd.instanceName.Concat["-provider"], className: providerClassName, interfaceNodes: usersInterface, initData: NEW [InitDataRep _ [name: sd.instanceName.Concat["-provider"], ioTemplate: ioTemplate]] ]; END; GetProvider: PROC [for: CellClass] RETURNS [providerName: ROPE] = BEGIN provider: CellClass; providerName _ for.name.Concat["-provider"]; IF (provider _ NARROW[cellClasses.Lookup[providerName]]) = NIL THEN BEGIN RegisterCellClass[className: providerName, expandProc: NIL, ioCreator: CreateProviderIO, initializer: InitializeProvider, evalProc: EvalProvider, ports: MirrorPorts[for.ports]]; END; END; --no longer needed (and thus commented out):-- InitializeProvider: Initializer = BEGIN --no longer needed (and thus commented out):-- pd: ProviderData _ NEW [ProviderDataRep _ [cell: cell]]; --no longer needed (and thus commented out):-- cell.realCellStuff.state _ pd; END; CreateProviderIO: IOCreator = BEGIN id: InitData _ NARROW[initData]; IF id.ioTemplate # NIL THEN --beg in-- TRUSTED --end in-- BEGIN usersIOAsTV: TypedVariable _ AMBridge.TVForReferent[id.ioTemplate]; ioType: Type _ AMTypes.TVType[usersIOAsTV]; newIOAsTV: TypedVariable _ AMTypes.New[ioType]; oldIOAsTV: TypedVariable _ AMTypes.New[ioType]; cell.realCellStuff.newIO _ AMBridge.RefFromTV[newIOAsTV]; cell.realCellStuff.oldIO _ AMBridge.RefFromTV[oldIOAsTV]; END ELSE {cell.realCellStuff.newIO _ cell.realCellStuff.oldIO _ NIL}; END; EvalProvider: EvalProc = BEGIN pd: ProviderData _ NARROW[cell.realCellStuff.state]; FOR i: CARDINAL IN [0 .. cell.class.ioWordCount) DO TRUSTED BEGIN (cell.realCellStuff.oldIOAsWP + i)^ _ (cell.realCellStuff.newIOAsWP + i)^; END; ENDLOOP; IF pd.armed THEN pd.pauser.Pause[]; END; LookupClass: PROC [name: ROPE] RETURNS [CellClass] = {RETURN [NARROW[cellClasses.Lookup[name]]]}; DecideFromFile: PUBLIC PROC [fileName: ROPE] RETURNS [dff: Rosemary.ExpandDeciderClosure] = BEGIN file: IO.STREAM _ NIL; top: LORA; file _ FIO.Open[fileName: fileName]; top _ LIST[NIL, NIL, IO.GetRefAny[file]]; file.Close[]; dff _ NEW [Rosemary.ExpandDeciderClosureRep _ [Decide: DecideByName, otherData: top]]; END; DecideByName: Rosemary.ExpandDecider = BEGIN Yelp: PROC [problem: ROPE] RETURNS [Rosemary.ExpandDecision] = TRUSTED BEGIN qerv.DisplayMessage[problem]; RETURN [Ask[cell, NIL]]; 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 RosemaryExtras.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; ExpandDecisionRef: TYPE = REF Rosemary.ExpandDecision; 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: Viewer; [qp, v] _ Pausers.CreatePauser[enabledName: "Answer Query", disabledName: "", viewerInit: [parent: in, border: FALSE], paint: FALSE]; RETURN [LIST[v]]; END; Ask: Rosemary.ExpandDecider = BEGIN first: BOOLEAN _ TRUE; eq.instanceName _ cell.name; eq.className _ cell.class.name; WHILE first OR NOT RosemaryExtras.Possible[cell, eq.whatToDo] DO qp.Pause[]; first _ FALSE ENDLOOP; RETURN [eq.whatToDo]; END; qerv: ViewRec.RecordViewer; Setup: PROC = BEGIN RegisterCellClass[className: "GiveItAnything", expandProc: ExpandAnything, ioCreator: NIL, evalProc: NIL, ports: NEW [PortsRep[0]]]; TRUSTED BEGIN qerv _ ViewRec.ViewRef[ agg: eq, otherStuff: MakeQueryPauser, viewerInit: [iconic: FALSE, column: right, name: "ExpandQuery"]]; END; Atom.PutProp[atom: $N, prop: decisionProp, val: NEW [Rosemary.ExpandDecision _ Nested]]; Atom.PutProp[atom: $I, prop: decisionProp, val: NEW [Rosemary.ExpandDecision _ Inline]]; Atom.PutProp[atom: $L, prop: decisionProp, val: NEW [Rosemary.ExpandDecision _ Leaf]]; providerHandler.Register[CODE[ProviderDataRep]]; END; Setup[]; END. NRoseHelpImpl.Mesa Last Edited by: Spreitzer, June 28, 1983 6:48 pm Last Edited by: Barth, June 9, 1983 11:23 am RunButtonProc: Buttons.ButtonProc = BEGIN pd: ProviderData _ NARROW[clientData]; pd.armed _ TRUE; Rosemary.ScheduleCell[pd.cell]; Rosemary.Run[CellToStr[pd.cell.parent]]; pd.armed _ FALSE; END; MakePauser: ViewRec.OtherStuffProc = TRUSTED BEGIN v, b: Viewer; [pd.pauser, v] _ Pausers.CreatePauser[enabledName: "Proceed", disabledName: "", viewerInit: [parent: in, border: FALSE], paint: FALSE]; b _ Buttons.Create[ proc: RunButtonProc, info: [parent: in, name: "Schedule & Run"], clientData: pd, paint: FALSE]; RETURN [LIST[v, b]]; END; id: InitData _ NARROW[initData]; TRUSTED BEGIN [] _ ViewRec.ViewRef[rec: cell.realCellStuff.newIO, otherStuff: MakePauser, viewerInit: [iconic: FALSE, name: id.name.Concat[".newIO"]]]; END; Κ A˜J™J™0JšΟk,™,codeš ˜ KšœUœQ˜¨—K˜šΠbx œœ˜Kšœfœ œ#˜ŸKšœ ˜—K˜Kšœœ˜$K˜Kšœœœœ˜'K˜Kš œœœœœœ˜K˜Kšœœ˜$Kšœœ˜Kšœœ˜,K˜Kš œœœœœ˜K˜Kšœ œœ˜#šœœœ˜Kšœœ˜K˜Kšœ œœœ˜—K˜Kšœ œœ ˜!šœ œœ˜Kšœœ˜ Kšœ œœ˜—K˜Kšœœœ˜)šœœœ˜ K˜ Kšœœ˜Kšœœœ˜—K˜Kšœ œœ˜'šœœœ˜Kšœœœ˜$Kšœ,˜,—K˜K˜šœ$œ˜@K˜!—K˜Kšœœ˜Kšœœ˜,šœœ!œ&˜UKšœœ˜—K˜Kšœœ˜#K˜KšΟnœ!˜1K˜šŸœœœ,œ œœœ!œ˜žKš˜šœœ˜%Kšœ=˜=—Kšœ œ ˜1Kš œ œœœœœ˜WKšœt˜tKšœ˜—K˜šŸœ˜Kš˜Kšœœ ˜!K˜Kšœœ˜Kšœ œœœ˜Kšœœœ˜šœœœ˜6Kšœœ˜(Kšœœ˜"K˜PKš œœœœœ ˜WKšœ˜—K˜*Kšœ™˜™šœ œ˜'Kšœ&˜&K˜Kšœœ˜—Kšœœœ˜9KšœœW˜χKšœ˜—K˜šŸ œœœœ˜AKš˜K˜Kšœ,˜,šœ œ&œ˜CKš˜Kšœ7œw˜±Kšœ˜—Kšœ˜—K˜šΟc.˜.šŸ œ™#Kš™Kšœœ ™&Kšœ œ™K™K™(Kšœ œ™Kšœ™——K˜šŸœ˜!Kš˜š .˜.šŸ œ™$Kšœ™ K™ Kšœqœ œ™‡™K™K™+K™Kšœœ™—Kšœœ™Kšœ™——K˜Kšœœ"˜8š .˜.Kšœœ ™ šœ™ Kšœaœ#™‰Kšœ™——Kšœ˜Kšœ˜—K˜šŸœ ˜Kš˜Kšœœ ˜ šœœ˜Kš  œœ  ˜Kš˜KšœC˜CKšœ+˜+Kšœ/˜/Kšœ/˜/K˜9K˜9Kš˜—Kšœ8œ˜AKšœ˜—K˜šŸ œ ˜Kš˜Kšœœ˜4šœœœ˜3šœ˜ KšœJ˜JKšœ˜—Kšœ˜—Kšœ œ˜#Kšœ˜—K˜šŸ œœœœ˜4Kšœœœ˜,—K˜š Ÿœœœ œœ'˜[Kš˜Kšœœœœ˜Kšœœ˜ Kšœœ˜$Kš œœœœœ˜)K˜ KšœœM˜VKšœ˜—K˜šŸ œ˜&Kš˜š Ÿœœ œœ˜FKš˜K˜Kšœ œ˜Kšœ˜—Kšœœœ ˜*K˜Kšœœ#˜.Kšœœ˜ Kšœœœ˜Kšœ œœœ˜7šœœ˜Kš˜Kšœ%œœ˜:Kšœ˜%Kšœ˜—Kš œœœœœœ ˜QKš œ&œ,œœœ˜ˆKšœœ œœœœœœœœ˜rKšœœ˜+Kšœ˜—K˜Kšœœœ˜6K˜šŸœœœ˜1Kš˜Kšœœ˜ šœœ˜Kšœœ˜K˜Kšœ˜—Kšœ˜—K˜š Ÿœœœœœ˜7Kš˜šŸœœœ œœœœ˜>Kš˜Kšœœ˜ Kšœœ˜ š œœœœœ˜'Kš˜KšœCœ˜IKšœœ˜Kšœ˜—Kšœœ˜š'œœœœœœœ œœœœœœ œœœœ œœ˜Kš˜KšœCœ˜IKšœœ˜Kšœ˜—šœœ œ˜Kšœœ˜ Kšœœ˜Kšœœ˜—Kšœ%œ˜3Kšœ˜—šœœ˜Kšœœ˜ šœœœœœœ œœ˜Kšœœ˜ Kšœ˜—K˜Kšœœ ˜Kšœ˜—Kšœ˜ Kšœ˜—K˜šŸœ˜)Kš˜K˜ Kšœoœ œ˜…Kšœœ˜Kšœ˜—K˜šŸœ˜Kš˜Kšœœœ˜K˜K˜Kš œœœ,œœœ˜cKšœ˜Kšœ˜—K˜K˜K˜šŸœœ˜ Kš˜˜.K˜Kšœ œ˜Kšœ œ˜Kšœœ˜—K˜šœ˜ ˜Kšœ˜K˜Kšœœ'˜A—Kšœ˜—K˜KšœX˜XKšœX˜XKšœV˜VK˜Kšœœ˜0Kšœ˜—K˜K˜K˜Kšœ˜—…—!T0γ