1 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985,86,88,93,94,95,97,98,99, 2000, 2001
3 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
32 #include "syssignal.h"
38 /* If IEEE_FLOATING_POINT isn't defined, default it from FLT_*. */
39 #ifndef IEEE_FLOATING_POINT
40 #if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \
41 && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128)
42 #define IEEE_FLOATING_POINT 1
44 #define IEEE_FLOATING_POINT 0
48 /* Work around a problem that happens because math.h on hpux 7
49 defines two static variables--which, in Emacs, are not really static,
50 because `static' is defined as nothing. The problem is that they are
51 here, in floatfns.c, and in lread.c.
52 These macros prevent the name conflict. */
53 #if defined (HPUX) && !defined (HPUX8)
54 #define _MAXLDBL data_c_maxldbl
55 #define _NMAXLDBL data_c_nmaxldbl
61 extern double atof ();
64 Lisp_Object Qnil
, Qt
, Qquote
, Qlambda
, Qsubr
, Qunbound
;
65 Lisp_Object Qerror_conditions
, Qerror_message
, Qtop_level
;
66 Lisp_Object Qerror
, Qquit
, Qwrong_type_argument
, Qargs_out_of_range
;
67 Lisp_Object Qvoid_variable
, Qvoid_function
, Qcyclic_function_indirection
;
68 Lisp_Object Qsetting_constant
, Qinvalid_read_syntax
;
69 Lisp_Object Qinvalid_function
, Qwrong_number_of_arguments
, Qno_catch
;
70 Lisp_Object Qend_of_file
, Qarith_error
, Qmark_inactive
;
71 Lisp_Object Qbeginning_of_buffer
, Qend_of_buffer
, Qbuffer_read_only
;
72 Lisp_Object Qtext_read_only
;
73 Lisp_Object Qintegerp
, Qnatnump
, Qwholenump
, Qsymbolp
, Qlistp
, Qconsp
;
74 Lisp_Object Qstringp
, Qarrayp
, Qsequencep
, Qbufferp
;
75 Lisp_Object Qchar_or_string_p
, Qmarkerp
, Qinteger_or_marker_p
, Qvectorp
;
76 Lisp_Object Qbuffer_or_string_p
, Qkeywordp
;
77 Lisp_Object Qboundp
, Qfboundp
;
78 Lisp_Object Qchar_table_p
, Qvector_or_char_table_p
;
81 Lisp_Object Qad_advice_info
, Qad_activate_internal
;
83 Lisp_Object Qrange_error
, Qdomain_error
, Qsingularity_error
;
84 Lisp_Object Qoverflow_error
, Qunderflow_error
;
87 Lisp_Object Qnumberp
, Qnumber_or_marker_p
;
89 static Lisp_Object Qinteger
, Qsymbol
, Qstring
, Qcons
, Qmarker
, Qoverlay
;
90 static Lisp_Object Qfloat
, Qwindow_configuration
, Qwindow
;
92 static Lisp_Object Qcompiled_function
, Qbuffer
, Qframe
, Qvector
;
93 static Lisp_Object Qchar_table
, Qbool_vector
, Qhash_table
;
94 static Lisp_Object Qsubrp
, Qmany
, Qunevalled
;
96 static Lisp_Object swap_in_symval_forwarding
P_ ((Lisp_Object
, Lisp_Object
));
99 wrong_type_argument (predicate
, value
)
100 register Lisp_Object predicate
, value
;
102 register Lisp_Object tem
;
105 if (!EQ (Vmocklisp_arguments
, Qt
))
107 if (STRINGP (value
) &&
108 (EQ (predicate
, Qintegerp
) || EQ (predicate
, Qinteger_or_marker_p
)))
109 return Fstring_to_number (value
, Qnil
);
110 if (INTEGERP (value
) && EQ (predicate
, Qstringp
))
111 return Fnumber_to_string (value
);
114 /* If VALUE is not even a valid Lisp object, abort here
115 where we can get a backtrace showing where it came from. */
116 if ((unsigned int) XGCTYPE (value
) >= Lisp_Type_Limit
)
119 value
= Fsignal (Qwrong_type_argument
, Fcons (predicate
, Fcons (value
, Qnil
)));
120 tem
= call1 (predicate
, value
);
129 error ("Attempt to modify read-only object");
133 args_out_of_range (a1
, a2
)
137 Fsignal (Qargs_out_of_range
, Fcons (a1
, Fcons (a2
, Qnil
)));
141 args_out_of_range_3 (a1
, a2
, a3
)
142 Lisp_Object a1
, a2
, a3
;
145 Fsignal (Qargs_out_of_range
, Fcons (a1
, Fcons (a2
, Fcons (a3
, Qnil
))));
148 /* On some machines, XINT needs a temporary location.
149 Here it is, in case it is needed. */
151 int sign_extend_temp
;
153 /* On a few machines, XINT can only be done by calling this. */
156 sign_extend_lisp_int (num
)
159 if (num
& (((EMACS_INT
) 1) << (VALBITS
- 1)))
160 return num
| (((EMACS_INT
) (-1)) << VALBITS
);
162 return num
& ((((EMACS_INT
) 1) << VALBITS
) - 1);
165 /* Data type predicates */
167 DEFUN ("eq", Feq
, Seq
, 2, 2, 0,
168 "Return t if the two args are the same Lisp object.")
170 Lisp_Object obj1
, obj2
;
177 DEFUN ("null", Fnull
, Snull
, 1, 1, 0, "Return t if OBJECT is nil.")
186 DEFUN ("type-of", Ftype_of
, Stype_of
, 1, 1, 0,
187 "Return a symbol representing the type of OBJECT.\n\
188 The symbol returned names the object's basic type;\n\
189 for example, (type-of 1) returns `integer'.")
193 switch (XGCTYPE (object
))
208 switch (XMISCTYPE (object
))
210 case Lisp_Misc_Marker
:
212 case Lisp_Misc_Overlay
:
214 case Lisp_Misc_Float
:
219 case Lisp_Vectorlike
:
220 if (GC_WINDOW_CONFIGURATIONP (object
))
221 return Qwindow_configuration
;
222 if (GC_PROCESSP (object
))
224 if (GC_WINDOWP (object
))
226 if (GC_SUBRP (object
))
228 if (GC_COMPILEDP (object
))
229 return Qcompiled_function
;
230 if (GC_BUFFERP (object
))
232 if (GC_CHAR_TABLE_P (object
))
234 if (GC_BOOL_VECTOR_P (object
))
236 if (GC_FRAMEP (object
))
238 if (GC_HASH_TABLE_P (object
))
250 DEFUN ("consp", Fconsp
, Sconsp
, 1, 1, 0, "Return t if OBJECT is a cons cell.")
259 DEFUN ("atom", Fatom
, Satom
, 1, 1, 0,
260 "Return t if OBJECT is not a cons cell. This includes nil.")
269 DEFUN ("listp", Flistp
, Slistp
, 1, 1, 0,
270 "Return t if OBJECT is a list. This includes nil.")
274 if (CONSP (object
) || NILP (object
))
279 DEFUN ("nlistp", Fnlistp
, Snlistp
, 1, 1, 0,
280 "Return t if OBJECT is not a list. Lists include nil.")
284 if (CONSP (object
) || NILP (object
))
289 DEFUN ("symbolp", Fsymbolp
, Ssymbolp
, 1, 1, 0,
290 "Return t if OBJECT is a symbol.")
294 if (SYMBOLP (object
))
299 /* Define this in C to avoid unnecessarily consing up the symbol
301 DEFUN ("keywordp", Fkeywordp
, Skeywordp
, 1, 1, 0,
302 "Return t if OBJECT is a keyword.\n\
303 This means that it is a symbol with a print name beginning with `:'\n\
304 interned in the initial obarray.")
309 && XSYMBOL (object
)->name
->data
[0] == ':'
310 && EQ (XSYMBOL (object
)->obarray
, initial_obarray
))
315 DEFUN ("vectorp", Fvectorp
, Svectorp
, 1, 1, 0,
316 "Return t if OBJECT is a vector.")
320 if (VECTORP (object
))
325 DEFUN ("stringp", Fstringp
, Sstringp
, 1, 1, 0,
326 "Return t if OBJECT is a string.")
330 if (STRINGP (object
))
335 DEFUN ("multibyte-string-p", Fmultibyte_string_p
, Smultibyte_string_p
,
336 1, 1, 0, "Return t if OBJECT is a multibyte string.")
340 if (STRINGP (object
) && STRING_MULTIBYTE (object
))
345 DEFUN ("char-table-p", Fchar_table_p
, Schar_table_p
, 1, 1, 0,
346 "Return t if OBJECT is a char-table.")
350 if (CHAR_TABLE_P (object
))
355 DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p
,
356 Svector_or_char_table_p
, 1, 1, 0,
357 "Return t if OBJECT is a char-table or vector.")
361 if (VECTORP (object
) || CHAR_TABLE_P (object
))
366 DEFUN ("bool-vector-p", Fbool_vector_p
, Sbool_vector_p
, 1, 1, 0, "Return t if OBJECT is a bool-vector.")
370 if (BOOL_VECTOR_P (object
))
375 DEFUN ("arrayp", Farrayp
, Sarrayp
, 1, 1, 0, "Return t if OBJECT is an array (string or vector).")
379 if (VECTORP (object
) || STRINGP (object
)
380 || CHAR_TABLE_P (object
) || BOOL_VECTOR_P (object
))
385 DEFUN ("sequencep", Fsequencep
, Ssequencep
, 1, 1, 0,
386 "Return t if OBJECT is a sequence (list or array).")
388 register Lisp_Object object
;
390 if (CONSP (object
) || NILP (object
) || VECTORP (object
) || STRINGP (object
)
391 || CHAR_TABLE_P (object
) || BOOL_VECTOR_P (object
))
396 DEFUN ("bufferp", Fbufferp
, Sbufferp
, 1, 1, 0, "Return t if OBJECT is an editor buffer.")
400 if (BUFFERP (object
))
405 DEFUN ("markerp", Fmarkerp
, Smarkerp
, 1, 1, 0, "Return t if OBJECT is a marker (editor pointer).")
409 if (MARKERP (object
))
414 DEFUN ("subrp", Fsubrp
, Ssubrp
, 1, 1, 0, "Return t if OBJECT is a built-in function.")
423 DEFUN ("byte-code-function-p", Fbyte_code_function_p
, Sbyte_code_function_p
,
424 1, 1, 0, "Return t if OBJECT is a byte-compiled function object.")
428 if (COMPILEDP (object
))
433 DEFUN ("char-or-string-p", Fchar_or_string_p
, Schar_or_string_p
, 1, 1, 0,
434 "Return t if OBJECT is a character (an integer) or a string.")
436 register Lisp_Object object
;
438 if (INTEGERP (object
) || STRINGP (object
))
443 DEFUN ("integerp", Fintegerp
, Sintegerp
, 1, 1, 0, "Return t if OBJECT is an integer.")
447 if (INTEGERP (object
))
452 DEFUN ("integer-or-marker-p", Finteger_or_marker_p
, Sinteger_or_marker_p
, 1, 1, 0,
453 "Return t if OBJECT is an integer or a marker (editor pointer).")
455 register Lisp_Object object
;
457 if (MARKERP (object
) || INTEGERP (object
))
462 DEFUN ("natnump", Fnatnump
, Snatnump
, 1, 1, 0,
463 "Return t if OBJECT is a nonnegative integer.")
467 if (NATNUMP (object
))
472 DEFUN ("numberp", Fnumberp
, Snumberp
, 1, 1, 0,
473 "Return t if OBJECT is a number (floating point or integer).")
477 if (NUMBERP (object
))
483 DEFUN ("number-or-marker-p", Fnumber_or_marker_p
,
484 Snumber_or_marker_p
, 1, 1, 0,
485 "Return t if OBJECT is a number or a marker.")
489 if (NUMBERP (object
) || MARKERP (object
))
494 DEFUN ("floatp", Ffloatp
, Sfloatp
, 1, 1, 0,
495 "Return t if OBJECT is a floating point number.")
505 /* Extract and set components of lists */
507 DEFUN ("car", Fcar
, Scar
, 1, 1, 0,
508 "Return the car of LIST. If arg is nil, return nil.\n\
509 Error if arg is not nil and not a cons cell. See also `car-safe'.")
511 register Lisp_Object list
;
517 else if (EQ (list
, Qnil
))
520 list
= wrong_type_argument (Qlistp
, list
);
524 DEFUN ("car-safe", Fcar_safe
, Scar_safe
, 1, 1, 0,
525 "Return the car of OBJECT if it is a cons cell, or else nil.")
530 return XCAR (object
);
535 DEFUN ("cdr", Fcdr
, Scdr
, 1, 1, 0,
536 "Return the cdr of LIST. If arg is nil, return nil.\n\
537 Error if arg is not nil and not a cons cell. See also `cdr-safe'.")
540 register Lisp_Object list
;
546 else if (EQ (list
, Qnil
))
549 list
= wrong_type_argument (Qlistp
, list
);
553 DEFUN ("cdr-safe", Fcdr_safe
, Scdr_safe
, 1, 1, 0,
554 "Return the cdr of OBJECT if it is a cons cell, or else nil.")
559 return XCDR (object
);
564 DEFUN ("setcar", Fsetcar
, Ssetcar
, 2, 2, 0,
565 "Set the car of CELL to be NEWCAR. Returns NEWCAR.")
567 register Lisp_Object cell
, newcar
;
570 cell
= wrong_type_argument (Qconsp
, cell
);
573 XCAR (cell
) = newcar
;
577 DEFUN ("setcdr", Fsetcdr
, Ssetcdr
, 2, 2, 0,
578 "Set the cdr of CELL to be NEWCDR. Returns NEWCDR.")
580 register Lisp_Object cell
, newcdr
;
583 cell
= wrong_type_argument (Qconsp
, cell
);
586 XCDR (cell
) = newcdr
;
590 /* Extract and set components of symbols */
592 DEFUN ("boundp", Fboundp
, Sboundp
, 1, 1, 0, "Return t if SYMBOL's value is not void.")
594 register Lisp_Object symbol
;
596 Lisp_Object valcontents
;
597 CHECK_SYMBOL (symbol
, 0);
599 valcontents
= XSYMBOL (symbol
)->value
;
601 if (BUFFER_LOCAL_VALUEP (valcontents
)
602 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
603 valcontents
= swap_in_symval_forwarding (symbol
, valcontents
);
605 return (EQ (valcontents
, Qunbound
) ? Qnil
: Qt
);
608 DEFUN ("fboundp", Ffboundp
, Sfboundp
, 1, 1, 0, "Return t if SYMBOL's function definition is not void.")
610 register Lisp_Object symbol
;
612 CHECK_SYMBOL (symbol
, 0);
613 return (EQ (XSYMBOL (symbol
)->function
, Qunbound
) ? Qnil
: Qt
);
616 DEFUN ("makunbound", Fmakunbound
, Smakunbound
, 1, 1, 0, "Make SYMBOL's value be void.")
618 register Lisp_Object symbol
;
620 CHECK_SYMBOL (symbol
, 0);
621 if (NILP (symbol
) || EQ (symbol
, Qt
)
622 || (XSYMBOL (symbol
)->name
->data
[0] == ':'
623 && EQ (XSYMBOL (symbol
)->obarray
, initial_obarray
)))
624 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
625 Fset (symbol
, Qunbound
);
629 DEFUN ("fmakunbound", Ffmakunbound
, Sfmakunbound
, 1, 1, 0, "Make SYMBOL's function definition be void.")
631 register Lisp_Object symbol
;
633 CHECK_SYMBOL (symbol
, 0);
634 if (NILP (symbol
) || EQ (symbol
, Qt
))
635 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
636 XSYMBOL (symbol
)->function
= Qunbound
;
640 DEFUN ("symbol-function", Fsymbol_function
, Ssymbol_function
, 1, 1, 0,
641 "Return SYMBOL's function definition. Error if that is void.")
643 register Lisp_Object symbol
;
645 CHECK_SYMBOL (symbol
, 0);
646 if (EQ (XSYMBOL (symbol
)->function
, Qunbound
))
647 return Fsignal (Qvoid_function
, Fcons (symbol
, Qnil
));
648 return XSYMBOL (symbol
)->function
;
651 DEFUN ("symbol-plist", Fsymbol_plist
, Ssymbol_plist
, 1, 1, 0, "Return SYMBOL's property list.")
653 register Lisp_Object symbol
;
655 CHECK_SYMBOL (symbol
, 0);
656 return XSYMBOL (symbol
)->plist
;
659 DEFUN ("symbol-name", Fsymbol_name
, Ssymbol_name
, 1, 1, 0, "Return SYMBOL's name, a string.")
661 register Lisp_Object symbol
;
663 register Lisp_Object name
;
665 CHECK_SYMBOL (symbol
, 0);
666 XSETSTRING (name
, XSYMBOL (symbol
)->name
);
670 DEFUN ("fset", Ffset
, Sfset
, 2, 2, 0,
671 "Set SYMBOL's function definition to DEFINITION, and return DEFINITION.")
673 register Lisp_Object symbol
, definition
;
675 CHECK_SYMBOL (symbol
, 0);
676 if (NILP (symbol
) || EQ (symbol
, Qt
))
677 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
678 if (!NILP (Vautoload_queue
) && !EQ (XSYMBOL (symbol
)->function
, Qunbound
))
679 Vautoload_queue
= Fcons (Fcons (symbol
, XSYMBOL (symbol
)->function
),
681 XSYMBOL (symbol
)->function
= definition
;
682 /* Handle automatic advice activation */
683 if (CONSP (XSYMBOL (symbol
)->plist
) && !NILP (Fget (symbol
, Qad_advice_info
)))
685 call2 (Qad_activate_internal
, symbol
, Qnil
);
686 definition
= XSYMBOL (symbol
)->function
;
691 DEFUN ("defalias", Fdefalias
, Sdefalias
, 2, 2, 0,
692 "Set SYMBOL's function definition to DEFINITION, and return DEFINITION.\n\
693 Associates the function with the current load file, if any.")
695 register Lisp_Object symbol
, definition
;
697 definition
= Ffset (symbol
, definition
);
698 LOADHIST_ATTACH (symbol
);
702 DEFUN ("setplist", Fsetplist
, Ssetplist
, 2, 2, 0,
703 "Set SYMBOL's property list to NEWVAL, and return NEWVAL.")
705 register Lisp_Object symbol
, newplist
;
707 CHECK_SYMBOL (symbol
, 0);
708 XSYMBOL (symbol
)->plist
= newplist
;
712 DEFUN ("subr-arity", Fsubr_arity
, Ssubr_arity
, 1, 1, 0,
713 "Return minimum and maximum number of args allowed for SUBR.\n\
714 SUBR must be a built-in function.\n\
715 The returned value is a pair (MIN . MAX). MIN is the minimum number\n\
716 of args. MAX is the maximum number or the symbol `many', for a\n\
717 function with `&rest' args, or `unevalled' for a special form.")
721 short minargs
, maxargs
;
723 wrong_type_argument (Qsubrp
, subr
);
724 minargs
= XSUBR (subr
)->min_args
;
725 maxargs
= XSUBR (subr
)->max_args
;
727 return Fcons (make_number (minargs
), Qmany
);
728 else if (maxargs
== UNEVALLED
)
729 return Fcons (make_number (minargs
), Qunevalled
);
731 return Fcons (make_number (minargs
), make_number (maxargs
));
734 DEFUN ("subr-interactive-form", Fsubr_interactive_form
, Ssubr_interactive_form
, 1, 1, 0,
735 "Return the interactive form of SUBR or nil if none.\n\
736 SUBR must be a built-in function. Value, if non-nil, is a list\n\
737 \(interactive SPEC).")
742 wrong_type_argument (Qsubrp
, subr
);
743 if (XSUBR (subr
)->prompt
)
744 return list2 (Qinteractive
, build_string (XSUBR (subr
)->prompt
));
749 /* Getting and setting values of symbols */
751 /* Given the raw contents of a symbol value cell,
752 return the Lisp value of the symbol.
753 This does not handle buffer-local variables; use
754 swap_in_symval_forwarding for that. */
757 do_symval_forwarding (valcontents
)
758 register Lisp_Object valcontents
;
760 register Lisp_Object val
;
762 if (MISCP (valcontents
))
763 switch (XMISCTYPE (valcontents
))
765 case Lisp_Misc_Intfwd
:
766 XSETINT (val
, *XINTFWD (valcontents
)->intvar
);
769 case Lisp_Misc_Boolfwd
:
770 return (*XBOOLFWD (valcontents
)->boolvar
? Qt
: Qnil
);
772 case Lisp_Misc_Objfwd
:
773 return *XOBJFWD (valcontents
)->objvar
;
775 case Lisp_Misc_Buffer_Objfwd
:
776 offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
777 return PER_BUFFER_VALUE (current_buffer
, offset
);
779 case Lisp_Misc_Kboard_Objfwd
:
780 offset
= XKBOARD_OBJFWD (valcontents
)->offset
;
781 return *(Lisp_Object
*)(offset
+ (char *)current_kboard
);
786 /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell
787 of SYMBOL. If SYMBOL is buffer-local, VALCONTENTS should be the
788 buffer-independent contents of the value cell: forwarded just one
789 step past the buffer-localness.
791 BUF non-zero means set the value in buffer BUF instead of the
792 current buffer. This only plays a role for per-buffer variables. */
795 store_symval_forwarding (symbol
, valcontents
, newval
, buf
)
797 register Lisp_Object valcontents
, newval
;
800 switch (SWITCH_ENUM_CAST (XTYPE (valcontents
)))
803 switch (XMISCTYPE (valcontents
))
805 case Lisp_Misc_Intfwd
:
806 CHECK_NUMBER (newval
, 1);
807 *XINTFWD (valcontents
)->intvar
= XINT (newval
);
808 if (*XINTFWD (valcontents
)->intvar
!= XINT (newval
))
809 error ("Value out of range for variable `%s'",
810 XSYMBOL (symbol
)->name
->data
);
813 case Lisp_Misc_Boolfwd
:
814 *XBOOLFWD (valcontents
)->boolvar
= NILP (newval
) ? 0 : 1;
817 case Lisp_Misc_Objfwd
:
818 *XOBJFWD (valcontents
)->objvar
= newval
;
821 case Lisp_Misc_Buffer_Objfwd
:
823 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
826 type
= PER_BUFFER_TYPE (offset
);
827 if (XINT (type
) == -1)
828 error ("Variable %s is read-only", XSYMBOL (symbol
)->name
->data
);
830 if (! NILP (type
) && ! NILP (newval
)
831 && XTYPE (newval
) != XINT (type
))
832 buffer_slot_type_mismatch (offset
);
835 buf
= current_buffer
;
836 PER_BUFFER_VALUE (buf
, offset
) = newval
;
840 case Lisp_Misc_Kboard_Objfwd
:
842 char *base
= (char *) current_kboard
;
843 char *p
= base
+ XKBOARD_OBJFWD (valcontents
)->offset
;
844 *(Lisp_Object
*) p
= newval
;
855 valcontents
= XSYMBOL (symbol
)->value
;
856 if (BUFFER_LOCAL_VALUEP (valcontents
)
857 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
858 XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
= newval
;
860 XSYMBOL (symbol
)->value
= newval
;
864 /* Set up SYMBOL to refer to its global binding.
865 This makes it safe to alter the status of other bindings. */
868 swap_in_global_binding (symbol
)
871 Lisp_Object valcontents
, cdr
;
873 valcontents
= XSYMBOL (symbol
)->value
;
874 if (!BUFFER_LOCAL_VALUEP (valcontents
)
875 && !SOME_BUFFER_LOCAL_VALUEP (valcontents
))
877 cdr
= XBUFFER_LOCAL_VALUE (valcontents
)->cdr
;
879 /* Unload the previously loaded binding. */
881 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
));
883 /* Select the global binding in the symbol. */
885 store_symval_forwarding (symbol
, valcontents
, XCDR (cdr
), NULL
);
887 /* Indicate that the global binding is set up now. */
888 XBUFFER_LOCAL_VALUE (valcontents
)->frame
= Qnil
;
889 XBUFFER_LOCAL_VALUE (valcontents
)->buffer
= Qnil
;
890 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
= 0;
891 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 0;
894 /* Set up the buffer-local symbol SYMBOL for validity in the current buffer.
895 VALCONTENTS is the contents of its value cell,
896 which points to a struct Lisp_Buffer_Local_Value.
898 Return the value forwarded one step past the buffer-local stage.
899 This could be another forwarding pointer. */
902 swap_in_symval_forwarding (symbol
, valcontents
)
903 Lisp_Object symbol
, valcontents
;
905 register Lisp_Object tem1
;
906 tem1
= XBUFFER_LOCAL_VALUE (valcontents
)->buffer
;
909 || current_buffer
!= XBUFFER (tem1
)
910 || (XBUFFER_LOCAL_VALUE (valcontents
)->check_frame
911 && ! EQ (selected_frame
, XBUFFER_LOCAL_VALUE (valcontents
)->frame
)))
913 /* Unload the previously loaded binding. */
914 tem1
= XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
916 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
));
917 /* Choose the new binding. */
918 tem1
= assq_no_quit (symbol
, current_buffer
->local_var_alist
);
919 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
= 0;
920 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 0;
923 if (XBUFFER_LOCAL_VALUE (valcontents
)->check_frame
)
924 tem1
= assq_no_quit (symbol
, XFRAME (selected_frame
)->param_alist
);
926 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
= 1;
928 tem1
= XBUFFER_LOCAL_VALUE (valcontents
)->cdr
;
931 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 1;
933 /* Load the new binding. */
934 XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
) = tem1
;
935 XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents
)->buffer
, current_buffer
);
936 XBUFFER_LOCAL_VALUE (valcontents
)->frame
= selected_frame
;
937 store_symval_forwarding (symbol
,
938 XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
941 return XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
;
944 /* Find the value of a symbol, returning Qunbound if it's not bound.
945 This is helpful for code which just wants to get a variable's value
946 if it has one, without signaling an error.
947 Note that it must not be possible to quit
948 within this function. Great care is required for this. */
951 find_symbol_value (symbol
)
954 register Lisp_Object valcontents
;
955 register Lisp_Object val
;
956 CHECK_SYMBOL (symbol
, 0);
957 valcontents
= XSYMBOL (symbol
)->value
;
959 if (BUFFER_LOCAL_VALUEP (valcontents
)
960 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
961 valcontents
= swap_in_symval_forwarding (symbol
, valcontents
);
963 if (MISCP (valcontents
))
965 switch (XMISCTYPE (valcontents
))
967 case Lisp_Misc_Intfwd
:
968 XSETINT (val
, *XINTFWD (valcontents
)->intvar
);
971 case Lisp_Misc_Boolfwd
:
972 return (*XBOOLFWD (valcontents
)->boolvar
? Qt
: Qnil
);
974 case Lisp_Misc_Objfwd
:
975 return *XOBJFWD (valcontents
)->objvar
;
977 case Lisp_Misc_Buffer_Objfwd
:
978 return PER_BUFFER_VALUE (current_buffer
,
979 XBUFFER_OBJFWD (valcontents
)->offset
);
981 case Lisp_Misc_Kboard_Objfwd
:
982 return *(Lisp_Object
*)(XKBOARD_OBJFWD (valcontents
)->offset
983 + (char *)current_kboard
);
990 DEFUN ("symbol-value", Fsymbol_value
, Ssymbol_value
, 1, 1, 0,
991 "Return SYMBOL's value. Error if that is void.")
997 val
= find_symbol_value (symbol
);
998 if (EQ (val
, Qunbound
))
999 return Fsignal (Qvoid_variable
, Fcons (symbol
, Qnil
));
1004 DEFUN ("set", Fset
, Sset
, 2, 2, 0,
1005 "Set SYMBOL's value to NEWVAL, and return NEWVAL.")
1007 register Lisp_Object symbol
, newval
;
1009 return set_internal (symbol
, newval
, current_buffer
, 0);
1012 /* Return 1 if SYMBOL currently has a let-binding
1013 which was made in the buffer that is now current. */
1016 let_shadows_buffer_binding_p (symbol
)
1019 struct specbinding
*p
;
1021 for (p
= specpdl_ptr
- 1; p
>= specpdl
; p
--)
1023 && CONSP (p
->symbol
)
1024 && EQ (symbol
, XCAR (p
->symbol
))
1025 && XBUFFER (XCDR (XCDR (p
->symbol
))) == current_buffer
)
1031 /* Store the value NEWVAL into SYMBOL.
1032 If buffer-locality is an issue, BUF specifies which buffer to use.
1033 (0 stands for the current buffer.)
1035 If BINDFLAG is zero, then if this symbol is supposed to become
1036 local in every buffer where it is set, then we make it local.
1037 If BINDFLAG is nonzero, we don't do that. */
1040 set_internal (symbol
, newval
, buf
, bindflag
)
1041 register Lisp_Object symbol
, newval
;
1045 int voide
= EQ (newval
, Qunbound
);
1047 register Lisp_Object valcontents
, innercontents
, tem1
, current_alist_element
;
1050 buf
= current_buffer
;
1052 /* If restoring in a dead buffer, do nothing. */
1053 if (NILP (buf
->name
))
1056 CHECK_SYMBOL (symbol
, 0);
1057 if (NILP (symbol
) || EQ (symbol
, Qt
)
1058 || (XSYMBOL (symbol
)->name
->data
[0] == ':'
1059 && EQ (XSYMBOL (symbol
)->obarray
, initial_obarray
)
1060 && !EQ (newval
, symbol
)))
1061 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
1063 innercontents
= valcontents
= XSYMBOL (symbol
)->value
;
1065 if (BUFFER_OBJFWDP (valcontents
))
1067 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1068 int idx
= PER_BUFFER_IDX (offset
);
1071 && !let_shadows_buffer_binding_p (symbol
))
1072 SET_PER_BUFFER_VALUE_P (buf
, idx
, 1);
1075 else if (BUFFER_LOCAL_VALUEP (valcontents
)
1076 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1078 /* valcontents is a struct Lisp_Buffer_Local_Value. */
1080 /* What binding is loaded right now? */
1081 current_alist_element
1082 = XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
1084 /* If the current buffer is not the buffer whose binding is
1085 loaded, or if there may be frame-local bindings and the frame
1086 isn't the right one, or if it's a Lisp_Buffer_Local_Value and
1087 the default binding is loaded, the loaded binding may be the
1089 if (!BUFFERP (XBUFFER_LOCAL_VALUE (valcontents
)->buffer
)
1090 || buf
!= XBUFFER (XBUFFER_LOCAL_VALUE (valcontents
)->buffer
)
1091 || (XBUFFER_LOCAL_VALUE (valcontents
)->check_frame
1092 && !EQ (selected_frame
, XBUFFER_LOCAL_VALUE (valcontents
)->frame
))
1093 || (BUFFER_LOCAL_VALUEP (valcontents
)
1094 && EQ (XCAR (current_alist_element
),
1095 current_alist_element
)))
1097 /* The currently loaded binding is not necessarily valid.
1098 We need to unload it, and choose a new binding. */
1100 /* Write out `realvalue' to the old loaded binding. */
1101 Fsetcdr (current_alist_element
,
1102 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
));
1104 /* Find the new binding. */
1105 tem1
= Fassq (symbol
, buf
->local_var_alist
);
1106 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 1;
1107 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
= 0;
1111 /* This buffer still sees the default value. */
1113 /* If the variable is a Lisp_Some_Buffer_Local_Value,
1114 or if this is `let' rather than `set',
1115 make CURRENT-ALIST-ELEMENT point to itself,
1116 indicating that we're seeing the default value.
1117 Likewise if the variable has been let-bound
1118 in the current buffer. */
1119 if (bindflag
|| SOME_BUFFER_LOCAL_VALUEP (valcontents
)
1120 || let_shadows_buffer_binding_p (symbol
))
1122 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 0;
1124 if (XBUFFER_LOCAL_VALUE (valcontents
)->check_frame
)
1125 tem1
= Fassq (symbol
,
1126 XFRAME (selected_frame
)->param_alist
);
1129 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
= 1;
1131 tem1
= XBUFFER_LOCAL_VALUE (valcontents
)->cdr
;
1133 /* If it's a Lisp_Buffer_Local_Value, being set not bound,
1134 and we're not within a let that was made for this buffer,
1135 create a new buffer-local binding for the variable.
1136 That means, give this buffer a new assoc for a local value
1137 and load that binding. */
1140 tem1
= Fcons (symbol
, Fcdr (current_alist_element
));
1141 buf
->local_var_alist
1142 = Fcons (tem1
, buf
->local_var_alist
);
1146 /* Record which binding is now loaded. */
1147 XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)
1150 /* Set `buffer' and `frame' slots for thebinding now loaded. */
1151 XSETBUFFER (XBUFFER_LOCAL_VALUE (valcontents
)->buffer
, buf
);
1152 XBUFFER_LOCAL_VALUE (valcontents
)->frame
= selected_frame
;
1154 innercontents
= XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
;
1157 /* If storing void (making the symbol void), forward only through
1158 buffer-local indicator, not through Lisp_Objfwd, etc. */
1160 store_symval_forwarding (symbol
, Qnil
, newval
, buf
);
1162 store_symval_forwarding (symbol
, innercontents
, newval
, buf
);
1164 /* If we just set a variable whose current binding is frame-local,
1165 store the new value in the frame parameter too. */
1167 if (BUFFER_LOCAL_VALUEP (valcontents
)
1168 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1170 /* What binding is loaded right now? */
1171 current_alist_element
1172 = XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
1174 /* If the current buffer is not the buffer whose binding is
1175 loaded, or if there may be frame-local bindings and the frame
1176 isn't the right one, or if it's a Lisp_Buffer_Local_Value and
1177 the default binding is loaded, the loaded binding may be the
1179 if (XBUFFER_LOCAL_VALUE (valcontents
)->found_for_frame
)
1180 XCDR (current_alist_element
) = newval
;
1186 /* Access or set a buffer-local symbol's default value. */
1188 /* Return the default value of SYMBOL, but don't check for voidness.
1189 Return Qunbound if it is void. */
1192 default_value (symbol
)
1195 register Lisp_Object valcontents
;
1197 CHECK_SYMBOL (symbol
, 0);
1198 valcontents
= XSYMBOL (symbol
)->value
;
1200 /* For a built-in buffer-local variable, get the default value
1201 rather than letting do_symval_forwarding get the current value. */
1202 if (BUFFER_OBJFWDP (valcontents
))
1204 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1205 if (PER_BUFFER_IDX (offset
) != 0)
1206 return PER_BUFFER_DEFAULT (offset
);
1209 /* Handle user-created local variables. */
1210 if (BUFFER_LOCAL_VALUEP (valcontents
)
1211 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1213 /* If var is set up for a buffer that lacks a local value for it,
1214 the current value is nominally the default value.
1215 But the `realvalue' slot may be more up to date, since
1216 ordinary setq stores just that slot. So use that. */
1217 Lisp_Object current_alist_element
, alist_element_car
;
1218 current_alist_element
1219 = XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
1220 alist_element_car
= XCAR (current_alist_element
);
1221 if (EQ (alist_element_car
, current_alist_element
))
1222 return do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
);
1224 return XCDR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
1226 /* For other variables, get the current value. */
1227 return do_symval_forwarding (valcontents
);
1230 DEFUN ("default-boundp", Fdefault_boundp
, Sdefault_boundp
, 1, 1, 0,
1231 "Return t if SYMBOL has a non-void default value.\n\
1232 This is the value that is seen in buffers that do not have their own values\n\
1233 for this variable.")
1237 register Lisp_Object value
;
1239 value
= default_value (symbol
);
1240 return (EQ (value
, Qunbound
) ? Qnil
: Qt
);
1243 DEFUN ("default-value", Fdefault_value
, Sdefault_value
, 1, 1, 0,
1244 "Return SYMBOL's default value.\n\
1245 This is the value that is seen in buffers that do not have their own values\n\
1246 for this variable. The default value is meaningful for variables with\n\
1247 local bindings in certain buffers.")
1251 register Lisp_Object value
;
1253 value
= default_value (symbol
);
1254 if (EQ (value
, Qunbound
))
1255 return Fsignal (Qvoid_variable
, Fcons (symbol
, Qnil
));
1259 DEFUN ("set-default", Fset_default
, Sset_default
, 2, 2, 0,
1260 "Set SYMBOL's default value to VAL. SYMBOL and VAL are evaluated.\n\
1261 The default value is seen in buffers that do not have their own values\n\
1262 for this variable.")
1264 Lisp_Object symbol
, value
;
1266 register Lisp_Object valcontents
, current_alist_element
, alist_element_buffer
;
1268 CHECK_SYMBOL (symbol
, 0);
1269 valcontents
= XSYMBOL (symbol
)->value
;
1271 /* Handle variables like case-fold-search that have special slots
1272 in the buffer. Make them work apparently like Lisp_Buffer_Local_Value
1274 if (BUFFER_OBJFWDP (valcontents
))
1276 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1277 int idx
= PER_BUFFER_IDX (offset
);
1279 PER_BUFFER_DEFAULT (offset
) = value
;
1281 /* If this variable is not always local in all buffers,
1282 set it in the buffers that don't nominally have a local value. */
1287 for (b
= all_buffers
; b
; b
= b
->next
)
1288 if (!PER_BUFFER_VALUE_P (b
, idx
))
1289 PER_BUFFER_VALUE (b
, offset
) = value
;
1294 if (!BUFFER_LOCAL_VALUEP (valcontents
)
1295 && !SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1296 return Fset (symbol
, value
);
1298 /* Store new value into the DEFAULT-VALUE slot. */
1299 XCDR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
) = value
;
1301 /* If the default binding is now loaded, set the REALVALUE slot too. */
1302 current_alist_element
1303 = XCAR (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
);
1304 alist_element_buffer
= Fcar (current_alist_element
);
1305 if (EQ (alist_element_buffer
, current_alist_element
))
1306 store_symval_forwarding (symbol
,
1307 XBUFFER_LOCAL_VALUE (valcontents
)->realvalue
,
1313 DEFUN ("setq-default", Fsetq_default
, Ssetq_default
, 2, UNEVALLED
, 0,
1314 "Set the default value of variable VAR to VALUE.\n\
1315 VAR, the variable name, is literal (not evaluated);\n\
1316 VALUE is an expression and it is evaluated.\n\
1317 The default value of a variable is seen in buffers\n\
1318 that do not have their own values for the variable.\n\
1320 More generally, you can use multiple variables and values, as in\n\
1321 (setq-default SYMBOL VALUE SYMBOL VALUE...)\n\
1322 This sets each SYMBOL's default value to the corresponding VALUE.\n\
1323 The VALUE for the Nth SYMBOL can refer to the new default values\n\
1328 register Lisp_Object args_left
;
1329 register Lisp_Object val
, symbol
;
1330 struct gcpro gcpro1
;
1340 val
= Feval (Fcar (Fcdr (args_left
)));
1341 symbol
= Fcar (args_left
);
1342 Fset_default (symbol
, val
);
1343 args_left
= Fcdr (Fcdr (args_left
));
1345 while (!NILP (args_left
));
1351 /* Lisp functions for creating and removing buffer-local variables. */
1353 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local
, Smake_variable_buffer_local
,
1354 1, 1, "vMake Variable Buffer Local: ",
1355 "Make VARIABLE become buffer-local whenever it is set.\n\
1356 At any time, the value for the current buffer is in effect,\n\
1357 unless the variable has never been set in this buffer,\n\
1358 in which case the default value is in effect.\n\
1359 Note that binding the variable with `let', or setting it while\n\
1360 a `let'-style binding made in this buffer is in effect,\n\
1361 does not make the variable buffer-local.\n\
1363 The function `default-value' gets the default value and `set-default' sets it.")
1365 register Lisp_Object variable
;
1367 register Lisp_Object tem
, valcontents
, newval
;
1369 CHECK_SYMBOL (variable
, 0);
1371 valcontents
= XSYMBOL (variable
)->value
;
1372 if (EQ (variable
, Qnil
) || EQ (variable
, Qt
) || KBOARD_OBJFWDP (valcontents
))
1373 error ("Symbol %s may not be buffer-local", XSYMBOL (variable
)->name
->data
);
1375 if (BUFFER_LOCAL_VALUEP (valcontents
) || BUFFER_OBJFWDP (valcontents
))
1377 if (SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1379 XMISCTYPE (XSYMBOL (variable
)->value
) = Lisp_Misc_Buffer_Local_Value
;
1382 if (EQ (valcontents
, Qunbound
))
1383 XSYMBOL (variable
)->value
= Qnil
;
1384 tem
= Fcons (Qnil
, Fsymbol_value (variable
));
1386 newval
= allocate_misc ();
1387 XMISCTYPE (newval
) = Lisp_Misc_Buffer_Local_Value
;
1388 XBUFFER_LOCAL_VALUE (newval
)->realvalue
= XSYMBOL (variable
)->value
;
1389 XBUFFER_LOCAL_VALUE (newval
)->buffer
= Fcurrent_buffer ();
1390 XBUFFER_LOCAL_VALUE (newval
)->frame
= Qnil
;
1391 XBUFFER_LOCAL_VALUE (newval
)->found_for_buffer
= 0;
1392 XBUFFER_LOCAL_VALUE (newval
)->found_for_frame
= 0;
1393 XBUFFER_LOCAL_VALUE (newval
)->check_frame
= 0;
1394 XBUFFER_LOCAL_VALUE (newval
)->cdr
= tem
;
1395 XSYMBOL (variable
)->value
= newval
;
1399 DEFUN ("make-local-variable", Fmake_local_variable
, Smake_local_variable
,
1400 1, 1, "vMake Local Variable: ",
1401 "Make VARIABLE have a separate value in the current buffer.\n\
1402 Other buffers will continue to share a common default value.\n\
1403 \(The buffer-local value of VARIABLE starts out as the same value\n\
1404 VARIABLE previously had. If VARIABLE was void, it remains void.\)\n\
1405 See also `make-variable-buffer-local'.\n\
1407 If the variable is already arranged to become local when set,\n\
1408 this function causes a local value to exist for this buffer,\n\
1409 just as setting the variable would do.\n\
1411 This function returns VARIABLE, and therefore\n\
1412 (set (make-local-variable 'VARIABLE) VALUE-EXP)\n\
1415 Do not use `make-local-variable' to make a hook variable buffer-local.\n\
1416 Use `make-local-hook' instead.")
1418 register Lisp_Object variable
;
1420 register Lisp_Object tem
, valcontents
;
1422 CHECK_SYMBOL (variable
, 0);
1424 valcontents
= XSYMBOL (variable
)->value
;
1425 if (EQ (variable
, Qnil
) || EQ (variable
, Qt
) || KBOARD_OBJFWDP (valcontents
))
1426 error ("Symbol %s may not be buffer-local", XSYMBOL (variable
)->name
->data
);
1428 if (BUFFER_LOCAL_VALUEP (valcontents
) || BUFFER_OBJFWDP (valcontents
))
1430 tem
= Fboundp (variable
);
1432 /* Make sure the symbol has a local value in this particular buffer,
1433 by setting it to the same value it already has. */
1434 Fset (variable
, (EQ (tem
, Qt
) ? Fsymbol_value (variable
) : Qunbound
));
1437 /* Make sure symbol is set up to hold per-buffer values. */
1438 if (!SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1441 tem
= Fcons (Qnil
, do_symval_forwarding (valcontents
));
1443 newval
= allocate_misc ();
1444 XMISCTYPE (newval
) = Lisp_Misc_Some_Buffer_Local_Value
;
1445 XBUFFER_LOCAL_VALUE (newval
)->realvalue
= XSYMBOL (variable
)->value
;
1446 XBUFFER_LOCAL_VALUE (newval
)->buffer
= Qnil
;
1447 XBUFFER_LOCAL_VALUE (newval
)->frame
= Qnil
;
1448 XBUFFER_LOCAL_VALUE (newval
)->found_for_buffer
= 0;
1449 XBUFFER_LOCAL_VALUE (newval
)->found_for_frame
= 0;
1450 XBUFFER_LOCAL_VALUE (newval
)->check_frame
= 0;
1451 XBUFFER_LOCAL_VALUE (newval
)->cdr
= tem
;
1452 XSYMBOL (variable
)->value
= newval
;
1454 /* Make sure this buffer has its own value of symbol. */
1455 tem
= Fassq (variable
, current_buffer
->local_var_alist
);
1458 /* Swap out any local binding for some other buffer, and make
1459 sure the current value is permanently recorded, if it's the
1461 find_symbol_value (variable
);
1463 current_buffer
->local_var_alist
1464 = Fcons (Fcons (variable
, XCDR (XBUFFER_LOCAL_VALUE (XSYMBOL (variable
)->value
)->cdr
)),
1465 current_buffer
->local_var_alist
);
1467 /* Make sure symbol does not think it is set up for this buffer;
1468 force it to look once again for this buffer's value. */
1470 Lisp_Object
*pvalbuf
;
1472 valcontents
= XSYMBOL (variable
)->value
;
1474 pvalbuf
= &XBUFFER_LOCAL_VALUE (valcontents
)->buffer
;
1475 if (current_buffer
== XBUFFER (*pvalbuf
))
1477 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 0;
1481 /* If the symbol forwards into a C variable, then load the binding
1482 for this buffer now. If C code modifies the variable before we
1483 load the binding in, then that new value will clobber the default
1484 binding the next time we unload it. */
1485 valcontents
= XBUFFER_LOCAL_VALUE (XSYMBOL (variable
)->value
)->realvalue
;
1486 if (INTFWDP (valcontents
) || BOOLFWDP (valcontents
) || OBJFWDP (valcontents
))
1487 swap_in_symval_forwarding (variable
, XSYMBOL (variable
)->value
);
1492 DEFUN ("kill-local-variable", Fkill_local_variable
, Skill_local_variable
,
1493 1, 1, "vKill Local Variable: ",
1494 "Make VARIABLE no longer have a separate value in the current buffer.\n\
1495 From now on the default value will apply in this buffer.")
1497 register Lisp_Object variable
;
1499 register Lisp_Object tem
, valcontents
;
1501 CHECK_SYMBOL (variable
, 0);
1503 valcontents
= XSYMBOL (variable
)->value
;
1505 if (BUFFER_OBJFWDP (valcontents
))
1507 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1508 int idx
= PER_BUFFER_IDX (offset
);
1512 SET_PER_BUFFER_VALUE_P (current_buffer
, idx
, 0);
1513 PER_BUFFER_VALUE (current_buffer
, offset
)
1514 = PER_BUFFER_DEFAULT (offset
);
1519 if (!BUFFER_LOCAL_VALUEP (valcontents
)
1520 && !SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1523 /* Get rid of this buffer's alist element, if any. */
1525 tem
= Fassq (variable
, current_buffer
->local_var_alist
);
1527 current_buffer
->local_var_alist
1528 = Fdelq (tem
, current_buffer
->local_var_alist
);
1530 /* If the symbol is set up with the current buffer's binding
1531 loaded, recompute its value. We have to do it now, or else
1532 forwarded objects won't work right. */
1534 Lisp_Object
*pvalbuf
;
1535 valcontents
= XSYMBOL (variable
)->value
;
1536 pvalbuf
= &XBUFFER_LOCAL_VALUE (valcontents
)->buffer
;
1537 if (current_buffer
== XBUFFER (*pvalbuf
))
1540 XBUFFER_LOCAL_VALUE (valcontents
)->found_for_buffer
= 0;
1541 find_symbol_value (variable
);
1548 /* Lisp functions for creating and removing buffer-local variables. */
1550 DEFUN ("make-variable-frame-local", Fmake_variable_frame_local
, Smake_variable_frame_local
,
1551 1, 1, "vMake Variable Frame Local: ",
1552 "Enable VARIABLE to have frame-local bindings.\n\
1553 When a frame-local binding exists in the current frame,\n\
1554 it is in effect whenever the current buffer has no buffer-local binding.\n\
1555 A frame-local binding is actual a frame parameter value;\n\
1556 thus, any given frame has a local binding for VARIABLE\n\
1557 if it has a value for the frame parameter named VARIABLE.\n\
1558 See `modify-frame-parameters'.")
1560 register Lisp_Object variable
;
1562 register Lisp_Object tem
, valcontents
, newval
;
1564 CHECK_SYMBOL (variable
, 0);
1566 valcontents
= XSYMBOL (variable
)->value
;
1567 if (EQ (variable
, Qnil
) || EQ (variable
, Qt
) || KBOARD_OBJFWDP (valcontents
)
1568 || BUFFER_OBJFWDP (valcontents
))
1569 error ("Symbol %s may not be frame-local", XSYMBOL (variable
)->name
->data
);
1571 if (BUFFER_LOCAL_VALUEP (valcontents
)
1572 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1574 XBUFFER_LOCAL_VALUE (valcontents
)->check_frame
= 1;
1578 if (EQ (valcontents
, Qunbound
))
1579 XSYMBOL (variable
)->value
= Qnil
;
1580 tem
= Fcons (Qnil
, Fsymbol_value (variable
));
1582 newval
= allocate_misc ();
1583 XMISCTYPE (newval
) = Lisp_Misc_Some_Buffer_Local_Value
;
1584 XBUFFER_LOCAL_VALUE (newval
)->realvalue
= XSYMBOL (variable
)->value
;
1585 XBUFFER_LOCAL_VALUE (newval
)->buffer
= Qnil
;
1586 XBUFFER_LOCAL_VALUE (newval
)->frame
= Qnil
;
1587 XBUFFER_LOCAL_VALUE (newval
)->found_for_buffer
= 0;
1588 XBUFFER_LOCAL_VALUE (newval
)->found_for_frame
= 0;
1589 XBUFFER_LOCAL_VALUE (newval
)->check_frame
= 1;
1590 XBUFFER_LOCAL_VALUE (newval
)->cdr
= tem
;
1591 XSYMBOL (variable
)->value
= newval
;
1595 DEFUN ("local-variable-p", Flocal_variable_p
, Slocal_variable_p
,
1597 "Non-nil if VARIABLE has a local binding in buffer BUFFER.\n\
1598 BUFFER defaults to the current buffer.")
1600 register Lisp_Object variable
, buffer
;
1602 Lisp_Object valcontents
;
1603 register struct buffer
*buf
;
1606 buf
= current_buffer
;
1609 CHECK_BUFFER (buffer
, 0);
1610 buf
= XBUFFER (buffer
);
1613 CHECK_SYMBOL (variable
, 0);
1615 valcontents
= XSYMBOL (variable
)->value
;
1616 if (BUFFER_LOCAL_VALUEP (valcontents
)
1617 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1619 Lisp_Object tail
, elt
;
1620 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
1623 if (EQ (variable
, XCAR (elt
)))
1627 if (BUFFER_OBJFWDP (valcontents
))
1629 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1630 int idx
= PER_BUFFER_IDX (offset
);
1631 if (idx
== -1 || PER_BUFFER_VALUE_P (buf
, idx
))
1637 DEFUN ("local-variable-if-set-p", Flocal_variable_if_set_p
, Slocal_variable_if_set_p
,
1639 "Non-nil if VARIABLE will be local in buffer BUFFER if it is set there.\n\
1640 BUFFER defaults to the current buffer.")
1642 register Lisp_Object variable
, buffer
;
1644 Lisp_Object valcontents
;
1645 register struct buffer
*buf
;
1648 buf
= current_buffer
;
1651 CHECK_BUFFER (buffer
, 0);
1652 buf
= XBUFFER (buffer
);
1655 CHECK_SYMBOL (variable
, 0);
1657 valcontents
= XSYMBOL (variable
)->value
;
1659 /* This means that make-variable-buffer-local was done. */
1660 if (BUFFER_LOCAL_VALUEP (valcontents
))
1662 /* All these slots become local if they are set. */
1663 if (BUFFER_OBJFWDP (valcontents
))
1665 if (SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1667 Lisp_Object tail
, elt
;
1668 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCDR (tail
))
1671 if (EQ (variable
, XCAR (elt
)))
1678 /* Find the function at the end of a chain of symbol function indirections. */
1680 /* If OBJECT is a symbol, find the end of its function chain and
1681 return the value found there. If OBJECT is not a symbol, just
1682 return it. If there is a cycle in the function chain, signal a
1683 cyclic-function-indirection error.
1685 This is like Findirect_function, except that it doesn't signal an
1686 error if the chain ends up unbound. */
1688 indirect_function (object
)
1689 register Lisp_Object object
;
1691 Lisp_Object tortoise
, hare
;
1693 hare
= tortoise
= object
;
1697 if (!SYMBOLP (hare
) || EQ (hare
, Qunbound
))
1699 hare
= XSYMBOL (hare
)->function
;
1700 if (!SYMBOLP (hare
) || EQ (hare
, Qunbound
))
1702 hare
= XSYMBOL (hare
)->function
;
1704 tortoise
= XSYMBOL (tortoise
)->function
;
1706 if (EQ (hare
, tortoise
))
1707 Fsignal (Qcyclic_function_indirection
, Fcons (object
, Qnil
));
1713 DEFUN ("indirect-function", Findirect_function
, Sindirect_function
, 1, 1, 0,
1714 "Return the function at the end of OBJECT's function chain.\n\
1715 If OBJECT is a symbol, follow all function indirections and return the final\n\
1716 function binding.\n\
1717 If OBJECT is not a symbol, just return it.\n\
1718 Signal a void-function error if the final symbol is unbound.\n\
1719 Signal a cyclic-function-indirection error if there is a loop in the\n\
1720 function chain of symbols.")
1722 register Lisp_Object object
;
1726 result
= indirect_function (object
);
1728 if (EQ (result
, Qunbound
))
1729 return Fsignal (Qvoid_function
, Fcons (object
, Qnil
));
1733 /* Extract and set vector and string elements */
1735 DEFUN ("aref", Faref
, Saref
, 2, 2, 0,
1736 "Return the element of ARRAY at index IDX.\n\
1737 ARRAY may be a vector, a string, a char-table, a bool-vector,\n\
1738 or a byte-code object. IDX starts at 0.")
1740 register Lisp_Object array
;
1743 register int idxval
;
1745 CHECK_NUMBER (idx
, 1);
1746 idxval
= XINT (idx
);
1747 if (STRINGP (array
))
1751 if (idxval
< 0 || idxval
>= XSTRING (array
)->size
)
1752 args_out_of_range (array
, idx
);
1753 if (! STRING_MULTIBYTE (array
))
1754 return make_number ((unsigned char) XSTRING (array
)->data
[idxval
]);
1755 idxval_byte
= string_char_to_byte (array
, idxval
);
1757 c
= STRING_CHAR (&XSTRING (array
)->data
[idxval_byte
],
1758 STRING_BYTES (XSTRING (array
)) - idxval_byte
);
1759 return make_number (c
);
1761 else if (BOOL_VECTOR_P (array
))
1765 if (idxval
< 0 || idxval
>= XBOOL_VECTOR (array
)->size
)
1766 args_out_of_range (array
, idx
);
1768 val
= (unsigned char) XBOOL_VECTOR (array
)->data
[idxval
/ BITS_PER_CHAR
];
1769 return (val
& (1 << (idxval
% BITS_PER_CHAR
)) ? Qt
: Qnil
);
1771 else if (CHAR_TABLE_P (array
))
1778 args_out_of_range (array
, idx
);
1779 if (idxval
< CHAR_TABLE_ORDINARY_SLOTS
)
1781 /* For ASCII and 8-bit European characters, the element is
1782 stored in the top table. */
1783 val
= XCHAR_TABLE (array
)->contents
[idxval
];
1785 val
= XCHAR_TABLE (array
)->defalt
;
1786 while (NILP (val
)) /* Follow parents until we find some value. */
1788 array
= XCHAR_TABLE (array
)->parent
;
1791 val
= XCHAR_TABLE (array
)->contents
[idxval
];
1793 val
= XCHAR_TABLE (array
)->defalt
;
1800 Lisp_Object sub_table
;
1802 SPLIT_CHAR (idxval
, code
[0], code
[1], code
[2]);
1803 if (code
[1] < 32) code
[1] = -1;
1804 else if (code
[2] < 32) code
[2] = -1;
1806 /* Here, the possible range of CODE[0] (== charset ID) is
1807 128..MAX_CHARSET. Since the top level char table contains
1808 data for multibyte characters after 256th element, we must
1809 increment CODE[0] by 128 to get a correct index. */
1811 code
[3] = -1; /* anchor */
1813 try_parent_char_table
:
1815 for (i
= 0; code
[i
] >= 0; i
++)
1817 val
= XCHAR_TABLE (sub_table
)->contents
[code
[i
]];
1818 if (SUB_CHAR_TABLE_P (val
))
1823 val
= XCHAR_TABLE (sub_table
)->defalt
;
1826 array
= XCHAR_TABLE (array
)->parent
;
1828 goto try_parent_char_table
;
1833 /* Here, VAL is a sub char table. We try the default value
1835 val
= XCHAR_TABLE (val
)->defalt
;
1838 array
= XCHAR_TABLE (array
)->parent
;
1840 goto try_parent_char_table
;
1848 if (VECTORP (array
))
1849 size
= XVECTOR (array
)->size
;
1850 else if (COMPILEDP (array
))
1851 size
= XVECTOR (array
)->size
& PSEUDOVECTOR_SIZE_MASK
;
1853 wrong_type_argument (Qarrayp
, array
);
1855 if (idxval
< 0 || idxval
>= size
)
1856 args_out_of_range (array
, idx
);
1857 return XVECTOR (array
)->contents
[idxval
];
1861 /* Don't use alloca for relocating string data larger than this, lest
1862 we overflow their stack. The value is the same as what used in
1863 fns.c for base64 handling. */
1864 #define MAX_ALLOCA 16*1024
1866 DEFUN ("aset", Faset
, Saset
, 3, 3, 0,
1867 "Store into the element of ARRAY at index IDX the value NEWELT.\n\
1868 ARRAY may be a vector, a string, a char-table or a bool-vector.\n\
1870 (array
, idx
, newelt
)
1871 register Lisp_Object array
;
1872 Lisp_Object idx
, newelt
;
1874 register int idxval
;
1876 CHECK_NUMBER (idx
, 1);
1877 idxval
= XINT (idx
);
1878 if (!VECTORP (array
) && !STRINGP (array
) && !BOOL_VECTOR_P (array
)
1879 && ! CHAR_TABLE_P (array
))
1880 array
= wrong_type_argument (Qarrayp
, array
);
1881 CHECK_IMPURE (array
);
1883 if (VECTORP (array
))
1885 if (idxval
< 0 || idxval
>= XVECTOR (array
)->size
)
1886 args_out_of_range (array
, idx
);
1887 XVECTOR (array
)->contents
[idxval
] = newelt
;
1889 else if (BOOL_VECTOR_P (array
))
1893 if (idxval
< 0 || idxval
>= XBOOL_VECTOR (array
)->size
)
1894 args_out_of_range (array
, idx
);
1896 val
= (unsigned char) XBOOL_VECTOR (array
)->data
[idxval
/ BITS_PER_CHAR
];
1898 if (! NILP (newelt
))
1899 val
|= 1 << (idxval
% BITS_PER_CHAR
);
1901 val
&= ~(1 << (idxval
% BITS_PER_CHAR
));
1902 XBOOL_VECTOR (array
)->data
[idxval
/ BITS_PER_CHAR
] = val
;
1904 else if (CHAR_TABLE_P (array
))
1907 args_out_of_range (array
, idx
);
1908 if (idxval
< CHAR_TABLE_ORDINARY_SLOTS
)
1909 XCHAR_TABLE (array
)->contents
[idxval
] = newelt
;
1915 SPLIT_CHAR (idxval
, code
[0], code
[1], code
[2]);
1916 if (code
[1] < 32) code
[1] = -1;
1917 else if (code
[2] < 32) code
[2] = -1;
1919 /* See the comment of the corresponding part in Faref. */
1921 code
[3] = -1; /* anchor */
1922 for (i
= 0; code
[i
+ 1] >= 0; i
++)
1924 val
= XCHAR_TABLE (array
)->contents
[code
[i
]];
1925 if (SUB_CHAR_TABLE_P (val
))
1931 /* VAL is a leaf. Create a sub char table with the
1932 default value VAL or XCHAR_TABLE (array)->defalt
1933 and look into it. */
1935 temp
= make_sub_char_table (NILP (val
)
1936 ? XCHAR_TABLE (array
)->defalt
1938 XCHAR_TABLE (array
)->contents
[code
[i
]] = temp
;
1942 XCHAR_TABLE (array
)->contents
[code
[i
]] = newelt
;
1945 else if (STRING_MULTIBYTE (array
))
1947 int idxval_byte
, prev_bytes
, new_bytes
;
1948 unsigned char workbuf
[MAX_MULTIBYTE_LENGTH
], *p0
= workbuf
, *p1
;
1950 if (idxval
< 0 || idxval
>= XSTRING (array
)->size
)
1951 args_out_of_range (array
, idx
);
1952 CHECK_NUMBER (newelt
, 2);
1954 idxval_byte
= string_char_to_byte (array
, idxval
);
1955 p1
= &XSTRING (array
)->data
[idxval_byte
];
1956 PARSE_MULTIBYTE_SEQ (p1
, nbytes
- idxval_byte
, prev_bytes
);
1957 new_bytes
= CHAR_STRING (XINT (newelt
), p0
);
1958 if (prev_bytes
!= new_bytes
)
1960 /* We must relocate the string data. */
1961 int nchars
= XSTRING (array
)->size
;
1962 int nbytes
= STRING_BYTES (XSTRING (array
));
1965 str
= (nbytes
<= MAX_ALLOCA
1966 ? (unsigned char *) alloca (nbytes
)
1967 : (unsigned char *) xmalloc (nbytes
));
1968 bcopy (XSTRING (array
)->data
, str
, nbytes
);
1969 allocate_string_data (XSTRING (array
), nchars
,
1970 nbytes
+ new_bytes
- prev_bytes
);
1971 bcopy (str
, XSTRING (array
)->data
, idxval_byte
);
1972 p1
= XSTRING (array
)->data
+ idxval_byte
;
1973 bcopy (str
+ idxval_byte
+ prev_bytes
, p1
+ new_bytes
,
1974 nbytes
- (idxval_byte
+ prev_bytes
));
1975 if (nbytes
> MAX_ALLOCA
)
1977 clear_string_char_byte_cache ();
1984 if (idxval
< 0 || idxval
>= XSTRING (array
)->size
)
1985 args_out_of_range (array
, idx
);
1986 CHECK_NUMBER (newelt
, 2);
1988 if (XINT (newelt
) < 0 || SINGLE_BYTE_CHAR_P (XINT (newelt
)))
1989 XSTRING (array
)->data
[idxval
] = XINT (newelt
);
1992 /* We must relocate the string data while converting it to
1994 int idxval_byte
, prev_bytes
, new_bytes
;
1995 unsigned char workbuf
[MAX_MULTIBYTE_LENGTH
], *p0
= workbuf
, *p1
;
1996 unsigned char *origstr
= XSTRING (array
)->data
, *str
;
1999 nchars
= XSTRING (array
)->size
;
2000 nbytes
= idxval_byte
= count_size_as_multibyte (origstr
, idxval
);
2001 nbytes
+= count_size_as_multibyte (origstr
+ idxval
,
2003 str
= (nbytes
<= MAX_ALLOCA
2004 ? (unsigned char *) alloca (nbytes
)
2005 : (unsigned char *) xmalloc (nbytes
));
2006 copy_text (XSTRING (array
)->data
, str
, nchars
, 0, 1);
2007 PARSE_MULTIBYTE_SEQ (str
+ idxval_byte
, nbytes
- idxval_byte
,
2009 new_bytes
= CHAR_STRING (XINT (newelt
), p0
);
2010 allocate_string_data (XSTRING (array
), nchars
,
2011 nbytes
+ new_bytes
- prev_bytes
);
2012 bcopy (str
, XSTRING (array
)->data
, idxval_byte
);
2013 p1
= XSTRING (array
)->data
+ idxval_byte
;
2016 bcopy (str
+ idxval_byte
+ prev_bytes
, p1
,
2017 nbytes
- (idxval_byte
+ prev_bytes
));
2018 if (nbytes
> MAX_ALLOCA
)
2020 clear_string_char_byte_cache ();
2027 /* Arithmetic functions */
2029 enum comparison
{ equal
, notequal
, less
, grtr
, less_or_equal
, grtr_or_equal
};
2032 arithcompare (num1
, num2
, comparison
)
2033 Lisp_Object num1
, num2
;
2034 enum comparison comparison
;
2036 double f1
= 0, f2
= 0;
2039 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1
, 0);
2040 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2
, 0);
2042 if (FLOATP (num1
) || FLOATP (num2
))
2045 f1
= (FLOATP (num1
)) ? XFLOAT_DATA (num1
) : XINT (num1
);
2046 f2
= (FLOATP (num2
)) ? XFLOAT_DATA (num2
) : XINT (num2
);
2052 if (floatp
? f1
== f2
: XINT (num1
) == XINT (num2
))
2057 if (floatp
? f1
!= f2
: XINT (num1
) != XINT (num2
))
2062 if (floatp
? f1
< f2
: XINT (num1
) < XINT (num2
))
2067 if (floatp
? f1
<= f2
: XINT (num1
) <= XINT (num2
))
2072 if (floatp
? f1
> f2
: XINT (num1
) > XINT (num2
))
2077 if (floatp
? f1
>= f2
: XINT (num1
) >= XINT (num2
))
2086 DEFUN ("=", Feqlsign
, Seqlsign
, 2, 2, 0,
2087 "Return t if two args, both numbers or markers, are equal.")
2089 register Lisp_Object num1
, num2
;
2091 return arithcompare (num1
, num2
, equal
);
2094 DEFUN ("<", Flss
, Slss
, 2, 2, 0,
2095 "Return t if first arg is less than second arg. Both must be numbers or markers.")
2097 register Lisp_Object num1
, num2
;
2099 return arithcompare (num1
, num2
, less
);
2102 DEFUN (">", Fgtr
, Sgtr
, 2, 2, 0,
2103 "Return t if first arg is greater than second arg. Both must be numbers or markers.")
2105 register Lisp_Object num1
, num2
;
2107 return arithcompare (num1
, num2
, grtr
);
2110 DEFUN ("<=", Fleq
, Sleq
, 2, 2, 0,
2111 "Return t if first arg is less than or equal to second arg.\n\
2112 Both must be numbers or markers.")
2114 register Lisp_Object num1
, num2
;
2116 return arithcompare (num1
, num2
, less_or_equal
);
2119 DEFUN (">=", Fgeq
, Sgeq
, 2, 2, 0,
2120 "Return t if first arg is greater than or equal to second arg.\n\
2121 Both must be numbers or markers.")
2123 register Lisp_Object num1
, num2
;
2125 return arithcompare (num1
, num2
, grtr_or_equal
);
2128 DEFUN ("/=", Fneq
, Sneq
, 2, 2, 0,
2129 "Return t if first arg is not equal to second arg. Both must be numbers or markers.")
2131 register Lisp_Object num1
, num2
;
2133 return arithcompare (num1
, num2
, notequal
);
2136 DEFUN ("zerop", Fzerop
, Szerop
, 1, 1, 0, "Return t if NUMBER is zero.")
2138 register Lisp_Object number
;
2140 CHECK_NUMBER_OR_FLOAT (number
, 0);
2142 if (FLOATP (number
))
2144 if (XFLOAT_DATA (number
) == 0.0)
2154 /* Convert between long values and pairs of Lisp integers. */
2160 unsigned int top
= i
>> 16;
2161 unsigned int bot
= i
& 0xFFFF;
2163 return make_number (bot
);
2164 if (top
== (unsigned long)-1 >> 16)
2165 return Fcons (make_number (-1), make_number (bot
));
2166 return Fcons (make_number (top
), make_number (bot
));
2173 Lisp_Object top
, bot
;
2180 return ((XINT (top
) << 16) | XINT (bot
));
2183 DEFUN ("number-to-string", Fnumber_to_string
, Snumber_to_string
, 1, 1, 0,
2184 "Convert NUMBER to a string by printing it in decimal.\n\
2185 Uses a minus sign if negative.\n\
2186 NUMBER may be an integer or a floating point number.")
2190 char buffer
[VALBITS
];
2192 CHECK_NUMBER_OR_FLOAT (number
, 0);
2194 if (FLOATP (number
))
2196 char pigbuf
[350]; /* see comments in float_to_string */
2198 float_to_string (pigbuf
, XFLOAT_DATA (number
));
2199 return build_string (pigbuf
);
2202 if (sizeof (int) == sizeof (EMACS_INT
))
2203 sprintf (buffer
, "%d", XINT (number
));
2204 else if (sizeof (long) == sizeof (EMACS_INT
))
2205 sprintf (buffer
, "%ld", (long) XINT (number
));
2208 return build_string (buffer
);
2212 digit_to_number (character
, base
)
2213 int character
, base
;
2217 if (character
>= '0' && character
<= '9')
2218 digit
= character
- '0';
2219 else if (character
>= 'a' && character
<= 'z')
2220 digit
= character
- 'a' + 10;
2221 else if (character
>= 'A' && character
<= 'Z')
2222 digit
= character
- 'A' + 10;
2232 DEFUN ("string-to-number", Fstring_to_number
, Sstring_to_number
, 1, 2, 0,
2233 "Convert STRING to a number by parsing it as a decimal number.\n\
2234 This parses both integers and floating point numbers.\n\
2235 It ignores leading spaces and tabs.\n\
2237 If BASE, interpret STRING as a number in that base. If BASE isn't\n\
2238 present, base 10 is used. BASE must be between 2 and 16 (inclusive).\n\
2239 If the base used is not 10, floating point is not recognized.")
2241 register Lisp_Object string
, base
;
2243 register unsigned char *p
;
2248 CHECK_STRING (string
, 0);
2254 CHECK_NUMBER (base
, 1);
2256 if (b
< 2 || b
> 16)
2257 Fsignal (Qargs_out_of_range
, Fcons (base
, Qnil
));
2260 /* Skip any whitespace at the front of the number. Some versions of
2261 atoi do this anyway, so we might as well make Emacs lisp consistent. */
2262 p
= XSTRING (string
)->data
;
2263 while (*p
== ' ' || *p
== '\t')
2274 if (isfloat_string (p
) && b
== 10)
2275 val
= make_float (sign
* atof (p
));
2282 int digit
= digit_to_number (*p
++, b
);
2288 if (v
> (EMACS_UINT
) (VALMASK
>> 1))
2289 val
= make_float (sign
* v
);
2291 val
= make_number (sign
* (int) v
);
2311 static Lisp_Object float_arith_driver
P_ ((double, int, enum arithop
,
2312 int, Lisp_Object
*));
2313 extern Lisp_Object
fmod_float ();
2316 arith_driver (code
, nargs
, args
)
2319 register Lisp_Object
*args
;
2321 register Lisp_Object val
;
2322 register int argnum
;
2323 register EMACS_INT accum
= 0;
2324 register EMACS_INT next
;
2326 switch (SWITCH_ENUM_CAST (code
))
2344 for (argnum
= 0; argnum
< nargs
; argnum
++)
2346 /* Using args[argnum] as argument to CHECK_NUMBER_... */
2348 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
, argnum
);
2351 return float_arith_driver ((double) accum
, argnum
, code
,
2354 next
= XINT (args
[argnum
]);
2355 switch (SWITCH_ENUM_CAST (code
))
2361 accum
= argnum
? accum
- next
: nargs
== 1 ? - next
: next
;
2372 Fsignal (Qarith_error
, Qnil
);
2386 if (!argnum
|| next
> accum
)
2390 if (!argnum
|| next
< accum
)
2396 XSETINT (val
, accum
);
2401 #define isnan(x) ((x) != (x))
2404 float_arith_driver (accum
, argnum
, code
, nargs
, args
)
2406 register int argnum
;
2409 register Lisp_Object
*args
;
2411 register Lisp_Object val
;
2414 for (; argnum
< nargs
; argnum
++)
2416 val
= args
[argnum
]; /* using args[argnum] as argument to CHECK_NUMBER_... */
2417 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
, argnum
);
2421 next
= XFLOAT_DATA (val
);
2425 args
[argnum
] = val
; /* runs into a compiler bug. */
2426 next
= XINT (args
[argnum
]);
2428 switch (SWITCH_ENUM_CAST (code
))
2434 accum
= argnum
? accum
- next
: nargs
== 1 ? - next
: next
;
2444 if (! IEEE_FLOATING_POINT
&& next
== 0)
2445 Fsignal (Qarith_error
, Qnil
);
2452 return wrong_type_argument (Qinteger_or_marker_p
, val
);
2454 if (!argnum
|| isnan (next
) || next
> accum
)
2458 if (!argnum
|| isnan (next
) || next
< accum
)
2464 return make_float (accum
);
2468 DEFUN ("+", Fplus
, Splus
, 0, MANY
, 0,
2469 "Return sum of any number of arguments, which are numbers or markers.")
2474 return arith_driver (Aadd
, nargs
, args
);
2477 DEFUN ("-", Fminus
, Sminus
, 0, MANY
, 0,
2478 "Negate number or subtract numbers or markers.\n\
2479 With one arg, negates it. With more than one arg,\n\
2480 subtracts all but the first from the first.")
2485 return arith_driver (Asub
, nargs
, args
);
2488 DEFUN ("*", Ftimes
, Stimes
, 0, MANY
, 0,
2489 "Returns product of any number of arguments, which are numbers or markers.")
2494 return arith_driver (Amult
, nargs
, args
);
2497 DEFUN ("/", Fquo
, Squo
, 2, MANY
, 0,
2498 "Returns first argument divided by all the remaining arguments.\n\
2499 The arguments must be numbers or markers.")
2504 return arith_driver (Adiv
, nargs
, args
);
2507 DEFUN ("%", Frem
, Srem
, 2, 2, 0,
2508 "Returns remainder of X divided by Y.\n\
2509 Both must be integers or markers.")
2511 register Lisp_Object x
, y
;
2515 CHECK_NUMBER_COERCE_MARKER (x
, 0);
2516 CHECK_NUMBER_COERCE_MARKER (y
, 1);
2518 if (XFASTINT (y
) == 0)
2519 Fsignal (Qarith_error
, Qnil
);
2521 XSETINT (val
, XINT (x
) % XINT (y
));
2535 /* If the magnitude of the result exceeds that of the divisor, or
2536 the sign of the result does not agree with that of the dividend,
2537 iterate with the reduced value. This does not yield a
2538 particularly accurate result, but at least it will be in the
2539 range promised by fmod. */
2541 r
-= f2
* floor (r
/ f2
);
2542 while (f2
<= (r
< 0 ? -r
: r
) || ((r
< 0) != (f1
< 0) && ! isnan (r
)));
2546 #endif /* ! HAVE_FMOD */
2548 DEFUN ("mod", Fmod
, Smod
, 2, 2, 0,
2549 "Returns X modulo Y.\n\
2550 The result falls between zero (inclusive) and Y (exclusive).\n\
2551 Both X and Y must be numbers or markers.")
2553 register Lisp_Object x
, y
;
2558 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x
, 0);
2559 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y
, 1);
2561 if (FLOATP (x
) || FLOATP (y
))
2562 return fmod_float (x
, y
);
2568 Fsignal (Qarith_error
, Qnil
);
2572 /* If the "remainder" comes out with the wrong sign, fix it. */
2573 if (i2
< 0 ? i1
> 0 : i1
< 0)
2580 DEFUN ("max", Fmax
, Smax
, 1, MANY
, 0,
2581 "Return largest of all the arguments (which must be numbers or markers).\n\
2582 The value is always a number; markers are converted to numbers.")
2587 return arith_driver (Amax
, nargs
, args
);
2590 DEFUN ("min", Fmin
, Smin
, 1, MANY
, 0,
2591 "Return smallest of all the arguments (which must be numbers or markers).\n\
2592 The value is always a number; markers are converted to numbers.")
2597 return arith_driver (Amin
, nargs
, args
);
2600 DEFUN ("logand", Flogand
, Slogand
, 0, MANY
, 0,
2601 "Return bitwise-and of all the arguments.\n\
2602 Arguments may be integers, or markers converted to integers.")
2607 return arith_driver (Alogand
, nargs
, args
);
2610 DEFUN ("logior", Flogior
, Slogior
, 0, MANY
, 0,
2611 "Return bitwise-or of all the arguments.\n\
2612 Arguments may be integers, or markers converted to integers.")
2617 return arith_driver (Alogior
, nargs
, args
);
2620 DEFUN ("logxor", Flogxor
, Slogxor
, 0, MANY
, 0,
2621 "Return bitwise-exclusive-or of all the arguments.\n\
2622 Arguments may be integers, or markers converted to integers.")
2627 return arith_driver (Alogxor
, nargs
, args
);
2630 DEFUN ("ash", Fash
, Sash
, 2, 2, 0,
2631 "Return VALUE with its bits shifted left by COUNT.\n\
2632 If COUNT is negative, shifting is actually to the right.\n\
2633 In this case, the sign bit is duplicated.")
2635 register Lisp_Object value
, count
;
2637 register Lisp_Object val
;
2639 CHECK_NUMBER (value
, 0);
2640 CHECK_NUMBER (count
, 1);
2642 if (XINT (count
) >= BITS_PER_EMACS_INT
)
2644 else if (XINT (count
) > 0)
2645 XSETINT (val
, XINT (value
) << XFASTINT (count
));
2646 else if (XINT (count
) <= -BITS_PER_EMACS_INT
)
2647 XSETINT (val
, XINT (value
) < 0 ? -1 : 0);
2649 XSETINT (val
, XINT (value
) >> -XINT (count
));
2653 DEFUN ("lsh", Flsh
, Slsh
, 2, 2, 0,
2654 "Return VALUE with its bits shifted left by COUNT.\n\
2655 If COUNT is negative, shifting is actually to the right.\n\
2656 In this case, zeros are shifted in on the left.")
2658 register Lisp_Object value
, count
;
2660 register Lisp_Object val
;
2662 CHECK_NUMBER (value
, 0);
2663 CHECK_NUMBER (count
, 1);
2665 if (XINT (count
) >= BITS_PER_EMACS_INT
)
2667 else if (XINT (count
) > 0)
2668 XSETINT (val
, (EMACS_UINT
) XUINT (value
) << XFASTINT (count
));
2669 else if (XINT (count
) <= -BITS_PER_EMACS_INT
)
2672 XSETINT (val
, (EMACS_UINT
) XUINT (value
) >> -XINT (count
));
2676 DEFUN ("1+", Fadd1
, Sadd1
, 1, 1, 0,
2677 "Return NUMBER plus one. NUMBER may be a number or a marker.\n\
2678 Markers are converted to integers.")
2680 register Lisp_Object number
;
2682 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
, 0);
2684 if (FLOATP (number
))
2685 return (make_float (1.0 + XFLOAT_DATA (number
)));
2687 XSETINT (number
, XINT (number
) + 1);
2691 DEFUN ("1-", Fsub1
, Ssub1
, 1, 1, 0,
2692 "Return NUMBER minus one. NUMBER may be a number or a marker.\n\
2693 Markers are converted to integers.")
2695 register Lisp_Object number
;
2697 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
, 0);
2699 if (FLOATP (number
))
2700 return (make_float (-1.0 + XFLOAT_DATA (number
)));
2702 XSETINT (number
, XINT (number
) - 1);
2706 DEFUN ("lognot", Flognot
, Slognot
, 1, 1, 0,
2707 "Return the bitwise complement of NUMBER. NUMBER must be an integer.")
2709 register Lisp_Object number
;
2711 CHECK_NUMBER (number
, 0);
2712 XSETINT (number
, ~XINT (number
));
2719 Lisp_Object error_tail
, arith_tail
;
2721 Qquote
= intern ("quote");
2722 Qlambda
= intern ("lambda");
2723 Qsubr
= intern ("subr");
2724 Qerror_conditions
= intern ("error-conditions");
2725 Qerror_message
= intern ("error-message");
2726 Qtop_level
= intern ("top-level");
2728 Qerror
= intern ("error");
2729 Qquit
= intern ("quit");
2730 Qwrong_type_argument
= intern ("wrong-type-argument");
2731 Qargs_out_of_range
= intern ("args-out-of-range");
2732 Qvoid_function
= intern ("void-function");
2733 Qcyclic_function_indirection
= intern ("cyclic-function-indirection");
2734 Qvoid_variable
= intern ("void-variable");
2735 Qsetting_constant
= intern ("setting-constant");
2736 Qinvalid_read_syntax
= intern ("invalid-read-syntax");
2738 Qinvalid_function
= intern ("invalid-function");
2739 Qwrong_number_of_arguments
= intern ("wrong-number-of-arguments");
2740 Qno_catch
= intern ("no-catch");
2741 Qend_of_file
= intern ("end-of-file");
2742 Qarith_error
= intern ("arith-error");
2743 Qbeginning_of_buffer
= intern ("beginning-of-buffer");
2744 Qend_of_buffer
= intern ("end-of-buffer");
2745 Qbuffer_read_only
= intern ("buffer-read-only");
2746 Qtext_read_only
= intern ("text-read-only");
2747 Qmark_inactive
= intern ("mark-inactive");
2749 Qlistp
= intern ("listp");
2750 Qconsp
= intern ("consp");
2751 Qsymbolp
= intern ("symbolp");
2752 Qkeywordp
= intern ("keywordp");
2753 Qintegerp
= intern ("integerp");
2754 Qnatnump
= intern ("natnump");
2755 Qwholenump
= intern ("wholenump");
2756 Qstringp
= intern ("stringp");
2757 Qarrayp
= intern ("arrayp");
2758 Qsequencep
= intern ("sequencep");
2759 Qbufferp
= intern ("bufferp");
2760 Qvectorp
= intern ("vectorp");
2761 Qchar_or_string_p
= intern ("char-or-string-p");
2762 Qmarkerp
= intern ("markerp");
2763 Qbuffer_or_string_p
= intern ("buffer-or-string-p");
2764 Qinteger_or_marker_p
= intern ("integer-or-marker-p");
2765 Qboundp
= intern ("boundp");
2766 Qfboundp
= intern ("fboundp");
2768 Qfloatp
= intern ("floatp");
2769 Qnumberp
= intern ("numberp");
2770 Qnumber_or_marker_p
= intern ("number-or-marker-p");
2772 Qchar_table_p
= intern ("char-table-p");
2773 Qvector_or_char_table_p
= intern ("vector-or-char-table-p");
2775 Qsubrp
= intern ("subrp");
2776 Qunevalled
= intern ("unevalled");
2777 Qmany
= intern ("many");
2779 Qcdr
= intern ("cdr");
2781 /* Handle automatic advice activation */
2782 Qad_advice_info
= intern ("ad-advice-info");
2783 Qad_activate_internal
= intern ("ad-activate-internal");
2785 error_tail
= Fcons (Qerror
, Qnil
);
2787 /* ERROR is used as a signaler for random errors for which nothing else is right */
2789 Fput (Qerror
, Qerror_conditions
,
2791 Fput (Qerror
, Qerror_message
,
2792 build_string ("error"));
2794 Fput (Qquit
, Qerror_conditions
,
2795 Fcons (Qquit
, Qnil
));
2796 Fput (Qquit
, Qerror_message
,
2797 build_string ("Quit"));
2799 Fput (Qwrong_type_argument
, Qerror_conditions
,
2800 Fcons (Qwrong_type_argument
, error_tail
));
2801 Fput (Qwrong_type_argument
, Qerror_message
,
2802 build_string ("Wrong type argument"));
2804 Fput (Qargs_out_of_range
, Qerror_conditions
,
2805 Fcons (Qargs_out_of_range
, error_tail
));
2806 Fput (Qargs_out_of_range
, Qerror_message
,
2807 build_string ("Args out of range"));
2809 Fput (Qvoid_function
, Qerror_conditions
,
2810 Fcons (Qvoid_function
, error_tail
));
2811 Fput (Qvoid_function
, Qerror_message
,
2812 build_string ("Symbol's function definition is void"));
2814 Fput (Qcyclic_function_indirection
, Qerror_conditions
,
2815 Fcons (Qcyclic_function_indirection
, error_tail
));
2816 Fput (Qcyclic_function_indirection
, Qerror_message
,
2817 build_string ("Symbol's chain of function indirections contains a loop"));
2819 Fput (Qvoid_variable
, Qerror_conditions
,
2820 Fcons (Qvoid_variable
, error_tail
));
2821 Fput (Qvoid_variable
, Qerror_message
,
2822 build_string ("Symbol's value as variable is void"));
2824 Fput (Qsetting_constant
, Qerror_conditions
,
2825 Fcons (Qsetting_constant
, error_tail
));
2826 Fput (Qsetting_constant
, Qerror_message
,
2827 build_string ("Attempt to set a constant symbol"));
2829 Fput (Qinvalid_read_syntax
, Qerror_conditions
,
2830 Fcons (Qinvalid_read_syntax
, error_tail
));
2831 Fput (Qinvalid_read_syntax
, Qerror_message
,
2832 build_string ("Invalid read syntax"));
2834 Fput (Qinvalid_function
, Qerror_conditions
,
2835 Fcons (Qinvalid_function
, error_tail
));
2836 Fput (Qinvalid_function
, Qerror_message
,
2837 build_string ("Invalid function"));
2839 Fput (Qwrong_number_of_arguments
, Qerror_conditions
,
2840 Fcons (Qwrong_number_of_arguments
, error_tail
));
2841 Fput (Qwrong_number_of_arguments
, Qerror_message
,
2842 build_string ("Wrong number of arguments"));
2844 Fput (Qno_catch
, Qerror_conditions
,
2845 Fcons (Qno_catch
, error_tail
));
2846 Fput (Qno_catch
, Qerror_message
,
2847 build_string ("No catch for tag"));
2849 Fput (Qend_of_file
, Qerror_conditions
,
2850 Fcons (Qend_of_file
, error_tail
));
2851 Fput (Qend_of_file
, Qerror_message
,
2852 build_string ("End of file during parsing"));
2854 arith_tail
= Fcons (Qarith_error
, error_tail
);
2855 Fput (Qarith_error
, Qerror_conditions
,
2857 Fput (Qarith_error
, Qerror_message
,
2858 build_string ("Arithmetic error"));
2860 Fput (Qbeginning_of_buffer
, Qerror_conditions
,
2861 Fcons (Qbeginning_of_buffer
, error_tail
));
2862 Fput (Qbeginning_of_buffer
, Qerror_message
,
2863 build_string ("Beginning of buffer"));
2865 Fput (Qend_of_buffer
, Qerror_conditions
,
2866 Fcons (Qend_of_buffer
, error_tail
));
2867 Fput (Qend_of_buffer
, Qerror_message
,
2868 build_string ("End of buffer"));
2870 Fput (Qbuffer_read_only
, Qerror_conditions
,
2871 Fcons (Qbuffer_read_only
, error_tail
));
2872 Fput (Qbuffer_read_only
, Qerror_message
,
2873 build_string ("Buffer is read-only"));
2875 Fput (Qtext_read_only
, Qerror_conditions
,
2876 Fcons (Qtext_read_only
, error_tail
));
2877 Fput (Qtext_read_only
, Qerror_message
,
2878 build_string ("Text is read-only"));
2880 Qrange_error
= intern ("range-error");
2881 Qdomain_error
= intern ("domain-error");
2882 Qsingularity_error
= intern ("singularity-error");
2883 Qoverflow_error
= intern ("overflow-error");
2884 Qunderflow_error
= intern ("underflow-error");
2886 Fput (Qdomain_error
, Qerror_conditions
,
2887 Fcons (Qdomain_error
, arith_tail
));
2888 Fput (Qdomain_error
, Qerror_message
,
2889 build_string ("Arithmetic domain error"));
2891 Fput (Qrange_error
, Qerror_conditions
,
2892 Fcons (Qrange_error
, arith_tail
));
2893 Fput (Qrange_error
, Qerror_message
,
2894 build_string ("Arithmetic range error"));
2896 Fput (Qsingularity_error
, Qerror_conditions
,
2897 Fcons (Qsingularity_error
, Fcons (Qdomain_error
, arith_tail
)));
2898 Fput (Qsingularity_error
, Qerror_message
,
2899 build_string ("Arithmetic singularity error"));
2901 Fput (Qoverflow_error
, Qerror_conditions
,
2902 Fcons (Qoverflow_error
, Fcons (Qdomain_error
, arith_tail
)));
2903 Fput (Qoverflow_error
, Qerror_message
,
2904 build_string ("Arithmetic overflow error"));
2906 Fput (Qunderflow_error
, Qerror_conditions
,
2907 Fcons (Qunderflow_error
, Fcons (Qdomain_error
, arith_tail
)));
2908 Fput (Qunderflow_error
, Qerror_message
,
2909 build_string ("Arithmetic underflow error"));
2911 staticpro (&Qrange_error
);
2912 staticpro (&Qdomain_error
);
2913 staticpro (&Qsingularity_error
);
2914 staticpro (&Qoverflow_error
);
2915 staticpro (&Qunderflow_error
);
2919 staticpro (&Qquote
);
2920 staticpro (&Qlambda
);
2922 staticpro (&Qunbound
);
2923 staticpro (&Qerror_conditions
);
2924 staticpro (&Qerror_message
);
2925 staticpro (&Qtop_level
);
2927 staticpro (&Qerror
);
2929 staticpro (&Qwrong_type_argument
);
2930 staticpro (&Qargs_out_of_range
);
2931 staticpro (&Qvoid_function
);
2932 staticpro (&Qcyclic_function_indirection
);
2933 staticpro (&Qvoid_variable
);
2934 staticpro (&Qsetting_constant
);
2935 staticpro (&Qinvalid_read_syntax
);
2936 staticpro (&Qwrong_number_of_arguments
);
2937 staticpro (&Qinvalid_function
);
2938 staticpro (&Qno_catch
);
2939 staticpro (&Qend_of_file
);
2940 staticpro (&Qarith_error
);
2941 staticpro (&Qbeginning_of_buffer
);
2942 staticpro (&Qend_of_buffer
);
2943 staticpro (&Qbuffer_read_only
);
2944 staticpro (&Qtext_read_only
);
2945 staticpro (&Qmark_inactive
);
2947 staticpro (&Qlistp
);
2948 staticpro (&Qconsp
);
2949 staticpro (&Qsymbolp
);
2950 staticpro (&Qkeywordp
);
2951 staticpro (&Qintegerp
);
2952 staticpro (&Qnatnump
);
2953 staticpro (&Qwholenump
);
2954 staticpro (&Qstringp
);
2955 staticpro (&Qarrayp
);
2956 staticpro (&Qsequencep
);
2957 staticpro (&Qbufferp
);
2958 staticpro (&Qvectorp
);
2959 staticpro (&Qchar_or_string_p
);
2960 staticpro (&Qmarkerp
);
2961 staticpro (&Qbuffer_or_string_p
);
2962 staticpro (&Qinteger_or_marker_p
);
2963 staticpro (&Qfloatp
);
2964 staticpro (&Qnumberp
);
2965 staticpro (&Qnumber_or_marker_p
);
2966 staticpro (&Qchar_table_p
);
2967 staticpro (&Qvector_or_char_table_p
);
2968 staticpro (&Qsubrp
);
2970 staticpro (&Qunevalled
);
2972 staticpro (&Qboundp
);
2973 staticpro (&Qfboundp
);
2975 staticpro (&Qad_advice_info
);
2976 staticpro (&Qad_activate_internal
);
2978 /* Types that type-of returns. */
2979 Qinteger
= intern ("integer");
2980 Qsymbol
= intern ("symbol");
2981 Qstring
= intern ("string");
2982 Qcons
= intern ("cons");
2983 Qmarker
= intern ("marker");
2984 Qoverlay
= intern ("overlay");
2985 Qfloat
= intern ("float");
2986 Qwindow_configuration
= intern ("window-configuration");
2987 Qprocess
= intern ("process");
2988 Qwindow
= intern ("window");
2989 /* Qsubr = intern ("subr"); */
2990 Qcompiled_function
= intern ("compiled-function");
2991 Qbuffer
= intern ("buffer");
2992 Qframe
= intern ("frame");
2993 Qvector
= intern ("vector");
2994 Qchar_table
= intern ("char-table");
2995 Qbool_vector
= intern ("bool-vector");
2996 Qhash_table
= intern ("hash-table");
2998 staticpro (&Qinteger
);
2999 staticpro (&Qsymbol
);
3000 staticpro (&Qstring
);
3002 staticpro (&Qmarker
);
3003 staticpro (&Qoverlay
);
3004 staticpro (&Qfloat
);
3005 staticpro (&Qwindow_configuration
);
3006 staticpro (&Qprocess
);
3007 staticpro (&Qwindow
);
3008 /* staticpro (&Qsubr); */
3009 staticpro (&Qcompiled_function
);
3010 staticpro (&Qbuffer
);
3011 staticpro (&Qframe
);
3012 staticpro (&Qvector
);
3013 staticpro (&Qchar_table
);
3014 staticpro (&Qbool_vector
);
3015 staticpro (&Qhash_table
);
3017 defsubr (&Ssubr_interactive_form
);
3020 defsubr (&Stype_of
);
3025 defsubr (&Sintegerp
);
3026 defsubr (&Sinteger_or_marker_p
);
3027 defsubr (&Snumberp
);
3028 defsubr (&Snumber_or_marker_p
);
3030 defsubr (&Snatnump
);
3031 defsubr (&Ssymbolp
);
3032 defsubr (&Skeywordp
);
3033 defsubr (&Sstringp
);
3034 defsubr (&Smultibyte_string_p
);
3035 defsubr (&Svectorp
);
3036 defsubr (&Schar_table_p
);
3037 defsubr (&Svector_or_char_table_p
);
3038 defsubr (&Sbool_vector_p
);
3040 defsubr (&Ssequencep
);
3041 defsubr (&Sbufferp
);
3042 defsubr (&Smarkerp
);
3044 defsubr (&Sbyte_code_function_p
);
3045 defsubr (&Schar_or_string_p
);
3048 defsubr (&Scar_safe
);
3049 defsubr (&Scdr_safe
);
3052 defsubr (&Ssymbol_function
);
3053 defsubr (&Sindirect_function
);
3054 defsubr (&Ssymbol_plist
);
3055 defsubr (&Ssymbol_name
);
3056 defsubr (&Smakunbound
);
3057 defsubr (&Sfmakunbound
);
3059 defsubr (&Sfboundp
);
3061 defsubr (&Sdefalias
);
3062 defsubr (&Ssetplist
);
3063 defsubr (&Ssymbol_value
);
3065 defsubr (&Sdefault_boundp
);
3066 defsubr (&Sdefault_value
);
3067 defsubr (&Sset_default
);
3068 defsubr (&Ssetq_default
);
3069 defsubr (&Smake_variable_buffer_local
);
3070 defsubr (&Smake_local_variable
);
3071 defsubr (&Skill_local_variable
);
3072 defsubr (&Smake_variable_frame_local
);
3073 defsubr (&Slocal_variable_p
);
3074 defsubr (&Slocal_variable_if_set_p
);
3077 defsubr (&Snumber_to_string
);
3078 defsubr (&Sstring_to_number
);
3079 defsubr (&Seqlsign
);
3102 defsubr (&Ssubr_arity
);
3104 XSYMBOL (Qwholenump
)->function
= XSYMBOL (Qnatnump
)->function
;
3111 #if defined(USG) && !defined(POSIX_SIGNALS)
3112 /* USG systems forget handlers when they are used;
3113 must reestablish each time */
3114 signal (signo
, arith_error
);
3117 /* VMS systems are like USG. */
3118 signal (signo
, arith_error
);
3122 #else /* not BSD4_1 */
3123 sigsetmask (SIGEMPTYMASK
);
3124 #endif /* not BSD4_1 */
3126 Fsignal (Qarith_error
, Qnil
);
3132 /* Don't do this if just dumping out.
3133 We don't want to call `signal' in this case
3134 so that we don't have trouble with dumping
3135 signal-delivering routines in an inconsistent state. */
3139 #endif /* CANNOT_DUMP */
3140 signal (SIGFPE
, arith_error
);
3143 signal (SIGEMT
, arith_error
);