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) \
144 DEFINE (Bpophandler, 060) \
145 DEFINE (Bpushconditioncase, 061) \
146 DEFINE (Bpushcatch, 062) \
149 DEFINE (Bsymbolp, 071) \
150 DEFINE (Bconsp, 072) \
151 DEFINE (Bstringp, 073) \
152 DEFINE (Blistp, 074) \
154 DEFINE (Bmemq, 076) \
156 DEFINE (Bcar, 0100) \
157 DEFINE (Bcdr, 0101) \
158 DEFINE (Bcons, 0102) \
159 DEFINE (Blist1, 0103) \
160 DEFINE (Blist2, 0104) \
161 DEFINE (Blist3, 0105) \
162 DEFINE (Blist4, 0106) \
163 DEFINE (Blength, 0107) \
164 DEFINE (Baref, 0110) \
165 DEFINE (Baset, 0111) \
166 DEFINE (Bsymbol_value, 0112) \
167 DEFINE (Bsymbol_function, 0113) \
168 DEFINE (Bset, 0114) \
169 DEFINE (Bfset, 0115) \
170 DEFINE (Bget, 0116) \
171 DEFINE (Bsubstring, 0117) \
172 DEFINE (Bconcat2, 0120) \
173 DEFINE (Bconcat3, 0121) \
174 DEFINE (Bconcat4, 0122) \
175 DEFINE (Bsub1, 0123) \
176 DEFINE (Badd1, 0124) \
177 DEFINE (Beqlsign, 0125) \
178 DEFINE (Bgtr, 0126) \
179 DEFINE (Blss, 0127) \
180 DEFINE (Bleq, 0130) \
181 DEFINE (Bgeq, 0131) \
182 DEFINE (Bdiff, 0132) \
183 DEFINE (Bnegate, 0133) \
184 DEFINE (Bplus, 0134) \
185 DEFINE (Bmax, 0135) \
186 DEFINE (Bmin, 0136) \
187 DEFINE (Bmult, 0137) \
189 DEFINE (Bpoint, 0140) \
190 /* Was Bmark in v17. */ \
191 DEFINE (Bsave_current_buffer, 0141) /* Obsolete. */ \
192 DEFINE (Bgoto_char, 0142) \
193 DEFINE (Binsert, 0143) \
194 DEFINE (Bpoint_max, 0144) \
195 DEFINE (Bpoint_min, 0145) \
196 DEFINE (Bchar_after, 0146) \
197 DEFINE (Bfollowing_char, 0147) \
198 DEFINE (Bpreceding_char, 0150) \
199 DEFINE (Bcurrent_column, 0151) \
200 DEFINE (Bindent_to, 0152) \
201 DEFINE (Beolp, 0154) \
202 DEFINE (Beobp, 0155) \
203 DEFINE (Bbolp, 0156) \
204 DEFINE (Bbobp, 0157) \
205 DEFINE (Bcurrent_buffer, 0160) \
206 DEFINE (Bset_buffer, 0161) \
207 DEFINE (Bsave_current_buffer_1, 0162) /* Replacing Bsave_current_buffer. */ \
208 DEFINE (Binteractive_p, 0164) /* Obsolete since Emacs-24.1. */ \
210 DEFINE (Bforward_char, 0165) \
211 DEFINE (Bforward_word, 0166) \
212 DEFINE (Bskip_chars_forward, 0167) \
213 DEFINE (Bskip_chars_backward, 0170) \
214 DEFINE (Bforward_line, 0171) \
215 DEFINE (Bchar_syntax, 0172) \
216 DEFINE (Bbuffer_substring, 0173) \
217 DEFINE (Bdelete_region, 0174) \
218 DEFINE (Bnarrow_to_region, 0175) \
219 DEFINE (Bwiden, 0176) \
220 DEFINE (Bend_of_line, 0177) \
222 DEFINE (Bconstant2, 0201) \
223 DEFINE (Bgoto, 0202) \
224 DEFINE (Bgotoifnil, 0203) \
225 DEFINE (Bgotoifnonnil, 0204) \
226 DEFINE (Bgotoifnilelsepop, 0205) \
227 DEFINE (Bgotoifnonnilelsepop, 0206) \
228 DEFINE (Breturn, 0207) \
229 DEFINE (Bdiscard, 0210) \
230 DEFINE (Bdup, 0211) \
232 DEFINE (Bsave_excursion, 0212) \
233 DEFINE (Bsave_window_excursion, 0213) /* Obsolete since Emacs-24.1. */ \
234 DEFINE (Bsave_restriction, 0214) \
235 DEFINE (Bcatch, 0215) \
237 DEFINE (Bunwind_protect, 0216) \
238 DEFINE (Bcondition_case, 0217) \
239 DEFINE (Btemp_output_buffer_setup, 0220) /* Obsolete since Emacs-24.1. */ \
240 DEFINE (Btemp_output_buffer_show, 0221) /* Obsolete since Emacs-24.1. */ \
242 DEFINE (Bunbind_all, 0222) /* Obsolete. Never used. */ \
244 DEFINE (Bset_marker, 0223) \
245 DEFINE (Bmatch_beginning, 0224) \
246 DEFINE (Bmatch_end, 0225) \
247 DEFINE (Bupcase, 0226) \
248 DEFINE (Bdowncase, 0227) \
250 DEFINE (Bstringeqlsign, 0230) \
251 DEFINE (Bstringlss, 0231) \
252 DEFINE (Bequal, 0232) \
253 DEFINE (Bnthcdr, 0233) \
254 DEFINE (Belt, 0234) \
255 DEFINE (Bmember, 0235) \
256 DEFINE (Bassq, 0236) \
257 DEFINE (Bnreverse, 0237) \
258 DEFINE (Bsetcar, 0240) \
259 DEFINE (Bsetcdr, 0241) \
260 DEFINE (Bcar_safe, 0242) \
261 DEFINE (Bcdr_safe, 0243) \
262 DEFINE (Bnconc, 0244) \
263 DEFINE (Bquo, 0245) \
264 DEFINE (Brem, 0246) \
265 DEFINE (Bnumberp, 0247) \
266 DEFINE (Bintegerp, 0250) \
268 DEFINE (BRgoto, 0252) \
269 DEFINE (BRgotoifnil, 0253) \
270 DEFINE (BRgotoifnonnil, 0254) \
271 DEFINE (BRgotoifnilelsepop, 0255) \
272 DEFINE (BRgotoifnonnilelsepop, 0256) \
274 DEFINE (BlistN, 0257) \
275 DEFINE (BconcatN, 0260) \
276 DEFINE (BinsertN, 0261) \
278 /* Bstack_ref is code 0. */ \
279 DEFINE (Bstack_set, 0262) \
280 DEFINE (Bstack_set2, 0263) \
281 DEFINE (BdiscardN, 0266) \
283 DEFINE (Bconstant, 0300)
287 #define DEFINE(name, value) name = value,
291 #ifdef BYTE_CODE_SAFE
292 Bscan_buffer
= 0153, /* No longer generated as of v18. */
293 Bset_mark
= 0163, /* this loser is no longer generated as of v18 */
296 B__dummy__
= 0 /* Pacify C89. */
299 /* Whether to maintain a `top' and `bottom' field in the stack frame. */
300 #define BYTE_MAINTAIN_TOP (BYTE_CODE_SAFE || BYTE_MARK_STACK)
302 /* Structure describing a value stack used during byte-code execution
307 /* Program counter. This points into the byte_string below
308 and is relocated when that string is relocated. */
309 const unsigned char *pc
;
311 /* Top and bottom of stack. The bottom points to an area of memory
312 allocated with alloca in Fbyte_code. */
313 #if BYTE_MAINTAIN_TOP
314 Lisp_Object
*top
, *bottom
;
317 /* The string containing the byte-code, and its current address.
318 Storing this here protects it from GC because mark_byte_stack
320 Lisp_Object byte_string
;
321 const unsigned char *byte_string_start
;
324 /* The vector of constants used during byte-code execution. Storing
325 this here protects it from GC because mark_byte_stack marks it. */
326 Lisp_Object constants
;
329 /* Next entry in byte_stack_list. */
330 struct byte_stack
*next
;
333 /* A list of currently active byte-code execution value stacks.
334 Fbyte_code adds an entry to the head of this list before it starts
335 processing byte-code, and it removes the entry again when it is
336 done. Signaling an error truncates the list analogous to
339 struct byte_stack
*byte_stack_list
;
342 /* Mark objects on byte_stack_list. Called during GC. */
346 mark_byte_stack (void)
348 struct byte_stack
*stack
;
351 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
353 /* If STACK->top is null here, this means there's an opcode in
354 Fbyte_code that wasn't expected to GC, but did. To find out
355 which opcode this is, record the value of `stack', and walk
356 up the stack in a debugger, stopping in frames of Fbyte_code.
357 The culprit is found in the frame of Fbyte_code where the
358 address of its local variable `stack' is equal to the
359 recorded value of `stack' here. */
360 eassert (stack
->top
);
362 for (obj
= stack
->bottom
; obj
<= stack
->top
; ++obj
)
365 mark_object (stack
->byte_string
);
366 mark_object (stack
->constants
);
371 /* Unmark objects in the stacks on byte_stack_list. Relocate program
372 counters. Called when GC has completed. */
375 unmark_byte_stack (void)
377 struct byte_stack
*stack
;
379 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
381 if (stack
->byte_string_start
!= SDATA (stack
->byte_string
))
383 ptrdiff_t offset
= stack
->pc
- stack
->byte_string_start
;
384 stack
->byte_string_start
= SDATA (stack
->byte_string
);
385 stack
->pc
= stack
->byte_string_start
+ offset
;
391 /* Fetch the next byte from the bytecode stream. */
393 #define FETCH *stack.pc++
395 /* Fetch two bytes from the bytecode stream and make a 16-bit number
398 #define FETCH2 (op = FETCH, op + (FETCH << 8))
400 /* Push x onto the execution stack. This used to be #define PUSH(x)
401 (*++stackp = (x)) This oddity is necessary because Alliant can't be
402 bothered to compile the preincrement operator properly, as of 4/91.
405 #define PUSH(x) (top++, *top = (x))
407 /* Pop a value off the execution stack. */
411 /* Discard n values from the execution stack. */
413 #define DISCARD(n) (top -= (n))
415 /* Get the value which is at the top of the execution stack, but don't
420 /* Actions that must be performed before and after calling a function
423 #if !BYTE_MAINTAIN_TOP
424 #define BEFORE_POTENTIAL_GC() ((void)0)
425 #define AFTER_POTENTIAL_GC() ((void)0)
427 #define BEFORE_POTENTIAL_GC() stack.top = top
428 #define AFTER_POTENTIAL_GC() stack.top = NULL
431 /* Garbage collect if we have consed enough since the last time.
432 We do this at every branch, to avoid loops that never GC. */
436 BEFORE_POTENTIAL_GC (); \
438 AFTER_POTENTIAL_GC (); \
441 /* Check for jumping out of range. */
443 #ifdef BYTE_CODE_SAFE
445 #define CHECK_RANGE(ARG) \
446 if (ARG >= bytestr_length) emacs_abort ()
448 #else /* not BYTE_CODE_SAFE */
450 #define CHECK_RANGE(ARG)
452 #endif /* not BYTE_CODE_SAFE */
454 /* A version of the QUIT macro which makes sure that the stack top is
455 set before signaling `quit'. */
457 #define BYTE_CODE_QUIT \
459 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
461 Lisp_Object flag = Vquit_flag; \
463 BEFORE_POTENTIAL_GC (); \
464 if (EQ (Vthrow_on_input, flag)) \
465 Fthrow (Vthrow_on_input, Qt); \
466 Fsignal (Qquit, Qnil); \
467 AFTER_POTENTIAL_GC (); \
469 else if (pending_signals) \
470 process_pending_signals (); \
474 DEFUN ("byte-code", Fbyte_code
, Sbyte_code
, 3, 3, 0,
475 doc
: /* Function used internally in byte-compiled code.
476 The first argument, BYTESTR, is a string of byte code;
477 the second, VECTOR, a vector of constants;
478 the third, MAXDEPTH, the maximum stack depth used in this function.
479 If the third argument is incorrect, Emacs may crash. */)
480 (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
)
482 return exec_byte_code (bytestr
, vector
, maxdepth
, Qnil
, 0, NULL
);
486 bcall0 (Lisp_Object f
)
491 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
492 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
493 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
494 argument list (including &rest, &optional, etc.), and ARGS, of size
495 NARGS, should be a vector of the actual arguments. The arguments in
496 ARGS are pushed on the stack according to ARGS_TEMPLATE before
497 executing BYTESTR. */
500 exec_byte_code (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
,
501 Lisp_Object args_template
, ptrdiff_t nargs
, Lisp_Object
*args
)
503 ptrdiff_t count
= SPECPDL_INDEX ();
504 ptrdiff_t volatile count_volatile
;
505 #ifdef BYTE_CODE_METER
506 int volatile this_op
= 0;
510 /* Lisp_Object v1, v2; */
511 Lisp_Object
*vectorp
;
512 Lisp_Object
*volatile vectorp_volatile
;
513 #ifdef BYTE_CODE_SAFE
514 ptrdiff_t volatile const_length
;
515 Lisp_Object
*volatile stacke
;
516 ptrdiff_t volatile bytestr_length
;
518 struct byte_stack stack
;
519 struct byte_stack
volatile stack_volatile
;
522 enum handlertype type
;
524 #if 0 /* CHECK_FRAME_FONT */
526 struct frame
*f
= SELECTED_FRAME ();
528 && FRAME_FONT (f
)->direction
!= 0
529 && FRAME_FONT (f
)->direction
!= 1)
534 CHECK_STRING (bytestr
);
535 CHECK_VECTOR (vector
);
536 CHECK_NATNUM (maxdepth
);
538 #ifdef BYTE_CODE_SAFE
539 const_length
= ASIZE (vector
);
542 if (STRING_MULTIBYTE (bytestr
))
543 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
544 because they produced a raw 8-bit string for byte-code and now
545 such a byte-code string is loaded as multibyte while raw 8-bit
546 characters converted to multibyte form. Thus, now we must
547 convert them back to the originally intended unibyte form. */
548 bytestr
= Fstring_as_unibyte (bytestr
);
550 #ifdef BYTE_CODE_SAFE
551 bytestr_length
= SBYTES (bytestr
);
553 vectorp
= XVECTOR (vector
)->contents
;
555 stack
.byte_string
= bytestr
;
556 stack
.pc
= stack
.byte_string_start
= SDATA (bytestr
);
558 stack
.constants
= vector
;
560 if (MAX_ALLOCA
/ word_size
<= XFASTINT (maxdepth
))
561 memory_full (SIZE_MAX
);
562 top
= alloca ((XFASTINT (maxdepth
) + 1) * sizeof *top
);
563 #if BYTE_MAINTAIN_TOP
564 stack
.bottom
= top
+ 1;
567 stack
.next
= byte_stack_list
;
568 byte_stack_list
= &stack
;
570 #ifdef BYTE_CODE_SAFE
571 stacke
= stack
.bottom
- 1 + XFASTINT (maxdepth
);
574 if (INTEGERP (args_template
))
576 ptrdiff_t at
= XINT (args_template
);
577 bool rest
= (at
& 128) != 0;
578 int mandatory
= at
& 127;
579 ptrdiff_t nonrest
= at
>> 8;
580 eassert (mandatory
<= nonrest
);
581 if (nargs
<= nonrest
)
584 for (i
= 0 ; i
< nargs
; i
++, args
++)
586 if (nargs
< mandatory
)
587 /* Too few arguments. */
588 Fsignal (Qwrong_number_of_arguments
,
589 list2 (Fcons (make_number (mandatory
),
590 rest
? Qand_rest
: make_number (nonrest
)),
591 make_number (nargs
)));
594 for (; i
< nonrest
; i
++)
603 for (i
= 0 ; i
< nonrest
; i
++, args
++)
605 PUSH (Flist (nargs
- nonrest
, args
));
608 /* Too many arguments. */
609 Fsignal (Qwrong_number_of_arguments
,
610 list2 (Fcons (make_number (mandatory
), make_number (nonrest
)),
611 make_number (nargs
)));
613 else if (! NILP (args_template
))
614 /* We should push some arguments on the stack. */
616 error ("Unknown args template!");
621 #ifdef BYTE_CODE_SAFE
624 else if (top
< stack
.bottom
- 1)
628 #ifdef BYTE_CODE_METER
630 this_op
= op
= FETCH
;
631 METER_CODE (prev_op
, op
);
633 #ifndef BYTE_CODE_THREADED
638 /* The interpreter can be compiled one of two ways: as an
639 ordinary switch-based interpreter, or as a threaded
640 interpreter. The threaded interpreter relies on GCC's
641 computed goto extension, so it is not available everywhere.
642 Threading provides a performance boost. These macros are how
643 we allow the code to be compiled both ways. */
644 #ifdef BYTE_CODE_THREADED
645 /* The CASE macro introduces an instruction's body. It is
646 either a label or a case label. */
647 #define CASE(OP) insn_ ## OP
648 /* NEXT is invoked at the end of an instruction to go to the
649 next instruction. It is either a computed goto, or a
651 #define NEXT goto *(targets[op = FETCH])
652 /* FIRST is like NEXT, but is only used at the start of the
653 interpreter body. In the switch-based interpreter it is the
654 switch, so the threaded definition must include a semicolon. */
656 /* Most cases are labeled with the CASE macro, above.
657 CASE_DEFAULT is one exception; it is used if the interpreter
658 being built requires a default case. The threaded
659 interpreter does not, because the dispatch table is
660 completely filled. */
662 /* This introduces an instruction that is known to call abort. */
663 #define CASE_ABORT CASE (Bstack_ref): CASE (default)
665 /* See above for the meaning of the various defines. */
666 #define CASE(OP) case OP
668 #define FIRST switch (op)
669 #define CASE_DEFAULT case 255: default:
670 #define CASE_ABORT case 0
673 #ifdef BYTE_CODE_THREADED
675 /* A convenience define that saves us a lot of typing and makes
676 the table clearer. */
677 #define LABEL(OP) [OP] = &&insn_ ## OP
679 #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
680 # pragma GCC diagnostic push
681 # pragma GCC diagnostic ignored "-Woverride-init"
682 #elif defined __clang__
683 # pragma GCC diagnostic push
684 # pragma GCC diagnostic ignored "-Winitializer-overrides"
687 /* This is the dispatch table for the threaded interpreter. */
688 static const void *const targets
[256] =
690 [0 ... (Bconstant
- 1)] = &&insn_default
,
691 [Bconstant
... 255] = &&insn_Bconstant
,
693 #define DEFINE(name, value) LABEL (name) ,
698 #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) || defined __clang__
699 # pragma GCC diagnostic pop
720 /* This seems to be the most frequently executed byte-code
721 among the Bvarref's, so avoid a goto here. */
731 if (XSYMBOL (v1
)->redirect
!= SYMBOL_PLAINVAL
732 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)),
735 BEFORE_POTENTIAL_GC ();
736 v2
= Fsymbol_value (v1
);
737 AFTER_POTENTIAL_GC ();
742 BEFORE_POTENTIAL_GC ();
743 v2
= Fsymbol_value (v1
);
744 AFTER_POTENTIAL_GC ();
760 stack
.pc
= stack
.byte_string_start
+ op
;
775 BEFORE_POTENTIAL_GC ();
776 wrong_type_argument (Qlistp
, v1
);
785 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
792 BEFORE_POTENTIAL_GC ();
794 TOP
= Fmemq (TOP
, v1
);
795 AFTER_POTENTIAL_GC ();
809 BEFORE_POTENTIAL_GC ();
810 wrong_type_argument (Qlistp
, v1
);
832 Lisp_Object sym
, val
;
837 /* Inline the most common case. */
839 && !EQ (val
, Qunbound
)
840 && !XSYMBOL (sym
)->redirect
841 && !SYMBOL_CONSTANT_P (sym
))
842 SET_SYMBOL_VAL (XSYMBOL (sym
), val
);
845 BEFORE_POTENTIAL_GC ();
846 set_internal (sym
, val
, Qnil
, 0);
847 AFTER_POTENTIAL_GC ();
861 /* ------------------ */
879 /* Specbind can signal and thus GC. */
880 BEFORE_POTENTIAL_GC ();
881 specbind (vectorp
[op
], POP
);
882 AFTER_POTENTIAL_GC ();
902 BEFORE_POTENTIAL_GC ();
904 #ifdef BYTE_CODE_METER
905 if (byte_metering_on
&& SYMBOLP (TOP
))
910 v2
= Fget (v1
, Qbyte_code_meter
);
912 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
914 XSETINT (v2
, XINT (v2
) + 1);
915 Fput (v1
, Qbyte_code_meter
, v2
);
919 TOP
= Ffuncall (op
+ 1, &TOP
);
920 AFTER_POTENTIAL_GC ();
940 BEFORE_POTENTIAL_GC ();
941 unbind_to (SPECPDL_INDEX () - op
, Qnil
);
942 AFTER_POTENTIAL_GC ();
945 CASE (Bunbind_all
): /* Obsolete. Never used. */
946 /* To unbind back to the beginning of this frame. Not used yet,
947 but will be needed for tail-recursion elimination. */
948 BEFORE_POTENTIAL_GC ();
949 unbind_to (count
, Qnil
);
950 AFTER_POTENTIAL_GC ();
956 op
= FETCH2
; /* pc = FETCH2 loses since FETCH2 contains pc++ */
958 stack
.pc
= stack
.byte_string_start
+ op
;
961 CASE (Bgotoifnonnil
):
971 stack
.pc
= stack
.byte_string_start
+ op
;
976 CASE (Bgotoifnilelsepop
):
983 stack
.pc
= stack
.byte_string_start
+ op
;
988 CASE (Bgotoifnonnilelsepop
):
995 stack
.pc
= stack
.byte_string_start
+ op
;
1003 stack
.pc
+= (int) *stack
.pc
- 127;
1014 stack
.pc
+= (int) *stack
.pc
- 128;
1020 CASE (BRgotoifnonnil
):
1028 stack
.pc
+= (int) *stack
.pc
- 128;
1034 CASE (BRgotoifnilelsepop
):
1040 stack
.pc
+= op
- 128;
1045 CASE (BRgotoifnonnilelsepop
):
1051 stack
.pc
+= op
- 128;
1065 PUSH (vectorp
[FETCH2
]);
1068 CASE (Bsave_excursion
):
1069 record_unwind_protect (save_excursion_restore
,
1070 save_excursion_save ());
1073 CASE (Bsave_current_buffer
): /* Obsolete since ??. */
1074 CASE (Bsave_current_buffer_1
):
1075 record_unwind_current_buffer ();
1078 CASE (Bsave_window_excursion
): /* Obsolete since 24.1. */
1080 ptrdiff_t count1
= SPECPDL_INDEX ();
1081 record_unwind_protect (restore_window_configuration
,
1082 Fcurrent_window_configuration (Qnil
));
1083 BEFORE_POTENTIAL_GC ();
1085 unbind_to (count1
, TOP
);
1086 AFTER_POTENTIAL_GC ();
1090 CASE (Bsave_restriction
):
1091 record_unwind_protect (save_restriction_restore
,
1092 save_restriction_save ());
1095 CASE (Bcatch
): /* Obsolete since 24.4. */
1098 BEFORE_POTENTIAL_GC ();
1100 TOP
= internal_catch (TOP
, eval_sub
, v1
);
1101 AFTER_POTENTIAL_GC ();
1105 CASE (Bpushcatch
): /* New in 24.4. */
1108 CASE (Bpushconditioncase
): /* New in 24.4. */
1110 extern EMACS_INT lisp_eval_depth
;
1111 extern int poll_suppress_count
;
1112 extern int interrupt_input_blocked
;
1117 type
= CONDITION_CASE
;
1122 PUSH_HANDLER (c
, tag
, type
);
1123 c
->bytecode_dest
= dest
;
1124 c
->bytecode_top
= top
;
1125 count_volatile
= count
;
1126 stack_volatile
= stack
;
1127 vectorp_volatile
= vectorp
;
1129 if (sys_setjmp (c
->jmp
))
1131 struct handler
*c
= handlerlist
;
1133 top
= c
->bytecode_top
;
1134 dest
= c
->bytecode_dest
;
1135 handlerlist
= c
->next
;
1138 stack
= stack_volatile
;
1139 stack
.pc
= stack
.byte_string_start
+ dest
;
1142 count
= count_volatile
;
1143 vectorp
= vectorp_volatile
;
1147 CASE (Bpophandler
): /* New in 24.4. */
1149 handlerlist
= handlerlist
->next
;
1153 CASE (Bunwind_protect
): /* FIXME: avoid closure for lexbind. */
1155 Lisp_Object handler
= POP
;
1156 /* Support for a function here is new in 24.4. */
1157 record_unwind_protect (NILP (Ffunctionp (handler
))
1158 ? unwind_body
: bcall0
,
1163 CASE (Bcondition_case
): /* Obsolete since 24.4. */
1165 Lisp_Object handlers
, body
;
1168 BEFORE_POTENTIAL_GC ();
1169 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
);
1170 AFTER_POTENTIAL_GC ();
1174 CASE (Btemp_output_buffer_setup
): /* Obsolete since 24.1. */
1175 BEFORE_POTENTIAL_GC ();
1177 temp_output_buffer_setup (SSDATA (TOP
));
1178 AFTER_POTENTIAL_GC ();
1179 TOP
= Vstandard_output
;
1182 CASE (Btemp_output_buffer_show
): /* Obsolete since 24.1. */
1185 BEFORE_POTENTIAL_GC ();
1187 temp_output_buffer_show (TOP
);
1189 /* pop binding of standard-output */
1190 unbind_to (SPECPDL_INDEX () - 1, Qnil
);
1191 AFTER_POTENTIAL_GC ();
1199 BEFORE_POTENTIAL_GC ();
1205 while (--n
>= 0 && CONSP (v1
))
1209 AFTER_POTENTIAL_GC ();
1214 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
1218 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
1222 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
1226 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
1230 TOP
= NILP (TOP
) ? Qt
: Qnil
;
1237 TOP
= Fcons (TOP
, v1
);
1249 TOP
= list2 (TOP
, v1
);
1255 TOP
= Flist (3, &TOP
);
1260 TOP
= Flist (4, &TOP
);
1266 TOP
= Flist (op
, &TOP
);
1270 BEFORE_POTENTIAL_GC ();
1271 TOP
= Flength (TOP
);
1272 AFTER_POTENTIAL_GC ();
1278 BEFORE_POTENTIAL_GC ();
1280 TOP
= Faref (TOP
, v1
);
1281 AFTER_POTENTIAL_GC ();
1288 BEFORE_POTENTIAL_GC ();
1290 TOP
= Faset (TOP
, v1
, v2
);
1291 AFTER_POTENTIAL_GC ();
1295 CASE (Bsymbol_value
):
1296 BEFORE_POTENTIAL_GC ();
1297 TOP
= Fsymbol_value (TOP
);
1298 AFTER_POTENTIAL_GC ();
1301 CASE (Bsymbol_function
):
1302 BEFORE_POTENTIAL_GC ();
1303 TOP
= Fsymbol_function (TOP
);
1304 AFTER_POTENTIAL_GC ();
1310 BEFORE_POTENTIAL_GC ();
1312 TOP
= Fset (TOP
, v1
);
1313 AFTER_POTENTIAL_GC ();
1320 BEFORE_POTENTIAL_GC ();
1322 TOP
= Ffset (TOP
, v1
);
1323 AFTER_POTENTIAL_GC ();
1330 BEFORE_POTENTIAL_GC ();
1332 TOP
= Fget (TOP
, v1
);
1333 AFTER_POTENTIAL_GC ();
1340 BEFORE_POTENTIAL_GC ();
1342 TOP
= Fsubstring (TOP
, v1
, v2
);
1343 AFTER_POTENTIAL_GC ();
1348 BEFORE_POTENTIAL_GC ();
1350 TOP
= Fconcat (2, &TOP
);
1351 AFTER_POTENTIAL_GC ();
1355 BEFORE_POTENTIAL_GC ();
1357 TOP
= Fconcat (3, &TOP
);
1358 AFTER_POTENTIAL_GC ();
1362 BEFORE_POTENTIAL_GC ();
1364 TOP
= Fconcat (4, &TOP
);
1365 AFTER_POTENTIAL_GC ();
1370 BEFORE_POTENTIAL_GC ();
1372 TOP
= Fconcat (op
, &TOP
);
1373 AFTER_POTENTIAL_GC ();
1382 XSETINT (v1
, XINT (v1
) - 1);
1387 BEFORE_POTENTIAL_GC ();
1389 AFTER_POTENTIAL_GC ();
1400 XSETINT (v1
, XINT (v1
) + 1);
1405 BEFORE_POTENTIAL_GC ();
1407 AFTER_POTENTIAL_GC ();
1415 BEFORE_POTENTIAL_GC ();
1417 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
1418 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
1419 AFTER_POTENTIAL_GC ();
1420 if (FLOATP (v1
) || FLOATP (v2
))
1424 f1
= (FLOATP (v1
) ? XFLOAT_DATA (v1
) : XINT (v1
));
1425 f2
= (FLOATP (v2
) ? XFLOAT_DATA (v2
) : XINT (v2
));
1426 TOP
= (f1
== f2
? Qt
: Qnil
);
1429 TOP
= (XINT (v1
) == XINT (v2
) ? Qt
: Qnil
);
1436 BEFORE_POTENTIAL_GC ();
1438 TOP
= arithcompare (TOP
, v1
, ARITH_GRTR
);
1439 AFTER_POTENTIAL_GC ();
1446 BEFORE_POTENTIAL_GC ();
1448 TOP
= arithcompare (TOP
, v1
, ARITH_LESS
);
1449 AFTER_POTENTIAL_GC ();
1456 BEFORE_POTENTIAL_GC ();
1458 TOP
= arithcompare (TOP
, v1
, ARITH_LESS_OR_EQUAL
);
1459 AFTER_POTENTIAL_GC ();
1466 BEFORE_POTENTIAL_GC ();
1468 TOP
= arithcompare (TOP
, v1
, ARITH_GRTR_OR_EQUAL
);
1469 AFTER_POTENTIAL_GC ();
1474 BEFORE_POTENTIAL_GC ();
1476 TOP
= Fminus (2, &TOP
);
1477 AFTER_POTENTIAL_GC ();
1486 XSETINT (v1
, - XINT (v1
));
1491 BEFORE_POTENTIAL_GC ();
1492 TOP
= Fminus (1, &TOP
);
1493 AFTER_POTENTIAL_GC ();
1499 BEFORE_POTENTIAL_GC ();
1501 TOP
= Fplus (2, &TOP
);
1502 AFTER_POTENTIAL_GC ();
1506 BEFORE_POTENTIAL_GC ();
1508 TOP
= Fmax (2, &TOP
);
1509 AFTER_POTENTIAL_GC ();
1513 BEFORE_POTENTIAL_GC ();
1515 TOP
= Fmin (2, &TOP
);
1516 AFTER_POTENTIAL_GC ();
1520 BEFORE_POTENTIAL_GC ();
1522 TOP
= Ftimes (2, &TOP
);
1523 AFTER_POTENTIAL_GC ();
1527 BEFORE_POTENTIAL_GC ();
1529 TOP
= Fquo (2, &TOP
);
1530 AFTER_POTENTIAL_GC ();
1536 BEFORE_POTENTIAL_GC ();
1538 TOP
= Frem (TOP
, v1
);
1539 AFTER_POTENTIAL_GC ();
1546 XSETFASTINT (v1
, PT
);
1552 BEFORE_POTENTIAL_GC ();
1553 TOP
= Fgoto_char (TOP
);
1554 AFTER_POTENTIAL_GC ();
1558 BEFORE_POTENTIAL_GC ();
1559 TOP
= Finsert (1, &TOP
);
1560 AFTER_POTENTIAL_GC ();
1565 BEFORE_POTENTIAL_GC ();
1567 TOP
= Finsert (op
, &TOP
);
1568 AFTER_POTENTIAL_GC ();
1574 XSETFASTINT (v1
, ZV
);
1582 XSETFASTINT (v1
, BEGV
);
1588 BEFORE_POTENTIAL_GC ();
1589 TOP
= Fchar_after (TOP
);
1590 AFTER_POTENTIAL_GC ();
1593 CASE (Bfollowing_char
):
1596 BEFORE_POTENTIAL_GC ();
1597 v1
= Ffollowing_char ();
1598 AFTER_POTENTIAL_GC ();
1603 CASE (Bpreceding_char
):
1606 BEFORE_POTENTIAL_GC ();
1607 v1
= Fprevious_char ();
1608 AFTER_POTENTIAL_GC ();
1613 CASE (Bcurrent_column
):
1616 BEFORE_POTENTIAL_GC ();
1617 XSETFASTINT (v1
, current_column ());
1618 AFTER_POTENTIAL_GC ();
1624 BEFORE_POTENTIAL_GC ();
1625 TOP
= Findent_to (TOP
, Qnil
);
1626 AFTER_POTENTIAL_GC ();
1645 CASE (Bcurrent_buffer
):
1646 PUSH (Fcurrent_buffer ());
1650 BEFORE_POTENTIAL_GC ();
1651 TOP
= Fset_buffer (TOP
);
1652 AFTER_POTENTIAL_GC ();
1655 CASE (Binteractive_p
): /* Obsolete since 24.1. */
1656 BEFORE_POTENTIAL_GC ();
1657 PUSH (call0 (intern ("interactive-p")));
1658 AFTER_POTENTIAL_GC ();
1661 CASE (Bforward_char
):
1662 BEFORE_POTENTIAL_GC ();
1663 TOP
= Fforward_char (TOP
);
1664 AFTER_POTENTIAL_GC ();
1667 CASE (Bforward_word
):
1668 BEFORE_POTENTIAL_GC ();
1669 TOP
= Fforward_word (TOP
);
1670 AFTER_POTENTIAL_GC ();
1673 CASE (Bskip_chars_forward
):
1676 BEFORE_POTENTIAL_GC ();
1678 TOP
= Fskip_chars_forward (TOP
, v1
);
1679 AFTER_POTENTIAL_GC ();
1683 CASE (Bskip_chars_backward
):
1686 BEFORE_POTENTIAL_GC ();
1688 TOP
= Fskip_chars_backward (TOP
, v1
);
1689 AFTER_POTENTIAL_GC ();
1693 CASE (Bforward_line
):
1694 BEFORE_POTENTIAL_GC ();
1695 TOP
= Fforward_line (TOP
);
1696 AFTER_POTENTIAL_GC ();
1699 CASE (Bchar_syntax
):
1703 BEFORE_POTENTIAL_GC ();
1704 CHECK_CHARACTER (TOP
);
1705 AFTER_POTENTIAL_GC ();
1707 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
1708 MAKE_CHAR_MULTIBYTE (c
);
1709 XSETFASTINT (TOP
, syntax_code_spec
[SYNTAX (c
)]);
1713 CASE (Bbuffer_substring
):
1716 BEFORE_POTENTIAL_GC ();
1718 TOP
= Fbuffer_substring (TOP
, v1
);
1719 AFTER_POTENTIAL_GC ();
1723 CASE (Bdelete_region
):
1726 BEFORE_POTENTIAL_GC ();
1728 TOP
= Fdelete_region (TOP
, v1
);
1729 AFTER_POTENTIAL_GC ();
1733 CASE (Bnarrow_to_region
):
1736 BEFORE_POTENTIAL_GC ();
1738 TOP
= Fnarrow_to_region (TOP
, v1
);
1739 AFTER_POTENTIAL_GC ();
1744 BEFORE_POTENTIAL_GC ();
1746 AFTER_POTENTIAL_GC ();
1749 CASE (Bend_of_line
):
1750 BEFORE_POTENTIAL_GC ();
1751 TOP
= Fend_of_line (TOP
);
1752 AFTER_POTENTIAL_GC ();
1758 BEFORE_POTENTIAL_GC ();
1761 TOP
= Fset_marker (TOP
, v2
, v1
);
1762 AFTER_POTENTIAL_GC ();
1766 CASE (Bmatch_beginning
):
1767 BEFORE_POTENTIAL_GC ();
1768 TOP
= Fmatch_beginning (TOP
);
1769 AFTER_POTENTIAL_GC ();
1773 BEFORE_POTENTIAL_GC ();
1774 TOP
= Fmatch_end (TOP
);
1775 AFTER_POTENTIAL_GC ();
1779 BEFORE_POTENTIAL_GC ();
1780 TOP
= Fupcase (TOP
);
1781 AFTER_POTENTIAL_GC ();
1785 BEFORE_POTENTIAL_GC ();
1786 TOP
= Fdowncase (TOP
);
1787 AFTER_POTENTIAL_GC ();
1790 CASE (Bstringeqlsign
):
1793 BEFORE_POTENTIAL_GC ();
1795 TOP
= Fstring_equal (TOP
, v1
);
1796 AFTER_POTENTIAL_GC ();
1803 BEFORE_POTENTIAL_GC ();
1805 TOP
= Fstring_lessp (TOP
, v1
);
1806 AFTER_POTENTIAL_GC ();
1814 TOP
= Fequal (TOP
, v1
);
1821 BEFORE_POTENTIAL_GC ();
1823 TOP
= Fnthcdr (TOP
, v1
);
1824 AFTER_POTENTIAL_GC ();
1833 /* Exchange args and then do nth. */
1835 BEFORE_POTENTIAL_GC ();
1839 AFTER_POTENTIAL_GC ();
1842 while (--n
>= 0 && CONSP (v1
))
1849 BEFORE_POTENTIAL_GC ();
1851 TOP
= Felt (TOP
, v1
);
1852 AFTER_POTENTIAL_GC ();
1860 BEFORE_POTENTIAL_GC ();
1862 TOP
= Fmember (TOP
, v1
);
1863 AFTER_POTENTIAL_GC ();
1870 BEFORE_POTENTIAL_GC ();
1872 TOP
= Fassq (TOP
, v1
);
1873 AFTER_POTENTIAL_GC ();
1878 BEFORE_POTENTIAL_GC ();
1879 TOP
= Fnreverse (TOP
);
1880 AFTER_POTENTIAL_GC ();
1886 BEFORE_POTENTIAL_GC ();
1888 TOP
= Fsetcar (TOP
, v1
);
1889 AFTER_POTENTIAL_GC ();
1896 BEFORE_POTENTIAL_GC ();
1898 TOP
= Fsetcdr (TOP
, v1
);
1899 AFTER_POTENTIAL_GC ();
1907 TOP
= CAR_SAFE (v1
);
1915 TOP
= CDR_SAFE (v1
);
1920 BEFORE_POTENTIAL_GC ();
1922 TOP
= Fnconc (2, &TOP
);
1923 AFTER_POTENTIAL_GC ();
1927 TOP
= (NUMBERP (TOP
) ? Qt
: Qnil
);
1931 TOP
= INTEGERP (TOP
) ? Qt
: Qnil
;
1934 #ifdef BYTE_CODE_SAFE
1935 /* These are intentionally written using 'case' syntax,
1936 because they are incompatible with the threaded
1940 BEFORE_POTENTIAL_GC ();
1941 error ("set-mark is an obsolete bytecode");
1942 AFTER_POTENTIAL_GC ();
1945 BEFORE_POTENTIAL_GC ();
1946 error ("scan-buffer is an obsolete bytecode");
1947 AFTER_POTENTIAL_GC ();
1952 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1953 for that instead. */
1954 /* CASE (Bstack_ref): */
1955 call3 (intern ("error"),
1956 build_string ("Invalid byte opcode: op=%s, ptr=%d"),
1958 make_number ((stack
.pc
- 1) - stack
.byte_string_start
));
1960 /* Handy byte-codes for lexical binding. */
1967 Lisp_Object
*ptr
= top
- (op
- Bstack_ref
);
1973 Lisp_Object
*ptr
= top
- (FETCH
);
1979 Lisp_Object
*ptr
= top
- (FETCH2
);
1984 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1986 Lisp_Object
*ptr
= top
- (FETCH
);
1992 Lisp_Object
*ptr
= top
- (FETCH2
);
2008 #ifdef BYTE_CODE_SAFE
2013 if ((op
-= Bconstant
) >= const_length
)
2019 PUSH (vectorp
[op
- Bconstant
]);
2027 byte_stack_list
= byte_stack_list
->next
;
2029 /* Binds and unbinds are supposed to be compiled balanced. */
2030 if (SPECPDL_INDEX () != count
)
2032 if (SPECPDL_INDEX () > count
)
2033 unbind_to (count
, Qnil
);
2034 error ("binding stack not balanced (serious byte compiler bug)");
2041 syms_of_bytecode (void)
2043 defsubr (&Sbyte_code
);
2045 #ifdef BYTE_CODE_METER
2047 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter
,
2048 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
2049 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
2050 opcode CODE has been executed.
2051 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
2052 indicates how many times the byte opcodes CODE1 and CODE2 have been
2053 executed in succession. */);
2055 DEFVAR_BOOL ("byte-metering-on", byte_metering_on
,
2056 doc
: /* If non-nil, keep profiling information on byte code usage.
2057 The variable byte-code-meter indicates how often each byte opcode is used.
2058 If a symbol has a property named `byte-code-meter' whose value is an
2059 integer, it is incremented each time that symbol's function is called. */);
2061 byte_metering_on
= 0;
2062 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
2063 DEFSYM (Qbyte_code_meter
, "byte-code-meter");
2067 ASET (Vbyte_code_meter
, i
,
2068 Fmake_vector (make_number (256), make_number (0)));