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. */
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 #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) */)
421 (int nargs
, Lisp_Object
*args
)
423 Lisp_Object args_tmpl
= nargs
>= 4 ? args
[3] : Qnil
;
424 int pnargs
= nargs
>= 4 ? nargs
- 4 : 0;
425 Lisp_Object
*pargs
= nargs
>= 4 ? args
+ 4 : 0;
426 return exec_byte_code (args
[0], args
[1], args
[2], args_tmpl
, pnargs
, pargs
);
429 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
430 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
431 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
432 argument list (including &rest, &optional, etc.), and ARGS, of size
433 NARGS, should be a vector of the actual arguments. The arguments in
434 ARGS are pushed on the stack according to ARGS_TEMPLATE before
435 executing BYTESTR. */
438 exec_byte_code (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
,
439 Lisp_Object args_template
, int nargs
, Lisp_Object
*args
)
441 int count
= SPECPDL_INDEX ();
442 #ifdef BYTE_CODE_METER
447 /* Lisp_Object v1, v2; */
448 Lisp_Object
*vectorp
;
449 #ifdef BYTE_CODE_SAFE
450 int const_length
= XVECTOR (vector
)->size
;
454 struct byte_stack stack
;
458 #if 0 /* CHECK_FRAME_FONT */
460 struct frame
*f
= SELECTED_FRAME ();
462 && FRAME_FONT (f
)->direction
!= 0
463 && FRAME_FONT (f
)->direction
!= 1)
468 CHECK_STRING (bytestr
);
469 CHECK_VECTOR (vector
);
470 CHECK_NUMBER (maxdepth
);
472 if (STRING_MULTIBYTE (bytestr
))
473 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
474 because they produced a raw 8-bit string for byte-code and now
475 such a byte-code string is loaded as multibyte while raw 8-bit
476 characters converted to multibyte form. Thus, now we must
477 convert them back to the originally intended unibyte form. */
478 bytestr
= Fstring_as_unibyte (bytestr
);
480 bytestr_length
= SBYTES (bytestr
);
481 vectorp
= XVECTOR (vector
)->contents
;
483 stack
.byte_string
= bytestr
;
484 stack
.pc
= stack
.byte_string_start
= SDATA (bytestr
);
485 stack
.constants
= vector
;
486 stack
.bottom
= (Lisp_Object
*) alloca (XFASTINT (maxdepth
)
487 * sizeof (Lisp_Object
));
488 top
= stack
.bottom
- 1;
490 stack
.next
= byte_stack_list
;
491 byte_stack_list
= &stack
;
493 #ifdef BYTE_CODE_SAFE
494 stacke
= stack
.bottom
- 1 + XFASTINT (maxdepth
);
497 if (! NILP (args_template
))
498 /* We should push some arguments on the stack. */
501 int pushed
= 0, optional
= 0;
503 for (at
= args_template
; CONSP (at
); at
= XCDR (at
))
504 if (EQ (XCAR (at
), Qand_optional
))
506 else if (EQ (XCAR (at
), Qand_rest
))
508 PUSH (Flist (nargs
, args
));
513 else if (pushed
< nargs
)
523 if (pushed
!= nargs
|| !NILP (at
))
524 Fsignal (Qwrong_number_of_arguments
,
525 Fcons (args_template
, Fcons (make_number (nargs
), Qnil
)));
530 #ifdef BYTE_CODE_SAFE
533 else if (top
< stack
.bottom
- 1)
537 #ifdef BYTE_CODE_METER
539 this_op
= op
= FETCH
;
540 METER_CODE (prev_op
, op
);
560 /* This seems to be the most frequently executed byte-code
561 among the Bvarref's, so avoid a goto here. */
571 if (XSYMBOL (v1
)->redirect
!= SYMBOL_PLAINVAL
572 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)),
575 BEFORE_POTENTIAL_GC ();
576 v2
= Fsymbol_value (v1
);
577 AFTER_POTENTIAL_GC ();
582 BEFORE_POTENTIAL_GC ();
583 v2
= Fsymbol_value (v1
);
584 AFTER_POTENTIAL_GC ();
600 stack
.pc
= stack
.byte_string_start
+ op
;
617 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
624 BEFORE_POTENTIAL_GC ();
626 TOP
= Fmemq (TOP
, v1
);
627 AFTER_POTENTIAL_GC ();
656 Lisp_Object sym
, val
;
661 /* Inline the most common case. */
663 && !EQ (val
, Qunbound
)
664 && !XSYMBOL (sym
)->redirect
665 && !SYMBOL_CONSTANT_P (sym
))
666 XSYMBOL (sym
)->val
.value
= val
;
669 BEFORE_POTENTIAL_GC ();
670 set_internal (sym
, val
, Qnil
, 0);
671 AFTER_POTENTIAL_GC ();
685 /* ------------------ */
703 /* Specbind can signal and thus GC. */
704 BEFORE_POTENTIAL_GC ();
705 specbind (vectorp
[op
], POP
);
706 AFTER_POTENTIAL_GC ();
726 BEFORE_POTENTIAL_GC ();
728 #ifdef BYTE_CODE_METER
729 if (byte_metering_on
&& SYMBOLP (TOP
))
734 v2
= Fget (v1
, Qbyte_code_meter
);
736 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
738 XSETINT (v2
, XINT (v2
) + 1);
739 Fput (v1
, Qbyte_code_meter
, v2
);
743 TOP
= Ffuncall (op
+ 1, &TOP
);
744 AFTER_POTENTIAL_GC ();
764 BEFORE_POTENTIAL_GC ();
765 unbind_to (SPECPDL_INDEX () - op
, Qnil
);
766 AFTER_POTENTIAL_GC ();
770 /* To unbind back to the beginning of this frame. Not used yet,
771 but will be needed for tail-recursion elimination. */
772 BEFORE_POTENTIAL_GC ();
773 unbind_to (count
, Qnil
);
774 AFTER_POTENTIAL_GC ();
780 op
= FETCH2
; /* pc = FETCH2 loses since FETCH2 contains pc++ */
782 stack
.pc
= stack
.byte_string_start
+ op
;
795 stack
.pc
= stack
.byte_string_start
+ op
;
800 case Bgotoifnilelsepop
:
807 stack
.pc
= stack
.byte_string_start
+ op
;
812 case Bgotoifnonnilelsepop
:
819 stack
.pc
= stack
.byte_string_start
+ op
;
827 stack
.pc
+= (int) *stack
.pc
- 127;
838 stack
.pc
+= (int) *stack
.pc
- 128;
852 stack
.pc
+= (int) *stack
.pc
- 128;
858 case BRgotoifnilelsepop
:
864 stack
.pc
+= op
- 128;
869 case BRgotoifnonnilelsepop
:
875 stack
.pc
+= op
- 128;
889 PUSH (vectorp
[FETCH2
]);
892 case Bsave_excursion
:
893 record_unwind_protect (save_excursion_restore
,
894 save_excursion_save ());
897 case Bsave_current_buffer
:
898 case Bsave_current_buffer_1
:
899 record_unwind_protect (set_buffer_if_live
, Fcurrent_buffer ());
902 case Bsave_window_excursion
:
903 BEFORE_POTENTIAL_GC ();
904 TOP
= Fsave_window_excursion (TOP
);
905 AFTER_POTENTIAL_GC ();
908 case Bsave_restriction
:
909 record_unwind_protect (save_restriction_restore
,
910 save_restriction_save ());
916 BEFORE_POTENTIAL_GC ();
918 TOP
= internal_catch (TOP
, Feval
, v1
);
919 AFTER_POTENTIAL_GC ();
923 case Bunwind_protect
:
924 record_unwind_protect (Fprogn
, POP
);
927 case Bcondition_case
:
929 Lisp_Object handlers
, body
;
932 BEFORE_POTENTIAL_GC ();
933 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
);
934 AFTER_POTENTIAL_GC ();
938 case Btemp_output_buffer_setup
:
939 BEFORE_POTENTIAL_GC ();
941 temp_output_buffer_setup (SDATA (TOP
));
942 AFTER_POTENTIAL_GC ();
943 TOP
= Vstandard_output
;
946 case Btemp_output_buffer_show
:
949 BEFORE_POTENTIAL_GC ();
951 temp_output_buffer_show (TOP
);
953 /* pop binding of standard-output */
954 unbind_to (SPECPDL_INDEX () - 1, Qnil
);
955 AFTER_POTENTIAL_GC ();
962 BEFORE_POTENTIAL_GC ();
966 AFTER_POTENTIAL_GC ();
969 while (--op
>= 0 && CONSP (v1
))
977 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
981 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
985 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
989 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
993 TOP
= NILP (TOP
) ? Qt
: Qnil
;
1000 TOP
= Fcons (TOP
, v1
);
1005 TOP
= Fcons (TOP
, Qnil
);
1012 TOP
= Fcons (TOP
, Fcons (v1
, Qnil
));
1018 TOP
= Flist (3, &TOP
);
1023 TOP
= Flist (4, &TOP
);
1029 TOP
= Flist (op
, &TOP
);
1033 BEFORE_POTENTIAL_GC ();
1034 TOP
= Flength (TOP
);
1035 AFTER_POTENTIAL_GC ();
1041 BEFORE_POTENTIAL_GC ();
1043 TOP
= Faref (TOP
, v1
);
1044 AFTER_POTENTIAL_GC ();
1051 BEFORE_POTENTIAL_GC ();
1053 TOP
= Faset (TOP
, v1
, v2
);
1054 AFTER_POTENTIAL_GC ();
1059 BEFORE_POTENTIAL_GC ();
1060 TOP
= Fsymbol_value (TOP
);
1061 AFTER_POTENTIAL_GC ();
1064 case Bsymbol_function
:
1065 BEFORE_POTENTIAL_GC ();
1066 TOP
= Fsymbol_function (TOP
);
1067 AFTER_POTENTIAL_GC ();
1073 BEFORE_POTENTIAL_GC ();
1075 TOP
= Fset (TOP
, v1
);
1076 AFTER_POTENTIAL_GC ();
1083 BEFORE_POTENTIAL_GC ();
1085 TOP
= Ffset (TOP
, v1
);
1086 AFTER_POTENTIAL_GC ();
1093 BEFORE_POTENTIAL_GC ();
1095 TOP
= Fget (TOP
, v1
);
1096 AFTER_POTENTIAL_GC ();
1103 BEFORE_POTENTIAL_GC ();
1105 TOP
= Fsubstring (TOP
, v1
, v2
);
1106 AFTER_POTENTIAL_GC ();
1111 BEFORE_POTENTIAL_GC ();
1113 TOP
= Fconcat (2, &TOP
);
1114 AFTER_POTENTIAL_GC ();
1118 BEFORE_POTENTIAL_GC ();
1120 TOP
= Fconcat (3, &TOP
);
1121 AFTER_POTENTIAL_GC ();
1125 BEFORE_POTENTIAL_GC ();
1127 TOP
= Fconcat (4, &TOP
);
1128 AFTER_POTENTIAL_GC ();
1133 BEFORE_POTENTIAL_GC ();
1135 TOP
= Fconcat (op
, &TOP
);
1136 AFTER_POTENTIAL_GC ();
1145 XSETINT (v1
, XINT (v1
) - 1);
1150 BEFORE_POTENTIAL_GC ();
1152 AFTER_POTENTIAL_GC ();
1163 XSETINT (v1
, XINT (v1
) + 1);
1168 BEFORE_POTENTIAL_GC ();
1170 AFTER_POTENTIAL_GC ();
1178 BEFORE_POTENTIAL_GC ();
1180 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
1181 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
1182 AFTER_POTENTIAL_GC ();
1183 if (FLOATP (v1
) || FLOATP (v2
))
1187 f1
= (FLOATP (v1
) ? XFLOAT_DATA (v1
) : XINT (v1
));
1188 f2
= (FLOATP (v2
) ? XFLOAT_DATA (v2
) : XINT (v2
));
1189 TOP
= (f1
== f2
? Qt
: Qnil
);
1192 TOP
= (XINT (v1
) == XINT (v2
) ? Qt
: Qnil
);
1199 BEFORE_POTENTIAL_GC ();
1201 TOP
= Fgtr (TOP
, v1
);
1202 AFTER_POTENTIAL_GC ();
1209 BEFORE_POTENTIAL_GC ();
1211 TOP
= Flss (TOP
, v1
);
1212 AFTER_POTENTIAL_GC ();
1219 BEFORE_POTENTIAL_GC ();
1221 TOP
= Fleq (TOP
, v1
);
1222 AFTER_POTENTIAL_GC ();
1229 BEFORE_POTENTIAL_GC ();
1231 TOP
= Fgeq (TOP
, v1
);
1232 AFTER_POTENTIAL_GC ();
1237 BEFORE_POTENTIAL_GC ();
1239 TOP
= Fminus (2, &TOP
);
1240 AFTER_POTENTIAL_GC ();
1249 XSETINT (v1
, - XINT (v1
));
1254 BEFORE_POTENTIAL_GC ();
1255 TOP
= Fminus (1, &TOP
);
1256 AFTER_POTENTIAL_GC ();
1262 BEFORE_POTENTIAL_GC ();
1264 TOP
= Fplus (2, &TOP
);
1265 AFTER_POTENTIAL_GC ();
1269 BEFORE_POTENTIAL_GC ();
1271 TOP
= Fmax (2, &TOP
);
1272 AFTER_POTENTIAL_GC ();
1276 BEFORE_POTENTIAL_GC ();
1278 TOP
= Fmin (2, &TOP
);
1279 AFTER_POTENTIAL_GC ();
1283 BEFORE_POTENTIAL_GC ();
1285 TOP
= Ftimes (2, &TOP
);
1286 AFTER_POTENTIAL_GC ();
1290 BEFORE_POTENTIAL_GC ();
1292 TOP
= Fquo (2, &TOP
);
1293 AFTER_POTENTIAL_GC ();
1299 BEFORE_POTENTIAL_GC ();
1301 TOP
= Frem (TOP
, v1
);
1302 AFTER_POTENTIAL_GC ();
1309 XSETFASTINT (v1
, PT
);
1315 BEFORE_POTENTIAL_GC ();
1316 TOP
= Fgoto_char (TOP
);
1317 AFTER_POTENTIAL_GC ();
1321 BEFORE_POTENTIAL_GC ();
1322 TOP
= Finsert (1, &TOP
);
1323 AFTER_POTENTIAL_GC ();
1328 BEFORE_POTENTIAL_GC ();
1330 TOP
= Finsert (op
, &TOP
);
1331 AFTER_POTENTIAL_GC ();
1337 XSETFASTINT (v1
, ZV
);
1345 XSETFASTINT (v1
, BEGV
);
1351 BEFORE_POTENTIAL_GC ();
1352 TOP
= Fchar_after (TOP
);
1353 AFTER_POTENTIAL_GC ();
1356 case Bfollowing_char
:
1359 BEFORE_POTENTIAL_GC ();
1360 v1
= Ffollowing_char ();
1361 AFTER_POTENTIAL_GC ();
1366 case Bpreceding_char
:
1369 BEFORE_POTENTIAL_GC ();
1370 v1
= Fprevious_char ();
1371 AFTER_POTENTIAL_GC ();
1376 case Bcurrent_column
:
1379 BEFORE_POTENTIAL_GC ();
1380 XSETFASTINT (v1
, (int) current_column ()); /* iftc */
1381 AFTER_POTENTIAL_GC ();
1387 BEFORE_POTENTIAL_GC ();
1388 TOP
= Findent_to (TOP
, Qnil
);
1389 AFTER_POTENTIAL_GC ();
1408 case Bcurrent_buffer
:
1409 PUSH (Fcurrent_buffer ());
1413 BEFORE_POTENTIAL_GC ();
1414 TOP
= Fset_buffer (TOP
);
1415 AFTER_POTENTIAL_GC ();
1418 case Binteractive_p
:
1419 PUSH (Finteractive_p ());
1423 BEFORE_POTENTIAL_GC ();
1424 TOP
= Fforward_char (TOP
);
1425 AFTER_POTENTIAL_GC ();
1429 BEFORE_POTENTIAL_GC ();
1430 TOP
= Fforward_word (TOP
);
1431 AFTER_POTENTIAL_GC ();
1434 case Bskip_chars_forward
:
1437 BEFORE_POTENTIAL_GC ();
1439 TOP
= Fskip_chars_forward (TOP
, v1
);
1440 AFTER_POTENTIAL_GC ();
1444 case Bskip_chars_backward
:
1447 BEFORE_POTENTIAL_GC ();
1449 TOP
= Fskip_chars_backward (TOP
, v1
);
1450 AFTER_POTENTIAL_GC ();
1455 BEFORE_POTENTIAL_GC ();
1456 TOP
= Fforward_line (TOP
);
1457 AFTER_POTENTIAL_GC ();
1464 BEFORE_POTENTIAL_GC ();
1465 CHECK_CHARACTER (TOP
);
1466 AFTER_POTENTIAL_GC ();
1468 if (NILP (current_buffer
->enable_multibyte_characters
))
1469 MAKE_CHAR_MULTIBYTE (c
);
1470 XSETFASTINT (TOP
, syntax_code_spec
[(int) SYNTAX (c
)]);
1474 case Bbuffer_substring
:
1477 BEFORE_POTENTIAL_GC ();
1479 TOP
= Fbuffer_substring (TOP
, v1
);
1480 AFTER_POTENTIAL_GC ();
1484 case Bdelete_region
:
1487 BEFORE_POTENTIAL_GC ();
1489 TOP
= Fdelete_region (TOP
, v1
);
1490 AFTER_POTENTIAL_GC ();
1494 case Bnarrow_to_region
:
1497 BEFORE_POTENTIAL_GC ();
1499 TOP
= Fnarrow_to_region (TOP
, v1
);
1500 AFTER_POTENTIAL_GC ();
1505 BEFORE_POTENTIAL_GC ();
1507 AFTER_POTENTIAL_GC ();
1511 BEFORE_POTENTIAL_GC ();
1512 TOP
= Fend_of_line (TOP
);
1513 AFTER_POTENTIAL_GC ();
1519 BEFORE_POTENTIAL_GC ();
1522 TOP
= Fset_marker (TOP
, v2
, v1
);
1523 AFTER_POTENTIAL_GC ();
1527 case Bmatch_beginning
:
1528 BEFORE_POTENTIAL_GC ();
1529 TOP
= Fmatch_beginning (TOP
);
1530 AFTER_POTENTIAL_GC ();
1534 BEFORE_POTENTIAL_GC ();
1535 TOP
= Fmatch_end (TOP
);
1536 AFTER_POTENTIAL_GC ();
1540 BEFORE_POTENTIAL_GC ();
1541 TOP
= Fupcase (TOP
);
1542 AFTER_POTENTIAL_GC ();
1546 BEFORE_POTENTIAL_GC ();
1547 TOP
= Fdowncase (TOP
);
1548 AFTER_POTENTIAL_GC ();
1551 case Bstringeqlsign
:
1554 BEFORE_POTENTIAL_GC ();
1556 TOP
= Fstring_equal (TOP
, v1
);
1557 AFTER_POTENTIAL_GC ();
1564 BEFORE_POTENTIAL_GC ();
1566 TOP
= Fstring_lessp (TOP
, v1
);
1567 AFTER_POTENTIAL_GC ();
1575 TOP
= Fequal (TOP
, v1
);
1582 BEFORE_POTENTIAL_GC ();
1584 TOP
= Fnthcdr (TOP
, v1
);
1585 AFTER_POTENTIAL_GC ();
1594 /* Exchange args and then do nth. */
1595 BEFORE_POTENTIAL_GC ();
1599 AFTER_POTENTIAL_GC ();
1602 while (--op
>= 0 && CONSP (v1
))
1609 BEFORE_POTENTIAL_GC ();
1611 TOP
= Felt (TOP
, v1
);
1612 AFTER_POTENTIAL_GC ();
1620 BEFORE_POTENTIAL_GC ();
1622 TOP
= Fmember (TOP
, v1
);
1623 AFTER_POTENTIAL_GC ();
1630 BEFORE_POTENTIAL_GC ();
1632 TOP
= Fassq (TOP
, v1
);
1633 AFTER_POTENTIAL_GC ();
1638 BEFORE_POTENTIAL_GC ();
1639 TOP
= Fnreverse (TOP
);
1640 AFTER_POTENTIAL_GC ();
1646 BEFORE_POTENTIAL_GC ();
1648 TOP
= Fsetcar (TOP
, v1
);
1649 AFTER_POTENTIAL_GC ();
1656 BEFORE_POTENTIAL_GC ();
1658 TOP
= Fsetcdr (TOP
, v1
);
1659 AFTER_POTENTIAL_GC ();
1667 TOP
= CAR_SAFE (v1
);
1675 TOP
= CDR_SAFE (v1
);
1680 BEFORE_POTENTIAL_GC ();
1682 TOP
= Fnconc (2, &TOP
);
1683 AFTER_POTENTIAL_GC ();
1687 TOP
= (NUMBERP (TOP
) ? Qt
: Qnil
);
1691 TOP
= INTEGERP (TOP
) ? Qt
: Qnil
;
1694 #ifdef BYTE_CODE_SAFE
1696 BEFORE_POTENTIAL_GC ();
1697 error ("set-mark is an obsolete bytecode");
1698 AFTER_POTENTIAL_GC ();
1701 BEFORE_POTENTIAL_GC ();
1702 error ("scan-buffer is an obsolete bytecode");
1703 AFTER_POTENTIAL_GC ();
1707 /* Handy byte-codes for lexical binding. */
1714 PUSH (stack
.bottom
[op
- Bstack_ref
]);
1717 PUSH (stack
.bottom
[FETCH
]);
1720 PUSH (stack
.bottom
[FETCH2
]);
1723 stack
.bottom
[FETCH
] = POP
;
1726 stack
.bottom
[FETCH2
] = POP
;
1730 /* These byte-codes used mostly for variable references to
1731 lexically bound variables that are in an environment vector
1732 instead of on the byte-interpreter stack (generally those
1733 variables which might be shared with a closure). */
1736 Lisp_Object vec
= POP
;
1738 if (! VECTORP (vec
))
1739 wrong_type_argument (Qvectorp
, vec
);
1740 else if (index
< 0 || index
>= XVECTOR (vec
)->size
)
1741 args_out_of_range (vec
, make_number (index
));
1744 PUSH (XVECTOR (vec
)->contents
[index
]);
1746 XVECTOR (vec
)->contents
[index
] = POP
;
1761 #ifdef BYTE_CODE_SAFE
1766 if ((op
-= Bconstant
) >= const_length
)
1772 PUSH (vectorp
[op
- Bconstant
]);
1779 byte_stack_list
= byte_stack_list
->next
;
1781 /* Binds and unbinds are supposed to be compiled balanced. */
1782 if (SPECPDL_INDEX () != count
)
1783 #ifdef BYTE_CODE_SAFE
1784 error ("binding stack not balanced (serious byte compiler bug)");
1793 syms_of_bytecode (void)
1795 Qbytecode
= intern_c_string ("byte-code");
1796 staticpro (&Qbytecode
);
1798 defsubr (&Sbyte_code
);
1800 #ifdef BYTE_CODE_METER
1802 DEFVAR_LISP ("byte-code-meter", &Vbyte_code_meter
,
1803 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
1804 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1805 opcode CODE has been executed.
1806 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1807 indicates how many times the byte opcodes CODE1 and CODE2 have been
1808 executed in succession. */);
1810 DEFVAR_BOOL ("byte-metering-on", &byte_metering_on
,
1811 doc
: /* If non-nil, keep profiling information on byte code usage.
1812 The variable byte-code-meter indicates how often each byte opcode is used.
1813 If a symbol has a property named `byte-code-meter' whose value is an
1814 integer, it is incremented each time that symbol's function is called. */);
1816 byte_metering_on
= 0;
1817 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
1818 Qbyte_code_meter
= intern_c_string ("byte-code-meter");
1819 staticpro (&Qbyte_code_meter
);
1823 XVECTOR (Vbyte_code_meter
)->contents
[i
] =
1824 Fmake_vector (make_number (256), make_number (0));
1829 /* arch-tag: b9803b6f-1ed6-4190-8adf-33fd3a9d10e9
1830 (do not change this comment) */