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