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
;
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
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
))
504 ? Flist (nargs
- pushed
, args
)
510 else if (pushed
< nargs
)
520 if (pushed
!= nargs
|| !NILP (at
))
521 Fsignal (Qwrong_number_of_arguments
,
522 Fcons (args_template
, Fcons (make_number (nargs
), Qnil
)));
527 #ifdef BYTE_CODE_SAFE
530 else if (top
< stack
.bottom
- 1)
534 #ifdef BYTE_CODE_METER
536 this_op
= op
= FETCH
;
537 METER_CODE (prev_op
, op
);
557 /* This seems to be the most frequently executed byte-code
558 among the Bvarref's, so avoid a goto here. */
568 if (XSYMBOL (v1
)->redirect
!= SYMBOL_PLAINVAL
569 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)),
572 BEFORE_POTENTIAL_GC ();
573 v2
= Fsymbol_value (v1
);
574 AFTER_POTENTIAL_GC ();
579 BEFORE_POTENTIAL_GC ();
580 v2
= Fsymbol_value (v1
);
581 AFTER_POTENTIAL_GC ();
597 stack
.pc
= stack
.byte_string_start
+ op
;
614 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
621 BEFORE_POTENTIAL_GC ();
623 TOP
= Fmemq (TOP
, v1
);
624 AFTER_POTENTIAL_GC ();
653 Lisp_Object sym
, val
;
658 /* Inline the most common case. */
660 && !EQ (val
, Qunbound
)
661 && !XSYMBOL (sym
)->redirect
662 && !SYMBOL_CONSTANT_P (sym
))
663 XSYMBOL (sym
)->val
.value
= val
;
666 BEFORE_POTENTIAL_GC ();
667 set_internal (sym
, val
, Qnil
, 0);
668 AFTER_POTENTIAL_GC ();
682 /* ------------------ */
700 /* Specbind can signal and thus GC. */
701 BEFORE_POTENTIAL_GC ();
702 specbind (vectorp
[op
], POP
);
703 AFTER_POTENTIAL_GC ();
723 BEFORE_POTENTIAL_GC ();
725 #ifdef BYTE_CODE_METER
726 if (byte_metering_on
&& SYMBOLP (TOP
))
731 v2
= Fget (v1
, Qbyte_code_meter
);
733 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
735 XSETINT (v2
, XINT (v2
) + 1);
736 Fput (v1
, Qbyte_code_meter
, v2
);
740 TOP
= Ffuncall (op
+ 1, &TOP
);
741 AFTER_POTENTIAL_GC ();
761 BEFORE_POTENTIAL_GC ();
762 unbind_to (SPECPDL_INDEX () - op
, Qnil
);
763 AFTER_POTENTIAL_GC ();
766 case Bunbind_all
: /* Obsolete. */
767 /* To unbind back to the beginning of this frame. Not used yet,
768 but will be needed for tail-recursion elimination. */
769 BEFORE_POTENTIAL_GC ();
770 unbind_to (count
, Qnil
);
771 AFTER_POTENTIAL_GC ();
777 op
= FETCH2
; /* pc = FETCH2 loses since FETCH2 contains pc++ */
779 stack
.pc
= stack
.byte_string_start
+ op
;
792 stack
.pc
= stack
.byte_string_start
+ op
;
797 case Bgotoifnilelsepop
:
804 stack
.pc
= stack
.byte_string_start
+ op
;
809 case Bgotoifnonnilelsepop
:
816 stack
.pc
= stack
.byte_string_start
+ op
;
824 stack
.pc
+= (int) *stack
.pc
- 127;
835 stack
.pc
+= (int) *stack
.pc
- 128;
849 stack
.pc
+= (int) *stack
.pc
- 128;
855 case BRgotoifnilelsepop
:
861 stack
.pc
+= op
- 128;
866 case BRgotoifnonnilelsepop
:
872 stack
.pc
+= op
- 128;
886 PUSH (vectorp
[FETCH2
]);
889 case Bsave_excursion
:
890 record_unwind_protect (save_excursion_restore
,
891 save_excursion_save ());
894 case Bsave_current_buffer
: /* Obsolete. */
895 case Bsave_current_buffer_1
:
896 record_unwind_protect (set_buffer_if_live
, Fcurrent_buffer ());
899 case Bsave_window_excursion
: /* Obsolete. */
901 register int count
= SPECPDL_INDEX ();
902 record_unwind_protect (Fset_window_configuration
,
903 Fcurrent_window_configuration (Qnil
));
904 BEFORE_POTENTIAL_GC ();
906 unbind_to (count
, TOP
);
907 AFTER_POTENTIAL_GC ();
911 case Bsave_restriction
:
912 record_unwind_protect (save_restriction_restore
,
913 save_restriction_save ());
919 BEFORE_POTENTIAL_GC ();
921 TOP
= internal_catch (TOP
, eval_sub
, v1
); /* FIXME: lexbind */
922 AFTER_POTENTIAL_GC ();
926 case Bunwind_protect
:
927 record_unwind_protect (Fprogn
, POP
); /* FIXME: lexbind */
930 case Bcondition_case
:
932 Lisp_Object handlers
, body
;
935 BEFORE_POTENTIAL_GC ();
936 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
); /* FIXME: lexbind */
937 AFTER_POTENTIAL_GC ();
941 case Btemp_output_buffer_setup
: /* Obsolete. */
942 BEFORE_POTENTIAL_GC ();
944 temp_output_buffer_setup (SSDATA (TOP
));
945 AFTER_POTENTIAL_GC ();
946 TOP
= Vstandard_output
;
949 case Btemp_output_buffer_show
: /* Obsolete. */
952 BEFORE_POTENTIAL_GC ();
954 temp_output_buffer_show (TOP
);
956 /* pop binding of standard-output */
957 unbind_to (SPECPDL_INDEX () - 1, Qnil
);
958 AFTER_POTENTIAL_GC ();
965 BEFORE_POTENTIAL_GC ();
969 AFTER_POTENTIAL_GC ();
972 while (--op
>= 0 && CONSP (v1
))
980 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
984 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
988 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
992 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
996 TOP
= NILP (TOP
) ? Qt
: Qnil
;
1003 TOP
= Fcons (TOP
, v1
);
1008 TOP
= Fcons (TOP
, Qnil
);
1015 TOP
= Fcons (TOP
, Fcons (v1
, Qnil
));
1021 TOP
= Flist (3, &TOP
);
1026 TOP
= Flist (4, &TOP
);
1032 TOP
= Flist (op
, &TOP
);
1036 BEFORE_POTENTIAL_GC ();
1037 TOP
= Flength (TOP
);
1038 AFTER_POTENTIAL_GC ();
1044 BEFORE_POTENTIAL_GC ();
1046 TOP
= Faref (TOP
, v1
);
1047 AFTER_POTENTIAL_GC ();
1054 BEFORE_POTENTIAL_GC ();
1056 TOP
= Faset (TOP
, v1
, v2
);
1057 AFTER_POTENTIAL_GC ();
1062 BEFORE_POTENTIAL_GC ();
1063 TOP
= Fsymbol_value (TOP
);
1064 AFTER_POTENTIAL_GC ();
1067 case Bsymbol_function
:
1068 BEFORE_POTENTIAL_GC ();
1069 TOP
= Fsymbol_function (TOP
);
1070 AFTER_POTENTIAL_GC ();
1076 BEFORE_POTENTIAL_GC ();
1078 TOP
= Fset (TOP
, v1
);
1079 AFTER_POTENTIAL_GC ();
1086 BEFORE_POTENTIAL_GC ();
1088 TOP
= Ffset (TOP
, v1
);
1089 AFTER_POTENTIAL_GC ();
1096 BEFORE_POTENTIAL_GC ();
1098 TOP
= Fget (TOP
, v1
);
1099 AFTER_POTENTIAL_GC ();
1106 BEFORE_POTENTIAL_GC ();
1108 TOP
= Fsubstring (TOP
, v1
, v2
);
1109 AFTER_POTENTIAL_GC ();
1114 BEFORE_POTENTIAL_GC ();
1116 TOP
= Fconcat (2, &TOP
);
1117 AFTER_POTENTIAL_GC ();
1121 BEFORE_POTENTIAL_GC ();
1123 TOP
= Fconcat (3, &TOP
);
1124 AFTER_POTENTIAL_GC ();
1128 BEFORE_POTENTIAL_GC ();
1130 TOP
= Fconcat (4, &TOP
);
1131 AFTER_POTENTIAL_GC ();
1136 BEFORE_POTENTIAL_GC ();
1138 TOP
= Fconcat (op
, &TOP
);
1139 AFTER_POTENTIAL_GC ();
1148 XSETINT (v1
, XINT (v1
) - 1);
1153 BEFORE_POTENTIAL_GC ();
1155 AFTER_POTENTIAL_GC ();
1166 XSETINT (v1
, XINT (v1
) + 1);
1171 BEFORE_POTENTIAL_GC ();
1173 AFTER_POTENTIAL_GC ();
1181 BEFORE_POTENTIAL_GC ();
1183 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
1184 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
1185 AFTER_POTENTIAL_GC ();
1186 if (FLOATP (v1
) || FLOATP (v2
))
1190 f1
= (FLOATP (v1
) ? XFLOAT_DATA (v1
) : XINT (v1
));
1191 f2
= (FLOATP (v2
) ? XFLOAT_DATA (v2
) : XINT (v2
));
1192 TOP
= (f1
== f2
? Qt
: Qnil
);
1195 TOP
= (XINT (v1
) == XINT (v2
) ? Qt
: Qnil
);
1202 BEFORE_POTENTIAL_GC ();
1204 TOP
= Fgtr (TOP
, v1
);
1205 AFTER_POTENTIAL_GC ();
1212 BEFORE_POTENTIAL_GC ();
1214 TOP
= Flss (TOP
, v1
);
1215 AFTER_POTENTIAL_GC ();
1222 BEFORE_POTENTIAL_GC ();
1224 TOP
= Fleq (TOP
, v1
);
1225 AFTER_POTENTIAL_GC ();
1232 BEFORE_POTENTIAL_GC ();
1234 TOP
= Fgeq (TOP
, v1
);
1235 AFTER_POTENTIAL_GC ();
1240 BEFORE_POTENTIAL_GC ();
1242 TOP
= Fminus (2, &TOP
);
1243 AFTER_POTENTIAL_GC ();
1252 XSETINT (v1
, - XINT (v1
));
1257 BEFORE_POTENTIAL_GC ();
1258 TOP
= Fminus (1, &TOP
);
1259 AFTER_POTENTIAL_GC ();
1265 BEFORE_POTENTIAL_GC ();
1267 TOP
= Fplus (2, &TOP
);
1268 AFTER_POTENTIAL_GC ();
1272 BEFORE_POTENTIAL_GC ();
1274 TOP
= Fmax (2, &TOP
);
1275 AFTER_POTENTIAL_GC ();
1279 BEFORE_POTENTIAL_GC ();
1281 TOP
= Fmin (2, &TOP
);
1282 AFTER_POTENTIAL_GC ();
1286 BEFORE_POTENTIAL_GC ();
1288 TOP
= Ftimes (2, &TOP
);
1289 AFTER_POTENTIAL_GC ();
1293 BEFORE_POTENTIAL_GC ();
1295 TOP
= Fquo (2, &TOP
);
1296 AFTER_POTENTIAL_GC ();
1302 BEFORE_POTENTIAL_GC ();
1304 TOP
= Frem (TOP
, v1
);
1305 AFTER_POTENTIAL_GC ();
1312 XSETFASTINT (v1
, PT
);
1318 BEFORE_POTENTIAL_GC ();
1319 TOP
= Fgoto_char (TOP
);
1320 AFTER_POTENTIAL_GC ();
1324 BEFORE_POTENTIAL_GC ();
1325 TOP
= Finsert (1, &TOP
);
1326 AFTER_POTENTIAL_GC ();
1331 BEFORE_POTENTIAL_GC ();
1333 TOP
= Finsert (op
, &TOP
);
1334 AFTER_POTENTIAL_GC ();
1340 XSETFASTINT (v1
, ZV
);
1348 XSETFASTINT (v1
, BEGV
);
1354 BEFORE_POTENTIAL_GC ();
1355 TOP
= Fchar_after (TOP
);
1356 AFTER_POTENTIAL_GC ();
1359 case Bfollowing_char
:
1362 BEFORE_POTENTIAL_GC ();
1363 v1
= Ffollowing_char ();
1364 AFTER_POTENTIAL_GC ();
1369 case Bpreceding_char
:
1372 BEFORE_POTENTIAL_GC ();
1373 v1
= Fprevious_char ();
1374 AFTER_POTENTIAL_GC ();
1379 case Bcurrent_column
:
1382 BEFORE_POTENTIAL_GC ();
1383 XSETFASTINT (v1
, (int) current_column ()); /* iftc */
1384 AFTER_POTENTIAL_GC ();
1390 BEFORE_POTENTIAL_GC ();
1391 TOP
= Findent_to (TOP
, Qnil
);
1392 AFTER_POTENTIAL_GC ();
1411 case Bcurrent_buffer
:
1412 PUSH (Fcurrent_buffer ());
1416 BEFORE_POTENTIAL_GC ();
1417 TOP
= Fset_buffer (TOP
);
1418 AFTER_POTENTIAL_GC ();
1421 case Binteractive_p
: /* Obsolete. */
1422 PUSH (Finteractive_p ());
1426 BEFORE_POTENTIAL_GC ();
1427 TOP
= Fforward_char (TOP
);
1428 AFTER_POTENTIAL_GC ();
1432 BEFORE_POTENTIAL_GC ();
1433 TOP
= Fforward_word (TOP
);
1434 AFTER_POTENTIAL_GC ();
1437 case Bskip_chars_forward
:
1440 BEFORE_POTENTIAL_GC ();
1442 TOP
= Fskip_chars_forward (TOP
, v1
);
1443 AFTER_POTENTIAL_GC ();
1447 case Bskip_chars_backward
:
1450 BEFORE_POTENTIAL_GC ();
1452 TOP
= Fskip_chars_backward (TOP
, v1
);
1453 AFTER_POTENTIAL_GC ();
1458 BEFORE_POTENTIAL_GC ();
1459 TOP
= Fforward_line (TOP
);
1460 AFTER_POTENTIAL_GC ();
1467 BEFORE_POTENTIAL_GC ();
1468 CHECK_CHARACTER (TOP
);
1469 AFTER_POTENTIAL_GC ();
1471 if (NILP (current_buffer
->enable_multibyte_characters
))
1472 MAKE_CHAR_MULTIBYTE (c
);
1473 XSETFASTINT (TOP
, syntax_code_spec
[(int) SYNTAX (c
)]);
1477 case Bbuffer_substring
:
1480 BEFORE_POTENTIAL_GC ();
1482 TOP
= Fbuffer_substring (TOP
, v1
);
1483 AFTER_POTENTIAL_GC ();
1487 case Bdelete_region
:
1490 BEFORE_POTENTIAL_GC ();
1492 TOP
= Fdelete_region (TOP
, v1
);
1493 AFTER_POTENTIAL_GC ();
1497 case Bnarrow_to_region
:
1500 BEFORE_POTENTIAL_GC ();
1502 TOP
= Fnarrow_to_region (TOP
, v1
);
1503 AFTER_POTENTIAL_GC ();
1508 BEFORE_POTENTIAL_GC ();
1510 AFTER_POTENTIAL_GC ();
1514 BEFORE_POTENTIAL_GC ();
1515 TOP
= Fend_of_line (TOP
);
1516 AFTER_POTENTIAL_GC ();
1522 BEFORE_POTENTIAL_GC ();
1525 TOP
= Fset_marker (TOP
, v2
, v1
);
1526 AFTER_POTENTIAL_GC ();
1530 case Bmatch_beginning
:
1531 BEFORE_POTENTIAL_GC ();
1532 TOP
= Fmatch_beginning (TOP
);
1533 AFTER_POTENTIAL_GC ();
1537 BEFORE_POTENTIAL_GC ();
1538 TOP
= Fmatch_end (TOP
);
1539 AFTER_POTENTIAL_GC ();
1543 BEFORE_POTENTIAL_GC ();
1544 TOP
= Fupcase (TOP
);
1545 AFTER_POTENTIAL_GC ();
1549 BEFORE_POTENTIAL_GC ();
1550 TOP
= Fdowncase (TOP
);
1551 AFTER_POTENTIAL_GC ();
1554 case Bstringeqlsign
:
1557 BEFORE_POTENTIAL_GC ();
1559 TOP
= Fstring_equal (TOP
, v1
);
1560 AFTER_POTENTIAL_GC ();
1567 BEFORE_POTENTIAL_GC ();
1569 TOP
= Fstring_lessp (TOP
, v1
);
1570 AFTER_POTENTIAL_GC ();
1578 TOP
= Fequal (TOP
, v1
);
1585 BEFORE_POTENTIAL_GC ();
1587 TOP
= Fnthcdr (TOP
, v1
);
1588 AFTER_POTENTIAL_GC ();
1597 /* Exchange args and then do nth. */
1598 BEFORE_POTENTIAL_GC ();
1602 AFTER_POTENTIAL_GC ();
1605 while (--op
>= 0 && CONSP (v1
))
1612 BEFORE_POTENTIAL_GC ();
1614 TOP
= Felt (TOP
, v1
);
1615 AFTER_POTENTIAL_GC ();
1623 BEFORE_POTENTIAL_GC ();
1625 TOP
= Fmember (TOP
, v1
);
1626 AFTER_POTENTIAL_GC ();
1633 BEFORE_POTENTIAL_GC ();
1635 TOP
= Fassq (TOP
, v1
);
1636 AFTER_POTENTIAL_GC ();
1641 BEFORE_POTENTIAL_GC ();
1642 TOP
= Fnreverse (TOP
);
1643 AFTER_POTENTIAL_GC ();
1649 BEFORE_POTENTIAL_GC ();
1651 TOP
= Fsetcar (TOP
, v1
);
1652 AFTER_POTENTIAL_GC ();
1659 BEFORE_POTENTIAL_GC ();
1661 TOP
= Fsetcdr (TOP
, v1
);
1662 AFTER_POTENTIAL_GC ();
1670 TOP
= CAR_SAFE (v1
);
1678 TOP
= CDR_SAFE (v1
);
1683 BEFORE_POTENTIAL_GC ();
1685 TOP
= Fnconc (2, &TOP
);
1686 AFTER_POTENTIAL_GC ();
1690 TOP
= (NUMBERP (TOP
) ? Qt
: Qnil
);
1694 TOP
= INTEGERP (TOP
) ? Qt
: Qnil
;
1697 #ifdef BYTE_CODE_SAFE
1699 BEFORE_POTENTIAL_GC ();
1700 error ("set-mark is an obsolete bytecode");
1701 AFTER_POTENTIAL_GC ();
1704 BEFORE_POTENTIAL_GC ();
1705 error ("scan-buffer is an obsolete bytecode");
1706 AFTER_POTENTIAL_GC ();
1710 /* Handy byte-codes for lexical binding. */
1711 /* case Bstack_ref: */ /* Use `dup' instead. */
1718 Lisp_Object
*ptr
= top
- (op
- Bstack_ref
);
1724 Lisp_Object
*ptr
= top
- (FETCH
);
1730 Lisp_Object
*ptr
= top
- (FETCH2
);
1734 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1737 Lisp_Object
*ptr
= top
- (FETCH
);
1743 Lisp_Object
*ptr
= top
- (FETCH2
);
1759 #ifdef BYTE_CODE_SAFE
1764 if ((op
-= Bconstant
) >= const_length
)
1770 PUSH (vectorp
[op
- Bconstant
]);
1777 byte_stack_list
= byte_stack_list
->next
;
1779 /* Binds and unbinds are supposed to be compiled balanced. */
1780 if (SPECPDL_INDEX () != count
)
1781 #ifdef BYTE_CODE_SAFE
1782 error ("binding stack not balanced (serious byte compiler bug)");
1791 syms_of_bytecode (void)
1793 Qbytecode
= intern_c_string ("byte-code");
1794 staticpro (&Qbytecode
);
1796 defsubr (&Sbyte_code
);
1798 #ifdef BYTE_CODE_METER
1800 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter
,
1801 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
1802 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1803 opcode CODE has been executed.
1804 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1805 indicates how many times the byte opcodes CODE1 and CODE2 have been
1806 executed in succession. */);
1808 DEFVAR_BOOL ("byte-metering-on", byte_metering_on
,
1809 doc
: /* If non-nil, keep profiling information on byte code usage.
1810 The variable byte-code-meter indicates how often each byte opcode is used.
1811 If a symbol has a property named `byte-code-meter' whose value is an
1812 integer, it is incremented each time that symbol's function is called. */);
1814 byte_metering_on
= 0;
1815 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
1816 Qbyte_code_meter
= intern_c_string ("byte-code-meter");
1817 staticpro (&Qbyte_code_meter
);
1821 XVECTOR (Vbyte_code_meter
)->contents
[i
] =
1822 Fmake_vector (make_number (256), make_number (0));