-- RCMapOps.mesa
  -- Last Modified By Paul Rovner On June 30, 1982 5:25 pm

DIRECTORY
  RCMap: TYPE USING[Base, Index],
  SymbolTable: TYPE USING[Base],
  Symbols: TYPE USING[SEIndex, MDIndex];
    
RCMapOps: DEFINITIONS
= BEGIN 

-- TYPEs

  MapMap: TYPE = LONG POINTER TO MapMapObj;  -- built by Include
  MapMapObj: TYPE;  -- OPAQUE

    -- Establish the specified Base as the "current" one.
    -- If expansionZone # NIL then ignore ptr and get a new RCMap.Base with
    -- size = nPages from expansionZone.
  Initialize: PROC[ptr: RCMap.Base,
                   nPages: CARDINAL,
                   expansionZone: UNCOUNTED ZONE ← NIL];

  Finalize: PROC;

    -- Establish an Outer proc
  EstablishOuter: PROC[outerProc: PROC [stb: SymbolTable.Base,
                                                mdi: Symbols.MDIndex,
                                                inner: PROC[base: SymbolTable.Base]]];

    -- Retrieve info about the current RCMap.Base
  GetBase: PROC RETURNS[base: RCMap.Base, nWords: CARDINAL];

    -- Returns an RCMap.Index in the current RCMap.Base of the RCMap for the specified type.
    -- Makes an entry if necessary.
  Acquire: PROC[stb: SymbolTable.Base, sei: Symbols.SEIndex] RETURNS[rcmx: RCMap.Index];

    -- Merges the specified RCMap.Base into the current one.
    -- If zone # NIL, allocates and returns a MapMap 
  Include: PROC[rcmb: RCMap.Base, nWords: CARDINAL, zone: UNCOUNTED ZONE ← NIL] RETURNS[MapMap];

    -- Does a MapMap lookup: returns the index in the current RCMap.Base that corresponds
    -- to the specified index in the RCMap.Base that Include processed.
  FindMapMapEntry: PROC[mapMap: MapMap, oldIndex: RCMap.Index] RETURNS[RCMap.Index];

  Enumerate: PROC[base: RCMap.Base,
                  nWords: CARDINAL,
                  proc: PROC[RCMap.Index] RETURNS[stop: BOOLEAN]]
      RETURNS[stopped: BOOLEAN];

END.

BEWARE: if you specify an expansionZone, you must be careful about concurrent access to
the current Base. In the current system, for performance
reasons (access to the base would have to be protected with a monitor), the Cedar runtime
does not specify an expansion zone (ERROR if RCMap Base overflows). Because it has its
own RCMap.Base and it has only one process, the compiler is able to specify an expansion
zone (and does so) without needing a monitor.