SaffronInstanceImpl.Mesa
Copyright Ó 1988 by Xerox Corporation. All rights reserved.
James Rauen, June 20, 1988 4:34:50 pm PDT
Last edited by: James Rauen July 12, 1988 11:26:47 am PDT
DIRECTORY
Basics USING [Comparison],
BigCardinals USING [BigAdd, BigCARD, BigCompare, BigDivMod, BigFromBinaryRope, BigFromDecimalRope, BigFromSmall, BigMultiply, BigSubtract, BigToDecimalRope, BigZero, FirstOneBit, Zero],
IO USING [bool, int, PutFR, PutR, rope],
Rope USING [ActionType, Cat, Fetch, ROPE, Substr],
SaffronBaseDef USING [LocalContextNode, ProgramGraphNode],
SaffronContextPrivateTypes USING [BaseTypeTGNBody, TypeGraphNodeListNodeBody, TypeGraphNodeNodeBody],
SaffronErrorHandling USING [Error, InternalError, Message],
SaffronInstance,
SaffronTargetArchitecture USING [TargetArchitecture];
SaffronInstanceImpl:
CEDAR
PROGRAM
IMPORTS BigCardinals, IO, Rope, SaffronErrorHandling
EXPORTS SaffronBaseDef, SaffronInstance
~ BEGIN
Nicknames
ROPE: TYPE ~ Rope.ROPE;
LocalContextNode: TYPE ~ SaffronBaseDef.LocalContextNode;
ProgramGraphNode: TYPE ~ SaffronBaseDef.ProgramGraphNode;
TypeGraphNodeNode: TYPE ~ REF TypeGraphNodeNodeBody;
TypeGraphNodeNodeBody: PUBLIC TYPE ~ SaffronContextPrivateTypes.TypeGraphNodeNodeBody;
TypeGraphNodeListNode: TYPE ~ REF TypeGraphNodeListNodeBody;
TypeGraphNodeListNodeBody: PUBLIC TYPE ~ SaffronContextPrivateTypes.TypeGraphNodeListNodeBody;
TargetArchitecture: TYPE ~ SaffronTargetArchitecture.TargetArchitecture;
Generic Operations
Static:
PUBLIC
PROC [i: InstanceNode]
RETURNS [
BOOLEAN] ~
BEGIN
RETURN [i.instanceKind = static];
END;
RuntimeValue:
PUBLIC
PROC [i: InstanceNode]
RETURNS [
BOOLEAN] ~
BEGIN
RETURN [i.instanceKind = runtime];
END;
Trash:
PUBLIC
PROC [i: InstanceNode]
RETURNS [
BOOLEAN] ~
BEGIN
RETURN [i.instanceKind = trash];
END;
Type:
PUBLIC
PROC [i: InstanceNode]
RETURNS [TypeGraphNodeNode] ~
BEGIN
RETURN [i.type];
END;
ChangeType:
PUBLIC
PROC [i: InstanceNode, newType: TypeGraphNodeNode]
RETURNS [InstanceNode] ~
BEGIN
IF newType = NIL THEN ERROR SaffronErrorHandling.InternalError["Tried to change type to NIL"];
RETURN [
NEW[InstanceNodeBody ←
WITH i
SELECT
FROM
ii: REF static InstanceNodeBody => [newType, i.code, static[ii.concreteRepresentation]],
ii: REF runtime InstanceNodeBody => [newType, i.code, runtime[]],
ii: REF trash InstanceNodeBody => [newType, i.code, trash[]],
ENDCASE => ERROR
]];
END;
Code:
PUBLIC
PROC [i: InstanceNode]
RETURNS [ProgramGraphNode] ~
BEGIN
RETURN[i.code];
END;
GetConcreteRepresentation:
PROC [i: InstanceNode]
RETURNS [
REF
ANY] ~
BEGIN
WITH i
SELECT
FROM
ii:
REF static InstanceNodeBody =>
RETURN[ii.concreteRepresentation];
ii:
REF runtime InstanceNodeBody =>
ERROR SaffronErrorHandling.InternalError[ "SaffronInstanceImpl.GetConcreteRepresentation called with runtime instance."];
ii:
REF trash InstanceNodeBody =>
ERROR SaffronErrorHandling.InternalError[ "SaffronInstanceImpl.GetConcreteRepresentation called with trash instance."];
ENDCASE;
RETURN[NIL]; -- to make the compiler happy
END;
RopeFromInstance:
PUBLIC
PROC [i: InstanceNode]
RETURNS [
ROPE] ~
BEGIN
RETURN [
WITH i
SELECT
FROM
ii: REF static InstanceNodeBody => RopeFromStaticInstance[ii],
ii: REF runtime InstanceNodeBody => "[RUNTIME VALUE]",
ii: REF trash InstanceNodeBody => "TRASH"
ENDCASE => ERROR
];
END;
RopeFromStaticInstance:
PROC [i:
REF static InstanceNodeBody]
RETURNS [
ROPE] ~
BEGIN
concreteRep: REF ANY = i.concreteRepresentation;
r:
ROPE ←
WITH concreteRep
SELECT
FROM
v: IntegerValue => UnparseIntegerValue[v, 10],
v: REF BOOLEAN => IO.PutR[IO.bool[v^]],
ENDCASE => "can't print it";
RETURN[Rope.Cat["STATIC[", r, "]"]];
END;
Constructed Types
MakeSubRange: PUBLIC PROC [low, high: InstanceNode, subRangeType: TypeGraphNodeNode] RETURNS [i: InstanceNode] ~ BEGIN
i ← NEW[InstanceNodeBody ← [TRUE, subRangeType, elements]];
MakeList: PUBLIC PROC [elements: LIST OF InstanceNode, listType: TypeGraphNodeNode] RETURNS [i: InstanceNode] ~ BEGIN
-- i ← NEW[InstanceNodeBody ← [listType, NIL, elements]];
-- FOR e: LIST OF InstanceNode ← elements, e.rest WHILE (e.first # NIL) DO
-- IF e.first.Static = FALSE THEN i.Static ← FALSE;
-- IF Incompatible[element.type, listType.elementType] THEN error...
-- ENDLOOP;
-- if this winds up being a not-compile-time-constant, then we need to return consing code.
RETURN [NEW[InstanceNodeBody ← [NIL, NIL, trash[]]]];