1 /* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985-1988, 1993, 2000-2012 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 hacked on by jwz@lucid.com 17-jun-91
21 o added a compile-time switch to turn on simple sanity checking;
22 o put back the obsolete byte-codes for error-detection;
23 o added a new instruction, unbind_all, which I will use for
24 tail-recursion elimination;
25 o made temp_output_buffer_show be called with the right number
27 o made the new bytecodes be called with args in the right order;
28 o added metering support.
31 o added relative jump instructions;
32 o all conditionals now only do QUIT if they jump.
38 #include "character.h"
43 #ifdef CHECK_FRAME_FONT
49 * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for
50 * debugging the byte compiler...)
52 * define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
54 /* #define BYTE_CODE_SAFE */
55 /* #define BYTE_CODE_METER */
57 /* If BYTE_CODE_THREADED is defined, then the interpreter will be
58 indirect threaded, using GCC's computed goto extension. This code,
59 as currently implemented, is incompatible with BYTE_CODE_SAFE and
61 #if defined (__GNUC__) && !defined (BYTE_CODE_SAFE) && !defined (BYTE_CODE_METER)
62 #define BYTE_CODE_THREADED
66 #ifdef BYTE_CODE_METER
68 Lisp_Object Qbyte_code_meter
;
69 #define METER_2(code1, code2) AREF (AREF (Vbyte_code_meter, code1), code2)
70 #define METER_1(code) METER_2 (0, code)
72 #define METER_CODE(last_code, this_code) \
74 if (byte_metering_on) \
76 if (XFASTINT (METER_1 (this_code)) < MOST_POSITIVE_FIXNUM) \
77 XSETFASTINT (METER_1 (this_code), \
78 XFASTINT (METER_1 (this_code)) + 1); \
80 && (XFASTINT (METER_2 (last_code, this_code)) \
81 < MOST_POSITIVE_FIXNUM)) \
82 XSETFASTINT (METER_2 (last_code, this_code), \
83 XFASTINT (METER_2 (last_code, this_code)) + 1); \
87 #endif /* BYTE_CODE_METER */
90 Lisp_Object Qbytecode
;
95 DEFINE (Bstack_ref, 0) /* Actually, Bstack_ref+0 is not implemented: use dup. */ \
96 DEFINE (Bstack_ref1, 1) \
97 DEFINE (Bstack_ref2, 2) \
98 DEFINE (Bstack_ref3, 3) \
99 DEFINE (Bstack_ref4, 4) \
100 DEFINE (Bstack_ref5, 5) \
101 DEFINE (Bstack_ref6, 6) \
102 DEFINE (Bstack_ref7, 7) \
103 DEFINE (Bvarref, 010) \
104 DEFINE (Bvarref1, 011) \
105 DEFINE (Bvarref2, 012) \
106 DEFINE (Bvarref3, 013) \
107 DEFINE (Bvarref4, 014) \
108 DEFINE (Bvarref5, 015) \
109 DEFINE (Bvarref6, 016) \
110 DEFINE (Bvarref7, 017) \
111 DEFINE (Bvarset, 020) \
112 DEFINE (Bvarset1, 021) \
113 DEFINE (Bvarset2, 022) \
114 DEFINE (Bvarset3, 023) \
115 DEFINE (Bvarset4, 024) \
116 DEFINE (Bvarset5, 025) \
117 DEFINE (Bvarset6, 026) \
118 DEFINE (Bvarset7, 027) \
119 DEFINE (Bvarbind, 030) \
120 DEFINE (Bvarbind1, 031) \
121 DEFINE (Bvarbind2, 032) \
122 DEFINE (Bvarbind3, 033) \
123 DEFINE (Bvarbind4, 034) \
124 DEFINE (Bvarbind5, 035) \
125 DEFINE (Bvarbind6, 036) \
126 DEFINE (Bvarbind7, 037) \
127 DEFINE (Bcall, 040) \
128 DEFINE (Bcall1, 041) \
129 DEFINE (Bcall2, 042) \
130 DEFINE (Bcall3, 043) \
131 DEFINE (Bcall4, 044) \
132 DEFINE (Bcall5, 045) \
133 DEFINE (Bcall6, 046) \
134 DEFINE (Bcall7, 047) \
135 DEFINE (Bunbind, 050) \
136 DEFINE (Bunbind1, 051) \
137 DEFINE (Bunbind2, 052) \
138 DEFINE (Bunbind3, 053) \
139 DEFINE (Bunbind4, 054) \
140 DEFINE (Bunbind5, 055) \
141 DEFINE (Bunbind6, 056) \
142 DEFINE (Bunbind7, 057) \
145 DEFINE (Bsymbolp, 071) \
146 DEFINE (Bconsp, 072) \
147 DEFINE (Bstringp, 073) \
148 DEFINE (Blistp, 074) \
150 DEFINE (Bmemq, 076) \
152 DEFINE (Bcar, 0100) \
153 DEFINE (Bcdr, 0101) \
154 DEFINE (Bcons, 0102) \
155 DEFINE (Blist1, 0103) \
156 DEFINE (Blist2, 0104) \
157 DEFINE (Blist3, 0105) \
158 DEFINE (Blist4, 0106) \
159 DEFINE (Blength, 0107) \
160 DEFINE (Baref, 0110) \
161 DEFINE (Baset, 0111) \
162 DEFINE (Bsymbol_value, 0112) \
163 DEFINE (Bsymbol_function, 0113) \
164 DEFINE (Bset, 0114) \
165 DEFINE (Bfset, 0115) \
166 DEFINE (Bget, 0116) \
167 DEFINE (Bsubstring, 0117) \
168 DEFINE (Bconcat2, 0120) \
169 DEFINE (Bconcat3, 0121) \
170 DEFINE (Bconcat4, 0122) \
171 DEFINE (Bsub1, 0123) \
172 DEFINE (Badd1, 0124) \
173 DEFINE (Beqlsign, 0125) \
174 DEFINE (Bgtr, 0126) \
175 DEFINE (Blss, 0127) \
176 DEFINE (Bleq, 0130) \
177 DEFINE (Bgeq, 0131) \
178 DEFINE (Bdiff, 0132) \
179 DEFINE (Bnegate, 0133) \
180 DEFINE (Bplus, 0134) \
181 DEFINE (Bmax, 0135) \
182 DEFINE (Bmin, 0136) \
183 DEFINE (Bmult, 0137) \
185 DEFINE (Bpoint, 0140) \
186 /* Was Bmark in v17. */ \
187 DEFINE (Bsave_current_buffer, 0141) /* Obsolete. */ \
188 DEFINE (Bgoto_char, 0142) \
189 DEFINE (Binsert, 0143) \
190 DEFINE (Bpoint_max, 0144) \
191 DEFINE (Bpoint_min, 0145) \
192 DEFINE (Bchar_after, 0146) \
193 DEFINE (Bfollowing_char, 0147) \
194 DEFINE (Bpreceding_char, 0150) \
195 DEFINE (Bcurrent_column, 0151) \
196 DEFINE (Bindent_to, 0152) \
197 DEFINE (Beolp, 0154) \
198 DEFINE (Beobp, 0155) \
199 DEFINE (Bbolp, 0156) \
200 DEFINE (Bbobp, 0157) \
201 DEFINE (Bcurrent_buffer, 0160) \
202 DEFINE (Bset_buffer, 0161) \
203 DEFINE (Bsave_current_buffer_1, 0162) /* Replacing Bsave_current_buffer. */ \
204 DEFINE (Binteractive_p, 0164) /* Obsolete since Emacs-24.1. */ \
206 DEFINE (Bforward_char, 0165) \
207 DEFINE (Bforward_word, 0166) \
208 DEFINE (Bskip_chars_forward, 0167) \
209 DEFINE (Bskip_chars_backward, 0170) \
210 DEFINE (Bforward_line, 0171) \
211 DEFINE (Bchar_syntax, 0172) \
212 DEFINE (Bbuffer_substring, 0173) \
213 DEFINE (Bdelete_region, 0174) \
214 DEFINE (Bnarrow_to_region, 0175) \
215 DEFINE (Bwiden, 0176) \
216 DEFINE (Bend_of_line, 0177) \
218 DEFINE (Bconstant2, 0201) \
219 DEFINE (Bgoto, 0202) \
220 DEFINE (Bgotoifnil, 0203) \
221 DEFINE (Bgotoifnonnil, 0204) \
222 DEFINE (Bgotoifnilelsepop, 0205) \
223 DEFINE (Bgotoifnonnilelsepop, 0206) \
224 DEFINE (Breturn, 0207) \
225 DEFINE (Bdiscard, 0210) \
226 DEFINE (Bdup, 0211) \
228 DEFINE (Bsave_excursion, 0212) \
229 DEFINE (Bsave_window_excursion, 0213) /* Obsolete since Emacs-24.1. */ \
230 DEFINE (Bsave_restriction, 0214) \
231 DEFINE (Bcatch, 0215) \
233 DEFINE (Bunwind_protect, 0216) \
234 DEFINE (Bcondition_case, 0217) \
235 DEFINE (Btemp_output_buffer_setup, 0220) /* Obsolete since Emacs-24.1. */ \
236 DEFINE (Btemp_output_buffer_show, 0221) /* Obsolete since Emacs-24.1. */ \
238 DEFINE (Bunbind_all, 0222) /* Obsolete. Never used. */ \
240 DEFINE (Bset_marker, 0223) \
241 DEFINE (Bmatch_beginning, 0224) \
242 DEFINE (Bmatch_end, 0225) \
243 DEFINE (Bupcase, 0226) \
244 DEFINE (Bdowncase, 0227) \
246 DEFINE (Bstringeqlsign, 0230) \
247 DEFINE (Bstringlss, 0231) \
248 DEFINE (Bequal, 0232) \
249 DEFINE (Bnthcdr, 0233) \
250 DEFINE (Belt, 0234) \
251 DEFINE (Bmember, 0235) \
252 DEFINE (Bassq, 0236) \
253 DEFINE (Bnreverse, 0237) \
254 DEFINE (Bsetcar, 0240) \
255 DEFINE (Bsetcdr, 0241) \
256 DEFINE (Bcar_safe, 0242) \
257 DEFINE (Bcdr_safe, 0243) \
258 DEFINE (Bnconc, 0244) \
259 DEFINE (Bquo, 0245) \
260 DEFINE (Brem, 0246) \
261 DEFINE (Bnumberp, 0247) \
262 DEFINE (Bintegerp, 0250) \
264 DEFINE (BRgoto, 0252) \
265 DEFINE (BRgotoifnil, 0253) \
266 DEFINE (BRgotoifnonnil, 0254) \
267 DEFINE (BRgotoifnilelsepop, 0255) \
268 DEFINE (BRgotoifnonnilelsepop, 0256) \
270 DEFINE (BlistN, 0257) \
271 DEFINE (BconcatN, 0260) \
272 DEFINE (BinsertN, 0261) \
274 /* Bstack_ref is code 0. */ \
275 DEFINE (Bstack_set, 0262) \
276 DEFINE (Bstack_set2, 0263) \
277 DEFINE (BdiscardN, 0266) \
279 DEFINE (Bconstant, 0300)
283 #define DEFINE(name, value) name = value,
287 #ifdef BYTE_CODE_SAFE
288 Bscan_buffer
= 0153, /* No longer generated as of v18. */
289 Bset_mark
= 0163 /* this loser is no longer generated as of v18 */
293 /* Whether to maintain a `top' and `bottom' field in the stack frame. */
294 #define BYTE_MAINTAIN_TOP (BYTE_CODE_SAFE || BYTE_MARK_STACK)
296 /* Structure describing a value stack used during byte-code execution
301 /* Program counter. This points into the byte_string below
302 and is relocated when that string is relocated. */
303 const unsigned char *pc
;
305 /* Top and bottom of stack. The bottom points to an area of memory
306 allocated with alloca in Fbyte_code. */
307 #if BYTE_MAINTAIN_TOP
308 Lisp_Object
*top
, *bottom
;
311 /* The string containing the byte-code, and its current address.
312 Storing this here protects it from GC because mark_byte_stack
314 Lisp_Object byte_string
;
315 const unsigned char *byte_string_start
;
317 /* The vector of constants used during byte-code execution. Storing
318 this here protects it from GC because mark_byte_stack marks it. */
319 Lisp_Object constants
;
321 /* Next entry in byte_stack_list. */
322 struct byte_stack
*next
;
325 /* A list of currently active byte-code execution value stacks.
326 Fbyte_code adds an entry to the head of this list before it starts
327 processing byte-code, and it removed the entry again when it is
328 done. Signaling an error truncates the list analogous to
331 struct byte_stack
*byte_stack_list
;
334 /* Mark objects on byte_stack_list. Called during GC. */
338 mark_byte_stack (void)
340 struct byte_stack
*stack
;
343 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
345 /* If STACK->top is null here, this means there's an opcode in
346 Fbyte_code that wasn't expected to GC, but did. To find out
347 which opcode this is, record the value of `stack', and walk
348 up the stack in a debugger, stopping in frames of Fbyte_code.
349 The culprit is found in the frame of Fbyte_code where the
350 address of its local variable `stack' is equal to the
351 recorded value of `stack' here. */
352 eassert (stack
->top
);
354 for (obj
= stack
->bottom
; obj
<= stack
->top
; ++obj
)
357 mark_object (stack
->byte_string
);
358 mark_object (stack
->constants
);
363 /* Unmark objects in the stacks on byte_stack_list. Relocate program
364 counters. Called when GC has completed. */
367 unmark_byte_stack (void)
369 struct byte_stack
*stack
;
371 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
373 if (stack
->byte_string_start
!= SDATA (stack
->byte_string
))
375 ptrdiff_t offset
= stack
->pc
- stack
->byte_string_start
;
376 stack
->byte_string_start
= SDATA (stack
->byte_string
);
377 stack
->pc
= stack
->byte_string_start
+ offset
;
383 /* Fetch the next byte from the bytecode stream */
385 #define FETCH *stack.pc++
387 /* Fetch two bytes from the bytecode stream and make a 16-bit number
390 #define FETCH2 (op = FETCH, op + (FETCH << 8))
392 /* Push x onto the execution stack. This used to be #define PUSH(x)
393 (*++stackp = (x)) This oddity is necessary because Alliant can't be
394 bothered to compile the preincrement operator properly, as of 4/91.
397 #define PUSH(x) (top++, *top = (x))
399 /* Pop a value off the execution stack. */
403 /* Discard n values from the execution stack. */
405 #define DISCARD(n) (top -= (n))
407 /* Get the value which is at the top of the execution stack, but don't
412 /* Actions that must be performed before and after calling a function
415 #if !BYTE_MAINTAIN_TOP
416 #define BEFORE_POTENTIAL_GC() ((void)0)
417 #define AFTER_POTENTIAL_GC() ((void)0)
419 #define BEFORE_POTENTIAL_GC() stack.top = top
420 #define AFTER_POTENTIAL_GC() stack.top = NULL
423 /* Garbage collect if we have consed enough since the last time.
424 We do this at every branch, to avoid loops that never GC. */
428 BEFORE_POTENTIAL_GC (); \
430 AFTER_POTENTIAL_GC (); \
433 /* Check for jumping out of range. */
435 #ifdef BYTE_CODE_SAFE
437 #define CHECK_RANGE(ARG) \
438 if (ARG >= bytestr_length) emacs_abort ()
440 #else /* not BYTE_CODE_SAFE */
442 #define CHECK_RANGE(ARG)
444 #endif /* not BYTE_CODE_SAFE */
446 /* A version of the QUIT macro which makes sure that the stack top is
447 set before signaling `quit'. */
449 #define BYTE_CODE_QUIT \
451 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
453 Lisp_Object flag = Vquit_flag; \
455 BEFORE_POTENTIAL_GC (); \
456 if (EQ (Vthrow_on_input, flag)) \
457 Fthrow (Vthrow_on_input, Qt); \
458 Fsignal (Qquit, Qnil); \
459 AFTER_POTENTIAL_GC (); \
461 else if (pending_signals) \
462 process_pending_signals (); \
466 DEFUN ("byte-code", Fbyte_code
, Sbyte_code
, 3, 3, 0,
467 doc
: /* Function used internally in byte-compiled code.
468 The first argument, BYTESTR, is a string of byte code;
469 the second, VECTOR, a vector of constants;
470 the third, MAXDEPTH, the maximum stack depth used in this function.
471 If the third argument is incorrect, Emacs may crash. */)
472 (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
)
474 return exec_byte_code (bytestr
, vector
, maxdepth
, Qnil
, 0, NULL
);
477 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
478 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
479 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
480 argument list (including &rest, &optional, etc.), and ARGS, of size
481 NARGS, should be a vector of the actual arguments. The arguments in
482 ARGS are pushed on the stack according to ARGS_TEMPLATE before
483 executing BYTESTR. */
486 exec_byte_code (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
,
487 Lisp_Object args_template
, ptrdiff_t nargs
, Lisp_Object
*args
)
489 ptrdiff_t count
= SPECPDL_INDEX ();
490 #ifdef BYTE_CODE_METER
495 /* Lisp_Object v1, v2; */
496 Lisp_Object
*vectorp
;
497 #ifdef BYTE_CODE_SAFE
498 ptrdiff_t const_length
;
500 ptrdiff_t bytestr_length
;
502 struct byte_stack stack
;
506 #if 0 /* CHECK_FRAME_FONT */
508 struct frame
*f
= SELECTED_FRAME ();
510 && FRAME_FONT (f
)->direction
!= 0
511 && FRAME_FONT (f
)->direction
!= 1)
516 CHECK_STRING (bytestr
);
517 CHECK_VECTOR (vector
);
518 CHECK_NATNUM (maxdepth
);
520 #ifdef BYTE_CODE_SAFE
521 const_length
= ASIZE (vector
);
524 if (STRING_MULTIBYTE (bytestr
))
525 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
526 because they produced a raw 8-bit string for byte-code and now
527 such a byte-code string is loaded as multibyte while raw 8-bit
528 characters converted to multibyte form. Thus, now we must
529 convert them back to the originally intended unibyte form. */
530 bytestr
= Fstring_as_unibyte (bytestr
);
532 #ifdef BYTE_CODE_SAFE
533 bytestr_length
= SBYTES (bytestr
);
535 vectorp
= XVECTOR (vector
)->contents
;
537 stack
.byte_string
= bytestr
;
538 stack
.pc
= stack
.byte_string_start
= SDATA (bytestr
);
539 stack
.constants
= vector
;
540 if (MAX_ALLOCA
/ word_size
<= XFASTINT (maxdepth
))
541 memory_full (SIZE_MAX
);
542 top
= alloca ((XFASTINT (maxdepth
) + 1) * sizeof *top
);
543 #if BYTE_MAINTAIN_TOP
544 stack
.bottom
= top
+ 1;
547 stack
.next
= byte_stack_list
;
548 byte_stack_list
= &stack
;
550 #ifdef BYTE_CODE_SAFE
551 stacke
= stack
.bottom
- 1 + XFASTINT (maxdepth
);
554 if (INTEGERP (args_template
))
556 ptrdiff_t at
= XINT (args_template
);
557 bool rest
= (at
& 128) != 0;
558 int mandatory
= at
& 127;
559 ptrdiff_t nonrest
= at
>> 8;
560 eassert (mandatory
<= nonrest
);
561 if (nargs
<= nonrest
)
564 for (i
= 0 ; i
< nargs
; i
++, args
++)
566 if (nargs
< mandatory
)
567 /* Too few arguments. */
568 Fsignal (Qwrong_number_of_arguments
,
569 Fcons (Fcons (make_number (mandatory
),
570 rest
? Qand_rest
: make_number (nonrest
)),
571 Fcons (make_number (nargs
), Qnil
)));
574 for (; i
< nonrest
; i
++)
583 for (i
= 0 ; i
< nonrest
; i
++, args
++)
585 PUSH (Flist (nargs
- nonrest
, args
));
588 /* Too many arguments. */
589 Fsignal (Qwrong_number_of_arguments
,
590 Fcons (Fcons (make_number (mandatory
),
591 make_number (nonrest
)),
592 Fcons (make_number (nargs
), Qnil
)));
594 else if (! NILP (args_template
))
595 /* We should push some arguments on the stack. */
597 error ("Unknown args template!");
602 #ifdef BYTE_CODE_SAFE
605 else if (top
< stack
.bottom
- 1)
609 #ifdef BYTE_CODE_METER
611 this_op
= op
= FETCH
;
612 METER_CODE (prev_op
, op
);
614 #ifndef BYTE_CODE_THREADED
619 /* The interpreter can be compiled one of two ways: as an
620 ordinary switch-based interpreter, or as a threaded
621 interpreter. The threaded interpreter relies on GCC's
622 computed goto extension, so it is not available everywhere.
623 Threading provides a performance boost. These macros are how
624 we allow the code to be compiled both ways. */
625 #ifdef BYTE_CODE_THREADED
626 /* The CASE macro introduces an instruction's body. It is
627 either a label or a case label. */
628 #define CASE(OP) insn_ ## OP
629 /* NEXT is invoked at the end of an instruction to go to the
630 next instruction. It is either a computed goto, or a
632 #define NEXT goto *(targets[op = FETCH])
633 /* FIRST is like NEXT, but is only used at the start of the
634 interpreter body. In the switch-based interpreter it is the
635 switch, so the threaded definition must include a semicolon. */
637 /* Most cases are labeled with the CASE macro, above.
638 CASE_DEFAULT is one exception; it is used if the interpreter
639 being built requires a default case. The threaded
640 interpreter does not, because the dispatch table is
641 completely filled. */
643 /* This introduces an instruction that is known to call abort. */
644 #define CASE_ABORT CASE (Bstack_ref): CASE (default)
646 /* See above for the meaning of the various defines. */
647 #define CASE(OP) case OP
649 #define FIRST switch (op)
650 #define CASE_DEFAULT case 255: default:
651 #define CASE_ABORT case 0
654 #ifdef BYTE_CODE_THREADED
656 /* A convenience define that saves us a lot of typing and makes
657 the table clearer. */
658 #define LABEL(OP) [OP] = &&insn_ ## OP
660 #if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
661 # pragma GCC diagnostic push
662 # pragma GCC diagnostic ignored "-Woverride-init"
665 /* This is the dispatch table for the threaded interpreter. */
666 static const void *const targets
[256] =
668 [0 ... (Bconstant
- 1)] = &&insn_default
,
669 [Bconstant
... 255] = &&insn_Bconstant
,
671 #define DEFINE(name, value) LABEL (name) ,
676 #if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
677 # pragma GCC diagnostic pop
698 /* This seems to be the most frequently executed byte-code
699 among the Bvarref's, so avoid a goto here. */
709 if (XSYMBOL (v1
)->redirect
!= SYMBOL_PLAINVAL
710 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)),
713 BEFORE_POTENTIAL_GC ();
714 v2
= Fsymbol_value (v1
);
715 AFTER_POTENTIAL_GC ();
720 BEFORE_POTENTIAL_GC ();
721 v2
= Fsymbol_value (v1
);
722 AFTER_POTENTIAL_GC ();
738 stack
.pc
= stack
.byte_string_start
+ op
;
753 BEFORE_POTENTIAL_GC ();
754 wrong_type_argument (Qlistp
, v1
);
755 AFTER_POTENTIAL_GC ();
764 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
771 BEFORE_POTENTIAL_GC ();
773 TOP
= Fmemq (TOP
, v1
);
774 AFTER_POTENTIAL_GC ();
788 BEFORE_POTENTIAL_GC ();
789 wrong_type_argument (Qlistp
, v1
);
790 AFTER_POTENTIAL_GC ();
812 Lisp_Object sym
, val
;
817 /* Inline the most common case. */
819 && !EQ (val
, Qunbound
)
820 && !XSYMBOL (sym
)->redirect
821 && !SYMBOL_CONSTANT_P (sym
))
822 SET_SYMBOL_VAL (XSYMBOL (sym
), val
);
825 BEFORE_POTENTIAL_GC ();
826 set_internal (sym
, val
, Qnil
, 0);
827 AFTER_POTENTIAL_GC ();
841 /* ------------------ */
859 /* Specbind can signal and thus GC. */
860 BEFORE_POTENTIAL_GC ();
861 specbind (vectorp
[op
], POP
);
862 AFTER_POTENTIAL_GC ();
882 BEFORE_POTENTIAL_GC ();
884 #ifdef BYTE_CODE_METER
885 if (byte_metering_on
&& SYMBOLP (TOP
))
890 v2
= Fget (v1
, Qbyte_code_meter
);
892 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
894 XSETINT (v2
, XINT (v2
) + 1);
895 Fput (v1
, Qbyte_code_meter
, v2
);
899 TOP
= Ffuncall (op
+ 1, &TOP
);
900 AFTER_POTENTIAL_GC ();
920 BEFORE_POTENTIAL_GC ();
921 unbind_to (SPECPDL_INDEX () - op
, Qnil
);
922 AFTER_POTENTIAL_GC ();
925 CASE (Bunbind_all
): /* Obsolete. Never used. */
926 /* To unbind back to the beginning of this frame. Not used yet,
927 but will be needed for tail-recursion elimination. */
928 BEFORE_POTENTIAL_GC ();
929 unbind_to (count
, Qnil
);
930 AFTER_POTENTIAL_GC ();
936 op
= FETCH2
; /* pc = FETCH2 loses since FETCH2 contains pc++ */
938 stack
.pc
= stack
.byte_string_start
+ op
;
941 CASE (Bgotoifnonnil
):
951 stack
.pc
= stack
.byte_string_start
+ op
;
956 CASE (Bgotoifnilelsepop
):
963 stack
.pc
= stack
.byte_string_start
+ op
;
968 CASE (Bgotoifnonnilelsepop
):
975 stack
.pc
= stack
.byte_string_start
+ op
;
983 stack
.pc
+= (int) *stack
.pc
- 127;
994 stack
.pc
+= (int) *stack
.pc
- 128;
1000 CASE (BRgotoifnonnil
):
1008 stack
.pc
+= (int) *stack
.pc
- 128;
1014 CASE (BRgotoifnilelsepop
):
1020 stack
.pc
+= op
- 128;
1025 CASE (BRgotoifnonnilelsepop
):
1031 stack
.pc
+= op
- 128;
1045 PUSH (vectorp
[FETCH2
]);
1048 CASE (Bsave_excursion
):
1049 record_unwind_protect (save_excursion_restore
,
1050 save_excursion_save ());
1053 CASE (Bsave_current_buffer
): /* Obsolete since ??. */
1054 CASE (Bsave_current_buffer_1
):
1055 record_unwind_current_buffer ();
1058 CASE (Bsave_window_excursion
): /* Obsolete since 24.1. */
1060 register ptrdiff_t count1
= SPECPDL_INDEX ();
1061 record_unwind_protect (Fset_window_configuration
,
1062 Fcurrent_window_configuration (Qnil
));
1063 BEFORE_POTENTIAL_GC ();
1065 unbind_to (count1
, TOP
);
1066 AFTER_POTENTIAL_GC ();
1070 CASE (Bsave_restriction
):
1071 record_unwind_protect (save_restriction_restore
,
1072 save_restriction_save ());
1075 CASE (Bcatch
): /* FIXME: ill-suited for lexbind. */
1078 BEFORE_POTENTIAL_GC ();
1080 TOP
= internal_catch (TOP
, eval_sub
, v1
);
1081 AFTER_POTENTIAL_GC ();
1085 CASE (Bunwind_protect
): /* FIXME: avoid closure for lexbind. */
1086 record_unwind_protect (Fprogn
, POP
);
1089 CASE (Bcondition_case
): /* FIXME: ill-suited for lexbind. */
1091 Lisp_Object handlers
, body
;
1094 BEFORE_POTENTIAL_GC ();
1095 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
);
1096 AFTER_POTENTIAL_GC ();
1100 CASE (Btemp_output_buffer_setup
): /* Obsolete since 24.1. */
1101 BEFORE_POTENTIAL_GC ();
1103 temp_output_buffer_setup (SSDATA (TOP
));
1104 AFTER_POTENTIAL_GC ();
1105 TOP
= Vstandard_output
;
1108 CASE (Btemp_output_buffer_show
): /* Obsolete since 24.1. */
1111 BEFORE_POTENTIAL_GC ();
1113 temp_output_buffer_show (TOP
);
1115 /* pop binding of standard-output */
1116 unbind_to (SPECPDL_INDEX () - 1, Qnil
);
1117 AFTER_POTENTIAL_GC ();
1125 BEFORE_POTENTIAL_GC ();
1131 while (--n
>= 0 && CONSP (v1
))
1135 AFTER_POTENTIAL_GC ();
1140 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
1144 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
1148 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
1152 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
1156 TOP
= NILP (TOP
) ? Qt
: Qnil
;
1163 TOP
= Fcons (TOP
, v1
);
1168 TOP
= Fcons (TOP
, Qnil
);
1175 TOP
= Fcons (TOP
, Fcons (v1
, Qnil
));
1181 TOP
= Flist (3, &TOP
);
1186 TOP
= Flist (4, &TOP
);
1192 TOP
= Flist (op
, &TOP
);
1196 BEFORE_POTENTIAL_GC ();
1197 TOP
= Flength (TOP
);
1198 AFTER_POTENTIAL_GC ();
1204 BEFORE_POTENTIAL_GC ();
1206 TOP
= Faref (TOP
, v1
);
1207 AFTER_POTENTIAL_GC ();
1214 BEFORE_POTENTIAL_GC ();
1216 TOP
= Faset (TOP
, v1
, v2
);
1217 AFTER_POTENTIAL_GC ();
1221 CASE (Bsymbol_value
):
1222 BEFORE_POTENTIAL_GC ();
1223 TOP
= Fsymbol_value (TOP
);
1224 AFTER_POTENTIAL_GC ();
1227 CASE (Bsymbol_function
):
1228 BEFORE_POTENTIAL_GC ();
1229 TOP
= Fsymbol_function (TOP
);
1230 AFTER_POTENTIAL_GC ();
1236 BEFORE_POTENTIAL_GC ();
1238 TOP
= Fset (TOP
, v1
);
1239 AFTER_POTENTIAL_GC ();
1246 BEFORE_POTENTIAL_GC ();
1248 TOP
= Ffset (TOP
, v1
);
1249 AFTER_POTENTIAL_GC ();
1256 BEFORE_POTENTIAL_GC ();
1258 TOP
= Fget (TOP
, v1
);
1259 AFTER_POTENTIAL_GC ();
1266 BEFORE_POTENTIAL_GC ();
1268 TOP
= Fsubstring (TOP
, v1
, v2
);
1269 AFTER_POTENTIAL_GC ();
1274 BEFORE_POTENTIAL_GC ();
1276 TOP
= Fconcat (2, &TOP
);
1277 AFTER_POTENTIAL_GC ();
1281 BEFORE_POTENTIAL_GC ();
1283 TOP
= Fconcat (3, &TOP
);
1284 AFTER_POTENTIAL_GC ();
1288 BEFORE_POTENTIAL_GC ();
1290 TOP
= Fconcat (4, &TOP
);
1291 AFTER_POTENTIAL_GC ();
1296 BEFORE_POTENTIAL_GC ();
1298 TOP
= Fconcat (op
, &TOP
);
1299 AFTER_POTENTIAL_GC ();
1308 XSETINT (v1
, XINT (v1
) - 1);
1313 BEFORE_POTENTIAL_GC ();
1315 AFTER_POTENTIAL_GC ();
1326 XSETINT (v1
, XINT (v1
) + 1);
1331 BEFORE_POTENTIAL_GC ();
1333 AFTER_POTENTIAL_GC ();
1341 BEFORE_POTENTIAL_GC ();
1343 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
1344 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
1345 AFTER_POTENTIAL_GC ();
1346 if (FLOATP (v1
) || FLOATP (v2
))
1350 f1
= (FLOATP (v1
) ? XFLOAT_DATA (v1
) : XINT (v1
));
1351 f2
= (FLOATP (v2
) ? XFLOAT_DATA (v2
) : XINT (v2
));
1352 TOP
= (f1
== f2
? Qt
: Qnil
);
1355 TOP
= (XINT (v1
) == XINT (v2
) ? Qt
: Qnil
);
1362 BEFORE_POTENTIAL_GC ();
1364 TOP
= Fgtr (TOP
, v1
);
1365 AFTER_POTENTIAL_GC ();
1372 BEFORE_POTENTIAL_GC ();
1374 TOP
= Flss (TOP
, v1
);
1375 AFTER_POTENTIAL_GC ();
1382 BEFORE_POTENTIAL_GC ();
1384 TOP
= Fleq (TOP
, v1
);
1385 AFTER_POTENTIAL_GC ();
1392 BEFORE_POTENTIAL_GC ();
1394 TOP
= Fgeq (TOP
, v1
);
1395 AFTER_POTENTIAL_GC ();
1400 BEFORE_POTENTIAL_GC ();
1402 TOP
= Fminus (2, &TOP
);
1403 AFTER_POTENTIAL_GC ();
1412 XSETINT (v1
, - XINT (v1
));
1417 BEFORE_POTENTIAL_GC ();
1418 TOP
= Fminus (1, &TOP
);
1419 AFTER_POTENTIAL_GC ();
1425 BEFORE_POTENTIAL_GC ();
1427 TOP
= Fplus (2, &TOP
);
1428 AFTER_POTENTIAL_GC ();
1432 BEFORE_POTENTIAL_GC ();
1434 TOP
= Fmax (2, &TOP
);
1435 AFTER_POTENTIAL_GC ();
1439 BEFORE_POTENTIAL_GC ();
1441 TOP
= Fmin (2, &TOP
);
1442 AFTER_POTENTIAL_GC ();
1446 BEFORE_POTENTIAL_GC ();
1448 TOP
= Ftimes (2, &TOP
);
1449 AFTER_POTENTIAL_GC ();
1453 BEFORE_POTENTIAL_GC ();
1455 TOP
= Fquo (2, &TOP
);
1456 AFTER_POTENTIAL_GC ();
1462 BEFORE_POTENTIAL_GC ();
1464 TOP
= Frem (TOP
, v1
);
1465 AFTER_POTENTIAL_GC ();
1472 XSETFASTINT (v1
, PT
);
1478 BEFORE_POTENTIAL_GC ();
1479 TOP
= Fgoto_char (TOP
);
1480 AFTER_POTENTIAL_GC ();
1484 BEFORE_POTENTIAL_GC ();
1485 TOP
= Finsert (1, &TOP
);
1486 AFTER_POTENTIAL_GC ();
1491 BEFORE_POTENTIAL_GC ();
1493 TOP
= Finsert (op
, &TOP
);
1494 AFTER_POTENTIAL_GC ();
1500 XSETFASTINT (v1
, ZV
);
1508 XSETFASTINT (v1
, BEGV
);
1514 BEFORE_POTENTIAL_GC ();
1515 TOP
= Fchar_after (TOP
);
1516 AFTER_POTENTIAL_GC ();
1519 CASE (Bfollowing_char
):
1522 BEFORE_POTENTIAL_GC ();
1523 v1
= Ffollowing_char ();
1524 AFTER_POTENTIAL_GC ();
1529 CASE (Bpreceding_char
):
1532 BEFORE_POTENTIAL_GC ();
1533 v1
= Fprevious_char ();
1534 AFTER_POTENTIAL_GC ();
1539 CASE (Bcurrent_column
):
1542 BEFORE_POTENTIAL_GC ();
1543 XSETFASTINT (v1
, current_column ());
1544 AFTER_POTENTIAL_GC ();
1550 BEFORE_POTENTIAL_GC ();
1551 TOP
= Findent_to (TOP
, Qnil
);
1552 AFTER_POTENTIAL_GC ();
1571 CASE (Bcurrent_buffer
):
1572 PUSH (Fcurrent_buffer ());
1576 BEFORE_POTENTIAL_GC ();
1577 TOP
= Fset_buffer (TOP
);
1578 AFTER_POTENTIAL_GC ();
1581 CASE (Binteractive_p
): /* Obsolete since 24.1. */
1582 PUSH (Finteractive_p ());
1585 CASE (Bforward_char
):
1586 BEFORE_POTENTIAL_GC ();
1587 TOP
= Fforward_char (TOP
);
1588 AFTER_POTENTIAL_GC ();
1591 CASE (Bforward_word
):
1592 BEFORE_POTENTIAL_GC ();
1593 TOP
= Fforward_word (TOP
);
1594 AFTER_POTENTIAL_GC ();
1597 CASE (Bskip_chars_forward
):
1600 BEFORE_POTENTIAL_GC ();
1602 TOP
= Fskip_chars_forward (TOP
, v1
);
1603 AFTER_POTENTIAL_GC ();
1607 CASE (Bskip_chars_backward
):
1610 BEFORE_POTENTIAL_GC ();
1612 TOP
= Fskip_chars_backward (TOP
, v1
);
1613 AFTER_POTENTIAL_GC ();
1617 CASE (Bforward_line
):
1618 BEFORE_POTENTIAL_GC ();
1619 TOP
= Fforward_line (TOP
);
1620 AFTER_POTENTIAL_GC ();
1623 CASE (Bchar_syntax
):
1627 BEFORE_POTENTIAL_GC ();
1628 CHECK_CHARACTER (TOP
);
1629 AFTER_POTENTIAL_GC ();
1631 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
1632 MAKE_CHAR_MULTIBYTE (c
);
1633 XSETFASTINT (TOP
, syntax_code_spec
[(int) SYNTAX (c
)]);
1637 CASE (Bbuffer_substring
):
1640 BEFORE_POTENTIAL_GC ();
1642 TOP
= Fbuffer_substring (TOP
, v1
);
1643 AFTER_POTENTIAL_GC ();
1647 CASE (Bdelete_region
):
1650 BEFORE_POTENTIAL_GC ();
1652 TOP
= Fdelete_region (TOP
, v1
);
1653 AFTER_POTENTIAL_GC ();
1657 CASE (Bnarrow_to_region
):
1660 BEFORE_POTENTIAL_GC ();
1662 TOP
= Fnarrow_to_region (TOP
, v1
);
1663 AFTER_POTENTIAL_GC ();
1668 BEFORE_POTENTIAL_GC ();
1670 AFTER_POTENTIAL_GC ();
1673 CASE (Bend_of_line
):
1674 BEFORE_POTENTIAL_GC ();
1675 TOP
= Fend_of_line (TOP
);
1676 AFTER_POTENTIAL_GC ();
1682 BEFORE_POTENTIAL_GC ();
1685 TOP
= Fset_marker (TOP
, v2
, v1
);
1686 AFTER_POTENTIAL_GC ();
1690 CASE (Bmatch_beginning
):
1691 BEFORE_POTENTIAL_GC ();
1692 TOP
= Fmatch_beginning (TOP
);
1693 AFTER_POTENTIAL_GC ();
1697 BEFORE_POTENTIAL_GC ();
1698 TOP
= Fmatch_end (TOP
);
1699 AFTER_POTENTIAL_GC ();
1703 BEFORE_POTENTIAL_GC ();
1704 TOP
= Fupcase (TOP
);
1705 AFTER_POTENTIAL_GC ();
1709 BEFORE_POTENTIAL_GC ();
1710 TOP
= Fdowncase (TOP
);
1711 AFTER_POTENTIAL_GC ();
1714 CASE (Bstringeqlsign
):
1717 BEFORE_POTENTIAL_GC ();
1719 TOP
= Fstring_equal (TOP
, v1
);
1720 AFTER_POTENTIAL_GC ();
1727 BEFORE_POTENTIAL_GC ();
1729 TOP
= Fstring_lessp (TOP
, v1
);
1730 AFTER_POTENTIAL_GC ();
1738 TOP
= Fequal (TOP
, v1
);
1745 BEFORE_POTENTIAL_GC ();
1747 TOP
= Fnthcdr (TOP
, v1
);
1748 AFTER_POTENTIAL_GC ();
1757 /* Exchange args and then do nth. */
1759 BEFORE_POTENTIAL_GC ();
1763 AFTER_POTENTIAL_GC ();
1766 while (--n
>= 0 && CONSP (v1
))
1773 BEFORE_POTENTIAL_GC ();
1775 TOP
= Felt (TOP
, v1
);
1776 AFTER_POTENTIAL_GC ();
1784 BEFORE_POTENTIAL_GC ();
1786 TOP
= Fmember (TOP
, v1
);
1787 AFTER_POTENTIAL_GC ();
1794 BEFORE_POTENTIAL_GC ();
1796 TOP
= Fassq (TOP
, v1
);
1797 AFTER_POTENTIAL_GC ();
1802 BEFORE_POTENTIAL_GC ();
1803 TOP
= Fnreverse (TOP
);
1804 AFTER_POTENTIAL_GC ();
1810 BEFORE_POTENTIAL_GC ();
1812 TOP
= Fsetcar (TOP
, v1
);
1813 AFTER_POTENTIAL_GC ();
1820 BEFORE_POTENTIAL_GC ();
1822 TOP
= Fsetcdr (TOP
, v1
);
1823 AFTER_POTENTIAL_GC ();
1831 TOP
= CAR_SAFE (v1
);
1839 TOP
= CDR_SAFE (v1
);
1844 BEFORE_POTENTIAL_GC ();
1846 TOP
= Fnconc (2, &TOP
);
1847 AFTER_POTENTIAL_GC ();
1851 TOP
= (NUMBERP (TOP
) ? Qt
: Qnil
);
1855 TOP
= INTEGERP (TOP
) ? Qt
: Qnil
;
1858 #ifdef BYTE_CODE_SAFE
1859 /* These are intentionally written using 'case' syntax,
1860 because they are incompatible with the threaded
1864 BEFORE_POTENTIAL_GC ();
1865 error ("set-mark is an obsolete bytecode");
1866 AFTER_POTENTIAL_GC ();
1869 BEFORE_POTENTIAL_GC ();
1870 error ("scan-buffer is an obsolete bytecode");
1871 AFTER_POTENTIAL_GC ();
1876 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1877 for that instead. */
1878 /* CASE (Bstack_ref): */
1879 error ("Invalid byte opcode");
1881 /* Handy byte-codes for lexical binding. */
1888 Lisp_Object
*ptr
= top
- (op
- Bstack_ref
);
1894 Lisp_Object
*ptr
= top
- (FETCH
);
1900 Lisp_Object
*ptr
= top
- (FETCH2
);
1905 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1907 Lisp_Object
*ptr
= top
- (FETCH
);
1913 Lisp_Object
*ptr
= top
- (FETCH2
);
1929 #ifdef BYTE_CODE_SAFE
1934 if ((op
-= Bconstant
) >= const_length
)
1940 PUSH (vectorp
[op
- Bconstant
]);
1948 byte_stack_list
= byte_stack_list
->next
;
1950 /* Binds and unbinds are supposed to be compiled balanced. */
1951 if (SPECPDL_INDEX () != count
)
1952 #ifdef BYTE_CODE_SAFE
1953 error ("binding stack not balanced (serious byte compiler bug)");
1962 syms_of_bytecode (void)
1964 DEFSYM (Qbytecode
, "byte-code");
1966 defsubr (&Sbyte_code
);
1968 #ifdef BYTE_CODE_METER
1970 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter
,
1971 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
1972 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1973 opcode CODE has been executed.
1974 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1975 indicates how many times the byte opcodes CODE1 and CODE2 have been
1976 executed in succession. */);
1978 DEFVAR_BOOL ("byte-metering-on", byte_metering_on
,
1979 doc
: /* If non-nil, keep profiling information on byte code usage.
1980 The variable byte-code-meter indicates how often each byte opcode is used.
1981 If a symbol has a property named `byte-code-meter' whose value is an
1982 integer, it is incremented each time that symbol's function is called. */);
1984 byte_metering_on
= 0;
1985 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
1986 DEFSYM (Qbyte_code_meter
, "byte-code-meter");
1990 ASET (Vbyte_code_meter
, i
,
1991 Fmake_vector (make_number (256), make_number (0)));