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