BiasTypesImpl.Mesa, from [Indigo]<Rosemary>2.6>Rosemary.DF
Last Edited by: Spreitzer, August 18, 1984 8:59:42 pm PDT
DIRECTORY IO, BiasTypes, RoseCreate, RoseTypes, SignalTypeRegistration, SwitchTypes, VFonts;
BiasTypesImpl: CEDAR PROGRAM
IMPORTS IO, RoseCreate, SignalTypeRegistration, SwitchTypes, VFonts
EXPORTS BiasTypes =
BEGIN OPEN RoseTypes, BiasTypes;
biasProcs: NodeProcs ← NEW [NodeProcsRep ← [
Bits: BiasBits,
MesaUse: BiasMesaUse,
UserDescription: BiasUserDescription,
MesaDescription: BiasMesaDescription,
ListFormats: BiasListFormats,
GetFormat: BiasGetFormat,
MakeTransducer: MakeBiasSwitchTransducer]];
biasType: PUBLIC NodeType ← NEW [NodeTypeRep[atom] ← [
procs: biasProcs,
typeData: NIL,
simple: TRUE,
structure: atom[]]];
onlyBiasFormat: Format ← NEW [FormatRep ← [
FormatValue: BiasFormatValue,
ParseValue: BiasParseValue,
FormatTest: BiasFormatTest,
ParseTest: BiasParseTest,
MaxWidth: BiasMaxWidth,
key: "bias"]];
ConstructBiasType: PROC [parms: REF ANY --UNION [BindingList, Args]--] RETURNS [type: NodeType]--RoseTranslateTypes.NodeTypeConstructor-- =
BEGIN
type ← biasType;
END;
BiasBits: PROC [NodeType] RETURNS [INTEGER] = {RETURN [1]};
BiasMesaUse: PROC [NodeType] RETURNS [m: Mesa] =
{m ← ["BiasTypes.Bias", LIST["BiasTypes"]]};
BiasUserDescription: PROC [NodeType] RETURNS [r: ROPE] = {r ← "Bias"};
BiasMesaDescription: PROC [NodeType] RETURNS [m: Mesa] =
{m ← [mesa: "BiasTypes.biasType", imports: LIST["BiasTypes"]]};
BiasListFormats: PROC [NodeType] RETURNS [l: RopeList] = {l ← LIST ["bias"]};
BiasGetFormat: PROC [NodeType, ROPE] RETURNS [f: Format] =
{f ← onlyBiasFormat};
BHP: TYPE = LONG POINTER TO BiasHolder;
BiasFormatValue: PROC [node: Node, fmt: Format, wp: WordPtr] RETURNS [r: ROPE] = TRUSTED {
bhp: BHPLOOPHOLE[wp];
r ← Encode[bhp.bias]};
Encode: PROC [b: Bias] RETURNS [r: ROPE] = {
r ← SELECT b FROM
Plus => "+",
Minus => "-",
ENDCASE => ERROR Coding};
Coding: ERROR = CODE;
BiasParseValue: PROC [node: Node, fmt: Format, wp: WordPtr, s: STREAM] RETURNS [success: BOOLEAN] = {
b: Bias;
bhp: BHPLOOPHOLE[wp];
success ← TRUE;
b ← Decode[s !Coding => {success ← FALSE; CONTINUE}];
IF NOT success THEN RETURN;
TRUSTED {bhp.bias ← b};
};
Decode: PROC [from: STREAM] RETURNS [b: Bias] = {
c: CHAR;
[] ← from.SkipWhitespace[flushComments: FALSE];
c ← from.GetChar[];
SELECT c FROM
'+ => b ← Plus;
'- => b ← Minus;
ENDCASE => ERROR Coding};
BiasFormatTest: PROC [nt: NodeType, fmt: Format, tp: NodeTestProc, td: NodeTestData] RETURNS [r: ROPE] =
BEGIN
rb: REF Bias ← NARROW[td];
r ← Encode[rb^];
END;
BiasParseTest: PROC [nt: NodeType, fmt: Format, s: STREAM] RETURNS [success: BOOLEAN, tp: NodeTestProc, td: NodeTestData] =
BEGIN
b: Bias;
success ← TRUE;
b ← Decode[s !Coding => {success ← FALSE; CONTINUE}];
IF NOT success THEN RETURN;
tp ← BiasTest;
td ← NEW [Bias ← b];
END;
BiasTest: NodeTestProc--PROC [where: WordPtr, testData: NodeTestData, nodeType: NodeType] RETURNS [passes: BOOLEAN]-- =
BEGIN
rb: REF Bias ← NARROW[testData];
bhp: BHPLOOPHOLE[where];
TRUSTED {passes ← bhp.bias = rb^};
END;
BiasMaxWidth: PROC [nt: NodeType, fmt: Format, font: VFonts.Font] RETURNS [INT] =
{RETURN [VFonts.StringWidth["+", font]]};
MakeBiasSwitchTransducer: PROC [myKind, otherKind: Node, within: Cell, writeMine, writeOther: BOOLEAN, for: ExpansionReceiver] RETURNS [t: Cell] = {
instanceName: ROPEIO.PutFR["%g-%g", IO.rope[myKind.name], IO.rope[otherKind.name]];
interfaceNodes: ROPEIO.PutFR["bias: %g, switch: %g", IO.rope[myKind.name], IO.rope[otherKind.name]];
t ← for.class.CellInstance[erInstance: for.instance, instanceName: instanceName, typeName: BSName[], interfaceNodes: interfaceNodes];
};
bsType: CellType ← NIL;
BSName: PROC RETURNS [name: ROPE] = {
IF bsType = NIL THEN {
bsPorts: Ports ← NEW [PortsRep[2]];
bsPorts[0] ← [0, 1, "bias", biasType, TRUE, TRUE];
bsPorts[1] ← [1, 1, "switch", SwitchTypes.bitType, TRUE, TRUE];
bsType ← RoseCreate.RegisterCellType[
name: "BiasSwitchTransducer",
ioCreator: CreateBSIO,
initializer: InitBS,
evals: [EvalSimple: EvalBS, InitUD: InitBSUD, PropUD: PropBSUD],
ports: bsPorts];
};
name ← bsType.name};
BSIORep: TYPE = MACHINE DEPENDENT RECORD [
bhp(0:0..15): BiasHolder,
switch(1:0..15): SwitchTypes.SwitchVal];
BSState: TYPE = REF BSStateRep;
BSStateRep: TYPE = RECORD [firstSwitch, firstSimple: BOOL];
InitBS: PROC [cell: Cell, leafily: BOOL] = {
IF leafily THEN cell.realCellStuff.state ← NEW [BSStateRep ← [TRUE, TRUE]]};
CreateBSIO: PROC [cell: Cell] = {
cell.realCellStuff.newIO ← NEW [BSIORep];
cell.realCellStuff.oldIO ← NEW [BSIORep];
cell.realCellStuff.switchIO ← NEW [BSIORep]};
EvalBS: PROC [cell: Cell] = {state: BSState ← NARROW[cell.realCellStuff.state];
IF state.firstSimple THEN state.firstSimple ← FALSE ELSE ERROR};
InitBSUD: PROC [cell: Cell] = {state: BSState ← NARROW[cell.realCellStuff.state];
IF state.firstSwitch THEN state.firstSwitch ← FALSE ELSE ERROR};
PropBSUD: PROC [cell: Cell] = {};
Setup: PROC =
BEGIN
SignalTypeRegistration.RegisterNodeTypeConstructor["BIAS", ConstructBiasType];
END;
Setup[];
END.