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 */
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
;
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
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 /* Needed since interactive-p takes unevalled args */
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
187 #define Bsave_restriction 0214
190 #define Bunwind_protect 0216
191 #define Bcondition_case 0217
192 #define Btemp_output_buffer_setup 0220
193 #define Btemp_output_buffer_show 0221
195 #define Bunbind_all 0222
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
240 /* Structure describing a value stack used during byte-code execution
245 /* Program counter. This points into the byte_string below
246 and is relocated when that string is relocated. */
247 const unsigned char *pc
;
249 /* Top and bottom of stack. The bottom points to an area of memory
250 allocated with alloca in Fbyte_code. */
251 Lisp_Object
*top
, *bottom
;
253 /* The string containing the byte-code, and its current address.
254 Storing this here protects it from GC because mark_byte_stack
256 Lisp_Object byte_string
;
257 const unsigned char *byte_string_start
;
259 /* The vector of constants used during byte-code execution. Storing
260 this here protects it from GC because mark_byte_stack marks it. */
261 Lisp_Object constants
;
263 /* Next entry in byte_stack_list. */
264 struct byte_stack
*next
;
267 /* A list of currently active byte-code execution value stacks.
268 Fbyte_code adds an entry to the head of this list before it starts
269 processing byte-code, and it removed the entry again when it is
270 done. Signalling an error truncates the list analoguous to
273 struct byte_stack
*byte_stack_list
;
276 /* Mark objects on byte_stack_list. Called during GC. */
279 mark_byte_stack (void)
281 struct byte_stack
*stack
;
284 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
286 /* If STACK->top is null here, this means there's an opcode in
287 Fbyte_code that wasn't expected to GC, but did. To find out
288 which opcode this is, record the value of `stack', and walk
289 up the stack in a debugger, stopping in frames of Fbyte_code.
290 The culprit is found in the frame of Fbyte_code where the
291 address of its local variable `stack' is equal to the
292 recorded value of `stack' here. */
293 eassert (stack
->top
);
295 for (obj
= stack
->bottom
; obj
<= stack
->top
; ++obj
)
298 mark_object (stack
->byte_string
);
299 mark_object (stack
->constants
);
304 /* Unmark objects in the stacks on byte_stack_list. Relocate program
305 counters. Called when GC has completed. */
308 unmark_byte_stack (void)
310 struct byte_stack
*stack
;
312 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
314 if (stack
->byte_string_start
!= SDATA (stack
->byte_string
))
316 int offset
= stack
->pc
- stack
->byte_string_start
;
317 stack
->byte_string_start
= SDATA (stack
->byte_string
);
318 stack
->pc
= stack
->byte_string_start
+ offset
;
324 /* Fetch the next byte from the bytecode stream */
326 #define FETCH *stack.pc++
328 /* Fetch two bytes from the bytecode stream and make a 16-bit number
331 #define FETCH2 (op = FETCH, op + (FETCH << 8))
333 /* Push x onto the execution stack. This used to be #define PUSH(x)
334 (*++stackp = (x)) This oddity is necessary because Alliant can't be
335 bothered to compile the preincrement operator properly, as of 4/91.
338 #define PUSH(x) (top++, *top = (x))
340 /* Pop a value off the execution stack. */
344 /* Discard n values from the execution stack. */
346 #define DISCARD(n) (top -= (n))
348 /* Get the value which is at the top of the execution stack, but don't
353 /* Actions that must be performed before and after calling a function
356 #define BEFORE_POTENTIAL_GC() stack.top = top
357 #define AFTER_POTENTIAL_GC() stack.top = NULL
359 /* Garbage collect if we have consed enough since the last time.
360 We do this at every branch, to avoid loops that never GC. */
363 if (consing_since_gc > gc_cons_threshold \
364 && consing_since_gc > gc_relative_threshold) \
366 BEFORE_POTENTIAL_GC (); \
367 Fgarbage_collect (); \
368 AFTER_POTENTIAL_GC (); \
372 /* Check for jumping out of range. */
374 #ifdef BYTE_CODE_SAFE
376 #define CHECK_RANGE(ARG) \
377 if (ARG >= bytestr_length) abort ()
379 #else /* not BYTE_CODE_SAFE */
381 #define CHECK_RANGE(ARG)
383 #endif /* not BYTE_CODE_SAFE */
385 /* A version of the QUIT macro which makes sure that the stack top is
386 set before signaling `quit'. */
388 #define BYTE_CODE_QUIT \
390 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
392 Lisp_Object flag = Vquit_flag; \
394 BEFORE_POTENTIAL_GC (); \
395 if (EQ (Vthrow_on_input, flag)) \
396 Fthrow (Vthrow_on_input, Qt); \
397 Fsignal (Qquit, Qnil); \
398 AFTER_POTENTIAL_GC (); \
400 ELSE_PENDING_SIGNALS \
404 DEFUN ("byte-code", Fbyte_code
, Sbyte_code
, 3, MANY
, 0,
405 doc
: /* Function used internally in byte-compiled code.
406 The first argument, BYTESTR, is a string of byte code;
407 the second, VECTOR, a vector of constants;
408 the third, MAXDEPTH, the maximum stack depth used in this function.
409 If the third argument is incorrect, Emacs may crash.
411 If ARGS-TEMPLATE is specified, it is an argument list specification,
412 according to which any remaining arguments are pushed on the stack
413 before executing BYTESTR.
415 usage: (byte-code BYTESTR VECTOR MAXDEP &optional ARGS-TEMPLATE &rest ARGS) */)
416 (int nargs
, Lisp_Object
*args
)
418 Lisp_Object args_tmpl
= nargs
>= 4 ? args
[3] : Qnil
;
419 int pnargs
= nargs
>= 4 ? nargs
- 4 : 0;
420 Lisp_Object
*pargs
= nargs
>= 4 ? args
+ 4 : 0;
421 return exec_byte_code (args
[0], args
[1], args
[2], args_tmpl
, pnargs
, pargs
);
424 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
425 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
426 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
427 argument list (including &rest, &optional, etc.), and ARGS, of size
428 NARGS, should be a vector of the actual arguments. The arguments in
429 ARGS are pushed on the stack according to ARGS_TEMPLATE before
430 executing BYTESTR. */
433 exec_byte_code (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
,
434 Lisp_Object args_template
, int nargs
, Lisp_Object
*args
)
436 int count
= SPECPDL_INDEX ();
437 #ifdef BYTE_CODE_METER
442 /* Lisp_Object v1, v2; */
443 Lisp_Object
*vectorp
;
444 #ifdef BYTE_CODE_SAFE
445 int const_length
= XVECTOR (vector
)->size
;
449 struct byte_stack stack
;
453 #if 0 /* CHECK_FRAME_FONT */
455 struct frame
*f
= SELECTED_FRAME ();
457 && FRAME_FONT (f
)->direction
!= 0
458 && FRAME_FONT (f
)->direction
!= 1)
463 CHECK_STRING (bytestr
);
464 CHECK_VECTOR (vector
);
465 CHECK_NUMBER (maxdepth
);
467 if (STRING_MULTIBYTE (bytestr
))
468 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
469 because they produced a raw 8-bit string for byte-code and now
470 such a byte-code string is loaded as multibyte while raw 8-bit
471 characters converted to multibyte form. Thus, now we must
472 convert them back to the originally intended unibyte form. */
473 bytestr
= Fstring_as_unibyte (bytestr
);
475 bytestr_length
= SBYTES (bytestr
);
476 vectorp
= XVECTOR (vector
)->contents
;
478 stack
.byte_string
= bytestr
;
479 stack
.pc
= stack
.byte_string_start
= SDATA (bytestr
);
480 stack
.constants
= vector
;
481 stack
.bottom
= (Lisp_Object
*) alloca (XFASTINT (maxdepth
)
482 * sizeof (Lisp_Object
));
483 top
= stack
.bottom
- 1;
485 stack
.next
= byte_stack_list
;
486 byte_stack_list
= &stack
;
488 #ifdef BYTE_CODE_SAFE
489 stacke
= stack
.bottom
- 1 + XFASTINT (maxdepth
);
492 if (! NILP (args_template
))
493 /* We should push some arguments on the stack. */
496 int pushed
= 0, optional
= 0;
498 for (at
= args_template
; CONSP (at
); at
= XCDR (at
))
499 if (EQ (XCAR (at
), Qand_optional
))
501 else if (EQ (XCAR (at
), Qand_rest
))
503 PUSH (Flist (nargs
, args
));
508 else if (pushed
< nargs
)
518 if (pushed
!= nargs
|| !NILP (at
))
519 Fsignal (Qwrong_number_of_arguments
,
520 Fcons (args_template
, Fcons (make_number (nargs
), Qnil
)));
525 #ifdef BYTE_CODE_SAFE
528 else if (top
< stack
.bottom
- 1)
532 #ifdef BYTE_CODE_METER
534 this_op
= op
= FETCH
;
535 METER_CODE (prev_op
, op
);
555 /* This seems to be the most frequently executed byte-code
556 among the Bvarref's, so avoid a goto here. */
566 if (XSYMBOL (v1
)->redirect
!= SYMBOL_PLAINVAL
567 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)),
570 BEFORE_POTENTIAL_GC ();
571 v2
= Fsymbol_value (v1
);
572 AFTER_POTENTIAL_GC ();
577 BEFORE_POTENTIAL_GC ();
578 v2
= Fsymbol_value (v1
);
579 AFTER_POTENTIAL_GC ();
595 stack
.pc
= stack
.byte_string_start
+ op
;
612 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
619 BEFORE_POTENTIAL_GC ();
621 TOP
= Fmemq (TOP
, v1
);
622 AFTER_POTENTIAL_GC ();
651 Lisp_Object sym
, val
;
656 /* Inline the most common case. */
658 && !EQ (val
, Qunbound
)
659 && !XSYMBOL (sym
)->redirect
660 && !SYMBOL_CONSTANT_P (sym
))
661 XSYMBOL (sym
)->val
.value
= val
;
664 BEFORE_POTENTIAL_GC ();
665 set_internal (sym
, val
, Qnil
, 0);
666 AFTER_POTENTIAL_GC ();
680 /* ------------------ */
698 /* Specbind can signal and thus GC. */
699 BEFORE_POTENTIAL_GC ();
700 specbind (vectorp
[op
], POP
);
701 AFTER_POTENTIAL_GC ();
721 BEFORE_POTENTIAL_GC ();
723 #ifdef BYTE_CODE_METER
724 if (byte_metering_on
&& SYMBOLP (TOP
))
729 v2
= Fget (v1
, Qbyte_code_meter
);
731 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
733 XSETINT (v2
, XINT (v2
) + 1);
734 Fput (v1
, Qbyte_code_meter
, v2
);
738 TOP
= Ffuncall (op
+ 1, &TOP
);
739 AFTER_POTENTIAL_GC ();
759 BEFORE_POTENTIAL_GC ();
760 unbind_to (SPECPDL_INDEX () - op
, Qnil
);
761 AFTER_POTENTIAL_GC ();
765 /* To unbind back to the beginning of this frame. Not used yet,
766 but will be needed for tail-recursion elimination. */
767 BEFORE_POTENTIAL_GC ();
768 unbind_to (count
, Qnil
);
769 AFTER_POTENTIAL_GC ();
775 op
= FETCH2
; /* pc = FETCH2 loses since FETCH2 contains pc++ */
777 stack
.pc
= stack
.byte_string_start
+ op
;
790 stack
.pc
= stack
.byte_string_start
+ op
;
795 case Bgotoifnilelsepop
:
802 stack
.pc
= stack
.byte_string_start
+ op
;
807 case Bgotoifnonnilelsepop
:
814 stack
.pc
= stack
.byte_string_start
+ op
;
822 stack
.pc
+= (int) *stack
.pc
- 127;
833 stack
.pc
+= (int) *stack
.pc
- 128;
847 stack
.pc
+= (int) *stack
.pc
- 128;
853 case BRgotoifnilelsepop
:
859 stack
.pc
+= op
- 128;
864 case BRgotoifnonnilelsepop
:
870 stack
.pc
+= op
- 128;
884 PUSH (vectorp
[FETCH2
]);
887 case Bsave_excursion
:
888 record_unwind_protect (save_excursion_restore
,
889 save_excursion_save ());
892 case Bsave_current_buffer
:
893 case Bsave_current_buffer_1
:
894 record_unwind_protect (set_buffer_if_live
, Fcurrent_buffer ());
897 case Bsave_window_excursion
:
898 BEFORE_POTENTIAL_GC ();
899 TOP
= Fsave_window_excursion (TOP
); /* FIXME: lexbind */
900 AFTER_POTENTIAL_GC ();
903 case Bsave_restriction
:
904 record_unwind_protect (save_restriction_restore
,
905 save_restriction_save ());
911 BEFORE_POTENTIAL_GC ();
913 TOP
= internal_catch (TOP
, eval_sub
, v1
); /* FIXME: lexbind */
914 AFTER_POTENTIAL_GC ();
918 case Bunwind_protect
:
919 record_unwind_protect (Fprogn
, POP
); /* FIXME: lexbind */
922 case Bcondition_case
:
924 Lisp_Object handlers
, body
;
927 BEFORE_POTENTIAL_GC ();
928 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
); /* FIXME: lexbind */
929 AFTER_POTENTIAL_GC ();
933 case Btemp_output_buffer_setup
:
934 BEFORE_POTENTIAL_GC ();
936 temp_output_buffer_setup (SSDATA (TOP
));
937 AFTER_POTENTIAL_GC ();
938 TOP
= Vstandard_output
;
941 case Btemp_output_buffer_show
:
944 BEFORE_POTENTIAL_GC ();
946 temp_output_buffer_show (TOP
);
948 /* pop binding of standard-output */
949 unbind_to (SPECPDL_INDEX () - 1, Qnil
);
950 AFTER_POTENTIAL_GC ();
957 BEFORE_POTENTIAL_GC ();
961 AFTER_POTENTIAL_GC ();
964 while (--op
>= 0 && CONSP (v1
))
972 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
976 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
980 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
984 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
988 TOP
= NILP (TOP
) ? Qt
: Qnil
;
995 TOP
= Fcons (TOP
, v1
);
1000 TOP
= Fcons (TOP
, Qnil
);
1007 TOP
= Fcons (TOP
, Fcons (v1
, Qnil
));
1013 TOP
= Flist (3, &TOP
);
1018 TOP
= Flist (4, &TOP
);
1024 TOP
= Flist (op
, &TOP
);
1028 BEFORE_POTENTIAL_GC ();
1029 TOP
= Flength (TOP
);
1030 AFTER_POTENTIAL_GC ();
1036 BEFORE_POTENTIAL_GC ();
1038 TOP
= Faref (TOP
, v1
);
1039 AFTER_POTENTIAL_GC ();
1046 BEFORE_POTENTIAL_GC ();
1048 TOP
= Faset (TOP
, v1
, v2
);
1049 AFTER_POTENTIAL_GC ();
1054 BEFORE_POTENTIAL_GC ();
1055 TOP
= Fsymbol_value (TOP
);
1056 AFTER_POTENTIAL_GC ();
1059 case Bsymbol_function
:
1060 BEFORE_POTENTIAL_GC ();
1061 TOP
= Fsymbol_function (TOP
);
1062 AFTER_POTENTIAL_GC ();
1068 BEFORE_POTENTIAL_GC ();
1070 TOP
= Fset (TOP
, v1
);
1071 AFTER_POTENTIAL_GC ();
1078 BEFORE_POTENTIAL_GC ();
1080 TOP
= Ffset (TOP
, v1
);
1081 AFTER_POTENTIAL_GC ();
1088 BEFORE_POTENTIAL_GC ();
1090 TOP
= Fget (TOP
, v1
);
1091 AFTER_POTENTIAL_GC ();
1098 BEFORE_POTENTIAL_GC ();
1100 TOP
= Fsubstring (TOP
, v1
, v2
);
1101 AFTER_POTENTIAL_GC ();
1106 BEFORE_POTENTIAL_GC ();
1108 TOP
= Fconcat (2, &TOP
);
1109 AFTER_POTENTIAL_GC ();
1113 BEFORE_POTENTIAL_GC ();
1115 TOP
= Fconcat (3, &TOP
);
1116 AFTER_POTENTIAL_GC ();
1120 BEFORE_POTENTIAL_GC ();
1122 TOP
= Fconcat (4, &TOP
);
1123 AFTER_POTENTIAL_GC ();
1128 BEFORE_POTENTIAL_GC ();
1130 TOP
= Fconcat (op
, &TOP
);
1131 AFTER_POTENTIAL_GC ();
1140 XSETINT (v1
, XINT (v1
) - 1);
1145 BEFORE_POTENTIAL_GC ();
1147 AFTER_POTENTIAL_GC ();
1158 XSETINT (v1
, XINT (v1
) + 1);
1163 BEFORE_POTENTIAL_GC ();
1165 AFTER_POTENTIAL_GC ();
1173 BEFORE_POTENTIAL_GC ();
1175 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
1176 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
1177 AFTER_POTENTIAL_GC ();
1178 if (FLOATP (v1
) || FLOATP (v2
))
1182 f1
= (FLOATP (v1
) ? XFLOAT_DATA (v1
) : XINT (v1
));
1183 f2
= (FLOATP (v2
) ? XFLOAT_DATA (v2
) : XINT (v2
));
1184 TOP
= (f1
== f2
? Qt
: Qnil
);
1187 TOP
= (XINT (v1
) == XINT (v2
) ? Qt
: Qnil
);
1194 BEFORE_POTENTIAL_GC ();
1196 TOP
= Fgtr (TOP
, v1
);
1197 AFTER_POTENTIAL_GC ();
1204 BEFORE_POTENTIAL_GC ();
1206 TOP
= Flss (TOP
, v1
);
1207 AFTER_POTENTIAL_GC ();
1214 BEFORE_POTENTIAL_GC ();
1216 TOP
= Fleq (TOP
, v1
);
1217 AFTER_POTENTIAL_GC ();
1224 BEFORE_POTENTIAL_GC ();
1226 TOP
= Fgeq (TOP
, v1
);
1227 AFTER_POTENTIAL_GC ();
1232 BEFORE_POTENTIAL_GC ();
1234 TOP
= Fminus (2, &TOP
);
1235 AFTER_POTENTIAL_GC ();
1244 XSETINT (v1
, - XINT (v1
));
1249 BEFORE_POTENTIAL_GC ();
1250 TOP
= Fminus (1, &TOP
);
1251 AFTER_POTENTIAL_GC ();
1257 BEFORE_POTENTIAL_GC ();
1259 TOP
= Fplus (2, &TOP
);
1260 AFTER_POTENTIAL_GC ();
1264 BEFORE_POTENTIAL_GC ();
1266 TOP
= Fmax (2, &TOP
);
1267 AFTER_POTENTIAL_GC ();
1271 BEFORE_POTENTIAL_GC ();
1273 TOP
= Fmin (2, &TOP
);
1274 AFTER_POTENTIAL_GC ();
1278 BEFORE_POTENTIAL_GC ();
1280 TOP
= Ftimes (2, &TOP
);
1281 AFTER_POTENTIAL_GC ();
1285 BEFORE_POTENTIAL_GC ();
1287 TOP
= Fquo (2, &TOP
);
1288 AFTER_POTENTIAL_GC ();
1294 BEFORE_POTENTIAL_GC ();
1296 TOP
= Frem (TOP
, v1
);
1297 AFTER_POTENTIAL_GC ();
1304 XSETFASTINT (v1
, PT
);
1310 BEFORE_POTENTIAL_GC ();
1311 TOP
= Fgoto_char (TOP
);
1312 AFTER_POTENTIAL_GC ();
1316 BEFORE_POTENTIAL_GC ();
1317 TOP
= Finsert (1, &TOP
);
1318 AFTER_POTENTIAL_GC ();
1323 BEFORE_POTENTIAL_GC ();
1325 TOP
= Finsert (op
, &TOP
);
1326 AFTER_POTENTIAL_GC ();
1332 XSETFASTINT (v1
, ZV
);
1340 XSETFASTINT (v1
, BEGV
);
1346 BEFORE_POTENTIAL_GC ();
1347 TOP
= Fchar_after (TOP
);
1348 AFTER_POTENTIAL_GC ();
1351 case Bfollowing_char
:
1354 BEFORE_POTENTIAL_GC ();
1355 v1
= Ffollowing_char ();
1356 AFTER_POTENTIAL_GC ();
1361 case Bpreceding_char
:
1364 BEFORE_POTENTIAL_GC ();
1365 v1
= Fprevious_char ();
1366 AFTER_POTENTIAL_GC ();
1371 case Bcurrent_column
:
1374 BEFORE_POTENTIAL_GC ();
1375 XSETFASTINT (v1
, (int) current_column ()); /* iftc */
1376 AFTER_POTENTIAL_GC ();
1382 BEFORE_POTENTIAL_GC ();
1383 TOP
= Findent_to (TOP
, Qnil
);
1384 AFTER_POTENTIAL_GC ();
1403 case Bcurrent_buffer
:
1404 PUSH (Fcurrent_buffer ());
1408 BEFORE_POTENTIAL_GC ();
1409 TOP
= Fset_buffer (TOP
);
1410 AFTER_POTENTIAL_GC ();
1413 case Binteractive_p
:
1414 PUSH (Finteractive_p ());
1418 BEFORE_POTENTIAL_GC ();
1419 TOP
= Fforward_char (TOP
);
1420 AFTER_POTENTIAL_GC ();
1424 BEFORE_POTENTIAL_GC ();
1425 TOP
= Fforward_word (TOP
);
1426 AFTER_POTENTIAL_GC ();
1429 case Bskip_chars_forward
:
1432 BEFORE_POTENTIAL_GC ();
1434 TOP
= Fskip_chars_forward (TOP
, v1
);
1435 AFTER_POTENTIAL_GC ();
1439 case Bskip_chars_backward
:
1442 BEFORE_POTENTIAL_GC ();
1444 TOP
= Fskip_chars_backward (TOP
, v1
);
1445 AFTER_POTENTIAL_GC ();
1450 BEFORE_POTENTIAL_GC ();
1451 TOP
= Fforward_line (TOP
);
1452 AFTER_POTENTIAL_GC ();
1459 BEFORE_POTENTIAL_GC ();
1460 CHECK_CHARACTER (TOP
);
1461 AFTER_POTENTIAL_GC ();
1463 if (NILP (current_buffer
->enable_multibyte_characters
))
1464 MAKE_CHAR_MULTIBYTE (c
);
1465 XSETFASTINT (TOP
, syntax_code_spec
[(int) SYNTAX (c
)]);
1469 case Bbuffer_substring
:
1472 BEFORE_POTENTIAL_GC ();
1474 TOP
= Fbuffer_substring (TOP
, v1
);
1475 AFTER_POTENTIAL_GC ();
1479 case Bdelete_region
:
1482 BEFORE_POTENTIAL_GC ();
1484 TOP
= Fdelete_region (TOP
, v1
);
1485 AFTER_POTENTIAL_GC ();
1489 case Bnarrow_to_region
:
1492 BEFORE_POTENTIAL_GC ();
1494 TOP
= Fnarrow_to_region (TOP
, v1
);
1495 AFTER_POTENTIAL_GC ();
1500 BEFORE_POTENTIAL_GC ();
1502 AFTER_POTENTIAL_GC ();
1506 BEFORE_POTENTIAL_GC ();
1507 TOP
= Fend_of_line (TOP
);
1508 AFTER_POTENTIAL_GC ();
1514 BEFORE_POTENTIAL_GC ();
1517 TOP
= Fset_marker (TOP
, v2
, v1
);
1518 AFTER_POTENTIAL_GC ();
1522 case Bmatch_beginning
:
1523 BEFORE_POTENTIAL_GC ();
1524 TOP
= Fmatch_beginning (TOP
);
1525 AFTER_POTENTIAL_GC ();
1529 BEFORE_POTENTIAL_GC ();
1530 TOP
= Fmatch_end (TOP
);
1531 AFTER_POTENTIAL_GC ();
1535 BEFORE_POTENTIAL_GC ();
1536 TOP
= Fupcase (TOP
);
1537 AFTER_POTENTIAL_GC ();
1541 BEFORE_POTENTIAL_GC ();
1542 TOP
= Fdowncase (TOP
);
1543 AFTER_POTENTIAL_GC ();
1546 case Bstringeqlsign
:
1549 BEFORE_POTENTIAL_GC ();
1551 TOP
= Fstring_equal (TOP
, v1
);
1552 AFTER_POTENTIAL_GC ();
1559 BEFORE_POTENTIAL_GC ();
1561 TOP
= Fstring_lessp (TOP
, v1
);
1562 AFTER_POTENTIAL_GC ();
1570 TOP
= Fequal (TOP
, v1
);
1577 BEFORE_POTENTIAL_GC ();
1579 TOP
= Fnthcdr (TOP
, v1
);
1580 AFTER_POTENTIAL_GC ();
1589 /* Exchange args and then do nth. */
1590 BEFORE_POTENTIAL_GC ();
1594 AFTER_POTENTIAL_GC ();
1597 while (--op
>= 0 && CONSP (v1
))
1604 BEFORE_POTENTIAL_GC ();
1606 TOP
= Felt (TOP
, v1
);
1607 AFTER_POTENTIAL_GC ();
1615 BEFORE_POTENTIAL_GC ();
1617 TOP
= Fmember (TOP
, v1
);
1618 AFTER_POTENTIAL_GC ();
1625 BEFORE_POTENTIAL_GC ();
1627 TOP
= Fassq (TOP
, v1
);
1628 AFTER_POTENTIAL_GC ();
1633 BEFORE_POTENTIAL_GC ();
1634 TOP
= Fnreverse (TOP
);
1635 AFTER_POTENTIAL_GC ();
1641 BEFORE_POTENTIAL_GC ();
1643 TOP
= Fsetcar (TOP
, v1
);
1644 AFTER_POTENTIAL_GC ();
1651 BEFORE_POTENTIAL_GC ();
1653 TOP
= Fsetcdr (TOP
, v1
);
1654 AFTER_POTENTIAL_GC ();
1662 TOP
= CAR_SAFE (v1
);
1670 TOP
= CDR_SAFE (v1
);
1675 BEFORE_POTENTIAL_GC ();
1677 TOP
= Fnconc (2, &TOP
);
1678 AFTER_POTENTIAL_GC ();
1682 TOP
= (NUMBERP (TOP
) ? Qt
: Qnil
);
1686 TOP
= INTEGERP (TOP
) ? Qt
: Qnil
;
1689 #ifdef BYTE_CODE_SAFE
1691 BEFORE_POTENTIAL_GC ();
1692 error ("set-mark is an obsolete bytecode");
1693 AFTER_POTENTIAL_GC ();
1696 BEFORE_POTENTIAL_GC ();
1697 error ("scan-buffer is an obsolete bytecode");
1698 AFTER_POTENTIAL_GC ();
1702 /* Handy byte-codes for lexical binding. */
1709 PUSH (stack
.bottom
[op
- Bstack_ref
]);
1712 PUSH (stack
.bottom
[FETCH
]);
1715 PUSH (stack
.bottom
[FETCH2
]);
1718 stack
.bottom
[FETCH
] = POP
;
1721 stack
.bottom
[FETCH2
] = POP
;
1735 #ifdef BYTE_CODE_SAFE
1740 if ((op
-= Bconstant
) >= const_length
)
1746 PUSH (vectorp
[op
- Bconstant
]);
1753 byte_stack_list
= byte_stack_list
->next
;
1755 /* Binds and unbinds are supposed to be compiled balanced. */
1756 if (SPECPDL_INDEX () != count
)
1757 #ifdef BYTE_CODE_SAFE
1758 error ("binding stack not balanced (serious byte compiler bug)");
1767 syms_of_bytecode (void)
1769 Qbytecode
= intern_c_string ("byte-code");
1770 staticpro (&Qbytecode
);
1772 defsubr (&Sbyte_code
);
1774 #ifdef BYTE_CODE_METER
1776 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter
,
1777 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
1778 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1779 opcode CODE has been executed.
1780 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1781 indicates how many times the byte opcodes CODE1 and CODE2 have been
1782 executed in succession. */);
1784 DEFVAR_BOOL ("byte-metering-on", byte_metering_on
,
1785 doc
: /* If non-nil, keep profiling information on byte code usage.
1786 The variable byte-code-meter indicates how often each byte opcode is used.
1787 If a symbol has a property named `byte-code-meter' whose value is an
1788 integer, it is incremented each time that symbol's function is called. */);
1790 byte_metering_on
= 0;
1791 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
1792 Qbyte_code_meter
= intern_c_string ("byte-code-meter");
1793 staticpro (&Qbyte_code_meter
);
1797 XVECTOR (Vbyte_code_meter
)->contents
[i
] =
1798 Fmake_vector (make_number (256), make_number (0));