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