Port to C89.
[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,
575 Fcons (Fcons (make_number (mandatory),
576 rest ? Qand_rest : make_number (nonrest)),
577 Fcons (make_number (nargs), Qnil)));
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,
e2abe5a1
SM
596 Fcons (Fcons (make_number (mandatory),
597 make_number (nonrest)),
598 Fcons (make_number (nargs), Qnil)));
599 }
600 else if (! NILP (args_template))
601 /* We should push some arguments on the stack. */
602 {
603 error ("Unknown args template!");
b9598260
SM
604 }
605
36f7ba0a
JB
606 while (1)
607 {
608#ifdef BYTE_CODE_SAFE
9e49c990 609 if (top > stacke)
1088b922 610 emacs_abort ();
7ca1e8b7 611 else if (top < stack.bottom - 1)
1088b922 612 emacs_abort ();
36f7ba0a
JB
613#endif
614
36f7ba0a
JB
615#ifdef BYTE_CODE_METER
616 prev_op = this_op;
617 this_op = op = FETCH;
618 METER_CODE (prev_op, op);
36f7ba0a 619#else
3a4c8000 620#ifndef BYTE_CODE_THREADED
4015b3c0 621 op = FETCH;
36f7ba0a 622#endif
3a4c8000
TT
623#endif
624
625 /* The interpreter can be compiled one of two ways: as an
626 ordinary switch-based interpreter, or as a threaded
627 interpreter. The threaded interpreter relies on GCC's
628 computed goto extension, so it is not available everywhere.
629 Threading provides a performance boost. These macros are how
630 we allow the code to be compiled both ways. */
631#ifdef BYTE_CODE_THREADED
632 /* The CASE macro introduces an instruction's body. It is
633 either a label or a case label. */
634#define CASE(OP) insn_ ## OP
635 /* NEXT is invoked at the end of an instruction to go to the
636 next instruction. It is either a computed goto, or a
637 plain break. */
638#define NEXT goto *(targets[op = FETCH])
639 /* FIRST is like NEXT, but is only used at the start of the
640 interpreter body. In the switch-based interpreter it is the
641 switch, so the threaded definition must include a semicolon. */
642#define FIRST NEXT;
643 /* Most cases are labeled with the CASE macro, above.
644 CASE_DEFAULT is one exception; it is used if the interpreter
645 being built requires a default case. The threaded
646 interpreter does not, because the dispatch table is
647 completely filled. */
648#define CASE_DEFAULT
649 /* This introduces an instruction that is known to call abort. */
650#define CASE_ABORT CASE (Bstack_ref): CASE (default)
651#else
652 /* See above for the meaning of the various defines. */
653#define CASE(OP) case OP
654#define NEXT break
655#define FIRST switch (op)
656#define CASE_DEFAULT case 255: default:
657#define CASE_ABORT case 0
658#endif
659
660#ifdef BYTE_CODE_THREADED
661
662 /* A convenience define that saves us a lot of typing and makes
663 the table clearer. */
664#define LABEL(OP) [OP] = &&insn_ ## OP
36f7ba0a 665
31ff141c 666#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__)
ffacb126
PE
667# pragma GCC diagnostic push
668# pragma GCC diagnostic ignored "-Woverride-init"
31ff141c
PE
669#elif defined __clang__
670# pragma GCC diagnostic push
671# pragma GCC diagnostic ignored "-Winitializer-overrides"
ffacb126
PE
672#endif
673
3a4c8000
TT
674 /* This is the dispatch table for the threaded interpreter. */
675 static const void *const targets[256] =
4015b3c0 676 {
3a4c8000
TT
677 [0 ... (Bconstant - 1)] = &&insn_default,
678 [Bconstant ... 255] = &&insn_Bconstant,
679
680#define DEFINE(name, value) LABEL (name) ,
681 BYTE_CODES
682#undef DEFINE
683 };
ffacb126 684
31ff141c 685#if 4 < __GNUC__ + (6 <= __GNUC_MINOR__) || defined __clang__
ffacb126
PE
686# pragma GCC diagnostic pop
687#endif
688
3a4c8000
TT
689#endif
690
691
692 FIRST
693 {
694 CASE (Bvarref7):
36f7ba0a
JB
695 op = FETCH2;
696 goto varref;
697
3a4c8000
TT
698 CASE (Bvarref):
699 CASE (Bvarref1):
700 CASE (Bvarref2):
701 CASE (Bvarref3):
702 CASE (Bvarref4):
703 CASE (Bvarref5):
36f7ba0a 704 op = op - Bvarref;
4015b3c0
GM
705 goto varref;
706
707 /* This seems to be the most frequently executed byte-code
708 among the Bvarref's, so avoid a goto here. */
3a4c8000 709 CASE (Bvarref6):
4015b3c0 710 op = FETCH;
36f7ba0a 711 varref:
4015b3c0
GM
712 {
713 Lisp_Object v1, v2;
714
715 v1 = vectorp[op];
716 if (SYMBOLP (v1))
717 {
ce5b453a
SM
718 if (XSYMBOL (v1)->redirect != SYMBOL_PLAINVAL
719 || (v2 = SYMBOL_VAL (XSYMBOL (v1)),
720 EQ (v2, Qunbound)))
bf1de43e
GM
721 {
722 BEFORE_POTENTIAL_GC ();
723 v2 = Fsymbol_value (v1);
724 AFTER_POTENTIAL_GC ();
725 }
4015b3c0
GM
726 }
727 else
bf1de43e
GM
728 {
729 BEFORE_POTENTIAL_GC ();
730 v2 = Fsymbol_value (v1);
731 AFTER_POTENTIAL_GC ();
732 }
4015b3c0 733 PUSH (v2);
3a4c8000 734 NEXT;
4015b3c0
GM
735 }
736
3a4c8000 737 CASE (Bgotoifnil):
21ed6de3
KR
738 {
739 Lisp_Object v1;
740 MAYBE_GC ();
741 op = FETCH2;
742 v1 = POP;
743 if (NILP (v1))
744 {
745 BYTE_CODE_QUIT;
746 CHECK_RANGE (op);
747 stack.pc = stack.byte_string_start + op;
748 }
3a4c8000 749 NEXT;
21ed6de3 750 }
36f7ba0a 751
3a4c8000 752 CASE (Bcar):
4015b3c0
GM
753 {
754 Lisp_Object v1;
755 v1 = TOP;
1c470562
SM
756 if (CONSP (v1))
757 TOP = XCAR (v1);
758 else if (NILP (v1))
759 TOP = Qnil;
760 else
761 {
762 BEFORE_POTENTIAL_GC ();
763 wrong_type_argument (Qlistp, v1);
1c470562 764 }
3a4c8000 765 NEXT;
4015b3c0
GM
766 }
767
3a4c8000 768 CASE (Beq):
4015b3c0
GM
769 {
770 Lisp_Object v1;
771 v1 = POP;
772 TOP = EQ (v1, TOP) ? Qt : Qnil;
3a4c8000 773 NEXT;
4015b3c0
GM
774 }
775
3a4c8000 776 CASE (Bmemq):
4015b3c0
GM
777 {
778 Lisp_Object v1;
bf1de43e 779 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
780 v1 = POP;
781 TOP = Fmemq (TOP, v1);
bf1de43e 782 AFTER_POTENTIAL_GC ();
3a4c8000 783 NEXT;
4015b3c0
GM
784 }
785
3a4c8000 786 CASE (Bcdr):
4015b3c0
GM
787 {
788 Lisp_Object v1;
789 v1 = TOP;
1c470562
SM
790 if (CONSP (v1))
791 TOP = XCDR (v1);
792 else if (NILP (v1))
793 TOP = Qnil;
794 else
795 {
796 BEFORE_POTENTIAL_GC ();
797 wrong_type_argument (Qlistp, v1);
1c470562 798 }
3a4c8000 799 NEXT;
4015b3c0 800 }
36f7ba0a 801
3a4c8000
TT
802 CASE (Bvarset):
803 CASE (Bvarset1):
804 CASE (Bvarset2):
805 CASE (Bvarset3):
806 CASE (Bvarset4):
807 CASE (Bvarset5):
620cc5fa 808 op -= Bvarset;
36f7ba0a
JB
809 goto varset;
810
3a4c8000 811 CASE (Bvarset7):
620cc5fa 812 op = FETCH2;
4015b3c0
GM
813 goto varset;
814
3a4c8000 815 CASE (Bvarset6):
4015b3c0 816 op = FETCH;
36f7ba0a 817 varset:
620cc5fa
GM
818 {
819 Lisp_Object sym, val;
8e11578b 820
620cc5fa 821 sym = vectorp[op];
bf1de43e 822 val = TOP;
620cc5fa
GM
823
824 /* Inline the most common case. */
825 if (SYMBOLP (sym)
826 && !EQ (val, Qunbound)
ce5b453a
SM
827 && !XSYMBOL (sym)->redirect
828 && !SYMBOL_CONSTANT_P (sym))
c644523b 829 SET_SYMBOL_VAL (XSYMBOL (sym), val);
620cc5fa 830 else
bf1de43e
GM
831 {
832 BEFORE_POTENTIAL_GC ();
94b612ad 833 set_internal (sym, val, Qnil, 0);
bf1de43e
GM
834 AFTER_POTENTIAL_GC ();
835 }
620cc5fa 836 }
3789dcdf 837 (void) POP;
3a4c8000 838 NEXT;
36f7ba0a 839
3a4c8000 840 CASE (Bdup):
4015b3c0
GM
841 {
842 Lisp_Object v1;
843 v1 = TOP;
844 PUSH (v1);
3a4c8000 845 NEXT;
4015b3c0
GM
846 }
847
848 /* ------------------ */
849
3a4c8000 850 CASE (Bvarbind6):
36f7ba0a
JB
851 op = FETCH;
852 goto varbind;
853
3a4c8000 854 CASE (Bvarbind7):
36f7ba0a
JB
855 op = FETCH2;
856 goto varbind;
857
3a4c8000
TT
858 CASE (Bvarbind):
859 CASE (Bvarbind1):
860 CASE (Bvarbind2):
861 CASE (Bvarbind3):
862 CASE (Bvarbind4):
863 CASE (Bvarbind5):
36f7ba0a
JB
864 op -= Bvarbind;
865 varbind:
56b8eef5
GM
866 /* Specbind can signal and thus GC. */
867 BEFORE_POTENTIAL_GC ();
36f7ba0a 868 specbind (vectorp[op], POP);
56b8eef5 869 AFTER_POTENTIAL_GC ();
3a4c8000 870 NEXT;
36f7ba0a 871
3a4c8000 872 CASE (Bcall6):
36f7ba0a
JB
873 op = FETCH;
874 goto docall;
875
3a4c8000 876 CASE (Bcall7):
36f7ba0a
JB
877 op = FETCH2;
878 goto docall;
879
3a4c8000
TT
880 CASE (Bcall):
881 CASE (Bcall1):
882 CASE (Bcall2):
883 CASE (Bcall3):
884 CASE (Bcall4):
885 CASE (Bcall5):
36f7ba0a
JB
886 op -= Bcall;
887 docall:
4015b3c0 888 {
fa9aabf6 889 BEFORE_POTENTIAL_GC ();
4015b3c0 890 DISCARD (op);
63639d44 891#ifdef BYTE_CODE_METER
4015b3c0
GM
892 if (byte_metering_on && SYMBOLP (TOP))
893 {
894 Lisp_Object v1, v2;
895
896 v1 = TOP;
897 v2 = Fget (v1, Qbyte_code_meter);
898 if (INTEGERP (v2)
f28e6371 899 && XINT (v2) < MOST_POSITIVE_FIXNUM)
4015b3c0
GM
900 {
901 XSETINT (v2, XINT (v2) + 1);
902 Fput (v1, Qbyte_code_meter, v2);
903 }
904 }
63639d44 905#endif
4015b3c0
GM
906 TOP = Ffuncall (op + 1, &TOP);
907 AFTER_POTENTIAL_GC ();
3a4c8000 908 NEXT;
4015b3c0 909 }
36f7ba0a 910
3a4c8000 911 CASE (Bunbind6):
36f7ba0a
JB
912 op = FETCH;
913 goto dounbind;
914
3a4c8000 915 CASE (Bunbind7):
36f7ba0a
JB
916 op = FETCH2;
917 goto dounbind;
918
3a4c8000
TT
919 CASE (Bunbind):
920 CASE (Bunbind1):
921 CASE (Bunbind2):
922 CASE (Bunbind3):
923 CASE (Bunbind4):
924 CASE (Bunbind5):
36f7ba0a
JB
925 op -= Bunbind;
926 dounbind:
7ca1e8b7 927 BEFORE_POTENTIAL_GC ();
aed13378 928 unbind_to (SPECPDL_INDEX () - op, Qnil);
7ca1e8b7 929 AFTER_POTENTIAL_GC ();
3a4c8000 930 NEXT;
36f7ba0a 931
3a4c8000 932 CASE (Bunbind_all): /* Obsolete. Never used. */
36f7ba0a 933 /* To unbind back to the beginning of this frame. Not used yet,
63639d44 934 but will be needed for tail-recursion elimination. */
7ca1e8b7 935 BEFORE_POTENTIAL_GC ();
36f7ba0a 936 unbind_to (count, Qnil);
7ca1e8b7 937 AFTER_POTENTIAL_GC ();
3a4c8000 938 NEXT;
36f7ba0a 939
3a4c8000 940 CASE (Bgoto):
14726871 941 MAYBE_GC ();
e12ea64e 942 BYTE_CODE_QUIT;
36f7ba0a 943 op = FETCH2; /* pc = FETCH2 loses since FETCH2 contains pc++ */
3d5fc37b 944 CHECK_RANGE (op);
7ca1e8b7 945 stack.pc = stack.byte_string_start + op;
3a4c8000 946 NEXT;
36f7ba0a 947
3a4c8000 948 CASE (Bgotoifnonnil):
21ed6de3
KR
949 {
950 Lisp_Object v1;
951 MAYBE_GC ();
952 op = FETCH2;
953 v1 = POP;
954 if (!NILP (v1))
955 {
956 BYTE_CODE_QUIT;
957 CHECK_RANGE (op);
958 stack.pc = stack.byte_string_start + op;
959 }
3a4c8000 960 NEXT;
21ed6de3 961 }
36f7ba0a 962
3a4c8000 963 CASE (Bgotoifnilelsepop):
14726871 964 MAYBE_GC ();
36f7ba0a 965 op = FETCH2;
921a8935 966 if (NILP (TOP))
36f7ba0a 967 {
e12ea64e 968 BYTE_CODE_QUIT;
3d5fc37b 969 CHECK_RANGE (op);
7ca1e8b7 970 stack.pc = stack.byte_string_start + op;
36f7ba0a 971 }
63639d44 972 else DISCARD (1);
3a4c8000 973 NEXT;
36f7ba0a 974
3a4c8000 975 CASE (Bgotoifnonnilelsepop):
14726871 976 MAYBE_GC ();
36f7ba0a 977 op = FETCH2;
921a8935 978 if (!NILP (TOP))
36f7ba0a 979 {
e12ea64e 980 BYTE_CODE_QUIT;
3d5fc37b 981 CHECK_RANGE (op);
7ca1e8b7 982 stack.pc = stack.byte_string_start + op;
36f7ba0a 983 }
63639d44 984 else DISCARD (1);
3a4c8000 985 NEXT;
63639d44 986
3a4c8000 987 CASE (BRgoto):
14726871 988 MAYBE_GC ();
e12ea64e 989 BYTE_CODE_QUIT;
7ca1e8b7 990 stack.pc += (int) *stack.pc - 127;
3a4c8000 991 NEXT;
63639d44 992
3a4c8000 993 CASE (BRgotoifnil):
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 (BRgotoifnonnil):
21ed6de3
KR
1008 {
1009 Lisp_Object v1;
1010 MAYBE_GC ();
1011 v1 = POP;
1012 if (!NILP (v1))
1013 {
1014 BYTE_CODE_QUIT;
1015 stack.pc += (int) *stack.pc - 128;
1016 }
1017 stack.pc++;
3a4c8000 1018 NEXT;
21ed6de3 1019 }
63639d44 1020
3a4c8000 1021 CASE (BRgotoifnilelsepop):
14726871 1022 MAYBE_GC ();
7ca1e8b7 1023 op = *stack.pc++;
63639d44
JB
1024 if (NILP (TOP))
1025 {
e12ea64e 1026 BYTE_CODE_QUIT;
7ca1e8b7 1027 stack.pc += op - 128;
63639d44
JB
1028 }
1029 else DISCARD (1);
3a4c8000 1030 NEXT;
63639d44 1031
3a4c8000 1032 CASE (BRgotoifnonnilelsepop):
14726871 1033 MAYBE_GC ();
7ca1e8b7 1034 op = *stack.pc++;
63639d44
JB
1035 if (!NILP (TOP))
1036 {
e12ea64e 1037 BYTE_CODE_QUIT;
7ca1e8b7 1038 stack.pc += op - 128;
63639d44
JB
1039 }
1040 else DISCARD (1);
3a4c8000 1041 NEXT;
98bf0c8d 1042
3a4c8000 1043 CASE (Breturn):
4015b3c0 1044 result = POP;
36f7ba0a
JB
1045 goto exit;
1046
3a4c8000 1047 CASE (Bdiscard):
63639d44 1048 DISCARD (1);
3a4c8000 1049 NEXT;
36f7ba0a 1050
3a4c8000 1051 CASE (Bconstant2):
36f7ba0a 1052 PUSH (vectorp[FETCH2]);
3a4c8000 1053 NEXT;
36f7ba0a 1054
3a4c8000 1055 CASE (Bsave_excursion):
fa9aabf6
GM
1056 record_unwind_protect (save_excursion_restore,
1057 save_excursion_save ());
3a4c8000 1058 NEXT;
36f7ba0a 1059
3a4c8000
TT
1060 CASE (Bsave_current_buffer): /* Obsolete since ??. */
1061 CASE (Bsave_current_buffer_1):
66322887 1062 record_unwind_current_buffer ();
3a4c8000 1063 NEXT;
3b841abc 1064
3a4c8000 1065 CASE (Bsave_window_excursion): /* Obsolete since 24.1. */
e0f57e65 1066 {
d311d28c 1067 register ptrdiff_t count1 = SPECPDL_INDEX ();
e0f57e65
SM
1068 record_unwind_protect (Fset_window_configuration,
1069 Fcurrent_window_configuration (Qnil));
1070 BEFORE_POTENTIAL_GC ();
1071 TOP = Fprogn (TOP);
fdfc4bf3 1072 unbind_to (count1, TOP);
e0f57e65 1073 AFTER_POTENTIAL_GC ();
3a4c8000 1074 NEXT;
e0f57e65 1075 }
36f7ba0a 1076
3a4c8000 1077 CASE (Bsave_restriction):
fa9aabf6
GM
1078 record_unwind_protect (save_restriction_restore,
1079 save_restriction_save ());
3a4c8000 1080 NEXT;
36f7ba0a 1081
3a4c8000 1082 CASE (Bcatch): /* FIXME: ill-suited for lexbind. */
4015b3c0
GM
1083 {
1084 Lisp_Object v1;
4015b3c0 1085 BEFORE_POTENTIAL_GC ();
bf1de43e 1086 v1 = POP;
ca105506 1087 TOP = internal_catch (TOP, eval_sub, v1);
4015b3c0 1088 AFTER_POTENTIAL_GC ();
3a4c8000 1089 NEXT;
4015b3c0 1090 }
36f7ba0a 1091
3a4c8000 1092 CASE (Bunwind_protect): /* FIXME: avoid closure for lexbind. */
ba3fb063 1093 record_unwind_protect (Fprogn, POP);
3a4c8000 1094 NEXT;
36f7ba0a 1095
3a4c8000 1096 CASE (Bcondition_case): /* FIXME: ill-suited for lexbind. */
4015b3c0 1097 {
5c125a13
RS
1098 Lisp_Object handlers, body;
1099 handlers = POP;
1100 body = POP;
4015b3c0 1101 BEFORE_POTENTIAL_GC ();
5c125a13 1102 TOP = internal_lisp_condition_case (TOP, body, handlers);
4015b3c0 1103 AFTER_POTENTIAL_GC ();
3a4c8000 1104 NEXT;
4015b3c0 1105 }
36f7ba0a 1106
3a4c8000 1107 CASE (Btemp_output_buffer_setup): /* Obsolete since 24.1. */
4015b3c0 1108 BEFORE_POTENTIAL_GC ();
b7826503 1109 CHECK_STRING (TOP);
42a5b22f 1110 temp_output_buffer_setup (SSDATA (TOP));
4015b3c0 1111 AFTER_POTENTIAL_GC ();
36f7ba0a 1112 TOP = Vstandard_output;
3a4c8000 1113 NEXT;
36f7ba0a 1114
3a4c8000 1115 CASE (Btemp_output_buffer_show): /* Obsolete since 24.1. */
4015b3c0
GM
1116 {
1117 Lisp_Object v1;
4015b3c0 1118 BEFORE_POTENTIAL_GC ();
bf1de43e 1119 v1 = POP;
4015b3c0
GM
1120 temp_output_buffer_show (TOP);
1121 TOP = v1;
1122 /* pop binding of standard-output */
aed13378 1123 unbind_to (SPECPDL_INDEX () - 1, Qnil);
4015b3c0 1124 AFTER_POTENTIAL_GC ();
3a4c8000 1125 NEXT;
4015b3c0 1126 }
36f7ba0a 1127
3a4c8000 1128 CASE (Bnth):
4015b3c0
GM
1129 {
1130 Lisp_Object v1, v2;
d311d28c 1131 EMACS_INT n;
bf1de43e 1132 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1133 v1 = POP;
1134 v2 = TOP;
b7826503 1135 CHECK_NUMBER (v2);
d311d28c 1136 n = XINT (v2);
4015b3c0 1137 immediate_quit = 1;
d311d28c 1138 while (--n >= 0 && CONSP (v1))
14c5155a 1139 v1 = XCDR (v1);
4015b3c0 1140 immediate_quit = 0;
14c5155a 1141 TOP = CAR (v1);
1c470562 1142 AFTER_POTENTIAL_GC ();
3a4c8000 1143 NEXT;
4015b3c0 1144 }
36f7ba0a 1145
3a4c8000 1146 CASE (Bsymbolp):
617bd3f6 1147 TOP = SYMBOLP (TOP) ? Qt : Qnil;
3a4c8000 1148 NEXT;
36f7ba0a 1149
3a4c8000 1150 CASE (Bconsp):
36f7ba0a 1151 TOP = CONSP (TOP) ? Qt : Qnil;
3a4c8000 1152 NEXT;
36f7ba0a 1153
3a4c8000 1154 CASE (Bstringp):
617bd3f6 1155 TOP = STRINGP (TOP) ? Qt : Qnil;
3a4c8000 1156 NEXT;
36f7ba0a 1157
3a4c8000 1158 CASE (Blistp):
921a8935 1159 TOP = CONSP (TOP) || NILP (TOP) ? Qt : Qnil;
3a4c8000 1160 NEXT;
36f7ba0a 1161
3a4c8000 1162 CASE (Bnot):
921a8935 1163 TOP = NILP (TOP) ? Qt : Qnil;
3a4c8000 1164 NEXT;
36f7ba0a 1165
3a4c8000 1166 CASE (Bcons):
4015b3c0
GM
1167 {
1168 Lisp_Object v1;
1169 v1 = POP;
1170 TOP = Fcons (TOP, v1);
3a4c8000 1171 NEXT;
4015b3c0 1172 }
36f7ba0a 1173
3a4c8000 1174 CASE (Blist1):
36f7ba0a 1175 TOP = Fcons (TOP, Qnil);
3a4c8000 1176 NEXT;
36f7ba0a 1177
3a4c8000 1178 CASE (Blist2):
4015b3c0
GM
1179 {
1180 Lisp_Object v1;
1181 v1 = POP;
1182 TOP = Fcons (TOP, Fcons (v1, Qnil));
3a4c8000 1183 NEXT;
4015b3c0 1184 }
36f7ba0a 1185
3a4c8000 1186 CASE (Blist3):
63639d44 1187 DISCARD (2);
36f7ba0a 1188 TOP = Flist (3, &TOP);
3a4c8000 1189 NEXT;
36f7ba0a 1190
3a4c8000 1191 CASE (Blist4):
63639d44 1192 DISCARD (3);
36f7ba0a 1193 TOP = Flist (4, &TOP);
3a4c8000 1194 NEXT;
36f7ba0a 1195
3a4c8000 1196 CASE (BlistN):
63639d44
JB
1197 op = FETCH;
1198 DISCARD (op - 1);
1199 TOP = Flist (op, &TOP);
3a4c8000 1200 NEXT;
63639d44 1201
3a4c8000 1202 CASE (Blength):
bf1de43e 1203 BEFORE_POTENTIAL_GC ();
36f7ba0a 1204 TOP = Flength (TOP);
bf1de43e 1205 AFTER_POTENTIAL_GC ();
3a4c8000 1206 NEXT;
36f7ba0a 1207
3a4c8000 1208 CASE (Baref):
4015b3c0
GM
1209 {
1210 Lisp_Object v1;
bf1de43e 1211 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1212 v1 = POP;
1213 TOP = Faref (TOP, v1);
bf1de43e 1214 AFTER_POTENTIAL_GC ();
3a4c8000 1215 NEXT;
4015b3c0 1216 }
36f7ba0a 1217
3a4c8000 1218 CASE (Baset):
4015b3c0
GM
1219 {
1220 Lisp_Object v1, v2;
bf1de43e 1221 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1222 v2 = POP; v1 = POP;
1223 TOP = Faset (TOP, v1, v2);
bf1de43e 1224 AFTER_POTENTIAL_GC ();
3a4c8000 1225 NEXT;
4015b3c0 1226 }
36f7ba0a 1227
3a4c8000 1228 CASE (Bsymbol_value):
bf1de43e 1229 BEFORE_POTENTIAL_GC ();
36f7ba0a 1230 TOP = Fsymbol_value (TOP);
bf1de43e 1231 AFTER_POTENTIAL_GC ();
3a4c8000 1232 NEXT;
36f7ba0a 1233
3a4c8000 1234 CASE (Bsymbol_function):
bf1de43e 1235 BEFORE_POTENTIAL_GC ();
36f7ba0a 1236 TOP = Fsymbol_function (TOP);
bf1de43e 1237 AFTER_POTENTIAL_GC ();
3a4c8000 1238 NEXT;
36f7ba0a 1239
3a4c8000 1240 CASE (Bset):
4015b3c0
GM
1241 {
1242 Lisp_Object v1;
bf1de43e 1243 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1244 v1 = POP;
1245 TOP = Fset (TOP, v1);
bf1de43e 1246 AFTER_POTENTIAL_GC ();
3a4c8000 1247 NEXT;
4015b3c0 1248 }
36f7ba0a 1249
3a4c8000 1250 CASE (Bfset):
4015b3c0
GM
1251 {
1252 Lisp_Object v1;
bf1de43e 1253 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1254 v1 = POP;
1255 TOP = Ffset (TOP, v1);
bf1de43e 1256 AFTER_POTENTIAL_GC ();
3a4c8000 1257 NEXT;
4015b3c0 1258 }
36f7ba0a 1259
3a4c8000 1260 CASE (Bget):
4015b3c0
GM
1261 {
1262 Lisp_Object v1;
bf1de43e 1263 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1264 v1 = POP;
1265 TOP = Fget (TOP, v1);
bf1de43e 1266 AFTER_POTENTIAL_GC ();
3a4c8000 1267 NEXT;
4015b3c0 1268 }
36f7ba0a 1269
3a4c8000 1270 CASE (Bsubstring):
4015b3c0
GM
1271 {
1272 Lisp_Object v1, v2;
fa9aabf6 1273 BEFORE_POTENTIAL_GC ();
bf1de43e 1274 v2 = POP; v1 = POP;
4015b3c0 1275 TOP = Fsubstring (TOP, v1, v2);
fa9aabf6 1276 AFTER_POTENTIAL_GC ();
3a4c8000 1277 NEXT;
4015b3c0 1278 }
36f7ba0a 1279
3a4c8000 1280 CASE (Bconcat2):
bf1de43e 1281 BEFORE_POTENTIAL_GC ();
63639d44 1282 DISCARD (1);
36f7ba0a 1283 TOP = Fconcat (2, &TOP);
bf1de43e 1284 AFTER_POTENTIAL_GC ();
3a4c8000 1285 NEXT;
36f7ba0a 1286
3a4c8000 1287 CASE (Bconcat3):
bf1de43e 1288 BEFORE_POTENTIAL_GC ();
63639d44 1289 DISCARD (2);
36f7ba0a 1290 TOP = Fconcat (3, &TOP);
bf1de43e 1291 AFTER_POTENTIAL_GC ();
3a4c8000 1292 NEXT;
36f7ba0a 1293
3a4c8000 1294 CASE (Bconcat4):
bf1de43e 1295 BEFORE_POTENTIAL_GC ();
63639d44 1296 DISCARD (3);
36f7ba0a 1297 TOP = Fconcat (4, &TOP);
bf1de43e 1298 AFTER_POTENTIAL_GC ();
3a4c8000 1299 NEXT;
36f7ba0a 1300
3a4c8000 1301 CASE (BconcatN):
63639d44 1302 op = FETCH;
bf1de43e 1303 BEFORE_POTENTIAL_GC ();
63639d44
JB
1304 DISCARD (op - 1);
1305 TOP = Fconcat (op, &TOP);
bf1de43e 1306 AFTER_POTENTIAL_GC ();
3a4c8000 1307 NEXT;
63639d44 1308
3a4c8000 1309 CASE (Bsub1):
4015b3c0
GM
1310 {
1311 Lisp_Object v1;
1312 v1 = TOP;
1313 if (INTEGERP (v1))
1314 {
1315 XSETINT (v1, XINT (v1) - 1);
1316 TOP = v1;
1317 }
1318 else
e494eee5
MB
1319 {
1320 BEFORE_POTENTIAL_GC ();
1321 TOP = Fsub1 (v1);
1322 AFTER_POTENTIAL_GC ();
1323 }
3a4c8000 1324 NEXT;
4015b3c0 1325 }
36f7ba0a 1326
3a4c8000 1327 CASE (Badd1):
4015b3c0
GM
1328 {
1329 Lisp_Object v1;
1330 v1 = TOP;
1331 if (INTEGERP (v1))
1332 {
1333 XSETINT (v1, XINT (v1) + 1);
1334 TOP = v1;
1335 }
1336 else
bf1de43e
GM
1337 {
1338 BEFORE_POTENTIAL_GC ();
1339 TOP = Fadd1 (v1);
1340 AFTER_POTENTIAL_GC ();
1341 }
3a4c8000 1342 NEXT;
4015b3c0 1343 }
36f7ba0a 1344
3a4c8000 1345 CASE (Beqlsign):
4015b3c0
GM
1346 {
1347 Lisp_Object v1, v2;
f5941bf8 1348 BEFORE_POTENTIAL_GC ();
bf1de43e 1349 v2 = POP; v1 = TOP;
b7826503
PJ
1350 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v1);
1351 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (v2);
f5941bf8 1352 AFTER_POTENTIAL_GC ();
4015b3c0
GM
1353 if (FLOATP (v1) || FLOATP (v2))
1354 {
1355 double f1, f2;
1356
1357 f1 = (FLOATP (v1) ? XFLOAT_DATA (v1) : XINT (v1));
1358 f2 = (FLOATP (v2) ? XFLOAT_DATA (v2) : XINT (v2));
1359 TOP = (f1 == f2 ? Qt : Qnil);
1360 }
1361 else
4015b3c0 1362 TOP = (XINT (v1) == XINT (v2) ? Qt : Qnil);
3a4c8000 1363 NEXT;
4015b3c0 1364 }
36f7ba0a 1365
3a4c8000 1366 CASE (Bgtr):
4015b3c0
GM
1367 {
1368 Lisp_Object v1;
bf1de43e 1369 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1370 v1 = POP;
1371 TOP = Fgtr (TOP, v1);
bf1de43e 1372 AFTER_POTENTIAL_GC ();
3a4c8000 1373 NEXT;
4015b3c0 1374 }
36f7ba0a 1375
3a4c8000 1376 CASE (Blss):
4015b3c0
GM
1377 {
1378 Lisp_Object v1;
bf1de43e 1379 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1380 v1 = POP;
1381 TOP = Flss (TOP, v1);
bf1de43e 1382 AFTER_POTENTIAL_GC ();
3a4c8000 1383 NEXT;
4015b3c0 1384 }
36f7ba0a 1385
3a4c8000 1386 CASE (Bleq):
4015b3c0
GM
1387 {
1388 Lisp_Object v1;
bf1de43e 1389 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1390 v1 = POP;
1391 TOP = Fleq (TOP, v1);
bf1de43e 1392 AFTER_POTENTIAL_GC ();
3a4c8000 1393 NEXT;
4015b3c0 1394 }
36f7ba0a 1395
3a4c8000 1396 CASE (Bgeq):
4015b3c0
GM
1397 {
1398 Lisp_Object v1;
d9c1f6f9 1399 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1400 v1 = POP;
1401 TOP = Fgeq (TOP, v1);
d9c1f6f9 1402 AFTER_POTENTIAL_GC ();
3a4c8000 1403 NEXT;
4015b3c0 1404 }
36f7ba0a 1405
3a4c8000 1406 CASE (Bdiff):
bf1de43e 1407 BEFORE_POTENTIAL_GC ();
63639d44 1408 DISCARD (1);
36f7ba0a 1409 TOP = Fminus (2, &TOP);
bf1de43e 1410 AFTER_POTENTIAL_GC ();
3a4c8000 1411 NEXT;
36f7ba0a 1412
3a4c8000 1413 CASE (Bnegate):
4015b3c0
GM
1414 {
1415 Lisp_Object v1;
1416 v1 = TOP;
1417 if (INTEGERP (v1))
1418 {
1419 XSETINT (v1, - XINT (v1));
1420 TOP = v1;
1421 }
1422 else
bf1de43e
GM
1423 {
1424 BEFORE_POTENTIAL_GC ();
1425 TOP = Fminus (1, &TOP);
1426 AFTER_POTENTIAL_GC ();
1427 }
3a4c8000 1428 NEXT;
4015b3c0 1429 }
36f7ba0a 1430
3a4c8000 1431 CASE (Bplus):
bf1de43e 1432 BEFORE_POTENTIAL_GC ();
63639d44 1433 DISCARD (1);
36f7ba0a 1434 TOP = Fplus (2, &TOP);
bf1de43e 1435 AFTER_POTENTIAL_GC ();
3a4c8000 1436 NEXT;
36f7ba0a 1437
3a4c8000 1438 CASE (Bmax):
bf1de43e 1439 BEFORE_POTENTIAL_GC ();
63639d44 1440 DISCARD (1);
36f7ba0a 1441 TOP = Fmax (2, &TOP);
bf1de43e 1442 AFTER_POTENTIAL_GC ();
3a4c8000 1443 NEXT;
36f7ba0a 1444
3a4c8000 1445 CASE (Bmin):
bf1de43e 1446 BEFORE_POTENTIAL_GC ();
63639d44 1447 DISCARD (1);
36f7ba0a 1448 TOP = Fmin (2, &TOP);
bf1de43e 1449 AFTER_POTENTIAL_GC ();
3a4c8000 1450 NEXT;
36f7ba0a 1451
3a4c8000 1452 CASE (Bmult):
bf1de43e 1453 BEFORE_POTENTIAL_GC ();
63639d44 1454 DISCARD (1);
36f7ba0a 1455 TOP = Ftimes (2, &TOP);
bf1de43e 1456 AFTER_POTENTIAL_GC ();
3a4c8000 1457 NEXT;
36f7ba0a 1458
3a4c8000 1459 CASE (Bquo):
bf1de43e 1460 BEFORE_POTENTIAL_GC ();
63639d44 1461 DISCARD (1);
36f7ba0a 1462 TOP = Fquo (2, &TOP);
bf1de43e 1463 AFTER_POTENTIAL_GC ();
3a4c8000 1464 NEXT;
36f7ba0a 1465
3a4c8000 1466 CASE (Brem):
4015b3c0
GM
1467 {
1468 Lisp_Object v1;
bf1de43e 1469 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1470 v1 = POP;
1471 TOP = Frem (TOP, v1);
bf1de43e 1472 AFTER_POTENTIAL_GC ();
3a4c8000 1473 NEXT;
4015b3c0 1474 }
36f7ba0a 1475
3a4c8000 1476 CASE (Bpoint):
4015b3c0
GM
1477 {
1478 Lisp_Object v1;
1479 XSETFASTINT (v1, PT);
1480 PUSH (v1);
3a4c8000 1481 NEXT;
4015b3c0 1482 }
36f7ba0a 1483
3a4c8000 1484 CASE (Bgoto_char):
4015b3c0 1485 BEFORE_POTENTIAL_GC ();
36f7ba0a 1486 TOP = Fgoto_char (TOP);
4015b3c0 1487 AFTER_POTENTIAL_GC ();
3a4c8000 1488 NEXT;
36f7ba0a 1489
3a4c8000 1490 CASE (Binsert):
4015b3c0 1491 BEFORE_POTENTIAL_GC ();
36f7ba0a 1492 TOP = Finsert (1, &TOP);
4015b3c0 1493 AFTER_POTENTIAL_GC ();
3a4c8000 1494 NEXT;
36f7ba0a 1495
3a4c8000 1496 CASE (BinsertN):
63639d44 1497 op = FETCH;
4015b3c0 1498 BEFORE_POTENTIAL_GC ();
fa9aabf6 1499 DISCARD (op - 1);
63639d44 1500 TOP = Finsert (op, &TOP);
4015b3c0 1501 AFTER_POTENTIAL_GC ();
3a4c8000 1502 NEXT;
63639d44 1503
3a4c8000 1504 CASE (Bpoint_max):
4015b3c0
GM
1505 {
1506 Lisp_Object v1;
1507 XSETFASTINT (v1, ZV);
1508 PUSH (v1);
3a4c8000 1509 NEXT;
4015b3c0 1510 }
36f7ba0a 1511
3a4c8000 1512 CASE (Bpoint_min):
4015b3c0
GM
1513 {
1514 Lisp_Object v1;
1515 XSETFASTINT (v1, BEGV);
1516 PUSH (v1);
3a4c8000 1517 NEXT;
4015b3c0 1518 }
36f7ba0a 1519
3a4c8000 1520 CASE (Bchar_after):
bf1de43e 1521 BEFORE_POTENTIAL_GC ();
36f7ba0a 1522 TOP = Fchar_after (TOP);
bf1de43e 1523 AFTER_POTENTIAL_GC ();
3a4c8000 1524 NEXT;
36f7ba0a 1525
3a4c8000 1526 CASE (Bfollowing_char):
4015b3c0
GM
1527 {
1528 Lisp_Object v1;
bf1de43e 1529 BEFORE_POTENTIAL_GC ();
4015b3c0 1530 v1 = Ffollowing_char ();
bf1de43e 1531 AFTER_POTENTIAL_GC ();
4015b3c0 1532 PUSH (v1);
3a4c8000 1533 NEXT;
4015b3c0 1534 }
36f7ba0a 1535
3a4c8000 1536 CASE (Bpreceding_char):
4015b3c0
GM
1537 {
1538 Lisp_Object v1;
bf1de43e 1539 BEFORE_POTENTIAL_GC ();
4015b3c0 1540 v1 = Fprevious_char ();
bf1de43e 1541 AFTER_POTENTIAL_GC ();
4015b3c0 1542 PUSH (v1);
3a4c8000 1543 NEXT;
4015b3c0 1544 }
36f7ba0a 1545
3a4c8000 1546 CASE (Bcurrent_column):
4015b3c0
GM
1547 {
1548 Lisp_Object v1;
96111f48 1549 BEFORE_POTENTIAL_GC ();
7831777b 1550 XSETFASTINT (v1, current_column ());
96111f48 1551 AFTER_POTENTIAL_GC ();
4015b3c0 1552 PUSH (v1);
3a4c8000 1553 NEXT;
4015b3c0 1554 }
36f7ba0a 1555
3a4c8000 1556 CASE (Bindent_to):
4015b3c0 1557 BEFORE_POTENTIAL_GC ();
36f7ba0a 1558 TOP = Findent_to (TOP, Qnil);
4015b3c0 1559 AFTER_POTENTIAL_GC ();
3a4c8000 1560 NEXT;
36f7ba0a 1561
3a4c8000 1562 CASE (Beolp):
36f7ba0a 1563 PUSH (Feolp ());
3a4c8000 1564 NEXT;
36f7ba0a 1565
3a4c8000 1566 CASE (Beobp):
36f7ba0a 1567 PUSH (Feobp ());
3a4c8000 1568 NEXT;
36f7ba0a 1569
3a4c8000 1570 CASE (Bbolp):
36f7ba0a 1571 PUSH (Fbolp ());
3a4c8000 1572 NEXT;
36f7ba0a 1573
3a4c8000 1574 CASE (Bbobp):
36f7ba0a 1575 PUSH (Fbobp ());
3a4c8000 1576 NEXT;
36f7ba0a 1577
3a4c8000 1578 CASE (Bcurrent_buffer):
36f7ba0a 1579 PUSH (Fcurrent_buffer ());
3a4c8000 1580 NEXT;
36f7ba0a 1581
3a4c8000 1582 CASE (Bset_buffer):
4015b3c0 1583 BEFORE_POTENTIAL_GC ();
36f7ba0a 1584 TOP = Fset_buffer (TOP);
4015b3c0 1585 AFTER_POTENTIAL_GC ();
3a4c8000 1586 NEXT;
36f7ba0a 1587
3a4c8000 1588 CASE (Binteractive_p): /* Obsolete since 24.1. */
23ba2705
SM
1589 BEFORE_POTENTIAL_GC ();
1590 PUSH (call0 (intern ("interactive-p")));
1591 AFTER_POTENTIAL_GC ();
3a4c8000 1592 NEXT;
36f7ba0a 1593
3a4c8000 1594 CASE (Bforward_char):
4015b3c0 1595 BEFORE_POTENTIAL_GC ();
36f7ba0a 1596 TOP = Fforward_char (TOP);
4015b3c0 1597 AFTER_POTENTIAL_GC ();
3a4c8000 1598 NEXT;
36f7ba0a 1599
3a4c8000 1600 CASE (Bforward_word):
4015b3c0 1601 BEFORE_POTENTIAL_GC ();
36f7ba0a 1602 TOP = Fforward_word (TOP);
4015b3c0 1603 AFTER_POTENTIAL_GC ();
3a4c8000 1604 NEXT;
36f7ba0a 1605
3a4c8000 1606 CASE (Bskip_chars_forward):
4015b3c0
GM
1607 {
1608 Lisp_Object v1;
4015b3c0 1609 BEFORE_POTENTIAL_GC ();
bf1de43e 1610 v1 = POP;
4015b3c0
GM
1611 TOP = Fskip_chars_forward (TOP, v1);
1612 AFTER_POTENTIAL_GC ();
3a4c8000 1613 NEXT;
4015b3c0 1614 }
36f7ba0a 1615
3a4c8000 1616 CASE (Bskip_chars_backward):
4015b3c0
GM
1617 {
1618 Lisp_Object v1;
4015b3c0 1619 BEFORE_POTENTIAL_GC ();
bf1de43e 1620 v1 = POP;
4015b3c0
GM
1621 TOP = Fskip_chars_backward (TOP, v1);
1622 AFTER_POTENTIAL_GC ();
3a4c8000 1623 NEXT;
4015b3c0 1624 }
36f7ba0a 1625
3a4c8000 1626 CASE (Bforward_line):
4015b3c0 1627 BEFORE_POTENTIAL_GC ();
36f7ba0a 1628 TOP = Fforward_line (TOP);
4015b3c0 1629 AFTER_POTENTIAL_GC ();
3a4c8000 1630 NEXT;
36f7ba0a 1631
3a4c8000 1632 CASE (Bchar_syntax):
9281d077
KH
1633 {
1634 int c;
1635
1636 BEFORE_POTENTIAL_GC ();
1637 CHECK_CHARACTER (TOP);
1638 AFTER_POTENTIAL_GC ();
1639 c = XFASTINT (TOP);
4b4deea2 1640 if (NILP (BVAR (current_buffer, enable_multibyte_characters)))
9281d077 1641 MAKE_CHAR_MULTIBYTE (c);
1fc71008 1642 XSETFASTINT (TOP, syntax_code_spec[SYNTAX (c)]);
8f924df7 1643 }
3a4c8000 1644 NEXT;
36f7ba0a 1645
3a4c8000 1646 CASE (Bbuffer_substring):
4015b3c0
GM
1647 {
1648 Lisp_Object v1;
4015b3c0 1649 BEFORE_POTENTIAL_GC ();
bf1de43e 1650 v1 = POP;
4015b3c0
GM
1651 TOP = Fbuffer_substring (TOP, v1);
1652 AFTER_POTENTIAL_GC ();
3a4c8000 1653 NEXT;
4015b3c0 1654 }
36f7ba0a 1655
3a4c8000 1656 CASE (Bdelete_region):
4015b3c0
GM
1657 {
1658 Lisp_Object v1;
4015b3c0 1659 BEFORE_POTENTIAL_GC ();
bf1de43e 1660 v1 = POP;
4015b3c0
GM
1661 TOP = Fdelete_region (TOP, v1);
1662 AFTER_POTENTIAL_GC ();
3a4c8000 1663 NEXT;
4015b3c0 1664 }
36f7ba0a 1665
3a4c8000 1666 CASE (Bnarrow_to_region):
4015b3c0
GM
1667 {
1668 Lisp_Object v1;
4015b3c0 1669 BEFORE_POTENTIAL_GC ();
bf1de43e 1670 v1 = POP;
4015b3c0
GM
1671 TOP = Fnarrow_to_region (TOP, v1);
1672 AFTER_POTENTIAL_GC ();
3a4c8000 1673 NEXT;
4015b3c0 1674 }
36f7ba0a 1675
3a4c8000 1676 CASE (Bwiden):
4015b3c0 1677 BEFORE_POTENTIAL_GC ();
36f7ba0a 1678 PUSH (Fwiden ());
4015b3c0 1679 AFTER_POTENTIAL_GC ();
3a4c8000 1680 NEXT;
36f7ba0a 1681
3a4c8000 1682 CASE (Bend_of_line):
4015b3c0 1683 BEFORE_POTENTIAL_GC ();
63639d44 1684 TOP = Fend_of_line (TOP);
4015b3c0 1685 AFTER_POTENTIAL_GC ();
3a4c8000 1686 NEXT;
63639d44 1687
3a4c8000 1688 CASE (Bset_marker):
4015b3c0
GM
1689 {
1690 Lisp_Object v1, v2;
bf1de43e 1691 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1692 v1 = POP;
1693 v2 = POP;
1694 TOP = Fset_marker (TOP, v2, v1);
bf1de43e 1695 AFTER_POTENTIAL_GC ();
3a4c8000 1696 NEXT;
4015b3c0 1697 }
63639d44 1698
3a4c8000 1699 CASE (Bmatch_beginning):
bf1de43e 1700 BEFORE_POTENTIAL_GC ();
63639d44 1701 TOP = Fmatch_beginning (TOP);
bf1de43e 1702 AFTER_POTENTIAL_GC ();
3a4c8000 1703 NEXT;
63639d44 1704
3a4c8000 1705 CASE (Bmatch_end):
bf1de43e 1706 BEFORE_POTENTIAL_GC ();
63639d44 1707 TOP = Fmatch_end (TOP);
bf1de43e 1708 AFTER_POTENTIAL_GC ();
3a4c8000 1709 NEXT;
63639d44 1710
3a4c8000 1711 CASE (Bupcase):
bf1de43e 1712 BEFORE_POTENTIAL_GC ();
63639d44 1713 TOP = Fupcase (TOP);
bf1de43e 1714 AFTER_POTENTIAL_GC ();
3a4c8000 1715 NEXT;
63639d44 1716
3a4c8000 1717 CASE (Bdowncase):
bf1de43e 1718 BEFORE_POTENTIAL_GC ();
63639d44 1719 TOP = Fdowncase (TOP);
bf1de43e 1720 AFTER_POTENTIAL_GC ();
3a4c8000 1721 NEXT;
63639d44 1722
3a4c8000 1723 CASE (Bstringeqlsign):
4015b3c0
GM
1724 {
1725 Lisp_Object v1;
bf1de43e 1726 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1727 v1 = POP;
1728 TOP = Fstring_equal (TOP, v1);
bf1de43e 1729 AFTER_POTENTIAL_GC ();
3a4c8000 1730 NEXT;
4015b3c0 1731 }
36f7ba0a 1732
3a4c8000 1733 CASE (Bstringlss):
4015b3c0
GM
1734 {
1735 Lisp_Object v1;
bf1de43e 1736 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1737 v1 = POP;
1738 TOP = Fstring_lessp (TOP, v1);
bf1de43e 1739 AFTER_POTENTIAL_GC ();
3a4c8000 1740 NEXT;
4015b3c0 1741 }
36f7ba0a 1742
3a4c8000 1743 CASE (Bequal):
4015b3c0
GM
1744 {
1745 Lisp_Object v1;
1746 v1 = POP;
1747 TOP = Fequal (TOP, v1);
3a4c8000 1748 NEXT;
4015b3c0 1749 }
36f7ba0a 1750
3a4c8000 1751 CASE (Bnthcdr):
4015b3c0
GM
1752 {
1753 Lisp_Object v1;
bf1de43e 1754 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1755 v1 = POP;
1756 TOP = Fnthcdr (TOP, v1);
bf1de43e 1757 AFTER_POTENTIAL_GC ();
3a4c8000 1758 NEXT;
4015b3c0 1759 }
36f7ba0a 1760
3a4c8000 1761 CASE (Belt):
4015b3c0
GM
1762 {
1763 Lisp_Object v1, v2;
1764 if (CONSP (TOP))
1765 {
1766 /* Exchange args and then do nth. */
d311d28c 1767 EMACS_INT n;
bf1de43e 1768 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1769 v2 = POP;
1770 v1 = TOP;
b7826503 1771 CHECK_NUMBER (v2);
f5941bf8 1772 AFTER_POTENTIAL_GC ();
d311d28c 1773 n = XINT (v2);
4015b3c0 1774 immediate_quit = 1;
d311d28c 1775 while (--n >= 0 && CONSP (v1))
14c5155a 1776 v1 = XCDR (v1);
4015b3c0 1777 immediate_quit = 0;
14c5155a 1778 TOP = CAR (v1);
4015b3c0
GM
1779 }
1780 else
1781 {
bf1de43e 1782 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1783 v1 = POP;
1784 TOP = Felt (TOP, v1);
bf1de43e 1785 AFTER_POTENTIAL_GC ();
4015b3c0 1786 }
3a4c8000 1787 NEXT;
4015b3c0 1788 }
36f7ba0a 1789
3a4c8000 1790 CASE (Bmember):
4015b3c0
GM
1791 {
1792 Lisp_Object v1;
bf1de43e 1793 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1794 v1 = POP;
1795 TOP = Fmember (TOP, v1);
bf1de43e 1796 AFTER_POTENTIAL_GC ();
3a4c8000 1797 NEXT;
4015b3c0 1798 }
36f7ba0a 1799
3a4c8000 1800 CASE (Bassq):
4015b3c0
GM
1801 {
1802 Lisp_Object v1;
bf1de43e 1803 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1804 v1 = POP;
1805 TOP = Fassq (TOP, v1);
bf1de43e 1806 AFTER_POTENTIAL_GC ();
3a4c8000 1807 NEXT;
4015b3c0 1808 }
36f7ba0a 1809
3a4c8000 1810 CASE (Bnreverse):
bf1de43e 1811 BEFORE_POTENTIAL_GC ();
36f7ba0a 1812 TOP = Fnreverse (TOP);
bf1de43e 1813 AFTER_POTENTIAL_GC ();
3a4c8000 1814 NEXT;
36f7ba0a 1815
3a4c8000 1816 CASE (Bsetcar):
4015b3c0
GM
1817 {
1818 Lisp_Object v1;
bf1de43e 1819 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1820 v1 = POP;
1821 TOP = Fsetcar (TOP, v1);
bf1de43e 1822 AFTER_POTENTIAL_GC ();
3a4c8000 1823 NEXT;
4015b3c0 1824 }
36f7ba0a 1825
3a4c8000 1826 CASE (Bsetcdr):
4015b3c0
GM
1827 {
1828 Lisp_Object v1;
bf1de43e 1829 BEFORE_POTENTIAL_GC ();
4015b3c0
GM
1830 v1 = POP;
1831 TOP = Fsetcdr (TOP, v1);
bf1de43e 1832 AFTER_POTENTIAL_GC ();
3a4c8000 1833 NEXT;
4015b3c0 1834 }
36f7ba0a 1835
3a4c8000 1836 CASE (Bcar_safe):
4015b3c0
GM
1837 {
1838 Lisp_Object v1;
1839 v1 = TOP;
14c5155a 1840 TOP = CAR_SAFE (v1);
3a4c8000 1841 NEXT;
4015b3c0 1842 }
36f7ba0a 1843
3a4c8000 1844 CASE (Bcdr_safe):
4015b3c0
GM
1845 {
1846 Lisp_Object v1;
1847 v1 = TOP;
14c5155a 1848 TOP = CDR_SAFE (v1);
3a4c8000 1849 NEXT;
4015b3c0 1850 }
36f7ba0a 1851
3a4c8000 1852 CASE (Bnconc):
bf1de43e 1853 BEFORE_POTENTIAL_GC ();
63639d44 1854 DISCARD (1);
36f7ba0a 1855 TOP = Fnconc (2, &TOP);
bf1de43e 1856 AFTER_POTENTIAL_GC ();
3a4c8000 1857 NEXT;
36f7ba0a 1858
3a4c8000 1859 CASE (Bnumberp):
63639d44 1860 TOP = (NUMBERP (TOP) ? Qt : Qnil);
3a4c8000 1861 NEXT;
36f7ba0a 1862
3a4c8000 1863 CASE (Bintegerp):
617bd3f6 1864 TOP = INTEGERP (TOP) ? Qt : Qnil;
3a4c8000 1865 NEXT;
36f7ba0a
JB
1866
1867#ifdef BYTE_CODE_SAFE
3a4c8000
TT
1868 /* These are intentionally written using 'case' syntax,
1869 because they are incompatible with the threaded
1870 interpreter. */
1871
36f7ba0a 1872 case Bset_mark:
f5941bf8 1873 BEFORE_POTENTIAL_GC ();
36f7ba0a 1874 error ("set-mark is an obsolete bytecode");
f5941bf8 1875 AFTER_POTENTIAL_GC ();
36f7ba0a
JB
1876 break;
1877 case Bscan_buffer:
f5941bf8 1878 BEFORE_POTENTIAL_GC ();
36f7ba0a 1879 error ("scan-buffer is an obsolete bytecode");
f5941bf8 1880 AFTER_POTENTIAL_GC ();
36f7ba0a 1881 break;
36f7ba0a
JB
1882#endif
1883
3a4c8000 1884 CASE_ABORT:
876c194c
SM
1885 /* Actually this is Bstack_ref with offset 0, but we use Bdup
1886 for that instead. */
3a4c8000 1887 /* CASE (Bstack_ref): */
22e8cf4a 1888 error ("Invalid byte opcode");
c96d71f7 1889
b9598260 1890 /* Handy byte-codes for lexical binding. */
3a4c8000
TT
1891 CASE (Bstack_ref1):
1892 CASE (Bstack_ref2):
1893 CASE (Bstack_ref3):
1894 CASE (Bstack_ref4):
1895 CASE (Bstack_ref5):
3e21b6a7
SM
1896 {
1897 Lisp_Object *ptr = top - (op - Bstack_ref);
1898 PUSH (*ptr);
3a4c8000 1899 NEXT;
3e21b6a7 1900 }
3a4c8000 1901 CASE (Bstack_ref6):
3e21b6a7
SM
1902 {
1903 Lisp_Object *ptr = top - (FETCH);
1904 PUSH (*ptr);
3a4c8000 1905 NEXT;
3e21b6a7 1906 }
3a4c8000 1907 CASE (Bstack_ref7):
3e21b6a7
SM
1908 {
1909 Lisp_Object *ptr = top - (FETCH2);
1910 PUSH (*ptr);
3a4c8000 1911 NEXT;
3e21b6a7 1912 }
3a4c8000 1913 CASE (Bstack_set):
2462470b 1914 /* stack-set-0 = discard; stack-set-1 = discard-1-preserve-tos. */
3e21b6a7
SM
1915 {
1916 Lisp_Object *ptr = top - (FETCH);
1917 *ptr = POP;
3a4c8000 1918 NEXT;
3e21b6a7 1919 }
3a4c8000 1920 CASE (Bstack_set2):
3e21b6a7
SM
1921 {
1922 Lisp_Object *ptr = top - (FETCH2);
1923 *ptr = POP;
3a4c8000 1924 NEXT;
3e21b6a7 1925 }
3a4c8000 1926 CASE (BdiscardN):
b9598260
SM
1927 op = FETCH;
1928 if (op & 0x80)
1929 {
1930 op &= 0x7F;
1931 top[-op] = TOP;
1932 }
1933 DISCARD (op);
3a4c8000 1934 NEXT;
c96d71f7 1935
3a4c8000
TT
1936 CASE_DEFAULT
1937 CASE (Bconstant):
36f7ba0a
JB
1938#ifdef BYTE_CODE_SAFE
1939 if (op < Bconstant)
f5941bf8 1940 {
1088b922 1941 emacs_abort ();
f5941bf8 1942 }
36f7ba0a 1943 if ((op -= Bconstant) >= const_length)
f5941bf8 1944 {
1088b922 1945 emacs_abort ();
f5941bf8 1946 }
36f7ba0a
JB
1947 PUSH (vectorp[op]);
1948#else
1949 PUSH (vectorp[op - Bconstant]);
1950#endif
3a4c8000 1951 NEXT;
36f7ba0a
JB
1952 }
1953 }
1954
1955 exit:
7ca1e8b7
GM
1956
1957 byte_stack_list = byte_stack_list->next;
1958
36f7ba0a 1959 /* Binds and unbinds are supposed to be compiled balanced. */
aed13378 1960 if (SPECPDL_INDEX () != count)
36f7ba0a
JB
1961#ifdef BYTE_CODE_SAFE
1962 error ("binding stack not balanced (serious byte compiler bug)");
1963#else
1088b922 1964 emacs_abort ();
36f7ba0a 1965#endif
8e11578b 1966
4015b3c0 1967 return result;
36f7ba0a
JB
1968}
1969
dfcf069d 1970void
971de7fb 1971syms_of_bytecode (void)
36f7ba0a 1972{
36f7ba0a
JB
1973 defsubr (&Sbyte_code);
1974
1975#ifdef BYTE_CODE_METER
1976
29208e82 1977 DEFVAR_LISP ("byte-code-meter", Vbyte_code_meter,
39f624fa
PJ
1978 doc: /* A vector of vectors which holds a histogram of byte-code usage.
1979\(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
1980opcode CODE has been executed.
1981\(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
1982indicates how many times the byte opcodes CODE1 and CODE2 have been
1983executed in succession. */);
8e11578b 1984
29208e82 1985 DEFVAR_BOOL ("byte-metering-on", byte_metering_on,
39f624fa
PJ
1986 doc: /* If non-nil, keep profiling information on byte code usage.
1987The variable byte-code-meter indicates how often each byte opcode is used.
1988If a symbol has a property named `byte-code-meter' whose value is an
1989integer, it is incremented each time that symbol's function is called. */);
36f7ba0a
JB
1990
1991 byte_metering_on = 0;
63639d44 1992 Vbyte_code_meter = Fmake_vector (make_number (256), make_number (0));
cd3520a4 1993 DEFSYM (Qbyte_code_meter, "byte-code-meter");
36f7ba0a
JB
1994 {
1995 int i = 256;
1996 while (i--)
28be1ada
DA
1997 ASET (Vbyte_code_meter, i,
1998 Fmake_vector (make_number (256), make_number (0)));
36f7ba0a
JB
1999 }
2000#endif
2001}