RoseBoolImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Barth, September 5, 1985 6:37:22 pm PDT
Spreitzer, September 22, 1985 4:36:24 pm PDT
DIRECTORY Basics, ImagerFont, IO, Real, Rope, RoseTransduce, RoseWireClasses, RoseWireTypes, VFonts;
RoseBoolImpl:
CEDAR
PROGRAM
IMPORTS ImagerFont, IO, Real, Rope, RoseTransduce
EXPORTS RoseWireClasses, RoseTransduce =
BEGIN OPEN RoseWireTypes;
GetBool:
PUBLIC
PROC
RETURNS [RoseWireClass] = {
RETURN[boolClass]};
boolSuperClass: RoseWireSuperClass ←
NEW[RoseWireSuperClassRec ← [
GetType: BoolGetType,
ListFormats: BoolListFormats,
GetFormat: BoolGetFormat,
SelectorOffset: NIL,
SubType: NIL,
SubClass: NIL,
Bits: BoolBits,
MesaRepresentation: BoolMesaRepresentation,
MesaRepAux: NIL,
flavor: simple,
Initialize: BoolInitialize,
Transduce: BoolTransduce
]];
boolClass: RoseWireClass ←
NEW[RoseWireClassRec ← [
structure: atom,
dereference: FALSE,
addressContaining: FALSE,
classData: NIL,
super: boolSuperClass]];
BoolGetType:
PROC [rwc: RoseWireClass, wire: Wire]
RETURNS [rwt: RoseWireType] = {
IF wire.structure # atom THEN ERROR;
RETURN[boolType];
};
boolType:
PUBLIC RoseWireType ←
NEW[RoseWireTypeRec ← [
class: boolClass,
typeData: NIL,
length: 0,
other: NIL]];
BoolListFormats:
PROC [rwt: RoseWireType]
RETURNS [lor:
LOR] = {
lor ← LIST["numeric"];
};
BoolGetFormat:
PROC [rwt: RoseWireType, formatName:
ROPE]
RETURNS [format: Format] = {
format ←
SELECT
TRUE
FROM
formatName.Equal["numeric"], formatName=NIL => numericFormat,
ENDCASE => ERROR;
};
BoolBits:
PROC [rwt: RoseWireType]
RETURNS [n:
INT] = {
RETURN[1]};
BoolMesaRepresentation:
PROC [rwc: RoseWireClass]
RETURNS [mesa: Mesa] = {
mesa ← [mesa: "BOOL"]};
BoolInitialize:
PROC [rwt: RoseWireType, p: Ptr, steady:
BOOL] = {
WriteBool[p, FALSE];
};
BoolTransduce:
PROC [fromS: Strength, fromT, toT: RoseWireType, fromP, toP: Ptr] = {
IF fromT # boolType THEN ERROR;
IF toT # RoseTransduce.bitType THEN ERROR;
RoseTransduce.WriteSwitch[
toP,
SELECT ReadBool[fromP]
FROM
FALSE => [s: [q: fromS, u: none, d: fromS], val: L],
TRUE => [s: [q: fromS, u: fromS, d: none], val: H],
ENDCASE => ERROR
];
};
numericFormat: Format ←
NEW [FormatRep ← [
FormatValue: NumericFormatValue,
ParseValue: NumericParseValue,
MaxWidth: NumericMaxWidth,
key: "numeric"]];
NumericFormatValue:
PROC [rwt: RoseWireType, f: Format, p: Ptr]
RETURNS [r:
ROPE] = {
r ←
SELECT ReadBool[p]
FROM
FALSE => "0",
TRUE => "1",
ENDCASE => ERROR;
};
NumericParseValue:
PROC [rwt: RoseWireType, f: Format, p: Ptr, s:
STREAM]
RETURNS [ok:
BOOL] = {
c: CHAR = s.GetChar[];
val: BOOL;
SELECT c
FROM
'0 => val ← FALSE;
'1 => val ← TRUE;
ENDCASE => RETURN [FALSE];
WriteBool[p, val];
ok ← TRUE;
};
NumericMaxWidth:
PROC [rwt: RoseWireType, fmt: Format, font: VFonts.Font]
RETURNS [max:
INT] = {
max ← Real.Round[ImagerFont.RopeWidth[font, "X"].x];
};
BoolArrayPtr: TYPE = LONG POINTER TO PACKED ARRAY [0 .. Basics.bitsPerWord) OF BOOL;
ReadBool:
PUBLIC
PROC [p: Ptr]
RETURNS [b:
BOOL] =
TRUSTED {
bap: BoolArrayPtr = LOOPHOLE[p.word];
b ← bap[p.bit];
};
WriteBool:
PUBLIC
PROC [p: Ptr, b:
BOOL] =
TRUSTED {
bap: BoolArrayPtr = LOOPHOLE[p.word];
bap[p.bit] ← b;
};
END.