allocators.red 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. %
  2. % ALLOCATORS.RED - Low level storage management
  3. %
  4. % Author: Eric Benson
  5. % Computer Science Dept.
  6. % University of Utah
  7. % Date: 27 August 1981
  8. % Copyright (c) 1981 University of Utah
  9. %
  10. % Edit by Cris Perdue, 16 Feb 1983 1834-PST
  11. % Pre-GC trap, known-free-space fns
  12. % <PSL.KERNEL>ALLOCATORS.RED.4, 10-Jan-83 15:50:50, Edit by PERDUE
  13. % Added GtEVect
  14. on SysLisp;
  15. external WArray BPS, Heap;
  16. if_system(PDP10, << % For the compacting GC
  17. exported WVar HeapLast = &Heap[0], % pointer to next free slot in heap
  18. HeapLowerBound = &Heap[0], % bottom of heap
  19. HeapUpperBound = &Heap[HeapSize],
  20. HeapTrapBound = &Heap[HeapSize]; % Value of HeapLast for trap
  21. >>, <<
  22. exported WVar HeapLast = &Heap[0], % pointer to next free slot in heap
  23. HeapLowerBound = &Heap[0], % bottom of heap
  24. HeapUpperBound = &Heap[HeapSize/2], % end of active heap
  25. OldHeapLast,
  26. OldHeapLowerBound = &Heap[HeapSize/2 + 1],
  27. OldHeapUpperBound = &Heap[HeapSize],
  28. HeapTrapBound = &Heap[HeapSize/2]; % Value of HeapLast for trap
  29. >>);
  30. exported WVar HeapTrapped = NIL; % Boolean: trap since last GC?
  31. compiletime flag('(GtHeap1), 'InternalFunction);
  32. syslsp procedure Known!-Free!-Space;
  33. MkInt((HeapUpperBound - HeapLast)/AddressingUnitsPerItem);
  34. syslsp procedure GtHEAP N; %. get heap block of N words
  35. if null N then known!-free!-space() else
  36. GtHeap1(N, NIL);
  37. syslsp procedure GtHeap1(N, LastTryP);
  38. begin scalar PrevLast;
  39. PrevLast := HeapLast;
  40. HeapLast := HeapLast + N*AddressingUnitsPerItem;
  41. if HeapLast > HeapTrapBound then
  42. if HeapLast > HeapUpperBound then
  43. << HeapLast := PrevLast;
  44. if LastTryP then FatalError "Heap space exhausted"
  45. else
  46. << !%Reclaim();
  47. return GtHeap1(N, T) >> >>
  48. else
  49. %% From one GC to the next there can be at most 1 GC trap,
  50. %% done the first time space gets "low". %Reclaim resets
  51. %% HeapTrapped to NIL.
  52. if HeapTrapped = NIL then
  53. << HeapTrapped := T;
  54. GC!-Trap() >>;
  55. return PrevLast
  56. end;
  57. syslsp procedure GC!-Trap!-Level;
  58. MkInt (HeapUpperBound - HeapTrapBound)/AddressingUnitsPerItem;
  59. syslsp procedure Set!-GC!-Trap!-Level N;
  60. << if not IntP(N) then NonIntegerError(N, 'Set!-GC!-Trap!-Level);
  61. N := IntInf N;
  62. HeapTrapBound := HeapUpperBound - N*AddressingUnitsPerItem;
  63. T >>;
  64. syslsp procedure DelHeap(LowPointer, HighPointer);
  65. if HighPointer eq HeapLast then HeapLast := LowPointer;
  66. syslsp procedure GtSTR N; %. Allocate space for a string N chars
  67. begin scalar S, NW;
  68. S := GtHEAP((NW := STRPack N) + 1);
  69. @S := MkItem(HBytes, N);
  70. S[NW] := 0; % clear last word, including last byte
  71. return S;
  72. end;
  73. syslsp procedure GtConstSTR N; %. allocate un-collected string for print name
  74. begin scalar S, NW; % same as GtSTR, but uses BPS, not heap
  75. S := GtBPS((NW := STRPack N) + 1);
  76. @S := N;
  77. S[NW] := 0; % clear last word, including last byte
  78. return S;
  79. end;
  80. syslsp procedure GtHalfWords N; %. Allocate space for N halfwords
  81. begin scalar S, NW;
  82. S := GtHEAP((NW := HalfWordPack N) + 1);
  83. @S := MkItem(HHalfWords, N);
  84. return S;
  85. end;
  86. syslsp procedure GtVECT N; %. Allocate space for a vector N items
  87. begin scalar V;
  88. V := GtHEAP(VECTPack N + 1);
  89. @V := MkItem(HVECT, N);
  90. return V;
  91. end;
  92. Putd('GtEvect,'expr,cdr getd 'GtVect);
  93. syslsp procedure GtWRDS N; %. Allocate space for N untraced words
  94. begin scalar W;
  95. W := GtHEAP(WRDPack N + 1);
  96. @W := MkItem(HWRDS, N);
  97. return W;
  98. end;
  99. syslsp procedure GtFIXN(); %. allocate space for a fixnum
  100. begin scalar W;
  101. W := GtHEAP(WRDPack 0 + 1);
  102. @W := MkItem(HWRDS, 0);
  103. return W;
  104. end;
  105. syslsp procedure GtFLTN(); %. allocate space for a float
  106. begin scalar W;
  107. W := GtHEAP(WRDPack 1 + 1);
  108. @W := MkItem(HWRDS, 1);
  109. return W;
  110. end;
  111. % NextSymbol and SymbolTableSize are globally declared
  112. syslsp procedure GtID(); %. Allocate a new ID
  113. %
  114. % IDs are allocated as a linked free list through the SymNam cell,
  115. % with a 0 to indicate the end of the list.
  116. %
  117. begin scalar U;
  118. if NextSymbol = 0 then
  119. << Reclaim();
  120. if NextSymbol = 0 then
  121. return FatalError "Ran out of ID space" >>;
  122. U := NextSymbol;
  123. NextSymbol := SymNam U;
  124. return U;
  125. end;
  126. exported WVar NextBPS = &BPS[0],
  127. LastBPS = &BPS[BPSSize];
  128. syslsp procedure GtBPS N; %. Allocate N words for binary code
  129. begin scalar B;
  130. if null N then return((LastBPS - NextBPS)/AddressingUnitsPerItem);
  131. % GTBPS NIL returns # left
  132. B := NextBPS;
  133. NextBPS := NextBPS + N*AddressingUnitsPerItem;
  134. return if NextBPS > LastBPS then
  135. StdError '"Ran out of binary program space"
  136. else B;
  137. end;
  138. syslsp procedure DelBPS(Bottom, Top); %. Return space to BPS
  139. if NextBPS eq Top then NextBPS := Bottom;
  140. syslsp procedure GtWArray N; %. Allocate N words for WVar/WArray/WString
  141. begin scalar B;
  142. if null N then return((LastBPS - NextBPS)/AddressingUnitsPerItem);
  143. % GtWArray NIL returns # left
  144. B := LastBPS - N*AddressingUnitsPerItem;
  145. return if NextBPS > B then
  146. StdError '"Ran out of WArray space"
  147. else
  148. LastBPS := B;
  149. end;
  150. syslsp procedure DelWArray(Bottom, Top); %. Return space for WArray
  151. if LastBPS eq Bottom then LastBPS := Top;
  152. off SysLisp;
  153. END;