(XDrawLine) [USE_MAC_IMAGE_IO]: Remove spurious return.
[bpt/emacs.git] / src / data.c
1 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 1986, 1988, 1993, 1994, 1995, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4 Free Software Foundation, Inc.
5
6 This file is part of GNU Emacs.
7
8 GNU Emacs is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3, or (at your option)
11 any later version.
12
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs; see the file COPYING. If not, write to
20 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
21 Boston, MA 02110-1301, USA. */
22
23
24 #include <config.h>
25 #include <signal.h>
26 #include <stdio.h>
27 #include "lisp.h"
28 #include "puresize.h"
29 #include "charset.h"
30 #include "buffer.h"
31 #include "keyboard.h"
32 #include "frame.h"
33 #include "syssignal.h"
34
35 #ifdef STDC_HEADERS
36 #include <float.h>
37 #endif
38
39 /* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*. */
40 #ifndef IEEE_FLOATING_POINT
41 #if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \
42 && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)
43 #define IEEE_FLOATING_POINT 1
44 #else
45 #define IEEE_FLOATING_POINT 0
46 #endif
47 #endif
48
49 /* Work around a problem that happens because math.h on hpux 7
50 defines two static variables--which, in Emacs, are not really static,
51 because `static' is defined as nothing. The problem is that they are
52 here, in floatfns.c, and in lread.c.
53 These macros prevent the name conflict. */
54 #if defined (HPUX) && !defined (HPUX8)
55 #define _MAXLDBL data_c_maxldbl
56 #define _NMAXLDBL data_c_nmaxldbl
57 #endif
58
59 #include <math.h>
60
61 #if !defined (atof)
62 extern double atof ();
63 #endif /* !atof */
64
65 Lisp_Object Qnil, Qt, Qquote, Qlambda, Qsubr, Qunbound;
66 Lisp_Object Qerror_conditions, Qerror_message, Qtop_level;
67 Lisp_Object Qerror, Qquit, Qwrong_type_argument, Qargs_out_of_range;
68 Lisp_Object Qvoid_variable, Qvoid_function, Qcyclic_function_indirection;
69 Lisp_Object Qcyclic_variable_indirection, Qcircular_list;
70 Lisp_Object Qsetting_constant, Qinvalid_read_syntax;
71 Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch;
72 Lisp_Object Qend_of_file, Qarith_error, Qmark_inactive;
73 Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
74 Lisp_Object Qtext_read_only;
75
76 Lisp_Object Qintegerp, Qnatnump, Qwholenump, Qsymbolp, Qlistp, Qconsp;
77 Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp;
78 Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp;
79 Lisp_Object Qbuffer_or_string_p, Qkeywordp;
80 Lisp_Object Qboundp, Qfboundp;
81 Lisp_Object Qchar_table_p, Qvector_or_char_table_p;
82
83 Lisp_Object Qcdr;
84 Lisp_Object Qad_advice_info, Qad_activate_internal;
85
86 Lisp_Object Qrange_error, Qdomain_error, Qsingularity_error;
87 Lisp_Object Qoverflow_error, Qunderflow_error;
88
89 Lisp_Object Qfloatp;
90 Lisp_Object Qnumberp, Qnumber_or_marker_p;
91
92 Lisp_Object Qinteger;
93 static Lisp_Object Qsymbol, Qstring, Qcons, Qmarker, Qoverlay;
94 static Lisp_Object Qfloat, Qwindow_configuration, Qwindow;
95 Lisp_Object Qprocess;
96 static Lisp_Object Qcompiled_function, Qbuffer, Qframe, Qvector;
97 static Lisp_Object Qchar_table, Qbool_vector, Qhash_table;
98 static Lisp_Object Qsubrp, Qmany, Qunevalled;
99
100 static Lisp_Object swap_in_symval_forwarding P_ ((Lisp_Object, Lisp_Object));
101
102 Lisp_Object Vmost_positive_fixnum, Vmost_negative_fixnum;
103
104
105 void
106 circular_list_error (list)
107 Lisp_Object list;
108 {
109 xsignal (Qcircular_list, list);
110 }
111
112
113 Lisp_Object
114 wrong_type_argument (predicate, value)
115 register Lisp_Object predicate, value;
116 {
117 /* If VALUE is not even a valid Lisp object, abort here
118 where we can get a backtrace showing where it came from. */
119 if ((unsigned int) XGCTYPE (value) >= Lisp_Type_Limit)
120 abort ();
121
122 xsignal2 (Qwrong_type_argument, predicate, value);
123 }
124
125 void
126 pure_write_error ()
127 {
128 error ("Attempt to modify read-only object");
129 }
130
131 void
132 args_out_of_range (a1, a2)
133 Lisp_Object a1, a2;
134 {
135 xsignal2 (Qargs_out_of_range, a1, a2);
136 }
137
138 void
139 args_out_of_range_3 (a1, a2, a3)
140 Lisp_Object a1, a2, a3;
141 {
142 xsignal3 (Qargs_out_of_range, a1, a2, a3);
143 }
144
145 /* On some machines, XINT needs a temporary location.
146 Here it is, in case it is needed. */
147
148 int sign_extend_temp;
149
150 /* On a few machines, XINT can only be done by calling this. */
151
152 int
153 sign_extend_lisp_int (num)
154 EMACS_INT num;
155 {
156 if (num & (((EMACS_INT) 1) << (VALBITS - 1)))
157 return num | (((EMACS_INT) (-1)) << VALBITS);
158 else
159 return num & ((((EMACS_INT) 1) << VALBITS) - 1);
160 }
161 \f
162 /* Data type predicates */
163
164 DEFUN ("eq", Feq, Seq, 2, 2, 0,
165 doc: /* Return t if the two args are the same Lisp object. */)
166 (obj1, obj2)
167 Lisp_Object obj1, obj2;
168 {
169 if (EQ (obj1, obj2))
170 return Qt;
171 return Qnil;
172 }
173
174 DEFUN ("null", Fnull, Snull, 1, 1, 0,
175 doc: /* Return t if OBJECT is nil. */)
176 (object)
177 Lisp_Object object;
178 {
179 if (NILP (object))
180 return Qt;
181 return Qnil;
182 }
183
184 DEFUN ("type-of", Ftype_of, Stype_of, 1, 1, 0,
185 doc: /* Return a symbol representing the type of OBJECT.
186 The symbol returned names the object's basic type;
187 for example, (type-of 1) returns `integer'. */)
188 (object)
189 Lisp_Object object;
190 {
191 switch (XGCTYPE (object))
192 {
193 case Lisp_Int:
194 return Qinteger;
195
196 case Lisp_Symbol:
197 return Qsymbol;
198
199 case Lisp_String:
200 return Qstring;
201
202 case Lisp_Cons:
203 return Qcons;
204
205 case Lisp_Misc:
206 switch (XMISCTYPE (object))
207 {
208 case Lisp_Misc_Marker:
209 return Qmarker;
210 case Lisp_Misc_Overlay:
211 return Qoverlay;
212 case Lisp_Misc_Float:
213 return Qfloat;
214 }
215 abort ();
216
217 case Lisp_Vectorlike:
218 if (GC_WINDOW_CONFIGURATIONP (object))
219 return Qwindow_configuration;
220 if (GC_PROCESSP (object))
221 return Qprocess;
222 if (GC_WINDOWP (object))
223 return Qwindow;
224 if (GC_SUBRP (object))
225 return Qsubr;
226 if (GC_COMPILEDP (object))
227 return Qcompiled_function;
228 if (GC_BUFFERP (object))
229 return Qbuffer;
230 if (GC_CHAR_TABLE_P (object))
231 return Qchar_table;
232 if (GC_BOOL_VECTOR_P (object))
233 return Qbool_vector;
234 if (GC_FRAMEP (object))
235 return Qframe;
236 if (GC_HASH_TABLE_P (object))
237 return Qhash_table;
238 return Qvector;
239
240 case Lisp_Float:
241 return Qfloat;
242
243 default:
244 abort ();
245 }
246 }
247
248 DEFUN ("consp", Fconsp, Sconsp, 1, 1, 0,
249 doc: /* Return t if OBJECT is a cons cell. */)
250 (object)
251 Lisp_Object object;
252 {
253 if (CONSP (object))
254 return Qt;
255 return Qnil;
256 }
257
258 DEFUN ("atom", Fatom, Satom, 1, 1, 0,
259 doc: /* Return t if OBJECT is not a cons cell. This includes nil. */)
260 (object)
261 Lisp_Object object;
262 {
263 if (CONSP (object))
264 return Qnil;
265 return Qt;
266 }
267
268 DEFUN ("listp", Flistp, Slistp, 1, 1, 0,
269 doc: /* Return t if OBJECT is a list, that is, a cons cell or nil.
270 Otherwise, return nil. */)
271 (object)
272 Lisp_Object object;
273 {
274 if (CONSP (object) || NILP (object))
275 return Qt;
276 return Qnil;
277 }
278
279 DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0,
280 doc: /* Return t if OBJECT is not a list. Lists include nil. */)
281 (object)
282 Lisp_Object object;
283 {
284 if (CONSP (object) || NILP (object))
285 return Qnil;
286 return Qt;
287 }
288 \f
289 DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0,
290 doc: /* Return t if OBJECT is a symbol. */)
291 (object)
292 Lisp_Object object;
293 {
294 if (SYMBOLP (object))
295 return Qt;
296 return Qnil;
297 }
298
299 /* Define this in C to avoid unnecessarily consing up the symbol
300 name. */
301 DEFUN ("keywordp", Fkeywordp, Skeywordp, 1, 1, 0,
302 doc: /* Return t if OBJECT is a keyword.
303 This means that it is a symbol with a print name beginning with `:'
304 interned in the initial obarray. */)
305 (object)
306 Lisp_Object object;
307 {
308 if (SYMBOLP (object)
309 && SREF (SYMBOL_NAME (object), 0) == ':'
310 && SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P (object))
311 return Qt;
312 return Qnil;
313 }
314
315 DEFUN ("vectorp", Fvectorp, Svectorp, 1, 1, 0,
316 doc: /* Return t if OBJECT is a vector. */)
317 (object)
318 Lisp_Object object;
319 {
320 if (VECTORP (object))
321 return Qt;
322 return Qnil;
323 }
324
325 DEFUN ("stringp", Fstringp, Sstringp, 1, 1, 0,
326 doc: /* Return t if OBJECT is a string. */)
327 (object)
328 Lisp_Object object;
329 {
330 if (STRINGP (object))
331 return Qt;
332 return Qnil;
333 }
334
335 DEFUN ("multibyte-string-p", Fmultibyte_string_p, Smultibyte_string_p,
336 1, 1, 0,
337 doc: /* Return t if OBJECT is a multibyte string. */)
338 (object)
339 Lisp_Object object;
340 {
341 if (STRINGP (object) && STRING_MULTIBYTE (object))
342 return Qt;
343 return Qnil;
344 }
345
346 DEFUN ("char-table-p", Fchar_table_p, Schar_table_p, 1, 1, 0,
347 doc: /* Return t if OBJECT is a char-table. */)
348 (object)
349 Lisp_Object object;
350 {
351 if (CHAR_TABLE_P (object))
352 return Qt;
353 return Qnil;
354 }
355
356 DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p,
357 Svector_or_char_table_p, 1, 1, 0,
358 doc: /* Return t if OBJECT is a char-table or vector. */)
359 (object)
360 Lisp_Object object;
361 {
362 if (VECTORP (object) || CHAR_TABLE_P (object))
363 return Qt;
364 return Qnil;
365 }
366
367 DEFUN ("bool-vector-p", Fbool_vector_p, Sbool_vector_p, 1, 1, 0,
368 doc: /* Return t if OBJECT is a bool-vector. */)
369 (object)
370 Lisp_Object object;
371 {
372 if (BOOL_VECTOR_P (object))
373 return Qt;
374 return Qnil;
375 }
376
377 DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0,
378 doc: /* Return t if OBJECT is an array (string or vector). */)
379 (object)
380 Lisp_Object object;
381 {
382 if (ARRAYP (object))
383 return Qt;
384 return Qnil;
385 }
386
387 DEFUN ("sequencep", Fsequencep, Ssequencep, 1, 1, 0,
388 doc: /* Return t if OBJECT is a sequence (list or array). */)
389 (object)
390 register Lisp_Object object;
391 {
392 if (CONSP (object) || NILP (object) || ARRAYP (object))
393 return Qt;
394 return Qnil;
395 }
396
397 DEFUN ("bufferp", Fbufferp, Sbufferp, 1, 1, 0,
398 doc: /* Return t if OBJECT is an editor buffer. */)
399 (object)
400 Lisp_Object object;
401 {
402 if (BUFFERP (object))
403 return Qt;
404 return Qnil;
405 }
406
407 DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0,
408 doc: /* Return t if OBJECT is a marker (editor pointer). */)
409 (object)
410 Lisp_Object object;
411 {
412 if (MARKERP (object))
413 return Qt;
414 return Qnil;
415 }
416
417 DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0,
418 doc: /* Return t if OBJECT is a built-in function. */)
419 (object)
420 Lisp_Object object;
421 {
422 if (SUBRP (object))
423 return Qt;
424 return Qnil;
425 }
426
427 DEFUN ("byte-code-function-p", Fbyte_code_function_p, Sbyte_code_function_p,
428 1, 1, 0,
429 doc: /* Return t if OBJECT is a byte-compiled function object. */)
430 (object)
431 Lisp_Object object;
432 {
433 if (COMPILEDP (object))
434 return Qt;
435 return Qnil;
436 }
437
438 DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0,
439 doc: /* Return t if OBJECT is a character (an integer) or a string. */)
440 (object)
441 register Lisp_Object object;
442 {
443 if (INTEGERP (object) || STRINGP (object))
444 return Qt;
445 return Qnil;
446 }
447 \f
448 DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0,
449 doc: /* Return t if OBJECT is an integer. */)
450 (object)
451 Lisp_Object object;
452 {
453 if (INTEGERP (object))
454 return Qt;
455 return Qnil;
456 }
457
458 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, Sinteger_or_marker_p, 1, 1, 0,
459 doc: /* Return t if OBJECT is an integer or a marker (editor pointer). */)
460 (object)
461 register Lisp_Object object;
462 {
463 if (MARKERP (object) || INTEGERP (object))
464 return Qt;
465 return Qnil;
466 }
467
468 DEFUN ("natnump", Fnatnump, Snatnump, 1, 1, 0,
469 doc: /* Return t if OBJECT is a nonnegative integer. */)
470 (object)
471 Lisp_Object object;
472 {
473 if (NATNUMP (object))
474 return Qt;
475 return Qnil;
476 }
477
478 DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0,
479 doc: /* Return t if OBJECT is a number (floating point or integer). */)
480 (object)
481 Lisp_Object object;
482 {
483 if (NUMBERP (object))
484 return Qt;
485 else
486 return Qnil;
487 }
488
489 DEFUN ("number-or-marker-p", Fnumber_or_marker_p,
490 Snumber_or_marker_p, 1, 1, 0,
491 doc: /* Return t if OBJECT is a number or a marker. */)
492 (object)
493 Lisp_Object object;
494 {
495 if (NUMBERP (object) || MARKERP (object))
496 return Qt;
497 return Qnil;
498 }
499
500 DEFUN ("floatp", Ffloatp, Sfloatp, 1, 1, 0,
501 doc: /* Return t if OBJECT is a floating point number. */)
502 (object)
503 Lisp_Object object;
504 {
505 if (FLOATP (object))
506 return Qt;
507 return Qnil;
508 }
509
510 \f
511 /* Extract and set components of lists */
512
513 DEFUN ("car", Fcar, Scar, 1, 1, 0,
514 doc: /* Return the car of LIST. If arg is nil, return nil.
515 Error if arg is not nil and not a cons cell. See also `car-safe'.
516
517 See Info node `(elisp)Cons Cells' for a discussion of related basic
518 Lisp concepts such as car, cdr, cons cell and list. */)
519 (list)
520 register Lisp_Object list;
521 {
522 return CAR (list);
523 }
524
525 DEFUN ("car-safe", Fcar_safe, Scar_safe, 1, 1, 0,
526 doc: /* Return the car of OBJECT if it is a cons cell, or else nil. */)
527 (object)
528 Lisp_Object object;
529 {
530 return CAR_SAFE (object);
531 }
532
533 DEFUN ("cdr", Fcdr, Scdr, 1, 1, 0,
534 doc: /* Return the cdr of LIST. If arg is nil, return nil.
535 Error if arg is not nil and not a cons cell. See also `cdr-safe'.
536
537 See Info node `(elisp)Cons Cells' for a discussion of related basic
538 Lisp concepts such as cdr, car, cons cell and list. */)
539 (list)
540 register Lisp_Object list;
541 {
542 return CDR (list);
543 }
544
545 DEFUN ("cdr-safe", Fcdr_safe, Scdr_safe, 1, 1, 0,
546 doc: /* Return the cdr of OBJECT if it is a cons cell, or else nil. */)
547 (object)
548 Lisp_Object object;
549 {
550 return CDR_SAFE (object);
551 }
552
553 DEFUN ("setcar", Fsetcar, Ssetcar, 2, 2, 0,
554 doc: /* Set the car of CELL to be NEWCAR. Returns NEWCAR. */)
555 (cell, newcar)
556 register Lisp_Object cell, newcar;
557 {
558 CHECK_CONS (cell);
559 CHECK_IMPURE (cell);
560 XSETCAR (cell, newcar);
561 return newcar;
562 }
563
564 DEFUN ("setcdr", Fsetcdr, Ssetcdr, 2, 2, 0,
565 doc: /* Set the cdr of CELL to be NEWCDR. Returns NEWCDR. */)
566 (cell, newcdr)
567 register Lisp_Object cell, newcdr;
568 {
569 CHECK_CONS (cell);
570 CHECK_IMPURE (cell);
571 XSETCDR (cell, newcdr);
572 return newcdr;
573 }
574 \f
575 /* Extract and set components of symbols */
576
577 DEFUN ("boundp", Fboundp, Sboundp, 1, 1, 0,
578 doc: /* Return t if SYMBOL's value is not void. */)
579 (symbol)
580 register Lisp_Object symbol;
581 {
582 Lisp_Object valcontents;
583 CHECK_SYMBOL (symbol);
584
585 valcontents = SYMBOL_VALUE (symbol);
586
587 if (BUFFER_LOCAL_VALUEP (valcontents)
588 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
589 valcontents = swap_in_symval_forwarding (symbol, valcontents);
590
591 return (EQ (valcontents, Qunbound) ? Qnil : Qt);
592 }
593
594 DEFUN ("fboundp", Ffboundp, Sfboundp, 1, 1, 0,
595 doc: /* Return t if SYMBOL's function definition is not void. */)
596 (symbol)
597 register Lisp_Object symbol;
598 {
599 CHECK_SYMBOL (symbol);
600 return (EQ (XSYMBOL (symbol)->function, Qunbound) ? Qnil : Qt);
601 }
602
603 DEFUN ("makunbound", Fmakunbound, Smakunbound, 1, 1, 0,
604 doc: /* Make SYMBOL's value be void.
605 Return SYMBOL. */)
606 (symbol)
607 register Lisp_Object symbol;
608 {
609 CHECK_SYMBOL (symbol);
610 if (SYMBOL_CONSTANT_P (symbol))
611 xsignal1 (Qsetting_constant, symbol);
612 Fset (symbol, Qunbound);
613 return symbol;
614 }
615
616 DEFUN ("fmakunbound", Ffmakunbound, Sfmakunbound, 1, 1, 0,
617 doc: /* Make SYMBOL's function definition be void.
618 Return SYMBOL. */)
619 (symbol)
620 register Lisp_Object symbol;
621 {
622 CHECK_SYMBOL (symbol);
623 if (NILP (symbol) || EQ (symbol, Qt))
624 xsignal1 (Qsetting_constant, symbol);
625 XSYMBOL (symbol)->function = Qunbound;
626 return symbol;
627 }
628
629 DEFUN ("symbol-function", Fsymbol_function, Ssymbol_function, 1, 1, 0,
630 doc: /* Return SYMBOL's function definition. Error if that is void. */)
631 (symbol)
632 register Lisp_Object symbol;
633 {
634 CHECK_SYMBOL (symbol);
635 if (!EQ (XSYMBOL (symbol)->function, Qunbound))
636 return XSYMBOL (symbol)->function;
637 xsignal1 (Qvoid_function, symbol);
638 }
639
640 DEFUN ("symbol-plist", Fsymbol_plist, Ssymbol_plist, 1, 1, 0,
641 doc: /* Return SYMBOL's property list. */)
642 (symbol)
643 register Lisp_Object symbol;
644 {
645 CHECK_SYMBOL (symbol);
646 return XSYMBOL (symbol)->plist;
647 }
648
649 DEFUN ("symbol-name", Fsymbol_name, Ssymbol_name, 1, 1, 0,
650 doc: /* Return SYMBOL's name, a string. */)
651 (symbol)
652 register Lisp_Object symbol;
653 {
654 register Lisp_Object name;
655
656 CHECK_SYMBOL (symbol);
657 name = SYMBOL_NAME (symbol);
658 return name;
659 }
660
661 DEFUN ("fset", Ffset, Sfset, 2, 2, 0,
662 doc: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION. */)
663 (symbol, definition)
664 register Lisp_Object symbol, definition;
665 {
666 register Lisp_Object function;
667
668 CHECK_SYMBOL (symbol);
669 if (NILP (symbol) || EQ (symbol, Qt))
670 xsignal1 (Qsetting_constant, symbol);
671
672 function = XSYMBOL (symbol)->function;
673
674 if (!NILP (Vautoload_queue) && !EQ (function, Qunbound))
675 Vautoload_queue = Fcons (Fcons (symbol, function), Vautoload_queue);
676
677 if (CONSP (function) && EQ (XCAR (function), Qautoload))
678 Fput (symbol, Qautoload, XCDR (function));
679
680 XSYMBOL (symbol)->function = definition;
681 /* Handle automatic advice activation */
682 if (CONSP (XSYMBOL (symbol)->plist) && !NILP (Fget (symbol, Qad_advice_info)))
683 {
684 call2 (Qad_activate_internal, symbol, Qnil);
685 definition = XSYMBOL (symbol)->function;
686 }
687 return definition;
688 }
689
690 extern Lisp_Object Qfunction_documentation;
691
692 DEFUN ("defalias", Fdefalias, Sdefalias, 2, 3, 0,
693 doc: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION.
694 Associates the function with the current load file, if any.
695 The optional third argument DOCSTRING specifies the documentation string
696 for SYMBOL; if it is omitted or nil, SYMBOL uses the documentation string
697 determined by DEFINITION. */)
698 (symbol, definition, docstring)
699 register Lisp_Object symbol, definition, docstring;
700 {
701 CHECK_SYMBOL (symbol);
702 if (CONSP (XSYMBOL (symbol)->function)
703 && EQ (XCAR (XSYMBOL (symbol)->function), Qautoload))
704 LOADHIST_ATTACH (Fcons (Qt, symbol));
705 definition = Ffset (symbol, definition);
706 LOADHIST_ATTACH (Fcons (Qdefun, symbol));
707 if (!NILP (docstring))
708 Fput (symbol, Qfunction_documentation, docstring);
709 return definition;
710 }
711
712 DEFUN ("setplist", Fsetplist, Ssetplist, 2, 2, 0,
713 doc: /* Set SYMBOL's property list to NEWPLIST, and return NEWPLIST. */)
714 (symbol, newplist)
715 register Lisp_Object symbol, newplist;
716 {
717 CHECK_SYMBOL (symbol);
718 XSYMBOL (symbol)->plist = newplist;
719 return newplist;
720 }
721
722 DEFUN ("subr-arity", Fsubr_arity, Ssubr_arity, 1, 1, 0,
723 doc: /* Return minimum and maximum number of args allowed for SUBR.
724 SUBR must be a built-in function.
725 The returned value is a pair (MIN . MAX). MIN is the minimum number
726 of args. MAX is the maximum number or the symbol `many', for a
727 function with `&rest' args, or `unevalled' for a special form. */)
728 (subr)
729 Lisp_Object subr;
730 {
731 short minargs, maxargs;
732 CHECK_SUBR (subr);
733 minargs = XSUBR (subr)->min_args;
734 maxargs = XSUBR (subr)->max_args;
735 if (maxargs == MANY)
736 return Fcons (make_number (minargs), Qmany);
737 else if (maxargs == UNEVALLED)
738 return Fcons (make_number (minargs), Qunevalled);
739 else
740 return Fcons (make_number (minargs), make_number (maxargs));
741 }
742
743 DEFUN ("subr-name", Fsubr_name, Ssubr_name, 1, 1, 0,
744 doc: /* Return name of subroutine SUBR.
745 SUBR must be a built-in function. */)
746 (subr)
747 Lisp_Object subr;
748 {
749 const char *name;
750 CHECK_SUBR (subr);
751 name = XSUBR (subr)->symbol_name;
752 return make_string (name, strlen (name));
753 }
754
755 DEFUN ("interactive-form", Finteractive_form, Sinteractive_form, 1, 1, 0,
756 doc: /* Return the interactive form of CMD or nil if none.
757 If CMD is not a command, the return value is nil.
758 Value, if non-nil, is a list \(interactive SPEC). */)
759 (cmd)
760 Lisp_Object cmd;
761 {
762 Lisp_Object fun = indirect_function (cmd);
763
764 if (SUBRP (fun))
765 {
766 if (XSUBR (fun)->prompt)
767 return list2 (Qinteractive, build_string (XSUBR (fun)->prompt));
768 }
769 else if (COMPILEDP (fun))
770 {
771 if ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE)
772 return list2 (Qinteractive, AREF (fun, COMPILED_INTERACTIVE));
773 }
774 else if (CONSP (fun))
775 {
776 Lisp_Object funcar = XCAR (fun);
777 if (EQ (funcar, Qlambda))
778 return Fassq (Qinteractive, Fcdr (XCDR (fun)));
779 else if (EQ (funcar, Qautoload))
780 {
781 struct gcpro gcpro1;
782 GCPRO1 (cmd);
783 do_autoload (fun, cmd);
784 UNGCPRO;
785 return Finteractive_form (cmd);
786 }
787 }
788 return Qnil;
789 }
790
791 \f
792 /***********************************************************************
793 Getting and Setting Values of Symbols
794 ***********************************************************************/
795
796 /* Return the symbol holding SYMBOL's value. Signal
797 `cyclic-variable-indirection' if SYMBOL's chain of variable
798 indirections contains a loop. */
799
800 Lisp_Object
801 indirect_variable (symbol)
802 Lisp_Object symbol;
803 {
804 Lisp_Object tortoise, hare;
805
806 hare = tortoise = symbol;
807
808 while (XSYMBOL (hare)->indirect_variable)
809 {
810 hare = XSYMBOL (hare)->value;
811 if (!XSYMBOL (hare)->indirect_variable)
812 break;
813
814 hare = XSYMBOL (hare)->value;
815 tortoise = XSYMBOL (tortoise)->value;
816
817 if (EQ (hare, tortoise))
818 xsignal1 (Qcyclic_variable_indirection, symbol);
819 }
820
821 return hare;
822 }
823
824
825 DEFUN ("indirect-variable", Findirect_variable, Sindirect_variable, 1, 1, 0,
826 doc: /* Return the variable at the end of OBJECT's variable chain.
827 If OBJECT is a symbol, follow all variable indirections and return the final
828 variable. If OBJECT is not a symbol, just return it.
829 Signal a cyclic-variable-indirection error if there is a loop in the
830 variable chain of symbols. */)
831 (object)
832 Lisp_Object object;
833 {
834 if (SYMBOLP (object))
835 object = indirect_variable (object);
836 return object;
837 }
838
839
840 /* Given the raw contents of a symbol value cell,
841 return the Lisp value of the symbol.
842 This does not handle buffer-local variables; use
843 swap_in_symval_forwarding for that. */
844
845 Lisp_Object
846 do_symval_forwarding (valcontents)
847 register Lisp_Object valcontents;
848 {
849 register Lisp_Object val;
850 int offset;
851 if (MISCP (valcontents))
852 switch (XMISCTYPE (valcontents))
853 {
854 case Lisp_Misc_Intfwd:
855 XSETINT (val, *XINTFWD (valcontents)->intvar);
856 return val;
857
858 case Lisp_Misc_Boolfwd:
859 return (*XBOOLFWD (valcontents)->boolvar ? Qt : Qnil);
860
861 case Lisp_Misc_Objfwd:
862 return *XOBJFWD (valcontents)->objvar;
863
864 case Lisp_Misc_Buffer_Objfwd:
865 offset = XBUFFER_OBJFWD (valcontents)->offset;
866 return PER_BUFFER_VALUE (current_buffer, offset);
867
868 case Lisp_Misc_Kboard_Objfwd:
869 offset = XKBOARD_OBJFWD (valcontents)->offset;
870 return *(Lisp_Object *)(offset + (char *)current_kboard);
871 }
872 return valcontents;
873 }
874
875 /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell
876 of SYMBOL. If SYMBOL is buffer-local, VALCONTENTS should be the
877 buffer-independent contents of the value cell: forwarded just one
878 step past the buffer-localness.
879
880 BUF non-zero means set the value in buffer BUF instead of the
881 current buffer. This only plays a role for per-buffer variables. */
882
883 void
884 store_symval_forwarding (symbol, valcontents, newval, buf)
885 Lisp_Object symbol;
886 register Lisp_Object valcontents, newval;
887 struct buffer *buf;
888 {
889 switch (SWITCH_ENUM_CAST (XTYPE (valcontents)))
890 {
891 case Lisp_Misc:
892 switch (XMISCTYPE (valcontents))
893 {
894 case Lisp_Misc_Intfwd:
895 CHECK_NUMBER (newval);
896 *XINTFWD (valcontents)->intvar = XINT (newval);
897 if (*XINTFWD (valcontents)->intvar != XINT (newval))
898 error ("Value out of range for variable `%s'",
899 SDATA (SYMBOL_NAME (symbol)));
900 break;
901
902 case Lisp_Misc_Boolfwd:
903 *XBOOLFWD (valcontents)->boolvar = NILP (newval) ? 0 : 1;
904 break;
905
906 case Lisp_Misc_Objfwd:
907 *XOBJFWD (valcontents)->objvar = newval;
908
909 /* If this variable is a default for something stored
910 in the buffer itself, such as default-fill-column,
911 find the buffers that don't have local values for it
912 and update them. */
913 if (XOBJFWD (valcontents)->objvar > (Lisp_Object *) &buffer_defaults
914 && XOBJFWD (valcontents)->objvar < (Lisp_Object *) (&buffer_defaults + 1))
915 {
916 int offset = ((char *) XOBJFWD (valcontents)->objvar
917 - (char *) &buffer_defaults);
918 int idx = PER_BUFFER_IDX (offset);
919
920 Lisp_Object tail;
921
922 if (idx <= 0)
923 break;
924
925 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
926 {
927 Lisp_Object buf;
928 struct buffer *b;
929
930 buf = Fcdr (XCAR (tail));
931 if (!BUFFERP (buf)) continue;
932 b = XBUFFER (buf);
933
934 if (! PER_BUFFER_VALUE_P (b, idx))
935 PER_BUFFER_VALUE (b, offset) = newval;
936 }
937 }
938 break;
939
940 case Lisp_Misc_Buffer_Objfwd:
941 {
942 int offset = XBUFFER_OBJFWD (valcontents)->offset;
943 Lisp_Object type;
944
945 type = PER_BUFFER_TYPE (offset);
946 if (! NILP (type) && ! NILP (newval)
947 && XTYPE (newval) != XINT (type))
948 buffer_slot_type_mismatch (offset);
949
950 if (buf == NULL)
951 buf = current_buffer;
952 PER_BUFFER_VALUE (buf, offset) = newval;
953 }
954 break;
955
956 case Lisp_Misc_Kboard_Objfwd:
957 {
958 char *base = (char *) current_kboard;
959 char *p = base + XKBOARD_OBJFWD (valcontents)->offset;
960 *(Lisp_Object *) p = newval;
961 }
962 break;
963
964 default:
965 goto def;
966 }
967 break;
968
969 default:
970 def:
971 valcontents = SYMBOL_VALUE (symbol);
972 if (BUFFER_LOCAL_VALUEP (valcontents)
973 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
974 XBUFFER_LOCAL_VALUE (valcontents)->realvalue = newval;
975 else
976 SET_SYMBOL_VALUE (symbol, newval);
977 }
978 }
979
980 /* Set up SYMBOL to refer to its global binding.
981 This makes it safe to alter the status of other bindings. */
982
983 void
984 swap_in_global_binding (symbol)
985 Lisp_Object symbol;
986 {
987 Lisp_Object valcontents, cdr;
988
989 valcontents = SYMBOL_VALUE (symbol);
990 if (!BUFFER_LOCAL_VALUEP (valcontents)
991 && !SOME_BUFFER_LOCAL_VALUEP (valcontents))
992 abort ();
993 cdr = XBUFFER_LOCAL_VALUE (valcontents)->cdr;
994
995 /* Unload the previously loaded binding. */
996 Fsetcdr (XCAR (cdr),
997 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue));
998
999 /* Select the global binding in the symbol. */
1000 XSETCAR (cdr, cdr);
1001 store_symval_forwarding (symbol, valcontents, XCDR (cdr), NULL);
1002
1003 /* Indicate that the global binding is set up now. */
1004 XBUFFER_LOCAL_VALUE (valcontents)->frame = Qnil;
1005 XBUFFER_LOCAL_VALUE (valcontents)->buffer = Qnil;
1006 XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 0;
1007 XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0;
1008 }
1009
1010 /* Set up the buffer-local symbol SYMBOL for validity in the current buffer.
1011 VALCONTENTS is the contents of its value cell,
1012 which points to a struct Lisp_Buffer_Local_Value.
1013
1014 Return the value forwarded one step past the buffer-local stage.
1015 This could be another forwarding pointer. */
1016
1017 static Lisp_Object
1018 swap_in_symval_forwarding (symbol, valcontents)
1019 Lisp_Object symbol, valcontents;
1020 {
1021 register Lisp_Object tem1;
1022
1023 tem1 = XBUFFER_LOCAL_VALUE (valcontents)->buffer;
1024
1025 if (NILP (tem1)
1026 || current_buffer != XBUFFER (tem1)
1027 || (XBUFFER_LOCAL_VALUE (valcontents)->check_frame
1028 && ! EQ (selected_frame, XBUFFER_LOCAL_VALUE (valcontents)->frame)))
1029 {
1030 if (XSYMBOL (symbol)->indirect_variable)
1031 symbol = indirect_variable (symbol);
1032
1033 /* Unload the previously loaded binding. */
1034 tem1 = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
1035 Fsetcdr (tem1,
1036 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue));
1037 /* Choose the new binding. */
1038 tem1 = assq_no_quit (symbol, current_buffer->local_var_alist);
1039 XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 0;
1040 XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0;
1041 if (NILP (tem1))
1042 {
1043 if (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
1044 tem1 = assq_no_quit (symbol, XFRAME (selected_frame)->param_alist);
1045 if (! NILP (tem1))
1046 XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 1;
1047 else
1048 tem1 = XBUFFER_LOCAL_VALUE (valcontents)->cdr;
1049 }
1050 else
1051 XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 1;
1052
1053 /* Load the new binding. */
1054 XSETCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr, tem1);
1055 XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer, current_buffer);
1056 XBUFFER_LOCAL_VALUE (valcontents)->frame = selected_frame;
1057 store_symval_forwarding (symbol,
1058 XBUFFER_LOCAL_VALUE (valcontents)->realvalue,
1059 Fcdr (tem1), NULL);
1060 }
1061 return XBUFFER_LOCAL_VALUE (valcontents)->realvalue;
1062 }
1063 \f
1064 /* Find the value of a symbol, returning Qunbound if it's not bound.
1065 This is helpful for code which just wants to get a variable's value
1066 if it has one, without signaling an error.
1067 Note that it must not be possible to quit
1068 within this function. Great care is required for this. */
1069
1070 Lisp_Object
1071 find_symbol_value (symbol)
1072 Lisp_Object symbol;
1073 {
1074 register Lisp_Object valcontents;
1075 register Lisp_Object val;
1076
1077 CHECK_SYMBOL (symbol);
1078 valcontents = SYMBOL_VALUE (symbol);
1079
1080 if (BUFFER_LOCAL_VALUEP (valcontents)
1081 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
1082 valcontents = swap_in_symval_forwarding (symbol, valcontents);
1083
1084 if (MISCP (valcontents))
1085 {
1086 switch (XMISCTYPE (valcontents))
1087 {
1088 case Lisp_Misc_Intfwd:
1089 XSETINT (val, *XINTFWD (valcontents)->intvar);
1090 return val;
1091
1092 case Lisp_Misc_Boolfwd:
1093 return (*XBOOLFWD (valcontents)->boolvar ? Qt : Qnil);
1094
1095 case Lisp_Misc_Objfwd:
1096 return *XOBJFWD (valcontents)->objvar;
1097
1098 case Lisp_Misc_Buffer_Objfwd:
1099 return PER_BUFFER_VALUE (current_buffer,
1100 XBUFFER_OBJFWD (valcontents)->offset);
1101
1102 case Lisp_Misc_Kboard_Objfwd:
1103 return *(Lisp_Object *)(XKBOARD_OBJFWD (valcontents)->offset
1104 + (char *)current_kboard);
1105 }
1106 }
1107
1108 return valcontents;
1109 }
1110
1111 DEFUN ("symbol-value", Fsymbol_value, Ssymbol_value, 1, 1, 0,
1112 doc: /* Return SYMBOL's value. Error if that is void. */)
1113 (symbol)
1114 Lisp_Object symbol;
1115 {
1116 Lisp_Object val;
1117
1118 val = find_symbol_value (symbol);
1119 if (!EQ (val, Qunbound))
1120 return val;
1121
1122 xsignal1 (Qvoid_variable, symbol);
1123 }
1124
1125 DEFUN ("set", Fset, Sset, 2, 2, 0,
1126 doc: /* Set SYMBOL's value to NEWVAL, and return NEWVAL. */)
1127 (symbol, newval)
1128 register Lisp_Object symbol, newval;
1129 {
1130 return set_internal (symbol, newval, current_buffer, 0);
1131 }
1132
1133 /* Return 1 if SYMBOL currently has a let-binding
1134 which was made in the buffer that is now current. */
1135
1136 static int
1137 let_shadows_buffer_binding_p (symbol)
1138 Lisp_Object symbol;
1139 {
1140 volatile struct specbinding *p;
1141
1142 for (p = specpdl_ptr - 1; p >= specpdl; p--)
1143 if (p->func == NULL
1144 && CONSP (p->symbol))
1145 {
1146 Lisp_Object let_bound_symbol = XCAR (p->symbol);
1147 if ((EQ (symbol, let_bound_symbol)
1148 || (XSYMBOL (let_bound_symbol)->indirect_variable
1149 && EQ (symbol, indirect_variable (let_bound_symbol))))
1150 && XBUFFER (XCDR (XCDR (p->symbol))) == current_buffer)
1151 break;
1152 }
1153
1154 return p >= specpdl;
1155 }
1156
1157 /* Store the value NEWVAL into SYMBOL.
1158 If buffer-locality is an issue, BUF specifies which buffer to use.
1159 (0 stands for the current buffer.)
1160
1161 If BINDFLAG is zero, then if this symbol is supposed to become
1162 local in every buffer where it is set, then we make it local.
1163 If BINDFLAG is nonzero, we don't do that. */
1164
1165 Lisp_Object
1166 set_internal (symbol, newval, buf, bindflag)
1167 register Lisp_Object symbol, newval;
1168 struct buffer *buf;
1169 int bindflag;
1170 {
1171 int voide = EQ (newval, Qunbound);
1172
1173 register Lisp_Object valcontents, innercontents, tem1, current_alist_element;
1174
1175 if (buf == 0)
1176 buf = current_buffer;
1177
1178 /* If restoring in a dead buffer, do nothing. */
1179 if (NILP (buf->name))
1180 return newval;
1181
1182 CHECK_SYMBOL (symbol);
1183 if (SYMBOL_CONSTANT_P (symbol)
1184 && (NILP (Fkeywordp (symbol))
1185 || !EQ (newval, SYMBOL_VALUE (symbol))))
1186 xsignal1 (Qsetting_constant, symbol);
1187
1188 innercontents = valcontents = SYMBOL_VALUE (symbol);
1189
1190 if (BUFFER_OBJFWDP (valcontents))
1191 {
1192 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1193 int idx = PER_BUFFER_IDX (offset);
1194 if (idx > 0
1195 && !bindflag
1196 && !let_shadows_buffer_binding_p (symbol))
1197 SET_PER_BUFFER_VALUE_P (buf, idx, 1);
1198 }
1199 else if (BUFFER_LOCAL_VALUEP (valcontents)
1200 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
1201 {
1202 /* valcontents is a struct Lisp_Buffer_Local_Value. */
1203 if (XSYMBOL (symbol)->indirect_variable)
1204 symbol = indirect_variable (symbol);
1205
1206 /* What binding is loaded right now? */
1207 current_alist_element
1208 = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
1209
1210 /* If the current buffer is not the buffer whose binding is
1211 loaded, or if there may be frame-local bindings and the frame
1212 isn't the right one, or if it's a Lisp_Buffer_Local_Value and
1213 the default binding is loaded, the loaded binding may be the
1214 wrong one. */
1215 if (!BUFFERP (XBUFFER_LOCAL_VALUE (valcontents)->buffer)
1216 || buf != XBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer)
1217 || (XBUFFER_LOCAL_VALUE (valcontents)->check_frame
1218 && !EQ (selected_frame, XBUFFER_LOCAL_VALUE (valcontents)->frame))
1219 || (BUFFER_LOCAL_VALUEP (valcontents)
1220 && EQ (XCAR (current_alist_element),
1221 current_alist_element)))
1222 {
1223 /* The currently loaded binding is not necessarily valid.
1224 We need to unload it, and choose a new binding. */
1225
1226 /* Write out `realvalue' to the old loaded binding. */
1227 Fsetcdr (current_alist_element,
1228 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue));
1229
1230 /* Find the new binding. */
1231 tem1 = Fassq (symbol, buf->local_var_alist);
1232 XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 1;
1233 XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 0;
1234
1235 if (NILP (tem1))
1236 {
1237 /* This buffer still sees the default value. */
1238
1239 /* If the variable is a Lisp_Some_Buffer_Local_Value,
1240 or if this is `let' rather than `set',
1241 make CURRENT-ALIST-ELEMENT point to itself,
1242 indicating that we're seeing the default value.
1243 Likewise if the variable has been let-bound
1244 in the current buffer. */
1245 if (bindflag || SOME_BUFFER_LOCAL_VALUEP (valcontents)
1246 || let_shadows_buffer_binding_p (symbol))
1247 {
1248 XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0;
1249
1250 if (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
1251 tem1 = Fassq (symbol,
1252 XFRAME (selected_frame)->param_alist);
1253
1254 if (! NILP (tem1))
1255 XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame = 1;
1256 else
1257 tem1 = XBUFFER_LOCAL_VALUE (valcontents)->cdr;
1258 }
1259 /* If it's a Lisp_Buffer_Local_Value, being set not bound,
1260 and we're not within a let that was made for this buffer,
1261 create a new buffer-local binding for the variable.
1262 That means, give this buffer a new assoc for a local value
1263 and load that binding. */
1264 else
1265 {
1266 tem1 = Fcons (symbol, XCDR (current_alist_element));
1267 buf->local_var_alist
1268 = Fcons (tem1, buf->local_var_alist);
1269 }
1270 }
1271
1272 /* Record which binding is now loaded. */
1273 XSETCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr,
1274 tem1);
1275
1276 /* Set `buffer' and `frame' slots for the binding now loaded. */
1277 XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents)->buffer, buf);
1278 XBUFFER_LOCAL_VALUE (valcontents)->frame = selected_frame;
1279 }
1280 innercontents = XBUFFER_LOCAL_VALUE (valcontents)->realvalue;
1281 }
1282
1283 /* If storing void (making the symbol void), forward only through
1284 buffer-local indicator, not through Lisp_Objfwd, etc. */
1285 if (voide)
1286 store_symval_forwarding (symbol, Qnil, newval, buf);
1287 else
1288 store_symval_forwarding (symbol, innercontents, newval, buf);
1289
1290 /* If we just set a variable whose current binding is frame-local,
1291 store the new value in the frame parameter too. */
1292
1293 if (BUFFER_LOCAL_VALUEP (valcontents)
1294 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
1295 {
1296 /* What binding is loaded right now? */
1297 current_alist_element
1298 = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
1299
1300 /* If the current buffer is not the buffer whose binding is
1301 loaded, or if there may be frame-local bindings and the frame
1302 isn't the right one, or if it's a Lisp_Buffer_Local_Value and
1303 the default binding is loaded, the loaded binding may be the
1304 wrong one. */
1305 if (XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame)
1306 XSETCDR (current_alist_element, newval);
1307 }
1308
1309 return newval;
1310 }
1311 \f
1312 /* Access or set a buffer-local symbol's default value. */
1313
1314 /* Return the default value of SYMBOL, but don't check for voidness.
1315 Return Qunbound if it is void. */
1316
1317 Lisp_Object
1318 default_value (symbol)
1319 Lisp_Object symbol;
1320 {
1321 register Lisp_Object valcontents;
1322
1323 CHECK_SYMBOL (symbol);
1324 valcontents = SYMBOL_VALUE (symbol);
1325
1326 /* For a built-in buffer-local variable, get the default value
1327 rather than letting do_symval_forwarding get the current value. */
1328 if (BUFFER_OBJFWDP (valcontents))
1329 {
1330 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1331 if (PER_BUFFER_IDX (offset) != 0)
1332 return PER_BUFFER_DEFAULT (offset);
1333 }
1334
1335 /* Handle user-created local variables. */
1336 if (BUFFER_LOCAL_VALUEP (valcontents)
1337 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
1338 {
1339 /* If var is set up for a buffer that lacks a local value for it,
1340 the current value is nominally the default value.
1341 But the `realvalue' slot may be more up to date, since
1342 ordinary setq stores just that slot. So use that. */
1343 Lisp_Object current_alist_element, alist_element_car;
1344 current_alist_element
1345 = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
1346 alist_element_car = XCAR (current_alist_element);
1347 if (EQ (alist_element_car, current_alist_element))
1348 return do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue);
1349 else
1350 return XCDR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
1351 }
1352 /* For other variables, get the current value. */
1353 return do_symval_forwarding (valcontents);
1354 }
1355
1356 DEFUN ("default-boundp", Fdefault_boundp, Sdefault_boundp, 1, 1, 0,
1357 doc: /* Return t if SYMBOL has a non-void default value.
1358 This is the value that is seen in buffers that do not have their own values
1359 for this variable. */)
1360 (symbol)
1361 Lisp_Object symbol;
1362 {
1363 register Lisp_Object value;
1364
1365 value = default_value (symbol);
1366 return (EQ (value, Qunbound) ? Qnil : Qt);
1367 }
1368
1369 DEFUN ("default-value", Fdefault_value, Sdefault_value, 1, 1, 0,
1370 doc: /* Return SYMBOL's default value.
1371 This is the value that is seen in buffers that do not have their own values
1372 for this variable. The default value is meaningful for variables with
1373 local bindings in certain buffers. */)
1374 (symbol)
1375 Lisp_Object symbol;
1376 {
1377 register Lisp_Object value;
1378
1379 value = default_value (symbol);
1380 if (!EQ (value, Qunbound))
1381 return value;
1382
1383 xsignal1 (Qvoid_variable, symbol);
1384 }
1385
1386 DEFUN ("set-default", Fset_default, Sset_default, 2, 2, 0,
1387 doc: /* Set SYMBOL's default value to VALUE. SYMBOL and VALUE are evaluated.
1388 The default value is seen in buffers that do not have their own values
1389 for this variable. */)
1390 (symbol, value)
1391 Lisp_Object symbol, value;
1392 {
1393 register Lisp_Object valcontents, current_alist_element, alist_element_buffer;
1394
1395 CHECK_SYMBOL (symbol);
1396 valcontents = SYMBOL_VALUE (symbol);
1397
1398 /* Handle variables like case-fold-search that have special slots
1399 in the buffer. Make them work apparently like Lisp_Buffer_Local_Value
1400 variables. */
1401 if (BUFFER_OBJFWDP (valcontents))
1402 {
1403 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1404 int idx = PER_BUFFER_IDX (offset);
1405
1406 PER_BUFFER_DEFAULT (offset) = value;
1407
1408 /* If this variable is not always local in all buffers,
1409 set it in the buffers that don't nominally have a local value. */
1410 if (idx > 0)
1411 {
1412 struct buffer *b;
1413
1414 for (b = all_buffers; b; b = b->next)
1415 if (!PER_BUFFER_VALUE_P (b, idx))
1416 PER_BUFFER_VALUE (b, offset) = value;
1417 }
1418 return value;
1419 }
1420
1421 if (!BUFFER_LOCAL_VALUEP (valcontents)
1422 && !SOME_BUFFER_LOCAL_VALUEP (valcontents))
1423 return Fset (symbol, value);
1424
1425 /* Store new value into the DEFAULT-VALUE slot. */
1426 XSETCDR (XBUFFER_LOCAL_VALUE (valcontents)->cdr, value);
1427
1428 /* If the default binding is now loaded, set the REALVALUE slot too. */
1429 current_alist_element
1430 = XCAR (XBUFFER_LOCAL_VALUE (valcontents)->cdr);
1431 alist_element_buffer = Fcar (current_alist_element);
1432 if (EQ (alist_element_buffer, current_alist_element))
1433 store_symval_forwarding (symbol,
1434 XBUFFER_LOCAL_VALUE (valcontents)->realvalue,
1435 value, NULL);
1436
1437 return value;
1438 }
1439
1440 DEFUN ("setq-default", Fsetq_default, Ssetq_default, 0, UNEVALLED, 0,
1441 doc: /* Set the default value of variable VAR to VALUE.
1442 VAR, the variable name, is literal (not evaluated);
1443 VALUE is an expression: it is evaluated and its value returned.
1444 The default value of a variable is seen in buffers
1445 that do not have their own values for the variable.
1446
1447 More generally, you can use multiple variables and values, as in
1448 (setq-default VAR VALUE VAR VALUE...)
1449 This sets each VAR's default value to the corresponding VALUE.
1450 The VALUE for the Nth VAR can refer to the new default values
1451 of previous VARs.
1452 usage: (setq-default [VAR VALUE]...) */)
1453 (args)
1454 Lisp_Object args;
1455 {
1456 register Lisp_Object args_left;
1457 register Lisp_Object val, symbol;
1458 struct gcpro gcpro1;
1459
1460 if (NILP (args))
1461 return Qnil;
1462
1463 args_left = args;
1464 GCPRO1 (args);
1465
1466 do
1467 {
1468 val = Feval (Fcar (Fcdr (args_left)));
1469 symbol = XCAR (args_left);
1470 Fset_default (symbol, val);
1471 args_left = Fcdr (XCDR (args_left));
1472 }
1473 while (!NILP (args_left));
1474
1475 UNGCPRO;
1476 return val;
1477 }
1478 \f
1479 /* Lisp functions for creating and removing buffer-local variables. */
1480
1481 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local, Smake_variable_buffer_local,
1482 1, 1, "vMake Variable Buffer Local: ",
1483 doc: /* Make VARIABLE become buffer-local whenever it is set.
1484 At any time, the value for the current buffer is in effect,
1485 unless the variable has never been set in this buffer,
1486 in which case the default value is in effect.
1487 Note that binding the variable with `let', or setting it while
1488 a `let'-style binding made in this buffer is in effect,
1489 does not make the variable buffer-local. Return VARIABLE.
1490
1491 In most cases it is better to use `make-local-variable',
1492 which makes a variable local in just one buffer.
1493
1494 The function `default-value' gets the default value and `set-default' sets it. */)
1495 (variable)
1496 register Lisp_Object variable;
1497 {
1498 register Lisp_Object tem, valcontents, newval;
1499
1500 CHECK_SYMBOL (variable);
1501 variable = indirect_variable (variable);
1502
1503 valcontents = SYMBOL_VALUE (variable);
1504 if (EQ (variable, Qnil) || EQ (variable, Qt) || KBOARD_OBJFWDP (valcontents))
1505 error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable)));
1506
1507 if (BUFFER_LOCAL_VALUEP (valcontents) || BUFFER_OBJFWDP (valcontents))
1508 return variable;
1509 if (SOME_BUFFER_LOCAL_VALUEP (valcontents))
1510 {
1511 XMISCTYPE (SYMBOL_VALUE (variable)) = Lisp_Misc_Buffer_Local_Value;
1512 return variable;
1513 }
1514 if (EQ (valcontents, Qunbound))
1515 SET_SYMBOL_VALUE (variable, Qnil);
1516 tem = Fcons (Qnil, Fsymbol_value (variable));
1517 XSETCAR (tem, tem);
1518 newval = allocate_misc ();
1519 XMISCTYPE (newval) = Lisp_Misc_Buffer_Local_Value;
1520 XBUFFER_LOCAL_VALUE (newval)->realvalue = SYMBOL_VALUE (variable);
1521 XBUFFER_LOCAL_VALUE (newval)->buffer = Fcurrent_buffer ();
1522 XBUFFER_LOCAL_VALUE (newval)->frame = Qnil;
1523 XBUFFER_LOCAL_VALUE (newval)->found_for_buffer = 0;
1524 XBUFFER_LOCAL_VALUE (newval)->found_for_frame = 0;
1525 XBUFFER_LOCAL_VALUE (newval)->check_frame = 0;
1526 XBUFFER_LOCAL_VALUE (newval)->cdr = tem;
1527 SET_SYMBOL_VALUE (variable, newval);
1528 return variable;
1529 }
1530
1531 DEFUN ("make-local-variable", Fmake_local_variable, Smake_local_variable,
1532 1, 1, "vMake Local Variable: ",
1533 doc: /* Make VARIABLE have a separate value in the current buffer.
1534 Other buffers will continue to share a common default value.
1535 \(The buffer-local value of VARIABLE starts out as the same value
1536 VARIABLE previously had. If VARIABLE was void, it remains void.\)
1537 Return VARIABLE.
1538
1539 If the variable is already arranged to become local when set,
1540 this function causes a local value to exist for this buffer,
1541 just as setting the variable would do.
1542
1543 This function returns VARIABLE, and therefore
1544 (set (make-local-variable 'VARIABLE) VALUE-EXP)
1545 works.
1546
1547 See also `make-variable-buffer-local'.
1548
1549 Do not use `make-local-variable' to make a hook variable buffer-local.
1550 Instead, use `add-hook' and specify t for the LOCAL argument. */)
1551 (variable)
1552 register Lisp_Object variable;
1553 {
1554 register Lisp_Object tem, valcontents;
1555
1556 CHECK_SYMBOL (variable);
1557 variable = indirect_variable (variable);
1558
1559 valcontents = SYMBOL_VALUE (variable);
1560 if (EQ (variable, Qnil) || EQ (variable, Qt) || KBOARD_OBJFWDP (valcontents))
1561 error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable)));
1562
1563 if (BUFFER_LOCAL_VALUEP (valcontents) || BUFFER_OBJFWDP (valcontents))
1564 {
1565 tem = Fboundp (variable);
1566
1567 /* Make sure the symbol has a local value in this particular buffer,
1568 by setting it to the same value it already has. */
1569 Fset (variable, (EQ (tem, Qt) ? Fsymbol_value (variable) : Qunbound));
1570 return variable;
1571 }
1572 /* Make sure symbol is set up to hold per-buffer values. */
1573 if (!SOME_BUFFER_LOCAL_VALUEP (valcontents))
1574 {
1575 Lisp_Object newval;
1576 tem = Fcons (Qnil, do_symval_forwarding (valcontents));
1577 XSETCAR (tem, tem);
1578 newval = allocate_misc ();
1579 XMISCTYPE (newval) = Lisp_Misc_Some_Buffer_Local_Value;
1580 XBUFFER_LOCAL_VALUE (newval)->realvalue = SYMBOL_VALUE (variable);
1581 XBUFFER_LOCAL_VALUE (newval)->buffer = Qnil;
1582 XBUFFER_LOCAL_VALUE (newval)->frame = Qnil;
1583 XBUFFER_LOCAL_VALUE (newval)->found_for_buffer = 0;
1584 XBUFFER_LOCAL_VALUE (newval)->found_for_frame = 0;
1585 XBUFFER_LOCAL_VALUE (newval)->check_frame = 0;
1586 XBUFFER_LOCAL_VALUE (newval)->cdr = tem;
1587 SET_SYMBOL_VALUE (variable, newval);
1588 }
1589 /* Make sure this buffer has its own value of symbol. */
1590 tem = Fassq (variable, current_buffer->local_var_alist);
1591 if (NILP (tem))
1592 {
1593 /* Swap out any local binding for some other buffer, and make
1594 sure the current value is permanently recorded, if it's the
1595 default value. */
1596 find_symbol_value (variable);
1597
1598 current_buffer->local_var_alist
1599 = Fcons (Fcons (variable, XCDR (XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (variable))->cdr)),
1600 current_buffer->local_var_alist);
1601
1602 /* Make sure symbol does not think it is set up for this buffer;
1603 force it to look once again for this buffer's value. */
1604 {
1605 Lisp_Object *pvalbuf;
1606
1607 valcontents = SYMBOL_VALUE (variable);
1608
1609 pvalbuf = &XBUFFER_LOCAL_VALUE (valcontents)->buffer;
1610 if (current_buffer == XBUFFER (*pvalbuf))
1611 *pvalbuf = Qnil;
1612 XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0;
1613 }
1614 }
1615
1616 /* If the symbol forwards into a C variable, then load the binding
1617 for this buffer now. If C code modifies the variable before we
1618 load the binding in, then that new value will clobber the default
1619 binding the next time we unload it. */
1620 valcontents = XBUFFER_LOCAL_VALUE (SYMBOL_VALUE (variable))->realvalue;
1621 if (INTFWDP (valcontents) || BOOLFWDP (valcontents) || OBJFWDP (valcontents))
1622 swap_in_symval_forwarding (variable, SYMBOL_VALUE (variable));
1623
1624 return variable;
1625 }
1626
1627 DEFUN ("kill-local-variable", Fkill_local_variable, Skill_local_variable,
1628 1, 1, "vKill Local Variable: ",
1629 doc: /* Make VARIABLE no longer have a separate value in the current buffer.
1630 From now on the default value will apply in this buffer. Return VARIABLE. */)
1631 (variable)
1632 register Lisp_Object variable;
1633 {
1634 register Lisp_Object tem, valcontents;
1635
1636 CHECK_SYMBOL (variable);
1637 variable = indirect_variable (variable);
1638
1639 valcontents = SYMBOL_VALUE (variable);
1640
1641 if (BUFFER_OBJFWDP (valcontents))
1642 {
1643 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1644 int idx = PER_BUFFER_IDX (offset);
1645
1646 if (idx > 0)
1647 {
1648 SET_PER_BUFFER_VALUE_P (current_buffer, idx, 0);
1649 PER_BUFFER_VALUE (current_buffer, offset)
1650 = PER_BUFFER_DEFAULT (offset);
1651 }
1652 return variable;
1653 }
1654
1655 if (!BUFFER_LOCAL_VALUEP (valcontents)
1656 && !SOME_BUFFER_LOCAL_VALUEP (valcontents))
1657 return variable;
1658
1659 /* Get rid of this buffer's alist element, if any. */
1660
1661 tem = Fassq (variable, current_buffer->local_var_alist);
1662 if (!NILP (tem))
1663 current_buffer->local_var_alist
1664 = Fdelq (tem, current_buffer->local_var_alist);
1665
1666 /* If the symbol is set up with the current buffer's binding
1667 loaded, recompute its value. We have to do it now, or else
1668 forwarded objects won't work right. */
1669 {
1670 Lisp_Object *pvalbuf, buf;
1671 valcontents = SYMBOL_VALUE (variable);
1672 pvalbuf = &XBUFFER_LOCAL_VALUE (valcontents)->buffer;
1673 XSETBUFFER (buf, current_buffer);
1674 if (EQ (buf, *pvalbuf))
1675 {
1676 *pvalbuf = Qnil;
1677 XBUFFER_LOCAL_VALUE (valcontents)->found_for_buffer = 0;
1678 find_symbol_value (variable);
1679 }
1680 }
1681
1682 return variable;
1683 }
1684
1685 /* Lisp functions for creating and removing buffer-local variables. */
1686
1687 DEFUN ("make-variable-frame-local", Fmake_variable_frame_local, Smake_variable_frame_local,
1688 1, 1, "vMake Variable Frame Local: ",
1689 doc: /* Enable VARIABLE to have frame-local bindings.
1690 This does not create any frame-local bindings for VARIABLE,
1691 it just makes them possible.
1692
1693 A frame-local binding is actually a frame parameter value.
1694 If a frame F has a value for the frame parameter named VARIABLE,
1695 that also acts as a frame-local binding for VARIABLE in F--
1696 provided this function has been called to enable VARIABLE
1697 to have frame-local bindings at all.
1698
1699 The only way to create a frame-local binding for VARIABLE in a frame
1700 is to set the VARIABLE frame parameter of that frame. See
1701 `modify-frame-parameters' for how to set frame parameters.
1702
1703 Buffer-local bindings take precedence over frame-local bindings. */)
1704 (variable)
1705 register Lisp_Object variable;
1706 {
1707 register Lisp_Object tem, valcontents, newval;
1708
1709 CHECK_SYMBOL (variable);
1710 variable = indirect_variable (variable);
1711
1712 valcontents = SYMBOL_VALUE (variable);
1713 if (EQ (variable, Qnil) || EQ (variable, Qt) || KBOARD_OBJFWDP (valcontents)
1714 || BUFFER_OBJFWDP (valcontents))
1715 error ("Symbol %s may not be frame-local", SDATA (SYMBOL_NAME (variable)));
1716
1717 if (BUFFER_LOCAL_VALUEP (valcontents)
1718 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
1719 {
1720 XBUFFER_LOCAL_VALUE (valcontents)->check_frame = 1;
1721 return variable;
1722 }
1723
1724 if (EQ (valcontents, Qunbound))
1725 SET_SYMBOL_VALUE (variable, Qnil);
1726 tem = Fcons (Qnil, Fsymbol_value (variable));
1727 XSETCAR (tem, tem);
1728 newval = allocate_misc ();
1729 XMISCTYPE (newval) = Lisp_Misc_Some_Buffer_Local_Value;
1730 XBUFFER_LOCAL_VALUE (newval)->realvalue = SYMBOL_VALUE (variable);
1731 XBUFFER_LOCAL_VALUE (newval)->buffer = Qnil;
1732 XBUFFER_LOCAL_VALUE (newval)->frame = Qnil;
1733 XBUFFER_LOCAL_VALUE (newval)->found_for_buffer = 0;
1734 XBUFFER_LOCAL_VALUE (newval)->found_for_frame = 0;
1735 XBUFFER_LOCAL_VALUE (newval)->check_frame = 1;
1736 XBUFFER_LOCAL_VALUE (newval)->cdr = tem;
1737 SET_SYMBOL_VALUE (variable, newval);
1738 return variable;
1739 }
1740
1741 DEFUN ("local-variable-p", Flocal_variable_p, Slocal_variable_p,
1742 1, 2, 0,
1743 doc: /* Non-nil if VARIABLE has a local binding in buffer BUFFER.
1744 BUFFER defaults to the current buffer. */)
1745 (variable, buffer)
1746 register Lisp_Object variable, buffer;
1747 {
1748 Lisp_Object valcontents;
1749 register struct buffer *buf;
1750
1751 if (NILP (buffer))
1752 buf = current_buffer;
1753 else
1754 {
1755 CHECK_BUFFER (buffer);
1756 buf = XBUFFER (buffer);
1757 }
1758
1759 CHECK_SYMBOL (variable);
1760 variable = indirect_variable (variable);
1761
1762 valcontents = SYMBOL_VALUE (variable);
1763 if (BUFFER_LOCAL_VALUEP (valcontents)
1764 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
1765 {
1766 Lisp_Object tail, elt;
1767
1768 for (tail = buf->local_var_alist; CONSP (tail); tail = XCDR (tail))
1769 {
1770 elt = XCAR (tail);
1771 if (EQ (variable, XCAR (elt)))
1772 return Qt;
1773 }
1774 }
1775 if (BUFFER_OBJFWDP (valcontents))
1776 {
1777 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1778 int idx = PER_BUFFER_IDX (offset);
1779 if (idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
1780 return Qt;
1781 }
1782 return Qnil;
1783 }
1784
1785 DEFUN ("local-variable-if-set-p", Flocal_variable_if_set_p, Slocal_variable_if_set_p,
1786 1, 2, 0,
1787 doc: /* Non-nil if VARIABLE will be local in buffer BUFFER when set there.
1788 More precisely, this means that setting the variable \(with `set' or`setq'),
1789 while it does not have a `let'-style binding that was made in BUFFER,
1790 will produce a buffer local binding. See Info node
1791 `(elisp)Creating Buffer-Local'.
1792 BUFFER defaults to the current buffer. */)
1793 (variable, buffer)
1794 register Lisp_Object variable, buffer;
1795 {
1796 Lisp_Object valcontents;
1797 register struct buffer *buf;
1798
1799 if (NILP (buffer))
1800 buf = current_buffer;
1801 else
1802 {
1803 CHECK_BUFFER (buffer);
1804 buf = XBUFFER (buffer);
1805 }
1806
1807 CHECK_SYMBOL (variable);
1808 variable = indirect_variable (variable);
1809
1810 valcontents = SYMBOL_VALUE (variable);
1811
1812 /* This means that make-variable-buffer-local was done. */
1813 if (BUFFER_LOCAL_VALUEP (valcontents))
1814 return Qt;
1815 /* All these slots become local if they are set. */
1816 if (BUFFER_OBJFWDP (valcontents))
1817 return Qt;
1818 if (SOME_BUFFER_LOCAL_VALUEP (valcontents))
1819 {
1820 Lisp_Object tail, elt;
1821 for (tail = buf->local_var_alist; CONSP (tail); tail = XCDR (tail))
1822 {
1823 elt = XCAR (tail);
1824 if (EQ (variable, XCAR (elt)))
1825 return Qt;
1826 }
1827 }
1828 return Qnil;
1829 }
1830
1831 DEFUN ("variable-binding-locus", Fvariable_binding_locus, Svariable_binding_locus,
1832 1, 1, 0,
1833 doc: /* Return a value indicating where VARIABLE's current binding comes from.
1834 If the current binding is buffer-local, the value is the current buffer.
1835 If the current binding is frame-local, the value is the selected frame.
1836 If the current binding is global (the default), the value is nil. */)
1837 (variable)
1838 register Lisp_Object variable;
1839 {
1840 Lisp_Object valcontents;
1841
1842 CHECK_SYMBOL (variable);
1843 variable = indirect_variable (variable);
1844
1845 /* Make sure the current binding is actually swapped in. */
1846 find_symbol_value (variable);
1847
1848 valcontents = XSYMBOL (variable)->value;
1849
1850 if (BUFFER_LOCAL_VALUEP (valcontents)
1851 || SOME_BUFFER_LOCAL_VALUEP (valcontents)
1852 || BUFFER_OBJFWDP (valcontents))
1853 {
1854 /* For a local variable, record both the symbol and which
1855 buffer's or frame's value we are saving. */
1856 if (!NILP (Flocal_variable_p (variable, Qnil)))
1857 return Fcurrent_buffer ();
1858 else if (!BUFFER_OBJFWDP (valcontents)
1859 && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame)
1860 return XBUFFER_LOCAL_VALUE (valcontents)->frame;
1861 }
1862
1863 return Qnil;
1864 }
1865 \f
1866 /* Find the function at the end of a chain of symbol function indirections. */
1867
1868 /* If OBJECT is a symbol, find the end of its function chain and
1869 return the value found there. If OBJECT is not a symbol, just
1870 return it. If there is a cycle in the function chain, signal a
1871 cyclic-function-indirection error.
1872
1873 This is like Findirect_function, except that it doesn't signal an
1874 error if the chain ends up unbound. */
1875 Lisp_Object
1876 indirect_function (object)
1877 register Lisp_Object object;
1878 {
1879 Lisp_Object tortoise, hare;
1880
1881 hare = tortoise = object;
1882
1883 for (;;)
1884 {
1885 if (!SYMBOLP (hare) || EQ (hare, Qunbound))
1886 break;
1887 hare = XSYMBOL (hare)->function;
1888 if (!SYMBOLP (hare) || EQ (hare, Qunbound))
1889 break;
1890 hare = XSYMBOL (hare)->function;
1891
1892 tortoise = XSYMBOL (tortoise)->function;
1893
1894 if (EQ (hare, tortoise))
1895 xsignal1 (Qcyclic_function_indirection, object);
1896 }
1897
1898 return hare;
1899 }
1900
1901 DEFUN ("indirect-function", Findirect_function, Sindirect_function, 1, 2, 0,
1902 doc: /* Return the function at the end of OBJECT's function chain.
1903 If OBJECT is not a symbol, just return it. Otherwise, follow all
1904 function indirections to find the final function binding and return it.
1905 If the final symbol in the chain is unbound, signal a void-function error.
1906 Optional arg NOERROR non-nil means to return nil instead of signalling.
1907 Signal a cyclic-function-indirection error if there is a loop in the
1908 function chain of symbols. */)
1909 (object, noerror)
1910 register Lisp_Object object;
1911 Lisp_Object noerror;
1912 {
1913 Lisp_Object result;
1914
1915 /* Optimize for no indirection. */
1916 result = object;
1917 if (SYMBOLP (result) && !EQ (result, Qunbound)
1918 && (result = XSYMBOL (result)->function, SYMBOLP (result)))
1919 result = indirect_function (result);
1920 if (!EQ (result, Qunbound))
1921 return result;
1922
1923 if (NILP (noerror))
1924 xsignal1 (Qvoid_function, object);
1925
1926 return Qnil;
1927 }
1928 \f
1929 /* Extract and set vector and string elements */
1930
1931 DEFUN ("aref", Faref, Saref, 2, 2, 0,
1932 doc: /* Return the element of ARRAY at index IDX.
1933 ARRAY may be a vector, a string, a char-table, a bool-vector,
1934 or a byte-code object. IDX starts at 0. */)
1935 (array, idx)
1936 register Lisp_Object array;
1937 Lisp_Object idx;
1938 {
1939 register int idxval;
1940
1941 CHECK_NUMBER (idx);
1942 idxval = XINT (idx);
1943 if (STRINGP (array))
1944 {
1945 int c, idxval_byte;
1946
1947 if (idxval < 0 || idxval >= SCHARS (array))
1948 args_out_of_range (array, idx);
1949 if (! STRING_MULTIBYTE (array))
1950 return make_number ((unsigned char) SREF (array, idxval));
1951 idxval_byte = string_char_to_byte (array, idxval);
1952
1953 c = STRING_CHAR (SDATA (array) + idxval_byte,
1954 SBYTES (array) - idxval_byte);
1955 return make_number (c);
1956 }
1957 else if (BOOL_VECTOR_P (array))
1958 {
1959 int val;
1960
1961 if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size)
1962 args_out_of_range (array, idx);
1963
1964 val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR];
1965 return (val & (1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR)) ? Qt : Qnil);
1966 }
1967 else if (CHAR_TABLE_P (array))
1968 {
1969 Lisp_Object val;
1970
1971 val = Qnil;
1972
1973 if (idxval < 0)
1974 args_out_of_range (array, idx);
1975 if (idxval < CHAR_TABLE_ORDINARY_SLOTS)
1976 {
1977 if (! SINGLE_BYTE_CHAR_P (idxval))
1978 args_out_of_range (array, idx);
1979 /* For ASCII and 8-bit European characters, the element is
1980 stored in the top table. */
1981 val = XCHAR_TABLE (array)->contents[idxval];
1982 if (NILP (val))
1983 {
1984 int default_slot
1985 = (idxval < 0x80 ? CHAR_TABLE_DEFAULT_SLOT_ASCII
1986 : idxval < 0xA0 ? CHAR_TABLE_DEFAULT_SLOT_8_BIT_CONTROL
1987 : CHAR_TABLE_DEFAULT_SLOT_8_BIT_GRAPHIC);
1988 val = XCHAR_TABLE (array)->contents[default_slot];
1989 }
1990 if (NILP (val))
1991 val = XCHAR_TABLE (array)->defalt;
1992 while (NILP (val)) /* Follow parents until we find some value. */
1993 {
1994 array = XCHAR_TABLE (array)->parent;
1995 if (NILP (array))
1996 return Qnil;
1997 val = XCHAR_TABLE (array)->contents[idxval];
1998 if (NILP (val))
1999 val = XCHAR_TABLE (array)->defalt;
2000 }
2001 return val;
2002 }
2003 else
2004 {
2005 int code[4], i;
2006 Lisp_Object sub_table;
2007 Lisp_Object current_default;
2008
2009 SPLIT_CHAR (idxval, code[0], code[1], code[2]);
2010 if (code[1] < 32) code[1] = -1;
2011 else if (code[2] < 32) code[2] = -1;
2012
2013 /* Here, the possible range of CODE[0] (== charset ID) is
2014 128..MAX_CHARSET. Since the top level char table contains
2015 data for multibyte characters after 256th element, we must
2016 increment CODE[0] by 128 to get a correct index. */
2017 code[0] += 128;
2018 code[3] = -1; /* anchor */
2019
2020 try_parent_char_table:
2021 current_default = XCHAR_TABLE (array)->defalt;
2022 sub_table = array;
2023 for (i = 0; code[i] >= 0; i++)
2024 {
2025 val = XCHAR_TABLE (sub_table)->contents[code[i]];
2026 if (SUB_CHAR_TABLE_P (val))
2027 {
2028 sub_table = val;
2029 if (! NILP (XCHAR_TABLE (sub_table)->defalt))
2030 current_default = XCHAR_TABLE (sub_table)->defalt;
2031 }
2032 else
2033 {
2034 if (NILP (val))
2035 val = current_default;
2036 if (NILP (val))
2037 {
2038 array = XCHAR_TABLE (array)->parent;
2039 if (!NILP (array))
2040 goto try_parent_char_table;
2041 }
2042 return val;
2043 }
2044 }
2045 /* Reaching here means IDXVAL is a generic character in
2046 which each character or a group has independent value.
2047 Essentially it's nonsense to get a value for such a
2048 generic character, but for backward compatibility, we try
2049 the default value and parent. */
2050 val = current_default;
2051 if (NILP (val))
2052 {
2053 array = XCHAR_TABLE (array)->parent;
2054 if (!NILP (array))
2055 goto try_parent_char_table;
2056 }
2057 return val;
2058 }
2059 }
2060 else
2061 {
2062 int size = 0;
2063 if (VECTORP (array))
2064 size = XVECTOR (array)->size;
2065 else if (COMPILEDP (array))
2066 size = XVECTOR (array)->size & PSEUDOVECTOR_SIZE_MASK;
2067 else
2068 wrong_type_argument (Qarrayp, array);
2069
2070 if (idxval < 0 || idxval >= size)
2071 args_out_of_range (array, idx);
2072 return XVECTOR (array)->contents[idxval];
2073 }
2074 }
2075
2076 DEFUN ("aset", Faset, Saset, 3, 3, 0,
2077 doc: /* Store into the element of ARRAY at index IDX the value NEWELT.
2078 Return NEWELT. ARRAY may be a vector, a string, a char-table or a
2079 bool-vector. IDX starts at 0. */)
2080 (array, idx, newelt)
2081 register Lisp_Object array;
2082 Lisp_Object idx, newelt;
2083 {
2084 register int idxval;
2085
2086 CHECK_NUMBER (idx);
2087 idxval = XINT (idx);
2088 CHECK_ARRAY (array, Qarrayp);
2089 CHECK_IMPURE (array);
2090
2091 if (VECTORP (array))
2092 {
2093 if (idxval < 0 || idxval >= XVECTOR (array)->size)
2094 args_out_of_range (array, idx);
2095 XVECTOR (array)->contents[idxval] = newelt;
2096 }
2097 else if (BOOL_VECTOR_P (array))
2098 {
2099 int val;
2100
2101 if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size)
2102 args_out_of_range (array, idx);
2103
2104 val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR];
2105
2106 if (! NILP (newelt))
2107 val |= 1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR);
2108 else
2109 val &= ~(1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR));
2110 XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR] = val;
2111 }
2112 else if (CHAR_TABLE_P (array))
2113 {
2114 if (idxval < 0)
2115 args_out_of_range (array, idx);
2116 if (idxval < CHAR_TABLE_ORDINARY_SLOTS)
2117 {
2118 if (! SINGLE_BYTE_CHAR_P (idxval))
2119 args_out_of_range (array, idx);
2120 XCHAR_TABLE (array)->contents[idxval] = newelt;
2121 }
2122 else
2123 {
2124 int code[4], i;
2125 Lisp_Object val;
2126
2127 SPLIT_CHAR (idxval, code[0], code[1], code[2]);
2128 if (code[1] < 32) code[1] = -1;
2129 else if (code[2] < 32) code[2] = -1;
2130
2131 /* See the comment of the corresponding part in Faref. */
2132 code[0] += 128;
2133 code[3] = -1; /* anchor */
2134 for (i = 0; code[i + 1] >= 0; i++)
2135 {
2136 val = XCHAR_TABLE (array)->contents[code[i]];
2137 if (SUB_CHAR_TABLE_P (val))
2138 array = val;
2139 else
2140 {
2141 Lisp_Object temp;
2142
2143 /* VAL is a leaf. Create a sub char table with the
2144 initial value VAL and look into it. */
2145
2146 temp = make_sub_char_table (val);
2147 XCHAR_TABLE (array)->contents[code[i]] = temp;
2148 array = temp;
2149 }
2150 }
2151 XCHAR_TABLE (array)->contents[code[i]] = newelt;
2152 }
2153 }
2154 else if (STRING_MULTIBYTE (array))
2155 {
2156 int idxval_byte, prev_bytes, new_bytes, nbytes;
2157 unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1;
2158
2159 if (idxval < 0 || idxval >= SCHARS (array))
2160 args_out_of_range (array, idx);
2161 CHECK_NUMBER (newelt);
2162
2163 nbytes = SBYTES (array);
2164
2165 idxval_byte = string_char_to_byte (array, idxval);
2166 p1 = SDATA (array) + idxval_byte;
2167 PARSE_MULTIBYTE_SEQ (p1, nbytes - idxval_byte, prev_bytes);
2168 new_bytes = CHAR_STRING (XINT (newelt), p0);
2169 if (prev_bytes != new_bytes)
2170 {
2171 /* We must relocate the string data. */
2172 int nchars = SCHARS (array);
2173 unsigned char *str;
2174 USE_SAFE_ALLOCA;
2175
2176 SAFE_ALLOCA (str, unsigned char *, nbytes);
2177 bcopy (SDATA (array), str, nbytes);
2178 allocate_string_data (XSTRING (array), nchars,
2179 nbytes + new_bytes - prev_bytes);
2180 bcopy (str, SDATA (array), idxval_byte);
2181 p1 = SDATA (array) + idxval_byte;
2182 bcopy (str + idxval_byte + prev_bytes, p1 + new_bytes,
2183 nbytes - (idxval_byte + prev_bytes));
2184 SAFE_FREE ();
2185 clear_string_char_byte_cache ();
2186 }
2187 while (new_bytes--)
2188 *p1++ = *p0++;
2189 }
2190 else
2191 {
2192 if (idxval < 0 || idxval >= SCHARS (array))
2193 args_out_of_range (array, idx);
2194 CHECK_NUMBER (newelt);
2195
2196 if (XINT (newelt) < 0 || SINGLE_BYTE_CHAR_P (XINT (newelt)))
2197 SSET (array, idxval, XINT (newelt));
2198 else
2199 {
2200 /* We must relocate the string data while converting it to
2201 multibyte. */
2202 int idxval_byte, prev_bytes, new_bytes;
2203 unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1;
2204 unsigned char *origstr = SDATA (array), *str;
2205 int nchars, nbytes;
2206 USE_SAFE_ALLOCA;
2207
2208 nchars = SCHARS (array);
2209 nbytes = idxval_byte = count_size_as_multibyte (origstr, idxval);
2210 nbytes += count_size_as_multibyte (origstr + idxval,
2211 nchars - idxval);
2212 SAFE_ALLOCA (str, unsigned char *, nbytes);
2213 copy_text (SDATA (array), str, nchars, 0, 1);
2214 PARSE_MULTIBYTE_SEQ (str + idxval_byte, nbytes - idxval_byte,
2215 prev_bytes);
2216 new_bytes = CHAR_STRING (XINT (newelt), p0);
2217 allocate_string_data (XSTRING (array), nchars,
2218 nbytes + new_bytes - prev_bytes);
2219 bcopy (str, SDATA (array), idxval_byte);
2220 p1 = SDATA (array) + idxval_byte;
2221 while (new_bytes--)
2222 *p1++ = *p0++;
2223 bcopy (str + idxval_byte + prev_bytes, p1,
2224 nbytes - (idxval_byte + prev_bytes));
2225 SAFE_FREE ();
2226 clear_string_char_byte_cache ();
2227 }
2228 }
2229
2230 return newelt;
2231 }
2232 \f
2233 /* Arithmetic functions */
2234
2235 enum comparison { equal, notequal, less, grtr, less_or_equal, grtr_or_equal };
2236
2237 Lisp_Object
2238 arithcompare (num1, num2, comparison)
2239 Lisp_Object num1, num2;
2240 enum comparison comparison;
2241 {
2242 double f1 = 0, f2 = 0;
2243 int floatp = 0;
2244
2245 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1);
2246 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2);
2247
2248 if (FLOATP (num1) || FLOATP (num2))
2249 {
2250 floatp = 1;
2251 f1 = (FLOATP (num1)) ? XFLOAT_DATA (num1) : XINT (num1);
2252 f2 = (FLOATP (num2)) ? XFLOAT_DATA (num2) : XINT (num2);
2253 }
2254
2255 switch (comparison)
2256 {
2257 case equal:
2258 if (floatp ? f1 == f2 : XINT (num1) == XINT (num2))
2259 return Qt;
2260 return Qnil;
2261
2262 case notequal:
2263 if (floatp ? f1 != f2 : XINT (num1) != XINT (num2))
2264 return Qt;
2265 return Qnil;
2266
2267 case less:
2268 if (floatp ? f1 < f2 : XINT (num1) < XINT (num2))
2269 return Qt;
2270 return Qnil;
2271
2272 case less_or_equal:
2273 if (floatp ? f1 <= f2 : XINT (num1) <= XINT (num2))
2274 return Qt;
2275 return Qnil;
2276
2277 case grtr:
2278 if (floatp ? f1 > f2 : XINT (num1) > XINT (num2))
2279 return Qt;
2280 return Qnil;
2281
2282 case grtr_or_equal:
2283 if (floatp ? f1 >= f2 : XINT (num1) >= XINT (num2))
2284 return Qt;
2285 return Qnil;
2286
2287 default:
2288 abort ();
2289 }
2290 }
2291
2292 DEFUN ("=", Feqlsign, Seqlsign, 2, 2, 0,
2293 doc: /* Return t if two args, both numbers or markers, are equal. */)
2294 (num1, num2)
2295 register Lisp_Object num1, num2;
2296 {
2297 return arithcompare (num1, num2, equal);
2298 }
2299
2300 DEFUN ("<", Flss, Slss, 2, 2, 0,
2301 doc: /* Return t if first arg is less than second arg. Both must be numbers or markers. */)
2302 (num1, num2)
2303 register Lisp_Object num1, num2;
2304 {
2305 return arithcompare (num1, num2, less);
2306 }
2307
2308 DEFUN (">", Fgtr, Sgtr, 2, 2, 0,
2309 doc: /* Return t if first arg is greater than second arg. Both must be numbers or markers. */)
2310 (num1, num2)
2311 register Lisp_Object num1, num2;
2312 {
2313 return arithcompare (num1, num2, grtr);
2314 }
2315
2316 DEFUN ("<=", Fleq, Sleq, 2, 2, 0,
2317 doc: /* Return t if first arg is less than or equal to second arg.
2318 Both must be numbers or markers. */)
2319 (num1, num2)
2320 register Lisp_Object num1, num2;
2321 {
2322 return arithcompare (num1, num2, less_or_equal);
2323 }
2324
2325 DEFUN (">=", Fgeq, Sgeq, 2, 2, 0,
2326 doc: /* Return t if first arg is greater than or equal to second arg.
2327 Both must be numbers or markers. */)
2328 (num1, num2)
2329 register Lisp_Object num1, num2;
2330 {
2331 return arithcompare (num1, num2, grtr_or_equal);
2332 }
2333
2334 DEFUN ("/=", Fneq, Sneq, 2, 2, 0,
2335 doc: /* Return t if first arg is not equal to second arg. Both must be numbers or markers. */)
2336 (num1, num2)
2337 register Lisp_Object num1, num2;
2338 {
2339 return arithcompare (num1, num2, notequal);
2340 }
2341
2342 DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0,
2343 doc: /* Return t if NUMBER is zero. */)
2344 (number)
2345 register Lisp_Object number;
2346 {
2347 CHECK_NUMBER_OR_FLOAT (number);
2348
2349 if (FLOATP (number))
2350 {
2351 if (XFLOAT_DATA (number) == 0.0)
2352 return Qt;
2353 return Qnil;
2354 }
2355
2356 if (!XINT (number))
2357 return Qt;
2358 return Qnil;
2359 }
2360 \f
2361 /* Convert between long values and pairs of Lisp integers.
2362 Note that long_to_cons returns a single Lisp integer
2363 when the value fits in one. */
2364
2365 Lisp_Object
2366 long_to_cons (i)
2367 unsigned long i;
2368 {
2369 unsigned long top = i >> 16;
2370 unsigned int bot = i & 0xFFFF;
2371 if (top == 0)
2372 return make_number (bot);
2373 if (top == (unsigned long)-1 >> 16)
2374 return Fcons (make_number (-1), make_number (bot));
2375 return Fcons (make_number (top), make_number (bot));
2376 }
2377
2378 unsigned long
2379 cons_to_long (c)
2380 Lisp_Object c;
2381 {
2382 Lisp_Object top, bot;
2383 if (INTEGERP (c))
2384 return XINT (c);
2385 top = XCAR (c);
2386 bot = XCDR (c);
2387 if (CONSP (bot))
2388 bot = XCAR (bot);
2389 return ((XINT (top) << 16) | XINT (bot));
2390 }
2391 \f
2392 DEFUN ("number-to-string", Fnumber_to_string, Snumber_to_string, 1, 1, 0,
2393 doc: /* Return the decimal representation of NUMBER as a string.
2394 Uses a minus sign if negative.
2395 NUMBER may be an integer or a floating point number. */)
2396 (number)
2397 Lisp_Object number;
2398 {
2399 char buffer[VALBITS];
2400
2401 CHECK_NUMBER_OR_FLOAT (number);
2402
2403 if (FLOATP (number))
2404 {
2405 char pigbuf[350]; /* see comments in float_to_string */
2406
2407 float_to_string (pigbuf, XFLOAT_DATA (number));
2408 return build_string (pigbuf);
2409 }
2410
2411 if (sizeof (int) == sizeof (EMACS_INT))
2412 sprintf (buffer, "%d", XINT (number));
2413 else if (sizeof (long) == sizeof (EMACS_INT))
2414 sprintf (buffer, "%ld", (long) XINT (number));
2415 else
2416 abort ();
2417 return build_string (buffer);
2418 }
2419
2420 INLINE static int
2421 digit_to_number (character, base)
2422 int character, base;
2423 {
2424 int digit;
2425
2426 if (character >= '0' && character <= '9')
2427 digit = character - '0';
2428 else if (character >= 'a' && character <= 'z')
2429 digit = character - 'a' + 10;
2430 else if (character >= 'A' && character <= 'Z')
2431 digit = character - 'A' + 10;
2432 else
2433 return -1;
2434
2435 if (digit >= base)
2436 return -1;
2437 else
2438 return digit;
2439 }
2440
2441 DEFUN ("string-to-number", Fstring_to_number, Sstring_to_number, 1, 2, 0,
2442 doc: /* Parse STRING as a decimal number and return the number.
2443 This parses both integers and floating point numbers.
2444 It ignores leading spaces and tabs.
2445
2446 If BASE, interpret STRING as a number in that base. If BASE isn't
2447 present, base 10 is used. BASE must be between 2 and 16 (inclusive).
2448 If the base used is not 10, floating point is not recognized. */)
2449 (string, base)
2450 register Lisp_Object string, base;
2451 {
2452 register unsigned char *p;
2453 register int b;
2454 int sign = 1;
2455 Lisp_Object val;
2456
2457 CHECK_STRING (string);
2458
2459 if (NILP (base))
2460 b = 10;
2461 else
2462 {
2463 CHECK_NUMBER (base);
2464 b = XINT (base);
2465 if (b < 2 || b > 16)
2466 xsignal1 (Qargs_out_of_range, base);
2467 }
2468
2469 /* Skip any whitespace at the front of the number. Some versions of
2470 atoi do this anyway, so we might as well make Emacs lisp consistent. */
2471 p = SDATA (string);
2472 while (*p == ' ' || *p == '\t')
2473 p++;
2474
2475 if (*p == '-')
2476 {
2477 sign = -1;
2478 p++;
2479 }
2480 else if (*p == '+')
2481 p++;
2482
2483 if (isfloat_string (p) && b == 10)
2484 val = make_float (sign * atof (p));
2485 else
2486 {
2487 double v = 0;
2488
2489 while (1)
2490 {
2491 int digit = digit_to_number (*p++, b);
2492 if (digit < 0)
2493 break;
2494 v = v * b + digit;
2495 }
2496
2497 val = make_fixnum_or_float (sign * v);
2498 }
2499
2500 return val;
2501 }
2502
2503 \f
2504 enum arithop
2505 {
2506 Aadd,
2507 Asub,
2508 Amult,
2509 Adiv,
2510 Alogand,
2511 Alogior,
2512 Alogxor,
2513 Amax,
2514 Amin
2515 };
2516
2517 static Lisp_Object float_arith_driver P_ ((double, int, enum arithop,
2518 int, Lisp_Object *));
2519 extern Lisp_Object fmod_float ();
2520
2521 Lisp_Object
2522 arith_driver (code, nargs, args)
2523 enum arithop code;
2524 int nargs;
2525 register Lisp_Object *args;
2526 {
2527 register Lisp_Object val;
2528 register int argnum;
2529 register EMACS_INT accum = 0;
2530 register EMACS_INT next;
2531
2532 switch (SWITCH_ENUM_CAST (code))
2533 {
2534 case Alogior:
2535 case Alogxor:
2536 case Aadd:
2537 case Asub:
2538 accum = 0;
2539 break;
2540 case Amult:
2541 accum = 1;
2542 break;
2543 case Alogand:
2544 accum = -1;
2545 break;
2546 default:
2547 break;
2548 }
2549
2550 for (argnum = 0; argnum < nargs; argnum++)
2551 {
2552 /* Using args[argnum] as argument to CHECK_NUMBER_... */
2553 val = args[argnum];
2554 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val);
2555
2556 if (FLOATP (val))
2557 return float_arith_driver ((double) accum, argnum, code,
2558 nargs, args);
2559 args[argnum] = val;
2560 next = XINT (args[argnum]);
2561 switch (SWITCH_ENUM_CAST (code))
2562 {
2563 case Aadd:
2564 accum += next;
2565 break;
2566 case Asub:
2567 accum = argnum ? accum - next : nargs == 1 ? - next : next;
2568 break;
2569 case Amult:
2570 accum *= next;
2571 break;
2572 case Adiv:
2573 if (!argnum)
2574 accum = next;
2575 else
2576 {
2577 if (next == 0)
2578 xsignal0 (Qarith_error);
2579 accum /= next;
2580 }
2581 break;
2582 case Alogand:
2583 accum &= next;
2584 break;
2585 case Alogior:
2586 accum |= next;
2587 break;
2588 case Alogxor:
2589 accum ^= next;
2590 break;
2591 case Amax:
2592 if (!argnum || next > accum)
2593 accum = next;
2594 break;
2595 case Amin:
2596 if (!argnum || next < accum)
2597 accum = next;
2598 break;
2599 }
2600 }
2601
2602 XSETINT (val, accum);
2603 return val;
2604 }
2605
2606 #undef isnan
2607 #define isnan(x) ((x) != (x))
2608
2609 static Lisp_Object
2610 float_arith_driver (accum, argnum, code, nargs, args)
2611 double accum;
2612 register int argnum;
2613 enum arithop code;
2614 int nargs;
2615 register Lisp_Object *args;
2616 {
2617 register Lisp_Object val;
2618 double next;
2619
2620 for (; argnum < nargs; argnum++)
2621 {
2622 val = args[argnum]; /* using args[argnum] as argument to CHECK_NUMBER_... */
2623 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val);
2624
2625 if (FLOATP (val))
2626 {
2627 next = XFLOAT_DATA (val);
2628 }
2629 else
2630 {
2631 args[argnum] = val; /* runs into a compiler bug. */
2632 next = XINT (args[argnum]);
2633 }
2634 switch (SWITCH_ENUM_CAST (code))
2635 {
2636 case Aadd:
2637 accum += next;
2638 break;
2639 case Asub:
2640 accum = argnum ? accum - next : nargs == 1 ? - next : next;
2641 break;
2642 case Amult:
2643 accum *= next;
2644 break;
2645 case Adiv:
2646 if (!argnum)
2647 accum = next;
2648 else
2649 {
2650 if (! IEEE_FLOATING_POINT && next == 0)
2651 xsignal0 (Qarith_error);
2652 accum /= next;
2653 }
2654 break;
2655 case Alogand:
2656 case Alogior:
2657 case Alogxor:
2658 return wrong_type_argument (Qinteger_or_marker_p, val);
2659 case Amax:
2660 if (!argnum || isnan (next) || next > accum)
2661 accum = next;
2662 break;
2663 case Amin:
2664 if (!argnum || isnan (next) || next < accum)
2665 accum = next;
2666 break;
2667 }
2668 }
2669
2670 return make_float (accum);
2671 }
2672
2673
2674 DEFUN ("+", Fplus, Splus, 0, MANY, 0,
2675 doc: /* Return sum of any number of arguments, which are numbers or markers.
2676 usage: (+ &rest NUMBERS-OR-MARKERS) */)
2677 (nargs, args)
2678 int nargs;
2679 Lisp_Object *args;
2680 {
2681 return arith_driver (Aadd, nargs, args);
2682 }
2683
2684 DEFUN ("-", Fminus, Sminus, 0, MANY, 0,
2685 doc: /* Negate number or subtract numbers or markers and return the result.
2686 With one arg, negates it. With more than one arg,
2687 subtracts all but the first from the first.
2688 usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */)
2689 (nargs, args)
2690 int nargs;
2691 Lisp_Object *args;
2692 {
2693 return arith_driver (Asub, nargs, args);
2694 }
2695
2696 DEFUN ("*", Ftimes, Stimes, 0, MANY, 0,
2697 doc: /* Return product of any number of arguments, which are numbers or markers.
2698 usage: (* &rest NUMBERS-OR-MARKERS) */)
2699 (nargs, args)
2700 int nargs;
2701 Lisp_Object *args;
2702 {
2703 return arith_driver (Amult, nargs, args);
2704 }
2705
2706 DEFUN ("/", Fquo, Squo, 2, MANY, 0,
2707 doc: /* Return first argument divided by all the remaining arguments.
2708 The arguments must be numbers or markers.
2709 usage: (/ DIVIDEND DIVISOR &rest DIVISORS) */)
2710 (nargs, args)
2711 int nargs;
2712 Lisp_Object *args;
2713 {
2714 int argnum;
2715 for (argnum = 2; argnum < nargs; argnum++)
2716 if (FLOATP (args[argnum]))
2717 return float_arith_driver (0, 0, Adiv, nargs, args);
2718 return arith_driver (Adiv, nargs, args);
2719 }
2720
2721 DEFUN ("%", Frem, Srem, 2, 2, 0,
2722 doc: /* Return remainder of X divided by Y.
2723 Both must be integers or markers. */)
2724 (x, y)
2725 register Lisp_Object x, y;
2726 {
2727 Lisp_Object val;
2728
2729 CHECK_NUMBER_COERCE_MARKER (x);
2730 CHECK_NUMBER_COERCE_MARKER (y);
2731
2732 if (XFASTINT (y) == 0)
2733 xsignal0 (Qarith_error);
2734
2735 XSETINT (val, XINT (x) % XINT (y));
2736 return val;
2737 }
2738
2739 #ifndef HAVE_FMOD
2740 double
2741 fmod (f1, f2)
2742 double f1, f2;
2743 {
2744 double r = f1;
2745
2746 if (f2 < 0.0)
2747 f2 = -f2;
2748
2749 /* If the magnitude of the result exceeds that of the divisor, or
2750 the sign of the result does not agree with that of the dividend,
2751 iterate with the reduced value. This does not yield a
2752 particularly accurate result, but at least it will be in the
2753 range promised by fmod. */
2754 do
2755 r -= f2 * floor (r / f2);
2756 while (f2 <= (r < 0 ? -r : r) || ((r < 0) != (f1 < 0) && ! isnan (r)));
2757
2758 return r;
2759 }
2760 #endif /* ! HAVE_FMOD */
2761
2762 DEFUN ("mod", Fmod, Smod, 2, 2, 0,
2763 doc: /* Return X modulo Y.
2764 The result falls between zero (inclusive) and Y (exclusive).
2765 Both X and Y must be numbers or markers. */)
2766 (x, y)
2767 register Lisp_Object x, y;
2768 {
2769 Lisp_Object val;
2770 EMACS_INT i1, i2;
2771
2772 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x);
2773 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y);
2774
2775 if (FLOATP (x) || FLOATP (y))
2776 return fmod_float (x, y);
2777
2778 i1 = XINT (x);
2779 i2 = XINT (y);
2780
2781 if (i2 == 0)
2782 xsignal0 (Qarith_error);
2783
2784 i1 %= i2;
2785
2786 /* If the "remainder" comes out with the wrong sign, fix it. */
2787 if (i2 < 0 ? i1 > 0 : i1 < 0)
2788 i1 += i2;
2789
2790 XSETINT (val, i1);
2791 return val;
2792 }
2793
2794 DEFUN ("max", Fmax, Smax, 1, MANY, 0,
2795 doc: /* Return largest of all the arguments (which must be numbers or markers).
2796 The value is always a number; markers are converted to numbers.
2797 usage: (max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2798 (nargs, args)
2799 int nargs;
2800 Lisp_Object *args;
2801 {
2802 return arith_driver (Amax, nargs, args);
2803 }
2804
2805 DEFUN ("min", Fmin, Smin, 1, MANY, 0,
2806 doc: /* Return smallest of all the arguments (which must be numbers or markers).
2807 The value is always a number; markers are converted to numbers.
2808 usage: (min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2809 (nargs, args)
2810 int nargs;
2811 Lisp_Object *args;
2812 {
2813 return arith_driver (Amin, nargs, args);
2814 }
2815
2816 DEFUN ("logand", Flogand, Slogand, 0, MANY, 0,
2817 doc: /* Return bitwise-and of all the arguments.
2818 Arguments may be integers, or markers converted to integers.
2819 usage: (logand &rest INTS-OR-MARKERS) */)
2820 (nargs, args)
2821 int nargs;
2822 Lisp_Object *args;
2823 {
2824 return arith_driver (Alogand, nargs, args);
2825 }
2826
2827 DEFUN ("logior", Flogior, Slogior, 0, MANY, 0,
2828 doc: /* Return bitwise-or of all the arguments.
2829 Arguments may be integers, or markers converted to integers.
2830 usage: (logior &rest INTS-OR-MARKERS) */)
2831 (nargs, args)
2832 int nargs;
2833 Lisp_Object *args;
2834 {
2835 return arith_driver (Alogior, nargs, args);
2836 }
2837
2838 DEFUN ("logxor", Flogxor, Slogxor, 0, MANY, 0,
2839 doc: /* Return bitwise-exclusive-or of all the arguments.
2840 Arguments may be integers, or markers converted to integers.
2841 usage: (logxor &rest INTS-OR-MARKERS) */)
2842 (nargs, args)
2843 int nargs;
2844 Lisp_Object *args;
2845 {
2846 return arith_driver (Alogxor, nargs, args);
2847 }
2848
2849 DEFUN ("ash", Fash, Sash, 2, 2, 0,
2850 doc: /* Return VALUE with its bits shifted left by COUNT.
2851 If COUNT is negative, shifting is actually to the right.
2852 In this case, the sign bit is duplicated. */)
2853 (value, count)
2854 register Lisp_Object value, count;
2855 {
2856 register Lisp_Object val;
2857
2858 CHECK_NUMBER (value);
2859 CHECK_NUMBER (count);
2860
2861 if (XINT (count) >= BITS_PER_EMACS_INT)
2862 XSETINT (val, 0);
2863 else if (XINT (count) > 0)
2864 XSETINT (val, XINT (value) << XFASTINT (count));
2865 else if (XINT (count) <= -BITS_PER_EMACS_INT)
2866 XSETINT (val, XINT (value) < 0 ? -1 : 0);
2867 else
2868 XSETINT (val, XINT (value) >> -XINT (count));
2869 return val;
2870 }
2871
2872 DEFUN ("lsh", Flsh, Slsh, 2, 2, 0,
2873 doc: /* Return VALUE with its bits shifted left by COUNT.
2874 If COUNT is negative, shifting is actually to the right.
2875 In this case, zeros are shifted in on the left. */)
2876 (value, count)
2877 register Lisp_Object value, count;
2878 {
2879 register Lisp_Object val;
2880
2881 CHECK_NUMBER (value);
2882 CHECK_NUMBER (count);
2883
2884 if (XINT (count) >= BITS_PER_EMACS_INT)
2885 XSETINT (val, 0);
2886 else if (XINT (count) > 0)
2887 XSETINT (val, (EMACS_UINT) XUINT (value) << XFASTINT (count));
2888 else if (XINT (count) <= -BITS_PER_EMACS_INT)
2889 XSETINT (val, 0);
2890 else
2891 XSETINT (val, (EMACS_UINT) XUINT (value) >> -XINT (count));
2892 return val;
2893 }
2894
2895 DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0,
2896 doc: /* Return NUMBER plus one. NUMBER may be a number or a marker.
2897 Markers are converted to integers. */)
2898 (number)
2899 register Lisp_Object number;
2900 {
2901 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number);
2902
2903 if (FLOATP (number))
2904 return (make_float (1.0 + XFLOAT_DATA (number)));
2905
2906 XSETINT (number, XINT (number) + 1);
2907 return number;
2908 }
2909
2910 DEFUN ("1-", Fsub1, Ssub1, 1, 1, 0,
2911 doc: /* Return NUMBER minus one. NUMBER may be a number or a marker.
2912 Markers are converted to integers. */)
2913 (number)
2914 register Lisp_Object number;
2915 {
2916 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number);
2917
2918 if (FLOATP (number))
2919 return (make_float (-1.0 + XFLOAT_DATA (number)));
2920
2921 XSETINT (number, XINT (number) - 1);
2922 return number;
2923 }
2924
2925 DEFUN ("lognot", Flognot, Slognot, 1, 1, 0,
2926 doc: /* Return the bitwise complement of NUMBER. NUMBER must be an integer. */)
2927 (number)
2928 register Lisp_Object number;
2929 {
2930 CHECK_NUMBER (number);
2931 XSETINT (number, ~XINT (number));
2932 return number;
2933 }
2934
2935 DEFUN ("byteorder", Fbyteorder, Sbyteorder, 0, 0, 0,
2936 doc: /* Return the byteorder for the machine.
2937 Returns 66 (ASCII uppercase B) for big endian machines or 108 (ASCII
2938 lowercase l) for small endian machines. */)
2939 ()
2940 {
2941 unsigned i = 0x04030201;
2942 int order = *(char *)&i == 1 ? 108 : 66;
2943
2944 return make_number (order);
2945 }
2946
2947
2948 \f
2949 void
2950 syms_of_data ()
2951 {
2952 Lisp_Object error_tail, arith_tail;
2953
2954 Qquote = intern ("quote");
2955 Qlambda = intern ("lambda");
2956 Qsubr = intern ("subr");
2957 Qerror_conditions = intern ("error-conditions");
2958 Qerror_message = intern ("error-message");
2959 Qtop_level = intern ("top-level");
2960
2961 Qerror = intern ("error");
2962 Qquit = intern ("quit");
2963 Qwrong_type_argument = intern ("wrong-type-argument");
2964 Qargs_out_of_range = intern ("args-out-of-range");
2965 Qvoid_function = intern ("void-function");
2966 Qcyclic_function_indirection = intern ("cyclic-function-indirection");
2967 Qcyclic_variable_indirection = intern ("cyclic-variable-indirection");
2968 Qvoid_variable = intern ("void-variable");
2969 Qsetting_constant = intern ("setting-constant");
2970 Qinvalid_read_syntax = intern ("invalid-read-syntax");
2971
2972 Qinvalid_function = intern ("invalid-function");
2973 Qwrong_number_of_arguments = intern ("wrong-number-of-arguments");
2974 Qno_catch = intern ("no-catch");
2975 Qend_of_file = intern ("end-of-file");
2976 Qarith_error = intern ("arith-error");
2977 Qbeginning_of_buffer = intern ("beginning-of-buffer");
2978 Qend_of_buffer = intern ("end-of-buffer");
2979 Qbuffer_read_only = intern ("buffer-read-only");
2980 Qtext_read_only = intern ("text-read-only");
2981 Qmark_inactive = intern ("mark-inactive");
2982
2983 Qlistp = intern ("listp");
2984 Qconsp = intern ("consp");
2985 Qsymbolp = intern ("symbolp");
2986 Qkeywordp = intern ("keywordp");
2987 Qintegerp = intern ("integerp");
2988 Qnatnump = intern ("natnump");
2989 Qwholenump = intern ("wholenump");
2990 Qstringp = intern ("stringp");
2991 Qarrayp = intern ("arrayp");
2992 Qsequencep = intern ("sequencep");
2993 Qbufferp = intern ("bufferp");
2994 Qvectorp = intern ("vectorp");
2995 Qchar_or_string_p = intern ("char-or-string-p");
2996 Qmarkerp = intern ("markerp");
2997 Qbuffer_or_string_p = intern ("buffer-or-string-p");
2998 Qinteger_or_marker_p = intern ("integer-or-marker-p");
2999 Qboundp = intern ("boundp");
3000 Qfboundp = intern ("fboundp");
3001
3002 Qfloatp = intern ("floatp");
3003 Qnumberp = intern ("numberp");
3004 Qnumber_or_marker_p = intern ("number-or-marker-p");
3005
3006 Qchar_table_p = intern ("char-table-p");
3007 Qvector_or_char_table_p = intern ("vector-or-char-table-p");
3008
3009 Qsubrp = intern ("subrp");
3010 Qunevalled = intern ("unevalled");
3011 Qmany = intern ("many");
3012
3013 Qcdr = intern ("cdr");
3014
3015 /* Handle automatic advice activation */
3016 Qad_advice_info = intern ("ad-advice-info");
3017 Qad_activate_internal = intern ("ad-activate-internal");
3018
3019 error_tail = Fcons (Qerror, Qnil);
3020
3021 /* ERROR is used as a signaler for random errors for which nothing else is right */
3022
3023 Fput (Qerror, Qerror_conditions,
3024 error_tail);
3025 Fput (Qerror, Qerror_message,
3026 build_string ("error"));
3027
3028 Fput (Qquit, Qerror_conditions,
3029 Fcons (Qquit, Qnil));
3030 Fput (Qquit, Qerror_message,
3031 build_string ("Quit"));
3032
3033 Fput (Qwrong_type_argument, Qerror_conditions,
3034 Fcons (Qwrong_type_argument, error_tail));
3035 Fput (Qwrong_type_argument, Qerror_message,
3036 build_string ("Wrong type argument"));
3037
3038 Fput (Qargs_out_of_range, Qerror_conditions,
3039 Fcons (Qargs_out_of_range, error_tail));
3040 Fput (Qargs_out_of_range, Qerror_message,
3041 build_string ("Args out of range"));
3042
3043 Fput (Qvoid_function, Qerror_conditions,
3044 Fcons (Qvoid_function, error_tail));
3045 Fput (Qvoid_function, Qerror_message,
3046 build_string ("Symbol's function definition is void"));
3047
3048 Fput (Qcyclic_function_indirection, Qerror_conditions,
3049 Fcons (Qcyclic_function_indirection, error_tail));
3050 Fput (Qcyclic_function_indirection, Qerror_message,
3051 build_string ("Symbol's chain of function indirections contains a loop"));
3052
3053 Fput (Qcyclic_variable_indirection, Qerror_conditions,
3054 Fcons (Qcyclic_variable_indirection, error_tail));
3055 Fput (Qcyclic_variable_indirection, Qerror_message,
3056 build_string ("Symbol's chain of variable indirections contains a loop"));
3057
3058 Qcircular_list = intern ("circular-list");
3059 staticpro (&Qcircular_list);
3060 Fput (Qcircular_list, Qerror_conditions,
3061 Fcons (Qcircular_list, error_tail));
3062 Fput (Qcircular_list, Qerror_message,
3063 build_string ("List contains a loop"));
3064
3065 Fput (Qvoid_variable, Qerror_conditions,
3066 Fcons (Qvoid_variable, error_tail));
3067 Fput (Qvoid_variable, Qerror_message,
3068 build_string ("Symbol's value as variable is void"));
3069
3070 Fput (Qsetting_constant, Qerror_conditions,
3071 Fcons (Qsetting_constant, error_tail));
3072 Fput (Qsetting_constant, Qerror_message,
3073 build_string ("Attempt to set a constant symbol"));
3074
3075 Fput (Qinvalid_read_syntax, Qerror_conditions,
3076 Fcons (Qinvalid_read_syntax, error_tail));
3077 Fput (Qinvalid_read_syntax, Qerror_message,
3078 build_string ("Invalid read syntax"));
3079
3080 Fput (Qinvalid_function, Qerror_conditions,
3081 Fcons (Qinvalid_function, error_tail));
3082 Fput (Qinvalid_function, Qerror_message,
3083 build_string ("Invalid function"));
3084
3085 Fput (Qwrong_number_of_arguments, Qerror_conditions,
3086 Fcons (Qwrong_number_of_arguments, error_tail));
3087 Fput (Qwrong_number_of_arguments, Qerror_message,
3088 build_string ("Wrong number of arguments"));
3089
3090 Fput (Qno_catch, Qerror_conditions,
3091 Fcons (Qno_catch, error_tail));
3092 Fput (Qno_catch, Qerror_message,
3093 build_string ("No catch for tag"));
3094
3095 Fput (Qend_of_file, Qerror_conditions,
3096 Fcons (Qend_of_file, error_tail));
3097 Fput (Qend_of_file, Qerror_message,
3098 build_string ("End of file during parsing"));
3099
3100 arith_tail = Fcons (Qarith_error, error_tail);
3101 Fput (Qarith_error, Qerror_conditions,
3102 arith_tail);
3103 Fput (Qarith_error, Qerror_message,
3104 build_string ("Arithmetic error"));
3105
3106 Fput (Qbeginning_of_buffer, Qerror_conditions,
3107 Fcons (Qbeginning_of_buffer, error_tail));
3108 Fput (Qbeginning_of_buffer, Qerror_message,
3109 build_string ("Beginning of buffer"));
3110
3111 Fput (Qend_of_buffer, Qerror_conditions,
3112 Fcons (Qend_of_buffer, error_tail));
3113 Fput (Qend_of_buffer, Qerror_message,
3114 build_string ("End of buffer"));
3115
3116 Fput (Qbuffer_read_only, Qerror_conditions,
3117 Fcons (Qbuffer_read_only, error_tail));
3118 Fput (Qbuffer_read_only, Qerror_message,
3119 build_string ("Buffer is read-only"));
3120
3121 Fput (Qtext_read_only, Qerror_conditions,
3122 Fcons (Qtext_read_only, error_tail));
3123 Fput (Qtext_read_only, Qerror_message,
3124 build_string ("Text is read-only"));
3125
3126 Qrange_error = intern ("range-error");
3127 Qdomain_error = intern ("domain-error");
3128 Qsingularity_error = intern ("singularity-error");
3129 Qoverflow_error = intern ("overflow-error");
3130 Qunderflow_error = intern ("underflow-error");
3131
3132 Fput (Qdomain_error, Qerror_conditions,
3133 Fcons (Qdomain_error, arith_tail));
3134 Fput (Qdomain_error, Qerror_message,
3135 build_string ("Arithmetic domain error"));
3136
3137 Fput (Qrange_error, Qerror_conditions,
3138 Fcons (Qrange_error, arith_tail));
3139 Fput (Qrange_error, Qerror_message,
3140 build_string ("Arithmetic range error"));
3141
3142 Fput (Qsingularity_error, Qerror_conditions,
3143 Fcons (Qsingularity_error, Fcons (Qdomain_error, arith_tail)));
3144 Fput (Qsingularity_error, Qerror_message,
3145 build_string ("Arithmetic singularity error"));
3146
3147 Fput (Qoverflow_error, Qerror_conditions,
3148 Fcons (Qoverflow_error, Fcons (Qdomain_error, arith_tail)));
3149 Fput (Qoverflow_error, Qerror_message,
3150 build_string ("Arithmetic overflow error"));
3151
3152 Fput (Qunderflow_error, Qerror_conditions,
3153 Fcons (Qunderflow_error, Fcons (Qdomain_error, arith_tail)));
3154 Fput (Qunderflow_error, Qerror_message,
3155 build_string ("Arithmetic underflow error"));
3156
3157 staticpro (&Qrange_error);
3158 staticpro (&Qdomain_error);
3159 staticpro (&Qsingularity_error);
3160 staticpro (&Qoverflow_error);
3161 staticpro (&Qunderflow_error);
3162
3163 staticpro (&Qnil);
3164 staticpro (&Qt);
3165 staticpro (&Qquote);
3166 staticpro (&Qlambda);
3167 staticpro (&Qsubr);
3168 staticpro (&Qunbound);
3169 staticpro (&Qerror_conditions);
3170 staticpro (&Qerror_message);
3171 staticpro (&Qtop_level);
3172
3173 staticpro (&Qerror);
3174 staticpro (&Qquit);
3175 staticpro (&Qwrong_type_argument);
3176 staticpro (&Qargs_out_of_range);
3177 staticpro (&Qvoid_function);
3178 staticpro (&Qcyclic_function_indirection);
3179 staticpro (&Qcyclic_variable_indirection);
3180 staticpro (&Qvoid_variable);
3181 staticpro (&Qsetting_constant);
3182 staticpro (&Qinvalid_read_syntax);
3183 staticpro (&Qwrong_number_of_arguments);
3184 staticpro (&Qinvalid_function);
3185 staticpro (&Qno_catch);
3186 staticpro (&Qend_of_file);
3187 staticpro (&Qarith_error);
3188 staticpro (&Qbeginning_of_buffer);
3189 staticpro (&Qend_of_buffer);
3190 staticpro (&Qbuffer_read_only);
3191 staticpro (&Qtext_read_only);
3192 staticpro (&Qmark_inactive);
3193
3194 staticpro (&Qlistp);
3195 staticpro (&Qconsp);
3196 staticpro (&Qsymbolp);
3197 staticpro (&Qkeywordp);
3198 staticpro (&Qintegerp);
3199 staticpro (&Qnatnump);
3200 staticpro (&Qwholenump);
3201 staticpro (&Qstringp);
3202 staticpro (&Qarrayp);
3203 staticpro (&Qsequencep);
3204 staticpro (&Qbufferp);
3205 staticpro (&Qvectorp);
3206 staticpro (&Qchar_or_string_p);
3207 staticpro (&Qmarkerp);
3208 staticpro (&Qbuffer_or_string_p);
3209 staticpro (&Qinteger_or_marker_p);
3210 staticpro (&Qfloatp);
3211 staticpro (&Qnumberp);
3212 staticpro (&Qnumber_or_marker_p);
3213 staticpro (&Qchar_table_p);
3214 staticpro (&Qvector_or_char_table_p);
3215 staticpro (&Qsubrp);
3216 staticpro (&Qmany);
3217 staticpro (&Qunevalled);
3218
3219 staticpro (&Qboundp);
3220 staticpro (&Qfboundp);
3221 staticpro (&Qcdr);
3222 staticpro (&Qad_advice_info);
3223 staticpro (&Qad_activate_internal);
3224
3225 /* Types that type-of returns. */
3226 Qinteger = intern ("integer");
3227 Qsymbol = intern ("symbol");
3228 Qstring = intern ("string");
3229 Qcons = intern ("cons");
3230 Qmarker = intern ("marker");
3231 Qoverlay = intern ("overlay");
3232 Qfloat = intern ("float");
3233 Qwindow_configuration = intern ("window-configuration");
3234 Qprocess = intern ("process");
3235 Qwindow = intern ("window");
3236 /* Qsubr = intern ("subr"); */
3237 Qcompiled_function = intern ("compiled-function");
3238 Qbuffer = intern ("buffer");
3239 Qframe = intern ("frame");
3240 Qvector = intern ("vector");
3241 Qchar_table = intern ("char-table");
3242 Qbool_vector = intern ("bool-vector");
3243 Qhash_table = intern ("hash-table");
3244
3245 staticpro (&Qinteger);
3246 staticpro (&Qsymbol);
3247 staticpro (&Qstring);
3248 staticpro (&Qcons);
3249 staticpro (&Qmarker);
3250 staticpro (&Qoverlay);
3251 staticpro (&Qfloat);
3252 staticpro (&Qwindow_configuration);
3253 staticpro (&Qprocess);
3254 staticpro (&Qwindow);
3255 /* staticpro (&Qsubr); */
3256 staticpro (&Qcompiled_function);
3257 staticpro (&Qbuffer);
3258 staticpro (&Qframe);
3259 staticpro (&Qvector);
3260 staticpro (&Qchar_table);
3261 staticpro (&Qbool_vector);
3262 staticpro (&Qhash_table);
3263
3264 defsubr (&Sindirect_variable);
3265 defsubr (&Sinteractive_form);
3266 defsubr (&Seq);
3267 defsubr (&Snull);
3268 defsubr (&Stype_of);
3269 defsubr (&Slistp);
3270 defsubr (&Snlistp);
3271 defsubr (&Sconsp);
3272 defsubr (&Satom);
3273 defsubr (&Sintegerp);
3274 defsubr (&Sinteger_or_marker_p);
3275 defsubr (&Snumberp);
3276 defsubr (&Snumber_or_marker_p);
3277 defsubr (&Sfloatp);
3278 defsubr (&Snatnump);
3279 defsubr (&Ssymbolp);
3280 defsubr (&Skeywordp);
3281 defsubr (&Sstringp);
3282 defsubr (&Smultibyte_string_p);
3283 defsubr (&Svectorp);
3284 defsubr (&Schar_table_p);
3285 defsubr (&Svector_or_char_table_p);
3286 defsubr (&Sbool_vector_p);
3287 defsubr (&Sarrayp);
3288 defsubr (&Ssequencep);
3289 defsubr (&Sbufferp);
3290 defsubr (&Smarkerp);
3291 defsubr (&Ssubrp);
3292 defsubr (&Sbyte_code_function_p);
3293 defsubr (&Schar_or_string_p);
3294 defsubr (&Scar);
3295 defsubr (&Scdr);
3296 defsubr (&Scar_safe);
3297 defsubr (&Scdr_safe);
3298 defsubr (&Ssetcar);
3299 defsubr (&Ssetcdr);
3300 defsubr (&Ssymbol_function);
3301 defsubr (&Sindirect_function);
3302 defsubr (&Ssymbol_plist);
3303 defsubr (&Ssymbol_name);
3304 defsubr (&Smakunbound);
3305 defsubr (&Sfmakunbound);
3306 defsubr (&Sboundp);
3307 defsubr (&Sfboundp);
3308 defsubr (&Sfset);
3309 defsubr (&Sdefalias);
3310 defsubr (&Ssetplist);
3311 defsubr (&Ssymbol_value);
3312 defsubr (&Sset);
3313 defsubr (&Sdefault_boundp);
3314 defsubr (&Sdefault_value);
3315 defsubr (&Sset_default);
3316 defsubr (&Ssetq_default);
3317 defsubr (&Smake_variable_buffer_local);
3318 defsubr (&Smake_local_variable);
3319 defsubr (&Skill_local_variable);
3320 defsubr (&Smake_variable_frame_local);
3321 defsubr (&Slocal_variable_p);
3322 defsubr (&Slocal_variable_if_set_p);
3323 defsubr (&Svariable_binding_locus);
3324 defsubr (&Saref);
3325 defsubr (&Saset);
3326 defsubr (&Snumber_to_string);
3327 defsubr (&Sstring_to_number);
3328 defsubr (&Seqlsign);
3329 defsubr (&Slss);
3330 defsubr (&Sgtr);
3331 defsubr (&Sleq);
3332 defsubr (&Sgeq);
3333 defsubr (&Sneq);
3334 defsubr (&Szerop);
3335 defsubr (&Splus);
3336 defsubr (&Sminus);
3337 defsubr (&Stimes);
3338 defsubr (&Squo);
3339 defsubr (&Srem);
3340 defsubr (&Smod);
3341 defsubr (&Smax);
3342 defsubr (&Smin);
3343 defsubr (&Slogand);
3344 defsubr (&Slogior);
3345 defsubr (&Slogxor);
3346 defsubr (&Slsh);
3347 defsubr (&Sash);
3348 defsubr (&Sadd1);
3349 defsubr (&Ssub1);
3350 defsubr (&Slognot);
3351 defsubr (&Sbyteorder);
3352 defsubr (&Ssubr_arity);
3353 defsubr (&Ssubr_name);
3354
3355 XSYMBOL (Qwholenump)->function = XSYMBOL (Qnatnump)->function;
3356
3357 DEFVAR_LISP ("most-positive-fixnum", &Vmost_positive_fixnum,
3358 doc: /* The largest value that is representable in a Lisp integer. */);
3359 Vmost_positive_fixnum = make_number (MOST_POSITIVE_FIXNUM);
3360
3361 DEFVAR_LISP ("most-negative-fixnum", &Vmost_negative_fixnum,
3362 doc: /* The smallest value that is representable in a Lisp integer. */);
3363 Vmost_negative_fixnum = make_number (MOST_NEGATIVE_FIXNUM);
3364 }
3365
3366 SIGTYPE
3367 arith_error (signo)
3368 int signo;
3369 {
3370 #if defined(USG) && !defined(POSIX_SIGNALS)
3371 /* USG systems forget handlers when they are used;
3372 must reestablish each time */
3373 signal (signo, arith_error);
3374 #endif /* USG */
3375 #ifdef VMS
3376 /* VMS systems are like USG. */
3377 signal (signo, arith_error);
3378 #endif /* VMS */
3379 #ifdef BSD4_1
3380 sigrelse (SIGFPE);
3381 #else /* not BSD4_1 */
3382 sigsetmask (SIGEMPTYMASK);
3383 #endif /* not BSD4_1 */
3384
3385 SIGNAL_THREAD_CHECK (signo);
3386 xsignal0 (Qarith_error);
3387 }
3388
3389 void
3390 init_data ()
3391 {
3392 /* Don't do this if just dumping out.
3393 We don't want to call `signal' in this case
3394 so that we don't have trouble with dumping
3395 signal-delivering routines in an inconsistent state. */
3396 #ifndef CANNOT_DUMP
3397 if (!initialized)
3398 return;
3399 #endif /* CANNOT_DUMP */
3400 signal (SIGFPE, arith_error);
3401
3402 #ifdef uts
3403 signal (SIGEMT, arith_error);
3404 #endif /* uts */
3405 }
3406
3407 /* arch-tag: 25879798-b84d-479a-9c89-7d148e2109f7
3408 (do not change this comment) */