-- File: DisjointProp.mesa
-- Routines to handle property lists
-- Written by Martin Newell/Dan Fitzpatrick June 1981
-- Last edited (Pilot): 16-Jul-81 14:27:
38

DIRECT
ORY

DisjointAllocDefs: FROM "DisjointAllocDefs" USING [AllocateProp, FreeProp],
DisjointTypes: FROM "DisjointTypes" USING [PropList, PropID],
DisjointPropDefs: FROM "DisjointPropDefs",
Inline: FROM "Inline" USING [LowHalf];

Disjo
intProp: PROGRAM
IMPORTS DisjointAllocDefs, Inline
EXPORTS DisjointPropDefs =
BEGIN
OPEN DisjointAllocDefs, DisjointTypes, Inline;

AllocPropID:
PUBLIC PROCEDURE[] RETURNS[PropID] =
-- Returns a uni
que PropID each time it is called
BEGIN
MaxPropID ← MaxPropID + 1;
RETURN[MaxPropID];
END;

PutProp: PUB
LIC PROCEDURE [list: LONG POINTER TO PropList, id: PropID, data: UNSPECIFIED] =
-- Enters data i
nto list with the specified PropID
-- Any data
already in list with the given PropID is overwritten
BEGIN
PutLongProp[list,id,LONG[data]];
END;

PutLongProp:
PUBLIC PROCEDURE [list: LONG POINTER TO PropList, id: PropID, data: LONG UNSPECIFIED] =
-- Enters long d
ata into list with the specified PropID
-- Any data
already in list with the given PropID is overwritten
BEGIN
prop: PropList ← FindProp[list↑,id];
IF prop # NIL THEN {
prop.data ← data;
}
ELSE {
prop ← FindProp[list↑, 0];
IF prop # NIL THEN {
prop.id ← id;
prop.data ← data;
}
ELSE {
prop ← AllocateProp[];
prop↑ ← [
next: list↑,
id: id,
data: data
];
list↑ ← prop;
}
}
END;

GetProp: PUB
LIC PROCEDURE [list: PropList, id: PropID] RETURNS[UNSPECIFIED] =
-- Finds data wi
th specified PropID from list
BEGIN
data: LONG UNSPECIFIED ← GetLongProp[list,id];
IF data = NIL THEN RETURN[NIL]
ELSE RETURN[LowHalf[data]];
END;

GetLongProp:
PUBLIC PROCEDURE [list: PropList, id: PropID] RETURNS[LONG UNSPECIFIED] =
-- Finds long da
ta with specified PropID from list
BEGIN
prop: PropList ← FindProp[list,id];
IF prop # NIL THEN RETURN[prop.data]
ELSE RETURN[LONG[NIL]];
END;

RemoveProp:
PUBLIC PROCEDURE [list: PropList, id: PropID] =
-- Removes any d
ata from list with the given PropID
BEGIN
prop: PropList ← FindProp[list,id];
IF prop # NIL THEN prop.id ← 0;
END;

FreePropList
: PUBLIC PROCEDURE [list: PropList] =
-- Frees all sto
rage used by list
BEGIN
next: PropList;
FOR prop: PropList ← list, next UNTIL prop = NIL DO
next ← prop.next;
FreeProp[prop];
ENDLOOP;
END;

FindProp: PR
OCEDURE [list: PropList, id: PropID] RETURNS[cell: PropList] =
-- Returns prope
rty cell found in list with given PropID
BEGIN
FOR cell ← list, cell.next UNTIL cell = NIL DO
IF cell.id = id THEN RETURN;
ENDLOOP;
END;

MaxPropID: CARDINAL ← 0;

END.