1 /* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985-1988, 1993, 2000-2016 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 (at
10 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/>. */
23 #include "blockinput.h"
24 #include "character.h"
30 #ifdef CHECK_FRAME_FONT
35 /* Work around GCC bug 54561. */
36 #if GNUC_PREREQ (4, 3, 0)
37 # pragma GCC diagnostic ignored "-Wclobbered"
41 * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for
42 * debugging the byte compiler...)
44 * define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
46 /* #define BYTE_CODE_SAFE */
47 /* #define BYTE_CODE_METER */
49 /* If BYTE_CODE_THREADED is defined, then the interpreter will be
50 indirect threaded, using GCC's computed goto extension. This code,
51 as currently implemented, is incompatible with BYTE_CODE_SAFE and
53 #if (defined __GNUC__ && !defined __STRICT_ANSI__ \
54 && !defined BYTE_CODE_SAFE && !defined BYTE_CODE_METER)
55 #define BYTE_CODE_THREADED
59 #ifdef BYTE_CODE_METER
61 #define METER_2(code1, code2) AREF (AREF (Vbyte_code_meter, code1), code2)
62 #define METER_1(code) METER_2 (0, code)
64 #define METER_CODE(last_code, this_code) \
66 if (byte_metering_on) \
68 if (XFASTINT (METER_1 (this_code)) < MOST_POSITIVE_FIXNUM) \
69 XSETFASTINT (METER_1 (this_code), \
70 XFASTINT (METER_1 (this_code)) + 1); \
72 && (XFASTINT (METER_2 (last_code, this_code)) \
73 < MOST_POSITIVE_FIXNUM)) \
74 XSETFASTINT (METER_2 (last_code, this_code), \
75 XFASTINT (METER_2 (last_code, this_code)) + 1); \
79 #endif /* BYTE_CODE_METER */
85 DEFINE (Bstack_ref, 0) /* Actually, Bstack_ref+0 is not implemented: use dup. */ \
86 DEFINE (Bstack_ref1, 1) \
87 DEFINE (Bstack_ref2, 2) \
88 DEFINE (Bstack_ref3, 3) \
89 DEFINE (Bstack_ref4, 4) \
90 DEFINE (Bstack_ref5, 5) \
91 DEFINE (Bstack_ref6, 6) \
92 DEFINE (Bstack_ref7, 7) \
93 DEFINE (Bvarref, 010) \
94 DEFINE (Bvarref1, 011) \
95 DEFINE (Bvarref2, 012) \
96 DEFINE (Bvarref3, 013) \
97 DEFINE (Bvarref4, 014) \
98 DEFINE (Bvarref5, 015) \
99 DEFINE (Bvarref6, 016) \
100 DEFINE (Bvarref7, 017) \
101 DEFINE (Bvarset, 020) \
102 DEFINE (Bvarset1, 021) \
103 DEFINE (Bvarset2, 022) \
104 DEFINE (Bvarset3, 023) \
105 DEFINE (Bvarset4, 024) \
106 DEFINE (Bvarset5, 025) \
107 DEFINE (Bvarset6, 026) \
108 DEFINE (Bvarset7, 027) \
109 DEFINE (Bvarbind, 030) \
110 DEFINE (Bvarbind1, 031) \
111 DEFINE (Bvarbind2, 032) \
112 DEFINE (Bvarbind3, 033) \
113 DEFINE (Bvarbind4, 034) \
114 DEFINE (Bvarbind5, 035) \
115 DEFINE (Bvarbind6, 036) \
116 DEFINE (Bvarbind7, 037) \
117 DEFINE (Bcall, 040) \
118 DEFINE (Bcall1, 041) \
119 DEFINE (Bcall2, 042) \
120 DEFINE (Bcall3, 043) \
121 DEFINE (Bcall4, 044) \
122 DEFINE (Bcall5, 045) \
123 DEFINE (Bcall6, 046) \
124 DEFINE (Bcall7, 047) \
125 DEFINE (Bunbind, 050) \
126 DEFINE (Bunbind1, 051) \
127 DEFINE (Bunbind2, 052) \
128 DEFINE (Bunbind3, 053) \
129 DEFINE (Bunbind4, 054) \
130 DEFINE (Bunbind5, 055) \
131 DEFINE (Bunbind6, 056) \
132 DEFINE (Bunbind7, 057) \
134 DEFINE (Bpophandler, 060) \
135 DEFINE (Bpushconditioncase, 061) \
136 DEFINE (Bpushcatch, 062) \
139 DEFINE (Bsymbolp, 071) \
140 DEFINE (Bconsp, 072) \
141 DEFINE (Bstringp, 073) \
142 DEFINE (Blistp, 074) \
144 DEFINE (Bmemq, 076) \
146 DEFINE (Bcar, 0100) \
147 DEFINE (Bcdr, 0101) \
148 DEFINE (Bcons, 0102) \
149 DEFINE (Blist1, 0103) \
150 DEFINE (Blist2, 0104) \
151 DEFINE (Blist3, 0105) \
152 DEFINE (Blist4, 0106) \
153 DEFINE (Blength, 0107) \
154 DEFINE (Baref, 0110) \
155 DEFINE (Baset, 0111) \
156 DEFINE (Bsymbol_value, 0112) \
157 DEFINE (Bsymbol_function, 0113) \
158 DEFINE (Bset, 0114) \
159 DEFINE (Bfset, 0115) \
160 DEFINE (Bget, 0116) \
161 DEFINE (Bsubstring, 0117) \
162 DEFINE (Bconcat2, 0120) \
163 DEFINE (Bconcat3, 0121) \
164 DEFINE (Bconcat4, 0122) \
165 DEFINE (Bsub1, 0123) \
166 DEFINE (Badd1, 0124) \
167 DEFINE (Beqlsign, 0125) \
168 DEFINE (Bgtr, 0126) \
169 DEFINE (Blss, 0127) \
170 DEFINE (Bleq, 0130) \
171 DEFINE (Bgeq, 0131) \
172 DEFINE (Bdiff, 0132) \
173 DEFINE (Bnegate, 0133) \
174 DEFINE (Bplus, 0134) \
175 DEFINE (Bmax, 0135) \
176 DEFINE (Bmin, 0136) \
177 DEFINE (Bmult, 0137) \
179 DEFINE (Bpoint, 0140) \
180 /* Was Bmark in v17. */ \
181 DEFINE (Bsave_current_buffer, 0141) /* Obsolete. */ \
182 DEFINE (Bgoto_char, 0142) \
183 DEFINE (Binsert, 0143) \
184 DEFINE (Bpoint_max, 0144) \
185 DEFINE (Bpoint_min, 0145) \
186 DEFINE (Bchar_after, 0146) \
187 DEFINE (Bfollowing_char, 0147) \
188 DEFINE (Bpreceding_char, 0150) \
189 DEFINE (Bcurrent_column, 0151) \
190 DEFINE (Bindent_to, 0152) \
191 DEFINE (Beolp, 0154) \
192 DEFINE (Beobp, 0155) \
193 DEFINE (Bbolp, 0156) \
194 DEFINE (Bbobp, 0157) \
195 DEFINE (Bcurrent_buffer, 0160) \
196 DEFINE (Bset_buffer, 0161) \
197 DEFINE (Bsave_current_buffer_1, 0162) /* Replacing Bsave_current_buffer. */ \
198 DEFINE (Binteractive_p, 0164) /* Obsolete since Emacs-24.1. */ \
200 DEFINE (Bforward_char, 0165) \
201 DEFINE (Bforward_word, 0166) \
202 DEFINE (Bskip_chars_forward, 0167) \
203 DEFINE (Bskip_chars_backward, 0170) \
204 DEFINE (Bforward_line, 0171) \
205 DEFINE (Bchar_syntax, 0172) \
206 DEFINE (Bbuffer_substring, 0173) \
207 DEFINE (Bdelete_region, 0174) \
208 DEFINE (Bnarrow_to_region, 0175) \
209 DEFINE (Bwiden, 0176) \
210 DEFINE (Bend_of_line, 0177) \
212 DEFINE (Bconstant2, 0201) \
213 DEFINE (Bgoto, 0202) \
214 DEFINE (Bgotoifnil, 0203) \
215 DEFINE (Bgotoifnonnil, 0204) \
216 DEFINE (Bgotoifnilelsepop, 0205) \
217 DEFINE (Bgotoifnonnilelsepop, 0206) \
218 DEFINE (Breturn, 0207) \
219 DEFINE (Bdiscard, 0210) \
220 DEFINE (Bdup, 0211) \
222 DEFINE (Bsave_excursion, 0212) \
223 DEFINE (Bsave_window_excursion, 0213) /* Obsolete since Emacs-24.1. */ \
224 DEFINE (Bsave_restriction, 0214) \
225 DEFINE (Bcatch, 0215) \
227 DEFINE (Bunwind_protect, 0216) \
228 DEFINE (Bcondition_case, 0217) \
229 DEFINE (Btemp_output_buffer_setup, 0220) /* Obsolete since Emacs-24.1. */ \
230 DEFINE (Btemp_output_buffer_show, 0221) /* Obsolete since Emacs-24.1. */ \
232 DEFINE (Bunbind_all, 0222) /* Obsolete. Never used. */ \
234 DEFINE (Bset_marker, 0223) \
235 DEFINE (Bmatch_beginning, 0224) \
236 DEFINE (Bmatch_end, 0225) \
237 DEFINE (Bupcase, 0226) \
238 DEFINE (Bdowncase, 0227) \
240 DEFINE (Bstringeqlsign, 0230) \
241 DEFINE (Bstringlss, 0231) \
242 DEFINE (Bequal, 0232) \
243 DEFINE (Bnthcdr, 0233) \
244 DEFINE (Belt, 0234) \
245 DEFINE (Bmember, 0235) \
246 DEFINE (Bassq, 0236) \
247 DEFINE (Bnreverse, 0237) \
248 DEFINE (Bsetcar, 0240) \
249 DEFINE (Bsetcdr, 0241) \
250 DEFINE (Bcar_safe, 0242) \
251 DEFINE (Bcdr_safe, 0243) \
252 DEFINE (Bnconc, 0244) \
253 DEFINE (Bquo, 0245) \
254 DEFINE (Brem, 0246) \
255 DEFINE (Bnumberp, 0247) \
256 DEFINE (Bintegerp, 0250) \
258 DEFINE (BRgoto, 0252) \
259 DEFINE (BRgotoifnil, 0253) \
260 DEFINE (BRgotoifnonnil, 0254) \
261 DEFINE (BRgotoifnilelsepop, 0255) \
262 DEFINE (BRgotoifnonnilelsepop, 0256) \
264 DEFINE (BlistN, 0257) \
265 DEFINE (BconcatN, 0260) \
266 DEFINE (BinsertN, 0261) \
268 /* Bstack_ref is code 0. */ \
269 DEFINE (Bstack_set, 0262) \
270 DEFINE (Bstack_set2, 0263) \
271 DEFINE (BdiscardN, 0266) \
273 DEFINE (Bconstant, 0300)
277 #define DEFINE(name, value) name = value,
281 #ifdef BYTE_CODE_SAFE
282 Bscan_buffer
= 0153, /* No longer generated as of v18. */
283 Bset_mark
= 0163, /* this loser is no longer generated as of v18 */
287 /* Structure describing a value stack used during byte-code execution
292 /* Program counter. This points into the byte_string below
293 and is relocated when that string is relocated. */
294 const unsigned char *pc
;
296 /* The string containing the byte-code, and its current address.
297 Storing this here protects it from GC. */
298 Lisp_Object byte_string
;
299 const unsigned char *byte_string_start
;
301 /* Next entry in byte_stack_list. */
302 struct byte_stack
*next
;
305 /* A list of currently active byte-code execution value stacks.
306 Fbyte_code adds an entry to the head of this list before it starts
307 processing byte-code, and it removes the entry again when it is
308 done. Signaling an error truncates the list. */
310 struct byte_stack
*byte_stack_list
;
313 /* Relocate program counters in the stacks on byte_stack_list. Called
314 when GC has completed. */
317 relocate_byte_stack (void)
319 struct byte_stack
*stack
;
321 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
323 if (stack
->byte_string_start
!= SDATA (stack
->byte_string
))
325 ptrdiff_t offset
= stack
->pc
- stack
->byte_string_start
;
326 stack
->byte_string_start
= SDATA (stack
->byte_string
);
327 stack
->pc
= stack
->byte_string_start
+ offset
;
333 /* Fetch the next byte from the bytecode stream. */
335 #ifdef BYTE_CODE_SAFE
336 #define FETCH (eassert (stack.byte_string_start == SDATA (stack.byte_string)), *stack.pc++)
338 #define FETCH *stack.pc++
341 /* Fetch two bytes from the bytecode stream and make a 16-bit number
344 #define FETCH2 (op = FETCH, op + (FETCH << 8))
346 /* Push X onto the execution stack. The expression X should not
347 contain TOP, to avoid competing side effects. */
349 #define PUSH(x) (*++top = (x))
351 /* Pop a value off the execution stack. */
355 /* Discard n values from the execution stack. */
357 #define DISCARD(n) (top -= (n))
359 /* Get the value which is at the top of the execution stack, but don't
364 /* Check for jumping out of range. */
366 #ifdef BYTE_CODE_SAFE
368 #define CHECK_RANGE(ARG) \
369 if (ARG >= bytestr_length) emacs_abort ()
371 #else /* not BYTE_CODE_SAFE */
373 #define CHECK_RANGE(ARG)
375 #endif /* not BYTE_CODE_SAFE */
377 /* A version of the QUIT macro which makes sure that the stack top is
378 set before signaling `quit'. */
380 #define BYTE_CODE_QUIT \
382 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
384 Lisp_Object flag = Vquit_flag; \
386 if (EQ (Vthrow_on_input, flag)) \
387 Fthrow (Vthrow_on_input, Qt); \
388 Fsignal (Qquit, Qnil); \
390 else if (pending_signals) \
391 process_pending_signals (); \
395 DEFUN ("byte-code", Fbyte_code
, Sbyte_code
, 3, 3, 0,
396 doc
: /* Function used internally in byte-compiled code.
397 The first argument, BYTESTR, is a string of byte code;
398 the second, VECTOR, a vector of constants;
399 the third, MAXDEPTH, the maximum stack depth used in this function.
400 If the third argument is incorrect, Emacs may crash. */)
401 (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
)
403 return exec_byte_code (bytestr
, vector
, maxdepth
, Qnil
, 0, NULL
);
407 bcall0 (Lisp_Object f
)
412 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
413 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
414 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
415 argument list (including &rest, &optional, etc.), and ARGS, of size
416 NARGS, should be a vector of the actual arguments. The arguments in
417 ARGS are pushed on the stack according to ARGS_TEMPLATE before
418 executing BYTESTR. */
421 exec_byte_code (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
,
422 Lisp_Object args_template
, ptrdiff_t nargs
, Lisp_Object
*args
)
424 ptrdiff_t count
= SPECPDL_INDEX ();
425 #ifdef BYTE_CODE_METER
426 int volatile this_op
= 0;
430 /* Lisp_Object v1, v2; */
431 Lisp_Object
*vectorp
;
432 #ifdef BYTE_CODE_SAFE
433 ptrdiff_t const_length
;
435 ptrdiff_t bytestr_length
;
437 struct byte_stack stack
;
440 enum handlertype type
;
442 #if 0 /* CHECK_FRAME_FONT */
444 struct frame
*f
= SELECTED_FRAME ();
446 && FRAME_FONT (f
)->direction
!= 0
447 && FRAME_FONT (f
)->direction
!= 1)
452 CHECK_STRING (bytestr
);
453 CHECK_VECTOR (vector
);
454 CHECK_NATNUM (maxdepth
);
456 #ifdef BYTE_CODE_SAFE
457 const_length
= ASIZE (vector
);
460 if (STRING_MULTIBYTE (bytestr
))
461 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
462 because they produced a raw 8-bit string for byte-code and now
463 such a byte-code string is loaded as multibyte while raw 8-bit
464 characters converted to multibyte form. Thus, now we must
465 convert them back to the originally intended unibyte form. */
466 bytestr
= Fstring_as_unibyte (bytestr
);
468 #ifdef BYTE_CODE_SAFE
469 bytestr_length
= SBYTES (bytestr
);
471 vectorp
= XVECTOR (vector
)->contents
;
473 stack
.byte_string
= bytestr
;
474 stack
.pc
= stack
.byte_string_start
= SDATA (bytestr
);
475 if (MAX_ALLOCA
/ word_size
<= XFASTINT (maxdepth
))
476 memory_full (SIZE_MAX
);
477 top
= alloca ((XFASTINT (maxdepth
) + 1) * sizeof *top
);
478 stack
.next
= byte_stack_list
;
479 byte_stack_list
= &stack
;
481 #ifdef BYTE_CODE_SAFE
482 stacke
= stack
.bottom
- 1 + XFASTINT (maxdepth
);
485 if (INTEGERP (args_template
))
487 ptrdiff_t at
= XINT (args_template
);
488 bool rest
= (at
& 128) != 0;
489 int mandatory
= at
& 127;
490 ptrdiff_t nonrest
= at
>> 8;
491 eassert (mandatory
<= nonrest
);
492 if (nargs
<= nonrest
)
495 for (i
= 0 ; i
< nargs
; i
++, args
++)
497 if (nargs
< mandatory
)
498 /* Too few arguments. */
499 Fsignal (Qwrong_number_of_arguments
,
500 list2 (Fcons (make_number (mandatory
),
501 rest
? Qand_rest
: make_number (nonrest
)),
502 make_number (nargs
)));
505 for (; i
< nonrest
; i
++)
514 for (i
= 0 ; i
< nonrest
; i
++, args
++)
516 PUSH (Flist (nargs
- nonrest
, args
));
519 /* Too many arguments. */
520 Fsignal (Qwrong_number_of_arguments
,
521 list2 (Fcons (make_number (mandatory
), make_number (nonrest
)),
522 make_number (nargs
)));
524 else if (! NILP (args_template
))
525 /* We should push some arguments on the stack. */
527 error ("Unknown args template!");
532 #ifdef BYTE_CODE_SAFE
535 else if (top
< stack
.bottom
- 1)
539 #ifdef BYTE_CODE_METER
541 this_op
= op
= FETCH
;
542 METER_CODE (prev_op
, op
);
544 #ifndef BYTE_CODE_THREADED
549 /* The interpreter can be compiled one of two ways: as an
550 ordinary switch-based interpreter, or as a threaded
551 interpreter. The threaded interpreter relies on GCC's
552 computed goto extension, so it is not available everywhere.
553 Threading provides a performance boost. These macros are how
554 we allow the code to be compiled both ways. */
555 #ifdef BYTE_CODE_THREADED
556 /* The CASE macro introduces an instruction's body. It is
557 either a label or a case label. */
558 #define CASE(OP) insn_ ## OP
559 /* NEXT is invoked at the end of an instruction to go to the
560 next instruction. It is either a computed goto, or a
562 #define NEXT goto *(targets[op = FETCH])
563 /* FIRST is like NEXT, but is only used at the start of the
564 interpreter body. In the switch-based interpreter it is the
565 switch, so the threaded definition must include a semicolon. */
567 /* Most cases are labeled with the CASE macro, above.
568 CASE_DEFAULT is one exception; it is used if the interpreter
569 being built requires a default case. The threaded
570 interpreter does not, because the dispatch table is
571 completely filled. */
573 /* This introduces an instruction that is known to call abort. */
574 #define CASE_ABORT CASE (Bstack_ref): CASE (default)
576 /* See above for the meaning of the various defines. */
577 #define CASE(OP) case OP
579 #define FIRST switch (op)
580 #define CASE_DEFAULT case 255: default:
581 #define CASE_ABORT case 0
584 #ifdef BYTE_CODE_THREADED
586 /* A convenience define that saves us a lot of typing and makes
587 the table clearer. */
588 #define LABEL(OP) [OP] = &&insn_ ## OP
590 #if GNUC_PREREQ (4, 6, 0)
591 # pragma GCC diagnostic push
592 # pragma GCC diagnostic ignored "-Woverride-init"
593 #elif defined __clang__
594 # pragma GCC diagnostic push
595 # pragma GCC diagnostic ignored "-Winitializer-overrides"
598 /* This is the dispatch table for the threaded interpreter. */
599 static const void *const targets
[256] =
601 [0 ... (Bconstant
- 1)] = &&insn_default
,
602 [Bconstant
... 255] = &&insn_Bconstant
,
604 #define DEFINE(name, value) LABEL (name) ,
609 #if GNUC_PREREQ (4, 6, 0) || defined __clang__
610 # pragma GCC diagnostic pop
631 /* This seems to be the most frequently executed byte-code
632 among the Bvarref's, so avoid a goto here. */
642 if (XSYMBOL (v1
)->redirect
!= SYMBOL_PLAINVAL
643 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)),
646 v2
= Fsymbol_value (v1
);
651 v2
= Fsymbol_value (v1
);
667 stack
.pc
= stack
.byte_string_start
+ op
;
682 wrong_type_argument (Qlistp
, v1
);
691 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
699 TOP
= Fmemq (TOP
, v1
);
713 wrong_type_argument (Qlistp
, v1
);
735 Lisp_Object sym
, val
;
740 /* Inline the most common case. */
742 && !EQ (val
, Qunbound
)
743 && !XSYMBOL (sym
)->redirect
744 && !SYMBOL_CONSTANT_P (sym
))
745 SET_SYMBOL_VAL (XSYMBOL (sym
), val
);
748 set_internal (sym
, val
, Qnil
, 0);
762 /* ------------------ */
780 /* Specbind can signal and thus GC. */
781 specbind (vectorp
[op
], POP
);
802 #ifdef BYTE_CODE_METER
803 if (byte_metering_on
&& SYMBOLP (TOP
))
808 v2
= Fget (v1
, Qbyte_code_meter
);
810 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
812 XSETINT (v2
, XINT (v2
) + 1);
813 Fput (v1
, Qbyte_code_meter
, v2
);
817 TOP
= Ffuncall (op
+ 1, &TOP
);
837 unbind_to (SPECPDL_INDEX () - op
, Qnil
);
840 CASE (Bunbind_all
): /* Obsolete. Never used. */
841 /* To unbind back to the beginning of this frame. Not used yet,
842 but will be needed for tail-recursion elimination. */
843 unbind_to (count
, Qnil
);
849 op
= FETCH2
; /* pc = FETCH2 loses since FETCH2 contains pc++ */
851 stack
.pc
= stack
.byte_string_start
+ op
;
854 CASE (Bgotoifnonnil
):
864 stack
.pc
= stack
.byte_string_start
+ op
;
869 CASE (Bgotoifnilelsepop
):
876 stack
.pc
= stack
.byte_string_start
+ op
;
881 CASE (Bgotoifnonnilelsepop
):
888 stack
.pc
= stack
.byte_string_start
+ op
;
896 stack
.pc
+= (int) *stack
.pc
- 127;
907 stack
.pc
+= (int) *stack
.pc
- 128;
913 CASE (BRgotoifnonnil
):
921 stack
.pc
+= (int) *stack
.pc
- 128;
927 CASE (BRgotoifnilelsepop
):
933 stack
.pc
+= op
- 128;
938 CASE (BRgotoifnonnilelsepop
):
944 stack
.pc
+= op
- 128;
958 PUSH (vectorp
[FETCH2
]);
961 CASE (Bsave_excursion
):
962 record_unwind_protect (save_excursion_restore
,
963 save_excursion_save ());
966 CASE (Bsave_current_buffer
): /* Obsolete since ??. */
967 CASE (Bsave_current_buffer_1
):
968 record_unwind_current_buffer ();
971 CASE (Bsave_window_excursion
): /* Obsolete since 24.1. */
973 ptrdiff_t count1
= SPECPDL_INDEX ();
974 record_unwind_protect (restore_window_configuration
,
975 Fcurrent_window_configuration (Qnil
));
977 unbind_to (count1
, TOP
);
981 CASE (Bsave_restriction
):
982 record_unwind_protect (save_restriction_restore
,
983 save_restriction_save ());
986 CASE (Bcatch
): /* Obsolete since 24.4. */
990 TOP
= internal_catch (TOP
, eval_sub
, v1
);
994 CASE (Bpushcatch
): /* New in 24.4. */
997 CASE (Bpushconditioncase
): /* New in 24.4. */
998 type
= CONDITION_CASE
;
1001 Lisp_Object tag
= POP
;
1004 struct handler
*c
= push_handler (tag
, type
);
1005 c
->bytecode_dest
= dest
;
1006 c
->bytecode_top
= top
;
1008 if (sys_setjmp (c
->jmp
))
1010 struct handler
*c
= handlerlist
;
1012 top
= c
->bytecode_top
;
1013 dest
= c
->bytecode_dest
;
1014 handlerlist
= c
->next
;
1017 /* Might have been re-set by longjmp! */
1018 stack
.byte_string_start
= SDATA (stack
.byte_string
);
1019 stack
.pc
= stack
.byte_string_start
+ dest
;
1025 CASE (Bpophandler
): /* New in 24.4. */
1027 handlerlist
= handlerlist
->next
;
1031 CASE (Bunwind_protect
): /* FIXME: avoid closure for lexbind. */
1033 Lisp_Object handler
= POP
;
1034 /* Support for a function here is new in 24.4. */
1035 record_unwind_protect (NILP (Ffunctionp (handler
))
1036 ? unwind_body
: bcall0
,
1041 CASE (Bcondition_case
): /* Obsolete since 24.4. */
1043 Lisp_Object handlers
, body
;
1046 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
);
1050 CASE (Btemp_output_buffer_setup
): /* Obsolete since 24.1. */
1052 temp_output_buffer_setup (SSDATA (TOP
));
1053 TOP
= Vstandard_output
;
1056 CASE (Btemp_output_buffer_show
): /* Obsolete since 24.1. */
1060 temp_output_buffer_show (TOP
);
1062 /* pop binding of standard-output */
1063 unbind_to (SPECPDL_INDEX () - 1, Qnil
);
1076 while (--n
>= 0 && CONSP (v1
))
1084 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
1088 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
1092 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
1096 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
1100 TOP
= NILP (TOP
) ? Qt
: Qnil
;
1107 TOP
= Fcons (TOP
, v1
);
1119 TOP
= list2 (TOP
, v1
);
1125 TOP
= Flist (3, &TOP
);
1130 TOP
= Flist (4, &TOP
);
1136 TOP
= Flist (op
, &TOP
);
1140 TOP
= Flength (TOP
);
1147 TOP
= Faref (TOP
, v1
);
1155 TOP
= Faset (TOP
, v1
, v2
);
1159 CASE (Bsymbol_value
):
1160 TOP
= Fsymbol_value (TOP
);
1163 CASE (Bsymbol_function
):
1164 TOP
= Fsymbol_function (TOP
);
1171 TOP
= Fset (TOP
, v1
);
1179 TOP
= Ffset (TOP
, v1
);
1187 TOP
= Fget (TOP
, v1
);
1195 TOP
= Fsubstring (TOP
, v1
, v2
);
1201 TOP
= Fconcat (2, &TOP
);
1206 TOP
= Fconcat (3, &TOP
);
1211 TOP
= Fconcat (4, &TOP
);
1217 TOP
= Fconcat (op
, &TOP
);
1226 XSETINT (v1
, XINT (v1
) - 1);
1242 XSETINT (v1
, XINT (v1
) + 1);
1256 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
1257 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
1258 if (FLOATP (v1
) || FLOATP (v2
))
1262 f1
= (FLOATP (v1
) ? XFLOAT_DATA (v1
) : XINT (v1
));
1263 f2
= (FLOATP (v2
) ? XFLOAT_DATA (v2
) : XINT (v2
));
1264 TOP
= (f1
== f2
? Qt
: Qnil
);
1267 TOP
= (XINT (v1
) == XINT (v2
) ? Qt
: Qnil
);
1275 TOP
= arithcompare (TOP
, v1
, ARITH_GRTR
);
1283 TOP
= arithcompare (TOP
, v1
, ARITH_LESS
);
1291 TOP
= arithcompare (TOP
, v1
, ARITH_LESS_OR_EQUAL
);
1299 TOP
= arithcompare (TOP
, v1
, ARITH_GRTR_OR_EQUAL
);
1305 TOP
= Fminus (2, &TOP
);
1314 XSETINT (v1
, - XINT (v1
));
1319 TOP
= Fminus (1, &TOP
);
1326 TOP
= Fplus (2, &TOP
);
1331 TOP
= Fmax (2, &TOP
);
1336 TOP
= Fmin (2, &TOP
);
1341 TOP
= Ftimes (2, &TOP
);
1346 TOP
= Fquo (2, &TOP
);
1353 TOP
= Frem (TOP
, v1
);
1360 XSETFASTINT (v1
, PT
);
1366 TOP
= Fgoto_char (TOP
);
1370 TOP
= Finsert (1, &TOP
);
1376 TOP
= Finsert (op
, &TOP
);
1382 XSETFASTINT (v1
, ZV
);
1390 XSETFASTINT (v1
, BEGV
);
1396 TOP
= Fchar_after (TOP
);
1399 CASE (Bfollowing_char
):
1402 v1
= Ffollowing_char ();
1407 CASE (Bpreceding_char
):
1410 v1
= Fprevious_char ();
1415 CASE (Bcurrent_column
):
1418 XSETFASTINT (v1
, current_column ());
1424 TOP
= Findent_to (TOP
, Qnil
);
1443 CASE (Bcurrent_buffer
):
1444 PUSH (Fcurrent_buffer ());
1448 TOP
= Fset_buffer (TOP
);
1451 CASE (Binteractive_p
): /* Obsolete since 24.1. */
1452 PUSH (call0 (intern ("interactive-p")));
1455 CASE (Bforward_char
):
1456 TOP
= Fforward_char (TOP
);
1459 CASE (Bforward_word
):
1460 TOP
= Fforward_word (TOP
);
1463 CASE (Bskip_chars_forward
):
1467 TOP
= Fskip_chars_forward (TOP
, v1
);
1471 CASE (Bskip_chars_backward
):
1475 TOP
= Fskip_chars_backward (TOP
, v1
);
1479 CASE (Bforward_line
):
1480 TOP
= Fforward_line (TOP
);
1483 CASE (Bchar_syntax
):
1487 CHECK_CHARACTER (TOP
);
1489 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
1490 MAKE_CHAR_MULTIBYTE (c
);
1491 XSETFASTINT (TOP
, syntax_code_spec
[SYNTAX (c
)]);
1495 CASE (Bbuffer_substring
):
1499 TOP
= Fbuffer_substring (TOP
, v1
);
1503 CASE (Bdelete_region
):
1507 TOP
= Fdelete_region (TOP
, v1
);
1511 CASE (Bnarrow_to_region
):
1515 TOP
= Fnarrow_to_region (TOP
, v1
);
1523 CASE (Bend_of_line
):
1524 TOP
= Fend_of_line (TOP
);
1532 TOP
= Fset_marker (TOP
, v2
, v1
);
1536 CASE (Bmatch_beginning
):
1537 TOP
= Fmatch_beginning (TOP
);
1541 TOP
= Fmatch_end (TOP
);
1545 TOP
= Fupcase (TOP
);
1549 TOP
= Fdowncase (TOP
);
1552 CASE (Bstringeqlsign
):
1556 TOP
= Fstring_equal (TOP
, v1
);
1564 TOP
= Fstring_lessp (TOP
, v1
);
1572 TOP
= Fequal (TOP
, v1
);
1580 TOP
= Fnthcdr (TOP
, v1
);
1589 /* Exchange args and then do nth. */
1596 while (--n
>= 0 && CONSP (v1
))
1604 TOP
= Felt (TOP
, v1
);
1613 TOP
= Fmember (TOP
, v1
);
1621 TOP
= Fassq (TOP
, v1
);
1626 TOP
= Fnreverse (TOP
);
1633 TOP
= Fsetcar (TOP
, v1
);
1641 TOP
= Fsetcdr (TOP
, v1
);
1649 TOP
= CAR_SAFE (v1
);
1657 TOP
= CDR_SAFE (v1
);
1663 TOP
= Fnconc (2, &TOP
);
1667 TOP
= (NUMBERP (TOP
) ? Qt
: Qnil
);
1671 TOP
= INTEGERP (TOP
) ? Qt
: Qnil
;
1674 #ifdef BYTE_CODE_SAFE
1675 /* These are intentionally written using 'case' syntax,
1676 because they are incompatible with the threaded
1680 error ("set-mark is an obsolete bytecode");
1683 error ("scan-buffer is an obsolete bytecode");
1688 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1689 for that instead. */
1690 /* CASE (Bstack_ref): */
1692 build_string ("Invalid byte opcode: op=%s, ptr=%d"),
1694 make_number ((stack
.pc
- 1) - stack
.byte_string_start
));
1696 /* Handy byte-codes for lexical binding. */
1703 Lisp_Object
*ptr
= top
- (op
- Bstack_ref
);
1709 Lisp_Object
*ptr
= top
- (FETCH
);
1715 Lisp_Object
*ptr
= top
- (FETCH2
);
1720 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1722 Lisp_Object
*ptr
= top
- (FETCH
);
1728 Lisp_Object
*ptr
= top
- (FETCH2
);
1744 #ifdef BYTE_CODE_SAFE
1749 if ((op
-= Bconstant
) >= const_length
)
1755 PUSH (vectorp
[op
- Bconstant
]);
1763 byte_stack_list
= byte_stack_list
->next
;
1765 /* Binds and unbinds are supposed to be compiled balanced. */
1766 if (SPECPDL_INDEX () != count
)
1768 if (SPECPDL_INDEX () > count
)
1769 unbind_to (count
, Qnil
);
1770 error ("binding stack not balanced (serious byte compiler bug)");
1776 /* `args_template' has the same meaning as in exec_byte_code() above. */
1778 get_byte_code_arity (Lisp_Object args_template
)
1780 eassert (NATNUMP (args_template
));
1781 EMACS_INT at
= XINT (args_template
);
1782 bool rest
= (at
& 128) != 0;
1783 int mandatory
= at
& 127;
1784 EMACS_INT nonrest
= at
>> 8;
1786 return Fcons (make_number (mandatory
),
1787 rest
? Qmany
: make_number (nonrest
));
1791 syms_of_bytecode (void)
1793 defsubr (&Sbyte_code
);
1795 #ifdef BYTE_CODE_METER
1797 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter
,
1798 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
1799 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1800 opcode CODE has been executed.
1801 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1802 indicates how many times the byte opcodes CODE1 and CODE2 have been
1803 executed in succession. */);
1805 DEFVAR_BOOL ("byte-metering-on", byte_metering_on
,
1806 doc
: /* If non-nil, keep profiling information on byte code usage.
1807 The variable byte-code-meter indicates how often each byte opcode is used.
1808 If a symbol has a property named `byte-code-meter' whose value is an
1809 integer, it is incremented each time that symbol's function is called. */);
1811 byte_metering_on
= 0;
1812 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
1813 DEFSYM (Qbyte_code_meter
, "byte-code-meter");
1817 ASET (Vbyte_code_meter
, i
,
1818 Fmake_vector (make_number (256), make_number (0)));