(doprnt): Handle long EMACS_INT in sprintf.
[bpt/emacs.git] / src / data.c
CommitLineData
7921925c 1/* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
0220c518 2 Copyright (C) 1985, 86, 88, 93, 94, 95 Free Software Foundation, Inc.
7921925c
JB
3
4This file is part of GNU Emacs.
5
6GNU Emacs is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 1, or (at your option)
9any later version.
10
11GNU Emacs is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Emacs; see the file COPYING. If not, write to
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20
21#include <signal.h>
22
18160b98 23#include <config.h>
7921925c 24#include "lisp.h"
29eab336 25#include "puresize.h"
7921925c
JB
26
27#ifndef standalone
28#include "buffer.h"
077d751f 29#include "keyboard.h"
7921925c
JB
30#endif
31
a44804c2 32#include "syssignal.h"
fb8e9847 33
aaf45c7b 34#ifdef MSDOS
6ba93f9d 35/* These are redefined (correctly, but differently) in values.h. */
aaf45c7b
RS
36#undef INTBITS
37#undef LONGBITS
38#undef SHORTBITS
39#endif
aaf45c7b 40
7921925c 41#ifdef LISP_FLOAT_TYPE
defa77b5 42
93b91208
JB
43#ifdef STDC_HEADERS
44#include <stdlib.h>
45#endif
defa77b5
RS
46
47/* Work around a problem that happens because math.h on hpux 7
48 defines two static variables--which, in Emacs, are not really static,
49 because `static' is defined as nothing. The problem is that they are
50 here, in floatfns.c, and in lread.c.
51 These macros prevent the name conflict. */
52#if defined (HPUX) && !defined (HPUX8)
53#define _MAXLDBL data_c_maxldbl
54#define _NMAXLDBL data_c_nmaxldbl
55#endif
56
7921925c
JB
57#include <math.h>
58#endif /* LISP_FLOAT_TYPE */
59
024ec58f
BF
60#if !defined (atof)
61extern double atof ();
62#endif /* !atof */
63
7921925c
JB
64Lisp_Object Qnil, Qt, Qquote, Qlambda, Qsubr, Qunbound;
65Lisp_Object Qerror_conditions, Qerror_message, Qtop_level;
66Lisp_Object Qerror, Qquit, Qwrong_type_argument, Qargs_out_of_range;
ffd56f97 67Lisp_Object Qvoid_variable, Qvoid_function, Qcyclic_function_indirection;
7921925c
JB
68Lisp_Object Qsetting_constant, Qinvalid_read_syntax;
69Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch;
3b8819d6 70Lisp_Object Qend_of_file, Qarith_error, Qmark_inactive;
7921925c 71Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
8e86942b 72Lisp_Object Qintegerp, Qnatnump, Qwholenump, Qsymbolp, Qlistp, Qconsp;
7921925c
JB
73Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp;
74Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp;
07bd8472 75Lisp_Object Qbuffer_or_string_p;
7921925c 76Lisp_Object Qboundp, Qfboundp;
39bcc759 77
7921925c 78Lisp_Object Qcdr;
ab297811 79Lisp_Object Qad_advice_info, Qad_activate;
7921925c 80
6315e761
RS
81Lisp_Object Qrange_error, Qdomain_error, Qsingularity_error;
82Lisp_Object Qoverflow_error, Qunderflow_error;
83
7921925c 84#ifdef LISP_FLOAT_TYPE
464f8898 85Lisp_Object Qfloatp;
7921925c
JB
86Lisp_Object Qnumberp, Qnumber_or_marker_p;
87#endif
88
39bcc759
RS
89static Lisp_Object Qinteger, Qsymbol, Qstring, Qcons, Qmarker, Qoverlay;
90static Lisp_Object Qfloat, Qwindow_configuration, Qprocess, Qwindow;
91static Lisp_Object Qcompiled_function, Qbuffer, Qframe, Qvector;
92
7921925c
JB
93static Lisp_Object swap_in_symval_forwarding ();
94
95Lisp_Object
96wrong_type_argument (predicate, value)
97 register Lisp_Object predicate, value;
98{
99 register Lisp_Object tem;
100 do
101 {
102 if (!EQ (Vmocklisp_arguments, Qt))
103 {
e9ebc175 104 if (STRINGP (value) &&
7921925c 105 (EQ (predicate, Qintegerp) || EQ (predicate, Qinteger_or_marker_p)))
25e40a4b 106 return Fstring_to_number (value);
e9ebc175 107 if (INTEGERP (value) && EQ (predicate, Qstringp))
f2980264 108 return Fnumber_to_string (value);
7921925c 109 }
e1351ff7
RS
110
111 /* If VALUE is not even a valid Lisp object, abort here
112 where we can get a backtrace showing where it came from. */
04be3993 113 if ((unsigned int) XGCTYPE (value) >= Lisp_Type_Limit)
e1351ff7
RS
114 abort ();
115
7921925c
JB
116 value = Fsignal (Qwrong_type_argument, Fcons (predicate, Fcons (value, Qnil)));
117 tem = call1 (predicate, value);
118 }
a33ef3ab 119 while (NILP (tem));
7921925c
JB
120 return value;
121}
122
123pure_write_error ()
124{
125 error ("Attempt to modify read-only object");
126}
127
128void
129args_out_of_range (a1, a2)
130 Lisp_Object a1, a2;
131{
132 while (1)
133 Fsignal (Qargs_out_of_range, Fcons (a1, Fcons (a2, Qnil)));
134}
135
136void
137args_out_of_range_3 (a1, a2, a3)
138 Lisp_Object a1, a2, a3;
139{
140 while (1)
141 Fsignal (Qargs_out_of_range, Fcons (a1, Fcons (a2, Fcons (a3, Qnil))));
142}
143
144Lisp_Object
145make_number (num)
146 int num;
147{
148 register Lisp_Object val;
f187f1f7 149 XSETINT (val, num);
7921925c
JB
150 return val;
151}
152
153/* On some machines, XINT needs a temporary location.
154 Here it is, in case it is needed. */
155
156int sign_extend_temp;
157
158/* On a few machines, XINT can only be done by calling this. */
159
160int
161sign_extend_lisp_int (num)
a0ed95ea 162 EMACS_INT num;
7921925c 163{
a0ed95ea
RS
164 if (num & (((EMACS_INT) 1) << (VALBITS - 1)))
165 return num | (((EMACS_INT) (-1)) << VALBITS);
7921925c 166 else
a0ed95ea 167 return num & ((((EMACS_INT) 1) << VALBITS) - 1);
7921925c
JB
168}
169\f
170/* Data type predicates */
171
172DEFUN ("eq", Feq, Seq, 2, 2, 0,
173 "T if the two args are the same Lisp object.")
174 (obj1, obj2)
175 Lisp_Object obj1, obj2;
176{
177 if (EQ (obj1, obj2))
178 return Qt;
179 return Qnil;
180}
181
182DEFUN ("null", Fnull, Snull, 1, 1, 0, "T if OBJECT is nil.")
39bcc759
RS
183 (object)
184 Lisp_Object object;
7921925c 185{
39bcc759 186 if (NILP (object))
7921925c
JB
187 return Qt;
188 return Qnil;
189}
190
39bcc759
RS
191DEFUN ("type-of", Ftype_of, Stype_of, 1, 1, 0,
192 "Return a symbol representing the type of OBJECT.\n\
193The symbol returned names the object's basic type;\n\
194for example, (type-of 1) returns `integer'.")
195 (object)
196 Lisp_Object object;
197{
198 switch (XGCTYPE (object))
199 {
200 case Lisp_Int:
201 return Qinteger;
202
203 case Lisp_Symbol:
204 return Qsymbol;
205
206 case Lisp_String:
207 return Qstring;
208
209 case Lisp_Cons:
210 return Qcons;
211
212 case Lisp_Misc:
324a6eef 213 switch (XMISCTYPE (object))
39bcc759
RS
214 {
215 case Lisp_Misc_Marker:
216 return Qmarker;
217 case Lisp_Misc_Overlay:
218 return Qoverlay;
219 case Lisp_Misc_Float:
220 return Qfloat;
221 }
222 abort ();
223
224 case Lisp_Vectorlike:
225 if (GC_WINDOW_CONFIGURATIONP (object))
226 return Qwindow_configuration;
227 if (GC_PROCESSP (object))
228 return Qprocess;
229 if (GC_WINDOWP (object))
230 return Qwindow;
231 if (GC_SUBRP (object))
232 return Qsubr;
233 if (GC_COMPILEDP (object))
234 return Qcompiled_function;
235 if (GC_BUFFERP (object))
236 return Qbuffer;
237
238#ifdef MULTI_FRAME
239 if (GC_FRAMEP (object))
240 return Qframe;
241#endif
242 return Qvector;
243
244#ifdef LISP_FLOAT_TYPE
245 case Lisp_Float:
246 return Qfloat;
247#endif
248
249 default:
250 abort ();
251 }
252}
253
7921925c 254DEFUN ("consp", Fconsp, Sconsp, 1, 1, 0, "T if OBJECT is a cons cell.")
39bcc759
RS
255 (object)
256 Lisp_Object object;
7921925c 257{
39bcc759 258 if (CONSP (object))
7921925c
JB
259 return Qt;
260 return Qnil;
261}
262
263DEFUN ("atom", Fatom, Satom, 1, 1, 0, "T if OBJECT is not a cons cell. This includes nil.")
39bcc759
RS
264 (object)
265 Lisp_Object object;
7921925c 266{
39bcc759 267 if (CONSP (object))
7921925c
JB
268 return Qnil;
269 return Qt;
270}
271
272DEFUN ("listp", Flistp, Slistp, 1, 1, 0, "T if OBJECT is a list. This includes nil.")
39bcc759
RS
273 (object)
274 Lisp_Object object;
7921925c 275{
39bcc759 276 if (CONSP (object) || NILP (object))
7921925c
JB
277 return Qt;
278 return Qnil;
279}
280
281DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0, "T if OBJECT is not a list. Lists include nil.")
39bcc759
RS
282 (object)
283 Lisp_Object object;
7921925c 284{
39bcc759 285 if (CONSP (object) || NILP (object))
7921925c
JB
286 return Qnil;
287 return Qt;
288}
289\f
290DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0, "T if OBJECT is a symbol.")
39bcc759
RS
291 (object)
292 Lisp_Object object;
7921925c 293{
39bcc759 294 if (SYMBOLP (object))
7921925c
JB
295 return Qt;
296 return Qnil;
297}
298
299DEFUN ("vectorp", Fvectorp, Svectorp, 1, 1, 0, "T if OBJECT is a vector.")
39bcc759
RS
300 (object)
301 Lisp_Object object;
7921925c 302{
39bcc759 303 if (VECTORP (object))
7921925c
JB
304 return Qt;
305 return Qnil;
306}
307
308DEFUN ("stringp", Fstringp, Sstringp, 1, 1, 0, "T if OBJECT is a string.")
39bcc759
RS
309 (object)
310 Lisp_Object object;
7921925c 311{
39bcc759 312 if (STRINGP (object))
7921925c
JB
313 return Qt;
314 return Qnil;
315}
316
317DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0, "T if OBJECT is an array (string or vector).")
39bcc759
RS
318 (object)
319 Lisp_Object object;
7921925c 320{
39bcc759 321 if (VECTORP (object) || STRINGP (object))
7921925c
JB
322 return Qt;
323 return Qnil;
324}
325
326DEFUN ("sequencep", Fsequencep, Ssequencep, 1, 1, 0,
327 "T if OBJECT is a sequence (list or array).")
39bcc759
RS
328 (object)
329 register Lisp_Object object;
7921925c 330{
39bcc759 331 if (CONSP (object) || NILP (object) || VECTORP (object) || STRINGP (object))
7921925c
JB
332 return Qt;
333 return Qnil;
334}
335
336DEFUN ("bufferp", Fbufferp, Sbufferp, 1, 1, 0, "T if OBJECT is an editor buffer.")
39bcc759
RS
337 (object)
338 Lisp_Object object;
7921925c 339{
39bcc759 340 if (BUFFERP (object))
7921925c
JB
341 return Qt;
342 return Qnil;
343}
344
345DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0, "T if OBJECT is a marker (editor pointer).")
39bcc759
RS
346 (object)
347 Lisp_Object object;
7921925c 348{
39bcc759 349 if (MARKERP (object))
7921925c
JB
350 return Qt;
351 return Qnil;
352}
353
7921925c 354DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0, "T if OBJECT is a built-in function.")
39bcc759
RS
355 (object)
356 Lisp_Object object;
7921925c 357{
39bcc759 358 if (SUBRP (object))
7921925c
JB
359 return Qt;
360 return Qnil;
361}
362
dbc4e1c1
JB
363DEFUN ("byte-code-function-p", Fbyte_code_function_p, Sbyte_code_function_p,
364 1, 1, 0, "T if OBJECT is a byte-compiled function object.")
39bcc759
RS
365 (object)
366 Lisp_Object object;
7921925c 367{
39bcc759 368 if (COMPILEDP (object))
7921925c
JB
369 return Qt;
370 return Qnil;
371}
372
0321d75c
KH
373DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0,
374 "T if OBJECT is a character (an integer) or a string.")
39bcc759
RS
375 (object)
376 register Lisp_Object object;
7921925c 377{
39bcc759 378 if (INTEGERP (object) || STRINGP (object))
7921925c
JB
379 return Qt;
380 return Qnil;
381}
382\f
0321d75c 383DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0, "T if OBJECT is an integer.")
39bcc759
RS
384 (object)
385 Lisp_Object object;
7921925c 386{
39bcc759 387 if (INTEGERP (object))
7921925c
JB
388 return Qt;
389 return Qnil;
390}
391
464f8898
RS
392DEFUN ("integer-or-marker-p", Finteger_or_marker_p, Sinteger_or_marker_p, 1, 1, 0,
393 "T if OBJECT is an integer or a marker (editor pointer).")
39bcc759
RS
394 (object)
395 register Lisp_Object object;
7921925c 396{
39bcc759 397 if (MARKERP (object) || INTEGERP (object))
7921925c
JB
398 return Qt;
399 return Qnil;
400}
401
0321d75c
KH
402DEFUN ("natnump", Fnatnump, Snatnump, 1, 1, 0,
403 "T if OBJECT is a nonnegative integer.")
39bcc759
RS
404 (object)
405 Lisp_Object object;
7921925c 406{
39bcc759 407 if (NATNUMP (object))
7921925c
JB
408 return Qt;
409 return Qnil;
410}
411
412DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0,
413 "T if OBJECT is a number (floating point or integer).")
39bcc759
RS
414 (object)
415 Lisp_Object object;
7921925c 416{
39bcc759 417 if (NUMBERP (object))
7921925c 418 return Qt;
dbc4e1c1
JB
419 else
420 return Qnil;
7921925c
JB
421}
422
423DEFUN ("number-or-marker-p", Fnumber_or_marker_p,
424 Snumber_or_marker_p, 1, 1, 0,
425 "T if OBJECT is a number or a marker.")
39bcc759
RS
426 (object)
427 Lisp_Object object;
7921925c 428{
39bcc759 429 if (NUMBERP (object) || MARKERP (object))
7921925c
JB
430 return Qt;
431 return Qnil;
432}
464f8898
RS
433
434#ifdef LISP_FLOAT_TYPE
435DEFUN ("floatp", Ffloatp, Sfloatp, 1, 1, 0,
436 "T if OBJECT is a floating point number.")
39bcc759
RS
437 (object)
438 Lisp_Object object;
464f8898 439{
39bcc759 440 if (FLOATP (object))
464f8898
RS
441 return Qt;
442 return Qnil;
443}
7921925c
JB
444#endif /* LISP_FLOAT_TYPE */
445\f
446/* Extract and set components of lists */
447
448DEFUN ("car", Fcar, Scar, 1, 1, 0,
e1960a18 449 "Return the car of LIST. If arg is nil, return nil.\n\
7921925c
JB
450Error if arg is not nil and not a cons cell. See also `car-safe'.")
451 (list)
452 register Lisp_Object list;
453{
454 while (1)
455 {
e9ebc175 456 if (CONSP (list))
7921925c
JB
457 return XCONS (list)->car;
458 else if (EQ (list, Qnil))
459 return Qnil;
460 else
461 list = wrong_type_argument (Qlistp, list);
462 }
463}
464
465DEFUN ("car-safe", Fcar_safe, Scar_safe, 1, 1, 0,
466 "Return the car of OBJECT if it is a cons cell, or else nil.")
467 (object)
468 Lisp_Object object;
469{
e9ebc175 470 if (CONSP (object))
7921925c
JB
471 return XCONS (object)->car;
472 else
473 return Qnil;
474}
475
476DEFUN ("cdr", Fcdr, Scdr, 1, 1, 0,
e1960a18 477 "Return the cdr of LIST. If arg is nil, return nil.\n\
7921925c
JB
478Error if arg is not nil and not a cons cell. See also `cdr-safe'.")
479
480 (list)
481 register Lisp_Object list;
482{
483 while (1)
484 {
e9ebc175 485 if (CONSP (list))
7921925c
JB
486 return XCONS (list)->cdr;
487 else if (EQ (list, Qnil))
488 return Qnil;
489 else
490 list = wrong_type_argument (Qlistp, list);
491 }
492}
493
494DEFUN ("cdr-safe", Fcdr_safe, Scdr_safe, 1, 1, 0,
b7abc8fa 495 "Return the cdr of OBJECT if it is a cons cell, or else nil.")
7921925c
JB
496 (object)
497 Lisp_Object object;
498{
e9ebc175 499 if (CONSP (object))
7921925c
JB
500 return XCONS (object)->cdr;
501 else
502 return Qnil;
503}
504
505DEFUN ("setcar", Fsetcar, Ssetcar, 2, 2, 0,
e1960a18 506 "Set the car of CELL to be NEWCAR. Returns NEWCAR.")
7921925c
JB
507 (cell, newcar)
508 register Lisp_Object cell, newcar;
509{
e9ebc175 510 if (!CONSP (cell))
7921925c
JB
511 cell = wrong_type_argument (Qconsp, cell);
512
513 CHECK_IMPURE (cell);
514 XCONS (cell)->car = newcar;
515 return newcar;
516}
517
518DEFUN ("setcdr", Fsetcdr, Ssetcdr, 2, 2, 0,
e1960a18 519 "Set the cdr of CELL to be NEWCDR. Returns NEWCDR.")
7921925c
JB
520 (cell, newcdr)
521 register Lisp_Object cell, newcdr;
522{
e9ebc175 523 if (!CONSP (cell))
7921925c
JB
524 cell = wrong_type_argument (Qconsp, cell);
525
526 CHECK_IMPURE (cell);
527 XCONS (cell)->cdr = newcdr;
528 return newcdr;
529}
530\f
531/* Extract and set components of symbols */
532
533DEFUN ("boundp", Fboundp, Sboundp, 1, 1, 0, "T if SYMBOL's value is not void.")
534 (sym)
535 register Lisp_Object sym;
536{
537 Lisp_Object valcontents;
538 CHECK_SYMBOL (sym, 0);
539
540 valcontents = XSYMBOL (sym)->value;
541
aabf6bec
KH
542 if (BUFFER_LOCAL_VALUEP (valcontents)
543 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
536b772a 544 valcontents = swap_in_symval_forwarding (sym, valcontents);
7921925c 545
1bfcade3 546 return (EQ (valcontents, Qunbound) ? Qnil : Qt);
7921925c
JB
547}
548
549DEFUN ("fboundp", Ffboundp, Sfboundp, 1, 1, 0, "T if SYMBOL's function definition is not void.")
550 (sym)
551 register Lisp_Object sym;
552{
553 CHECK_SYMBOL (sym, 0);
1bfcade3 554 return (EQ (XSYMBOL (sym)->function, Qunbound) ? Qnil : Qt);
7921925c
JB
555}
556
557DEFUN ("makunbound", Fmakunbound, Smakunbound, 1, 1, 0, "Make SYMBOL's value be void.")
558 (sym)
559 register Lisp_Object sym;
560{
561 CHECK_SYMBOL (sym, 0);
a33ef3ab 562 if (NILP (sym) || EQ (sym, Qt))
7921925c
JB
563 return Fsignal (Qsetting_constant, Fcons (sym, Qnil));
564 Fset (sym, Qunbound);
565 return sym;
566}
567
568DEFUN ("fmakunbound", Ffmakunbound, Sfmakunbound, 1, 1, 0, "Make SYMBOL's function definition be void.")
569 (sym)
570 register Lisp_Object sym;
571{
572 CHECK_SYMBOL (sym, 0);
c15c5d40
KH
573 if (NILP (sym) || EQ (sym, Qt))
574 return Fsignal (Qsetting_constant, Fcons (sym, Qnil));
7921925c
JB
575 XSYMBOL (sym)->function = Qunbound;
576 return sym;
577}
578
579DEFUN ("symbol-function", Fsymbol_function, Ssymbol_function, 1, 1, 0,
580 "Return SYMBOL's function definition. Error if that is void.")
ffd56f97
JB
581 (symbol)
582 register Lisp_Object symbol;
7921925c 583{
ffd56f97
JB
584 CHECK_SYMBOL (symbol, 0);
585 if (EQ (XSYMBOL (symbol)->function, Qunbound))
586 return Fsignal (Qvoid_function, Fcons (symbol, Qnil));
587 return XSYMBOL (symbol)->function;
7921925c
JB
588}
589
590DEFUN ("symbol-plist", Fsymbol_plist, Ssymbol_plist, 1, 1, 0, "Return SYMBOL's property list.")
591 (sym)
592 register Lisp_Object sym;
593{
594 CHECK_SYMBOL (sym, 0);
595 return XSYMBOL (sym)->plist;
596}
597
598DEFUN ("symbol-name", Fsymbol_name, Ssymbol_name, 1, 1, 0, "Return SYMBOL's name, a string.")
599 (sym)
600 register Lisp_Object sym;
601{
602 register Lisp_Object name;
603
604 CHECK_SYMBOL (sym, 0);
f187f1f7 605 XSETSTRING (name, XSYMBOL (sym)->name);
7921925c
JB
606 return name;
607}
608
609DEFUN ("fset", Ffset, Sfset, 2, 2, 0,
610 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.")
611 (sym, newdef)
612 register Lisp_Object sym, newdef;
613{
614 CHECK_SYMBOL (sym, 0);
c15c5d40
KH
615 if (NILP (sym) || EQ (sym, Qt))
616 return Fsignal (Qsetting_constant, Fcons (sym, Qnil));
a33ef3ab 617 if (!NILP (Vautoload_queue) && !EQ (XSYMBOL (sym)->function, Qunbound))
7921925c
JB
618 Vautoload_queue = Fcons (Fcons (sym, XSYMBOL (sym)->function),
619 Vautoload_queue);
620 XSYMBOL (sym)->function = newdef;
f845f2c9 621 /* Handle automatic advice activation */
ab297811 622 if (CONSP (XSYMBOL (sym)->plist) && !NILP (Fget (sym, Qad_advice_info)))
f845f2c9 623 {
ab297811 624 call2 (Qad_activate, sym, Qnil);
f845f2c9
RS
625 newdef = XSYMBOL (sym)->function;
626 }
7921925c
JB
627 return newdef;
628}
629
d9bcdb34
RS
630/* This name should be removed once it is eliminated from elsewhere. */
631
80df38a2 632DEFUN ("defalias", Fdefalias, Sdefalias, 2, 2, 0,
fc08c367
RS
633 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.\n\
634Associates the function with the current load file, if any.")
635 (sym, newdef)
636 register Lisp_Object sym, newdef;
637{
638 CHECK_SYMBOL (sym, 0);
639 if (!NILP (Vautoload_queue) && !EQ (XSYMBOL (sym)->function, Qunbound))
640 Vautoload_queue = Fcons (Fcons (sym, XSYMBOL (sym)->function),
641 Vautoload_queue);
642 XSYMBOL (sym)->function = newdef;
ab297811
RS
643 /* Handle automatic advice activation */
644 if (CONSP (XSYMBOL (sym)->plist) && !NILP (Fget (sym, Qad_advice_info)))
645 {
646 call2 (Qad_activate, sym, Qnil);
647 newdef = XSYMBOL (sym)->function;
648 }
fc08c367
RS
649 LOADHIST_ATTACH (sym);
650 return newdef;
651}
652
d9bcdb34
RS
653DEFUN ("define-function", Fdefine_function, Sdefine_function, 2, 2, 0,
654 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.\n\
655Associates the function with the current load file, if any.")
656 (sym, newdef)
657 register Lisp_Object sym, newdef;
658{
659 CHECK_SYMBOL (sym, 0);
660 if (!NILP (Vautoload_queue) && !EQ (XSYMBOL (sym)->function, Qunbound))
661 Vautoload_queue = Fcons (Fcons (sym, XSYMBOL (sym)->function),
662 Vautoload_queue);
663 XSYMBOL (sym)->function = newdef;
ab297811
RS
664 /* Handle automatic advice activation */
665 if (CONSP (XSYMBOL (sym)->plist) && !NILP (Fget (sym, Qad_advice_info)))
666 {
667 call2 (Qad_activate, sym, Qnil);
668 newdef = XSYMBOL (sym)->function;
669 }
d9bcdb34
RS
670 LOADHIST_ATTACH (sym);
671 return newdef;
672}
673
7921925c
JB
674DEFUN ("setplist", Fsetplist, Ssetplist, 2, 2, 0,
675 "Set SYMBOL's property list to NEWVAL, and return NEWVAL.")
676 (sym, newplist)
677 register Lisp_Object sym, newplist;
678{
679 CHECK_SYMBOL (sym, 0);
680 XSYMBOL (sym)->plist = newplist;
681 return newplist;
682}
ffd56f97 683
7921925c
JB
684\f
685/* Getting and setting values of symbols */
686
687/* Given the raw contents of a symbol value cell,
688 return the Lisp value of the symbol.
689 This does not handle buffer-local variables; use
690 swap_in_symval_forwarding for that. */
691
692Lisp_Object
693do_symval_forwarding (valcontents)
694 register Lisp_Object valcontents;
695{
696 register Lisp_Object val;
46b2ac21
KH
697 int offset;
698 if (MISCP (valcontents))
324a6eef 699 switch (XMISCTYPE (valcontents))
46b2ac21
KH
700 {
701 case Lisp_Misc_Intfwd:
702 XSETINT (val, *XINTFWD (valcontents)->intvar);
703 return val;
7921925c 704
46b2ac21
KH
705 case Lisp_Misc_Boolfwd:
706 return (*XBOOLFWD (valcontents)->boolvar ? Qt : Qnil);
7921925c 707
46b2ac21
KH
708 case Lisp_Misc_Objfwd:
709 return *XOBJFWD (valcontents)->objvar;
7921925c 710
46b2ac21
KH
711 case Lisp_Misc_Buffer_Objfwd:
712 offset = XBUFFER_OBJFWD (valcontents)->offset;
713 return *(Lisp_Object *)(offset + (char *)current_buffer);
7403b5c8 714
e5f8af9e
KH
715 case Lisp_Misc_Kboard_Objfwd:
716 offset = XKBOARD_OBJFWD (valcontents)->offset;
717 return *(Lisp_Object *)(offset + (char *)current_kboard);
46b2ac21 718 }
7921925c
JB
719 return valcontents;
720}
721
722/* Store NEWVAL into SYM, where VALCONTENTS is found in the value cell
723 of SYM. If SYM is buffer-local, VALCONTENTS should be the
724 buffer-independent contents of the value cell: forwarded just one
725 step past the buffer-localness. */
726
727void
728store_symval_forwarding (sym, valcontents, newval)
729 Lisp_Object sym;
730 register Lisp_Object valcontents, newval;
731{
0220c518 732 switch (SWITCH_ENUM_CAST (XTYPE (valcontents)))
7921925c 733 {
46b2ac21 734 case Lisp_Misc:
324a6eef 735 switch (XMISCTYPE (valcontents))
46b2ac21
KH
736 {
737 case Lisp_Misc_Intfwd:
738 CHECK_NUMBER (newval, 1);
739 *XINTFWD (valcontents)->intvar = XINT (newval);
740 break;
741
742 case Lisp_Misc_Boolfwd:
743 *XBOOLFWD (valcontents)->boolvar = NILP (newval) ? 0 : 1;
744 break;
745
746 case Lisp_Misc_Objfwd:
747 *XOBJFWD (valcontents)->objvar = newval;
748 break;
749
750 case Lisp_Misc_Buffer_Objfwd:
751 {
752 int offset = XBUFFER_OBJFWD (valcontents)->offset;
753 Lisp_Object type;
754
755 type = *(Lisp_Object *)(offset + (char *)&buffer_local_types);
756 if (! NILP (type) && ! NILP (newval)
757 && XTYPE (newval) != XINT (type))
758 buffer_slot_type_mismatch (offset);
759
760 *(Lisp_Object *)(offset + (char *)current_buffer) = newval;
46b2ac21 761 }
7403b5c8
KH
762 break;
763
e5f8af9e
KH
764 case Lisp_Misc_Kboard_Objfwd:
765 (*(Lisp_Object *)((char *)current_kboard
766 + XKBOARD_OBJFWD (valcontents)->offset))
7403b5c8
KH
767 = newval;
768 break;
769
46b2ac21
KH
770 default:
771 goto def;
772 }
7921925c
JB
773 break;
774
7921925c 775 default:
46b2ac21 776 def:
7921925c 777 valcontents = XSYMBOL (sym)->value;
e9ebc175
KH
778 if (BUFFER_LOCAL_VALUEP (valcontents)
779 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
8d4afcac 780 XBUFFER_LOCAL_VALUE (valcontents)->car = newval;
7921925c
JB
781 else
782 XSYMBOL (sym)->value = newval;
783 }
784}
785
786/* Set up the buffer-local symbol SYM for validity in the current
787 buffer. VALCONTENTS is the contents of its value cell.
788 Return the value forwarded one step past the buffer-local indicator. */
789
790static Lisp_Object
791swap_in_symval_forwarding (sym, valcontents)
792 Lisp_Object sym, valcontents;
793{
7403b5c8 794 /* valcontents is a pointer to a struct resembling the cons
7921925c 795 (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE)).
7403b5c8 796
7921925c 797 CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
533984a8
JB
798 local_var_alist, that being the element whose car is this
799 variable. Or it can be a pointer to the
800 (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER does not have
801 an element in its alist for this variable.
802
803 If the current buffer is not BUFFER, we store the current
804 REALVALUE value into CURRENT-ALIST-ELEMENT, then find the
805 appropriate alist element for the buffer now current and set up
806 CURRENT-ALIST-ELEMENT. Then we set REALVALUE out of that
807 element, and store into BUFFER.
808
7921925c
JB
809 Note that REALVALUE can be a forwarding pointer. */
810
811 register Lisp_Object tem1;
8d4afcac 812 tem1 = XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car;
7921925c 813
a33ef3ab 814 if (NILP (tem1) || current_buffer != XBUFFER (tem1))
7921925c 815 {
8d4afcac
KH
816 tem1 = XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car;
817 Fsetcdr (tem1,
818 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->car));
7921925c 819 tem1 = assq_no_quit (sym, current_buffer->local_var_alist);
a33ef3ab 820 if (NILP (tem1))
8d4afcac
KH
821 tem1 = XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr;
822 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car = tem1;
823 XSETBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car,
824 current_buffer);
825 store_symval_forwarding (sym, XBUFFER_LOCAL_VALUE (valcontents)->car,
826 Fcdr (tem1));
7921925c 827 }
8d4afcac 828 return XBUFFER_LOCAL_VALUE (valcontents)->car;
7921925c
JB
829}
830\f
14e76af9
JB
831/* Find the value of a symbol, returning Qunbound if it's not bound.
832 This is helpful for code which just wants to get a variable's value
833 if it has one, without signalling an error.
834 Note that it must not be possible to quit
835 within this function. Great care is required for this. */
7921925c 836
14e76af9
JB
837Lisp_Object
838find_symbol_value (sym)
7921925c
JB
839 Lisp_Object sym;
840{
841 register Lisp_Object valcontents, tem1;
842 register Lisp_Object val;
843 CHECK_SYMBOL (sym, 0);
844 valcontents = XSYMBOL (sym)->value;
845
aabf6bec
KH
846 if (BUFFER_LOCAL_VALUEP (valcontents)
847 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
536b772a 848 valcontents = swap_in_symval_forwarding (sym, valcontents);
7921925c 849
536b772a
KH
850 if (MISCP (valcontents))
851 {
324a6eef 852 switch (XMISCTYPE (valcontents))
46b2ac21
KH
853 {
854 case Lisp_Misc_Intfwd:
855 XSETINT (val, *XINTFWD (valcontents)->intvar);
856 return val;
7921925c 857
46b2ac21
KH
858 case Lisp_Misc_Boolfwd:
859 return (*XBOOLFWD (valcontents)->boolvar ? Qt : Qnil);
7921925c 860
46b2ac21
KH
861 case Lisp_Misc_Objfwd:
862 return *XOBJFWD (valcontents)->objvar;
7921925c 863
46b2ac21
KH
864 case Lisp_Misc_Buffer_Objfwd:
865 return *(Lisp_Object *)(XBUFFER_OBJFWD (valcontents)->offset
866 + (char *)current_buffer);
7403b5c8 867
e5f8af9e
KH
868 case Lisp_Misc_Kboard_Objfwd:
869 return *(Lisp_Object *)(XKBOARD_OBJFWD (valcontents)->offset
870 + (char *)current_kboard);
46b2ac21 871 }
7921925c
JB
872 }
873
874 return valcontents;
875}
876
14e76af9
JB
877DEFUN ("symbol-value", Fsymbol_value, Ssymbol_value, 1, 1, 0,
878 "Return SYMBOL's value. Error if that is void.")
879 (sym)
880 Lisp_Object sym;
881{
0671d7c0 882 Lisp_Object val;
14e76af9 883
0671d7c0 884 val = find_symbol_value (sym);
14e76af9
JB
885 if (EQ (val, Qunbound))
886 return Fsignal (Qvoid_variable, Fcons (sym, Qnil));
887 else
888 return val;
889}
890
7921925c
JB
891DEFUN ("set", Fset, Sset, 2, 2, 0,
892 "Set SYMBOL's value to NEWVAL, and return NEWVAL.")
893 (sym, newval)
894 register Lisp_Object sym, newval;
895{
1bfcade3 896 int voide = EQ (newval, Qunbound);
7921925c 897
7921925c 898 register Lisp_Object valcontents, tem1, current_alist_element;
7921925c
JB
899
900 CHECK_SYMBOL (sym, 0);
a33ef3ab 901 if (NILP (sym) || EQ (sym, Qt))
7921925c
JB
902 return Fsignal (Qsetting_constant, Fcons (sym, Qnil));
903 valcontents = XSYMBOL (sym)->value;
904
e9ebc175 905 if (BUFFER_OBJFWDP (valcontents))
7921925c 906 {
46b2ac21 907 register int idx = XBUFFER_OBJFWD (valcontents)->offset;
865c050f
KH
908 register int mask = XINT (*((Lisp_Object *)
909 (idx + (char *)&buffer_local_flags)));
7921925c
JB
910 if (mask > 0)
911 current_buffer->local_var_flags |= mask;
912 }
913
e9ebc175
KH
914 else if (BUFFER_LOCAL_VALUEP (valcontents)
915 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
7921925c 916 {
8d4afcac
KH
917 /* valcontents is actually a pointer to a struct resembling a cons,
918 with contents something like:
d8cafeb5
JB
919 (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE).
920
921 BUFFER is the last buffer for which this symbol's value was
922 made up to date.
923
924 CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
925 local_var_alist, that being the element whose car is this
926 variable. Or it can be a pointer to the
927 (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER does not
928 have an element in its alist for this variable (that is, if
929 BUFFER sees the default value of this variable).
930
931 If we want to examine or set the value and BUFFER is current,
932 we just examine or set REALVALUE. If BUFFER is not current, we
933 store the current REALVALUE value into CURRENT-ALIST-ELEMENT,
934 then find the appropriate alist element for the buffer now
935 current and set up CURRENT-ALIST-ELEMENT. Then we set
936 REALVALUE out of that element, and store into BUFFER.
937
938 If we are setting the variable and the current buffer does
939 not have an alist entry for this variable, an alist entry is
940 created.
941
942 Note that REALVALUE can be a forwarding pointer. Each time
943 it is examined or set, forwarding must be done. */
944
945 /* What value are we caching right now? */
946 current_alist_element =
8d4afcac 947 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car;
d8cafeb5
JB
948
949 /* If the current buffer is not the buffer whose binding is
950 currently cached, or if it's a Lisp_Buffer_Local_Value and
951 we're looking at the default value, the cache is invalid; we
952 need to write it out, and find the new CURRENT-ALIST-ELEMENT. */
953 if ((current_buffer
8d4afcac 954 != XBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car))
e9ebc175 955 || (BUFFER_LOCAL_VALUEP (valcontents)
b06faa91
JB
956 && EQ (XCONS (current_alist_element)->car,
957 current_alist_element)))
7921925c 958 {
d8cafeb5
JB
959 /* Write out the cached value for the old buffer; copy it
960 back to its alist element. This works if the current
961 buffer only sees the default value, too. */
962 Fsetcdr (current_alist_element,
8d4afcac 963 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->car));
7921925c 964
d8cafeb5 965 /* Find the new value for CURRENT-ALIST-ELEMENT. */
7921925c 966 tem1 = Fassq (sym, current_buffer->local_var_alist);
a33ef3ab 967 if (NILP (tem1))
d8cafeb5
JB
968 {
969 /* This buffer still sees the default value. */
970
971 /* If the variable is a Lisp_Some_Buffer_Local_Value,
972 make CURRENT-ALIST-ELEMENT point to itself,
973 indicating that we're seeing the default value. */
e9ebc175 974 if (SOME_BUFFER_LOCAL_VALUEP (valcontents))
8d4afcac 975 tem1 = XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr;
d8cafeb5
JB
976
977 /* If it's a Lisp_Buffer_Local_Value, give this buffer a
978 new assoc for a local value and set
979 CURRENT-ALIST-ELEMENT to point to that. */
980 else
981 {
982 tem1 = Fcons (sym, Fcdr (current_alist_element));
983 current_buffer->local_var_alist =
984 Fcons (tem1, current_buffer->local_var_alist);
985 }
986 }
987 /* Cache the new buffer's assoc in CURRENT-ALIST-ELEMENT. */
8d4afcac
KH
988 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car
989 = tem1;
d8cafeb5
JB
990
991 /* Set BUFFER, now that CURRENT-ALIST-ELEMENT is accurate. */
8d4afcac
KH
992 XSETBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car,
993 current_buffer);
7921925c 994 }
8d4afcac 995 valcontents = XBUFFER_LOCAL_VALUE (valcontents)->car;
7921925c 996 }
d8cafeb5 997
7921925c
JB
998 /* If storing void (making the symbol void), forward only through
999 buffer-local indicator, not through Lisp_Objfwd, etc. */
1000 if (voide)
1001 store_symval_forwarding (sym, Qnil, newval);
1002 else
1003 store_symval_forwarding (sym, valcontents, newval);
d8cafeb5 1004
7921925c
JB
1005 return newval;
1006}
1007\f
1008/* Access or set a buffer-local symbol's default value. */
1009
1010/* Return the default value of SYM, but don't check for voidness.
1bfcade3 1011 Return Qunbound if it is void. */
7921925c
JB
1012
1013Lisp_Object
1014default_value (sym)
1015 Lisp_Object sym;
1016{
1017 register Lisp_Object valcontents;
1018
1019 CHECK_SYMBOL (sym, 0);
1020 valcontents = XSYMBOL (sym)->value;
1021
1022 /* For a built-in buffer-local variable, get the default value
1023 rather than letting do_symval_forwarding get the current value. */
e9ebc175 1024 if (BUFFER_OBJFWDP (valcontents))
7921925c 1025 {
46b2ac21 1026 register int idx = XBUFFER_OBJFWD (valcontents)->offset;
7921925c 1027
865c050f 1028 if (XINT (*(Lisp_Object *) (idx + (char *) &buffer_local_flags)) != 0)
7921925c
JB
1029 return *(Lisp_Object *)(idx + (char *) &buffer_defaults);
1030 }
1031
1032 /* Handle user-created local variables. */
e9ebc175
KH
1033 if (BUFFER_LOCAL_VALUEP (valcontents)
1034 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
7921925c
JB
1035 {
1036 /* If var is set up for a buffer that lacks a local value for it,
1037 the current value is nominally the default value.
1038 But the current value slot may be more up to date, since
1039 ordinary setq stores just that slot. So use that. */
1040 Lisp_Object current_alist_element, alist_element_car;
1041 current_alist_element
8d4afcac 1042 = XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car;
7921925c
JB
1043 alist_element_car = XCONS (current_alist_element)->car;
1044 if (EQ (alist_element_car, current_alist_element))
8d4afcac 1045 return do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->car);
7921925c 1046 else
8d4afcac 1047 return XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->cdr;
7921925c
JB
1048 }
1049 /* For other variables, get the current value. */
1050 return do_symval_forwarding (valcontents);
1051}
1052
1053DEFUN ("default-boundp", Fdefault_boundp, Sdefault_boundp, 1, 1, 0,
1054 "Return T if SYMBOL has a non-void default value.\n\
1055This is the value that is seen in buffers that do not have their own values\n\
1056for this variable.")
1057 (sym)
1058 Lisp_Object sym;
1059{
1060 register Lisp_Object value;
1061
1062 value = default_value (sym);
1bfcade3 1063 return (EQ (value, Qunbound) ? Qnil : Qt);
7921925c
JB
1064}
1065
1066DEFUN ("default-value", Fdefault_value, Sdefault_value, 1, 1, 0,
1067 "Return SYMBOL's default value.\n\
1068This is the value that is seen in buffers that do not have their own values\n\
1069for this variable. The default value is meaningful for variables with\n\
1070local bindings in certain buffers.")
1071 (sym)
1072 Lisp_Object sym;
1073{
1074 register Lisp_Object value;
1075
1076 value = default_value (sym);
1bfcade3 1077 if (EQ (value, Qunbound))
7921925c
JB
1078 return Fsignal (Qvoid_variable, Fcons (sym, Qnil));
1079 return value;
1080}
1081
1082DEFUN ("set-default", Fset_default, Sset_default, 2, 2, 0,
1083 "Set SYMBOL's default value to VAL. SYMBOL and VAL are evaluated.\n\
1084The default value is seen in buffers that do not have their own values\n\
1085for this variable.")
1086 (sym, value)
1087 Lisp_Object sym, value;
1088{
1089 register Lisp_Object valcontents, current_alist_element, alist_element_buffer;
1090
1091 CHECK_SYMBOL (sym, 0);
1092 valcontents = XSYMBOL (sym)->value;
1093
1094 /* Handle variables like case-fold-search that have special slots
1095 in the buffer. Make them work apparently like Lisp_Buffer_Local_Value
1096 variables. */
e9ebc175 1097 if (BUFFER_OBJFWDP (valcontents))
7921925c 1098 {
46b2ac21 1099 register int idx = XBUFFER_OBJFWD (valcontents)->offset;
7921925c 1100 register struct buffer *b;
865c050f
KH
1101 register int mask = XINT (*((Lisp_Object *)
1102 (idx + (char *)&buffer_local_flags)));
7921925c
JB
1103
1104 if (mask > 0)
1105 {
1106 *(Lisp_Object *)(idx + (char *) &buffer_defaults) = value;
1107 for (b = all_buffers; b; b = b->next)
1108 if (!(b->local_var_flags & mask))
1109 *(Lisp_Object *)(idx + (char *) b) = value;
1110 }
1111 return value;
1112 }
1113
e9ebc175
KH
1114 if (!BUFFER_LOCAL_VALUEP (valcontents)
1115 && !SOME_BUFFER_LOCAL_VALUEP (valcontents))
7921925c
JB
1116 return Fset (sym, value);
1117
1118 /* Store new value into the DEFAULT-VALUE slot */
8d4afcac 1119 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->cdr = value;
7921925c
JB
1120
1121 /* If that slot is current, we must set the REALVALUE slot too */
8d4afcac
KH
1122 current_alist_element
1123 = XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->cdr)->car;
7921925c
JB
1124 alist_element_buffer = Fcar (current_alist_element);
1125 if (EQ (alist_element_buffer, current_alist_element))
8d4afcac
KH
1126 store_symval_forwarding (sym, XBUFFER_LOCAL_VALUE (valcontents)->car,
1127 value);
7921925c
JB
1128
1129 return value;
1130}
1131
1132DEFUN ("setq-default", Fsetq_default, Ssetq_default, 2, UNEVALLED, 0,
0412bf67
RS
1133 "Set the default value of variable VAR to VALUE.\n\
1134VAR, the variable name, is literal (not evaluated);\n\
1135VALUE is an expression and it is evaluated.\n\
1136The default value of a variable is seen in buffers\n\
1137that do not have their own values for the variable.\n\
1138\n\
1139More generally, you can use multiple variables and values, as in\n\
1140 (setq-default SYM VALUE SYM VALUE...)\n\
1141This sets each SYM's default value to the corresponding VALUE.\n\
1142The VALUE for the Nth SYM can refer to the new default values\n\
1143of previous SYMs.")
7921925c
JB
1144 (args)
1145 Lisp_Object args;
1146{
1147 register Lisp_Object args_left;
1148 register Lisp_Object val, sym;
1149 struct gcpro gcpro1;
1150
a33ef3ab 1151 if (NILP (args))
7921925c
JB
1152 return Qnil;
1153
1154 args_left = args;
1155 GCPRO1 (args);
1156
1157 do
1158 {
1159 val = Feval (Fcar (Fcdr (args_left)));
1160 sym = Fcar (args_left);
1161 Fset_default (sym, val);
1162 args_left = Fcdr (Fcdr (args_left));
1163 }
a33ef3ab 1164 while (!NILP (args_left));
7921925c
JB
1165
1166 UNGCPRO;
1167 return val;
1168}
1169\f
a5ca2b75
JB
1170/* Lisp functions for creating and removing buffer-local variables. */
1171
7921925c
JB
1172DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local, Smake_variable_buffer_local,
1173 1, 1, "vMake Variable Buffer Local: ",
1174 "Make VARIABLE have a separate value for each buffer.\n\
1175At any time, the value for the current buffer is in effect.\n\
1176There is also a default value which is seen in any buffer which has not yet\n\
1177set its own value.\n\
1178Using `set' or `setq' to set the variable causes it to have a separate value\n\
1179for the current buffer if it was previously using the default value.\n\
1180The function `default-value' gets the default value and `set-default' sets it.")
1181 (sym)
1182 register Lisp_Object sym;
1183{
8d4afcac 1184 register Lisp_Object tem, valcontents, newval;
7921925c
JB
1185
1186 CHECK_SYMBOL (sym, 0);
1187
7403b5c8 1188 valcontents = XSYMBOL (sym)->value;
e5f8af9e 1189 if (EQ (sym, Qnil) || EQ (sym, Qt) || KBOARD_OBJFWDP (valcontents))
7921925c
JB
1190 error ("Symbol %s may not be buffer-local", XSYMBOL (sym)->name->data);
1191
e9ebc175 1192 if (BUFFER_LOCAL_VALUEP (valcontents) || BUFFER_OBJFWDP (valcontents))
7921925c 1193 return sym;
e9ebc175 1194 if (SOME_BUFFER_LOCAL_VALUEP (valcontents))
7921925c 1195 {
324a6eef 1196 XMISCTYPE (XSYMBOL (sym)->value) = Lisp_Misc_Buffer_Local_Value;
7921925c
JB
1197 return sym;
1198 }
1199 if (EQ (valcontents, Qunbound))
1200 XSYMBOL (sym)->value = Qnil;
1201 tem = Fcons (Qnil, Fsymbol_value (sym));
1202 XCONS (tem)->car = tem;
8d4afcac 1203 newval = allocate_misc ();
324a6eef 1204 XMISCTYPE (newval) = Lisp_Misc_Buffer_Local_Value;
8d4afcac
KH
1205 XBUFFER_LOCAL_VALUE (newval)->car = XSYMBOL (sym)->value;
1206 XBUFFER_LOCAL_VALUE (newval)->cdr = Fcons (Fcurrent_buffer (), tem);
1207 XSYMBOL (sym)->value = newval;
7921925c
JB
1208 return sym;
1209}
1210
1211DEFUN ("make-local-variable", Fmake_local_variable, Smake_local_variable,
1212 1, 1, "vMake Local Variable: ",
1213 "Make VARIABLE have a separate value in the current buffer.\n\
1214Other buffers will continue to share a common default value.\n\
a782f0d5
RS
1215\(The buffer-local value of VARIABLE starts out as the same value\n\
1216VARIABLE previously had. If VARIABLE was void, it remains void.\)\n\
7921925c
JB
1217See also `make-variable-buffer-local'.\n\n\
1218If the variable is already arranged to become local when set,\n\
1219this function causes a local value to exist for this buffer,\n\
62476adc
RS
1220just as setting the variable would do.\n\
1221\n\
1222Do not use `make-local-variable' to make a hook variable buffer-local.\n\
1223Use `make-local-hook' instead.")
7921925c
JB
1224 (sym)
1225 register Lisp_Object sym;
1226{
1227 register Lisp_Object tem, valcontents;
1228
1229 CHECK_SYMBOL (sym, 0);
1230
7403b5c8 1231 valcontents = XSYMBOL (sym)->value;
e5f8af9e 1232 if (EQ (sym, Qnil) || EQ (sym, Qt) || KBOARD_OBJFWDP (valcontents))
7921925c
JB
1233 error ("Symbol %s may not be buffer-local", XSYMBOL (sym)->name->data);
1234
e9ebc175 1235 if (BUFFER_LOCAL_VALUEP (valcontents) || BUFFER_OBJFWDP (valcontents))
7921925c
JB
1236 {
1237 tem = Fboundp (sym);
7403b5c8 1238
7921925c
JB
1239 /* Make sure the symbol has a local value in this particular buffer,
1240 by setting it to the same value it already has. */
1241 Fset (sym, (EQ (tem, Qt) ? Fsymbol_value (sym) : Qunbound));
1242 return sym;
1243 }
1244 /* Make sure sym is set up to hold per-buffer values */
e9ebc175 1245 if (!SOME_BUFFER_LOCAL_VALUEP (valcontents))
7921925c 1246 {
8d4afcac 1247 Lisp_Object newval;
7921925c
JB
1248 tem = Fcons (Qnil, do_symval_forwarding (valcontents));
1249 XCONS (tem)->car = tem;
8d4afcac 1250 newval = allocate_misc ();
324a6eef 1251 XMISCTYPE (newval) = Lisp_Misc_Some_Buffer_Local_Value;
8d4afcac
KH
1252 XBUFFER_LOCAL_VALUE (newval)->car = XSYMBOL (sym)->value;
1253 XBUFFER_LOCAL_VALUE (newval)->cdr = Fcons (Qnil, tem);
1254 XSYMBOL (sym)->value = newval;
7921925c
JB
1255 }
1256 /* Make sure this buffer has its own value of sym */
1257 tem = Fassq (sym, current_buffer->local_var_alist);
a33ef3ab 1258 if (NILP (tem))
7921925c
JB
1259 {
1260 current_buffer->local_var_alist
8d4afcac 1261 = Fcons (Fcons (sym, XCONS (XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->cdr)->cdr)->cdr),
7921925c
JB
1262 current_buffer->local_var_alist);
1263
1264 /* Make sure symbol does not think it is set up for this buffer;
1265 force it to look once again for this buffer's value */
1266 {
8d4afcac
KH
1267 Lisp_Object *pvalbuf;
1268 valcontents = XSYMBOL (sym)->value;
1269 pvalbuf = &XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car;
1270 if (current_buffer == XBUFFER (*pvalbuf))
1271 *pvalbuf = Qnil;
7921925c 1272 }
7921925c 1273 }
a5ca2b75
JB
1274
1275 /* If the symbol forwards into a C variable, then swap in the
1276 variable for this buffer immediately. If C code modifies the
1277 variable before we swap in, then that new value will clobber the
1278 default value the next time we swap. */
8d4afcac 1279 valcontents = XBUFFER_LOCAL_VALUE (XSYMBOL (sym)->value)->car;
e9ebc175 1280 if (INTFWDP (valcontents) || BOOLFWDP (valcontents) || OBJFWDP (valcontents))
a5ca2b75
JB
1281 swap_in_symval_forwarding (sym, XSYMBOL (sym)->value);
1282
7921925c
JB
1283 return sym;
1284}
1285
1286DEFUN ("kill-local-variable", Fkill_local_variable, Skill_local_variable,
1287 1, 1, "vKill Local Variable: ",
1288 "Make VARIABLE no longer have a separate value in the current buffer.\n\
1289From now on the default value will apply in this buffer.")
1290 (sym)
1291 register Lisp_Object sym;
1292{
1293 register Lisp_Object tem, valcontents;
1294
1295 CHECK_SYMBOL (sym, 0);
1296
1297 valcontents = XSYMBOL (sym)->value;
1298
e9ebc175 1299 if (BUFFER_OBJFWDP (valcontents))
7921925c 1300 {
46b2ac21 1301 register int idx = XBUFFER_OBJFWD (valcontents)->offset;
865c050f
KH
1302 register int mask = XINT (*((Lisp_Object*)
1303 (idx + (char *)&buffer_local_flags)));
7921925c
JB
1304
1305 if (mask > 0)
1306 {
1307 *(Lisp_Object *)(idx + (char *) current_buffer)
1308 = *(Lisp_Object *)(idx + (char *) &buffer_defaults);
1309 current_buffer->local_var_flags &= ~mask;
1310 }
1311 return sym;
1312 }
1313
e9ebc175
KH
1314 if (!BUFFER_LOCAL_VALUEP (valcontents)
1315 && !SOME_BUFFER_LOCAL_VALUEP (valcontents))
7921925c
JB
1316 return sym;
1317
1318 /* Get rid of this buffer's alist element, if any */
1319
1320 tem = Fassq (sym, current_buffer->local_var_alist);
a33ef3ab 1321 if (!NILP (tem))
8d4afcac
KH
1322 current_buffer->local_var_alist
1323 = Fdelq (tem, current_buffer->local_var_alist);
7921925c
JB
1324
1325 /* Make sure symbol does not think it is set up for this buffer;
1326 force it to look once again for this buffer's value */
1327 {
8d4afcac
KH
1328 Lisp_Object *pvalbuf;
1329 valcontents = XSYMBOL (sym)->value;
1330 pvalbuf = &XCONS (XBUFFER_LOCAL_VALUE (valcontents)->cdr)->car;
1331 if (current_buffer == XBUFFER (*pvalbuf))
1332 *pvalbuf = Qnil;
7921925c
JB
1333 }
1334
1335 return sym;
1336}
62476adc
RS
1337
1338DEFUN ("local-variable-p", Flocal_variable_p, Slocal_variable_p,
1339 1, 1, 0,
1340 "Non-nil if VARIABLE has a local binding in the current buffer.")
1341 (sym)
1342 register Lisp_Object sym;
1343{
1344 Lisp_Object valcontents;
1345
1346 CHECK_SYMBOL (sym, 0);
1347
1348 valcontents = XSYMBOL (sym)->value;
1349 return ((BUFFER_LOCAL_VALUEP (valcontents)
1350 || SOME_BUFFER_LOCAL_VALUEP (valcontents)
1351 || BUFFER_OBJFWDP (valcontents))
1352 ? Qt : Qnil);
1353}
7921925c 1354\f
ffd56f97
JB
1355/* Find the function at the end of a chain of symbol function indirections. */
1356
1357/* If OBJECT is a symbol, find the end of its function chain and
1358 return the value found there. If OBJECT is not a symbol, just
1359 return it. If there is a cycle in the function chain, signal a
1360 cyclic-function-indirection error.
1361
1362 This is like Findirect_function, except that it doesn't signal an
1363 error if the chain ends up unbound. */
1364Lisp_Object
a2932990 1365indirect_function (object)
62476adc 1366 register Lisp_Object object;
ffd56f97 1367{
eb8c3be9 1368 Lisp_Object tortoise, hare;
ffd56f97 1369
eb8c3be9 1370 hare = tortoise = object;
ffd56f97
JB
1371
1372 for (;;)
1373 {
e9ebc175 1374 if (!SYMBOLP (hare) || EQ (hare, Qunbound))
ffd56f97
JB
1375 break;
1376 hare = XSYMBOL (hare)->function;
e9ebc175 1377 if (!SYMBOLP (hare) || EQ (hare, Qunbound))
ffd56f97
JB
1378 break;
1379 hare = XSYMBOL (hare)->function;
1380
eb8c3be9 1381 tortoise = XSYMBOL (tortoise)->function;
ffd56f97 1382
eb8c3be9 1383 if (EQ (hare, tortoise))
ffd56f97
JB
1384 Fsignal (Qcyclic_function_indirection, Fcons (object, Qnil));
1385 }
1386
1387 return hare;
1388}
1389
1390DEFUN ("indirect-function", Findirect_function, Sindirect_function, 1, 1, 0,
1391 "Return the function at the end of OBJECT's function chain.\n\
1392If OBJECT is a symbol, follow all function indirections and return the final\n\
1393function binding.\n\
1394If OBJECT is not a symbol, just return it.\n\
1395Signal a void-function error if the final symbol is unbound.\n\
1396Signal a cyclic-function-indirection error if there is a loop in the\n\
1397function chain of symbols.")
1398 (object)
1399 register Lisp_Object object;
1400{
1401 Lisp_Object result;
1402
1403 result = indirect_function (object);
1404
1405 if (EQ (result, Qunbound))
1406 return Fsignal (Qvoid_function, Fcons (object, Qnil));
1407 return result;
1408}
1409\f
7921925c
JB
1410/* Extract and set vector and string elements */
1411
1412DEFUN ("aref", Faref, Saref, 2, 2, 0,
1413 "Return the element of ARRAY at index INDEX.\n\
1414ARRAY may be a vector or a string, or a byte-code object. INDEX starts at 0.")
1415 (array, idx)
1416 register Lisp_Object array;
1417 Lisp_Object idx;
1418{
1419 register int idxval;
1420
1421 CHECK_NUMBER (idx, 1);
1422 idxval = XINT (idx);
e9ebc175 1423 if (STRINGP (array))
7921925c
JB
1424 {
1425 Lisp_Object val;
c24e4efe
KH
1426 if (idxval < 0 || idxval >= XSTRING (array)->size)
1427 args_out_of_range (array, idx);
1b42cf2e 1428 XSETFASTINT (val, (unsigned char) XSTRING (array)->data[idxval]);
7921925c
JB
1429 return val;
1430 }
1431 else
c24e4efe 1432 {
7f358972
RS
1433 int size;
1434 if (VECTORP (array))
1435 size = XVECTOR (array)->size;
1436 else if (COMPILEDP (array))
1437 size = XVECTOR (array)->size & PSEUDOVECTOR_SIZE_MASK;
1438 else
1439 wrong_type_argument (Qarrayp, array);
1440
1441 if (idxval < 0 || idxval >= size)
c24e4efe
KH
1442 args_out_of_range (array, idx);
1443 return XVECTOR (array)->contents[idxval];
1444 }
7921925c
JB
1445}
1446
1447DEFUN ("aset", Faset, Saset, 3, 3, 0,
73d40355
RS
1448 "Store into the element of ARRAY at index IDX the value NEWELT.\n\
1449ARRAY may be a vector or a string. IDX starts at 0.")
7921925c
JB
1450 (array, idx, newelt)
1451 register Lisp_Object array;
1452 Lisp_Object idx, newelt;
1453{
1454 register int idxval;
1455
1456 CHECK_NUMBER (idx, 1);
1457 idxval = XINT (idx);
e9ebc175 1458 if (!VECTORP (array) && !STRINGP (array))
7921925c 1459 array = wrong_type_argument (Qarrayp, array);
7921925c
JB
1460 CHECK_IMPURE (array);
1461
e9ebc175 1462 if (VECTORP (array))
c24e4efe
KH
1463 {
1464 if (idxval < 0 || idxval >= XVECTOR (array)->size)
1465 args_out_of_range (array, idx);
1466 XVECTOR (array)->contents[idxval] = newelt;
1467 }
7921925c
JB
1468 else
1469 {
c24e4efe
KH
1470 if (idxval < 0 || idxval >= XSTRING (array)->size)
1471 args_out_of_range (array, idx);
7921925c
JB
1472 CHECK_NUMBER (newelt, 2);
1473 XSTRING (array)->data[idxval] = XINT (newelt);
1474 }
1475
1476 return newelt;
1477}
7921925c
JB
1478\f
1479/* Arithmetic functions */
1480
1481enum comparison { equal, notequal, less, grtr, less_or_equal, grtr_or_equal };
1482
1483Lisp_Object
1484arithcompare (num1, num2, comparison)
1485 Lisp_Object num1, num2;
1486 enum comparison comparison;
1487{
1488 double f1, f2;
1489 int floatp = 0;
1490
1491#ifdef LISP_FLOAT_TYPE
1492 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1, 0);
1493 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2, 0);
1494
e9ebc175 1495 if (FLOATP (num1) || FLOATP (num2))
7921925c
JB
1496 {
1497 floatp = 1;
e9ebc175
KH
1498 f1 = (FLOATP (num1)) ? XFLOAT (num1)->data : XINT (num1);
1499 f2 = (FLOATP (num2)) ? XFLOAT (num2)->data : XINT (num2);
7921925c
JB
1500 }
1501#else
1502 CHECK_NUMBER_COERCE_MARKER (num1, 0);
1503 CHECK_NUMBER_COERCE_MARKER (num2, 0);
1504#endif /* LISP_FLOAT_TYPE */
1505
1506 switch (comparison)
1507 {
1508 case equal:
1509 if (floatp ? f1 == f2 : XINT (num1) == XINT (num2))
1510 return Qt;
1511 return Qnil;
1512
1513 case notequal:
1514 if (floatp ? f1 != f2 : XINT (num1) != XINT (num2))
1515 return Qt;
1516 return Qnil;
1517
1518 case less:
1519 if (floatp ? f1 < f2 : XINT (num1) < XINT (num2))
1520 return Qt;
1521 return Qnil;
1522
1523 case less_or_equal:
1524 if (floatp ? f1 <= f2 : XINT (num1) <= XINT (num2))
1525 return Qt;
1526 return Qnil;
1527
1528 case grtr:
1529 if (floatp ? f1 > f2 : XINT (num1) > XINT (num2))
1530 return Qt;
1531 return Qnil;
1532
1533 case grtr_or_equal:
1534 if (floatp ? f1 >= f2 : XINT (num1) >= XINT (num2))
1535 return Qt;
1536 return Qnil;
25e40a4b
JB
1537
1538 default:
1539 abort ();
7921925c
JB
1540 }
1541}
1542
1543DEFUN ("=", Feqlsign, Seqlsign, 2, 2, 0,
1544 "T if two args, both numbers or markers, are equal.")
1545 (num1, num2)
1546 register Lisp_Object num1, num2;
1547{
1548 return arithcompare (num1, num2, equal);
1549}
1550
1551DEFUN ("<", Flss, Slss, 2, 2, 0,
1552 "T if first arg is less than second arg. Both must be numbers or markers.")
1553 (num1, num2)
1554 register Lisp_Object num1, num2;
1555{
1556 return arithcompare (num1, num2, less);
1557}
1558
1559DEFUN (">", Fgtr, Sgtr, 2, 2, 0,
1560 "T if first arg is greater than second arg. Both must be numbers or markers.")
1561 (num1, num2)
1562 register Lisp_Object num1, num2;
1563{
1564 return arithcompare (num1, num2, grtr);
1565}
1566
1567DEFUN ("<=", Fleq, Sleq, 2, 2, 0,
1568 "T if first arg is less than or equal to second arg.\n\
1569Both must be numbers or markers.")
1570 (num1, num2)
1571 register Lisp_Object num1, num2;
1572{
1573 return arithcompare (num1, num2, less_or_equal);
1574}
1575
1576DEFUN (">=", Fgeq, Sgeq, 2, 2, 0,
1577 "T if first arg is greater than or equal to second arg.\n\
1578Both must be numbers or markers.")
1579 (num1, num2)
1580 register Lisp_Object num1, num2;
1581{
1582 return arithcompare (num1, num2, grtr_or_equal);
1583}
1584
1585DEFUN ("/=", Fneq, Sneq, 2, 2, 0,
1586 "T if first arg is not equal to second arg. Both must be numbers or markers.")
1587 (num1, num2)
1588 register Lisp_Object num1, num2;
1589{
1590 return arithcompare (num1, num2, notequal);
1591}
1592
1593DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0, "T if NUMBER is zero.")
1594 (num)
1595 register Lisp_Object num;
1596{
1597#ifdef LISP_FLOAT_TYPE
1598 CHECK_NUMBER_OR_FLOAT (num, 0);
1599
e9ebc175 1600 if (FLOATP (num))
7921925c
JB
1601 {
1602 if (XFLOAT(num)->data == 0.0)
1603 return Qt;
1604 return Qnil;
1605 }
1606#else
1607 CHECK_NUMBER (num, 0);
1608#endif /* LISP_FLOAT_TYPE */
1609
1610 if (!XINT (num))
1611 return Qt;
1612 return Qnil;
1613}
1614\f
51cf3e31
JB
1615/* Convert between 32-bit values and pairs of lispy 24-bit values. */
1616
1617Lisp_Object
1618long_to_cons (i)
1619 unsigned long i;
1620{
1621 unsigned int top = i >> 16;
1622 unsigned int bot = i & 0xFFFF;
1623 if (top == 0)
1624 return make_number (bot);
1625 if (top == 0xFFFF)
1626 return Fcons (make_number (-1), make_number (bot));
1627 return Fcons (make_number (top), make_number (bot));
1628}
1629
1630unsigned long
1631cons_to_long (c)
1632 Lisp_Object c;
1633{
878a80cc 1634 Lisp_Object top, bot;
51cf3e31
JB
1635 if (INTEGERP (c))
1636 return XINT (c);
1637 top = XCONS (c)->car;
1638 bot = XCONS (c)->cdr;
1639 if (CONSP (bot))
1640 bot = XCONS (bot)->car;
1641 return ((XINT (top) << 16) | XINT (bot));
1642}
1643\f
f2980264 1644DEFUN ("number-to-string", Fnumber_to_string, Snumber_to_string, 1, 1, 0,
25e40a4b
JB
1645 "Convert NUM to a string by printing it in decimal.\n\
1646Uses a minus sign if negative.\n\
1647NUM may be an integer or a floating point number.")
7921925c
JB
1648 (num)
1649 Lisp_Object num;
1650{
1651 char buffer[20];
1652
1653#ifndef LISP_FLOAT_TYPE
1654 CHECK_NUMBER (num, 0);
1655#else
1656 CHECK_NUMBER_OR_FLOAT (num, 0);
1657
e9ebc175 1658 if (FLOATP (num))
7921925c
JB
1659 {
1660 char pigbuf[350]; /* see comments in float_to_string */
1661
1662 float_to_string (pigbuf, XFLOAT(num)->data);
7403b5c8 1663 return build_string (pigbuf);
7921925c
JB
1664 }
1665#endif /* LISP_FLOAT_TYPE */
1666
1667 sprintf (buffer, "%d", XINT (num));
1668 return build_string (buffer);
1669}
1670
25e40a4b
JB
1671DEFUN ("string-to-number", Fstring_to_number, Sstring_to_number, 1, 1, 0,
1672 "Convert STRING to a number by parsing it as a decimal number.\n\
1c1c17eb
RS
1673This parses both integers and floating point numbers.\n\
1674It ignores leading spaces and tabs.")
7921925c
JB
1675 (str)
1676 register Lisp_Object str;
1677{
0a3e4d65 1678 unsigned char *p;
25e40a4b 1679
7921925c
JB
1680 CHECK_STRING (str, 0);
1681
25e40a4b
JB
1682 p = XSTRING (str)->data;
1683
1684 /* Skip any whitespace at the front of the number. Some versions of
1685 atoi do this anyway, so we might as well make Emacs lisp consistent. */
0a3e4d65 1686 while (*p == ' ' || *p == '\t')
25e40a4b
JB
1687 p++;
1688
7921925c 1689#ifdef LISP_FLOAT_TYPE
25e40a4b
JB
1690 if (isfloat_string (p))
1691 return make_float (atof (p));
7921925c
JB
1692#endif /* LISP_FLOAT_TYPE */
1693
25e40a4b 1694 return make_number (atoi (p));
7921925c 1695}
7403b5c8 1696\f
7921925c
JB
1697enum arithop
1698 { Aadd, Asub, Amult, Adiv, Alogand, Alogior, Alogxor, Amax, Amin };
1699
b06faa91
JB
1700extern Lisp_Object float_arith_driver ();
1701
7921925c 1702Lisp_Object
87fbf902 1703arith_driver (code, nargs, args)
7921925c
JB
1704 enum arithop code;
1705 int nargs;
1706 register Lisp_Object *args;
1707{
1708 register Lisp_Object val;
1709 register int argnum;
5260234d
RS
1710 register EMACS_INT accum;
1711 register EMACS_INT next;
7921925c 1712
0220c518 1713 switch (SWITCH_ENUM_CAST (code))
7921925c
JB
1714 {
1715 case Alogior:
1716 case Alogxor:
1717 case Aadd:
1718 case Asub:
1719 accum = 0; break;
1720 case Amult:
1721 accum = 1; break;
1722 case Alogand:
1723 accum = -1; break;
1724 }
1725
1726 for (argnum = 0; argnum < nargs; argnum++)
1727 {
1728 val = args[argnum]; /* using args[argnum] as argument to CHECK_NUMBER_... */
1729#ifdef LISP_FLOAT_TYPE
1730 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val, argnum);
1731
e9ebc175 1732 if (FLOATP (val)) /* time to do serious math */
7921925c
JB
1733 return (float_arith_driver ((double) accum, argnum, code,
1734 nargs, args));
1735#else
1736 CHECK_NUMBER_COERCE_MARKER (val, argnum);
1737#endif /* LISP_FLOAT_TYPE */
1738 args[argnum] = val; /* runs into a compiler bug. */
1739 next = XINT (args[argnum]);
0220c518 1740 switch (SWITCH_ENUM_CAST (code))
7921925c
JB
1741 {
1742 case Aadd: accum += next; break;
1743 case Asub:
1744 if (!argnum && nargs != 1)
1745 next = - next;
1746 accum -= next;
1747 break;
1748 case Amult: accum *= next; break;
1749 case Adiv:
1750 if (!argnum) accum = next;
87fbf902
RS
1751 else
1752 {
1753 if (next == 0)
1754 Fsignal (Qarith_error, Qnil);
1755 accum /= next;
1756 }
7921925c
JB
1757 break;
1758 case Alogand: accum &= next; break;
1759 case Alogior: accum |= next; break;
1760 case Alogxor: accum ^= next; break;
1761 case Amax: if (!argnum || next > accum) accum = next; break;
1762 case Amin: if (!argnum || next < accum) accum = next; break;
1763 }
1764 }
1765
f187f1f7 1766 XSETINT (val, accum);
7921925c
JB
1767 return val;
1768}
1769
1770#ifdef LISP_FLOAT_TYPE
1a2f2d33
KH
1771
1772#undef isnan
1773#define isnan(x) ((x) != (x))
1774
7921925c
JB
1775Lisp_Object
1776float_arith_driver (accum, argnum, code, nargs, args)
1777 double accum;
1778 register int argnum;
1779 enum arithop code;
1780 int nargs;
1781 register Lisp_Object *args;
1782{
1783 register Lisp_Object val;
1784 double next;
7403b5c8 1785
7921925c
JB
1786 for (; argnum < nargs; argnum++)
1787 {
1788 val = args[argnum]; /* using args[argnum] as argument to CHECK_NUMBER_... */
1789 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val, argnum);
1790
e9ebc175 1791 if (FLOATP (val))
7921925c
JB
1792 {
1793 next = XFLOAT (val)->data;
1794 }
1795 else
1796 {
1797 args[argnum] = val; /* runs into a compiler bug. */
1798 next = XINT (args[argnum]);
1799 }
0220c518 1800 switch (SWITCH_ENUM_CAST (code))
7921925c
JB
1801 {
1802 case Aadd:
1803 accum += next;
1804 break;
1805 case Asub:
1806 if (!argnum && nargs != 1)
1807 next = - next;
1808 accum -= next;
1809 break;
1810 case Amult:
1811 accum *= next;
1812 break;
1813 case Adiv:
1814 if (!argnum)
1815 accum = next;
1816 else
87fbf902
RS
1817 {
1818 if (next == 0)
1819 Fsignal (Qarith_error, Qnil);
1820 accum /= next;
1821 }
7921925c
JB
1822 break;
1823 case Alogand:
1824 case Alogior:
1825 case Alogxor:
1826 return wrong_type_argument (Qinteger_or_marker_p, val);
1827 case Amax:
1a2f2d33 1828 if (!argnum || isnan (next) || next > accum)
7921925c
JB
1829 accum = next;
1830 break;
1831 case Amin:
1a2f2d33 1832 if (!argnum || isnan (next) || next < accum)
7921925c
JB
1833 accum = next;
1834 break;
1835 }
1836 }
1837
1838 return make_float (accum);
1839}
1840#endif /* LISP_FLOAT_TYPE */
1841
1842DEFUN ("+", Fplus, Splus, 0, MANY, 0,
1843 "Return sum of any number of arguments, which are numbers or markers.")
1844 (nargs, args)
1845 int nargs;
1846 Lisp_Object *args;
1847{
1848 return arith_driver (Aadd, nargs, args);
1849}
1850
1851DEFUN ("-", Fminus, Sminus, 0, MANY, 0,
1852 "Negate number or subtract numbers or markers.\n\
1853With one arg, negates it. With more than one arg,\n\
1854subtracts all but the first from the first.")
1855 (nargs, args)
1856 int nargs;
1857 Lisp_Object *args;
1858{
1859 return arith_driver (Asub, nargs, args);
1860}
1861
1862DEFUN ("*", Ftimes, Stimes, 0, MANY, 0,
1863 "Returns product of any number of arguments, which are numbers or markers.")
1864 (nargs, args)
1865 int nargs;
1866 Lisp_Object *args;
1867{
1868 return arith_driver (Amult, nargs, args);
1869}
1870
1871DEFUN ("/", Fquo, Squo, 2, MANY, 0,
1872 "Returns first argument divided by all the remaining arguments.\n\
1873The arguments must be numbers or markers.")
1874 (nargs, args)
1875 int nargs;
1876 Lisp_Object *args;
1877{
1878 return arith_driver (Adiv, nargs, args);
1879}
1880
1881DEFUN ("%", Frem, Srem, 2, 2, 0,
1882 "Returns remainder of first arg divided by second.\n\
aa29f9b9 1883Both must be integers or markers.")
7921925c
JB
1884 (num1, num2)
1885 register Lisp_Object num1, num2;
1886{
1887 Lisp_Object val;
1888
7921925c
JB
1889 CHECK_NUMBER_COERCE_MARKER (num1, 0);
1890 CHECK_NUMBER_COERCE_MARKER (num2, 1);
7921925c 1891
87fbf902
RS
1892 if (XFASTINT (num2) == 0)
1893 Fsignal (Qarith_error, Qnil);
1894
f187f1f7 1895 XSETINT (val, XINT (num1) % XINT (num2));
7921925c
JB
1896 return val;
1897}
1898
1d66a5fa
KH
1899#ifndef HAVE_FMOD
1900double
1901fmod (f1, f2)
1902 double f1, f2;
1903{
1904#ifdef HAVE_DREM /* Some systems use this non-standard name. */
1905 return (drem (f1, f2));
1906#else /* Other systems don't seem to have it at all. */
1907 return (f1 - f2 * floor (f1/f2));
1908#endif
1909}
1910#endif /* ! HAVE_FMOD */
1911
44fa9da5
PE
1912DEFUN ("mod", Fmod, Smod, 2, 2, 0,
1913 "Returns X modulo Y.\n\
1914The result falls between zero (inclusive) and Y (exclusive).\n\
1915Both X and Y must be numbers or markers.")
1916 (num1, num2)
1917 register Lisp_Object num1, num2;
1918{
1919 Lisp_Object val;
5260234d 1920 EMACS_INT i1, i2;
44fa9da5
PE
1921
1922#ifdef LISP_FLOAT_TYPE
1923 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1, 0);
1924 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2, 1);
1925
e9ebc175 1926 if (FLOATP (num1) || FLOATP (num2))
44fa9da5
PE
1927 {
1928 double f1, f2;
1929
e9ebc175
KH
1930 f1 = FLOATP (num1) ? XFLOAT (num1)->data : XINT (num1);
1931 f2 = FLOATP (num2) ? XFLOAT (num2)->data : XINT (num2);
44fa9da5
PE
1932 if (f2 == 0)
1933 Fsignal (Qarith_error, Qnil);
1934
44fa9da5 1935 f1 = fmod (f1, f2);
44fa9da5
PE
1936 /* If the "remainder" comes out with the wrong sign, fix it. */
1937 if ((f1 < 0) != (f2 < 0))
1938 f1 += f2;
1939 return (make_float (f1));
1940 }
1941#else /* not LISP_FLOAT_TYPE */
1942 CHECK_NUMBER_COERCE_MARKER (num1, 0);
1943 CHECK_NUMBER_COERCE_MARKER (num2, 1);
1944#endif /* not LISP_FLOAT_TYPE */
1945
1946 i1 = XINT (num1);
1947 i2 = XINT (num2);
1948
1949 if (i2 == 0)
1950 Fsignal (Qarith_error, Qnil);
7403b5c8 1951
44fa9da5
PE
1952 i1 %= i2;
1953
1954 /* If the "remainder" comes out with the wrong sign, fix it. */
04f7ec69 1955 if (i2 < 0 ? i1 > 0 : i1 < 0)
44fa9da5
PE
1956 i1 += i2;
1957
f187f1f7 1958 XSETINT (val, i1);
44fa9da5
PE
1959 return val;
1960}
1961
7921925c
JB
1962DEFUN ("max", Fmax, Smax, 1, MANY, 0,
1963 "Return largest of all the arguments (which must be numbers or markers).\n\
1964The value is always a number; markers are converted to numbers.")
1965 (nargs, args)
1966 int nargs;
1967 Lisp_Object *args;
1968{
1969 return arith_driver (Amax, nargs, args);
1970}
1971
1972DEFUN ("min", Fmin, Smin, 1, MANY, 0,
1973 "Return smallest of all the arguments (which must be numbers or markers).\n\
1974The value is always a number; markers are converted to numbers.")
1975 (nargs, args)
1976 int nargs;
1977 Lisp_Object *args;
1978{
1979 return arith_driver (Amin, nargs, args);
1980}
1981
1982DEFUN ("logand", Flogand, Slogand, 0, MANY, 0,
1983 "Return bitwise-and of all the arguments.\n\
1984Arguments may be integers, or markers converted to integers.")
1985 (nargs, args)
1986 int nargs;
1987 Lisp_Object *args;
1988{
1989 return arith_driver (Alogand, nargs, args);
1990}
1991
1992DEFUN ("logior", Flogior, Slogior, 0, MANY, 0,
1993 "Return bitwise-or of all the arguments.\n\
1994Arguments may be integers, or markers converted to integers.")
1995 (nargs, args)
1996 int nargs;
1997 Lisp_Object *args;
1998{
1999 return arith_driver (Alogior, nargs, args);
2000}
2001
2002DEFUN ("logxor", Flogxor, Slogxor, 0, MANY, 0,
2003 "Return bitwise-exclusive-or of all the arguments.\n\
2004Arguments may be integers, or markers converted to integers.")
2005 (nargs, args)
2006 int nargs;
2007 Lisp_Object *args;
2008{
2009 return arith_driver (Alogxor, nargs, args);
2010}
2011
2012DEFUN ("ash", Fash, Sash, 2, 2, 0,
2013 "Return VALUE with its bits shifted left by COUNT.\n\
2014If COUNT is negative, shifting is actually to the right.\n\
2015In this case, the sign bit is duplicated.")
3b9f7964
RS
2016 (value, count)
2017 register Lisp_Object value, count;
7921925c
JB
2018{
2019 register Lisp_Object val;
2020
3d9652eb
RS
2021 CHECK_NUMBER (value, 0);
2022 CHECK_NUMBER (count, 1);
7921925c 2023
3d9652eb
RS
2024 if (XINT (count) > 0)
2025 XSETINT (val, XINT (value) << XFASTINT (count));
7921925c 2026 else
3d9652eb 2027 XSETINT (val, XINT (value) >> -XINT (count));
7921925c
JB
2028 return val;
2029}
2030
2031DEFUN ("lsh", Flsh, Slsh, 2, 2, 0,
2032 "Return VALUE with its bits shifted left by COUNT.\n\
2033If COUNT is negative, shifting is actually to the right.\n\
2034In this case, zeros are shifted in on the left.")
3d9652eb
RS
2035 (value, count)
2036 register Lisp_Object value, count;
7921925c
JB
2037{
2038 register Lisp_Object val;
2039
3d9652eb
RS
2040 CHECK_NUMBER (value, 0);
2041 CHECK_NUMBER (count, 1);
7921925c 2042
3d9652eb
RS
2043 if (XINT (count) > 0)
2044 XSETINT (val, (EMACS_UINT) XUINT (value) << XFASTINT (count));
7921925c 2045 else
3d9652eb 2046 XSETINT (val, (EMACS_UINT) XUINT (value) >> -XINT (count));
7921925c
JB
2047 return val;
2048}
2049
2050DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0,
2051 "Return NUMBER plus one. NUMBER may be a number or a marker.\n\
2052Markers are converted to integers.")
2053 (num)
2054 register Lisp_Object num;
2055{
2056#ifdef LISP_FLOAT_TYPE
2057 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num, 0);
2058
e9ebc175 2059 if (FLOATP (num))
7921925c
JB
2060 return (make_float (1.0 + XFLOAT (num)->data));
2061#else
2062 CHECK_NUMBER_COERCE_MARKER (num, 0);
2063#endif /* LISP_FLOAT_TYPE */
2064
702672da 2065 XSETINT (num, XINT (num) + 1);
7921925c
JB
2066 return num;
2067}
2068
2069DEFUN ("1-", Fsub1, Ssub1, 1, 1, 0,
2070 "Return NUMBER minus one. NUMBER may be a number or a marker.\n\
2071Markers are converted to integers.")
2072 (num)
2073 register Lisp_Object num;
2074{
2075#ifdef LISP_FLOAT_TYPE
2076 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num, 0);
2077
e9ebc175 2078 if (FLOATP (num))
7921925c
JB
2079 return (make_float (-1.0 + XFLOAT (num)->data));
2080#else
2081 CHECK_NUMBER_COERCE_MARKER (num, 0);
2082#endif /* LISP_FLOAT_TYPE */
2083
702672da 2084 XSETINT (num, XINT (num) - 1);
7921925c
JB
2085 return num;
2086}
2087
2088DEFUN ("lognot", Flognot, Slognot, 1, 1, 0,
2089 "Return the bitwise complement of ARG. ARG must be an integer.")
2090 (num)
2091 register Lisp_Object num;
2092{
2093 CHECK_NUMBER (num, 0);
702672da 2094 XSETINT (num, ~XINT (num));
7921925c
JB
2095 return num;
2096}
2097\f
2098void
2099syms_of_data ()
2100{
6315e761
RS
2101 Lisp_Object error_tail, arith_tail;
2102
7921925c
JB
2103 Qquote = intern ("quote");
2104 Qlambda = intern ("lambda");
2105 Qsubr = intern ("subr");
2106 Qerror_conditions = intern ("error-conditions");
2107 Qerror_message = intern ("error-message");
2108 Qtop_level = intern ("top-level");
2109
2110 Qerror = intern ("error");
2111 Qquit = intern ("quit");
2112 Qwrong_type_argument = intern ("wrong-type-argument");
2113 Qargs_out_of_range = intern ("args-out-of-range");
2114 Qvoid_function = intern ("void-function");
ffd56f97 2115 Qcyclic_function_indirection = intern ("cyclic-function-indirection");
7921925c
JB
2116 Qvoid_variable = intern ("void-variable");
2117 Qsetting_constant = intern ("setting-constant");
2118 Qinvalid_read_syntax = intern ("invalid-read-syntax");
2119
2120 Qinvalid_function = intern ("invalid-function");
2121 Qwrong_number_of_arguments = intern ("wrong-number-of-arguments");
2122 Qno_catch = intern ("no-catch");
2123 Qend_of_file = intern ("end-of-file");
2124 Qarith_error = intern ("arith-error");
2125 Qbeginning_of_buffer = intern ("beginning-of-buffer");
2126 Qend_of_buffer = intern ("end-of-buffer");
2127 Qbuffer_read_only = intern ("buffer-read-only");
3b8819d6 2128 Qmark_inactive = intern ("mark-inactive");
7921925c
JB
2129
2130 Qlistp = intern ("listp");
2131 Qconsp = intern ("consp");
2132 Qsymbolp = intern ("symbolp");
2133 Qintegerp = intern ("integerp");
2134 Qnatnump = intern ("natnump");
8e86942b 2135 Qwholenump = intern ("wholenump");
7921925c
JB
2136 Qstringp = intern ("stringp");
2137 Qarrayp = intern ("arrayp");
2138 Qsequencep = intern ("sequencep");
2139 Qbufferp = intern ("bufferp");
2140 Qvectorp = intern ("vectorp");
2141 Qchar_or_string_p = intern ("char-or-string-p");
2142 Qmarkerp = intern ("markerp");
07bd8472 2143 Qbuffer_or_string_p = intern ("buffer-or-string-p");
7921925c
JB
2144 Qinteger_or_marker_p = intern ("integer-or-marker-p");
2145 Qboundp = intern ("boundp");
2146 Qfboundp = intern ("fboundp");
2147
2148#ifdef LISP_FLOAT_TYPE
2149 Qfloatp = intern ("floatp");
2150 Qnumberp = intern ("numberp");
2151 Qnumber_or_marker_p = intern ("number-or-marker-p");
2152#endif /* LISP_FLOAT_TYPE */
2153
2154 Qcdr = intern ("cdr");
2155
f845f2c9 2156 /* Handle automatic advice activation */
ab297811
RS
2157 Qad_advice_info = intern ("ad-advice-info");
2158 Qad_activate = intern ("ad-activate");
f845f2c9 2159
6315e761
RS
2160 error_tail = Fcons (Qerror, Qnil);
2161
7921925c
JB
2162 /* ERROR is used as a signaler for random errors for which nothing else is right */
2163
2164 Fput (Qerror, Qerror_conditions,
6315e761 2165 error_tail);
7921925c
JB
2166 Fput (Qerror, Qerror_message,
2167 build_string ("error"));
2168
2169 Fput (Qquit, Qerror_conditions,
2170 Fcons (Qquit, Qnil));
2171 Fput (Qquit, Qerror_message,
2172 build_string ("Quit"));
2173
2174 Fput (Qwrong_type_argument, Qerror_conditions,
6315e761 2175 Fcons (Qwrong_type_argument, error_tail));
7921925c
JB
2176 Fput (Qwrong_type_argument, Qerror_message,
2177 build_string ("Wrong type argument"));
2178
2179 Fput (Qargs_out_of_range, Qerror_conditions,
6315e761 2180 Fcons (Qargs_out_of_range, error_tail));
7921925c
JB
2181 Fput (Qargs_out_of_range, Qerror_message,
2182 build_string ("Args out of range"));
2183
2184 Fput (Qvoid_function, Qerror_conditions,
6315e761 2185 Fcons (Qvoid_function, error_tail));
7921925c
JB
2186 Fput (Qvoid_function, Qerror_message,
2187 build_string ("Symbol's function definition is void"));
2188
ffd56f97 2189 Fput (Qcyclic_function_indirection, Qerror_conditions,
6315e761 2190 Fcons (Qcyclic_function_indirection, error_tail));
ffd56f97
JB
2191 Fput (Qcyclic_function_indirection, Qerror_message,
2192 build_string ("Symbol's chain of function indirections contains a loop"));
2193
7921925c 2194 Fput (Qvoid_variable, Qerror_conditions,
6315e761 2195 Fcons (Qvoid_variable, error_tail));
7921925c
JB
2196 Fput (Qvoid_variable, Qerror_message,
2197 build_string ("Symbol's value as variable is void"));
2198
2199 Fput (Qsetting_constant, Qerror_conditions,
6315e761 2200 Fcons (Qsetting_constant, error_tail));
7921925c
JB
2201 Fput (Qsetting_constant, Qerror_message,
2202 build_string ("Attempt to set a constant symbol"));
2203
2204 Fput (Qinvalid_read_syntax, Qerror_conditions,
6315e761 2205 Fcons (Qinvalid_read_syntax, error_tail));
7921925c
JB
2206 Fput (Qinvalid_read_syntax, Qerror_message,
2207 build_string ("Invalid read syntax"));
2208
2209 Fput (Qinvalid_function, Qerror_conditions,
6315e761 2210 Fcons (Qinvalid_function, error_tail));
7921925c
JB
2211 Fput (Qinvalid_function, Qerror_message,
2212 build_string ("Invalid function"));
2213
2214 Fput (Qwrong_number_of_arguments, Qerror_conditions,
6315e761 2215 Fcons (Qwrong_number_of_arguments, error_tail));
7921925c
JB
2216 Fput (Qwrong_number_of_arguments, Qerror_message,
2217 build_string ("Wrong number of arguments"));
2218
2219 Fput (Qno_catch, Qerror_conditions,
6315e761 2220 Fcons (Qno_catch, error_tail));
7921925c
JB
2221 Fput (Qno_catch, Qerror_message,
2222 build_string ("No catch for tag"));
2223
2224 Fput (Qend_of_file, Qerror_conditions,
6315e761 2225 Fcons (Qend_of_file, error_tail));
7921925c
JB
2226 Fput (Qend_of_file, Qerror_message,
2227 build_string ("End of file during parsing"));
2228
6315e761 2229 arith_tail = Fcons (Qarith_error, error_tail);
7921925c 2230 Fput (Qarith_error, Qerror_conditions,
6315e761 2231 arith_tail);
7921925c
JB
2232 Fput (Qarith_error, Qerror_message,
2233 build_string ("Arithmetic error"));
2234
2235 Fput (Qbeginning_of_buffer, Qerror_conditions,
6315e761 2236 Fcons (Qbeginning_of_buffer, error_tail));
7921925c
JB
2237 Fput (Qbeginning_of_buffer, Qerror_message,
2238 build_string ("Beginning of buffer"));
2239
2240 Fput (Qend_of_buffer, Qerror_conditions,
6315e761 2241 Fcons (Qend_of_buffer, error_tail));
7921925c
JB
2242 Fput (Qend_of_buffer, Qerror_message,
2243 build_string ("End of buffer"));
2244
2245 Fput (Qbuffer_read_only, Qerror_conditions,
6315e761 2246 Fcons (Qbuffer_read_only, error_tail));
7921925c
JB
2247 Fput (Qbuffer_read_only, Qerror_message,
2248 build_string ("Buffer is read-only"));
2249
6315e761
RS
2250#ifdef LISP_FLOAT_TYPE
2251 Qrange_error = intern ("range-error");
2252 Qdomain_error = intern ("domain-error");
2253 Qsingularity_error = intern ("singularity-error");
2254 Qoverflow_error = intern ("overflow-error");
2255 Qunderflow_error = intern ("underflow-error");
2256
2257 Fput (Qdomain_error, Qerror_conditions,
2258 Fcons (Qdomain_error, arith_tail));
2259 Fput (Qdomain_error, Qerror_message,
2260 build_string ("Arithmetic domain error"));
2261
2262 Fput (Qrange_error, Qerror_conditions,
2263 Fcons (Qrange_error, arith_tail));
2264 Fput (Qrange_error, Qerror_message,
2265 build_string ("Arithmetic range error"));
2266
2267 Fput (Qsingularity_error, Qerror_conditions,
2268 Fcons (Qsingularity_error, Fcons (Qdomain_error, arith_tail)));
2269 Fput (Qsingularity_error, Qerror_message,
2270 build_string ("Arithmetic singularity error"));
2271
2272 Fput (Qoverflow_error, Qerror_conditions,
2273 Fcons (Qoverflow_error, Fcons (Qdomain_error, arith_tail)));
2274 Fput (Qoverflow_error, Qerror_message,
2275 build_string ("Arithmetic overflow error"));
2276
2277 Fput (Qunderflow_error, Qerror_conditions,
2278 Fcons (Qunderflow_error, Fcons (Qdomain_error, arith_tail)));
2279 Fput (Qunderflow_error, Qerror_message,
2280 build_string ("Arithmetic underflow error"));
2281
2282 staticpro (&Qrange_error);
2283 staticpro (&Qdomain_error);
2284 staticpro (&Qsingularity_error);
2285 staticpro (&Qoverflow_error);
2286 staticpro (&Qunderflow_error);
2287#endif /* LISP_FLOAT_TYPE */
2288
7921925c
JB
2289 staticpro (&Qnil);
2290 staticpro (&Qt);
2291 staticpro (&Qquote);
2292 staticpro (&Qlambda);
2293 staticpro (&Qsubr);
2294 staticpro (&Qunbound);
2295 staticpro (&Qerror_conditions);
2296 staticpro (&Qerror_message);
2297 staticpro (&Qtop_level);
2298
2299 staticpro (&Qerror);
2300 staticpro (&Qquit);
2301 staticpro (&Qwrong_type_argument);
2302 staticpro (&Qargs_out_of_range);
2303 staticpro (&Qvoid_function);
ffd56f97 2304 staticpro (&Qcyclic_function_indirection);
7921925c
JB
2305 staticpro (&Qvoid_variable);
2306 staticpro (&Qsetting_constant);
2307 staticpro (&Qinvalid_read_syntax);
2308 staticpro (&Qwrong_number_of_arguments);
2309 staticpro (&Qinvalid_function);
2310 staticpro (&Qno_catch);
2311 staticpro (&Qend_of_file);
2312 staticpro (&Qarith_error);
2313 staticpro (&Qbeginning_of_buffer);
2314 staticpro (&Qend_of_buffer);
2315 staticpro (&Qbuffer_read_only);
638b77e6 2316 staticpro (&Qmark_inactive);
7921925c
JB
2317
2318 staticpro (&Qlistp);
2319 staticpro (&Qconsp);
2320 staticpro (&Qsymbolp);
2321 staticpro (&Qintegerp);
2322 staticpro (&Qnatnump);
8e86942b 2323 staticpro (&Qwholenump);
7921925c
JB
2324 staticpro (&Qstringp);
2325 staticpro (&Qarrayp);
2326 staticpro (&Qsequencep);
2327 staticpro (&Qbufferp);
2328 staticpro (&Qvectorp);
2329 staticpro (&Qchar_or_string_p);
2330 staticpro (&Qmarkerp);
07bd8472 2331 staticpro (&Qbuffer_or_string_p);
7921925c
JB
2332 staticpro (&Qinteger_or_marker_p);
2333#ifdef LISP_FLOAT_TYPE
2334 staticpro (&Qfloatp);
464f8898
RS
2335 staticpro (&Qnumberp);
2336 staticpro (&Qnumber_or_marker_p);
7921925c
JB
2337#endif /* LISP_FLOAT_TYPE */
2338
2339 staticpro (&Qboundp);
2340 staticpro (&Qfboundp);
2341 staticpro (&Qcdr);
ab297811
RS
2342 staticpro (&Qad_advice_info);
2343 staticpro (&Qad_activate);
7921925c 2344
39bcc759
RS
2345 /* Types that type-of returns. */
2346 Qinteger = intern ("integer");
2347 Qsymbol = intern ("symbol");
2348 Qstring = intern ("string");
2349 Qcons = intern ("cons");
2350 Qmarker = intern ("marker");
2351 Qoverlay = intern ("overlay");
2352 Qfloat = intern ("float");
2353 Qwindow_configuration = intern ("window-configuration");
2354 Qprocess = intern ("process");
2355 Qwindow = intern ("window");
2356 /* Qsubr = intern ("subr"); */
2357 Qcompiled_function = intern ("compiled-function");
2358 Qbuffer = intern ("buffer");
2359 Qframe = intern ("frame");
2360 Qvector = intern ("vector");
2361
2362 staticpro (&Qinteger);
2363 staticpro (&Qsymbol);
2364 staticpro (&Qstring);
2365 staticpro (&Qcons);
2366 staticpro (&Qmarker);
2367 staticpro (&Qoverlay);
2368 staticpro (&Qfloat);
2369 staticpro (&Qwindow_configuration);
2370 staticpro (&Qprocess);
2371 staticpro (&Qwindow);
2372 /* staticpro (&Qsubr); */
2373 staticpro (&Qcompiled_function);
2374 staticpro (&Qbuffer);
2375 staticpro (&Qframe);
2376 staticpro (&Qvector);
2377
7921925c
JB
2378 defsubr (&Seq);
2379 defsubr (&Snull);
39bcc759 2380 defsubr (&Stype_of);
7921925c
JB
2381 defsubr (&Slistp);
2382 defsubr (&Snlistp);
2383 defsubr (&Sconsp);
2384 defsubr (&Satom);
2385 defsubr (&Sintegerp);
464f8898 2386 defsubr (&Sinteger_or_marker_p);
7921925c
JB
2387 defsubr (&Snumberp);
2388 defsubr (&Snumber_or_marker_p);
464f8898
RS
2389#ifdef LISP_FLOAT_TYPE
2390 defsubr (&Sfloatp);
7921925c
JB
2391#endif /* LISP_FLOAT_TYPE */
2392 defsubr (&Snatnump);
2393 defsubr (&Ssymbolp);
2394 defsubr (&Sstringp);
2395 defsubr (&Svectorp);
2396 defsubr (&Sarrayp);
2397 defsubr (&Ssequencep);
2398 defsubr (&Sbufferp);
2399 defsubr (&Smarkerp);
7921925c 2400 defsubr (&Ssubrp);
dbc4e1c1 2401 defsubr (&Sbyte_code_function_p);
7921925c
JB
2402 defsubr (&Schar_or_string_p);
2403 defsubr (&Scar);
2404 defsubr (&Scdr);
2405 defsubr (&Scar_safe);
2406 defsubr (&Scdr_safe);
2407 defsubr (&Ssetcar);
2408 defsubr (&Ssetcdr);
2409 defsubr (&Ssymbol_function);
ffd56f97 2410 defsubr (&Sindirect_function);
7921925c
JB
2411 defsubr (&Ssymbol_plist);
2412 defsubr (&Ssymbol_name);
2413 defsubr (&Smakunbound);
2414 defsubr (&Sfmakunbound);
2415 defsubr (&Sboundp);
2416 defsubr (&Sfboundp);
2417 defsubr (&Sfset);
80df38a2 2418 defsubr (&Sdefalias);
d9bcdb34 2419 defsubr (&Sdefine_function);
7921925c
JB
2420 defsubr (&Ssetplist);
2421 defsubr (&Ssymbol_value);
2422 defsubr (&Sset);
2423 defsubr (&Sdefault_boundp);
2424 defsubr (&Sdefault_value);
2425 defsubr (&Sset_default);
2426 defsubr (&Ssetq_default);
2427 defsubr (&Smake_variable_buffer_local);
2428 defsubr (&Smake_local_variable);
2429 defsubr (&Skill_local_variable);
62476adc 2430 defsubr (&Slocal_variable_p);
7921925c
JB
2431 defsubr (&Saref);
2432 defsubr (&Saset);
f2980264 2433 defsubr (&Snumber_to_string);
25e40a4b 2434 defsubr (&Sstring_to_number);
7921925c
JB
2435 defsubr (&Seqlsign);
2436 defsubr (&Slss);
2437 defsubr (&Sgtr);
2438 defsubr (&Sleq);
2439 defsubr (&Sgeq);
2440 defsubr (&Sneq);
2441 defsubr (&Szerop);
2442 defsubr (&Splus);
2443 defsubr (&Sminus);
2444 defsubr (&Stimes);
2445 defsubr (&Squo);
2446 defsubr (&Srem);
44fa9da5 2447 defsubr (&Smod);
7921925c
JB
2448 defsubr (&Smax);
2449 defsubr (&Smin);
2450 defsubr (&Slogand);
2451 defsubr (&Slogior);
2452 defsubr (&Slogxor);
2453 defsubr (&Slsh);
2454 defsubr (&Sash);
2455 defsubr (&Sadd1);
2456 defsubr (&Ssub1);
2457 defsubr (&Slognot);
8e86942b 2458
c80bd143 2459 XSYMBOL (Qwholenump)->function = XSYMBOL (Qnatnump)->function;
7921925c
JB
2460}
2461
a33ef3ab 2462SIGTYPE
7921925c
JB
2463arith_error (signo)
2464 int signo;
2465{
2466#ifdef USG
2467 /* USG systems forget handlers when they are used;
2468 must reestablish each time */
2469 signal (signo, arith_error);
2470#endif /* USG */
2471#ifdef VMS
2472 /* VMS systems are like USG. */
2473 signal (signo, arith_error);
2474#endif /* VMS */
2475#ifdef BSD4_1
2476 sigrelse (SIGFPE);
2477#else /* not BSD4_1 */
e065a56e 2478 sigsetmask (SIGEMPTYMASK);
7921925c
JB
2479#endif /* not BSD4_1 */
2480
2481 Fsignal (Qarith_error, Qnil);
2482}
2483
2484init_data ()
2485{
2486 /* Don't do this if just dumping out.
2487 We don't want to call `signal' in this case
2488 so that we don't have trouble with dumping
2489 signal-delivering routines in an inconsistent state. */
2490#ifndef CANNOT_DUMP
2491 if (!initialized)
2492 return;
2493#endif /* CANNOT_DUMP */
2494 signal (SIGFPE, arith_error);
7403b5c8 2495
7921925c
JB
2496#ifdef uts
2497 signal (SIGEMT, arith_error);
2498#endif /* uts */
2499}