-- UnsafeStorage.Mesa
-- last edited May 20, 1982 10:06 am by Paul Rovner

DIRECTORY
  RTBasic USING[Type, nullType],
  SafeStorage USING[SizeRepresentation];

UnsafeStorage: DEFINITIONS
= BEGIN OPEN RTBasic;

    -- instead of uz.NEW (useful if types are used or if explicit control of the size arg is required)
  NewUObject: PROC  -- used when NEW won't do, e.g for type-carrying heap objects
            [ size: CARDINAL,  -- words 
              zone: UNCOUNTED ZONE,
              type: Type ← nullType
            ] RETURNS [LONG POINTER];

  GetHeapReferentType: PROC[ptr: LONG POINTER] RETURNS[type: Type];

  NewUZone: PROC
            [ initialSize: LONG CARDINAL ← 0,  -- words
              sr: SafeStorage.SizeRepresentation ← prefixed,
              typeRepresentation: BOOLEAN ← FALSE
            ] RETURNS[UNCOUNTED ZONE];

  FreeUZone: PROC[uz: UNCOUNTED ZONE];
   -- releases all storage associeated with the zone. Beware of dangling pointers!

  ExtendUZone: UZoneFullProc;

    UZoneFullProc: TYPE = PROC[zone: UNCOUNTED ZONE, size: LONG CARDINAL--words--];
  SetUZoneFullProc: PROC  -- default is ExtendUZone
            [ zone: UNCOUNTED ZONE, 
              proc: UZoneFullProc
            ] RETURNS[oldProc: UZoneFullProc];

  MergeUZone: PROC[zone: UNCOUNTED ZONE];  -- for prefixed UNCOUNTED ZONEs
  
  TrimUZone: PROC[zone: UNCOUNTED ZONE];

  IsUZoneEmpty: PROC[zone: UNCOUNTED ZONE] RETURNS[BOOLEAN];
   --TRUE if no quanta are assigned to it

    -- Access to the pre-defined UNCOUNTED ZONE
  GetSystemUZone: PROC RETURNS[UNCOUNTED ZONE];  -- a prefixed UNCOUNTED ZONE

-- SIGNALs and ERRORs

  InvalidPointer: ERROR[ptr: LONG POINTER];  -- Raised by FREE

END.