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 "blockinput.h"
40 #include "character.h"
46 #ifdef CHECK_FRAME_FONT
52 * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for
53 * debugging the byte compiler...)
55 * define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
57 /* #define BYTE_CODE_SAFE */
58 /* #define BYTE_CODE_METER */
60 /* If BYTE_CODE_THREADED is defined, then the interpreter will be
61 indirect threaded, using GCC's computed goto extension. This code,
62 as currently implemented, is incompatible with BYTE_CODE_SAFE and
64 #if (defined __GNUC__ && !defined __STRICT_ANSI__ \
65 && !defined BYTE_CODE_SAFE && !defined BYTE_CODE_METER)
66 #define BYTE_CODE_THREADED
70 #ifdef BYTE_CODE_METER
72 Lisp_Object Qbyte_code_meter
;
73 #define METER_2(code1, code2) AREF (AREF (Vbyte_code_meter, code1), code2)
74 #define METER_1(code) METER_2 (0, code)
76 #define METER_CODE(last_code, this_code) \
78 if (byte_metering_on) \
80 if (XFASTINT (METER_1 (this_code)) < MOST_POSITIVE_FIXNUM) \
81 XSETFASTINT (METER_1 (this_code), \
82 XFASTINT (METER_1 (this_code)) + 1); \
84 && (XFASTINT (METER_2 (last_code, this_code)) \
85 < MOST_POSITIVE_FIXNUM)) \
86 XSETFASTINT (METER_2 (last_code, this_code), \
87 XFASTINT (METER_2 (last_code, this_code)) + 1); \
91 #endif /* BYTE_CODE_METER */
97 DEFINE (Bstack_ref, 0) /* Actually, Bstack_ref+0 is not implemented: use dup. */ \
98 DEFINE (Bstack_ref1, 1) \
99 DEFINE (Bstack_ref2, 2) \
100 DEFINE (Bstack_ref3, 3) \
101 DEFINE (Bstack_ref4, 4) \
102 DEFINE (Bstack_ref5, 5) \
103 DEFINE (Bstack_ref6, 6) \
104 DEFINE (Bstack_ref7, 7) \
105 DEFINE (Bvarref, 010) \
106 DEFINE (Bvarref1, 011) \
107 DEFINE (Bvarref2, 012) \
108 DEFINE (Bvarref3, 013) \
109 DEFINE (Bvarref4, 014) \
110 DEFINE (Bvarref5, 015) \
111 DEFINE (Bvarref6, 016) \
112 DEFINE (Bvarref7, 017) \
113 DEFINE (Bvarset, 020) \
114 DEFINE (Bvarset1, 021) \
115 DEFINE (Bvarset2, 022) \
116 DEFINE (Bvarset3, 023) \
117 DEFINE (Bvarset4, 024) \
118 DEFINE (Bvarset5, 025) \
119 DEFINE (Bvarset6, 026) \
120 DEFINE (Bvarset7, 027) \
121 DEFINE (Bvarbind, 030) \
122 DEFINE (Bvarbind1, 031) \
123 DEFINE (Bvarbind2, 032) \
124 DEFINE (Bvarbind3, 033) \
125 DEFINE (Bvarbind4, 034) \
126 DEFINE (Bvarbind5, 035) \
127 DEFINE (Bvarbind6, 036) \
128 DEFINE (Bvarbind7, 037) \
129 DEFINE (Bcall, 040) \
130 DEFINE (Bcall1, 041) \
131 DEFINE (Bcall2, 042) \
132 DEFINE (Bcall3, 043) \
133 DEFINE (Bcall4, 044) \
134 DEFINE (Bcall5, 045) \
135 DEFINE (Bcall6, 046) \
136 DEFINE (Bcall7, 047) \
137 DEFINE (Bunbind, 050) \
138 DEFINE (Bunbind1, 051) \
139 DEFINE (Bunbind2, 052) \
140 DEFINE (Bunbind3, 053) \
141 DEFINE (Bunbind4, 054) \
142 DEFINE (Bunbind5, 055) \
143 DEFINE (Bunbind6, 056) \
144 DEFINE (Bunbind7, 057) \
146 DEFINE (Bpophandler, 060) \
147 DEFINE (Bpushconditioncase, 061) \
148 DEFINE (Bpushcatch, 062) \
151 DEFINE (Bsymbolp, 071) \
152 DEFINE (Bconsp, 072) \
153 DEFINE (Bstringp, 073) \
154 DEFINE (Blistp, 074) \
156 DEFINE (Bmemq, 076) \
158 DEFINE (Bcar, 0100) \
159 DEFINE (Bcdr, 0101) \
160 DEFINE (Bcons, 0102) \
161 DEFINE (Blist1, 0103) \
162 DEFINE (Blist2, 0104) \
163 DEFINE (Blist3, 0105) \
164 DEFINE (Blist4, 0106) \
165 DEFINE (Blength, 0107) \
166 DEFINE (Baref, 0110) \
167 DEFINE (Baset, 0111) \
168 DEFINE (Bsymbol_value, 0112) \
169 DEFINE (Bsymbol_function, 0113) \
170 DEFINE (Bset, 0114) \
171 DEFINE (Bfset, 0115) \
172 DEFINE (Bget, 0116) \
173 DEFINE (Bsubstring, 0117) \
174 DEFINE (Bconcat2, 0120) \
175 DEFINE (Bconcat3, 0121) \
176 DEFINE (Bconcat4, 0122) \
177 DEFINE (Bsub1, 0123) \
178 DEFINE (Badd1, 0124) \
179 DEFINE (Beqlsign, 0125) \
180 DEFINE (Bgtr, 0126) \
181 DEFINE (Blss, 0127) \
182 DEFINE (Bleq, 0130) \
183 DEFINE (Bgeq, 0131) \
184 DEFINE (Bdiff, 0132) \
185 DEFINE (Bnegate, 0133) \
186 DEFINE (Bplus, 0134) \
187 DEFINE (Bmax, 0135) \
188 DEFINE (Bmin, 0136) \
189 DEFINE (Bmult, 0137) \
191 DEFINE (Bpoint, 0140) \
192 /* Was Bmark in v17. */ \
193 DEFINE (Bsave_current_buffer, 0141) /* Obsolete. */ \
194 DEFINE (Bgoto_char, 0142) \
195 DEFINE (Binsert, 0143) \
196 DEFINE (Bpoint_max, 0144) \
197 DEFINE (Bpoint_min, 0145) \
198 DEFINE (Bchar_after, 0146) \
199 DEFINE (Bfollowing_char, 0147) \
200 DEFINE (Bpreceding_char, 0150) \
201 DEFINE (Bcurrent_column, 0151) \
202 DEFINE (Bindent_to, 0152) \
203 DEFINE (Beolp, 0154) \
204 DEFINE (Beobp, 0155) \
205 DEFINE (Bbolp, 0156) \
206 DEFINE (Bbobp, 0157) \
207 DEFINE (Bcurrent_buffer, 0160) \
208 DEFINE (Bset_buffer, 0161) \
209 DEFINE (Bsave_current_buffer_1, 0162) /* Replacing Bsave_current_buffer. */ \
210 DEFINE (Binteractive_p, 0164) /* Obsolete since Emacs-24.1. */ \
212 DEFINE (Bforward_char, 0165) \
213 DEFINE (Bforward_word, 0166) \
214 DEFINE (Bskip_chars_forward, 0167) \
215 DEFINE (Bskip_chars_backward, 0170) \
216 DEFINE (Bforward_line, 0171) \
217 DEFINE (Bchar_syntax, 0172) \
218 DEFINE (Bbuffer_substring, 0173) \
219 DEFINE (Bdelete_region, 0174) \
220 DEFINE (Bnarrow_to_region, 0175) \
221 DEFINE (Bwiden, 0176) \
222 DEFINE (Bend_of_line, 0177) \
224 DEFINE (Bconstant2, 0201) \
225 DEFINE (Bgoto, 0202) \
226 DEFINE (Bgotoifnil, 0203) \
227 DEFINE (Bgotoifnonnil, 0204) \
228 DEFINE (Bgotoifnilelsepop, 0205) \
229 DEFINE (Bgotoifnonnilelsepop, 0206) \
230 DEFINE (Breturn, 0207) \
231 DEFINE (Bdiscard, 0210) \
232 DEFINE (Bdup, 0211) \
234 DEFINE (Bsave_excursion, 0212) \
235 DEFINE (Bsave_window_excursion, 0213) /* Obsolete since Emacs-24.1. */ \
236 DEFINE (Bsave_restriction, 0214) \
237 DEFINE (Bcatch, 0215) \
239 DEFINE (Bunwind_protect, 0216) \
240 DEFINE (Bcondition_case, 0217) \
241 DEFINE (Btemp_output_buffer_setup, 0220) /* Obsolete since Emacs-24.1. */ \
242 DEFINE (Btemp_output_buffer_show, 0221) /* Obsolete since Emacs-24.1. */ \
244 DEFINE (Bunbind_all, 0222) /* Obsolete. Never used. */ \
246 DEFINE (Bset_marker, 0223) \
247 DEFINE (Bmatch_beginning, 0224) \
248 DEFINE (Bmatch_end, 0225) \
249 DEFINE (Bupcase, 0226) \
250 DEFINE (Bdowncase, 0227) \
252 DEFINE (Bstringeqlsign, 0230) \
253 DEFINE (Bstringlss, 0231) \
254 DEFINE (Bequal, 0232) \
255 DEFINE (Bnthcdr, 0233) \
256 DEFINE (Belt, 0234) \
257 DEFINE (Bmember, 0235) \
258 DEFINE (Bassq, 0236) \
259 DEFINE (Bnreverse, 0237) \
260 DEFINE (Bsetcar, 0240) \
261 DEFINE (Bsetcdr, 0241) \
262 DEFINE (Bcar_safe, 0242) \
263 DEFINE (Bcdr_safe, 0243) \
264 DEFINE (Bnconc, 0244) \
265 DEFINE (Bquo, 0245) \
266 DEFINE (Brem, 0246) \
267 DEFINE (Bnumberp, 0247) \
268 DEFINE (Bintegerp, 0250) \
270 DEFINE (BRgoto, 0252) \
271 DEFINE (BRgotoifnil, 0253) \
272 DEFINE (BRgotoifnonnil, 0254) \
273 DEFINE (BRgotoifnilelsepop, 0255) \
274 DEFINE (BRgotoifnonnilelsepop, 0256) \
276 DEFINE (BlistN, 0257) \
277 DEFINE (BconcatN, 0260) \
278 DEFINE (BinsertN, 0261) \
280 /* Bstack_ref is code 0. */ \
281 DEFINE (Bstack_set, 0262) \
282 DEFINE (Bstack_set2, 0263) \
283 DEFINE (BdiscardN, 0266) \
285 DEFINE (Bconstant, 0300)
289 #define DEFINE(name, value) name = value,
293 #ifdef BYTE_CODE_SAFE
294 Bscan_buffer
= 0153, /* No longer generated as of v18. */
295 Bset_mark
= 0163, /* this loser is no longer generated as of v18 */
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 #ifdef BYTE_CODE_SAFE
394 #define FETCH (eassert (stack.byte_string_start == SDATA (stack.byte_string)), *stack.pc++)
396 #define FETCH *stack.pc++
399 /* Fetch two bytes from the bytecode stream and make a 16-bit number
402 #define FETCH2 (op = FETCH, op + (FETCH << 8))
404 /* Push x onto the execution stack. This used to be #define PUSH(x)
405 (*++stackp = (x)) This oddity is necessary because Alliant can't be
406 bothered to compile the preincrement operator properly, as of 4/91.
409 #define PUSH(x) (top++, *top = (x))
411 /* Pop a value off the execution stack. */
415 /* Discard n values from the execution stack. */
417 #define DISCARD(n) (top -= (n))
419 /* Get the value which is at the top of the execution stack, but don't
424 /* Actions that must be performed before and after calling a function
427 #if !BYTE_MAINTAIN_TOP
428 #define BEFORE_POTENTIAL_GC() ((void)0)
429 #define AFTER_POTENTIAL_GC() ((void)0)
431 #define BEFORE_POTENTIAL_GC() stack.top = top
432 #define AFTER_POTENTIAL_GC() stack.top = NULL
435 /* Garbage collect if we have consed enough since the last time.
436 We do this at every branch, to avoid loops that never GC. */
440 BEFORE_POTENTIAL_GC (); \
442 AFTER_POTENTIAL_GC (); \
445 /* Check for jumping out of range. */
447 #ifdef BYTE_CODE_SAFE
449 #define CHECK_RANGE(ARG) \
450 if (ARG >= bytestr_length) emacs_abort ()
452 #else /* not BYTE_CODE_SAFE */
454 #define CHECK_RANGE(ARG)
456 #endif /* not BYTE_CODE_SAFE */
458 /* A version of the QUIT macro which makes sure that the stack top is
459 set before signaling `quit'. */
461 #define BYTE_CODE_QUIT \
463 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
465 Lisp_Object flag = Vquit_flag; \
467 BEFORE_POTENTIAL_GC (); \
468 if (EQ (Vthrow_on_input, flag)) \
469 Fthrow (Vthrow_on_input, Qt); \
470 Fsignal (Qquit, Qnil); \
471 AFTER_POTENTIAL_GC (); \
473 else if (pending_signals) \
474 process_pending_signals (); \
478 DEFUN ("byte-code", Fbyte_code
, Sbyte_code
, 3, 3, 0,
479 doc
: /* Function used internally in byte-compiled code.
480 The first argument, BYTESTR, is a string of byte code;
481 the second, VECTOR, a vector of constants;
482 the third, MAXDEPTH, the maximum stack depth used in this function.
483 If the third argument is incorrect, Emacs may crash. */)
484 (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
)
486 return exec_byte_code (bytestr
, vector
, maxdepth
, Qnil
, 0, NULL
);
490 bcall0 (Lisp_Object f
)
495 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
496 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
497 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
498 argument list (including &rest, &optional, etc.), and ARGS, of size
499 NARGS, should be a vector of the actual arguments. The arguments in
500 ARGS are pushed on the stack according to ARGS_TEMPLATE before
501 executing BYTESTR. */
504 exec_byte_code (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
,
505 Lisp_Object args_template
, ptrdiff_t nargs
, Lisp_Object
*args
)
507 ptrdiff_t count
= SPECPDL_INDEX ();
508 #ifdef BYTE_CODE_METER
509 int volatile this_op
= 0;
513 /* Lisp_Object v1, v2; */
514 Lisp_Object
*vectorp
;
515 #ifdef BYTE_CODE_SAFE
516 ptrdiff_t const_length
;
518 ptrdiff_t bytestr_length
;
520 struct byte_stack stack
;
523 enum handlertype type
;
525 #if 0 /* CHECK_FRAME_FONT */
527 struct frame
*f
= SELECTED_FRAME ();
529 && FRAME_FONT (f
)->direction
!= 0
530 && FRAME_FONT (f
)->direction
!= 1)
535 CHECK_STRING (bytestr
);
536 CHECK_VECTOR (vector
);
537 CHECK_NATNUM (maxdepth
);
539 #ifdef BYTE_CODE_SAFE
540 const_length
= ASIZE (vector
);
543 if (STRING_MULTIBYTE (bytestr
))
544 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
545 because they produced a raw 8-bit string for byte-code and now
546 such a byte-code string is loaded as multibyte while raw 8-bit
547 characters converted to multibyte form. Thus, now we must
548 convert them back to the originally intended unibyte form. */
549 bytestr
= Fstring_as_unibyte (bytestr
);
551 #ifdef BYTE_CODE_SAFE
552 bytestr_length
= SBYTES (bytestr
);
554 vectorp
= XVECTOR (vector
)->contents
;
556 stack
.byte_string
= bytestr
;
557 stack
.pc
= stack
.byte_string_start
= SDATA (bytestr
);
559 stack
.constants
= vector
;
561 if (MAX_ALLOCA
/ word_size
<= XFASTINT (maxdepth
))
562 memory_full (SIZE_MAX
);
563 top
= alloca ((XFASTINT (maxdepth
) + 1) * sizeof *top
);
564 #if BYTE_MAINTAIN_TOP
565 stack
.bottom
= top
+ 1;
568 stack
.next
= byte_stack_list
;
569 byte_stack_list
= &stack
;
571 #ifdef BYTE_CODE_SAFE
572 stacke
= stack
.bottom
- 1 + XFASTINT (maxdepth
);
575 if (INTEGERP (args_template
))
577 ptrdiff_t at
= XINT (args_template
);
578 bool rest
= (at
& 128) != 0;
579 int mandatory
= at
& 127;
580 ptrdiff_t nonrest
= at
>> 8;
581 eassert (mandatory
<= nonrest
);
582 if (nargs
<= nonrest
)
585 for (i
= 0 ; i
< nargs
; i
++, args
++)
587 if (nargs
< mandatory
)
588 /* Too few arguments. */
589 Fsignal (Qwrong_number_of_arguments
,
590 list2 (Fcons (make_number (mandatory
),
591 rest
? Qand_rest
: make_number (nonrest
)),
592 make_number (nargs
)));
595 for (; i
< nonrest
; i
++)
604 for (i
= 0 ; i
< nonrest
; i
++, args
++)
606 PUSH (Flist (nargs
- nonrest
, args
));
609 /* Too many arguments. */
610 Fsignal (Qwrong_number_of_arguments
,
611 list2 (Fcons (make_number (mandatory
), make_number (nonrest
)),
612 make_number (nargs
)));
614 else if (! NILP (args_template
))
615 /* We should push some arguments on the stack. */
617 error ("Unknown args template!");
622 #ifdef BYTE_CODE_SAFE
625 else if (top
< stack
.bottom
- 1)
629 #ifdef BYTE_CODE_METER
631 this_op
= op
= FETCH
;
632 METER_CODE (prev_op
, op
);
634 #ifndef BYTE_CODE_THREADED
639 /* The interpreter can be compiled one of two ways: as an
640 ordinary switch-based interpreter, or as a threaded
641 interpreter. The threaded interpreter relies on GCC's
642 computed goto extension, so it is not available everywhere.
643 Threading provides a performance boost. These macros are how
644 we allow the code to be compiled both ways. */
645 #ifdef BYTE_CODE_THREADED
646 /* The CASE macro introduces an instruction's body. It is
647 either a label or a case label. */
648 #define CASE(OP) insn_ ## OP
649 /* NEXT is invoked at the end of an instruction to go to the
650 next instruction. It is either a computed goto, or a
652 #define NEXT goto *(targets[op = FETCH])
653 /* FIRST is like NEXT, but is only used at the start of the
654 interpreter body. In the switch-based interpreter it is the
655 switch, so the threaded definition must include a semicolon. */
657 /* Most cases are labeled with the CASE macro, above.
658 CASE_DEFAULT is one exception; it is used if the interpreter
659 being built requires a default case. The threaded
660 interpreter does not, because the dispatch table is
661 completely filled. */
663 /* This introduces an instruction that is known to call abort. */
664 #define CASE_ABORT CASE (Bstack_ref): CASE (default)
666 /* See above for the meaning of the various defines. */
667 #define CASE(OP) case OP
669 #define FIRST switch (op)
670 #define CASE_DEFAULT case 255: default:
671 #define CASE_ABORT case 0
674 #ifdef BYTE_CODE_THREADED
676 /* A convenience define that saves us a lot of typing and makes
677 the table clearer. */
678 #define LABEL(OP) [OP] = &&insn_ ## OP
680 #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
681 # pragma GCC diagnostic push
682 # pragma GCC diagnostic ignored "-Woverride-init"
683 #elif defined __clang__
684 # pragma GCC diagnostic push
685 # pragma GCC diagnostic ignored "-Winitializer-overrides"
688 /* This is the dispatch table for the threaded interpreter. */
689 static const void *const targets
[256] =
691 [0 ... (Bconstant
- 1)] = &&insn_default
,
692 [Bconstant
... 255] = &&insn_Bconstant
,
694 #define DEFINE(name, value) LABEL (name) ,
699 #if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) || defined __clang__
700 # pragma GCC diagnostic pop
721 /* This seems to be the most frequently executed byte-code
722 among the Bvarref's, so avoid a goto here. */
732 if (XSYMBOL (v1
)->redirect
!= SYMBOL_PLAINVAL
733 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)),
736 BEFORE_POTENTIAL_GC ();
737 v2
= Fsymbol_value (v1
);
738 AFTER_POTENTIAL_GC ();
743 BEFORE_POTENTIAL_GC ();
744 v2
= Fsymbol_value (v1
);
745 AFTER_POTENTIAL_GC ();
761 stack
.pc
= stack
.byte_string_start
+ op
;
776 BEFORE_POTENTIAL_GC ();
777 wrong_type_argument (Qlistp
, v1
);
786 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
793 BEFORE_POTENTIAL_GC ();
795 TOP
= Fmemq (TOP
, v1
);
796 AFTER_POTENTIAL_GC ();
810 BEFORE_POTENTIAL_GC ();
811 wrong_type_argument (Qlistp
, v1
);
833 Lisp_Object sym
, val
;
838 /* Inline the most common case. */
840 && !EQ (val
, Qunbound
)
841 && !XSYMBOL (sym
)->redirect
842 && !SYMBOL_CONSTANT_P (sym
))
843 SET_SYMBOL_VAL (XSYMBOL (sym
), val
);
846 BEFORE_POTENTIAL_GC ();
847 set_internal (sym
, val
, Qnil
, 0);
848 AFTER_POTENTIAL_GC ();
862 /* ------------------ */
880 /* Specbind can signal and thus GC. */
881 BEFORE_POTENTIAL_GC ();
882 specbind (vectorp
[op
], POP
);
883 AFTER_POTENTIAL_GC ();
903 BEFORE_POTENTIAL_GC ();
905 #ifdef BYTE_CODE_METER
906 if (byte_metering_on
&& SYMBOLP (TOP
))
911 v2
= Fget (v1
, Qbyte_code_meter
);
913 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
915 XSETINT (v2
, XINT (v2
) + 1);
916 Fput (v1
, Qbyte_code_meter
, v2
);
920 TOP
= Ffuncall (op
+ 1, &TOP
);
921 AFTER_POTENTIAL_GC ();
941 BEFORE_POTENTIAL_GC ();
942 unbind_to (SPECPDL_INDEX () - op
, Qnil
);
943 AFTER_POTENTIAL_GC ();
946 CASE (Bunbind_all
): /* Obsolete. Never used. */
947 /* To unbind back to the beginning of this frame. Not used yet,
948 but will be needed for tail-recursion elimination. */
949 BEFORE_POTENTIAL_GC ();
950 unbind_to (count
, Qnil
);
951 AFTER_POTENTIAL_GC ();
957 op
= FETCH2
; /* pc = FETCH2 loses since FETCH2 contains pc++ */
959 stack
.pc
= stack
.byte_string_start
+ op
;
962 CASE (Bgotoifnonnil
):
972 stack
.pc
= stack
.byte_string_start
+ op
;
977 CASE (Bgotoifnilelsepop
):
984 stack
.pc
= stack
.byte_string_start
+ op
;
989 CASE (Bgotoifnonnilelsepop
):
996 stack
.pc
= stack
.byte_string_start
+ op
;
1004 stack
.pc
+= (int) *stack
.pc
- 127;
1015 stack
.pc
+= (int) *stack
.pc
- 128;
1021 CASE (BRgotoifnonnil
):
1029 stack
.pc
+= (int) *stack
.pc
- 128;
1035 CASE (BRgotoifnilelsepop
):
1041 stack
.pc
+= op
- 128;
1046 CASE (BRgotoifnonnilelsepop
):
1052 stack
.pc
+= op
- 128;
1066 PUSH (vectorp
[FETCH2
]);
1069 CASE (Bsave_excursion
):
1070 record_unwind_protect (save_excursion_restore
,
1071 save_excursion_save ());
1074 CASE (Bsave_current_buffer
): /* Obsolete since ??. */
1075 CASE (Bsave_current_buffer_1
):
1076 record_unwind_current_buffer ();
1079 CASE (Bsave_window_excursion
): /* Obsolete since 24.1. */
1081 ptrdiff_t count1
= SPECPDL_INDEX ();
1082 record_unwind_protect (restore_window_configuration
,
1083 Fcurrent_window_configuration (Qnil
));
1084 BEFORE_POTENTIAL_GC ();
1086 unbind_to (count1
, TOP
);
1087 AFTER_POTENTIAL_GC ();
1091 CASE (Bsave_restriction
):
1092 record_unwind_protect (save_restriction_restore
,
1093 save_restriction_save ());
1096 CASE (Bcatch
): /* Obsolete since 24.4. */
1099 BEFORE_POTENTIAL_GC ();
1101 TOP
= internal_catch (TOP
, eval_sub
, v1
);
1102 AFTER_POTENTIAL_GC ();
1106 CASE (Bpushcatch
): /* New in 24.4. */
1109 CASE (Bpushconditioncase
): /* New in 24.4. */
1115 type
= CONDITION_CASE
;
1120 PUSH_HANDLER (c
, tag
, type
);
1121 c
->bytecode_dest
= dest
;
1122 c
->bytecode_top
= top
;
1124 if (sys_setjmp (c
->jmp
))
1126 struct handler
*c
= handlerlist
;
1128 top
= c
->bytecode_top
;
1129 dest
= c
->bytecode_dest
;
1130 handlerlist
= c
->next
;
1133 /* Might have been re-set by longjmp! */
1134 stack
.byte_string_start
= SDATA (stack
.byte_string
);
1135 stack
.pc
= stack
.byte_string_start
+ dest
;
1141 CASE (Bpophandler
): /* New in 24.4. */
1143 handlerlist
= handlerlist
->next
;
1147 CASE (Bunwind_protect
): /* FIXME: avoid closure for lexbind. */
1149 Lisp_Object handler
= POP
;
1150 /* Support for a function here is new in 24.4. */
1151 record_unwind_protect (NILP (Ffunctionp (handler
))
1152 ? unwind_body
: bcall0
,
1157 CASE (Bcondition_case
): /* Obsolete since 24.4. */
1159 Lisp_Object handlers
, body
;
1162 BEFORE_POTENTIAL_GC ();
1163 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
);
1164 AFTER_POTENTIAL_GC ();
1168 CASE (Btemp_output_buffer_setup
): /* Obsolete since 24.1. */
1169 BEFORE_POTENTIAL_GC ();
1171 temp_output_buffer_setup (SSDATA (TOP
));
1172 AFTER_POTENTIAL_GC ();
1173 TOP
= Vstandard_output
;
1176 CASE (Btemp_output_buffer_show
): /* Obsolete since 24.1. */
1179 BEFORE_POTENTIAL_GC ();
1181 temp_output_buffer_show (TOP
);
1183 /* pop binding of standard-output */
1184 unbind_to (SPECPDL_INDEX () - 1, Qnil
);
1185 AFTER_POTENTIAL_GC ();
1193 BEFORE_POTENTIAL_GC ();
1199 while (--n
>= 0 && CONSP (v1
))
1203 AFTER_POTENTIAL_GC ();
1208 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
1212 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
1216 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
1220 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
1224 TOP
= NILP (TOP
) ? Qt
: Qnil
;
1231 TOP
= Fcons (TOP
, v1
);
1243 TOP
= list2 (TOP
, v1
);
1249 TOP
= Flist (3, &TOP
);
1254 TOP
= Flist (4, &TOP
);
1260 TOP
= Flist (op
, &TOP
);
1264 BEFORE_POTENTIAL_GC ();
1265 TOP
= Flength (TOP
);
1266 AFTER_POTENTIAL_GC ();
1272 BEFORE_POTENTIAL_GC ();
1274 TOP
= Faref (TOP
, v1
);
1275 AFTER_POTENTIAL_GC ();
1282 BEFORE_POTENTIAL_GC ();
1284 TOP
= Faset (TOP
, v1
, v2
);
1285 AFTER_POTENTIAL_GC ();
1289 CASE (Bsymbol_value
):
1290 BEFORE_POTENTIAL_GC ();
1291 TOP
= Fsymbol_value (TOP
);
1292 AFTER_POTENTIAL_GC ();
1295 CASE (Bsymbol_function
):
1296 BEFORE_POTENTIAL_GC ();
1297 TOP
= Fsymbol_function (TOP
);
1298 AFTER_POTENTIAL_GC ();
1304 BEFORE_POTENTIAL_GC ();
1306 TOP
= Fset (TOP
, v1
);
1307 AFTER_POTENTIAL_GC ();
1314 BEFORE_POTENTIAL_GC ();
1316 TOP
= Ffset (TOP
, v1
);
1317 AFTER_POTENTIAL_GC ();
1324 BEFORE_POTENTIAL_GC ();
1326 TOP
= Fget (TOP
, v1
);
1327 AFTER_POTENTIAL_GC ();
1334 BEFORE_POTENTIAL_GC ();
1336 TOP
= Fsubstring (TOP
, v1
, v2
);
1337 AFTER_POTENTIAL_GC ();
1342 BEFORE_POTENTIAL_GC ();
1344 TOP
= Fconcat (2, &TOP
);
1345 AFTER_POTENTIAL_GC ();
1349 BEFORE_POTENTIAL_GC ();
1351 TOP
= Fconcat (3, &TOP
);
1352 AFTER_POTENTIAL_GC ();
1356 BEFORE_POTENTIAL_GC ();
1358 TOP
= Fconcat (4, &TOP
);
1359 AFTER_POTENTIAL_GC ();
1364 BEFORE_POTENTIAL_GC ();
1366 TOP
= Fconcat (op
, &TOP
);
1367 AFTER_POTENTIAL_GC ();
1376 XSETINT (v1
, XINT (v1
) - 1);
1381 BEFORE_POTENTIAL_GC ();
1383 AFTER_POTENTIAL_GC ();
1394 XSETINT (v1
, XINT (v1
) + 1);
1399 BEFORE_POTENTIAL_GC ();
1401 AFTER_POTENTIAL_GC ();
1409 BEFORE_POTENTIAL_GC ();
1411 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
1412 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
1413 AFTER_POTENTIAL_GC ();
1414 if (FLOATP (v1
) || FLOATP (v2
))
1418 f1
= (FLOATP (v1
) ? XFLOAT_DATA (v1
) : XINT (v1
));
1419 f2
= (FLOATP (v2
) ? XFLOAT_DATA (v2
) : XINT (v2
));
1420 TOP
= (f1
== f2
? Qt
: Qnil
);
1423 TOP
= (XINT (v1
) == XINT (v2
) ? Qt
: Qnil
);
1430 BEFORE_POTENTIAL_GC ();
1432 TOP
= arithcompare (TOP
, v1
, ARITH_GRTR
);
1433 AFTER_POTENTIAL_GC ();
1440 BEFORE_POTENTIAL_GC ();
1442 TOP
= arithcompare (TOP
, v1
, ARITH_LESS
);
1443 AFTER_POTENTIAL_GC ();
1450 BEFORE_POTENTIAL_GC ();
1452 TOP
= arithcompare (TOP
, v1
, ARITH_LESS_OR_EQUAL
);
1453 AFTER_POTENTIAL_GC ();
1460 BEFORE_POTENTIAL_GC ();
1462 TOP
= arithcompare (TOP
, v1
, ARITH_GRTR_OR_EQUAL
);
1463 AFTER_POTENTIAL_GC ();
1468 BEFORE_POTENTIAL_GC ();
1470 TOP
= Fminus (2, &TOP
);
1471 AFTER_POTENTIAL_GC ();
1480 XSETINT (v1
, - XINT (v1
));
1485 BEFORE_POTENTIAL_GC ();
1486 TOP
= Fminus (1, &TOP
);
1487 AFTER_POTENTIAL_GC ();
1493 BEFORE_POTENTIAL_GC ();
1495 TOP
= Fplus (2, &TOP
);
1496 AFTER_POTENTIAL_GC ();
1500 BEFORE_POTENTIAL_GC ();
1502 TOP
= Fmax (2, &TOP
);
1503 AFTER_POTENTIAL_GC ();
1507 BEFORE_POTENTIAL_GC ();
1509 TOP
= Fmin (2, &TOP
);
1510 AFTER_POTENTIAL_GC ();
1514 BEFORE_POTENTIAL_GC ();
1516 TOP
= Ftimes (2, &TOP
);
1517 AFTER_POTENTIAL_GC ();
1521 BEFORE_POTENTIAL_GC ();
1523 TOP
= Fquo (2, &TOP
);
1524 AFTER_POTENTIAL_GC ();
1530 BEFORE_POTENTIAL_GC ();
1532 TOP
= Frem (TOP
, v1
);
1533 AFTER_POTENTIAL_GC ();
1540 XSETFASTINT (v1
, PT
);
1546 BEFORE_POTENTIAL_GC ();
1547 TOP
= Fgoto_char (TOP
);
1548 AFTER_POTENTIAL_GC ();
1552 BEFORE_POTENTIAL_GC ();
1553 TOP
= Finsert (1, &TOP
);
1554 AFTER_POTENTIAL_GC ();
1559 BEFORE_POTENTIAL_GC ();
1561 TOP
= Finsert (op
, &TOP
);
1562 AFTER_POTENTIAL_GC ();
1568 XSETFASTINT (v1
, ZV
);
1576 XSETFASTINT (v1
, BEGV
);
1582 BEFORE_POTENTIAL_GC ();
1583 TOP
= Fchar_after (TOP
);
1584 AFTER_POTENTIAL_GC ();
1587 CASE (Bfollowing_char
):
1590 BEFORE_POTENTIAL_GC ();
1591 v1
= Ffollowing_char ();
1592 AFTER_POTENTIAL_GC ();
1597 CASE (Bpreceding_char
):
1600 BEFORE_POTENTIAL_GC ();
1601 v1
= Fprevious_char ();
1602 AFTER_POTENTIAL_GC ();
1607 CASE (Bcurrent_column
):
1610 BEFORE_POTENTIAL_GC ();
1611 XSETFASTINT (v1
, current_column ());
1612 AFTER_POTENTIAL_GC ();
1618 BEFORE_POTENTIAL_GC ();
1619 TOP
= Findent_to (TOP
, Qnil
);
1620 AFTER_POTENTIAL_GC ();
1639 CASE (Bcurrent_buffer
):
1640 PUSH (Fcurrent_buffer ());
1644 BEFORE_POTENTIAL_GC ();
1645 TOP
= Fset_buffer (TOP
);
1646 AFTER_POTENTIAL_GC ();
1649 CASE (Binteractive_p
): /* Obsolete since 24.1. */
1650 BEFORE_POTENTIAL_GC ();
1651 PUSH (call0 (intern ("interactive-p")));
1652 AFTER_POTENTIAL_GC ();
1655 CASE (Bforward_char
):
1656 BEFORE_POTENTIAL_GC ();
1657 TOP
= Fforward_char (TOP
);
1658 AFTER_POTENTIAL_GC ();
1661 CASE (Bforward_word
):
1662 BEFORE_POTENTIAL_GC ();
1663 TOP
= Fforward_word (TOP
);
1664 AFTER_POTENTIAL_GC ();
1667 CASE (Bskip_chars_forward
):
1670 BEFORE_POTENTIAL_GC ();
1672 TOP
= Fskip_chars_forward (TOP
, v1
);
1673 AFTER_POTENTIAL_GC ();
1677 CASE (Bskip_chars_backward
):
1680 BEFORE_POTENTIAL_GC ();
1682 TOP
= Fskip_chars_backward (TOP
, v1
);
1683 AFTER_POTENTIAL_GC ();
1687 CASE (Bforward_line
):
1688 BEFORE_POTENTIAL_GC ();
1689 TOP
= Fforward_line (TOP
);
1690 AFTER_POTENTIAL_GC ();
1693 CASE (Bchar_syntax
):
1697 BEFORE_POTENTIAL_GC ();
1698 CHECK_CHARACTER (TOP
);
1699 AFTER_POTENTIAL_GC ();
1701 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
1702 MAKE_CHAR_MULTIBYTE (c
);
1703 XSETFASTINT (TOP
, syntax_code_spec
[SYNTAX (c
)]);
1707 CASE (Bbuffer_substring
):
1710 BEFORE_POTENTIAL_GC ();
1712 TOP
= Fbuffer_substring (TOP
, v1
);
1713 AFTER_POTENTIAL_GC ();
1717 CASE (Bdelete_region
):
1720 BEFORE_POTENTIAL_GC ();
1722 TOP
= Fdelete_region (TOP
, v1
);
1723 AFTER_POTENTIAL_GC ();
1727 CASE (Bnarrow_to_region
):
1730 BEFORE_POTENTIAL_GC ();
1732 TOP
= Fnarrow_to_region (TOP
, v1
);
1733 AFTER_POTENTIAL_GC ();
1738 BEFORE_POTENTIAL_GC ();
1740 AFTER_POTENTIAL_GC ();
1743 CASE (Bend_of_line
):
1744 BEFORE_POTENTIAL_GC ();
1745 TOP
= Fend_of_line (TOP
);
1746 AFTER_POTENTIAL_GC ();
1752 BEFORE_POTENTIAL_GC ();
1755 TOP
= Fset_marker (TOP
, v2
, v1
);
1756 AFTER_POTENTIAL_GC ();
1760 CASE (Bmatch_beginning
):
1761 BEFORE_POTENTIAL_GC ();
1762 TOP
= Fmatch_beginning (TOP
);
1763 AFTER_POTENTIAL_GC ();
1767 BEFORE_POTENTIAL_GC ();
1768 TOP
= Fmatch_end (TOP
);
1769 AFTER_POTENTIAL_GC ();
1773 BEFORE_POTENTIAL_GC ();
1774 TOP
= Fupcase (TOP
);
1775 AFTER_POTENTIAL_GC ();
1779 BEFORE_POTENTIAL_GC ();
1780 TOP
= Fdowncase (TOP
);
1781 AFTER_POTENTIAL_GC ();
1784 CASE (Bstringeqlsign
):
1787 BEFORE_POTENTIAL_GC ();
1789 TOP
= Fstring_equal (TOP
, v1
);
1790 AFTER_POTENTIAL_GC ();
1797 BEFORE_POTENTIAL_GC ();
1799 TOP
= Fstring_lessp (TOP
, v1
);
1800 AFTER_POTENTIAL_GC ();
1808 TOP
= Fequal (TOP
, v1
);
1815 BEFORE_POTENTIAL_GC ();
1817 TOP
= Fnthcdr (TOP
, v1
);
1818 AFTER_POTENTIAL_GC ();
1827 /* Exchange args and then do nth. */
1829 BEFORE_POTENTIAL_GC ();
1833 AFTER_POTENTIAL_GC ();
1836 while (--n
>= 0 && CONSP (v1
))
1843 BEFORE_POTENTIAL_GC ();
1845 TOP
= Felt (TOP
, v1
);
1846 AFTER_POTENTIAL_GC ();
1854 BEFORE_POTENTIAL_GC ();
1856 TOP
= Fmember (TOP
, v1
);
1857 AFTER_POTENTIAL_GC ();
1864 BEFORE_POTENTIAL_GC ();
1866 TOP
= Fassq (TOP
, v1
);
1867 AFTER_POTENTIAL_GC ();
1872 BEFORE_POTENTIAL_GC ();
1873 TOP
= Fnreverse (TOP
);
1874 AFTER_POTENTIAL_GC ();
1880 BEFORE_POTENTIAL_GC ();
1882 TOP
= Fsetcar (TOP
, v1
);
1883 AFTER_POTENTIAL_GC ();
1890 BEFORE_POTENTIAL_GC ();
1892 TOP
= Fsetcdr (TOP
, v1
);
1893 AFTER_POTENTIAL_GC ();
1901 TOP
= CAR_SAFE (v1
);
1909 TOP
= CDR_SAFE (v1
);
1914 BEFORE_POTENTIAL_GC ();
1916 TOP
= Fnconc (2, &TOP
);
1917 AFTER_POTENTIAL_GC ();
1921 TOP
= (NUMBERP (TOP
) ? Qt
: Qnil
);
1925 TOP
= INTEGERP (TOP
) ? Qt
: Qnil
;
1928 #ifdef BYTE_CODE_SAFE
1929 /* These are intentionally written using 'case' syntax,
1930 because they are incompatible with the threaded
1934 BEFORE_POTENTIAL_GC ();
1935 error ("set-mark is an obsolete bytecode");
1936 AFTER_POTENTIAL_GC ();
1939 BEFORE_POTENTIAL_GC ();
1940 error ("scan-buffer is an obsolete bytecode");
1941 AFTER_POTENTIAL_GC ();
1946 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1947 for that instead. */
1948 /* CASE (Bstack_ref): */
1949 call3 (intern ("error"),
1950 build_string ("Invalid byte opcode: op=%s, ptr=%d"),
1952 make_number ((stack
.pc
- 1) - stack
.byte_string_start
));
1954 /* Handy byte-codes for lexical binding. */
1961 Lisp_Object
*ptr
= top
- (op
- Bstack_ref
);
1967 Lisp_Object
*ptr
= top
- (FETCH
);
1973 Lisp_Object
*ptr
= top
- (FETCH2
);
1978 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1980 Lisp_Object
*ptr
= top
- (FETCH
);
1986 Lisp_Object
*ptr
= top
- (FETCH2
);
2002 #ifdef BYTE_CODE_SAFE
2007 if ((op
-= Bconstant
) >= const_length
)
2013 PUSH (vectorp
[op
- Bconstant
]);
2021 byte_stack_list
= byte_stack_list
->next
;
2023 /* Binds and unbinds are supposed to be compiled balanced. */
2024 if (SPECPDL_INDEX () != count
)
2026 if (SPECPDL_INDEX () > count
)
2027 unbind_to (count
, Qnil
);
2028 error ("binding stack not balanced (serious byte compiler bug)");
2035 syms_of_bytecode (void)
2037 defsubr (&Sbyte_code
);
2039 #ifdef BYTE_CODE_METER
2041 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter
,
2042 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
2043 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
2044 opcode CODE has been executed.
2045 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
2046 indicates how many times the byte opcodes CODE1 and CODE2 have been
2047 executed in succession. */);
2049 DEFVAR_BOOL ("byte-metering-on", byte_metering_on
,
2050 doc
: /* If non-nil, keep profiling information on byte code usage.
2051 The variable byte-code-meter indicates how often each byte opcode is used.
2052 If a symbol has a property named `byte-code-meter' whose value is an
2053 integer, it is incremented each time that symbol's function is called. */);
2055 byte_metering_on
= 0;
2056 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
2057 DEFSYM (Qbyte_code_meter
, "byte-code-meter");
2061 ASET (Vbyte_code_meter
, i
,
2062 Fmake_vector (make_number (256), make_number (0)));