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