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