COMPACT.LST 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. Listing:
  2. 1 IMPLEMENTATION MODULE Compact;
  3. 2
  4. 3 (* A memory handler that allows the heap to be compacted *)
  5. 4 (* For the time being will only work with one 64K segment *)
  6. 5 (* Note that this is for demonstration purposes and therefore is designed
  7. 6 to be visible rather than fast. A rewrite would be in order before using
  8. 7 this thing in anger*)
  9. 8
  10. 9 IMPORT Storage,Lib;
  11. 10
  12. 11 VAR
  13. 12 Head:MemRecP; (* If more that one segment this would be more complex *)
  14. ***** ^ undeclared identifier
  15. 13 NextHandle:HandleType;
  16. ***** ^ undeclared identifier
  17. 14
  18. 15 PROCEDURE MergeBlanks();
  19. 16 VAR
  20. 17 Finger:MemRecP;
  21. ***** ^ undeclared identifier
  22. 18 BEGIN
  23. 19 Finger:=Head;
  24. ***** ^ not supported yet
  25. ***** ^ not supported yet
  26. 20 WHILE (Finger<>NIL) AND (Finger^.Next<>NIL) DO
  27. ***** ^ not supported yet
  28. ***** ^ not supported yet
  29. ***** ^ not supported yet
  30. 21 IF (Finger^.Handle=NotAHandle) AND (Finger^.Next^.Handle=NotAHandle) THEN
  31. ***** ^ not supported yet
  32. ***** ^ not supported yet
  33. ***** ^ undeclared identifier
  34. ***** ^ not supported yet
  35. ***** ^ not supported yet
  36. ***** ^ not supported yet
  37. ***** ^ undeclared identifier
  38. 22 Finger^.Length:=Finger^.Length+Finger^.Next^.Length+SIZE(MemRec);
  39. ***** ^ not supported yet
  40. ***** ^ not supported yet
  41. ***** ^ not supported yet
  42. ***** ^ not supported yet
  43. ***** ^ not supported yet
  44. ***** ^ not supported yet
  45. ***** ^ not supported yet
  46. ***** ^ undeclared identifier
  47. ***** ^ undeclared identifier
  48. 23 Finger^.Next:=Finger^.Next^.Next
  49. ***** ^ not supported yet
  50. ***** ^ not supported yet
  51. ***** ^ not supported yet
  52. ***** ^ not supported yet
  53. ***** ^ not supported yet
  54. 24 ELSE
  55. 25 Finger:=Finger^.Next;
  56. ***** ^ not supported yet
  57. ***** ^ not supported yet
  58. ***** ^ not supported yet
  59. 26 END;
  60. 27 END
  61. 28 END MergeBlanks;
  62. ***** ^ not supported yet
  63. 29
  64. 30 PROCEDURE Deallocate(x:HandleType);
  65. ***** ^ undeclared identifier
  66. 31 VAR
  67. 32 Finger:MemRecP;
  68. ***** ^ undeclared identifier
  69. 33 BEGIN
  70. 34 Finger:=Head;
  71. ***** ^ not supported yet
  72. ***** ^ not supported yet
  73. 35 WHILE (Finger<>NIL) AND (Finger^.Handle<>x) DO
  74. ***** ^ not supported yet
  75. ***** ^ not supported yet
  76. ***** ^ not supported yet
  77. ***** ^ not supported yet
  78. 36 Finger:=Finger^.Next
  79. ***** ^ not supported yet
  80. ***** ^ not supported yet
  81. ***** ^ not supported yet
  82. 37 END;
  83. 38 IF Finger<>NIL THEN
  84. ***** ^ not supported yet
  85. 39 Finger^.Handle:=NotAHandle;
  86. ***** ^ not supported yet
  87. ***** ^ not supported yet
  88. ***** ^ undeclared identifier
  89. 40 MergeBlanks();
  90. ***** ^ not supported yet
  91. ***** ^ not supported yet
  92. 41 END
  93. 42 END Deallocate;
  94. ***** ^ not supported yet
  95. 43
  96. 44 PROCEDURE CompactMemory();
  97. 45 VAR
  98. 46 Temp,Finger:MemRecP;
  99. ***** ^ undeclared identifier
  100. 47 OldSize,ComingSize:CARDINAL;
  101. 48 BEGIN
  102. 49 Finger:=Head;
  103. ***** ^ not supported yet
  104. ***** ^ not supported yet
  105. 50 WHILE (Finger<>NIL) AND (Finger^.Next<>NIL) DO
  106. ***** ^ not supported yet
  107. ***** ^ not supported yet
  108. ***** ^ not supported yet
  109. 51 IF Finger^.Handle=NotAHandle THEN (* Two blanks so merge *)
  110. ***** ^ not supported yet
  111. ***** ^ not supported yet
  112. ***** ^ undeclared identifier
  113. 52 ComingSize:=Finger^.Next^.Length+SIZE(MemRec);
  114. ***** ^ not supported yet
  115. ***** ^ not supported yet
  116. ***** ^ not supported yet
  117. ***** ^ undeclared identifier
  118. ***** ^ undeclared identifier
  119. 53 IF Finger^.Next^.Handle=NotAHandle THEN
  120. ***** ^ not supported yet
  121. ***** ^ not supported yet
  122. ***** ^ not supported yet
  123. ***** ^ undeclared identifier
  124. 54 Finger^.Length:=Finger^.Length+ComingSize;
  125. ***** ^ not supported yet
  126. ***** ^ not supported yet
  127. ***** ^ not supported yet
  128. ***** ^ not supported yet
  129. 55 Finger^.Next:=Finger^.Next^.Next;
  130. ***** ^ not supported yet
  131. ***** ^ not supported yet
  132. ***** ^ not supported yet
  133. ***** ^ not supported yet
  134. ***** ^ not supported yet
  135. 56 ELSE
  136. 57 OldSize:=Finger^.Length;
  137. ***** ^ not supported yet
  138. ***** ^ not supported yet
  139. 58 Lib.Move(Finger^.Next,Finger,ComingSize); (* Move data down *)
  140. ***** ^ not supported yet
  141. ***** ^ not supported yet
  142. ***** ^ not supported yet
  143. ***** ^ not supported yet
  144. ***** ^ not supported yet
  145. ***** ^ not supported yet
  146. 59 Temp:=Lib.AddAddr(Finger,ComingSize); (* Create the new blank record *)
  147. ***** ^ not supported yet
  148. ***** ^ not supported yet
  149. ***** ^ not supported yet
  150. ***** ^ not supported yet
  151. ***** ^ not supported yet
  152. 60 Temp^.Handle:=NotAHandle;
  153. ***** ^ not supported yet
  154. ***** ^ not supported yet
  155. ***** ^ undeclared identifier
  156. 61 Temp^.Length:=OldSize;
  157. ***** ^ not supported yet
  158. ***** ^ not supported yet
  159. 62 Temp^.Next:=Finger^.Next;
  160. ***** ^ not supported yet
  161. ***** ^ not supported yet
  162. ***** ^ not supported yet
  163. ***** ^ not supported yet
  164. 63 Finger^.Next:=Temp;
  165. ***** ^ not supported yet
  166. ***** ^ not supported yet
  167. ***** ^ not supported yet
  168. 64 END
  169. 65 ELSE
  170. 66 Finger:=Finger^.Next;
  171. ***** ^ not supported yet
  172. ***** ^ not supported yet
  173. ***** ^ not supported yet
  174. 67 END
  175. 68 END;
  176. 69 END CompactMemory;
  177. ***** ^ not supported yet
  178. 70
  179. 71 PROCEDURE DerefHandle(x:HandleType):ADDRESS;
  180. ***** ^ undeclared identifier
  181. ***** ^ undeclared identifier
  182. 72 VAR
  183. 73 Finger:MemRecP;
  184. ***** ^ undeclared identifier
  185. 74 BEGIN
  186. 75 Finger:=Head;
  187. ***** ^ not supported yet
  188. ***** ^ not supported yet
  189. 76 WHILE (Finger<>NIL) AND (Finger^.Handle<>x) DO
  190. ***** ^ not supported yet
  191. ***** ^ not supported yet
  192. ***** ^ not supported yet
  193. ***** ^ not supported yet
  194. 77 Finger:=Finger^.Next
  195. ***** ^ not supported yet
  196. ***** ^ not supported yet
  197. ***** ^ not supported yet
  198. 78 END;
  199. 79 IF Finger=NIL THEN
  200. ***** ^ not supported yet
  201. 80 RETURN ADDRESS(0)
  202. ***** ^ undeclared identifier
  203. ***** ^ not supported yet
  204. 81 ELSE
  205. 82 RETURN Lib.AddAddr(Finger,SIZE(MemRec))
  206. ***** ^ not supported yet
  207. ***** ^ not supported yet
  208. ***** ^ not supported yet
  209. ***** ^ undeclared identifier
  210. ***** ^ undeclared identifier
  211. 83 END
  212. 84 END DerefHandle;
  213. ***** ^ not supported yet
  214. 85
  215. 86 PROCEDURE Allocate(size:CARDINAL):HandleType;
  216. ***** ^ undeclared identifier
  217. 87 VAR
  218. 88 SecondTry:BOOLEAN;
  219. 89 Value:HandleType;
  220. ***** ^ undeclared identifier
  221. 90 Temp,Finger:MemRecP;
  222. ***** ^ undeclared identifier
  223. 91 BEGIN
  224. 92 SecondTry:=TRUE;
  225. 93 IF size<SmallestAlloc THEN
  226. ***** ^ undeclared identifier
  227. 94 size:=SmallestAlloc
  228. ***** ^ undeclared identifier
  229. 95 END;
  230. 96 Value:=NotAHandle;
  231. ***** ^ not supported yet
  232. ***** ^ undeclared identifier
  233. 97 REPEAT
  234. 98 SecondTry:=NOT SecondTry;
  235. 99 Finger:=Head;
  236. ***** ^ not supported yet
  237. ***** ^ not supported yet
  238. 100 WHILE (Finger<>NIL) AND (
  239. ***** ^ not supported yet
  240. 101 (Finger^.Handle<>NotAHandle) OR (Finger^.Length<size)) DO
  241. ***** ^ not supported yet
  242. ***** ^ not supported yet
  243. ***** ^ undeclared identifier
  244. ***** ^ not supported yet
  245. ***** ^ not supported yet
  246. 102 Finger:=Finger^.Next
  247. ***** ^ not supported yet
  248. ***** ^ not supported yet
  249. ***** ^ not supported yet
  250. 103 END;
  251. 104 IF Finger=NIL THEN
  252. ***** ^ not supported yet
  253. 105 IF NOT SecondTry THEN
  254. 106 CompactMemory
  255. ***** ^ not supported yet
  256. 107 END
  257. 108 ELSE
  258. 109 INC(NextHandle);
  259. ***** ^ undeclared identifier
  260. ***** ^ not supported yet
  261. 110 Value:=NextHandle;
  262. ***** ^ not supported yet
  263. ***** ^ not supported yet
  264. 111 IF Finger^.Length>size+SIZE(MemRec) THEN (* Insert new blank record *)
  265. ***** ^ not supported yet
  266. ***** ^ not supported yet
  267. ***** ^ undeclared identifier
  268. ***** ^ undeclared identifier
  269. 112 Temp:=Lib.AddAddr(Finger,size+SIZE(MemRec));
  270. ***** ^ not supported yet
  271. ***** ^ not supported yet
  272. ***** ^ not supported yet
  273. ***** ^ not supported yet
  274. ***** ^ undeclared identifier
  275. ***** ^ undeclared identifier
  276. 113 Temp^.Length:=Finger^.Length-size-SIZE(MemRec);
  277. ***** ^ not supported yet
  278. ***** ^ not supported yet
  279. ***** ^ not supported yet
  280. ***** ^ not supported yet
  281. ***** ^ undeclared identifier
  282. ***** ^ undeclared identifier
  283. 114 Temp^.Handle:=NotAHandle;
  284. ***** ^ not supported yet
  285. ***** ^ not supported yet
  286. ***** ^ undeclared identifier
  287. 115 Temp^.Next:=Finger^.Next;
  288. ***** ^ not supported yet
  289. ***** ^ not supported yet
  290. ***** ^ not supported yet
  291. ***** ^ not supported yet
  292. 116 Finger^.Next:=Temp;
  293. ***** ^ not supported yet
  294. ***** ^ not supported yet
  295. ***** ^ not supported yet
  296. 117 Finger^.Length:=size;
  297. ***** ^ not supported yet
  298. ***** ^ not supported yet
  299. 118 ELSE
  300. 119 size:=Finger^.Length;
  301. ***** ^ not supported yet
  302. ***** ^ not supported yet
  303. 120 END;
  304. 121 Finger^.Handle:=Value;
  305. ***** ^ not supported yet
  306. ***** ^ not supported yet
  307. ***** ^ not supported yet
  308. 122 END;
  309. 123 UNTIL SecondTry OR (Value<>NotAHandle);
  310. ***** ^ not supported yet
  311. ***** ^ undeclared identifier
  312. 124 RETURN Value;
  313. ***** ^ not supported yet
  314. 125 END Allocate;
  315. ***** ^ not supported yet
  316. 126
  317. 127 BEGIN
  318. 128 Storage.ALLOCATE(Head,64*1024);
  319. ***** ^ not supported yet
  320. ***** ^ not supported yet
  321. ***** ^ not supported yet
  322. ***** ^ not supported yet
  323. 129 Head^.Length:=64*1024-SIZE(MemRec);
  324. ***** ^ not supported yet
  325. ***** ^ not supported yet
  326. ***** ^ undeclared identifier
  327. ***** ^ undeclared identifier
  328. 130 Head^.Next:=NIL;
  329. ***** ^ not supported yet
  330. ***** ^ not supported yet
  331. 131 Head^.Handle:=MAX(CARDINAL);
  332. ***** ^ not supported yet
  333. ***** ^ not supported yet
  334. ***** ^ undeclared identifier
  335. ***** ^ not supported yet
  336. 132 NextHandle:=NotAHandle;
  337. ***** ^ not supported yet
  338. ***** ^ undeclared identifier
  339. 133 END Compact.
  340. ***** ^ not supported yet
  341. 206 errors