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