Mercurial > hg > xemacs-beta
annotate src/bytecode.c @ 4677:8f1ee2d15784
Support full Common Lisp multiple values in C.
lisp/ChangeLog
2009-08-11 Aidan Kehoe <kehoea@parhasard.net>
* bytecomp.el :
Update this file to support full C-level multiple values. This
involves:
-- Four new bytecodes, and special compiler functions to compile
multiple-value-call, multiple-value-list-internal, values,
values-list, and, since it now needs to pass back multiple values
and is a special form, throw.
-- There's a new compiler variable, byte-compile-checks-on-load,
which is a list of forms that are evaluated at the very start of a
file, with an error thrown if any of them give nil.
-- The header is now inserted *after* compilation, giving a chance
for the compilation process to influence what those checks
are. There is still a check done before compilation for non-ASCII
characters, to try to turn off dynamic docstrings if appopriate,
in `byte-compile-maybe-reset-coding'.
Space is reserved for checks; comments describing the version of
the byte compiler generating the file are inserted if space
remains for them.
* bytecomp.el (byte-compile-version):
Update this, we're a newer version of the byte compiler.
* byte-optimize.el (byte-optimize-funcall):
Correct a comment.
* bytecomp.el (byte-compile-lapcode):
Discard the arg with byte-multiple-value-call.
* bytecomp.el (byte-compile-checks-and-comments-space):
New variable, describe how many octets to reserve for checks at
the start of byte-compiled files.
* cl-compat.el:
Remove the fake multiple-value implementation. Have the functions
that use it use the real multiple-value implementation instead.
* cl-macs.el (cl-block-wrapper, cl-block-throw):
Revise the byte-compile properties of these symbols to work now
we've made throw into a special form; keep the byte-compile
properties as anonymous lambdas, since we don't have docstrings
for them.
* cl-macs.el (multiple-value-bind, multiple-value-setq)
(multiple-value-list, nth-value):
Update these functions to work with the C support for multiple
values.
* cl-macs.el (values):
Modify the setf handler for this to call
#'multiple-value-list-internal appropriately.
* cl-macs.el (cl-setf-do-store):
If the store form is a cons, treat it specially as wrapping the
store value.
* cl.el (cl-block-wrapper):
Make this an alias of #'and, not #'identity, since it needs to
pass back multiple values.
* cl.el (multiple-value-apply):
We no longer support this, mark it obsolete.
* lisp-mode.el (eval-interactive-verbose):
Remove a useless space in the docstring.
* lisp-mode.el (eval-interactive):
Update this function and its docstring. It now passes back a list,
basically wrapping any eval calls with multiple-value-list. This
allows multiple values to be printed by default in *scratch*.
* lisp-mode.el (prin1-list-as-multiple-values):
New function, printing a list as multiple values in the manner of
Bruno Haible's clisp, separating each entry with " ;\n".
* lisp-mode.el (eval-last-sexp):
Call #'prin1-list-as-multiple-values on the return value of
#'eval-interactive.
* lisp-mode.el (eval-defun):
Call #'prin1-list-as-multiple-values on the return value of
#'eval-interactive.
* mouse.el (mouse-eval-sexp):
Deal with lists corresponding to multiple values from
#'eval-interactive. Call #'cl-prettyprint, which is always
available, instead of sometimes calling #'pprint and sometimes
falling back to prin1.
* obsolete.el (obsolete-throw):
New function, called from eval.c when #'funcall encounters an
attempt to call #'throw (now a special form) as a function. Only
needed for compatibility with 21.4 byte-code.
man/ChangeLog addition:
2009-08-11 Aidan Kehoe <kehoea@parhasard.net>
* cl.texi (Organization):
Remove references to the obsolete multiple-value emulating code.
src/ChangeLog addition:
2009-08-11 Aidan Kehoe <kehoea@parhasard.net>
* bytecode.c (enum Opcode /* Byte codes */):
Add four new bytecodes, to deal with multiple values.
(POP_WITH_MULTIPLE_VALUES): New macro.
(POP): Modify this macro to ignore multiple values.
(DISCARD_PRESERVING_MULTIPLE_VALUES): New macro.
(DISCARD): Modify this macro to ignore multiple values.
(TOP_WITH_MULTIPLE_VALUES): New macro.
(TOP_ADDRESS): New macro.
(TOP): Modify this macro to ignore multiple values.
(TOP_LVALUE): New macro.
(Bcall): Ignore multiple values where appropriate.
(Breturn): Pass back multiple values.
(Bdup): Preserve multiple values.
Use TOP_LVALUE with most bytecodes that assign anything to
anything.
(Bbind_multiple_value_limits, Bmultiple_value_call,
Bmultiple_value_list_internal, Bthrow): Implement the new
bytecodes.
(Bgotoifnilelsepop, Bgotoifnonnilelsepop, BRgotoifnilelsepop,
BRgotoifnonnilelsepop):
Discard any multiple values.
* callint.c (Fcall_interactively):
Ignore multiple values when calling #'eval, in two places.
* device-x.c (x_IO_error_handler):
* macros.c (pop_kbd_macro_event):
* eval.c (Fsignal):
* eval.c (flagged_a_squirmer):
Call throw_or_bomb_out, not Fthrow, now that the latter is a
special form.
* eval.c:
Make Qthrow, Qobsolete_throw available as symbols.
Provide multiple_value_current_limit, multiple-values-limit (the
latter as specified by Common Lisp.
* eval.c (For):
Ignore multiple values when comparing with Qnil, but pass any
multiple values back for the last arg.
* eval.c (Fand):
Ditto.
* eval.c (Fif):
Ignore multiple values when examining the result of the
condition.
* eval.c (Fcond):
Ignore multiple values when comparing what the clauses give, but
pass them back if a clause gave non-nil.
* eval.c (Fprog2):
Never pass back multiple values.
* eval.c (FletX, Flet):
Ignore multiple when evaluating what exactly symbols should be
bound to.
* eval.c (Fwhile):
Ignore multiple values when evaluating the test.
* eval.c (Fsetq, Fdefvar, Fdefconst):
Ignore multiple values.
* eval.c (Fthrow):
Declare this as a special form; ignore multiple values for TAG,
preserve them for VALUE.
* eval.c (throw_or_bomb_out):
Make this available to other files, now Fthrow is a special form.
* eval.c (Feval):
Ignore multiple values when calling a compiled function, a
non-special-form subr, or a lambda expression.
* eval.c (Ffuncall):
If we attempt to call #'throw (now a special form) as a function,
don't error, call #'obsolete-throw instead.
* eval.c (make_multiple_value, multiple_value_aset)
(multiple_value_aref, print_multiple_value, mark_multiple_value)
(size_multiple_value):
Implement the multiple_value type. Add a long comment describing
our implementation.
* eval.c (bind_multiple_value_limits):
New function, used by the bytecode and by #'multiple-value-call,
#'multiple-value-list-internal.
* eval.c (multiple_value_call):
New function, used by the bytecode and #'multiple-value-call.
* eval.c (Fmultiple_value_call):
New special form.
* eval.c (multiple_value_list_internal):
New function, used by the byte code and
#'multiple-value-list-internal.
* eval.c (Fmultiple_value_list_internal, Fmultiple_value_prog1):
New special forms.
* eval.c (Fvalues, Fvalues_list):
New Lisp functions.
* eval.c (values2):
New function, for C code returning multiple values.
* eval.c (syms_of_eval):
Make our new Lisp functions and symbols available.
* eval.c (multiple-values-limit):
Make this available to Lisp.
* event-msw.c (dde_eval_string):
* event-stream.c (execute_help_form):
* glade.c (connector):
* glyphs-widget.c (glyph_instantiator_to_glyph):
* glyphs.c (evaluate_xpm_color_symbols):
* gui-x.c (wv_set_evalable_slot, button_item_to_widget_value):
* gui.c (gui_item_value, gui_item_display_flush_left):
* lread.c (check_if_suppressed):
* menubar-gtk.c (menu_convert, menu_descriptor_to_widget_1):
* menubar-msw.c (populate_menu_add_item):
* print.c (Fwith_output_to_temp_buffer):
* symbols.c (Fsetq_default):
Ignore multiple values when calling Feval.
* symeval.h:
Add the header declarations necessary for the multiple-values
implementation.
* inline.c:
#include symeval.h, now that it has some inline functions.
* lisp.h:
Update Fthrow's declaration. Make throw_or_bomb_out available to
all files.
* lrecord.h (enum lrecord_type):
Add the multiple_value type here.
author | Aidan Kehoe <kehoea@parhasard.net> |
---|---|
date | Sun, 16 Aug 2009 20:55:49 +0100 |
parents | d674024a8674 |
children | b5e1d4f6b66f |
rev | line source |
---|---|
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 |
3092 | 61 #ifdef NEW_GC |
62 static Lisp_Object | |
63 make_compiled_function_args (int totalargs) | |
64 { | |
65 Lisp_Compiled_Function_Args *args; | |
66 args = (Lisp_Compiled_Function_Args *) | |
67 alloc_lrecord | |
68 (FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Compiled_Function_Args, | |
69 Lisp_Object, args, totalargs), | |
70 &lrecord_compiled_function_args); | |
71 args->size = totalargs; | |
72 return wrap_compiled_function_args (args); | |
73 } | |
74 | |
75 static Bytecount | |
76 size_compiled_function_args (const void *lheader) | |
77 { | |
78 return FLEXIBLE_ARRAY_STRUCT_SIZEOF (Lisp_Compiled_Function_Args, | |
79 Lisp_Object, args, | |
80 ((Lisp_Compiled_Function_Args *) | |
81 lheader)->size); | |
82 } | |
83 | |
84 static const struct memory_description compiled_function_args_description[] = { | |
85 { XD_LONG, offsetof (Lisp_Compiled_Function_Args, size) }, | |
86 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Compiled_Function_Args, args), | |
87 XD_INDIRECT(0, 0) }, | |
88 { XD_END } | |
89 }; | |
90 | |
91 DEFINE_LRECORD_SEQUENCE_IMPLEMENTATION ("compiled-function-args", | |
92 compiled_function_args, | |
93 1, /*dumpable-flag*/ | |
94 0, 0, 0, 0, 0, | |
95 compiled_function_args_description, | |
96 size_compiled_function_args, | |
97 Lisp_Compiled_Function_Args); | |
98 #endif /* NEW_GC */ | |
99 | |
428 | 100 EXFUN (Ffetch_bytecode, 1); |
101 | |
102 Lisp_Object Qbyte_code, Qcompiled_functionp, Qinvalid_byte_code; | |
103 | |
104 enum Opcode /* Byte codes */ | |
105 { | |
106 Bvarref = 010, | |
107 Bvarset = 020, | |
108 Bvarbind = 030, | |
109 Bcall = 040, | |
110 Bunbind = 050, | |
111 | |
112 Bnth = 070, | |
113 Bsymbolp = 071, | |
114 Bconsp = 072, | |
115 Bstringp = 073, | |
116 Blistp = 074, | |
117 Bold_eq = 075, | |
118 Bold_memq = 076, | |
119 Bnot = 077, | |
120 Bcar = 0100, | |
121 Bcdr = 0101, | |
122 Bcons = 0102, | |
123 Blist1 = 0103, | |
124 Blist2 = 0104, | |
125 Blist3 = 0105, | |
126 Blist4 = 0106, | |
127 Blength = 0107, | |
128 Baref = 0110, | |
129 Baset = 0111, | |
130 Bsymbol_value = 0112, | |
131 Bsymbol_function = 0113, | |
132 Bset = 0114, | |
133 Bfset = 0115, | |
134 Bget = 0116, | |
135 Bsubstring = 0117, | |
136 Bconcat2 = 0120, | |
137 Bconcat3 = 0121, | |
138 Bconcat4 = 0122, | |
139 Bsub1 = 0123, | |
140 Badd1 = 0124, | |
141 Beqlsign = 0125, | |
142 Bgtr = 0126, | |
143 Blss = 0127, | |
144 Bleq = 0130, | |
145 Bgeq = 0131, | |
146 Bdiff = 0132, | |
147 Bnegate = 0133, | |
148 Bplus = 0134, | |
149 Bmax = 0135, | |
150 Bmin = 0136, | |
151 Bmult = 0137, | |
152 | |
153 Bpoint = 0140, | |
154 Beq = 0141, /* was Bmark, | |
155 but no longer generated as of v18 */ | |
156 Bgoto_char = 0142, | |
157 Binsert = 0143, | |
158 Bpoint_max = 0144, | |
159 Bpoint_min = 0145, | |
160 Bchar_after = 0146, | |
161 Bfollowing_char = 0147, | |
162 Bpreceding_char = 0150, | |
163 Bcurrent_column = 0151, | |
164 Bindent_to = 0152, | |
165 Bequal = 0153, /* was Bscan_buffer, | |
166 but no longer generated as of v18 */ | |
167 Beolp = 0154, | |
168 Beobp = 0155, | |
169 Bbolp = 0156, | |
170 Bbobp = 0157, | |
171 Bcurrent_buffer = 0160, | |
172 Bset_buffer = 0161, | |
173 Bsave_current_buffer = 0162, /* was Bread_char, | |
174 but no longer generated as of v19 */ | |
175 Bmemq = 0163, /* was Bset_mark, | |
176 but no longer generated as of v18 */ | |
177 Binteractive_p = 0164, /* Needed since interactive-p takes | |
178 unevalled args */ | |
179 Bforward_char = 0165, | |
180 Bforward_word = 0166, | |
181 Bskip_chars_forward = 0167, | |
182 Bskip_chars_backward = 0170, | |
183 Bforward_line = 0171, | |
184 Bchar_syntax = 0172, | |
185 Bbuffer_substring = 0173, | |
186 Bdelete_region = 0174, | |
187 Bnarrow_to_region = 0175, | |
188 Bwiden = 0176, | |
189 Bend_of_line = 0177, | |
190 | |
191 Bconstant2 = 0201, | |
192 Bgoto = 0202, | |
193 Bgotoifnil = 0203, | |
194 Bgotoifnonnil = 0204, | |
195 Bgotoifnilelsepop = 0205, | |
196 Bgotoifnonnilelsepop = 0206, | |
197 Breturn = 0207, | |
198 Bdiscard = 0210, | |
199 Bdup = 0211, | |
200 | |
201 Bsave_excursion = 0212, | |
202 Bsave_window_excursion= 0213, | |
203 Bsave_restriction = 0214, | |
204 Bcatch = 0215, | |
205 | |
206 Bunwind_protect = 0216, | |
207 Bcondition_case = 0217, | |
208 Btemp_output_buffer_setup = 0220, | |
209 Btemp_output_buffer_show = 0221, | |
210 | |
211 Bunbind_all = 0222, | |
212 | |
213 Bset_marker = 0223, | |
214 Bmatch_beginning = 0224, | |
215 Bmatch_end = 0225, | |
216 Bupcase = 0226, | |
217 Bdowncase = 0227, | |
218 | |
219 Bstring_equal = 0230, | |
220 Bstring_lessp = 0231, | |
221 Bold_equal = 0232, | |
222 Bnthcdr = 0233, | |
223 Belt = 0234, | |
224 Bold_member = 0235, | |
225 Bold_assq = 0236, | |
226 Bnreverse = 0237, | |
227 Bsetcar = 0240, | |
228 Bsetcdr = 0241, | |
229 Bcar_safe = 0242, | |
230 Bcdr_safe = 0243, | |
231 Bnconc = 0244, | |
232 Bquo = 0245, | |
233 Brem = 0246, | |
234 Bnumberp = 0247, | |
235 Bintegerp = 0250, | |
236 | |
237 BRgoto = 0252, | |
238 BRgotoifnil = 0253, | |
239 BRgotoifnonnil = 0254, | |
240 BRgotoifnilelsepop = 0255, | |
241 BRgotoifnonnilelsepop = 0256, | |
242 | |
243 BlistN = 0257, | |
244 BconcatN = 0260, | |
245 BinsertN = 0261, | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
246 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
247 Bbind_multiple_value_limits = 0262, /* New in 21.5. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
248 Bmultiple_value_list_internal = 0263, /* New in 21.5. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
249 Bmultiple_value_call = 0264, /* New in 21.5. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
250 Bthrow = 0265, /* New in 21.5. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
251 |
428 | 252 Bmember = 0266, /* new in v20 */ |
253 Bassq = 0267, /* new in v20 */ | |
254 | |
255 Bconstant = 0300 | |
256 }; | |
257 typedef enum Opcode Opcode; | |
258 | |
259 | |
260 Lisp_Object * execute_rare_opcode (Lisp_Object *stack_ptr, | |
442 | 261 const Opbyte *program_ptr, |
428 | 262 Opcode opcode); |
263 | |
264 /* Define BYTE_CODE_METER to enable generation of a byte-op usage histogram. | |
265 This isn't defined in FSF Emacs and isn't defined in XEmacs v19. */ | |
266 /* #define BYTE_CODE_METER */ | |
267 | |
268 | |
269 #ifdef BYTE_CODE_METER | |
270 | |
271 Lisp_Object Vbyte_code_meter, Qbyte_code_meter; | |
272 int byte_metering_on; | |
273 | |
274 static void | |
275 meter_code (Opcode prev_opcode, Opcode this_opcode) | |
276 { | |
277 if (byte_metering_on) | |
278 { | |
279 Lisp_Object *p = XVECTOR_DATA (XVECTOR_DATA (Vbyte_code_meter)[this_opcode]); | |
280 p[0] = INT_PLUS1 (p[0]); | |
281 if (prev_opcode) | |
282 p[prev_opcode] = INT_PLUS1 (p[prev_opcode]); | |
283 } | |
284 } | |
285 | |
286 #endif /* BYTE_CODE_METER */ | |
287 | |
288 | |
289 static Lisp_Object | |
290 bytecode_negate (Lisp_Object obj) | |
291 { | |
292 retry: | |
293 | |
1983 | 294 if (INTP (obj)) return make_integer (- XINT (obj)); |
428 | 295 if (FLOATP (obj)) return make_float (- XFLOAT_DATA (obj)); |
1983 | 296 if (CHARP (obj)) return make_integer (- ((int) XCHAR (obj))); |
297 if (MARKERP (obj)) return make_integer (- ((int) marker_position (obj))); | |
298 #ifdef HAVE_BIGNUM | |
299 if (BIGNUMP (obj)) BIGNUM_ARITH_RETURN (obj, neg); | |
300 #endif | |
301 #ifdef HAVE_RATIO | |
302 if (RATIOP (obj)) RATIO_ARITH_RETURN (obj, neg); | |
303 #endif | |
304 #ifdef HAVE_BIG_FLOAT | |
305 if (BIGFLOAT_P (obj)) BIGFLOAT_ARITH_RETURN (obj, neg); | |
306 #endif | |
428 | 307 |
308 obj = wrong_type_argument (Qnumber_char_or_marker_p, obj); | |
309 goto retry; | |
310 } | |
311 | |
312 static Lisp_Object | |
313 bytecode_nreverse (Lisp_Object list) | |
314 { | |
315 REGISTER Lisp_Object prev = Qnil; | |
316 REGISTER Lisp_Object tail = list; | |
317 | |
318 while (!NILP (tail)) | |
319 { | |
320 REGISTER Lisp_Object next; | |
321 CHECK_CONS (tail); | |
322 next = XCDR (tail); | |
323 XCDR (tail) = prev; | |
324 prev = tail; | |
325 tail = next; | |
326 } | |
327 return prev; | |
328 } | |
329 | |
330 | |
331 /* We have our own two-argument versions of various arithmetic ops. | |
332 Only two-argument arithmetic operations have their own byte codes. */ | |
333 static int | |
334 bytecode_arithcompare (Lisp_Object obj1, Lisp_Object obj2) | |
335 { | |
1983 | 336 #ifdef WITH_NUMBER_TYPES |
337 switch (promote_args (&obj1, &obj2)) | |
338 { | |
339 case FIXNUM_T: | |
340 { | |
341 EMACS_INT ival1 = XREALINT (obj1), ival2 = XREALINT (obj2); | |
342 return ival1 < ival2 ? -1 : ival1 > ival2 ? 1 : 0; | |
343 } | |
344 #ifdef HAVE_BIGNUM | |
345 case BIGNUM_T: | |
346 return bignum_cmp (XBIGNUM_DATA (obj1), XBIGNUM_DATA (obj2)); | |
347 #endif | |
348 #ifdef HAVE_RATIO | |
349 case RATIO_T: | |
350 return ratio_cmp (XRATIO_DATA (obj1), XRATIO_DATA (obj2)); | |
351 #endif | |
1995 | 352 #ifdef HAVE_BIGFLOAT |
353 case BIGFLOAT_T: | |
354 return bigfloat_cmp (XBIGFLOAT_DATA (obj1), XBIGFLOAT_DATA (obj2)); | |
355 #endif | |
356 default: /* FLOAT_T */ | |
1983 | 357 { |
358 double dval1 = XFLOAT_DATA (obj1), dval2 = XFLOAT_DATA (obj2); | |
359 return dval1 < dval2 ? -1 : dval1 > dval2 ? 1 : 0; | |
360 } | |
361 } | |
362 #else /* !WITH_NUMBER_TYPES */ | |
428 | 363 retry: |
364 | |
365 { | |
366 EMACS_INT ival1, ival2; | |
367 | |
368 if (INTP (obj1)) ival1 = XINT (obj1); | |
369 else if (CHARP (obj1)) ival1 = XCHAR (obj1); | |
370 else if (MARKERP (obj1)) ival1 = marker_position (obj1); | |
371 else goto arithcompare_float; | |
372 | |
373 if (INTP (obj2)) ival2 = XINT (obj2); | |
374 else if (CHARP (obj2)) ival2 = XCHAR (obj2); | |
375 else if (MARKERP (obj2)) ival2 = marker_position (obj2); | |
376 else goto arithcompare_float; | |
377 | |
378 return ival1 < ival2 ? -1 : ival1 > ival2 ? 1 : 0; | |
379 } | |
380 | |
381 arithcompare_float: | |
382 | |
383 { | |
384 double dval1, dval2; | |
385 | |
386 if (FLOATP (obj1)) dval1 = XFLOAT_DATA (obj1); | |
387 else if (INTP (obj1)) dval1 = (double) XINT (obj1); | |
388 else if (CHARP (obj1)) dval1 = (double) XCHAR (obj1); | |
389 else if (MARKERP (obj1)) dval1 = (double) marker_position (obj1); | |
390 else | |
391 { | |
392 obj1 = wrong_type_argument (Qnumber_char_or_marker_p, obj1); | |
393 goto retry; | |
394 } | |
395 | |
396 if (FLOATP (obj2)) dval2 = XFLOAT_DATA (obj2); | |
397 else if (INTP (obj2)) dval2 = (double) XINT (obj2); | |
398 else if (CHARP (obj2)) dval2 = (double) XCHAR (obj2); | |
399 else if (MARKERP (obj2)) dval2 = (double) marker_position (obj2); | |
400 else | |
401 { | |
402 obj2 = wrong_type_argument (Qnumber_char_or_marker_p, obj2); | |
403 goto retry; | |
404 } | |
405 | |
406 return dval1 < dval2 ? -1 : dval1 > dval2 ? 1 : 0; | |
407 } | |
1983 | 408 #endif /* WITH_NUMBER_TYPES */ |
428 | 409 } |
410 | |
411 static Lisp_Object | |
412 bytecode_arithop (Lisp_Object obj1, Lisp_Object obj2, Opcode opcode) | |
413 { | |
1983 | 414 #ifdef WITH_NUMBER_TYPES |
415 switch (promote_args (&obj1, &obj2)) | |
416 { | |
417 case FIXNUM_T: | |
418 { | |
419 EMACS_INT ival1 = XREALINT (obj1), ival2 = XREALINT (obj2); | |
420 switch (opcode) | |
421 { | |
422 case Bplus: ival1 += ival2; break; | |
423 case Bdiff: ival1 -= ival2; break; | |
424 case Bmult: | |
425 #ifdef HAVE_BIGNUM | |
426 /* Due to potential overflow, we compute using bignums */ | |
427 bignum_set_long (scratch_bignum, ival1); | |
428 bignum_set_long (scratch_bignum2, ival2); | |
429 bignum_mul (scratch_bignum, scratch_bignum, scratch_bignum2); | |
430 return Fcanonicalize_number (make_bignum_bg (scratch_bignum)); | |
431 #else | |
432 ival1 *= ival2; break; | |
433 #endif | |
434 case Bquo: | |
435 if (ival2 == 0) Fsignal (Qarith_error, Qnil); | |
436 ival1 /= ival2; | |
437 break; | |
438 case Bmax: if (ival1 < ival2) ival1 = ival2; break; | |
439 case Bmin: if (ival1 > ival2) ival1 = ival2; break; | |
440 } | |
441 return make_integer (ival1); | |
442 } | |
443 #ifdef HAVE_BIGNUM | |
444 case BIGNUM_T: | |
445 switch (opcode) | |
446 { | |
447 case Bplus: | |
448 bignum_add (scratch_bignum, XBIGNUM_DATA (obj1), | |
449 XBIGNUM_DATA (obj2)); | |
450 break; | |
451 case Bdiff: | |
452 bignum_sub (scratch_bignum, XBIGNUM_DATA (obj1), | |
453 XBIGNUM_DATA (obj2)); | |
454 break; | |
455 case Bmult: | |
456 bignum_mul (scratch_bignum, XBIGNUM_DATA (obj1), | |
457 XBIGNUM_DATA (obj2)); | |
458 break; | |
459 case Bquo: | |
460 if (bignum_sign (XBIGNUM_DATA (obj2)) == 0) | |
461 Fsignal (Qarith_error, Qnil); | |
462 bignum_div (scratch_bignum, XBIGNUM_DATA (obj1), | |
463 XBIGNUM_DATA (obj2)); | |
464 break; | |
465 case Bmax: | |
466 return bignum_gt (XBIGNUM_DATA (obj1), XBIGNUM_DATA (obj2)) | |
467 ? obj1 : obj2; | |
468 case Bmin: | |
469 return bignum_lt (XBIGNUM_DATA (obj1), XBIGNUM_DATA (obj2)) | |
470 ? obj1 : obj2; | |
471 } | |
472 return Fcanonicalize_number (make_bignum_bg (scratch_bignum)); | |
473 #endif | |
474 #ifdef HAVE_RATIO | |
475 case RATIO_T: | |
476 switch (opcode) | |
477 { | |
478 case Bplus: | |
479 ratio_add (scratch_ratio, XRATIO_DATA (obj1), XRATIO_DATA (obj2)); | |
480 break; | |
481 case Bdiff: | |
482 ratio_sub (scratch_ratio, XRATIO_DATA (obj1), XRATIO_DATA (obj2)); | |
483 break; | |
484 case Bmult: | |
485 ratio_mul (scratch_ratio, XRATIO_DATA (obj1), XRATIO_DATA (obj2)); | |
486 break; | |
487 case Bquo: | |
488 if (ratio_sign (XRATIO_DATA (obj2)) == 0) | |
489 Fsignal (Qarith_error, Qnil); | |
490 ratio_div (scratch_ratio, XRATIO_DATA (obj1), XRATIO_DATA (obj2)); | |
491 break; | |
492 case Bmax: | |
493 return ratio_gt (XRATIO_DATA (obj1), XRATIO_DATA (obj2)) | |
494 ? obj1 : obj2; | |
495 case Bmin: | |
496 return ratio_lt (XRATIO_DATA (obj1), XRATIO_DATA (obj2)) | |
497 ? obj1 : obj2; | |
498 } | |
499 return make_ratio_rt (scratch_ratio); | |
500 #endif | |
501 #ifdef HAVE_BIGFLOAT | |
502 case BIGFLOAT_T: | |
503 bigfloat_set_prec (scratch_bigfloat, max (XBIGFLOAT_GET_PREC (obj1), | |
504 XBIGFLOAT_GET_PREC (obj2))); | |
505 switch (opcode) | |
506 { | |
507 case Bplus: | |
508 bigfloat_add (scratch_bigfloat, XBIGFLOAT_DATA (obj1), | |
509 XBIGFLOAT_DATA (obj2)); | |
510 break; | |
511 case Bdiff: | |
512 bigfloat_sub (scratch_bigfloat, XBIGFLOAT_DATA (obj1), | |
513 XBIGFLOAT_DATA (obj2)); | |
514 break; | |
515 case Bmult: | |
516 bigfloat_mul (scratch_bigfloat, XBIGFLOAT_DATA (obj1), | |
517 XBIGFLOAT_DATA (obj2)); | |
518 break; | |
519 case Bquo: | |
520 if (bigfloat_sign (XBIGFLOAT_DATA (obj2)) == 0) | |
521 Fsignal (Qarith_error, Qnil); | |
522 bigfloat_div (scratch_bigfloat, XBIGFLOAT_DATA (obj1), | |
523 XBIGFLOAT_DATA (obj2)); | |
524 break; | |
525 case Bmax: | |
526 return bigfloat_gt (XBIGFLOAT_DATA (obj1), XBIGFLOAT_DATA (obj2)) | |
527 ? obj1 : obj2; | |
528 case Bmin: | |
529 return bigfloat_lt (XBIGFLOAT_DATA (obj1), XBIGFLOAT_DATA (obj2)) | |
530 ? obj1 : obj2; | |
531 } | |
532 return make_bigfloat_bf (scratch_bigfloat); | |
533 #endif | |
1995 | 534 default: /* FLOAT_T */ |
535 { | |
536 double dval1 = XFLOAT_DATA (obj1), dval2 = XFLOAT_DATA (obj2); | |
537 switch (opcode) | |
538 { | |
539 case Bplus: dval1 += dval2; break; | |
540 case Bdiff: dval1 -= dval2; break; | |
541 case Bmult: dval1 *= dval2; break; | |
542 case Bquo: | |
543 if (dval2 == 0.0) Fsignal (Qarith_error, Qnil); | |
544 dval1 /= dval2; | |
545 break; | |
546 case Bmax: if (dval1 < dval2) dval1 = dval2; break; | |
547 case Bmin: if (dval1 > dval2) dval1 = dval2; break; | |
548 } | |
549 return make_float (dval1); | |
550 } | |
1983 | 551 } |
552 #else /* !WITH_NUMBER_TYPES */ | |
428 | 553 EMACS_INT ival1, ival2; |
554 int float_p; | |
555 | |
556 retry: | |
557 | |
558 float_p = 0; | |
559 | |
560 if (INTP (obj1)) ival1 = XINT (obj1); | |
561 else if (CHARP (obj1)) ival1 = XCHAR (obj1); | |
562 else if (MARKERP (obj1)) ival1 = marker_position (obj1); | |
563 else if (FLOATP (obj1)) ival1 = 0, float_p = 1; | |
564 else | |
565 { | |
566 obj1 = wrong_type_argument (Qnumber_char_or_marker_p, obj1); | |
567 goto retry; | |
568 } | |
569 | |
570 if (INTP (obj2)) ival2 = XINT (obj2); | |
571 else if (CHARP (obj2)) ival2 = XCHAR (obj2); | |
572 else if (MARKERP (obj2)) ival2 = marker_position (obj2); | |
573 else if (FLOATP (obj2)) ival2 = 0, float_p = 1; | |
574 else | |
575 { | |
576 obj2 = wrong_type_argument (Qnumber_char_or_marker_p, obj2); | |
577 goto retry; | |
578 } | |
579 | |
580 if (!float_p) | |
581 { | |
582 switch (opcode) | |
583 { | |
584 case Bplus: ival1 += ival2; break; | |
585 case Bdiff: ival1 -= ival2; break; | |
586 case Bmult: ival1 *= ival2; break; | |
587 case Bquo: | |
588 if (ival2 == 0) Fsignal (Qarith_error, Qnil); | |
589 ival1 /= ival2; | |
590 break; | |
591 case Bmax: if (ival1 < ival2) ival1 = ival2; break; | |
592 case Bmin: if (ival1 > ival2) ival1 = ival2; break; | |
593 } | |
594 return make_int (ival1); | |
595 } | |
596 else | |
597 { | |
598 double dval1 = FLOATP (obj1) ? XFLOAT_DATA (obj1) : (double) ival1; | |
599 double dval2 = FLOATP (obj2) ? XFLOAT_DATA (obj2) : (double) ival2; | |
600 switch (opcode) | |
601 { | |
602 case Bplus: dval1 += dval2; break; | |
603 case Bdiff: dval1 -= dval2; break; | |
604 case Bmult: dval1 *= dval2; break; | |
605 case Bquo: | |
606 if (dval2 == 0) Fsignal (Qarith_error, Qnil); | |
607 dval1 /= dval2; | |
608 break; | |
609 case Bmax: if (dval1 < dval2) dval1 = dval2; break; | |
610 case Bmin: if (dval1 > dval2) dval1 = dval2; break; | |
611 } | |
612 return make_float (dval1); | |
613 } | |
1983 | 614 #endif /* WITH_NUMBER_TYPES */ |
428 | 615 } |
616 | |
617 | |
618 /* Read next uint8 from the instruction stream. */ | |
619 #define READ_UINT_1 ((unsigned int) (unsigned char) *program_ptr++) | |
620 | |
621 /* Read next uint16 from the instruction stream. */ | |
622 #define READ_UINT_2 \ | |
623 (program_ptr += 2, \ | |
624 (((unsigned int) (unsigned char) program_ptr[-1]) * 256 + \ | |
625 ((unsigned int) (unsigned char) program_ptr[-2]))) | |
626 | |
627 /* Read next int8 from the instruction stream. */ | |
628 #define READ_INT_1 ((int) (signed char) *program_ptr++) | |
629 | |
630 /* Read next int16 from the instruction stream. */ | |
631 #define READ_INT_2 \ | |
632 (program_ptr += 2, \ | |
633 (((int) ( signed char) program_ptr[-1]) * 256 + \ | |
634 ((int) (unsigned char) program_ptr[-2]))) | |
635 | |
636 /* Read next int8 from instruction stream; don't advance program_pointer */ | |
637 #define PEEK_INT_1 ((int) (signed char) program_ptr[0]) | |
638 | |
639 /* Read next int16 from instruction stream; don't advance program_pointer */ | |
640 #define PEEK_INT_2 \ | |
641 ((((int) ( signed char) program_ptr[1]) * 256) | \ | |
642 ((int) (unsigned char) program_ptr[0])) | |
643 | |
644 /* Do relative jumps from the current location. | |
645 We only do a QUIT if we jump backwards, for efficiency. | |
646 No infloops without backward jumps! */ | |
647 #define JUMP_RELATIVE(jump) do { \ | |
648 int JR_jump = (jump); \ | |
649 if (JR_jump < 0) QUIT; \ | |
650 program_ptr += JR_jump; \ | |
651 } while (0) | |
652 | |
653 #define JUMP JUMP_RELATIVE (PEEK_INT_2) | |
654 #define JUMPR JUMP_RELATIVE (PEEK_INT_1) | |
655 | |
656 #define JUMP_NEXT ((void) (program_ptr += 2)) | |
657 #define JUMPR_NEXT ((void) (program_ptr += 1)) | |
658 | |
659 /* Push x onto the execution stack. */ | |
660 #define PUSH(x) (*++stack_ptr = (x)) | |
661 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
662 /* Pop a value, which may be multiple, off the execution stack. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
663 #define POP_WITH_MULTIPLE_VALUES (*stack_ptr--) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
664 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
665 /* Pop a value off the execution stack, treating multiple values as single. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
666 #define POP (IGNORE_MULTIPLE_VALUES (POP_WITH_MULTIPLE_VALUES)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
667 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
668 #define DISCARD_PRESERVING_MULTIPLE_VALUES(n) (stack_ptr -= (n)) |
428 | 669 |
670 /* Discard n values from the execution stack. */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
671 #define DISCARD(n) do { \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
672 if (1 != multiple_value_current_limit) \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
673 { \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
674 int i, en = n; \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
675 for (i = 0; i < en; i++) \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
676 { \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
677 *stack_ptr = ignore_multiple_values (*stack_ptr); \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
678 stack_ptr--; \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
679 } \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
680 } \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
681 else \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
682 { \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
683 stack_ptr -= (n); \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
684 } \ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
685 } while (0) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
686 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
687 /* Get the value, which may be multiple, at the top of the execution stack; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
688 and leave it there. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
689 #define TOP_WITH_MULTIPLE_VALUES (*stack_ptr) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
690 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
691 #define TOP_ADDRESS (stack_ptr) |
428 | 692 |
693 /* Get the value which is at the top of the execution stack, | |
694 but don't pop it. */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
695 #define TOP (IGNORE_MULTIPLE_VALUES (TOP_WITH_MULTIPLE_VALUES)) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
696 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
697 #define TOP_LVALUE (*stack_ptr) |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
698 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
699 |
428 | 700 |
1920 | 701 /* See comment before the big switch in execute_optimized_program(). */ |
1884 | 702 #define GCPRO_STACK (gcpro1.nvars = stack_ptr - stack_beg) |
703 | |
428 | 704 /* The actual interpreter for byte code. |
705 This function has been seriously optimized for performance. | |
706 Don't change the constructs unless you are willing to do | |
707 real benchmarking and profiling work -- martin */ | |
708 | |
709 | |
814 | 710 Lisp_Object |
442 | 711 execute_optimized_program (const Opbyte *program, |
428 | 712 int stack_depth, |
713 Lisp_Object *constants_data) | |
714 { | |
715 /* This function can GC */ | |
442 | 716 REGISTER const Opbyte *program_ptr = (Opbyte *) program; |
1884 | 717 Lisp_Object *stack_beg = alloca_array (Lisp_Object, stack_depth + 1); |
718 REGISTER Lisp_Object *stack_ptr = stack_beg; | |
428 | 719 int speccount = specpdl_depth (); |
720 struct gcpro gcpro1; | |
721 | |
722 #ifdef BYTE_CODE_METER | |
723 Opcode this_opcode = 0; | |
724 Opcode prev_opcode; | |
725 #endif | |
726 | |
727 #ifdef ERROR_CHECK_BYTE_CODE | |
728 Lisp_Object *stack_end = stack_beg + stack_depth; | |
729 #endif | |
730 | |
1920 | 731 /* We used to GCPRO the whole interpreter stack before entering this while |
732 loop (21.5.14 and before), but that interferes with collection of weakly | |
733 referenced objects. Although strictly speaking there's no promise that | |
734 weak references will disappear by any given point in time, they should | |
735 be collected at the first opportunity. Waiting until exit from the | |
736 function caused test failures because "stale" objects "above" the top of | |
737 the stack were still GCPROed, and they were not getting collected until | |
738 after exit from the (byte-compiled) test! | |
739 | |
740 Now the idea is to dynamically adjust the array of GCPROed objects to | |
741 include only the "active" region of the stack. | |
742 | |
743 We use the "GCPRO1 the array base and set the nvars member" method. It | |
744 would be slightly inefficient but correct to use GCPRO1_ARRAY here. It | |
745 would just redundantly set nvars. | |
746 #### Maybe it would be clearer to use GCPRO1_ARRAY and do GCPRO_STACK | |
747 after the switch? | |
748 | |
749 GCPRO_STACK is something of a misnomer, because it suggests that a | |
750 struct gcpro is initialized each time. This is false; only the nvars | |
751 member of a single struct gcpro is being adjusted. This works because | |
752 each time a new object is assigned to a stack location, the old object | |
753 loses its reference and is effectively UNGCPROed, and the new object is | |
754 automatically GCPROed as long as nvars is correct. Only when we | |
755 return from the interpreter do we need to finalize the struct gcpro | |
756 itself, and that's done at case Breturn. | |
757 */ | |
428 | 758 GCPRO1 (stack_ptr[1]); |
1758 | 759 |
428 | 760 while (1) |
761 { | |
762 REGISTER Opcode opcode = (Opcode) READ_UINT_1; | |
1920 | 763 |
764 GCPRO_STACK; /* Get nvars right before maybe signaling. */ | |
428 | 765 #ifdef ERROR_CHECK_BYTE_CODE |
766 if (stack_ptr > stack_end) | |
563 | 767 stack_overflow ("byte code stack overflow", Qunbound); |
428 | 768 if (stack_ptr < stack_beg) |
563 | 769 stack_overflow ("byte code stack underflow", Qunbound); |
428 | 770 #endif |
771 | |
772 #ifdef BYTE_CODE_METER | |
773 prev_opcode = this_opcode; | |
774 this_opcode = opcode; | |
775 meter_code (prev_opcode, this_opcode); | |
776 #endif | |
777 | |
778 switch (opcode) | |
779 { | |
780 REGISTER int n; | |
781 | |
782 default: | |
783 if (opcode >= Bconstant) | |
784 PUSH (constants_data[opcode - Bconstant]); | |
785 else | |
1884 | 786 { |
787 /* We're not sure what these do, so better safe than sorry. */ | |
788 /* GCPRO_STACK; */ | |
789 stack_ptr = execute_rare_opcode (stack_ptr, program_ptr, opcode); | |
790 } | |
428 | 791 break; |
792 | |
793 case Bvarref: | |
794 case Bvarref+1: | |
795 case Bvarref+2: | |
796 case Bvarref+3: | |
797 case Bvarref+4: | |
798 case Bvarref+5: n = opcode - Bvarref; goto do_varref; | |
799 case Bvarref+7: n = READ_UINT_2; goto do_varref; | |
800 case Bvarref+6: n = READ_UINT_1; /* most common */ | |
801 do_varref: | |
802 { | |
803 Lisp_Object symbol = constants_data[n]; | |
804 Lisp_Object value = XSYMBOL (symbol)->value; | |
805 if (SYMBOL_VALUE_MAGIC_P (value)) | |
1920 | 806 /* I GCPRO_STACKed Fsymbol_value elsewhere, but I dunno why. */ |
807 /* GCPRO_STACK; */ | |
428 | 808 value = Fsymbol_value (symbol); |
809 PUSH (value); | |
810 break; | |
811 } | |
812 | |
813 case Bvarset: | |
814 case Bvarset+1: | |
815 case Bvarset+2: | |
816 case Bvarset+3: | |
817 case Bvarset+4: | |
818 case Bvarset+5: n = opcode - Bvarset; goto do_varset; | |
819 case Bvarset+7: n = READ_UINT_2; goto do_varset; | |
820 case Bvarset+6: n = READ_UINT_1; /* most common */ | |
821 do_varset: | |
822 { | |
823 Lisp_Object symbol = constants_data[n]; | |
440 | 824 Lisp_Symbol *symbol_ptr = XSYMBOL (symbol); |
428 | 825 Lisp_Object old_value = symbol_ptr->value; |
826 Lisp_Object new_value = POP; | |
1661 | 827 if (!SYMBOL_VALUE_MAGIC_P (old_value) || UNBOUNDP (old_value)) |
428 | 828 symbol_ptr->value = new_value; |
1884 | 829 else { |
830 /* Fset may call magic handlers */ | |
831 /* GCPRO_STACK; */ | |
428 | 832 Fset (symbol, new_value); |
1884 | 833 } |
834 | |
428 | 835 break; |
836 } | |
837 | |
838 case Bvarbind: | |
839 case Bvarbind+1: | |
840 case Bvarbind+2: | |
841 case Bvarbind+3: | |
842 case Bvarbind+4: | |
843 case Bvarbind+5: n = opcode - Bvarbind; goto do_varbind; | |
844 case Bvarbind+7: n = READ_UINT_2; goto do_varbind; | |
845 case Bvarbind+6: n = READ_UINT_1; /* most common */ | |
846 do_varbind: | |
847 { | |
848 Lisp_Object symbol = constants_data[n]; | |
440 | 849 Lisp_Symbol *symbol_ptr = XSYMBOL (symbol); |
428 | 850 Lisp_Object old_value = symbol_ptr->value; |
851 Lisp_Object new_value = POP; | |
852 if (!SYMBOL_VALUE_MAGIC_P (old_value) || UNBOUNDP (old_value)) | |
853 { | |
854 specpdl_ptr->symbol = symbol; | |
855 specpdl_ptr->old_value = old_value; | |
856 specpdl_ptr->func = 0; | |
857 specpdl_ptr++; | |
858 specpdl_depth_counter++; | |
859 | |
860 symbol_ptr->value = new_value; | |
853 | 861 |
862 #ifdef ERROR_CHECK_CATCH | |
863 check_specbind_stack_sanity (); | |
864 #endif | |
428 | 865 } |
866 else | |
1884 | 867 { |
868 /* does an Fset, may call magic handlers */ | |
869 /* GCPRO_STACK; */ | |
870 specbind_magic (symbol, new_value); | |
871 } | |
428 | 872 break; |
873 } | |
874 | |
875 case Bcall: | |
876 case Bcall+1: | |
877 case Bcall+2: | |
878 case Bcall+3: | |
879 case Bcall+4: | |
880 case Bcall+5: | |
881 case Bcall+6: | |
882 case Bcall+7: | |
883 n = (opcode < Bcall+6 ? opcode - Bcall : | |
884 opcode == Bcall+6 ? READ_UINT_1 : READ_UINT_2); | |
1920 | 885 /* #### Shouldn't this be just before the Ffuncall? |
886 Neither Fget nor Fput can GC. */ | |
1884 | 887 /* GCPRO_STACK; */ |
428 | 888 DISCARD (n); |
889 #ifdef BYTE_CODE_METER | |
890 if (byte_metering_on && SYMBOLP (TOP)) | |
891 { | |
892 Lisp_Object val = Fget (TOP, Qbyte_code_meter, Qnil); | |
893 if (INTP (val)) | |
894 Fput (TOP, Qbyte_code_meter, make_int (XINT (val) + 1)); | |
895 } | |
896 #endif | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
897 TOP_LVALUE = TOP; /* Ignore multiple values. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
898 TOP_LVALUE = Ffuncall (n + 1, TOP_ADDRESS); |
428 | 899 break; |
900 | |
901 case Bunbind: | |
902 case Bunbind+1: | |
903 case Bunbind+2: | |
904 case Bunbind+3: | |
905 case Bunbind+4: | |
906 case Bunbind+5: | |
907 case Bunbind+6: | |
908 case Bunbind+7: | |
909 UNBIND_TO (specpdl_depth() - | |
910 (opcode < Bunbind+6 ? opcode-Bunbind : | |
911 opcode == Bunbind+6 ? READ_UINT_1 : READ_UINT_2)); | |
912 break; | |
913 | |
914 | |
915 case Bgoto: | |
916 JUMP; | |
917 break; | |
918 | |
919 case Bgotoifnil: | |
920 if (NILP (POP)) | |
921 JUMP; | |
922 else | |
923 JUMP_NEXT; | |
924 break; | |
925 | |
926 case Bgotoifnonnil: | |
927 if (!NILP (POP)) | |
928 JUMP; | |
929 else | |
930 JUMP_NEXT; | |
931 break; | |
932 | |
933 case Bgotoifnilelsepop: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
934 /* Discard any multiple value: */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
935 if (NILP (TOP_LVALUE = TOP)) |
428 | 936 JUMP; |
937 else | |
938 { | |
939 DISCARD (1); | |
940 JUMP_NEXT; | |
941 } | |
942 break; | |
943 | |
944 case Bgotoifnonnilelsepop: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
945 /* Discard any multiple value: */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
946 if (!NILP (TOP_LVALUE = TOP)) |
428 | 947 JUMP; |
948 else | |
949 { | |
950 DISCARD (1); | |
951 JUMP_NEXT; | |
952 } | |
953 break; | |
954 | |
955 | |
956 case BRgoto: | |
957 JUMPR; | |
958 break; | |
959 | |
960 case BRgotoifnil: | |
961 if (NILP (POP)) | |
962 JUMPR; | |
963 else | |
964 JUMPR_NEXT; | |
965 break; | |
966 | |
967 case BRgotoifnonnil: | |
968 if (!NILP (POP)) | |
969 JUMPR; | |
970 else | |
971 JUMPR_NEXT; | |
972 break; | |
973 | |
974 case BRgotoifnilelsepop: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
975 if (NILP (TOP_LVALUE = TOP)) |
428 | 976 JUMPR; |
977 else | |
978 { | |
979 DISCARD (1); | |
980 JUMPR_NEXT; | |
981 } | |
982 break; | |
983 | |
984 case BRgotoifnonnilelsepop: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
985 if (!NILP (TOP_LVALUE = TOP)) |
428 | 986 JUMPR; |
987 else | |
988 { | |
989 DISCARD (1); | |
990 JUMPR_NEXT; | |
991 } | |
992 break; | |
993 | |
994 case Breturn: | |
995 UNGCPRO; | |
996 #ifdef ERROR_CHECK_BYTE_CODE | |
997 /* Binds and unbinds are supposed to be compiled balanced. */ | |
998 if (specpdl_depth() != speccount) | |
563 | 999 invalid_byte_code ("unbalanced specbinding stack", Qunbound); |
428 | 1000 #endif |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1001 return TOP_WITH_MULTIPLE_VALUES; |
428 | 1002 |
1003 case Bdiscard: | |
1004 DISCARD (1); | |
1005 break; | |
1006 | |
1007 case Bdup: | |
1008 { | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1009 Lisp_Object arg = TOP_WITH_MULTIPLE_VALUES; |
428 | 1010 PUSH (arg); |
1011 break; | |
1012 } | |
1013 | |
1014 case Bconstant2: | |
1015 PUSH (constants_data[READ_UINT_2]); | |
1016 break; | |
1017 | |
1018 case Bcar: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1019 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1020 /* Fcar can GC via wrong_type_argument. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1021 /* GCPRO_STACK; */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1022 Lisp_Object arg = TOP; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1023 TOP_LVALUE = CONSP (arg) ? XCAR (arg) : Fcar (arg); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1024 break; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1025 } |
428 | 1026 |
1027 case Bcdr: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1028 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1029 /* Fcdr can GC via wrong_type_argument. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1030 /* GCPRO_STACK; */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1031 Lisp_Object arg = TOP; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1032 TOP_LVALUE = CONSP (arg) ? XCDR (arg) : Fcdr (arg); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1033 break; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1034 } |
428 | 1035 |
1036 case Bunbind_all: | |
1037 /* To unbind back to the beginning of this frame. Not used yet, | |
1038 but will be needed for tail-recursion elimination. */ | |
771 | 1039 unbind_to (speccount); |
428 | 1040 break; |
1041 | |
1042 case Bnth: | |
1043 { | |
1044 Lisp_Object arg = POP; | |
1920 | 1045 /* Fcar and Fnthcdr can GC via wrong_type_argument. */ |
1046 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1047 TOP_LVALUE = Fcar (Fnthcdr (TOP, arg)); |
428 | 1048 break; |
1049 } | |
1050 | |
1051 case Bsymbolp: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1052 TOP_LVALUE = SYMBOLP (TOP) ? Qt : Qnil; |
428 | 1053 break; |
1054 | |
1055 case Bconsp: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1056 TOP_LVALUE = CONSP (TOP) ? Qt : Qnil; |
428 | 1057 break; |
1058 | |
1059 case Bstringp: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1060 TOP_LVALUE = STRINGP (TOP) ? Qt : Qnil; |
428 | 1061 break; |
1062 | |
1063 case Blistp: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1064 TOP_LVALUE = LISTP (TOP) ? Qt : Qnil; |
428 | 1065 break; |
1066 | |
1067 case Bnumberp: | |
1983 | 1068 #ifdef WITH_NUMBER_TYPES |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1069 TOP_LVALUE = NUMBERP (TOP) ? Qt : Qnil; |
1983 | 1070 #else |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1071 TOP_LVALUE = INT_OR_FLOATP (TOP) ? Qt : Qnil; |
1983 | 1072 #endif |
428 | 1073 break; |
1074 | |
1075 case Bintegerp: | |
1983 | 1076 #ifdef HAVE_BIGNUM |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1077 TOP_LVALUE = INTEGERP (TOP) ? Qt : Qnil; |
1983 | 1078 #else |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1079 TOP_LVALUE = INTP (TOP) ? Qt : Qnil; |
1983 | 1080 #endif |
428 | 1081 break; |
1082 | |
1083 case Beq: | |
1084 { | |
1085 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1086 TOP_LVALUE = EQ_WITH_EBOLA_NOTICE (TOP, arg) ? Qt : Qnil; |
428 | 1087 break; |
1088 } | |
1089 | |
1090 case Bnot: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1091 TOP_LVALUE = NILP (TOP) ? Qt : Qnil; |
428 | 1092 break; |
1093 | |
1094 case Bcons: | |
1095 { | |
1096 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1097 TOP_LVALUE = Fcons (TOP, arg); |
428 | 1098 break; |
1099 } | |
1100 | |
1101 case Blist1: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1102 TOP_LVALUE = Fcons (TOP, Qnil); |
428 | 1103 break; |
1104 | |
1105 | |
1106 case BlistN: | |
1107 n = READ_UINT_1; | |
1108 goto do_list; | |
1109 | |
1110 case Blist2: | |
1111 case Blist3: | |
1112 case Blist4: | |
1113 /* common case */ | |
1114 n = opcode - (Blist1 - 1); | |
1115 do_list: | |
1116 { | |
1117 Lisp_Object list = Qnil; | |
1118 list_loop: | |
1119 list = Fcons (TOP, list); | |
1120 if (--n) | |
1121 { | |
1122 DISCARD (1); | |
1123 goto list_loop; | |
1124 } | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1125 TOP_LVALUE = list; |
428 | 1126 break; |
1127 } | |
1128 | |
1129 | |
1130 case Bconcat2: | |
1131 case Bconcat3: | |
1132 case Bconcat4: | |
1133 n = opcode - (Bconcat2 - 2); | |
1134 goto do_concat; | |
1135 | |
1136 case BconcatN: | |
1137 /* common case */ | |
1138 n = READ_UINT_1; | |
1139 do_concat: | |
1140 DISCARD (n - 1); | |
1920 | 1141 /* Apparently `concat' can GC; Fconcat GCPROs its arguments. */ |
1142 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1143 TOP_LVALUE = TOP; /* Ignore multiple values. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1144 TOP_LVALUE = Fconcat (n, TOP_ADDRESS); |
428 | 1145 break; |
1146 | |
1147 | |
1148 case Blength: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1149 TOP_LVALUE = Flength (TOP); |
428 | 1150 break; |
1151 | |
1152 case Baset: | |
1153 { | |
1154 Lisp_Object arg2 = POP; | |
1155 Lisp_Object arg1 = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1156 TOP_LVALUE = Faset (TOP, arg1, arg2); |
428 | 1157 break; |
1158 } | |
1159 | |
1160 case Bsymbol_value: | |
1920 | 1161 /* Why does this need GCPRO_STACK? If not, remove others, too. */ |
1884 | 1162 /* GCPRO_STACK; */ |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1163 TOP_LVALUE = Fsymbol_value (TOP); |
428 | 1164 break; |
1165 | |
1166 case Bsymbol_function: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1167 TOP_LVALUE = Fsymbol_function (TOP); |
428 | 1168 break; |
1169 | |
1170 case Bget: | |
1171 { | |
1172 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1173 TOP_LVALUE = Fget (TOP, arg, Qnil); |
428 | 1174 break; |
1175 } | |
1176 | |
1177 case Bsub1: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1178 { |
1983 | 1179 #ifdef HAVE_BIGNUM |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1180 TOP_LVALUE = Fsub1 (TOP); |
1983 | 1181 #else |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1182 Lisp_Object arg = TOP; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1183 TOP_LVALUE = INTP (arg) ? INT_MINUS1 (arg) : Fsub1 (arg); |
1983 | 1184 #endif |
428 | 1185 break; |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1186 } |
428 | 1187 case Badd1: |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1188 { |
1983 | 1189 #ifdef HAVE_BIGNUM |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1190 TOP_LVALUE = Fadd1 (TOP); |
1983 | 1191 #else |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1192 Lisp_Object arg = TOP; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1193 TOP_LVALUE = INTP (arg) ? INT_PLUS1 (arg) : Fadd1 (arg); |
1983 | 1194 #endif |
428 | 1195 break; |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1196 } |
428 | 1197 |
1198 case Beqlsign: | |
1199 { | |
1200 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1201 TOP_LVALUE = bytecode_arithcompare (TOP, arg) == 0 ? Qt : Qnil; |
428 | 1202 break; |
1203 } | |
1204 | |
1205 case Bgtr: | |
1206 { | |
1207 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1208 TOP_LVALUE = bytecode_arithcompare (TOP, arg) > 0 ? Qt : Qnil; |
428 | 1209 break; |
1210 } | |
1211 | |
1212 case Blss: | |
1213 { | |
1214 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1215 TOP_LVALUE = bytecode_arithcompare (TOP, arg) < 0 ? Qt : Qnil; |
428 | 1216 break; |
1217 } | |
1218 | |
1219 case Bleq: | |
1220 { | |
1221 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1222 TOP_LVALUE = bytecode_arithcompare (TOP, arg) <= 0 ? Qt : Qnil; |
428 | 1223 break; |
1224 } | |
1225 | |
1226 case Bgeq: | |
1227 { | |
1228 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1229 TOP_LVALUE = bytecode_arithcompare (TOP, arg) >= 0 ? Qt : Qnil; |
428 | 1230 break; |
1231 } | |
1232 | |
1233 | |
1234 case Bnegate: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1235 TOP_LVALUE = bytecode_negate (TOP); |
428 | 1236 break; |
1237 | |
1238 case Bnconc: | |
1239 DISCARD (1); | |
1920 | 1240 /* nconc2 GCPROs before calling this. */ |
1241 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1242 TOP_LVALUE = TOP; /* Ignore multiple values. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1243 TOP_LVALUE = bytecode_nconc2 (TOP_ADDRESS); |
428 | 1244 break; |
1245 | |
1246 case Bplus: | |
1247 { | |
1248 Lisp_Object arg2 = POP; | |
1249 Lisp_Object arg1 = TOP; | |
1983 | 1250 #ifdef HAVE_BIGNUM |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1251 TOP_LVALUE = bytecode_arithop (arg1, arg2, opcode); |
1983 | 1252 #else |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1253 TOP_LVALUE = INTP (arg1) && INTP (arg2) ? |
428 | 1254 INT_PLUS (arg1, arg2) : |
1255 bytecode_arithop (arg1, arg2, opcode); | |
1983 | 1256 #endif |
428 | 1257 break; |
1258 } | |
1259 | |
1260 case Bdiff: | |
1261 { | |
1262 Lisp_Object arg2 = POP; | |
1263 Lisp_Object arg1 = TOP; | |
1983 | 1264 #ifdef HAVE_BIGNUM |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1265 TOP_LVALUE = bytecode_arithop (arg1, arg2, opcode); |
1983 | 1266 #else |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1267 TOP_LVALUE = INTP (arg1) && INTP (arg2) ? |
428 | 1268 INT_MINUS (arg1, arg2) : |
1269 bytecode_arithop (arg1, arg2, opcode); | |
1983 | 1270 #endif |
428 | 1271 break; |
1272 } | |
1273 | |
1274 case Bmult: | |
1275 case Bquo: | |
1276 case Bmax: | |
1277 case Bmin: | |
1278 { | |
1279 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1280 TOP_LVALUE = bytecode_arithop (TOP, arg, opcode); |
428 | 1281 break; |
1282 } | |
1283 | |
1284 case Bpoint: | |
1285 PUSH (make_int (BUF_PT (current_buffer))); | |
1286 break; | |
1287 | |
1288 case Binsert: | |
1920 | 1289 /* Says it can GC. */ |
1290 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1291 TOP_LVALUE = TOP; /* Ignore multiple values. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1292 TOP_LVALUE = Finsert (1, TOP_ADDRESS); |
428 | 1293 break; |
1294 | |
1295 case BinsertN: | |
1296 n = READ_UINT_1; | |
1297 DISCARD (n - 1); | |
1920 | 1298 /* See Binsert. */ |
1299 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1300 TOP_LVALUE = TOP; /* Ignore multiple values. */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1301 TOP_LVALUE = Finsert (n, TOP_ADDRESS); |
428 | 1302 break; |
1303 | |
1304 case Baref: | |
1305 { | |
1306 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1307 TOP_LVALUE = Faref (TOP, arg); |
428 | 1308 break; |
1309 } | |
1310 | |
1311 case Bmemq: | |
1312 { | |
1313 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1314 TOP_LVALUE = Fmemq (TOP, arg); |
428 | 1315 break; |
1316 } | |
1317 | |
1318 case Bset: | |
1319 { | |
1320 Lisp_Object arg = POP; | |
1884 | 1321 /* Fset may call magic handlers */ |
1322 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1323 TOP_LVALUE = Fset (TOP, arg); |
428 | 1324 break; |
1325 } | |
1326 | |
1327 case Bequal: | |
1328 { | |
1329 Lisp_Object arg = POP; | |
1920 | 1330 /* Can QUIT, so can GC, right? */ |
1331 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1332 TOP_LVALUE = Fequal (TOP, arg); |
428 | 1333 break; |
1334 } | |
1335 | |
1336 case Bnthcdr: | |
1337 { | |
1338 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1339 TOP_LVALUE = Fnthcdr (TOP, arg); |
428 | 1340 break; |
1341 } | |
1342 | |
1343 case Belt: | |
1344 { | |
1345 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1346 TOP_LVALUE = Felt (TOP, arg); |
428 | 1347 break; |
1348 } | |
1349 | |
1350 case Bmember: | |
1351 { | |
1352 Lisp_Object arg = POP; | |
1920 | 1353 /* Can QUIT, so can GC, right? */ |
1354 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1355 TOP_LVALUE = Fmember (TOP, arg); |
428 | 1356 break; |
1357 } | |
1358 | |
1359 case Bgoto_char: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1360 TOP_LVALUE = Fgoto_char (TOP, Qnil); |
428 | 1361 break; |
1362 | |
1363 case Bcurrent_buffer: | |
1364 { | |
793 | 1365 Lisp_Object buffer = wrap_buffer (current_buffer); |
1366 | |
428 | 1367 PUSH (buffer); |
1368 break; | |
1369 } | |
1370 | |
1371 case Bset_buffer: | |
1884 | 1372 /* #### WAG: set-buffer may cause Fset's of buffer locals |
1373 Didn't prevent crash. :-( */ | |
1374 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1375 TOP_LVALUE = Fset_buffer (TOP); |
428 | 1376 break; |
1377 | |
1378 case Bpoint_max: | |
1379 PUSH (make_int (BUF_ZV (current_buffer))); | |
1380 break; | |
1381 | |
1382 case Bpoint_min: | |
1383 PUSH (make_int (BUF_BEGV (current_buffer))); | |
1384 break; | |
1385 | |
1386 case Bskip_chars_forward: | |
1387 { | |
1388 Lisp_Object arg = POP; | |
1920 | 1389 /* Can QUIT, so can GC, right? */ |
1390 /* GCPRO_STACK; */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1391 TOP_LVALUE = Fskip_chars_forward (TOP, arg, Qnil); |
428 | 1392 break; |
1393 } | |
1394 | |
1395 case Bassq: | |
1396 { | |
1397 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1398 TOP_LVALUE = Fassq (TOP, arg); |
428 | 1399 break; |
1400 } | |
1401 | |
1402 case Bsetcar: | |
1403 { | |
1404 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1405 TOP_LVALUE = Fsetcar (TOP, arg); |
428 | 1406 break; |
1407 } | |
1408 | |
1409 case Bsetcdr: | |
1410 { | |
1411 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1412 TOP_LVALUE = Fsetcdr (TOP, arg); |
428 | 1413 break; |
1414 } | |
1415 | |
1416 case Bnreverse: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1417 TOP_LVALUE = bytecode_nreverse (TOP); |
428 | 1418 break; |
1419 | |
1420 case Bcar_safe: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1421 TOP_LVALUE = CONSP (TOP) ? XCAR (TOP) : Qnil; |
428 | 1422 break; |
1423 | |
1424 case Bcdr_safe: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1425 TOP_LVALUE = CONSP (TOP) ? XCDR (TOP) : Qnil; |
428 | 1426 break; |
1427 | |
1428 } | |
1429 } | |
1430 } | |
1431 | |
1432 /* It makes a worthwhile performance difference (5%) to shunt | |
1433 lesser-used opcodes off to a subroutine, to keep the switch in | |
1434 execute_optimized_program small. If you REALLY care about | |
1435 performance, you want to keep your heavily executed code away from | |
1436 rarely executed code, to minimize cache misses. | |
1437 | |
1438 Don't make this function static, since then the compiler might inline it. */ | |
1439 Lisp_Object * | |
1440 execute_rare_opcode (Lisp_Object *stack_ptr, | |
2286 | 1441 const Opbyte *UNUSED (program_ptr), |
428 | 1442 Opcode opcode) |
1443 { | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1444 REGISTER int n; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1445 |
428 | 1446 switch (opcode) |
1447 { | |
1448 | |
1449 case Bsave_excursion: | |
1450 record_unwind_protect (save_excursion_restore, | |
1451 save_excursion_save ()); | |
1452 break; | |
1453 | |
1454 case Bsave_window_excursion: | |
1455 { | |
1456 int count = specpdl_depth (); | |
1457 record_unwind_protect (save_window_excursion_unwind, | |
1149 | 1458 call1 (Qcurrent_window_configuration, Qnil)); |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1459 TOP_LVALUE = Fprogn (TOP); |
771 | 1460 unbind_to (count); |
428 | 1461 break; |
1462 } | |
1463 | |
1464 case Bsave_restriction: | |
1465 record_unwind_protect (save_restriction_restore, | |
844 | 1466 save_restriction_save (current_buffer)); |
428 | 1467 break; |
1468 | |
1469 case Bcatch: | |
1470 { | |
1471 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1472 TOP_LVALUE = internal_catch (TOP, Feval, arg, 0, 0, 0); |
428 | 1473 break; |
1474 } | |
1475 | |
1476 case Bskip_chars_backward: | |
1477 { | |
1478 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1479 TOP_LVALUE = Fskip_chars_backward (TOP, arg, Qnil); |
428 | 1480 break; |
1481 } | |
1482 | |
1483 case Bunwind_protect: | |
1484 record_unwind_protect (Fprogn, POP); | |
1485 break; | |
1486 | |
1487 case Bcondition_case: | |
1488 { | |
1489 Lisp_Object arg2 = POP; /* handlers */ | |
1490 Lisp_Object arg1 = POP; /* bodyform */ | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1491 TOP_LVALUE = condition_case_3 (arg1, TOP, arg2); |
428 | 1492 break; |
1493 } | |
1494 | |
1495 case Bset_marker: | |
1496 { | |
1497 Lisp_Object arg2 = POP; | |
1498 Lisp_Object arg1 = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1499 TOP_LVALUE = Fset_marker (TOP, arg1, arg2); |
428 | 1500 break; |
1501 } | |
1502 | |
1503 case Brem: | |
1504 { | |
1505 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1506 TOP_LVALUE = Frem (TOP, arg); |
428 | 1507 break; |
1508 } | |
1509 | |
1510 case Bmatch_beginning: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1511 TOP_LVALUE = Fmatch_beginning (TOP); |
428 | 1512 break; |
1513 | |
1514 case Bmatch_end: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1515 TOP_LVALUE = Fmatch_end (TOP); |
428 | 1516 break; |
1517 | |
1518 case Bupcase: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1519 TOP_LVALUE = Fupcase (TOP, Qnil); |
428 | 1520 break; |
1521 | |
1522 case Bdowncase: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1523 TOP_LVALUE = Fdowncase (TOP, Qnil); |
428 | 1524 break; |
1525 | |
1526 case Bfset: | |
1527 { | |
1528 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1529 TOP_LVALUE = Ffset (TOP, arg); |
428 | 1530 break; |
1531 } | |
1532 | |
1533 case Bstring_equal: | |
1534 { | |
1535 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1536 TOP_LVALUE = Fstring_equal (TOP, arg); |
428 | 1537 break; |
1538 } | |
1539 | |
1540 case Bstring_lessp: | |
1541 { | |
1542 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1543 TOP_LVALUE = Fstring_lessp (TOP, arg); |
428 | 1544 break; |
1545 } | |
1546 | |
1547 case Bsubstring: | |
1548 { | |
1549 Lisp_Object arg2 = POP; | |
1550 Lisp_Object arg1 = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1551 TOP_LVALUE = Fsubstring (TOP, arg1, arg2); |
428 | 1552 break; |
1553 } | |
1554 | |
1555 case Bcurrent_column: | |
1556 PUSH (make_int (current_column (current_buffer))); | |
1557 break; | |
1558 | |
1559 case Bchar_after: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1560 TOP_LVALUE = Fchar_after (TOP, Qnil); |
428 | 1561 break; |
1562 | |
1563 case Bindent_to: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1564 TOP_LVALUE = Findent_to (TOP, Qnil, Qnil); |
428 | 1565 break; |
1566 | |
1567 case Bwiden: | |
1568 PUSH (Fwiden (Qnil)); | |
1569 break; | |
1570 | |
1571 case Bfollowing_char: | |
1572 PUSH (Ffollowing_char (Qnil)); | |
1573 break; | |
1574 | |
1575 case Bpreceding_char: | |
1576 PUSH (Fpreceding_char (Qnil)); | |
1577 break; | |
1578 | |
1579 case Beolp: | |
1580 PUSH (Feolp (Qnil)); | |
1581 break; | |
1582 | |
1583 case Beobp: | |
1584 PUSH (Feobp (Qnil)); | |
1585 break; | |
1586 | |
1587 case Bbolp: | |
1588 PUSH (Fbolp (Qnil)); | |
1589 break; | |
1590 | |
1591 case Bbobp: | |
1592 PUSH (Fbobp (Qnil)); | |
1593 break; | |
1594 | |
1595 case Bsave_current_buffer: | |
1596 record_unwind_protect (save_current_buffer_restore, | |
1597 Fcurrent_buffer ()); | |
1598 break; | |
1599 | |
1600 case Binteractive_p: | |
1601 PUSH (Finteractive_p ()); | |
1602 break; | |
1603 | |
1604 case Bforward_char: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1605 TOP_LVALUE = Fforward_char (TOP, Qnil); |
428 | 1606 break; |
1607 | |
1608 case Bforward_word: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1609 TOP_LVALUE = Fforward_word (TOP, Qnil); |
428 | 1610 break; |
1611 | |
1612 case Bforward_line: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1613 TOP_LVALUE = Fforward_line (TOP, Qnil); |
428 | 1614 break; |
1615 | |
1616 case Bchar_syntax: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1617 TOP_LVALUE = Fchar_syntax (TOP, Qnil); |
428 | 1618 break; |
1619 | |
1620 case Bbuffer_substring: | |
1621 { | |
1622 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1623 TOP_LVALUE = Fbuffer_substring (TOP, arg, Qnil); |
428 | 1624 break; |
1625 } | |
1626 | |
1627 case Bdelete_region: | |
1628 { | |
1629 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1630 TOP_LVALUE = Fdelete_region (TOP, arg, Qnil); |
428 | 1631 break; |
1632 } | |
1633 | |
1634 case Bnarrow_to_region: | |
1635 { | |
1636 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1637 TOP_LVALUE = Fnarrow_to_region (TOP, arg, Qnil); |
428 | 1638 break; |
1639 } | |
1640 | |
1641 case Bend_of_line: | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1642 TOP_LVALUE = Fend_of_line (TOP, Qnil); |
428 | 1643 break; |
1644 | |
1645 case Btemp_output_buffer_setup: | |
1646 temp_output_buffer_setup (TOP); | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1647 TOP_LVALUE = Vstandard_output; |
428 | 1648 break; |
1649 | |
1650 case Btemp_output_buffer_show: | |
1651 { | |
1652 Lisp_Object arg = POP; | |
1653 temp_output_buffer_show (TOP, Qnil); | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1654 TOP_LVALUE = arg; |
428 | 1655 /* GAG ME!! */ |
1656 /* pop binding of standard-output */ | |
771 | 1657 unbind_to (specpdl_depth() - 1); |
428 | 1658 break; |
1659 } | |
1660 | |
1661 case Bold_eq: | |
1662 { | |
1663 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1664 TOP_LVALUE = HACKEQ_UNSAFE (TOP, arg) ? Qt : Qnil; |
428 | 1665 break; |
1666 } | |
1667 | |
1668 case Bold_memq: | |
1669 { | |
1670 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1671 TOP_LVALUE = Fold_memq (TOP, arg); |
428 | 1672 break; |
1673 } | |
1674 | |
1675 case Bold_equal: | |
1676 { | |
1677 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1678 TOP_LVALUE = Fold_equal (TOP, arg); |
428 | 1679 break; |
1680 } | |
1681 | |
1682 case Bold_member: | |
1683 { | |
1684 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1685 TOP_LVALUE = Fold_member (TOP, arg); |
428 | 1686 break; |
1687 } | |
1688 | |
1689 case Bold_assq: | |
1690 { | |
1691 Lisp_Object arg = POP; | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1692 TOP_LVALUE = Fold_assq (TOP, arg); |
428 | 1693 break; |
1694 } | |
1695 | |
4677
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1696 case Bbind_multiple_value_limits: |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1697 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1698 Lisp_Object upper = POP, first = TOP, speccount; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1699 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1700 CHECK_NATNUM (upper); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1701 CHECK_NATNUM (first); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1702 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1703 speccount = make_int (bind_multiple_value_limits (XINT (first), |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1704 XINT (upper))); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1705 PUSH (upper); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1706 PUSH (speccount); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1707 break; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1708 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1709 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1710 case Bmultiple_value_call: |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1711 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1712 n = XINT (POP); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1713 DISCARD_PRESERVING_MULTIPLE_VALUES (n - 1); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1714 /* Discard multiple values for the first (function) argument: */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1715 TOP_LVALUE = TOP; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1716 TOP_LVALUE = multiple_value_call (n, TOP_ADDRESS); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1717 break; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1718 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1719 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1720 case Bmultiple_value_list_internal: |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1721 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1722 DISCARD_PRESERVING_MULTIPLE_VALUES (3); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1723 TOP_LVALUE = multiple_value_list_internal (4, TOP_ADDRESS); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1724 break; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1725 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1726 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1727 case Bthrow: |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1728 { |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1729 Lisp_Object arg = POP_WITH_MULTIPLE_VALUES; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1730 |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1731 /* We never throw to a catch tag that is a multiple value: */ |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1732 throw_or_bomb_out (TOP, arg, 0, Qnil, Qnil); |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1733 break; |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1734 } |
8f1ee2d15784
Support full Common Lisp multiple values in C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
3263
diff
changeset
|
1735 |
428 | 1736 default: |
2500 | 1737 ABORT(); |
428 | 1738 break; |
1739 } | |
1740 return stack_ptr; | |
1741 } | |
1742 | |
1743 | |
563 | 1744 DOESNT_RETURN |
867 | 1745 invalid_byte_code (const CIbyte *reason, Lisp_Object frob) |
428 | 1746 { |
563 | 1747 signal_error (Qinvalid_byte_code, reason, frob); |
428 | 1748 } |
1749 | |
1750 /* Check for valid opcodes. Change this when adding new opcodes. */ | |
1751 static void | |
1752 check_opcode (Opcode opcode) | |
1753 { | |
1754 if ((opcode < Bvarref) || | |
1755 (opcode == 0251) || | |
1756 (opcode > Bassq && opcode < Bconstant)) | |
563 | 1757 invalid_byte_code ("invalid opcode in instruction stream", |
1758 make_int (opcode)); | |
428 | 1759 } |
1760 | |
1761 /* Check that IDX is a valid offset into the `constants' vector */ | |
1762 static void | |
1763 check_constants_index (int idx, Lisp_Object constants) | |
1764 { | |
1765 if (idx < 0 || idx >= XVECTOR_LENGTH (constants)) | |
563 | 1766 signal_ferror |
1767 (Qinvalid_byte_code, | |
1768 "reference %d to constants array out of range 0, %ld", | |
428 | 1769 idx, XVECTOR_LENGTH (constants) - 1); |
1770 } | |
1771 | |
1772 /* Get next character from Lisp instructions string. */ | |
563 | 1773 #define READ_INSTRUCTION_CHAR(lvalue) do { \ |
867 | 1774 (lvalue) = itext_ichar (ptr); \ |
1775 INC_IBYTEPTR (ptr); \ | |
563 | 1776 *icounts_ptr++ = program_ptr - program; \ |
1777 if (lvalue > UCHAR_MAX) \ | |
1778 invalid_byte_code \ | |
1779 ("Invalid character in byte code string", make_char (lvalue)); \ | |
428 | 1780 } while (0) |
1781 | |
1782 /* Get opcode from Lisp instructions string. */ | |
1783 #define READ_OPCODE do { \ | |
1784 unsigned int c; \ | |
1785 READ_INSTRUCTION_CHAR (c); \ | |
1786 opcode = (Opcode) c; \ | |
1787 } while (0) | |
1788 | |
1789 /* Get next operand, a uint8, from Lisp instructions string. */ | |
1790 #define READ_OPERAND_1 do { \ | |
1791 READ_INSTRUCTION_CHAR (arg); \ | |
1792 argsize = 1; \ | |
1793 } while (0) | |
1794 | |
1795 /* Get next operand, a uint16, from Lisp instructions string. */ | |
1796 #define READ_OPERAND_2 do { \ | |
1797 unsigned int arg1, arg2; \ | |
1798 READ_INSTRUCTION_CHAR (arg1); \ | |
1799 READ_INSTRUCTION_CHAR (arg2); \ | |
1800 arg = arg1 + (arg2 << 8); \ | |
1801 argsize = 2; \ | |
1802 } while (0) | |
1803 | |
1804 /* Write 1 byte to PTR, incrementing PTR */ | |
1805 #define WRITE_INT8(value, ptr) do { \ | |
1806 *((ptr)++) = (value); \ | |
1807 } while (0) | |
1808 | |
1809 /* Write 2 bytes to PTR, incrementing PTR */ | |
1810 #define WRITE_INT16(value, ptr) do { \ | |
1811 WRITE_INT8 (((unsigned) (value)) & 0x00ff, (ptr)); \ | |
1812 WRITE_INT8 (((unsigned) (value)) >> 8 , (ptr)); \ | |
1813 } while (0) | |
1814 | |
1815 /* We've changed our minds about the opcode we've already written. */ | |
1816 #define REWRITE_OPCODE(new_opcode) ((void) (program_ptr[-1] = new_opcode)) | |
1817 | |
1818 /* Encode an op arg within the opcode, or as a 1 or 2-byte operand. */ | |
1819 #define WRITE_NARGS(base_opcode) do { \ | |
1820 if (arg <= 5) \ | |
1821 { \ | |
1822 REWRITE_OPCODE (base_opcode + arg); \ | |
1823 } \ | |
1824 else if (arg <= UCHAR_MAX) \ | |
1825 { \ | |
1826 REWRITE_OPCODE (base_opcode + 6); \ | |
1827 WRITE_INT8 (arg, program_ptr); \ | |
1828 } \ | |
1829 else \ | |
1830 { \ | |
1831 REWRITE_OPCODE (base_opcode + 7); \ | |
1832 WRITE_INT16 (arg, program_ptr); \ | |
1833 } \ | |
1834 } while (0) | |
1835 | |
1836 /* Encode a constants reference within the opcode, or as a 2-byte operand. */ | |
1837 #define WRITE_CONSTANT do { \ | |
1838 check_constants_index(arg, constants); \ | |
1839 if (arg <= UCHAR_MAX - Bconstant) \ | |
1840 { \ | |
1841 REWRITE_OPCODE (Bconstant + arg); \ | |
1842 } \ | |
1843 else \ | |
1844 { \ | |
1845 REWRITE_OPCODE (Bconstant2); \ | |
1846 WRITE_INT16 (arg, program_ptr); \ | |
1847 } \ | |
1848 } while (0) | |
1849 | |
1850 #define WRITE_OPCODE WRITE_INT8 (opcode, program_ptr) | |
1851 | |
1852 /* Compile byte code instructions into free space provided by caller, with | |
1853 size >= (2 * string_char_length (instructions) + 1) * sizeof (Opbyte). | |
1854 Returns length of compiled code. */ | |
1855 static void | |
1856 optimize_byte_code (/* in */ | |
1857 Lisp_Object instructions, | |
1858 Lisp_Object constants, | |
1859 /* out */ | |
442 | 1860 Opbyte * const program, |
1861 int * const program_length, | |
1862 int * const varbind_count) | |
428 | 1863 { |
647 | 1864 Bytecount instructions_length = XSTRING_LENGTH (instructions); |
665 | 1865 Elemcount comfy_size = (Elemcount) (2 * instructions_length); |
428 | 1866 |
442 | 1867 int * const icounts = alloca_array (int, comfy_size); |
428 | 1868 int * icounts_ptr = icounts; |
1869 | |
1870 /* We maintain a table of jumps in the source code. */ | |
1871 struct jump | |
1872 { | |
1873 int from; | |
1874 int to; | |
1875 }; | |
442 | 1876 struct jump * const jumps = alloca_array (struct jump, comfy_size); |
428 | 1877 struct jump *jumps_ptr = jumps; |
1878 | |
1879 Opbyte *program_ptr = program; | |
1880 | |
867 | 1881 const Ibyte *ptr = XSTRING_DATA (instructions); |
1882 const Ibyte * const end = ptr + instructions_length; | |
428 | 1883 |
1884 *varbind_count = 0; | |
1885 | |
1886 while (ptr < end) | |
1887 { | |
1888 Opcode opcode; | |
1889 int arg; | |
1890 int argsize = 0; | |
1891 READ_OPCODE; | |
1892 WRITE_OPCODE; | |
1893 | |
1894 switch (opcode) | |
1895 { | |
1896 Lisp_Object val; | |
1897 | |
1898 case Bvarref+7: READ_OPERAND_2; goto do_varref; | |
1899 case Bvarref+6: READ_OPERAND_1; goto do_varref; | |
1900 case Bvarref: case Bvarref+1: case Bvarref+2: | |
1901 case Bvarref+3: case Bvarref+4: case Bvarref+5: | |
1902 arg = opcode - Bvarref; | |
1903 do_varref: | |
1904 check_constants_index (arg, constants); | |
1905 val = XVECTOR_DATA (constants) [arg]; | |
1906 if (!SYMBOLP (val)) | |
563 | 1907 invalid_byte_code ("variable reference to non-symbol", val); |
428 | 1908 if (EQ (val, Qnil) || EQ (val, Qt) || (SYMBOL_IS_KEYWORD (val))) |
563 | 1909 invalid_byte_code ("variable reference to constant symbol", val); |
428 | 1910 WRITE_NARGS (Bvarref); |
1911 break; | |
1912 | |
1913 case Bvarset+7: READ_OPERAND_2; goto do_varset; | |
1914 case Bvarset+6: READ_OPERAND_1; goto do_varset; | |
1915 case Bvarset: case Bvarset+1: case Bvarset+2: | |
1916 case Bvarset+3: case Bvarset+4: case Bvarset+5: | |
1917 arg = opcode - Bvarset; | |
1918 do_varset: | |
1919 check_constants_index (arg, constants); | |
1920 val = XVECTOR_DATA (constants) [arg]; | |
1921 if (!SYMBOLP (val)) | |
563 | 1922 wtaerror ("attempt to set non-symbol", val); |
428 | 1923 if (EQ (val, Qnil) || EQ (val, Qt)) |
563 | 1924 signal_error (Qsetting_constant, 0, val); |
428 | 1925 /* Ignore assignments to keywords by converting to Bdiscard. |
1926 For backward compatibility only - we'd like to make this an error. */ | |
1927 if (SYMBOL_IS_KEYWORD (val)) | |
1928 REWRITE_OPCODE (Bdiscard); | |
1929 else | |
1930 WRITE_NARGS (Bvarset); | |
1931 break; | |
1932 | |
1933 case Bvarbind+7: READ_OPERAND_2; goto do_varbind; | |
1934 case Bvarbind+6: READ_OPERAND_1; goto do_varbind; | |
1935 case Bvarbind: case Bvarbind+1: case Bvarbind+2: | |
1936 case Bvarbind+3: case Bvarbind+4: case Bvarbind+5: | |
1937 arg = opcode - Bvarbind; | |
1938 do_varbind: | |
1939 (*varbind_count)++; | |
1940 check_constants_index (arg, constants); | |
1941 val = XVECTOR_DATA (constants) [arg]; | |
1942 if (!SYMBOLP (val)) | |
563 | 1943 wtaerror ("attempt to let-bind non-symbol", val); |
428 | 1944 if (EQ (val, Qnil) || EQ (val, Qt) || (SYMBOL_IS_KEYWORD (val))) |
563 | 1945 signal_error (Qsetting_constant, |
1946 "attempt to let-bind constant symbol", val); | |
428 | 1947 WRITE_NARGS (Bvarbind); |
1948 break; | |
1949 | |
1950 case Bcall+7: READ_OPERAND_2; goto do_call; | |
1951 case Bcall+6: READ_OPERAND_1; goto do_call; | |
1952 case Bcall: case Bcall+1: case Bcall+2: | |
1953 case Bcall+3: case Bcall+4: case Bcall+5: | |
1954 arg = opcode - Bcall; | |
1955 do_call: | |
1956 WRITE_NARGS (Bcall); | |
1957 break; | |
1958 | |
1959 case Bunbind+7: READ_OPERAND_2; goto do_unbind; | |
1960 case Bunbind+6: READ_OPERAND_1; goto do_unbind; | |
1961 case Bunbind: case Bunbind+1: case Bunbind+2: | |
1962 case Bunbind+3: case Bunbind+4: case Bunbind+5: | |
1963 arg = opcode - Bunbind; | |
1964 do_unbind: | |
1965 WRITE_NARGS (Bunbind); | |
1966 break; | |
1967 | |
1968 case Bgoto: | |
1969 case Bgotoifnil: | |
1970 case Bgotoifnonnil: | |
1971 case Bgotoifnilelsepop: | |
1972 case Bgotoifnonnilelsepop: | |
1973 READ_OPERAND_2; | |
1974 /* Make program_ptr-relative */ | |
1975 arg += icounts - (icounts_ptr - argsize); | |
1976 goto do_jump; | |
1977 | |
1978 case BRgoto: | |
1979 case BRgotoifnil: | |
1980 case BRgotoifnonnil: | |
1981 case BRgotoifnilelsepop: | |
1982 case BRgotoifnonnilelsepop: | |
1983 READ_OPERAND_1; | |
1984 /* Make program_ptr-relative */ | |
1985 arg -= 127; | |
1986 do_jump: | |
1987 /* Record program-relative goto addresses in `jumps' table */ | |
1988 jumps_ptr->from = icounts_ptr - icounts - argsize; | |
1989 jumps_ptr->to = jumps_ptr->from + arg; | |
1990 jumps_ptr++; | |
1991 if (arg >= -1 && arg <= argsize) | |
563 | 1992 invalid_byte_code ("goto instruction is its own target", Qunbound); |
428 | 1993 if (arg <= SCHAR_MIN || |
1994 arg > SCHAR_MAX) | |
1995 { | |
1996 if (argsize == 1) | |
1997 REWRITE_OPCODE (opcode + Bgoto - BRgoto); | |
1998 WRITE_INT16 (arg, program_ptr); | |
1999 } | |
2000 else | |
2001 { | |
2002 if (argsize == 2) | |
2003 REWRITE_OPCODE (opcode + BRgoto - Bgoto); | |
2004 WRITE_INT8 (arg, program_ptr); | |
2005 } | |
2006 break; | |
2007 | |
2008 case Bconstant2: | |
2009 READ_OPERAND_2; | |
2010 WRITE_CONSTANT; | |
2011 break; | |
2012 | |
2013 case BlistN: | |
2014 case BconcatN: | |
2015 case BinsertN: | |
2016 READ_OPERAND_1; | |
2017 WRITE_INT8 (arg, program_ptr); | |
2018 break; | |
2019 | |
2020 default: | |
2021 if (opcode < Bconstant) | |
2022 check_opcode (opcode); | |
2023 else | |
2024 { | |
2025 arg = opcode - Bconstant; | |
2026 WRITE_CONSTANT; | |
2027 } | |
2028 break; | |
2029 } | |
2030 } | |
2031 | |
2032 /* Fix up jumps table to refer to NEW offsets. */ | |
2033 { | |
2034 struct jump *j; | |
2035 for (j = jumps; j < jumps_ptr; j++) | |
2036 { | |
2037 #ifdef ERROR_CHECK_BYTE_CODE | |
2038 assert (j->from < icounts_ptr - icounts); | |
2039 assert (j->to < icounts_ptr - icounts); | |
2040 #endif | |
2041 j->from = icounts[j->from]; | |
2042 j->to = icounts[j->to]; | |
2043 #ifdef ERROR_CHECK_BYTE_CODE | |
2044 assert (j->from < program_ptr - program); | |
2045 assert (j->to < program_ptr - program); | |
2046 check_opcode ((Opcode) (program[j->from-1])); | |
2047 #endif | |
2048 check_opcode ((Opcode) (program[j->to])); | |
2049 } | |
2050 } | |
2051 | |
2052 /* Fixup jumps in byte-code until no more fixups needed */ | |
2053 { | |
2054 int more_fixups_needed = 1; | |
2055 | |
2056 while (more_fixups_needed) | |
2057 { | |
2058 struct jump *j; | |
2059 more_fixups_needed = 0; | |
2060 for (j = jumps; j < jumps_ptr; j++) | |
2061 { | |
2062 int from = j->from; | |
2063 int to = j->to; | |
2064 int jump = to - from; | |
2065 Opbyte *p = program + from; | |
2066 Opcode opcode = (Opcode) p[-1]; | |
2067 if (!more_fixups_needed) | |
2068 check_opcode ((Opcode) p[jump]); | |
2069 assert (to >= 0 && program + to < program_ptr); | |
2070 switch (opcode) | |
2071 { | |
2072 case Bgoto: | |
2073 case Bgotoifnil: | |
2074 case Bgotoifnonnil: | |
2075 case Bgotoifnilelsepop: | |
2076 case Bgotoifnonnilelsepop: | |
2077 WRITE_INT16 (jump, p); | |
2078 break; | |
2079 | |
2080 case BRgoto: | |
2081 case BRgotoifnil: | |
2082 case BRgotoifnonnil: | |
2083 case BRgotoifnilelsepop: | |
2084 case BRgotoifnonnilelsepop: | |
2085 if (jump > SCHAR_MIN && | |
2086 jump <= SCHAR_MAX) | |
2087 { | |
2088 WRITE_INT8 (jump, p); | |
2089 } | |
2090 else /* barf */ | |
2091 { | |
2092 struct jump *jj; | |
2093 for (jj = jumps; jj < jumps_ptr; jj++) | |
2094 { | |
2095 assert (jj->from < program_ptr - program); | |
2096 assert (jj->to < program_ptr - program); | |
2097 if (jj->from > from) jj->from++; | |
2098 if (jj->to > from) jj->to++; | |
2099 } | |
2100 p[-1] += Bgoto - BRgoto; | |
2101 more_fixups_needed = 1; | |
2102 memmove (p+1, p, program_ptr++ - p); | |
2103 WRITE_INT16 (jump, p); | |
2104 } | |
2105 break; | |
2106 | |
2107 default: | |
2500 | 2108 ABORT(); |
428 | 2109 break; |
2110 } | |
2111 } | |
2112 } | |
2113 } | |
2114 | |
2115 /* *program_ptr++ = 0; */ | |
2116 *program_length = program_ptr - program; | |
2117 } | |
2118 | |
2119 /* Optimize the byte code and store the optimized program, only | |
2120 understood by bytecode.c, in an opaque object in the | |
2121 instructions slot of the Compiled_Function object. */ | |
2122 void | |
2123 optimize_compiled_function (Lisp_Object compiled_function) | |
2124 { | |
2125 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (compiled_function); | |
2126 int program_length; | |
2127 int varbind_count; | |
2128 Opbyte *program; | |
2129 | |
1737 | 2130 { |
2131 int minargs = 0, maxargs = 0, totalargs = 0; | |
2132 int optional_p = 0, rest_p = 0, i = 0; | |
2133 { | |
2134 LIST_LOOP_2 (arg, f->arglist) | |
2135 { | |
2136 if (EQ (arg, Qand_optional)) | |
2137 optional_p = 1; | |
2138 else if (EQ (arg, Qand_rest)) | |
2139 rest_p = 1; | |
2140 else | |
2141 { | |
2142 if (rest_p) | |
2143 { | |
2144 maxargs = MANY; | |
2145 totalargs++; | |
2146 break; | |
2147 } | |
2148 if (!optional_p) | |
2149 minargs++; | |
2150 maxargs++; | |
2151 totalargs++; | |
2152 } | |
2153 } | |
2154 } | |
2155 | |
2156 if (totalargs) | |
3092 | 2157 #ifdef NEW_GC |
2158 f->arguments = make_compiled_function_args (totalargs); | |
2159 #else /* not NEW_GC */ | |
1737 | 2160 f->args = xnew_array (Lisp_Object, totalargs); |
3092 | 2161 #endif /* not NEW_GC */ |
1737 | 2162 |
2163 { | |
2164 LIST_LOOP_2 (arg, f->arglist) | |
2165 { | |
2166 if (!EQ (arg, Qand_optional) && !EQ (arg, Qand_rest)) | |
3092 | 2167 #ifdef NEW_GC |
2168 XCOMPILED_FUNCTION_ARGS_DATA (f->arguments)[i++] = arg; | |
2169 #else /* not NEW_GC */ | |
1737 | 2170 f->args[i++] = arg; |
3092 | 2171 #endif /* not NEW_GC */ |
1737 | 2172 } |
2173 } | |
2174 | |
2175 f->max_args = maxargs; | |
2176 f->min_args = minargs; | |
2177 f->args_in_array = totalargs; | |
2178 } | |
2179 | |
428 | 2180 /* If we have not actually read the bytecode string |
2181 and constants vector yet, fetch them from the file. */ | |
2182 if (CONSP (f->instructions)) | |
2183 Ffetch_bytecode (compiled_function); | |
2184 | |
2185 if (STRINGP (f->instructions)) | |
2186 { | |
826 | 2187 /* XSTRING_LENGTH() is more efficient than string_char_length(), |
428 | 2188 which would be slightly more `proper' */ |
2189 program = alloca_array (Opbyte, 1 + 2 * XSTRING_LENGTH (f->instructions)); | |
2190 optimize_byte_code (f->instructions, f->constants, | |
2191 program, &program_length, &varbind_count); | |
2500 | 2192 f->specpdl_depth = (unsigned short) (XINT (Flength (f->arglist)) + |
2193 varbind_count); | |
428 | 2194 f->instructions = |
440 | 2195 make_opaque (program, program_length * sizeof (Opbyte)); |
428 | 2196 } |
2197 | |
2198 assert (OPAQUEP (f->instructions)); | |
2199 } | |
2200 | |
2201 /************************************************************************/ | |
2202 /* The compiled-function object type */ | |
2203 /************************************************************************/ | |
3092 | 2204 |
428 | 2205 static void |
2206 print_compiled_function (Lisp_Object obj, Lisp_Object printcharfun, | |
2207 int escapeflag) | |
2208 { | |
2209 /* This function can GC */ | |
2210 Lisp_Compiled_Function *f = | |
2211 XCOMPILED_FUNCTION (obj); /* GC doesn't relocate */ | |
2212 int docp = f->flags.documentationp; | |
2213 int intp = f->flags.interactivep; | |
2214 struct gcpro gcpro1, gcpro2; | |
2215 GCPRO2 (obj, printcharfun); | |
2216 | |
826 | 2217 write_c_string (printcharfun, print_readably ? "#[" : "#<compiled-function "); |
428 | 2218 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK |
2219 if (!print_readably) | |
2220 { | |
2221 Lisp_Object ann = compiled_function_annotation (f); | |
2222 if (!NILP (ann)) | |
800 | 2223 write_fmt_string_lisp (printcharfun, "(from %S) ", 1, ann); |
428 | 2224 } |
2225 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */ | |
2226 /* COMPILED_ARGLIST = 0 */ | |
2227 print_internal (compiled_function_arglist (f), printcharfun, escapeflag); | |
2228 | |
2229 /* COMPILED_INSTRUCTIONS = 1 */ | |
826 | 2230 write_c_string (printcharfun, " "); |
428 | 2231 { |
2232 struct gcpro ngcpro1; | |
2233 Lisp_Object instructions = compiled_function_instructions (f); | |
2234 NGCPRO1 (instructions); | |
2235 if (STRINGP (instructions) && !print_readably) | |
2236 { | |
2237 /* We don't usually want to see that junk in the bytecode. */ | |
800 | 2238 write_fmt_string (printcharfun, "\"...(%ld)\"", |
826 | 2239 (long) string_char_length (instructions)); |
428 | 2240 } |
2241 else | |
2242 print_internal (instructions, printcharfun, escapeflag); | |
2243 NUNGCPRO; | |
2244 } | |
2245 | |
2246 /* COMPILED_CONSTANTS = 2 */ | |
826 | 2247 write_c_string (printcharfun, " "); |
428 | 2248 print_internal (compiled_function_constants (f), printcharfun, escapeflag); |
2249 | |
2250 /* COMPILED_STACK_DEPTH = 3 */ | |
800 | 2251 write_fmt_string (printcharfun, " %d", compiled_function_stack_depth (f)); |
428 | 2252 |
2253 /* COMPILED_DOC_STRING = 4 */ | |
2254 if (docp || intp) | |
2255 { | |
826 | 2256 write_c_string (printcharfun, " "); |
428 | 2257 print_internal (compiled_function_documentation (f), printcharfun, |
2258 escapeflag); | |
2259 } | |
2260 | |
2261 /* COMPILED_INTERACTIVE = 5 */ | |
2262 if (intp) | |
2263 { | |
826 | 2264 write_c_string (printcharfun, " "); |
428 | 2265 print_internal (compiled_function_interactive (f), printcharfun, |
2266 escapeflag); | |
2267 } | |
2268 | |
2269 UNGCPRO; | |
826 | 2270 write_c_string (printcharfun, print_readably ? "]" : ">"); |
428 | 2271 } |
2272 | |
2273 | |
2274 static Lisp_Object | |
2275 mark_compiled_function (Lisp_Object obj) | |
2276 { | |
2277 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (obj); | |
814 | 2278 int i; |
428 | 2279 |
2280 mark_object (f->instructions); | |
2281 mark_object (f->arglist); | |
2282 mark_object (f->doc_and_interactive); | |
2283 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
2284 mark_object (f->annotated); | |
2285 #endif | |
814 | 2286 for (i = 0; i < f->args_in_array; i++) |
3092 | 2287 #ifdef NEW_GC |
2288 mark_object (XCOMPILED_FUNCTION_ARGS_DATA (f->arguments)[i]); | |
2289 #else /* not NEW_GC */ | |
814 | 2290 mark_object (f->args[i]); |
3092 | 2291 #endif /* not NEW_GC */ |
814 | 2292 |
428 | 2293 /* tail-recurse on constants */ |
2294 return f->constants; | |
2295 } | |
2296 | |
2297 static int | |
2298 compiled_function_equal (Lisp_Object obj1, Lisp_Object obj2, int depth) | |
2299 { | |
2300 Lisp_Compiled_Function *f1 = XCOMPILED_FUNCTION (obj1); | |
2301 Lisp_Compiled_Function *f2 = XCOMPILED_FUNCTION (obj2); | |
2302 return | |
2303 (f1->flags.documentationp == f2->flags.documentationp && | |
2304 f1->flags.interactivep == f2->flags.interactivep && | |
2305 f1->flags.domainp == f2->flags.domainp && /* I18N3 */ | |
2306 internal_equal (compiled_function_instructions (f1), | |
2307 compiled_function_instructions (f2), depth + 1) && | |
2308 internal_equal (f1->constants, f2->constants, depth + 1) && | |
2309 internal_equal (f1->arglist, f2->arglist, depth + 1) && | |
2310 internal_equal (f1->doc_and_interactive, | |
2311 f2->doc_and_interactive, depth + 1)); | |
2312 } | |
2313 | |
665 | 2314 static Hashcode |
428 | 2315 compiled_function_hash (Lisp_Object obj, int depth) |
2316 { | |
2317 Lisp_Compiled_Function *f = XCOMPILED_FUNCTION (obj); | |
2318 return HASH3 ((f->flags.documentationp << 2) + | |
2319 (f->flags.interactivep << 1) + | |
2320 f->flags.domainp, | |
2321 internal_hash (f->instructions, depth + 1), | |
2322 internal_hash (f->constants, depth + 1)); | |
2323 } | |
2324 | |
1204 | 2325 static const struct memory_description compiled_function_description[] = { |
814 | 2326 { XD_INT, offsetof (Lisp_Compiled_Function, args_in_array) }, |
3092 | 2327 #ifdef NEW_GC |
2328 { XD_LISP_OBJECT, offsetof (Lisp_Compiled_Function, arguments) }, | |
2329 #else /* not NEW_GC */ | |
2330 { XD_BLOCK_PTR, offsetof (Lisp_Compiled_Function, args), | |
2551 | 2331 XD_INDIRECT (0, 0), { &lisp_object_description } }, |
3092 | 2332 #endif /* not NEW_GC */ |
440 | 2333 { XD_LISP_OBJECT, offsetof (Lisp_Compiled_Function, instructions) }, |
2334 { XD_LISP_OBJECT, offsetof (Lisp_Compiled_Function, constants) }, | |
2335 { XD_LISP_OBJECT, offsetof (Lisp_Compiled_Function, arglist) }, | |
2336 { XD_LISP_OBJECT, offsetof (Lisp_Compiled_Function, doc_and_interactive) }, | |
428 | 2337 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK |
440 | 2338 { XD_LISP_OBJECT, offsetof (Lisp_Compiled_Function, annotated) }, |
428 | 2339 #endif |
2340 { XD_END } | |
2341 }; | |
2342 | |
934 | 2343 DEFINE_BASIC_LRECORD_IMPLEMENTATION ("compiled-function", compiled_function, |
2344 1, /*dumpable_flag*/ | |
2345 mark_compiled_function, | |
2346 print_compiled_function, 0, | |
2347 compiled_function_equal, | |
2348 compiled_function_hash, | |
2349 compiled_function_description, | |
2350 Lisp_Compiled_Function); | |
3092 | 2351 |
428 | 2352 |
2353 DEFUN ("compiled-function-p", Fcompiled_function_p, 1, 1, 0, /* | |
2354 Return t if OBJECT is a byte-compiled function object. | |
2355 */ | |
2356 (object)) | |
2357 { | |
2358 return COMPILED_FUNCTIONP (object) ? Qt : Qnil; | |
2359 } | |
2360 | |
2361 /************************************************************************/ | |
2362 /* compiled-function object accessor functions */ | |
2363 /************************************************************************/ | |
2364 | |
2365 Lisp_Object | |
2366 compiled_function_arglist (Lisp_Compiled_Function *f) | |
2367 { | |
2368 return f->arglist; | |
2369 } | |
2370 | |
2371 Lisp_Object | |
2372 compiled_function_instructions (Lisp_Compiled_Function *f) | |
2373 { | |
2374 if (! OPAQUEP (f->instructions)) | |
2375 return f->instructions; | |
2376 | |
2377 { | |
2378 /* Invert action performed by optimize_byte_code() */ | |
2379 Lisp_Opaque *opaque = XOPAQUE (f->instructions); | |
2380 | |
867 | 2381 Ibyte * const buffer = |
2367 | 2382 alloca_ibytes (OPAQUE_SIZE (opaque) * MAX_ICHAR_LEN); |
867 | 2383 Ibyte *bp = buffer; |
428 | 2384 |
442 | 2385 const Opbyte * const program = (const Opbyte *) OPAQUE_DATA (opaque); |
2386 const Opbyte *program_ptr = program; | |
2387 const Opbyte * const program_end = program_ptr + OPAQUE_SIZE (opaque); | |
428 | 2388 |
2389 while (program_ptr < program_end) | |
2390 { | |
2391 Opcode opcode = (Opcode) READ_UINT_1; | |
867 | 2392 bp += set_itext_ichar (bp, opcode); |
428 | 2393 switch (opcode) |
2394 { | |
2395 case Bvarref+7: | |
2396 case Bvarset+7: | |
2397 case Bvarbind+7: | |
2398 case Bcall+7: | |
2399 case Bunbind+7: | |
2400 case Bconstant2: | |
867 | 2401 bp += set_itext_ichar (bp, READ_UINT_1); |
2402 bp += set_itext_ichar (bp, READ_UINT_1); | |
428 | 2403 break; |
2404 | |
2405 case Bvarref+6: | |
2406 case Bvarset+6: | |
2407 case Bvarbind+6: | |
2408 case Bcall+6: | |
2409 case Bunbind+6: | |
2410 case BlistN: | |
2411 case BconcatN: | |
2412 case BinsertN: | |
867 | 2413 bp += set_itext_ichar (bp, READ_UINT_1); |
428 | 2414 break; |
2415 | |
2416 case Bgoto: | |
2417 case Bgotoifnil: | |
2418 case Bgotoifnonnil: | |
2419 case Bgotoifnilelsepop: | |
2420 case Bgotoifnonnilelsepop: | |
2421 { | |
2422 int jump = READ_INT_2; | |
2423 Opbyte buf2[2]; | |
2424 Opbyte *buf2p = buf2; | |
2425 /* Convert back to program-relative address */ | |
2426 WRITE_INT16 (jump + (program_ptr - 2 - program), buf2p); | |
867 | 2427 bp += set_itext_ichar (bp, buf2[0]); |
2428 bp += set_itext_ichar (bp, buf2[1]); | |
428 | 2429 break; |
2430 } | |
2431 | |
2432 case BRgoto: | |
2433 case BRgotoifnil: | |
2434 case BRgotoifnonnil: | |
2435 case BRgotoifnilelsepop: | |
2436 case BRgotoifnonnilelsepop: | |
867 | 2437 bp += set_itext_ichar (bp, READ_INT_1 + 127); |
428 | 2438 break; |
2439 | |
2440 default: | |
2441 break; | |
2442 } | |
2443 } | |
2444 return make_string (buffer, bp - buffer); | |
2445 } | |
2446 } | |
2447 | |
2448 Lisp_Object | |
2449 compiled_function_constants (Lisp_Compiled_Function *f) | |
2450 { | |
2451 return f->constants; | |
2452 } | |
2453 | |
2454 int | |
2455 compiled_function_stack_depth (Lisp_Compiled_Function *f) | |
2456 { | |
2457 return f->stack_depth; | |
2458 } | |
2459 | |
2460 /* The compiled_function->doc_and_interactive slot uses the minimal | |
2461 number of conses, based on compiled_function->flags; it may take | |
2462 any of the following forms: | |
2463 | |
2464 doc | |
2465 interactive | |
2466 domain | |
2467 (doc . interactive) | |
2468 (doc . domain) | |
2469 (interactive . domain) | |
2470 (doc . (interactive . domain)) | |
2471 */ | |
2472 | |
2473 /* Caller must check flags.interactivep first */ | |
2474 Lisp_Object | |
2475 compiled_function_interactive (Lisp_Compiled_Function *f) | |
2476 { | |
2477 assert (f->flags.interactivep); | |
2478 if (f->flags.documentationp && f->flags.domainp) | |
2479 return XCAR (XCDR (f->doc_and_interactive)); | |
2480 else if (f->flags.documentationp) | |
2481 return XCDR (f->doc_and_interactive); | |
2482 else if (f->flags.domainp) | |
2483 return XCAR (f->doc_and_interactive); | |
2484 else | |
2485 return f->doc_and_interactive; | |
2486 } | |
2487 | |
2488 /* Caller need not check flags.documentationp first */ | |
2489 Lisp_Object | |
2490 compiled_function_documentation (Lisp_Compiled_Function *f) | |
2491 { | |
2492 if (! f->flags.documentationp) | |
2493 return Qnil; | |
2494 else if (f->flags.interactivep && f->flags.domainp) | |
2495 return XCAR (f->doc_and_interactive); | |
2496 else if (f->flags.interactivep) | |
2497 return XCAR (f->doc_and_interactive); | |
2498 else if (f->flags.domainp) | |
2499 return XCAR (f->doc_and_interactive); | |
2500 else | |
2501 return f->doc_and_interactive; | |
2502 } | |
2503 | |
2504 /* Caller need not check flags.domainp first */ | |
2505 Lisp_Object | |
2506 compiled_function_domain (Lisp_Compiled_Function *f) | |
2507 { | |
2508 if (! f->flags.domainp) | |
2509 return Qnil; | |
2510 else if (f->flags.documentationp && f->flags.interactivep) | |
2511 return XCDR (XCDR (f->doc_and_interactive)); | |
2512 else if (f->flags.documentationp) | |
2513 return XCDR (f->doc_and_interactive); | |
2514 else if (f->flags.interactivep) | |
2515 return XCDR (f->doc_and_interactive); | |
2516 else | |
2517 return f->doc_and_interactive; | |
2518 } | |
2519 | |
2520 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
2521 | |
2522 Lisp_Object | |
2523 compiled_function_annotation (Lisp_Compiled_Function *f) | |
2524 { | |
2525 return f->annotated; | |
2526 } | |
2527 | |
2528 #endif | |
2529 | |
2530 /* used only by Snarf-documentation; there must be doc already. */ | |
2531 void | |
2532 set_compiled_function_documentation (Lisp_Compiled_Function *f, | |
2533 Lisp_Object new_doc) | |
2534 { | |
2535 assert (f->flags.documentationp); | |
2536 assert (INTP (new_doc) || STRINGP (new_doc)); | |
2537 | |
2538 if (f->flags.interactivep && f->flags.domainp) | |
2539 XCAR (f->doc_and_interactive) = new_doc; | |
2540 else if (f->flags.interactivep) | |
2541 XCAR (f->doc_and_interactive) = new_doc; | |
2542 else if (f->flags.domainp) | |
2543 XCAR (f->doc_and_interactive) = new_doc; | |
2544 else | |
2545 f->doc_and_interactive = new_doc; | |
2546 } | |
2547 | |
2548 | |
2549 DEFUN ("compiled-function-arglist", Fcompiled_function_arglist, 1, 1, 0, /* | |
2550 Return the argument list of the compiled-function object FUNCTION. | |
2551 */ | |
2552 (function)) | |
2553 { | |
2554 CHECK_COMPILED_FUNCTION (function); | |
2555 return compiled_function_arglist (XCOMPILED_FUNCTION (function)); | |
2556 } | |
2557 | |
2558 DEFUN ("compiled-function-instructions", Fcompiled_function_instructions, 1, 1, 0, /* | |
2559 Return the byte-opcode string of the compiled-function object FUNCTION. | |
2560 */ | |
2561 (function)) | |
2562 { | |
2563 CHECK_COMPILED_FUNCTION (function); | |
2564 return compiled_function_instructions (XCOMPILED_FUNCTION (function)); | |
2565 } | |
2566 | |
2567 DEFUN ("compiled-function-constants", Fcompiled_function_constants, 1, 1, 0, /* | |
2568 Return the constants vector of the compiled-function object FUNCTION. | |
2569 */ | |
2570 (function)) | |
2571 { | |
2572 CHECK_COMPILED_FUNCTION (function); | |
2573 return compiled_function_constants (XCOMPILED_FUNCTION (function)); | |
2574 } | |
2575 | |
2576 DEFUN ("compiled-function-stack-depth", Fcompiled_function_stack_depth, 1, 1, 0, /* | |
444 | 2577 Return the maximum stack depth of the compiled-function object FUNCTION. |
428 | 2578 */ |
2579 (function)) | |
2580 { | |
2581 CHECK_COMPILED_FUNCTION (function); | |
2582 return make_int (compiled_function_stack_depth (XCOMPILED_FUNCTION (function))); | |
2583 } | |
2584 | |
2585 DEFUN ("compiled-function-doc-string", Fcompiled_function_doc_string, 1, 1, 0, /* | |
2586 Return the doc string of the compiled-function object FUNCTION, if available. | |
2587 Functions that had their doc strings snarfed into the DOC file will have | |
2588 an integer returned instead of a string. | |
2589 */ | |
2590 (function)) | |
2591 { | |
2592 CHECK_COMPILED_FUNCTION (function); | |
2593 return compiled_function_documentation (XCOMPILED_FUNCTION (function)); | |
2594 } | |
2595 | |
2596 DEFUN ("compiled-function-interactive", Fcompiled_function_interactive, 1, 1, 0, /* | |
2597 Return the interactive spec of the compiled-function object FUNCTION, or nil. | |
2598 If non-nil, the return value will be a list whose first element is | |
2599 `interactive' and whose second element is the interactive spec. | |
2600 */ | |
2601 (function)) | |
2602 { | |
2603 CHECK_COMPILED_FUNCTION (function); | |
2604 return XCOMPILED_FUNCTION (function)->flags.interactivep | |
2605 ? list2 (Qinteractive, | |
2606 compiled_function_interactive (XCOMPILED_FUNCTION (function))) | |
2607 : Qnil; | |
2608 } | |
2609 | |
2610 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
2611 | |
826 | 2612 DEFUN ("compiled-function-annotation", Fcompiled_function_annotation, 1, 1, 0, /* |
428 | 2613 Return the annotation of the compiled-function object FUNCTION, or nil. |
2614 The annotation is a piece of information indicating where this | |
2615 compiled-function object came from. Generally this will be | |
2616 a symbol naming a function; or a string naming a file, if the | |
2617 compiled-function object was not defined in a function; or nil, | |
2618 if the compiled-function object was not created as a result of | |
2619 a `load'. | |
2620 */ | |
2621 (function)) | |
2622 { | |
2623 CHECK_COMPILED_FUNCTION (function); | |
2624 return compiled_function_annotation (XCOMPILED_FUNCTION (function)); | |
2625 } | |
2626 | |
2627 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */ | |
2628 | |
2629 DEFUN ("compiled-function-domain", Fcompiled_function_domain, 1, 1, 0, /* | |
2630 Return the domain of the compiled-function object FUNCTION, or nil. | |
2631 This is only meaningful if I18N3 was enabled when emacs was compiled. | |
2632 */ | |
2633 (function)) | |
2634 { | |
2635 CHECK_COMPILED_FUNCTION (function); | |
2636 return XCOMPILED_FUNCTION (function)->flags.domainp | |
2637 ? compiled_function_domain (XCOMPILED_FUNCTION (function)) | |
2638 : Qnil; | |
2639 } | |
2640 | |
2641 | |
2642 | |
2643 DEFUN ("fetch-bytecode", Ffetch_bytecode, 1, 1, 0, /* | |
2644 If the byte code for compiled function FUNCTION is lazy-loaded, fetch it now. | |
2645 */ | |
2646 (function)) | |
2647 { | |
2648 Lisp_Compiled_Function *f; | |
2649 CHECK_COMPILED_FUNCTION (function); | |
2650 f = XCOMPILED_FUNCTION (function); | |
2651 | |
2652 if (OPAQUEP (f->instructions) || STRINGP (f->instructions)) | |
2653 return function; | |
2654 | |
2655 if (CONSP (f->instructions)) | |
2656 { | |
2657 Lisp_Object tem = read_doc_string (f->instructions); | |
2658 if (!CONSP (tem)) | |
563 | 2659 signal_error (Qinvalid_byte_code, |
2660 "Invalid lazy-loaded byte code", tem); | |
428 | 2661 /* v18 or v19 bytecode file. Need to Ebolify. */ |
2662 if (f->flags.ebolified && VECTORP (XCDR (tem))) | |
2663 ebolify_bytecode_constants (XCDR (tem)); | |
2664 f->instructions = XCAR (tem); | |
2665 f->constants = XCDR (tem); | |
2666 return function; | |
2667 } | |
2500 | 2668 ABORT (); |
801 | 2669 return Qnil; /* not (usually) reached */ |
428 | 2670 } |
2671 | |
2672 DEFUN ("optimize-compiled-function", Foptimize_compiled_function, 1, 1, 0, /* | |
2673 Convert compiled function FUNCTION into an optimized internal form. | |
2674 */ | |
2675 (function)) | |
2676 { | |
2677 Lisp_Compiled_Function *f; | |
2678 CHECK_COMPILED_FUNCTION (function); | |
2679 f = XCOMPILED_FUNCTION (function); | |
2680 | |
2681 if (OPAQUEP (f->instructions)) /* Already optimized? */ | |
2682 return Qnil; | |
2683 | |
2684 optimize_compiled_function (function); | |
2685 return Qnil; | |
2686 } | |
2687 | |
2688 DEFUN ("byte-code", Fbyte_code, 3, 3, 0, /* | |
2689 Function used internally in byte-compiled code. | |
2690 First argument INSTRUCTIONS is a string of byte code. | |
2691 Second argument CONSTANTS is a vector of constants. | |
2692 Third argument STACK-DEPTH is the maximum stack depth used in this function. | |
2693 If STACK-DEPTH is incorrect, Emacs may crash. | |
2694 */ | |
2695 (instructions, constants, stack_depth)) | |
2696 { | |
2697 /* This function can GC */ | |
2698 int varbind_count; | |
2699 int program_length; | |
2700 Opbyte *program; | |
2701 | |
2702 CHECK_STRING (instructions); | |
2703 CHECK_VECTOR (constants); | |
2704 CHECK_NATNUM (stack_depth); | |
2705 | |
2706 /* Optimize the `instructions' string, just like when executing a | |
2707 regular compiled function, but don't save it for later since this is | |
2708 likely to only be executed once. */ | |
2709 program = alloca_array (Opbyte, 1 + 2 * XSTRING_LENGTH (instructions)); | |
2710 optimize_byte_code (instructions, constants, program, | |
2711 &program_length, &varbind_count); | |
2712 SPECPDL_RESERVE (varbind_count); | |
2713 return execute_optimized_program (program, | |
2714 XINT (stack_depth), | |
2715 XVECTOR_DATA (constants)); | |
2716 } | |
2717 | |
2718 | |
2719 void | |
2720 syms_of_bytecode (void) | |
2721 { | |
442 | 2722 INIT_LRECORD_IMPLEMENTATION (compiled_function); |
3092 | 2723 #ifdef NEW_GC |
2724 INIT_LRECORD_IMPLEMENTATION (compiled_function_args); | |
2725 #endif /* NEW_GC */ | |
442 | 2726 |
2727 DEFERROR_STANDARD (Qinvalid_byte_code, Qinvalid_state); | |
563 | 2728 DEFSYMBOL (Qbyte_code); |
2729 DEFSYMBOL_MULTIWORD_PREDICATE (Qcompiled_functionp); | |
428 | 2730 |
2731 DEFSUBR (Fbyte_code); | |
2732 DEFSUBR (Ffetch_bytecode); | |
2733 DEFSUBR (Foptimize_compiled_function); | |
2734 | |
2735 DEFSUBR (Fcompiled_function_p); | |
2736 DEFSUBR (Fcompiled_function_instructions); | |
2737 DEFSUBR (Fcompiled_function_constants); | |
2738 DEFSUBR (Fcompiled_function_stack_depth); | |
2739 DEFSUBR (Fcompiled_function_arglist); | |
2740 DEFSUBR (Fcompiled_function_interactive); | |
2741 DEFSUBR (Fcompiled_function_doc_string); | |
2742 DEFSUBR (Fcompiled_function_domain); | |
2743 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK | |
2744 DEFSUBR (Fcompiled_function_annotation); | |
2745 #endif | |
2746 | |
2747 #ifdef BYTE_CODE_METER | |
563 | 2748 DEFSYMBOL (Qbyte_code_meter); |
428 | 2749 #endif |
2750 } | |
2751 | |
2752 void | |
2753 vars_of_bytecode (void) | |
2754 { | |
2755 #ifdef BYTE_CODE_METER | |
2756 | |
2757 DEFVAR_LISP ("byte-code-meter", &Vbyte_code_meter /* | |
2758 A vector of vectors which holds a histogram of byte code usage. | |
2759 \(aref (aref byte-code-meter 0) CODE) indicates how many times the byte | |
2760 opcode CODE has been executed. | |
2761 \(aref (aref byte-code-meter CODE1) CODE2), where CODE1 is not 0, | |
2762 indicates how many times the byte opcodes CODE1 and CODE2 have been | |
2763 executed in succession. | |
2764 */ ); | |
2765 DEFVAR_BOOL ("byte-metering-on", &byte_metering_on /* | |
2766 If non-nil, keep profiling information on byte code usage. | |
2767 The variable `byte-code-meter' indicates how often each byte opcode is used. | |
2768 If a symbol has a property named `byte-code-meter' whose value is an | |
2769 integer, it is incremented each time that symbol's function is called. | |
2770 */ ); | |
2771 | |
2772 byte_metering_on = 0; | |
2773 Vbyte_code_meter = make_vector (256, Qzero); | |
2774 { | |
2775 int i = 256; | |
2776 while (i--) | |
2777 XVECTOR_DATA (Vbyte_code_meter)[i] = make_vector (256, Qzero); | |
2778 } | |
2779 #endif /* BYTE_CODE_METER */ | |
2780 } |