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
|
185
|
297 stackp = alloca_array (Lisp_Object, XINT (maxdepth));
|
0
|
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. */
|
185
|
308 massaged_code = alloca_array (Emchar,
|
|
309 1 + string_char_length (XSTRING (bytestr)));
|
0
|
310 massaged_code_len =
|
16
|
311 convert_bufbyte_string_into_emchar_string (XSTRING_DATA (bytestr),
|
|
312 XSTRING_LENGTH (bytestr),
|
0
|
313 massaged_code);
|
|
314 massaged_code[massaged_code_len] = 0;
|
|
315 pc = 0;
|
173
|
316
|
0
|
317 while (1)
|
|
318 {
|
|
319 #ifdef BYTE_CODE_SAFE
|
|
320 if (stackp > stacke)
|
173
|
321 error ("Byte code stack overflow (byte compiler bug), pc %d, depth %ld",
|
|
322 pc, (long) (stacke - stackp));
|
0
|
323 if (stackp < stack)
|
|
324 error ("Byte code stack underflow (byte compiler bug), pc %d",
|
|
325 pc);
|
|
326 #endif
|
|
327
|
|
328 #ifdef BYTE_CODE_METER
|
|
329 prev_op = this_op;
|
|
330 this_op = op = FETCH;
|
|
331 METER_CODE (prev_op, op);
|
|
332 switch (op)
|
|
333 #else
|
|
334 switch (op = FETCH)
|
|
335 #endif
|
|
336 {
|
|
337 case Bvarref+6:
|
|
338 op = FETCH;
|
|
339 goto varref;
|
|
340
|
|
341 case Bvarref+7:
|
|
342 op = FETCH2;
|
|
343 goto varref;
|
|
344
|
|
345 case Bvarref: case Bvarref+1: case Bvarref+2: case Bvarref+3:
|
|
346 case Bvarref+4: case Bvarref+5:
|
|
347 op = op - Bvarref;
|
|
348 varref:
|
|
349 v1 = vectorp[op];
|
|
350 if (!SYMBOLP (v1))
|
|
351 v2 = Fsymbol_value (v1);
|
|
352 else
|
|
353 {
|
|
354 v2 = XSYMBOL (v1)->value;
|
|
355 if (SYMBOL_VALUE_MAGIC_P (v2))
|
|
356 v2 = Fsymbol_value (v1);
|
|
357 }
|
|
358 PUSH (v2);
|
|
359 break;
|
|
360
|
|
361 case Bvarset+6:
|
|
362 op = FETCH;
|
|
363 goto varset;
|
|
364
|
|
365 case Bvarset+7:
|
|
366 op = FETCH2;
|
|
367 goto varset;
|
|
368
|
|
369 case Bvarset: case Bvarset+1: case Bvarset+2: case Bvarset+3:
|
|
370 case Bvarset+4: case Bvarset+5:
|
|
371 op -= Bvarset;
|
|
372 varset:
|
|
373 Fset (vectorp[op], POP);
|
|
374 break;
|
|
375
|
|
376 case Bvarbind+6:
|
|
377 op = FETCH;
|
|
378 goto varbind;
|
|
379
|
|
380 case Bvarbind+7:
|
|
381 op = FETCH2;
|
|
382 goto varbind;
|
|
383
|
|
384 case Bvarbind: case Bvarbind+1: case Bvarbind+2: case Bvarbind+3:
|
|
385 case Bvarbind+4: case Bvarbind+5:
|
|
386 op -= Bvarbind;
|
|
387 varbind:
|
|
388 specbind (vectorp[op], POP);
|
|
389 break;
|
|
390
|
|
391 case Bcall+6:
|
|
392 op = FETCH;
|
|
393 goto docall;
|
|
394
|
|
395 case Bcall+7:
|
|
396 op = FETCH2;
|
|
397 goto docall;
|
|
398
|
|
399 case Bcall: case Bcall+1: case Bcall+2: case Bcall+3:
|
|
400 case Bcall+4: case Bcall+5:
|
|
401 op -= Bcall;
|
|
402 docall:
|
|
403 DISCARD (op);
|
|
404 #ifdef BYTE_CODE_METER
|
|
405 if (byte_metering_on && SYMBOLP (TOP))
|
|
406 {
|
|
407 v1 = TOP;
|
|
408 v2 = Fget (v1, Qbyte_code_meter, Qnil);
|
|
409 if (INTP (v2)
|
|
410 && XINT (v2) != ((1<<VALBITS)-1))
|
|
411 {
|
|
412 XSETINT (v2, XINT (v2) + 1);
|
|
413 Fput (v1, Qbyte_code_meter, v2);
|
|
414 }
|
|
415 }
|
16
|
416 #endif /* BYTE_CODE_METER */
|
0
|
417 TOP = Ffuncall (op + 1, &TOP);
|
|
418 break;
|
|
419
|
|
420 case Bunbind+6:
|
|
421 op = FETCH;
|
|
422 goto dounbind;
|
|
423
|
|
424 case Bunbind+7:
|
|
425 op = FETCH2;
|
|
426 goto dounbind;
|
|
427
|
|
428 case Bunbind: case Bunbind+1: case Bunbind+2: case Bunbind+3:
|
|
429 case Bunbind+4: case Bunbind+5:
|
|
430 op -= Bunbind;
|
|
431 dounbind:
|
|
432 unbind_to (specpdl_depth () - op, Qnil);
|
|
433 break;
|
|
434
|
|
435 case Bunbind_all:
|
|
436 /* To unbind back to the beginning of this frame. Not used yet,
|
|
437 but will be needed for tail-recursion elimination. */
|
|
438 unbind_to (speccount, Qnil);
|
|
439 break;
|
|
440
|
|
441 case Bgoto:
|
|
442 QUIT;
|
|
443 op = FETCH2; /* pc = FETCH2 loses since FETCH2 contains pc++ */
|
|
444 pc = op;
|
|
445 break;
|
|
446
|
|
447 case Bgotoifnil:
|
|
448 op = FETCH2;
|
|
449 if (NILP (POP))
|
|
450 {
|
|
451 QUIT;
|
|
452 pc = op;
|
|
453 }
|
|
454 break;
|
|
455
|
|
456 case Bgotoifnonnil:
|
|
457 op = FETCH2;
|
|
458 if (!NILP (POP))
|
|
459 {
|
|
460 QUIT;
|
|
461 pc = op;
|
|
462 }
|
|
463 break;
|
|
464
|
|
465 case Bgotoifnilelsepop:
|
|
466 op = FETCH2;
|
|
467 if (NILP (TOP))
|
|
468 {
|
|
469 QUIT;
|
|
470 pc = op;
|
|
471 }
|
|
472 else DISCARD (1);
|
|
473 break;
|
|
474
|
|
475 case Bgotoifnonnilelsepop:
|
|
476 op = FETCH2;
|
|
477 if (!NILP (TOP))
|
|
478 {
|
|
479 QUIT;
|
|
480 pc = op;
|
|
481 }
|
|
482 else DISCARD (1);
|
|
483 break;
|
|
484
|
|
485 case BRgoto:
|
|
486 QUIT;
|
|
487 pc += massaged_code[pc] - 127;
|
|
488 break;
|
|
489
|
|
490 case BRgotoifnil:
|
|
491 if (NILP (POP))
|
|
492 {
|
|
493 QUIT;
|
|
494 pc += massaged_code[pc] - 128;
|
|
495 }
|
|
496 pc++;
|
|
497 break;
|
|
498
|
|
499 case BRgotoifnonnil:
|
|
500 if (!NILP (POP))
|
|
501 {
|
|
502 QUIT;
|
|
503 pc += massaged_code[pc] - 128;
|
|
504 }
|
|
505 pc++;
|
|
506 break;
|
|
507
|
|
508 case BRgotoifnilelsepop:
|
|
509 op = FETCH;
|
|
510 if (NILP (TOP))
|
|
511 {
|
|
512 QUIT;
|
|
513 pc += op - 128;
|
|
514 }
|
|
515 else DISCARD (1);
|
|
516 break;
|
|
517
|
|
518 case BRgotoifnonnilelsepop:
|
|
519 op = FETCH;
|
|
520 if (!NILP (TOP))
|
|
521 {
|
|
522 QUIT;
|
|
523 pc += op - 128;
|
|
524 }
|
|
525 else DISCARD (1);
|
|
526 break;
|
|
527
|
|
528 case Breturn:
|
|
529 v1 = POP;
|
|
530 goto exit;
|
|
531
|
|
532 case Bdiscard:
|
|
533 DISCARD (1);
|
|
534 break;
|
|
535
|
|
536 case Bdup:
|
|
537 v1 = TOP;
|
|
538 PUSH (v1);
|
|
539 break;
|
|
540
|
|
541 case Bconstant2:
|
|
542 PUSH (vectorp[FETCH2]);
|
|
543 break;
|
|
544
|
|
545 case Bsave_excursion:
|
|
546 record_unwind_protect (save_excursion_restore,
|
|
547 save_excursion_save ());
|
|
548 break;
|
|
549
|
|
550 case Bsave_window_excursion:
|
|
551 {
|
|
552 int count = specpdl_depth ();
|
|
553 record_unwind_protect (save_window_excursion_unwind,
|
|
554 Fcurrent_window_configuration (Qnil));
|
|
555 TOP = Fprogn (TOP);
|
|
556 unbind_to (count, Qnil);
|
|
557 break;
|
|
558 }
|
|
559
|
|
560 case Bsave_restriction:
|
|
561 record_unwind_protect (save_restriction_restore,
|
|
562 save_restriction_save ());
|
|
563 break;
|
|
564
|
|
565 case Bcatch:
|
|
566 v1 = POP;
|
|
567 TOP = internal_catch (TOP, Feval, v1, 0);
|
|
568 break;
|
|
569
|
|
570 case Bunwind_protect:
|
|
571 record_unwind_protect (Fprogn, POP);
|
|
572 break;
|
|
573
|
|
574 case Bcondition_case:
|
|
575 v1 = POP; /* handlers */
|
|
576 v2 = POP; /* bodyform */
|
|
577 TOP = Fcondition_case_3 (v2, TOP, v1);
|
|
578 break;
|
|
579
|
|
580 case Btemp_output_buffer_setup:
|
16
|
581 temp_output_buffer_setup ((char *) XSTRING_DATA (TOP));
|
0
|
582 TOP = Vstandard_output;
|
|
583 break;
|
|
584
|
|
585 case Btemp_output_buffer_show:
|
|
586 v1 = POP;
|
|
587 temp_output_buffer_show (TOP, Qnil);
|
|
588 TOP = v1;
|
|
589 /* GAG ME!! */
|
|
590 /* pop binding of standard-output */
|
|
591 unbind_to (specpdl_depth() - 1, Qnil);
|
|
592 break;
|
|
593
|
|
594 case Bnth:
|
|
595 v1 = POP;
|
|
596 v2 = TOP;
|
|
597 /* nth_entry: */
|
|
598 CHECK_INT (v2);
|
|
599 op = XINT (v2);
|
|
600 while (--op >= 0)
|
|
601 {
|
|
602 if (CONSP (v1))
|
|
603 v1 = XCDR (v1);
|
|
604 else if (!NILP (v1))
|
|
605 {
|
|
606 v1 = wrong_type_argument (Qlistp, v1);
|
|
607 op++;
|
|
608 }
|
|
609 QUIT;
|
|
610 }
|
|
611 goto docar;
|
|
612
|
|
613 case Bsymbolp:
|
|
614 TOP = ((SYMBOLP (TOP)) ? Qt : Qnil);
|
|
615 break;
|
|
616
|
|
617 case Bconsp:
|
|
618 TOP = ((CONSP (TOP)) ? Qt : Qnil);
|
|
619 break;
|
|
620
|
|
621 case Bstringp:
|
|
622 TOP = ((STRINGP (TOP)) ? Qt : Qnil);
|
|
623 break;
|
|
624
|
|
625 case Blistp:
|
|
626 TOP = CONSP (TOP) || NILP (TOP) ? Qt : Qnil;
|
|
627 break;
|
|
628
|
|
629 case Beq:
|
|
630 v1 = POP;
|
70
|
631 TOP = ((EQ_WITH_EBOLA_NOTICE (v1, TOP)) ? Qt : Qnil);
|
|
632 break;
|
|
633
|
|
634 case Bold_eq:
|
|
635 v1 = POP;
|
0
|
636 TOP = ((HACKEQ_UNSAFE (v1, TOP)) ? Qt : Qnil);
|
|
637 break;
|
|
638
|
|
639 case Bmemq:
|
|
640 v1 = POP;
|
|
641 TOP = Fmemq (TOP, v1);
|
|
642 break;
|
|
643
|
70
|
644 case Bold_memq:
|
|
645 v1 = POP;
|
|
646 TOP = Fold_memq (TOP, v1);
|
|
647 break;
|
|
648
|
0
|
649 case Bnot:
|
|
650 TOP = NILP (TOP) ? Qt : Qnil;
|
|
651 break;
|
|
652
|
|
653 case Bcar:
|
|
654 v1 = TOP;
|
|
655 docar:
|
|
656 if (CONSP (v1)) TOP = XCAR (v1);
|
|
657 else if (NILP (v1)) TOP = Qnil;
|
|
658 else Fcar (wrong_type_argument (Qlistp, v1));
|
|
659 break;
|
|
660
|
|
661 case Bcdr:
|
|
662 v1 = TOP;
|
|
663 if (CONSP (v1)) TOP = XCDR (v1);
|
|
664 else if (NILP (v1)) TOP = Qnil;
|
|
665 else Fcdr (wrong_type_argument (Qlistp, v1));
|
|
666 break;
|
|
667
|
|
668 case Bcons:
|
|
669 v1 = POP;
|
|
670 TOP = Fcons (TOP, v1);
|
|
671 break;
|
|
672
|
|
673 case Blist1:
|
|
674 TOP = Fcons (TOP, Qnil);
|
|
675 break;
|
|
676
|
|
677 case Blist2:
|
|
678 v1 = POP;
|
|
679 TOP = Fcons (TOP, Fcons (v1, Qnil));
|
|
680 break;
|
|
681
|
|
682 case Blist3:
|
|
683 DISCARD (2);
|
|
684 TOP = Flist (3, &TOP);
|
|
685 break;
|
|
686
|
|
687 case Blist4:
|
|
688 DISCARD (3);
|
|
689 TOP = Flist (4, &TOP);
|
|
690 break;
|
|
691
|
|
692 case BlistN:
|
|
693 op = FETCH;
|
|
694 DISCARD (op - 1);
|
|
695 TOP = Flist (op, &TOP);
|
|
696 break;
|
|
697
|
|
698 case Blength:
|
|
699 TOP = Flength (TOP);
|
|
700 break;
|
|
701
|
|
702 case Baref:
|
|
703 v1 = POP;
|
|
704 TOP = Faref (TOP, v1);
|
|
705 break;
|
|
706
|
|
707 case Baset:
|
|
708 v2 = POP; v1 = POP;
|
|
709 TOP = Faset (TOP, v1, v2);
|
|
710 break;
|
|
711
|
|
712 case Bsymbol_value:
|
|
713 TOP = Fsymbol_value (TOP);
|
|
714 break;
|
|
715
|
|
716 case Bsymbol_function:
|
|
717 TOP = Fsymbol_function (TOP);
|
|
718 break;
|
|
719
|
|
720 case Bset:
|
|
721 v1 = POP;
|
|
722 TOP = Fset (TOP, v1);
|
|
723 break;
|
|
724
|
|
725 case Bfset:
|
|
726 v1 = POP;
|
|
727 TOP = Ffset (TOP, v1);
|
|
728 break;
|
|
729
|
|
730 case Bget:
|
|
731 v1 = POP;
|
|
732 TOP = Fget (TOP, v1, Qnil);
|
|
733 break;
|
|
734
|
|
735 case Bsubstring:
|
|
736 v2 = POP; v1 = POP;
|
|
737 TOP = Fsubstring (TOP, v1, v2);
|
|
738 break;
|
|
739
|
|
740 case Bconcat2:
|
|
741 DISCARD (1);
|
|
742 TOP = Fconcat (2, &TOP);
|
|
743 break;
|
|
744
|
|
745 case Bconcat3:
|
|
746 DISCARD (2);
|
|
747 TOP = Fconcat (3, &TOP);
|
|
748 break;
|
|
749
|
|
750 case Bconcat4:
|
|
751 DISCARD (3);
|
|
752 TOP = Fconcat (4, &TOP);
|
|
753 break;
|
|
754
|
|
755 case BconcatN:
|
|
756 op = FETCH;
|
|
757 DISCARD (op - 1);
|
|
758 TOP = Fconcat (op, &TOP);
|
|
759 break;
|
|
760
|
|
761 case Bsub1:
|
|
762 v1 = TOP;
|
|
763 if (INTP (v1))
|
|
764 {
|
|
765 XSETINT (v1, XINT (v1) - 1);
|
|
766 TOP = v1;
|
|
767 }
|
|
768 else
|
|
769 TOP = Fsub1 (v1);
|
|
770 break;
|
|
771
|
|
772 case Badd1:
|
|
773 v1 = TOP;
|
|
774 if (INTP (v1))
|
|
775 {
|
|
776 XSETINT (v1, XINT (v1) + 1);
|
|
777 TOP = v1;
|
|
778 }
|
|
779 else
|
|
780 TOP = Fadd1 (v1);
|
|
781 break;
|
|
782
|
|
783 case Beqlsign:
|
|
784 v2 = POP; v1 = TOP;
|
|
785 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (v1);
|
|
786 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (v2);
|
|
787 #ifdef LISP_FLOAT_TYPE
|
|
788 if (FLOATP (v1) || FLOATP (v2))
|
|
789 {
|
|
790 double f1, f2;
|
|
791
|
|
792 f1 = (FLOATP (v1) ? float_data (XFLOAT (v1)) : XINT (v1));
|
|
793 f2 = (FLOATP (v2) ? float_data (XFLOAT (v2)) : XINT (v2));
|
|
794 TOP = (f1 == f2 ? Qt : Qnil);
|
|
795 }
|
|
796 else
|
16
|
797 #endif /* LISP_FLOAT_TYPE */
|
0
|
798 TOP = (XINT (v1) == XINT (v2) ? Qt : Qnil);
|
|
799 break;
|
|
800
|
|
801 case Bgtr:
|
|
802 v1 = POP;
|
|
803 TOP = Fgtr (TOP, v1);
|
|
804 break;
|
|
805
|
|
806 case Blss:
|
|
807 v1 = POP;
|
|
808 TOP = Flss (TOP, v1);
|
|
809 break;
|
|
810
|
|
811 case Bleq:
|
|
812 v1 = POP;
|
|
813 TOP = Fleq (TOP, v1);
|
|
814 break;
|
|
815
|
|
816 case Bgeq:
|
|
817 v1 = POP;
|
|
818 TOP = Fgeq (TOP, v1);
|
|
819 break;
|
|
820
|
|
821 case Bdiff:
|
|
822 DISCARD (1);
|
|
823 TOP = Fminus (2, &TOP);
|
|
824 break;
|
|
825
|
|
826 case Bnegate:
|
|
827 v1 = TOP;
|
|
828 if (INTP (v1))
|
|
829 {
|
|
830 XSETINT (v1, - XINT (v1));
|
|
831 TOP = v1;
|
|
832 }
|
|
833 else
|
|
834 TOP = Fminus (1, &TOP);
|
|
835 break;
|
|
836
|
|
837 case Bplus:
|
|
838 DISCARD (1);
|
|
839 TOP = Fplus (2, &TOP);
|
|
840 break;
|
|
841
|
|
842 case Bmax:
|
|
843 DISCARD (1);
|
|
844 TOP = Fmax (2, &TOP);
|
|
845 break;
|
|
846
|
|
847 case Bmin:
|
|
848 DISCARD (1);
|
|
849 TOP = Fmin (2, &TOP);
|
|
850 break;
|
|
851
|
|
852 case Bmult:
|
|
853 DISCARD (1);
|
|
854 TOP = Ftimes (2, &TOP);
|
|
855 break;
|
|
856
|
|
857 case Bquo:
|
|
858 DISCARD (1);
|
|
859 TOP = Fquo (2, &TOP);
|
|
860 break;
|
|
861
|
|
862 case Brem:
|
|
863 v1 = POP;
|
|
864 TOP = Frem (TOP, v1);
|
|
865 break;
|
|
866
|
|
867 case Bpoint:
|
|
868 v1 = make_int (BUF_PT (current_buffer));
|
|
869 PUSH (v1);
|
|
870 break;
|
|
871
|
|
872 case Bgoto_char:
|
|
873 TOP = Fgoto_char (TOP, Fcurrent_buffer ());
|
|
874 break;
|
|
875
|
|
876 case Binsert:
|
|
877 TOP = Finsert (1, &TOP);
|
|
878 break;
|
|
879
|
|
880 case BinsertN:
|
|
881 op = FETCH;
|
|
882 DISCARD (op - 1);
|
|
883 TOP = Finsert (op, &TOP);
|
|
884 break;
|
|
885
|
|
886 case Bpoint_max:
|
|
887 v1 = make_int (BUF_ZV (current_buffer));
|
|
888 PUSH (v1);
|
|
889 break;
|
|
890
|
|
891 case Bpoint_min:
|
|
892 v1 = make_int (BUF_BEGV (current_buffer));
|
|
893 PUSH (v1);
|
|
894 break;
|
|
895
|
|
896 case Bchar_after:
|
|
897 TOP = Fchar_after (TOP, Fcurrent_buffer ());
|
|
898 break;
|
|
899
|
|
900 case Bfollowing_char:
|
|
901 v1 = Ffollowing_char (Fcurrent_buffer ());
|
|
902 PUSH (v1);
|
|
903 break;
|
|
904
|
|
905 case Bpreceding_char:
|
|
906 v1 = Fpreceding_char (Fcurrent_buffer ());
|
|
907 PUSH (v1);
|
|
908 break;
|
|
909
|
|
910 case Bcurrent_column:
|
|
911 v1 = make_int (current_column (current_buffer));
|
|
912 PUSH (v1);
|
|
913 break;
|
|
914
|
|
915 case Bindent_to:
|
|
916 TOP = Findent_to (TOP, Qnil, Fcurrent_buffer ());
|
|
917 break;
|
|
918
|
|
919 case Beolp:
|
|
920 PUSH (Feolp (Fcurrent_buffer ()));
|
|
921 break;
|
|
922
|
|
923 case Beobp:
|
|
924 PUSH (Feobp (Fcurrent_buffer ()));
|
|
925 break;
|
|
926
|
|
927 case Bbolp:
|
|
928 PUSH (Fbolp (Fcurrent_buffer ()));
|
|
929 break;
|
|
930
|
|
931 case Bbobp:
|
|
932 PUSH (Fbobp (Fcurrent_buffer ()));
|
|
933 break;
|
|
934
|
|
935 case Bcurrent_buffer:
|
|
936 PUSH (Fcurrent_buffer ());
|
|
937 break;
|
|
938
|
|
939 case Bset_buffer:
|
|
940 TOP = Fset_buffer (TOP);
|
|
941 break;
|
|
942
|
161
|
943 case Bsave_current_buffer:
|
169
|
944 record_unwind_protect (save_current_buffer_restore,
|
|
945 Fcurrent_buffer ());
|
|
946 break;
|
0
|
947
|
|
948 case Binteractive_p:
|
|
949 PUSH (Finteractive_p ());
|
|
950 break;
|
|
951
|
|
952 case Bforward_char:
|
|
953 TOP = Fforward_char (TOP, Fcurrent_buffer ());
|
|
954 break;
|
|
955
|
|
956 case Bforward_word:
|
|
957 TOP = Fforward_word (TOP, Fcurrent_buffer ());
|
|
958 break;
|
|
959
|
|
960 case Bskip_chars_forward:
|
|
961 v1 = POP;
|
|
962 TOP = Fskip_chars_forward (TOP, v1, Fcurrent_buffer ());
|
|
963 break;
|
|
964
|
|
965 case Bskip_chars_backward:
|
|
966 v1 = POP;
|
|
967 TOP = Fskip_chars_backward (TOP, v1, Fcurrent_buffer ());
|
|
968 break;
|
|
969
|
|
970 case Bforward_line:
|
|
971 TOP = Fforward_line (TOP, Fcurrent_buffer ());
|
|
972 break;
|
|
973
|
|
974 case Bchar_syntax:
|
195
|
975 #if 0
|
0
|
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))]);
|
195
|
982 #endif
|
|
983 /*v1 = POP;*/
|
|
984 TOP = Fchar_syntax(TOP, Qnil);
|
0
|
985 break;
|
|
986
|
|
987 case Bbuffer_substring:
|
|
988 v1 = POP;
|
|
989 TOP = Fbuffer_substring (TOP, v1, Fcurrent_buffer ());
|
|
990 break;
|
|
991
|
|
992 case Bdelete_region:
|
|
993 v1 = POP;
|
|
994 TOP = Fdelete_region (TOP, v1, Fcurrent_buffer ());
|
|
995 break;
|
|
996
|
|
997 case Bnarrow_to_region:
|
|
998 v1 = POP;
|
|
999 TOP = Fnarrow_to_region (TOP, v1, Fcurrent_buffer ());
|
|
1000 break;
|
|
1001
|
|
1002 case Bwiden:
|
|
1003 PUSH (Fwiden (Fcurrent_buffer ()));
|
|
1004 break;
|
|
1005
|
|
1006 case Bend_of_line:
|
|
1007 TOP = Fend_of_line (TOP, Fcurrent_buffer ());
|
|
1008 break;
|
|
1009
|
|
1010 case Bset_marker:
|
|
1011 v1 = POP;
|
|
1012 v2 = POP;
|
|
1013 TOP = Fset_marker (TOP, v2, v1);
|
|
1014 break;
|
|
1015
|
|
1016 case Bmatch_beginning:
|
|
1017 TOP = Fmatch_beginning (TOP);
|
|
1018 break;
|
|
1019
|
|
1020 case Bmatch_end:
|
|
1021 TOP = Fmatch_end (TOP);
|
|
1022 break;
|
|
1023
|
|
1024 case Bupcase:
|
|
1025 TOP = Fupcase (TOP, Fcurrent_buffer ());
|
|
1026 break;
|
|
1027
|
|
1028 case Bdowncase:
|
|
1029 TOP = Fdowncase (TOP, Fcurrent_buffer ());
|
|
1030 break;
|
|
1031
|
|
1032 case Bstringeqlsign:
|
|
1033 v1 = POP;
|
|
1034 TOP = Fstring_equal (TOP, v1);
|
|
1035 break;
|
|
1036
|
|
1037 case Bstringlss:
|
|
1038 v1 = POP;
|
|
1039 TOP = Fstring_lessp (TOP, v1);
|
|
1040 break;
|
|
1041
|
|
1042 case Bequal:
|
|
1043 v1 = POP;
|
|
1044 TOP = Fequal (TOP, v1);
|
|
1045 break;
|
|
1046
|
70
|
1047 case Bold_equal:
|
|
1048 v1 = POP;
|
|
1049 TOP = Fold_equal (TOP, v1);
|
|
1050 break;
|
|
1051
|
0
|
1052 case Bnthcdr:
|
|
1053 v1 = POP;
|
|
1054 TOP = Fnthcdr (TOP, v1);
|
|
1055 break;
|
|
1056
|
|
1057 case Belt:
|
|
1058 #if 0
|
|
1059 /* probably this code is OK, but nth_entry is commented
|
|
1060 out above --ben */
|
207
|
1061 /* #### will not work if cons type is an lrecord. */
|
185
|
1062 if (XTYPE (TOP) == Lisp_Type_Cons)
|
0
|
1063 {
|
|
1064 /* Exchange args and then do nth. */
|
|
1065 v2 = POP;
|
|
1066 v1 = TOP;
|
|
1067 goto nth_entry;
|
|
1068 }
|
|
1069 #endif
|
|
1070 v1 = POP;
|
|
1071 TOP = Felt (TOP, v1);
|
|
1072 break;
|
|
1073
|
|
1074 case Bmember:
|
|
1075 v1 = POP;
|
|
1076 TOP = Fmember (TOP, v1);
|
|
1077 break;
|
|
1078
|
70
|
1079 case Bold_member:
|
|
1080 v1 = POP;
|
|
1081 TOP = Fold_member (TOP, v1);
|
|
1082 break;
|
|
1083
|
0
|
1084 case Bassq:
|
|
1085 v1 = POP;
|
|
1086 TOP = Fassq (TOP, v1);
|
|
1087 break;
|
|
1088
|
70
|
1089 case Bold_assq:
|
|
1090 v1 = POP;
|
|
1091 TOP = Fold_assq (TOP, v1);
|
|
1092 break;
|
|
1093
|
0
|
1094 case Bnreverse:
|
|
1095 TOP = Fnreverse (TOP);
|
|
1096 break;
|
|
1097
|
|
1098 case Bsetcar:
|
|
1099 v1 = POP;
|
|
1100 TOP = Fsetcar (TOP, v1);
|
|
1101 break;
|
|
1102
|
|
1103 case Bsetcdr:
|
|
1104 v1 = POP;
|
|
1105 TOP = Fsetcdr (TOP, v1);
|
|
1106 break;
|
|
1107
|
|
1108 case Bcar_safe:
|
|
1109 v1 = TOP;
|
|
1110 if (CONSP (v1))
|
|
1111 TOP = XCAR (v1);
|
|
1112 else
|
|
1113 TOP = Qnil;
|
|
1114 break;
|
|
1115
|
|
1116 case Bcdr_safe:
|
|
1117 v1 = TOP;
|
|
1118 if (CONSP (v1))
|
|
1119 TOP = XCDR (v1);
|
|
1120 else
|
|
1121 TOP = Qnil;
|
|
1122 break;
|
|
1123
|
|
1124 case Bnconc:
|
|
1125 DISCARD (1);
|
|
1126 TOP = Fnconc (2, &TOP);
|
|
1127 break;
|
|
1128
|
|
1129 case Bnumberp:
|
|
1130 TOP = ((INT_OR_FLOATP (TOP)) ? Qt : Qnil);
|
|
1131 break;
|
|
1132
|
|
1133 case Bintegerp:
|
|
1134 TOP = ((INTP (TOP)) ? Qt : Qnil);
|
|
1135 break;
|
|
1136
|
|
1137 default:
|
|
1138 #ifdef BYTE_CODE_SAFE
|
|
1139 if (op < Bconstant)
|
|
1140 error ("unknown bytecode %d (byte compiler bug)", op);
|
|
1141 if ((op -= Bconstant) >= const_length)
|
|
1142 error ("no constant number %d (byte compiler bug)", op);
|
|
1143 PUSH (vectorp[op]);
|
|
1144 #else
|
|
1145 PUSH (vectorp[op - Bconstant]);
|
|
1146 #endif
|
|
1147 }
|
|
1148 }
|
|
1149
|
|
1150 exit:
|
|
1151 UNGCPRO;
|
|
1152 /* Binds and unbinds are supposed to be compiled balanced. */
|
|
1153 if (specpdl_depth() != speccount)
|
|
1154 /* FSF: abort() if BYTE_CODE_SAFE not defined */
|
|
1155 error ("binding stack not balanced (serious byte compiler bug)");
|
|
1156 return v1;
|
|
1157 }
|
|
1158
|
|
1159 void
|
|
1160 syms_of_bytecode (void)
|
|
1161 {
|
|
1162 defsymbol (&Qbyte_code, "byte-code");
|
20
|
1163 DEFSUBR (Fbyte_code);
|
0
|
1164 #ifdef BYTE_CODE_METER
|
|
1165 defsymbol (&Qbyte_code_meter, "byte-code-meter");
|
|
1166 #endif
|
|
1167 }
|
|
1168
|
|
1169 void
|
|
1170 vars_of_bytecode (void)
|
|
1171 {
|
|
1172 #ifdef BYTE_CODE_METER
|
|
1173
|
|
1174 DEFVAR_LISP ("byte-code-meter", &Vbyte_code_meter /*
|
|
1175 A vector of vectors which holds a histogram of byte-code usage.
|
|
1176 (aref (aref byte-code-meter 0) CODE) indicates how many times the byte
|
|
1177 opcode CODE has been executed.
|
|
1178 (aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
|
|
1179 indicates how many times the byte opcodes CODE1 and CODE2 have been
|
|
1180 executed in succession.
|
|
1181 */ );
|
|
1182 DEFVAR_BOOL ("byte-metering-on", &byte_metering_on /*
|
|
1183 If non-nil, keep profiling information on byte code usage.
|
|
1184 The variable byte-code-meter indicates how often each byte opcode is used.
|
|
1185 If a symbol has a property named `byte-code-meter' whose value is an
|
|
1186 integer, it is incremented each time that symbol's function is called.
|
|
1187 */ );
|
|
1188
|
|
1189 byte_metering_on = 0;
|
|
1190 Vbyte_code_meter = make_vector (256, Qzero);
|
|
1191 {
|
|
1192 int i = 256;
|
|
1193 while (i--)
|
173
|
1194 XVECTOR_DATA (Vbyte_code_meter)[i] =
|
0
|
1195 make_vector (256, Qzero);
|
|
1196 }
|
|
1197 #endif
|
|
1198 }
|