SaffronRandomBaseFunctionsImpl.Mesa
Copyright Ó 1988 by Xerox Corporation. All rights reserved.
James Rauen, July 10, 1988 2:59:55 pm PDT
DIRECTORY
BigIntegers USING [BigFromSmall, BigINT],
Rope USING [Cat, Equal, ROPE],
SaffronBaseDef USING [],
SaffronErrorHandling USING [InternalError],
SaffronGenericDef USING [DecimalnumNode, FlnumNode, HexnumNode, IdNode, IdNodeBody, OctalnumNode, StringNode, StringNodeBody];
SaffronRandomBaseFunctionsImpl: CEDAR PROGRAM
IMPORTS BigIntegers, Rope, SaffronErrorHandling
EXPORTS SaffronBaseDef
= BEGIN
OPEN SaffronGenericDef;
RopeFromId: PUBLIC PROC [ id: IdNode ] RETURNS [ Rope.ROPE ] ~ {
RETURN[IF ( id # NIL ) THEN id.text ELSE ""];
};
RopeFromString: PUBLIC PROC [ string: StringNode ] RETURNS [ Rope.ROPE ] ~ {
RETURN[IF ( string # NIL ) THEN string.text ELSE ""];
};
RopeFromDecimalnum: PUBLIC PROC [num: DecimalnumNode] RETURNS [Rope.ROPE] ~ {
RETURN[num.text];
};
RopeFromOctalnum: PUBLIC PROC [num: OctalnumNode] RETURNS [Rope.ROPE] ~ {
RETURN[num.text];
};
RopeFromHexnum: PUBLIC PROC [num: HexnumNode] RETURNS [Rope.ROPE] ~ {
RETURN[num.text];
};
RopeFromFlnum: PUBLIC PROC [num: FlnumNode] RETURNS [Rope.ROPE] ~ {
RETURN[num.text];
};
StringFromId: PUBLIC PROC [id: IdNode] RETURNS [StringNode] = BEGIN
RETURN[NEW[StringNodeBody ← [text: id.text, position: id.position, length: id.length]]];
END;
IdFromRope: PUBLIC PROC [r: Rope.ROPE] RETURNS [IdNode] = BEGIN
RETURN[NEW[IdNodeBody ← [text: r, position: 0, length: 0]]];
END;
True: PUBLIC PROC RETURNS [ BOOLEAN ] ~ { RETURN[TRUE] };
False: PUBLIC PROC RETURNS [ BOOLEAN ] ~ { RETURN[FALSE] };
And: PUBLIC PROC [a, b: BOOLEAN] RETURNS [BOOLEAN] ~ { RETURN[a AND b] };
Or: PUBLIC PROC [a, b: BOOLEAN] RETURNS [BOOLEAN] ~ { RETURN[a OR b] };
Not: PUBLIC PROC [a: BOOLEAN] RETURNS [BOOLEAN] ~ { RETURN[NOT a] };
BooleanConst: PUBLIC PROC [ r: Rope.ROPE ] RETURNS [ BOOLEAN ] ~ {
SELECT TRUE FROM
Rope.Equal[r, "True"] => RETURN[TRUE];
Rope.Equal[r, "False"] => RETURN[FALSE];
ENDCASE => ERROR SaffronErrorHandling.InternalError[Rope.Cat["Bad argument (", r, ") to SaffronContextCreateCTImpl.BooleanConst"]];
};
Error: PUBLIC PROC [ r: Rope.ROPE ] RETURNS [ BOOLEAN ] ~ { ERROR };
NullId: PUBLIC PROC RETURNS [ IdNode ] ~ { RETURN[NIL] };
DummyBigINT: PUBLIC PROC RETURNS [BigIntegers.BigINT] = BEGIN
RETURN [BigIntegers.BigFromSmall[239]];
END;
END.