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