-- JaMTSFrameImpl.mesa
-- Last changed by Paxton,  2-Feb-82 12:53:07

DIRECTORY
  JaMTSFrame;

JaMTSFrameImpl: MONITOR
  EXPORTS JaMTSFrame = {
  OPEN JaMTSFrame;

TSList: TYPE = REF TSFrame;
TSFrame: TYPE = RECORD [rest: TSList, ts: TS, frame: Frame, tsi: TSInfo];
list: TSList;

Remember: PUBLIC ENTRY PROC [ts: TS, frame: Frame, tsi: TSInfo] = {
	ENABLE UNWIND => NULL;
	-- establish two-way connection between ts and frame
	-- called when create the typescript
	FOR l:TSList ← list, l.rest UNTIL l=NIL DO
		IF l.ts=ts THEN ERROR;
		ENDLOOP;
	list ← NEW[TSFrame ← [list,ts,frame,tsi]] };

Forget: PUBLIC ENTRY PROC [ts: TS] = {
	-- forget the connection.  called when destroy ts
	ENABLE UNWIND => NULL;
	pred: TSList;
	IF list=NIL THEN RETURN;
	IF list.ts=ts THEN { list ← list.rest; RETURN };
	pred ← list;
	FOR l:TSList ← list.rest, l.rest UNTIL l=NIL DO
		IF l.ts=ts THEN { pred.rest ← l.rest; RETURN };
		pred ← l; ENDLOOP };

GetFrame: PUBLIC ENTRY PROC [ts: TS] RETURNS [Frame] = {
	ENABLE UNWIND => NULL;
	-- return the frame associated with ts
	-- returns NIL if no association exists
	FOR l:TSList ← list, l.rest UNTIL l=NIL DO
		IF l.ts=ts THEN RETURN [l.frame];
		ENDLOOP;
	RETURN [NIL] };

GetTypeScript: PUBLIC ENTRY PROC [frame: Frame] RETURNS [TS] = {
	ENABLE UNWIND => NULL;
	-- return the ts associated with frame
	-- returns NIL if no association exists
	FOR l:TSList ← list, l.rest UNTIL l=NIL DO
		IF l.frame=frame THEN RETURN [l.ts];
		ENDLOOP;
	RETURN [NIL] };

GetTSInfo: PUBLIC ENTRY PROC [ts: TS] RETURNS [TSInfo] = {
	ENABLE UNWIND => NULL;
	-- return the TSInfo associated with ts
	-- returns NIL if no association exists
	FOR l:TSList ← list, l.rest UNTIL l=NIL DO
		IF l.ts=ts THEN RETURN [l.tsi];
		ENDLOOP;
	RETURN [NIL] };

}.