1 /* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985-1988, 1993, 2000-2013 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 "character.h"
44 #ifdef CHECK_FRAME_FONT
50 * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for
51 * debugging the byte compiler...)
53 * define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
55 /* #define BYTE_CODE_SAFE */
56 /* #define BYTE_CODE_METER */
58 /* If BYTE_CODE_THREADED is defined, then the interpreter will be
59 indirect threaded, using GCC's computed goto extension. This code,
60 as currently implemented, is incompatible with BYTE_CODE_SAFE and
62 #if defined (__GNUC__) && !defined (BYTE_CODE_SAFE) && !defined (BYTE_CODE_METER)
63 #define BYTE_CODE_THREADED
67 #ifdef BYTE_CODE_METER
69 Lisp_Object Qbyte_code_meter
;
70 #define METER_2(code1, code2) AREF (AREF (Vbyte_code_meter, code1), code2)
71 #define METER_1(code) METER_2 (0, code)
73 #define METER_CODE(last_code, this_code) \
75 if (byte_metering_on) \
77 if (XFASTINT (METER_1 (this_code)) < MOST_POSITIVE_FIXNUM) \
78 XSETFASTINT (METER_1 (this_code), \
79 XFASTINT (METER_1 (this_code)) + 1); \
81 && (XFASTINT (METER_2 (last_code, this_code)) \
82 < MOST_POSITIVE_FIXNUM)) \
83 XSETFASTINT (METER_2 (last_code, this_code), \
84 XFASTINT (METER_2 (last_code, this_code)) + 1); \
88 #endif /* BYTE_CODE_METER */
94 DEFINE (Bstack_ref, 0) /* Actually, Bstack_ref+0 is not implemented: use dup. */ \
95 DEFINE (Bstack_ref1, 1) \
96 DEFINE (Bstack_ref2, 2) \
97 DEFINE (Bstack_ref3, 3) \
98 DEFINE (Bstack_ref4, 4) \
99 DEFINE (Bstack_ref5, 5) \
100 DEFINE (Bstack_ref6, 6) \
101 DEFINE (Bstack_ref7, 7) \
102 DEFINE (Bvarref, 010) \
103 DEFINE (Bvarref1, 011) \
104 DEFINE (Bvarref2, 012) \
105 DEFINE (Bvarref3, 013) \
106 DEFINE (Bvarref4, 014) \
107 DEFINE (Bvarref5, 015) \
108 DEFINE (Bvarref6, 016) \
109 DEFINE (Bvarref7, 017) \
110 DEFINE (Bvarset, 020) \
111 DEFINE (Bvarset1, 021) \
112 DEFINE (Bvarset2, 022) \
113 DEFINE (Bvarset3, 023) \
114 DEFINE (Bvarset4, 024) \
115 DEFINE (Bvarset5, 025) \
116 DEFINE (Bvarset6, 026) \
117 DEFINE (Bvarset7, 027) \
118 DEFINE (Bvarbind, 030) \
119 DEFINE (Bvarbind1, 031) \
120 DEFINE (Bvarbind2, 032) \
121 DEFINE (Bvarbind3, 033) \
122 DEFINE (Bvarbind4, 034) \
123 DEFINE (Bvarbind5, 035) \
124 DEFINE (Bvarbind6, 036) \
125 DEFINE (Bvarbind7, 037) \
126 DEFINE (Bcall, 040) \
127 DEFINE (Bcall1, 041) \
128 DEFINE (Bcall2, 042) \
129 DEFINE (Bcall3, 043) \
130 DEFINE (Bcall4, 044) \
131 DEFINE (Bcall5, 045) \
132 DEFINE (Bcall6, 046) \
133 DEFINE (Bcall7, 047) \
134 DEFINE (Bunbind, 050) \
135 DEFINE (Bunbind1, 051) \
136 DEFINE (Bunbind2, 052) \
137 DEFINE (Bunbind3, 053) \
138 DEFINE (Bunbind4, 054) \
139 DEFINE (Bunbind5, 055) \
140 DEFINE (Bunbind6, 056) \
141 DEFINE (Bunbind7, 057) \
144 DEFINE (Bsymbolp, 071) \
145 DEFINE (Bconsp, 072) \
146 DEFINE (Bstringp, 073) \
147 DEFINE (Blistp, 074) \
149 DEFINE (Bmemq, 076) \
151 DEFINE (Bcar, 0100) \
152 DEFINE (Bcdr, 0101) \
153 DEFINE (Bcons, 0102) \
154 DEFINE (Blist1, 0103) \
155 DEFINE (Blist2, 0104) \
156 DEFINE (Blist3, 0105) \
157 DEFINE (Blist4, 0106) \
158 DEFINE (Blength, 0107) \
159 DEFINE (Baref, 0110) \
160 DEFINE (Baset, 0111) \
161 DEFINE (Bsymbol_value, 0112) \
162 DEFINE (Bsymbol_function, 0113) \
163 DEFINE (Bset, 0114) \
164 DEFINE (Bfset, 0115) \
165 DEFINE (Bget, 0116) \
166 DEFINE (Bsubstring, 0117) \
167 DEFINE (Bconcat2, 0120) \
168 DEFINE (Bconcat3, 0121) \
169 DEFINE (Bconcat4, 0122) \
170 DEFINE (Bsub1, 0123) \
171 DEFINE (Badd1, 0124) \
172 DEFINE (Beqlsign, 0125) \
173 DEFINE (Bgtr, 0126) \
174 DEFINE (Blss, 0127) \
175 DEFINE (Bleq, 0130) \
176 DEFINE (Bgeq, 0131) \
177 DEFINE (Bdiff, 0132) \
178 DEFINE (Bnegate, 0133) \
179 DEFINE (Bplus, 0134) \
180 DEFINE (Bmax, 0135) \
181 DEFINE (Bmin, 0136) \
182 DEFINE (Bmult, 0137) \
184 DEFINE (Bpoint, 0140) \
185 /* Was Bmark in v17. */ \
186 DEFINE (Bsave_current_buffer, 0141) /* Obsolete. */ \
187 DEFINE (Bgoto_char, 0142) \
188 DEFINE (Binsert, 0143) \
189 DEFINE (Bpoint_max, 0144) \
190 DEFINE (Bpoint_min, 0145) \
191 DEFINE (Bchar_after, 0146) \
192 DEFINE (Bfollowing_char, 0147) \
193 DEFINE (Bpreceding_char, 0150) \
194 DEFINE (Bcurrent_column, 0151) \
195 DEFINE (Bindent_to, 0152) \
196 DEFINE (Beolp, 0154) \
197 DEFINE (Beobp, 0155) \
198 DEFINE (Bbolp, 0156) \
199 DEFINE (Bbobp, 0157) \
200 DEFINE (Bcurrent_buffer, 0160) \
201 DEFINE (Bset_buffer, 0161) \
202 DEFINE (Bsave_current_buffer_1, 0162) /* Replacing Bsave_current_buffer. */ \
203 DEFINE (Binteractive_p, 0164) /* Obsolete since Emacs-24.1. */ \
205 DEFINE (Bforward_char, 0165) \
206 DEFINE (Bforward_word, 0166) \
207 DEFINE (Bskip_chars_forward, 0167) \
208 DEFINE (Bskip_chars_backward, 0170) \
209 DEFINE (Bforward_line, 0171) \
210 DEFINE (Bchar_syntax, 0172) \
211 DEFINE (Bbuffer_substring, 0173) \
212 DEFINE (Bdelete_region, 0174) \
213 DEFINE (Bnarrow_to_region, 0175) \
214 DEFINE (Bwiden, 0176) \
215 DEFINE (Bend_of_line, 0177) \
217 DEFINE (Bconstant2, 0201) \
218 DEFINE (Bgoto, 0202) \
219 DEFINE (Bgotoifnil, 0203) \
220 DEFINE (Bgotoifnonnil, 0204) \
221 DEFINE (Bgotoifnilelsepop, 0205) \
222 DEFINE (Bgotoifnonnilelsepop, 0206) \
223 DEFINE (Breturn, 0207) \
224 DEFINE (Bdiscard, 0210) \
225 DEFINE (Bdup, 0211) \
227 DEFINE (Bsave_excursion, 0212) \
228 DEFINE (Bsave_window_excursion, 0213) /* Obsolete since Emacs-24.1. */ \
229 DEFINE (Bsave_restriction, 0214) \
230 DEFINE (Bcatch, 0215) \
232 DEFINE (Bunwind_protect, 0216) \
233 DEFINE (Bcondition_case, 0217) \
234 DEFINE (Btemp_output_buffer_setup, 0220) /* Obsolete since Emacs-24.1. */ \
235 DEFINE (Btemp_output_buffer_show, 0221) /* Obsolete since Emacs-24.1. */ \
237 DEFINE (Bunbind_all, 0222) /* Obsolete. Never used. */ \
239 DEFINE (Bset_marker, 0223) \
240 DEFINE (Bmatch_beginning, 0224) \
241 DEFINE (Bmatch_end, 0225) \
242 DEFINE (Bupcase, 0226) \
243 DEFINE (Bdowncase, 0227) \
245 DEFINE (Bstringeqlsign, 0230) \
246 DEFINE (Bstringlss, 0231) \
247 DEFINE (Bequal, 0232) \
248 DEFINE (Bnthcdr, 0233) \
249 DEFINE (Belt, 0234) \
250 DEFINE (Bmember, 0235) \
251 DEFINE (Bassq, 0236) \
252 DEFINE (Bnreverse, 0237) \
253 DEFINE (Bsetcar, 0240) \
254 DEFINE (Bsetcdr, 0241) \
255 DEFINE (Bcar_safe, 0242) \
256 DEFINE (Bcdr_safe, 0243) \
257 DEFINE (Bnconc, 0244) \
258 DEFINE (Bquo, 0245) \
259 DEFINE (Brem, 0246) \
260 DEFINE (Bnumberp, 0247) \
261 DEFINE (Bintegerp, 0250) \
263 DEFINE (BRgoto, 0252) \
264 DEFINE (BRgotoifnil, 0253) \
265 DEFINE (BRgotoifnonnil, 0254) \
266 DEFINE (BRgotoifnilelsepop, 0255) \
267 DEFINE (BRgotoifnonnilelsepop, 0256) \
269 DEFINE (BlistN, 0257) \
270 DEFINE (BconcatN, 0260) \
271 DEFINE (BinsertN, 0261) \
273 /* Bstack_ref is code 0. */ \
274 DEFINE (Bstack_set, 0262) \
275 DEFINE (Bstack_set2, 0263) \
276 DEFINE (BdiscardN, 0266) \
278 DEFINE (Bconstant, 0300)
282 #define DEFINE(name, value) name = value,
286 #ifdef BYTE_CODE_SAFE
287 Bscan_buffer
= 0153, /* No longer generated as of v18. */
288 Bset_mark
= 0163 /* this loser is no longer generated as of v18 */
292 /* Whether to maintain a `top' and `bottom' field in the stack frame. */
293 #define BYTE_MAINTAIN_TOP (BYTE_CODE_SAFE || BYTE_MARK_STACK)
295 /* Structure describing a value stack used during byte-code execution
300 /* Program counter. This points into the byte_string below
301 and is relocated when that string is relocated. */
302 const unsigned char *pc
;
304 /* Top and bottom of stack. The bottom points to an area of memory
305 allocated with alloca in Fbyte_code. */
306 #if BYTE_MAINTAIN_TOP
307 Lisp_Object
*top
, *bottom
;
310 /* The string containing the byte-code, and its current address.
311 Storing this here protects it from GC because mark_byte_stack
313 Lisp_Object byte_string
;
314 const unsigned char *byte_string_start
;
316 /* The vector of constants used during byte-code execution. Storing
317 this here protects it from GC because mark_byte_stack marks it. */
318 Lisp_Object constants
;
320 /* Next entry in byte_stack_list. */
321 struct byte_stack
*next
;
324 /* A list of currently active byte-code execution value stacks.
325 Fbyte_code adds an entry to the head of this list before it starts
326 processing byte-code, and it removed the entry again when it is
327 done. Signaling an error truncates the list analogous to
330 struct byte_stack
*byte_stack_list
;
333 /* Mark objects on byte_stack_list. Called during GC. */
337 mark_byte_stack (void)
339 struct byte_stack
*stack
;
342 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
344 /* If STACK->top is null here, this means there's an opcode in
345 Fbyte_code that wasn't expected to GC, but did. To find out
346 which opcode this is, record the value of `stack', and walk
347 up the stack in a debugger, stopping in frames of Fbyte_code.
348 The culprit is found in the frame of Fbyte_code where the
349 address of its local variable `stack' is equal to the
350 recorded value of `stack' here. */
351 eassert (stack
->top
);
353 for (obj
= stack
->bottom
; obj
<= stack
->top
; ++obj
)
356 mark_object (stack
->byte_string
);
357 mark_object (stack
->constants
);
362 /* Unmark objects in the stacks on byte_stack_list. Relocate program
363 counters. Called when GC has completed. */
366 unmark_byte_stack (void)
368 struct byte_stack
*stack
;
370 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
372 if (stack
->byte_string_start
!= SDATA (stack
->byte_string
))
374 ptrdiff_t offset
= stack
->pc
- stack
->byte_string_start
;
375 stack
->byte_string_start
= SDATA (stack
->byte_string
);
376 stack
->pc
= stack
->byte_string_start
+ offset
;
382 /* Fetch the next byte from the bytecode stream */
384 #define FETCH *stack.pc++
386 /* Fetch two bytes from the bytecode stream and make a 16-bit number
389 #define FETCH2 (op = FETCH, op + (FETCH << 8))
391 /* Push x onto the execution stack. This used to be #define PUSH(x)
392 (*++stackp = (x)) This oddity is necessary because Alliant can't be
393 bothered to compile the preincrement operator properly, as of 4/91.
396 #define PUSH(x) (top++, *top = (x))
398 /* Pop a value off the execution stack. */
402 /* Discard n values from the execution stack. */
404 #define DISCARD(n) (top -= (n))
406 /* Get the value which is at the top of the execution stack, but don't
411 /* Actions that must be performed before and after calling a function
414 #if !BYTE_MAINTAIN_TOP
415 #define BEFORE_POTENTIAL_GC() ((void)0)
416 #define AFTER_POTENTIAL_GC() ((void)0)
418 #define BEFORE_POTENTIAL_GC() stack.top = top
419 #define AFTER_POTENTIAL_GC() stack.top = NULL
422 /* Garbage collect if we have consed enough since the last time.
423 We do this at every branch, to avoid loops that never GC. */
427 BEFORE_POTENTIAL_GC (); \
429 AFTER_POTENTIAL_GC (); \
432 /* Check for jumping out of range. */
434 #ifdef BYTE_CODE_SAFE
436 #define CHECK_RANGE(ARG) \
437 if (ARG >= bytestr_length) emacs_abort ()
439 #else /* not BYTE_CODE_SAFE */
441 #define CHECK_RANGE(ARG)
443 #endif /* not BYTE_CODE_SAFE */
445 /* A version of the QUIT macro which makes sure that the stack top is
446 set before signaling `quit'. */
448 #define BYTE_CODE_QUIT \
450 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
452 Lisp_Object flag = Vquit_flag; \
454 BEFORE_POTENTIAL_GC (); \
455 if (EQ (Vthrow_on_input, flag)) \
456 Fthrow (Vthrow_on_input, Qt); \
457 Fsignal (Qquit, Qnil); \
458 AFTER_POTENTIAL_GC (); \
460 else if (pending_signals) \
461 process_pending_signals (); \
465 DEFUN ("byte-code", Fbyte_code
, Sbyte_code
, 3, 3, 0,
466 doc
: /* Function used internally in byte-compiled code.
467 The first argument, BYTESTR, is a string of byte code;
468 the second, VECTOR, a vector of constants;
469 the third, MAXDEPTH, the maximum stack depth used in this function.
470 If the third argument is incorrect, Emacs may crash. */)
471 (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
)
473 return exec_byte_code (bytestr
, vector
, maxdepth
, Qnil
, 0, NULL
);
476 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
477 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
478 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
479 argument list (including &rest, &optional, etc.), and ARGS, of size
480 NARGS, should be a vector of the actual arguments. The arguments in
481 ARGS are pushed on the stack according to ARGS_TEMPLATE before
482 executing BYTESTR. */
485 exec_byte_code (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
,
486 Lisp_Object args_template
, ptrdiff_t nargs
, Lisp_Object
*args
)
488 ptrdiff_t count
= SPECPDL_INDEX ();
489 #ifdef BYTE_CODE_METER
494 /* Lisp_Object v1, v2; */
495 Lisp_Object
*vectorp
;
496 #ifdef BYTE_CODE_SAFE
497 ptrdiff_t const_length
;
499 ptrdiff_t bytestr_length
;
501 struct byte_stack stack
;
505 #if 0 /* CHECK_FRAME_FONT */
507 struct frame
*f
= SELECTED_FRAME ();
509 && FRAME_FONT (f
)->direction
!= 0
510 && FRAME_FONT (f
)->direction
!= 1)
515 CHECK_STRING (bytestr
);
516 CHECK_VECTOR (vector
);
517 CHECK_NATNUM (maxdepth
);
519 #ifdef BYTE_CODE_SAFE
520 const_length
= ASIZE (vector
);
523 if (STRING_MULTIBYTE (bytestr
))
524 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
525 because they produced a raw 8-bit string for byte-code and now
526 such a byte-code string is loaded as multibyte while raw 8-bit
527 characters converted to multibyte form. Thus, now we must
528 convert them back to the originally intended unibyte form. */
529 bytestr
= Fstring_as_unibyte (bytestr
);
531 #ifdef BYTE_CODE_SAFE
532 bytestr_length
= SBYTES (bytestr
);
534 vectorp
= XVECTOR (vector
)->contents
;
536 stack
.byte_string
= bytestr
;
537 stack
.pc
= stack
.byte_string_start
= SDATA (bytestr
);
538 stack
.constants
= vector
;
539 if (MAX_ALLOCA
/ word_size
<= XFASTINT (maxdepth
))
540 memory_full (SIZE_MAX
);
541 top
= alloca ((XFASTINT (maxdepth
) + 1) * sizeof *top
);
542 #if BYTE_MAINTAIN_TOP
543 stack
.bottom
= top
+ 1;
546 stack
.next
= byte_stack_list
;
547 byte_stack_list
= &stack
;
549 #ifdef BYTE_CODE_SAFE
550 stacke
= stack
.bottom
- 1 + XFASTINT (maxdepth
);
553 if (INTEGERP (args_template
))
555 ptrdiff_t at
= XINT (args_template
);
556 bool rest
= (at
& 128) != 0;
557 int mandatory
= at
& 127;
558 ptrdiff_t nonrest
= at
>> 8;
559 eassert (mandatory
<= nonrest
);
560 if (nargs
<= nonrest
)
563 for (i
= 0 ; i
< nargs
; i
++, args
++)
565 if (nargs
< mandatory
)
566 /* Too few arguments. */
567 Fsignal (Qwrong_number_of_arguments
,
568 Fcons (Fcons (make_number (mandatory
),
569 rest
? Qand_rest
: make_number (nonrest
)),
570 Fcons (make_number (nargs
), Qnil
)));
573 for (; i
< nonrest
; i
++)
582 for (i
= 0 ; i
< nonrest
; i
++, args
++)
584 PUSH (Flist (nargs
- nonrest
, args
));
587 /* Too many arguments. */
588 Fsignal (Qwrong_number_of_arguments
,
589 Fcons (Fcons (make_number (mandatory
),
590 make_number (nonrest
)),
591 Fcons (make_number (nargs
), Qnil
)));
593 else if (! NILP (args_template
))
594 /* We should push some arguments on the stack. */
596 error ("Unknown args template!");
601 #ifdef BYTE_CODE_SAFE
604 else if (top
< stack
.bottom
- 1)
608 #ifdef BYTE_CODE_METER
610 this_op
= op
= FETCH
;
611 METER_CODE (prev_op
, op
);
613 #ifndef BYTE_CODE_THREADED
618 /* The interpreter can be compiled one of two ways: as an
619 ordinary switch-based interpreter, or as a threaded
620 interpreter. The threaded interpreter relies on GCC's
621 computed goto extension, so it is not available everywhere.
622 Threading provides a performance boost. These macros are how
623 we allow the code to be compiled both ways. */
624 #ifdef BYTE_CODE_THREADED
625 /* The CASE macro introduces an instruction's body. It is
626 either a label or a case label. */
627 #define CASE(OP) insn_ ## OP
628 /* NEXT is invoked at the end of an instruction to go to the
629 next instruction. It is either a computed goto, or a
631 #define NEXT goto *(targets[op = FETCH])
632 /* FIRST is like NEXT, but is only used at the start of the
633 interpreter body. In the switch-based interpreter it is the
634 switch, so the threaded definition must include a semicolon. */
636 /* Most cases are labeled with the CASE macro, above.
637 CASE_DEFAULT is one exception; it is used if the interpreter
638 being built requires a default case. The threaded
639 interpreter does not, because the dispatch table is
640 completely filled. */
642 /* This introduces an instruction that is known to call abort. */
643 #define CASE_ABORT CASE (Bstack_ref): CASE (default)
645 /* See above for the meaning of the various defines. */
646 #define CASE(OP) case OP
648 #define FIRST switch (op)
649 #define CASE_DEFAULT case 255: default:
650 #define CASE_ABORT case 0
653 #ifdef BYTE_CODE_THREADED
655 /* A convenience define that saves us a lot of typing and makes
656 the table clearer. */
657 #define LABEL(OP) [OP] = &&insn_ ## OP
659 #if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
660 # pragma GCC diagnostic push
661 # pragma GCC diagnostic ignored "-Woverride-init"
664 /* This is the dispatch table for the threaded interpreter. */
665 static const void *const targets
[256] =
667 [0 ... (Bconstant
- 1)] = &&insn_default
,
668 [Bconstant
... 255] = &&insn_Bconstant
,
670 #define DEFINE(name, value) LABEL (name) ,
675 #if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
676 # pragma GCC diagnostic pop
697 /* This seems to be the most frequently executed byte-code
698 among the Bvarref's, so avoid a goto here. */
708 if (XSYMBOL (v1
)->redirect
!= SYMBOL_PLAINVAL
709 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)),
712 BEFORE_POTENTIAL_GC ();
713 v2
= Fsymbol_value (v1
);
714 AFTER_POTENTIAL_GC ();
719 BEFORE_POTENTIAL_GC ();
720 v2
= Fsymbol_value (v1
);
721 AFTER_POTENTIAL_GC ();
737 stack
.pc
= stack
.byte_string_start
+ op
;
752 BEFORE_POTENTIAL_GC ();
753 wrong_type_argument (Qlistp
, v1
);
754 AFTER_POTENTIAL_GC ();
763 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
770 BEFORE_POTENTIAL_GC ();
772 TOP
= Fmemq (TOP
, v1
);
773 AFTER_POTENTIAL_GC ();
787 BEFORE_POTENTIAL_GC ();
788 wrong_type_argument (Qlistp
, v1
);
789 AFTER_POTENTIAL_GC ();
811 Lisp_Object sym
, val
;
816 /* Inline the most common case. */
818 && !EQ (val
, Qunbound
)
819 && !XSYMBOL (sym
)->redirect
820 && !SYMBOL_CONSTANT_P (sym
))
821 SET_SYMBOL_VAL (XSYMBOL (sym
), val
);
824 BEFORE_POTENTIAL_GC ();
825 set_internal (sym
, val
, Qnil
, 0);
826 AFTER_POTENTIAL_GC ();
840 /* ------------------ */
858 /* Specbind can signal and thus GC. */
859 BEFORE_POTENTIAL_GC ();
860 specbind (vectorp
[op
], POP
);
861 AFTER_POTENTIAL_GC ();
881 BEFORE_POTENTIAL_GC ();
883 #ifdef BYTE_CODE_METER
884 if (byte_metering_on
&& SYMBOLP (TOP
))
889 v2
= Fget (v1
, Qbyte_code_meter
);
891 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
893 XSETINT (v2
, XINT (v2
) + 1);
894 Fput (v1
, Qbyte_code_meter
, v2
);
898 TOP
= Ffuncall (op
+ 1, &TOP
);
899 AFTER_POTENTIAL_GC ();
919 BEFORE_POTENTIAL_GC ();
920 unbind_to (SPECPDL_INDEX () - op
, Qnil
);
921 AFTER_POTENTIAL_GC ();
924 CASE (Bunbind_all
): /* Obsolete. Never used. */
925 /* To unbind back to the beginning of this frame. Not used yet,
926 but will be needed for tail-recursion elimination. */
927 BEFORE_POTENTIAL_GC ();
928 unbind_to (count
, Qnil
);
929 AFTER_POTENTIAL_GC ();
935 op
= FETCH2
; /* pc = FETCH2 loses since FETCH2 contains pc++ */
937 stack
.pc
= stack
.byte_string_start
+ op
;
940 CASE (Bgotoifnonnil
):
950 stack
.pc
= stack
.byte_string_start
+ op
;
955 CASE (Bgotoifnilelsepop
):
962 stack
.pc
= stack
.byte_string_start
+ op
;
967 CASE (Bgotoifnonnilelsepop
):
974 stack
.pc
= stack
.byte_string_start
+ op
;
982 stack
.pc
+= (int) *stack
.pc
- 127;
993 stack
.pc
+= (int) *stack
.pc
- 128;
999 CASE (BRgotoifnonnil
):
1007 stack
.pc
+= (int) *stack
.pc
- 128;
1013 CASE (BRgotoifnilelsepop
):
1019 stack
.pc
+= op
- 128;
1024 CASE (BRgotoifnonnilelsepop
):
1030 stack
.pc
+= op
- 128;
1044 PUSH (vectorp
[FETCH2
]);
1047 CASE (Bsave_excursion
):
1048 record_unwind_protect (save_excursion_restore
,
1049 save_excursion_save ());
1052 CASE (Bsave_current_buffer
): /* Obsolete since ??. */
1053 CASE (Bsave_current_buffer_1
):
1054 record_unwind_current_buffer ();
1057 CASE (Bsave_window_excursion
): /* Obsolete since 24.1. */
1059 register ptrdiff_t count1
= SPECPDL_INDEX ();
1060 record_unwind_protect (Fset_window_configuration
,
1061 Fcurrent_window_configuration (Qnil
));
1062 BEFORE_POTENTIAL_GC ();
1064 unbind_to (count1
, TOP
);
1065 AFTER_POTENTIAL_GC ();
1069 CASE (Bsave_restriction
):
1070 record_unwind_protect (save_restriction_restore
,
1071 save_restriction_save ());
1074 CASE (Bcatch
): /* FIXME: ill-suited for lexbind. */
1077 BEFORE_POTENTIAL_GC ();
1079 TOP
= internal_catch (TOP
, eval_sub
, v1
);
1080 AFTER_POTENTIAL_GC ();
1084 CASE (Bunwind_protect
): /* FIXME: avoid closure for lexbind. */
1085 record_unwind_protect (Fprogn
, POP
);
1088 CASE (Bcondition_case
): /* FIXME: ill-suited for lexbind. */
1090 Lisp_Object handlers
, body
;
1093 BEFORE_POTENTIAL_GC ();
1094 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
);
1095 AFTER_POTENTIAL_GC ();
1099 CASE (Btemp_output_buffer_setup
): /* Obsolete since 24.1. */
1100 BEFORE_POTENTIAL_GC ();
1102 temp_output_buffer_setup (SSDATA (TOP
));
1103 AFTER_POTENTIAL_GC ();
1104 TOP
= Vstandard_output
;
1107 CASE (Btemp_output_buffer_show
): /* Obsolete since 24.1. */
1110 BEFORE_POTENTIAL_GC ();
1112 temp_output_buffer_show (TOP
);
1114 /* pop binding of standard-output */
1115 unbind_to (SPECPDL_INDEX () - 1, Qnil
);
1116 AFTER_POTENTIAL_GC ();
1124 BEFORE_POTENTIAL_GC ();
1130 while (--n
>= 0 && CONSP (v1
))
1134 AFTER_POTENTIAL_GC ();
1139 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
1143 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
1147 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
1151 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
1155 TOP
= NILP (TOP
) ? Qt
: Qnil
;
1162 TOP
= Fcons (TOP
, v1
);
1167 TOP
= Fcons (TOP
, Qnil
);
1174 TOP
= Fcons (TOP
, Fcons (v1
, Qnil
));
1180 TOP
= Flist (3, &TOP
);
1185 TOP
= Flist (4, &TOP
);
1191 TOP
= Flist (op
, &TOP
);
1195 BEFORE_POTENTIAL_GC ();
1196 TOP
= Flength (TOP
);
1197 AFTER_POTENTIAL_GC ();
1203 BEFORE_POTENTIAL_GC ();
1205 TOP
= Faref (TOP
, v1
);
1206 AFTER_POTENTIAL_GC ();
1213 BEFORE_POTENTIAL_GC ();
1215 TOP
= Faset (TOP
, v1
, v2
);
1216 AFTER_POTENTIAL_GC ();
1220 CASE (Bsymbol_value
):
1221 BEFORE_POTENTIAL_GC ();
1222 TOP
= Fsymbol_value (TOP
);
1223 AFTER_POTENTIAL_GC ();
1226 CASE (Bsymbol_function
):
1227 BEFORE_POTENTIAL_GC ();
1228 TOP
= Fsymbol_function (TOP
);
1229 AFTER_POTENTIAL_GC ();
1235 BEFORE_POTENTIAL_GC ();
1237 TOP
= Fset (TOP
, v1
);
1238 AFTER_POTENTIAL_GC ();
1245 BEFORE_POTENTIAL_GC ();
1247 TOP
= Ffset (TOP
, v1
);
1248 AFTER_POTENTIAL_GC ();
1255 BEFORE_POTENTIAL_GC ();
1257 TOP
= Fget (TOP
, v1
);
1258 AFTER_POTENTIAL_GC ();
1265 BEFORE_POTENTIAL_GC ();
1267 TOP
= Fsubstring (TOP
, v1
, v2
);
1268 AFTER_POTENTIAL_GC ();
1273 BEFORE_POTENTIAL_GC ();
1275 TOP
= Fconcat (2, &TOP
);
1276 AFTER_POTENTIAL_GC ();
1280 BEFORE_POTENTIAL_GC ();
1282 TOP
= Fconcat (3, &TOP
);
1283 AFTER_POTENTIAL_GC ();
1287 BEFORE_POTENTIAL_GC ();
1289 TOP
= Fconcat (4, &TOP
);
1290 AFTER_POTENTIAL_GC ();
1295 BEFORE_POTENTIAL_GC ();
1297 TOP
= Fconcat (op
, &TOP
);
1298 AFTER_POTENTIAL_GC ();
1307 XSETINT (v1
, XINT (v1
) - 1);
1312 BEFORE_POTENTIAL_GC ();
1314 AFTER_POTENTIAL_GC ();
1325 XSETINT (v1
, XINT (v1
) + 1);
1330 BEFORE_POTENTIAL_GC ();
1332 AFTER_POTENTIAL_GC ();
1340 BEFORE_POTENTIAL_GC ();
1342 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
1343 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
1344 AFTER_POTENTIAL_GC ();
1345 if (FLOATP (v1
) || FLOATP (v2
))
1349 f1
= (FLOATP (v1
) ? XFLOAT_DATA (v1
) : XINT (v1
));
1350 f2
= (FLOATP (v2
) ? XFLOAT_DATA (v2
) : XINT (v2
));
1351 TOP
= (f1
== f2
? Qt
: Qnil
);
1354 TOP
= (XINT (v1
) == XINT (v2
) ? Qt
: Qnil
);
1361 BEFORE_POTENTIAL_GC ();
1363 TOP
= Fgtr (TOP
, v1
);
1364 AFTER_POTENTIAL_GC ();
1371 BEFORE_POTENTIAL_GC ();
1373 TOP
= Flss (TOP
, v1
);
1374 AFTER_POTENTIAL_GC ();
1381 BEFORE_POTENTIAL_GC ();
1383 TOP
= Fleq (TOP
, v1
);
1384 AFTER_POTENTIAL_GC ();
1391 BEFORE_POTENTIAL_GC ();
1393 TOP
= Fgeq (TOP
, v1
);
1394 AFTER_POTENTIAL_GC ();
1399 BEFORE_POTENTIAL_GC ();
1401 TOP
= Fminus (2, &TOP
);
1402 AFTER_POTENTIAL_GC ();
1411 XSETINT (v1
, - XINT (v1
));
1416 BEFORE_POTENTIAL_GC ();
1417 TOP
= Fminus (1, &TOP
);
1418 AFTER_POTENTIAL_GC ();
1424 BEFORE_POTENTIAL_GC ();
1426 TOP
= Fplus (2, &TOP
);
1427 AFTER_POTENTIAL_GC ();
1431 BEFORE_POTENTIAL_GC ();
1433 TOP
= Fmax (2, &TOP
);
1434 AFTER_POTENTIAL_GC ();
1438 BEFORE_POTENTIAL_GC ();
1440 TOP
= Fmin (2, &TOP
);
1441 AFTER_POTENTIAL_GC ();
1445 BEFORE_POTENTIAL_GC ();
1447 TOP
= Ftimes (2, &TOP
);
1448 AFTER_POTENTIAL_GC ();
1452 BEFORE_POTENTIAL_GC ();
1454 TOP
= Fquo (2, &TOP
);
1455 AFTER_POTENTIAL_GC ();
1461 BEFORE_POTENTIAL_GC ();
1463 TOP
= Frem (TOP
, v1
);
1464 AFTER_POTENTIAL_GC ();
1471 XSETFASTINT (v1
, PT
);
1477 BEFORE_POTENTIAL_GC ();
1478 TOP
= Fgoto_char (TOP
);
1479 AFTER_POTENTIAL_GC ();
1483 BEFORE_POTENTIAL_GC ();
1484 TOP
= Finsert (1, &TOP
);
1485 AFTER_POTENTIAL_GC ();
1490 BEFORE_POTENTIAL_GC ();
1492 TOP
= Finsert (op
, &TOP
);
1493 AFTER_POTENTIAL_GC ();
1499 XSETFASTINT (v1
, ZV
);
1507 XSETFASTINT (v1
, BEGV
);
1513 BEFORE_POTENTIAL_GC ();
1514 TOP
= Fchar_after (TOP
);
1515 AFTER_POTENTIAL_GC ();
1518 CASE (Bfollowing_char
):
1521 BEFORE_POTENTIAL_GC ();
1522 v1
= Ffollowing_char ();
1523 AFTER_POTENTIAL_GC ();
1528 CASE (Bpreceding_char
):
1531 BEFORE_POTENTIAL_GC ();
1532 v1
= Fprevious_char ();
1533 AFTER_POTENTIAL_GC ();
1538 CASE (Bcurrent_column
):
1541 BEFORE_POTENTIAL_GC ();
1542 XSETFASTINT (v1
, current_column ());
1543 AFTER_POTENTIAL_GC ();
1549 BEFORE_POTENTIAL_GC ();
1550 TOP
= Findent_to (TOP
, Qnil
);
1551 AFTER_POTENTIAL_GC ();
1570 CASE (Bcurrent_buffer
):
1571 PUSH (Fcurrent_buffer ());
1575 BEFORE_POTENTIAL_GC ();
1576 TOP
= Fset_buffer (TOP
);
1577 AFTER_POTENTIAL_GC ();
1580 CASE (Binteractive_p
): /* Obsolete since 24.1. */
1581 BEFORE_POTENTIAL_GC ();
1582 PUSH (call0 (intern ("interactive-p")));
1583 AFTER_POTENTIAL_GC ();
1586 CASE (Bforward_char
):
1587 BEFORE_POTENTIAL_GC ();
1588 TOP
= Fforward_char (TOP
);
1589 AFTER_POTENTIAL_GC ();
1592 CASE (Bforward_word
):
1593 BEFORE_POTENTIAL_GC ();
1594 TOP
= Fforward_word (TOP
);
1595 AFTER_POTENTIAL_GC ();
1598 CASE (Bskip_chars_forward
):
1601 BEFORE_POTENTIAL_GC ();
1603 TOP
= Fskip_chars_forward (TOP
, v1
);
1604 AFTER_POTENTIAL_GC ();
1608 CASE (Bskip_chars_backward
):
1611 BEFORE_POTENTIAL_GC ();
1613 TOP
= Fskip_chars_backward (TOP
, v1
);
1614 AFTER_POTENTIAL_GC ();
1618 CASE (Bforward_line
):
1619 BEFORE_POTENTIAL_GC ();
1620 TOP
= Fforward_line (TOP
);
1621 AFTER_POTENTIAL_GC ();
1624 CASE (Bchar_syntax
):
1628 BEFORE_POTENTIAL_GC ();
1629 CHECK_CHARACTER (TOP
);
1630 AFTER_POTENTIAL_GC ();
1632 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
1633 MAKE_CHAR_MULTIBYTE (c
);
1634 XSETFASTINT (TOP
, syntax_code_spec
[(int) SYNTAX (c
)]);
1638 CASE (Bbuffer_substring
):
1641 BEFORE_POTENTIAL_GC ();
1643 TOP
= Fbuffer_substring (TOP
, v1
);
1644 AFTER_POTENTIAL_GC ();
1648 CASE (Bdelete_region
):
1651 BEFORE_POTENTIAL_GC ();
1653 TOP
= Fdelete_region (TOP
, v1
);
1654 AFTER_POTENTIAL_GC ();
1658 CASE (Bnarrow_to_region
):
1661 BEFORE_POTENTIAL_GC ();
1663 TOP
= Fnarrow_to_region (TOP
, v1
);
1664 AFTER_POTENTIAL_GC ();
1669 BEFORE_POTENTIAL_GC ();
1671 AFTER_POTENTIAL_GC ();
1674 CASE (Bend_of_line
):
1675 BEFORE_POTENTIAL_GC ();
1676 TOP
= Fend_of_line (TOP
);
1677 AFTER_POTENTIAL_GC ();
1683 BEFORE_POTENTIAL_GC ();
1686 TOP
= Fset_marker (TOP
, v2
, v1
);
1687 AFTER_POTENTIAL_GC ();
1691 CASE (Bmatch_beginning
):
1692 BEFORE_POTENTIAL_GC ();
1693 TOP
= Fmatch_beginning (TOP
);
1694 AFTER_POTENTIAL_GC ();
1698 BEFORE_POTENTIAL_GC ();
1699 TOP
= Fmatch_end (TOP
);
1700 AFTER_POTENTIAL_GC ();
1704 BEFORE_POTENTIAL_GC ();
1705 TOP
= Fupcase (TOP
);
1706 AFTER_POTENTIAL_GC ();
1710 BEFORE_POTENTIAL_GC ();
1711 TOP
= Fdowncase (TOP
);
1712 AFTER_POTENTIAL_GC ();
1715 CASE (Bstringeqlsign
):
1718 BEFORE_POTENTIAL_GC ();
1720 TOP
= Fstring_equal (TOP
, v1
);
1721 AFTER_POTENTIAL_GC ();
1728 BEFORE_POTENTIAL_GC ();
1730 TOP
= Fstring_lessp (TOP
, v1
);
1731 AFTER_POTENTIAL_GC ();
1739 TOP
= Fequal (TOP
, v1
);
1746 BEFORE_POTENTIAL_GC ();
1748 TOP
= Fnthcdr (TOP
, v1
);
1749 AFTER_POTENTIAL_GC ();
1758 /* Exchange args and then do nth. */
1760 BEFORE_POTENTIAL_GC ();
1764 AFTER_POTENTIAL_GC ();
1767 while (--n
>= 0 && CONSP (v1
))
1774 BEFORE_POTENTIAL_GC ();
1776 TOP
= Felt (TOP
, v1
);
1777 AFTER_POTENTIAL_GC ();
1785 BEFORE_POTENTIAL_GC ();
1787 TOP
= Fmember (TOP
, v1
);
1788 AFTER_POTENTIAL_GC ();
1795 BEFORE_POTENTIAL_GC ();
1797 TOP
= Fassq (TOP
, v1
);
1798 AFTER_POTENTIAL_GC ();
1803 BEFORE_POTENTIAL_GC ();
1804 TOP
= Fnreverse (TOP
);
1805 AFTER_POTENTIAL_GC ();
1811 BEFORE_POTENTIAL_GC ();
1813 TOP
= Fsetcar (TOP
, v1
);
1814 AFTER_POTENTIAL_GC ();
1821 BEFORE_POTENTIAL_GC ();
1823 TOP
= Fsetcdr (TOP
, v1
);
1824 AFTER_POTENTIAL_GC ();
1832 TOP
= CAR_SAFE (v1
);
1840 TOP
= CDR_SAFE (v1
);
1845 BEFORE_POTENTIAL_GC ();
1847 TOP
= Fnconc (2, &TOP
);
1848 AFTER_POTENTIAL_GC ();
1852 TOP
= (NUMBERP (TOP
) ? Qt
: Qnil
);
1856 TOP
= INTEGERP (TOP
) ? Qt
: Qnil
;
1859 #ifdef BYTE_CODE_SAFE
1860 /* These are intentionally written using 'case' syntax,
1861 because they are incompatible with the threaded
1865 BEFORE_POTENTIAL_GC ();
1866 error ("set-mark is an obsolete bytecode");
1867 AFTER_POTENTIAL_GC ();
1870 BEFORE_POTENTIAL_GC ();
1871 error ("scan-buffer is an obsolete bytecode");
1872 AFTER_POTENTIAL_GC ();
1877 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1878 for that instead. */
1879 /* CASE (Bstack_ref): */
1880 error ("Invalid byte opcode");
1882 /* Handy byte-codes for lexical binding. */
1889 Lisp_Object
*ptr
= top
- (op
- Bstack_ref
);
1895 Lisp_Object
*ptr
= top
- (FETCH
);
1901 Lisp_Object
*ptr
= top
- (FETCH2
);
1906 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1908 Lisp_Object
*ptr
= top
- (FETCH
);
1914 Lisp_Object
*ptr
= top
- (FETCH2
);
1930 #ifdef BYTE_CODE_SAFE
1935 if ((op
-= Bconstant
) >= const_length
)
1941 PUSH (vectorp
[op
- Bconstant
]);
1949 byte_stack_list
= byte_stack_list
->next
;
1951 /* Binds and unbinds are supposed to be compiled balanced. */
1952 if (SPECPDL_INDEX () != count
)
1953 #ifdef BYTE_CODE_SAFE
1954 error ("binding stack not balanced (serious byte compiler bug)");
1963 syms_of_bytecode (void)
1965 defsubr (&Sbyte_code
);
1967 #ifdef BYTE_CODE_METER
1969 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter
,
1970 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
1971 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1972 opcode CODE has been executed.
1973 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1974 indicates how many times the byte opcodes CODE1 and CODE2 have been
1975 executed in succession. */);
1977 DEFVAR_BOOL ("byte-metering-on", byte_metering_on
,
1978 doc
: /* If non-nil, keep profiling information on byte code usage.
1979 The variable byte-code-meter indicates how often each byte opcode is used.
1980 If a symbol has a property named `byte-code-meter' whose value is an
1981 integer, it is incremented each time that symbol's function is called. */);
1983 byte_metering_on
= 0;
1984 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
1985 DEFSYM (Qbyte_code_meter
, "byte-code-meter");
1989 ASET (Vbyte_code_meter
, i
,
1990 Fmake_vector (make_number (256), make_number (0)));