0
|
1 /* Execution of byte code produced by bytecomp.el.
|
|
2 Copyright (C) 1992, 1993 Free Software Foundation, Inc.
|
|
3
|
|
4 This file is part of XEmacs.
|
|
5
|
|
6 XEmacs is free software; you can redistribute it and/or modify it
|
|
7 under the terms of the GNU General Public License as published by the
|
|
8 Free Software Foundation; either version 2, or (at your option) any
|
|
9 later version.
|
|
10
|
|
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 for more details.
|
|
15
|
|
16 You should have received a copy of the GNU General Public License
|
|
17 along with XEmacs; see the file COPYING. If not, write to
|
|
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
19 Boston, MA 02111-1307, USA. */
|
|
20
|
|
21 /* Synched up with: Mule 2.0, FSF 19.30. */
|
|
22
|
70
|
23 /* This file has been Mule-ized. */
|
|
24
|
|
25
|
0
|
26 /* Authorship:
|
|
27
|
|
28 FSF: long ago.
|
|
29
|
149
|
30 hacked on by jwz@netscape.com 17-jun-91
|
0
|
31 o added a compile-time switch to turn on simple sanity checking;
|
|
32 o put back the obsolete byte-codes for error-detection;
|
|
33 o added a new instruction, unbind_all, which I will use for
|
|
34 tail-recursion elimination;
|
|
35 o made temp_output_buffer_show be called with the right number
|
|
36 of args;
|
|
37 o made the new bytecodes be called with args in the right order;
|
|
38 o added metering support.
|
|
39
|
|
40 by Hallvard:
|
|
41 o added relative jump instructions;
|
|
42 o all conditionals now only do QUIT if they jump.
|
70
|
43
|
|
44 Ben Wing: some changes for Mule, June 1995.
|
0
|
45 */
|
|
46
|
|
47 #include <config.h>
|
|
48 #include "lisp.h"
|
|
49 #include "buffer.h"
|
|
50 #include "syntax.h"
|
|
51
|
|
52 /*
|
|
53 * define BYTE_CODE_SAFE to enable some minor sanity checking (useful for
|
|
54 * debugging the byte compiler...) Somewhat surprisingly, defining this
|
|
55 * makes Fbyte_code about 8% slower.
|
|
56 *
|
|
57 * define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
|
|
58 */
|
70
|
59 #define BYTE_CODE_SAFE
|
0
|
60 /* #define BYTE_CODE_METER */
|
|
61
|
|
62
|
|
63 #ifdef BYTE_CODE_METER
|
|
64
|
|
65 Lisp_Object Vbyte_code_meter, Qbyte_code_meter;
|
|
66 int byte_metering_on;
|
|
67
|
|
68 #define METER_2(code1, code2) \
|
|
69 XINT (XVECTOR (vector_data (XVECTOR (Vbyte_code_meter))[(code1)]) \
|
|
70 ->contents[(code2)])
|
|
71
|
|
72 #define METER_1(code) METER_2 (0, (code))
|
|
73
|
|
74 #define METER_CODE(last_code, this_code) \
|
|
75 { \
|
|
76 if (byte_metering_on) \
|
|
77 { \
|
|
78 if (METER_1 (this_code) != ((1<<VALBITS)-1)) \
|
|
79 METER_1 (this_code)++; \
|
|
80 if (last_code \
|
|
81 && METER_2 (last_code, this_code) != ((1<<VALBITS)-1))\
|
|
82 METER_2 (last_code, this_code)++; \
|
|
83 } \
|
|
84 }
|
|
85
|
|
86 #endif /* no BYTE_CODE_METER */
|
|
87
|
|
88
|
|
89 Lisp_Object Qbyte_code;
|
|
90
|
|
91 /* Byte codes: */
|
|
92
|
|
93 #define Bvarref 010
|
|
94 #define Bvarset 020
|
|
95 #define Bvarbind 030
|
|
96 #define Bcall 040
|
|
97 #define Bunbind 050
|
|
98
|
|
99 #define Bnth 070
|
|
100 #define Bsymbolp 071
|
|
101 #define Bconsp 072
|
|
102 #define Bstringp 073
|
|
103 #define Blistp 074
|
70
|
104 #define Bold_eq 075
|
|
105 #define Bold_memq 076
|
0
|
106 #define Bnot 077
|
|
107 #define Bcar 0100
|
|
108 #define Bcdr 0101
|
|
109 #define Bcons 0102
|
|
110 #define Blist1 0103
|
|
111 #define Blist2 0104
|
|
112 #define Blist3 0105
|
|
113 #define Blist4 0106
|
|
114 #define Blength 0107
|
|
115 #define Baref 0110
|
|
116 #define Baset 0111
|
|
117 #define Bsymbol_value 0112
|
|
118 #define Bsymbol_function 0113
|
|
119 #define Bset 0114
|
|
120 #define Bfset 0115
|
|
121 #define Bget 0116
|
|
122 #define Bsubstring 0117
|
|
123 #define Bconcat2 0120
|
|
124 #define Bconcat3 0121
|
|
125 #define Bconcat4 0122
|
|
126 #define Bsub1 0123
|
|
127 #define Badd1 0124
|
|
128 #define Beqlsign 0125
|
|
129 #define Bgtr 0126
|
|
130 #define Blss 0127
|
|
131 #define Bleq 0130
|
|
132 #define Bgeq 0131
|
|
133 #define Bdiff 0132
|
|
134 #define Bnegate 0133
|
|
135 #define Bplus 0134
|
|
136 #define Bmax 0135
|
|
137 #define Bmin 0136
|
|
138 #define Bmult 0137
|
|
139
|
|
140 #define Bpoint 0140
|
70
|
141 #define Beq 0141 /* was Bmark, but no longer generated as of v18 */
|
0
|
142 #define Bgoto_char 0142
|
|
143 #define Binsert 0143
|
|
144 #define Bpoint_max 0144
|
|
145 #define Bpoint_min 0145
|
|
146 #define Bchar_after 0146
|
|
147 #define Bfollowing_char 0147
|
|
148 #define Bpreceding_char 0150
|
|
149 #define Bcurrent_column 0151
|
|
150 #define Bindent_to 0152
|
70
|
151 #define Bequal 0153 /* was Bscan_buffer, but no longer generated as of v18 */
|
0
|
152 #define Beolp 0154
|
|
153 #define Beobp 0155
|
|
154 #define Bbolp 0156
|
|
155 #define Bbobp 0157
|
|
156 #define Bcurrent_buffer 0160
|
|
157 #define Bset_buffer 0161
|
161
|
158 #define Bsave_current_buffer 0162 /* was Bread_char, but no longer
|
|
159 generated as of v19 */
|
70
|
160 #define Bmemq 0163 /* was Bset_mark, but no longer generated as of v18 */
|
0
|
161 #define Binteractive_p 0164 /* Needed since interactive-p takes unevalled args */
|
|
162
|
|
163 #define Bforward_char 0165
|
|
164 #define Bforward_word 0166
|
|
165 #define Bskip_chars_forward 0167
|
|
166 #define Bskip_chars_backward 0170
|
|
167 #define Bforward_line 0171
|
|
168 #define Bchar_syntax 0172
|
|
169 #define Bbuffer_substring 0173
|
|
170 #define Bdelete_region 0174
|
|
171 #define Bnarrow_to_region 0175
|
|
172 #define Bwiden 0176
|
|
173 #define Bend_of_line 0177
|
|
174
|
|
175 #define Bconstant2 0201
|
|
176 #define Bgoto 0202
|
|
177 #define Bgotoifnil 0203
|
|
178 #define Bgotoifnonnil 0204
|
|
179 #define Bgotoifnilelsepop 0205
|
|
180 #define Bgotoifnonnilelsepop 0206
|
|
181 #define Breturn 0207
|
|
182 #define Bdiscard 0210
|
|
183 #define Bdup 0211
|
|
184
|
|
185 #define Bsave_excursion 0212
|
|
186 #define Bsave_window_excursion 0213
|
|
187 #define Bsave_restriction 0214
|
|
188 #define Bcatch 0215
|
|
189
|
|
190 #define Bunwind_protect 0216
|
|
191 #define Bcondition_case 0217
|
|
192 #define Btemp_output_buffer_setup 0220
|
|
193 #define Btemp_output_buffer_show 0221
|
|
194
|
|
195 #define Bunbind_all 0222
|
|
196
|
|
197 #define Bset_marker 0223
|
|
198 #define Bmatch_beginning 0224
|
|
199 #define Bmatch_end 0225
|
|
200 #define Bupcase 0226
|
|
201 #define Bdowncase 0227
|
|
202
|
|
203 #define Bstringeqlsign 0230
|
|
204 #define Bstringlss 0231
|
70
|
205 #define Bold_equal 0232
|
0
|
206 #define Bnthcdr 0233
|
|
207 #define Belt 0234
|
70
|
208 #define Bold_member 0235
|
|
209 #define Bold_assq 0236
|
0
|
210 #define Bnreverse 0237
|
|
211 #define Bsetcar 0240
|
|
212 #define Bsetcdr 0241
|
|
213 #define Bcar_safe 0242
|
|
214 #define Bcdr_safe 0243
|
|
215 #define Bnconc 0244
|
|
216 #define Bquo 0245
|
|
217 #define Brem 0246
|
|
218 #define Bnumberp 0247
|
|
219 #define Bintegerp 0250
|
|
220
|
|
221 #define BRgoto 0252
|
|
222 #define BRgotoifnil 0253
|
|
223 #define BRgotoifnonnil 0254
|
|
224 #define BRgotoifnilelsepop 0255
|
|
225 #define BRgotoifnonnilelsepop 0256
|
|
226
|
|
227 #define BlistN 0257
|
|
228 #define BconcatN 0260
|
|
229 #define BinsertN 0261
|
70
|
230 #define Bmember 0266 /* new in v20 */
|
|
231 #define Bassq 0267 /* new in v20 */
|
0
|
232
|
|
233 #define Bconstant 0300
|
|
234 #define CONSTANTLIM 0100
|
|
235
|
|
236 /* Fetch the next byte from the bytecode stream */
|
|
237
|
|
238 #define FETCH (massaged_code[pc++])
|
|
239
|
|
240 /* Fetch two bytes from the bytecode stream
|
|
241 and make a 16-bit number out of them */
|
|
242
|
|
243 #define FETCH2 (op = FETCH, op + (FETCH << 8))
|
|
244
|
|
245 /* Push x onto the execution stack. */
|
|
246
|
|
247 /* This used to be #define PUSH(x) (*++stackp = (x))
|
|
248 This oddity is necessary because Alliant can't be bothered to
|
|
249 compile the preincrement operator properly, as of 4/91. -JimB */
|
|
250 #define PUSH(x) (stackp++, *stackp = (x))
|
|
251
|
|
252 /* Pop a value off the execution stack. */
|
|
253
|
|
254 #define POP (*stackp--)
|
|
255
|
|
256 /* Discard n values from the execution stack. */
|
|
257
|
|
258 #define DISCARD(n) (stackp -= (n))
|
|
259
|
|
260 /* Get the value which is at the top of the execution stack,
|
|
261 but don't pop it. */
|
|
262
|
|
263 #define TOP (*stackp)
|
|
264
|
20
|
265 DEFUN ("byte-code", Fbyte_code, 3, 3, 0, /*
|
0
|
266 Function used internally in byte-compiled code.
|
|
267 The first argument is a string of byte code; the second, a vector of constants;
|
|
268 the third, the maximum stack depth used in this function.
|
|
269 If the third argument is incorrect, Emacs may crash.
|
20
|
270 */
|
|
271 (bytestr, vector, maxdepth))
|
0
|
272 {
|
|
273 /* This function can GC */
|
|
274 struct gcpro gcpro1, gcpro2, gcpro3;
|
|
275 int speccount = specpdl_depth ();
|
|
276 #ifdef BYTE_CODE_METER
|
|
277 int this_op = 0;
|
|
278 int prev_op;
|
|
279 #endif
|
|
280 REGISTER int op;
|
|
281 int pc;
|
|
282 Lisp_Object *stack;
|
|
283 REGISTER Lisp_Object *stackp;
|
|
284 Lisp_Object *stacke;
|
|
285 REGISTER Lisp_Object v1, v2;
|
|
286 REGISTER Lisp_Object *vectorp = vector_data (XVECTOR (vector));
|
|
287 #ifdef BYTE_CODE_SAFE
|
|
288 REGISTER int const_length = vector_length (XVECTOR (vector));
|
|
289 #endif
|
|
290 REGISTER Emchar *massaged_code;
|
|
291 int massaged_code_len;
|
|
292
|
|
293 CHECK_STRING (bytestr);
|
|
294 if (!VECTORP (vector))
|
|
295 vector = wrong_type_argument (Qvectorp, vector);
|
|
296 CHECK_NATNUM (maxdepth);
|
|
297
|
|
298 stackp = (Lisp_Object *) alloca (XINT (maxdepth) * sizeof (Lisp_Object));
|
|
299 memset (stackp, 0, XINT (maxdepth) * sizeof (Lisp_Object));
|
|
300 GCPRO3 (bytestr, vector, *stackp);
|
|
301 gcpro3.nvars = XINT (maxdepth);
|
|
302
|
|
303 --stackp;
|
|
304 stack = stackp;
|
|
305 stacke = stackp + XINT (maxdepth);
|
|
306
|
|
307 /* Initialize the pc-register and convert the string into a fixed-width
|
|
308 format for easier processing. */
|
|
309 massaged_code =
|
|
310 (Emchar *) alloca (sizeof (Emchar) *
|
|
311 (1 + string_char_length (XSTRING (bytestr))));
|
|
312 massaged_code_len =
|
16
|
313 convert_bufbyte_string_into_emchar_string (XSTRING_DATA (bytestr),
|
|
314 XSTRING_LENGTH (bytestr),
|
0
|
315 massaged_code);
|
|
316 massaged_code[massaged_code_len] = 0;
|
|
317 pc = 0;
|
70
|
318
|
0
|
319 while (1)
|
|
320 {
|
|
321 #ifdef BYTE_CODE_SAFE
|
|
322 if (stackp > stacke)
|
|
323 error ("Byte code stack overflow (byte compiler bug), pc %d, depth %d",
|
|
324 pc, stacke - stackp);
|
|
325 if (stackp < stack)
|
|
326 error ("Byte code stack underflow (byte compiler bug), pc %d",
|
|
327 pc);
|
|
328 #endif
|
|
329
|
|
330 #ifdef BYTE_CODE_METER
|
|
331 prev_op = this_op;
|
|
332 this_op = op = FETCH;
|
|
333 METER_CODE (prev_op, op);
|
|
334 switch (op)
|
|
335 #else
|
|
336 switch (op = FETCH)
|
|
337 #endif
|
|
338 {
|
|
339 case Bvarref+6:
|
|
340 op = FETCH;
|
|
341 goto varref;
|
|
342
|
|
343 case Bvarref+7:
|
|
344 op = FETCH2;
|
|
345 goto varref;
|
|
346
|
|
347 case Bvarref: case Bvarref+1: case Bvarref+2: case Bvarref+3:
|
|
348 case Bvarref+4: case Bvarref+5:
|
|
349 op = op - Bvarref;
|
|
350 varref:
|
|
351 v1 = vectorp[op];
|
|
352 if (!SYMBOLP (v1))
|
|
353 v2 = Fsymbol_value (v1);
|
|
354 else
|
|
355 {
|
|
356 v2 = XSYMBOL (v1)->value;
|
|
357 if (SYMBOL_VALUE_MAGIC_P (v2))
|
|
358 v2 = Fsymbol_value (v1);
|
|
359 }
|
|
360 PUSH (v2);
|
|
361 break;
|
|
362
|
|
363 case Bvarset+6:
|
|
364 op = FETCH;
|
|
365 goto varset;
|
|
366
|
|
367 case Bvarset+7:
|
|
368 op = FETCH2;
|
|
369 goto varset;
|
|
370
|
|
371 case Bvarset: case Bvarset+1: case Bvarset+2: case Bvarset+3:
|
|
372 case Bvarset+4: case Bvarset+5:
|
|
373 op -= Bvarset;
|
|
374 varset:
|
|
375 Fset (vectorp[op], POP);
|
|
376 break;
|
|
377
|
|
378 case Bvarbind+6:
|
|
379 op = FETCH;
|
|
380 goto varbind;
|
|
381
|
|
382 case Bvarbind+7:
|
|
383 op = FETCH2;
|
|
384 goto varbind;
|
|
385
|
|
386 case Bvarbind: case Bvarbind+1: case Bvarbind+2: case Bvarbind+3:
|
|
387 case Bvarbind+4: case Bvarbind+5:
|
|
388 op -= Bvarbind;
|
|
389 varbind:
|
|
390 specbind (vectorp[op], POP);
|
|
391 break;
|
|
392
|
|
393 case Bcall+6:
|
|
394 op = FETCH;
|
|
395 goto docall;
|
|
396
|
|
397 case Bcall+7:
|
|
398 op = FETCH2;
|
|
399 goto docall;
|
|
400
|
|
401 case Bcall: case Bcall+1: case Bcall+2: case Bcall+3:
|
|
402 case Bcall+4: case Bcall+5:
|
|
403 op -= Bcall;
|
|
404 docall:
|
|
405 DISCARD (op);
|
|
406 #ifdef BYTE_CODE_METER
|
|
407 if (byte_metering_on && SYMBOLP (TOP))
|
|
408 {
|
|
409 v1 = TOP;
|
|
410 v2 = Fget (v1, Qbyte_code_meter, Qnil);
|
|
411 if (INTP (v2)
|
|
412 && XINT (v2) != ((1<<VALBITS)-1))
|
|
413 {
|
|
414 XSETINT (v2, XINT (v2) + 1);
|
|
415 Fput (v1, Qbyte_code_meter, v2);
|
|
416 }
|
|
417 }
|
16
|
418 #endif /* BYTE_CODE_METER */
|
0
|
419 TOP = Ffuncall (op + 1, &TOP);
|
|
420 break;
|
|
421
|
|
422 case Bunbind+6:
|
|
423 op = FETCH;
|
|
424 goto dounbind;
|
|
425
|
|
426 case Bunbind+7:
|
|
427 op = FETCH2;
|
|
428 goto dounbind;
|
|
429
|
|
430 case Bunbind: case Bunbind+1: case Bunbind+2: case Bunbind+3:
|
|
431 case Bunbind+4: case Bunbind+5:
|
|
432 op -= Bunbind;
|
|
433 dounbind:
|
|
434 unbind_to (specpdl_depth () - op, Qnil);
|
|
435 break;
|
|
436
|
|
437 case Bunbind_all:
|
|
438 /* To unbind back to the beginning of this frame. Not used yet,
|
|
439 but will be needed for tail-recursion elimination. */
|
|
440 unbind_to (speccount, Qnil);
|
|
441 break;
|
|
442
|
|
443 case Bgoto:
|
|
444 QUIT;
|
|
445 op = FETCH2; /* pc = FETCH2 loses since FETCH2 contains pc++ */
|
|
446 pc = op;
|
|
447 break;
|
|
448
|
|
449 case Bgotoifnil:
|
|
450 op = FETCH2;
|
|
451 if (NILP (POP))
|
|
452 {
|
|
453 QUIT;
|
|
454 pc = op;
|
|
455 }
|
|
456 break;
|
|
457
|
|
458 case Bgotoifnonnil:
|
|
459 op = FETCH2;
|
|
460 if (!NILP (POP))
|
|
461 {
|
|
462 QUIT;
|
|
463 pc = op;
|
|
464 }
|
|
465 break;
|
|
466
|
|
467 case Bgotoifnilelsepop:
|
|
468 op = FETCH2;
|
|
469 if (NILP (TOP))
|
|
470 {
|
|
471 QUIT;
|
|
472 pc = op;
|
|
473 }
|
|
474 else DISCARD (1);
|
|
475 break;
|
|
476
|
|
477 case Bgotoifnonnilelsepop:
|
|
478 op = FETCH2;
|
|
479 if (!NILP (TOP))
|
|
480 {
|
|
481 QUIT;
|
|
482 pc = op;
|
|
483 }
|
|
484 else DISCARD (1);
|
|
485 break;
|
|
486
|
|
487 case BRgoto:
|
|
488 QUIT;
|
|
489 pc += massaged_code[pc] - 127;
|
|
490 break;
|
|
491
|
|
492 case BRgotoifnil:
|
|
493 if (NILP (POP))
|
|
494 {
|
|
495 QUIT;
|
|
496 pc += massaged_code[pc] - 128;
|
|
497 }
|
|
498 pc++;
|
|
499 break;
|
|
500
|
|
501 case BRgotoifnonnil:
|
|
502 if (!NILP (POP))
|
|
503 {
|
|
504 QUIT;
|
|
505 pc += massaged_code[pc] - 128;
|
|
506 }
|
|
507 pc++;
|
|
508 break;
|
|
509
|
|
510 case BRgotoifnilelsepop:
|
|
511 op = FETCH;
|
|
512 if (NILP (TOP))
|
|
513 {
|
|
514 QUIT;
|
|
515 pc += op - 128;
|
|
516 }
|
|
517 else DISCARD (1);
|
|
518 break;
|
|
519
|
|
520 case BRgotoifnonnilelsepop:
|
|
521 op = FETCH;
|
|
522 if (!NILP (TOP))
|
|
523 {
|
|
524 QUIT;
|
|
525 pc += op - 128;
|
|
526 }
|
|
527 else DISCARD (1);
|
|
528 break;
|
|
529
|
|
530 case Breturn:
|
|
531 v1 = POP;
|
|
532 goto exit;
|
|
533
|
|
534 case Bdiscard:
|
|
535 DISCARD (1);
|
|
536 break;
|
|
537
|
|
538 case Bdup:
|
|
539 v1 = TOP;
|
|
540 PUSH (v1);
|
|
541 break;
|
|
542
|
|
543 case Bconstant2:
|
|
544 PUSH (vectorp[FETCH2]);
|
|
545 break;
|
|
546
|
|
547 case Bsave_excursion:
|
|
548 record_unwind_protect (save_excursion_restore,
|
|
549 save_excursion_save ());
|
|
550 break;
|
|
551
|
|
552 case Bsave_window_excursion:
|
|
553 {
|
|
554 int count = specpdl_depth ();
|
|
555 record_unwind_protect (save_window_excursion_unwind,
|
|
556 Fcurrent_window_configuration (Qnil));
|
|
557 TOP = Fprogn (TOP);
|
|
558 unbind_to (count, Qnil);
|
|
559 break;
|
|
560 }
|
|
561
|
|
562 case Bsave_restriction:
|
|
563 record_unwind_protect (save_restriction_restore,
|
|
564 save_restriction_save ());
|
|
565 break;
|
|
566
|
|
567 case Bcatch:
|
|
568 v1 = POP;
|
|
569 TOP = internal_catch (TOP, Feval, v1, 0);
|
|
570 break;
|
|
571
|
|
572 case Bunwind_protect:
|
|
573 record_unwind_protect (Fprogn, POP);
|
|
574 break;
|
|
575
|
|
576 case Bcondition_case:
|
|
577 v1 = POP; /* handlers */
|
|
578 v2 = POP; /* bodyform */
|
|
579 TOP = Fcondition_case_3 (v2, TOP, v1);
|
|
580 break;
|
|
581
|
|
582 case Btemp_output_buffer_setup:
|
16
|
583 temp_output_buffer_setup ((char *) XSTRING_DATA (TOP));
|
0
|
584 TOP = Vstandard_output;
|
|
585 break;
|
|
586
|
|
587 case Btemp_output_buffer_show:
|
|
588 v1 = POP;
|
|
589 temp_output_buffer_show (TOP, Qnil);
|
|
590 TOP = v1;
|
|
591 /* GAG ME!! */
|
|
592 /* pop binding of standard-output */
|
|
593 unbind_to (specpdl_depth() - 1, Qnil);
|
|
594 break;
|
|
595
|
|
596 case Bnth:
|
|
597 v1 = POP;
|
|
598 v2 = TOP;
|
|
599 /* nth_entry: */
|
|
600 CHECK_INT (v2);
|
|
601 op = XINT (v2);
|
|
602 while (--op >= 0)
|
|
603 {
|
|
604 if (CONSP (v1))
|
|
605 v1 = XCDR (v1);
|
|
606 else if (!NILP (v1))
|
|
607 {
|
|
608 v1 = wrong_type_argument (Qlistp, v1);
|
|
609 op++;
|
|
610 }
|
|
611 QUIT;
|
|
612 }
|
|
613 goto docar;
|
|
614
|
|
615 case Bsymbolp:
|
|
616 TOP = ((SYMBOLP (TOP)) ? Qt : Qnil);
|
|
617 break;
|
|
618
|
|
619 case Bconsp:
|
|
620 TOP = ((CONSP (TOP)) ? Qt : Qnil);
|
|
621 break;
|
|
622
|
|
623 case Bstringp:
|
|
624 TOP = ((STRINGP (TOP)) ? Qt : Qnil);
|
|
625 break;
|
|
626
|
|
627 case Blistp:
|
|
628 TOP = CONSP (TOP) || NILP (TOP) ? Qt : Qnil;
|
|
629 break;
|
|
630
|
|
631 case Beq:
|
|
632 v1 = POP;
|
70
|
633 TOP = ((EQ_WITH_EBOLA_NOTICE (v1, TOP)) ? Qt : Qnil);
|
|
634 break;
|
|
635
|
|
636 case Bold_eq:
|
|
637 v1 = POP;
|
0
|
638 TOP = ((HACKEQ_UNSAFE (v1, TOP)) ? Qt : Qnil);
|
|
639 break;
|
|
640
|
|
641 case Bmemq:
|
|
642 v1 = POP;
|
|
643 TOP = Fmemq (TOP, v1);
|
|
644 break;
|
|
645
|
70
|
646 case Bold_memq:
|
|
647 v1 = POP;
|
|
648 TOP = Fold_memq (TOP, v1);
|
|
649 break;
|
|
650
|
0
|
651 case Bnot:
|
|
652 TOP = NILP (TOP) ? Qt : Qnil;
|
|
653 break;
|
|
654
|
|
655 case Bcar:
|
|
656 v1 = TOP;
|
|
657 docar:
|
|
658 if (CONSP (v1)) TOP = XCAR (v1);
|
|
659 else if (NILP (v1)) TOP = Qnil;
|
|
660 else Fcar (wrong_type_argument (Qlistp, v1));
|
|
661 break;
|
|
662
|
|
663 case Bcdr:
|
|
664 v1 = TOP;
|
|
665 if (CONSP (v1)) TOP = XCDR (v1);
|
|
666 else if (NILP (v1)) TOP = Qnil;
|
|
667 else Fcdr (wrong_type_argument (Qlistp, v1));
|
|
668 break;
|
|
669
|
|
670 case Bcons:
|
|
671 v1 = POP;
|
|
672 TOP = Fcons (TOP, v1);
|
|
673 break;
|
|
674
|
|
675 case Blist1:
|
|
676 TOP = Fcons (TOP, Qnil);
|
|
677 break;
|
|
678
|
|
679 case Blist2:
|
|
680 v1 = POP;
|
|
681 TOP = Fcons (TOP, Fcons (v1, Qnil));
|
|
682 break;
|
|
683
|
|
684 case Blist3:
|
|
685 DISCARD (2);
|
|
686 TOP = Flist (3, &TOP);
|
|
687 break;
|
|
688
|
|
689 case Blist4:
|
|
690 DISCARD (3);
|
|
691 TOP = Flist (4, &TOP);
|
|
692 break;
|
|
693
|
|
694 case BlistN:
|
|
695 op = FETCH;
|
|
696 DISCARD (op - 1);
|
|
697 TOP = Flist (op, &TOP);
|
|
698 break;
|
|
699
|
|
700 case Blength:
|
|
701 TOP = Flength (TOP);
|
|
702 break;
|
|
703
|
|
704 case Baref:
|
|
705 v1 = POP;
|
|
706 TOP = Faref (TOP, v1);
|
|
707 break;
|
|
708
|
|
709 case Baset:
|
|
710 v2 = POP; v1 = POP;
|
|
711 TOP = Faset (TOP, v1, v2);
|
|
712 break;
|
|
713
|
|
714 case Bsymbol_value:
|
|
715 TOP = Fsymbol_value (TOP);
|
|
716 break;
|
|
717
|
|
718 case Bsymbol_function:
|
|
719 TOP = Fsymbol_function (TOP);
|
|
720 break;
|
|
721
|
|
722 case Bset:
|
|
723 v1 = POP;
|
|
724 TOP = Fset (TOP, v1);
|
|
725 break;
|
|
726
|
|
727 case Bfset:
|
|
728 v1 = POP;
|
|
729 TOP = Ffset (TOP, v1);
|
|
730 break;
|
|
731
|
|
732 case Bget:
|
|
733 v1 = POP;
|
|
734 TOP = Fget (TOP, v1, Qnil);
|
|
735 break;
|
|
736
|
|
737 case Bsubstring:
|
|
738 v2 = POP; v1 = POP;
|
|
739 TOP = Fsubstring (TOP, v1, v2);
|
|
740 break;
|
|
741
|
|
742 case Bconcat2:
|
|
743 DISCARD (1);
|
|
744 TOP = Fconcat (2, &TOP);
|
|
745 break;
|
|
746
|
|
747 case Bconcat3:
|
|
748 DISCARD (2);
|
|
749 TOP = Fconcat (3, &TOP);
|
|
750 break;
|
|
751
|
|
752 case Bconcat4:
|
|
753 DISCARD (3);
|
|
754 TOP = Fconcat (4, &TOP);
|
|
755 break;
|
|
756
|
|
757 case BconcatN:
|
|
758 op = FETCH;
|
|
759 DISCARD (op - 1);
|
|
760 TOP = Fconcat (op, &TOP);
|
|
761 break;
|
|
762
|
|
763 case Bsub1:
|
|
764 v1 = TOP;
|
|
765 if (INTP (v1))
|
|
766 {
|
|
767 XSETINT (v1, XINT (v1) - 1);
|
|
768 TOP = v1;
|
|
769 }
|
|
770 else
|
|
771 TOP = Fsub1 (v1);
|
|
772 break;
|
|
773
|
|
774 case Badd1:
|
|
775 v1 = TOP;
|
|
776 if (INTP (v1))
|
|
777 {
|
|
778 XSETINT (v1, XINT (v1) + 1);
|
|
779 TOP = v1;
|
|
780 }
|
|
781 else
|
|
782 TOP = Fadd1 (v1);
|
|
783 break;
|
|
784
|
|
785 case Beqlsign:
|
|
786 v2 = POP; v1 = TOP;
|
|
787 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (v1);
|
|
788 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (v2);
|
|
789 #ifdef LISP_FLOAT_TYPE
|
|
790 if (FLOATP (v1) || FLOATP (v2))
|
|
791 {
|
|
792 double f1, f2;
|
|
793
|
|
794 f1 = (FLOATP (v1) ? float_data (XFLOAT (v1)) : XINT (v1));
|
|
795 f2 = (FLOATP (v2) ? float_data (XFLOAT (v2)) : XINT (v2));
|
|
796 TOP = (f1 == f2 ? Qt : Qnil);
|
|
797 }
|
|
798 else
|
16
|
799 #endif /* LISP_FLOAT_TYPE */
|
0
|
800 TOP = (XINT (v1) == XINT (v2) ? Qt : Qnil);
|
|
801 break;
|
|
802
|
|
803 case Bgtr:
|
|
804 v1 = POP;
|
|
805 TOP = Fgtr (TOP, v1);
|
|
806 break;
|
|
807
|
|
808 case Blss:
|
|
809 v1 = POP;
|
|
810 TOP = Flss (TOP, v1);
|
|
811 break;
|
|
812
|
|
813 case Bleq:
|
|
814 v1 = POP;
|
|
815 TOP = Fleq (TOP, v1);
|
|
816 break;
|
|
817
|
|
818 case Bgeq:
|
|
819 v1 = POP;
|
|
820 TOP = Fgeq (TOP, v1);
|
|
821 break;
|
|
822
|
|
823 case Bdiff:
|
|
824 DISCARD (1);
|
|
825 TOP = Fminus (2, &TOP);
|
|
826 break;
|
|
827
|
|
828 case Bnegate:
|
|
829 v1 = TOP;
|
|
830 if (INTP (v1))
|
|
831 {
|
|
832 XSETINT (v1, - XINT (v1));
|
|
833 TOP = v1;
|
|
834 }
|
|
835 else
|
|
836 TOP = Fminus (1, &TOP);
|
|
837 break;
|
|
838
|
|
839 case Bplus:
|
|
840 DISCARD (1);
|
|
841 TOP = Fplus (2, &TOP);
|
|
842 break;
|
|
843
|
|
844 case Bmax:
|
|
845 DISCARD (1);
|
|
846 TOP = Fmax (2, &TOP);
|
|
847 break;
|
|
848
|
|
849 case Bmin:
|
|
850 DISCARD (1);
|
|
851 TOP = Fmin (2, &TOP);
|
|
852 break;
|
|
853
|
|
854 case Bmult:
|
|
855 DISCARD (1);
|
|
856 TOP = Ftimes (2, &TOP);
|
|
857 break;
|
|
858
|
|
859 case Bquo:
|
|
860 DISCARD (1);
|
|
861 TOP = Fquo (2, &TOP);
|
|
862 break;
|
|
863
|
|
864 case Brem:
|
|
865 v1 = POP;
|
|
866 TOP = Frem (TOP, v1);
|
|
867 break;
|
|
868
|
|
869 case Bpoint:
|
|
870 v1 = make_int (BUF_PT (current_buffer));
|
|
871 PUSH (v1);
|
|
872 break;
|
|
873
|
|
874 case Bgoto_char:
|
|
875 TOP = Fgoto_char (TOP, Fcurrent_buffer ());
|
|
876 break;
|
|
877
|
|
878 case Binsert:
|
|
879 TOP = Finsert (1, &TOP);
|
|
880 break;
|
|
881
|
|
882 case BinsertN:
|
|
883 op = FETCH;
|
|
884 DISCARD (op - 1);
|
|
885 TOP = Finsert (op, &TOP);
|
|
886 break;
|
|
887
|
|
888 case Bpoint_max:
|
|
889 v1 = make_int (BUF_ZV (current_buffer));
|
|
890 PUSH (v1);
|
|
891 break;
|
|
892
|
|
893 case Bpoint_min:
|
|
894 v1 = make_int (BUF_BEGV (current_buffer));
|
|
895 PUSH (v1);
|
|
896 break;
|
|
897
|
|
898 case Bchar_after:
|
|
899 TOP = Fchar_after (TOP, Fcurrent_buffer ());
|
|
900 break;
|
|
901
|
|
902 case Bfollowing_char:
|
|
903 v1 = Ffollowing_char (Fcurrent_buffer ());
|
|
904 PUSH (v1);
|
|
905 break;
|
|
906
|
|
907 case Bpreceding_char:
|
|
908 v1 = Fpreceding_char (Fcurrent_buffer ());
|
|
909 PUSH (v1);
|
|
910 break;
|
|
911
|
|
912 case Bcurrent_column:
|
|
913 v1 = make_int (current_column (current_buffer));
|
|
914 PUSH (v1);
|
|
915 break;
|
|
916
|
|
917 case Bindent_to:
|
|
918 TOP = Findent_to (TOP, Qnil, Fcurrent_buffer ());
|
|
919 break;
|
|
920
|
|
921 case Beolp:
|
|
922 PUSH (Feolp (Fcurrent_buffer ()));
|
|
923 break;
|
|
924
|
|
925 case Beobp:
|
|
926 PUSH (Feobp (Fcurrent_buffer ()));
|
|
927 break;
|
|
928
|
|
929 case Bbolp:
|
|
930 PUSH (Fbolp (Fcurrent_buffer ()));
|
|
931 break;
|
|
932
|
|
933 case Bbobp:
|
|
934 PUSH (Fbobp (Fcurrent_buffer ()));
|
|
935 break;
|
|
936
|
|
937 case Bcurrent_buffer:
|
|
938 PUSH (Fcurrent_buffer ());
|
|
939 break;
|
|
940
|
|
941 case Bset_buffer:
|
|
942 TOP = Fset_buffer (TOP);
|
|
943 break;
|
|
944
|
161
|
945 case Bsave_current_buffer:
|
169
|
946 record_unwind_protect (save_current_buffer_restore,
|
|
947 Fcurrent_buffer ());
|
|
948 break;
|
0
|
949
|
|
950 case Binteractive_p:
|
|
951 PUSH (Finteractive_p ());
|
|
952 break;
|
|
953
|
|
954 case Bforward_char:
|
|
955 TOP = Fforward_char (TOP, Fcurrent_buffer ());
|
|
956 break;
|
|
957
|
|
958 case Bforward_word:
|
|
959 TOP = Fforward_word (TOP, Fcurrent_buffer ());
|
|
960 break;
|
|
961
|
|
962 case Bskip_chars_forward:
|
|
963 v1 = POP;
|
|
964 TOP = Fskip_chars_forward (TOP, v1, Fcurrent_buffer ());
|
|
965 break;
|
|
966
|
|
967 case Bskip_chars_backward:
|
|
968 v1 = POP;
|
|
969 TOP = Fskip_chars_backward (TOP, v1, Fcurrent_buffer ());
|
|
970 break;
|
|
971
|
|
972 case Bforward_line:
|
|
973 TOP = Fforward_line (TOP, Fcurrent_buffer ());
|
|
974 break;
|
|
975
|
|
976 case Bchar_syntax:
|
|
977 CHECK_CHAR_COERCE_INT (TOP);
|
|
978 TOP = make_char (syntax_code_spec
|
16
|
979 [(int) SYNTAX
|
70
|
980 (XCHAR_TABLE
|
|
981 (current_buffer->mirror_syntax_table),
|
|
982 XCHAR (TOP))]);
|
0
|
983 break;
|
|
984
|
|
985 case Bbuffer_substring:
|
|
986 v1 = POP;
|
|
987 TOP = Fbuffer_substring (TOP, v1, Fcurrent_buffer ());
|
|
988 break;
|
|
989
|
|
990 case Bdelete_region:
|
|
991 v1 = POP;
|
|
992 TOP = Fdelete_region (TOP, v1, Fcurrent_buffer ());
|
|
993 break;
|
|
994
|
|
995 case Bnarrow_to_region:
|
|
996 v1 = POP;
|
|
997 TOP = Fnarrow_to_region (TOP, v1, Fcurrent_buffer ());
|
|
998 break;
|
|
999
|
|
1000 case Bwiden:
|
|
1001 PUSH (Fwiden (Fcurrent_buffer ()));
|
|
1002 break;
|
|
1003
|
|
1004 case Bend_of_line:
|
|
1005 TOP = Fend_of_line (TOP, Fcurrent_buffer ());
|
|
1006 break;
|
|
1007
|
|
1008 case Bset_marker:
|
|
1009 v1 = POP;
|
|
1010 v2 = POP;
|
|
1011 TOP = Fset_marker (TOP, v2, v1);
|
|
1012 break;
|
|
1013
|
|
1014 case Bmatch_beginning:
|
|
1015 TOP = Fmatch_beginning (TOP);
|
|
1016 break;
|
|
1017
|
|
1018 case Bmatch_end:
|
|
1019 TOP = Fmatch_end (TOP);
|
|
1020 break;
|
|
1021
|
|
1022 case Bupcase:
|
|
1023 TOP = Fupcase (TOP, Fcurrent_buffer ());
|
|
1024 break;
|
|
1025
|
|
1026 case Bdowncase:
|
|
1027 TOP = Fdowncase (TOP, Fcurrent_buffer ());
|
|
1028 break;
|
|
1029
|
|
1030 case Bstringeqlsign:
|
|
1031 v1 = POP;
|
|
1032 TOP = Fstring_equal (TOP, v1);
|
|
1033 break;
|
|
1034
|
|
1035 case Bstringlss:
|
|
1036 v1 = POP;
|
|
1037 TOP = Fstring_lessp (TOP, v1);
|
|
1038 break;
|
|
1039
|
|
1040 case Bequal:
|
|
1041 v1 = POP;
|
|
1042 TOP = Fequal (TOP, v1);
|
|
1043 break;
|
|
1044
|
70
|
1045 case Bold_equal:
|
|
1046 v1 = POP;
|
|
1047 TOP = Fold_equal (TOP, v1);
|
|
1048 break;
|
|
1049
|
0
|
1050 case Bnthcdr:
|
|
1051 v1 = POP;
|
|
1052 TOP = Fnthcdr (TOP, v1);
|
|
1053 break;
|
|
1054
|
|
1055 case Belt:
|
|
1056 #if 0
|
|
1057 /* probably this code is OK, but nth_entry is commented
|
|
1058 out above --ben */
|
|
1059 if (XTYPE (TOP) == Lisp_Cons)
|
|
1060 {
|
|
1061 /* Exchange args and then do nth. */
|
|
1062 v2 = POP;
|
|
1063 v1 = TOP;
|
|
1064 goto nth_entry;
|
|
1065 }
|
|
1066 #endif
|
|
1067 v1 = POP;
|
|
1068 TOP = Felt (TOP, v1);
|
|
1069 break;
|
|
1070
|
|
1071 case Bmember:
|
|
1072 v1 = POP;
|
|
1073 TOP = Fmember (TOP, v1);
|
|
1074 break;
|
|
1075
|
70
|
1076 case Bold_member:
|
|
1077 v1 = POP;
|
|
1078 TOP = Fold_member (TOP, v1);
|
|
1079 break;
|
|
1080
|
0
|
1081 case Bassq:
|
|
1082 v1 = POP;
|
|
1083 TOP = Fassq (TOP, v1);
|
|
1084 break;
|
|
1085
|
70
|
1086 case Bold_assq:
|
|
1087 v1 = POP;
|
|
1088 TOP = Fold_assq (TOP, v1);
|
|
1089 break;
|
|
1090
|
0
|
1091 case Bnreverse:
|
|
1092 TOP = Fnreverse (TOP);
|
|
1093 break;
|
|
1094
|
|
1095 case Bsetcar:
|
|
1096 v1 = POP;
|
|
1097 TOP = Fsetcar (TOP, v1);
|
|
1098 break;
|
|
1099
|
|
1100 case Bsetcdr:
|
|
1101 v1 = POP;
|
|
1102 TOP = Fsetcdr (TOP, v1);
|
|
1103 break;
|
|
1104
|
|
1105 case Bcar_safe:
|
|
1106 v1 = TOP;
|
|
1107 if (CONSP (v1))
|
|
1108 TOP = XCAR (v1);
|
|
1109 else
|
|
1110 TOP = Qnil;
|
|
1111 break;
|
|
1112
|
|
1113 case Bcdr_safe:
|
|
1114 v1 = TOP;
|
|
1115 if (CONSP (v1))
|
|
1116 TOP = XCDR (v1);
|
|
1117 else
|
|
1118 TOP = Qnil;
|
|
1119 break;
|
|
1120
|
|
1121 case Bnconc:
|
|
1122 DISCARD (1);
|
|
1123 TOP = Fnconc (2, &TOP);
|
|
1124 break;
|
|
1125
|
|
1126 case Bnumberp:
|
|
1127 TOP = ((INT_OR_FLOATP (TOP)) ? Qt : Qnil);
|
|
1128 break;
|
|
1129
|
|
1130 case Bintegerp:
|
|
1131 TOP = ((INTP (TOP)) ? Qt : Qnil);
|
|
1132 break;
|
|
1133
|
|
1134 default:
|
|
1135 #ifdef BYTE_CODE_SAFE
|
|
1136 if (op < Bconstant)
|
|
1137 error ("unknown bytecode %d (byte compiler bug)", op);
|
|
1138 if ((op -= Bconstant) >= const_length)
|
|
1139 error ("no constant number %d (byte compiler bug)", op);
|
|
1140 PUSH (vectorp[op]);
|
|
1141 #else
|
|
1142 PUSH (vectorp[op - Bconstant]);
|
|
1143 #endif
|
|
1144 }
|
|
1145 }
|
|
1146
|
|
1147 exit:
|
|
1148 UNGCPRO;
|
|
1149 /* Binds and unbinds are supposed to be compiled balanced. */
|
|
1150 if (specpdl_depth() != speccount)
|
|
1151 /* FSF: abort() if BYTE_CODE_SAFE not defined */
|
|
1152 error ("binding stack not balanced (serious byte compiler bug)");
|
|
1153 return v1;
|
|
1154 }
|
|
1155
|
|
1156 void
|
|
1157 syms_of_bytecode (void)
|
|
1158 {
|
|
1159 defsymbol (&Qbyte_code, "byte-code");
|
20
|
1160 DEFSUBR (Fbyte_code);
|
0
|
1161 #ifdef BYTE_CODE_METER
|
|
1162 defsymbol (&Qbyte_code_meter, "byte-code-meter");
|
|
1163 #endif
|
|
1164 }
|
|
1165
|
|
1166 void
|
|
1167 vars_of_bytecode (void)
|
|
1168 {
|
|
1169 #ifdef BYTE_CODE_METER
|
|
1170
|
|
1171 DEFVAR_LISP ("byte-code-meter", &Vbyte_code_meter /*
|
|
1172 A vector of vectors which holds a histogram of byte-code usage.
|
|
1173 (aref (aref byte-code-meter 0) CODE) indicates how many times the byte
|
|
1174 opcode CODE has been executed.
|
|
1175 (aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
|
|
1176 indicates how many times the byte opcodes CODE1 and CODE2 have been
|
|
1177 executed in succession.
|
|
1178 */ );
|
|
1179 DEFVAR_BOOL ("byte-metering-on", &byte_metering_on /*
|
|
1180 If non-nil, keep profiling information on byte code usage.
|
|
1181 The variable byte-code-meter indicates how often each byte opcode is used.
|
|
1182 If a symbol has a property named `byte-code-meter' whose value is an
|
|
1183 integer, it is incremented each time that symbol's function is called.
|
|
1184 */ );
|
|
1185
|
|
1186 byte_metering_on = 0;
|
|
1187 Vbyte_code_meter = make_vector (256, Qzero);
|
|
1188 {
|
|
1189 int i = 256;
|
|
1190 while (i--)
|
|
1191 vector_data (XVECTOR (Vbyte_code_meter))[i] =
|
|
1192 make_vector (256, Qzero);
|
|
1193 }
|
|
1194 #endif
|
|
1195 }
|