1 /* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985-1988, 1993, 2000-2015 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
10 (at 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/>. */
21 hacked on by jwz@lucid.com 17-jun-91
22 o added a compile-time switch to turn on simple sanity checking;
23 o put back the obsolete byte-codes for error-detection;
24 o added a new instruction, unbind_all, which I will use for
25 tail-recursion elimination;
26 o made temp_output_buffer_show be called with the right number
28 o made the new bytecodes be called with args in the right order;
29 o added metering support.
32 o added relative jump instructions;
33 o all conditionals now only do QUIT if they jump.
39 #include "blockinput.h"
40 #include "character.h"
46 #ifdef CHECK_FRAME_FONT
52 * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for
53 * debugging the byte compiler...)
55 * define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
57 /* #define BYTE_CODE_SAFE */
58 /* #define BYTE_CODE_METER */
60 /* If BYTE_CODE_THREADED is defined, then the interpreter will be
61 indirect threaded, using GCC's computed goto extension. This code,
62 as currently implemented, is incompatible with BYTE_CODE_SAFE and
64 #if (defined __GNUC__ && !defined __STRICT_ANSI__ \
65 && !defined BYTE_CODE_SAFE && !defined BYTE_CODE_METER)
66 #define BYTE_CODE_THREADED
70 #ifdef BYTE_CODE_METER
72 #define METER_2(code1, code2) AREF (AREF (Vbyte_code_meter, code1), code2)
73 #define METER_1(code) METER_2 (0, code)
75 #define METER_CODE(last_code, this_code) \
77 if (byte_metering_on) \
79 if (XFASTINT (METER_1 (this_code)) < MOST_POSITIVE_FIXNUM) \
80 XSETFASTINT (METER_1 (this_code), \
81 XFASTINT (METER_1 (this_code)) + 1); \
83 && (XFASTINT (METER_2 (last_code, this_code)) \
84 < MOST_POSITIVE_FIXNUM)) \
85 XSETFASTINT (METER_2 (last_code, this_code), \
86 XFASTINT (METER_2 (last_code, this_code)) + 1); \
90 #endif /* BYTE_CODE_METER */
96 DEFINE (Bstack_ref, 0) /* Actually, Bstack_ref+0 is not implemented: use dup. */ \
97 DEFINE (Bstack_ref1, 1) \
98 DEFINE (Bstack_ref2, 2) \
99 DEFINE (Bstack_ref3, 3) \
100 DEFINE (Bstack_ref4, 4) \
101 DEFINE (Bstack_ref5, 5) \
102 DEFINE (Bstack_ref6, 6) \
103 DEFINE (Bstack_ref7, 7) \
104 DEFINE (Bvarref, 010) \
105 DEFINE (Bvarref1, 011) \
106 DEFINE (Bvarref2, 012) \
107 DEFINE (Bvarref3, 013) \
108 DEFINE (Bvarref4, 014) \
109 DEFINE (Bvarref5, 015) \
110 DEFINE (Bvarref6, 016) \
111 DEFINE (Bvarref7, 017) \
112 DEFINE (Bvarset, 020) \
113 DEFINE (Bvarset1, 021) \
114 DEFINE (Bvarset2, 022) \
115 DEFINE (Bvarset3, 023) \
116 DEFINE (Bvarset4, 024) \
117 DEFINE (Bvarset5, 025) \
118 DEFINE (Bvarset6, 026) \
119 DEFINE (Bvarset7, 027) \
120 DEFINE (Bvarbind, 030) \
121 DEFINE (Bvarbind1, 031) \
122 DEFINE (Bvarbind2, 032) \
123 DEFINE (Bvarbind3, 033) \
124 DEFINE (Bvarbind4, 034) \
125 DEFINE (Bvarbind5, 035) \
126 DEFINE (Bvarbind6, 036) \
127 DEFINE (Bvarbind7, 037) \
128 DEFINE (Bcall, 040) \
129 DEFINE (Bcall1, 041) \
130 DEFINE (Bcall2, 042) \
131 DEFINE (Bcall3, 043) \
132 DEFINE (Bcall4, 044) \
133 DEFINE (Bcall5, 045) \
134 DEFINE (Bcall6, 046) \
135 DEFINE (Bcall7, 047) \
136 DEFINE (Bunbind, 050) \
137 DEFINE (Bunbind1, 051) \
138 DEFINE (Bunbind2, 052) \
139 DEFINE (Bunbind3, 053) \
140 DEFINE (Bunbind4, 054) \
141 DEFINE (Bunbind5, 055) \
142 DEFINE (Bunbind6, 056) \
143 DEFINE (Bunbind7, 057) \
145 DEFINE (Bpophandler, 060) \
146 DEFINE (Bpushconditioncase, 061) \
147 DEFINE (Bpushcatch, 062) \
150 DEFINE (Bsymbolp, 071) \
151 DEFINE (Bconsp, 072) \
152 DEFINE (Bstringp, 073) \
153 DEFINE (Blistp, 074) \
155 DEFINE (Bmemq, 076) \
157 DEFINE (Bcar, 0100) \
158 DEFINE (Bcdr, 0101) \
159 DEFINE (Bcons, 0102) \
160 DEFINE (Blist1, 0103) \
161 DEFINE (Blist2, 0104) \
162 DEFINE (Blist3, 0105) \
163 DEFINE (Blist4, 0106) \
164 DEFINE (Blength, 0107) \
165 DEFINE (Baref, 0110) \
166 DEFINE (Baset, 0111) \
167 DEFINE (Bsymbol_value, 0112) \
168 DEFINE (Bsymbol_function, 0113) \
169 DEFINE (Bset, 0114) \
170 DEFINE (Bfset, 0115) \
171 DEFINE (Bget, 0116) \
172 DEFINE (Bsubstring, 0117) \
173 DEFINE (Bconcat2, 0120) \
174 DEFINE (Bconcat3, 0121) \
175 DEFINE (Bconcat4, 0122) \
176 DEFINE (Bsub1, 0123) \
177 DEFINE (Badd1, 0124) \
178 DEFINE (Beqlsign, 0125) \
179 DEFINE (Bgtr, 0126) \
180 DEFINE (Blss, 0127) \
181 DEFINE (Bleq, 0130) \
182 DEFINE (Bgeq, 0131) \
183 DEFINE (Bdiff, 0132) \
184 DEFINE (Bnegate, 0133) \
185 DEFINE (Bplus, 0134) \
186 DEFINE (Bmax, 0135) \
187 DEFINE (Bmin, 0136) \
188 DEFINE (Bmult, 0137) \
190 DEFINE (Bpoint, 0140) \
191 /* Was Bmark in v17. */ \
192 DEFINE (Bsave_current_buffer, 0141) /* Obsolete. */ \
193 DEFINE (Bgoto_char, 0142) \
194 DEFINE (Binsert, 0143) \
195 DEFINE (Bpoint_max, 0144) \
196 DEFINE (Bpoint_min, 0145) \
197 DEFINE (Bchar_after, 0146) \
198 DEFINE (Bfollowing_char, 0147) \
199 DEFINE (Bpreceding_char, 0150) \
200 DEFINE (Bcurrent_column, 0151) \
201 DEFINE (Bindent_to, 0152) \
202 DEFINE (Beolp, 0154) \
203 DEFINE (Beobp, 0155) \
204 DEFINE (Bbolp, 0156) \
205 DEFINE (Bbobp, 0157) \
206 DEFINE (Bcurrent_buffer, 0160) \
207 DEFINE (Bset_buffer, 0161) \
208 DEFINE (Bsave_current_buffer_1, 0162) /* Replacing Bsave_current_buffer. */ \
209 DEFINE (Binteractive_p, 0164) /* Obsolete since Emacs-24.1. */ \
211 DEFINE (Bforward_char, 0165) \
212 DEFINE (Bforward_word, 0166) \
213 DEFINE (Bskip_chars_forward, 0167) \
214 DEFINE (Bskip_chars_backward, 0170) \
215 DEFINE (Bforward_line, 0171) \
216 DEFINE (Bchar_syntax, 0172) \
217 DEFINE (Bbuffer_substring, 0173) \
218 DEFINE (Bdelete_region, 0174) \
219 DEFINE (Bnarrow_to_region, 0175) \
220 DEFINE (Bwiden, 0176) \
221 DEFINE (Bend_of_line, 0177) \
223 DEFINE (Bconstant2, 0201) \
224 DEFINE (Bgoto, 0202) \
225 DEFINE (Bgotoifnil, 0203) \
226 DEFINE (Bgotoifnonnil, 0204) \
227 DEFINE (Bgotoifnilelsepop, 0205) \
228 DEFINE (Bgotoifnonnilelsepop, 0206) \
229 DEFINE (Breturn, 0207) \
230 DEFINE (Bdiscard, 0210) \
231 DEFINE (Bdup, 0211) \
233 DEFINE (Bsave_excursion, 0212) \
234 DEFINE (Bsave_window_excursion, 0213) /* Obsolete since Emacs-24.1. */ \
235 DEFINE (Bsave_restriction, 0214) \
236 DEFINE (Bcatch, 0215) \
238 DEFINE (Bunwind_protect, 0216) \
239 DEFINE (Bcondition_case, 0217) \
240 DEFINE (Btemp_output_buffer_setup, 0220) /* Obsolete since Emacs-24.1. */ \
241 DEFINE (Btemp_output_buffer_show, 0221) /* Obsolete since Emacs-24.1. */ \
243 DEFINE (Bunbind_all, 0222) /* Obsolete. Never used. */ \
245 DEFINE (Bset_marker, 0223) \
246 DEFINE (Bmatch_beginning, 0224) \
247 DEFINE (Bmatch_end, 0225) \
248 DEFINE (Bupcase, 0226) \
249 DEFINE (Bdowncase, 0227) \
251 DEFINE (Bstringeqlsign, 0230) \
252 DEFINE (Bstringlss, 0231) \
253 DEFINE (Bequal, 0232) \
254 DEFINE (Bnthcdr, 0233) \
255 DEFINE (Belt, 0234) \
256 DEFINE (Bmember, 0235) \
257 DEFINE (Bassq, 0236) \
258 DEFINE (Bnreverse, 0237) \
259 DEFINE (Bsetcar, 0240) \
260 DEFINE (Bsetcdr, 0241) \
261 DEFINE (Bcar_safe, 0242) \
262 DEFINE (Bcdr_safe, 0243) \
263 DEFINE (Bnconc, 0244) \
264 DEFINE (Bquo, 0245) \
265 DEFINE (Brem, 0246) \
266 DEFINE (Bnumberp, 0247) \
267 DEFINE (Bintegerp, 0250) \
269 DEFINE (BRgoto, 0252) \
270 DEFINE (BRgotoifnil, 0253) \
271 DEFINE (BRgotoifnonnil, 0254) \
272 DEFINE (BRgotoifnilelsepop, 0255) \
273 DEFINE (BRgotoifnonnilelsepop, 0256) \
275 DEFINE (BlistN, 0257) \
276 DEFINE (BconcatN, 0260) \
277 DEFINE (BinsertN, 0261) \
279 /* Bstack_ref is code 0. */ \
280 DEFINE (Bstack_set, 0262) \
281 DEFINE (Bstack_set2, 0263) \
282 DEFINE (BdiscardN, 0266) \
284 DEFINE (Bconstant, 0300)
288 #define DEFINE(name, value) name = value,
292 #ifdef BYTE_CODE_SAFE
293 Bscan_buffer
= 0153, /* No longer generated as of v18. */
294 Bset_mark
= 0163, /* this loser is no longer generated as of v18 */
298 /* Whether to maintain a `top' and `bottom' field in the stack frame. */
299 #define BYTE_MAINTAIN_TOP BYTE_CODE_SAFE
301 /* Structure describing a value stack used during byte-code execution
306 /* Program counter. This points into the byte_string below
307 and is relocated when that string is relocated. */
308 const unsigned char *pc
;
310 /* Top and bottom of stack. The bottom points to an area of memory
311 allocated with alloca in Fbyte_code. */
312 #if BYTE_MAINTAIN_TOP
313 Lisp_Object
*top
, *bottom
;
316 /* The string containing the byte-code, and its current address.
317 Storing this here protects it from GC because mark_byte_stack
319 Lisp_Object byte_string
;
320 const unsigned char *byte_string_start
;
322 /* Next entry in byte_stack_list. */
323 struct byte_stack
*next
;
326 /* A list of currently active byte-code execution value stacks.
327 Fbyte_code adds an entry to the head of this list before it starts
328 processing byte-code, and it removes the entry again when it is
329 done. Signaling an error truncates the list. */
331 struct byte_stack
*byte_stack_list
;
334 /* Relocate program counters in the stacks on byte_stack_list. Called
335 when GC has completed. */
338 relocate_byte_stack (void)
340 struct byte_stack
*stack
;
342 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
344 if (stack
->byte_string_start
!= SDATA (stack
->byte_string
))
346 ptrdiff_t offset
= stack
->pc
- stack
->byte_string_start
;
347 stack
->byte_string_start
= SDATA (stack
->byte_string
);
348 stack
->pc
= stack
->byte_string_start
+ offset
;
354 /* Fetch the next byte from the bytecode stream. */
356 #ifdef BYTE_CODE_SAFE
357 #define FETCH (eassert (stack.byte_string_start == SDATA (stack.byte_string)), *stack.pc++)
359 #define FETCH *stack.pc++
362 /* Fetch two bytes from the bytecode stream and make a 16-bit number
365 #define FETCH2 (op = FETCH, op + (FETCH << 8))
367 /* Push x onto the execution stack. This used to be #define PUSH(x)
368 (*++stackp = (x)) This oddity is necessary because Alliant can't be
369 bothered to compile the preincrement operator properly, as of 4/91.
372 #define PUSH(x) (top++, *top = (x))
374 /* Pop a value off the execution stack. */
378 /* Discard n values from the execution stack. */
380 #define DISCARD(n) (top -= (n))
382 /* Get the value which is at the top of the execution stack, but don't
387 /* Actions that must be performed before and after calling a function
390 #if !BYTE_MAINTAIN_TOP
391 #define BEFORE_POTENTIAL_GC() ((void)0)
392 #define AFTER_POTENTIAL_GC() ((void)0)
394 #define BEFORE_POTENTIAL_GC() stack.top = top
395 #define AFTER_POTENTIAL_GC() stack.top = NULL
398 /* Garbage collect if we have consed enough since the last time.
399 We do this at every branch, to avoid loops that never GC. */
403 BEFORE_POTENTIAL_GC (); \
405 AFTER_POTENTIAL_GC (); \
408 /* Check for jumping out of range. */
410 #ifdef BYTE_CODE_SAFE
412 #define CHECK_RANGE(ARG) \
413 if (ARG >= bytestr_length) emacs_abort ()
415 #else /* not BYTE_CODE_SAFE */
417 #define CHECK_RANGE(ARG)
419 #endif /* not BYTE_CODE_SAFE */
421 /* A version of the QUIT macro which makes sure that the stack top is
422 set before signaling `quit'. */
424 #define BYTE_CODE_QUIT \
426 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
428 Lisp_Object flag = Vquit_flag; \
430 BEFORE_POTENTIAL_GC (); \
431 if (EQ (Vthrow_on_input, flag)) \
432 Fthrow (Vthrow_on_input, Qt); \
433 Fsignal (Qquit, Qnil); \
434 AFTER_POTENTIAL_GC (); \
436 else if (pending_signals) \
437 process_pending_signals (); \
441 DEFUN ("byte-code", Fbyte_code
, Sbyte_code
, 3, 3, 0,
442 doc
: /* Function used internally in byte-compiled code.
443 The first argument, BYTESTR, is a string of byte code;
444 the second, VECTOR, a vector of constants;
445 the third, MAXDEPTH, the maximum stack depth used in this function.
446 If the third argument is incorrect, Emacs may crash. */)
447 (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
)
449 return exec_byte_code (bytestr
, vector
, maxdepth
, Qnil
, 0, NULL
);
453 bcall0 (Lisp_Object f
)
458 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
459 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
460 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
461 argument list (including &rest, &optional, etc.), and ARGS, of size
462 NARGS, should be a vector of the actual arguments. The arguments in
463 ARGS are pushed on the stack according to ARGS_TEMPLATE before
464 executing BYTESTR. */
467 exec_byte_code (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
,
468 Lisp_Object args_template
, ptrdiff_t nargs
, Lisp_Object
*args
)
470 ptrdiff_t count
= SPECPDL_INDEX ();
471 #ifdef BYTE_CODE_METER
472 int volatile this_op
= 0;
476 /* Lisp_Object v1, v2; */
477 Lisp_Object
*vectorp
;
478 #ifdef BYTE_CODE_SAFE
479 ptrdiff_t const_length
;
481 ptrdiff_t bytestr_length
;
483 struct byte_stack stack
;
486 enum handlertype type
;
488 #if 0 /* CHECK_FRAME_FONT */
490 struct frame
*f
= SELECTED_FRAME ();
492 && FRAME_FONT (f
)->direction
!= 0
493 && FRAME_FONT (f
)->direction
!= 1)
498 CHECK_STRING (bytestr
);
499 CHECK_VECTOR (vector
);
500 CHECK_NATNUM (maxdepth
);
502 #ifdef BYTE_CODE_SAFE
503 const_length
= ASIZE (vector
);
506 if (STRING_MULTIBYTE (bytestr
))
507 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
508 because they produced a raw 8-bit string for byte-code and now
509 such a byte-code string is loaded as multibyte while raw 8-bit
510 characters converted to multibyte form. Thus, now we must
511 convert them back to the originally intended unibyte form. */
512 bytestr
= Fstring_as_unibyte (bytestr
);
514 #ifdef BYTE_CODE_SAFE
515 bytestr_length
= SBYTES (bytestr
);
517 vectorp
= XVECTOR (vector
)->contents
;
519 stack
.byte_string
= bytestr
;
520 stack
.pc
= stack
.byte_string_start
= SDATA (bytestr
);
521 if (MAX_ALLOCA
/ word_size
<= XFASTINT (maxdepth
))
522 memory_full (SIZE_MAX
);
523 top
= alloca ((XFASTINT (maxdepth
) + 1) * sizeof *top
);
524 #if BYTE_MAINTAIN_TOP
525 stack
.bottom
= top
+ 1;
528 stack
.next
= byte_stack_list
;
529 byte_stack_list
= &stack
;
531 #ifdef BYTE_CODE_SAFE
532 stacke
= stack
.bottom
- 1 + XFASTINT (maxdepth
);
535 if (INTEGERP (args_template
))
537 ptrdiff_t at
= XINT (args_template
);
538 bool rest
= (at
& 128) != 0;
539 int mandatory
= at
& 127;
540 ptrdiff_t nonrest
= at
>> 8;
541 eassert (mandatory
<= nonrest
);
542 if (nargs
<= nonrest
)
545 for (i
= 0 ; i
< nargs
; i
++, args
++)
547 if (nargs
< mandatory
)
548 /* Too few arguments. */
549 Fsignal (Qwrong_number_of_arguments
,
550 list2 (Fcons (make_number (mandatory
),
551 rest
? Qand_rest
: make_number (nonrest
)),
552 make_number (nargs
)));
555 for (; i
< nonrest
; i
++)
564 for (i
= 0 ; i
< nonrest
; i
++, args
++)
566 PUSH (Flist (nargs
- nonrest
, args
));
569 /* Too many arguments. */
570 Fsignal (Qwrong_number_of_arguments
,
571 list2 (Fcons (make_number (mandatory
), make_number (nonrest
)),
572 make_number (nargs
)));
574 else if (! NILP (args_template
))
575 /* We should push some arguments on the stack. */
577 error ("Unknown args template!");
582 #ifdef BYTE_CODE_SAFE
585 else if (top
< stack
.bottom
- 1)
589 #ifdef BYTE_CODE_METER
591 this_op
= op
= FETCH
;
592 METER_CODE (prev_op
, op
);
594 #ifndef BYTE_CODE_THREADED
599 /* The interpreter can be compiled one of two ways: as an
600 ordinary switch-based interpreter, or as a threaded
601 interpreter. The threaded interpreter relies on GCC's
602 computed goto extension, so it is not available everywhere.
603 Threading provides a performance boost. These macros are how
604 we allow the code to be compiled both ways. */
605 #ifdef BYTE_CODE_THREADED
606 /* The CASE macro introduces an instruction's body. It is
607 either a label or a case label. */
608 #define CASE(OP) insn_ ## OP
609 /* NEXT is invoked at the end of an instruction to go to the
610 next instruction. It is either a computed goto, or a
612 #define NEXT goto *(targets[op = FETCH])
613 /* FIRST is like NEXT, but is only used at the start of the
614 interpreter body. In the switch-based interpreter it is the
615 switch, so the threaded definition must include a semicolon. */
617 /* Most cases are labeled with the CASE macro, above.
618 CASE_DEFAULT is one exception; it is used if the interpreter
619 being built requires a default case. The threaded
620 interpreter does not, because the dispatch table is
621 completely filled. */
623 /* This introduces an instruction that is known to call abort. */
624 #define CASE_ABORT CASE (Bstack_ref): CASE (default)
626 /* See above for the meaning of the various defines. */
627 #define CASE(OP) case OP
629 #define FIRST switch (op)
630 #define CASE_DEFAULT case 255: default:
631 #define CASE_ABORT case 0
634 #ifdef BYTE_CODE_THREADED
636 /* A convenience define that saves us a lot of typing and makes
637 the table clearer. */
638 #define LABEL(OP) [OP] = &&insn_ ## OP
640 #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
641 # pragma GCC diagnostic push
642 # pragma GCC diagnostic ignored "-Woverride-init"
643 #elif defined __clang__
644 # pragma GCC diagnostic push
645 # pragma GCC diagnostic ignored "-Winitializer-overrides"
648 /* This is the dispatch table for the threaded interpreter. */
649 static const void *const targets
[256] =
651 [0 ... (Bconstant
- 1)] = &&insn_default
,
652 [Bconstant
... 255] = &&insn_Bconstant
,
654 #define DEFINE(name, value) LABEL (name) ,
659 #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) || defined __clang__
660 # pragma GCC diagnostic pop
681 /* This seems to be the most frequently executed byte-code
682 among the Bvarref's, so avoid a goto here. */
692 if (XSYMBOL (v1
)->redirect
!= SYMBOL_PLAINVAL
693 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)),
696 BEFORE_POTENTIAL_GC ();
697 v2
= Fsymbol_value (v1
);
698 AFTER_POTENTIAL_GC ();
703 BEFORE_POTENTIAL_GC ();
704 v2
= Fsymbol_value (v1
);
705 AFTER_POTENTIAL_GC ();
721 stack
.pc
= stack
.byte_string_start
+ op
;
736 BEFORE_POTENTIAL_GC ();
737 wrong_type_argument (Qlistp
, v1
);
746 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
753 BEFORE_POTENTIAL_GC ();
755 TOP
= Fmemq (TOP
, v1
);
756 AFTER_POTENTIAL_GC ();
770 BEFORE_POTENTIAL_GC ();
771 wrong_type_argument (Qlistp
, v1
);
793 Lisp_Object sym
, val
;
798 /* Inline the most common case. */
800 && !EQ (val
, Qunbound
)
801 && !XSYMBOL (sym
)->redirect
802 && !SYMBOL_CONSTANT_P (sym
))
803 SET_SYMBOL_VAL (XSYMBOL (sym
), val
);
806 BEFORE_POTENTIAL_GC ();
807 set_internal (sym
, val
, Qnil
, 0);
808 AFTER_POTENTIAL_GC ();
822 /* ------------------ */
840 /* Specbind can signal and thus GC. */
841 BEFORE_POTENTIAL_GC ();
842 specbind (vectorp
[op
], POP
);
843 AFTER_POTENTIAL_GC ();
863 BEFORE_POTENTIAL_GC ();
865 #ifdef BYTE_CODE_METER
866 if (byte_metering_on
&& SYMBOLP (TOP
))
871 v2
= Fget (v1
, Qbyte_code_meter
);
873 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
875 XSETINT (v2
, XINT (v2
) + 1);
876 Fput (v1
, Qbyte_code_meter
, v2
);
880 TOP
= Ffuncall (op
+ 1, &TOP
);
881 AFTER_POTENTIAL_GC ();
901 BEFORE_POTENTIAL_GC ();
902 unbind_to (SPECPDL_INDEX () - op
, Qnil
);
903 AFTER_POTENTIAL_GC ();
906 CASE (Bunbind_all
): /* Obsolete. Never used. */
907 /* To unbind back to the beginning of this frame. Not used yet,
908 but will be needed for tail-recursion elimination. */
909 BEFORE_POTENTIAL_GC ();
910 unbind_to (count
, Qnil
);
911 AFTER_POTENTIAL_GC ();
917 op
= FETCH2
; /* pc = FETCH2 loses since FETCH2 contains pc++ */
919 stack
.pc
= stack
.byte_string_start
+ op
;
922 CASE (Bgotoifnonnil
):
932 stack
.pc
= stack
.byte_string_start
+ op
;
937 CASE (Bgotoifnilelsepop
):
944 stack
.pc
= stack
.byte_string_start
+ op
;
949 CASE (Bgotoifnonnilelsepop
):
956 stack
.pc
= stack
.byte_string_start
+ op
;
964 stack
.pc
+= (int) *stack
.pc
- 127;
975 stack
.pc
+= (int) *stack
.pc
- 128;
981 CASE (BRgotoifnonnil
):
989 stack
.pc
+= (int) *stack
.pc
- 128;
995 CASE (BRgotoifnilelsepop
):
1001 stack
.pc
+= op
- 128;
1006 CASE (BRgotoifnonnilelsepop
):
1012 stack
.pc
+= op
- 128;
1026 PUSH (vectorp
[FETCH2
]);
1029 CASE (Bsave_excursion
):
1030 record_unwind_protect (save_excursion_restore
,
1031 save_excursion_save ());
1034 CASE (Bsave_current_buffer
): /* Obsolete since ??. */
1035 CASE (Bsave_current_buffer_1
):
1036 record_unwind_current_buffer ();
1039 CASE (Bsave_window_excursion
): /* Obsolete since 24.1. */
1041 ptrdiff_t count1
= SPECPDL_INDEX ();
1042 record_unwind_protect (restore_window_configuration
,
1043 Fcurrent_window_configuration (Qnil
));
1044 BEFORE_POTENTIAL_GC ();
1046 unbind_to (count1
, TOP
);
1047 AFTER_POTENTIAL_GC ();
1051 CASE (Bsave_restriction
):
1052 record_unwind_protect (save_restriction_restore
,
1053 save_restriction_save ());
1056 CASE (Bcatch
): /* Obsolete since 24.4. */
1059 BEFORE_POTENTIAL_GC ();
1061 TOP
= internal_catch (TOP
, eval_sub
, v1
);
1062 AFTER_POTENTIAL_GC ();
1066 CASE (Bpushcatch
): /* New in 24.4. */
1069 CASE (Bpushconditioncase
): /* New in 24.4. */
1075 type
= CONDITION_CASE
;
1080 PUSH_HANDLER (c
, tag
, type
);
1081 c
->bytecode_dest
= dest
;
1082 c
->bytecode_top
= top
;
1084 if (sys_setjmp (c
->jmp
))
1086 struct handler
*c
= handlerlist
;
1088 top
= c
->bytecode_top
;
1089 dest
= c
->bytecode_dest
;
1090 handlerlist
= c
->next
;
1093 /* Might have been re-set by longjmp! */
1094 stack
.byte_string_start
= SDATA (stack
.byte_string
);
1095 stack
.pc
= stack
.byte_string_start
+ dest
;
1101 CASE (Bpophandler
): /* New in 24.4. */
1103 handlerlist
= handlerlist
->next
;
1107 CASE (Bunwind_protect
): /* FIXME: avoid closure for lexbind. */
1109 Lisp_Object handler
= POP
;
1110 /* Support for a function here is new in 24.4. */
1111 record_unwind_protect (NILP (Ffunctionp (handler
))
1112 ? unwind_body
: bcall0
,
1117 CASE (Bcondition_case
): /* Obsolete since 24.4. */
1119 Lisp_Object handlers
, body
;
1122 BEFORE_POTENTIAL_GC ();
1123 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
);
1124 AFTER_POTENTIAL_GC ();
1128 CASE (Btemp_output_buffer_setup
): /* Obsolete since 24.1. */
1129 BEFORE_POTENTIAL_GC ();
1131 temp_output_buffer_setup (SSDATA (TOP
));
1132 AFTER_POTENTIAL_GC ();
1133 TOP
= Vstandard_output
;
1136 CASE (Btemp_output_buffer_show
): /* Obsolete since 24.1. */
1139 BEFORE_POTENTIAL_GC ();
1141 temp_output_buffer_show (TOP
);
1143 /* pop binding of standard-output */
1144 unbind_to (SPECPDL_INDEX () - 1, Qnil
);
1145 AFTER_POTENTIAL_GC ();
1153 BEFORE_POTENTIAL_GC ();
1159 while (--n
>= 0 && CONSP (v1
))
1163 AFTER_POTENTIAL_GC ();
1168 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
1172 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
1176 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
1180 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
1184 TOP
= NILP (TOP
) ? Qt
: Qnil
;
1191 TOP
= Fcons (TOP
, v1
);
1203 TOP
= list2 (TOP
, v1
);
1209 TOP
= Flist (3, &TOP
);
1214 TOP
= Flist (4, &TOP
);
1220 TOP
= Flist (op
, &TOP
);
1224 BEFORE_POTENTIAL_GC ();
1225 TOP
= Flength (TOP
);
1226 AFTER_POTENTIAL_GC ();
1232 BEFORE_POTENTIAL_GC ();
1234 TOP
= Faref (TOP
, v1
);
1235 AFTER_POTENTIAL_GC ();
1242 BEFORE_POTENTIAL_GC ();
1244 TOP
= Faset (TOP
, v1
, v2
);
1245 AFTER_POTENTIAL_GC ();
1249 CASE (Bsymbol_value
):
1250 BEFORE_POTENTIAL_GC ();
1251 TOP
= Fsymbol_value (TOP
);
1252 AFTER_POTENTIAL_GC ();
1255 CASE (Bsymbol_function
):
1256 BEFORE_POTENTIAL_GC ();
1257 TOP
= Fsymbol_function (TOP
);
1258 AFTER_POTENTIAL_GC ();
1264 BEFORE_POTENTIAL_GC ();
1266 TOP
= Fset (TOP
, v1
);
1267 AFTER_POTENTIAL_GC ();
1274 BEFORE_POTENTIAL_GC ();
1276 TOP
= Ffset (TOP
, v1
);
1277 AFTER_POTENTIAL_GC ();
1284 BEFORE_POTENTIAL_GC ();
1286 TOP
= Fget (TOP
, v1
);
1287 AFTER_POTENTIAL_GC ();
1294 BEFORE_POTENTIAL_GC ();
1296 TOP
= Fsubstring (TOP
, v1
, v2
);
1297 AFTER_POTENTIAL_GC ();
1302 BEFORE_POTENTIAL_GC ();
1304 TOP
= Fconcat (2, &TOP
);
1305 AFTER_POTENTIAL_GC ();
1309 BEFORE_POTENTIAL_GC ();
1311 TOP
= Fconcat (3, &TOP
);
1312 AFTER_POTENTIAL_GC ();
1316 BEFORE_POTENTIAL_GC ();
1318 TOP
= Fconcat (4, &TOP
);
1319 AFTER_POTENTIAL_GC ();
1324 BEFORE_POTENTIAL_GC ();
1326 TOP
= Fconcat (op
, &TOP
);
1327 AFTER_POTENTIAL_GC ();
1336 XSETINT (v1
, XINT (v1
) - 1);
1341 BEFORE_POTENTIAL_GC ();
1343 AFTER_POTENTIAL_GC ();
1354 XSETINT (v1
, XINT (v1
) + 1);
1359 BEFORE_POTENTIAL_GC ();
1361 AFTER_POTENTIAL_GC ();
1369 BEFORE_POTENTIAL_GC ();
1371 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
1372 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
1373 AFTER_POTENTIAL_GC ();
1374 if (FLOATP (v1
) || FLOATP (v2
))
1378 f1
= (FLOATP (v1
) ? XFLOAT_DATA (v1
) : XINT (v1
));
1379 f2
= (FLOATP (v2
) ? XFLOAT_DATA (v2
) : XINT (v2
));
1380 TOP
= (f1
== f2
? Qt
: Qnil
);
1383 TOP
= (XINT (v1
) == XINT (v2
) ? Qt
: Qnil
);
1390 BEFORE_POTENTIAL_GC ();
1392 TOP
= arithcompare (TOP
, v1
, ARITH_GRTR
);
1393 AFTER_POTENTIAL_GC ();
1400 BEFORE_POTENTIAL_GC ();
1402 TOP
= arithcompare (TOP
, v1
, ARITH_LESS
);
1403 AFTER_POTENTIAL_GC ();
1410 BEFORE_POTENTIAL_GC ();
1412 TOP
= arithcompare (TOP
, v1
, ARITH_LESS_OR_EQUAL
);
1413 AFTER_POTENTIAL_GC ();
1420 BEFORE_POTENTIAL_GC ();
1422 TOP
= arithcompare (TOP
, v1
, ARITH_GRTR_OR_EQUAL
);
1423 AFTER_POTENTIAL_GC ();
1428 BEFORE_POTENTIAL_GC ();
1430 TOP
= Fminus (2, &TOP
);
1431 AFTER_POTENTIAL_GC ();
1440 XSETINT (v1
, - XINT (v1
));
1445 BEFORE_POTENTIAL_GC ();
1446 TOP
= Fminus (1, &TOP
);
1447 AFTER_POTENTIAL_GC ();
1453 BEFORE_POTENTIAL_GC ();
1455 TOP
= Fplus (2, &TOP
);
1456 AFTER_POTENTIAL_GC ();
1460 BEFORE_POTENTIAL_GC ();
1462 TOP
= Fmax (2, &TOP
);
1463 AFTER_POTENTIAL_GC ();
1467 BEFORE_POTENTIAL_GC ();
1469 TOP
= Fmin (2, &TOP
);
1470 AFTER_POTENTIAL_GC ();
1474 BEFORE_POTENTIAL_GC ();
1476 TOP
= Ftimes (2, &TOP
);
1477 AFTER_POTENTIAL_GC ();
1481 BEFORE_POTENTIAL_GC ();
1483 TOP
= Fquo (2, &TOP
);
1484 AFTER_POTENTIAL_GC ();
1490 BEFORE_POTENTIAL_GC ();
1492 TOP
= Frem (TOP
, v1
);
1493 AFTER_POTENTIAL_GC ();
1500 XSETFASTINT (v1
, PT
);
1506 BEFORE_POTENTIAL_GC ();
1507 TOP
= Fgoto_char (TOP
);
1508 AFTER_POTENTIAL_GC ();
1512 BEFORE_POTENTIAL_GC ();
1513 TOP
= Finsert (1, &TOP
);
1514 AFTER_POTENTIAL_GC ();
1519 BEFORE_POTENTIAL_GC ();
1521 TOP
= Finsert (op
, &TOP
);
1522 AFTER_POTENTIAL_GC ();
1528 XSETFASTINT (v1
, ZV
);
1536 XSETFASTINT (v1
, BEGV
);
1542 BEFORE_POTENTIAL_GC ();
1543 TOP
= Fchar_after (TOP
);
1544 AFTER_POTENTIAL_GC ();
1547 CASE (Bfollowing_char
):
1550 BEFORE_POTENTIAL_GC ();
1551 v1
= Ffollowing_char ();
1552 AFTER_POTENTIAL_GC ();
1557 CASE (Bpreceding_char
):
1560 BEFORE_POTENTIAL_GC ();
1561 v1
= Fprevious_char ();
1562 AFTER_POTENTIAL_GC ();
1567 CASE (Bcurrent_column
):
1570 BEFORE_POTENTIAL_GC ();
1571 XSETFASTINT (v1
, current_column ());
1572 AFTER_POTENTIAL_GC ();
1578 BEFORE_POTENTIAL_GC ();
1579 TOP
= Findent_to (TOP
, Qnil
);
1580 AFTER_POTENTIAL_GC ();
1599 CASE (Bcurrent_buffer
):
1600 PUSH (Fcurrent_buffer ());
1604 BEFORE_POTENTIAL_GC ();
1605 TOP
= Fset_buffer (TOP
);
1606 AFTER_POTENTIAL_GC ();
1609 CASE (Binteractive_p
): /* Obsolete since 24.1. */
1610 BEFORE_POTENTIAL_GC ();
1611 PUSH (call0 (intern ("interactive-p")));
1612 AFTER_POTENTIAL_GC ();
1615 CASE (Bforward_char
):
1616 BEFORE_POTENTIAL_GC ();
1617 TOP
= Fforward_char (TOP
);
1618 AFTER_POTENTIAL_GC ();
1621 CASE (Bforward_word
):
1622 BEFORE_POTENTIAL_GC ();
1623 TOP
= Fforward_word (TOP
);
1624 AFTER_POTENTIAL_GC ();
1627 CASE (Bskip_chars_forward
):
1630 BEFORE_POTENTIAL_GC ();
1632 TOP
= Fskip_chars_forward (TOP
, v1
);
1633 AFTER_POTENTIAL_GC ();
1637 CASE (Bskip_chars_backward
):
1640 BEFORE_POTENTIAL_GC ();
1642 TOP
= Fskip_chars_backward (TOP
, v1
);
1643 AFTER_POTENTIAL_GC ();
1647 CASE (Bforward_line
):
1648 BEFORE_POTENTIAL_GC ();
1649 TOP
= Fforward_line (TOP
);
1650 AFTER_POTENTIAL_GC ();
1653 CASE (Bchar_syntax
):
1657 BEFORE_POTENTIAL_GC ();
1658 CHECK_CHARACTER (TOP
);
1659 AFTER_POTENTIAL_GC ();
1661 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
1662 MAKE_CHAR_MULTIBYTE (c
);
1663 XSETFASTINT (TOP
, syntax_code_spec
[SYNTAX (c
)]);
1667 CASE (Bbuffer_substring
):
1670 BEFORE_POTENTIAL_GC ();
1672 TOP
= Fbuffer_substring (TOP
, v1
);
1673 AFTER_POTENTIAL_GC ();
1677 CASE (Bdelete_region
):
1680 BEFORE_POTENTIAL_GC ();
1682 TOP
= Fdelete_region (TOP
, v1
);
1683 AFTER_POTENTIAL_GC ();
1687 CASE (Bnarrow_to_region
):
1690 BEFORE_POTENTIAL_GC ();
1692 TOP
= Fnarrow_to_region (TOP
, v1
);
1693 AFTER_POTENTIAL_GC ();
1698 BEFORE_POTENTIAL_GC ();
1700 AFTER_POTENTIAL_GC ();
1703 CASE (Bend_of_line
):
1704 BEFORE_POTENTIAL_GC ();
1705 TOP
= Fend_of_line (TOP
);
1706 AFTER_POTENTIAL_GC ();
1712 BEFORE_POTENTIAL_GC ();
1715 TOP
= Fset_marker (TOP
, v2
, v1
);
1716 AFTER_POTENTIAL_GC ();
1720 CASE (Bmatch_beginning
):
1721 BEFORE_POTENTIAL_GC ();
1722 TOP
= Fmatch_beginning (TOP
);
1723 AFTER_POTENTIAL_GC ();
1727 BEFORE_POTENTIAL_GC ();
1728 TOP
= Fmatch_end (TOP
);
1729 AFTER_POTENTIAL_GC ();
1733 BEFORE_POTENTIAL_GC ();
1734 TOP
= Fupcase (TOP
);
1735 AFTER_POTENTIAL_GC ();
1739 BEFORE_POTENTIAL_GC ();
1740 TOP
= Fdowncase (TOP
);
1741 AFTER_POTENTIAL_GC ();
1744 CASE (Bstringeqlsign
):
1747 BEFORE_POTENTIAL_GC ();
1749 TOP
= Fstring_equal (TOP
, v1
);
1750 AFTER_POTENTIAL_GC ();
1757 BEFORE_POTENTIAL_GC ();
1759 TOP
= Fstring_lessp (TOP
, v1
);
1760 AFTER_POTENTIAL_GC ();
1768 TOP
= Fequal (TOP
, v1
);
1775 BEFORE_POTENTIAL_GC ();
1777 TOP
= Fnthcdr (TOP
, v1
);
1778 AFTER_POTENTIAL_GC ();
1787 /* Exchange args and then do nth. */
1789 BEFORE_POTENTIAL_GC ();
1793 AFTER_POTENTIAL_GC ();
1796 while (--n
>= 0 && CONSP (v1
))
1803 BEFORE_POTENTIAL_GC ();
1805 TOP
= Felt (TOP
, v1
);
1806 AFTER_POTENTIAL_GC ();
1814 BEFORE_POTENTIAL_GC ();
1816 TOP
= Fmember (TOP
, v1
);
1817 AFTER_POTENTIAL_GC ();
1824 BEFORE_POTENTIAL_GC ();
1826 TOP
= Fassq (TOP
, v1
);
1827 AFTER_POTENTIAL_GC ();
1832 BEFORE_POTENTIAL_GC ();
1833 TOP
= Fnreverse (TOP
);
1834 AFTER_POTENTIAL_GC ();
1840 BEFORE_POTENTIAL_GC ();
1842 TOP
= Fsetcar (TOP
, v1
);
1843 AFTER_POTENTIAL_GC ();
1850 BEFORE_POTENTIAL_GC ();
1852 TOP
= Fsetcdr (TOP
, v1
);
1853 AFTER_POTENTIAL_GC ();
1861 TOP
= CAR_SAFE (v1
);
1869 TOP
= CDR_SAFE (v1
);
1874 BEFORE_POTENTIAL_GC ();
1876 TOP
= Fnconc (2, &TOP
);
1877 AFTER_POTENTIAL_GC ();
1881 TOP
= (NUMBERP (TOP
) ? Qt
: Qnil
);
1885 TOP
= INTEGERP (TOP
) ? Qt
: Qnil
;
1888 #ifdef BYTE_CODE_SAFE
1889 /* These are intentionally written using 'case' syntax,
1890 because they are incompatible with the threaded
1894 BEFORE_POTENTIAL_GC ();
1895 error ("set-mark is an obsolete bytecode");
1896 AFTER_POTENTIAL_GC ();
1899 BEFORE_POTENTIAL_GC ();
1900 error ("scan-buffer is an obsolete bytecode");
1901 AFTER_POTENTIAL_GC ();
1906 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1907 for that instead. */
1908 /* CASE (Bstack_ref): */
1910 build_string ("Invalid byte opcode: op=%s, ptr=%d"),
1912 make_number ((stack
.pc
- 1) - stack
.byte_string_start
));
1914 /* Handy byte-codes for lexical binding. */
1921 Lisp_Object
*ptr
= top
- (op
- Bstack_ref
);
1927 Lisp_Object
*ptr
= top
- (FETCH
);
1933 Lisp_Object
*ptr
= top
- (FETCH2
);
1938 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1940 Lisp_Object
*ptr
= top
- (FETCH
);
1946 Lisp_Object
*ptr
= top
- (FETCH2
);
1962 #ifdef BYTE_CODE_SAFE
1967 if ((op
-= Bconstant
) >= const_length
)
1973 PUSH (vectorp
[op
- Bconstant
]);
1981 byte_stack_list
= byte_stack_list
->next
;
1983 /* Binds and unbinds are supposed to be compiled balanced. */
1984 if (SPECPDL_INDEX () != count
)
1986 if (SPECPDL_INDEX () > count
)
1987 unbind_to (count
, Qnil
);
1988 error ("binding stack not balanced (serious byte compiler bug)");
1995 syms_of_bytecode (void)
1997 defsubr (&Sbyte_code
);
1999 #ifdef BYTE_CODE_METER
2001 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter
,
2002 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
2003 (aref (aref byte-code-meter 0) CODE) indicates how many times the byte
2004 opcode CODE has been executed.
2005 (aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
2006 indicates how many times the byte opcodes CODE1 and CODE2 have been
2007 executed in succession. */);
2009 DEFVAR_BOOL ("byte-metering-on", byte_metering_on
,
2010 doc
: /* If non-nil, keep profiling information on byte code usage.
2011 The variable byte-code-meter indicates how often each byte opcode is used.
2012 If a symbol has a property named `byte-code-meter' whose value is an
2013 integer, it is incremented each time that symbol's function is called. */);
2015 byte_metering_on
= 0;
2016 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
2017 DEFSYM (Qbyte_code_meter
, "byte-code-meter");
2021 ASET (Vbyte_code_meter
, i
,
2022 Fmake_vector (make_number (256), make_number (0)));