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