-- TiogaAlloc.mesa -- written by Bill Paxton, March 1981 -- last edit by Bill Paxton, March 18, 1981 3:49 PM DIRECTORY RopeReader, RunReader, Rope; TiogaAlloc: DEFINITIONS = BEGIN OPEN ropeRI:RopeReader, runRI:RunReader, r:Rope; CharsArray: TYPE = RopeReader.CharsArray; Chars: TYPE = REF CharsArray; Rope: TYPE = r.Ref; AllocChars: PROC [len: NAT] RETURNS [chars: Chars, start: NAT, base: Rope]; -- allocates room for len characters -- chars is the array to hold them starting at start -- base is rope pointing to the entire chars array AllocWords: PROC [nwords: NAT] RETURNS [chars: Chars, start: NAT, base: Rope]; -- ensures that start is even, i.e., start on word boundary TryAllocAdjacent: PROC [base: Rope, start: NAT, len: NAT] RETURNS [ok: BOOLEAN, chars: Chars]; -- if base is current CharsArray -- and start is current next free loc in base -- and there are at least len free chars remaining -- then allocates those chars and returns true -- the next routines provide caches of readers -- so can avoid creating a lot of garbage GetRopeReader: PROC RETURNS [reader: ropeRI.Ref]; FreeRopeReader: PROC [reader: ropeRI.Ref]; GetRunReader: PROC RETURNS [reader: runRI.Ref]; FreeRunReader: PROC [reader: runRI.Ref]; END.