data-machine.red 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  1. %
  2. % DATA-MACHINE.RED - Macros for fast access to data structures
  3. %
  4. % Author: Eric Benson
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 5 April 1982
  9. % Copyright (c) 1982 University of Utah
  10. %
  11. % <PSL.COMP>DATA-MACHINE.RED.13, 30-Mar-83 11:03:57, Edit by KENDZIERSKI
  12. % Included the text from data-machine.build at the beginning of this file.
  13. % The file names w/extensions were getting too large for the VAX to deal with.
  14. % <PERDUE.PSL>DATA-MACHINE.RED.3, 28-Feb-83 12:28:57, Edit by PERDUE
  15. % Added nasty comments and proposed changes
  16. % <PSL.COMP>DATA-MACHINE.RED.10, 10-Jan-83 16:31:31, Edit by PERDUE
  17. % Added PutEvecLen for EVectors; this had been omitted
  18. % Edit by GRISS, 3Nov: Added missing EVEC operations
  19. % Primitives handled by the compiler are BYTE, PUTBYTE, GETMEM, PUTMEM,
  20. % MKITEM, FIELD, SIGNEDFIELD, PUTFIELD, HALFWORD, PUYTHALFWORD
  21. CompileTime << load if!-system, syslisp; % Assume still there, else load source
  22. off UserMode; >>;
  23. in "wdeclare.red"$
  24. CompileTime if_system(PDP10, << in "P20C:DEC20-DATA-MACHINE.RED"$ >>)$
  25. CompileTime if_system(VAX, << in "vax/vax-data-machine.red"$ >>)$
  26. CompileTime if_system(HP9836, << in "phpc:hp-data-machine.red"$ >>)$
  27. on Syslisp;
  28. off R2I;
  29. % These definitions are for interpretive testing of Syslisp code.
  30. % They may be dangerous in some cases.
  31. CommentOutCode <<
  32. syslsp procedure Byte(WAddr, ByteOffset);
  33. Byte(WAddr, ByteOffset);
  34. syslsp procedure PutByte(WAddr, ByteOffset, Val);
  35. PutByte(WAddr, ByteOffset, Val);
  36. syslsp procedure Halfword(WAddr, HalfwordOffset);
  37. Halfword(WAddr, HalfwordOffset);
  38. syslsp procedure PutHalfword(WAddr, HalfwordOffset, Val);
  39. PutHalfword(WAddr, HalfwordOffset, Val);
  40. syslsp procedure GetMem Addr;
  41. GetMem Addr;
  42. syslsp procedure PutMem(Addr, Val);
  43. PutMem(Addr, Val);
  44. syslsp procedure MkItem(TagPart, InfPart);
  45. MkItem(TagPart, InfPart);
  46. CommentOutCode << % can't do FIELD w/ non constants
  47. syslsp procedure Field(Cell, StartingBit, BitLength);
  48. Field(Cell, StartingBit, BitLength);
  49. syslsp procedure SignedField(Cell, StartingBit, BitLength);
  50. SignedField(Cell, StartingBit, BitLength);
  51. syslsp procedure PutField(Cell, StartingBit, BitLength, Val);
  52. PutField(Cell, StartingBit, BitLength, Val);
  53. >>;
  54. syslsp procedure WPlus2(R1, R2);
  55. WPlus2(R1, R2);
  56. syslsp procedure WDifference(R1, R2);
  57. WDifference(R1, R2);
  58. syslsp procedure WTimes2(R1, R2);
  59. WTimes2(R1, R2);
  60. syslsp procedure WQuotient(R1, R2);
  61. WQuotient(R1, R2);
  62. syslsp procedure WRemainder(R1, R2);
  63. WRemainder(R1, R2);
  64. syslsp procedure WMinus R1;
  65. WMinus R1;
  66. syslsp procedure WShift(R1, R2);
  67. WShift(R1, R2);
  68. syslsp procedure WAnd(R1, R2);
  69. WAnd(R1, R2);
  70. syslsp procedure WOr(R1, R2);
  71. WOr(R1, R2);
  72. syslsp procedure WXor(R1, R2);
  73. WXor(R1, R2);
  74. syslsp procedure WNot R1;
  75. WNot R1;
  76. syslsp procedure WLessP(R1, R2);
  77. WLessP(R1, R2);
  78. syslsp procedure WGreaterP(R1, R2);
  79. WGreaterP(R1, R2);
  80. syslsp procedure WLEQ(R1, R2);
  81. WLEQ(R1, R2);
  82. syslsp procedure WGEQ(R1, R2);
  83. WGEQ(R1, R2);
  84. >>;
  85. on R2I;
  86. off Syslisp;
  87. % SysLisp array accessing primitives
  88. syslsp macro procedure WGetV U;
  89. list('GetMem, list('WPlus2, cadr U, list('WTimes2, caddr U,
  90. '(WConst AddressingUnitsPerItem))));
  91. syslsp macro procedure WPutV U;
  92. list('PutMem, list('WPlus2, cadr U, list('WTimes2, caddr U,
  93. '(WConst AddressingUnitsPerItem))),
  94. cadddr U);
  95. % tags
  96. CompileTime <<
  97. lisp procedure DeclareTagRange(NameList, StartingValue, Increment);
  98. begin scalar Result;
  99. Result := list 'progn;
  100. while NameList do
  101. << Result := list('put, MkQuote car NameList,
  102. '(quote WConst),
  103. StartingValue)
  104. . Result;
  105. StartingValue := StartingValue + Increment;
  106. NameList := cdr NameList >>;
  107. return ReversIP Result;
  108. end;
  109. macro procedure LowTags U;
  110. DeclareTagRange(cdr U, 0, 1);
  111. macro procedure HighTags U;
  112. DeclareTagRange(cdr U, LSH(1, get('TagBitLength, 'WConst)) - 1, -1);
  113. >>;
  114. % JumpInType and friends depend on the ordering and contiguity of
  115. % the numeric type tags. Fast arithmetic depends on PosInt = 0,
  116. % NegInt = -1. Garbage collectors depend on pointer tags being
  117. % between PosInt and Code, non-inclusive. /csp
  118. LowTags(PosInt, FixN, BigN, FltN, Str, Bytes, HalfWords, Wrds, Vect, Pair,
  119. Evect);
  120. put('Code, 'WConst, 15);
  121. HighTags(NegInt, ID, Unbound, BtrTag, Forward,
  122. HVect, HWrds, HHalfWords, HBytes);
  123. % Item constructor macros
  124. lisp procedure MakeItemConstructor(TagPart, InfPart);
  125. list('MkItem, TagPart, InfPart);
  126. syslsp macro procedure MkBTR U;
  127. MakeItemConstructor('(wconst BtrTag), cadr U);
  128. syslsp macro procedure MkID U;
  129. MakeItemConstructor('(wconst ID), cadr U);
  130. syslsp macro procedure MkFIXN U;
  131. MakeItemConstructor('(wconst FIXN), cadr U);
  132. syslsp macro procedure MkFLTN U;
  133. MakeItemConstructor('(wconst FLTN), cadr U);
  134. syslsp macro procedure MkBIGN U;
  135. MakeItemConstructor('(wconst BIGN), cadr U);
  136. syslsp macro procedure MkPAIR U;
  137. MakeItemConstructor('(wconst PAIR), cadr U);
  138. syslsp macro procedure MkVEC U;
  139. MakeItemConstructor('(wconst VECT), cadr U);
  140. syslsp macro procedure MkEVECT U;
  141. MakeItemConstructor('(wconst EVECT), cadr U);
  142. syslsp macro procedure MkWRDS U;
  143. MakeItemConstructor('(wconst WRDS), cadr U);
  144. syslsp macro procedure MkSTR U;
  145. MakeItemConstructor('(wconst STR), cadr U);
  146. syslsp macro procedure MkBYTES U;
  147. MakeItemConstructor('(wconst BYTES), cadr U);
  148. syslsp macro procedure MkHalfWords U;
  149. MakeItemConstructor('(wconst HalfWords), cadr U);
  150. syslsp macro procedure MkCODE U;
  151. MakeItemConstructor('(wconst CODE), cadr U);
  152. % Access to tag (type indicator) of Lisp item in ordinary code
  153. syslsp macro procedure Tag U;
  154. list('Field, cadr U, '(wconst TagStartingBit), '(wconst TagBitLength));
  155. % Access to info field of item (pointer or immediate operand)
  156. syslsp macro procedure Inf U;
  157. list('Field, cadr U, '(wconst InfStartingBit), '(wconst InfBitLength));
  158. syslsp macro procedure PutInf U;
  159. list('PutField, cadr U, '(wconst InfStartingBit),
  160. '(wconst InfBitLength), caddr U);
  161. for each X in '(IDInf StrInf VecInf EvecInf PairInf WrdInf HalfWordInf CodeInf
  162. FixInf FltInf BigInf) do
  163. PutD(X, 'Macro, cdr getd 'Inf);
  164. for each X in '(PutIDInf PutStrInf PutVecInf PutPairInf PutWrdInf
  165. PutHalfWordInf PutEvecInf
  166. PutFixInf PutFltInf PutBigInf) do
  167. PutD(X, 'Macro, cdr getd 'PutInf);
  168. % IntInf is no longer needed, will be a macro no-op
  169. % for the time being
  170. RemProp('IntInf, 'OpenFn);
  171. macro procedure IntInf U;
  172. cadr U;
  173. % Similarly for MkINT
  174. macro procedure MkINT U;
  175. cadr U;
  176. % # of words in a pair
  177. syslsp macro procedure PairPack U;
  178. 2;
  179. % length (in characters, words, etc.) of a string, vector, or whatever,
  180. % stored in the first word pointed to
  181. syslsp macro procedure GetLen U;
  182. list('SignedField, list('GetMem, cadr U), '(WConst InfStartingBit),
  183. '(WConst InfBitLength));
  184. syslsp macro procedure StrBase U; % point to chars of string
  185. list('WPlus2, cadr U, '(WConst AddressingUnitsPerItem));
  186. % chars string length --> words string length
  187. % Don't add 1 in this! (Put change in at some reasonable time.)
  188. % Actually need space for extra null, but magic constant to add
  189. % to determine number of words needed is CharsPerWord-1, so all
  190. % cancels out. /csp 2-28-83
  191. syslsp macro procedure StrPack U;
  192. list('WQuotient, list('WPlus2, cadr U,
  193. list('WPlus2, '(WConst CharactersPerWord),
  194. 1)),
  195. '(WConst CharactersPerWord));
  196. % access to bytes of string; skip first word
  197. syslsp macro procedure StrByt U;
  198. list('Byte, list('WPlus2, cadr U, '(WConst AddressingUnitsPerItem)),
  199. caddr U);
  200. syslsp macro procedure PutStrByt U;
  201. list('PutByte, list('WPlus2, cadr U, '(WConst AddressingUnitsPerItem)),
  202. caddr U,
  203. cadddr U);
  204. % access to halfword entries; skip first word
  205. syslsp macro procedure HalfWordItm U;
  206. list('HalfWord, list('WPlus2, cadr U,
  207. '(WConst AddressingUnitsPerItem)),
  208. caddr U);
  209. syslsp macro procedure PutHalfWordItm U;
  210. list('PutHalfWord, list('WPlus2, cadr U,
  211. '(WConst AddressingUnitsPerItem)),
  212. caddr U,
  213. cadddr U);
  214. % halfword length --> words length
  215. % Should add 1 before shift! /csp 2-28-83
  216. syslsp macro procedure HalfWordPack U;
  217. list('WPlus2, list('WShift, cadr U, -1), 1);
  218. % length (in Item size quantities) of Lisp vectors
  219. % size of Lisp vector in words
  220. % Adding 1 not needed for GtVect! /csp 2-28-83
  221. syslsp macro procedure VectPack U;
  222. list('WPlus2, cadr U, 1);
  223. % size of Lisp Evector in words
  224. % See comment above! /csp
  225. syslsp macro procedure EVectPack U;
  226. list('WPlus2, cadr U, 1);
  227. % access to elements of Lisp vector
  228. syslsp macro procedure VecItm U;
  229. list('WGetV, cadr U,
  230. list('WPlus2, caddr U, 1));
  231. syslsp macro procedure PutVecItm U;
  232. list('WPutV, cadr U,
  233. list('WPlus2, caddr U, 1),
  234. cadddr U);
  235. % access to elements of Lisp Evector
  236. syslsp macro procedure EVecItm U;
  237. list('WGetV, cadr U,
  238. list('WPlus2, caddr U, 1));
  239. syslsp macro procedure PutEVecItm U;
  240. list('WPutV, cadr U,
  241. list('WPlus2, caddr U, 1),
  242. cadddr U);
  243. % Wrd is like Vect, but not traced by the garbage collector
  244. % See comment for VectPack, above! /csp 2-28-83
  245. syslsp macro procedure WrdPack U;
  246. list('WPlus2, cadr U, 1);
  247. for each X in '(StrLen ByteLen VecLen EVecLen WrdLen HalfWordLen) do
  248. PutD(X, 'Macro, cdr getd 'GetLen);
  249. PutD('WrdItm, 'Macro, cdr GetD 'VecItm);
  250. PutD('PutWrdItm, 'Macro, cdr GetD 'PutVecItm);
  251. % So what about FixPack and FloatPack, turkeys? /csp 2-28-83
  252. syslsp macro procedure FixVal U;
  253. list('WGetV, cadr U, 1);
  254. syslsp macro procedure PutFixVal U;
  255. list('WPutV, cadr U, 1, caddr U);
  256. syslsp macro procedure FloatBase U;
  257. list('WPlus2, cadr U, '(WConst AddressingUnitsPerItem));
  258. syslsp macro procedure FloatHighOrder U;
  259. list('WGetV, cadr U, 1);
  260. syslsp macro procedure FloatLowOrder U;
  261. list('WGetV, cadr U, 2);
  262. % New addition: A code pointer can have the number of arguments it expects
  263. % stored in the word just before the entry
  264. syslsp macro procedure !%code!-number!-of!-arguments U;
  265. list('WGetV, cadr U, -1);
  266. % The four basic cells for each symbol: Val, Nam, Fnc, Prp, corresponding to
  267. % variable value, symbol name (as string), function cell (jump to compiled
  268. % code or lambda linker) and property list (pairs for PUT, GET, atoms for FLAG,
  269. % FLAGP). These are currently 4 separate arrays, but this representation may
  270. % be changed to a contiguous 4 element record for each symbol or something else
  271. % and therefore should not be accessed as arrays.
  272. syslsp macro procedure SymVal U;
  273. list('WGetV, '(WConst SymVal), cadr U);
  274. syslsp macro procedure PutSymVal U;
  275. list('WPutV, '(WConst SymVal), cadr U, caddr U);
  276. syslsp macro procedure LispVar U; % Access value cell by name
  277. list('(WConst SymVal), list('IDLoc, cadr U));
  278. syslsp macro procedure PutLispVar U;
  279. list('PutSymVal, list('IDLoc, cadr U), caddr U);
  280. syslsp macro procedure SymNam U;
  281. list('WGetV, '(WConst SymNam), cadr U);
  282. syslsp macro procedure PutSymNam U;
  283. list('WPutV, '(WConst SymNam), cadr U, caddr U);
  284. % Retrieve the address stored in the function cell
  285. % SymFnc and PutSymFnc are not defined portably
  286. syslsp macro procedure SymPrp U;
  287. list('WGetV, '(WConst SymPrp), cadr U);
  288. syslsp macro procedure PutSymPrp U;
  289. list('WPutV, '(WConst SymPrp), cadr U, caddr U);
  290. % Binding stack primitives
  291. syslsp macro procedure BndStkID U;
  292. list('WGetV, cadr U, -1);
  293. syslsp macro procedure PutBndStkID U;
  294. list('WPutV, cadr U, -1, caddr U);
  295. syslsp macro procedure BndStkVal U;
  296. list('GetMem, cadr U);
  297. syslsp macro procedure PutBndStkVal U;
  298. list('PutMem, cadr U, caddr U);
  299. syslsp macro procedure AdjustBndStkPtr U;
  300. list('WPlus2, cadr U,
  301. list('WTimes2, caddr U,
  302. list('WTimes2,
  303. '(WConst AddressingUnitsPerItem),
  304. 2)));
  305. % ObArray is a linearly allocated hash table containing ID numbers of entries
  306. % maintained as a circular buffer. It is referenced only via these macros
  307. % because we may decide to change to some other representation.
  308. syslsp smacro procedure ObArray I;
  309. HalfWord(HashTable, I);
  310. syslsp smacro procedure PutObArray(I, X);
  311. HalfWord(HashTable, I) := X;
  312. put('ObArray, 'Assign!-Op, 'PutObArray);
  313. syslsp smacro procedure OccupiedSlot U;
  314. ObArray U > 0;
  315. DefList('((GetMem PutMem)
  316. (Field PutField)
  317. (Byte PutByte)
  318. (HalfWord PutHalfWord)
  319. (Tag PutTag)
  320. (Inf PutInf)
  321. (IDInf PutIDInf)
  322. (StrInf PutStrInf)
  323. (VecInf PutVecInf)
  324. (EVecInf PutEVecInf)
  325. (WrdInf PutWrdInf)
  326. (PairInf PutPairInf)
  327. (FixInf PutFixInf)
  328. (FixVal PutFixVal)
  329. (FltInf PutFltInf)
  330. (BigInf PutBigInf)
  331. (StrLen PutStrLen)
  332. (StrByt PutStrByt)
  333. (VecLen PutVecLen)
  334. (EVecLen PutEvecLen)
  335. (VecItm PutVecItm)
  336. (EVecItm PutEVecItm)
  337. (WrdLen PutWrdLen)
  338. (WrdItm PutWrdItm)
  339. (SymVal PutSymVal)
  340. (LispVar PutLispVar)
  341. (SymNam PutSymNam)
  342. (SymFnc PutSymFnc)
  343. (SymPrp PutSymPrp)
  344. (BndStkID PutBndStkID)
  345. (BndStkVal PutBndStkVal)), 'Assign!-Op);
  346. % This is redefined for the HP 9836 to cure the high-order FF problem
  347. macro procedure !%chipmunk!-kludge x;
  348. cadr x;
  349. END;