-- RTTypesBasicPrivate.Mesa
-- last edited December 21, 1982 2:30 pm by Paul Rovner

DIRECTORY
BcdDefs USING[SGIndex, SGNull],
BcdOps USING[BcdBase],
RCMap USING[Index, nullIndex, Limit],
RTBasic USING[TypeIndex, Pointer, Type, nullType],
RTQueue USING[Q, qNil],
RTSymbolDefs USING[SymbolTableHandle, nullHandle, SymbolIndex, nullSymbolIndex],
TimeStamp USING[Stamp],
TypeStrings USING[TypeString];

RTTypesBasicPrivate: DEFINITIONS
SHARES RTBasic

= BEGIN OPEN RTBasic, RTSymbolDefs;

-- Cedar System Internal goodies

-- Types --

-- The Runtime Type Table: maps TypeIndex to TypeDesc
RMapTiTd: TYPE = RECORD[ptds: SEQUENCE length: NAT OF PTypeDesc];
TMapTiTd: TYPE = LONG POINTER TO RMapTiTd;
MapTiTd: TMapTiTd;

PTypeDesc: TYPE = LONG POINTER TO TypeDesc;

TypeDesc: TYPE = MACHINE DEPENDENT RECORD
[ equivalentTypePad: [0..3] ← 0,
equivalentType: Type ← nullType, -- nullType means not "canonicalized"
nPackageRefsPad: [0..1] ← 0,
nPackageRefs: NAT ← 0, -- ucode does not depend on stuff below
rcmx: RCMap.Index ← RCMap.nullIndex,
fill: [0..LAST[CARDINAL]/RCMap.Limit] ← 0,
utf: UniqueTypeFinger,
symbolAccess: SymbolAccess,
next: PTypeDesc ← NIL, -- link in list of types with the same ts hash
myTypePad: [0..3] ← 0,
myType: Type, -- a back pointer(logically)
typeStructure: TypeStructure,
extension: PTypeExtension ← NIL -- LOOPHOLE
];

PTypeExtension: TYPE = LONG POINTER TO TypeExtension; -- LOOPHOLE

RTypeExtension: TYPE = REF TypeExtension;

TypeExtension: TYPE = RECORD [next: RTypeExtension, -- link in the list of them; stay honest
finalizationSet: RTQueue.Q ← RTQueue.qNil,
attachment: REF ANYNIL];

-- Access to symbol table information

PreDefinedSEI: TYPE = CARDINAL[0..249];

SymbolAccess: TYPE = RECORD[sti: SymbolTableIndex ← 0,
sei: SymbolIndex ← nullSymbolIndex];
SymbolTableIndex: TYPE = NAT; -- index into MapStiStd

MapStiStd: TMapStiStd; -- The map from SymbolTableIndex to STDesc
TMapStiStd: TYPE = LONG POINTER TO RMapStiStd;
RMapStiStd: TYPE = RECORD[stiv: SEQUENCE length: SymbolTableIndex OF PSTDesc];

-- A STDesc describes options for finding the bits of a particular symbol table as follows:
--If bcd=NIL, the symbolsStamp identifies a compiler-created .bcd file with
--version=symbolsStamp, and sth is a valid SymbolTableHandle.
--else if sgi # SGNull, the symbolsStamp matches a (possibly composite) .bcd
--or .symbols file version stamp, and the sgi identifies the symbol table
--within bcd.
--else if sgi = SGNull, the symbolsStamp matches an entry in bcd's file table,
--which identifies a compiler-created .bcd file with version=symbolsStamp.
PSTDesc: TYPE = LONG POINTER TO STDesc;
STDesc: TYPE = RECORD [symbolsStamp: TimeStamp.Stamp,
bcd: BcdOps.BcdBase ← NIL,
sgi: BcdDefs.SGIndex ← BcdDefs.SGNull,
sth: SymbolTableHandle ← nullHandle];



TypeStructure: TYPE = TypeStrings.TypeString;
-- support for NARROW and runtime type-equivalence determination: canonical types.

UniqueTypeFinger: TYPE = RECORD[umid: TimeStamp.Stamp, -- of original defining module
seIndex: SymbolIndex];-- type seIndex therein

useCanonicalTypeMicroCode: BOOLEAN; -- exported variable


-- Procedures --

-- for CedarProbe
GetLastTypeIndex: PROC RETURNS[TypeIndex];

-- for RTStartImpl
GetCanonicalReferentTypeSDTrap: PROC[ref: REF ANY] RETURNS[type: Type];
GetReferentTypeTrap: PROC[ref: REF ANY] RETURNS[type: Type];
GetCanonicalReferentTypeTrap: PROC[ref: REF ANY] RETURNS[type: Type];
CheckForNarrowRefFault: PROC[ref: REF ANY, targetType: Type] RETURNS[REF ANY];

NPackageRefs: PROC[type: Type] RETURNS[NAT] = INLINE
{RETURN[MapTiTd[type].nPackageRefs]};

MapTiRcmx: PROC[ti: TypeIndex] RETURNS[RCMap.Index] = INLINE
{RETURN[MapTiTd[ti].rcmx]};

PutForFinalization: PROC[type: Type, ref: REF ANY] RETURNS[done: BOOLEAN];

MapRefs: PROC[ptr: LONG POINTER, rcmx: RCMap.Index, procLeaf: PROC[p: REF ANY]];
MapRefOffsets: PROC[ref: REF ANY, procLeaf: PROC[offset: LONG CARDINAL]];
DoFREEify: PROC[ptr: Pointer, rcmx: RCMap.Index, procLeaf: PROC[p: REF ANY]];

GetMapTiTd: PROC RETURNS[TMapTiTd];

NotifyAtomRecType: PROC[type: Type];

AcquireTypeForLoader: PROC[utf: UniqueTypeFinger,
std: STDesc,
sei: SymbolIndex,
ts: TypeStructure,
rcmi: RCMap.Index,
canonicalize: BOOLEANFALSE]
RETURNS[Type];

-- for supporting RTTypes
MakeNewType: PROC[utf: UniqueTypeFinger,
std: STDesc,
sei: SymbolIndex,
ts: TypeStructure,
rcmx: RCMap.Index,
canonicalize: BOOLEANFALSE,
type: Type ← nullType]
RETURNS[Type];

FindSTI: PROC[std: STDesc] RETURNS[i: SymbolTableIndex];

FindCanonicalPTD: PROC[ts: TypeStructure] RETURNS[ptd: PTypeDesc];

FindPTD: PROC[utf: UniqueTypeFinger, ts: TypeStructure ← NIL] RETURNS[ptd: PTypeDesc];

Enter: PROC[inner: PROC];

END.