(gnus-cache-enter-remove-article, gnus-cache-possibly-remove-articles):
[emacs.git] / src / bytecode.c
blobcc5b46047db82627651e932849976db7919ea3e7
1 /* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985, 1986, 1987, 1988, 1993 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
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.
30 by Hallvard:
31 o added relative jump instructions;
32 o all conditionals now only do QUIT if they jump.
35 #include <config.h>
36 #include "lisp.h"
37 #include "buffer.h"
38 #include "syntax.h"
41 * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for
42 * debugging the byte compiler...)
44 * define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
46 /* #define BYTE_CODE_SAFE */
47 /* #define BYTE_CODE_METER */
50 #ifdef BYTE_CODE_METER
52 Lisp_Object Vbyte_code_meter, Qbyte_code_meter;
53 int byte_metering_on;
55 #define METER_2(code1, code2) \
56 XFASTINT (XVECTOR (XVECTOR (Vbyte_code_meter)->contents[(code1)]) \
57 ->contents[(code2)])
59 #define METER_1(code) METER_2 (0, (code))
61 #define METER_CODE(last_code, this_code) \
62 { \
63 if (byte_metering_on) \
64 { \
65 if (METER_1 (this_code) != ((1<<VALBITS)-1)) \
66 METER_1 (this_code)++; \
67 if (last_code \
68 && METER_2 (last_code, this_code) != ((1<<VALBITS)-1))\
69 METER_2 (last_code, this_code)++; \
70 } \
73 #else /* no BYTE_CODE_METER */
75 #define METER_CODE(last_code, this_code)
77 #endif /* no BYTE_CODE_METER */
80 Lisp_Object Qbytecode;
82 /* Byte codes: */
84 #define Bvarref 010
85 #define Bvarset 020
86 #define Bvarbind 030
87 #define Bcall 040
88 #define Bunbind 050
90 #define Bnth 070
91 #define Bsymbolp 071
92 #define Bconsp 072
93 #define Bstringp 073
94 #define Blistp 074
95 #define Beq 075
96 #define Bmemq 076
97 #define Bnot 077
98 #define Bcar 0100
99 #define Bcdr 0101
100 #define Bcons 0102
101 #define Blist1 0103
102 #define Blist2 0104
103 #define Blist3 0105
104 #define Blist4 0106
105 #define Blength 0107
106 #define Baref 0110
107 #define Baset 0111
108 #define Bsymbol_value 0112
109 #define Bsymbol_function 0113
110 #define Bset 0114
111 #define Bfset 0115
112 #define Bget 0116
113 #define Bsubstring 0117
114 #define Bconcat2 0120
115 #define Bconcat3 0121
116 #define Bconcat4 0122
117 #define Bsub1 0123
118 #define Badd1 0124
119 #define Beqlsign 0125
120 #define Bgtr 0126
121 #define Blss 0127
122 #define Bleq 0130
123 #define Bgeq 0131
124 #define Bdiff 0132
125 #define Bnegate 0133
126 #define Bplus 0134
127 #define Bmax 0135
128 #define Bmin 0136
129 #define Bmult 0137
131 #define Bpoint 0140
132 #define Bmark 0141 /* no longer generated as of v18 */
133 #define Bgoto_char 0142
134 #define Binsert 0143
135 #define Bpoint_max 0144
136 #define Bpoint_min 0145
137 #define Bchar_after 0146
138 #define Bfollowing_char 0147
139 #define Bpreceding_char 0150
140 #define Bcurrent_column 0151
141 #define Bindent_to 0152
142 #define Bscan_buffer 0153 /* No longer generated as of v18 */
143 #define Beolp 0154
144 #define Beobp 0155
145 #define Bbolp 0156
146 #define Bbobp 0157
147 #define Bcurrent_buffer 0160
148 #define Bset_buffer 0161
149 #define Bread_char 0162 /* No longer generated as of v19 */
150 #define Bset_mark 0163 /* this loser is no longer generated as of v18 */
151 #define Binteractive_p 0164 /* Needed since interactive-p takes unevalled args */
153 #define Bforward_char 0165
154 #define Bforward_word 0166
155 #define Bskip_chars_forward 0167
156 #define Bskip_chars_backward 0170
157 #define Bforward_line 0171
158 #define Bchar_syntax 0172
159 #define Bbuffer_substring 0173
160 #define Bdelete_region 0174
161 #define Bnarrow_to_region 0175
162 #define Bwiden 0176
163 #define Bend_of_line 0177
165 #define Bconstant2 0201
166 #define Bgoto 0202
167 #define Bgotoifnil 0203
168 #define Bgotoifnonnil 0204
169 #define Bgotoifnilelsepop 0205
170 #define Bgotoifnonnilelsepop 0206
171 #define Breturn 0207
172 #define Bdiscard 0210
173 #define Bdup 0211
175 #define Bsave_excursion 0212
176 #define Bsave_window_excursion 0213
177 #define Bsave_restriction 0214
178 #define Bcatch 0215
180 #define Bunwind_protect 0216
181 #define Bcondition_case 0217
182 #define Btemp_output_buffer_setup 0220
183 #define Btemp_output_buffer_show 0221
185 #define Bunbind_all 0222
187 #define Bset_marker 0223
188 #define Bmatch_beginning 0224
189 #define Bmatch_end 0225
190 #define Bupcase 0226
191 #define Bdowncase 0227
193 #define Bstringeqlsign 0230
194 #define Bstringlss 0231
195 #define Bequal 0232
196 #define Bnthcdr 0233
197 #define Belt 0234
198 #define Bmember 0235
199 #define Bassq 0236
200 #define Bnreverse 0237
201 #define Bsetcar 0240
202 #define Bsetcdr 0241
203 #define Bcar_safe 0242
204 #define Bcdr_safe 0243
205 #define Bnconc 0244
206 #define Bquo 0245
207 #define Brem 0246
208 #define Bnumberp 0247
209 #define Bintegerp 0250
211 #define BRgoto 0252
212 #define BRgotoifnil 0253
213 #define BRgotoifnonnil 0254
214 #define BRgotoifnilelsepop 0255
215 #define BRgotoifnonnilelsepop 0256
217 #define BlistN 0257
218 #define BconcatN 0260
219 #define BinsertN 0261
221 #define Bconstant 0300
222 #define CONSTANTLIM 0100
224 /* Fetch the next byte from the bytecode stream */
226 #define FETCH *pc++
228 /* Fetch two bytes from the bytecode stream
229 and make a 16-bit number out of them */
231 #define FETCH2 (op = FETCH, op + (FETCH << 8))
233 /* Push x onto the execution stack. */
235 /* This used to be #define PUSH(x) (*++stackp = (x))
236 This oddity is necessary because Alliant can't be bothered to
237 compile the preincrement operator properly, as of 4/91. -JimB */
238 #define PUSH(x) (stackp++, *stackp = (x))
240 /* Pop a value off the execution stack. */
242 #define POP (*stackp--)
244 /* Discard n values from the execution stack. */
246 #define DISCARD(n) (stackp -= (n))
248 /* Get the value which is at the top of the execution stack, but don't pop it. */
250 #define TOP (*stackp)
252 DEFUN ("byte-code", Fbyte_code, Sbyte_code, 3, 3, 0,
253 "Function used internally in byte-compiled code.\n\
254 The first argument is a string of byte code; the second, a vector of constants;\n\
255 the third, the maximum stack depth used in this function.\n\
256 If the third argument is incorrect, Emacs may crash.")
257 (bytestr, vector, maxdepth)
258 Lisp_Object bytestr, vector, maxdepth;
260 struct gcpro gcpro1, gcpro2, gcpro3;
261 int count = specpdl_ptr - specpdl;
262 #ifdef BYTE_CODE_METER
263 int this_op = 0;
264 int prev_op;
265 #endif
266 register int op;
267 unsigned char *pc;
268 Lisp_Object *stack;
269 register Lisp_Object *stackp;
270 Lisp_Object *stacke;
271 register Lisp_Object v1, v2;
272 register Lisp_Object *vectorp = XVECTOR (vector)->contents;
273 #ifdef BYTE_CODE_SAFE
274 register int const_length = XVECTOR (vector)->size;
275 #endif
276 /* Copy of BYTESTR, saved so we can tell if BYTESTR was relocated. */
277 Lisp_Object string_saved;
278 /* Cached address of beginning of string,
279 valid if BYTESTR equals STRING_SAVED. */
280 register unsigned char *strbeg;
282 CHECK_STRING (bytestr, 0);
283 if (!VECTORP (vector))
284 vector = wrong_type_argument (Qvectorp, vector);
285 CHECK_NUMBER (maxdepth, 2);
287 stackp = (Lisp_Object *) alloca (XFASTINT (maxdepth) * sizeof (Lisp_Object));
288 bzero (stackp, XFASTINT (maxdepth) * sizeof (Lisp_Object));
289 GCPRO3 (bytestr, vector, *stackp);
290 gcpro3.nvars = XFASTINT (maxdepth);
292 --stackp;
293 stack = stackp;
294 stacke = stackp + XFASTINT (maxdepth);
296 /* Initialize the saved pc-pointer for fetching from the string. */
297 string_saved = bytestr;
298 pc = XSTRING (string_saved)->data;
300 while (1)
302 #ifdef BYTE_CODE_SAFE
303 if (stackp > stacke)
304 error ("Byte code stack overflow (byte compiler bug), pc %d, depth %d",
305 pc - XSTRING (string_saved)->data, stacke - stackp);
306 if (stackp < stack)
307 error ("Byte code stack underflow (byte compiler bug), pc %d",
308 pc - XSTRING (string_saved)->data);
309 #endif
311 if (! EQ (string_saved, bytestr))
313 pc = pc - XSTRING (string_saved)->data + XSTRING (bytestr)->data;
314 string_saved = bytestr;
317 #ifdef BYTE_CODE_METER
318 prev_op = this_op;
319 this_op = op = FETCH;
320 METER_CODE (prev_op, op);
321 switch (op)
322 #else
323 switch (op = FETCH)
324 #endif
326 case Bvarref+6:
327 op = FETCH;
328 goto varref;
330 case Bvarref+7:
331 op = FETCH2;
332 goto varref;
334 case Bvarref: case Bvarref+1: case Bvarref+2: case Bvarref+3:
335 case Bvarref+4: case Bvarref+5:
336 op = op - Bvarref;
337 varref:
338 v1 = vectorp[op];
339 if (!SYMBOLP (v1))
340 v2 = Fsymbol_value (v1);
341 else
343 v2 = XSYMBOL (v1)->value;
344 if (MISCP (v2) || EQ (v2, Qunbound))
345 v2 = Fsymbol_value (v1);
347 PUSH (v2);
348 break;
350 case Bvarset+6:
351 op = FETCH;
352 goto varset;
354 case Bvarset+7:
355 op = FETCH2;
356 goto varset;
358 case Bvarset: case Bvarset+1: case Bvarset+2: case Bvarset+3:
359 case Bvarset+4: case Bvarset+5:
360 op -= Bvarset;
361 varset:
362 Fset (vectorp[op], POP);
363 break;
365 case Bvarbind+6:
366 op = FETCH;
367 goto varbind;
369 case Bvarbind+7:
370 op = FETCH2;
371 goto varbind;
373 case Bvarbind: case Bvarbind+1: case Bvarbind+2: case Bvarbind+3:
374 case Bvarbind+4: case Bvarbind+5:
375 op -= Bvarbind;
376 varbind:
377 specbind (vectorp[op], POP);
378 break;
380 case Bcall+6:
381 op = FETCH;
382 goto docall;
384 case Bcall+7:
385 op = FETCH2;
386 goto docall;
388 case Bcall: case Bcall+1: case Bcall+2: case Bcall+3:
389 case Bcall+4: case Bcall+5:
390 op -= Bcall;
391 docall:
392 DISCARD (op);
393 #ifdef BYTE_CODE_METER
394 if (byte_metering_on && SYMBOLP (TOP))
396 v1 = TOP;
397 v2 = Fget (v1, Qbyte_code_meter);
398 if (INTEGERP (v2)
399 && XINT (v2) != ((1<<VALBITS)-1))
401 XSETINT (v2, XINT (v2) + 1);
402 Fput (v1, Qbyte_code_meter, v2);
405 #endif
406 TOP = Ffuncall (op + 1, &TOP);
407 break;
409 case Bunbind+6:
410 op = FETCH;
411 goto dounbind;
413 case Bunbind+7:
414 op = FETCH2;
415 goto dounbind;
417 case Bunbind: case Bunbind+1: case Bunbind+2: case Bunbind+3:
418 case Bunbind+4: case Bunbind+5:
419 op -= Bunbind;
420 dounbind:
421 unbind_to (specpdl_ptr - specpdl - op, Qnil);
422 break;
424 case Bunbind_all:
425 /* To unbind back to the beginning of this frame. Not used yet,
426 but will be needed for tail-recursion elimination. */
427 unbind_to (count, Qnil);
428 break;
430 case Bgoto:
431 QUIT;
432 op = FETCH2; /* pc = FETCH2 loses since FETCH2 contains pc++ */
433 pc = XSTRING (string_saved)->data + op;
434 break;
436 case Bgotoifnil:
437 op = FETCH2;
438 if (NILP (POP))
440 QUIT;
441 pc = XSTRING (string_saved)->data + op;
443 break;
445 case Bgotoifnonnil:
446 op = FETCH2;
447 if (!NILP (POP))
449 QUIT;
450 pc = XSTRING (string_saved)->data + op;
452 break;
454 case Bgotoifnilelsepop:
455 op = FETCH2;
456 if (NILP (TOP))
458 QUIT;
459 pc = XSTRING (string_saved)->data + op;
461 else DISCARD (1);
462 break;
464 case Bgotoifnonnilelsepop:
465 op = FETCH2;
466 if (!NILP (TOP))
468 QUIT;
469 pc = XSTRING (string_saved)->data + op;
471 else DISCARD (1);
472 break;
474 case BRgoto:
475 QUIT;
476 pc += *pc - 127;
477 break;
479 case BRgotoifnil:
480 if (NILP (POP))
482 QUIT;
483 pc += *pc - 128;
485 pc++;
486 break;
488 case BRgotoifnonnil:
489 if (!NILP (POP))
491 QUIT;
492 pc += *pc - 128;
494 pc++;
495 break;
497 case BRgotoifnilelsepop:
498 op = *pc++;
499 if (NILP (TOP))
501 QUIT;
502 pc += op - 128;
504 else DISCARD (1);
505 break;
507 case BRgotoifnonnilelsepop:
508 op = *pc++;
509 if (!NILP (TOP))
511 QUIT;
512 pc += op - 128;
514 else DISCARD (1);
515 break;
517 case Breturn:
518 v1 = POP;
519 goto exit;
521 case Bdiscard:
522 DISCARD (1);
523 break;
525 case Bdup:
526 v1 = TOP;
527 PUSH (v1);
528 break;
530 case Bconstant2:
531 PUSH (vectorp[FETCH2]);
532 break;
534 case Bsave_excursion:
535 record_unwind_protect (save_excursion_restore, save_excursion_save ());
536 break;
538 case Bsave_window_excursion:
539 TOP = Fsave_window_excursion (TOP);
540 break;
542 case Bsave_restriction:
543 record_unwind_protect (save_restriction_restore, save_restriction_save ());
544 break;
546 case Bcatch:
547 v1 = POP;
548 TOP = internal_catch (TOP, Feval, v1);
549 break;
551 case Bunwind_protect:
552 record_unwind_protect (0, POP);
553 (specpdl_ptr - 1)->symbol = Qnil;
554 break;
556 case Bcondition_case:
557 v1 = POP;
558 v1 = Fcons (POP, v1);
559 TOP = Fcondition_case (Fcons (TOP, v1));
560 break;
562 case Btemp_output_buffer_setup:
563 temp_output_buffer_setup (XSTRING (TOP)->data);
564 TOP = Vstandard_output;
565 break;
567 case Btemp_output_buffer_show:
568 v1 = POP;
569 temp_output_buffer_show (TOP);
570 TOP = v1;
571 /* pop binding of standard-output */
572 unbind_to (specpdl_ptr - specpdl - 1, Qnil);
573 break;
575 case Bnth:
576 v1 = POP;
577 v2 = TOP;
578 nth_entry:
579 CHECK_NUMBER (v2, 0);
580 op = XINT (v2);
581 immediate_quit = 1;
582 while (--op >= 0)
584 if (CONSP (v1))
585 v1 = XCONS (v1)->cdr;
586 else if (!NILP (v1))
588 immediate_quit = 0;
589 v1 = wrong_type_argument (Qlistp, v1);
590 immediate_quit = 1;
591 op++;
594 immediate_quit = 0;
595 goto docar;
597 case Bsymbolp:
598 TOP = SYMBOLP (TOP) ? Qt : Qnil;
599 break;
601 case Bconsp:
602 TOP = CONSP (TOP) ? Qt : Qnil;
603 break;
605 case Bstringp:
606 TOP = STRINGP (TOP) ? Qt : Qnil;
607 break;
609 case Blistp:
610 TOP = CONSP (TOP) || NILP (TOP) ? Qt : Qnil;
611 break;
613 case Beq:
614 v1 = POP;
615 TOP = EQ (v1, TOP) ? Qt : Qnil;
616 break;
618 case Bmemq:
619 v1 = POP;
620 TOP = Fmemq (TOP, v1);
621 break;
623 case Bnot:
624 TOP = NILP (TOP) ? Qt : Qnil;
625 break;
627 case Bcar:
628 v1 = TOP;
629 docar:
630 if (CONSP (v1)) TOP = XCONS (v1)->car;
631 else if (NILP (v1)) TOP = Qnil;
632 else Fcar (wrong_type_argument (Qlistp, v1));
633 break;
635 case Bcdr:
636 v1 = TOP;
637 if (CONSP (v1)) TOP = XCONS (v1)->cdr;
638 else if (NILP (v1)) TOP = Qnil;
639 else Fcdr (wrong_type_argument (Qlistp, v1));
640 break;
642 case Bcons:
643 v1 = POP;
644 TOP = Fcons (TOP, v1);
645 break;
647 case Blist1:
648 TOP = Fcons (TOP, Qnil);
649 break;
651 case Blist2:
652 v1 = POP;
653 TOP = Fcons (TOP, Fcons (v1, Qnil));
654 break;
656 case Blist3:
657 DISCARD (2);
658 TOP = Flist (3, &TOP);
659 break;
661 case Blist4:
662 DISCARD (3);
663 TOP = Flist (4, &TOP);
664 break;
666 case BlistN:
667 op = FETCH;
668 DISCARD (op - 1);
669 TOP = Flist (op, &TOP);
670 break;
672 case Blength:
673 TOP = Flength (TOP);
674 break;
676 case Baref:
677 v1 = POP;
678 TOP = Faref (TOP, v1);
679 break;
681 case Baset:
682 v2 = POP; v1 = POP;
683 TOP = Faset (TOP, v1, v2);
684 break;
686 case Bsymbol_value:
687 TOP = Fsymbol_value (TOP);
688 break;
690 case Bsymbol_function:
691 TOP = Fsymbol_function (TOP);
692 break;
694 case Bset:
695 v1 = POP;
696 TOP = Fset (TOP, v1);
697 break;
699 case Bfset:
700 v1 = POP;
701 TOP = Ffset (TOP, v1);
702 break;
704 case Bget:
705 v1 = POP;
706 TOP = Fget (TOP, v1);
707 break;
709 case Bsubstring:
710 v2 = POP; v1 = POP;
711 TOP = Fsubstring (TOP, v1, v2);
712 break;
714 case Bconcat2:
715 DISCARD (1);
716 TOP = Fconcat (2, &TOP);
717 break;
719 case Bconcat3:
720 DISCARD (2);
721 TOP = Fconcat (3, &TOP);
722 break;
724 case Bconcat4:
725 DISCARD (3);
726 TOP = Fconcat (4, &TOP);
727 break;
729 case BconcatN:
730 op = FETCH;
731 DISCARD (op - 1);
732 TOP = Fconcat (op, &TOP);
733 break;
735 case Bsub1:
736 v1 = TOP;
737 if (INTEGERP (v1))
739 XSETINT (v1, XINT (v1) - 1);
740 TOP = v1;
742 else
743 TOP = Fsub1 (v1);
744 break;
746 case Badd1:
747 v1 = TOP;
748 if (INTEGERP (v1))
750 XSETINT (v1, XINT (v1) + 1);
751 TOP = v1;
753 else
754 TOP = Fadd1 (v1);
755 break;
757 case Beqlsign:
758 v2 = POP; v1 = TOP;
759 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1, 0);
760 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2, 0);
761 #ifdef LISP_FLOAT_TYPE
762 if (FLOATP (v1) || FLOATP (v2))
764 double f1, f2;
766 f1 = (FLOATP (v1) ? XFLOAT (v1)->data : XINT (v1));
767 f2 = (FLOATP (v2) ? XFLOAT (v2)->data : XINT (v2));
768 TOP = (f1 == f2 ? Qt : Qnil);
770 else
771 #endif
772 TOP = (XINT (v1) == XINT (v2) ? Qt : Qnil);
773 break;
775 case Bgtr:
776 v1 = POP;
777 TOP = Fgtr (TOP, v1);
778 break;
780 case Blss:
781 v1 = POP;
782 TOP = Flss (TOP, v1);
783 break;
785 case Bleq:
786 v1 = POP;
787 TOP = Fleq (TOP, v1);
788 break;
790 case Bgeq:
791 v1 = POP;
792 TOP = Fgeq (TOP, v1);
793 break;
795 case Bdiff:
796 DISCARD (1);
797 TOP = Fminus (2, &TOP);
798 break;
800 case Bnegate:
801 v1 = TOP;
802 if (INTEGERP (v1))
804 XSETINT (v1, - XINT (v1));
805 TOP = v1;
807 else
808 TOP = Fminus (1, &TOP);
809 break;
811 case Bplus:
812 DISCARD (1);
813 TOP = Fplus (2, &TOP);
814 break;
816 case Bmax:
817 DISCARD (1);
818 TOP = Fmax (2, &TOP);
819 break;
821 case Bmin:
822 DISCARD (1);
823 TOP = Fmin (2, &TOP);
824 break;
826 case Bmult:
827 DISCARD (1);
828 TOP = Ftimes (2, &TOP);
829 break;
831 case Bquo:
832 DISCARD (1);
833 TOP = Fquo (2, &TOP);
834 break;
836 case Brem:
837 v1 = POP;
838 TOP = Frem (TOP, v1);
839 break;
841 case Bpoint:
842 XSETFASTINT (v1, point);
843 PUSH (v1);
844 break;
846 case Bgoto_char:
847 TOP = Fgoto_char (TOP);
848 break;
850 case Binsert:
851 TOP = Finsert (1, &TOP);
852 break;
854 case BinsertN:
855 op = FETCH;
856 DISCARD (op - 1);
857 TOP = Finsert (op, &TOP);
858 break;
860 case Bpoint_max:
861 XSETFASTINT (v1, ZV);
862 PUSH (v1);
863 break;
865 case Bpoint_min:
866 XSETFASTINT (v1, BEGV);
867 PUSH (v1);
868 break;
870 case Bchar_after:
871 TOP = Fchar_after (TOP);
872 break;
874 case Bfollowing_char:
875 v1 = Ffollowing_char ();
876 PUSH (v1);
877 break;
879 case Bpreceding_char:
880 v1 = Fprevious_char ();
881 PUSH (v1);
882 break;
884 case Bcurrent_column:
885 XSETFASTINT (v1, current_column ());
886 PUSH (v1);
887 break;
889 case Bindent_to:
890 TOP = Findent_to (TOP, Qnil);
891 break;
893 case Beolp:
894 PUSH (Feolp ());
895 break;
897 case Beobp:
898 PUSH (Feobp ());
899 break;
901 case Bbolp:
902 PUSH (Fbolp ());
903 break;
905 case Bbobp:
906 PUSH (Fbobp ());
907 break;
909 case Bcurrent_buffer:
910 PUSH (Fcurrent_buffer ());
911 break;
913 case Bset_buffer:
914 TOP = Fset_buffer (TOP);
915 break;
917 case Bread_char:
918 PUSH (Fread_char ());
919 QUIT;
920 break;
922 case Binteractive_p:
923 PUSH (Finteractive_p ());
924 break;
926 case Bforward_char:
927 TOP = Fforward_char (TOP);
928 break;
930 case Bforward_word:
931 TOP = Fforward_word (TOP);
932 break;
934 case Bskip_chars_forward:
935 v1 = POP;
936 TOP = Fskip_chars_forward (TOP, v1);
937 break;
939 case Bskip_chars_backward:
940 v1 = POP;
941 TOP = Fskip_chars_backward (TOP, v1);
942 break;
944 case Bforward_line:
945 TOP = Fforward_line (TOP);
946 break;
948 case Bchar_syntax:
949 CHECK_NUMBER (TOP, 0);
950 XSETFASTINT (TOP,
951 syntax_code_spec[(int) SYNTAX (XINT (TOP))]);
952 break;
954 case Bbuffer_substring:
955 v1 = POP;
956 TOP = Fbuffer_substring (TOP, v1);
957 break;
959 case Bdelete_region:
960 v1 = POP;
961 TOP = Fdelete_region (TOP, v1);
962 break;
964 case Bnarrow_to_region:
965 v1 = POP;
966 TOP = Fnarrow_to_region (TOP, v1);
967 break;
969 case Bwiden:
970 PUSH (Fwiden ());
971 break;
973 case Bend_of_line:
974 TOP = Fend_of_line (TOP);
975 break;
977 case Bset_marker:
978 v1 = POP;
979 v2 = POP;
980 TOP = Fset_marker (TOP, v2, v1);
981 break;
983 case Bmatch_beginning:
984 TOP = Fmatch_beginning (TOP);
985 break;
987 case Bmatch_end:
988 TOP = Fmatch_end (TOP);
989 break;
991 case Bupcase:
992 TOP = Fupcase (TOP);
993 break;
995 case Bdowncase:
996 TOP = Fdowncase (TOP);
997 break;
999 case Bstringeqlsign:
1000 v1 = POP;
1001 TOP = Fstring_equal (TOP, v1);
1002 break;
1004 case Bstringlss:
1005 v1 = POP;
1006 TOP = Fstring_lessp (TOP, v1);
1007 break;
1009 case Bequal:
1010 v1 = POP;
1011 TOP = Fequal (TOP, v1);
1012 break;
1014 case Bnthcdr:
1015 v1 = POP;
1016 TOP = Fnthcdr (TOP, v1);
1017 break;
1019 case Belt:
1020 if (CONSP (TOP))
1022 /* Exchange args and then do nth. */
1023 v2 = POP;
1024 v1 = TOP;
1025 goto nth_entry;
1027 v1 = POP;
1028 TOP = Felt (TOP, v1);
1029 break;
1031 case Bmember:
1032 v1 = POP;
1033 TOP = Fmember (TOP, v1);
1034 break;
1036 case Bassq:
1037 v1 = POP;
1038 TOP = Fassq (TOP, v1);
1039 break;
1041 case Bnreverse:
1042 TOP = Fnreverse (TOP);
1043 break;
1045 case Bsetcar:
1046 v1 = POP;
1047 TOP = Fsetcar (TOP, v1);
1048 break;
1050 case Bsetcdr:
1051 v1 = POP;
1052 TOP = Fsetcdr (TOP, v1);
1053 break;
1055 case Bcar_safe:
1056 v1 = TOP;
1057 if (CONSP (v1))
1058 TOP = XCONS (v1)->car;
1059 else
1060 TOP = Qnil;
1061 break;
1063 case Bcdr_safe:
1064 v1 = TOP;
1065 if (CONSP (v1))
1066 TOP = XCONS (v1)->cdr;
1067 else
1068 TOP = Qnil;
1069 break;
1071 case Bnconc:
1072 DISCARD (1);
1073 TOP = Fnconc (2, &TOP);
1074 break;
1076 case Bnumberp:
1077 TOP = (NUMBERP (TOP) ? Qt : Qnil);
1078 break;
1080 case Bintegerp:
1081 TOP = INTEGERP (TOP) ? Qt : Qnil;
1082 break;
1084 #ifdef BYTE_CODE_SAFE
1085 case Bset_mark:
1086 error ("set-mark is an obsolete bytecode");
1087 break;
1088 case Bscan_buffer:
1089 error ("scan-buffer is an obsolete bytecode");
1090 break;
1091 case Bmark:
1092 error ("mark is an obsolete bytecode");
1093 break;
1094 #endif
1096 default:
1097 #ifdef BYTE_CODE_SAFE
1098 if (op < Bconstant)
1099 error ("unknown bytecode %d (byte compiler bug)", op);
1100 if ((op -= Bconstant) >= const_length)
1101 error ("no constant number %d (byte compiler bug)", op);
1102 PUSH (vectorp[op]);
1103 #else
1104 PUSH (vectorp[op - Bconstant]);
1105 #endif
1109 exit:
1110 UNGCPRO;
1111 /* Binds and unbinds are supposed to be compiled balanced. */
1112 if (specpdl_ptr - specpdl != count)
1113 #ifdef BYTE_CODE_SAFE
1114 error ("binding stack not balanced (serious byte compiler bug)");
1115 #else
1116 abort ();
1117 #endif
1118 return v1;
1121 syms_of_bytecode ()
1123 Qbytecode = intern ("byte-code");
1124 staticpro (&Qbytecode);
1126 defsubr (&Sbyte_code);
1128 #ifdef BYTE_CODE_METER
1130 DEFVAR_LISP ("byte-code-meter", &Vbyte_code_meter,
1131 "A vector of vectors which holds a histogram of byte-code usage.\n\
1132 (aref (aref byte-code-meter 0) CODE) indicates how many times the byte\n\
1133 opcode CODE has been executed.\n\
1134 (aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,\n\
1135 indicates how many times the byte opcodes CODE1 and CODE2 have been\n\
1136 executed in succession.");
1137 DEFVAR_BOOL ("byte-metering-on", &byte_metering_on,
1138 "If non-nil, keep profiling information on byte code usage.\n\
1139 The variable byte-code-meter indicates how often each byte opcode is used.\n\
1140 If a symbol has a property named `byte-code-meter' whose value is an\n\
1141 integer, it is incremented each time that symbol's function is called.");
1143 byte_metering_on = 0;
1144 Vbyte_code_meter = Fmake_vector (make_number (256), make_number (0));
1145 Qbyte_code_meter = intern ("byte-code-meter");
1146 staticpro (&Qbyte_code_meter);
1148 int i = 256;
1149 while (i--)
1150 XVECTOR (Vbyte_code_meter)->contents[i] =
1151 Fmake_vector (make_number (256), make_number (0));
1153 #endif