*** empty log message ***
[bpt/emacs.git] / src / bytecode.c
CommitLineData
36f7ba0a
JB
1/* Execution of byte code produced by bytecomp.el.
2 Copyright (C) 1985, 1986, 1987, 1988 Free Software Foundation, Inc.
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 1, or (at your option)
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
19
98bf0c8d 20hacked on by jwz@lucid.com 17-jun-91
36f7ba0a
JB
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 put back fset, symbol-function, and read-char because I don't
24 see any reason for them to have been removed;
25 o added a new instruction, unbind_all, which I will use for
26 tail-recursion elimination;
27 o made temp_output_buffer_show() be called with the right number
28 of args;
29 o made the new bytecodes be called with args in the right order;
30 o added metering support.
31
32by Hallvard:
98bf0c8d 33 o added relative jump instructions.
36f7ba0a
JB
34 o all conditionals now only do QUIT if they jump.
35 */
36
37
38#include "config.h"
39#include "lisp.h"
40#include "buffer.h"
41#include "syntax.h"
42
98bf0c8d
JB
43/*
44 * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for
45 * debugging the byte compiler...)
46 *
47 * define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
36f7ba0a
JB
48 */
49#define BYTE_CODE_SAFE
36f7ba0a
JB
50#define BYTE_CODE_METER
51
52\f
53#ifdef BYTE_CODE_METER
54
98bf0c8d 55Lisp_Object Vbyte_code_meter, Qbyte_code_meter;
36f7ba0a
JB
56int byte_metering_on;
57
58# define METER_2(code1,code2) \
59 XFASTINT (XVECTOR (XVECTOR (Vbyte_code_meter)->contents[(code1)]) \
60 ->contents[(code2)])
61
62# define METER_1(code) METER_2 (0,(code))
63
64# define METER_CODE(last_code, this_code) { \
65 if (byte_metering_on) { \
66 if (METER_1 (this_code) != ((1<<VALBITS)-1)) \
67 METER_1 (this_code) ++; \
68 if (last_code && \
69 METER_2 (last_code,this_code) != ((1<<VALBITS)-1)) \
70 METER_2 (last_code,this_code) ++; \
71 } \
72 }
73
74#else /* ! BYTE_CODE_METER */
75
76# define meter_code(last_code, this_code)
77
78#endif
79\f
80
81Lisp_Object Qbytecode;
82
83/* Byte codes: */
84
85#define Bvarref 010
86#define Bvarset 020
87#define Bvarbind 030
88#define Bcall 040
89#define Bunbind 050
90
91#define Bnth 070
92#define Bsymbolp 071
93#define Bconsp 072
94#define Bstringp 073
95#define Blistp 074
96#define Beq 075
97#define Bmemq 076
98#define Bnot 077
99#define Bcar 0100
100#define Bcdr 0101
101#define Bcons 0102
102#define Blist1 0103
103#define Blist2 0104
104#define Blist3 0105
105#define Blist4 0106
106#define Blength 0107
107#define Baref 0110
108#define Baset 0111
109#define Bsymbol_value 0112
98bf0c8d 110#define Bsymbol_function 0113
36f7ba0a 111#define Bset 0114
98bf0c8d 112#define Bfset 0115
36f7ba0a
JB
113#define Bget 0116
114#define Bsubstring 0117
115#define Bconcat2 0120
116#define Bconcat3 0121
117#define Bconcat4 0122
118#define Bsub1 0123
119#define Badd1 0124
120#define Beqlsign 0125
121#define Bgtr 0126
122#define Blss 0127
123#define Bleq 0130
124#define Bgeq 0131
125#define Bdiff 0132
126#define Bnegate 0133
127#define Bplus 0134
128#define Bmax 0135
129#define Bmin 0136
130#define Bmult 0137
131
132#define Bpoint 0140
133#define Bmark 0141 /* no longer generated as of v18 */
134#define Bgoto_char 0142
135#define Binsert 0143
136#define Bpoint_max 0144
137#define Bpoint_min 0145
138#define Bchar_after 0146
139#define Bfollowing_char 0147
140#define Bpreceding_char 0150
141#define Bcurrent_column 0151
142#define Bindent_to 0152
143#define Bscan_buffer 0153 /* No longer generated as of v18 */
144#define Beolp 0154
145#define Beobp 0155
146#define Bbolp 0156
147#define Bbobp 0157
148#define Bcurrent_buffer 0160
149#define Bset_buffer 0161
98bf0c8d 150#define Bread_char 0162 /* No longer generated as of v19 */
36f7ba0a
JB
151#define Bset_mark 0163 /* this loser is no longer generated as of v18 */
152#define Binteractive_p 0164 /* Needed since interactive-p takes unevalled args */
153
154#define Bforward_char 0165
155#define Bforward_word 0166
156#define Bskip_chars_forward 0167
157#define Bskip_chars_backward 0170
158#define Bforward_line 0171
159#define Bchar_syntax 0172
160#define Bbuffer_substring 0173
161#define Bdelete_region 0174
162#define Bnarrow_to_region 0175
163#define Bwiden 0176
98bf0c8d 164#define Bend_of_line 0177
36f7ba0a
JB
165
166#define Bconstant2 0201
167#define Bgoto 0202
168#define Bgotoifnil 0203
169#define Bgotoifnonnil 0204
170#define Bgotoifnilelsepop 0205
171#define Bgotoifnonnilelsepop 0206
172#define Breturn 0207
173#define Bdiscard 0210
174#define Bdup 0211
175
176#define Bsave_excursion 0212
177#define Bsave_window_excursion 0213
178#define Bsave_restriction 0214
179#define Bcatch 0215
180
181#define Bunwind_protect 0216
182#define Bcondition_case 0217
183#define Btemp_output_buffer_setup 0220
184#define Btemp_output_buffer_show 0221
185
186#define Bunbind_all 0222
187
98bf0c8d
JB
188#define Bset_marker 0223
189#define Bmatch_beginning 0224
190#define Bmatch_end 0225
191#define Bupcase 0226
192#define Bdowncase 0227
193
36f7ba0a
JB
194#define Bstringeqlsign 0230
195#define Bstringlss 0231
196#define Bequal 0232
197#define Bnthcdr 0233
198#define Belt 0234
199#define Bmember 0235
200#define Bassq 0236
201#define Bnreverse 0237
202#define Bsetcar 0240
203#define Bsetcdr 0241
204#define Bcar_safe 0242
205#define Bcdr_safe 0243
206#define Bnconc 0244
207#define Bquo 0245
208#define Brem 0246
209#define Bnumberp 0247
210#define Bintegerp 0250
211
98bf0c8d
JB
212#define BRgoto 0252
213#define BRgotoifnil 0253
214#define BRgotoifnonnil 0254
215#define BRgotoifnilelsepop 0255
216#define BRgotoifnonnilelsepop 0256
217
218#define BlistN 0257
219#define BconcatN 0260
220
36f7ba0a
JB
221#define Bconstant 0300
222#define CONSTANTLIM 0100
223\f
224/* Fetch the next byte from the bytecode stream */
225
226#define FETCH *pc++
227
228/* Fetch two bytes from the bytecode stream
229 and make a 16-bit number out of them */
230
231#define FETCH2 (op = FETCH, op + (FETCH << 8))
232
233/* Push x onto the execution stack. */
234
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))
239
240/* Pop a value off the execution stack. */
241
242#define POP (*stackp--)
243
244/* Discard n values from the execution stack. */
245
246#define DISCARD(n) (stackp -= (n))
247
248/* Get the value which is at the top of the execution stack, but don't pop it. */
249
250#define TOP (*stackp)
251
252DEFUN ("byte-code", Fbyte_code, Sbyte_code, 3, 3, 0,
253 "Function used internally in byte-compiled code.\n\
254The first argument is a string of byte code; the second, a vector of constants;\n\
255the third, the maximum stack depth used in this function.\n\
256If the third argument is incorrect, Emacs may crash.")
257 (bytestr, vector, maxdepth)
258 Lisp_Object bytestr, vector, maxdepth;
259{
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;
281
282 CHECK_STRING (bytestr, 0);
283 if (XTYPE (vector) != Lisp_Vector)
284 vector = wrong_type_argument (Qvectorp, vector);
285 CHECK_NUMBER (maxdepth, 2);
286
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);
291
292 --stackp;
293 stack = stackp;
294 stacke = stackp + XFASTINT (maxdepth);
295
296 /* Initialize the saved pc-pointer for fetching from the string. */
297 string_saved = bytestr;
298 pc = XSTRING (string_saved)->data;
299
300 while (1)
301 {
302#ifdef BYTE_CODE_SAFE
303 if (stackp > stacke)
304 error (
305 "Stack overflow in byte code (byte compiler bug), pc = %d, depth = %d",
306 pc - XSTRING (string_saved)->data, stacke - stackp);
307 if (stackp < stack)
308 error ("Stack underflow in byte code (byte compiler bug), pc = %d",
309 pc - XSTRING (string_saved)->data);
310#endif
311
312 if (string_saved != bytestr)
313 {
314 pc = pc - XSTRING (string_saved)->data + XSTRING (bytestr)->data;
315 string_saved = bytestr;
316 }
317
318#ifdef BYTE_CODE_METER
319 prev_op = this_op;
320 this_op = op = FETCH;
321 METER_CODE (prev_op, op);
322 switch (op)
323#else
324 switch (op = FETCH)
325#endif
326 {
327 case Bvarref+6:
328 op = FETCH;
329 goto varref;
330
331 case Bvarref+7:
332 op = FETCH2;
333 goto varref;
334
335 case Bvarref: case Bvarref+1: case Bvarref+2: case Bvarref+3:
336 case Bvarref+4: case Bvarref+5:
337 op = op - Bvarref;
338 varref:
339 v1 = vectorp[op];
340 if (XTYPE (v1) != Lisp_Symbol)
341 v2 = Fsymbol_value (v1);
342 else
343 {
344 v2 = XSYMBOL (v1)->value;
345#ifdef SWITCH_ENUM_BUG
346 switch ((int) XTYPE (v2))
347#else
348 switch (XTYPE (v2))
349#endif
350 {
351 case Lisp_Symbol:
352 if (!EQ (v2, Qunbound))
353 break;
354 case Lisp_Intfwd:
355 case Lisp_Boolfwd:
356 case Lisp_Objfwd:
357 case Lisp_Buffer_Local_Value:
358 case Lisp_Some_Buffer_Local_Value:
359 case Lisp_Buffer_Objfwd:
360 case Lisp_Void:
361 v2 = Fsymbol_value (v1);
362 }
363 }
364 PUSH (v2);
365 break;
366
367 case Bvarset+6:
368 op = FETCH;
369 goto varset;
370
371 case Bvarset+7:
372 op = FETCH2;
373 goto varset;
374
375 case Bvarset: case Bvarset+1: case Bvarset+2: case Bvarset+3:
376 case Bvarset+4: case Bvarset+5:
377 op -= Bvarset;
378 varset:
379 Fset (vectorp[op], POP);
380 break;
381
382 case Bvarbind+6:
383 op = FETCH;
384 goto varbind;
385
386 case Bvarbind+7:
387 op = FETCH2;
388 goto varbind;
389
390 case Bvarbind: case Bvarbind+1: case Bvarbind+2: case Bvarbind+3:
391 case Bvarbind+4: case Bvarbind+5:
392 op -= Bvarbind;
393 varbind:
394 specbind (vectorp[op], POP);
395 break;
396
397 case Bcall+6:
398 op = FETCH;
399 goto docall;
400
401 case Bcall+7:
402 op = FETCH2;
403 goto docall;
404
405 case Bcall: case Bcall+1: case Bcall+2: case Bcall+3:
406 case Bcall+4: case Bcall+5:
407 op -= Bcall;
408 docall:
409 DISCARD(op);
98bf0c8d
JB
410#ifdef BYTE_CODE_METER
411 if (byte_metering_on && XTYPE (TOP) == Lisp_Symbol)
412 {
413 v1 = TOP;
414 v2 = Fget (v1, Qbyte_code_meter);
415 if (XTYPE (v2) == Lisp_Int)
416 {
417 XSETINT (v2, XINT (v2) + 1);
418 Fput (v1, Qbyte_code_meter, v2);
419 }
420 }
421#endif
36f7ba0a
JB
422 TOP = Ffuncall (op + 1, &TOP);
423 break;
424
425 case Bunbind+6:
426 op = FETCH;
427 goto dounbind;
428
429 case Bunbind+7:
430 op = FETCH2;
431 goto dounbind;
432
433 case Bunbind: case Bunbind+1: case Bunbind+2: case Bunbind+3:
434 case Bunbind+4: case Bunbind+5:
435 op -= Bunbind;
436 dounbind:
437 unbind_to (specpdl_ptr - specpdl - op, Qnil);
438 break;
439
440 case Bunbind_all:
441 /* To unbind back to the beginning of this frame. Not used yet,
442 but wil be needed for tail-recursion elimination.
443 */
444 unbind_to (count, Qnil);
445 break;
446
447 case Bgoto:
448 QUIT;
449 op = FETCH2; /* pc = FETCH2 loses since FETCH2 contains pc++ */
450 pc = XSTRING (string_saved)->data + op;
451 break;
452
453 case Bgotoifnil:
454 op = FETCH2;
455 if (NULL (POP))
456 {
457 QUIT;
458 pc = XSTRING (string_saved)->data + op;
459 }
460 break;
461
462 case Bgotoifnonnil:
463 op = FETCH2;
464 if (!NULL (POP))
465 {
466 QUIT;
467 pc = XSTRING (string_saved)->data + op;
468 }
469 break;
470
471 case Bgotoifnilelsepop:
472 op = FETCH2;
473 if (NULL (TOP))
474 {
475 QUIT;
476 pc = XSTRING (string_saved)->data + op;
477 }
478 else DISCARD(1);
479 break;
480
481 case Bgotoifnonnilelsepop:
482 op = FETCH2;
483 if (!NULL (TOP))
484 {
485 QUIT;
486 pc = XSTRING (string_saved)->data + op;
487 }
488 else DISCARD(1);
489 break;
490
98bf0c8d
JB
491 case BRgoto:
492 QUIT;
493 pc += *pc - 127;
494 break;
495
496 case BRgotoifnil:
497 if (NULL (POP))
498 {
499 QUIT;
500 pc += *pc - 128;
501 }
502 pc++;
503 break;
504
505 case BRgotoifnonnil:
506 if (!NULL (POP))
507 {
508 QUIT;
509 pc += *pc - 128;
510 }
511 pc++;
512 break;
513
514 case BRgotoifnilelsepop:
515 op = *pc++;
516 if (NULL (TOP))
517 {
518 QUIT;
519 pc += op - 128;
520 }
521 else DISCARD(1);
522 break;
523
524 case BRgotoifnonnilelsepop:
525 op = *pc++;
526 if (!NULL (TOP))
527 {
528 QUIT;
529 pc += op - 128;
530 }
531 else DISCARD(1);
532 break;
533
36f7ba0a
JB
534 case Breturn:
535 v1 = POP;
536 goto exit;
537
538 case Bdiscard:
539 DISCARD(1);
540 break;
541
542 case Bdup:
543 v1 = TOP;
544 PUSH (v1);
545 break;
546
547 case Bconstant2:
548 PUSH (vectorp[FETCH2]);
549 break;
550
551 case Bsave_excursion:
552 record_unwind_protect (save_excursion_restore, save_excursion_save ());
553 break;
554
555 case Bsave_window_excursion:
556 TOP = Fsave_window_excursion (TOP);
557 break;
558
559 case Bsave_restriction:
560 record_unwind_protect (save_restriction_restore, save_restriction_save ());
561 break;
562
563 case Bcatch:
564 v1 = POP;
565 TOP = internal_catch (TOP, Feval, v1);
566 break;
567
568 case Bunwind_protect:
569 record_unwind_protect (0, POP);
570 (specpdl_ptr - 1)->symbol = Qnil;
571 break;
572
573 case Bcondition_case:
574 v1 = POP;
575 v1 = Fcons (POP, v1);
576 TOP = Fcondition_case (Fcons (TOP, v1));
577 break;
578
579 case Btemp_output_buffer_setup:
580 temp_output_buffer_setup (XSTRING (TOP)->data);
581 TOP = Vstandard_output;
582 break;
583
584 case Btemp_output_buffer_show:
585 v1 = POP;
586 temp_output_buffer_show (TOP, Qnil);
587 TOP = v1;
588 /* pop binding of standard-output */
589 unbind_to (specpdl_ptr - specpdl - 1, Qnil);
590 break;
591
592 case Bnth:
593 v1 = POP;
594 v2 = TOP;
595 nth_entry:
596 CHECK_NUMBER (v2, 0);
597 op = XINT (v2);
598 immediate_quit = 1;
599 while (--op >= 0)
600 {
601 if (CONSP (v1))
602 v1 = XCONS (v1)->cdr;
603 else if (!NULL (v1))
604 {
605 immediate_quit = 0;
606 v1 = wrong_type_argument (Qlistp, v1);
607 immediate_quit = 1;
608 op++;
609 }
610 }
611 immediate_quit = 0;
612 goto docar;
613
614 case Bsymbolp:
615 TOP = XTYPE (TOP) == Lisp_Symbol ? Qt : Qnil;
616 break;
617
618 case Bconsp:
619 TOP = CONSP (TOP) ? Qt : Qnil;
620 break;
621
622 case Bstringp:
623 TOP = XTYPE (TOP) == Lisp_String ? Qt : Qnil;
624 break;
625
626 case Blistp:
627 TOP = CONSP (TOP) || NULL (TOP) ? Qt : Qnil;
628 break;
629
630 case Beq:
631 v1 = POP;
632 TOP = EQ (v1, TOP) ? Qt : Qnil;
633 break;
634
635 case Bmemq:
636 v1 = POP;
637 TOP = Fmemq (TOP, v1);
638 break;
639
640 case Bnot:
641 TOP = NULL (TOP) ? Qt : Qnil;
642 break;
643
644 case Bcar:
645 v1 = TOP;
646 docar:
647 if (CONSP (v1)) TOP = XCONS (v1)->car;
648 else if (NULL (v1)) TOP = Qnil;
649 else Fcar (wrong_type_argument (Qlistp, v1));
650 break;
651
652 case Bcdr:
653 v1 = TOP;
654 if (CONSP (v1)) TOP = XCONS (v1)->cdr;
655 else if (NULL (v1)) TOP = Qnil;
656 else Fcdr (wrong_type_argument (Qlistp, v1));
657 break;
658
659 case Bcons:
660 v1 = POP;
661 TOP = Fcons (TOP, v1);
662 break;
663
664 case Blist1:
665 TOP = Fcons (TOP, Qnil);
666 break;
667
668 case Blist2:
669 v1 = POP;
670 TOP = Fcons (TOP, Fcons (v1, Qnil));
671 break;
672
673 case Blist3:
674 DISCARD(2);
675 TOP = Flist (3, &TOP);
676 break;
677
678 case Blist4:
679 DISCARD(3);
680 TOP = Flist (4, &TOP);
681 break;
682
98bf0c8d
JB
683 case BlistN:
684 op = FETCH;
685 DISCARD (op - 1);
686 TOP = Flist (op, &TOP);
687 break;
688
36f7ba0a
JB
689 case Blength:
690 TOP = Flength (TOP);
691 break;
692
693 case Baref:
694 v1 = POP;
695 TOP = Faref (TOP, v1);
696 break;
697
698 case Baset:
699 v2 = POP; v1 = POP;
700 TOP = Faset (TOP, v1, v2);
701 break;
702
703 case Bsymbol_value:
704 TOP = Fsymbol_value (TOP);
705 break;
706
707 case Bsymbol_function:
708 TOP = Fsymbol_function (TOP);
709 break;
710
711 case Bset:
712 v1 = POP;
713 TOP = Fset (TOP, v1);
714 break;
715
716 case Bfset:
717 v1 = POP;
718 TOP = Ffset (TOP, v1);
719 break;
720
721 case Bget:
722 v1 = POP;
723 TOP = Fget (TOP, v1);
724 break;
725
726 case Bsubstring:
727 v2 = POP; v1 = POP;
728 TOP = Fsubstring (TOP, v1, v2);
729 break;
730
731 case Bconcat2:
732 DISCARD(1);
733 TOP = Fconcat (2, &TOP);
734 break;
735
736 case Bconcat3:
737 DISCARD(2);
738 TOP = Fconcat (3, &TOP);
739 break;
740
741 case Bconcat4:
742 DISCARD(3);
743 TOP = Fconcat (4, &TOP);
744 break;
745
98bf0c8d
JB
746 case BconcatN:
747 op = FETCH;
748 DISCARD (op - 1);
749 TOP = Fconcat (op, &TOP);
750 break;
751
36f7ba0a
JB
752 case Bsub1:
753 v1 = TOP;
754 if (XTYPE (v1) == Lisp_Int)
755 {
756 XSETINT (v1, XINT (v1) - 1);
757 TOP = v1;
758 }
759 else
760 TOP = Fsub1 (v1);
761 break;
762
763 case Badd1:
764 v1 = TOP;
765 if (XTYPE (v1) == Lisp_Int)
766 {
767 XSETINT (v1, XINT (v1) + 1);
768 TOP = v1;
769 }
770 else
771 TOP = Fadd1 (v1);
772 break;
773
774 case Beqlsign:
775 v2 = POP; v1 = TOP;
776 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1, 0);
777 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2, 0);
778 TOP = (XFLOATINT (v1) == XFLOATINT (v2)) ? Qt : Qnil;
779 break;
780
781 case Bgtr:
782 v1 = POP;
783 TOP = Fgtr (TOP, v1);
784 break;
785
786 case Blss:
787 v1 = POP;
788 TOP = Flss (TOP, v1);
789 break;
790
791 case Bleq:
792 v1 = POP;
793 TOP = Fleq (TOP, v1);
794 break;
795
796 case Bgeq:
797 v1 = POP;
798 TOP = Fgeq (TOP, v1);
799 break;
800
801 case Bdiff:
802 DISCARD(1);
803 TOP = Fminus (2, &TOP);
804 break;
805
806 case Bnegate:
807 v1 = TOP;
808 if (XTYPE (v1) == Lisp_Int)
809 {
810 XSETINT (v1, - XINT (v1));
811 TOP = v1;
812 }
813 else
814 TOP = Fminus (1, &TOP);
815 break;
816
817 case Bplus:
818 DISCARD(1);
819 TOP = Fplus (2, &TOP);
820 break;
821
822 case Bmax:
823 DISCARD(1);
824 TOP = Fmax (2, &TOP);
825 break;
826
827 case Bmin:
828 DISCARD(1);
829 TOP = Fmin (2, &TOP);
830 break;
831
832 case Bmult:
833 DISCARD(1);
834 TOP = Ftimes (2, &TOP);
835 break;
836
837 case Bquo:
838 DISCARD(1);
839 TOP = Fquo (2, &TOP);
840 break;
841
842 case Brem:
843 v1 = POP;
36f7ba0a
JB
844 TOP = Frem (TOP, v1);
845 break;
846
847 case Bpoint:
848 XFASTINT (v1) = point;
849 PUSH (v1);
850 break;
851
852 case Bgoto_char:
853 TOP = Fgoto_char (TOP);
854 break;
855
856 case Binsert:
857 TOP = Finsert (1, &TOP);
858 break;
859
860 case Bpoint_max:
861 XFASTINT (v1) = ZV;
862 PUSH (v1);
863 break;
864
865 case Bpoint_min:
866 XFASTINT (v1) = BEGV;
867 PUSH (v1);
868 break;
869
870 case Bchar_after:
871 TOP = Fchar_after (TOP);
872 break;
873
874 case Bfollowing_char:
875 XFASTINT (v1) = PT == ZV ? 0 : FETCH_CHAR (point);
876 PUSH (v1);
877 break;
878
879 case Bpreceding_char:
880 XFASTINT (v1) = point <= BEGV ? 0 : FETCH_CHAR (point - 1);
881 PUSH (v1);
882 break;
883
884 case Bcurrent_column:
885 XFASTINT (v1) = current_column ();
886 PUSH (v1);
887 break;
888
889 case Bindent_to:
890 TOP = Findent_to (TOP, Qnil);
891 break;
892
893 case Beolp:
894 PUSH (Feolp ());
895 break;
896
897 case Beobp:
898 PUSH (Feobp ());
899 break;
900
901 case Bbolp:
902 PUSH (Fbolp ());
903 break;
904
905 case Bbobp:
906 PUSH (Fbobp ());
907 break;
908
909 case Bcurrent_buffer:
910 PUSH (Fcurrent_buffer ());
911 break;
912
913 case Bset_buffer:
914 TOP = Fset_buffer (TOP);
915 break;
916
917 case Bread_char:
918 PUSH (Fread_char ());
919 QUIT;
920 break;
921
922 case Binteractive_p:
923 PUSH (Finteractive_p ());
924 break;
925
926 case Bforward_char:
36f7ba0a
JB
927 TOP = Fforward_char (TOP);
928 break;
929
930 case Bforward_word:
36f7ba0a
JB
931 TOP = Fforward_word (TOP);
932 break;
933
934 case Bskip_chars_forward:
36f7ba0a
JB
935 v1 = POP;
936 TOP = Fskip_chars_forward (TOP, v1);
937 break;
938
939 case Bskip_chars_backward:
36f7ba0a
JB
940 v1 = POP;
941 TOP = Fskip_chars_backward (TOP, v1);
942 break;
943
944 case Bforward_line:
36f7ba0a
JB
945 TOP = Fforward_line (TOP);
946 break;
947
948 case Bchar_syntax:
949 CHECK_NUMBER (TOP, 0);
950 XFASTINT (TOP) = syntax_code_spec[(int) SYNTAX (0xFF & XINT (TOP))];
951 break;
952
953 case Bbuffer_substring:
954 v1 = POP;
955 TOP = Fbuffer_substring (TOP, v1);
956 break;
957
958 case Bdelete_region:
959 v1 = POP;
36f7ba0a
JB
960 TOP = Fdelete_region (TOP, v1);
961 break;
962
963 case Bnarrow_to_region:
964 v1 = POP;
36f7ba0a
JB
965 TOP = Fnarrow_to_region (TOP, v1);
966 break;
967
968 case Bwiden:
969 PUSH (Fwiden ());
970 break;
971
98bf0c8d
JB
972 case Bend_of_line:
973 TOP = Fend_of_line (TOP);
974 break;
975
976 case Bset_marker:
977 v1 = POP;
978 v2 = POP;
979 TOP = Fset_marker (TOP, v2, v1);
980 break;
981
982 case Bmatch_beginning:
983 TOP = Fmatch_beginning (TOP);
984 break;
985
986 case Bmatch_end:
987 TOP = Fmatch_end (TOP);
988 break;
989
990 case Bupcase:
991 TOP = Fupcase (TOP);
992 break;
993
994 case Bdowncase:
995 TOP = Fdowncase (TOP);
996 break;
997
36f7ba0a
JB
998 case Bstringeqlsign:
999 v1 = POP;
36f7ba0a
JB
1000 TOP = Fstring_equal (TOP, v1);
1001 break;
1002
1003 case Bstringlss:
1004 v1 = POP;
36f7ba0a
JB
1005 TOP = Fstring_lessp (TOP, v1);
1006 break;
1007
1008 case Bequal:
1009 v1 = POP;
36f7ba0a
JB
1010 TOP = Fequal (TOP, v1);
1011 break;
1012
1013 case Bnthcdr:
1014 v1 = POP;
36f7ba0a
JB
1015 TOP = Fnthcdr (TOP, v1);
1016 break;
1017
1018 case Belt:
1019 if (XTYPE (TOP) == Lisp_Cons)
1020 {
1021 /* Exchange args and then do nth. */
1022 v2 = POP;
1023 v1 = TOP;
1024 goto nth_entry;
1025 }
1026 v1 = POP;
1027 TOP = Felt (TOP, v1);
1028 break;
1029
1030 case Bmember:
1031 v1 = POP;
36f7ba0a
JB
1032 TOP = Fmember (TOP, v1);
1033 break;
1034
1035 case Bassq:
1036 v1 = POP;
36f7ba0a
JB
1037 TOP = Fassq (TOP, v1);
1038 break;
1039
1040 case Bnreverse:
1041 TOP = Fnreverse (TOP);
1042 break;
1043
1044 case Bsetcar:
1045 v1 = POP;
36f7ba0a
JB
1046 TOP = Fsetcar (TOP, v1);
1047 break;
1048
1049 case Bsetcdr:
1050 v1 = POP;
36f7ba0a
JB
1051 TOP = Fsetcdr (TOP, v1);
1052 break;
1053
1054 case Bcar_safe:
1055 v1 = TOP;
1056 if (XTYPE (v1) == Lisp_Cons)
1057 TOP = XCONS (v1)->car;
1058 else
1059 TOP = Qnil;
1060 break;
1061
1062 case Bcdr_safe:
1063 v1 = TOP;
1064 if (XTYPE (v1) == Lisp_Cons)
1065 TOP = XCONS (v1)->cdr;
1066 else
1067 TOP = Qnil;
1068 break;
1069
1070 case Bnconc:
1071 DISCARD(1);
1072 TOP = Fnconc (2, &TOP);
1073 break;
1074
1075 case Bnumberp:
1076 TOP = (XTYPE (TOP) == Lisp_Int || XTYPE (TOP) == Lisp_Float
1077 ? Qt : Qnil);
1078 break;
1079
1080 case Bintegerp:
1081 TOP = XTYPE (TOP) == Lisp_Int ? Qt : Qnil;
1082 break;
1083
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
1095
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
1106 }
1107 }
1108
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;
1119}
1120
1121syms_of_bytecode ()
1122{
1123 Qbytecode = intern ("byte-code");
1124 staticpro (&Qbytecode);
1125
1126 defsubr (&Sbyte_code);
1127
1128#ifdef BYTE_CODE_METER
1129
1130 DEFVAR_LISP ("byte-code-meter", &Vbyte_code_meter,
1131 "a vector of vectors which holds a histogram of byte-code usage.");
1132 DEFVAR_BOOL ("byte-metering-on", &byte_metering_on, "");
1133
1134 byte_metering_on = 0;
1135 Vbyte_code_meter = Fmake_vector(make_number(256), make_number(0));
98bf0c8d 1136 staticpro (&Qbyte_code_meter);
36f7ba0a
JB
1137 {
1138 int i = 256;
1139 while (i--)
1140 XVECTOR(Vbyte_code_meter)->contents[i] =
1141 Fmake_vector(make_number(256), make_number(0));
1142 }
1143#endif
1144}