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