1 /* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985-1988, 1993, 2000-2014 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 */
297 /* Structure describing a value stack used during byte-code execution
302 /* Program counter. This points into the byte_string below
303 and is relocated when that string is relocated. */
304 const unsigned char *pc
;
306 /* The string containing the byte-code, and its current address.
307 Storing this here protects it from GC because mark_byte_stack
309 Lisp_Object byte_string
;
310 const unsigned char *byte_string_start
;
313 /* The vector of constants used during byte-code execution. Storing
314 this here protects it from GC because mark_byte_stack marks it. */
315 Lisp_Object constants
;
319 /* Fetch the next byte from the bytecode stream. */
321 #ifdef BYTE_CODE_SAFE
322 #define FETCH (eassert (stack.byte_string_start == SDATA (stack.byte_string)), *stack.pc++)
324 #define FETCH *stack.pc++
327 /* Fetch two bytes from the bytecode stream and make a 16-bit number
330 #define FETCH2 (op = FETCH, op + (FETCH << 8))
332 /* Push x onto the execution stack. This used to be #define PUSH(x)
333 (*++stackp = (x)) This oddity is necessary because Alliant can't be
334 bothered to compile the preincrement operator properly, as of 4/91.
337 #define PUSH(x) (top++, *top = (x))
339 /* Pop a value off the execution stack. */
343 /* Discard n values from the execution stack. */
345 #define DISCARD(n) (top -= (n))
347 /* Get the value which is at the top of the execution stack, but don't
352 /* Actions that must be performed before and after calling a function
355 #define BEFORE_POTENTIAL_GC() ((void)0)
356 #define AFTER_POTENTIAL_GC() ((void)0)
358 /* Garbage collect if we have consed enough since the last time.
359 We do this at every branch, to avoid loops that never GC. */
363 BEFORE_POTENTIAL_GC (); \
365 AFTER_POTENTIAL_GC (); \
368 /* Check for jumping out of range. */
370 #ifdef BYTE_CODE_SAFE
372 #define CHECK_RANGE(ARG) \
373 if (ARG >= bytestr_length) emacs_abort ()
375 #else /* not BYTE_CODE_SAFE */
377 #define CHECK_RANGE(ARG)
379 #endif /* not BYTE_CODE_SAFE */
381 /* A version of the QUIT macro which makes sure that the stack top is
382 set before signaling `quit'. */
384 #define BYTE_CODE_QUIT \
386 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
388 Lisp_Object flag = Vquit_flag; \
390 BEFORE_POTENTIAL_GC (); \
391 if (EQ (Vthrow_on_input, flag)) \
392 Fthrow (Vthrow_on_input, Qt); \
393 Fsignal (Qquit, Qnil); \
394 AFTER_POTENTIAL_GC (); \
396 else if (pending_signals) \
397 process_pending_signals (); \
401 DEFUN ("byte-code", Fbyte_code
, Sbyte_code
, 3, 3, 0,
402 doc
: /* Function used internally in byte-compiled code.
403 The first argument, BYTESTR, is a string of byte code;
404 the second, VECTOR, a vector of constants;
405 the third, MAXDEPTH, the maximum stack depth used in this function.
406 If the third argument is incorrect, Emacs may crash. */)
407 (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
)
409 return exec_byte_code (bytestr
, vector
, maxdepth
, Qnil
, 0, NULL
);
413 bcall0 (Lisp_Object f
)
418 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
419 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
420 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
421 argument list (including &rest, &optional, etc.), and ARGS, of size
422 NARGS, should be a vector of the actual arguments. The arguments in
423 ARGS are pushed on the stack according to ARGS_TEMPLATE before
424 executing BYTESTR. */
427 exec_byte_code (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
,
428 Lisp_Object args_template
, ptrdiff_t nargs
, Lisp_Object
*args
)
430 ptrdiff_t count
= SPECPDL_INDEX ();
431 #ifdef BYTE_CODE_METER
432 int volatile this_op
= 0;
436 /* Lisp_Object v1, v2; */
437 Lisp_Object
*vectorp
;
438 #ifdef BYTE_CODE_SAFE
439 ptrdiff_t const_length
;
441 ptrdiff_t bytestr_length
;
443 struct byte_stack stack
;
446 enum handlertype type
;
448 #if 0 /* CHECK_FRAME_FONT */
450 struct frame
*f
= SELECTED_FRAME ();
452 && FRAME_FONT (f
)->direction
!= 0
453 && FRAME_FONT (f
)->direction
!= 1)
458 CHECK_STRING (bytestr
);
459 CHECK_VECTOR (vector
);
460 CHECK_NATNUM (maxdepth
);
462 #ifdef BYTE_CODE_SAFE
463 const_length
= ASIZE (vector
);
466 if (STRING_MULTIBYTE (bytestr
))
467 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
468 because they produced a raw 8-bit string for byte-code and now
469 such a byte-code string is loaded as multibyte while raw 8-bit
470 characters converted to multibyte form. Thus, now we must
471 convert them back to the originally intended unibyte form. */
472 bytestr
= Fstring_as_unibyte (bytestr
);
474 #ifdef BYTE_CODE_SAFE
475 bytestr_length
= SBYTES (bytestr
);
477 vectorp
= XVECTOR (vector
)->contents
;
479 stack
.byte_string
= bytestr
;
480 stack
.pc
= stack
.byte_string_start
= SDATA (bytestr
);
482 stack
.constants
= vector
;
484 if (MAX_ALLOCA
/ word_size
<= XFASTINT (maxdepth
))
485 memory_full (SIZE_MAX
);
486 top
= alloca ((XFASTINT (maxdepth
) + 1) * sizeof *top
);
488 #ifdef BYTE_CODE_SAFE
489 stacke
= stack
.bottom
- 1 + XFASTINT (maxdepth
);
492 if (INTEGERP (args_template
))
494 ptrdiff_t at
= XINT (args_template
);
495 bool rest
= (at
& 128) != 0;
496 int mandatory
= at
& 127;
497 ptrdiff_t nonrest
= at
>> 8;
498 eassert (mandatory
<= nonrest
);
499 if (nargs
<= nonrest
)
502 for (i
= 0 ; i
< nargs
; i
++, args
++)
504 if (nargs
< mandatory
)
505 /* Too few arguments. */
506 Fsignal (Qwrong_number_of_arguments
,
507 list2 (Fcons (make_number (mandatory
),
508 rest
? Qand_rest
: make_number (nonrest
)),
509 make_number (nargs
)));
512 for (; i
< nonrest
; i
++)
521 for (i
= 0 ; i
< nonrest
; i
++, args
++)
523 PUSH (Flist (nargs
- nonrest
, args
));
526 /* Too many arguments. */
527 Fsignal (Qwrong_number_of_arguments
,
528 list2 (Fcons (make_number (mandatory
), make_number (nonrest
)),
529 make_number (nargs
)));
531 else if (! NILP (args_template
))
532 /* We should push some arguments on the stack. */
534 error ("Unknown args template!");
539 #ifdef BYTE_CODE_SAFE
542 else if (top
< stack
.bottom
- 1)
546 #ifdef BYTE_CODE_METER
548 this_op
= op
= FETCH
;
549 METER_CODE (prev_op
, op
);
551 #ifndef BYTE_CODE_THREADED
556 /* The interpreter can be compiled one of two ways: as an
557 ordinary switch-based interpreter, or as a threaded
558 interpreter. The threaded interpreter relies on GCC's
559 computed goto extension, so it is not available everywhere.
560 Threading provides a performance boost. These macros are how
561 we allow the code to be compiled both ways. */
562 #ifdef BYTE_CODE_THREADED
563 /* The CASE macro introduces an instruction's body. It is
564 either a label or a case label. */
565 #define CASE(OP) insn_ ## OP
566 /* NEXT is invoked at the end of an instruction to go to the
567 next instruction. It is either a computed goto, or a
569 #define NEXT goto *(targets[op = FETCH])
570 /* FIRST is like NEXT, but is only used at the start of the
571 interpreter body. In the switch-based interpreter it is the
572 switch, so the threaded definition must include a semicolon. */
574 /* Most cases are labeled with the CASE macro, above.
575 CASE_DEFAULT is one exception; it is used if the interpreter
576 being built requires a default case. The threaded
577 interpreter does not, because the dispatch table is
578 completely filled. */
580 /* This introduces an instruction that is known to call abort. */
581 #define CASE_ABORT CASE (Bstack_ref): CASE (default)
583 /* See above for the meaning of the various defines. */
584 #define CASE(OP) case OP
586 #define FIRST switch (op)
587 #define CASE_DEFAULT case 255: default:
588 #define CASE_ABORT case 0
591 #ifdef BYTE_CODE_THREADED
593 /* A convenience define that saves us a lot of typing and makes
594 the table clearer. */
595 #define LABEL(OP) [OP] = &&insn_ ## OP
597 #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
598 # pragma GCC diagnostic push
599 # pragma GCC diagnostic ignored "-Woverride-init"
600 #elif defined __clang__
601 # pragma GCC diagnostic push
602 # pragma GCC diagnostic ignored "-Winitializer-overrides"
605 /* This is the dispatch table for the threaded interpreter. */
606 static const void *const targets
[256] =
608 [0 ... (Bconstant
- 1)] = &&insn_default
,
609 [Bconstant
... 255] = &&insn_Bconstant
,
611 #define DEFINE(name, value) LABEL (name) ,
616 #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) || defined __clang__
617 # pragma GCC diagnostic pop
638 /* This seems to be the most frequently executed byte-code
639 among the Bvarref's, so avoid a goto here. */
649 if (XSYMBOL (v1
)->redirect
!= SYMBOL_PLAINVAL
650 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)),
653 BEFORE_POTENTIAL_GC ();
654 v2
= Fsymbol_value (v1
);
655 AFTER_POTENTIAL_GC ();
660 BEFORE_POTENTIAL_GC ();
661 v2
= Fsymbol_value (v1
);
662 AFTER_POTENTIAL_GC ();
678 stack
.pc
= stack
.byte_string_start
+ op
;
693 BEFORE_POTENTIAL_GC ();
694 wrong_type_argument (Qlistp
, v1
);
703 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
710 BEFORE_POTENTIAL_GC ();
712 TOP
= Fmemq (TOP
, v1
);
713 AFTER_POTENTIAL_GC ();
727 BEFORE_POTENTIAL_GC ();
728 wrong_type_argument (Qlistp
, v1
);
750 Lisp_Object sym
, val
;
755 /* Inline the most common case. */
757 && !EQ (val
, Qunbound
)
758 && !XSYMBOL (sym
)->redirect
759 && !SYMBOL_CONSTANT_P (sym
))
760 SET_SYMBOL_VAL (XSYMBOL (sym
), val
);
763 BEFORE_POTENTIAL_GC ();
764 set_internal (sym
, val
, Qnil
, 0);
765 AFTER_POTENTIAL_GC ();
779 /* ------------------ */
797 /* Specbind can signal and thus GC. */
798 BEFORE_POTENTIAL_GC ();
800 specbind (vectorp
[op
], POP
);
801 AFTER_POTENTIAL_GC ();
821 BEFORE_POTENTIAL_GC ();
823 #ifdef BYTE_CODE_METER
824 if (byte_metering_on
&& SYMBOLP (TOP
))
829 v2
= Fget (v1
, Qbyte_code_meter
);
831 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
833 XSETINT (v2
, XINT (v2
) + 1);
834 Fput (v1
, Qbyte_code_meter
, v2
);
838 TOP
= Ffuncall (op
+ 1, &TOP
);
839 AFTER_POTENTIAL_GC ();
859 BEFORE_POTENTIAL_GC ();
860 for (int i
= 0; i
< op
; i
++)
862 AFTER_POTENTIAL_GC ();
865 CASE (Bunbind_all
): /* Obsolete. Never used. */
872 op
= FETCH2
; /* pc = FETCH2 loses since FETCH2 contains pc++ */
874 stack
.pc
= stack
.byte_string_start
+ op
;
877 CASE (Bgotoifnonnil
):
887 stack
.pc
= stack
.byte_string_start
+ op
;
892 CASE (Bgotoifnilelsepop
):
899 stack
.pc
= stack
.byte_string_start
+ op
;
904 CASE (Bgotoifnonnilelsepop
):
911 stack
.pc
= stack
.byte_string_start
+ op
;
919 stack
.pc
+= (int) *stack
.pc
- 127;
930 stack
.pc
+= (int) *stack
.pc
- 128;
936 CASE (BRgotoifnonnil
):
944 stack
.pc
+= (int) *stack
.pc
- 128;
950 CASE (BRgotoifnilelsepop
):
956 stack
.pc
+= op
- 128;
961 CASE (BRgotoifnonnilelsepop
):
967 stack
.pc
+= op
- 128;
981 PUSH (vectorp
[FETCH2
]);
984 CASE (Bsave_excursion
):
986 record_unwind_protect (save_excursion_restore
,
987 save_excursion_save ());
990 CASE (Bsave_current_buffer
): /* Obsolete since ??. */
991 CASE (Bsave_current_buffer_1
):
993 record_unwind_current_buffer ();
996 CASE (Bsave_window_excursion
): /* Obsolete since 24.1. */
999 record_unwind_protect (restore_window_configuration
,
1000 Fcurrent_window_configuration (Qnil
));
1001 BEFORE_POTENTIAL_GC ();
1004 AFTER_POTENTIAL_GC ();
1008 CASE (Bsave_restriction
):
1010 record_unwind_protect (save_restriction_restore
,
1011 save_restriction_save ());
1014 CASE (Bcatch
): /* Obsolete since 24.4. */
1017 BEFORE_POTENTIAL_GC ();
1019 TOP
= internal_catch (TOP
, eval_sub
, v1
);
1020 AFTER_POTENTIAL_GC ();
1024 CASE (Bpushcatch
): /* New in 24.4. */
1027 CASE (Bpushconditioncase
): /* New in 24.4. */
1029 extern EMACS_INT lisp_eval_depth
;
1030 extern int poll_suppress_count
;
1031 extern int interrupt_input_blocked
;
1036 type
= CONDITION_CASE
;
1041 PUSH_HANDLER (c
, tag
, type
);
1042 c
->bytecode_dest
= dest
;
1043 c
->bytecode_top
= top
;
1045 if (sys_setjmp (c
->jmp
))
1047 struct handler
*c
= handlerlist
;
1049 top
= c
->bytecode_top
;
1050 dest
= c
->bytecode_dest
;
1051 handlerlist
= c
->next
;
1054 /* Might have been re-set by longjmp! */
1055 stack
.byte_string_start
= SDATA (stack
.byte_string
);
1056 stack
.pc
= stack
.byte_string_start
+ dest
;
1062 CASE (Bpophandler
): /* New in 24.4. */
1064 handlerlist
= handlerlist
->next
;
1068 CASE (Bunwind_protect
): /* FIXME: avoid closure for lexbind. */
1070 Lisp_Object handler
= POP
;
1072 /* Support for a function here is new in 24.4. */
1073 record_unwind_protect (NILP (Ffunctionp (handler
))
1074 ? unwind_body
: bcall0
,
1079 CASE (Bcondition_case
): /* Obsolete since 24.4. */
1081 Lisp_Object handlers
, body
;
1084 BEFORE_POTENTIAL_GC ();
1085 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
);
1086 AFTER_POTENTIAL_GC ();
1090 CASE (Btemp_output_buffer_setup
): /* Obsolete since 24.1. */
1091 BEFORE_POTENTIAL_GC ();
1094 temp_output_buffer_setup (SSDATA (TOP
));
1095 AFTER_POTENTIAL_GC ();
1096 TOP
= Vstandard_output
;
1099 CASE (Btemp_output_buffer_show
): /* Obsolete since 24.1. */
1102 BEFORE_POTENTIAL_GC ();
1104 temp_output_buffer_show (TOP
);
1106 /* pop binding of standard-output */
1108 AFTER_POTENTIAL_GC ();
1116 BEFORE_POTENTIAL_GC ();
1122 while (--n
>= 0 && CONSP (v1
))
1126 AFTER_POTENTIAL_GC ();
1131 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
1135 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
1139 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
1143 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
1147 TOP
= NILP (TOP
) ? Qt
: Qnil
;
1154 TOP
= Fcons (TOP
, v1
);
1166 TOP
= list2 (TOP
, v1
);
1172 TOP
= Flist (3, &TOP
);
1177 TOP
= Flist (4, &TOP
);
1183 TOP
= Flist (op
, &TOP
);
1187 BEFORE_POTENTIAL_GC ();
1188 TOP
= Flength (TOP
);
1189 AFTER_POTENTIAL_GC ();
1195 BEFORE_POTENTIAL_GC ();
1197 TOP
= Faref (TOP
, v1
);
1198 AFTER_POTENTIAL_GC ();
1205 BEFORE_POTENTIAL_GC ();
1207 TOP
= Faset (TOP
, v1
, v2
);
1208 AFTER_POTENTIAL_GC ();
1212 CASE (Bsymbol_value
):
1213 BEFORE_POTENTIAL_GC ();
1214 TOP
= Fsymbol_value (TOP
);
1215 AFTER_POTENTIAL_GC ();
1218 CASE (Bsymbol_function
):
1219 BEFORE_POTENTIAL_GC ();
1220 TOP
= Fsymbol_function (TOP
);
1221 AFTER_POTENTIAL_GC ();
1227 BEFORE_POTENTIAL_GC ();
1229 TOP
= Fset (TOP
, v1
);
1230 AFTER_POTENTIAL_GC ();
1237 BEFORE_POTENTIAL_GC ();
1239 TOP
= Ffset (TOP
, v1
);
1240 AFTER_POTENTIAL_GC ();
1247 BEFORE_POTENTIAL_GC ();
1249 TOP
= Fget (TOP
, v1
);
1250 AFTER_POTENTIAL_GC ();
1257 BEFORE_POTENTIAL_GC ();
1259 TOP
= Fsubstring (TOP
, v1
, v2
);
1260 AFTER_POTENTIAL_GC ();
1265 BEFORE_POTENTIAL_GC ();
1267 TOP
= Fconcat (2, &TOP
);
1268 AFTER_POTENTIAL_GC ();
1272 BEFORE_POTENTIAL_GC ();
1274 TOP
= Fconcat (3, &TOP
);
1275 AFTER_POTENTIAL_GC ();
1279 BEFORE_POTENTIAL_GC ();
1281 TOP
= Fconcat (4, &TOP
);
1282 AFTER_POTENTIAL_GC ();
1287 BEFORE_POTENTIAL_GC ();
1289 TOP
= Fconcat (op
, &TOP
);
1290 AFTER_POTENTIAL_GC ();
1299 XSETINT (v1
, XINT (v1
) - 1);
1304 BEFORE_POTENTIAL_GC ();
1306 AFTER_POTENTIAL_GC ();
1317 XSETINT (v1
, XINT (v1
) + 1);
1322 BEFORE_POTENTIAL_GC ();
1324 AFTER_POTENTIAL_GC ();
1332 BEFORE_POTENTIAL_GC ();
1334 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
1335 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
1336 AFTER_POTENTIAL_GC ();
1337 if (FLOATP (v1
) || FLOATP (v2
))
1341 f1
= (FLOATP (v1
) ? XFLOAT_DATA (v1
) : XINT (v1
));
1342 f2
= (FLOATP (v2
) ? XFLOAT_DATA (v2
) : XINT (v2
));
1343 TOP
= (f1
== f2
? Qt
: Qnil
);
1346 TOP
= (XINT (v1
) == XINT (v2
) ? Qt
: Qnil
);
1353 BEFORE_POTENTIAL_GC ();
1355 TOP
= arithcompare (TOP
, v1
, ARITH_GRTR
);
1356 AFTER_POTENTIAL_GC ();
1363 BEFORE_POTENTIAL_GC ();
1365 TOP
= arithcompare (TOP
, v1
, ARITH_LESS
);
1366 AFTER_POTENTIAL_GC ();
1373 BEFORE_POTENTIAL_GC ();
1375 TOP
= arithcompare (TOP
, v1
, ARITH_LESS_OR_EQUAL
);
1376 AFTER_POTENTIAL_GC ();
1383 BEFORE_POTENTIAL_GC ();
1385 TOP
= arithcompare (TOP
, v1
, ARITH_GRTR_OR_EQUAL
);
1386 AFTER_POTENTIAL_GC ();
1391 BEFORE_POTENTIAL_GC ();
1393 TOP
= Fminus (2, &TOP
);
1394 AFTER_POTENTIAL_GC ();
1403 XSETINT (v1
, - XINT (v1
));
1408 BEFORE_POTENTIAL_GC ();
1409 TOP
= Fminus (1, &TOP
);
1410 AFTER_POTENTIAL_GC ();
1416 BEFORE_POTENTIAL_GC ();
1418 TOP
= Fplus (2, &TOP
);
1419 AFTER_POTENTIAL_GC ();
1423 BEFORE_POTENTIAL_GC ();
1425 TOP
= Fmax (2, &TOP
);
1426 AFTER_POTENTIAL_GC ();
1430 BEFORE_POTENTIAL_GC ();
1432 TOP
= Fmin (2, &TOP
);
1433 AFTER_POTENTIAL_GC ();
1437 BEFORE_POTENTIAL_GC ();
1439 TOP
= Ftimes (2, &TOP
);
1440 AFTER_POTENTIAL_GC ();
1444 BEFORE_POTENTIAL_GC ();
1446 TOP
= Fquo (2, &TOP
);
1447 AFTER_POTENTIAL_GC ();
1453 BEFORE_POTENTIAL_GC ();
1455 TOP
= Frem (TOP
, v1
);
1456 AFTER_POTENTIAL_GC ();
1463 XSETFASTINT (v1
, PT
);
1469 BEFORE_POTENTIAL_GC ();
1470 TOP
= Fgoto_char (TOP
);
1471 AFTER_POTENTIAL_GC ();
1475 BEFORE_POTENTIAL_GC ();
1476 TOP
= Finsert (1, &TOP
);
1477 AFTER_POTENTIAL_GC ();
1482 BEFORE_POTENTIAL_GC ();
1484 TOP
= Finsert (op
, &TOP
);
1485 AFTER_POTENTIAL_GC ();
1491 XSETFASTINT (v1
, ZV
);
1499 XSETFASTINT (v1
, BEGV
);
1505 BEFORE_POTENTIAL_GC ();
1506 TOP
= Fchar_after (TOP
);
1507 AFTER_POTENTIAL_GC ();
1510 CASE (Bfollowing_char
):
1513 BEFORE_POTENTIAL_GC ();
1514 v1
= Ffollowing_char ();
1515 AFTER_POTENTIAL_GC ();
1520 CASE (Bpreceding_char
):
1523 BEFORE_POTENTIAL_GC ();
1524 v1
= Fprevious_char ();
1525 AFTER_POTENTIAL_GC ();
1530 CASE (Bcurrent_column
):
1533 BEFORE_POTENTIAL_GC ();
1534 XSETFASTINT (v1
, current_column ());
1535 AFTER_POTENTIAL_GC ();
1541 BEFORE_POTENTIAL_GC ();
1542 TOP
= Findent_to (TOP
, Qnil
);
1543 AFTER_POTENTIAL_GC ();
1562 CASE (Bcurrent_buffer
):
1563 PUSH (Fcurrent_buffer ());
1567 BEFORE_POTENTIAL_GC ();
1568 TOP
= Fset_buffer (TOP
);
1569 AFTER_POTENTIAL_GC ();
1572 CASE (Binteractive_p
): /* Obsolete since 24.1. */
1573 BEFORE_POTENTIAL_GC ();
1574 PUSH (call0 (intern ("interactive-p")));
1575 AFTER_POTENTIAL_GC ();
1578 CASE (Bforward_char
):
1579 BEFORE_POTENTIAL_GC ();
1580 TOP
= Fforward_char (TOP
);
1581 AFTER_POTENTIAL_GC ();
1584 CASE (Bforward_word
):
1585 BEFORE_POTENTIAL_GC ();
1586 TOP
= Fforward_word (TOP
);
1587 AFTER_POTENTIAL_GC ();
1590 CASE (Bskip_chars_forward
):
1593 BEFORE_POTENTIAL_GC ();
1595 TOP
= Fskip_chars_forward (TOP
, v1
);
1596 AFTER_POTENTIAL_GC ();
1600 CASE (Bskip_chars_backward
):
1603 BEFORE_POTENTIAL_GC ();
1605 TOP
= Fskip_chars_backward (TOP
, v1
);
1606 AFTER_POTENTIAL_GC ();
1610 CASE (Bforward_line
):
1611 BEFORE_POTENTIAL_GC ();
1612 TOP
= Fforward_line (TOP
);
1613 AFTER_POTENTIAL_GC ();
1616 CASE (Bchar_syntax
):
1620 BEFORE_POTENTIAL_GC ();
1621 CHECK_CHARACTER (TOP
);
1622 AFTER_POTENTIAL_GC ();
1624 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
1625 MAKE_CHAR_MULTIBYTE (c
);
1626 XSETFASTINT (TOP
, syntax_code_spec
[SYNTAX (c
)]);
1630 CASE (Bbuffer_substring
):
1633 BEFORE_POTENTIAL_GC ();
1635 TOP
= Fbuffer_substring (TOP
, v1
);
1636 AFTER_POTENTIAL_GC ();
1640 CASE (Bdelete_region
):
1643 BEFORE_POTENTIAL_GC ();
1645 TOP
= Fdelete_region (TOP
, v1
);
1646 AFTER_POTENTIAL_GC ();
1650 CASE (Bnarrow_to_region
):
1653 BEFORE_POTENTIAL_GC ();
1655 TOP
= Fnarrow_to_region (TOP
, v1
);
1656 AFTER_POTENTIAL_GC ();
1661 BEFORE_POTENTIAL_GC ();
1663 AFTER_POTENTIAL_GC ();
1666 CASE (Bend_of_line
):
1667 BEFORE_POTENTIAL_GC ();
1668 TOP
= Fend_of_line (TOP
);
1669 AFTER_POTENTIAL_GC ();
1675 BEFORE_POTENTIAL_GC ();
1678 TOP
= Fset_marker (TOP
, v2
, v1
);
1679 AFTER_POTENTIAL_GC ();
1683 CASE (Bmatch_beginning
):
1684 BEFORE_POTENTIAL_GC ();
1685 TOP
= Fmatch_beginning (TOP
);
1686 AFTER_POTENTIAL_GC ();
1690 BEFORE_POTENTIAL_GC ();
1691 TOP
= Fmatch_end (TOP
);
1692 AFTER_POTENTIAL_GC ();
1696 BEFORE_POTENTIAL_GC ();
1697 TOP
= Fupcase (TOP
);
1698 AFTER_POTENTIAL_GC ();
1702 BEFORE_POTENTIAL_GC ();
1703 TOP
= Fdowncase (TOP
);
1704 AFTER_POTENTIAL_GC ();
1707 CASE (Bstringeqlsign
):
1710 BEFORE_POTENTIAL_GC ();
1712 TOP
= Fstring_equal (TOP
, v1
);
1713 AFTER_POTENTIAL_GC ();
1720 BEFORE_POTENTIAL_GC ();
1722 TOP
= Fstring_lessp (TOP
, v1
);
1723 AFTER_POTENTIAL_GC ();
1731 TOP
= Fequal (TOP
, v1
);
1738 BEFORE_POTENTIAL_GC ();
1740 TOP
= Fnthcdr (TOP
, v1
);
1741 AFTER_POTENTIAL_GC ();
1750 /* Exchange args and then do nth. */
1752 BEFORE_POTENTIAL_GC ();
1756 AFTER_POTENTIAL_GC ();
1759 while (--n
>= 0 && CONSP (v1
))
1766 BEFORE_POTENTIAL_GC ();
1768 TOP
= Felt (TOP
, v1
);
1769 AFTER_POTENTIAL_GC ();
1777 BEFORE_POTENTIAL_GC ();
1779 TOP
= Fmember (TOP
, v1
);
1780 AFTER_POTENTIAL_GC ();
1787 BEFORE_POTENTIAL_GC ();
1789 TOP
= Fassq (TOP
, v1
);
1790 AFTER_POTENTIAL_GC ();
1795 BEFORE_POTENTIAL_GC ();
1796 TOP
= Fnreverse (TOP
);
1797 AFTER_POTENTIAL_GC ();
1803 BEFORE_POTENTIAL_GC ();
1805 TOP
= Fsetcar (TOP
, v1
);
1806 AFTER_POTENTIAL_GC ();
1813 BEFORE_POTENTIAL_GC ();
1815 TOP
= Fsetcdr (TOP
, v1
);
1816 AFTER_POTENTIAL_GC ();
1824 TOP
= CAR_SAFE (v1
);
1832 TOP
= CDR_SAFE (v1
);
1837 BEFORE_POTENTIAL_GC ();
1839 TOP
= Fnconc (2, &TOP
);
1840 AFTER_POTENTIAL_GC ();
1844 TOP
= (NUMBERP (TOP
) ? Qt
: Qnil
);
1848 TOP
= INTEGERP (TOP
) ? Qt
: Qnil
;
1851 #ifdef BYTE_CODE_SAFE
1852 /* These are intentionally written using 'case' syntax,
1853 because they are incompatible with the threaded
1857 BEFORE_POTENTIAL_GC ();
1858 error ("set-mark is an obsolete bytecode");
1859 AFTER_POTENTIAL_GC ();
1862 BEFORE_POTENTIAL_GC ();
1863 error ("scan-buffer is an obsolete bytecode");
1864 AFTER_POTENTIAL_GC ();
1869 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1870 for that instead. */
1871 /* CASE (Bstack_ref): */
1872 call3 (intern ("error"),
1873 build_string ("Invalid byte opcode: op=%s, ptr=%d"),
1875 make_number ((stack
.pc
- 1) - stack
.byte_string_start
));
1877 /* Handy byte-codes for lexical binding. */
1884 Lisp_Object
*ptr
= top
- (op
- Bstack_ref
);
1890 Lisp_Object
*ptr
= top
- (FETCH
);
1896 Lisp_Object
*ptr
= top
- (FETCH2
);
1901 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1903 Lisp_Object
*ptr
= top
- (FETCH
);
1909 Lisp_Object
*ptr
= top
- (FETCH2
);
1925 #ifdef BYTE_CODE_SAFE
1930 if ((op
-= Bconstant
) >= const_length
)
1936 PUSH (vectorp
[op
- Bconstant
]);
1944 /* Binds and unbinds are supposed to be compiled balanced. */
1945 if (SPECPDL_INDEX () != count
)
1947 if (SPECPDL_INDEX () > count
)
1948 unbind_to (count
, Qnil
);
1949 error ("binding stack not balanced (serious byte compiler bug)");
1956 syms_of_bytecode (void)
1958 #include "bytecode.x"
1960 #ifdef BYTE_CODE_METER
1962 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter
,
1963 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
1964 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1965 opcode CODE has been executed.
1966 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1967 indicates how many times the byte opcodes CODE1 and CODE2 have been
1968 executed in succession. */);
1970 DEFVAR_BOOL ("byte-metering-on", byte_metering_on
,
1971 doc
: /* If non-nil, keep profiling information on byte code usage.
1972 The variable byte-code-meter indicates how often each byte opcode is used.
1973 If a symbol has a property named `byte-code-meter' whose value is an
1974 integer, it is incremented each time that symbol's function is called. */);
1976 byte_metering_on
= 0;
1977 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
1978 DEFSYM (Qbyte_code_meter
, "byte-code-meter");
1982 ASET (Vbyte_code_meter
, i
,
1983 Fmake_vector (make_number (256), make_number (0)));