-- HeapImplAlto.mesa last edited by: HGM on: January 30, 1981  5:10 PM
-- From HeapImpl.mesa (last edited by: McJones on: August 5, 1980  1:54 PM)

DIRECTORY
  Heap USING [NWords],
  Inline USING [LowHalf],
  Storage USING [Node, Free];

HeapImplAlto: PROGRAM IMPORTS Inline, Storage EXPORTS Heap =
  BEGIN


  NWords: TYPE = Heap.NWords;

  systemZone: PUBLIC UNCOUNTED ZONE = LOOPHOLE[LONG[@uzo]];
  systemMDSZone: PUBLIC MDSZone = LOOPHOLE[@uzoMDS];

  standardProcs: Procs ← [Make: MakeNode, Free: FreeNode];
  uzo: UncountedZoneObject ← [@standardProcs, NIL];
  standardMDSProcs: MDSProcs ← [Make: MakeMDSNode, Free: FreeMDSNode];
  uzoMDS: MDSZoneObject ← [@standardMDSProcs, NIL];

  UncountedZoneRep: TYPE = LONG POINTER TO UncountedZoneObject;
  UncountedZoneObject: TYPE = MACHINE DEPENDENT RECORD [
    procs(0:0..31): LONG POINTER TO Procs, data(2:0..31): LONG POINTER];
  Procs: TYPE = MACHINE DEPENDENT RECORD [
    Make(0): PROCEDURE [UNCOUNTED ZONE, NWords] RETURNS [LONG POINTER],
    Free(1): PROCEDURE [UNCOUNTED ZONE, LONG POINTER]];

  MDSZoneRep: TYPE = POINTER TO MDSZoneObject;
  MDSZoneObject: TYPE = MACHINE DEPENDENT RECORD [
    procs(0:0..15): POINTER TO MDSProcs, data(1:0..15): POINTER];
  MDSProcs: TYPE = MACHINE DEPENDENT RECORD [
    Make(0): PROCEDURE [MDSZone, NWords] RETURNS [POINTER],
    Free(1): PROCEDURE [MDSZone, POINTER]];



  MakeNode: PUBLIC PROCEDURE [z: UNCOUNTED ZONE, n: NWords]
    RETURNS [p: LONG POINTER] = BEGIN RETURN[Storage.Node[n]]; END;

  FreeNode: PUBLIC PROCEDURE [z: UNCOUNTED ZONE, p: LONG POINTER] =
    BEGIN Storage.Free[Inline.LowHalf[p]]; END;

  MakeMDSNode: PUBLIC PROCEDURE [z: MDSZone, n: NWords] RETURNS [p: POINTER] =
    BEGIN RETURN[Storage.Node[n]]; END;

  FreeMDSNode: PUBLIC PROCEDURE [z: MDSZone, p: POINTER] =
    BEGIN Storage.Free[p]; END;

  END.