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 */
93 DEFINE (Bstack_ref, 0) /* Actually, Bstack_ref+0 is not implemented: use dup. */ \
94 DEFINE (Bstack_ref1, 1) \
95 DEFINE (Bstack_ref2, 2) \
96 DEFINE (Bstack_ref3, 3) \
97 DEFINE (Bstack_ref4, 4) \
98 DEFINE (Bstack_ref5, 5) \
99 DEFINE (Bstack_ref6, 6) \
100 DEFINE (Bstack_ref7, 7) \
101 DEFINE (Bvarref, 010) \
102 DEFINE (Bvarref1, 011) \
103 DEFINE (Bvarref2, 012) \
104 DEFINE (Bvarref3, 013) \
105 DEFINE (Bvarref4, 014) \
106 DEFINE (Bvarref5, 015) \
107 DEFINE (Bvarref6, 016) \
108 DEFINE (Bvarref7, 017) \
109 DEFINE (Bvarset, 020) \
110 DEFINE (Bvarset1, 021) \
111 DEFINE (Bvarset2, 022) \
112 DEFINE (Bvarset3, 023) \
113 DEFINE (Bvarset4, 024) \
114 DEFINE (Bvarset5, 025) \
115 DEFINE (Bvarset6, 026) \
116 DEFINE (Bvarset7, 027) \
117 DEFINE (Bvarbind, 030) \
118 DEFINE (Bvarbind1, 031) \
119 DEFINE (Bvarbind2, 032) \
120 DEFINE (Bvarbind3, 033) \
121 DEFINE (Bvarbind4, 034) \
122 DEFINE (Bvarbind5, 035) \
123 DEFINE (Bvarbind6, 036) \
124 DEFINE (Bvarbind7, 037) \
125 DEFINE (Bcall, 040) \
126 DEFINE (Bcall1, 041) \
127 DEFINE (Bcall2, 042) \
128 DEFINE (Bcall3, 043) \
129 DEFINE (Bcall4, 044) \
130 DEFINE (Bcall5, 045) \
131 DEFINE (Bcall6, 046) \
132 DEFINE (Bcall7, 047) \
133 DEFINE (Bunbind, 050) \
134 DEFINE (Bunbind1, 051) \
135 DEFINE (Bunbind2, 052) \
136 DEFINE (Bunbind3, 053) \
137 DEFINE (Bunbind4, 054) \
138 DEFINE (Bunbind5, 055) \
139 DEFINE (Bunbind6, 056) \
140 DEFINE (Bunbind7, 057) \
143 DEFINE (Bsymbolp, 071) \
144 DEFINE (Bconsp, 072) \
145 DEFINE (Bstringp, 073) \
146 DEFINE (Blistp, 074) \
148 DEFINE (Bmemq, 076) \
150 DEFINE (Bcar, 0100) \
151 DEFINE (Bcdr, 0101) \
152 DEFINE (Bcons, 0102) \
153 DEFINE (Blist1, 0103) \
154 DEFINE (Blist2, 0104) \
155 DEFINE (Blist3, 0105) \
156 DEFINE (Blist4, 0106) \
157 DEFINE (Blength, 0107) \
158 DEFINE (Baref, 0110) \
159 DEFINE (Baset, 0111) \
160 DEFINE (Bsymbol_value, 0112) \
161 DEFINE (Bsymbol_function, 0113) \
162 DEFINE (Bset, 0114) \
163 DEFINE (Bfset, 0115) \
164 DEFINE (Bget, 0116) \
165 DEFINE (Bsubstring, 0117) \
166 DEFINE (Bconcat2, 0120) \
167 DEFINE (Bconcat3, 0121) \
168 DEFINE (Bconcat4, 0122) \
169 DEFINE (Bsub1, 0123) \
170 DEFINE (Badd1, 0124) \
171 DEFINE (Beqlsign, 0125) \
172 DEFINE (Bgtr, 0126) \
173 DEFINE (Blss, 0127) \
174 DEFINE (Bleq, 0130) \
175 DEFINE (Bgeq, 0131) \
176 DEFINE (Bdiff, 0132) \
177 DEFINE (Bnegate, 0133) \
178 DEFINE (Bplus, 0134) \
179 DEFINE (Bmax, 0135) \
180 DEFINE (Bmin, 0136) \
181 DEFINE (Bmult, 0137) \
183 DEFINE (Bpoint, 0140) \
184 /* Was Bmark in v17. */ \
185 DEFINE (Bsave_current_buffer, 0141) /* Obsolete. */ \
186 DEFINE (Bgoto_char, 0142) \
187 DEFINE (Binsert, 0143) \
188 DEFINE (Bpoint_max, 0144) \
189 DEFINE (Bpoint_min, 0145) \
190 DEFINE (Bchar_after, 0146) \
191 DEFINE (Bfollowing_char, 0147) \
192 DEFINE (Bpreceding_char, 0150) \
193 DEFINE (Bcurrent_column, 0151) \
194 DEFINE (Bindent_to, 0152) \
195 DEFINE (Beolp, 0154) \
196 DEFINE (Beobp, 0155) \
197 DEFINE (Bbolp, 0156) \
198 DEFINE (Bbobp, 0157) \
199 DEFINE (Bcurrent_buffer, 0160) \
200 DEFINE (Bset_buffer, 0161) \
201 DEFINE (Bsave_current_buffer_1, 0162) /* Replacing Bsave_current_buffer. */ \
202 DEFINE (Binteractive_p, 0164) /* Obsolete since Emacs-24.1. */ \
204 DEFINE (Bforward_char, 0165) \
205 DEFINE (Bforward_word, 0166) \
206 DEFINE (Bskip_chars_forward, 0167) \
207 DEFINE (Bskip_chars_backward, 0170) \
208 DEFINE (Bforward_line, 0171) \
209 DEFINE (Bchar_syntax, 0172) \
210 DEFINE (Bbuffer_substring, 0173) \
211 DEFINE (Bdelete_region, 0174) \
212 DEFINE (Bnarrow_to_region, 0175) \
213 DEFINE (Bwiden, 0176) \
214 DEFINE (Bend_of_line, 0177) \
216 DEFINE (Bconstant2, 0201) \
217 DEFINE (Bgoto, 0202) \
218 DEFINE (Bgotoifnil, 0203) \
219 DEFINE (Bgotoifnonnil, 0204) \
220 DEFINE (Bgotoifnilelsepop, 0205) \
221 DEFINE (Bgotoifnonnilelsepop, 0206) \
222 DEFINE (Breturn, 0207) \
223 DEFINE (Bdiscard, 0210) \
224 DEFINE (Bdup, 0211) \
226 DEFINE (Bsave_excursion, 0212) \
227 DEFINE (Bsave_window_excursion, 0213) /* Obsolete since Emacs-24.1. */ \
228 DEFINE (Bsave_restriction, 0214) \
229 DEFINE (Bcatch, 0215) \
231 DEFINE (Bunwind_protect, 0216) \
232 DEFINE (Bcondition_case, 0217) \
233 DEFINE (Btemp_output_buffer_setup, 0220) /* Obsolete since Emacs-24.1. */ \
234 DEFINE (Btemp_output_buffer_show, 0221) /* Obsolete since Emacs-24.1. */ \
236 DEFINE (Bunbind_all, 0222) /* Obsolete. Never used. */ \
238 DEFINE (Bset_marker, 0223) \
239 DEFINE (Bmatch_beginning, 0224) \
240 DEFINE (Bmatch_end, 0225) \
241 DEFINE (Bupcase, 0226) \
242 DEFINE (Bdowncase, 0227) \
244 DEFINE (Bstringeqlsign, 0230) \
245 DEFINE (Bstringlss, 0231) \
246 DEFINE (Bequal, 0232) \
247 DEFINE (Bnthcdr, 0233) \
248 DEFINE (Belt, 0234) \
249 DEFINE (Bmember, 0235) \
250 DEFINE (Bassq, 0236) \
251 DEFINE (Bnreverse, 0237) \
252 DEFINE (Bsetcar, 0240) \
253 DEFINE (Bsetcdr, 0241) \
254 DEFINE (Bcar_safe, 0242) \
255 DEFINE (Bcdr_safe, 0243) \
256 DEFINE (Bnconc, 0244) \
257 DEFINE (Bquo, 0245) \
258 DEFINE (Brem, 0246) \
259 DEFINE (Bnumberp, 0247) \
260 DEFINE (Bintegerp, 0250) \
262 DEFINE (BRgoto, 0252) \
263 DEFINE (BRgotoifnil, 0253) \
264 DEFINE (BRgotoifnonnil, 0254) \
265 DEFINE (BRgotoifnilelsepop, 0255) \
266 DEFINE (BRgotoifnonnilelsepop, 0256) \
268 DEFINE (BlistN, 0257) \
269 DEFINE (BconcatN, 0260) \
270 DEFINE (BinsertN, 0261) \
272 /* Bstack_ref is code 0. */ \
273 DEFINE (Bstack_set, 0262) \
274 DEFINE (Bstack_set2, 0263) \
275 DEFINE (BdiscardN, 0266) \
277 DEFINE (Bconstant, 0300)
281 #define DEFINE(name, value) name = value,
285 #ifdef BYTE_CODE_SAFE
286 Bscan_buffer
= 0153, /* No longer generated as of v18. */
287 Bset_mark
= 0163 /* this loser is no longer generated as of v18 */
291 /* Whether to maintain a `top' and `bottom' field in the stack frame. */
292 #define BYTE_MAINTAIN_TOP (BYTE_CODE_SAFE || BYTE_MARK_STACK)
294 /* Structure describing a value stack used during byte-code execution
299 /* Program counter. This points into the byte_string below
300 and is relocated when that string is relocated. */
301 const unsigned char *pc
;
303 /* Top and bottom of stack. The bottom points to an area of memory
304 allocated with alloca in Fbyte_code. */
305 #if BYTE_MAINTAIN_TOP
306 Lisp_Object
*top
, *bottom
;
309 /* The string containing the byte-code, and its current address.
310 Storing this here protects it from GC because mark_byte_stack
312 Lisp_Object byte_string
;
313 const unsigned char *byte_string_start
;
315 /* The vector of constants used during byte-code execution. Storing
316 this here protects it from GC because mark_byte_stack marks it. */
317 Lisp_Object constants
;
319 /* Next entry in byte_stack_list. */
320 struct byte_stack
*next
;
323 /* A list of currently active byte-code execution value stacks.
324 Fbyte_code adds an entry to the head of this list before it starts
325 processing byte-code, and it removed the entry again when it is
326 done. Signaling an error truncates the list analogous to
329 struct byte_stack
*byte_stack_list
;
332 /* Mark objects on byte_stack_list. Called during GC. */
336 mark_byte_stack (void)
338 struct byte_stack
*stack
;
341 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
343 /* If STACK->top is null here, this means there's an opcode in
344 Fbyte_code that wasn't expected to GC, but did. To find out
345 which opcode this is, record the value of `stack', and walk
346 up the stack in a debugger, stopping in frames of Fbyte_code.
347 The culprit is found in the frame of Fbyte_code where the
348 address of its local variable `stack' is equal to the
349 recorded value of `stack' here. */
350 eassert (stack
->top
);
352 for (obj
= stack
->bottom
; obj
<= stack
->top
; ++obj
)
355 mark_object (stack
->byte_string
);
356 mark_object (stack
->constants
);
361 /* Unmark objects in the stacks on byte_stack_list. Relocate program
362 counters. Called when GC has completed. */
365 unmark_byte_stack (void)
367 struct byte_stack
*stack
;
369 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
371 if (stack
->byte_string_start
!= SDATA (stack
->byte_string
))
373 ptrdiff_t offset
= stack
->pc
- stack
->byte_string_start
;
374 stack
->byte_string_start
= SDATA (stack
->byte_string
);
375 stack
->pc
= stack
->byte_string_start
+ offset
;
381 /* Fetch the next byte from the bytecode stream */
383 #define FETCH *stack.pc++
385 /* Fetch two bytes from the bytecode stream and make a 16-bit number
388 #define FETCH2 (op = FETCH, op + (FETCH << 8))
390 /* Push x onto the execution stack. This used to be #define PUSH(x)
391 (*++stackp = (x)) This oddity is necessary because Alliant can't be
392 bothered to compile the preincrement operator properly, as of 4/91.
395 #define PUSH(x) (top++, *top = (x))
397 /* Pop a value off the execution stack. */
401 /* Discard n values from the execution stack. */
403 #define DISCARD(n) (top -= (n))
405 /* Get the value which is at the top of the execution stack, but don't
410 /* Actions that must be performed before and after calling a function
413 #if !BYTE_MAINTAIN_TOP
414 #define BEFORE_POTENTIAL_GC() ((void)0)
415 #define AFTER_POTENTIAL_GC() ((void)0)
417 #define BEFORE_POTENTIAL_GC() stack.top = top
418 #define AFTER_POTENTIAL_GC() stack.top = NULL
421 /* Garbage collect if we have consed enough since the last time.
422 We do this at every branch, to avoid loops that never GC. */
426 BEFORE_POTENTIAL_GC (); \
428 AFTER_POTENTIAL_GC (); \
431 /* Check for jumping out of range. */
433 #ifdef BYTE_CODE_SAFE
435 #define CHECK_RANGE(ARG) \
436 if (ARG >= bytestr_length) emacs_abort ()
438 #else /* not BYTE_CODE_SAFE */
440 #define CHECK_RANGE(ARG)
442 #endif /* not BYTE_CODE_SAFE */
444 /* A version of the QUIT macro which makes sure that the stack top is
445 set before signaling `quit'. */
447 #define BYTE_CODE_QUIT \
449 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
451 Lisp_Object flag = Vquit_flag; \
453 BEFORE_POTENTIAL_GC (); \
454 if (EQ (Vthrow_on_input, flag)) \
455 Fthrow (Vthrow_on_input, Qt); \
456 Fsignal (Qquit, Qnil); \
457 AFTER_POTENTIAL_GC (); \
459 else if (pending_signals) \
460 process_pending_signals (); \
464 DEFUN ("byte-code", Fbyte_code
, Sbyte_code
, 3, 3, 0,
465 doc
: /* Function used internally in byte-compiled code.
466 The first argument, BYTESTR, is a string of byte code;
467 the second, VECTOR, a vector of constants;
468 the third, MAXDEPTH, the maximum stack depth used in this function.
469 If the third argument is incorrect, Emacs may crash. */)
470 (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
)
472 return exec_byte_code (bytestr
, vector
, maxdepth
, Qnil
, 0, NULL
);
475 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
476 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
477 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
478 argument list (including &rest, &optional, etc.), and ARGS, of size
479 NARGS, should be a vector of the actual arguments. The arguments in
480 ARGS are pushed on the stack according to ARGS_TEMPLATE before
481 executing BYTESTR. */
484 exec_byte_code (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
,
485 Lisp_Object args_template
, ptrdiff_t nargs
, Lisp_Object
*args
)
487 ptrdiff_t count
= SPECPDL_INDEX ();
488 #ifdef BYTE_CODE_METER
493 /* Lisp_Object v1, v2; */
494 Lisp_Object
*vectorp
;
495 #ifdef BYTE_CODE_SAFE
496 ptrdiff_t const_length
;
498 ptrdiff_t bytestr_length
;
500 struct byte_stack stack
;
504 #if 0 /* CHECK_FRAME_FONT */
506 struct frame
*f
= SELECTED_FRAME ();
508 && FRAME_FONT (f
)->direction
!= 0
509 && FRAME_FONT (f
)->direction
!= 1)
514 CHECK_STRING (bytestr
);
515 CHECK_VECTOR (vector
);
516 CHECK_NATNUM (maxdepth
);
518 #ifdef BYTE_CODE_SAFE
519 const_length
= ASIZE (vector
);
522 if (STRING_MULTIBYTE (bytestr
))
523 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
524 because they produced a raw 8-bit string for byte-code and now
525 such a byte-code string is loaded as multibyte while raw 8-bit
526 characters converted to multibyte form. Thus, now we must
527 convert them back to the originally intended unibyte form. */
528 bytestr
= Fstring_as_unibyte (bytestr
);
530 #ifdef BYTE_CODE_SAFE
531 bytestr_length
= SBYTES (bytestr
);
533 vectorp
= XVECTOR (vector
)->contents
;
535 stack
.byte_string
= bytestr
;
536 stack
.pc
= stack
.byte_string_start
= SDATA (bytestr
);
537 stack
.constants
= vector
;
538 if (MAX_ALLOCA
/ word_size
<= XFASTINT (maxdepth
))
539 memory_full (SIZE_MAX
);
540 top
= alloca ((XFASTINT (maxdepth
) + 1) * sizeof *top
);
541 #if BYTE_MAINTAIN_TOP
542 stack
.bottom
= top
+ 1;
545 stack
.next
= byte_stack_list
;
546 byte_stack_list
= &stack
;
548 #ifdef BYTE_CODE_SAFE
549 stacke
= stack
.bottom
- 1 + XFASTINT (maxdepth
);
552 if (INTEGERP (args_template
))
554 ptrdiff_t at
= XINT (args_template
);
555 bool rest
= (at
& 128) != 0;
556 int mandatory
= at
& 127;
557 ptrdiff_t nonrest
= at
>> 8;
558 eassert (mandatory
<= nonrest
);
559 if (nargs
<= nonrest
)
562 for (i
= 0 ; i
< nargs
; i
++, args
++)
564 if (nargs
< mandatory
)
565 /* Too few arguments. */
566 Fsignal (Qwrong_number_of_arguments
,
567 Fcons (Fcons (make_number (mandatory
),
568 rest
? Qand_rest
: make_number (nonrest
)),
569 Fcons (make_number (nargs
), Qnil
)));
572 for (; i
< nonrest
; i
++)
581 for (i
= 0 ; i
< nonrest
; i
++, args
++)
583 PUSH (Flist (nargs
- nonrest
, args
));
586 /* Too many arguments. */
587 Fsignal (Qwrong_number_of_arguments
,
588 Fcons (Fcons (make_number (mandatory
),
589 make_number (nonrest
)),
590 Fcons (make_number (nargs
), Qnil
)));
592 else if (! NILP (args_template
))
593 /* We should push some arguments on the stack. */
595 error ("Unknown args template!");
600 #ifdef BYTE_CODE_SAFE
603 else if (top
< stack
.bottom
- 1)
607 #ifdef BYTE_CODE_METER
609 this_op
= op
= FETCH
;
610 METER_CODE (prev_op
, op
);
612 #ifndef BYTE_CODE_THREADED
617 /* The interpreter can be compiled one of two ways: as an
618 ordinary switch-based interpreter, or as a threaded
619 interpreter. The threaded interpreter relies on GCC's
620 computed goto extension, so it is not available everywhere.
621 Threading provides a performance boost. These macros are how
622 we allow the code to be compiled both ways. */
623 #ifdef BYTE_CODE_THREADED
624 /* The CASE macro introduces an instruction's body. It is
625 either a label or a case label. */
626 #define CASE(OP) insn_ ## OP
627 /* NEXT is invoked at the end of an instruction to go to the
628 next instruction. It is either a computed goto, or a
630 #define NEXT goto *(targets[op = FETCH])
631 /* FIRST is like NEXT, but is only used at the start of the
632 interpreter body. In the switch-based interpreter it is the
633 switch, so the threaded definition must include a semicolon. */
635 /* Most cases are labeled with the CASE macro, above.
636 CASE_DEFAULT is one exception; it is used if the interpreter
637 being built requires a default case. The threaded
638 interpreter does not, because the dispatch table is
639 completely filled. */
641 /* This introduces an instruction that is known to call abort. */
642 #define CASE_ABORT CASE (Bstack_ref): CASE (default)
644 /* See above for the meaning of the various defines. */
645 #define CASE(OP) case OP
647 #define FIRST switch (op)
648 #define CASE_DEFAULT case 255: default:
649 #define CASE_ABORT case 0
652 #ifdef BYTE_CODE_THREADED
654 /* A convenience define that saves us a lot of typing and makes
655 the table clearer. */
656 #define LABEL(OP) [OP] = &&insn_ ## OP
658 #if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
659 # pragma GCC diagnostic push
660 # pragma GCC diagnostic ignored "-Woverride-init"
663 /* This is the dispatch table for the threaded interpreter. */
664 static const void *const targets
[256] =
666 [0 ... (Bconstant
- 1)] = &&insn_default
,
667 [Bconstant
... 255] = &&insn_Bconstant
,
669 #define DEFINE(name, value) LABEL (name) ,
674 #if (__GNUC__ == 4 && 6 <= __GNUC_MINOR__) || 4 < __GNUC__
675 # pragma GCC diagnostic pop
696 /* This seems to be the most frequently executed byte-code
697 among the Bvarref's, so avoid a goto here. */
707 if (XSYMBOL (v1
)->redirect
!= SYMBOL_PLAINVAL
708 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)),
711 BEFORE_POTENTIAL_GC ();
712 v2
= Fsymbol_value (v1
);
713 AFTER_POTENTIAL_GC ();
718 BEFORE_POTENTIAL_GC ();
719 v2
= Fsymbol_value (v1
);
720 AFTER_POTENTIAL_GC ();
736 stack
.pc
= stack
.byte_string_start
+ op
;
751 BEFORE_POTENTIAL_GC ();
752 wrong_type_argument (Qlistp
, v1
);
753 AFTER_POTENTIAL_GC ();
762 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
769 BEFORE_POTENTIAL_GC ();
771 TOP
= Fmemq (TOP
, v1
);
772 AFTER_POTENTIAL_GC ();
786 BEFORE_POTENTIAL_GC ();
787 wrong_type_argument (Qlistp
, v1
);
788 AFTER_POTENTIAL_GC ();
810 Lisp_Object sym
, val
;
815 /* Inline the most common case. */
817 && !EQ (val
, Qunbound
)
818 && !XSYMBOL (sym
)->redirect
819 && !SYMBOL_CONSTANT_P (sym
))
820 SET_SYMBOL_VAL (XSYMBOL (sym
), val
);
823 BEFORE_POTENTIAL_GC ();
824 set_internal (sym
, val
, Qnil
, 0);
825 AFTER_POTENTIAL_GC ();
839 /* ------------------ */
857 /* Specbind can signal and thus GC. */
858 BEFORE_POTENTIAL_GC ();
859 specbind (vectorp
[op
], POP
);
860 AFTER_POTENTIAL_GC ();
880 BEFORE_POTENTIAL_GC ();
882 #ifdef BYTE_CODE_METER
883 if (byte_metering_on
&& SYMBOLP (TOP
))
888 v2
= Fget (v1
, Qbyte_code_meter
);
890 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
892 XSETINT (v2
, XINT (v2
) + 1);
893 Fput (v1
, Qbyte_code_meter
, v2
);
897 TOP
= Ffuncall (op
+ 1, &TOP
);
898 AFTER_POTENTIAL_GC ();
918 BEFORE_POTENTIAL_GC ();
919 unbind_to (SPECPDL_INDEX () - op
, Qnil
);
920 AFTER_POTENTIAL_GC ();
923 CASE (Bunbind_all
): /* Obsolete. Never used. */
924 /* To unbind back to the beginning of this frame. Not used yet,
925 but will be needed for tail-recursion elimination. */
926 BEFORE_POTENTIAL_GC ();
927 unbind_to (count
, Qnil
);
928 AFTER_POTENTIAL_GC ();
934 op
= FETCH2
; /* pc = FETCH2 loses since FETCH2 contains pc++ */
936 stack
.pc
= stack
.byte_string_start
+ op
;
939 CASE (Bgotoifnonnil
):
949 stack
.pc
= stack
.byte_string_start
+ op
;
954 CASE (Bgotoifnilelsepop
):
961 stack
.pc
= stack
.byte_string_start
+ op
;
966 CASE (Bgotoifnonnilelsepop
):
973 stack
.pc
= stack
.byte_string_start
+ op
;
981 stack
.pc
+= (int) *stack
.pc
- 127;
992 stack
.pc
+= (int) *stack
.pc
- 128;
998 CASE (BRgotoifnonnil
):
1006 stack
.pc
+= (int) *stack
.pc
- 128;
1012 CASE (BRgotoifnilelsepop
):
1018 stack
.pc
+= op
- 128;
1023 CASE (BRgotoifnonnilelsepop
):
1029 stack
.pc
+= op
- 128;
1043 PUSH (vectorp
[FETCH2
]);
1046 CASE (Bsave_excursion
):
1047 record_unwind_protect (save_excursion_restore
,
1048 save_excursion_save ());
1051 CASE (Bsave_current_buffer
): /* Obsolete since ??. */
1052 CASE (Bsave_current_buffer_1
):
1053 record_unwind_current_buffer ();
1056 CASE (Bsave_window_excursion
): /* Obsolete since 24.1. */
1058 register ptrdiff_t count1
= SPECPDL_INDEX ();
1059 record_unwind_protect (Fset_window_configuration
,
1060 Fcurrent_window_configuration (Qnil
));
1061 BEFORE_POTENTIAL_GC ();
1063 unbind_to (count1
, TOP
);
1064 AFTER_POTENTIAL_GC ();
1068 CASE (Bsave_restriction
):
1069 record_unwind_protect (save_restriction_restore
,
1070 save_restriction_save ());
1073 CASE (Bcatch
): /* FIXME: ill-suited for lexbind. */
1076 BEFORE_POTENTIAL_GC ();
1078 TOP
= internal_catch (TOP
, eval_sub
, v1
);
1079 AFTER_POTENTIAL_GC ();
1083 CASE (Bunwind_protect
): /* FIXME: avoid closure for lexbind. */
1084 record_unwind_protect (Fprogn
, POP
);
1087 CASE (Bcondition_case
): /* FIXME: ill-suited for lexbind. */
1089 Lisp_Object handlers
, body
;
1092 BEFORE_POTENTIAL_GC ();
1093 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
);
1094 AFTER_POTENTIAL_GC ();
1098 CASE (Btemp_output_buffer_setup
): /* Obsolete since 24.1. */
1099 BEFORE_POTENTIAL_GC ();
1101 temp_output_buffer_setup (SSDATA (TOP
));
1102 AFTER_POTENTIAL_GC ();
1103 TOP
= Vstandard_output
;
1106 CASE (Btemp_output_buffer_show
): /* Obsolete since 24.1. */
1109 BEFORE_POTENTIAL_GC ();
1111 temp_output_buffer_show (TOP
);
1113 /* pop binding of standard-output */
1114 unbind_to (SPECPDL_INDEX () - 1, Qnil
);
1115 AFTER_POTENTIAL_GC ();
1123 BEFORE_POTENTIAL_GC ();
1129 while (--n
>= 0 && CONSP (v1
))
1133 AFTER_POTENTIAL_GC ();
1138 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
1142 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
1146 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
1150 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
1154 TOP
= NILP (TOP
) ? Qt
: Qnil
;
1161 TOP
= Fcons (TOP
, v1
);
1166 TOP
= Fcons (TOP
, Qnil
);
1173 TOP
= Fcons (TOP
, Fcons (v1
, Qnil
));
1179 TOP
= Flist (3, &TOP
);
1184 TOP
= Flist (4, &TOP
);
1190 TOP
= Flist (op
, &TOP
);
1194 BEFORE_POTENTIAL_GC ();
1195 TOP
= Flength (TOP
);
1196 AFTER_POTENTIAL_GC ();
1202 BEFORE_POTENTIAL_GC ();
1204 TOP
= Faref (TOP
, v1
);
1205 AFTER_POTENTIAL_GC ();
1212 BEFORE_POTENTIAL_GC ();
1214 TOP
= Faset (TOP
, v1
, v2
);
1215 AFTER_POTENTIAL_GC ();
1219 CASE (Bsymbol_value
):
1220 BEFORE_POTENTIAL_GC ();
1221 TOP
= Fsymbol_value (TOP
);
1222 AFTER_POTENTIAL_GC ();
1225 CASE (Bsymbol_function
):
1226 BEFORE_POTENTIAL_GC ();
1227 TOP
= Fsymbol_function (TOP
);
1228 AFTER_POTENTIAL_GC ();
1234 BEFORE_POTENTIAL_GC ();
1236 TOP
= Fset (TOP
, v1
);
1237 AFTER_POTENTIAL_GC ();
1244 BEFORE_POTENTIAL_GC ();
1246 TOP
= Ffset (TOP
, v1
);
1247 AFTER_POTENTIAL_GC ();
1254 BEFORE_POTENTIAL_GC ();
1256 TOP
= Fget (TOP
, v1
);
1257 AFTER_POTENTIAL_GC ();
1264 BEFORE_POTENTIAL_GC ();
1266 TOP
= Fsubstring (TOP
, v1
, v2
);
1267 AFTER_POTENTIAL_GC ();
1272 BEFORE_POTENTIAL_GC ();
1274 TOP
= Fconcat (2, &TOP
);
1275 AFTER_POTENTIAL_GC ();
1279 BEFORE_POTENTIAL_GC ();
1281 TOP
= Fconcat (3, &TOP
);
1282 AFTER_POTENTIAL_GC ();
1286 BEFORE_POTENTIAL_GC ();
1288 TOP
= Fconcat (4, &TOP
);
1289 AFTER_POTENTIAL_GC ();
1294 BEFORE_POTENTIAL_GC ();
1296 TOP
= Fconcat (op
, &TOP
);
1297 AFTER_POTENTIAL_GC ();
1306 XSETINT (v1
, XINT (v1
) - 1);
1311 BEFORE_POTENTIAL_GC ();
1313 AFTER_POTENTIAL_GC ();
1324 XSETINT (v1
, XINT (v1
) + 1);
1329 BEFORE_POTENTIAL_GC ();
1331 AFTER_POTENTIAL_GC ();
1339 BEFORE_POTENTIAL_GC ();
1341 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
1342 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
1343 AFTER_POTENTIAL_GC ();
1344 if (FLOATP (v1
) || FLOATP (v2
))
1348 f1
= (FLOATP (v1
) ? XFLOAT_DATA (v1
) : XINT (v1
));
1349 f2
= (FLOATP (v2
) ? XFLOAT_DATA (v2
) : XINT (v2
));
1350 TOP
= (f1
== f2
? Qt
: Qnil
);
1353 TOP
= (XINT (v1
) == XINT (v2
) ? Qt
: Qnil
);
1360 BEFORE_POTENTIAL_GC ();
1362 TOP
= Fgtr (TOP
, v1
);
1363 AFTER_POTENTIAL_GC ();
1370 BEFORE_POTENTIAL_GC ();
1372 TOP
= Flss (TOP
, v1
);
1373 AFTER_POTENTIAL_GC ();
1380 BEFORE_POTENTIAL_GC ();
1382 TOP
= Fleq (TOP
, v1
);
1383 AFTER_POTENTIAL_GC ();
1390 BEFORE_POTENTIAL_GC ();
1392 TOP
= Fgeq (TOP
, v1
);
1393 AFTER_POTENTIAL_GC ();
1398 BEFORE_POTENTIAL_GC ();
1400 TOP
= Fminus (2, &TOP
);
1401 AFTER_POTENTIAL_GC ();
1410 XSETINT (v1
, - XINT (v1
));
1415 BEFORE_POTENTIAL_GC ();
1416 TOP
= Fminus (1, &TOP
);
1417 AFTER_POTENTIAL_GC ();
1423 BEFORE_POTENTIAL_GC ();
1425 TOP
= Fplus (2, &TOP
);
1426 AFTER_POTENTIAL_GC ();
1430 BEFORE_POTENTIAL_GC ();
1432 TOP
= Fmax (2, &TOP
);
1433 AFTER_POTENTIAL_GC ();
1437 BEFORE_POTENTIAL_GC ();
1439 TOP
= Fmin (2, &TOP
);
1440 AFTER_POTENTIAL_GC ();
1444 BEFORE_POTENTIAL_GC ();
1446 TOP
= Ftimes (2, &TOP
);
1447 AFTER_POTENTIAL_GC ();
1451 BEFORE_POTENTIAL_GC ();
1453 TOP
= Fquo (2, &TOP
);
1454 AFTER_POTENTIAL_GC ();
1460 BEFORE_POTENTIAL_GC ();
1462 TOP
= Frem (TOP
, v1
);
1463 AFTER_POTENTIAL_GC ();
1470 XSETFASTINT (v1
, PT
);
1476 BEFORE_POTENTIAL_GC ();
1477 TOP
= Fgoto_char (TOP
);
1478 AFTER_POTENTIAL_GC ();
1482 BEFORE_POTENTIAL_GC ();
1483 TOP
= Finsert (1, &TOP
);
1484 AFTER_POTENTIAL_GC ();
1489 BEFORE_POTENTIAL_GC ();
1491 TOP
= Finsert (op
, &TOP
);
1492 AFTER_POTENTIAL_GC ();
1498 XSETFASTINT (v1
, ZV
);
1506 XSETFASTINT (v1
, BEGV
);
1512 BEFORE_POTENTIAL_GC ();
1513 TOP
= Fchar_after (TOP
);
1514 AFTER_POTENTIAL_GC ();
1517 CASE (Bfollowing_char
):
1520 BEFORE_POTENTIAL_GC ();
1521 v1
= Ffollowing_char ();
1522 AFTER_POTENTIAL_GC ();
1527 CASE (Bpreceding_char
):
1530 BEFORE_POTENTIAL_GC ();
1531 v1
= Fprevious_char ();
1532 AFTER_POTENTIAL_GC ();
1537 CASE (Bcurrent_column
):
1540 BEFORE_POTENTIAL_GC ();
1541 XSETFASTINT (v1
, current_column ());
1542 AFTER_POTENTIAL_GC ();
1548 BEFORE_POTENTIAL_GC ();
1549 TOP
= Findent_to (TOP
, Qnil
);
1550 AFTER_POTENTIAL_GC ();
1569 CASE (Bcurrent_buffer
):
1570 PUSH (Fcurrent_buffer ());
1574 BEFORE_POTENTIAL_GC ();
1575 TOP
= Fset_buffer (TOP
);
1576 AFTER_POTENTIAL_GC ();
1579 CASE (Binteractive_p
): /* Obsolete since 24.1. */
1580 BEFORE_POTENTIAL_GC ();
1581 PUSH (call0 (intern ("interactive-p")));
1582 AFTER_POTENTIAL_GC ();
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 defsubr (&Sbyte_code
);
1966 #ifdef BYTE_CODE_METER
1968 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter
,
1969 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
1970 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1971 opcode CODE has been executed.
1972 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1973 indicates how many times the byte opcodes CODE1 and CODE2 have been
1974 executed in succession. */);
1976 DEFVAR_BOOL ("byte-metering-on", byte_metering_on
,
1977 doc
: /* If non-nil, keep profiling information on byte code usage.
1978 The variable byte-code-meter indicates how often each byte opcode is used.
1979 If a symbol has a property named `byte-code-meter' whose value is an
1980 integer, it is incremented each time that symbol's function is called. */);
1982 byte_metering_on
= 0;
1983 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
1984 DEFSYM (Qbyte_code_meter
, "byte-code-meter");
1988 ASET (Vbyte_code_meter
, i
,
1989 Fmake_vector (make_number (256), make_number (0)));