1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23: #include <config.h>
24: #include "lisp.h"
25: #include "blockinput.h"
26: #include "commands.h"
27: #include "keyboard.h"
28: #include "dispextern.h"
29: #include <setjmp.h>
30:
31: #if HAVE_X_WINDOWS
32: #include "xterm.h"
33: #endif
34:
35:
36:
37:
38: struct backtrace
39: {
40: struct backtrace *next;
41: Lisp_Object *function;
42: Lisp_Object *args;
43: int nargs;
44:
45:
46: char evalargs;
47:
48: char debug_on_exit;
49: };
50:
51: struct backtrace *backtrace_list;
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72: struct catchtag
73: {
74: Lisp_Object tag;
75: Lisp_Object val;
76: struct catchtag *next;
77: struct gcpro *gcpro;
78: jmp_buf jmp;
79: struct backtrace *backlist;
80: struct handler *handlerlist;
81: int lisp_eval_depth;
82: int pdlcount;
83: int poll_suppress_count;
84: int interrupt_input_blocked;
85: struct byte_stack *byte_stack;
86: };
87:
88: struct catchtag *catchlist;
89:
90: #ifdef DEBUG_GCPRO
91:
92: int gcpro_level;
93: #endif
94:
95: Lisp_Object Qautoload, Qmacro, Qexit, Qinteractive, Qcommandp, Qdefun;
96: Lisp_Object Qinhibit_quit, Vinhibit_quit, Vquit_flag;
97: Lisp_Object Qand_rest, Qand_optional;
98: Lisp_Object Qdebug_on_error;
99: Lisp_Object Qdeclare;
100:
101:
102:
103:
104:
105: Lisp_Object Vrun_hooks;
106:
107:
108:
109:
110:
111:
112: Lisp_Object Vautoload_queue;
113:
114:
115:
116: int specpdl_size;
117:
118:
119:
120: struct specbinding *specpdl;
121:
122:
123:
124: struct specbinding *specpdl_ptr;
125:
126:
127:
128: EMACS_INT max_specpdl_size;
129:
130:
131:
132: int lisp_eval_depth;
133:
134:
135:
136: EMACS_INT max_lisp_eval_depth;
137:
138:
139:
140: int debug_on_next_call;
141:
142:
143:
144:
145:
146: int debugger_may_continue;
147:
148:
149:
150:
151: Lisp_Object Vstack_trace_on_error;
152:
153:
154:
155:
156: Lisp_Object Vdebug_on_error;
157:
158:
159:
160:
161: Lisp_Object Vdebug_ignored_errors;
162:
163:
164:
165: Lisp_Object Vdebug_on_signal;
166:
167:
168:
169: Lisp_Object Vsignal_hook_function;
170:
171:
172:
173:
174: int debug_on_quit;
175:
176:
177:
178:
179:
180:
181:
182:
183: int when_entered_debugger;
184:
185: Lisp_Object Vdebugger;
186:
187:
188:
189:
190: Lisp_Object Vsignaling_function;
191:
192:
193:
194:
195:
196: int handling_signal;
197:
198:
199:
200: Lisp_Object Vmacro_declaration_function;
201:
202: extern Lisp_Object Qrisky_local_variable;
203:
204: static Lisp_Object funcall_lambda P_ ((Lisp_Object, int, Lisp_Object*));
205: static void unwind_to_catch P_ ((struct catchtag *, Lisp_Object)) NO_RETURN;
206:
207: #if __GNUC__
208:
209:
210:
211: Lisp_Object apply1 () __attribute__((noinline));
212: Lisp_Object call2 () __attribute__((noinline));
213: #endif
214: ^L
215: void
216: init_eval_once ()
217: {
218: specpdl_size = 50;
219: specpdl = (struct specbinding *) xmalloc (specpdl_size * sizeof (struct specbinding));
220: specpdl_ptr = specpdl;
221:
222: max_specpdl_size = 1000;
223: max_lisp_eval_depth = 300;
224:
225: Vrun_hooks = Qnil;
226: }
227:
228: void
229: init_eval ()
230: {
231: specpdl_ptr = specpdl;
232: catchlist = 0;
233: handlerlist = 0;
234: backtrace_list = 0;
235: Vquit_flag = Qnil;
236: debug_on_next_call = 0;
237: lisp_eval_depth = 0;
238: #ifdef DEBUG_GCPRO
239: gcpro_level = 0;
240: #endif
241:
242: when_entered_debugger = -1;
243: }
244:
245:
246:
247: static Lisp_Object
248: restore_stack_limits (data)
249: Lisp_Object data;
250: {
251: max_specpdl_size = XINT (XCAR (data));
252: max_lisp_eval_depth = XINT (XCDR (data));
253: return Qnil;
254: }
255:
256:
257:
258: Lisp_Object
259: call_debugger (arg)
260: Lisp_Object arg;
261: {
262: int debug_while_redisplaying;
263: int count = SPECPDL_INDEX ();
264: Lisp_Object val;
265: int old_max = max_specpdl_size;
266:
267:
268:
269:
270: max_specpdl_size += 1;
271: record_unwind_protect (restore_stack_limits,
272: Fcons (make_number (old_max),
273: make_number (max_lisp_eval_depth)));
274: max_specpdl_size = old_max;
275:
276: if (lisp_eval_depth + 40 > max_lisp_eval_depth)
277: max_lisp_eval_depth = lisp_eval_depth + 40;
278:
279: if (SPECPDL_INDEX () + 100 > max_specpdl_size)
280: max_specpdl_size = SPECPDL_INDEX () + 100;
281:
282: #ifdef HAVE_X_WINDOWS
283: if (display_hourglass_p)
284: cancel_hourglass ();
285: #endif
286:
287: debug_on_next_call = 0;
288: when_entered_debugger = num_nonmacro_input_events;
289:
290:
291:
292: debug_while_redisplaying = redisplaying_p;
293: redisplaying_p = 0;
294: specbind (intern ("debugger-may-continue"),
295: debug_while_redisplaying ? Qnil : Qt);
296: specbind (Qinhibit_redisplay, Qnil);
297: specbind (Qdebug_on_error, Qnil);
298:
299: #if 0
300:
301: specbind (Qinhibit_eval_during_redisplay, Qt);
302: #endif
303:
304: val = apply1 (Vdebugger, arg);
305:
306:
307:
308:
309: if (debug_while_redisplaying)
310: Ftop_level ();
311:
312: return unbind_to (count, val);
313: }
314:
315: void
316: do_debug_on_call (code)
317: Lisp_Object code;
318: {
319: debug_on_next_call = 0;
320: backtrace_list->debug_on_exit = 1;
321: call_debugger (Fcons (code, Qnil));
322: }
323: ^L
324:
325:
326:
327:
328: DEFUN ("or", For, Sor, 0, UNEVALLED, 0,
329: doc:
330:
331:
332: )
333: (args)
334: Lisp_Object args;
335: {
336: register Lisp_Object val = Qnil;
337: struct gcpro gcpro1;
338:
339: GCPRO1 (args);
340:
341: while (CONSP (args))
342: {
343: val = Feval (XCAR (args));
344: if (!NILP (val))
345: break;
346: args = XCDR (args);
347: }
348:
349: UNGCPRO;
350: return val;
351: }
352:
353: DEFUN ("and", Fand, Sand, 0, UNEVALLED, 0,
354: doc:
355:
356:
357: )
358: (args)
359: Lisp_Object args;
360: {
361: register Lisp_Object val = Qt;
362: struct gcpro gcpro1;
363:
364: GCPRO1 (args);
365:
366: while (CONSP (args))
367: {
368: val = Feval (XCAR (args));
369: if (NILP (val))
370: break;
371: args = XCDR (args);
372: }
373:
374: UNGCPRO;
375: return val;
376: }
377:
378: DEFUN ("if", Fif, Sif, 2, UNEVALLED, 0,
379: doc:
380:
381:
382:
383: )
384: (args)
385: Lisp_Object args;
386: {
387: register Lisp_Object cond;
388: struct gcpro gcpro1;
389:
390: GCPRO1 (args);
391: cond = Feval (Fcar (args));
392: UNGCPRO;
393:
394: if (!NILP (cond))
395: return Feval (Fcar (Fcdr (args)));
396: return Fprogn (Fcdr (Fcdr (args)));
397: }
398:
399: DEFUN ("cond", Fcond, Scond, 0, UNEVALLED, 0,
400: doc:
401:
402:
403:
404:
405:
406:
407:
408: )
409: (args)
410: Lisp_Object args;
411: {
412: register Lisp_Object clause, val;
413: struct gcpro gcpro1;
414:
415: val = Qnil;
416: GCPRO1 (args);
417: while (!NILP (args))
418: {
419: clause = Fcar (args);
420: val = Feval (Fcar (clause));
421: if (!NILP (val))
422: {
423: if (!EQ (XCDR (clause), Qnil))
424: val = Fprogn (XCDR (clause));
425: break;
426: }
427: args = XCDR (args);
428: }
429: UNGCPRO;
430:
431: return val;
432: }
433:
434: DEFUN ("progn", Fprogn, Sprogn, 0, UNEVALLED, 0,
435: doc:
436: )
437: (args)
438: Lisp_Object args;
439: {
440: register Lisp_Object val = Qnil;
441: struct gcpro gcpro1;
442:
443: GCPRO1 (args);
444:
445: while (CONSP (args))
446: {
447: val = Feval (XCAR (args));
448: args = XCDR (args);
449: }
450:
451: UNGCPRO;
452: return val;
453: }
454:
455: DEFUN ("prog1", Fprog1, Sprog1, 1, UNEVALLED, 0,
456: doc:
457:
458:
459: )
460: (args)
461: Lisp_Object args;
462: {
463: Lisp_Object val;
464: register Lisp_Object args_left;
465: struct gcpro gcpro1, gcpro2;
466: register int argnum = 0;
467:
468: if (NILP(args))
469: return Qnil;
470:
471: args_left = args;
472: val = Qnil;
473: GCPRO2 (args, val);
474:
475: do
476: {
477: if (!(argnum++))
478: val = Feval (Fcar (args_left));
479: else
480: Feval (Fcar (args_left));
481: args_left = Fcdr (args_left);
482: }
483: while (!NILP(args_left));
484:
485: UNGCPRO;
486: return val;
487: }
488:
489: DEFUN ("prog2", Fprog2, Sprog2, 2, UNEVALLED, 0,
490: doc:
491:
492:
493: )
494: (args)
495: Lisp_Object args;
496: {
497: Lisp_Object val;
498: register Lisp_Object args_left;
499: struct gcpro gcpro1, gcpro2;
500: register int argnum = -1;
501:
502: val = Qnil;
503:
504: if (NILP (args))
505: return Qnil;
506:
507: args_left = args;
508: val = Qnil;
509: GCPRO2 (args, val);
510:
511: do
512: {
513: if (!(argnum++))
514: val = Feval (Fcar (args_left));
515: else
516: Feval (Fcar (args_left));
517: args_left = Fcdr (args_left);
518: }
519: while (!NILP (args_left));
520:
521: UNGCPRO;
522: return val;
523: }
524:
525: DEFUN ("setq", Fsetq, Ssetq, 0, UNEVALLED, 0,
526: doc:
527:
528:
529:
530:
531:
532:
533: )
534: (args)
535: Lisp_Object args;
536: {
537: register Lisp_Object args_left;
538: register Lisp_Object val, sym;
539: struct gcpro gcpro1;
540:
541: if (NILP(args))
542: return Qnil;
543:
544: args_left = args;
545: GCPRO1 (args);
546:
547: do
548: {
549: val = Feval (Fcar (Fcdr (args_left)));
550: sym = Fcar (args_left);
551: Fset (sym, val);
552: args_left = Fcdr (Fcdr (args_left));
553: }
554: while (!NILP(args_left));
555:
556: UNGCPRO;
557: return val;
558: }
559:
560: DEFUN ("quote", Fquote, Squote, 1, UNEVALLED, 0,
561: doc:
562: )
563: (args)
564: Lisp_Object args;
565: {
566: return Fcar (args);
567: }
568:
569: DEFUN ("function", Ffunction, Sfunction, 1, UNEVALLED, 0,
570: doc:
571:
572:
573: )
574: (args)
575: Lisp_Object args;
576: {
577: return Fcar (args);
578: }
579:
580:
581: DEFUN ("interactive-p", Finteractive_p, Sinteractive_p, 0, 0, 0,
582: doc:
583:
584:
585:
586:
587:
588:
589:
590:
591:
592:
593:
594:
595:
596:
597: )
598: ()
599: {
600: return (INTERACTIVE && interactive_p (1)) ? Qt : Qnil;
601: }
602:
603:
604: DEFUN ("called-interactively-p", Fcalled_interactively_p, Scalled_interactively_p, 0, 0, 0,
605: doc:
606:
607:
608:
609:
610:
611:
612: )
613: ()
614: {
615: return interactive_p (1) ? Qt : Qnil;
616: }
617:
618:
619:
620:
621:
622:
623:
624:
625: int
626: interactive_p (exclude_subrs_p)
627: int exclude_subrs_p;
628: {
629: struct backtrace *btp;
630: Lisp_Object fun;
631:
632: btp = backtrace_list;
633:
634:
635:
636: fun = Findirect_function (*btp->function, Qnil);
637: if (SUBRP (fun) && (XSUBR (fun) == &Sinteractive_p
638: || XSUBR (fun) == &Scalled_interactively_p))
639: btp = btp->next;
640:
641:
642:
643:
644:
645:
646:
647:
648: while (btp
649: && (EQ (*btp->function, Qbytecode)
650: || btp->nargs == UNEVALLED))
651: btp = btp->next;
652:
653:
654:
655: