BiasTypesImpl.Mesa, from [Indigo]<Rosemary>®>Rosemary.DF
Last Edited by: Spreitzer, May 8, 1985 4:02:31 pm PDT
DIRECTORY Atom, Basics, BiasTypes, IO, Rope, RoseTypes, SignalTypeRegistration, VFonts;
BiasTypesImpl:
CEDAR
PROGRAM
IMPORTS Atom, IO, Rope, SignalTypeRegistration, VFonts
EXPORTS BiasTypes =
BEGIN OPEN RoseTypes, BiasTypes;
biasProcs: NodeProcs ←
NEW [NodeProcsRep ← [
UserDescription: BiasUserDescription,
ListFormats: BiasListFormats,
GetFormat: BiasGetFormat,
MesaForSelf: BiasMesaForSelf,
SelectorOffset: BiasSelectorOffset,
SubType: BiasSubType,
Bits: BiasBits,
MesaRepresentation: BiasMesaRepresentation
]];
biasType:
PUBLIC NodeType ←
NEW [NodeTypeRep[atom] ← [
procs: biasProcs,
typeData: NIL,
simple: TRUE,
structure: atom[$BiasWire]]];
normalBiasFormat: Format ←
NEW [FormatRep ← [
FormatValue: BiasFormatValue,
ParseValue: BiasParseValue,
FormatTest: BiasFormatTest,
ParseTest: BiasParseTest,
MaxWidth: BiasMaxWidth,
key: "bias"]];
initBiasFormat: Format ←
NEW [FormatRep ← [
ParseValue: BiasParseInitValue,
key: "init"]];
ConstructBiasType:
PROC [parms:
REF
ANY
--UNION [BindingList, Args]--]
RETURNS [type: NodeType]
--RoseTranslateTypes.NodeTypeConstructor-- =
BEGIN
type ← biasType;
END;
BiasUserDescription: PROC [NodeType] RETURNS [r: ROPE] = {r ← "Bias"};
BiasListFormats: PROC [NodeType] RETURNS [l: RopeList] = {l ← LIST ["bias"]};
BiasGetFormat:
PROC [nt: NodeType, f:
ROPE]
RETURNS [fmt: Format] =
{fmt ← IF f.Equal["init"] THEN initBiasFormat ELSE normalBiasFormat};
BiasMesaForSelf:
PROC [NodeType]
RETURNS [m: Mesa] =
{m ← [mesa: "BiasTypes.biasType", imports: LIST["BiasTypes"]]};
BiasSelectorOffset:
PROC [nt: NodeType, s: Selector]
RETURNS [o:
NAT] = {
o ←
WITH s
SELECT
FROM
whole => 0,
number, range => ERROR,
ENDCASE => ERROR};
BiasSubType:
PROC [nt: NodeType, s: Selector]
RETURNS [snt: NodeType] = {
snt ←
WITH s
SELECT
FROM
whole => nt,
number, range => ERROR,
ENDCASE => ERROR};
BiasBits:
PROC [NodeType]
RETURNS [container, data, leftPad:
INT] =
{RETURN [1, 1, 0]};
BiasMesaRepresentation:
PROC [NodeType]
RETURNS [m: Mesa] =
{m ← ["BiasTypes.Bias", LIST["BiasTypes"]]};
BiasPtr:
TYPE =
RECORD [
i: [0 .. Basics.bitsPerWord),
p: LONG POINTER TO PACKED ARRAY [0 .. Basics.bitsPerWord) OF Bias];
ToBiasPtr:
PROC [p: Ptr]
RETURNS [bp: BiasPtr] =
TRUSTED
{bp ← [p.bit, LOOPHOLE[p.word]]};
BiasFormatValue:
PROC [node: Node, fmt: Format, p: Ptr]
RETURNS [r:
ROPE] =
TRUSTED {
bp: BiasPtr ← ToBiasPtr[p];
r ← Encode[bp.p[bp.i]]};
Encode:
PROC [b: Bias]
RETURNS [r:
ROPE] = {
r ←
SELECT b
FROM
Plus => "+",
Minus => "-",
ENDCASE => ERROR Coding};
Coding: ERROR = CODE;
BiasParseInitValue:
PROC [node: Node, fmt: Format, p: Ptr, s:
STREAM]
RETURNS [success:
BOOLEAN] = {
b: Bias;
bp: BiasPtr ← ToBiasPtr[p];
atom: ATOM ← Atom.MakeAtom[s.GetID[]];
success ← TRUE;
SELECT atom
FROM
$initial, $steady => b ← Plus;
ENDCASE => success ← FALSE;
IF NOT success THEN RETURN;
TRUSTED {bp.p[bp.i] ← b};
};
BiasParseValue:
PROC [node: Node, fmt: Format, p: Ptr, s:
STREAM]
RETURNS [success:
BOOLEAN] = {
b: Bias;
bp: BiasPtr ← ToBiasPtr[p];
success ← TRUE;
b ← Decode[s !Coding => {success ← FALSE; CONTINUE}];
IF NOT success THEN RETURN;
TRUSTED {bp.p[bp.i] ← 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, test: NodeTest]
RETURNS [r:
ROPE] =
BEGIN
rb: REF Bias ← NARROW[test.data];
r ← Encode[rb^];
END;
BiasParseTest:
PROC [nt: NodeType, fmt: Format, s:
STREAM]
RETURNS [success:
BOOLEAN, test: NodeTest] =
BEGIN
b: Bias;
success ← TRUE;
b ← Decode[s !Coding => {success ← FALSE; CONTINUE}];
IF NOT success THEN RETURN;
test ← [BiasTest, NEW [Bias ← b]];
END;
BiasTest:
PROC [where: Ptr, testData:
REF
ANY, nodeType: NodeType]
RETURNS [passes:
BOOLEAN]
--NodeTestProc-- =
BEGIN
rb: REF Bias ← NARROW[testData];
bp: BiasPtr ← ToBiasPtr[where];
TRUSTED {passes ← bp.p[bp.i] = rb^};
END;
BiasMaxWidth:
PROC [nt: NodeType, fmt: Format, font: VFonts.Font]
RETURNS [
INT] =
{RETURN [VFonts.StringWidth["+", font]]};
Setup:
PROC =
BEGIN
SignalTypeRegistration.RegisterNodeTypeConstructor["BIAS", ConstructBiasType];
END;
Setup[];
END.