428
|
1 /* Execution of byte code produced by bytecomp.el.
|
|
2 Implementation of compiled-function objects.
|
|
3 Copyright (C) 1992, 1993 Free Software Foundation, Inc.
|
814
|
4 Copyright (C) 1995, 2002 Ben Wing.
|
428
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: Mule 2.0, FSF 19.30. */
|
|
24
|
|
25 /* This file has been Mule-ized. */
|
|
26
|
|
27
|
|
28 /* Authorship:
|
|
29
|
|
30 FSF: long ago.
|
|
31
|
|
32 hacked on by jwz@jwz.org 1991-06
|
|
33 o added a compile-time switch to turn on simple sanity checking;
|
|
34 o put back the obsolete byte-codes for error-detection;
|
|
35 o added a new instruction, unbind_all, which I will use for
|
|
36 tail-recursion elimination;
|
|
37 o made temp_output_buffer_show be called with the right number
|
|
38 of args;
|
|
39 o made the new bytecodes be called with args in the right order;
|
|
40 o added metering support.
|
|
41
|
|
42 by Hallvard:
|
|
43 o added relative jump instructions;
|
|
44 o all conditionals now only do QUIT if they jump.
|
|
45
|
|
46 Ben Wing: some changes for Mule, 1995-06.
|
|
47
|
|
48 Martin Buchholz: performance hacking, 1998-09.
|
|
49 See Internals Manual, Evaluation.
|
|
50 */
|
|
51
|
|
52 #include <config.h>
|
|
53 #include "lisp.h"
|
|
54 #include "backtrace.h"
|
|
55 #include "buffer.h"
|
|
56 #include "bytecode.h"
|
|
57 #include "opaque.h"
|
|
58 #include "syntax.h"
|
872
|
59 #include "window.h"
|
428
|
60
|
|
61 EXFUN (Ffetch_bytecode, 1);
|
|
62
|
|
63 Lisp_Object Qbyte_code, Qcompiled_functionp, Qinvalid_byte_code;
|
|
64
|
|
65 enum Opcode /* Byte codes */
|
|
66 {
|
|
67 Bvarref = 010,
|
|
68 Bvarset = 020,
|
|
69 Bvarbind = 030,
|
|
70 Bcall = 040,
|
|
71 Bunbind = 050,
|
|
72
|
|
73 Bnth = 070,
|
|
74 Bsymbolp = 071,
|
|
75 Bconsp = 072,
|
|
76 Bstringp = 073,
|
|
77 Blistp = 074,
|
|
78 Bold_eq = 075,
|
|
79 Bold_memq = 076,
|
|
80 Bnot = 077,
|
|
81 Bcar = 0100,
|
|
82 Bcdr = 0101,
|
|
83 Bcons = 0102,
|
|
84 Blist1 = 0103,
|
|
85 Blist2 = 0104,
|
|
86 Blist3 = 0105,
|
|
87 Blist4 = 0106,
|
|
88 Blength = 0107,
|
|
89 Baref = 0110,
|
|
90 Baset = 0111,
|
|
91 Bsymbol_value = 0112,
|
|
92 Bsymbol_function = 0113,
|
|
93 Bset = 0114,
|
|
94 Bfset = 0115,
|
|
95 Bget = 0116,
|
|
96 Bsubstring = 0117,
|
|
97 Bconcat2 = 0120,
|
|
98 Bconcat3 = 0121,
|
|
99 Bconcat4 = 0122,
|
|
100 Bsub1 = 0123,
|
|
101 Badd1 = 0124,
|
|
102 Beqlsign = 0125,
|
|
103 Bgtr = 0126,
|
|
104 Blss = 0127,
|
|
105 Bleq = 0130,
|
|
106 Bgeq = 0131,
|
|
107 Bdiff = 0132,
|
|
108 Bnegate = 0133,
|
|
109 Bplus = 0134,
|
|
110 Bmax = 0135,
|
|
111 Bmin = 0136,
|
|
112 Bmult = 0137,
|
|
113
|
|
114 Bpoint = 0140,
|
|
115 Beq = 0141, /* was Bmark,
|
|
116 but no longer generated as of v18 */
|
|
117 Bgoto_char = 0142,
|
|
118 Binsert = 0143,
|
|
119 Bpoint_max = 0144,
|
|
120 Bpoint_min = 0145,
|
|
121 Bchar_after = 0146,
|
|
122 Bfollowing_char = 0147,
|
|
123 Bpreceding_char = 0150,
|
|
124 Bcurrent_column = 0151,
|
|
125 Bindent_to = 0152,
|
|
126 Bequal = 0153, /* was Bscan_buffer,
|
|
127 but no longer generated as of v18 */
|
|
128 Beolp = 0154,
|
|
129 Beobp = 0155,
|
|
130 Bbolp = 0156,
|
|
131 Bbobp = 0157,
|
|
132 Bcurrent_buffer = 0160,
|
|
133 Bset_buffer = 0161,
|
|
134 Bsave_current_buffer = 0162, /* was Bread_char,
|
|
135 but no longer generated as of v19 */
|
|
136 Bmemq = 0163, /* was Bset_mark,
|
|
137 but no longer generated as of v18 */
|
|
138 Binteractive_p = 0164, /* Needed since interactive-p takes
|
|
139 unevalled args */
|
|
140 Bforward_char = 0165,
|
|
141 Bforward_word = 0166,
|
|
142 Bskip_chars_forward = 0167,
|
|
143 Bskip_chars_backward = 0170,
|
|
144 Bforward_line = 0171,
|
|
145 Bchar_syntax = 0172,
|
|
146 Bbuffer_substring = 0173,
|
|
147 Bdelete_region = 0174,
|
|
148 Bnarrow_to_region = 0175,
|
|
149 Bwiden = 0176,
|
|
150 Bend_of_line = 0177,
|
|
151
|
|
152 Bconstant2 = 0201,
|
|
153 Bgoto = 0202,
|
|
154 Bgotoifnil = 0203,
|
|
155 Bgotoifnonnil = 0204,
|
|
156 Bgotoifnilelsepop = 0205,
|
|
157 Bgotoifnonnilelsepop = 0206,
|
|
158 Breturn = 0207,
|
|
159 Bdiscard = 0210,
|
|
160 Bdup = 0211,
|
|
161
|
|
162 Bsave_excursion = 0212,
|
|
163 Bsave_window_excursion= 0213,
|
|
164 Bsave_restriction = 0214,
|
|
165 Bcatch = 0215,
|
|
166
|
|
167 Bunwind_protect = 0216,
|
|
168 Bcondition_case = 0217,
|
|
169 Btemp_output_buffer_setup = 0220,
|
|
170 Btemp_output_buffer_show = 0221,
|
|
171
|
|
172 Bunbind_all = 0222,
|
|
173
|
|
174 Bset_marker = 0223,
|
|
175 Bmatch_beginning = 0224,
|
|
176 Bmatch_end = 0225,
|
|
177 Bupcase = 0226,
|
|
178 Bdowncase = 0227,
|
|
179
|
|
180 Bstring_equal = 0230,
|
|
181 Bstring_lessp = 0231,
|
|
182 Bold_equal = 0232,
|
|
183 Bnthcdr = 0233,
|
|
184 Belt = 0234,
|
|
185 Bold_member = 0235,
|
|
186 Bold_assq = 0236,
|
|
187 Bnreverse = 0237,
|
|
188 Bsetcar = 0240,
|
|
189 Bsetcdr = 0241,
|
|
190 Bcar_safe = 0242,
|
|
191 Bcdr_safe = 0243,
|
|
192 Bnconc = 0244,
|
|
193 Bquo = 0245,
|
|
194 Brem = 0246,
|
|
195 Bnumberp = 0247,
|
|
196 Bintegerp = 0250,
|
|
197
|
|
198 BRgoto = 0252,
|
|
199 BRgotoifnil = 0253,
|
|
200 BRgotoifnonnil = 0254,
|
|
201 BRgotoifnilelsepop = 0255,
|
|
202 BRgotoifnonnilelsepop = 0256,
|
|
203
|
|
204 BlistN = 0257,
|
|
205 BconcatN = 0260,
|
|
206 BinsertN = 0261,
|
|
207 Bmember = 0266, /* new in v20 */
|
|
208 Bassq = 0267, /* new in v20 */
|
|
209
|
|
210 Bconstant = 0300
|
|
211 };
|
|
212 typedef enum Opcode Opcode;
|
|
213
|
|
214
|
|
215 Lisp_Object * execute_rare_opcode (Lisp_Object *stack_ptr,
|
442
|
216 const Opbyte *program_ptr,
|
428
|
217 Opcode opcode);
|
|
218
|
|
219 /* Define BYTE_CODE_METER to enable generation of a byte-op usage histogram.
|
|
220 This isn't defined in FSF Emacs and isn't defined in XEmacs v19. */
|
|
221 /* #define BYTE_CODE_METER */
|
|
222
|
|
223
|
|
224 #ifdef BYTE_CODE_METER
|
|
225
|
|
226 Lisp_Object Vbyte_code_meter, Qbyte_code_meter;
|
|
227 int byte_metering_on;
|
|
228
|
|
229 static void
|
|
230 meter_code (Opcode prev_opcode, Opcode this_opcode)
|
|
231 {
|
|
232 if (byte_metering_on)
|
|
233 {
|
|
234 Lisp_Object *p = XVECTOR_DATA (XVECTOR_DATA (Vbyte_code_meter)[this_opcode]);
|
|
235 p[0] = INT_PLUS1 (p[0]);
|
|
236 if (prev_opcode)
|
|
237 p[prev_opcode] = INT_PLUS1 (p[prev_opcode]);
|
|
238 }
|
|
239 }
|
|
240
|
|
241 #endif /* BYTE_CODE_METER */
|
|
242
|
|
243
|
|
244 static Lisp_Object
|
|
245 bytecode_negate (Lisp_Object obj)
|
|
246 {
|
|
247 retry:
|
|
248
|
|
249 if (INTP (obj)) return make_int (- XINT (obj));
|
|
250 #ifdef LISP_FLOAT_TYPE
|
|
251 if (FLOATP (obj)) return make_float (- XFLOAT_DATA (obj));
|
|
252 #endif
|
|
253 if (CHARP (obj)) return make_int (- ((int) XCHAR (obj)));
|
|
254 if (MARKERP (obj)) return make_int (- ((int) marker_position (obj)));
|
|
255
|
|
256 obj = wrong_type_argument (Qnumber_char_or_marker_p, obj);
|
|
257 goto retry;
|
|
258 }
|
|
259
|
|
260 static Lisp_Object
|
|
261 bytecode_nreverse (Lisp_Object list)
|
|
262 {
|
|
263 REGISTER Lisp_Object prev = Qnil;
|
|
264 REGISTER Lisp_Object tail = list;
|
|
265
|
|
266 while (!NILP (tail))
|
|
267 {
|
|
268 REGISTER Lisp_Object next;
|
|
269 CHECK_CONS (tail);
|
|
270 next = XCDR (tail);
|
|
271 XCDR (tail) = prev;
|
|
272 prev = tail;
|
|
273 tail = next;
|
|
274 }
|
|
275 return prev;
|
|
276 }
|
|
277
|
|
278
|
|
279 /* We have our own two-argument versions of various arithmetic ops.
|
|
280 Only two-argument arithmetic operations have their own byte codes. */
|
|
281 static int
|
|
282 bytecode_arithcompare (Lisp_Object obj1, Lisp_Object obj2)
|
|
283 {
|
|
284 retry:
|
|
285
|
|
286 #ifdef LISP_FLOAT_TYPE
|
|
287 {
|
|
288 EMACS_INT ival1, ival2;
|
|
289
|
|
290 if (INTP (obj1)) ival1 = XINT (obj1);
|
|
291 else if (CHARP (obj1)) ival1 = XCHAR (obj1);
|
|
292 else if (MARKERP (obj1)) ival1 = marker_position (obj1);
|
|
293 else goto arithcompare_float;
|
|
294
|
|
295 if (INTP (obj2)) ival2 = XINT (obj2);
|
|
296 else if (CHARP (obj2)) ival2 = XCHAR (obj2);
|
|
297 else if (MARKERP (obj2)) ival2 = marker_position (obj2);
|
|
298 else goto arithcompare_float;
|
|
299
|
|
300 return ival1 < ival2 ? -1 : ival1 > ival2 ? 1 : 0;
|
|
301 }
|
|
302
|
|
303 arithcompare_float:
|
|
304
|
|
305 {
|
|
306 double dval1, dval2;
|
|
307
|
|
308 if (FLOATP (obj1)) dval1 = XFLOAT_DATA (obj1);
|
|
309 else if (INTP (obj1)) dval1 = (double) XINT (obj1);
|
|
310 else if (CHARP (obj1)) dval1 = (double) XCHAR (obj1);
|
|
311 else if (MARKERP (obj1)) dval1 = (double) marker_position (obj1);
|
|
312 else
|
|
313 {
|
|
314 obj1 = wrong_type_argument (Qnumber_char_or_marker_p, obj1);
|
|
315 goto retry;
|
|
316 }
|
|
317
|
|
318 if (FLOATP (obj2)) dval2 = XFLOAT_DATA (obj2);
|
|
319 else if (INTP (obj2)) dval2 = (double) XINT (obj2);
|
|
320 else if (CHARP (obj2)) dval2 = (double) XCHAR (obj2);
|
|
321 else if (MARKERP (obj2)) dval2 = (double) marker_position (obj2);
|
|
322 else
|
|
323 {
|
|
324 obj2 = wrong_type_argument (Qnumber_char_or_marker_p, obj2);
|
|
325 goto retry;
|
|
326 }
|
|
327
|
|
328 return dval1 < dval2 ? -1 : dval1 > dval2 ? 1 : 0;
|
|
329 }
|
|
330 #else /* !LISP_FLOAT_TYPE */
|
|
331 {
|
|
332 EMACS_INT ival1, ival2;
|
|
333
|
|
334 if (INTP (obj1)) ival1 = XINT (obj1);
|
|
335 else if (CHARP (obj1)) ival1 = XCHAR (obj1);
|
|
336 else if (MARKERP (obj1)) ival1 = marker_position (obj1);
|
|
337 else
|
|
338 {
|
|
339 obj1 = wrong_type_argument (Qnumber_char_or_marker_p, obj1);
|
|
340 goto retry;
|
|
341 }
|
|
342
|
|
343 if (INTP (obj2)) ival2 = XINT (obj2);
|
|
344 else if (CHARP (obj2)) ival2 = XCHAR (obj2);
|
|
345 else if (MARKERP (obj2)) ival2 = marker_position (obj2);
|
|
346 else
|
|
347 {
|
|
348 obj2 = wrong_type_argument (Qnumber_char_or_marker_p, obj2);
|
|
349 goto retry;
|
|
350 }
|
|
351
|
|
352 return ival1 < ival2 ? -1 : ival1 > ival2 ? 1 : 0;
|
|
353 }
|
|
354 #endif /* !LISP_FLOAT_TYPE */
|
|
355 }
|
|
356
|
|
357 static Lisp_Object
|
|
358 bytecode_arithop (Lisp_Object obj1, Lisp_Object obj2, Opcode opcode)
|
|
359 {
|
|
360 #ifdef LISP_FLOAT_TYPE
|
|
361 EMACS_INT ival1, ival2;
|
|
362 int float_p;
|
|
363
|
|
364 retry:
|
|
365
|
|
366 float_p = 0;
|
|
367
|
|
368 if (INTP (obj1)) ival1 = XINT (obj1);
|
|
369 else if (CHARP (obj1)) ival1 = XCHAR (obj1);
|
|
370 else if (MARKERP (obj1)) ival1 = marker_position (obj1);
|
|
371 else if (FLOATP (obj1)) ival1 = 0, float_p = 1;
|
|
372 else
|
|
373 {
|
|
374 obj1 = wrong_type_argument (Qnumber_char_or_marker_p, obj1);
|
|
375 goto retry;
|
|
376 }
|
|
377
|
|
378 if (INTP (obj2)) ival2 = XINT (obj2);
|
|
379 else if (CHARP (obj2)) ival2 = XCHAR (obj2);
|
|
380 else if (MARKERP (obj2)) ival2 = marker_position (obj2);
|
|
381 else if (FLOATP (obj2)) ival2 = 0, float_p = 1;
|
|
382 else
|
|
383 {
|
|
384 obj2 = wrong_type_argument (Qnumber_char_or_marker_p, obj2);
|
|
385 goto retry;
|
|
386 }
|
|
387
|
|
388 if (!float_p)
|
|
389 {
|
|
390 switch (opcode)
|
|
391 {
|
|
392 case Bplus: ival1 += ival2; break;
|
|
393 case Bdiff: ival1 -= ival2; break;
|
|
394 case Bmult: ival1 *= ival2; break;
|
|
395 case Bquo:
|
|
396 if (ival2 == 0) Fsignal (Qarith_error, Qnil);
|
|
397 ival1 /= ival2;
|
|
398 break;
|
|
399 case Bmax: if (ival1 < ival2) ival1 = ival2; break;
|
|
400 case Bmin: if (ival1 > ival2) ival1 = ival2; break;
|
|
401 }
|
|
402 return make_int (ival1);
|
|
403 }
|
|
404 else
|
|
405 {
|
|
406 double dval1 = FLOATP (obj1) ? XFLOAT_DATA (obj1) : (double) ival1;
|
|
407 double dval2 = FLOATP (obj2) ? XFLOAT_DATA (obj2) : (double) ival2;
|
|
408 switch (opcode)
|
|
409 {
|
|
410 case Bplus: dval1 += dval2; break;
|
|
411 case Bdiff: dval1 -= dval2; break;
|
|
412 case Bmult: dval1 *= dval2; break;
|
|
413 case Bquo:
|
|
414 if (dval2 == 0) Fsignal (Qarith_error, Qnil);
|
|
415 dval1 /= dval2;
|
|
416 break;
|
|
417 case Bmax: if (dval1 < dval2) dval1 = dval2; break;
|
|
418 case Bmin: if (dval1 > dval2) dval1 = dval2; break;
|
|
419 }
|
|
420 return make_float (dval1);
|
|
421 }
|
|
422 #else /* !LISP_FLOAT_TYPE */
|
|
423 EMACS_INT ival1, ival2;
|
|
424
|
|
425 retry:
|
|
426
|
|
427 if (INTP (obj1)) ival1 = XINT (obj1);
|
|
428 else if (CHARP (obj1)) ival1 = XCHAR (obj1);
|
|
429 else if (MARKERP (obj1)) ival1 = marker_position (obj1);
|
|
430 else
|
|
431 {
|
|
432 obj1 = wrong_type_argument (Qnumber_char_or_marker_p, obj1);
|
|
433 goto retry;
|
|
434 }
|
|
435
|
|
436 if (INTP (obj2)) ival2 = XINT (obj2);
|
|
437 else if (CHARP (obj2)) ival2 = XCHAR (obj2);
|
|
438 else if (MARKERP (obj2)) ival2 = marker_position (obj2);
|
|
439 else
|
|
440 {
|
|
441 obj2 = wrong_type_argument (Qnumber_char_or_marker_p, obj2);
|
|
442 goto retry;
|
|
443 }
|
|
444
|
|
445 switch (opcode)
|
|
446 {
|
|
447 case Bplus: ival1 += ival2; break;
|
|
448 case Bdiff: ival1 -= ival2; break;
|
|
449 case Bmult: ival1 *= ival2; break;
|
|
450 case Bquo:
|
|
451 if (ival2 == 0) Fsignal (Qarith_error, Qnil);
|
|
452 ival1 /= ival2;
|
|
453 break;
|
|
454 case Bmax: if (ival1 < ival2) ival1 = ival2; break;
|
|
455 case Bmin: if (ival1 > ival2) ival1 = ival2; break;
|
|
456 }
|
|
457 return make_int (ival1);
|
|
458 #endif /* !LISP_FLOAT_TYPE */
|
|
459 }
|
|
460
|
|
461
|
|
462 /* Read next uint8 from the instruction stream. */
|
|
463 #define READ_UINT_1 ((unsigned int) (unsigned char) *program_ptr++)
|
|
464
|
|
465 /* Read next uint16 from the instruction stream. */
|
|
466 #define READ_UINT_2 \
|
|
467 (program_ptr += 2, \
|
|
468 (((unsigned int) (unsigned char) program_ptr[-1]) * 256 + \
|
|
469 ((unsigned int) (unsigned char) program_ptr[-2])))
|
|
470
|
|
471 /* Read next int8 from the instruction stream. */
|
|
472 #define READ_INT_1 ((int) (signed char) *program_ptr++)
|
|
473
|
|
474 /* Read next int16 from the instruction stream. */
|
|
475 #define READ_INT_2 \
|
|
476 (program_ptr += 2, \
|
|
477 (((int) ( signed char) program_ptr[-1]) * 256 + \
|
|
478 ((int) (unsigned char) program_ptr[-2])))
|
|
479
|
|
480 /* Read next int8 from instruction stream; don't advance program_pointer */
|
|
481 #define PEEK_INT_1 ((int) (signed char) program_ptr[0])
|
|
482
|
|
483 /* Read next int16 from instruction stream; don't advance program_pointer */
|
|
484 #define PEEK_INT_2 \
|
|
485 ((((int) ( signed char) program_ptr[1]) * 256) | \
|
|
486 ((int) (unsigned char) program_ptr[0]))
|
|
487
|
|
488 /* Do relative jumps from the current location.
|
|
489 We only do a QUIT if we jump backwards, for efficiency.
|
|
490 No infloops without backward jumps! */
|
|
491 #define JUMP_RELATIVE(jump) do { \
|
|
492 int JR_jump = (jump); \
|
|
493 if (JR_jump < 0) QUIT; \
|
|
494 program_ptr += JR_jump; \
|
|
495 } while (0)
|
|
496
|
|
497 #define JUMP JUMP_RELATIVE (PEEK_INT_2)
|
|
498 #define JUMPR JUMP_RELATIVE (PEEK_INT_1)
|
|
499
|
|
500 #define JUMP_NEXT ((void) (program_ptr += 2))
|
|
501 #define JUMPR_NEXT ((void) (program_ptr += 1))
|
|
502
|
|
503 /* Push x onto the execution stack. */
|
|
504 #define PUSH(x) (*++stack_ptr = (x))
|
|
505
|
|
506 /* Pop a value off the execution stack. */
|
|
507 #define POP (*stack_ptr--)
|
|
508
|
|
509 /* Discard n values from the execution stack. */
|
|
510 #define DISCARD(n) (stack_ptr -= (n))
|
|
511
|
|
512 /* Get the value which is at the top of the execution stack,
|
|
513 but don't pop it. */
|
|
514 #define TOP (*stack_ptr)
|
|
515
|
|
516 /* The actual interpreter for byte code.
|
|
517 This function has been seriously optimized for performance.
|
|
518 Don't change the constructs unless you are willing to do
|
|
519 real benchmarking and profiling work -- martin */
|
|
520
|
|
521
|
814
|
522 Lisp_Object
|
442
|
523 execute_optimized_program (const Opbyte *program,
|
428
|
524 int stack_depth,
|
|
525 Lisp_Object *constants_data)
|
|
526 {
|
|
527 /* This function can GC */
|
442
|
528 REGISTER const Opbyte *program_ptr = (Opbyte *) program;
|
428
|
529 REGISTER Lisp_Object *stack_ptr
|
|
530 = alloca_array (Lisp_Object, stack_depth + 1);
|
|
531 int speccount = specpdl_depth ();
|
|
532 struct gcpro gcpro1;
|
|
533
|
|
534 #ifdef BYTE_CODE_METER
|
|
535 Opcode this_opcode = 0;
|
|
536 Opcode prev_opcode;
|
|
537 #endif
|
|
538
|
|
539 #ifdef ERROR_CHECK_BYTE_CODE
|
|
540 Lisp_Object *stack_beg = stack_ptr;
|
|
541 Lisp_Object *stack_end = stack_beg + stack_depth;
|
|
542 #endif
|
|
543
|
|
544 /* Initialize all the objects on the stack to Qnil,
|
|
545 so we can GCPRO the whole stack.
|
|
546 The first element of the stack is actually a dummy. */
|
|
547 {
|
|
548 int i;
|
|
549 Lisp_Object *p;
|
|
550 for (i = stack_depth, p = stack_ptr; i--;)
|
|
551 *++p = Qnil;
|
|
552 }
|
|
553
|
|
554 GCPRO1 (stack_ptr[1]);
|
|
555 gcpro1.nvars = stack_depth;
|
|
556
|
|
557 while (1)
|
|
558 {
|
|
559 REGISTER Opcode opcode = (Opcode) READ_UINT_1;
|
|
560 #ifdef ERROR_CHECK_BYTE_CODE
|
|
561 if (stack_ptr > stack_end)
|
563
|
562 stack_overflow ("byte code stack overflow", Qunbound);
|
428
|
563 if (stack_ptr < stack_beg)
|
563
|
564 stack_overflow ("byte code stack underflow", Qunbound);
|
428
|
565 #endif
|
|
566
|
|
567 #ifdef BYTE_CODE_METER
|
|
568 prev_opcode = this_opcode;
|
|
569 this_opcode = opcode;
|
|
570 meter_code (prev_opcode, this_opcode);
|
|
571 #endif
|
|
572
|
|
573 switch (opcode)
|
|
574 {
|
|
575 REGISTER int n;
|
|
576
|
|
577 default:
|
|
578 if (opcode >= Bconstant)
|
|
579 PUSH (constants_data[opcode - Bconstant]);
|
|
580 else
|
|
581 stack_ptr = execute_rare_opcode (stack_ptr, program_ptr, opcode);
|
|
582 break;
|
|
583
|
|
584 case Bvarref:
|
|
585 case Bvarref+1:
|
|
586 case Bvarref+2:
|
|
587 case Bvarref+3:
|
|
588 case Bvarref+4:
|
|
589 case Bvarref+5: n = opcode - Bvarref; goto do_varref;
|
|
590 case Bvarref+7: n = READ_UINT_2; goto do_varref;
|
|
591 case Bvarref+6: n = READ_UINT_1; /* most common */
|
|
592 do_varref:
|
|
593 {
|
|
594 Lisp_Object symbol = constants_data[n];
|
|
595 Lisp_Object value = XSYMBOL (symbol)->value;
|
|
596 if (SYMBOL_VALUE_MAGIC_P (value))
|
|
597 value = Fsymbol_value (symbol);
|
|
598 PUSH (value);
|
|
599 break;
|
|
600 }
|
|
601
|
|
602 case Bvarset:
|
|
603 case Bvarset+1:
|
|
604 case Bvarset+2:
|
|
605 case Bvarset+3:
|
|
606 case Bvarset+4:
|
|
607 case Bvarset+5: n = opcode - Bvarset; goto do_varset;
|
|
608 case Bvarset+7: n = READ_UINT_2; goto do_varset;
|
|
609 case Bvarset+6: n = READ_UINT_1; /* most common */
|
|
610 do_varset:
|
|
611 {
|
|
612 Lisp_Object symbol = constants_data[n];
|
440
|
613 Lisp_Symbol *symbol_ptr = XSYMBOL (symbol);
|
428
|
614 Lisp_Object old_value = symbol_ptr->value;
|
|
615 Lisp_Object new_value = POP;
|
|
616 if (!SYMBOL_VALUE_MAGIC_P (old_value) || UNBOUNDP (old_value))
|
|
617 symbol_ptr->value = new_value;
|
|
618 else
|
|
619 Fset (symbol, new_value);
|
|
620 break;
|
|
621 }
|
|
622
|
|
623 case Bvarbind:
|
|
624 case Bvarbind+1:
|
|
625 case Bvarbind+2:
|
|
626 case Bvarbind+3:
|
|
627 case Bvarbind+4:
|
|
628 case Bvarbind+5: n = opcode - Bvarbind; goto do_varbind;
|
|
629 case Bvarbind+7: n = READ_UINT_2; goto do_varbind;
|
|
630 case Bvarbind+6: n = READ_UINT_1; /* most common */
|
|
631 do_varbind:
|
|
632 {
|
|
633 Lisp_Object symbol = constants_data[n];
|
440
|
634 Lisp_Symbol *symbol_ptr = XSYMBOL (symbol);
|
428
|
635 Lisp_Object old_value = symbol_ptr->value;
|
|
636 Lisp_Object new_value = POP;
|
|
637 if (!SYMBOL_VALUE_MAGIC_P (old_value) || UNBOUNDP (old_value))
|
|
638 {
|
|
639 specpdl_ptr->symbol = symbol;
|
|
640 specpdl_ptr->old_value = old_value;
|
|
641 specpdl_ptr->func = 0;
|
|
642 specpdl_ptr++;
|
|
643 specpdl_depth_counter++;
|
|
644
|
|
645 symbol_ptr->value = new_value;
|
853
|
646
|
|
647 #ifdef ERROR_CHECK_CATCH
|
|
648 check_specbind_stack_sanity ();
|
|
649 #endif
|
428
|
650 }
|
|
651 else
|
|
652 specbind_magic (symbol, new_value);
|
|
653 break;
|
|
654 }
|
|
655
|
|
656 case Bcall:
|
|
657 case Bcall+1:
|
|
658 case Bcall+2:
|
|
659 case Bcall+3:
|
|
660 case Bcall+4:
|
|
661 case Bcall+5:
|
|
662 case Bcall+6:
|
|
663 case Bcall+7:
|
|
664 n = (opcode < Bcall+6 ? opcode - Bcall :
|
|
665 opcode == Bcall+6 ? READ_UINT_1 : READ_UINT_2);
|
|
666 DISCARD (n);
|
|
667 #ifdef BYTE_CODE_METER
|
|
668 if (byte_metering_on && SYMBOLP (TOP))
|
|
669 {
|
|
670 Lisp_Object val = Fget (TOP, Qbyte_code_meter, Qnil);
|
|
671 if (INTP (val))
|
|
672 Fput (TOP, Qbyte_code_meter, make_int (XINT (val) + 1));
|
|
673 }
|
|
674 #endif
|
|
675 TOP = Ffuncall (n + 1, &TOP);
|
|
676 break;
|
|
677
|
|
678 case Bunbind:
|
|
679 case Bunbind+1:
|
|
680 case Bunbind+2:
|
|
681 case Bunbind+3:
|
|
682 case Bunbind+4:
|
|
683 case Bunbind+5:
|
|
684 case Bunbind+6:
|
|
685 case Bunbind+7:
|
|
686 UNBIND_TO (specpdl_depth() -
|
|
687 (opcode < Bunbind+6 ? opcode-Bunbind :
|
|
688 opcode == Bunbind+6 ? READ_UINT_1 : READ_UINT_2));
|
|
689 break;
|
|
690
|
|
691
|
|
692 case Bgoto:
|
|
693 JUMP;
|
|
694 break;
|
|
695
|
|
696 case Bgotoifnil:
|
|
697 if (NILP (POP))
|
|
698 JUMP;
|
|
699 else
|
|
700 JUMP_NEXT;
|
|
701 break;
|
|
702
|
|
703 case Bgotoifnonnil:
|
|
704 if (!NILP (POP))
|
|
705 JUMP;
|
|
706 else
|
|
707 JUMP_NEXT;
|
|
708 break;
|
|
709
|
|
710 case Bgotoifnilelsepop:
|
|
711 if (NILP (TOP))
|
|
712 JUMP;
|
|
713 else
|
|
714 {
|
|
715 DISCARD (1);
|
|
716 JUMP_NEXT;
|
|
717 }
|
|
718 break;
|
|
719
|
|
720 case Bgotoifnonnilelsepop:
|
|
721 if (!NILP (TOP))
|
|
722 JUMP;
|
|
723 else
|
|
724 {
|
|
725 DISCARD (1);
|
|
726 JUMP_NEXT;
|
|
727 }
|
|
728 break;
|
|
729
|
|
730
|
|
731 case BRgoto:
|
|
732 JUMPR;
|
|
733 break;
|
|
734
|
|
735 case BRgotoifnil:
|
|
736 if (NILP (POP))
|
|
737 JUMPR;
|
|
738 else
|
|
739 JUMPR_NEXT;
|
|
740 break;
|
|
741
|
|
742 case BRgotoifnonnil:
|
|
743 if (!NILP (POP))
|
|
744 JUMPR;
|
|
745 else
|
|
746 JUMPR_NEXT;
|
|
747 break;
|
|
748
|
|
749 case BRgotoifnilelsepop:
|
|
750 if (NILP (TOP))
|
|
751 JUMPR;
|
|
752 else
|
|
753 {
|
|
754 DISCARD (1);
|
|
755 JUMPR_NEXT;
|
|
756 }
|
|
757 break;
|
|
758
|
|
759 case BRgotoifnonnilelsepop:
|
|
760 if (!NILP (TOP))
|
|
761 JUMPR;
|
|
762 else
|
|
763 {
|
|
764 DISCARD (1);
|
|
765 JUMPR_NEXT;
|
|
766 }
|
|
767 break;
|
|
768
|
|
769 case Breturn:
|
|
770 UNGCPRO;
|
|
771 #ifdef ERROR_CHECK_BYTE_CODE
|
|
772 /* Binds and unbinds are supposed to be compiled balanced. */
|
|
773 if (specpdl_depth() != speccount)
|
563
|
774 invalid_byte_code ("unbalanced specbinding stack", Qunbound);
|
428
|
775 #endif
|
|
776 return TOP;
|
|
777
|
|
778 case Bdiscard:
|
|
779 DISCARD (1);
|
|
780 break;
|
|
781
|
|
782 case Bdup:
|
|
783 {
|
|
784 Lisp_Object arg = TOP;
|
|
785 PUSH (arg);
|
|
786 break;
|
|
787 }
|
|
788
|
|
789 case Bconstant2:
|
|
790 PUSH (constants_data[READ_UINT_2]);
|
|
791 break;
|
|
792
|
|
793 case Bcar:
|
|
794 TOP = CONSP (TOP) ? XCAR (TOP) : Fcar (TOP);
|
|
795 break;
|
|
796
|
|
797 case Bcdr:
|
|
798 TOP = CONSP (TOP) ? XCDR (TOP) : Fcdr (TOP);
|
|
799 break;
|
|
800
|
|
801
|
|
802 case Bunbind_all:
|
|
803 /* To unbind back to the beginning of this frame. Not used yet,
|
|
804 but will be needed for tail-recursion elimination. */
|
771
|
805 unbind_to (speccount);
|
428
|
806 break;
|
|
807
|
|
808 case Bnth:
|
|
809 {
|
|
810 Lisp_Object arg = POP;
|
|
811 TOP = Fcar (Fnthcdr (TOP, arg));
|
|
812 break;
|
|
813 }
|
|
814
|
|
815 case Bsymbolp:
|
|
816 TOP = SYMBOLP (TOP) ? Qt : Qnil;
|
|
817 break;
|
|
818
|
|
819 case Bconsp:
|
|
820 TOP = CONSP (TOP) ? Qt : Qnil;
|
|
821 break;
|
|
822
|
|
823 case Bstringp:
|
|
824 TOP = STRINGP (TOP) ? Qt : Qnil;
|
|
825 break;
|
|
826
|
|
827 case Blistp:
|
|
828 TOP = LISTP (TOP) ? Qt : Qnil;
|
|
829 break;
|
|
830
|
|
831 case Bnumberp:
|
|
832 TOP = INT_OR_FLOATP (TOP) ? Qt : Qnil;
|
|
833 break;
|
|
834
|
|
835 case Bintegerp:
|
|
836 TOP = INTP (TOP) ? Qt : Qnil;
|
|
837 break;
|
|
838
|
|
839 case Beq:
|
|
840 {
|
|
841 Lisp_Object arg = POP;
|
|
842 TOP = EQ_WITH_EBOLA_NOTICE (TOP, arg) ? Qt : Qnil;
|
|
843 break;
|
|
844 }
|
|
845
|
|
846 case Bnot:
|
|
847 TOP = NILP (TOP) ? Qt : Qnil;
|
|
848 break;
|
|
849
|
|
850 case Bcons:
|
|
851 {
|
|
852 Lisp_Object arg = POP;
|
|
853 TOP = Fcons (TOP, arg);
|
|
854 break;
|
|
855 }
|
|
856
|
|
857 case Blist1:
|
|
858 TOP = Fcons (TOP, Qnil);
|
|
859 break;
|
|
860
|
|
861
|
|
862 case BlistN:
|
|
863 n = READ_UINT_1;
|
|
864 goto do_list;
|
|
865
|
|
866 case Blist2:
|
|
867 case Blist3:
|
|
868 case Blist4:
|
|
869 /* common case */
|
|
870 n = opcode - (Blist1 - 1);
|
|
871 do_list:
|
|
872 {
|
|
873 Lisp_Object list = Qnil;
|
|
874 list_loop:
|
|
875 list = Fcons (TOP, list);
|
|
876 if (--n)
|
|
877 {
|
|
878 DISCARD (1);
|
|
879 goto list_loop;
|
|
880 }
|
|
881 TOP = list;
|
|
882 break;
|
|
883 }
|
|
884
|
|
885
|
|
886 case Bconcat2:
|
|
887 case Bconcat3:
|
|
888 case Bconcat4:
|
|
889 n = opcode - (Bconcat2 - 2);
|
|
890 goto do_concat;
|
|
891
|
|
892 case BconcatN:
|
|
893 /* common case */
|
|
894 n = READ_UINT_1;
|
|
895 do_concat:
|
|
896 DISCARD (n - 1);
|
|
897 TOP = Fconcat (n, &TOP);
|
|
898 break;
|
|
899
|
|
900
|
|
901 case Blength:
|
|
902 TOP = Flength (TOP);
|
|
903 break;
|
|
904
|
|
905 case Baset:
|
|
906 {
|
|
907 Lisp_Object arg2 = POP;
|
|
908 Lisp_Object arg1 = POP;
|
|
909 TOP = Faset (TOP, arg1, arg2);
|
|
910 break;
|
|
911 }
|
|
912
|
|
913 case Bsymbol_value:
|
|
914 TOP = Fsymbol_value (TOP);
|
|
915 break;
|
|
916
|
|
917 case Bsymbol_function:
|
|
918 TOP = Fsymbol_function (TOP);
|
|
919 break;
|
|
920
|
|
921 case Bget:
|
|
922 {
|
|
923 Lisp_Object arg = POP;
|
|
924 TOP = Fget (TOP, arg, Qnil);
|
|
925 break;
|
|
926 }
|
|
927
|
|
928 case Bsub1:
|
|
929 TOP = INTP (TOP) ? INT_MINUS1 (TOP) : Fsub1 (TOP);
|
|
930 break;
|
|
931
|
|
932 case Badd1:
|
|
933 TOP = INTP (TOP) ? INT_PLUS1 (TOP) : Fadd1 (TOP);
|
|
934 break;
|
|
935
|
|
936
|
|
937 case Beqlsign:
|
|
938 {
|
|
939 Lisp_Object arg = POP;
|
|
940 TOP = bytecode_arithcompare (TOP, arg) == 0 ? Qt : Qnil;
|
|
941 break;
|
|
942 }
|
|
943
|
|
944 case Bgtr:
|
|
945 {
|
|
946 Lisp_Object arg = POP;
|
|
947 TOP = bytecode_arithcompare (TOP, arg) > 0 ? Qt : Qnil;
|
|
948 break;
|
|
949 }
|
|
950
|
|
951 case Blss:
|
|
952 {
|
|
953 Lisp_Object arg = POP;
|
|
954 TOP = bytecode_arithcompare (TOP, arg) < 0 ? Qt : Qnil;
|
|
955 break;
|
|
956 }
|
|
957
|
|
958 case Bleq:
|
|
959 {
|
|
960 Lisp_Object arg = POP;
|
|
961 TOP = bytecode_arithcompare (TOP, arg) <= 0 ? Qt : Qnil;
|
|
962 break;
|
|
963 }
|
|
964
|
|
965 case Bgeq:
|
|
966 {
|
|
967 Lisp_Object arg = POP;
|
|
968 TOP = bytecode_arithcompare (TOP, arg) >= 0 ? Qt : Qnil;
|
|
969 break;
|
|
970 }
|
|
971
|
|
972
|
|
973 case Bnegate:
|
|
974 TOP = bytecode_negate (TOP);
|
|
975 break;
|
|
976
|
|
977 case Bnconc:
|
|
978 DISCARD (1);
|
|
979 TOP = bytecode_nconc2 (&TOP);
|
|
980 break;
|
|
981
|
|
982 case Bplus:
|
|
983 {
|
|
984 Lisp_Object arg2 = POP;
|
|
985 Lisp_Object arg1 = TOP;
|
|
986 TOP = INTP (arg1) && INTP (arg2) ?
|
|
987 INT_PLUS (arg1, arg2) :
|
|
988 bytecode_arithop (arg1, arg2, opcode);
|
|
989 break;
|
|
990 }
|
|
991
|
|
992 case Bdiff:
|
|
993 {
|
|
994 Lisp_Object arg2 = POP;
|
|
995 Lisp_Object arg1 = TOP;
|
|
996 TOP = INTP (arg1) && INTP (arg2) ?
|
|
997 INT_MINUS (arg1, arg2) :
|
|
998 bytecode_arithop (arg1, arg2, opcode);
|
|
999 break;
|
|
1000 }
|
|
1001
|
|
1002 case Bmult:
|
|
1003 case Bquo:
|
|
1004 case Bmax:
|
|
1005 case Bmin:
|
|
1006 {
|
|
1007 Lisp_Object arg = POP;
|
|
1008 TOP = bytecode_arithop (TOP, arg, opcode);
|
|
1009 break;
|
|
1010 }
|
|
1011
|
|
1012 case Bpoint:
|
|
1013 PUSH (make_int (BUF_PT (current_buffer)));
|
|
1014 break;
|
|
1015
|
|
1016 case Binsert:
|
|
1017 TOP = Finsert (1, &TOP);
|
|
1018 break;
|
|
1019
|
|
1020 case BinsertN:
|
|
1021 n = READ_UINT_1;
|
|
1022 DISCARD (n - 1);
|
|
1023 TOP = Finsert (n, &TOP);
|
|
1024 break;
|
|
1025
|
|
1026 case Baref:
|
|
1027 {
|
|
1028 Lisp_Object arg = POP;
|
|
1029 TOP = Faref (TOP, arg);
|
|
1030 break;
|
|
1031 }
|
|
1032
|
|
1033 case Bmemq:
|
|
1034 {
|
|
1035 Lisp_Object arg = POP;
|
|
1036 TOP = Fmemq (TOP, arg);
|
|
1037 break;
|
|
1038 }
|
|
1039
|
|
1040 case Bset:
|
|
1041 {
|
|
1042 Lisp_Object arg = POP;
|
|
1043 TOP = Fset (TOP, arg);
|
|
1044 break;
|
|
1045 }
|
|
1046
|
|
1047 case Bequal:
|
|
1048 {
|
|
1049 Lisp_Object arg = POP;
|
|
1050 TOP = Fequal (TOP, arg);
|
|
1051 break;
|
|
1052 }
|
|
1053
|
|
1054 case Bnthcdr:
|
|
1055 {
|
|
1056 Lisp_Object arg = POP;
|
|
1057 TOP = Fnthcdr (TOP, arg);
|
|
1058 break;
|
|
1059 }
|
|
1060
|
|
1061 case Belt:
|
|
1062 {
|
|
1063 Lisp_Object arg = POP;
|
|
1064 TOP = Felt (TOP, arg);
|
|
1065 break;
|
|
1066 }
|
|
1067
|
|
1068 case Bmember:
|
|
1069 {
|
|
1070 Lisp_Object arg = POP;
|
|
1071 TOP = Fmember (TOP, arg);
|
|
1072 break;
|
|
1073 }
|
|
1074
|
|
1075 case Bgoto_char:
|
|
1076 TOP = Fgoto_char (TOP, Qnil);
|
|
1077 break;
|
|
1078
|
|
1079 case Bcurrent_buffer:
|
|
1080 {
|
793
|
1081 Lisp_Object buffer = wrap_buffer (current_buffer);
|
|
1082
|
428
|
1083 PUSH (buffer);
|
|
1084 break;
|
|
1085 }
|
|
1086
|
|
1087 case Bset_buffer:
|
|
1088 TOP = Fset_buffer (TOP);
|
|
1089 break;
|
|
1090
|
|
1091 case Bpoint_max:
|
|
1092 PUSH (make_int (BUF_ZV (current_buffer)));
|
|
1093 break;
|
|
1094
|
|
1095 case Bpoint_min:
|
|
1096 PUSH (make_int (BUF_BEGV (current_buffer)));
|
|
1097 break;
|
|
1098
|
|
1099 case Bskip_chars_forward:
|
|
1100 {
|
|
1101 Lisp_Object arg = POP;
|
|
1102 TOP = Fskip_chars_forward (TOP, arg, Qnil);
|
|
1103 break;
|
|
1104 }
|
|
1105
|
|
1106 case Bassq:
|
|
1107 {
|
|
1108 Lisp_Object arg = POP;
|
|
1109 TOP = Fassq (TOP, arg);
|
|
1110 break;
|
|
1111 }
|
|
1112
|
|
1113 case Bsetcar:
|
|
1114 {
|
|
1115 Lisp_Object arg = POP;
|
|
1116 TOP = Fsetcar (TOP, arg);
|
|
1117 break;
|
|
1118 }
|
|
1119
|
|
1120 case Bsetcdr:
|
|
1121 {
|
|
1122 Lisp_Object arg = POP;
|
|
1123 TOP = Fsetcdr (TOP, arg);
|
|
1124 break;
|
|
1125 }
|
|
1126
|
|
1127 case Bnreverse:
|
|
1128 TOP = bytecode_nreverse (TOP);
|
|
1129 break;
|
|
1130
|
|
1131 case Bcar_safe:
|
|
1132 TOP = CONSP (TOP) ? XCAR (TOP) : Qnil;
|
|
1133 break;
|
|
1134
|
|
1135 case Bcdr_safe:
|
|
1136 TOP = CONSP (TOP) ? XCDR (TOP) : Qnil;
|
|
1137 break;
|
|
1138
|
|
1139 }
|
|
1140 }
|
|
1141 }
|
|
1142
|
|
1143 /* It makes a worthwhile performance difference (5%) to shunt
|
|
1144 lesser-used opcodes off to a subroutine, to keep the switch in
|
|
1145 execute_optimized_program small. If you REALLY care about
|
|
1146 performance, you want to keep your heavily executed code away from
|
|
1147 rarely executed code, to minimize cache misses.
|
|
1148
|
|
1149 Don't make this function static, since then the compiler might inline it. */
|
|
1150 Lisp_Object *
|
|
1151 execute_rare_opcode (Lisp_Object *stack_ptr,
|
442
|
1152 const Opbyte *program_ptr,
|
428
|
1153 Opcode opcode)
|
|
1154 {
|
|
1155 switch (opcode)
|
|
1156 {
|
|
1157
|
|
1158 case Bsave_excursion:
|
|
1159 record_unwind_protect (save_excursion_restore,
|
|
1160 save_excursion_save ());
|
|
1161 break;
|
|
1162
|
|
1163 case Bsave_window_excursion:
|
|
1164 {
|
|
1165 int count = specpdl_depth ();
|
|
1166 record_unwind_protect (save_window_excursion_unwind,
|
|
1167 Fcurrent_window_configuration (Qnil));
|
|
1168 TOP = Fprogn (TOP);
|
771
|
1169 unbind_to (count);
|
428
|
1170 break;
|
|
1171 }
|
|
1172
|
|
1173 case Bsave_restriction:
|
|
1174 record_unwind_protect (save_restriction_restore,
|
844
|
1175 save_restriction_save (current_buffer));
|
428
|
1176 break;
|
|
1177
|
|
1178 case Bcatch:
|
|
1179 {
|
|
1180 Lisp_Object arg = POP;
|
853
|
1181 TOP = internal_catch (TOP, Feval, arg, 0, 0);
|
428
|
1182 break;
|
|
1183 }
|
|
1184
|
|
1185 case Bskip_chars_backward:
|
|
1186 {
|
|
1187 Lisp_Object arg = POP;
|
|
1188 TOP = Fskip_chars_backward (TOP, arg, Qnil);
|
|
1189 break;
|
|
1190 }
|
|
1191
|
|
1192 case Bunwind_protect:
|
|
1193 record_unwind_protect (Fprogn, POP);
|
|
1194 break;
|
|
1195
|
|
1196 case Bcondition_case:
|
|
1197 {
|
|
1198 Lisp_Object arg2 = POP; /* handlers */
|
|
1199 Lisp_Object arg1 = POP; /* bodyform */
|
|
1200 TOP = condition_case_3 (arg1, TOP, arg2);
|
|
1201 break;
|
|
1202 }
|
|
1203
|
|
1204 case Bset_marker:
|
|
1205 {
|
|
1206 Lisp_Object arg2 = POP;
|
|
1207 Lisp_Object arg1 = POP;
|
|
1208 TOP = Fset_marker (TOP, arg1, arg2);
|
|
1209 break;
|
|
1210 }
|
|
1211
|
|
1212 case Brem:
|
|
1213 {
|
|
1214 Lisp_Object arg = POP;
|
|
1215 TOP = Frem (TOP, arg);
|
|
1216 break;
|
|
1217 }
|
|
1218
|
|
1219 case Bmatch_beginning:
|
|
1220 TOP = Fmatch_beginning (TOP);
|
|
1221 break;
|
|
1222
|
|
1223 case Bmatch_end:
|
|
1224 TOP = Fmatch_end (TOP);
|
|
1225 break;
|
|
1226
|
|
1227 case Bupcase:
|
|
1228 TOP = Fupcase (TOP, Qnil);
|
|
1229 break;
|
|
1230
|
|
1231 case Bdowncase:
|
|
1232 TOP = Fdowncase (TOP, Qnil);
|
|
1233 break;
|
|
1234
|
|
1235 case Bfset:
|
|
1236 {
|
|
1237 Lisp_Object arg = POP;
|
|
1238 TOP = Ffset (TOP, arg);
|
|
1239 break;
|
|
1240 }
|
|
1241
|
|
1242 case Bstring_equal:
|
|
1243 {
|
|
1244 Lisp_Object arg = POP;
|
|
1245 TOP = Fstring_equal (TOP, arg);
|
|
1246 break;
|
|
1247 }
|
|
1248
|
|
1249 case Bstring_lessp:
|
|
1250 {
|
|
1251 Lisp_Object arg = POP;
|
|
1252 TOP = Fstring_lessp (TOP, arg);
|
|
1253 break;
|
|
1254 }
|
|
1255
|
|
1256 case Bsubstring:
|
|
1257 {
|
|
1258 Lisp_Object arg2 = POP;
|
|
1259 Lisp_Object arg1 = POP;
|
|
1260 TOP = Fsubstring (TOP, arg1, arg2);
|
|
1261 break;
|
|
1262 }
|
|
1263
|
|
1264 case Bcurrent_column:
|
|
1265 PUSH (make_int (current_column (current_buffer)));
|
|
1266 break;
|
|
1267
|
|
1268 case Bchar_after:
|
|
1269 TOP = Fchar_after (TOP, Qnil);
|
|
1270 break;
|
|
1271
|
|
1272 case Bindent_to:
|
|
1273 TOP = Findent_to (TOP, Qnil, Qnil);
|
|
1274 break;
|
|
1275
|
|
1276 case Bwiden:
|
|
1277 PUSH (Fwiden (Qnil));
|
|
1278 break;
|
|
1279
|
|
1280 case Bfollowing_char:
|
|
1281 PUSH (Ffollowing_char (Qnil));
|
|
1282 break;
|
|
1283
|
|
1284 case Bpreceding_char:
|
|
1285 PUSH (Fpreceding_char (Qnil));
|
|
1286 break;
|
|
1287
|
|
1288 case Beolp:
|
|
1289 PUSH (Feolp (Qnil));
|
|
1290 break;
|
|
1291
|
|
1292 case Beobp:
|
|
1293 PUSH (Feobp (Qnil));
|
|
1294 break;
|
|
1295
|
|
1296 case Bbolp:
|
|
1297 PUSH (Fbolp (Qnil));
|
|
1298 break;
|
|
1299
|
|
1300 case Bbobp:
|
|
1301 PUSH (Fbobp (Qnil));
|
|
1302 break;
|
|
1303
|
|
1304 case Bsave_current_buffer:
|
|
1305 record_unwind_protect (save_current_buffer_restore,
|
|
1306 Fcurrent_buffer ());
|
|
1307 break;
|
|
1308
|
|
1309 case Binteractive_p:
|
|
1310 PUSH (Finteractive_p ());
|
|
1311 break;
|
|
1312
|
|
1313 case Bforward_char:
|
|
1314 TOP = Fforward_char (TOP, Qnil);
|
|
1315 break;
|
|
1316
|
|
1317 case Bforward_word:
|
|
1318 TOP = Fforward_word (TOP, Qnil);
|
|
1319 break;
|
|
1320
|
|
1321 case Bforward_line:
|
|
1322 TOP = Fforward_line (TOP, Qnil);
|
|
1323 break;
|
|
1324
|
|
1325 case Bchar_syntax:
|
|
1326 TOP = Fchar_syntax (TOP, Qnil);
|
|
1327 break;
|
|
1328
|
|
1329 case Bbuffer_substring:
|
|
1330 {
|
|
1331 Lisp_Object arg = POP;
|
|
1332 TOP = Fbuffer_substring (TOP, arg, Qnil);
|
|
1333 break;
|
|
1334 }
|
|
1335
|
|
1336 case Bdelete_region:
|
|
1337 {
|
|
1338 Lisp_Object arg = POP;
|
|
1339 TOP = Fdelete_region (TOP, arg, Qnil);
|
|
1340 break;
|
|
1341 }
|
|
1342
|
|
1343 case Bnarrow_to_region:
|
|
1344 {
|
|
1345 Lisp_Object arg = POP;
|
|
1346 TOP = Fnarrow_to_region (TOP, arg, Qnil);
|
|
1347 break;
|
|
1348 }
|
|
1349
|
|
1350 case Bend_of_line:
|
|
1351 TOP = Fend_of_line (TOP, Qnil);
|
|
1352 break;
|
|
1353
|
|
1354 case Btemp_output_buffer_setup:
|
|
1355 temp_output_buffer_setup (TOP);
|
|
1356 TOP = Vstandard_output;
|
|
1357 break;
|
|
1358
|
|
1359 case Btemp_output_buffer_show:
|
|
1360 {
|
|
1361 Lisp_Object arg = POP;
|
|
1362 temp_output_buffer_show (TOP, Qnil);
|
|
1363 TOP = arg;
|
|
1364 /* GAG ME!! */
|
|
1365 /* pop binding of standard-output */
|
771
|
1366 unbind_to (specpdl_depth() - 1);
|
428
|
1367 break;
|
|
1368 }
|
|
1369
|
|
1370 case Bold_eq:
|
|
1371 {
|
|
1372 Lisp_Object arg = POP;
|
|
1373 TOP = HACKEQ_UNSAFE (TOP, arg) ? Qt : Qnil;
|
|
1374 break;
|
|
1375 }
|
|
1376
|
|
1377 case Bold_memq:
|
|
1378 {
|
|
1379 Lisp_Object arg = POP;
|
|
1380 TOP = Fold_memq (TOP, arg);
|
|
1381 break;
|
|
1382 }
|
|
1383
|
|
1384 case Bold_equal:
|
|
1385 {
|
|
1386 Lisp_Object arg = POP;
|
|
1387 TOP = Fold_equal (TOP, arg);
|
|
1388 break;
|
|
1389 }
|
|
1390
|
|
1391 case Bold_member:
|
|
1392 {
|
|
1393 Lisp_Object arg = POP;
|
|
1394 TOP = Fold_member (TOP, arg);
|
|
1395 break;
|
|
1396 }
|
|
1397
|
|
1398 case Bold_assq:
|
|
1399 {
|
|
1400 Lisp_Object arg = POP;
|
|
1401 TOP = Fold_assq (TOP, arg);
|
|
1402 break;
|
|
1403 }
|
|
1404
|
|
1405 default:
|
|
1406 abort();
|
|
1407 break;
|
|
1408 }
|
|
1409 return stack_ptr;
|
|
1410 }
|
|
1411
|
|
1412
|
563
|
1413 DOESNT_RETURN
|
867
|
1414 invalid_byte_code (const CIbyte *reason, Lisp_Object frob)
|
428
|
1415 {
|
563
|
1416 signal_error (Qinvalid_byte_code, reason, frob);
|
428
|
1417 }
|
|
1418
|
|
1419 /* Check for valid opcodes. Change this when adding new opcodes. */
|
|
1420 static void
|
|
1421 check_opcode (Opcode opcode)
|
|
1422 {
|
|
1423 if ((opcode < Bvarref) ||
|
|
1424 (opcode == 0251) ||
|
|
1425 (opcode > Bassq && opcode < Bconstant))
|
563
|
1426 invalid_byte_code ("invalid opcode in instruction stream",
|
|
1427 make_int (opcode));
|
428
|
1428 }
|
|
1429
|
|
1430 /* Check that IDX is a valid offset into the `constants' vector */
|
|
1431 static void
|
|
1432 check_constants_index (int idx, Lisp_Object constants)
|
|
1433 {
|
|
1434 if (idx < 0 || idx >= XVECTOR_LENGTH (constants))
|
563
|
1435 signal_ferror
|
|
1436 (Qinvalid_byte_code,
|
|
1437 "reference %d to constants array out of range 0, %ld",
|
428
|
1438 idx, XVECTOR_LENGTH (constants) - 1);
|
|
1439 }
|
|
1440
|
|
1441 /* Get next character from Lisp instructions string. */
|
563
|
1442 #define READ_INSTRUCTION_CHAR(lvalue) do { \
|
867
|
1443 (lvalue) = itext_ichar (ptr); \
|
|
1444 INC_IBYTEPTR (ptr); \
|
563
|
1445 *icounts_ptr++ = program_ptr - program; \
|
|
1446 if (lvalue > UCHAR_MAX) \
|
|
1447 invalid_byte_code \
|
|
1448 ("Invalid character in byte code string", make_char (lvalue)); \
|
428
|
1449 } while (0)
|
|
1450
|
|
1451 /* Get opcode from Lisp instructions string. */
|
|
1452 #define READ_OPCODE do { \
|
|
1453 unsigned int c; \
|
|
1454 READ_INSTRUCTION_CHAR (c); \
|
|
1455 opcode = (Opcode) c; \
|
|
1456 } while (0)
|
|
1457
|
|
1458 /* Get next operand, a uint8, from Lisp instructions string. */
|
|
1459 #define READ_OPERAND_1 do { \
|
|
1460 READ_INSTRUCTION_CHAR (arg); \
|
|
1461 argsize = 1; \
|
|
1462 } while (0)
|
|
1463
|
|
1464 /* Get next operand, a uint16, from Lisp instructions string. */
|
|
1465 #define READ_OPERAND_2 do { \
|
|
1466 unsigned int arg1, arg2; \
|
|
1467 READ_INSTRUCTION_CHAR (arg1); \
|
|
1468 READ_INSTRUCTION_CHAR (arg2); \
|
|
1469 arg = arg1 + (arg2 << 8); \
|
|
1470 argsize = 2; \
|
|
1471 } while (0)
|
|
1472
|
|
1473 /* Write 1 byte to PTR, incrementing PTR */
|
|
1474 #define WRITE_INT8(value, ptr) do { \
|
|
1475 *((ptr)++) = (value); \
|
|
1476 } while (0)
|
|
1477
|
|
1478 /* Write 2 bytes to PTR, incrementing PTR */
|
|
1479 #define WRITE_INT16(value, ptr) do { \
|
|
1480 WRITE_INT8 (((unsigned) (value)) & 0x00ff, (ptr)); \
|
|
1481 WRITE_INT8 (((unsigned) (value)) >> 8 , (ptr)); \
|
|
1482 } while (0)
|
|
1483
|
|
1484 /* We've changed our minds about the opcode we've already written. */
|
|
1485 #define REWRITE_OPCODE(new_opcode) ((void) (program_ptr[-1] = new_opcode))
|
|
1486
|
|
1487 /* Encode an op arg within the opcode, or as a 1 or 2-byte operand. */
|
|
1488 #define WRITE_NARGS(base_opcode) do { \
|
|
1489 if (arg <= 5) \
|
|
1490 { \
|
|
1491 REWRITE_OPCODE (base_opcode + arg); \
|
|
1492 } \
|
|
1493 else if (arg <= UCHAR_MAX) \
|
|
1494 { \
|
|
1495 REWRITE_OPCODE (base_opcode + 6); \
|
|
1496 WRITE_INT8 (arg, program_ptr); \
|
|
1497 } \
|
|
1498 else \
|
|
1499 { \
|
|
1500 REWRITE_OPCODE (base_opcode + 7); \
|
|
1501 WRITE_INT16 (arg, program_ptr); \
|
|
1502 } \
|
|
1503 } while (0)
|
|
1504
|
|
1505 /* Encode a constants reference within the opcode, or as a 2-byte operand. */
|
|
1506 #define WRITE_CONSTANT do { \
|
|
1507 check_constants_index(arg, constants); \
|
|
1508 if (arg <= UCHAR_MAX - Bconstant) \
|
|
1509 { \
|
|
1510 REWRITE_OPCODE (Bconstant + arg); \
|
|
1511 } \
|
|
1512 else \
|
|
1513 { \
|
|
1514 REWRITE_OPCODE (Bconstant2); \
|
|
1515 WRITE_INT16 (arg, program_ptr); \
|
|
1516 } \
|
|
1517 } while (0)
|
|
1518
|
|
1519 #define WRITE_OPCODE WRITE_INT8 (opcode, program_ptr)
|
|
1520
|
|
1521 /* Compile byte code instructions into free space provided by caller, with
|
|
1522 size >= (2 * string_char_length (instructions) + 1) * sizeof (Opbyte).
|
|
1523 Returns length of compiled code. */
|
|
1524 static void
|
|
1525 optimize_byte_code (/* in */
|
|
1526 Lisp_Object instructions,
|
|
1527 Lisp_Object constants,
|
|
1528 /* out */
|
442
|
1529 Opbyte * const program,
|
|
1530 int * const program_length,
|
|
1531 int * const varbind_count)
|
428
|
1532 {
|
647
|
1533 Bytecount instructions_length = XSTRING_LENGTH (instructions);
|
665
|
1534 Elemcount comfy_size = (Elemcount) (2 * instructions_length);
|
428
|
1535
|
442
|
1536 int * const icounts = alloca_array (int, comfy_size);
|
428
|
1537 int * icounts_ptr = icounts;
|
|
1538
|
|
1539 /* We maintain a table of jumps in the source code. */
|
|
1540 struct jump
|
|
1541 {
|
|
1542 int from;
|
|
1543 int to;
|
|
1544 };
|
442
|
1545 struct jump * const jumps = alloca_array (struct jump, comfy_size);
|
428
|
1546 struct jump *jumps_ptr = jumps;
|
|
1547
|
|
1548 Opbyte *program_ptr = program;
|
|
1549
|
867
|
1550 const Ibyte *ptr = XSTRING_DATA (instructions);
|
|
1551 const Ibyte * const end = ptr + instructions_length;
|
428
|
1552
|
|
1553 *varbind_count = 0;
|
|
1554
|
|
1555 while (ptr < end)
|
|
1556 {
|
|
1557 Opcode opcode;
|
|
1558 int arg;
|
|
1559 int argsize = 0;
|
|
1560 READ_OPCODE;
|
|
1561 WRITE_OPCODE;
|
|
1562
|
|
1563 switch (opcode)
|
|
1564 {
|
|
1565 Lisp_Object val;
|
|
1566
|
|
1567 case Bvarref+7: READ_OPERAND_2; goto do_varref;
|
|
1568 case Bvarref+6: READ_OPERAND_1; goto do_varref;
|
|
1569 case Bvarref: case Bvarref+1: case Bvarref+2:
|
|
1570 case Bvarref+3: case Bvarref+4: case Bvarref+5:
|
|
1571 arg = opcode - Bvarref;
|
|
1572 do_varref:
|
|
1573 check_constants_index (arg, constants);
|
|
1574 val = XVECTOR_DATA (constants) [arg];
|
|
1575 if (!SYMBOLP (val))
|
563
|
1576 invalid_byte_code ("variable reference to non-symbol", val);
|
428
|
1577 if (EQ (val, Qnil) || EQ (val, Qt) || (SYMBOL_IS_KEYWORD (val)))
|
563
|
1578 invalid_byte_code ("variable reference to constant symbol", val);
|
428
|
1579 WRITE_NARGS (Bvarref);
|
|
1580 break;
|
|
1581
|
|
1582 case Bvarset+7: READ_OPERAND_2; goto do_varset;
|
|
1583 case Bvarset+6: READ_OPERAND_1; goto do_varset;
|
|
1584 case Bvarset: case Bvarset+1: case Bvarset+2:
|
|
1585 case Bvarset+3: case Bvarset+4: case Bvarset+5:
|
|
1586 arg = opcode - Bvarset;
|
|
1587 do_varset:
|
|
1588 check_constants_index (arg, constants);
|
|
1589 val = XVECTOR_DATA (constants) [arg];
|
|
1590 if (!SYMBOLP (val))
|
563
|
1591 wtaerror ("attempt to set non-symbol", val);
|
428
|
1592 if (EQ (val, Qnil) || EQ (val, Qt))
|
563
|
1593 signal_error (Qsetting_constant, 0, val);
|
428
|
1594 /* Ignore assignments to keywords by converting to Bdiscard.
|
|
1595 For backward compatibility only - we'd like to make this an error. */
|
|
1596 if (SYMBOL_IS_KEYWORD (val))
|
|
1597 REWRITE_OPCODE (Bdiscard);
|
|
1598 else
|
|
1599 WRITE_NARGS (Bvarset);
|
|
1600 break;
|
|
1601
|
|
1602 case Bvarbind+7: READ_OPERAND_2; goto do_varbind;
|
|
1603 case Bvarbind+6: READ_OPERAND_1; goto do_varbind;
|
|
1604 case Bvarbind: case Bvarbind+1: case Bvarbind+2:
|
|
1605 case Bvarbind+3: case Bvarbind+4: case Bvarbind+5:
|
|
1606 arg = opcode - Bvarbind;
|
|
1607 do_varbind:
|
|
1608 (*varbind_count)++;
|
|
1609 check_constants_index (arg, constants);
|
|
1610 val = XVECTOR_DATA (constants) [arg];
|
|
1611 if (!SYMBOLP (val))
|
563
|
1612 wtaerror ("attempt to let-bind non-symbol", val);
|
428
|
1613 if (EQ (val, Qnil) || EQ (val, Qt) || (SYMBOL_IS_KEYWORD (val)))
|
563
|
1614 signal_error (Qsetting_constant,
|
|
1615 "attempt to let-bind constant symbol", val);
|
428
|
1616 WRITE_NARGS (Bvarbind);
|
|
1617 break;
|
|
1618
|
|
1619 case Bcall+7: READ_OPERAND_2; goto do_call;
|
|
1620 case Bcall+6: READ_OPERAND_1; goto do_call;
|
|
1621 case Bcall: case Bcall+1: case Bcall+2:
|
|
1622 case Bcall+3: case Bcall+4: case Bcall+5:
|
|
1623 arg = opcode - Bcall;
|
|
1624 do_call:
|
|
1625 WRITE_NARGS (Bcall);
|
|
1626 break;
|
|
1627
|
|
1628 case Bunbind+7: READ_OPERAND_2; goto do_unbind;
|
|
1629 case Bunbind+6: READ_OPERAND_1; goto do_unbind;
|
|
1630 case Bunbind: case Bunbind+1: case Bunbind+2:
|
|
1631 case Bunbind+3: case Bunbind+4: case Bunbind+5:
|
|
1632 arg = opcode - Bunbind;
|
|
1633 do_unbind:
|
|
1634 WRITE_NARGS (Bunbind);
|
|
1635 break;
|
|
1636
|
|
1637 case Bgoto:
|
|
1638 case Bgotoifnil:
|
|
1639 case Bgotoifnonnil:
|
|
1640 case Bgotoifnilelsepop:
|
|
1641 case Bgotoifnonnilelsepop:
|
|
1642 READ_OPERAND_2;
|
|
1643 /* Make program_ptr-relative */
|
|
1644 arg += icounts - (icounts_ptr - argsize);
|
|
1645 goto do_jump;
|
|
1646
|
|
1647 case BRgoto:
|
|
1648 case BRgotoifnil:
|
|
1649 case BRgotoifnonnil:
|
|
1650 case BRgotoifnilelsepop:
|
|
1651 case BRgotoifnonnilelsepop:
|
|
1652 READ_OPERAND_1;
|
|
1653 /* Make program_ptr-relative */
|
|
1654 arg -= 127;
|
|
1655 do_jump:
|
|
1656 /* Record program-relative goto addresses in `jumps' table */
|
|
1657 jumps_ptr->from = icounts_ptr - icounts - argsize;
|
|
1658 jumps_ptr->to = jumps_ptr->from + arg;
|
|
1659 jumps_ptr++;
|
|
1660 if (arg >= -1 && arg <= argsize)
|
563
|
1661 invalid_byte_code ("goto instruction is its own target", Qunbound);
|
428
|
1662 if (arg <= SCHAR_MIN ||
|
|
1663 arg > SCHAR_MAX)
|
|
1664 {
|
|
1665 if (argsize == 1)
|
|
1666 REWRITE_OPCODE (opcode + Bgoto - BRgoto);
|
|
1667 WRITE_INT16 (arg, program_ptr);
|
|
1668 }
|
|
1669 else
|
|
1670 {
|
|
1671 if (argsize == 2)
|
|
1672 REWRITE_OPCODE (opcode + BRgoto - Bgoto);
|
|
1673 WRITE_INT8 (arg, program_ptr);
|
|
1674 }
|
|
1675 break;
|
|
1676
|
|
1677 case Bconstant2:
|
|
1678 READ_OPERAND_2;
|
|
1679 WRITE_CONSTANT;
|
|
1680 break;
|
|
1681
|
|
1682 case BlistN:
|
|
1683 case BconcatN:
|
|
1684 case BinsertN:
|
|
1685 READ_OPERAND_1;
|
|
1686 WRITE_INT8 (arg, program_ptr);
|
|
1687 break;
|
|
1688
|
|
1689 default:
|
|
1690 if (opcode < Bconstant)
|
|
1691 check_opcode (opcode);
|
|
1692 else
|
|
1693 {
|
|
1694 arg = opcode - Bconstant;
|
|
1695 WRITE_CONSTANT;
|
|
1696 }
|
|
1697 break;
|
|
1698 }
|
|
1699 }
|
|
1700
|
|
1701 /* Fix up jumps table to refer to NEW offsets. */
|
|
1702 {
|
|
1703 struct jump *j;
|
|
1704 for (j = jumps; j < jumps_ptr; j++)
|
|
1705 {
|
|
1706 #ifdef ERROR_CHECK_BYTE_CODE
|
|
1707 assert (j->from < icounts_ptr - icounts);
|
|
1708 assert (j->to < icounts_ptr - icounts);
|
|
1709 #endif
|
|
1710 j->from = icounts[j->from];
|
|
1711 j->to = icounts[j->to];
|
|
1712 #ifdef ERROR_CHECK_BYTE_CODE
|
|
1713 assert (j->from < program_ptr - program);
|
|
1714 assert (j->to < program_ptr - program);
|
|
1715 check_opcode ((Opcode) (program[j->from-1]));
|
|
1716 #endif
|
|
1717 check_opcode ((Opcode) (program[j->to]));
|
|
1718 }
|
|
1719 }
|
|
1720
|
|
1721 /* Fixup jumps in byte-code until no more fixups needed */
|
|
1722 {
|
|
1723 int more_fixups_needed = 1;
|
|
1724
|
|
1725 while (more_fixups_needed)
|
|
1726 {
|
|
1727 struct jump *j;
|
|
1728 more_fixups_needed = 0;
|
|
1729 for (j = jumps; j < jumps_ptr; j++)
|
|
1730 {
|
|
1731 int from = j->from;
|
|
1732 int to = j->to;
|
|
1733 int jump = to - from;
|
|
1734 Opbyte *p = program + from;
|
|
1735 Opcode opcode = (Opcode) p[-1];
|
|
1736 if (!more_fixups_needed)
|
|
1737 check_opcode ((Opcode) p[jump]);
|
|
1738 assert (to >= 0 && program + to < program_ptr);
|
|
1739 switch (opcode)
|
|
1740 {
|
|
1741 case Bgoto:
|
|
1742 case Bgotoifnil:
|
|
1743 case Bgotoifnonnil:
|
|
1744 case Bgotoifnilelsepop:
|
|
1745 case Bgotoifnonnilelsepop:
|
|
1746 WRITE_INT16 (jump, p);
|
|
1747 break;
|
|
1748
|
|
1749 case BRgoto:
|
|
1750 case BRgotoifnil:
|
|
1751 case BRgotoifnonnil:
|
|
1752 case BRgotoifnilelsepop:
|
|
1753 case BRgotoifnonnilelsepop:
|
|
1754 if (jump > SCHAR_MIN &&
|
|
1755 jump <= SCHAR_MAX)
|
|
1756 {
|
|
1757 WRITE_INT8 (jump, p);
|
|
1758 }
|
|
1759 else /* barf */
|
|
1760 {
|
|
1761 struct jump *jj;
|
|
1762 for (jj = jumps; jj < jumps_ptr; jj++)
|
|
1763 {
|
|
1764 assert (jj->from < program_ptr - program);
|
|
1765 assert (jj->to < program_ptr - program);
|
|
1766 if (jj->from > from) jj->from++;
|
|
1767 if (jj->to > from) jj->to++;
|
|
1768 }
|
|
1769 p[-1] += Bgoto - BRgoto;
|
|
1770 more_fixups_needed = 1;
|
|
1771 memmove (p+1, p, program_ptr++ - p);
|
|
1772 WRITE_INT16 (jump, p);
|
|
1773 }
|
|
1774 break;
|
|
1775
|
|
1776 default:
|
|
1777 abort();
|
|
1778 break;
|
|
1779 }
|
|
1780 }
|
|
1781 }
|
|
1782 }
|
|
1783
|
|
1784 /* *program_ptr++ = 0; */
|
|
1785 *program_length = program_ptr - program;
|
|
1786 }
|
|
1787
|
|
1788 /* Optimize the byte code and store the optimized program, only
|
|
1789 understood by bytecode.c, in an opaque object in the
|
|
1790 instructions slot of the Compiled_Function object. */
|
|
1791 void
|
|
1792 optimize_compiled_function (Lisp_Object compiled_function)
|
|
1793 {
|
|
1794 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (compiled_function);
|
|
1795 int program_length;
|
|
1796 int varbind_count;
|
|
1797 Opbyte *program;
|
|
1798
|
|
1799 /* If we have not actually read the bytecode string
|
|
1800 and constants vector yet, fetch them from the file. */
|
|
1801 if (CONSP (f->instructions))
|
|
1802 Ffetch_bytecode (compiled_function);
|
|
1803
|
|
1804 if (STRINGP (f->instructions))
|
|
1805 {
|
826
|
1806 /* XSTRING_LENGTH() is more efficient than string_char_length(),
|
428
|
1807 which would be slightly more `proper' */
|
|
1808 program = alloca_array (Opbyte, 1 + 2 * XSTRING_LENGTH (f->instructions));
|
|
1809 optimize_byte_code (f->instructions, f->constants,
|
|
1810 program, &program_length, &varbind_count);
|
|
1811 f->specpdl_depth = XINT (Flength (f->arglist)) + varbind_count;
|
|
1812 f->instructions =
|
440
|
1813 make_opaque (program, program_length * sizeof (Opbyte));
|
428
|
1814 }
|
|
1815
|
|
1816 assert (OPAQUEP (f->instructions));
|
|
1817 }
|
|
1818
|
|
1819 /************************************************************************/
|
|
1820 /* The compiled-function object type */
|
|
1821 /************************************************************************/
|
|
1822 static void
|
|
1823 print_compiled_function (Lisp_Object obj, Lisp_Object printcharfun,
|
|
1824 int escapeflag)
|
|
1825 {
|
|
1826 /* This function can GC */
|
|
1827 Lisp_Compiled_Function *f =
|
|
1828 XCOMPILED_FUNCTION (obj); /* GC doesn't relocate */
|
|
1829 int docp = f->flags.documentationp;
|
|
1830 int intp = f->flags.interactivep;
|
|
1831 struct gcpro gcpro1, gcpro2;
|
|
1832 GCPRO2 (obj, printcharfun);
|
|
1833
|
826
|
1834 write_c_string (printcharfun, print_readably ? "#[" : "#<compiled-function ");
|
428
|
1835 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1836 if (!print_readably)
|
|
1837 {
|
|
1838 Lisp_Object ann = compiled_function_annotation (f);
|
|
1839 if (!NILP (ann))
|
800
|
1840 write_fmt_string_lisp (printcharfun, "(from %S) ", 1, ann);
|
428
|
1841 }
|
|
1842 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */
|
|
1843 /* COMPILED_ARGLIST = 0 */
|
|
1844 print_internal (compiled_function_arglist (f), printcharfun, escapeflag);
|
|
1845
|
|
1846 /* COMPILED_INSTRUCTIONS = 1 */
|
826
|
1847 write_c_string (printcharfun, " ");
|
428
|
1848 {
|
|
1849 struct gcpro ngcpro1;
|
|
1850 Lisp_Object instructions = compiled_function_instructions (f);
|
|
1851 NGCPRO1 (instructions);
|
|
1852 if (STRINGP (instructions) && !print_readably)
|
|
1853 {
|
|
1854 /* We don't usually want to see that junk in the bytecode. */
|
800
|
1855 write_fmt_string (printcharfun, "\"...(%ld)\"",
|
826
|
1856 (long) string_char_length (instructions));
|
428
|
1857 }
|
|
1858 else
|
|
1859 print_internal (instructions, printcharfun, escapeflag);
|
|
1860 NUNGCPRO;
|
|
1861 }
|
|
1862
|
|
1863 /* COMPILED_CONSTANTS = 2 */
|
826
|
1864 write_c_string (printcharfun, " ");
|
428
|
1865 print_internal (compiled_function_constants (f), printcharfun, escapeflag);
|
|
1866
|
|
1867 /* COMPILED_STACK_DEPTH = 3 */
|
800
|
1868 write_fmt_string (printcharfun, " %d", compiled_function_stack_depth (f));
|
428
|
1869
|
|
1870 /* COMPILED_DOC_STRING = 4 */
|
|
1871 if (docp || intp)
|
|
1872 {
|
826
|
1873 write_c_string (printcharfun, " ");
|
428
|
1874 print_internal (compiled_function_documentation (f), printcharfun,
|
|
1875 escapeflag);
|
|
1876 }
|
|
1877
|
|
1878 /* COMPILED_INTERACTIVE = 5 */
|
|
1879 if (intp)
|
|
1880 {
|
826
|
1881 write_c_string (printcharfun, " ");
|
428
|
1882 print_internal (compiled_function_interactive (f), printcharfun,
|
|
1883 escapeflag);
|
|
1884 }
|
|
1885
|
|
1886 UNGCPRO;
|
826
|
1887 write_c_string (printcharfun, print_readably ? "]" : ">");
|
428
|
1888 }
|
|
1889
|
|
1890
|
|
1891 static Lisp_Object
|
|
1892 mark_compiled_function (Lisp_Object obj)
|
|
1893 {
|
|
1894 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (obj);
|
814
|
1895 int i;
|
428
|
1896
|
|
1897 mark_object (f->instructions);
|
|
1898 mark_object (f->arglist);
|
|
1899 mark_object (f->doc_and_interactive);
|
|
1900 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
1901 mark_object (f->annotated);
|
|
1902 #endif
|
814
|
1903 for (i = 0; i < f->args_in_array; i++)
|
|
1904 mark_object (f->args[i]);
|
|
1905
|
428
|
1906 /* tail-recurse on constants */
|
|
1907 return f->constants;
|
|
1908 }
|
|
1909
|
|
1910 static int
|
|
1911 compiled_function_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
|
1912 {
|
|
1913 Lisp_Compiled_Function *f1 = XCOMPILED_FUNCTION (obj1);
|
|
1914 Lisp_Compiled_Function *f2 = XCOMPILED_FUNCTION (obj2);
|
|
1915 return
|
|
1916 (f1->flags.documentationp == f2->flags.documentationp &&
|
|
1917 f1->flags.interactivep == f2->flags.interactivep &&
|
|
1918 f1->flags.domainp == f2->flags.domainp && /* I18N3 */
|
|
1919 internal_equal (compiled_function_instructions (f1),
|
|
1920 compiled_function_instructions (f2), depth + 1) &&
|
|
1921 internal_equal (f1->constants, f2->constants, depth + 1) &&
|
|
1922 internal_equal (f1->arglist, f2->arglist, depth + 1) &&
|
|
1923 internal_equal (f1->doc_and_interactive,
|
|
1924 f2->doc_and_interactive, depth + 1));
|
|
1925 }
|
|
1926
|
665
|
1927 static Hashcode
|
428
|
1928 compiled_function_hash (Lisp_Object obj, int depth)
|
|
1929 {
|
|
1930 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (obj);
|
|
1931 return HASH3 ((f->flags.documentationp << 2) +
|
|
1932 (f->flags.interactivep << 1) +
|
|
1933 f->flags.domainp,
|
|
1934 internal_hash (f->instructions, depth + 1),
|
|
1935 internal_hash (f->constants, depth + 1));
|
|
1936 }
|
|
1937
|
814
|
1938 static const struct lrecord_description lo_description_1[] = {
|
|
1939 { XD_LISP_OBJECT, 0 },
|
|
1940 { XD_END }
|
|
1941 };
|
|
1942
|
|
1943 static const struct struct_description lo_description = {
|
|
1944 sizeof (Lisp_Object),
|
|
1945 lo_description_1
|
|
1946 };
|
|
1947
|
428
|
1948 static const struct lrecord_description compiled_function_description[] = {
|
814
|
1949 { XD_INT, offsetof (Lisp_Compiled_Function, args_in_array) },
|
|
1950 { XD_STRUCT_PTR, offsetof (Lisp_Compiled_Function, args),
|
|
1951 XD_INDIRECT (0, 0), &lo_description },
|
440
|
1952 { XD_LISP_OBJECT, offsetof (Lisp_Compiled_Function, instructions) },
|
|
1953 { XD_LISP_OBJECT, offsetof (Lisp_Compiled_Function, constants) },
|
|
1954 { XD_LISP_OBJECT, offsetof (Lisp_Compiled_Function, arglist) },
|
|
1955 { XD_LISP_OBJECT, offsetof (Lisp_Compiled_Function, doc_and_interactive) },
|
428
|
1956 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
440
|
1957 { XD_LISP_OBJECT, offsetof (Lisp_Compiled_Function, annotated) },
|
428
|
1958 #endif
|
|
1959 { XD_END }
|
|
1960 };
|
|
1961
|
|
1962 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("compiled-function", compiled_function,
|
|
1963 mark_compiled_function,
|
|
1964 print_compiled_function, 0,
|
|
1965 compiled_function_equal,
|
|
1966 compiled_function_hash,
|
|
1967 compiled_function_description,
|
|
1968 Lisp_Compiled_Function);
|
|
1969
|
|
1970 DEFUN ("compiled-function-p", Fcompiled_function_p, 1, 1, 0, /*
|
|
1971 Return t if OBJECT is a byte-compiled function object.
|
|
1972 */
|
|
1973 (object))
|
|
1974 {
|
|
1975 return COMPILED_FUNCTIONP (object) ? Qt : Qnil;
|
|
1976 }
|
|
1977
|
|
1978 /************************************************************************/
|
|
1979 /* compiled-function object accessor functions */
|
|
1980 /************************************************************************/
|
|
1981
|
|
1982 Lisp_Object
|
|
1983 compiled_function_arglist (Lisp_Compiled_Function *f)
|
|
1984 {
|
|
1985 return f->arglist;
|
|
1986 }
|
|
1987
|
|
1988 Lisp_Object
|
|
1989 compiled_function_instructions (Lisp_Compiled_Function *f)
|
|
1990 {
|
|
1991 if (! OPAQUEP (f->instructions))
|
|
1992 return f->instructions;
|
|
1993
|
|
1994 {
|
|
1995 /* Invert action performed by optimize_byte_code() */
|
|
1996 Lisp_Opaque *opaque = XOPAQUE (f->instructions);
|
|
1997
|
867
|
1998 Ibyte * const buffer =
|
|
1999 alloca_array (Ibyte, OPAQUE_SIZE (opaque) * MAX_ICHAR_LEN);
|
|
2000 Ibyte *bp = buffer;
|
428
|
2001
|
442
|
2002 const Opbyte * const program = (const Opbyte *) OPAQUE_DATA (opaque);
|
|
2003 const Opbyte *program_ptr = program;
|
|
2004 const Opbyte * const program_end = program_ptr + OPAQUE_SIZE (opaque);
|
428
|
2005
|
|
2006 while (program_ptr < program_end)
|
|
2007 {
|
|
2008 Opcode opcode = (Opcode) READ_UINT_1;
|
867
|
2009 bp += set_itext_ichar (bp, opcode);
|
428
|
2010 switch (opcode)
|
|
2011 {
|
|
2012 case Bvarref+7:
|
|
2013 case Bvarset+7:
|
|
2014 case Bvarbind+7:
|
|
2015 case Bcall+7:
|
|
2016 case Bunbind+7:
|
|
2017 case Bconstant2:
|
867
|
2018 bp += set_itext_ichar (bp, READ_UINT_1);
|
|
2019 bp += set_itext_ichar (bp, READ_UINT_1);
|
428
|
2020 break;
|
|
2021
|
|
2022 case Bvarref+6:
|
|
2023 case Bvarset+6:
|
|
2024 case Bvarbind+6:
|
|
2025 case Bcall+6:
|
|
2026 case Bunbind+6:
|
|
2027 case BlistN:
|
|
2028 case BconcatN:
|
|
2029 case BinsertN:
|
867
|
2030 bp += set_itext_ichar (bp, READ_UINT_1);
|
428
|
2031 break;
|
|
2032
|
|
2033 case Bgoto:
|
|
2034 case Bgotoifnil:
|
|
2035 case Bgotoifnonnil:
|
|
2036 case Bgotoifnilelsepop:
|
|
2037 case Bgotoifnonnilelsepop:
|
|
2038 {
|
|
2039 int jump = READ_INT_2;
|
|
2040 Opbyte buf2[2];
|
|
2041 Opbyte *buf2p = buf2;
|
|
2042 /* Convert back to program-relative address */
|
|
2043 WRITE_INT16 (jump + (program_ptr - 2 - program), buf2p);
|
867
|
2044 bp += set_itext_ichar (bp, buf2[0]);
|
|
2045 bp += set_itext_ichar (bp, buf2[1]);
|
428
|
2046 break;
|
|
2047 }
|
|
2048
|
|
2049 case BRgoto:
|
|
2050 case BRgotoifnil:
|
|
2051 case BRgotoifnonnil:
|
|
2052 case BRgotoifnilelsepop:
|
|
2053 case BRgotoifnonnilelsepop:
|
867
|
2054 bp += set_itext_ichar (bp, READ_INT_1 + 127);
|
428
|
2055 break;
|
|
2056
|
|
2057 default:
|
|
2058 break;
|
|
2059 }
|
|
2060 }
|
|
2061 return make_string (buffer, bp - buffer);
|
|
2062 }
|
|
2063 }
|
|
2064
|
|
2065 Lisp_Object
|
|
2066 compiled_function_constants (Lisp_Compiled_Function *f)
|
|
2067 {
|
|
2068 return f->constants;
|
|
2069 }
|
|
2070
|
|
2071 int
|
|
2072 compiled_function_stack_depth (Lisp_Compiled_Function *f)
|
|
2073 {
|
|
2074 return f->stack_depth;
|
|
2075 }
|
|
2076
|
|
2077 /* The compiled_function->doc_and_interactive slot uses the minimal
|
|
2078 number of conses, based on compiled_function->flags; it may take
|
|
2079 any of the following forms:
|
|
2080
|
|
2081 doc
|
|
2082 interactive
|
|
2083 domain
|
|
2084 (doc . interactive)
|
|
2085 (doc . domain)
|
|
2086 (interactive . domain)
|
|
2087 (doc . (interactive . domain))
|
|
2088 */
|
|
2089
|
|
2090 /* Caller must check flags.interactivep first */
|
|
2091 Lisp_Object
|
|
2092 compiled_function_interactive (Lisp_Compiled_Function *f)
|
|
2093 {
|
|
2094 assert (f->flags.interactivep);
|
|
2095 if (f->flags.documentationp && f->flags.domainp)
|
|
2096 return XCAR (XCDR (f->doc_and_interactive));
|
|
2097 else if (f->flags.documentationp)
|
|
2098 return XCDR (f->doc_and_interactive);
|
|
2099 else if (f->flags.domainp)
|
|
2100 return XCAR (f->doc_and_interactive);
|
|
2101 else
|
|
2102 return f->doc_and_interactive;
|
|
2103 }
|
|
2104
|
|
2105 /* Caller need not check flags.documentationp first */
|
|
2106 Lisp_Object
|
|
2107 compiled_function_documentation (Lisp_Compiled_Function *f)
|
|
2108 {
|
|
2109 if (! f->flags.documentationp)
|
|
2110 return Qnil;
|
|
2111 else if (f->flags.interactivep && f->flags.domainp)
|
|
2112 return XCAR (f->doc_and_interactive);
|
|
2113 else if (f->flags.interactivep)
|
|
2114 return XCAR (f->doc_and_interactive);
|
|
2115 else if (f->flags.domainp)
|
|
2116 return XCAR (f->doc_and_interactive);
|
|
2117 else
|
|
2118 return f->doc_and_interactive;
|
|
2119 }
|
|
2120
|
|
2121 /* Caller need not check flags.domainp first */
|
|
2122 Lisp_Object
|
|
2123 compiled_function_domain (Lisp_Compiled_Function *f)
|
|
2124 {
|
|
2125 if (! f->flags.domainp)
|
|
2126 return Qnil;
|
|
2127 else if (f->flags.documentationp && f->flags.interactivep)
|
|
2128 return XCDR (XCDR (f->doc_and_interactive));
|
|
2129 else if (f->flags.documentationp)
|
|
2130 return XCDR (f->doc_and_interactive);
|
|
2131 else if (f->flags.interactivep)
|
|
2132 return XCDR (f->doc_and_interactive);
|
|
2133 else
|
|
2134 return f->doc_and_interactive;
|
|
2135 }
|
|
2136
|
|
2137 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
2138
|
|
2139 Lisp_Object
|
|
2140 compiled_function_annotation (Lisp_Compiled_Function *f)
|
|
2141 {
|
|
2142 return f->annotated;
|
|
2143 }
|
|
2144
|
|
2145 #endif
|
|
2146
|
|
2147 /* used only by Snarf-documentation; there must be doc already. */
|
|
2148 void
|
|
2149 set_compiled_function_documentation (Lisp_Compiled_Function *f,
|
|
2150 Lisp_Object new_doc)
|
|
2151 {
|
|
2152 assert (f->flags.documentationp);
|
|
2153 assert (INTP (new_doc) || STRINGP (new_doc));
|
|
2154
|
|
2155 if (f->flags.interactivep && f->flags.domainp)
|
|
2156 XCAR (f->doc_and_interactive) = new_doc;
|
|
2157 else if (f->flags.interactivep)
|
|
2158 XCAR (f->doc_and_interactive) = new_doc;
|
|
2159 else if (f->flags.domainp)
|
|
2160 XCAR (f->doc_and_interactive) = new_doc;
|
|
2161 else
|
|
2162 f->doc_and_interactive = new_doc;
|
|
2163 }
|
|
2164
|
|
2165
|
|
2166 DEFUN ("compiled-function-arglist", Fcompiled_function_arglist, 1, 1, 0, /*
|
|
2167 Return the argument list of the compiled-function object FUNCTION.
|
|
2168 */
|
|
2169 (function))
|
|
2170 {
|
|
2171 CHECK_COMPILED_FUNCTION (function);
|
|
2172 return compiled_function_arglist (XCOMPILED_FUNCTION (function));
|
|
2173 }
|
|
2174
|
|
2175 DEFUN ("compiled-function-instructions", Fcompiled_function_instructions, 1, 1, 0, /*
|
|
2176 Return the byte-opcode string of the compiled-function object FUNCTION.
|
|
2177 */
|
|
2178 (function))
|
|
2179 {
|
|
2180 CHECK_COMPILED_FUNCTION (function);
|
|
2181 return compiled_function_instructions (XCOMPILED_FUNCTION (function));
|
|
2182 }
|
|
2183
|
|
2184 DEFUN ("compiled-function-constants", Fcompiled_function_constants, 1, 1, 0, /*
|
|
2185 Return the constants vector of the compiled-function object FUNCTION.
|
|
2186 */
|
|
2187 (function))
|
|
2188 {
|
|
2189 CHECK_COMPILED_FUNCTION (function);
|
|
2190 return compiled_function_constants (XCOMPILED_FUNCTION (function));
|
|
2191 }
|
|
2192
|
|
2193 DEFUN ("compiled-function-stack-depth", Fcompiled_function_stack_depth, 1, 1, 0, /*
|
444
|
2194 Return the maximum stack depth of the compiled-function object FUNCTION.
|
428
|
2195 */
|
|
2196 (function))
|
|
2197 {
|
|
2198 CHECK_COMPILED_FUNCTION (function);
|
|
2199 return make_int (compiled_function_stack_depth (XCOMPILED_FUNCTION (function)));
|
|
2200 }
|
|
2201
|
|
2202 DEFUN ("compiled-function-doc-string", Fcompiled_function_doc_string, 1, 1, 0, /*
|
|
2203 Return the doc string of the compiled-function object FUNCTION, if available.
|
|
2204 Functions that had their doc strings snarfed into the DOC file will have
|
|
2205 an integer returned instead of a string.
|
|
2206 */
|
|
2207 (function))
|
|
2208 {
|
|
2209 CHECK_COMPILED_FUNCTION (function);
|
|
2210 return compiled_function_documentation (XCOMPILED_FUNCTION (function));
|
|
2211 }
|
|
2212
|
|
2213 DEFUN ("compiled-function-interactive", Fcompiled_function_interactive, 1, 1, 0, /*
|
|
2214 Return the interactive spec of the compiled-function object FUNCTION, or nil.
|
|
2215 If non-nil, the return value will be a list whose first element is
|
|
2216 `interactive' and whose second element is the interactive spec.
|
|
2217 */
|
|
2218 (function))
|
|
2219 {
|
|
2220 CHECK_COMPILED_FUNCTION (function);
|
|
2221 return XCOMPILED_FUNCTION (function)->flags.interactivep
|
|
2222 ? list2 (Qinteractive,
|
|
2223 compiled_function_interactive (XCOMPILED_FUNCTION (function)))
|
|
2224 : Qnil;
|
|
2225 }
|
|
2226
|
|
2227 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
2228
|
826
|
2229 DEFUN ("compiled-function-annotation", Fcompiled_function_annotation, 1, 1, 0, /*
|
428
|
2230 Return the annotation of the compiled-function object FUNCTION, or nil.
|
|
2231 The annotation is a piece of information indicating where this
|
|
2232 compiled-function object came from. Generally this will be
|
|
2233 a symbol naming a function; or a string naming a file, if the
|
|
2234 compiled-function object was not defined in a function; or nil,
|
|
2235 if the compiled-function object was not created as a result of
|
|
2236 a `load'.
|
|
2237 */
|
|
2238 (function))
|
|
2239 {
|
|
2240 CHECK_COMPILED_FUNCTION (function);
|
|
2241 return compiled_function_annotation (XCOMPILED_FUNCTION (function));
|
|
2242 }
|
|
2243
|
|
2244 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */
|
|
2245
|
|
2246 DEFUN ("compiled-function-domain", Fcompiled_function_domain, 1, 1, 0, /*
|
|
2247 Return the domain of the compiled-function object FUNCTION, or nil.
|
|
2248 This is only meaningful if I18N3 was enabled when emacs was compiled.
|
|
2249 */
|
|
2250 (function))
|
|
2251 {
|
|
2252 CHECK_COMPILED_FUNCTION (function);
|
|
2253 return XCOMPILED_FUNCTION (function)->flags.domainp
|
|
2254 ? compiled_function_domain (XCOMPILED_FUNCTION (function))
|
|
2255 : Qnil;
|
|
2256 }
|
|
2257
|
|
2258
|
|
2259
|
|
2260 DEFUN ("fetch-bytecode", Ffetch_bytecode, 1, 1, 0, /*
|
|
2261 If the byte code for compiled function FUNCTION is lazy-loaded, fetch it now.
|
|
2262 */
|
|
2263 (function))
|
|
2264 {
|
|
2265 Lisp_Compiled_Function *f;
|
|
2266 CHECK_COMPILED_FUNCTION (function);
|
|
2267 f = XCOMPILED_FUNCTION (function);
|
|
2268
|
|
2269 if (OPAQUEP (f->instructions) || STRINGP (f->instructions))
|
|
2270 return function;
|
|
2271
|
|
2272 if (CONSP (f->instructions))
|
|
2273 {
|
|
2274 Lisp_Object tem = read_doc_string (f->instructions);
|
|
2275 if (!CONSP (tem))
|
563
|
2276 signal_error (Qinvalid_byte_code,
|
|
2277 "Invalid lazy-loaded byte code", tem);
|
428
|
2278 /* v18 or v19 bytecode file. Need to Ebolify. */
|
|
2279 if (f->flags.ebolified && VECTORP (XCDR (tem)))
|
|
2280 ebolify_bytecode_constants (XCDR (tem));
|
|
2281 f->instructions = XCAR (tem);
|
|
2282 f->constants = XCDR (tem);
|
|
2283 return function;
|
|
2284 }
|
|
2285 abort ();
|
801
|
2286 return Qnil; /* not (usually) reached */
|
428
|
2287 }
|
|
2288
|
|
2289 DEFUN ("optimize-compiled-function", Foptimize_compiled_function, 1, 1, 0, /*
|
|
2290 Convert compiled function FUNCTION into an optimized internal form.
|
|
2291 */
|
|
2292 (function))
|
|
2293 {
|
|
2294 Lisp_Compiled_Function *f;
|
|
2295 CHECK_COMPILED_FUNCTION (function);
|
|
2296 f = XCOMPILED_FUNCTION (function);
|
|
2297
|
|
2298 if (OPAQUEP (f->instructions)) /* Already optimized? */
|
|
2299 return Qnil;
|
|
2300
|
|
2301 optimize_compiled_function (function);
|
|
2302 return Qnil;
|
|
2303 }
|
|
2304
|
|
2305 DEFUN ("byte-code", Fbyte_code, 3, 3, 0, /*
|
|
2306 Function used internally in byte-compiled code.
|
|
2307 First argument INSTRUCTIONS is a string of byte code.
|
|
2308 Second argument CONSTANTS is a vector of constants.
|
|
2309 Third argument STACK-DEPTH is the maximum stack depth used in this function.
|
|
2310 If STACK-DEPTH is incorrect, Emacs may crash.
|
|
2311 */
|
|
2312 (instructions, constants, stack_depth))
|
|
2313 {
|
|
2314 /* This function can GC */
|
|
2315 int varbind_count;
|
|
2316 int program_length;
|
|
2317 Opbyte *program;
|
|
2318
|
|
2319 CHECK_STRING (instructions);
|
|
2320 CHECK_VECTOR (constants);
|
|
2321 CHECK_NATNUM (stack_depth);
|
|
2322
|
|
2323 /* Optimize the `instructions' string, just like when executing a
|
|
2324 regular compiled function, but don't save it for later since this is
|
|
2325 likely to only be executed once. */
|
|
2326 program = alloca_array (Opbyte, 1 + 2 * XSTRING_LENGTH (instructions));
|
|
2327 optimize_byte_code (instructions, constants, program,
|
|
2328 &program_length, &varbind_count);
|
|
2329 SPECPDL_RESERVE (varbind_count);
|
|
2330 return execute_optimized_program (program,
|
|
2331 XINT (stack_depth),
|
|
2332 XVECTOR_DATA (constants));
|
|
2333 }
|
|
2334
|
|
2335
|
|
2336 void
|
|
2337 syms_of_bytecode (void)
|
|
2338 {
|
442
|
2339 INIT_LRECORD_IMPLEMENTATION (compiled_function);
|
|
2340
|
|
2341 DEFERROR_STANDARD (Qinvalid_byte_code, Qinvalid_state);
|
563
|
2342 DEFSYMBOL (Qbyte_code);
|
|
2343 DEFSYMBOL_MULTIWORD_PREDICATE (Qcompiled_functionp);
|
428
|
2344
|
|
2345 DEFSUBR (Fbyte_code);
|
|
2346 DEFSUBR (Ffetch_bytecode);
|
|
2347 DEFSUBR (Foptimize_compiled_function);
|
|
2348
|
|
2349 DEFSUBR (Fcompiled_function_p);
|
|
2350 DEFSUBR (Fcompiled_function_instructions);
|
|
2351 DEFSUBR (Fcompiled_function_constants);
|
|
2352 DEFSUBR (Fcompiled_function_stack_depth);
|
|
2353 DEFSUBR (Fcompiled_function_arglist);
|
|
2354 DEFSUBR (Fcompiled_function_interactive);
|
|
2355 DEFSUBR (Fcompiled_function_doc_string);
|
|
2356 DEFSUBR (Fcompiled_function_domain);
|
|
2357 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
2358 DEFSUBR (Fcompiled_function_annotation);
|
|
2359 #endif
|
|
2360
|
|
2361 #ifdef BYTE_CODE_METER
|
563
|
2362 DEFSYMBOL (Qbyte_code_meter);
|
428
|
2363 #endif
|
|
2364 }
|
|
2365
|
|
2366 void
|
|
2367 vars_of_bytecode (void)
|
|
2368 {
|
|
2369 #ifdef BYTE_CODE_METER
|
|
2370
|
|
2371 DEFVAR_LISP ("byte-code-meter", &Vbyte_code_meter /*
|
|
2372 A vector of vectors which holds a histogram of byte code usage.
|
|
2373 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte
|
|
2374 opcode CODE has been executed.
|
|
2375 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0,
|
|
2376 indicates how many times the byte opcodes CODE1 and CODE2 have been
|
|
2377 executed in succession.
|
|
2378 */ );
|
|
2379 DEFVAR_BOOL ("byte-metering-on", &byte_metering_on /*
|
|
2380 If non-nil, keep profiling information on byte code usage.
|
|
2381 The variable `byte-code-meter' indicates how often each byte opcode is used.
|
|
2382 If a symbol has a property named `byte-code-meter' whose value is an
|
|
2383 integer, it is incremented each time that symbol's function is called.
|
|
2384 */ );
|
|
2385
|
|
2386 byte_metering_on = 0;
|
|
2387 Vbyte_code_meter = make_vector (256, Qzero);
|
|
2388 {
|
|
2389 int i = 256;
|
|
2390 while (i--)
|
|
2391 XVECTOR_DATA (Vbyte_code_meter)[i] = make_vector (256, Qzero);
|
|
2392 }
|
|
2393 #endif /* BYTE_CODE_METER */
|
|
2394 }
|