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