TypePack.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Satterthwaite, February 17, 1983 4:51 pm
Rovner, July 6, 1983 1:42 pm
Russ Atkinson (RRA) January 31, 1985 1:15:53 pm PST
DIRECTORY
ConvertUnsafe USING [SubString, EqualSubStrings],
SymbolTable USING [Base],
Symbols USING [Name, SEIndex, ISEIndex, CSEIndex, RecordSEIndex, CTXIndex, MDIndex, nullName, MDNull, OwnMdi, ISENull, RecordSENull, StandardContext, typeANY, typeTYPE],
Types USING [Handle];
RecordHandle:
TYPE =
RECORD [
stb: SymbolTable.Base,
sei: RecordSEIndex];
MatchFields:
PROC [rec1, rec2: RecordHandle]
RETURNS [
BOOL] = {
OPEN b1: rec1.stb, b2: rec2.stb;
sei1, sei2: ISEIndex;
IF rec1.sei = RecordSENull
OR rec2.sei = RecordSENull
THEN RETURN [rec1.sei = rec2.sei];
IF EqContexts[[rec1.stb, b1.seb[rec1.sei].fieldCtx], [rec2.stb, b2.seb[rec2.sei].fieldCtx]]
THEN RETURN [TRUE];
sei1 ← b1.FirstCtxSe[b1.seb[rec1.sei].fieldCtx];
sei2 ← b2.FirstCtxSe[b2.seb[rec2.sei].fieldCtx];
UNTIL sei1 = ISENull
OR sei2 = ISENull
DO
IF ~(Equal[[rec1.stb, b1.seb[sei1].idType], [rec2.stb, b2.seb[sei2].idType]]
AND
EqualIds[[rec1.stb, b1.seb[sei1].hash], [rec2.stb, b2.seb[sei2].hash]])
THEN RETURN [FALSE];
sei1 ← b1.NextSe[sei1]; sei2 ← b2.NextSe[sei2];
ENDLOOP;
RETURN [sei1 = sei2]};
CheckFields:
PROC [rec1, rec2: RecordHandle, mode: Mode]
RETURNS [
BOOL] = {
OPEN b1: rec1.stb, b2: rec2.stb;
sei1, sei2: ISEIndex;
checkIds: BOOL;
IF rec1.sei = RecordSENull
OR rec2.sei = RecordSENull
THEN RETURN [rec1.sei = rec2.sei];
IF EqContexts[[rec1.stb, b1.seb[rec1.sei].fieldCtx], [rec2.stb, b2.seb[rec2.sei].fieldCtx]]
THEN RETURN [TRUE];
checkIds ← ~(b1.seb[rec1.sei].hints.unifield OR b2.seb[rec2.sei].hints.unifield);
sei1 ← b1.FirstCtxSe[b1.seb[rec1.sei].fieldCtx];
sei2 ← b2.FirstCtxSe[b2.seb[rec2.sei].fieldCtx];
UNTIL sei1 = ISENull
OR sei2 = ISENull
DO
IF ~Conformable[[rec1.stb, b1.seb[sei1].idType], [rec2.stb, b2.seb[sei2].idType], mode]
OR (checkIds
AND
b1.seb[sei1].hash # nullName AND b2.seb[sei2].hash # nullName AND
~EqualIds[[rec1.stb, b1.seb[sei1].hash], [rec2.stb, b2.seb[sei2].hash]])
THEN RETURN [FALSE];
sei1 ← b1.NextSe[sei1]; sei2 ← b2.NextSe[sei2];
ENDLOOP;
RETURN [sei1 = sei2]};
MatchConstants:
PROC [context1, context2: CTXHandle]
RETURNS [
BOOL] = {
OPEN b1: context1.stb, b2: context2.stb;
sei1, sei2: ISEIndex;
IF EqContexts[context1, context2] THEN RETURN [TRUE];
sei1 ← b1.FirstCtxSe[context1.ctx];
sei2 ← b2.FirstCtxSe[context2.ctx];
UNTIL sei1 = ISENull
OR sei2 = ISENull
DO
IF ~EqualIds[[context1.stb, b1.seb[sei1].hash], [context2.stb, b2.seb[sei2].hash]]
THEN RETURN [FALSE];
sei1 ← b1.NextSe[sei1]; sei2 ← b2.NextSe[sei2];
ENDLOOP;
RETURN [sei1 = sei2]};
ISEHandle:
TYPE =
RECORD [
stb: SymbolTable.Base,
sei: ISEIndex];
MatchTags:
PROC [tag1, tag2: ISEHandle]
RETURNS [
BOOL] = {
OPEN b1: tag1.stb, b2: tag2.stb;
RETURN [
EqualIds[[tag1.stb, b1.seb[tag1.sei].hash], [tag2.stb, b2.seb[tag2.sei].hash]] AND
Equal[[tag1.stb, b1.seb[tag1.sei].idType], [tag2.stb, b2.seb[tag2.sei].idType]]]};
Covering:
PROC [typeL, typeR: Types.Handle]
RETURNS [
BOOL] = {
OPEN bL: typeL.stb, bR: typeR.stb;
IF typeL = typeR THEN RETURN [TRUE];
RETURN [
WITH tL: bL.seb[typeL.sei]
SELECT
FROM
array =>
WITH tR: bR.seb[typeR.sei]
SELECT
FROM
array =>
tL.packed = tR.packed
AND Equivalent[
[typeL.stb, bL.UnderType[tL.componentType]],
[typeR.stb, bR.UnderType[tR.componentType]]]
AND Conformable[[typeL.stb, tL.indexType], [typeR.stb, tR.indexType], val],
ENDCASE => FALSE,
ENDCASE => Equivalent[typeL, typeR]]};
FullRangeType:
PROC [type: Types.Handle]
RETURNS [Types.Handle] = {
OPEN b: type.stb;
sei, next: CSEIndex;
FOR sei ← type.sei, next
DO
WITH b.seb[sei]
SELECT
FROM
subrange => next ← b.UnderType[rangeType];
ENDCASE => EXIT;
ENDLOOP;
RETURN [[type.stb, sei]]};
}.