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