1 /* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985-1988, 1993, 2000-2013 Free Software Foundation,
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 hacked on by jwz@lucid.com 17-jun-91
22 o added a compile-time switch to turn on simple sanity checking;
23 o put back the obsolete byte-codes for error-detection;
24 o added a new instruction, unbind_all, which I will use for
25 tail-recursion elimination;
26 o made temp_output_buffer_show be called with the right number
28 o made the new bytecodes be called with args in the right order;
29 o added metering support.
32 o added relative jump instructions;
33 o all conditionals now only do QUIT if they jump.
39 #include "character.h"
44 #ifdef CHECK_FRAME_FONT
50 * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for
51 * debugging the byte compiler...)
53 * define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
55 /* #define BYTE_CODE_SAFE */
56 /* #define BYTE_CODE_METER */
58 /* If BYTE_CODE_THREADED is defined, then the interpreter will be
59 indirect threaded, using GCC's computed goto extension. This code,
60 as currently implemented, is incompatible with BYTE_CODE_SAFE and
62 #if (defined __GNUC__ && !defined __STRICT_ANSI__ \
63 && !defined BYTE_CODE_SAFE && !defined BYTE_CODE_METER)
64 #define BYTE_CODE_THREADED
68 #ifdef BYTE_CODE_METER
70 Lisp_Object Qbyte_code_meter
;
71 #define METER_2(code1, code2) AREF (AREF (Vbyte_code_meter, code1), code2)
72 #define METER_1(code) METER_2 (0, code)
74 #define METER_CODE(last_code, this_code) \
76 if (byte_metering_on) \
78 if (XFASTINT (METER_1 (this_code)) < MOST_POSITIVE_FIXNUM) \
79 XSETFASTINT (METER_1 (this_code), \
80 XFASTINT (METER_1 (this_code)) + 1); \
82 && (XFASTINT (METER_2 (last_code, this_code)) \
83 < MOST_POSITIVE_FIXNUM)) \
84 XSETFASTINT (METER_2 (last_code, this_code), \
85 XFASTINT (METER_2 (last_code, this_code)) + 1); \
89 #endif /* BYTE_CODE_METER */
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 */
292 B__dummy__
= 0 /* Pacify C89. */
295 /* Whether to maintain a `top' and `bottom' field in the stack frame. */
296 #define BYTE_MAINTAIN_TOP (BYTE_CODE_SAFE || BYTE_MARK_STACK)
298 /* Structure describing a value stack used during byte-code execution
303 /* Program counter. This points into the byte_string below
304 and is relocated when that string is relocated. */
305 const unsigned char *pc
;
307 /* Top and bottom of stack. The bottom points to an area of memory
308 allocated with alloca in Fbyte_code. */
309 #if BYTE_MAINTAIN_TOP
310 Lisp_Object
*top
, *bottom
;
313 /* The string containing the byte-code, and its current address.
314 Storing this here protects it from GC because mark_byte_stack
316 Lisp_Object byte_string
;
317 const unsigned char *byte_string_start
;
320 /* The vector of constants used during byte-code execution. Storing
321 this here protects it from GC because mark_byte_stack marks it. */
322 Lisp_Object constants
;
325 /* Next entry in byte_stack_list. */
326 struct byte_stack
*next
;
329 /* A list of currently active byte-code execution value stacks.
330 Fbyte_code adds an entry to the head of this list before it starts
331 processing byte-code, and it removed the entry again when it is
332 done. Signaling an error truncates the list analogous to
335 struct byte_stack
*byte_stack_list
;
338 /* Mark objects on byte_stack_list. Called during GC. */
342 mark_byte_stack (void)
344 struct byte_stack
*stack
;
347 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
349 /* If STACK->top is null here, this means there's an opcode in
350 Fbyte_code that wasn't expected to GC, but did. To find out
351 which opcode this is, record the value of `stack', and walk
352 up the stack in a debugger, stopping in frames of Fbyte_code.
353 The culprit is found in the frame of Fbyte_code where the
354 address of its local variable `stack' is equal to the
355 recorded value of `stack' here. */
356 eassert (stack
->top
);
358 for (obj
= stack
->bottom
; obj
<= stack
->top
; ++obj
)
361 mark_object (stack
->byte_string
);
362 mark_object (stack
->constants
);
367 /* Unmark objects in the stacks on byte_stack_list. Relocate program
368 counters. Called when GC has completed. */
371 unmark_byte_stack (void)
373 struct byte_stack
*stack
;
375 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
377 if (stack
->byte_string_start
!= SDATA (stack
->byte_string
))
379 ptrdiff_t offset
= stack
->pc
- stack
->byte_string_start
;
380 stack
->byte_string_start
= SDATA (stack
->byte_string
);
381 stack
->pc
= stack
->byte_string_start
+ offset
;
387 /* Fetch the next byte from the bytecode stream. */
389 #define FETCH *stack.pc++
391 /* Fetch two bytes from the bytecode stream and make a 16-bit number
394 #define FETCH2 (op = FETCH, op + (FETCH << 8))
396 /* Push x onto the execution stack. This used to be #define PUSH(x)
397 (*++stackp = (x)) This oddity is necessary because Alliant can't be
398 bothered to compile the preincrement operator properly, as of 4/91.
401 #define PUSH(x) (top++, *top = (x))
403 /* Pop a value off the execution stack. */
407 /* Discard n values from the execution stack. */
409 #define DISCARD(n) (top -= (n))
411 /* Get the value which is at the top of the execution stack, but don't
416 /* Actions that must be performed before and after calling a function
419 #if !BYTE_MAINTAIN_TOP
420 #define BEFORE_POTENTIAL_GC() ((void)0)
421 #define AFTER_POTENTIAL_GC() ((void)0)
423 #define BEFORE_POTENTIAL_GC() stack.top = top
424 #define AFTER_POTENTIAL_GC() stack.top = NULL
427 /* Garbage collect if we have consed enough since the last time.
428 We do this at every branch, to avoid loops that never GC. */
432 BEFORE_POTENTIAL_GC (); \
434 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) emacs_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 if (pending_signals) \
466 process_pending_signals (); \
470 DEFUN ("byte-code", Fbyte_code
, Sbyte_code
, 3, 3, 0,
471 doc
: /* Function used internally in byte-compiled code.
472 The first argument, BYTESTR, is a string of byte code;
473 the second, VECTOR, a vector of constants;
474 the third, MAXDEPTH, the maximum stack depth used in this function.
475 If the third argument is incorrect, Emacs may crash. */)
476 (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
)
478 return exec_byte_code (bytestr
, vector
, maxdepth
, Qnil
, 0, NULL
);
481 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
482 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
483 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
484 argument list (including &rest, &optional, etc.), and ARGS, of size
485 NARGS, should be a vector of the actual arguments. The arguments in
486 ARGS are pushed on the stack according to ARGS_TEMPLATE before
487 executing BYTESTR. */
490 exec_byte_code (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
,
491 Lisp_Object args_template
, ptrdiff_t nargs
, Lisp_Object
*args
)
493 ptrdiff_t count
= SPECPDL_INDEX ();
494 #ifdef BYTE_CODE_METER
499 /* Lisp_Object v1, v2; */
500 Lisp_Object
*vectorp
;
501 #ifdef BYTE_CODE_SAFE
502 ptrdiff_t const_length
;
504 ptrdiff_t bytestr_length
;
506 struct byte_stack stack
;
510 #if 0 /* CHECK_FRAME_FONT */
512 struct frame
*f
= SELECTED_FRAME ();
514 && FRAME_FONT (f
)->direction
!= 0
515 && FRAME_FONT (f
)->direction
!= 1)
520 CHECK_STRING (bytestr
);
521 CHECK_VECTOR (vector
);
522 CHECK_NATNUM (maxdepth
);
524 #ifdef BYTE_CODE_SAFE
525 const_length
= ASIZE (vector
);
528 if (STRING_MULTIBYTE (bytestr
))
529 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
530 because they produced a raw 8-bit string for byte-code and now
531 such a byte-code string is loaded as multibyte while raw 8-bit
532 characters converted to multibyte form. Thus, now we must
533 convert them back to the originally intended unibyte form. */
534 bytestr
= Fstring_as_unibyte (bytestr
);
536 #ifdef BYTE_CODE_SAFE
537 bytestr_length
= SBYTES (bytestr
);
539 vectorp
= XVECTOR (vector
)->contents
;
541 stack
.byte_string
= bytestr
;
542 stack
.pc
= stack
.byte_string_start
= SDATA (bytestr
);
544 stack
.constants
= vector
;
546 if (MAX_ALLOCA
/ word_size
<= XFASTINT (maxdepth
))
547 memory_full (SIZE_MAX
);
548 top
= alloca ((XFASTINT (maxdepth
) + 1) * sizeof *top
);
549 #if BYTE_MAINTAIN_TOP
550 stack
.bottom
= top
+ 1;
553 stack
.next
= byte_stack_list
;
554 byte_stack_list
= &stack
;
556 #ifdef BYTE_CODE_SAFE
557 stacke
= stack
.bottom
- 1 + XFASTINT (maxdepth
);
560 if (INTEGERP (args_template
))
562 ptrdiff_t at
= XINT (args_template
);
563 bool rest
= (at
& 128) != 0;
564 int mandatory
= at
& 127;
565 ptrdiff_t nonrest
= at
>> 8;
566 eassert (mandatory
<= nonrest
);
567 if (nargs
<= nonrest
)
570 for (i
= 0 ; i
< nargs
; i
++, args
++)
572 if (nargs
< mandatory
)
573 /* Too few arguments. */
574 Fsignal (Qwrong_number_of_arguments
,
575 list2 (Fcons (make_number (mandatory
),
576 rest
? Qand_rest
: make_number (nonrest
)),
577 make_number (nargs
)));
580 for (; i
< nonrest
; i
++)
589 for (i
= 0 ; i
< nonrest
; i
++, args
++)
591 PUSH (Flist (nargs
- nonrest
, args
));
594 /* Too many arguments. */
595 Fsignal (Qwrong_number_of_arguments
,
596 list2 (Fcons (make_number (mandatory
), make_number (nonrest
)),
597 make_number (nargs
)));
599 else if (! NILP (args_template
))
600 /* We should push some arguments on the stack. */
602 error ("Unknown args template!");
607 #ifdef BYTE_CODE_SAFE
610 else if (top
< stack
.bottom
- 1)
614 #ifdef BYTE_CODE_METER
616 this_op
= op
= FETCH
;
617 METER_CODE (prev_op
, op
);
619 #ifndef BYTE_CODE_THREADED
624 /* The interpreter can be compiled one of two ways: as an
625 ordinary switch-based interpreter, or as a threaded
626 interpreter. The threaded interpreter relies on GCC's
627 computed goto extension, so it is not available everywhere.
628 Threading provides a performance boost. These macros are how
629 we allow the code to be compiled both ways. */
630 #ifdef BYTE_CODE_THREADED
631 /* The CASE macro introduces an instruction's body. It is
632 either a label or a case label. */
633 #define CASE(OP) insn_ ## OP
634 /* NEXT is invoked at the end of an instruction to go to the
635 next instruction. It is either a computed goto, or a
637 #define NEXT goto *(targets[op = FETCH])
638 /* FIRST is like NEXT, but is only used at the start of the
639 interpreter body. In the switch-based interpreter it is the
640 switch, so the threaded definition must include a semicolon. */
642 /* Most cases are labeled with the CASE macro, above.
643 CASE_DEFAULT is one exception; it is used if the interpreter
644 being built requires a default case. The threaded
645 interpreter does not, because the dispatch table is
646 completely filled. */
648 /* This introduces an instruction that is known to call abort. */
649 #define CASE_ABORT CASE (Bstack_ref): CASE (default)
651 /* See above for the meaning of the various defines. */
652 #define CASE(OP) case OP
654 #define FIRST switch (op)
655 #define CASE_DEFAULT case 255: default:
656 #define CASE_ABORT case 0
659 #ifdef BYTE_CODE_THREADED
661 /* A convenience define that saves us a lot of typing and makes
662 the table clearer. */
663 #define LABEL(OP) [OP] = &&insn_ ## OP
665 #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
666 # pragma GCC diagnostic push
667 # pragma GCC diagnostic ignored "-Woverride-init"
668 #elif defined __clang__
669 # pragma GCC diagnostic push
670 # pragma GCC diagnostic ignored "-Winitializer-overrides"
673 /* This is the dispatch table for the threaded interpreter. */
674 static const void *const targets
[256] =
676 [0 ... (Bconstant
- 1)] = &&insn_default
,
677 [Bconstant
... 255] = &&insn_Bconstant
,
679 #define DEFINE(name, value) LABEL (name) ,
684 #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) || defined __clang__
685 # pragma GCC diagnostic pop
706 /* This seems to be the most frequently executed byte-code
707 among the Bvarref's, so avoid a goto here. */
717 if (XSYMBOL (v1
)->redirect
!= SYMBOL_PLAINVAL
718 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)),
721 BEFORE_POTENTIAL_GC ();
722 v2
= Fsymbol_value (v1
);
723 AFTER_POTENTIAL_GC ();
728 BEFORE_POTENTIAL_GC ();
729 v2
= Fsymbol_value (v1
);
730 AFTER_POTENTIAL_GC ();
746 stack
.pc
= stack
.byte_string_start
+ op
;
761 BEFORE_POTENTIAL_GC ();
762 wrong_type_argument (Qlistp
, v1
);
771 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
778 BEFORE_POTENTIAL_GC ();
780 TOP
= Fmemq (TOP
, v1
);
781 AFTER_POTENTIAL_GC ();
795 BEFORE_POTENTIAL_GC ();
796 wrong_type_argument (Qlistp
, v1
);
818 Lisp_Object sym
, val
;
823 /* Inline the most common case. */
825 && !EQ (val
, Qunbound
)
826 && !XSYMBOL (sym
)->redirect
827 && !SYMBOL_CONSTANT_P (sym
))
828 SET_SYMBOL_VAL (XSYMBOL (sym
), val
);
831 BEFORE_POTENTIAL_GC ();
832 set_internal (sym
, val
, Qnil
, 0);
833 AFTER_POTENTIAL_GC ();
847 /* ------------------ */
865 /* Specbind can signal and thus GC. */
866 BEFORE_POTENTIAL_GC ();
867 specbind (vectorp
[op
], POP
);
868 AFTER_POTENTIAL_GC ();
888 BEFORE_POTENTIAL_GC ();
890 #ifdef BYTE_CODE_METER
891 if (byte_metering_on
&& SYMBOLP (TOP
))
896 v2
= Fget (v1
, Qbyte_code_meter
);
898 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
900 XSETINT (v2
, XINT (v2
) + 1);
901 Fput (v1
, Qbyte_code_meter
, v2
);
905 TOP
= Ffuncall (op
+ 1, &TOP
);
906 AFTER_POTENTIAL_GC ();
926 BEFORE_POTENTIAL_GC ();
927 unbind_to (SPECPDL_INDEX () - op
, Qnil
);
928 AFTER_POTENTIAL_GC ();
931 CASE (Bunbind_all
): /* Obsolete. Never used. */
932 /* To unbind back to the beginning of this frame. Not used yet,
933 but will be needed for tail-recursion elimination. */
934 BEFORE_POTENTIAL_GC ();
935 unbind_to (count
, Qnil
);
936 AFTER_POTENTIAL_GC ();
942 op
= FETCH2
; /* pc = FETCH2 loses since FETCH2 contains pc++ */
944 stack
.pc
= stack
.byte_string_start
+ op
;
947 CASE (Bgotoifnonnil
):
957 stack
.pc
= stack
.byte_string_start
+ op
;
962 CASE (Bgotoifnilelsepop
):
969 stack
.pc
= stack
.byte_string_start
+ op
;
974 CASE (Bgotoifnonnilelsepop
):
981 stack
.pc
= stack
.byte_string_start
+ op
;
989 stack
.pc
+= (int) *stack
.pc
- 127;
1000 stack
.pc
+= (int) *stack
.pc
- 128;
1006 CASE (BRgotoifnonnil
):
1014 stack
.pc
+= (int) *stack
.pc
- 128;
1020 CASE (BRgotoifnilelsepop
):
1026 stack
.pc
+= op
- 128;
1031 CASE (BRgotoifnonnilelsepop
):
1037 stack
.pc
+= op
- 128;
1051 PUSH (vectorp
[FETCH2
]);
1054 CASE (Bsave_excursion
):
1055 record_unwind_protect (save_excursion_restore
,
1056 save_excursion_save ());
1059 CASE (Bsave_current_buffer
): /* Obsolete since ??. */
1060 CASE (Bsave_current_buffer_1
):
1061 record_unwind_current_buffer ();
1064 CASE (Bsave_window_excursion
): /* Obsolete since 24.1. */
1066 ptrdiff_t count1
= SPECPDL_INDEX ();
1067 record_unwind_protect (restore_window_configuration
,
1068 Fcurrent_window_configuration (Qnil
));
1069 BEFORE_POTENTIAL_GC ();
1071 unbind_to (count1
, TOP
);
1072 AFTER_POTENTIAL_GC ();
1076 CASE (Bsave_restriction
):
1077 record_unwind_protect (save_restriction_restore
,
1078 save_restriction_save ());
1081 CASE (Bcatch
): /* FIXME: ill-suited for lexbind. */
1084 BEFORE_POTENTIAL_GC ();
1086 TOP
= internal_catch (TOP
, eval_sub
, v1
);
1087 AFTER_POTENTIAL_GC ();
1091 CASE (Bunwind_protect
): /* FIXME: avoid closure for lexbind. */
1092 record_unwind_protect (unwind_body
, POP
);
1095 CASE (Bcondition_case
): /* FIXME: ill-suited for lexbind. */
1097 Lisp_Object handlers
, body
;
1100 BEFORE_POTENTIAL_GC ();
1101 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
);
1102 AFTER_POTENTIAL_GC ();
1106 CASE (Btemp_output_buffer_setup
): /* Obsolete since 24.1. */
1107 BEFORE_POTENTIAL_GC ();
1109 temp_output_buffer_setup (SSDATA (TOP
));
1110 AFTER_POTENTIAL_GC ();
1111 TOP
= Vstandard_output
;
1114 CASE (Btemp_output_buffer_show
): /* Obsolete since 24.1. */
1117 BEFORE_POTENTIAL_GC ();
1119 temp_output_buffer_show (TOP
);
1121 /* pop binding of standard-output */
1122 unbind_to (SPECPDL_INDEX () - 1, Qnil
);
1123 AFTER_POTENTIAL_GC ();
1131 BEFORE_POTENTIAL_GC ();
1137 while (--n
>= 0 && CONSP (v1
))
1141 AFTER_POTENTIAL_GC ();
1146 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
1150 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
1154 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
1158 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
1162 TOP
= NILP (TOP
) ? Qt
: Qnil
;
1169 TOP
= Fcons (TOP
, v1
);
1181 TOP
= list2 (TOP
, v1
);
1187 TOP
= Flist (3, &TOP
);
1192 TOP
= Flist (4, &TOP
);
1198 TOP
= Flist (op
, &TOP
);
1202 BEFORE_POTENTIAL_GC ();
1203 TOP
= Flength (TOP
);
1204 AFTER_POTENTIAL_GC ();
1210 BEFORE_POTENTIAL_GC ();
1212 TOP
= Faref (TOP
, v1
);
1213 AFTER_POTENTIAL_GC ();
1220 BEFORE_POTENTIAL_GC ();
1222 TOP
= Faset (TOP
, v1
, v2
);
1223 AFTER_POTENTIAL_GC ();
1227 CASE (Bsymbol_value
):
1228 BEFORE_POTENTIAL_GC ();
1229 TOP
= Fsymbol_value (TOP
);
1230 AFTER_POTENTIAL_GC ();
1233 CASE (Bsymbol_function
):
1234 BEFORE_POTENTIAL_GC ();
1235 TOP
= Fsymbol_function (TOP
);
1236 AFTER_POTENTIAL_GC ();
1242 BEFORE_POTENTIAL_GC ();
1244 TOP
= Fset (TOP
, v1
);
1245 AFTER_POTENTIAL_GC ();
1252 BEFORE_POTENTIAL_GC ();
1254 TOP
= Ffset (TOP
, v1
);
1255 AFTER_POTENTIAL_GC ();
1262 BEFORE_POTENTIAL_GC ();
1264 TOP
= Fget (TOP
, v1
);
1265 AFTER_POTENTIAL_GC ();
1272 BEFORE_POTENTIAL_GC ();
1274 TOP
= Fsubstring (TOP
, v1
, v2
);
1275 AFTER_POTENTIAL_GC ();
1280 BEFORE_POTENTIAL_GC ();
1282 TOP
= Fconcat (2, &TOP
);
1283 AFTER_POTENTIAL_GC ();
1287 BEFORE_POTENTIAL_GC ();
1289 TOP
= Fconcat (3, &TOP
);
1290 AFTER_POTENTIAL_GC ();
1294 BEFORE_POTENTIAL_GC ();
1296 TOP
= Fconcat (4, &TOP
);
1297 AFTER_POTENTIAL_GC ();
1302 BEFORE_POTENTIAL_GC ();
1304 TOP
= Fconcat (op
, &TOP
);
1305 AFTER_POTENTIAL_GC ();
1314 XSETINT (v1
, XINT (v1
) - 1);
1319 BEFORE_POTENTIAL_GC ();
1321 AFTER_POTENTIAL_GC ();
1332 XSETINT (v1
, XINT (v1
) + 1);
1337 BEFORE_POTENTIAL_GC ();
1339 AFTER_POTENTIAL_GC ();
1347 BEFORE_POTENTIAL_GC ();
1349 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
1350 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
1351 AFTER_POTENTIAL_GC ();
1352 if (FLOATP (v1
) || FLOATP (v2
))
1356 f1
= (FLOATP (v1
) ? XFLOAT_DATA (v1
) : XINT (v1
));
1357 f2
= (FLOATP (v2
) ? XFLOAT_DATA (v2
) : XINT (v2
));
1358 TOP
= (f1
== f2
? Qt
: Qnil
);
1361 TOP
= (XINT (v1
) == XINT (v2
) ? Qt
: Qnil
);
1368 BEFORE_POTENTIAL_GC ();
1370 TOP
= Fgtr (TOP
, v1
);
1371 AFTER_POTENTIAL_GC ();
1378 BEFORE_POTENTIAL_GC ();
1380 TOP
= Flss (TOP
, v1
);
1381 AFTER_POTENTIAL_GC ();
1388 BEFORE_POTENTIAL_GC ();
1390 TOP
= Fleq (TOP
, v1
);
1391 AFTER_POTENTIAL_GC ();
1398 BEFORE_POTENTIAL_GC ();
1400 TOP
= Fgeq (TOP
, v1
);
1401 AFTER_POTENTIAL_GC ();
1406 BEFORE_POTENTIAL_GC ();
1408 TOP
= Fminus (2, &TOP
);
1409 AFTER_POTENTIAL_GC ();
1418 XSETINT (v1
, - XINT (v1
));
1423 BEFORE_POTENTIAL_GC ();
1424 TOP
= Fminus (1, &TOP
);
1425 AFTER_POTENTIAL_GC ();
1431 BEFORE_POTENTIAL_GC ();
1433 TOP
= Fplus (2, &TOP
);
1434 AFTER_POTENTIAL_GC ();
1438 BEFORE_POTENTIAL_GC ();
1440 TOP
= Fmax (2, &TOP
);
1441 AFTER_POTENTIAL_GC ();
1445 BEFORE_POTENTIAL_GC ();
1447 TOP
= Fmin (2, &TOP
);
1448 AFTER_POTENTIAL_GC ();
1452 BEFORE_POTENTIAL_GC ();
1454 TOP
= Ftimes (2, &TOP
);
1455 AFTER_POTENTIAL_GC ();
1459 BEFORE_POTENTIAL_GC ();
1461 TOP
= Fquo (2, &TOP
);
1462 AFTER_POTENTIAL_GC ();
1468 BEFORE_POTENTIAL_GC ();
1470 TOP
= Frem (TOP
, v1
);
1471 AFTER_POTENTIAL_GC ();
1478 XSETFASTINT (v1
, PT
);
1484 BEFORE_POTENTIAL_GC ();
1485 TOP
= Fgoto_char (TOP
);
1486 AFTER_POTENTIAL_GC ();
1490 BEFORE_POTENTIAL_GC ();
1491 TOP
= Finsert (1, &TOP
);
1492 AFTER_POTENTIAL_GC ();
1497 BEFORE_POTENTIAL_GC ();
1499 TOP
= Finsert (op
, &TOP
);
1500 AFTER_POTENTIAL_GC ();
1506 XSETFASTINT (v1
, ZV
);
1514 XSETFASTINT (v1
, BEGV
);
1520 BEFORE_POTENTIAL_GC ();
1521 TOP
= Fchar_after (TOP
);
1522 AFTER_POTENTIAL_GC ();
1525 CASE (Bfollowing_char
):
1528 BEFORE_POTENTIAL_GC ();
1529 v1
= Ffollowing_char ();
1530 AFTER_POTENTIAL_GC ();
1535 CASE (Bpreceding_char
):
1538 BEFORE_POTENTIAL_GC ();
1539 v1
= Fprevious_char ();
1540 AFTER_POTENTIAL_GC ();
1545 CASE (Bcurrent_column
):
1548 BEFORE_POTENTIAL_GC ();
1549 XSETFASTINT (v1
, current_column ());
1550 AFTER_POTENTIAL_GC ();
1556 BEFORE_POTENTIAL_GC ();
1557 TOP
= Findent_to (TOP
, Qnil
);
1558 AFTER_POTENTIAL_GC ();
1577 CASE (Bcurrent_buffer
):
1578 PUSH (Fcurrent_buffer ());
1582 BEFORE_POTENTIAL_GC ();
1583 TOP
= Fset_buffer (TOP
);
1584 AFTER_POTENTIAL_GC ();
1587 CASE (Binteractive_p
): /* Obsolete since 24.1. */
1588 BEFORE_POTENTIAL_GC ();
1589 PUSH (call0 (intern ("interactive-p")));
1590 AFTER_POTENTIAL_GC ();
1593 CASE (Bforward_char
):
1594 BEFORE_POTENTIAL_GC ();
1595 TOP
= Fforward_char (TOP
);
1596 AFTER_POTENTIAL_GC ();
1599 CASE (Bforward_word
):
1600 BEFORE_POTENTIAL_GC ();
1601 TOP
= Fforward_word (TOP
);
1602 AFTER_POTENTIAL_GC ();
1605 CASE (Bskip_chars_forward
):
1608 BEFORE_POTENTIAL_GC ();
1610 TOP
= Fskip_chars_forward (TOP
, v1
);
1611 AFTER_POTENTIAL_GC ();
1615 CASE (Bskip_chars_backward
):
1618 BEFORE_POTENTIAL_GC ();
1620 TOP
= Fskip_chars_backward (TOP
, v1
);
1621 AFTER_POTENTIAL_GC ();
1625 CASE (Bforward_line
):
1626 BEFORE_POTENTIAL_GC ();
1627 TOP
= Fforward_line (TOP
);
1628 AFTER_POTENTIAL_GC ();
1631 CASE (Bchar_syntax
):
1635 BEFORE_POTENTIAL_GC ();
1636 CHECK_CHARACTER (TOP
);
1637 AFTER_POTENTIAL_GC ();
1639 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
1640 MAKE_CHAR_MULTIBYTE (c
);
1641 XSETFASTINT (TOP
, syntax_code_spec
[SYNTAX (c
)]);
1645 CASE (Bbuffer_substring
):
1648 BEFORE_POTENTIAL_GC ();
1650 TOP
= Fbuffer_substring (TOP
, v1
);
1651 AFTER_POTENTIAL_GC ();
1655 CASE (Bdelete_region
):
1658 BEFORE_POTENTIAL_GC ();
1660 TOP
= Fdelete_region (TOP
, v1
);
1661 AFTER_POTENTIAL_GC ();
1665 CASE (Bnarrow_to_region
):
1668 BEFORE_POTENTIAL_GC ();
1670 TOP
= Fnarrow_to_region (TOP
, v1
);
1671 AFTER_POTENTIAL_GC ();
1676 BEFORE_POTENTIAL_GC ();
1678 AFTER_POTENTIAL_GC ();
1681 CASE (Bend_of_line
):
1682 BEFORE_POTENTIAL_GC ();
1683 TOP
= Fend_of_line (TOP
);
1684 AFTER_POTENTIAL_GC ();
1690 BEFORE_POTENTIAL_GC ();
1693 TOP
= Fset_marker (TOP
, v2
, v1
);
1694 AFTER_POTENTIAL_GC ();
1698 CASE (Bmatch_beginning
):
1699 BEFORE_POTENTIAL_GC ();
1700 TOP
= Fmatch_beginning (TOP
);
1701 AFTER_POTENTIAL_GC ();
1705 BEFORE_POTENTIAL_GC ();
1706 TOP
= Fmatch_end (TOP
);
1707 AFTER_POTENTIAL_GC ();
1711 BEFORE_POTENTIAL_GC ();
1712 TOP
= Fupcase (TOP
);
1713 AFTER_POTENTIAL_GC ();
1717 BEFORE_POTENTIAL_GC ();
1718 TOP
= Fdowncase (TOP
);
1719 AFTER_POTENTIAL_GC ();
1722 CASE (Bstringeqlsign
):
1725 BEFORE_POTENTIAL_GC ();
1727 TOP
= Fstring_equal (TOP
, v1
);
1728 AFTER_POTENTIAL_GC ();
1735 BEFORE_POTENTIAL_GC ();
1737 TOP
= Fstring_lessp (TOP
, v1
);
1738 AFTER_POTENTIAL_GC ();
1746 TOP
= Fequal (TOP
, v1
);
1753 BEFORE_POTENTIAL_GC ();
1755 TOP
= Fnthcdr (TOP
, v1
);
1756 AFTER_POTENTIAL_GC ();
1765 /* Exchange args and then do nth. */
1767 BEFORE_POTENTIAL_GC ();
1771 AFTER_POTENTIAL_GC ();
1774 while (--n
>= 0 && CONSP (v1
))
1781 BEFORE_POTENTIAL_GC ();
1783 TOP
= Felt (TOP
, v1
);
1784 AFTER_POTENTIAL_GC ();
1792 BEFORE_POTENTIAL_GC ();
1794 TOP
= Fmember (TOP
, v1
);
1795 AFTER_POTENTIAL_GC ();
1802 BEFORE_POTENTIAL_GC ();
1804 TOP
= Fassq (TOP
, v1
);
1805 AFTER_POTENTIAL_GC ();
1810 BEFORE_POTENTIAL_GC ();
1811 TOP
= Fnreverse (TOP
);
1812 AFTER_POTENTIAL_GC ();
1818 BEFORE_POTENTIAL_GC ();
1820 TOP
= Fsetcar (TOP
, v1
);
1821 AFTER_POTENTIAL_GC ();
1828 BEFORE_POTENTIAL_GC ();
1830 TOP
= Fsetcdr (TOP
, v1
);
1831 AFTER_POTENTIAL_GC ();
1839 TOP
= CAR_SAFE (v1
);
1847 TOP
= CDR_SAFE (v1
);
1852 BEFORE_POTENTIAL_GC ();
1854 TOP
= Fnconc (2, &TOP
);
1855 AFTER_POTENTIAL_GC ();
1859 TOP
= (NUMBERP (TOP
) ? Qt
: Qnil
);
1863 TOP
= INTEGERP (TOP
) ? Qt
: Qnil
;
1866 #ifdef BYTE_CODE_SAFE
1867 /* These are intentionally written using 'case' syntax,
1868 because they are incompatible with the threaded
1872 BEFORE_POTENTIAL_GC ();
1873 error ("set-mark is an obsolete bytecode");
1874 AFTER_POTENTIAL_GC ();
1877 BEFORE_POTENTIAL_GC ();
1878 error ("scan-buffer is an obsolete bytecode");
1879 AFTER_POTENTIAL_GC ();
1884 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1885 for that instead. */
1886 /* CASE (Bstack_ref): */
1887 error ("Invalid byte opcode");
1889 /* Handy byte-codes for lexical binding. */
1896 Lisp_Object
*ptr
= top
- (op
- Bstack_ref
);
1902 Lisp_Object
*ptr
= top
- (FETCH
);
1908 Lisp_Object
*ptr
= top
- (FETCH2
);
1913 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1915 Lisp_Object
*ptr
= top
- (FETCH
);
1921 Lisp_Object
*ptr
= top
- (FETCH2
);
1937 #ifdef BYTE_CODE_SAFE
1942 if ((op
-= Bconstant
) >= const_length
)
1948 PUSH (vectorp
[op
- Bconstant
]);
1956 byte_stack_list
= byte_stack_list
->next
;
1958 /* Binds and unbinds are supposed to be compiled balanced. */
1959 if (SPECPDL_INDEX () != count
)
1960 #ifdef BYTE_CODE_SAFE
1961 error ("binding stack not balanced (serious byte compiler bug)");
1970 syms_of_bytecode (void)
1972 defsubr (&Sbyte_code
);
1974 #ifdef BYTE_CODE_METER
1976 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter
,
1977 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
1978 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1979 opcode CODE has been executed.
1980 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1981 indicates how many times the byte opcodes CODE1 and CODE2 have been
1982 executed in succession. */);
1984 DEFVAR_BOOL ("byte-metering-on", byte_metering_on
,
1985 doc
: /* If non-nil, keep profiling information on byte code usage.
1986 The variable byte-code-meter indicates how often each byte opcode is used.
1987 If a symbol has a property named `byte-code-meter' whose value is an
1988 integer, it is incremented each time that symbol's function is called. */);
1990 byte_metering_on
= 0;
1991 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
1992 DEFSYM (Qbyte_code_meter
, "byte-code-meter");
1996 ASET (Vbyte_code_meter
, i
,
1997 Fmake_vector (make_number (256), make_number (0)));