]> code.delx.au - gnu-emacs/blob - src/bytecode.c
bb7922d54a49f3f3eb98aa0e0b21ecd0b6e30542
[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 /*
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 #if 0 /* CHECK_FRAME_FONT */
438 {
439 struct frame *f = SELECTED_FRAME ();
440 if (FRAME_X_P (f)
441 && FRAME_FONT (f)->direction != 0
442 && FRAME_FONT (f)->direction != 1)
443 emacs_abort ();
444 }
445 #endif
446
447 CHECK_STRING (bytestr);
448 CHECK_VECTOR (vector);
449 CHECK_NATNUM (maxdepth);
450
451 #ifdef BYTE_CODE_SAFE
452 const_length = ASIZE (vector);
453 #endif
454
455 if (STRING_MULTIBYTE (bytestr))
456 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
457 because they produced a raw 8-bit string for byte-code and now
458 such a byte-code string is loaded as multibyte while raw 8-bit
459 characters converted to multibyte form. Thus, now we must
460 convert them back to the originally intended unibyte form. */
461 bytestr = Fstring_as_unibyte (bytestr);
462
463 #ifdef BYTE_CODE_SAFE
464 bytestr_length = SBYTES (bytestr);
465 #endif
466 vectorp = XVECTOR (vector)->contents;
467
468 stack.byte_string = bytestr;
469 stack.pc = stack.byte_string_start = SDATA (bytestr);
470 if (MAX_ALLOCA / word_size <= XFASTINT (maxdepth))
471 memory_full (SIZE_MAX);
472 top = alloca ((XFASTINT (maxdepth) + 1) * sizeof *top);
473 stack.next = byte_stack_list;
474 byte_stack_list = &stack;
475
476 #ifdef BYTE_CODE_SAFE
477 stacke = stack.bottom - 1 + XFASTINT (maxdepth);
478 #endif
479
480 if (INTEGERP (args_template))
481 {
482 ptrdiff_t at = XINT (args_template);
483 bool rest = (at & 128) != 0;
484 int mandatory = at & 127;
485 ptrdiff_t nonrest = at >> 8;
486 eassert (mandatory <= nonrest);
487 if (nargs <= nonrest)
488 {
489 ptrdiff_t i;
490 for (i = 0 ; i < nargs; i++, args++)
491 PUSH (*args);
492 if (nargs < mandatory)
493 /* Too few arguments. */
494 Fsignal (Qwrong_number_of_arguments,
495 list2 (Fcons (make_number (mandatory),
496 rest ? Qand_rest : make_number (nonrest)),
497 make_number (nargs)));
498 else
499 {
500 for (; i < nonrest; i++)
501 PUSH (Qnil);
502 if (rest)
503 PUSH (Qnil);
504 }
505 }
506 else if (rest)
507 {
508 ptrdiff_t i;
509 for (i = 0 ; i < nonrest; i++, args++)
510 PUSH (*args);
511 PUSH (Flist (nargs - nonrest, args));
512 }
513 else
514 /* Too many arguments. */
515 Fsignal (Qwrong_number_of_arguments,
516 list2 (Fcons (make_number (mandatory), make_number (nonrest)),
517 make_number (nargs)));
518 }
519 else if (! NILP (args_template))
520 /* We should push some arguments on the stack. */
521 {
522 error ("Unknown args template!");
523 }
524
525 while (1)
526 {
527 #ifdef BYTE_CODE_SAFE
528 if (top > stacke)
529 emacs_abort ();
530 else if (top < stack.bottom - 1)
531 emacs_abort ();
532 #endif
533
534 #ifdef BYTE_CODE_METER
535 prev_op = this_op;
536 this_op = op = FETCH;
537 METER_CODE (prev_op, op);
538 #else
539 #ifndef BYTE_CODE_THREADED
540 op = FETCH;
541 #endif
542 #endif
543
544 /* The interpreter can be compiled one of two ways: as an
545 ordinary switch-based interpreter, or as a threaded
546 interpreter. The threaded interpreter relies on GCC's
547 computed goto extension, so it is not available everywhere.
548 Threading provides a performance boost. These macros are how
549 we allow the code to be compiled both ways. */
550 #ifdef BYTE_CODE_THREADED
551 /* The CASE macro introduces an instruction's body. It is
552 either a label or a case label. */
553 #define CASE(OP) insn_ ## OP
554 /* NEXT is invoked at the end of an instruction to go to the
555 next instruction. It is either a computed goto, or a
556 plain break. */
557 #define NEXT goto *(targets[op = FETCH])
558 /* FIRST is like NEXT, but is only used at the start of the
559 interpreter body. In the switch-based interpreter it is the
560 switch, so the threaded definition must include a semicolon. */
561 #define FIRST NEXT;
562 /* Most cases are labeled with the CASE macro, above.
563 CASE_DEFAULT is one exception; it is used if the interpreter
564 being built requires a default case. The threaded
565 interpreter does not, because the dispatch table is
566 completely filled. */
567 #define CASE_DEFAULT
568 /* This introduces an instruction that is known to call abort. */
569 #define CASE_ABORT CASE (Bstack_ref): CASE (default)
570 #else
571 /* See above for the meaning of the various defines. */
572 #define CASE(OP) case OP
573 #define NEXT break
574 #define FIRST switch (op)
575 #define CASE_DEFAULT case 255: default:
576 #define CASE_ABORT case 0
577 #endif
578
579 #ifdef BYTE_CODE_THREADED
580
581 /* A convenience define that saves us a lot of typing and makes
582 the table clearer. */
583 #define LABEL(OP) [OP] = &&insn_ ## OP
584
585 #if GNUC_PREREQ (4, 6, 0)
586 # pragma GCC diagnostic push
587 # pragma GCC diagnostic ignored "-Woverride-init"
588 #elif defined __clang__
589 # pragma GCC diagnostic push
590 # pragma GCC diagnostic ignored "-Winitializer-overrides"
591 #endif
592
593 /* This is the dispatch table for the threaded interpreter. */
594 static const void *const targets[256] =
595 {
596 [0 ... (Bconstant - 1)] = &&insn_default,
597 [Bconstant ... 255] = &&insn_Bconstant,
598
599 #define DEFINE(name, value) LABEL (name) ,
600 BYTE_CODES
601 #undef DEFINE
602 };
603
604 #if GNUC_PREREQ (4, 6, 0) || defined __clang__
605 # pragma GCC diagnostic pop
606 #endif
607
608 #endif
609
610
611 FIRST
612 {
613 CASE (Bvarref7):
614 op = FETCH2;
615 goto varref;
616
617 CASE (Bvarref):
618 CASE (Bvarref1):
619 CASE (Bvarref2):
620 CASE (Bvarref3):
621 CASE (Bvarref4):
622 CASE (Bvarref5):
623 op = op - Bvarref;
624 goto varref;
625
626 /* This seems to be the most frequently executed byte-code
627 among the Bvarref's, so avoid a goto here. */
628 CASE (Bvarref6):
629 op = FETCH;
630 varref:
631 {
632 Lisp_Object v1, v2;
633
634 v1 = vectorp[op];
635 if (SYMBOLP (v1))
636 {
637 if (XSYMBOL (v1)->redirect != SYMBOL_PLAINVAL
638 || (v2 = SYMBOL_VAL (XSYMBOL (v1)),
639 EQ (v2, Qunbound)))
640 {
641 v2 = Fsymbol_value (v1);
642 }
643 }
644 else
645 {
646 v2 = Fsymbol_value (v1);
647 }
648 PUSH (v2);
649 NEXT;
650 }
651
652 CASE (Bgotoifnil):
653 {
654 Lisp_Object v1;
655 maybe_gc ();
656 op = FETCH2;
657 v1 = POP;
658 if (NILP (v1))
659 {
660 BYTE_CODE_QUIT;
661 CHECK_RANGE (op);
662 stack.pc = stack.byte_string_start + op;
663 }
664 NEXT;
665 }
666
667 CASE (Bcar):
668 {
669 Lisp_Object v1;
670 v1 = TOP;
671 if (CONSP (v1))
672 TOP = XCAR (v1);
673 else if (NILP (v1))
674 TOP = Qnil;
675 else
676 {
677 wrong_type_argument (Qlistp, v1);
678 }
679 NEXT;
680 }
681
682 CASE (Beq):
683 {
684 Lisp_Object v1;
685 v1 = POP;
686 TOP = EQ (v1, TOP) ? Qt : Qnil;
687 NEXT;
688 }
689
690 CASE (Bmemq):
691 {
692 Lisp_Object v1;
693 v1 = POP;
694 TOP = Fmemq (TOP, v1);
695 NEXT;
696 }
697
698 CASE (Bcdr):
699 {
700 Lisp_Object v1;
701 v1 = TOP;
702 if (CONSP (v1))
703 TOP = XCDR (v1);
704 else if (NILP (v1))
705 TOP = Qnil;
706 else
707 {
708 wrong_type_argument (Qlistp, v1);
709 }
710 NEXT;
711 }
712
713 CASE (Bvarset):
714 CASE (Bvarset1):
715 CASE (Bvarset2):
716 CASE (Bvarset3):
717 CASE (Bvarset4):
718 CASE (Bvarset5):
719 op -= Bvarset;
720 goto varset;
721
722 CASE (Bvarset7):
723 op = FETCH2;
724 goto varset;
725
726 CASE (Bvarset6):
727 op = FETCH;
728 varset:
729 {
730 Lisp_Object sym, val;
731
732 sym = vectorp[op];
733 val = TOP;
734
735 /* Inline the most common case. */
736 if (SYMBOLP (sym)
737 && !EQ (val, Qunbound)
738 && !XSYMBOL (sym)->redirect
739 && !SYMBOL_CONSTANT_P (sym))
740 SET_SYMBOL_VAL (XSYMBOL (sym), val);
741 else
742 {
743 set_internal (sym, val, Qnil, 0);
744 }
745 }
746 (void) POP;
747 NEXT;
748
749 CASE (Bdup):
750 {
751 Lisp_Object v1;
752 v1 = TOP;
753 PUSH (v1);
754 NEXT;
755 }
756
757 /* ------------------ */
758
759 CASE (Bvarbind6):
760 op = FETCH;
761 goto varbind;
762
763 CASE (Bvarbind7):
764 op = FETCH2;
765 goto varbind;
766
767 CASE (Bvarbind):
768 CASE (Bvarbind1):
769 CASE (Bvarbind2):
770 CASE (Bvarbind3):
771 CASE (Bvarbind4):
772 CASE (Bvarbind5):
773 op -= Bvarbind;
774 varbind:
775 /* Specbind can signal and thus GC. */
776 specbind (vectorp[op], POP);
777 NEXT;
778
779 CASE (Bcall6):
780 op = FETCH;
781 goto docall;
782
783 CASE (Bcall7):
784 op = FETCH2;
785 goto docall;
786
787 CASE (Bcall):
788 CASE (Bcall1):
789 CASE (Bcall2):
790 CASE (Bcall3):
791 CASE (Bcall4):
792 CASE (Bcall5):
793 op -= Bcall;
794 docall:
795 {
796 DISCARD (op);
797 #ifdef BYTE_CODE_METER
798 if (byte_metering_on && SYMBOLP (TOP))
799 {
800 Lisp_Object v1, v2;
801
802 v1 = TOP;
803 v2 = Fget (v1, Qbyte_code_meter);
804 if (INTEGERP (v2)
805 && XINT (v2) < MOST_POSITIVE_FIXNUM)
806 {
807 XSETINT (v2, XINT (v2) + 1);
808 Fput (v1, Qbyte_code_meter, v2);
809 }
810 }
811 #endif
812 TOP = Ffuncall (op + 1, &TOP);
813 NEXT;
814 }
815
816 CASE (Bunbind6):
817 op = FETCH;
818 goto dounbind;
819
820 CASE (Bunbind7):
821 op = FETCH2;
822 goto dounbind;
823
824 CASE (Bunbind):
825 CASE (Bunbind1):
826 CASE (Bunbind2):
827 CASE (Bunbind3):
828 CASE (Bunbind4):
829 CASE (Bunbind5):
830 op -= Bunbind;
831 dounbind:
832 unbind_to (SPECPDL_INDEX () - op, Qnil);
833 NEXT;
834
835 CASE (Bunbind_all): /* Obsolete. Never used. */
836 /* To unbind back to the beginning of this frame. Not used yet,
837 but will be needed for tail-recursion elimination. */
838 unbind_to (count, Qnil);
839 NEXT;
840
841 CASE (Bgoto):
842 maybe_gc ();
843 BYTE_CODE_QUIT;
844 op = FETCH2; /* pc = FETCH2 loses since FETCH2 contains pc++ */
845 CHECK_RANGE (op);
846 stack.pc = stack.byte_string_start + op;
847 NEXT;
848
849 CASE (Bgotoifnonnil):
850 {
851 Lisp_Object v1;
852 maybe_gc ();
853 op = FETCH2;
854 v1 = POP;
855 if (!NILP (v1))
856 {
857 BYTE_CODE_QUIT;
858 CHECK_RANGE (op);
859 stack.pc = stack.byte_string_start + op;
860 }
861 NEXT;
862 }
863
864 CASE (Bgotoifnilelsepop):
865 maybe_gc ();
866 op = FETCH2;
867 if (NILP (TOP))
868 {
869 BYTE_CODE_QUIT;
870 CHECK_RANGE (op);
871 stack.pc = stack.byte_string_start + op;
872 }
873 else DISCARD (1);
874 NEXT;
875
876 CASE (Bgotoifnonnilelsepop):
877 maybe_gc ();
878 op = FETCH2;
879 if (!NILP (TOP))
880 {
881 BYTE_CODE_QUIT;
882 CHECK_RANGE (op);
883 stack.pc = stack.byte_string_start + op;
884 }
885 else DISCARD (1);
886 NEXT;
887
888 CASE (BRgoto):
889 maybe_gc ();
890 BYTE_CODE_QUIT;
891 stack.pc += (int) *stack.pc - 127;
892 NEXT;
893
894 CASE (BRgotoifnil):
895 {
896 Lisp_Object v1;
897 maybe_gc ();
898 v1 = POP;
899 if (NILP (v1))
900 {
901 BYTE_CODE_QUIT;
902 stack.pc += (int) *stack.pc - 128;
903 }
904 stack.pc++;
905 NEXT;
906 }
907
908 CASE (BRgotoifnonnil):
909 {
910 Lisp_Object v1;
911 maybe_gc ();
912 v1 = POP;
913 if (!NILP (v1))
914 {
915 BYTE_CODE_QUIT;
916 stack.pc += (int) *stack.pc - 128;
917 }
918 stack.pc++;
919 NEXT;
920 }
921
922 CASE (BRgotoifnilelsepop):
923 maybe_gc ();
924 op = *stack.pc++;
925 if (NILP (TOP))
926 {
927 BYTE_CODE_QUIT;
928 stack.pc += op - 128;
929 }
930 else DISCARD (1);
931 NEXT;
932
933 CASE (BRgotoifnonnilelsepop):
934 maybe_gc ();
935 op = *stack.pc++;
936 if (!NILP (TOP))
937 {
938 BYTE_CODE_QUIT;
939 stack.pc += op - 128;
940 }
941 else DISCARD (1);
942 NEXT;
943
944 CASE (Breturn):
945 result = POP;
946 goto exit;
947
948 CASE (Bdiscard):
949 DISCARD (1);
950 NEXT;
951
952 CASE (Bconstant2):
953 PUSH (vectorp[FETCH2]);
954 NEXT;
955
956 CASE (Bsave_excursion):
957 record_unwind_protect (save_excursion_restore,
958 save_excursion_save ());
959 NEXT;
960
961 CASE (Bsave_current_buffer): /* Obsolete since ??. */
962 CASE (Bsave_current_buffer_1):
963 record_unwind_current_buffer ();
964 NEXT;
965
966 CASE (Bsave_window_excursion): /* Obsolete since 24.1. */
967 {
968 ptrdiff_t count1 = SPECPDL_INDEX ();
969 record_unwind_protect (restore_window_configuration,
970 Fcurrent_window_configuration (Qnil));
971 TOP = Fprogn (TOP);
972 unbind_to (count1, TOP);
973 NEXT;
974 }
975
976 CASE (Bsave_restriction):
977 record_unwind_protect (save_restriction_restore,
978 save_restriction_save ());
979 NEXT;
980
981 CASE (Bcatch): /* Obsolete since 24.4. */
982 {
983 Lisp_Object v1;
984 v1 = POP;
985 TOP = internal_catch (TOP, eval_sub, v1);
986 NEXT;
987 }
988
989 CASE (Bpushcatch): /* New in 24.4. */
990 type = CATCHER;
991 goto pushhandler;
992 CASE (Bpushconditioncase): /* New in 24.4. */
993 type = CONDITION_CASE;
994 pushhandler:
995 {
996 Lisp_Object tag = POP;
997 int dest = FETCH2;
998
999 struct handler *c = push_handler (tag, type);
1000 c->bytecode_dest = dest;
1001 c->bytecode_top = top;
1002
1003 if (sys_setjmp (c->jmp))
1004 {
1005 struct handler *c = handlerlist;
1006 int dest;
1007 top = c->bytecode_top;
1008 dest = c->bytecode_dest;
1009 handlerlist = c->next;
1010 PUSH (c->val);
1011 CHECK_RANGE (dest);
1012 /* Might have been re-set by longjmp! */
1013 stack.byte_string_start = SDATA (stack.byte_string);
1014 stack.pc = stack.byte_string_start + dest;
1015 }
1016
1017 NEXT;
1018 }
1019
1020 CASE (Bpophandler): /* New in 24.4. */
1021 {
1022 handlerlist = handlerlist->next;
1023 NEXT;
1024 }
1025
1026 CASE (Bunwind_protect): /* FIXME: avoid closure for lexbind. */
1027 {
1028 Lisp_Object handler = POP;
1029 /* Support for a function here is new in 24.4. */
1030 record_unwind_protect (NILP (Ffunctionp (handler))
1031 ? unwind_body : bcall0,
1032 handler);
1033 NEXT;
1034 }
1035
1036 CASE (Bcondition_case): /* Obsolete since 24.4. */
1037 {
1038 Lisp_Object handlers, body;
1039 handlers = POP;
1040 body = POP;
1041 TOP = internal_lisp_condition_case (TOP, body, handlers);
1042 NEXT;
1043 }
1044
1045 CASE (Btemp_output_buffer_setup): /* Obsolete since 24.1. */
1046 CHECK_STRING (TOP);
1047 temp_output_buffer_setup (SSDATA (TOP));
1048 TOP = Vstandard_output;
1049 NEXT;
1050
1051 CASE (Btemp_output_buffer_show): /* Obsolete since 24.1. */
1052 {
1053 Lisp_Object v1;
1054 v1 = POP;
1055 temp_output_buffer_show (TOP);
1056 TOP = v1;
1057 /* pop binding of standard-output */
1058 unbind_to (SPECPDL_INDEX () - 1, Qnil);
1059 NEXT;
1060 }
1061
1062 CASE (Bnth):
1063 {
1064 Lisp_Object v1, v2;
1065 EMACS_INT n;
1066 v1 = POP;
1067 v2 = TOP;
1068 CHECK_NUMBER (v2);
1069 n = XINT (v2);
1070 immediate_quit = 1;
1071 while (--n >= 0 && CONSP (v1))
1072 v1 = XCDR (v1);
1073 immediate_quit = 0;
1074 TOP = CAR (v1);
1075 NEXT;
1076 }
1077
1078 CASE (Bsymbolp):
1079 TOP = SYMBOLP (TOP) ? Qt : Qnil;
1080 NEXT;
1081
1082 CASE (Bconsp):
1083 TOP = CONSP (TOP) ? Qt : Qnil;
1084 NEXT;
1085
1086 CASE (Bstringp):
1087 TOP = STRINGP (TOP) ? Qt : Qnil;
1088 NEXT;
1089
1090 CASE (Blistp):
1091 TOP = CONSP (TOP) || NILP (TOP) ? Qt : Qnil;
1092 NEXT;
1093
1094 CASE (Bnot):
1095 TOP = NILP (TOP) ? Qt : Qnil;
1096 NEXT;
1097
1098 CASE (Bcons):
1099 {
1100 Lisp_Object v1;
1101 v1 = POP;
1102 TOP = Fcons (TOP, v1);
1103 NEXT;
1104 }
1105
1106 CASE (Blist1):
1107 TOP = list1 (TOP);
1108 NEXT;
1109
1110 CASE (Blist2):
1111 {
1112 Lisp_Object v1;
1113 v1 = POP;
1114 TOP = list2 (TOP, v1);
1115 NEXT;
1116 }
1117
1118 CASE (Blist3):
1119 DISCARD (2);
1120 TOP = Flist (3, &TOP);
1121 NEXT;
1122
1123 CASE (Blist4):
1124 DISCARD (3);
1125 TOP = Flist (4, &TOP);
1126 NEXT;
1127
1128 CASE (BlistN):
1129 op = FETCH;
1130 DISCARD (op - 1);
1131 TOP = Flist (op, &TOP);
1132 NEXT;
1133
1134 CASE (Blength):
1135 TOP = Flength (TOP);
1136 NEXT;
1137
1138 CASE (Baref):
1139 {
1140 Lisp_Object v1;
1141 v1 = POP;
1142 TOP = Faref (TOP, v1);
1143 NEXT;
1144 }
1145
1146 CASE (Baset):
1147 {
1148 Lisp_Object v1, v2;
1149 v2 = POP; v1 = POP;
1150 TOP = Faset (TOP, v1, v2);
1151 NEXT;
1152 }
1153
1154 CASE (Bsymbol_value):
1155 TOP = Fsymbol_value (TOP);
1156 NEXT;
1157
1158 CASE (Bsymbol_function):
1159 TOP = Fsymbol_function (TOP);
1160 NEXT;
1161
1162 CASE (Bset):
1163 {
1164 Lisp_Object v1;
1165 v1 = POP;
1166 TOP = Fset (TOP, v1);
1167 NEXT;
1168 }
1169
1170 CASE (Bfset):
1171 {
1172 Lisp_Object v1;
1173 v1 = POP;
1174 TOP = Ffset (TOP, v1);
1175 NEXT;
1176 }
1177
1178 CASE (Bget):
1179 {
1180 Lisp_Object v1;
1181 v1 = POP;
1182 TOP = Fget (TOP, v1);
1183 NEXT;
1184 }
1185
1186 CASE (Bsubstring):
1187 {
1188 Lisp_Object v1, v2;
1189 v2 = POP; v1 = POP;
1190 TOP = Fsubstring (TOP, v1, v2);
1191 NEXT;
1192 }
1193
1194 CASE (Bconcat2):
1195 DISCARD (1);
1196 TOP = Fconcat (2, &TOP);
1197 NEXT;
1198
1199 CASE (Bconcat3):
1200 DISCARD (2);
1201 TOP = Fconcat (3, &TOP);
1202 NEXT;
1203
1204 CASE (Bconcat4):
1205 DISCARD (3);
1206 TOP = Fconcat (4, &TOP);
1207 NEXT;
1208
1209 CASE (BconcatN):
1210 op = FETCH;
1211 DISCARD (op - 1);
1212 TOP = Fconcat (op, &TOP);
1213 NEXT;
1214
1215 CASE (Bsub1):
1216 {
1217 Lisp_Object v1;
1218 v1 = TOP;
1219 if (INTEGERP (v1))
1220 {
1221 XSETINT (v1, XINT (v1) - 1);
1222 TOP = v1;
1223 }
1224 else
1225 {
1226 TOP = Fsub1 (v1);
1227 }
1228 NEXT;
1229 }
1230
1231 CASE (Badd1):
1232 {
1233 Lisp_Object v1;
1234 v1 = TOP;
1235 if (INTEGERP (v1))
1236 {
1237 XSETINT (v1, XINT (v1) + 1);
1238 TOP = v1;
1239 }
1240 else
1241 {
1242 TOP = Fadd1 (v1);
1243 }
1244 NEXT;
1245 }
1246
1247 CASE (Beqlsign):
1248 {
1249 Lisp_Object v1, v2;
1250 v2 = POP; v1 = TOP;
1251 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1);
1252 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2);
1253 if (FLOATP (v1) || FLOATP (v2))
1254 {
1255 double f1, f2;
1256
1257 f1 = (FLOATP (v1) ? XFLOAT_DATA (v1) : XINT (v1));
1258 f2 = (FLOATP (v2) ? XFLOAT_DATA (v2) : XINT (v2));
1259 TOP = (f1 == f2 ? Qt : Qnil);
1260 }
1261 else
1262 TOP = (XINT (v1) == XINT (v2) ? Qt : Qnil);
1263 NEXT;
1264 }
1265
1266 CASE (Bgtr):
1267 {
1268 Lisp_Object v1;
1269 v1 = POP;
1270 TOP = arithcompare (TOP, v1, ARITH_GRTR);
1271 NEXT;
1272 }
1273
1274 CASE (Blss):
1275 {
1276 Lisp_Object v1;
1277 v1 = POP;
1278 TOP = arithcompare (TOP, v1, ARITH_LESS);
1279 NEXT;
1280 }
1281
1282 CASE (Bleq):
1283 {
1284 Lisp_Object v1;
1285 v1 = POP;
1286 TOP = arithcompare (TOP, v1, ARITH_LESS_OR_EQUAL);
1287 NEXT;
1288 }
1289
1290 CASE (Bgeq):
1291 {
1292 Lisp_Object v1;
1293 v1 = POP;
1294 TOP = arithcompare (TOP, v1, ARITH_GRTR_OR_EQUAL);
1295 NEXT;
1296 }
1297
1298 CASE (Bdiff):
1299 DISCARD (1);
1300 TOP = Fminus (2, &TOP);
1301 NEXT;
1302
1303 CASE (Bnegate):
1304 {
1305 Lisp_Object v1;
1306 v1 = TOP;
1307 if (INTEGERP (v1))
1308 {
1309 XSETINT (v1, - XINT (v1));
1310 TOP = v1;
1311 }
1312 else
1313 {
1314 TOP = Fminus (1, &TOP);
1315 }
1316 NEXT;
1317 }
1318
1319 CASE (Bplus):
1320 DISCARD (1);
1321 TOP = Fplus (2, &TOP);
1322 NEXT;
1323
1324 CASE (Bmax):
1325 DISCARD (1);
1326 TOP = Fmax (2, &TOP);
1327 NEXT;
1328
1329 CASE (Bmin):
1330 DISCARD (1);
1331 TOP = Fmin (2, &TOP);
1332 NEXT;
1333
1334 CASE (Bmult):
1335 DISCARD (1);
1336 TOP = Ftimes (2, &TOP);
1337 NEXT;
1338
1339 CASE (Bquo):
1340 DISCARD (1);
1341 TOP = Fquo (2, &TOP);
1342 NEXT;
1343
1344 CASE (Brem):
1345 {
1346 Lisp_Object v1;
1347 v1 = POP;
1348 TOP = Frem (TOP, v1);
1349 NEXT;
1350 }
1351
1352 CASE (Bpoint):
1353 {
1354 Lisp_Object v1;
1355 XSETFASTINT (v1, PT);
1356 PUSH (v1);
1357 NEXT;
1358 }
1359
1360 CASE (Bgoto_char):
1361 TOP = Fgoto_char (TOP);
1362 NEXT;
1363
1364 CASE (Binsert):
1365 TOP = Finsert (1, &TOP);
1366 NEXT;
1367
1368 CASE (BinsertN):
1369 op = FETCH;
1370 DISCARD (op - 1);
1371 TOP = Finsert (op, &TOP);
1372 NEXT;
1373
1374 CASE (Bpoint_max):
1375 {
1376 Lisp_Object v1;
1377 XSETFASTINT (v1, ZV);
1378 PUSH (v1);
1379 NEXT;
1380 }
1381
1382 CASE (Bpoint_min):
1383 {
1384 Lisp_Object v1;
1385 XSETFASTINT (v1, BEGV);
1386 PUSH (v1);
1387 NEXT;
1388 }
1389
1390 CASE (Bchar_after):
1391 TOP = Fchar_after (TOP);
1392 NEXT;
1393
1394 CASE (Bfollowing_char):
1395 {
1396 Lisp_Object v1;
1397 v1 = Ffollowing_char ();
1398 PUSH (v1);
1399 NEXT;
1400 }
1401
1402 CASE (Bpreceding_char):
1403 {
1404 Lisp_Object v1;
1405 v1 = Fprevious_char ();
1406 PUSH (v1);
1407 NEXT;
1408 }
1409
1410 CASE (Bcurrent_column):
1411 {
1412 Lisp_Object v1;
1413 XSETFASTINT (v1, current_column ());
1414 PUSH (v1);
1415 NEXT;
1416 }
1417
1418 CASE (Bindent_to):
1419 TOP = Findent_to (TOP, Qnil);
1420 NEXT;
1421
1422 CASE (Beolp):
1423 PUSH (Feolp ());
1424 NEXT;
1425
1426 CASE (Beobp):
1427 PUSH (Feobp ());
1428 NEXT;
1429
1430 CASE (Bbolp):
1431 PUSH (Fbolp ());
1432 NEXT;
1433
1434 CASE (Bbobp):
1435 PUSH (Fbobp ());
1436 NEXT;
1437
1438 CASE (Bcurrent_buffer):
1439 PUSH (Fcurrent_buffer ());
1440 NEXT;
1441
1442 CASE (Bset_buffer):
1443 TOP = Fset_buffer (TOP);
1444 NEXT;
1445
1446 CASE (Binteractive_p): /* Obsolete since 24.1. */
1447 PUSH (call0 (intern ("interactive-p")));
1448 NEXT;
1449
1450 CASE (Bforward_char):
1451 TOP = Fforward_char (TOP);
1452 NEXT;
1453
1454 CASE (Bforward_word):
1455 TOP = Fforward_word (TOP);
1456 NEXT;
1457
1458 CASE (Bskip_chars_forward):
1459 {
1460 Lisp_Object v1;
1461 v1 = POP;
1462 TOP = Fskip_chars_forward (TOP, v1);
1463 NEXT;
1464 }
1465
1466 CASE (Bskip_chars_backward):
1467 {
1468 Lisp_Object v1;
1469 v1 = POP;
1470 TOP = Fskip_chars_backward (TOP, v1);
1471 NEXT;
1472 }
1473
1474 CASE (Bforward_line):
1475 TOP = Fforward_line (TOP);
1476 NEXT;
1477
1478 CASE (Bchar_syntax):
1479 {
1480 int c;
1481
1482 CHECK_CHARACTER (TOP);
1483 c = XFASTINT (TOP);
1484 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
1485 MAKE_CHAR_MULTIBYTE (c);
1486 XSETFASTINT (TOP, syntax_code_spec[SYNTAX (c)]);
1487 }
1488 NEXT;
1489
1490 CASE (Bbuffer_substring):
1491 {
1492 Lisp_Object v1;
1493 v1 = POP;
1494 TOP = Fbuffer_substring (TOP, v1);
1495 NEXT;
1496 }
1497
1498 CASE (Bdelete_region):
1499 {
1500 Lisp_Object v1;
1501 v1 = POP;
1502 TOP = Fdelete_region (TOP, v1);
1503 NEXT;
1504 }
1505
1506 CASE (Bnarrow_to_region):
1507 {
1508 Lisp_Object v1;
1509 v1 = POP;
1510 TOP = Fnarrow_to_region (TOP, v1);
1511 NEXT;
1512 }
1513
1514 CASE (Bwiden):
1515 PUSH (Fwiden ());
1516 NEXT;
1517
1518 CASE (Bend_of_line):
1519 TOP = Fend_of_line (TOP);
1520 NEXT;
1521
1522 CASE (Bset_marker):
1523 {
1524 Lisp_Object v1, v2;
1525 v1 = POP;
1526 v2 = POP;
1527 TOP = Fset_marker (TOP, v2, v1);
1528 NEXT;
1529 }
1530
1531 CASE (Bmatch_beginning):
1532 TOP = Fmatch_beginning (TOP);
1533 NEXT;
1534
1535 CASE (Bmatch_end):
1536 TOP = Fmatch_end (TOP);
1537 NEXT;
1538
1539 CASE (Bupcase):
1540 TOP = Fupcase (TOP);
1541 NEXT;
1542
1543 CASE (Bdowncase):
1544 TOP = Fdowncase (TOP);
1545 NEXT;
1546
1547 CASE (Bstringeqlsign):
1548 {
1549 Lisp_Object v1;
1550 v1 = POP;
1551 TOP = Fstring_equal (TOP, v1);
1552 NEXT;
1553 }
1554
1555 CASE (Bstringlss):
1556 {
1557 Lisp_Object v1;
1558 v1 = POP;
1559 TOP = Fstring_lessp (TOP, v1);
1560 NEXT;
1561 }
1562
1563 CASE (Bequal):
1564 {
1565 Lisp_Object v1;
1566 v1 = POP;
1567 TOP = Fequal (TOP, v1);
1568 NEXT;
1569 }
1570
1571 CASE (Bnthcdr):
1572 {
1573 Lisp_Object v1;
1574 v1 = POP;
1575 TOP = Fnthcdr (TOP, v1);
1576 NEXT;
1577 }
1578
1579 CASE (Belt):
1580 {
1581 Lisp_Object v1, v2;
1582 if (CONSP (TOP))
1583 {
1584 /* Exchange args and then do nth. */
1585 EMACS_INT n;
1586 v2 = POP;
1587 v1 = TOP;
1588 CHECK_NUMBER (v2);
1589 n = XINT (v2);
1590 immediate_quit = 1;
1591 while (--n >= 0 && CONSP (v1))
1592 v1 = XCDR (v1);
1593 immediate_quit = 0;
1594 TOP = CAR (v1);
1595 }
1596 else
1597 {
1598 v1 = POP;
1599 TOP = Felt (TOP, v1);
1600 }
1601 NEXT;
1602 }
1603
1604 CASE (Bmember):
1605 {
1606 Lisp_Object v1;
1607 v1 = POP;
1608 TOP = Fmember (TOP, v1);
1609 NEXT;
1610 }
1611
1612 CASE (Bassq):
1613 {
1614 Lisp_Object v1;
1615 v1 = POP;
1616 TOP = Fassq (TOP, v1);
1617 NEXT;
1618 }
1619
1620 CASE (Bnreverse):
1621 TOP = Fnreverse (TOP);
1622 NEXT;
1623
1624 CASE (Bsetcar):
1625 {
1626 Lisp_Object v1;
1627 v1 = POP;
1628 TOP = Fsetcar (TOP, v1);
1629 NEXT;
1630 }
1631
1632 CASE (Bsetcdr):
1633 {
1634 Lisp_Object v1;
1635 v1 = POP;
1636 TOP = Fsetcdr (TOP, v1);
1637 NEXT;
1638 }
1639
1640 CASE (Bcar_safe):
1641 {
1642 Lisp_Object v1;
1643 v1 = TOP;
1644 TOP = CAR_SAFE (v1);
1645 NEXT;
1646 }
1647
1648 CASE (Bcdr_safe):
1649 {
1650 Lisp_Object v1;
1651 v1 = TOP;
1652 TOP = CDR_SAFE (v1);
1653 NEXT;
1654 }
1655
1656 CASE (Bnconc):
1657 DISCARD (1);
1658 TOP = Fnconc (2, &TOP);
1659 NEXT;
1660
1661 CASE (Bnumberp):
1662 TOP = (NUMBERP (TOP) ? Qt : Qnil);
1663 NEXT;
1664
1665 CASE (Bintegerp):
1666 TOP = INTEGERP (TOP) ? Qt : Qnil;
1667 NEXT;
1668
1669 #ifdef BYTE_CODE_SAFE
1670 /* These are intentionally written using 'case' syntax,
1671 because they are incompatible with the threaded
1672 interpreter. */
1673
1674 case Bset_mark:
1675 error ("set-mark is an obsolete bytecode");
1676 break;
1677 case Bscan_buffer:
1678 error ("scan-buffer is an obsolete bytecode");
1679 break;
1680 #endif
1681
1682 CASE_ABORT:
1683 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1684 for that instead. */
1685 /* CASE (Bstack_ref): */
1686 call3 (Qerror,
1687 build_string ("Invalid byte opcode: op=%s, ptr=%d"),
1688 make_number (op),
1689 make_number ((stack.pc - 1) - stack.byte_string_start));
1690
1691 /* Handy byte-codes for lexical binding. */
1692 CASE (Bstack_ref1):
1693 CASE (Bstack_ref2):
1694 CASE (Bstack_ref3):
1695 CASE (Bstack_ref4):
1696 CASE (Bstack_ref5):
1697 {
1698 Lisp_Object *ptr = top - (op - Bstack_ref);
1699 PUSH (*ptr);
1700 NEXT;
1701 }
1702 CASE (Bstack_ref6):
1703 {
1704 Lisp_Object *ptr = top - (FETCH);
1705 PUSH (*ptr);
1706 NEXT;
1707 }
1708 CASE (Bstack_ref7):
1709 {
1710 Lisp_Object *ptr = top - (FETCH2);
1711 PUSH (*ptr);
1712 NEXT;
1713 }
1714 CASE (Bstack_set):
1715 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1716 {
1717 Lisp_Object *ptr = top - (FETCH);
1718 *ptr = POP;
1719 NEXT;
1720 }
1721 CASE (Bstack_set2):
1722 {
1723 Lisp_Object *ptr = top - (FETCH2);
1724 *ptr = POP;
1725 NEXT;
1726 }
1727 CASE (BdiscardN):
1728 op = FETCH;
1729 if (op & 0x80)
1730 {
1731 op &= 0x7F;
1732 top[-op] = TOP;
1733 }
1734 DISCARD (op);
1735 NEXT;
1736
1737 CASE_DEFAULT
1738 CASE (Bconstant):
1739 #ifdef BYTE_CODE_SAFE
1740 if (op < Bconstant)
1741 {
1742 emacs_abort ();
1743 }
1744 if ((op -= Bconstant) >= const_length)
1745 {
1746 emacs_abort ();
1747 }
1748 PUSH (vectorp[op]);
1749 #else
1750 PUSH (vectorp[op - Bconstant]);
1751 #endif
1752 NEXT;
1753 }
1754 }
1755
1756 exit:
1757
1758 byte_stack_list = byte_stack_list->next;
1759
1760 /* Binds and unbinds are supposed to be compiled balanced. */
1761 if (SPECPDL_INDEX () != count)
1762 {
1763 if (SPECPDL_INDEX () > count)
1764 unbind_to (count, Qnil);
1765 error ("binding stack not balanced (serious byte compiler bug)");
1766 }
1767
1768 return result;
1769 }
1770
1771 /* `args_template' has the same meaning as in exec_byte_code() above. */
1772 Lisp_Object
1773 get_byte_code_arity (Lisp_Object args_template)
1774 {
1775 eassert (NATNUMP (args_template));
1776 EMACS_INT at = XINT (args_template);
1777 bool rest = (at & 128) != 0;
1778 int mandatory = at & 127;
1779 EMACS_INT nonrest = at >> 8;
1780
1781 return Fcons (make_number (mandatory),
1782 rest ? Qmany : make_number (nonrest));
1783 }
1784
1785 void
1786 syms_of_bytecode (void)
1787 {
1788 defsubr (&Sbyte_code);
1789
1790 #ifdef BYTE_CODE_METER
1791
1792 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter,
1793 doc: /* A vector of vectors which holds a histogram of byte-code usage.
1794 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1795 opcode CODE has been executed.
1796 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1797 indicates how many times the byte opcodes CODE1 and CODE2 have been
1798 executed in succession. */);
1799
1800 DEFVAR_BOOL ("byte-metering-on", byte_metering_on,
1801 doc: /* If non-nil, keep profiling information on byte code usage.
1802 The variable byte-code-meter indicates how often each byte opcode is used.
1803 If a symbol has a property named `byte-code-meter' whose value is an
1804 integer, it is incremented each time that symbol's function is called. */);
1805
1806 byte_metering_on = 0;
1807 Vbyte_code_meter = Fmake_vector (make_number (256), make_number (0));
1808 DEFSYM (Qbyte_code_meter, "byte-code-meter");
1809 {
1810 int i = 256;
1811 while (i--)
1812 ASET (Vbyte_code_meter, i,
1813 Fmake_vector (make_number (256), make_number (0)));
1814 }
1815 #endif
1816 }