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