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