1 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985, 86, 88, 93, 94, 95 Free Software Foundation, Inc.
4 This file is part of GNU Emacs.
6 GNU Emacs is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Emacs is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Emacs; see the file COPYING. If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
33 #include "syssignal.h"
35 #ifdef LISP_FLOAT_TYPE
41 /* Work around a problem that happens because math.h on hpux 7
42 defines two static variables--which, in Emacs, are not really static,
43 because `static' is defined as nothing. The problem is that they are
44 here, in floatfns.c, and in lread.c.
45 These macros prevent the name conflict. */
46 #if defined (HPUX) && !defined (HPUX8)
47 #define _MAXLDBL data_c_maxldbl
48 #define _NMAXLDBL data_c_nmaxldbl
52 #endif /* LISP_FLOAT_TYPE */
55 extern double atof ();
58 Lisp_Object Qnil
, Qt
, Qquote
, Qlambda
, Qsubr
, Qunbound
;
59 Lisp_Object Qerror_conditions
, Qerror_message
, Qtop_level
;
60 Lisp_Object Qerror
, Qquit
, Qwrong_type_argument
, Qargs_out_of_range
;
61 Lisp_Object Qvoid_variable
, Qvoid_function
, Qcyclic_function_indirection
;
62 Lisp_Object Qsetting_constant
, Qinvalid_read_syntax
;
63 Lisp_Object Qinvalid_function
, Qwrong_number_of_arguments
, Qno_catch
;
64 Lisp_Object Qend_of_file
, Qarith_error
, Qmark_inactive
;
65 Lisp_Object Qbeginning_of_buffer
, Qend_of_buffer
, Qbuffer_read_only
;
66 Lisp_Object Qintegerp
, Qnatnump
, Qwholenump
, Qsymbolp
, Qlistp
, Qconsp
;
67 Lisp_Object Qstringp
, Qarrayp
, Qsequencep
, Qbufferp
;
68 Lisp_Object Qchar_or_string_p
, Qmarkerp
, Qinteger_or_marker_p
, Qvectorp
;
69 Lisp_Object Qbuffer_or_string_p
;
70 Lisp_Object Qboundp
, Qfboundp
;
71 Lisp_Object Qchar_table_p
, Qvector_or_char_table_p
;
74 Lisp_Object Qad_advice_info
, Qad_activate
;
76 Lisp_Object Qrange_error
, Qdomain_error
, Qsingularity_error
;
77 Lisp_Object Qoverflow_error
, Qunderflow_error
;
79 #ifdef LISP_FLOAT_TYPE
81 Lisp_Object Qnumberp
, Qnumber_or_marker_p
;
84 static Lisp_Object Qinteger
, Qsymbol
, Qstring
, Qcons
, Qmarker
, Qoverlay
;
85 static Lisp_Object Qfloat
, Qwindow_configuration
, Qprocess
, Qwindow
;
86 static Lisp_Object Qcompiled_function
, Qbuffer
, Qframe
, Qvector
;
87 static Lisp_Object Qchar_table
, Qbool_vector
;
89 static Lisp_Object
swap_in_symval_forwarding ();
92 wrong_type_argument (predicate
, value
)
93 register Lisp_Object predicate
, value
;
95 register Lisp_Object tem
;
98 if (!EQ (Vmocklisp_arguments
, Qt
))
100 if (STRINGP (value
) &&
101 (EQ (predicate
, Qintegerp
) || EQ (predicate
, Qinteger_or_marker_p
)))
102 return Fstring_to_number (value
);
103 if (INTEGERP (value
) && EQ (predicate
, Qstringp
))
104 return Fnumber_to_string (value
);
107 /* If VALUE is not even a valid Lisp object, abort here
108 where we can get a backtrace showing where it came from. */
109 if ((unsigned int) XGCTYPE (value
) >= Lisp_Type_Limit
)
112 value
= Fsignal (Qwrong_type_argument
, Fcons (predicate
, Fcons (value
, Qnil
)));
113 tem
= call1 (predicate
, value
);
121 error ("Attempt to modify read-only object");
125 args_out_of_range (a1
, a2
)
129 Fsignal (Qargs_out_of_range
, Fcons (a1
, Fcons (a2
, Qnil
)));
133 args_out_of_range_3 (a1
, a2
, a3
)
134 Lisp_Object a1
, a2
, a3
;
137 Fsignal (Qargs_out_of_range
, Fcons (a1
, Fcons (a2
, Fcons (a3
, Qnil
))));
144 register Lisp_Object val
;
149 /* On some machines, XINT needs a temporary location.
150 Here it is, in case it is needed. */
152 int sign_extend_temp
;
154 /* On a few machines, XINT can only be done by calling this. */
157 sign_extend_lisp_int (num
)
160 if (num
& (((EMACS_INT
) 1) << (VALBITS
- 1)))
161 return num
| (((EMACS_INT
) (-1)) << VALBITS
);
163 return num
& ((((EMACS_INT
) 1) << VALBITS
) - 1);
166 /* Data type predicates */
168 DEFUN ("eq", Feq
, Seq
, 2, 2, 0,
169 "T if the two args are the same Lisp object.")
171 Lisp_Object obj1
, obj2
;
178 DEFUN ("null", Fnull
, Snull
, 1, 1, 0, "T if OBJECT is nil.")
187 DEFUN ("type-of", Ftype_of
, Stype_of
, 1, 1, 0,
188 "Return a symbol representing the type of OBJECT.\n\
189 The symbol returned names the object's basic type;\n\
190 for example, (type-of 1) returns `integer'.")
194 switch (XGCTYPE (object
))
209 switch (XMISCTYPE (object
))
211 case Lisp_Misc_Marker
:
213 case Lisp_Misc_Overlay
:
215 case Lisp_Misc_Float
:
220 case Lisp_Vectorlike
:
221 if (GC_WINDOW_CONFIGURATIONP (object
))
222 return Qwindow_configuration
;
223 if (GC_PROCESSP (object
))
225 if (GC_WINDOWP (object
))
227 if (GC_SUBRP (object
))
229 if (GC_COMPILEDP (object
))
230 return Qcompiled_function
;
231 if (GC_BUFFERP (object
))
233 if (GC_CHAR_TABLE_P (object
))
235 if (GC_BOOL_VECTOR_P (object
))
239 if (GC_FRAMEP (object
))
244 #ifdef LISP_FLOAT_TYPE
254 DEFUN ("consp", Fconsp
, Sconsp
, 1, 1, 0, "T if OBJECT is a cons cell.")
263 DEFUN ("atom", Fatom
, Satom
, 1, 1, 0, "T if OBJECT is not a cons cell. This includes nil.")
272 DEFUN ("listp", Flistp
, Slistp
, 1, 1, 0, "T if OBJECT is a list. This includes nil.")
276 if (CONSP (object
) || NILP (object
))
281 DEFUN ("nlistp", Fnlistp
, Snlistp
, 1, 1, 0, "T if OBJECT is not a list. Lists include nil.")
285 if (CONSP (object
) || NILP (object
))
290 DEFUN ("symbolp", Fsymbolp
, Ssymbolp
, 1, 1, 0, "T if OBJECT is a symbol.")
294 if (SYMBOLP (object
))
299 DEFUN ("vectorp", Fvectorp
, Svectorp
, 1, 1, 0, "T if OBJECT is a vector.")
303 if (VECTORP (object
))
308 DEFUN ("stringp", Fstringp
, Sstringp
, 1, 1, 0, "T if OBJECT is a string.")
312 if (STRINGP (object
))
317 DEFUN ("char-table-p", Fchar_table_p
, Schar_table_p
, 1, 1, 0, "T if OBJECT is a char-table.")
321 if (CHAR_TABLE_P (object
))
326 DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p
,
327 Svector_or_char_table_p
, 1, 1, 0,
328 "T if OBJECT is a char-table or vector.")
332 if (VECTORP (object
) || CHAR_TABLE_P (object
))
337 DEFUN ("bool-vector-p", Fbool_vector_p
, Sbool_vector_p
, 1, 1, 0, "T if OBJECT is a bool-vector.")
341 if (BOOL_VECTOR_P (object
))
346 DEFUN ("arrayp", Farrayp
, Sarrayp
, 1, 1, 0, "T if OBJECT is an array (string or vector).")
350 if (VECTORP (object
) || STRINGP (object
))
355 DEFUN ("sequencep", Fsequencep
, Ssequencep
, 1, 1, 0,
356 "T if OBJECT is a sequence (list or array).")
358 register Lisp_Object object
;
360 if (CONSP (object
) || NILP (object
) || VECTORP (object
) || STRINGP (object
)
361 || CHAR_TABLE_P (object
) || BOOL_VECTOR_P (object
))
366 DEFUN ("bufferp", Fbufferp
, Sbufferp
, 1, 1, 0, "T if OBJECT is an editor buffer.")
370 if (BUFFERP (object
))
375 DEFUN ("markerp", Fmarkerp
, Smarkerp
, 1, 1, 0, "T if OBJECT is a marker (editor pointer).")
379 if (MARKERP (object
))
384 DEFUN ("subrp", Fsubrp
, Ssubrp
, 1, 1, 0, "T if OBJECT is a built-in function.")
393 DEFUN ("byte-code-function-p", Fbyte_code_function_p
, Sbyte_code_function_p
,
394 1, 1, 0, "T if OBJECT is a byte-compiled function object.")
398 if (COMPILEDP (object
))
403 DEFUN ("char-or-string-p", Fchar_or_string_p
, Schar_or_string_p
, 1, 1, 0,
404 "T if OBJECT is a character (an integer) or a string.")
406 register Lisp_Object object
;
408 if (INTEGERP (object
) || STRINGP (object
))
413 DEFUN ("integerp", Fintegerp
, Sintegerp
, 1, 1, 0, "T if OBJECT is an integer.")
417 if (INTEGERP (object
))
422 DEFUN ("integer-or-marker-p", Finteger_or_marker_p
, Sinteger_or_marker_p
, 1, 1, 0,
423 "T if OBJECT is an integer or a marker (editor pointer).")
425 register Lisp_Object object
;
427 if (MARKERP (object
) || INTEGERP (object
))
432 DEFUN ("natnump", Fnatnump
, Snatnump
, 1, 1, 0,
433 "T if OBJECT is a nonnegative integer.")
437 if (NATNUMP (object
))
442 DEFUN ("numberp", Fnumberp
, Snumberp
, 1, 1, 0,
443 "T if OBJECT is a number (floating point or integer).")
447 if (NUMBERP (object
))
453 DEFUN ("number-or-marker-p", Fnumber_or_marker_p
,
454 Snumber_or_marker_p
, 1, 1, 0,
455 "T if OBJECT is a number or a marker.")
459 if (NUMBERP (object
) || MARKERP (object
))
464 #ifdef LISP_FLOAT_TYPE
465 DEFUN ("floatp", Ffloatp
, Sfloatp
, 1, 1, 0,
466 "T if OBJECT is a floating point number.")
474 #endif /* LISP_FLOAT_TYPE */
476 /* Extract and set components of lists */
478 DEFUN ("car", Fcar
, Scar
, 1, 1, 0,
479 "Return the car of LIST. If arg is nil, return nil.\n\
480 Error if arg is not nil and not a cons cell. See also `car-safe'.")
482 register Lisp_Object list
;
487 return XCONS (list
)->car
;
488 else if (EQ (list
, Qnil
))
491 list
= wrong_type_argument (Qlistp
, list
);
495 DEFUN ("car-safe", Fcar_safe
, Scar_safe
, 1, 1, 0,
496 "Return the car of OBJECT if it is a cons cell, or else nil.")
501 return XCONS (object
)->car
;
506 DEFUN ("cdr", Fcdr
, Scdr
, 1, 1, 0,
507 "Return the cdr of LIST. If arg is nil, return nil.\n\
508 Error if arg is not nil and not a cons cell. See also `cdr-safe'.")
511 register Lisp_Object list
;
516 return XCONS (list
)->cdr
;
517 else if (EQ (list
, Qnil
))
520 list
= wrong_type_argument (Qlistp
, list
);
524 DEFUN ("cdr-safe", Fcdr_safe
, Scdr_safe
, 1, 1, 0,
525 "Return the cdr of OBJECT if it is a cons cell, or else nil.")
530 return XCONS (object
)->cdr
;
535 DEFUN ("setcar", Fsetcar
, Ssetcar
, 2, 2, 0,
536 "Set the car of CELL to be NEWCAR. Returns NEWCAR.")
538 register Lisp_Object cell
, newcar
;
541 cell
= wrong_type_argument (Qconsp
, cell
);
544 XCONS (cell
)->car
= newcar
;
548 DEFUN ("setcdr", Fsetcdr
, Ssetcdr
, 2, 2, 0,
549 "Set the cdr of CELL to be NEWCDR. Returns NEWCDR.")
551 register Lisp_Object cell
, newcdr
;
554 cell
= wrong_type_argument (Qconsp
, cell
);
557 XCONS (cell
)->cdr
= newcdr
;
561 /* Extract and set components of symbols */
563 DEFUN ("boundp", Fboundp
, Sboundp
, 1, 1, 0, "T if SYMBOL's value is not void.")
565 register Lisp_Object symbol
;
567 Lisp_Object valcontents
;
568 CHECK_SYMBOL (symbol
, 0);
570 valcontents
= XSYMBOL (symbol
)->value
;
572 if (BUFFER_LOCAL_VALUEP (valcontents
)
573 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
574 valcontents
= swap_in_symval_forwarding (symbol
, valcontents
);
576 return (EQ (valcontents
, Qunbound
) ? Qnil
: Qt
);
579 DEFUN ("fboundp", Ffboundp
, Sfboundp
, 1, 1, 0, "T if SYMBOL's function definition is not void.")
581 register Lisp_Object symbol
;
583 CHECK_SYMBOL (symbol
, 0);
584 return (EQ (XSYMBOL (symbol
)->function
, Qunbound
) ? Qnil
: Qt
);
587 DEFUN ("makunbound", Fmakunbound
, Smakunbound
, 1, 1, 0, "Make SYMBOL's value be void.")
589 register Lisp_Object symbol
;
591 CHECK_SYMBOL (symbol
, 0);
592 if (NILP (symbol
) || EQ (symbol
, Qt
))
593 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
594 Fset (symbol
, Qunbound
);
598 DEFUN ("fmakunbound", Ffmakunbound
, Sfmakunbound
, 1, 1, 0, "Make SYMBOL's function definition be void.")
600 register Lisp_Object symbol
;
602 CHECK_SYMBOL (symbol
, 0);
603 if (NILP (symbol
) || EQ (symbol
, Qt
))
604 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
605 XSYMBOL (symbol
)->function
= Qunbound
;
609 DEFUN ("symbol-function", Fsymbol_function
, Ssymbol_function
, 1, 1, 0,
610 "Return SYMBOL's function definition. Error if that is void.")
612 register Lisp_Object symbol
;
614 CHECK_SYMBOL (symbol
, 0);
615 if (EQ (XSYMBOL (symbol
)->function
, Qunbound
))
616 return Fsignal (Qvoid_function
, Fcons (symbol
, Qnil
));
617 return XSYMBOL (symbol
)->function
;
620 DEFUN ("symbol-plist", Fsymbol_plist
, Ssymbol_plist
, 1, 1, 0, "Return SYMBOL's property list.")
622 register Lisp_Object symbol
;
624 CHECK_SYMBOL (symbol
, 0);
625 return XSYMBOL (symbol
)->plist
;
628 DEFUN ("symbol-name", Fsymbol_name
, Ssymbol_name
, 1, 1, 0, "Return SYMBOL's name, a string.")
630 register Lisp_Object symbol
;
632 register Lisp_Object name
;
634 CHECK_SYMBOL (symbol
, 0);
635 XSETSTRING (name
, XSYMBOL (symbol
)->name
);
639 DEFUN ("fset", Ffset
, Sfset
, 2, 2, 0,
640 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.")
642 register Lisp_Object symbol
, newdef
;
644 CHECK_SYMBOL (symbol
, 0);
645 if (NILP (symbol
) || EQ (symbol
, Qt
))
646 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
647 if (!NILP (Vautoload_queue
) && !EQ (XSYMBOL (symbol
)->function
, Qunbound
))
648 Vautoload_queue
= Fcons (Fcons (symbol
, XSYMBOL (symbol
)->function
),
650 XSYMBOL (symbol
)->function
= newdef
;
651 /* Handle automatic advice activation */
652 if (CONSP (XSYMBOL (symbol
)->plist
) && !NILP (Fget (symbol
, Qad_advice_info
)))
654 call2 (Qad_activate
, symbol
, Qnil
);
655 newdef
= XSYMBOL (symbol
)->function
;
660 /* This name should be removed once it is eliminated from elsewhere. */
662 DEFUN ("defalias", Fdefalias
, Sdefalias
, 2, 2, 0,
663 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.\n\
664 Associates the function with the current load file, if any.")
666 register Lisp_Object symbol
, newdef
;
668 CHECK_SYMBOL (symbol
, 0);
669 if (!NILP (Vautoload_queue
) && !EQ (XSYMBOL (symbol
)->function
, Qunbound
))
670 Vautoload_queue
= Fcons (Fcons (symbol
, XSYMBOL (symbol
)->function
),
672 XSYMBOL (symbol
)->function
= newdef
;
673 /* Handle automatic advice activation */
674 if (CONSP (XSYMBOL (symbol
)->plist
) && !NILP (Fget (symbol
, Qad_advice_info
)))
676 call2 (Qad_activate
, symbol
, Qnil
);
677 newdef
= XSYMBOL (symbol
)->function
;
679 LOADHIST_ATTACH (symbol
);
683 DEFUN ("define-function", Fdefine_function
, Sdefine_function
, 2, 2, 0,
684 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.\n\
685 Associates the function with the current load file, if any.")
687 register Lisp_Object symbol
, newdef
;
689 CHECK_SYMBOL (symbol
, 0);
690 if (!NILP (Vautoload_queue
) && !EQ (XSYMBOL (symbol
)->function
, Qunbound
))
691 Vautoload_queue
= Fcons (Fcons (symbol
, XSYMBOL (symbol
)->function
),
693 XSYMBOL (symbol
)->function
= newdef
;
694 /* Handle automatic advice activation */
695 if (CONSP (XSYMBOL (symbol
)->plist
) && !NILP (Fget (symbol
, Qad_advice_info
)))
697 call2 (Qad_activate
, symbol
, Qnil
);
698 newdef
= XSYMBOL (symbol
)->function
;
700 LOADHIST_ATTACH (symbol
);
704 DEFUN ("setplist", Fsetplist
, Ssetplist
, 2, 2, 0,
705 "Set SYMBOL's property list to NEWVAL, and return NEWVAL.")
707 register Lisp_Object symbol
, newplist
;
709 CHECK_SYMBOL (symbol
, 0);
710 XSYMBOL (symbol
)->plist
= newplist
;
715 /* Getting and setting values of symbols */
717 /* Given the raw contents of a symbol value cell,
718 return the Lisp value of the symbol.
719 This does not handle buffer-local variables; use
720 swap_in_symval_forwarding for that. */
723 do_symval_forwarding (valcontents
)
724 register Lisp_Object valcontents
;
726 register Lisp_Object val
;
728 if (MISCP (valcontents
))
729 switch (XMISCTYPE (valcontents
))
731 case Lisp_Misc_Intfwd
:
732 XSETINT (val
, *XINTFWD (valcontents
)->intvar
);
735 case Lisp_Misc_Boolfwd
:
736 return (*XBOOLFWD (valcontents
)->boolvar
? Qt
: Qnil
);
738 case Lisp_Misc_Objfwd
:
739 return *XOBJFWD (valcontents
)->objvar
;
741 case Lisp_Misc_Buffer_Objfwd
:
742 offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
743 return *(Lisp_Object
*)(offset
+ (char *)current_buffer
);
745 case Lisp_Misc_Kboard_Objfwd
:
746 offset
= XKBOARD_OBJFWD (valcontents
)->offset
;
747 return *(Lisp_Object
*)(offset
+ (char *)current_kboard
);
752 /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell
753 of SYMBOL. If SYMBOL is buffer-local, VALCONTENTS should be the
754 buffer-independent contents of the value cell: forwarded just one
755 step past the buffer-localness. */
758 store_symval_forwarding (symbol
, valcontents
, newval
)
760 register Lisp_Object valcontents
, newval
;
762 switch (SWITCH_ENUM_CAST (XTYPE (valcontents
)))
765 switch (XMISCTYPE (valcontents
))
767 case Lisp_Misc_Intfwd
:
768 CHECK_NUMBER (newval
, 1);
769 *XINTFWD (valcontents
)->intvar
= XINT (newval
);
770 if (*XINTFWD (valcontents
)->intvar
!= XINT (newval
))
771 error ("Value out of range for variable `%s'",
772 XSYMBOL (symbol
)->name
->data
);
775 case Lisp_Misc_Boolfwd
:
776 *XBOOLFWD (valcontents
)->boolvar
= NILP (newval
) ? 0 : 1;
779 case Lisp_Misc_Objfwd
:
780 *XOBJFWD (valcontents
)->objvar
= newval
;
783 case Lisp_Misc_Buffer_Objfwd
:
785 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
788 type
= *(Lisp_Object
*)(offset
+ (char *)&buffer_local_types
);
789 if (! NILP (type
) && ! NILP (newval
)
790 && XTYPE (newval
) != XINT (type
))
791 buffer_slot_type_mismatch (offset
);
793 *(Lisp_Object
*)(offset
+ (char *)current_buffer
) = newval
;
797 case Lisp_Misc_Kboard_Objfwd
:
798 (*(Lisp_Object
*)((char *)current_kboard
799 + XKBOARD_OBJFWD (valcontents
)->offset
))
810 valcontents
= XSYMBOL (symbol
)->value
;
811 if (BUFFER_LOCAL_VALUEP (valcontents
)
812 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
813 XBUFFER_LOCAL_VALUE (valcontents
)->car
= newval
;
815 XSYMBOL (symbol
)->value
= newval
;
819 /* Set up the buffer-local symbol SYMBOL for validity in the current
820 buffer. VALCONTENTS is the contents of its value cell.
821 Return the value forwarded one step past the buffer-local indicator. */
824 swap_in_symval_forwarding (symbol
, valcontents
)
825 Lisp_Object symbol
, valcontents
;
827 /* valcontents is a pointer to a struct resembling the cons
828 (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE)).
830 CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
831 local_var_alist, that being the element whose car is this
832 variable. Or it can be a pointer to the
833 (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER does not have
834 an element in its alist for this variable.
836 If the current buffer is not BUFFER, we store the current
837 REALVALUE value into CURRENT-ALIST-ELEMENT, then find the
838 appropriate alist element for the buffer now current and set up
839 CURRENT-ALIST-ELEMENT. Then we set REALVALUE out of that
840 element, and store into BUFFER.
842 Note that REALVALUE can be a forwarding pointer. */
844 register Lisp_Object tem1
;
845 tem1
= XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
;
847 if (NILP (tem1
) || current_buffer
!= XBUFFER (tem1
))
849 tem1
= XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
;
851 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->car
));
852 tem1
= assq_no_quit (symbol
, current_buffer
->local_var_alist
);
854 tem1
= XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
;
855 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
= tem1
;
856 XSETBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
,
858 store_symval_forwarding (symbol
, XBUFFER_LOCAL_VALUE (valcontents
)->car
,
861 return XBUFFER_LOCAL_VALUE (valcontents
)->car
;
864 /* Find the value of a symbol, returning Qunbound if it's not bound.
865 This is helpful for code which just wants to get a variable's value
866 if it has one, without signaling an error.
867 Note that it must not be possible to quit
868 within this function. Great care is required for this. */
871 find_symbol_value (symbol
)
874 register Lisp_Object valcontents
, tem1
;
875 register Lisp_Object val
;
876 CHECK_SYMBOL (symbol
, 0);
877 valcontents
= XSYMBOL (symbol
)->value
;
879 if (BUFFER_LOCAL_VALUEP (valcontents
)
880 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
881 valcontents
= swap_in_symval_forwarding (symbol
, valcontents
);
883 if (MISCP (valcontents
))
885 switch (XMISCTYPE (valcontents
))
887 case Lisp_Misc_Intfwd
:
888 XSETINT (val
, *XINTFWD (valcontents
)->intvar
);
891 case Lisp_Misc_Boolfwd
:
892 return (*XBOOLFWD (valcontents
)->boolvar
? Qt
: Qnil
);
894 case Lisp_Misc_Objfwd
:
895 return *XOBJFWD (valcontents
)->objvar
;
897 case Lisp_Misc_Buffer_Objfwd
:
898 return *(Lisp_Object
*)(XBUFFER_OBJFWD (valcontents
)->offset
899 + (char *)current_buffer
);
901 case Lisp_Misc_Kboard_Objfwd
:
902 return *(Lisp_Object
*)(XKBOARD_OBJFWD (valcontents
)->offset
903 + (char *)current_kboard
);
910 DEFUN ("symbol-value", Fsymbol_value
, Ssymbol_value
, 1, 1, 0,
911 "Return SYMBOL's value. Error if that is void.")
917 val
= find_symbol_value (symbol
);
918 if (EQ (val
, Qunbound
))
919 return Fsignal (Qvoid_variable
, Fcons (symbol
, Qnil
));
924 DEFUN ("set", Fset
, Sset
, 2, 2, 0,
925 "Set SYMBOL's value to NEWVAL, and return NEWVAL.")
927 register Lisp_Object symbol
, newval
;
929 int voide
= EQ (newval
, Qunbound
);
931 register Lisp_Object valcontents
, tem1
, current_alist_element
;
933 CHECK_SYMBOL (symbol
, 0);
934 if (NILP (symbol
) || EQ (symbol
, Qt
))
935 return Fsignal (Qsetting_constant
, Fcons (symbol
, Qnil
));
936 valcontents
= XSYMBOL (symbol
)->value
;
938 if (BUFFER_OBJFWDP (valcontents
))
940 register int idx
= XBUFFER_OBJFWD (valcontents
)->offset
;
941 register int mask
= XINT (*((Lisp_Object
*)
942 (idx
+ (char *)&buffer_local_flags
)));
944 current_buffer
->local_var_flags
|= mask
;
947 else if (BUFFER_LOCAL_VALUEP (valcontents
)
948 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
950 /* valcontents is actually a pointer to a struct resembling a cons,
951 with contents something like:
952 (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE).
954 BUFFER is the last buffer for which this symbol's value was
957 CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's
958 local_var_alist, that being the element whose car is this
959 variable. Or it can be a pointer to the
960 (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER does not
961 have an element in its alist for this variable (that is, if
962 BUFFER sees the default value of this variable).
964 If we want to examine or set the value and BUFFER is current,
965 we just examine or set REALVALUE. If BUFFER is not current, we
966 store the current REALVALUE value into CURRENT-ALIST-ELEMENT,
967 then find the appropriate alist element for the buffer now
968 current and set up CURRENT-ALIST-ELEMENT. Then we set
969 REALVALUE out of that element, and store into BUFFER.
971 If we are setting the variable and the current buffer does
972 not have an alist entry for this variable, an alist entry is
975 Note that REALVALUE can be a forwarding pointer. Each time
976 it is examined or set, forwarding must be done. */
978 /* What value are we caching right now? */
979 current_alist_element
=
980 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
;
982 /* If the current buffer is not the buffer whose binding is
983 currently cached, or if it's a Lisp_Buffer_Local_Value and
984 we're looking at the default value, the cache is invalid; we
985 need to write it out, and find the new CURRENT-ALIST-ELEMENT. */
987 != XBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
))
988 || (BUFFER_LOCAL_VALUEP (valcontents
)
989 && EQ (XCONS (current_alist_element
)->car
,
990 current_alist_element
)))
992 /* Write out the cached value for the old buffer; copy it
993 back to its alist element. This works if the current
994 buffer only sees the default value, too. */
995 Fsetcdr (current_alist_element
,
996 do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->car
));
998 /* Find the new value for CURRENT-ALIST-ELEMENT. */
999 tem1
= Fassq (symbol
, current_buffer
->local_var_alist
);
1002 /* This buffer still sees the default value. */
1004 /* If the variable is a Lisp_Some_Buffer_Local_Value,
1005 make CURRENT-ALIST-ELEMENT point to itself,
1006 indicating that we're seeing the default value. */
1007 if (SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1008 tem1
= XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
;
1010 /* If it's a Lisp_Buffer_Local_Value, give this buffer a
1011 new assoc for a local value and set
1012 CURRENT-ALIST-ELEMENT to point to that. */
1015 tem1
= Fcons (symbol
, Fcdr (current_alist_element
));
1016 current_buffer
->local_var_alist
=
1017 Fcons (tem1
, current_buffer
->local_var_alist
);
1020 /* Cache the new buffer's assoc in CURRENT-ALIST-ELEMENT. */
1021 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
1024 /* Set BUFFER, now that CURRENT-ALIST-ELEMENT is accurate. */
1025 XSETBUFFER (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
,
1028 valcontents
= XBUFFER_LOCAL_VALUE (valcontents
)->car
;
1031 /* If storing void (making the symbol void), forward only through
1032 buffer-local indicator, not through Lisp_Objfwd, etc. */
1034 store_symval_forwarding (symbol
, Qnil
, newval
);
1036 store_symval_forwarding (symbol
, valcontents
, newval
);
1041 /* Access or set a buffer-local symbol's default value. */
1043 /* Return the default value of SYMBOL, but don't check for voidness.
1044 Return Qunbound if it is void. */
1047 default_value (symbol
)
1050 register Lisp_Object valcontents
;
1052 CHECK_SYMBOL (symbol
, 0);
1053 valcontents
= XSYMBOL (symbol
)->value
;
1055 /* For a built-in buffer-local variable, get the default value
1056 rather than letting do_symval_forwarding get the current value. */
1057 if (BUFFER_OBJFWDP (valcontents
))
1059 register int idx
= XBUFFER_OBJFWD (valcontents
)->offset
;
1061 if (XINT (*(Lisp_Object
*) (idx
+ (char *) &buffer_local_flags
)) != 0)
1062 return *(Lisp_Object
*)(idx
+ (char *) &buffer_defaults
);
1065 /* Handle user-created local variables. */
1066 if (BUFFER_LOCAL_VALUEP (valcontents
)
1067 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1069 /* If var is set up for a buffer that lacks a local value for it,
1070 the current value is nominally the default value.
1071 But the current value slot may be more up to date, since
1072 ordinary setq stores just that slot. So use that. */
1073 Lisp_Object current_alist_element
, alist_element_car
;
1074 current_alist_element
1075 = XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
;
1076 alist_element_car
= XCONS (current_alist_element
)->car
;
1077 if (EQ (alist_element_car
, current_alist_element
))
1078 return do_symval_forwarding (XBUFFER_LOCAL_VALUE (valcontents
)->car
);
1080 return XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->cdr
;
1082 /* For other variables, get the current value. */
1083 return do_symval_forwarding (valcontents
);
1086 DEFUN ("default-boundp", Fdefault_boundp
, Sdefault_boundp
, 1, 1, 0,
1087 "Return T if SYMBOL has a non-void default value.\n\
1088 This is the value that is seen in buffers that do not have their own values\n\
1089 for this variable.")
1093 register Lisp_Object value
;
1095 value
= default_value (symbol
);
1096 return (EQ (value
, Qunbound
) ? Qnil
: Qt
);
1099 DEFUN ("default-value", Fdefault_value
, Sdefault_value
, 1, 1, 0,
1100 "Return SYMBOL's default value.\n\
1101 This is the value that is seen in buffers that do not have their own values\n\
1102 for this variable. The default value is meaningful for variables with\n\
1103 local bindings in certain buffers.")
1107 register Lisp_Object value
;
1109 value
= default_value (symbol
);
1110 if (EQ (value
, Qunbound
))
1111 return Fsignal (Qvoid_variable
, Fcons (symbol
, Qnil
));
1115 DEFUN ("set-default", Fset_default
, Sset_default
, 2, 2, 0,
1116 "Set SYMBOL's default value to VAL. SYMBOL and VAL are evaluated.\n\
1117 The default value is seen in buffers that do not have their own values\n\
1118 for this variable.")
1120 Lisp_Object symbol
, value
;
1122 register Lisp_Object valcontents
, current_alist_element
, alist_element_buffer
;
1124 CHECK_SYMBOL (symbol
, 0);
1125 valcontents
= XSYMBOL (symbol
)->value
;
1127 /* Handle variables like case-fold-search that have special slots
1128 in the buffer. Make them work apparently like Lisp_Buffer_Local_Value
1130 if (BUFFER_OBJFWDP (valcontents
))
1132 register int idx
= XBUFFER_OBJFWD (valcontents
)->offset
;
1133 register struct buffer
*b
;
1134 register int mask
= XINT (*((Lisp_Object
*)
1135 (idx
+ (char *)&buffer_local_flags
)));
1139 *(Lisp_Object
*)(idx
+ (char *) &buffer_defaults
) = value
;
1140 for (b
= all_buffers
; b
; b
= b
->next
)
1141 if (!(b
->local_var_flags
& mask
))
1142 *(Lisp_Object
*)(idx
+ (char *) b
) = value
;
1147 if (!BUFFER_LOCAL_VALUEP (valcontents
)
1148 && !SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1149 return Fset (symbol
, value
);
1151 /* Store new value into the DEFAULT-VALUE slot */
1152 XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->cdr
= value
;
1154 /* If that slot is current, we must set the REALVALUE slot too */
1155 current_alist_element
1156 = XCONS (XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->cdr
)->car
;
1157 alist_element_buffer
= Fcar (current_alist_element
);
1158 if (EQ (alist_element_buffer
, current_alist_element
))
1159 store_symval_forwarding (symbol
, XBUFFER_LOCAL_VALUE (valcontents
)->car
,
1165 DEFUN ("setq-default", Fsetq_default
, Ssetq_default
, 2, UNEVALLED
, 0,
1166 "Set the default value of variable VAR to VALUE.\n\
1167 VAR, the variable name, is literal (not evaluated);\n\
1168 VALUE is an expression and it is evaluated.\n\
1169 The default value of a variable is seen in buffers\n\
1170 that do not have their own values for the variable.\n\
1172 More generally, you can use multiple variables and values, as in\n\
1173 (setq-default SYMBOL VALUE SYMBOL VALUE...)\n\
1174 This sets each SYMBOL's default value to the corresponding VALUE.\n\
1175 The VALUE for the Nth SYMBOL can refer to the new default values\n\
1180 register Lisp_Object args_left
;
1181 register Lisp_Object val
, symbol
;
1182 struct gcpro gcpro1
;
1192 val
= Feval (Fcar (Fcdr (args_left
)));
1193 symbol
= Fcar (args_left
);
1194 Fset_default (symbol
, val
);
1195 args_left
= Fcdr (Fcdr (args_left
));
1197 while (!NILP (args_left
));
1203 /* Lisp functions for creating and removing buffer-local variables. */
1205 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local
, Smake_variable_buffer_local
,
1206 1, 1, "vMake Variable Buffer Local: ",
1207 "Make VARIABLE have a separate value for each buffer.\n\
1208 At any time, the value for the current buffer is in effect.\n\
1209 There is also a default value which is seen in any buffer which has not yet\n\
1210 set its own value.\n\
1211 Using `set' or `setq' to set the variable causes it to have a separate value\n\
1212 for the current buffer if it was previously using the default value.\n\
1213 The function `default-value' gets the default value and `set-default' sets it.")
1215 register Lisp_Object variable
;
1217 register Lisp_Object tem
, valcontents
, newval
;
1219 CHECK_SYMBOL (variable
, 0);
1221 valcontents
= XSYMBOL (variable
)->value
;
1222 if (EQ (variable
, Qnil
) || EQ (variable
, Qt
) || KBOARD_OBJFWDP (valcontents
))
1223 error ("Symbol %s may not be buffer-local", XSYMBOL (variable
)->name
->data
);
1225 if (BUFFER_LOCAL_VALUEP (valcontents
) || BUFFER_OBJFWDP (valcontents
))
1227 if (SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1229 XMISCTYPE (XSYMBOL (variable
)->value
) = Lisp_Misc_Buffer_Local_Value
;
1232 if (EQ (valcontents
, Qunbound
))
1233 XSYMBOL (variable
)->value
= Qnil
;
1234 tem
= Fcons (Qnil
, Fsymbol_value (variable
));
1235 XCONS (tem
)->car
= tem
;
1236 newval
= allocate_misc ();
1237 XMISCTYPE (newval
) = Lisp_Misc_Buffer_Local_Value
;
1238 XBUFFER_LOCAL_VALUE (newval
)->car
= XSYMBOL (variable
)->value
;
1239 XBUFFER_LOCAL_VALUE (newval
)->cdr
= Fcons (Fcurrent_buffer (), tem
);
1240 XSYMBOL (variable
)->value
= newval
;
1244 DEFUN ("make-local-variable", Fmake_local_variable
, Smake_local_variable
,
1245 1, 1, "vMake Local Variable: ",
1246 "Make VARIABLE have a separate value in the current buffer.\n\
1247 Other buffers will continue to share a common default value.\n\
1248 \(The buffer-local value of VARIABLE starts out as the same value\n\
1249 VARIABLE previously had. If VARIABLE was void, it remains void.\)\n\
1250 See also `make-variable-buffer-local'.\n\n\
1251 If the variable is already arranged to become local when set,\n\
1252 this function causes a local value to exist for this buffer,\n\
1253 just as setting the variable would do.\n\
1255 Do not use `make-local-variable' to make a hook variable buffer-local.\n\
1256 Use `make-local-hook' instead.")
1258 register Lisp_Object variable
;
1260 register Lisp_Object tem
, valcontents
;
1262 CHECK_SYMBOL (variable
, 0);
1264 valcontents
= XSYMBOL (variable
)->value
;
1265 if (EQ (variable
, Qnil
) || EQ (variable
, Qt
) || KBOARD_OBJFWDP (valcontents
))
1266 error ("Symbol %s may not be buffer-local", XSYMBOL (variable
)->name
->data
);
1268 if (BUFFER_LOCAL_VALUEP (valcontents
) || BUFFER_OBJFWDP (valcontents
))
1270 tem
= Fboundp (variable
);
1272 /* Make sure the symbol has a local value in this particular buffer,
1273 by setting it to the same value it already has. */
1274 Fset (variable
, (EQ (tem
, Qt
) ? Fsymbol_value (variable
) : Qunbound
));
1277 /* Make sure symbol is set up to hold per-buffer values */
1278 if (!SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1281 tem
= Fcons (Qnil
, do_symval_forwarding (valcontents
));
1282 XCONS (tem
)->car
= tem
;
1283 newval
= allocate_misc ();
1284 XMISCTYPE (newval
) = Lisp_Misc_Some_Buffer_Local_Value
;
1285 XBUFFER_LOCAL_VALUE (newval
)->car
= XSYMBOL (variable
)->value
;
1286 XBUFFER_LOCAL_VALUE (newval
)->cdr
= Fcons (Qnil
, tem
);
1287 XSYMBOL (variable
)->value
= newval
;
1289 /* Make sure this buffer has its own value of symbol */
1290 tem
= Fassq (variable
, current_buffer
->local_var_alist
);
1293 /* Swap out any local binding for some other buffer, and make
1294 sure the current value is permanently recorded, if it's the
1296 find_symbol_value (variable
);
1298 current_buffer
->local_var_alist
1299 = Fcons (Fcons (variable
, XCONS (XCONS (XBUFFER_LOCAL_VALUE (XSYMBOL (variable
)->value
)->cdr
)->cdr
)->cdr
),
1300 current_buffer
->local_var_alist
);
1302 /* Make sure symbol does not think it is set up for this buffer;
1303 force it to look once again for this buffer's value */
1305 Lisp_Object
*pvalbuf
;
1307 valcontents
= XSYMBOL (variable
)->value
;
1309 pvalbuf
= &XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
;
1310 if (current_buffer
== XBUFFER (*pvalbuf
))
1315 /* If the symbol forwards into a C variable, then swap in the
1316 variable for this buffer immediately. If C code modifies the
1317 variable before we swap in, then that new value will clobber the
1318 default value the next time we swap. */
1319 valcontents
= XBUFFER_LOCAL_VALUE (XSYMBOL (variable
)->value
)->car
;
1320 if (INTFWDP (valcontents
) || BOOLFWDP (valcontents
) || OBJFWDP (valcontents
))
1321 swap_in_symval_forwarding (variable
, XSYMBOL (variable
)->value
);
1326 DEFUN ("kill-local-variable", Fkill_local_variable
, Skill_local_variable
,
1327 1, 1, "vKill Local Variable: ",
1328 "Make VARIABLE no longer have a separate value in the current buffer.\n\
1329 From now on the default value will apply in this buffer.")
1331 register Lisp_Object variable
;
1333 register Lisp_Object tem
, valcontents
;
1335 CHECK_SYMBOL (variable
, 0);
1337 valcontents
= XSYMBOL (variable
)->value
;
1339 if (BUFFER_OBJFWDP (valcontents
))
1341 register int idx
= XBUFFER_OBJFWD (valcontents
)->offset
;
1342 register int mask
= XINT (*((Lisp_Object
*)
1343 (idx
+ (char *)&buffer_local_flags
)));
1347 *(Lisp_Object
*)(idx
+ (char *) current_buffer
)
1348 = *(Lisp_Object
*)(idx
+ (char *) &buffer_defaults
);
1349 current_buffer
->local_var_flags
&= ~mask
;
1354 if (!BUFFER_LOCAL_VALUEP (valcontents
)
1355 && !SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1358 /* Get rid of this buffer's alist element, if any */
1360 tem
= Fassq (variable
, current_buffer
->local_var_alist
);
1362 current_buffer
->local_var_alist
1363 = Fdelq (tem
, current_buffer
->local_var_alist
);
1365 /* Make sure symbol does not think it is set up for this buffer;
1366 force it to look once again for this buffer's value */
1368 Lisp_Object
*pvalbuf
;
1369 valcontents
= XSYMBOL (variable
)->value
;
1370 pvalbuf
= &XCONS (XBUFFER_LOCAL_VALUE (valcontents
)->cdr
)->car
;
1371 if (current_buffer
== XBUFFER (*pvalbuf
))
1378 DEFUN ("local-variable-p", Flocal_variable_p
, Slocal_variable_p
,
1380 "Non-nil if VARIABLE has a local binding in buffer BUFFER.\n\
1381 BUFFER defaults to the current buffer.")
1383 register Lisp_Object variable
, buffer
;
1385 Lisp_Object valcontents
;
1386 register struct buffer
*buf
;
1389 buf
= current_buffer
;
1392 CHECK_BUFFER (buffer
, 0);
1393 buf
= XBUFFER (buffer
);
1396 CHECK_SYMBOL (variable
, 0);
1398 valcontents
= XSYMBOL (variable
)->value
;
1399 if (BUFFER_LOCAL_VALUEP (valcontents
)
1400 || SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1402 Lisp_Object tail
, elt
;
1403 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1405 elt
= XCONS (tail
)->car
;
1406 if (EQ (variable
, XCONS (elt
)->car
))
1410 if (BUFFER_OBJFWDP (valcontents
))
1412 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1413 int mask
= XINT (*(Lisp_Object
*)(offset
+ (char *)&buffer_local_flags
));
1414 if (mask
== -1 || (buf
->local_var_flags
& mask
))
1420 DEFUN ("local-variable-if-set-p", Flocal_variable_if_set_p
, Slocal_variable_if_set_p
,
1422 "Non-nil if VARIABLE will be local in buffer BUFFER if it is set there.\n\
1423 BUFFER defaults to the current buffer.")
1425 register Lisp_Object variable
, buffer
;
1427 Lisp_Object valcontents
;
1428 register struct buffer
*buf
;
1431 buf
= current_buffer
;
1434 CHECK_BUFFER (buffer
, 0);
1435 buf
= XBUFFER (buffer
);
1438 CHECK_SYMBOL (variable
, 0);
1440 valcontents
= XSYMBOL (variable
)->value
;
1442 /* This means that make-variable-buffer-local was done. */
1443 if (BUFFER_LOCAL_VALUEP (valcontents
))
1445 /* All these slots become local if they are set. */
1446 if (BUFFER_OBJFWDP (valcontents
))
1448 if (SOME_BUFFER_LOCAL_VALUEP (valcontents
))
1450 Lisp_Object tail
, elt
;
1451 for (tail
= buf
->local_var_alist
; CONSP (tail
); tail
= XCONS (tail
)->cdr
)
1453 elt
= XCONS (tail
)->car
;
1454 if (EQ (variable
, XCONS (elt
)->car
))
1461 /* Find the function at the end of a chain of symbol function indirections. */
1463 /* If OBJECT is a symbol, find the end of its function chain and
1464 return the value found there. If OBJECT is not a symbol, just
1465 return it. If there is a cycle in the function chain, signal a
1466 cyclic-function-indirection error.
1468 This is like Findirect_function, except that it doesn't signal an
1469 error if the chain ends up unbound. */
1471 indirect_function (object
)
1472 register Lisp_Object object
;
1474 Lisp_Object tortoise
, hare
;
1476 hare
= tortoise
= object
;
1480 if (!SYMBOLP (hare
) || EQ (hare
, Qunbound
))
1482 hare
= XSYMBOL (hare
)->function
;
1483 if (!SYMBOLP (hare
) || EQ (hare
, Qunbound
))
1485 hare
= XSYMBOL (hare
)->function
;
1487 tortoise
= XSYMBOL (tortoise
)->function
;
1489 if (EQ (hare
, tortoise
))
1490 Fsignal (Qcyclic_function_indirection
, Fcons (object
, Qnil
));
1496 DEFUN ("indirect-function", Findirect_function
, Sindirect_function
, 1, 1, 0,
1497 "Return the function at the end of OBJECT's function chain.\n\
1498 If OBJECT is a symbol, follow all function indirections and return the final\n\
1499 function binding.\n\
1500 If OBJECT is not a symbol, just return it.\n\
1501 Signal a void-function error if the final symbol is unbound.\n\
1502 Signal a cyclic-function-indirection error if there is a loop in the\n\
1503 function chain of symbols.")
1505 register Lisp_Object object
;
1509 result
= indirect_function (object
);
1511 if (EQ (result
, Qunbound
))
1512 return Fsignal (Qvoid_function
, Fcons (object
, Qnil
));
1516 /* Extract and set vector and string elements */
1518 DEFUN ("aref", Faref
, Saref
, 2, 2, 0,
1519 "Return the element of ARRAY at index IDX.\n\
1520 ARRAY may be a vector, a string, a char-table, a bool-vector,\n\
1521 or a byte-code object. IDX starts at 0.")
1523 register Lisp_Object array
;
1526 register int idxval
;
1528 CHECK_NUMBER (idx
, 1);
1529 idxval
= XINT (idx
);
1530 if (STRINGP (array
))
1533 if (idxval
< 0 || idxval
>= XSTRING (array
)->size
)
1534 args_out_of_range (array
, idx
);
1535 XSETFASTINT (val
, (unsigned char) XSTRING (array
)->data
[idxval
]);
1538 else if (BOOL_VECTOR_P (array
))
1542 if (idxval
< 0 || idxval
>= XBOOL_VECTOR (array
)->size
)
1543 args_out_of_range (array
, idx
);
1545 val
= (unsigned char) XBOOL_VECTOR (array
)->data
[idxval
/ BITS_PER_CHAR
];
1546 return (val
& (1 << (idxval
% BITS_PER_CHAR
)) ? Qt
: Qnil
);
1548 else if (CHAR_TABLE_P (array
))
1553 args_out_of_range (array
, idx
);
1555 if ((unsigned) idxval
>= CHAR_TABLE_ORDINARY_SLOTS
)
1556 args_out_of_range (array
, idx
);
1557 return val
= XCHAR_TABLE (array
)->contents
[idxval
];
1559 if ((unsigned) idxval
< CHAR_TABLE_ORDINARY_SLOTS
)
1560 val
= XCHAR_TABLE (array
)->data
[idxval
];
1564 unsigned char c1
, c2
;
1565 Lisp_Object val
, temp
;
1567 BREAKUP_NON_ASCII_CHAR (idxval
, charset
, c1
, c2
);
1569 try_parent_char_table
:
1570 val
= XCHAR_TABLE (array
)->contents
[charset
];
1571 if (c1
== 0 || !CHAR_TABLE_P (val
))
1574 temp
= XCHAR_TABLE (val
)->contents
[c1
];
1576 val
= XCHAR_TABLE (val
)->defalt
;
1580 if (NILP (val
) && !NILP (XCHAR_TABLE (array
)->parent
))
1582 array
= XCHAR_TABLE (array
)->parent
;
1583 goto try_parent_char_table
;
1587 if (c2
== 0 || !CHAR_TABLE_P (val
))
1590 temp
= XCHAR_TABLE (val
)->contents
[c2
];
1592 val
= XCHAR_TABLE (val
)->defalt
;
1596 if (NILP (val
) && !NILP (XCHAR_TABLE (array
)->parent
))
1598 array
= XCHAR_TABLE (array
)->parent
;
1599 goto try_parent_char_table
;
1609 if (VECTORP (array
))
1610 size
= XVECTOR (array
)->size
;
1611 else if (COMPILEDP (array
))
1612 size
= XVECTOR (array
)->size
& PSEUDOVECTOR_SIZE_MASK
;
1614 wrong_type_argument (Qarrayp
, array
);
1616 if (idxval
< 0 || idxval
>= size
)
1617 args_out_of_range (array
, idx
);
1618 return XVECTOR (array
)->contents
[idxval
];
1622 DEFUN ("aset", Faset
, Saset
, 3, 3, 0,
1623 "Store into the element of ARRAY at index IDX the value NEWELT.\n\
1624 ARRAY may be a vector or a string. IDX starts at 0.")
1625 (array
, idx
, newelt
)
1626 register Lisp_Object array
;
1627 Lisp_Object idx
, newelt
;
1629 register int idxval
;
1631 CHECK_NUMBER (idx
, 1);
1632 idxval
= XINT (idx
);
1633 if (!VECTORP (array
) && !STRINGP (array
) && !BOOL_VECTOR_P (array
)
1634 && ! CHAR_TABLE_P (array
))
1635 array
= wrong_type_argument (Qarrayp
, array
);
1636 CHECK_IMPURE (array
);
1638 if (VECTORP (array
))
1640 if (idxval
< 0 || idxval
>= XVECTOR (array
)->size
)
1641 args_out_of_range (array
, idx
);
1642 XVECTOR (array
)->contents
[idxval
] = newelt
;
1644 else if (BOOL_VECTOR_P (array
))
1648 if (idxval
< 0 || idxval
>= XBOOL_VECTOR (array
)->size
)
1649 args_out_of_range (array
, idx
);
1651 val
= (unsigned char) XBOOL_VECTOR (array
)->data
[idxval
/ BITS_PER_CHAR
];
1653 if (! NILP (newelt
))
1654 val
|= 1 << (idxval
% BITS_PER_CHAR
);
1656 val
&= ~(1 << (idxval
% BITS_PER_CHAR
));
1657 XBOOL_VECTOR (array
)->data
[idxval
/ BITS_PER_CHAR
] = val
;
1659 else if (CHAR_TABLE_P (array
))
1664 args_out_of_range (array
, idx
);
1666 if (idxval
>= CHAR_TABLE_ORDINARY_SLOTS
)
1667 args_out_of_range (array
, idx
);
1668 XCHAR_TABLE (array
)->contents
[idxval
] = newelt
;
1671 if (idxval
< CHAR_TABLE_ORDINARY_SLOTS
)
1672 val
= XCHAR_TABLE (array
)->contents
[idxval
];
1676 unsigned char c1
, c2
;
1677 Lisp_Object val
, val2
;
1679 BREAKUP_NON_ASCII_CHAR (idxval
, charset
, c1
, c2
);
1682 return XCHAR_TABLE (array
)->contents
[charset
] = newelt
;
1684 val
= XCHAR_TABLE (array
)->contents
[charset
];
1685 if (!CHAR_TABLE_P (val
))
1686 XCHAR_TABLE (array
)->contents
[charset
]
1687 = val
= Fmake_char_table (Qnil
);
1690 return XCHAR_TABLE (val
)->contents
[c1
] = newelt
;
1692 val2
= XCHAR_TABLE (val
)->contents
[c2
];
1693 if (!CHAR_TABLE_P (val2
))
1694 XCHAR_TABLE (val
)->contents
[charset
]
1695 = val2
= Fmake_char_table (Qnil
);
1697 return XCHAR_TABLE (val2
)->contents
[c2
] = newelt
;
1703 if (idxval
< 0 || idxval
>= XSTRING (array
)->size
)
1704 args_out_of_range (array
, idx
);
1705 CHECK_NUMBER (newelt
, 2);
1706 XSTRING (array
)->data
[idxval
] = XINT (newelt
);
1712 /* Arithmetic functions */
1714 enum comparison
{ equal
, notequal
, less
, grtr
, less_or_equal
, grtr_or_equal
};
1717 arithcompare (num1
, num2
, comparison
)
1718 Lisp_Object num1
, num2
;
1719 enum comparison comparison
;
1724 #ifdef LISP_FLOAT_TYPE
1725 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1
, 0);
1726 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2
, 0);
1728 if (FLOATP (num1
) || FLOATP (num2
))
1731 f1
= (FLOATP (num1
)) ? XFLOAT (num1
)->data
: XINT (num1
);
1732 f2
= (FLOATP (num2
)) ? XFLOAT (num2
)->data
: XINT (num2
);
1735 CHECK_NUMBER_COERCE_MARKER (num1
, 0);
1736 CHECK_NUMBER_COERCE_MARKER (num2
, 0);
1737 #endif /* LISP_FLOAT_TYPE */
1742 if (floatp
? f1
== f2
: XINT (num1
) == XINT (num2
))
1747 if (floatp
? f1
!= f2
: XINT (num1
) != XINT (num2
))
1752 if (floatp
? f1
< f2
: XINT (num1
) < XINT (num2
))
1757 if (floatp
? f1
<= f2
: XINT (num1
) <= XINT (num2
))
1762 if (floatp
? f1
> f2
: XINT (num1
) > XINT (num2
))
1767 if (floatp
? f1
>= f2
: XINT (num1
) >= XINT (num2
))
1776 DEFUN ("=", Feqlsign
, Seqlsign
, 2, 2, 0,
1777 "T if two args, both numbers or markers, are equal.")
1779 register Lisp_Object num1
, num2
;
1781 return arithcompare (num1
, num2
, equal
);
1784 DEFUN ("<", Flss
, Slss
, 2, 2, 0,
1785 "T if first arg is less than second arg. Both must be numbers or markers.")
1787 register Lisp_Object num1
, num2
;
1789 return arithcompare (num1
, num2
, less
);
1792 DEFUN (">", Fgtr
, Sgtr
, 2, 2, 0,
1793 "T if first arg is greater than second arg. Both must be numbers or markers.")
1795 register Lisp_Object num1
, num2
;
1797 return arithcompare (num1
, num2
, grtr
);
1800 DEFUN ("<=", Fleq
, Sleq
, 2, 2, 0,
1801 "T if first arg is less than or equal to second arg.\n\
1802 Both must be numbers or markers.")
1804 register Lisp_Object num1
, num2
;
1806 return arithcompare (num1
, num2
, less_or_equal
);
1809 DEFUN (">=", Fgeq
, Sgeq
, 2, 2, 0,
1810 "T if first arg is greater than or equal to second arg.\n\
1811 Both must be numbers or markers.")
1813 register Lisp_Object num1
, num2
;
1815 return arithcompare (num1
, num2
, grtr_or_equal
);
1818 DEFUN ("/=", Fneq
, Sneq
, 2, 2, 0,
1819 "T if first arg is not equal to second arg. Both must be numbers or markers.")
1821 register Lisp_Object num1
, num2
;
1823 return arithcompare (num1
, num2
, notequal
);
1826 DEFUN ("zerop", Fzerop
, Szerop
, 1, 1, 0, "T if NUMBER is zero.")
1828 register Lisp_Object number
;
1830 #ifdef LISP_FLOAT_TYPE
1831 CHECK_NUMBER_OR_FLOAT (number
, 0);
1833 if (FLOATP (number
))
1835 if (XFLOAT(number
)->data
== 0.0)
1840 CHECK_NUMBER (number
, 0);
1841 #endif /* LISP_FLOAT_TYPE */
1848 /* Convert between long values and pairs of Lisp integers. */
1854 unsigned int top
= i
>> 16;
1855 unsigned int bot
= i
& 0xFFFF;
1857 return make_number (bot
);
1858 if (top
== (unsigned long)-1 >> 16)
1859 return Fcons (make_number (-1), make_number (bot
));
1860 return Fcons (make_number (top
), make_number (bot
));
1867 Lisp_Object top
, bot
;
1870 top
= XCONS (c
)->car
;
1871 bot
= XCONS (c
)->cdr
;
1873 bot
= XCONS (bot
)->car
;
1874 return ((XINT (top
) << 16) | XINT (bot
));
1877 DEFUN ("number-to-string", Fnumber_to_string
, Snumber_to_string
, 1, 1, 0,
1878 "Convert NUMBER to a string by printing it in decimal.\n\
1879 Uses a minus sign if negative.\n\
1880 NUMBER may be an integer or a floating point number.")
1884 char buffer
[VALBITS
];
1886 #ifndef LISP_FLOAT_TYPE
1887 CHECK_NUMBER (number
, 0);
1889 CHECK_NUMBER_OR_FLOAT (number
, 0);
1891 if (FLOATP (number
))
1893 char pigbuf
[350]; /* see comments in float_to_string */
1895 float_to_string (pigbuf
, XFLOAT(number
)->data
);
1896 return build_string (pigbuf
);
1898 #endif /* LISP_FLOAT_TYPE */
1900 if (sizeof (int) == sizeof (EMACS_INT
))
1901 sprintf (buffer
, "%d", XINT (number
));
1902 else if (sizeof (long) == sizeof (EMACS_INT
))
1903 sprintf (buffer
, "%ld", XINT (number
));
1906 return build_string (buffer
);
1909 DEFUN ("string-to-number", Fstring_to_number
, Sstring_to_number
, 1, 1, 0,
1910 "Convert STRING to a number by parsing it as a decimal number.\n\
1911 This parses both integers and floating point numbers.\n\
1912 It ignores leading spaces and tabs.")
1914 register Lisp_Object string
;
1919 CHECK_STRING (string
, 0);
1921 p
= XSTRING (string
)->data
;
1923 /* Skip any whitespace at the front of the number. Some versions of
1924 atoi do this anyway, so we might as well make Emacs lisp consistent. */
1925 while (*p
== ' ' || *p
== '\t')
1928 #ifdef LISP_FLOAT_TYPE
1929 if (isfloat_string (p
))
1930 return make_float (atof (p
));
1931 #endif /* LISP_FLOAT_TYPE */
1933 if (sizeof (int) == sizeof (EMACS_INT
))
1934 XSETINT (value
, atoi (p
));
1935 else if (sizeof (long) == sizeof (EMACS_INT
))
1936 XSETINT (value
, atol (p
));
1943 { Aadd
, Asub
, Amult
, Adiv
, Alogand
, Alogior
, Alogxor
, Amax
, Amin
};
1945 extern Lisp_Object
float_arith_driver ();
1948 arith_driver (code
, nargs
, args
)
1951 register Lisp_Object
*args
;
1953 register Lisp_Object val
;
1954 register int argnum
;
1955 register EMACS_INT accum
;
1956 register EMACS_INT next
;
1958 switch (SWITCH_ENUM_CAST (code
))
1971 for (argnum
= 0; argnum
< nargs
; argnum
++)
1973 val
= args
[argnum
]; /* using args[argnum] as argument to CHECK_NUMBER_... */
1974 #ifdef LISP_FLOAT_TYPE
1975 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
, argnum
);
1977 if (FLOATP (val
)) /* time to do serious math */
1978 return (float_arith_driver ((double) accum
, argnum
, code
,
1981 CHECK_NUMBER_COERCE_MARKER (val
, argnum
);
1982 #endif /* LISP_FLOAT_TYPE */
1983 args
[argnum
] = val
; /* runs into a compiler bug. */
1984 next
= XINT (args
[argnum
]);
1985 switch (SWITCH_ENUM_CAST (code
))
1987 case Aadd
: accum
+= next
; break;
1989 if (!argnum
&& nargs
!= 1)
1993 case Amult
: accum
*= next
; break;
1995 if (!argnum
) accum
= next
;
1999 Fsignal (Qarith_error
, Qnil
);
2003 case Alogand
: accum
&= next
; break;
2004 case Alogior
: accum
|= next
; break;
2005 case Alogxor
: accum
^= next
; break;
2006 case Amax
: if (!argnum
|| next
> accum
) accum
= next
; break;
2007 case Amin
: if (!argnum
|| next
< accum
) accum
= next
; break;
2011 XSETINT (val
, accum
);
2015 #ifdef LISP_FLOAT_TYPE
2018 #define isnan(x) ((x) != (x))
2021 float_arith_driver (accum
, argnum
, code
, nargs
, args
)
2023 register int argnum
;
2026 register Lisp_Object
*args
;
2028 register Lisp_Object val
;
2031 for (; argnum
< nargs
; argnum
++)
2033 val
= args
[argnum
]; /* using args[argnum] as argument to CHECK_NUMBER_... */
2034 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
, argnum
);
2038 next
= XFLOAT (val
)->data
;
2042 args
[argnum
] = val
; /* runs into a compiler bug. */
2043 next
= XINT (args
[argnum
]);
2045 switch (SWITCH_ENUM_CAST (code
))
2051 if (!argnum
&& nargs
!= 1)
2064 Fsignal (Qarith_error
, Qnil
);
2071 return wrong_type_argument (Qinteger_or_marker_p
, val
);
2073 if (!argnum
|| isnan (next
) || next
> accum
)
2077 if (!argnum
|| isnan (next
) || next
< accum
)
2083 return make_float (accum
);
2085 #endif /* LISP_FLOAT_TYPE */
2087 DEFUN ("+", Fplus
, Splus
, 0, MANY
, 0,
2088 "Return sum of any number of arguments, which are numbers or markers.")
2093 return arith_driver (Aadd
, nargs
, args
);
2096 DEFUN ("-", Fminus
, Sminus
, 0, MANY
, 0,
2097 "Negate number or subtract numbers or markers.\n\
2098 With one arg, negates it. With more than one arg,\n\
2099 subtracts all but the first from the first.")
2104 return arith_driver (Asub
, nargs
, args
);
2107 DEFUN ("*", Ftimes
, Stimes
, 0, MANY
, 0,
2108 "Returns product of any number of arguments, which are numbers or markers.")
2113 return arith_driver (Amult
, nargs
, args
);
2116 DEFUN ("/", Fquo
, Squo
, 2, MANY
, 0,
2117 "Returns first argument divided by all the remaining arguments.\n\
2118 The arguments must be numbers or markers.")
2123 return arith_driver (Adiv
, nargs
, args
);
2126 DEFUN ("%", Frem
, Srem
, 2, 2, 0,
2127 "Returns remainder of X divided by Y.\n\
2128 Both must be integers or markers.")
2130 register Lisp_Object x
, y
;
2134 CHECK_NUMBER_COERCE_MARKER (x
, 0);
2135 CHECK_NUMBER_COERCE_MARKER (y
, 1);
2137 if (XFASTINT (y
) == 0)
2138 Fsignal (Qarith_error
, Qnil
);
2140 XSETINT (val
, XINT (x
) % XINT (y
));
2151 return (f1
- f2
* floor (f1
/f2
));
2153 #endif /* ! HAVE_FMOD */
2155 DEFUN ("mod", Fmod
, Smod
, 2, 2, 0,
2156 "Returns X modulo Y.\n\
2157 The result falls between zero (inclusive) and Y (exclusive).\n\
2158 Both X and Y must be numbers or markers.")
2160 register Lisp_Object x
, y
;
2165 #ifdef LISP_FLOAT_TYPE
2166 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x
, 0);
2167 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y
, 1);
2169 if (FLOATP (x
) || FLOATP (y
))
2173 f1
= FLOATP (x
) ? XFLOAT (x
)->data
: XINT (x
);
2174 f2
= FLOATP (y
) ? XFLOAT (y
)->data
: XINT (y
);
2176 Fsignal (Qarith_error
, Qnil
);
2179 /* If the "remainder" comes out with the wrong sign, fix it. */
2180 if (f2
< 0 ? f1
> 0 : f1
< 0)
2182 return (make_float (f1
));
2184 #else /* not LISP_FLOAT_TYPE */
2185 CHECK_NUMBER_COERCE_MARKER (x
, 0);
2186 CHECK_NUMBER_COERCE_MARKER (y
, 1);
2187 #endif /* not LISP_FLOAT_TYPE */
2193 Fsignal (Qarith_error
, Qnil
);
2197 /* If the "remainder" comes out with the wrong sign, fix it. */
2198 if (i2
< 0 ? i1
> 0 : i1
< 0)
2205 DEFUN ("max", Fmax
, Smax
, 1, MANY
, 0,
2206 "Return largest of all the arguments (which must be numbers or markers).\n\
2207 The value is always a number; markers are converted to numbers.")
2212 return arith_driver (Amax
, nargs
, args
);
2215 DEFUN ("min", Fmin
, Smin
, 1, MANY
, 0,
2216 "Return smallest of all the arguments (which must be numbers or markers).\n\
2217 The value is always a number; markers are converted to numbers.")
2222 return arith_driver (Amin
, nargs
, args
);
2225 DEFUN ("logand", Flogand
, Slogand
, 0, MANY
, 0,
2226 "Return bitwise-and of all the arguments.\n\
2227 Arguments may be integers, or markers converted to integers.")
2232 return arith_driver (Alogand
, nargs
, args
);
2235 DEFUN ("logior", Flogior
, Slogior
, 0, MANY
, 0,
2236 "Return bitwise-or of all the arguments.\n\
2237 Arguments may be integers, or markers converted to integers.")
2242 return arith_driver (Alogior
, nargs
, args
);
2245 DEFUN ("logxor", Flogxor
, Slogxor
, 0, MANY
, 0,
2246 "Return bitwise-exclusive-or of all the arguments.\n\
2247 Arguments may be integers, or markers converted to integers.")
2252 return arith_driver (Alogxor
, nargs
, args
);
2255 DEFUN ("ash", Fash
, Sash
, 2, 2, 0,
2256 "Return VALUE with its bits shifted left by COUNT.\n\
2257 If COUNT is negative, shifting is actually to the right.\n\
2258 In this case, the sign bit is duplicated.")
2260 register Lisp_Object value
, count
;
2262 register Lisp_Object val
;
2264 CHECK_NUMBER (value
, 0);
2265 CHECK_NUMBER (count
, 1);
2267 if (XINT (count
) > 0)
2268 XSETINT (val
, XINT (value
) << XFASTINT (count
));
2270 XSETINT (val
, XINT (value
) >> -XINT (count
));
2274 DEFUN ("lsh", Flsh
, Slsh
, 2, 2, 0,
2275 "Return VALUE with its bits shifted left by COUNT.\n\
2276 If COUNT is negative, shifting is actually to the right.\n\
2277 In this case, zeros are shifted in on the left.")
2279 register Lisp_Object value
, count
;
2281 register Lisp_Object val
;
2283 CHECK_NUMBER (value
, 0);
2284 CHECK_NUMBER (count
, 1);
2286 if (XINT (count
) > 0)
2287 XSETINT (val
, (EMACS_UINT
) XUINT (value
) << XFASTINT (count
));
2289 XSETINT (val
, (EMACS_UINT
) XUINT (value
) >> -XINT (count
));
2293 DEFUN ("1+", Fadd1
, Sadd1
, 1, 1, 0,
2294 "Return NUMBER plus one. NUMBER may be a number or a marker.\n\
2295 Markers are converted to integers.")
2297 register Lisp_Object number
;
2299 #ifdef LISP_FLOAT_TYPE
2300 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
, 0);
2302 if (FLOATP (number
))
2303 return (make_float (1.0 + XFLOAT (number
)->data
));
2305 CHECK_NUMBER_COERCE_MARKER (number
, 0);
2306 #endif /* LISP_FLOAT_TYPE */
2308 XSETINT (number
, XINT (number
) + 1);
2312 DEFUN ("1-", Fsub1
, Ssub1
, 1, 1, 0,
2313 "Return NUMBER minus one. NUMBER may be a number or a marker.\n\
2314 Markers are converted to integers.")
2316 register Lisp_Object number
;
2318 #ifdef LISP_FLOAT_TYPE
2319 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
, 0);
2321 if (FLOATP (number
))
2322 return (make_float (-1.0 + XFLOAT (number
)->data
));
2324 CHECK_NUMBER_COERCE_MARKER (number
, 0);
2325 #endif /* LISP_FLOAT_TYPE */
2327 XSETINT (number
, XINT (number
) - 1);
2331 DEFUN ("lognot", Flognot
, Slognot
, 1, 1, 0,
2332 "Return the bitwise complement of NUMBER. NUMBER must be an integer.")
2334 register Lisp_Object number
;
2336 CHECK_NUMBER (number
, 0);
2337 XSETINT (number
, ~XINT (number
));
2344 Lisp_Object error_tail
, arith_tail
;
2346 Qquote
= intern ("quote");
2347 Qlambda
= intern ("lambda");
2348 Qsubr
= intern ("subr");
2349 Qerror_conditions
= intern ("error-conditions");
2350 Qerror_message
= intern ("error-message");
2351 Qtop_level
= intern ("top-level");
2353 Qerror
= intern ("error");
2354 Qquit
= intern ("quit");
2355 Qwrong_type_argument
= intern ("wrong-type-argument");
2356 Qargs_out_of_range
= intern ("args-out-of-range");
2357 Qvoid_function
= intern ("void-function");
2358 Qcyclic_function_indirection
= intern ("cyclic-function-indirection");
2359 Qvoid_variable
= intern ("void-variable");
2360 Qsetting_constant
= intern ("setting-constant");
2361 Qinvalid_read_syntax
= intern ("invalid-read-syntax");
2363 Qinvalid_function
= intern ("invalid-function");
2364 Qwrong_number_of_arguments
= intern ("wrong-number-of-arguments");
2365 Qno_catch
= intern ("no-catch");
2366 Qend_of_file
= intern ("end-of-file");
2367 Qarith_error
= intern ("arith-error");
2368 Qbeginning_of_buffer
= intern ("beginning-of-buffer");
2369 Qend_of_buffer
= intern ("end-of-buffer");
2370 Qbuffer_read_only
= intern ("buffer-read-only");
2371 Qmark_inactive
= intern ("mark-inactive");
2373 Qlistp
= intern ("listp");
2374 Qconsp
= intern ("consp");
2375 Qsymbolp
= intern ("symbolp");
2376 Qintegerp
= intern ("integerp");
2377 Qnatnump
= intern ("natnump");
2378 Qwholenump
= intern ("wholenump");
2379 Qstringp
= intern ("stringp");
2380 Qarrayp
= intern ("arrayp");
2381 Qsequencep
= intern ("sequencep");
2382 Qbufferp
= intern ("bufferp");
2383 Qvectorp
= intern ("vectorp");
2384 Qchar_or_string_p
= intern ("char-or-string-p");
2385 Qmarkerp
= intern ("markerp");
2386 Qbuffer_or_string_p
= intern ("buffer-or-string-p");
2387 Qinteger_or_marker_p
= intern ("integer-or-marker-p");
2388 Qboundp
= intern ("boundp");
2389 Qfboundp
= intern ("fboundp");
2391 #ifdef LISP_FLOAT_TYPE
2392 Qfloatp
= intern ("floatp");
2393 Qnumberp
= intern ("numberp");
2394 Qnumber_or_marker_p
= intern ("number-or-marker-p");
2395 #endif /* LISP_FLOAT_TYPE */
2397 Qchar_table_p
= intern ("char-table-p");
2398 Qvector_or_char_table_p
= intern ("vector-or-char-table-p");
2400 Qcdr
= intern ("cdr");
2402 /* Handle automatic advice activation */
2403 Qad_advice_info
= intern ("ad-advice-info");
2404 Qad_activate
= intern ("ad-activate");
2406 error_tail
= Fcons (Qerror
, Qnil
);
2408 /* ERROR is used as a signaler for random errors for which nothing else is right */
2410 Fput (Qerror
, Qerror_conditions
,
2412 Fput (Qerror
, Qerror_message
,
2413 build_string ("error"));
2415 Fput (Qquit
, Qerror_conditions
,
2416 Fcons (Qquit
, Qnil
));
2417 Fput (Qquit
, Qerror_message
,
2418 build_string ("Quit"));
2420 Fput (Qwrong_type_argument
, Qerror_conditions
,
2421 Fcons (Qwrong_type_argument
, error_tail
));
2422 Fput (Qwrong_type_argument
, Qerror_message
,
2423 build_string ("Wrong type argument"));
2425 Fput (Qargs_out_of_range
, Qerror_conditions
,
2426 Fcons (Qargs_out_of_range
, error_tail
));
2427 Fput (Qargs_out_of_range
, Qerror_message
,
2428 build_string ("Args out of range"));
2430 Fput (Qvoid_function
, Qerror_conditions
,
2431 Fcons (Qvoid_function
, error_tail
));
2432 Fput (Qvoid_function
, Qerror_message
,
2433 build_string ("Symbol's function definition is void"));
2435 Fput (Qcyclic_function_indirection
, Qerror_conditions
,
2436 Fcons (Qcyclic_function_indirection
, error_tail
));
2437 Fput (Qcyclic_function_indirection
, Qerror_message
,
2438 build_string ("Symbol's chain of function indirections contains a loop"));
2440 Fput (Qvoid_variable
, Qerror_conditions
,
2441 Fcons (Qvoid_variable
, error_tail
));
2442 Fput (Qvoid_variable
, Qerror_message
,
2443 build_string ("Symbol's value as variable is void"));
2445 Fput (Qsetting_constant
, Qerror_conditions
,
2446 Fcons (Qsetting_constant
, error_tail
));
2447 Fput (Qsetting_constant
, Qerror_message
,
2448 build_string ("Attempt to set a constant symbol"));
2450 Fput (Qinvalid_read_syntax
, Qerror_conditions
,
2451 Fcons (Qinvalid_read_syntax
, error_tail
));
2452 Fput (Qinvalid_read_syntax
, Qerror_message
,
2453 build_string ("Invalid read syntax"));
2455 Fput (Qinvalid_function
, Qerror_conditions
,
2456 Fcons (Qinvalid_function
, error_tail
));
2457 Fput (Qinvalid_function
, Qerror_message
,
2458 build_string ("Invalid function"));
2460 Fput (Qwrong_number_of_arguments
, Qerror_conditions
,
2461 Fcons (Qwrong_number_of_arguments
, error_tail
));
2462 Fput (Qwrong_number_of_arguments
, Qerror_message
,
2463 build_string ("Wrong number of arguments"));
2465 Fput (Qno_catch
, Qerror_conditions
,
2466 Fcons (Qno_catch
, error_tail
));
2467 Fput (Qno_catch
, Qerror_message
,
2468 build_string ("No catch for tag"));
2470 Fput (Qend_of_file
, Qerror_conditions
,
2471 Fcons (Qend_of_file
, error_tail
));
2472 Fput (Qend_of_file
, Qerror_message
,
2473 build_string ("End of file during parsing"));
2475 arith_tail
= Fcons (Qarith_error
, error_tail
);
2476 Fput (Qarith_error
, Qerror_conditions
,
2478 Fput (Qarith_error
, Qerror_message
,
2479 build_string ("Arithmetic error"));
2481 Fput (Qbeginning_of_buffer
, Qerror_conditions
,
2482 Fcons (Qbeginning_of_buffer
, error_tail
));
2483 Fput (Qbeginning_of_buffer
, Qerror_message
,
2484 build_string ("Beginning of buffer"));
2486 Fput (Qend_of_buffer
, Qerror_conditions
,
2487 Fcons (Qend_of_buffer
, error_tail
));
2488 Fput (Qend_of_buffer
, Qerror_message
,
2489 build_string ("End of buffer"));
2491 Fput (Qbuffer_read_only
, Qerror_conditions
,
2492 Fcons (Qbuffer_read_only
, error_tail
));
2493 Fput (Qbuffer_read_only
, Qerror_message
,
2494 build_string ("Buffer is read-only"));
2496 #ifdef LISP_FLOAT_TYPE
2497 Qrange_error
= intern ("range-error");
2498 Qdomain_error
= intern ("domain-error");
2499 Qsingularity_error
= intern ("singularity-error");
2500 Qoverflow_error
= intern ("overflow-error");
2501 Qunderflow_error
= intern ("underflow-error");
2503 Fput (Qdomain_error
, Qerror_conditions
,
2504 Fcons (Qdomain_error
, arith_tail
));
2505 Fput (Qdomain_error
, Qerror_message
,
2506 build_string ("Arithmetic domain error"));
2508 Fput (Qrange_error
, Qerror_conditions
,
2509 Fcons (Qrange_error
, arith_tail
));
2510 Fput (Qrange_error
, Qerror_message
,
2511 build_string ("Arithmetic range error"));
2513 Fput (Qsingularity_error
, Qerror_conditions
,
2514 Fcons (Qsingularity_error
, Fcons (Qdomain_error
, arith_tail
)));
2515 Fput (Qsingularity_error
, Qerror_message
,
2516 build_string ("Arithmetic singularity error"));
2518 Fput (Qoverflow_error
, Qerror_conditions
,
2519 Fcons (Qoverflow_error
, Fcons (Qdomain_error
, arith_tail
)));
2520 Fput (Qoverflow_error
, Qerror_message
,
2521 build_string ("Arithmetic overflow error"));
2523 Fput (Qunderflow_error
, Qerror_conditions
,
2524 Fcons (Qunderflow_error
, Fcons (Qdomain_error
, arith_tail
)));
2525 Fput (Qunderflow_error
, Qerror_message
,
2526 build_string ("Arithmetic underflow error"));
2528 staticpro (&Qrange_error
);
2529 staticpro (&Qdomain_error
);
2530 staticpro (&Qsingularity_error
);
2531 staticpro (&Qoverflow_error
);
2532 staticpro (&Qunderflow_error
);
2533 #endif /* LISP_FLOAT_TYPE */
2537 staticpro (&Qquote
);
2538 staticpro (&Qlambda
);
2540 staticpro (&Qunbound
);
2541 staticpro (&Qerror_conditions
);
2542 staticpro (&Qerror_message
);
2543 staticpro (&Qtop_level
);
2545 staticpro (&Qerror
);
2547 staticpro (&Qwrong_type_argument
);
2548 staticpro (&Qargs_out_of_range
);
2549 staticpro (&Qvoid_function
);
2550 staticpro (&Qcyclic_function_indirection
);
2551 staticpro (&Qvoid_variable
);
2552 staticpro (&Qsetting_constant
);
2553 staticpro (&Qinvalid_read_syntax
);
2554 staticpro (&Qwrong_number_of_arguments
);
2555 staticpro (&Qinvalid_function
);
2556 staticpro (&Qno_catch
);
2557 staticpro (&Qend_of_file
);
2558 staticpro (&Qarith_error
);
2559 staticpro (&Qbeginning_of_buffer
);
2560 staticpro (&Qend_of_buffer
);
2561 staticpro (&Qbuffer_read_only
);
2562 staticpro (&Qmark_inactive
);
2564 staticpro (&Qlistp
);
2565 staticpro (&Qconsp
);
2566 staticpro (&Qsymbolp
);
2567 staticpro (&Qintegerp
);
2568 staticpro (&Qnatnump
);
2569 staticpro (&Qwholenump
);
2570 staticpro (&Qstringp
);
2571 staticpro (&Qarrayp
);
2572 staticpro (&Qsequencep
);
2573 staticpro (&Qbufferp
);
2574 staticpro (&Qvectorp
);
2575 staticpro (&Qchar_or_string_p
);
2576 staticpro (&Qmarkerp
);
2577 staticpro (&Qbuffer_or_string_p
);
2578 staticpro (&Qinteger_or_marker_p
);
2579 #ifdef LISP_FLOAT_TYPE
2580 staticpro (&Qfloatp
);
2581 staticpro (&Qnumberp
);
2582 staticpro (&Qnumber_or_marker_p
);
2583 #endif /* LISP_FLOAT_TYPE */
2584 staticpro (&Qchar_table_p
);
2585 staticpro (&Qvector_or_char_table_p
);
2587 staticpro (&Qboundp
);
2588 staticpro (&Qfboundp
);
2590 staticpro (&Qad_advice_info
);
2591 staticpro (&Qad_activate
);
2593 /* Types that type-of returns. */
2594 Qinteger
= intern ("integer");
2595 Qsymbol
= intern ("symbol");
2596 Qstring
= intern ("string");
2597 Qcons
= intern ("cons");
2598 Qmarker
= intern ("marker");
2599 Qoverlay
= intern ("overlay");
2600 Qfloat
= intern ("float");
2601 Qwindow_configuration
= intern ("window-configuration");
2602 Qprocess
= intern ("process");
2603 Qwindow
= intern ("window");
2604 /* Qsubr = intern ("subr"); */
2605 Qcompiled_function
= intern ("compiled-function");
2606 Qbuffer
= intern ("buffer");
2607 Qframe
= intern ("frame");
2608 Qvector
= intern ("vector");
2609 Qchar_table
= intern ("char-table");
2610 Qbool_vector
= intern ("bool-vector");
2612 staticpro (&Qinteger
);
2613 staticpro (&Qsymbol
);
2614 staticpro (&Qstring
);
2616 staticpro (&Qmarker
);
2617 staticpro (&Qoverlay
);
2618 staticpro (&Qfloat
);
2619 staticpro (&Qwindow_configuration
);
2620 staticpro (&Qprocess
);
2621 staticpro (&Qwindow
);
2622 /* staticpro (&Qsubr); */
2623 staticpro (&Qcompiled_function
);
2624 staticpro (&Qbuffer
);
2625 staticpro (&Qframe
);
2626 staticpro (&Qvector
);
2627 staticpro (&Qchar_table
);
2628 staticpro (&Qbool_vector
);
2632 defsubr (&Stype_of
);
2637 defsubr (&Sintegerp
);
2638 defsubr (&Sinteger_or_marker_p
);
2639 defsubr (&Snumberp
);
2640 defsubr (&Snumber_or_marker_p
);
2641 #ifdef LISP_FLOAT_TYPE
2643 #endif /* LISP_FLOAT_TYPE */
2644 defsubr (&Snatnump
);
2645 defsubr (&Ssymbolp
);
2646 defsubr (&Sstringp
);
2647 defsubr (&Svectorp
);
2648 defsubr (&Schar_table_p
);
2649 defsubr (&Svector_or_char_table_p
);
2650 defsubr (&Sbool_vector_p
);
2652 defsubr (&Ssequencep
);
2653 defsubr (&Sbufferp
);
2654 defsubr (&Smarkerp
);
2656 defsubr (&Sbyte_code_function_p
);
2657 defsubr (&Schar_or_string_p
);
2660 defsubr (&Scar_safe
);
2661 defsubr (&Scdr_safe
);
2664 defsubr (&Ssymbol_function
);
2665 defsubr (&Sindirect_function
);
2666 defsubr (&Ssymbol_plist
);
2667 defsubr (&Ssymbol_name
);
2668 defsubr (&Smakunbound
);
2669 defsubr (&Sfmakunbound
);
2671 defsubr (&Sfboundp
);
2673 defsubr (&Sdefalias
);
2674 defsubr (&Sdefine_function
);
2675 defsubr (&Ssetplist
);
2676 defsubr (&Ssymbol_value
);
2678 defsubr (&Sdefault_boundp
);
2679 defsubr (&Sdefault_value
);
2680 defsubr (&Sset_default
);
2681 defsubr (&Ssetq_default
);
2682 defsubr (&Smake_variable_buffer_local
);
2683 defsubr (&Smake_local_variable
);
2684 defsubr (&Skill_local_variable
);
2685 defsubr (&Slocal_variable_p
);
2686 defsubr (&Slocal_variable_if_set_p
);
2689 defsubr (&Snumber_to_string
);
2690 defsubr (&Sstring_to_number
);
2691 defsubr (&Seqlsign
);
2715 XSYMBOL (Qwholenump
)->function
= XSYMBOL (Qnatnump
)->function
;
2723 /* USG systems forget handlers when they are used;
2724 must reestablish each time */
2725 signal (signo
, arith_error
);
2728 /* VMS systems are like USG. */
2729 signal (signo
, arith_error
);
2733 #else /* not BSD4_1 */
2734 sigsetmask (SIGEMPTYMASK
);
2735 #endif /* not BSD4_1 */
2737 Fsignal (Qarith_error
, Qnil
);
2742 /* Don't do this if just dumping out.
2743 We don't want to call `signal' in this case
2744 so that we don't have trouble with dumping
2745 signal-delivering routines in an inconsistent state. */
2749 #endif /* CANNOT_DUMP */
2750 signal (SIGFPE
, arith_error
);
2753 signal (SIGEMT
, arith_error
);