-- LongStreams.mesa  Edited by Sandman on September 4, 1980  6:34 PM

DIRECTORY
  Segments USING [
    Access, AllAccess, DefaultAccess, FHandle, Read, ReadWrite, Write],
  StreamDefs USING [
    CleanupDiskStream, CreateByteStream, FileLength, GetPosition,
    IndexToPosition, NewByteStream, SetPosition, StreamError,
    StreamHandle];


Streams: DEFINITIONS IMPORTS StreamDefs =
  BEGIN

  Address: TYPE = LONG POINTER;

  -- Assert: The word POINTER does not appear below here.

  Handle: TYPE = PRIVATE StreamDefs.StreamHandle;

  Access: TYPE = PRIVATE Segments.Access;
  AllAccess: Access = Segments.AllAccess;
  DefaultAccess: Access = Segments.DefaultAccess;
  Read: Access = Segments.Read;
  ReadWrite: Access = Segments.ReadWrite;
  Write: Access = Segments.Write;

  End: PROCEDURE RETURNS [SIGNAL [UNSPECIFIED]] = INLINE {
    RETURN[LOOPHOLE[StreamDefs.StreamError]]};

  Cleanup: PROCEDURE [h: Handle] = INLINE {StreamDefs.CleanupDiskStream[h]};

  CreateStream: PROCEDURE [file: Segments.FHandle, access: Access ← Read]
    RETURNS [Handle] = INLINE {RETURN[StreamDefs.CreateByteStream[file, access]]};

  Destroy: PROCEDURE [h: Handle] = INLINE {h.destroy[h]};

  GetIndex: PROCEDURE [h: Handle] RETURNS [LONG CARDINAL] = INLINE {
    RETURN[StreamDefs.GetPosition[h]]};

  GetLength: PROCEDURE [h: Handle] RETURNS [LONG CARDINAL] = INLINE {
    RETURN[StreamDefs.IndexToPosition[StreamDefs.FileLength[h]]]};

  NewStream: PROCEDURE [name: STRING, access: Access ← Read] RETURNS [Handle] =
    INLINE {RETURN[StreamDefs.NewByteStream[name, access]]};

  SetIndex: PROCEDURE [h: Handle, i: LONG CARDINAL] = INLINE {
    StreamDefs.SetPosition[h, i]};

  GetBlock: PROCEDURE [h: Handle, a: Address, words: CARDINAL] RETURNS [CARDINAL];

  GetByte: PROCEDURE [h: Handle] RETURNS [UNSPECIFIED [0..256)] = INLINE {
    RETURN[h.get[h]]};

  GetWord: PROCEDURE [h: Handle] RETURNS [UNSPECIFIED] = INLINE {
    t: CARDINAL = CARDINAL[h.get[h]]*256; RETURN[h.get[h] + t]};

  PutBlock: PROCEDURE [h: Handle, a: Address, words: CARDINAL] RETURNS [CARDINAL];

  PutByte: PROCEDURE [h: Handle, u: UNSPECIFIED [0..256)] = INLINE {h.put[h, u]};

  PutWord: PROCEDURE [h: Handle, u: UNSPECIFIED] = INLINE {
    h.put[h, CARDINAL[u]/256]; h.put[h, CARDINAL[u] MOD 256]};

  END.