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