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