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