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