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 if (consing_since_gc > gc_cons_threshold \
429 && consing_since_gc > gc_relative_threshold) \
431 BEFORE_POTENTIAL_GC (); \
432 Fgarbage_collect (); \
433 AFTER_POTENTIAL_GC (); \
437 /* Check for jumping out of range. */
439 #ifdef BYTE_CODE_SAFE
441 #define CHECK_RANGE(ARG) \
442 if (ARG >= bytestr_length) abort ()
444 #else /* not BYTE_CODE_SAFE */
446 #define CHECK_RANGE(ARG)
448 #endif /* not BYTE_CODE_SAFE */
450 /* A version of the QUIT macro which makes sure that the stack top is
451 set before signaling `quit'. */
453 #define BYTE_CODE_QUIT \
455 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
457 Lisp_Object flag = Vquit_flag; \
459 BEFORE_POTENTIAL_GC (); \
460 if (EQ (Vthrow_on_input, flag)) \
461 Fthrow (Vthrow_on_input, Qt); \
462 Fsignal (Qquit, Qnil); \
463 AFTER_POTENTIAL_GC (); \
465 ELSE_PENDING_SIGNALS \
469 DEFUN ("byte-code", Fbyte_code
, Sbyte_code
, 3, 3, 0,
470 doc
: /* Function used internally in byte-compiled code.
471 The first argument, BYTESTR, is a string of byte code;
472 the second, VECTOR, a vector of constants;
473 the third, MAXDEPTH, the maximum stack depth used in this function.
474 If the third argument is incorrect, Emacs may crash. */)
475 (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
)
477 return exec_byte_code (bytestr
, vector
, maxdepth
, Qnil
, 0, NULL
);
480 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
481 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
482 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
483 argument list (including &rest, &optional, etc.), and ARGS, of size
484 NARGS, should be a vector of the actual arguments. The arguments in
485 ARGS are pushed on the stack according to ARGS_TEMPLATE before
486 executing BYTESTR. */
489 exec_byte_code (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
,
490 Lisp_Object args_template
, ptrdiff_t nargs
, Lisp_Object
*args
)
492 ptrdiff_t count
= SPECPDL_INDEX ();
493 #ifdef BYTE_CODE_METER
498 /* Lisp_Object v1, v2; */
499 Lisp_Object
*vectorp
;
500 #ifdef BYTE_CODE_SAFE
501 ptrdiff_t const_length
;
503 ptrdiff_t bytestr_length
;
505 struct byte_stack stack
;
509 #if 0 /* CHECK_FRAME_FONT */
511 struct frame
*f
= SELECTED_FRAME ();
513 && FRAME_FONT (f
)->direction
!= 0
514 && FRAME_FONT (f
)->direction
!= 1)
519 CHECK_STRING (bytestr
);
520 CHECK_VECTOR (vector
);
521 CHECK_NATNUM (maxdepth
);
523 #ifdef BYTE_CODE_SAFE
524 const_length
= ASIZE (vector
);
527 if (STRING_MULTIBYTE (bytestr
))
528 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
529 because they produced a raw 8-bit string for byte-code and now
530 such a byte-code string is loaded as multibyte while raw 8-bit
531 characters converted to multibyte form. Thus, now we must
532 convert them back to the originally intended unibyte form. */
533 bytestr
= Fstring_as_unibyte (bytestr
);
535 #ifdef BYTE_CODE_SAFE
536 bytestr_length
= SBYTES (bytestr
);
538 vectorp
= XVECTOR (vector
)->contents
;
540 stack
.byte_string
= bytestr
;
541 stack
.pc
= stack
.byte_string_start
= SDATA (bytestr
);
542 stack
.constants
= vector
;
543 if (MAX_ALLOCA
/ sizeof (Lisp_Object
) <= XFASTINT (maxdepth
))
544 memory_full (SIZE_MAX
);
545 top
= alloca ((XFASTINT (maxdepth
) + 1) * sizeof *top
);
546 #if BYTE_MAINTAIN_TOP
547 stack
.bottom
= top
+ 1;
550 stack
.next
= byte_stack_list
;
551 byte_stack_list
= &stack
;
553 #ifdef BYTE_CODE_SAFE
554 stacke
= stack
.bottom
- 1 + XFASTINT (maxdepth
);
557 if (INTEGERP (args_template
))
559 ptrdiff_t at
= XINT (args_template
);
561 int mandatory
= at
& 127;
562 ptrdiff_t nonrest
= at
>> 8;
563 eassert (mandatory
<= nonrest
);
564 if (nargs
<= nonrest
)
567 for (i
= 0 ; i
< nargs
; i
++, args
++)
569 if (nargs
< mandatory
)
570 /* Too few arguments. */
571 Fsignal (Qwrong_number_of_arguments
,
572 Fcons (Fcons (make_number (mandatory
),
573 rest
? Qand_rest
: make_number (nonrest
)),
574 Fcons (make_number (nargs
), Qnil
)));
577 for (; i
< nonrest
; i
++)
586 for (i
= 0 ; i
< nonrest
; i
++, args
++)
588 PUSH (Flist (nargs
- nonrest
, args
));
591 /* Too many arguments. */
592 Fsignal (Qwrong_number_of_arguments
,
593 Fcons (Fcons (make_number (mandatory
),
594 make_number (nonrest
)),
595 Fcons (make_number (nargs
), Qnil
)));
597 else if (! NILP (args_template
))
598 /* We should push some arguments on the stack. */
600 error ("Unknown args template!");
605 #ifdef BYTE_CODE_SAFE
608 else if (top
< stack
.bottom
- 1)
612 #ifdef BYTE_CODE_METER
614 this_op
= op
= FETCH
;
615 METER_CODE (prev_op
, op
);
617 #ifndef BYTE_CODE_THREADED
622 /* The interpreter can be compiled one of two ways: as an
623 ordinary switch-based interpreter, or as a threaded
624 interpreter. The threaded interpreter relies on GCC's
625 computed goto extension, so it is not available everywhere.
626 Threading provides a performance boost. These macros are how
627 we allow the code to be compiled both ways. */
628 #ifdef BYTE_CODE_THREADED
629 /* The CASE macro introduces an instruction's body. It is
630 either a label or a case label. */
631 #define CASE(OP) insn_ ## OP
632 /* NEXT is invoked at the end of an instruction to go to the
633 next instruction. It is either a computed goto, or a
635 #define NEXT goto *(targets[op = FETCH])
636 /* FIRST is like NEXT, but is only used at the start of the
637 interpreter body. In the switch-based interpreter it is the
638 switch, so the threaded definition must include a semicolon. */
640 /* Most cases are labeled with the CASE macro, above.
641 CASE_DEFAULT is one exception; it is used if the interpreter
642 being built requires a default case. The threaded
643 interpreter does not, because the dispatch table is
644 completely filled. */
646 /* This introduces an instruction that is known to call abort. */
647 #define CASE_ABORT CASE (Bstack_ref): CASE (default)
649 /* See above for the meaning of the various defines. */
650 #define CASE(OP) case OP
652 #define FIRST switch (op)
653 #define CASE_DEFAULT case 255: default:
654 #define CASE_ABORT case 0
657 #ifdef BYTE_CODE_THREADED
659 /* A convenience define that saves us a lot of typing and makes
660 the table clearer. */
661 #define LABEL(OP) [OP] = &&insn_ ## OP
663 #if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
664 # pragma GCC diagnostic push
665 # pragma GCC diagnostic ignored "-Woverride-init"
668 /* This is the dispatch table for the threaded interpreter. */
669 static const void *const targets
[256] =
671 [0 ... (Bconstant
- 1)] = &&insn_default
,
672 [Bconstant
... 255] = &&insn_Bconstant
,
674 #define DEFINE(name, value) LABEL (name) ,
679 #if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
680 # pragma GCC diagnostic pop
701 /* This seems to be the most frequently executed byte-code
702 among the Bvarref's, so avoid a goto here. */
712 if (XSYMBOL (v1
)->redirect
!= SYMBOL_PLAINVAL
713 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)),
716 BEFORE_POTENTIAL_GC ();
717 v2
= Fsymbol_value (v1
);
718 AFTER_POTENTIAL_GC ();
723 BEFORE_POTENTIAL_GC ();
724 v2
= Fsymbol_value (v1
);
725 AFTER_POTENTIAL_GC ();
741 stack
.pc
= stack
.byte_string_start
+ op
;
756 BEFORE_POTENTIAL_GC ();
757 wrong_type_argument (Qlistp
, v1
);
758 AFTER_POTENTIAL_GC ();
767 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
774 BEFORE_POTENTIAL_GC ();
776 TOP
= Fmemq (TOP
, v1
);
777 AFTER_POTENTIAL_GC ();
791 BEFORE_POTENTIAL_GC ();
792 wrong_type_argument (Qlistp
, v1
);
793 AFTER_POTENTIAL_GC ();
815 Lisp_Object sym
, val
;
820 /* Inline the most common case. */
822 && !EQ (val
, Qunbound
)
823 && !XSYMBOL (sym
)->redirect
824 && !SYMBOL_CONSTANT_P (sym
))
825 XSYMBOL (sym
)->val
.value
= val
;
828 BEFORE_POTENTIAL_GC ();
829 set_internal (sym
, val
, Qnil
, 0);
830 AFTER_POTENTIAL_GC ();
844 /* ------------------ */
862 /* Specbind can signal and thus GC. */
863 BEFORE_POTENTIAL_GC ();
864 specbind (vectorp
[op
], POP
);
865 AFTER_POTENTIAL_GC ();
885 BEFORE_POTENTIAL_GC ();
887 #ifdef BYTE_CODE_METER
888 if (byte_metering_on
&& SYMBOLP (TOP
))
893 v2
= Fget (v1
, Qbyte_code_meter
);
895 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
897 XSETINT (v2
, XINT (v2
) + 1);
898 Fput (v1
, Qbyte_code_meter
, v2
);
902 TOP
= Ffuncall (op
+ 1, &TOP
);
903 AFTER_POTENTIAL_GC ();
923 BEFORE_POTENTIAL_GC ();
924 unbind_to (SPECPDL_INDEX () - op
, Qnil
);
925 AFTER_POTENTIAL_GC ();
928 CASE (Bunbind_all
): /* Obsolete. Never used. */
929 /* To unbind back to the beginning of this frame. Not used yet,
930 but will be needed for tail-recursion elimination. */
931 BEFORE_POTENTIAL_GC ();
932 unbind_to (count
, Qnil
);
933 AFTER_POTENTIAL_GC ();
939 op
= FETCH2
; /* pc = FETCH2 loses since FETCH2 contains pc++ */
941 stack
.pc
= stack
.byte_string_start
+ op
;
944 CASE (Bgotoifnonnil
):
954 stack
.pc
= stack
.byte_string_start
+ op
;
959 CASE (Bgotoifnilelsepop
):
966 stack
.pc
= stack
.byte_string_start
+ op
;
971 CASE (Bgotoifnonnilelsepop
):
978 stack
.pc
= stack
.byte_string_start
+ op
;
986 stack
.pc
+= (int) *stack
.pc
- 127;
997 stack
.pc
+= (int) *stack
.pc
- 128;
1003 CASE (BRgotoifnonnil
):
1011 stack
.pc
+= (int) *stack
.pc
- 128;
1017 CASE (BRgotoifnilelsepop
):
1023 stack
.pc
+= op
- 128;
1028 CASE (BRgotoifnonnilelsepop
):
1034 stack
.pc
+= op
- 128;
1048 PUSH (vectorp
[FETCH2
]);
1051 CASE (Bsave_excursion
):
1052 record_unwind_protect (save_excursion_restore
,
1053 save_excursion_save ());
1056 CASE (Bsave_current_buffer
): /* Obsolete since ??. */
1057 CASE (Bsave_current_buffer_1
):
1058 record_unwind_protect (set_buffer_if_live
, Fcurrent_buffer ());
1061 CASE (Bsave_window_excursion
): /* Obsolete since 24.1. */
1063 register ptrdiff_t count1
= SPECPDL_INDEX ();
1064 record_unwind_protect (Fset_window_configuration
,
1065 Fcurrent_window_configuration (Qnil
));
1066 BEFORE_POTENTIAL_GC ();
1068 unbind_to (count1
, TOP
);
1069 AFTER_POTENTIAL_GC ();
1073 CASE (Bsave_restriction
):
1074 record_unwind_protect (save_restriction_restore
,
1075 save_restriction_save ());
1078 CASE (Bcatch
): /* FIXME: ill-suited for lexbind. */
1081 BEFORE_POTENTIAL_GC ();
1083 TOP
= internal_catch (TOP
, eval_sub
, v1
);
1084 AFTER_POTENTIAL_GC ();
1088 CASE (Bunwind_protect
): /* FIXME: avoid closure for lexbind. */
1089 record_unwind_protect (Fprogn
, POP
);
1092 CASE (Bcondition_case
): /* FIXME: ill-suited for lexbind. */
1094 Lisp_Object handlers
, body
;
1097 BEFORE_POTENTIAL_GC ();
1098 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
);
1099 AFTER_POTENTIAL_GC ();
1103 CASE (Btemp_output_buffer_setup
): /* Obsolete since 24.1. */
1104 BEFORE_POTENTIAL_GC ();
1106 temp_output_buffer_setup (SSDATA (TOP
));
1107 AFTER_POTENTIAL_GC ();
1108 TOP
= Vstandard_output
;
1111 CASE (Btemp_output_buffer_show
): /* Obsolete since 24.1. */
1114 BEFORE_POTENTIAL_GC ();
1116 temp_output_buffer_show (TOP
);
1118 /* pop binding of standard-output */
1119 unbind_to (SPECPDL_INDEX () - 1, Qnil
);
1120 AFTER_POTENTIAL_GC ();
1128 BEFORE_POTENTIAL_GC ();
1134 while (--n
>= 0 && CONSP (v1
))
1138 AFTER_POTENTIAL_GC ();
1143 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
1147 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
1151 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
1155 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
1159 TOP
= NILP (TOP
) ? Qt
: Qnil
;
1166 TOP
= Fcons (TOP
, v1
);
1171 TOP
= Fcons (TOP
, Qnil
);
1178 TOP
= Fcons (TOP
, Fcons (v1
, Qnil
));
1184 TOP
= Flist (3, &TOP
);
1189 TOP
= Flist (4, &TOP
);
1195 TOP
= Flist (op
, &TOP
);
1199 BEFORE_POTENTIAL_GC ();
1200 TOP
= Flength (TOP
);
1201 AFTER_POTENTIAL_GC ();
1207 BEFORE_POTENTIAL_GC ();
1209 TOP
= Faref (TOP
, v1
);
1210 AFTER_POTENTIAL_GC ();
1217 BEFORE_POTENTIAL_GC ();
1219 TOP
= Faset (TOP
, v1
, v2
);
1220 AFTER_POTENTIAL_GC ();
1224 CASE (Bsymbol_value
):
1225 BEFORE_POTENTIAL_GC ();
1226 TOP
= Fsymbol_value (TOP
);
1227 AFTER_POTENTIAL_GC ();
1230 CASE (Bsymbol_function
):
1231 BEFORE_POTENTIAL_GC ();
1232 TOP
= Fsymbol_function (TOP
);
1233 AFTER_POTENTIAL_GC ();
1239 BEFORE_POTENTIAL_GC ();
1241 TOP
= Fset (TOP
, v1
);
1242 AFTER_POTENTIAL_GC ();
1249 BEFORE_POTENTIAL_GC ();
1251 TOP
= Ffset (TOP
, v1
);
1252 AFTER_POTENTIAL_GC ();
1259 BEFORE_POTENTIAL_GC ();
1261 TOP
= Fget (TOP
, v1
);
1262 AFTER_POTENTIAL_GC ();
1269 BEFORE_POTENTIAL_GC ();
1271 TOP
= Fsubstring (TOP
, v1
, v2
);
1272 AFTER_POTENTIAL_GC ();
1277 BEFORE_POTENTIAL_GC ();
1279 TOP
= Fconcat (2, &TOP
);
1280 AFTER_POTENTIAL_GC ();
1284 BEFORE_POTENTIAL_GC ();
1286 TOP
= Fconcat (3, &TOP
);
1287 AFTER_POTENTIAL_GC ();
1291 BEFORE_POTENTIAL_GC ();
1293 TOP
= Fconcat (4, &TOP
);
1294 AFTER_POTENTIAL_GC ();
1299 BEFORE_POTENTIAL_GC ();
1301 TOP
= Fconcat (op
, &TOP
);
1302 AFTER_POTENTIAL_GC ();
1311 XSETINT (v1
, XINT (v1
) - 1);
1316 BEFORE_POTENTIAL_GC ();
1318 AFTER_POTENTIAL_GC ();
1329 XSETINT (v1
, XINT (v1
) + 1);
1334 BEFORE_POTENTIAL_GC ();
1336 AFTER_POTENTIAL_GC ();
1344 BEFORE_POTENTIAL_GC ();
1346 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
1347 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
1348 AFTER_POTENTIAL_GC ();
1349 if (FLOATP (v1
) || FLOATP (v2
))
1353 f1
= (FLOATP (v1
) ? XFLOAT_DATA (v1
) : XINT (v1
));
1354 f2
= (FLOATP (v2
) ? XFLOAT_DATA (v2
) : XINT (v2
));
1355 TOP
= (f1
== f2
? Qt
: Qnil
);
1358 TOP
= (XINT (v1
) == XINT (v2
) ? Qt
: Qnil
);
1365 BEFORE_POTENTIAL_GC ();
1367 TOP
= Fgtr (TOP
, v1
);
1368 AFTER_POTENTIAL_GC ();
1375 BEFORE_POTENTIAL_GC ();
1377 TOP
= Flss (TOP
, v1
);
1378 AFTER_POTENTIAL_GC ();
1385 BEFORE_POTENTIAL_GC ();
1387 TOP
= Fleq (TOP
, v1
);
1388 AFTER_POTENTIAL_GC ();
1395 BEFORE_POTENTIAL_GC ();
1397 TOP
= Fgeq (TOP
, v1
);
1398 AFTER_POTENTIAL_GC ();
1403 BEFORE_POTENTIAL_GC ();
1405 TOP
= Fminus (2, &TOP
);
1406 AFTER_POTENTIAL_GC ();
1415 XSETINT (v1
, - XINT (v1
));
1420 BEFORE_POTENTIAL_GC ();
1421 TOP
= Fminus (1, &TOP
);
1422 AFTER_POTENTIAL_GC ();
1428 BEFORE_POTENTIAL_GC ();
1430 TOP
= Fplus (2, &TOP
);
1431 AFTER_POTENTIAL_GC ();
1435 BEFORE_POTENTIAL_GC ();
1437 TOP
= Fmax (2, &TOP
);
1438 AFTER_POTENTIAL_GC ();
1442 BEFORE_POTENTIAL_GC ();
1444 TOP
= Fmin (2, &TOP
);
1445 AFTER_POTENTIAL_GC ();
1449 BEFORE_POTENTIAL_GC ();
1451 TOP
= Ftimes (2, &TOP
);
1452 AFTER_POTENTIAL_GC ();
1456 BEFORE_POTENTIAL_GC ();
1458 TOP
= Fquo (2, &TOP
);
1459 AFTER_POTENTIAL_GC ();
1465 BEFORE_POTENTIAL_GC ();
1467 TOP
= Frem (TOP
, v1
);
1468 AFTER_POTENTIAL_GC ();
1475 XSETFASTINT (v1
, PT
);
1481 BEFORE_POTENTIAL_GC ();
1482 TOP
= Fgoto_char (TOP
);
1483 AFTER_POTENTIAL_GC ();
1487 BEFORE_POTENTIAL_GC ();
1488 TOP
= Finsert (1, &TOP
);
1489 AFTER_POTENTIAL_GC ();
1494 BEFORE_POTENTIAL_GC ();
1496 TOP
= Finsert (op
, &TOP
);
1497 AFTER_POTENTIAL_GC ();
1503 XSETFASTINT (v1
, ZV
);
1511 XSETFASTINT (v1
, BEGV
);
1517 BEFORE_POTENTIAL_GC ();
1518 TOP
= Fchar_after (TOP
);
1519 AFTER_POTENTIAL_GC ();
1522 CASE (Bfollowing_char
):
1525 BEFORE_POTENTIAL_GC ();
1526 v1
= Ffollowing_char ();
1527 AFTER_POTENTIAL_GC ();
1532 CASE (Bpreceding_char
):
1535 BEFORE_POTENTIAL_GC ();
1536 v1
= Fprevious_char ();
1537 AFTER_POTENTIAL_GC ();
1542 CASE (Bcurrent_column
):
1545 BEFORE_POTENTIAL_GC ();
1546 XSETFASTINT (v1
, current_column ());
1547 AFTER_POTENTIAL_GC ();
1553 BEFORE_POTENTIAL_GC ();
1554 TOP
= Findent_to (TOP
, Qnil
);
1555 AFTER_POTENTIAL_GC ();
1574 CASE (Bcurrent_buffer
):
1575 PUSH (Fcurrent_buffer ());
1579 BEFORE_POTENTIAL_GC ();
1580 TOP
= Fset_buffer (TOP
);
1581 AFTER_POTENTIAL_GC ();
1584 CASE (Binteractive_p
): /* Obsolete since 24.1. */
1585 PUSH (Finteractive_p ());
1588 CASE (Bforward_char
):
1589 BEFORE_POTENTIAL_GC ();
1590 TOP
= Fforward_char (TOP
);
1591 AFTER_POTENTIAL_GC ();
1594 CASE (Bforward_word
):
1595 BEFORE_POTENTIAL_GC ();
1596 TOP
= Fforward_word (TOP
);
1597 AFTER_POTENTIAL_GC ();
1600 CASE (Bskip_chars_forward
):
1603 BEFORE_POTENTIAL_GC ();
1605 TOP
= Fskip_chars_forward (TOP
, v1
);
1606 AFTER_POTENTIAL_GC ();
1610 CASE (Bskip_chars_backward
):
1613 BEFORE_POTENTIAL_GC ();
1615 TOP
= Fskip_chars_backward (TOP
, v1
);
1616 AFTER_POTENTIAL_GC ();
1620 CASE (Bforward_line
):
1621 BEFORE_POTENTIAL_GC ();
1622 TOP
= Fforward_line (TOP
);
1623 AFTER_POTENTIAL_GC ();
1626 CASE (Bchar_syntax
):
1630 BEFORE_POTENTIAL_GC ();
1631 CHECK_CHARACTER (TOP
);
1632 AFTER_POTENTIAL_GC ();
1634 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
1635 MAKE_CHAR_MULTIBYTE (c
);
1636 XSETFASTINT (TOP
, syntax_code_spec
[(int) SYNTAX (c
)]);
1640 CASE (Bbuffer_substring
):
1643 BEFORE_POTENTIAL_GC ();
1645 TOP
= Fbuffer_substring (TOP
, v1
);
1646 AFTER_POTENTIAL_GC ();
1650 CASE (Bdelete_region
):
1653 BEFORE_POTENTIAL_GC ();
1655 TOP
= Fdelete_region (TOP
, v1
);
1656 AFTER_POTENTIAL_GC ();
1660 CASE (Bnarrow_to_region
):
1663 BEFORE_POTENTIAL_GC ();
1665 TOP
= Fnarrow_to_region (TOP
, v1
);
1666 AFTER_POTENTIAL_GC ();
1671 BEFORE_POTENTIAL_GC ();
1673 AFTER_POTENTIAL_GC ();
1676 CASE (Bend_of_line
):
1677 BEFORE_POTENTIAL_GC ();
1678 TOP
= Fend_of_line (TOP
);
1679 AFTER_POTENTIAL_GC ();
1685 BEFORE_POTENTIAL_GC ();
1688 TOP
= Fset_marker (TOP
, v2
, v1
);
1689 AFTER_POTENTIAL_GC ();
1693 CASE (Bmatch_beginning
):
1694 BEFORE_POTENTIAL_GC ();
1695 TOP
= Fmatch_beginning (TOP
);
1696 AFTER_POTENTIAL_GC ();
1700 BEFORE_POTENTIAL_GC ();
1701 TOP
= Fmatch_end (TOP
);
1702 AFTER_POTENTIAL_GC ();
1706 BEFORE_POTENTIAL_GC ();
1707 TOP
= Fupcase (TOP
);
1708 AFTER_POTENTIAL_GC ();
1712 BEFORE_POTENTIAL_GC ();
1713 TOP
= Fdowncase (TOP
);
1714 AFTER_POTENTIAL_GC ();
1717 CASE (Bstringeqlsign
):
1720 BEFORE_POTENTIAL_GC ();
1722 TOP
= Fstring_equal (TOP
, v1
);
1723 AFTER_POTENTIAL_GC ();
1730 BEFORE_POTENTIAL_GC ();
1732 TOP
= Fstring_lessp (TOP
, v1
);
1733 AFTER_POTENTIAL_GC ();
1741 TOP
= Fequal (TOP
, v1
);
1748 BEFORE_POTENTIAL_GC ();
1750 TOP
= Fnthcdr (TOP
, v1
);
1751 AFTER_POTENTIAL_GC ();
1760 /* Exchange args and then do nth. */
1762 BEFORE_POTENTIAL_GC ();
1766 AFTER_POTENTIAL_GC ();
1769 while (--n
>= 0 && CONSP (v1
))
1776 BEFORE_POTENTIAL_GC ();
1778 TOP
= Felt (TOP
, v1
);
1779 AFTER_POTENTIAL_GC ();
1787 BEFORE_POTENTIAL_GC ();
1789 TOP
= Fmember (TOP
, v1
);
1790 AFTER_POTENTIAL_GC ();
1797 BEFORE_POTENTIAL_GC ();
1799 TOP
= Fassq (TOP
, v1
);
1800 AFTER_POTENTIAL_GC ();
1805 BEFORE_POTENTIAL_GC ();
1806 TOP
= Fnreverse (TOP
);
1807 AFTER_POTENTIAL_GC ();
1813 BEFORE_POTENTIAL_GC ();
1815 TOP
= Fsetcar (TOP
, v1
);
1816 AFTER_POTENTIAL_GC ();
1823 BEFORE_POTENTIAL_GC ();
1825 TOP
= Fsetcdr (TOP
, v1
);
1826 AFTER_POTENTIAL_GC ();
1834 TOP
= CAR_SAFE (v1
);
1842 TOP
= CDR_SAFE (v1
);
1847 BEFORE_POTENTIAL_GC ();
1849 TOP
= Fnconc (2, &TOP
);
1850 AFTER_POTENTIAL_GC ();
1854 TOP
= (NUMBERP (TOP
) ? Qt
: Qnil
);
1858 TOP
= INTEGERP (TOP
) ? Qt
: Qnil
;
1861 #ifdef BYTE_CODE_SAFE
1862 /* These are intentionally written using 'case' syntax,
1863 because they are incompatible with the threaded
1867 BEFORE_POTENTIAL_GC ();
1868 error ("set-mark is an obsolete bytecode");
1869 AFTER_POTENTIAL_GC ();
1872 BEFORE_POTENTIAL_GC ();
1873 error ("scan-buffer is an obsolete bytecode");
1874 AFTER_POTENTIAL_GC ();
1879 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1880 for that instead. */
1881 /* CASE (Bstack_ref): */
1884 /* Handy byte-codes for lexical binding. */
1891 Lisp_Object
*ptr
= top
- (op
- Bstack_ref
);
1897 Lisp_Object
*ptr
= top
- (FETCH
);
1903 Lisp_Object
*ptr
= top
- (FETCH2
);
1908 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1910 Lisp_Object
*ptr
= top
- (FETCH
);
1916 Lisp_Object
*ptr
= top
- (FETCH2
);
1932 #ifdef BYTE_CODE_SAFE
1937 if ((op
-= Bconstant
) >= const_length
)
1943 PUSH (vectorp
[op
- Bconstant
]);
1951 byte_stack_list
= byte_stack_list
->next
;
1953 /* Binds and unbinds are supposed to be compiled balanced. */
1954 if (SPECPDL_INDEX () != count
)
1955 #ifdef BYTE_CODE_SAFE
1956 error ("binding stack not balanced (serious byte compiler bug)");
1965 syms_of_bytecode (void)
1967 DEFSYM (Qbytecode
, "byte-code");
1969 defsubr (&Sbyte_code
);
1971 #ifdef BYTE_CODE_METER
1973 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter
,
1974 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
1975 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1976 opcode CODE has been executed.
1977 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1978 indicates how many times the byte opcodes CODE1 and CODE2 have been
1979 executed in succession. */);
1981 DEFVAR_BOOL ("byte-metering-on", byte_metering_on
,
1982 doc
: /* If non-nil, keep profiling information on byte code usage.
1983 The variable byte-code-meter indicates how often each byte opcode is used.
1984 If a symbol has a property named `byte-code-meter' whose value is an
1985 integer, it is incremented each time that symbol's function is called. */);
1987 byte_metering_on
= 0;
1988 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
1989 DEFSYM (Qbyte_code_meter
, "byte-code-meter");
1993 ASET (Vbyte_code_meter
, i
,
1994 Fmake_vector (make_number (256), make_number (0)));