eval4.c 52 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766
  1. /* eval4.c Copyright (C) 1991-2002, Codemist Ltd */
  2. /*
  3. * Bytecode interpreter/main interpreter interfaces
  4. */
  5. /*
  6. * This code may be used and modified, and redistributed in binary
  7. * or source form, subject to the "CCL Public License", which should
  8. * accompany it. This license is a variant on the BSD license, and thus
  9. * permits use of code derived from this in either open and commercial
  10. * projects: but it does require that updates to this code be made
  11. * available back to the originators of the package.
  12. * Before merging other code in with this or linking this code
  13. * with other packages or libraries please check that the license terms
  14. * of the other material are compatible with those of this.
  15. */
  16. /* Signature: 2ff31eb7 10-Oct-2002 */
  17. #include <stdarg.h>
  18. #include <string.h>
  19. #include <ctype.h>
  20. #include "machine.h"
  21. #include "tags.h"
  22. #include "cslerror.h"
  23. #include "externs.h"
  24. #include "arith.h"
  25. #include "entries.h"
  26. #ifdef TIMEOUT
  27. #include "timeout.h"
  28. #endif
  29. #ifdef DEBUG
  30. int trace_all = 0;
  31. #endif
  32. #define name_from(def) elt(qcdr(def), 0)
  33. Lisp_Object MS_CDECL bytecoded0(Lisp_Object def, int nargs, ...)
  34. {
  35. Lisp_Object nil=C_nil;
  36. if (nargs != 0) return error(2, err_wrong_no_args, name_from(def),
  37. fixnum_of_int((int32)nargs));
  38. push2(litvec, codevec);
  39. stackcheck1(2, def);
  40. /*
  41. * The "-2" a few lines down is discussed in the file bytes1.c. It is
  42. * part of the mechanism for allowing functions to have a few data bytes
  43. * at the start of the code-vector.
  44. */
  45. #ifdef DEBUG
  46. if (trace_all)
  47. { trace_all = 0;
  48. push(def);
  49. freshline_trace();
  50. trace_printf("Entering ");
  51. loop_print_trace(name_from(def));
  52. trace_printf(" (no args)\n");
  53. trace_all = 1;
  54. nil = C_nil;
  55. if (exception_pending()) { popv(3); return nil; }
  56. pop(def);
  57. }
  58. #endif
  59. def = bytestream_interpret(qcar(def)-2, qcdr(def), stack);
  60. nil = C_nil;
  61. if (exception_pending())
  62. { flip_exception();
  63. pop2(codevec, litvec);
  64. flip_exception();
  65. return nil;
  66. }
  67. pop2(codevec, litvec);
  68. return def;
  69. }
  70. Lisp_Object bytecoded1(Lisp_Object def, Lisp_Object a)
  71. {
  72. Lisp_Object r;
  73. Lisp_Object nil = C_nil;
  74. push3(litvec, codevec, a);
  75. stackcheck1(3, def);
  76. #ifdef DEBUG
  77. if (trace_all)
  78. { trace_all = 0;
  79. push(def);
  80. freshline_trace();
  81. trace_printf("Entering ");
  82. loop_print_trace(name_from(def));
  83. trace_printf("\nArg1: ");
  84. loop_print_trace(stack[-1]);
  85. trace_printf("\n");
  86. trace_all = 1;
  87. nil = C_nil;
  88. if (exception_pending()) { popv(4); return nil; }
  89. pop(def);
  90. }
  91. #endif
  92. r = bytestream_interpret(qcar(def)-2, qcdr(def), stack-1);
  93. nil = C_nil;
  94. if (exception_pending())
  95. { flip_exception();
  96. /*
  97. * If bytestream_interpret handed back a failure code then the VERY LAST
  98. * thing that it did was to move stack down, in effect losing the argument
  99. * that had been passed to the bytesteam code. But nothing can touch the
  100. * stack between that action and here, so if I quickly increment the
  101. * stack pointer again I can find the argument again - or at least whetever
  102. * value the failed function left in that variable. Yes this does look
  103. * a little delicate, but I do like seeing argument values in my backtraces,
  104. * and the software stack involved here it totally under my control.
  105. * NOTE however that if the function I am calling here does a tail call
  106. * to something that is not directly bytecoded then the stack can be
  107. * clobbered, and the results will be garbage in the backtrace.
  108. */
  109. stack++;
  110. pop3(a, codevec, litvec);
  111. if ((exit_reason & UNWIND_ERROR) != 0)
  112. { err_printf("Arg1: ");
  113. loop_print_error(a); err_printf("\n");
  114. ignore_exception();
  115. }
  116. flip_exception();
  117. return nil;
  118. }
  119. pop2(codevec, litvec);
  120. return r;
  121. }
  122. Lisp_Object bytecoded2(Lisp_Object def, Lisp_Object a, Lisp_Object b)
  123. {
  124. Lisp_Object r;
  125. Lisp_Object nil = C_nil;
  126. push4(litvec, codevec, a, b);
  127. stackcheck1(4, def);
  128. #ifdef DEBUG
  129. if (trace_all)
  130. { trace_all = 0;
  131. push(def);
  132. freshline_trace();
  133. trace_printf("Entering ");
  134. loop_print_trace(name_from(def));
  135. trace_printf("\nArg1: ");
  136. loop_print_trace(stack[-2]);
  137. trace_printf("\n");
  138. trace_printf("Arg2: ");
  139. loop_print_trace(stack[-1]);
  140. trace_printf("\n");
  141. trace_all = 1;
  142. nil = C_nil;
  143. if (exception_pending()) { popv(5); return nil; }
  144. pop(def);
  145. }
  146. #endif
  147. r = bytestream_interpret(qcar(def)-2, qcdr(def), stack-2);
  148. nil = C_nil;
  149. if (exception_pending())
  150. { flip_exception();
  151. stack += 2;
  152. if ((exit_reason & UNWIND_ERROR) != 0)
  153. { err_printf("Arg 1: ");
  154. loop_print_error(stack[-1]); err_printf("\n");
  155. ignore_exception();
  156. err_printf("Arg 2: ");
  157. loop_print_error(stack[0]); err_printf("\n");
  158. ignore_exception();
  159. }
  160. popv(2); pop2(codevec, litvec);
  161. flip_exception();
  162. return nil;
  163. }
  164. pop2(codevec, litvec);
  165. return r;
  166. }
  167. Lisp_Object MS_CDECL bytecoded3(Lisp_Object def, int nargs, ...)
  168. {
  169. va_list aa;
  170. Lisp_Object r, a, b, c;
  171. Lisp_Object nil = C_nil;
  172. if (nargs != 3) return error(2, err_wrong_no_args, name_from(def),
  173. fixnum_of_int((int32)nargs));
  174. va_start(aa, nargs);
  175. a = va_arg(aa, Lisp_Object);
  176. b = va_arg(aa, Lisp_Object);
  177. c = va_arg(aa, Lisp_Object);
  178. va_end(aa);
  179. push5(litvec, codevec, a, b, c);
  180. stackcheck1(5, def);
  181. #ifdef DEBUG
  182. if (trace_all)
  183. { trace_all = 0;
  184. push(def);
  185. freshline_trace();
  186. trace_printf("Entering ");
  187. loop_print_trace(name_from(def));
  188. trace_printf("\nArg1: ");
  189. loop_print_trace(stack[-3]);
  190. trace_printf("\n");
  191. trace_printf("Arg2: ");
  192. loop_print_trace(stack[-2]);
  193. trace_printf("\n");
  194. trace_printf("Arg3: ");
  195. loop_print_trace(stack[-1]);
  196. trace_printf("\n");
  197. trace_all = 1;
  198. nil = C_nil;
  199. if (exception_pending()) { popv(6); return nil; }
  200. pop(def);
  201. }
  202. #endif
  203. r = bytestream_interpret(qcar(def)-2, qcdr(def), stack-3);
  204. nil = C_nil;
  205. if (exception_pending())
  206. { flip_exception();
  207. stack += 3;
  208. if ((exit_reason & UNWIND_ERROR) != 0)
  209. { err_printf("Arg1: ");
  210. loop_print_error(stack[-2]); err_printf("\n");
  211. ignore_exception();
  212. err_printf("Arg2: ");
  213. loop_print_error(stack[-1]); err_printf("\n");
  214. ignore_exception();
  215. err_printf("Arg3: ");
  216. loop_print_error(stack[0]); err_printf("\n");
  217. ignore_exception();
  218. }
  219. popv(3); pop2(codevec, litvec);
  220. flip_exception();
  221. return nil;
  222. }
  223. pop2(codevec, litvec);
  224. return r;
  225. }
  226. Lisp_Object MS_CDECL bytecodedn(Lisp_Object def, int nargs, ...)
  227. {
  228. /*
  229. * The messing about here is to get the (unknown number of) args
  230. * into a nice neat vector so that they can be indexed into. If I knew
  231. * that the args were in consecutive locations on the stack I could
  232. * probably save a copying operation.
  233. */
  234. Lisp_Object r;
  235. Lisp_Object nil = C_nil;
  236. int i;
  237. Lisp_Object *stack_save = stack;
  238. va_list a;
  239. push2(litvec, codevec);
  240. if (nargs != 0)
  241. { va_start(a, nargs);
  242. push_args(a, nargs);
  243. }
  244. stackcheck1(stack-stack_save, def);
  245. r = qcar(def);
  246. if (nargs != ((unsigned char *)data_of_bps(r))[0])
  247. { popv(nargs+2);
  248. return error(2, err_wrong_no_args, name_from(def),
  249. fixnum_of_int((int32)nargs));
  250. }
  251. r = bytestream_interpret(r-1, qcdr(def), stack-nargs);
  252. nil = C_nil;
  253. if (exception_pending())
  254. { flip_exception();
  255. stack += nargs;
  256. if ((exit_reason & UNWIND_ERROR) != 0)
  257. /*
  258. * Note that in this display if a function had over 50 args then the
  259. * final bunch of them will be bundled up in to a list (as if for &rest).
  260. */
  261. for (i=1; i<=nargs; i++)
  262. { err_printf("Arg%d: ", i);
  263. loop_print_error(stack[i-nargs]); err_printf("\n");
  264. ignore_exception();
  265. }
  266. popv(nargs); pop2(codevec, litvec);
  267. flip_exception();
  268. return nil;
  269. }
  270. pop2(codevec, litvec);
  271. return r;
  272. }
  273. /*
  274. * Now I have carbon copies of the above, but with some print statements
  275. * inserted. These are installed when a function is marked for trace
  276. * output.
  277. */
  278. Lisp_Object unpack_mv(Lisp_Object nil, Lisp_Object r)
  279. {
  280. Lisp_Object *p = &mv_1;
  281. exit_count = 0;
  282. *p = nil;
  283. while (r != nil)
  284. { *p++ = qcar(r);
  285. r = qcdr(r);
  286. exit_count++;
  287. }
  288. return mv_1;
  289. }
  290. Lisp_Object MS_CDECL tracebytecoded0(Lisp_Object def, int nargs, ...)
  291. {
  292. Lisp_Object r, nil=C_nil;
  293. if (nargs != 0) return error(2, err_wrong_no_args, name_from(def),
  294. fixnum_of_int((int32)nargs));
  295. push3(litvec, codevec, def);
  296. freshline_trace();
  297. trace_printf("Entering ");
  298. loop_print_trace(name_from(def));
  299. trace_printf(" (no args)\n");
  300. nil = C_nil;
  301. if (exception_pending()) { popv(3); return nil; }
  302. def = stack[0];
  303. r = bytestream_interpret(qcar(def)-2, qcdr(def), stack);
  304. nil = C_nil;
  305. if (exception_pending())
  306. { flip_exception();
  307. popv(1); pop2(codevec, litvec);
  308. flip_exception();
  309. return nil;
  310. }
  311. #ifdef COMMON
  312. r = Lmv_list(nil, r);
  313. if (exception_pending())
  314. { flip_exception();
  315. popv(1); pop2(codevec, litvec);
  316. flip_exception();
  317. return nil;
  318. }
  319. #endif
  320. pop(def);
  321. push(r);
  322. freshline_trace();
  323. loop_print_trace(name_from(def));
  324. nil = C_nil;
  325. if (!exception_pending())
  326. { trace_printf(" = ");
  327. loop_print_trace(r);
  328. trace_printf("\n");
  329. }
  330. if (exception_pending())
  331. { flip_exception();
  332. popv(1); pop2(codevec, litvec);
  333. flip_exception();
  334. return nil;
  335. }
  336. pop3(r, codevec, litvec);
  337. #ifdef COMMON
  338. r = unpack_mv(nil, r);
  339. #endif
  340. return r;
  341. }
  342. Lisp_Object tracebytecoded1(Lisp_Object def, Lisp_Object a)
  343. {
  344. Lisp_Object r;
  345. Lisp_Object nil = C_nil;
  346. push4(litvec, codevec, def, a);
  347. freshline_trace();
  348. trace_printf("Entering ");
  349. loop_print_trace(name_from(def));
  350. nil = C_nil;
  351. if (exception_pending())
  352. { flip_exception();
  353. popv(2); pop2(codevec, litvec);
  354. flip_exception();
  355. return nil;
  356. }
  357. trace_printf(" (1 arg)\nArg1: ");
  358. loop_print_trace(stack[0]);
  359. trace_printf("\n");
  360. nil = C_nil;
  361. if (exception_pending())
  362. { flip_exception();
  363. popv(2); pop2(codevec, litvec);
  364. flip_exception();
  365. return nil;
  366. }
  367. stackcheck0(4);
  368. def = stack[-1];
  369. r = bytestream_interpret(qcar(def)-2, qcdr(def), stack-1);
  370. nil = C_nil;
  371. if (exception_pending())
  372. { flip_exception();
  373. stack++;
  374. pop(a); popv(1); pop2(codevec, litvec);
  375. if ((exit_reason & UNWIND_ERROR) != 0)
  376. { err_printf("Arg1: ");
  377. loop_print_error(a); err_printf("\n");
  378. ignore_exception();
  379. }
  380. flip_exception();
  381. return nil;
  382. }
  383. #ifdef COMMON
  384. r = Lmv_list(nil, r);
  385. if (exception_pending())
  386. { flip_exception();
  387. popv(1); pop2(codevec, litvec);
  388. flip_exception();
  389. return nil;
  390. }
  391. #endif
  392. pop(def);
  393. push(r);
  394. freshline_trace();
  395. loop_print_trace(name_from(def));
  396. trace_printf(" = ");
  397. loop_print_trace(r);
  398. trace_printf("\n");
  399. pop3(r, codevec, litvec);
  400. #ifdef COMMON
  401. r = unpack_mv(nil, r);
  402. #endif
  403. return r;
  404. }
  405. Lisp_Object tracebytecoded2(Lisp_Object def,
  406. Lisp_Object a, Lisp_Object b)
  407. {
  408. Lisp_Object r;
  409. Lisp_Object nil = C_nil;
  410. push5(litvec, codevec, def, a, b);
  411. freshline_trace();
  412. trace_printf("Entering ");
  413. loop_print_trace(name_from(def));
  414. nil = C_nil;
  415. if (exception_pending())
  416. { flip_exception();
  417. popv(3); pop2(codevec, litvec);
  418. flip_exception();
  419. return nil;
  420. }
  421. trace_printf(" (2 args)\nArg1: ");
  422. loop_print_trace(stack[-1]);
  423. nil = C_nil;
  424. if (exception_pending())
  425. { flip_exception();
  426. popv(3); pop2(codevec, litvec);
  427. flip_exception();
  428. return nil;
  429. }
  430. trace_printf("\nArg2: ");
  431. loop_print_trace(stack[0]);
  432. trace_printf("\n");
  433. nil = C_nil;
  434. if (exception_pending())
  435. { flip_exception();
  436. popv(3); pop2(codevec, litvec);
  437. flip_exception();
  438. return nil;
  439. }
  440. stackcheck0(5);
  441. def = stack[-2];
  442. r = bytestream_interpret(qcar(def)-2, qcdr(def), stack-2);
  443. nil = C_nil;
  444. if (exception_pending())
  445. { flip_exception();
  446. stack += 2;
  447. if ((exit_reason & UNWIND_ERROR) != 0)
  448. { err_printf("Arg1: ");
  449. loop_print_error(stack[-1]); err_printf("\n");
  450. ignore_exception();
  451. err_printf("Arg2: ");
  452. loop_print_error(stack[0]); err_printf("\n");
  453. ignore_exception();
  454. }
  455. popv(3); pop2(codevec, litvec);
  456. flip_exception();
  457. return nil;
  458. }
  459. #ifdef COMMON
  460. r = Lmv_list(nil, r);
  461. if (exception_pending())
  462. { flip_exception();
  463. popv(1); pop2(codevec, litvec);
  464. flip_exception();
  465. return nil;
  466. }
  467. #endif
  468. pop(def);
  469. push(r);
  470. freshline_trace();
  471. loop_print_trace(name_from(def));
  472. trace_printf(" = ");
  473. loop_print_trace(r);
  474. trace_printf("\n");
  475. pop3(r, codevec, litvec);
  476. #ifdef COMMON
  477. r = unpack_mv(nil, r);
  478. #endif
  479. return r;
  480. }
  481. Lisp_Object MS_CDECL tracebytecoded3(Lisp_Object def, int nargs, ...)
  482. {
  483. va_list aa;
  484. Lisp_Object r, a, b, c;
  485. Lisp_Object nil = C_nil;
  486. if (nargs != 3) return error(2, err_wrong_no_args, name_from(def),
  487. fixnum_of_int((int32)nargs));
  488. va_start(aa, nargs);
  489. a = va_arg(aa, Lisp_Object);
  490. b = va_arg(aa, Lisp_Object);
  491. c = va_arg(aa, Lisp_Object);
  492. va_end(aa);
  493. push2(litvec, codevec);
  494. push4(def, a, b, c);
  495. freshline_trace();
  496. trace_printf("Entering ");
  497. loop_print_trace(name_from(def));
  498. nil = C_nil;
  499. if (exception_pending())
  500. { flip_exception();
  501. popv(4); pop2(codevec, litvec);
  502. flip_exception();
  503. return nil;
  504. }
  505. trace_printf(" (3 args)\nArg1: ");
  506. loop_print_trace(stack[-2]);
  507. nil = C_nil;
  508. if (exception_pending())
  509. { flip_exception();
  510. popv(4); pop2(codevec, litvec);
  511. flip_exception();
  512. return nil;
  513. }
  514. trace_printf("\nArg2: ");
  515. loop_print_trace(stack[-1]);
  516. nil = C_nil;
  517. if (exception_pending())
  518. { flip_exception();
  519. popv(4); pop2(codevec, litvec);
  520. flip_exception();
  521. return nil;
  522. }
  523. trace_printf("\nArg3: ");
  524. loop_print_trace(stack[0]);
  525. trace_printf("\n");
  526. nil = C_nil;
  527. if (exception_pending())
  528. { flip_exception();
  529. popv(4); pop2(codevec, litvec);
  530. flip_exception();
  531. return nil;
  532. }
  533. stackcheck0(6);
  534. def = stack[-3];
  535. r = bytestream_interpret(qcar(def)-2, qcdr(def), stack-3);
  536. nil = C_nil;
  537. if (exception_pending())
  538. { flip_exception();
  539. stack += 3;
  540. if ((exit_reason & UNWIND_ERROR) != 0)
  541. { err_printf("Arg1: ");
  542. loop_print_error(stack[-2]); err_printf("\n");
  543. ignore_exception();
  544. err_printf("Arg2: ");
  545. loop_print_error(stack[-1]); err_printf("\n");
  546. ignore_exception();
  547. err_printf("Arg3: ");
  548. loop_print_error(stack[0]); err_printf("\n");
  549. ignore_exception();
  550. }
  551. popv(4); pop2(codevec, litvec);
  552. flip_exception();
  553. return nil;
  554. }
  555. #ifdef COMMON
  556. r = Lmv_list(nil, r);
  557. if (exception_pending())
  558. { flip_exception();
  559. popv(1); pop2(codevec, litvec);
  560. flip_exception();
  561. return nil;
  562. }
  563. #endif
  564. pop(def);
  565. push(r);
  566. freshline_trace();
  567. loop_print_trace(name_from(def));
  568. trace_printf(" = ");
  569. loop_print_trace(r);
  570. trace_printf("\n");
  571. pop3(r, codevec, litvec);
  572. #ifdef COMMON
  573. r = unpack_mv(nil, r);
  574. #endif
  575. return r;
  576. }
  577. Lisp_Object MS_CDECL tracebytecodedn(Lisp_Object def, int nargs, ...)
  578. {
  579. /*
  580. * The messing about here is to get the (unknown number of) args
  581. * into a nice neat vector so that they can be indexed into. If I knew
  582. * that the args were in consecutive locations on the stack I could
  583. * probably save a copying operation.
  584. */
  585. Lisp_Object r;
  586. Lisp_Object nil = C_nil;
  587. int i;
  588. Lisp_Object *stack_save = stack;
  589. va_list a;
  590. push3(litvec, codevec, def);
  591. if (nargs != 0)
  592. { va_start(a, nargs);
  593. push_args(a, nargs);
  594. }
  595. stackcheck1(stack-stack_save, def);
  596. freshline_trace();
  597. loop_print_trace(name_from(def));
  598. trace_printf(" (%d args)\n", nargs);
  599. for (i=1; i<=nargs; i++)
  600. { trace_printf("Arg%d: ", i);
  601. loop_print_trace(stack[i-nargs]);
  602. trace_printf("\n");
  603. }
  604. def = stack[-nargs];
  605. r = qcar(def);
  606. if (nargs != ((unsigned char *)data_of_bps(r))[0])
  607. { popv(nargs+3);
  608. return error(2, err_wrong_no_args, name_from(def),
  609. fixnum_of_int((int32)nargs));
  610. }
  611. r = bytestream_interpret(r-1, qcdr(def), stack-nargs);
  612. nil = C_nil;
  613. if (exception_pending())
  614. { flip_exception();
  615. stack += nargs;
  616. if ((exit_reason & UNWIND_ERROR) != 0)
  617. for (i=1; i<=nargs; i++)
  618. { err_printf("Arg%d: ", i);
  619. loop_print_error(stack[i-nargs]); err_printf("\n");
  620. ignore_exception();
  621. }
  622. popv(nargs+1); pop2(codevec, litvec);
  623. flip_exception();
  624. return nil;
  625. }
  626. #ifdef COMMON
  627. r = Lmv_list(nil, r);
  628. if (exception_pending())
  629. { flip_exception();
  630. popv(1); pop2(codevec, litvec);
  631. flip_exception();
  632. return nil;
  633. }
  634. #endif
  635. pop(def);
  636. push(r);
  637. freshline_trace();
  638. loop_print_trace(name_from(def));
  639. trace_printf(" = ");
  640. loop_print_trace(r);
  641. trace_printf("\n");
  642. pop3(r, codevec, litvec);
  643. #ifdef COMMON
  644. r = unpack_mv(nil, r);
  645. #endif
  646. return r;
  647. }
  648. int doubled_execution = 0;
  649. Lisp_Object MS_CDECL double_bytecoded0(Lisp_Object def, int nargs, ...)
  650. {
  651. Lisp_Object nil=C_nil;
  652. if (nargs != 0) return error(2, err_wrong_no_args, name_from(def),
  653. fixnum_of_int((int32)nargs));
  654. push2(litvec, codevec);
  655. stackcheck1(2, def);
  656. if (!doubled_execution)
  657. { push3(def, litvec, codevec);
  658. doubled_execution = 1;
  659. bytestream_interpret(qcar(def)-2, qcdr(def), stack);
  660. nil = C_nil;
  661. pop3(codevec, litvec, def);
  662. if (!exception_pending())
  663. def = bytestream_interpret(qcar(def)-2, qcdr(def), stack);
  664. doubled_execution = 0;
  665. }
  666. else def = bytestream_interpret(qcar(def)-2, qcdr(def), stack);
  667. nil = C_nil;
  668. if (exception_pending())
  669. { flip_exception();
  670. pop2(codevec, litvec);
  671. flip_exception();
  672. return nil;
  673. }
  674. pop2(codevec, litvec);
  675. return def;
  676. }
  677. Lisp_Object double_bytecoded1(Lisp_Object def, Lisp_Object a)
  678. {
  679. Lisp_Object r;
  680. Lisp_Object nil = C_nil;
  681. push3(litvec, codevec, a);
  682. stackcheck1(3, def);
  683. if (!doubled_execution)
  684. { push4(def, litvec, codevec, a);
  685. doubled_execution = 1;
  686. r = bytestream_interpret(qcar(def)-2, qcdr(def), stack-1);
  687. nil = C_nil;
  688. pop3(codevec, litvec, def);
  689. if (!exception_pending())
  690. r = bytestream_interpret(qcar(def)-2, qcdr(def), stack-1);
  691. doubled_execution = 0;
  692. }
  693. else r = bytestream_interpret(qcar(def)-2, qcdr(def), stack-1);
  694. nil = C_nil;
  695. if (exception_pending())
  696. { flip_exception();
  697. stack++;
  698. pop3(a, codevec, litvec);
  699. if ((exit_reason & UNWIND_ERROR) != 0)
  700. { err_printf("Arg1: ");
  701. loop_print_error(a); err_printf("\n");
  702. ignore_exception();
  703. }
  704. flip_exception();
  705. return nil;
  706. }
  707. pop2(codevec, litvec);
  708. return r;
  709. }
  710. Lisp_Object double_bytecoded2(Lisp_Object def, Lisp_Object a, Lisp_Object b)
  711. {
  712. Lisp_Object r;
  713. Lisp_Object nil = C_nil;
  714. push4(litvec, codevec, a, b);
  715. stackcheck1(4, def);
  716. if (!doubled_execution)
  717. { push5(def, litvec, codevec, a, b);
  718. doubled_execution = 1;
  719. r = bytestream_interpret(qcar(def)-2, qcdr(def), stack-2);
  720. nil = C_nil;
  721. pop3(codevec, litvec, def);
  722. if (!exception_pending())
  723. r = bytestream_interpret(qcar(def)-2, qcdr(def), stack-2);
  724. doubled_execution = 0;
  725. }
  726. else r = bytestream_interpret(qcar(def)-2, qcdr(def), stack-2);
  727. nil = C_nil;
  728. if (exception_pending())
  729. { flip_exception();
  730. stack += 2;
  731. if ((exit_reason & UNWIND_ERROR) != 0)
  732. { err_printf("Arg 1: ");
  733. loop_print_error(stack[-1]); err_printf("\n");
  734. ignore_exception();
  735. err_printf("Arg 2: ");
  736. loop_print_error(stack[0]); err_printf("\n");
  737. ignore_exception();
  738. }
  739. popv(2); pop2(codevec, litvec);
  740. flip_exception();
  741. return nil;
  742. }
  743. pop2(codevec, litvec);
  744. return r;
  745. }
  746. Lisp_Object MS_CDECL double_bytecoded3(Lisp_Object def, int nargs, ...)
  747. {
  748. va_list aa;
  749. Lisp_Object r, a, b, c;
  750. Lisp_Object nil = C_nil;
  751. if (nargs != 3) return error(2, err_wrong_no_args, name_from(def),
  752. fixnum_of_int((int32)nargs));
  753. va_start(aa, nargs);
  754. a = va_arg(aa, Lisp_Object);
  755. b = va_arg(aa, Lisp_Object);
  756. c = va_arg(aa, Lisp_Object);
  757. va_end(aa);
  758. push5(litvec, codevec, a, b, c);
  759. stackcheck1(5, def);
  760. if (!doubled_execution)
  761. { push6(def, litvec, codevec, a, b, c);
  762. doubled_execution = 1;
  763. r = bytestream_interpret(qcar(def)-2, qcdr(def), stack-3);
  764. nil = C_nil;
  765. pop3(codevec, litvec, def);
  766. if (!exception_pending())
  767. r = bytestream_interpret(qcar(def)-2, qcdr(def), stack-3);
  768. doubled_execution = 0;
  769. }
  770. else r = bytestream_interpret(qcar(def)-2, qcdr(def), stack-3);
  771. nil = C_nil;
  772. if (exception_pending())
  773. { flip_exception();
  774. stack += 3;
  775. if ((exit_reason & UNWIND_ERROR) != 0)
  776. { err_printf("Arg1: ");
  777. loop_print_error(stack[-2]); err_printf("\n");
  778. ignore_exception();
  779. err_printf("Arg2: ");
  780. loop_print_error(stack[-1]); err_printf("\n");
  781. ignore_exception();
  782. err_printf("Arg3: ");
  783. loop_print_error(stack[0]); err_printf("\n");
  784. ignore_exception();
  785. }
  786. popv(3); pop2(codevec, litvec);
  787. flip_exception();
  788. return nil;
  789. }
  790. pop2(codevec, litvec);
  791. return r;
  792. }
  793. Lisp_Object MS_CDECL double_bytecodedn(Lisp_Object def, int nargs, ...)
  794. {
  795. Lisp_Object r;
  796. Lisp_Object nil = C_nil;
  797. int i;
  798. Lisp_Object *stack_save = stack;
  799. va_list a;
  800. push2(litvec, codevec);
  801. if (nargs != 0)
  802. { va_start(a, nargs);
  803. push_args(a, nargs);
  804. }
  805. stackcheck1(stack-stack_save, def);
  806. r = qcar(def);
  807. if (nargs != ((unsigned char *)data_of_bps(r))[0])
  808. { popv(nargs+2);
  809. return error(2, err_wrong_no_args, name_from(def),
  810. fixnum_of_int((int32)nargs));
  811. }
  812. trace_printf("Function with > 3 args not doubled\n");
  813. r = bytestream_interpret(r-1, qcdr(def), stack-nargs);
  814. nil = C_nil;
  815. if (exception_pending())
  816. { flip_exception();
  817. stack += nargs;
  818. if ((exit_reason & UNWIND_ERROR) != 0)
  819. for (i=1; i<=nargs; i++)
  820. { err_printf("Arg%d: ", i);
  821. loop_print_error(stack[i-nargs]); err_printf("\n");
  822. ignore_exception();
  823. }
  824. popv(nargs); pop2(codevec, litvec);
  825. flip_exception();
  826. return nil;
  827. }
  828. pop2(codevec, litvec);
  829. return r;
  830. }
  831. /*
  832. * The code that follows is just used to support compiled code that
  833. * has &optional or &rest arguments.
  834. */
  835. Lisp_Object byteopt1(Lisp_Object def, Lisp_Object a)
  836. {
  837. return byteoptn(def, 1, a);
  838. }
  839. Lisp_Object byteopt2(Lisp_Object def, Lisp_Object a, Lisp_Object b)
  840. {
  841. return byteoptn(def, 2, a, b);
  842. }
  843. static Lisp_Object vbyteoptn(Lisp_Object def, int nargs,
  844. va_list a, Lisp_Object dflt)
  845. {
  846. Lisp_Object r;
  847. Lisp_Object nil = C_nil;
  848. int i, wantargs, wantopts;
  849. Lisp_Object *stack_save = stack;
  850. push2(litvec, codevec);
  851. /*
  852. * Maybe I should raise an exception (continuable error) if too many args
  853. * are provided - for now I just silently ignore the excess.
  854. */
  855. if (nargs != 0) push_args(a, nargs);
  856. else va_end(a);
  857. stackcheck1(stack-stack_save, def);
  858. r = qcar(def);
  859. wantargs = ((unsigned char *)data_of_bps(r))[0];
  860. wantopts = ((unsigned char *)data_of_bps(r))[1];
  861. if (nargs < wantargs || nargs > wantargs+wantopts)
  862. { popv(nargs); pop2(codevec, litvec)
  863. return error(2, err_wrong_no_args, name_from(def),
  864. fixnum_of_int((int32)nargs));
  865. }
  866. while (nargs < wantargs+wantopts)
  867. { push(dflt); /* Provide value for all optional args */
  868. nargs++;
  869. }
  870. stackcheck1(stack-stack_save, def);
  871. r = qcar(def);
  872. r = bytestream_interpret(r, qcdr(def), stack-nargs);
  873. nil = C_nil;
  874. if (exception_pending())
  875. { flip_exception();
  876. stack += nargs;
  877. if ((exit_reason & UNWIND_ERROR) != 0)
  878. for (i=1; i<=nargs; i++)
  879. { err_printf("Arg%d: ", i);
  880. loop_print_error(stack[i-nargs]); err_printf("\n");
  881. ignore_exception();
  882. }
  883. popv(nargs); pop2(codevec, litvec);
  884. flip_exception();
  885. return nil;
  886. }
  887. pop2(codevec, litvec);
  888. return r;
  889. }
  890. Lisp_Object MS_CDECL byteoptn(Lisp_Object def, int nargs, ...)
  891. {
  892. va_list a;
  893. va_start(a, nargs);
  894. return vbyteoptn(def, nargs, a, C_nil);
  895. }
  896. Lisp_Object hardopt1(Lisp_Object def, Lisp_Object a)
  897. {
  898. return hardoptn(def, 1, a);
  899. }
  900. Lisp_Object hardopt2(Lisp_Object def, Lisp_Object a, Lisp_Object b)
  901. {
  902. return hardoptn(def, 2, a, b);
  903. }
  904. Lisp_Object MS_CDECL hardoptn(Lisp_Object def, int nargs, ...)
  905. {
  906. va_list a;
  907. va_start(a, nargs);
  908. return vbyteoptn(def, nargs, a, SPID_NOARG);
  909. }
  910. Lisp_Object byteoptrest1(Lisp_Object def, Lisp_Object a)
  911. {
  912. return byteoptrestn(def, 1, a);
  913. }
  914. Lisp_Object byteoptrest2(Lisp_Object def, Lisp_Object a, Lisp_Object b)
  915. {
  916. return byteoptrestn(def, 2, a, b);
  917. }
  918. static Lisp_Object vbyterestn(Lisp_Object def, int nargs,
  919. va_list a, Lisp_Object dflt)
  920. {
  921. Lisp_Object r;
  922. Lisp_Object nil = C_nil;
  923. int i, wantargs, wantopts;
  924. Lisp_Object *stack_save = stack;
  925. push2(litvec, codevec);
  926. if (nargs != 0) push_args(a, nargs);
  927. else va_end(a);
  928. stackcheck1(stack-stack_save, def);
  929. r = qcar(def);
  930. wantargs = ((unsigned char *)data_of_bps(r))[0];
  931. wantopts = ((unsigned char *)data_of_bps(r))[1];
  932. if (nargs < wantargs)
  933. { popv(nargs+2);
  934. return error(2, err_wrong_no_args, name_from(def),
  935. fixnum_of_int((int32)nargs));
  936. }
  937. while (nargs < wantargs+wantopts)
  938. { push(dflt); /* Provide value for all optional args */
  939. nargs++;
  940. }
  941. { Lisp_Object rest = nil;
  942. while (nargs > wantargs+wantopts)
  943. { Lisp_Object w = stack[0];
  944. stack[0] = def;
  945. rest = cons(w, rest);
  946. errexitn(nargs+2);
  947. pop(def);
  948. nargs--;
  949. }
  950. push(rest);
  951. nargs++;
  952. }
  953. stackcheck1(stack-stack_save, def);
  954. r = qcar(def);
  955. r = bytestream_interpret(r, qcdr(def), stack-nargs);
  956. nil = C_nil;
  957. if (exception_pending())
  958. { flip_exception();
  959. stack += nargs;
  960. if ((exit_reason & UNWIND_ERROR) != 0)
  961. for (i=1; i<=nargs; i++)
  962. { err_printf("Arg%d: ", i);
  963. loop_print_error(stack[i-nargs]); err_printf("\n");
  964. ignore_exception();
  965. }
  966. popv(nargs); pop2(codevec, litvec);
  967. flip_exception();
  968. return nil;
  969. }
  970. pop2(codevec, litvec);
  971. return r;
  972. }
  973. Lisp_Object MS_CDECL byteoptrestn(Lisp_Object def, int nargs, ...)
  974. {
  975. va_list a;
  976. va_start(a, nargs);
  977. return vbyterestn(def, nargs, a, C_nil);
  978. }
  979. Lisp_Object hardoptrest1(Lisp_Object def, Lisp_Object a)
  980. {
  981. return hardoptrestn(def, 1, a);
  982. }
  983. Lisp_Object hardoptrest2(Lisp_Object def, Lisp_Object a, Lisp_Object b)
  984. {
  985. return hardoptrestn(def, 2, a, b);
  986. }
  987. Lisp_Object MS_CDECL hardoptrestn(Lisp_Object def, int nargs, ...)
  988. {
  989. va_list a;
  990. va_start(a, nargs);
  991. return vbyterestn(def, nargs, a, SPID_NOARG);
  992. }
  993. /*
  994. * Next the execution-doubling versions of the &opt/&rest interfaces
  995. */
  996. Lisp_Object double_byteopt1(Lisp_Object def, Lisp_Object a)
  997. {
  998. return double_byteoptn(def, 1, a);
  999. }
  1000. Lisp_Object double_byteopt2(Lisp_Object def, Lisp_Object a, Lisp_Object b)
  1001. {
  1002. return double_byteoptn(def, 2, a, b);
  1003. }
  1004. static Lisp_Object double_vbyteoptn(Lisp_Object def, int nargs,
  1005. va_list a, Lisp_Object dflt)
  1006. {
  1007. Lisp_Object r;
  1008. Lisp_Object nil = C_nil;
  1009. int i, wantargs, wantopts;
  1010. Lisp_Object *stack_save = stack;
  1011. push2(litvec, codevec);
  1012. /*
  1013. * Maybe I should raise an exception (continuable error) if too many args
  1014. * are provided - for now I just silently ignore th excess.
  1015. */
  1016. if (nargs != 0) push_args(a, nargs);
  1017. else va_end(a);
  1018. stackcheck1(stack-stack_save, def);
  1019. r = qcar(def);
  1020. wantargs = ((unsigned char *)data_of_bps(r))[0];
  1021. wantopts = ((unsigned char *)data_of_bps(r))[1];
  1022. if (nargs < wantargs || nargs > wantargs+wantopts)
  1023. { popv(nargs); pop2(codevec, litvec)
  1024. return error(2, err_wrong_no_args, name_from(def),
  1025. fixnum_of_int((int32)nargs));
  1026. }
  1027. while (nargs < wantargs+wantopts)
  1028. { push(dflt); /* Provide value for all optional args */
  1029. nargs++;
  1030. }
  1031. stackcheck1(stack-stack_save, def);
  1032. trace_printf("Function with simple &opt arg not doubled\n");
  1033. r = qcar(def);
  1034. r = bytestream_interpret(r, qcdr(def), stack-nargs);
  1035. nil = C_nil;
  1036. if (exception_pending())
  1037. { flip_exception();
  1038. stack += nargs;
  1039. if ((exit_reason & UNWIND_ERROR) != 0)
  1040. for (i=1; i<=nargs; i++)
  1041. { err_printf("Arg%d: ", i);
  1042. loop_print_error(stack[i-nargs]); err_printf("\n");
  1043. ignore_exception();
  1044. }
  1045. popv(nargs); pop2(codevec, litvec);
  1046. flip_exception();
  1047. return nil;
  1048. }
  1049. pop2(codevec, litvec);
  1050. return r;
  1051. }
  1052. Lisp_Object MS_CDECL double_byteoptn(Lisp_Object def, int nargs, ...)
  1053. {
  1054. va_list a;
  1055. va_start(a, nargs);
  1056. return double_vbyteoptn(def, nargs, a, C_nil);
  1057. }
  1058. Lisp_Object double_hardopt1(Lisp_Object def, Lisp_Object a)
  1059. {
  1060. return double_hardoptn(def, 1, a);
  1061. }
  1062. Lisp_Object double_hardopt2(Lisp_Object def, Lisp_Object a, Lisp_Object b)
  1063. {
  1064. return double_hardoptn(def, 2, a, b);
  1065. }
  1066. Lisp_Object MS_CDECL double_hardoptn(Lisp_Object def, int nargs, ...)
  1067. {
  1068. va_list a;
  1069. va_start(a, nargs);
  1070. return double_vbyteoptn(def, nargs, a, SPID_NOARG);
  1071. }
  1072. Lisp_Object double_byteoptrest1(Lisp_Object def, Lisp_Object a)
  1073. {
  1074. return double_byteoptrestn(def, 1, a);
  1075. }
  1076. Lisp_Object double_byteoptrest2(Lisp_Object def, Lisp_Object a, Lisp_Object b)
  1077. {
  1078. return double_byteoptrestn(def, 2, a, b);
  1079. }
  1080. static Lisp_Object double_vbyterestn(Lisp_Object def, int nargs,
  1081. va_list a, Lisp_Object dflt)
  1082. {
  1083. Lisp_Object r;
  1084. Lisp_Object nil = C_nil;
  1085. int i, wantargs, wantopts;
  1086. Lisp_Object *stack_save = stack;
  1087. push2(litvec, codevec);
  1088. if (nargs != 0) push_args(a, nargs);
  1089. else va_end(a);
  1090. stackcheck1(stack-stack_save, def);
  1091. r = qcar(def);
  1092. wantargs = ((unsigned char *)data_of_bps(r))[0];
  1093. wantopts = ((unsigned char *)data_of_bps(r))[1];
  1094. if (nargs < wantargs)
  1095. { popv(nargs+2);
  1096. return error(2, err_wrong_no_args, name_from(def),
  1097. fixnum_of_int((int32)nargs));
  1098. }
  1099. while (nargs < wantargs+wantopts)
  1100. { push(dflt); /* Provide value for all optional args */
  1101. nargs++;
  1102. }
  1103. { Lisp_Object rest = nil;
  1104. while (nargs > wantargs+wantopts)
  1105. { Lisp_Object w = stack[0];
  1106. stack[0] = def;
  1107. rest = cons(w, rest);
  1108. errexitn(nargs+2);
  1109. pop(def);
  1110. nargs--;
  1111. }
  1112. push(rest);
  1113. nargs++;
  1114. }
  1115. stackcheck1(stack-stack_save, def);
  1116. trace_printf("Function with simple &rest arg not doubled\n");
  1117. r = qcar(def);
  1118. r = bytestream_interpret(r, qcdr(def), stack-nargs);
  1119. nil = C_nil;
  1120. if (exception_pending())
  1121. { flip_exception();
  1122. stack += nargs;
  1123. if ((exit_reason & UNWIND_ERROR) != 0)
  1124. for (i=1; i<=nargs; i++)
  1125. { err_printf("Arg%d: ", i);
  1126. loop_print_error(stack[i-nargs]); err_printf("\n");
  1127. ignore_exception();
  1128. }
  1129. popv(nargs); pop2(codevec, litvec);
  1130. flip_exception();
  1131. return nil;
  1132. }
  1133. pop2(codevec, litvec);
  1134. return r;
  1135. }
  1136. Lisp_Object MS_CDECL double_byteoptrestn(Lisp_Object def, int nargs, ...)
  1137. {
  1138. va_list a;
  1139. va_start(a, nargs);
  1140. return double_vbyterestn(def, nargs, a, C_nil);
  1141. }
  1142. Lisp_Object double_hardoptrest1(Lisp_Object def, Lisp_Object a)
  1143. {
  1144. return double_hardoptrestn(def, 1, a);
  1145. }
  1146. Lisp_Object double_hardoptrest2(Lisp_Object def, Lisp_Object a, Lisp_Object b)
  1147. {
  1148. return double_hardoptrestn(def, 2, a, b);
  1149. }
  1150. Lisp_Object MS_CDECL double_hardoptrestn(Lisp_Object def, int nargs, ...)
  1151. {
  1152. va_list a;
  1153. va_start(a, nargs);
  1154. return double_vbyterestn(def, nargs, a, SPID_NOARG);
  1155. }
  1156. Lisp_Object tracebyteopt1(Lisp_Object def, Lisp_Object a)
  1157. {
  1158. return tracebyteoptn(def, 1, a);
  1159. }
  1160. Lisp_Object tracebyteopt2(Lisp_Object def, Lisp_Object a, Lisp_Object b)
  1161. {
  1162. return tracebyteoptn(def, 2, a, b);
  1163. }
  1164. static Lisp_Object vtracebyteoptn(Lisp_Object def, int nargs,
  1165. va_list a, Lisp_Object dflt)
  1166. {
  1167. Lisp_Object r;
  1168. Lisp_Object nil = C_nil;
  1169. int i, wantargs, wantopts;
  1170. Lisp_Object *stack_save = stack;
  1171. push3(litvec, codevec, def);
  1172. /*
  1173. * Maybe I should raise an exception (continuable error) if too many args
  1174. * are provided - for now I just silently ignore th excess.
  1175. */
  1176. if (nargs != 0) push_args(a, nargs);
  1177. else va_end(a);
  1178. stackcheck1(stack-stack_save, def);
  1179. r = qcar(def);
  1180. wantargs = ((unsigned char *)data_of_bps(r))[0];
  1181. wantopts = ((unsigned char *)data_of_bps(r))[1];
  1182. if (nargs < wantargs || nargs > wantargs+wantopts)
  1183. { popv(nargs+1); pop2(codevec, litvec)
  1184. return error(2, err_wrong_no_args, name_from(def),
  1185. fixnum_of_int((int32)nargs));
  1186. }
  1187. while (nargs < wantargs+wantopts)
  1188. { push(dflt); /* Provide value for all optional args */
  1189. nargs++;
  1190. }
  1191. stackcheck1(stack-stack_save, def);
  1192. freshline_trace();
  1193. loop_print_trace(name_from(def));
  1194. trace_printf(" (%d args)\n", nargs);
  1195. for (i=1; i<=nargs; i++)
  1196. { trace_printf("Arg%d: ", i);
  1197. loop_print_trace(stack[i-nargs]);
  1198. trace_printf("\n");
  1199. }
  1200. def = stack[-nargs];
  1201. r = qcar(def);
  1202. r = bytestream_interpret(r, qcdr(def), stack-nargs);
  1203. nil = C_nil;
  1204. if (exception_pending())
  1205. { flip_exception();
  1206. stack += nargs;
  1207. if ((exit_reason & UNWIND_ERROR) != 0)
  1208. for (i=1; i<=nargs; i++)
  1209. { err_printf("Arg%d: ", i);
  1210. loop_print_error(stack[i-nargs]); err_printf("\n");
  1211. ignore_exception();
  1212. }
  1213. popv(nargs+1); pop2(codevec, litvec);
  1214. flip_exception();
  1215. return nil;
  1216. }
  1217. #ifdef COMMON
  1218. r = Lmv_list(nil, r);
  1219. if (exception_pending())
  1220. { flip_exception();
  1221. popv(1); pop2(codevec, litvec);
  1222. flip_exception();
  1223. return nil;
  1224. }
  1225. #endif
  1226. pop(def);
  1227. push(r);
  1228. freshline_trace();
  1229. loop_print_trace(name_from(def));
  1230. nil = C_nil;
  1231. if (!exception_pending())
  1232. { trace_printf(" = ");
  1233. loop_print_trace(r);
  1234. trace_printf("\n");
  1235. }
  1236. if (exception_pending())
  1237. { flip_exception();
  1238. popv(1); pop2(codevec, litvec);
  1239. flip_exception();
  1240. return nil;
  1241. }
  1242. pop3(r, codevec, litvec);
  1243. #ifdef COMMON
  1244. r = unpack_mv(nil, r);
  1245. #endif
  1246. return r;
  1247. }
  1248. Lisp_Object MS_CDECL tracebyteoptn(Lisp_Object def, int nargs, ...)
  1249. {
  1250. va_list a;
  1251. va_start(a, nargs);
  1252. return vtracebyteoptn(def, nargs, a, C_nil);
  1253. }
  1254. Lisp_Object tracehardopt1(Lisp_Object def, Lisp_Object a)
  1255. {
  1256. return tracehardoptn(def, 1, a);
  1257. }
  1258. Lisp_Object tracehardopt2(Lisp_Object def, Lisp_Object a, Lisp_Object b)
  1259. {
  1260. return tracehardoptn(def, 2, a, b);
  1261. }
  1262. Lisp_Object MS_CDECL tracehardoptn(Lisp_Object def, int nargs, ...)
  1263. {
  1264. va_list a;
  1265. va_start(a, nargs);
  1266. return vtracebyteoptn(def, nargs, a, SPID_NOARG);
  1267. }
  1268. Lisp_Object tracebyteoptrest1(Lisp_Object def, Lisp_Object a)
  1269. {
  1270. return tracebyteoptrestn(def, 1, a);
  1271. }
  1272. Lisp_Object tracebyteoptrest2(Lisp_Object def, Lisp_Object a, Lisp_Object b)
  1273. {
  1274. return tracebyteoptrestn(def, 2, a, b);
  1275. }
  1276. static Lisp_Object vtracebyterestn(Lisp_Object def, int nargs,
  1277. va_list a, Lisp_Object dflt)
  1278. {
  1279. Lisp_Object r;
  1280. Lisp_Object nil = C_nil;
  1281. int i, wantargs, wantopts;
  1282. Lisp_Object *stack_save = stack;
  1283. push3(litvec, codevec, def);
  1284. if (nargs != 0) push_args(a, nargs);
  1285. else va_end(a);
  1286. stackcheck1(stack-stack_save, def);
  1287. r = qcar(def);
  1288. wantargs = ((unsigned char *)data_of_bps(r))[0];
  1289. wantopts = ((unsigned char *)data_of_bps(r))[1];
  1290. if (nargs < wantargs)
  1291. { popv(nargs+2);
  1292. return error(2, err_wrong_no_args, name_from(def),
  1293. fixnum_of_int((int32)nargs));
  1294. }
  1295. while (nargs < wantargs+wantopts)
  1296. { push(dflt); /* Provide value for all optional args */
  1297. nargs++;
  1298. }
  1299. { Lisp_Object rest = nil;
  1300. while (nargs > wantargs+wantopts)
  1301. { Lisp_Object w = stack[0];
  1302. stack[0] = def;
  1303. rest = cons(w, rest);
  1304. errexitn(nargs+2);
  1305. pop(def);
  1306. nargs--;
  1307. }
  1308. push(rest);
  1309. nargs++;
  1310. }
  1311. stackcheck1(stack-stack_save, def);
  1312. freshline_trace();
  1313. loop_print_trace(name_from(def));
  1314. trace_printf(" (%d args)\n", nargs);
  1315. for (i=1; i<=nargs; i++)
  1316. { trace_printf("Arg%d: ", i);
  1317. loop_print_trace(stack[i-nargs]);
  1318. trace_printf("\n");
  1319. }
  1320. def = stack[-nargs];
  1321. r = qcar(def);
  1322. r = bytestream_interpret(r, qcdr(def), stack-nargs);
  1323. nil = C_nil;
  1324. if (exception_pending())
  1325. { flip_exception();
  1326. stack += nargs;
  1327. if ((exit_reason & UNWIND_ERROR) != 0)
  1328. for (i=1; i<=nargs; i++)
  1329. { err_printf("Arg%d: ", i);
  1330. loop_print_error(stack[i-nargs]); err_printf("\n");
  1331. ignore_exception();
  1332. }
  1333. popv(nargs+1); pop2(codevec, litvec);
  1334. flip_exception();
  1335. return nil;
  1336. }
  1337. #ifdef COMMON
  1338. r = Lmv_list(nil, r);
  1339. if (exception_pending())
  1340. { flip_exception();
  1341. popv(1); pop2(codevec, litvec);
  1342. flip_exception();
  1343. return nil;
  1344. }
  1345. #endif
  1346. pop(def);
  1347. push(r);
  1348. freshline_trace();
  1349. loop_print_trace(name_from(def));
  1350. nil = C_nil;
  1351. if (!exception_pending())
  1352. { trace_printf(" = ");
  1353. loop_print_trace(r);
  1354. trace_printf("\n");
  1355. }
  1356. if (exception_pending())
  1357. { flip_exception();
  1358. popv(1); pop2(codevec, litvec);
  1359. flip_exception();
  1360. return nil;
  1361. }
  1362. pop3(r, codevec, litvec);
  1363. #ifdef COMMON
  1364. r = unpack_mv(nil, r);
  1365. #endif
  1366. return r;
  1367. }
  1368. Lisp_Object MS_CDECL tracebyteoptrestn(Lisp_Object def, int nargs, ...)
  1369. {
  1370. va_list a;
  1371. va_start(a, nargs);
  1372. return vtracebyterestn(def, nargs, a, C_nil);
  1373. }
  1374. Lisp_Object tracehardoptrest1(Lisp_Object def, Lisp_Object a)
  1375. {
  1376. return tracehardoptrestn(def, 1, a);
  1377. }
  1378. Lisp_Object tracehardoptrest2(Lisp_Object def, Lisp_Object a, Lisp_Object b)
  1379. {
  1380. return tracehardoptrestn(def, 2, a, b);
  1381. }
  1382. Lisp_Object MS_CDECL tracehardoptrestn(Lisp_Object def, int nargs, ...)
  1383. {
  1384. va_list a;
  1385. va_start(a, nargs);
  1386. return vtracebyterestn(def, nargs, a, SPID_NOARG);
  1387. }
  1388. static Lisp_Object Lis_spid(Lisp_Object nil, Lisp_Object a)
  1389. { /* Used in compilation for optional args */
  1390. return onevalue(Lispify_predicate(is_spid(a)));
  1391. }
  1392. static Lisp_Object Lspid_to_nil(Lisp_Object nil, Lisp_Object a)
  1393. { /* Used in compilation for optional args */
  1394. if (is_spid(a)) a = nil;
  1395. return onevalue(a);
  1396. }
  1397. static Lisp_Object MS_CDECL Lload_spid(Lisp_Object nil, int nargs, ...)
  1398. { /* Used in compilation of UNWIND-PROTECT */
  1399. CSL_IGNORE(nil);
  1400. CSL_IGNORE(nargs);
  1401. return onevalue(SPID_PROTECT);
  1402. }
  1403. Lisp_Object Lmv_list(Lisp_Object nil, Lisp_Object a)
  1404. /*
  1405. * This does a (multiple-value-list A) on just one form. It must be used
  1406. * carefully so that the value-count information does not get lost between
  1407. * the evaluation of A and calling this code.
  1408. */
  1409. {
  1410. #ifdef COMMON
  1411. Lisp_Object r, *save_stack = stack;
  1412. int i, x = exit_count;
  1413. stackcheck1(0, a);
  1414. if (x > 0) push(a);
  1415. for (i=2; i<=x; i++) push((&work_0)[i]);
  1416. r = nil;
  1417. for (i=0; i<x; i++)
  1418. { Lisp_Object w;
  1419. pop(w);
  1420. r = cons(w, r);
  1421. nil = C_nil;
  1422. if (exception_pending())
  1423. { stack = save_stack;
  1424. return nil;
  1425. }
  1426. }
  1427. return onevalue(r);
  1428. #else
  1429. CSL_IGNORE(nil);
  1430. return ncons(a);
  1431. #endif
  1432. }
  1433. /*
  1434. * In these tables there are some functions that would need adjusting
  1435. * for a Common Lisp compiler, since they take different numbers of
  1436. * args in Common and Standard Lisp.
  1437. * This means, to be specific:
  1438. *
  1439. * Lgensym Lread Latan Ltruncate Lfloat
  1440. * Lintern Lmacroexpand Lmacroexpand_1
  1441. * Lrandom Lunintern Lappend Leqn Lgcd
  1442. * Lgeq Lgreaterp Llcm Lleq Llessp
  1443. * Lquotient
  1444. *
  1445. * In these cases (at least!) the Common Lisp version of the compiler will
  1446. * need to avoid generating the call that uses this table.
  1447. *
  1448. * Some functions are missing from the list here because they seemed
  1449. * critical enough to be awarded single-byte opcodes or because the
  1450. * compiler always expands them away - car through cddddr are the main
  1451. * cases, together with eq and equal.
  1452. */
  1453. n_args *zero_arg_functions[] =
  1454. {
  1455. Lbatchp, /* 0 */
  1456. Ldate, /* 1 */
  1457. Leject, /* 2 */
  1458. Lerror0, /* 3 */
  1459. Lgctime, /* 4 */
  1460. Lgensym, /* 5 */
  1461. Llposn, /* 6 */
  1462. Lnext_random, /* 7 */
  1463. Lposn, /* 8 */
  1464. Lread, /* 9 */
  1465. Lreadch, /* 10 */
  1466. Lterpri, /* 11 */
  1467. Ltime, /* 12 */
  1468. Ltyi, /* 13 */
  1469. Lload_spid, /* 14 */ /* ONLY used in compiled code */
  1470. NULL
  1471. };
  1472. one_args *one_arg_functions[] =
  1473. {
  1474. Labsval, /* 0 */
  1475. Ladd1, /* 1 */
  1476. Latan, /* 2 */
  1477. Lapply0, /* 3 */
  1478. Latom, /* 4 */
  1479. Lboundp, /* 5 */
  1480. Lchar_code, /* 6 */
  1481. Lclose, /* 7 */
  1482. Lcodep, /* 8 */
  1483. Lcompress, /* 9 */
  1484. Lconstantp, /* 10 */
  1485. Ldigitp, /* 11 */
  1486. Lendp, /* 12 */
  1487. Leval, /* 13 */
  1488. Levenp, /* 14 */
  1489. Levlis, /* 15 */
  1490. Lexplode, /* 16 */
  1491. Lexplode2lc, /* 17 */
  1492. Lexplodec, /* 18 */
  1493. Lfixp, /* 19 */
  1494. Lfloat, /* 20 */
  1495. Lfloatp, /* 21 */
  1496. Lsymbol_specialp, /* 22 */
  1497. Lgc, /* 23 */
  1498. Lgensym1, /* 24 */
  1499. Lgetenv, /* 25 */
  1500. Lsymbol_globalp, /* 26 */
  1501. Liadd1, /* 27 */
  1502. Lsymbolp, /* 28 */
  1503. Liminus, /* 29 */
  1504. Liminusp, /* 30 */
  1505. Lindirect, /* 31 */
  1506. Lintegerp, /* 32 */
  1507. Lintern, /* 33 */
  1508. Lisub1, /* 34 */
  1509. Llength, /* 35 */
  1510. Llengthc, /* 36 */
  1511. Llinelength, /* 37 */
  1512. Lalpha_char_p, /* 38 */
  1513. Lload_module, /* 39 */
  1514. Llognot, /* 40 */
  1515. Lmacroexpand, /* 41 */
  1516. Lmacroexpand_1, /* 42 */
  1517. Lmacro_function, /* 43 */
  1518. Lget_bps, /* 44 */
  1519. Lmake_global, /* 45 */
  1520. Lsmkvect, /* 46 */
  1521. Lmake_special, /* 47 */
  1522. Lminus, /* 48 */
  1523. Lminusp, /* 49 */
  1524. Lmkvect, /* 50 */
  1525. Lmodular_minus, /* 51 */
  1526. Lmodular_number, /* 52 */
  1527. Lmodular_reciprocal, /* 53 */
  1528. Lnull, /* 54 */
  1529. Loddp, /* 55 */
  1530. Lonep, /* 56 */
  1531. Lpagelength, /* 57 */
  1532. Lconsp, /* 58 */
  1533. Lplist, /* 59 */
  1534. Lplusp, /* 60 */
  1535. Lprin, /* 61 */
  1536. Lprinc, /* 62 */
  1537. Lprint, /* 63 */
  1538. Lprintc, /* 64 */
  1539. Lrandom, /* 65 */
  1540. Lrational, /* 66 */
  1541. Lrdf1, /* 67 */
  1542. Lrds, /* 68 */
  1543. Lremd, /* 69 */
  1544. Lreverse, /* 70 */
  1545. Lnreverse, /* 71 */
  1546. Lwhitespace_char_p, /* 72 */
  1547. Lset_small_modulus, /* 73 */
  1548. Lxtab, /* 74 */
  1549. Lspecial_char, /* 75 */
  1550. Lspecial_form_p, /* 76 */
  1551. Lspool, /* 77 */
  1552. Lstop, /* 78 */
  1553. Lstringp, /* 79 */
  1554. Lsub1, /* 80 */
  1555. Lsymbol_env, /* 81 */
  1556. Lsymbol_function, /* 82 */
  1557. Lsymbol_name, /* 83 */
  1558. Lsymbol_value, /* 84 */
  1559. Lsystem, /* 85 */
  1560. Ltruncate, /* 86 */
  1561. Lttab, /* 87 */
  1562. Ltyo, /* 88 */
  1563. Lunintern, /* 89 */
  1564. Lunmake_global, /* 90 */
  1565. Lunmake_special, /* 91 */
  1566. Lupbv, /* 92 */
  1567. Lsimple_vectorp, /* 93 */
  1568. Lverbos, /* 94 */
  1569. Lwrs, /* 95 */
  1570. Lzerop, /* 96 */
  1571. Lcar, /* 97 */
  1572. Lcdr, /* 98 */
  1573. Lcaar, /* 99 */
  1574. Lcadr, /* 100 */
  1575. Lcdar, /* 101 */
  1576. Lcddr, /* 102 */
  1577. Lcar, /* 103 */ /* Really QCAR (unchecked) */
  1578. Lcdr, /* 104 */
  1579. Lcaar, /* 105 */
  1580. Lcadr, /* 106 */
  1581. Lcdar, /* 107 */
  1582. Lcddr, /* 108 */
  1583. Lncons, /* 109 */
  1584. Lnumberp, /* 110 */
  1585. Lis_spid, /* 111 */ /* ONLY used in compiled code */
  1586. Lspid_to_nil, /* 112 */ /* ONLY used in compiled code */
  1587. Lmv_list, /* 113 */ /* ONLY used in compiled code */
  1588. NULL
  1589. };
  1590. two_args *two_arg_functions[] =
  1591. {
  1592. Lappend, /* 0 */
  1593. Lash, /* 1 */
  1594. Lassoc, /* 2 */
  1595. Latsoc, /* 3 */
  1596. Ldeleq, /* 4 */
  1597. Ldelete, /* 5 */
  1598. Ldivide, /* 6 */
  1599. Leqcar, /* 7 */
  1600. Leql, /* 8 */
  1601. Leqn, /* 9 */
  1602. Lexpt, /* 10 */
  1603. Lflag, /* 11 */
  1604. Lflagpcar, /* 12 */
  1605. Lgcd, /* 13 */
  1606. Lgeq, /* 14 */
  1607. Lgetv, /* 15 */
  1608. Lgreaterp, /* 16 */
  1609. Lidifference, /* 17 */
  1610. Ligreaterp, /* 18 */
  1611. Lilessp, /* 19 */
  1612. Limax, /* 20 */
  1613. Limin, /* 21 */
  1614. Liplus2, /* 22 */
  1615. Liquotient, /* 23 */
  1616. Liremainder, /* 24 */
  1617. Lirightshift, /* 25 */
  1618. Litimes2, /* 26 */
  1619. Llcm, /* 27 */
  1620. Lleq, /* 28 */
  1621. Llessp, /* 29 */
  1622. Lmake_random_state, /* 30 */
  1623. Lmax2, /* 31 */
  1624. Lmember, /* 32 */
  1625. Lmemq, /* 33 */
  1626. Lmin2, /* 34 */
  1627. Lmod, /* 35 */
  1628. Lmodular_difference, /* 36 */
  1629. Lmodular_expt, /* 37 */
  1630. Lmodular_plus, /* 38 */
  1631. Lmodular_quotient, /* 39 */
  1632. Lmodular_times, /* 40 */
  1633. Lnconc, /* 41 */
  1634. Lneq, /* 42 */
  1635. Lorderp, /* 43 */
  1636. Lquotient, /* 44 */
  1637. Lrem, /* 45 */
  1638. Lremflag, /* 46 */
  1639. Lremprop, /* 47 */
  1640. Lrplaca, /* 48 */
  1641. Lrplacd, /* 49 */
  1642. Lsgetv, /* 50 */
  1643. Lset, /* 51 */
  1644. Lsmemq, /* 52 */
  1645. Lsubla, /* 53 */
  1646. Lsublis, /* 54 */
  1647. Lsymbol_set_definition, /* 55 */
  1648. Lsymbol_set_env, /* 56 */
  1649. Ltimes2, /* 57 */
  1650. Lxcons, /* 58 */
  1651. Lequal, /* 59 */
  1652. Leq, /* 60 */
  1653. Lcons, /* 61 */
  1654. Llist2, /* 62 */
  1655. Lget, /* 63 */
  1656. Lgetv, /* 64 */ /* QGETV */
  1657. Lflagp, /* 65 */
  1658. Lapply1, /* 66 */
  1659. Ldifference2, /* 67 */
  1660. Lplus2, /* 68 */
  1661. Ltimes2, /* 69 */
  1662. Lequalcar, /* 70 */
  1663. Leq, /* 71 */ /* IEQUAL */
  1664. Lnreverse2, /* 72 */
  1665. NULL
  1666. };
  1667. n_args *three_arg_functions[] =
  1668. {
  1669. Lbpsputv, /* 0 */
  1670. Lerrorsetn, /* 1 */
  1671. Llist2star, /* 2 */
  1672. Llist3, /* 3 */
  1673. Lputprop, /* 4 */
  1674. Lputv, /* 5 */
  1675. Lsputv, /* 6 */
  1676. Lsubst, /* 7 */
  1677. Lapply2, /* 8 */
  1678. Lacons, /* 9 */
  1679. NULL
  1680. };
  1681. /* end of eval4.c */