Merge from trunk
[emacs.git] / src / bytecode.c
blobd94b19b2d07c659d5445a0f97e19de72c83a42c4
1 /* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993, 2000, 2001, 2002, 2003, 2004,
3 2005, 2006, 2007, 2008, 2009, 2010 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 hacked on by jwz@lucid.com 17-jun-91
22 o added a compile-time switch to turn on simple sanity checking;
23 o put back the obsolete byte-codes for error-detection;
24 o added a new instruction, unbind_all, which I will use for
25 tail-recursion elimination;
26 o made temp_output_buffer_show be called with the right number
27 of args;
28 o made the new bytecodes be called with args in the right order;
29 o added metering support.
31 by Hallvard:
32 o added relative jump instructions;
33 o all conditionals now only do QUIT if they jump.
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"
44 #ifdef CHECK_FRAME_FONT
45 #include "frame.h"
46 #include "xterm.h"
47 #endif
50 * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for
51 * debugging the byte compiler...)
53 * define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
55 /* #define BYTE_CODE_SAFE */
56 /* #define BYTE_CODE_METER */
59 #ifdef BYTE_CODE_METER
61 Lisp_Object Vbyte_code_meter, Qbyte_code_meter;
62 int byte_metering_on;
64 #define METER_2(code1, code2) \
65 XFASTINT (XVECTOR (XVECTOR (Vbyte_code_meter)->contents[(code1)]) \
66 ->contents[(code2)])
68 #define METER_1(code) METER_2 (0, (code))
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 } \
82 #else /* no BYTE_CODE_METER */
84 #define METER_CODE(last_code, this_code)
86 #endif /* no BYTE_CODE_METER */
89 Lisp_Object Qbytecode;
90 extern Lisp_Object Qand_optional, Qand_rest;
92 /* Byte codes: */
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
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
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 */
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
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
188 #define Bsave_excursion 0212
189 #define Bsave_window_excursion 0213
190 #define Bsave_restriction 0214
191 #define Bcatch 0215
193 #define Bunwind_protect 0216
194 #define Bcondition_case 0217
195 #define Btemp_output_buffer_setup 0220
196 #define Btemp_output_buffer_show 0221
198 #define Bunbind_all 0222
200 #define Bset_marker 0223
201 #define Bmatch_beginning 0224
202 #define Bmatch_end 0225
203 #define Bupcase 0226
204 #define Bdowncase 0227
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
224 #define BRgoto 0252
225 #define BRgotoifnil 0253
226 #define BRgotoifnonnil 0254
227 #define BRgotoifnilelsepop 0255
228 #define BRgotoifnonnilelsepop 0256
230 #define BlistN 0257
231 #define BconcatN 0260
232 #define BinsertN 0261
234 /* Bstack_ref is code 0. */
235 #define Bstack_set 0262
236 #define Bstack_set2 0263
237 #define Bvec_ref 0264
238 #define Bvec_set 0265
239 #define BdiscardN 0266
241 #define Bconstant 0300
242 #define CONSTANTLIM 0100
245 /* Structure describing a value stack used during byte-code execution
246 in Fbyte_code. */
248 struct byte_stack
250 /* Program counter. This points into the byte_string below
251 and is relocated when that string is relocated. */
252 const unsigned char *pc;
254 /* Top and bottom of stack. The bottom points to an area of memory
255 allocated with alloca in Fbyte_code. */
256 Lisp_Object *top, *bottom;
258 /* The string containing the byte-code, and its current address.
259 Storing this here protects it from GC because mark_byte_stack
260 marks it. */
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
276 gcprolist. */
278 struct byte_stack *byte_stack_list;
281 /* Mark objects on byte_stack_list. Called during GC. */
283 void
284 mark_byte_stack (void)
286 struct byte_stack *stack;
287 Lisp_Object *obj;
289 for (stack = byte_stack_list; stack; stack = stack->next)
291 /* If STACK->top is null here, this means there's an opcode in
292 Fbyte_code that wasn't expected to GC, but did. To find out
293 which opcode this is, record the value of `stack', and walk
294 up the stack in a debugger, stopping in frames of Fbyte_code.
295 The culprit is found in the frame of Fbyte_code where the
296 address of its local variable `stack' is equal to the
297 recorded value of `stack' here. */
298 eassert (stack->top);
300 for (obj = stack->bottom; obj <= stack->top; ++obj)
301 mark_object (*obj);
303 mark_object (stack->byte_string);
304 mark_object (stack->constants);
309 /* Unmark objects in the stacks on byte_stack_list. Relocate program
310 counters. Called when GC has completed. */
312 void
313 unmark_byte_stack (void)
315 struct byte_stack *stack;
317 for (stack = byte_stack_list; stack; stack = stack->next)
319 if (stack->byte_string_start != SDATA (stack->byte_string))
321 int offset = stack->pc - stack->byte_string_start;
322 stack->byte_string_start = SDATA (stack->byte_string);
323 stack->pc = stack->byte_string_start + offset;
329 /* Fetch the next byte from the bytecode stream */
331 #define FETCH *stack.pc++
333 /* Fetch two bytes from the bytecode stream and make a 16-bit number
334 out of them */
336 #define FETCH2 (op = FETCH, op + (FETCH << 8))
338 /* Push x onto the execution stack. This used to be #define PUSH(x)
339 (*++stackp = (x)) This oddity is necessary because Alliant can't be
340 bothered to compile the preincrement operator properly, as of 4/91.
341 -JimB */
343 #define PUSH(x) (top++, *top = (x))
345 /* Pop a value off the execution stack. */
347 #define POP (*top--)
349 /* Discard n values from the execution stack. */
351 #define DISCARD(n) (top -= (n))
353 /* Get the value which is at the top of the execution stack, but don't
354 pop it. */
356 #define TOP (*top)
358 /* Actions that must be performed before and after calling a function
359 that might GC. */
361 #define BEFORE_POTENTIAL_GC() stack.top = top
362 #define AFTER_POTENTIAL_GC() stack.top = NULL
364 /* Garbage collect if we have consed enough since the last time.
365 We do this at every branch, to avoid loops that never GC. */
367 #define MAYBE_GC() \
368 if (consing_since_gc > gc_cons_threshold \
369 && consing_since_gc > gc_relative_threshold) \
371 BEFORE_POTENTIAL_GC (); \
372 Fgarbage_collect (); \
373 AFTER_POTENTIAL_GC (); \
375 else
377 /* Check for jumping out of range. */
379 #ifdef BYTE_CODE_SAFE
381 #define CHECK_RANGE(ARG) \
382 if (ARG >= bytestr_length) abort ()
384 #else /* not BYTE_CODE_SAFE */
386 #define CHECK_RANGE(ARG)
388 #endif /* not BYTE_CODE_SAFE */
390 /* A version of the QUIT macro which makes sure that the stack top is
391 set before signaling `quit'. */
393 #define BYTE_CODE_QUIT \
394 do { \
395 if (!NILP (Vquit_flag) && NILP (Vinhibit_quit)) \
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 (); \
405 ELSE_PENDING_SIGNALS \
406 } while (0)
409 DEFUN ("byte-code", Fbyte_code, Sbyte_code, 3, MANY, 0,
410 doc: /* Function used internally in byte-compiled code.
411 The first argument, BYTESTR, is a string of byte code;
412 the second, VECTOR, a vector of constants;
413 the third, MAXDEPTH, the maximum stack depth used in this function.
414 If the third argument is incorrect, Emacs may crash.
416 If ARGS-TEMPLATE is specified, it is an argument list specification,
417 according to which any remaining arguments are pushed on the stack
418 before executing BYTESTR.
420 usage: (byte-code BYTESTR VECTOR MAXDEP &optional ARGS-TEMPLATE &rest ARGS) */)
421 (int nargs, Lisp_Object *args)
423 Lisp_Object args_tmpl = nargs >= 4 ? args[3] : Qnil;
424 int pnargs = nargs >= 4 ? nargs - 4 : 0;
425 Lisp_Object *pargs = nargs >= 4 ? args + 4 : 0;
426 return exec_byte_code (args[0], args[1], args[2], args_tmpl, pnargs, pargs);
429 /* Execute the byte-code in BYTESTR. VECTOR is the constant vector, and
430 MAXDEPTH is the maximum stack depth used (if MAXDEPTH is incorrect,
431 emacs may crash!). If ARGS_TEMPLATE is non-nil, it should be a lisp
432 argument list (including &rest, &optional, etc.), and ARGS, of size
433 NARGS, should be a vector of the actual arguments. The arguments in
434 ARGS are pushed on the stack according to ARGS_TEMPLATE before
435 executing BYTESTR. */
437 Lisp_Object
438 exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth,
439 Lisp_Object args_template, int nargs, Lisp_Object *args)
441 int count = SPECPDL_INDEX ();
442 #ifdef BYTE_CODE_METER
443 int this_op = 0;
444 int prev_op;
445 #endif
446 int op;
447 /* Lisp_Object v1, v2; */
448 Lisp_Object *vectorp;
449 #ifdef BYTE_CODE_SAFE
450 int const_length = XVECTOR (vector)->size;
451 Lisp_Object *stacke;
452 #endif
453 int bytestr_length;
454 struct byte_stack stack;
455 Lisp_Object *top;
456 Lisp_Object result;
458 #if 0 /* CHECK_FRAME_FONT */
460 struct frame *f = SELECTED_FRAME ();
461 if (FRAME_X_P (f)
462 && FRAME_FONT (f)->direction != 0
463 && FRAME_FONT (f)->direction != 1)
464 abort ();
466 #endif
468 CHECK_STRING (bytestr);
469 CHECK_VECTOR (vector);
470 CHECK_NUMBER (maxdepth);
472 if (STRING_MULTIBYTE (bytestr))
473 /* BYTESTR must have been produced by Emacs 20.2 or the earlier
474 because they produced a raw 8-bit string for byte-code and now
475 such a byte-code string is loaded as multibyte while raw 8-bit
476 characters converted to multibyte form. Thus, now we must
477 convert them back to the originally intended unibyte form. */
478 bytestr = Fstring_as_unibyte (bytestr);
480 bytestr_length = SBYTES (bytestr);
481 vectorp = XVECTOR (vector)->contents;
483 stack.byte_string = bytestr;
484 stack.pc = stack.byte_string_start = SDATA (bytestr);
485 stack.constants = vector;
486 stack.bottom = (Lisp_Object *) alloca (XFASTINT (maxdepth)
487 * sizeof (Lisp_Object));
488 top = stack.bottom - 1;
489 stack.top = NULL;
490 stack.next = byte_stack_list;
491 byte_stack_list = &stack;
493 #ifdef BYTE_CODE_SAFE
494 stacke = stack.bottom - 1 + XFASTINT (maxdepth);
495 #endif
497 if (! NILP (args_template))
498 /* We should push some arguments on the stack. */
500 Lisp_Object at;
501 int pushed = 0, optional = 0;
503 for (at = args_template; CONSP (at); at = XCDR (at))
504 if (EQ (XCAR (at), Qand_optional))
505 optional = 1;
506 else if (EQ (XCAR (at), Qand_rest))
508 PUSH (Flist (nargs, args));
509 pushed = nargs;
510 at = Qnil;
511 break;
513 else if (pushed < nargs)
515 PUSH (*args++);
516 pushed++;
518 else if (optional)
519 PUSH (Qnil);
520 else
521 break;
523 if (pushed != nargs || !NILP (at))
524 Fsignal (Qwrong_number_of_arguments,
525 Fcons (args_template, Fcons (make_number (nargs), Qnil)));
528 while (1)
530 #ifdef BYTE_CODE_SAFE
531 if (top > stacke)
532 abort ();
533 else if (top < stack.bottom - 1)
534 abort ();
535 #endif
537 #ifdef BYTE_CODE_METER
538 prev_op = this_op;
539 this_op = op = FETCH;
540 METER_CODE (prev_op, op);
541 #else
542 op = FETCH;
543 #endif
545 switch (op)
547 case Bvarref + 7:
548 op = FETCH2;
549 goto varref;
551 case Bvarref:
552 case Bvarref + 1:
553 case Bvarref + 2:
554 case Bvarref + 3:
555 case Bvarref + 4:
556 case Bvarref + 5:
557 op = op - Bvarref;
558 goto varref;
560 /* This seems to be the most frequently executed byte-code
561 among the Bvarref's, so avoid a goto here. */
562 case Bvarref+6:
563 op = FETCH;
564 varref:
566 Lisp_Object v1, v2;
568 v1 = vectorp[op];
569 if (SYMBOLP (v1))
571 if (XSYMBOL (v1)->redirect != SYMBOL_PLAINVAL
572 || (v2 = SYMBOL_VAL (XSYMBOL (v1)),
573 EQ (v2, Qunbound)))
575 BEFORE_POTENTIAL_GC ();
576 v2 = Fsymbol_value (v1);
577 AFTER_POTENTIAL_GC ();
580 else
582 BEFORE_POTENTIAL_GC ();
583 v2 = Fsymbol_value (v1);
584 AFTER_POTENTIAL_GC ();
586 PUSH (v2);
587 break;
590 case Bgotoifnil:
592 Lisp_Object v1;
593 MAYBE_GC ();
594 op = FETCH2;
595 v1 = POP;
596 if (NILP (v1))
598 BYTE_CODE_QUIT;
599 CHECK_RANGE (op);
600 stack.pc = stack.byte_string_start + op;
602 break;
605 case Bcar:
607 Lisp_Object v1;
608 v1 = TOP;
609 TOP = CAR (v1);
610 break;
613 case Beq:
615 Lisp_Object v1;
616 v1 = POP;
617 TOP = EQ (v1, TOP) ? Qt : Qnil;
618 break;
621 case Bmemq:
623 Lisp_Object v1;
624 BEFORE_POTENTIAL_GC ();
625 v1 = POP;
626 TOP = Fmemq (TOP, v1);
627 AFTER_POTENTIAL_GC ();
628 break;
631 case Bcdr:
633 Lisp_Object v1;
634 v1 = TOP;
635 TOP = CDR (v1);
636 break;
639 case Bvarset:
640 case Bvarset+1:
641 case Bvarset+2:
642 case Bvarset+3:
643 case Bvarset+4:
644 case Bvarset+5:
645 op -= Bvarset;
646 goto varset;
648 case Bvarset+7:
649 op = FETCH2;
650 goto varset;
652 case Bvarset+6:
653 op = FETCH;
654 varset:
656 Lisp_Object sym, val;
658 sym = vectorp[op];
659 val = TOP;
661 /* Inline the most common case. */
662 if (SYMBOLP (sym)
663 && !EQ (val, Qunbound)
664 && !XSYMBOL (sym)->redirect
665 && !SYMBOL_CONSTANT_P (sym))
666 XSYMBOL (sym)->val.value = val;
667 else
669 BEFORE_POTENTIAL_GC ();
670 set_internal (sym, val, Qnil, 0);
671 AFTER_POTENTIAL_GC ();
674 (void) POP;
675 break;
677 case Bdup:
679 Lisp_Object v1;
680 v1 = TOP;
681 PUSH (v1);
682 break;
685 /* ------------------ */
687 case Bvarbind+6:
688 op = FETCH;
689 goto varbind;
691 case Bvarbind+7:
692 op = FETCH2;
693 goto varbind;
695 case Bvarbind:
696 case Bvarbind+1:
697 case Bvarbind+2:
698 case Bvarbind+3:
699 case Bvarbind+4:
700 case Bvarbind+5:
701 op -= Bvarbind;
702 varbind:
703 /* Specbind can signal and thus GC. */
704 BEFORE_POTENTIAL_GC ();
705 specbind (vectorp[op], POP);
706 AFTER_POTENTIAL_GC ();
707 break;
709 case Bcall+6:
710 op = FETCH;
711 goto docall;
713 case Bcall+7:
714 op = FETCH2;
715 goto docall;
717 case Bcall:
718 case Bcall+1:
719 case Bcall+2:
720 case Bcall+3:
721 case Bcall+4:
722 case Bcall+5:
723 op -= Bcall;
724 docall:
726 BEFORE_POTENTIAL_GC ();
727 DISCARD (op);
728 #ifdef BYTE_CODE_METER
729 if (byte_metering_on && SYMBOLP (TOP))
731 Lisp_Object v1, v2;
733 v1 = TOP;
734 v2 = Fget (v1, Qbyte_code_meter);
735 if (INTEGERP (v2)
736 && XINT (v2) < MOST_POSITIVE_FIXNUM)
738 XSETINT (v2, XINT (v2) + 1);
739 Fput (v1, Qbyte_code_meter, v2);
742 #endif
743 TOP = Ffuncall (op + 1, &TOP);
744 AFTER_POTENTIAL_GC ();
745 break;
748 case Bunbind+6:
749 op = FETCH;
750 goto dounbind;
752 case Bunbind+7:
753 op = FETCH2;
754 goto dounbind;
756 case Bunbind:
757 case Bunbind+1:
758 case Bunbind+2:
759 case Bunbind+3:
760 case Bunbind+4:
761 case Bunbind+5:
762 op -= Bunbind;
763 dounbind:
764 BEFORE_POTENTIAL_GC ();
765 unbind_to (SPECPDL_INDEX () - op, Qnil);
766 AFTER_POTENTIAL_GC ();
767 break;
769 case Bunbind_all:
770 /* To unbind back to the beginning of this frame. Not used yet,
771 but will be needed for tail-recursion elimination. */
772 BEFORE_POTENTIAL_GC ();
773 unbind_to (count, Qnil);
774 AFTER_POTENTIAL_GC ();
775 break;
777 case Bgoto:
778 MAYBE_GC ();
779 BYTE_CODE_QUIT;
780 op = FETCH2; /* pc = FETCH2 loses since FETCH2 contains pc++ */
781 CHECK_RANGE (op);
782 stack.pc = stack.byte_string_start + op;
783 break;
785 case Bgotoifnonnil:
787 Lisp_Object v1;
788 MAYBE_GC ();
789 op = FETCH2;
790 v1 = POP;
791 if (!NILP (v1))
793 BYTE_CODE_QUIT;
794 CHECK_RANGE (op);
795 stack.pc = stack.byte_string_start + op;
797 break;
800 case Bgotoifnilelsepop:
801 MAYBE_GC ();
802 op = FETCH2;
803 if (NILP (TOP))
805 BYTE_CODE_QUIT;
806 CHECK_RANGE (op);
807 stack.pc = stack.byte_string_start + op;
809 else DISCARD (1);
810 break;
812 case Bgotoifnonnilelsepop:
813 MAYBE_GC ();
814 op = FETCH2;
815 if (!NILP (TOP))
817 BYTE_CODE_QUIT;
818 CHECK_RANGE (op);
819 stack.pc = stack.byte_string_start + op;
821 else DISCARD (1);
822 break;
824 case BRgoto:
825 MAYBE_GC ();
826 BYTE_CODE_QUIT;
827 stack.pc += (int) *stack.pc - 127;
828 break;
830 case BRgotoifnil:
832 Lisp_Object v1;
833 MAYBE_GC ();
834 v1 = POP;
835 if (NILP (v1))
837 BYTE_CODE_QUIT;
838 stack.pc += (int) *stack.pc - 128;
840 stack.pc++;
841 break;
844 case BRgotoifnonnil:
846 Lisp_Object v1;
847 MAYBE_GC ();
848 v1 = POP;
849 if (!NILP (v1))
851 BYTE_CODE_QUIT;
852 stack.pc += (int) *stack.pc - 128;
854 stack.pc++;
855 break;
858 case BRgotoifnilelsepop:
859 MAYBE_GC ();
860 op = *stack.pc++;
861 if (NILP (TOP))
863 BYTE_CODE_QUIT;
864 stack.pc += op - 128;
866 else DISCARD (1);
867 break;
869 case BRgotoifnonnilelsepop:
870 MAYBE_GC ();
871 op = *stack.pc++;
872 if (!NILP (TOP))
874 BYTE_CODE_QUIT;
875 stack.pc += op - 128;
877 else DISCARD (1);
878 break;
880 case Breturn:
881 result = POP;
882 goto exit;
884 case Bdiscard:
885 DISCARD (1);
886 break;
888 case Bconstant2:
889 PUSH (vectorp[FETCH2]);
890 break;
892 case Bsave_excursion:
893 record_unwind_protect (save_excursion_restore,
894 save_excursion_save ());
895 break;
897 case Bsave_current_buffer:
898 case Bsave_current_buffer_1:
899 record_unwind_protect (set_buffer_if_live, Fcurrent_buffer ());
900 break;
902 case Bsave_window_excursion:
903 BEFORE_POTENTIAL_GC ();
904 TOP = Fsave_window_excursion (TOP);
905 AFTER_POTENTIAL_GC ();
906 break;
908 case Bsave_restriction:
909 record_unwind_protect (save_restriction_restore,
910 save_restriction_save ());
911 break;
913 case Bcatch:
915 Lisp_Object v1;
916 BEFORE_POTENTIAL_GC ();
917 v1 = POP;
918 TOP = internal_catch (TOP, Feval, v1);
919 AFTER_POTENTIAL_GC ();
920 break;
923 case Bunwind_protect:
924 record_unwind_protect (Fprogn, POP);
925 break;
927 case Bcondition_case:
929 Lisp_Object handlers, body;
930 handlers = POP;
931 body = POP;
932 BEFORE_POTENTIAL_GC ();
933 TOP = internal_lisp_condition_case (TOP, body, handlers);
934 AFTER_POTENTIAL_GC ();
935 break;
938 case Btemp_output_buffer_setup:
939 BEFORE_POTENTIAL_GC ();
940 CHECK_STRING (TOP);
941 temp_output_buffer_setup (SDATA (TOP));
942 AFTER_POTENTIAL_GC ();
943 TOP = Vstandard_output;
944 break;
946 case Btemp_output_buffer_show:
948 Lisp_Object v1;
949 BEFORE_POTENTIAL_GC ();
950 v1 = POP;
951 temp_output_buffer_show (TOP);
952 TOP = v1;
953 /* pop binding of standard-output */
954 unbind_to (SPECPDL_INDEX () - 1, Qnil);
955 AFTER_POTENTIAL_GC ();
956 break;
959 case Bnth:
961 Lisp_Object v1, v2;
962 BEFORE_POTENTIAL_GC ();
963 v1 = POP;
964 v2 = TOP;
965 CHECK_NUMBER (v2);
966 AFTER_POTENTIAL_GC ();
967 op = XINT (v2);
968 immediate_quit = 1;
969 while (--op >= 0 && CONSP (v1))
970 v1 = XCDR (v1);
971 immediate_quit = 0;
972 TOP = CAR (v1);
973 break;
976 case Bsymbolp:
977 TOP = SYMBOLP (TOP) ? Qt : Qnil;
978 break;
980 case Bconsp:
981 TOP = CONSP (TOP) ? Qt : Qnil;
982 break;
984 case Bstringp:
985 TOP = STRINGP (TOP) ? Qt : Qnil;
986 break;
988 case Blistp:
989 TOP = CONSP (TOP) || NILP (TOP) ? Qt : Qnil;
990 break;
992 case Bnot:
993 TOP = NILP (TOP) ? Qt : Qnil;
994 break;
996 case Bcons:
998 Lisp_Object v1;
999 v1 = POP;
1000 TOP = Fcons (TOP, v1);
1001 break;
1004 case Blist1:
1005 TOP = Fcons (TOP, Qnil);
1006 break;
1008 case Blist2:
1010 Lisp_Object v1;
1011 v1 = POP;
1012 TOP = Fcons (TOP, Fcons (v1, Qnil));
1013 break;
1016 case Blist3:
1017 DISCARD (2);
1018 TOP = Flist (3, &TOP);
1019 break;
1021 case Blist4:
1022 DISCARD (3);
1023 TOP = Flist (4, &TOP);
1024 break;
1026 case BlistN:
1027 op = FETCH;
1028 DISCARD (op - 1);
1029 TOP = Flist (op, &TOP);
1030 break;
1032 case Blength:
1033 BEFORE_POTENTIAL_GC ();
1034 TOP = Flength (TOP);
1035 AFTER_POTENTIAL_GC ();
1036 break;
1038 case Baref:
1040 Lisp_Object v1;
1041 BEFORE_POTENTIAL_GC ();
1042 v1 = POP;
1043 TOP = Faref (TOP, v1);
1044 AFTER_POTENTIAL_GC ();
1045 break;
1048 case Baset:
1050 Lisp_Object v1, v2;
1051 BEFORE_POTENTIAL_GC ();
1052 v2 = POP; v1 = POP;
1053 TOP = Faset (TOP, v1, v2);
1054 AFTER_POTENTIAL_GC ();
1055 break;
1058 case Bsymbol_value:
1059 BEFORE_POTENTIAL_GC ();
1060 TOP = Fsymbol_value (TOP);
1061 AFTER_POTENTIAL_GC ();
1062 break;
1064 case Bsymbol_function:
1065 BEFORE_POTENTIAL_GC ();
1066 TOP = Fsymbol_function (TOP);
1067 AFTER_POTENTIAL_GC ();
1068 break;
1070 case Bset:
1072 Lisp_Object v1;
1073 BEFORE_POTENTIAL_GC ();
1074 v1 = POP;
1075 TOP = Fset (TOP, v1);
1076 AFTER_POTENTIAL_GC ();
1077 break;
1080 case Bfset:
1082 Lisp_Object v1;
1083 BEFORE_POTENTIAL_GC ();
1084 v1 = POP;
1085 TOP = Ffset (TOP, v1);
1086 AFTER_POTENTIAL_GC ();
1087 break;
1090 case Bget:
1092 Lisp_Object v1;
1093 BEFORE_POTENTIAL_GC ();
1094 v1 = POP;
1095 TOP = Fget (TOP, v1);
1096 AFTER_POTENTIAL_GC ();
1097 break;
1100 case Bsubstring:
1102 Lisp_Object v1, v2;
1103 BEFORE_POTENTIAL_GC ();
1104 v2 = POP; v1 = POP;
1105 TOP = Fsubstring (TOP, v1, v2);
1106 AFTER_POTENTIAL_GC ();
1107 break;
1110 case Bconcat2:
1111 BEFORE_POTENTIAL_GC ();
1112 DISCARD (1);
1113 TOP = Fconcat (2, &TOP);
1114 AFTER_POTENTIAL_GC ();
1115 break;
1117 case Bconcat3:
1118 BEFORE_POTENTIAL_GC ();
1119 DISCARD (2);
1120 TOP = Fconcat (3, &TOP);
1121 AFTER_POTENTIAL_GC ();
1122 break;
1124 case Bconcat4:
1125 BEFORE_POTENTIAL_GC ();
1126 DISCARD (3);
1127 TOP = Fconcat (4, &TOP);
1128 AFTER_POTENTIAL_GC ();
1129 break;
1131 case BconcatN:
1132 op = FETCH;
1133 BEFORE_POTENTIAL_GC ();
1134 DISCARD (op - 1);
1135 TOP = Fconcat (op, &TOP);
1136 AFTER_POTENTIAL_GC ();
1137 break;
1139 case Bsub1:
1141 Lisp_Object v1;
1142 v1 = TOP;
1143 if (INTEGERP (v1))
1145 XSETINT (v1, XINT (v1) - 1);
1146 TOP = v1;
1148 else
1150 BEFORE_POTENTIAL_GC ();
1151 TOP = Fsub1 (v1);
1152 AFTER_POTENTIAL_GC ();
1154 break;
1157 case Badd1:
1159 Lisp_Object v1;
1160 v1 = TOP;
1161 if (INTEGERP (v1))
1163 XSETINT (v1, XINT (v1) + 1);
1164 TOP = v1;
1166 else
1168 BEFORE_POTENTIAL_GC ();
1169 TOP = Fadd1 (v1);
1170 AFTER_POTENTIAL_GC ();
1172 break;
1175 case Beqlsign:
1177 Lisp_Object v1, v2;
1178 BEFORE_POTENTIAL_GC ();
1179 v2 = POP; v1 = TOP;
1180 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1);
1181 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2);
1182 AFTER_POTENTIAL_GC ();
1183 if (FLOATP (v1) || FLOATP (v2))
1185 double f1, f2;
1187 f1 = (FLOATP (v1) ? XFLOAT_DATA (v1) : XINT (v1));
1188 f2 = (FLOATP (v2) ? XFLOAT_DATA (v2) : XINT (v2));
1189 TOP = (f1 == f2 ? Qt : Qnil);
1191 else
1192 TOP = (XINT (v1) == XINT (v2) ? Qt : Qnil);
1193 break;
1196 case Bgtr:
1198 Lisp_Object v1;
1199 BEFORE_POTENTIAL_GC ();
1200 v1 = POP;
1201 TOP = Fgtr (TOP, v1);
1202 AFTER_POTENTIAL_GC ();
1203 break;
1206 case Blss:
1208 Lisp_Object v1;
1209 BEFORE_POTENTIAL_GC ();
1210 v1 = POP;
1211 TOP = Flss (TOP, v1);
1212 AFTER_POTENTIAL_GC ();
1213 break;
1216 case Bleq:
1218 Lisp_Object v1;
1219 BEFORE_POTENTIAL_GC ();
1220 v1 = POP;
1221 TOP = Fleq (TOP, v1);
1222 AFTER_POTENTIAL_GC ();
1223 break;
1226 case Bgeq:
1228 Lisp_Object v1;
1229 BEFORE_POTENTIAL_GC ();
1230 v1 = POP;
1231 TOP = Fgeq (TOP, v1);
1232 AFTER_POTENTIAL_GC ();
1233 break;
1236 case Bdiff:
1237 BEFORE_POTENTIAL_GC ();
1238 DISCARD (1);
1239 TOP = Fminus (2, &TOP);
1240 AFTER_POTENTIAL_GC ();
1241 break;
1243 case Bnegate:
1245 Lisp_Object v1;
1246 v1 = TOP;
1247 if (INTEGERP (v1))
1249 XSETINT (v1, - XINT (v1));
1250 TOP = v1;
1252 else
1254 BEFORE_POTENTIAL_GC ();
1255 TOP = Fminus (1, &TOP);
1256 AFTER_POTENTIAL_GC ();
1258 break;
1261 case Bplus:
1262 BEFORE_POTENTIAL_GC ();
1263 DISCARD (1);
1264 TOP = Fplus (2, &TOP);
1265 AFTER_POTENTIAL_GC ();
1266 break;
1268 case Bmax:
1269 BEFORE_POTENTIAL_GC ();
1270 DISCARD (1);
1271 TOP = Fmax (2, &TOP);
1272 AFTER_POTENTIAL_GC ();
1273 break;
1275 case Bmin:
1276 BEFORE_POTENTIAL_GC ();
1277 DISCARD (1);
1278 TOP = Fmin (2, &TOP);
1279 AFTER_POTENTIAL_GC ();
1280 break;
1282 case Bmult:
1283 BEFORE_POTENTIAL_GC ();
1284 DISCARD (1);
1285 TOP = Ftimes (2, &TOP);
1286 AFTER_POTENTIAL_GC ();
1287 break;
1289 case Bquo:
1290 BEFORE_POTENTIAL_GC ();
1291 DISCARD (1);
1292 TOP = Fquo (2, &TOP);
1293 AFTER_POTENTIAL_GC ();
1294 break;
1296 case Brem:
1298 Lisp_Object v1;
1299 BEFORE_POTENTIAL_GC ();
1300 v1 = POP;
1301 TOP = Frem (TOP, v1);
1302 AFTER_POTENTIAL_GC ();
1303 break;
1306 case Bpoint:
1308 Lisp_Object v1;
1309 XSETFASTINT (v1, PT);
1310 PUSH (v1);
1311 break;
1314 case Bgoto_char:
1315 BEFORE_POTENTIAL_GC ();
1316 TOP = Fgoto_char (TOP);
1317 AFTER_POTENTIAL_GC ();
1318 break;
1320 case Binsert:
1321 BEFORE_POTENTIAL_GC ();
1322 TOP = Finsert (1, &TOP);
1323 AFTER_POTENTIAL_GC ();
1324 break;
1326 case BinsertN:
1327 op = FETCH;
1328 BEFORE_POTENTIAL_GC ();
1329 DISCARD (op - 1);
1330 TOP = Finsert (op, &TOP);
1331 AFTER_POTENTIAL_GC ();
1332 break;
1334 case Bpoint_max:
1336 Lisp_Object v1;
1337 XSETFASTINT (v1, ZV);
1338 PUSH (v1);
1339 break;
1342 case Bpoint_min:
1344 Lisp_Object v1;
1345 XSETFASTINT (v1, BEGV);
1346 PUSH (v1);
1347 break;
1350 case Bchar_after:
1351 BEFORE_POTENTIAL_GC ();
1352 TOP = Fchar_after (TOP);
1353 AFTER_POTENTIAL_GC ();
1354 break;
1356 case Bfollowing_char:
1358 Lisp_Object v1;
1359 BEFORE_POTENTIAL_GC ();
1360 v1 = Ffollowing_char ();
1361 AFTER_POTENTIAL_GC ();
1362 PUSH (v1);
1363 break;
1366 case Bpreceding_char:
1368 Lisp_Object v1;
1369 BEFORE_POTENTIAL_GC ();
1370 v1 = Fprevious_char ();
1371 AFTER_POTENTIAL_GC ();
1372 PUSH (v1);
1373 break;
1376 case Bcurrent_column:
1378 Lisp_Object v1;
1379 BEFORE_POTENTIAL_GC ();
1380 XSETFASTINT (v1, (int) current_column ()); /* iftc */
1381 AFTER_POTENTIAL_GC ();
1382 PUSH (v1);
1383 break;
1386 case Bindent_to:
1387 BEFORE_POTENTIAL_GC ();
1388 TOP = Findent_to (TOP, Qnil);
1389 AFTER_POTENTIAL_GC ();
1390 break;
1392 case Beolp:
1393 PUSH (Feolp ());
1394 break;
1396 case Beobp:
1397 PUSH (Feobp ());
1398 break;
1400 case Bbolp:
1401 PUSH (Fbolp ());
1402 break;
1404 case Bbobp:
1405 PUSH (Fbobp ());
1406 break;
1408 case Bcurrent_buffer:
1409 PUSH (Fcurrent_buffer ());
1410 break;
1412 case Bset_buffer:
1413 BEFORE_POTENTIAL_GC ();
1414 TOP = Fset_buffer (TOP);
1415 AFTER_POTENTIAL_GC ();
1416 break;
1418 case Binteractive_p:
1419 PUSH (Finteractive_p ());
1420 break;
1422 case Bforward_char:
1423 BEFORE_POTENTIAL_GC ();
1424 TOP = Fforward_char (TOP);
1425 AFTER_POTENTIAL_GC ();
1426 break;
1428 case Bforward_word:
1429 BEFORE_POTENTIAL_GC ();
1430 TOP = Fforward_word (TOP);
1431 AFTER_POTENTIAL_GC ();
1432 break;
1434 case Bskip_chars_forward:
1436 Lisp_Object v1;
1437 BEFORE_POTENTIAL_GC ();
1438 v1 = POP;
1439 TOP = Fskip_chars_forward (TOP, v1);
1440 AFTER_POTENTIAL_GC ();
1441 break;
1444 case Bskip_chars_backward:
1446 Lisp_Object v1;
1447 BEFORE_POTENTIAL_GC ();
1448 v1 = POP;
1449 TOP = Fskip_chars_backward (TOP, v1);
1450 AFTER_POTENTIAL_GC ();
1451 break;
1454 case Bforward_line:
1455 BEFORE_POTENTIAL_GC ();
1456 TOP = Fforward_line (TOP);
1457 AFTER_POTENTIAL_GC ();
1458 break;
1460 case Bchar_syntax:
1462 int c;
1464 BEFORE_POTENTIAL_GC ();
1465 CHECK_CHARACTER (TOP);
1466 AFTER_POTENTIAL_GC ();
1467 c = XFASTINT (TOP);
1468 if (NILP (current_buffer->enable_multibyte_characters))
1469 MAKE_CHAR_MULTIBYTE (c);
1470 XSETFASTINT (TOP, syntax_code_spec[(int) SYNTAX (c)]);
1472 break;
1474 case Bbuffer_substring:
1476 Lisp_Object v1;
1477 BEFORE_POTENTIAL_GC ();
1478 v1 = POP;
1479 TOP = Fbuffer_substring (TOP, v1);
1480 AFTER_POTENTIAL_GC ();
1481 break;
1484 case Bdelete_region:
1486 Lisp_Object v1;
1487 BEFORE_POTENTIAL_GC ();
1488 v1 = POP;
1489 TOP = Fdelete_region (TOP, v1);
1490 AFTER_POTENTIAL_GC ();
1491 break;
1494 case Bnarrow_to_region:
1496 Lisp_Object v1;
1497 BEFORE_POTENTIAL_GC ();
1498 v1 = POP;
1499 TOP = Fnarrow_to_region (TOP, v1);
1500 AFTER_POTENTIAL_GC ();
1501 break;
1504 case Bwiden:
1505 BEFORE_POTENTIAL_GC ();
1506 PUSH (Fwiden ());
1507 AFTER_POTENTIAL_GC ();
1508 break;
1510 case Bend_of_line:
1511 BEFORE_POTENTIAL_GC ();
1512 TOP = Fend_of_line (TOP);
1513 AFTER_POTENTIAL_GC ();
1514 break;
1516 case Bset_marker:
1518 Lisp_Object v1, v2;
1519 BEFORE_POTENTIAL_GC ();
1520 v1 = POP;
1521 v2 = POP;
1522 TOP = Fset_marker (TOP, v2, v1);
1523 AFTER_POTENTIAL_GC ();
1524 break;
1527 case Bmatch_beginning:
1528 BEFORE_POTENTIAL_GC ();
1529 TOP = Fmatch_beginning (TOP);
1530 AFTER_POTENTIAL_GC ();
1531 break;
1533 case Bmatch_end:
1534 BEFORE_POTENTIAL_GC ();
1535 TOP = Fmatch_end (TOP);
1536 AFTER_POTENTIAL_GC ();
1537 break;
1539 case Bupcase:
1540 BEFORE_POTENTIAL_GC ();
1541 TOP = Fupcase (TOP);
1542 AFTER_POTENTIAL_GC ();
1543 break;
1545 case Bdowncase:
1546 BEFORE_POTENTIAL_GC ();
1547 TOP = Fdowncase (TOP);
1548 AFTER_POTENTIAL_GC ();
1549 break;
1551 case Bstringeqlsign:
1553 Lisp_Object v1;
1554 BEFORE_POTENTIAL_GC ();
1555 v1 = POP;
1556 TOP = Fstring_equal (TOP, v1);
1557 AFTER_POTENTIAL_GC ();
1558 break;
1561 case Bstringlss:
1563 Lisp_Object v1;
1564 BEFORE_POTENTIAL_GC ();
1565 v1 = POP;
1566 TOP = Fstring_lessp (TOP, v1);
1567 AFTER_POTENTIAL_GC ();
1568 break;
1571 case Bequal:
1573 Lisp_Object v1;
1574 v1 = POP;
1575 TOP = Fequal (TOP, v1);
1576 break;
1579 case Bnthcdr:
1581 Lisp_Object v1;
1582 BEFORE_POTENTIAL_GC ();
1583 v1 = POP;
1584 TOP = Fnthcdr (TOP, v1);
1585 AFTER_POTENTIAL_GC ();
1586 break;
1589 case Belt:
1591 Lisp_Object v1, v2;
1592 if (CONSP (TOP))
1594 /* Exchange args and then do nth. */
1595 BEFORE_POTENTIAL_GC ();
1596 v2 = POP;
1597 v1 = TOP;
1598 CHECK_NUMBER (v2);
1599 AFTER_POTENTIAL_GC ();
1600 op = XINT (v2);
1601 immediate_quit = 1;
1602 while (--op >= 0 && CONSP (v1))
1603 v1 = XCDR (v1);
1604 immediate_quit = 0;
1605 TOP = CAR (v1);
1607 else
1609 BEFORE_POTENTIAL_GC ();
1610 v1 = POP;
1611 TOP = Felt (TOP, v1);
1612 AFTER_POTENTIAL_GC ();
1614 break;
1617 case Bmember:
1619 Lisp_Object v1;
1620 BEFORE_POTENTIAL_GC ();
1621 v1 = POP;
1622 TOP = Fmember (TOP, v1);
1623 AFTER_POTENTIAL_GC ();
1624 break;
1627 case Bassq:
1629 Lisp_Object v1;
1630 BEFORE_POTENTIAL_GC ();
1631 v1 = POP;
1632 TOP = Fassq (TOP, v1);
1633 AFTER_POTENTIAL_GC ();
1634 break;
1637 case Bnreverse:
1638 BEFORE_POTENTIAL_GC ();
1639 TOP = Fnreverse (TOP);
1640 AFTER_POTENTIAL_GC ();
1641 break;
1643 case Bsetcar:
1645 Lisp_Object v1;
1646 BEFORE_POTENTIAL_GC ();
1647 v1 = POP;
1648 TOP = Fsetcar (TOP, v1);
1649 AFTER_POTENTIAL_GC ();
1650 break;
1653 case Bsetcdr:
1655 Lisp_Object v1;
1656 BEFORE_POTENTIAL_GC ();
1657 v1 = POP;
1658 TOP = Fsetcdr (TOP, v1);
1659 AFTER_POTENTIAL_GC ();
1660 break;
1663 case Bcar_safe:
1665 Lisp_Object v1;
1666 v1 = TOP;
1667 TOP = CAR_SAFE (v1);
1668 break;
1671 case Bcdr_safe:
1673 Lisp_Object v1;
1674 v1 = TOP;
1675 TOP = CDR_SAFE (v1);
1676 break;
1679 case Bnconc:
1680 BEFORE_POTENTIAL_GC ();
1681 DISCARD (1);
1682 TOP = Fnconc (2, &TOP);
1683 AFTER_POTENTIAL_GC ();
1684 break;
1686 case Bnumberp:
1687 TOP = (NUMBERP (TOP) ? Qt : Qnil);
1688 break;
1690 case Bintegerp:
1691 TOP = INTEGERP (TOP) ? Qt : Qnil;
1692 break;
1694 #ifdef BYTE_CODE_SAFE
1695 case Bset_mark:
1696 BEFORE_POTENTIAL_GC ();
1697 error ("set-mark is an obsolete bytecode");
1698 AFTER_POTENTIAL_GC ();
1699 break;
1700 case Bscan_buffer:
1701 BEFORE_POTENTIAL_GC ();
1702 error ("scan-buffer is an obsolete bytecode");
1703 AFTER_POTENTIAL_GC ();
1704 break;
1705 #endif
1707 /* Handy byte-codes for lexical binding. */
1708 case Bstack_ref:
1709 case Bstack_ref+1:
1710 case Bstack_ref+2:
1711 case Bstack_ref+3:
1712 case Bstack_ref+4:
1713 case Bstack_ref+5:
1714 PUSH (stack.bottom[op - Bstack_ref]);
1715 break;
1716 case Bstack_ref+6:
1717 PUSH (stack.bottom[FETCH]);
1718 break;
1719 case Bstack_ref+7:
1720 PUSH (stack.bottom[FETCH2]);
1721 break;
1722 case Bstack_set:
1723 stack.bottom[FETCH] = POP;
1724 break;
1725 case Bstack_set2:
1726 stack.bottom[FETCH2] = POP;
1727 break;
1728 case Bvec_ref:
1729 case Bvec_set:
1730 /* These byte-codes used mostly for variable references to
1731 lexically bound variables that are in an environment vector
1732 instead of on the byte-interpreter stack (generally those
1733 variables which might be shared with a closure). */
1735 int index = FETCH;
1736 Lisp_Object vec = POP;
1738 if (! VECTORP (vec))
1739 wrong_type_argument (Qvectorp, vec);
1740 else if (index < 0 || index >= XVECTOR (vec)->size)
1741 args_out_of_range (vec, make_number (index));
1743 if (op == Bvec_ref)
1744 PUSH (XVECTOR (vec)->contents[index]);
1745 else
1746 XVECTOR (vec)->contents[index] = POP;
1748 break;
1749 case BdiscardN:
1750 op = FETCH;
1751 if (op & 0x80)
1753 op &= 0x7F;
1754 top[-op] = TOP;
1756 DISCARD (op);
1757 break;
1759 case 255:
1760 default:
1761 #ifdef BYTE_CODE_SAFE
1762 if (op < Bconstant)
1764 abort ();
1766 if ((op -= Bconstant) >= const_length)
1768 abort ();
1770 PUSH (vectorp[op]);
1771 #else
1772 PUSH (vectorp[op - Bconstant]);
1773 #endif
1777 exit:
1779 byte_stack_list = byte_stack_list->next;
1781 /* Binds and unbinds are supposed to be compiled balanced. */
1782 if (SPECPDL_INDEX () != count)
1783 #ifdef BYTE_CODE_SAFE
1784 error ("binding stack not balanced (serious byte compiler bug)");
1785 #else
1786 abort ();
1787 #endif
1789 return result;
1792 void
1793 syms_of_bytecode (void)
1795 Qbytecode = intern_c_string ("byte-code");
1796 staticpro (&Qbytecode);
1798 defsubr (&Sbyte_code);
1800 #ifdef BYTE_CODE_METER
1802 DEFVAR_LISP ("byte-code-meter", &Vbyte_code_meter,
1803 doc: /* A vector of vectors which holds a histogram of byte-code usage.
1804 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1805 opcode CODE has been executed.
1806 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1807 indicates how many times the byte opcodes CODE1 and CODE2 have been
1808 executed in succession. */);
1810 DEFVAR_BOOL ("byte-metering-on", &byte_metering_on,
1811 doc: /* If non-nil, keep profiling information on byte code usage.
1812 The variable byte-code-meter indicates how often each byte opcode is used.
1813 If a symbol has a property named `byte-code-meter' whose value is an
1814 integer, it is incremented each time that symbol's function is called. */);
1816 byte_metering_on = 0;
1817 Vbyte_code_meter = Fmake_vector (make_number (256), make_number (0));
1818 Qbyte_code_meter = intern_c_string ("byte-code-meter");
1819 staticpro (&Qbyte_code_meter);
1821 int i = 256;
1822 while (i--)
1823 XVECTOR (Vbyte_code_meter)->contents[i] =
1824 Fmake_vector (make_number (256), make_number (0));
1826 #endif
1829 /* arch-tag: b9803b6f-1ed6-4190-8adf-33fd3a9d10e9
1830 (do not change this comment) */