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