428
|
1 /* Primitive operations on Lisp data types for XEmacs Lisp interpreter.
|
|
2 Copyright (C) 1985, 1986, 1988, 1992, 1993, 1994, 1995
|
|
3 Free Software Foundation, Inc.
|
1330
|
4 Copyright (C) 2000, 2001, 2002, 2003 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. Some of FSF's data.c is in
|
|
24 XEmacs' symbols.c. */
|
|
25
|
|
26 /* This file has been Mule-ized. */
|
|
27
|
|
28 #include <config.h>
|
|
29 #include "lisp.h"
|
|
30
|
|
31 #include "buffer.h"
|
|
32 #include "bytecode.h"
|
|
33 #include "syssignal.h"
|
771
|
34 #include "sysfloat.h"
|
428
|
35
|
|
36 Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound;
|
|
37 Lisp_Object Qerror_conditions, Qerror_message;
|
442
|
38 Lisp_Object Qerror, Qquit, Qsyntax_error, Qinvalid_read_syntax;
|
563
|
39 Lisp_Object Qlist_formation_error, Qstructure_formation_error;
|
442
|
40 Lisp_Object Qmalformed_list, Qmalformed_property_list;
|
|
41 Lisp_Object Qcircular_list, Qcircular_property_list;
|
563
|
42 Lisp_Object Qinvalid_argument, Qinvalid_constant, Qwrong_type_argument;
|
|
43 Lisp_Object Qargs_out_of_range;
|
442
|
44 Lisp_Object Qwrong_number_of_arguments, Qinvalid_function, Qno_catch;
|
563
|
45 Lisp_Object Qinternal_error, Qinvalid_state, Qstack_overflow, Qout_of_memory;
|
428
|
46 Lisp_Object Qvoid_variable, Qcyclic_variable_indirection;
|
|
47 Lisp_Object Qvoid_function, Qcyclic_function_indirection;
|
563
|
48 Lisp_Object Qinvalid_operation, Qinvalid_change, Qprinting_unreadable_object;
|
442
|
49 Lisp_Object Qsetting_constant;
|
|
50 Lisp_Object Qediting_error;
|
|
51 Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
|
563
|
52 Lisp_Object Qio_error, Qfile_error, Qconversion_error, Qend_of_file;
|
580
|
53 Lisp_Object Qtext_conversion_error;
|
428
|
54 Lisp_Object Qarith_error, Qrange_error, Qdomain_error;
|
|
55 Lisp_Object Qsingularity_error, Qoverflow_error, Qunderflow_error;
|
1983
|
56 Lisp_Object Qintegerp, Qnatnump, Qnonnegativep, Qsymbolp;
|
428
|
57 Lisp_Object Qlistp, Qtrue_list_p, Qweak_listp;
|
|
58 Lisp_Object Qconsp, Qsubrp;
|
|
59 Lisp_Object Qcharacterp, Qstringp, Qarrayp, Qsequencep, Qvectorp;
|
|
60 Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qbufferp;
|
|
61 Lisp_Object Qinteger_or_char_p, Qinteger_char_or_marker_p;
|
|
62 Lisp_Object Qnumberp, Qnumber_char_or_marker_p;
|
|
63 Lisp_Object Qbit_vectorp, Qbitp, Qcdr;
|
|
64
|
563
|
65 Lisp_Object Qerror_lacks_explanatory_string;
|
428
|
66 Lisp_Object Qfloatp;
|
|
67
|
|
68 #ifdef DEBUG_XEMACS
|
|
69
|
|
70 int debug_issue_ebola_notices;
|
|
71
|
458
|
72 Fixnum debug_ebola_backtrace_length;
|
428
|
73
|
|
74 int
|
|
75 eq_with_ebola_notice (Lisp_Object obj1, Lisp_Object obj2)
|
|
76 {
|
|
77 if (debug_issue_ebola_notices
|
|
78 && ((CHARP (obj1) && INTP (obj2)) || (CHARP (obj2) && INTP (obj1))))
|
|
79 {
|
|
80 /* #### It would be really nice if this were a proper warning
|
1551
|
81 instead of brain-dead print to Qexternal_debugging_output. */
|
826
|
82 write_c_string
|
|
83 (Qexternal_debugging_output,
|
|
84 "Comparison between integer and character is constant nil (");
|
428
|
85 Fprinc (obj1, Qexternal_debugging_output);
|
826
|
86 write_c_string (Qexternal_debugging_output, " and ");
|
428
|
87 Fprinc (obj2, Qexternal_debugging_output);
|
826
|
88 write_c_string (Qexternal_debugging_output, ")\n");
|
428
|
89 debug_short_backtrace (debug_ebola_backtrace_length);
|
|
90 }
|
|
91 return EQ (obj1, obj2);
|
|
92 }
|
|
93
|
|
94 #endif /* DEBUG_XEMACS */
|
|
95
|
|
96
|
|
97
|
|
98 Lisp_Object
|
|
99 wrong_type_argument (Lisp_Object predicate, Lisp_Object value)
|
|
100 {
|
|
101 /* This function can GC */
|
|
102 REGISTER Lisp_Object tem;
|
|
103 do
|
|
104 {
|
|
105 value = Fsignal (Qwrong_type_argument, list2 (predicate, value));
|
|
106 tem = call1 (predicate, value);
|
|
107 }
|
|
108 while (NILP (tem));
|
|
109 return value;
|
|
110 }
|
|
111
|
|
112 DOESNT_RETURN
|
|
113 dead_wrong_type_argument (Lisp_Object predicate, Lisp_Object value)
|
|
114 {
|
563
|
115 signal_error_1 (Qwrong_type_argument, list2 (predicate, value));
|
428
|
116 }
|
|
117
|
|
118 DEFUN ("wrong-type-argument", Fwrong_type_argument, 2, 2, 0, /*
|
|
119 Signal an error until the correct type value is given by the user.
|
|
120 This function loops, signalling a continuable `wrong-type-argument' error
|
|
121 with PREDICATE and VALUE as the data associated with the error and then
|
|
122 calling PREDICATE on the returned value, until the value gotten satisfies
|
|
123 PREDICATE. At that point, the gotten value is returned.
|
|
124 */
|
|
125 (predicate, value))
|
|
126 {
|
|
127 return wrong_type_argument (predicate, value);
|
|
128 }
|
|
129
|
|
130 DOESNT_RETURN
|
|
131 c_write_error (Lisp_Object obj)
|
|
132 {
|
563
|
133 signal_error (Qsetting_constant,
|
|
134 "Attempt to modify read-only object (c)", obj);
|
428
|
135 }
|
|
136
|
|
137 DOESNT_RETURN
|
|
138 lisp_write_error (Lisp_Object obj)
|
|
139 {
|
563
|
140 signal_error (Qsetting_constant,
|
|
141 "Attempt to modify read-only object (lisp)", obj);
|
428
|
142 }
|
|
143
|
|
144 DOESNT_RETURN
|
|
145 args_out_of_range (Lisp_Object a1, Lisp_Object a2)
|
|
146 {
|
563
|
147 signal_error_1 (Qargs_out_of_range, list2 (a1, a2));
|
428
|
148 }
|
|
149
|
|
150 DOESNT_RETURN
|
|
151 args_out_of_range_3 (Lisp_Object a1, Lisp_Object a2, Lisp_Object a3)
|
|
152 {
|
563
|
153 signal_error_1 (Qargs_out_of_range, list3 (a1, a2, a3));
|
428
|
154 }
|
|
155
|
|
156 void
|
|
157 check_int_range (EMACS_INT val, EMACS_INT min, EMACS_INT max)
|
|
158 {
|
|
159 if (val < min || val > max)
|
|
160 args_out_of_range_3 (make_int (val), make_int (min), make_int (max));
|
|
161 }
|
|
162
|
|
163 /* On some machines, XINT needs a temporary location.
|
|
164 Here it is, in case it is needed. */
|
|
165
|
|
166 EMACS_INT sign_extend_temp;
|
|
167
|
|
168 /* On a few machines, XINT can only be done by calling this. */
|
|
169 /* XEmacs: only used by m/convex.h */
|
|
170 EMACS_INT sign_extend_lisp_int (EMACS_INT num);
|
|
171 EMACS_INT
|
|
172 sign_extend_lisp_int (EMACS_INT num)
|
|
173 {
|
2039
|
174 if (num & (1L << (INT_VALBITS - 1)))
|
|
175 return num | ((-1L) << INT_VALBITS);
|
428
|
176 else
|
2039
|
177 return num & (EMACS_INT) ((1UL << INT_VALBITS) - 1);
|
428
|
178 }
|
|
179
|
|
180
|
|
181 /* Data type predicates */
|
|
182
|
|
183 DEFUN ("eq", Feq, 2, 2, 0, /*
|
|
184 Return t if the two args are the same Lisp object.
|
|
185 */
|
444
|
186 (object1, object2))
|
428
|
187 {
|
444
|
188 return EQ_WITH_EBOLA_NOTICE (object1, object2) ? Qt : Qnil;
|
428
|
189 }
|
|
190
|
|
191 DEFUN ("old-eq", Fold_eq, 2, 2, 0, /*
|
|
192 Return t if the two args are (in most cases) the same Lisp object.
|
|
193
|
|
194 Special kludge: A character is considered `old-eq' to its equivalent integer
|
|
195 even though they are not the same object and are in fact of different
|
|
196 types. This is ABSOLUTELY AND UTTERLY HORRENDOUS but is necessary to
|
|
197 preserve byte-code compatibility with v19. This kludge is known as the
|
|
198 \"char-int confoundance disease\" and appears in a number of other
|
|
199 functions with `old-foo' equivalents.
|
|
200
|
|
201 Do not use this function!
|
|
202 */
|
444
|
203 (object1, object2))
|
428
|
204 {
|
|
205 /* #### blasphemy */
|
444
|
206 return HACKEQ_UNSAFE (object1, object2) ? Qt : Qnil;
|
428
|
207 }
|
|
208
|
|
209 DEFUN ("null", Fnull, 1, 1, 0, /*
|
|
210 Return t if OBJECT is nil.
|
|
211 */
|
|
212 (object))
|
|
213 {
|
|
214 return NILP (object) ? Qt : Qnil;
|
|
215 }
|
|
216
|
|
217 DEFUN ("consp", Fconsp, 1, 1, 0, /*
|
|
218 Return t if OBJECT is a cons cell. `nil' is not a cons cell.
|
3343
|
219
|
3355
|
220 See the documentation for `cons' or the Lisp manual for more details on what
|
|
221 a cons cell is.
|
428
|
222 */
|
|
223 (object))
|
|
224 {
|
|
225 return CONSP (object) ? Qt : Qnil;
|
|
226 }
|
|
227
|
|
228 DEFUN ("atom", Fatom, 1, 1, 0, /*
|
|
229 Return t if OBJECT is not a cons cell. `nil' is not a cons cell.
|
3355
|
230
|
|
231 See the documentation for `cons' or the Lisp manual for more details on what
|
|
232 a cons cell is.
|
428
|
233 */
|
|
234 (object))
|
|
235 {
|
|
236 return CONSP (object) ? Qnil : Qt;
|
|
237 }
|
|
238
|
|
239 DEFUN ("listp", Flistp, 1, 1, 0, /*
|
|
240 Return t if OBJECT is a list. `nil' is a list.
|
3343
|
241
|
3355
|
242 A list is either the Lisp object nil (a symbol), interpreted as the empty
|
|
243 list in this context, or a cons cell whose CDR refers to either nil or a
|
|
244 cons cell. A "proper list" contains no cycles.
|
428
|
245 */
|
|
246 (object))
|
|
247 {
|
|
248 return LISTP (object) ? Qt : Qnil;
|
|
249 }
|
|
250
|
|
251 DEFUN ("nlistp", Fnlistp, 1, 1, 0, /*
|
|
252 Return t if OBJECT is not a list. `nil' is a list.
|
|
253 */
|
|
254 (object))
|
|
255 {
|
|
256 return LISTP (object) ? Qnil : Qt;
|
|
257 }
|
|
258
|
|
259 DEFUN ("true-list-p", Ftrue_list_p, 1, 1, 0, /*
|
1551
|
260 Return t if OBJECT is an acyclic, nil-terminated (ie, not dotted), list.
|
428
|
261 */
|
|
262 (object))
|
|
263 {
|
|
264 return TRUE_LIST_P (object) ? Qt : Qnil;
|
|
265 }
|
|
266
|
|
267 DEFUN ("symbolp", Fsymbolp, 1, 1, 0, /*
|
|
268 Return t if OBJECT is a symbol.
|
3343
|
269
|
|
270 A symbol is a Lisp object with a name. It can optionally have any and all of
|
|
271 a value, a property list and an associated function.
|
428
|
272 */
|
|
273 (object))
|
|
274 {
|
|
275 return SYMBOLP (object) ? Qt : Qnil;
|
|
276 }
|
|
277
|
|
278 DEFUN ("keywordp", Fkeywordp, 1, 1, 0, /*
|
|
279 Return t if OBJECT is a keyword.
|
|
280 */
|
|
281 (object))
|
|
282 {
|
|
283 return KEYWORDP (object) ? Qt : Qnil;
|
|
284 }
|
|
285
|
|
286 DEFUN ("vectorp", Fvectorp, 1, 1, 0, /*
|
|
287 Return t if OBJECT is a vector.
|
|
288 */
|
|
289 (object))
|
|
290 {
|
|
291 return VECTORP (object) ? Qt : Qnil;
|
|
292 }
|
|
293
|
|
294 DEFUN ("bit-vector-p", Fbit_vector_p, 1, 1, 0, /*
|
|
295 Return t if OBJECT is a bit vector.
|
|
296 */
|
|
297 (object))
|
|
298 {
|
|
299 return BIT_VECTORP (object) ? Qt : Qnil;
|
|
300 }
|
|
301
|
|
302 DEFUN ("stringp", Fstringp, 1, 1, 0, /*
|
|
303 Return t if OBJECT is a string.
|
|
304 */
|
|
305 (object))
|
|
306 {
|
|
307 return STRINGP (object) ? Qt : Qnil;
|
|
308 }
|
|
309
|
|
310 DEFUN ("arrayp", Farrayp, 1, 1, 0, /*
|
|
311 Return t if OBJECT is an array (string, vector, or bit vector).
|
|
312 */
|
|
313 (object))
|
|
314 {
|
|
315 return (VECTORP (object) ||
|
|
316 STRINGP (object) ||
|
|
317 BIT_VECTORP (object))
|
|
318 ? Qt : Qnil;
|
|
319 }
|
|
320
|
|
321 DEFUN ("sequencep", Fsequencep, 1, 1, 0, /*
|
|
322 Return t if OBJECT is a sequence (list or array).
|
|
323 */
|
|
324 (object))
|
|
325 {
|
|
326 return (LISTP (object) ||
|
|
327 VECTORP (object) ||
|
|
328 STRINGP (object) ||
|
|
329 BIT_VECTORP (object))
|
|
330 ? Qt : Qnil;
|
|
331 }
|
|
332
|
|
333 DEFUN ("markerp", Fmarkerp, 1, 1, 0, /*
|
|
334 Return t if OBJECT is a marker (editor pointer).
|
|
335 */
|
|
336 (object))
|
|
337 {
|
|
338 return MARKERP (object) ? Qt : Qnil;
|
|
339 }
|
|
340
|
|
341 DEFUN ("subrp", Fsubrp, 1, 1, 0, /*
|
|
342 Return t if OBJECT is a built-in function.
|
|
343 */
|
|
344 (object))
|
|
345 {
|
|
346 return SUBRP (object) ? Qt : Qnil;
|
|
347 }
|
|
348
|
|
349 DEFUN ("subr-min-args", Fsubr_min_args, 1, 1, 0, /*
|
|
350 Return minimum number of args built-in function SUBR may be called with.
|
|
351 */
|
|
352 (subr))
|
|
353 {
|
|
354 CHECK_SUBR (subr);
|
|
355 return make_int (XSUBR (subr)->min_args);
|
|
356 }
|
|
357
|
|
358 DEFUN ("subr-max-args", Fsubr_max_args, 1, 1, 0, /*
|
|
359 Return maximum number of args built-in function SUBR may be called with,
|
|
360 or nil if it takes an arbitrary number of arguments or is a special form.
|
|
361 */
|
|
362 (subr))
|
|
363 {
|
|
364 int nargs;
|
|
365 CHECK_SUBR (subr);
|
|
366 nargs = XSUBR (subr)->max_args;
|
|
367 if (nargs == MANY || nargs == UNEVALLED)
|
|
368 return Qnil;
|
|
369 else
|
|
370 return make_int (nargs);
|
|
371 }
|
|
372
|
|
373 DEFUN ("subr-interactive", Fsubr_interactive, 1, 1, 0, /*
|
444
|
374 Return the interactive spec of the subr object SUBR, or nil.
|
428
|
375 If non-nil, the return value will be a list whose first element is
|
|
376 `interactive' and whose second element is the interactive spec.
|
|
377 */
|
|
378 (subr))
|
|
379 {
|
867
|
380 const CIbyte *prompt;
|
428
|
381 CHECK_SUBR (subr);
|
|
382 prompt = XSUBR (subr)->prompt;
|
771
|
383 return prompt ? list2 (Qinteractive, build_msg_string (prompt)) : Qnil;
|
428
|
384 }
|
|
385
|
|
386
|
|
387 DEFUN ("characterp", Fcharacterp, 1, 1, 0, /*
|
|
388 Return t if OBJECT is a character.
|
|
389 Unlike in XEmacs v19 and FSF Emacs, a character is its own primitive type.
|
|
390 Any character can be converted into an equivalent integer using
|
|
391 `char-int'. To convert the other way, use `int-char'; however,
|
|
392 only some integers can be converted into characters. Such an integer
|
|
393 is called a `char-int'; see `char-int-p'.
|
|
394
|
|
395 Some functions that work on integers (e.g. the comparison functions
|
|
396 <, <=, =, /=, etc. and the arithmetic functions +, -, *, etc.)
|
|
397 accept characters and implicitly convert them into integers. In
|
|
398 general, functions that work on characters also accept char-ints and
|
|
399 implicitly convert them into characters. WARNING: Neither of these
|
|
400 behaviors is very desirable, and they are maintained for backward
|
|
401 compatibility with old E-Lisp programs that confounded characters and
|
|
402 integers willy-nilly. These behaviors may change in the future; therefore,
|
|
403 do not rely on them. Instead, use the character-specific functions such
|
|
404 as `char='.
|
|
405 */
|
|
406 (object))
|
|
407 {
|
|
408 return CHARP (object) ? Qt : Qnil;
|
|
409 }
|
|
410
|
|
411 DEFUN ("char-to-int", Fchar_to_int, 1, 1, 0, /*
|
444
|
412 Convert CHARACTER into an equivalent integer.
|
428
|
413 The resulting integer will always be non-negative. The integers in
|
|
414 the range 0 - 255 map to characters as follows:
|
|
415
|
|
416 0 - 31 Control set 0
|
|
417 32 - 127 ASCII
|
|
418 128 - 159 Control set 1
|
|
419 160 - 255 Right half of ISO-8859-1
|
|
420
|
|
421 If support for Mule does not exist, these are the only valid character
|
|
422 values. When Mule support exists, the values assigned to other characters
|
|
423 may vary depending on the particular version of XEmacs, the order in which
|
|
424 character sets were loaded, etc., and you should not depend on them.
|
|
425 */
|
444
|
426 (character))
|
428
|
427 {
|
444
|
428 CHECK_CHAR (character);
|
|
429 return make_int (XCHAR (character));
|
428
|
430 }
|
|
431
|
|
432 DEFUN ("int-to-char", Fint_to_char, 1, 1, 0, /*
|
444
|
433 Convert integer INTEGER into the equivalent character.
|
428
|
434 Not all integers correspond to valid characters; use `char-int-p' to
|
|
435 determine whether this is the case. If the integer cannot be converted,
|
|
436 nil is returned.
|
|
437 */
|
|
438 (integer))
|
|
439 {
|
|
440 CHECK_INT (integer);
|
|
441 if (CHAR_INTP (integer))
|
|
442 return make_char (XINT (integer));
|
|
443 else
|
|
444 return Qnil;
|
|
445 }
|
|
446
|
|
447 DEFUN ("char-int-p", Fchar_int_p, 1, 1, 0, /*
|
|
448 Return t if OBJECT is an integer that can be converted into a character.
|
|
449 See `char-int'.
|
|
450 */
|
|
451 (object))
|
|
452 {
|
|
453 return CHAR_INTP (object) ? Qt : Qnil;
|
|
454 }
|
|
455
|
|
456 DEFUN ("char-or-char-int-p", Fchar_or_char_int_p, 1, 1, 0, /*
|
|
457 Return t if OBJECT is a character or an integer that can be converted into one.
|
|
458 */
|
|
459 (object))
|
|
460 {
|
|
461 return CHAR_OR_CHAR_INTP (object) ? Qt : Qnil;
|
|
462 }
|
|
463
|
|
464 DEFUN ("char-or-string-p", Fchar_or_string_p, 1, 1, 0, /*
|
|
465 Return t if OBJECT is a character (or a char-int) or a string.
|
|
466 It is semi-hateful that we allow a char-int here, as it goes against
|
|
467 the name of this function, but it makes the most sense considering the
|
|
468 other steps we take to maintain compatibility with the old character/integer
|
|
469 confoundedness in older versions of E-Lisp.
|
|
470 */
|
|
471 (object))
|
|
472 {
|
|
473 return CHAR_OR_CHAR_INTP (object) || STRINGP (object) ? Qt : Qnil;
|
|
474 }
|
|
475
|
1983
|
476 #ifdef HAVE_BIGNUM
|
|
477 /* In this case, integerp is defined in number.c. */
|
|
478 DEFUN ("fixnump", Ffixnump, 1, 1, 0, /*
|
|
479 Return t if OBJECT is a fixnum.
|
|
480 */
|
|
481 (object))
|
|
482 {
|
|
483 return INTP (object) ? Qt : Qnil;
|
|
484 }
|
|
485 #else
|
428
|
486 DEFUN ("integerp", Fintegerp, 1, 1, 0, /*
|
|
487 Return t if OBJECT is an integer.
|
|
488 */
|
|
489 (object))
|
|
490 {
|
|
491 return INTP (object) ? Qt : Qnil;
|
|
492 }
|
1983
|
493 #endif
|
428
|
494
|
|
495 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, 1, 1, 0, /*
|
|
496 Return t if OBJECT is an integer or a marker (editor pointer).
|
|
497 */
|
|
498 (object))
|
|
499 {
|
|
500 return INTP (object) || MARKERP (object) ? Qt : Qnil;
|
|
501 }
|
|
502
|
|
503 DEFUN ("integer-or-char-p", Finteger_or_char_p, 1, 1, 0, /*
|
|
504 Return t if OBJECT is an integer or a character.
|
|
505 */
|
|
506 (object))
|
|
507 {
|
|
508 return INTP (object) || CHARP (object) ? Qt : Qnil;
|
|
509 }
|
|
510
|
|
511 DEFUN ("integer-char-or-marker-p", Finteger_char_or_marker_p, 1, 1, 0, /*
|
|
512 Return t if OBJECT is an integer, character or a marker (editor pointer).
|
|
513 */
|
|
514 (object))
|
|
515 {
|
|
516 return INTP (object) || CHARP (object) || MARKERP (object) ? Qt : Qnil;
|
|
517 }
|
|
518
|
|
519 DEFUN ("natnump", Fnatnump, 1, 1, 0, /*
|
|
520 Return t if OBJECT is a nonnegative integer.
|
|
521 */
|
|
522 (object))
|
|
523 {
|
1983
|
524 return NATNUMP (object)
|
|
525 #ifdef HAVE_BIGNUM
|
|
526 || (BIGNUMP (object) && bignum_sign (XBIGNUM_DATA (object)) >= 0)
|
|
527 #endif
|
|
528 ? Qt : Qnil;
|
|
529 }
|
|
530
|
|
531 DEFUN ("nonnegativep", Fnonnegativep, 1, 1, 0, /*
|
|
532 Return t if OBJECT is a nonnegative number.
|
|
533 */
|
|
534 (object))
|
|
535 {
|
|
536 return NATNUMP (object)
|
|
537 #ifdef HAVE_BIGNUM
|
|
538 || (BIGNUMP (object) && bignum_sign (XBIGNUM_DATA (object)) >= 0)
|
|
539 #endif
|
|
540 #ifdef HAVE_RATIO
|
|
541 || (RATIOP (object) && ratio_sign (XRATIO_DATA (object)) >= 0)
|
|
542 #endif
|
|
543 #ifdef HAVE_BIGFLOAT
|
|
544 || (BIGFLOATP (object) && bigfloat_sign (XBIGFLOAT_DATA (object)) >= 0)
|
|
545 #endif
|
|
546 ? Qt : Qnil;
|
428
|
547 }
|
|
548
|
|
549 DEFUN ("bitp", Fbitp, 1, 1, 0, /*
|
|
550 Return t if OBJECT is a bit (0 or 1).
|
|
551 */
|
|
552 (object))
|
|
553 {
|
|
554 return BITP (object) ? Qt : Qnil;
|
|
555 }
|
|
556
|
|
557 DEFUN ("numberp", Fnumberp, 1, 1, 0, /*
|
|
558 Return t if OBJECT is a number (floating point or integer).
|
|
559 */
|
|
560 (object))
|
|
561 {
|
1983
|
562 #ifdef WITH_NUMBER_TYPES
|
|
563 return NUMBERP (object) ? Qt : Qnil;
|
|
564 #else
|
428
|
565 return INT_OR_FLOATP (object) ? Qt : Qnil;
|
1983
|
566 #endif
|
428
|
567 }
|
|
568
|
|
569 DEFUN ("number-or-marker-p", Fnumber_or_marker_p, 1, 1, 0, /*
|
|
570 Return t if OBJECT is a number or a marker.
|
|
571 */
|
|
572 (object))
|
|
573 {
|
|
574 return INT_OR_FLOATP (object) || MARKERP (object) ? Qt : Qnil;
|
|
575 }
|
|
576
|
|
577 DEFUN ("number-char-or-marker-p", Fnumber_char_or_marker_p, 1, 1, 0, /*
|
|
578 Return t if OBJECT is a number, character or a marker.
|
|
579 */
|
|
580 (object))
|
|
581 {
|
|
582 return (INT_OR_FLOATP (object) ||
|
|
583 CHARP (object) ||
|
|
584 MARKERP (object))
|
|
585 ? Qt : Qnil;
|
|
586 }
|
|
587
|
|
588 DEFUN ("floatp", Ffloatp, 1, 1, 0, /*
|
|
589 Return t if OBJECT is a floating point number.
|
|
590 */
|
|
591 (object))
|
|
592 {
|
|
593 return FLOATP (object) ? Qt : Qnil;
|
|
594 }
|
|
595
|
|
596 DEFUN ("type-of", Ftype_of, 1, 1, 0, /*
|
|
597 Return a symbol representing the type of OBJECT.
|
|
598 */
|
|
599 (object))
|
|
600 {
|
|
601 switch (XTYPE (object))
|
|
602 {
|
|
603 case Lisp_Type_Record:
|
|
604 return intern (XRECORD_LHEADER_IMPLEMENTATION (object)->name);
|
|
605
|
|
606 case Lisp_Type_Char: return Qcharacter;
|
|
607
|
|
608 default: return Qinteger;
|
|
609 }
|
|
610 }
|
|
611
|
|
612
|
|
613 /* Extract and set components of lists */
|
|
614
|
|
615 DEFUN ("car", Fcar, 1, 1, 0, /*
|
3343
|
616 Return the car of CONS. If CONS is nil, return nil.
|
|
617 The car of a list or a dotted pair is its first element.
|
|
618
|
|
619 Error if CONS is not nil and not a cons cell. See also `car-safe'.
|
428
|
620 */
|
3343
|
621 (cons))
|
428
|
622 {
|
|
623 while (1)
|
|
624 {
|
3343
|
625 if (CONSP (cons))
|
|
626 return XCAR (cons);
|
|
627 else if (NILP (cons))
|
428
|
628 return Qnil;
|
|
629 else
|
3343
|
630 cons = wrong_type_argument (Qlistp, cons);
|
428
|
631 }
|
|
632 }
|
|
633
|
|
634 DEFUN ("car-safe", Fcar_safe, 1, 1, 0, /*
|
|
635 Return the car of OBJECT if it is a cons cell, or else nil.
|
|
636 */
|
|
637 (object))
|
|
638 {
|
|
639 return CONSP (object) ? XCAR (object) : Qnil;
|
|
640 }
|
|
641
|
|
642 DEFUN ("cdr", Fcdr, 1, 1, 0, /*
|
3343
|
643 Return the cdr of CONS. If CONS is nil, return nil.
|
|
644 The cdr of a list is the list without its first element. The cdr of a
|
|
645 dotted pair (A . B) is the second element, B.
|
|
646
|
428
|
647 Error if arg is not nil and not a cons cell. See also `cdr-safe'.
|
|
648 */
|
3343
|
649 (cons))
|
428
|
650 {
|
|
651 while (1)
|
|
652 {
|
3343
|
653 if (CONSP (cons))
|
|
654 return XCDR (cons);
|
|
655 else if (NILP (cons))
|
428
|
656 return Qnil;
|
|
657 else
|
3343
|
658 cons = wrong_type_argument (Qlistp, cons);
|
428
|
659 }
|
|
660 }
|
|
661
|
|
662 DEFUN ("cdr-safe", Fcdr_safe, 1, 1, 0, /*
|
|
663 Return the cdr of OBJECT if it is a cons cell, else nil.
|
|
664 */
|
|
665 (object))
|
|
666 {
|
|
667 return CONSP (object) ? XCDR (object) : Qnil;
|
|
668 }
|
|
669
|
|
670 DEFUN ("setcar", Fsetcar, 2, 2, 0, /*
|
444
|
671 Set the car of CONS-CELL to be NEWCAR. Return NEWCAR.
|
3343
|
672 The car of a list or a dotted pair is its first element.
|
428
|
673 */
|
444
|
674 (cons_cell, newcar))
|
428
|
675 {
|
444
|
676 if (!CONSP (cons_cell))
|
|
677 cons_cell = wrong_type_argument (Qconsp, cons_cell);
|
428
|
678
|
444
|
679 XCAR (cons_cell) = newcar;
|
428
|
680 return newcar;
|
|
681 }
|
|
682
|
|
683 DEFUN ("setcdr", Fsetcdr, 2, 2, 0, /*
|
444
|
684 Set the cdr of CONS-CELL to be NEWCDR. Return NEWCDR.
|
3343
|
685 The cdr of a list is the list without its first element. The cdr of a
|
|
686 dotted pair (A . B) is the second element, B.
|
428
|
687 */
|
444
|
688 (cons_cell, newcdr))
|
428
|
689 {
|
444
|
690 if (!CONSP (cons_cell))
|
|
691 cons_cell = wrong_type_argument (Qconsp, cons_cell);
|
428
|
692
|
444
|
693 XCDR (cons_cell) = newcdr;
|
428
|
694 return newcdr;
|
|
695 }
|
|
696
|
|
697 /* Find the function at the end of a chain of symbol function indirections.
|
|
698
|
|
699 If OBJECT is a symbol, find the end of its function chain and
|
|
700 return the value found there. If OBJECT is not a symbol, just
|
|
701 return it. If there is a cycle in the function chain, signal a
|
|
702 cyclic-function-indirection error.
|
|
703
|
442
|
704 This is like Findirect_function when VOID_FUNCTION_ERRORP is true.
|
|
705 When VOID_FUNCTION_ERRORP is false, no error is signaled if the end
|
|
706 of the chain ends up being Qunbound. */
|
428
|
707 Lisp_Object
|
442
|
708 indirect_function (Lisp_Object object, int void_function_errorp)
|
428
|
709 {
|
|
710 #define FUNCTION_INDIRECTION_SUSPICION_LENGTH 16
|
|
711 Lisp_Object tortoise, hare;
|
|
712 int count;
|
|
713
|
|
714 for (hare = tortoise = object, count = 0;
|
|
715 SYMBOLP (hare);
|
|
716 hare = XSYMBOL (hare)->function, count++)
|
|
717 {
|
|
718 if (count < FUNCTION_INDIRECTION_SUSPICION_LENGTH) continue;
|
|
719
|
|
720 if (count & 1)
|
|
721 tortoise = XSYMBOL (tortoise)->function;
|
|
722 if (EQ (hare, tortoise))
|
|
723 return Fsignal (Qcyclic_function_indirection, list1 (object));
|
|
724 }
|
|
725
|
442
|
726 if (void_function_errorp && UNBOUNDP (hare))
|
436
|
727 return signal_void_function_error (object);
|
428
|
728
|
|
729 return hare;
|
|
730 }
|
|
731
|
|
732 DEFUN ("indirect-function", Findirect_function, 1, 1, 0, /*
|
|
733 Return the function at the end of OBJECT's function chain.
|
|
734 If OBJECT is a symbol, follow all function indirections and return
|
|
735 the final function binding.
|
|
736 If OBJECT is not a symbol, just return it.
|
|
737 Signal a void-function error if the final symbol is unbound.
|
|
738 Signal a cyclic-function-indirection error if there is a loop in the
|
|
739 function chain of symbols.
|
|
740 */
|
|
741 (object))
|
|
742 {
|
|
743 return indirect_function (object, 1);
|
|
744 }
|
|
745
|
|
746 /* Extract and set vector and string elements */
|
|
747
|
|
748 DEFUN ("aref", Faref, 2, 2, 0, /*
|
|
749 Return the element of ARRAY at index INDEX.
|
|
750 ARRAY may be a vector, bit vector, or string. INDEX starts at 0.
|
|
751 */
|
|
752 (array, index_))
|
|
753 {
|
|
754 EMACS_INT idx;
|
|
755
|
|
756 retry:
|
|
757
|
|
758 if (INTP (index_)) idx = XINT (index_);
|
|
759 else if (CHARP (index_)) idx = XCHAR (index_); /* yuck! */
|
|
760 else
|
|
761 {
|
|
762 index_ = wrong_type_argument (Qinteger_or_char_p, index_);
|
|
763 goto retry;
|
|
764 }
|
|
765
|
|
766 if (idx < 0) goto range_error;
|
|
767
|
|
768 if (VECTORP (array))
|
|
769 {
|
|
770 if (idx >= XVECTOR_LENGTH (array)) goto range_error;
|
|
771 return XVECTOR_DATA (array)[idx];
|
|
772 }
|
|
773 else if (BIT_VECTORP (array))
|
|
774 {
|
647
|
775 if (idx >= (EMACS_INT) bit_vector_length (XBIT_VECTOR (array)))
|
|
776 goto range_error;
|
428
|
777 return make_int (bit_vector_bit (XBIT_VECTOR (array), idx));
|
|
778 }
|
|
779 else if (STRINGP (array))
|
|
780 {
|
826
|
781 if (idx >= string_char_length (array)) goto range_error;
|
867
|
782 return make_char (string_ichar (array, idx));
|
428
|
783 }
|
|
784 #ifdef LOSING_BYTECODE
|
|
785 else if (COMPILED_FUNCTIONP (array))
|
|
786 {
|
|
787 /* Weird, gross compatibility kludge */
|
|
788 return Felt (array, index_);
|
|
789 }
|
|
790 #endif
|
|
791 else
|
|
792 {
|
|
793 check_losing_bytecode ("aref", array);
|
|
794 array = wrong_type_argument (Qarrayp, array);
|
|
795 goto retry;
|
|
796 }
|
|
797
|
|
798 range_error:
|
|
799 args_out_of_range (array, index_);
|
1204
|
800 RETURN_NOT_REACHED (Qnil);
|
428
|
801 }
|
|
802
|
|
803 DEFUN ("aset", Faset, 3, 3, 0, /*
|
|
804 Store into the element of ARRAY at index INDEX the value NEWVAL.
|
|
805 ARRAY may be a vector, bit vector, or string. INDEX starts at 0.
|
|
806 */
|
|
807 (array, index_, newval))
|
|
808 {
|
|
809 EMACS_INT idx;
|
|
810
|
|
811 retry:
|
|
812
|
|
813 if (INTP (index_)) idx = XINT (index_);
|
|
814 else if (CHARP (index_)) idx = XCHAR (index_); /* yuck! */
|
|
815 else
|
|
816 {
|
|
817 index_ = wrong_type_argument (Qinteger_or_char_p, index_);
|
|
818 goto retry;
|
|
819 }
|
|
820
|
|
821 if (idx < 0) goto range_error;
|
|
822
|
771
|
823 CHECK_LISP_WRITEABLE (array);
|
428
|
824 if (VECTORP (array))
|
|
825 {
|
|
826 if (idx >= XVECTOR_LENGTH (array)) goto range_error;
|
|
827 XVECTOR_DATA (array)[idx] = newval;
|
|
828 }
|
|
829 else if (BIT_VECTORP (array))
|
|
830 {
|
647
|
831 if (idx >= (EMACS_INT) bit_vector_length (XBIT_VECTOR (array)))
|
|
832 goto range_error;
|
428
|
833 CHECK_BIT (newval);
|
|
834 set_bit_vector_bit (XBIT_VECTOR (array), idx, !ZEROP (newval));
|
|
835 }
|
|
836 else if (STRINGP (array))
|
|
837 {
|
|
838 CHECK_CHAR_COERCE_INT (newval);
|
826
|
839 if (idx >= string_char_length (array)) goto range_error;
|
793
|
840 set_string_char (array, idx, XCHAR (newval));
|
428
|
841 bump_string_modiff (array);
|
|
842 }
|
|
843 else
|
|
844 {
|
|
845 array = wrong_type_argument (Qarrayp, array);
|
|
846 goto retry;
|
|
847 }
|
|
848
|
|
849 return newval;
|
|
850
|
|
851 range_error:
|
|
852 args_out_of_range (array, index_);
|
1204
|
853 RETURN_NOT_REACHED (Qnil);
|
428
|
854 }
|
|
855
|
|
856
|
|
857 /**********************************************************************/
|
|
858 /* Arithmetic functions */
|
|
859 /**********************************************************************/
|
2001
|
860 #ifndef WITH_NUMBER_TYPES
|
428
|
861 typedef struct
|
|
862 {
|
|
863 int int_p;
|
|
864 union
|
|
865 {
|
|
866 EMACS_INT ival;
|
|
867 double dval;
|
|
868 } c;
|
|
869 } int_or_double;
|
|
870
|
|
871 static void
|
|
872 number_char_or_marker_to_int_or_double (Lisp_Object obj, int_or_double *p)
|
|
873 {
|
|
874 retry:
|
|
875 p->int_p = 1;
|
|
876 if (INTP (obj)) p->c.ival = XINT (obj);
|
|
877 else if (CHARP (obj)) p->c.ival = XCHAR (obj);
|
|
878 else if (MARKERP (obj)) p->c.ival = marker_position (obj);
|
|
879 else if (FLOATP (obj)) p->c.dval = XFLOAT_DATA (obj), p->int_p = 0;
|
|
880 else
|
|
881 {
|
|
882 obj = wrong_type_argument (Qnumber_char_or_marker_p, obj);
|
|
883 goto retry;
|
|
884 }
|
|
885 }
|
|
886
|
|
887 static double
|
|
888 number_char_or_marker_to_double (Lisp_Object obj)
|
|
889 {
|
|
890 retry:
|
|
891 if (INTP (obj)) return (double) XINT (obj);
|
|
892 else if (CHARP (obj)) return (double) XCHAR (obj);
|
|
893 else if (MARKERP (obj)) return (double) marker_position (obj);
|
|
894 else if (FLOATP (obj)) return XFLOAT_DATA (obj);
|
|
895 else
|
|
896 {
|
|
897 obj = wrong_type_argument (Qnumber_char_or_marker_p, obj);
|
|
898 goto retry;
|
|
899 }
|
|
900 }
|
2001
|
901 #endif /* WITH_NUMBER_TYPES */
|
428
|
902
|
|
903 static EMACS_INT
|
|
904 integer_char_or_marker_to_int (Lisp_Object obj)
|
|
905 {
|
|
906 retry:
|
|
907 if (INTP (obj)) return XINT (obj);
|
|
908 else if (CHARP (obj)) return XCHAR (obj);
|
|
909 else if (MARKERP (obj)) return marker_position (obj);
|
|
910 else
|
|
911 {
|
|
912 obj = wrong_type_argument (Qinteger_char_or_marker_p, obj);
|
|
913 goto retry;
|
|
914 }
|
|
915 }
|
|
916
|
1983
|
917 #ifdef WITH_NUMBER_TYPES
|
|
918
|
|
919 #ifdef HAVE_BIGNUM
|
|
920 #define BIGNUM_CASE(op) \
|
|
921 case BIGNUM_T: \
|
|
922 if (!bignum_##op (XBIGNUM_DATA (obj1), XBIGNUM_DATA (obj2))) \
|
|
923 return Qnil; \
|
|
924 break;
|
|
925 #else
|
|
926 #define BIGNUM_CASE(op)
|
|
927 #endif /* HAVE_BIGNUM */
|
|
928
|
|
929 #ifdef HAVE_RATIO
|
|
930 #define RATIO_CASE(op) \
|
|
931 case RATIO_T: \
|
|
932 if (!ratio_##op (XRATIO_DATA (obj1), XRATIO_DATA (obj2))) \
|
|
933 return Qnil; \
|
|
934 break;
|
|
935 #else
|
|
936 #define RATIO_CASE(op)
|
|
937 #endif /* HAVE_RATIO */
|
|
938
|
|
939 #ifdef HAVE_BIGFLOAT
|
|
940 #define BIGFLOAT_CASE(op) \
|
|
941 case BIGFLOAT_T: \
|
|
942 if (!bigfloat_##op (XBIGFLOAT_DATA (obj1), XBIGFLOAT_DATA (obj2))) \
|
|
943 return Qnil; \
|
|
944 break;
|
|
945 #else
|
|
946 #define BIGFLOAT_CASE(op)
|
|
947 #endif /* HAVE_BIGFLOAT */
|
|
948
|
|
949 #define ARITHCOMPARE_MANY(c_op,op) \
|
|
950 { \
|
|
951 REGISTER int i; \
|
|
952 Lisp_Object obj1, obj2; \
|
|
953 \
|
|
954 for (i = 1; i < nargs; i++) \
|
|
955 { \
|
|
956 obj1 = args[i - 1]; \
|
|
957 obj2 = args[i]; \
|
|
958 switch (promote_args (&obj1, &obj2)) \
|
|
959 { \
|
|
960 case FIXNUM_T: \
|
|
961 if (!(XREALINT (obj1) c_op XREALINT (obj2))) \
|
|
962 return Qnil; \
|
|
963 break; \
|
|
964 BIGNUM_CASE (op) \
|
|
965 RATIO_CASE (op) \
|
|
966 case FLOAT_T: \
|
|
967 if (!(XFLOAT_DATA (obj1) c_op XFLOAT_DATA (obj2))) \
|
|
968 return Qnil; \
|
|
969 break; \
|
|
970 BIGFLOAT_CASE (op) \
|
|
971 } \
|
|
972 } \
|
|
973 return Qt; \
|
|
974 }
|
|
975 #else /* !WITH_NUMBER_TYPES */
|
|
976 #define ARITHCOMPARE_MANY(c_op,op) \
|
428
|
977 { \
|
|
978 int_or_double iod1, iod2, *p = &iod1, *q = &iod2; \
|
|
979 Lisp_Object *args_end = args + nargs; \
|
|
980 \
|
|
981 number_char_or_marker_to_int_or_double (*args++, p); \
|
|
982 \
|
|
983 while (args < args_end) \
|
|
984 { \
|
|
985 number_char_or_marker_to_int_or_double (*args++, q); \
|
|
986 \
|
|
987 if (!((p->int_p && q->int_p) ? \
|
1983
|
988 (p->c.ival c_op q->c.ival) : \
|
|
989 ((p->int_p ? (double) p->c.ival : p->c.dval) c_op \
|
428
|
990 (q->int_p ? (double) q->c.ival : q->c.dval)))) \
|
|
991 return Qnil; \
|
|
992 \
|
|
993 { /* swap */ int_or_double *r = p; p = q; q = r; } \
|
|
994 } \
|
|
995 return Qt; \
|
|
996 }
|
1983
|
997 #endif /* WITH_NUMBER_TYPES */
|
428
|
998
|
|
999 DEFUN ("=", Feqlsign, 1, MANY, 0, /*
|
|
1000 Return t if all the arguments are numerically equal.
|
|
1001 The arguments may be numbers, characters or markers.
|
|
1002 */
|
|
1003 (int nargs, Lisp_Object *args))
|
|
1004 {
|
1983
|
1005 ARITHCOMPARE_MANY (==, eql)
|
428
|
1006 }
|
|
1007
|
|
1008 DEFUN ("<", Flss, 1, MANY, 0, /*
|
|
1009 Return t if the sequence of arguments is monotonically increasing.
|
3343
|
1010
|
|
1011 (That is, if there is a second argument, it must be numerically greater than
|
|
1012 the first. If there is a third, it must be numerically greater than the
|
|
1013 second, and so on.) At least one argument is required.
|
|
1014
|
|
1015 The arguments may be numbers, characters or markers.
|
428
|
1016 */
|
|
1017 (int nargs, Lisp_Object *args))
|
|
1018 {
|
1983
|
1019 ARITHCOMPARE_MANY (<, lt)
|
428
|
1020 }
|
|
1021
|
|
1022 DEFUN (">", Fgtr, 1, MANY, 0, /*
|
|
1023 Return t if the sequence of arguments is monotonically decreasing.
|
3343
|
1024
|
|
1025 (That is, if there is a second argument, it must be numerically less than
|
|
1026 the first. If there is a third, it must be numerically less than the
|
|
1027 second, and so forth.) At least one argument is required.
|
|
1028
|
428
|
1029 The arguments may be numbers, characters or markers.
|
|
1030 */
|
|
1031 (int nargs, Lisp_Object *args))
|
|
1032 {
|
1983
|
1033 ARITHCOMPARE_MANY (>, gt)
|
428
|
1034 }
|
|
1035
|
|
1036 DEFUN ("<=", Fleq, 1, MANY, 0, /*
|
|
1037 Return t if the sequence of arguments is monotonically nondecreasing.
|
|
1038 The arguments may be numbers, characters or markers.
|
|
1039 */
|
|
1040 (int nargs, Lisp_Object *args))
|
|
1041 {
|
1983
|
1042 ARITHCOMPARE_MANY (<=, le)
|
428
|
1043 }
|
|
1044
|
|
1045 DEFUN (">=", Fgeq, 1, MANY, 0, /*
|
|
1046 Return t if the sequence of arguments is monotonically nonincreasing.
|
|
1047 The arguments may be numbers, characters or markers.
|
|
1048 */
|
|
1049 (int nargs, Lisp_Object *args))
|
|
1050 {
|
1983
|
1051 ARITHCOMPARE_MANY (>=, ge)
|
428
|
1052 }
|
|
1053
|
1983
|
1054 /* Unlike all the other comparisons, this is an O(N*N) algorithm. But who
|
|
1055 cares? Inspection of all elisp code distributed by xemacs.org shows that
|
|
1056 it is almost always called with 2 arguments, rarely with 3, and never with
|
|
1057 more than 3. The constant factors of algorithms with better asymptotic
|
|
1058 complexity are higher, which means that those algorithms will run SLOWER
|
|
1059 than this one in the common case. Optimize the common case! */
|
428
|
1060 DEFUN ("/=", Fneq, 1, MANY, 0, /*
|
|
1061 Return t if no two arguments are numerically equal.
|
|
1062 The arguments may be numbers, characters or markers.
|
|
1063 */
|
|
1064 (int nargs, Lisp_Object *args))
|
|
1065 {
|
1983
|
1066 #ifdef WITH_NUMBER_TYPES
|
|
1067 REGISTER int i, j;
|
|
1068 Lisp_Object obj1, obj2;
|
|
1069
|
|
1070 for (i = 0; i < nargs - 1; i++)
|
|
1071 {
|
|
1072 obj1 = args[i];
|
|
1073 for (j = i + 1; j < nargs; j++)
|
|
1074 {
|
|
1075 obj2 = args[j];
|
|
1076 switch (promote_args (&obj1, &obj2))
|
|
1077 {
|
|
1078 case FIXNUM_T:
|
|
1079 if (XREALINT (obj1) == XREALINT (obj2))
|
|
1080 return Qnil;
|
|
1081 break;
|
|
1082 #ifdef HAVE_BIGNUM
|
|
1083 case BIGNUM_T:
|
|
1084 if (bignum_eql (XBIGNUM_DATA (obj1), XBIGNUM_DATA (obj2)))
|
|
1085 return Qnil;
|
|
1086 break;
|
|
1087 #endif
|
|
1088 #ifdef HAVE_RATIO
|
|
1089 case RATIO_T:
|
|
1090 if (ratio_eql (XRATIO_DATA (obj1), XRATIO_DATA (obj2)))
|
|
1091 return Qnil;
|
|
1092 break;
|
|
1093 #endif
|
|
1094 case FLOAT_T:
|
|
1095 if (XFLOAT_DATA (obj1) == XFLOAT_DATA (obj2))
|
|
1096 return Qnil;
|
|
1097 break;
|
|
1098 #ifdef HAVE_BIGFLOAT
|
|
1099 case BIGFLOAT_T:
|
|
1100 if (bigfloat_eql (XBIGFLOAT_DATA (obj1), XBIGFLOAT_DATA (obj2)))
|
|
1101 return Qnil;
|
|
1102 break;
|
|
1103 #endif
|
|
1104 }
|
|
1105 }
|
|
1106 }
|
|
1107 return Qt;
|
|
1108 #else /* !WITH_NUMBER_TYPES */
|
428
|
1109 Lisp_Object *args_end = args + nargs;
|
|
1110 Lisp_Object *p, *q;
|
|
1111
|
|
1112 /* Unlike all the other comparisons, this is an N*N algorithm.
|
|
1113 We could use a hash table for nargs > 50 to make this linear. */
|
|
1114 for (p = args; p < args_end; p++)
|
|
1115 {
|
|
1116 int_or_double iod1, iod2;
|
|
1117 number_char_or_marker_to_int_or_double (*p, &iod1);
|
|
1118
|
|
1119 for (q = p + 1; q < args_end; q++)
|
|
1120 {
|
|
1121 number_char_or_marker_to_int_or_double (*q, &iod2);
|
|
1122
|
|
1123 if (!((iod1.int_p && iod2.int_p) ?
|
|
1124 (iod1.c.ival != iod2.c.ival) :
|
|
1125 ((iod1.int_p ? (double) iod1.c.ival : iod1.c.dval) !=
|
|
1126 (iod2.int_p ? (double) iod2.c.ival : iod2.c.dval))))
|
|
1127 return Qnil;
|
|
1128 }
|
|
1129 }
|
|
1130 return Qt;
|
1983
|
1131 #endif /* WITH_NUMBER_TYPES */
|
428
|
1132 }
|
|
1133
|
|
1134 DEFUN ("zerop", Fzerop, 1, 1, 0, /*
|
|
1135 Return t if NUMBER is zero.
|
|
1136 */
|
|
1137 (number))
|
|
1138 {
|
|
1139 retry:
|
|
1140 if (INTP (number))
|
|
1141 return EQ (number, Qzero) ? Qt : Qnil;
|
1983
|
1142 #ifdef HAVE_BIGNUM
|
|
1143 else if (BIGNUMP (number))
|
|
1144 return bignum_sign (XBIGNUM_DATA (number)) == 0 ? Qt : Qnil;
|
|
1145 #endif
|
|
1146 #ifdef HAVE_RATIO
|
|
1147 else if (RATIOP (number))
|
|
1148 return ratio_sign (XRATIO_DATA (number)) == 0 ? Qt : Qnil;
|
|
1149 #endif
|
428
|
1150 else if (FLOATP (number))
|
|
1151 return XFLOAT_DATA (number) == 0.0 ? Qt : Qnil;
|
1983
|
1152 #ifdef HAVE_BIGFLOAT
|
|
1153 else if (BIGFLOATP (number))
|
|
1154 return bigfloat_sign (XBIGFLOAT_DATA (number)) == 0 ? Qt : Qnil;
|
|
1155 #endif
|
428
|
1156 else
|
|
1157 {
|
|
1158 number = wrong_type_argument (Qnumberp, number);
|
|
1159 goto retry;
|
|
1160 }
|
|
1161 }
|
|
1162
|
|
1163 /* Convert between a 32-bit value and a cons of two 16-bit values.
|
|
1164 This is used to pass 32-bit integers to and from the user.
|
|
1165 Use time_to_lisp() and lisp_to_time() for time values.
|
|
1166
|
|
1167 If you're thinking of using this to store a pointer into a Lisp Object
|
|
1168 for internal purposes (such as when calling record_unwind_protect()),
|
|
1169 try using make_opaque_ptr()/get_opaque_ptr() instead. */
|
|
1170 Lisp_Object
|
|
1171 word_to_lisp (unsigned int item)
|
|
1172 {
|
|
1173 return Fcons (make_int (item >> 16), make_int (item & 0xffff));
|
|
1174 }
|
|
1175
|
|
1176 unsigned int
|
|
1177 lisp_to_word (Lisp_Object item)
|
|
1178 {
|
|
1179 if (INTP (item))
|
|
1180 return XINT (item);
|
|
1181 else
|
|
1182 {
|
|
1183 Lisp_Object top = Fcar (item);
|
|
1184 Lisp_Object bot = Fcdr (item);
|
|
1185 CHECK_INT (top);
|
|
1186 CHECK_INT (bot);
|
|
1187 return (XINT (top) << 16) | (XINT (bot) & 0xffff);
|
|
1188 }
|
|
1189 }
|
|
1190
|
|
1191
|
|
1192 DEFUN ("number-to-string", Fnumber_to_string, 1, 1, 0, /*
|
444
|
1193 Convert NUMBER to a string by printing it in decimal.
|
428
|
1194 Uses a minus sign if negative.
|
444
|
1195 NUMBER may be an integer or a floating point number.
|
1983
|
1196 If supported, it may also be a ratio.
|
428
|
1197 */
|
444
|
1198 (number))
|
428
|
1199 {
|
1983
|
1200 #ifdef WITH_NUMBER_TYPES
|
|
1201 CHECK_NUMBER (number);
|
|
1202 #else
|
444
|
1203 CHECK_INT_OR_FLOAT (number);
|
1983
|
1204 #endif
|
428
|
1205
|
444
|
1206 if (FLOATP (number))
|
428
|
1207 {
|
|
1208 char pigbuf[350]; /* see comments in float_to_string */
|
|
1209
|
444
|
1210 float_to_string (pigbuf, XFLOAT_DATA (number));
|
428
|
1211 return build_string (pigbuf);
|
|
1212 }
|
1983
|
1213 #ifdef HAVE_BIGNUM
|
|
1214 if (BIGNUMP (number))
|
|
1215 {
|
|
1216 char *str = bignum_to_string (XBIGNUM_DATA (number), 10);
|
|
1217 Lisp_Object retval = build_string (str);
|
|
1218 xfree (str, char *);
|
|
1219 return retval;
|
|
1220 }
|
|
1221 #endif
|
|
1222 #ifdef HAVE_RATIO
|
|
1223 if (RATIOP (number))
|
|
1224 {
|
|
1225 char *str = ratio_to_string (XRATIO_DATA (number), 10);
|
|
1226 Lisp_Object retval = build_string (str);
|
|
1227 xfree (str, char *);
|
|
1228 return retval;
|
|
1229 }
|
|
1230 #endif
|
|
1231 #ifdef HAVE_BIGFLOAT
|
|
1232 if (BIGFLOATP (number))
|
|
1233 {
|
|
1234 char *str = bigfloat_to_string (XBIGFLOAT_DATA (number), 10);
|
|
1235 Lisp_Object retval = build_string (str);
|
|
1236 xfree (str, char *);
|
|
1237 return retval;
|
|
1238 }
|
|
1239 #endif
|
428
|
1240
|
603
|
1241 {
|
|
1242 char buffer[DECIMAL_PRINT_SIZE (long)];
|
|
1243
|
|
1244 long_to_string (buffer, XINT (number));
|
|
1245 return build_string (buffer);
|
|
1246 }
|
428
|
1247 }
|
|
1248
|
2001
|
1249 #ifndef HAVE_BIGNUM
|
428
|
1250 static int
|
|
1251 digit_to_number (int character, int base)
|
|
1252 {
|
|
1253 /* Assumes ASCII */
|
|
1254 int digit = ((character >= '0' && character <= '9') ? character - '0' :
|
|
1255 (character >= 'a' && character <= 'z') ? character - 'a' + 10 :
|
|
1256 (character >= 'A' && character <= 'Z') ? character - 'A' + 10 :
|
|
1257 -1);
|
|
1258
|
|
1259 return digit >= base ? -1 : digit;
|
|
1260 }
|
2001
|
1261 #endif
|
428
|
1262
|
|
1263 DEFUN ("string-to-number", Fstring_to_number, 1, 2, 0, /*
|
444
|
1264 Convert STRING to a number by parsing it as a number in base BASE.
|
428
|
1265 This parses both integers and floating point numbers.
|
1983
|
1266 If they are supported, it also reads ratios.
|
428
|
1267 It ignores leading spaces and tabs.
|
|
1268
|
444
|
1269 If BASE is nil or omitted, base 10 is used.
|
|
1270 BASE must be an integer between 2 and 16 (inclusive).
|
428
|
1271 Floating point numbers always use base 10.
|
|
1272 */
|
|
1273 (string, base))
|
|
1274 {
|
1995
|
1275 Ibyte *p;
|
428
|
1276 int b;
|
|
1277
|
|
1278 CHECK_STRING (string);
|
|
1279
|
|
1280 if (NILP (base))
|
|
1281 b = 10;
|
|
1282 else
|
|
1283 {
|
|
1284 CHECK_INT (base);
|
|
1285 b = XINT (base);
|
|
1286 check_int_range (b, 2, 16);
|
|
1287 }
|
|
1288
|
1995
|
1289 p = XSTRING_DATA (string);
|
428
|
1290
|
|
1291 /* Skip any whitespace at the front of the number. Some versions of
|
|
1292 atoi do this anyway, so we might as well make Emacs lisp consistent. */
|
|
1293 while (*p == ' ' || *p == '\t')
|
|
1294 p++;
|
|
1295
|
1995
|
1296 if (isfloat_string ((const char *) p) && b == 10)
|
1983
|
1297 {
|
|
1298 #ifdef HAVE_BIGFLOAT
|
|
1299 if (ZEROP (Vdefault_float_precision))
|
|
1300 #endif
|
1995
|
1301 return make_float (atof ((const char *) p));
|
1983
|
1302 #ifdef HAVE_BIGFLOAT
|
|
1303 else
|
|
1304 {
|
2013
|
1305 /* The GMP version of bigfloat_set_string (mpf_set_str) has the
|
|
1306 following limitation: if p starts with a '+' sign, it does
|
|
1307 nothing; i.e., it leaves its bigfloat argument untouched.
|
|
1308 Therefore, move p past any leading '+' signs. */
|
2010
|
1309 if (*p == '+')
|
|
1310 p++;
|
1983
|
1311 bigfloat_set_prec (scratch_bigfloat, bigfloat_get_default_prec ());
|
1995
|
1312 bigfloat_set_string (scratch_bigfloat, (const char *) p, b);
|
1983
|
1313 return make_bigfloat_bf (scratch_bigfloat);
|
|
1314 }
|
|
1315 #endif
|
|
1316 }
|
|
1317
|
|
1318 #ifdef HAVE_RATIO
|
|
1319 if (qxestrchr (p, '/') != NULL)
|
|
1320 {
|
2013
|
1321 /* The GMP version of ratio_set_string (mpq_set_str) has the following
|
|
1322 limitations:
|
|
1323 - If p starts with a '+' sign, it does nothing; i.e., it leaves its
|
|
1324 ratio argument untouched.
|
|
1325 - If p has a '+' sign after the '/' (e.g., 300/+400), it sets the
|
|
1326 numerator from the string, but *leaves the denominator unchanged*.
|
|
1327 - If p has trailing nonnumeric characters, it sets the numerator from
|
|
1328 the string, but leaves the denominator unchanged.
|
|
1329 - If p has more than one '/', (e.g., 1/2/3), then it sets the
|
|
1330 numerator from the string, but leaves the denominator unchanged.
|
|
1331
|
|
1332 Therefore, move p past any leading '+' signs, temporarily drop a null
|
|
1333 after the numeric characters we are trying to convert, and then put
|
|
1334 the nulled character back afterward. I am not going to fix problem
|
|
1335 #2; just don't write ratios that look like that. */
|
|
1336 Ibyte *end, save;
|
|
1337
|
2010
|
1338 if (*p == '+')
|
|
1339 p++;
|
2013
|
1340
|
2014
|
1341 end = p;
|
|
1342 if (*end == '-')
|
|
1343 end++;
|
|
1344 while ((*end >= '0' && *end <= '9') ||
|
2013
|
1345 (b > 10 && *end >= 'a' && *end <= 'a' + b - 11) ||
|
2014
|
1346 (b > 10 && *end >= 'A' && *end <= 'A' + b - 11))
|
|
1347 end++;
|
2013
|
1348 if (*end == '/')
|
2014
|
1349 {
|
|
1350 end++;
|
|
1351 if (*end == '-')
|
|
1352 end++;
|
|
1353 while ((*end >= '0' && *end <= '9') ||
|
|
1354 (b > 10 && *end >= 'a' && *end <= 'a' + b - 11) ||
|
|
1355 (b > 10 && *end >= 'A' && *end <= 'A' + b - 11))
|
|
1356 end++;
|
|
1357 }
|
2013
|
1358 save = *end;
|
|
1359 *end = '\0';
|
1995
|
1360 ratio_set_string (scratch_ratio, (const char *) p, b);
|
2013
|
1361 *end = save;
|
|
1362 ratio_canonicalize (scratch_ratio);
|
1983
|
1363 return make_ratio_rt (scratch_ratio);
|
|
1364 }
|
|
1365 #endif /* HAVE_RATIO */
|
|
1366
|
|
1367 #ifdef HAVE_BIGNUM
|
2013
|
1368 {
|
|
1369 /* The GMP version of bignum_set_string (mpz_set_str) has the following
|
|
1370 limitations:
|
|
1371 - If p starts with a '+' sign, it does nothing; i.e., it leaves its
|
|
1372 bignum argument untouched.
|
|
1373 - If p is the empty string, it does nothing.
|
|
1374 - If p has trailing nonnumeric characters, it does nothing.
|
|
1375
|
|
1376 Therefore, move p past any leading '+' signs, temporarily drop a null
|
|
1377 after the numeric characters we are trying to convert, special case the
|
|
1378 empty string, and then put the nulled character back afterward. */
|
|
1379 Ibyte *end, save;
|
|
1380 Lisp_Object retval;
|
|
1381
|
|
1382 if (*p == '+')
|
|
1383 p++;
|
2014
|
1384 end = p;
|
|
1385 if (*end == '-')
|
|
1386 end++;
|
|
1387 while ((*end >= '0' && *end <= '9') ||
|
2013
|
1388 (b > 10 && *end >= 'a' && *end <= 'a' + b - 11) ||
|
2014
|
1389 (b > 10 && *end >= 'A' && *end <= 'A' + b - 11))
|
|
1390 end++;
|
2013
|
1391 save = *end;
|
|
1392 *end = '\0';
|
|
1393 if (*p == '\0')
|
|
1394 retval = make_int (0);
|
|
1395 else
|
|
1396 {
|
|
1397 bignum_set_string (scratch_bignum, (const char *) p, b);
|
|
1398 retval = Fcanonicalize_number (make_bignum_bg (scratch_bignum));
|
|
1399 }
|
|
1400 *end = save;
|
|
1401 return retval;
|
|
1402 }
|
1983
|
1403 #else
|
428
|
1404 if (b == 10)
|
|
1405 {
|
|
1406 /* Use the system-provided functions for base 10. */
|
|
1407 #if SIZEOF_EMACS_INT == SIZEOF_INT
|
2054
|
1408 return make_int (atoi ((char*) p));
|
428
|
1409 #elif SIZEOF_EMACS_INT == SIZEOF_LONG
|
2054
|
1410 return make_int (atol ((char*) p));
|
428
|
1411 #elif SIZEOF_EMACS_INT == SIZEOF_LONG_LONG
|
2054
|
1412 return make_int (atoll ((char*) p));
|
428
|
1413 #endif
|
|
1414 }
|
|
1415 else
|
|
1416 {
|
444
|
1417 int negative = 1;
|
428
|
1418 EMACS_INT v = 0;
|
|
1419
|
|
1420 if (*p == '-')
|
|
1421 {
|
|
1422 negative = -1;
|
|
1423 p++;
|
|
1424 }
|
|
1425 else if (*p == '+')
|
|
1426 p++;
|
|
1427 while (1)
|
|
1428 {
|
444
|
1429 int digit = digit_to_number (*p++, b);
|
428
|
1430 if (digit < 0)
|
|
1431 break;
|
|
1432 v = v * b + digit;
|
|
1433 }
|
|
1434 return make_int (negative * v);
|
|
1435 }
|
1983
|
1436 #endif /* HAVE_BIGNUM */
|
428
|
1437 }
|
|
1438
|
|
1439
|
|
1440 DEFUN ("+", Fplus, 0, MANY, 0, /*
|
|
1441 Return sum of any number of arguments.
|
|
1442 The arguments should all be numbers, characters or markers.
|
|
1443 */
|
|
1444 (int nargs, Lisp_Object *args))
|
|
1445 {
|
1983
|
1446 #ifdef WITH_NUMBER_TYPES
|
|
1447 REGISTER int i;
|
|
1448 Lisp_Object accum = make_int (0), addend;
|
|
1449
|
|
1450 for (i = 0; i < nargs; i++)
|
|
1451 {
|
|
1452 addend = args[i];
|
|
1453 switch (promote_args (&accum, &addend))
|
|
1454 {
|
|
1455 case FIXNUM_T:
|
|
1456 accum = make_integer (XREALINT (accum) + XREALINT (addend));
|
|
1457 break;
|
|
1458 #ifdef HAVE_BIGNUM
|
|
1459 case BIGNUM_T:
|
|
1460 bignum_add (scratch_bignum, XBIGNUM_DATA (accum),
|
|
1461 XBIGNUM_DATA (addend));
|
|
1462 accum = make_bignum_bg (scratch_bignum);
|
|
1463 break;
|
|
1464 #endif
|
|
1465 #ifdef HAVE_RATIO
|
|
1466 case RATIO_T:
|
|
1467 ratio_add (scratch_ratio, XRATIO_DATA (accum),
|
|
1468 XRATIO_DATA (addend));
|
|
1469 accum = make_ratio_rt (scratch_ratio);
|
|
1470 break;
|
|
1471 #endif
|
|
1472 case FLOAT_T:
|
|
1473 accum = make_float (XFLOAT_DATA (accum) + XFLOAT_DATA (addend));
|
|
1474 break;
|
|
1475 #ifdef HAVE_BIGFLOAT
|
|
1476 case BIGFLOAT_T:
|
|
1477 bigfloat_set_prec (scratch_bigfloat,
|
|
1478 max (XBIGFLOAT_GET_PREC (addend),
|
|
1479 XBIGFLOAT_GET_PREC (accum)));
|
|
1480 bigfloat_add (scratch_bigfloat, XBIGFLOAT_DATA (accum),
|
|
1481 XBIGFLOAT_DATA (addend));
|
|
1482 accum = make_bigfloat_bf (scratch_bigfloat);
|
|
1483 break;
|
|
1484 #endif
|
|
1485 }
|
|
1486 }
|
|
1487 return Fcanonicalize_number (accum);
|
|
1488 #else /* !WITH_NUMBER_TYPES */
|
428
|
1489 EMACS_INT iaccum = 0;
|
|
1490 Lisp_Object *args_end = args + nargs;
|
|
1491
|
|
1492 while (args < args_end)
|
|
1493 {
|
|
1494 int_or_double iod;
|
|
1495 number_char_or_marker_to_int_or_double (*args++, &iod);
|
|
1496 if (iod.int_p)
|
|
1497 iaccum += iod.c.ival;
|
|
1498 else
|
|
1499 {
|
|
1500 double daccum = (double) iaccum + iod.c.dval;
|
|
1501 while (args < args_end)
|
|
1502 daccum += number_char_or_marker_to_double (*args++);
|
|
1503 return make_float (daccum);
|
|
1504 }
|
|
1505 }
|
|
1506
|
|
1507 return make_int (iaccum);
|
1983
|
1508 #endif /* WITH_NUMBER_TYPES */
|
428
|
1509 }
|
|
1510
|
|
1511 DEFUN ("-", Fminus, 1, MANY, 0, /*
|
|
1512 Negate number or subtract numbers, characters or markers.
|
|
1513 With one arg, negates it. With more than one arg,
|
|
1514 subtracts all but the first from the first.
|
|
1515 */
|
|
1516 (int nargs, Lisp_Object *args))
|
|
1517 {
|
1983
|
1518 #ifdef WITH_NUMBER_TYPES
|
|
1519 REGISTER int i;
|
|
1520 Lisp_Object accum = args[0], subtrahend;
|
|
1521
|
|
1522 if (nargs == 1)
|
|
1523 {
|
|
1524 if (CHARP (accum))
|
|
1525 accum = make_int (XCHAR (accum));
|
|
1526 else if (MARKERP (accum))
|
|
1527 accum = make_int (marker_position (accum));
|
|
1528
|
|
1529 /* Invert the sign of accum */
|
|
1530 CHECK_NUMBER (accum);
|
|
1531 switch (get_number_type (accum))
|
|
1532 {
|
|
1533 case FIXNUM_T:
|
|
1534 return make_integer (-XREALINT (accum));
|
|
1535 #ifdef HAVE_BIGNUM
|
|
1536 case BIGNUM_T:
|
|
1537 bignum_neg (scratch_bignum, XBIGNUM_DATA (accum));
|
|
1538 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
|
|
1539 #endif
|
|
1540 #ifdef HAVE_RATIO
|
|
1541 case RATIO_T:
|
|
1542 ratio_neg (scratch_ratio, XRATIO_DATA (accum));
|
|
1543 return make_ratio_rt (scratch_ratio);
|
|
1544 #endif
|
|
1545 case FLOAT_T:
|
|
1546 return make_float (-XFLOAT_DATA (accum));
|
|
1547 #ifdef HAVE_BIGFLOAT
|
|
1548 case BIGFLOAT_T:
|
|
1549 bigfloat_set_prec (scratch_bigfloat, XBIGFLOAT_GET_PREC (accum));
|
|
1550 bigfloat_neg (scratch_bigfloat, XBIGFLOAT_DATA (accum));
|
|
1551 return make_bigfloat_bf (scratch_bigfloat);
|
|
1552 #endif
|
|
1553 }
|
|
1554 }
|
|
1555 else
|
|
1556 {
|
|
1557 /* Subtrace the remaining arguments from accum */
|
|
1558 for (i = 1; i < nargs; i++)
|
|
1559 {
|
|
1560 subtrahend = args[i];
|
|
1561 switch (promote_args (&accum, &subtrahend))
|
|
1562 {
|
|
1563 case FIXNUM_T:
|
|
1564 accum = make_integer (XREALINT (accum) - XREALINT (subtrahend));
|
|
1565 break;
|
|
1566 #ifdef HAVE_BIGNUM
|
|
1567 case BIGNUM_T:
|
|
1568 bignum_sub (scratch_bignum, XBIGNUM_DATA (accum),
|
|
1569 XBIGNUM_DATA (subtrahend));
|
|
1570 accum = make_bignum_bg (scratch_bignum);
|
|
1571 break;
|
|
1572 #endif
|
|
1573 #ifdef HAVE_RATIO
|
|
1574 case RATIO_T:
|
|
1575 ratio_sub (scratch_ratio, XRATIO_DATA (accum),
|
|
1576 XRATIO_DATA (subtrahend));
|
|
1577 accum = make_ratio_rt (scratch_ratio);
|
|
1578 break;
|
|
1579 #endif
|
|
1580 case FLOAT_T:
|
|
1581 accum =
|
|
1582 make_float (XFLOAT_DATA (accum) - XFLOAT_DATA (subtrahend));
|
|
1583 break;
|
|
1584 #ifdef HAVE_BIGFLOAT
|
|
1585 case BIGFLOAT_T:
|
|
1586 bigfloat_set_prec (scratch_bigfloat,
|
|
1587 max (XBIGFLOAT_GET_PREC (subtrahend),
|
|
1588 XBIGFLOAT_GET_PREC (accum)));
|
|
1589 bigfloat_sub (scratch_bigfloat, XBIGFLOAT_DATA (accum),
|
|
1590 XBIGFLOAT_DATA (subtrahend));
|
|
1591 accum = make_bigfloat_bf (scratch_bigfloat);
|
|
1592 break;
|
|
1593 #endif
|
|
1594 }
|
|
1595 }
|
|
1596 }
|
|
1597 return Fcanonicalize_number (accum);
|
|
1598 #else /* !WITH_NUMBER_TYPES */
|
428
|
1599 EMACS_INT iaccum;
|
|
1600 double daccum;
|
|
1601 Lisp_Object *args_end = args + nargs;
|
|
1602 int_or_double iod;
|
|
1603
|
|
1604 number_char_or_marker_to_int_or_double (*args++, &iod);
|
|
1605 if (iod.int_p)
|
|
1606 iaccum = nargs > 1 ? iod.c.ival : - iod.c.ival;
|
|
1607 else
|
|
1608 {
|
|
1609 daccum = nargs > 1 ? iod.c.dval : - iod.c.dval;
|
|
1610 goto do_float;
|
|
1611 }
|
|
1612
|
|
1613 while (args < args_end)
|
|
1614 {
|
|
1615 number_char_or_marker_to_int_or_double (*args++, &iod);
|
|
1616 if (iod.int_p)
|
|
1617 iaccum -= iod.c.ival;
|
|
1618 else
|
|
1619 {
|
|
1620 daccum = (double) iaccum - iod.c.dval;
|
|
1621 goto do_float;
|
|
1622 }
|
|
1623 }
|
|
1624
|
|
1625 return make_int (iaccum);
|
|
1626
|
|
1627 do_float:
|
|
1628 for (; args < args_end; args++)
|
|
1629 daccum -= number_char_or_marker_to_double (*args);
|
|
1630 return make_float (daccum);
|
1983
|
1631 #endif /* WITH_NUMBER_TYPES */
|
428
|
1632 }
|
|
1633
|
|
1634 DEFUN ("*", Ftimes, 0, MANY, 0, /*
|
|
1635 Return product of any number of arguments.
|
|
1636 The arguments should all be numbers, characters or markers.
|
|
1637 */
|
|
1638 (int nargs, Lisp_Object *args))
|
|
1639 {
|
1983
|
1640 #ifdef WITH_NUMBER_TYPES
|
|
1641 REGISTER int i;
|
|
1642 /* Start with a bignum to avoid overflow */
|
|
1643 Lisp_Object accum = make_bignum (1L), multiplier;
|
|
1644
|
|
1645 for (i = 0; i < nargs; i++)
|
|
1646 {
|
|
1647 multiplier = args[i];
|
|
1648 switch (promote_args (&accum, &multiplier))
|
|
1649 {
|
|
1650 #ifdef HAVE_BIGNUM
|
|
1651 case BIGNUM_T:
|
|
1652 bignum_mul (scratch_bignum, XBIGNUM_DATA (accum),
|
|
1653 XBIGNUM_DATA (multiplier));
|
|
1654 accum = make_bignum_bg (scratch_bignum);
|
|
1655 break;
|
|
1656 #endif
|
|
1657 #ifdef HAVE_RATIO
|
|
1658 case RATIO_T:
|
|
1659 ratio_mul (scratch_ratio, XRATIO_DATA (accum),
|
|
1660 XRATIO_DATA (multiplier));
|
|
1661 accum = make_ratio_rt (scratch_ratio);
|
|
1662 break;
|
|
1663 #endif
|
|
1664 case FLOAT_T:
|
|
1665 accum = make_float (XFLOAT_DATA (accum) * XFLOAT_DATA (multiplier));
|
|
1666 break;
|
|
1667 #ifdef HAVE_BIGFLOAT
|
|
1668 case BIGFLOAT_T:
|
|
1669 bigfloat_set_prec (scratch_bigfloat,
|
|
1670 max (XBIGFLOAT_GET_PREC (multiplier),
|
|
1671 XBIGFLOAT_GET_PREC (accum)));
|
|
1672 bigfloat_mul (scratch_bigfloat, XBIGFLOAT_DATA (accum),
|
|
1673 XBIGFLOAT_DATA (multiplier));
|
|
1674 accum = make_bigfloat_bf (scratch_bigfloat);
|
|
1675 break;
|
|
1676 #endif
|
|
1677 }
|
|
1678 }
|
|
1679 return Fcanonicalize_number (accum);
|
|
1680 #else /* !WITH_NUMBER_TYPES */
|
428
|
1681 EMACS_INT iaccum = 1;
|
|
1682 Lisp_Object *args_end = args + nargs;
|
|
1683
|
|
1684 while (args < args_end)
|
|
1685 {
|
|
1686 int_or_double iod;
|
|
1687 number_char_or_marker_to_int_or_double (*args++, &iod);
|
|
1688 if (iod.int_p)
|
|
1689 iaccum *= iod.c.ival;
|
|
1690 else
|
|
1691 {
|
|
1692 double daccum = (double) iaccum * iod.c.dval;
|
|
1693 while (args < args_end)
|
|
1694 daccum *= number_char_or_marker_to_double (*args++);
|
|
1695 return make_float (daccum);
|
|
1696 }
|
|
1697 }
|
|
1698
|
|
1699 return make_int (iaccum);
|
1983
|
1700 #endif /* WITH_NUMBER_TYPES */
|
428
|
1701 }
|
|
1702
|
1983
|
1703 #ifdef HAVE_RATIO
|
|
1704 DEFUN ("div", Fdiv, 1, MANY, 0, /*
|
|
1705 Same as `/', but dividing integers creates a ratio instead of truncating.
|
|
1706 Note that this is a departure from Common Lisp, where / creates ratios when
|
|
1707 dividing integers. Having a separate function lets us avoid breaking existing
|
|
1708 Emacs Lisp code that expects / to do integer division.
|
|
1709 */
|
|
1710 (int nargs, Lisp_Object *args))
|
|
1711 {
|
|
1712 REGISTER int i;
|
|
1713 Lisp_Object accum, divisor;
|
|
1714
|
|
1715 if (nargs == 1)
|
|
1716 {
|
|
1717 i = 0;
|
|
1718 accum = make_int (1);
|
|
1719 }
|
|
1720 else
|
|
1721 {
|
|
1722 i = 1;
|
|
1723 accum = args[0];
|
|
1724 }
|
|
1725 for (; i < nargs; i++)
|
|
1726 {
|
|
1727 divisor = args[i];
|
|
1728 switch (promote_args (&accum, &divisor))
|
|
1729 {
|
|
1730 case FIXNUM_T:
|
|
1731 if (XREALINT (divisor) == 0) goto divide_by_zero;
|
|
1732 bignum_set_long (scratch_bignum, XREALINT (accum));
|
|
1733 bignum_set_long (scratch_bignum2, XREALINT (divisor));
|
|
1734 accum = make_ratio_bg (scratch_bignum, scratch_bignum2);
|
|
1735 break;
|
|
1736 case BIGNUM_T:
|
|
1737 if (bignum_sign (XBIGNUM_DATA (divisor)) == 0) goto divide_by_zero;
|
|
1738 accum = make_ratio_bg (XBIGNUM_DATA (accum), XBIGNUM_DATA (divisor));
|
|
1739 break;
|
|
1740 case RATIO_T:
|
|
1741 if (ratio_sign (XRATIO_DATA (divisor)) == 0) goto divide_by_zero;
|
|
1742 ratio_div (scratch_ratio, XRATIO_DATA (accum),
|
|
1743 XRATIO_DATA (divisor));
|
|
1744 accum = make_ratio_rt (scratch_ratio);
|
|
1745 break;
|
|
1746 case FLOAT_T:
|
|
1747 if (XFLOAT_DATA (divisor) == 0.0) goto divide_by_zero;
|
|
1748 accum = make_float (XFLOAT_DATA (accum) / XFLOAT_DATA (divisor));
|
|
1749 break;
|
|
1750 #ifdef HAVE_BIGFLOAT
|
|
1751 case BIGFLOAT_T:
|
|
1752 if (bigfloat_sign (XBIGFLOAT_DATA (divisor)) == 0)
|
|
1753 goto divide_by_zero;
|
|
1754 bigfloat_set_prec (scratch_bigfloat,
|
|
1755 max (XBIGFLOAT_GET_PREC (divisor),
|
|
1756 XBIGFLOAT_GET_PREC (accum)));
|
|
1757 bigfloat_div (scratch_bigfloat, XBIGFLOAT_DATA (accum),
|
|
1758 XBIGFLOAT_DATA (divisor));
|
|
1759 accum = make_bigfloat_bf (scratch_bigfloat);
|
|
1760 break;
|
|
1761 #endif
|
|
1762 }
|
|
1763 }
|
|
1764 return Fcanonicalize_number (accum);
|
|
1765
|
|
1766 divide_by_zero:
|
|
1767 Fsignal (Qarith_error, Qnil);
|
|
1768 return Qnil; /* not (usually) reached */
|
|
1769 }
|
|
1770 #endif /* HAVE_RATIO */
|
|
1771
|
428
|
1772 DEFUN ("/", Fquo, 1, MANY, 0, /*
|
|
1773 Return first argument divided by all the remaining arguments.
|
|
1774 The arguments must be numbers, characters or markers.
|
|
1775 With one argument, reciprocates the argument.
|
|
1776 */
|
|
1777 (int nargs, Lisp_Object *args))
|
|
1778 {
|
1983
|
1779 #ifdef WITH_NUMBER_TYPES
|
|
1780 REGISTER int i;
|
|
1781 Lisp_Object accum, divisor;
|
|
1782
|
|
1783 if (nargs == 1)
|
|
1784 {
|
|
1785 i = 0;
|
|
1786 accum = make_int (1);
|
|
1787 }
|
|
1788 else
|
|
1789 {
|
|
1790 i = 1;
|
|
1791 accum = args[0];
|
|
1792 }
|
|
1793 for (; i < nargs; i++)
|
|
1794 {
|
|
1795 divisor = args[i];
|
|
1796 switch (promote_args (&accum, &divisor))
|
|
1797 {
|
|
1798 case FIXNUM_T:
|
|
1799 if (XREALINT (divisor) == 0) goto divide_by_zero;
|
|
1800 accum = make_integer (XREALINT (accum) / XREALINT (divisor));
|
|
1801 break;
|
|
1802 #ifdef HAVE_BIGNUM
|
|
1803 case BIGNUM_T:
|
|
1804 if (bignum_sign (XBIGNUM_DATA (divisor)) == 0) goto divide_by_zero;
|
|
1805 bignum_div (scratch_bignum, XBIGNUM_DATA (accum),
|
|
1806 XBIGNUM_DATA (divisor));
|
|
1807 accum = make_bignum_bg (scratch_bignum);
|
|
1808 break;
|
|
1809 #endif
|
|
1810 #ifdef HAVE_RATIO
|
|
1811 case RATIO_T:
|
|
1812 if (ratio_sign (XRATIO_DATA (divisor)) == 0) goto divide_by_zero;
|
|
1813 ratio_div (scratch_ratio, XRATIO_DATA (accum),
|
|
1814 XRATIO_DATA (divisor));
|
|
1815 accum = make_ratio_rt (scratch_ratio);
|
|
1816 break;
|
|
1817 #endif
|
|
1818 case FLOAT_T:
|
|
1819 if (XFLOAT_DATA (divisor) == 0.0) goto divide_by_zero;
|
|
1820 accum = make_float (XFLOAT_DATA (accum) / XFLOAT_DATA (divisor));
|
|
1821 break;
|
|
1822 #ifdef HAVE_BIGFLOAT
|
|
1823 case BIGFLOAT_T:
|
|
1824 if (bigfloat_sign (XBIGFLOAT_DATA (divisor)) == 0)
|
|
1825 goto divide_by_zero;
|
|
1826 bigfloat_set_prec (scratch_bigfloat,
|
|
1827 max (XBIGFLOAT_GET_PREC (divisor),
|
|
1828 XBIGFLOAT_GET_PREC (accum)));
|
|
1829 bigfloat_div (scratch_bigfloat, XBIGFLOAT_DATA (accum),
|
|
1830 XBIGFLOAT_DATA (divisor));
|
|
1831 accum = make_bigfloat_bf (scratch_bigfloat);
|
|
1832 break;
|
|
1833 #endif
|
|
1834 }
|
|
1835 }
|
|
1836 return Fcanonicalize_number (accum);
|
|
1837 #else /* !WITH_NUMBER_TYPES */
|
428
|
1838 EMACS_INT iaccum;
|
|
1839 double daccum;
|
|
1840 Lisp_Object *args_end = args + nargs;
|
|
1841 int_or_double iod;
|
|
1842
|
|
1843 if (nargs == 1)
|
|
1844 iaccum = 1;
|
|
1845 else
|
|
1846 {
|
|
1847 number_char_or_marker_to_int_or_double (*args++, &iod);
|
|
1848 if (iod.int_p)
|
|
1849 iaccum = iod.c.ival;
|
|
1850 else
|
|
1851 {
|
|
1852 daccum = iod.c.dval;
|
|
1853 goto divide_floats;
|
|
1854 }
|
|
1855 }
|
|
1856
|
|
1857 while (args < args_end)
|
|
1858 {
|
|
1859 number_char_or_marker_to_int_or_double (*args++, &iod);
|
|
1860 if (iod.int_p)
|
|
1861 {
|
|
1862 if (iod.c.ival == 0) goto divide_by_zero;
|
|
1863 iaccum /= iod.c.ival;
|
|
1864 }
|
|
1865 else
|
|
1866 {
|
|
1867 if (iod.c.dval == 0) goto divide_by_zero;
|
|
1868 daccum = (double) iaccum / iod.c.dval;
|
|
1869 goto divide_floats;
|
|
1870 }
|
|
1871 }
|
|
1872
|
|
1873 return make_int (iaccum);
|
|
1874
|
|
1875 divide_floats:
|
|
1876 for (; args < args_end; args++)
|
|
1877 {
|
|
1878 double dval = number_char_or_marker_to_double (*args);
|
|
1879 if (dval == 0) goto divide_by_zero;
|
|
1880 daccum /= dval;
|
|
1881 }
|
|
1882 return make_float (daccum);
|
1983
|
1883 #endif /* WITH_NUMBER_TYPES */
|
428
|
1884
|
|
1885 divide_by_zero:
|
|
1886 Fsignal (Qarith_error, Qnil);
|
801
|
1887 return Qnil; /* not (usually) reached */
|
428
|
1888 }
|
|
1889
|
|
1890 DEFUN ("max", Fmax, 1, MANY, 0, /*
|
|
1891 Return largest of all the arguments.
|
1983
|
1892 All arguments must be real numbers, characters or markers.
|
428
|
1893 The value is always a number; markers and characters are converted
|
|
1894 to numbers.
|
|
1895 */
|
|
1896 (int nargs, Lisp_Object *args))
|
|
1897 {
|
1983
|
1898 #ifdef WITH_NUMBER_TYPES
|
|
1899 REGISTER int i, maxindex = 0;
|
|
1900 Lisp_Object comp1, comp2;
|
|
1901
|
|
1902 while (!(CHARP (args[0]) || MARKERP (args[0]) || REALP (args[0])))
|
|
1903 args[0] = wrong_type_argument (Qnumber_char_or_marker_p, args[0]);
|
|
1904 if (CHARP (args[0]))
|
|
1905 args[0] = make_int (XCHAR (args[0]));
|
|
1906 else if (MARKERP (args[0]))
|
|
1907 args[0] = make_int (marker_position (args[0]));
|
|
1908 for (i = 1; i < nargs; i++)
|
|
1909 {
|
|
1910 comp1 = args[maxindex];
|
|
1911 comp2 = args[i];
|
|
1912 switch (promote_args (&comp1, &comp2))
|
|
1913 {
|
|
1914 case FIXNUM_T:
|
|
1915 if (XREALINT (comp1) < XREALINT (comp2))
|
|
1916 maxindex = i;
|
|
1917 break;
|
|
1918 #ifdef HAVE_BIGNUM
|
|
1919 case BIGNUM_T:
|
|
1920 if (bignum_lt (XBIGNUM_DATA (comp1), XBIGNUM_DATA (comp2)))
|
|
1921 maxindex = i;
|
|
1922 break;
|
|
1923 #endif
|
|
1924 #ifdef HAVE_RATIO
|
|
1925 case RATIO_T:
|
|
1926 if (ratio_lt (XRATIO_DATA (comp1), XRATIO_DATA (comp2)))
|
|
1927 maxindex = i;
|
|
1928 break;
|
|
1929 #endif
|
|
1930 case FLOAT_T:
|
|
1931 if (XFLOAT_DATA (comp1) < XFLOAT_DATA (comp2))
|
|
1932 maxindex = i;
|
|
1933 break;
|
|
1934 #ifdef HAVE_BIGFLOAT
|
|
1935 case BIGFLOAT_T:
|
|
1936 if (bigfloat_lt (XBIGFLOAT_DATA (comp1), XBIGFLOAT_DATA (comp2)))
|
|
1937 maxindex = i;
|
|
1938 break;
|
|
1939 #endif
|
|
1940 }
|
|
1941 }
|
|
1942 return args[maxindex];
|
|
1943 #else /* !WITH_NUMBER_TYPES */
|
428
|
1944 EMACS_INT imax;
|
|
1945 double dmax;
|
|
1946 Lisp_Object *args_end = args + nargs;
|
|
1947 int_or_double iod;
|
|
1948
|
|
1949 number_char_or_marker_to_int_or_double (*args++, &iod);
|
|
1950 if (iod.int_p)
|
|
1951 imax = iod.c.ival;
|
|
1952 else
|
|
1953 {
|
|
1954 dmax = iod.c.dval;
|
|
1955 goto max_floats;
|
|
1956 }
|
|
1957
|
|
1958 while (args < args_end)
|
|
1959 {
|
|
1960 number_char_or_marker_to_int_or_double (*args++, &iod);
|
|
1961 if (iod.int_p)
|
|
1962 {
|
|
1963 if (imax < iod.c.ival) imax = iod.c.ival;
|
|
1964 }
|
|
1965 else
|
|
1966 {
|
|
1967 dmax = (double) imax;
|
|
1968 if (dmax < iod.c.dval) dmax = iod.c.dval;
|
|
1969 goto max_floats;
|
|
1970 }
|
|
1971 }
|
|
1972
|
|
1973 return make_int (imax);
|
|
1974
|
|
1975 max_floats:
|
|
1976 while (args < args_end)
|
|
1977 {
|
|
1978 double dval = number_char_or_marker_to_double (*args++);
|
|
1979 if (dmax < dval) dmax = dval;
|
|
1980 }
|
|
1981 return make_float (dmax);
|
1983
|
1982 #endif /* WITH_NUMBER_TYPES */
|
428
|
1983 }
|
|
1984
|
|
1985 DEFUN ("min", Fmin, 1, MANY, 0, /*
|
|
1986 Return smallest of all the arguments.
|
|
1987 All arguments must be numbers, characters or markers.
|
|
1988 The value is always a number; markers and characters are converted
|
|
1989 to numbers.
|
|
1990 */
|
|
1991 (int nargs, Lisp_Object *args))
|
|
1992 {
|
1983
|
1993 #ifdef WITH_NUMBER_TYPES
|
|
1994 REGISTER int i, minindex = 0;
|
|
1995 Lisp_Object comp1, comp2;
|
|
1996
|
|
1997 while (!(CHARP (args[0]) || MARKERP (args[0]) || REALP (args[0])))
|
|
1998 args[0] = wrong_type_argument (Qnumber_char_or_marker_p, args[0]);
|
|
1999 if (CHARP (args[0]))
|
|
2000 args[0] = make_int (XCHAR (args[0]));
|
|
2001 else if (MARKERP (args[0]))
|
|
2002 args[0] = make_int (marker_position (args[0]));
|
|
2003 for (i = 1; i < nargs; i++)
|
|
2004 {
|
|
2005 comp1 = args[minindex];
|
|
2006 comp2 = args[i];
|
|
2007 switch (promote_args (&comp1, &comp2))
|
|
2008 {
|
|
2009 case FIXNUM_T:
|
|
2010 if (XREALINT (comp1) > XREALINT (comp2))
|
|
2011 minindex = i;
|
|
2012 break;
|
|
2013 #ifdef HAVE_BIGNUM
|
|
2014 case BIGNUM_T:
|
|
2015 if (bignum_gt (XBIGNUM_DATA (comp1), XBIGNUM_DATA (comp2)))
|
|
2016 minindex = i;
|
|
2017 break;
|
|
2018 #endif
|
|
2019 #ifdef HAVE_RATIO
|
|
2020 case RATIO_T:
|
|
2021 if (ratio_gt (XRATIO_DATA (comp1), XRATIO_DATA (comp2)))
|
|
2022 minindex = i;
|
|
2023 break;
|
|
2024 #endif
|
|
2025 case FLOAT_T:
|
|
2026 if (XFLOAT_DATA (comp1) > XFLOAT_DATA (comp2))
|
|
2027 minindex = i;
|
|
2028 break;
|
|
2029 #ifdef HAVE_BIGFLOAT
|
|
2030 case BIGFLOAT_T:
|
|
2031 if (bigfloat_gt (XBIGFLOAT_DATA (comp1), XBIGFLOAT_DATA (comp2)))
|
|
2032 minindex = i;
|
|
2033 break;
|
|
2034 #endif
|
|
2035 }
|
|
2036 }
|
|
2037 return args[minindex];
|
|
2038 #else /* !WITH_NUMBER_TYPES */
|
428
|
2039 EMACS_INT imin;
|
|
2040 double dmin;
|
|
2041 Lisp_Object *args_end = args + nargs;
|
|
2042 int_or_double iod;
|
|
2043
|
|
2044 number_char_or_marker_to_int_or_double (*args++, &iod);
|
|
2045 if (iod.int_p)
|
|
2046 imin = iod.c.ival;
|
|
2047 else
|
|
2048 {
|
|
2049 dmin = iod.c.dval;
|
|
2050 goto min_floats;
|
|
2051 }
|
|
2052
|
|
2053 while (args < args_end)
|
|
2054 {
|
|
2055 number_char_or_marker_to_int_or_double (*args++, &iod);
|
|
2056 if (iod.int_p)
|
|
2057 {
|
|
2058 if (imin > iod.c.ival) imin = iod.c.ival;
|
|
2059 }
|
|
2060 else
|
|
2061 {
|
|
2062 dmin = (double) imin;
|
|
2063 if (dmin > iod.c.dval) dmin = iod.c.dval;
|
|
2064 goto min_floats;
|
|
2065 }
|
|
2066 }
|
|
2067
|
|
2068 return make_int (imin);
|
|
2069
|
|
2070 min_floats:
|
|
2071 while (args < args_end)
|
|
2072 {
|
|
2073 double dval = number_char_or_marker_to_double (*args++);
|
|
2074 if (dmin > dval) dmin = dval;
|
|
2075 }
|
|
2076 return make_float (dmin);
|
1983
|
2077 #endif /* WITH_NUMBER_TYPES */
|
428
|
2078 }
|
|
2079
|
|
2080 DEFUN ("logand", Flogand, 0, MANY, 0, /*
|
|
2081 Return bitwise-and of all the arguments.
|
|
2082 Arguments may be integers, or markers or characters converted to integers.
|
|
2083 */
|
|
2084 (int nargs, Lisp_Object *args))
|
|
2085 {
|
1983
|
2086 #ifdef HAVE_BIGNUM
|
|
2087 REGISTER int i;
|
|
2088 Lisp_Object result, other;
|
|
2089
|
|
2090 if (nargs == 0)
|
|
2091 return make_int (~0);
|
|
2092
|
|
2093 while (!(CHARP (args[0]) || MARKERP (args[0]) || INTEGERP (args[0])))
|
|
2094 args[0] = wrong_type_argument (Qnumber_char_or_marker_p, args[0]);
|
|
2095
|
|
2096 result = args[0];
|
|
2097 if (CHARP (result))
|
|
2098 result = make_int (XCHAR (result));
|
|
2099 else if (MARKERP (result))
|
|
2100 result = make_int (marker_position (result));
|
|
2101 for (i = 1; i < nargs; i++)
|
|
2102 {
|
|
2103 while (!(CHARP (args[i]) || MARKERP (args[i]) || INTEGERP (args[i])))
|
|
2104 args[i] = wrong_type_argument (Qnumber_char_or_marker_p, args[i]);
|
|
2105 other = args[i];
|
1995
|
2106 switch (promote_args (&result, &other))
|
1983
|
2107 {
|
|
2108 case FIXNUM_T:
|
1995
|
2109 result = make_int (XREALINT (result) & XREALINT (other));
|
1983
|
2110 break;
|
|
2111 case BIGNUM_T:
|
|
2112 bignum_and (scratch_bignum, XBIGNUM_DATA (result),
|
|
2113 XBIGNUM_DATA (other));
|
|
2114 result = make_bignum_bg (scratch_bignum);
|
|
2115 break;
|
|
2116 }
|
|
2117 }
|
|
2118 return Fcanonicalize_number (result);
|
|
2119 #else /* !HAVE_BIGNUM */
|
428
|
2120 EMACS_INT bits = ~0;
|
|
2121 Lisp_Object *args_end = args + nargs;
|
|
2122
|
|
2123 while (args < args_end)
|
|
2124 bits &= integer_char_or_marker_to_int (*args++);
|
|
2125
|
|
2126 return make_int (bits);
|
1983
|
2127 #endif /* HAVE_BIGNUM */
|
428
|
2128 }
|
|
2129
|
|
2130 DEFUN ("logior", Flogior, 0, MANY, 0, /*
|
|
2131 Return bitwise-or of all the arguments.
|
|
2132 Arguments may be integers, or markers or characters converted to integers.
|
|
2133 */
|
|
2134 (int nargs, Lisp_Object *args))
|
|
2135 {
|
1983
|
2136 #ifdef HAVE_BIGNUM
|
|
2137 REGISTER int i;
|
|
2138 Lisp_Object result, other;
|
|
2139
|
|
2140 if (nargs == 0)
|
|
2141 return make_int (0);
|
|
2142
|
|
2143 while (!(CHARP (args[0]) || MARKERP (args[0]) || INTEGERP (args[0])))
|
|
2144 args[0] = wrong_type_argument (Qnumber_char_or_marker_p, args[0]);
|
|
2145
|
|
2146 result = args[0];
|
|
2147 if (CHARP (result))
|
|
2148 result = make_int (XCHAR (result));
|
|
2149 else if (MARKERP (result))
|
|
2150 result = make_int (marker_position (result));
|
|
2151 for (i = 1; i < nargs; i++)
|
|
2152 {
|
|
2153 while (!(CHARP (args[i]) || MARKERP (args[i]) || INTEGERP (args[i])))
|
|
2154 args[i] = wrong_type_argument (Qnumber_char_or_marker_p, args[i]);
|
|
2155 other = args[i];
|
|
2156 switch (promote_args (&result, &other))
|
|
2157 {
|
|
2158 case FIXNUM_T:
|
1992
|
2159 result = make_int (XREALINT (result) | XREALINT (other));
|
1983
|
2160 break;
|
|
2161 case BIGNUM_T:
|
|
2162 bignum_ior (scratch_bignum, XBIGNUM_DATA (result),
|
|
2163 XBIGNUM_DATA (other));
|
|
2164 result = make_bignum_bg (scratch_bignum);
|
|
2165 break;
|
|
2166 }
|
|
2167 }
|
|
2168 return Fcanonicalize_number (result);
|
|
2169 #else /* !HAVE_BIGNUM */
|
428
|
2170 EMACS_INT bits = 0;
|
|
2171 Lisp_Object *args_end = args + nargs;
|
|
2172
|
|
2173 while (args < args_end)
|
|
2174 bits |= integer_char_or_marker_to_int (*args++);
|
|
2175
|
|
2176 return make_int (bits);
|
1983
|
2177 #endif /* HAVE_BIGNUM */
|
428
|
2178 }
|
|
2179
|
|
2180 DEFUN ("logxor", Flogxor, 0, MANY, 0, /*
|
|
2181 Return bitwise-exclusive-or of all the arguments.
|
|
2182 Arguments may be integers, or markers or characters converted to integers.
|
|
2183 */
|
|
2184 (int nargs, Lisp_Object *args))
|
|
2185 {
|
1983
|
2186 #ifdef HAVE_BIGNUM
|
|
2187 REGISTER int i;
|
|
2188 Lisp_Object result, other;
|
|
2189
|
|
2190 if (nargs == 0)
|
|
2191 return make_int (0);
|
|
2192
|
|
2193 while (!(CHARP (args[0]) || MARKERP (args[0]) || INTEGERP (args[0])))
|
|
2194 args[0] = wrong_type_argument (Qnumber_char_or_marker_p, args[0]);
|
|
2195
|
|
2196 result = args[0];
|
|
2197 if (CHARP (result))
|
|
2198 result = make_int (XCHAR (result));
|
|
2199 else if (MARKERP (result))
|
|
2200 result = make_int (marker_position (result));
|
|
2201 for (i = 1; i < nargs; i++)
|
|
2202 {
|
|
2203 while (!(CHARP (args[i]) || MARKERP (args[i]) || INTEGERP (args[i])))
|
|
2204 args[i] = wrong_type_argument (Qnumber_char_or_marker_p, args[i]);
|
|
2205 other = args[i];
|
|
2206 if (promote_args (&result, &other) == FIXNUM_T)
|
|
2207 {
|
|
2208 result = make_int (XREALINT (result) ^ XREALINT (other));
|
|
2209 }
|
|
2210 else
|
|
2211 {
|
|
2212 bignum_xor (scratch_bignum, XBIGNUM_DATA (result),
|
|
2213 XBIGNUM_DATA (other));
|
|
2214 result = make_bignum_bg (scratch_bignum);
|
|
2215 }
|
|
2216 }
|
|
2217 return Fcanonicalize_number (result);
|
|
2218 #else /* !HAVE_BIGNUM */
|
428
|
2219 EMACS_INT bits = 0;
|
|
2220 Lisp_Object *args_end = args + nargs;
|
|
2221
|
|
2222 while (args < args_end)
|
|
2223 bits ^= integer_char_or_marker_to_int (*args++);
|
|
2224
|
|
2225 return make_int (bits);
|
1983
|
2226 #endif /* !HAVE_BIGNUM */
|
428
|
2227 }
|
|
2228
|
|
2229 DEFUN ("lognot", Flognot, 1, 1, 0, /*
|
|
2230 Return the bitwise complement of NUMBER.
|
|
2231 NUMBER may be an integer, marker or character converted to integer.
|
|
2232 */
|
|
2233 (number))
|
|
2234 {
|
1983
|
2235 #ifdef HAVE_BIGNUM
|
|
2236 if (BIGNUMP (number))
|
|
2237 {
|
|
2238 bignum_not (scratch_bignum, XBIGNUM_DATA (number));
|
|
2239 return make_bignum_bg (scratch_bignum);
|
|
2240 }
|
|
2241 #endif /* HAVE_BIGNUM */
|
428
|
2242 return make_int (~ integer_char_or_marker_to_int (number));
|
|
2243 }
|
|
2244
|
|
2245 DEFUN ("%", Frem, 2, 2, 0, /*
|
|
2246 Return remainder of first arg divided by second.
|
|
2247 Both must be integers, characters or markers.
|
|
2248 */
|
444
|
2249 (number1, number2))
|
428
|
2250 {
|
1983
|
2251 #ifdef HAVE_BIGNUM
|
|
2252 while (!(CHARP (number1) || MARKERP (number1) || INTEGERP (number1)))
|
|
2253 number1 = wrong_type_argument (Qnumber_char_or_marker_p, number1);
|
|
2254 while (!(CHARP (number2) || MARKERP (number2) || INTEGERP (number2)))
|
|
2255 number2 = wrong_type_argument (Qnumber_char_or_marker_p, number2);
|
|
2256
|
|
2257 if (promote_args (&number1, &number2) == FIXNUM_T)
|
|
2258 {
|
|
2259 if (XREALINT (number2) == 0)
|
|
2260 Fsignal (Qarith_error, Qnil);
|
|
2261 return make_int (XREALINT (number1) % XREALINT (number2));
|
|
2262 }
|
|
2263 else
|
|
2264 {
|
|
2265 if (bignum_sign (XBIGNUM_DATA (number2)) == 0)
|
|
2266 Fsignal (Qarith_error, Qnil);
|
|
2267 bignum_mod (scratch_bignum, XBIGNUM_DATA (number1),
|
|
2268 XBIGNUM_DATA (number2));
|
|
2269 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
|
|
2270 }
|
|
2271 #else /* !HAVE_BIGNUM */
|
444
|
2272 EMACS_INT ival1 = integer_char_or_marker_to_int (number1);
|
|
2273 EMACS_INT ival2 = integer_char_or_marker_to_int (number2);
|
428
|
2274
|
|
2275 if (ival2 == 0)
|
|
2276 Fsignal (Qarith_error, Qnil);
|
|
2277
|
|
2278 return make_int (ival1 % ival2);
|
1983
|
2279 #endif /* HAVE_BIGNUM */
|
428
|
2280 }
|
|
2281
|
|
2282 /* Note, ANSI *requires* the presence of the fmod() library routine.
|
|
2283 If your system doesn't have it, complain to your vendor, because
|
|
2284 that is a bug. */
|
|
2285
|
|
2286 #ifndef HAVE_FMOD
|
|
2287 double
|
|
2288 fmod (double f1, double f2)
|
|
2289 {
|
|
2290 if (f2 < 0.0)
|
|
2291 f2 = -f2;
|
|
2292 return f1 - f2 * floor (f1/f2);
|
|
2293 }
|
|
2294 #endif /* ! HAVE_FMOD */
|
|
2295
|
|
2296
|
|
2297 DEFUN ("mod", Fmod, 2, 2, 0, /*
|
|
2298 Return X modulo Y.
|
|
2299 The result falls between zero (inclusive) and Y (exclusive).
|
|
2300 Both X and Y must be numbers, characters or markers.
|
|
2301 If either argument is a float, a float will be returned.
|
|
2302 */
|
|
2303 (x, y))
|
|
2304 {
|
1983
|
2305 #ifdef WITH_NUMBER_TYPES
|
|
2306 while (!(CHARP (x) || MARKERP (x) || REALP (x)))
|
|
2307 x = wrong_type_argument (Qnumber_char_or_marker_p, x);
|
|
2308 while (!(CHARP (y) || MARKERP (y) || REALP (y)))
|
|
2309 y = wrong_type_argument (Qnumber_char_or_marker_p, y);
|
|
2310 switch (promote_args (&x, &y))
|
|
2311 {
|
|
2312 case FIXNUM_T:
|
|
2313 {
|
|
2314 EMACS_INT ival;
|
|
2315 if (XREALINT (y) == 0) goto divide_by_zero;
|
|
2316 ival = XREALINT (x) % XREALINT (y);
|
|
2317 /* If the "remainder" comes out with the wrong sign, fix it. */
|
|
2318 if (XREALINT (y) < 0 ? ival > 0 : ival < 0)
|
|
2319 ival += XREALINT (y);
|
|
2320 return make_int (ival);
|
|
2321 }
|
|
2322 #ifdef HAVE_BIGNUM
|
|
2323 case BIGNUM_T:
|
|
2324 if (bignum_sign (XBIGNUM_DATA (y)) == 0) goto divide_by_zero;
|
|
2325 bignum_mod (scratch_bignum, XBIGNUM_DATA (x), XBIGNUM_DATA (y));
|
|
2326 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
|
|
2327 #endif
|
|
2328 #ifdef HAVE_RATIO
|
|
2329 case RATIO_T:
|
|
2330 if (ratio_sign (XRATIO_DATA (y)) == 0) goto divide_by_zero;
|
|
2331 ratio_div (scratch_ratio, XRATIO_DATA (x), XRATIO_DATA (y));
|
|
2332 bignum_div (scratch_bignum, ratio_numerator (scratch_ratio),
|
|
2333 ratio_denominator (scratch_ratio));
|
|
2334 ratio_set_bignum (scratch_ratio, scratch_bignum);
|
|
2335 ratio_mul (scratch_ratio, scratch_ratio, XRATIO_DATA (y));
|
|
2336 ratio_sub (scratch_ratio, XRATIO_DATA (x), scratch_ratio);
|
|
2337 return Fcanonicalize_number (make_ratio_rt (scratch_ratio));
|
|
2338 #endif
|
|
2339 case FLOAT_T:
|
|
2340 {
|
|
2341 double dval;
|
|
2342 if (XFLOAT_DATA (y) == 0.0) goto divide_by_zero;
|
|
2343 dval = fmod (XFLOAT_DATA (x), XFLOAT_DATA (y));
|
|
2344 /* If the "remainder" comes out with the wrong sign, fix it. */
|
|
2345 if (XFLOAT_DATA (y) < 0 ? dval > 0 : dval < 0)
|
|
2346 dval += XFLOAT_DATA (y);
|
|
2347 return make_float (dval);
|
|
2348 }
|
|
2349 #ifdef HAVE_BIGFLOAT
|
|
2350 case BIGFLOAT_T:
|
|
2351 bigfloat_set_prec (scratch_bigfloat,
|
|
2352 max (XBIGFLOAT_GET_PREC (x), XBIGFLOAT_GET_PREC (y)));
|
|
2353 bigfloat_div (scratch_bigfloat, XBIGFLOAT_DATA (x), XBIGFLOAT_DATA (y));
|
|
2354 bigfloat_trunc (scratch_bigfloat, scratch_bigfloat);
|
|
2355 bigfloat_mul (scratch_bigfloat, scratch_bigfloat, XBIGFLOAT_DATA (y));
|
|
2356 bigfloat_sub (scratch_bigfloat, XBIGFLOAT_DATA (x), scratch_bigfloat);
|
|
2357 return make_bigfloat_bf (scratch_bigfloat);
|
|
2358 #endif
|
|
2359 }
|
|
2360 #else /* !WITH_NUMBER_TYPES */
|
428
|
2361 int_or_double iod1, iod2;
|
|
2362 number_char_or_marker_to_int_or_double (x, &iod1);
|
|
2363 number_char_or_marker_to_int_or_double (y, &iod2);
|
|
2364
|
|
2365 if (!iod1.int_p || !iod2.int_p)
|
|
2366 {
|
|
2367 double dval1 = iod1.int_p ? (double) iod1.c.ival : iod1.c.dval;
|
|
2368 double dval2 = iod2.int_p ? (double) iod2.c.ival : iod2.c.dval;
|
|
2369 if (dval2 == 0) goto divide_by_zero;
|
|
2370 dval1 = fmod (dval1, dval2);
|
|
2371
|
|
2372 /* If the "remainder" comes out with the wrong sign, fix it. */
|
|
2373 if (dval2 < 0 ? dval1 > 0 : dval1 < 0)
|
|
2374 dval1 += dval2;
|
|
2375
|
|
2376 return make_float (dval1);
|
|
2377 }
|
1104
|
2378
|
428
|
2379 {
|
|
2380 EMACS_INT ival;
|
|
2381 if (iod2.c.ival == 0) goto divide_by_zero;
|
|
2382
|
|
2383 ival = iod1.c.ival % iod2.c.ival;
|
|
2384
|
|
2385 /* If the "remainder" comes out with the wrong sign, fix it. */
|
|
2386 if (iod2.c.ival < 0 ? ival > 0 : ival < 0)
|
|
2387 ival += iod2.c.ival;
|
|
2388
|
|
2389 return make_int (ival);
|
|
2390 }
|
1983
|
2391 #endif /* WITH_NUMBER_TYPES */
|
428
|
2392
|
|
2393 divide_by_zero:
|
|
2394 Fsignal (Qarith_error, Qnil);
|
801
|
2395 return Qnil; /* not (usually) reached */
|
428
|
2396 }
|
|
2397
|
|
2398 DEFUN ("ash", Fash, 2, 2, 0, /*
|
|
2399 Return VALUE with its bits shifted left by COUNT.
|
|
2400 If COUNT is negative, shifting is actually to the right.
|
|
2401 In this case, the sign bit is duplicated.
|
1983
|
2402 This function cannot be applied to bignums, as there is no leftmost sign bit
|
|
2403 to be duplicated. Use `lsh' instead.
|
428
|
2404 */
|
|
2405 (value, count))
|
|
2406 {
|
|
2407 CHECK_INT_COERCE_CHAR (value);
|
|
2408 CONCHECK_INT (count);
|
|
2409
|
|
2410 return make_int (XINT (count) > 0 ?
|
|
2411 XINT (value) << XINT (count) :
|
|
2412 XINT (value) >> -XINT (count));
|
|
2413 }
|
|
2414
|
|
2415 DEFUN ("lsh", Flsh, 2, 2, 0, /*
|
|
2416 Return VALUE with its bits shifted left by COUNT.
|
|
2417 If COUNT is negative, shifting is actually to the right.
|
|
2418 In this case, zeros are shifted in on the left.
|
|
2419 */
|
|
2420 (value, count))
|
|
2421 {
|
1983
|
2422 #ifdef HAVE_BIGNUM
|
|
2423 while (!(CHARP (value) || MARKERP (value) || INTEGERP (value)))
|
|
2424 wrong_type_argument (Qnumber_char_or_marker_p, value);
|
|
2425 CONCHECK_INTEGER (count);
|
|
2426
|
|
2427 if (promote_args (&value, &count) == FIXNUM_T)
|
|
2428 {
|
|
2429 if (XREALINT (count) <= 0)
|
|
2430 return make_int (XREALINT (value) >> -XREALINT (count));
|
|
2431 /* Use bignums to avoid overflow */
|
|
2432 bignum_set_long (scratch_bignum2, XREALINT (value));
|
|
2433 bignum_lshift (scratch_bignum, scratch_bignum2, XREALINT (count));
|
|
2434 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
|
|
2435 }
|
|
2436 else
|
|
2437 {
|
|
2438 if (bignum_sign (XBIGNUM_DATA (count)) <= 0)
|
|
2439 {
|
|
2440 bignum_neg (scratch_bignum, XBIGNUM_DATA (count));
|
|
2441 if (!bignum_fits_ulong_p (scratch_bignum))
|
|
2442 args_out_of_range (Qnumber_char_or_marker_p, count);
|
|
2443 bignum_rshift (scratch_bignum2, XBIGNUM_DATA (value),
|
|
2444 bignum_to_ulong (scratch_bignum));
|
|
2445 }
|
|
2446 else
|
|
2447 {
|
|
2448 if (!bignum_fits_ulong_p (XBIGNUM_DATA (count)))
|
|
2449 args_out_of_range (Qnumber_char_or_marker_p, count);
|
|
2450 bignum_lshift (scratch_bignum2, XBIGNUM_DATA (value),
|
|
2451 bignum_to_ulong (XBIGNUM_DATA (count)));
|
|
2452 }
|
|
2453 return Fcanonicalize_number (make_bignum_bg (scratch_bignum2));
|
|
2454 }
|
|
2455 #else /* !HAVE_BIGNUM */
|
428
|
2456 CHECK_INT_COERCE_CHAR (value);
|
|
2457 CONCHECK_INT (count);
|
|
2458
|
|
2459 return make_int (XINT (count) > 0 ?
|
|
2460 XUINT (value) << XINT (count) :
|
|
2461 XUINT (value) >> -XINT (count));
|
1983
|
2462 #endif /* HAVE_BIGNUM */
|
428
|
2463 }
|
|
2464
|
|
2465 DEFUN ("1+", Fadd1, 1, 1, 0, /*
|
|
2466 Return NUMBER plus one. NUMBER may be a number, character or marker.
|
|
2467 Markers and characters are converted to integers.
|
|
2468 */
|
|
2469 (number))
|
|
2470 {
|
|
2471 retry:
|
|
2472
|
1983
|
2473 if (INTP (number)) return make_integer (XINT (number) + 1);
|
|
2474 if (CHARP (number)) return make_integer (XCHAR (number) + 1);
|
|
2475 if (MARKERP (number)) return make_integer (marker_position (number) + 1);
|
428
|
2476 if (FLOATP (number)) return make_float (XFLOAT_DATA (number) + 1.0);
|
1983
|
2477 #ifdef HAVE_BIGNUM
|
|
2478 if (BIGNUMP (number))
|
|
2479 {
|
|
2480 bignum_set_long (scratch_bignum, 1L);
|
|
2481 bignum_add (scratch_bignum2, XBIGNUM_DATA (number), scratch_bignum);
|
|
2482 return Fcanonicalize_number (make_bignum_bg (scratch_bignum2));
|
|
2483 }
|
|
2484 #endif
|
|
2485 #ifdef HAVE_RATIO
|
|
2486 if (RATIOP (number))
|
|
2487 {
|
|
2488 ratio_set_long (scratch_ratio, 1L);
|
|
2489 ratio_add (scratch_ratio, XRATIO_DATA (number), scratch_ratio);
|
|
2490 /* No need to canonicalize after adding 1 */
|
|
2491 return make_ratio_rt (scratch_ratio);
|
|
2492 }
|
|
2493 #endif
|
|
2494 #ifdef HAVE_BIGFLOAT
|
|
2495 if (BIGFLOATP (number))
|
|
2496 {
|
|
2497 bigfloat_set_prec (scratch_bigfloat, XBIGFLOAT_GET_PREC (number));
|
|
2498 bigfloat_set_long (scratch_bigfloat, 1L);
|
|
2499 bigfloat_add (scratch_bigfloat, XBIGFLOAT_DATA (number),
|
|
2500 scratch_bigfloat);
|
|
2501 return make_bigfloat_bf (scratch_bigfloat);
|
|
2502 }
|
|
2503 #endif
|
428
|
2504
|
|
2505 number = wrong_type_argument (Qnumber_char_or_marker_p, number);
|
|
2506 goto retry;
|
|
2507 }
|
|
2508
|
|
2509 DEFUN ("1-", Fsub1, 1, 1, 0, /*
|
|
2510 Return NUMBER minus one. NUMBER may be a number, character or marker.
|
|
2511 Markers and characters are converted to integers.
|
|
2512 */
|
|
2513 (number))
|
|
2514 {
|
|
2515 retry:
|
|
2516
|
1983
|
2517 if (INTP (number)) return make_integer (XINT (number) - 1);
|
|
2518 if (CHARP (number)) return make_integer (XCHAR (number) - 1);
|
|
2519 if (MARKERP (number)) return make_integer (marker_position (number) - 1);
|
428
|
2520 if (FLOATP (number)) return make_float (XFLOAT_DATA (number) - 1.0);
|
1983
|
2521 #ifdef HAVE_BIGNUM
|
|
2522 if (BIGNUMP (number))
|
|
2523 {
|
|
2524 bignum_set_long (scratch_bignum, 1L);
|
|
2525 bignum_sub (scratch_bignum2, XBIGNUM_DATA (number), scratch_bignum);
|
|
2526 return Fcanonicalize_number (make_bignum_bg (scratch_bignum2));
|
|
2527 }
|
|
2528 #endif
|
|
2529 #ifdef HAVE_RATIO
|
|
2530 if (RATIOP (number))
|
|
2531 {
|
|
2532 ratio_set_long (scratch_ratio, 1L);
|
|
2533 ratio_sub (scratch_ratio, XRATIO_DATA (number), scratch_ratio);
|
|
2534 /* No need to canonicalize after subtracting 1 */
|
|
2535 return make_ratio_rt (scratch_ratio);
|
|
2536 }
|
|
2537 #endif
|
|
2538 #ifdef HAVE_BIGFLOAT
|
|
2539 if (BIGFLOATP (number))
|
|
2540 {
|
|
2541 bigfloat_set_prec (scratch_bigfloat, XBIGFLOAT_GET_PREC (number));
|
|
2542 bigfloat_set_long (scratch_bigfloat, 1L);
|
|
2543 bigfloat_sub (scratch_bigfloat, XBIGFLOAT_DATA (number),
|
|
2544 scratch_bigfloat);
|
|
2545 return make_bigfloat_bf (scratch_bigfloat);
|
|
2546 }
|
|
2547 #endif
|
428
|
2548
|
|
2549 number = wrong_type_argument (Qnumber_char_or_marker_p, number);
|
|
2550 goto retry;
|
|
2551 }
|
|
2552
|
|
2553
|
|
2554 /************************************************************************/
|
|
2555 /* weak lists */
|
|
2556 /************************************************************************/
|
|
2557
|
|
2558 /* A weak list is like a normal list except that elements automatically
|
|
2559 disappear when no longer in use, i.e. when no longer GC-protected.
|
|
2560 The basic idea is that we don't mark the elements during GC, but
|
|
2561 wait for them to be marked elsewhere. If they're not marked, we
|
|
2562 remove them. This is analogous to weak hash tables; see the explanation
|
|
2563 there for more info. */
|
|
2564
|
|
2565 static Lisp_Object Vall_weak_lists; /* Gemarke es nicht!!! */
|
|
2566
|
|
2567 static Lisp_Object encode_weak_list_type (enum weak_list_type type);
|
|
2568
|
|
2569 static Lisp_Object
|
2286
|
2570 mark_weak_list (Lisp_Object UNUSED (obj))
|
428
|
2571 {
|
|
2572 return Qnil; /* nichts ist gemarkt */
|
|
2573 }
|
|
2574
|
|
2575 static void
|
2286
|
2576 print_weak_list (Lisp_Object obj, Lisp_Object printcharfun,
|
|
2577 int UNUSED (escapeflag))
|
428
|
2578 {
|
|
2579 if (print_readably)
|
563
|
2580 printing_unreadable_object ("#<weak-list>");
|
428
|
2581
|
800
|
2582 write_fmt_string_lisp (printcharfun, "#<weak-list %s %S>", 2,
|
|
2583 encode_weak_list_type (XWEAK_LIST (obj)->type),
|
|
2584 XWEAK_LIST (obj)->list);
|
428
|
2585 }
|
|
2586
|
|
2587 static int
|
|
2588 weak_list_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
|
2589 {
|
|
2590 struct weak_list *w1 = XWEAK_LIST (obj1);
|
|
2591 struct weak_list *w2 = XWEAK_LIST (obj2);
|
|
2592
|
|
2593 return ((w1->type == w2->type) &&
|
|
2594 internal_equal (w1->list, w2->list, depth + 1));
|
|
2595 }
|
|
2596
|
665
|
2597 static Hashcode
|
428
|
2598 weak_list_hash (Lisp_Object obj, int depth)
|
|
2599 {
|
|
2600 struct weak_list *w = XWEAK_LIST (obj);
|
|
2601
|
665
|
2602 return HASH2 ((Hashcode) w->type,
|
428
|
2603 internal_hash (w->list, depth + 1));
|
|
2604 }
|
|
2605
|
|
2606 Lisp_Object
|
|
2607 make_weak_list (enum weak_list_type type)
|
|
2608 {
|
|
2609 Lisp_Object result;
|
|
2610 struct weak_list *wl =
|
3017
|
2611 ALLOC_LCRECORD_TYPE (struct weak_list, &lrecord_weak_list);
|
428
|
2612
|
|
2613 wl->list = Qnil;
|
|
2614 wl->type = type;
|
793
|
2615 result = wrap_weak_list (wl);
|
428
|
2616 wl->next_weak = Vall_weak_lists;
|
|
2617 Vall_weak_lists = result;
|
|
2618 return result;
|
|
2619 }
|
|
2620
|
1204
|
2621 static const struct memory_description weak_list_description[] = {
|
1598
|
2622 { XD_LISP_OBJECT, offsetof (struct weak_list, list),
|
2551
|
2623 0, { 0 }, XD_FLAG_NO_KKCC },
|
1598
|
2624 { XD_LO_LINK, offsetof (struct weak_list, next_weak),
|
2551
|
2625 0, { 0 }, XD_FLAG_NO_KKCC },
|
428
|
2626 { XD_END }
|
|
2627 };
|
|
2628
|
934
|
2629 DEFINE_LRECORD_IMPLEMENTATION ("weak-list", weak_list,
|
|
2630 1, /*dumpable-flag*/
|
|
2631 mark_weak_list, print_weak_list,
|
|
2632 0, weak_list_equal, weak_list_hash,
|
|
2633 weak_list_description,
|
|
2634 struct weak_list);
|
428
|
2635 /*
|
|
2636 -- we do not mark the list elements (either the elements themselves
|
|
2637 or the cons cells that hold them) in the normal marking phase.
|
|
2638 -- at the end of marking, we go through all weak lists that are
|
|
2639 marked, and mark the cons cells that hold all marked
|
|
2640 objects, and possibly parts of the objects themselves.
|
|
2641 (See alloc.c, "after-mark".)
|
|
2642 -- after that, we prune away all the cons cells that are not marked.
|
|
2643
|
|
2644 WARNING WARNING WARNING WARNING WARNING:
|
|
2645
|
|
2646 The code in the following two functions is *unbelievably* tricky.
|
|
2647 Don't mess with it. You'll be sorry.
|
|
2648
|
|
2649 Linked lists just majorly suck, d'ya know?
|
|
2650 */
|
|
2651
|
|
2652 int
|
|
2653 finish_marking_weak_lists (void)
|
|
2654 {
|
|
2655 Lisp_Object rest;
|
|
2656 int did_mark = 0;
|
|
2657
|
|
2658 for (rest = Vall_weak_lists;
|
|
2659 !NILP (rest);
|
|
2660 rest = XWEAK_LIST (rest)->next_weak)
|
|
2661 {
|
|
2662 Lisp_Object rest2;
|
|
2663 enum weak_list_type type = XWEAK_LIST (rest)->type;
|
|
2664
|
|
2665 if (! marked_p (rest))
|
|
2666 /* The weak list is probably garbage. Ignore it. */
|
|
2667 continue;
|
|
2668
|
|
2669 for (rest2 = XWEAK_LIST (rest)->list;
|
|
2670 /* We need to be trickier since we're inside of GC;
|
|
2671 use CONSP instead of !NILP in case of user-visible
|
|
2672 imperfect lists */
|
|
2673 CONSP (rest2);
|
|
2674 rest2 = XCDR (rest2))
|
|
2675 {
|
|
2676 Lisp_Object elem;
|
|
2677 /* If the element is "marked" (meaning depends on the type
|
|
2678 of weak list), we need to mark the cons containing the
|
|
2679 element, and maybe the element itself (if only some part
|
|
2680 was already marked). */
|
|
2681 int need_to_mark_cons = 0;
|
|
2682 int need_to_mark_elem = 0;
|
|
2683
|
|
2684 /* If a cons is already marked, then its car is already marked
|
|
2685 (either because of an external pointer or because of
|
|
2686 a previous call to this function), and likewise for all
|
|
2687 the rest of the elements in the list, so we can stop now. */
|
|
2688 if (marked_p (rest2))
|
|
2689 break;
|
|
2690
|
|
2691 elem = XCAR (rest2);
|
|
2692
|
|
2693 switch (type)
|
|
2694 {
|
|
2695 case WEAK_LIST_SIMPLE:
|
|
2696 if (marked_p (elem))
|
|
2697 need_to_mark_cons = 1;
|
|
2698 break;
|
|
2699
|
|
2700 case WEAK_LIST_ASSOC:
|
|
2701 if (!CONSP (elem))
|
|
2702 {
|
|
2703 /* just leave bogus elements there */
|
|
2704 need_to_mark_cons = 1;
|
|
2705 need_to_mark_elem = 1;
|
|
2706 }
|
|
2707 else if (marked_p (XCAR (elem)) &&
|
|
2708 marked_p (XCDR (elem)))
|
|
2709 {
|
|
2710 need_to_mark_cons = 1;
|
|
2711 /* We still need to mark elem, because it's
|
|
2712 probably not marked. */
|
|
2713 need_to_mark_elem = 1;
|
|
2714 }
|
|
2715 break;
|
|
2716
|
|
2717 case WEAK_LIST_KEY_ASSOC:
|
|
2718 if (!CONSP (elem))
|
|
2719 {
|
|
2720 /* just leave bogus elements there */
|
|
2721 need_to_mark_cons = 1;
|
|
2722 need_to_mark_elem = 1;
|
|
2723 }
|
|
2724 else if (marked_p (XCAR (elem)))
|
|
2725 {
|
|
2726 need_to_mark_cons = 1;
|
|
2727 /* We still need to mark elem and XCDR (elem);
|
|
2728 marking elem does both */
|
|
2729 need_to_mark_elem = 1;
|
|
2730 }
|
|
2731 break;
|
|
2732
|
|
2733 case WEAK_LIST_VALUE_ASSOC:
|
|
2734 if (!CONSP (elem))
|
|
2735 {
|
|
2736 /* just leave bogus elements there */
|
|
2737 need_to_mark_cons = 1;
|
|
2738 need_to_mark_elem = 1;
|
|
2739 }
|
|
2740 else if (marked_p (XCDR (elem)))
|
|
2741 {
|
|
2742 need_to_mark_cons = 1;
|
|
2743 /* We still need to mark elem and XCAR (elem);
|
|
2744 marking elem does both */
|
|
2745 need_to_mark_elem = 1;
|
|
2746 }
|
|
2747 break;
|
|
2748
|
442
|
2749 case WEAK_LIST_FULL_ASSOC:
|
|
2750 if (!CONSP (elem))
|
|
2751 {
|
|
2752 /* just leave bogus elements there */
|
|
2753 need_to_mark_cons = 1;
|
|
2754 need_to_mark_elem = 1;
|
|
2755 }
|
|
2756 else if (marked_p (XCAR (elem)) ||
|
|
2757 marked_p (XCDR (elem)))
|
|
2758 {
|
|
2759 need_to_mark_cons = 1;
|
|
2760 /* We still need to mark elem and XCAR (elem);
|
|
2761 marking elem does both */
|
|
2762 need_to_mark_elem = 1;
|
|
2763 }
|
|
2764 break;
|
|
2765
|
428
|
2766 default:
|
2500
|
2767 ABORT ();
|
428
|
2768 }
|
|
2769
|
|
2770 if (need_to_mark_elem && ! marked_p (elem))
|
|
2771 {
|
1598
|
2772 #ifdef USE_KKCC
|
2645
|
2773 kkcc_gc_stack_push_lisp_object (elem, 0, -1);
|
1598
|
2774 #else /* NOT USE_KKCC */
|
428
|
2775 mark_object (elem);
|
1598
|
2776 #endif /* NOT USE_KKCC */
|
428
|
2777 did_mark = 1;
|
|
2778 }
|
|
2779
|
|
2780 /* We also need to mark the cons that holds the elem or
|
|
2781 assoc-pair. We do *not* want to call (mark_object) here
|
|
2782 because that will mark the entire list; we just want to
|
|
2783 mark the cons itself.
|
|
2784 */
|
|
2785 if (need_to_mark_cons)
|
|
2786 {
|
|
2787 Lisp_Cons *c = XCONS (rest2);
|
|
2788 if (!CONS_MARKED_P (c))
|
|
2789 {
|
|
2790 MARK_CONS (c);
|
|
2791 did_mark = 1;
|
|
2792 }
|
|
2793 }
|
|
2794 }
|
|
2795
|
|
2796 /* In case of imperfect list, need to mark the final cons
|
|
2797 because we're not removing it */
|
|
2798 if (!NILP (rest2) && ! marked_p (rest2))
|
|
2799 {
|
1598
|
2800 #ifdef USE_KKCC
|
2645
|
2801 kkcc_gc_stack_push_lisp_object (rest2, 0, -1);
|
1598
|
2802 #else /* NOT USE_KKCC */
|
428
|
2803 mark_object (rest2);
|
1598
|
2804 #endif /* NOT USE_KKCC */
|
428
|
2805 did_mark = 1;
|
|
2806 }
|
|
2807 }
|
|
2808
|
|
2809 return did_mark;
|
|
2810 }
|
|
2811
|
|
2812 void
|
|
2813 prune_weak_lists (void)
|
|
2814 {
|
|
2815 Lisp_Object rest, prev = Qnil;
|
|
2816
|
|
2817 for (rest = Vall_weak_lists;
|
|
2818 !NILP (rest);
|
|
2819 rest = XWEAK_LIST (rest)->next_weak)
|
|
2820 {
|
|
2821 if (! (marked_p (rest)))
|
|
2822 {
|
|
2823 /* This weak list itself is garbage. Remove it from the list. */
|
|
2824 if (NILP (prev))
|
|
2825 Vall_weak_lists = XWEAK_LIST (rest)->next_weak;
|
|
2826 else
|
|
2827 XWEAK_LIST (prev)->next_weak =
|
|
2828 XWEAK_LIST (rest)->next_weak;
|
|
2829 }
|
|
2830 else
|
|
2831 {
|
|
2832 Lisp_Object rest2, prev2 = Qnil;
|
|
2833 Lisp_Object tortoise;
|
|
2834 int go_tortoise = 0;
|
|
2835
|
|
2836 for (rest2 = XWEAK_LIST (rest)->list, tortoise = rest2;
|
|
2837 /* We need to be trickier since we're inside of GC;
|
|
2838 use CONSP instead of !NILP in case of user-visible
|
|
2839 imperfect lists */
|
|
2840 CONSP (rest2);)
|
|
2841 {
|
|
2842 /* It suffices to check the cons for marking,
|
|
2843 regardless of the type of weak list:
|
|
2844
|
|
2845 -- if the cons is pointed to somewhere else,
|
|
2846 then it should stay around and will be marked.
|
|
2847 -- otherwise, if it should stay around, it will
|
|
2848 have been marked in finish_marking_weak_lists().
|
|
2849 -- otherwise, it's not marked and should disappear.
|
|
2850 */
|
|
2851 if (! marked_p (rest2))
|
|
2852 {
|
|
2853 /* bye bye :-( */
|
|
2854 if (NILP (prev2))
|
|
2855 XWEAK_LIST (rest)->list = XCDR (rest2);
|
|
2856 else
|
|
2857 XCDR (prev2) = XCDR (rest2);
|
|
2858 rest2 = XCDR (rest2);
|
|
2859 /* Ouch. Circularity checking is even trickier
|
|
2860 than I thought. When we cut out a link
|
|
2861 like this, we can't advance the turtle or
|
|
2862 it'll catch up to us. Imagine that we're
|
|
2863 standing on floor tiles and moving forward --
|
|
2864 what we just did here is as if the floor
|
|
2865 tile under us just disappeared and all the
|
|
2866 ones ahead of us slid one tile towards us.
|
|
2867 In other words, we didn't move at all;
|
|
2868 if the tortoise was one step behind us
|
|
2869 previously, it still is, and therefore
|
|
2870 it must not move. */
|
|
2871 }
|
|
2872 else
|
|
2873 {
|
|
2874 prev2 = rest2;
|
|
2875
|
|
2876 /* Implementing circularity checking is trickier here
|
|
2877 than in other places because we have to guarantee
|
|
2878 that we've processed all elements before exiting
|
|
2879 due to a circularity. (In most places, an error
|
|
2880 is issued upon encountering a circularity, so it
|
|
2881 doesn't really matter if all elements are processed.)
|
|
2882 The idea is that we process along with the hare
|
|
2883 rather than the tortoise. If at any point in
|
|
2884 our forward process we encounter the tortoise,
|
|
2885 we must have already visited the spot, so we exit.
|
|
2886 (If we process with the tortoise, we can fail to
|
|
2887 process cases where a cons points to itself, or
|
|
2888 where cons A points to cons B, which points to
|
|
2889 cons A.) */
|
|
2890
|
|
2891 rest2 = XCDR (rest2);
|
|
2892 if (go_tortoise)
|
|
2893 tortoise = XCDR (tortoise);
|
|
2894 go_tortoise = !go_tortoise;
|
|
2895 if (EQ (rest2, tortoise))
|
|
2896 break;
|
|
2897 }
|
|
2898 }
|
|
2899
|
|
2900 prev = rest;
|
|
2901 }
|
|
2902 }
|
|
2903 }
|
|
2904
|
|
2905 static enum weak_list_type
|
|
2906 decode_weak_list_type (Lisp_Object symbol)
|
|
2907 {
|
|
2908 CHECK_SYMBOL (symbol);
|
|
2909 if (EQ (symbol, Qsimple)) return WEAK_LIST_SIMPLE;
|
|
2910 if (EQ (symbol, Qassoc)) return WEAK_LIST_ASSOC;
|
|
2911 if (EQ (symbol, Qold_assoc)) return WEAK_LIST_ASSOC; /* EBOLA ALERT! */
|
|
2912 if (EQ (symbol, Qkey_assoc)) return WEAK_LIST_KEY_ASSOC;
|
|
2913 if (EQ (symbol, Qvalue_assoc)) return WEAK_LIST_VALUE_ASSOC;
|
442
|
2914 if (EQ (symbol, Qfull_assoc)) return WEAK_LIST_FULL_ASSOC;
|
428
|
2915
|
563
|
2916 invalid_constant ("Invalid weak list type", symbol);
|
1204
|
2917 RETURN_NOT_REACHED (WEAK_LIST_SIMPLE);
|
428
|
2918 }
|
|
2919
|
|
2920 static Lisp_Object
|
|
2921 encode_weak_list_type (enum weak_list_type type)
|
|
2922 {
|
|
2923 switch (type)
|
|
2924 {
|
|
2925 case WEAK_LIST_SIMPLE: return Qsimple;
|
|
2926 case WEAK_LIST_ASSOC: return Qassoc;
|
|
2927 case WEAK_LIST_KEY_ASSOC: return Qkey_assoc;
|
|
2928 case WEAK_LIST_VALUE_ASSOC: return Qvalue_assoc;
|
442
|
2929 case WEAK_LIST_FULL_ASSOC: return Qfull_assoc;
|
428
|
2930 default:
|
2500
|
2931 ABORT ();
|
428
|
2932 }
|
|
2933
|
801
|
2934 return Qnil; /* not (usually) reached */
|
428
|
2935 }
|
|
2936
|
|
2937 DEFUN ("weak-list-p", Fweak_list_p, 1, 1, 0, /*
|
|
2938 Return non-nil if OBJECT is a weak list.
|
|
2939 */
|
|
2940 (object))
|
|
2941 {
|
|
2942 return WEAK_LISTP (object) ? Qt : Qnil;
|
|
2943 }
|
|
2944
|
|
2945 DEFUN ("make-weak-list", Fmake_weak_list, 0, 1, 0, /*
|
|
2946 Return a new weak list object of type TYPE.
|
|
2947 A weak list object is an object that contains a list. This list behaves
|
|
2948 like any other list except that its elements do not count towards
|
456
|
2949 garbage collection -- if the only pointer to an object is inside a weak
|
428
|
2950 list (other than pointers in similar objects such as weak hash tables),
|
|
2951 the object is garbage collected and automatically removed from the list.
|
|
2952 This is used internally, for example, to manage the list holding the
|
|
2953 children of an extent -- an extent that is unused but has a parent will
|
|
2954 still be reclaimed, and will automatically be removed from its parent's
|
|
2955 list of children.
|
|
2956
|
|
2957 Optional argument TYPE specifies the type of the weak list, and defaults
|
|
2958 to `simple'. Recognized types are
|
|
2959
|
|
2960 `simple' Objects in the list disappear if not pointed to.
|
|
2961 `assoc' Objects in the list disappear if they are conses
|
|
2962 and either the car or the cdr of the cons is not
|
|
2963 pointed to.
|
|
2964 `key-assoc' Objects in the list disappear if they are conses
|
|
2965 and the car is not pointed to.
|
|
2966 `value-assoc' Objects in the list disappear if they are conses
|
|
2967 and the cdr is not pointed to.
|
442
|
2968 `full-assoc' Objects in the list disappear if they are conses
|
|
2969 and neither the car nor the cdr is pointed to.
|
428
|
2970 */
|
|
2971 (type))
|
|
2972 {
|
|
2973 if (NILP (type))
|
|
2974 type = Qsimple;
|
|
2975
|
|
2976 return make_weak_list (decode_weak_list_type (type));
|
|
2977 }
|
|
2978
|
|
2979 DEFUN ("weak-list-type", Fweak_list_type, 1, 1, 0, /*
|
|
2980 Return the type of the given weak-list object.
|
|
2981 */
|
|
2982 (weak))
|
|
2983 {
|
|
2984 CHECK_WEAK_LIST (weak);
|
|
2985 return encode_weak_list_type (XWEAK_LIST (weak)->type);
|
|
2986 }
|
|
2987
|
|
2988 DEFUN ("weak-list-list", Fweak_list_list, 1, 1, 0, /*
|
|
2989 Return the list contained in a weak-list object.
|
|
2990 */
|
|
2991 (weak))
|
|
2992 {
|
|
2993 CHECK_WEAK_LIST (weak);
|
|
2994 return XWEAK_LIST_LIST (weak);
|
|
2995 }
|
|
2996
|
|
2997 DEFUN ("set-weak-list-list", Fset_weak_list_list, 2, 2, 0, /*
|
|
2998 Change the list contained in a weak-list object.
|
|
2999 */
|
|
3000 (weak, new_list))
|
|
3001 {
|
|
3002 CHECK_WEAK_LIST (weak);
|
|
3003 XWEAK_LIST_LIST (weak) = new_list;
|
|
3004 return new_list;
|
|
3005 }
|
|
3006
|
888
|
3007
|
858
|
3008 /************************************************************************/
|
|
3009 /* weak boxes */
|
|
3010 /************************************************************************/
|
|
3011
|
|
3012 static Lisp_Object Vall_weak_boxes; /* Gemarke es niemals ever!!! */
|
|
3013
|
|
3014 void
|
|
3015 prune_weak_boxes (void)
|
|
3016 {
|
|
3017 Lisp_Object rest, prev = Qnil;
|
888
|
3018 int removep = 0;
|
858
|
3019
|
|
3020 for (rest = Vall_weak_boxes;
|
|
3021 !NILP(rest);
|
|
3022 rest = XWEAK_BOX (rest)->next_weak_box)
|
|
3023 {
|
|
3024 if (! (marked_p (rest)))
|
888
|
3025 /* This weak box itself is garbage. */
|
|
3026 removep = 1;
|
|
3027
|
|
3028 if (! marked_p (XWEAK_BOX (rest)->value))
|
|
3029 {
|
|
3030 XSET_WEAK_BOX (rest, Qnil);
|
|
3031 removep = 1;
|
|
3032 }
|
|
3033
|
|
3034 if (removep)
|
|
3035 {
|
|
3036 /* Remove weak box from list. */
|
|
3037 if (NILP (prev))
|
|
3038 Vall_weak_boxes = XWEAK_BOX (rest)->next_weak_box;
|
|
3039 else
|
|
3040 XWEAK_BOX (prev)->next_weak_box = XWEAK_BOX (rest)->next_weak_box;
|
|
3041 removep = 0;
|
|
3042 }
|
|
3043 else
|
|
3044 prev = rest;
|
858
|
3045 }
|
|
3046 }
|
|
3047
|
|
3048 static Lisp_Object
|
2286
|
3049 mark_weak_box (Lisp_Object UNUSED (obj))
|
858
|
3050 {
|
|
3051 return Qnil;
|
|
3052 }
|
|
3053
|
|
3054 static void
|
2286
|
3055 print_weak_box (Lisp_Object UNUSED (obj), Lisp_Object printcharfun,
|
|
3056 int UNUSED (escapeflag))
|
858
|
3057 {
|
|
3058 if (print_readably)
|
|
3059 printing_unreadable_object ("#<weak_box>");
|
|
3060 write_fmt_string (printcharfun, "#<weak_box>");
|
|
3061 }
|
|
3062
|
|
3063 static int
|
|
3064 weak_box_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
|
3065 {
|
888
|
3066 struct weak_box *wb1 = XWEAK_BOX (obj1);
|
|
3067 struct weak_box *wb2 = XWEAK_BOX (obj2);
|
858
|
3068
|
888
|
3069 return (internal_equal (wb1->value, wb2->value, depth + 1));
|
858
|
3070 }
|
|
3071
|
|
3072 static Hashcode
|
|
3073 weak_box_hash (Lisp_Object obj, int depth)
|
|
3074 {
|
888
|
3075 struct weak_box *wb = XWEAK_BOX (obj);
|
858
|
3076
|
888
|
3077 return internal_hash (wb->value, depth + 1);
|
858
|
3078 }
|
|
3079
|
|
3080 Lisp_Object
|
|
3081 make_weak_box (Lisp_Object value)
|
|
3082 {
|
|
3083 Lisp_Object result;
|
|
3084
|
|
3085 struct weak_box *wb =
|
3017
|
3086 ALLOC_LCRECORD_TYPE (struct weak_box, &lrecord_weak_box);
|
858
|
3087
|
|
3088 wb->value = value;
|
|
3089 result = wrap_weak_box (wb);
|
|
3090 wb->next_weak_box = Vall_weak_boxes;
|
|
3091 Vall_weak_boxes = result;
|
|
3092 return result;
|
|
3093 }
|
|
3094
|
1204
|
3095 static const struct memory_description weak_box_description[] = {
|
858
|
3096 { XD_LO_LINK, offsetof (struct weak_box, value) },
|
888
|
3097 { XD_END}
|
858
|
3098 };
|
|
3099
|
934
|
3100 DEFINE_LRECORD_IMPLEMENTATION ("weak_box", weak_box,
|
|
3101 0, /*dumpable-flag*/
|
|
3102 mark_weak_box, print_weak_box,
|
|
3103 0, weak_box_equal, weak_box_hash,
|
|
3104 weak_box_description,
|
|
3105 struct weak_box);
|
858
|
3106
|
|
3107 DEFUN ("make-weak-box", Fmake_weak_box, 1, 1, 0, /*
|
|
3108 Return a new weak box from value CONTENTS.
|
|
3109 The weak box is a reference to CONTENTS which may be extracted with
|
|
3110 `weak-box-ref'. However, the weak box does not contribute to the
|
|
3111 reachability of CONTENTS. When CONTENTS is garbage-collected,
|
|
3112 `weak-box-ref' will return NIL.
|
|
3113 */
|
|
3114 (value))
|
|
3115 {
|
|
3116 return make_weak_box(value);
|
|
3117 }
|
|
3118
|
|
3119 DEFUN ("weak-box-ref", Fweak_box_ref, 1, 1, 0, /*
|
|
3120 Return the contents of weak box WEAK-BOX.
|
|
3121 If the contents have been GCed, return NIL.
|
|
3122 */
|
888
|
3123 (wb))
|
858
|
3124 {
|
888
|
3125 return XWEAK_BOX (wb)->value;
|
858
|
3126 }
|
|
3127
|
|
3128 DEFUN ("weak-box-p", Fweak_boxp, 1, 1, 0, /*
|
|
3129 Return non-nil if OBJECT is a weak box.
|
|
3130 */
|
|
3131 (object))
|
|
3132 {
|
|
3133 return WEAK_BOXP (object) ? Qt : Qnil;
|
|
3134 }
|
|
3135
|
888
|
3136 /************************************************************************/
|
|
3137 /* ephemerons */
|
|
3138 /************************************************************************/
|
|
3139
|
993
|
3140 /* The concept of ephemerons is due to:
|
|
3141 * Barry Hayes: Ephemerons: A New Finalization Mechanism. OOPSLA 1997: 176-183
|
|
3142 * The original idea is due to George Bosworth of Digitalk, Inc.
|
|
3143 *
|
|
3144 * For a discussion of finalization and weakness that also reviews
|
|
3145 * ephemerons, refer to:
|
|
3146 * Simon Peyton Jones, Simon Marlow, Conal Elliot:
|
|
3147 * Stretching the storage manager
|
|
3148 * Implementation of Functional Languages, 1999
|
|
3149 */
|
|
3150
|
888
|
3151 static Lisp_Object Vall_ephemerons; /* Gemarke es niemals ever!!! */
|
1590
|
3152 static Lisp_Object Vnew_all_ephemerons;
|
888
|
3153 static Lisp_Object Vfinalize_list;
|
|
3154
|
1590
|
3155 void
|
|
3156 init_marking_ephemerons(void)
|
|
3157 {
|
|
3158 Vnew_all_ephemerons = Qnil;
|
|
3159 }
|
|
3160
|
|
3161 /* Move all live ephemerons with live keys over to
|
|
3162 * Vnew_all_ephemerons, marking the values and finalizers along the
|
|
3163 * way. */
|
|
3164
|
|
3165 int
|
|
3166 continue_marking_ephemerons(void)
|
|
3167 {
|
|
3168 Lisp_Object rest = Vall_ephemerons, next, prev = Qnil;
|
|
3169 int did_mark = 0;
|
|
3170
|
|
3171 while (!NILP (rest))
|
|
3172 {
|
|
3173 next = XEPHEMERON_NEXT (rest);
|
|
3174
|
|
3175 if (marked_p (rest))
|
|
3176 {
|
|
3177 MARK_CONS (XCONS (XEPHEMERON (rest)->cons_chain));
|
|
3178 if (marked_p (XEPHEMERON (rest)->key))
|
|
3179 {
|
1598
|
3180 #ifdef USE_KKCC
|
|
3181 kkcc_gc_stack_push_lisp_object
|
2645
|
3182 (XCAR (XEPHEMERON (rest)->cons_chain), 0, -1);
|
1598
|
3183 #else /* NOT USE_KKCC */
|
1590
|
3184 mark_object (XCAR (XEPHEMERON (rest)->cons_chain));
|
1598
|
3185 #endif /* NOT USE_KKCC */
|
1590
|
3186 did_mark = 1;
|
|
3187 XSET_EPHEMERON_NEXT (rest, Vnew_all_ephemerons);
|
|
3188 Vnew_all_ephemerons = rest;
|
|
3189 if (NILP (prev))
|
|
3190 Vall_ephemerons = next;
|
|
3191 else
|
|
3192 XSET_EPHEMERON_NEXT (prev, next);
|
|
3193 }
|
|
3194 else
|
|
3195 prev = rest;
|
|
3196 }
|
|
3197 else
|
|
3198 prev = rest;
|
|
3199
|
|
3200 rest = next;
|
|
3201 }
|
|
3202
|
|
3203 return did_mark;
|
|
3204 }
|
|
3205
|
|
3206 /* At this point, everything that's in Vall_ephemerons is dead.
|
|
3207 * Well, almost: we still need to run the finalizers, so we need to
|
|
3208 * resurrect them.
|
|
3209 */
|
|
3210
|
888
|
3211 int
|
|
3212 finish_marking_ephemerons(void)
|
|
3213 {
|
1590
|
3214 Lisp_Object rest = Vall_ephemerons, next, prev = Qnil;
|
888
|
3215 int did_mark = 0;
|
|
3216
|
|
3217 while (! NILP (rest))
|
|
3218 {
|
|
3219 next = XEPHEMERON_NEXT (rest);
|
|
3220
|
|
3221 if (marked_p (rest))
|
1590
|
3222 /* The ephemeron itself is live, but its key is garbage */
|
888
|
3223 {
|
1590
|
3224 /* tombstone */
|
|
3225 XSET_EPHEMERON_VALUE (rest, Qnil);
|
|
3226
|
|
3227 if (! NILP (XEPHEMERON_FINALIZER (rest)))
|
888
|
3228 {
|
1590
|
3229 MARK_CONS (XCONS (XEPHEMERON (rest)->cons_chain));
|
1598
|
3230 #ifdef USE_KKCC
|
|
3231 kkcc_gc_stack_push_lisp_object
|
2645
|
3232 (XCAR (XEPHEMERON (rest)->cons_chain), 0, -1);
|
1598
|
3233 #else /* NOT USE_KKCC */
|
1590
|
3234 mark_object (XCAR (XEPHEMERON (rest)->cons_chain));
|
1598
|
3235 #endif /* NOT USE_KKCC */
|
1590
|
3236
|
|
3237 /* Register the finalizer */
|
|
3238 XSET_EPHEMERON_NEXT (rest, Vfinalize_list);
|
|
3239 Vfinalize_list = XEPHEMERON (rest)->cons_chain;
|
|
3240 did_mark = 1;
|
888
|
3241 }
|
|
3242
|
|
3243 /* Remove it from the list. */
|
|
3244 if (NILP (prev))
|
|
3245 Vall_ephemerons = next;
|
|
3246 else
|
|
3247 XSET_EPHEMERON_NEXT (prev, next);
|
|
3248 }
|
|
3249 else
|
|
3250 prev = rest;
|
|
3251
|
|
3252 rest = next;
|
|
3253 }
|
1590
|
3254
|
|
3255 return did_mark;
|
|
3256 }
|
|
3257
|
|
3258 void
|
|
3259 prune_ephemerons(void)
|
|
3260 {
|
|
3261 Vall_ephemerons = Vnew_all_ephemerons;
|
888
|
3262 }
|
|
3263
|
|
3264 Lisp_Object
|
|
3265 zap_finalize_list(void)
|
|
3266 {
|
|
3267 Lisp_Object finalizers = Vfinalize_list;
|
|
3268
|
|
3269 Vfinalize_list = Qnil;
|
|
3270
|
|
3271 return finalizers;
|
|
3272 }
|
|
3273
|
|
3274 static Lisp_Object
|
2286
|
3275 mark_ephemeron (Lisp_Object UNUSED (obj))
|
888
|
3276 {
|
|
3277 return Qnil;
|
|
3278 }
|
|
3279
|
|
3280 static void
|
2286
|
3281 print_ephemeron (Lisp_Object UNUSED (obj), Lisp_Object printcharfun,
|
|
3282 int UNUSED (escapeflag))
|
888
|
3283 {
|
|
3284 if (print_readably)
|
|
3285 printing_unreadable_object ("#<ephemeron>");
|
|
3286 write_fmt_string (printcharfun, "#<ephemeron>");
|
|
3287 }
|
|
3288
|
|
3289 static int
|
|
3290 ephemeron_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
|
|
3291 {
|
|
3292 return
|
|
3293 internal_equal (XEPHEMERON_REF (obj1), XEPHEMERON_REF(obj2), depth + 1);
|
|
3294 }
|
|
3295
|
|
3296 static Hashcode
|
|
3297 ephemeron_hash(Lisp_Object obj, int depth)
|
|
3298 {
|
|
3299 return internal_hash (XEPHEMERON_REF (obj), depth + 1);
|
|
3300 }
|
|
3301
|
|
3302 Lisp_Object
|
|
3303 make_ephemeron(Lisp_Object key, Lisp_Object value, Lisp_Object finalizer)
|
|
3304 {
|
|
3305 Lisp_Object result, temp = Qnil;
|
|
3306 struct gcpro gcpro1, gcpro2;
|
|
3307
|
|
3308 struct ephemeron *eph =
|
3017
|
3309 ALLOC_LCRECORD_TYPE (struct ephemeron, &lrecord_ephemeron);
|
888
|
3310
|
|
3311 eph->key = Qnil;
|
|
3312 eph->cons_chain = Qnil;
|
|
3313 eph->value = Qnil;
|
|
3314
|
|
3315 result = wrap_ephemeron(eph);
|
|
3316 GCPRO2 (result, temp);
|
|
3317
|
|
3318 eph->key = key;
|
|
3319 temp = Fcons(value, finalizer);
|
|
3320 eph->cons_chain = Fcons(temp, Vall_ephemerons);
|
|
3321 eph->value = value;
|
|
3322
|
|
3323 Vall_ephemerons = result;
|
|
3324
|
|
3325 UNGCPRO;
|
|
3326 return result;
|
|
3327 }
|
|
3328
|
1598
|
3329 /* Ephemerons are special cases in the KKCC mark algorithm, so nothing
|
|
3330 is marked here. */
|
1204
|
3331 static const struct memory_description ephemeron_description[] = {
|
|
3332 { XD_LISP_OBJECT, offsetof(struct ephemeron, key),
|
2551
|
3333 0, { 0 }, XD_FLAG_NO_KKCC },
|
1204
|
3334 { XD_LISP_OBJECT, offsetof(struct ephemeron, cons_chain),
|
2551
|
3335 0, { 0 }, XD_FLAG_NO_KKCC },
|
1204
|
3336 { XD_LISP_OBJECT, offsetof(struct ephemeron, value),
|
2551
|
3337 0, { 0 }, XD_FLAG_NO_KKCC },
|
888
|
3338 { XD_END }
|
|
3339 };
|
|
3340
|
934
|
3341 DEFINE_LRECORD_IMPLEMENTATION ("ephemeron", ephemeron,
|
|
3342 0, /*dumpable-flag*/
|
|
3343 mark_ephemeron, print_ephemeron,
|
|
3344 0, ephemeron_equal, ephemeron_hash,
|
|
3345 ephemeron_description,
|
|
3346 struct ephemeron);
|
888
|
3347
|
|
3348 DEFUN ("make-ephemeron", Fmake_ephemeron, 2, 3, 0, /*
|
1590
|
3349 Return a new ephemeron with key KEY, value VALUE, and finalizer FINALIZER.
|
|
3350 The ephemeron is a reference to VALUE which may be extracted with
|
|
3351 `ephemeron-ref'. VALUE is only reachable through the ephemeron as
|
888
|
3352 long as KEY is reachable; the ephemeron does not contribute to the
|
|
3353 reachability of KEY. When KEY becomes unreachable while the ephemeron
|
1590
|
3354 itself is still reachable, VALUE is queued for finalization: FINALIZER
|
|
3355 will possibly be called on VALUE some time in the future. Moreover,
|
888
|
3356 future calls to `ephemeron-ref' will return NIL.
|
|
3357 */
|
|
3358 (key, value, finalizer))
|
|
3359 {
|
|
3360 return make_ephemeron(key, value, finalizer);
|
|
3361 }
|
|
3362
|
|
3363 DEFUN ("ephemeron-ref", Fephemeron_ref, 1, 1, 0, /*
|
|
3364 Return the contents of ephemeron EPHEMERON.
|
|
3365 If the contents have been GCed, return NIL.
|
|
3366 */
|
|
3367 (eph))
|
|
3368 {
|
|
3369 return XEPHEMERON_REF (eph);
|
|
3370 }
|
|
3371
|
|
3372 DEFUN ("ephemeron-p", Fephemeronp, 1, 1, 0, /*
|
|
3373 Return non-nil if OBJECT is an ephemeron.
|
|
3374 */
|
|
3375 (object))
|
|
3376 {
|
|
3377 return EPHEMERONP (object) ? Qt : Qnil;
|
|
3378 }
|
428
|
3379
|
|
3380 /************************************************************************/
|
|
3381 /* initialization */
|
|
3382 /************************************************************************/
|
|
3383
|
|
3384 static SIGTYPE
|
|
3385 arith_error (int signo)
|
|
3386 {
|
|
3387 EMACS_REESTABLISH_SIGNAL (signo, arith_error);
|
|
3388 EMACS_UNBLOCK_SIGNAL (signo);
|
563
|
3389 signal_error (Qarith_error, 0, Qunbound);
|
428
|
3390 }
|
|
3391
|
|
3392 void
|
|
3393 init_data_very_early (void)
|
|
3394 {
|
|
3395 /* Don't do this if just dumping out.
|
|
3396 We don't want to call `signal' in this case
|
|
3397 so that we don't have trouble with dumping
|
|
3398 signal-delivering routines in an inconsistent state. */
|
|
3399 if (!initialized)
|
|
3400 return;
|
613
|
3401 EMACS_SIGNAL (SIGFPE, arith_error);
|
428
|
3402 #ifdef uts
|
613
|
3403 EMACS_SIGNAL (SIGEMT, arith_error);
|
428
|
3404 #endif /* uts */
|
|
3405 }
|
|
3406
|
|
3407 void
|
|
3408 init_errors_once_early (void)
|
|
3409 {
|
442
|
3410 DEFSYMBOL (Qerror_conditions);
|
|
3411 DEFSYMBOL (Qerror_message);
|
428
|
3412
|
|
3413 /* We declare the errors here because some other deferrors depend
|
|
3414 on some of the errors below. */
|
|
3415
|
|
3416 /* ERROR is used as a signaler for random errors for which nothing
|
|
3417 else is right */
|
|
3418
|
442
|
3419 DEFERROR (Qerror, "error", Qnil);
|
|
3420 DEFERROR_STANDARD (Qquit, Qnil);
|
428
|
3421
|
563
|
3422 DEFERROR_STANDARD (Qinvalid_argument, Qerror);
|
|
3423
|
|
3424 DEFERROR_STANDARD (Qsyntax_error, Qinvalid_argument);
|
442
|
3425 DEFERROR_STANDARD (Qinvalid_read_syntax, Qsyntax_error);
|
563
|
3426 DEFERROR_STANDARD (Qstructure_formation_error, Qsyntax_error);
|
|
3427 DEFERROR_STANDARD (Qlist_formation_error, Qstructure_formation_error);
|
442
|
3428 DEFERROR_STANDARD (Qmalformed_list, Qlist_formation_error);
|
|
3429 DEFERROR_STANDARD (Qmalformed_property_list, Qmalformed_list);
|
|
3430 DEFERROR_STANDARD (Qcircular_list, Qlist_formation_error);
|
|
3431 DEFERROR_STANDARD (Qcircular_property_list, Qcircular_list);
|
428
|
3432
|
442
|
3433 DEFERROR_STANDARD (Qwrong_type_argument, Qinvalid_argument);
|
|
3434 DEFERROR_STANDARD (Qargs_out_of_range, Qinvalid_argument);
|
|
3435 DEFERROR_STANDARD (Qwrong_number_of_arguments, Qinvalid_argument);
|
|
3436 DEFERROR_STANDARD (Qinvalid_function, Qinvalid_argument);
|
563
|
3437 DEFERROR_STANDARD (Qinvalid_constant, Qinvalid_argument);
|
442
|
3438 DEFERROR (Qno_catch, "No catch for tag", Qinvalid_argument);
|
|
3439
|
563
|
3440 DEFERROR_STANDARD (Qinvalid_state, Qerror);
|
442
|
3441 DEFERROR (Qvoid_function, "Symbol's function definition is void",
|
|
3442 Qinvalid_state);
|
|
3443 DEFERROR (Qcyclic_function_indirection,
|
|
3444 "Symbol's chain of function indirections contains a loop",
|
|
3445 Qinvalid_state);
|
|
3446 DEFERROR (Qvoid_variable, "Symbol's value as variable is void",
|
|
3447 Qinvalid_state);
|
|
3448 DEFERROR (Qcyclic_variable_indirection,
|
|
3449 "Symbol's chain of variable indirections contains a loop",
|
|
3450 Qinvalid_state);
|
563
|
3451 DEFERROR_STANDARD (Qstack_overflow, Qinvalid_state);
|
|
3452 DEFERROR_STANDARD (Qinternal_error, Qinvalid_state);
|
|
3453 DEFERROR_STANDARD (Qout_of_memory, Qinvalid_state);
|
428
|
3454
|
563
|
3455 DEFERROR_STANDARD (Qinvalid_operation, Qerror);
|
|
3456 DEFERROR_STANDARD (Qinvalid_change, Qinvalid_operation);
|
442
|
3457 DEFERROR (Qsetting_constant, "Attempt to set a constant symbol",
|
|
3458 Qinvalid_change);
|
563
|
3459 DEFERROR_STANDARD (Qprinting_unreadable_object, Qinvalid_operation);
|
|
3460 DEFERROR (Qunimplemented, "Feature not yet implemented", Qinvalid_operation);
|
442
|
3461
|
563
|
3462 DEFERROR_STANDARD (Qediting_error, Qinvalid_operation);
|
442
|
3463 DEFERROR_STANDARD (Qbeginning_of_buffer, Qediting_error);
|
|
3464 DEFERROR_STANDARD (Qend_of_buffer, Qediting_error);
|
|
3465 DEFERROR (Qbuffer_read_only, "Buffer is read-only", Qediting_error);
|
|
3466
|
|
3467 DEFERROR (Qio_error, "IO Error", Qinvalid_operation);
|
563
|
3468 DEFERROR_STANDARD (Qfile_error, Qio_error);
|
|
3469 DEFERROR (Qend_of_file, "End of file or stream", Qfile_error);
|
|
3470 DEFERROR_STANDARD (Qconversion_error, Qio_error);
|
580
|
3471 DEFERROR_STANDARD (Qtext_conversion_error, Qconversion_error);
|
442
|
3472
|
|
3473 DEFERROR (Qarith_error, "Arithmetic error", Qinvalid_operation);
|
|
3474 DEFERROR (Qrange_error, "Arithmetic range error", Qarith_error);
|
|
3475 DEFERROR (Qdomain_error, "Arithmetic domain error", Qarith_error);
|
|
3476 DEFERROR (Qsingularity_error, "Arithmetic singularity error", Qdomain_error);
|
|
3477 DEFERROR (Qoverflow_error, "Arithmetic overflow error", Qdomain_error);
|
|
3478 DEFERROR (Qunderflow_error, "Arithmetic underflow error", Qdomain_error);
|
428
|
3479 }
|
|
3480
|
|
3481 void
|
|
3482 syms_of_data (void)
|
|
3483 {
|
442
|
3484 INIT_LRECORD_IMPLEMENTATION (weak_list);
|
888
|
3485 INIT_LRECORD_IMPLEMENTATION (ephemeron);
|
858
|
3486 INIT_LRECORD_IMPLEMENTATION (weak_box);
|
442
|
3487
|
|
3488 DEFSYMBOL (Qquote);
|
|
3489 DEFSYMBOL (Qlambda);
|
|
3490 DEFSYMBOL (Qlistp);
|
|
3491 DEFSYMBOL (Qtrue_list_p);
|
|
3492 DEFSYMBOL (Qconsp);
|
|
3493 DEFSYMBOL (Qsubrp);
|
|
3494 DEFSYMBOL (Qsymbolp);
|
|
3495 DEFSYMBOL (Qintegerp);
|
|
3496 DEFSYMBOL (Qcharacterp);
|
|
3497 DEFSYMBOL (Qnatnump);
|
1983
|
3498 DEFSYMBOL (Qnonnegativep);
|
442
|
3499 DEFSYMBOL (Qstringp);
|
|
3500 DEFSYMBOL (Qarrayp);
|
|
3501 DEFSYMBOL (Qsequencep);
|
|
3502 DEFSYMBOL (Qbufferp);
|
|
3503 DEFSYMBOL (Qbitp);
|
|
3504 DEFSYMBOL_MULTIWORD_PREDICATE (Qbit_vectorp);
|
|
3505 DEFSYMBOL (Qvectorp);
|
|
3506 DEFSYMBOL (Qchar_or_string_p);
|
|
3507 DEFSYMBOL (Qmarkerp);
|
|
3508 DEFSYMBOL (Qinteger_or_marker_p);
|
|
3509 DEFSYMBOL (Qinteger_or_char_p);
|
|
3510 DEFSYMBOL (Qinteger_char_or_marker_p);
|
|
3511 DEFSYMBOL (Qnumberp);
|
|
3512 DEFSYMBOL (Qnumber_char_or_marker_p);
|
|
3513 DEFSYMBOL (Qcdr);
|
563
|
3514 DEFSYMBOL (Qerror_lacks_explanatory_string);
|
442
|
3515 DEFSYMBOL_MULTIWORD_PREDICATE (Qweak_listp);
|
|
3516 DEFSYMBOL (Qfloatp);
|
428
|
3517
|
|
3518 DEFSUBR (Fwrong_type_argument);
|
|
3519
|
1983
|
3520 #ifdef HAVE_RATIO
|
|
3521 DEFSUBR (Fdiv);
|
|
3522 #endif
|
428
|
3523 DEFSUBR (Feq);
|
|
3524 DEFSUBR (Fold_eq);
|
|
3525 DEFSUBR (Fnull);
|
|
3526 Ffset (intern ("not"), intern ("null"));
|
|
3527 DEFSUBR (Flistp);
|
|
3528 DEFSUBR (Fnlistp);
|
|
3529 DEFSUBR (Ftrue_list_p);
|
|
3530 DEFSUBR (Fconsp);
|
|
3531 DEFSUBR (Fatom);
|
|
3532 DEFSUBR (Fchar_or_string_p);
|
|
3533 DEFSUBR (Fcharacterp);
|
|
3534 DEFSUBR (Fchar_int_p);
|
|
3535 DEFSUBR (Fchar_to_int);
|
|
3536 DEFSUBR (Fint_to_char);
|
|
3537 DEFSUBR (Fchar_or_char_int_p);
|
1983
|
3538 #ifdef HAVE_BIGNUM
|
|
3539 DEFSUBR (Ffixnump);
|
|
3540 #else
|
428
|
3541 DEFSUBR (Fintegerp);
|
1983
|
3542 #endif
|
428
|
3543 DEFSUBR (Finteger_or_marker_p);
|
|
3544 DEFSUBR (Finteger_or_char_p);
|
|
3545 DEFSUBR (Finteger_char_or_marker_p);
|
|
3546 DEFSUBR (Fnumberp);
|
|
3547 DEFSUBR (Fnumber_or_marker_p);
|
|
3548 DEFSUBR (Fnumber_char_or_marker_p);
|
|
3549 DEFSUBR (Ffloatp);
|
|
3550 DEFSUBR (Fnatnump);
|
1983
|
3551 DEFSUBR (Fnonnegativep);
|
428
|
3552 DEFSUBR (Fsymbolp);
|
|
3553 DEFSUBR (Fkeywordp);
|
|
3554 DEFSUBR (Fstringp);
|
|
3555 DEFSUBR (Fvectorp);
|
|
3556 DEFSUBR (Fbitp);
|
|
3557 DEFSUBR (Fbit_vector_p);
|
|
3558 DEFSUBR (Farrayp);
|
|
3559 DEFSUBR (Fsequencep);
|
|
3560 DEFSUBR (Fmarkerp);
|
|
3561 DEFSUBR (Fsubrp);
|
|
3562 DEFSUBR (Fsubr_min_args);
|
|
3563 DEFSUBR (Fsubr_max_args);
|
|
3564 DEFSUBR (Fsubr_interactive);
|
|
3565 DEFSUBR (Ftype_of);
|
|
3566 DEFSUBR (Fcar);
|
|
3567 DEFSUBR (Fcdr);
|
|
3568 DEFSUBR (Fcar_safe);
|
|
3569 DEFSUBR (Fcdr_safe);
|
|
3570 DEFSUBR (Fsetcar);
|
|
3571 DEFSUBR (Fsetcdr);
|
|
3572 DEFSUBR (Findirect_function);
|
|
3573 DEFSUBR (Faref);
|
|
3574 DEFSUBR (Faset);
|
|
3575
|
|
3576 DEFSUBR (Fnumber_to_string);
|
|
3577 DEFSUBR (Fstring_to_number);
|
|
3578 DEFSUBR (Feqlsign);
|
|
3579 DEFSUBR (Flss);
|
|
3580 DEFSUBR (Fgtr);
|
|
3581 DEFSUBR (Fleq);
|
|
3582 DEFSUBR (Fgeq);
|
|
3583 DEFSUBR (Fneq);
|
|
3584 DEFSUBR (Fzerop);
|
|
3585 DEFSUBR (Fplus);
|
|
3586 DEFSUBR (Fminus);
|
|
3587 DEFSUBR (Ftimes);
|
|
3588 DEFSUBR (Fquo);
|
|
3589 DEFSUBR (Frem);
|
|
3590 DEFSUBR (Fmod);
|
|
3591 DEFSUBR (Fmax);
|
|
3592 DEFSUBR (Fmin);
|
|
3593 DEFSUBR (Flogand);
|
|
3594 DEFSUBR (Flogior);
|
|
3595 DEFSUBR (Flogxor);
|
|
3596 DEFSUBR (Flsh);
|
|
3597 DEFSUBR (Fash);
|
|
3598 DEFSUBR (Fadd1);
|
|
3599 DEFSUBR (Fsub1);
|
|
3600 DEFSUBR (Flognot);
|
|
3601
|
|
3602 DEFSUBR (Fweak_list_p);
|
|
3603 DEFSUBR (Fmake_weak_list);
|
|
3604 DEFSUBR (Fweak_list_type);
|
|
3605 DEFSUBR (Fweak_list_list);
|
|
3606 DEFSUBR (Fset_weak_list_list);
|
858
|
3607
|
888
|
3608 DEFSUBR (Fmake_ephemeron);
|
|
3609 DEFSUBR (Fephemeron_ref);
|
|
3610 DEFSUBR (Fephemeronp);
|
858
|
3611 DEFSUBR (Fmake_weak_box);
|
|
3612 DEFSUBR (Fweak_box_ref);
|
|
3613 DEFSUBR (Fweak_boxp);
|
428
|
3614 }
|
|
3615
|
|
3616 void
|
|
3617 vars_of_data (void)
|
|
3618 {
|
|
3619 /* This must not be staticpro'd */
|
|
3620 Vall_weak_lists = Qnil;
|
452
|
3621 dump_add_weak_object_chain (&Vall_weak_lists);
|
428
|
3622
|
888
|
3623 Vall_ephemerons = Qnil;
|
|
3624 dump_add_weak_object_chain (&Vall_ephemerons);
|
|
3625
|
|
3626 Vfinalize_list = Qnil;
|
|
3627 staticpro (&Vfinalize_list);
|
|
3628
|
858
|
3629 Vall_weak_boxes = Qnil;
|
|
3630 dump_add_weak_object_chain (&Vall_weak_boxes);
|
|
3631
|
428
|
3632 #ifdef DEBUG_XEMACS
|
|
3633 DEFVAR_BOOL ("debug-issue-ebola-notices", &debug_issue_ebola_notices /*
|
|
3634 If non-zero, note when your code may be suffering from char-int confoundance.
|
|
3635 That is to say, if XEmacs encounters a usage of `eq', `memq', `equal',
|
|
3636 etc. where an int and a char with the same value are being compared,
|
|
3637 it will issue a notice on stderr to this effect, along with a backtrace.
|
|
3638 In such situations, the result would be different in XEmacs 19 versus
|
|
3639 XEmacs 20, and you probably don't want this.
|
|
3640
|
|
3641 Note that in order to see these notices, you have to byte compile your
|
|
3642 code under XEmacs 20 -- any code byte-compiled under XEmacs 19 will
|
|
3643 have its chars and ints all confounded in the byte code, making it
|
|
3644 impossible to accurately determine Ebola infection.
|
|
3645 */ );
|
|
3646
|
|
3647 debug_issue_ebola_notices = 0;
|
|
3648
|
|
3649 DEFVAR_INT ("debug-ebola-backtrace-length",
|
|
3650 &debug_ebola_backtrace_length /*
|
|
3651 Length (in stack frames) of short backtrace printed out in Ebola notices.
|
|
3652 See `debug-issue-ebola-notices'.
|
|
3653 */ );
|
|
3654 debug_ebola_backtrace_length = 32;
|
|
3655
|
|
3656 #endif /* DEBUG_XEMACS */
|
|
3657 }
|