-- Storage.mesa  Last Edited by Sandman on June 30, 1980  5:05 PM
-- Copyright  Xerox Corporation 1979, 1980

DIRECTORY
  AltoDefs USING [PageSize];

Storage: DEFINITIONS =
  BEGIN

  ZoneTooSmall: ERROR [POINTER];
  InvalidNode: ERROR [POINTER];

  Node: PROCEDURE [nwords: CARDINAL] RETURNS [p: POINTER];
  String: PROCEDURE [nchars: CARDINAL] RETURNS [s: STRING];
  Pages: PROCEDURE [npages: CARDINAL] RETURNS [base: POINTER];
  Words: PROCEDURE [nwords: CARDINAL] RETURNS [base: POINTER];

  Free: PROCEDURE [p: POINTER];
  FreeString: PROCEDURE [s: STRING];
  FreePages, FreeWords: PROCEDURE [base: POINTER];

  FreeNodeNil: PROCEDURE [p: POINTER] RETURNS [nil: POINTER] = INLINE
    BEGIN Free[p]; RETURN[NIL] END;

  FreeStringNil: PROCEDURE [s: STRING] RETURNS [nil: STRING] = INLINE
    BEGIN Free[s]; RETURN[NIL] END;

  FreePagesNil: PROCEDURE [base: POINTER] RETURNS [nil: POINTER] = INLINE
    BEGIN FreePages[base]; RETURN[NIL] END;

  Expand: PROCEDURE [pages: CARDINAL];
  Prune: PROCEDURE RETURNS [BOOLEAN];

  CopyString: PROCEDURE [s: STRING, longer: CARDINAL ← 0] RETURNS [newS: STRING];
  ExpandString: PROCEDURE [s: POINTER TO STRING, longer: CARDINAL];

  EmptyString: PROCEDURE [s: STRING] RETURNS [BOOLEAN] = INLINE
    BEGIN RETURN[s = NIL OR s.length = 0] END;

  PagesForWords: PROCEDURE [nWords: CARDINAL] RETURNS [CARDINAL] = INLINE
    BEGIN RETURN[(nWords + AltoDefs.PageSize - 1)/AltoDefs.PageSize] END;

  StringLength: PROCEDURE [s: STRING] RETURNS [CARDINAL] = INLINE
    BEGIN RETURN[IF s = NIL THEN 0 ELSE s.length] END;

  HeapZone: PROCEDURE RETURNS [POINTER];

  END.