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