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