now realvalue is a Lisp_ThreadLocal
[emacs.git] / src / data.c
blobc509afae01b6ed17739e53537ebb928343b63f66
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 (), Qthread_local_mark);
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))
1112 *find_variable_location (&indirect_variable (XSYMBOL (symbol))->value) = newval;
1113 else
1114 SET_SYMBOL_VALUE (symbol, newval);
1118 /* Set up SYMBOL to refer to its global binding.
1119 This makes it safe to alter the status of other bindings. */
1121 void
1122 swap_in_global_binding (symbol)
1123 Lisp_Object symbol;
1125 Lisp_Object valcontents = SYMBOL_VALUE (symbol);
1126 struct Lisp_Buffer_Local_Value *blv = XBUFFER_LOCAL_VALUE (valcontents);
1127 Lisp_Object cdr = BLOCAL_CDR (blv);
1129 /* Unload the previously loaded binding. */
1130 Fsetcdr (XCAR (cdr),
1131 do_symval_forwarding (blv->realvalue));
1133 /* Select the global binding in the symbol. */
1134 XSETCAR (cdr, cdr);
1135 store_symval_forwarding (symbol, blv->realvalue, XCDR (cdr), NULL);
1137 /* Indicate that the global binding is set up now. */
1138 BLOCAL_FRAME (blv) = Qnil;
1139 BLOCAL_BUFFER (blv) = Qnil;
1140 BLOCAL_CLEAR_FLAGS (blv);
1143 /* Set up the buffer-local symbol SYMBOL for validity in the current buffer.
1144 VALCONTENTS is the contents of its value cell,
1145 which points to a struct Lisp_Buffer_Local_Value.
1147 Return the value forwarded one step past the buffer-local stage.
1148 This could be another forwarding pointer. */
1150 static Lisp_Object
1151 swap_in_symval_forwarding (symbol, valcontents)
1152 Lisp_Object symbol, valcontents;
1154 register Lisp_Object tem1;
1156 tem1 = BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents));
1158 if (NILP (tem1)
1159 || current_buffer != XBUFFER (tem1)
1160 || (XBUFFER_LOCAL_VALUE (valcontents)->check_frame
1161 && ! EQ (selected_frame, BLOCAL_FRAME (XBUFFER_LOCAL_VALUE (valcontents)))))
1163 struct Lisp_Symbol *sym = XSYMBOL (symbol);
1164 if (sym->indirect_variable)
1166 sym = indirect_variable (sym);
1167 XSETSYMBOL (symbol, sym);
1170 /* Unload the previously loaded binding. */
1171 tem1 = XCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)));
1172 Fsetcdr (tem1,
1173 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue));
1174 /* Choose the new binding. */
1175 tem1 = assq_no_quit (symbol, BUF_LOCAL_VAR_ALIST (current_buffer));
1176 BLOCAL_CLEAR_FLAGS (XBUFFER_LOCAL_VALUE (valcontents));
1177 if (NILP (tem1))
1179 if (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
1180 tem1 = assq_no_quit (symbol, XFRAME (selected_frame)->param_alist);
1181 if (! NILP (tem1))
1182 BLOCAL_SET_FOUND_FOR_FRAME (XBUFFER_LOCAL_VALUE (valcontents));
1183 else
1184 tem1 = BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents));
1186 else
1187 BLOCAL_SET_FOUND_FOR_BUFFER (XBUFFER_LOCAL_VALUE (valcontents));
1189 /* Load the new binding. */
1190 XSETCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)), tem1);
1191 XSETBUFFER (BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents)), current_buffer);
1192 BLOCAL_FRAME (XBUFFER_LOCAL_VALUE (valcontents)) = selected_frame;
1193 store_symval_forwarding (symbol,
1194 XBUFFER_LOCAL_VALUE (valcontents)->realvalue,
1195 Fcdr (tem1), NULL);
1198 return XBUFFER_LOCAL_VALUE (valcontents)->realvalue;
1202 /* Find the value of a symbol, returning Qunbound if it's not bound.
1203 This is helpful for code which just wants to get a variable's value
1204 if it has one, without signaling an error.
1205 Note that it must not be possible to quit
1206 within this function. Great care is required for this. */
1208 Lisp_Object
1209 find_symbol_value (symbol)
1210 Lisp_Object symbol;
1212 register Lisp_Object valcontents;
1213 register Lisp_Object val;
1215 CHECK_SYMBOL (symbol);
1216 valcontents = SYMBOL_VALUE (symbol);
1218 if (BUFFER_LOCAL_VALUEP (valcontents))
1219 valcontents = swap_in_symval_forwarding (symbol, valcontents);
1221 return do_symval_forwarding (valcontents);
1224 DEFUN ("symbol-value", Fsymbol_value, Ssymbol_value, 1, 1, 0,
1225 doc: /* Return SYMBOL's value. Error if that is void. */)
1226 (symbol)
1227 Lisp_Object symbol;
1229 Lisp_Object val;
1231 val = find_symbol_value (symbol);
1232 if (!EQ (val, Qunbound))
1233 return val;
1235 xsignal1 (Qvoid_variable, symbol);
1238 DEFUN ("set", Fset, Sset, 2, 2, 0,
1239 doc: /* Set SYMBOL's value to NEWVAL, and return NEWVAL. */)
1240 (symbol, newval)
1241 register Lisp_Object symbol, newval;
1243 return set_internal (symbol, newval, current_buffer, 0);
1246 /* Return 1 if SYMBOL currently has a let-binding
1247 which was made in the buffer that is now current. */
1249 static int
1250 let_shadows_buffer_binding_p (symbol)
1251 struct Lisp_Symbol *symbol;
1253 volatile struct specbinding *p;
1255 for (p = specpdl_ptr - 1; p >= specpdl; p--)
1256 if (p->func == NULL
1257 && CONSP (p->symbol))
1259 struct Lisp_Symbol *let_bound_symbol = XSYMBOL (XCAR (p->symbol));
1260 if ((symbol == let_bound_symbol
1261 || (let_bound_symbol->indirect_variable
1262 && symbol == indirect_variable (let_bound_symbol)))
1263 && XBUFFER (XCDR (XCDR (p->symbol))) == current_buffer)
1264 break;
1267 return p >= specpdl;
1270 /* Store the value NEWVAL into SYMBOL.
1271 If buffer-locality is an issue, BUF specifies which buffer to use.
1272 (0 stands for the current buffer.)
1274 If BINDFLAG is zero, then if this symbol is supposed to become
1275 local in every buffer where it is set, then we make it local.
1276 If BINDFLAG is nonzero, we don't do that. */
1278 Lisp_Object
1279 set_internal (symbol, newval, buf, bindflag)
1280 register Lisp_Object symbol, newval;
1281 struct buffer *buf;
1282 int bindflag;
1284 int voide = EQ (newval, Qunbound);
1286 register Lisp_Object valcontents, innercontents, tem1, current_alist_element;
1288 if (buf == 0)
1289 buf = current_buffer;
1291 /* If restoring in a dead buffer, do nothing. */
1292 if (NILP (BUF_NAME (buf)))
1293 return newval;
1295 CHECK_SYMBOL (symbol);
1296 if (SYMBOL_CONSTANT_P (symbol)
1297 && (NILP (Fkeywordp (symbol))
1298 || !EQ (newval, SYMBOL_VALUE (symbol))))
1299 xsignal1 (Qsetting_constant, symbol);
1301 innercontents = valcontents = SYMBOL_VALUE (symbol);
1303 if (BUFFER_OBJFWDP (valcontents))
1305 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1306 int idx = PER_BUFFER_IDX (offset);
1307 if (idx > 0
1308 && !bindflag
1309 && !let_shadows_buffer_binding_p (XSYMBOL (symbol)))
1310 SET_PER_BUFFER_VALUE_P (buf, idx, 1);
1312 else if (BUFFER_LOCAL_VALUEP (valcontents))
1314 /* valcontents is a struct Lisp_Buffer_Local_Value. */
1315 if (XSYMBOL (symbol)->indirect_variable)
1316 XSETSYMBOL (symbol, indirect_variable (XSYMBOL (symbol)));
1318 /* What binding is loaded right now? */
1319 current_alist_element
1320 = XCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)));
1322 /* If the current buffer is not the buffer whose binding is
1323 loaded, or if there may be frame-local bindings and the frame
1324 isn't the right one, or if it's a Lisp_Buffer_Local_Value and
1325 the default binding is loaded, the loaded binding may be the
1326 wrong one. */
1327 if (!BUFFERP (BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents)))
1328 || buf != XBUFFER (BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents)))
1329 || (XBUFFER_LOCAL_VALUE (valcontents)->check_frame
1330 && !EQ (selected_frame, BLOCAL_FRAME (XBUFFER_LOCAL_VALUE (valcontents))))
1331 /* Also unload a global binding (if the var is local_if_set). */
1332 || (EQ (XCAR (current_alist_element),
1333 current_alist_element)))
1335 /* The currently loaded binding is not necessarily valid.
1336 We need to unload it, and choose a new binding. */
1338 /* Write out `realvalue' to the old loaded binding. */
1339 Fsetcdr (current_alist_element,
1340 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue));
1342 /* Find the new binding. */
1343 tem1 = Fassq (symbol, BUF_LOCAL_VAR_ALIST (buf));
1344 BLOCAL_SET_FOUND_FOR_BUFFER (XBUFFER_LOCAL_VALUE (valcontents));
1346 if (NILP (tem1))
1348 /* This buffer still sees the default value. */
1350 /* If the variable is not local_if_set,
1351 or if this is `let' rather than `set',
1352 make CURRENT-ALIST-ELEMENT point to itself,
1353 indicating that we're seeing the default value.
1354 Likewise if the variable has been let-bound
1355 in the current buffer. */
1356 if (bindflag || !XBUFFER_LOCAL_VALUE (valcontents)->local_if_set
1357 || let_shadows_buffer_binding_p (XSYMBOL (symbol)))
1359 BLOCAL_CLEAR_FLAGS (XBUFFER_LOCAL_VALUE (valcontents));
1361 if (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
1362 tem1 = Fassq (symbol,
1363 XFRAME (selected_frame)->param_alist);
1365 if (! NILP (tem1))
1366 BLOCAL_SET_FOUND_FOR_FRAME (XBUFFER_LOCAL_VALUE (valcontents));
1367 else
1368 tem1 = BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents));
1370 /* If it's a Lisp_Buffer_Local_Value, being set not bound,
1371 and we're not within a let that was made for this buffer,
1372 create a new buffer-local binding for the variable.
1373 That means, give this buffer a new assoc for a local value
1374 and load that binding. */
1375 else
1377 tem1 = Fcons (symbol, XCDR (current_alist_element));
1378 BUF_LOCAL_VAR_ALIST (buf)
1379 = Fcons (tem1, BUF_LOCAL_VAR_ALIST (buf));
1383 /* Record which binding is now loaded. */
1384 XSETCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)), tem1);
1386 /* Set `buffer' and `frame' slots for the binding now loaded. */
1387 XSETBUFFER (BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents)), buf);
1388 BLOCAL_FRAME (XBUFFER_LOCAL_VALUE (valcontents)) = selected_frame;
1390 innercontents = BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (valcontents));
1392 /* Store the new value in the cons-cell. */
1393 XSETCDR (XCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents))), newval);
1396 /* If storing void (making the symbol void), forward only through
1397 buffer-local indicator, not through Lisp_Objfwd, etc. */
1398 if (voide)
1399 store_symval_forwarding (symbol, Qnil, newval, buf);
1400 else
1401 store_symval_forwarding (symbol, innercontents, newval, buf);
1403 return newval;
1406 /* Access or set a buffer-local symbol's default value. */
1408 /* Return the default value of SYMBOL, but don't check for voidness.
1409 Return Qunbound if it is void. */
1411 Lisp_Object
1412 default_value (symbol)
1413 Lisp_Object symbol;
1415 register Lisp_Object valcontents;
1417 CHECK_SYMBOL (symbol);
1418 valcontents = SYMBOL_VALUE (symbol);
1420 /* For a built-in buffer-local variable, get the default value
1421 rather than letting do_symval_forwarding get the current value. */
1422 if (BUFFER_OBJFWDP (valcontents))
1424 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1425 if (PER_BUFFER_IDX (offset) != 0)
1426 return PER_BUFFER_DEFAULT (offset);
1429 /* Handle user-created local variables. */
1430 if (BUFFER_LOCAL_VALUEP (valcontents))
1432 /* If var is set up for a buffer that lacks a local value for it,
1433 the current value is nominally the default value.
1434 But the `realvalue' slot may be more up to date, since
1435 ordinary setq stores just that slot. So use that. */
1436 Lisp_Object current_alist_element, alist_element_car;
1437 current_alist_element
1438 = XCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)));
1439 alist_element_car = XCAR (current_alist_element);
1440 if (EQ (alist_element_car, current_alist_element))
1441 return do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents)->realvalue);
1442 else
1443 return XCDR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)));
1445 /* For other variables, get the current value. */
1446 return do_symval_forwarding (valcontents);
1449 DEFUN ("default-boundp", Fdefault_boundp, Sdefault_boundp, 1, 1, 0,
1450 doc: /* Return t if SYMBOL has a non-void default value.
1451 This is the value that is seen in buffers that do not have their own values
1452 for this variable. */)
1453 (symbol)
1454 Lisp_Object symbol;
1456 register Lisp_Object value;
1458 value = default_value (symbol);
1459 return (EQ (value, Qunbound) ? Qnil : Qt);
1462 DEFUN ("default-value", Fdefault_value, Sdefault_value, 1, 1, 0,
1463 doc: /* Return SYMBOL's default value.
1464 This is the value that is seen in buffers that do not have their own values
1465 for this variable. The default value is meaningful for variables with
1466 local bindings in certain buffers. */)
1467 (symbol)
1468 Lisp_Object symbol;
1470 register Lisp_Object value;
1472 value = default_value (symbol);
1473 if (!EQ (value, Qunbound))
1474 return value;
1476 xsignal1 (Qvoid_variable, symbol);
1479 DEFUN ("set-default", Fset_default, Sset_default, 2, 2, 0,
1480 doc: /* Set SYMBOL's default value to VALUE. SYMBOL and VALUE are evaluated.
1481 The default value is seen in buffers that do not have their own values
1482 for this variable. */)
1483 (symbol, value)
1484 Lisp_Object symbol, value;
1486 register Lisp_Object valcontents, current_alist_element, alist_element_buffer;
1488 CHECK_SYMBOL (symbol);
1489 valcontents = SYMBOL_VALUE (symbol);
1491 /* Handle variables like case-fold-search that have special slots
1492 in the buffer. Make them work apparently like Lisp_Buffer_Local_Value
1493 variables. */
1494 if (BUFFER_OBJFWDP (valcontents))
1496 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1497 int idx = PER_BUFFER_IDX (offset);
1499 PER_BUFFER_DEFAULT (offset) = value;
1501 /* If this variable is not always local in all buffers,
1502 set it in the buffers that don't nominally have a local value. */
1503 if (idx > 0)
1505 struct buffer *b;
1507 for (b = all_buffers; b; b = b->next)
1508 if (!PER_BUFFER_VALUE_P (b, idx))
1509 PER_BUFFER_VALUE (b, offset) = value;
1511 return value;
1514 if (!BUFFER_LOCAL_VALUEP (valcontents))
1515 return Fset (symbol, value);
1517 /* Store new value into the DEFAULT-VALUE slot. */
1518 XSETCDR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)), value);
1520 /* If the default binding is now loaded, set the REALVALUE slot too. */
1521 current_alist_element
1522 = XCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)));
1523 alist_element_buffer = Fcar (current_alist_element);
1524 if (EQ (alist_element_buffer, current_alist_element))
1525 store_symval_forwarding (symbol,
1526 XBUFFER_LOCAL_VALUE (valcontents)->realvalue,
1527 value, NULL);
1529 return value;
1532 DEFUN ("setq-default", Fsetq_default, Ssetq_default, 0, UNEVALLED, 0,
1533 doc: /* Set the default value of variable VAR to VALUE.
1534 VAR, the variable name, is literal (not evaluated);
1535 VALUE is an expression: it is evaluated and its value returned.
1536 The default value of a variable is seen in buffers
1537 that do not have their own values for the variable.
1539 More generally, you can use multiple variables and values, as in
1540 (setq-default VAR VALUE VAR VALUE...)
1541 This sets each VAR's default value to the corresponding VALUE.
1542 The VALUE for the Nth VAR can refer to the new default values
1543 of previous VARs.
1544 usage: (setq-default [VAR VALUE]...) */)
1545 (args)
1546 Lisp_Object args;
1548 register Lisp_Object args_left;
1549 register Lisp_Object val, symbol;
1550 struct gcpro gcpro1;
1552 if (NILP (args))
1553 return Qnil;
1555 args_left = args;
1556 GCPRO1 (args);
1560 val = Feval (Fcar (Fcdr (args_left)));
1561 symbol = XCAR (args_left);
1562 Fset_default (symbol, val);
1563 args_left = Fcdr (XCDR (args_left));
1565 while (!NILP (args_left));
1567 UNGCPRO;
1568 return val;
1571 /* Lisp functions for creating and removing buffer-local variables. */
1573 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local, Smake_variable_buffer_local,
1574 1, 1, "vMake Variable Buffer Local: ",
1575 doc: /* Make VARIABLE become buffer-local whenever it is set.
1576 At any time, the value for the current buffer is in effect,
1577 unless the variable has never been set in this buffer,
1578 in which case the default value is in effect.
1579 Note that binding the variable with `let', or setting it while
1580 a `let'-style binding made in this buffer is in effect,
1581 does not make the variable buffer-local. Return VARIABLE.
1583 In most cases it is better to use `make-local-variable',
1584 which makes a variable local in just one buffer.
1586 The function `default-value' gets the default value and `set-default' sets it. */)
1587 (variable)
1588 register Lisp_Object variable;
1590 register Lisp_Object tem, valcontents, newval;
1591 struct Lisp_Symbol *sym;
1593 CHECK_SYMBOL (variable);
1594 sym = indirect_variable (XSYMBOL (variable));
1596 valcontents = sym->value;
1597 if (sym->constant || KBOARD_OBJFWDP (valcontents))
1598 error ("Symbol %s may not be buffer-local", SDATA (sym->xname));
1600 if (BUFFER_OBJFWDP (valcontents))
1601 return variable;
1602 else if (BUFFER_LOCAL_VALUEP (valcontents))
1604 if (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
1605 error ("Symbol %s may not be buffer-local", SDATA (sym->xname));
1606 newval = valcontents;
1608 else
1610 Lisp_Object len, val_vec;
1611 XSETFASTINT (len, 4);
1612 val_vec = Fmake_vector (len, Qnil);
1613 if (EQ (valcontents, Qunbound))
1614 sym->value = Qnil;
1615 tem = Fcons (Qnil, Fsymbol_value (variable));
1616 XSETCAR (tem, tem);
1617 newval = allocate_misc ();
1618 XMISCTYPE (newval) = Lisp_Misc_Buffer_Local_Value;
1619 XBUFFER_LOCAL_VALUE (newval)->thread_data = Qnil;
1620 BLOCAL_CLEAR_FLAGS_VEC (val_vec);
1621 BLOCAL_BUFFER_VEC (val_vec) = Fcurrent_buffer ();
1622 BLOCAL_FRAME_VEC (val_vec) = Qnil;
1623 BLOCAL_CDR_VEC (val_vec) = tem;
1624 XBUFFER_LOCAL_VALUE (newval)->check_frame = 0;
1625 BLOCAL_SET_THREAD_DATA (XBUFFER_LOCAL_VALUE (newval), val_vec);
1626 XBUFFER_LOCAL_VALUE (newval)->realvalue = allocate_misc ();
1627 XMISCTYPE (XBUFFER_LOCAL_VALUE (newval)->realvalue)
1628 = Lisp_Misc_ThreadLocal;
1629 XTHREADLOCAL (XBUFFER_LOCAL_VALUE (newval)->realvalue)->global = Qnil;
1630 XTHREADLOCAL (XBUFFER_LOCAL_VALUE (newval)->realvalue)->thread_alist
1631 = Fcons (Fcons (get_current_thread (), Qnil), Qnil);
1632 BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (newval)) = sym->value;
1633 sym->value = newval;
1635 XBUFFER_LOCAL_VALUE (newval)->local_if_set = 1;
1636 return variable;
1639 DEFUN ("make-local-variable", Fmake_local_variable, Smake_local_variable,
1640 1, 1, "vMake Local Variable: ",
1641 doc: /* Make VARIABLE have a separate value in the current buffer.
1642 Other buffers will continue to share a common default value.
1643 \(The buffer-local value of VARIABLE starts out as the same value
1644 VARIABLE previously had. If VARIABLE was void, it remains void.\)
1645 Return VARIABLE.
1647 If the variable is already arranged to become local when set,
1648 this function causes a local value to exist for this buffer,
1649 just as setting the variable would do.
1651 This function returns VARIABLE, and therefore
1652 (set (make-local-variable 'VARIABLE) VALUE-EXP)
1653 works.
1655 See also `make-variable-buffer-local'.
1657 Do not use `make-local-variable' to make a hook variable buffer-local.
1658 Instead, use `add-hook' and specify t for the LOCAL argument. */)
1659 (variable)
1660 register Lisp_Object variable;
1662 register Lisp_Object tem, valcontents;
1663 struct Lisp_Symbol *sym;
1665 CHECK_SYMBOL (variable);
1666 sym = indirect_variable (XSYMBOL (variable));
1668 valcontents = sym->value;
1669 if (sym->constant || KBOARD_OBJFWDP (valcontents)
1670 || (BUFFER_LOCAL_VALUEP (valcontents)
1671 && (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)))
1672 error ("Symbol %s may not be buffer-local", SDATA (sym->xname));
1674 if ((BUFFER_LOCAL_VALUEP (valcontents)
1675 && XBUFFER_LOCAL_VALUE (valcontents)->local_if_set)
1676 || BUFFER_OBJFWDP (valcontents))
1678 tem = Fboundp (variable);
1680 /* Make sure the symbol has a local value in this particular buffer,
1681 by setting it to the same value it already has. */
1682 Fset (variable, (EQ (tem, Qt) ? Fsymbol_value (variable) : Qunbound));
1683 return variable;
1685 /* Make sure symbol is set up to hold per-buffer values. */
1686 if (!BUFFER_LOCAL_VALUEP (valcontents))
1688 Lisp_Object newval, len, val_vec;
1689 XSETFASTINT (len, 4);
1690 val_vec = Fmake_vector (len, Qnil);
1691 tem = Fcons (Qnil, do_symval_forwarding (valcontents));
1692 XSETCAR (tem, tem);
1693 newval = allocate_misc ();
1694 XMISCTYPE (newval) = Lisp_Misc_Buffer_Local_Value;
1695 XBUFFER_LOCAL_VALUE (newval)->thread_data = Qnil;
1696 BLOCAL_BUFFER_VEC (val_vec) = Qnil;
1697 BLOCAL_FRAME_VEC (val_vec) = Qnil;
1698 BLOCAL_CDR_VEC (val_vec) = tem;
1699 XBUFFER_LOCAL_VALUE (newval)->local_if_set = 0;
1700 XBUFFER_LOCAL_VALUE (newval)->check_frame = 0;
1701 BLOCAL_SET_THREAD_DATA (XBUFFER_LOCAL_VALUE (newval), val_vec);
1702 XBUFFER_LOCAL_VALUE (newval)->realvalue = allocate_misc ();
1703 XMISCTYPE (XBUFFER_LOCAL_VALUE (newval)->realvalue)
1704 = Lisp_Misc_ThreadLocal;
1705 XTHREADLOCAL (XBUFFER_LOCAL_VALUE (newval)->realvalue)->global = Qnil;
1706 XTHREADLOCAL (XBUFFER_LOCAL_VALUE (newval)->realvalue)->thread_alist
1707 = Fcons (Fcons (get_current_thread (), Qnil), Qnil);
1708 BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (newval)) = sym->value;
1709 sym->value = newval;
1711 /* Make sure this buffer has its own value of symbol. */
1712 XSETSYMBOL (variable, sym); /* Propagate variable indirections. */
1713 tem = Fassq (variable, BUF_LOCAL_VAR_ALIST (current_buffer));
1714 if (NILP (tem))
1716 /* Swap out any local binding for some other buffer, and make
1717 sure the current value is permanently recorded, if it's the
1718 default value. */
1719 find_symbol_value (variable);
1721 BUF_LOCAL_VAR_ALIST (current_buffer)
1722 = Fcons (Fcons (variable, XCDR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (sym->value)))),
1723 BUF_LOCAL_VAR_ALIST (current_buffer));
1725 /* Make sure symbol does not think it is set up for this buffer;
1726 force it to look once again for this buffer's value. */
1728 Lisp_Object *pvalbuf;
1730 valcontents = sym->value;
1732 pvalbuf = &BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents));
1733 if (current_buffer == XBUFFER (*pvalbuf))
1734 *pvalbuf = Qnil;
1735 BLOCAL_CLEAR_FLAGS (XBUFFER_LOCAL_VALUE (valcontents));
1739 /* If the symbol forwards into a C variable, then load the binding
1740 for this buffer now. If C code modifies the variable before we
1741 load the binding in, then that new value will clobber the default
1742 binding the next time we unload it. */
1743 valcontents = XBUFFER_LOCAL_VALUE (sym->value)->realvalue;
1744 if (INTFWDP (valcontents) || BOOLFWDP (valcontents) || OBJFWDP (valcontents))
1745 swap_in_symval_forwarding (variable, sym->value);
1747 return variable;
1750 DEFUN ("kill-local-variable", Fkill_local_variable, Skill_local_variable,
1751 1, 1, "vKill Local Variable: ",
1752 doc: /* Make VARIABLE no longer have a separate value in the current buffer.
1753 From now on the default value will apply in this buffer. Return VARIABLE. */)
1754 (variable)
1755 register Lisp_Object variable;
1757 register Lisp_Object tem, valcontents;
1758 struct Lisp_Symbol *sym;
1760 CHECK_SYMBOL (variable);
1761 sym = indirect_variable (XSYMBOL (variable));
1763 valcontents = sym->value;
1765 if (BUFFER_OBJFWDP (valcontents))
1767 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1768 int idx = PER_BUFFER_IDX (offset);
1770 if (idx > 0)
1772 SET_PER_BUFFER_VALUE_P (current_buffer, idx, 0);
1773 PER_BUFFER_VALUE (current_buffer, offset)
1774 = PER_BUFFER_DEFAULT (offset);
1776 return variable;
1779 if (!BUFFER_LOCAL_VALUEP (valcontents))
1780 return variable;
1782 /* Get rid of this buffer's alist element, if any. */
1783 XSETSYMBOL (variable, sym); /* Propagate variable indirection. */
1784 tem = Fassq (variable, BUF_LOCAL_VAR_ALIST (current_buffer));
1785 if (!NILP (tem))
1786 BUF_LOCAL_VAR_ALIST (current_buffer)
1787 = Fdelq (tem, BUF_LOCAL_VAR_ALIST (current_buffer));
1789 /* If the symbol is set up with the current buffer's binding
1790 loaded, recompute its value. We have to do it now, or else
1791 forwarded objects won't work right. */
1793 Lisp_Object *pvalbuf, buf;
1794 valcontents = sym->value;
1795 pvalbuf = &BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents));
1796 XSETBUFFER (buf, current_buffer);
1797 if (EQ (buf, *pvalbuf))
1799 *pvalbuf = Qnil;
1800 BLOCAL_CLEAR_FLAGS (XBUFFER_LOCAL_VALUE (valcontents));
1801 find_symbol_value (variable);
1805 return variable;
1808 /* Lisp functions for creating and removing buffer-local variables. */
1810 /* Obsolete since 22.2. NB adjust doc of modify-frame-parameters
1811 when/if this is removed. */
1813 DEFUN ("make-variable-frame-local", Fmake_variable_frame_local, Smake_variable_frame_local,
1814 1, 1, "vMake Variable Frame Local: ",
1815 doc: /* Enable VARIABLE to have frame-local bindings.
1816 This does not create any frame-local bindings for VARIABLE,
1817 it just makes them possible.
1819 A frame-local binding is actually a frame parameter value.
1820 If a frame F has a value for the frame parameter named VARIABLE,
1821 that also acts as a frame-local binding for VARIABLE in F--
1822 provided this function has been called to enable VARIABLE
1823 to have frame-local bindings at all.
1825 The only way to create a frame-local binding for VARIABLE in a frame
1826 is to set the VARIABLE frame parameter of that frame. See
1827 `modify-frame-parameters' for how to set frame parameters.
1829 Note that since Emacs 23.1, variables cannot be both buffer-local and
1830 frame-local any more (buffer-local bindings used to take precedence over
1831 frame-local bindings). */)
1832 (variable)
1833 register Lisp_Object variable;
1835 register Lisp_Object tem, valcontents, newval, val_vec, len;
1836 struct Lisp_Symbol *sym;
1838 CHECK_SYMBOL (variable);
1839 sym = indirect_variable (XSYMBOL (variable));
1841 valcontents = sym->value;
1842 if (sym->constant || KBOARD_OBJFWDP (valcontents)
1843 || BUFFER_OBJFWDP (valcontents))
1844 error ("Symbol %s may not be frame-local", SDATA (sym->xname));
1846 if (BUFFER_LOCAL_VALUEP (valcontents))
1848 if (!XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
1849 error ("Symbol %s may not be frame-local", SDATA (sym->xname));
1850 return variable;
1853 if (EQ (valcontents, Qunbound))
1854 sym->value = Qnil;
1855 tem = Fcons (Qnil, Fsymbol_value (variable));
1856 XSETCAR (tem, tem);
1857 newval = allocate_misc ();
1858 XSETFASTINT (len, 4);
1859 val_vec = Fmake_vector (len, Qnil);
1860 XMISCTYPE (newval) = Lisp_Misc_Buffer_Local_Value;
1861 XBUFFER_LOCAL_VALUE (newval)->thread_data = Qnil;
1862 BLOCAL_CLEAR_FLAGS_VEC (val_vec);
1863 BLOCAL_BUFFER_VEC (val_vec) = Qnil;
1864 BLOCAL_FRAME_VEC (val_vec) = Qnil;
1865 BLOCAL_CDR_VEC (val_vec) = tem;
1866 XBUFFER_LOCAL_VALUE (newval)->local_if_set = 0;
1867 XBUFFER_LOCAL_VALUE (newval)->check_frame = 1;
1868 BLOCAL_SET_THREAD_DATA (XBUFFER_LOCAL_VALUE (newval), val_vec);
1869 XBUFFER_LOCAL_VALUE (newval)->realvalue = allocate_misc ();
1870 XMISCTYPE (XBUFFER_LOCAL_VALUE (newval)->realvalue)
1871 = Lisp_Misc_ThreadLocal;
1872 XTHREADLOCAL (XBUFFER_LOCAL_VALUE (newval)->realvalue)->global = Qnil;
1873 XTHREADLOCAL (XBUFFER_LOCAL_VALUE (newval)->realvalue)->thread_alist
1874 = Fcons (Fcons (get_current_thread (), Qnil), Qnil);
1875 BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (newval)) = sym->value;
1876 sym->value = newval;
1877 return variable;
1880 DEFUN ("local-variable-p", Flocal_variable_p, Slocal_variable_p,
1881 1, 2, 0,
1882 doc: /* Non-nil if VARIABLE has a local binding in buffer BUFFER.
1883 BUFFER defaults to the current buffer. */)
1884 (variable, buffer)
1885 register Lisp_Object variable, buffer;
1887 Lisp_Object valcontents;
1888 register struct buffer *buf;
1889 struct Lisp_Symbol *sym;
1891 if (NILP (buffer))
1892 buf = current_buffer;
1893 else
1895 CHECK_BUFFER (buffer);
1896 buf = XBUFFER (buffer);
1899 CHECK_SYMBOL (variable);
1900 sym = indirect_variable (XSYMBOL (variable));
1901 XSETSYMBOL (variable, sym);
1903 valcontents = sym->value;
1904 if (BUFFER_LOCAL_VALUEP (valcontents))
1906 Lisp_Object tail, elt;
1908 for (tail = BUF_LOCAL_VAR_ALIST (buf); CONSP (tail); tail = XCDR (tail))
1910 elt = XCAR (tail);
1911 if (EQ (variable, XCAR (elt)))
1912 return Qt;
1915 if (BUFFER_OBJFWDP (valcontents))
1917 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1918 int idx = PER_BUFFER_IDX (offset);
1919 if (idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
1920 return Qt;
1922 return Qnil;
1925 DEFUN ("local-variable-if-set-p", Flocal_variable_if_set_p, Slocal_variable_if_set_p,
1926 1, 2, 0,
1927 doc: /* Non-nil if VARIABLE will be local in buffer BUFFER when set there.
1928 More precisely, this means that setting the variable \(with `set' or`setq'),
1929 while it does not have a `let'-style binding that was made in BUFFER,
1930 will produce a buffer local binding. See Info node
1931 `(elisp)Creating Buffer-Local'.
1932 BUFFER defaults to the current buffer. */)
1933 (variable, buffer)
1934 register Lisp_Object variable, buffer;
1936 Lisp_Object valcontents;
1937 register struct buffer *buf;
1938 struct Lisp_Symbol *sym;
1940 if (NILP (buffer))
1941 buf = current_buffer;
1942 else
1944 CHECK_BUFFER (buffer);
1945 buf = XBUFFER (buffer);
1948 CHECK_SYMBOL (variable);
1949 sym = indirect_variable (XSYMBOL (variable));
1950 XSETSYMBOL (variable, sym);
1952 valcontents = sym->value;
1954 if (BUFFER_OBJFWDP (valcontents))
1955 /* All these slots become local if they are set. */
1956 return Qt;
1957 else if (BUFFER_LOCAL_VALUEP (valcontents))
1959 Lisp_Object tail, elt;
1960 if (XBUFFER_LOCAL_VALUE (valcontents)->local_if_set)
1961 return Qt;
1962 for (tail = BUF_LOCAL_VAR_ALIST (buf); CONSP (tail); tail = XCDR (tail))
1964 elt = XCAR (tail);
1965 if (EQ (variable, XCAR (elt)))
1966 return Qt;
1969 return Qnil;
1972 DEFUN ("variable-binding-locus", Fvariable_binding_locus, Svariable_binding_locus,
1973 1, 1, 0,
1974 doc: /* Return a value indicating where VARIABLE's current binding comes from.
1975 If the current binding is buffer-local, the value is the current buffer.
1976 If the current binding is frame-local, the value is the selected frame.
1977 If the current binding is global (the default), the value is nil. */)
1978 (variable)
1979 register Lisp_Object variable;
1981 Lisp_Object valcontents;
1982 struct Lisp_Symbol *sym;
1984 CHECK_SYMBOL (variable);
1985 sym = indirect_variable (XSYMBOL (variable));
1987 /* Make sure the current binding is actually swapped in. */
1988 find_symbol_value (variable);
1990 valcontents = sym->value;
1992 if (BUFFER_LOCAL_VALUEP (valcontents)
1993 || BUFFER_OBJFWDP (valcontents))
1995 /* For a local variable, record both the symbol and which
1996 buffer's or frame's value we are saving. */
1997 if (!NILP (Flocal_variable_p (variable, Qnil)))
1998 return Fcurrent_buffer ();
1999 else if (BUFFER_LOCAL_VALUEP (valcontents)
2000 && BLOCAL_FOUND_FOR_FRAME (XBUFFER_LOCAL_VALUE (valcontents)))
2001 return BLOCAL_FRAME (XBUFFER_LOCAL_VALUE (valcontents));
2004 return Qnil;
2007 /* This code is disabled now that we use the selected frame to return
2008 keyboard-local-values. */
2009 #if 0
2010 extern struct terminal *get_terminal P_ ((Lisp_Object display, int));
2012 DEFUN ("terminal-local-value", Fterminal_local_value, Sterminal_local_value, 2, 2, 0,
2013 doc: /* Return the terminal-local value of SYMBOL on TERMINAL.
2014 If SYMBOL is not a terminal-local variable, then return its normal
2015 value, like `symbol-value'.
2017 TERMINAL may be a terminal object, a frame, or nil (meaning the
2018 selected frame's terminal device). */)
2019 (symbol, terminal)
2020 Lisp_Object symbol;
2021 Lisp_Object terminal;
2023 Lisp_Object result;
2024 struct terminal *t = get_terminal (terminal, 1);
2025 push_kboard (t->kboard);
2026 result = Fsymbol_value (symbol);
2027 pop_kboard ();
2028 return result;
2031 DEFUN ("set-terminal-local-value", Fset_terminal_local_value, Sset_terminal_local_value, 3, 3, 0,
2032 doc: /* Set the terminal-local binding of SYMBOL on TERMINAL to VALUE.
2033 If VARIABLE is not a terminal-local variable, then set its normal
2034 binding, like `set'.
2036 TERMINAL may be a terminal object, a frame, or nil (meaning the
2037 selected frame's terminal device). */)
2038 (symbol, terminal, value)
2039 Lisp_Object symbol;
2040 Lisp_Object terminal;
2041 Lisp_Object value;
2043 Lisp_Object result;
2044 struct terminal *t = get_terminal (terminal, 1);
2045 push_kboard (d->kboard);
2046 result = Fset (symbol, value);
2047 pop_kboard ();
2048 return result;
2050 #endif
2052 /* Find the function at the end of a chain of symbol function indirections. */
2054 /* If OBJECT is a symbol, find the end of its function chain and
2055 return the value found there. If OBJECT is not a symbol, just
2056 return it. If there is a cycle in the function chain, signal a
2057 cyclic-function-indirection error.
2059 This is like Findirect_function, except that it doesn't signal an
2060 error if the chain ends up unbound. */
2061 Lisp_Object
2062 indirect_function (object)
2063 register Lisp_Object object;
2065 Lisp_Object tortoise, hare;
2067 hare = tortoise = object;
2069 for (;;)
2071 if (!SYMBOLP (hare) || EQ (hare, Qunbound))
2072 break;
2073 hare = XSYMBOL (hare)->function;
2074 if (!SYMBOLP (hare) || EQ (hare, Qunbound))
2075 break;
2076 hare = XSYMBOL (hare)->function;
2078 tortoise = XSYMBOL (tortoise)->function;
2080 if (EQ (hare, tortoise))
2081 xsignal1 (Qcyclic_function_indirection, object);
2084 return hare;
2087 DEFUN ("indirect-function", Findirect_function, Sindirect_function, 1, 2, 0,
2088 doc: /* Return the function at the end of OBJECT's function chain.
2089 If OBJECT is not a symbol, just return it. Otherwise, follow all
2090 function indirections to find the final function binding and return it.
2091 If the final symbol in the chain is unbound, signal a void-function error.
2092 Optional arg NOERROR non-nil means to return nil instead of signalling.
2093 Signal a cyclic-function-indirection error if there is a loop in the
2094 function chain of symbols. */)
2095 (object, noerror)
2096 register Lisp_Object object;
2097 Lisp_Object noerror;
2099 Lisp_Object result;
2101 /* Optimize for no indirection. */
2102 result = object;
2103 if (SYMBOLP (result) && !EQ (result, Qunbound)
2104 && (result = XSYMBOL (result)->function, SYMBOLP (result)))
2105 result = indirect_function (result);
2106 if (!EQ (result, Qunbound))
2107 return result;
2109 if (NILP (noerror))
2110 xsignal1 (Qvoid_function, object);
2112 return Qnil;
2115 /* Extract and set vector and string elements */
2117 DEFUN ("aref", Faref, Saref, 2, 2, 0,
2118 doc: /* Return the element of ARRAY at index IDX.
2119 ARRAY may be a vector, a string, a char-table, a bool-vector,
2120 or a byte-code object. IDX starts at 0. */)
2121 (array, idx)
2122 register Lisp_Object array;
2123 Lisp_Object idx;
2125 register int idxval;
2127 CHECK_NUMBER (idx);
2128 idxval = XINT (idx);
2129 if (STRINGP (array))
2131 int c, idxval_byte;
2133 if (idxval < 0 || idxval >= SCHARS (array))
2134 args_out_of_range (array, idx);
2135 if (! STRING_MULTIBYTE (array))
2136 return make_number ((unsigned char) SREF (array, idxval));
2137 idxval_byte = string_char_to_byte (array, idxval);
2139 c = STRING_CHAR (SDATA (array) + idxval_byte);
2140 return make_number (c);
2142 else if (BOOL_VECTOR_P (array))
2144 int val;
2146 if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size)
2147 args_out_of_range (array, idx);
2149 val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR];
2150 return (val & (1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR)) ? Qt : Qnil);
2152 else if (CHAR_TABLE_P (array))
2154 CHECK_CHARACTER (idx);
2155 return CHAR_TABLE_REF (array, idxval);
2157 else
2159 int size = 0;
2160 if (VECTORP (array))
2161 size = XVECTOR (array)->size;
2162 else if (COMPILEDP (array))
2163 size = XVECTOR (array)->size & PSEUDOVECTOR_SIZE_MASK;
2164 else
2165 wrong_type_argument (Qarrayp, array);
2167 if (idxval < 0 || idxval >= size)
2168 args_out_of_range (array, idx);
2169 return XVECTOR (array)->contents[idxval];
2173 DEFUN ("aset", Faset, Saset, 3, 3, 0,
2174 doc: /* Store into the element of ARRAY at index IDX the value NEWELT.
2175 Return NEWELT. ARRAY may be a vector, a string, a char-table or a
2176 bool-vector. IDX starts at 0. */)
2177 (array, idx, newelt)
2178 register Lisp_Object array;
2179 Lisp_Object idx, newelt;
2181 register int idxval;
2183 CHECK_NUMBER (idx);
2184 idxval = XINT (idx);
2185 CHECK_ARRAY (array, Qarrayp);
2186 CHECK_IMPURE (array);
2188 if (VECTORP (array))
2190 if (idxval < 0 || idxval >= XVECTOR (array)->size)
2191 args_out_of_range (array, idx);
2192 XVECTOR (array)->contents[idxval] = newelt;
2194 else if (BOOL_VECTOR_P (array))
2196 int val;
2198 if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size)
2199 args_out_of_range (array, idx);
2201 val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR];
2203 if (! NILP (newelt))
2204 val |= 1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR);
2205 else
2206 val &= ~(1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR));
2207 XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR] = val;
2209 else if (CHAR_TABLE_P (array))
2211 CHECK_CHARACTER (idx);
2212 CHAR_TABLE_SET (array, idxval, newelt);
2214 else if (STRING_MULTIBYTE (array))
2216 int idxval_byte, prev_bytes, new_bytes, nbytes;
2217 unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1;
2219 if (idxval < 0 || idxval >= SCHARS (array))
2220 args_out_of_range (array, idx);
2221 CHECK_CHARACTER (newelt);
2223 nbytes = SBYTES (array);
2225 idxval_byte = string_char_to_byte (array, idxval);
2226 p1 = SDATA (array) + idxval_byte;
2227 PARSE_MULTIBYTE_SEQ (p1, nbytes - idxval_byte, prev_bytes);
2228 new_bytes = CHAR_STRING (XINT (newelt), p0);
2229 if (prev_bytes != new_bytes)
2231 /* We must relocate the string data. */
2232 int nchars = SCHARS (array);
2233 unsigned char *str;
2234 USE_SAFE_ALLOCA;
2236 SAFE_ALLOCA (str, unsigned char *, nbytes);
2237 bcopy (SDATA (array), str, nbytes);
2238 allocate_string_data (XSTRING (array), nchars,
2239 nbytes + new_bytes - prev_bytes);
2240 bcopy (str, SDATA (array), idxval_byte);
2241 p1 = SDATA (array) + idxval_byte;
2242 bcopy (str + idxval_byte + prev_bytes, p1 + new_bytes,
2243 nbytes - (idxval_byte + prev_bytes));
2244 SAFE_FREE ();
2245 clear_string_char_byte_cache ();
2247 while (new_bytes--)
2248 *p1++ = *p0++;
2250 else
2252 if (idxval < 0 || idxval >= SCHARS (array))
2253 args_out_of_range (array, idx);
2254 CHECK_NUMBER (newelt);
2256 if (XINT (newelt) >= 0 && ! SINGLE_BYTE_CHAR_P (XINT (newelt)))
2258 int i;
2260 for (i = SBYTES (array) - 1; i >= 0; i--)
2261 if (SREF (array, i) >= 0x80)
2262 args_out_of_range (array, newelt);
2263 /* ARRAY is an ASCII string. Convert it to a multibyte
2264 string, and try `aset' again. */
2265 STRING_SET_MULTIBYTE (array);
2266 return Faset (array, idx, newelt);
2268 SSET (array, idxval, XINT (newelt));
2271 return newelt;
2274 /* Arithmetic functions */
2276 enum comparison { equal, notequal, less, grtr, less_or_equal, grtr_or_equal };
2278 Lisp_Object
2279 arithcompare (num1, num2, comparison)
2280 Lisp_Object num1, num2;
2281 enum comparison comparison;
2283 double f1 = 0, f2 = 0;
2284 int floatp = 0;
2286 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1);
2287 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2);
2289 if (FLOATP (num1) || FLOATP (num2))
2291 floatp = 1;
2292 f1 = (FLOATP (num1)) ? XFLOAT_DATA (num1) : XINT (num1);
2293 f2 = (FLOATP (num2)) ? XFLOAT_DATA (num2) : XINT (num2);
2296 switch (comparison)
2298 case equal:
2299 if (floatp ? f1 == f2 : XINT (num1) == XINT (num2))
2300 return Qt;
2301 return Qnil;
2303 case notequal:
2304 if (floatp ? f1 != f2 : XINT (num1) != XINT (num2))
2305 return Qt;
2306 return Qnil;
2308 case less:
2309 if (floatp ? f1 < f2 : XINT (num1) < XINT (num2))
2310 return Qt;
2311 return Qnil;
2313 case less_or_equal:
2314 if (floatp ? f1 <= f2 : XINT (num1) <= XINT (num2))
2315 return Qt;
2316 return Qnil;
2318 case grtr:
2319 if (floatp ? f1 > f2 : XINT (num1) > XINT (num2))
2320 return Qt;
2321 return Qnil;
2323 case grtr_or_equal:
2324 if (floatp ? f1 >= f2 : XINT (num1) >= XINT (num2))
2325 return Qt;
2326 return Qnil;
2328 default:
2329 abort ();
2333 DEFUN ("=", Feqlsign, Seqlsign, 2, 2, 0,
2334 doc: /* Return t if two args, both numbers or markers, are equal. */)
2335 (num1, num2)
2336 register Lisp_Object num1, num2;
2338 return arithcompare (num1, num2, equal);
2341 DEFUN ("<", Flss, Slss, 2, 2, 0,
2342 doc: /* Return t if first arg is less than second arg. Both must be numbers or markers. */)
2343 (num1, num2)
2344 register Lisp_Object num1, num2;
2346 return arithcompare (num1, num2, less);
2349 DEFUN (">", Fgtr, Sgtr, 2, 2, 0,
2350 doc: /* Return t if first arg is greater than second arg. Both must be numbers or markers. */)
2351 (num1, num2)
2352 register Lisp_Object num1, num2;
2354 return arithcompare (num1, num2, grtr);
2357 DEFUN ("<=", Fleq, Sleq, 2, 2, 0,
2358 doc: /* Return t if first arg is less than or equal to second arg.
2359 Both must be numbers or markers. */)
2360 (num1, num2)
2361 register Lisp_Object num1, num2;
2363 return arithcompare (num1, num2, less_or_equal);
2366 DEFUN (">=", Fgeq, Sgeq, 2, 2, 0,
2367 doc: /* Return t if first arg is greater than or equal to second arg.
2368 Both must be numbers or markers. */)
2369 (num1, num2)
2370 register Lisp_Object num1, num2;
2372 return arithcompare (num1, num2, grtr_or_equal);
2375 DEFUN ("/=", Fneq, Sneq, 2, 2, 0,
2376 doc: /* Return t if first arg is not equal to second arg. Both must be numbers or markers. */)
2377 (num1, num2)
2378 register Lisp_Object num1, num2;
2380 return arithcompare (num1, num2, notequal);
2383 DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0,
2384 doc: /* Return t if NUMBER is zero. */)
2385 (number)
2386 register Lisp_Object number;
2388 CHECK_NUMBER_OR_FLOAT (number);
2390 if (FLOATP (number))
2392 if (XFLOAT_DATA (number) == 0.0)
2393 return Qt;
2394 return Qnil;
2397 if (!XINT (number))
2398 return Qt;
2399 return Qnil;
2402 /* Convert between long values and pairs of Lisp integers.
2403 Note that long_to_cons returns a single Lisp integer
2404 when the value fits in one. */
2406 Lisp_Object
2407 long_to_cons (i)
2408 unsigned long i;
2410 unsigned long top = i >> 16;
2411 unsigned int bot = i & 0xFFFF;
2412 if (top == 0)
2413 return make_number (bot);
2414 if (top == (unsigned long)-1 >> 16)
2415 return Fcons (make_number (-1), make_number (bot));
2416 return Fcons (make_number (top), make_number (bot));
2419 unsigned long
2420 cons_to_long (c)
2421 Lisp_Object c;
2423 Lisp_Object top, bot;
2424 if (INTEGERP (c))
2425 return XINT (c);
2426 top = XCAR (c);
2427 bot = XCDR (c);
2428 if (CONSP (bot))
2429 bot = XCAR (bot);
2430 return ((XINT (top) << 16) | XINT (bot));
2433 DEFUN ("number-to-string", Fnumber_to_string, Snumber_to_string, 1, 1, 0,
2434 doc: /* Return the decimal representation of NUMBER as a string.
2435 Uses a minus sign if negative.
2436 NUMBER may be an integer or a floating point number. */)
2437 (number)
2438 Lisp_Object number;
2440 char buffer[VALBITS];
2442 CHECK_NUMBER_OR_FLOAT (number);
2444 if (FLOATP (number))
2446 char pigbuf[350]; /* see comments in float_to_string */
2448 float_to_string (pigbuf, XFLOAT_DATA (number));
2449 return build_string (pigbuf);
2452 if (sizeof (int) == sizeof (EMACS_INT))
2453 sprintf (buffer, "%d", (int) XINT (number));
2454 else if (sizeof (long) == sizeof (EMACS_INT))
2455 sprintf (buffer, "%ld", (long) XINT (number));
2456 else
2457 abort ();
2458 return build_string (buffer);
2461 INLINE static int
2462 digit_to_number (character, base)
2463 int character, base;
2465 int digit;
2467 if (character >= '0' && character <= '9')
2468 digit = character - '0';
2469 else if (character >= 'a' && character <= 'z')
2470 digit = character - 'a' + 10;
2471 else if (character >= 'A' && character <= 'Z')
2472 digit = character - 'A' + 10;
2473 else
2474 return -1;
2476 if (digit >= base)
2477 return -1;
2478 else
2479 return digit;
2482 DEFUN ("string-to-number", Fstring_to_number, Sstring_to_number, 1, 2, 0,
2483 doc: /* Parse STRING as a decimal number and return the number.
2484 This parses both integers and floating point numbers.
2485 It ignores leading spaces and tabs, and all trailing chars.
2487 If BASE, interpret STRING as a number in that base. If BASE isn't
2488 present, base 10 is used. BASE must be between 2 and 16 (inclusive).
2489 If the base used is not 10, STRING is always parsed as integer. */)
2490 (string, base)
2491 register Lisp_Object string, base;
2493 register unsigned char *p;
2494 register int b;
2495 int sign = 1;
2496 Lisp_Object val;
2498 CHECK_STRING (string);
2500 if (NILP (base))
2501 b = 10;
2502 else
2504 CHECK_NUMBER (base);
2505 b = XINT (base);
2506 if (b < 2 || b > 16)
2507 xsignal1 (Qargs_out_of_range, base);
2510 /* Skip any whitespace at the front of the number. Some versions of
2511 atoi do this anyway, so we might as well make Emacs lisp consistent. */
2512 p = SDATA (string);
2513 while (*p == ' ' || *p == '\t')
2514 p++;
2516 if (*p == '-')
2518 sign = -1;
2519 p++;
2521 else if (*p == '+')
2522 p++;
2524 if (isfloat_string (p, 1) && b == 10)
2525 val = make_float (sign * atof (p));
2526 else
2528 double v = 0;
2530 while (1)
2532 int digit = digit_to_number (*p++, b);
2533 if (digit < 0)
2534 break;
2535 v = v * b + digit;
2538 val = make_fixnum_or_float (sign * v);
2541 return val;
2545 enum arithop
2547 Aadd,
2548 Asub,
2549 Amult,
2550 Adiv,
2551 Alogand,
2552 Alogior,
2553 Alogxor,
2554 Amax,
2555 Amin
2558 static Lisp_Object float_arith_driver P_ ((double, int, enum arithop,
2559 int, Lisp_Object *));
2560 extern Lisp_Object fmod_float ();
2562 Lisp_Object
2563 arith_driver (code, nargs, args)
2564 enum arithop code;
2565 int nargs;
2566 register Lisp_Object *args;
2568 register Lisp_Object val;
2569 register int argnum;
2570 register EMACS_INT accum = 0;
2571 register EMACS_INT next;
2573 switch (SWITCH_ENUM_CAST (code))
2575 case Alogior:
2576 case Alogxor:
2577 case Aadd:
2578 case Asub:
2579 accum = 0;
2580 break;
2581 case Amult:
2582 accum = 1;
2583 break;
2584 case Alogand:
2585 accum = -1;
2586 break;
2587 default:
2588 break;
2591 for (argnum = 0; argnum < nargs; argnum++)
2593 /* Using args[argnum] as argument to CHECK_NUMBER_... */
2594 val = args[argnum];
2595 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val);
2597 if (FLOATP (val))
2598 return float_arith_driver ((double) accum, argnum, code,
2599 nargs, args);
2600 args[argnum] = val;
2601 next = XINT (args[argnum]);
2602 switch (SWITCH_ENUM_CAST (code))
2604 case Aadd:
2605 accum += next;
2606 break;
2607 case Asub:
2608 accum = argnum ? accum - next : nargs == 1 ? - next : next;
2609 break;
2610 case Amult:
2611 accum *= next;
2612 break;
2613 case Adiv:
2614 if (!argnum)
2615 accum = next;
2616 else
2618 if (next == 0)
2619 xsignal0 (Qarith_error);
2620 accum /= next;
2622 break;
2623 case Alogand:
2624 accum &= next;
2625 break;
2626 case Alogior:
2627 accum |= next;
2628 break;
2629 case Alogxor:
2630 accum ^= next;
2631 break;
2632 case Amax:
2633 if (!argnum || next > accum)
2634 accum = next;
2635 break;
2636 case Amin:
2637 if (!argnum || next < accum)
2638 accum = next;
2639 break;
2643 XSETINT (val, accum);
2644 return val;
2647 #undef isnan
2648 #define isnan(x) ((x) != (x))
2650 static Lisp_Object
2651 float_arith_driver (accum, argnum, code, nargs, args)
2652 double accum;
2653 register int argnum;
2654 enum arithop code;
2655 int nargs;
2656 register Lisp_Object *args;
2658 register Lisp_Object val;
2659 double next;
2661 for (; argnum < nargs; argnum++)
2663 val = args[argnum]; /* using args[argnum] as argument to CHECK_NUMBER_... */
2664 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val);
2666 if (FLOATP (val))
2668 next = XFLOAT_DATA (val);
2670 else
2672 args[argnum] = val; /* runs into a compiler bug. */
2673 next = XINT (args[argnum]);
2675 switch (SWITCH_ENUM_CAST (code))
2677 case Aadd:
2678 accum += next;
2679 break;
2680 case Asub:
2681 accum = argnum ? accum - next : nargs == 1 ? - next : next;
2682 break;
2683 case Amult:
2684 accum *= next;
2685 break;
2686 case Adiv:
2687 if (!argnum)
2688 accum = next;
2689 else
2691 if (! IEEE_FLOATING_POINT && next == 0)
2692 xsignal0 (Qarith_error);
2693 accum /= next;
2695 break;
2696 case Alogand:
2697 case Alogior:
2698 case Alogxor:
2699 return wrong_type_argument (Qinteger_or_marker_p, val);
2700 case Amax:
2701 if (!argnum || isnan (next) || next > accum)
2702 accum = next;
2703 break;
2704 case Amin:
2705 if (!argnum || isnan (next) || next < accum)
2706 accum = next;
2707 break;
2711 return make_float (accum);
2715 DEFUN ("+", Fplus, Splus, 0, MANY, 0,
2716 doc: /* Return sum of any number of arguments, which are numbers or markers.
2717 usage: (+ &rest NUMBERS-OR-MARKERS) */)
2718 (nargs, args)
2719 int nargs;
2720 Lisp_Object *args;
2722 return arith_driver (Aadd, nargs, args);
2725 DEFUN ("-", Fminus, Sminus, 0, MANY, 0,
2726 doc: /* Negate number or subtract numbers or markers and return the result.
2727 With one arg, negates it. With more than one arg,
2728 subtracts all but the first from the first.
2729 usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */)
2730 (nargs, args)
2731 int nargs;
2732 Lisp_Object *args;
2734 return arith_driver (Asub, nargs, args);
2737 DEFUN ("*", Ftimes, Stimes, 0, MANY, 0,
2738 doc: /* Return product of any number of arguments, which are numbers or markers.
2739 usage: (* &rest NUMBERS-OR-MARKERS) */)
2740 (nargs, args)
2741 int nargs;
2742 Lisp_Object *args;
2744 return arith_driver (Amult, nargs, args);
2747 DEFUN ("/", Fquo, Squo, 2, MANY, 0,
2748 doc: /* Return first argument divided by all the remaining arguments.
2749 The arguments must be numbers or markers.
2750 usage: (/ DIVIDEND DIVISOR &rest DIVISORS) */)
2751 (nargs, args)
2752 int nargs;
2753 Lisp_Object *args;
2755 int argnum;
2756 for (argnum = 2; argnum < nargs; argnum++)
2757 if (FLOATP (args[argnum]))
2758 return float_arith_driver (0, 0, Adiv, nargs, args);
2759 return arith_driver (Adiv, nargs, args);
2762 DEFUN ("%", Frem, Srem, 2, 2, 0,
2763 doc: /* Return remainder of X divided by Y.
2764 Both must be integers or markers. */)
2765 (x, y)
2766 register Lisp_Object x, y;
2768 Lisp_Object val;
2770 CHECK_NUMBER_COERCE_MARKER (x);
2771 CHECK_NUMBER_COERCE_MARKER (y);
2773 if (XFASTINT (y) == 0)
2774 xsignal0 (Qarith_error);
2776 XSETINT (val, XINT (x) % XINT (y));
2777 return val;
2780 #ifndef HAVE_FMOD
2781 double
2782 fmod (f1, f2)
2783 double f1, f2;
2785 double r = f1;
2787 if (f2 < 0.0)
2788 f2 = -f2;
2790 /* If the magnitude of the result exceeds that of the divisor, or
2791 the sign of the result does not agree with that of the dividend,
2792 iterate with the reduced value. This does not yield a
2793 particularly accurate result, but at least it will be in the
2794 range promised by fmod. */
2796 r -= f2 * floor (r / f2);
2797 while (f2 <= (r < 0 ? -r : r) || ((r < 0) != (f1 < 0) && ! isnan (r)));
2799 return r;
2801 #endif /* ! HAVE_FMOD */
2803 DEFUN ("mod", Fmod, Smod, 2, 2, 0,
2804 doc: /* Return X modulo Y.
2805 The result falls between zero (inclusive) and Y (exclusive).
2806 Both X and Y must be numbers or markers. */)
2807 (x, y)
2808 register Lisp_Object x, y;
2810 Lisp_Object val;
2811 EMACS_INT i1, i2;
2813 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x);
2814 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y);
2816 if (FLOATP (x) || FLOATP (y))
2817 return fmod_float (x, y);
2819 i1 = XINT (x);
2820 i2 = XINT (y);
2822 if (i2 == 0)
2823 xsignal0 (Qarith_error);
2825 i1 %= i2;
2827 /* If the "remainder" comes out with the wrong sign, fix it. */
2828 if (i2 < 0 ? i1 > 0 : i1 < 0)
2829 i1 += i2;
2831 XSETINT (val, i1);
2832 return val;
2835 DEFUN ("max", Fmax, Smax, 1, MANY, 0,
2836 doc: /* Return largest of all the arguments (which must be numbers or markers).
2837 The value is always a number; markers are converted to numbers.
2838 usage: (max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2839 (nargs, args)
2840 int nargs;
2841 Lisp_Object *args;
2843 return arith_driver (Amax, nargs, args);
2846 DEFUN ("min", Fmin, Smin, 1, MANY, 0,
2847 doc: /* Return smallest of all the arguments (which must be numbers or markers).
2848 The value is always a number; markers are converted to numbers.
2849 usage: (min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2850 (nargs, args)
2851 int nargs;
2852 Lisp_Object *args;
2854 return arith_driver (Amin, nargs, args);
2857 DEFUN ("logand", Flogand, Slogand, 0, MANY, 0,
2858 doc: /* Return bitwise-and of all the arguments.
2859 Arguments may be integers, or markers converted to integers.
2860 usage: (logand &rest INTS-OR-MARKERS) */)
2861 (nargs, args)
2862 int nargs;
2863 Lisp_Object *args;
2865 return arith_driver (Alogand, nargs, args);
2868 DEFUN ("logior", Flogior, Slogior, 0, MANY, 0,
2869 doc: /* Return bitwise-or of all the arguments.
2870 Arguments may be integers, or markers converted to integers.
2871 usage: (logior &rest INTS-OR-MARKERS) */)
2872 (nargs, args)
2873 int nargs;
2874 Lisp_Object *args;
2876 return arith_driver (Alogior, nargs, args);
2879 DEFUN ("logxor", Flogxor, Slogxor, 0, MANY, 0,
2880 doc: /* Return bitwise-exclusive-or of all the arguments.
2881 Arguments may be integers, or markers converted to integers.
2882 usage: (logxor &rest INTS-OR-MARKERS) */)
2883 (nargs, args)
2884 int nargs;
2885 Lisp_Object *args;
2887 return arith_driver (Alogxor, nargs, args);
2890 DEFUN ("ash", Fash, Sash, 2, 2, 0,
2891 doc: /* Return VALUE with its bits shifted left by COUNT.
2892 If COUNT is negative, shifting is actually to the right.
2893 In this case, the sign bit is duplicated. */)
2894 (value, count)
2895 register Lisp_Object value, count;
2897 register Lisp_Object val;
2899 CHECK_NUMBER (value);
2900 CHECK_NUMBER (count);
2902 if (XINT (count) >= BITS_PER_EMACS_INT)
2903 XSETINT (val, 0);
2904 else if (XINT (count) > 0)
2905 XSETINT (val, XINT (value) << XFASTINT (count));
2906 else if (XINT (count) <= -BITS_PER_EMACS_INT)
2907 XSETINT (val, XINT (value) < 0 ? -1 : 0);
2908 else
2909 XSETINT (val, XINT (value) >> -XINT (count));
2910 return val;
2913 DEFUN ("lsh", Flsh, Slsh, 2, 2, 0,
2914 doc: /* Return VALUE with its bits shifted left by COUNT.
2915 If COUNT is negative, shifting is actually to the right.
2916 In this case, zeros are shifted in on the left. */)
2917 (value, count)
2918 register Lisp_Object value, count;
2920 register Lisp_Object val;
2922 CHECK_NUMBER (value);
2923 CHECK_NUMBER (count);
2925 if (XINT (count) >= BITS_PER_EMACS_INT)
2926 XSETINT (val, 0);
2927 else if (XINT (count) > 0)
2928 XSETINT (val, (EMACS_UINT) XUINT (value) << XFASTINT (count));
2929 else if (XINT (count) <= -BITS_PER_EMACS_INT)
2930 XSETINT (val, 0);
2931 else
2932 XSETINT (val, (EMACS_UINT) XUINT (value) >> -XINT (count));
2933 return val;
2936 DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0,
2937 doc: /* Return NUMBER plus one. NUMBER may be a number or a marker.
2938 Markers are converted to integers. */)
2939 (number)
2940 register Lisp_Object number;
2942 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number);
2944 if (FLOATP (number))
2945 return (make_float (1.0 + XFLOAT_DATA (number)));
2947 XSETINT (number, XINT (number) + 1);
2948 return number;
2951 DEFUN ("1-", Fsub1, Ssub1, 1, 1, 0,
2952 doc: /* Return NUMBER minus one. NUMBER may be a number or a marker.
2953 Markers are converted to integers. */)
2954 (number)
2955 register Lisp_Object number;
2957 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number);
2959 if (FLOATP (number))
2960 return (make_float (-1.0 + XFLOAT_DATA (number)));
2962 XSETINT (number, XINT (number) - 1);
2963 return number;
2966 DEFUN ("lognot", Flognot, Slognot, 1, 1, 0,
2967 doc: /* Return the bitwise complement of NUMBER. NUMBER must be an integer. */)
2968 (number)
2969 register Lisp_Object number;
2971 CHECK_NUMBER (number);
2972 XSETINT (number, ~XINT (number));
2973 return number;
2976 DEFUN ("byteorder", Fbyteorder, Sbyteorder, 0, 0, 0,
2977 doc: /* Return the byteorder for the machine.
2978 Returns 66 (ASCII uppercase B) for big endian machines or 108 (ASCII
2979 lowercase l) for small endian machines. */)
2982 unsigned i = 0x04030201;
2983 int order = *(char *)&i == 1 ? 108 : 66;
2985 return make_number (order);
2990 void
2991 syms_of_data ()
2993 Lisp_Object error_tail, arith_tail;
2995 Qquote = intern_c_string ("quote");
2996 Qlambda = intern_c_string ("lambda");
2997 Qsubr = intern_c_string ("subr");
2998 Qerror_conditions = intern_c_string ("error-conditions");
2999 Qerror_message = intern_c_string ("error-message");
3000 Qtop_level = intern_c_string ("top-level");
3002 Qerror = intern_c_string ("error");
3003 Qquit = intern_c_string ("quit");
3004 Qwrong_type_argument = intern_c_string ("wrong-type-argument");
3005 Qargs_out_of_range = intern_c_string ("args-out-of-range");
3006 Qvoid_function = intern_c_string ("void-function");
3007 Qcyclic_function_indirection = intern_c_string ("cyclic-function-indirection");
3008 Qcyclic_variable_indirection = intern_c_string ("cyclic-variable-indirection");
3009 Qvoid_variable = intern_c_string ("void-variable");
3010 Qsetting_constant = intern_c_string ("setting-constant");
3011 Qinvalid_read_syntax = intern_c_string ("invalid-read-syntax");
3013 Qinvalid_function = intern_c_string ("invalid-function");
3014 Qwrong_number_of_arguments = intern_c_string ("wrong-number-of-arguments");
3015 Qno_catch = intern_c_string ("no-catch");
3016 Qend_of_file = intern_c_string ("end-of-file");
3017 Qarith_error = intern_c_string ("arith-error");
3018 Qbeginning_of_buffer = intern_c_string ("beginning-of-buffer");
3019 Qend_of_buffer = intern_c_string ("end-of-buffer");
3020 Qbuffer_read_only = intern_c_string ("buffer-read-only");
3021 Qtext_read_only = intern_c_string ("text-read-only");
3022 Qmark_inactive = intern_c_string ("mark-inactive");
3024 Qlistp = intern_c_string ("listp");
3025 Qconsp = intern_c_string ("consp");
3026 Qsymbolp = intern_c_string ("symbolp");
3027 Qkeywordp = intern_c_string ("keywordp");
3028 Qintegerp = intern_c_string ("integerp");
3029 Qnatnump = intern_c_string ("natnump");
3030 Qwholenump = intern_c_string ("wholenump");
3031 Qstringp = intern_c_string ("stringp");
3032 Qarrayp = intern_c_string ("arrayp");
3033 Qsequencep = intern_c_string ("sequencep");
3034 Qbufferp = intern_c_string ("bufferp");
3035 Qvectorp = intern_c_string ("vectorp");
3036 Qchar_or_string_p = intern_c_string ("char-or-string-p");
3037 Qmarkerp = intern_c_string ("markerp");
3038 Qbuffer_or_string_p = intern_c_string ("buffer-or-string-p");
3039 Qinteger_or_marker_p = intern_c_string ("integer-or-marker-p");
3040 Qboundp = intern_c_string ("boundp");
3041 Qfboundp = intern_c_string ("fboundp");
3043 Qfloatp = intern_c_string ("floatp");
3044 Qnumberp = intern_c_string ("numberp");
3045 Qnumber_or_marker_p = intern_c_string ("number-or-marker-p");
3047 Qchar_table_p = intern_c_string ("char-table-p");
3048 Qvector_or_char_table_p = intern_c_string ("vector-or-char-table-p");
3050 Qsubrp = intern_c_string ("subrp");
3051 Qunevalled = intern_c_string ("unevalled");
3052 Qmany = intern_c_string ("many");
3054 Qcdr = intern_c_string ("cdr");
3056 /* Handle automatic advice activation */
3057 Qad_advice_info = intern_c_string ("ad-advice-info");
3058 Qad_activate_internal = intern_c_string ("ad-activate-internal");
3060 error_tail = pure_cons (Qerror, Qnil);
3062 /* ERROR is used as a signaler for random errors for which nothing else is right */
3064 Fput (Qerror, Qerror_conditions,
3065 error_tail);
3066 Fput (Qerror, Qerror_message,
3067 make_pure_c_string ("error"));
3069 Fput (Qquit, Qerror_conditions,
3070 pure_cons (Qquit, Qnil));
3071 Fput (Qquit, Qerror_message,
3072 make_pure_c_string ("Quit"));
3074 Fput (Qwrong_type_argument, Qerror_conditions,
3075 pure_cons (Qwrong_type_argument, error_tail));
3076 Fput (Qwrong_type_argument, Qerror_message,
3077 make_pure_c_string ("Wrong type argument"));
3079 Fput (Qargs_out_of_range, Qerror_conditions,
3080 pure_cons (Qargs_out_of_range, error_tail));
3081 Fput (Qargs_out_of_range, Qerror_message,
3082 make_pure_c_string ("Args out of range"));
3084 Fput (Qvoid_function, Qerror_conditions,
3085 pure_cons (Qvoid_function, error_tail));
3086 Fput (Qvoid_function, Qerror_message,
3087 make_pure_c_string ("Symbol's function definition is void"));
3089 Fput (Qcyclic_function_indirection, Qerror_conditions,
3090 pure_cons (Qcyclic_function_indirection, error_tail));
3091 Fput (Qcyclic_function_indirection, Qerror_message,
3092 make_pure_c_string ("Symbol's chain of function indirections contains a loop"));
3094 Fput (Qcyclic_variable_indirection, Qerror_conditions,
3095 pure_cons (Qcyclic_variable_indirection, error_tail));
3096 Fput (Qcyclic_variable_indirection, Qerror_message,
3097 make_pure_c_string ("Symbol's chain of variable indirections contains a loop"));
3099 Qcircular_list = intern_c_string ("circular-list");
3100 staticpro (&Qcircular_list);
3101 Fput (Qcircular_list, Qerror_conditions,
3102 pure_cons (Qcircular_list, error_tail));
3103 Fput (Qcircular_list, Qerror_message,
3104 make_pure_c_string ("List contains a loop"));
3106 Fput (Qvoid_variable, Qerror_conditions,
3107 pure_cons (Qvoid_variable, error_tail));
3108 Fput (Qvoid_variable, Qerror_message,
3109 make_pure_c_string ("Symbol's value as variable is void"));
3111 Fput (Qsetting_constant, Qerror_conditions,
3112 pure_cons (Qsetting_constant, error_tail));
3113 Fput (Qsetting_constant, Qerror_message,
3114 make_pure_c_string ("Attempt to set a constant symbol"));
3116 Fput (Qinvalid_read_syntax, Qerror_conditions,
3117 pure_cons (Qinvalid_read_syntax, error_tail));
3118 Fput (Qinvalid_read_syntax, Qerror_message,
3119 make_pure_c_string ("Invalid read syntax"));
3121 Fput (Qinvalid_function, Qerror_conditions,
3122 pure_cons (Qinvalid_function, error_tail));
3123 Fput (Qinvalid_function, Qerror_message,
3124 make_pure_c_string ("Invalid function"));
3126 Fput (Qwrong_number_of_arguments, Qerror_conditions,
3127 pure_cons (Qwrong_number_of_arguments, error_tail));
3128 Fput (Qwrong_number_of_arguments, Qerror_message,
3129 make_pure_c_string ("Wrong number of arguments"));
3131 Fput (Qno_catch, Qerror_conditions,
3132 pure_cons (Qno_catch, error_tail));
3133 Fput (Qno_catch, Qerror_message,
3134 make_pure_c_string ("No catch for tag"));
3136 Fput (Qend_of_file, Qerror_conditions,
3137 pure_cons (Qend_of_file, error_tail));
3138 Fput (Qend_of_file, Qerror_message,
3139 make_pure_c_string ("End of file during parsing"));
3141 arith_tail = pure_cons (Qarith_error, error_tail);
3142 Fput (Qarith_error, Qerror_conditions,
3143 arith_tail);
3144 Fput (Qarith_error, Qerror_message,
3145 make_pure_c_string ("Arithmetic error"));
3147 Fput (Qbeginning_of_buffer, Qerror_conditions,
3148 pure_cons (Qbeginning_of_buffer, error_tail));
3149 Fput (Qbeginning_of_buffer, Qerror_message,
3150 make_pure_c_string ("Beginning of buffer"));
3152 Fput (Qend_of_buffer, Qerror_conditions,
3153 pure_cons (Qend_of_buffer, error_tail));
3154 Fput (Qend_of_buffer, Qerror_message,
3155 make_pure_c_string ("End of buffer"));
3157 Fput (Qbuffer_read_only, Qerror_conditions,
3158 pure_cons (Qbuffer_read_only, error_tail));
3159 Fput (Qbuffer_read_only, Qerror_message,
3160 make_pure_c_string ("Buffer is read-only"));
3162 Fput (Qtext_read_only, Qerror_conditions,
3163 pure_cons (Qtext_read_only, error_tail));
3164 Fput (Qtext_read_only, Qerror_message,
3165 make_pure_c_string ("Text is read-only"));
3167 Qrange_error = intern_c_string ("range-error");
3168 Qdomain_error = intern_c_string ("domain-error");
3169 Qsingularity_error = intern_c_string ("singularity-error");
3170 Qoverflow_error = intern_c_string ("overflow-error");
3171 Qunderflow_error = intern_c_string ("underflow-error");
3173 Fput (Qdomain_error, Qerror_conditions,
3174 pure_cons (Qdomain_error, arith_tail));
3175 Fput (Qdomain_error, Qerror_message,
3176 make_pure_c_string ("Arithmetic domain error"));
3178 Fput (Qrange_error, Qerror_conditions,
3179 pure_cons (Qrange_error, arith_tail));
3180 Fput (Qrange_error, Qerror_message,
3181 make_pure_c_string ("Arithmetic range error"));
3183 Fput (Qsingularity_error, Qerror_conditions,
3184 pure_cons (Qsingularity_error, Fcons (Qdomain_error, arith_tail)));
3185 Fput (Qsingularity_error, Qerror_message,
3186 make_pure_c_string ("Arithmetic singularity error"));
3188 Fput (Qoverflow_error, Qerror_conditions,
3189 pure_cons (Qoverflow_error, Fcons (Qdomain_error, arith_tail)));
3190 Fput (Qoverflow_error, Qerror_message,
3191 make_pure_c_string ("Arithmetic overflow error"));
3193 Fput (Qunderflow_error, Qerror_conditions,
3194 pure_cons (Qunderflow_error, Fcons (Qdomain_error, arith_tail)));
3195 Fput (Qunderflow_error, Qerror_message,
3196 make_pure_c_string ("Arithmetic underflow error"));
3198 staticpro (&Qrange_error);
3199 staticpro (&Qdomain_error);
3200 staticpro (&Qsingularity_error);
3201 staticpro (&Qoverflow_error);
3202 staticpro (&Qunderflow_error);
3204 staticpro (&Qnil);
3205 staticpro (&Qt);
3206 staticpro (&Qquote);
3207 staticpro (&Qlambda);
3208 staticpro (&Qsubr);
3209 staticpro (&Qunbound);
3210 staticpro (&Qerror_conditions);
3211 staticpro (&Qerror_message);
3212 staticpro (&Qtop_level);
3214 staticpro (&Qerror);
3215 staticpro (&Qquit);
3216 staticpro (&Qwrong_type_argument);
3217 staticpro (&Qargs_out_of_range);
3218 staticpro (&Qvoid_function);
3219 staticpro (&Qcyclic_function_indirection);
3220 staticpro (&Qcyclic_variable_indirection);
3221 staticpro (&Qvoid_variable);
3222 staticpro (&Qsetting_constant);
3223 staticpro (&Qinvalid_read_syntax);
3224 staticpro (&Qwrong_number_of_arguments);
3225 staticpro (&Qinvalid_function);
3226 staticpro (&Qno_catch);
3227 staticpro (&Qend_of_file);
3228 staticpro (&Qarith_error);
3229 staticpro (&Qbeginning_of_buffer);
3230 staticpro (&Qend_of_buffer);
3231 staticpro (&Qbuffer_read_only);
3232 staticpro (&Qtext_read_only);
3233 staticpro (&Qmark_inactive);
3235 staticpro (&Qlistp);
3236 staticpro (&Qconsp);
3237 staticpro (&Qsymbolp);
3238 staticpro (&Qkeywordp);
3239 staticpro (&Qintegerp);
3240 staticpro (&Qnatnump);
3241 staticpro (&Qwholenump);
3242 staticpro (&Qstringp);
3243 staticpro (&Qarrayp);
3244 staticpro (&Qsequencep);
3245 staticpro (&Qbufferp);
3246 staticpro (&Qvectorp);
3247 staticpro (&Qchar_or_string_p);
3248 staticpro (&Qmarkerp);
3249 staticpro (&Qbuffer_or_string_p);
3250 staticpro (&Qinteger_or_marker_p);
3251 staticpro (&Qfloatp);
3252 staticpro (&Qnumberp);
3253 staticpro (&Qnumber_or_marker_p);
3254 staticpro (&Qchar_table_p);
3255 staticpro (&Qvector_or_char_table_p);
3256 staticpro (&Qsubrp);
3257 staticpro (&Qmany);
3258 staticpro (&Qunevalled);
3260 staticpro (&Qboundp);
3261 staticpro (&Qfboundp);
3262 staticpro (&Qcdr);
3263 staticpro (&Qad_advice_info);
3264 staticpro (&Qad_activate_internal);
3266 /* Types that type-of returns. */
3267 Qinteger = intern_c_string ("integer");
3268 Qsymbol = intern_c_string ("symbol");
3269 Qstring = intern_c_string ("string");
3270 Qcons = intern_c_string ("cons");
3271 Qmarker = intern_c_string ("marker");
3272 Qoverlay = intern_c_string ("overlay");
3273 Qfloat = intern_c_string ("float");
3274 Qwindow_configuration = intern_c_string ("window-configuration");
3275 Qprocess = intern_c_string ("process");
3276 Qwindow = intern_c_string ("window");
3277 /* Qsubr = intern_c_string ("subr"); */
3278 Qcompiled_function = intern_c_string ("compiled-function");
3279 Qbuffer = intern_c_string ("buffer");
3280 Qframe = intern_c_string ("frame");
3281 Qvector = intern_c_string ("vector");
3282 Qchar_table = intern_c_string ("char-table");
3283 Qbool_vector = intern_c_string ("bool-vector");
3284 Qhash_table = intern_c_string ("hash-table");
3286 Qthread_local_mark = Fmake_symbol (make_pure_string ("thread-local-mark",
3287 17, 17, 0));
3289 DEFSYM (Qfont_spec, "font-spec");
3290 DEFSYM (Qfont_entity, "font-entity");
3291 DEFSYM (Qfont_object, "font-object");
3293 DEFSYM (Qinteractive_form, "interactive-form");
3295 staticpro (&Qinteger);
3296 staticpro (&Qsymbol);
3297 staticpro (&Qstring);
3298 staticpro (&Qcons);
3299 staticpro (&Qmarker);
3300 staticpro (&Qoverlay);
3301 staticpro (&Qfloat);
3302 staticpro (&Qwindow_configuration);
3303 staticpro (&Qprocess);
3304 staticpro (&Qwindow);
3305 /* staticpro (&Qsubr); */
3306 staticpro (&Qcompiled_function);
3307 staticpro (&Qbuffer);
3308 staticpro (&Qframe);
3309 staticpro (&Qvector);
3310 staticpro (&Qchar_table);
3311 staticpro (&Qbool_vector);
3312 staticpro (&Qhash_table);
3313 staticpro (&Qthread_local_mark);
3315 defsubr (&Sindirect_variable);
3316 defsubr (&Sinteractive_form);
3317 defsubr (&Seq);
3318 defsubr (&Snull);
3319 defsubr (&Stype_of);
3320 defsubr (&Slistp);
3321 defsubr (&Snlistp);
3322 defsubr (&Sconsp);
3323 defsubr (&Satom);
3324 defsubr (&Sintegerp);
3325 defsubr (&Sinteger_or_marker_p);
3326 defsubr (&Snumberp);
3327 defsubr (&Snumber_or_marker_p);
3328 defsubr (&Sfloatp);
3329 defsubr (&Snatnump);
3330 defsubr (&Ssymbolp);
3331 defsubr (&Skeywordp);
3332 defsubr (&Sstringp);
3333 defsubr (&Smultibyte_string_p);
3334 defsubr (&Svectorp);
3335 defsubr (&Schar_table_p);
3336 defsubr (&Svector_or_char_table_p);
3337 defsubr (&Sbool_vector_p);
3338 defsubr (&Sarrayp);
3339 defsubr (&Ssequencep);
3340 defsubr (&Sbufferp);
3341 defsubr (&Smarkerp);
3342 defsubr (&Ssubrp);
3343 defsubr (&Sbyte_code_function_p);
3344 defsubr (&Schar_or_string_p);
3345 defsubr (&Scar);
3346 defsubr (&Scdr);
3347 defsubr (&Scar_safe);
3348 defsubr (&Scdr_safe);
3349 defsubr (&Ssetcar);
3350 defsubr (&Ssetcdr);
3351 defsubr (&Ssymbol_function);
3352 defsubr (&Sindirect_function);
3353 defsubr (&Ssymbol_plist);
3354 defsubr (&Ssymbol_name);
3355 defsubr (&Smakunbound);
3356 defsubr (&Sfmakunbound);
3357 defsubr (&Sboundp);
3358 defsubr (&Sfboundp);
3359 defsubr (&Sfset);
3360 defsubr (&Sdefalias);
3361 defsubr (&Ssetplist);
3362 defsubr (&Ssymbol_value);
3363 defsubr (&Sset);
3364 defsubr (&Sdefault_boundp);
3365 defsubr (&Sdefault_value);
3366 defsubr (&Sset_default);
3367 defsubr (&Ssetq_default);
3368 defsubr (&Smake_variable_buffer_local);
3369 defsubr (&Smake_local_variable);
3370 defsubr (&Skill_local_variable);
3371 defsubr (&Smake_variable_frame_local);
3372 defsubr (&Slocal_variable_p);
3373 defsubr (&Slocal_variable_if_set_p);
3374 defsubr (&Svariable_binding_locus);
3375 #if 0 /* XXX Remove this. --lorentey */
3376 defsubr (&Sterminal_local_value);
3377 defsubr (&Sset_terminal_local_value);
3378 #endif
3379 defsubr (&Saref);
3380 defsubr (&Saset);
3381 defsubr (&Snumber_to_string);
3382 defsubr (&Sstring_to_number);
3383 defsubr (&Seqlsign);
3384 defsubr (&Slss);
3385 defsubr (&Sgtr);
3386 defsubr (&Sleq);
3387 defsubr (&Sgeq);
3388 defsubr (&Sneq);
3389 defsubr (&Szerop);
3390 defsubr (&Splus);
3391 defsubr (&Sminus);
3392 defsubr (&Stimes);
3393 defsubr (&Squo);
3394 defsubr (&Srem);
3395 defsubr (&Smod);
3396 defsubr (&Smax);
3397 defsubr (&Smin);
3398 defsubr (&Slogand);
3399 defsubr (&Slogior);
3400 defsubr (&Slogxor);
3401 defsubr (&Slsh);
3402 defsubr (&Sash);
3403 defsubr (&Sadd1);
3404 defsubr (&Ssub1);
3405 defsubr (&Slognot);
3406 defsubr (&Sbyteorder);
3407 defsubr (&Ssubr_arity);
3408 defsubr (&Ssubr_name);
3410 XSYMBOL (Qwholenump)->function = XSYMBOL (Qnatnump)->function;
3412 DEFVAR_LISP ("most-positive-fixnum", &Vmost_positive_fixnum,
3413 doc: /* The largest value that is representable in a Lisp integer. */);
3414 Vmost_positive_fixnum = make_number (MOST_POSITIVE_FIXNUM);
3415 XSYMBOL (intern_c_string ("most-positive-fixnum"))->constant = 1;
3417 DEFVAR_LISP ("most-negative-fixnum", &Vmost_negative_fixnum,
3418 doc: /* The smallest value that is representable in a Lisp integer. */);
3419 Vmost_negative_fixnum = make_number (MOST_NEGATIVE_FIXNUM);
3420 XSYMBOL (intern_c_string ("most-negative-fixnum"))->constant = 1;
3423 SIGTYPE
3424 arith_error (signo)
3425 int signo;
3427 sigsetmask (SIGEMPTYMASK);
3429 SIGNAL_THREAD_CHECK (signo);
3430 xsignal0 (Qarith_error);
3433 void
3434 init_data ()
3436 /* Don't do this if just dumping out.
3437 We don't want to call `signal' in this case
3438 so that we don't have trouble with dumping
3439 signal-delivering routines in an inconsistent state. */
3440 #ifndef CANNOT_DUMP
3441 if (!initialized)
3442 return;
3443 #endif /* CANNOT_DUMP */
3444 signal (SIGFPE, arith_error);
3446 #ifdef uts
3447 signal (SIGEMT, arith_error);
3448 #endif /* uts */
3451 /* arch-tag: 25879798-b84d-479a-9c89-7d148e2109f7
3452 (do not change this comment) */