1 /* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985-1988, 1993, 2000-2011 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 hacked on by jwz@lucid.com 17-jun-91
21 o added a compile-time switch to turn on simple sanity checking;
22 o put back the obsolete byte-codes for error-detection;
23 o added a new instruction, unbind_all, which I will use for
24 tail-recursion elimination;
25 o made temp_output_buffer_show be called with the right number
27 o made the new bytecodes be called with args in the right order;
28 o added metering support.
31 o added relative jump instructions;
32 o all conditionals now only do QUIT if they jump.
39 #include "character.h"
43 #ifdef CHECK_FRAME_FONT
49 * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for
50 * debugging the byte compiler...)
52 * define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
54 /* #define BYTE_CODE_SAFE 1 */
55 /* #define BYTE_CODE_METER */
58 #ifdef BYTE_CODE_METER
60 Lisp_Object Qbyte_code_meter
;
61 #define METER_2(code1, code2) \
62 XFASTINT (XVECTOR (XVECTOR (Vbyte_code_meter)->contents[(code1)]) \
65 #define METER_1(code) METER_2 (0, (code))
67 #define METER_CODE(last_code, this_code) \
69 if (byte_metering_on) \
71 if (METER_1 (this_code) < MOST_POSITIVE_FIXNUM) \
72 METER_1 (this_code)++; \
74 && METER_2 (last_code, this_code) < MOST_POSITIVE_FIXNUM) \
75 METER_2 (last_code, this_code)++; \
79 #else /* no BYTE_CODE_METER */
81 #define METER_CODE(last_code, this_code)
83 #endif /* no BYTE_CODE_METER */
86 Lisp_Object Qbytecode
;
87 extern Lisp_Object Qand_optional
, Qand_rest
;
91 #define Bstack_ref 0 /* Actually, Bstack_ref+0 is not implemented: use dup. */
116 #define Bsymbol_value 0112
117 #define Bsymbol_function 0113
121 #define Bsubstring 0117
122 #define Bconcat2 0120
123 #define Bconcat3 0121
124 #define Bconcat4 0122
127 #define Beqlsign 0125
140 /* Was Bmark in v17. */
141 #define Bsave_current_buffer 0141 /* Obsolete. */
142 #define Bgoto_char 0142
144 #define Bpoint_max 0144
145 #define Bpoint_min 0145
146 #define Bchar_after 0146
147 #define Bfollowing_char 0147
148 #define Bpreceding_char 0150
149 #define Bcurrent_column 0151
150 #define Bindent_to 0152
151 #define Bscan_buffer 0153 /* No longer generated as of v18 */
156 #define Bcurrent_buffer 0160
157 #define Bset_buffer 0161
158 #define Bsave_current_buffer_1 0162 /* Replacing Bsave_current_buffer. */
159 #define Bread_char 0162 /* No longer generated as of v19 */
160 #define Bset_mark 0163 /* this loser is no longer generated as of v18 */
161 #define Binteractive_p 0164 /* Obsolete. */
163 #define Bforward_char 0165
164 #define Bforward_word 0166
165 #define Bskip_chars_forward 0167
166 #define Bskip_chars_backward 0170
167 #define Bforward_line 0171
168 #define Bchar_syntax 0172
169 #define Bbuffer_substring 0173
170 #define Bdelete_region 0174
171 #define Bnarrow_to_region 0175
173 #define Bend_of_line 0177
175 #define Bconstant2 0201
177 #define Bgotoifnil 0203
178 #define Bgotoifnonnil 0204
179 #define Bgotoifnilelsepop 0205
180 #define Bgotoifnonnilelsepop 0206
182 #define Bdiscard 0210
185 #define Bsave_excursion 0212
186 #define Bsave_window_excursion 0213 /* Obsolete. */
187 #define Bsave_restriction 0214
190 #define Bunwind_protect 0216
191 #define Bcondition_case 0217
192 #define Btemp_output_buffer_setup 0220 /* Obsolete. */
193 #define Btemp_output_buffer_show 0221 /* Obsolete. */
195 #define Bunbind_all 0222 /* Obsolete. */
197 #define Bset_marker 0223
198 #define Bmatch_beginning 0224
199 #define Bmatch_end 0225
201 #define Bdowncase 0227
203 #define Bstringeqlsign 0230
204 #define Bstringlss 0231
210 #define Bnreverse 0237
213 #define Bcar_safe 0242
214 #define Bcdr_safe 0243
218 #define Bnumberp 0247
219 #define Bintegerp 0250
222 #define BRgotoifnil 0253
223 #define BRgotoifnonnil 0254
224 #define BRgotoifnilelsepop 0255
225 #define BRgotoifnonnilelsepop 0256
228 #define BconcatN 0260
229 #define BinsertN 0261
231 /* Bstack_ref is code 0. */
232 #define Bstack_set 0262
233 #define Bstack_set2 0263
234 #define BdiscardN 0266
236 #define Bconstant 0300
237 #define CONSTANTLIM 0100
239 /* Whether to maintain a `top' and `bottom' field in the stack frame. */
240 #define BYTE_MAINTAIN_TOP (BYTE_CODE_SAFE || BYTE_MARK_STACK)
242 /* Structure describing a value stack used during byte-code execution
247 /* Program counter. This points into the byte_string below
248 and is relocated when that string is relocated. */
249 const unsigned char *pc
;
251 /* Top and bottom of stack. The bottom points to an area of memory
252 allocated with alloca in Fbyte_code. */
253 #if BYTE_MAINTAIN_TOP
254 Lisp_Object
*top
, *bottom
;
257 /* The string containing the byte-code, and its current address.
258 Storing this here protects it from GC because mark_byte_stack
260 Lisp_Object byte_string
;
261 const unsigned char *byte_string_start
;
263 /* The vector of constants used during byte-code execution. Storing
264 this here protects it from GC because mark_byte_stack marks it. */
265 Lisp_Object constants
;
267 /* Next entry in byte_stack_list. */
268 struct byte_stack
*next
;
271 /* A list of currently active byte-code execution value stacks.
272 Fbyte_code adds an entry to the head of this list before it starts
273 processing byte-code, and it removed the entry again when it is
274 done. Signalling an error truncates the list analoguous to
277 struct byte_stack
*byte_stack_list
;
280 /* Mark objects on byte_stack_list. Called during GC. */
284 mark_byte_stack (void)
286 struct byte_stack
*stack
;
289 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
291 /* If STACK->top is null here, this means there's an opcode in
292 Fbyte_code that wasn't expected to GC, but did. To find out
293 which opcode this is, record the value of `stack', and walk
294 up the stack in a debugger, stopping in frames of Fbyte_code.
295 The culprit is found in the frame of Fbyte_code where the
296 address of its local variable `stack' is equal to the
297 recorded value of `stack' here. */
298 eassert (stack
->top
);
300 for (obj
= stack
->bottom
; obj
<= stack
->top
; ++obj
)
303 mark_object (stack
->byte_string
);
304 mark_object (stack
->constants
);
309 /* Unmark objects in the stacks on byte_stack_list. Relocate program
310 counters. Called when GC has completed. */
313 unmark_byte_stack (void)
315 struct byte_stack
*stack
;
317 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
319 if (stack
->byte_string_start
!= SDATA (stack
->byte_string
))
321 int offset
= stack
->pc
- stack
->byte_string_start
;
322 stack
->byte_string_start
= SDATA (stack
->byte_string
);
323 stack
->pc
= stack
->byte_string_start
+ offset
;
329 /* Fetch the next byte from the bytecode stream */
331 #define FETCH *stack.pc++
333 /* Fetch two bytes from the bytecode stream and make a 16-bit number
336 #define FETCH2 (op = FETCH, op + (FETCH << 8))
338 /* Push x onto the execution stack. This used to be #define PUSH(x)
339 (*++stackp = (x)) This oddity is necessary because Alliant can't be
340 bothered to compile the preincrement operator properly, as of 4/91.
343 #define PUSH(x) (top++, *top = (x))
345 /* Pop a value off the execution stack. */
349 /* Discard n values from the execution stack. */
351 #define DISCARD(n) (top -= (n))
353 /* Get the value which is at the top of the execution stack, but don't
358 /* Actions that must be performed before and after calling a function
361 #if !BYTE_MAINTAIN_TOP
362 #define BEFORE_POTENTIAL_GC() ((void)0)
363 #define AFTER_POTENTIAL_GC() ((void)0)
365 #define BEFORE_POTENTIAL_GC() stack.top = top
366 #define AFTER_POTENTIAL_GC() stack.top = NULL
369 /* Garbage collect if we have consed enough since the last time.
370 We do this at every branch, to avoid loops that never GC. */
373 if (consing_since_gc > gc_cons_threshold \
374 && consing_since_gc > gc_relative_threshold) \
376 BEFORE_POTENTIAL_GC (); \
377 Fgarbage_collect (); \
378 AFTER_POTENTIAL_GC (); \
382 /* Check for jumping out of range. */
384 #ifdef BYTE_CODE_SAFE
386 #define CHECK_RANGE(ARG) \
387 if (ARG >= bytestr_length) abort ()
389 #else /* not BYTE_CODE_SAFE */
391 #define CHECK_RANGE(ARG)
393 #endif /* not BYTE_CODE_SAFE */
395 /* A version of the QUIT macro which makes sure that the stack top is
396 set before signaling `quit'. */
398 #define BYTE_CODE_QUIT \
400 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
402 Lisp_Object flag = Vquit_flag; \
404 BEFORE_POTENTIAL_GC (); \
405 if (EQ (Vthrow_on_input, flag)) \
406 Fthrow (Vthrow_on_input, Qt); \
407 Fsignal (Qquit, Qnil); \
408 AFTER_POTENTIAL_GC (); \
410 ELSE_PENDING_SIGNALS \
414 DEFUN ("byte-code", Fbyte_code
, Sbyte_code
, 3, MANY
, 0,
415 doc
: /* Function used internally in byte-compiled code.
416 The first argument, BYTESTR, is a string of byte code;
417 the second, VECTOR, a vector of constants;
418 the third, MAXDEPTH, the maximum stack depth used in this function.
419 If the third argument is incorrect, Emacs may crash.
421 If ARGS-TEMPLATE is specified, it is an argument list specification,
422 according to which any remaining arguments are pushed on the stack
423 before executing BYTESTR.
425 usage: (byte-code BYTESTR VECTOR MAXDEP &optional ARGS-TEMPLATE &rest ARGS) */)
426 (int nargs
, Lisp_Object
*args
)
428 Lisp_Object args_tmpl
= nargs
>= 4 ? args
[3] : Qnil
;
429 int pnargs
= nargs
>= 4 ? nargs
- 4 : 0;
430 Lisp_Object
*pargs
= nargs
>= 4 ? args
+ 4 : 0;
431 return exec_byte_code (args
[0], args
[1], args
[2], args_tmpl
, pnargs
, pargs
);
434 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
435 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
436 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
437 argument list (including &rest, &optional, etc.), and ARGS, of size
438 NARGS, should be a vector of the actual arguments. The arguments in
439 ARGS are pushed on the stack according to ARGS_TEMPLATE before
440 executing BYTESTR. */
443 exec_byte_code (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
,
444 Lisp_Object args_template
, int nargs
, Lisp_Object
*args
)
446 int count
= SPECPDL_INDEX ();
447 #ifdef BYTE_CODE_METER
452 /* Lisp_Object v1, v2; */
453 Lisp_Object
*vectorp
;
454 #ifdef BYTE_CODE_SAFE
455 int const_length
= XVECTOR (vector
)->size
;
459 struct byte_stack stack
;
463 #if 0 /* CHECK_FRAME_FONT */
465 struct frame
*f
= SELECTED_FRAME ();
467 && FRAME_FONT (f
)->direction
!= 0
468 && FRAME_FONT (f
)->direction
!= 1)
473 CHECK_STRING (bytestr
);
474 CHECK_VECTOR (vector
);
475 CHECK_NUMBER (maxdepth
);
477 if (STRING_MULTIBYTE (bytestr
))
478 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
479 because they produced a raw 8-bit string for byte-code and now
480 such a byte-code string is loaded as multibyte while raw 8-bit
481 characters converted to multibyte form. Thus, now we must
482 convert them back to the originally intended unibyte form. */
483 bytestr
= Fstring_as_unibyte (bytestr
);
485 bytestr_length
= SBYTES (bytestr
);
486 vectorp
= XVECTOR (vector
)->contents
;
488 stack
.byte_string
= bytestr
;
489 stack
.pc
= stack
.byte_string_start
= SDATA (bytestr
);
490 stack
.constants
= vector
;
491 top
= (Lisp_Object
*) alloca (XFASTINT (maxdepth
)
492 * sizeof (Lisp_Object
));
493 #if BYTE_MAINTAIN_TOP
498 stack
.next
= byte_stack_list
;
499 byte_stack_list
= &stack
;
501 #ifdef BYTE_CODE_SAFE
502 stacke
= stack
.bottom
- 1 + XFASTINT (maxdepth
);
505 if (! NILP (args_template
))
506 /* We should push some arguments on the stack. */
509 int pushed
= 0, optional
= 0;
511 for (at
= args_template
; CONSP (at
); at
= XCDR (at
))
512 if (EQ (XCAR (at
), Qand_optional
))
514 else if (EQ (XCAR (at
), Qand_rest
))
517 ? Flist (nargs
- pushed
, args
)
523 else if (pushed
< nargs
)
533 if (pushed
!= nargs
|| !NILP (at
))
534 Fsignal (Qwrong_number_of_arguments
,
535 Fcons (args_template
, Fcons (make_number (nargs
), Qnil
)));
540 #ifdef BYTE_CODE_SAFE
543 else if (top
< stack
.bottom
- 1)
547 #ifdef BYTE_CODE_METER
549 this_op
= op
= FETCH
;
550 METER_CODE (prev_op
, op
);
570 /* This seems to be the most frequently executed byte-code
571 among the Bvarref's, so avoid a goto here. */
581 if (XSYMBOL (v1
)->redirect
!= SYMBOL_PLAINVAL
582 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)),
585 BEFORE_POTENTIAL_GC ();
586 v2
= Fsymbol_value (v1
);
587 AFTER_POTENTIAL_GC ();
592 BEFORE_POTENTIAL_GC ();
593 v2
= Fsymbol_value (v1
);
594 AFTER_POTENTIAL_GC ();
610 stack
.pc
= stack
.byte_string_start
+ op
;
627 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
634 BEFORE_POTENTIAL_GC ();
636 TOP
= Fmemq (TOP
, v1
);
637 AFTER_POTENTIAL_GC ();
666 Lisp_Object sym
, val
;
671 /* Inline the most common case. */
673 && !EQ (val
, Qunbound
)
674 && !XSYMBOL (sym
)->redirect
675 && !SYMBOL_CONSTANT_P (sym
))
676 XSYMBOL (sym
)->val
.value
= val
;
679 BEFORE_POTENTIAL_GC ();
680 set_internal (sym
, val
, Qnil
, 0);
681 AFTER_POTENTIAL_GC ();
695 /* ------------------ */
713 /* Specbind can signal and thus GC. */
714 BEFORE_POTENTIAL_GC ();
715 specbind (vectorp
[op
], POP
);
716 AFTER_POTENTIAL_GC ();
736 BEFORE_POTENTIAL_GC ();
738 #ifdef BYTE_CODE_METER
739 if (byte_metering_on
&& SYMBOLP (TOP
))
744 v2
= Fget (v1
, Qbyte_code_meter
);
746 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
748 XSETINT (v2
, XINT (v2
) + 1);
749 Fput (v1
, Qbyte_code_meter
, v2
);
753 TOP
= Ffuncall (op
+ 1, &TOP
);
754 AFTER_POTENTIAL_GC ();
774 BEFORE_POTENTIAL_GC ();
775 unbind_to (SPECPDL_INDEX () - op
, Qnil
);
776 AFTER_POTENTIAL_GC ();
779 case Bunbind_all
: /* Obsolete. */
780 /* To unbind back to the beginning of this frame. Not used yet,
781 but will be needed for tail-recursion elimination. */
782 BEFORE_POTENTIAL_GC ();
783 unbind_to (count
, Qnil
);
784 AFTER_POTENTIAL_GC ();
790 op
= FETCH2
; /* pc = FETCH2 loses since FETCH2 contains pc++ */
792 stack
.pc
= stack
.byte_string_start
+ op
;
805 stack
.pc
= stack
.byte_string_start
+ op
;
810 case Bgotoifnilelsepop
:
817 stack
.pc
= stack
.byte_string_start
+ op
;
822 case Bgotoifnonnilelsepop
:
829 stack
.pc
= stack
.byte_string_start
+ op
;
837 stack
.pc
+= (int) *stack
.pc
- 127;
848 stack
.pc
+= (int) *stack
.pc
- 128;
862 stack
.pc
+= (int) *stack
.pc
- 128;
868 case BRgotoifnilelsepop
:
874 stack
.pc
+= op
- 128;
879 case BRgotoifnonnilelsepop
:
885 stack
.pc
+= op
- 128;
899 PUSH (vectorp
[FETCH2
]);
902 case Bsave_excursion
:
903 record_unwind_protect (save_excursion_restore
,
904 save_excursion_save ());
907 case Bsave_current_buffer
: /* Obsolete. */
908 case Bsave_current_buffer_1
:
909 record_unwind_protect (set_buffer_if_live
, Fcurrent_buffer ());
912 case Bsave_window_excursion
: /* Obsolete. */
914 register int count
= SPECPDL_INDEX ();
915 record_unwind_protect (Fset_window_configuration
,
916 Fcurrent_window_configuration (Qnil
));
917 BEFORE_POTENTIAL_GC ();
919 unbind_to (count
, TOP
);
920 AFTER_POTENTIAL_GC ();
924 case Bsave_restriction
:
925 record_unwind_protect (save_restriction_restore
,
926 save_restriction_save ());
932 BEFORE_POTENTIAL_GC ();
934 TOP
= internal_catch (TOP
, eval_sub
, v1
); /* FIXME: lexbind */
935 AFTER_POTENTIAL_GC ();
939 case Bunwind_protect
:
940 record_unwind_protect (Fprogn
, POP
); /* FIXME: lexbind */
943 case Bcondition_case
:
945 Lisp_Object handlers
, body
;
948 BEFORE_POTENTIAL_GC ();
949 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
); /* FIXME: lexbind */
950 AFTER_POTENTIAL_GC ();
954 case Btemp_output_buffer_setup
: /* Obsolete. */
955 BEFORE_POTENTIAL_GC ();
957 temp_output_buffer_setup (SSDATA (TOP
));
958 AFTER_POTENTIAL_GC ();
959 TOP
= Vstandard_output
;
962 case Btemp_output_buffer_show
: /* Obsolete. */
965 BEFORE_POTENTIAL_GC ();
967 temp_output_buffer_show (TOP
);
969 /* pop binding of standard-output */
970 unbind_to (SPECPDL_INDEX () - 1, Qnil
);
971 AFTER_POTENTIAL_GC ();
978 BEFORE_POTENTIAL_GC ();
982 AFTER_POTENTIAL_GC ();
985 while (--op
>= 0 && CONSP (v1
))
993 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
997 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
1001 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
1005 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
1009 TOP
= NILP (TOP
) ? Qt
: Qnil
;
1016 TOP
= Fcons (TOP
, v1
);
1021 TOP
= Fcons (TOP
, Qnil
);
1028 TOP
= Fcons (TOP
, Fcons (v1
, Qnil
));
1034 TOP
= Flist (3, &TOP
);
1039 TOP
= Flist (4, &TOP
);
1045 TOP
= Flist (op
, &TOP
);
1049 BEFORE_POTENTIAL_GC ();
1050 TOP
= Flength (TOP
);
1051 AFTER_POTENTIAL_GC ();
1057 BEFORE_POTENTIAL_GC ();
1059 TOP
= Faref (TOP
, v1
);
1060 AFTER_POTENTIAL_GC ();
1067 BEFORE_POTENTIAL_GC ();
1069 TOP
= Faset (TOP
, v1
, v2
);
1070 AFTER_POTENTIAL_GC ();
1075 BEFORE_POTENTIAL_GC ();
1076 TOP
= Fsymbol_value (TOP
);
1077 AFTER_POTENTIAL_GC ();
1080 case Bsymbol_function
:
1081 BEFORE_POTENTIAL_GC ();
1082 TOP
= Fsymbol_function (TOP
);
1083 AFTER_POTENTIAL_GC ();
1089 BEFORE_POTENTIAL_GC ();
1091 TOP
= Fset (TOP
, v1
);
1092 AFTER_POTENTIAL_GC ();
1099 BEFORE_POTENTIAL_GC ();
1101 TOP
= Ffset (TOP
, v1
);
1102 AFTER_POTENTIAL_GC ();
1109 BEFORE_POTENTIAL_GC ();
1111 TOP
= Fget (TOP
, v1
);
1112 AFTER_POTENTIAL_GC ();
1119 BEFORE_POTENTIAL_GC ();
1121 TOP
= Fsubstring (TOP
, v1
, v2
);
1122 AFTER_POTENTIAL_GC ();
1127 BEFORE_POTENTIAL_GC ();
1129 TOP
= Fconcat (2, &TOP
);
1130 AFTER_POTENTIAL_GC ();
1134 BEFORE_POTENTIAL_GC ();
1136 TOP
= Fconcat (3, &TOP
);
1137 AFTER_POTENTIAL_GC ();
1141 BEFORE_POTENTIAL_GC ();
1143 TOP
= Fconcat (4, &TOP
);
1144 AFTER_POTENTIAL_GC ();
1149 BEFORE_POTENTIAL_GC ();
1151 TOP
= Fconcat (op
, &TOP
);
1152 AFTER_POTENTIAL_GC ();
1161 XSETINT (v1
, XINT (v1
) - 1);
1166 BEFORE_POTENTIAL_GC ();
1168 AFTER_POTENTIAL_GC ();
1179 XSETINT (v1
, XINT (v1
) + 1);
1184 BEFORE_POTENTIAL_GC ();
1186 AFTER_POTENTIAL_GC ();
1194 BEFORE_POTENTIAL_GC ();
1196 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
1197 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
1198 AFTER_POTENTIAL_GC ();
1199 if (FLOATP (v1
) || FLOATP (v2
))
1203 f1
= (FLOATP (v1
) ? XFLOAT_DATA (v1
) : XINT (v1
));
1204 f2
= (FLOATP (v2
) ? XFLOAT_DATA (v2
) : XINT (v2
));
1205 TOP
= (f1
== f2
? Qt
: Qnil
);
1208 TOP
= (XINT (v1
) == XINT (v2
) ? Qt
: Qnil
);
1215 BEFORE_POTENTIAL_GC ();
1217 TOP
= Fgtr (TOP
, v1
);
1218 AFTER_POTENTIAL_GC ();
1225 BEFORE_POTENTIAL_GC ();
1227 TOP
= Flss (TOP
, v1
);
1228 AFTER_POTENTIAL_GC ();
1235 BEFORE_POTENTIAL_GC ();
1237 TOP
= Fleq (TOP
, v1
);
1238 AFTER_POTENTIAL_GC ();
1245 BEFORE_POTENTIAL_GC ();
1247 TOP
= Fgeq (TOP
, v1
);
1248 AFTER_POTENTIAL_GC ();
1253 BEFORE_POTENTIAL_GC ();
1255 TOP
= Fminus (2, &TOP
);
1256 AFTER_POTENTIAL_GC ();
1265 XSETINT (v1
, - XINT (v1
));
1270 BEFORE_POTENTIAL_GC ();
1271 TOP
= Fminus (1, &TOP
);
1272 AFTER_POTENTIAL_GC ();
1278 BEFORE_POTENTIAL_GC ();
1280 TOP
= Fplus (2, &TOP
);
1281 AFTER_POTENTIAL_GC ();
1285 BEFORE_POTENTIAL_GC ();
1287 TOP
= Fmax (2, &TOP
);
1288 AFTER_POTENTIAL_GC ();
1292 BEFORE_POTENTIAL_GC ();
1294 TOP
= Fmin (2, &TOP
);
1295 AFTER_POTENTIAL_GC ();
1299 BEFORE_POTENTIAL_GC ();
1301 TOP
= Ftimes (2, &TOP
);
1302 AFTER_POTENTIAL_GC ();
1306 BEFORE_POTENTIAL_GC ();
1308 TOP
= Fquo (2, &TOP
);
1309 AFTER_POTENTIAL_GC ();
1315 BEFORE_POTENTIAL_GC ();
1317 TOP
= Frem (TOP
, v1
);
1318 AFTER_POTENTIAL_GC ();
1325 XSETFASTINT (v1
, PT
);
1331 BEFORE_POTENTIAL_GC ();
1332 TOP
= Fgoto_char (TOP
);
1333 AFTER_POTENTIAL_GC ();
1337 BEFORE_POTENTIAL_GC ();
1338 TOP
= Finsert (1, &TOP
);
1339 AFTER_POTENTIAL_GC ();
1344 BEFORE_POTENTIAL_GC ();
1346 TOP
= Finsert (op
, &TOP
);
1347 AFTER_POTENTIAL_GC ();
1353 XSETFASTINT (v1
, ZV
);
1361 XSETFASTINT (v1
, BEGV
);
1367 BEFORE_POTENTIAL_GC ();
1368 TOP
= Fchar_after (TOP
);
1369 AFTER_POTENTIAL_GC ();
1372 case Bfollowing_char
:
1375 BEFORE_POTENTIAL_GC ();
1376 v1
= Ffollowing_char ();
1377 AFTER_POTENTIAL_GC ();
1382 case Bpreceding_char
:
1385 BEFORE_POTENTIAL_GC ();
1386 v1
= Fprevious_char ();
1387 AFTER_POTENTIAL_GC ();
1392 case Bcurrent_column
:
1395 BEFORE_POTENTIAL_GC ();
1396 XSETFASTINT (v1
, (int) current_column ()); /* iftc */
1397 AFTER_POTENTIAL_GC ();
1403 BEFORE_POTENTIAL_GC ();
1404 TOP
= Findent_to (TOP
, Qnil
);
1405 AFTER_POTENTIAL_GC ();
1424 case Bcurrent_buffer
:
1425 PUSH (Fcurrent_buffer ());
1429 BEFORE_POTENTIAL_GC ();
1430 TOP
= Fset_buffer (TOP
);
1431 AFTER_POTENTIAL_GC ();
1434 case Binteractive_p
: /* Obsolete. */
1435 PUSH (Finteractive_p ());
1439 BEFORE_POTENTIAL_GC ();
1440 TOP
= Fforward_char (TOP
);
1441 AFTER_POTENTIAL_GC ();
1445 BEFORE_POTENTIAL_GC ();
1446 TOP
= Fforward_word (TOP
);
1447 AFTER_POTENTIAL_GC ();
1450 case Bskip_chars_forward
:
1453 BEFORE_POTENTIAL_GC ();
1455 TOP
= Fskip_chars_forward (TOP
, v1
);
1456 AFTER_POTENTIAL_GC ();
1460 case Bskip_chars_backward
:
1463 BEFORE_POTENTIAL_GC ();
1465 TOP
= Fskip_chars_backward (TOP
, v1
);
1466 AFTER_POTENTIAL_GC ();
1471 BEFORE_POTENTIAL_GC ();
1472 TOP
= Fforward_line (TOP
);
1473 AFTER_POTENTIAL_GC ();
1480 BEFORE_POTENTIAL_GC ();
1481 CHECK_CHARACTER (TOP
);
1482 AFTER_POTENTIAL_GC ();
1484 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
1485 MAKE_CHAR_MULTIBYTE (c
);
1486 XSETFASTINT (TOP
, syntax_code_spec
[(int) SYNTAX (c
)]);
1490 case Bbuffer_substring
:
1493 BEFORE_POTENTIAL_GC ();
1495 TOP
= Fbuffer_substring (TOP
, v1
);
1496 AFTER_POTENTIAL_GC ();
1500 case Bdelete_region
:
1503 BEFORE_POTENTIAL_GC ();
1505 TOP
= Fdelete_region (TOP
, v1
);
1506 AFTER_POTENTIAL_GC ();
1510 case Bnarrow_to_region
:
1513 BEFORE_POTENTIAL_GC ();
1515 TOP
= Fnarrow_to_region (TOP
, v1
);
1516 AFTER_POTENTIAL_GC ();
1521 BEFORE_POTENTIAL_GC ();
1523 AFTER_POTENTIAL_GC ();
1527 BEFORE_POTENTIAL_GC ();
1528 TOP
= Fend_of_line (TOP
);
1529 AFTER_POTENTIAL_GC ();
1535 BEFORE_POTENTIAL_GC ();
1538 TOP
= Fset_marker (TOP
, v2
, v1
);
1539 AFTER_POTENTIAL_GC ();
1543 case Bmatch_beginning
:
1544 BEFORE_POTENTIAL_GC ();
1545 TOP
= Fmatch_beginning (TOP
);
1546 AFTER_POTENTIAL_GC ();
1550 BEFORE_POTENTIAL_GC ();
1551 TOP
= Fmatch_end (TOP
);
1552 AFTER_POTENTIAL_GC ();
1556 BEFORE_POTENTIAL_GC ();
1557 TOP
= Fupcase (TOP
);
1558 AFTER_POTENTIAL_GC ();
1562 BEFORE_POTENTIAL_GC ();
1563 TOP
= Fdowncase (TOP
);
1564 AFTER_POTENTIAL_GC ();
1567 case Bstringeqlsign
:
1570 BEFORE_POTENTIAL_GC ();
1572 TOP
= Fstring_equal (TOP
, v1
);
1573 AFTER_POTENTIAL_GC ();
1580 BEFORE_POTENTIAL_GC ();
1582 TOP
= Fstring_lessp (TOP
, v1
);
1583 AFTER_POTENTIAL_GC ();
1591 TOP
= Fequal (TOP
, v1
);
1598 BEFORE_POTENTIAL_GC ();
1600 TOP
= Fnthcdr (TOP
, v1
);
1601 AFTER_POTENTIAL_GC ();
1610 /* Exchange args and then do nth. */
1611 BEFORE_POTENTIAL_GC ();
1615 AFTER_POTENTIAL_GC ();
1618 while (--op
>= 0 && CONSP (v1
))
1625 BEFORE_POTENTIAL_GC ();
1627 TOP
= Felt (TOP
, v1
);
1628 AFTER_POTENTIAL_GC ();
1636 BEFORE_POTENTIAL_GC ();
1638 TOP
= Fmember (TOP
, v1
);
1639 AFTER_POTENTIAL_GC ();
1646 BEFORE_POTENTIAL_GC ();
1648 TOP
= Fassq (TOP
, v1
);
1649 AFTER_POTENTIAL_GC ();
1654 BEFORE_POTENTIAL_GC ();
1655 TOP
= Fnreverse (TOP
);
1656 AFTER_POTENTIAL_GC ();
1662 BEFORE_POTENTIAL_GC ();
1664 TOP
= Fsetcar (TOP
, v1
);
1665 AFTER_POTENTIAL_GC ();
1672 BEFORE_POTENTIAL_GC ();
1674 TOP
= Fsetcdr (TOP
, v1
);
1675 AFTER_POTENTIAL_GC ();
1683 TOP
= CAR_SAFE (v1
);
1691 TOP
= CDR_SAFE (v1
);
1696 BEFORE_POTENTIAL_GC ();
1698 TOP
= Fnconc (2, &TOP
);
1699 AFTER_POTENTIAL_GC ();
1703 TOP
= (NUMBERP (TOP
) ? Qt
: Qnil
);
1707 TOP
= INTEGERP (TOP
) ? Qt
: Qnil
;
1710 #ifdef BYTE_CODE_SAFE
1712 BEFORE_POTENTIAL_GC ();
1713 error ("set-mark is an obsolete bytecode");
1714 AFTER_POTENTIAL_GC ();
1717 BEFORE_POTENTIAL_GC ();
1718 error ("scan-buffer is an obsolete bytecode");
1719 AFTER_POTENTIAL_GC ();
1723 /* Handy byte-codes for lexical binding. */
1724 /* case Bstack_ref: */ /* Use `dup' instead. */
1731 Lisp_Object
*ptr
= top
- (op
- Bstack_ref
);
1737 Lisp_Object
*ptr
= top
- (FETCH
);
1743 Lisp_Object
*ptr
= top
- (FETCH2
);
1747 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1750 Lisp_Object
*ptr
= top
- (FETCH
);
1756 Lisp_Object
*ptr
= top
- (FETCH2
);
1772 #ifdef BYTE_CODE_SAFE
1777 if ((op
-= Bconstant
) >= const_length
)
1783 PUSH (vectorp
[op
- Bconstant
]);
1790 byte_stack_list
= byte_stack_list
->next
;
1792 /* Binds and unbinds are supposed to be compiled balanced. */
1793 if (SPECPDL_INDEX () != count
)
1794 #ifdef BYTE_CODE_SAFE
1795 error ("binding stack not balanced (serious byte compiler bug)");
1804 syms_of_bytecode (void)
1806 Qbytecode
= intern_c_string ("byte-code");
1807 staticpro (&Qbytecode
);
1809 defsubr (&Sbyte_code
);
1811 #ifdef BYTE_CODE_METER
1813 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter
,
1814 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
1815 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1816 opcode CODE has been executed.
1817 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1818 indicates how many times the byte opcodes CODE1 and CODE2 have been
1819 executed in succession. */);
1821 DEFVAR_BOOL ("byte-metering-on", byte_metering_on
,
1822 doc
: /* If non-nil, keep profiling information on byte code usage.
1823 The variable byte-code-meter indicates how often each byte opcode is used.
1824 If a symbol has a property named `byte-code-meter' whose value is an
1825 integer, it is incremented each time that symbol's function is called. */);
1827 byte_metering_on
= 0;
1828 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
1829 Qbyte_code_meter
= intern_c_string ("byte-code-meter");
1830 staticpro (&Qbyte_code_meter
);
1834 XVECTOR (Vbyte_code_meter
)->contents
[i
] =
1835 Fmake_vector (make_number (256), make_number (0));