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