1 /* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985-1988, 1993, 2000-2017 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 <https://www.gnu.org/licenses/>. */
23 #include "blockinput.h"
24 #include "character.h"
27 #include "ptr-bounds.h"
31 /* Work around GCC bug 54561. */
32 #if GNUC_PREREQ (4, 3, 0)
33 # pragma GCC diagnostic ignored "-Wclobbered"
36 /* Define BYTE_CODE_SAFE true to enable some minor sanity checking,
37 useful for debugging the byte compiler. It defaults to false. */
39 #ifndef BYTE_CODE_SAFE
40 # define BYTE_CODE_SAFE false
43 /* Define BYTE_CODE_METER to generate a byte-op usage histogram. */
44 /* #define BYTE_CODE_METER */
46 /* If BYTE_CODE_THREADED is defined, then the interpreter will be
47 indirect threaded, using GCC's computed goto extension. This code,
48 as currently implemented, is incompatible with BYTE_CODE_SAFE and
50 #if (defined __GNUC__ && !defined __STRICT_ANSI__ && !defined __CHKP__ \
51 && !BYTE_CODE_SAFE && !defined BYTE_CODE_METER)
52 #define BYTE_CODE_THREADED
56 #ifdef BYTE_CODE_METER
58 #define METER_2(code1, code2) \
59 (*aref_addr (AREF (Vbyte_code_meter, code1), code2))
60 #define METER_1(code) METER_2 (0, code)
62 #define METER_CODE(last_code, this_code) \
64 if (byte_metering_on) \
66 if (XFASTINT (METER_1 (this_code)) < MOST_POSITIVE_FIXNUM) \
67 XSETFASTINT (METER_1 (this_code), \
68 XFASTINT (METER_1 (this_code)) + 1); \
70 && (XFASTINT (METER_2 (last_code, this_code)) \
71 < MOST_POSITIVE_FIXNUM)) \
72 XSETFASTINT (METER_2 (last_code, this_code), \
73 XFASTINT (METER_2 (last_code, this_code)) + 1); \
77 #endif /* BYTE_CODE_METER */
83 DEFINE (Bstack_ref, 0) /* Actually, Bstack_ref+0 is not implemented: use dup. */ \
84 DEFINE (Bstack_ref1, 1) \
85 DEFINE (Bstack_ref2, 2) \
86 DEFINE (Bstack_ref3, 3) \
87 DEFINE (Bstack_ref4, 4) \
88 DEFINE (Bstack_ref5, 5) \
89 DEFINE (Bstack_ref6, 6) \
90 DEFINE (Bstack_ref7, 7) \
91 DEFINE (Bvarref, 010) \
92 DEFINE (Bvarref1, 011) \
93 DEFINE (Bvarref2, 012) \
94 DEFINE (Bvarref3, 013) \
95 DEFINE (Bvarref4, 014) \
96 DEFINE (Bvarref5, 015) \
97 DEFINE (Bvarref6, 016) \
98 DEFINE (Bvarref7, 017) \
99 DEFINE (Bvarset, 020) \
100 DEFINE (Bvarset1, 021) \
101 DEFINE (Bvarset2, 022) \
102 DEFINE (Bvarset3, 023) \
103 DEFINE (Bvarset4, 024) \
104 DEFINE (Bvarset5, 025) \
105 DEFINE (Bvarset6, 026) \
106 DEFINE (Bvarset7, 027) \
107 DEFINE (Bvarbind, 030) \
108 DEFINE (Bvarbind1, 031) \
109 DEFINE (Bvarbind2, 032) \
110 DEFINE (Bvarbind3, 033) \
111 DEFINE (Bvarbind4, 034) \
112 DEFINE (Bvarbind5, 035) \
113 DEFINE (Bvarbind6, 036) \
114 DEFINE (Bvarbind7, 037) \
115 DEFINE (Bcall, 040) \
116 DEFINE (Bcall1, 041) \
117 DEFINE (Bcall2, 042) \
118 DEFINE (Bcall3, 043) \
119 DEFINE (Bcall4, 044) \
120 DEFINE (Bcall5, 045) \
121 DEFINE (Bcall6, 046) \
122 DEFINE (Bcall7, 047) \
123 DEFINE (Bunbind, 050) \
124 DEFINE (Bunbind1, 051) \
125 DEFINE (Bunbind2, 052) \
126 DEFINE (Bunbind3, 053) \
127 DEFINE (Bunbind4, 054) \
128 DEFINE (Bunbind5, 055) \
129 DEFINE (Bunbind6, 056) \
130 DEFINE (Bunbind7, 057) \
132 DEFINE (Bpophandler, 060) \
133 DEFINE (Bpushconditioncase, 061) \
134 DEFINE (Bpushcatch, 062) \
137 DEFINE (Bsymbolp, 071) \
138 DEFINE (Bconsp, 072) \
139 DEFINE (Bstringp, 073) \
140 DEFINE (Blistp, 074) \
142 DEFINE (Bmemq, 076) \
144 DEFINE (Bcar, 0100) \
145 DEFINE (Bcdr, 0101) \
146 DEFINE (Bcons, 0102) \
147 DEFINE (Blist1, 0103) \
148 DEFINE (Blist2, 0104) \
149 DEFINE (Blist3, 0105) \
150 DEFINE (Blist4, 0106) \
151 DEFINE (Blength, 0107) \
152 DEFINE (Baref, 0110) \
153 DEFINE (Baset, 0111) \
154 DEFINE (Bsymbol_value, 0112) \
155 DEFINE (Bsymbol_function, 0113) \
156 DEFINE (Bset, 0114) \
157 DEFINE (Bfset, 0115) \
158 DEFINE (Bget, 0116) \
159 DEFINE (Bsubstring, 0117) \
160 DEFINE (Bconcat2, 0120) \
161 DEFINE (Bconcat3, 0121) \
162 DEFINE (Bconcat4, 0122) \
163 DEFINE (Bsub1, 0123) \
164 DEFINE (Badd1, 0124) \
165 DEFINE (Beqlsign, 0125) \
166 DEFINE (Bgtr, 0126) \
167 DEFINE (Blss, 0127) \
168 DEFINE (Bleq, 0130) \
169 DEFINE (Bgeq, 0131) \
170 DEFINE (Bdiff, 0132) \
171 DEFINE (Bnegate, 0133) \
172 DEFINE (Bplus, 0134) \
173 DEFINE (Bmax, 0135) \
174 DEFINE (Bmin, 0136) \
175 DEFINE (Bmult, 0137) \
177 DEFINE (Bpoint, 0140) \
178 /* Was Bmark in v17. */ \
179 DEFINE (Bsave_current_buffer, 0141) /* Obsolete. */ \
180 DEFINE (Bgoto_char, 0142) \
181 DEFINE (Binsert, 0143) \
182 DEFINE (Bpoint_max, 0144) \
183 DEFINE (Bpoint_min, 0145) \
184 DEFINE (Bchar_after, 0146) \
185 DEFINE (Bfollowing_char, 0147) \
186 DEFINE (Bpreceding_char, 0150) \
187 DEFINE (Bcurrent_column, 0151) \
188 DEFINE (Bindent_to, 0152) \
189 DEFINE (Beolp, 0154) \
190 DEFINE (Beobp, 0155) \
191 DEFINE (Bbolp, 0156) \
192 DEFINE (Bbobp, 0157) \
193 DEFINE (Bcurrent_buffer, 0160) \
194 DEFINE (Bset_buffer, 0161) \
195 DEFINE (Bsave_current_buffer_1, 0162) /* Replacing Bsave_current_buffer. */ \
196 DEFINE (Binteractive_p, 0164) /* Obsolete since Emacs-24.1. */ \
198 DEFINE (Bforward_char, 0165) \
199 DEFINE (Bforward_word, 0166) \
200 DEFINE (Bskip_chars_forward, 0167) \
201 DEFINE (Bskip_chars_backward, 0170) \
202 DEFINE (Bforward_line, 0171) \
203 DEFINE (Bchar_syntax, 0172) \
204 DEFINE (Bbuffer_substring, 0173) \
205 DEFINE (Bdelete_region, 0174) \
206 DEFINE (Bnarrow_to_region, 0175) \
207 DEFINE (Bwiden, 0176) \
208 DEFINE (Bend_of_line, 0177) \
210 DEFINE (Bconstant2, 0201) \
211 DEFINE (Bgoto, 0202) \
212 DEFINE (Bgotoifnil, 0203) \
213 DEFINE (Bgotoifnonnil, 0204) \
214 DEFINE (Bgotoifnilelsepop, 0205) \
215 DEFINE (Bgotoifnonnilelsepop, 0206) \
216 DEFINE (Breturn, 0207) \
217 DEFINE (Bdiscard, 0210) \
218 DEFINE (Bdup, 0211) \
220 DEFINE (Bsave_excursion, 0212) \
221 DEFINE (Bsave_window_excursion, 0213) /* Obsolete since Emacs-24.1. */ \
222 DEFINE (Bsave_restriction, 0214) \
223 DEFINE (Bcatch, 0215) \
225 DEFINE (Bunwind_protect, 0216) \
226 DEFINE (Bcondition_case, 0217) \
227 DEFINE (Btemp_output_buffer_setup, 0220) /* Obsolete since Emacs-24.1. */ \
228 DEFINE (Btemp_output_buffer_show, 0221) /* Obsolete since Emacs-24.1. */ \
230 DEFINE (Bunbind_all, 0222) /* Obsolete. Never used. */ \
232 DEFINE (Bset_marker, 0223) \
233 DEFINE (Bmatch_beginning, 0224) \
234 DEFINE (Bmatch_end, 0225) \
235 DEFINE (Bupcase, 0226) \
236 DEFINE (Bdowncase, 0227) \
238 DEFINE (Bstringeqlsign, 0230) \
239 DEFINE (Bstringlss, 0231) \
240 DEFINE (Bequal, 0232) \
241 DEFINE (Bnthcdr, 0233) \
242 DEFINE (Belt, 0234) \
243 DEFINE (Bmember, 0235) \
244 DEFINE (Bassq, 0236) \
245 DEFINE (Bnreverse, 0237) \
246 DEFINE (Bsetcar, 0240) \
247 DEFINE (Bsetcdr, 0241) \
248 DEFINE (Bcar_safe, 0242) \
249 DEFINE (Bcdr_safe, 0243) \
250 DEFINE (Bnconc, 0244) \
251 DEFINE (Bquo, 0245) \
252 DEFINE (Brem, 0246) \
253 DEFINE (Bnumberp, 0247) \
254 DEFINE (Bintegerp, 0250) \
256 DEFINE (BRgoto, 0252) \
257 DEFINE (BRgotoifnil, 0253) \
258 DEFINE (BRgotoifnonnil, 0254) \
259 DEFINE (BRgotoifnilelsepop, 0255) \
260 DEFINE (BRgotoifnonnilelsepop, 0256) \
262 DEFINE (BlistN, 0257) \
263 DEFINE (BconcatN, 0260) \
264 DEFINE (BinsertN, 0261) \
266 /* Bstack_ref is code 0. */ \
267 DEFINE (Bstack_set, 0262) \
268 DEFINE (Bstack_set2, 0263) \
269 DEFINE (BdiscardN, 0266) \
271 DEFINE (Bswitch, 0267) \
273 DEFINE (Bconstant, 0300)
277 #define DEFINE(name, value) name = value,
282 Bscan_buffer
= 0153, /* No longer generated as of v18. */
283 Bset_mark
= 0163, /* this loser is no longer generated as of v18 */
287 /* Fetch the next byte from the bytecode stream. */
289 #define FETCH (*pc++)
291 /* Fetch two bytes from the bytecode stream and make a 16-bit number
294 #define FETCH2 (op = FETCH, op + (FETCH << 8))
296 /* Push X onto the execution stack. The expression X should not
297 contain TOP, to avoid competing side effects. */
299 #define PUSH(x) (*++top = (x))
301 /* Pop a value off the execution stack. */
305 /* Discard n values from the execution stack. */
307 #define DISCARD(n) (top -= (n))
309 /* Get the value which is at the top of the execution stack, but don't
314 DEFUN ("byte-code", Fbyte_code
, Sbyte_code
, 3, 3, 0,
315 doc
: /* Function used internally in byte-compiled code.
316 The first argument, BYTESTR, is a string of byte code;
317 the second, VECTOR, a vector of constants;
318 the third, MAXDEPTH, the maximum stack depth used in this function.
319 If the third argument is incorrect, Emacs may crash. */)
320 (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
)
322 return exec_byte_code (bytestr
, vector
, maxdepth
, Qnil
, 0, NULL
);
326 bcall0 (Lisp_Object f
)
331 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
332 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
333 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
334 argument list (including &rest, &optional, etc.), and ARGS, of size
335 NARGS, should be a vector of the actual arguments. The arguments in
336 ARGS are pushed on the stack according to ARGS_TEMPLATE before
337 executing BYTESTR. */
340 exec_byte_code (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
,
341 Lisp_Object args_template
, ptrdiff_t nargs
, Lisp_Object
*args
)
343 #ifdef BYTE_CODE_METER
344 int volatile this_op
= 0;
347 CHECK_STRING (bytestr
);
348 CHECK_VECTOR (vector
);
349 CHECK_NATNUM (maxdepth
);
351 ptrdiff_t const_length
= ASIZE (vector
);
353 if (STRING_MULTIBYTE (bytestr
))
354 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
355 because they produced a raw 8-bit string for byte-code and now
356 such a byte-code string is loaded as multibyte while raw 8-bit
357 characters converted to multibyte form. Thus, now we must
358 convert them back to the originally intended unibyte form. */
359 bytestr
= Fstring_as_unibyte (bytestr
);
361 ptrdiff_t bytestr_length
= SBYTES (bytestr
);
362 Lisp_Object
*vectorp
= XVECTOR (vector
)->contents
;
364 unsigned char quitcounter
= 1;
365 EMACS_INT stack_items
= XFASTINT (maxdepth
) + 1;
368 SAFE_ALLOCA_LISP_EXTRA (alloc
, stack_items
, bytestr_length
);
369 ptrdiff_t item_bytes
= stack_items
* word_size
;
370 Lisp_Object
*stack_base
= ptr_bounds_clip (alloc
, item_bytes
);
371 Lisp_Object
*top
= stack_base
;
372 Lisp_Object
*stack_lim
= stack_base
+ stack_items
;
373 unsigned char *bytestr_data
= alloc
;
374 bytestr_data
= ptr_bounds_clip (bytestr_data
+ item_bytes
, bytestr_length
);
375 memcpy (bytestr_data
, SDATA (bytestr
), bytestr_length
);
376 unsigned char const *pc
= bytestr_data
;
377 ptrdiff_t count
= SPECPDL_INDEX ();
379 if (!NILP (args_template
))
381 eassert (INTEGERP (args_template
));
382 ptrdiff_t at
= XINT (args_template
);
383 bool rest
= (at
& 128) != 0;
384 int mandatory
= at
& 127;
385 ptrdiff_t nonrest
= at
>> 8;
386 ptrdiff_t maxargs
= rest
? PTRDIFF_MAX
: nonrest
;
387 if (! (mandatory
<= nargs
&& nargs
<= maxargs
))
388 Fsignal (Qwrong_number_of_arguments
,
389 list2 (Fcons (make_number (mandatory
), make_number (nonrest
)),
390 make_number (nargs
)));
391 ptrdiff_t pushedargs
= min (nonrest
, nargs
);
392 for (ptrdiff_t i
= 0; i
< pushedargs
; i
++, args
++)
395 PUSH (Flist (nargs
- nonrest
, args
));
397 for (ptrdiff_t i
= nargs
- rest
; i
< nonrest
; i
++)
404 enum handlertype type
;
406 if (BYTE_CODE_SAFE
&& ! (stack_base
<= top
&& top
< stack_lim
))
409 #ifdef BYTE_CODE_METER
410 int prev_op
= this_op
;
411 this_op
= op
= FETCH
;
412 METER_CODE (prev_op
, op
);
413 #elif !defined BYTE_CODE_THREADED
417 /* The interpreter can be compiled one of two ways: as an
418 ordinary switch-based interpreter, or as a threaded
419 interpreter. The threaded interpreter relies on GCC's
420 computed goto extension, so it is not available everywhere.
421 Threading provides a performance boost. These macros are how
422 we allow the code to be compiled both ways. */
423 #ifdef BYTE_CODE_THREADED
424 /* The CASE macro introduces an instruction's body. It is
425 either a label or a case label. */
426 #define CASE(OP) insn_ ## OP
427 /* NEXT is invoked at the end of an instruction to go to the
428 next instruction. It is either a computed goto, or a
430 #define NEXT goto *(targets[op = FETCH])
431 /* FIRST is like NEXT, but is only used at the start of the
432 interpreter body. In the switch-based interpreter it is the
433 switch, so the threaded definition must include a semicolon. */
435 /* Most cases are labeled with the CASE macro, above.
436 CASE_DEFAULT is one exception; it is used if the interpreter
437 being built requires a default case. The threaded
438 interpreter does not, because the dispatch table is
439 completely filled. */
441 /* This introduces an instruction that is known to call abort. */
442 #define CASE_ABORT CASE (Bstack_ref): CASE (default)
444 /* See above for the meaning of the various defines. */
445 #define CASE(OP) case OP
447 #define FIRST switch (op)
448 #define CASE_DEFAULT case 255: default:
449 #define CASE_ABORT case 0
452 #ifdef BYTE_CODE_THREADED
454 /* A convenience define that saves us a lot of typing and makes
455 the table clearer. */
456 #define LABEL(OP) [OP] = &&insn_ ## OP
458 /* This is the dispatch table for the threaded interpreter. */
459 static const void *const targets
[256] =
461 [0 ... (Bconstant
- 1)] = &&insn_default
,
462 [Bconstant
... 255] = &&insn_Bconstant
,
464 #define DEFINE(name, value) LABEL (name) ,
487 /* This seems to be the most frequently executed byte-code
488 among the Bvarref's, so avoid a goto here. */
493 Lisp_Object v1
= vectorp
[op
], v2
;
495 || XSYMBOL (v1
)->u
.s
.redirect
!= SYMBOL_PLAINVAL
496 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)), EQ (v2
, Qunbound
)))
497 v2
= Fsymbol_value (v1
);
504 Lisp_Object v1
= POP
;
514 else if (!NILP (TOP
))
515 wrong_type_argument (Qlistp
, TOP
);
520 Lisp_Object v1
= POP
;
521 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
527 Lisp_Object v1
= POP
;
528 TOP
= Fmemq (TOP
, v1
);
536 else if (!NILP (TOP
))
537 wrong_type_argument (Qlistp
, TOP
);
558 Lisp_Object sym
= vectorp
[op
];
559 Lisp_Object val
= POP
;
561 /* Inline the most common case. */
563 && !EQ (val
, Qunbound
)
564 && !XSYMBOL (sym
)->u
.s
.redirect
565 && !SYMBOL_TRAPPED_WRITE_P (sym
))
566 SET_SYMBOL_VAL (XSYMBOL (sym
), val
);
568 set_internal (sym
, val
, Qnil
, SET_INTERNAL_SET
);
574 Lisp_Object v1
= TOP
;
579 /* ------------------ */
597 /* Specbind can signal and thus GC. */
598 specbind (vectorp
[op
], POP
);
619 #ifdef BYTE_CODE_METER
620 if (byte_metering_on
&& SYMBOLP (TOP
))
622 Lisp_Object v1
= TOP
;
623 Lisp_Object v2
= Fget (v1
, Qbyte_code_meter
);
625 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
627 XSETINT (v2
, XINT (v2
) + 1);
628 Fput (v1
, Qbyte_code_meter
, v2
);
632 TOP
= Ffuncall (op
+ 1, &TOP
);
652 unbind_to (SPECPDL_INDEX () - op
, Qnil
);
655 CASE (Bunbind_all
): /* Obsolete. Never used. */
656 /* To unbind back to the beginning of this frame. Not used yet,
657 but will be needed for tail-recursion elimination. */
658 unbind_to (count
, Qnil
);
664 op
-= pc
- bytestr_data
;
667 && ! (bytestr_data
- pc
<= op
668 && op
< bytestr_data
+ bytestr_length
- pc
))
670 quitcounter
+= op
< 0;
680 CASE (Bgotoifnonnil
):
686 CASE (Bgotoifnilelsepop
):
693 CASE (Bgotoifnonnilelsepop
):
702 goto op_relative_branch
;
707 goto op_relative_branch
;
710 CASE (BRgotoifnonnil
):
713 goto op_relative_branch
;
716 CASE (BRgotoifnilelsepop
):
719 goto op_relative_branch
;
723 CASE (BRgotoifnonnilelsepop
):
726 goto op_relative_branch
;
738 PUSH (vectorp
[FETCH2
]);
741 CASE (Bsave_excursion
):
742 record_unwind_protect (save_excursion_restore
,
743 save_excursion_save ());
746 CASE (Bsave_current_buffer
): /* Obsolete since ??. */
747 CASE (Bsave_current_buffer_1
):
748 record_unwind_current_buffer ();
751 CASE (Bsave_window_excursion
): /* Obsolete since 24.1. */
753 ptrdiff_t count1
= SPECPDL_INDEX ();
754 record_unwind_protect (restore_window_configuration
,
755 Fcurrent_window_configuration (Qnil
));
757 unbind_to (count1
, TOP
);
761 CASE (Bsave_restriction
):
762 record_unwind_protect (save_restriction_restore
,
763 save_restriction_save ());
766 CASE (Bcatch
): /* Obsolete since 24.4. */
768 Lisp_Object v1
= POP
;
769 TOP
= internal_catch (TOP
, eval_sub
, v1
);
773 CASE (Bpushcatch
): /* New in 24.4. */
776 CASE (Bpushconditioncase
): /* New in 24.4. */
777 type
= CONDITION_CASE
;
780 struct handler
*c
= push_handler (POP
, type
);
781 c
->bytecode_dest
= FETCH2
;
782 c
->bytecode_top
= top
;
784 if (sys_setjmp (c
->jmp
))
786 struct handler
*c
= handlerlist
;
787 top
= c
->bytecode_top
;
788 op
= c
->bytecode_dest
;
789 handlerlist
= c
->next
;
797 CASE (Bpophandler
): /* New in 24.4. */
798 handlerlist
= handlerlist
->next
;
801 CASE (Bunwind_protect
): /* FIXME: avoid closure for lexbind. */
803 Lisp_Object handler
= POP
;
804 /* Support for a function here is new in 24.4. */
805 record_unwind_protect (FUNCTIONP (handler
) ? bcall0
: prog_ignore
,
810 CASE (Bcondition_case
): /* Obsolete since 24.4. */
812 Lisp_Object handlers
= POP
, body
= POP
;
813 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
);
817 CASE (Btemp_output_buffer_setup
): /* Obsolete since 24.1. */
819 temp_output_buffer_setup (SSDATA (TOP
));
820 TOP
= Vstandard_output
;
823 CASE (Btemp_output_buffer_show
): /* Obsolete since 24.1. */
825 Lisp_Object v1
= POP
;
826 temp_output_buffer_show (TOP
);
828 /* pop binding of standard-output */
829 unbind_to (SPECPDL_INDEX () - 1, Qnil
);
835 Lisp_Object v2
= POP
, v1
= TOP
;
837 for (EMACS_INT n
= XINT (v1
); 0 < n
&& CONSP (v2
); n
--)
847 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
851 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
855 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
859 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
863 TOP
= NILP (TOP
) ? Qt
: Qnil
;
868 Lisp_Object v1
= POP
;
869 TOP
= Fcons (TOP
, v1
);
879 Lisp_Object v1
= POP
;
880 TOP
= list2 (TOP
, v1
);
886 TOP
= Flist (3, &TOP
);
891 TOP
= Flist (4, &TOP
);
897 TOP
= Flist (op
, &TOP
);
906 Lisp_Object v1
= POP
;
907 TOP
= Faref (TOP
, v1
);
913 Lisp_Object v2
= POP
, v1
= POP
;
914 TOP
= Faset (TOP
, v1
, v2
);
918 CASE (Bsymbol_value
):
919 TOP
= Fsymbol_value (TOP
);
922 CASE (Bsymbol_function
):
923 TOP
= Fsymbol_function (TOP
);
928 Lisp_Object v1
= POP
;
929 TOP
= Fset (TOP
, v1
);
935 Lisp_Object v1
= POP
;
936 TOP
= Ffset (TOP
, v1
);
942 Lisp_Object v1
= POP
;
943 TOP
= Fget (TOP
, v1
);
949 Lisp_Object v2
= POP
, v1
= POP
;
950 TOP
= Fsubstring (TOP
, v1
, v2
);
956 TOP
= Fconcat (2, &TOP
);
961 TOP
= Fconcat (3, &TOP
);
966 TOP
= Fconcat (4, &TOP
);
972 TOP
= Fconcat (op
, &TOP
);
976 TOP
= INTEGERP (TOP
) ? make_number (XINT (TOP
) - 1) : Fsub1 (TOP
);
980 TOP
= INTEGERP (TOP
) ? make_number (XINT (TOP
) + 1) : Fadd1 (TOP
);
985 Lisp_Object v2
= POP
, v1
= TOP
;
986 if (FLOATP (v1
) || FLOATP (v2
))
987 TOP
= arithcompare (v1
, v2
, ARITH_EQUAL
);
990 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
991 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
992 TOP
= EQ (v1
, v2
) ? Qt
: Qnil
;
999 Lisp_Object v1
= POP
;
1000 TOP
= arithcompare (TOP
, v1
, ARITH_GRTR
);
1006 Lisp_Object v1
= POP
;
1007 TOP
= arithcompare (TOP
, v1
, ARITH_LESS
);
1013 Lisp_Object v1
= POP
;
1014 TOP
= arithcompare (TOP
, v1
, ARITH_LESS_OR_EQUAL
);
1020 Lisp_Object v1
= POP
;
1021 TOP
= arithcompare (TOP
, v1
, ARITH_GRTR_OR_EQUAL
);
1027 TOP
= Fminus (2, &TOP
);
1031 TOP
= INTEGERP (TOP
) ? make_number (- XINT (TOP
)) : Fminus (1, &TOP
);
1036 TOP
= Fplus (2, &TOP
);
1041 TOP
= Fmax (2, &TOP
);
1046 TOP
= Fmin (2, &TOP
);
1051 TOP
= Ftimes (2, &TOP
);
1056 TOP
= Fquo (2, &TOP
);
1061 Lisp_Object v1
= POP
;
1062 TOP
= Frem (TOP
, v1
);
1067 PUSH (make_natnum (PT
));
1071 TOP
= Fgoto_char (TOP
);
1075 TOP
= Finsert (1, &TOP
);
1081 TOP
= Finsert (op
, &TOP
);
1087 XSETFASTINT (v1
, ZV
);
1093 PUSH (make_natnum (BEGV
));
1097 TOP
= Fchar_after (TOP
);
1100 CASE (Bfollowing_char
):
1101 PUSH (Ffollowing_char ());
1104 CASE (Bpreceding_char
):
1105 PUSH (Fprevious_char ());
1108 CASE (Bcurrent_column
):
1109 PUSH (make_natnum (current_column ()));
1113 TOP
= Findent_to (TOP
, Qnil
);
1132 CASE (Bcurrent_buffer
):
1133 PUSH (Fcurrent_buffer ());
1137 TOP
= Fset_buffer (TOP
);
1140 CASE (Binteractive_p
): /* Obsolete since 24.1. */
1141 PUSH (call0 (intern ("interactive-p")));
1144 CASE (Bforward_char
):
1145 TOP
= Fforward_char (TOP
);
1148 CASE (Bforward_word
):
1149 TOP
= Fforward_word (TOP
);
1152 CASE (Bskip_chars_forward
):
1154 Lisp_Object v1
= POP
;
1155 TOP
= Fskip_chars_forward (TOP
, v1
);
1159 CASE (Bskip_chars_backward
):
1161 Lisp_Object v1
= POP
;
1162 TOP
= Fskip_chars_backward (TOP
, v1
);
1166 CASE (Bforward_line
):
1167 TOP
= Fforward_line (TOP
);
1170 CASE (Bchar_syntax
):
1172 CHECK_CHARACTER (TOP
);
1173 int c
= XFASTINT (TOP
);
1174 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
1175 MAKE_CHAR_MULTIBYTE (c
);
1176 XSETFASTINT (TOP
, syntax_code_spec
[SYNTAX (c
)]);
1180 CASE (Bbuffer_substring
):
1182 Lisp_Object v1
= POP
;
1183 TOP
= Fbuffer_substring (TOP
, v1
);
1187 CASE (Bdelete_region
):
1189 Lisp_Object v1
= POP
;
1190 TOP
= Fdelete_region (TOP
, v1
);
1194 CASE (Bnarrow_to_region
):
1196 Lisp_Object v1
= POP
;
1197 TOP
= Fnarrow_to_region (TOP
, v1
);
1205 CASE (Bend_of_line
):
1206 TOP
= Fend_of_line (TOP
);
1211 Lisp_Object v2
= POP
, v1
= POP
;
1212 TOP
= Fset_marker (TOP
, v1
, v2
);
1216 CASE (Bmatch_beginning
):
1217 TOP
= Fmatch_beginning (TOP
);
1221 TOP
= Fmatch_end (TOP
);
1225 TOP
= Fupcase (TOP
);
1229 TOP
= Fdowncase (TOP
);
1232 CASE (Bstringeqlsign
):
1234 Lisp_Object v1
= POP
;
1235 TOP
= Fstring_equal (TOP
, v1
);
1241 Lisp_Object v1
= POP
;
1242 TOP
= Fstring_lessp (TOP
, v1
);
1248 Lisp_Object v1
= POP
;
1249 TOP
= Fequal (TOP
, v1
);
1255 Lisp_Object v1
= POP
;
1256 TOP
= Fnthcdr (TOP
, v1
);
1264 /* Exchange args and then do nth. */
1265 Lisp_Object v2
= POP
, v1
= TOP
;
1267 for (EMACS_INT n
= XINT (v2
); 0 < n
&& CONSP (v1
); n
--)
1276 Lisp_Object v1
= POP
;
1277 TOP
= Felt (TOP
, v1
);
1284 Lisp_Object v1
= POP
;
1285 TOP
= Fmember (TOP
, v1
);
1291 Lisp_Object v1
= POP
;
1292 TOP
= Fassq (TOP
, v1
);
1297 TOP
= Fnreverse (TOP
);
1302 Lisp_Object v1
= POP
;
1303 TOP
= Fsetcar (TOP
, v1
);
1309 Lisp_Object v1
= POP
;
1310 TOP
= Fsetcdr (TOP
, v1
);
1315 TOP
= CAR_SAFE (TOP
);
1319 TOP
= CDR_SAFE (TOP
);
1324 TOP
= Fnconc (2, &TOP
);
1328 TOP
= NUMBERP (TOP
) ? Qt
: Qnil
;
1332 TOP
= INTEGERP (TOP
) ? Qt
: Qnil
;
1336 /* These are intentionally written using 'case' syntax,
1337 because they are incompatible with the threaded
1341 error ("set-mark is an obsolete bytecode");
1344 error ("scan-buffer is an obsolete bytecode");
1349 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1350 for that instead. */
1351 /* CASE (Bstack_ref): */
1352 error ("Invalid byte opcode: op=%d, ptr=%"pD
"d",
1353 op
, pc
- 1 - bytestr_data
);
1355 /* Handy byte-codes for lexical binding. */
1362 Lisp_Object v1
= top
[Bstack_ref
- op
];
1368 Lisp_Object v1
= top
[- FETCH
];
1374 Lisp_Object v1
= top
[- FETCH2
];
1379 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1381 Lisp_Object
*ptr
= top
- FETCH
;
1387 Lisp_Object
*ptr
= top
- FETCH2
;
1403 /* TODO: Perhaps introduce another byte-code for switch when the
1404 number of cases is less, which uses a simple vector for linear
1405 search as the jump table. */
1406 Lisp_Object jmp_table
= POP
;
1407 if (BYTE_CODE_SAFE
&& !HASH_TABLE_P (jmp_table
))
1409 Lisp_Object v1
= POP
;
1411 struct Lisp_Hash_Table
*h
= XHASH_TABLE (jmp_table
);
1413 /* h->count is a faster approximation for HASH_TABLE_SIZE (h)
1416 { /* Do a linear search if there are not many cases
1417 FIXME: 5 is arbitrarily chosen. */
1418 Lisp_Object hash_code
= h
->test
.cmpfn
1419 ? make_number (h
->test
.hashfn (&h
->test
, v1
)) : Qnil
;
1421 for (i
= h
->count
; 0 <= --i
; )
1422 if (EQ (v1
, HASH_KEY (h
, i
))
1424 && EQ (hash_code
, HASH_HASH (h
, i
))
1425 && h
->test
.cmpfn (&h
->test
, v1
, HASH_KEY (h
, i
))))
1430 i
= hash_lookup (h
, v1
, NULL
);
1434 Lisp_Object val
= HASH_VALUE (h
, i
);
1435 if (BYTE_CODE_SAFE
&& !INTEGERP (val
))
1446 && ! (Bconstant
<= op
&& op
< Bconstant
+ const_length
))
1448 PUSH (vectorp
[op
- Bconstant
]);
1455 /* Binds and unbinds are supposed to be compiled balanced. */
1456 if (SPECPDL_INDEX () != count
)
1458 if (SPECPDL_INDEX () > count
)
1459 unbind_to (count
, Qnil
);
1460 error ("binding stack not balanced (serious byte compiler bug)");
1463 Lisp_Object result
= TOP
;
1468 /* `args_template' has the same meaning as in exec_byte_code() above. */
1470 get_byte_code_arity (Lisp_Object args_template
)
1472 eassert (NATNUMP (args_template
));
1473 EMACS_INT at
= XINT (args_template
);
1474 bool rest
= (at
& 128) != 0;
1475 int mandatory
= at
& 127;
1476 EMACS_INT nonrest
= at
>> 8;
1478 return Fcons (make_number (mandatory
),
1479 rest
? Qmany
: make_number (nonrest
));
1483 syms_of_bytecode (void)
1485 defsubr (&Sbyte_code
);
1487 #ifdef BYTE_CODE_METER
1489 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter
,
1490 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
1491 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1492 opcode CODE has been executed.
1493 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1494 indicates how many times the byte opcodes CODE1 and CODE2 have been
1495 executed in succession. */);
1497 DEFVAR_BOOL ("byte-metering-on", byte_metering_on
,
1498 doc
: /* If non-nil, keep profiling information on byte code usage.
1499 The variable byte-code-meter indicates how often each byte opcode is used.
1500 If a symbol has a property named `byte-code-meter' whose value is an
1501 integer, it is incremented each time that symbol's function is called. */);
1503 byte_metering_on
= false;
1504 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
1505 DEFSYM (Qbyte_code_meter
, "byte-code-meter");
1509 ASET (Vbyte_code_meter
, i
,
1510 Fmake_vector (make_number (256), make_number (0)));