data-machine.red 12 KB

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