Move realvalue to thread_data.
[emacs.git] / src / data.c
blobf0b988b8446e5971fa28c3171dd6b908f5191e0c
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;
105 XSETFASTINT (len, 5);
106 ret = Fmake_vector (len, Qnil);
107 BLOCAL_CLEAR_FLAGS_VEC (ret);
109 if (!NILP (l->thread_data))
111 /* FIXME: use the parent, not the first element. (or not?) */
112 Lisp_Object tem, parent = XCDR (XCAR (l->thread_data));
113 XSETFASTINT (AREF (ret, 0), AREF (parent, 0));
114 BLOCAL_BUFFER_VEC (ret) = BLOCAL_BUFFER_VEC (parent);
115 BLOCAL_FRAME_VEC (ret) = BLOCAL_FRAME_VEC (parent);
116 tem = Fcons (Qnil, Qnil);
117 XSETCAR (tem, tem);
119 BLOCAL_CDR_VEC (ret) = tem;
122 l->thread_data = Fcons (Fcons (get_current_thread (), ret),
123 l->thread_data);
126 return &XCDR_AS_LVALUE (ret);
129 void
130 blocal_set_thread_data (struct Lisp_Buffer_Local_Value *l, Lisp_Object obj)
132 l->thread_data = Fcons (Fcons (get_current_thread (), obj), Qnil);
135 void
136 circular_list_error (list)
137 Lisp_Object list;
139 xsignal (Qcircular_list, list);
143 Lisp_Object
144 wrong_type_argument (predicate, value)
145 register Lisp_Object predicate, value;
147 /* If VALUE is not even a valid Lisp object, we'd want to abort here
148 where we can get a backtrace showing where it came from. We used
149 to try and do that by checking the tagbits, but nowadays all
150 tagbits are potentially valid. */
151 /* if ((unsigned int) XTYPE (value) >= Lisp_Type_Limit)
152 * abort (); */
154 xsignal2 (Qwrong_type_argument, predicate, value);
157 void
158 pure_write_error ()
160 error ("Attempt to modify read-only object");
163 void
164 args_out_of_range (a1, a2)
165 Lisp_Object a1, a2;
167 xsignal2 (Qargs_out_of_range, a1, a2);
170 void
171 args_out_of_range_3 (a1, a2, a3)
172 Lisp_Object a1, a2, a3;
174 xsignal3 (Qargs_out_of_range, a1, a2, a3);
177 /* On some machines, XINT needs a temporary location.
178 Here it is, in case it is needed. */
180 int sign_extend_temp;
182 /* On a few machines, XINT can only be done by calling this. */
185 sign_extend_lisp_int (num)
186 EMACS_INT num;
188 if (num & (((EMACS_INT) 1) << (VALBITS - 1)))
189 return num | (((EMACS_INT) (-1)) << VALBITS);
190 else
191 return num & ((((EMACS_INT) 1) << VALBITS) - 1);
194 /* Data type predicates */
196 DEFUN ("eq", Feq, Seq, 2, 2, 0,
197 doc: /* Return t if the two args are the same Lisp object. */)
198 (obj1, obj2)
199 Lisp_Object obj1, obj2;
201 if (EQ (obj1, obj2))
202 return Qt;
203 return Qnil;
206 DEFUN ("null", Fnull, Snull, 1, 1, 0,
207 doc: /* Return t if OBJECT is nil. */)
208 (object)
209 Lisp_Object object;
211 if (NILP (object))
212 return Qt;
213 return Qnil;
216 DEFUN ("type-of", Ftype_of, Stype_of, 1, 1, 0,
217 doc: /* Return a symbol representing the type of OBJECT.
218 The symbol returned names the object's basic type;
219 for example, (type-of 1) returns `integer'. */)
220 (object)
221 Lisp_Object object;
223 switch (XTYPE (object))
225 case_Lisp_Int:
226 return Qinteger;
228 case Lisp_Symbol:
229 return Qsymbol;
231 case Lisp_String:
232 return Qstring;
234 case Lisp_Cons:
235 return Qcons;
237 case Lisp_Misc:
238 switch (XMISCTYPE (object))
240 case Lisp_Misc_Marker:
241 return Qmarker;
242 case Lisp_Misc_Overlay:
243 return Qoverlay;
244 case Lisp_Misc_Float:
245 return Qfloat;
247 abort ();
249 case Lisp_Vectorlike:
250 if (WINDOW_CONFIGURATIONP (object))
251 return Qwindow_configuration;
252 if (PROCESSP (object))
253 return Qprocess;
254 if (WINDOWP (object))
255 return Qwindow;
256 if (SUBRP (object))
257 return Qsubr;
258 if (COMPILEDP (object))
259 return Qcompiled_function;
260 if (BUFFERP (object))
261 return Qbuffer;
262 if (CHAR_TABLE_P (object))
263 return Qchar_table;
264 if (BOOL_VECTOR_P (object))
265 return Qbool_vector;
266 if (FRAMEP (object))
267 return Qframe;
268 if (HASH_TABLE_P (object))
269 return Qhash_table;
270 if (FONT_SPEC_P (object))
271 return Qfont_spec;
272 if (FONT_ENTITY_P (object))
273 return Qfont_entity;
274 if (FONT_OBJECT_P (object))
275 return Qfont_object;
276 return Qvector;
278 case Lisp_Float:
279 return Qfloat;
281 default:
282 abort ();
286 DEFUN ("consp", Fconsp, Sconsp, 1, 1, 0,
287 doc: /* Return t if OBJECT is a cons cell. */)
288 (object)
289 Lisp_Object object;
291 if (CONSP (object))
292 return Qt;
293 return Qnil;
296 DEFUN ("atom", Fatom, Satom, 1, 1, 0,
297 doc: /* Return t if OBJECT is not a cons cell. This includes nil. */)
298 (object)
299 Lisp_Object object;
301 if (CONSP (object))
302 return Qnil;
303 return Qt;
306 DEFUN ("listp", Flistp, Slistp, 1, 1, 0,
307 doc: /* Return t if OBJECT is a list, that is, a cons cell or nil.
308 Otherwise, return nil. */)
309 (object)
310 Lisp_Object object;
312 if (CONSP (object) || NILP (object))
313 return Qt;
314 return Qnil;
317 DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0,
318 doc: /* Return t if OBJECT is not a list. Lists include nil. */)
319 (object)
320 Lisp_Object object;
322 if (CONSP (object) || NILP (object))
323 return Qnil;
324 return Qt;
327 DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0,
328 doc: /* Return t if OBJECT is a symbol. */)
329 (object)
330 Lisp_Object object;
332 if (SYMBOLP (object))
333 return Qt;
334 return Qnil;
337 /* Define this in C to avoid unnecessarily consing up the symbol
338 name. */
339 DEFUN ("keywordp", Fkeywordp, Skeywordp, 1, 1, 0,
340 doc: /* Return t if OBJECT is a keyword.
341 This means that it is a symbol with a print name beginning with `:'
342 interned in the initial obarray. */)
343 (object)
344 Lisp_Object object;
346 if (SYMBOLP (object)
347 && SREF (SYMBOL_NAME (object), 0) == ':'
348 && SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P (object))
349 return Qt;
350 return Qnil;
353 DEFUN ("vectorp", Fvectorp, Svectorp, 1, 1, 0,
354 doc: /* Return t if OBJECT is a vector. */)
355 (object)
356 Lisp_Object object;
358 if (VECTORP (object))
359 return Qt;
360 return Qnil;
363 DEFUN ("stringp", Fstringp, Sstringp, 1, 1, 0,
364 doc: /* Return t if OBJECT is a string. */)
365 (object)
366 Lisp_Object object;
368 if (STRINGP (object))
369 return Qt;
370 return Qnil;
373 DEFUN ("multibyte-string-p", Fmultibyte_string_p, Smultibyte_string_p,
374 1, 1, 0,
375 doc: /* Return t if OBJECT is a multibyte string. */)
376 (object)
377 Lisp_Object object;
379 if (STRINGP (object) && STRING_MULTIBYTE (object))
380 return Qt;
381 return Qnil;
384 DEFUN ("char-table-p", Fchar_table_p, Schar_table_p, 1, 1, 0,
385 doc: /* Return t if OBJECT is a char-table. */)
386 (object)
387 Lisp_Object object;
389 if (CHAR_TABLE_P (object))
390 return Qt;
391 return Qnil;
394 DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p,
395 Svector_or_char_table_p, 1, 1, 0,
396 doc: /* Return t if OBJECT is a char-table or vector. */)
397 (object)
398 Lisp_Object object;
400 if (VECTORP (object) || CHAR_TABLE_P (object))
401 return Qt;
402 return Qnil;
405 DEFUN ("bool-vector-p", Fbool_vector_p, Sbool_vector_p, 1, 1, 0,
406 doc: /* Return t if OBJECT is a bool-vector. */)
407 (object)
408 Lisp_Object object;
410 if (BOOL_VECTOR_P (object))
411 return Qt;
412 return Qnil;
415 DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0,
416 doc: /* Return t if OBJECT is an array (string or vector). */)
417 (object)
418 Lisp_Object object;
420 if (ARRAYP (object))
421 return Qt;
422 return Qnil;
425 DEFUN ("sequencep", Fsequencep, Ssequencep, 1, 1, 0,
426 doc: /* Return t if OBJECT is a sequence (list or array). */)
427 (object)
428 register Lisp_Object object;
430 if (CONSP (object) || NILP (object) || ARRAYP (object))
431 return Qt;
432 return Qnil;
435 DEFUN ("bufferp", Fbufferp, Sbufferp, 1, 1, 0,
436 doc: /* Return t if OBJECT is an editor buffer. */)
437 (object)
438 Lisp_Object object;
440 if (BUFFERP (object))
441 return Qt;
442 return Qnil;
445 DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0,
446 doc: /* Return t if OBJECT is a marker (editor pointer). */)
447 (object)
448 Lisp_Object object;
450 if (MARKERP (object))
451 return Qt;
452 return Qnil;
455 DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0,
456 doc: /* Return t if OBJECT is a built-in function. */)
457 (object)
458 Lisp_Object object;
460 if (SUBRP (object))
461 return Qt;
462 return Qnil;
465 DEFUN ("byte-code-function-p", Fbyte_code_function_p, Sbyte_code_function_p,
466 1, 1, 0,
467 doc: /* Return t if OBJECT is a byte-compiled function object. */)
468 (object)
469 Lisp_Object object;
471 if (COMPILEDP (object))
472 return Qt;
473 return Qnil;
476 DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0,
477 doc: /* Return t if OBJECT is a character or a string. */)
478 (object)
479 register Lisp_Object object;
481 if (CHARACTERP (object) || STRINGP (object))
482 return Qt;
483 return Qnil;
486 DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0,
487 doc: /* Return t if OBJECT is an integer. */)
488 (object)
489 Lisp_Object object;
491 if (INTEGERP (object))
492 return Qt;
493 return Qnil;
496 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, Sinteger_or_marker_p, 1, 1, 0,
497 doc: /* Return t if OBJECT is an integer or a marker (editor pointer). */)
498 (object)
499 register Lisp_Object object;
501 if (MARKERP (object) || INTEGERP (object))
502 return Qt;
503 return Qnil;
506 DEFUN ("natnump", Fnatnump, Snatnump, 1, 1, 0,
507 doc: /* Return t if OBJECT is a nonnegative integer. */)
508 (object)
509 Lisp_Object object;
511 if (NATNUMP (object))
512 return Qt;
513 return Qnil;
516 DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0,
517 doc: /* Return t if OBJECT is a number (floating point or integer). */)
518 (object)
519 Lisp_Object object;
521 if (NUMBERP (object))
522 return Qt;
523 else
524 return Qnil;
527 DEFUN ("number-or-marker-p", Fnumber_or_marker_p,
528 Snumber_or_marker_p, 1, 1, 0,
529 doc: /* Return t if OBJECT is a number or a marker. */)
530 (object)
531 Lisp_Object object;
533 if (NUMBERP (object) || MARKERP (object))
534 return Qt;
535 return Qnil;
538 DEFUN ("floatp", Ffloatp, Sfloatp, 1, 1, 0,
539 doc: /* Return t if OBJECT is a floating point number. */)
540 (object)
541 Lisp_Object object;
543 if (FLOATP (object))
544 return Qt;
545 return Qnil;
549 /* Extract and set components of lists */
551 DEFUN ("car", Fcar, Scar, 1, 1, 0,
552 doc: /* Return the car of LIST. If arg is nil, return nil.
553 Error if arg is not nil and not a cons cell. See also `car-safe'.
555 See Info node `(elisp)Cons Cells' for a discussion of related basic
556 Lisp concepts such as car, cdr, cons cell and list. */)
557 (list)
558 register Lisp_Object list;
560 return CAR (list);
563 DEFUN ("car-safe", Fcar_safe, Scar_safe, 1, 1, 0,
564 doc: /* Return the car of OBJECT if it is a cons cell, or else nil. */)
565 (object)
566 Lisp_Object object;
568 return CAR_SAFE (object);
571 DEFUN ("cdr", Fcdr, Scdr, 1, 1, 0,
572 doc: /* Return the cdr of LIST. If arg is nil, return nil.
573 Error if arg is not nil and not a cons cell. See also `cdr-safe'.
575 See Info node `(elisp)Cons Cells' for a discussion of related basic
576 Lisp concepts such as cdr, car, cons cell and list. */)
577 (list)
578 register Lisp_Object list;
580 return CDR (list);
583 DEFUN ("cdr-safe", Fcdr_safe, Scdr_safe, 1, 1, 0,
584 doc: /* Return the cdr of OBJECT if it is a cons cell, or else nil. */)
585 (object)
586 Lisp_Object object;
588 return CDR_SAFE (object);
591 DEFUN ("setcar", Fsetcar, Ssetcar, 2, 2, 0,
592 doc: /* Set the car of CELL to be NEWCAR. Returns NEWCAR. */)
593 (cell, newcar)
594 register Lisp_Object cell, newcar;
596 CHECK_CONS (cell);
597 CHECK_IMPURE (cell);
598 XSETCAR (cell, newcar);
599 return newcar;
602 DEFUN ("setcdr", Fsetcdr, Ssetcdr, 2, 2, 0,
603 doc: /* Set the cdr of CELL to be NEWCDR. Returns NEWCDR. */)
604 (cell, newcdr)
605 register Lisp_Object cell, newcdr;
607 CHECK_CONS (cell);
608 CHECK_IMPURE (cell);
609 XSETCDR (cell, newcdr);
610 return newcdr;
613 /* Extract and set components of symbols */
615 DEFUN ("boundp", Fboundp, Sboundp, 1, 1, 0,
616 doc: /* Return t if SYMBOL's value is not void. */)
617 (symbol)
618 register Lisp_Object symbol;
620 Lisp_Object valcontents;
622 valcontents = find_symbol_value (symbol);
624 return (EQ (valcontents, Qunbound) ? Qnil : Qt);
627 DEFUN ("fboundp", Ffboundp, Sfboundp, 1, 1, 0,
628 doc: /* Return t if SYMBOL's function definition is not void. */)
629 (symbol)
630 register Lisp_Object symbol;
632 CHECK_SYMBOL (symbol);
633 return (EQ (XSYMBOL (symbol)->function, Qunbound) ? Qnil : Qt);
636 DEFUN ("makunbound", Fmakunbound, Smakunbound, 1, 1, 0,
637 doc: /* Make SYMBOL's value be void.
638 Return SYMBOL. */)
639 (symbol)
640 register Lisp_Object symbol;
642 CHECK_SYMBOL (symbol);
643 if (SYMBOL_CONSTANT_P (symbol))
644 xsignal1 (Qsetting_constant, symbol);
645 Fset (symbol, Qunbound);
646 return symbol;
649 DEFUN ("fmakunbound", Ffmakunbound, Sfmakunbound, 1, 1, 0,
650 doc: /* Make SYMBOL's function definition be void.
651 Return SYMBOL. */)
652 (symbol)
653 register Lisp_Object symbol;
655 CHECK_SYMBOL (symbol);
656 if (NILP (symbol) || EQ (symbol, Qt))
657 xsignal1 (Qsetting_constant, symbol);
658 XSYMBOL (symbol)->function = Qunbound;
659 return symbol;
662 DEFUN ("symbol-function", Fsymbol_function, Ssymbol_function, 1, 1, 0,
663 doc: /* Return SYMBOL's function definition. Error if that is void. */)
664 (symbol)
665 register Lisp_Object symbol;
667 CHECK_SYMBOL (symbol);
668 if (!EQ (XSYMBOL (symbol)->function, Qunbound))
669 return XSYMBOL (symbol)->function;
670 xsignal1 (Qvoid_function, symbol);
673 DEFUN ("symbol-plist", Fsymbol_plist, Ssymbol_plist, 1, 1, 0,
674 doc: /* Return SYMBOL's property list. */)
675 (symbol)
676 register Lisp_Object symbol;
678 CHECK_SYMBOL (symbol);
679 return XSYMBOL (symbol)->plist;
682 DEFUN ("symbol-name", Fsymbol_name, Ssymbol_name, 1, 1, 0,
683 doc: /* Return SYMBOL's name, a string. */)
684 (symbol)
685 register Lisp_Object symbol;
687 register Lisp_Object name;
689 CHECK_SYMBOL (symbol);
690 name = SYMBOL_NAME (symbol);
691 return name;
694 DEFUN ("fset", Ffset, Sfset, 2, 2, 0,
695 doc: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION. */)
696 (symbol, definition)
697 register Lisp_Object symbol, definition;
699 register Lisp_Object function;
701 CHECK_SYMBOL (symbol);
702 if (NILP (symbol) || EQ (symbol, Qt))
703 xsignal1 (Qsetting_constant, symbol);
705 function = XSYMBOL (symbol)->function;
707 if (!NILP (Vautoload_queue) && !EQ (function, Qunbound))
708 Vautoload_queue = Fcons (Fcons (symbol, function), Vautoload_queue);
710 if (CONSP (function) && EQ (XCAR (function), Qautoload))
711 Fput (symbol, Qautoload, XCDR (function));
713 XSYMBOL (symbol)->function = definition;
714 /* Handle automatic advice activation */
715 if (CONSP (XSYMBOL (symbol)->plist) && !NILP (Fget (symbol, Qad_advice_info)))
717 call2 (Qad_activate_internal, symbol, Qnil);
718 definition = XSYMBOL (symbol)->function;
720 return definition;
723 extern Lisp_Object Qfunction_documentation;
725 DEFUN ("defalias", Fdefalias, Sdefalias, 2, 3, 0,
726 doc: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION.
727 Associates the function with the current load file, if any.
728 The optional third argument DOCSTRING specifies the documentation string
729 for SYMBOL; if it is omitted or nil, SYMBOL uses the documentation string
730 determined by DEFINITION. */)
731 (symbol, definition, docstring)
732 register Lisp_Object symbol, definition, docstring;
734 CHECK_SYMBOL (symbol);
735 if (CONSP (XSYMBOL (symbol)->function)
736 && EQ (XCAR (XSYMBOL (symbol)->function), Qautoload))
737 LOADHIST_ATTACH (Fcons (Qt, symbol));
738 definition = Ffset (symbol, definition);
739 LOADHIST_ATTACH (Fcons (Qdefun, symbol));
740 if (!NILP (docstring))
741 Fput (symbol, Qfunction_documentation, docstring);
742 return definition;
745 DEFUN ("setplist", Fsetplist, Ssetplist, 2, 2, 0,
746 doc: /* Set SYMBOL's property list to NEWPLIST, and return NEWPLIST. */)
747 (symbol, newplist)
748 register Lisp_Object symbol, newplist;
750 CHECK_SYMBOL (symbol);
751 XSYMBOL (symbol)->plist = newplist;
752 return newplist;
755 DEFUN ("subr-arity", Fsubr_arity, Ssubr_arity, 1, 1, 0,
756 doc: /* Return minimum and maximum number of args allowed for SUBR.
757 SUBR must be a built-in function.
758 The returned value is a pair (MIN . MAX). MIN is the minimum number
759 of args. MAX is the maximum number or the symbol `many', for a
760 function with `&rest' args, or `unevalled' for a special form. */)
761 (subr)
762 Lisp_Object subr;
764 short minargs, maxargs;
765 CHECK_SUBR (subr);
766 minargs = XSUBR (subr)->min_args;
767 maxargs = XSUBR (subr)->max_args;
768 if (maxargs == MANY)
769 return Fcons (make_number (minargs), Qmany);
770 else if (maxargs == UNEVALLED)
771 return Fcons (make_number (minargs), Qunevalled);
772 else
773 return Fcons (make_number (minargs), make_number (maxargs));
776 DEFUN ("subr-name", Fsubr_name, Ssubr_name, 1, 1, 0,
777 doc: /* Return name of subroutine SUBR.
778 SUBR must be a built-in function. */)
779 (subr)
780 Lisp_Object subr;
782 const char *name;
783 CHECK_SUBR (subr);
784 name = XSUBR (subr)->symbol_name;
785 return make_string (name, strlen (name));
788 DEFUN ("interactive-form", Finteractive_form, Sinteractive_form, 1, 1, 0,
789 doc: /* Return the interactive form of CMD or nil if none.
790 If CMD is not a command, the return value is nil.
791 Value, if non-nil, is a list \(interactive SPEC). */)
792 (cmd)
793 Lisp_Object cmd;
795 Lisp_Object fun = indirect_function (cmd); /* Check cycles. */
797 if (NILP (fun) || EQ (fun, Qunbound))
798 return Qnil;
800 /* Use an `interactive-form' property if present, analogous to the
801 function-documentation property. */
802 fun = cmd;
803 while (SYMBOLP (fun))
805 Lisp_Object tmp = Fget (fun, Qinteractive_form);
806 if (!NILP (tmp))
807 return tmp;
808 else
809 fun = Fsymbol_function (fun);
812 if (SUBRP (fun))
814 char *spec = XSUBR (fun)->intspec;
815 if (spec)
816 return list2 (Qinteractive,
817 (*spec != '(') ? build_string (spec) :
818 Fcar (Fread_from_string (build_string (spec), Qnil, Qnil)));
820 else if (COMPILEDP (fun))
822 if ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE)
823 return list2 (Qinteractive, AREF (fun, COMPILED_INTERACTIVE));
825 else if (CONSP (fun))
827 Lisp_Object funcar = XCAR (fun);
828 if (EQ (funcar, Qlambda))
829 return Fassq (Qinteractive, Fcdr (XCDR (fun)));
830 else if (EQ (funcar, Qautoload))
832 struct gcpro gcpro1;
833 GCPRO1 (cmd);
834 do_autoload (fun, cmd);
835 UNGCPRO;
836 return Finteractive_form (cmd);
839 return Qnil;
843 /***********************************************************************
844 Getting and Setting Values of Symbols
845 ***********************************************************************/
847 Lisp_Object *
848 find_variable_location (Lisp_Object *root)
850 if (THREADLOCALP (*root))
852 struct Lisp_ThreadLocal *thr = XTHREADLOCAL (*root);
853 Lisp_Object cons = assq_no_quit (get_current_thread (),
854 thr->thread_alist);
855 if (!EQ (cons, Qnil))
856 return &XCDR_AS_LVALUE (cons);
857 return &thr->global;
860 return root;
863 Lisp_Object
864 ensure_thread_local (Lisp_Object *root)
866 Lisp_Object cons;
868 if (THREADLOCALP (*root))
869 cons = assq_no_quit (get_current_thread (),
870 XTHREADLOCAL (*root)->thread_alist);
871 else
873 Lisp_Object newval;
874 newval = allocate_misc ();
875 XMISCTYPE (newval) = Lisp_Misc_ThreadLocal;
876 XTHREADLOCAL (newval)->global = *root;
877 XTHREADLOCAL (newval)->thread_alist = Qnil;
878 *root = newval;
879 cons = Qnil;
882 if (NILP (cons))
884 struct Lisp_ThreadLocal *local = XTHREADLOCAL (*root);
885 cons = Fcons (get_current_thread (), Qthread_local_mark);
886 local->thread_alist = Fcons (cons, local->thread_alist);
889 return cons;
892 void
893 remove_thread_local (Lisp_Object *root)
895 if (THREADLOCALP (*root))
897 Lisp_Object iter, thr = get_current_thread (), prior = Qnil;
898 struct Lisp_ThreadLocal *local = XTHREADLOCAL (*root);
899 for (iter = local->thread_alist; !NILP (iter); iter = XCDR (iter))
901 if (EQ (XCAR (XCAR (iter)), thr))
903 if (NILP (prior))
904 local->thread_alist = XCDR (iter);
905 else
906 XSETCDR (prior, XCDR (iter));
907 break;
909 prior = iter;
914 /* Return the symbol holding SYMBOL's value. Signal
915 `cyclic-variable-indirection' if SYMBOL's chain of variable
916 indirections contains a loop. */
918 struct Lisp_Symbol *
919 indirect_variable (symbol)
920 struct Lisp_Symbol *symbol;
922 struct Lisp_Symbol *tortoise, *hare;
924 hare = tortoise = symbol;
926 while (hare->indirect_variable)
928 hare = XSYMBOL (hare->value);
929 if (!hare->indirect_variable)
930 break;
932 hare = XSYMBOL (hare->value);
933 tortoise = XSYMBOL (tortoise->value);
935 if (hare == tortoise)
937 Lisp_Object tem;
938 XSETSYMBOL (tem, symbol);
939 xsignal1 (Qcyclic_variable_indirection, tem);
943 return hare;
947 DEFUN ("indirect-variable", Findirect_variable, Sindirect_variable, 1, 1, 0,
948 doc: /* Return the variable at the end of OBJECT's variable chain.
949 If OBJECT is a symbol, follow all variable indirections and return the final
950 variable. If OBJECT is not a symbol, just return it.
951 Signal a cyclic-variable-indirection error if there is a loop in the
952 variable chain of symbols. */)
953 (object)
954 Lisp_Object object;
956 if (SYMBOLP (object))
957 XSETSYMBOL (object, indirect_variable (XSYMBOL (object)));
958 return object;
962 /* Given the raw contents of a symbol value cell,
963 return the Lisp value of the symbol.
964 This does not handle buffer-local variables; use
965 swap_in_symval_forwarding for that. */
967 Lisp_Object
968 do_symval_forwarding (valcontents)
969 Lisp_Object valcontents;
971 register Lisp_Object val;
972 if (MISCP (valcontents))
973 switch (XMISCTYPE (valcontents))
975 case Lisp_Misc_Intfwd:
976 XSETINT (val, *XINTFWD (valcontents)->intvar);
977 return val;
979 case Lisp_Misc_Boolfwd:
980 return (*XBOOLFWD (valcontents)->boolvar ? Qt : Qnil);
982 case Lisp_Misc_Objfwd:
983 return *XOBJFWD (valcontents)->objvar;
985 case Lisp_Misc_Buffer_Objfwd:
986 return PER_BUFFER_VALUE (current_buffer,
987 XBUFFER_OBJFWD (valcontents)->offset);
989 case Lisp_Misc_Kboard_Objfwd:
990 /* We used to simply use current_kboard here, but from Lisp
991 code, it's value is often unexpected. It seems nicer to
992 allow constructions like this to work as intuitively expected:
994 (with-selected-frame frame
995 (define-key local-function-map "\eOP" [f1]))
997 On the other hand, this affects the semantics of
998 last-command and real-last-command, and people may rely on
999 that. I took a quick look at the Lisp codebase, and I
1000 don't think anything will break. --lorentey */
1001 return *(Lisp_Object *)(XKBOARD_OBJFWD (valcontents)->offset
1002 + (char *)FRAME_KBOARD (SELECTED_FRAME ()));
1004 case Lisp_Misc_ThreadLocal:
1005 return *find_variable_location (&valcontents);
1007 return valcontents;
1010 /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell
1011 of SYMBOL. If SYMBOL is buffer-local, VALCONTENTS should be the
1012 buffer-independent contents of the value cell: forwarded just one
1013 step past the buffer-localness.
1015 BUF non-zero means set the value in buffer BUF instead of the
1016 current buffer. This only plays a role for per-buffer variables. */
1018 void
1019 store_symval_forwarding (symbol, valcontents, newval, buf)
1020 Lisp_Object symbol;
1021 register Lisp_Object valcontents, newval;
1022 struct buffer *buf;
1024 switch (SWITCH_ENUM_CAST (XTYPE (valcontents)))
1026 case Lisp_Misc:
1027 switch (XMISCTYPE (valcontents))
1029 case Lisp_Misc_Intfwd:
1030 CHECK_NUMBER (newval);
1031 *XINTFWD (valcontents)->intvar = XINT (newval);
1032 /* This can never happen since intvar points to an EMACS_INT
1033 which is at least large enough to hold a Lisp_Object.
1034 if (*XINTFWD (valcontents)->intvar != XINT (newval))
1035 error ("Value out of range for variable `%s'",
1036 SDATA (SYMBOL_NAME (symbol))); */
1037 break;
1039 case Lisp_Misc_Boolfwd:
1040 *XBOOLFWD (valcontents)->boolvar = !NILP (newval);
1041 break;
1043 case Lisp_Misc_Objfwd:
1044 *find_variable_location (XOBJFWD (valcontents)->objvar) = newval;
1046 /* If this variable is a default for something stored
1047 in the buffer itself, such as default-fill-column,
1048 find the buffers that don't have local values for it
1049 and update them. */
1050 if (XOBJFWD (valcontents)->objvar > (Lisp_Object *) &buffer_defaults
1051 && XOBJFWD (valcontents)->objvar < (Lisp_Object *) (&buffer_defaults + 1))
1053 int offset = ((char *) XOBJFWD (valcontents)->objvar
1054 - (char *) &buffer_defaults);
1055 int idx = PER_BUFFER_IDX (offset);
1057 Lisp_Object tail;
1059 if (idx <= 0)
1060 break;
1062 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
1064 Lisp_Object buf;
1065 struct buffer *b;
1067 buf = Fcdr (XCAR (tail));
1068 if (!BUFFERP (buf)) continue;
1069 b = XBUFFER (buf);
1071 if (! PER_BUFFER_VALUE_P (b, idx))
1072 SET_PER_BUFFER_VALUE_RAW (b, offset, newval);
1075 break;
1077 case Lisp_Misc_Buffer_Objfwd:
1079 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1080 Lisp_Object type = XBUFFER_OBJFWD (valcontents)->slottype;
1082 if (!(NILP (type) || NILP (newval)
1083 || (XINT (type) == LISP_INT_TAG
1084 ? INTEGERP (newval)
1085 : XTYPE (newval) == XINT (type))))
1086 buffer_slot_type_mismatch (newval, XINT (type));
1088 if (buf == NULL)
1089 buf = current_buffer;
1090 PER_BUFFER_VALUE (buf, offset) = newval;
1092 break;
1094 case Lisp_Misc_Kboard_Objfwd:
1096 char *base = (char *) FRAME_KBOARD (SELECTED_FRAME ());
1097 char *p = base + XKBOARD_OBJFWD (valcontents)->offset;
1098 *(Lisp_Object *) p = newval;
1100 break;
1102 default:
1103 goto def;
1105 break;
1107 default:
1108 def:
1109 valcontents = SYMBOL_VALUE (symbol);
1110 if (BUFFER_LOCAL_VALUEP (valcontents))
1111 BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (valcontents)) = newval;
1112 else if (THREADLOCALP (valcontents))
1113 *find_variable_location (&indirect_variable (XSYMBOL (symbol))->value) = newval;
1114 else
1115 SET_SYMBOL_VALUE (symbol, newval);
1119 /* Set up SYMBOL to refer to its global binding.
1120 This makes it safe to alter the status of other bindings. */
1122 void
1123 swap_in_global_binding (symbol)
1124 Lisp_Object symbol;
1126 Lisp_Object valcontents = SYMBOL_VALUE (symbol);
1127 struct Lisp_Buffer_Local_Value *blv = XBUFFER_LOCAL_VALUE (valcontents);
1128 Lisp_Object cdr = BLOCAL_CDR (blv);
1130 /* Unload the previously loaded binding. */
1131 Fsetcdr (XCAR (cdr),
1132 do_symval_forwarding (BLOCAL_REALVALUE (blv)));
1134 /* Select the global binding in the symbol. */
1135 XSETCAR (cdr, cdr);
1136 store_symval_forwarding (symbol, BLOCAL_REALVALUE (blv), XCDR (cdr), NULL);
1138 /* Indicate that the global binding is set up now. */
1139 BLOCAL_FRAME (blv) = Qnil;
1140 BLOCAL_BUFFER (blv) = Qnil;
1141 BLOCAL_CLEAR_FLAGS (blv);
1144 /* Set up the buffer-local symbol SYMBOL for validity in the current buffer.
1145 VALCONTENTS is the contents of its value cell,
1146 which points to a struct Lisp_Buffer_Local_Value.
1148 Return the value forwarded one step past the buffer-local stage.
1149 This could be another forwarding pointer. */
1151 static Lisp_Object
1152 swap_in_symval_forwarding (symbol, valcontents)
1153 Lisp_Object symbol, valcontents;
1155 register Lisp_Object tem1;
1157 tem1 = BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents));
1159 if (NILP (tem1)
1160 || current_buffer != XBUFFER (tem1)
1161 || (XBUFFER_LOCAL_VALUE (valcontents)->check_frame
1162 && ! EQ (selected_frame, BLOCAL_FRAME (XBUFFER_LOCAL_VALUE (valcontents)))))
1164 struct Lisp_Symbol *sym = XSYMBOL (symbol);
1165 if (sym->indirect_variable)
1167 sym = indirect_variable (sym);
1168 XSETSYMBOL (symbol, sym);
1171 /* Unload the previously loaded binding. */
1172 tem1 = XCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)));
1173 Fsetcdr (tem1,
1174 do_symval_forwarding (BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (valcontents))));
1175 /* Choose the new binding. */
1176 tem1 = assq_no_quit (symbol, BUF_LOCAL_VAR_ALIST (current_buffer));
1177 BLOCAL_CLEAR_FLAGS (XBUFFER_LOCAL_VALUE (valcontents));
1178 if (NILP (tem1))
1180 if (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
1181 tem1 = assq_no_quit (symbol, XFRAME (selected_frame)->param_alist);
1182 if (! NILP (tem1))
1183 BLOCAL_SET_FOUND_FOR_FRAME (XBUFFER_LOCAL_VALUE (valcontents));
1184 else
1185 tem1 = BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents));
1187 else
1188 BLOCAL_SET_FOUND_FOR_BUFFER (XBUFFER_LOCAL_VALUE (valcontents));
1190 /* Load the new binding. */
1191 XSETCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)), tem1);
1192 XSETBUFFER (BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents)), current_buffer);
1193 BLOCAL_FRAME (XBUFFER_LOCAL_VALUE (valcontents)) = selected_frame;
1194 store_symval_forwarding (symbol,
1195 BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (valcontents)),
1196 Fcdr (tem1), NULL);
1198 return BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (valcontents));
1201 /* Find the value of a symbol, returning Qunbound if it's not bound.
1202 This is helpful for code which just wants to get a variable's value
1203 if it has one, without signaling an error.
1204 Note that it must not be possible to quit
1205 within this function. Great care is required for this. */
1207 Lisp_Object
1208 find_symbol_value (symbol)
1209 Lisp_Object symbol;
1211 register Lisp_Object valcontents;
1212 register Lisp_Object val;
1214 CHECK_SYMBOL (symbol);
1215 valcontents = SYMBOL_VALUE (symbol);
1217 if (BUFFER_LOCAL_VALUEP (valcontents))
1218 valcontents = swap_in_symval_forwarding (symbol, valcontents);
1220 return do_symval_forwarding (valcontents);
1223 DEFUN ("symbol-value", Fsymbol_value, Ssymbol_value, 1, 1, 0,
1224 doc: /* Return SYMBOL's value. Error if that is void. */)
1225 (symbol)
1226 Lisp_Object symbol;
1228 Lisp_Object val;
1230 val = find_symbol_value (symbol);
1231 if (!EQ (val, Qunbound))
1232 return val;
1234 xsignal1 (Qvoid_variable, symbol);
1237 DEFUN ("set", Fset, Sset, 2, 2, 0,
1238 doc: /* Set SYMBOL's value to NEWVAL, and return NEWVAL. */)
1239 (symbol, newval)
1240 register Lisp_Object symbol, newval;
1242 return set_internal (symbol, newval, current_buffer, 0);
1245 /* Return 1 if SYMBOL currently has a let-binding
1246 which was made in the buffer that is now current. */
1248 static int
1249 let_shadows_buffer_binding_p (symbol)
1250 struct Lisp_Symbol *symbol;
1252 volatile struct specbinding *p;
1254 for (p = specpdl_ptr - 1; p >= specpdl; p--)
1255 if (p->func == NULL
1256 && CONSP (p->symbol))
1258 struct Lisp_Symbol *let_bound_symbol = XSYMBOL (XCAR (p->symbol));
1259 if ((symbol == let_bound_symbol
1260 || (let_bound_symbol->indirect_variable
1261 && symbol == indirect_variable (let_bound_symbol)))
1262 && XBUFFER (XCDR (XCDR (p->symbol))) == current_buffer)
1263 break;
1266 return p >= specpdl;
1269 /* Store the value NEWVAL into SYMBOL.
1270 If buffer-locality is an issue, BUF specifies which buffer to use.
1271 (0 stands for the current buffer.)
1273 If BINDFLAG is zero, then if this symbol is supposed to become
1274 local in every buffer where it is set, then we make it local.
1275 If BINDFLAG is nonzero, we don't do that. */
1277 Lisp_Object
1278 set_internal (symbol, newval, buf, bindflag)
1279 register Lisp_Object symbol, newval;
1280 struct buffer *buf;
1281 int bindflag;
1283 int voide = EQ (newval, Qunbound);
1285 register Lisp_Object valcontents, innercontents, tem1, current_alist_element;
1287 if (buf == 0)
1288 buf = current_buffer;
1290 /* If restoring in a dead buffer, do nothing. */
1291 if (NILP (BUF_NAME (buf)))
1292 return newval;
1294 CHECK_SYMBOL (symbol);
1295 if (SYMBOL_CONSTANT_P (symbol)
1296 && (NILP (Fkeywordp (symbol))
1297 || !EQ (newval, SYMBOL_VALUE (symbol))))
1298 xsignal1 (Qsetting_constant, symbol);
1300 innercontents = valcontents = SYMBOL_VALUE (symbol);
1302 if (BUFFER_OBJFWDP (valcontents))
1304 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1305 int idx = PER_BUFFER_IDX (offset);
1306 if (idx > 0
1307 && !bindflag
1308 && !let_shadows_buffer_binding_p (XSYMBOL (symbol)))
1309 SET_PER_BUFFER_VALUE_P (buf, idx, 1);
1311 else if (BUFFER_LOCAL_VALUEP (valcontents))
1313 /* valcontents is a struct Lisp_Buffer_Local_Value. */
1314 if (XSYMBOL (symbol)->indirect_variable)
1315 XSETSYMBOL (symbol, indirect_variable (XSYMBOL (symbol)));
1317 /* What binding is loaded right now? */
1318 current_alist_element
1319 = XCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)));
1321 /* If the current buffer is not the buffer whose binding is
1322 loaded, or if there may be frame-local bindings and the frame
1323 isn't the right one, or if it's a Lisp_Buffer_Local_Value and
1324 the default binding is loaded, the loaded binding may be the
1325 wrong one. */
1326 if (!BUFFERP (BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents)))
1327 || buf != XBUFFER (BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents)))
1328 || (XBUFFER_LOCAL_VALUE (valcontents)->check_frame
1329 && !EQ (selected_frame, BLOCAL_FRAME (XBUFFER_LOCAL_VALUE (valcontents))))
1330 /* Also unload a global binding (if the var is local_if_set). */
1331 || (EQ (XCAR (current_alist_element),
1332 current_alist_element)))
1334 /* The currently loaded binding is not necessarily valid.
1335 We need to unload it, and choose a new binding. */
1337 /* Write out `realvalue' to the old loaded binding. */
1338 Fsetcdr (current_alist_element,
1339 do_symval_forwarding (BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (valcontents))));
1341 /* Find the new binding. */
1342 tem1 = Fassq (symbol, BUF_LOCAL_VAR_ALIST (buf));
1343 BLOCAL_SET_FOUND_FOR_BUFFER (XBUFFER_LOCAL_VALUE (valcontents));
1345 if (NILP (tem1))
1347 /* This buffer still sees the default value. */
1349 /* If the variable is not local_if_set,
1350 or if this is `let' rather than `set',
1351 make CURRENT-ALIST-ELEMENT point to itself,
1352 indicating that we're seeing the default value.
1353 Likewise if the variable has been let-bound
1354 in the current buffer. */
1355 if (bindflag || !XBUFFER_LOCAL_VALUE (valcontents)->local_if_set
1356 || let_shadows_buffer_binding_p (XSYMBOL (symbol)))
1358 BLOCAL_CLEAR_FLAGS (XBUFFER_LOCAL_VALUE (valcontents));
1360 if (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
1361 tem1 = Fassq (symbol,
1362 XFRAME (selected_frame)->param_alist);
1364 if (! NILP (tem1))
1365 BLOCAL_SET_FOUND_FOR_FRAME (XBUFFER_LOCAL_VALUE (valcontents));
1366 else
1367 tem1 = BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents));
1369 /* If it's a Lisp_Buffer_Local_Value, being set not bound,
1370 and we're not within a let that was made for this buffer,
1371 create a new buffer-local binding for the variable.
1372 That means, give this buffer a new assoc for a local value
1373 and load that binding. */
1374 else
1376 tem1 = Fcons (symbol, XCDR (current_alist_element));
1377 BUF_LOCAL_VAR_ALIST (buf)
1378 = Fcons (tem1, BUF_LOCAL_VAR_ALIST (buf));
1382 /* Record which binding is now loaded. */
1383 XSETCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)), tem1);
1385 /* Set `buffer' and `frame' slots for the binding now loaded. */
1386 XSETBUFFER (BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents)), buf);
1387 BLOCAL_FRAME (XBUFFER_LOCAL_VALUE (valcontents)) = selected_frame;
1389 innercontents = BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (valcontents));
1391 /* Store the new value in the cons-cell. */
1392 XSETCDR (XCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents))), newval);
1395 /* If storing void (making the symbol void), forward only through
1396 buffer-local indicator, not through Lisp_Objfwd, etc. */
1397 if (voide)
1398 store_symval_forwarding (symbol, Qnil, newval, buf);
1399 else
1400 store_symval_forwarding (symbol, innercontents, newval, buf);
1402 return newval;
1405 /* Access or set a buffer-local symbol's default value. */
1407 /* Return the default value of SYMBOL, but don't check for voidness.
1408 Return Qunbound if it is void. */
1410 Lisp_Object
1411 default_value (symbol)
1412 Lisp_Object symbol;
1414 register Lisp_Object valcontents;
1416 CHECK_SYMBOL (symbol);
1417 valcontents = SYMBOL_VALUE (symbol);
1419 /* For a built-in buffer-local variable, get the default value
1420 rather than letting do_symval_forwarding get the current value. */
1421 if (BUFFER_OBJFWDP (valcontents))
1423 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1424 if (PER_BUFFER_IDX (offset) != 0)
1425 return PER_BUFFER_DEFAULT (offset);
1428 /* Handle user-created local variables. */
1429 if (BUFFER_LOCAL_VALUEP (valcontents))
1431 /* If var is set up for a buffer that lacks a local value for it,
1432 the current value is nominally the default value.
1433 But the `realvalue' slot may be more up to date, since
1434 ordinary setq stores just that slot. So use that. */
1435 Lisp_Object current_alist_element, alist_element_car;
1436 current_alist_element
1437 = XCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)));
1438 alist_element_car = XCAR (current_alist_element);
1439 if (EQ (alist_element_car, current_alist_element))
1440 return do_symval_forwarding (BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (valcontents)));
1441 else
1442 return XCDR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)));
1444 /* For other variables, get the current value. */
1445 return do_symval_forwarding (valcontents);
1448 DEFUN ("default-boundp", Fdefault_boundp, Sdefault_boundp, 1, 1, 0,
1449 doc: /* Return t if SYMBOL has a non-void default value.
1450 This is the value that is seen in buffers that do not have their own values
1451 for this variable. */)
1452 (symbol)
1453 Lisp_Object symbol;
1455 register Lisp_Object value;
1457 value = default_value (symbol);
1458 return (EQ (value, Qunbound) ? Qnil : Qt);
1461 DEFUN ("default-value", Fdefault_value, Sdefault_value, 1, 1, 0,
1462 doc: /* Return SYMBOL's default value.
1463 This is the value that is seen in buffers that do not have their own values
1464 for this variable. The default value is meaningful for variables with
1465 local bindings in certain buffers. */)
1466 (symbol)
1467 Lisp_Object symbol;
1469 register Lisp_Object value;
1471 value = default_value (symbol);
1472 if (!EQ (value, Qunbound))
1473 return value;
1475 xsignal1 (Qvoid_variable, symbol);
1478 DEFUN ("set-default", Fset_default, Sset_default, 2, 2, 0,
1479 doc: /* Set SYMBOL's default value to VALUE. SYMBOL and VALUE are evaluated.
1480 The default value is seen in buffers that do not have their own values
1481 for this variable. */)
1482 (symbol, value)
1483 Lisp_Object symbol, value;
1485 register Lisp_Object valcontents, current_alist_element, alist_element_buffer;
1487 CHECK_SYMBOL (symbol);
1488 valcontents = SYMBOL_VALUE (symbol);
1490 /* Handle variables like case-fold-search that have special slots
1491 in the buffer. Make them work apparently like Lisp_Buffer_Local_Value
1492 variables. */
1493 if (BUFFER_OBJFWDP (valcontents))
1495 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1496 int idx = PER_BUFFER_IDX (offset);
1498 PER_BUFFER_DEFAULT (offset) = value;
1500 /* If this variable is not always local in all buffers,
1501 set it in the buffers that don't nominally have a local value. */
1502 if (idx > 0)
1504 struct buffer *b;
1506 for (b = all_buffers; b; b = b->next)
1507 if (!PER_BUFFER_VALUE_P (b, idx))
1508 PER_BUFFER_VALUE (b, offset) = value;
1510 return value;
1513 if (!BUFFER_LOCAL_VALUEP (valcontents))
1514 return Fset (symbol, value);
1516 /* Store new value into the DEFAULT-VALUE slot. */
1517 XSETCDR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)), value);
1519 /* If the default binding is now loaded, set the REALVALUE slot too. */
1520 current_alist_element
1521 = XCAR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (valcontents)));
1522 alist_element_buffer = Fcar (current_alist_element);
1523 if (EQ (alist_element_buffer, current_alist_element))
1524 store_symval_forwarding (symbol,
1525 BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (valcontents)),
1526 value, NULL);
1528 return value;
1531 DEFUN ("setq-default", Fsetq_default, Ssetq_default, 0, UNEVALLED, 0,
1532 doc: /* Set the default value of variable VAR to VALUE.
1533 VAR, the variable name, is literal (not evaluated);
1534 VALUE is an expression: it is evaluated and its value returned.
1535 The default value of a variable is seen in buffers
1536 that do not have their own values for the variable.
1538 More generally, you can use multiple variables and values, as in
1539 (setq-default VAR VALUE VAR VALUE...)
1540 This sets each VAR's default value to the corresponding VALUE.
1541 The VALUE for the Nth VAR can refer to the new default values
1542 of previous VARs.
1543 usage: (setq-default [VAR VALUE]...) */)
1544 (args)
1545 Lisp_Object args;
1547 register Lisp_Object args_left;
1548 register Lisp_Object val, symbol;
1549 struct gcpro gcpro1;
1551 if (NILP (args))
1552 return Qnil;
1554 args_left = args;
1555 GCPRO1 (args);
1559 val = Feval (Fcar (Fcdr (args_left)));
1560 symbol = XCAR (args_left);
1561 Fset_default (symbol, val);
1562 args_left = Fcdr (XCDR (args_left));
1564 while (!NILP (args_left));
1566 UNGCPRO;
1567 return val;
1570 /* Lisp functions for creating and removing buffer-local variables. */
1572 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local, Smake_variable_buffer_local,
1573 1, 1, "vMake Variable Buffer Local: ",
1574 doc: /* Make VARIABLE become buffer-local whenever it is set.
1575 At any time, the value for the current buffer is in effect,
1576 unless the variable has never been set in this buffer,
1577 in which case the default value is in effect.
1578 Note that binding the variable with `let', or setting it while
1579 a `let'-style binding made in this buffer is in effect,
1580 does not make the variable buffer-local. Return VARIABLE.
1582 In most cases it is better to use `make-local-variable',
1583 which makes a variable local in just one buffer.
1585 The function `default-value' gets the default value and `set-default' sets it. */)
1586 (variable)
1587 register Lisp_Object variable;
1589 register Lisp_Object tem, valcontents, newval;
1590 struct Lisp_Symbol *sym;
1592 CHECK_SYMBOL (variable);
1593 sym = indirect_variable (XSYMBOL (variable));
1595 valcontents = sym->value;
1596 if (sym->constant || KBOARD_OBJFWDP (valcontents))
1597 error ("Symbol %s may not be buffer-local", SDATA (sym->xname));
1599 if (BUFFER_OBJFWDP (valcontents))
1600 return variable;
1601 else if (BUFFER_LOCAL_VALUEP (valcontents))
1603 if (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
1604 error ("Symbol %s may not be buffer-local", SDATA (sym->xname));
1605 newval = valcontents;
1607 else
1609 Lisp_Object len, val_vec;
1610 XSETFASTINT (len, 5);
1611 val_vec = Fmake_vector (len, Qnil);
1612 if (EQ (valcontents, Qunbound))
1613 sym->value = Qnil;
1614 tem = Fcons (Qnil, Fsymbol_value (variable));
1615 XSETCAR (tem, tem);
1616 newval = allocate_misc ();
1617 XMISCTYPE (newval) = Lisp_Misc_Buffer_Local_Value;
1618 XBUFFER_LOCAL_VALUE (newval)->thread_data = Qnil;
1619 BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (newval)) = sym->value;
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 sym->value = newval;
1628 XBUFFER_LOCAL_VALUE (newval)->local_if_set = 1;
1629 return variable;
1632 DEFUN ("make-local-variable", Fmake_local_variable, Smake_local_variable,
1633 1, 1, "vMake Local Variable: ",
1634 doc: /* Make VARIABLE have a separate value in the current buffer.
1635 Other buffers will continue to share a common default value.
1636 \(The buffer-local value of VARIABLE starts out as the same value
1637 VARIABLE previously had. If VARIABLE was void, it remains void.\)
1638 Return VARIABLE.
1640 If the variable is already arranged to become local when set,
1641 this function causes a local value to exist for this buffer,
1642 just as setting the variable would do.
1644 This function returns VARIABLE, and therefore
1645 (set (make-local-variable 'VARIABLE) VALUE-EXP)
1646 works.
1648 See also `make-variable-buffer-local'.
1650 Do not use `make-local-variable' to make a hook variable buffer-local.
1651 Instead, use `add-hook' and specify t for the LOCAL argument. */)
1652 (variable)
1653 register Lisp_Object variable;
1655 register Lisp_Object tem, valcontents;
1656 struct Lisp_Symbol *sym;
1658 CHECK_SYMBOL (variable);
1659 sym = indirect_variable (XSYMBOL (variable));
1661 valcontents = sym->value;
1662 if (sym->constant || KBOARD_OBJFWDP (valcontents)
1663 || (BUFFER_LOCAL_VALUEP (valcontents)
1664 && (XBUFFER_LOCAL_VALUE (valcontents)->check_frame)))
1665 error ("Symbol %s may not be buffer-local", SDATA (sym->xname));
1667 if ((BUFFER_LOCAL_VALUEP (valcontents)
1668 && XBUFFER_LOCAL_VALUE (valcontents)->local_if_set)
1669 || BUFFER_OBJFWDP (valcontents))
1671 tem = Fboundp (variable);
1673 /* Make sure the symbol has a local value in this particular buffer,
1674 by setting it to the same value it already has. */
1675 Fset (variable, (EQ (tem, Qt) ? Fsymbol_value (variable) : Qunbound));
1676 return variable;
1678 /* Make sure symbol is set up to hold per-buffer values. */
1679 if (!BUFFER_LOCAL_VALUEP (valcontents))
1681 Lisp_Object newval, len, val_vec;
1682 XSETFASTINT (len, 5);
1683 val_vec = Fmake_vector (len, Qnil);
1684 tem = Fcons (Qnil, do_symval_forwarding (valcontents));
1685 XSETCAR (tem, tem);
1686 newval = allocate_misc ();
1687 XMISCTYPE (newval) = Lisp_Misc_Buffer_Local_Value;
1688 XBUFFER_LOCAL_VALUE (newval)->thread_data = Qnil;
1689 BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (newval)) = sym->value;
1690 BLOCAL_CDR_VEC (val_vec);
1691 BLOCAL_BUFFER_VEC (val_vec) = Qnil;
1692 BLOCAL_FRAME_VEC (val_vec) = Qnil;
1693 BLOCAL_REALVALUE_VEC (val_vec) = Qnil;
1694 BLOCAL_CDR_VEC (val_vec) = tem;
1695 XBUFFER_LOCAL_VALUE (newval)->local_if_set = 0;
1696 XBUFFER_LOCAL_VALUE (newval)->check_frame = 0;
1697 BLOCAL_SET_THREAD_DATA (XBUFFER_LOCAL_VALUE (newval), val_vec);
1698 sym->value = newval;
1700 /* Make sure this buffer has its own value of symbol. */
1701 XSETSYMBOL (variable, sym); /* Propagate variable indirections. */
1702 tem = Fassq (variable, BUF_LOCAL_VAR_ALIST (current_buffer));
1703 if (NILP (tem))
1705 /* Swap out any local binding for some other buffer, and make
1706 sure the current value is permanently recorded, if it's the
1707 default value. */
1708 find_symbol_value (variable);
1710 BUF_LOCAL_VAR_ALIST (current_buffer)
1711 = Fcons (Fcons (variable, XCDR (BLOCAL_CDR (XBUFFER_LOCAL_VALUE (sym->value)))),
1712 BUF_LOCAL_VAR_ALIST (current_buffer));
1714 /* Make sure symbol does not think it is set up for this buffer;
1715 force it to look once again for this buffer's value. */
1717 Lisp_Object *pvalbuf;
1719 valcontents = sym->value;
1721 pvalbuf = &BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents));
1722 if (current_buffer == XBUFFER (*pvalbuf))
1723 *pvalbuf = Qnil;
1724 BLOCAL_CLEAR_FLAGS (XBUFFER_LOCAL_VALUE (valcontents));
1728 /* If the symbol forwards into a C variable, then load the binding
1729 for this buffer now. If C code modifies the variable before we
1730 load the binding in, then that new value will clobber the default
1731 binding the next time we unload it. */
1732 valcontents = BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (sym->value));
1733 if (INTFWDP (valcontents) || BOOLFWDP (valcontents) || OBJFWDP (valcontents))
1734 swap_in_symval_forwarding (variable, sym->value);
1736 return variable;
1739 DEFUN ("kill-local-variable", Fkill_local_variable, Skill_local_variable,
1740 1, 1, "vKill Local Variable: ",
1741 doc: /* Make VARIABLE no longer have a separate value in the current buffer.
1742 From now on the default value will apply in this buffer. Return VARIABLE. */)
1743 (variable)
1744 register Lisp_Object variable;
1746 register Lisp_Object tem, valcontents;
1747 struct Lisp_Symbol *sym;
1749 CHECK_SYMBOL (variable);
1750 sym = indirect_variable (XSYMBOL (variable));
1752 valcontents = sym->value;
1754 if (BUFFER_OBJFWDP (valcontents))
1756 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1757 int idx = PER_BUFFER_IDX (offset);
1759 if (idx > 0)
1761 SET_PER_BUFFER_VALUE_P (current_buffer, idx, 0);
1762 PER_BUFFER_VALUE (current_buffer, offset)
1763 = PER_BUFFER_DEFAULT (offset);
1765 return variable;
1768 if (!BUFFER_LOCAL_VALUEP (valcontents))
1769 return variable;
1771 /* Get rid of this buffer's alist element, if any. */
1772 XSETSYMBOL (variable, sym); /* Propagate variable indirection. */
1773 tem = Fassq (variable, BUF_LOCAL_VAR_ALIST (current_buffer));
1774 if (!NILP (tem))
1775 BUF_LOCAL_VAR_ALIST (current_buffer)
1776 = Fdelq (tem, BUF_LOCAL_VAR_ALIST (current_buffer));
1778 /* If the symbol is set up with the current buffer's binding
1779 loaded, recompute its value. We have to do it now, or else
1780 forwarded objects won't work right. */
1782 Lisp_Object *pvalbuf, buf;
1783 valcontents = sym->value;
1784 pvalbuf = &BLOCAL_BUFFER (XBUFFER_LOCAL_VALUE (valcontents));
1785 XSETBUFFER (buf, current_buffer);
1786 if (EQ (buf, *pvalbuf))
1788 *pvalbuf = Qnil;
1789 BLOCAL_CLEAR_FLAGS (XBUFFER_LOCAL_VALUE (valcontents));
1790 find_symbol_value (variable);
1794 return variable;
1797 /* Lisp functions for creating and removing buffer-local variables. */
1799 /* Obsolete since 22.2. NB adjust doc of modify-frame-parameters
1800 when/if this is removed. */
1802 DEFUN ("make-variable-frame-local", Fmake_variable_frame_local, Smake_variable_frame_local,
1803 1, 1, "vMake Variable Frame Local: ",
1804 doc: /* Enable VARIABLE to have frame-local bindings.
1805 This does not create any frame-local bindings for VARIABLE,
1806 it just makes them possible.
1808 A frame-local binding is actually a frame parameter value.
1809 If a frame F has a value for the frame parameter named VARIABLE,
1810 that also acts as a frame-local binding for VARIABLE in F--
1811 provided this function has been called to enable VARIABLE
1812 to have frame-local bindings at all.
1814 The only way to create a frame-local binding for VARIABLE in a frame
1815 is to set the VARIABLE frame parameter of that frame. See
1816 `modify-frame-parameters' for how to set frame parameters.
1818 Note that since Emacs 23.1, variables cannot be both buffer-local and
1819 frame-local any more (buffer-local bindings used to take precedence over
1820 frame-local bindings). */)
1821 (variable)
1822 register Lisp_Object variable;
1824 register Lisp_Object tem, valcontents, newval, val_vec, len;
1825 struct Lisp_Symbol *sym;
1827 CHECK_SYMBOL (variable);
1828 sym = indirect_variable (XSYMBOL (variable));
1830 valcontents = sym->value;
1831 if (sym->constant || KBOARD_OBJFWDP (valcontents)
1832 || BUFFER_OBJFWDP (valcontents))
1833 error ("Symbol %s may not be frame-local", SDATA (sym->xname));
1835 if (BUFFER_LOCAL_VALUEP (valcontents))
1837 if (!XBUFFER_LOCAL_VALUE (valcontents)->check_frame)
1838 error ("Symbol %s may not be frame-local", SDATA (sym->xname));
1839 return variable;
1842 if (EQ (valcontents, Qunbound))
1843 sym->value = Qnil;
1844 tem = Fcons (Qnil, Fsymbol_value (variable));
1845 XSETCAR (tem, tem);
1846 newval = allocate_misc ();
1847 XSETFASTINT (len, 5);
1848 val_vec = Fmake_vector (len, Qnil);
1849 XMISCTYPE (newval) = Lisp_Misc_Buffer_Local_Value;
1850 XBUFFER_LOCAL_VALUE (newval)->thread_data = Qnil;
1851 BLOCAL_REALVALUE (XBUFFER_LOCAL_VALUE (newval)) = sym->value;
1852 BLOCAL_CLEAR_FLAGS_VEC (val_vec);
1853 BLOCAL_BUFFER_VEC (val_vec) = Qnil;
1854 BLOCAL_FRAME_VEC (val_vec) = Qnil;
1855 BLOCAL_CDR_VEC (val_vec) = tem;
1856 BLOCAL_REALVALUE_VEC (val_vec) = Qnil;
1857 XBUFFER_LOCAL_VALUE (newval)->local_if_set = 0;
1858 XBUFFER_LOCAL_VALUE (newval)->check_frame = 1;
1859 BLOCAL_SET_THREAD_DATA (XBUFFER_LOCAL_VALUE (newval), val_vec);
1860 sym->value = newval;
1861 return variable;
1864 DEFUN ("local-variable-p", Flocal_variable_p, Slocal_variable_p,
1865 1, 2, 0,
1866 doc: /* Non-nil if VARIABLE has a local binding in buffer BUFFER.
1867 BUFFER defaults to the current buffer. */)
1868 (variable, buffer)
1869 register Lisp_Object variable, buffer;
1871 Lisp_Object valcontents;
1872 register struct buffer *buf;
1873 struct Lisp_Symbol *sym;
1875 if (NILP (buffer))
1876 buf = current_buffer;
1877 else
1879 CHECK_BUFFER (buffer);
1880 buf = XBUFFER (buffer);
1883 CHECK_SYMBOL (variable);
1884 sym = indirect_variable (XSYMBOL (variable));
1885 XSETSYMBOL (variable, sym);
1887 valcontents = sym->value;
1888 if (BUFFER_LOCAL_VALUEP (valcontents))
1890 Lisp_Object tail, elt;
1892 for (tail = BUF_LOCAL_VAR_ALIST (buf); CONSP (tail); tail = XCDR (tail))
1894 elt = XCAR (tail);
1895 if (EQ (variable, XCAR (elt)))
1896 return Qt;
1899 if (BUFFER_OBJFWDP (valcontents))
1901 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1902 int idx = PER_BUFFER_IDX (offset);
1903 if (idx == -1 || PER_BUFFER_VALUE_P (buf, idx))
1904 return Qt;
1906 return Qnil;
1909 DEFUN ("local-variable-if-set-p", Flocal_variable_if_set_p, Slocal_variable_if_set_p,
1910 1, 2, 0,
1911 doc: /* Non-nil if VARIABLE will be local in buffer BUFFER when set there.
1912 More precisely, this means that setting the variable \(with `set' or`setq'),
1913 while it does not have a `let'-style binding that was made in BUFFER,
1914 will produce a buffer local binding. See Info node
1915 `(elisp)Creating Buffer-Local'.
1916 BUFFER defaults to the current buffer. */)
1917 (variable, buffer)
1918 register Lisp_Object variable, buffer;
1920 Lisp_Object valcontents;
1921 register struct buffer *buf;
1922 struct Lisp_Symbol *sym;
1924 if (NILP (buffer))
1925 buf = current_buffer;
1926 else
1928 CHECK_BUFFER (buffer);
1929 buf = XBUFFER (buffer);
1932 CHECK_SYMBOL (variable);
1933 sym = indirect_variable (XSYMBOL (variable));
1934 XSETSYMBOL (variable, sym);
1936 valcontents = sym->value;
1938 if (BUFFER_OBJFWDP (valcontents))
1939 /* All these slots become local if they are set. */
1940 return Qt;
1941 else if (BUFFER_LOCAL_VALUEP (valcontents))
1943 Lisp_Object tail, elt;
1944 if (XBUFFER_LOCAL_VALUE (valcontents)->local_if_set)
1945 return Qt;
1946 for (tail = BUF_LOCAL_VAR_ALIST (buf); CONSP (tail); tail = XCDR (tail))
1948 elt = XCAR (tail);
1949 if (EQ (variable, XCAR (elt)))
1950 return Qt;
1953 return Qnil;
1956 DEFUN ("variable-binding-locus", Fvariable_binding_locus, Svariable_binding_locus,
1957 1, 1, 0,
1958 doc: /* Return a value indicating where VARIABLE's current binding comes from.
1959 If the current binding is buffer-local, the value is the current buffer.
1960 If the current binding is frame-local, the value is the selected frame.
1961 If the current binding is global (the default), the value is nil. */)
1962 (variable)
1963 register Lisp_Object variable;
1965 Lisp_Object valcontents;
1966 struct Lisp_Symbol *sym;
1968 CHECK_SYMBOL (variable);
1969 sym = indirect_variable (XSYMBOL (variable));
1971 /* Make sure the current binding is actually swapped in. */
1972 find_symbol_value (variable);
1974 valcontents = sym->value;
1976 if (BUFFER_LOCAL_VALUEP (valcontents)
1977 || BUFFER_OBJFWDP (valcontents))
1979 /* For a local variable, record both the symbol and which
1980 buffer's or frame's value we are saving. */
1981 if (!NILP (Flocal_variable_p (variable, Qnil)))
1982 return Fcurrent_buffer ();
1983 else if (BUFFER_LOCAL_VALUEP (valcontents)
1984 && BLOCAL_FOUND_FOR_FRAME (XBUFFER_LOCAL_VALUE (valcontents)))
1985 return BLOCAL_FRAME (XBUFFER_LOCAL_VALUE (valcontents));
1988 return Qnil;
1991 /* This code is disabled now that we use the selected frame to return
1992 keyboard-local-values. */
1993 #if 0
1994 extern struct terminal *get_terminal P_ ((Lisp_Object display, int));
1996 DEFUN ("terminal-local-value", Fterminal_local_value, Sterminal_local_value, 2, 2, 0,
1997 doc: /* Return the terminal-local value of SYMBOL on TERMINAL.
1998 If SYMBOL is not a terminal-local variable, then return its normal
1999 value, like `symbol-value'.
2001 TERMINAL may be a terminal object, a frame, or nil (meaning the
2002 selected frame's terminal device). */)
2003 (symbol, terminal)
2004 Lisp_Object symbol;
2005 Lisp_Object terminal;
2007 Lisp_Object result;
2008 struct terminal *t = get_terminal (terminal, 1);
2009 push_kboard (t->kboard);
2010 result = Fsymbol_value (symbol);
2011 pop_kboard ();
2012 return result;
2015 DEFUN ("set-terminal-local-value", Fset_terminal_local_value, Sset_terminal_local_value, 3, 3, 0,
2016 doc: /* Set the terminal-local binding of SYMBOL on TERMINAL to VALUE.
2017 If VARIABLE is not a terminal-local variable, then set its normal
2018 binding, like `set'.
2020 TERMINAL may be a terminal object, a frame, or nil (meaning the
2021 selected frame's terminal device). */)
2022 (symbol, terminal, value)
2023 Lisp_Object symbol;
2024 Lisp_Object terminal;
2025 Lisp_Object value;
2027 Lisp_Object result;
2028 struct terminal *t = get_terminal (terminal, 1);
2029 push_kboard (d->kboard);
2030 result = Fset (symbol, value);
2031 pop_kboard ();
2032 return result;
2034 #endif
2036 /* Find the function at the end of a chain of symbol function indirections. */
2038 /* If OBJECT is a symbol, find the end of its function chain and
2039 return the value found there. If OBJECT is not a symbol, just
2040 return it. If there is a cycle in the function chain, signal a
2041 cyclic-function-indirection error.
2043 This is like Findirect_function, except that it doesn't signal an
2044 error if the chain ends up unbound. */
2045 Lisp_Object
2046 indirect_function (object)
2047 register Lisp_Object object;
2049 Lisp_Object tortoise, hare;
2051 hare = tortoise = object;
2053 for (;;)
2055 if (!SYMBOLP (hare) || EQ (hare, Qunbound))
2056 break;
2057 hare = XSYMBOL (hare)->function;
2058 if (!SYMBOLP (hare) || EQ (hare, Qunbound))
2059 break;
2060 hare = XSYMBOL (hare)->function;
2062 tortoise = XSYMBOL (tortoise)->function;
2064 if (EQ (hare, tortoise))
2065 xsignal1 (Qcyclic_function_indirection, object);
2068 return hare;
2071 DEFUN ("indirect-function", Findirect_function, Sindirect_function, 1, 2, 0,
2072 doc: /* Return the function at the end of OBJECT's function chain.
2073 If OBJECT is not a symbol, just return it. Otherwise, follow all
2074 function indirections to find the final function binding and return it.
2075 If the final symbol in the chain is unbound, signal a void-function error.
2076 Optional arg NOERROR non-nil means to return nil instead of signalling.
2077 Signal a cyclic-function-indirection error if there is a loop in the
2078 function chain of symbols. */)
2079 (object, noerror)
2080 register Lisp_Object object;
2081 Lisp_Object noerror;
2083 Lisp_Object result;
2085 /* Optimize for no indirection. */
2086 result = object;
2087 if (SYMBOLP (result) && !EQ (result, Qunbound)
2088 && (result = XSYMBOL (result)->function, SYMBOLP (result)))
2089 result = indirect_function (result);
2090 if (!EQ (result, Qunbound))
2091 return result;
2093 if (NILP (noerror))
2094 xsignal1 (Qvoid_function, object);
2096 return Qnil;
2099 /* Extract and set vector and string elements */
2101 DEFUN ("aref", Faref, Saref, 2, 2, 0,
2102 doc: /* Return the element of ARRAY at index IDX.
2103 ARRAY may be a vector, a string, a char-table, a bool-vector,
2104 or a byte-code object. IDX starts at 0. */)
2105 (array, idx)
2106 register Lisp_Object array;
2107 Lisp_Object idx;
2109 register int idxval;
2111 CHECK_NUMBER (idx);
2112 idxval = XINT (idx);
2113 if (STRINGP (array))
2115 int c, idxval_byte;
2117 if (idxval < 0 || idxval >= SCHARS (array))
2118 args_out_of_range (array, idx);
2119 if (! STRING_MULTIBYTE (array))
2120 return make_number ((unsigned char) SREF (array, idxval));
2121 idxval_byte = string_char_to_byte (array, idxval);
2123 c = STRING_CHAR (SDATA (array) + idxval_byte);
2124 return make_number (c);
2126 else if (BOOL_VECTOR_P (array))
2128 int val;
2130 if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size)
2131 args_out_of_range (array, idx);
2133 val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR];
2134 return (val & (1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR)) ? Qt : Qnil);
2136 else if (CHAR_TABLE_P (array))
2138 CHECK_CHARACTER (idx);
2139 return CHAR_TABLE_REF (array, idxval);
2141 else
2143 int size = 0;
2144 if (VECTORP (array))
2145 size = XVECTOR (array)->size;
2146 else if (COMPILEDP (array))
2147 size = XVECTOR (array)->size & PSEUDOVECTOR_SIZE_MASK;
2148 else
2149 wrong_type_argument (Qarrayp, array);
2151 if (idxval < 0 || idxval >= size)
2152 args_out_of_range (array, idx);
2153 return XVECTOR (array)->contents[idxval];
2157 DEFUN ("aset", Faset, Saset, 3, 3, 0,
2158 doc: /* Store into the element of ARRAY at index IDX the value NEWELT.
2159 Return NEWELT. ARRAY may be a vector, a string, a char-table or a
2160 bool-vector. IDX starts at 0. */)
2161 (array, idx, newelt)
2162 register Lisp_Object array;
2163 Lisp_Object idx, newelt;
2165 register int idxval;
2167 CHECK_NUMBER (idx);
2168 idxval = XINT (idx);
2169 CHECK_ARRAY (array, Qarrayp);
2170 CHECK_IMPURE (array);
2172 if (VECTORP (array))
2174 if (idxval < 0 || idxval >= XVECTOR (array)->size)
2175 args_out_of_range (array, idx);
2176 XVECTOR (array)->contents[idxval] = newelt;
2178 else if (BOOL_VECTOR_P (array))
2180 int val;
2182 if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size)
2183 args_out_of_range (array, idx);
2185 val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR];
2187 if (! NILP (newelt))
2188 val |= 1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR);
2189 else
2190 val &= ~(1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR));
2191 XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR] = val;
2193 else if (CHAR_TABLE_P (array))
2195 CHECK_CHARACTER (idx);
2196 CHAR_TABLE_SET (array, idxval, newelt);
2198 else if (STRING_MULTIBYTE (array))
2200 int idxval_byte, prev_bytes, new_bytes, nbytes;
2201 unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1;
2203 if (idxval < 0 || idxval >= SCHARS (array))
2204 args_out_of_range (array, idx);
2205 CHECK_CHARACTER (newelt);
2207 nbytes = SBYTES (array);
2209 idxval_byte = string_char_to_byte (array, idxval);
2210 p1 = SDATA (array) + idxval_byte;
2211 PARSE_MULTIBYTE_SEQ (p1, nbytes - idxval_byte, prev_bytes);
2212 new_bytes = CHAR_STRING (XINT (newelt), p0);
2213 if (prev_bytes != new_bytes)
2215 /* We must relocate the string data. */
2216 int nchars = SCHARS (array);
2217 unsigned char *str;
2218 USE_SAFE_ALLOCA;
2220 SAFE_ALLOCA (str, unsigned char *, nbytes);
2221 bcopy (SDATA (array), str, nbytes);
2222 allocate_string_data (XSTRING (array), nchars,
2223 nbytes + new_bytes - prev_bytes);
2224 bcopy (str, SDATA (array), idxval_byte);
2225 p1 = SDATA (array) + idxval_byte;
2226 bcopy (str + idxval_byte + prev_bytes, p1 + new_bytes,
2227 nbytes - (idxval_byte + prev_bytes));
2228 SAFE_FREE ();
2229 clear_string_char_byte_cache ();
2231 while (new_bytes--)
2232 *p1++ = *p0++;
2234 else
2236 if (idxval < 0 || idxval >= SCHARS (array))
2237 args_out_of_range (array, idx);
2238 CHECK_NUMBER (newelt);
2240 if (XINT (newelt) >= 0 && ! SINGLE_BYTE_CHAR_P (XINT (newelt)))
2242 int i;
2244 for (i = SBYTES (array) - 1; i >= 0; i--)
2245 if (SREF (array, i) >= 0x80)
2246 args_out_of_range (array, newelt);
2247 /* ARRAY is an ASCII string. Convert it to a multibyte
2248 string, and try `aset' again. */
2249 STRING_SET_MULTIBYTE (array);
2250 return Faset (array, idx, newelt);
2252 SSET (array, idxval, XINT (newelt));
2255 return newelt;
2258 /* Arithmetic functions */
2260 enum comparison { equal, notequal, less, grtr, less_or_equal, grtr_or_equal };
2262 Lisp_Object
2263 arithcompare (num1, num2, comparison)
2264 Lisp_Object num1, num2;
2265 enum comparison comparison;
2267 double f1 = 0, f2 = 0;
2268 int floatp = 0;
2270 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1);
2271 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2);
2273 if (FLOATP (num1) || FLOATP (num2))
2275 floatp = 1;
2276 f1 = (FLOATP (num1)) ? XFLOAT_DATA (num1) : XINT (num1);
2277 f2 = (FLOATP (num2)) ? XFLOAT_DATA (num2) : XINT (num2);
2280 switch (comparison)
2282 case equal:
2283 if (floatp ? f1 == f2 : XINT (num1) == XINT (num2))
2284 return Qt;
2285 return Qnil;
2287 case notequal:
2288 if (floatp ? f1 != f2 : XINT (num1) != XINT (num2))
2289 return Qt;
2290 return Qnil;
2292 case less:
2293 if (floatp ? f1 < f2 : XINT (num1) < XINT (num2))
2294 return Qt;
2295 return Qnil;
2297 case less_or_equal:
2298 if (floatp ? f1 <= f2 : XINT (num1) <= XINT (num2))
2299 return Qt;
2300 return Qnil;
2302 case grtr:
2303 if (floatp ? f1 > f2 : XINT (num1) > XINT (num2))
2304 return Qt;
2305 return Qnil;
2307 case grtr_or_equal:
2308 if (floatp ? f1 >= f2 : XINT (num1) >= XINT (num2))
2309 return Qt;
2310 return Qnil;
2312 default:
2313 abort ();
2317 DEFUN ("=", Feqlsign, Seqlsign, 2, 2, 0,
2318 doc: /* Return t if two args, both numbers or markers, are equal. */)
2319 (num1, num2)
2320 register Lisp_Object num1, num2;
2322 return arithcompare (num1, num2, equal);
2325 DEFUN ("<", Flss, Slss, 2, 2, 0,
2326 doc: /* Return t if first arg is less than second arg. Both must be numbers or markers. */)
2327 (num1, num2)
2328 register Lisp_Object num1, num2;
2330 return arithcompare (num1, num2, less);
2333 DEFUN (">", Fgtr, Sgtr, 2, 2, 0,
2334 doc: /* Return t if first arg is greater than second arg. Both must be numbers or markers. */)
2335 (num1, num2)
2336 register Lisp_Object num1, num2;
2338 return arithcompare (num1, num2, grtr);
2341 DEFUN ("<=", Fleq, Sleq, 2, 2, 0,
2342 doc: /* Return t if first arg is less than or equal to second arg.
2343 Both must be numbers or markers. */)
2344 (num1, num2)
2345 register Lisp_Object num1, num2;
2347 return arithcompare (num1, num2, less_or_equal);
2350 DEFUN (">=", Fgeq, Sgeq, 2, 2, 0,
2351 doc: /* Return t if first arg is greater than or equal to second arg.
2352 Both must be numbers or markers. */)
2353 (num1, num2)
2354 register Lisp_Object num1, num2;
2356 return arithcompare (num1, num2, grtr_or_equal);
2359 DEFUN ("/=", Fneq, Sneq, 2, 2, 0,
2360 doc: /* Return t if first arg is not equal to second arg. Both must be numbers or markers. */)
2361 (num1, num2)
2362 register Lisp_Object num1, num2;
2364 return arithcompare (num1, num2, notequal);
2367 DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0,
2368 doc: /* Return t if NUMBER is zero. */)
2369 (number)
2370 register Lisp_Object number;
2372 CHECK_NUMBER_OR_FLOAT (number);
2374 if (FLOATP (number))
2376 if (XFLOAT_DATA (number) == 0.0)
2377 return Qt;
2378 return Qnil;
2381 if (!XINT (number))
2382 return Qt;
2383 return Qnil;
2386 /* Convert between long values and pairs of Lisp integers.
2387 Note that long_to_cons returns a single Lisp integer
2388 when the value fits in one. */
2390 Lisp_Object
2391 long_to_cons (i)
2392 unsigned long i;
2394 unsigned long top = i >> 16;
2395 unsigned int bot = i & 0xFFFF;
2396 if (top == 0)
2397 return make_number (bot);
2398 if (top == (unsigned long)-1 >> 16)
2399 return Fcons (make_number (-1), make_number (bot));
2400 return Fcons (make_number (top), make_number (bot));
2403 unsigned long
2404 cons_to_long (c)
2405 Lisp_Object c;
2407 Lisp_Object top, bot;
2408 if (INTEGERP (c))
2409 return XINT (c);
2410 top = XCAR (c);
2411 bot = XCDR (c);
2412 if (CONSP (bot))
2413 bot = XCAR (bot);
2414 return ((XINT (top) << 16) | XINT (bot));
2417 DEFUN ("number-to-string", Fnumber_to_string, Snumber_to_string, 1, 1, 0,
2418 doc: /* Return the decimal representation of NUMBER as a string.
2419 Uses a minus sign if negative.
2420 NUMBER may be an integer or a floating point number. */)
2421 (number)
2422 Lisp_Object number;
2424 char buffer[VALBITS];
2426 CHECK_NUMBER_OR_FLOAT (number);
2428 if (FLOATP (number))
2430 char pigbuf[350]; /* see comments in float_to_string */
2432 float_to_string (pigbuf, XFLOAT_DATA (number));
2433 return build_string (pigbuf);
2436 if (sizeof (int) == sizeof (EMACS_INT))
2437 sprintf (buffer, "%d", (int) XINT (number));
2438 else if (sizeof (long) == sizeof (EMACS_INT))
2439 sprintf (buffer, "%ld", (long) XINT (number));
2440 else
2441 abort ();
2442 return build_string (buffer);
2445 INLINE static int
2446 digit_to_number (character, base)
2447 int character, base;
2449 int digit;
2451 if (character >= '0' && character <= '9')
2452 digit = character - '0';
2453 else if (character >= 'a' && character <= 'z')
2454 digit = character - 'a' + 10;
2455 else if (character >= 'A' && character <= 'Z')
2456 digit = character - 'A' + 10;
2457 else
2458 return -1;
2460 if (digit >= base)
2461 return -1;
2462 else
2463 return digit;
2466 DEFUN ("string-to-number", Fstring_to_number, Sstring_to_number, 1, 2, 0,
2467 doc: /* Parse STRING as a decimal number and return the number.
2468 This parses both integers and floating point numbers.
2469 It ignores leading spaces and tabs, and all trailing chars.
2471 If BASE, interpret STRING as a number in that base. If BASE isn't
2472 present, base 10 is used. BASE must be between 2 and 16 (inclusive).
2473 If the base used is not 10, STRING is always parsed as integer. */)
2474 (string, base)
2475 register Lisp_Object string, base;
2477 register unsigned char *p;
2478 register int b;
2479 int sign = 1;
2480 Lisp_Object val;
2482 CHECK_STRING (string);
2484 if (NILP (base))
2485 b = 10;
2486 else
2488 CHECK_NUMBER (base);
2489 b = XINT (base);
2490 if (b < 2 || b > 16)
2491 xsignal1 (Qargs_out_of_range, base);
2494 /* Skip any whitespace at the front of the number. Some versions of
2495 atoi do this anyway, so we might as well make Emacs lisp consistent. */
2496 p = SDATA (string);
2497 while (*p == ' ' || *p == '\t')
2498 p++;
2500 if (*p == '-')
2502 sign = -1;
2503 p++;
2505 else if (*p == '+')
2506 p++;
2508 if (isfloat_string (p, 1) && b == 10)
2509 val = make_float (sign * atof (p));
2510 else
2512 double v = 0;
2514 while (1)
2516 int digit = digit_to_number (*p++, b);
2517 if (digit < 0)
2518 break;
2519 v = v * b + digit;
2522 val = make_fixnum_or_float (sign * v);
2525 return val;
2529 enum arithop
2531 Aadd,
2532 Asub,
2533 Amult,
2534 Adiv,
2535 Alogand,
2536 Alogior,
2537 Alogxor,
2538 Amax,
2539 Amin
2542 static Lisp_Object float_arith_driver P_ ((double, int, enum arithop,
2543 int, Lisp_Object *));
2544 extern Lisp_Object fmod_float ();
2546 Lisp_Object
2547 arith_driver (code, nargs, args)
2548 enum arithop code;
2549 int nargs;
2550 register Lisp_Object *args;
2552 register Lisp_Object val;
2553 register int argnum;
2554 register EMACS_INT accum = 0;
2555 register EMACS_INT next;
2557 switch (SWITCH_ENUM_CAST (code))
2559 case Alogior:
2560 case Alogxor:
2561 case Aadd:
2562 case Asub:
2563 accum = 0;
2564 break;
2565 case Amult:
2566 accum = 1;
2567 break;
2568 case Alogand:
2569 accum = -1;
2570 break;
2571 default:
2572 break;
2575 for (argnum = 0; argnum < nargs; argnum++)
2577 /* Using args[argnum] as argument to CHECK_NUMBER_... */
2578 val = args[argnum];
2579 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val);
2581 if (FLOATP (val))
2582 return float_arith_driver ((double) accum, argnum, code,
2583 nargs, args);
2584 args[argnum] = val;
2585 next = XINT (args[argnum]);
2586 switch (SWITCH_ENUM_CAST (code))
2588 case Aadd:
2589 accum += next;
2590 break;
2591 case Asub:
2592 accum = argnum ? accum - next : nargs == 1 ? - next : next;
2593 break;
2594 case Amult:
2595 accum *= next;
2596 break;
2597 case Adiv:
2598 if (!argnum)
2599 accum = next;
2600 else
2602 if (next == 0)
2603 xsignal0 (Qarith_error);
2604 accum /= next;
2606 break;
2607 case Alogand:
2608 accum &= next;
2609 break;
2610 case Alogior:
2611 accum |= next;
2612 break;
2613 case Alogxor:
2614 accum ^= next;
2615 break;
2616 case Amax:
2617 if (!argnum || next > accum)
2618 accum = next;
2619 break;
2620 case Amin:
2621 if (!argnum || next < accum)
2622 accum = next;
2623 break;
2627 XSETINT (val, accum);
2628 return val;
2631 #undef isnan
2632 #define isnan(x) ((x) != (x))
2634 static Lisp_Object
2635 float_arith_driver (accum, argnum, code, nargs, args)
2636 double accum;
2637 register int argnum;
2638 enum arithop code;
2639 int nargs;
2640 register Lisp_Object *args;
2642 register Lisp_Object val;
2643 double next;
2645 for (; argnum < nargs; argnum++)
2647 val = args[argnum]; /* using args[argnum] as argument to CHECK_NUMBER_... */
2648 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val);
2650 if (FLOATP (val))
2652 next = XFLOAT_DATA (val);
2654 else
2656 args[argnum] = val; /* runs into a compiler bug. */
2657 next = XINT (args[argnum]);
2659 switch (SWITCH_ENUM_CAST (code))
2661 case Aadd:
2662 accum += next;
2663 break;
2664 case Asub:
2665 accum = argnum ? accum - next : nargs == 1 ? - next : next;
2666 break;
2667 case Amult:
2668 accum *= next;
2669 break;
2670 case Adiv:
2671 if (!argnum)
2672 accum = next;
2673 else
2675 if (! IEEE_FLOATING_POINT && next == 0)
2676 xsignal0 (Qarith_error);
2677 accum /= next;
2679 break;
2680 case Alogand:
2681 case Alogior:
2682 case Alogxor:
2683 return wrong_type_argument (Qinteger_or_marker_p, val);
2684 case Amax:
2685 if (!argnum || isnan (next) || next > accum)
2686 accum = next;
2687 break;
2688 case Amin:
2689 if (!argnum || isnan (next) || next < accum)
2690 accum = next;
2691 break;
2695 return make_float (accum);
2699 DEFUN ("+", Fplus, Splus, 0, MANY, 0,
2700 doc: /* Return sum of any number of arguments, which are numbers or markers.
2701 usage: (+ &rest NUMBERS-OR-MARKERS) */)
2702 (nargs, args)
2703 int nargs;
2704 Lisp_Object *args;
2706 return arith_driver (Aadd, nargs, args);
2709 DEFUN ("-", Fminus, Sminus, 0, MANY, 0,
2710 doc: /* Negate number or subtract numbers or markers and return the result.
2711 With one arg, negates it. With more than one arg,
2712 subtracts all but the first from the first.
2713 usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */)
2714 (nargs, args)
2715 int nargs;
2716 Lisp_Object *args;
2718 return arith_driver (Asub, nargs, args);
2721 DEFUN ("*", Ftimes, Stimes, 0, MANY, 0,
2722 doc: /* Return product of any number of arguments, which are numbers or markers.
2723 usage: (* &rest NUMBERS-OR-MARKERS) */)
2724 (nargs, args)
2725 int nargs;
2726 Lisp_Object *args;
2728 return arith_driver (Amult, nargs, args);
2731 DEFUN ("/", Fquo, Squo, 2, MANY, 0,
2732 doc: /* Return first argument divided by all the remaining arguments.
2733 The arguments must be numbers or markers.
2734 usage: (/ DIVIDEND DIVISOR &rest DIVISORS) */)
2735 (nargs, args)
2736 int nargs;
2737 Lisp_Object *args;
2739 int argnum;
2740 for (argnum = 2; argnum < nargs; argnum++)
2741 if (FLOATP (args[argnum]))
2742 return float_arith_driver (0, 0, Adiv, nargs, args);
2743 return arith_driver (Adiv, nargs, args);
2746 DEFUN ("%", Frem, Srem, 2, 2, 0,
2747 doc: /* Return remainder of X divided by Y.
2748 Both must be integers or markers. */)
2749 (x, y)
2750 register Lisp_Object x, y;
2752 Lisp_Object val;
2754 CHECK_NUMBER_COERCE_MARKER (x);
2755 CHECK_NUMBER_COERCE_MARKER (y);
2757 if (XFASTINT (y) == 0)
2758 xsignal0 (Qarith_error);
2760 XSETINT (val, XINT (x) % XINT (y));
2761 return val;
2764 #ifndef HAVE_FMOD
2765 double
2766 fmod (f1, f2)
2767 double f1, f2;
2769 double r = f1;
2771 if (f2 < 0.0)
2772 f2 = -f2;
2774 /* If the magnitude of the result exceeds that of the divisor, or
2775 the sign of the result does not agree with that of the dividend,
2776 iterate with the reduced value. This does not yield a
2777 particularly accurate result, but at least it will be in the
2778 range promised by fmod. */
2780 r -= f2 * floor (r / f2);
2781 while (f2 <= (r < 0 ? -r : r) || ((r < 0) != (f1 < 0) && ! isnan (r)));
2783 return r;
2785 #endif /* ! HAVE_FMOD */
2787 DEFUN ("mod", Fmod, Smod, 2, 2, 0,
2788 doc: /* Return X modulo Y.
2789 The result falls between zero (inclusive) and Y (exclusive).
2790 Both X and Y must be numbers or markers. */)
2791 (x, y)
2792 register Lisp_Object x, y;
2794 Lisp_Object val;
2795 EMACS_INT i1, i2;
2797 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x);
2798 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y);
2800 if (FLOATP (x) || FLOATP (y))
2801 return fmod_float (x, y);
2803 i1 = XINT (x);
2804 i2 = XINT (y);
2806 if (i2 == 0)
2807 xsignal0 (Qarith_error);
2809 i1 %= i2;
2811 /* If the "remainder" comes out with the wrong sign, fix it. */
2812 if (i2 < 0 ? i1 > 0 : i1 < 0)
2813 i1 += i2;
2815 XSETINT (val, i1);
2816 return val;
2819 DEFUN ("max", Fmax, Smax, 1, MANY, 0,
2820 doc: /* Return largest of all the arguments (which must be numbers or markers).
2821 The value is always a number; markers are converted to numbers.
2822 usage: (max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2823 (nargs, args)
2824 int nargs;
2825 Lisp_Object *args;
2827 return arith_driver (Amax, nargs, args);
2830 DEFUN ("min", Fmin, Smin, 1, MANY, 0,
2831 doc: /* Return smallest of all the arguments (which must be numbers or markers).
2832 The value is always a number; markers are converted to numbers.
2833 usage: (min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2834 (nargs, args)
2835 int nargs;
2836 Lisp_Object *args;
2838 return arith_driver (Amin, nargs, args);
2841 DEFUN ("logand", Flogand, Slogand, 0, MANY, 0,
2842 doc: /* Return bitwise-and of all the arguments.
2843 Arguments may be integers, or markers converted to integers.
2844 usage: (logand &rest INTS-OR-MARKERS) */)
2845 (nargs, args)
2846 int nargs;
2847 Lisp_Object *args;
2849 return arith_driver (Alogand, nargs, args);
2852 DEFUN ("logior", Flogior, Slogior, 0, MANY, 0,
2853 doc: /* Return bitwise-or of all the arguments.
2854 Arguments may be integers, or markers converted to integers.
2855 usage: (logior &rest INTS-OR-MARKERS) */)
2856 (nargs, args)
2857 int nargs;
2858 Lisp_Object *args;
2860 return arith_driver (Alogior, nargs, args);
2863 DEFUN ("logxor", Flogxor, Slogxor, 0, MANY, 0,
2864 doc: /* Return bitwise-exclusive-or of all the arguments.
2865 Arguments may be integers, or markers converted to integers.
2866 usage: (logxor &rest INTS-OR-MARKERS) */)
2867 (nargs, args)
2868 int nargs;
2869 Lisp_Object *args;
2871 return arith_driver (Alogxor, nargs, args);
2874 DEFUN ("ash", Fash, Sash, 2, 2, 0,
2875 doc: /* Return VALUE with its bits shifted left by COUNT.
2876 If COUNT is negative, shifting is actually to the right.
2877 In this case, the sign bit is duplicated. */)
2878 (value, count)
2879 register Lisp_Object value, count;
2881 register Lisp_Object val;
2883 CHECK_NUMBER (value);
2884 CHECK_NUMBER (count);
2886 if (XINT (count) >= BITS_PER_EMACS_INT)
2887 XSETINT (val, 0);
2888 else if (XINT (count) > 0)
2889 XSETINT (val, XINT (value) << XFASTINT (count));
2890 else if (XINT (count) <= -BITS_PER_EMACS_INT)
2891 XSETINT (val, XINT (value) < 0 ? -1 : 0);
2892 else
2893 XSETINT (val, XINT (value) >> -XINT (count));
2894 return val;
2897 DEFUN ("lsh", Flsh, Slsh, 2, 2, 0,
2898 doc: /* Return VALUE with its bits shifted left by COUNT.
2899 If COUNT is negative, shifting is actually to the right.
2900 In this case, zeros are shifted in on the left. */)
2901 (value, count)
2902 register Lisp_Object value, count;
2904 register Lisp_Object val;
2906 CHECK_NUMBER (value);
2907 CHECK_NUMBER (count);
2909 if (XINT (count) >= BITS_PER_EMACS_INT)
2910 XSETINT (val, 0);
2911 else if (XINT (count) > 0)
2912 XSETINT (val, (EMACS_UINT) XUINT (value) << XFASTINT (count));
2913 else if (XINT (count) <= -BITS_PER_EMACS_INT)
2914 XSETINT (val, 0);
2915 else
2916 XSETINT (val, (EMACS_UINT) XUINT (value) >> -XINT (count));
2917 return val;
2920 DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0,
2921 doc: /* Return NUMBER plus one. NUMBER may be a number or a marker.
2922 Markers are converted to integers. */)
2923 (number)
2924 register Lisp_Object number;
2926 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number);
2928 if (FLOATP (number))
2929 return (make_float (1.0 + XFLOAT_DATA (number)));
2931 XSETINT (number, XINT (number) + 1);
2932 return number;
2935 DEFUN ("1-", Fsub1, Ssub1, 1, 1, 0,
2936 doc: /* Return NUMBER minus one. NUMBER may be a number or a marker.
2937 Markers are converted to integers. */)
2938 (number)
2939 register Lisp_Object number;
2941 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number);
2943 if (FLOATP (number))
2944 return (make_float (-1.0 + XFLOAT_DATA (number)));
2946 XSETINT (number, XINT (number) - 1);
2947 return number;
2950 DEFUN ("lognot", Flognot, Slognot, 1, 1, 0,
2951 doc: /* Return the bitwise complement of NUMBER. NUMBER must be an integer. */)
2952 (number)
2953 register Lisp_Object number;
2955 CHECK_NUMBER (number);
2956 XSETINT (number, ~XINT (number));
2957 return number;
2960 DEFUN ("byteorder", Fbyteorder, Sbyteorder, 0, 0, 0,
2961 doc: /* Return the byteorder for the machine.
2962 Returns 66 (ASCII uppercase B) for big endian machines or 108 (ASCII
2963 lowercase l) for small endian machines. */)
2966 unsigned i = 0x04030201;
2967 int order = *(char *)&i == 1 ? 108 : 66;
2969 return make_number (order);
2974 void
2975 syms_of_data ()
2977 Lisp_Object error_tail, arith_tail;
2979 Qquote = intern_c_string ("quote");
2980 Qlambda = intern_c_string ("lambda");
2981 Qsubr = intern_c_string ("subr");
2982 Qerror_conditions = intern_c_string ("error-conditions");
2983 Qerror_message = intern_c_string ("error-message");
2984 Qtop_level = intern_c_string ("top-level");
2986 Qerror = intern_c_string ("error");
2987 Qquit = intern_c_string ("quit");
2988 Qwrong_type_argument = intern_c_string ("wrong-type-argument");
2989 Qargs_out_of_range = intern_c_string ("args-out-of-range");
2990 Qvoid_function = intern_c_string ("void-function");
2991 Qcyclic_function_indirection = intern_c_string ("cyclic-function-indirection");
2992 Qcyclic_variable_indirection = intern_c_string ("cyclic-variable-indirection");
2993 Qvoid_variable = intern_c_string ("void-variable");
2994 Qsetting_constant = intern_c_string ("setting-constant");
2995 Qinvalid_read_syntax = intern_c_string ("invalid-read-syntax");
2997 Qinvalid_function = intern_c_string ("invalid-function");
2998 Qwrong_number_of_arguments = intern_c_string ("wrong-number-of-arguments");
2999 Qno_catch = intern_c_string ("no-catch");
3000 Qend_of_file = intern_c_string ("end-of-file");
3001 Qarith_error = intern_c_string ("arith-error");
3002 Qbeginning_of_buffer = intern_c_string ("beginning-of-buffer");
3003 Qend_of_buffer = intern_c_string ("end-of-buffer");
3004 Qbuffer_read_only = intern_c_string ("buffer-read-only");
3005 Qtext_read_only = intern_c_string ("text-read-only");
3006 Qmark_inactive = intern_c_string ("mark-inactive");
3008 Qlistp = intern_c_string ("listp");
3009 Qconsp = intern_c_string ("consp");
3010 Qsymbolp = intern_c_string ("symbolp");
3011 Qkeywordp = intern_c_string ("keywordp");
3012 Qintegerp = intern_c_string ("integerp");
3013 Qnatnump = intern_c_string ("natnump");
3014 Qwholenump = intern_c_string ("wholenump");
3015 Qstringp = intern_c_string ("stringp");
3016 Qarrayp = intern_c_string ("arrayp");
3017 Qsequencep = intern_c_string ("sequencep");
3018 Qbufferp = intern_c_string ("bufferp");
3019 Qvectorp = intern_c_string ("vectorp");
3020 Qchar_or_string_p = intern_c_string ("char-or-string-p");
3021 Qmarkerp = intern_c_string ("markerp");
3022 Qbuffer_or_string_p = intern_c_string ("buffer-or-string-p");
3023 Qinteger_or_marker_p = intern_c_string ("integer-or-marker-p");
3024 Qboundp = intern_c_string ("boundp");
3025 Qfboundp = intern_c_string ("fboundp");
3027 Qfloatp = intern_c_string ("floatp");
3028 Qnumberp = intern_c_string ("numberp");
3029 Qnumber_or_marker_p = intern_c_string ("number-or-marker-p");
3031 Qchar_table_p = intern_c_string ("char-table-p");
3032 Qvector_or_char_table_p = intern_c_string ("vector-or-char-table-p");
3034 Qsubrp = intern_c_string ("subrp");
3035 Qunevalled = intern_c_string ("unevalled");
3036 Qmany = intern_c_string ("many");
3038 Qcdr = intern_c_string ("cdr");
3040 /* Handle automatic advice activation */
3041 Qad_advice_info = intern_c_string ("ad-advice-info");
3042 Qad_activate_internal = intern_c_string ("ad-activate-internal");
3044 error_tail = pure_cons (Qerror, Qnil);
3046 /* ERROR is used as a signaler for random errors for which nothing else is right */
3048 Fput (Qerror, Qerror_conditions,
3049 error_tail);
3050 Fput (Qerror, Qerror_message,
3051 make_pure_c_string ("error"));
3053 Fput (Qquit, Qerror_conditions,
3054 pure_cons (Qquit, Qnil));
3055 Fput (Qquit, Qerror_message,
3056 make_pure_c_string ("Quit"));
3058 Fput (Qwrong_type_argument, Qerror_conditions,
3059 pure_cons (Qwrong_type_argument, error_tail));
3060 Fput (Qwrong_type_argument, Qerror_message,
3061 make_pure_c_string ("Wrong type argument"));
3063 Fput (Qargs_out_of_range, Qerror_conditions,
3064 pure_cons (Qargs_out_of_range, error_tail));
3065 Fput (Qargs_out_of_range, Qerror_message,
3066 make_pure_c_string ("Args out of range"));
3068 Fput (Qvoid_function, Qerror_conditions,
3069 pure_cons (Qvoid_function, error_tail));
3070 Fput (Qvoid_function, Qerror_message,
3071 make_pure_c_string ("Symbol's function definition is void"));
3073 Fput (Qcyclic_function_indirection, Qerror_conditions,
3074 pure_cons (Qcyclic_function_indirection, error_tail));
3075 Fput (Qcyclic_function_indirection, Qerror_message,
3076 make_pure_c_string ("Symbol's chain of function indirections contains a loop"));
3078 Fput (Qcyclic_variable_indirection, Qerror_conditions,
3079 pure_cons (Qcyclic_variable_indirection, error_tail));
3080 Fput (Qcyclic_variable_indirection, Qerror_message,
3081 make_pure_c_string ("Symbol's chain of variable indirections contains a loop"));
3083 Qcircular_list = intern_c_string ("circular-list");
3084 staticpro (&Qcircular_list);
3085 Fput (Qcircular_list, Qerror_conditions,
3086 pure_cons (Qcircular_list, error_tail));
3087 Fput (Qcircular_list, Qerror_message,
3088 make_pure_c_string ("List contains a loop"));
3090 Fput (Qvoid_variable, Qerror_conditions,
3091 pure_cons (Qvoid_variable, error_tail));
3092 Fput (Qvoid_variable, Qerror_message,
3093 make_pure_c_string ("Symbol's value as variable is void"));
3095 Fput (Qsetting_constant, Qerror_conditions,
3096 pure_cons (Qsetting_constant, error_tail));
3097 Fput (Qsetting_constant, Qerror_message,
3098 make_pure_c_string ("Attempt to set a constant symbol"));
3100 Fput (Qinvalid_read_syntax, Qerror_conditions,
3101 pure_cons (Qinvalid_read_syntax, error_tail));
3102 Fput (Qinvalid_read_syntax, Qerror_message,
3103 make_pure_c_string ("Invalid read syntax"));
3105 Fput (Qinvalid_function, Qerror_conditions,
3106 pure_cons (Qinvalid_function, error_tail));
3107 Fput (Qinvalid_function, Qerror_message,
3108 make_pure_c_string ("Invalid function"));
3110 Fput (Qwrong_number_of_arguments, Qerror_conditions,
3111 pure_cons (Qwrong_number_of_arguments, error_tail));
3112 Fput (Qwrong_number_of_arguments, Qerror_message,
3113 make_pure_c_string ("Wrong number of arguments"));
3115 Fput (Qno_catch, Qerror_conditions,
3116 pure_cons (Qno_catch, error_tail));
3117 Fput (Qno_catch, Qerror_message,
3118 make_pure_c_string ("No catch for tag"));
3120 Fput (Qend_of_file, Qerror_conditions,
3121 pure_cons (Qend_of_file, error_tail));
3122 Fput (Qend_of_file, Qerror_message,
3123 make_pure_c_string ("End of file during parsing"));
3125 arith_tail = pure_cons (Qarith_error, error_tail);
3126 Fput (Qarith_error, Qerror_conditions,
3127 arith_tail);
3128 Fput (Qarith_error, Qerror_message,
3129 make_pure_c_string ("Arithmetic error"));
3131 Fput (Qbeginning_of_buffer, Qerror_conditions,
3132 pure_cons (Qbeginning_of_buffer, error_tail));
3133 Fput (Qbeginning_of_buffer, Qerror_message,
3134 make_pure_c_string ("Beginning of buffer"));
3136 Fput (Qend_of_buffer, Qerror_conditions,
3137 pure_cons (Qend_of_buffer, error_tail));
3138 Fput (Qend_of_buffer, Qerror_message,
3139 make_pure_c_string ("End of buffer"));
3141 Fput (Qbuffer_read_only, Qerror_conditions,
3142 pure_cons (Qbuffer_read_only, error_tail));
3143 Fput (Qbuffer_read_only, Qerror_message,
3144 make_pure_c_string ("Buffer is read-only"));
3146 Fput (Qtext_read_only, Qerror_conditions,
3147 pure_cons (Qtext_read_only, error_tail));
3148 Fput (Qtext_read_only, Qerror_message,
3149 make_pure_c_string ("Text is read-only"));
3151 Qrange_error = intern_c_string ("range-error");
3152 Qdomain_error = intern_c_string ("domain-error");
3153 Qsingularity_error = intern_c_string ("singularity-error");
3154 Qoverflow_error = intern_c_string ("overflow-error");
3155 Qunderflow_error = intern_c_string ("underflow-error");
3157 Fput (Qdomain_error, Qerror_conditions,
3158 pure_cons (Qdomain_error, arith_tail));
3159 Fput (Qdomain_error, Qerror_message,
3160 make_pure_c_string ("Arithmetic domain error"));
3162 Fput (Qrange_error, Qerror_conditions,
3163 pure_cons (Qrange_error, arith_tail));
3164 Fput (Qrange_error, Qerror_message,
3165 make_pure_c_string ("Arithmetic range error"));
3167 Fput (Qsingularity_error, Qerror_conditions,
3168 pure_cons (Qsingularity_error, Fcons (Qdomain_error, arith_tail)));
3169 Fput (Qsingularity_error, Qerror_message,
3170 make_pure_c_string ("Arithmetic singularity error"));
3172 Fput (Qoverflow_error, Qerror_conditions,
3173 pure_cons (Qoverflow_error, Fcons (Qdomain_error, arith_tail)));
3174 Fput (Qoverflow_error, Qerror_message,
3175 make_pure_c_string ("Arithmetic overflow error"));
3177 Fput (Qunderflow_error, Qerror_conditions,
3178 pure_cons (Qunderflow_error, Fcons (Qdomain_error, arith_tail)));
3179 Fput (Qunderflow_error, Qerror_message,
3180 make_pure_c_string ("Arithmetic underflow error"));
3182 staticpro (&Qrange_error);
3183 staticpro (&Qdomain_error);
3184 staticpro (&Qsingularity_error);
3185 staticpro (&Qoverflow_error);
3186 staticpro (&Qunderflow_error);
3188 staticpro (&Qnil);
3189 staticpro (&Qt);
3190 staticpro (&Qquote);
3191 staticpro (&Qlambda);
3192 staticpro (&Qsubr);
3193 staticpro (&Qunbound);
3194 staticpro (&Qerror_conditions);
3195 staticpro (&Qerror_message);
3196 staticpro (&Qtop_level);
3198 staticpro (&Qerror);
3199 staticpro (&Qquit);
3200 staticpro (&Qwrong_type_argument);
3201 staticpro (&Qargs_out_of_range);
3202 staticpro (&Qvoid_function);
3203 staticpro (&Qcyclic_function_indirection);
3204 staticpro (&Qcyclic_variable_indirection);
3205 staticpro (&Qvoid_variable);
3206 staticpro (&Qsetting_constant);
3207 staticpro (&Qinvalid_read_syntax);
3208 staticpro (&Qwrong_number_of_arguments);
3209 staticpro (&Qinvalid_function);
3210 staticpro (&Qno_catch);
3211 staticpro (&Qend_of_file);
3212 staticpro (&Qarith_error);
3213 staticpro (&Qbeginning_of_buffer);
3214 staticpro (&Qend_of_buffer);
3215 staticpro (&Qbuffer_read_only);
3216 staticpro (&Qtext_read_only);
3217 staticpro (&Qmark_inactive);
3219 staticpro (&Qlistp);
3220 staticpro (&Qconsp);
3221 staticpro (&Qsymbolp);
3222 staticpro (&Qkeywordp);
3223 staticpro (&Qintegerp);
3224 staticpro (&Qnatnump);
3225 staticpro (&Qwholenump);
3226 staticpro (&Qstringp);
3227 staticpro (&Qarrayp);
3228 staticpro (&Qsequencep);
3229 staticpro (&Qbufferp);
3230 staticpro (&Qvectorp);
3231 staticpro (&Qchar_or_string_p);
3232 staticpro (&Qmarkerp);
3233 staticpro (&Qbuffer_or_string_p);
3234 staticpro (&Qinteger_or_marker_p);
3235 staticpro (&Qfloatp);
3236 staticpro (&Qnumberp);
3237 staticpro (&Qnumber_or_marker_p);
3238 staticpro (&Qchar_table_p);
3239 staticpro (&Qvector_or_char_table_p);
3240 staticpro (&Qsubrp);
3241 staticpro (&Qmany);
3242 staticpro (&Qunevalled);
3244 staticpro (&Qboundp);
3245 staticpro (&Qfboundp);
3246 staticpro (&Qcdr);
3247 staticpro (&Qad_advice_info);
3248 staticpro (&Qad_activate_internal);
3250 /* Types that type-of returns. */
3251 Qinteger = intern_c_string ("integer");
3252 Qsymbol = intern_c_string ("symbol");
3253 Qstring = intern_c_string ("string");
3254 Qcons = intern_c_string ("cons");
3255 Qmarker = intern_c_string ("marker");
3256 Qoverlay = intern_c_string ("overlay");
3257 Qfloat = intern_c_string ("float");
3258 Qwindow_configuration = intern_c_string ("window-configuration");
3259 Qprocess = intern_c_string ("process");
3260 Qwindow = intern_c_string ("window");
3261 /* Qsubr = intern_c_string ("subr"); */
3262 Qcompiled_function = intern_c_string ("compiled-function");
3263 Qbuffer = intern_c_string ("buffer");
3264 Qframe = intern_c_string ("frame");
3265 Qvector = intern_c_string ("vector");
3266 Qchar_table = intern_c_string ("char-table");
3267 Qbool_vector = intern_c_string ("bool-vector");
3268 Qhash_table = intern_c_string ("hash-table");
3270 Qthread_local_mark = Fmake_symbol (make_pure_string ("thread-local-mark",
3271 17, 17, 0));
3273 DEFSYM (Qfont_spec, "font-spec");
3274 DEFSYM (Qfont_entity, "font-entity");
3275 DEFSYM (Qfont_object, "font-object");
3277 DEFSYM (Qinteractive_form, "interactive-form");
3279 staticpro (&Qinteger);
3280 staticpro (&Qsymbol);
3281 staticpro (&Qstring);
3282 staticpro (&Qcons);
3283 staticpro (&Qmarker);
3284 staticpro (&Qoverlay);
3285 staticpro (&Qfloat);
3286 staticpro (&Qwindow_configuration);
3287 staticpro (&Qprocess);
3288 staticpro (&Qwindow);
3289 /* staticpro (&Qsubr); */
3290 staticpro (&Qcompiled_function);
3291 staticpro (&Qbuffer);
3292 staticpro (&Qframe);
3293 staticpro (&Qvector);
3294 staticpro (&Qchar_table);
3295 staticpro (&Qbool_vector);
3296 staticpro (&Qhash_table);
3297 staticpro (&Qthread_local_mark);
3299 defsubr (&Sindirect_variable);
3300 defsubr (&Sinteractive_form);
3301 defsubr (&Seq);
3302 defsubr (&Snull);
3303 defsubr (&Stype_of);
3304 defsubr (&Slistp);
3305 defsubr (&Snlistp);
3306 defsubr (&Sconsp);
3307 defsubr (&Satom);
3308 defsubr (&Sintegerp);
3309 defsubr (&Sinteger_or_marker_p);
3310 defsubr (&Snumberp);
3311 defsubr (&Snumber_or_marker_p);
3312 defsubr (&Sfloatp);
3313 defsubr (&Snatnump);
3314 defsubr (&Ssymbolp);
3315 defsubr (&Skeywordp);
3316 defsubr (&Sstringp);
3317 defsubr (&Smultibyte_string_p);
3318 defsubr (&Svectorp);
3319 defsubr (&Schar_table_p);
3320 defsubr (&Svector_or_char_table_p);
3321 defsubr (&Sbool_vector_p);
3322 defsubr (&Sarrayp);
3323 defsubr (&Ssequencep);
3324 defsubr (&Sbufferp);
3325 defsubr (&Smarkerp);
3326 defsubr (&Ssubrp);
3327 defsubr (&Sbyte_code_function_p);
3328 defsubr (&Schar_or_string_p);
3329 defsubr (&Scar);
3330 defsubr (&Scdr);
3331 defsubr (&Scar_safe);
3332 defsubr (&Scdr_safe);
3333 defsubr (&Ssetcar);
3334 defsubr (&Ssetcdr);
3335 defsubr (&Ssymbol_function);
3336 defsubr (&Sindirect_function);
3337 defsubr (&Ssymbol_plist);
3338 defsubr (&Ssymbol_name);
3339 defsubr (&Smakunbound);
3340 defsubr (&Sfmakunbound);
3341 defsubr (&Sboundp);
3342 defsubr (&Sfboundp);
3343 defsubr (&Sfset);
3344 defsubr (&Sdefalias);
3345 defsubr (&Ssetplist);
3346 defsubr (&Ssymbol_value);
3347 defsubr (&Sset);
3348 defsubr (&Sdefault_boundp);
3349 defsubr (&Sdefault_value);
3350 defsubr (&Sset_default);
3351 defsubr (&Ssetq_default);
3352 defsubr (&Smake_variable_buffer_local);
3353 defsubr (&Smake_local_variable);
3354 defsubr (&Skill_local_variable);
3355 defsubr (&Smake_variable_frame_local);
3356 defsubr (&Slocal_variable_p);
3357 defsubr (&Slocal_variable_if_set_p);
3358 defsubr (&Svariable_binding_locus);
3359 #if 0 /* XXX Remove this. --lorentey */
3360 defsubr (&Sterminal_local_value);
3361 defsubr (&Sset_terminal_local_value);
3362 #endif
3363 defsubr (&Saref);
3364 defsubr (&Saset);
3365 defsubr (&Snumber_to_string);
3366 defsubr (&Sstring_to_number);
3367 defsubr (&Seqlsign);
3368 defsubr (&Slss);
3369 defsubr (&Sgtr);
3370 defsubr (&Sleq);
3371 defsubr (&Sgeq);
3372 defsubr (&Sneq);
3373 defsubr (&Szerop);
3374 defsubr (&Splus);
3375 defsubr (&Sminus);
3376 defsubr (&Stimes);
3377 defsubr (&Squo);
3378 defsubr (&Srem);
3379 defsubr (&Smod);
3380 defsubr (&Smax);
3381 defsubr (&Smin);
3382 defsubr (&Slogand);
3383 defsubr (&Slogior);
3384 defsubr (&Slogxor);
3385 defsubr (&Slsh);
3386 defsubr (&Sash);
3387 defsubr (&Sadd1);
3388 defsubr (&Ssub1);
3389 defsubr (&Slognot);
3390 defsubr (&Sbyteorder);
3391 defsubr (&Ssubr_arity);
3392 defsubr (&Ssubr_name);
3394 XSYMBOL (Qwholenump)->function = XSYMBOL (Qnatnump)->function;
3396 DEFVAR_LISP ("most-positive-fixnum", &Vmost_positive_fixnum,
3397 doc: /* The largest value that is representable in a Lisp integer. */);
3398 Vmost_positive_fixnum = make_number (MOST_POSITIVE_FIXNUM);
3399 XSYMBOL (intern_c_string ("most-positive-fixnum"))->constant = 1;
3401 DEFVAR_LISP ("most-negative-fixnum", &Vmost_negative_fixnum,
3402 doc: /* The smallest value that is representable in a Lisp integer. */);
3403 Vmost_negative_fixnum = make_number (MOST_NEGATIVE_FIXNUM);
3404 XSYMBOL (intern_c_string ("most-negative-fixnum"))->constant = 1;
3407 SIGTYPE
3408 arith_error (signo)
3409 int signo;
3411 sigsetmask (SIGEMPTYMASK);
3413 SIGNAL_THREAD_CHECK (signo);
3414 xsignal0 (Qarith_error);
3417 void
3418 init_data ()
3420 /* Don't do this if just dumping out.
3421 We don't want to call `signal' in this case
3422 so that we don't have trouble with dumping
3423 signal-delivering routines in an inconsistent state. */
3424 #ifndef CANNOT_DUMP
3425 if (!initialized)
3426 return;
3427 #endif /* CANNOT_DUMP */
3428 signal (SIGFPE, arith_error);
3430 #ifdef uts
3431 signal (SIGEMT, arith_error);
3432 #endif /* uts */
3435 /* arch-tag: 25879798-b84d-479a-9c89-7d148e2109f7
3436 (do not change this comment) */