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