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