TypePutProp:
PUBLIC
PROC [type: Type ← nullType, prop:
REF
ANY, val:
REF
ANY] = {
OPEN AMTypes;
underType: Type = UnderType[type];
class: Class = TypeClass[underType];
typeInfo: REF TypeRecord;
IF class = ref
OR class = list
OR AMList.IsAList[underType: underType]
THEN {
if type is a ref type, attach to referent as well, so that if you start with the ref, and therefore can only obtain type for its referent, will still be able to find the type attachment.. IF there were a way of getting to type REF FOO from type FOO, then this would be unnecessary because if you wanted to know whether REF FOO had a type attachment and you had a FOO in hand, you would simply construct that type.
referentType: Type ← GetCanonicalType[Range[type]];
typeInfo ← NARROW[GetTypeAttachment[referentType]];
IF typeInfo =
NIL
THEN
{typeInfo ← NEW[TypeRecord ← []];
PutTypeAttachment[referentType, typeInfo]
};
typeInfo.forRefThis ← Atom.PutPropOnList[typeInfo.forRefThis, prop, val];
};
type ← GetCanonicalType[type];
typeInfo ← NARROW[GetTypeAttachment[type]];
IF typeInfo =
NIL
THEN
{typeInfo ← NEW[TypeRecord ← []];
PutTypeAttachment[type, typeInfo]
};
typeInfo.forThis ← Atom.PutPropOnList[typeInfo.forThis, prop, val];
}; -- of TypePutProp
TypeGetProp:
PUBLIC
PROC [type: Type ← nullType, prop:
REF
ANY, dereferenced:
BOOLEAN ←
FALSE, ref:
REF
ANY ←
NIL]
RETURNS[
REF
ANY] =
{
typeInfo: REF TypeRecord;
IF type = nullType
THEN TRUSTED {
IF ref #
NIL
THEN {
type ← AMTypes.TVType[AMBridge.TVForReferent[ref]];
dereferenced ← TRUE;
}
ELSE RETURN[NIL];
};
type ← GetCanonicalType[type];
typeInfo ← NARROW[GetTypeAttachment[type]];
IF typeInfo = NIL THEN RETURN[NIL];
RETURN[Atom.GetPropFromList[IF dereferenced THEN typeInfo.forRefThis ELSE typeInfo.forThis, prop]];
}; -- of TypeGetProp