fap.red 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684
  1. COMMENT The FAP building module;
  2. COMMENT this module needs to IMPORT MATHPR;
  3. %PUT('FAP,'IMPORTS,'(MEVAL COMPLR IO));
  4. COMMENT FASLOUT, used to produce FAP files for
  5. subsequent fast loading (FISL);
  6. SYMBOLIC$ % This page links Lisp compiler to FASLAP producer;
  7. SYMBOLIC SMACRO PROCEDURE !&PUSH(A,B); B := A . B;
  8. GLOBAL '(DFPRINT!* !*MODULE !*FASLMSG !*ARGNAMES !*ARGCOUNT);
  9. COMMENT !*ARGNAMES enables generation of list of all argument names
  10. for compiled functions
  11. !*ARGCOUNT enables generation of just a number showing how
  12. many args a function has, but not what they are called;
  13. FLUID '(MSGCHN!* FSLCHN!*
  14. FILE !*DEFN CFL!* BTIME!*
  15. FASLOUTFILE USERFORF OFILE PROP BASE IBASE
  16. XPR DDTSYMS UNDEFSYMS SYM LITERALS NUMBERTABLE
  17. ENTRYPOINTS
  18. ALLATOMS AMBIGSYMS ATOMINDX BFUNCS BINCT CURRENTFNSYMS
  19. CURRENTFN DDTSYMP DDTSYMS !*FASLDEBUG FILOC LITCNT
  20. LITERALS LITLOC LOC MAINSYMPDL NUMBERTABLE PASS2LIT SYMBOLSP
  21. SYMPDL UNDEFSYMS WINP
  22. );
  23. IF NOT GETD 'BEGIN THEN
  24. <<FLAG('(RDS DEFLIST FLAG FLUID GLOBAL REMPROP REMFLAG UNFLUID
  25. DM FASLEND),'EVAL);
  26. FLAG('(RDS),'IGNORE)>>;
  27. SYMBOLIC PROCEDURE FASLOUT FIL;
  28. % Initiate FSL to file FIL;
  29. FSLOUTF MKFIL ADDEXTN(CAR FIL,'FAP);
  30. SYMBOLIC PROCEDURE ADDEXTN(U,V);
  31. %Adds the extension V to the file named U;
  32. BEGIN SCALAR X,Y;
  33. X := EXPLODEC U;
  34. Y := REVERSE X;
  35. A: IF NULL Y OR CAR Y EQ '!>
  36. THEN RETURN COMPRESS('!" .
  37. NCONC(X,'!. . ACONC(EXPLODEC V,'!")))
  38. ELSE IF CAR Y EQ '!. THEN TYPERR(U,"fasl file name");
  39. Y := CDR Y;
  40. GO TO A
  41. END;
  42. IF GETD 'BEGIN THEN RLISTAT '(FASLOUT); %only do it if REDUCE used;
  43. SYMBOLIC PROCEDURE FSLOUT1 X;
  44. IF ATOM X THEN FSLOUTS X
  45. ELSE IF CAR X EQ 'DE
  46. THEN FSLOUT2(CADR X,'EXPR,LIST('LAMBDA,CADDR X,CADDDR X))
  47. ELSE IF CAR X EQ 'DF
  48. THEN FSLOUT2(CADR X,'FEXPR,LIST('LAMBDA,CADDR X,CADDDR X))
  49. ELSE IF CAR X EQ 'DM AND FLAGP('MACRO,'COMPILE)
  50. THEN FSLOUT2(CADR X,'MACRO,LIST('LAMBDA,CADDR X,CADDDR X))
  51. ELSE IF CAR X MEMQ '(PUTD PUTC) AND EQCAR(CADR X,'QUOTE)
  52. AND EQCAR(CADDR X,'QUOTE) AND EQCAR(CADDDR X,'QUOTE)
  53. AND FLAGP(CADR CADDR X,'COMPILE)
  54. THEN FSLOUT2(CADADR X,CADAR(X:=CDDR X),CADADR X)
  55. ELSE IF CAR X EQ 'PROGN THEN FOR EACH Z IN CDR X DO FSLOUT1 Z
  56. ELSE IF CAR X EQ 'LETFN THEN EVAL X
  57. ELSE IF CAR X EQ 'PUTC THEN FSLOUTS('PUT . CDR X)
  58. ELSE FSLOUTS X;
  59. SYMBOLIC PROCEDURE FSLOUT2(NAME,TYPE,EXP);
  60. IF !*MODULE THEN MODCMP(NAME,TYPE,EXP)
  61. ELSE IF NAME MEMQ FUNCNAMES!* AND TYPE MEMQ FTYPES!* THEN NIL
  62. %means part of a compilable LET;
  63. ELSE FSLOUT3(NAME,TYPE,EXP);
  64. SYMBOLIC PROCEDURE FSLOUT3(NAME,TYPE,EXP);
  65. BEGIN SCALAR VARLIS; %SCALAR BASE,IBASE;
  66. IF NOT FLAGP(TYPE,'COMPILE)
  67. THEN ERROR(0,LIST("UNCOMPILABLE FUNCTION",
  68. NAME,"OF TYPE",TYPE));
  69. IF TYPE MEMQ '(EXPR FEXPR) AND NOT EQCAR(GETD NAME,TYPE)
  70. THEN PUT(NAME,'CFNTYPE,LIST TYPE); % careful for fwd ref;
  71. VARLIS := CADR EXP;
  72. EXP := !&COMPROC(EXP,IF TYPE MEMQ '(EXPR FEXPR) THEN NAME);
  73. FSLOUTS LIST('LAP,
  74. MKQUOTE(LIST('!*ENTRY,NAME,TYPE,LENGTH VARLIS) . EXP));
  75. IF !*ARGNAMES OR !*ARGCOUNT
  76. THEN FSLOUTS LIST('PUT,MKQUOTE NAME,MKQUOTE 'ARGUMENTS!*,
  77. IF !*ARGNAMES THEN MKQUOTE LIST VARLIS
  78. ELSE LENGTH VARLIS)
  79. END;
  80. GLOBAL '(!$EOF!$);
  81. SYMBOLIC PROCEDURE FSLOUTF FILE;
  82. BEGIN SCALAR A,CRFIL,OCRFIL;
  83. BTIME!* := TIME();
  84. TERPRI();
  85. IF GETD 'BEGIN THEN
  86. <<PRIN2 "FASLOUT: IN files; or type in expressions";
  87. TERPRI();
  88. PRIN2 "When all done, execute FASLEND; ">>
  89. ELSE <<PRIN2 "FASLOUT: (DSKIN files) or type in expressions";
  90. TERPRI();
  91. PRIN2 "When all done, execute (FASLEND) ">>;
  92. TERPRI();
  93. WINP:=NIL; % Error Flag;
  94. LOC:=FILOC:=LITLOC:=LITCNT:=BINCT:=NIL;
  95. ATOMINDX:=NIL; % Numeric;
  96. CURRENTFN:=DDTSYMP:=SYMBOLSP:=NIL;
  97. PASS2LIT:=NIL; % Var & flags;
  98. CURRENTFNSYMS:=SYMPDL:=MAINSYMPDL:=NIL; % !&PUSHed on;
  99. DDTSYMS:=AMBIGSYMS:=UNDEFSYMS:=LITERALS:=NIL;
  100. CURRENTFN:='FASLOUT;
  101. WINP:=ERRORSET('(FASL!-START FILE),T,!*BAKGAG);
  102. %sets channel;
  103. FSLCHN!* := WRS MSGCHN!*;
  104. IF ATOM WINP THEN
  105. <<TERPRI();
  106. PRIN2 LIST( "FASL aborted, in",CURRENTFN,"after",
  107. FILOC,'!+,LOC);
  108. TERPRI();
  109. RETURN WINP>>;
  110. DFPRINT!* := 'FSLOUT1;
  111. !*COMP := NIL; %to avoid recompilation of macros;
  112. !*DEFN:=T;
  113. IF GETD 'BEGIN THEN RETURN WINP;
  114. NDF: IF NOT (A EQ !$EOF!$) THEN <<WINP:=A; GO LOP>>;
  115. CRFIL:=NIL;
  116. IF NULL OCRFIL THEN GO LOP;
  117. CRFIL:=CAAR OCRFIL;
  118. RDS CDAR OCRFIL;
  119. OCRFIL:=CDR OCRFIL;
  120. LOP: A:=ERRORSET('(READ),T,!*BAKGAG);
  121. IF ATOM A THEN GO NDF;
  122. A:=CAR A;
  123. IF NOT PAIRP A THEN <<WINP := A; GO LOP>>;
  124. IF CAR A EQ 'DSKIN THEN
  125. <<OCRFIL:=(CRFIL.RDS OPEN(CDR A,'INPUT)).OCRFIL;
  126. CRFIL:=CDR A; GO LOP>>;
  127. IF NOT FLAGP(CAR A,'IGNORE)
  128. THEN ERRORSET(LIST('FSLOUT1,MKQUOTE A),T,!*BAKGAG);
  129. IF FLAGP(CAR A,'EVAL) OR
  130. CAR A EQ 'SETQ AND
  131. (CADDR A MEMQ '(T NIL) OR CONSTANTP CADDR A OR
  132. EQCAR(CADDR A,'QUOTE))
  133. THEN ERRORSET(A,T,!*BAKGAG);
  134. IF !*DEFN THEN GO LOP;
  135. RETURN WINP
  136. END;
  137. IF NULL GETD 'BEGIN THEN PUTD('FASLOUT,'FEXPR,CDR GETD 'FSLOUTF);
  138. SYMBOLIC PROCEDURE FASLEND;
  139. BEGIN %SCALAR BASE,IBASE;
  140. WINP:=ERRORSET('(FASL!-CLOSE WINP),T,!*BAKGAG);
  141. DFPRINT!* := NIL;
  142. TERPRI();
  143. !*DEFN:=NIL;
  144. PRIN2 "Atomindex: ";
  145. PRIN2 ATOMINDX;
  146. PRIN2 " block length: ";
  147. PRIN2 FILOC; PRIN2 " time: ";PRIN2 BTIME!*; PRIN2 " ms"; TERPRI();
  148. END;
  149. FLAG('(FASLEND),'IGNORE); %To execute in ON DEFN mode, no output;
  150. PUT('FASLEND,'STAT,'ENDSTAT);
  151. SYMBOLIC PROCEDURE FSLOUTS1 X;
  152. IF NULL X THEN T
  153. ELSE IF ATOM X THEN FBF LIST("UnFASL'd:",X)
  154. ELSE FASLIFY X;
  155. SYMBOLIC PROCEDURE FSLOUTS U;
  156. BEGIN
  157. CURRENTFN:='FSLOUTS;
  158. MSGCHN!* := WRS FSLCHN!*;
  159. WINP:=ERRORSET(LIST('FSLOUTS1,MKQUOTE U),T,!*BAKGAG);
  160. FSLCHN!* := WRS MSGCHN!*;
  161. WINP:= IF ATOM WINP THEN
  162. <<TERPRI();
  163. PRINT LIST("FASL aborted, in",CURRENTFN,
  164. "after",FILOC,'!+,LOC);
  165. TERPRI()>>
  166. ELSE T;
  167. RETURN WINP;
  168. END;
  169. !*FASLDEBUG:=NIL$
  170. GLOBAL '(BNAR BTAR BXAR);
  171. BTAR:=MKVECT 9;
  172. BNAR:=MKVECT 9;
  173. BXAR:=MKVECT 9;
  174. SYMBOLIC PROCEDURE FASL!-START OFILE;
  175. BEGIN
  176. BINCT:= 0;
  177. ATOMINDX:= 0;
  178. LOC:=FILOC:=LITLOC:= 0;
  179. NUMBERTABLE:= ALLATOMS:= NIL;
  180. SYMPDL:= MAINSYMPDL:= CURRENTFNSYMS:= NIL;
  181. IF ATOM OFILE THEN OFILE:= 'DSK!: . LIST OFILE ELSE
  182. IF NOT !%DEVP CAR OFILE THEN OFILE:= 'DSK!: . OFILE;
  183. MSGCHN!* := WRS OPEN(OFILE,'OUTBIN);
  184. BFBO (-30863143776); % ASCII /FASLP/;
  185. BFBO EXAMINE 95; % Lisp assembly-version #, someday;
  186. END;
  187. FLUID '(ELIST);
  188. GLOBAL '(FUNCNAMES!*);
  189. SYMBOLIC PROCEDURE FASL!-CLOSE FLG;
  190. BEGIN
  191. IF !*MODULE THEN BLKCMP();
  192. WHILE ELIST DO <<FSLOUT1 CAR ELIST; ELIST := CDR ELIST>>;
  193. IF FUNCNAMES!* THEN FOR EACH X IN FUNCNAMES!* DO
  194. BEGIN SCALAR Y;
  195. IF (Y := GETD X) THEN IF CAR Y MEMQ '(EXPR FEXPR)
  196. THEN <<FSLOUT3(X,CAR Y,CDR Y);
  197. REMD X;
  198. PUT(X,'CFNTYPE,LIST CAR Y)>>
  199. ELSE NIL;
  200. %presumably function defined in earlier module;
  201. END;
  202. BTIME!* := TIME()-BTIME!*;
  203. MSGCHN!* := WRS FSLCHN!*;
  204. IF FLG THEN BUFO(15,0,NIL); % EOF word if no ERR;
  205. CLOSE WRS MSGCHN!*;
  206. REMPROPL(ALLATOMS,'ATOMINDX);
  207. NUMBERTABLE:=ALLATOMS:=NIL;
  208. SYMPDL:=MAINSYMPDL:=CURRENTFNSYMS:=NIL;
  209. END;
  210. SYMBOLIC PROCEDURE FASLIFY Y;
  211. BEGIN
  212. CURRENTFN:= 'FASLIFY;
  213. IF ATOM Y THEN NIL % IGNORE RANDOM ATOMS;
  214. ELSE IF CAR Y MEMQ '(LAP LAP10) THEN
  215. BEGIN
  216. FASLPASS1 (Y:= FASLPASS0 (NIL . EVAL CADR Y));
  217. FASLPASS2 Y;
  218. FILOC:= FILOC+LOC;
  219. END
  220. ELSE IF MUNGEABLE Y THEN <<IF CAR Y EQ 'SETQ
  221. THEN CURRENTFN:= CADR Y;
  222. COLLECTATOMS Y;
  223. BUFO(14,LSH(-1,18),Y)>>
  224. ELSE IF NOT MEMQ(CAR Y,'(COMMENT QUOTE)) THEN
  225. FBF LIST("UNFASL'd:",Y)
  226. END;
  227. SYMBOLIC PROCEDURE MUNGEABLE X;
  228. NOT (MEMQ(CAR X,'(COMMENT QUOTE)) OR
  229. CAR X EQ 'EVAL AND EQCAR(CADR X,'QUOTE));
  230. %SYMBOLIC PROCEDURE FASLPASS0 FLAP; % Convert any MCs else stet;
  231. % BEGIN SCALAR X,Y,L;
  232. % X:=FLAP;
  233. % LP: IF NULL (Y:=CDR X) THEN RETURN FLAP
  234. % ELSE IF ATOM(L:=CAR Y) OR NUMBERP CAR L
  235. % OR CAR L EQ '!*ENTRY
  236. % OR CADR L MEMQ '(FEXPR EXPR) THEN NIL
  237. % ELSE IF FLAGP(CAR L,'MC) THEN
  238. % <<RPLACD(X,APPEND(EVAL(CAR L,
  239. % FOR EACH J IN CDR L COLLECT MKQUOTE J),
  240. % CDR Y)),
  241. % GO TO LP>>;
  242. % X:=CDR X;
  243. % GO TO LP;
  244. % END;
  245. SYMBOLIC PROCEDURE FASLPASS0 U; U; %now done by pass1;
  246. SYMBOLIC PROCEDURE FASLPASS1 Q; % =((LAP) ... NIL);
  247. (LAMBDA BASE,IBASE;
  248. BEGIN SCALAR AMBIGSYMS,N,XPR;
  249. LOC:=0;
  250. CURRENTFNSYMS:= LITERALS:= NIL;
  251. DDTSYMP:= SYMBOLSP:= NIL;
  252. WHILE CDR Q DO
  253. <<IF ATOM (XPR:= CADR Q) THEN
  254. <<FASLDEFSYM(XPR,LIST('RELOC,FILOC+LOC));
  255. Q := NIL . RPLACD(Q,CDDR Q)>>
  256. ELSE IF CAR XPR EQ '!*ENTRY
  257. THEN <<IF GET(CADR XPR,'ENTRY) THEN
  258. FBF LIST("Duplicate entryname:",CADR XPR);
  259. IF !*COUNTMC THEN
  260. RPLACD(CDR Q,
  261. APPEND(<<PUT(CAR XPR,'MCCOUNT,
  262. ADD1 GET(CAR XPR,'MCCOUNT));
  263. COUNTMC CAR XPR>>,CDDR Q));
  264. PUT(CADR XPR,'ENTRY,FILOC+LOC)>>
  265. ELSE IF CADR XPR MEMQ '(FEXPR EXPR) THEN
  266. <<IF GET(CAR XPR,'ENTRY) THEN
  267. FBF LIST("Duplicate entryname:",CAR XPR);
  268. PUT(CAR XPR,'ENTRY,FILOC+LOC)>>
  269. % ELSE IF CAR XPR EQ 'DEFSYM THEN FASLDEFSYM(XPR,NIL) % EVAL
  270. % ELSE IF CAR XPR EQ 'DDTSYM THEN
  271. % << DDTSYMP:=T;
  272. % MAPC(CDR XPR,FUNCTION !*DDTSYM)>>
  273. % ELSE IF CAR XPR EQ 'EVAL THEN MAPC(CDR XPR,FUNCTION EVAL)
  274. % ELSE IF CAR XPR EQ 'SYMBOLS THEN SYMBOLSP:=T
  275. % ELSE IF MEMQ(CAR XPR,'(ASCII SIXBIT BLOCK)) THEN
  276. % LOC:= LOC + BLOBLENGTH XPR;
  277. ELSE IF FLAGP(CAR XPR,'MC)
  278. THEN Q := NIL . RPLACD(Q,
  279. APPEND(IF !*COUNTMC
  280. THEN <<PUT(CAR XPR,'MCCOUNT,ADD1 GET(CAR XPR,'MCCOUNT));
  281. COUNTMC CAR XPR>>,
  282. APPEND(EVAL(CAR XPR .
  283. FOR EACH J IN CDR XPR COLLECT MKQUOTE J),
  284. CDDR Q)))
  285. ELSE IF NOT MEMQ(CAR XPR,'(COMMENT ARGS)) THEN
  286. <<RECLITCOUNT(XPR,T); LOC:=LOC+1>>;
  287. Q := CDR Q>>;
  288. LITLOC:= LOC; % where to assemble literals;
  289. LITERALS:= REVERSE LITERALS;
  290. END)
  291. (8,8);
  292. SYMBOLIC PROCEDURE FASLPASS2 Q;
  293. (LAMBDA BASE,IBASE,LITCNT;
  294. BEGIN SCALAR DDTSYMS,AMBIGSYMS,LASTENTRY,ENTRYPOINTS,PASS2LIT,
  295. UNDEFSYMS,OLITERALS,XPR;
  296. OLITERALS:=LITERALS;
  297. LOC:=0;
  298. WHILE Q:=CDR Q DO
  299. IF ATOM (XPR:=CAR Q) THEN
  300. % IF SYMBOLSP THEN BUFO(13,0,XPR) ELSE; NIL
  301. ELSE IF CAR XPR EQ '!*ENTRY
  302. THEN <<COLLECTATOMS CADR XPR;
  303. COLLECTATOMS CADDR XPR;
  304. !&PUSH(CDR XPR . (FILOC+LOC), ENTRYPOINTS);
  305. % IF SYMBOLSP THEN BUFO(13,0,CADR XPR);
  306. LASTENTRY:= CADR XPR>>
  307. ELSE IF CADR XPR MEMQ '(FEXPR EXPR) THEN
  308. <<COLLECTATOMS CAR XPR;
  309. COLLECTATOMS CADR XPR;
  310. !&PUSH(XPR . (FILOC+LOC), ENTRYPOINTS);
  311. % IF SYMBOLSP THEN BUFO(13,0,CAR XPR);
  312. LASTENTRY:= CAR XPR>>
  313. % ELSE IF CAR XPR EQ 'ARGS THEN
  314. % IF CADR XPR EQ LASTENTRY THEN
  315. % PUT(CADR XPR,'ARGSINFO,CADDR XPR)
  316. % ELSE FBF LIST("ARGS misplaced",XPR)
  317. % ELSE IF CAR XPR EQ 'SYMBOLS THEN SYMBOLSP:=CADR XPR
  318. % ELSE IF CAR XPR EQ 'EVAL THEN MAPC(CDR XPR,FUNCTION EVAL)
  319. % ELSE IF CAR XPR EQ 'DDTSYM THEN
  320. % MAPC(CDR XPR,FUNCTION(LAMBDA X;
  321. % IF NOT MEMQ(X,DDTSYMS) THEN !&PUSH(X,DDTSYMS)));
  322. ELSE IF FLAGP(CAR XPR,'MC)
  323. THEN ERROR(0,"SEE ACH: FASLPASS2 MC TEST TRUE")
  324. % THEN APPEND(IF !*COUNTMC
  325. % THEN <<PUT(CAR XPR,'MCCOUNT,ADD1 GET(CAR XPR,'MCCOUNT));
  326. % COUNTMC CAR XPR>>,
  327. % APPEND(EVAL(CAR XPR .
  328. % FOR EACH J IN CDR XPR COLLECT MKQUOTE J),
  329. % CDR Q))
  330. ELSE IF NOT MEMQ(CAR XPR,'(DEFSYM COMMENT)) THEN MAKEWORD XPR;
  331. IF LITERALS OR NOT(LOC = LITLOC) THEN GO TO PHAS;
  332. PASS2LIT:=T; % Let FASLEVAL know we're doing lits;
  333. MAPC(OLITERALS,FUNCTION MAKEWORD);
  334. IF NOT(LOC = (LITLOC+LITCNT)) THEN GO TO PHAS;
  335. ENTRYPOINTS := REVERSIP ENTRYPOINTS;
  336. FOR EACH X IN ENTRYPOINTS DO
  337. BUFO(IF CADAR X MEMQ FTYPES!* THEN 11 ELSE 9,CDR X,CAR X);
  338. % DDTSYMS AND IF DDTSYMP THEN FBF LIST('DDTSYMS,DDTSYMS)
  339. % ELSE FBF LIST("Undefined SYMs made DDTSYMs:",DDTSYMS);
  340. IF UNDEFSYMS THEN FBF LIST("Undefined:",UNDEFSYMS);
  341. BASE := 10;
  342. IF !*FASLMSG THEN WHILE ENTRYPOINTS DO
  343. BEGIN SCALAR X; INTEGER Y;
  344. X := CAR ENTRYPOINTS;
  345. IF CDR ENTRYPOINTS THEN Y := CDADR ENTRYPOINTS
  346. ELSE Y := LOC;
  347. FBF LIST(CAAR X,"processed; Entrypoint =",CDR X,
  348. ", words =",Y);
  349. ENTRYPOINTS := CDR ENTRYPOINTS
  350. END;
  351. REMPROPL(CURRENTFNSYMS,'SYM);
  352. % REMPROPL(DDTSYMS,'SYM);
  353. SYMPOP SYMPDL;
  354. RETURN NIL;
  355. PHAS:FBF LIST('ERR,"Pass 2 phase",CURRENTFN,LOC,LITLOC,LITCNT);
  356. END)
  357. (8,8,0);
  358. SYMBOLIC PROCEDURE FASLEVAL X; % Used only by MAKEWORD;
  359. IF NUMBERP X THEN X % Embedded Pass2 LITs recurse;
  360. ELSE IF ATOM X THEN
  361. IF X EQ '!* THEN LIST('RELOC,FILOC+LOC) ELSE
  362. IF GET(X,'SYM) THEN GET(X,'SYM) ELSE
  363. IF NULL X OR MEMQ(X,UNDEFSYMS) THEN 0 ELSE
  364. IF GET(X,'MACOP) THEN GET(X,'MACOP) ELSE
  365. % IF NULL DDTSYMP THEN << !&PUSH(X,DDTSYMS);
  366. % !*DDTSYM X>> ELSE;
  367. <<!&PUSH(X,UNDEFSYMS); 0>>
  368. ELSE IF CAR X EQ 'QUOTE THEN X % Could check for GOFOO's...;
  369. ELSE IF MEMQ(CAR X,'(E FLUID FUNCTION ARRAY EVAL)) THEN X
  370. ELSE IF CAR X EQ 'C THEN
  371. % IF NOT FSLFLD1P() THEN <<FBF "BAD LIT";% 0>> ELSE
  372. % IF LAPCONST CDR X THEN <<FBF X;% 0>> ELSE;
  373. IF NOT PASS2LIT THEN
  374. <<LITERALS:=CDR LITERALS; % Chop off for phase test;
  375. (LAMBDA RLC;
  376. <<LITCNT:=LITCNT+
  377. % IF MEMQ(CADR X,'(ASCII SIXBIT BLOCK)) THEN
  378. % BLOBLENGTH CDR X ELSE;
  379. IF RECLITCOUNT(CDR X,NIL)=0 THEN 1
  380. ELSE <<RLC:=RLC+RECLITCOUNT(CDR X,NIL); % Embedded;
  381. RLC-LITCNT+1>>;
  382. LIST('RELOC,FILOC+LITLOC+RLC) >> )
  383. LITCNT>>
  384. ELSE (LAMBDA RLC; <<MAKEWORD CDR X; RLC>> )
  385. FASLEVAL '!* % Embedded;
  386. ELSE IF MEMQ(CAR X,'(ASCII SIXBIT SQUOZE !- !+)) THEN <<FBF X; 0>>
  387. ELSE IF CDR X THEN RELOADD(FASLEVAL CAR X,FASLEVAL CDR X)
  388. ELSE FASLEVAL CAR X;
  389. SYMBOLIC PROCEDURE RELOADD(X,Y);
  390. BEGIN SCALAR A;
  391. IF NUMBERP X THEN <<A:=X; X:=Y; Y:=A>>;
  392. IF NUMBERP Y THEN
  393. IF NUMBERP X THEN RETURN (X + Y)
  394. ELSE IF EQCAR(X,'RELOC) THEN RETURN
  395. LIST('RELOC,Y + CADR X);
  396. ERROR(0,LIST(X,Y,"NON RELOCATABLE"))
  397. END;
  398. SYMBOLIC PROCEDURE LAPCONST X; NIL;
  399. SYMBOLIC PROCEDURE RECLITCOUNT(XPR,PASS1);
  400. IF CDR XPR AND % POPJ P;
  401. CDDR XPR AND % MOVE 2 1;
  402. (XPR:= IF CADDR XPR EQ '!@ OR CADR XPR EQ '!@
  403. THEN CADDDR XPR ELSE CADDR XPR) AND
  404. NOT ATOM XPR AND
  405. CAR XPR EQ 'C AND % SUB P (C 0 0 2 2);
  406. NOT LAPCONST CDR XPR THEN
  407. IF PASS1 THEN <<!&PUSH(CDR XPR,LITERALS); 0>> ELSE
  408. % IF MEMQ(CADR XPR,'(ASCII SIXBIT BLOCK))
  409. % THEN BLOBLENGTH XPR ELSE;
  410. RECLITCOUNT(XPR,NIL)+1
  411. ELSE 0;
  412. %SYMBOLIC PROCEDURE !*DDTSYM X;
  413. % BEGIN SCALAR Y;
  414. % FBF LIST("unusual sym",X);
  415. % IF (Y:=!*GETSYM X) THEN PUT(X,'SYM,Y);
  416. % END;
  417. SYMBOLIC PROCEDURE COLLECTATOMS X;
  418. X AND (LAMBDA TYPE;
  419. IF TYPE EQ 'SYMBOL THEN IF NULL GET(X,'ATOMINDX)
  420. THEN << !&PUSH(X,ALLATOMS);
  421. PUT(X,'ATOMINDX,ATOMINDX:=ATOMINDX+1);
  422. BUFO(10,0,X)>> ELSE NIL
  423. ELSE IF TYPE EQ 'LIST THEN BEGIN LP: COLLECTATOMS CAR X;
  424. IF ATOM (X:=CDR X) THEN COLLECTATOMS X ELSE GO TO LP END
  425. ELSE IF MEMQ(TYPE,'(FIXNUM FLONUM BIGNUM STRING)) THEN
  426. IF NULL ASSOC(X . TYPE,NUMBERTABLE) THEN
  427. << !&PUSH((X . TYPE).(ATOMINDX:=ATOMINDX+1),NUMBERTABLE);
  428. BUFO(10,0,X)>>)
  429. (TYPEP X);
  430. SYMBOLIC PROCEDURE ATOMINDEX (X,TYPE);
  431. IF NULL X THEN 0 ELSE
  432. << IF NULL TYPE THEN TYPE:=TYPEP X;
  433. TYPE:=IF TYPE EQ 'SYMBOL THEN GET(X,'ATOMINDX) ELSE
  434. IF MEMQ(TYPE,'(FIXNUM FLONUM BIGNUM STRING))
  435. AND (TYPE:=ASSOC(X . TYPE,NUMBERTABLE)) THEN CDR TYPE;
  436. IF TYPE THEN TYPE ELSE FBF LIST('ERR,"Atomindex missing for",X)>>;
  437. SYMBOLIC PROCEDURE FASLDEFSYM (SYM,VAL);
  438. BEGIN SCALAR Z;
  439. IF NULL (Z:=GET(SYM,'SYM)) THEN !&PUSH(SYM,CURRENTFNSYMS) ELSE
  440. IF Z=VAL THEN RETURN Z ELSE
  441. IF NOT MEMQ(SYM,AMBIGSYMS) THEN
  442. <<!&PUSH(SYM,AMBIGSYMS);
  443. IF NOT MEMQ(SYM,CURRENTFNSYMS) THEN
  444. MAINSYMPDL:=!&PUSH(SYM.Z,SYMPDL)>>;
  445. PUT(SYM,'SYM,VAL);
  446. RETURN VAL;
  447. END;
  448. SYMBOLIC PROCEDURE TYPEP X;
  449. IF IDP X THEN 'SYMBOL
  450. ELSE IF PAIRP X THEN 'LIST
  451. ELSE IF STRINGP X THEN 'STRING
  452. ELSE IF BIGP X THEN 'BIGNUM
  453. ELSE IF FIXP X THEN 'FIXNUM
  454. ELSE IF FLOATP X THEN 'FLONUM;
  455. SYMBOLIC PROCEDURE BUFO (TYP,N,X);
  456. BEGIN SCALAR I,SS;
  457. IF !*FASLDEBUG THEN FBF LIST('BUF!*,TYP,N,X);
  458. PUTV(BTAR,BINCT,TYP);
  459. PUTV(BNAR,BINCT,N);
  460. PUTV(BXAR,BINCT,X);
  461. IF NOT(TYP EQ 15) AND BINCT<8 THEN RETURN BINCT:=BINCT+1;
  462. SS:=0;
  463. FOR I:=0:BINCT DO SS:=SS+ LSH(GETV(BTAR,I),4*(8-I));
  464. BFBO SS;
  465. FOR I:=0:BINCT DO
  466. BEGIN TYP:=GETV(BTAR,I);
  467. N:=GETV(BNAR,I);
  468. IF TYP<5 OR TYP EQ 6 OR TYP EQ 8 THEN RETURN BFBO N;
  469. X:=GETV(BXAR,I);
  470. IF TYP EQ 5 THEN <<LISTOUT X;
  471. BFBO BOOLE(7,LSH(-1,18),
  472. LSH(N,-18));
  473. BFBO SXHASH X>>
  474. ELSE IF TYP EQ 10 THEN (LAMBDA TYPE;
  475. IF TYPE EQ 'SYMBOL THEN <<SS:=GET(X,'PNAME);
  476. BFBO BOOLE(7,
  477. IF INTERNP X THEN 0
  478. ELSE LSH(1,32),
  479. LENGTH SS);
  480. MAPC(SS,FUNCTION BINV)>>
  481. ELSE IF TYPE EQ 'STRING THEN
  482. <<BFBO BOOLE(7,LSH(2,32),LENGTH CDR X);
  483. MAPC(CDR X,FUNCTION BINV)>>
  484. ELSE IF TYPE EQ 'BIGNUM THEN
  485. <<BFBO BOOLE(7,IF X<0
  486. THEN LSH(6,32)
  487. ELSE LSH(5,32),
  488. LENGTH CDR X);
  489. MAPC(REVERSE CDR X,FUNCTION BINV)>>
  490. ELSE IF TYPE EQ 'FLONUM
  491. THEN <<BFBO LSH(4,32); BINV CDR X>>
  492. ELSE <<BFBO IF TYPE EQ 'FIXNUM THEN LSH(3,32)
  493. ELSE LSH(4,32);
  494. BFBO X>>)
  495. (TYPEP X)
  496. ELSE IF TYP EQ 11 OR TYP EQ 9 THEN
  497. <<BFBO BOOLE(7,LSH(ATOMINDEX(CAR X,'SYMBOL),18),
  498. ATOMINDEX(CADR X,'SYMBOL));
  499. BFBO BOOLE(7,LSH(CADDR X,18),N)>>
  500. ELSE IF TYP EQ 14 THEN <<LISTOUT X; BFBO N>>
  501. ELSE IF TYP EQ 15 THEN BFBO (-30863143776)
  502. ELSE IF TYP EQ 7 THEN <<BFBO N; X AND BFBO X>>
  503. ELSE IF TYP EQ 13 THEN BFBO SQUOZE LIST X
  504. ELSE FBF LIST('ERR,"BUFO args:",TYP,N,X);
  505. END;
  506. RETURN BINCT:=0;
  507. END;
  508. SYMBOLIC PROCEDURE LISTOUT X;
  509. (LAMBDA TYPE;
  510. IF NOT(TYPE EQ 'LIST) THEN BFBO ATOMINDEX(X,TYPE) ELSE
  511. (BEGIN SCALAR I,Y;
  512. I:=0; Y:=X;
  513. LP: IF ATOM Y THEN
  514. RETURN BFBO BOOLE(7,I,IF Y THEN <<LISTOUT Y;
  515. LSH(2,33)>>
  516. ELSE LSH(1,33));
  517. LISTOUT CAR Y;
  518. I:=I+1; Y:=CDR Y;
  519. GO LP;
  520. END))
  521. (TYPEP X);
  522. SYMBOLIC PROCEDURE SXHASH X; 0;
  523. SYMBOLIC PROCEDURE SQUOZE X; 0;
  524. %SYMBOLIC PROCEDURE BLOBLENGTH X;
  525. % FBF LIST('BLOBLENGTH,X);
  526. SYMBOLIC PROCEDURE SYMPOP L;
  527. MAPC(L,FUNCTION (LAMBDA X; PUT(CAR X,'SYM,CDR X)));
  528. SYMBOLIC PROCEDURE REMPROPL(L,PROP);
  529. MAPC(L,FUNCTION(LAMBDA X; REMPROP(X,PROP)));
  530. SYMBOLIC PROCEDURE FBF L;
  531. IF CAR L EQ 'ERR THEN ERROR(0,L) ELSE WARNING L;
  532. SYMBOLIC PROCEDURE BFBO X;
  533. IF !*FASLDEBUG THEN FBF LIST('BINO,LSH(X,-18),LSH(LSH(X,18),-18))
  534. ELSE BINO X;
  535. SYMBOLIC PROCEDURE BINV X; BFBO EXAMINE !*BOX X;
  536. % SYMBOLIC PROCEDURE BINO X;% NIL; % For debugging;
  537. SYMBOLIC PROCEDURE MAKEWORD L;
  538. BEGIN SCALAR WRK,LSUM,RLC,A,B,C,SL,FSLFLD,F1;
  539. IF !*FASLDEBUG THEN FBF LIST("MW ",L);
  540. IF MEMQ(CAR L,'(ASCII SIXBIT BLOCK SQUOZE)) THEN GO TO ERR;
  541. LSUM:=RLC:=0;
  542. WRK:=L;
  543. FSLFLD:='((MACOP) (23 . 15) (0 . 262143) (18 . -1));
  544. WA: IF NULL WRK THEN GO TO XIT;
  545. A:= CAR WRK;
  546. IF A EQ '!@ THEN <<LSUM:=LSUM+LSH(1,22);WRK:= CDR WRK;GO TO WA>>;
  547. IF NOT NUMBERP(B:=FASLEVAL A) THEN GO TO NNM;
  548. WC: LSUM:=LSUM+ IF CAR(SL:=CAR FSLFLD) EQ 'MACOP THEN
  549. LSH(B,IF B<512 THEN 27 ELSE 18)
  550. ELSE LSH(BOOLE(1,CDR SL,B),CAR SL);
  551. WRK:=CDR WRK;
  552. IF (FSLFLD:=CDR FSLFLD) THEN GO TO WA;
  553. XIT: LOC:=LOC+1;
  554. BUFO (RLC,LSUM,IF RLC EQ 5 THEN F1 ELSE NIL);
  555. RETURN NIL;
  556. NNM: IF B EQ 'FOO THEN GO TO ERR;
  557. A:=CAR B;
  558. B:= CAR (C:=CDR B);
  559. IF NUMBERP A THEN GO TO NUM ELSE
  560. IF NOT(CAAR FSLFLD=0) THEN GO TO ERR ELSE
  561. IF A EQ 'RELOC THEN GO TO REL ELSE
  562. IF A EQ 'FLUID THEN GO TO FLU ELSE
  563. IF MEMQ(A,'(QUOTE E FUNCTION)) THEN GO TO QUO;
  564. ERR: FBF LIST("Unimplemented or error",L); % ARRAY, EVAL, etc;
  565. LSUM:=RLC:=0;
  566. GO TO XIT;
  567. REL: RLC:=1;
  568. IF CDR C THEN GO TO ERR ELSE GO TO WC;
  569. NUM: B:=A;
  570. IF C THEN GO TO ERR ELSE GO TO WC;
  571. FLU: COLLECTATOMS B;
  572. IF NOT (A:= TYPEP B) EQ 'SYMBOL THEN GO TO ERR;
  573. B:= ATOMINDEX(B,A);
  574. RLC:=2;
  575. GO TO WC;
  576. QUO: COLLECTATOMS B;
  577. IF (A:= TYPEP B) EQ 'LIST THEN
  578. <<F1:=B; B:=0; RLC:=5; GO TO WC>>;
  579. B:= ATOMINDEX(B,A);
  580. IF MEMQ(CAR L,'(CALL JCALL)) THEN RLC:=3 ELSE RLC:=4;
  581. GO TO WC;
  582. END;
  583. UNFLUID '(MSGCHN!* FSLCHN!*
  584. FILE CFL!* BTIME!*
  585. FASLOUTFILE USERFORF OFILE PROP BASE IBASE
  586. XPR DDTSYMS UNDEFSYMS SYM LITERALS NUMBERTABLE
  587. ENTRYPOINTS
  588. ALLATOMS AMBIGSYMS ATOMINDX BFUNCS BINCT CURRENTFNSYMS
  589. CURRENTFN DDTSYMP DDTSYMS !*FASLDEBUG FILOC LITCNT
  590. LITERALS LITLOC LOC MAINSYMPDL NUMBERTABLE PASS2LIT SYMBOLSP
  591. SYMPDL UNDEFSYMS WINP
  592. );
  593. COMMENT EQCAR and MKQUOTE defined to use FAP in LISP;
  594. SYMBOLIC PROCEDURE EQCAR(U,V);
  595. PAIRP U AND CAR U EQ V;
  596. SYMBOLIC PROCEDURE MKQUOTE U; LIST('QUOTE,U);
  597. END;