lap-to-asm.red 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176
  1. %
  2. % LAP-TO-ASM.RED - LAP to assembler translator
  3. %
  4. % Author: Eric Benson
  5. % Symbolic Computation Group
  6. % Computer Science Dept.
  7. % University of Utah
  8. % Date: 13 August 1981
  9. % Copyright (c) 1981 University of Utah
  10. %
  11. % 21-May-83 Mark R. Swanson
  12. % Added IndWord functions to support extended-20
  13. % 01-Mar-83 Nancy Kendzierski
  14. % Changed EVIN to PathIn in ASMOUT to enable search paths to be
  15. % used when doing system builds connected to a directory other
  16. % than pxx:, where xx=machine (hp, 20, vax, etc.)
  17. % Only set InputSymFile!*, OutputSymFile!*, GlobalDataFileName!*,
  18. % and InitFileNameFormat!* if they aren't already initialized.
  19. % Changed SEMIC!* declaration from global to fluid.
  20. % <PSL.COMP>LAP-TO-ASM.RED.5, 30-Apr-82 14:47:52, Edit by BENSON
  21. % Removed EVAL and IGNORE processing
  22. Imports '(PathIn);
  23. fluid '(Semic!*
  24. !*Comp
  25. !*PLap
  26. DfPrint!*
  27. CharactersPerWord
  28. AddressingUnitsPerItem
  29. AddressingUnitsPerFunctionCell
  30. InputSymFile!*
  31. OutputSymFile!*
  32. CodeOut!*
  33. DataOut!*
  34. InitOut!*;
  35. CodeFileNameFormat!*
  36. DataFileNameFormat!*
  37. InitFileNameFormat!*
  38. ModuleName!*
  39. UncompiledExpressions!*
  40. NextIDNumber!*
  41. OrderedIDList!*
  42. NilNumber!*
  43. !*MainFound
  44. !*MAIN
  45. !*DeclareBeforeUse
  46. MainEntryPointName!*
  47. EntryPoints!*
  48. LocalLabels!*
  49. CodeExternals!*
  50. CodeExporteds!*
  51. DataExternals!*
  52. DataExporteds!*
  53. ExternalDeclarationFormat!*
  54. ExportedDeclarationFormat!*
  55. LabelFormat!*
  56. FullWordFormat!*
  57. DoubleFloatFormat!*
  58. ReserveDataBlockFormat!*
  59. ReserveZeroBlockFormat!*
  60. UndefinedFunctionCellInstructions!*
  61. DefinedFunctionCellFormat!*
  62. PrintExpressionForm!*
  63. PrintExpressionFormPointer!*
  64. CommentFormat!*
  65. NumericRegisterNames!*
  66. ExpressionCount!*
  67. ASMOpenParen!*
  68. ASMCloseParen!*
  69. ToBeCompiledExpressions!*
  70. GlobalDataFileName!*
  71. );
  72. % Default values; set up if not already initialized.
  73. if null InputSymFile!* then InputSymFile!* := "psl.sym";
  74. if null OutputSymFile!* then OutputSymFile!* := "psl.sym";
  75. if null GlobalDataFileName!* then GlobalDataFileName!* := "global-data.red";
  76. if null InitFileNameFormat!* then InitFileNameFormat!* := "%w.init";
  77. lisp procedure DfPrintASM U; %. Called by TOP-loop, DFPRINT!*
  78. begin scalar Nam, Ty, Fn;
  79. if atom U then return NIL;
  80. Fn := car U;
  81. IF FN = 'PUTD THEN GOTO DB2;
  82. IF NOT (FN MEMQ '(DE DF DM DN)) THEN GOTO DB1;
  83. NAM:=CADR U;
  84. U:='LAMBDA . CDDR U;
  85. TY:=CDR ASSOC(FN, '((DE . EXPR)
  86. (DF . FEXPR)
  87. (DM . MACRO)
  88. (DN . NEXPR)));
  89. DB3: if Ty = 'MACRO then begin scalar !*Comp;
  90. PutD(Nam, Ty, U); % Macros get defined now
  91. end;
  92. if FlagP(Nam, 'Lose) then <<
  93. ErrorPrintF("*** %r has not been defined, because it is flagged LOSE",
  94. Nam);
  95. return NIL >>;
  96. IF FLAGP(TY,'COMPILE) THEN
  97. << PUT(NAM,'CFNTYPE,LIST TY);
  98. U := LIST('!*ENTRY,NAM,TY,LENGTH CADR U)
  99. . !&COMPROC(U, NAM);
  100. if !*PLAP then for each X in U do Print X;
  101. if TY neq 'EXPR then
  102. DfPrintASM list('put, MkQuote Nam, '(quote TYPE), MkQuote TY);
  103. ASMOUTLAP U >>
  104. ELSE % should never happen
  105. SaveUncompiledExpression LIST('PUTD, MKQUOTE NAM,
  106. MKQUOTE TY,
  107. MKQUOTE U);
  108. RETURN NIL;
  109. DB1: % Simple S-EXPRESSION, maybe EVAL it;
  110. IF NOT PAIRP U THEN RETURN NIL;
  111. if (Fn := get(car U, 'ASMPreEval)) then return Apply(Fn, list U)
  112. else if (Fn := GetD car U) and car Fn = 'MACRO then
  113. return DFPRINTASM Apply(cdr Fn, list U);
  114. SaveUncompiledExpression U;
  115. RETURN NIL;
  116. DB2: NAM:=CADR U;
  117. TY:=CADDR U;
  118. FN:=CADDDR U;
  119. IF EQCAR(NAM,'QUOTE) THEN << NAM:=CADR NAM;
  120. IF EQCAR(TY,'QUOTE) THEN << TY:=CADR TY;
  121. IF PAIRP FN AND CAR FN MEMBER '(FUNCTION QUOTE) THEN << FN:=CADR FN;
  122. IF TY MEMQ '(EXPR FEXPR MACRO NEXPR) THEN
  123. << U:=FN; GOTO DB3 >> >> >> >>;
  124. GOTO DB1;
  125. END;
  126. lisp procedure ASMPreEvalLoadTime U;
  127. DFPrintASM cadr U; % remove LOADTIME
  128. put('LoadTime, 'ASMPreEval, 'ASMPreEvalLoadTime);
  129. lisp procedure ASMPreEvalStartupTime U;
  130. SaveForCompilation cadr U;
  131. put('StartupTime, 'ASMPreEval, 'ASMPreEvalStartupTime);
  132. lisp procedure ASMPreEvalProgN U;
  133. for each X in cdr U do
  134. DFPrintASM X;
  135. put('ProgN, 'ASMPreEval, 'ASMPreEvalProgN);
  136. put('WDeclare, 'ASMPreEval, 'Eval); % do it now
  137. lisp procedure ASMPreEvalSetQ U;
  138. begin scalar X, Val;
  139. X := cadr U;
  140. Val := caddr U;
  141. return if ConstantP Val or Val = T then
  142. << FindIDNumber X;
  143. put(X, 'InitialValue, Val);
  144. NIL >>
  145. else if null Val then
  146. << FindIDNumber X;
  147. RemProp(X, 'InitialValue);
  148. Flag(list X, 'NilInitialValue);
  149. NIL >>
  150. else if EqCar(Val, 'QUOTE) then
  151. << FindIDNumber X;
  152. Val := cadr Val;
  153. if null Val then
  154. << RemProp(X, 'InitialValue);
  155. Flag(list X, 'NilInitialValue) >>
  156. else
  157. put(X, 'InitialValue, Val);
  158. NIL >>
  159. else if IDP Val and get(Val, 'InitialValue)
  160. or FlagP(Val, 'NilInitialValue) then
  161. << if (Val := get(Val, 'InitialValue)) then
  162. put(X, 'InitialValue, Val)
  163. else Flag(list X, 'NilInitialValue) >>
  164. else SaveUncompiledExpression U; % just check simple cases, else return
  165. end;
  166. put('SetQ, 'ASMPreEval, 'ASMPreEvalSetQ);
  167. lisp procedure ASMPreEvalPutD U;
  168. SaveUncompiledExpression CheckForEasySharedEntryPoints U;
  169. lisp procedure CheckForEasySharedEntryPoints U;
  170. %
  171. % looking for (PUTD (QUOTE name1) xxxx (CDR (GETD (QUOTE name2))))
  172. %
  173. begin scalar NU, Nam, Exp;
  174. NU := cdr U;
  175. Nam := car NU;
  176. if car Nam = 'QUOTE then Nam := cadr Nam else return U;
  177. NU := cdr NU;
  178. Exp := cadr NU;
  179. if not (car Exp = 'CDR) then return U;
  180. Exp := cadr Exp;
  181. if not (car Exp = 'GETD) then return U;
  182. Exp := cadr Exp;
  183. if not (car Exp = 'QUOTE) then return U;
  184. Exp := cadr Exp;
  185. FindIDNumber Nam;
  186. put(Nam, 'EntryPoint, FindEntryPoint Exp);
  187. if not (car NU = '(QUOTE EXPR)) then return list('Put, '(Quote Type),
  188. car NU);
  189. return NIL;
  190. end;
  191. put('PutD, 'ASMPreEval, 'ASMPreEvalPutD);
  192. lisp procedure ASMPreEvalFluidAndGlobal U;
  193. << if EqCar(cadr U, 'QUOTE) then Flag(cadr cadr U, 'NilInitialValue);
  194. SaveUncompiledExpression U >>;
  195. put('Fluid, 'ASMPreEval, 'ASMPreEvalFluidAndGlobal);
  196. put('Global, 'ASMPreEval, 'ASMPreEvalFluidAndGlobal);
  197. CommentOutCode <<
  198. fluid '(NewFluids!* NewGlobals!*);
  199. lisp procedure ASMPreEvalFluidAndGlobal U;
  200. begin scalar L;
  201. L := cadr U;
  202. return if car L = 'QUOTE then
  203. << L := cadr L;
  204. if car U = 'FLUID then
  205. NewFluids!* := UnionQ(NewFluids!*, L) % take union
  206. else NewGlobals!* := UnionQ(NewGlobals!*, L);
  207. Flag(L, 'NilInitialValue);
  208. NIL >>
  209. else SaveUncompiledExpression U;
  210. end;
  211. put('Fluid, 'ASMPreEval, 'ASMPreEvalFluidAndGlobal);
  212. put('Global, 'ASMPreEval, 'ASMPreEvalFluidAndGlobal);
  213. >>;
  214. lisp procedure ASMPreEvalLAP U;
  215. if EqCar(cadr U, 'QUOTE) then ASMOutLap cadr cadr U
  216. else SaveUncompiledExpression U;
  217. put('LAP, 'ASMPreEval, 'ASMPreEvalLAP);
  218. CommentOutCode <<
  219. lisp procedure InitialPut(Nam, Ind, Val);
  220. begin scalar L, P;
  221. FindIDNumber Nam;
  222. if (P := Atsoc(Ind, L := get(Nam, 'InitialPropertyList))) then
  223. Rplacd(P, Val)
  224. else put(Nam, 'InitialPropertyList, (Ind . Val) . L);
  225. end;
  226. lisp procedure InitialRemprop(Nam, Ind);
  227. begin scalar L;
  228. if (L := get(Nam, 'InitialPropertyList)) then
  229. put(Nam, 'InitialPropertyList, DelAtQIP(Ind, L));
  230. end;
  231. lisp procedure InitialFlag1(Nam, Ind);
  232. begin scalar L, P;
  233. FindIDNumber Nam;
  234. if not Ind memq (L := get(Nam, 'InitialPropertyList)) then
  235. put(Nam, 'InitialPropertyList, Ind . L);
  236. end;
  237. lisp procedure InitialRemFlag1(Nam, Ind);
  238. begin scalar L;
  239. if (L := get(Nam, 'InitialPropertyList)) then
  240. put(Nam, 'InitialPropertyList, DelQIP(Ind, L));
  241. end;
  242. lisp procedure ASMPreEvalPut U;
  243. begin scalar Nam, Ind, Val;
  244. Nam := second U;
  245. Ind := third U;
  246. Val := fourth U;
  247. if EqCar(Nam, 'QUOTE) and EqCar(Ind, 'QUOTE) and
  248. (ConstantP Val or Val = T or EqCar(Val, 'QUOTE)) then
  249. InitialPut(second Nam, second Ind, if EqCar(Val, 'QUOTE) then
  250. second Val else Val)
  251. else SaveUncompiledExpression U;
  252. end;
  253. put('put, 'ASMPreEval, 'ASMPreEvalPut);
  254. lisp procedure ASMPreEvalRemProp U;
  255. begin scalar Nam, Ind;
  256. Nam := second U;
  257. Ind := third U;
  258. if EqCar(Nam, 'QUOTE) and EqCar(Ind, 'QUOTE) then
  259. InitialRemProp(second Nam, second Ind)
  260. else SaveUncompiledExpression U;
  261. end;
  262. put('RemProp, 'ASMPreEval, 'ASMPreEvalRemProp);
  263. lisp procedure ASMPreEvalDefList U;
  264. begin scalar DList, Ind;
  265. DList := second U;
  266. Ind := third U;
  267. if EqCar(DList, 'QUOTE) and EqCar(Ind, 'QUOTE) then
  268. << DList := second DList;
  269. Ind := second Ind;
  270. for each X in Dlist do InitialPut(first X, Ind, second X) >>
  271. else SaveUncompiledExpression U;
  272. end;
  273. put('DefList, 'ASMPreEval, 'ASMPreEvalDefList);
  274. lisp procedure ASMPreEvalFlag U;
  275. begin scalar NameList, Ind;
  276. NameList := second U;
  277. Ind := third U;
  278. if EqCar(NameList, 'QUOTE) and EqCar(Ind, 'QUOTE) then
  279. << Ind := second Ind;
  280. for each X in second NameList do
  281. InitialFlag1(X, Ind) >>
  282. else SaveUncompiledExpression U;
  283. end;
  284. put('flag, 'ASMPreEval, 'ASMPreEvalFlag);
  285. lisp procedure ASMPreEvalRemFlag U;
  286. begin scalar NameList, Ind;
  287. NameList := second U;
  288. Ind := third U;
  289. if EqCar(NameList, 'QUOTE) and EqCar(Ind, 'QUOTE) then
  290. << Ind := second Ind;
  291. for each X in second NameList do
  292. InitialRemFlag1(X, Ind) >>
  293. else SaveUncompiledExpression U;
  294. end;
  295. put('RemFlag, 'ASMPreEval, 'ASMPreEvalRemFlag);
  296. lisp procedure ASMPreEvalGlobal U;
  297. begin scalar NameList;
  298. NameList := second U;
  299. if EqCar(NameList, 'QUOTE) then
  300. for each X in second NameList do
  301. InitialPut(X, 'TYPE, 'Global)
  302. else SaveUncompiledExpression U;
  303. end;
  304. put('Global, 'ASMPreEval, 'ASMPreEvalGlobal);
  305. lisp procedure ASMPreEvalFluid U;
  306. begin scalar NameList;
  307. NameList := second U;
  308. if EqCar(NameList, 'QUOTE) then
  309. for each X in second NameList do
  310. InitialPut(X, 'TYPE, 'FLUID)
  311. else SaveUncompiledExpression U;
  312. end;
  313. put('Fluid, 'ASMPreEval, 'ASMPreEvalFluid);
  314. lisp procedure ASMPreEvalUnFluid U;
  315. begin scalar NameList;
  316. NameList := second U;
  317. if EqCar(NameList, 'QUOTE) then
  318. for each X in second NameList do
  319. InitialRemProp(X, 'TYPE)
  320. else SaveUncompiledExpression U;
  321. end;
  322. put('UnFluid, 'ASMPreEval, 'ASMPreEvalUnFluid);
  323. >>;
  324. lisp procedure SaveUncompiledExpression U;
  325. if PairP U then
  326. begin scalar OldOut;
  327. OldOut := WRS InitOut!*;
  328. Print U;
  329. WRS OldOut;
  330. end;
  331. ToBeCompiledExpressions!* := NIL . NIL;
  332. lisp procedure SaveForCompilation U;
  333. if atom U or U member car ToBeCompiledExpressions!* then NIL
  334. else if car U = 'progn then
  335. for each X in cdr U do SaveForCompilation X
  336. else TConc(ToBeCompiledExpressions!*, U);
  337. SYMBOLIC PROCEDURE ASMOUT FIL;
  338. begin scalar OldOut;
  339. ModuleName!* := FIL;
  340. Prin2T "ASMOUT: IN files; or type in expressions";
  341. Prin2T "When all done execute ASMEND;";
  342. CodeOut!* := Open(BldMsg(CodeFileNameFormat!*, ModuleName!*), 'OUTPUT);
  343. OldOut := WRS CodeOut!*;
  344. LineLength 1000;
  345. WRS OldOut;
  346. CodeFileHeader();
  347. DataOut!* := Open(BldMsg(DataFileNameFormat!*, ModuleName!*), 'OUTPUT);
  348. OldOut := WRS DataOut!*;
  349. LineLength 1000;
  350. WRS OldOut;
  351. DataFileHeader();
  352. InitOut!* := Open(BldMsg(InitFileNameFormat!*, ModuleName!*), 'OUTPUT);
  353. ReadSYMFile();
  354. DFPRINT!* := 'DFPRINTASM;
  355. RemD 'OldLap;
  356. PutD('OldLap, 'EXPR, cdr RemD 'Lap);
  357. PutD('Lap, 'EXPR, cdr GetD 'ASMOutLap);
  358. !*DEFN := T;
  359. SEMIC!* := '!$ ; % to turn echo off for IN
  360. if not ((ModuleName!* = "main")
  361. or !*Main) then PathIn GlobalDataFileName!*
  362. else !*Main := T;
  363. end;
  364. lisp procedure ASMEnd;
  365. << off SysLisp;
  366. if !*MainFound then
  367. << CompileUncompiledExpressions();
  368. % WriteInitFile();
  369. InitializeSymbolTable() >>
  370. else WriteSymFile();
  371. CodeFileTrailer();
  372. Close CodeOut!*;
  373. DataFileTrailer();
  374. Close DataOut!*;
  375. Close InitOut!*;
  376. RemD 'Lap;
  377. PutD('Lap, 'EXPR, cdr GetD 'OldLap);
  378. DFPRINT!* := NIL;
  379. !*DEFN := NIL >>;
  380. FLAG('(ASMEND), 'IGNORE);
  381. DEFINEROP('ASMEND,NIL,ESTAT('ASMEND));
  382. lisp procedure CompileUncompiledExpressions();
  383. << CommentOutCode << AddFluidAndGlobalDecls(); >>;
  384. DFPRINTASM list('DE, 'INITCODE, '(),
  385. 'PROGN . car ToBeCompiledExpressions!*) >>;
  386. CommentOutCode <<
  387. lisp procedure AddFluidAndGlobalDecls();
  388. << SaveUncompiledExpression list('GLOBAL, MkQuote NewGlobals!*);
  389. SaveUncompiledExpression list('FLUID, MkQuote NewFluids!*) >>;
  390. >>;
  391. lisp procedure ReadSymFile();
  392. LapIN InputSymFile!*;
  393. lisp procedure WriteSymFile();
  394. begin scalar NewOut, OldOut;
  395. OldOut := WRS(NewOut := Open(OutputSymFile!*, 'OUTPUT));
  396. print list('SaveForCompilation,
  397. MkQuote('progn . car ToBeCompiledExpressions!*));
  398. SaveIDList();
  399. SetqPrint 'NextIDNumber!*;
  400. SetqPrint 'StringGenSym!*;
  401. MapObl function PutPrintEntryAndSym;
  402. WRS OldOut;
  403. Close NewOut;
  404. end;
  405. CommentOutCode <<
  406. lisp procedure WriteInitFile();
  407. begin scalar OldOut, NewOut;
  408. NewOut := Open(InitFileName!*, 'OUTPUT);
  409. OldOut := WRS NewOut;
  410. for each X in car UncompiledExpressions!* do PrintInit X;
  411. Close NewOut;
  412. WRS OldOut;
  413. end;
  414. lisp procedure PrintInit X;
  415. if EqCar(X, 'progn) then
  416. for each Y in cdr X do PrintInit Y
  417. else Print X;
  418. >>;
  419. lisp procedure SaveIDList();
  420. << Print list('setq, 'OrderedIDList!*, MkQuote car OrderedIDList!*);
  421. Print quote(OrderedIDList!* :=
  422. OrderedIDList!* . LastPair OrderedIDList!*) >>;
  423. lisp procedure SetqPrint U;
  424. print list('SETQ, U, MkQuote Eval U);
  425. lisp procedure PutPrint(X, Y, Z);
  426. print list('PUT, MkQuote X, MkQuote Y, MkQuote Z);
  427. lisp procedure PutPrintEntryAndSym X;
  428. begin scalar Y;
  429. if (Y := get(X, 'EntryPoint)) then PutPrint(X, 'EntryPoint, Y);
  430. if (Y := get(X, 'IDNumber)) then
  431. PutPrint(X, 'IDNumber, Y);
  432. CommentOutCode <<
  433. if (Y := get(X, 'InitialPropertyList)) then
  434. PutPrint(X, 'InitialPropertyList, Y);
  435. >>;
  436. if (Y := get(X, 'InitialValue)) then
  437. PutPrint(X, 'InitialValue, Y)
  438. else if FlagP(X, 'NilInitialValue) then
  439. print list('flag, MkQuote list X, '(quote NilInitialValue));
  440. if get(X, 'SCOPE) = 'EXTERNAL then
  441. << PutPrint(X, 'SCOPE, 'EXTERNAL);
  442. PutPrint(X, 'ASMSymbol, get(X, 'ASMSymbol));
  443. if get(X, 'WVar) then PutPrint(X, 'WVar, X)
  444. else if get(X, 'WArray) then PutPrint(X, 'WArray, X)
  445. else if get(X, 'WString) then PutPrint(X, 'WString, X)
  446. else if (Y := get(X, 'WConst)) then PutPrint(X, 'WConst, Y) >>;
  447. end;
  448. lisp procedure FindIDNumber U;
  449. begin scalar I;
  450. return if (I := ID2Int U) <= 128 then I
  451. else if (I := get(U, 'IDNumber)) then I
  452. else
  453. << put(U, 'IDNumber, I := NextIDNumber!*);
  454. OrderedIDList!* := TConc(OrderedIDList!*, U);
  455. NextIDNumber!* := NextIDNumber!* + 1;
  456. I >>;
  457. end;
  458. OrderedIDList!* := NIL . NIL;
  459. NextIDNumber!* := 129;
  460. lisp procedure InitializeSymbolTable();
  461. begin scalar MaxSymbol;
  462. MaxSymbol := get('MaxSymbols, 'WConst);
  463. if MaxSymbol < NextIDNumber!* then
  464. << ErrorPrintF("*** MaxSymbols %r is too small; at least %r is needed",
  465. MaxSymbol, NextIDNumber!*);
  466. MaxSymbol := NextIDNumber!* + 100 >>;
  467. Flag('(NIL), 'NilInitialValue);
  468. put('T, 'InitialValue, 'T);
  469. put('!$EOF!$, 'InitialValue, Int2ID get('EOF, 'CharConst));
  470. put('!$EOL!$, 'InitialValue, '!
  471. );
  472. NilNumber!* := CompileConstant NIL;
  473. DataAlignFullWord();
  474. %/ This is a BUG? M.L. G.
  475. %/ for I := NextIDNumber!* step 1 until MaxSymbol do
  476. %/ DataPrintFullWord NilNumber!*;
  477. InitializeSymVal();
  478. DataReserveBlock((MaxSymbol - NextIDNumber!*) + 1);
  479. InitializeSymPrp();
  480. DataReserveBlock((MaxSymbol - NextIDNumber!*) + 1);
  481. %/ This is a BUG? M.L. G.
  482. %/ for I := NextIDNumber!* step 1 until MaxSymbol do
  483. %/ DataPrintFullWord NilNumber!*;
  484. InitializeSymNam MaxSymbol;
  485. InitializeSymFnc();
  486. DataReserveFunctionCellBlock((MaxSymbol - NextIDNumber!*) + 1);
  487. DataAlignFullWord();
  488. DataPrintGlobalLabel FindGlobalLabel 'NextSymbol;
  489. DataPrintFullWord NextIDNumber!*;
  490. end;
  491. lisp procedure InitializeSymPrp();
  492. << CommentOutCode << InitializeHeap(); >>; % init prop lists
  493. DataPrintGlobalLabel FindGlobalLabel 'SymPrp;
  494. for I := 0 step 1 until 128 do
  495. InitSymPrp1 Int2ID I;
  496. for each X in car OrderedIDList!* do
  497. InitSymPrp1 X >>;
  498. lisp procedure InitSymPrp1 X;
  499. <<
  500. CommentOutCode <<
  501. DataPrintFullWord(if (X := get(X, 'InitialPropertyList)) then
  502. X
  503. else NilNumber!*);
  504. >>;
  505. DataPrintFullWord NilNumber!* >>;
  506. CommentOutCode <<
  507. lisp procedure InitializeHeap();
  508. begin scalar L;
  509. DataPrintGlobalLabel FindGlobalLabel 'Heap;
  510. for I := 0 step 1 until 128 do
  511. PrintPropertyList Int2ID I;
  512. for each X in car OrderedIDList!* do
  513. PrintPropertyList X;
  514. L := get('HeapSize, 'WConst);
  515. end;
  516. >>;
  517. lisp procedure InitializeSymNam MaxSymbol;
  518. << DataPrintGlobalLabel FindGlobalLabel 'SymNam;
  519. for I := 0 step 1 until 128 do
  520. DataPrintFullWord CompileConstant ID2String Int2ID I;
  521. for each IDName in car OrderedIDList!* do
  522. DataPrintFullWord CompileConstant ID2String IDName;
  523. MaxSymbol := MaxSymbol - 1;
  524. for I := NextIDNumber!* step 1 until MaxSymbol do
  525. DataPrintFullWord(I + 1);
  526. DataPrintFullWord 0 >>;
  527. lisp procedure InitializeSymVal();
  528. << DataPrintGlobalLabel FindGlobalLabel 'SymVal;
  529. for I := 0 step 1 until 128 do InitSymVal1 Int2ID I;
  530. for each X in car OrderedIDList!* do InitSymVal1 X >>;
  531. lisp procedure InitSymVal1 X;
  532. begin scalar Val;
  533. return DataPrintFullWord(if (Val := get(X, 'InitialValue)) then
  534. CompileConstant Val
  535. else if FlagP(X, 'NilInitialValue) then
  536. NilNumber!*
  537. else list('MkItem, get('Unbound, 'WConst),
  538. FindIDNumber X));
  539. end;
  540. lisp procedure InitializeSymFnc();
  541. << DataPrintGlobalLabel FindGlobalLabel 'SymFnc;
  542. for I := 0 step 1 until 128 do InitSymFnc1 Int2ID I;
  543. for each X in car OrderedIDList!* do InitSymFnc1 X >>;
  544. lisp procedure InitSymFnc1 X;
  545. begin scalar EP;
  546. EP := get(X, 'EntryPoint);
  547. if null EP then DataPrintUndefinedFunctionCell()
  548. else DataPrintDefinedFunctionCell EP;
  549. end;
  550. lisp procedure ASMOutLap U;
  551. begin scalar LocalLabels!*, OldOut;
  552. U := Pass1Lap U; % Expand cmacros, quoted expressions
  553. CodeBlockHeader();
  554. OldOut := WRS CodeOut!*;
  555. for each X in U do ASMOutLap1 X;
  556. WRS OldOut;
  557. CodeBlockTrailer();
  558. end;
  559. lisp procedure ASMOutLap1 X;
  560. begin scalar Fn;
  561. return if StringP X then PrintLabel X
  562. else if atom X then PrintLabel FindLocalLabel X
  563. else if (Fn := get(car X, 'ASMPseudoOp)) then Apply(Fn, list X)
  564. else
  565. % instruction output form is:
  566. % "space" <opcode> [ "space" <operand> { "comma" <operand> } ] "newline"
  567. << Prin2 '! ; % Space
  568. PrintOpcode car X;
  569. X := cdr X;
  570. if not null X then
  571. << Prin2 '! ; % SPACE
  572. PrintOperand car X;
  573. for each U in cdr X do
  574. << Prin2 '!,; % COMMA
  575. PrintOperand U >> >>;
  576. Prin2 !$EOL!$ >>; % NEWLINE
  577. end;
  578. put('!*Entry, 'ASMPseudoOp, 'ASMPrintEntry);
  579. lisp procedure ASMPrintEntry X;
  580. begin scalar Y;
  581. PrintComment X;
  582. X := cadr X;
  583. Y := FindEntryPoint X;
  584. if not FlagP(X, 'InternalFunction) then FindIDNumber X;
  585. if X eq MainEntryPointName!* then
  586. << !*MainFound := T;
  587. SpecialActionForMainEntryPoint() >>
  588. else CodeDeclareExportedUse Y;
  589. end;
  590. Procedure CodeDeclareExportedUse Y;
  591. if !*DeclareBeforeUse then
  592. << CodeDeclareExported Y;
  593. PrintLabel Y >>
  594. else
  595. << PrintLabel Y;
  596. CodeDeclareExported Y >>;
  597. lisp procedure FindEntryPoint X;
  598. begin scalar E;
  599. return if (E := get(X, 'EntryPoint)) then E
  600. else if ASMSymbolP X and not get(X, 'ASMSymbol) then
  601. << put(X, 'EntryPoint, X);
  602. X >>
  603. else
  604. << E := StringGenSym();
  605. put(X, 'EntryPoint, E);
  606. E >>;
  607. end;
  608. lisp procedure ASMPseudoPrintFloat X;
  609. PrintF(DoubleFloatFormat!*, cadr X);
  610. put('Float, 'ASMPseudoOp, 'ASMPseudoPrintFloat);
  611. lisp procedure ASMPseudoPrintFullWord X;
  612. for each Y in cdr X do PrintFullWord Y;
  613. put('FullWord, 'ASMPseudoOp, 'ASMPseudoPrintFullWord);
  614. lisp procedure ASMPseudoPrintIndWord X;
  615. for each Y in cdr X do PrintIndWord Y;
  616. put('IndWord, 'ASMPseudoOp, 'ASMPseudoPrintIndWord);
  617. lisp procedure ASMPseudoPrintByte X;
  618. PrintByteList cdr X;
  619. put('Byte, 'ASMPseudoOp, 'ASMPseudoPrintByte);
  620. lisp procedure ASMPseudoPrintHalfWord X;
  621. PrintHalfWordList cdr X;
  622. put('HalfWord, 'ASMPseudoOp, 'ASMPseudoPrintHalfWord);
  623. lisp procedure ASMPseudoPrintString X;
  624. PrintString cadr X;
  625. put('String, 'ASMPseudoOp, 'ASMPseudoPrintString);
  626. lisp procedure PrintOperand X;
  627. if StringP X then Prin2 X
  628. else if NumberP X then PrintNumericOperand X
  629. else if IDP X then Prin2 FindLabel X
  630. else begin scalar Hd, Fn;
  631. Hd := car X;
  632. if (Fn := get(Hd, 'OperandPrintFunction)) then
  633. Apply(Fn, list X)
  634. else if (Fn := GetD Hd) and car Fn = 'MACRO then
  635. PrintOperand Apply(cdr Fn, list X)
  636. else if (Fn := WConstEvaluable X) then PrintOperand Fn
  637. else PrintExpression X;
  638. end;
  639. put('REG, 'OperandPrintFunction, 'PrintRegister);
  640. lisp procedure PrintRegister X;
  641. begin scalar Nam;
  642. X := cadr X;
  643. if StringP X then Prin2 X
  644. else if NumberP X then Prin2 GetV(NumericRegisterNames!*, X)
  645. else if Nam := RegisterNameP X then Prin2 Nam
  646. else
  647. << ErrorPrintF("***** Unknown register %r", X);
  648. Prin2 X >>;
  649. end;
  650. lisp procedure RegisterNameP X;
  651. get(X, 'RegisterName);
  652. lisp procedure ASMEntry X;
  653. PrintExpression
  654. list('plus2, 'SymFnc,
  655. list('times2, AddressingUnitsPerFunctionCell,
  656. list('IDLoc, cadr X)));
  657. put('Entry, 'OperandPrintFunction, 'ASMEntry);
  658. lisp procedure ASMInternalEntry X;
  659. Prin2 FindEntryPoint cadr X;
  660. put('InternalEntry, 'OperandPrintFunction, 'ASMInternalEntry);
  661. put('InternalEntry, 'ASMExpressionFunction, 'ASMInternalEntry);
  662. macro procedure ExtraReg U;
  663. list('plus2, '(WArray ArgumentBlock), (cadr U - (LastActualReg!& + 1))
  664. * AddressingUnitsPerItem);
  665. lisp procedure ASMSyslispVarsPrint X;
  666. Prin2 FindGlobalLabel cadr X;
  667. DefList('((WVar ASMSyslispVarsPrint)
  668. (WArray ASMSyslispVarsPrint)
  669. (WString ASMSyslispVarsPrint)), 'OperandPrintFunction);
  670. DefList('((WVar ASMSyslispVarsPrint)
  671. (WArray ASMSyslispVarsPrint)
  672. (WString ASMSyslispVarsPrint)), 'ASMExpressionFunction);
  673. lisp procedure ASMPrintValueCell X;
  674. PrintExpression list('plus2, 'SymVal,
  675. list('times, AddressingUnitsPerItem,
  676. list('IDLoc, cadr X)));
  677. DefList('((fluid ASMPrintValueCell)
  678. (!$fluid ASMPrintValueCell)
  679. (global ASMPrintValueCell)
  680. (!$global ASMPrintValueCell)), 'OperandPrintFunction);
  681. % Redefinition of WDeclare for output to assembler file
  682. % if either UpperBound or Initializer are NIL, they are considered to be
  683. % unspecified.
  684. fexpr procedure WDeclare U;
  685. for each X in cddr U do WDeclare1(car X, car U, cadr U, cadr X, caddr X);
  686. flag('(WDeclare), 'IGNORE);
  687. lisp procedure WDeclare1(Name, Scope, Typ, UpperBound, Initializer);
  688. if Typ = 'WCONST then
  689. if Scope = 'EXTERNAL and not get(Name, 'WCONST) then
  690. ErrorPrintF("*** A value has not been defined for WConst %r",
  691. Name)
  692. else
  693. << put(Name, 'SCOPE, if Scope = 'EXPORTED then 'EXTERNAL else Scope);
  694. put(Name, 'WCONST, WConstReform Initializer) >>
  695. else
  696. << put(Name, Typ, Name);
  697. if Scope = 'EXTERNAL then
  698. << put(Name, 'SCOPE, 'EXTERNAL);
  699. if not RegisterNameP Name then % kludge to avoid declaring
  700. << Name := LookupOrAddASMSymbol Name;
  701. DataDeclareExternal Name; % registers as variables
  702. CodeDeclareExternal Name >> >>
  703. else
  704. << put(Name, 'SCOPE, if Scope = 'EXPORTED then 'EXTERNAL else Scope);
  705. Name := LookupOrAddASMSymbol Name;
  706. if !*DeclareBeforeUse then DataDeclareExported Name;
  707. DataInit(Name,
  708. Typ,
  709. UpperBound,
  710. Initializer);
  711. if not !*DeclareBeforeUse then DataDeclareExported Name;
  712. CodeDeclareExternal Name >> >>;
  713. lisp procedure DataInit(ASMSymbol, Typ, UpperBound, Initializer);
  714. << DataAlignFullWord();
  715. if Typ = 'WVAR then
  716. << if UpperBound then
  717. ErrorPrintF "*** An UpperBound may not be specified for a WVar";
  718. Initializer := if Initializer then WConstReform Initializer else 0;
  719. DataPrintVar(ASMSymbol, Initializer) >>
  720. else
  721. << if UpperBound and Initializer then
  722. ErrorPrintF "*** Can't have both UpperBound and initializer"
  723. else if not (UpperBound or Initializer) then
  724. ErrorPrintF "*** Must have either UpperBound or initializer"
  725. else if UpperBound then
  726. DataPrintBlock(ASMSymbol, WConstReform UpperBound, Typ)
  727. else
  728. << Initializer := if StringP Initializer then Initializer
  729. else WConstReformLis Initializer;
  730. DataPrintList(ASMSymbol, Initializer, Typ) >> >> >>;
  731. lisp procedure WConstReform U;
  732. begin scalar X;
  733. return if FixP U or StringP U then U
  734. else if IDP U then
  735. if get(U, 'WARRAY) or get(U, 'WSTRING) then U
  736. else if get(U,'WVAR) then list('GETMEM,U)
  737. else if (X := get(U, 'WCONST)) then X
  738. else ErrorPrintF("*** Unknown symbol %r in WConstReform", U)
  739. else if PairP U then
  740. if (X := get(car U, 'WConstReformPseudo)) then Apply(X, list U)
  741. else if (X := get(car U, 'DOFN)) then X . WConstReformLis cdr U
  742. else if MacroP car U then WConstReform Apply(cdr GetD car U, list U)
  743. else car U . WConstReformLis cdr U
  744. else ErrorPrintF("*** Illegal expression %r in WConstReform", U);
  745. end;
  746. lisp procedure WConstReformIdent U;
  747. U;
  748. put('InternalEntry, 'WConstReformPseudo, 'WConstReformIdent);
  749. lisp procedure WConstReformQuote U;
  750. CompileConstant cadr U;
  751. put('QUOTE, 'WConstReformPseudo, 'WConstReformQuote);
  752. lisp procedure WConstReformLis U;
  753. for each X in U collect WConstReform X;
  754. lisp procedure WConstReformLoc U; %. To handle &Foo[23]
  755. << U := WConstReform cadr U;
  756. if car U neq 'GETMEM then
  757. ErrorPrintF("*** Illegal constant addressing expression %r",
  758. list('LOC, U))
  759. else cadr U >>;
  760. put('LOC, 'WConstReformPseudo, 'WConstReformLoc);
  761. lisp procedure WConstReformIDLoc U;
  762. FindIDNumber cadr U;
  763. put('IDLoc, 'WConstReformPseudo, 'WConstReformIDLoc);
  764. lisp procedure LookupOrAddASMSymbol U;
  765. begin scalar X;
  766. if not (X := get(U, 'ASMSymbol)) then X := AddASMSymbol U;
  767. return X;
  768. end;
  769. lisp procedure AddASMSymbol U;
  770. begin scalar X;
  771. X := if ASMSymbolP U and not get(U, 'EntryPoint) then U
  772. else StringGensym();
  773. put(U, 'ASMSymbol, X);
  774. return X;
  775. end;
  776. lisp procedure DataPrintVar(Name, Init);
  777. begin scalar OldOut;
  778. DataPrintLabel Name;
  779. OldOut := WRS DataOut!*;
  780. PrintFullWord Init;
  781. WRS OldOut;
  782. end;
  783. lisp procedure DataPrintBlock(Name, Siz, Typ);
  784. << if Typ = 'WSTRING
  785. then Siz := list('quotient, list('plus2, Siz, CharactersPerWord + 1),
  786. CharactersPerWord)
  787. else Siz := list('plus2, Siz, 1);
  788. DataReserveZeroBlock(Name, Siz) >>;
  789. lisp procedure DataPrintList(Nam, Init, Typ);
  790. begin scalar OldOut;
  791. DataPrintLabel Nam;
  792. OldOut := WRS DataOut!*;
  793. if Typ = 'WSTRING then
  794. if StringP Init then
  795. << PrintFullWord Size Init;
  796. PrintString Init >>
  797. else
  798. << PrintFullWord(Length Init - 1);
  799. PrintByteList Append(Init, '(0)) >>
  800. else
  801. if StringP Init then begin scalar S;
  802. S := Size Init;
  803. for I := 0 step 1 until S do
  804. PrintFullWord Indx(Init, I);
  805. end else for each X in Init do
  806. PrintFullWord X;
  807. WRS OldOut;
  808. end;
  809. lisp procedure DataPrintGlobalLabel X;
  810. << if !*DeclareBeforeUse then DataDeclareExported X;
  811. DataPrintLabel X;
  812. if not !*DeclareBeforeUse then DataDeclareExported X;
  813. CodeDeclareExternal X >>;
  814. lisp procedure DataDeclareExternal X;
  815. if not (X member DataExternals!* or X member DataExporteds!*) then
  816. << DataExternals!* := X . DataExternals!*;
  817. DataPrintF(ExternalDeclarationFormat!*, X, X) >>;
  818. lisp procedure CodeDeclareExternal X;
  819. if not (X member CodeExternals!* or X member CodeExporteds!*) then
  820. << CodeExternals!* := X . CodeExternals!*;
  821. CodePrintF(ExternalDeclarationFormat!*, X, X) >>;
  822. lisp procedure DataDeclareExported X;
  823. << if X member DataExternals!* or X member DataExporteds!* then
  824. ErrorPrintF("***** %r multiply defined", X);
  825. DataExporteds!* := X . DataExporteds!*;
  826. DataPrintF(ExportedDeclarationFormat!*, X, X) >>;
  827. lisp procedure CodeDeclareExported X;
  828. << if X member CodeExternals!* or X member CodeExporteds!* then
  829. ErrorPrintF("***** %r multiply defined", X);
  830. CodeExporteds!* := X . CodeExporteds!*;
  831. CodePrintF(ExportedDeclarationFormat!*, X, X) >>;
  832. lisp procedure PrintLabel X;
  833. PrintF(LabelFormat!*, X,X);
  834. lisp procedure DataPrintLabel X;
  835. DataPrintF(LabelFormat!*, X,X);
  836. lisp procedure CodePrintLabel X;
  837. CodePrintF(LabelFormat!*, X,X);
  838. lisp procedure PrintComment X;
  839. PrintF(CommentFormat!*, X);
  840. PrintExpressionForm!* := list('PrintExpression, MkQuote NIL);
  841. PrintExpressionFormPointer!* := cdadr PrintExpressionForm!*;
  842. % Save some consing
  843. % instead of list('PrintExpression, MkQuote X), reuse the same list structure
  844. lisp procedure PrintFullWord X;
  845. << RplacA(PrintExpressionFormPointer!*, X);
  846. PrintF(FullWordFormat!*, PrintExpressionForm!*) >>;
  847. lisp procedure PrintIndWord X;
  848. << RplacA(PrintExpressionFormPointer!*, X);
  849. PrintF(IndWordFormat!*, PrintExpressionForm!*) >>;
  850. lisp procedure DataPrintFullWord X;
  851. << RplacA(PrintExpressionFormPointer!*, X);
  852. DataPrintF(FullWordFormat!*, PrintExpressionForm!*) >>;
  853. lisp procedure CodePrintFullWord X;
  854. << RplacA(PrintExpressionFormPointer!*, X);
  855. CodePrintF(FullWordFormat!*, PrintExpressionForm!*) >>;
  856. lisp procedure DataReserveZeroBlock(Nam, X);
  857. << RplacA(PrintExpressionFormPointer!*,
  858. list('Times2, AddressingUnitsPerItem, X));
  859. DataPrintF(ReserveZeroBlockFormat!*, Nam, PrintExpressionForm!*) >>;
  860. lisp procedure DataReserveBlock X;
  861. << RplacA(PrintExpressionFormPointer!*,
  862. list('Times2, AddressingUnitsPerItem, X));
  863. DataPrintF(ReserveDataBlockFormat!*, PrintExpressionForm!*) >>;
  864. lisp procedure DataReserveFunctionCellBlock X;
  865. << RplacA(PrintExpressionFormPointer!*,
  866. list('Times2, AddressingUnitsPerFunctionCell, X));
  867. DataPrintF(ReserveDataBlockFormat!*, PrintExpressionForm!*) >>;
  868. lisp procedure DataPrintUndefinedFunctionCell();
  869. begin scalar OldOut;
  870. OldOut := WRS DataOut!*;
  871. for each X in UndefinedFunctionCellInstructions!* do
  872. ASMOutLap1 X;
  873. WRS OldOut;
  874. end;
  875. lisp procedure DataPrintDefinedFunctionCell X;
  876. <<DataDeclareExternal X;
  877. DataPrintF(DefinedFunctionCellFormat!*, X, X)>>;
  878. % in case it's needed twice
  879. lisp procedure DataPrintByteList X;
  880. begin scalar OldOut;
  881. OldOut := WRS DataOut!*;
  882. PrintByteList X;
  883. WRS OldOut;
  884. end;
  885. lisp procedure DataPrintExpression X;
  886. begin scalar OldOut;
  887. OldOut := WRS DataOut!*;
  888. PrintExpression X;
  889. WRS OldOut;
  890. end;
  891. lisp procedure CodePrintExpression X;
  892. begin scalar OldOut;
  893. OldOut := WRS CodeOut!*;
  894. PrintExpression X;
  895. WRS OldOut;
  896. end;
  897. ExpressionCount!* := -1;
  898. lisp procedure PrintExpression X;
  899. (lambda(ExpressionCount!*);
  900. begin scalar Hd, Tl, Fn;
  901. X := ResolveWConstExpression X;
  902. if NumberP X or StringP X then Prin2 X
  903. else if IDP X then Prin2 FindLabel X
  904. else if atom X then
  905. << ErrorPrintF("***** Oddity in expression %r", X);
  906. Prin2 X >>
  907. else
  908. << Hd := car X;
  909. Tl := cdr X;
  910. if (Fn := get(Hd, 'BinaryASMOp)) then
  911. << if ExpressionCount!* > 0 then Prin2 ASMOpenParen!*;
  912. PrintExpression car Tl;
  913. Prin2 Fn;
  914. PrintExpression cadr Tl;
  915. if ExpressionCount!* > 0 then Prin2 ASMCloseParen!* >>
  916. else if (Fn := get(Hd, 'UnaryASMOp)) then
  917. << Prin2 Fn;
  918. PrintExpression car Tl >>
  919. else if (Fn := get(Hd, 'ASMExpressionFormat)) then
  920. Apply('PrintF, Fn . for each Y in Tl collect
  921. list('PrintExpression, MkQuote Y))
  922. else if (Fn := GetD Hd) and car Fn = 'MACRO then
  923. PrintExpression Apply(cdr Fn, list X)
  924. else if (Fn := get(Hd, 'ASMExpressionFunction)) then
  925. Apply(Fn, list X)
  926. else
  927. << ErrorPrintF("***** Unknown expression %r", X);
  928. PrintF("*** Expression error %r ***", X) >> >>;
  929. end)(ExpressionCount!* + 1);
  930. lisp procedure ASMPrintWConst U;
  931. PrintExpression cadr U;
  932. put('WConst, 'ASMExpressionFunction, 'ASMPrintWConst);
  933. DefList('((Plus2 !+)
  934. (WPlus2 !+)
  935. (Difference !-)
  936. (WDifference !-)
  937. (Times2 !*)
  938. (WTimes2 !*)
  939. (Quotient !/)
  940. (WQuotient !/)), 'BinaryASMOp);
  941. DefList('((Minus !-)
  942. (WMinus !-)), 'UnaryASMOp);
  943. lisp procedure CompileConstant X;
  944. << X := BuildConstant X;
  945. if null cdr X then car X
  946. else
  947. << If !*DeclareBeforeUse then CodeDeclareExported cadr X;
  948. ASMOutLap cdr X;
  949. DataDeclareExternal cadr X;
  950. If Not !*DeclareBeforeUse then CodeDeclareExported cadr X;
  951. car X >> >>;
  952. CommentOutCode <<
  953. lisp procedure CompileHeapData X;
  954. begin scalar Y;
  955. X := BuildConstant X;
  956. return if null cdr X then car X
  957. else
  958. << Y := WRS DataOut!*;
  959. for each Z in cdr X do ASMOutLap1 Z;
  960. DataDeclareExported cadr X;
  961. WRS Y;
  962. car X >>;
  963. end;
  964. >>;
  965. lisp procedure DataPrintString X;
  966. begin scalar OldOut;
  967. OldOut := WRS DataOut!*;
  968. PrintString X;
  969. WRS OldOut;
  970. end;
  971. lisp procedure FindLabel X;
  972. begin scalar Y;
  973. return if (Y := Atsoc(X, LocalLabels!*)) then cdr Y
  974. else if (Y := get(X, 'ASMSymbol)) then Y
  975. else if (Y := get(X, 'WConst)) then Y
  976. else FindLocalLabel X;
  977. end;
  978. lisp procedure FindLocalLabel X;
  979. begin scalar Y;
  980. return if (Y := Atsoc(X, LocalLabels!*)) then cdr Y
  981. else
  982. << LocalLabels!* := (X . (Y := StringGensym())) . LocalLabels!*;
  983. Y >>;
  984. end;
  985. lisp procedure FindGlobalLabel X;
  986. get(X, 'ASMSymbol) or ErrorPrintF("***** Undefined symbol %r", X);
  987. lisp procedure CodePrintF(Fmt, A1, A2, A3, A4);
  988. begin scalar OldOut;
  989. OldOut := WRS CodeOut!*;
  990. PrintF(Fmt, A1, A2, A3, A4);
  991. WRS OldOut;
  992. end;
  993. lisp procedure DataPrintF(Fmt, A1, A2, A3, A4);
  994. begin scalar OldOut;
  995. OldOut := WRS DataOut!*;
  996. PrintF(Fmt, A1, A2, A3, A4);
  997. WRS OldOut;
  998. end;
  999. % Kludge of the year, just to avoid having IDLOC defined during compilation
  1000. CompileTime fluid '(MACRO);
  1001. MACRO := 'MACRO;
  1002. PutD('IDLoc, MACRO,
  1003. function lambda X;
  1004. FindIDNumber cadr X);
  1005. END;