-- Transport mechanism: Heap implementation of R-Lists

-- [Juniper]<dms>MS>HeapRList.mesa

-- Andrew Birrell   4-Aug-80 16:19:12

DIRECTORY
  BodyDefs USING [RName],
  HeapDefs USING [
    HeapAbandonWrite, HeapEndRead, HeapEndWrite, HeapStartRead, HeapStartWrite,
    ObjectNumber, objectStart, ReaderHandle, ReadRList, ReceiveComponent,
    SetReaderOffset, WriterHandle],
  ProtocolDefs USING [Handle],
  RListDefs USING [];

HeapRList: PROGRAM IMPORTS HeapDefs EXPORTS RListDefs =

  BEGIN

  RListHandle: PUBLIC TYPE = HeapDefs.ReaderHandle;

  Receive: PUBLIC PROC [str: ProtocolDefs.Handle] RETURNS [list: RListHandle] =
    BEGIN
    writer: HeapDefs.WriterHandle = HeapDefs.HeapStartWrite[temp];
    Accept: PROC [obj: HeapDefs.ObjectNumber] = {
      list ← HeapDefs.HeapStartRead[obj]};
    HeapDefs.ReceiveComponent[
      writer, str ! UNWIND => HeapDefs.HeapAbandonWrite[writer]];
    HeapDefs.HeapEndWrite[writer, Accept];
    END;

  Enumerate: PUBLIC PROC [
    list: RListHandle, work: PROC [BodyDefs.RName] RETURNS [done: BOOLEAN]] =
    BEGIN
    HeapDefs.SetReaderOffset[list, HeapDefs.objectStart];
    HeapDefs.ReadRList[list, work];
    END;

  Close: PUBLIC PROC [list: RListHandle] = {HeapDefs.HeapEndRead[list]};

  END.