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