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