p-allocators.red 4.1 KB

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