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