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