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