lisp/emacs-lisp/cl-macs.el: Fix typos in docstrings.
[emacs.git] / src / bytecode.c
blobc79027597f8ee92f35c79183b19b8d18ab169aaf
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 (void)
344 struct byte_stack *stack;
345 Lisp_Object *obj;
347 for (stack = byte_stack_list; stack; stack = stack->next)
349 /* If STACK->top is null here, this means there's an opcode in
350 Fbyte_code that wasn't expected to GC, but did. To find out
351 which opcode this is, record the value of `stack', and walk
352 up the stack in a debugger, stopping in frames of Fbyte_code.
353 The culprit is found in the frame of Fbyte_code where the
354 address of its local variable `stack' is equal to the
355 recorded value of `stack' here. */
356 eassert (stack->top);
358 for (obj = stack->bottom; obj <= stack->top; ++obj)
359 mark_object (*obj);
361 mark_object (stack->byte_string);
362 mark_object (stack->constants);
365 #endif
367 /* Unmark objects in the stacks on byte_stack_list. Relocate program
368 counters. Called when GC has completed. */
370 void
371 unmark_byte_stack (void)
373 struct byte_stack *stack;
375 for (stack = byte_stack_list; stack; stack = stack->next)
377 if (stack->byte_string_start != SDATA (stack->byte_string))
379 ptrdiff_t offset = stack->pc - stack->byte_string_start;
380 stack->byte_string_start = SDATA (stack->byte_string);
381 stack->pc = stack->byte_string_start + offset;
387 /* Fetch the next byte from the bytecode stream. */
389 #define FETCH *stack.pc++
391 /* Fetch two bytes from the bytecode stream and make a 16-bit number
392 out of them. */
394 #define FETCH2 (op = FETCH, op + (FETCH << 8))
396 /* Push x onto the execution stack. This used to be #define PUSH(x)
397 (*++stackp = (x)) This oddity is necessary because Alliant can't be
398 bothered to compile the preincrement operator properly, as of 4/91.
399 -JimB */
401 #define PUSH(x) (top++, *top = (x))
403 /* Pop a value off the execution stack. */
405 #define POP (*top--)
407 /* Discard n values from the execution stack. */
409 #define DISCARD(n) (top -= (n))
411 /* Get the value which is at the top of the execution stack, but don't
412 pop it. */
414 #define TOP (*top)
416 /* Actions that must be performed before and after calling a function
417 that might GC. */
419 #if !BYTE_MAINTAIN_TOP
420 #define BEFORE_POTENTIAL_GC() ((void)0)
421 #define AFTER_POTENTIAL_GC() ((void)0)
422 #else
423 #define BEFORE_POTENTIAL_GC() stack.top = top
424 #define AFTER_POTENTIAL_GC() stack.top = NULL
425 #endif
427 /* Garbage collect if we have consed enough since the last time.
428 We do this at every branch, to avoid loops that never GC. */
430 #define MAYBE_GC() \
431 do { \
432 BEFORE_POTENTIAL_GC (); \
433 maybe_gc (); \
434 AFTER_POTENTIAL_GC (); \
435 } while (0)
437 /* Check for jumping out of range. */
439 #ifdef BYTE_CODE_SAFE
441 #define CHECK_RANGE(ARG) \
442 if (ARG >= bytestr_length) emacs_abort ()
444 #else /* not BYTE_CODE_SAFE */
446 #define CHECK_RANGE(ARG)
448 #endif /* not BYTE_CODE_SAFE */
450 /* A version of the QUIT macro which makes sure that the stack top is
451 set before signaling `quit'. */
453 #define BYTE_CODE_QUIT \
454 do { \
455 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
457 Lisp_Object flag = Vquit_flag; \
458 Vquit_flag = Qnil; \
459 BEFORE_POTENTIAL_GC (); \
460 if (EQ (Vthrow_on_input, flag)) \
461 Fthrow (Vthrow_on_input, Qt); \
462 Fsignal (Qquit, Qnil); \
463 AFTER_POTENTIAL_GC (); \
465 else if (pending_signals) \
466 process_pending_signals (); \
467 } while (0)
470 DEFUN ("byte-code", Fbyte_code, Sbyte_code, 3, 3, 0,
471 doc: /* Function used internally in byte-compiled code.
472 The first argument, BYTESTR, is a string of byte code;
473 the second, VECTOR, a vector of constants;
474 the third, MAXDEPTH, the maximum stack depth used in this function.
475 If the third argument is incorrect, Emacs may crash. */)
476 (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth)
478 return exec_byte_code (bytestr, vector, maxdepth, Qnil, 0, NULL);
481 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
482 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
483 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
484 argument list (including &rest, &optional, etc.), and ARGS, of size
485 NARGS, should be a vector of the actual arguments. The arguments in
486 ARGS are pushed on the stack according to ARGS_TEMPLATE before
487 executing BYTESTR. */
489 Lisp_Object
490 exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
491 Lisp_Object args_template, ptrdiff_t nargs, Lisp_Object *args)
493 ptrdiff_t count = SPECPDL_INDEX ();
494 #ifdef BYTE_CODE_METER
495 int this_op = 0;
496 int prev_op;
497 #endif
498 int op;
499 /* Lisp_Object v1, v2; */
500 Lisp_Object *vectorp;
501 #ifdef BYTE_CODE_SAFE
502 ptrdiff_t const_length;
503 Lisp_Object *stacke;
504 ptrdiff_t bytestr_length;
505 #endif
506 struct byte_stack stack;
507 Lisp_Object *top;
508 Lisp_Object result;
510 #if 0 /* CHECK_FRAME_FONT */
512 struct frame *f = SELECTED_FRAME ();
513 if (FRAME_X_P (f)
514 && FRAME_FONT (f)->direction != 0
515 && FRAME_FONT (f)->direction != 1)
516 emacs_abort ();
518 #endif
520 CHECK_STRING (bytestr);
521 CHECK_VECTOR (vector);
522 CHECK_NATNUM (maxdepth);
524 #ifdef BYTE_CODE_SAFE
525 const_length = ASIZE (vector);
526 #endif
528 if (STRING_MULTIBYTE (bytestr))
529 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
530 because they produced a raw 8-bit string for byte-code and now
531 such a byte-code string is loaded as multibyte while raw 8-bit
532 characters converted to multibyte form. Thus, now we must
533 convert them back to the originally intended unibyte form. */
534 bytestr = Fstring_as_unibyte (bytestr);
536 #ifdef BYTE_CODE_SAFE
537 bytestr_length = SBYTES (bytestr);
538 #endif
539 vectorp = XVECTOR (vector)->contents;
541 stack.byte_string = bytestr;
542 stack.pc = stack.byte_string_start = SDATA (bytestr);
543 #if BYTE_MARK_STACK
544 stack.constants = vector;
545 #endif
546 if (MAX_ALLOCA / word_size <= XFASTINT (maxdepth))
547 memory_full (SIZE_MAX);
548 top = alloca ((XFASTINT (maxdepth) + 1) * sizeof *top);
549 #if BYTE_MAINTAIN_TOP
550 stack.bottom = top + 1;
551 stack.top = NULL;
552 #endif
553 stack.next = byte_stack_list;
554 byte_stack_list = &stack;
556 #ifdef BYTE_CODE_SAFE
557 stacke = stack.bottom - 1 + XFASTINT (maxdepth);
558 #endif
560 if (INTEGERP (args_template))
562 ptrdiff_t at = XINT (args_template);
563 bool rest = (at & 128) != 0;
564 int mandatory = at & 127;
565 ptrdiff_t nonrest = at >> 8;
566 eassert (mandatory <= nonrest);
567 if (nargs <= nonrest)
569 ptrdiff_t i;
570 for (i = 0 ; i < nargs; i++, args++)
571 PUSH (*args);
572 if (nargs < mandatory)
573 /* Too few arguments. */
574 Fsignal (Qwrong_number_of_arguments,
575 Fcons (Fcons (make_number (mandatory),
576 rest ? Qand_rest : make_number (nonrest)),
577 Fcons (make_number (nargs), Qnil)));
578 else
580 for (; i < nonrest; i++)
581 PUSH (Qnil);
582 if (rest)
583 PUSH (Qnil);
586 else if (rest)
588 ptrdiff_t i;
589 for (i = 0 ; i < nonrest; i++, args++)
590 PUSH (*args);
591 PUSH (Flist (nargs - nonrest, args));
593 else
594 /* Too many arguments. */
595 Fsignal (Qwrong_number_of_arguments,
596 Fcons (Fcons (make_number (mandatory),
597 make_number (nonrest)),
598 Fcons (make_number (nargs), Qnil)));
600 else if (! NILP (args_template))
601 /* We should push some arguments on the stack. */
603 error ("Unknown args template!");
606 while (1)
608 #ifdef BYTE_CODE_SAFE
609 if (top > stacke)
610 emacs_abort ();
611 else if (top < stack.bottom - 1)
612 emacs_abort ();
613 #endif
615 #ifdef BYTE_CODE_METER
616 prev_op = this_op;
617 this_op = op = FETCH;
618 METER_CODE (prev_op, op);
619 #else
620 #ifndef BYTE_CODE_THREADED
621 op = FETCH;
622 #endif
623 #endif
625 /* The interpreter can be compiled one of two ways: as an
626 ordinary switch-based interpreter, or as a threaded
627 interpreter. The threaded interpreter relies on GCC's
628 computed goto extension, so it is not available everywhere.
629 Threading provides a performance boost. These macros are how
630 we allow the code to be compiled both ways. */
631 #ifdef BYTE_CODE_THREADED
632 /* The CASE macro introduces an instruction's body. It is
633 either a label or a case label. */
634 #define CASE(OP) insn_ ## OP
635 /* NEXT is invoked at the end of an instruction to go to the
636 next instruction. It is either a computed goto, or a
637 plain break. */
638 #define NEXT goto *(targets[op = FETCH])
639 /* FIRST is like NEXT, but is only used at the start of the
640 interpreter body. In the switch-based interpreter it is the
641 switch, so the threaded definition must include a semicolon. */
642 #define FIRST NEXT;
643 /* Most cases are labeled with the CASE macro, above.
644 CASE_DEFAULT is one exception; it is used if the interpreter
645 being built requires a default case. The threaded
646 interpreter does not, because the dispatch table is
647 completely filled. */
648 #define CASE_DEFAULT
649 /* This introduces an instruction that is known to call abort. */
650 #define CASE_ABORT CASE (Bstack_ref): CASE (default)
651 #else
652 /* See above for the meaning of the various defines. */
653 #define CASE(OP) case OP
654 #define NEXT break
655 #define FIRST switch (op)
656 #define CASE_DEFAULT case 255: default:
657 #define CASE_ABORT case 0
658 #endif
660 #ifdef BYTE_CODE_THREADED
662 /* A convenience define that saves us a lot of typing and makes
663 the table clearer. */
664 #define LABEL(OP) [OP] = &&insn_ ## OP
666 #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
667 # pragma GCC diagnostic push
668 # pragma GCC diagnostic ignored "-Woverride-init"
669 #elif defined __clang__
670 # pragma GCC diagnostic push
671 # pragma GCC diagnostic ignored "-Winitializer-overrides"
672 #endif
674 /* This is the dispatch table for the threaded interpreter. */
675 static const void *const targets[256] =
677 [0 ... (Bconstant - 1)] = &&insn_default,
678 [Bconstant ... 255] = &&insn_Bconstant,
680 #define DEFINE(name, value) LABEL (name) ,
681 BYTE_CODES
682 #undef DEFINE
685 #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) || defined __clang__
686 # pragma GCC diagnostic pop
687 #endif
689 #endif
692 FIRST
694 CASE (Bvarref7):
695 op = FETCH2;
696 goto varref;
698 CASE (Bvarref):
699 CASE (Bvarref1):
700 CASE (Bvarref2):
701 CASE (Bvarref3):
702 CASE (Bvarref4):
703 CASE (Bvarref5):
704 op = op - Bvarref;
705 goto varref;
707 /* This seems to be the most frequently executed byte-code
708 among the Bvarref's, so avoid a goto here. */
709 CASE (Bvarref6):
710 op = FETCH;
711 varref:
713 Lisp_Object v1, v2;
715 v1 = vectorp[op];
716 if (SYMBOLP (v1))
718 if (XSYMBOL (v1)->redirect != SYMBOL_PLAINVAL
719 || (v2 = SYMBOL_VAL (XSYMBOL (v1)),
720 EQ (v2, Qunbound)))
722 BEFORE_POTENTIAL_GC ();
723 v2 = Fsymbol_value (v1);
724 AFTER_POTENTIAL_GC ();
727 else
729 BEFORE_POTENTIAL_GC ();
730 v2 = Fsymbol_value (v1);
731 AFTER_POTENTIAL_GC ();
733 PUSH (v2);
734 NEXT;
737 CASE (Bgotoifnil):
739 Lisp_Object v1;
740 MAYBE_GC ();
741 op = FETCH2;
742 v1 = POP;
743 if (NILP (v1))
745 BYTE_CODE_QUIT;
746 CHECK_RANGE (op);
747 stack.pc = stack.byte_string_start + op;
749 NEXT;
752 CASE (Bcar):
754 Lisp_Object v1;
755 v1 = TOP;
756 if (CONSP (v1))
757 TOP = XCAR (v1);
758 else if (NILP (v1))
759 TOP = Qnil;
760 else
762 BEFORE_POTENTIAL_GC ();
763 wrong_type_argument (Qlistp, v1);
765 NEXT;
768 CASE (Beq):
770 Lisp_Object v1;
771 v1 = POP;
772 TOP = EQ (v1, TOP) ? Qt : Qnil;
773 NEXT;
776 CASE (Bmemq):
778 Lisp_Object v1;
779 BEFORE_POTENTIAL_GC ();
780 v1 = POP;
781 TOP = Fmemq (TOP, v1);
782 AFTER_POTENTIAL_GC ();
783 NEXT;
786 CASE (Bcdr):
788 Lisp_Object v1;
789 v1 = TOP;
790 if (CONSP (v1))
791 TOP = XCDR (v1);
792 else if (NILP (v1))
793 TOP = Qnil;
794 else
796 BEFORE_POTENTIAL_GC ();
797 wrong_type_argument (Qlistp, v1);
799 NEXT;
802 CASE (Bvarset):
803 CASE (Bvarset1):
804 CASE (Bvarset2):
805 CASE (Bvarset3):
806 CASE (Bvarset4):
807 CASE (Bvarset5):
808 op -= Bvarset;
809 goto varset;
811 CASE (Bvarset7):
812 op = FETCH2;
813 goto varset;
815 CASE (Bvarset6):
816 op = FETCH;
817 varset:
819 Lisp_Object sym, val;
821 sym = vectorp[op];
822 val = TOP;
824 /* Inline the most common case. */
825 if (SYMBOLP (sym)
826 && !EQ (val, Qunbound)
827 && !XSYMBOL (sym)->redirect
828 && !SYMBOL_CONSTANT_P (sym))
829 SET_SYMBOL_VAL (XSYMBOL (sym), val);
830 else
832 BEFORE_POTENTIAL_GC ();
833 set_internal (sym, val, Qnil, 0);
834 AFTER_POTENTIAL_GC ();
837 (void) POP;
838 NEXT;
840 CASE (Bdup):
842 Lisp_Object v1;
843 v1 = TOP;
844 PUSH (v1);
845 NEXT;
848 /* ------------------ */
850 CASE (Bvarbind6):
851 op = FETCH;
852 goto varbind;
854 CASE (Bvarbind7):
855 op = FETCH2;
856 goto varbind;
858 CASE (Bvarbind):
859 CASE (Bvarbind1):
860 CASE (Bvarbind2):
861 CASE (Bvarbind3):
862 CASE (Bvarbind4):
863 CASE (Bvarbind5):
864 op -= Bvarbind;
865 varbind:
866 /* Specbind can signal and thus GC. */
867 BEFORE_POTENTIAL_GC ();
868 specbind (vectorp[op], POP);
869 AFTER_POTENTIAL_GC ();
870 NEXT;
872 CASE (Bcall6):
873 op = FETCH;
874 goto docall;
876 CASE (Bcall7):
877 op = FETCH2;
878 goto docall;
880 CASE (Bcall):
881 CASE (Bcall1):
882 CASE (Bcall2):
883 CASE (Bcall3):
884 CASE (Bcall4):
885 CASE (Bcall5):
886 op -= Bcall;
887 docall:
889 BEFORE_POTENTIAL_GC ();
890 DISCARD (op);
891 #ifdef BYTE_CODE_METER
892 if (byte_metering_on && SYMBOLP (TOP))
894 Lisp_Object v1, v2;
896 v1 = TOP;
897 v2 = Fget (v1, Qbyte_code_meter);
898 if (INTEGERP (v2)
899 && XINT (v2) < MOST_POSITIVE_FIXNUM)
901 XSETINT (v2, XINT (v2) + 1);
902 Fput (v1, Qbyte_code_meter, v2);
905 #endif
906 TOP = Ffuncall (op + 1, &TOP);
907 AFTER_POTENTIAL_GC ();
908 NEXT;
911 CASE (Bunbind6):
912 op = FETCH;
913 goto dounbind;
915 CASE (Bunbind7):
916 op = FETCH2;
917 goto dounbind;
919 CASE (Bunbind):
920 CASE (Bunbind1):
921 CASE (Bunbind2):
922 CASE (Bunbind3):
923 CASE (Bunbind4):
924 CASE (Bunbind5):
925 op -= Bunbind;
926 dounbind:
927 BEFORE_POTENTIAL_GC ();
928 unbind_to (SPECPDL_INDEX () - op, Qnil);
929 AFTER_POTENTIAL_GC ();
930 NEXT;
932 CASE (Bunbind_all): /* Obsolete. Never used. */
933 /* To unbind back to the beginning of this frame. Not used yet,
934 but will be needed for tail-recursion elimination. */
935 BEFORE_POTENTIAL_GC ();
936 unbind_to (count, Qnil);
937 AFTER_POTENTIAL_GC ();
938 NEXT;
940 CASE (Bgoto):
941 MAYBE_GC ();
942 BYTE_CODE_QUIT;
943 op = FETCH2; /* pc = FETCH2 loses since FETCH2 contains pc++ */
944 CHECK_RANGE (op);
945 stack.pc = stack.byte_string_start + op;
946 NEXT;
948 CASE (Bgotoifnonnil):
950 Lisp_Object v1;
951 MAYBE_GC ();
952 op = FETCH2;
953 v1 = POP;
954 if (!NILP (v1))
956 BYTE_CODE_QUIT;
957 CHECK_RANGE (op);
958 stack.pc = stack.byte_string_start + op;
960 NEXT;
963 CASE (Bgotoifnilelsepop):
964 MAYBE_GC ();
965 op = FETCH2;
966 if (NILP (TOP))
968 BYTE_CODE_QUIT;
969 CHECK_RANGE (op);
970 stack.pc = stack.byte_string_start + op;
972 else DISCARD (1);
973 NEXT;
975 CASE (Bgotoifnonnilelsepop):
976 MAYBE_GC ();
977 op = FETCH2;
978 if (!NILP (TOP))
980 BYTE_CODE_QUIT;
981 CHECK_RANGE (op);
982 stack.pc = stack.byte_string_start + op;
984 else DISCARD (1);
985 NEXT;
987 CASE (BRgoto):
988 MAYBE_GC ();
989 BYTE_CODE_QUIT;
990 stack.pc += (int) *stack.pc - 127;
991 NEXT;
993 CASE (BRgotoifnil):
995 Lisp_Object v1;
996 MAYBE_GC ();
997 v1 = POP;
998 if (NILP (v1))
1000 BYTE_CODE_QUIT;
1001 stack.pc += (int) *stack.pc - 128;
1003 stack.pc++;
1004 NEXT;
1007 CASE (BRgotoifnonnil):
1009 Lisp_Object v1;
1010 MAYBE_GC ();
1011 v1 = POP;
1012 if (!NILP (v1))
1014 BYTE_CODE_QUIT;
1015 stack.pc += (int) *stack.pc - 128;
1017 stack.pc++;
1018 NEXT;
1021 CASE (BRgotoifnilelsepop):
1022 MAYBE_GC ();
1023 op = *stack.pc++;
1024 if (NILP (TOP))
1026 BYTE_CODE_QUIT;
1027 stack.pc += op - 128;
1029 else DISCARD (1);
1030 NEXT;
1032 CASE (BRgotoifnonnilelsepop):
1033 MAYBE_GC ();
1034 op = *stack.pc++;
1035 if (!NILP (TOP))
1037 BYTE_CODE_QUIT;
1038 stack.pc += op - 128;
1040 else DISCARD (1);
1041 NEXT;
1043 CASE (Breturn):
1044 result = POP;
1045 goto exit;
1047 CASE (Bdiscard):
1048 DISCARD (1);
1049 NEXT;
1051 CASE (Bconstant2):
1052 PUSH (vectorp[FETCH2]);
1053 NEXT;
1055 CASE (Bsave_excursion):
1056 record_unwind_protect (save_excursion_restore,
1057 save_excursion_save ());
1058 NEXT;
1060 CASE (Bsave_current_buffer): /* Obsolete since ??. */
1061 CASE (Bsave_current_buffer_1):
1062 record_unwind_current_buffer ();
1063 NEXT;
1065 CASE (Bsave_window_excursion): /* Obsolete since 24.1. */
1067 register ptrdiff_t count1 = SPECPDL_INDEX ();
1068 record_unwind_protect (Fset_window_configuration,
1069 Fcurrent_window_configuration (Qnil));
1070 BEFORE_POTENTIAL_GC ();
1071 TOP = Fprogn (TOP);
1072 unbind_to (count1, TOP);
1073 AFTER_POTENTIAL_GC ();
1074 NEXT;
1077 CASE (Bsave_restriction):
1078 record_unwind_protect (save_restriction_restore,
1079 save_restriction_save ());
1080 NEXT;
1082 CASE (Bcatch): /* FIXME: ill-suited for lexbind. */
1084 Lisp_Object v1;
1085 BEFORE_POTENTIAL_GC ();
1086 v1 = POP;
1087 TOP = internal_catch (TOP, eval_sub, v1);
1088 AFTER_POTENTIAL_GC ();
1089 NEXT;
1092 CASE (Bunwind_protect): /* FIXME: avoid closure for lexbind. */
1093 record_unwind_protect (Fprogn, POP);
1094 NEXT;
1096 CASE (Bcondition_case): /* FIXME: ill-suited for lexbind. */
1098 Lisp_Object handlers, body;
1099 handlers = POP;
1100 body = POP;
1101 BEFORE_POTENTIAL_GC ();
1102 TOP = internal_lisp_condition_case (TOP, body, handlers);
1103 AFTER_POTENTIAL_GC ();
1104 NEXT;
1107 CASE (Btemp_output_buffer_setup): /* Obsolete since 24.1. */
1108 BEFORE_POTENTIAL_GC ();
1109 CHECK_STRING (TOP);
1110 temp_output_buffer_setup (SSDATA (TOP));
1111 AFTER_POTENTIAL_GC ();
1112 TOP = Vstandard_output;
1113 NEXT;
1115 CASE (Btemp_output_buffer_show): /* Obsolete since 24.1. */
1117 Lisp_Object v1;
1118 BEFORE_POTENTIAL_GC ();
1119 v1 = POP;
1120 temp_output_buffer_show (TOP);
1121 TOP = v1;
1122 /* pop binding of standard-output */
1123 unbind_to (SPECPDL_INDEX () - 1, Qnil);
1124 AFTER_POTENTIAL_GC ();
1125 NEXT;
1128 CASE (Bnth):
1130 Lisp_Object v1, v2;
1131 EMACS_INT n;
1132 BEFORE_POTENTIAL_GC ();
1133 v1 = POP;
1134 v2 = TOP;
1135 CHECK_NUMBER (v2);
1136 n = XINT (v2);
1137 immediate_quit = 1;
1138 while (--n >= 0 && CONSP (v1))
1139 v1 = XCDR (v1);
1140 immediate_quit = 0;
1141 TOP = CAR (v1);
1142 AFTER_POTENTIAL_GC ();
1143 NEXT;
1146 CASE (Bsymbolp):
1147 TOP = SYMBOLP (TOP) ? Qt : Qnil;
1148 NEXT;
1150 CASE (Bconsp):
1151 TOP = CONSP (TOP) ? Qt : Qnil;
1152 NEXT;
1154 CASE (Bstringp):
1155 TOP = STRINGP (TOP) ? Qt : Qnil;
1156 NEXT;
1158 CASE (Blistp):
1159 TOP = CONSP (TOP) || NILP (TOP) ? Qt : Qnil;
1160 NEXT;
1162 CASE (Bnot):
1163 TOP = NILP (TOP) ? Qt : Qnil;
1164 NEXT;
1166 CASE (Bcons):
1168 Lisp_Object v1;
1169 v1 = POP;
1170 TOP = Fcons (TOP, v1);
1171 NEXT;
1174 CASE (Blist1):
1175 TOP = Fcons (TOP, Qnil);
1176 NEXT;
1178 CASE (Blist2):
1180 Lisp_Object v1;
1181 v1 = POP;
1182 TOP = Fcons (TOP, Fcons (v1, Qnil));
1183 NEXT;
1186 CASE (Blist3):
1187 DISCARD (2);
1188 TOP = Flist (3, &TOP);
1189 NEXT;
1191 CASE (Blist4):
1192 DISCARD (3);
1193 TOP = Flist (4, &TOP);
1194 NEXT;
1196 CASE (BlistN):
1197 op = FETCH;
1198 DISCARD (op - 1);
1199 TOP = Flist (op, &TOP);
1200 NEXT;
1202 CASE (Blength):
1203 BEFORE_POTENTIAL_GC ();
1204 TOP = Flength (TOP);
1205 AFTER_POTENTIAL_GC ();
1206 NEXT;
1208 CASE (Baref):
1210 Lisp_Object v1;
1211 BEFORE_POTENTIAL_GC ();
1212 v1 = POP;
1213 TOP = Faref (TOP, v1);
1214 AFTER_POTENTIAL_GC ();
1215 NEXT;
1218 CASE (Baset):
1220 Lisp_Object v1, v2;
1221 BEFORE_POTENTIAL_GC ();
1222 v2 = POP; v1 = POP;
1223 TOP = Faset (TOP, v1, v2);
1224 AFTER_POTENTIAL_GC ();
1225 NEXT;
1228 CASE (Bsymbol_value):
1229 BEFORE_POTENTIAL_GC ();
1230 TOP = Fsymbol_value (TOP);
1231 AFTER_POTENTIAL_GC ();
1232 NEXT;
1234 CASE (Bsymbol_function):
1235 BEFORE_POTENTIAL_GC ();
1236 TOP = Fsymbol_function (TOP);
1237 AFTER_POTENTIAL_GC ();
1238 NEXT;
1240 CASE (Bset):
1242 Lisp_Object v1;
1243 BEFORE_POTENTIAL_GC ();
1244 v1 = POP;
1245 TOP = Fset (TOP, v1);
1246 AFTER_POTENTIAL_GC ();
1247 NEXT;
1250 CASE (Bfset):
1252 Lisp_Object v1;
1253 BEFORE_POTENTIAL_GC ();
1254 v1 = POP;
1255 TOP = Ffset (TOP, v1);
1256 AFTER_POTENTIAL_GC ();
1257 NEXT;
1260 CASE (Bget):
1262 Lisp_Object v1;
1263 BEFORE_POTENTIAL_GC ();
1264 v1 = POP;
1265 TOP = Fget (TOP, v1);
1266 AFTER_POTENTIAL_GC ();
1267 NEXT;
1270 CASE (Bsubstring):
1272 Lisp_Object v1, v2;
1273 BEFORE_POTENTIAL_GC ();
1274 v2 = POP; v1 = POP;
1275 TOP = Fsubstring (TOP, v1, v2);
1276 AFTER_POTENTIAL_GC ();
1277 NEXT;
1280 CASE (Bconcat2):
1281 BEFORE_POTENTIAL_GC ();
1282 DISCARD (1);
1283 TOP = Fconcat (2, &TOP);
1284 AFTER_POTENTIAL_GC ();
1285 NEXT;
1287 CASE (Bconcat3):
1288 BEFORE_POTENTIAL_GC ();
1289 DISCARD (2);
1290 TOP = Fconcat (3, &TOP);
1291 AFTER_POTENTIAL_GC ();
1292 NEXT;
1294 CASE (Bconcat4):
1295 BEFORE_POTENTIAL_GC ();
1296 DISCARD (3);
1297 TOP = Fconcat (4, &TOP);
1298 AFTER_POTENTIAL_GC ();
1299 NEXT;
1301 CASE (BconcatN):
1302 op = FETCH;
1303 BEFORE_POTENTIAL_GC ();
1304 DISCARD (op - 1);
1305 TOP = Fconcat (op, &TOP);
1306 AFTER_POTENTIAL_GC ();
1307 NEXT;
1309 CASE (Bsub1):
1311 Lisp_Object v1;
1312 v1 = TOP;
1313 if (INTEGERP (v1))
1315 XSETINT (v1, XINT (v1) - 1);
1316 TOP = v1;
1318 else
1320 BEFORE_POTENTIAL_GC ();
1321 TOP = Fsub1 (v1);
1322 AFTER_POTENTIAL_GC ();
1324 NEXT;
1327 CASE (Badd1):
1329 Lisp_Object v1;
1330 v1 = TOP;
1331 if (INTEGERP (v1))
1333 XSETINT (v1, XINT (v1) + 1);
1334 TOP = v1;
1336 else
1338 BEFORE_POTENTIAL_GC ();
1339 TOP = Fadd1 (v1);
1340 AFTER_POTENTIAL_GC ();
1342 NEXT;
1345 CASE (Beqlsign):
1347 Lisp_Object v1, v2;
1348 BEFORE_POTENTIAL_GC ();
1349 v2 = POP; v1 = TOP;
1350 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1);
1351 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2);
1352 AFTER_POTENTIAL_GC ();
1353 if (FLOATP (v1) || FLOATP (v2))
1355 double f1, f2;
1357 f1 = (FLOATP (v1) ? XFLOAT_DATA (v1) : XINT (v1));
1358 f2 = (FLOATP (v2) ? XFLOAT_DATA (v2) : XINT (v2));
1359 TOP = (f1 == f2 ? Qt : Qnil);
1361 else
1362 TOP = (XINT (v1) == XINT (v2) ? Qt : Qnil);
1363 NEXT;
1366 CASE (Bgtr):
1368 Lisp_Object v1;
1369 BEFORE_POTENTIAL_GC ();
1370 v1 = POP;
1371 TOP = Fgtr (TOP, v1);
1372 AFTER_POTENTIAL_GC ();
1373 NEXT;
1376 CASE (Blss):
1378 Lisp_Object v1;
1379 BEFORE_POTENTIAL_GC ();
1380 v1 = POP;
1381 TOP = Flss (TOP, v1);
1382 AFTER_POTENTIAL_GC ();
1383 NEXT;
1386 CASE (Bleq):
1388 Lisp_Object v1;
1389 BEFORE_POTENTIAL_GC ();
1390 v1 = POP;
1391 TOP = Fleq (TOP, v1);
1392 AFTER_POTENTIAL_GC ();
1393 NEXT;
1396 CASE (Bgeq):
1398 Lisp_Object v1;
1399 BEFORE_POTENTIAL_GC ();
1400 v1 = POP;
1401 TOP = Fgeq (TOP, v1);
1402 AFTER_POTENTIAL_GC ();
1403 NEXT;
1406 CASE (Bdiff):
1407 BEFORE_POTENTIAL_GC ();
1408 DISCARD (1);
1409 TOP = Fminus (2, &TOP);
1410 AFTER_POTENTIAL_GC ();
1411 NEXT;
1413 CASE (Bnegate):
1415 Lisp_Object v1;
1416 v1 = TOP;
1417 if (INTEGERP (v1))
1419 XSETINT (v1, - XINT (v1));
1420 TOP = v1;
1422 else
1424 BEFORE_POTENTIAL_GC ();
1425 TOP = Fminus (1, &TOP);
1426 AFTER_POTENTIAL_GC ();
1428 NEXT;
1431 CASE (Bplus):
1432 BEFORE_POTENTIAL_GC ();
1433 DISCARD (1);
1434 TOP = Fplus (2, &TOP);
1435 AFTER_POTENTIAL_GC ();
1436 NEXT;
1438 CASE (Bmax):
1439 BEFORE_POTENTIAL_GC ();
1440 DISCARD (1);
1441 TOP = Fmax (2, &TOP);
1442 AFTER_POTENTIAL_GC ();
1443 NEXT;
1445 CASE (Bmin):
1446 BEFORE_POTENTIAL_GC ();
1447 DISCARD (1);
1448 TOP = Fmin (2, &TOP);
1449 AFTER_POTENTIAL_GC ();
1450 NEXT;
1452 CASE (Bmult):
1453 BEFORE_POTENTIAL_GC ();
1454 DISCARD (1);
1455 TOP = Ftimes (2, &TOP);
1456 AFTER_POTENTIAL_GC ();
1457 NEXT;
1459 CASE (Bquo):
1460 BEFORE_POTENTIAL_GC ();
1461 DISCARD (1);
1462 TOP = Fquo (2, &TOP);
1463 AFTER_POTENTIAL_GC ();
1464 NEXT;
1466 CASE (Brem):
1468 Lisp_Object v1;
1469 BEFORE_POTENTIAL_GC ();
1470 v1 = POP;
1471 TOP = Frem (TOP, v1);
1472 AFTER_POTENTIAL_GC ();
1473 NEXT;
1476 CASE (Bpoint):
1478 Lisp_Object v1;
1479 XSETFASTINT (v1, PT);
1480 PUSH (v1);
1481 NEXT;
1484 CASE (Bgoto_char):
1485 BEFORE_POTENTIAL_GC ();
1486 TOP = Fgoto_char (TOP);
1487 AFTER_POTENTIAL_GC ();
1488 NEXT;
1490 CASE (Binsert):
1491 BEFORE_POTENTIAL_GC ();
1492 TOP = Finsert (1, &TOP);
1493 AFTER_POTENTIAL_GC ();
1494 NEXT;
1496 CASE (BinsertN):
1497 op = FETCH;
1498 BEFORE_POTENTIAL_GC ();
1499 DISCARD (op - 1);
1500 TOP = Finsert (op, &TOP);
1501 AFTER_POTENTIAL_GC ();
1502 NEXT;
1504 CASE (Bpoint_max):
1506 Lisp_Object v1;
1507 XSETFASTINT (v1, ZV);
1508 PUSH (v1);
1509 NEXT;
1512 CASE (Bpoint_min):
1514 Lisp_Object v1;
1515 XSETFASTINT (v1, BEGV);
1516 PUSH (v1);
1517 NEXT;
1520 CASE (Bchar_after):
1521 BEFORE_POTENTIAL_GC ();
1522 TOP = Fchar_after (TOP);
1523 AFTER_POTENTIAL_GC ();
1524 NEXT;
1526 CASE (Bfollowing_char):
1528 Lisp_Object v1;
1529 BEFORE_POTENTIAL_GC ();
1530 v1 = Ffollowing_char ();
1531 AFTER_POTENTIAL_GC ();
1532 PUSH (v1);
1533 NEXT;
1536 CASE (Bpreceding_char):
1538 Lisp_Object v1;
1539 BEFORE_POTENTIAL_GC ();
1540 v1 = Fprevious_char ();
1541 AFTER_POTENTIAL_GC ();
1542 PUSH (v1);
1543 NEXT;
1546 CASE (Bcurrent_column):
1548 Lisp_Object v1;
1549 BEFORE_POTENTIAL_GC ();
1550 XSETFASTINT (v1, current_column ());
1551 AFTER_POTENTIAL_GC ();
1552 PUSH (v1);
1553 NEXT;
1556 CASE (Bindent_to):
1557 BEFORE_POTENTIAL_GC ();
1558 TOP = Findent_to (TOP, Qnil);
1559 AFTER_POTENTIAL_GC ();
1560 NEXT;
1562 CASE (Beolp):
1563 PUSH (Feolp ());
1564 NEXT;
1566 CASE (Beobp):
1567 PUSH (Feobp ());
1568 NEXT;
1570 CASE (Bbolp):
1571 PUSH (Fbolp ());
1572 NEXT;
1574 CASE (Bbobp):
1575 PUSH (Fbobp ());
1576 NEXT;
1578 CASE (Bcurrent_buffer):
1579 PUSH (Fcurrent_buffer ());
1580 NEXT;
1582 CASE (Bset_buffer):
1583 BEFORE_POTENTIAL_GC ();
1584 TOP = Fset_buffer (TOP);
1585 AFTER_POTENTIAL_GC ();
1586 NEXT;
1588 CASE (Binteractive_p): /* Obsolete since 24.1. */
1589 BEFORE_POTENTIAL_GC ();
1590 PUSH (call0 (intern ("interactive-p")));
1591 AFTER_POTENTIAL_GC ();
1592 NEXT;
1594 CASE (Bforward_char):
1595 BEFORE_POTENTIAL_GC ();
1596 TOP = Fforward_char (TOP);
1597 AFTER_POTENTIAL_GC ();
1598 NEXT;
1600 CASE (Bforward_word):
1601 BEFORE_POTENTIAL_GC ();
1602 TOP = Fforward_word (TOP);
1603 AFTER_POTENTIAL_GC ();
1604 NEXT;
1606 CASE (Bskip_chars_forward):
1608 Lisp_Object v1;
1609 BEFORE_POTENTIAL_GC ();
1610 v1 = POP;
1611 TOP = Fskip_chars_forward (TOP, v1);
1612 AFTER_POTENTIAL_GC ();
1613 NEXT;
1616 CASE (Bskip_chars_backward):
1618 Lisp_Object v1;
1619 BEFORE_POTENTIAL_GC ();
1620 v1 = POP;
1621 TOP = Fskip_chars_backward (TOP, v1);
1622 AFTER_POTENTIAL_GC ();
1623 NEXT;
1626 CASE (Bforward_line):
1627 BEFORE_POTENTIAL_GC ();
1628 TOP = Fforward_line (TOP);
1629 AFTER_POTENTIAL_GC ();
1630 NEXT;
1632 CASE (Bchar_syntax):
1634 int c;
1636 BEFORE_POTENTIAL_GC ();
1637 CHECK_CHARACTER (TOP);
1638 AFTER_POTENTIAL_GC ();
1639 c = XFASTINT (TOP);
1640 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
1641 MAKE_CHAR_MULTIBYTE (c);
1642 XSETFASTINT (TOP, syntax_code_spec[SYNTAX (c)]);
1644 NEXT;
1646 CASE (Bbuffer_substring):
1648 Lisp_Object v1;
1649 BEFORE_POTENTIAL_GC ();
1650 v1 = POP;
1651 TOP = Fbuffer_substring (TOP, v1);
1652 AFTER_POTENTIAL_GC ();
1653 NEXT;
1656 CASE (Bdelete_region):
1658 Lisp_Object v1;
1659 BEFORE_POTENTIAL_GC ();
1660 v1 = POP;
1661 TOP = Fdelete_region (TOP, v1);
1662 AFTER_POTENTIAL_GC ();
1663 NEXT;
1666 CASE (Bnarrow_to_region):
1668 Lisp_Object v1;
1669 BEFORE_POTENTIAL_GC ();
1670 v1 = POP;
1671 TOP = Fnarrow_to_region (TOP, v1);
1672 AFTER_POTENTIAL_GC ();
1673 NEXT;
1676 CASE (Bwiden):
1677 BEFORE_POTENTIAL_GC ();
1678 PUSH (Fwiden ());
1679 AFTER_POTENTIAL_GC ();
1680 NEXT;
1682 CASE (Bend_of_line):
1683 BEFORE_POTENTIAL_GC ();
1684 TOP = Fend_of_line (TOP);
1685 AFTER_POTENTIAL_GC ();
1686 NEXT;
1688 CASE (Bset_marker):
1690 Lisp_Object v1, v2;
1691 BEFORE_POTENTIAL_GC ();
1692 v1 = POP;
1693 v2 = POP;
1694 TOP = Fset_marker (TOP, v2, v1);
1695 AFTER_POTENTIAL_GC ();
1696 NEXT;
1699 CASE (Bmatch_beginning):
1700 BEFORE_POTENTIAL_GC ();
1701 TOP = Fmatch_beginning (TOP);
1702 AFTER_POTENTIAL_GC ();
1703 NEXT;
1705 CASE (Bmatch_end):
1706 BEFORE_POTENTIAL_GC ();
1707 TOP = Fmatch_end (TOP);
1708 AFTER_POTENTIAL_GC ();
1709 NEXT;
1711 CASE (Bupcase):
1712 BEFORE_POTENTIAL_GC ();
1713 TOP = Fupcase (TOP);
1714 AFTER_POTENTIAL_GC ();
1715 NEXT;
1717 CASE (Bdowncase):
1718 BEFORE_POTENTIAL_GC ();
1719 TOP = Fdowncase (TOP);
1720 AFTER_POTENTIAL_GC ();
1721 NEXT;
1723 CASE (Bstringeqlsign):
1725 Lisp_Object v1;
1726 BEFORE_POTENTIAL_GC ();
1727 v1 = POP;
1728 TOP = Fstring_equal (TOP, v1);
1729 AFTER_POTENTIAL_GC ();
1730 NEXT;
1733 CASE (Bstringlss):
1735 Lisp_Object v1;
1736 BEFORE_POTENTIAL_GC ();
1737 v1 = POP;
1738 TOP = Fstring_lessp (TOP, v1);
1739 AFTER_POTENTIAL_GC ();
1740 NEXT;
1743 CASE (Bequal):
1745 Lisp_Object v1;
1746 v1 = POP;
1747 TOP = Fequal (TOP, v1);
1748 NEXT;
1751 CASE (Bnthcdr):
1753 Lisp_Object v1;
1754 BEFORE_POTENTIAL_GC ();
1755 v1 = POP;
1756 TOP = Fnthcdr (TOP, v1);
1757 AFTER_POTENTIAL_GC ();
1758 NEXT;
1761 CASE (Belt):
1763 Lisp_Object v1, v2;
1764 if (CONSP (TOP))
1766 /* Exchange args and then do nth. */
1767 EMACS_INT n;
1768 BEFORE_POTENTIAL_GC ();
1769 v2 = POP;
1770 v1 = TOP;
1771 CHECK_NUMBER (v2);
1772 AFTER_POTENTIAL_GC ();
1773 n = XINT (v2);
1774 immediate_quit = 1;
1775 while (--n >= 0 && CONSP (v1))
1776 v1 = XCDR (v1);
1777 immediate_quit = 0;
1778 TOP = CAR (v1);
1780 else
1782 BEFORE_POTENTIAL_GC ();
1783 v1 = POP;
1784 TOP = Felt (TOP, v1);
1785 AFTER_POTENTIAL_GC ();
1787 NEXT;
1790 CASE (Bmember):
1792 Lisp_Object v1;
1793 BEFORE_POTENTIAL_GC ();
1794 v1 = POP;
1795 TOP = Fmember (TOP, v1);
1796 AFTER_POTENTIAL_GC ();
1797 NEXT;
1800 CASE (Bassq):
1802 Lisp_Object v1;
1803 BEFORE_POTENTIAL_GC ();
1804 v1 = POP;
1805 TOP = Fassq (TOP, v1);
1806 AFTER_POTENTIAL_GC ();
1807 NEXT;
1810 CASE (Bnreverse):
1811 BEFORE_POTENTIAL_GC ();
1812 TOP = Fnreverse (TOP);
1813 AFTER_POTENTIAL_GC ();
1814 NEXT;
1816 CASE (Bsetcar):
1818 Lisp_Object v1;
1819 BEFORE_POTENTIAL_GC ();
1820 v1 = POP;
1821 TOP = Fsetcar (TOP, v1);
1822 AFTER_POTENTIAL_GC ();
1823 NEXT;
1826 CASE (Bsetcdr):
1828 Lisp_Object v1;
1829 BEFORE_POTENTIAL_GC ();
1830 v1 = POP;
1831 TOP = Fsetcdr (TOP, v1);
1832 AFTER_POTENTIAL_GC ();
1833 NEXT;
1836 CASE (Bcar_safe):
1838 Lisp_Object v1;
1839 v1 = TOP;
1840 TOP = CAR_SAFE (v1);
1841 NEXT;
1844 CASE (Bcdr_safe):
1846 Lisp_Object v1;
1847 v1 = TOP;
1848 TOP = CDR_SAFE (v1);
1849 NEXT;
1852 CASE (Bnconc):
1853 BEFORE_POTENTIAL_GC ();
1854 DISCARD (1);
1855 TOP = Fnconc (2, &TOP);
1856 AFTER_POTENTIAL_GC ();
1857 NEXT;
1859 CASE (Bnumberp):
1860 TOP = (NUMBERP (TOP) ? Qt : Qnil);
1861 NEXT;
1863 CASE (Bintegerp):
1864 TOP = INTEGERP (TOP) ? Qt : Qnil;
1865 NEXT;
1867 #ifdef BYTE_CODE_SAFE
1868 /* These are intentionally written using 'case' syntax,
1869 because they are incompatible with the threaded
1870 interpreter. */
1872 case Bset_mark:
1873 BEFORE_POTENTIAL_GC ();
1874 error ("set-mark is an obsolete bytecode");
1875 AFTER_POTENTIAL_GC ();
1876 break;
1877 case Bscan_buffer:
1878 BEFORE_POTENTIAL_GC ();
1879 error ("scan-buffer is an obsolete bytecode");
1880 AFTER_POTENTIAL_GC ();
1881 break;
1882 #endif
1884 CASE_ABORT:
1885 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1886 for that instead. */
1887 /* CASE (Bstack_ref): */
1888 error ("Invalid byte opcode");
1890 /* Handy byte-codes for lexical binding. */
1891 CASE (Bstack_ref1):
1892 CASE (Bstack_ref2):
1893 CASE (Bstack_ref3):
1894 CASE (Bstack_ref4):
1895 CASE (Bstack_ref5):
1897 Lisp_Object *ptr = top - (op - Bstack_ref);
1898 PUSH (*ptr);
1899 NEXT;
1901 CASE (Bstack_ref6):
1903 Lisp_Object *ptr = top - (FETCH);
1904 PUSH (*ptr);
1905 NEXT;
1907 CASE (Bstack_ref7):
1909 Lisp_Object *ptr = top - (FETCH2);
1910 PUSH (*ptr);
1911 NEXT;
1913 CASE (Bstack_set):
1914 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1916 Lisp_Object *ptr = top - (FETCH);
1917 *ptr = POP;
1918 NEXT;
1920 CASE (Bstack_set2):
1922 Lisp_Object *ptr = top - (FETCH2);
1923 *ptr = POP;
1924 NEXT;
1926 CASE (BdiscardN):
1927 op = FETCH;
1928 if (op & 0x80)
1930 op &= 0x7F;
1931 top[-op] = TOP;
1933 DISCARD (op);
1934 NEXT;
1936 CASE_DEFAULT
1937 CASE (Bconstant):
1938 #ifdef BYTE_CODE_SAFE
1939 if (op < Bconstant)
1941 emacs_abort ();
1943 if ((op -= Bconstant) >= const_length)
1945 emacs_abort ();
1947 PUSH (vectorp[op]);
1948 #else
1949 PUSH (vectorp[op - Bconstant]);
1950 #endif
1951 NEXT;
1955 exit:
1957 byte_stack_list = byte_stack_list->next;
1959 /* Binds and unbinds are supposed to be compiled balanced. */
1960 if (SPECPDL_INDEX () != count)
1961 #ifdef BYTE_CODE_SAFE
1962 error ("binding stack not balanced (serious byte compiler bug)");
1963 #else
1964 emacs_abort ();
1965 #endif
1967 return result;
1970 void
1971 syms_of_bytecode (void)
1973 defsubr (&Sbyte_code);
1975 #ifdef BYTE_CODE_METER
1977 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter,
1978 doc: /* A vector of vectors which holds a histogram of byte-code usage.
1979 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1980 opcode CODE has been executed.
1981 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1982 indicates how many times the byte opcodes CODE1 and CODE2 have been
1983 executed in succession. */);
1985 DEFVAR_BOOL ("byte-metering-on", byte_metering_on,
1986 doc: /* If non-nil, keep profiling information on byte code usage.
1987 The variable byte-code-meter indicates how often each byte opcode is used.
1988 If a symbol has a property named `byte-code-meter' whose value is an
1989 integer, it is incremented each time that symbol's function is called. */);
1991 byte_metering_on = 0;
1992 Vbyte_code_meter = Fmake_vector (make_number (256), make_number (0));
1993 DEFSYM (Qbyte_code_meter, "byte-code-meter");
1995 int i = 256;
1996 while (i--)
1997 ASET (Vbyte_code_meter, i,
1998 Fmake_vector (make_number (256), make_number (0)));
2000 #endif