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