Avoid a double symval forwarding
[emacs.git] / src / data.c
blob43257cb8de34380f43dcb9e441d1e583c8aafc66
1 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 1986, 1988, 1993, 1994, 1995, 1997, 1998, 1999, 2000,
3 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22 #include <config.h>
23 #include <signal.h>
24 #include <stdio.h>
25 #include <setjmp.h>
26 #include "lisp.h"
27 #include "puresize.h"
28 #include "character.h"
29 #include "buffer.h"
30 #include "keyboard.h"
31 #include "frame.h"
32 #include "syssignal.h"
33 #include "termhooks.h" /* For FRAME_KBOARD reference in y-or-n-p. */
34 #include "font.h"
36 #ifdef STDC_HEADERS
37 #include <float.h>
38 #endif
40 /* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*. */
41 #ifndef IEEE_FLOATING_POINT
42 #if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \
43 && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)
44 #define IEEE_FLOATING_POINT 1
45 #else
46 #define IEEE_FLOATING_POINT 0
47 #endif
48 #endif
50 #include <math.h>
52 #if !defined (atof)
53 extern double atof ();
54 #endif /* !atof */
56 Lisp_Object Qnil, Qt, Qquote, Qlambda, Qsubr, Qunbound, Qthread_local_mark;
57 Lisp_Object Qerror_conditions, Qerror_message, Qtop_level;
58 Lisp_Object Qerror, Qquit, Qwrong_type_argument, Qargs_out_of_range;
59 Lisp_Object Qvoid_variable, Qvoid_function, Qcyclic_function_indirection;
60 Lisp_Object Qcyclic_variable_indirection, Qcircular_list;
61 Lisp_Object Qsetting_constant, Qinvalid_read_syntax;
62 Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch;
63 Lisp_Object Qend_of_file, Qarith_error, Qmark_inactive;
64 Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
65 Lisp_Object Qtext_read_only;
67 Lisp_Object Qintegerp, Qnatnump, Qwholenump, Qsymbolp, Qlistp, Qconsp;
68 Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp;
69 Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp;
70 Lisp_Object Qbuffer_or_string_p, Qkeywordp;
71 Lisp_Object Qboundp, Qfboundp;
72 Lisp_Object Qchar_table_p, Qvector_or_char_table_p;
74 Lisp_Object Qcdr;
75 Lisp_Object Qad_advice_info, Qad_activate_internal;
77 Lisp_Object Qrange_error, Qdomain_error, Qsingularity_error;
78 Lisp_Object Qoverflow_error, Qunderflow_error;
80 Lisp_Object Qfloatp;
81 Lisp_Object Qnumberp, Qnumber_or_marker_p;
83 Lisp_Object Qinteger;
84 static Lisp_Object Qsymbol, Qstring, Qcons, Qmarker, Qoverlay;
85 static Lisp_Object Qfloat, Qwindow_configuration, Qwindow;
86 Lisp_Object Qprocess;
87 static Lisp_Object Qcompiled_function, Qbuffer, Qframe, Qvector;
88 static Lisp_Object Qchar_table, Qbool_vector, Qhash_table;
89 static Lisp_Object Qsubrp, Qmany, Qunevalled;
90 Lisp_Object Qfont_spec, Qfont_entity, Qfont_object;
92 Lisp_Object Qinteractive_form;
94 static Lisp_Object swap_in_symval_forwarding P_ ((Lisp_Object, Lisp_Object));
96 Lisp_Object impl_Vmost_positive_fixnum, impl_Vmost_negative_fixnum;
98 Lisp_Object *
99 blocal_get_thread_data (struct Lisp_Buffer_Local_Value *l)
101 Lisp_Object ret = assq_no_quit (get_current_thread (), l->thread_data);
102 if (NILP (ret))
104 Lisp_Object len, tem, parent = XCDR (XCAR (l->thread_data));
105 XSETFASTINT (len, 4);
106 ret = Fmake_vector (len, Qnil);
108 /* FIXME: use the parent, not the first element. (or not?) */
109 XSETFASTINT (AREF (ret, 0), AREF (parent, 0));
110 BLOCAL_BUFFER_VEC (ret) = BLOCAL_BUFFER_VEC (parent);
111 BLOCAL_FRAME_VEC (ret) = BLOCAL_FRAME_VEC (parent);
112 tem = Fcons (Qnil, Qnil);
113 XSETCAR (tem, tem);
114 BLOCAL_CDR_VEC (ret) = tem;
115 ret = Fcons (get_current_thread (), ret);
116 l->thread_data = Fcons (ret, l->thread_data);
117 XTHREADLOCAL (l->realvalue)->thread_alist =
118 Fcons (Fcons (get_current_thread (), Qnil),
119 XTHREADLOCAL (l->realvalue)->thread_alist);
122 return &XCDR_AS_LVALUE (ret);
125 void
126 blocal_set_thread_data (struct Lisp_Buffer_Local_Value *l, Lisp_Object obj)
128 if (! NILP (l->thread_data))
129 abort ();
131 l->thread_data = Fcons (Fcons (get_current_thread (), obj), Qnil);
134 void
135 circular_list_error (list)
136 Lisp_Object list;
138 xsignal (Qcircular_list, list);
142 Lisp_Object
143 wrong_type_argument (predicate, value)
144 register Lisp_Object predicate, value;
146 /* If VALUE is not even a valid Lisp object, we'd want to abort here
147 where we can get a backtrace showing where it came from. We used
148 to try and do that by checking the tagbits, but nowadays all
149 tagbits are potentially valid. */
150 /* if ((unsigned int) XTYPE (value) >= Lisp_Type_Limit)
151 * abort (); */
153 xsignal2 (Qwrong_type_argument, predicate, value);
156 void
157 pure_write_error ()
159 error ("Attempt to modify read-only object");
162 void
163 args_out_of_range (a1, a2)
164 Lisp_Object a1, a2;
166 xsignal2 (Qargs_out_of_range, a1, a2);
169 void
170 args_out_of_range_3 (a1, a2, a3)
171 Lisp_Object a1, a2, a3;
173 xsignal3 (Qargs_out_of_range, a1, a2, a3);
176 /* On some machines, XINT needs a temporary location.
177 Here it is, in case it is needed. */
179 int sign_extend_temp;
181 /* On a few machines, XINT can only be done by calling this. */
184 sign_extend_lisp_int (num)
185 EMACS_INT num;
187 if (num & (((EMACS_INT) 1) << (VALBITS - 1)))
188 return num | (((EMACS_INT) (-1)) << VALBITS);
189 else
190 return num & ((((EMACS_INT) 1) << VALBITS) - 1);
193 /* Data type predicates */
195 DEFUN ("eq", Feq, Seq, 2, 2, 0,
196 doc: /* Return t if the two args are the same Lisp object. */)
197 (obj1, obj2)
198 Lisp_Object obj1, obj2;
200 if (EQ (obj1, obj2))
201 return Qt;
202 return Qnil;
205 DEFUN ("null", Fnull, Snull, 1, 1, 0,
206 doc: /* Return t if OBJECT is nil. */)
207 (object)
208 Lisp_Object object;
210 if (NILP (object))
211 return Qt;
212 return Qnil;
215 DEFUN ("type-of", Ftype_of, Stype_of, 1, 1, 0,
216 doc: /* Return a symbol representing the type of OBJECT.
217 The symbol returned names the object's basic type;
218 for example, (type-of 1) returns `integer'. */)
219 (object)
220 Lisp_Object object;
222 switch (XTYPE (object))
224 case_Lisp_Int:
225 return Qinteger;
227 case Lisp_Symbol:
228 return Qsymbol;
230 case Lisp_String:
231 return Qstring;
233 case Lisp_Cons:
234 return Qcons;
236 case Lisp_Misc:
237 switch (XMISCTYPE (object))
239 case Lisp_Misc_Marker:
240 return Qmarker;
241 case Lisp_Misc_Overlay:
242 return Qoverlay;
243 case Lisp_Misc_Float:
244 return Qfloat;
246 abort ();
248 case Lisp_Vectorlike:
249 if (WINDOW_CONFIGURATIONP (object))
250 return Qwindow_configuration;
251 if (PROCESSP (object))
252 return Qprocess;
253 if (WINDOWP (object))
254 return Qwindow;
255 if (SUBRP (object))
256 return Qsubr;
257 if (COMPILEDP (object))
258 return Qcompiled_function;
259 if (BUFFERP (object))
260 return Qbuffer;
261 if (CHAR_TABLE_P (object))
262 return Qchar_table;
263 if (BOOL_VECTOR_P (object))
264 return Qbool_vector;
265 if (FRAMEP (object))
266 return Qframe;
267 if (HASH_TABLE_P (object))
268 return Qhash_table;
269 if (FONT_SPEC_P (object))
270 return Qfont_spec;
271 if (FONT_ENTITY_P (object))
272 return Qfont_entity;
273 if (FONT_OBJECT_P (object))
274 return Qfont_object;
275 return Qvector;
277 case Lisp_Float:
278 return Qfloat;
280 default:
281 abort ();
285 DEFUN ("consp", Fconsp, Sconsp, 1, 1, 0,
286 doc: /* Return t if OBJECT is a cons cell. */)
287 (object)
288 Lisp_Object object;
290 if (CONSP (object))
291 return Qt;
292 return Qnil;
295 DEFUN ("atom", Fatom, Satom, 1, 1, 0,
296 doc: /* Return t if OBJECT is not a cons cell. This includes nil. */)
297 (object)
298 Lisp_Object object;
300 if (CONSP (object))
301 return Qnil;
302 return Qt;
305 DEFUN ("listp", Flistp, Slistp, 1, 1, 0,
306 doc: /* Return t if OBJECT is a list, that is, a cons cell or nil.
307 Otherwise, return nil. */)
308 (object)
309 Lisp_Object object;
311 if (CONSP (object) || NILP (object))
312 return Qt;
313 return Qnil;
316 DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0,
317 doc: /* Return t if OBJECT is not a list. Lists include nil. */)
318 (object)
319 Lisp_Object object;
321 if (CONSP (object) || NILP (object))
322 return Qnil;
323 return Qt;
326 DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0,
327 doc: /* Return t if OBJECT is a symbol. */)
328 (object)
329 Lisp_Object object;
331 if (SYMBOLP (object))
332 return Qt;
333 return Qnil;
336 /* Define this in C to avoid unnecessarily consing up the symbol
337 name. */
338 DEFUN ("keywordp", Fkeywordp, Skeywordp, 1, 1, 0,
339 doc: /* Return t if OBJECT is a keyword.
340 This means that it is a symbol with a print name beginning with `:'
341 interned in the initial obarray. */)
342 (object)
343 Lisp_Object object;
345 if (SYMBOLP (object)
346 && SREF (SYMBOL_NAME (object), 0) == ':'
347 && SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P (object))
348 return Qt;
349 return Qnil;
352 DEFUN ("vectorp", Fvectorp, Svectorp, 1, 1, 0,
353 doc: /* Return t if OBJECT is a vector. */)
354 (object)
355 Lisp_Object object;
357 if (VECTORP (object))
358 return Qt;
359 return Qnil;
362 DEFUN ("stringp", Fstringp, Sstringp, 1, 1, 0,
363 doc: /* Return t if OBJECT is a string. */)
364 (object)
365 Lisp_Object object;
367 if (STRINGP (object))
368 return Qt;
369 return Qnil;
372 DEFUN ("multibyte-string-p", Fmultibyte_string_p, Smultibyte_string_p,
373 1, 1, 0,
374 doc: /* Return t if OBJECT is a multibyte string. */)
375 (object)
376 Lisp_Object object;
378 if (STRINGP (object) && STRING_MULTIBYTE (object))
379 return Qt;
380 return Qnil;
383 DEFUN ("char-table-p", Fchar_table_p, Schar_table_p, 1, 1, 0,
384 doc: /* Return t if OBJECT is a char-table. */)
385 (object)
386 Lisp_Object object;
388 if (CHAR_TABLE_P (object))
389 return Qt;
390 return Qnil;
393 DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p,
394 Svector_or_char_table_p, 1, 1, 0,
395 doc: /* Return t if OBJECT is a char-table or vector. */)
396 (object)
397 Lisp_Object object;
399 if (VECTORP (object) || CHAR_TABLE_P (object))
400 return Qt;
401 return Qnil;
404 DEFUN ("bool-vector-p", Fbool_vector_p, Sbool_vector_p, 1, 1, 0,
405 doc: /* Return t if OBJECT is a bool-vector. */)
406 (object)
407 Lisp_Object object;
409 if (BOOL_VECTOR_P (object))
410 return Qt;
411 return Qnil;
414 DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0,
415 doc: /* Return t if OBJECT is an array (string or vector). */)
416 (object)
417 Lisp_Object object;
419 if (ARRAYP (object))
420 return Qt;
421 return Qnil;
424 DEFUN ("sequencep", Fsequencep, Ssequencep, 1, 1, 0,
425 doc: /* Return t if OBJECT is a sequence (list or array). */)
426 (object)
427 register Lisp_Object object;
429 if (CONSP (object) || NILP (object) || ARRAYP (object))
430 return Qt;
431 return Qnil;
434 DEFUN ("bufferp", Fbufferp, Sbufferp, 1, 1, 0,
435 doc: /* Return t if OBJECT is an editor buffer. */)
436 (object)
437 Lisp_Object object;
439 if (BUFFERP (object))
440 return Qt;
441 return Qnil;
444 DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0,
445 doc: /* Return t if OBJECT is a marker (editor pointer). */)
446 (object)
447 Lisp_Object object;
449 if (MARKERP (object))
450 return Qt;
451 return Qnil;
454 DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0,
455 doc: /* Return t if OBJECT is a built-in function. */)
456 (object)
457 Lisp_Object object;
459 if (SUBRP (object))
460 return Qt;
461 return Qnil;
464 DEFUN ("byte-code-function-p", Fbyte_code_function_p, Sbyte_code_function_p,
465 1, 1, 0,
466 doc: /* Return t if OBJECT is a byte-compiled function object. */)
467 (object)
468 Lisp_Object object;
470 if (COMPILEDP (object))
471 return Qt;
472 return Qnil;
475 DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0,
476 doc: /* Return t if OBJECT is a character or a string. */)
477 (object)
478 register Lisp_Object object;
480 if (CHARACTERP (object) || STRINGP (object))
481 return Qt;
482 return Qnil;
485 DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0,
486 doc: /* Return t if OBJECT is an integer. */)
487 (object)
488 Lisp_Object object;
490 if (INTEGERP (object))
491 return Qt;
492 return Qnil;
495 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, Sinteger_or_marker_p, 1, 1, 0,
496 doc: /* Return t if OBJECT is an integer or a marker (editor pointer). */)
497 (object)
498 register Lisp_Object object;
500 if (MARKERP (object) || INTEGERP (object))
501 return Qt;
502 return Qnil;
505 DEFUN ("natnump", Fnatnump, Snatnump, 1, 1, 0,
506 doc: /* Return t if OBJECT is a nonnegative integer. */)
507 (object)
508 Lisp_Object object;
510 if (NATNUMP (object))
511 return Qt;
512 return Qnil;
515 DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0,
516 doc: /* Return t if OBJECT is a number (floating point or integer). */)
517 (object)
518 Lisp_Object object;
520 if (NUMBERP (object))
521 return Qt;
522 else
523 return Qnil;
526 DEFUN ("number-or-marker-p", Fnumber_or_marker_p,
527 Snumber_or_marker_p, 1, 1, 0,
528 doc: /* Return t if OBJECT is a number or a marker. */)
529 (object)
530 Lisp_Object object;
532 if (NUMBERP (object) || MARKERP (object))
533 return Qt;
534 return Qnil;
537 DEFUN ("floatp", Ffloatp, Sfloatp, 1, 1, 0,
538 doc: /* Return t if OBJECT is a floating point number. */)
539 (object)
540 Lisp_Object object;
542 if (FLOATP (object))
543 return Qt;
544 return Qnil;
548 /* Extract and set components of lists */
550 DEFUN ("car", Fcar, Scar, 1, 1, 0,
551 doc: /* Return the car of LIST. If arg is nil, return nil.
552 Error if arg is not nil and not a cons cell. See also `car-safe'.
554 See Info node `(elisp)Cons Cells' for a discussion of related basic
555 Lisp concepts such as car, cdr, cons cell and list. */)
556 (list)
557 register Lisp_Object list;
559 return CAR (list);
562 DEFUN ("car-safe", Fcar_safe, Scar_safe, 1, 1, 0,
563 doc: /* Return the car of OBJECT if it is a cons cell, or else nil. */)
564 (object)
565 Lisp_Object object;
567 return CAR_SAFE (object);
570 DEFUN ("cdr", Fcdr, Scdr, 1, 1, 0,
571 doc: /* Return the cdr of LIST. If arg is nil, return nil.
572 Error if arg is not nil and not a cons cell. See also `cdr-safe'.
574 See Info node `(elisp)Cons Cells' for a discussion of related basic
575 Lisp concepts such as cdr, car, cons cell and list. */)
576 (list)
577 register Lisp_Object list;
579 return CDR (list);
582 DEFUN ("cdr-safe", Fcdr_safe, Scdr_safe, 1, 1, 0,
583 doc: /* Return the cdr of OBJECT if it is a cons cell, or else nil. */)
584 (object)
585 Lisp_Object object;
587 return CDR_SAFE (object);
590 DEFUN ("setcar", Fsetcar, Ssetcar, 2, 2, 0,
591 doc: /* Set the car of CELL to be NEWCAR. Returns NEWCAR. */)
592 (cell, newcar)
593 register Lisp_Object cell, newcar;
595 CHECK_CONS (cell);
596 CHECK_IMPURE (cell);
597 XSETCAR (cell, newcar);
598 return newcar;
601 DEFUN ("setcdr", Fsetcdr, Ssetcdr, 2, 2, 0,
602 doc: /* Set the cdr of CELL to be NEWCDR. Returns NEWCDR. */)
603 (cell, newcdr)
604 register Lisp_Object cell, newcdr;
606 CHECK_CONS (cell);
607 CHECK_IMPURE (cell);
608 XSETCDR (cell, newcdr);
609 return newcdr;
612 /* Extract and set components of symbols */
614 DEFUN ("boundp", Fboundp, Sboundp, 1, 1, 0,
615 doc: /* Return t if SYMBOL's value is not void. */)
616 (symbol)
617 register Lisp_Object symbol;
619 Lisp_Object valcontents;
621 valcontents = find_symbol_value (symbol);
623 return (EQ (valcontents, Qunbound) ? Qnil : Qt);
626 DEFUN ("fboundp", Ffboundp, Sfboundp, 1, 1, 0,
627 doc: /* Return t if SYMBOL's function definition is not void. */)
628 (symbol)
629 register Lisp_Object symbol;
631 CHECK_SYMBOL (symbol);
632 return (EQ (XSYMBOL (symbol)->function, Qunbound) ? Qnil : Qt);
635 DEFUN ("makunbound", Fmakunbound, Smakunbound, 1, 1, 0,
636 doc: /* Make SYMBOL's value be void.
637 Return SYMBOL. */)
638 (symbol)
639 register Lisp_Object symbol;
641 CHECK_SYMBOL (symbol);
642 if (SYMBOL_CONSTANT_P (symbol))
643 xsignal1 (Qsetting_constant, symbol);
644 Fset (symbol, Qunbound);
645 return symbol;
648 DEFUN ("fmakunbound", Ffmakunbound, Sfmakunbound, 1, 1, 0,
649 doc: /* Make SYMBOL's function definition be void.
650 Return SYMBOL. */)
651 (symbol)
652 register Lisp_Object symbol;
654 CHECK_SYMBOL (symbol);
655 if (NILP (symbol) || EQ (symbol, Qt))
656 xsignal1 (Qsetting_constant, symbol);
657 XSYMBOL (symbol)->function = Qunbound;
658 return symbol;
661 DEFUN ("symbol-function", Fsymbol_function, Ssymbol_function, 1, 1, 0,
662 doc: /* Return SYMBOL's function definition. Error if that is void. */)
663 (symbol)
664 register Lisp_Object symbol;
666 CHECK_SYMBOL (symbol);
667 if (!EQ (XSYMBOL (symbol)->function, Qunbound))
668 return XSYMBOL (symbol)->function;
669 xsignal1 (Qvoid_function, symbol);
672 DEFUN ("symbol-plist", Fsymbol_plist, Ssymbol_plist, 1, 1, 0,
673 doc: /* Return SYMBOL's property list. */)
674 (symbol)
675 register Lisp_Object symbol;
677 CHECK_SYMBOL (symbol);
678 return XSYMBOL (symbol)->plist;
681 DEFUN ("symbol-name", Fsymbol_name, Ssymbol_name, 1, 1, 0,
682 doc: /* Return SYMBOL's name, a string. */)
683 (symbol)
684 register Lisp_Object symbol;
686 register Lisp_Object name;
688 CHECK_SYMBOL (symbol);
689 name = SYMBOL_NAME (symbol);
690 return name;
693 DEFUN ("fset", Ffset, Sfset, 2, 2, 0,
694 doc: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION. */)
695 (symbol, definition)
696 register Lisp_Object symbol, definition;
698 register Lisp_Object function;
700 CHECK_SYMBOL (symbol);
701 if (NILP (symbol) || EQ (symbol, Qt))
702 xsignal1 (Qsetting_constant, symbol);
704 function = XSYMBOL (symbol)->function;
706 if (!NILP (Vautoload_queue) && !EQ (function, Qunbound))
707 Vautoload_queue = Fcons (Fcons (symbol, function), Vautoload_queue);
709 if (CONSP (function) && EQ (XCAR (function), Qautoload))
710 Fput (symbol, Qautoload, XCDR (function));
712 XSYMBOL (symbol)->function = definition;
713 /* Handle automatic advice activation */
714 if (CONSP (XSYMBOL (symbol)->plist) && !NILP (Fget (symbol, Qad_advice_info)))
716 call2 (Qad_activate_internal, symbol, Qnil);
717 definition = XSYMBOL (symbol)->function;
719 return definition;
722 extern Lisp_Object Qfunction_documentation;
724 DEFUN ("defalias", Fdefalias, Sdefalias, 2, 3, 0,
725 doc: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION.
726 Associates the function with the current load file, if any.
727 The optional third argument DOCSTRING specifies the documentation string
728 for SYMBOL; if it is omitted or nil, SYMBOL uses the documentation string
729 determined by DEFINITION. */)
730 (symbol, definition, docstring)
731 register Lisp_Object symbol, definition, docstring;
733 CHECK_SYMBOL (symbol);
734 if (CONSP (XSYMBOL (symbol)->function)
735 && EQ (XCAR (XSYMBOL (symbol)->function), Qautoload))
736 LOADHIST_ATTACH (Fcons (Qt, symbol));
737 definition = Ffset (symbol, definition);
738 LOADHIST_ATTACH (Fcons (Qdefun, symbol));
739 if (!NILP (docstring))
740 Fput (symbol, Qfunction_documentation, docstring);
741 return definition;
744 DEFUN ("setplist", Fsetplist, Ssetplist, 2, 2, 0,
745 doc: /* Set SYMBOL's property list to NEWPLIST, and return NEWPLIST. */)
746 (symbol, newplist)
747 register Lisp_Object symbol, newplist;
749 CHECK_SYMBOL (symbol);
750 XSYMBOL (symbol)->plist = newplist;
751 return newplist;
754 DEFUN ("subr-arity", Fsubr_arity, Ssubr_arity, 1, 1, 0,
755 doc: /* Return minimum and maximum number of args allowed for SUBR.
756 SUBR must be a built-in function.
757 The returned value is a pair (MIN . MAX). MIN is the minimum number
758 of args. MAX is the maximum number or the symbol `many', for a
759 function with `&rest' args, or `unevalled' for a special form. */)
760 (subr)
761 Lisp_Object subr;
763 short minargs, maxargs;
764 CHECK_SUBR (subr);
765 minargs = XSUBR (subr)->min_args;
766 maxargs = XSUBR (subr)->max_args;
767 if (maxargs == MANY)
768 return Fcons (make_number (minargs), Qmany);
769 else if (maxargs == UNEVALLED)
770 return Fcons (make_number (minargs), Qunevalled);
771 else
772 return Fcons (make_number (minargs), make_number (maxargs));
775 DEFUN ("subr-name", Fsubr_name, Ssubr_name, 1, 1, 0,
776 doc: /* Return name of subroutine SUBR.
777 SUBR must be a built-in function. */)
778 (subr)
779 Lisp_Object subr;
781 const char *name;
782 CHECK_SUBR (subr);
783 name = XSUBR (subr)->symbol_name;
784 return make_string (name, strlen (name));
787 DEFUN ("interactive-form", Finteractive_form, Sinteractive_form, 1, 1, 0,
788 doc: /* Return the interactive form of CMD or nil if none.
789 If CMD is not a command, the return value is nil.
790 Value, if non-nil, is a list \(interactive SPEC). */)
791 (cmd)
792 Lisp_Object cmd;
794 Lisp_Object fun = indirect_function (cmd); /* Check cycles. */
796 if (NILP (fun) || EQ (fun, Qunbound))
797 return Qnil;
799 /* Use an `interactive-form' property if present, analogous to the
800 function-documentation property. */
801 fun = cmd;
802 while (SYMBOLP (fun))
804 Lisp_Object tmp = Fget (fun, Qinteractive_form);
805 if (!NILP (tmp))
806 return tmp;
807 else
808 fun = Fsymbol_function (fun);
811 if (SUBRP (fun))
813 char *spec = XSUBR (fun)->intspec;
814 if (spec)
815 return list2 (Qinteractive,
816 (*spec != '(') ? build_string (spec) :
817 Fcar (Fread_from_string (build_string (spec), Qnil, Qnil)));
819 else if (COMPILEDP (fun))
821 if ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE)
822 return list2 (Qinteractive, AREF (fun, COMPILED_INTERACTIVE));
824 else if (CONSP (fun))
826 Lisp_Object funcar = XCAR (fun);
827 if (EQ (funcar, Qlambda))
828 return Fassq (Qinteractive, Fcdr (XCDR (fun)));
829 else if (EQ (funcar, Qautoload))
831 struct gcpro gcpro1;
832 GCPRO1 (cmd);
833 do_autoload (fun, cmd);
834 UNGCPRO;
835 return Finteractive_form (cmd);
838 return Qnil;
842 /***********************************************************************
843 Getting and Setting Values of Symbols
844 ***********************************************************************/
846 Lisp_Object *
847 find_variable_location (Lisp_Object *root)
849 if (THREADLOCALP (*root))
851 struct Lisp_ThreadLocal *thr = XTHREADLOCAL (*root);
852 Lisp_Object cons = assq_no_quit (get_current_thread (),
853 thr->thread_alist);
854 if (!EQ (cons, Qnil))
855 return &XCDR_AS_LVALUE (cons);
856 return &thr->global;
859 return root;
862 Lisp_Object
863 ensure_thread_local (Lisp_Object *root)
865 Lisp_Object cons;
867 if (THREADLOCALP (*root))
868 cons = assq_no_quit (get_current_thread (),
869 XTHREADLOCAL (*root)->thread_alist);
870 else
872 Lisp_Object newval;
873 newval = allocate_misc ();
874 XMISCTYPE (newval) = Lisp_Misc_ThreadLocal;
875 XTHREADLOCAL (newval)->global = *root;
876 XTHREADLOCAL (newval)->thread_alist = Qnil;
877 *root = newval;
878 cons = Qnil;
881 if (NILP (cons))
883 struct Lisp_ThreadLocal *local = XTHREADLOCAL (*root);
884 cons = Fcons (get_current_thread (), XTHREADLOCAL (*root)->global);
885 local->thread_alist = Fcons (cons, local->thread_alist);
888 return cons;
891 void
892 remove_thread_local (Lisp_Object *root)
894 if (THREADLOCALP (*root))
896 Lisp_Object iter, thr = get_current_thread (), prior = Qnil;
897 struct Lisp_ThreadLocal *local = XTHREADLOCAL (*root);
898 for (iter = local->thread_alist; !NILP (iter); iter = XCDR (iter))
900 if (EQ (XCAR (XCAR (iter)), thr))
902 if (NILP (prior))
903 local->thread_alist = XCDR (iter);
904 else
905 XSETCDR (prior, XCDR (iter));
906 break;
908 prior = iter;
913 /* Return the symbol holding SYMBOL's value. Signal
914 `cyclic-variable-indirection' if SYMBOL's chain of variable
915 indirections contains a loop. */
917 struct Lisp_Symbol *
918 indirect_variable (symbol)
919 struct Lisp_Symbol *symbol;
921 struct Lisp_Symbol *tortoise, *hare;
923 hare = tortoise = symbol;
925 while (hare->indirect_variable)
927 hare = XSYMBOL (hare->value);
928 if (!hare->indirect_variable)
929 break;
931 hare = XSYMBOL (hare->value);
932 tortoise = XSYMBOL (tortoise->value);
934 if (hare == tortoise)
936 Lisp_Object tem;
937 XSETSYMBOL (tem, symbol);
938 xsignal1 (Qcyclic_variable_indirection, tem);
942 return hare;
946 DEFUN ("indirect-variable", Findirect_variable, Sindirect_variable, 1, 1, 0,
947 doc: /* Return the variable at the end of OBJECT's variable chain.
948 If OBJECT is a symbol, follow all variable indirections and return the final
949 variable. If OBJECT is not a symbol, just return it.
950 Signal a cyclic-variable-indirection error if there is a loop in the
951 variable chain of symbols. */)
952 (object)
953 Lisp_Object object;
955 if (SYMBOLP (object))
956 XSETSYMBOL (object, indirect_variable (XSYMBOL (object)));
957 return object;
961 /* Given the raw contents of a symbol value cell,
962 return the Lisp value of the symbol.
963 This does not handle buffer-local variables; use
964 swap_in_symval_forwarding for that. */
966 Lisp_Object
967 do_symval_forwarding (valcontents)
968 Lisp_Object valcontents;
970 register Lisp_Object val;
971 if (MISCP (valcontents))
972 switch (XMISCTYPE (valcontents))
974 case Lisp_Misc_Intfwd:
975 XSETINT (val, *XINTFWD (valcontents)->intvar);
976 return val;
978 case Lisp_Misc_Boolfwd:
979 return (*XBOOLFWD (valcontents)->boolvar ? Qt : Qnil);
981 case Lisp_Misc_Objfwd:
982 return *XOBJFWD (valcontents)->objvar;
984 case Lisp_Misc_Buffer_Objfwd:
985 return PER_BUFFER_VALUE (current_buffer,
986 XBUFFER_OBJFWD (valcontents)->offset);
988 case Lisp_Misc_Kboard_Objfwd:
989 /* We used to simply use current_kboard here, but from Lisp
990 code, it's value is often unexpected. It seems nicer to
991 allow constructions like this to work as intuitively expected:
993 (with-selected-frame frame
994 (define-key local-function-map "\eOP" [f1]))
996 On the other hand, this affects the semantics of
997 last-command and real-last-command, and people may rely on
998 that. I took a quick look at the Lisp codebase, and I
999 don't think anything will break. --lorentey */
1000 return *(Lisp_Object *)(XKBOARD_OBJFWD (valcontents)->offset
1001 + (char *)FRAME_KBOARD (SELECTED_FRAME ()));
1003 case Lisp_Misc_ThreadLocal:
1004 return *find_variable_location (&valcontents);
1006 return valcontents;
1009 /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell
1010 of SYMBOL. If SYMBOL is buffer-local, VALCONTENTS should be the
1011 buffer-independent contents of the value cell: forwarded just one
1012 step past the buffer-localness.
1014 BUF non-zero means set the value in buffer BUF instead of the
1015 current buffer. This only plays a role for per-buffer variables. */
1017 void
1018 store_symval_forwarding (symbol, valcontents, newval, buf)
1019 Lisp_Object symbol;
1020 register Lisp_Object valcontents, newval;
1021 struct buffer *buf;
1023 switch (SWITCH_ENUM_CAST (XTYPE (valcontents)))
1025 case Lisp_Misc:
1026 switch (XMISCTYPE (valcontents))
1028 case Lisp_Misc_Intfwd:
1029 CHECK_NUMBER (newval);
1030 *XINTFWD (valcontents)->intvar = XINT (newval);
1031 /* This can never happen since intvar points to an EMACS_INT
1032 which is at least large enough to hold a Lisp_Object.
1033 if (*XINTFWD (valcontents)->intvar != XINT (newval))
1034 error ("Value out of range for variable `%s'",
1035 SDATA (SYMBOL_NAME (symbol))); */
1036 break;
1038 case Lisp_Misc_Boolfwd:
1039 *XBOOLFWD (valcontents)->boolvar = !NILP (newval);
1040 break;
1042 case Lisp_Misc_Objfwd:
1043 *find_variable_location (XOBJFWD (valcontents)->objvar) = newval;
1045 /* If this variable is a default for something stored
1046 in the buffer itself, such as default-fill-column,
1047 find the buffers that don't have local values for it
1048 and update them. */
1049 if (XOBJFWD (valcontents)->objvar > (Lisp_Object *) &buffer_defaults
1050 && XOBJFWD (valcontents)->objvar < (Lisp_Object *) (&buffer_defaults + 1))
1052 int offset = ((char *) XOBJFWD (valcontents)->objvar
1053 - (char *) &buffer_defaults);
1054 int idx = PER_BUFFER_IDX (offset);
1056 Lisp_Object tail;
1058 if (idx <= 0)
1059 break;
1061 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
1063 Lisp_Object buf;
1064 struct buffer *b;
1066 buf = Fcdr (XCAR (tail));
1067 if (!BUFFERP (buf)) continue;
1068 b = XBUFFER (buf);
1070 if (! PER_BUFFER_VALUE_P (b, idx))
1071 SET_PER_BUFFER_VALUE_RAW (b, offset, newval);
1074 break;
1076 case Lisp_Misc_Buffer_Objfwd:
1078 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1079 Lisp_Object type = XBUFFER_OBJFWD (valcontents)->slottype;
1081 if (!(NILP (type) || NILP (newval)
1082 || (XINT (type) == LISP_INT_TAG
1083 ? INTEGERP (newval)
1084 : XTYPE (newval) == XINT (type))))
1085 buffer_slot_type_mismatch (newval, XINT (type));
1087 if (buf == NULL)
1088 buf = current_buffer;
1089 PER_BUFFER_VALUE (buf, offset) = newval;
1091 break;
1093 case Lisp_Misc_Kboard_Objfwd:
1095 char *base = (char *) FRAME_KBOARD (SELECTED_FRAME ());
1096 char *p = base + XKBOARD_OBJFWD (valcontents)->offset;
1097 *(Lisp_Object *) p = newval;
1099 break;
1101 default:
1102 goto def;
1104 break;
1106 default:
1107 def:
1108 valcontents = SYMBOL_VALUE (symbol);
1109 if (BUFFER_LOCAL_VALUEP (valcontents))
1110 BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (valcontents)) = newval;
1111 else if (THREADLOCALP (valcontents))
1113 Lisp_Object val = indirect_variable (XSYMBOL (symbol))->value;
1114 ensure_thread_local (&val);
1115 *find_variable_location (&val) = newval;
1117 else
1118 SET_SYMBOL_VALUE (symbol, newval);
1122 /* Set up SYMBOL to refer to its global binding.
1123 This makes it safe to alter the status of other bindings. */
1125 void
1126 swap_in_global_binding (symbol)
1127 Lisp_Object symbol;
1129 Lisp_Object valcontents = SYMBOL_VALUE (symbol);
1130 struct Lisp_Buffer_Local_Value *blv = XBUFFER_LOCAL_VALUE (valcontents);
1131 Lisp_Object cdr = BLOCAL_CDR (blv);
1133 /* Unload the previously loaded binding. */
1134 Fsetcdr (XCAR (cdr),
1135 do_symval_forwarding (blv->realvalue));
1137 /* Select the global binding in the symbol. */
1138 XSETCAR (cdr, cdr);
1139 store_symval_forwarding (symbol, blv->realvalue, XCDR (cdr), NULL);
1141 /* Indicate that the global binding is set up now. */
1142 BLOCAL_FRAME (blv) = Qnil;
1143 BLOCAL_BUFFER (blv) = Qnil;
1144 BLOCAL_CLEAR_FLAGS (blv);
1147 /* Set up the buffer-local symbol SYMBOL for validity in the current buffer.
1148 VALCONTENTS is the contents of its value cell,
1149 which points to a struct Lisp_Buffer_Local_Value.
1151 Return the value forwarded one step past the buffer-local stage.
1152 This could be another forwarding pointer. */
1154 static Lisp_Object
1155 swap_in_symval_forwarding (symbol, valcontents)
1156 Lisp_Object symbol, valcontents;
1158 register Lisp_Object tem1;
1160 tem1 = BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents));
1162 if (NILP (tem1)
1163 || current_buffer != XBUFFER (tem1)
1164 || (XBUFFER_LOCAL_VALUE (valcontents)->check_frame
1165 && ! EQ (selected_frame, BLOCAL_FRAME (XBUFFER_LOCAL_VALUE (valcontents)))))
1167 struct Lisp_Symbol *sym = XSYMBOL (symbol);
1168 if (sym->indirect_variable)
1170 sym = indirect_variable (sym);
1171 XSETSYMBOL (symbol, sym);
1174 /* Unload the previously loaded binding. */
1175 tem1 = XCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)));
1176 Fsetcdr (tem1,
1177 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue));
1178 /* Choose the new binding. */
1179 tem1 = assq_no_quit (symbol, BUF_LOCAL_VAR_ALIST (current_buffer));
1180 BLOCAL_CLEAR_FLAGS (XBUFFER_LOCAL_VALUE (valcontents));
1181 if (NILP (tem1))
1183 if (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
1184 tem1 = assq_no_quit (symbol, XFRAME (selected_frame)->param_alist);
1185 if (! NILP (tem1))
1186 BLOCAL_SET_FOUND_FOR_FRAME (XBUFFER_LOCAL_VALUE (valcontents));
1187 else
1188 tem1 = BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents));
1190 else
1191 BLOCAL_SET_FOUND_FOR_BUFFER (XBUFFER_LOCAL_VALUE (valcontents));
1193 /* Load the new binding. */
1194 XSETCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)), tem1);
1195 XSETBUFFER (BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents)), current_buffer);
1196 BLOCAL_FRAME (XBUFFER_LOCAL_VALUE (valcontents)) = selected_frame;
1197 store_symval_forwarding (symbol,
1198 XBUFFER_LOCAL_VALUE (valcontents)->realvalue,
1199 Fcdr (tem1), NULL);
1202 return BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (valcontents));
1206 /* Find the value of a symbol, returning Qunbound if it's not bound.
1207 This is helpful for code which just wants to get a variable's value
1208 if it has one, without signaling an error.
1209 Note that it must not be possible to quit
1210 within this function. Great care is required for this. */
1212 Lisp_Object
1213 find_symbol_value (symbol)
1214 Lisp_Object symbol;
1216 register Lisp_Object valcontents;
1217 register Lisp_Object val;
1219 CHECK_SYMBOL (symbol);
1220 valcontents = SYMBOL_VALUE (symbol);
1222 if (BUFFER_LOCAL_VALUEP (valcontents))
1223 valcontents = swap_in_symval_forwarding (symbol, valcontents);
1225 return do_symval_forwarding (valcontents);
1228 DEFUN ("symbol-value", Fsymbol_value, Ssymbol_value, 1, 1, 0,
1229 doc: /* Return SYMBOL's value. Error if that is void. */)
1230 (symbol)
1231 Lisp_Object symbol;
1233 Lisp_Object val;
1235 val = find_symbol_value (symbol);
1236 if (!EQ (val, Qunbound))
1237 return val;
1239 xsignal1 (Qvoid_variable, symbol);
1242 DEFUN ("set", Fset, Sset, 2, 2, 0,
1243 doc: /* Set SYMBOL's value to NEWVAL, and return NEWVAL. */)
1244 (symbol, newval)
1245 register Lisp_Object symbol, newval;
1247 return set_internal (symbol, newval, current_buffer, 0);
1250 /* Return 1 if SYMBOL currently has a let-binding
1251 which was made in the buffer that is now current. */
1253 static int
1254 let_shadows_buffer_binding_p (symbol)
1255 struct Lisp_Symbol *symbol;
1257 volatile struct specbinding *p;
1259 for (p = specpdl_ptr - 1; p >= specpdl; p--)
1260 if (p->func == NULL
1261 && CONSP (p->symbol))
1263 struct Lisp_Symbol *let_bound_symbol = XSYMBOL (XCAR (p->symbol));
1264 if ((symbol == let_bound_symbol
1265 || (let_bound_symbol->indirect_variable
1266 && symbol == indirect_variable (let_bound_symbol)))
1267 && XBUFFER (XCDR (XCDR (p->symbol))) == current_buffer)
1268 break;
1271 return p >= specpdl;
1274 /* Store the value NEWVAL into SYMBOL.
1275 If buffer-locality is an issue, BUF specifies which buffer to use.
1276 (0 stands for the current buffer.)
1278 If BINDFLAG is zero, then if this symbol is supposed to become
1279 local in every buffer where it is set, then we make it local.
1280 If BINDFLAG is nonzero, we don't do that. */
1282 Lisp_Object
1283 set_internal (symbol, newval, buf, bindflag)
1284 register Lisp_Object symbol, newval;
1285 struct buffer *buf;
1286 int bindflag;
1288 int voide = EQ (newval, Qunbound);
1290 register Lisp_Object valcontents, innercontents, tem1, current_alist_element;
1292 if (buf == 0)
1293 buf = current_buffer;
1295 /* If restoring in a dead buffer, do nothing. */
1296 if (NILP (BUF_NAME (buf)))
1297 return newval;
1299 CHECK_SYMBOL (symbol);
1300 if (SYMBOL_CONSTANT_P (symbol)
1301 && (NILP (Fkeywordp (symbol))
1302 || !EQ (newval, SYMBOL_VALUE (symbol))))
1303 xsignal1 (Qsetting_constant, symbol);
1305 innercontents = valcontents = SYMBOL_VALUE (symbol);
1307 if (BUFFER_OBJFWDP (valcontents))
1309 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1310 int idx = PER_BUFFER_IDX (offset);
1311 if (idx > 0
1312 && !bindflag
1313 && !let_shadows_buffer_binding_p (XSYMBOL (symbol)))
1314 SET_PER_BUFFER_VALUE_P (buf, idx, 1);
1316 else if (BUFFER_LOCAL_VALUEP (valcontents))
1318 /* valcontents is a struct Lisp_Buffer_Local_Value. */
1319 if (XSYMBOL (symbol)->indirect_variable)
1320 XSETSYMBOL (symbol, indirect_variable (XSYMBOL (symbol)));
1322 /* What binding is loaded right now? */
1323 current_alist_element
1324 = XCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)));
1326 /* If the current buffer is not the buffer whose binding is
1327 loaded, or if there may be frame-local bindings and the frame
1328 isn't the right one, or if it's a Lisp_Buffer_Local_Value and
1329 the default binding is loaded, the loaded binding may be the
1330 wrong one. */
1331 if (!BUFFERP (BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents)))
1332 || buf != XBUFFER (BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents)))
1333 || (XBUFFER_LOCAL_VALUE (valcontents)->check_frame
1334 && !EQ (selected_frame, BLOCAL_FRAME (XBUFFER_LOCAL_VALUE (valcontents))))
1335 /* Also unload a global binding (if the var is local_if_set). */
1336 || (EQ (XCAR (current_alist_element),
1337 current_alist_element)))
1339 /* The currently loaded binding is not necessarily valid.
1340 We need to unload it, and choose a new binding. */
1342 /* Write out `realvalue' to the old loaded binding. */
1343 Fsetcdr (current_alist_element,
1344 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue));
1346 /* Find the new binding. */
1347 tem1 = Fassq (symbol, BUF_LOCAL_VAR_ALIST (buf));
1348 BLOCAL_SET_FOUND_FOR_BUFFER (XBUFFER_LOCAL_VALUE (valcontents));
1350 if (NILP (tem1))
1352 /* This buffer still sees the default value. */
1354 /* If the variable is not local_if_set,
1355 or if this is `let' rather than `set',
1356 make CURRENT-ALIST-ELEMENT point to itself,
1357 indicating that we're seeing the default value.
1358 Likewise if the variable has been let-bound
1359 in the current buffer. */
1360 if (bindflag || !XBUFFER_LOCAL_VALUE (valcontents)->local_if_set
1361 || let_shadows_buffer_binding_p (XSYMBOL (symbol)))
1363 BLOCAL_CLEAR_FLAGS (XBUFFER_LOCAL_VALUE (valcontents));
1365 if (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
1366 tem1 = Fassq (symbol,
1367 XFRAME (selected_frame)->param_alist);
1369 if (! NILP (tem1))
1370 BLOCAL_SET_FOUND_FOR_FRAME (XBUFFER_LOCAL_VALUE (valcontents));
1371 else
1372 tem1 = BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents));
1374 /* If it's a Lisp_Buffer_Local_Value, being set not bound,
1375 and we're not within a let that was made for this buffer,
1376 create a new buffer-local binding for the variable.
1377 That means, give this buffer a new assoc for a local value
1378 and load that binding. */
1379 else
1381 tem1 = Fcons (symbol, XCDR (current_alist_element));
1382 BUF_LOCAL_VAR_ALIST (buf)
1383 = Fcons (tem1, BUF_LOCAL_VAR_ALIST (buf));
1387 /* Record which binding is now loaded. */
1388 XSETCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)), tem1);
1390 /* Set `buffer' and `frame' slots for the binding now loaded. */
1391 XSETBUFFER (BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents)), buf);
1392 BLOCAL_FRAME (XBUFFER_LOCAL_VALUE (valcontents)) = selected_frame;
1394 innercontents = BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (valcontents));
1396 /* Store the new value in the cons-cell. */
1397 XSETCDR (XCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents))), newval);
1400 /* If storing void (making the symbol void), forward only through
1401 buffer-local indicator, not through Lisp_Objfwd, etc. */
1402 if (voide)
1403 store_symval_forwarding (symbol, Qnil, newval, buf);
1404 else
1405 store_symval_forwarding (symbol, innercontents, newval, buf);
1407 return newval;
1410 /* Access or set a buffer-local symbol's default value. */
1412 /* Return the default value of SYMBOL, but don't check for voidness.
1413 Return Qunbound if it is void. */
1415 Lisp_Object
1416 default_value (symbol)
1417 Lisp_Object symbol;
1419 register Lisp_Object valcontents;
1421 CHECK_SYMBOL (symbol);
1422 valcontents = SYMBOL_VALUE (symbol);
1424 /* For a built-in buffer-local variable, get the default value
1425 rather than letting do_symval_forwarding get the current value. */
1426 if (BUFFER_OBJFWDP (valcontents))
1428 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1429 if (PER_BUFFER_IDX (offset) != 0)
1430 return PER_BUFFER_DEFAULT (offset);
1433 /* Handle user-created local variables. */
1434 if (BUFFER_LOCAL_VALUEP (valcontents))
1436 /* If var is set up for a buffer that lacks a local value for it,
1437 the current value is nominally the default value.
1438 But the `realvalue' slot may be more up to date, since
1439 ordinary setq stores just that slot. So use that. */
1440 Lisp_Object current_alist_element, alist_element_car;
1441 current_alist_element
1442 = XCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)));
1443 alist_element_car = XCAR (current_alist_element);
1444 if (EQ (alist_element_car, current_alist_element))
1445 return do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue);
1446 else
1447 return XCDR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)));
1449 /* For other variables, get the current value. */
1450 return do_symval_forwarding (valcontents);
1453 DEFUN ("default-boundp", Fdefault_boundp, Sdefault_boundp, 1, 1, 0,
1454 doc: /* Return t if SYMBOL has a non-void default value.
1455 This is the value that is seen in buffers that do not have their own values
1456 for this variable. */)
1457 (symbol)
1458 Lisp_Object symbol;
1460 register Lisp_Object value;
1462 value = default_value (symbol);
1463 return (EQ (value, Qunbound) ? Qnil : Qt);
1466 DEFUN ("default-value", Fdefault_value, Sdefault_value, 1, 1, 0,
1467 doc: /* Return SYMBOL's default value.
1468 This is the value that is seen in buffers that do not have their own values
1469 for this variable. The default value is meaningful for variables with
1470 local bindings in certain buffers. */)
1471 (symbol)
1472 Lisp_Object symbol;
1474 register Lisp_Object value;
1476 value = default_value (symbol);
1477 if (!EQ (value, Qunbound))
1478 return value;
1480 xsignal1 (Qvoid_variable, symbol);
1483 DEFUN ("set-default", Fset_default, Sset_default, 2, 2, 0,
1484 doc: /* Set SYMBOL's default value to VALUE. SYMBOL and VALUE are evaluated.
1485 The default value is seen in buffers that do not have their own values
1486 for this variable. */)
1487 (symbol, value)
1488 Lisp_Object symbol, value;
1490 register Lisp_Object valcontents, current_alist_element, alist_element_buffer;
1492 CHECK_SYMBOL (symbol);
1493 valcontents = SYMBOL_VALUE (symbol);
1495 /* Handle variables like case-fold-search that have special slots
1496 in the buffer. Make them work apparently like Lisp_Buffer_Local_Value
1497 variables. */
1498 if (BUFFER_OBJFWDP (valcontents))
1500 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1501 int idx = PER_BUFFER_IDX (offset);
1503 PER_BUFFER_DEFAULT (offset) = value;
1505 /* If this variable is not always local in all buffers,
1506 set it in the buffers that don't nominally have a local value. */
1507 if (idx > 0)
1509 struct buffer *b;
1511 for (b = all_buffers; b; b = b->next)
1512 if (!PER_BUFFER_VALUE_P (b, idx))
1513 PER_BUFFER_VALUE (b, offset) = value;
1515 return value;
1518 if (!BUFFER_LOCAL_VALUEP (valcontents))
1519 return Fset (symbol, value);
1521 /* Store new value into the DEFAULT-VALUE slot. */
1522 XSETCDR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)), value);
1524 /* If the default binding is now loaded, set the REALVALUE slot too. */
1525 current_alist_element
1526 = XCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)));
1527 alist_element_buffer = Fcar (current_alist_element);
1528 if (EQ (alist_element_buffer, current_alist_element))
1529 store_symval_forwarding (symbol,
1530 XBUFFER_LOCAL_VALUE (valcontents)->realvalue,
1531 value, NULL);
1533 return value;
1536 DEFUN ("setq-default", Fsetq_default, Ssetq_default, 0, UNEVALLED, 0,
1537 doc: /* Set the default value of variable VAR to VALUE.
1538 VAR, the variable name, is literal (not evaluated);
1539 VALUE is an expression: it is evaluated and its value returned.
1540 The default value of a variable is seen in buffers
1541 that do not have their own values for the variable.
1543 More generally, you can use multiple variables and values, as in
1544 (setq-default VAR VALUE VAR VALUE...)
1545 This sets each VAR's default value to the corresponding VALUE.
1546 The VALUE for the Nth VAR can refer to the new default values
1547 of previous VARs.
1548 usage: (setq-default [VAR VALUE]...) */)
1549 (args)
1550 Lisp_Object args;
1552 register Lisp_Object args_left;
1553 register Lisp_Object val, symbol;
1554 struct gcpro gcpro1;
1556 if (NILP (args))
1557 return Qnil;
1559 args_left = args;
1560 GCPRO1 (args);
1564 val = Feval (Fcar (Fcdr (args_left)));
1565 symbol = XCAR (args_left);
1566 Fset_default (symbol, val);
1567 args_left = Fcdr (XCDR (args_left));
1569 while (!NILP (args_left));
1571 UNGCPRO;
1572 return val;
1575 /* Lisp functions for creating and removing buffer-local variables. */
1577 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local, Smake_variable_buffer_local,
1578 1, 1, "vMake Variable Buffer Local: ",
1579 doc: /* Make VARIABLE become buffer-local whenever it is set.
1580 At any time, the value for the current buffer is in effect,
1581 unless the variable has never been set in this buffer,
1582 in which case the default value is in effect.
1583 Note that binding the variable with `let', or setting it while
1584 a `let'-style binding made in this buffer is in effect,
1585 does not make the variable buffer-local. Return VARIABLE.
1587 In most cases it is better to use `make-local-variable',
1588 which makes a variable local in just one buffer.
1590 The function `default-value' gets the default value and `set-default' sets it. */)
1591 (variable)
1592 register Lisp_Object variable;
1594 register Lisp_Object tem, valcontents, newval;
1595 struct Lisp_Symbol *sym;
1597 CHECK_SYMBOL (variable);
1598 sym = indirect_variable (XSYMBOL (variable));
1600 valcontents = sym->value;
1601 if (sym->constant || KBOARD_OBJFWDP (valcontents))
1602 error ("Symbol %s may not be buffer-local", SDATA (sym->xname));
1604 if (BUFFER_OBJFWDP (valcontents))
1605 return variable;
1606 else if (BUFFER_LOCAL_VALUEP (valcontents))
1608 if (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
1609 error ("Symbol %s may not be buffer-local", SDATA (sym->xname));
1610 newval = valcontents;
1612 else
1614 Lisp_Object len, val_vec;
1615 XSETFASTINT (len, 4);
1616 val_vec = Fmake_vector (len, Qnil);
1617 if (EQ (valcontents, Qunbound))
1618 sym->value = Qnil;
1619 tem = Fcons (Qnil, Fsymbol_value (variable));
1620 XSETCAR (tem, tem);
1621 newval = allocate_misc ();
1622 XMISCTYPE (newval) = Lisp_Misc_Buffer_Local_Value;
1623 XBUFFER_LOCAL_VALUE (newval)->thread_data = Qnil;
1624 BLOCAL_CLEAR_FLAGS_VEC (val_vec);
1625 BLOCAL_BUFFER_VEC (val_vec) = Fcurrent_buffer ();
1626 BLOCAL_FRAME_VEC (val_vec) = Qnil;
1627 BLOCAL_CDR_VEC (val_vec) = tem;
1628 XBUFFER_LOCAL_VALUE (newval)->check_frame = 0;
1629 BLOCAL_SET_THREAD_DATA (XBUFFER_LOCAL_VALUE (newval), val_vec);
1630 XBUFFER_LOCAL_VALUE (newval)->realvalue = allocate_misc ();
1631 XMISCTYPE (XBUFFER_LOCAL_VALUE (newval)->realvalue)
1632 = Lisp_Misc_ThreadLocal;
1633 XTHREADLOCAL (XBUFFER_LOCAL_VALUE (newval)->realvalue)->global = Qnil;
1634 XTHREADLOCAL (XBUFFER_LOCAL_VALUE (newval)->realvalue)->thread_alist
1635 = Fcons (Fcons (get_current_thread (), Qnil), Qnil);
1636 BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (newval)) = sym->value;
1637 sym->value = newval;
1639 XBUFFER_LOCAL_VALUE (newval)->local_if_set = 1;
1640 return variable;
1643 DEFUN ("make-local-variable", Fmake_local_variable, Smake_local_variable,
1644 1, 1, "vMake Local Variable: ",
1645 doc: /* Make VARIABLE have a separate value in the current buffer.
1646 Other buffers will continue to share a common default value.
1647 \(The buffer-local value of VARIABLE starts out as the same value
1648 VARIABLE previously had. If VARIABLE was void, it remains void.\)
1649 Return VARIABLE.
1651 If the variable is already arranged to become local when set,
1652 this function causes a local value to exist for this buffer,
1653 just as setting the variable would do.
1655 This function returns VARIABLE, and therefore
1656 (set (make-local-variable 'VARIABLE) VALUE-EXP)
1657 works.
1659 See also `make-variable-buffer-local'.
1661 Do not use `make-local-variable' to make a hook variable buffer-local.
1662 Instead, use `add-hook' and specify t for the LOCAL argument. */)
1663 (variable)
1664 register Lisp_Object variable;
1666 register Lisp_Object tem, valcontents;
1667 struct Lisp_Symbol *sym;
1669 CHECK_SYMBOL (variable);
1670 sym = indirect_variable (XSYMBOL (variable));
1672 valcontents = sym->value;
1673 if (sym->constant || KBOARD_OBJFWDP (valcontents)
1674 || (BUFFER_LOCAL_VALUEP (valcontents)
1675 && (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)))
1676 error ("Symbol %s may not be buffer-local", SDATA (sym->xname));
1678 if ((BUFFER_LOCAL_VALUEP (valcontents)
1679 && XBUFFER_LOCAL_VALUE (valcontents)->local_if_set)
1680 || BUFFER_OBJFWDP (valcontents))
1682 tem = Fboundp (variable);
1684 /* Make sure the symbol has a local value in this particular buffer,
1685 by setting it to the same value it already has. */
1686 Fset (variable, (EQ (tem, Qt) ? Fsymbol_value (variable) : Qunbound));
1687 return variable;
1689 /* Make sure symbol is set up to hold per-buffer values. */
1690 if (!BUFFER_LOCAL_VALUEP (valcontents))
1692 Lisp_Object newval, len, val_vec;
1693 XSETFASTINT (len, 4);
1694 val_vec = Fmake_vector (len, Qnil);
1695 tem = Fcons (Qnil, do_symval_forwarding (valcontents));
1696 XSETCAR (tem, tem);
1697 newval = allocate_misc ();
1698 XMISCTYPE (newval) = Lisp_Misc_Buffer_Local_Value;
1699 XBUFFER_LOCAL_VALUE (newval)->thread_data = Qnil;
1700 BLOCAL_BUFFER_VEC (val_vec) = Qnil;
1701 BLOCAL_FRAME_VEC (val_vec) = Qnil;
1702 BLOCAL_CDR_VEC (val_vec) = tem;
1703 XBUFFER_LOCAL_VALUE (newval)->local_if_set = 0;
1704 XBUFFER_LOCAL_VALUE (newval)->check_frame = 0;
1705 BLOCAL_SET_THREAD_DATA (XBUFFER_LOCAL_VALUE (newval), val_vec);
1706 XBUFFER_LOCAL_VALUE (newval)->realvalue = allocate_misc ();
1707 XMISCTYPE (XBUFFER_LOCAL_VALUE (newval)->realvalue)
1708 = Lisp_Misc_ThreadLocal;
1709 XTHREADLOCAL (XBUFFER_LOCAL_VALUE (newval)->realvalue)->global = Qnil;
1710 XTHREADLOCAL (XBUFFER_LOCAL_VALUE (newval)->realvalue)->thread_alist
1711 = Fcons (Fcons (get_current_thread (), Qnil), Qnil);
1712 BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (newval)) = sym->value;
1713 sym->value = newval;
1715 /* Make sure this buffer has its own value of symbol. */
1716 XSETSYMBOL (variable, sym); /* Propagate variable indirections. */
1717 tem = Fassq (variable, BUF_LOCAL_VAR_ALIST (current_buffer));
1718 if (NILP (tem))
1720 /* Swap out any local binding for some other buffer, and make
1721 sure the current value is permanently recorded, if it's the
1722 default value. */
1723 find_symbol_value (variable);
1725 BUF_LOCAL_VAR_ALIST (current_buffer)
1726 = Fcons (Fcons (variable, XCDR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (sym->value)))),
1727 BUF_LOCAL_VAR_ALIST (current_buffer));
1729 /* Make sure symbol does not think it is set up for this buffer;
1730 force it to look once again for this buffer's value. */
1732 Lisp_Object *pvalbuf;
1734 valcontents = sym->value;
1736 pvalbuf = &BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents));
1737 if (current_buffer == XBUFFER (*pvalbuf))
1738 *pvalbuf = Qnil;
1739 BLOCAL_CLEAR_FLAGS (XBUFFER_LOCAL_VALUE (valcontents));
1743 /* If the symbol forwards into a C variable, then load the binding
1744 for this buffer now. If C code modifies the variable before we
1745 load the binding in, then that new value will clobber the default
1746 binding the next time we unload it. */
1747 valcontents = XBUFFER_LOCAL_VALUE (sym->value)->realvalue;
1748 if (INTFWDP (valcontents) || BOOLFWDP (valcontents) || OBJFWDP (valcontents))
1749 swap_in_symval_forwarding (variable, sym->value);
1751 return variable;
1754 DEFUN ("kill-local-variable", Fkill_local_variable, Skill_local_variable,
1755 1, 1, "vKill Local Variable: ",
1756 doc: /* Make VARIABLE no longer have a separate value in the current buffer.
1757 From now on the default value will apply in this buffer. Return VARIABLE. */)
1758 (variable)
1759 register Lisp_Object variable;
1761 register Lisp_Object tem, valcontents;
1762 struct Lisp_Symbol *sym;
1764 CHECK_SYMBOL (variable);
1765 sym = indirect_variable (XSYMBOL (variable));
1767 valcontents = sym->value;
1769 if (BUFFER_OBJFWDP (valcontents))
1771 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1772 int idx = PER_BUFFER_IDX (offset);
1774 if (idx > 0)
1776 SET_PER_BUFFER_VALUE_P (current_buffer, idx, 0);
1777 PER_BUFFER_VALUE (current_buffer, offset)
1778 = PER_BUFFER_DEFAULT (offset);
1780 return variable;
1783 if (!BUFFER_LOCAL_VALUEP (valcontents))
1784 return variable;
1786 /* Get rid of this buffer's alist element, if any. */
1787 XSETSYMBOL (variable, sym); /* Propagate variable indirection. */
1788 tem = Fassq (variable, BUF_LOCAL_VAR_ALIST (current_buffer));
1789 if (!NILP (tem))
1790 BUF_LOCAL_VAR_ALIST (current_buffer)
1791 = Fdelq (tem, BUF_LOCAL_VAR_ALIST (current_buffer));
1793 /* If the symbol is set up with the current buffer's binding
1794 loaded, recompute its value. We have to do it now, or else
1795 forwarded objects won't work right. */
1797 Lisp_Object *pvalbuf, buf;
1798 valcontents = sym->value;
1799 pvalbuf = &BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents));
1800 XSETBUFFER (buf, current_buffer);
1801 if (EQ (buf, *pvalbuf))
1803 *pvalbuf = Qnil;
1804 BLOCAL_CLEAR_FLAGS (XBUFFER_LOCAL_VALUE (valcontents));
1805 find_symbol_value (variable);
1809 return variable;
1812 /* Lisp functions for creating and removing buffer-local variables. */
1814 /* Obsolete since 22.2. NB adjust doc of modify-frame-parameters
1815 when/if this is removed. */
1817 DEFUN ("make-variable-frame-local", Fmake_variable_frame_local, Smake_variable_frame_local,
1818 1, 1, "vMake Variable Frame Local: ",
1819 doc: /* Enable VARIABLE to have frame-local bindings.
1820 This does not create any frame-local bindings for VARIABLE,
1821 it just makes them possible.
1823 A frame-local binding is actually a frame parameter value.
1824 If a frame F has a value for the frame parameter named VARIABLE,
1825 that also acts as a frame-local binding for VARIABLE in F--
1826 provided this function has been called to enable VARIABLE
1827 to have frame-local bindings at all.
1829 The only way to create a frame-local binding for VARIABLE in a frame
1830 is to set the VARIABLE frame parameter of that frame. See
1831 `modify-frame-parameters' for how to set frame parameters.
1833 Note that since Emacs 23.1, variables cannot be both buffer-local and
1834 frame-local any more (buffer-local bindings used to take precedence over
1835 frame-local bindings). */)
1836 (variable)
1837 register Lisp_Object variable;
1839 register Lisp_Object tem, valcontents, newval, val_vec, len;
1840 struct Lisp_Symbol *sym;
1842 CHECK_SYMBOL (variable);
1843 sym = indirect_variable (XSYMBOL (variable));
1845 valcontents = sym->value;
1846 if (sym->constant || KBOARD_OBJFWDP (valcontents)
1847 || BUFFER_OBJFWDP (valcontents))
1848 error ("Symbol %s may not be frame-local", SDATA (sym->xname));
1850 if (BUFFER_LOCAL_VALUEP (valcontents))
1852 if (!XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
1853 error ("Symbol %s may not be frame-local", SDATA (sym->xname));
1854 return variable;
1857 if (EQ (valcontents, Qunbound))
1858 sym->value = Qnil;
1859 tem = Fcons (Qnil, Fsymbol_value (variable));
1860 XSETCAR (tem, tem);
1861 newval = allocate_misc ();
1862 XSETFASTINT (len, 4);
1863 val_vec = Fmake_vector (len, Qnil);
1864 XMISCTYPE (newval) = Lisp_Misc_Buffer_Local_Value;
1865 XBUFFER_LOCAL_VALUE (newval)->thread_data = Qnil;
1866 BLOCAL_CLEAR_FLAGS_VEC (val_vec);
1867 BLOCAL_BUFFER_VEC (val_vec) = Qnil;
1868 BLOCAL_FRAME_VEC (val_vec) = Qnil;
1869 BLOCAL_CDR_VEC (val_vec) = tem;
1870 XBUFFER_LOCAL_VALUE (newval)->local_if_set = 0;
1871 XBUFFER_LOCAL_VALUE (newval)->check_frame = 1;
1872 BLOCAL_SET_THREAD_DATA (XBUFFER_LOCAL_VALUE (newval), val_vec);
1873 XBUFFER_LOCAL_VALUE (newval)->realvalue = allocate_misc ();
1874 XMISCTYPE (XBUFFER_LOCAL_VALUE (newval)->realvalue)
1875 = Lisp_Misc_ThreadLocal;
1876 XTHREADLOCAL (XBUFFER_LOCAL_VALUE (newval)->realvalue)->global = Qnil;
1877 XTHREADLOCAL (XBUFFER_LOCAL_VALUE (newval)->realvalue)->thread_alist
1878 = Fcons (Fcons (get_current_thread (), Qnil), Qnil);
1879 BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (newval)) = sym->value;
1880 sym->value = newval;
1881 return variable;
1884 DEFUN ("local-variable-p", Flocal_variable_p, Slocal_variable_p,
1885 1, 2, 0,
1886 doc: /* Non-nil if VARIABLE has a local binding in buffer BUFFER.
1887 BUFFER defaults to the current buffer. */)
1888 (variable, buffer)
1889 register Lisp_Object variable, buffer;
1891 Lisp_Object valcontents;
1892 register struct buffer *buf;
1893 struct Lisp_Symbol *sym;
1895 if (NILP (buffer))
1896 buf = current_buffer;
1897 else
1899 CHECK_BUFFER (buffer);
1900 buf = XBUFFER (buffer);
1903 CHECK_SYMBOL (variable);
1904 sym = indirect_variable (XSYMBOL (variable));
1905 XSETSYMBOL (variable, sym);
1907 valcontents = sym->value;
1908 if (BUFFER_LOCAL_VALUEP (valcontents))
1910 Lisp_Object tail, elt;
1912 for (tail = BUF_LOCAL_VAR_ALIST (buf); CONSP (tail); tail = XCDR (tail))
1914 elt = XCAR (tail);
1915 if (EQ (variable, XCAR (elt)))
1916 return Qt;
1919 if (BUFFER_OBJFWDP (valcontents))
1921 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1922 int idx = PER_BUFFER_IDX (offset);
1923 if (idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
1924 return Qt;
1926 return Qnil;
1929 DEFUN ("local-variable-if-set-p", Flocal_variable_if_set_p, Slocal_variable_if_set_p,
1930 1, 2, 0,
1931 doc: /* Non-nil if VARIABLE will be local in buffer BUFFER when set there.
1932 More precisely, this means that setting the variable \(with `set' or`setq'),
1933 while it does not have a `let'-style binding that was made in BUFFER,
1934 will produce a buffer local binding. See Info node
1935 `(elisp)Creating Buffer-Local'.
1936 BUFFER defaults to the current buffer. */)
1937 (variable, buffer)
1938 register Lisp_Object variable, buffer;
1940 Lisp_Object valcontents;
1941 register struct buffer *buf;
1942 struct Lisp_Symbol *sym;
1944 if (NILP (buffer))
1945 buf = current_buffer;
1946 else
1948 CHECK_BUFFER (buffer);
1949 buf = XBUFFER (buffer);
1952 CHECK_SYMBOL (variable);
1953 sym = indirect_variable (XSYMBOL (variable));
1954 XSETSYMBOL (variable, sym);
1956 valcontents = sym->value;
1958 if (BUFFER_OBJFWDP (valcontents))
1959 /* All these slots become local if they are set. */
1960 return Qt;
1961 else if (BUFFER_LOCAL_VALUEP (valcontents))
1963 Lisp_Object tail, elt;
1964 if (XBUFFER_LOCAL_VALUE (valcontents)->local_if_set)
1965 return Qt;
1966 for (tail = BUF_LOCAL_VAR_ALIST (buf); CONSP (tail); tail = XCDR (tail))
1968 elt = XCAR (tail);
1969 if (EQ (variable, XCAR (elt)))
1970 return Qt;
1973 return Qnil;
1976 DEFUN ("variable-binding-locus", Fvariable_binding_locus, Svariable_binding_locus,
1977 1, 1, 0,
1978 doc: /* Return a value indicating where VARIABLE's current binding comes from.
1979 If the current binding is buffer-local, the value is the current buffer.
1980 If the current binding is frame-local, the value is the selected frame.
1981 If the current binding is global (the default), the value is nil. */)
1982 (variable)
1983 register Lisp_Object variable;
1985 Lisp_Object valcontents;
1986 struct Lisp_Symbol *sym;
1988 CHECK_SYMBOL (variable);
1989 sym = indirect_variable (XSYMBOL (variable));
1991 /* Make sure the current binding is actually swapped in. */
1992 find_symbol_value (variable);
1994 valcontents = sym->value;
1996 if (BUFFER_LOCAL_VALUEP (valcontents)
1997 || BUFFER_OBJFWDP (valcontents))
1999 /* For a local variable, record both the symbol and which
2000 buffer's or frame's value we are saving. */
2001 if (!NILP (Flocal_variable_p (variable, Qnil)))
2002 return Fcurrent_buffer ();
2003 else if (BUFFER_LOCAL_VALUEP (valcontents)
2004 && BLOCAL_FOUND_FOR_FRAME (XBUFFER_LOCAL_VALUE (valcontents)))
2005 return BLOCAL_FRAME (XBUFFER_LOCAL_VALUE (valcontents));
2008 return Qnil;
2011 /* This code is disabled now that we use the selected frame to return
2012 keyboard-local-values. */
2013 #if 0
2014 extern struct terminal *get_terminal P_ ((Lisp_Object display, int));
2016 DEFUN ("terminal-local-value", Fterminal_local_value, Sterminal_local_value, 2, 2, 0,
2017 doc: /* Return the terminal-local value of SYMBOL on TERMINAL.
2018 If SYMBOL is not a terminal-local variable, then return its normal
2019 value, like `symbol-value'.
2021 TERMINAL may be a terminal object, a frame, or nil (meaning the
2022 selected frame's terminal device). */)
2023 (symbol, terminal)
2024 Lisp_Object symbol;
2025 Lisp_Object terminal;
2027 Lisp_Object result;
2028 struct terminal *t = get_terminal (terminal, 1);
2029 push_kboard (t->kboard);
2030 result = Fsymbol_value (symbol);
2031 pop_kboard ();
2032 return result;
2035 DEFUN ("set-terminal-local-value", Fset_terminal_local_value, Sset_terminal_local_value, 3, 3, 0,
2036 doc: /* Set the terminal-local binding of SYMBOL on TERMINAL to VALUE.
2037 If VARIABLE is not a terminal-local variable, then set its normal
2038 binding, like `set'.
2040 TERMINAL may be a terminal object, a frame, or nil (meaning the
2041 selected frame's terminal device). */)
2042 (symbol, terminal, value)
2043 Lisp_Object symbol;
2044 Lisp_Object terminal;
2045 Lisp_Object value;
2047 Lisp_Object result;
2048 struct terminal *t = get_terminal (terminal, 1);
2049 push_kboard (d->kboard);
2050 result = Fset (symbol, value);
2051 pop_kboard ();
2052 return result;
2054 #endif
2056 /* Find the function at the end of a chain of symbol function indirections. */
2058 /* If OBJECT is a symbol, find the end of its function chain and
2059 return the value found there. If OBJECT is not a symbol, just
2060 return it. If there is a cycle in the function chain, signal a
2061 cyclic-function-indirection error.
2063 This is like Findirect_function, except that it doesn't signal an
2064 error if the chain ends up unbound. */
2065 Lisp_Object
2066 indirect_function (object)
2067 register Lisp_Object object;
2069 Lisp_Object tortoise, hare;
2071 hare = tortoise = object;
2073 for (;;)
2075 if (!SYMBOLP (hare) || EQ (hare, Qunbound))
2076 break;
2077 hare = XSYMBOL (hare)->function;
2078 if (!SYMBOLP (hare) || EQ (hare, Qunbound))
2079 break;
2080 hare = XSYMBOL (hare)->function;
2082 tortoise = XSYMBOL (tortoise)->function;
2084 if (EQ (hare, tortoise))
2085 xsignal1 (Qcyclic_function_indirection, object);
2088 return hare;
2091 DEFUN ("indirect-function", Findirect_function, Sindirect_function, 1, 2, 0,
2092 doc: /* Return the function at the end of OBJECT's function chain.
2093 If OBJECT is not a symbol, just return it. Otherwise, follow all
2094 function indirections to find the final function binding and return it.
2095 If the final symbol in the chain is unbound, signal a void-function error.
2096 Optional arg NOERROR non-nil means to return nil instead of signalling.
2097 Signal a cyclic-function-indirection error if there is a loop in the
2098 function chain of symbols. */)
2099 (object, noerror)
2100 register Lisp_Object object;
2101 Lisp_Object noerror;
2103 Lisp_Object result;
2105 /* Optimize for no indirection. */
2106 result = object;
2107 if (SYMBOLP (result) && !EQ (result, Qunbound)
2108 && (result = XSYMBOL (result)->function, SYMBOLP (result)))
2109 result = indirect_function (result);
2110 if (!EQ (result, Qunbound))
2111 return result;
2113 if (NILP (noerror))
2114 xsignal1 (Qvoid_function, object);
2116 return Qnil;
2119 /* Extract and set vector and string elements */
2121 DEFUN ("aref", Faref, Saref, 2, 2, 0,
2122 doc: /* Return the element of ARRAY at index IDX.
2123 ARRAY may be a vector, a string, a char-table, a bool-vector,
2124 or a byte-code object. IDX starts at 0. */)
2125 (array, idx)
2126 register Lisp_Object array;
2127 Lisp_Object idx;
2129 register int idxval;
2131 CHECK_NUMBER (idx);
2132 idxval = XINT (idx);
2133 if (STRINGP (array))
2135 int c, idxval_byte;
2137 if (idxval < 0 || idxval >= SCHARS (array))
2138 args_out_of_range (array, idx);
2139 if (! STRING_MULTIBYTE (array))
2140 return make_number ((unsigned char) SREF (array, idxval));
2141 idxval_byte = string_char_to_byte (array, idxval);
2143 c = STRING_CHAR (SDATA (array) + idxval_byte);
2144 return make_number (c);
2146 else if (BOOL_VECTOR_P (array))
2148 int val;
2150 if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size)
2151 args_out_of_range (array, idx);
2153 val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR];
2154 return (val & (1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR)) ? Qt : Qnil);
2156 else if (CHAR_TABLE_P (array))
2158 CHECK_CHARACTER (idx);
2159 return CHAR_TABLE_REF (array, idxval);
2161 else
2163 int size = 0;
2164 if (VECTORP (array))
2165 size = XVECTOR (array)->size;
2166 else if (COMPILEDP (array))
2167 size = XVECTOR (array)->size & PSEUDOVECTOR_SIZE_MASK;
2168 else
2169 wrong_type_argument (Qarrayp, array);
2171 if (idxval < 0 || idxval >= size)
2172 args_out_of_range (array, idx);
2173 return XVECTOR (array)->contents[idxval];
2177 DEFUN ("aset", Faset, Saset, 3, 3, 0,
2178 doc: /* Store into the element of ARRAY at index IDX the value NEWELT.
2179 Return NEWELT. ARRAY may be a vector, a string, a char-table or a
2180 bool-vector. IDX starts at 0. */)
2181 (array, idx, newelt)
2182 register Lisp_Object array;
2183 Lisp_Object idx, newelt;
2185 register int idxval;
2187 CHECK_NUMBER (idx);
2188 idxval = XINT (idx);
2189 CHECK_ARRAY (array, Qarrayp);
2190 CHECK_IMPURE (array);
2192 if (VECTORP (array))
2194 if (idxval < 0 || idxval >= XVECTOR (array)->size)
2195 args_out_of_range (array, idx);
2196 XVECTOR (array)->contents[idxval] = newelt;
2198 else if (BOOL_VECTOR_P (array))
2200 int val;
2202 if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size)
2203 args_out_of_range (array, idx);
2205 val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR];
2207 if (! NILP (newelt))
2208 val |= 1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR);
2209 else
2210 val &= ~(1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR));
2211 XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR] = val;
2213 else if (CHAR_TABLE_P (array))
2215 CHECK_CHARACTER (idx);
2216 CHAR_TABLE_SET (array, idxval, newelt);
2218 else if (STRING_MULTIBYTE (array))
2220 int idxval_byte, prev_bytes, new_bytes, nbytes;
2221 unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1;
2223 if (idxval < 0 || idxval >= SCHARS (array))
2224 args_out_of_range (array, idx);
2225 CHECK_CHARACTER (newelt);
2227 nbytes = SBYTES (array);
2229 idxval_byte = string_char_to_byte (array, idxval);
2230 p1 = SDATA (array) + idxval_byte;
2231 PARSE_MULTIBYTE_SEQ (p1, nbytes - idxval_byte, prev_bytes);
2232 new_bytes = CHAR_STRING (XINT (newelt), p0);
2233 if (prev_bytes != new_bytes)
2235 /* We must relocate the string data. */
2236 int nchars = SCHARS (array);
2237 unsigned char *str;
2238 USE_SAFE_ALLOCA;
2240 SAFE_ALLOCA (str, unsigned char *, nbytes);
2241 bcopy (SDATA (array), str, nbytes);
2242 allocate_string_data (XSTRING (array), nchars,
2243 nbytes + new_bytes - prev_bytes);
2244 bcopy (str, SDATA (array), idxval_byte);
2245 p1 = SDATA (array) + idxval_byte;
2246 bcopy (str + idxval_byte + prev_bytes, p1 + new_bytes,
2247 nbytes - (idxval_byte + prev_bytes));
2248 SAFE_FREE ();
2249 clear_string_char_byte_cache ();
2251 while (new_bytes--)
2252 *p1++ = *p0++;
2254 else
2256 if (idxval < 0 || idxval >= SCHARS (array))
2257 args_out_of_range (array, idx);
2258 CHECK_NUMBER (newelt);
2260 if (XINT (newelt) >= 0 && ! SINGLE_BYTE_CHAR_P (XINT (newelt)))
2262 int i;
2264 for (i = SBYTES (array) - 1; i >= 0; i--)
2265 if (SREF (array, i) >= 0x80)
2266 args_out_of_range (array, newelt);
2267 /* ARRAY is an ASCII string. Convert it to a multibyte
2268 string, and try `aset' again. */
2269 STRING_SET_MULTIBYTE (array);
2270 return Faset (array, idx, newelt);
2272 SSET (array, idxval, XINT (newelt));
2275 return newelt;
2278 /* Arithmetic functions */
2280 enum comparison { equal, notequal, less, grtr, less_or_equal, grtr_or_equal };
2282 Lisp_Object
2283 arithcompare (num1, num2, comparison)
2284 Lisp_Object num1, num2;
2285 enum comparison comparison;
2287 double f1 = 0, f2 = 0;
2288 int floatp = 0;
2290 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1);
2291 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2);
2293 if (FLOATP (num1) || FLOATP (num2))
2295 floatp = 1;
2296 f1 = (FLOATP (num1)) ? XFLOAT_DATA (num1) : XINT (num1);
2297 f2 = (FLOATP (num2)) ? XFLOAT_DATA (num2) : XINT (num2);
2300 switch (comparison)
2302 case equal:
2303 if (floatp ? f1 == f2 : XINT (num1) == XINT (num2))
2304 return Qt;
2305 return Qnil;
2307 case notequal:
2308 if (floatp ? f1 != f2 : XINT (num1) != XINT (num2))
2309 return Qt;
2310 return Qnil;
2312 case less:
2313 if (floatp ? f1 < f2 : XINT (num1) < XINT (num2))
2314 return Qt;
2315 return Qnil;
2317 case less_or_equal:
2318 if (floatp ? f1 <= f2 : XINT (num1) <= XINT (num2))
2319 return Qt;
2320 return Qnil;
2322 case grtr:
2323 if (floatp ? f1 > f2 : XINT (num1) > XINT (num2))
2324 return Qt;
2325 return Qnil;
2327 case grtr_or_equal:
2328 if (floatp ? f1 >= f2 : XINT (num1) >= XINT (num2))
2329 return Qt;
2330 return Qnil;
2332 default:
2333 abort ();
2337 DEFUN ("=", Feqlsign, Seqlsign, 2, 2, 0,
2338 doc: /* Return t if two args, both numbers or markers, are equal. */)
2339 (num1, num2)
2340 register Lisp_Object num1, num2;
2342 return arithcompare (num1, num2, equal);
2345 DEFUN ("<", Flss, Slss, 2, 2, 0,
2346 doc: /* Return t if first arg is less than second arg. Both must be numbers or markers. */)
2347 (num1, num2)
2348 register Lisp_Object num1, num2;
2350 return arithcompare (num1, num2, less);
2353 DEFUN (">", Fgtr, Sgtr, 2, 2, 0,
2354 doc: /* Return t if first arg is greater than second arg. Both must be numbers or markers. */)
2355 (num1, num2)
2356 register Lisp_Object num1, num2;
2358 return arithcompare (num1, num2, grtr);
2361 DEFUN ("<=", Fleq, Sleq, 2, 2, 0,
2362 doc: /* Return t if first arg is less than or equal to second arg.
2363 Both must be numbers or markers. */)
2364 (num1, num2)
2365 register Lisp_Object num1, num2;
2367 return arithcompare (num1, num2, less_or_equal);
2370 DEFUN (">=", Fgeq, Sgeq, 2, 2, 0,
2371 doc: /* Return t if first arg is greater than or equal to second arg.
2372 Both must be numbers or markers. */)
2373 (num1, num2)
2374 register Lisp_Object num1, num2;
2376 return arithcompare (num1, num2, grtr_or_equal);
2379 DEFUN ("/=", Fneq, Sneq, 2, 2, 0,
2380 doc: /* Return t if first arg is not equal to second arg. Both must be numbers or markers. */)
2381 (num1, num2)
2382 register Lisp_Object num1, num2;
2384 return arithcompare (num1, num2, notequal);
2387 DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0,
2388 doc: /* Return t if NUMBER is zero. */)
2389 (number)
2390 register Lisp_Object number;
2392 CHECK_NUMBER_OR_FLOAT (number);
2394 if (FLOATP (number))
2396 if (XFLOAT_DATA (number) == 0.0)
2397 return Qt;
2398 return Qnil;
2401 if (!XINT (number))
2402 return Qt;
2403 return Qnil;
2406 /* Convert between long values and pairs of Lisp integers.
2407 Note that long_to_cons returns a single Lisp integer
2408 when the value fits in one. */
2410 Lisp_Object
2411 long_to_cons (i)
2412 unsigned long i;
2414 unsigned long top = i >> 16;
2415 unsigned int bot = i & 0xFFFF;
2416 if (top == 0)
2417 return make_number (bot);
2418 if (top == (unsigned long)-1 >> 16)
2419 return Fcons (make_number (-1), make_number (bot));
2420 return Fcons (make_number (top), make_number (bot));
2423 unsigned long
2424 cons_to_long (c)
2425 Lisp_Object c;
2427 Lisp_Object top, bot;
2428 if (INTEGERP (c))
2429 return XINT (c);
2430 top = XCAR (c);
2431 bot = XCDR (c);
2432 if (CONSP (bot))
2433 bot = XCAR (bot);
2434 return ((XINT (top) << 16) | XINT (bot));
2437 DEFUN ("number-to-string", Fnumber_to_string, Snumber_to_string, 1, 1, 0,
2438 doc: /* Return the decimal representation of NUMBER as a string.
2439 Uses a minus sign if negative.
2440 NUMBER may be an integer or a floating point number. */)
2441 (number)
2442 Lisp_Object number;
2444 char buffer[VALBITS];
2446 CHECK_NUMBER_OR_FLOAT (number);
2448 if (FLOATP (number))
2450 char pigbuf[350]; /* see comments in float_to_string */
2452 float_to_string (pigbuf, XFLOAT_DATA (number));
2453 return build_string (pigbuf);
2456 if (sizeof (int) == sizeof (EMACS_INT))
2457 sprintf (buffer, "%d", (int) XINT (number));
2458 else if (sizeof (long) == sizeof (EMACS_INT))
2459 sprintf (buffer, "%ld", (long) XINT (number));
2460 else
2461 abort ();
2462 return build_string (buffer);
2465 INLINE static int
2466 digit_to_number (character, base)
2467 int character, base;
2469 int digit;
2471 if (character >= '0' && character <= '9')
2472 digit = character - '0';
2473 else if (character >= 'a' && character <= 'z')
2474 digit = character - 'a' + 10;
2475 else if (character >= 'A' && character <= 'Z')
2476 digit = character - 'A' + 10;
2477 else
2478 return -1;
2480 if (digit >= base)
2481 return -1;
2482 else
2483 return digit;
2486 DEFUN ("string-to-number", Fstring_to_number, Sstring_to_number, 1, 2, 0,
2487 doc: /* Parse STRING as a decimal number and return the number.
2488 This parses both integers and floating point numbers.
2489 It ignores leading spaces and tabs, and all trailing chars.
2491 If BASE, interpret STRING as a number in that base. If BASE isn't
2492 present, base 10 is used. BASE must be between 2 and 16 (inclusive).
2493 If the base used is not 10, STRING is always parsed as integer. */)
2494 (string, base)
2495 register Lisp_Object string, base;
2497 register unsigned char *p;
2498 register int b;
2499 int sign = 1;
2500 Lisp_Object val;
2502 CHECK_STRING (string);
2504 if (NILP (base))
2505 b = 10;
2506 else
2508 CHECK_NUMBER (base);
2509 b = XINT (base);
2510 if (b < 2 || b > 16)
2511 xsignal1 (Qargs_out_of_range, base);
2514 /* Skip any whitespace at the front of the number. Some versions of
2515 atoi do this anyway, so we might as well make Emacs lisp consistent. */
2516 p = SDATA (string);
2517 while (*p == ' ' || *p == '\t')
2518 p++;
2520 if (*p == '-')
2522 sign = -1;
2523 p++;
2525 else if (*p == '+')
2526 p++;
2528 if (isfloat_string (p, 1) && b == 10)
2529 val = make_float (sign * atof (p));
2530 else
2532 double v = 0;
2534 while (1)
2536 int digit = digit_to_number (*p++, b);
2537 if (digit < 0)
2538 break;
2539 v = v * b + digit;
2542 val = make_fixnum_or_float (sign * v);
2545 return val;
2549 enum arithop
2551 Aadd,
2552 Asub,
2553 Amult,
2554 Adiv,
2555 Alogand,
2556 Alogior,
2557 Alogxor,
2558 Amax,
2559 Amin
2562 static Lisp_Object float_arith_driver P_ ((double, int, enum arithop,
2563 int, Lisp_Object *));
2564 extern Lisp_Object fmod_float ();
2566 Lisp_Object
2567 arith_driver (code, nargs, args)
2568 enum arithop code;
2569 int nargs;
2570 register Lisp_Object *args;
2572 register Lisp_Object val;
2573 register int argnum;
2574 register EMACS_INT accum = 0;
2575 register EMACS_INT next;
2577 switch (SWITCH_ENUM_CAST (code))
2579 case Alogior:
2580 case Alogxor:
2581 case Aadd:
2582 case Asub:
2583 accum = 0;
2584 break;
2585 case Amult:
2586 accum = 1;
2587 break;
2588 case Alogand:
2589 accum = -1;
2590 break;
2591 default:
2592 break;
2595 for (argnum = 0; argnum < nargs; argnum++)
2597 /* Using args[argnum] as argument to CHECK_NUMBER_... */
2598 val = args[argnum];
2599 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val);
2601 if (FLOATP (val))
2602 return float_arith_driver ((double) accum, argnum, code,
2603 nargs, args);
2604 args[argnum] = val;
2605 next = XINT (args[argnum]);
2606 switch (SWITCH_ENUM_CAST (code))
2608 case Aadd:
2609 accum += next;
2610 break;
2611 case Asub:
2612 accum = argnum ? accum - next : nargs == 1 ? - next : next;
2613 break;
2614 case Amult:
2615 accum *= next;
2616 break;
2617 case Adiv:
2618 if (!argnum)
2619 accum = next;
2620 else
2622 if (next == 0)
2623 xsignal0 (Qarith_error);
2624 accum /= next;
2626 break;
2627 case Alogand:
2628 accum &= next;
2629 break;
2630 case Alogior:
2631 accum |= next;
2632 break;
2633 case Alogxor:
2634 accum ^= next;
2635 break;
2636 case Amax:
2637 if (!argnum || next > accum)
2638 accum = next;
2639 break;
2640 case Amin:
2641 if (!argnum || next < accum)
2642 accum = next;
2643 break;
2647 XSETINT (val, accum);
2648 return val;
2651 #undef isnan
2652 #define isnan(x) ((x) != (x))
2654 static Lisp_Object
2655 float_arith_driver (accum, argnum, code, nargs, args)
2656 double accum;
2657 register int argnum;
2658 enum arithop code;
2659 int nargs;
2660 register Lisp_Object *args;
2662 register Lisp_Object val;
2663 double next;
2665 for (; argnum < nargs; argnum++)
2667 val = args[argnum]; /* using args[argnum] as argument to CHECK_NUMBER_... */
2668 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val);
2670 if (FLOATP (val))
2672 next = XFLOAT_DATA (val);
2674 else
2676 args[argnum] = val; /* runs into a compiler bug. */
2677 next = XINT (args[argnum]);
2679 switch (SWITCH_ENUM_CAST (code))
2681 case Aadd:
2682 accum += next;
2683 break;
2684 case Asub:
2685 accum = argnum ? accum - next : nargs == 1 ? - next : next;
2686 break;
2687 case Amult:
2688 accum *= next;
2689 break;
2690 case Adiv:
2691 if (!argnum)
2692 accum = next;
2693 else
2695 if (! IEEE_FLOATING_POINT && next == 0)
2696 xsignal0 (Qarith_error);
2697 accum /= next;
2699 break;
2700 case Alogand:
2701 case Alogior:
2702 case Alogxor:
2703 return wrong_type_argument (Qinteger_or_marker_p, val);
2704 case Amax:
2705 if (!argnum || isnan (next) || next > accum)
2706 accum = next;
2707 break;
2708 case Amin:
2709 if (!argnum || isnan (next) || next < accum)
2710 accum = next;
2711 break;
2715 return make_float (accum);
2719 DEFUN ("+", Fplus, Splus, 0, MANY, 0,
2720 doc: /* Return sum of any number of arguments, which are numbers or markers.
2721 usage: (+ &rest NUMBERS-OR-MARKERS) */)
2722 (nargs, args)
2723 int nargs;
2724 Lisp_Object *args;
2726 return arith_driver (Aadd, nargs, args);
2729 DEFUN ("-", Fminus, Sminus, 0, MANY, 0,
2730 doc: /* Negate number or subtract numbers or markers and return the result.
2731 With one arg, negates it. With more than one arg,
2732 subtracts all but the first from the first.
2733 usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */)
2734 (nargs, args)
2735 int nargs;
2736 Lisp_Object *args;
2738 return arith_driver (Asub, nargs, args);
2741 DEFUN ("*", Ftimes, Stimes, 0, MANY, 0,
2742 doc: /* Return product of any number of arguments, which are numbers or markers.
2743 usage: (* &rest NUMBERS-OR-MARKERS) */)
2744 (nargs, args)
2745 int nargs;
2746 Lisp_Object *args;
2748 return arith_driver (Amult, nargs, args);
2751 DEFUN ("/", Fquo, Squo, 2, MANY, 0,
2752 doc: /* Return first argument divided by all the remaining arguments.
2753 The arguments must be numbers or markers.
2754 usage: (/ DIVIDEND DIVISOR &rest DIVISORS) */)
2755 (nargs, args)
2756 int nargs;
2757 Lisp_Object *args;
2759 int argnum;
2760 for (argnum = 2; argnum < nargs; argnum++)
2761 if (FLOATP (args[argnum]))
2762 return float_arith_driver (0, 0, Adiv, nargs, args);
2763 return arith_driver (Adiv, nargs, args);
2766 DEFUN ("%", Frem, Srem, 2, 2, 0,
2767 doc: /* Return remainder of X divided by Y.
2768 Both must be integers or markers. */)
2769 (x, y)
2770 register Lisp_Object x, y;
2772 Lisp_Object val;
2774 CHECK_NUMBER_COERCE_MARKER (x);
2775 CHECK_NUMBER_COERCE_MARKER (y);
2777 if (XFASTINT (y) == 0)
2778 xsignal0 (Qarith_error);
2780 XSETINT (val, XINT (x) % XINT (y));
2781 return val;
2784 #ifndef HAVE_FMOD
2785 double
2786 fmod (f1, f2)
2787 double f1, f2;
2789 double r = f1;
2791 if (f2 < 0.0)
2792 f2 = -f2;
2794 /* If the magnitude of the result exceeds that of the divisor, or
2795 the sign of the result does not agree with that of the dividend,
2796 iterate with the reduced value. This does not yield a
2797 particularly accurate result, but at least it will be in the
2798 range promised by fmod. */
2800 r -= f2 * floor (r / f2);
2801 while (f2 <= (r < 0 ? -r : r) || ((r < 0) != (f1 < 0) && ! isnan (r)));
2803 return r;
2805 #endif /* ! HAVE_FMOD */
2807 DEFUN ("mod", Fmod, Smod, 2, 2, 0,
2808 doc: /* Return X modulo Y.
2809 The result falls between zero (inclusive) and Y (exclusive).
2810 Both X and Y must be numbers or markers. */)
2811 (x, y)
2812 register Lisp_Object x, y;
2814 Lisp_Object val;
2815 EMACS_INT i1, i2;
2817 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x);
2818 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y);
2820 if (FLOATP (x) || FLOATP (y))
2821 return fmod_float (x, y);
2823 i1 = XINT (x);
2824 i2 = XINT (y);
2826 if (i2 == 0)
2827 xsignal0 (Qarith_error);
2829 i1 %= i2;
2831 /* If the "remainder" comes out with the wrong sign, fix it. */
2832 if (i2 < 0 ? i1 > 0 : i1 < 0)
2833 i1 += i2;
2835 XSETINT (val, i1);
2836 return val;
2839 DEFUN ("max", Fmax, Smax, 1, MANY, 0,
2840 doc: /* Return largest of all the arguments (which must be numbers or markers).
2841 The value is always a number; markers are converted to numbers.
2842 usage: (max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2843 (nargs, args)
2844 int nargs;
2845 Lisp_Object *args;
2847 return arith_driver (Amax, nargs, args);
2850 DEFUN ("min", Fmin, Smin, 1, MANY, 0,
2851 doc: /* Return smallest of all the arguments (which must be numbers or markers).
2852 The value is always a number; markers are converted to numbers.
2853 usage: (min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2854 (nargs, args)
2855 int nargs;
2856 Lisp_Object *args;
2858 return arith_driver (Amin, nargs, args);
2861 DEFUN ("logand", Flogand, Slogand, 0, MANY, 0,
2862 doc: /* Return bitwise-and of all the arguments.
2863 Arguments may be integers, or markers converted to integers.
2864 usage: (logand &rest INTS-OR-MARKERS) */)
2865 (nargs, args)
2866 int nargs;
2867 Lisp_Object *args;
2869 return arith_driver (Alogand, nargs, args);
2872 DEFUN ("logior", Flogior, Slogior, 0, MANY, 0,
2873 doc: /* Return bitwise-or of all the arguments.
2874 Arguments may be integers, or markers converted to integers.
2875 usage: (logior &rest INTS-OR-MARKERS) */)
2876 (nargs, args)
2877 int nargs;
2878 Lisp_Object *args;
2880 return arith_driver (Alogior, nargs, args);
2883 DEFUN ("logxor", Flogxor, Slogxor, 0, MANY, 0,
2884 doc: /* Return bitwise-exclusive-or of all the arguments.
2885 Arguments may be integers, or markers converted to integers.
2886 usage: (logxor &rest INTS-OR-MARKERS) */)
2887 (nargs, args)
2888 int nargs;
2889 Lisp_Object *args;
2891 return arith_driver (Alogxor, nargs, args);
2894 DEFUN ("ash", Fash, Sash, 2, 2, 0,
2895 doc: /* Return VALUE with its bits shifted left by COUNT.
2896 If COUNT is negative, shifting is actually to the right.
2897 In this case, the sign bit is duplicated. */)
2898 (value, count)
2899 register Lisp_Object value, count;
2901 register Lisp_Object val;
2903 CHECK_NUMBER (value);
2904 CHECK_NUMBER (count);
2906 if (XINT (count) >= BITS_PER_EMACS_INT)
2907 XSETINT (val, 0);
2908 else if (XINT (count) > 0)
2909 XSETINT (val, XINT (value) << XFASTINT (count));
2910 else if (XINT (count) <= -BITS_PER_EMACS_INT)
2911 XSETINT (val, XINT (value) < 0 ? -1 : 0);
2912 else
2913 XSETINT (val, XINT (value) >> -XINT (count));
2914 return val;
2917 DEFUN ("lsh", Flsh, Slsh, 2, 2, 0,
2918 doc: /* Return VALUE with its bits shifted left by COUNT.
2919 If COUNT is negative, shifting is actually to the right.
2920 In this case, zeros are shifted in on the left. */)
2921 (value, count)
2922 register Lisp_Object value, count;
2924 register Lisp_Object val;
2926 CHECK_NUMBER (value);
2927 CHECK_NUMBER (count);
2929 if (XINT (count) >= BITS_PER_EMACS_INT)
2930 XSETINT (val, 0);
2931 else if (XINT (count) > 0)
2932 XSETINT (val, (EMACS_UINT) XUINT (value) << XFASTINT (count));
2933 else if (XINT (count) <= -BITS_PER_EMACS_INT)
2934 XSETINT (val, 0);
2935 else
2936 XSETINT (val, (EMACS_UINT) XUINT (value) >> -XINT (count));
2937 return val;
2940 DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0,
2941 doc: /* Return NUMBER plus one. NUMBER may be a number or a marker.
2942 Markers are converted to integers. */)
2943 (number)
2944 register Lisp_Object number;
2946 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number);
2948 if (FLOATP (number))
2949 return (make_float (1.0 + XFLOAT_DATA (number)));
2951 XSETINT (number, XINT (number) + 1);
2952 return number;
2955 DEFUN ("1-", Fsub1, Ssub1, 1, 1, 0,
2956 doc: /* Return NUMBER minus one. NUMBER may be a number or a marker.
2957 Markers are converted to integers. */)
2958 (number)
2959 register Lisp_Object number;
2961 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number);
2963 if (FLOATP (number))
2964 return (make_float (-1.0 + XFLOAT_DATA (number)));
2966 XSETINT (number, XINT (number) - 1);
2967 return number;
2970 DEFUN ("lognot", Flognot, Slognot, 1, 1, 0,
2971 doc: /* Return the bitwise complement of NUMBER. NUMBER must be an integer. */)
2972 (number)
2973 register Lisp_Object number;
2975 CHECK_NUMBER (number);
2976 XSETINT (number, ~XINT (number));
2977 return number;
2980 DEFUN ("byteorder", Fbyteorder, Sbyteorder, 0, 0, 0,
2981 doc: /* Return the byteorder for the machine.
2982 Returns 66 (ASCII uppercase B) for big endian machines or 108 (ASCII
2983 lowercase l) for small endian machines. */)
2986 unsigned i = 0x04030201;
2987 int order = *(char *)&i == 1 ? 108 : 66;
2989 return make_number (order);
2994 void
2995 syms_of_data ()
2997 Lisp_Object error_tail, arith_tail;
2999 Qquote = intern_c_string ("quote");
3000 Qlambda = intern_c_string ("lambda");
3001 Qsubr = intern_c_string ("subr");
3002 Qerror_conditions = intern_c_string ("error-conditions");
3003 Qerror_message = intern_c_string ("error-message");
3004 Qtop_level = intern_c_string ("top-level");
3006 Qerror = intern_c_string ("error");
3007 Qquit = intern_c_string ("quit");
3008 Qwrong_type_argument = intern_c_string ("wrong-type-argument");
3009 Qargs_out_of_range = intern_c_string ("args-out-of-range");
3010 Qvoid_function = intern_c_string ("void-function");
3011 Qcyclic_function_indirection = intern_c_string ("cyclic-function-indirection");
3012 Qcyclic_variable_indirection = intern_c_string ("cyclic-variable-indirection");
3013 Qvoid_variable = intern_c_string ("void-variable");
3014 Qsetting_constant = intern_c_string ("setting-constant");
3015 Qinvalid_read_syntax = intern_c_string ("invalid-read-syntax");
3017 Qinvalid_function = intern_c_string ("invalid-function");
3018 Qwrong_number_of_arguments = intern_c_string ("wrong-number-of-arguments");
3019 Qno_catch = intern_c_string ("no-catch");
3020 Qend_of_file = intern_c_string ("end-of-file");
3021 Qarith_error = intern_c_string ("arith-error");
3022 Qbeginning_of_buffer = intern_c_string ("beginning-of-buffer");
3023 Qend_of_buffer = intern_c_string ("end-of-buffer");
3024 Qbuffer_read_only = intern_c_string ("buffer-read-only");
3025 Qtext_read_only = intern_c_string ("text-read-only");
3026 Qmark_inactive = intern_c_string ("mark-inactive");
3028 Qlistp = intern_c_string ("listp");
3029 Qconsp = intern_c_string ("consp");
3030 Qsymbolp = intern_c_string ("symbolp");
3031 Qkeywordp = intern_c_string ("keywordp");
3032 Qintegerp = intern_c_string ("integerp");
3033 Qnatnump = intern_c_string ("natnump");
3034 Qwholenump = intern_c_string ("wholenump");
3035 Qstringp = intern_c_string ("stringp");
3036 Qarrayp = intern_c_string ("arrayp");
3037 Qsequencep = intern_c_string ("sequencep");
3038 Qbufferp = intern_c_string ("bufferp");
3039 Qvectorp = intern_c_string ("vectorp");
3040 Qchar_or_string_p = intern_c_string ("char-or-string-p");
3041 Qmarkerp = intern_c_string ("markerp");
3042 Qbuffer_or_string_p = intern_c_string ("buffer-or-string-p");
3043 Qinteger_or_marker_p = intern_c_string ("integer-or-marker-p");
3044 Qboundp = intern_c_string ("boundp");
3045 Qfboundp = intern_c_string ("fboundp");
3047 Qfloatp = intern_c_string ("floatp");
3048 Qnumberp = intern_c_string ("numberp");
3049 Qnumber_or_marker_p = intern_c_string ("number-or-marker-p");
3051 Qchar_table_p = intern_c_string ("char-table-p");
3052 Qvector_or_char_table_p = intern_c_string ("vector-or-char-table-p");
3054 Qsubrp = intern_c_string ("subrp");
3055 Qunevalled = intern_c_string ("unevalled");
3056 Qmany = intern_c_string ("many");
3058 Qcdr = intern_c_string ("cdr");
3060 /* Handle automatic advice activation */
3061 Qad_advice_info = intern_c_string ("ad-advice-info");
3062 Qad_activate_internal = intern_c_string ("ad-activate-internal");
3064 error_tail = pure_cons (Qerror, Qnil);
3066 /* ERROR is used as a signaler for random errors for which nothing else is right */
3068 Fput (Qerror, Qerror_conditions,
3069 error_tail);
3070 Fput (Qerror, Qerror_message,
3071 make_pure_c_string ("error"));
3073 Fput (Qquit, Qerror_conditions,
3074 pure_cons (Qquit, Qnil));
3075 Fput (Qquit, Qerror_message,
3076 make_pure_c_string ("Quit"));
3078 Fput (Qwrong_type_argument, Qerror_conditions,
3079 pure_cons (Qwrong_type_argument, error_tail));
3080 Fput (Qwrong_type_argument, Qerror_message,
3081 make_pure_c_string ("Wrong type argument"));
3083 Fput (Qargs_out_of_range, Qerror_conditions,
3084 pure_cons (Qargs_out_of_range, error_tail));
3085 Fput (Qargs_out_of_range, Qerror_message,
3086 make_pure_c_string ("Args out of range"));
3088 Fput (Qvoid_function, Qerror_conditions,
3089 pure_cons (Qvoid_function, error_tail));
3090 Fput (Qvoid_function, Qerror_message,
3091 make_pure_c_string ("Symbol's function definition is void"));
3093 Fput (Qcyclic_function_indirection, Qerror_conditions,
3094 pure_cons (Qcyclic_function_indirection, error_tail));
3095 Fput (Qcyclic_function_indirection, Qerror_message,
3096 make_pure_c_string ("Symbol's chain of function indirections contains a loop"));
3098 Fput (Qcyclic_variable_indirection, Qerror_conditions,
3099 pure_cons (Qcyclic_variable_indirection, error_tail));
3100 Fput (Qcyclic_variable_indirection, Qerror_message,
3101 make_pure_c_string ("Symbol's chain of variable indirections contains a loop"));
3103 Qcircular_list = intern_c_string ("circular-list");
3104 staticpro (&Qcircular_list);
3105 Fput (Qcircular_list, Qerror_conditions,
3106 pure_cons (Qcircular_list, error_tail));
3107 Fput (Qcircular_list, Qerror_message,
3108 make_pure_c_string ("List contains a loop"));
3110 Fput (Qvoid_variable, Qerror_conditions,
3111 pure_cons (Qvoid_variable, error_tail));
3112 Fput (Qvoid_variable, Qerror_message,
3113 make_pure_c_string ("Symbol's value as variable is void"));
3115 Fput (Qsetting_constant, Qerror_conditions,
3116 pure_cons (Qsetting_constant, error_tail));
3117 Fput (Qsetting_constant, Qerror_message,
3118 make_pure_c_string ("Attempt to set a constant symbol"));
3120 Fput (Qinvalid_read_syntax, Qerror_conditions,
3121 pure_cons (Qinvalid_read_syntax, error_tail));
3122 Fput (Qinvalid_read_syntax, Qerror_message,
3123 make_pure_c_string ("Invalid read syntax"));
3125 Fput (Qinvalid_function, Qerror_conditions,
3126 pure_cons (Qinvalid_function, error_tail));
3127 Fput (Qinvalid_function, Qerror_message,
3128 make_pure_c_string ("Invalid function"));
3130 Fput (Qwrong_number_of_arguments, Qerror_conditions,
3131 pure_cons (Qwrong_number_of_arguments, error_tail));
3132 Fput (Qwrong_number_of_arguments, Qerror_message,
3133 make_pure_c_string ("Wrong number of arguments"));
3135 Fput (Qno_catch, Qerror_conditions,
3136 pure_cons (Qno_catch, error_tail));
3137 Fput (Qno_catch, Qerror_message,
3138 make_pure_c_string ("No catch for tag"));
3140 Fput (Qend_of_file, Qerror_conditions,
3141 pure_cons (Qend_of_file, error_tail));
3142 Fput (Qend_of_file, Qerror_message,
3143 make_pure_c_string ("End of file during parsing"));
3145 arith_tail = pure_cons (Qarith_error, error_tail);
3146 Fput (Qarith_error, Qerror_conditions,
3147 arith_tail);
3148 Fput (Qarith_error, Qerror_message,
3149 make_pure_c_string ("Arithmetic error"));
3151 Fput (Qbeginning_of_buffer, Qerror_conditions,
3152 pure_cons (Qbeginning_of_buffer, error_tail));
3153 Fput (Qbeginning_of_buffer, Qerror_message,
3154 make_pure_c_string ("Beginning of buffer"));
3156 Fput (Qend_of_buffer, Qerror_conditions,
3157 pure_cons (Qend_of_buffer, error_tail));
3158 Fput (Qend_of_buffer, Qerror_message,
3159 make_pure_c_string ("End of buffer"));
3161 Fput (Qbuffer_read_only, Qerror_conditions,
3162 pure_cons (Qbuffer_read_only, error_tail));
3163 Fput (Qbuffer_read_only, Qerror_message,
3164 make_pure_c_string ("Buffer is read-only"));
3166 Fput (Qtext_read_only, Qerror_conditions,
3167 pure_cons (Qtext_read_only, error_tail));
3168 Fput (Qtext_read_only, Qerror_message,
3169 make_pure_c_string ("Text is read-only"));
3171 Qrange_error = intern_c_string ("range-error");
3172 Qdomain_error = intern_c_string ("domain-error");
3173 Qsingularity_error = intern_c_string ("singularity-error");
3174 Qoverflow_error = intern_c_string ("overflow-error");
3175 Qunderflow_error = intern_c_string ("underflow-error");
3177 Fput (Qdomain_error, Qerror_conditions,
3178 pure_cons (Qdomain_error, arith_tail));
3179 Fput (Qdomain_error, Qerror_message,
3180 make_pure_c_string ("Arithmetic domain error"));
3182 Fput (Qrange_error, Qerror_conditions,
3183 pure_cons (Qrange_error, arith_tail));
3184 Fput (Qrange_error, Qerror_message,
3185 make_pure_c_string ("Arithmetic range error"));
3187 Fput (Qsingularity_error, Qerror_conditions,
3188 pure_cons (Qsingularity_error, Fcons (Qdomain_error, arith_tail)));
3189 Fput (Qsingularity_error, Qerror_message,
3190 make_pure_c_string ("Arithmetic singularity error"));
3192 Fput (Qoverflow_error, Qerror_conditions,
3193 pure_cons (Qoverflow_error, Fcons (Qdomain_error, arith_tail)));
3194 Fput (Qoverflow_error, Qerror_message,
3195 make_pure_c_string ("Arithmetic overflow error"));
3197 Fput (Qunderflow_error, Qerror_conditions,
3198 pure_cons (Qunderflow_error, Fcons (Qdomain_error, arith_tail)));
3199 Fput (Qunderflow_error, Qerror_message,
3200 make_pure_c_string ("Arithmetic underflow error"));
3202 staticpro (&Qrange_error);
3203 staticpro (&Qdomain_error);
3204 staticpro (&Qsingularity_error);
3205 staticpro (&Qoverflow_error);
3206 staticpro (&Qunderflow_error);
3208 staticpro (&Qnil);
3209 staticpro (&Qt);
3210 staticpro (&Qquote);
3211 staticpro (&Qlambda);
3212 staticpro (&Qsubr);
3213 staticpro (&Qunbound);
3214 staticpro (&Qerror_conditions);
3215 staticpro (&Qerror_message);
3216 staticpro (&Qtop_level);
3218 staticpro (&Qerror);
3219 staticpro (&Qquit);
3220 staticpro (&Qwrong_type_argument);
3221 staticpro (&Qargs_out_of_range);
3222 staticpro (&Qvoid_function);
3223 staticpro (&Qcyclic_function_indirection);
3224 staticpro (&Qcyclic_variable_indirection);
3225 staticpro (&Qvoid_variable);
3226 staticpro (&Qsetting_constant);
3227 staticpro (&Qinvalid_read_syntax);
3228 staticpro (&Qwrong_number_of_arguments);
3229 staticpro (&Qinvalid_function);
3230 staticpro (&Qno_catch);
3231 staticpro (&Qend_of_file);
3232 staticpro (&Qarith_error);
3233 staticpro (&Qbeginning_of_buffer);
3234 staticpro (&Qend_of_buffer);
3235 staticpro (&Qbuffer_read_only);
3236 staticpro (&Qtext_read_only);
3237 staticpro (&Qmark_inactive);
3239 staticpro (&Qlistp);
3240 staticpro (&Qconsp);
3241 staticpro (&Qsymbolp);
3242 staticpro (&Qkeywordp);
3243 staticpro (&Qintegerp);
3244 staticpro (&Qnatnump);
3245 staticpro (&Qwholenump);
3246 staticpro (&Qstringp);
3247 staticpro (&Qarrayp);
3248 staticpro (&Qsequencep);
3249 staticpro (&Qbufferp);
3250 staticpro (&Qvectorp);
3251 staticpro (&Qchar_or_string_p);
3252 staticpro (&Qmarkerp);
3253 staticpro (&Qbuffer_or_string_p);
3254 staticpro (&Qinteger_or_marker_p);
3255 staticpro (&Qfloatp);
3256 staticpro (&Qnumberp);
3257 staticpro (&Qnumber_or_marker_p);
3258 staticpro (&Qchar_table_p);
3259 staticpro (&Qvector_or_char_table_p);
3260 staticpro (&Qsubrp);
3261 staticpro (&Qmany);
3262 staticpro (&Qunevalled);
3264 staticpro (&Qboundp);
3265 staticpro (&Qfboundp);
3266 staticpro (&Qcdr);
3267 staticpro (&Qad_advice_info);
3268 staticpro (&Qad_activate_internal);
3270 /* Types that type-of returns. */
3271 Qinteger = intern_c_string ("integer");
3272 Qsymbol = intern_c_string ("symbol");
3273 Qstring = intern_c_string ("string");
3274 Qcons = intern_c_string ("cons");
3275 Qmarker = intern_c_string ("marker");
3276 Qoverlay = intern_c_string ("overlay");
3277 Qfloat = intern_c_string ("float");
3278 Qwindow_configuration = intern_c_string ("window-configuration");
3279 Qprocess = intern_c_string ("process");
3280 Qwindow = intern_c_string ("window");
3281 /* Qsubr = intern_c_string ("subr"); */
3282 Qcompiled_function = intern_c_string ("compiled-function");
3283 Qbuffer = intern_c_string ("buffer");
3284 Qframe = intern_c_string ("frame");
3285 Qvector = intern_c_string ("vector");
3286 Qchar_table = intern_c_string ("char-table");
3287 Qbool_vector = intern_c_string ("bool-vector");
3288 Qhash_table = intern_c_string ("hash-table");
3290 Qthread_local_mark = Fmake_symbol (make_pure_string ("thread-local-mark",
3291 17, 17, 0));
3293 DEFSYM (Qfont_spec, "font-spec");
3294 DEFSYM (Qfont_entity, "font-entity");
3295 DEFSYM (Qfont_object, "font-object");
3297 DEFSYM (Qinteractive_form, "interactive-form");
3299 staticpro (&Qinteger);
3300 staticpro (&Qsymbol);
3301 staticpro (&Qstring);
3302 staticpro (&Qcons);
3303 staticpro (&Qmarker);
3304 staticpro (&Qoverlay);
3305 staticpro (&Qfloat);
3306 staticpro (&Qwindow_configuration);
3307 staticpro (&Qprocess);
3308 staticpro (&Qwindow);
3309 /* staticpro (&Qsubr); */
3310 staticpro (&Qcompiled_function);
3311 staticpro (&Qbuffer);
3312 staticpro (&Qframe);
3313 staticpro (&Qvector);
3314 staticpro (&Qchar_table);
3315 staticpro (&Qbool_vector);
3316 staticpro (&Qhash_table);
3317 staticpro (&Qthread_local_mark);
3319 defsubr (&Sindirect_variable);
3320 defsubr (&Sinteractive_form);
3321 defsubr (&Seq);
3322 defsubr (&Snull);
3323 defsubr (&Stype_of);
3324 defsubr (&Slistp);
3325 defsubr (&Snlistp);
3326 defsubr (&Sconsp);
3327 defsubr (&Satom);
3328 defsubr (&Sintegerp);
3329 defsubr (&Sinteger_or_marker_p);
3330 defsubr (&Snumberp);
3331 defsubr (&Snumber_or_marker_p);
3332 defsubr (&Sfloatp);
3333 defsubr (&Snatnump);
3334 defsubr (&Ssymbolp);
3335 defsubr (&Skeywordp);
3336 defsubr (&Sstringp);
3337 defsubr (&Smultibyte_string_p);
3338 defsubr (&Svectorp);
3339 defsubr (&Schar_table_p);
3340 defsubr (&Svector_or_char_table_p);
3341 defsubr (&Sbool_vector_p);
3342 defsubr (&Sarrayp);
3343 defsubr (&Ssequencep);
3344 defsubr (&Sbufferp);
3345 defsubr (&Smarkerp);
3346 defsubr (&Ssubrp);
3347 defsubr (&Sbyte_code_function_p);
3348 defsubr (&Schar_or_string_p);
3349 defsubr (&Scar);
3350 defsubr (&Scdr);
3351 defsubr (&Scar_safe);
3352 defsubr (&Scdr_safe);
3353 defsubr (&Ssetcar);
3354 defsubr (&Ssetcdr);
3355 defsubr (&Ssymbol_function);
3356 defsubr (&Sindirect_function);
3357 defsubr (&Ssymbol_plist);
3358 defsubr (&Ssymbol_name);
3359 defsubr (&Smakunbound);
3360 defsubr (&Sfmakunbound);
3361 defsubr (&Sboundp);
3362 defsubr (&Sfboundp);
3363 defsubr (&Sfset);
3364 defsubr (&Sdefalias);
3365 defsubr (&Ssetplist);
3366 defsubr (&Ssymbol_value);
3367 defsubr (&Sset);
3368 defsubr (&Sdefault_boundp);
3369 defsubr (&Sdefault_value);
3370 defsubr (&Sset_default);
3371 defsubr (&Ssetq_default);
3372 defsubr (&Smake_variable_buffer_local);
3373 defsubr (&Smake_local_variable);
3374 defsubr (&Skill_local_variable);
3375 defsubr (&Smake_variable_frame_local);
3376 defsubr (&Slocal_variable_p);
3377 defsubr (&Slocal_variable_if_set_p);
3378 defsubr (&Svariable_binding_locus);
3379 #if 0 /* XXX Remove this. --lorentey */
3380 defsubr (&Sterminal_local_value);
3381 defsubr (&Sset_terminal_local_value);
3382 #endif
3383 defsubr (&Saref);
3384 defsubr (&Saset);
3385 defsubr (&Snumber_to_string);
3386 defsubr (&Sstring_to_number);
3387 defsubr (&Seqlsign);
3388 defsubr (&Slss);
3389 defsubr (&Sgtr);
3390 defsubr (&Sleq);
3391 defsubr (&Sgeq);
3392 defsubr (&Sneq);
3393 defsubr (&Szerop);
3394 defsubr (&Splus);
3395 defsubr (&Sminus);
3396 defsubr (&Stimes);
3397 defsubr (&Squo);
3398 defsubr (&Srem);
3399 defsubr (&Smod);
3400 defsubr (&Smax);
3401 defsubr (&Smin);
3402 defsubr (&Slogand);
3403 defsubr (&Slogior);
3404 defsubr (&Slogxor);
3405 defsubr (&Slsh);
3406 defsubr (&Sash);
3407 defsubr (&Sadd1);
3408 defsubr (&Ssub1);
3409 defsubr (&Slognot);
3410 defsubr (&Sbyteorder);
3411 defsubr (&Ssubr_arity);
3412 defsubr (&Ssubr_name);
3414 XSYMBOL (Qwholenump)->function = XSYMBOL (Qnatnump)->function;
3416 DEFVAR_LISP ("most-positive-fixnum", &Vmost_positive_fixnum,
3417 doc: /* The largest value that is representable in a Lisp integer. */);
3418 Vmost_positive_fixnum = make_number (MOST_POSITIVE_FIXNUM);
3419 XSYMBOL (intern_c_string ("most-positive-fixnum"))->constant = 1;
3421 DEFVAR_LISP ("most-negative-fixnum", &Vmost_negative_fixnum,
3422 doc: /* The smallest value that is representable in a Lisp integer. */);
3423 Vmost_negative_fixnum = make_number (MOST_NEGATIVE_FIXNUM);
3424 XSYMBOL (intern_c_string ("most-negative-fixnum"))->constant = 1;
3427 SIGTYPE
3428 arith_error (signo)
3429 int signo;
3431 sigsetmask (SIGEMPTYMASK);
3433 SIGNAL_THREAD_CHECK (signo);
3434 xsignal0 (Qarith_error);
3437 void
3438 init_data ()
3440 /* Don't do this if just dumping out.
3441 We don't want to call `signal' in this case
3442 so that we don't have trouble with dumping
3443 signal-delivering routines in an inconsistent state. */
3444 #ifndef CANNOT_DUMP
3445 if (!initialized)
3446 return;
3447 #endif /* CANNOT_DUMP */
3448 signal (SIGFPE, arith_error);
3450 #ifdef uts
3451 signal (SIGEMT, arith_error);
3452 #endif /* uts */
3455 /* arch-tag: 25879798-b84d-479a-9c89-7d148e2109f7
3456 (do not change this comment) */