1 /* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985-1988, 1993, 2000-2011 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 hacked on by jwz@lucid.com 17-jun-91
21 o added a compile-time switch to turn on simple sanity checking;
22 o put back the obsolete byte-codes for error-detection;
23 o added a new instruction, unbind_all, which I will use for
24 tail-recursion elimination;
25 o made temp_output_buffer_show be called with the right number
27 o made the new bytecodes be called with args in the right order;
28 o added metering support.
31 o added relative jump instructions;
32 o all conditionals now only do QUIT if they jump.
39 #include "character.h"
43 #ifdef CHECK_FRAME_FONT
49 * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for
50 * debugging the byte compiler...)
52 * define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
54 #define BYTE_CODE_SAFE 1
55 /* #define BYTE_CODE_METER */
58 #ifdef BYTE_CODE_METER
60 Lisp_Object Qbyte_code_meter
;
61 #define METER_2(code1, code2) \
62 XFASTINT (XVECTOR (XVECTOR (Vbyte_code_meter)->contents[(code1)]) \
65 #define METER_1(code) METER_2 (0, (code))
67 #define METER_CODE(last_code, this_code) \
69 if (byte_metering_on) \
71 if (METER_1 (this_code) < MOST_POSITIVE_FIXNUM) \
72 METER_1 (this_code)++; \
74 && METER_2 (last_code, this_code) < MOST_POSITIVE_FIXNUM) \
75 METER_2 (last_code, this_code)++; \
79 #endif /* BYTE_CODE_METER */
82 Lisp_Object Qbytecode
;
83 extern Lisp_Object Qand_optional
, Qand_rest
;
87 #define Bstack_ref 0 /* Actually, Bstack_ref+0 is not implemented: use dup. */
112 #define Bsymbol_value 0112
113 #define Bsymbol_function 0113
117 #define Bsubstring 0117
118 #define Bconcat2 0120
119 #define Bconcat3 0121
120 #define Bconcat4 0122
123 #define Beqlsign 0125
136 /* Was Bmark in v17. */
137 #define Bsave_current_buffer 0141 /* Obsolete. */
138 #define Bgoto_char 0142
140 #define Bpoint_max 0144
141 #define Bpoint_min 0145
142 #define Bchar_after 0146
143 #define Bfollowing_char 0147
144 #define Bpreceding_char 0150
145 #define Bcurrent_column 0151
146 #define Bindent_to 0152
147 #ifdef BYTE_CODE_SAFE
148 #define Bscan_buffer 0153 /* No longer generated as of v18 */
154 #define Bcurrent_buffer 0160
155 #define Bset_buffer 0161
156 #define Bsave_current_buffer_1 0162 /* Replacing Bsave_current_buffer. */
158 #define Bread_char 0162 /* No longer generated as of v19 */
160 #ifdef BYTE_CODE_SAFE
161 #define Bset_mark 0163 /* this loser is no longer generated as of v18 */
163 #define Binteractive_p 0164 /* Obsolete. */
165 #define Bforward_char 0165
166 #define Bforward_word 0166
167 #define Bskip_chars_forward 0167
168 #define Bskip_chars_backward 0170
169 #define Bforward_line 0171
170 #define Bchar_syntax 0172
171 #define Bbuffer_substring 0173
172 #define Bdelete_region 0174
173 #define Bnarrow_to_region 0175
175 #define Bend_of_line 0177
177 #define Bconstant2 0201
179 #define Bgotoifnil 0203
180 #define Bgotoifnonnil 0204
181 #define Bgotoifnilelsepop 0205
182 #define Bgotoifnonnilelsepop 0206
184 #define Bdiscard 0210
187 #define Bsave_excursion 0212
188 #define Bsave_window_excursion 0213 /* Obsolete. */
189 #define Bsave_restriction 0214
192 #define Bunwind_protect 0216
193 #define Bcondition_case 0217
194 #define Btemp_output_buffer_setup 0220 /* Obsolete. */
195 #define Btemp_output_buffer_show 0221 /* Obsolete. */
197 #define Bunbind_all 0222 /* Obsolete. */
199 #define Bset_marker 0223
200 #define Bmatch_beginning 0224
201 #define Bmatch_end 0225
203 #define Bdowncase 0227
205 #define Bstringeqlsign 0230
206 #define Bstringlss 0231
212 #define Bnreverse 0237
215 #define Bcar_safe 0242
216 #define Bcdr_safe 0243
220 #define Bnumberp 0247
221 #define Bintegerp 0250
224 #define BRgotoifnil 0253
225 #define BRgotoifnonnil 0254
226 #define BRgotoifnilelsepop 0255
227 #define BRgotoifnonnilelsepop 0256
230 #define BconcatN 0260
231 #define BinsertN 0261
233 /* Bstack_ref is code 0. */
234 #define Bstack_set 0262
235 #define Bstack_set2 0263
236 #define BdiscardN 0266
238 #define Bconstant 0300
240 /* Whether to maintain a `top' and `bottom' field in the stack frame. */
241 #define BYTE_MAINTAIN_TOP (BYTE_CODE_SAFE || BYTE_MARK_STACK)
243 /* Structure describing a value stack used during byte-code execution
248 /* Program counter. This points into the byte_string below
249 and is relocated when that string is relocated. */
250 const unsigned char *pc
;
252 /* Top and bottom of stack. The bottom points to an area of memory
253 allocated with alloca in Fbyte_code. */
254 #if BYTE_MAINTAIN_TOP
255 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. */
285 mark_byte_stack (void)
287 struct byte_stack
*stack
;
290 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
292 /* If STACK->top is null here, this means there's an opcode in
293 Fbyte_code that wasn't expected to GC, but did. To find out
294 which opcode this is, record the value of `stack', and walk
295 up the stack in a debugger, stopping in frames of Fbyte_code.
296 The culprit is found in the frame of Fbyte_code where the
297 address of its local variable `stack' is equal to the
298 recorded value of `stack' here. */
299 eassert (stack
->top
);
301 for (obj
= stack
->bottom
; obj
<= stack
->top
; ++obj
)
304 mark_object (stack
->byte_string
);
305 mark_object (stack
->constants
);
310 /* Unmark objects in the stacks on byte_stack_list. Relocate program
311 counters. Called when GC has completed. */
314 unmark_byte_stack (void)
316 struct byte_stack
*stack
;
318 for (stack
= byte_stack_list
; stack
; stack
= stack
->next
)
320 if (stack
->byte_string_start
!= SDATA (stack
->byte_string
))
322 int offset
= stack
->pc
- stack
->byte_string_start
;
323 stack
->byte_string_start
= SDATA (stack
->byte_string
);
324 stack
->pc
= stack
->byte_string_start
+ offset
;
330 /* Fetch the next byte from the bytecode stream */
332 #define FETCH *stack.pc++
334 /* Fetch two bytes from the bytecode stream and make a 16-bit number
337 #define FETCH2 (op = FETCH, op + (FETCH << 8))
339 /* Push x onto the execution stack. This used to be #define PUSH(x)
340 (*++stackp = (x)) This oddity is necessary because Alliant can't be
341 bothered to compile the preincrement operator properly, as of 4/91.
344 #define PUSH(x) (top++, *top = (x))
346 /* Pop a value off the execution stack. */
350 /* Discard n values from the execution stack. */
352 #define DISCARD(n) (top -= (n))
354 /* Get the value which is at the top of the execution stack, but don't
359 /* Actions that must be performed before and after calling a function
362 #if !BYTE_MAINTAIN_TOP
363 #define BEFORE_POTENTIAL_GC() ((void)0)
364 #define AFTER_POTENTIAL_GC() ((void)0)
366 #define BEFORE_POTENTIAL_GC() stack.top = top
367 #define AFTER_POTENTIAL_GC() stack.top = NULL
370 /* Garbage collect if we have consed enough since the last time.
371 We do this at every branch, to avoid loops that never GC. */
375 if (consing_since_gc > gc_cons_threshold \
376 && consing_since_gc > gc_relative_threshold) \
378 BEFORE_POTENTIAL_GC (); \
379 Fgarbage_collect (); \
380 AFTER_POTENTIAL_GC (); \
384 /* Check for jumping out of range. */
386 #ifdef BYTE_CODE_SAFE
388 #define CHECK_RANGE(ARG) \
389 if (ARG >= bytestr_length) abort ()
391 #else /* not BYTE_CODE_SAFE */
393 #define CHECK_RANGE(ARG)
395 #endif /* not BYTE_CODE_SAFE */
397 /* A version of the QUIT macro which makes sure that the stack top is
398 set before signaling `quit'. */
400 #define BYTE_CODE_QUIT \
402 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
404 Lisp_Object flag = Vquit_flag; \
406 BEFORE_POTENTIAL_GC (); \
407 if (EQ (Vthrow_on_input, flag)) \
408 Fthrow (Vthrow_on_input, Qt); \
409 Fsignal (Qquit, Qnil); \
410 AFTER_POTENTIAL_GC (); \
412 ELSE_PENDING_SIGNALS \
416 DEFUN ("byte-code", Fbyte_code
, Sbyte_code
, 3, MANY
, 0,
417 doc
: /* Function used internally in byte-compiled code.
418 The first argument, BYTESTR, is a string of byte code;
419 the second, VECTOR, a vector of constants;
420 the third, MAXDEPTH, the maximum stack depth used in this function.
421 If the third argument is incorrect, Emacs may crash.
423 If ARGS-TEMPLATE is specified, it is an argument list specification,
424 according to which any remaining arguments are pushed on the stack
425 before executing BYTESTR.
427 usage: (byte-code BYTESTR VECTOR MAXDEP &optional ARGS-TEMPLATE &rest ARGS) */)
428 (size_t nargs
, Lisp_Object
*args
)
430 Lisp_Object args_tmpl
= nargs
>= 4 ? args
[3] : Qnil
;
431 int pnargs
= nargs
>= 4 ? nargs
- 4 : 0;
432 Lisp_Object
*pargs
= nargs
>= 4 ? args
+ 4 : 0;
433 return exec_byte_code (args
[0], args
[1], args
[2], args_tmpl
, pnargs
, pargs
);
436 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
437 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
438 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
439 argument list (including &rest, &optional, etc.), and ARGS, of size
440 NARGS, should be a vector of the actual arguments. The arguments in
441 ARGS are pushed on the stack according to ARGS_TEMPLATE before
442 executing BYTESTR. */
445 exec_byte_code (Lisp_Object bytestr
, Lisp_Object vector
, Lisp_Object maxdepth
,
446 Lisp_Object args_template
, int nargs
, Lisp_Object
*args
)
448 int count
= SPECPDL_INDEX ();
449 #ifdef BYTE_CODE_METER
454 /* Lisp_Object v1, v2; */
455 Lisp_Object
*vectorp
;
456 #ifdef BYTE_CODE_SAFE
457 int const_length
= XVECTOR (vector
)->size
;
461 struct byte_stack stack
;
465 #if 0 /* CHECK_FRAME_FONT */
467 struct frame
*f
= SELECTED_FRAME ();
469 && FRAME_FONT (f
)->direction
!= 0
470 && FRAME_FONT (f
)->direction
!= 1)
475 CHECK_STRING (bytestr
);
476 CHECK_VECTOR (vector
);
477 CHECK_NUMBER (maxdepth
);
479 if (STRING_MULTIBYTE (bytestr
))
480 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
481 because they produced a raw 8-bit string for byte-code and now
482 such a byte-code string is loaded as multibyte while raw 8-bit
483 characters converted to multibyte form. Thus, now we must
484 convert them back to the originally intended unibyte form. */
485 bytestr
= Fstring_as_unibyte (bytestr
);
487 bytestr_length
= SBYTES (bytestr
);
488 vectorp
= XVECTOR (vector
)->contents
;
490 stack
.byte_string
= bytestr
;
491 stack
.pc
= stack
.byte_string_start
= SDATA (bytestr
);
492 stack
.constants
= vector
;
493 top
= (Lisp_Object
*) alloca (XFASTINT (maxdepth
)
494 * sizeof (Lisp_Object
));
495 #if BYTE_MAINTAIN_TOP
500 stack
.next
= byte_stack_list
;
501 byte_stack_list
= &stack
;
503 #ifdef BYTE_CODE_SAFE
504 stacke
= stack
.bottom
- 1 + XFASTINT (maxdepth
);
507 if (INTEGERP (args_template
))
509 int at
= XINT (args_template
);
511 int mandatory
= at
& 127;
512 int nonrest
= at
>> 8;
513 eassert (mandatory
<= nonrest
);
514 if (nargs
<= nonrest
)
517 for (i
= 0 ; i
< nargs
; i
++, args
++)
519 if (nargs
< mandatory
)
520 /* Too few arguments. */
521 Fsignal (Qwrong_number_of_arguments
,
522 Fcons (Fcons (make_number (mandatory
),
523 rest
? Qand_rest
: make_number (nonrest
)),
524 Fcons (make_number (nargs
), Qnil
)));
527 for (; i
< nonrest
; i
++)
536 for (i
= 0 ; i
< nonrest
; i
++, args
++)
538 PUSH (Flist (nargs
- nonrest
, args
));
541 /* Too many arguments. */
542 Fsignal (Qwrong_number_of_arguments
,
543 Fcons (Fcons (make_number (mandatory
),
544 make_number (nonrest
)),
545 Fcons (make_number (nargs
), Qnil
)));
547 else if (! NILP (args_template
))
548 /* We should push some arguments on the stack. */
550 error ("Unknown args template!");
555 #ifdef BYTE_CODE_SAFE
558 else if (top
< stack
.bottom
- 1)
562 #ifdef BYTE_CODE_METER
564 this_op
= op
= FETCH
;
565 METER_CODE (prev_op
, op
);
585 /* This seems to be the most frequently executed byte-code
586 among the Bvarref's, so avoid a goto here. */
596 if (XSYMBOL (v1
)->redirect
!= SYMBOL_PLAINVAL
597 || (v2
= SYMBOL_VAL (XSYMBOL (v1
)),
600 BEFORE_POTENTIAL_GC ();
601 v2
= Fsymbol_value (v1
);
602 AFTER_POTENTIAL_GC ();
607 BEFORE_POTENTIAL_GC ();
608 v2
= Fsymbol_value (v1
);
609 AFTER_POTENTIAL_GC ();
625 stack
.pc
= stack
.byte_string_start
+ op
;
640 BEFORE_POTENTIAL_GC ();
641 wrong_type_argument (Qlistp
, v1
);
642 AFTER_POTENTIAL_GC ();
651 TOP
= EQ (v1
, TOP
) ? Qt
: Qnil
;
658 BEFORE_POTENTIAL_GC ();
660 TOP
= Fmemq (TOP
, v1
);
661 AFTER_POTENTIAL_GC ();
675 BEFORE_POTENTIAL_GC ();
676 wrong_type_argument (Qlistp
, v1
);
677 AFTER_POTENTIAL_GC ();
700 Lisp_Object sym
, val
;
705 /* Inline the most common case. */
707 && !EQ (val
, Qunbound
)
708 && !XSYMBOL (sym
)->redirect
709 && !SYMBOL_CONSTANT_P (sym
))
710 XSYMBOL (sym
)->val
.value
= val
;
713 BEFORE_POTENTIAL_GC ();
714 set_internal (sym
, val
, Qnil
, 0);
715 AFTER_POTENTIAL_GC ();
729 /* ------------------ */
747 /* Specbind can signal and thus GC. */
748 BEFORE_POTENTIAL_GC ();
749 specbind (vectorp
[op
], POP
);
750 AFTER_POTENTIAL_GC ();
770 BEFORE_POTENTIAL_GC ();
772 #ifdef BYTE_CODE_METER
773 if (byte_metering_on
&& SYMBOLP (TOP
))
778 v2
= Fget (v1
, Qbyte_code_meter
);
780 && XINT (v2
) < MOST_POSITIVE_FIXNUM
)
782 XSETINT (v2
, XINT (v2
) + 1);
783 Fput (v1
, Qbyte_code_meter
, v2
);
787 TOP
= Ffuncall (op
+ 1, &TOP
);
788 AFTER_POTENTIAL_GC ();
808 BEFORE_POTENTIAL_GC ();
809 unbind_to (SPECPDL_INDEX () - op
, Qnil
);
810 AFTER_POTENTIAL_GC ();
813 case Bunbind_all
: /* Obsolete. */
814 /* To unbind back to the beginning of this frame. Not used yet,
815 but will be needed for tail-recursion elimination. */
816 BEFORE_POTENTIAL_GC ();
817 unbind_to (count
, Qnil
);
818 AFTER_POTENTIAL_GC ();
824 op
= FETCH2
; /* pc = FETCH2 loses since FETCH2 contains pc++ */
826 stack
.pc
= stack
.byte_string_start
+ op
;
839 stack
.pc
= stack
.byte_string_start
+ op
;
844 case Bgotoifnilelsepop
:
851 stack
.pc
= stack
.byte_string_start
+ op
;
856 case Bgotoifnonnilelsepop
:
863 stack
.pc
= stack
.byte_string_start
+ op
;
871 stack
.pc
+= (int) *stack
.pc
- 127;
882 stack
.pc
+= (int) *stack
.pc
- 128;
896 stack
.pc
+= (int) *stack
.pc
- 128;
902 case BRgotoifnilelsepop
:
908 stack
.pc
+= op
- 128;
913 case BRgotoifnonnilelsepop
:
919 stack
.pc
+= op
- 128;
933 PUSH (vectorp
[FETCH2
]);
936 case Bsave_excursion
:
937 record_unwind_protect (save_excursion_restore
,
938 save_excursion_save ());
941 case Bsave_current_buffer
: /* Obsolete. */
942 case Bsave_current_buffer_1
:
943 record_unwind_protect (set_buffer_if_live
, Fcurrent_buffer ());
946 case Bsave_window_excursion
: /* Obsolete. */
948 register int count
= SPECPDL_INDEX ();
949 record_unwind_protect (Fset_window_configuration
,
950 Fcurrent_window_configuration (Qnil
));
951 BEFORE_POTENTIAL_GC ();
953 unbind_to (count
, TOP
);
954 AFTER_POTENTIAL_GC ();
958 case Bsave_restriction
:
959 record_unwind_protect (save_restriction_restore
,
960 save_restriction_save ());
963 case Bcatch
: /* FIXME: ill-suited for lexbind */
966 BEFORE_POTENTIAL_GC ();
968 TOP
= internal_catch (TOP
, eval_sub
, v1
);
969 AFTER_POTENTIAL_GC ();
973 case Bunwind_protect
: /* FIXME: avoid closure for lexbind */
974 record_unwind_protect (Fprogn
, POP
);
977 case Bcondition_case
: /* FIXME: ill-suited for lexbind */
979 Lisp_Object handlers
, body
;
982 BEFORE_POTENTIAL_GC ();
983 TOP
= internal_lisp_condition_case (TOP
, body
, handlers
);
984 AFTER_POTENTIAL_GC ();
988 case Btemp_output_buffer_setup
: /* Obsolete. */
989 BEFORE_POTENTIAL_GC ();
991 temp_output_buffer_setup (SSDATA (TOP
));
992 AFTER_POTENTIAL_GC ();
993 TOP
= Vstandard_output
;
996 case Btemp_output_buffer_show
: /* Obsolete. */
999 BEFORE_POTENTIAL_GC ();
1001 temp_output_buffer_show (TOP
);
1003 /* pop binding of standard-output */
1004 unbind_to (SPECPDL_INDEX () - 1, Qnil
);
1005 AFTER_POTENTIAL_GC ();
1012 BEFORE_POTENTIAL_GC ();
1018 while (--op
>= 0 && CONSP (v1
))
1022 AFTER_POTENTIAL_GC ();
1027 TOP
= SYMBOLP (TOP
) ? Qt
: Qnil
;
1031 TOP
= CONSP (TOP
) ? Qt
: Qnil
;
1035 TOP
= STRINGP (TOP
) ? Qt
: Qnil
;
1039 TOP
= CONSP (TOP
) || NILP (TOP
) ? Qt
: Qnil
;
1043 TOP
= NILP (TOP
) ? Qt
: Qnil
;
1050 TOP
= Fcons (TOP
, v1
);
1055 TOP
= Fcons (TOP
, Qnil
);
1062 TOP
= Fcons (TOP
, Fcons (v1
, Qnil
));
1068 TOP
= Flist (3, &TOP
);
1073 TOP
= Flist (4, &TOP
);
1079 TOP
= Flist (op
, &TOP
);
1083 BEFORE_POTENTIAL_GC ();
1084 TOP
= Flength (TOP
);
1085 AFTER_POTENTIAL_GC ();
1091 BEFORE_POTENTIAL_GC ();
1093 TOP
= Faref (TOP
, v1
);
1094 AFTER_POTENTIAL_GC ();
1101 BEFORE_POTENTIAL_GC ();
1103 TOP
= Faset (TOP
, v1
, v2
);
1104 AFTER_POTENTIAL_GC ();
1109 BEFORE_POTENTIAL_GC ();
1110 TOP
= Fsymbol_value (TOP
);
1111 AFTER_POTENTIAL_GC ();
1114 case Bsymbol_function
:
1115 BEFORE_POTENTIAL_GC ();
1116 TOP
= Fsymbol_function (TOP
);
1117 AFTER_POTENTIAL_GC ();
1123 BEFORE_POTENTIAL_GC ();
1125 TOP
= Fset (TOP
, v1
);
1126 AFTER_POTENTIAL_GC ();
1133 BEFORE_POTENTIAL_GC ();
1135 TOP
= Ffset (TOP
, v1
);
1136 AFTER_POTENTIAL_GC ();
1143 BEFORE_POTENTIAL_GC ();
1145 TOP
= Fget (TOP
, v1
);
1146 AFTER_POTENTIAL_GC ();
1153 BEFORE_POTENTIAL_GC ();
1155 TOP
= Fsubstring (TOP
, v1
, v2
);
1156 AFTER_POTENTIAL_GC ();
1161 BEFORE_POTENTIAL_GC ();
1163 TOP
= Fconcat (2, &TOP
);
1164 AFTER_POTENTIAL_GC ();
1168 BEFORE_POTENTIAL_GC ();
1170 TOP
= Fconcat (3, &TOP
);
1171 AFTER_POTENTIAL_GC ();
1175 BEFORE_POTENTIAL_GC ();
1177 TOP
= Fconcat (4, &TOP
);
1178 AFTER_POTENTIAL_GC ();
1183 BEFORE_POTENTIAL_GC ();
1185 TOP
= Fconcat (op
, &TOP
);
1186 AFTER_POTENTIAL_GC ();
1195 XSETINT (v1
, XINT (v1
) - 1);
1200 BEFORE_POTENTIAL_GC ();
1202 AFTER_POTENTIAL_GC ();
1213 XSETINT (v1
, XINT (v1
) + 1);
1218 BEFORE_POTENTIAL_GC ();
1220 AFTER_POTENTIAL_GC ();
1228 BEFORE_POTENTIAL_GC ();
1230 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1
);
1231 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2
);
1232 AFTER_POTENTIAL_GC ();
1233 if (FLOATP (v1
) || FLOATP (v2
))
1237 f1
= (FLOATP (v1
) ? XFLOAT_DATA (v1
) : XINT (v1
));
1238 f2
= (FLOATP (v2
) ? XFLOAT_DATA (v2
) : XINT (v2
));
1239 TOP
= (f1
== f2
? Qt
: Qnil
);
1242 TOP
= (XINT (v1
) == XINT (v2
) ? Qt
: Qnil
);
1249 BEFORE_POTENTIAL_GC ();
1251 TOP
= Fgtr (TOP
, v1
);
1252 AFTER_POTENTIAL_GC ();
1259 BEFORE_POTENTIAL_GC ();
1261 TOP
= Flss (TOP
, v1
);
1262 AFTER_POTENTIAL_GC ();
1269 BEFORE_POTENTIAL_GC ();
1271 TOP
= Fleq (TOP
, v1
);
1272 AFTER_POTENTIAL_GC ();
1279 BEFORE_POTENTIAL_GC ();
1281 TOP
= Fgeq (TOP
, v1
);
1282 AFTER_POTENTIAL_GC ();
1287 BEFORE_POTENTIAL_GC ();
1289 TOP
= Fminus (2, &TOP
);
1290 AFTER_POTENTIAL_GC ();
1299 XSETINT (v1
, - XINT (v1
));
1304 BEFORE_POTENTIAL_GC ();
1305 TOP
= Fminus (1, &TOP
);
1306 AFTER_POTENTIAL_GC ();
1312 BEFORE_POTENTIAL_GC ();
1314 TOP
= Fplus (2, &TOP
);
1315 AFTER_POTENTIAL_GC ();
1319 BEFORE_POTENTIAL_GC ();
1321 TOP
= Fmax (2, &TOP
);
1322 AFTER_POTENTIAL_GC ();
1326 BEFORE_POTENTIAL_GC ();
1328 TOP
= Fmin (2, &TOP
);
1329 AFTER_POTENTIAL_GC ();
1333 BEFORE_POTENTIAL_GC ();
1335 TOP
= Ftimes (2, &TOP
);
1336 AFTER_POTENTIAL_GC ();
1340 BEFORE_POTENTIAL_GC ();
1342 TOP
= Fquo (2, &TOP
);
1343 AFTER_POTENTIAL_GC ();
1349 BEFORE_POTENTIAL_GC ();
1351 TOP
= Frem (TOP
, v1
);
1352 AFTER_POTENTIAL_GC ();
1359 XSETFASTINT (v1
, PT
);
1365 BEFORE_POTENTIAL_GC ();
1366 TOP
= Fgoto_char (TOP
);
1367 AFTER_POTENTIAL_GC ();
1371 BEFORE_POTENTIAL_GC ();
1372 TOP
= Finsert (1, &TOP
);
1373 AFTER_POTENTIAL_GC ();
1378 BEFORE_POTENTIAL_GC ();
1380 TOP
= Finsert (op
, &TOP
);
1381 AFTER_POTENTIAL_GC ();
1387 XSETFASTINT (v1
, ZV
);
1395 XSETFASTINT (v1
, BEGV
);
1401 BEFORE_POTENTIAL_GC ();
1402 TOP
= Fchar_after (TOP
);
1403 AFTER_POTENTIAL_GC ();
1406 case Bfollowing_char
:
1409 BEFORE_POTENTIAL_GC ();
1410 v1
= Ffollowing_char ();
1411 AFTER_POTENTIAL_GC ();
1416 case Bpreceding_char
:
1419 BEFORE_POTENTIAL_GC ();
1420 v1
= Fprevious_char ();
1421 AFTER_POTENTIAL_GC ();
1426 case Bcurrent_column
:
1429 BEFORE_POTENTIAL_GC ();
1430 XSETFASTINT (v1
, current_column ());
1431 AFTER_POTENTIAL_GC ();
1437 BEFORE_POTENTIAL_GC ();
1438 TOP
= Findent_to (TOP
, Qnil
);
1439 AFTER_POTENTIAL_GC ();
1458 case Bcurrent_buffer
:
1459 PUSH (Fcurrent_buffer ());
1463 BEFORE_POTENTIAL_GC ();
1464 TOP
= Fset_buffer (TOP
);
1465 AFTER_POTENTIAL_GC ();
1468 case Binteractive_p
: /* Obsolete. */
1469 PUSH (Finteractive_p ());
1473 BEFORE_POTENTIAL_GC ();
1474 TOP
= Fforward_char (TOP
);
1475 AFTER_POTENTIAL_GC ();
1479 BEFORE_POTENTIAL_GC ();
1480 TOP
= Fforward_word (TOP
);
1481 AFTER_POTENTIAL_GC ();
1484 case Bskip_chars_forward
:
1487 BEFORE_POTENTIAL_GC ();
1489 TOP
= Fskip_chars_forward (TOP
, v1
);
1490 AFTER_POTENTIAL_GC ();
1494 case Bskip_chars_backward
:
1497 BEFORE_POTENTIAL_GC ();
1499 TOP
= Fskip_chars_backward (TOP
, v1
);
1500 AFTER_POTENTIAL_GC ();
1505 BEFORE_POTENTIAL_GC ();
1506 TOP
= Fforward_line (TOP
);
1507 AFTER_POTENTIAL_GC ();
1514 BEFORE_POTENTIAL_GC ();
1515 CHECK_CHARACTER (TOP
);
1516 AFTER_POTENTIAL_GC ();
1518 if (NILP (BVAR (current_buffer
, enable_multibyte_characters
)))
1519 MAKE_CHAR_MULTIBYTE (c
);
1520 XSETFASTINT (TOP
, syntax_code_spec
[(int) SYNTAX (c
)]);
1524 case Bbuffer_substring
:
1527 BEFORE_POTENTIAL_GC ();
1529 TOP
= Fbuffer_substring (TOP
, v1
);
1530 AFTER_POTENTIAL_GC ();
1534 case Bdelete_region
:
1537 BEFORE_POTENTIAL_GC ();
1539 TOP
= Fdelete_region (TOP
, v1
);
1540 AFTER_POTENTIAL_GC ();
1544 case Bnarrow_to_region
:
1547 BEFORE_POTENTIAL_GC ();
1549 TOP
= Fnarrow_to_region (TOP
, v1
);
1550 AFTER_POTENTIAL_GC ();
1555 BEFORE_POTENTIAL_GC ();
1557 AFTER_POTENTIAL_GC ();
1561 BEFORE_POTENTIAL_GC ();
1562 TOP
= Fend_of_line (TOP
);
1563 AFTER_POTENTIAL_GC ();
1569 BEFORE_POTENTIAL_GC ();
1572 TOP
= Fset_marker (TOP
, v2
, v1
);
1573 AFTER_POTENTIAL_GC ();
1577 case Bmatch_beginning
:
1578 BEFORE_POTENTIAL_GC ();
1579 TOP
= Fmatch_beginning (TOP
);
1580 AFTER_POTENTIAL_GC ();
1584 BEFORE_POTENTIAL_GC ();
1585 TOP
= Fmatch_end (TOP
);
1586 AFTER_POTENTIAL_GC ();
1590 BEFORE_POTENTIAL_GC ();
1591 TOP
= Fupcase (TOP
);
1592 AFTER_POTENTIAL_GC ();
1596 BEFORE_POTENTIAL_GC ();
1597 TOP
= Fdowncase (TOP
);
1598 AFTER_POTENTIAL_GC ();
1601 case Bstringeqlsign
:
1604 BEFORE_POTENTIAL_GC ();
1606 TOP
= Fstring_equal (TOP
, v1
);
1607 AFTER_POTENTIAL_GC ();
1614 BEFORE_POTENTIAL_GC ();
1616 TOP
= Fstring_lessp (TOP
, v1
);
1617 AFTER_POTENTIAL_GC ();
1625 TOP
= Fequal (TOP
, v1
);
1632 BEFORE_POTENTIAL_GC ();
1634 TOP
= Fnthcdr (TOP
, v1
);
1635 AFTER_POTENTIAL_GC ();
1644 /* Exchange args and then do nth. */
1645 BEFORE_POTENTIAL_GC ();
1649 AFTER_POTENTIAL_GC ();
1652 while (--op
>= 0 && CONSP (v1
))
1659 BEFORE_POTENTIAL_GC ();
1661 TOP
= Felt (TOP
, v1
);
1662 AFTER_POTENTIAL_GC ();
1670 BEFORE_POTENTIAL_GC ();
1672 TOP
= Fmember (TOP
, v1
);
1673 AFTER_POTENTIAL_GC ();
1680 BEFORE_POTENTIAL_GC ();
1682 TOP
= Fassq (TOP
, v1
);
1683 AFTER_POTENTIAL_GC ();
1688 BEFORE_POTENTIAL_GC ();
1689 TOP
= Fnreverse (TOP
);
1690 AFTER_POTENTIAL_GC ();
1696 BEFORE_POTENTIAL_GC ();
1698 TOP
= Fsetcar (TOP
, v1
);
1699 AFTER_POTENTIAL_GC ();
1706 BEFORE_POTENTIAL_GC ();
1708 TOP
= Fsetcdr (TOP
, v1
);
1709 AFTER_POTENTIAL_GC ();
1717 TOP
= CAR_SAFE (v1
);
1725 TOP
= CDR_SAFE (v1
);
1730 BEFORE_POTENTIAL_GC ();
1732 TOP
= Fnconc (2, &TOP
);
1733 AFTER_POTENTIAL_GC ();
1737 TOP
= (NUMBERP (TOP
) ? Qt
: Qnil
);
1741 TOP
= INTEGERP (TOP
) ? Qt
: Qnil
;
1744 #ifdef BYTE_CODE_SAFE
1746 BEFORE_POTENTIAL_GC ();
1747 error ("set-mark is an obsolete bytecode");
1748 AFTER_POTENTIAL_GC ();
1751 BEFORE_POTENTIAL_GC ();
1752 error ("scan-buffer is an obsolete bytecode");
1753 AFTER_POTENTIAL_GC ();
1758 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1759 for that instead. */
1760 /* case Bstack_ref: */
1763 /* Handy byte-codes for lexical binding. */
1770 Lisp_Object
*ptr
= top
- (op
- Bstack_ref
);
1776 Lisp_Object
*ptr
= top
- (FETCH
);
1782 Lisp_Object
*ptr
= top
- (FETCH2
);
1786 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1789 Lisp_Object
*ptr
= top
- (FETCH
);
1795 Lisp_Object
*ptr
= top
- (FETCH2
);
1811 #ifdef BYTE_CODE_SAFE
1816 if ((op
-= Bconstant
) >= const_length
)
1822 PUSH (vectorp
[op
- Bconstant
]);
1829 byte_stack_list
= byte_stack_list
->next
;
1831 /* Binds and unbinds are supposed to be compiled balanced. */
1832 if (SPECPDL_INDEX () != count
)
1833 #ifdef BYTE_CODE_SAFE
1834 error ("binding stack not balanced (serious byte compiler bug)");
1843 syms_of_bytecode (void)
1845 Qbytecode
= intern_c_string ("byte-code");
1846 staticpro (&Qbytecode
);
1848 defsubr (&Sbyte_code
);
1850 #ifdef BYTE_CODE_METER
1852 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter
,
1853 doc
: /* A vector of vectors which holds a histogram of byte-code usage.
1854 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1855 opcode CODE has been executed.
1856 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1857 indicates how many times the byte opcodes CODE1 and CODE2 have been
1858 executed in succession. */);
1860 DEFVAR_BOOL ("byte-metering-on", byte_metering_on
,
1861 doc
: /* If non-nil, keep profiling information on byte code usage.
1862 The variable byte-code-meter indicates how often each byte opcode is used.
1863 If a symbol has a property named `byte-code-meter' whose value is an
1864 integer, it is incremented each time that symbol's function is called. */);
1866 byte_metering_on
= 0;
1867 Vbyte_code_meter
= Fmake_vector (make_number (256), make_number (0));
1868 Qbyte_code_meter
= intern_c_string ("byte-code-meter");
1869 staticpro (&Qbyte_code_meter
);
1873 XVECTOR (Vbyte_code_meter
)->contents
[i
] =
1874 Fmake_vector (make_number (256), make_number (0));