-- file Table.Mesa
-- last modified by Satterthwaite, July 30, 1980  10:32 AM
-- Copyright  Xerox Corporation 1979, 1980

DIRECTORY
  Bases: TYPE USING [
    Base, BaseDescriptor, Finger, Index, IPointer, Limit, OrderedIndex,
    SizeDescriptor];

Table: DEFINITIONS =
  BEGIN

  Selector: TYPE = CARDINAL;

  Base: TYPE = Bases.Base;
  Finger: TYPE = Bases.Finger;
  Limit: CARDINAL = Bases.Limit;
  Index: TYPE = Bases.Index;
  OrderedIndex: TYPE = Bases.OrderedIndex;

  IPointer: TYPE = Bases.IPointer;

  BaseDescriptor: TYPE = Bases.BaseDescriptor;
  SizeDescriptor: TYPE = Bases.SizeDescriptor;

  -- allocation from the tables as stacks

  Allocate: PROC [table: Table.Selector, size: CARDINAL]
    RETURNS [Table.OrderedIndex];
  Bounds: PROC [table: Table.Selector] RETURNS [base: Table.Base, size: CARDINAL];
  Top: PROC [table: Table.Selector] RETURNS [Table.OrderedIndex] = INLINE {
    RETURN[FIRST[Table.OrderedIndex] + Bounds[table].size]};

  Trim: PROC [table: Table.Selector, size: CARDINAL];

  -- allocation from free list (first table only)

  chunkType: Table.Selector = FIRST[Table.Selector];

  GetChunk: PROC [size: CARDINAL] RETURNS [Table.Index];
  FreeChunk: PROC [index: Table.Index, size: CARDINAL];

  -- inquiries

  WordsUsed: PROC RETURNS [CARDINAL];
  WordsFree: PROC RETURNS [CARDINAL];

  -- notification of repacking

  Notifier: TYPE = PROC [base: Table.BaseDescriptor];

  AddNotify: PROC [proc: Table.Notifier];
  DropNotify: PROC [proc: Table.Notifier];

  -- initialization and termination

  Region: TYPE = RECORD [origin: Table.Base, size: CARDINAL];

  Create: PROC [region: Table.Region, weights: DESCRIPTOR FOR ARRAY OF CARDINAL];
  Destroy: PROC;

  Overflow: SIGNAL RETURNS [Region];
  Failure: ERROR [table: Table.Selector];

  END.