1 /* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
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.
40 #include "character.h"
44 #ifdef CHECK_FRAME_FONT
50 * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for
51 * debugging the byte compiler...)
53 * define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
55 /* #define BYTE_CODE_SAFE */
56 /* #define BYTE_CODE_METER */
59 #ifdef BYTE_CODE_METER
61 Lisp_Object Vbyte_code_meter
, Qbyte_code_meter
;
64 #define METER_2(code1, code2) \
65 XFASTINT (XVECTOR (XVECTOR (Vbyte_code_meter)->contents[(code1)]) \
68 #define METER_1(code) METER_2 (0, (code))
70 #define METER_CODE(last_code, this_code) \
72 if (byte_metering_on) \
74 if (METER_1 (this_code) < MOST_POSITIVE_FIXNUM) \
75 METER_1 (this_code)++; \
77 && METER_2 (last_code, this_code) < MOST_POSITIVE_FIXNUM) \
78 METER_2 (last_code, this_code)++; \
82 #else /* no BYTE_CODE_METER */
84 #define METER_CODE(last_code, this_code)
86 #endif /* no BYTE_CODE_METER */
89 Lisp_Object Qbytecode
;
90 extern Lisp_Object Qand_optional
, Qand_rest
;
119 #define Bsymbol_value 0112
120 #define Bsymbol_function 0113
124 #define Bsubstring 0117
125 #define Bconcat2 0120
126 #define Bconcat3 0121
127 #define Bconcat4 0122
130 #define Beqlsign 0125
143 /* Was Bmark in v17. */
144 #define Bsave_current_buffer 0141
145 #define Bgoto_char 0142
147 #define Bpoint_max 0144
148 #define Bpoint_min 0145
149 #define Bchar_after 0146
150 #define Bfollowing_char 0147
151 #define Bpreceding_char 0150
152 #define Bcurrent_column 0151
153 #define Bindent_to 0152
154 #define Bscan_buffer 0153 /* No longer generated as of v18 */
159 #define Bcurrent_buffer 0160
160 #define Bset_buffer 0161
161 #define Bsave_current_buffer_1 0162 /* Replacing Bsave_current_buffer. */
162 #define Bread_char 0162 /* No longer generated as of v19 */
163 #define Bset_mark 0163 /* this loser is no longer generated as of v18 */
164 #define Binteractive_p 0164 /* Needed since interactive-p takes unevalled args */
166 #define Bforward_char 0165
167 #define Bforward_word 0166
168 #define Bskip_chars_forward 0167
169 #define Bskip_chars_backward 0170
170 #define Bforward_line 0171
171 #define Bchar_syntax 0172
172 #define Bbuffer_substring 0173
173 #define Bdelete_region 0174
174 #define Bnarrow_to_region 0175
176 #define Bend_of_line 0177
178 #define Bconstant2 0201
180 #define Bgotoifnil 0203
181 #define Bgotoifnonnil 0204
182 #define Bgotoifnilelsepop 0205
183 #define Bgotoifnonnilelsepop 0206
185 #define Bdiscard 0210
188 #define Bsave_excursion 0212
189 #define Bsave_window_excursion 0213
190 #define Bsave_restriction 0214
193 #define Bunwind_protect 0216
194 #define Bcondition_case 0217
195 #define Btemp_output_buffer_setup 0220
196 #define Btemp_output_buffer_show 0221
198 #define Bunbind_all 0222
200 #define Bset_marker 0223
201 #define Bmatch_beginning 0224
202 #define Bmatch_end 0225
204 #define Bdowncase 0227
206 #define Bstringeqlsign 0230
207 #define Bstringlss 0231
213 #define Bnreverse 0237
216 #define Bcar_safe 0242
217 #define Bcdr_safe 0243
221 #define Bnumberp 0247
222 #define Bintegerp 0250
225 #define BRgotoifnil 0253
226 #define BRgotoifnonnil 0254
227 #define BRgotoifnilelsepop 0255
228 #define BRgotoifnonnilelsepop 0256
231 #define BconcatN 0260
232 #define BinsertN 0261
234 /* Bstack_ref is code 0. */
235 #define Bstack_set 0262
236 #define Bstack_set2 0263
237 #define Bvec_ref 0264
238 #define Bvec_set 0265
239 #define BdiscardN 0266
241 #define Bconstant 0300
242 #define CONSTANTLIM 0100
245 /* Structure describing a value stack used during byte-code execution
250 /* Program counter. This points into the byte_string below
251 and is relocated when that string is relocated. */
252 const unsigned char *pc
;
254 /* Top and bottom of stack. The bottom points to an area of memory
255 allocated with alloca in Fbyte_code. */
256 Lisp_Object
*top
, *bottom
;
258 /* The string containing the byte-code, and its current address.
259 Storing this here protects it from GC because mark_byte_stack
261 Lisp_Object byte_string
;
262 const unsigned char *byte_string_start
;
264 /* The vector of constants used during byte-code execution. Storing
265 this here protects it from GC because mark_byte_stack marks it. */
266 Lisp_Object constants
;
268 /* Next entry in byte_stack_list. */
269 struct byte_stack
*next
;
272 /* A list of currently active byte-code execution value stacks.
273 Fbyte_code adds an entry to the head of this list before it starts
274 processing byte-code, and it removed the entry again when it is
275 done. Signalling an error truncates the list analoguous to
278 struct byte_stack
*byte_stack_list
;
281 /* Mark objects on byte_stack_list. Called during GC. */
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. */
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 #define BEFORE_POTENTIAL_GC() stack.top = top
362 #define AFTER_POTENTIAL_GC() stack.top = NULL
364 /* Garbage collect if we have consed enough since the last time.
365 We do this at every branch, to avoid loops that never GC. */
368 if (consing_since_gc > gc_cons_threshold \
369 && consing_since_gc > gc_relative_threshold) \
371 BEFORE_POTENTIAL_GC (); \
372 Fgarbage_collect (); \
373 AFTER_POTENTIAL_GC (); \
377 /* Check for jumping out of range. */
379 #ifdef BYTE_CODE_SAFE
381 #define CHECK_RANGE(ARG) \
382 if (ARG >= bytestr_length) abort ()
384 #else /* not BYTE_CODE_SAFE */
386 #define CHECK_RANGE(ARG)
388 #endif /* not BYTE_CODE_SAFE */
390 /* A version of the QUIT macro which makes sure that the stack top is
391 set before signaling `quit'. */
393 #define BYTE_CODE_QUIT \
395 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
397 Lisp_Object flag = Vquit_flag; \
399 BEFORE_POTENTIAL_GC (); \
400 if (EQ (Vthrow_on_input, flag)) \
401 Fthrow (Vthrow_on_input, Qt); \
402 Fsignal (Qquit, Qnil); \
403 AFTER_POTENTIAL_GC (); \
405 ELSE_PENDING_SIGNALS \
409 DEFUN ("byte-code", Fbyte_code
, Sbyte_code
, 3, MANY
, 0,
410 doc
: /* Function used internally in byte-compiled code.
411 The first argument, BYTESTR, is a string of byte code;
412 the second, VECTOR, a vector of constants;
413 the third, MAXDEPTH, the maximum stack depth used in this function.
414 If the third argument is incorrect, Emacs may crash.
416 If ARGS-TEMPLATE is specified, it is an argument list specification,
417 according to which any remaining arguments are pushed on the stack
418 before executing BYTESTR.
420 usage: (byte-code BYTESTR VECTOR MAXDEP &optional ARGS-TEMPLATE &rest ARGS) */)
425 Lisp_Object args_tmpl
= nargs
>= 4 ? args
[3] : Qnil
;
426 int pnargs
= nargs
>= 4 ? nargs
- 4 : 0;
427 Lisp_Object
*pargs
= nargs
>= 4 ? args
+ 4 : 0;
428 return exec_byte_code (args
[0], args
[1], args
[2], args_tmpl
, pnargs
, pargs
);
431 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
432 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
433 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
434 argument list (including &rest, &optional, etc.), and ARGS, of size
435 NARGS, should be a vector of the actual arguments. The arguments in
436 ARGS are pushed on the stack according to ARGS_TEMPLATE before
437 executing BYTESTR. */
440 exec_byte_code (bytestr
, vector
, maxdepth
, args_template
, nargs
, args
)
441 Lisp_Object bytestr
, vector
, maxdepth
, args_template
;
445 int count
= SPECPDL_INDEX ();
446 #ifdef BYTE_CODE_METER
451 /* Lisp_Object v1, v2; */
452 Lisp_Object
*vectorp
;
453 #ifdef BYTE_CODE_SAFE
454 int const_length
= XVECTOR (vector
)->size
;
458 struct byte_stack stack
;
462 #if 0 /* CHECK_FRAME_FONT */
464 struct frame
*f
= SELECTED_FRAME ();
466 && FRAME_FONT (f
)->direction
!= 0
467 && FRAME_FONT (f
)->direction
!= 1)
472 CHECK_STRING (bytestr
);
473 CHECK_VECTOR (vector
);
474 CHECK_NUMBER (maxdepth
);
476 if (STRING_MULTIBYTE (bytestr
))
477 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
478 because they produced a raw 8-bit string for byte-code and now
479 such a byte-code string is loaded as multibyte while raw 8-bit
480 characters converted to multibyte form. Thus, now we must
481 convert them back to the originally intended unibyte form. */
482 bytestr
= Fstring_as_unibyte (bytestr
);
484 bytestr_length
= SBYTES (bytestr
);
485 vectorp
= XVECTOR (vector
)->contents
;
487 stack
.byte_string
= bytestr
;
488 stack
.pc
= stack
.byte_string_start
= SDATA (bytestr
);
489 stack
.constants
= vector
;
490 stack
.bottom
= (Lisp_Object
*) alloca (XFASTINT (maxdepth
)
491 * sizeof (Lisp_Object
));
492 top
= stack
.bottom
- 1;
494 stack
.next
= byte_stack_list
;
495 byte_stack_list
= &stack
;
497 #ifdef BYTE_CODE_SAFE
498 stacke
= stack
.bottom
- 1 + XFASTINT (maxdepth
);
501 if (! NILP (args_template
))
502 /* We should push some arguments on the stack. */
505 int pushed
= 0, optional
= 0;
507 for (at
= args_template
; CONSP (at
); at
= XCDR (at
))
508 if (EQ (XCAR (at
), Qand_optional
))
510 else if (EQ (XCAR (at
), Qand_rest
))
512 PUSH (Flist (nargs
, args
));
517 else if (pushed
< nargs
)
527 if (pushed
!= nargs
|| !NILP (at
))
528 Fsignal (Qwrong_number_of_arguments
,
529 Fcons (args_template
, Fcons (make_number (nargs
), Qnil
)));
534 #ifdef BYTE_CODE_SAFE
537 else if (top
< stack
.bottom
- 1)
541 #ifdef BYTE_CODE_METER
543 this_op
= op
= FETCH
;
544 METER_CODE (prev_op
, op
);
564 /* This seems to be the most frequently executed byte-code
565 among the Bvarref's, so avoid a goto here. */
575 if (XSYMBOL (v1
)->redirect
!= SYMBOL_PLAINVAL
576 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)),
579 BEFORE_POTENTIAL_GC ();
580 v2
= Fsymbol_value (v1
);
581 AFTER_POTENTIAL_GC ();
586 BEFORE_POTENTIAL_GC ();
587 v2
= Fsymbol_value (v1
);
588 AFTER_POTENTIAL_GC ();
604 stack
.pc
= stack
.byte_string_start
+ op
;
621 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
628 BEFORE_POTENTIAL_GC ();
630 TOP
= Fmemq (TOP
, v1
);
631 AFTER_POTENTIAL_GC ();
660 Lisp_Object sym
, val
;
665 /* Inline the most common case. */
667 && !EQ (val
, Qunbound
)
668 && !XSYMBOL (sym
)->redirect
669 && !SYMBOL_CONSTANT_P (sym
))
670 XSYMBOL (sym
)->val
.value
= val
;
673 BEFORE_POTENTIAL_GC ();
674 set_internal (sym
, val
, Qnil
, 0);
675 AFTER_POTENTIAL_GC ();
689 /* ------------------ */
707 /* Specbind can signal and thus GC. */
708 BEFORE_POTENTIAL_GC ();
709 specbind (vectorp
[op
], POP
);
710 AFTER_POTENTIAL_GC ();
730 BEFORE_POTENTIAL_GC ();
732 #ifdef BYTE_CODE_METER
733 if (byte_metering_on
&& SYMBOLP (TOP
))
738 v2
= Fget (v1
, Qbyte_code_meter
);
740 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
742 XSETINT (v2
, XINT (v2
) + 1);
743 Fput (v1
, Qbyte_code_meter
, v2
);
747 TOP
= Ffuncall (op
+ 1, &TOP
);
748 AFTER_POTENTIAL_GC ();
768 BEFORE_POTENTIAL_GC ();
769 unbind_to (SPECPDL_INDEX () - op
, Qnil
);
770 AFTER_POTENTIAL_GC ();
774 /* To unbind back to the beginning of this frame. Not used yet,
775 but will be needed for tail-recursion elimination. */
776 BEFORE_POTENTIAL_GC ();
777 unbind_to (count
, Qnil
);
778 AFTER_POTENTIAL_GC ();
784 op
= FETCH2
; /* pc = FETCH2 loses since FETCH2 contains pc++ */
786 stack
.pc
= stack
.byte_string_start
+ op
;
799 stack
.pc
= stack
.byte_string_start
+ op
;
804 case Bgotoifnilelsepop
:
811 stack
.pc
= stack
.byte_string_start
+ op
;
816 case Bgotoifnonnilelsepop
:
823 stack
.pc
= stack
.byte_string_start
+ op
;
831 stack
.pc
+= (int) *stack
.pc
- 127;
842 stack
.pc
+= (int) *stack
.pc
- 128;
856 stack
.pc
+= (int) *stack
.pc
- 128;
862 case BRgotoifnilelsepop
:
868 stack
.pc
+= op
- 128;
873 case BRgotoifnonnilelsepop
:
879 stack
.pc
+= op
- 128;
893 PUSH (vectorp
[FETCH2
]);
896 case Bsave_excursion
:
897 record_unwind_protect (save_excursion_restore
,
898 save_excursion_save ());
901 case Bsave_current_buffer
:
902 case Bsave_current_buffer_1
:
903 record_unwind_protect (set_buffer_if_live
, Fcurrent_buffer ());
906 case Bsave_window_excursion
:
907 BEFORE_POTENTIAL_GC ();
908 TOP
= Fsave_window_excursion (TOP
);
909 AFTER_POTENTIAL_GC ();
912 case Bsave_restriction
:
913 record_unwind_protect (save_restriction_restore
,
914 save_restriction_save ());
920 BEFORE_POTENTIAL_GC ();
922 TOP
= internal_catch (TOP
, Feval
, v1
);
923 AFTER_POTENTIAL_GC ();
927 case Bunwind_protect
:
928 record_unwind_protect (Fprogn
, POP
);
931 case Bcondition_case
:
933 Lisp_Object handlers
, body
;
936 BEFORE_POTENTIAL_GC ();
937 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
);
938 AFTER_POTENTIAL_GC ();
942 case Btemp_output_buffer_setup
:
943 BEFORE_POTENTIAL_GC ();
945 temp_output_buffer_setup (SDATA (TOP
));
946 AFTER_POTENTIAL_GC ();
947 TOP
= Vstandard_output
;
950 case Btemp_output_buffer_show
:
953 BEFORE_POTENTIAL_GC ();
955 temp_output_buffer_show (TOP
);
957 /* pop binding of standard-output */
958 unbind_to (SPECPDL_INDEX () - 1, Qnil
);
959 AFTER_POTENTIAL_GC ();
966 BEFORE_POTENTIAL_GC ();
970 AFTER_POTENTIAL_GC ();
973 while (--op
>= 0 && CONSP (v1
))
981 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
985 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
989 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
993 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
997 TOP
= NILP (TOP
) ? Qt
: Qnil
;
1004 TOP
= Fcons (TOP
, v1
);
1009 TOP
= Fcons (TOP
, Qnil
);
1016 TOP
= Fcons (TOP
, Fcons (v1
, Qnil
));
1022 TOP
= Flist (3, &TOP
);
1027 TOP
= Flist (4, &TOP
);
1033 TOP
= Flist (op
, &TOP
);
1037 BEFORE_POTENTIAL_GC ();
1038 TOP
= Flength (TOP
);
1039 AFTER_POTENTIAL_GC ();
1045 BEFORE_POTENTIAL_GC ();
1047 TOP
= Faref (TOP
, v1
);
1048 AFTER_POTENTIAL_GC ();
1055 BEFORE_POTENTIAL_GC ();
1057 TOP
= Faset (TOP
, v1
, v2
);
1058 AFTER_POTENTIAL_GC ();
1063 BEFORE_POTENTIAL_GC ();
1064 TOP
= Fsymbol_value (TOP
);
1065 AFTER_POTENTIAL_GC ();
1068 case Bsymbol_function
:
1069 BEFORE_POTENTIAL_GC ();
1070 TOP
= Fsymbol_function (TOP
);
1071 AFTER_POTENTIAL_GC ();
1077 BEFORE_POTENTIAL_GC ();
1079 TOP
= Fset (TOP
, v1
);
1080 AFTER_POTENTIAL_GC ();
1087 BEFORE_POTENTIAL_GC ();
1089 TOP
= Ffset (TOP
, v1
);
1090 AFTER_POTENTIAL_GC ();
1097 BEFORE_POTENTIAL_GC ();
1099 TOP
= Fget (TOP
, v1
);
1100 AFTER_POTENTIAL_GC ();
1107 BEFORE_POTENTIAL_GC ();
1109 TOP
= Fsubstring (TOP
, v1
, v2
);
1110 AFTER_POTENTIAL_GC ();
1115 BEFORE_POTENTIAL_GC ();
1117 TOP
= Fconcat (2, &TOP
);
1118 AFTER_POTENTIAL_GC ();
1122 BEFORE_POTENTIAL_GC ();
1124 TOP
= Fconcat (3, &TOP
);
1125 AFTER_POTENTIAL_GC ();
1129 BEFORE_POTENTIAL_GC ();
1131 TOP
= Fconcat (4, &TOP
);
1132 AFTER_POTENTIAL_GC ();
1137 BEFORE_POTENTIAL_GC ();
1139 TOP
= Fconcat (op
, &TOP
);
1140 AFTER_POTENTIAL_GC ();
1149 XSETINT (v1
, XINT (v1
) - 1);
1154 BEFORE_POTENTIAL_GC ();
1156 AFTER_POTENTIAL_GC ();
1167 XSETINT (v1
, XINT (v1
) + 1);
1172 BEFORE_POTENTIAL_GC ();
1174 AFTER_POTENTIAL_GC ();
1182 BEFORE_POTENTIAL_GC ();
1184 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
1185 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
1186 AFTER_POTENTIAL_GC ();
1187 if (FLOATP (v1
) || FLOATP (v2
))
1191 f1
= (FLOATP (v1
) ? XFLOAT_DATA (v1
) : XINT (v1
));
1192 f2
= (FLOATP (v2
) ? XFLOAT_DATA (v2
) : XINT (v2
));
1193 TOP
= (f1
== f2
? Qt
: Qnil
);
1196 TOP
= (XINT (v1
) == XINT (v2
) ? Qt
: Qnil
);
1203 BEFORE_POTENTIAL_GC ();
1205 TOP
= Fgtr (TOP
, v1
);
1206 AFTER_POTENTIAL_GC ();
1213 BEFORE_POTENTIAL_GC ();
1215 TOP
= Flss (TOP
, v1
);
1216 AFTER_POTENTIAL_GC ();
1223 BEFORE_POTENTIAL_GC ();
1225 TOP
= Fleq (TOP
, v1
);
1226 AFTER_POTENTIAL_GC ();
1233 BEFORE_POTENTIAL_GC ();
1235 TOP
= Fgeq (TOP
, v1
);
1236 AFTER_POTENTIAL_GC ();
1241 BEFORE_POTENTIAL_GC ();
1243 TOP
= Fminus (2, &TOP
);
1244 AFTER_POTENTIAL_GC ();
1253 XSETINT (v1
, - XINT (v1
));
1258 BEFORE_POTENTIAL_GC ();
1259 TOP
= Fminus (1, &TOP
);
1260 AFTER_POTENTIAL_GC ();
1266 BEFORE_POTENTIAL_GC ();
1268 TOP
= Fplus (2, &TOP
);
1269 AFTER_POTENTIAL_GC ();
1273 BEFORE_POTENTIAL_GC ();
1275 TOP
= Fmax (2, &TOP
);
1276 AFTER_POTENTIAL_GC ();
1280 BEFORE_POTENTIAL_GC ();
1282 TOP
= Fmin (2, &TOP
);
1283 AFTER_POTENTIAL_GC ();
1287 BEFORE_POTENTIAL_GC ();
1289 TOP
= Ftimes (2, &TOP
);
1290 AFTER_POTENTIAL_GC ();
1294 BEFORE_POTENTIAL_GC ();
1296 TOP
= Fquo (2, &TOP
);
1297 AFTER_POTENTIAL_GC ();
1303 BEFORE_POTENTIAL_GC ();
1305 TOP
= Frem (TOP
, v1
);
1306 AFTER_POTENTIAL_GC ();
1313 XSETFASTINT (v1
, PT
);
1319 BEFORE_POTENTIAL_GC ();
1320 TOP
= Fgoto_char (TOP
);
1321 AFTER_POTENTIAL_GC ();
1325 BEFORE_POTENTIAL_GC ();
1326 TOP
= Finsert (1, &TOP
);
1327 AFTER_POTENTIAL_GC ();
1332 BEFORE_POTENTIAL_GC ();
1334 TOP
= Finsert (op
, &TOP
);
1335 AFTER_POTENTIAL_GC ();
1341 XSETFASTINT (v1
, ZV
);
1349 XSETFASTINT (v1
, BEGV
);
1355 BEFORE_POTENTIAL_GC ();
1356 TOP
= Fchar_after (TOP
);
1357 AFTER_POTENTIAL_GC ();
1360 case Bfollowing_char
:
1363 BEFORE_POTENTIAL_GC ();
1364 v1
= Ffollowing_char ();
1365 AFTER_POTENTIAL_GC ();
1370 case Bpreceding_char
:
1373 BEFORE_POTENTIAL_GC ();
1374 v1
= Fprevious_char ();
1375 AFTER_POTENTIAL_GC ();
1380 case Bcurrent_column
:
1383 BEFORE_POTENTIAL_GC ();
1384 XSETFASTINT (v1
, (int) current_column ()); /* iftc */
1385 AFTER_POTENTIAL_GC ();
1391 BEFORE_POTENTIAL_GC ();
1392 TOP
= Findent_to (TOP
, Qnil
);
1393 AFTER_POTENTIAL_GC ();
1412 case Bcurrent_buffer
:
1413 PUSH (Fcurrent_buffer ());
1417 BEFORE_POTENTIAL_GC ();
1418 TOP
= Fset_buffer (TOP
);
1419 AFTER_POTENTIAL_GC ();
1422 case Binteractive_p
:
1423 PUSH (Finteractive_p ());
1427 BEFORE_POTENTIAL_GC ();
1428 TOP
= Fforward_char (TOP
);
1429 AFTER_POTENTIAL_GC ();
1433 BEFORE_POTENTIAL_GC ();
1434 TOP
= Fforward_word (TOP
);
1435 AFTER_POTENTIAL_GC ();
1438 case Bskip_chars_forward
:
1441 BEFORE_POTENTIAL_GC ();
1443 TOP
= Fskip_chars_forward (TOP
, v1
);
1444 AFTER_POTENTIAL_GC ();
1448 case Bskip_chars_backward
:
1451 BEFORE_POTENTIAL_GC ();
1453 TOP
= Fskip_chars_backward (TOP
, v1
);
1454 AFTER_POTENTIAL_GC ();
1459 BEFORE_POTENTIAL_GC ();
1460 TOP
= Fforward_line (TOP
);
1461 AFTER_POTENTIAL_GC ();
1468 BEFORE_POTENTIAL_GC ();
1469 CHECK_CHARACTER (TOP
);
1470 AFTER_POTENTIAL_GC ();
1472 if (NILP (current_buffer
->enable_multibyte_characters
))
1473 MAKE_CHAR_MULTIBYTE (c
);
1474 XSETFASTINT (TOP
, syntax_code_spec
[(int) SYNTAX (c
)]);
1478 case Bbuffer_substring
:
1481 BEFORE_POTENTIAL_GC ();
1483 TOP
= Fbuffer_substring (TOP
, v1
);
1484 AFTER_POTENTIAL_GC ();
1488 case Bdelete_region
:
1491 BEFORE_POTENTIAL_GC ();
1493 TOP
= Fdelete_region (TOP
, v1
);
1494 AFTER_POTENTIAL_GC ();
1498 case Bnarrow_to_region
:
1501 BEFORE_POTENTIAL_GC ();
1503 TOP
= Fnarrow_to_region (TOP
, v1
);
1504 AFTER_POTENTIAL_GC ();
1509 BEFORE_POTENTIAL_GC ();
1511 AFTER_POTENTIAL_GC ();
1515 BEFORE_POTENTIAL_GC ();
1516 TOP
= Fend_of_line (TOP
);
1517 AFTER_POTENTIAL_GC ();
1523 BEFORE_POTENTIAL_GC ();
1526 TOP
= Fset_marker (TOP
, v2
, v1
);
1527 AFTER_POTENTIAL_GC ();
1531 case Bmatch_beginning
:
1532 BEFORE_POTENTIAL_GC ();
1533 TOP
= Fmatch_beginning (TOP
);
1534 AFTER_POTENTIAL_GC ();
1538 BEFORE_POTENTIAL_GC ();
1539 TOP
= Fmatch_end (TOP
);
1540 AFTER_POTENTIAL_GC ();
1544 BEFORE_POTENTIAL_GC ();
1545 TOP
= Fupcase (TOP
);
1546 AFTER_POTENTIAL_GC ();
1550 BEFORE_POTENTIAL_GC ();
1551 TOP
= Fdowncase (TOP
);
1552 AFTER_POTENTIAL_GC ();
1555 case Bstringeqlsign
:
1558 BEFORE_POTENTIAL_GC ();
1560 TOP
= Fstring_equal (TOP
, v1
);
1561 AFTER_POTENTIAL_GC ();
1568 BEFORE_POTENTIAL_GC ();
1570 TOP
= Fstring_lessp (TOP
, v1
);
1571 AFTER_POTENTIAL_GC ();
1579 TOP
= Fequal (TOP
, v1
);
1586 BEFORE_POTENTIAL_GC ();
1588 TOP
= Fnthcdr (TOP
, v1
);
1589 AFTER_POTENTIAL_GC ();
1598 /* Exchange args and then do nth. */
1599 BEFORE_POTENTIAL_GC ();
1603 AFTER_POTENTIAL_GC ();
1606 while (--op
>= 0 && CONSP (v1
))
1613 BEFORE_POTENTIAL_GC ();
1615 TOP
= Felt (TOP
, v1
);
1616 AFTER_POTENTIAL_GC ();
1624 BEFORE_POTENTIAL_GC ();
1626 TOP
= Fmember (TOP
, v1
);
1627 AFTER_POTENTIAL_GC ();
1634 BEFORE_POTENTIAL_GC ();
1636 TOP
= Fassq (TOP
, v1
);
1637 AFTER_POTENTIAL_GC ();
1642 BEFORE_POTENTIAL_GC ();
1643 TOP
= Fnreverse (TOP
);
1644 AFTER_POTENTIAL_GC ();
1650 BEFORE_POTENTIAL_GC ();
1652 TOP
= Fsetcar (TOP
, v1
);
1653 AFTER_POTENTIAL_GC ();
1660 BEFORE_POTENTIAL_GC ();
1662 TOP
= Fsetcdr (TOP
, v1
);
1663 AFTER_POTENTIAL_GC ();
1671 TOP
= CAR_SAFE (v1
);
1679 TOP
= CDR_SAFE (v1
);
1684 BEFORE_POTENTIAL_GC ();
1686 TOP
= Fnconc (2, &TOP
);
1687 AFTER_POTENTIAL_GC ();
1691 TOP
= (NUMBERP (TOP
) ? Qt
: Qnil
);
1695 TOP
= INTEGERP (TOP
) ? Qt
: Qnil
;
1698 #ifdef BYTE_CODE_SAFE
1700 BEFORE_POTENTIAL_GC ();
1701 error ("set-mark is an obsolete bytecode");
1702 AFTER_POTENTIAL_GC ();
1705 BEFORE_POTENTIAL_GC ();
1706 error ("scan-buffer is an obsolete bytecode");
1707 AFTER_POTENTIAL_GC ();
1711 /* Handy byte-codes for lexical binding. */
1718 PUSH (stack
.bottom
[op
- Bstack_ref
]);
1721 PUSH (stack
.bottom
[FETCH
]);
1724 PUSH (stack
.bottom
[FETCH2
]);
1727 stack
.bottom
[FETCH
] = POP
;
1730 stack
.bottom
[FETCH2
] = POP
;
1734 /* These byte-codes used mostly for variable references to
1735 lexically bound variables that are in an environment vector
1736 instead of on the byte-interpreter stack (generally those
1737 variables which might be shared with a closure). */
1740 Lisp_Object vec
= POP
;
1742 if (! VECTORP (vec
))
1743 wrong_type_argument (Qvectorp
, vec
);
1744 else if (index
< 0 || index
>= XVECTOR (vec
)->size
)
1745 args_out_of_range (vec
, index
);
1748 PUSH (XVECTOR (vec
)->contents
[index
]);
1750 XVECTOR (vec
)->contents
[index
] = POP
;
1765 #ifdef BYTE_CODE_SAFE
1770 if ((op
-= Bconstant
) >= const_length
)
1776 PUSH (vectorp
[op
- Bconstant
]);
1783 byte_stack_list
= byte_stack_list
->next
;
1785 /* Binds and unbinds are supposed to be compiled balanced. */
1786 if (SPECPDL_INDEX () != count
)
1787 #ifdef BYTE_CODE_SAFE
1788 error ("binding stack not balanced (serious byte compiler bug)");
1799 Qbytecode
= intern_c_string ("byte-code");
1800 staticpro (&Qbytecode
);
1802 defsubr (&Sbyte_code
);
1804 #ifdef BYTE_CODE_METER
1806 DEFVAR_LISP ("byte-code-meter", &Vbyte_code_meter
,
1807 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
1808 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1809 opcode CODE has been executed.
1810 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1811 indicates how many times the byte opcodes CODE1 and CODE2 have been
1812 executed in succession. */);
1814 DEFVAR_BOOL ("byte-metering-on", &byte_metering_on
,
1815 doc
: /* If non-nil, keep profiling information on byte code usage.
1816 The variable byte-code-meter indicates how often each byte opcode is used.
1817 If a symbol has a property named `byte-code-meter' whose value is an
1818 integer, it is incremented each time that symbol's function is called. */);
1820 byte_metering_on
= 0;
1821 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
1822 Qbyte_code_meter
= intern_c_string ("byte-code-meter");
1823 staticpro (&Qbyte_code_meter
);
1827 XVECTOR (Vbyte_code_meter
)->contents
[i
] =
1828 Fmake_vector (make_number (256), make_number (0));
1833 /* arch-tag: b9803b6f-1ed6-4190-8adf-33fd3a9d10e9
1834 (do not change this comment) */