vc-hooks.el workaround for bug#11490
[emacs.git] / src / bytecode.c
blob648813aed86103e6f5fa7a8d0c81c95e6af6240f
1 /* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985-1988, 1993, 2000-2012 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
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.
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.
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/>. */
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.
30 by Hallvard:
31 o added relative jump instructions;
32 o all conditionals now only do QUIT if they jump.
35 #include <config.h>
37 #include "lisp.h"
38 #include "character.h"
39 #include "buffer.h"
40 #include "syntax.h"
41 #include "window.h"
43 #ifdef CHECK_FRAME_FONT
44 #include "frame.h"
45 #include "xterm.h"
46 #endif
49 * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for
50 * debugging the byte compiler...)
52 * define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
54 /* #define BYTE_CODE_SAFE */
55 /* #define BYTE_CODE_METER */
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
66 #ifdef BYTE_CODE_METER
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)
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 } \
87 #endif /* BYTE_CODE_METER */
90 Lisp_Object Qbytecode;
92 /* Byte codes: */
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) \
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) \
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. */ \
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) \
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) \
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) \
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. */ \
238 DEFINE (Bunbind_all, 0222) /* Obsolete. Never used. */ \
240 DEFINE (Bset_marker, 0223) \
241 DEFINE (Bmatch_beginning, 0224) \
242 DEFINE (Bmatch_end, 0225) \
243 DEFINE (Bupcase, 0226) \
244 DEFINE (Bdowncase, 0227) \
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) \
264 DEFINE (BRgoto, 0252) \
265 DEFINE (BRgotoifnil, 0253) \
266 DEFINE (BRgotoifnonnil, 0254) \
267 DEFINE (BRgotoifnilelsepop, 0255) \
268 DEFINE (BRgotoifnonnilelsepop, 0256) \
270 DEFINE (BlistN, 0257) \
271 DEFINE (BconcatN, 0260) \
272 DEFINE (BinsertN, 0261) \
274 /* Bstack_ref is code 0. */ \
275 DEFINE (Bstack_set, 0262) \
276 DEFINE (Bstack_set2, 0263) \
277 DEFINE (BdiscardN, 0266) \
279 DEFINE (Bconstant, 0300)
281 enum byte_code_op
283 #define DEFINE(name, value) name = value,
284 BYTE_CODES
285 #undef DEFINE
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
293 /* Whether to maintain a `top' and `bottom' field in the stack frame. */
294 #define BYTE_MAINTAIN_TOP (BYTE_CODE_SAFE || BYTE_MARK_STACK)
296 /* Structure describing a value stack used during byte-code execution
297 in Fbyte_code. */
299 struct byte_stack
301 /* Program counter. This points into the byte_string below
302 and is relocated when that string is relocated. */
303 const unsigned char *pc;
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
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;
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;
321 /* Next entry in byte_stack_list. */
322 struct byte_stack *next;
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. */
331 struct byte_stack *byte_stack_list;
334 /* Mark objects on byte_stack_list. Called during GC. */
336 #if BYTE_MARK_STACK
337 void
338 mark_byte_stack (void)
340 struct byte_stack *stack;
341 Lisp_Object *obj;
343 for (stack = byte_stack_list; stack; stack = stack->next)
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);
354 for (obj = stack->bottom; obj <= stack->top; ++obj)
355 mark_object (*obj);
357 mark_object (stack->byte_string);
358 mark_object (stack->constants);
361 #endif
363 /* Unmark objects in the stacks on byte_stack_list. Relocate program
364 counters. Called when GC has completed. */
366 void
367 unmark_byte_stack (void)
369 struct byte_stack *stack;
371 for (stack = byte_stack_list; stack; stack = stack->next)
373 if (stack->byte_string_start != SDATA (stack->byte_string))
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;
383 /* Fetch the next byte from the bytecode stream */
385 #define FETCH *stack.pc++
387 /* Fetch two bytes from the bytecode stream and make a 16-bit number
388 out of them */
390 #define FETCH2 (op = FETCH, op + (FETCH << 8))
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 */
397 #define PUSH(x) (top++, *top = (x))
399 /* Pop a value off the execution stack. */
401 #define POP (*top--)
403 /* Discard n values from the execution stack. */
405 #define DISCARD(n) (top -= (n))
407 /* Get the value which is at the top of the execution stack, but don't
408 pop it. */
410 #define TOP (*top)
412 /* Actions that must be performed before and after calling a function
413 that might GC. */
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
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. */
426 #define MAYBE_GC() \
427 do { \
428 BEFORE_POTENTIAL_GC (); \
429 maybe_gc (); \
430 AFTER_POTENTIAL_GC (); \
431 } while (0)
433 /* Check for jumping out of range. */
435 #ifdef BYTE_CODE_SAFE
437 #define CHECK_RANGE(ARG) \
438 if (ARG >= bytestr_length) emacs_abort ()
440 #else /* not BYTE_CODE_SAFE */
442 #define CHECK_RANGE(ARG)
444 #endif /* not BYTE_CODE_SAFE */
446 /* A version of the QUIT macro which makes sure that the stack top is
447 set before signaling `quit'. */
449 #define BYTE_CODE_QUIT \
450 do { \
451 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
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 (); \
461 else if (pending_signals) \
462 process_pending_signals (); \
463 } while (0)
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)
474 return exec_byte_code (bytestr, vector, maxdepth, Qnil, 0, NULL);
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. */
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)
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;
506 #if 0 /* CHECK_FRAME_FONT */
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 ();
514 #endif
516 CHECK_STRING (bytestr);
517 CHECK_VECTOR (vector);
518 CHECK_NATNUM (maxdepth);
520 #ifdef BYTE_CODE_SAFE
521 const_length = ASIZE (vector);
522 #endif
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);
532 #ifdef BYTE_CODE_SAFE
533 bytestr_length = SBYTES (bytestr);
534 #endif
535 vectorp = XVECTOR (vector)->contents;
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;
550 #ifdef BYTE_CODE_SAFE
551 stacke = stack.bottom - 1 + XFASTINT (maxdepth);
552 #endif
554 if (INTEGERP (args_template))
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)
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
574 for (; i < nonrest; i++)
575 PUSH (Qnil);
576 if (rest)
577 PUSH (Qnil);
580 else if (rest)
582 ptrdiff_t i;
583 for (i = 0 ; i < nonrest; i++, args++)
584 PUSH (*args);
585 PUSH (Flist (nargs - nonrest, args));
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)));
594 else if (! NILP (args_template))
595 /* We should push some arguments on the stack. */
597 error ("Unknown args template!");
600 while (1)
602 #ifdef BYTE_CODE_SAFE
603 if (top > stacke)
604 emacs_abort ();
605 else if (top < stack.bottom - 1)
606 emacs_abort ();
607 #endif
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
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
654 #ifdef BYTE_CODE_THREADED
656 /* A convenience define that saves us a lot of typing and makes
657 the table clearer. */
658 #define LABEL(OP) [OP] = &&insn_ ## OP
660 #if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
661 # pragma GCC diagnostic push
662 # pragma GCC diagnostic ignored "-Woverride-init"
663 #endif
665 /* This is the dispatch table for the threaded interpreter. */
666 static const void *const targets[256] =
668 [0 ... (Bconstant - 1)] = &&insn_default,
669 [Bconstant ... 255] = &&insn_Bconstant,
671 #define DEFINE(name, value) LABEL (name) ,
672 BYTE_CODES
673 #undef DEFINE
676 #if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
677 # pragma GCC diagnostic pop
678 #endif
680 #endif
683 FIRST
685 CASE (Bvarref7):
686 op = FETCH2;
687 goto varref;
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;
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:
704 Lisp_Object v1, v2;
706 v1 = vectorp[op];
707 if (SYMBOLP (v1))
709 if (XSYMBOL (v1)->redirect != SYMBOL_PLAINVAL
710 || (v2 = SYMBOL_VAL (XSYMBOL (v1)),
711 EQ (v2, Qunbound)))
713 BEFORE_POTENTIAL_GC ();
714 v2 = Fsymbol_value (v1);
715 AFTER_POTENTIAL_GC ();
718 else
720 BEFORE_POTENTIAL_GC ();
721 v2 = Fsymbol_value (v1);
722 AFTER_POTENTIAL_GC ();
724 PUSH (v2);
725 NEXT;
728 CASE (Bgotoifnil):
730 Lisp_Object v1;
731 MAYBE_GC ();
732 op = FETCH2;
733 v1 = POP;
734 if (NILP (v1))
736 BYTE_CODE_QUIT;
737 CHECK_RANGE (op);
738 stack.pc = stack.byte_string_start + op;
740 NEXT;
743 CASE (Bcar):
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
753 BEFORE_POTENTIAL_GC ();
754 wrong_type_argument (Qlistp, v1);
755 AFTER_POTENTIAL_GC ();
757 NEXT;
760 CASE (Beq):
762 Lisp_Object v1;
763 v1 = POP;
764 TOP = EQ (v1, TOP) ? Qt : Qnil;
765 NEXT;
768 CASE (Bmemq):
770 Lisp_Object v1;
771 BEFORE_POTENTIAL_GC ();
772 v1 = POP;
773 TOP = Fmemq (TOP, v1);
774 AFTER_POTENTIAL_GC ();
775 NEXT;
778 CASE (Bcdr):
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
788 BEFORE_POTENTIAL_GC ();
789 wrong_type_argument (Qlistp, v1);
790 AFTER_POTENTIAL_GC ();
792 NEXT;
795 CASE (Bvarset):
796 CASE (Bvarset1):
797 CASE (Bvarset2):
798 CASE (Bvarset3):
799 CASE (Bvarset4):
800 CASE (Bvarset5):
801 op -= Bvarset;
802 goto varset;
804 CASE (Bvarset7):
805 op = FETCH2;
806 goto varset;
808 CASE (Bvarset6):
809 op = FETCH;
810 varset:
812 Lisp_Object sym, val;
814 sym = vectorp[op];
815 val = TOP;
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
825 BEFORE_POTENTIAL_GC ();
826 set_internal (sym, val, Qnil, 0);
827 AFTER_POTENTIAL_GC ();
830 (void) POP;
831 NEXT;
833 CASE (Bdup):
835 Lisp_Object v1;
836 v1 = TOP;
837 PUSH (v1);
838 NEXT;
841 /* ------------------ */
843 CASE (Bvarbind6):
844 op = FETCH;
845 goto varbind;
847 CASE (Bvarbind7):
848 op = FETCH2;
849 goto varbind;
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;
865 CASE (Bcall6):
866 op = FETCH;
867 goto docall;
869 CASE (Bcall7):
870 op = FETCH2;
871 goto docall;
873 CASE (Bcall):
874 CASE (Bcall1):
875 CASE (Bcall2):
876 CASE (Bcall3):
877 CASE (Bcall4):
878 CASE (Bcall5):
879 op -= Bcall;
880 docall:
882 BEFORE_POTENTIAL_GC ();
883 DISCARD (op);
884 #ifdef BYTE_CODE_METER
885 if (byte_metering_on && SYMBOLP (TOP))
887 Lisp_Object v1, v2;
889 v1 = TOP;
890 v2 = Fget (v1, Qbyte_code_meter);
891 if (INTEGERP (v2)
892 && XINT (v2) < MOST_POSITIVE_FIXNUM)
894 XSETINT (v2, XINT (v2) + 1);
895 Fput (v1, Qbyte_code_meter, v2);
898 #endif
899 TOP = Ffuncall (op + 1, &TOP);
900 AFTER_POTENTIAL_GC ();
901 NEXT;
904 CASE (Bunbind6):
905 op = FETCH;
906 goto dounbind;
908 CASE (Bunbind7):
909 op = FETCH2;
910 goto dounbind;
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;
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;
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;
941 CASE (Bgotoifnonnil):
943 Lisp_Object v1;
944 MAYBE_GC ();
945 op = FETCH2;
946 v1 = POP;
947 if (!NILP (v1))
949 BYTE_CODE_QUIT;
950 CHECK_RANGE (op);
951 stack.pc = stack.byte_string_start + op;
953 NEXT;
956 CASE (Bgotoifnilelsepop):
957 MAYBE_GC ();
958 op = FETCH2;
959 if (NILP (TOP))
961 BYTE_CODE_QUIT;
962 CHECK_RANGE (op);
963 stack.pc = stack.byte_string_start + op;
965 else DISCARD (1);
966 NEXT;
968 CASE (Bgotoifnonnilelsepop):
969 MAYBE_GC ();
970 op = FETCH2;
971 if (!NILP (TOP))
973 BYTE_CODE_QUIT;
974 CHECK_RANGE (op);
975 stack.pc = stack.byte_string_start + op;
977 else DISCARD (1);
978 NEXT;
980 CASE (BRgoto):
981 MAYBE_GC ();
982 BYTE_CODE_QUIT;
983 stack.pc += (int) *stack.pc - 127;
984 NEXT;
986 CASE (BRgotoifnil):
988 Lisp_Object v1;
989 MAYBE_GC ();
990 v1 = POP;
991 if (NILP (v1))
993 BYTE_CODE_QUIT;
994 stack.pc += (int) *stack.pc - 128;
996 stack.pc++;
997 NEXT;
1000 CASE (BRgotoifnonnil):
1002 Lisp_Object v1;
1003 MAYBE_GC ();
1004 v1 = POP;
1005 if (!NILP (v1))
1007 BYTE_CODE_QUIT;
1008 stack.pc += (int) *stack.pc - 128;
1010 stack.pc++;
1011 NEXT;
1014 CASE (BRgotoifnilelsepop):
1015 MAYBE_GC ();
1016 op = *stack.pc++;
1017 if (NILP (TOP))
1019 BYTE_CODE_QUIT;
1020 stack.pc += op - 128;
1022 else DISCARD (1);
1023 NEXT;
1025 CASE (BRgotoifnonnilelsepop):
1026 MAYBE_GC ();
1027 op = *stack.pc++;
1028 if (!NILP (TOP))
1030 BYTE_CODE_QUIT;
1031 stack.pc += op - 128;
1033 else DISCARD (1);
1034 NEXT;
1036 CASE (Breturn):
1037 result = POP;
1038 goto exit;
1040 CASE (Bdiscard):
1041 DISCARD (1);
1042 NEXT;
1044 CASE (Bconstant2):
1045 PUSH (vectorp[FETCH2]);
1046 NEXT;
1048 CASE (Bsave_excursion):
1049 record_unwind_protect (save_excursion_restore,
1050 save_excursion_save ());
1051 NEXT;
1053 CASE (Bsave_current_buffer): /* Obsolete since ??. */
1054 CASE (Bsave_current_buffer_1):
1055 record_unwind_current_buffer ();
1056 NEXT;
1058 CASE (Bsave_window_excursion): /* Obsolete since 24.1. */
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;
1070 CASE (Bsave_restriction):
1071 record_unwind_protect (save_restriction_restore,
1072 save_restriction_save ());
1073 NEXT;
1075 CASE (Bcatch): /* FIXME: ill-suited for lexbind. */
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;
1085 CASE (Bunwind_protect): /* FIXME: avoid closure for lexbind. */
1086 record_unwind_protect (Fprogn, POP);
1087 NEXT;
1089 CASE (Bcondition_case): /* FIXME: ill-suited for lexbind. */
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;
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;
1108 CASE (Btemp_output_buffer_show): /* Obsolete since 24.1. */
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;
1121 CASE (Bnth):
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;
1139 CASE (Bsymbolp):
1140 TOP = SYMBOLP (TOP) ? Qt : Qnil;
1141 NEXT;
1143 CASE (Bconsp):
1144 TOP = CONSP (TOP) ? Qt : Qnil;
1145 NEXT;
1147 CASE (Bstringp):
1148 TOP = STRINGP (TOP) ? Qt : Qnil;
1149 NEXT;
1151 CASE (Blistp):
1152 TOP = CONSP (TOP) || NILP (TOP) ? Qt : Qnil;
1153 NEXT;
1155 CASE (Bnot):
1156 TOP = NILP (TOP) ? Qt : Qnil;
1157 NEXT;
1159 CASE (Bcons):
1161 Lisp_Object v1;
1162 v1 = POP;
1163 TOP = Fcons (TOP, v1);
1164 NEXT;
1167 CASE (Blist1):
1168 TOP = Fcons (TOP, Qnil);
1169 NEXT;
1171 CASE (Blist2):
1173 Lisp_Object v1;
1174 v1 = POP;
1175 TOP = Fcons (TOP, Fcons (v1, Qnil));
1176 NEXT;
1179 CASE (Blist3):
1180 DISCARD (2);
1181 TOP = Flist (3, &TOP);
1182 NEXT;
1184 CASE (Blist4):
1185 DISCARD (3);
1186 TOP = Flist (4, &TOP);
1187 NEXT;
1189 CASE (BlistN):
1190 op = FETCH;
1191 DISCARD (op - 1);
1192 TOP = Flist (op, &TOP);
1193 NEXT;
1195 CASE (Blength):
1196 BEFORE_POTENTIAL_GC ();
1197 TOP = Flength (TOP);
1198 AFTER_POTENTIAL_GC ();
1199 NEXT;
1201 CASE (Baref):
1203 Lisp_Object v1;
1204 BEFORE_POTENTIAL_GC ();
1205 v1 = POP;
1206 TOP = Faref (TOP, v1);
1207 AFTER_POTENTIAL_GC ();
1208 NEXT;
1211 CASE (Baset):
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;
1221 CASE (Bsymbol_value):
1222 BEFORE_POTENTIAL_GC ();
1223 TOP = Fsymbol_value (TOP);
1224 AFTER_POTENTIAL_GC ();
1225 NEXT;
1227 CASE (Bsymbol_function):
1228 BEFORE_POTENTIAL_GC ();
1229 TOP = Fsymbol_function (TOP);
1230 AFTER_POTENTIAL_GC ();
1231 NEXT;
1233 CASE (Bset):
1235 Lisp_Object v1;
1236 BEFORE_POTENTIAL_GC ();
1237 v1 = POP;
1238 TOP = Fset (TOP, v1);
1239 AFTER_POTENTIAL_GC ();
1240 NEXT;
1243 CASE (Bfset):
1245 Lisp_Object v1;
1246 BEFORE_POTENTIAL_GC ();
1247 v1 = POP;
1248 TOP = Ffset (TOP, v1);
1249 AFTER_POTENTIAL_GC ();
1250 NEXT;
1253 CASE (Bget):
1255 Lisp_Object v1;
1256 BEFORE_POTENTIAL_GC ();
1257 v1 = POP;
1258 TOP = Fget (TOP, v1);
1259 AFTER_POTENTIAL_GC ();
1260 NEXT;
1263 CASE (Bsubstring):
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;
1273 CASE (Bconcat2):
1274 BEFORE_POTENTIAL_GC ();
1275 DISCARD (1);
1276 TOP = Fconcat (2, &TOP);
1277 AFTER_POTENTIAL_GC ();
1278 NEXT;
1280 CASE (Bconcat3):
1281 BEFORE_POTENTIAL_GC ();
1282 DISCARD (2);
1283 TOP = Fconcat (3, &TOP);
1284 AFTER_POTENTIAL_GC ();
1285 NEXT;
1287 CASE (Bconcat4):
1288 BEFORE_POTENTIAL_GC ();
1289 DISCARD (3);
1290 TOP = Fconcat (4, &TOP);
1291 AFTER_POTENTIAL_GC ();
1292 NEXT;
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;
1302 CASE (Bsub1):
1304 Lisp_Object v1;
1305 v1 = TOP;
1306 if (INTEGERP (v1))
1308 XSETINT (v1, XINT (v1) - 1);
1309 TOP = v1;
1311 else
1313 BEFORE_POTENTIAL_GC ();
1314 TOP = Fsub1 (v1);
1315 AFTER_POTENTIAL_GC ();
1317 NEXT;
1320 CASE (Badd1):
1322 Lisp_Object v1;
1323 v1 = TOP;
1324 if (INTEGERP (v1))
1326 XSETINT (v1, XINT (v1) + 1);
1327 TOP = v1;
1329 else
1331 BEFORE_POTENTIAL_GC ();
1332 TOP = Fadd1 (v1);
1333 AFTER_POTENTIAL_GC ();
1335 NEXT;
1338 CASE (Beqlsign):
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))
1348 double f1, f2;
1350 f1 = (FLOATP (v1) ? XFLOAT_DATA (v1) : XINT (v1));
1351 f2 = (FLOATP (v2) ? XFLOAT_DATA (v2) : XINT (v2));
1352 TOP = (f1 == f2 ? Qt : Qnil);
1354 else
1355 TOP = (XINT (v1) == XINT (v2) ? Qt : Qnil);
1356 NEXT;
1359 CASE (Bgtr):
1361 Lisp_Object v1;
1362 BEFORE_POTENTIAL_GC ();
1363 v1 = POP;
1364 TOP = Fgtr (TOP, v1);
1365 AFTER_POTENTIAL_GC ();
1366 NEXT;
1369 CASE (Blss):
1371 Lisp_Object v1;
1372 BEFORE_POTENTIAL_GC ();
1373 v1 = POP;
1374 TOP = Flss (TOP, v1);
1375 AFTER_POTENTIAL_GC ();
1376 NEXT;
1379 CASE (Bleq):
1381 Lisp_Object v1;
1382 BEFORE_POTENTIAL_GC ();
1383 v1 = POP;
1384 TOP = Fleq (TOP, v1);
1385 AFTER_POTENTIAL_GC ();
1386 NEXT;
1389 CASE (Bgeq):
1391 Lisp_Object v1;
1392 BEFORE_POTENTIAL_GC ();
1393 v1 = POP;
1394 TOP = Fgeq (TOP, v1);
1395 AFTER_POTENTIAL_GC ();
1396 NEXT;
1399 CASE (Bdiff):
1400 BEFORE_POTENTIAL_GC ();
1401 DISCARD (1);
1402 TOP = Fminus (2, &TOP);
1403 AFTER_POTENTIAL_GC ();
1404 NEXT;
1406 CASE (Bnegate):
1408 Lisp_Object v1;
1409 v1 = TOP;
1410 if (INTEGERP (v1))
1412 XSETINT (v1, - XINT (v1));
1413 TOP = v1;
1415 else
1417 BEFORE_POTENTIAL_GC ();
1418 TOP = Fminus (1, &TOP);
1419 AFTER_POTENTIAL_GC ();
1421 NEXT;
1424 CASE (Bplus):
1425 BEFORE_POTENTIAL_GC ();
1426 DISCARD (1);
1427 TOP = Fplus (2, &TOP);
1428 AFTER_POTENTIAL_GC ();
1429 NEXT;
1431 CASE (Bmax):
1432 BEFORE_POTENTIAL_GC ();
1433 DISCARD (1);
1434 TOP = Fmax (2, &TOP);
1435 AFTER_POTENTIAL_GC ();
1436 NEXT;
1438 CASE (Bmin):
1439 BEFORE_POTENTIAL_GC ();
1440 DISCARD (1);
1441 TOP = Fmin (2, &TOP);
1442 AFTER_POTENTIAL_GC ();
1443 NEXT;
1445 CASE (Bmult):
1446 BEFORE_POTENTIAL_GC ();
1447 DISCARD (1);
1448 TOP = Ftimes (2, &TOP);
1449 AFTER_POTENTIAL_GC ();
1450 NEXT;
1452 CASE (Bquo):
1453 BEFORE_POTENTIAL_GC ();
1454 DISCARD (1);
1455 TOP = Fquo (2, &TOP);
1456 AFTER_POTENTIAL_GC ();
1457 NEXT;
1459 CASE (Brem):
1461 Lisp_Object v1;
1462 BEFORE_POTENTIAL_GC ();
1463 v1 = POP;
1464 TOP = Frem (TOP, v1);
1465 AFTER_POTENTIAL_GC ();
1466 NEXT;
1469 CASE (Bpoint):
1471 Lisp_Object v1;
1472 XSETFASTINT (v1, PT);
1473 PUSH (v1);
1474 NEXT;
1477 CASE (Bgoto_char):
1478 BEFORE_POTENTIAL_GC ();
1479 TOP = Fgoto_char (TOP);
1480 AFTER_POTENTIAL_GC ();
1481 NEXT;
1483 CASE (Binsert):
1484 BEFORE_POTENTIAL_GC ();
1485 TOP = Finsert (1, &TOP);
1486 AFTER_POTENTIAL_GC ();
1487 NEXT;
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;
1497 CASE (Bpoint_max):
1499 Lisp_Object v1;
1500 XSETFASTINT (v1, ZV);
1501 PUSH (v1);
1502 NEXT;
1505 CASE (Bpoint_min):
1507 Lisp_Object v1;
1508 XSETFASTINT (v1, BEGV);
1509 PUSH (v1);
1510 NEXT;
1513 CASE (Bchar_after):
1514 BEFORE_POTENTIAL_GC ();
1515 TOP = Fchar_after (TOP);
1516 AFTER_POTENTIAL_GC ();
1517 NEXT;
1519 CASE (Bfollowing_char):
1521 Lisp_Object v1;
1522 BEFORE_POTENTIAL_GC ();
1523 v1 = Ffollowing_char ();
1524 AFTER_POTENTIAL_GC ();
1525 PUSH (v1);
1526 NEXT;
1529 CASE (Bpreceding_char):
1531 Lisp_Object v1;
1532 BEFORE_POTENTIAL_GC ();
1533 v1 = Fprevious_char ();
1534 AFTER_POTENTIAL_GC ();
1535 PUSH (v1);
1536 NEXT;
1539 CASE (Bcurrent_column):
1541 Lisp_Object v1;
1542 BEFORE_POTENTIAL_GC ();
1543 XSETFASTINT (v1, current_column ());
1544 AFTER_POTENTIAL_GC ();
1545 PUSH (v1);
1546 NEXT;
1549 CASE (Bindent_to):
1550 BEFORE_POTENTIAL_GC ();
1551 TOP = Findent_to (TOP, Qnil);
1552 AFTER_POTENTIAL_GC ();
1553 NEXT;
1555 CASE (Beolp):
1556 PUSH (Feolp ());
1557 NEXT;
1559 CASE (Beobp):
1560 PUSH (Feobp ());
1561 NEXT;
1563 CASE (Bbolp):
1564 PUSH (Fbolp ());
1565 NEXT;
1567 CASE (Bbobp):
1568 PUSH (Fbobp ());
1569 NEXT;
1571 CASE (Bcurrent_buffer):
1572 PUSH (Fcurrent_buffer ());
1573 NEXT;
1575 CASE (Bset_buffer):
1576 BEFORE_POTENTIAL_GC ();
1577 TOP = Fset_buffer (TOP);
1578 AFTER_POTENTIAL_GC ();
1579 NEXT;
1581 CASE (Binteractive_p): /* Obsolete since 24.1. */
1582 PUSH (Finteractive_p ());
1583 NEXT;
1585 CASE (Bforward_char):
1586 BEFORE_POTENTIAL_GC ();
1587 TOP = Fforward_char (TOP);
1588 AFTER_POTENTIAL_GC ();
1589 NEXT;
1591 CASE (Bforward_word):
1592 BEFORE_POTENTIAL_GC ();
1593 TOP = Fforward_word (TOP);
1594 AFTER_POTENTIAL_GC ();
1595 NEXT;
1597 CASE (Bskip_chars_forward):
1599 Lisp_Object v1;
1600 BEFORE_POTENTIAL_GC ();
1601 v1 = POP;
1602 TOP = Fskip_chars_forward (TOP, v1);
1603 AFTER_POTENTIAL_GC ();
1604 NEXT;
1607 CASE (Bskip_chars_backward):
1609 Lisp_Object v1;
1610 BEFORE_POTENTIAL_GC ();
1611 v1 = POP;
1612 TOP = Fskip_chars_backward (TOP, v1);
1613 AFTER_POTENTIAL_GC ();
1614 NEXT;
1617 CASE (Bforward_line):
1618 BEFORE_POTENTIAL_GC ();
1619 TOP = Fforward_line (TOP);
1620 AFTER_POTENTIAL_GC ();
1621 NEXT;
1623 CASE (Bchar_syntax):
1625 int c;
1627 BEFORE_POTENTIAL_GC ();
1628 CHECK_CHARACTER (TOP);
1629 AFTER_POTENTIAL_GC ();
1630 c = XFASTINT (TOP);
1631 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
1632 MAKE_CHAR_MULTIBYTE (c);
1633 XSETFASTINT (TOP, syntax_code_spec[(int) SYNTAX (c)]);
1635 NEXT;
1637 CASE (Bbuffer_substring):
1639 Lisp_Object v1;
1640 BEFORE_POTENTIAL_GC ();
1641 v1 = POP;
1642 TOP = Fbuffer_substring (TOP, v1);
1643 AFTER_POTENTIAL_GC ();
1644 NEXT;
1647 CASE (Bdelete_region):
1649 Lisp_Object v1;
1650 BEFORE_POTENTIAL_GC ();
1651 v1 = POP;
1652 TOP = Fdelete_region (TOP, v1);
1653 AFTER_POTENTIAL_GC ();
1654 NEXT;
1657 CASE (Bnarrow_to_region):
1659 Lisp_Object v1;
1660 BEFORE_POTENTIAL_GC ();
1661 v1 = POP;
1662 TOP = Fnarrow_to_region (TOP, v1);
1663 AFTER_POTENTIAL_GC ();
1664 NEXT;
1667 CASE (Bwiden):
1668 BEFORE_POTENTIAL_GC ();
1669 PUSH (Fwiden ());
1670 AFTER_POTENTIAL_GC ();
1671 NEXT;
1673 CASE (Bend_of_line):
1674 BEFORE_POTENTIAL_GC ();
1675 TOP = Fend_of_line (TOP);
1676 AFTER_POTENTIAL_GC ();
1677 NEXT;
1679 CASE (Bset_marker):
1681 Lisp_Object v1, v2;
1682 BEFORE_POTENTIAL_GC ();
1683 v1 = POP;
1684 v2 = POP;
1685 TOP = Fset_marker (TOP, v2, v1);
1686 AFTER_POTENTIAL_GC ();
1687 NEXT;
1690 CASE (Bmatch_beginning):
1691 BEFORE_POTENTIAL_GC ();
1692 TOP = Fmatch_beginning (TOP);
1693 AFTER_POTENTIAL_GC ();
1694 NEXT;
1696 CASE (Bmatch_end):
1697 BEFORE_POTENTIAL_GC ();
1698 TOP = Fmatch_end (TOP);
1699 AFTER_POTENTIAL_GC ();
1700 NEXT;
1702 CASE (Bupcase):
1703 BEFORE_POTENTIAL_GC ();
1704 TOP = Fupcase (TOP);
1705 AFTER_POTENTIAL_GC ();
1706 NEXT;
1708 CASE (Bdowncase):
1709 BEFORE_POTENTIAL_GC ();
1710 TOP = Fdowncase (TOP);
1711 AFTER_POTENTIAL_GC ();
1712 NEXT;
1714 CASE (Bstringeqlsign):
1716 Lisp_Object v1;
1717 BEFORE_POTENTIAL_GC ();
1718 v1 = POP;
1719 TOP = Fstring_equal (TOP, v1);
1720 AFTER_POTENTIAL_GC ();
1721 NEXT;
1724 CASE (Bstringlss):
1726 Lisp_Object v1;
1727 BEFORE_POTENTIAL_GC ();
1728 v1 = POP;
1729 TOP = Fstring_lessp (TOP, v1);
1730 AFTER_POTENTIAL_GC ();
1731 NEXT;
1734 CASE (Bequal):
1736 Lisp_Object v1;
1737 v1 = POP;
1738 TOP = Fequal (TOP, v1);
1739 NEXT;
1742 CASE (Bnthcdr):
1744 Lisp_Object v1;
1745 BEFORE_POTENTIAL_GC ();
1746 v1 = POP;
1747 TOP = Fnthcdr (TOP, v1);
1748 AFTER_POTENTIAL_GC ();
1749 NEXT;
1752 CASE (Belt):
1754 Lisp_Object v1, v2;
1755 if (CONSP (TOP))
1757 /* Exchange args and then do nth. */
1758 EMACS_INT n;
1759 BEFORE_POTENTIAL_GC ();
1760 v2 = POP;
1761 v1 = TOP;
1762 CHECK_NUMBER (v2);
1763 AFTER_POTENTIAL_GC ();
1764 n = XINT (v2);
1765 immediate_quit = 1;
1766 while (--n >= 0 && CONSP (v1))
1767 v1 = XCDR (v1);
1768 immediate_quit = 0;
1769 TOP = CAR (v1);
1771 else
1773 BEFORE_POTENTIAL_GC ();
1774 v1 = POP;
1775 TOP = Felt (TOP, v1);
1776 AFTER_POTENTIAL_GC ();
1778 NEXT;
1781 CASE (Bmember):
1783 Lisp_Object v1;
1784 BEFORE_POTENTIAL_GC ();
1785 v1 = POP;
1786 TOP = Fmember (TOP, v1);
1787 AFTER_POTENTIAL_GC ();
1788 NEXT;
1791 CASE (Bassq):
1793 Lisp_Object v1;
1794 BEFORE_POTENTIAL_GC ();
1795 v1 = POP;
1796 TOP = Fassq (TOP, v1);
1797 AFTER_POTENTIAL_GC ();
1798 NEXT;
1801 CASE (Bnreverse):
1802 BEFORE_POTENTIAL_GC ();
1803 TOP = Fnreverse (TOP);
1804 AFTER_POTENTIAL_GC ();
1805 NEXT;
1807 CASE (Bsetcar):
1809 Lisp_Object v1;
1810 BEFORE_POTENTIAL_GC ();
1811 v1 = POP;
1812 TOP = Fsetcar (TOP, v1);
1813 AFTER_POTENTIAL_GC ();
1814 NEXT;
1817 CASE (Bsetcdr):
1819 Lisp_Object v1;
1820 BEFORE_POTENTIAL_GC ();
1821 v1 = POP;
1822 TOP = Fsetcdr (TOP, v1);
1823 AFTER_POTENTIAL_GC ();
1824 NEXT;
1827 CASE (Bcar_safe):
1829 Lisp_Object v1;
1830 v1 = TOP;
1831 TOP = CAR_SAFE (v1);
1832 NEXT;
1835 CASE (Bcdr_safe):
1837 Lisp_Object v1;
1838 v1 = TOP;
1839 TOP = CDR_SAFE (v1);
1840 NEXT;
1843 CASE (Bnconc):
1844 BEFORE_POTENTIAL_GC ();
1845 DISCARD (1);
1846 TOP = Fnconc (2, &TOP);
1847 AFTER_POTENTIAL_GC ();
1848 NEXT;
1850 CASE (Bnumberp):
1851 TOP = (NUMBERP (TOP) ? Qt : Qnil);
1852 NEXT;
1854 CASE (Bintegerp):
1855 TOP = INTEGERP (TOP) ? Qt : Qnil;
1856 NEXT;
1858 #ifdef BYTE_CODE_SAFE
1859 /* These are intentionally written using 'case' syntax,
1860 because they are incompatible with the threaded
1861 interpreter. */
1863 case Bset_mark:
1864 BEFORE_POTENTIAL_GC ();
1865 error ("set-mark is an obsolete bytecode");
1866 AFTER_POTENTIAL_GC ();
1867 break;
1868 case Bscan_buffer:
1869 BEFORE_POTENTIAL_GC ();
1870 error ("scan-buffer is an obsolete bytecode");
1871 AFTER_POTENTIAL_GC ();
1872 break;
1873 #endif
1875 CASE_ABORT:
1876 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1877 for that instead. */
1878 /* CASE (Bstack_ref): */
1879 error ("Invalid byte opcode");
1881 /* Handy byte-codes for lexical binding. */
1882 CASE (Bstack_ref1):
1883 CASE (Bstack_ref2):
1884 CASE (Bstack_ref3):
1885 CASE (Bstack_ref4):
1886 CASE (Bstack_ref5):
1888 Lisp_Object *ptr = top - (op - Bstack_ref);
1889 PUSH (*ptr);
1890 NEXT;
1892 CASE (Bstack_ref6):
1894 Lisp_Object *ptr = top - (FETCH);
1895 PUSH (*ptr);
1896 NEXT;
1898 CASE (Bstack_ref7):
1900 Lisp_Object *ptr = top - (FETCH2);
1901 PUSH (*ptr);
1902 NEXT;
1904 CASE (Bstack_set):
1905 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1907 Lisp_Object *ptr = top - (FETCH);
1908 *ptr = POP;
1909 NEXT;
1911 CASE (Bstack_set2):
1913 Lisp_Object *ptr = top - (FETCH2);
1914 *ptr = POP;
1915 NEXT;
1917 CASE (BdiscardN):
1918 op = FETCH;
1919 if (op & 0x80)
1921 op &= 0x7F;
1922 top[-op] = TOP;
1924 DISCARD (op);
1925 NEXT;
1927 CASE_DEFAULT
1928 CASE (Bconstant):
1929 #ifdef BYTE_CODE_SAFE
1930 if (op < Bconstant)
1932 emacs_abort ();
1934 if ((op -= Bconstant) >= const_length)
1936 emacs_abort ();
1938 PUSH (vectorp[op]);
1939 #else
1940 PUSH (vectorp[op - Bconstant]);
1941 #endif
1942 NEXT;
1946 exit:
1948 byte_stack_list = byte_stack_list->next;
1950 /* Binds and unbinds are supposed to be compiled balanced. */
1951 if (SPECPDL_INDEX () != count)
1952 #ifdef BYTE_CODE_SAFE
1953 error ("binding stack not balanced (serious byte compiler bug)");
1954 #else
1955 emacs_abort ();
1956 #endif
1958 return result;
1961 void
1962 syms_of_bytecode (void)
1964 DEFSYM (Qbytecode, "byte-code");
1966 defsubr (&Sbyte_code);
1968 #ifdef BYTE_CODE_METER
1970 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter,
1971 doc: /* A vector of vectors which holds a histogram of byte-code usage.
1972 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1973 opcode CODE has been executed.
1974 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1975 indicates how many times the byte opcodes CODE1 and CODE2 have been
1976 executed in succession. */);
1978 DEFVAR_BOOL ("byte-metering-on", byte_metering_on,
1979 doc: /* If non-nil, keep profiling information on byte code usage.
1980 The variable byte-code-meter indicates how often each byte opcode is used.
1981 If a symbol has a property named `byte-code-meter' whose value is an
1982 integer, it is incremented each time that symbol's function is called. */);
1984 byte_metering_on = 0;
1985 Vbyte_code_meter = Fmake_vector (make_number (256), make_number (0));
1986 DEFSYM (Qbyte_code_meter, "byte-code-meter");
1988 int i = 256;
1989 while (i--)
1990 ASET (Vbyte_code_meter, i,
1991 Fmake_vector (make_number (256), make_number (0)));
1993 #endif