-- LongStorage.mesa  Last Edited by
-- Sandman on June 30, 1980  5:05 PM
-- Karlton on July 16, 1980  6:02 PM
-- Johnsson on  5-Dec-80  8:50:26

DIRECTORY Environment USING [wordsPerPage];

LongStorage: DEFINITIONS =
  BEGIN
  
  ZoneTooSmall: ERROR [p: LONG POINTER];
  InvalidNode: ERROR [p: LONG POINTER];
  
  Node: PROCEDURE [nwords: CARDINAL] RETURNS [p: LONG POINTER];
  String: PROCEDURE [nchars: CARDINAL] RETURNS [s: LONG STRING];
  Pages: PROCEDURE [npages: CARDINAL] RETURNS [base: LONG POINTER];
  Words: PROCEDURE [nwords: CARDINAL] RETURNS [base: LONG POINTER];
  
  Free: PROCEDURE [p: LONG POINTER];
  FreeString: PROCEDURE [s: LONG STRING];
  FreePages, FreeWords: PROCEDURE [base: LONG POINTER];
  
  FreeNodeNil: PROCEDURE [p: LONG POINTER] RETURNS [LONG POINTER] = INLINE
    BEGIN Free[p]; RETURN[NIL] END;
    
  FreeStringNil: PROCEDURE [s: LONG STRING] RETURNS [LONG STRING] = INLINE
    BEGIN Free[s]; RETURN[NIL] END;
    
  FreePagesNil: PROCEDURE [base: LONG POINTER] RETURNS [LONG POINTER] = INLINE
    BEGIN FreePages[base]; RETURN[NIL] END;
    
  Expand: PROCEDURE [pages: CARDINAL];
  Prune: PROCEDURE RETURNS [BOOLEAN];
  
  CopyString: PROCEDURE [s: LONG STRING, longer: CARDINAL ← 0] RETURNS [newS: LONG STRING];
  ExpandString: PROCEDURE [s: LONG POINTER TO LONG STRING, longer: CARDINAL];
  
  EmptyString: PROCEDURE [s: LONG STRING] RETURNS [BOOLEAN] = INLINE
    BEGIN RETURN[s = NIL OR s.length = 0] END;
    
  PagesForWords: PROCEDURE [nWords: CARDINAL] RETURNS [CARDINAL] = INLINE
    BEGIN RETURN[(nWords + Environment.wordsPerPage - 1)/Environment.wordsPerPage] END;
    
  StringLength: PROCEDURE [s: LONG STRING] RETURNS [CARDINAL] = INLINE
    BEGIN RETURN[IF s = NIL THEN 0 ELSE s.length] END;
    
  HeapZone: PROCEDURE RETURNS [LONG POINTER];
  
  END.