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