Teach sql-mode's imenu about IF NOT EXISTS
[bpt/emacs.git] / src / bytecode.c
1 /* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985-1988, 1993, 2000-2012 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
6 GNU Emacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
18
19 /*
20 hacked on by jwz@lucid.com 17-jun-91
21 o added a compile-time switch to turn on simple sanity checking;
22 o put back the obsolete byte-codes for error-detection;
23 o added a new instruction, unbind_all, which I will use for
24 tail-recursion elimination;
25 o made temp_output_buffer_show be called with the right number
26 of args;
27 o made the new bytecodes be called with args in the right order;
28 o added metering support.
29
30 by Hallvard:
31 o added relative jump instructions;
32 o all conditionals now only do QUIT if they jump.
33 */
34
35 #include <config.h>
36
37 #include "lisp.h"
38 #include "character.h"
39 #include "buffer.h"
40 #include "syntax.h"
41 #include "window.h"
42
43 #ifdef CHECK_FRAME_FONT
44 #include "frame.h"
45 #include "xterm.h"
46 #endif
47
48 /*
49 * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for
50 * debugging the byte compiler...)
51 *
52 * define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
53 */
54 /* #define BYTE_CODE_SAFE */
55 /* #define BYTE_CODE_METER */
56
57 /* If BYTE_CODE_THREADED is defined, then the interpreter will be
58 indirect threaded, using GCC's computed goto extension. This code,
59 as currently implemented, is incompatible with BYTE_CODE_SAFE and
60 BYTE_CODE_METER. */
61 #if defined (__GNUC__) && !defined (BYTE_CODE_SAFE) && !defined (BYTE_CODE_METER)
62 #define BYTE_CODE_THREADED
63 #endif
64
65 \f
66 #ifdef BYTE_CODE_METER
67
68 Lisp_Object Qbyte_code_meter;
69 #define METER_2(code1, code2) AREF (AREF (Vbyte_code_meter, code1), code2)
70 #define METER_1(code) METER_2 (0, code)
71
72 #define METER_CODE(last_code, this_code) \
73 { \
74 if (byte_metering_on) \
75 { \
76 if (XFASTINT (METER_1 (this_code)) < MOST_POSITIVE_FIXNUM) \
77 XSETFASTINT (METER_1 (this_code), \
78 XFASTINT (METER_1 (this_code)) + 1); \
79 if (last_code \
80 && (XFASTINT (METER_2 (last_code, this_code)) \
81 < MOST_POSITIVE_FIXNUM)) \
82 XSETFASTINT (METER_2 (last_code, this_code), \
83 XFASTINT (METER_2 (last_code, this_code)) + 1); \
84 } \
85 }
86
87 #endif /* BYTE_CODE_METER */
88 \f
89
90 Lisp_Object Qbytecode;
91
92 /* Byte codes: */
93
94 #define BYTE_CODES \
95 DEFINE (Bstack_ref, 0) /* Actually, Bstack_ref+0 is not implemented: use dup. */ \
96 DEFINE (Bstack_ref1, 1) \
97 DEFINE (Bstack_ref2, 2) \
98 DEFINE (Bstack_ref3, 3) \
99 DEFINE (Bstack_ref4, 4) \
100 DEFINE (Bstack_ref5, 5) \
101 DEFINE (Bstack_ref6, 6) \
102 DEFINE (Bstack_ref7, 7) \
103 DEFINE (Bvarref, 010) \
104 DEFINE (Bvarref1, 011) \
105 DEFINE (Bvarref2, 012) \
106 DEFINE (Bvarref3, 013) \
107 DEFINE (Bvarref4, 014) \
108 DEFINE (Bvarref5, 015) \
109 DEFINE (Bvarref6, 016) \
110 DEFINE (Bvarref7, 017) \
111 DEFINE (Bvarset, 020) \
112 DEFINE (Bvarset1, 021) \
113 DEFINE (Bvarset2, 022) \
114 DEFINE (Bvarset3, 023) \
115 DEFINE (Bvarset4, 024) \
116 DEFINE (Bvarset5, 025) \
117 DEFINE (Bvarset6, 026) \
118 DEFINE (Bvarset7, 027) \
119 DEFINE (Bvarbind, 030) \
120 DEFINE (Bvarbind1, 031) \
121 DEFINE (Bvarbind2, 032) \
122 DEFINE (Bvarbind3, 033) \
123 DEFINE (Bvarbind4, 034) \
124 DEFINE (Bvarbind5, 035) \
125 DEFINE (Bvarbind6, 036) \
126 DEFINE (Bvarbind7, 037) \
127 DEFINE (Bcall, 040) \
128 DEFINE (Bcall1, 041) \
129 DEFINE (Bcall2, 042) \
130 DEFINE (Bcall3, 043) \
131 DEFINE (Bcall4, 044) \
132 DEFINE (Bcall5, 045) \
133 DEFINE (Bcall6, 046) \
134 DEFINE (Bcall7, 047) \
135 DEFINE (Bunbind, 050) \
136 DEFINE (Bunbind1, 051) \
137 DEFINE (Bunbind2, 052) \
138 DEFINE (Bunbind3, 053) \
139 DEFINE (Bunbind4, 054) \
140 DEFINE (Bunbind5, 055) \
141 DEFINE (Bunbind6, 056) \
142 DEFINE (Bunbind7, 057) \
143 \
144 DEFINE (Bnth, 070) \
145 DEFINE (Bsymbolp, 071) \
146 DEFINE (Bconsp, 072) \
147 DEFINE (Bstringp, 073) \
148 DEFINE (Blistp, 074) \
149 DEFINE (Beq, 075) \
150 DEFINE (Bmemq, 076) \
151 DEFINE (Bnot, 077) \
152 DEFINE (Bcar, 0100) \
153 DEFINE (Bcdr, 0101) \
154 DEFINE (Bcons, 0102) \
155 DEFINE (Blist1, 0103) \
156 DEFINE (Blist2, 0104) \
157 DEFINE (Blist3, 0105) \
158 DEFINE (Blist4, 0106) \
159 DEFINE (Blength, 0107) \
160 DEFINE (Baref, 0110) \
161 DEFINE (Baset, 0111) \
162 DEFINE (Bsymbol_value, 0112) \
163 DEFINE (Bsymbol_function, 0113) \
164 DEFINE (Bset, 0114) \
165 DEFINE (Bfset, 0115) \
166 DEFINE (Bget, 0116) \
167 DEFINE (Bsubstring, 0117) \
168 DEFINE (Bconcat2, 0120) \
169 DEFINE (Bconcat3, 0121) \
170 DEFINE (Bconcat4, 0122) \
171 DEFINE (Bsub1, 0123) \
172 DEFINE (Badd1, 0124) \
173 DEFINE (Beqlsign, 0125) \
174 DEFINE (Bgtr, 0126) \
175 DEFINE (Blss, 0127) \
176 DEFINE (Bleq, 0130) \
177 DEFINE (Bgeq, 0131) \
178 DEFINE (Bdiff, 0132) \
179 DEFINE (Bnegate, 0133) \
180 DEFINE (Bplus, 0134) \
181 DEFINE (Bmax, 0135) \
182 DEFINE (Bmin, 0136) \
183 DEFINE (Bmult, 0137) \
184 \
185 DEFINE (Bpoint, 0140) \
186 /* Was Bmark in v17. */ \
187 DEFINE (Bsave_current_buffer, 0141) /* Obsolete. */ \
188 DEFINE (Bgoto_char, 0142) \
189 DEFINE (Binsert, 0143) \
190 DEFINE (Bpoint_max, 0144) \
191 DEFINE (Bpoint_min, 0145) \
192 DEFINE (Bchar_after, 0146) \
193 DEFINE (Bfollowing_char, 0147) \
194 DEFINE (Bpreceding_char, 0150) \
195 DEFINE (Bcurrent_column, 0151) \
196 DEFINE (Bindent_to, 0152) \
197 DEFINE (Beolp, 0154) \
198 DEFINE (Beobp, 0155) \
199 DEFINE (Bbolp, 0156) \
200 DEFINE (Bbobp, 0157) \
201 DEFINE (Bcurrent_buffer, 0160) \
202 DEFINE (Bset_buffer, 0161) \
203 DEFINE (Bsave_current_buffer_1, 0162) /* Replacing Bsave_current_buffer. */ \
204 DEFINE (Binteractive_p, 0164) /* Obsolete since Emacs-24.1. */ \
205 \
206 DEFINE (Bforward_char, 0165) \
207 DEFINE (Bforward_word, 0166) \
208 DEFINE (Bskip_chars_forward, 0167) \
209 DEFINE (Bskip_chars_backward, 0170) \
210 DEFINE (Bforward_line, 0171) \
211 DEFINE (Bchar_syntax, 0172) \
212 DEFINE (Bbuffer_substring, 0173) \
213 DEFINE (Bdelete_region, 0174) \
214 DEFINE (Bnarrow_to_region, 0175) \
215 DEFINE (Bwiden, 0176) \
216 DEFINE (Bend_of_line, 0177) \
217 \
218 DEFINE (Bconstant2, 0201) \
219 DEFINE (Bgoto, 0202) \
220 DEFINE (Bgotoifnil, 0203) \
221 DEFINE (Bgotoifnonnil, 0204) \
222 DEFINE (Bgotoifnilelsepop, 0205) \
223 DEFINE (Bgotoifnonnilelsepop, 0206) \
224 DEFINE (Breturn, 0207) \
225 DEFINE (Bdiscard, 0210) \
226 DEFINE (Bdup, 0211) \
227 \
228 DEFINE (Bsave_excursion, 0212) \
229 DEFINE (Bsave_window_excursion, 0213) /* Obsolete since Emacs-24.1. */ \
230 DEFINE (Bsave_restriction, 0214) \
231 DEFINE (Bcatch, 0215) \
232 \
233 DEFINE (Bunwind_protect, 0216) \
234 DEFINE (Bcondition_case, 0217) \
235 DEFINE (Btemp_output_buffer_setup, 0220) /* Obsolete since Emacs-24.1. */ \
236 DEFINE (Btemp_output_buffer_show, 0221) /* Obsolete since Emacs-24.1. */ \
237 \
238 DEFINE (Bunbind_all, 0222) /* Obsolete. Never used. */ \
239 \
240 DEFINE (Bset_marker, 0223) \
241 DEFINE (Bmatch_beginning, 0224) \
242 DEFINE (Bmatch_end, 0225) \
243 DEFINE (Bupcase, 0226) \
244 DEFINE (Bdowncase, 0227) \
245 \
246 DEFINE (Bstringeqlsign, 0230) \
247 DEFINE (Bstringlss, 0231) \
248 DEFINE (Bequal, 0232) \
249 DEFINE (Bnthcdr, 0233) \
250 DEFINE (Belt, 0234) \
251 DEFINE (Bmember, 0235) \
252 DEFINE (Bassq, 0236) \
253 DEFINE (Bnreverse, 0237) \
254 DEFINE (Bsetcar, 0240) \
255 DEFINE (Bsetcdr, 0241) \
256 DEFINE (Bcar_safe, 0242) \
257 DEFINE (Bcdr_safe, 0243) \
258 DEFINE (Bnconc, 0244) \
259 DEFINE (Bquo, 0245) \
260 DEFINE (Brem, 0246) \
261 DEFINE (Bnumberp, 0247) \
262 DEFINE (Bintegerp, 0250) \
263 \
264 DEFINE (BRgoto, 0252) \
265 DEFINE (BRgotoifnil, 0253) \
266 DEFINE (BRgotoifnonnil, 0254) \
267 DEFINE (BRgotoifnilelsepop, 0255) \
268 DEFINE (BRgotoifnonnilelsepop, 0256) \
269 \
270 DEFINE (BlistN, 0257) \
271 DEFINE (BconcatN, 0260) \
272 DEFINE (BinsertN, 0261) \
273 \
274 /* Bstack_ref is code 0. */ \
275 DEFINE (Bstack_set, 0262) \
276 DEFINE (Bstack_set2, 0263) \
277 DEFINE (BdiscardN, 0266) \
278 \
279 DEFINE (Bconstant, 0300)
280
281 enum byte_code_op
282 {
283 #define DEFINE(name, value) name = value,
284 BYTE_CODES
285 #undef DEFINE
286
287 #ifdef BYTE_CODE_SAFE
288 Bscan_buffer = 0153, /* No longer generated as of v18. */
289 Bset_mark = 0163 /* this loser is no longer generated as of v18 */
290 #endif
291 };
292
293 /* Whether to maintain a `top' and `bottom' field in the stack frame. */
294 #define BYTE_MAINTAIN_TOP (BYTE_CODE_SAFE || BYTE_MARK_STACK)
295 \f
296 /* Structure describing a value stack used during byte-code execution
297 in Fbyte_code. */
298
299 struct byte_stack
300 {
301 /* Program counter. This points into the byte_string below
302 and is relocated when that string is relocated. */
303 const unsigned char *pc;
304
305 /* Top and bottom of stack. The bottom points to an area of memory
306 allocated with alloca in Fbyte_code. */
307 #if BYTE_MAINTAIN_TOP
308 Lisp_Object *top, *bottom;
309 #endif
310
311 /* The string containing the byte-code, and its current address.
312 Storing this here protects it from GC because mark_byte_stack
313 marks it. */
314 Lisp_Object byte_string;
315 const unsigned char *byte_string_start;
316
317 /* The vector of constants used during byte-code execution. Storing
318 this here protects it from GC because mark_byte_stack marks it. */
319 Lisp_Object constants;
320
321 /* Next entry in byte_stack_list. */
322 struct byte_stack *next;
323 };
324
325 /* A list of currently active byte-code execution value stacks.
326 Fbyte_code adds an entry to the head of this list before it starts
327 processing byte-code, and it removed the entry again when it is
328 done. Signaling an error truncates the list analogous to
329 gcprolist. */
330
331 struct byte_stack *byte_stack_list;
332
333 \f
334 /* Mark objects on byte_stack_list. Called during GC. */
335
336 #if BYTE_MARK_STACK
337 void
338 mark_byte_stack (void)
339 {
340 struct byte_stack *stack;
341 Lisp_Object *obj;
342
343 for (stack = byte_stack_list; stack; stack = stack->next)
344 {
345 /* If STACK->top is null here, this means there's an opcode in
346 Fbyte_code that wasn't expected to GC, but did. To find out
347 which opcode this is, record the value of `stack', and walk
348 up the stack in a debugger, stopping in frames of Fbyte_code.
349 The culprit is found in the frame of Fbyte_code where the
350 address of its local variable `stack' is equal to the
351 recorded value of `stack' here. */
352 eassert (stack->top);
353
354 for (obj = stack->bottom; obj <= stack->top; ++obj)
355 mark_object (*obj);
356
357 mark_object (stack->byte_string);
358 mark_object (stack->constants);
359 }
360 }
361 #endif
362
363 /* Unmark objects in the stacks on byte_stack_list. Relocate program
364 counters. Called when GC has completed. */
365
366 void
367 unmark_byte_stack (void)
368 {
369 struct byte_stack *stack;
370
371 for (stack = byte_stack_list; stack; stack = stack->next)
372 {
373 if (stack->byte_string_start != SDATA (stack->byte_string))
374 {
375 ptrdiff_t offset = stack->pc - stack->byte_string_start;
376 stack->byte_string_start = SDATA (stack->byte_string);
377 stack->pc = stack->byte_string_start + offset;
378 }
379 }
380 }
381
382 \f
383 /* Fetch the next byte from the bytecode stream */
384
385 #define FETCH *stack.pc++
386
387 /* Fetch two bytes from the bytecode stream and make a 16-bit number
388 out of them */
389
390 #define FETCH2 (op = FETCH, op + (FETCH << 8))
391
392 /* Push x onto the execution stack. This used to be #define PUSH(x)
393 (*++stackp = (x)) This oddity is necessary because Alliant can't be
394 bothered to compile the preincrement operator properly, as of 4/91.
395 -JimB */
396
397 #define PUSH(x) (top++, *top = (x))
398
399 /* Pop a value off the execution stack. */
400
401 #define POP (*top--)
402
403 /* Discard n values from the execution stack. */
404
405 #define DISCARD(n) (top -= (n))
406
407 /* Get the value which is at the top of the execution stack, but don't
408 pop it. */
409
410 #define TOP (*top)
411
412 /* Actions that must be performed before and after calling a function
413 that might GC. */
414
415 #if !BYTE_MAINTAIN_TOP
416 #define BEFORE_POTENTIAL_GC() ((void)0)
417 #define AFTER_POTENTIAL_GC() ((void)0)
418 #else
419 #define BEFORE_POTENTIAL_GC() stack.top = top
420 #define AFTER_POTENTIAL_GC() stack.top = NULL
421 #endif
422
423 /* Garbage collect if we have consed enough since the last time.
424 We do this at every branch, to avoid loops that never GC. */
425
426 #define MAYBE_GC() \
427 do { \
428 BEFORE_POTENTIAL_GC (); \
429 maybe_gc (); \
430 AFTER_POTENTIAL_GC (); \
431 } while (0)
432
433 /* Check for jumping out of range. */
434
435 #ifdef BYTE_CODE_SAFE
436
437 #define CHECK_RANGE(ARG) \
438 if (ARG >= bytestr_length) emacs_abort ()
439
440 #else /* not BYTE_CODE_SAFE */
441
442 #define CHECK_RANGE(ARG)
443
444 #endif /* not BYTE_CODE_SAFE */
445
446 /* A version of the QUIT macro which makes sure that the stack top is
447 set before signaling `quit'. */
448
449 #define BYTE_CODE_QUIT \
450 do { \
451 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
452 { \
453 Lisp_Object flag = Vquit_flag; \
454 Vquit_flag = Qnil; \
455 BEFORE_POTENTIAL_GC (); \
456 if (EQ (Vthrow_on_input, flag)) \
457 Fthrow (Vthrow_on_input, Qt); \
458 Fsignal (Qquit, Qnil); \
459 AFTER_POTENTIAL_GC (); \
460 } \
461 else if (pending_signals) \
462 process_pending_signals (); \
463 } while (0)
464
465
466 DEFUN ("byte-code", Fbyte_code, Sbyte_code, 3, 3, 0,
467 doc: /* Function used internally in byte-compiled code.
468 The first argument, BYTESTR, is a string of byte code;
469 the second, VECTOR, a vector of constants;
470 the third, MAXDEPTH, the maximum stack depth used in this function.
471 If the third argument is incorrect, Emacs may crash. */)
472 (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth)
473 {
474 return exec_byte_code (bytestr, vector, maxdepth, Qnil, 0, NULL);
475 }
476
477 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
478 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
479 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
480 argument list (including &rest, &optional, etc.), and ARGS, of size
481 NARGS, should be a vector of the actual arguments. The arguments in
482 ARGS are pushed on the stack according to ARGS_TEMPLATE before
483 executing BYTESTR. */
484
485 Lisp_Object
486 exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
487 Lisp_Object args_template, ptrdiff_t nargs, Lisp_Object *args)
488 {
489 ptrdiff_t count = SPECPDL_INDEX ();
490 #ifdef BYTE_CODE_METER
491 int this_op = 0;
492 int prev_op;
493 #endif
494 int op;
495 /* Lisp_Object v1, v2; */
496 Lisp_Object *vectorp;
497 #ifdef BYTE_CODE_SAFE
498 ptrdiff_t const_length;
499 Lisp_Object *stacke;
500 ptrdiff_t bytestr_length;
501 #endif
502 struct byte_stack stack;
503 Lisp_Object *top;
504 Lisp_Object result;
505
506 #if 0 /* CHECK_FRAME_FONT */
507 {
508 struct frame *f = SELECTED_FRAME ();
509 if (FRAME_X_P (f)
510 && FRAME_FONT (f)->direction != 0
511 && FRAME_FONT (f)->direction != 1)
512 emacs_abort ();
513 }
514 #endif
515
516 CHECK_STRING (bytestr);
517 CHECK_VECTOR (vector);
518 CHECK_NATNUM (maxdepth);
519
520 #ifdef BYTE_CODE_SAFE
521 const_length = ASIZE (vector);
522 #endif
523
524 if (STRING_MULTIBYTE (bytestr))
525 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
526 because they produced a raw 8-bit string for byte-code and now
527 such a byte-code string is loaded as multibyte while raw 8-bit
528 characters converted to multibyte form. Thus, now we must
529 convert them back to the originally intended unibyte form. */
530 bytestr = Fstring_as_unibyte (bytestr);
531
532 #ifdef BYTE_CODE_SAFE
533 bytestr_length = SBYTES (bytestr);
534 #endif
535 vectorp = XVECTOR (vector)->contents;
536
537 stack.byte_string = bytestr;
538 stack.pc = stack.byte_string_start = SDATA (bytestr);
539 stack.constants = vector;
540 if (MAX_ALLOCA / word_size <= XFASTINT (maxdepth))
541 memory_full (SIZE_MAX);
542 top = alloca ((XFASTINT (maxdepth) + 1) * sizeof *top);
543 #if BYTE_MAINTAIN_TOP
544 stack.bottom = top + 1;
545 stack.top = NULL;
546 #endif
547 stack.next = byte_stack_list;
548 byte_stack_list = &stack;
549
550 #ifdef BYTE_CODE_SAFE
551 stacke = stack.bottom - 1 + XFASTINT (maxdepth);
552 #endif
553
554 if (INTEGERP (args_template))
555 {
556 ptrdiff_t at = XINT (args_template);
557 bool rest = (at & 128) != 0;
558 int mandatory = at & 127;
559 ptrdiff_t nonrest = at >> 8;
560 eassert (mandatory <= nonrest);
561 if (nargs <= nonrest)
562 {
563 ptrdiff_t i;
564 for (i = 0 ; i < nargs; i++, args++)
565 PUSH (*args);
566 if (nargs < mandatory)
567 /* Too few arguments. */
568 Fsignal (Qwrong_number_of_arguments,
569 Fcons (Fcons (make_number (mandatory),
570 rest ? Qand_rest : make_number (nonrest)),
571 Fcons (make_number (nargs), Qnil)));
572 else
573 {
574 for (; i < nonrest; i++)
575 PUSH (Qnil);
576 if (rest)
577 PUSH (Qnil);
578 }
579 }
580 else if (rest)
581 {
582 ptrdiff_t i;
583 for (i = 0 ; i < nonrest; i++, args++)
584 PUSH (*args);
585 PUSH (Flist (nargs - nonrest, args));
586 }
587 else
588 /* Too many arguments. */
589 Fsignal (Qwrong_number_of_arguments,
590 Fcons (Fcons (make_number (mandatory),
591 make_number (nonrest)),
592 Fcons (make_number (nargs), Qnil)));
593 }
594 else if (! NILP (args_template))
595 /* We should push some arguments on the stack. */
596 {
597 error ("Unknown args template!");
598 }
599
600 while (1)
601 {
602 #ifdef BYTE_CODE_SAFE
603 if (top > stacke)
604 emacs_abort ();
605 else if (top < stack.bottom - 1)
606 emacs_abort ();
607 #endif
608
609 #ifdef BYTE_CODE_METER
610 prev_op = this_op;
611 this_op = op = FETCH;
612 METER_CODE (prev_op, op);
613 #else
614 #ifndef BYTE_CODE_THREADED
615 op = FETCH;
616 #endif
617 #endif
618
619 /* The interpreter can be compiled one of two ways: as an
620 ordinary switch-based interpreter, or as a threaded
621 interpreter. The threaded interpreter relies on GCC's
622 computed goto extension, so it is not available everywhere.
623 Threading provides a performance boost. These macros are how
624 we allow the code to be compiled both ways. */
625 #ifdef BYTE_CODE_THREADED
626 /* The CASE macro introduces an instruction's body. It is
627 either a label or a case label. */
628 #define CASE(OP) insn_ ## OP
629 /* NEXT is invoked at the end of an instruction to go to the
630 next instruction. It is either a computed goto, or a
631 plain break. */
632 #define NEXT goto *(targets[op = FETCH])
633 /* FIRST is like NEXT, but is only used at the start of the
634 interpreter body. In the switch-based interpreter it is the
635 switch, so the threaded definition must include a semicolon. */
636 #define FIRST NEXT;
637 /* Most cases are labeled with the CASE macro, above.
638 CASE_DEFAULT is one exception; it is used if the interpreter
639 being built requires a default case. The threaded
640 interpreter does not, because the dispatch table is
641 completely filled. */
642 #define CASE_DEFAULT
643 /* This introduces an instruction that is known to call abort. */
644 #define CASE_ABORT CASE (Bstack_ref): CASE (default)
645 #else
646 /* See above for the meaning of the various defines. */
647 #define CASE(OP) case OP
648 #define NEXT break
649 #define FIRST switch (op)
650 #define CASE_DEFAULT case 255: default:
651 #define CASE_ABORT case 0
652 #endif
653
654 #ifdef BYTE_CODE_THREADED
655
656 /* A convenience define that saves us a lot of typing and makes
657 the table clearer. */
658 #define LABEL(OP) [OP] = &&insn_ ## OP
659
660 #if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
661 # pragma GCC diagnostic push
662 # pragma GCC diagnostic ignored "-Woverride-init"
663 #endif
664
665 /* This is the dispatch table for the threaded interpreter. */
666 static const void *const targets[256] =
667 {
668 [0 ... (Bconstant - 1)] = &&insn_default,
669 [Bconstant ... 255] = &&insn_Bconstant,
670
671 #define DEFINE(name, value) LABEL (name) ,
672 BYTE_CODES
673 #undef DEFINE
674 };
675
676 #if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
677 # pragma GCC diagnostic pop
678 #endif
679
680 #endif
681
682
683 FIRST
684 {
685 CASE (Bvarref7):
686 op = FETCH2;
687 goto varref;
688
689 CASE (Bvarref):
690 CASE (Bvarref1):
691 CASE (Bvarref2):
692 CASE (Bvarref3):
693 CASE (Bvarref4):
694 CASE (Bvarref5):
695 op = op - Bvarref;
696 goto varref;
697
698 /* This seems to be the most frequently executed byte-code
699 among the Bvarref's, so avoid a goto here. */
700 CASE (Bvarref6):
701 op = FETCH;
702 varref:
703 {
704 Lisp_Object v1, v2;
705
706 v1 = vectorp[op];
707 if (SYMBOLP (v1))
708 {
709 if (XSYMBOL (v1)->redirect != SYMBOL_PLAINVAL
710 || (v2 = SYMBOL_VAL (XSYMBOL (v1)),
711 EQ (v2, Qunbound)))
712 {
713 BEFORE_POTENTIAL_GC ();
714 v2 = Fsymbol_value (v1);
715 AFTER_POTENTIAL_GC ();
716 }
717 }
718 else
719 {
720 BEFORE_POTENTIAL_GC ();
721 v2 = Fsymbol_value (v1);
722 AFTER_POTENTIAL_GC ();
723 }
724 PUSH (v2);
725 NEXT;
726 }
727
728 CASE (Bgotoifnil):
729 {
730 Lisp_Object v1;
731 MAYBE_GC ();
732 op = FETCH2;
733 v1 = POP;
734 if (NILP (v1))
735 {
736 BYTE_CODE_QUIT;
737 CHECK_RANGE (op);
738 stack.pc = stack.byte_string_start + op;
739 }
740 NEXT;
741 }
742
743 CASE (Bcar):
744 {
745 Lisp_Object v1;
746 v1 = TOP;
747 if (CONSP (v1))
748 TOP = XCAR (v1);
749 else if (NILP (v1))
750 TOP = Qnil;
751 else
752 {
753 BEFORE_POTENTIAL_GC ();
754 wrong_type_argument (Qlistp, v1);
755 AFTER_POTENTIAL_GC ();
756 }
757 NEXT;
758 }
759
760 CASE (Beq):
761 {
762 Lisp_Object v1;
763 v1 = POP;
764 TOP = EQ (v1, TOP) ? Qt : Qnil;
765 NEXT;
766 }
767
768 CASE (Bmemq):
769 {
770 Lisp_Object v1;
771 BEFORE_POTENTIAL_GC ();
772 v1 = POP;
773 TOP = Fmemq (TOP, v1);
774 AFTER_POTENTIAL_GC ();
775 NEXT;
776 }
777
778 CASE (Bcdr):
779 {
780 Lisp_Object v1;
781 v1 = TOP;
782 if (CONSP (v1))
783 TOP = XCDR (v1);
784 else if (NILP (v1))
785 TOP = Qnil;
786 else
787 {
788 BEFORE_POTENTIAL_GC ();
789 wrong_type_argument (Qlistp, v1);
790 AFTER_POTENTIAL_GC ();
791 }
792 NEXT;
793 }
794
795 CASE (Bvarset):
796 CASE (Bvarset1):
797 CASE (Bvarset2):
798 CASE (Bvarset3):
799 CASE (Bvarset4):
800 CASE (Bvarset5):
801 op -= Bvarset;
802 goto varset;
803
804 CASE (Bvarset7):
805 op = FETCH2;
806 goto varset;
807
808 CASE (Bvarset6):
809 op = FETCH;
810 varset:
811 {
812 Lisp_Object sym, val;
813
814 sym = vectorp[op];
815 val = TOP;
816
817 /* Inline the most common case. */
818 if (SYMBOLP (sym)
819 && !EQ (val, Qunbound)
820 && !XSYMBOL (sym)->redirect
821 && !SYMBOL_CONSTANT_P (sym))
822 SET_SYMBOL_VAL (XSYMBOL (sym), val);
823 else
824 {
825 BEFORE_POTENTIAL_GC ();
826 set_internal (sym, val, Qnil, 0);
827 AFTER_POTENTIAL_GC ();
828 }
829 }
830 (void) POP;
831 NEXT;
832
833 CASE (Bdup):
834 {
835 Lisp_Object v1;
836 v1 = TOP;
837 PUSH (v1);
838 NEXT;
839 }
840
841 /* ------------------ */
842
843 CASE (Bvarbind6):
844 op = FETCH;
845 goto varbind;
846
847 CASE (Bvarbind7):
848 op = FETCH2;
849 goto varbind;
850
851 CASE (Bvarbind):
852 CASE (Bvarbind1):
853 CASE (Bvarbind2):
854 CASE (Bvarbind3):
855 CASE (Bvarbind4):
856 CASE (Bvarbind5):
857 op -= Bvarbind;
858 varbind:
859 /* Specbind can signal and thus GC. */
860 BEFORE_POTENTIAL_GC ();
861 specbind (vectorp[op], POP);
862 AFTER_POTENTIAL_GC ();
863 NEXT;
864
865 CASE (Bcall6):
866 op = FETCH;
867 goto docall;
868
869 CASE (Bcall7):
870 op = FETCH2;
871 goto docall;
872
873 CASE (Bcall):
874 CASE (Bcall1):
875 CASE (Bcall2):
876 CASE (Bcall3):
877 CASE (Bcall4):
878 CASE (Bcall5):
879 op -= Bcall;
880 docall:
881 {
882 BEFORE_POTENTIAL_GC ();
883 DISCARD (op);
884 #ifdef BYTE_CODE_METER
885 if (byte_metering_on && SYMBOLP (TOP))
886 {
887 Lisp_Object v1, v2;
888
889 v1 = TOP;
890 v2 = Fget (v1, Qbyte_code_meter);
891 if (INTEGERP (v2)
892 && XINT (v2) < MOST_POSITIVE_FIXNUM)
893 {
894 XSETINT (v2, XINT (v2) + 1);
895 Fput (v1, Qbyte_code_meter, v2);
896 }
897 }
898 #endif
899 TOP = Ffuncall (op + 1, &TOP);
900 AFTER_POTENTIAL_GC ();
901 NEXT;
902 }
903
904 CASE (Bunbind6):
905 op = FETCH;
906 goto dounbind;
907
908 CASE (Bunbind7):
909 op = FETCH2;
910 goto dounbind;
911
912 CASE (Bunbind):
913 CASE (Bunbind1):
914 CASE (Bunbind2):
915 CASE (Bunbind3):
916 CASE (Bunbind4):
917 CASE (Bunbind5):
918 op -= Bunbind;
919 dounbind:
920 BEFORE_POTENTIAL_GC ();
921 unbind_to (SPECPDL_INDEX () - op, Qnil);
922 AFTER_POTENTIAL_GC ();
923 NEXT;
924
925 CASE (Bunbind_all): /* Obsolete. Never used. */
926 /* To unbind back to the beginning of this frame. Not used yet,
927 but will be needed for tail-recursion elimination. */
928 BEFORE_POTENTIAL_GC ();
929 unbind_to (count, Qnil);
930 AFTER_POTENTIAL_GC ();
931 NEXT;
932
933 CASE (Bgoto):
934 MAYBE_GC ();
935 BYTE_CODE_QUIT;
936 op = FETCH2; /* pc = FETCH2 loses since FETCH2 contains pc++ */
937 CHECK_RANGE (op);
938 stack.pc = stack.byte_string_start + op;
939 NEXT;
940
941 CASE (Bgotoifnonnil):
942 {
943 Lisp_Object v1;
944 MAYBE_GC ();
945 op = FETCH2;
946 v1 = POP;
947 if (!NILP (v1))
948 {
949 BYTE_CODE_QUIT;
950 CHECK_RANGE (op);
951 stack.pc = stack.byte_string_start + op;
952 }
953 NEXT;
954 }
955
956 CASE (Bgotoifnilelsepop):
957 MAYBE_GC ();
958 op = FETCH2;
959 if (NILP (TOP))
960 {
961 BYTE_CODE_QUIT;
962 CHECK_RANGE (op);
963 stack.pc = stack.byte_string_start + op;
964 }
965 else DISCARD (1);
966 NEXT;
967
968 CASE (Bgotoifnonnilelsepop):
969 MAYBE_GC ();
970 op = FETCH2;
971 if (!NILP (TOP))
972 {
973 BYTE_CODE_QUIT;
974 CHECK_RANGE (op);
975 stack.pc = stack.byte_string_start + op;
976 }
977 else DISCARD (1);
978 NEXT;
979
980 CASE (BRgoto):
981 MAYBE_GC ();
982 BYTE_CODE_QUIT;
983 stack.pc += (int) *stack.pc - 127;
984 NEXT;
985
986 CASE (BRgotoifnil):
987 {
988 Lisp_Object v1;
989 MAYBE_GC ();
990 v1 = POP;
991 if (NILP (v1))
992 {
993 BYTE_CODE_QUIT;
994 stack.pc += (int) *stack.pc - 128;
995 }
996 stack.pc++;
997 NEXT;
998 }
999
1000 CASE (BRgotoifnonnil):
1001 {
1002 Lisp_Object v1;
1003 MAYBE_GC ();
1004 v1 = POP;
1005 if (!NILP (v1))
1006 {
1007 BYTE_CODE_QUIT;
1008 stack.pc += (int) *stack.pc - 128;
1009 }
1010 stack.pc++;
1011 NEXT;
1012 }
1013
1014 CASE (BRgotoifnilelsepop):
1015 MAYBE_GC ();
1016 op = *stack.pc++;
1017 if (NILP (TOP))
1018 {
1019 BYTE_CODE_QUIT;
1020 stack.pc += op - 128;
1021 }
1022 else DISCARD (1);
1023 NEXT;
1024
1025 CASE (BRgotoifnonnilelsepop):
1026 MAYBE_GC ();
1027 op = *stack.pc++;
1028 if (!NILP (TOP))
1029 {
1030 BYTE_CODE_QUIT;
1031 stack.pc += op - 128;
1032 }
1033 else DISCARD (1);
1034 NEXT;
1035
1036 CASE (Breturn):
1037 result = POP;
1038 goto exit;
1039
1040 CASE (Bdiscard):
1041 DISCARD (1);
1042 NEXT;
1043
1044 CASE (Bconstant2):
1045 PUSH (vectorp[FETCH2]);
1046 NEXT;
1047
1048 CASE (Bsave_excursion):
1049 record_unwind_protect (save_excursion_restore,
1050 save_excursion_save ());
1051 NEXT;
1052
1053 CASE (Bsave_current_buffer): /* Obsolete since ??. */
1054 CASE (Bsave_current_buffer_1):
1055 record_unwind_current_buffer ();
1056 NEXT;
1057
1058 CASE (Bsave_window_excursion): /* Obsolete since 24.1. */
1059 {
1060 register ptrdiff_t count1 = SPECPDL_INDEX ();
1061 record_unwind_protect (Fset_window_configuration,
1062 Fcurrent_window_configuration (Qnil));
1063 BEFORE_POTENTIAL_GC ();
1064 TOP = Fprogn (TOP);
1065 unbind_to (count1, TOP);
1066 AFTER_POTENTIAL_GC ();
1067 NEXT;
1068 }
1069
1070 CASE (Bsave_restriction):
1071 record_unwind_protect (save_restriction_restore,
1072 save_restriction_save ());
1073 NEXT;
1074
1075 CASE (Bcatch): /* FIXME: ill-suited for lexbind. */
1076 {
1077 Lisp_Object v1;
1078 BEFORE_POTENTIAL_GC ();
1079 v1 = POP;
1080 TOP = internal_catch (TOP, eval_sub, v1);
1081 AFTER_POTENTIAL_GC ();
1082 NEXT;
1083 }
1084
1085 CASE (Bunwind_protect): /* FIXME: avoid closure for lexbind. */
1086 record_unwind_protect (Fprogn, POP);
1087 NEXT;
1088
1089 CASE (Bcondition_case): /* FIXME: ill-suited for lexbind. */
1090 {
1091 Lisp_Object handlers, body;
1092 handlers = POP;
1093 body = POP;
1094 BEFORE_POTENTIAL_GC ();
1095 TOP = internal_lisp_condition_case (TOP, body, handlers);
1096 AFTER_POTENTIAL_GC ();
1097 NEXT;
1098 }
1099
1100 CASE (Btemp_output_buffer_setup): /* Obsolete since 24.1. */
1101 BEFORE_POTENTIAL_GC ();
1102 CHECK_STRING (TOP);
1103 temp_output_buffer_setup (SSDATA (TOP));
1104 AFTER_POTENTIAL_GC ();
1105 TOP = Vstandard_output;
1106 NEXT;
1107
1108 CASE (Btemp_output_buffer_show): /* Obsolete since 24.1. */
1109 {
1110 Lisp_Object v1;
1111 BEFORE_POTENTIAL_GC ();
1112 v1 = POP;
1113 temp_output_buffer_show (TOP);
1114 TOP = v1;
1115 /* pop binding of standard-output */
1116 unbind_to (SPECPDL_INDEX () - 1, Qnil);
1117 AFTER_POTENTIAL_GC ();
1118 NEXT;
1119 }
1120
1121 CASE (Bnth):
1122 {
1123 Lisp_Object v1, v2;
1124 EMACS_INT n;
1125 BEFORE_POTENTIAL_GC ();
1126 v1 = POP;
1127 v2 = TOP;
1128 CHECK_NUMBER (v2);
1129 n = XINT (v2);
1130 immediate_quit = 1;
1131 while (--n >= 0 && CONSP (v1))
1132 v1 = XCDR (v1);
1133 immediate_quit = 0;
1134 TOP = CAR (v1);
1135 AFTER_POTENTIAL_GC ();
1136 NEXT;
1137 }
1138
1139 CASE (Bsymbolp):
1140 TOP = SYMBOLP (TOP) ? Qt : Qnil;
1141 NEXT;
1142
1143 CASE (Bconsp):
1144 TOP = CONSP (TOP) ? Qt : Qnil;
1145 NEXT;
1146
1147 CASE (Bstringp):
1148 TOP = STRINGP (TOP) ? Qt : Qnil;
1149 NEXT;
1150
1151 CASE (Blistp):
1152 TOP = CONSP (TOP) || NILP (TOP) ? Qt : Qnil;
1153 NEXT;
1154
1155 CASE (Bnot):
1156 TOP = NILP (TOP) ? Qt : Qnil;
1157 NEXT;
1158
1159 CASE (Bcons):
1160 {
1161 Lisp_Object v1;
1162 v1 = POP;
1163 TOP = Fcons (TOP, v1);
1164 NEXT;
1165 }
1166
1167 CASE (Blist1):
1168 TOP = Fcons (TOP, Qnil);
1169 NEXT;
1170
1171 CASE (Blist2):
1172 {
1173 Lisp_Object v1;
1174 v1 = POP;
1175 TOP = Fcons (TOP, Fcons (v1, Qnil));
1176 NEXT;
1177 }
1178
1179 CASE (Blist3):
1180 DISCARD (2);
1181 TOP = Flist (3, &TOP);
1182 NEXT;
1183
1184 CASE (Blist4):
1185 DISCARD (3);
1186 TOP = Flist (4, &TOP);
1187 NEXT;
1188
1189 CASE (BlistN):
1190 op = FETCH;
1191 DISCARD (op - 1);
1192 TOP = Flist (op, &TOP);
1193 NEXT;
1194
1195 CASE (Blength):
1196 BEFORE_POTENTIAL_GC ();
1197 TOP = Flength (TOP);
1198 AFTER_POTENTIAL_GC ();
1199 NEXT;
1200
1201 CASE (Baref):
1202 {
1203 Lisp_Object v1;
1204 BEFORE_POTENTIAL_GC ();
1205 v1 = POP;
1206 TOP = Faref (TOP, v1);
1207 AFTER_POTENTIAL_GC ();
1208 NEXT;
1209 }
1210
1211 CASE (Baset):
1212 {
1213 Lisp_Object v1, v2;
1214 BEFORE_POTENTIAL_GC ();
1215 v2 = POP; v1 = POP;
1216 TOP = Faset (TOP, v1, v2);
1217 AFTER_POTENTIAL_GC ();
1218 NEXT;
1219 }
1220
1221 CASE (Bsymbol_value):
1222 BEFORE_POTENTIAL_GC ();
1223 TOP = Fsymbol_value (TOP);
1224 AFTER_POTENTIAL_GC ();
1225 NEXT;
1226
1227 CASE (Bsymbol_function):
1228 BEFORE_POTENTIAL_GC ();
1229 TOP = Fsymbol_function (TOP);
1230 AFTER_POTENTIAL_GC ();
1231 NEXT;
1232
1233 CASE (Bset):
1234 {
1235 Lisp_Object v1;
1236 BEFORE_POTENTIAL_GC ();
1237 v1 = POP;
1238 TOP = Fset (TOP, v1);
1239 AFTER_POTENTIAL_GC ();
1240 NEXT;
1241 }
1242
1243 CASE (Bfset):
1244 {
1245 Lisp_Object v1;
1246 BEFORE_POTENTIAL_GC ();
1247 v1 = POP;
1248 TOP = Ffset (TOP, v1);
1249 AFTER_POTENTIAL_GC ();
1250 NEXT;
1251 }
1252
1253 CASE (Bget):
1254 {
1255 Lisp_Object v1;
1256 BEFORE_POTENTIAL_GC ();
1257 v1 = POP;
1258 TOP = Fget (TOP, v1);
1259 AFTER_POTENTIAL_GC ();
1260 NEXT;
1261 }
1262
1263 CASE (Bsubstring):
1264 {
1265 Lisp_Object v1, v2;
1266 BEFORE_POTENTIAL_GC ();
1267 v2 = POP; v1 = POP;
1268 TOP = Fsubstring (TOP, v1, v2);
1269 AFTER_POTENTIAL_GC ();
1270 NEXT;
1271 }
1272
1273 CASE (Bconcat2):
1274 BEFORE_POTENTIAL_GC ();
1275 DISCARD (1);
1276 TOP = Fconcat (2, &TOP);
1277 AFTER_POTENTIAL_GC ();
1278 NEXT;
1279
1280 CASE (Bconcat3):
1281 BEFORE_POTENTIAL_GC ();
1282 DISCARD (2);
1283 TOP = Fconcat (3, &TOP);
1284 AFTER_POTENTIAL_GC ();
1285 NEXT;
1286
1287 CASE (Bconcat4):
1288 BEFORE_POTENTIAL_GC ();
1289 DISCARD (3);
1290 TOP = Fconcat (4, &TOP);
1291 AFTER_POTENTIAL_GC ();
1292 NEXT;
1293
1294 CASE (BconcatN):
1295 op = FETCH;
1296 BEFORE_POTENTIAL_GC ();
1297 DISCARD (op - 1);
1298 TOP = Fconcat (op, &TOP);
1299 AFTER_POTENTIAL_GC ();
1300 NEXT;
1301
1302 CASE (Bsub1):
1303 {
1304 Lisp_Object v1;
1305 v1 = TOP;
1306 if (INTEGERP (v1))
1307 {
1308 XSETINT (v1, XINT (v1) - 1);
1309 TOP = v1;
1310 }
1311 else
1312 {
1313 BEFORE_POTENTIAL_GC ();
1314 TOP = Fsub1 (v1);
1315 AFTER_POTENTIAL_GC ();
1316 }
1317 NEXT;
1318 }
1319
1320 CASE (Badd1):
1321 {
1322 Lisp_Object v1;
1323 v1 = TOP;
1324 if (INTEGERP (v1))
1325 {
1326 XSETINT (v1, XINT (v1) + 1);
1327 TOP = v1;
1328 }
1329 else
1330 {
1331 BEFORE_POTENTIAL_GC ();
1332 TOP = Fadd1 (v1);
1333 AFTER_POTENTIAL_GC ();
1334 }
1335 NEXT;
1336 }
1337
1338 CASE (Beqlsign):
1339 {
1340 Lisp_Object v1, v2;
1341 BEFORE_POTENTIAL_GC ();
1342 v2 = POP; v1 = TOP;
1343 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1);
1344 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2);
1345 AFTER_POTENTIAL_GC ();
1346 if (FLOATP (v1) || FLOATP (v2))
1347 {
1348 double f1, f2;
1349
1350 f1 = (FLOATP (v1) ? XFLOAT_DATA (v1) : XINT (v1));
1351 f2 = (FLOATP (v2) ? XFLOAT_DATA (v2) : XINT (v2));
1352 TOP = (f1 == f2 ? Qt : Qnil);
1353 }
1354 else
1355 TOP = (XINT (v1) == XINT (v2) ? Qt : Qnil);
1356 NEXT;
1357 }
1358
1359 CASE (Bgtr):
1360 {
1361 Lisp_Object v1;
1362 BEFORE_POTENTIAL_GC ();
1363 v1 = POP;
1364 TOP = Fgtr (TOP, v1);
1365 AFTER_POTENTIAL_GC ();
1366 NEXT;
1367 }
1368
1369 CASE (Blss):
1370 {
1371 Lisp_Object v1;
1372 BEFORE_POTENTIAL_GC ();
1373 v1 = POP;
1374 TOP = Flss (TOP, v1);
1375 AFTER_POTENTIAL_GC ();
1376 NEXT;
1377 }
1378
1379 CASE (Bleq):
1380 {
1381 Lisp_Object v1;
1382 BEFORE_POTENTIAL_GC ();
1383 v1 = POP;
1384 TOP = Fleq (TOP, v1);
1385 AFTER_POTENTIAL_GC ();
1386 NEXT;
1387 }
1388
1389 CASE (Bgeq):
1390 {
1391 Lisp_Object v1;
1392 BEFORE_POTENTIAL_GC ();
1393 v1 = POP;
1394 TOP = Fgeq (TOP, v1);
1395 AFTER_POTENTIAL_GC ();
1396 NEXT;
1397 }
1398
1399 CASE (Bdiff):
1400 BEFORE_POTENTIAL_GC ();
1401 DISCARD (1);
1402 TOP = Fminus (2, &TOP);
1403 AFTER_POTENTIAL_GC ();
1404 NEXT;
1405
1406 CASE (Bnegate):
1407 {
1408 Lisp_Object v1;
1409 v1 = TOP;
1410 if (INTEGERP (v1))
1411 {
1412 XSETINT (v1, - XINT (v1));
1413 TOP = v1;
1414 }
1415 else
1416 {
1417 BEFORE_POTENTIAL_GC ();
1418 TOP = Fminus (1, &TOP);
1419 AFTER_POTENTIAL_GC ();
1420 }
1421 NEXT;
1422 }
1423
1424 CASE (Bplus):
1425 BEFORE_POTENTIAL_GC ();
1426 DISCARD (1);
1427 TOP = Fplus (2, &TOP);
1428 AFTER_POTENTIAL_GC ();
1429 NEXT;
1430
1431 CASE (Bmax):
1432 BEFORE_POTENTIAL_GC ();
1433 DISCARD (1);
1434 TOP = Fmax (2, &TOP);
1435 AFTER_POTENTIAL_GC ();
1436 NEXT;
1437
1438 CASE (Bmin):
1439 BEFORE_POTENTIAL_GC ();
1440 DISCARD (1);
1441 TOP = Fmin (2, &TOP);
1442 AFTER_POTENTIAL_GC ();
1443 NEXT;
1444
1445 CASE (Bmult):
1446 BEFORE_POTENTIAL_GC ();
1447 DISCARD (1);
1448 TOP = Ftimes (2, &TOP);
1449 AFTER_POTENTIAL_GC ();
1450 NEXT;
1451
1452 CASE (Bquo):
1453 BEFORE_POTENTIAL_GC ();
1454 DISCARD (1);
1455 TOP = Fquo (2, &TOP);
1456 AFTER_POTENTIAL_GC ();
1457 NEXT;
1458
1459 CASE (Brem):
1460 {
1461 Lisp_Object v1;
1462 BEFORE_POTENTIAL_GC ();
1463 v1 = POP;
1464 TOP = Frem (TOP, v1);
1465 AFTER_POTENTIAL_GC ();
1466 NEXT;
1467 }
1468
1469 CASE (Bpoint):
1470 {
1471 Lisp_Object v1;
1472 XSETFASTINT (v1, PT);
1473 PUSH (v1);
1474 NEXT;
1475 }
1476
1477 CASE (Bgoto_char):
1478 BEFORE_POTENTIAL_GC ();
1479 TOP = Fgoto_char (TOP);
1480 AFTER_POTENTIAL_GC ();
1481 NEXT;
1482
1483 CASE (Binsert):
1484 BEFORE_POTENTIAL_GC ();
1485 TOP = Finsert (1, &TOP);
1486 AFTER_POTENTIAL_GC ();
1487 NEXT;
1488
1489 CASE (BinsertN):
1490 op = FETCH;
1491 BEFORE_POTENTIAL_GC ();
1492 DISCARD (op - 1);
1493 TOP = Finsert (op, &TOP);
1494 AFTER_POTENTIAL_GC ();
1495 NEXT;
1496
1497 CASE (Bpoint_max):
1498 {
1499 Lisp_Object v1;
1500 XSETFASTINT (v1, ZV);
1501 PUSH (v1);
1502 NEXT;
1503 }
1504
1505 CASE (Bpoint_min):
1506 {
1507 Lisp_Object v1;
1508 XSETFASTINT (v1, BEGV);
1509 PUSH (v1);
1510 NEXT;
1511 }
1512
1513 CASE (Bchar_after):
1514 BEFORE_POTENTIAL_GC ();
1515 TOP = Fchar_after (TOP);
1516 AFTER_POTENTIAL_GC ();
1517 NEXT;
1518
1519 CASE (Bfollowing_char):
1520 {
1521 Lisp_Object v1;
1522 BEFORE_POTENTIAL_GC ();
1523 v1 = Ffollowing_char ();
1524 AFTER_POTENTIAL_GC ();
1525 PUSH (v1);
1526 NEXT;
1527 }
1528
1529 CASE (Bpreceding_char):
1530 {
1531 Lisp_Object v1;
1532 BEFORE_POTENTIAL_GC ();
1533 v1 = Fprevious_char ();
1534 AFTER_POTENTIAL_GC ();
1535 PUSH (v1);
1536 NEXT;
1537 }
1538
1539 CASE (Bcurrent_column):
1540 {
1541 Lisp_Object v1;
1542 BEFORE_POTENTIAL_GC ();
1543 XSETFASTINT (v1, current_column ());
1544 AFTER_POTENTIAL_GC ();
1545 PUSH (v1);
1546 NEXT;
1547 }
1548
1549 CASE (Bindent_to):
1550 BEFORE_POTENTIAL_GC ();
1551 TOP = Findent_to (TOP, Qnil);
1552 AFTER_POTENTIAL_GC ();
1553 NEXT;
1554
1555 CASE (Beolp):
1556 PUSH (Feolp ());
1557 NEXT;
1558
1559 CASE (Beobp):
1560 PUSH (Feobp ());
1561 NEXT;
1562
1563 CASE (Bbolp):
1564 PUSH (Fbolp ());
1565 NEXT;
1566
1567 CASE (Bbobp):
1568 PUSH (Fbobp ());
1569 NEXT;
1570
1571 CASE (Bcurrent_buffer):
1572 PUSH (Fcurrent_buffer ());
1573 NEXT;
1574
1575 CASE (Bset_buffer):
1576 BEFORE_POTENTIAL_GC ();
1577 TOP = Fset_buffer (TOP);
1578 AFTER_POTENTIAL_GC ();
1579 NEXT;
1580
1581 CASE (Binteractive_p): /* Obsolete since 24.1. */
1582 BEFORE_POTENTIAL_GC ();
1583 PUSH (call0 (intern ("interactive-p")));
1584 AFTER_POTENTIAL_GC ();
1585 NEXT;
1586
1587 CASE (Bforward_char):
1588 BEFORE_POTENTIAL_GC ();
1589 TOP = Fforward_char (TOP);
1590 AFTER_POTENTIAL_GC ();
1591 NEXT;
1592
1593 CASE (Bforward_word):
1594 BEFORE_POTENTIAL_GC ();
1595 TOP = Fforward_word (TOP);
1596 AFTER_POTENTIAL_GC ();
1597 NEXT;
1598
1599 CASE (Bskip_chars_forward):
1600 {
1601 Lisp_Object v1;
1602 BEFORE_POTENTIAL_GC ();
1603 v1 = POP;
1604 TOP = Fskip_chars_forward (TOP, v1);
1605 AFTER_POTENTIAL_GC ();
1606 NEXT;
1607 }
1608
1609 CASE (Bskip_chars_backward):
1610 {
1611 Lisp_Object v1;
1612 BEFORE_POTENTIAL_GC ();
1613 v1 = POP;
1614 TOP = Fskip_chars_backward (TOP, v1);
1615 AFTER_POTENTIAL_GC ();
1616 NEXT;
1617 }
1618
1619 CASE (Bforward_line):
1620 BEFORE_POTENTIAL_GC ();
1621 TOP = Fforward_line (TOP);
1622 AFTER_POTENTIAL_GC ();
1623 NEXT;
1624
1625 CASE (Bchar_syntax):
1626 {
1627 int c;
1628
1629 BEFORE_POTENTIAL_GC ();
1630 CHECK_CHARACTER (TOP);
1631 AFTER_POTENTIAL_GC ();
1632 c = XFASTINT (TOP);
1633 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
1634 MAKE_CHAR_MULTIBYTE (c);
1635 XSETFASTINT (TOP, syntax_code_spec[(int) SYNTAX (c)]);
1636 }
1637 NEXT;
1638
1639 CASE (Bbuffer_substring):
1640 {
1641 Lisp_Object v1;
1642 BEFORE_POTENTIAL_GC ();
1643 v1 = POP;
1644 TOP = Fbuffer_substring (TOP, v1);
1645 AFTER_POTENTIAL_GC ();
1646 NEXT;
1647 }
1648
1649 CASE (Bdelete_region):
1650 {
1651 Lisp_Object v1;
1652 BEFORE_POTENTIAL_GC ();
1653 v1 = POP;
1654 TOP = Fdelete_region (TOP, v1);
1655 AFTER_POTENTIAL_GC ();
1656 NEXT;
1657 }
1658
1659 CASE (Bnarrow_to_region):
1660 {
1661 Lisp_Object v1;
1662 BEFORE_POTENTIAL_GC ();
1663 v1 = POP;
1664 TOP = Fnarrow_to_region (TOP, v1);
1665 AFTER_POTENTIAL_GC ();
1666 NEXT;
1667 }
1668
1669 CASE (Bwiden):
1670 BEFORE_POTENTIAL_GC ();
1671 PUSH (Fwiden ());
1672 AFTER_POTENTIAL_GC ();
1673 NEXT;
1674
1675 CASE (Bend_of_line):
1676 BEFORE_POTENTIAL_GC ();
1677 TOP = Fend_of_line (TOP);
1678 AFTER_POTENTIAL_GC ();
1679 NEXT;
1680
1681 CASE (Bset_marker):
1682 {
1683 Lisp_Object v1, v2;
1684 BEFORE_POTENTIAL_GC ();
1685 v1 = POP;
1686 v2 = POP;
1687 TOP = Fset_marker (TOP, v2, v1);
1688 AFTER_POTENTIAL_GC ();
1689 NEXT;
1690 }
1691
1692 CASE (Bmatch_beginning):
1693 BEFORE_POTENTIAL_GC ();
1694 TOP = Fmatch_beginning (TOP);
1695 AFTER_POTENTIAL_GC ();
1696 NEXT;
1697
1698 CASE (Bmatch_end):
1699 BEFORE_POTENTIAL_GC ();
1700 TOP = Fmatch_end (TOP);
1701 AFTER_POTENTIAL_GC ();
1702 NEXT;
1703
1704 CASE (Bupcase):
1705 BEFORE_POTENTIAL_GC ();
1706 TOP = Fupcase (TOP);
1707 AFTER_POTENTIAL_GC ();
1708 NEXT;
1709
1710 CASE (Bdowncase):
1711 BEFORE_POTENTIAL_GC ();
1712 TOP = Fdowncase (TOP);
1713 AFTER_POTENTIAL_GC ();
1714 NEXT;
1715
1716 CASE (Bstringeqlsign):
1717 {
1718 Lisp_Object v1;
1719 BEFORE_POTENTIAL_GC ();
1720 v1 = POP;
1721 TOP = Fstring_equal (TOP, v1);
1722 AFTER_POTENTIAL_GC ();
1723 NEXT;
1724 }
1725
1726 CASE (Bstringlss):
1727 {
1728 Lisp_Object v1;
1729 BEFORE_POTENTIAL_GC ();
1730 v1 = POP;
1731 TOP = Fstring_lessp (TOP, v1);
1732 AFTER_POTENTIAL_GC ();
1733 NEXT;
1734 }
1735
1736 CASE (Bequal):
1737 {
1738 Lisp_Object v1;
1739 v1 = POP;
1740 TOP = Fequal (TOP, v1);
1741 NEXT;
1742 }
1743
1744 CASE (Bnthcdr):
1745 {
1746 Lisp_Object v1;
1747 BEFORE_POTENTIAL_GC ();
1748 v1 = POP;
1749 TOP = Fnthcdr (TOP, v1);
1750 AFTER_POTENTIAL_GC ();
1751 NEXT;
1752 }
1753
1754 CASE (Belt):
1755 {
1756 Lisp_Object v1, v2;
1757 if (CONSP (TOP))
1758 {
1759 /* Exchange args and then do nth. */
1760 EMACS_INT n;
1761 BEFORE_POTENTIAL_GC ();
1762 v2 = POP;
1763 v1 = TOP;
1764 CHECK_NUMBER (v2);
1765 AFTER_POTENTIAL_GC ();
1766 n = XINT (v2);
1767 immediate_quit = 1;
1768 while (--n >= 0 && CONSP (v1))
1769 v1 = XCDR (v1);
1770 immediate_quit = 0;
1771 TOP = CAR (v1);
1772 }
1773 else
1774 {
1775 BEFORE_POTENTIAL_GC ();
1776 v1 = POP;
1777 TOP = Felt (TOP, v1);
1778 AFTER_POTENTIAL_GC ();
1779 }
1780 NEXT;
1781 }
1782
1783 CASE (Bmember):
1784 {
1785 Lisp_Object v1;
1786 BEFORE_POTENTIAL_GC ();
1787 v1 = POP;
1788 TOP = Fmember (TOP, v1);
1789 AFTER_POTENTIAL_GC ();
1790 NEXT;
1791 }
1792
1793 CASE (Bassq):
1794 {
1795 Lisp_Object v1;
1796 BEFORE_POTENTIAL_GC ();
1797 v1 = POP;
1798 TOP = Fassq (TOP, v1);
1799 AFTER_POTENTIAL_GC ();
1800 NEXT;
1801 }
1802
1803 CASE (Bnreverse):
1804 BEFORE_POTENTIAL_GC ();
1805 TOP = Fnreverse (TOP);
1806 AFTER_POTENTIAL_GC ();
1807 NEXT;
1808
1809 CASE (Bsetcar):
1810 {
1811 Lisp_Object v1;
1812 BEFORE_POTENTIAL_GC ();
1813 v1 = POP;
1814 TOP = Fsetcar (TOP, v1);
1815 AFTER_POTENTIAL_GC ();
1816 NEXT;
1817 }
1818
1819 CASE (Bsetcdr):
1820 {
1821 Lisp_Object v1;
1822 BEFORE_POTENTIAL_GC ();
1823 v1 = POP;
1824 TOP = Fsetcdr (TOP, v1);
1825 AFTER_POTENTIAL_GC ();
1826 NEXT;
1827 }
1828
1829 CASE (Bcar_safe):
1830 {
1831 Lisp_Object v1;
1832 v1 = TOP;
1833 TOP = CAR_SAFE (v1);
1834 NEXT;
1835 }
1836
1837 CASE (Bcdr_safe):
1838 {
1839 Lisp_Object v1;
1840 v1 = TOP;
1841 TOP = CDR_SAFE (v1);
1842 NEXT;
1843 }
1844
1845 CASE (Bnconc):
1846 BEFORE_POTENTIAL_GC ();
1847 DISCARD (1);
1848 TOP = Fnconc (2, &TOP);
1849 AFTER_POTENTIAL_GC ();
1850 NEXT;
1851
1852 CASE (Bnumberp):
1853 TOP = (NUMBERP (TOP) ? Qt : Qnil);
1854 NEXT;
1855
1856 CASE (Bintegerp):
1857 TOP = INTEGERP (TOP) ? Qt : Qnil;
1858 NEXT;
1859
1860 #ifdef BYTE_CODE_SAFE
1861 /* These are intentionally written using 'case' syntax,
1862 because they are incompatible with the threaded
1863 interpreter. */
1864
1865 case Bset_mark:
1866 BEFORE_POTENTIAL_GC ();
1867 error ("set-mark is an obsolete bytecode");
1868 AFTER_POTENTIAL_GC ();
1869 break;
1870 case Bscan_buffer:
1871 BEFORE_POTENTIAL_GC ();
1872 error ("scan-buffer is an obsolete bytecode");
1873 AFTER_POTENTIAL_GC ();
1874 break;
1875 #endif
1876
1877 CASE_ABORT:
1878 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1879 for that instead. */
1880 /* CASE (Bstack_ref): */
1881 error ("Invalid byte opcode");
1882
1883 /* Handy byte-codes for lexical binding. */
1884 CASE (Bstack_ref1):
1885 CASE (Bstack_ref2):
1886 CASE (Bstack_ref3):
1887 CASE (Bstack_ref4):
1888 CASE (Bstack_ref5):
1889 {
1890 Lisp_Object *ptr = top - (op - Bstack_ref);
1891 PUSH (*ptr);
1892 NEXT;
1893 }
1894 CASE (Bstack_ref6):
1895 {
1896 Lisp_Object *ptr = top - (FETCH);
1897 PUSH (*ptr);
1898 NEXT;
1899 }
1900 CASE (Bstack_ref7):
1901 {
1902 Lisp_Object *ptr = top - (FETCH2);
1903 PUSH (*ptr);
1904 NEXT;
1905 }
1906 CASE (Bstack_set):
1907 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1908 {
1909 Lisp_Object *ptr = top - (FETCH);
1910 *ptr = POP;
1911 NEXT;
1912 }
1913 CASE (Bstack_set2):
1914 {
1915 Lisp_Object *ptr = top - (FETCH2);
1916 *ptr = POP;
1917 NEXT;
1918 }
1919 CASE (BdiscardN):
1920 op = FETCH;
1921 if (op & 0x80)
1922 {
1923 op &= 0x7F;
1924 top[-op] = TOP;
1925 }
1926 DISCARD (op);
1927 NEXT;
1928
1929 CASE_DEFAULT
1930 CASE (Bconstant):
1931 #ifdef BYTE_CODE_SAFE
1932 if (op < Bconstant)
1933 {
1934 emacs_abort ();
1935 }
1936 if ((op -= Bconstant) >= const_length)
1937 {
1938 emacs_abort ();
1939 }
1940 PUSH (vectorp[op]);
1941 #else
1942 PUSH (vectorp[op - Bconstant]);
1943 #endif
1944 NEXT;
1945 }
1946 }
1947
1948 exit:
1949
1950 byte_stack_list = byte_stack_list->next;
1951
1952 /* Binds and unbinds are supposed to be compiled balanced. */
1953 if (SPECPDL_INDEX () != count)
1954 #ifdef BYTE_CODE_SAFE
1955 error ("binding stack not balanced (serious byte compiler bug)");
1956 #else
1957 emacs_abort ();
1958 #endif
1959
1960 return result;
1961 }
1962
1963 void
1964 syms_of_bytecode (void)
1965 {
1966 DEFSYM (Qbytecode, "byte-code");
1967
1968 defsubr (&Sbyte_code);
1969
1970 #ifdef BYTE_CODE_METER
1971
1972 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter,
1973 doc: /* A vector of vectors which holds a histogram of byte-code usage.
1974 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1975 opcode CODE has been executed.
1976 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1977 indicates how many times the byte opcodes CODE1 and CODE2 have been
1978 executed in succession. */);
1979
1980 DEFVAR_BOOL ("byte-metering-on", byte_metering_on,
1981 doc: /* If non-nil, keep profiling information on byte code usage.
1982 The variable byte-code-meter indicates how often each byte opcode is used.
1983 If a symbol has a property named `byte-code-meter' whose value is an
1984 integer, it is incremented each time that symbol's function is called. */);
1985
1986 byte_metering_on = 0;
1987 Vbyte_code_meter = Fmake_vector (make_number (256), make_number (0));
1988 DEFSYM (Qbyte_code_meter, "byte-code-meter");
1989 {
1990 int i = 256;
1991 while (i--)
1992 ASET (Vbyte_code_meter, i,
1993 Fmake_vector (make_number (256), make_number (0)));
1994 }
1995 #endif
1996 }