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