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