SaffronPGOperationsImpl.Mesa
Copyright Ó 1988 by Xerox Corporation. All rights reserved.
James Rauen, June 13, 1988 11:39:42 am PDT
Last edited by: James Rauen June 15, 1988 12:52:27 pm PDT
DIRECTORY
Convert USING [RopeFromInt],
IO USING [int, PutF, STREAM],
MessageWindow USING [Append, Blink],
Rope USING [Concat, ROPE],
SaffronPGDeclsDef USING [],
SaffronPGOperations USING [],
SaffronPGPrivateTypes USING [ProgramGraphNode, ProgramGraphNodeBody, EvaluatedExpressionNode, EvaluatedExpressionNodeBody];
SaffronPGOperationsImpl:
CEDAR
PROGRAM
IMPORTS IO, MessageWindow, Rope, Convert
EXPORTS SaffronPGDeclsDef, SaffronPGOperations ~ BEGIN
ProgramGraphNode: TYPE ~ REF ProgramGraphNodeBody;
ProgramGraphNodeBody: PUBLIC TYPE ~ SaffronPGPrivateTypes.ProgramGraphNodeBody;
MakeBogusPGN:
PUBLIC PROC []
RETURNS [ProgramGraphNode] ~
BEGIN
foo: ProgramGraphNode ← NEW[ProgramGraphNodeBody];
MessageWindow.Blink[];
MessageWindow.Append["Making a bogus program graph node.", TRUE];
RETURN[foo];
END;
MakeSemiBogusPGN:
PUBLIC PROC [e: EvaluatedExpressionNode]
RETURNS [ProgramGraphNode] ~
BEGIN
foo: ProgramGraphNode ← NEW[ProgramGraphNodeBody];
foo.operation ← IntegerEvExpVal[e];
MessageWindow.Blink[];
MessageWindow.Append["Making a semibogus program graph node.", TRUE];
RETURN[foo];
END;
PrintProgramGraph:
PUBLIC
PROC [stream:
IO.
STREAM, pg: ProgramGraphNode]
RETURNS [
BOOLEAN] ~
BEGIN
IO.PutF[stream, "The computed value is %g\n", IO.int[pg.operation]];
RETURN[TRUE];
END;
NewPrintProgramGraph:
PUBLIC
PROC [stream:
IO.
STREAM, pg: ProgramGraphNode] ~
BEGIN
IO.PutF[stream, "The computed value is %g\n", IO.int[pg.operation]];
END;
EvaluatedExpressionNode: TYPE ~ SaffronPGPrivateTypes.EvaluatedExpressionNode;
EvaluatedExpressionNodeBody: PUBLIC TYPE ~ SaffronPGPrivateTypes.EvaluatedExpressionNodeBody;
MakeIntegerEvExp:
PUBLIC
PROC [i:
INT]
RETURNS [EvaluatedExpressionNode] ~
{
MessageWindow.Blink[];
MessageWindow.Append[Rope.Concat["Evaluated value = ", Convert.RopeFromInt[i]], TRUE];
RETURN[NEW[EvaluatedExpressionNodeBody ← [integer[i]]]];
};
MakeRealEvExp:
PUBLIC
PROC [r:
REAL]
RETURNS [EvaluatedExpressionNode] ~
{
RETURN[NEW[EvaluatedExpressionNodeBody ← [real[r]]]];
};
MakeBooleanEvExp:
PUBLIC
PROC [b:
BOOLEAN]
RETURNS [EvaluatedExpressionNode] ~
{
RETURN[NEW[EvaluatedExpressionNodeBody ← [boolean[b]]]];
};
MakeRopeEvExp:
PUBLIC
PROC [r: Rope.
ROPE]
RETURNS [EvaluatedExpressionNode] ~
{
RETURN[NEW[EvaluatedExpressionNodeBody ← [rope[r]]]];
};
MakeComputedEvExp:
PUBLIC
PROC [code: ProgramGraphNode]
RETURNS [EvaluatedExpressionNode] ~ {
RETURN[NEW[EvaluatedExpressionNodeBody ← [computed[code]]]];
};
IsIntegerEvExp:
PUBLIC
PROC [e: EvaluatedExpressionNode]
RETURNS [
BOOLEAN] ~ {
RETURN[e.type = integer];
};
IsRealEvExp:
PUBLIC
PROC [e: EvaluatedExpressionNode]
RETURNS [
BOOLEAN] ~ {
RETURN[e.type = real];
};
IsBooleanEvExp:
PUBLIC
PROC [e: EvaluatedExpressionNode]
RETURNS [
BOOLEAN] ~ {
RETURN[e.type = boolean];
};
IsRopeEvExp:
PUBLIC
PROC [e: EvaluatedExpressionNode]
RETURNS [
BOOLEAN] ~ {
RETURN[e.type = rope];
};
IsComputedEvExp:
PUBLIC
PROC [e: EvaluatedExpressionNode]
RETURNS [
BOOLEAN] ~ {
RETURN[e.type = computed];
};
EvExpTypeError:
ERROR =
CODE;
IntegerEvExpVal:
PUBLIC
PROC [e: EvaluatedExpressionNode]
RETURNS [
INT] ~ {
WITH e
SELECT
FROM
i: REF integer EvaluatedExpressionNodeBody => RETURN[i.value];
ENDCASE;
ERROR EvExpTypeError;
};
RealEvExpVal:
PUBLIC
PROC [e: EvaluatedExpressionNode]
RETURNS [
REAL] ~ {
WITH e
SELECT
FROM
i: REF real EvaluatedExpressionNodeBody => RETURN[i.value];
ENDCASE;
ERROR EvExpTypeError;
};
BooleanEvExpVal:
PUBLIC
PROC [e: EvaluatedExpressionNode]
RETURNS [
BOOLEAN] ~ {
WITH e
SELECT
FROM
i: REF boolean EvaluatedExpressionNodeBody => RETURN[i.value];
ENDCASE;
ERROR EvExpTypeError;
};
Rope
EvExpVal:
PUBLIC
PROC [e: EvaluatedExpressionNode]
RETURNS [Rope.
ROPE] ~ {
WITH e
SELECT
FROM
i: REF rope EvaluatedExpressionNodeBody => RETURN[i.value];
ENDCASE;
ERROR EvExpTypeError;
};
ComputedEvExpVal:
PUBLIC
PROC [e: EvaluatedExpressionNode]
RETURNS [ProgramGraphNode] ~ {
WITH e
SELECT
FROM
i: REF computed EvaluatedExpressionNodeBody => RETURN[i.code];
ENDCASE;
ERROR EvExpTypeError;
};
DoTargetMachineOp:
PUBLIC
PROC [op:
ATOM, lhs, rhs: EvaluatedExpressionNode]
RETURNS [res: EvaluatedExpressionNode] ~
BEGIN
SELECT op
FROM
$add => res ← MakeIntegerEvExp[IntegerEvExpVal[lhs] + IntegerEvExpVal[rhs]]
ENDCASE;
END;