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