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