1 /* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985-1988, 1993, 2000-2016 Free Software Foundation,
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or (at
10 your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
23 #include "blockinput.h"
24 #include "character.h"
30 #ifdef CHECK_FRAME_FONT
36 * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for
37 * debugging the byte compiler...)
39 * define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
41 /* #define BYTE_CODE_SAFE */
42 /* #define BYTE_CODE_METER */
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
48 #if (defined __GNUC__ && !defined __STRICT_ANSI__ \
49 && !defined BYTE_CODE_SAFE && !defined BYTE_CODE_METER)
50 #define BYTE_CODE_THREADED
54 #ifdef BYTE_CODE_METER
56 #define METER_2(code1, code2) AREF (AREF (Vbyte_code_meter, code1), code2)
57 #define METER_1(code) METER_2 (0, code)
59 #define METER_CODE(last_code, this_code) \
61 if (byte_metering_on) \
63 if (XFASTINT (METER_1 (this_code)) < MOST_POSITIVE_FIXNUM) \
64 XSETFASTINT (METER_1 (this_code), \
65 XFASTINT (METER_1 (this_code)) + 1); \
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); \
74 #endif /* BYTE_CODE_METER */
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) \
129 DEFINE (Bpophandler, 060) \
130 DEFINE (Bpushconditioncase, 061) \
131 DEFINE (Bpushcatch, 062) \
134 DEFINE (Bsymbolp, 071) \
135 DEFINE (Bconsp, 072) \
136 DEFINE (Bstringp, 073) \
137 DEFINE (Blistp, 074) \
139 DEFINE (Bmemq, 076) \
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) \
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. */ \
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) \
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) \
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) \
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. */ \
227 DEFINE (Bunbind_all, 0222) /* Obsolete. Never used. */ \
229 DEFINE (Bset_marker, 0223) \
230 DEFINE (Bmatch_beginning, 0224) \
231 DEFINE (Bmatch_end, 0225) \
232 DEFINE (Bupcase, 0226) \
233 DEFINE (Bdowncase, 0227) \
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) \
253 DEFINE (BRgoto, 0252) \
254 DEFINE (BRgotoifnil, 0253) \
255 DEFINE (BRgotoifnonnil, 0254) \
256 DEFINE (BRgotoifnilelsepop, 0255) \
257 DEFINE (BRgotoifnonnilelsepop, 0256) \
259 DEFINE (BlistN, 0257) \
260 DEFINE (BconcatN, 0260) \
261 DEFINE (BinsertN, 0261) \
263 /* Bstack_ref is code 0. */ \
264 DEFINE (Bstack_set, 0262) \
265 DEFINE (Bstack_set2, 0263) \
266 DEFINE (BdiscardN, 0266) \
268 DEFINE (Bconstant, 0300)
272 #define DEFINE(name, value) name = value,
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 */
282 /* Whether to maintain a `top' and `bottom' field in the stack frame. */
283 #define BYTE_MAINTAIN_TOP BYTE_CODE_SAFE
285 /* Structure describing a value stack used during byte-code execution
290 /* Program counter. This points into the byte_string below
291 and is relocated when that string is relocated. */
292 const unsigned char *pc
;
294 /* Top and bottom of stack. The bottom points to an area of memory
295 allocated with alloca in Fbyte_code. */
296 #if BYTE_MAINTAIN_TOP
297 Lisp_Object
*top
, *bottom
;
300 /* The string containing the byte-code, and its current address.
301 Storing this here protects it from GC. */
302 Lisp_Object byte_string
;
303 const unsigned char *byte_string_start
;
305 /* Next entry in byte_stack_list. */
306 struct byte_stack
*next
;
309 /* A list of currently active byte-code execution value stacks.
310 Fbyte_code adds an entry to the head of this list before it starts
311 processing byte-code, and it removes the entry again when it is
312 done. Signaling an error truncates the list. */
314 struct byte_stack
*byte_stack_list
;
317 /* Relocate program counters in the stacks on byte_stack_list. Called
318 when GC has completed. */
321 relocate_byte_stack (void)
323 struct byte_stack
*stack
;
325 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
327 if (stack
->byte_string_start
!= SDATA (stack
->byte_string
))
329 ptrdiff_t offset
= stack
->pc
- stack
->byte_string_start
;
330 stack
->byte_string_start
= SDATA (stack
->byte_string
);
331 stack
->pc
= stack
->byte_string_start
+ offset
;
337 /* Fetch the next byte from the bytecode stream. */
339 #ifdef BYTE_CODE_SAFE
340 #define FETCH (eassert (stack.byte_string_start == SDATA (stack.byte_string)), *stack.pc++)
342 #define FETCH *stack.pc++
345 /* Fetch two bytes from the bytecode stream and make a 16-bit number
348 #define FETCH2 (op = FETCH, op + (FETCH << 8))
350 /* Push x onto the execution stack. This used to be #define PUSH(x)
351 (*++stackp = (x)) This oddity is necessary because Alliant can't be
352 bothered to compile the preincrement operator properly, as of 4/91.
355 #define PUSH(x) (top++, *top = (x))
357 /* Pop a value off the execution stack. */
361 /* Discard n values from the execution stack. */
363 #define DISCARD(n) (top -= (n))
365 /* Get the value which is at the top of the execution stack, but don't
370 /* Actions that must be performed before and after calling a function
373 #if !BYTE_MAINTAIN_TOP
374 #define BEFORE_POTENTIAL_GC() ((void)0)
375 #define AFTER_POTENTIAL_GC() ((void)0)
377 #define BEFORE_POTENTIAL_GC() stack.top = top
378 #define AFTER_POTENTIAL_GC() stack.top = NULL
381 /* Garbage collect if we have consed enough since the last time.
382 We do this at every branch, to avoid loops that never GC. */
386 BEFORE_POTENTIAL_GC (); \
388 AFTER_POTENTIAL_GC (); \
391 /* Check for jumping out of range. */
393 #ifdef BYTE_CODE_SAFE
395 #define CHECK_RANGE(ARG) \
396 if (ARG >= bytestr_length) emacs_abort ()
398 #else /* not BYTE_CODE_SAFE */
400 #define CHECK_RANGE(ARG)
402 #endif /* not BYTE_CODE_SAFE */
404 /* A version of the QUIT macro which makes sure that the stack top is
405 set before signaling `quit'. */
407 #define BYTE_CODE_QUIT \
409 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
411 Lisp_Object flag = Vquit_flag; \
413 BEFORE_POTENTIAL_GC (); \
414 if (EQ (Vthrow_on_input, flag)) \
415 Fthrow (Vthrow_on_input, Qt); \
416 Fsignal (Qquit, Qnil); \
417 AFTER_POTENTIAL_GC (); \
419 else if (pending_signals) \
420 process_pending_signals (); \
424 DEFUN ("byte-code", Fbyte_code
, Sbyte_code
, 3, 3, 0,
425 doc
: /* Function used internally in byte-compiled code.
426 The first argument, BYTESTR, is a string of byte code;
427 the second, VECTOR, a vector of constants;
428 the third, MAXDEPTH, the maximum stack depth used in this function.
429 If the third argument is incorrect, Emacs may crash. */)
430 (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
)
432 return exec_byte_code (bytestr
, vector
, maxdepth
, Qnil
, 0, NULL
);
436 bcall0 (Lisp_Object f
)
441 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
442 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
443 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
444 argument list (including &rest, &optional, etc.), and ARGS, of size
445 NARGS, should be a vector of the actual arguments. The arguments in
446 ARGS are pushed on the stack according to ARGS_TEMPLATE before
447 executing BYTESTR. */
450 exec_byte_code (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
,
451 Lisp_Object args_template
, ptrdiff_t nargs
, Lisp_Object
*args
)
453 ptrdiff_t count
= SPECPDL_INDEX ();
454 #ifdef BYTE_CODE_METER
455 int volatile this_op
= 0;
459 /* Lisp_Object v1, v2; */
460 Lisp_Object
*vectorp
;
461 #ifdef BYTE_CODE_SAFE
462 ptrdiff_t const_length
;
464 ptrdiff_t bytestr_length
;
466 struct byte_stack stack
;
469 enum handlertype type
;
471 #if 0 /* CHECK_FRAME_FONT */
473 struct frame
*f
= SELECTED_FRAME ();
475 && FRAME_FONT (f
)->direction
!= 0
476 && FRAME_FONT (f
)->direction
!= 1)
481 CHECK_STRING (bytestr
);
482 CHECK_VECTOR (vector
);
483 CHECK_NATNUM (maxdepth
);
485 #ifdef BYTE_CODE_SAFE
486 const_length
= ASIZE (vector
);
489 if (STRING_MULTIBYTE (bytestr
))
490 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
491 because they produced a raw 8-bit string for byte-code and now
492 such a byte-code string is loaded as multibyte while raw 8-bit
493 characters converted to multibyte form. Thus, now we must
494 convert them back to the originally intended unibyte form. */
495 bytestr
= Fstring_as_unibyte (bytestr
);
497 #ifdef BYTE_CODE_SAFE
498 bytestr_length
= SBYTES (bytestr
);
500 vectorp
= XVECTOR (vector
)->contents
;
502 stack
.byte_string
= bytestr
;
503 stack
.pc
= stack
.byte_string_start
= SDATA (bytestr
);
504 if (MAX_ALLOCA
/ word_size
<= XFASTINT (maxdepth
))
505 memory_full (SIZE_MAX
);
506 top
= alloca ((XFASTINT (maxdepth
) + 1) * sizeof *top
);
507 #if BYTE_MAINTAIN_TOP
508 stack
.bottom
= top
+ 1;
511 stack
.next
= byte_stack_list
;
512 byte_stack_list
= &stack
;
514 #ifdef BYTE_CODE_SAFE
515 stacke
= stack
.bottom
- 1 + XFASTINT (maxdepth
);
518 if (INTEGERP (args_template
))
520 ptrdiff_t at
= XINT (args_template
);
521 bool rest
= (at
& 128) != 0;
522 int mandatory
= at
& 127;
523 ptrdiff_t nonrest
= at
>> 8;
524 eassert (mandatory
<= nonrest
);
525 if (nargs
<= nonrest
)
528 for (i
= 0 ; i
< nargs
; i
++, args
++)
530 if (nargs
< mandatory
)
531 /* Too few arguments. */
532 Fsignal (Qwrong_number_of_arguments
,
533 list2 (Fcons (make_number (mandatory
),
534 rest
? Qand_rest
: make_number (nonrest
)),
535 make_number (nargs
)));
538 for (; i
< nonrest
; i
++)
547 for (i
= 0 ; i
< nonrest
; i
++, args
++)
549 PUSH (Flist (nargs
- nonrest
, args
));
552 /* Too many arguments. */
553 Fsignal (Qwrong_number_of_arguments
,
554 list2 (Fcons (make_number (mandatory
), make_number (nonrest
)),
555 make_number (nargs
)));
557 else if (! NILP (args_template
))
558 /* We should push some arguments on the stack. */
560 error ("Unknown args template!");
565 #ifdef BYTE_CODE_SAFE
568 else if (top
< stack
.bottom
- 1)
572 #ifdef BYTE_CODE_METER
574 this_op
= op
= FETCH
;
575 METER_CODE (prev_op
, op
);
577 #ifndef BYTE_CODE_THREADED
582 /* The interpreter can be compiled one of two ways: as an
583 ordinary switch-based interpreter, or as a threaded
584 interpreter. The threaded interpreter relies on GCC's
585 computed goto extension, so it is not available everywhere.
586 Threading provides a performance boost. These macros are how
587 we allow the code to be compiled both ways. */
588 #ifdef BYTE_CODE_THREADED
589 /* The CASE macro introduces an instruction's body. It is
590 either a label or a case label. */
591 #define CASE(OP) insn_ ## OP
592 /* NEXT is invoked at the end of an instruction to go to the
593 next instruction. It is either a computed goto, or a
595 #define NEXT goto *(targets[op = FETCH])
596 /* FIRST is like NEXT, but is only used at the start of the
597 interpreter body. In the switch-based interpreter it is the
598 switch, so the threaded definition must include a semicolon. */
600 /* Most cases are labeled with the CASE macro, above.
601 CASE_DEFAULT is one exception; it is used if the interpreter
602 being built requires a default case. The threaded
603 interpreter does not, because the dispatch table is
604 completely filled. */
606 /* This introduces an instruction that is known to call abort. */
607 #define CASE_ABORT CASE (Bstack_ref): CASE (default)
609 /* See above for the meaning of the various defines. */
610 #define CASE(OP) case OP
612 #define FIRST switch (op)
613 #define CASE_DEFAULT case 255: default:
614 #define CASE_ABORT case 0
617 #ifdef BYTE_CODE_THREADED
619 /* A convenience define that saves us a lot of typing and makes
620 the table clearer. */
621 #define LABEL(OP) [OP] = &&insn_ ## OP
623 #if GNUC_PREREQ (4, 6, 0)
624 # pragma GCC diagnostic push
625 # pragma GCC diagnostic ignored "-Woverride-init"
626 #elif defined __clang__
627 # pragma GCC diagnostic push
628 # pragma GCC diagnostic ignored "-Winitializer-overrides"
631 /* This is the dispatch table for the threaded interpreter. */
632 static const void *const targets
[256] =
634 [0 ... (Bconstant
- 1)] = &&insn_default
,
635 [Bconstant
... 255] = &&insn_Bconstant
,
637 #define DEFINE(name, value) LABEL (name) ,
642 #if GNUC_PREREQ (4, 6, 0) || defined __clang__
643 # pragma GCC diagnostic pop
664 /* This seems to be the most frequently executed byte-code
665 among the Bvarref's, so avoid a goto here. */
675 if (XSYMBOL (v1
)->redirect
!= SYMBOL_PLAINVAL
676 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)),
679 BEFORE_POTENTIAL_GC ();
680 v2
= Fsymbol_value (v1
);
681 AFTER_POTENTIAL_GC ();
686 BEFORE_POTENTIAL_GC ();
687 v2
= Fsymbol_value (v1
);
688 AFTER_POTENTIAL_GC ();
704 stack
.pc
= stack
.byte_string_start
+ op
;
719 BEFORE_POTENTIAL_GC ();
720 wrong_type_argument (Qlistp
, v1
);
729 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
736 BEFORE_POTENTIAL_GC ();
738 TOP
= Fmemq (TOP
, v1
);
739 AFTER_POTENTIAL_GC ();
753 BEFORE_POTENTIAL_GC ();
754 wrong_type_argument (Qlistp
, v1
);
776 Lisp_Object sym
, val
;
781 /* Inline the most common case. */
783 && !EQ (val
, Qunbound
)
784 && !XSYMBOL (sym
)->redirect
785 && !SYMBOL_CONSTANT_P (sym
))
786 SET_SYMBOL_VAL (XSYMBOL (sym
), val
);
789 BEFORE_POTENTIAL_GC ();
790 set_internal (sym
, val
, Qnil
, 0);
791 AFTER_POTENTIAL_GC ();
805 /* ------------------ */
823 /* Specbind can signal and thus GC. */
824 BEFORE_POTENTIAL_GC ();
825 specbind (vectorp
[op
], POP
);
826 AFTER_POTENTIAL_GC ();
846 BEFORE_POTENTIAL_GC ();
848 #ifdef BYTE_CODE_METER
849 if (byte_metering_on
&& SYMBOLP (TOP
))
854 v2
= Fget (v1
, Qbyte_code_meter
);
856 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
858 XSETINT (v2
, XINT (v2
) + 1);
859 Fput (v1
, Qbyte_code_meter
, v2
);
863 TOP
= Ffuncall (op
+ 1, &TOP
);
864 AFTER_POTENTIAL_GC ();
884 BEFORE_POTENTIAL_GC ();
885 unbind_to (SPECPDL_INDEX () - op
, Qnil
);
886 AFTER_POTENTIAL_GC ();
889 CASE (Bunbind_all
): /* Obsolete. Never used. */
890 /* To unbind back to the beginning of this frame. Not used yet,
891 but will be needed for tail-recursion elimination. */
892 BEFORE_POTENTIAL_GC ();
893 unbind_to (count
, Qnil
);
894 AFTER_POTENTIAL_GC ();
900 op
= FETCH2
; /* pc = FETCH2 loses since FETCH2 contains pc++ */
902 stack
.pc
= stack
.byte_string_start
+ op
;
905 CASE (Bgotoifnonnil
):
915 stack
.pc
= stack
.byte_string_start
+ op
;
920 CASE (Bgotoifnilelsepop
):
927 stack
.pc
= stack
.byte_string_start
+ op
;
932 CASE (Bgotoifnonnilelsepop
):
939 stack
.pc
= stack
.byte_string_start
+ op
;
947 stack
.pc
+= (int) *stack
.pc
- 127;
958 stack
.pc
+= (int) *stack
.pc
- 128;
964 CASE (BRgotoifnonnil
):
972 stack
.pc
+= (int) *stack
.pc
- 128;
978 CASE (BRgotoifnilelsepop
):
984 stack
.pc
+= op
- 128;
989 CASE (BRgotoifnonnilelsepop
):
995 stack
.pc
+= op
- 128;
1009 PUSH (vectorp
[FETCH2
]);
1012 CASE (Bsave_excursion
):
1013 record_unwind_protect (save_excursion_restore
,
1014 save_excursion_save ());
1017 CASE (Bsave_current_buffer
): /* Obsolete since ??. */
1018 CASE (Bsave_current_buffer_1
):
1019 record_unwind_current_buffer ();
1022 CASE (Bsave_window_excursion
): /* Obsolete since 24.1. */
1024 ptrdiff_t count1
= SPECPDL_INDEX ();
1025 record_unwind_protect (restore_window_configuration
,
1026 Fcurrent_window_configuration (Qnil
));
1027 BEFORE_POTENTIAL_GC ();
1029 unbind_to (count1
, TOP
);
1030 AFTER_POTENTIAL_GC ();
1034 CASE (Bsave_restriction
):
1035 record_unwind_protect (save_restriction_restore
,
1036 save_restriction_save ());
1039 CASE (Bcatch
): /* Obsolete since 24.4. */
1042 BEFORE_POTENTIAL_GC ();
1044 TOP
= internal_catch (TOP
, eval_sub
, v1
);
1045 AFTER_POTENTIAL_GC ();
1049 CASE (Bpushcatch
): /* New in 24.4. */
1052 CASE (Bpushconditioncase
): /* New in 24.4. */
1053 type
= CONDITION_CASE
;
1056 Lisp_Object tag
= POP
;
1059 struct handler
*c
= push_handler (tag
, type
);
1060 c
->bytecode_dest
= dest
;
1061 c
->bytecode_top
= top
;
1063 if (sys_setjmp (c
->jmp
))
1065 struct handler
*c
= handlerlist
;
1067 top
= c
->bytecode_top
;
1068 dest
= c
->bytecode_dest
;
1069 handlerlist
= c
->next
;
1072 /* Might have been re-set by longjmp! */
1073 stack
.byte_string_start
= SDATA (stack
.byte_string
);
1074 stack
.pc
= stack
.byte_string_start
+ dest
;
1080 CASE (Bpophandler
): /* New in 24.4. */
1082 handlerlist
= handlerlist
->next
;
1086 CASE (Bunwind_protect
): /* FIXME: avoid closure for lexbind. */
1088 Lisp_Object handler
= POP
;
1089 /* Support for a function here is new in 24.4. */
1090 record_unwind_protect (NILP (Ffunctionp (handler
))
1091 ? unwind_body
: bcall0
,
1096 CASE (Bcondition_case
): /* Obsolete since 24.4. */
1098 Lisp_Object handlers
, body
;
1101 BEFORE_POTENTIAL_GC ();
1102 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
);
1103 AFTER_POTENTIAL_GC ();
1107 CASE (Btemp_output_buffer_setup
): /* Obsolete since 24.1. */
1108 BEFORE_POTENTIAL_GC ();
1110 temp_output_buffer_setup (SSDATA (TOP
));
1111 AFTER_POTENTIAL_GC ();
1112 TOP
= Vstandard_output
;
1115 CASE (Btemp_output_buffer_show
): /* Obsolete since 24.1. */
1118 BEFORE_POTENTIAL_GC ();
1120 temp_output_buffer_show (TOP
);
1122 /* pop binding of standard-output */
1123 unbind_to (SPECPDL_INDEX () - 1, Qnil
);
1124 AFTER_POTENTIAL_GC ();
1132 BEFORE_POTENTIAL_GC ();
1138 while (--n
>= 0 && CONSP (v1
))
1142 AFTER_POTENTIAL_GC ();
1147 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
1151 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
1155 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
1159 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
1163 TOP
= NILP (TOP
) ? Qt
: Qnil
;
1170 TOP
= Fcons (TOP
, v1
);
1182 TOP
= list2 (TOP
, v1
);
1188 TOP
= Flist (3, &TOP
);
1193 TOP
= Flist (4, &TOP
);
1199 TOP
= Flist (op
, &TOP
);
1203 BEFORE_POTENTIAL_GC ();
1204 TOP
= Flength (TOP
);
1205 AFTER_POTENTIAL_GC ();
1211 BEFORE_POTENTIAL_GC ();
1213 TOP
= Faref (TOP
, v1
);
1214 AFTER_POTENTIAL_GC ();
1221 BEFORE_POTENTIAL_GC ();
1223 TOP
= Faset (TOP
, v1
, v2
);
1224 AFTER_POTENTIAL_GC ();
1228 CASE (Bsymbol_value
):
1229 BEFORE_POTENTIAL_GC ();
1230 TOP
= Fsymbol_value (TOP
);
1231 AFTER_POTENTIAL_GC ();
1234 CASE (Bsymbol_function
):
1235 BEFORE_POTENTIAL_GC ();
1236 TOP
= Fsymbol_function (TOP
);
1237 AFTER_POTENTIAL_GC ();
1243 BEFORE_POTENTIAL_GC ();
1245 TOP
= Fset (TOP
, v1
);
1246 AFTER_POTENTIAL_GC ();
1253 BEFORE_POTENTIAL_GC ();
1255 TOP
= Ffset (TOP
, v1
);
1256 AFTER_POTENTIAL_GC ();
1263 BEFORE_POTENTIAL_GC ();
1265 TOP
= Fget (TOP
, v1
);
1266 AFTER_POTENTIAL_GC ();
1273 BEFORE_POTENTIAL_GC ();
1275 TOP
= Fsubstring (TOP
, v1
, v2
);
1276 AFTER_POTENTIAL_GC ();
1281 BEFORE_POTENTIAL_GC ();
1283 TOP
= Fconcat (2, &TOP
);
1284 AFTER_POTENTIAL_GC ();
1288 BEFORE_POTENTIAL_GC ();
1290 TOP
= Fconcat (3, &TOP
);
1291 AFTER_POTENTIAL_GC ();
1295 BEFORE_POTENTIAL_GC ();
1297 TOP
= Fconcat (4, &TOP
);
1298 AFTER_POTENTIAL_GC ();
1303 BEFORE_POTENTIAL_GC ();
1305 TOP
= Fconcat (op
, &TOP
);
1306 AFTER_POTENTIAL_GC ();
1315 XSETINT (v1
, XINT (v1
) - 1);
1320 BEFORE_POTENTIAL_GC ();
1322 AFTER_POTENTIAL_GC ();
1333 XSETINT (v1
, XINT (v1
) + 1);
1338 BEFORE_POTENTIAL_GC ();
1340 AFTER_POTENTIAL_GC ();
1348 BEFORE_POTENTIAL_GC ();
1350 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
1351 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
1352 AFTER_POTENTIAL_GC ();
1353 if (FLOATP (v1
) || FLOATP (v2
))
1357 f1
= (FLOATP (v1
) ? XFLOAT_DATA (v1
) : XINT (v1
));
1358 f2
= (FLOATP (v2
) ? XFLOAT_DATA (v2
) : XINT (v2
));
1359 TOP
= (f1
== f2
? Qt
: Qnil
);
1362 TOP
= (XINT (v1
) == XINT (v2
) ? Qt
: Qnil
);
1369 BEFORE_POTENTIAL_GC ();
1371 TOP
= arithcompare (TOP
, v1
, ARITH_GRTR
);
1372 AFTER_POTENTIAL_GC ();
1379 BEFORE_POTENTIAL_GC ();
1381 TOP
= arithcompare (TOP
, v1
, ARITH_LESS
);
1382 AFTER_POTENTIAL_GC ();
1389 BEFORE_POTENTIAL_GC ();
1391 TOP
= arithcompare (TOP
, v1
, ARITH_LESS_OR_EQUAL
);
1392 AFTER_POTENTIAL_GC ();
1399 BEFORE_POTENTIAL_GC ();
1401 TOP
= arithcompare (TOP
, v1
, ARITH_GRTR_OR_EQUAL
);
1402 AFTER_POTENTIAL_GC ();
1407 BEFORE_POTENTIAL_GC ();
1409 TOP
= Fminus (2, &TOP
);
1410 AFTER_POTENTIAL_GC ();
1419 XSETINT (v1
, - XINT (v1
));
1424 BEFORE_POTENTIAL_GC ();
1425 TOP
= Fminus (1, &TOP
);
1426 AFTER_POTENTIAL_GC ();
1432 BEFORE_POTENTIAL_GC ();
1434 TOP
= Fplus (2, &TOP
);
1435 AFTER_POTENTIAL_GC ();
1439 BEFORE_POTENTIAL_GC ();
1441 TOP
= Fmax (2, &TOP
);
1442 AFTER_POTENTIAL_GC ();
1446 BEFORE_POTENTIAL_GC ();
1448 TOP
= Fmin (2, &TOP
);
1449 AFTER_POTENTIAL_GC ();
1453 BEFORE_POTENTIAL_GC ();
1455 TOP
= Ftimes (2, &TOP
);
1456 AFTER_POTENTIAL_GC ();
1460 BEFORE_POTENTIAL_GC ();
1462 TOP
= Fquo (2, &TOP
);
1463 AFTER_POTENTIAL_GC ();
1469 BEFORE_POTENTIAL_GC ();
1471 TOP
= Frem (TOP
, v1
);
1472 AFTER_POTENTIAL_GC ();
1479 XSETFASTINT (v1
, PT
);
1485 BEFORE_POTENTIAL_GC ();
1486 TOP
= Fgoto_char (TOP
);
1487 AFTER_POTENTIAL_GC ();
1491 BEFORE_POTENTIAL_GC ();
1492 TOP
= Finsert (1, &TOP
);
1493 AFTER_POTENTIAL_GC ();
1498 BEFORE_POTENTIAL_GC ();
1500 TOP
= Finsert (op
, &TOP
);
1501 AFTER_POTENTIAL_GC ();
1507 XSETFASTINT (v1
, ZV
);
1515 XSETFASTINT (v1
, BEGV
);
1521 BEFORE_POTENTIAL_GC ();
1522 TOP
= Fchar_after (TOP
);
1523 AFTER_POTENTIAL_GC ();
1526 CASE (Bfollowing_char
):
1529 BEFORE_POTENTIAL_GC ();
1530 v1
= Ffollowing_char ();
1531 AFTER_POTENTIAL_GC ();
1536 CASE (Bpreceding_char
):
1539 BEFORE_POTENTIAL_GC ();
1540 v1
= Fprevious_char ();
1541 AFTER_POTENTIAL_GC ();
1546 CASE (Bcurrent_column
):
1549 BEFORE_POTENTIAL_GC ();
1550 XSETFASTINT (v1
, current_column ());
1551 AFTER_POTENTIAL_GC ();
1557 BEFORE_POTENTIAL_GC ();
1558 TOP
= Findent_to (TOP
, Qnil
);
1559 AFTER_POTENTIAL_GC ();
1578 CASE (Bcurrent_buffer
):
1579 PUSH (Fcurrent_buffer ());
1583 BEFORE_POTENTIAL_GC ();
1584 TOP
= Fset_buffer (TOP
);
1585 AFTER_POTENTIAL_GC ();
1588 CASE (Binteractive_p
): /* Obsolete since 24.1. */
1589 BEFORE_POTENTIAL_GC ();
1590 PUSH (call0 (intern ("interactive-p")));
1591 AFTER_POTENTIAL_GC ();
1594 CASE (Bforward_char
):
1595 BEFORE_POTENTIAL_GC ();
1596 TOP
= Fforward_char (TOP
);
1597 AFTER_POTENTIAL_GC ();
1600 CASE (Bforward_word
):
1601 BEFORE_POTENTIAL_GC ();
1602 TOP
= Fforward_word (TOP
);
1603 AFTER_POTENTIAL_GC ();
1606 CASE (Bskip_chars_forward
):
1609 BEFORE_POTENTIAL_GC ();
1611 TOP
= Fskip_chars_forward (TOP
, v1
);
1612 AFTER_POTENTIAL_GC ();
1616 CASE (Bskip_chars_backward
):
1619 BEFORE_POTENTIAL_GC ();
1621 TOP
= Fskip_chars_backward (TOP
, v1
);
1622 AFTER_POTENTIAL_GC ();
1626 CASE (Bforward_line
):
1627 BEFORE_POTENTIAL_GC ();
1628 TOP
= Fforward_line (TOP
);
1629 AFTER_POTENTIAL_GC ();
1632 CASE (Bchar_syntax
):
1636 BEFORE_POTENTIAL_GC ();
1637 CHECK_CHARACTER (TOP
);
1638 AFTER_POTENTIAL_GC ();
1640 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
1641 MAKE_CHAR_MULTIBYTE (c
);
1642 XSETFASTINT (TOP
, syntax_code_spec
[SYNTAX (c
)]);
1646 CASE (Bbuffer_substring
):
1649 BEFORE_POTENTIAL_GC ();
1651 TOP
= Fbuffer_substring (TOP
, v1
);
1652 AFTER_POTENTIAL_GC ();
1656 CASE (Bdelete_region
):
1659 BEFORE_POTENTIAL_GC ();
1661 TOP
= Fdelete_region (TOP
, v1
);
1662 AFTER_POTENTIAL_GC ();
1666 CASE (Bnarrow_to_region
):
1669 BEFORE_POTENTIAL_GC ();
1671 TOP
= Fnarrow_to_region (TOP
, v1
);
1672 AFTER_POTENTIAL_GC ();
1677 BEFORE_POTENTIAL_GC ();
1679 AFTER_POTENTIAL_GC ();
1682 CASE (Bend_of_line
):
1683 BEFORE_POTENTIAL_GC ();
1684 TOP
= Fend_of_line (TOP
);
1685 AFTER_POTENTIAL_GC ();
1691 BEFORE_POTENTIAL_GC ();
1694 TOP
= Fset_marker (TOP
, v2
, v1
);
1695 AFTER_POTENTIAL_GC ();
1699 CASE (Bmatch_beginning
):
1700 BEFORE_POTENTIAL_GC ();
1701 TOP
= Fmatch_beginning (TOP
);
1702 AFTER_POTENTIAL_GC ();
1706 BEFORE_POTENTIAL_GC ();
1707 TOP
= Fmatch_end (TOP
);
1708 AFTER_POTENTIAL_GC ();
1712 BEFORE_POTENTIAL_GC ();
1713 TOP
= Fupcase (TOP
);
1714 AFTER_POTENTIAL_GC ();
1718 BEFORE_POTENTIAL_GC ();
1719 TOP
= Fdowncase (TOP
);
1720 AFTER_POTENTIAL_GC ();
1723 CASE (Bstringeqlsign
):
1726 BEFORE_POTENTIAL_GC ();
1728 TOP
= Fstring_equal (TOP
, v1
);
1729 AFTER_POTENTIAL_GC ();
1736 BEFORE_POTENTIAL_GC ();
1738 TOP
= Fstring_lessp (TOP
, v1
);
1739 AFTER_POTENTIAL_GC ();
1747 TOP
= Fequal (TOP
, v1
);
1754 BEFORE_POTENTIAL_GC ();
1756 TOP
= Fnthcdr (TOP
, v1
);
1757 AFTER_POTENTIAL_GC ();
1766 /* Exchange args and then do nth. */
1768 BEFORE_POTENTIAL_GC ();
1772 AFTER_POTENTIAL_GC ();
1775 while (--n
>= 0 && CONSP (v1
))
1782 BEFORE_POTENTIAL_GC ();
1784 TOP
= Felt (TOP
, v1
);
1785 AFTER_POTENTIAL_GC ();
1793 BEFORE_POTENTIAL_GC ();
1795 TOP
= Fmember (TOP
, v1
);
1796 AFTER_POTENTIAL_GC ();
1803 BEFORE_POTENTIAL_GC ();
1805 TOP
= Fassq (TOP
, v1
);
1806 AFTER_POTENTIAL_GC ();
1811 BEFORE_POTENTIAL_GC ();
1812 TOP
= Fnreverse (TOP
);
1813 AFTER_POTENTIAL_GC ();
1819 BEFORE_POTENTIAL_GC ();
1821 TOP
= Fsetcar (TOP
, v1
);
1822 AFTER_POTENTIAL_GC ();
1829 BEFORE_POTENTIAL_GC ();
1831 TOP
= Fsetcdr (TOP
, v1
);
1832 AFTER_POTENTIAL_GC ();
1840 TOP
= CAR_SAFE (v1
);
1848 TOP
= CDR_SAFE (v1
);
1853 BEFORE_POTENTIAL_GC ();
1855 TOP
= Fnconc (2, &TOP
);
1856 AFTER_POTENTIAL_GC ();
1860 TOP
= (NUMBERP (TOP
) ? Qt
: Qnil
);
1864 TOP
= INTEGERP (TOP
) ? Qt
: Qnil
;
1867 #ifdef BYTE_CODE_SAFE
1868 /* These are intentionally written using 'case' syntax,
1869 because they are incompatible with the threaded
1873 BEFORE_POTENTIAL_GC ();
1874 error ("set-mark is an obsolete bytecode");
1875 AFTER_POTENTIAL_GC ();
1878 BEFORE_POTENTIAL_GC ();
1879 error ("scan-buffer is an obsolete bytecode");
1880 AFTER_POTENTIAL_GC ();
1885 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1886 for that instead. */
1887 /* CASE (Bstack_ref): */
1889 build_string ("Invalid byte opcode: op=%s, ptr=%d"),
1891 make_number ((stack
.pc
- 1) - stack
.byte_string_start
));
1893 /* Handy byte-codes for lexical binding. */
1900 Lisp_Object
*ptr
= top
- (op
- Bstack_ref
);
1906 Lisp_Object
*ptr
= top
- (FETCH
);
1912 Lisp_Object
*ptr
= top
- (FETCH2
);
1917 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1919 Lisp_Object
*ptr
= top
- (FETCH
);
1925 Lisp_Object
*ptr
= top
- (FETCH2
);
1941 #ifdef BYTE_CODE_SAFE
1946 if ((op
-= Bconstant
) >= const_length
)
1952 PUSH (vectorp
[op
- Bconstant
]);
1960 byte_stack_list
= byte_stack_list
->next
;
1962 /* Binds and unbinds are supposed to be compiled balanced. */
1963 if (SPECPDL_INDEX () != count
)
1965 if (SPECPDL_INDEX () > count
)
1966 unbind_to (count
, Qnil
);
1967 error ("binding stack not balanced (serious byte compiler bug)");
1973 /* `args_template' has the same meaning as in exec_byte_code() above. */
1975 get_byte_code_arity (Lisp_Object args_template
)
1977 eassert (NATNUMP (args_template
));
1978 EMACS_INT at
= XINT (args_template
);
1979 bool rest
= (at
& 128) != 0;
1980 int mandatory
= at
& 127;
1981 EMACS_INT nonrest
= at
>> 8;
1983 return Fcons (make_number (mandatory
),
1984 rest
? Qmany
: make_number (nonrest
));
1988 syms_of_bytecode (void)
1990 defsubr (&Sbyte_code
);
1992 #ifdef BYTE_CODE_METER
1994 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter
,
1995 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
1996 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1997 opcode CODE has been executed.
1998 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1999 indicates how many times the byte opcodes CODE1 and CODE2 have been
2000 executed in succession. */);
2002 DEFVAR_BOOL ("byte-metering-on", byte_metering_on
,
2003 doc
: /* If non-nil, keep profiling information on byte code usage.
2004 The variable byte-code-meter indicates how often each byte opcode is used.
2005 If a symbol has a property named `byte-code-meter' whose value is an
2006 integer, it is incremented each time that symbol's function is called. */);
2008 byte_metering_on
= 0;
2009 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
2010 DEFSYM (Qbyte_code_meter
, "byte-code-meter");
2014 ASET (Vbyte_code_meter
, i
,
2015 Fmake_vector (make_number (256), make_number (0)));