! Integerfns TRAPPED FREE CHUNKS and TRAPPED FREE STORE return
! the NUMBER OF and SPACE OCCUPIED BY the chunks of
! space on the heap's list of "holes".

! Routine AMALGAMATE HEAP causes any adjacent holes in the heap
! to be joined together to form bigger holes.

%externalroutinespec mark
%externalroutinespec release

%recordformat heap hole fm -
 (%byte level %or %integer size,
  %record(*)%name next,prev)

%recordformat heap base fm -
 (%integer limit,
  (%byte level %or %integer size),
  %record(*)%name link,holes)

@724(a5)%record(heap base fm)%name b

%externalintegerfn trapped free store
%record(heap hole fm)%name h == b_holes
%integer s=0
  %while h##nil %cycle
    s = s+h_size&16_ffffff; h == h_next
  %repeat
  %result = s
%end

%externalintegerfn trapped free chunks
%record(heap hole fm)%name h == b_holes
%integer n=0
  %while h##nil %cycle
    n = n+1; h == h_next
  %repeat
  %result = n
%end

%externalroutine amalgamate trapped chunks
  mark
  release
%end
