copiers.red 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. % COPIERS.RED - Functions for copying various data types
  2. %
  3. % Author: Eric Benson
  4. % Symbolic Computation Group
  5. % Computer Science Dept.
  6. % University of Utah
  7. % Date: 27 August 1981
  8. % Copyright (c) 1981 University of Utah
  9. %
  10. % <PSL.KERNEL>COPIERS.RED.2, 28-Sep-82 10:21:15, Edit by PERDUE
  11. % Made CopyStringToFrom safe and to not bother clearing the
  12. % terminating byte.
  13. on SysLisp;
  14. syslsp procedure CopyStringToFrom(New, Old); %. Copy all chars in Old to New
  15. begin scalar SLen, StripNew, StripOld;
  16. StripNew := StrInf New;
  17. StripOld := StrInf Old;
  18. SLen := StrLen StripOld;
  19. if StrLen StripNew < SLen then SLen := StrLen StripNew;
  20. for I := 0 step 1 until SLen do
  21. StrByt(StripNew, I) := StrByt(StripOld, I);
  22. return New;
  23. end;
  24. syslsp procedure CopyString S; %. copy to new heap string
  25. begin scalar S1;
  26. S1 := GtSTR StrLen StrInf S;
  27. CopyStringToFrom(S1, StrInf S);
  28. return MkSTR S1;
  29. end;
  30. syslsp procedure CopyWArray(New, Old, UpLim); %. copy UpLim + 1 words
  31. << for I := 0 step 1 until UpLim do
  32. New[I] := Old[I];
  33. New >>;
  34. syslsp procedure CopyVectorToFrom(New, Old); %. Move elements, don't recurse
  35. begin scalar SLen, StripNew, StripOld;
  36. StripNew := VecInf New;
  37. StripOld := VecInf Old;
  38. SLen := VecLen StripOld; % assumes VecLen New has been set
  39. for I := 0 step 1 until SLen do
  40. VecItm(StripNew, I) := VecItm(StripOld, I);
  41. return New;
  42. end;
  43. syslsp procedure CopyVector S; %. Copy to new vector in heap
  44. begin scalar S1;
  45. S1 := GtVECT VecLen VecInf S;
  46. CopyVectorToFrom(S1, VecInf S);
  47. return MkVEC S1;
  48. end;
  49. syslsp procedure CopyWRDSToFrom(New, Old); %. Like CopyWArray in heap
  50. begin scalar SLen, StripNew, StripOld;
  51. StripNew := WrdInf New;
  52. StripOld := WrdInf Old;
  53. SLen := WrdLen StripOld; % assumes WrdLen New has been set
  54. for I := 0 step 1 until SLen do
  55. WrdItm(StripNew, I) := WrdItm(StripOld, I);
  56. return New;
  57. end;
  58. syslsp procedure CopyWRDS S; %. Allocate new WRDS array in heap
  59. begin scalar S1;
  60. S1 := GtWRDS WrdLen WrdInf S;
  61. CopyWRDSToFrom(S1, WrdInf S);
  62. return MkWRDS S1;
  63. end;
  64. % CopyPairToFrom is RplacW, found in EASY-NON-SL.RED
  65. % CopyPair is: car S . cdr S;
  66. % Usual Lisp definition of Copy only copies pairs, is found in EASY-NON-SL.RED
  67. syslsp procedure TotalCopy S; %. Unique copy of entire structure
  68. begin scalar Len, Ptr, StripS; % blows up on circular structures
  69. return case Tag S of
  70. PAIR:
  71. TotalCopy car S . TotalCopy cdr S;
  72. STR:
  73. CopyString S;
  74. VECT:
  75. << StripS := VecInf S;
  76. Len := VecLen StripS;
  77. Ptr := MkVEC GtVECT Len;
  78. for I := 0 step 1 until Len do
  79. VecItm(VecInf Ptr, I) := TotalCopy VecItm(VecInf S, I);
  80. Ptr >>;
  81. WRDS:
  82. CopyWRDS S;
  83. FIXN:
  84. MkFIXN Inf CopyWRDS S;
  85. FLTN:
  86. MkFLTN Inf CopyWRDS S;
  87. default:
  88. S
  89. end;
  90. end;
  91. off SysLisp;
  92. END;