DIRECTORY IO, NumTypes, Rope, RoseCreate, RoseRun, RoseTypes, SwitchNumConvert, SwitchTypes; SwitchNumConvertImpl: CEDAR PROGRAM IMPORTS IO, NumTypes, Rope, RoseCreate, RoseRun, SwitchTypes EXPORTS SwitchNumConvert = BEGIN OPEN RoseTypes; ConverterState: TYPE = REF ConverterStateRep; ConverterStateRep: TYPE = RECORD [ atomic: BOOLEAN, first, last, length, no, switchWordCount, numWordCount: INTEGER _ 0, writeSwitchy, writeNummy: BOOLEAN]; MakeTransducer: PUBLIC PROC [switchy, nummy: Node, within: Cell, writeSwitchy, writeNummy: BOOLEAN] RETURNS [t: Cell] = BEGIN className: ROPE; state: ConverterState; state _ NEW [ConverterStateRep _ [ atomic: switchy.type.structureType = atom, writeSwitchy: writeSwitchy, writeNummy: writeNummy]]; IF NOT SwitchTypes.IsSwitchType[switchy.type] THEN RETURN [NIL]; IF NOT NumTypes.Numeric[nummy.type] THEN RETURN [NIL]; IF writeSwitchy = writeNummy THEN ERROR; IF NOT SameStructure[switchy.type, nummy.type] THEN ERROR; WITH switchy.type SELECT FROM a: AtomNodeType => NULL; a: ArrayNodeType => {state.first _ a.first; state.last _ a.last}; ENDCASE => ERROR; state.length _ state.last - state.first + 1; state.numWordCount _ (15 + state.length)/16; state.switchWordCount _ (SwitchTypes.switchValsPerWord + state.length - 1)/SwitchTypes.switchValsPerWord; state.no _ (16 - (state.length MOD 16)) MOD 16; className _ GetClass[state, switchy, nummy]; t _ RoseCreate.CreateCell[within: within, instanceName: switchy.name.Cat["-", nummy.name], className: className, interfaceNodes: switchy.name.Cat[", ", nummy.name], initData: state]; END; GetAtom: PROC [nt: NodeType] RETURNS [a: NodeType] = { WITH nt SELECT FROM x: AtomNodeType => a _ nt; x: ArrayNodeType => a _ GetAtom[x.element]; ENDCASE => ERROR}; SameStructure: PROC [a, b: NodeType] RETURNS [same: BOOLEAN] = BEGIN first, last: INTEGER; IF a.structureType # b.structureType THEN RETURN [FALSE]; WITH a SELECT FROM x: ArrayNodeType => {first _ x.first; last _ x.last}; x: AtomNodeType => NULL; ENDCASE => ERROR; WITH b SELECT FROM x: ArrayNodeType => {same _ first = x.first AND last = x.last}; x: AtomNodeType => same _ TRUE; ENDCASE => ERROR; END; ClassNote: TYPE = RECORD [ parms: ConverterStateRep, class: CellClass]; ClassNoteList: TYPE = LIST OF ClassNote; classNotes: ClassNoteList _ NIL; Words: TYPE = REF WordsRep; WordsRep: TYPE = RECORD [words: SEQUENCE length: CARDINAL OF CARDINAL]; Switches: TYPE = LONG POINTER TO PACKED ARRAY CARDINAL OF SwitchTypes.SwitchVal; Nums: TYPE = LONG POINTER TO PACKED ARRAY CARDINAL OF BOOLEAN; GetClass: PROC [state: ConverterState, switchy, nummy: Node] RETURNS [className: ROPE] = BEGIN ports: Ports _ NEW [PortsRep[2]]; ports[0] _ [1, state.switchWordCount, "switchy", switchy.type, state.writeNummy, state.writeSwitchy, state.writeNummy]; ports[1] _ [1+state.switchWordCount, state.numWordCount, "nummy", nummy.type, state.writeSwitchy, state.writeNummy]; FOR cnl: ClassNoteList _ classNotes, cnl.rest WHILE cnl # NIL DO IF cnl.first.parms = state^ THEN RETURN [cnl.first.class.name]; ENDLOOP; className _ IO.PutFR[ "SN %g %g..%g %g %g", IO.bool[state.atomic], IO.int[state.first], IO.int[state.last], IO.bool[state.writeSwitchy], IO.bool[state.writeNummy]]; [] _ RoseCreate.RegisterCellClass[ className: className, ioCreator: CreateConverterIO, initializer: InitializeConverter, evals: [ ValsChanged: ConverterValsChanged, InitQ: NIL, PropQ: ConverterPropQ, InitUD: NIL, PropUD: ConverterPropUD, FinalUD: NIL, EvalSimple: ConverterSimple, FindVicinity: NIL], ports: ports]; END; CreateConverterIO: IOCreator--PROC [cell: Cell, initData: REF ANY]-- = BEGIN cs: ConverterState _ NARROW[initData]; cell.realCellStuff.switchIO _ NEW [WordsRep[cs.switchWordCount+cs.numWordCount]]; cell.realCellStuff.newIO _ NEW [WordsRep[cs.switchWordCount+cs.numWordCount]]; cell.realCellStuff.oldIO _ NEW [WordsRep[cs.switchWordCount+cs.numWordCount]]; END; InitializeConverter: Initializer--PROCEDURE [cell: Cell, initData: REF ANY, leafily: BOOLEAN]-- = {IF leafily THEN cell.realCellStuff.state _ initData}; ConverterSimple: CellProc--PROC [cell: Cell]-- = BEGIN cs: ConverterState _ NARROW[cell.realCellStuff.state]; IF cs.writeSwitchy THEN RoseRun.PerturbPort[cell, 0]; END; ConverterValsChanged: CellProc--PROC [cell: Cell]-- = BEGIN cs: ConverterState _ NARROW[cell.realCellStuff.state]; IF cs.writeNummy THEN { s: Switches; n: Nums; TRUSTED { s _ LOOPHOLE[cell.realCellStuff.switchIOAsWP+1]; n _ LOOPHOLE[cell.realCellStuff.newIOAsWP+1+cs.switchWordCount]}; FOR i: INTEGER IN [0 .. cs.length) DO TRUSTED {IF s[i].val # X THEN n[i+cs.no] _ s[i].val = H}; ENDLOOP; }; END; ConverterPropQ: CellProc--PROC [cell: Cell]-- = BEGIN cs: ConverterState _ NARROW[cell.realCellStuff.state]; IF cs.writeSwitchy THEN TRUSTED { s: Switches _ LOOPHOLE[cell.realCellStuff.switchIOAsWP+1]; n: Nums _ LOOPHOLE[cell.realCellStuff.newIOAsWP+1+cs.switchWordCount]; FOR i: INTEGER IN [0 .. cs.length) DO s[i].s[q] _ drive ENDLOOP; }; END; ConverterPropUD: CellProc--PROC [cell: Cell]-- = BEGIN Convert: PROC [on: BOOLEAN] RETURNS [up, down: SwitchTypes.Strength] = { IF on THEN RETURN [drive, none] ELSE RETURN [none, drive]}; cs: ConverterState _ NARROW[cell.realCellStuff.state]; IF cs.writeSwitchy THEN TRUSTED { s: Switches _ LOOPHOLE[cell.realCellStuff.switchIOAsWP+1]; n: Nums _ LOOPHOLE[cell.realCellStuff.newIOAsWP+1+cs.switchWordCount]; FOR i: INTEGER IN [0 .. cs.length) DO [s[i].s[u], s[i].s[d]] _ Convert[n[i+cs.no]]; ENDLOOP; }; END; END. L[Indigo]PreRelease>Rosemary2.DF=>SwitchNumConvertImpl.Mesa Last Edited by: Spreitzer, March 19, 1984 2:37:21 pm PST new: Words _ NARROW[cell.realCellStuff.newIO]; old: Words _ NARROW[cell.realCellStuff.oldIO]; FOR i: INTEGER IN [cs.switchWordCount .. cs.switchWordCount+cs.numWordCount) DO old[i] _ new[i] ENDLOOP; Κ'– "cedar" style˜JšœD™DJ™8J˜IcodešΟk œS˜\K˜šΠbxœœ˜#Kšœ5˜Kš˜Kšœ œ˜Kšœ#œœœ˜9šœœ˜Kšœ5˜5Kšœœ˜Kšœœ˜—šœœ˜Kšœ,œ˜?Kšœœ˜Kšœœ˜—Kšœ˜—K˜šœ œœ˜Kšœ˜K˜—K˜Kšœœœœ ˜(K˜Kšœœ˜ K˜Kšœœœ ˜Kš œ œœ œ œœœ˜GK˜Kšœ œœœœœœœœ˜PKšœœœœœœœœœœ˜>K˜šŸœœ/œ œ˜XKš˜Kšœœ˜!Kšœw˜wKšœt˜tšœ+œœ˜@Kšœœœ˜?Kšœ˜—šœ œ˜Kšœ˜Kšœ˜Kšœ˜Kšœ˜Kšœ˜Kšœ˜—˜"Kšœ˜Kšœ˜K˜!šœ˜K˜"Kšœœ˜ K˜Kšœœ˜ K˜Kšœ œ˜ Kšœ˜Kšœœ˜—K˜—Kšœ˜—K˜šŸœ Οc(œ˜FKš˜Kšœœ ˜&Kšœœ0˜QKšœœ0˜NKšœœ0˜NKšœ˜—K˜šŸœ  ?œ˜aKšœœ œ&˜6—K˜šŸœ  œ˜0Kš˜Kšœœ˜6Kšœœ˜5Kšœ˜—K˜šŸœ  œ˜5Kš˜Kšœœ˜6Kšœ œ™.Kšœ œ™.Kš œœœ<œœ™hšœœ˜K˜ K˜šœ˜ Kšœœ$˜0Kšœœ5˜A—šœœœ˜%Kš œœ œœœ˜9Kšœ˜—K˜—Kšœ˜—K˜šŸœ  œ˜/Kš˜Kšœœ˜6šœ œ˜!Kšœœ$˜:Kšœ œ4˜FKš œœœœœ˜@Kšœ˜—Kšœ˜—K˜šŸœ  œ˜0Kš˜šŸœœœœ%˜HKš œœœœœ˜;—Kšœœ˜6šœœœ˜!Kšœœ$˜:Kšœ œ4˜Fšœœœ˜%Kšœ-˜-Kšœ˜—Kšœ˜—Kšœ˜—K˜Kšœ˜—…—nα