merge from trunk
[emacs.git] / src / bytecode.c
blob1be3e5c6188ec433ac1299ed10c909b828d1df3e
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 __STRICT_ANSI__ \
63 && !defined BYTE_CODE_SAFE && !defined BYTE_CODE_METER)
64 #define BYTE_CODE_THREADED
65 #endif
68 #ifdef BYTE_CODE_METER
70 Lisp_Object Qbyte_code_meter;
71 #define METER_2(code1, code2) AREF (AREF (Vbyte_code_meter, code1), code2)
72 #define METER_1(code) METER_2 (0, code)
74 #define METER_CODE(last_code, this_code) \
75 { \
76 if (byte_metering_on) \
77 { \
78 if (XFASTINT (METER_1 (this_code)) < MOST_POSITIVE_FIXNUM) \
79 XSETFASTINT (METER_1 (this_code), \
80 XFASTINT (METER_1 (this_code)) + 1); \
81 if (last_code \
82 && (XFASTINT (METER_2 (last_code, this_code)) \
83 < MOST_POSITIVE_FIXNUM)) \
84 XSETFASTINT (METER_2 (last_code, this_code), \
85 XFASTINT (METER_2 (last_code, this_code)) + 1); \
86 } \
89 #endif /* BYTE_CODE_METER */
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
292 B__dummy__ = 0 /* Pacify C89. */
295 /* Whether to maintain a `top' and `bottom' field in the stack frame. */
296 #define BYTE_MAINTAIN_TOP (BYTE_CODE_SAFE || BYTE_MARK_STACK)
298 /* Structure describing a value stack used during byte-code execution
299 in Fbyte_code. */
301 struct byte_stack
303 /* Program counter. This points into the byte_string below
304 and is relocated when that string is relocated. */
305 const unsigned char *pc;
307 /* Top and bottom of stack. The bottom points to an area of memory
308 allocated with alloca in Fbyte_code. */
309 #if BYTE_MAINTAIN_TOP
310 Lisp_Object *top, *bottom;
311 #endif
313 /* The string containing the byte-code, and its current address.
314 Storing this here protects it from GC because mark_byte_stack
315 marks it. */
316 Lisp_Object byte_string;
317 const unsigned char *byte_string_start;
319 #if BYTE_MARK_STACK
320 /* The vector of constants used during byte-code execution. Storing
321 this here protects it from GC because mark_byte_stack marks it. */
322 Lisp_Object constants;
323 #endif
325 /* Next entry in byte_stack_list. */
326 struct byte_stack *next;
329 /* A list of currently active byte-code execution value stacks.
330 Fbyte_code adds an entry to the head of this list before it starts
331 processing byte-code, and it removed the entry again when it is
332 done. Signaling an error truncates the list analogous to
333 gcprolist. */
335 /* struct byte_stack *byte_stack_list; */
338 /* Mark objects on byte_stack_list. Called during GC. */
340 #if BYTE_MARK_STACK
341 void
342 mark_byte_stack (struct byte_stack *stack)
344 Lisp_Object *obj;
346 for (; stack; stack = stack->next)
348 /* If STACK->top is null here, this means there's an opcode in
349 Fbyte_code that wasn't expected to GC, but did. To find out
350 which opcode this is, record the value of `stack', and walk
351 up the stack in a debugger, stopping in frames of Fbyte_code.
352 The culprit is found in the frame of Fbyte_code where the
353 address of its local variable `stack' is equal to the
354 recorded value of `stack' here. */
355 eassert (stack->top);
357 for (obj = stack->bottom; obj <= stack->top; ++obj)
358 mark_object (*obj);
360 mark_object (stack->byte_string);
361 mark_object (stack->constants);
364 #endif
366 /* Unmark objects in the stacks on byte_stack_list. Relocate program
367 counters. Called when GC has completed. */
369 void
370 unmark_byte_stack (struct byte_stack *stack)
372 for (; 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 list2 (Fcons (make_number (mandatory),
573 rest ? Qand_rest : make_number (nonrest)),
574 make_number (nargs)));
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 list2 (Fcons (make_number (mandatory), make_number (nonrest)),
594 make_number (nargs)));
596 else if (! NILP (args_template))
597 /* We should push some arguments on the stack. */
599 error ("Unknown args template!");
602 while (1)
604 #ifdef BYTE_CODE_SAFE
605 if (top > stacke)
606 emacs_abort ();
607 else if (top < stack.bottom - 1)
608 emacs_abort ();
609 #endif
611 #ifdef BYTE_CODE_METER
612 prev_op = this_op;
613 this_op = op = FETCH;
614 METER_CODE (prev_op, op);
615 #else
616 #ifndef BYTE_CODE_THREADED
617 op = FETCH;
618 #endif
619 #endif
621 /* The interpreter can be compiled one of two ways: as an
622 ordinary switch-based interpreter, or as a threaded
623 interpreter. The threaded interpreter relies on GCC's
624 computed goto extension, so it is not available everywhere.
625 Threading provides a performance boost. These macros are how
626 we allow the code to be compiled both ways. */
627 #ifdef BYTE_CODE_THREADED
628 /* The CASE macro introduces an instruction's body. It is
629 either a label or a case label. */
630 #define CASE(OP) insn_ ## OP
631 /* NEXT is invoked at the end of an instruction to go to the
632 next instruction. It is either a computed goto, or a
633 plain break. */
634 #define NEXT goto *(targets[op = FETCH])
635 /* FIRST is like NEXT, but is only used at the start of the
636 interpreter body. In the switch-based interpreter it is the
637 switch, so the threaded definition must include a semicolon. */
638 #define FIRST NEXT;
639 /* Most cases are labeled with the CASE macro, above.
640 CASE_DEFAULT is one exception; it is used if the interpreter
641 being built requires a default case. The threaded
642 interpreter does not, because the dispatch table is
643 completely filled. */
644 #define CASE_DEFAULT
645 /* This introduces an instruction that is known to call abort. */
646 #define CASE_ABORT CASE (Bstack_ref): CASE (default)
647 #else
648 /* See above for the meaning of the various defines. */
649 #define CASE(OP) case OP
650 #define NEXT break
651 #define FIRST switch (op)
652 #define CASE_DEFAULT case 255: default:
653 #define CASE_ABORT case 0
654 #endif
656 #ifdef BYTE_CODE_THREADED
658 /* A convenience define that saves us a lot of typing and makes
659 the table clearer. */
660 #define LABEL(OP) [OP] = &&insn_ ## OP
662 #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
663 # pragma GCC diagnostic push
664 # pragma GCC diagnostic ignored "-Woverride-init"
665 #elif defined __clang__
666 # pragma GCC diagnostic push
667 # pragma GCC diagnostic ignored "-Winitializer-overrides"
668 #endif
670 /* This is the dispatch table for the threaded interpreter. */
671 static const void *const targets[256] =
673 [0 ... (Bconstant - 1)] = &&insn_default,
674 [Bconstant ... 255] = &&insn_Bconstant,
676 #define DEFINE(name, value) LABEL (name) ,
677 BYTE_CODES
678 #undef DEFINE
681 #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) || defined __clang__
682 # pragma GCC diagnostic pop
683 #endif
685 #endif
688 FIRST
690 CASE (Bvarref7):
691 op = FETCH2;
692 goto varref;
694 CASE (Bvarref):
695 CASE (Bvarref1):
696 CASE (Bvarref2):
697 CASE (Bvarref3):
698 CASE (Bvarref4):
699 CASE (Bvarref5):
700 op = op - Bvarref;
701 goto varref;
703 /* This seems to be the most frequently executed byte-code
704 among the Bvarref's, so avoid a goto here. */
705 CASE (Bvarref6):
706 op = FETCH;
707 varref:
709 Lisp_Object v1, v2;
711 v1 = vectorp[op];
712 if (SYMBOLP (v1))
714 if (XSYMBOL (v1)->redirect != SYMBOL_PLAINVAL
715 || (v2 = SYMBOL_VAL (XSYMBOL (v1)),
716 EQ (v2, Qunbound)))
718 BEFORE_POTENTIAL_GC ();
719 v2 = Fsymbol_value (v1);
720 AFTER_POTENTIAL_GC ();
723 else
725 BEFORE_POTENTIAL_GC ();
726 v2 = Fsymbol_value (v1);
727 AFTER_POTENTIAL_GC ();
729 PUSH (v2);
730 NEXT;
733 CASE (Bgotoifnil):
735 Lisp_Object v1;
736 MAYBE_GC ();
737 op = FETCH2;
738 v1 = POP;
739 if (NILP (v1))
741 BYTE_CODE_QUIT;
742 CHECK_RANGE (op);
743 stack.pc = stack.byte_string_start + op;
745 NEXT;
748 CASE (Bcar):
750 Lisp_Object v1;
751 v1 = TOP;
752 if (CONSP (v1))
753 TOP = XCAR (v1);
754 else if (NILP (v1))
755 TOP = Qnil;
756 else
758 BEFORE_POTENTIAL_GC ();
759 wrong_type_argument (Qlistp, v1);
761 NEXT;
764 CASE (Beq):
766 Lisp_Object v1;
767 v1 = POP;
768 TOP = EQ (v1, TOP) ? Qt : Qnil;
769 NEXT;
772 CASE (Bmemq):
774 Lisp_Object v1;
775 BEFORE_POTENTIAL_GC ();
776 v1 = POP;
777 TOP = Fmemq (TOP, v1);
778 AFTER_POTENTIAL_GC ();
779 NEXT;
782 CASE (Bcdr):
784 Lisp_Object v1;
785 v1 = TOP;
786 if (CONSP (v1))
787 TOP = XCDR (v1);
788 else if (NILP (v1))
789 TOP = Qnil;
790 else
792 BEFORE_POTENTIAL_GC ();
793 wrong_type_argument (Qlistp, v1);
795 NEXT;
798 CASE (Bvarset):
799 CASE (Bvarset1):
800 CASE (Bvarset2):
801 CASE (Bvarset3):
802 CASE (Bvarset4):
803 CASE (Bvarset5):
804 op -= Bvarset;
805 goto varset;
807 CASE (Bvarset7):
808 op = FETCH2;
809 goto varset;
811 CASE (Bvarset6):
812 op = FETCH;
813 varset:
815 Lisp_Object sym, val;
817 sym = vectorp[op];
818 val = TOP;
820 /* Inline the most common case. */
821 if (SYMBOLP (sym)
822 && !EQ (val, Qunbound)
823 && !XSYMBOL (sym)->redirect
824 && !SYMBOL_CONSTANT_P (sym))
825 SET_SYMBOL_VAL (XSYMBOL (sym), val);
826 else
828 BEFORE_POTENTIAL_GC ();
829 set_internal (sym, val, Qnil, 0);
830 AFTER_POTENTIAL_GC ();
833 (void) POP;
834 NEXT;
836 CASE (Bdup):
838 Lisp_Object v1;
839 v1 = TOP;
840 PUSH (v1);
841 NEXT;
844 /* ------------------ */
846 CASE (Bvarbind6):
847 op = FETCH;
848 goto varbind;
850 CASE (Bvarbind7):
851 op = FETCH2;
852 goto varbind;
854 CASE (Bvarbind):
855 CASE (Bvarbind1):
856 CASE (Bvarbind2):
857 CASE (Bvarbind3):
858 CASE (Bvarbind4):
859 CASE (Bvarbind5):
860 op -= Bvarbind;
861 varbind:
862 /* Specbind can signal and thus GC. */
863 BEFORE_POTENTIAL_GC ();
864 specbind (vectorp[op], POP);
865 AFTER_POTENTIAL_GC ();
866 NEXT;
868 CASE (Bcall6):
869 op = FETCH;
870 goto docall;
872 CASE (Bcall7):
873 op = FETCH2;
874 goto docall;
876 CASE (Bcall):
877 CASE (Bcall1):
878 CASE (Bcall2):
879 CASE (Bcall3):
880 CASE (Bcall4):
881 CASE (Bcall5):
882 op -= Bcall;
883 docall:
885 BEFORE_POTENTIAL_GC ();
886 DISCARD (op);
887 #ifdef BYTE_CODE_METER
888 if (byte_metering_on && SYMBOLP (TOP))
890 Lisp_Object v1, v2;
892 v1 = TOP;
893 v2 = Fget (v1, Qbyte_code_meter);
894 if (INTEGERP (v2)
895 && XINT (v2) < MOST_POSITIVE_FIXNUM)
897 XSETINT (v2, XINT (v2) + 1);
898 Fput (v1, Qbyte_code_meter, v2);
901 #endif
902 TOP = Ffuncall (op + 1, &TOP);
903 AFTER_POTENTIAL_GC ();
904 NEXT;
907 CASE (Bunbind6):
908 op = FETCH;
909 goto dounbind;
911 CASE (Bunbind7):
912 op = FETCH2;
913 goto dounbind;
915 CASE (Bunbind):
916 CASE (Bunbind1):
917 CASE (Bunbind2):
918 CASE (Bunbind3):
919 CASE (Bunbind4):
920 CASE (Bunbind5):
921 op -= Bunbind;
922 dounbind:
923 BEFORE_POTENTIAL_GC ();
924 unbind_to (SPECPDL_INDEX () - op, Qnil);
925 AFTER_POTENTIAL_GC ();
926 NEXT;
928 CASE (Bunbind_all): /* Obsolete. Never used. */
929 /* To unbind back to the beginning of this frame. Not used yet,
930 but will be needed for tail-recursion elimination. */
931 BEFORE_POTENTIAL_GC ();
932 unbind_to (count, Qnil);
933 AFTER_POTENTIAL_GC ();
934 NEXT;
936 CASE (Bgoto):
937 MAYBE_GC ();
938 BYTE_CODE_QUIT;
939 op = FETCH2; /* pc = FETCH2 loses since FETCH2 contains pc++ */
940 CHECK_RANGE (op);
941 stack.pc = stack.byte_string_start + op;
942 NEXT;
944 CASE (Bgotoifnonnil):
946 Lisp_Object v1;
947 MAYBE_GC ();
948 op = FETCH2;
949 v1 = POP;
950 if (!NILP (v1))
952 BYTE_CODE_QUIT;
953 CHECK_RANGE (op);
954 stack.pc = stack.byte_string_start + op;
956 NEXT;
959 CASE (Bgotoifnilelsepop):
960 MAYBE_GC ();
961 op = FETCH2;
962 if (NILP (TOP))
964 BYTE_CODE_QUIT;
965 CHECK_RANGE (op);
966 stack.pc = stack.byte_string_start + op;
968 else DISCARD (1);
969 NEXT;
971 CASE (Bgotoifnonnilelsepop):
972 MAYBE_GC ();
973 op = FETCH2;
974 if (!NILP (TOP))
976 BYTE_CODE_QUIT;
977 CHECK_RANGE (op);
978 stack.pc = stack.byte_string_start + op;
980 else DISCARD (1);
981 NEXT;
983 CASE (BRgoto):
984 MAYBE_GC ();
985 BYTE_CODE_QUIT;
986 stack.pc += (int) *stack.pc - 127;
987 NEXT;
989 CASE (BRgotoifnil):
991 Lisp_Object v1;
992 MAYBE_GC ();
993 v1 = POP;
994 if (NILP (v1))
996 BYTE_CODE_QUIT;
997 stack.pc += (int) *stack.pc - 128;
999 stack.pc++;
1000 NEXT;
1003 CASE (BRgotoifnonnil):
1005 Lisp_Object v1;
1006 MAYBE_GC ();
1007 v1 = POP;
1008 if (!NILP (v1))
1010 BYTE_CODE_QUIT;
1011 stack.pc += (int) *stack.pc - 128;
1013 stack.pc++;
1014 NEXT;
1017 CASE (BRgotoifnilelsepop):
1018 MAYBE_GC ();
1019 op = *stack.pc++;
1020 if (NILP (TOP))
1022 BYTE_CODE_QUIT;
1023 stack.pc += op - 128;
1025 else DISCARD (1);
1026 NEXT;
1028 CASE (BRgotoifnonnilelsepop):
1029 MAYBE_GC ();
1030 op = *stack.pc++;
1031 if (!NILP (TOP))
1033 BYTE_CODE_QUIT;
1034 stack.pc += op - 128;
1036 else DISCARD (1);
1037 NEXT;
1039 CASE (Breturn):
1040 result = POP;
1041 goto exit;
1043 CASE (Bdiscard):
1044 DISCARD (1);
1045 NEXT;
1047 CASE (Bconstant2):
1048 PUSH (vectorp[FETCH2]);
1049 NEXT;
1051 CASE (Bsave_excursion):
1052 record_unwind_protect (save_excursion_restore,
1053 save_excursion_save ());
1054 NEXT;
1056 CASE (Bsave_current_buffer): /* Obsolete since ??. */
1057 CASE (Bsave_current_buffer_1):
1058 record_unwind_current_buffer ();
1059 NEXT;
1061 CASE (Bsave_window_excursion): /* Obsolete since 24.1. */
1063 ptrdiff_t count1 = SPECPDL_INDEX ();
1064 record_unwind_protect (restore_window_configuration,
1065 Fcurrent_window_configuration (Qnil));
1066 BEFORE_POTENTIAL_GC ();
1067 TOP = Fprogn (TOP);
1068 unbind_to (count1, TOP);
1069 AFTER_POTENTIAL_GC ();
1070 NEXT;
1073 CASE (Bsave_restriction):
1074 record_unwind_protect (save_restriction_restore,
1075 save_restriction_save ());
1076 NEXT;
1078 CASE (Bcatch): /* FIXME: ill-suited for lexbind. */
1080 Lisp_Object v1;
1081 BEFORE_POTENTIAL_GC ();
1082 v1 = POP;
1083 TOP = internal_catch (TOP, eval_sub, v1);
1084 AFTER_POTENTIAL_GC ();
1085 NEXT;
1088 CASE (Bunwind_protect): /* FIXME: avoid closure for lexbind. */
1089 record_unwind_protect (unwind_body, POP);
1090 NEXT;
1092 CASE (Bcondition_case): /* FIXME: ill-suited for lexbind. */
1094 Lisp_Object handlers, body;
1095 handlers = POP;
1096 body = POP;
1097 BEFORE_POTENTIAL_GC ();
1098 TOP = internal_lisp_condition_case (TOP, body, handlers);
1099 AFTER_POTENTIAL_GC ();
1100 NEXT;
1103 CASE (Btemp_output_buffer_setup): /* Obsolete since 24.1. */
1104 BEFORE_POTENTIAL_GC ();
1105 CHECK_STRING (TOP);
1106 temp_output_buffer_setup (SSDATA (TOP));
1107 AFTER_POTENTIAL_GC ();
1108 TOP = Vstandard_output;
1109 NEXT;
1111 CASE (Btemp_output_buffer_show): /* Obsolete since 24.1. */
1113 Lisp_Object v1;
1114 BEFORE_POTENTIAL_GC ();
1115 v1 = POP;
1116 temp_output_buffer_show (TOP);
1117 TOP = v1;
1118 /* pop binding of standard-output */
1119 unbind_to (SPECPDL_INDEX () - 1, Qnil);
1120 AFTER_POTENTIAL_GC ();
1121 NEXT;
1124 CASE (Bnth):
1126 Lisp_Object v1, v2;
1127 EMACS_INT n;
1128 BEFORE_POTENTIAL_GC ();
1129 v1 = POP;
1130 v2 = TOP;
1131 CHECK_NUMBER (v2);
1132 n = XINT (v2);
1133 immediate_quit = 1;
1134 while (--n >= 0 && CONSP (v1))
1135 v1 = XCDR (v1);
1136 immediate_quit = 0;
1137 TOP = CAR (v1);
1138 AFTER_POTENTIAL_GC ();
1139 NEXT;
1142 CASE (Bsymbolp):
1143 TOP = SYMBOLP (TOP) ? Qt : Qnil;
1144 NEXT;
1146 CASE (Bconsp):
1147 TOP = CONSP (TOP) ? Qt : Qnil;
1148 NEXT;
1150 CASE (Bstringp):
1151 TOP = STRINGP (TOP) ? Qt : Qnil;
1152 NEXT;
1154 CASE (Blistp):
1155 TOP = CONSP (TOP) || NILP (TOP) ? Qt : Qnil;
1156 NEXT;
1158 CASE (Bnot):
1159 TOP = NILP (TOP) ? Qt : Qnil;
1160 NEXT;
1162 CASE (Bcons):
1164 Lisp_Object v1;
1165 v1 = POP;
1166 TOP = Fcons (TOP, v1);
1167 NEXT;
1170 CASE (Blist1):
1171 TOP = list1 (TOP);
1172 NEXT;
1174 CASE (Blist2):
1176 Lisp_Object v1;
1177 v1 = POP;
1178 TOP = list2 (TOP, v1);
1179 NEXT;
1182 CASE (Blist3):
1183 DISCARD (2);
1184 TOP = Flist (3, &TOP);
1185 NEXT;
1187 CASE (Blist4):
1188 DISCARD (3);
1189 TOP = Flist (4, &TOP);
1190 NEXT;
1192 CASE (BlistN):
1193 op = FETCH;
1194 DISCARD (op - 1);
1195 TOP = Flist (op, &TOP);
1196 NEXT;
1198 CASE (Blength):
1199 BEFORE_POTENTIAL_GC ();
1200 TOP = Flength (TOP);
1201 AFTER_POTENTIAL_GC ();
1202 NEXT;
1204 CASE (Baref):
1206 Lisp_Object v1;
1207 BEFORE_POTENTIAL_GC ();
1208 v1 = POP;
1209 TOP = Faref (TOP, v1);
1210 AFTER_POTENTIAL_GC ();
1211 NEXT;
1214 CASE (Baset):
1216 Lisp_Object v1, v2;
1217 BEFORE_POTENTIAL_GC ();
1218 v2 = POP; v1 = POP;
1219 TOP = Faset (TOP, v1, v2);
1220 AFTER_POTENTIAL_GC ();
1221 NEXT;
1224 CASE (Bsymbol_value):
1225 BEFORE_POTENTIAL_GC ();
1226 TOP = Fsymbol_value (TOP);
1227 AFTER_POTENTIAL_GC ();
1228 NEXT;
1230 CASE (Bsymbol_function):
1231 BEFORE_POTENTIAL_GC ();
1232 TOP = Fsymbol_function (TOP);
1233 AFTER_POTENTIAL_GC ();
1234 NEXT;
1236 CASE (Bset):
1238 Lisp_Object v1;
1239 BEFORE_POTENTIAL_GC ();
1240 v1 = POP;
1241 TOP = Fset (TOP, v1);
1242 AFTER_POTENTIAL_GC ();
1243 NEXT;
1246 CASE (Bfset):
1248 Lisp_Object v1;
1249 BEFORE_POTENTIAL_GC ();
1250 v1 = POP;
1251 TOP = Ffset (TOP, v1);
1252 AFTER_POTENTIAL_GC ();
1253 NEXT;
1256 CASE (Bget):
1258 Lisp_Object v1;
1259 BEFORE_POTENTIAL_GC ();
1260 v1 = POP;
1261 TOP = Fget (TOP, v1);
1262 AFTER_POTENTIAL_GC ();
1263 NEXT;
1266 CASE (Bsubstring):
1268 Lisp_Object v1, v2;
1269 BEFORE_POTENTIAL_GC ();
1270 v2 = POP; v1 = POP;
1271 TOP = Fsubstring (TOP, v1, v2);
1272 AFTER_POTENTIAL_GC ();
1273 NEXT;
1276 CASE (Bconcat2):
1277 BEFORE_POTENTIAL_GC ();
1278 DISCARD (1);
1279 TOP = Fconcat (2, &TOP);
1280 AFTER_POTENTIAL_GC ();
1281 NEXT;
1283 CASE (Bconcat3):
1284 BEFORE_POTENTIAL_GC ();
1285 DISCARD (2);
1286 TOP = Fconcat (3, &TOP);
1287 AFTER_POTENTIAL_GC ();
1288 NEXT;
1290 CASE (Bconcat4):
1291 BEFORE_POTENTIAL_GC ();
1292 DISCARD (3);
1293 TOP = Fconcat (4, &TOP);
1294 AFTER_POTENTIAL_GC ();
1295 NEXT;
1297 CASE (BconcatN):
1298 op = FETCH;
1299 BEFORE_POTENTIAL_GC ();
1300 DISCARD (op - 1);
1301 TOP = Fconcat (op, &TOP);
1302 AFTER_POTENTIAL_GC ();
1303 NEXT;
1305 CASE (Bsub1):
1307 Lisp_Object v1;
1308 v1 = TOP;
1309 if (INTEGERP (v1))
1311 XSETINT (v1, XINT (v1) - 1);
1312 TOP = v1;
1314 else
1316 BEFORE_POTENTIAL_GC ();
1317 TOP = Fsub1 (v1);
1318 AFTER_POTENTIAL_GC ();
1320 NEXT;
1323 CASE (Badd1):
1325 Lisp_Object v1;
1326 v1 = TOP;
1327 if (INTEGERP (v1))
1329 XSETINT (v1, XINT (v1) + 1);
1330 TOP = v1;
1332 else
1334 BEFORE_POTENTIAL_GC ();
1335 TOP = Fadd1 (v1);
1336 AFTER_POTENTIAL_GC ();
1338 NEXT;
1341 CASE (Beqlsign):
1343 Lisp_Object v1, v2;
1344 BEFORE_POTENTIAL_GC ();
1345 v2 = POP; v1 = TOP;
1346 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1);
1347 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2);
1348 AFTER_POTENTIAL_GC ();
1349 if (FLOATP (v1) || FLOATP (v2))
1351 double f1, f2;
1353 f1 = (FLOATP (v1) ? XFLOAT_DATA (v1) : XINT (v1));
1354 f2 = (FLOATP (v2) ? XFLOAT_DATA (v2) : XINT (v2));
1355 TOP = (f1 == f2 ? Qt : Qnil);
1357 else
1358 TOP = (XINT (v1) == XINT (v2) ? Qt : Qnil);
1359 NEXT;
1362 CASE (Bgtr):
1364 Lisp_Object v1;
1365 BEFORE_POTENTIAL_GC ();
1366 v1 = POP;
1367 TOP = Fgtr (TOP, v1);
1368 AFTER_POTENTIAL_GC ();
1369 NEXT;
1372 CASE (Blss):
1374 Lisp_Object v1;
1375 BEFORE_POTENTIAL_GC ();
1376 v1 = POP;
1377 TOP = Flss (TOP, v1);
1378 AFTER_POTENTIAL_GC ();
1379 NEXT;
1382 CASE (Bleq):
1384 Lisp_Object v1;
1385 BEFORE_POTENTIAL_GC ();
1386 v1 = POP;
1387 TOP = Fleq (TOP, v1);
1388 AFTER_POTENTIAL_GC ();
1389 NEXT;
1392 CASE (Bgeq):
1394 Lisp_Object v1;
1395 BEFORE_POTENTIAL_GC ();
1396 v1 = POP;
1397 TOP = Fgeq (TOP, v1);
1398 AFTER_POTENTIAL_GC ();
1399 NEXT;
1402 CASE (Bdiff):
1403 BEFORE_POTENTIAL_GC ();
1404 DISCARD (1);
1405 TOP = Fminus (2, &TOP);
1406 AFTER_POTENTIAL_GC ();
1407 NEXT;
1409 CASE (Bnegate):
1411 Lisp_Object v1;
1412 v1 = TOP;
1413 if (INTEGERP (v1))
1415 XSETINT (v1, - XINT (v1));
1416 TOP = v1;
1418 else
1420 BEFORE_POTENTIAL_GC ();
1421 TOP = Fminus (1, &TOP);
1422 AFTER_POTENTIAL_GC ();
1424 NEXT;
1427 CASE (Bplus):
1428 BEFORE_POTENTIAL_GC ();
1429 DISCARD (1);
1430 TOP = Fplus (2, &TOP);
1431 AFTER_POTENTIAL_GC ();
1432 NEXT;
1434 CASE (Bmax):
1435 BEFORE_POTENTIAL_GC ();
1436 DISCARD (1);
1437 TOP = Fmax (2, &TOP);
1438 AFTER_POTENTIAL_GC ();
1439 NEXT;
1441 CASE (Bmin):
1442 BEFORE_POTENTIAL_GC ();
1443 DISCARD (1);
1444 TOP = Fmin (2, &TOP);
1445 AFTER_POTENTIAL_GC ();
1446 NEXT;
1448 CASE (Bmult):
1449 BEFORE_POTENTIAL_GC ();
1450 DISCARD (1);
1451 TOP = Ftimes (2, &TOP);
1452 AFTER_POTENTIAL_GC ();
1453 NEXT;
1455 CASE (Bquo):
1456 BEFORE_POTENTIAL_GC ();
1457 DISCARD (1);
1458 TOP = Fquo (2, &TOP);
1459 AFTER_POTENTIAL_GC ();
1460 NEXT;
1462 CASE (Brem):
1464 Lisp_Object v1;
1465 BEFORE_POTENTIAL_GC ();
1466 v1 = POP;
1467 TOP = Frem (TOP, v1);
1468 AFTER_POTENTIAL_GC ();
1469 NEXT;
1472 CASE (Bpoint):
1474 Lisp_Object v1;
1475 XSETFASTINT (v1, PT);
1476 PUSH (v1);
1477 NEXT;
1480 CASE (Bgoto_char):
1481 BEFORE_POTENTIAL_GC ();
1482 TOP = Fgoto_char (TOP);
1483 AFTER_POTENTIAL_GC ();
1484 NEXT;
1486 CASE (Binsert):
1487 BEFORE_POTENTIAL_GC ();
1488 TOP = Finsert (1, &TOP);
1489 AFTER_POTENTIAL_GC ();
1490 NEXT;
1492 CASE (BinsertN):
1493 op = FETCH;
1494 BEFORE_POTENTIAL_GC ();
1495 DISCARD (op - 1);
1496 TOP = Finsert (op, &TOP);
1497 AFTER_POTENTIAL_GC ();
1498 NEXT;
1500 CASE (Bpoint_max):
1502 Lisp_Object v1;
1503 XSETFASTINT (v1, ZV);
1504 PUSH (v1);
1505 NEXT;
1508 CASE (Bpoint_min):
1510 Lisp_Object v1;
1511 XSETFASTINT (v1, BEGV);
1512 PUSH (v1);
1513 NEXT;
1516 CASE (Bchar_after):
1517 BEFORE_POTENTIAL_GC ();
1518 TOP = Fchar_after (TOP);
1519 AFTER_POTENTIAL_GC ();
1520 NEXT;
1522 CASE (Bfollowing_char):
1524 Lisp_Object v1;
1525 BEFORE_POTENTIAL_GC ();
1526 v1 = Ffollowing_char ();
1527 AFTER_POTENTIAL_GC ();
1528 PUSH (v1);
1529 NEXT;
1532 CASE (Bpreceding_char):
1534 Lisp_Object v1;
1535 BEFORE_POTENTIAL_GC ();
1536 v1 = Fprevious_char ();
1537 AFTER_POTENTIAL_GC ();
1538 PUSH (v1);
1539 NEXT;
1542 CASE (Bcurrent_column):
1544 Lisp_Object v1;
1545 BEFORE_POTENTIAL_GC ();
1546 XSETFASTINT (v1, current_column ());
1547 AFTER_POTENTIAL_GC ();
1548 PUSH (v1);
1549 NEXT;
1552 CASE (Bindent_to):
1553 BEFORE_POTENTIAL_GC ();
1554 TOP = Findent_to (TOP, Qnil);
1555 AFTER_POTENTIAL_GC ();
1556 NEXT;
1558 CASE (Beolp):
1559 PUSH (Feolp ());
1560 NEXT;
1562 CASE (Beobp):
1563 PUSH (Feobp ());
1564 NEXT;
1566 CASE (Bbolp):
1567 PUSH (Fbolp ());
1568 NEXT;
1570 CASE (Bbobp):
1571 PUSH (Fbobp ());
1572 NEXT;
1574 CASE (Bcurrent_buffer):
1575 PUSH (Fcurrent_buffer ());
1576 NEXT;
1578 CASE (Bset_buffer):
1579 BEFORE_POTENTIAL_GC ();
1580 TOP = Fset_buffer (TOP);
1581 AFTER_POTENTIAL_GC ();
1582 NEXT;
1584 CASE (Binteractive_p): /* Obsolete since 24.1. */
1585 BEFORE_POTENTIAL_GC ();
1586 PUSH (call0 (intern ("interactive-p")));
1587 AFTER_POTENTIAL_GC ();
1588 NEXT;
1590 CASE (Bforward_char):
1591 BEFORE_POTENTIAL_GC ();
1592 TOP = Fforward_char (TOP);
1593 AFTER_POTENTIAL_GC ();
1594 NEXT;
1596 CASE (Bforward_word):
1597 BEFORE_POTENTIAL_GC ();
1598 TOP = Fforward_word (TOP);
1599 AFTER_POTENTIAL_GC ();
1600 NEXT;
1602 CASE (Bskip_chars_forward):
1604 Lisp_Object v1;
1605 BEFORE_POTENTIAL_GC ();
1606 v1 = POP;
1607 TOP = Fskip_chars_forward (TOP, v1);
1608 AFTER_POTENTIAL_GC ();
1609 NEXT;
1612 CASE (Bskip_chars_backward):
1614 Lisp_Object v1;
1615 BEFORE_POTENTIAL_GC ();
1616 v1 = POP;
1617 TOP = Fskip_chars_backward (TOP, v1);
1618 AFTER_POTENTIAL_GC ();
1619 NEXT;
1622 CASE (Bforward_line):
1623 BEFORE_POTENTIAL_GC ();
1624 TOP = Fforward_line (TOP);
1625 AFTER_POTENTIAL_GC ();
1626 NEXT;
1628 CASE (Bchar_syntax):
1630 int c;
1632 BEFORE_POTENTIAL_GC ();
1633 CHECK_CHARACTER (TOP);
1634 AFTER_POTENTIAL_GC ();
1635 c = XFASTINT (TOP);
1636 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
1637 MAKE_CHAR_MULTIBYTE (c);
1638 XSETFASTINT (TOP, syntax_code_spec[SYNTAX (c)]);
1640 NEXT;
1642 CASE (Bbuffer_substring):
1644 Lisp_Object v1;
1645 BEFORE_POTENTIAL_GC ();
1646 v1 = POP;
1647 TOP = Fbuffer_substring (TOP, v1);
1648 AFTER_POTENTIAL_GC ();
1649 NEXT;
1652 CASE (Bdelete_region):
1654 Lisp_Object v1;
1655 BEFORE_POTENTIAL_GC ();
1656 v1 = POP;
1657 TOP = Fdelete_region (TOP, v1);
1658 AFTER_POTENTIAL_GC ();
1659 NEXT;
1662 CASE (Bnarrow_to_region):
1664 Lisp_Object v1;
1665 BEFORE_POTENTIAL_GC ();
1666 v1 = POP;
1667 TOP = Fnarrow_to_region (TOP, v1);
1668 AFTER_POTENTIAL_GC ();
1669 NEXT;
1672 CASE (Bwiden):
1673 BEFORE_POTENTIAL_GC ();
1674 PUSH (Fwiden ());
1675 AFTER_POTENTIAL_GC ();
1676 NEXT;
1678 CASE (Bend_of_line):
1679 BEFORE_POTENTIAL_GC ();
1680 TOP = Fend_of_line (TOP);
1681 AFTER_POTENTIAL_GC ();
1682 NEXT;
1684 CASE (Bset_marker):
1686 Lisp_Object v1, v2;
1687 BEFORE_POTENTIAL_GC ();
1688 v1 = POP;
1689 v2 = POP;
1690 TOP = Fset_marker (TOP, v2, v1);
1691 AFTER_POTENTIAL_GC ();
1692 NEXT;
1695 CASE (Bmatch_beginning):
1696 BEFORE_POTENTIAL_GC ();
1697 TOP = Fmatch_beginning (TOP);
1698 AFTER_POTENTIAL_GC ();
1699 NEXT;
1701 CASE (Bmatch_end):
1702 BEFORE_POTENTIAL_GC ();
1703 TOP = Fmatch_end (TOP);
1704 AFTER_POTENTIAL_GC ();
1705 NEXT;
1707 CASE (Bupcase):
1708 BEFORE_POTENTIAL_GC ();
1709 TOP = Fupcase (TOP);
1710 AFTER_POTENTIAL_GC ();
1711 NEXT;
1713 CASE (Bdowncase):
1714 BEFORE_POTENTIAL_GC ();
1715 TOP = Fdowncase (TOP);
1716 AFTER_POTENTIAL_GC ();
1717 NEXT;
1719 CASE (Bstringeqlsign):
1721 Lisp_Object v1;
1722 BEFORE_POTENTIAL_GC ();
1723 v1 = POP;
1724 TOP = Fstring_equal (TOP, v1);
1725 AFTER_POTENTIAL_GC ();
1726 NEXT;
1729 CASE (Bstringlss):
1731 Lisp_Object v1;
1732 BEFORE_POTENTIAL_GC ();
1733 v1 = POP;
1734 TOP = Fstring_lessp (TOP, v1);
1735 AFTER_POTENTIAL_GC ();
1736 NEXT;
1739 CASE (Bequal):
1741 Lisp_Object v1;
1742 v1 = POP;
1743 TOP = Fequal (TOP, v1);
1744 NEXT;
1747 CASE (Bnthcdr):
1749 Lisp_Object v1;
1750 BEFORE_POTENTIAL_GC ();
1751 v1 = POP;
1752 TOP = Fnthcdr (TOP, v1);
1753 AFTER_POTENTIAL_GC ();
1754 NEXT;
1757 CASE (Belt):
1759 Lisp_Object v1, v2;
1760 if (CONSP (TOP))
1762 /* Exchange args and then do nth. */
1763 EMACS_INT n;
1764 BEFORE_POTENTIAL_GC ();
1765 v2 = POP;
1766 v1 = TOP;
1767 CHECK_NUMBER (v2);
1768 AFTER_POTENTIAL_GC ();
1769 n = XINT (v2);
1770 immediate_quit = 1;
1771 while (--n >= 0 && CONSP (v1))
1772 v1 = XCDR (v1);
1773 immediate_quit = 0;
1774 TOP = CAR (v1);
1776 else
1778 BEFORE_POTENTIAL_GC ();
1779 v1 = POP;
1780 TOP = Felt (TOP, v1);
1781 AFTER_POTENTIAL_GC ();
1783 NEXT;
1786 CASE (Bmember):
1788 Lisp_Object v1;
1789 BEFORE_POTENTIAL_GC ();
1790 v1 = POP;
1791 TOP = Fmember (TOP, v1);
1792 AFTER_POTENTIAL_GC ();
1793 NEXT;
1796 CASE (Bassq):
1798 Lisp_Object v1;
1799 BEFORE_POTENTIAL_GC ();
1800 v1 = POP;
1801 TOP = Fassq (TOP, v1);
1802 AFTER_POTENTIAL_GC ();
1803 NEXT;
1806 CASE (Bnreverse):
1807 BEFORE_POTENTIAL_GC ();
1808 TOP = Fnreverse (TOP);
1809 AFTER_POTENTIAL_GC ();
1810 NEXT;
1812 CASE (Bsetcar):
1814 Lisp_Object v1;
1815 BEFORE_POTENTIAL_GC ();
1816 v1 = POP;
1817 TOP = Fsetcar (TOP, v1);
1818 AFTER_POTENTIAL_GC ();
1819 NEXT;
1822 CASE (Bsetcdr):
1824 Lisp_Object v1;
1825 BEFORE_POTENTIAL_GC ();
1826 v1 = POP;
1827 TOP = Fsetcdr (TOP, v1);
1828 AFTER_POTENTIAL_GC ();
1829 NEXT;
1832 CASE (Bcar_safe):
1834 Lisp_Object v1;
1835 v1 = TOP;
1836 TOP = CAR_SAFE (v1);
1837 NEXT;
1840 CASE (Bcdr_safe):
1842 Lisp_Object v1;
1843 v1 = TOP;
1844 TOP = CDR_SAFE (v1);
1845 NEXT;
1848 CASE (Bnconc):
1849 BEFORE_POTENTIAL_GC ();
1850 DISCARD (1);
1851 TOP = Fnconc (2, &TOP);
1852 AFTER_POTENTIAL_GC ();
1853 NEXT;
1855 CASE (Bnumberp):
1856 TOP = (NUMBERP (TOP) ? Qt : Qnil);
1857 NEXT;
1859 CASE (Bintegerp):
1860 TOP = INTEGERP (TOP) ? Qt : Qnil;
1861 NEXT;
1863 #ifdef BYTE_CODE_SAFE
1864 /* These are intentionally written using 'case' syntax,
1865 because they are incompatible with the threaded
1866 interpreter. */
1868 case Bset_mark:
1869 BEFORE_POTENTIAL_GC ();
1870 error ("set-mark is an obsolete bytecode");
1871 AFTER_POTENTIAL_GC ();
1872 break;
1873 case Bscan_buffer:
1874 BEFORE_POTENTIAL_GC ();
1875 error ("scan-buffer is an obsolete bytecode");
1876 AFTER_POTENTIAL_GC ();
1877 break;
1878 #endif
1880 CASE_ABORT:
1881 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1882 for that instead. */
1883 /* CASE (Bstack_ref): */
1884 error ("Invalid byte opcode");
1886 /* Handy byte-codes for lexical binding. */
1887 CASE (Bstack_ref1):
1888 CASE (Bstack_ref2):
1889 CASE (Bstack_ref3):
1890 CASE (Bstack_ref4):
1891 CASE (Bstack_ref5):
1893 Lisp_Object *ptr = top - (op - Bstack_ref);
1894 PUSH (*ptr);
1895 NEXT;
1897 CASE (Bstack_ref6):
1899 Lisp_Object *ptr = top - (FETCH);
1900 PUSH (*ptr);
1901 NEXT;
1903 CASE (Bstack_ref7):
1905 Lisp_Object *ptr = top - (FETCH2);
1906 PUSH (*ptr);
1907 NEXT;
1909 CASE (Bstack_set):
1910 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1912 Lisp_Object *ptr = top - (FETCH);
1913 *ptr = POP;
1914 NEXT;
1916 CASE (Bstack_set2):
1918 Lisp_Object *ptr = top - (FETCH2);
1919 *ptr = POP;
1920 NEXT;
1922 CASE (BdiscardN):
1923 op = FETCH;
1924 if (op & 0x80)
1926 op &= 0x7F;
1927 top[-op] = TOP;
1929 DISCARD (op);
1930 NEXT;
1932 CASE_DEFAULT
1933 CASE (Bconstant):
1934 #ifdef BYTE_CODE_SAFE
1935 if (op < Bconstant)
1937 emacs_abort ();
1939 if ((op -= Bconstant) >= const_length)
1941 emacs_abort ();
1943 PUSH (vectorp[op]);
1944 #else
1945 PUSH (vectorp[op - Bconstant]);
1946 #endif
1947 NEXT;
1951 exit:
1953 byte_stack_list = byte_stack_list->next;
1955 /* Binds and unbinds are supposed to be compiled balanced. */
1956 if (SPECPDL_INDEX () != count)
1957 #ifdef BYTE_CODE_SAFE
1958 error ("binding stack not balanced (serious byte compiler bug)");
1959 #else
1960 emacs_abort ();
1961 #endif
1963 return result;
1966 void
1967 syms_of_bytecode (void)
1969 defsubr (&Sbyte_code);
1971 #ifdef BYTE_CODE_METER
1973 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter,
1974 doc: /* A vector of vectors which holds a histogram of byte-code usage.
1975 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1976 opcode CODE has been executed.
1977 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1978 indicates how many times the byte opcodes CODE1 and CODE2 have been
1979 executed in succession. */);
1981 DEFVAR_BOOL ("byte-metering-on", byte_metering_on,
1982 doc: /* If non-nil, keep profiling information on byte code usage.
1983 The variable byte-code-meter indicates how often each byte opcode is used.
1984 If a symbol has a property named `byte-code-meter' whose value is an
1985 integer, it is incremented each time that symbol's function is called. */);
1987 byte_metering_on = 0;
1988 Vbyte_code_meter = Fmake_vector (make_number (256), make_number (0));
1989 DEFSYM (Qbyte_code_meter, "byte-code-meter");
1991 int i = 256;
1992 while (i--)
1993 ASET (Vbyte_code_meter, i,
1994 Fmake_vector (make_number (256), make_number (0)));
1996 #endif