-- RTTypesBasic.Mesa
-- last edited May 27, 1982 12:51 pm by Paul Rovner

DIRECTORY
  RTBasic USING[Type, nullType];

RTTypesBasic: CEDAR DEFINITIONS
= BEGIN

  Type: TYPE = RTBasic.Type;
    
      -- predefined Types
    nullType: Type = RTBasic.nullType;
    unspecType: Type = [1];  -- the distinguished type of UNSPECIFIED
    fhType: Type = [2];  -- the distinguished type of localFrames
    gfhType: Type = [3]; -- the distinguished type of globalFrames
    listOfRefAnyType: Type = [4];
    refAnyType: Type = [5];
    anyType: Type = [6];
               -- There will be other predefined Types.

  -- PROCS --

  GetReferentType: PROC[ref: REF ANY] RETURNS[type: Type];
  GetCanonicalReferentType: PROC[ref: REF ANY] RETURNS[type: Type];

  EquivalentTypes: PROC[t1, t2: Type] RETURNS[BOOLEAN];
  GetCanonicalType: PROC[type: Type] RETURNS[Type];

  IsReferentType: PROC[ref: REF ANY, type: Type] RETURNS[BOOLEAN];
  NarrowRef: PROC[ref: REF ANY, type: Type] RETURNS[REF ANY];
    -- Raises SafeStorage.NarrowRefFault

        -- Package finalization
-- BEWARE Establish finalization for a type BEFORE allocating any objects
-- of the type. Allocate objects of the type ONLY in the same program module in which
-- the calls to establish finalization appear. Use the exact same type expression in these
-- calls and in NEW expressions for objects of the type.

  maxNPackageRefs: CARDINAL = 2;

  FinalizationQueue: TYPE = PRIVATE RECORD[REF ANY];

  EstablishFinalization: PROC [type: Type, npr: [1..maxNPackageRefs], fq: FinalizationQueue];
  ReEstablishFinalization: PROC [type: Type, npr: [1..maxNPackageRefs], fq: FinalizationQueue];

  PutTypeAttachment: PROC[type: Type, attachment: REF ANY];
  GetTypeAttachment: PROC [type: Type] RETURNS[REF ANY];

  NewFQ: PROC[length: CARDINAL ← 10--refs--] RETURNS[FinalizationQueue];
  FQNext: PROC[fq: FinalizationQueue] RETURNS[REF ANY];  -- waits 'till there is one
  FQEmpty: PROC[fq: FinalizationQueue] RETURNS[BOOLEAN];


  -- SIGNALS and ERRORS --

  InvalidType: ERROR[type: Type];
  CantEstablishFinalization: ERROR[type: Type];

END.