(M-40132'): Unify GT-53970.
[chise/xemacs-chise.git-] / src / data.c
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.
4    Copyright (C) 2000 Ben Wing.
5
6 This file is part of XEmacs.
7
8 XEmacs is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 2, or (at your option) any
11 later version.
12
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with XEmacs; see the file COPYING.  If not, write to
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA.  */
22
23 /* Synched up with: Mule 2.0, FSF 19.30.  Some of FSF's data.c is in
24    XEmacs' symbols.c. */
25
26 /* This file has been Mule-ized. */
27
28 #include <config.h>
29 #include "lisp.h"
30
31 #include "buffer.h"
32 #include "bytecode.h"
33 #include "syssignal.h"
34
35 #ifdef LISP_FLOAT_TYPE
36 /* Need to define a differentiating symbol -- see sysfloat.h */
37 # define THIS_FILENAME data_c
38 # include "sysfloat.h"
39 #endif /* LISP_FLOAT_TYPE */
40
41 Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound;
42 Lisp_Object Qerror_conditions, Qerror_message;
43 Lisp_Object Qerror, Qquit, Qsyntax_error, Qinvalid_read_syntax;
44 Lisp_Object Qlist_formation_error;
45 Lisp_Object Qmalformed_list, Qmalformed_property_list;
46 Lisp_Object Qcircular_list, Qcircular_property_list;
47 Lisp_Object Qinvalid_argument, Qwrong_type_argument, Qargs_out_of_range;
48 Lisp_Object Qwrong_number_of_arguments, Qinvalid_function, Qno_catch;
49 Lisp_Object Qinternal_error, Qinvalid_state;
50 Lisp_Object Qvoid_variable, Qcyclic_variable_indirection;
51 Lisp_Object Qvoid_function, Qcyclic_function_indirection;
52 Lisp_Object Qinvalid_operation, Qinvalid_change;
53 Lisp_Object Qsetting_constant;
54 Lisp_Object Qediting_error;
55 Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
56 Lisp_Object Qio_error, Qend_of_file;
57 Lisp_Object Qarith_error, Qrange_error, Qdomain_error;
58 Lisp_Object Qsingularity_error, Qoverflow_error, Qunderflow_error;
59 Lisp_Object Qintegerp, Qnatnump, Qsymbolp;
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
68 Lisp_Object Qfloatp;
69
70 #ifdef DEBUG_XEMACS
71
72 int debug_issue_ebola_notices;
73
74 Fixnum debug_ebola_backtrace_length;
75
76 int
77 eq_with_ebola_notice (Lisp_Object obj1, Lisp_Object obj2)
78 {
79   if (debug_issue_ebola_notices
80       && ((CHARP (obj1) && INTP (obj2)) || (CHARP (obj2) && INTP (obj1))))
81     {
82       /* #### It would be really nice if this were a proper warning
83          instead of brain-dead print ro Qexternal_debugging_output.  */
84       write_c_string ("Comparison between integer and character is constant nil (",
85                       Qexternal_debugging_output);
86       Fprinc (obj1, Qexternal_debugging_output);
87       write_c_string (" and ", Qexternal_debugging_output);
88       Fprinc (obj2, Qexternal_debugging_output);
89       write_c_string (")\n", Qexternal_debugging_output);
90       debug_short_backtrace (debug_ebola_backtrace_length);
91     }
92   return EQ (obj1, obj2);
93 }
94
95 #endif /* DEBUG_XEMACS */
96
97
98 \f
99 Lisp_Object
100 wrong_type_argument (Lisp_Object predicate, Lisp_Object value)
101 {
102   /* This function can GC */
103   REGISTER Lisp_Object tem;
104   do
105     {
106       value = Fsignal (Qwrong_type_argument, list2 (predicate, value));
107       tem = call1 (predicate, value);
108     }
109   while (NILP (tem));
110   return value;
111 }
112
113 DOESNT_RETURN
114 dead_wrong_type_argument (Lisp_Object predicate, Lisp_Object value)
115 {
116   signal_error (Qwrong_type_argument, list2 (predicate, value));
117 }
118
119 DEFUN ("wrong-type-argument", Fwrong_type_argument, 2, 2, 0, /*
120 Signal an error until the correct type value is given by the user.
121 This function loops, signalling a continuable `wrong-type-argument' error
122 with PREDICATE and VALUE as the data associated with the error and then
123 calling PREDICATE on the returned value, until the value gotten satisfies
124 PREDICATE.  At that point, the gotten value is returned.
125 */
126        (predicate, value))
127 {
128   return wrong_type_argument (predicate, value);
129 }
130
131 DOESNT_RETURN
132 c_write_error (Lisp_Object obj)
133 {
134   signal_simple_error ("Attempt to modify read-only object (c)", obj);
135 }
136
137 DOESNT_RETURN
138 lisp_write_error (Lisp_Object obj)
139 {
140   signal_simple_error ("Attempt to modify read-only object (lisp)", obj);
141 }
142
143 DOESNT_RETURN
144 args_out_of_range (Lisp_Object a1, Lisp_Object a2)
145 {
146   signal_error (Qargs_out_of_range, list2 (a1, a2));
147 }
148
149 DOESNT_RETURN
150 args_out_of_range_3 (Lisp_Object a1, Lisp_Object a2, Lisp_Object a3)
151 {
152   signal_error (Qargs_out_of_range, list3 (a1, a2, a3));
153 }
154
155 void
156 check_int_range (EMACS_INT val, EMACS_INT min, EMACS_INT max)
157 {
158   if (val < min || val > max)
159     args_out_of_range_3 (make_int (val), make_int (min), make_int (max));
160 }
161
162 /* On some machines, XINT needs a temporary location.
163    Here it is, in case it is needed.  */
164
165 EMACS_INT sign_extend_temp;
166
167 /* On a few machines, XINT can only be done by calling this.  */
168 /* XEmacs:  only used by m/convex.h */
169 EMACS_INT sign_extend_lisp_int (EMACS_INT num);
170 EMACS_INT
171 sign_extend_lisp_int (EMACS_INT num)
172 {
173   if (num & (1L << (VALBITS - 1)))
174     return num | ((-1L) << VALBITS);
175   else
176     return num & ((1L << VALBITS) - 1);
177 }
178
179 \f
180 /* Data type predicates */
181
182 DEFUN ("eq", Feq, 2, 2, 0, /*
183 Return t if the two args are the same Lisp object.
184 */
185        (object1, object2))
186 {
187   return EQ_WITH_EBOLA_NOTICE (object1, object2) ? Qt : Qnil;
188 }
189
190 DEFUN ("old-eq", Fold_eq, 2, 2, 0, /*
191 Return t if the two args are (in most cases) the same Lisp object.
192
193 Special kludge: A character is considered `old-eq' to its equivalent integer
194 even though they are not the same object and are in fact of different
195 types.  This is ABSOLUTELY AND UTTERLY HORRENDOUS but is necessary to
196 preserve byte-code compatibility with v19.  This kludge is known as the
197 \"char-int confoundance disease\" and appears in a number of other
198 functions with `old-foo' equivalents.
199
200 Do not use this function!
201 */
202        (object1, object2))
203 {
204   /* #### blasphemy */
205   return HACKEQ_UNSAFE (object1, object2) ? Qt : Qnil;
206 }
207
208 DEFUN ("null", Fnull, 1, 1, 0, /*
209 Return t if OBJECT is nil.
210 */
211        (object))
212 {
213   return NILP (object) ? Qt : Qnil;
214 }
215
216 DEFUN ("consp", Fconsp, 1, 1, 0, /*
217 Return t if OBJECT is a cons cell.  `nil' is not a cons cell.
218 */
219        (object))
220 {
221   return CONSP (object) ? Qt : Qnil;
222 }
223
224 DEFUN ("atom", Fatom, 1, 1, 0, /*
225 Return t if OBJECT is not a cons cell.  `nil' is not a cons cell.
226 */
227        (object))
228 {
229   return CONSP (object) ? Qnil : Qt;
230 }
231
232 DEFUN ("listp", Flistp, 1, 1, 0, /*
233 Return t if OBJECT is a list.  `nil' is a list.
234 */
235        (object))
236 {
237   return LISTP (object) ? Qt : Qnil;
238 }
239
240 DEFUN ("nlistp", Fnlistp, 1, 1, 0, /*
241 Return t if OBJECT is not a list.  `nil' is a list.
242 */
243        (object))
244 {
245   return LISTP (object) ? Qnil : Qt;
246 }
247
248 DEFUN ("true-list-p", Ftrue_list_p, 1, 1, 0, /*
249 Return t if OBJECT is a non-dotted, i.e. nil-terminated, list.
250 */
251        (object))
252 {
253   return TRUE_LIST_P (object) ? Qt : Qnil;
254 }
255 \f
256 DEFUN ("symbolp", Fsymbolp, 1, 1, 0, /*
257 Return t if OBJECT is a symbol.
258 */
259        (object))
260 {
261   return SYMBOLP (object) ? Qt : Qnil;
262 }
263
264 DEFUN ("keywordp", Fkeywordp, 1, 1, 0, /*
265 Return t if OBJECT is a keyword.
266 */
267        (object))
268 {
269   return KEYWORDP (object) ? Qt : Qnil;
270 }
271
272 DEFUN ("vectorp", Fvectorp, 1, 1, 0, /*
273 Return t if OBJECT is a vector.
274 */
275        (object))
276 {
277   return VECTORP (object) ? Qt : Qnil;
278 }
279
280 DEFUN ("bit-vector-p", Fbit_vector_p, 1, 1, 0, /*
281 Return t if OBJECT is a bit vector.
282 */
283        (object))
284 {
285   return BIT_VECTORP (object) ? Qt : Qnil;
286 }
287
288 DEFUN ("stringp", Fstringp, 1, 1, 0, /*
289 Return t if OBJECT is a string.
290 */
291        (object))
292 {
293   return STRINGP (object) ? Qt : Qnil;
294 }
295
296 DEFUN ("arrayp", Farrayp, 1, 1, 0, /*
297 Return t if OBJECT is an array (string, vector, or bit vector).
298 */
299        (object))
300 {
301   return (VECTORP       (object) ||
302           STRINGP       (object) ||
303           BIT_VECTORP   (object))
304     ? Qt : Qnil;
305 }
306
307 DEFUN ("sequencep", Fsequencep, 1, 1, 0, /*
308 Return t if OBJECT is a sequence (list or array).
309 */
310        (object))
311 {
312   return (LISTP         (object) ||
313           VECTORP       (object) ||
314           STRINGP       (object) ||
315           BIT_VECTORP   (object))
316     ? Qt : Qnil;
317 }
318
319 DEFUN ("markerp", Fmarkerp, 1, 1, 0, /*
320 Return t if OBJECT is a marker (editor pointer).
321 */
322        (object))
323 {
324   return MARKERP (object) ? Qt : Qnil;
325 }
326
327 DEFUN ("subrp", Fsubrp, 1, 1, 0, /*
328 Return t if OBJECT is a built-in function.
329 */
330        (object))
331 {
332   return SUBRP (object) ? Qt : Qnil;
333 }
334
335 DEFUN ("subr-min-args", Fsubr_min_args, 1, 1, 0, /*
336 Return minimum number of args built-in function SUBR may be called with.
337 */
338        (subr))
339 {
340   CHECK_SUBR (subr);
341   return make_int (XSUBR (subr)->min_args);
342 }
343
344 DEFUN ("subr-max-args", Fsubr_max_args, 1, 1, 0, /*
345 Return maximum number of args built-in function SUBR may be called with,
346 or nil if it takes an arbitrary number of arguments or is a special form.
347 */
348        (subr))
349 {
350   int nargs;
351   CHECK_SUBR (subr);
352   nargs = XSUBR (subr)->max_args;
353   if (nargs == MANY || nargs == UNEVALLED)
354     return Qnil;
355   else
356     return make_int (nargs);
357 }
358
359 DEFUN ("subr-interactive", Fsubr_interactive, 1, 1, 0, /*
360 Return the interactive spec of the subr object SUBR, or nil.
361 If non-nil, the return value will be a list whose first element is
362 `interactive' and whose second element is the interactive spec.
363 */
364        (subr))
365 {
366   const char *prompt;
367   CHECK_SUBR (subr);
368   prompt = XSUBR (subr)->prompt;
369   return prompt ? list2 (Qinteractive, build_string (prompt)) : Qnil;
370 }
371
372 \f
373 DEFUN ("characterp", Fcharacterp, 1, 1, 0, /*
374 Return t if OBJECT is a character.
375 Unlike in XEmacs v19 and FSF Emacs, a character is its own primitive type.
376 Any character can be converted into an equivalent integer using
377 `char-int'.  To convert the other way, use `int-char'; however,
378 only some integers can be converted into characters.  Such an integer
379 is called a `char-int'; see `char-int-p'.
380
381 Some functions that work on integers (e.g. the comparison functions
382 <, <=, =, /=, etc. and the arithmetic functions +, -, *, etc.)
383 accept characters and implicitly convert them into integers.  In
384 general, functions that work on characters also accept char-ints and
385 implicitly convert them into characters.  WARNING: Neither of these
386 behaviors is very desirable, and they are maintained for backward
387 compatibility with old E-Lisp programs that confounded characters and
388 integers willy-nilly.  These behaviors may change in the future; therefore,
389 do not rely on them.  Instead, use the character-specific functions such
390 as `char='.
391 */
392        (object))
393 {
394   return CHARP (object) ? Qt : Qnil;
395 }
396
397 DEFUN ("char-to-int", Fchar_to_int, 1, 1, 0, /*
398 Convert CHARACTER into an equivalent integer.
399 The resulting integer will always be non-negative.  The integers in
400 the range 0 - 255 map to characters as follows:
401
402 0 - 31          Control set 0
403 32 - 127        ASCII
404 128 - 159       Control set 1
405 160 - 255       Right half of ISO-8859-1
406
407 If support for Mule does not exist, these are the only valid character
408 values.  When Mule support exists, the values assigned to other characters
409 may vary depending on the particular version of XEmacs, the order in which
410 character sets were loaded, etc., and you should not depend on them.
411 */
412        (character))
413 {
414   CHECK_CHAR (character);
415   return make_int (XCHAR (character));
416 }
417
418 DEFUN ("int-to-char", Fint_to_char, 1, 1, 0, /*
419 Convert integer INTEGER into the equivalent character.
420 Not all integers correspond to valid characters; use `char-int-p' to
421 determine whether this is the case.  If the integer cannot be converted,
422 nil is returned.
423 */
424        (integer))
425 {
426   CHECK_INT (integer);
427   if (CHAR_INTP (integer))
428     return make_char (XINT (integer));
429   else
430     return Qnil;
431 }
432
433 DEFUN ("char-int-p", Fchar_int_p, 1, 1, 0, /*
434 Return t if OBJECT is an integer that can be converted into a character.
435 See `char-int'.
436 */
437        (object))
438 {
439   return CHAR_INTP (object) ? Qt : Qnil;
440 }
441
442 DEFUN ("char-or-char-int-p", Fchar_or_char_int_p, 1, 1, 0, /*
443 Return t if OBJECT is a character or an integer that can be converted into one.
444 */
445        (object))
446 {
447   return CHAR_OR_CHAR_INTP (object) ? Qt : Qnil;
448 }
449
450 DEFUN ("char-or-string-p", Fchar_or_string_p, 1, 1, 0, /*
451 Return t if OBJECT is a character (or a char-int) or a string.
452 It is semi-hateful that we allow a char-int here, as it goes against
453 the name of this function, but it makes the most sense considering the
454 other steps we take to maintain compatibility with the old character/integer
455 confoundedness in older versions of E-Lisp.
456 */
457        (object))
458 {
459   return CHAR_OR_CHAR_INTP (object) || STRINGP (object) ? Qt : Qnil;
460 }
461
462 DEFUN ("char-ref-p", Fchar_ref_p, 1, 1, 0, /*
463 Return t if OBJECT is a character-reference.
464 */
465        (object))
466 {
467   return CONSP (object) && KEYWORDP (XCAR (object)) ? Qt : Qnil;
468 }
469 \f
470 DEFUN ("integerp", Fintegerp, 1, 1, 0, /*
471 Return t if OBJECT is an integer.
472 */
473        (object))
474 {
475   return INTP (object) ? Qt : Qnil;
476 }
477
478 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, 1, 1, 0, /*
479 Return t if OBJECT is an integer or a marker (editor pointer).
480 */
481        (object))
482 {
483   return INTP (object) || MARKERP (object) ? Qt : Qnil;
484 }
485
486 DEFUN ("integer-or-char-p", Finteger_or_char_p, 1, 1, 0, /*
487 Return t if OBJECT is an integer or a character.
488 */
489        (object))
490 {
491   return INTP (object) || CHARP (object) ? Qt : Qnil;
492 }
493
494 DEFUN ("integer-char-or-marker-p", Finteger_char_or_marker_p, 1, 1, 0, /*
495 Return t if OBJECT is an integer, character or a marker (editor pointer).
496 */
497        (object))
498 {
499   return INTP (object) || CHARP (object) || MARKERP (object) ? Qt : Qnil;
500 }
501
502 DEFUN ("natnump", Fnatnump, 1, 1, 0, /*
503 Return t if OBJECT is a nonnegative integer.
504 */
505        (object))
506 {
507   return NATNUMP (object) ? Qt : Qnil;
508 }
509
510 DEFUN ("bitp", Fbitp, 1, 1, 0, /*
511 Return t if OBJECT is a bit (0 or 1).
512 */
513        (object))
514 {
515   return BITP (object) ? Qt : Qnil;
516 }
517
518 DEFUN ("numberp", Fnumberp, 1, 1, 0, /*
519 Return t if OBJECT is a number (floating point or integer).
520 */
521        (object))
522 {
523   return INT_OR_FLOATP (object) ? Qt : Qnil;
524 }
525
526 DEFUN ("number-or-marker-p", Fnumber_or_marker_p, 1, 1, 0, /*
527 Return t if OBJECT is a number or a marker.
528 */
529        (object))
530 {
531   return INT_OR_FLOATP (object) || MARKERP (object) ? Qt : Qnil;
532 }
533
534 DEFUN ("number-char-or-marker-p", Fnumber_char_or_marker_p, 1, 1, 0, /*
535 Return t if OBJECT is a number, character or a marker.
536 */
537        (object))
538 {
539   return (INT_OR_FLOATP (object) ||
540           CHARP         (object) ||
541           MARKERP       (object))
542     ? Qt : Qnil;
543 }
544
545 #ifdef LISP_FLOAT_TYPE
546 DEFUN ("floatp", Ffloatp, 1, 1, 0, /*
547 Return t if OBJECT is a floating point number.
548 */
549        (object))
550 {
551   return FLOATP (object) ? Qt : Qnil;
552 }
553 #endif /* LISP_FLOAT_TYPE */
554
555 DEFUN ("type-of", Ftype_of, 1, 1, 0, /*
556 Return a symbol representing the type of OBJECT.
557 */
558        (object))
559 {
560   switch (XTYPE (object))
561     {
562     case Lisp_Type_Record:
563       return intern (XRECORD_LHEADER_IMPLEMENTATION (object)->name);
564
565     case Lisp_Type_Char: return Qcharacter;
566
567     default: return Qinteger;
568     }
569 }
570
571 \f
572 /* Extract and set components of lists */
573
574 DEFUN ("car", Fcar, 1, 1, 0, /*
575 Return the car of LIST.  If arg is nil, return nil.
576 Error if arg is not nil and not a cons cell.  See also `car-safe'.
577 */
578        (list))
579 {
580   while (1)
581     {
582       if (CONSP (list))
583         return XCAR (list);
584       else if (NILP (list))
585         return Qnil;
586       else
587         list = wrong_type_argument (Qlistp, list);
588     }
589 }
590
591 DEFUN ("car-safe", Fcar_safe, 1, 1, 0, /*
592 Return the car of OBJECT if it is a cons cell, or else nil.
593 */
594        (object))
595 {
596   return CONSP (object) ? XCAR (object) : Qnil;
597 }
598
599 DEFUN ("cdr", Fcdr, 1, 1, 0, /*
600 Return the cdr of LIST.  If arg is nil, return nil.
601 Error if arg is not nil and not a cons cell.  See also `cdr-safe'.
602 */
603        (list))
604 {
605   while (1)
606     {
607       if (CONSP (list))
608         return XCDR (list);
609       else if (NILP (list))
610         return Qnil;
611       else
612         list = wrong_type_argument (Qlistp, list);
613     }
614 }
615
616 DEFUN ("cdr-safe", Fcdr_safe, 1, 1, 0, /*
617 Return the cdr of OBJECT if it is a cons cell, else nil.
618 */
619        (object))
620 {
621   return CONSP (object) ? XCDR (object) : Qnil;
622 }
623
624 DEFUN ("setcar", Fsetcar, 2, 2, 0, /*
625 Set the car of CONS-CELL to be NEWCAR.  Return NEWCAR.
626 */
627        (cons_cell, newcar))
628 {
629   if (!CONSP (cons_cell))
630     cons_cell = wrong_type_argument (Qconsp, cons_cell);
631
632   XCAR (cons_cell) = newcar;
633   return newcar;
634 }
635
636 DEFUN ("setcdr", Fsetcdr, 2, 2, 0, /*
637 Set the cdr of CONS-CELL to be NEWCDR.  Return NEWCDR.
638 */
639        (cons_cell, newcdr))
640 {
641   if (!CONSP (cons_cell))
642     cons_cell = wrong_type_argument (Qconsp, cons_cell);
643
644   XCDR (cons_cell) = newcdr;
645   return newcdr;
646 }
647 \f
648 /* Find the function at the end of a chain of symbol function indirections.
649
650    If OBJECT is a symbol, find the end of its function chain and
651    return the value found there.  If OBJECT is not a symbol, just
652    return it.  If there is a cycle in the function chain, signal a
653    cyclic-function-indirection error.
654
655    This is like Findirect_function when VOID_FUNCTION_ERRORP is true.
656    When VOID_FUNCTION_ERRORP is false, no error is signaled if the end
657    of the chain ends up being Qunbound. */
658 Lisp_Object
659 indirect_function (Lisp_Object object, int void_function_errorp)
660 {
661 #define FUNCTION_INDIRECTION_SUSPICION_LENGTH 16
662   Lisp_Object tortoise, hare;
663   int count;
664
665   for (hare = tortoise = object, count = 0;
666        SYMBOLP (hare);
667        hare = XSYMBOL (hare)->function, count++)
668     {
669       if (count < FUNCTION_INDIRECTION_SUSPICION_LENGTH) continue;
670
671       if (count & 1)
672         tortoise = XSYMBOL (tortoise)->function;
673       if (EQ (hare, tortoise))
674         return Fsignal (Qcyclic_function_indirection, list1 (object));
675     }
676
677   if (void_function_errorp && UNBOUNDP (hare))
678     return signal_void_function_error (object);
679
680   return hare;
681 }
682
683 DEFUN ("indirect-function", Findirect_function, 1, 1, 0, /*
684 Return the function at the end of OBJECT's function chain.
685 If OBJECT is a symbol, follow all function indirections and return
686 the final function binding.
687 If OBJECT is not a symbol, just return it.
688 Signal a void-function error if the final symbol is unbound.
689 Signal a cyclic-function-indirection error if there is a loop in the
690 function chain of symbols.
691 */
692        (object))
693 {
694   return indirect_function (object, 1);
695 }
696 \f
697 /* Extract and set vector and string elements */
698
699 DEFUN ("aref", Faref, 2, 2, 0, /*
700 Return the element of ARRAY at index INDEX.
701 ARRAY may be a vector, bit vector, or string.  INDEX starts at 0.
702 */
703        (array, index_))
704 {
705   EMACS_INT idx;
706
707  retry:
708
709   if      (INTP  (index_)) idx = XINT  (index_);
710   else if (CHARP (index_)) idx = XCHAR (index_); /* yuck! */
711   else
712     {
713       index_ = wrong_type_argument (Qinteger_or_char_p, index_);
714       goto retry;
715     }
716
717   if (idx < 0) goto range_error;
718
719   if (VECTORP (array))
720     {
721       if (idx >= XVECTOR_LENGTH (array)) goto range_error;
722       return XVECTOR_DATA (array)[idx];
723     }
724   else if (BIT_VECTORP (array))
725     {
726       if (idx >= bit_vector_length (XBIT_VECTOR (array))) goto range_error;
727       return make_int (bit_vector_bit (XBIT_VECTOR (array), idx));
728     }
729   else if (STRINGP (array))
730     {
731       if (idx >= XSTRING_CHAR_LENGTH (array)) goto range_error;
732       return make_char (string_char (XSTRING (array), idx));
733     }
734 #ifdef LOSING_BYTECODE
735   else if (COMPILED_FUNCTIONP (array))
736     {
737       /* Weird, gross compatibility kludge */
738       return Felt (array, index_);
739     }
740 #endif
741   else
742     {
743       check_losing_bytecode ("aref", array);
744       array = wrong_type_argument (Qarrayp, array);
745       goto retry;
746     }
747
748  range_error:
749   args_out_of_range (array, index_);
750   return Qnil; /* not reached */
751 }
752
753 DEFUN ("aset", Faset, 3, 3, 0, /*
754 Store into the element of ARRAY at index INDEX the value NEWVAL.
755 ARRAY may be a vector, bit vector, or string.  INDEX starts at 0.
756 */
757        (array, index_, newval))
758 {
759   EMACS_INT idx;
760
761  retry:
762
763   if      (INTP  (index_)) idx = XINT (index_);
764   else if (CHARP (index_)) idx = XCHAR (index_); /* yuck! */
765   else
766     {
767       index_ = wrong_type_argument (Qinteger_or_char_p, index_);
768       goto retry;
769     }
770
771   if (idx < 0) goto range_error;
772
773   if (VECTORP (array))
774     {
775       if (idx >= XVECTOR_LENGTH (array)) goto range_error;
776       XVECTOR_DATA (array)[idx] = newval;
777     }
778   else if (BIT_VECTORP (array))
779     {
780       if (idx >= bit_vector_length (XBIT_VECTOR (array))) goto range_error;
781       CHECK_BIT (newval);
782       set_bit_vector_bit (XBIT_VECTOR (array), idx, !ZEROP (newval));
783     }
784   else if (STRINGP (array))
785     {
786       CHECK_CHAR_COERCE_INT (newval);
787       if (idx >= XSTRING_CHAR_LENGTH (array)) goto range_error;
788       set_string_char (XSTRING (array), idx, XCHAR (newval));
789       bump_string_modiff (array);
790     }
791   else
792     {
793       array = wrong_type_argument (Qarrayp, array);
794       goto retry;
795     }
796
797   return newval;
798
799  range_error:
800   args_out_of_range (array, index_);
801   return Qnil; /* not reached */
802 }
803
804 \f
805 /**********************************************************************/
806 /*                       Arithmetic functions                         */
807 /**********************************************************************/
808 typedef struct
809 {
810   int int_p;
811   union
812   {
813     EMACS_INT ival;
814     double dval;
815   } c;
816 } int_or_double;
817
818 static void
819 number_char_or_marker_to_int_or_double (Lisp_Object obj, int_or_double *p)
820 {
821  retry:
822   p->int_p = 1;
823   if      (INTP    (obj)) p->c.ival = XINT  (obj);
824   else if (CHARP   (obj)) p->c.ival = XCHAR (obj);
825   else if (MARKERP (obj)) p->c.ival = marker_position (obj);
826 #ifdef LISP_FLOAT_TYPE
827   else if (FLOATP  (obj)) p->c.dval = XFLOAT_DATA (obj), p->int_p = 0;
828 #endif
829   else
830     {
831       obj = wrong_type_argument (Qnumber_char_or_marker_p, obj);
832       goto retry;
833     }
834 }
835
836 static double
837 number_char_or_marker_to_double (Lisp_Object obj)
838 {
839  retry:
840   if      (INTP    (obj)) return (double) XINT  (obj);
841   else if (CHARP   (obj)) return (double) XCHAR (obj);
842   else if (MARKERP (obj)) return (double) marker_position (obj);
843 #ifdef LISP_FLOAT_TYPE
844   else if (FLOATP  (obj)) return XFLOAT_DATA (obj);
845 #endif
846   else
847     {
848       obj = wrong_type_argument (Qnumber_char_or_marker_p, obj);
849       goto retry;
850     }
851 }
852
853 static EMACS_INT
854 integer_char_or_marker_to_int (Lisp_Object obj)
855 {
856  retry:
857   if      (INTP    (obj)) return XINT  (obj);
858   else if (CHARP   (obj)) return XCHAR (obj);
859   else if (MARKERP (obj)) return marker_position (obj);
860   else
861     {
862       obj = wrong_type_argument (Qinteger_char_or_marker_p, obj);
863       goto retry;
864     }
865 }
866
867 #define ARITHCOMPARE_MANY(op)                                   \
868 {                                                               \
869   int_or_double iod1, iod2, *p = &iod1, *q = &iod2;             \
870   Lisp_Object *args_end = args + nargs;                         \
871                                                                 \
872   number_char_or_marker_to_int_or_double (*args++, p);          \
873                                                                 \
874   while (args < args_end)                                       \
875     {                                                           \
876       number_char_or_marker_to_int_or_double (*args++, q);      \
877                                                                 \
878       if (!((p->int_p && q->int_p) ?                            \
879             (p->c.ival op q->c.ival) :                          \
880             ((p->int_p ? (double) p->c.ival : p->c.dval) op     \
881              (q->int_p ? (double) q->c.ival : q->c.dval))))     \
882         return Qnil;                                            \
883                                                                 \
884       { /* swap */ int_or_double *r = p; p = q; q = r; }        \
885     }                                                           \
886   return Qt;                                                    \
887 }
888
889 DEFUN ("=", Feqlsign, 1, MANY, 0, /*
890 Return t if all the arguments are numerically equal.
891 The arguments may be numbers, characters or markers.
892 */
893        (int nargs, Lisp_Object *args))
894 {
895   ARITHCOMPARE_MANY (==)
896 }
897
898 DEFUN ("<", Flss, 1, MANY, 0, /*
899 Return t if the sequence of arguments is monotonically increasing.
900 The arguments may be numbers, characters or markers.
901 */
902        (int nargs, Lisp_Object *args))
903 {
904   ARITHCOMPARE_MANY (<)
905 }
906
907 DEFUN (">", Fgtr, 1, MANY, 0, /*
908 Return t if the sequence of arguments is monotonically decreasing.
909 The arguments may be numbers, characters or markers.
910 */
911        (int nargs, Lisp_Object *args))
912 {
913   ARITHCOMPARE_MANY (>)
914 }
915
916 DEFUN ("<=", Fleq, 1, MANY, 0, /*
917 Return t if the sequence of arguments is monotonically nondecreasing.
918 The arguments may be numbers, characters or markers.
919 */
920        (int nargs, Lisp_Object *args))
921 {
922   ARITHCOMPARE_MANY (<=)
923 }
924
925 DEFUN (">=", Fgeq, 1, MANY, 0, /*
926 Return t if the sequence of arguments is monotonically nonincreasing.
927 The arguments may be numbers, characters or markers.
928 */
929        (int nargs, Lisp_Object *args))
930 {
931   ARITHCOMPARE_MANY (>=)
932 }
933
934 DEFUN ("/=", Fneq, 1, MANY, 0, /*
935 Return t if no two arguments are numerically equal.
936 The arguments may be numbers, characters or markers.
937 */
938        (int nargs, Lisp_Object *args))
939 {
940   Lisp_Object *args_end = args + nargs;
941   Lisp_Object *p, *q;
942
943   /* Unlike all the other comparisons, this is an N*N algorithm.
944      We could use a hash table for nargs > 50 to make this linear. */
945   for (p = args; p < args_end; p++)
946     {
947       int_or_double iod1, iod2;
948       number_char_or_marker_to_int_or_double (*p, &iod1);
949
950       for (q = p + 1; q < args_end; q++)
951         {
952           number_char_or_marker_to_int_or_double (*q, &iod2);
953
954           if (!((iod1.int_p && iod2.int_p) ?
955                 (iod1.c.ival != iod2.c.ival) :
956                 ((iod1.int_p ? (double) iod1.c.ival : iod1.c.dval) !=
957                  (iod2.int_p ? (double) iod2.c.ival : iod2.c.dval))))
958             return Qnil;
959         }
960     }
961   return Qt;
962 }
963
964 DEFUN ("zerop", Fzerop, 1, 1, 0, /*
965 Return t if NUMBER is zero.
966 */
967        (number))
968 {
969  retry:
970   if (INTP (number))
971     return EQ (number, Qzero) ? Qt : Qnil;
972 #ifdef LISP_FLOAT_TYPE
973   else if (FLOATP (number))
974     return XFLOAT_DATA (number) == 0.0 ? Qt : Qnil;
975 #endif /* LISP_FLOAT_TYPE */
976   else
977     {
978       number = wrong_type_argument (Qnumberp, number);
979       goto retry;
980     }
981 }
982 \f
983 /* Convert between a 32-bit value and a cons of two 16-bit values.
984    This is used to pass 32-bit integers to and from the user.
985    Use time_to_lisp() and lisp_to_time() for time values.
986
987    If you're thinking of using this to store a pointer into a Lisp Object
988    for internal purposes (such as when calling record_unwind_protect()),
989    try using make_opaque_ptr()/get_opaque_ptr() instead. */
990 Lisp_Object
991 word_to_lisp (unsigned int item)
992 {
993   return Fcons (make_int (item >> 16), make_int (item & 0xffff));
994 }
995
996 unsigned int
997 lisp_to_word (Lisp_Object item)
998 {
999   if (INTP (item))
1000     return XINT (item);
1001   else
1002     {
1003       Lisp_Object top = Fcar (item);
1004       Lisp_Object bot = Fcdr (item);
1005       CHECK_INT (top);
1006       CHECK_INT (bot);
1007       return (XINT (top) << 16) | (XINT (bot) & 0xffff);
1008     }
1009 }
1010
1011 \f
1012 DEFUN ("number-to-string", Fnumber_to_string, 1, 1, 0, /*
1013 Convert NUMBER to a string by printing it in decimal.
1014 Uses a minus sign if negative.
1015 NUMBER may be an integer or a floating point number.
1016 */
1017        (number))
1018 {
1019   char buffer[VALBITS];
1020
1021   CHECK_INT_OR_FLOAT (number);
1022
1023 #ifdef LISP_FLOAT_TYPE
1024   if (FLOATP (number))
1025     {
1026       char pigbuf[350]; /* see comments in float_to_string */
1027
1028       float_to_string (pigbuf, XFLOAT_DATA (number));
1029       return build_string (pigbuf);
1030     }
1031 #endif /* LISP_FLOAT_TYPE */
1032
1033   long_to_string (buffer, XINT (number));
1034   return build_string (buffer);
1035 }
1036
1037 static int
1038 digit_to_number (int character, int base)
1039 {
1040   /* Assumes ASCII */
1041   int digit = ((character >= '0' && character <= '9') ? character - '0'      :
1042                (character >= 'a' && character <= 'z') ? character - 'a' + 10 :
1043                (character >= 'A' && character <= 'Z') ? character - 'A' + 10 :
1044                -1);
1045
1046   return digit >= base ? -1 : digit;
1047 }
1048
1049 DEFUN ("string-to-number", Fstring_to_number, 1, 2, 0, /*
1050 Convert STRING to a number by parsing it as a number in base BASE.
1051 This parses both integers and floating point numbers.
1052 It ignores leading spaces and tabs.
1053
1054 If BASE is nil or omitted, base 10 is used.
1055 BASE must be an integer between 2 and 16 (inclusive).
1056 Floating point numbers always use base 10.
1057 */
1058        (string, base))
1059 {
1060   char *p;
1061   int b;
1062
1063   CHECK_STRING (string);
1064
1065   if (NILP (base))
1066     b = 10;
1067   else
1068     {
1069       CHECK_INT (base);
1070       b = XINT (base);
1071       check_int_range (b, 2, 16);
1072     }
1073
1074   p = (char *) XSTRING_DATA (string);
1075
1076   /* Skip any whitespace at the front of the number.  Some versions of
1077      atoi do this anyway, so we might as well make Emacs lisp consistent.  */
1078   while (*p == ' ' || *p == '\t')
1079     p++;
1080
1081 #ifdef LISP_FLOAT_TYPE
1082   if (isfloat_string (p) && b == 10)
1083     return make_float (atof (p));
1084 #endif /* LISP_FLOAT_TYPE */
1085
1086   if (b == 10)
1087     {
1088       /* Use the system-provided functions for base 10. */
1089 #if   SIZEOF_EMACS_INT == SIZEOF_INT
1090       return make_int (atoi (p));
1091 #elif SIZEOF_EMACS_INT == SIZEOF_LONG
1092       return make_int (atol (p));
1093 #elif SIZEOF_EMACS_INT == SIZEOF_LONG_LONG
1094       return make_int (atoll (p));
1095 #endif
1096     }
1097   else
1098     {
1099       int negative = 1;
1100       EMACS_INT v = 0;
1101
1102       if (*p == '-')
1103         {
1104           negative = -1;
1105           p++;
1106         }
1107       else if (*p == '+')
1108         p++;
1109       while (1)
1110         {
1111           int digit = digit_to_number (*p++, b);
1112           if (digit < 0)
1113             break;
1114           v = v * b + digit;
1115         }
1116       return make_int (negative * v);
1117     }
1118 }
1119 \f
1120
1121 DEFUN ("+", Fplus, 0, MANY, 0, /*
1122 Return sum of any number of arguments.
1123 The arguments should all be numbers, characters or markers.
1124 */
1125        (int nargs, Lisp_Object *args))
1126 {
1127   EMACS_INT iaccum = 0;
1128   Lisp_Object *args_end = args + nargs;
1129
1130   while (args < args_end)
1131     {
1132       int_or_double iod;
1133       number_char_or_marker_to_int_or_double (*args++, &iod);
1134       if (iod.int_p)
1135         iaccum += iod.c.ival;
1136       else
1137         {
1138           double daccum = (double) iaccum + iod.c.dval;
1139           while (args < args_end)
1140             daccum += number_char_or_marker_to_double (*args++);
1141           return make_float (daccum);
1142         }
1143     }
1144
1145   return make_int (iaccum);
1146 }
1147
1148 DEFUN ("-", Fminus, 1, MANY, 0, /*
1149 Negate number or subtract numbers, characters or markers.
1150 With one arg, negates it.  With more than one arg,
1151 subtracts all but the first from the first.
1152 */
1153        (int nargs, Lisp_Object *args))
1154 {
1155   EMACS_INT iaccum;
1156   double daccum;
1157   Lisp_Object *args_end = args + nargs;
1158   int_or_double iod;
1159
1160   number_char_or_marker_to_int_or_double (*args++, &iod);
1161   if (iod.int_p)
1162     iaccum = nargs > 1 ? iod.c.ival : - iod.c.ival;
1163   else
1164     {
1165       daccum = nargs > 1 ? iod.c.dval : - iod.c.dval;
1166       goto do_float;
1167     }
1168
1169   while (args < args_end)
1170     {
1171       number_char_or_marker_to_int_or_double (*args++, &iod);
1172       if (iod.int_p)
1173         iaccum -= iod.c.ival;
1174       else
1175         {
1176           daccum = (double) iaccum - iod.c.dval;
1177           goto do_float;
1178         }
1179     }
1180
1181   return make_int (iaccum);
1182
1183  do_float:
1184   for (; args < args_end; args++)
1185     daccum -= number_char_or_marker_to_double (*args);
1186   return make_float (daccum);
1187 }
1188
1189 DEFUN ("*", Ftimes, 0, MANY, 0, /*
1190 Return product of any number of arguments.
1191 The arguments should all be numbers, characters or markers.
1192 */
1193        (int nargs, Lisp_Object *args))
1194 {
1195   EMACS_INT iaccum = 1;
1196   Lisp_Object *args_end = args + nargs;
1197
1198   while (args < args_end)
1199     {
1200       int_or_double iod;
1201       number_char_or_marker_to_int_or_double (*args++, &iod);
1202       if (iod.int_p)
1203         iaccum *= iod.c.ival;
1204       else
1205         {
1206           double daccum = (double) iaccum * iod.c.dval;
1207           while (args < args_end)
1208             daccum *= number_char_or_marker_to_double (*args++);
1209           return make_float (daccum);
1210         }
1211     }
1212
1213   return make_int (iaccum);
1214 }
1215
1216 DEFUN ("/", Fquo, 1, MANY, 0, /*
1217 Return first argument divided by all the remaining arguments.
1218 The arguments must be numbers, characters or markers.
1219 With one argument, reciprocates the argument.
1220 */
1221        (int nargs, Lisp_Object *args))
1222 {
1223   EMACS_INT iaccum;
1224   double daccum;
1225   Lisp_Object *args_end = args + nargs;
1226   int_or_double iod;
1227
1228   if (nargs == 1)
1229     iaccum = 1;
1230   else
1231     {
1232       number_char_or_marker_to_int_or_double (*args++, &iod);
1233       if (iod.int_p)
1234         iaccum = iod.c.ival;
1235       else
1236         {
1237           daccum = iod.c.dval;
1238           goto divide_floats;
1239         }
1240     }
1241
1242   while (args < args_end)
1243     {
1244       number_char_or_marker_to_int_or_double (*args++, &iod);
1245       if (iod.int_p)
1246         {
1247           if (iod.c.ival == 0) goto divide_by_zero;
1248           iaccum /= iod.c.ival;
1249         }
1250       else
1251         {
1252           if (iod.c.dval == 0) goto divide_by_zero;
1253           daccum = (double) iaccum / iod.c.dval;
1254           goto divide_floats;
1255         }
1256     }
1257
1258   return make_int (iaccum);
1259
1260  divide_floats:
1261   for (; args < args_end; args++)
1262     {
1263       double dval = number_char_or_marker_to_double (*args);
1264       if (dval == 0) goto divide_by_zero;
1265       daccum /= dval;
1266     }
1267   return make_float (daccum);
1268
1269  divide_by_zero:
1270   Fsignal (Qarith_error, Qnil);
1271   return Qnil; /* not reached */
1272 }
1273
1274 DEFUN ("max", Fmax, 1, MANY, 0, /*
1275 Return largest of all the arguments.
1276 All arguments must be numbers, characters or markers.
1277 The value is always a number; markers and characters are converted
1278 to numbers.
1279 */
1280        (int nargs, Lisp_Object *args))
1281 {
1282   EMACS_INT imax;
1283   double dmax;
1284   Lisp_Object *args_end = args + nargs;
1285   int_or_double iod;
1286
1287   number_char_or_marker_to_int_or_double (*args++, &iod);
1288   if (iod.int_p)
1289     imax = iod.c.ival;
1290   else
1291     {
1292       dmax = iod.c.dval;
1293       goto max_floats;
1294     }
1295
1296   while (args < args_end)
1297     {
1298       number_char_or_marker_to_int_or_double (*args++, &iod);
1299       if (iod.int_p)
1300         {
1301           if (imax < iod.c.ival) imax = iod.c.ival;
1302         }
1303       else
1304         {
1305           dmax = (double) imax;
1306           if (dmax < iod.c.dval) dmax = iod.c.dval;
1307           goto max_floats;
1308         }
1309     }
1310
1311   return make_int (imax);
1312
1313  max_floats:
1314   while (args < args_end)
1315     {
1316       double dval = number_char_or_marker_to_double (*args++);
1317       if (dmax < dval) dmax = dval;
1318     }
1319   return make_float (dmax);
1320 }
1321
1322 DEFUN ("min", Fmin, 1, MANY, 0, /*
1323 Return smallest of all the arguments.
1324 All arguments must be numbers, characters or markers.
1325 The value is always a number; markers and characters are converted
1326 to numbers.
1327 */
1328        (int nargs, Lisp_Object *args))
1329 {
1330   EMACS_INT imin;
1331   double dmin;
1332   Lisp_Object *args_end = args + nargs;
1333   int_or_double iod;
1334
1335   number_char_or_marker_to_int_or_double (*args++, &iod);
1336   if (iod.int_p)
1337     imin = iod.c.ival;
1338   else
1339     {
1340       dmin = iod.c.dval;
1341       goto min_floats;
1342     }
1343
1344   while (args < args_end)
1345     {
1346       number_char_or_marker_to_int_or_double (*args++, &iod);
1347       if (iod.int_p)
1348         {
1349           if (imin > iod.c.ival) imin = iod.c.ival;
1350         }
1351       else
1352         {
1353           dmin = (double) imin;
1354           if (dmin > iod.c.dval) dmin = iod.c.dval;
1355           goto min_floats;
1356         }
1357     }
1358
1359   return make_int (imin);
1360
1361  min_floats:
1362   while (args < args_end)
1363     {
1364       double dval = number_char_or_marker_to_double (*args++);
1365       if (dmin > dval) dmin = dval;
1366     }
1367   return make_float (dmin);
1368 }
1369
1370 DEFUN ("logand", Flogand, 0, MANY, 0, /*
1371 Return bitwise-and of all the arguments.
1372 Arguments may be integers, or markers or characters converted to integers.
1373 */
1374        (int nargs, Lisp_Object *args))
1375 {
1376   EMACS_INT bits = ~0;
1377   Lisp_Object *args_end = args + nargs;
1378
1379   while (args < args_end)
1380     bits &= integer_char_or_marker_to_int (*args++);
1381
1382   return make_int (bits);
1383 }
1384
1385 DEFUN ("logior", Flogior, 0, MANY, 0, /*
1386 Return bitwise-or of all the arguments.
1387 Arguments may be integers, or markers or characters converted to integers.
1388 */
1389        (int nargs, Lisp_Object *args))
1390 {
1391   EMACS_INT bits = 0;
1392   Lisp_Object *args_end = args + nargs;
1393
1394   while (args < args_end)
1395     bits |= integer_char_or_marker_to_int (*args++);
1396
1397   return make_int (bits);
1398 }
1399
1400 DEFUN ("logxor", Flogxor, 0, MANY, 0, /*
1401 Return bitwise-exclusive-or of all the arguments.
1402 Arguments may be integers, or markers or characters converted to integers.
1403 */
1404        (int nargs, Lisp_Object *args))
1405 {
1406   EMACS_INT bits = 0;
1407   Lisp_Object *args_end = args + nargs;
1408
1409   while (args < args_end)
1410     bits ^= integer_char_or_marker_to_int (*args++);
1411
1412   return make_int (bits);
1413 }
1414
1415 DEFUN ("lognot", Flognot, 1, 1, 0, /*
1416 Return the bitwise complement of NUMBER.
1417 NUMBER may be an integer, marker or character converted to integer.
1418 */
1419        (number))
1420 {
1421   return make_int (~ integer_char_or_marker_to_int (number));
1422 }
1423
1424 DEFUN ("%", Frem, 2, 2, 0, /*
1425 Return remainder of first arg divided by second.
1426 Both must be integers, characters or markers.
1427 */
1428        (number1, number2))
1429 {
1430   EMACS_INT ival1 = integer_char_or_marker_to_int (number1);
1431   EMACS_INT ival2 = integer_char_or_marker_to_int (number2);
1432
1433   if (ival2 == 0)
1434     Fsignal (Qarith_error, Qnil);
1435
1436   return make_int (ival1 % ival2);
1437 }
1438
1439 /* Note, ANSI *requires* the presence of the fmod() library routine.
1440    If your system doesn't have it, complain to your vendor, because
1441    that is a bug. */
1442
1443 #ifndef HAVE_FMOD
1444 double
1445 fmod (double f1, double f2)
1446 {
1447   if (f2 < 0.0)
1448     f2 = -f2;
1449   return f1 - f2 * floor (f1/f2);
1450 }
1451 #endif /* ! HAVE_FMOD */
1452
1453
1454 DEFUN ("mod", Fmod, 2, 2, 0, /*
1455 Return X modulo Y.
1456 The result falls between zero (inclusive) and Y (exclusive).
1457 Both X and Y must be numbers, characters or markers.
1458 If either argument is a float, a float will be returned.
1459 */
1460        (x, y))
1461 {
1462   int_or_double iod1, iod2;
1463   number_char_or_marker_to_int_or_double (x, &iod1);
1464   number_char_or_marker_to_int_or_double (y, &iod2);
1465
1466 #ifdef LISP_FLOAT_TYPE
1467   if (!iod1.int_p || !iod2.int_p)
1468     {
1469       double dval1 = iod1.int_p ? (double) iod1.c.ival : iod1.c.dval;
1470       double dval2 = iod2.int_p ? (double) iod2.c.ival : iod2.c.dval;
1471       if (dval2 == 0) goto divide_by_zero;
1472       dval1 = fmod (dval1, dval2);
1473
1474       /* If the "remainder" comes out with the wrong sign, fix it.  */
1475       if (dval2 < 0 ? dval1 > 0 : dval1 < 0)
1476         dval1 += dval2;
1477
1478       return make_float (dval1);
1479     }
1480 #endif /* LISP_FLOAT_TYPE */
1481   {
1482     EMACS_INT ival;
1483     if (iod2.c.ival == 0) goto divide_by_zero;
1484
1485     ival = iod1.c.ival % iod2.c.ival;
1486
1487     /* If the "remainder" comes out with the wrong sign, fix it.  */
1488     if (iod2.c.ival < 0 ? ival > 0 : ival < 0)
1489       ival += iod2.c.ival;
1490
1491     return make_int (ival);
1492   }
1493
1494  divide_by_zero:
1495   Fsignal (Qarith_error, Qnil);
1496   return Qnil; /* not reached */
1497 }
1498
1499 DEFUN ("ash", Fash, 2, 2, 0, /*
1500 Return VALUE with its bits shifted left by COUNT.
1501 If COUNT is negative, shifting is actually to the right.
1502 In this case, the sign bit is duplicated.
1503 */
1504        (value, count))
1505 {
1506   CHECK_INT_COERCE_CHAR (value);
1507   CONCHECK_INT (count);
1508
1509   return make_int (XINT (count) > 0 ?
1510                    XINT (value) <<  XINT (count) :
1511                    XINT (value) >> -XINT (count));
1512 }
1513
1514 DEFUN ("lsh", Flsh, 2, 2, 0, /*
1515 Return VALUE with its bits shifted left by COUNT.
1516 If COUNT is negative, shifting is actually to the right.
1517 In this case, zeros are shifted in on the left.
1518 */
1519        (value, count))
1520 {
1521   CHECK_INT_COERCE_CHAR (value);
1522   CONCHECK_INT (count);
1523
1524   return make_int (XINT (count) > 0 ?
1525                    XUINT (value) <<  XINT (count) :
1526                    XUINT (value) >> -XINT (count));
1527 }
1528
1529 DEFUN ("1+", Fadd1, 1, 1, 0, /*
1530 Return NUMBER plus one.  NUMBER may be a number, character or marker.
1531 Markers and characters are converted to integers.
1532 */
1533        (number))
1534 {
1535  retry:
1536
1537   if (INTP    (number)) return make_int (XINT  (number) + 1);
1538   if (CHARP   (number)) return make_int (XCHAR (number) + 1);
1539   if (MARKERP (number)) return make_int (marker_position (number) + 1);
1540 #ifdef LISP_FLOAT_TYPE
1541   if (FLOATP  (number)) return make_float (XFLOAT_DATA (number) + 1.0);
1542 #endif /* LISP_FLOAT_TYPE */
1543
1544   number = wrong_type_argument (Qnumber_char_or_marker_p, number);
1545   goto retry;
1546 }
1547
1548 DEFUN ("1-", Fsub1, 1, 1, 0, /*
1549 Return NUMBER minus one.  NUMBER may be a number, character or marker.
1550 Markers and characters are converted to integers.
1551 */
1552        (number))
1553 {
1554  retry:
1555
1556   if (INTP    (number)) return make_int (XINT  (number) - 1);
1557   if (CHARP   (number)) return make_int (XCHAR (number) - 1);
1558   if (MARKERP (number)) return make_int (marker_position (number) - 1);
1559 #ifdef LISP_FLOAT_TYPE
1560   if (FLOATP  (number)) return make_float (XFLOAT_DATA (number) - 1.0);
1561 #endif /* LISP_FLOAT_TYPE */
1562
1563   number = wrong_type_argument (Qnumber_char_or_marker_p, number);
1564   goto retry;
1565 }
1566
1567 \f
1568 /************************************************************************/
1569 /*                              weak lists                              */
1570 /************************************************************************/
1571
1572 /* A weak list is like a normal list except that elements automatically
1573    disappear when no longer in use, i.e. when no longer GC-protected.
1574    The basic idea is that we don't mark the elements during GC, but
1575    wait for them to be marked elsewhere.  If they're not marked, we
1576    remove them.  This is analogous to weak hash tables; see the explanation
1577    there for more info. */
1578
1579 static Lisp_Object Vall_weak_lists; /* Gemarke es nicht!!! */
1580
1581 static Lisp_Object encode_weak_list_type (enum weak_list_type type);
1582
1583 static Lisp_Object
1584 mark_weak_list (Lisp_Object obj)
1585 {
1586   return Qnil; /* nichts ist gemarkt */
1587 }
1588
1589 static void
1590 print_weak_list (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
1591 {
1592   if (print_readably)
1593     error ("printing unreadable object #<weak-list>");
1594
1595   write_c_string ("#<weak-list ", printcharfun);
1596   print_internal (encode_weak_list_type (XWEAK_LIST (obj)->type),
1597                   printcharfun, 0);
1598   write_c_string (" ", printcharfun);
1599   print_internal (XWEAK_LIST (obj)->list, printcharfun, escapeflag);
1600   write_c_string (">", printcharfun);
1601 }
1602
1603 static int
1604 weak_list_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
1605 {
1606   struct weak_list *w1 = XWEAK_LIST (obj1);
1607   struct weak_list *w2 = XWEAK_LIST (obj2);
1608
1609   return ((w1->type == w2->type) &&
1610           internal_equal (w1->list, w2->list, depth + 1));
1611 }
1612
1613 static unsigned long
1614 weak_list_hash (Lisp_Object obj, int depth)
1615 {
1616   struct weak_list *w = XWEAK_LIST (obj);
1617
1618   return HASH2 ((unsigned long) w->type,
1619                 internal_hash (w->list, depth + 1));
1620 }
1621
1622 Lisp_Object
1623 make_weak_list (enum weak_list_type type)
1624 {
1625   Lisp_Object result;
1626   struct weak_list *wl =
1627     alloc_lcrecord_type (struct weak_list, &lrecord_weak_list);
1628
1629   wl->list = Qnil;
1630   wl->type = type;
1631   XSETWEAK_LIST (result, wl);
1632   wl->next_weak = Vall_weak_lists;
1633   Vall_weak_lists = result;
1634   return result;
1635 }
1636
1637 static const struct lrecord_description weak_list_description[] = {
1638   { XD_LISP_OBJECT, offsetof (struct weak_list, list) },
1639   { XD_LO_LINK,     offsetof (struct weak_list, next_weak) },
1640   { XD_END }
1641 };
1642
1643 DEFINE_LRECORD_IMPLEMENTATION ("weak-list", weak_list,
1644                                mark_weak_list, print_weak_list,
1645                                0, weak_list_equal, weak_list_hash,
1646                                weak_list_description,
1647                                struct weak_list);
1648 /*
1649    -- we do not mark the list elements (either the elements themselves
1650       or the cons cells that hold them) in the normal marking phase.
1651    -- at the end of marking, we go through all weak lists that are
1652       marked, and mark the cons cells that hold all marked
1653       objects, and possibly parts of the objects themselves.
1654       (See alloc.c, "after-mark".)
1655    -- after that, we prune away all the cons cells that are not marked.
1656
1657    WARNING WARNING WARNING WARNING WARNING:
1658
1659    The code in the following two functions is *unbelievably* tricky.
1660    Don't mess with it.  You'll be sorry.
1661
1662    Linked lists just majorly suck, d'ya know?
1663 */
1664
1665 int
1666 finish_marking_weak_lists (void)
1667 {
1668   Lisp_Object rest;
1669   int did_mark = 0;
1670
1671   for (rest = Vall_weak_lists;
1672        !NILP (rest);
1673        rest = XWEAK_LIST (rest)->next_weak)
1674     {
1675       Lisp_Object rest2;
1676       enum weak_list_type type = XWEAK_LIST (rest)->type;
1677
1678       if (! marked_p (rest))
1679         /* The weak list is probably garbage.  Ignore it. */
1680         continue;
1681
1682       for (rest2 = XWEAK_LIST (rest)->list;
1683            /* We need to be trickier since we're inside of GC;
1684               use CONSP instead of !NILP in case of user-visible
1685               imperfect lists */
1686            CONSP (rest2);
1687            rest2 = XCDR (rest2))
1688         {
1689           Lisp_Object elem;
1690           /* If the element is "marked" (meaning depends on the type
1691              of weak list), we need to mark the cons containing the
1692              element, and maybe the element itself (if only some part
1693              was already marked). */
1694           int need_to_mark_cons = 0;
1695           int need_to_mark_elem = 0;
1696
1697           /* If a cons is already marked, then its car is already marked
1698              (either because of an external pointer or because of
1699              a previous call to this function), and likewise for all
1700              the rest of the elements in the list, so we can stop now. */
1701           if (marked_p (rest2))
1702             break;
1703
1704           elem = XCAR (rest2);
1705
1706           switch (type)
1707             {
1708             case WEAK_LIST_SIMPLE:
1709               if (marked_p (elem))
1710                 need_to_mark_cons = 1;
1711               break;
1712
1713             case WEAK_LIST_ASSOC:
1714               if (!CONSP (elem))
1715                 {
1716                   /* just leave bogus elements there */
1717                   need_to_mark_cons = 1;
1718                   need_to_mark_elem = 1;
1719                 }
1720               else if (marked_p (XCAR (elem)) &&
1721                        marked_p (XCDR (elem)))
1722                 {
1723                   need_to_mark_cons = 1;
1724                   /* We still need to mark elem, because it's
1725                      probably not marked. */
1726                   need_to_mark_elem = 1;
1727                 }
1728               break;
1729
1730             case WEAK_LIST_KEY_ASSOC:
1731               if (!CONSP (elem))
1732                 {
1733                   /* just leave bogus elements there */
1734                   need_to_mark_cons = 1;
1735                   need_to_mark_elem = 1;
1736                 }
1737               else if (marked_p (XCAR (elem)))
1738                 {
1739                   need_to_mark_cons = 1;
1740                   /* We still need to mark elem and XCDR (elem);
1741                      marking elem does both */
1742                   need_to_mark_elem = 1;
1743                 }
1744               break;
1745
1746             case WEAK_LIST_VALUE_ASSOC:
1747               if (!CONSP (elem))
1748                 {
1749                   /* just leave bogus elements there */
1750                   need_to_mark_cons = 1;
1751                   need_to_mark_elem = 1;
1752                 }
1753               else if (marked_p (XCDR (elem)))
1754                 {
1755                   need_to_mark_cons = 1;
1756                   /* We still need to mark elem and XCAR (elem);
1757                      marking elem does both */
1758                   need_to_mark_elem = 1;
1759                 }
1760               break;
1761
1762             case WEAK_LIST_FULL_ASSOC:
1763               if (!CONSP (elem))
1764                 {
1765                   /* just leave bogus elements there */
1766                   need_to_mark_cons = 1;
1767                   need_to_mark_elem = 1;
1768                 }
1769               else if (marked_p (XCAR (elem)) ||
1770                        marked_p (XCDR (elem)))
1771                 {
1772                   need_to_mark_cons = 1;
1773                   /* We still need to mark elem and XCAR (elem);
1774                      marking elem does both */
1775                   need_to_mark_elem = 1;
1776                 }
1777               break;
1778
1779             default:
1780               abort ();
1781             }
1782
1783           if (need_to_mark_elem && ! marked_p (elem))
1784             {
1785               mark_object (elem);
1786               did_mark = 1;
1787             }
1788
1789           /* We also need to mark the cons that holds the elem or
1790              assoc-pair.  We do *not* want to call (mark_object) here
1791              because that will mark the entire list; we just want to
1792              mark the cons itself.
1793              */
1794           if (need_to_mark_cons)
1795             {
1796               Lisp_Cons *c = XCONS (rest2);
1797               if (!CONS_MARKED_P (c))
1798                 {
1799                   MARK_CONS (c);
1800                   did_mark = 1;
1801                 }
1802             }
1803         }
1804
1805       /* In case of imperfect list, need to mark the final cons
1806          because we're not removing it */
1807       if (!NILP (rest2) && ! marked_p (rest2))
1808         {
1809           mark_object (rest2);
1810           did_mark = 1;
1811         }
1812     }
1813
1814   return did_mark;
1815 }
1816
1817 void
1818 prune_weak_lists (void)
1819 {
1820   Lisp_Object rest, prev = Qnil;
1821
1822   for (rest = Vall_weak_lists;
1823        !NILP (rest);
1824        rest = XWEAK_LIST (rest)->next_weak)
1825     {
1826       if (! (marked_p (rest)))
1827         {
1828           /* This weak list itself is garbage.  Remove it from the list. */
1829           if (NILP (prev))
1830             Vall_weak_lists = XWEAK_LIST (rest)->next_weak;
1831           else
1832             XWEAK_LIST (prev)->next_weak =
1833               XWEAK_LIST (rest)->next_weak;
1834         }
1835       else
1836         {
1837           Lisp_Object rest2, prev2 = Qnil;
1838           Lisp_Object tortoise;
1839           int go_tortoise = 0;
1840
1841           for (rest2 = XWEAK_LIST (rest)->list, tortoise = rest2;
1842                /* We need to be trickier since we're inside of GC;
1843                   use CONSP instead of !NILP in case of user-visible
1844                   imperfect lists */
1845                CONSP (rest2);)
1846             {
1847               /* It suffices to check the cons for marking,
1848                  regardless of the type of weak list:
1849
1850                  -- if the cons is pointed to somewhere else,
1851                     then it should stay around and will be marked.
1852                  -- otherwise, if it should stay around, it will
1853                     have been marked in finish_marking_weak_lists().
1854                  -- otherwise, it's not marked and should disappear.
1855                  */
1856               if (! marked_p (rest2))
1857                 {
1858                   /* bye bye :-( */
1859                   if (NILP (prev2))
1860                     XWEAK_LIST (rest)->list = XCDR (rest2);
1861                   else
1862                     XCDR (prev2) = XCDR (rest2);
1863                   rest2 = XCDR (rest2);
1864                   /* Ouch.  Circularity checking is even trickier
1865                      than I thought.  When we cut out a link
1866                      like this, we can't advance the turtle or
1867                      it'll catch up to us.  Imagine that we're
1868                      standing on floor tiles and moving forward --
1869                      what we just did here is as if the floor
1870                      tile under us just disappeared and all the
1871                      ones ahead of us slid one tile towards us.
1872                      In other words, we didn't move at all;
1873                      if the tortoise was one step behind us
1874                      previously, it still is, and therefore
1875                      it must not move. */
1876                 }
1877               else
1878                 {
1879                   prev2 = rest2;
1880
1881                   /* Implementing circularity checking is trickier here
1882                      than in other places because we have to guarantee
1883                      that we've processed all elements before exiting
1884                      due to a circularity. (In most places, an error
1885                      is issued upon encountering a circularity, so it
1886                      doesn't really matter if all elements are processed.)
1887                      The idea is that we process along with the hare
1888                      rather than the tortoise.  If at any point in
1889                      our forward process we encounter the tortoise,
1890                      we must have already visited the spot, so we exit.
1891                      (If we process with the tortoise, we can fail to
1892                      process cases where a cons points to itself, or
1893                      where cons A points to cons B, which points to
1894                      cons A.) */
1895
1896                   rest2 = XCDR (rest2);
1897                   if (go_tortoise)
1898                     tortoise = XCDR (tortoise);
1899                   go_tortoise = !go_tortoise;
1900                   if (EQ (rest2, tortoise))
1901                     break;
1902                 }
1903             }
1904
1905           prev = rest;
1906         }
1907     }
1908 }
1909
1910 static enum weak_list_type
1911 decode_weak_list_type (Lisp_Object symbol)
1912 {
1913   CHECK_SYMBOL (symbol);
1914   if (EQ (symbol, Qsimple))      return WEAK_LIST_SIMPLE;
1915   if (EQ (symbol, Qassoc))       return WEAK_LIST_ASSOC;
1916   if (EQ (symbol, Qold_assoc))   return WEAK_LIST_ASSOC;  /* EBOLA ALERT! */
1917   if (EQ (symbol, Qkey_assoc))   return WEAK_LIST_KEY_ASSOC;
1918   if (EQ (symbol, Qvalue_assoc)) return WEAK_LIST_VALUE_ASSOC;
1919   if (EQ (symbol, Qfull_assoc))  return WEAK_LIST_FULL_ASSOC;
1920
1921   signal_simple_error ("Invalid weak list type", symbol);
1922   return WEAK_LIST_SIMPLE; /* not reached */
1923 }
1924
1925 static Lisp_Object
1926 encode_weak_list_type (enum weak_list_type type)
1927 {
1928   switch (type)
1929     {
1930     case WEAK_LIST_SIMPLE:      return Qsimple;
1931     case WEAK_LIST_ASSOC:       return Qassoc;
1932     case WEAK_LIST_KEY_ASSOC:   return Qkey_assoc;
1933     case WEAK_LIST_VALUE_ASSOC: return Qvalue_assoc;
1934     case WEAK_LIST_FULL_ASSOC:  return Qfull_assoc;
1935     default:
1936       abort ();
1937     }
1938
1939   return Qnil; /* not reached */
1940 }
1941
1942 DEFUN ("weak-list-p", Fweak_list_p, 1, 1, 0, /*
1943 Return non-nil if OBJECT is a weak list.
1944 */
1945        (object))
1946 {
1947   return WEAK_LISTP (object) ? Qt : Qnil;
1948 }
1949
1950 DEFUN ("make-weak-list", Fmake_weak_list, 0, 1, 0, /*
1951 Return a new weak list object of type TYPE.
1952 A weak list object is an object that contains a list.  This list behaves
1953 like any other list except that its elements do not count towards
1954 garbage collection -- if the only pointer to an object is inside a weak
1955 list (other than pointers in similar objects such as weak hash tables),
1956 the object is garbage collected and automatically removed from the list.
1957 This is used internally, for example, to manage the list holding the
1958 children of an extent -- an extent that is unused but has a parent will
1959 still be reclaimed, and will automatically be removed from its parent's
1960 list of children.
1961
1962 Optional argument TYPE specifies the type of the weak list, and defaults
1963 to `simple'.  Recognized types are
1964
1965 `simple'        Objects in the list disappear if not pointed to.
1966 `assoc'         Objects in the list disappear if they are conses
1967                 and either the car or the cdr of the cons is not
1968                 pointed to.
1969 `key-assoc'     Objects in the list disappear if they are conses
1970                 and the car is not pointed to.
1971 `value-assoc'   Objects in the list disappear if they are conses
1972                 and the cdr is not pointed to.
1973 `full-assoc'    Objects in the list disappear if they are conses
1974                 and neither the car nor the cdr is pointed to.
1975 */
1976        (type))
1977 {
1978   if (NILP (type))
1979     type = Qsimple;
1980
1981   return make_weak_list (decode_weak_list_type (type));
1982 }
1983
1984 DEFUN ("weak-list-type", Fweak_list_type, 1, 1, 0, /*
1985 Return the type of the given weak-list object.
1986 */
1987        (weak))
1988 {
1989   CHECK_WEAK_LIST (weak);
1990   return encode_weak_list_type (XWEAK_LIST (weak)->type);
1991 }
1992
1993 DEFUN ("weak-list-list", Fweak_list_list, 1, 1, 0, /*
1994 Return the list contained in a weak-list object.
1995 */
1996        (weak))
1997 {
1998   CHECK_WEAK_LIST (weak);
1999   return XWEAK_LIST_LIST (weak);
2000 }
2001
2002 DEFUN ("set-weak-list-list", Fset_weak_list_list, 2, 2, 0, /*
2003 Change the list contained in a weak-list object.
2004 */
2005        (weak, new_list))
2006 {
2007   CHECK_WEAK_LIST (weak);
2008   XWEAK_LIST_LIST (weak) = new_list;
2009   return new_list;
2010 }
2011
2012 \f
2013 /************************************************************************/
2014 /*                            initialization                            */
2015 /************************************************************************/
2016
2017 static SIGTYPE
2018 arith_error (int signo)
2019 {
2020   EMACS_REESTABLISH_SIGNAL (signo, arith_error);
2021   EMACS_UNBLOCK_SIGNAL (signo);
2022   signal_error (Qarith_error, Qnil);
2023 }
2024
2025 void
2026 init_data_very_early (void)
2027 {
2028   /* Don't do this if just dumping out.
2029      We don't want to call `signal' in this case
2030      so that we don't have trouble with dumping
2031      signal-delivering routines in an inconsistent state.  */
2032 #ifndef CANNOT_DUMP
2033   if (!initialized)
2034     return;
2035 #endif /* CANNOT_DUMP */
2036   signal (SIGFPE, arith_error);
2037 #ifdef uts
2038   signal (SIGEMT, arith_error);
2039 #endif /* uts */
2040 }
2041
2042 void
2043 init_errors_once_early (void)
2044 {
2045   DEFSYMBOL (Qerror_conditions);
2046   DEFSYMBOL (Qerror_message);
2047
2048   /* We declare the errors here because some other deferrors depend
2049      on some of the errors below. */
2050
2051   /* ERROR is used as a signaler for random errors for which nothing
2052      else is right */
2053
2054   DEFERROR (Qerror, "error", Qnil);
2055   DEFERROR_STANDARD (Qquit, Qnil);
2056
2057   DEFERROR (Qunimplemented, "Feature not yet implemented", Qerror);
2058   DEFERROR_STANDARD (Qsyntax_error, Qerror);
2059   DEFERROR_STANDARD (Qinvalid_read_syntax, Qsyntax_error);
2060   DEFERROR_STANDARD (Qlist_formation_error, Qsyntax_error);
2061
2062   /* Generated by list traversal macros */
2063   DEFERROR_STANDARD (Qmalformed_list, Qlist_formation_error);
2064   DEFERROR_STANDARD (Qmalformed_property_list, Qmalformed_list);
2065   DEFERROR_STANDARD (Qcircular_list, Qlist_formation_error);
2066   DEFERROR_STANDARD (Qcircular_property_list, Qcircular_list);
2067
2068   DEFERROR_STANDARD (Qinvalid_argument, Qerror);
2069   DEFERROR_STANDARD (Qwrong_type_argument, Qinvalid_argument);
2070   DEFERROR_STANDARD (Qargs_out_of_range, Qinvalid_argument);
2071   DEFERROR_STANDARD (Qwrong_number_of_arguments, Qinvalid_argument);
2072   DEFERROR_STANDARD (Qinvalid_function, Qinvalid_argument);
2073   DEFERROR (Qno_catch, "No catch for tag", Qinvalid_argument);
2074
2075   DEFERROR_STANDARD (Qinternal_error, Qerror);
2076
2077   DEFERROR (Qinvalid_state, "Properties or values have been set incorrectly",
2078             Qerror);
2079   DEFERROR (Qvoid_function, "Symbol's function definition is void",
2080             Qinvalid_state);
2081   DEFERROR (Qcyclic_function_indirection,
2082             "Symbol's chain of function indirections contains a loop",
2083             Qinvalid_state);
2084   DEFERROR (Qvoid_variable, "Symbol's value as variable is void",
2085             Qinvalid_state);
2086   DEFERROR (Qcyclic_variable_indirection,
2087             "Symbol's chain of variable indirections contains a loop",
2088             Qinvalid_state);
2089
2090   DEFERROR (Qinvalid_operation,
2091             "Operation not allowed or error during operation", Qerror);
2092   DEFERROR (Qinvalid_change, "Attempt to set properties or values incorrectly",
2093             Qinvalid_operation);
2094   DEFERROR (Qsetting_constant, "Attempt to set a constant symbol",
2095             Qinvalid_change);
2096
2097   DEFERROR (Qediting_error, "Invalid operation during editing",
2098             Qinvalid_operation);
2099   DEFERROR_STANDARD (Qbeginning_of_buffer, Qediting_error);
2100   DEFERROR_STANDARD (Qend_of_buffer, Qediting_error);
2101   DEFERROR (Qbuffer_read_only, "Buffer is read-only", Qediting_error);
2102
2103   DEFERROR (Qio_error, "IO Error", Qinvalid_operation);
2104   DEFERROR (Qend_of_file, "End of file or stream", Qio_error);
2105
2106   DEFERROR (Qarith_error, "Arithmetic error", Qinvalid_operation);
2107   DEFERROR (Qrange_error, "Arithmetic range error", Qarith_error);
2108   DEFERROR (Qdomain_error, "Arithmetic domain error", Qarith_error);
2109   DEFERROR (Qsingularity_error, "Arithmetic singularity error", Qdomain_error);
2110   DEFERROR (Qoverflow_error, "Arithmetic overflow error", Qdomain_error);
2111   DEFERROR (Qunderflow_error, "Arithmetic underflow error", Qdomain_error);
2112 }
2113
2114 void
2115 syms_of_data (void)
2116 {
2117   INIT_LRECORD_IMPLEMENTATION (weak_list);
2118
2119   DEFSYMBOL (Qquote);
2120   DEFSYMBOL (Qlambda);
2121   DEFSYMBOL (Qlistp);
2122   DEFSYMBOL (Qtrue_list_p);
2123   DEFSYMBOL (Qconsp);
2124   DEFSYMBOL (Qsubrp);
2125   DEFSYMBOL (Qsymbolp);
2126   DEFSYMBOL (Qintegerp);
2127   DEFSYMBOL (Qcharacterp);
2128   DEFSYMBOL (Qnatnump);
2129   DEFSYMBOL (Qstringp);
2130   DEFSYMBOL (Qarrayp);
2131   DEFSYMBOL (Qsequencep);
2132   DEFSYMBOL (Qbufferp);
2133   DEFSYMBOL (Qbitp);
2134   DEFSYMBOL_MULTIWORD_PREDICATE (Qbit_vectorp);
2135   DEFSYMBOL (Qvectorp);
2136   DEFSYMBOL (Qchar_or_string_p);
2137   DEFSYMBOL (Qmarkerp);
2138   DEFSYMBOL (Qinteger_or_marker_p);
2139   DEFSYMBOL (Qinteger_or_char_p);
2140   DEFSYMBOL (Qinteger_char_or_marker_p);
2141   DEFSYMBOL (Qnumberp);
2142   DEFSYMBOL (Qnumber_char_or_marker_p);
2143   DEFSYMBOL (Qcdr);
2144   DEFSYMBOL_MULTIWORD_PREDICATE (Qweak_listp);
2145
2146 #ifdef LISP_FLOAT_TYPE
2147   DEFSYMBOL (Qfloatp);
2148 #endif /* LISP_FLOAT_TYPE */
2149
2150   DEFSUBR (Fwrong_type_argument);
2151
2152   DEFSUBR (Feq);
2153   DEFSUBR (Fold_eq);
2154   DEFSUBR (Fnull);
2155   Ffset (intern ("not"), intern ("null"));
2156   DEFSUBR (Flistp);
2157   DEFSUBR (Fnlistp);
2158   DEFSUBR (Ftrue_list_p);
2159   DEFSUBR (Fconsp);
2160   DEFSUBR (Fatom);
2161   DEFSUBR (Fchar_or_string_p);
2162   DEFSUBR (Fcharacterp);
2163   DEFSUBR (Fchar_int_p);
2164   DEFSUBR (Fchar_to_int);
2165   DEFSUBR (Fint_to_char);
2166   DEFSUBR (Fchar_or_char_int_p);
2167   DEFSUBR (Fchar_ref_p);
2168   DEFSUBR (Fintegerp);
2169   DEFSUBR (Finteger_or_marker_p);
2170   DEFSUBR (Finteger_or_char_p);
2171   DEFSUBR (Finteger_char_or_marker_p);
2172   DEFSUBR (Fnumberp);
2173   DEFSUBR (Fnumber_or_marker_p);
2174   DEFSUBR (Fnumber_char_or_marker_p);
2175 #ifdef LISP_FLOAT_TYPE
2176   DEFSUBR (Ffloatp);
2177 #endif /* LISP_FLOAT_TYPE */
2178   DEFSUBR (Fnatnump);
2179   DEFSUBR (Fsymbolp);
2180   DEFSUBR (Fkeywordp);
2181   DEFSUBR (Fstringp);
2182   DEFSUBR (Fvectorp);
2183   DEFSUBR (Fbitp);
2184   DEFSUBR (Fbit_vector_p);
2185   DEFSUBR (Farrayp);
2186   DEFSUBR (Fsequencep);
2187   DEFSUBR (Fmarkerp);
2188   DEFSUBR (Fsubrp);
2189   DEFSUBR (Fsubr_min_args);
2190   DEFSUBR (Fsubr_max_args);
2191   DEFSUBR (Fsubr_interactive);
2192   DEFSUBR (Ftype_of);
2193   DEFSUBR (Fcar);
2194   DEFSUBR (Fcdr);
2195   DEFSUBR (Fcar_safe);
2196   DEFSUBR (Fcdr_safe);
2197   DEFSUBR (Fsetcar);
2198   DEFSUBR (Fsetcdr);
2199   DEFSUBR (Findirect_function);
2200   DEFSUBR (Faref);
2201   DEFSUBR (Faset);
2202
2203   DEFSUBR (Fnumber_to_string);
2204   DEFSUBR (Fstring_to_number);
2205   DEFSUBR (Feqlsign);
2206   DEFSUBR (Flss);
2207   DEFSUBR (Fgtr);
2208   DEFSUBR (Fleq);
2209   DEFSUBR (Fgeq);
2210   DEFSUBR (Fneq);
2211   DEFSUBR (Fzerop);
2212   DEFSUBR (Fplus);
2213   DEFSUBR (Fminus);
2214   DEFSUBR (Ftimes);
2215   DEFSUBR (Fquo);
2216   DEFSUBR (Frem);
2217   DEFSUBR (Fmod);
2218   DEFSUBR (Fmax);
2219   DEFSUBR (Fmin);
2220   DEFSUBR (Flogand);
2221   DEFSUBR (Flogior);
2222   DEFSUBR (Flogxor);
2223   DEFSUBR (Flsh);
2224   DEFSUBR (Fash);
2225   DEFSUBR (Fadd1);
2226   DEFSUBR (Fsub1);
2227   DEFSUBR (Flognot);
2228
2229   DEFSUBR (Fweak_list_p);
2230   DEFSUBR (Fmake_weak_list);
2231   DEFSUBR (Fweak_list_type);
2232   DEFSUBR (Fweak_list_list);
2233   DEFSUBR (Fset_weak_list_list);
2234 }
2235
2236 void
2237 vars_of_data (void)
2238 {
2239   /* This must not be staticpro'd */
2240   Vall_weak_lists = Qnil;
2241   dump_add_weak_object_chain (&Vall_weak_lists);
2242
2243 #ifdef DEBUG_XEMACS
2244   DEFVAR_BOOL ("debug-issue-ebola-notices", &debug_issue_ebola_notices /*
2245 If non-zero, note when your code may be suffering from char-int confoundance.
2246 That is to say, if XEmacs encounters a usage of `eq', `memq', `equal',
2247 etc. where an int and a char with the same value are being compared,
2248 it will issue a notice on stderr to this effect, along with a backtrace.
2249 In such situations, the result would be different in XEmacs 19 versus
2250 XEmacs 20, and you probably don't want this.
2251
2252 Note that in order to see these notices, you have to byte compile your
2253 code under XEmacs 20 -- any code byte-compiled under XEmacs 19 will
2254 have its chars and ints all confounded in the byte code, making it
2255 impossible to accurately determine Ebola infection.
2256 */ );
2257
2258   debug_issue_ebola_notices = 0;
2259
2260   DEFVAR_INT ("debug-ebola-backtrace-length",
2261               &debug_ebola_backtrace_length /*
2262 Length (in stack frames) of short backtrace printed out in Ebola notices.
2263 See `debug-issue-ebola-notices'.
2264 */ );
2265   debug_ebola_backtrace_length = 32;
2266
2267 #endif /* DEBUG_XEMACS */
2268 }