lap.red 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. COMMENT MODULE LAP;
  2. SYMBOLIC;
  3. COMMENT definition of LAP ops;
  4. SYMBOLIC FEXPR PROCEDURE MACOPS L;
  5. BEGIN
  6. A:
  7. IF NULL L THEN RETURN T;
  8. PUT(CAR L,'MACOP,CADR L);
  9. L := CDDR L;
  10. GO TO A
  11. END;
  12. MACOPS(PUSHJ,
  13. 176,
  14. POPJ,
  15. 179,
  16. PUSH,
  17. 177,
  18. POP,
  19. 178,
  20. CALL,
  21. 28,
  22. JCALL,
  23. 29,
  24. CALLF,
  25. 30,
  26. JCALLF,
  27. 31,
  28. JRST,
  29. 172,
  30. JSP,
  31. 181,
  32. CALLF!@,
  33. 15376,
  34. JCALLF!@,
  35. 15888,
  36. MOVE,
  37. 128,
  38. MOVEI,
  39. 129,
  40. MOVEM,
  41. 130,
  42. HRRZS,363,
  43. MOVNI,
  44. 137,
  45. HLLZS,331,
  46. CAIE,
  47. 194,
  48. CAIN,
  49. 198,
  50. CAME,
  51. 202,
  52. CAMGE,
  53. 205,
  54. CAMLE,
  55. 203,
  56. CAMN,
  57. 206,
  58. ADD,
  59. 184,
  60. SUB,
  61. 188,
  62. IMUL,
  63. 144,
  64. CLEARM,
  65. 258,
  66. CLEARB,
  67. 259,
  68. EXCH,
  69. 168,
  70. TDZA,
  71. 412,
  72. JUMP,
  73. 208,
  74. JUMPE,
  75. 210,
  76. JUMPN,
  77. 214,
  78. HRRZ,
  79. 360,
  80. HLRZ,
  81. 364,
  82. HRRM,
  83. 354,
  84. HRLM,
  85. 326,
  86. HRLI,
  87. 325,
  88. HRRZ!@,
  89. 184336,
  90. HLRZ!@,
  91. 186384,
  92. HRRM!@,
  93. 181264,
  94. HRLM!@,
  95. 166928,
  96. HRRZS!@,
  97. 185872,
  98. HLLZS!@,
  99. 169488,
  100. JUMPGE,
  101. 213);
  102. MACOPS(NIL,0,A,1,B,2,C,3,TT,7,D,10,R,11,P,12,SP,15);
  103. MACOPS(CARA,
  104. 364,
  105. CARA!@,
  106. 186384,
  107. CDRA,
  108. 360,
  109. CDRA!@,
  110. 184336,
  111. RPLCA,
  112. 326,
  113. RPLCA!@,
  114. 166928,
  115. RPLCD,
  116. 354,
  117. RPLCD!@,
  118. 181264,
  119. JSYS,
  120. 68);
  121. MACOPS(SETO,
  122. 316,
  123. MOVSI,
  124. 133,
  125. ILDB,
  126. 92,
  127. IDPB,
  128. 94,
  129. TRZ,
  130. 400,
  131. HRRI,
  132. 353,
  133. HRROI,
  134. 369,
  135. HRL,
  136. 324,
  137. HRRZ,
  138. 360,
  139. TRO,
  140. 432,
  141. ADDI,
  142. 185,
  143. AOBJN,
  144. 171,
  145. CAIL,
  146. 193,
  147. SKIPA,
  148. 220,
  149. SKIPE,
  150. 218,
  151. SETZM,
  152. 258,
  153. BLT,
  154. 169,
  155. SUBI,
  156. 189,
  157. AOJN,
  158. 230,
  159. SKIPG,
  160. 223,
  161. LDB,
  162. 93,
  163. AOJA,
  164. 228,
  165. SOJA,
  166. 244,
  167. CAIG,
  168. 199,
  169. CAILE,
  170. 195,
  171. LSH,
  172. 162,
  173. IORM,
  174. 286,
  175. HRLZ,
  176. 332,
  177. HRLZM,
  178. 334,
  179. SOJE,
  180. 242,
  181. SOJN,
  182. 246,
  183. DPB,
  184. 95,
  185. ANDI,
  186. 261);
  187. FLUID '(BPORG BPEND CLIST QLIST);
  188. FLUID '(!*PWRDS
  189. !*PGWD
  190. !*SAVECOM
  191. CONLIST
  192. GEN
  193. REMSYMS);
  194. SYMBOLIC PROCEDURE LAP U; LAP10 U;
  195. SYMBOLIC PROCEDURE LAP10 U;
  196. BEGIN SCALAR SL,LOC,CONLIST,GEN,REMSYMS,X;
  197. GEN := GENSYM(); %entry point for constants;
  198. CONLIST := LIST NIL; %constant list;
  199. LOC := BPORG; %entry point for function;
  200. WHILE U DO
  201. <<IF ATOM(X := CAR U)
  202. THEN <<IF !*PGWD THEN PRINT X; DEFSYM(X,BPORG)>>
  203. ELSE IF CAR X EQ '!*ENTRY
  204. THEN <<IF SL THEN RPLACD(CDAR SL,BPORG);
  205. SL := LIST(CDR X,BPORG) . SL;
  206. LOC := BPORG;
  207. IF !*COUNTMC
  208. THEN RPLACD(U,APPEND(
  209. <<PUT(CAR X,'MCCOUNT,ADD1 GET(CAR X,'MCCOUNT));
  210. COUNTMC CAR X>>,CDR U));
  211. IF !*PGWD THEN PRINT X>>
  212. ELSE IF CADR X MEMBER '(EXPR FEXPR)
  213. THEN <<IF SL THEN RPLACD(CDAR SL,BPORG);
  214. SL := LIST(X,BPORG) . SL;
  215. LOC := BPORG;
  216. IF !*PGWD THEN PRINT X>>
  217. ELSE IF NOT NUMBERP CAR X AND FLAGP(CAR X,'MC)
  218. THEN RPLACD(U,APPEND(IF !*COUNTMC THEN
  219. <<PUT(CAR X,'MCCOUNT,ADD1 GET(CAR X,'MCCOUNT));
  220. COUNTMC CAR X>>,
  221. APPEND(EVAL(CAR X .
  222. FOR EACH J IN CDR X COLLECT MKQUOTE J),
  223. CDR U)))
  224. ELSE <<DEPOSIT(BPORG,KWD X);
  225. IF (BPORG := BPORG+1)>BPEND
  226. THEN REDERR "BINARY PROGRAM SPACE EXCEEDED">>;
  227. U := CDR U>>;
  228. IF SL THEN <<RPLACD(CDAR SL,BPORG);
  229. SL := REVERSIP SL;
  230. IF !*PWRDS THEN FOR EACH X IN SL DO
  231. LPRIM LIST(CAAR X,CADR X,'BASE,
  232. CDDR X-CADR X,
  233. 'WORDS,BPEND-CDDR X,'LEFT)>>;
  234. DEFSYM(GEN,BPORG); %define entry point for constants;
  235. WHILE CONLIST := CDR CONLIST DO
  236. <<CLIST := (CAR CONLIST . BPORG) . CLIST;
  237. DEPOSIT(BPORG,KWD CAR CONLIST);
  238. IF (BPORG := BPORG+1)>BPEND
  239. THEN REDERR "BINARY PROGRAM SPACE EXCEEDED">>;
  240. FOR EACH X IN REMSYMS DO REMSYM X;
  241. IF !*SAVECOM
  242. THEN FOR EACH X IN SL DO
  243. <<REMD CAAR X;
  244. !%PUTD(CAAR X,CADAR X,MKCODE(CADR X,CADDAR X))>>;
  245. END;
  246. SYMBOLIC PROCEDURE KWD U;
  247. BEGIN SCALAR X;
  248. X := GWD U;
  249. IF !*PGWD
  250. THEN BEGIN INTEGER N;
  251. PRIN1 U;
  252. SPACES2 30;
  253. N := BASE;
  254. BASE := 7+1;
  255. PRINT(IF X < 0 THEN X + 68719476736 ELSE X);
  256. BASE := N
  257. END;
  258. RETURN X
  259. END;
  260. SYMBOLIC PROCEDURE SPACES2 N;
  261. BEGIN SCALAR M;
  262. M := N-POSN();
  263. IF M<1 THEN PRIN2 " "
  264. ELSE WHILE M>0 DO <<PRIN2 " "; M := M-1>>
  265. END;
  266. % PRINT MACROS FIRST, IF T;
  267. !*PWRDS := T;
  268. % PRINT SPACE-USAGE, IF T;
  269. !*PGWD := NIL;
  270. % PRINT EXPANDED CODE IF T;
  271. !*SAVECOM := T;
  272. % ACTUALLY LOAD IF T;
  273. !*SAVEDEF := NIL;
  274. % RETAIN EXPR/FEXPR IF T;
  275. QSET('QLIST,NIL);
  276. QSET('CLIST,NIL);
  277. SYMBOLIC PROCEDURE GWD X;
  278. BEGIN SCALAR WRD,FLD;
  279. WRD := LAPEVAL CAR X;
  280. WRD := LSH(WRD,IF WRD<512 THEN 27 ELSE 18);
  281. FLD := '((23 . 15) (0 . 262143) (18 . -1));
  282. MAPC(CDR X,
  283. FUNCTION LAMBDA ZZ;
  284. <<WRD :=
  285. WRD
  286. + LSH(BOOLE(1,CDAR FLD,LAPEVAL ZZ),
  287. CAAR FLD);
  288. FLD := CDR FLD>>);
  289. RETURN WRD
  290. END;
  291. SYMBOLIC PROCEDURE RELOC L; LAPEVAL CAR L + 96;
  292. SYMBOLIC PROCEDURE LAPEVAL X;
  293. IF NUMBERP X THEN X
  294. ELSE IF ATOM X THEN GVAL X
  295. ELSE IF CAR X MEMBER '(E QUOTE)
  296. THEN !*BOX IF (NOT ATOM (X := CADR X)
  297. OR NUMBERP X AND NOT INUMP X)
  298. OR STRINGP X
  299. THEN BEGIN SCALAR Y;
  300. Y := QLIST;
  301. A:
  302. IF NULL Y
  303. THEN RETURN CAR (QLIST := X . QLIST)
  304. ELSE IF X=CAR Y
  305. AND FLOATP X EQ FLOATP CAR Y
  306. THEN RETURN CAR Y;
  307. Y := CDR Y;
  308. GO TO A
  309. END
  310. ELSE X
  311. ELSE IF CAR X EQ 'FLUID OR CAR X EQ 'SPECIAL
  312. THEN <<QSET(CADR X,NIL);
  313. !*BOX GET(CADR X,'VALUE)>>
  314. ELSE IF CAR X EQ 'C
  315. THEN BEGIN SCALAR N,CPTR;
  316. CPTR := CLIST;
  317. L11:
  318. IF NULL CPTR THEN GO TO L12
  319. ELSE IF CDR X=CAAR CPTR THEN RETURN CDAR CPTR;
  320. CPTR := CDR CPTR;
  321. GO TO L11;
  322. L12:
  323. GVAL GEN;
  324. N := 0;
  325. CPTR := CONLIST;
  326. A:
  327. IF NULL CDR CPTR THEN RPLACD(CPTR,LIST CDR X);
  328. IF CDR X=CADR CPTR THEN RETURN N;
  329. N := N + 1;
  330. CPTR := CDR CPTR;
  331. GO TO A
  332. END
  333. ELSE IF CAR X EQ 'RELOC THEN LAPEVAL CADR X + 96
  334. ELSE IF CAR X EQ 'EXARG AND NOT ATOM CDR X
  335. THEN LAPEVAL 'EXARG + LAPEVAL CADR X
  336. ELSE LAPEVAL CAR X + LAPEVAL CDR X;
  337. SYMBOLIC PROCEDURE DEFSYM(SYM,VAL);
  338. BEGIN SCALAR Z;
  339. IF Z := GET(SYM,'UNDEF) THEN GO TO PATCH;
  340. REMSYMS := SYM . REMSYMS;
  341. A:
  342. RETURN PUT(SYM,'SYM,VAL);
  343. PATCH:
  344. IF NULL Z THEN <<REMPROP(SYM,'UNDEF); GO TO A>>;
  345. DEPOSIT(CAR Z,EXAMINE CAR Z + VAL);
  346. Z := CDR Z;
  347. GO TO PATCH
  348. END;
  349. SYMBOLIC PROCEDURE GVAL SYM;
  350. BEGIN SCALAR X;
  351. IF X := GET(SYM,'MACOP) THEN RETURN X
  352. ELSE IF X := GET(SYM,'SYM) THEN RETURN X
  353. ELSE IF GET(SYM,'VALUE) THEN RETURN !*BOX SYM;
  354. PUT(SYM,
  355. 'UNDEF,
  356. BPORG
  357. . IF X := GET(SYM,'UNDEF) THEN X
  358. ELSE <<REMSYMS := SYM . REMSYMS; NIL>>);
  359. RETURN 0
  360. END;
  361. SYMBOLIC PROCEDURE REMSYM L;
  362. IF GET(L,'UNDEF) THEN LPRIE LIST(L,"UNDEFINED SYMBOL")
  363. ELSE IF NULL REMPROP(L,'SYM)
  364. THEN LPRIE LIST(L,"MULTIPLY DEFINED")
  365. ELSE IF CAADR L EQ 'PNAME THEN REMOB L %means L has no props;
  366. ELSE NIL;
  367. BPORG1 := BPORG;
  368. LAP10 '((GWD EXPR 1)
  369. (PUSH P (C 0))
  370. (PUSH P 1)
  371. (PUSHJ P TAG04)
  372. (CAIG 1 511)
  373. (LSH 1 9)
  374. (HLRZ 2 1)
  375. (HRRZ 3 1)
  376. (CAIN 2 34816)
  377. (CAIL 3 512)
  378. (JRST 0 TAG01)
  379. (MOVEM 1 -1 P)
  380. (JUMPN 3 TAG02)
  381. TAG01
  382. (HRLZM 1 -1 P)
  383. (PUSHJ P TAG04)
  384. (ANDI 1 15)
  385. (LSH 1 23)
  386. (IORM 1 -1 P)
  387. (PUSHJ P TAG04)
  388. (HRRM 1 -1 P)
  389. (PUSHJ P TAG04)
  390. (HRLZ 1 1)
  391. (IORM 1 -1 P)
  392. TAG02
  393. (POP P 1)
  394. (POP P 1)
  395. (JCALL 1 (E !*BOX))
  396. TAG03
  397. (POP P 1)
  398. (JRST 0 TAG02)
  399. TAG04
  400. (MOVE 2 -1 P)
  401. (JUMPE 2 TAG03)
  402. (CARA 1 0 2)
  403. (CDRA 2 0 2)
  404. (MOVEM 2 -1 P)
  405. (CALL 1 (E LAPEVAL))
  406. (JCALL 1 (E NUMVAL)));
  407. CLIST := NIL;
  408. IF BPEND<131072 THEN BPORG := BPORG1; %means DECUS version;
  409. END;