p-allocators.red 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. % Revisions, MLG, 20 Feb 1983
  10. % Moved space declarations to XXX-HEADER.RED
  11. % <PSL.KERNEL>ALLOCATORS.RED.4, 10-Jan-83 15:50:50, Edit by PERDUE
  12. % Added GtEVect
  13. on SysLisp;
  14. external Wvar HeapLowerBound,
  15. HeapUpperBound,
  16. HeapLast,
  17. HeapPreviousLast,
  18. NextBPS,
  19. LastBPS;
  20. % NextSymbol is in GLOBAL-DATA.RED
  21. syslsp procedure GtHEAP N;
  22. % get heap block of N words
  23. if null N then (HeapUpperBound - HeapLast) / AddressingUnitsPerItem else
  24. << HeapPreviousLast := HeapLast;
  25. HeapLast := HeapLast + N*AddressingUnitsPerItem;
  26. if HeapLast > HeapUpperBound then
  27. << !%Reclaim();
  28. HeapPreviousLast := HeapLast;
  29. HeapLast := HeapLast + N*AddressingUnitsPerItem;
  30. if HeapLast > HeapUpperBound then
  31. FatalError "Heap space exhausted" >>;
  32. HeapPreviousLast >>;
  33. syslsp procedure DelHeap(LowPointer, HighPointer);
  34. if HighPointer eq HeapLast then HeapLast := LowPointer;
  35. syslsp procedure GtSTR N;
  36. % Allocate space for a string N chars
  37. begin scalar S, NW;
  38. S := GtHEAP((NW := STRPack N) + 1);
  39. @S := MkItem(HBytes, N);
  40. S[NW] := 0; % clear last word, including last byte
  41. return S;
  42. end;
  43. syslsp procedure GtConstSTR N;
  44. % allocate un-collected string for print name
  45. begin scalar S, NW; % same as GtSTR, but uses BPS, not heap
  46. S := GtBPS((NW := STRPack N) + 1);
  47. @S := N;
  48. S[NW] := 0; % clear last word, including last byte
  49. return S;
  50. end;
  51. syslsp procedure GtHalfWords N;
  52. % Allocate space for N halfwords
  53. begin scalar S, NW;
  54. S := GtHEAP((NW := HalfWordPack N) + 1);
  55. @S := MkItem(HHalfWords, N);
  56. return S;
  57. end;
  58. syslsp procedure GtVECT N;
  59. % Allocate space for a vector N items
  60. begin scalar V;
  61. V := GtHEAP(VECTPack N + 1);
  62. @V := MkItem(HVECT, N);
  63. return V;
  64. end;
  65. syslsp procedure GtEVECT N;
  66. % Allocate space for a Evector N items
  67. begin scalar V;
  68. V := GtHEAP(VECTPack N + 1);
  69. @V := MkItem(HVECT, N);
  70. return V;
  71. end;
  72. syslsp procedure GtWRDS N;
  73. % Allocate space for N untraced words
  74. begin scalar W;
  75. W := GtHEAP(WRDPack N + 1);
  76. @W := MkItem(HWRDS, N);
  77. return W;
  78. end;
  79. syslsp procedure GtFIXN();
  80. % allocate space for a fixnum
  81. begin scalar W;
  82. W := GtHEAP(WRDPack 0 + 1);
  83. @W := MkItem(HWRDS, 0);
  84. return W;
  85. end;
  86. syslsp procedure GtFLTN();
  87. % allocate space for a float
  88. begin scalar W;
  89. W := GtHEAP(WRDPack 1 + 1);
  90. @W := MkItem(HWRDS, 1);
  91. return W;
  92. end;
  93. syslsp procedure GtID();
  94. % Allocate a new ID
  95. %
  96. % IDs are allocated as a linked free list through the SymNam cell,
  97. % with a 0 to indicate the end of the list.
  98. %
  99. begin scalar U;
  100. if NextSymbol = 0 then
  101. << Reclaim();
  102. if NextSymbol = 0 then
  103. return FatalError "Ran out of ID space" >>;
  104. U := NextSymbol;
  105. NextSymbol := SymNam U;
  106. return U;
  107. end;
  108. syslsp procedure GtBPS N;
  109. % Allocate N words for binary code
  110. begin scalar B;
  111. if null N then return((LastBPS - NextBPS)/AddressingUnitsPerItem);
  112. % GTBPS NIL returns # left
  113. B := NextBPS;
  114. NextBPS := NextBPS + N*AddressingUnitsPerItem;
  115. return if NextBPS > LastBPS then
  116. StdError '"Ran out of binary program space"
  117. else B;
  118. end;
  119. syslsp procedure DelBPS(Bottom, Top);
  120. % Return space to BPS
  121. if NextBPS eq Top then NextBPS := Bottom;
  122. syslsp procedure GtWArray N;
  123. % Allocate N words for WVar/WArray/WString
  124. begin scalar B;
  125. if null N then return((LastBPS - NextBPS)/AddressingUnitsPerItem);
  126. % GtWArray NIL returns # left
  127. B := LastBPS - N*AddressingUnitsPerItem;
  128. return if NextBPS > B then
  129. StdError '"Ran out of WArray space"
  130. else
  131. LastBPS := B;
  132. end;
  133. syslsp procedure DelWArray(Bottom, Top);
  134. % Return space for WArray
  135. if LastBPS eq Bottom then LastBPS := Top;
  136. off SysLisp;
  137. END;