* alloc.c (pure_bytes_used_lisp, pure_bytes_used_non_lisp):
[bpt/emacs.git] / src / bytecode.c
1 /* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985-1988, 1993, 2000-2011 Free Software Foundation, Inc.
3
4 This file is part of GNU Emacs.
5
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.
10
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.
15
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/>. */
18
19 /*
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
26 of args;
27 o made the new bytecodes be called with args in the right order;
28 o added metering support.
29
30 by Hallvard:
31 o added relative jump instructions;
32 o all conditionals now only do QUIT if they jump.
33 */
34
35 #include <config.h>
36 #include <setjmp.h>
37 #include "lisp.h"
38 #include "buffer.h"
39 #include "character.h"
40 #include "syntax.h"
41 #include "window.h"
42
43 #ifdef CHECK_FRAME_FONT
44 #include "frame.h"
45 #include "xterm.h"
46 #endif
47
48 /*
49 * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for
50 * debugging the byte compiler...)
51 *
52 * define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
53 */
54 /* #define BYTE_CODE_SAFE */
55 /* #define BYTE_CODE_METER */
56
57 \f
58 #ifdef BYTE_CODE_METER
59
60 Lisp_Object Qbyte_code_meter;
61 #define METER_2(code1, code2) \
62 XFASTINT (XVECTOR (XVECTOR (Vbyte_code_meter)->contents[(code1)]) \
63 ->contents[(code2)])
64
65 #define METER_1(code) METER_2 (0, (code))
66
67 #define METER_CODE(last_code, this_code) \
68 { \
69 if (byte_metering_on) \
70 { \
71 if (METER_1 (this_code) < MOST_POSITIVE_FIXNUM) \
72 METER_1 (this_code)++; \
73 if (last_code \
74 && METER_2 (last_code, this_code) < MOST_POSITIVE_FIXNUM) \
75 METER_2 (last_code, this_code)++; \
76 } \
77 }
78
79 #endif /* BYTE_CODE_METER */
80 \f
81
82 Lisp_Object Qbytecode;
83
84 /* Byte codes: */
85
86 #define Bstack_ref 0 /* Actually, Bstack_ref+0 is not implemented: use dup. */
87 #define Bvarref 010
88 #define Bvarset 020
89 #define Bvarbind 030
90 #define Bcall 040
91 #define Bunbind 050
92
93 #define Bnth 070
94 #define Bsymbolp 071
95 #define Bconsp 072
96 #define Bstringp 073
97 #define Blistp 074
98 #define Beq 075
99 #define Bmemq 076
100 #define Bnot 077
101 #define Bcar 0100
102 #define Bcdr 0101
103 #define Bcons 0102
104 #define Blist1 0103
105 #define Blist2 0104
106 #define Blist3 0105
107 #define Blist4 0106
108 #define Blength 0107
109 #define Baref 0110
110 #define Baset 0111
111 #define Bsymbol_value 0112
112 #define Bsymbol_function 0113
113 #define Bset 0114
114 #define Bfset 0115
115 #define Bget 0116
116 #define Bsubstring 0117
117 #define Bconcat2 0120
118 #define Bconcat3 0121
119 #define Bconcat4 0122
120 #define Bsub1 0123
121 #define Badd1 0124
122 #define Beqlsign 0125
123 #define Bgtr 0126
124 #define Blss 0127
125 #define Bleq 0130
126 #define Bgeq 0131
127 #define Bdiff 0132
128 #define Bnegate 0133
129 #define Bplus 0134
130 #define Bmax 0135
131 #define Bmin 0136
132 #define Bmult 0137
133
134 #define Bpoint 0140
135 /* Was Bmark in v17. */
136 #define Bsave_current_buffer 0141 /* Obsolete. */
137 #define Bgoto_char 0142
138 #define Binsert 0143
139 #define Bpoint_max 0144
140 #define Bpoint_min 0145
141 #define Bchar_after 0146
142 #define Bfollowing_char 0147
143 #define Bpreceding_char 0150
144 #define Bcurrent_column 0151
145 #define Bindent_to 0152
146 #ifdef BYTE_CODE_SAFE
147 #define Bscan_buffer 0153 /* No longer generated as of v18. */
148 #endif
149 #define Beolp 0154
150 #define Beobp 0155
151 #define Bbolp 0156
152 #define Bbobp 0157
153 #define Bcurrent_buffer 0160
154 #define Bset_buffer 0161
155 #define Bsave_current_buffer_1 0162 /* Replacing Bsave_current_buffer. */
156 #if 0
157 #define Bread_char 0162 /* No longer generated as of v19 */
158 #endif
159 #ifdef BYTE_CODE_SAFE
160 #define Bset_mark 0163 /* this loser is no longer generated as of v18 */
161 #endif
162 #define Binteractive_p 0164 /* Obsolete since Emacs-24.1. */
163
164 #define Bforward_char 0165
165 #define Bforward_word 0166
166 #define Bskip_chars_forward 0167
167 #define Bskip_chars_backward 0170
168 #define Bforward_line 0171
169 #define Bchar_syntax 0172
170 #define Bbuffer_substring 0173
171 #define Bdelete_region 0174
172 #define Bnarrow_to_region 0175
173 #define Bwiden 0176
174 #define Bend_of_line 0177
175
176 #define Bconstant2 0201
177 #define Bgoto 0202
178 #define Bgotoifnil 0203
179 #define Bgotoifnonnil 0204
180 #define Bgotoifnilelsepop 0205
181 #define Bgotoifnonnilelsepop 0206
182 #define Breturn 0207
183 #define Bdiscard 0210
184 #define Bdup 0211
185
186 #define Bsave_excursion 0212
187 #define Bsave_window_excursion 0213 /* Obsolete since Emacs-24.1. */
188 #define Bsave_restriction 0214
189 #define Bcatch 0215
190
191 #define Bunwind_protect 0216
192 #define Bcondition_case 0217
193 #define Btemp_output_buffer_setup 0220 /* Obsolete since Emacs-24.1. */
194 #define Btemp_output_buffer_show 0221 /* Obsolete since Emacs-24.1. */
195
196 #define Bunbind_all 0222 /* Obsolete. Never used. */
197
198 #define Bset_marker 0223
199 #define Bmatch_beginning 0224
200 #define Bmatch_end 0225
201 #define Bupcase 0226
202 #define Bdowncase 0227
203
204 #define Bstringeqlsign 0230
205 #define Bstringlss 0231
206 #define Bequal 0232
207 #define Bnthcdr 0233
208 #define Belt 0234
209 #define Bmember 0235
210 #define Bassq 0236
211 #define Bnreverse 0237
212 #define Bsetcar 0240
213 #define Bsetcdr 0241
214 #define Bcar_safe 0242
215 #define Bcdr_safe 0243
216 #define Bnconc 0244
217 #define Bquo 0245
218 #define Brem 0246
219 #define Bnumberp 0247
220 #define Bintegerp 0250
221
222 #define BRgoto 0252
223 #define BRgotoifnil 0253
224 #define BRgotoifnonnil 0254
225 #define BRgotoifnilelsepop 0255
226 #define BRgotoifnonnilelsepop 0256
227
228 #define BlistN 0257
229 #define BconcatN 0260
230 #define BinsertN 0261
231
232 /* Bstack_ref is code 0. */
233 #define Bstack_set 0262
234 #define Bstack_set2 0263
235 #define BdiscardN 0266
236
237 #define Bconstant 0300
238
239 /* Whether to maintain a `top' and `bottom' field in the stack frame. */
240 #define BYTE_MAINTAIN_TOP (BYTE_CODE_SAFE || BYTE_MARK_STACK)
241 \f
242 /* Structure describing a value stack used during byte-code execution
243 in Fbyte_code. */
244
245 struct byte_stack
246 {
247 /* Program counter. This points into the byte_string below
248 and is relocated when that string is relocated. */
249 const unsigned char *pc;
250
251 /* Top and bottom of stack. The bottom points to an area of memory
252 allocated with alloca in Fbyte_code. */
253 #if BYTE_MAINTAIN_TOP
254 Lisp_Object *top, *bottom;
255 #endif
256
257 /* The string containing the byte-code, and its current address.
258 Storing this here protects it from GC because mark_byte_stack
259 marks it. */
260 Lisp_Object byte_string;
261 const unsigned char *byte_string_start;
262
263 /* The vector of constants used during byte-code execution. Storing
264 this here protects it from GC because mark_byte_stack marks it. */
265 Lisp_Object constants;
266
267 /* Next entry in byte_stack_list. */
268 struct byte_stack *next;
269 };
270
271 /* A list of currently active byte-code execution value stacks.
272 Fbyte_code adds an entry to the head of this list before it starts
273 processing byte-code, and it removed the entry again when it is
274 done. Signalling an error truncates the list analoguous to
275 gcprolist. */
276
277 struct byte_stack *byte_stack_list;
278
279 \f
280 /* Mark objects on byte_stack_list. Called during GC. */
281
282 #if BYTE_MARK_STACK
283 void
284 mark_byte_stack (void)
285 {
286 struct byte_stack *stack;
287 Lisp_Object *obj;
288
289 for (stack = byte_stack_list; stack; stack = stack->next)
290 {
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);
299
300 for (obj = stack->bottom; obj <= stack->top; ++obj)
301 mark_object (*obj);
302
303 mark_object (stack->byte_string);
304 mark_object (stack->constants);
305 }
306 }
307 #endif
308
309 /* Unmark objects in the stacks on byte_stack_list. Relocate program
310 counters. Called when GC has completed. */
311
312 void
313 unmark_byte_stack (void)
314 {
315 struct byte_stack *stack;
316
317 for (stack = byte_stack_list; stack; stack = stack->next)
318 {
319 if (stack->byte_string_start != SDATA (stack->byte_string))
320 {
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;
324 }
325 }
326 }
327
328 \f
329 /* Fetch the next byte from the bytecode stream */
330
331 #define FETCH *stack.pc++
332
333 /* Fetch two bytes from the bytecode stream and make a 16-bit number
334 out of them */
335
336 #define FETCH2 (op = FETCH, op + (FETCH << 8))
337
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.
341 -JimB */
342
343 #define PUSH(x) (top++, *top = (x))
344
345 /* Pop a value off the execution stack. */
346
347 #define POP (*top--)
348
349 /* Discard n values from the execution stack. */
350
351 #define DISCARD(n) (top -= (n))
352
353 /* Get the value which is at the top of the execution stack, but don't
354 pop it. */
355
356 #define TOP (*top)
357
358 /* Actions that must be performed before and after calling a function
359 that might GC. */
360
361 #if !BYTE_MAINTAIN_TOP
362 #define BEFORE_POTENTIAL_GC() ((void)0)
363 #define AFTER_POTENTIAL_GC() ((void)0)
364 #else
365 #define BEFORE_POTENTIAL_GC() stack.top = top
366 #define AFTER_POTENTIAL_GC() stack.top = NULL
367 #endif
368
369 /* Garbage collect if we have consed enough since the last time.
370 We do this at every branch, to avoid loops that never GC. */
371
372 #define MAYBE_GC() \
373 do { \
374 if (consing_since_gc > gc_cons_threshold \
375 && consing_since_gc > gc_relative_threshold) \
376 { \
377 BEFORE_POTENTIAL_GC (); \
378 Fgarbage_collect (); \
379 AFTER_POTENTIAL_GC (); \
380 } \
381 } while (0)
382
383 /* Check for jumping out of range. */
384
385 #ifdef BYTE_CODE_SAFE
386
387 #define CHECK_RANGE(ARG) \
388 if (ARG >= bytestr_length) abort ()
389
390 #else /* not BYTE_CODE_SAFE */
391
392 #define CHECK_RANGE(ARG)
393
394 #endif /* not BYTE_CODE_SAFE */
395
396 /* A version of the QUIT macro which makes sure that the stack top is
397 set before signaling `quit'. */
398
399 #define BYTE_CODE_QUIT \
400 do { \
401 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
402 { \
403 Lisp_Object flag = Vquit_flag; \
404 Vquit_flag = Qnil; \
405 BEFORE_POTENTIAL_GC (); \
406 if (EQ (Vthrow_on_input, flag)) \
407 Fthrow (Vthrow_on_input, Qt); \
408 Fsignal (Qquit, Qnil); \
409 AFTER_POTENTIAL_GC (); \
410 } \
411 ELSE_PENDING_SIGNALS \
412 } while (0)
413
414
415 DEFUN ("byte-code", Fbyte_code, Sbyte_code, 3, 3, 0,
416 doc: /* Function used internally in byte-compiled code.
417 The first argument, BYTESTR, is a string of byte code;
418 the second, VECTOR, a vector of constants;
419 the third, MAXDEPTH, the maximum stack depth used in this function.
420 If the third argument is incorrect, Emacs may crash. */)
421 (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth)
422 {
423 return exec_byte_code (bytestr, vector, maxdepth, Qnil, 0, NULL);
424 }
425
426 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
427 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
428 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
429 argument list (including &rest, &optional, etc.), and ARGS, of size
430 NARGS, should be a vector of the actual arguments. The arguments in
431 ARGS are pushed on the stack according to ARGS_TEMPLATE before
432 executing BYTESTR. */
433
434 Lisp_Object
435 exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
436 Lisp_Object args_template, ptrdiff_t nargs, Lisp_Object *args)
437 {
438 ptrdiff_t count = SPECPDL_INDEX ();
439 #ifdef BYTE_CODE_METER
440 int this_op = 0;
441 int prev_op;
442 #endif
443 int op;
444 /* Lisp_Object v1, v2; */
445 Lisp_Object *vectorp;
446 #ifdef BYTE_CODE_SAFE
447 ptrdiff_t const_length;
448 Lisp_Object *stacke;
449 int bytestr_length;
450 #endif
451 struct byte_stack stack;
452 Lisp_Object *top;
453 Lisp_Object result;
454
455 #if 0 /* CHECK_FRAME_FONT */
456 {
457 struct frame *f = SELECTED_FRAME ();
458 if (FRAME_X_P (f)
459 && FRAME_FONT (f)->direction != 0
460 && FRAME_FONT (f)->direction != 1)
461 abort ();
462 }
463 #endif
464
465 CHECK_STRING (bytestr);
466 CHECK_VECTOR (vector);
467 CHECK_NATNUM (maxdepth);
468
469 #ifdef BYTE_CODE_SAFE
470 const_length = ASIZE (vector);
471 #endif
472
473 if (STRING_MULTIBYTE (bytestr))
474 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
475 because they produced a raw 8-bit string for byte-code and now
476 such a byte-code string is loaded as multibyte while raw 8-bit
477 characters converted to multibyte form. Thus, now we must
478 convert them back to the originally intended unibyte form. */
479 bytestr = Fstring_as_unibyte (bytestr);
480
481 #ifdef BYTE_CODE_SAFE
482 bytestr_length = SBYTES (bytestr);
483 #endif
484 vectorp = XVECTOR (vector)->contents;
485
486 stack.byte_string = bytestr;
487 stack.pc = stack.byte_string_start = SDATA (bytestr);
488 stack.constants = vector;
489 top = (Lisp_Object *) alloca (XFASTINT (maxdepth)
490 * sizeof (Lisp_Object));
491 #if BYTE_MAINTAIN_TOP
492 stack.bottom = top;
493 stack.top = NULL;
494 #endif
495 top -= 1;
496 stack.next = byte_stack_list;
497 byte_stack_list = &stack;
498
499 #ifdef BYTE_CODE_SAFE
500 stacke = stack.bottom - 1 + XFASTINT (maxdepth);
501 #endif
502
503 if (INTEGERP (args_template))
504 {
505 EMACS_INT at = XINT (args_template);
506 int rest = at & 128;
507 int mandatory = at & 127;
508 EMACS_INT nonrest = at >> 8;
509 eassert (mandatory <= nonrest);
510 if (nargs <= nonrest)
511 {
512 EMACS_INT i;
513 for (i = 0 ; i < nargs; i++, args++)
514 PUSH (*args);
515 if (nargs < mandatory)
516 /* Too few arguments. */
517 Fsignal (Qwrong_number_of_arguments,
518 Fcons (Fcons (make_number (mandatory),
519 rest ? Qand_rest : make_number (nonrest)),
520 Fcons (make_number (nargs), Qnil)));
521 else
522 {
523 for (; i < nonrest; i++)
524 PUSH (Qnil);
525 if (rest)
526 PUSH (Qnil);
527 }
528 }
529 else if (rest)
530 {
531 ptrdiff_t i;
532 for (i = 0 ; i < nonrest; i++, args++)
533 PUSH (*args);
534 PUSH (Flist (nargs - nonrest, args));
535 }
536 else
537 /* Too many arguments. */
538 Fsignal (Qwrong_number_of_arguments,
539 Fcons (Fcons (make_number (mandatory),
540 make_number (nonrest)),
541 Fcons (make_number (nargs), Qnil)));
542 }
543 else if (! NILP (args_template))
544 /* We should push some arguments on the stack. */
545 {
546 error ("Unknown args template!");
547 }
548
549 while (1)
550 {
551 #ifdef BYTE_CODE_SAFE
552 if (top > stacke)
553 abort ();
554 else if (top < stack.bottom - 1)
555 abort ();
556 #endif
557
558 #ifdef BYTE_CODE_METER
559 prev_op = this_op;
560 this_op = op = FETCH;
561 METER_CODE (prev_op, op);
562 #else
563 op = FETCH;
564 #endif
565
566 switch (op)
567 {
568 case Bvarref + 7:
569 op = FETCH2;
570 goto varref;
571
572 case Bvarref:
573 case Bvarref + 1:
574 case Bvarref + 2:
575 case Bvarref + 3:
576 case Bvarref + 4:
577 case Bvarref + 5:
578 op = op - Bvarref;
579 goto varref;
580
581 /* This seems to be the most frequently executed byte-code
582 among the Bvarref's, so avoid a goto here. */
583 case Bvarref+6:
584 op = FETCH;
585 varref:
586 {
587 Lisp_Object v1, v2;
588
589 v1 = vectorp[op];
590 if (SYMBOLP (v1))
591 {
592 if (XSYMBOL (v1)->redirect != SYMBOL_PLAINVAL
593 || (v2 = SYMBOL_VAL (XSYMBOL (v1)),
594 EQ (v2, Qunbound)))
595 {
596 BEFORE_POTENTIAL_GC ();
597 v2 = Fsymbol_value (v1);
598 AFTER_POTENTIAL_GC ();
599 }
600 }
601 else
602 {
603 BEFORE_POTENTIAL_GC ();
604 v2 = Fsymbol_value (v1);
605 AFTER_POTENTIAL_GC ();
606 }
607 PUSH (v2);
608 break;
609 }
610
611 case Bgotoifnil:
612 {
613 Lisp_Object v1;
614 MAYBE_GC ();
615 op = FETCH2;
616 v1 = POP;
617 if (NILP (v1))
618 {
619 BYTE_CODE_QUIT;
620 CHECK_RANGE (op);
621 stack.pc = stack.byte_string_start + op;
622 }
623 break;
624 }
625
626 case Bcar:
627 {
628 Lisp_Object v1;
629 v1 = TOP;
630 if (CONSP (v1))
631 TOP = XCAR (v1);
632 else if (NILP (v1))
633 TOP = Qnil;
634 else
635 {
636 BEFORE_POTENTIAL_GC ();
637 wrong_type_argument (Qlistp, v1);
638 AFTER_POTENTIAL_GC ();
639 }
640 break;
641 }
642
643 case Beq:
644 {
645 Lisp_Object v1;
646 v1 = POP;
647 TOP = EQ (v1, TOP) ? Qt : Qnil;
648 break;
649 }
650
651 case Bmemq:
652 {
653 Lisp_Object v1;
654 BEFORE_POTENTIAL_GC ();
655 v1 = POP;
656 TOP = Fmemq (TOP, v1);
657 AFTER_POTENTIAL_GC ();
658 break;
659 }
660
661 case Bcdr:
662 {
663 Lisp_Object v1;
664 v1 = TOP;
665 if (CONSP (v1))
666 TOP = XCDR (v1);
667 else if (NILP (v1))
668 TOP = Qnil;
669 else
670 {
671 BEFORE_POTENTIAL_GC ();
672 wrong_type_argument (Qlistp, v1);
673 AFTER_POTENTIAL_GC ();
674 }
675 break;
676 break;
677 }
678
679 case Bvarset:
680 case Bvarset+1:
681 case Bvarset+2:
682 case Bvarset+3:
683 case Bvarset+4:
684 case Bvarset+5:
685 op -= Bvarset;
686 goto varset;
687
688 case Bvarset+7:
689 op = FETCH2;
690 goto varset;
691
692 case Bvarset+6:
693 op = FETCH;
694 varset:
695 {
696 Lisp_Object sym, val;
697
698 sym = vectorp[op];
699 val = TOP;
700
701 /* Inline the most common case. */
702 if (SYMBOLP (sym)
703 && !EQ (val, Qunbound)
704 && !XSYMBOL (sym)->redirect
705 && !SYMBOL_CONSTANT_P (sym))
706 XSYMBOL (sym)->val.value = val;
707 else
708 {
709 BEFORE_POTENTIAL_GC ();
710 set_internal (sym, val, Qnil, 0);
711 AFTER_POTENTIAL_GC ();
712 }
713 }
714 (void) POP;
715 break;
716
717 case Bdup:
718 {
719 Lisp_Object v1;
720 v1 = TOP;
721 PUSH (v1);
722 break;
723 }
724
725 /* ------------------ */
726
727 case Bvarbind+6:
728 op = FETCH;
729 goto varbind;
730
731 case Bvarbind+7:
732 op = FETCH2;
733 goto varbind;
734
735 case Bvarbind:
736 case Bvarbind+1:
737 case Bvarbind+2:
738 case Bvarbind+3:
739 case Bvarbind+4:
740 case Bvarbind+5:
741 op -= Bvarbind;
742 varbind:
743 /* Specbind can signal and thus GC. */
744 BEFORE_POTENTIAL_GC ();
745 specbind (vectorp[op], POP);
746 AFTER_POTENTIAL_GC ();
747 break;
748
749 case Bcall+6:
750 op = FETCH;
751 goto docall;
752
753 case Bcall+7:
754 op = FETCH2;
755 goto docall;
756
757 case Bcall:
758 case Bcall+1:
759 case Bcall+2:
760 case Bcall+3:
761 case Bcall+4:
762 case Bcall+5:
763 op -= Bcall;
764 docall:
765 {
766 BEFORE_POTENTIAL_GC ();
767 DISCARD (op);
768 #ifdef BYTE_CODE_METER
769 if (byte_metering_on && SYMBOLP (TOP))
770 {
771 Lisp_Object v1, v2;
772
773 v1 = TOP;
774 v2 = Fget (v1, Qbyte_code_meter);
775 if (INTEGERP (v2)
776 && XINT (v2) < MOST_POSITIVE_FIXNUM)
777 {
778 XSETINT (v2, XINT (v2) + 1);
779 Fput (v1, Qbyte_code_meter, v2);
780 }
781 }
782 #endif
783 TOP = Ffuncall (op + 1, &TOP);
784 AFTER_POTENTIAL_GC ();
785 break;
786 }
787
788 case Bunbind+6:
789 op = FETCH;
790 goto dounbind;
791
792 case Bunbind+7:
793 op = FETCH2;
794 goto dounbind;
795
796 case Bunbind:
797 case Bunbind+1:
798 case Bunbind+2:
799 case Bunbind+3:
800 case Bunbind+4:
801 case Bunbind+5:
802 op -= Bunbind;
803 dounbind:
804 BEFORE_POTENTIAL_GC ();
805 unbind_to (SPECPDL_INDEX () - op, Qnil);
806 AFTER_POTENTIAL_GC ();
807 break;
808
809 case Bunbind_all: /* Obsolete. Never used. */
810 /* To unbind back to the beginning of this frame. Not used yet,
811 but will be needed for tail-recursion elimination. */
812 BEFORE_POTENTIAL_GC ();
813 unbind_to (count, Qnil);
814 AFTER_POTENTIAL_GC ();
815 break;
816
817 case Bgoto:
818 MAYBE_GC ();
819 BYTE_CODE_QUIT;
820 op = FETCH2; /* pc = FETCH2 loses since FETCH2 contains pc++ */
821 CHECK_RANGE (op);
822 stack.pc = stack.byte_string_start + op;
823 break;
824
825 case Bgotoifnonnil:
826 {
827 Lisp_Object v1;
828 MAYBE_GC ();
829 op = FETCH2;
830 v1 = POP;
831 if (!NILP (v1))
832 {
833 BYTE_CODE_QUIT;
834 CHECK_RANGE (op);
835 stack.pc = stack.byte_string_start + op;
836 }
837 break;
838 }
839
840 case Bgotoifnilelsepop:
841 MAYBE_GC ();
842 op = FETCH2;
843 if (NILP (TOP))
844 {
845 BYTE_CODE_QUIT;
846 CHECK_RANGE (op);
847 stack.pc = stack.byte_string_start + op;
848 }
849 else DISCARD (1);
850 break;
851
852 case Bgotoifnonnilelsepop:
853 MAYBE_GC ();
854 op = FETCH2;
855 if (!NILP (TOP))
856 {
857 BYTE_CODE_QUIT;
858 CHECK_RANGE (op);
859 stack.pc = stack.byte_string_start + op;
860 }
861 else DISCARD (1);
862 break;
863
864 case BRgoto:
865 MAYBE_GC ();
866 BYTE_CODE_QUIT;
867 stack.pc += (int) *stack.pc - 127;
868 break;
869
870 case BRgotoifnil:
871 {
872 Lisp_Object v1;
873 MAYBE_GC ();
874 v1 = POP;
875 if (NILP (v1))
876 {
877 BYTE_CODE_QUIT;
878 stack.pc += (int) *stack.pc - 128;
879 }
880 stack.pc++;
881 break;
882 }
883
884 case BRgotoifnonnil:
885 {
886 Lisp_Object v1;
887 MAYBE_GC ();
888 v1 = POP;
889 if (!NILP (v1))
890 {
891 BYTE_CODE_QUIT;
892 stack.pc += (int) *stack.pc - 128;
893 }
894 stack.pc++;
895 break;
896 }
897
898 case BRgotoifnilelsepop:
899 MAYBE_GC ();
900 op = *stack.pc++;
901 if (NILP (TOP))
902 {
903 BYTE_CODE_QUIT;
904 stack.pc += op - 128;
905 }
906 else DISCARD (1);
907 break;
908
909 case BRgotoifnonnilelsepop:
910 MAYBE_GC ();
911 op = *stack.pc++;
912 if (!NILP (TOP))
913 {
914 BYTE_CODE_QUIT;
915 stack.pc += op - 128;
916 }
917 else DISCARD (1);
918 break;
919
920 case Breturn:
921 result = POP;
922 goto exit;
923
924 case Bdiscard:
925 DISCARD (1);
926 break;
927
928 case Bconstant2:
929 PUSH (vectorp[FETCH2]);
930 break;
931
932 case Bsave_excursion:
933 record_unwind_protect (save_excursion_restore,
934 save_excursion_save ());
935 break;
936
937 case Bsave_current_buffer: /* Obsolete since ??. */
938 case Bsave_current_buffer_1:
939 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
940 break;
941
942 case Bsave_window_excursion: /* Obsolete since 24.1. */
943 {
944 register ptrdiff_t count1 = SPECPDL_INDEX ();
945 record_unwind_protect (Fset_window_configuration,
946 Fcurrent_window_configuration (Qnil));
947 BEFORE_POTENTIAL_GC ();
948 TOP = Fprogn (TOP);
949 unbind_to (count1, TOP);
950 AFTER_POTENTIAL_GC ();
951 break;
952 }
953
954 case Bsave_restriction:
955 record_unwind_protect (save_restriction_restore,
956 save_restriction_save ());
957 break;
958
959 case Bcatch: /* FIXME: ill-suited for lexbind. */
960 {
961 Lisp_Object v1;
962 BEFORE_POTENTIAL_GC ();
963 v1 = POP;
964 TOP = internal_catch (TOP, eval_sub, v1);
965 AFTER_POTENTIAL_GC ();
966 break;
967 }
968
969 case Bunwind_protect: /* FIXME: avoid closure for lexbind. */
970 record_unwind_protect (Fprogn, POP);
971 break;
972
973 case Bcondition_case: /* FIXME: ill-suited for lexbind. */
974 {
975 Lisp_Object handlers, body;
976 handlers = POP;
977 body = POP;
978 BEFORE_POTENTIAL_GC ();
979 TOP = internal_lisp_condition_case (TOP, body, handlers);
980 AFTER_POTENTIAL_GC ();
981 break;
982 }
983
984 case Btemp_output_buffer_setup: /* Obsolete since 24.1. */
985 BEFORE_POTENTIAL_GC ();
986 CHECK_STRING (TOP);
987 temp_output_buffer_setup (SSDATA (TOP));
988 AFTER_POTENTIAL_GC ();
989 TOP = Vstandard_output;
990 break;
991
992 case Btemp_output_buffer_show: /* Obsolete since 24.1. */
993 {
994 Lisp_Object v1;
995 BEFORE_POTENTIAL_GC ();
996 v1 = POP;
997 temp_output_buffer_show (TOP);
998 TOP = v1;
999 /* pop binding of standard-output */
1000 unbind_to (SPECPDL_INDEX () - 1, Qnil);
1001 AFTER_POTENTIAL_GC ();
1002 break;
1003 }
1004
1005 case Bnth:
1006 {
1007 Lisp_Object v1, v2;
1008 EMACS_INT n;
1009 BEFORE_POTENTIAL_GC ();
1010 v1 = POP;
1011 v2 = TOP;
1012 CHECK_NUMBER (v2);
1013 n = XINT (v2);
1014 immediate_quit = 1;
1015 while (--n >= 0 && CONSP (v1))
1016 v1 = XCDR (v1);
1017 immediate_quit = 0;
1018 TOP = CAR (v1);
1019 AFTER_POTENTIAL_GC ();
1020 break;
1021 }
1022
1023 case Bsymbolp:
1024 TOP = SYMBOLP (TOP) ? Qt : Qnil;
1025 break;
1026
1027 case Bconsp:
1028 TOP = CONSP (TOP) ? Qt : Qnil;
1029 break;
1030
1031 case Bstringp:
1032 TOP = STRINGP (TOP) ? Qt : Qnil;
1033 break;
1034
1035 case Blistp:
1036 TOP = CONSP (TOP) || NILP (TOP) ? Qt : Qnil;
1037 break;
1038
1039 case Bnot:
1040 TOP = NILP (TOP) ? Qt : Qnil;
1041 break;
1042
1043 case Bcons:
1044 {
1045 Lisp_Object v1;
1046 v1 = POP;
1047 TOP = Fcons (TOP, v1);
1048 break;
1049 }
1050
1051 case Blist1:
1052 TOP = Fcons (TOP, Qnil);
1053 break;
1054
1055 case Blist2:
1056 {
1057 Lisp_Object v1;
1058 v1 = POP;
1059 TOP = Fcons (TOP, Fcons (v1, Qnil));
1060 break;
1061 }
1062
1063 case Blist3:
1064 DISCARD (2);
1065 TOP = Flist (3, &TOP);
1066 break;
1067
1068 case Blist4:
1069 DISCARD (3);
1070 TOP = Flist (4, &TOP);
1071 break;
1072
1073 case BlistN:
1074 op = FETCH;
1075 DISCARD (op - 1);
1076 TOP = Flist (op, &TOP);
1077 break;
1078
1079 case Blength:
1080 BEFORE_POTENTIAL_GC ();
1081 TOP = Flength (TOP);
1082 AFTER_POTENTIAL_GC ();
1083 break;
1084
1085 case Baref:
1086 {
1087 Lisp_Object v1;
1088 BEFORE_POTENTIAL_GC ();
1089 v1 = POP;
1090 TOP = Faref (TOP, v1);
1091 AFTER_POTENTIAL_GC ();
1092 break;
1093 }
1094
1095 case Baset:
1096 {
1097 Lisp_Object v1, v2;
1098 BEFORE_POTENTIAL_GC ();
1099 v2 = POP; v1 = POP;
1100 TOP = Faset (TOP, v1, v2);
1101 AFTER_POTENTIAL_GC ();
1102 break;
1103 }
1104
1105 case Bsymbol_value:
1106 BEFORE_POTENTIAL_GC ();
1107 TOP = Fsymbol_value (TOP);
1108 AFTER_POTENTIAL_GC ();
1109 break;
1110
1111 case Bsymbol_function:
1112 BEFORE_POTENTIAL_GC ();
1113 TOP = Fsymbol_function (TOP);
1114 AFTER_POTENTIAL_GC ();
1115 break;
1116
1117 case Bset:
1118 {
1119 Lisp_Object v1;
1120 BEFORE_POTENTIAL_GC ();
1121 v1 = POP;
1122 TOP = Fset (TOP, v1);
1123 AFTER_POTENTIAL_GC ();
1124 break;
1125 }
1126
1127 case Bfset:
1128 {
1129 Lisp_Object v1;
1130 BEFORE_POTENTIAL_GC ();
1131 v1 = POP;
1132 TOP = Ffset (TOP, v1);
1133 AFTER_POTENTIAL_GC ();
1134 break;
1135 }
1136
1137 case Bget:
1138 {
1139 Lisp_Object v1;
1140 BEFORE_POTENTIAL_GC ();
1141 v1 = POP;
1142 TOP = Fget (TOP, v1);
1143 AFTER_POTENTIAL_GC ();
1144 break;
1145 }
1146
1147 case Bsubstring:
1148 {
1149 Lisp_Object v1, v2;
1150 BEFORE_POTENTIAL_GC ();
1151 v2 = POP; v1 = POP;
1152 TOP = Fsubstring (TOP, v1, v2);
1153 AFTER_POTENTIAL_GC ();
1154 break;
1155 }
1156
1157 case Bconcat2:
1158 BEFORE_POTENTIAL_GC ();
1159 DISCARD (1);
1160 TOP = Fconcat (2, &TOP);
1161 AFTER_POTENTIAL_GC ();
1162 break;
1163
1164 case Bconcat3:
1165 BEFORE_POTENTIAL_GC ();
1166 DISCARD (2);
1167 TOP = Fconcat (3, &TOP);
1168 AFTER_POTENTIAL_GC ();
1169 break;
1170
1171 case Bconcat4:
1172 BEFORE_POTENTIAL_GC ();
1173 DISCARD (3);
1174 TOP = Fconcat (4, &TOP);
1175 AFTER_POTENTIAL_GC ();
1176 break;
1177
1178 case BconcatN:
1179 op = FETCH;
1180 BEFORE_POTENTIAL_GC ();
1181 DISCARD (op - 1);
1182 TOP = Fconcat (op, &TOP);
1183 AFTER_POTENTIAL_GC ();
1184 break;
1185
1186 case Bsub1:
1187 {
1188 Lisp_Object v1;
1189 v1 = TOP;
1190 if (INTEGERP (v1))
1191 {
1192 XSETINT (v1, XINT (v1) - 1);
1193 TOP = v1;
1194 }
1195 else
1196 {
1197 BEFORE_POTENTIAL_GC ();
1198 TOP = Fsub1 (v1);
1199 AFTER_POTENTIAL_GC ();
1200 }
1201 break;
1202 }
1203
1204 case Badd1:
1205 {
1206 Lisp_Object v1;
1207 v1 = TOP;
1208 if (INTEGERP (v1))
1209 {
1210 XSETINT (v1, XINT (v1) + 1);
1211 TOP = v1;
1212 }
1213 else
1214 {
1215 BEFORE_POTENTIAL_GC ();
1216 TOP = Fadd1 (v1);
1217 AFTER_POTENTIAL_GC ();
1218 }
1219 break;
1220 }
1221
1222 case Beqlsign:
1223 {
1224 Lisp_Object v1, v2;
1225 BEFORE_POTENTIAL_GC ();
1226 v2 = POP; v1 = TOP;
1227 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1);
1228 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2);
1229 AFTER_POTENTIAL_GC ();
1230 if (FLOATP (v1) || FLOATP (v2))
1231 {
1232 double f1, f2;
1233
1234 f1 = (FLOATP (v1) ? XFLOAT_DATA (v1) : XINT (v1));
1235 f2 = (FLOATP (v2) ? XFLOAT_DATA (v2) : XINT (v2));
1236 TOP = (f1 == f2 ? Qt : Qnil);
1237 }
1238 else
1239 TOP = (XINT (v1) == XINT (v2) ? Qt : Qnil);
1240 break;
1241 }
1242
1243 case Bgtr:
1244 {
1245 Lisp_Object v1;
1246 BEFORE_POTENTIAL_GC ();
1247 v1 = POP;
1248 TOP = Fgtr (TOP, v1);
1249 AFTER_POTENTIAL_GC ();
1250 break;
1251 }
1252
1253 case Blss:
1254 {
1255 Lisp_Object v1;
1256 BEFORE_POTENTIAL_GC ();
1257 v1 = POP;
1258 TOP = Flss (TOP, v1);
1259 AFTER_POTENTIAL_GC ();
1260 break;
1261 }
1262
1263 case Bleq:
1264 {
1265 Lisp_Object v1;
1266 BEFORE_POTENTIAL_GC ();
1267 v1 = POP;
1268 TOP = Fleq (TOP, v1);
1269 AFTER_POTENTIAL_GC ();
1270 break;
1271 }
1272
1273 case Bgeq:
1274 {
1275 Lisp_Object v1;
1276 BEFORE_POTENTIAL_GC ();
1277 v1 = POP;
1278 TOP = Fgeq (TOP, v1);
1279 AFTER_POTENTIAL_GC ();
1280 break;
1281 }
1282
1283 case Bdiff:
1284 BEFORE_POTENTIAL_GC ();
1285 DISCARD (1);
1286 TOP = Fminus (2, &TOP);
1287 AFTER_POTENTIAL_GC ();
1288 break;
1289
1290 case Bnegate:
1291 {
1292 Lisp_Object v1;
1293 v1 = TOP;
1294 if (INTEGERP (v1))
1295 {
1296 XSETINT (v1, - XINT (v1));
1297 TOP = v1;
1298 }
1299 else
1300 {
1301 BEFORE_POTENTIAL_GC ();
1302 TOP = Fminus (1, &TOP);
1303 AFTER_POTENTIAL_GC ();
1304 }
1305 break;
1306 }
1307
1308 case Bplus:
1309 BEFORE_POTENTIAL_GC ();
1310 DISCARD (1);
1311 TOP = Fplus (2, &TOP);
1312 AFTER_POTENTIAL_GC ();
1313 break;
1314
1315 case Bmax:
1316 BEFORE_POTENTIAL_GC ();
1317 DISCARD (1);
1318 TOP = Fmax (2, &TOP);
1319 AFTER_POTENTIAL_GC ();
1320 break;
1321
1322 case Bmin:
1323 BEFORE_POTENTIAL_GC ();
1324 DISCARD (1);
1325 TOP = Fmin (2, &TOP);
1326 AFTER_POTENTIAL_GC ();
1327 break;
1328
1329 case Bmult:
1330 BEFORE_POTENTIAL_GC ();
1331 DISCARD (1);
1332 TOP = Ftimes (2, &TOP);
1333 AFTER_POTENTIAL_GC ();
1334 break;
1335
1336 case Bquo:
1337 BEFORE_POTENTIAL_GC ();
1338 DISCARD (1);
1339 TOP = Fquo (2, &TOP);
1340 AFTER_POTENTIAL_GC ();
1341 break;
1342
1343 case Brem:
1344 {
1345 Lisp_Object v1;
1346 BEFORE_POTENTIAL_GC ();
1347 v1 = POP;
1348 TOP = Frem (TOP, v1);
1349 AFTER_POTENTIAL_GC ();
1350 break;
1351 }
1352
1353 case Bpoint:
1354 {
1355 Lisp_Object v1;
1356 XSETFASTINT (v1, PT);
1357 PUSH (v1);
1358 break;
1359 }
1360
1361 case Bgoto_char:
1362 BEFORE_POTENTIAL_GC ();
1363 TOP = Fgoto_char (TOP);
1364 AFTER_POTENTIAL_GC ();
1365 break;
1366
1367 case Binsert:
1368 BEFORE_POTENTIAL_GC ();
1369 TOP = Finsert (1, &TOP);
1370 AFTER_POTENTIAL_GC ();
1371 break;
1372
1373 case BinsertN:
1374 op = FETCH;
1375 BEFORE_POTENTIAL_GC ();
1376 DISCARD (op - 1);
1377 TOP = Finsert (op, &TOP);
1378 AFTER_POTENTIAL_GC ();
1379 break;
1380
1381 case Bpoint_max:
1382 {
1383 Lisp_Object v1;
1384 XSETFASTINT (v1, ZV);
1385 PUSH (v1);
1386 break;
1387 }
1388
1389 case Bpoint_min:
1390 {
1391 Lisp_Object v1;
1392 XSETFASTINT (v1, BEGV);
1393 PUSH (v1);
1394 break;
1395 }
1396
1397 case Bchar_after:
1398 BEFORE_POTENTIAL_GC ();
1399 TOP = Fchar_after (TOP);
1400 AFTER_POTENTIAL_GC ();
1401 break;
1402
1403 case Bfollowing_char:
1404 {
1405 Lisp_Object v1;
1406 BEFORE_POTENTIAL_GC ();
1407 v1 = Ffollowing_char ();
1408 AFTER_POTENTIAL_GC ();
1409 PUSH (v1);
1410 break;
1411 }
1412
1413 case Bpreceding_char:
1414 {
1415 Lisp_Object v1;
1416 BEFORE_POTENTIAL_GC ();
1417 v1 = Fprevious_char ();
1418 AFTER_POTENTIAL_GC ();
1419 PUSH (v1);
1420 break;
1421 }
1422
1423 case Bcurrent_column:
1424 {
1425 Lisp_Object v1;
1426 BEFORE_POTENTIAL_GC ();
1427 XSETFASTINT (v1, current_column ());
1428 AFTER_POTENTIAL_GC ();
1429 PUSH (v1);
1430 break;
1431 }
1432
1433 case Bindent_to:
1434 BEFORE_POTENTIAL_GC ();
1435 TOP = Findent_to (TOP, Qnil);
1436 AFTER_POTENTIAL_GC ();
1437 break;
1438
1439 case Beolp:
1440 PUSH (Feolp ());
1441 break;
1442
1443 case Beobp:
1444 PUSH (Feobp ());
1445 break;
1446
1447 case Bbolp:
1448 PUSH (Fbolp ());
1449 break;
1450
1451 case Bbobp:
1452 PUSH (Fbobp ());
1453 break;
1454
1455 case Bcurrent_buffer:
1456 PUSH (Fcurrent_buffer ());
1457 break;
1458
1459 case Bset_buffer:
1460 BEFORE_POTENTIAL_GC ();
1461 TOP = Fset_buffer (TOP);
1462 AFTER_POTENTIAL_GC ();
1463 break;
1464
1465 case Binteractive_p: /* Obsolete since 24.1. */
1466 PUSH (Finteractive_p ());
1467 break;
1468
1469 case Bforward_char:
1470 BEFORE_POTENTIAL_GC ();
1471 TOP = Fforward_char (TOP);
1472 AFTER_POTENTIAL_GC ();
1473 break;
1474
1475 case Bforward_word:
1476 BEFORE_POTENTIAL_GC ();
1477 TOP = Fforward_word (TOP);
1478 AFTER_POTENTIAL_GC ();
1479 break;
1480
1481 case Bskip_chars_forward:
1482 {
1483 Lisp_Object v1;
1484 BEFORE_POTENTIAL_GC ();
1485 v1 = POP;
1486 TOP = Fskip_chars_forward (TOP, v1);
1487 AFTER_POTENTIAL_GC ();
1488 break;
1489 }
1490
1491 case Bskip_chars_backward:
1492 {
1493 Lisp_Object v1;
1494 BEFORE_POTENTIAL_GC ();
1495 v1 = POP;
1496 TOP = Fskip_chars_backward (TOP, v1);
1497 AFTER_POTENTIAL_GC ();
1498 break;
1499 }
1500
1501 case Bforward_line:
1502 BEFORE_POTENTIAL_GC ();
1503 TOP = Fforward_line (TOP);
1504 AFTER_POTENTIAL_GC ();
1505 break;
1506
1507 case Bchar_syntax:
1508 {
1509 int c;
1510
1511 BEFORE_POTENTIAL_GC ();
1512 CHECK_CHARACTER (TOP);
1513 AFTER_POTENTIAL_GC ();
1514 c = XFASTINT (TOP);
1515 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
1516 MAKE_CHAR_MULTIBYTE (c);
1517 XSETFASTINT (TOP, syntax_code_spec[(int) SYNTAX (c)]);
1518 }
1519 break;
1520
1521 case Bbuffer_substring:
1522 {
1523 Lisp_Object v1;
1524 BEFORE_POTENTIAL_GC ();
1525 v1 = POP;
1526 TOP = Fbuffer_substring (TOP, v1);
1527 AFTER_POTENTIAL_GC ();
1528 break;
1529 }
1530
1531 case Bdelete_region:
1532 {
1533 Lisp_Object v1;
1534 BEFORE_POTENTIAL_GC ();
1535 v1 = POP;
1536 TOP = Fdelete_region (TOP, v1);
1537 AFTER_POTENTIAL_GC ();
1538 break;
1539 }
1540
1541 case Bnarrow_to_region:
1542 {
1543 Lisp_Object v1;
1544 BEFORE_POTENTIAL_GC ();
1545 v1 = POP;
1546 TOP = Fnarrow_to_region (TOP, v1);
1547 AFTER_POTENTIAL_GC ();
1548 break;
1549 }
1550
1551 case Bwiden:
1552 BEFORE_POTENTIAL_GC ();
1553 PUSH (Fwiden ());
1554 AFTER_POTENTIAL_GC ();
1555 break;
1556
1557 case Bend_of_line:
1558 BEFORE_POTENTIAL_GC ();
1559 TOP = Fend_of_line (TOP);
1560 AFTER_POTENTIAL_GC ();
1561 break;
1562
1563 case Bset_marker:
1564 {
1565 Lisp_Object v1, v2;
1566 BEFORE_POTENTIAL_GC ();
1567 v1 = POP;
1568 v2 = POP;
1569 TOP = Fset_marker (TOP, v2, v1);
1570 AFTER_POTENTIAL_GC ();
1571 break;
1572 }
1573
1574 case Bmatch_beginning:
1575 BEFORE_POTENTIAL_GC ();
1576 TOP = Fmatch_beginning (TOP);
1577 AFTER_POTENTIAL_GC ();
1578 break;
1579
1580 case Bmatch_end:
1581 BEFORE_POTENTIAL_GC ();
1582 TOP = Fmatch_end (TOP);
1583 AFTER_POTENTIAL_GC ();
1584 break;
1585
1586 case Bupcase:
1587 BEFORE_POTENTIAL_GC ();
1588 TOP = Fupcase (TOP);
1589 AFTER_POTENTIAL_GC ();
1590 break;
1591
1592 case Bdowncase:
1593 BEFORE_POTENTIAL_GC ();
1594 TOP = Fdowncase (TOP);
1595 AFTER_POTENTIAL_GC ();
1596 break;
1597
1598 case Bstringeqlsign:
1599 {
1600 Lisp_Object v1;
1601 BEFORE_POTENTIAL_GC ();
1602 v1 = POP;
1603 TOP = Fstring_equal (TOP, v1);
1604 AFTER_POTENTIAL_GC ();
1605 break;
1606 }
1607
1608 case Bstringlss:
1609 {
1610 Lisp_Object v1;
1611 BEFORE_POTENTIAL_GC ();
1612 v1 = POP;
1613 TOP = Fstring_lessp (TOP, v1);
1614 AFTER_POTENTIAL_GC ();
1615 break;
1616 }
1617
1618 case Bequal:
1619 {
1620 Lisp_Object v1;
1621 v1 = POP;
1622 TOP = Fequal (TOP, v1);
1623 break;
1624 }
1625
1626 case Bnthcdr:
1627 {
1628 Lisp_Object v1;
1629 BEFORE_POTENTIAL_GC ();
1630 v1 = POP;
1631 TOP = Fnthcdr (TOP, v1);
1632 AFTER_POTENTIAL_GC ();
1633 break;
1634 }
1635
1636 case Belt:
1637 {
1638 Lisp_Object v1, v2;
1639 if (CONSP (TOP))
1640 {
1641 /* Exchange args and then do nth. */
1642 EMACS_INT n;
1643 BEFORE_POTENTIAL_GC ();
1644 v2 = POP;
1645 v1 = TOP;
1646 CHECK_NUMBER (v2);
1647 AFTER_POTENTIAL_GC ();
1648 n = XINT (v2);
1649 immediate_quit = 1;
1650 while (--n >= 0 && CONSP (v1))
1651 v1 = XCDR (v1);
1652 immediate_quit = 0;
1653 TOP = CAR (v1);
1654 }
1655 else
1656 {
1657 BEFORE_POTENTIAL_GC ();
1658 v1 = POP;
1659 TOP = Felt (TOP, v1);
1660 AFTER_POTENTIAL_GC ();
1661 }
1662 break;
1663 }
1664
1665 case Bmember:
1666 {
1667 Lisp_Object v1;
1668 BEFORE_POTENTIAL_GC ();
1669 v1 = POP;
1670 TOP = Fmember (TOP, v1);
1671 AFTER_POTENTIAL_GC ();
1672 break;
1673 }
1674
1675 case Bassq:
1676 {
1677 Lisp_Object v1;
1678 BEFORE_POTENTIAL_GC ();
1679 v1 = POP;
1680 TOP = Fassq (TOP, v1);
1681 AFTER_POTENTIAL_GC ();
1682 break;
1683 }
1684
1685 case Bnreverse:
1686 BEFORE_POTENTIAL_GC ();
1687 TOP = Fnreverse (TOP);
1688 AFTER_POTENTIAL_GC ();
1689 break;
1690
1691 case Bsetcar:
1692 {
1693 Lisp_Object v1;
1694 BEFORE_POTENTIAL_GC ();
1695 v1 = POP;
1696 TOP = Fsetcar (TOP, v1);
1697 AFTER_POTENTIAL_GC ();
1698 break;
1699 }
1700
1701 case Bsetcdr:
1702 {
1703 Lisp_Object v1;
1704 BEFORE_POTENTIAL_GC ();
1705 v1 = POP;
1706 TOP = Fsetcdr (TOP, v1);
1707 AFTER_POTENTIAL_GC ();
1708 break;
1709 }
1710
1711 case Bcar_safe:
1712 {
1713 Lisp_Object v1;
1714 v1 = TOP;
1715 TOP = CAR_SAFE (v1);
1716 break;
1717 }
1718
1719 case Bcdr_safe:
1720 {
1721 Lisp_Object v1;
1722 v1 = TOP;
1723 TOP = CDR_SAFE (v1);
1724 break;
1725 }
1726
1727 case Bnconc:
1728 BEFORE_POTENTIAL_GC ();
1729 DISCARD (1);
1730 TOP = Fnconc (2, &TOP);
1731 AFTER_POTENTIAL_GC ();
1732 break;
1733
1734 case Bnumberp:
1735 TOP = (NUMBERP (TOP) ? Qt : Qnil);
1736 break;
1737
1738 case Bintegerp:
1739 TOP = INTEGERP (TOP) ? Qt : Qnil;
1740 break;
1741
1742 #ifdef BYTE_CODE_SAFE
1743 case Bset_mark:
1744 BEFORE_POTENTIAL_GC ();
1745 error ("set-mark is an obsolete bytecode");
1746 AFTER_POTENTIAL_GC ();
1747 break;
1748 case Bscan_buffer:
1749 BEFORE_POTENTIAL_GC ();
1750 error ("scan-buffer is an obsolete bytecode");
1751 AFTER_POTENTIAL_GC ();
1752 break;
1753 #endif
1754
1755 case 0:
1756 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1757 for that instead. */
1758 /* case Bstack_ref: */
1759 abort ();
1760
1761 /* Handy byte-codes for lexical binding. */
1762 case Bstack_ref+1:
1763 case Bstack_ref+2:
1764 case Bstack_ref+3:
1765 case Bstack_ref+4:
1766 case Bstack_ref+5:
1767 {
1768 Lisp_Object *ptr = top - (op - Bstack_ref);
1769 PUSH (*ptr);
1770 break;
1771 }
1772 case Bstack_ref+6:
1773 {
1774 Lisp_Object *ptr = top - (FETCH);
1775 PUSH (*ptr);
1776 break;
1777 }
1778 case Bstack_ref+7:
1779 {
1780 Lisp_Object *ptr = top - (FETCH2);
1781 PUSH (*ptr);
1782 break;
1783 }
1784 case Bstack_set:
1785 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
1786 {
1787 Lisp_Object *ptr = top - (FETCH);
1788 *ptr = POP;
1789 break;
1790 }
1791 case Bstack_set2:
1792 {
1793 Lisp_Object *ptr = top - (FETCH2);
1794 *ptr = POP;
1795 break;
1796 }
1797 case BdiscardN:
1798 op = FETCH;
1799 if (op & 0x80)
1800 {
1801 op &= 0x7F;
1802 top[-op] = TOP;
1803 }
1804 DISCARD (op);
1805 break;
1806
1807 case 255:
1808 default:
1809 #ifdef BYTE_CODE_SAFE
1810 if (op < Bconstant)
1811 {
1812 abort ();
1813 }
1814 if ((op -= Bconstant) >= const_length)
1815 {
1816 abort ();
1817 }
1818 PUSH (vectorp[op]);
1819 #else
1820 PUSH (vectorp[op - Bconstant]);
1821 #endif
1822 }
1823 }
1824
1825 exit:
1826
1827 byte_stack_list = byte_stack_list->next;
1828
1829 /* Binds and unbinds are supposed to be compiled balanced. */
1830 if (SPECPDL_INDEX () != count)
1831 #ifdef BYTE_CODE_SAFE
1832 error ("binding stack not balanced (serious byte compiler bug)");
1833 #else
1834 abort ();
1835 #endif
1836
1837 return result;
1838 }
1839
1840 void
1841 syms_of_bytecode (void)
1842 {
1843 DEFSYM (Qbytecode, "byte-code");
1844
1845 defsubr (&Sbyte_code);
1846
1847 #ifdef BYTE_CODE_METER
1848
1849 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter,
1850 doc: /* A vector of vectors which holds a histogram of byte-code usage.
1851 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1852 opcode CODE has been executed.
1853 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1854 indicates how many times the byte opcodes CODE1 and CODE2 have been
1855 executed in succession. */);
1856
1857 DEFVAR_BOOL ("byte-metering-on", byte_metering_on,
1858 doc: /* If non-nil, keep profiling information on byte code usage.
1859 The variable byte-code-meter indicates how often each byte opcode is used.
1860 If a symbol has a property named `byte-code-meter' whose value is an
1861 integer, it is incremented each time that symbol's function is called. */);
1862
1863 byte_metering_on = 0;
1864 Vbyte_code_meter = Fmake_vector (make_number (256), make_number (0));
1865 DEFSYM (Qbyte_code_meter, "byte-code-meter");
1866 {
1867 int i = 256;
1868 while (i--)
1869 XVECTOR (Vbyte_code_meter)->contents[i] =
1870 Fmake_vector (make_number (256), make_number (0));
1871 }
1872 #endif
1873 }