mini-allocators.red 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. % MINI-ALLOC.RED : Crude Mini Allocator and support
  2. % See PT:P-ALLOCATORS.RED
  3. % Revisions: MLG, 18 Feb,1983
  4. % Moved HEAP declaration to XXX-HEADER
  5. % Had to provide an InitHeap routine
  6. % (or will be LoadTime :=)
  7. on syslisp;
  8. external Wvar HeapLowerBound, HeapUpperBound;
  9. external WVar HeapLast, % next free slot in heap
  10. HeapPreviousLast; % save start of new block
  11. syslsp procedure GtHEAP N;
  12. % get heap block of N words
  13. if null N then (HeapUpperBound - HeapLast) / AddressingUnitsPerItem else
  14. << HeapPreviousLast := HeapLast;
  15. HeapLast := HeapLast + N*AddressingUnitsPerItem;
  16. if HeapLast > HeapUpperBound then
  17. << !%Reclaim();
  18. HeapPreviousLast := HeapLast;
  19. HeapLast := HeapLast + N*AddressingUnitsPerItem;
  20. if HeapLast > HeapUpperBound then
  21. FatalError "Heap space exhausted" >>;
  22. HeapPreviousLast >>;
  23. syslsp procedure GtSTR N;
  24. % Allocate space for a string N chars
  25. begin scalar S, NW;
  26. S := GtHEAP((NW := STRPack N) + 1);
  27. @S := MkItem(HBytes, N);
  28. S[NW] := 0; % clear last word, including last byte
  29. return S;
  30. end;
  31. syslsp procedure GtVECT N;
  32. % Allocate space for a vector N items
  33. begin scalar V;
  34. V := GtHEAP(VECTPack N + 1);
  35. @V := MkItem(HVECT, N);
  36. return V;
  37. end;
  38. Procedure GtWarray N;
  39. % Dummy for Now, since no GC
  40. GtVect N;
  41. Procedure GtID();
  42. % Simple ID Allocator
  43. Begin scalar D;
  44. D:=NextSymbol;
  45. NextSymbol:=NextSymbol+1;
  46. return D;
  47. End;
  48. Off syslisp;
  49. End;