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