1 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2014 Free Software
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 3 of the License, or
10 (at your option) any later version.
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. If not, see <http://www.gnu.org/licenses/>. */
25 #include <count-one-bits.h>
26 #include <count-trailing-zeros.h>
31 #include "character.h"
35 #include "syssignal.h"
36 #include "termhooks.h" /* For FRAME_KBOARD reference in y-or-n-p. */
40 Lisp_Object Qnil
, Qt
, Qquote
, Qlambda
, Qunbound
;
41 static Lisp_Object Qsubr
;
42 Lisp_Object Qerror_conditions
, Qerror_message
, Qtop_level
;
43 Lisp_Object Qerror
, Quser_error
, Qquit
, Qargs_out_of_range
;
44 static Lisp_Object Qwrong_length_argument
;
45 static Lisp_Object Qwrong_type_argument
;
46 Lisp_Object Qvoid_variable
, Qvoid_function
;
47 static Lisp_Object Qcyclic_function_indirection
;
48 static Lisp_Object Qcyclic_variable_indirection
;
49 Lisp_Object Qcircular_list
;
50 static Lisp_Object Qsetting_constant
;
51 Lisp_Object Qinvalid_read_syntax
;
52 Lisp_Object Qinvalid_function
, Qwrong_number_of_arguments
, Qno_catch
;
53 Lisp_Object Qend_of_file
, Qarith_error
, Qmark_inactive
;
54 Lisp_Object Qbeginning_of_buffer
, Qend_of_buffer
, Qbuffer_read_only
;
55 Lisp_Object Qtext_read_only
;
57 Lisp_Object Qintegerp
, Qwholenump
, Qsymbolp
, Qlistp
, Qconsp
;
58 static Lisp_Object Qnatnump
;
59 Lisp_Object Qstringp
, Qarrayp
, Qsequencep
, Qbufferp
;
60 Lisp_Object Qchar_or_string_p
, Qmarkerp
, Qinteger_or_marker_p
, Qvectorp
;
61 Lisp_Object Qbool_vector_p
;
62 Lisp_Object Qbuffer_or_string_p
;
63 static Lisp_Object Qkeywordp
, Qboundp
;
65 Lisp_Object Qchar_table_p
, Qvector_or_char_table_p
;
68 static Lisp_Object Qad_advice_info
, Qad_activate_internal
;
70 static Lisp_Object Qdomain_error
, Qsingularity_error
, Qunderflow_error
;
71 Lisp_Object Qrange_error
, Qoverflow_error
;
74 Lisp_Object Qnumberp
, Qnumber_or_marker_p
;
76 Lisp_Object Qinteger
, Qsymbol
;
77 static Lisp_Object Qcons
, Qfloat
, Qmisc
, Qstring
, Qvector
;
79 static Lisp_Object Qoverlay
, Qwindow_configuration
;
80 static Lisp_Object Qprocess
, Qmarker
;
81 static Lisp_Object Qcompiled_function
, Qframe
;
83 static Lisp_Object Qchar_table
, Qbool_vector
, Qhash_table
;
84 static Lisp_Object Qsubrp
;
85 static Lisp_Object Qmany
, Qunevalled
;
86 Lisp_Object Qfont_spec
, Qfont_entity
, Qfont_object
;
87 static Lisp_Object Qdefun
;
89 Lisp_Object Qinteractive_form
;
90 static Lisp_Object Qdefalias_fset_function
;
92 static void swap_in_symval_forwarding (struct Lisp_Symbol
*,
93 struct Lisp_Buffer_Local_Value
*);
96 BOOLFWDP (union Lisp_Fwd
*a
)
98 return XFWDTYPE (a
) == Lisp_Fwd_Bool
;
101 INTFWDP (union Lisp_Fwd
*a
)
103 return XFWDTYPE (a
) == Lisp_Fwd_Int
;
106 KBOARD_OBJFWDP (union Lisp_Fwd
*a
)
108 return XFWDTYPE (a
) == Lisp_Fwd_Kboard_Obj
;
111 OBJFWDP (union Lisp_Fwd
*a
)
113 return XFWDTYPE (a
) == Lisp_Fwd_Obj
;
116 static struct Lisp_Boolfwd
*
117 XBOOLFWD (union Lisp_Fwd
*a
)
119 eassert (BOOLFWDP (a
));
120 return &a
->u_boolfwd
;
122 static struct Lisp_Kboard_Objfwd
*
123 XKBOARD_OBJFWD (union Lisp_Fwd
*a
)
125 eassert (KBOARD_OBJFWDP (a
));
126 return &a
->u_kboard_objfwd
;
128 static struct Lisp_Intfwd
*
129 XINTFWD (union Lisp_Fwd
*a
)
131 eassert (INTFWDP (a
));
134 static struct Lisp_Objfwd
*
135 XOBJFWD (union Lisp_Fwd
*a
)
137 eassert (OBJFWDP (a
));
142 CHECK_SUBR (Lisp_Object x
)
144 CHECK_TYPE (SUBRP (x
), Qsubrp
, x
);
148 set_blv_found (struct Lisp_Buffer_Local_Value
*blv
, int found
)
150 eassert (found
== !EQ (blv
->defcell
, blv
->valcell
));
155 blv_value (struct Lisp_Buffer_Local_Value
*blv
)
157 return XCDR (blv
->valcell
);
161 set_blv_value (struct Lisp_Buffer_Local_Value
*blv
, Lisp_Object val
)
163 XSETCDR (blv
->valcell
, val
);
167 set_blv_where (struct Lisp_Buffer_Local_Value
*blv
, Lisp_Object val
)
173 set_blv_defcell (struct Lisp_Buffer_Local_Value
*blv
, Lisp_Object val
)
179 set_blv_valcell (struct Lisp_Buffer_Local_Value
*blv
, Lisp_Object val
)
184 static _Noreturn
void
185 wrong_length_argument (Lisp_Object a1
, Lisp_Object a2
, Lisp_Object a3
)
187 Lisp_Object size1
= make_number (bool_vector_size (a1
));
188 Lisp_Object size2
= make_number (bool_vector_size (a2
));
190 xsignal2 (Qwrong_length_argument
, size1
, size2
);
192 xsignal3 (Qwrong_length_argument
, size1
, size2
,
193 make_number (bool_vector_size (a3
)));
197 wrong_type_argument (register Lisp_Object predicate
, register Lisp_Object value
)
199 /* If VALUE is not even a valid Lisp object, we'd want to abort here
200 where we can get a backtrace showing where it came from. We used
201 to try and do that by checking the tagbits, but nowadays all
202 tagbits are potentially valid. */
203 /* if ((unsigned int) XTYPE (value) >= Lisp_Type_Limit)
206 xsignal2 (Qwrong_type_argument
, predicate
, value
);
210 pure_write_error (Lisp_Object obj
)
212 xsignal2 (Qerror
, build_string ("Attempt to modify read-only object"), obj
);
216 args_out_of_range (Lisp_Object a1
, Lisp_Object a2
)
218 xsignal2 (Qargs_out_of_range
, a1
, a2
);
222 args_out_of_range_3 (Lisp_Object a1
, Lisp_Object a2
, Lisp_Object a3
)
224 xsignal3 (Qargs_out_of_range
, a1
, a2
, a3
);
228 /* Data type predicates. */
230 DEFUN ("eq", Feq
, Seq
, 2, 2, 0,
231 doc
: /* Return t if the two args are the same Lisp object. */)
232 (Lisp_Object obj1
, Lisp_Object obj2
)
239 DEFUN ("null", Fnull
, Snull
, 1, 1, 0,
240 doc
: /* Return t if OBJECT is nil. */)
248 DEFUN ("type-of", Ftype_of
, Stype_of
, 1, 1, 0,
249 doc
: /* Return a symbol representing the type of OBJECT.
250 The symbol returned names the object's basic type;
251 for example, (type-of 1) returns `integer'. */)
254 switch (XTYPE (object
))
269 switch (XMISCTYPE (object
))
271 case Lisp_Misc_Marker
:
273 case Lisp_Misc_Overlay
:
275 case Lisp_Misc_Float
:
280 case Lisp_Vectorlike
:
281 if (WINDOW_CONFIGURATIONP (object
))
282 return Qwindow_configuration
;
283 if (PROCESSP (object
))
285 if (WINDOWP (object
))
289 if (COMPILEDP (object
))
290 return Qcompiled_function
;
291 if (BUFFERP (object
))
293 if (CHAR_TABLE_P (object
))
295 if (BOOL_VECTOR_P (object
))
299 if (HASH_TABLE_P (object
))
301 if (FONT_SPEC_P (object
))
303 if (FONT_ENTITY_P (object
))
305 if (FONT_OBJECT_P (object
))
317 DEFUN ("consp", Fconsp
, Sconsp
, 1, 1, 0,
318 doc
: /* Return t if OBJECT is a cons cell. */)
326 DEFUN ("atom", Fatom
, Satom
, 1, 1, 0,
327 doc
: /* Return t if OBJECT is not a cons cell. This includes nil. */)
335 DEFUN ("listp", Flistp
, Slistp
, 1, 1, 0,
336 doc
: /* Return t if OBJECT is a list, that is, a cons cell or nil.
337 Otherwise, return nil. */)
340 if (CONSP (object
) || NILP (object
))
345 DEFUN ("nlistp", Fnlistp
, Snlistp
, 1, 1, 0,
346 doc
: /* Return t if OBJECT is not a list. Lists include nil. */)
349 if (CONSP (object
) || NILP (object
))
354 DEFUN ("symbolp", Fsymbolp
, Ssymbolp
, 1, 1, 0,
355 doc
: /* Return t if OBJECT is a symbol. */)
358 if (SYMBOLP (object
))
363 /* Define this in C to avoid unnecessarily consing up the symbol
365 DEFUN ("keywordp", Fkeywordp
, Skeywordp
, 1, 1, 0,
366 doc
: /* Return t if OBJECT is a keyword.
367 This means that it is a symbol with a print name beginning with `:'
368 interned in the initial obarray. */)
372 && SREF (SYMBOL_NAME (object
), 0) == ':'
373 && SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P (object
))
378 DEFUN ("vectorp", Fvectorp
, Svectorp
, 1, 1, 0,
379 doc
: /* Return t if OBJECT is a vector. */)
382 if (VECTORP (object
))
387 DEFUN ("stringp", Fstringp
, Sstringp
, 1, 1, 0,
388 doc
: /* Return t if OBJECT is a string. */)
391 if (STRINGP (object
))
396 DEFUN ("multibyte-string-p", Fmultibyte_string_p
, Smultibyte_string_p
,
398 doc
: /* Return t if OBJECT is a multibyte string.
399 Return nil if OBJECT is either a unibyte string, or not a string. */)
402 if (STRINGP (object
) && STRING_MULTIBYTE (object
))
407 DEFUN ("char-table-p", Fchar_table_p
, Schar_table_p
, 1, 1, 0,
408 doc
: /* Return t if OBJECT is a char-table. */)
411 if (CHAR_TABLE_P (object
))
416 DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p
,
417 Svector_or_char_table_p
, 1, 1, 0,
418 doc
: /* Return t if OBJECT is a char-table or vector. */)
421 if (VECTORP (object
) || CHAR_TABLE_P (object
))
426 DEFUN ("bool-vector-p", Fbool_vector_p
, Sbool_vector_p
, 1, 1, 0,
427 doc
: /* Return t if OBJECT is a bool-vector. */)
430 if (BOOL_VECTOR_P (object
))
435 DEFUN ("arrayp", Farrayp
, Sarrayp
, 1, 1, 0,
436 doc
: /* Return t if OBJECT is an array (string or vector). */)
444 DEFUN ("sequencep", Fsequencep
, Ssequencep
, 1, 1, 0,
445 doc
: /* Return t if OBJECT is a sequence (list or array). */)
446 (register Lisp_Object object
)
448 if (CONSP (object
) || NILP (object
) || ARRAYP (object
))
453 DEFUN ("bufferp", Fbufferp
, Sbufferp
, 1, 1, 0,
454 doc
: /* Return t if OBJECT is an editor buffer. */)
457 if (BUFFERP (object
))
462 DEFUN ("markerp", Fmarkerp
, Smarkerp
, 1, 1, 0,
463 doc
: /* Return t if OBJECT is a marker (editor pointer). */)
466 if (MARKERP (object
))
471 DEFUN ("subrp", Fsubrp
, Ssubrp
, 1, 1, 0,
472 doc
: /* Return t if OBJECT is a built-in function. */)
480 DEFUN ("byte-code-function-p", Fbyte_code_function_p
, Sbyte_code_function_p
,
482 doc
: /* Return t if OBJECT is a byte-compiled function object. */)
485 if (COMPILEDP (object
))
490 DEFUN ("char-or-string-p", Fchar_or_string_p
, Schar_or_string_p
, 1, 1, 0,
491 doc
: /* Return t if OBJECT is a character or a string. */)
492 (register Lisp_Object object
)
494 if (CHARACTERP (object
) || STRINGP (object
))
499 DEFUN ("integerp", Fintegerp
, Sintegerp
, 1, 1, 0,
500 doc
: /* Return t if OBJECT is an integer. */)
503 if (INTEGERP (object
))
508 DEFUN ("integer-or-marker-p", Finteger_or_marker_p
, Sinteger_or_marker_p
, 1, 1, 0,
509 doc
: /* Return t if OBJECT is an integer or a marker (editor pointer). */)
510 (register Lisp_Object object
)
512 if (MARKERP (object
) || INTEGERP (object
))
517 DEFUN ("natnump", Fnatnump
, Snatnump
, 1, 1, 0,
518 doc
: /* Return t if OBJECT is a nonnegative integer. */)
521 if (NATNUMP (object
))
526 DEFUN ("numberp", Fnumberp
, Snumberp
, 1, 1, 0,
527 doc
: /* Return t if OBJECT is a number (floating point or integer). */)
530 if (NUMBERP (object
))
536 DEFUN ("number-or-marker-p", Fnumber_or_marker_p
,
537 Snumber_or_marker_p
, 1, 1, 0,
538 doc
: /* Return t if OBJECT is a number or a marker. */)
541 if (NUMBERP (object
) || MARKERP (object
))
546 DEFUN ("floatp", Ffloatp
, Sfloatp
, 1, 1, 0,
547 doc
: /* Return t if OBJECT is a floating point number. */)
556 /* Extract and set components of lists. */
558 DEFUN ("car", Fcar
, Scar
, 1, 1, 0,
559 doc
: /* Return the car of LIST. If arg is nil, return nil.
560 Error if arg is not nil and not a cons cell. See also `car-safe'.
562 See Info node `(elisp)Cons Cells' for a discussion of related basic
563 Lisp concepts such as car, cdr, cons cell and list. */)
564 (register Lisp_Object list
)
569 DEFUN ("car-safe", Fcar_safe
, Scar_safe
, 1, 1, 0,
570 doc
: /* Return the car of OBJECT if it is a cons cell, or else nil. */)
573 return CAR_SAFE (object
);
576 DEFUN ("cdr", Fcdr
, Scdr
, 1, 1, 0,
577 doc
: /* Return the cdr of LIST. If arg is nil, return nil.
578 Error if arg is not nil and not a cons cell. See also `cdr-safe'.
580 See Info node `(elisp)Cons Cells' for a discussion of related basic
581 Lisp concepts such as cdr, car, cons cell and list. */)
582 (register Lisp_Object list
)
587 DEFUN ("cdr-safe", Fcdr_safe
, Scdr_safe
, 1, 1, 0,
588 doc
: /* Return the cdr of OBJECT if it is a cons cell, or else nil. */)
591 return CDR_SAFE (object
);
594 DEFUN ("setcar", Fsetcar
, Ssetcar
, 2, 2, 0,
595 doc
: /* Set the car of CELL to be NEWCAR. Returns NEWCAR. */)
596 (register Lisp_Object cell
, Lisp_Object newcar
)
600 XSETCAR (cell
, newcar
);
604 DEFUN ("setcdr", Fsetcdr
, Ssetcdr
, 2, 2, 0,
605 doc
: /* Set the cdr of CELL to be NEWCDR. Returns NEWCDR. */)
606 (register Lisp_Object cell
, Lisp_Object newcdr
)
610 XSETCDR (cell
, newcdr
);
614 /* Extract and set components of symbols. */
616 DEFUN ("boundp", Fboundp
, Sboundp
, 1, 1, 0,
617 doc
: /* Return t if SYMBOL's value is not void.
618 Note that if `lexical-binding' is in effect, this refers to the
619 global value outside of any lexical scope. */)
620 (register Lisp_Object symbol
)
622 Lisp_Object valcontents
;
623 struct Lisp_Symbol
*sym
;
624 CHECK_SYMBOL (symbol
);
625 sym
= XSYMBOL (symbol
);
628 switch (sym
->redirect
)
630 case SYMBOL_PLAINVAL
: valcontents
= SYMBOL_VAL (sym
); break;
631 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
632 case SYMBOL_LOCALIZED
:
634 struct Lisp_Buffer_Local_Value
*blv
= SYMBOL_BLV (sym
);
636 /* In set_internal, we un-forward vars when their value is
641 swap_in_symval_forwarding (sym
, blv
);
642 valcontents
= blv_value (blv
);
646 case SYMBOL_FORWARDED
:
647 /* In set_internal, we un-forward vars when their value is
650 default: emacs_abort ();
653 return (EQ (valcontents
, Qunbound
) ? Qnil
: Qt
);
656 /* FIXME: Make it an alias for function-symbol! */
657 DEFUN ("fboundp", Ffboundp
, Sfboundp
, 1, 1, 0,
658 doc
: /* Return t if SYMBOL's function definition is not void. */)
659 (register Lisp_Object symbol
)
661 CHECK_SYMBOL (symbol
);
662 return NILP (XSYMBOL (symbol
)->function
) ? Qnil
: Qt
;
665 DEFUN ("makunbound", Fmakunbound
, Smakunbound
, 1, 1, 0,
666 doc
: /* Make SYMBOL's value be void.
668 (register Lisp_Object symbol
)
670 CHECK_SYMBOL (symbol
);
671 if (SYMBOL_CONSTANT_P (symbol
))
672 xsignal1 (Qsetting_constant
, symbol
);
673 Fset (symbol
, Qunbound
);
677 DEFUN ("fmakunbound", Ffmakunbound
, Sfmakunbound
, 1, 1, 0,
678 doc
: /* Make SYMBOL's function definition be nil.
680 (register Lisp_Object symbol
)
682 CHECK_SYMBOL (symbol
);
683 if (NILP (symbol
) || EQ (symbol
, Qt
))
684 xsignal1 (Qsetting_constant
, symbol
);
685 set_symbol_function (symbol
, Qnil
);
689 DEFUN ("symbol-function", Fsymbol_function
, Ssymbol_function
, 1, 1, 0,
690 doc
: /* Return SYMBOL's function definition, or nil if that is void. */)
691 (register Lisp_Object symbol
)
693 CHECK_SYMBOL (symbol
);
694 return XSYMBOL (symbol
)->function
;
697 DEFUN ("symbol-plist", Fsymbol_plist
, Ssymbol_plist
, 1, 1, 0,
698 doc
: /* Return SYMBOL's property list. */)
699 (register Lisp_Object symbol
)
701 CHECK_SYMBOL (symbol
);
702 return XSYMBOL (symbol
)->plist
;
705 DEFUN ("symbol-name", Fsymbol_name
, Ssymbol_name
, 1, 1, 0,
706 doc
: /* Return SYMBOL's name, a string. */)
707 (register Lisp_Object symbol
)
709 register Lisp_Object name
;
711 CHECK_SYMBOL (symbol
);
712 name
= SYMBOL_NAME (symbol
);
716 DEFUN ("fset", Ffset
, Sfset
, 2, 2, 0,
717 doc
: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION. */)
718 (register Lisp_Object symbol
, Lisp_Object definition
)
720 register Lisp_Object function
;
721 CHECK_SYMBOL (symbol
);
723 function
= XSYMBOL (symbol
)->function
;
725 if (!NILP (Vautoload_queue
) && !NILP (function
))
726 Vautoload_queue
= Fcons (Fcons (symbol
, function
), Vautoload_queue
);
728 if (AUTOLOADP (function
))
729 Fput (symbol
, Qautoload
, XCDR (function
));
731 /* Convert to eassert or remove after GC bug is found. In the
732 meantime, check unconditionally, at a slight perf hit. */
733 if (! valid_lisp_object_p (definition
))
736 set_symbol_function (symbol
, definition
);
741 DEFUN ("defalias", Fdefalias
, Sdefalias
, 2, 3, 0,
742 doc
: /* Set SYMBOL's function definition to DEFINITION.
743 Associates the function with the current load file, if any.
744 The optional third argument DOCSTRING specifies the documentation string
745 for SYMBOL; if it is omitted or nil, SYMBOL uses the documentation string
746 determined by DEFINITION.
748 Internally, this normally uses `fset', but if SYMBOL has a
749 `defalias-fset-function' property, the associated value is used instead.
751 The return value is undefined. */)
752 (register Lisp_Object symbol
, Lisp_Object definition
, Lisp_Object docstring
)
754 CHECK_SYMBOL (symbol
);
755 if (!NILP (Vpurify_flag
)
756 /* If `definition' is a keymap, immutable (and copying) is wrong. */
757 && !KEYMAPP (definition
))
758 definition
= Fpurecopy (definition
);
761 bool autoload
= AUTOLOADP (definition
);
762 if (NILP (Vpurify_flag
) || !autoload
)
763 { /* Only add autoload entries after dumping, because the ones before are
764 not useful and else we get loads of them from the loaddefs.el. */
766 if (AUTOLOADP (XSYMBOL (symbol
)->function
))
767 /* Remember that the function was already an autoload. */
768 LOADHIST_ATTACH (Fcons (Qt
, symbol
));
769 LOADHIST_ATTACH (Fcons (autoload
? Qautoload
: Qdefun
, symbol
));
773 { /* Handle automatic advice activation. */
774 Lisp_Object hook
= Fget (symbol
, Qdefalias_fset_function
);
776 call2 (hook
, symbol
, definition
);
778 Ffset (symbol
, definition
);
781 if (!NILP (docstring
))
782 Fput (symbol
, Qfunction_documentation
, docstring
);
783 /* We used to return `definition', but now that `defun' and `defmacro' expand
784 to a call to `defalias', we return `symbol' for backward compatibility
789 DEFUN ("setplist", Fsetplist
, Ssetplist
, 2, 2, 0,
790 doc
: /* Set SYMBOL's property list to NEWPLIST, and return NEWPLIST. */)
791 (register Lisp_Object symbol
, Lisp_Object newplist
)
793 CHECK_SYMBOL (symbol
);
794 set_symbol_plist (symbol
, newplist
);
798 DEFUN ("subr-arity", Fsubr_arity
, Ssubr_arity
, 1, 1, 0,
799 doc
: /* Return minimum and maximum number of args allowed for SUBR.
800 SUBR must be a built-in function.
801 The returned value is a pair (MIN . MAX). MIN is the minimum number
802 of args. MAX is the maximum number or the symbol `many', for a
803 function with `&rest' args, or `unevalled' for a special form. */)
806 short minargs
, maxargs
;
808 minargs
= XSUBR (subr
)->min_args
;
809 maxargs
= XSUBR (subr
)->max_args
;
810 return Fcons (make_number (minargs
),
811 maxargs
== MANY
? Qmany
812 : maxargs
== UNEVALLED
? Qunevalled
813 : make_number (maxargs
));
816 DEFUN ("subr-name", Fsubr_name
, Ssubr_name
, 1, 1, 0,
817 doc
: /* Return name of subroutine SUBR.
818 SUBR must be a built-in function. */)
823 name
= XSUBR (subr
)->symbol_name
;
824 return build_string (name
);
827 DEFUN ("interactive-form", Finteractive_form
, Sinteractive_form
, 1, 1, 0,
828 doc
: /* Return the interactive form of CMD or nil if none.
829 If CMD is not a command, the return value is nil.
830 Value, if non-nil, is a list \(interactive SPEC). */)
833 Lisp_Object fun
= indirect_function (cmd
); /* Check cycles. */
838 /* Use an `interactive-form' property if present, analogous to the
839 function-documentation property. */
841 while (SYMBOLP (fun
))
843 Lisp_Object tmp
= Fget (fun
, Qinteractive_form
);
847 fun
= Fsymbol_function (fun
);
852 const char *spec
= XSUBR (fun
)->intspec
;
854 return list2 (Qinteractive
,
855 (*spec
!= '(') ? build_string (spec
) :
856 Fcar (Fread_from_string (build_string (spec
), Qnil
, Qnil
)));
858 else if (COMPILEDP (fun
))
860 if ((ASIZE (fun
) & PSEUDOVECTOR_SIZE_MASK
) > COMPILED_INTERACTIVE
)
861 return list2 (Qinteractive
, AREF (fun
, COMPILED_INTERACTIVE
));
863 else if (AUTOLOADP (fun
))
864 return Finteractive_form (Fautoload_do_load (fun
, cmd
, Qnil
));
865 else if (CONSP (fun
))
867 Lisp_Object funcar
= XCAR (fun
);
868 if (EQ (funcar
, Qclosure
))
869 return Fassq (Qinteractive
, Fcdr (Fcdr (XCDR (fun
))));
870 else if (EQ (funcar
, Qlambda
))
871 return Fassq (Qinteractive
, Fcdr (XCDR (fun
)));
877 /***********************************************************************
878 Getting and Setting Values of Symbols
879 ***********************************************************************/
881 /* Return the symbol holding SYMBOL's value. Signal
882 `cyclic-variable-indirection' if SYMBOL's chain of variable
883 indirections contains a loop. */
886 indirect_variable (struct Lisp_Symbol
*symbol
)
888 struct Lisp_Symbol
*tortoise
, *hare
;
890 hare
= tortoise
= symbol
;
892 while (hare
->redirect
== SYMBOL_VARALIAS
)
894 hare
= SYMBOL_ALIAS (hare
);
895 if (hare
->redirect
!= SYMBOL_VARALIAS
)
898 hare
= SYMBOL_ALIAS (hare
);
899 tortoise
= SYMBOL_ALIAS (tortoise
);
901 if (hare
== tortoise
)
904 XSETSYMBOL (tem
, symbol
);
905 xsignal1 (Qcyclic_variable_indirection
, tem
);
913 DEFUN ("indirect-variable", Findirect_variable
, Sindirect_variable
, 1, 1, 0,
914 doc
: /* Return the variable at the end of OBJECT's variable chain.
915 If OBJECT is a symbol, follow its variable indirections (if any), and
916 return the variable at the end of the chain of aliases. See Info node
917 `(elisp)Variable Aliases'.
919 If OBJECT is not a symbol, just return it. If there is a loop in the
920 chain of aliases, signal a `cyclic-variable-indirection' error. */)
923 if (SYMBOLP (object
))
925 struct Lisp_Symbol
*sym
= indirect_variable (XSYMBOL (object
));
926 XSETSYMBOL (object
, sym
);
932 /* Given the raw contents of a symbol value cell,
933 return the Lisp value of the symbol.
934 This does not handle buffer-local variables; use
935 swap_in_symval_forwarding for that. */
938 do_symval_forwarding (register union Lisp_Fwd
*valcontents
)
940 register Lisp_Object val
;
941 switch (XFWDTYPE (valcontents
))
944 XSETINT (val
, *XINTFWD (valcontents
)->intvar
);
948 return (*XBOOLFWD (valcontents
)->boolvar
? Qt
: Qnil
);
951 return *XOBJFWD (valcontents
)->objvar
;
953 case Lisp_Fwd_Buffer_Obj
:
954 return per_buffer_value (current_buffer
,
955 XBUFFER_OBJFWD (valcontents
)->offset
);
957 case Lisp_Fwd_Kboard_Obj
:
958 /* We used to simply use current_kboard here, but from Lisp
959 code, its value is often unexpected. It seems nicer to
960 allow constructions like this to work as intuitively expected:
962 (with-selected-frame frame
963 (define-key local-function-map "\eOP" [f1]))
965 On the other hand, this affects the semantics of
966 last-command and real-last-command, and people may rely on
967 that. I took a quick look at the Lisp codebase, and I
968 don't think anything will break. --lorentey */
969 return *(Lisp_Object
*)(XKBOARD_OBJFWD (valcontents
)->offset
970 + (char *)FRAME_KBOARD (SELECTED_FRAME ()));
971 default: emacs_abort ();
975 /* Used to signal a user-friendly error when symbol WRONG is
976 not a member of CHOICE, which should be a list of symbols. */
979 wrong_choice (Lisp_Object choice
, Lisp_Object wrong
)
981 ptrdiff_t i
= 0, len
= XINT (Flength (choice
));
982 Lisp_Object obj
, *args
;
983 AUTO_STRING (one_of
, "One of ");
984 AUTO_STRING (comma
, ", ");
985 AUTO_STRING (or, " or ");
986 AUTO_STRING (should_be_specified
, " should be specified");
989 SAFE_ALLOCA_LISP (args
, len
* 2 + 1);
993 for (obj
= choice
; !NILP (obj
); obj
= XCDR (obj
))
995 args
[i
++] = SYMBOL_NAME (XCAR (obj
));
996 args
[i
++] = (NILP (XCDR (obj
)) ? should_be_specified
997 : NILP (XCDR (XCDR (obj
))) ? or : comma
);
1000 obj
= Fconcat (i
, args
);
1002 xsignal2 (Qerror
, obj
, wrong
);
1005 /* Used to signal a user-friendly error if WRONG is not a number or
1006 integer/floating-point number outsize of inclusive MIN..MAX range. */
1009 wrong_range (Lisp_Object min
, Lisp_Object max
, Lisp_Object wrong
)
1011 AUTO_STRING (value_should_be_from
, "Value should be from ");
1012 AUTO_STRING (to
, " to ");
1014 Fconcat (4, ((Lisp_Object
[])
1015 {value_should_be_from
, Fnumber_to_string (min
),
1016 to
, Fnumber_to_string (max
)})),
1020 /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell
1021 of SYMBOL. If SYMBOL is buffer-local, VALCONTENTS should be the
1022 buffer-independent contents of the value cell: forwarded just one
1023 step past the buffer-localness.
1025 BUF non-zero means set the value in buffer BUF instead of the
1026 current buffer. This only plays a role for per-buffer variables. */
1029 store_symval_forwarding (union Lisp_Fwd
*valcontents
, register Lisp_Object newval
, struct buffer
*buf
)
1031 switch (XFWDTYPE (valcontents
))
1034 CHECK_NUMBER (newval
);
1035 *XINTFWD (valcontents
)->intvar
= XINT (newval
);
1039 *XBOOLFWD (valcontents
)->boolvar
= !NILP (newval
);
1043 *XOBJFWD (valcontents
)->objvar
= newval
;
1045 /* If this variable is a default for something stored
1046 in the buffer itself, such as default-fill-column,
1047 find the buffers that don't have local values for it
1049 if (XOBJFWD (valcontents
)->objvar
> (Lisp_Object
*) &buffer_defaults
1050 && XOBJFWD (valcontents
)->objvar
< (Lisp_Object
*) (&buffer_defaults
+ 1))
1052 int offset
= ((char *) XOBJFWD (valcontents
)->objvar
1053 - (char *) &buffer_defaults
);
1054 int idx
= PER_BUFFER_IDX (offset
);
1056 Lisp_Object tail
, buf
;
1061 FOR_EACH_LIVE_BUFFER (tail
, buf
)
1063 struct buffer
*b
= XBUFFER (buf
);
1065 if (! PER_BUFFER_VALUE_P (b
, idx
))
1066 set_per_buffer_value (b
, offset
, newval
);
1071 case Lisp_Fwd_Buffer_Obj
:
1073 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1074 Lisp_Object predicate
= XBUFFER_OBJFWD (valcontents
)->predicate
;
1078 if (SYMBOLP (predicate
))
1082 if ((prop
= Fget (predicate
, Qchoice
), !NILP (prop
)))
1084 if (NILP (Fmemq (newval
, prop
)))
1085 wrong_choice (prop
, newval
);
1087 else if ((prop
= Fget (predicate
, Qrange
), !NILP (prop
)))
1089 Lisp_Object min
= XCAR (prop
), max
= XCDR (prop
);
1091 if (!NUMBERP (newval
)
1092 || !NILP (arithcompare (newval
, min
, ARITH_LESS
))
1093 || !NILP (arithcompare (newval
, max
, ARITH_GRTR
)))
1094 wrong_range (min
, max
, newval
);
1096 else if (FUNCTIONP (predicate
))
1098 if (NILP (call1 (predicate
, newval
)))
1099 wrong_type_argument (predicate
, newval
);
1104 buf
= current_buffer
;
1105 set_per_buffer_value (buf
, offset
, newval
);
1109 case Lisp_Fwd_Kboard_Obj
:
1111 char *base
= (char *) FRAME_KBOARD (SELECTED_FRAME ());
1112 char *p
= base
+ XKBOARD_OBJFWD (valcontents
)->offset
;
1113 *(Lisp_Object
*) p
= newval
;
1118 emacs_abort (); /* goto def; */
1122 /* Set up SYMBOL to refer to its global binding. This makes it safe
1123 to alter the status of other bindings. BEWARE: this may be called
1124 during the mark phase of GC, where we assume that Lisp_Object slots
1125 of BLV are marked after this function has changed them. */
1128 swap_in_global_binding (struct Lisp_Symbol
*symbol
)
1130 struct Lisp_Buffer_Local_Value
*blv
= SYMBOL_BLV (symbol
);
1132 /* Unload the previously loaded binding. */
1134 set_blv_value (blv
, do_symval_forwarding (blv
->fwd
));
1136 /* Select the global binding in the symbol. */
1137 set_blv_valcell (blv
, blv
->defcell
);
1139 store_symval_forwarding (blv
->fwd
, XCDR (blv
->defcell
), NULL
);
1141 /* Indicate that the global binding is set up now. */
1142 set_blv_where (blv
, Qnil
);
1143 set_blv_found (blv
, 0);
1146 /* Set up the buffer-local symbol SYMBOL for validity in the current buffer.
1147 VALCONTENTS is the contents of its value cell,
1148 which points to a struct Lisp_Buffer_Local_Value.
1150 Return the value forwarded one step past the buffer-local stage.
1151 This could be another forwarding pointer. */
1154 swap_in_symval_forwarding (struct Lisp_Symbol
*symbol
, struct Lisp_Buffer_Local_Value
*blv
)
1156 register Lisp_Object tem1
;
1158 eassert (blv
== SYMBOL_BLV (symbol
));
1163 || (blv
->frame_local
1164 ? !EQ (selected_frame
, tem1
)
1165 : current_buffer
!= XBUFFER (tem1
)))
1168 /* Unload the previously loaded binding. */
1169 tem1
= blv
->valcell
;
1171 set_blv_value (blv
, do_symval_forwarding (blv
->fwd
));
1172 /* Choose the new binding. */
1175 XSETSYMBOL (var
, symbol
);
1176 if (blv
->frame_local
)
1178 tem1
= assq_no_quit (var
, XFRAME (selected_frame
)->param_alist
);
1179 set_blv_where (blv
, selected_frame
);
1183 tem1
= assq_no_quit (var
, BVAR (current_buffer
, local_var_alist
));
1184 set_blv_where (blv
, Fcurrent_buffer ());
1187 if (!(blv
->found
= !NILP (tem1
)))
1188 tem1
= blv
->defcell
;
1190 /* Load the new binding. */
1191 set_blv_valcell (blv
, tem1
);
1193 store_symval_forwarding (blv
->fwd
, blv_value (blv
), NULL
);
1197 /* Find the value of a symbol, returning Qunbound if it's not bound.
1198 This is helpful for code which just wants to get a variable's value
1199 if it has one, without signaling an error.
1200 Note that it must not be possible to quit
1201 within this function. Great care is required for this. */
1204 find_symbol_value (Lisp_Object symbol
)
1206 struct Lisp_Symbol
*sym
;
1208 CHECK_SYMBOL (symbol
);
1209 sym
= XSYMBOL (symbol
);
1212 switch (sym
->redirect
)
1214 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
1215 case SYMBOL_PLAINVAL
: return SYMBOL_VAL (sym
);
1216 case SYMBOL_LOCALIZED
:
1218 struct Lisp_Buffer_Local_Value
*blv
= SYMBOL_BLV (sym
);
1219 swap_in_symval_forwarding (sym
, blv
);
1220 return blv
->fwd
? do_symval_forwarding (blv
->fwd
) : blv_value (blv
);
1223 case SYMBOL_FORWARDED
:
1224 return do_symval_forwarding (SYMBOL_FWD (sym
));
1225 default: emacs_abort ();
1229 DEFUN ("symbol-value", Fsymbol_value
, Ssymbol_value
, 1, 1, 0,
1230 doc
: /* Return SYMBOL's value. Error if that is void.
1231 Note that if `lexical-binding' is in effect, this returns the
1232 global value outside of any lexical scope. */)
1233 (Lisp_Object symbol
)
1237 val
= find_symbol_value (symbol
);
1238 if (!EQ (val
, Qunbound
))
1241 xsignal1 (Qvoid_variable
, symbol
);
1244 DEFUN ("set", Fset
, Sset
, 2, 2, 0,
1245 doc
: /* Set SYMBOL's value to NEWVAL, and return NEWVAL. */)
1246 (register Lisp_Object symbol
, Lisp_Object newval
)
1248 set_internal (symbol
, newval
, Qnil
, 0);
1252 /* Store the value NEWVAL into SYMBOL.
1253 If buffer/frame-locality is an issue, WHERE specifies which context to use.
1254 (nil stands for the current buffer/frame).
1256 If BINDFLAG is false, then if this symbol is supposed to become
1257 local in every buffer where it is set, then we make it local.
1258 If BINDFLAG is true, we don't do that. */
1261 set_internal (Lisp_Object symbol
, Lisp_Object newval
, Lisp_Object where
,
1264 bool voide
= EQ (newval
, Qunbound
);
1265 struct Lisp_Symbol
*sym
;
1268 /* If restoring in a dead buffer, do nothing. */
1269 /* if (BUFFERP (where) && NILP (XBUFFER (where)->name))
1272 CHECK_SYMBOL (symbol
);
1273 if (SYMBOL_CONSTANT_P (symbol
))
1275 if (NILP (Fkeywordp (symbol
))
1276 || !EQ (newval
, Fsymbol_value (symbol
)))
1277 xsignal1 (Qsetting_constant
, symbol
);
1279 /* Allow setting keywords to their own value. */
1283 sym
= XSYMBOL (symbol
);
1286 switch (sym
->redirect
)
1288 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
1289 case SYMBOL_PLAINVAL
: SET_SYMBOL_VAL (sym
, newval
); return;
1290 case SYMBOL_LOCALIZED
:
1292 struct Lisp_Buffer_Local_Value
*blv
= SYMBOL_BLV (sym
);
1295 if (blv
->frame_local
)
1296 where
= selected_frame
;
1298 XSETBUFFER (where
, current_buffer
);
1300 /* If the current buffer is not the buffer whose binding is
1301 loaded, or if there may be frame-local bindings and the frame
1302 isn't the right one, or if it's a Lisp_Buffer_Local_Value and
1303 the default binding is loaded, the loaded binding may be the
1305 if (!EQ (blv
->where
, where
)
1306 /* Also unload a global binding (if the var is local_if_set). */
1307 || (EQ (blv
->valcell
, blv
->defcell
)))
1309 /* The currently loaded binding is not necessarily valid.
1310 We need to unload it, and choose a new binding. */
1312 /* Write out `realvalue' to the old loaded binding. */
1314 set_blv_value (blv
, do_symval_forwarding (blv
->fwd
));
1316 /* Find the new binding. */
1317 XSETSYMBOL (symbol
, sym
); /* May have changed via aliasing. */
1318 tem1
= assq_no_quit (symbol
,
1320 ? XFRAME (where
)->param_alist
1321 : BVAR (XBUFFER (where
), local_var_alist
)));
1322 set_blv_where (blv
, where
);
1327 /* This buffer still sees the default value. */
1329 /* If the variable is a Lisp_Some_Buffer_Local_Value,
1330 or if this is `let' rather than `set',
1331 make CURRENT-ALIST-ELEMENT point to itself,
1332 indicating that we're seeing the default value.
1333 Likewise if the variable has been let-bound
1334 in the current buffer. */
1335 if (bindflag
|| !blv
->local_if_set
1336 || let_shadows_buffer_binding_p (sym
))
1339 tem1
= blv
->defcell
;
1341 /* If it's a local_if_set, being set not bound,
1342 and we're not within a let that was made for this buffer,
1343 create a new buffer-local binding for the variable.
1344 That means, give this buffer a new assoc for a local value
1345 and load that binding. */
1348 /* local_if_set is only supported for buffer-local
1349 bindings, not for frame-local bindings. */
1350 eassert (!blv
->frame_local
);
1351 tem1
= Fcons (symbol
, XCDR (blv
->defcell
));
1352 bset_local_var_alist
1354 Fcons (tem1
, BVAR (XBUFFER (where
), local_var_alist
)));
1358 /* Record which binding is now loaded. */
1359 set_blv_valcell (blv
, tem1
);
1362 /* Store the new value in the cons cell. */
1363 set_blv_value (blv
, newval
);
1368 /* If storing void (making the symbol void), forward only through
1369 buffer-local indicator, not through Lisp_Objfwd, etc. */
1372 store_symval_forwarding (blv
->fwd
, newval
,
1374 ? XBUFFER (where
) : current_buffer
);
1378 case SYMBOL_FORWARDED
:
1381 = BUFFERP (where
) ? XBUFFER (where
) : current_buffer
;
1382 union Lisp_Fwd
*innercontents
= SYMBOL_FWD (sym
);
1383 if (BUFFER_OBJFWDP (innercontents
))
1385 int offset
= XBUFFER_OBJFWD (innercontents
)->offset
;
1386 int idx
= PER_BUFFER_IDX (offset
);
1389 && !let_shadows_buffer_binding_p (sym
))
1390 SET_PER_BUFFER_VALUE_P (buf
, idx
, 1);
1394 { /* If storing void (making the symbol void), forward only through
1395 buffer-local indicator, not through Lisp_Objfwd, etc. */
1396 sym
->redirect
= SYMBOL_PLAINVAL
;
1397 SET_SYMBOL_VAL (sym
, newval
);
1400 store_symval_forwarding (/* sym, */ innercontents
, newval
, buf
);
1403 default: emacs_abort ();
1408 /* Access or set a buffer-local symbol's default value. */
1410 /* Return the default value of SYMBOL, but don't check for voidness.
1411 Return Qunbound if it is void. */
1414 default_value (Lisp_Object symbol
)
1416 struct Lisp_Symbol
*sym
;
1418 CHECK_SYMBOL (symbol
);
1419 sym
= XSYMBOL (symbol
);
1422 switch (sym
->redirect
)
1424 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
1425 case SYMBOL_PLAINVAL
: return SYMBOL_VAL (sym
);
1426 case SYMBOL_LOCALIZED
:
1428 /* If var is set up for a buffer that lacks a local value for it,
1429 the current value is nominally the default value.
1430 But the `realvalue' slot may be more up to date, since
1431 ordinary setq stores just that slot. So use that. */
1432 struct Lisp_Buffer_Local_Value
*blv
= SYMBOL_BLV (sym
);
1433 if (blv
->fwd
&& EQ (blv
->valcell
, blv
->defcell
))
1434 return do_symval_forwarding (blv
->fwd
);
1436 return XCDR (blv
->defcell
);
1438 case SYMBOL_FORWARDED
:
1440 union Lisp_Fwd
*valcontents
= SYMBOL_FWD (sym
);
1442 /* For a built-in buffer-local variable, get the default value
1443 rather than letting do_symval_forwarding get the current value. */
1444 if (BUFFER_OBJFWDP (valcontents
))
1446 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1447 if (PER_BUFFER_IDX (offset
) != 0)
1448 return per_buffer_default (offset
);
1451 /* For other variables, get the current value. */
1452 return do_symval_forwarding (valcontents
);
1454 default: emacs_abort ();
1458 DEFUN ("default-boundp", Fdefault_boundp
, Sdefault_boundp
, 1, 1, 0,
1459 doc
: /* Return t if SYMBOL has a non-void default value.
1460 This is the value that is seen in buffers that do not have their own values
1461 for this variable. */)
1462 (Lisp_Object symbol
)
1464 register Lisp_Object value
;
1466 value
= default_value (symbol
);
1467 return (EQ (value
, Qunbound
) ? Qnil
: Qt
);
1470 DEFUN ("default-value", Fdefault_value
, Sdefault_value
, 1, 1, 0,
1471 doc
: /* Return SYMBOL's default value.
1472 This is the value that is seen in buffers that do not have their own values
1473 for this variable. The default value is meaningful for variables with
1474 local bindings in certain buffers. */)
1475 (Lisp_Object symbol
)
1477 Lisp_Object value
= default_value (symbol
);
1478 if (!EQ (value
, Qunbound
))
1481 xsignal1 (Qvoid_variable
, symbol
);
1484 DEFUN ("set-default", Fset_default
, Sset_default
, 2, 2, 0,
1485 doc
: /* Set SYMBOL's default value to VALUE. SYMBOL and VALUE are evaluated.
1486 The default value is seen in buffers that do not have their own values
1487 for this variable. */)
1488 (Lisp_Object symbol
, Lisp_Object value
)
1490 struct Lisp_Symbol
*sym
;
1492 CHECK_SYMBOL (symbol
);
1493 if (SYMBOL_CONSTANT_P (symbol
))
1495 if (NILP (Fkeywordp (symbol
))
1496 || !EQ (value
, Fdefault_value (symbol
)))
1497 xsignal1 (Qsetting_constant
, symbol
);
1499 /* Allow setting keywords to their own value. */
1502 sym
= XSYMBOL (symbol
);
1505 switch (sym
->redirect
)
1507 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
1508 case SYMBOL_PLAINVAL
: return Fset (symbol
, value
);
1509 case SYMBOL_LOCALIZED
:
1511 struct Lisp_Buffer_Local_Value
*blv
= SYMBOL_BLV (sym
);
1513 /* Store new value into the DEFAULT-VALUE slot. */
1514 XSETCDR (blv
->defcell
, value
);
1516 /* If the default binding is now loaded, set the REALVALUE slot too. */
1517 if (blv
->fwd
&& EQ (blv
->defcell
, blv
->valcell
))
1518 store_symval_forwarding (blv
->fwd
, value
, NULL
);
1521 case SYMBOL_FORWARDED
:
1523 union Lisp_Fwd
*valcontents
= SYMBOL_FWD (sym
);
1525 /* Handle variables like case-fold-search that have special slots
1527 Make them work apparently like Lisp_Buffer_Local_Value variables. */
1528 if (BUFFER_OBJFWDP (valcontents
))
1530 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1531 int idx
= PER_BUFFER_IDX (offset
);
1533 set_per_buffer_default (offset
, value
);
1535 /* If this variable is not always local in all buffers,
1536 set it in the buffers that don't nominally have a local value. */
1542 if (!PER_BUFFER_VALUE_P (b
, idx
))
1543 set_per_buffer_value (b
, offset
, value
);
1548 return Fset (symbol
, value
);
1550 default: emacs_abort ();
1554 DEFUN ("setq-default", Fsetq_default
, Ssetq_default
, 0, UNEVALLED
, 0,
1555 doc
: /* Set the default value of variable VAR to VALUE.
1556 VAR, the variable name, is literal (not evaluated);
1557 VALUE is an expression: it is evaluated and its value returned.
1558 The default value of a variable is seen in buffers
1559 that do not have their own values for the variable.
1561 More generally, you can use multiple variables and values, as in
1562 (setq-default VAR VALUE VAR VALUE...)
1563 This sets each VAR's default value to the corresponding VALUE.
1564 The VALUE for the Nth VAR can refer to the new default values
1566 usage: (setq-default [VAR VALUE]...) */)
1569 Lisp_Object args_left
, symbol
, val
;
1570 struct gcpro gcpro1
;
1572 args_left
= val
= args
;
1575 while (CONSP (args_left
))
1577 val
= eval_sub (Fcar (XCDR (args_left
)));
1578 symbol
= XCAR (args_left
);
1579 Fset_default (symbol
, val
);
1580 args_left
= Fcdr (XCDR (args_left
));
1587 /* Lisp functions for creating and removing buffer-local variables. */
1592 union Lisp_Fwd
*fwd
;
1595 static struct Lisp_Buffer_Local_Value
*
1596 make_blv (struct Lisp_Symbol
*sym
, bool forwarded
,
1597 union Lisp_Val_Fwd valcontents
)
1599 struct Lisp_Buffer_Local_Value
*blv
= xmalloc (sizeof *blv
);
1603 XSETSYMBOL (symbol
, sym
);
1604 tem
= Fcons (symbol
, (forwarded
1605 ? do_symval_forwarding (valcontents
.fwd
)
1606 : valcontents
.value
));
1608 /* Buffer_Local_Values cannot have as realval a buffer-local
1609 or keyboard-local forwarding. */
1610 eassert (!(forwarded
&& BUFFER_OBJFWDP (valcontents
.fwd
)));
1611 eassert (!(forwarded
&& KBOARD_OBJFWDP (valcontents
.fwd
)));
1612 blv
->fwd
= forwarded
? valcontents
.fwd
: NULL
;
1613 set_blv_where (blv
, Qnil
);
1614 blv
->frame_local
= 0;
1615 blv
->local_if_set
= 0;
1616 set_blv_defcell (blv
, tem
);
1617 set_blv_valcell (blv
, tem
);
1618 set_blv_found (blv
, 0);
1622 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local
,
1623 Smake_variable_buffer_local
, 1, 1, "vMake Variable Buffer Local: ",
1624 doc
: /* Make VARIABLE become buffer-local whenever it is set.
1625 At any time, the value for the current buffer is in effect,
1626 unless the variable has never been set in this buffer,
1627 in which case the default value is in effect.
1628 Note that binding the variable with `let', or setting it while
1629 a `let'-style binding made in this buffer is in effect,
1630 does not make the variable buffer-local. Return VARIABLE.
1632 This globally affects all uses of this variable, so it belongs together with
1633 the variable declaration, rather than with its uses (if you just want to make
1634 a variable local to the current buffer for one particular use, use
1635 `make-local-variable'). Buffer-local bindings are normally cleared
1636 while setting up a new major mode, unless they have a `permanent-local'
1639 The function `default-value' gets the default value and `set-default' sets it. */)
1640 (register Lisp_Object variable
)
1642 struct Lisp_Symbol
*sym
;
1643 struct Lisp_Buffer_Local_Value
*blv
= NULL
;
1644 union Lisp_Val_Fwd valcontents
IF_LINT (= {LISP_INITIALLY_ZERO
});
1645 bool forwarded
IF_LINT (= 0);
1647 CHECK_SYMBOL (variable
);
1648 sym
= XSYMBOL (variable
);
1651 switch (sym
->redirect
)
1653 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
1654 case SYMBOL_PLAINVAL
:
1655 forwarded
= 0; valcontents
.value
= SYMBOL_VAL (sym
);
1656 if (EQ (valcontents
.value
, Qunbound
))
1657 valcontents
.value
= Qnil
;
1659 case SYMBOL_LOCALIZED
:
1660 blv
= SYMBOL_BLV (sym
);
1661 if (blv
->frame_local
)
1662 error ("Symbol %s may not be buffer-local",
1663 SDATA (SYMBOL_NAME (variable
)));
1665 case SYMBOL_FORWARDED
:
1666 forwarded
= 1; valcontents
.fwd
= SYMBOL_FWD (sym
);
1667 if (KBOARD_OBJFWDP (valcontents
.fwd
))
1668 error ("Symbol %s may not be buffer-local",
1669 SDATA (SYMBOL_NAME (variable
)));
1670 else if (BUFFER_OBJFWDP (valcontents
.fwd
))
1673 default: emacs_abort ();
1677 error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable
)));
1681 blv
= make_blv (sym
, forwarded
, valcontents
);
1682 sym
->redirect
= SYMBOL_LOCALIZED
;
1683 SET_SYMBOL_BLV (sym
, blv
);
1686 XSETSYMBOL (symbol
, sym
); /* In case `variable' is aliased. */
1687 if (let_shadows_global_binding_p (symbol
))
1688 message ("Making %s buffer-local while let-bound!",
1689 SDATA (SYMBOL_NAME (variable
)));
1693 blv
->local_if_set
= 1;
1697 DEFUN ("make-local-variable", Fmake_local_variable
, Smake_local_variable
,
1698 1, 1, "vMake Local Variable: ",
1699 doc
: /* Make VARIABLE have a separate value in the current buffer.
1700 Other buffers will continue to share a common default value.
1701 \(The buffer-local value of VARIABLE starts out as the same value
1702 VARIABLE previously had. If VARIABLE was void, it remains void.\)
1705 If the variable is already arranged to become local when set,
1706 this function causes a local value to exist for this buffer,
1707 just as setting the variable would do.
1709 This function returns VARIABLE, and therefore
1710 (set (make-local-variable 'VARIABLE) VALUE-EXP)
1713 See also `make-variable-buffer-local'.
1715 Do not use `make-local-variable' to make a hook variable buffer-local.
1716 Instead, use `add-hook' and specify t for the LOCAL argument. */)
1717 (Lisp_Object variable
)
1720 bool forwarded
IF_LINT (= 0);
1721 union Lisp_Val_Fwd valcontents
IF_LINT (= {LISP_INITIALLY_ZERO
});
1722 struct Lisp_Symbol
*sym
;
1723 struct Lisp_Buffer_Local_Value
*blv
= NULL
;
1725 CHECK_SYMBOL (variable
);
1726 sym
= XSYMBOL (variable
);
1729 switch (sym
->redirect
)
1731 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
1732 case SYMBOL_PLAINVAL
:
1733 forwarded
= 0; valcontents
.value
= SYMBOL_VAL (sym
); break;
1734 case SYMBOL_LOCALIZED
:
1735 blv
= SYMBOL_BLV (sym
);
1736 if (blv
->frame_local
)
1737 error ("Symbol %s may not be buffer-local",
1738 SDATA (SYMBOL_NAME (variable
)));
1740 case SYMBOL_FORWARDED
:
1741 forwarded
= 1; valcontents
.fwd
= SYMBOL_FWD (sym
);
1742 if (KBOARD_OBJFWDP (valcontents
.fwd
))
1743 error ("Symbol %s may not be buffer-local",
1744 SDATA (SYMBOL_NAME (variable
)));
1746 default: emacs_abort ();
1750 error ("Symbol %s may not be buffer-local",
1751 SDATA (SYMBOL_NAME (variable
)));
1753 if (blv
? blv
->local_if_set
1754 : (forwarded
&& BUFFER_OBJFWDP (valcontents
.fwd
)))
1756 tem
= Fboundp (variable
);
1757 /* Make sure the symbol has a local value in this particular buffer,
1758 by setting it to the same value it already has. */
1759 Fset (variable
, (EQ (tem
, Qt
) ? Fsymbol_value (variable
) : Qunbound
));
1764 blv
= make_blv (sym
, forwarded
, valcontents
);
1765 sym
->redirect
= SYMBOL_LOCALIZED
;
1766 SET_SYMBOL_BLV (sym
, blv
);
1769 XSETSYMBOL (symbol
, sym
); /* In case `variable' is aliased. */
1770 if (let_shadows_global_binding_p (symbol
))
1771 message ("Making %s local to %s while let-bound!",
1772 SDATA (SYMBOL_NAME (variable
)),
1773 SDATA (BVAR (current_buffer
, name
)));
1777 /* Make sure this buffer has its own value of symbol. */
1778 XSETSYMBOL (variable
, sym
); /* Update in case of aliasing. */
1779 tem
= Fassq (variable
, BVAR (current_buffer
, local_var_alist
));
1782 if (let_shadows_buffer_binding_p (sym
))
1783 message ("Making %s buffer-local while locally let-bound!",
1784 SDATA (SYMBOL_NAME (variable
)));
1786 /* Swap out any local binding for some other buffer, and make
1787 sure the current value is permanently recorded, if it's the
1789 find_symbol_value (variable
);
1791 bset_local_var_alist
1793 Fcons (Fcons (variable
, XCDR (blv
->defcell
)),
1794 BVAR (current_buffer
, local_var_alist
)));
1796 /* Make sure symbol does not think it is set up for this buffer;
1797 force it to look once again for this buffer's value. */
1798 if (current_buffer
== XBUFFER (blv
->where
))
1799 set_blv_where (blv
, Qnil
);
1800 set_blv_found (blv
, 0);
1803 /* If the symbol forwards into a C variable, then load the binding
1804 for this buffer now. If C code modifies the variable before we
1805 load the binding in, then that new value will clobber the default
1806 binding the next time we unload it. */
1808 swap_in_symval_forwarding (sym
, blv
);
1813 DEFUN ("kill-local-variable", Fkill_local_variable
, Skill_local_variable
,
1814 1, 1, "vKill Local Variable: ",
1815 doc
: /* Make VARIABLE no longer have a separate value in the current buffer.
1816 From now on the default value will apply in this buffer. Return VARIABLE. */)
1817 (register Lisp_Object variable
)
1819 register Lisp_Object tem
;
1820 struct Lisp_Buffer_Local_Value
*blv
;
1821 struct Lisp_Symbol
*sym
;
1823 CHECK_SYMBOL (variable
);
1824 sym
= XSYMBOL (variable
);
1827 switch (sym
->redirect
)
1829 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
1830 case SYMBOL_PLAINVAL
: return variable
;
1831 case SYMBOL_FORWARDED
:
1833 union Lisp_Fwd
*valcontents
= SYMBOL_FWD (sym
);
1834 if (BUFFER_OBJFWDP (valcontents
))
1836 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1837 int idx
= PER_BUFFER_IDX (offset
);
1841 SET_PER_BUFFER_VALUE_P (current_buffer
, idx
, 0);
1842 set_per_buffer_value (current_buffer
, offset
,
1843 per_buffer_default (offset
));
1848 case SYMBOL_LOCALIZED
:
1849 blv
= SYMBOL_BLV (sym
);
1850 if (blv
->frame_local
)
1853 default: emacs_abort ();
1856 /* Get rid of this buffer's alist element, if any. */
1857 XSETSYMBOL (variable
, sym
); /* Propagate variable indirection. */
1858 tem
= Fassq (variable
, BVAR (current_buffer
, local_var_alist
));
1860 bset_local_var_alist
1862 Fdelq (tem
, BVAR (current_buffer
, local_var_alist
)));
1864 /* If the symbol is set up with the current buffer's binding
1865 loaded, recompute its value. We have to do it now, or else
1866 forwarded objects won't work right. */
1868 Lisp_Object buf
; XSETBUFFER (buf
, current_buffer
);
1869 if (EQ (buf
, blv
->where
))
1871 set_blv_where (blv
, Qnil
);
1873 find_symbol_value (variable
);
1880 /* Lisp functions for creating and removing buffer-local variables. */
1882 /* Obsolete since 22.2. NB adjust doc of modify-frame-parameters
1883 when/if this is removed. */
1885 DEFUN ("make-variable-frame-local", Fmake_variable_frame_local
, Smake_variable_frame_local
,
1886 1, 1, "vMake Variable Frame Local: ",
1887 doc
: /* Enable VARIABLE to have frame-local bindings.
1888 This does not create any frame-local bindings for VARIABLE,
1889 it just makes them possible.
1891 A frame-local binding is actually a frame parameter value.
1892 If a frame F has a value for the frame parameter named VARIABLE,
1893 that also acts as a frame-local binding for VARIABLE in F--
1894 provided this function has been called to enable VARIABLE
1895 to have frame-local bindings at all.
1897 The only way to create a frame-local binding for VARIABLE in a frame
1898 is to set the VARIABLE frame parameter of that frame. See
1899 `modify-frame-parameters' for how to set frame parameters.
1901 Note that since Emacs 23.1, variables cannot be both buffer-local and
1902 frame-local any more (buffer-local bindings used to take precedence over
1903 frame-local bindings). */)
1904 (Lisp_Object variable
)
1907 union Lisp_Val_Fwd valcontents
;
1908 struct Lisp_Symbol
*sym
;
1909 struct Lisp_Buffer_Local_Value
*blv
= NULL
;
1911 CHECK_SYMBOL (variable
);
1912 sym
= XSYMBOL (variable
);
1915 switch (sym
->redirect
)
1917 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
1918 case SYMBOL_PLAINVAL
:
1919 forwarded
= 0; valcontents
.value
= SYMBOL_VAL (sym
);
1920 if (EQ (valcontents
.value
, Qunbound
))
1921 valcontents
.value
= Qnil
;
1923 case SYMBOL_LOCALIZED
:
1924 if (SYMBOL_BLV (sym
)->frame_local
)
1927 error ("Symbol %s may not be frame-local",
1928 SDATA (SYMBOL_NAME (variable
)));
1929 case SYMBOL_FORWARDED
:
1930 forwarded
= 1; valcontents
.fwd
= SYMBOL_FWD (sym
);
1931 if (KBOARD_OBJFWDP (valcontents
.fwd
) || BUFFER_OBJFWDP (valcontents
.fwd
))
1932 error ("Symbol %s may not be frame-local",
1933 SDATA (SYMBOL_NAME (variable
)));
1935 default: emacs_abort ();
1939 error ("Symbol %s may not be frame-local", SDATA (SYMBOL_NAME (variable
)));
1941 blv
= make_blv (sym
, forwarded
, valcontents
);
1942 blv
->frame_local
= 1;
1943 sym
->redirect
= SYMBOL_LOCALIZED
;
1944 SET_SYMBOL_BLV (sym
, blv
);
1947 XSETSYMBOL (symbol
, sym
); /* In case `variable' is aliased. */
1948 if (let_shadows_global_binding_p (symbol
))
1949 message ("Making %s frame-local while let-bound!",
1950 SDATA (SYMBOL_NAME (variable
)));
1955 DEFUN ("local-variable-p", Flocal_variable_p
, Slocal_variable_p
,
1957 doc
: /* Non-nil if VARIABLE has a local binding in buffer BUFFER.
1958 BUFFER defaults to the current buffer. */)
1959 (Lisp_Object variable
, Lisp_Object buffer
)
1961 struct buffer
*buf
= decode_buffer (buffer
);
1962 struct Lisp_Symbol
*sym
;
1964 CHECK_SYMBOL (variable
);
1965 sym
= XSYMBOL (variable
);
1968 switch (sym
->redirect
)
1970 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
1971 case SYMBOL_PLAINVAL
: return Qnil
;
1972 case SYMBOL_LOCALIZED
:
1974 Lisp_Object tail
, elt
, tmp
;
1975 struct Lisp_Buffer_Local_Value
*blv
= SYMBOL_BLV (sym
);
1976 XSETBUFFER (tmp
, buf
);
1977 XSETSYMBOL (variable
, sym
); /* Update in case of aliasing. */
1979 if (EQ (blv
->where
, tmp
)) /* The binding is already loaded. */
1980 return blv_found (blv
) ? Qt
: Qnil
;
1982 for (tail
= BVAR (buf
, local_var_alist
); CONSP (tail
); tail
= XCDR (tail
))
1985 if (EQ (variable
, XCAR (elt
)))
1987 eassert (!blv
->frame_local
);
1993 case SYMBOL_FORWARDED
:
1995 union Lisp_Fwd
*valcontents
= SYMBOL_FWD (sym
);
1996 if (BUFFER_OBJFWDP (valcontents
))
1998 int offset
= XBUFFER_OBJFWD (valcontents
)->offset
;
1999 int idx
= PER_BUFFER_IDX (offset
);
2000 if (idx
== -1 || PER_BUFFER_VALUE_P (buf
, idx
))
2005 default: emacs_abort ();
2009 DEFUN ("local-variable-if-set-p", Flocal_variable_if_set_p
, Slocal_variable_if_set_p
,
2011 doc
: /* Non-nil if VARIABLE is local in buffer BUFFER when set there.
2012 BUFFER defaults to the current buffer.
2014 More precisely, return non-nil if either VARIABLE already has a local
2015 value in BUFFER, or if VARIABLE is automatically buffer-local (see
2016 `make-variable-buffer-local'). */)
2017 (register Lisp_Object variable
, Lisp_Object buffer
)
2019 struct Lisp_Symbol
*sym
;
2021 CHECK_SYMBOL (variable
);
2022 sym
= XSYMBOL (variable
);
2025 switch (sym
->redirect
)
2027 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
2028 case SYMBOL_PLAINVAL
: return Qnil
;
2029 case SYMBOL_LOCALIZED
:
2031 struct Lisp_Buffer_Local_Value
*blv
= SYMBOL_BLV (sym
);
2032 if (blv
->local_if_set
)
2034 XSETSYMBOL (variable
, sym
); /* Update in case of aliasing. */
2035 return Flocal_variable_p (variable
, buffer
);
2037 case SYMBOL_FORWARDED
:
2038 /* All BUFFER_OBJFWD slots become local if they are set. */
2039 return (BUFFER_OBJFWDP (SYMBOL_FWD (sym
)) ? Qt
: Qnil
);
2040 default: emacs_abort ();
2044 DEFUN ("variable-binding-locus", Fvariable_binding_locus
, Svariable_binding_locus
,
2046 doc
: /* Return a value indicating where VARIABLE's current binding comes from.
2047 If the current binding is buffer-local, the value is the current buffer.
2048 If the current binding is frame-local, the value is the selected frame.
2049 If the current binding is global (the default), the value is nil. */)
2050 (register Lisp_Object variable
)
2052 struct Lisp_Symbol
*sym
;
2054 CHECK_SYMBOL (variable
);
2055 sym
= XSYMBOL (variable
);
2057 /* Make sure the current binding is actually swapped in. */
2058 find_symbol_value (variable
);
2061 switch (sym
->redirect
)
2063 case SYMBOL_VARALIAS
: sym
= indirect_variable (sym
); goto start
;
2064 case SYMBOL_PLAINVAL
: return Qnil
;
2065 case SYMBOL_FORWARDED
:
2067 union Lisp_Fwd
*valcontents
= SYMBOL_FWD (sym
);
2068 if (KBOARD_OBJFWDP (valcontents
))
2069 return Fframe_terminal (selected_frame
);
2070 else if (!BUFFER_OBJFWDP (valcontents
))
2074 case SYMBOL_LOCALIZED
:
2075 /* For a local variable, record both the symbol and which
2076 buffer's or frame's value we are saving. */
2077 if (!NILP (Flocal_variable_p (variable
, Qnil
)))
2078 return Fcurrent_buffer ();
2079 else if (sym
->redirect
== SYMBOL_LOCALIZED
2080 && blv_found (SYMBOL_BLV (sym
)))
2081 return SYMBOL_BLV (sym
)->where
;
2084 default: emacs_abort ();
2088 /* This code is disabled now that we use the selected frame to return
2089 keyboard-local-values. */
2091 extern struct terminal
*get_terminal (Lisp_Object display
, int);
2093 DEFUN ("terminal-local-value", Fterminal_local_value
,
2094 Sterminal_local_value
, 2, 2, 0,
2095 doc
: /* Return the terminal-local value of SYMBOL on TERMINAL.
2096 If SYMBOL is not a terminal-local variable, then return its normal
2097 value, like `symbol-value'.
2099 TERMINAL may be a terminal object, a frame, or nil (meaning the
2100 selected frame's terminal device). */)
2101 (Lisp_Object symbol
, Lisp_Object terminal
)
2104 struct terminal
*t
= get_terminal (terminal
, 1);
2105 push_kboard (t
->kboard
);
2106 result
= Fsymbol_value (symbol
);
2111 DEFUN ("set-terminal-local-value", Fset_terminal_local_value
,
2112 Sset_terminal_local_value
, 3, 3, 0,
2113 doc
: /* Set the terminal-local binding of SYMBOL on TERMINAL to VALUE.
2114 If VARIABLE is not a terminal-local variable, then set its normal
2115 binding, like `set'.
2117 TERMINAL may be a terminal object, a frame, or nil (meaning the
2118 selected frame's terminal device). */)
2119 (Lisp_Object symbol
, Lisp_Object terminal
, Lisp_Object value
)
2122 struct terminal
*t
= get_terminal (terminal
, 1);
2123 push_kboard (d
->kboard
);
2124 result
= Fset (symbol
, value
);
2130 /* Find the function at the end of a chain of symbol function indirections. */
2132 /* If OBJECT is a symbol, find the end of its function chain and
2133 return the value found there. If OBJECT is not a symbol, just
2134 return it. If there is a cycle in the function chain, signal a
2135 cyclic-function-indirection error.
2137 This is like Findirect_function, except that it doesn't signal an
2138 error if the chain ends up unbound. */
2140 indirect_function (register Lisp_Object object
)
2142 Lisp_Object tortoise
, hare
;
2144 hare
= tortoise
= object
;
2148 if (!SYMBOLP (hare
) || NILP (hare
))
2150 hare
= XSYMBOL (hare
)->function
;
2151 if (!SYMBOLP (hare
) || NILP (hare
))
2153 hare
= XSYMBOL (hare
)->function
;
2155 tortoise
= XSYMBOL (tortoise
)->function
;
2157 if (EQ (hare
, tortoise
))
2158 xsignal1 (Qcyclic_function_indirection
, object
);
2164 DEFUN ("indirect-function", Findirect_function
, Sindirect_function
, 1, 2, 0,
2165 doc
: /* Return the function at the end of OBJECT's function chain.
2166 If OBJECT is not a symbol, just return it. Otherwise, follow all
2167 function indirections to find the final function binding and return it.
2168 If the final symbol in the chain is unbound, signal a void-function error.
2169 Optional arg NOERROR non-nil means to return nil instead of signaling.
2170 Signal a cyclic-function-indirection error if there is a loop in the
2171 function chain of symbols. */)
2172 (register Lisp_Object object
, Lisp_Object noerror
)
2176 /* Optimize for no indirection. */
2178 if (SYMBOLP (result
) && !NILP (result
)
2179 && (result
= XSYMBOL (result
)->function
, SYMBOLP (result
)))
2180 result
= indirect_function (result
);
2185 xsignal1 (Qvoid_function
, object
);
2190 /* Extract and set vector and string elements. */
2192 DEFUN ("aref", Faref
, Saref
, 2, 2, 0,
2193 doc
: /* Return the element of ARRAY at index IDX.
2194 ARRAY may be a vector, a string, a char-table, a bool-vector,
2195 or a byte-code object. IDX starts at 0. */)
2196 (register Lisp_Object array
, Lisp_Object idx
)
2198 register EMACS_INT idxval
;
2201 idxval
= XINT (idx
);
2202 if (STRINGP (array
))
2205 ptrdiff_t idxval_byte
;
2207 if (idxval
< 0 || idxval
>= SCHARS (array
))
2208 args_out_of_range (array
, idx
);
2209 if (! STRING_MULTIBYTE (array
))
2210 return make_number ((unsigned char) SREF (array
, idxval
));
2211 idxval_byte
= string_char_to_byte (array
, idxval
);
2213 c
= STRING_CHAR (SDATA (array
) + idxval_byte
);
2214 return make_number (c
);
2216 else if (BOOL_VECTOR_P (array
))
2218 if (idxval
< 0 || idxval
>= bool_vector_size (array
))
2219 args_out_of_range (array
, idx
);
2220 return bool_vector_ref (array
, idxval
);
2222 else if (CHAR_TABLE_P (array
))
2224 CHECK_CHARACTER (idx
);
2225 return CHAR_TABLE_REF (array
, idxval
);
2230 if (VECTORP (array
))
2231 size
= ASIZE (array
);
2232 else if (COMPILEDP (array
))
2233 size
= ASIZE (array
) & PSEUDOVECTOR_SIZE_MASK
;
2235 wrong_type_argument (Qarrayp
, array
);
2237 if (idxval
< 0 || idxval
>= size
)
2238 args_out_of_range (array
, idx
);
2239 return AREF (array
, idxval
);
2243 DEFUN ("aset", Faset
, Saset
, 3, 3, 0,
2244 doc
: /* Store into the element of ARRAY at index IDX the value NEWELT.
2245 Return NEWELT. ARRAY may be a vector, a string, a char-table or a
2246 bool-vector. IDX starts at 0. */)
2247 (register Lisp_Object array
, Lisp_Object idx
, Lisp_Object newelt
)
2249 register EMACS_INT idxval
;
2252 idxval
= XINT (idx
);
2253 CHECK_ARRAY (array
, Qarrayp
);
2254 CHECK_IMPURE (array
);
2256 if (VECTORP (array
))
2258 if (idxval
< 0 || idxval
>= ASIZE (array
))
2259 args_out_of_range (array
, idx
);
2260 ASET (array
, idxval
, newelt
);
2262 else if (BOOL_VECTOR_P (array
))
2264 if (idxval
< 0 || idxval
>= bool_vector_size (array
))
2265 args_out_of_range (array
, idx
);
2266 bool_vector_set (array
, idxval
, !NILP (newelt
));
2268 else if (CHAR_TABLE_P (array
))
2270 CHECK_CHARACTER (idx
);
2271 CHAR_TABLE_SET (array
, idxval
, newelt
);
2277 if (idxval
< 0 || idxval
>= SCHARS (array
))
2278 args_out_of_range (array
, idx
);
2279 CHECK_CHARACTER (newelt
);
2280 c
= XFASTINT (newelt
);
2282 if (STRING_MULTIBYTE (array
))
2284 ptrdiff_t idxval_byte
, nbytes
;
2285 int prev_bytes
, new_bytes
;
2286 unsigned char workbuf
[MAX_MULTIBYTE_LENGTH
], *p0
= workbuf
, *p1
;
2288 nbytes
= SBYTES (array
);
2289 idxval_byte
= string_char_to_byte (array
, idxval
);
2290 p1
= SDATA (array
) + idxval_byte
;
2291 prev_bytes
= BYTES_BY_CHAR_HEAD (*p1
);
2292 new_bytes
= CHAR_STRING (c
, p0
);
2293 if (prev_bytes
!= new_bytes
)
2295 /* We must relocate the string data. */
2296 ptrdiff_t nchars
= SCHARS (array
);
2298 unsigned char *str
= SAFE_ALLOCA (nbytes
);
2300 memcpy (str
, SDATA (array
), nbytes
);
2301 allocate_string_data (XSTRING (array
), nchars
,
2302 nbytes
+ new_bytes
- prev_bytes
);
2303 memcpy (SDATA (array
), str
, idxval_byte
);
2304 p1
= SDATA (array
) + idxval_byte
;
2305 memcpy (p1
+ new_bytes
, str
+ idxval_byte
+ prev_bytes
,
2306 nbytes
- (idxval_byte
+ prev_bytes
));
2308 clear_string_char_byte_cache ();
2315 if (! SINGLE_BYTE_CHAR_P (c
))
2319 for (i
= SBYTES (array
) - 1; i
>= 0; i
--)
2320 if (SREF (array
, i
) >= 0x80)
2321 args_out_of_range (array
, newelt
);
2322 /* ARRAY is an ASCII string. Convert it to a multibyte
2323 string, and try `aset' again. */
2324 STRING_SET_MULTIBYTE (array
);
2325 return Faset (array
, idx
, newelt
);
2327 SSET (array
, idxval
, c
);
2334 /* Arithmetic functions */
2337 arithcompare (Lisp_Object num1
, Lisp_Object num2
, enum Arith_Comparison comparison
)
2339 double f1
= 0, f2
= 0;
2342 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1
);
2343 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2
);
2345 if (FLOATP (num1
) || FLOATP (num2
))
2348 f1
= (FLOATP (num1
)) ? XFLOAT_DATA (num1
) : XINT (num1
);
2349 f2
= (FLOATP (num2
)) ? XFLOAT_DATA (num2
) : XINT (num2
);
2355 if (floatp
? f1
== f2
: XINT (num1
) == XINT (num2
))
2359 case ARITH_NOTEQUAL
:
2360 if (floatp
? f1
!= f2
: XINT (num1
) != XINT (num2
))
2365 if (floatp
? f1
< f2
: XINT (num1
) < XINT (num2
))
2369 case ARITH_LESS_OR_EQUAL
:
2370 if (floatp
? f1
<= f2
: XINT (num1
) <= XINT (num2
))
2375 if (floatp
? f1
> f2
: XINT (num1
) > XINT (num2
))
2379 case ARITH_GRTR_OR_EQUAL
:
2380 if (floatp
? f1
>= f2
: XINT (num1
) >= XINT (num2
))
2390 arithcompare_driver (ptrdiff_t nargs
, Lisp_Object
*args
,
2391 enum Arith_Comparison comparison
)
2394 for (argnum
= 1; argnum
< nargs
; ++argnum
)
2396 if (EQ (Qnil
, arithcompare (args
[argnum
- 1], args
[argnum
], comparison
)))
2402 DEFUN ("=", Feqlsign
, Seqlsign
, 1, MANY
, 0,
2403 doc
: /* Return t if args, all numbers or markers, are equal.
2404 usage: (= NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2405 (ptrdiff_t nargs
, Lisp_Object
*args
)
2407 return arithcompare_driver (nargs
, args
, ARITH_EQUAL
);
2410 DEFUN ("<", Flss
, Slss
, 1, MANY
, 0,
2411 doc
: /* Return t if each arg (a number or marker), is less than the next arg.
2412 usage: (< NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2413 (ptrdiff_t nargs
, Lisp_Object
*args
)
2415 return arithcompare_driver (nargs
, args
, ARITH_LESS
);
2418 DEFUN (">", Fgtr
, Sgtr
, 1, MANY
, 0,
2419 doc
: /* Return t if each arg (a number or marker) is greater than the next arg.
2420 usage: (> NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2421 (ptrdiff_t nargs
, Lisp_Object
*args
)
2423 return arithcompare_driver (nargs
, args
, ARITH_GRTR
);
2426 DEFUN ("<=", Fleq
, Sleq
, 1, MANY
, 0,
2427 doc
: /* Return t if each arg (a number or marker) is less than or equal to the next.
2428 usage: (<= NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2429 (ptrdiff_t nargs
, Lisp_Object
*args
)
2431 return arithcompare_driver (nargs
, args
, ARITH_LESS_OR_EQUAL
);
2434 DEFUN (">=", Fgeq
, Sgeq
, 1, MANY
, 0,
2435 doc
: /* Return t if each arg (a number or marker) is greater than or equal to the next.
2436 usage: (>= NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2437 (ptrdiff_t nargs
, Lisp_Object
*args
)
2439 return arithcompare_driver (nargs
, args
, ARITH_GRTR_OR_EQUAL
);
2442 DEFUN ("/=", Fneq
, Sneq
, 2, 2, 0,
2443 doc
: /* Return t if first arg is not equal to second arg. Both must be numbers or markers. */)
2444 (register Lisp_Object num1
, Lisp_Object num2
)
2446 return arithcompare (num1
, num2
, ARITH_NOTEQUAL
);
2449 /* Convert the cons-of-integers, integer, or float value C to an
2450 unsigned value with maximum value MAX. Signal an error if C does not
2451 have a valid format or is out of range. */
2453 cons_to_unsigned (Lisp_Object c
, uintmax_t max
)
2456 uintmax_t val
IF_LINT (= 0);
2459 valid
= 0 <= XINT (c
);
2462 else if (FLOATP (c
))
2464 double d
= XFLOAT_DATA (c
);
2466 && d
< (max
== UINTMAX_MAX
? (double) UINTMAX_MAX
+ 1 : max
+ 1))
2472 else if (CONSP (c
) && NATNUMP (XCAR (c
)))
2474 uintmax_t top
= XFASTINT (XCAR (c
));
2475 Lisp_Object rest
= XCDR (c
);
2476 if (top
<= UINTMAX_MAX
>> 24 >> 16
2478 && NATNUMP (XCAR (rest
)) && XFASTINT (XCAR (rest
)) < 1 << 24
2479 && NATNUMP (XCDR (rest
)) && XFASTINT (XCDR (rest
)) < 1 << 16)
2481 uintmax_t mid
= XFASTINT (XCAR (rest
));
2482 val
= top
<< 24 << 16 | mid
<< 16 | XFASTINT (XCDR (rest
));
2485 else if (top
<= UINTMAX_MAX
>> 16)
2489 if (NATNUMP (rest
) && XFASTINT (rest
) < 1 << 16)
2491 val
= top
<< 16 | XFASTINT (rest
);
2497 if (! (valid
&& val
<= max
))
2498 error ("Not an in-range integer, float, or cons of integers");
2502 /* Convert the cons-of-integers, integer, or float value C to a signed
2503 value with extrema MIN and MAX. Signal an error if C does not have
2504 a valid format or is out of range. */
2506 cons_to_signed (Lisp_Object c
, intmax_t min
, intmax_t max
)
2509 intmax_t val
IF_LINT (= 0);
2515 else if (FLOATP (c
))
2517 double d
= XFLOAT_DATA (c
);
2519 && d
< (max
== INTMAX_MAX
? (double) INTMAX_MAX
+ 1 : max
+ 1))
2525 else if (CONSP (c
) && INTEGERP (XCAR (c
)))
2527 intmax_t top
= XINT (XCAR (c
));
2528 Lisp_Object rest
= XCDR (c
);
2529 if (INTMAX_MIN
>> 24 >> 16 <= top
&& top
<= INTMAX_MAX
>> 24 >> 16
2531 && NATNUMP (XCAR (rest
)) && XFASTINT (XCAR (rest
)) < 1 << 24
2532 && NATNUMP (XCDR (rest
)) && XFASTINT (XCDR (rest
)) < 1 << 16)
2534 intmax_t mid
= XFASTINT (XCAR (rest
));
2535 val
= top
<< 24 << 16 | mid
<< 16 | XFASTINT (XCDR (rest
));
2538 else if (INTMAX_MIN
>> 16 <= top
&& top
<= INTMAX_MAX
>> 16)
2542 if (NATNUMP (rest
) && XFASTINT (rest
) < 1 << 16)
2544 val
= top
<< 16 | XFASTINT (rest
);
2550 if (! (valid
&& min
<= val
&& val
<= max
))
2551 error ("Not an in-range integer, float, or cons of integers");
2555 DEFUN ("number-to-string", Fnumber_to_string
, Snumber_to_string
, 1, 1, 0,
2556 doc
: /* Return the decimal representation of NUMBER as a string.
2557 Uses a minus sign if negative.
2558 NUMBER may be an integer or a floating point number. */)
2559 (Lisp_Object number
)
2561 char buffer
[max (FLOAT_TO_STRING_BUFSIZE
, INT_BUFSIZE_BOUND (EMACS_INT
))];
2564 CHECK_NUMBER_OR_FLOAT (number
);
2566 if (FLOATP (number
))
2567 len
= float_to_string (buffer
, XFLOAT_DATA (number
));
2569 len
= sprintf (buffer
, "%"pI
"d", XINT (number
));
2571 return make_unibyte_string (buffer
, len
);
2574 DEFUN ("string-to-number", Fstring_to_number
, Sstring_to_number
, 1, 2, 0,
2575 doc
: /* Parse STRING as a decimal number and return the number.
2576 Ignore leading spaces and tabs, and all trailing chars. Return 0 if
2577 STRING cannot be parsed as an integer or floating point number.
2579 If BASE, interpret STRING as a number in that base. If BASE isn't
2580 present, base 10 is used. BASE must be between 2 and 16 (inclusive).
2581 If the base used is not 10, STRING is always parsed as an integer. */)
2582 (register Lisp_Object string
, Lisp_Object base
)
2588 CHECK_STRING (string
);
2594 CHECK_NUMBER (base
);
2595 if (! (2 <= XINT (base
) && XINT (base
) <= 16))
2596 xsignal1 (Qargs_out_of_range
, base
);
2600 p
= SSDATA (string
);
2601 while (*p
== ' ' || *p
== '\t')
2604 val
= string_to_number (p
, b
, 1);
2605 return NILP (val
) ? make_number (0) : val
;
2621 static Lisp_Object
float_arith_driver (double, ptrdiff_t, enum arithop
,
2622 ptrdiff_t, Lisp_Object
*);
2624 arith_driver (enum arithop code
, ptrdiff_t nargs
, Lisp_Object
*args
)
2627 ptrdiff_t argnum
, ok_args
;
2628 EMACS_INT accum
= 0;
2629 EMACS_INT next
, ok_accum
;
2650 for (argnum
= 0; argnum
< nargs
; argnum
++)
2658 /* Using args[argnum] as argument to CHECK_NUMBER_... */
2660 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
);
2663 return float_arith_driver (ok_accum
, ok_args
, code
,
2666 next
= XINT (args
[argnum
]);
2670 if (INT_ADD_OVERFLOW (accum
, next
))
2678 if (INT_SUBTRACT_OVERFLOW (accum
, next
))
2683 accum
= argnum
? accum
- next
: nargs
== 1 ? - next
: next
;
2686 if (INT_MULTIPLY_OVERFLOW (accum
, next
))
2688 EMACS_UINT a
= accum
, b
= next
, ab
= a
* b
;
2690 accum
= ab
& INTMASK
;
2701 xsignal0 (Qarith_error
);
2715 if (!argnum
|| next
> accum
)
2719 if (!argnum
|| next
< accum
)
2725 XSETINT (val
, accum
);
2730 #define isnan(x) ((x) != (x))
2733 float_arith_driver (double accum
, ptrdiff_t argnum
, enum arithop code
,
2734 ptrdiff_t nargs
, Lisp_Object
*args
)
2736 register Lisp_Object val
;
2739 for (; argnum
< nargs
; argnum
++)
2741 val
= args
[argnum
]; /* using args[argnum] as argument to CHECK_NUMBER_... */
2742 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val
);
2746 next
= XFLOAT_DATA (val
);
2750 args
[argnum
] = val
; /* runs into a compiler bug. */
2751 next
= XINT (args
[argnum
]);
2759 accum
= argnum
? accum
- next
: nargs
== 1 ? - next
: next
;
2769 if (! IEEE_FLOATING_POINT
&& next
== 0)
2770 xsignal0 (Qarith_error
);
2777 return wrong_type_argument (Qinteger_or_marker_p
, val
);
2779 if (!argnum
|| isnan (next
) || next
> accum
)
2783 if (!argnum
|| isnan (next
) || next
< accum
)
2789 return make_float (accum
);
2793 DEFUN ("+", Fplus
, Splus
, 0, MANY
, 0,
2794 doc
: /* Return sum of any number of arguments, which are numbers or markers.
2795 usage: (+ &rest NUMBERS-OR-MARKERS) */)
2796 (ptrdiff_t nargs
, Lisp_Object
*args
)
2798 return arith_driver (Aadd
, nargs
, args
);
2801 DEFUN ("-", Fminus
, Sminus
, 0, MANY
, 0,
2802 doc
: /* Negate number or subtract numbers or markers and return the result.
2803 With one arg, negates it. With more than one arg,
2804 subtracts all but the first from the first.
2805 usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */)
2806 (ptrdiff_t nargs
, Lisp_Object
*args
)
2808 return arith_driver (Asub
, nargs
, args
);
2811 DEFUN ("*", Ftimes
, Stimes
, 0, MANY
, 0,
2812 doc
: /* Return product of any number of arguments, which are numbers or markers.
2813 usage: (* &rest NUMBERS-OR-MARKERS) */)
2814 (ptrdiff_t nargs
, Lisp_Object
*args
)
2816 return arith_driver (Amult
, nargs
, args
);
2819 DEFUN ("/", Fquo
, Squo
, 1, MANY
, 0,
2820 doc
: /* Return first argument divided by all the remaining arguments.
2821 The arguments must be numbers or markers.
2822 usage: (/ DIVIDEND &rest DIVISORS) */)
2823 (ptrdiff_t nargs
, Lisp_Object
*args
)
2826 for (argnum
= 2; argnum
< nargs
; argnum
++)
2827 if (FLOATP (args
[argnum
]))
2828 return float_arith_driver (0, 0, Adiv
, nargs
, args
);
2829 return arith_driver (Adiv
, nargs
, args
);
2832 DEFUN ("%", Frem
, Srem
, 2, 2, 0,
2833 doc
: /* Return remainder of X divided by Y.
2834 Both must be integers or markers. */)
2835 (register Lisp_Object x
, Lisp_Object y
)
2839 CHECK_NUMBER_COERCE_MARKER (x
);
2840 CHECK_NUMBER_COERCE_MARKER (y
);
2843 xsignal0 (Qarith_error
);
2845 XSETINT (val
, XINT (x
) % XINT (y
));
2849 DEFUN ("mod", Fmod
, Smod
, 2, 2, 0,
2850 doc
: /* Return X modulo Y.
2851 The result falls between zero (inclusive) and Y (exclusive).
2852 Both X and Y must be numbers or markers. */)
2853 (register Lisp_Object x
, Lisp_Object y
)
2858 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x
);
2859 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y
);
2861 if (FLOATP (x
) || FLOATP (y
))
2862 return fmod_float (x
, y
);
2868 xsignal0 (Qarith_error
);
2872 /* If the "remainder" comes out with the wrong sign, fix it. */
2873 if (i2
< 0 ? i1
> 0 : i1
< 0)
2880 DEFUN ("max", Fmax
, Smax
, 1, MANY
, 0,
2881 doc
: /* Return largest of all the arguments (which must be numbers or markers).
2882 The value is always a number; markers are converted to numbers.
2883 usage: (max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2884 (ptrdiff_t nargs
, Lisp_Object
*args
)
2886 return arith_driver (Amax
, nargs
, args
);
2889 DEFUN ("min", Fmin
, Smin
, 1, MANY
, 0,
2890 doc
: /* Return smallest of all the arguments (which must be numbers or markers).
2891 The value is always a number; markers are converted to numbers.
2892 usage: (min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */)
2893 (ptrdiff_t nargs
, Lisp_Object
*args
)
2895 return arith_driver (Amin
, nargs
, args
);
2898 DEFUN ("logand", Flogand
, Slogand
, 0, MANY
, 0,
2899 doc
: /* Return bitwise-and of all the arguments.
2900 Arguments may be integers, or markers converted to integers.
2901 usage: (logand &rest INTS-OR-MARKERS) */)
2902 (ptrdiff_t nargs
, Lisp_Object
*args
)
2904 return arith_driver (Alogand
, nargs
, args
);
2907 DEFUN ("logior", Flogior
, Slogior
, 0, MANY
, 0,
2908 doc
: /* Return bitwise-or of all the arguments.
2909 Arguments may be integers, or markers converted to integers.
2910 usage: (logior &rest INTS-OR-MARKERS) */)
2911 (ptrdiff_t nargs
, Lisp_Object
*args
)
2913 return arith_driver (Alogior
, nargs
, args
);
2916 DEFUN ("logxor", Flogxor
, Slogxor
, 0, MANY
, 0,
2917 doc
: /* Return bitwise-exclusive-or of all the arguments.
2918 Arguments may be integers, or markers converted to integers.
2919 usage: (logxor &rest INTS-OR-MARKERS) */)
2920 (ptrdiff_t nargs
, Lisp_Object
*args
)
2922 return arith_driver (Alogxor
, nargs
, args
);
2925 DEFUN ("ash", Fash
, Sash
, 2, 2, 0,
2926 doc
: /* Return VALUE with its bits shifted left by COUNT.
2927 If COUNT is negative, shifting is actually to the right.
2928 In this case, the sign bit is duplicated. */)
2929 (register Lisp_Object value
, Lisp_Object count
)
2931 register Lisp_Object val
;
2933 CHECK_NUMBER (value
);
2934 CHECK_NUMBER (count
);
2936 if (XINT (count
) >= BITS_PER_EMACS_INT
)
2938 else if (XINT (count
) > 0)
2939 XSETINT (val
, XUINT (value
) << XFASTINT (count
));
2940 else if (XINT (count
) <= -BITS_PER_EMACS_INT
)
2941 XSETINT (val
, XINT (value
) < 0 ? -1 : 0);
2943 XSETINT (val
, XINT (value
) >> -XINT (count
));
2947 DEFUN ("lsh", Flsh
, Slsh
, 2, 2, 0,
2948 doc
: /* Return VALUE with its bits shifted left by COUNT.
2949 If COUNT is negative, shifting is actually to the right.
2950 In this case, zeros are shifted in on the left. */)
2951 (register Lisp_Object value
, Lisp_Object count
)
2953 register Lisp_Object val
;
2955 CHECK_NUMBER (value
);
2956 CHECK_NUMBER (count
);
2958 if (XINT (count
) >= BITS_PER_EMACS_INT
)
2960 else if (XINT (count
) > 0)
2961 XSETINT (val
, XUINT (value
) << XFASTINT (count
));
2962 else if (XINT (count
) <= -BITS_PER_EMACS_INT
)
2965 XSETINT (val
, XUINT (value
) >> -XINT (count
));
2969 DEFUN ("1+", Fadd1
, Sadd1
, 1, 1, 0,
2970 doc
: /* Return NUMBER plus one. NUMBER may be a number or a marker.
2971 Markers are converted to integers. */)
2972 (register Lisp_Object number
)
2974 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
);
2976 if (FLOATP (number
))
2977 return (make_float (1.0 + XFLOAT_DATA (number
)));
2979 XSETINT (number
, XINT (number
) + 1);
2983 DEFUN ("1-", Fsub1
, Ssub1
, 1, 1, 0,
2984 doc
: /* Return NUMBER minus one. NUMBER may be a number or a marker.
2985 Markers are converted to integers. */)
2986 (register Lisp_Object number
)
2988 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number
);
2990 if (FLOATP (number
))
2991 return (make_float (-1.0 + XFLOAT_DATA (number
)));
2993 XSETINT (number
, XINT (number
) - 1);
2997 DEFUN ("lognot", Flognot
, Slognot
, 1, 1, 0,
2998 doc
: /* Return the bitwise complement of NUMBER. NUMBER must be an integer. */)
2999 (register Lisp_Object number
)
3001 CHECK_NUMBER (number
);
3002 XSETINT (number
, ~XINT (number
));
3006 DEFUN ("byteorder", Fbyteorder
, Sbyteorder
, 0, 0, 0,
3007 doc
: /* Return the byteorder for the machine.
3008 Returns 66 (ASCII uppercase B) for big endian machines or 108 (ASCII
3009 lowercase l) for small endian machines. */)
3012 unsigned i
= 0x04030201;
3013 int order
= *(char *)&i
== 1 ? 108 : 66;
3015 return make_number (order
);
3018 /* Because we round up the bool vector allocate size to word_size
3019 units, we can safely read past the "end" of the vector in the
3020 operations below. These extra bits are always zero. */
3023 bool_vector_spare_mask (EMACS_INT nr_bits
)
3025 return (((bits_word
) 1) << (nr_bits
% BITS_PER_BITS_WORD
)) - 1;
3028 /* Info about unsigned long long, falling back on unsigned long
3029 if unsigned long long is not available. */
3031 #if HAVE_UNSIGNED_LONG_LONG_INT && defined ULLONG_MAX
3032 enum { BITS_PER_ULL
= CHAR_BIT
* sizeof (unsigned long long) };
3033 # define ULL_MAX ULLONG_MAX
3035 enum { BITS_PER_ULL
= CHAR_BIT
* sizeof (unsigned long) };
3036 # define ULL_MAX ULONG_MAX
3037 # define count_one_bits_ll count_one_bits_l
3038 # define count_trailing_zeros_ll count_trailing_zeros_l
3041 /* Shift VAL right by the width of an unsigned long long.
3042 BITS_PER_ULL must be less than BITS_PER_BITS_WORD. */
3045 shift_right_ull (bits_word w
)
3047 /* Pacify bogus GCC warning about shift count exceeding type width. */
3048 int shift
= BITS_PER_ULL
- BITS_PER_BITS_WORD
< 0 ? BITS_PER_ULL
: 0;
3052 /* Return the number of 1 bits in W. */
3055 count_one_bits_word (bits_word w
)
3057 if (BITS_WORD_MAX
<= UINT_MAX
)
3058 return count_one_bits (w
);
3059 else if (BITS_WORD_MAX
<= ULONG_MAX
)
3060 return count_one_bits_l (w
);
3063 int i
= 0, count
= 0;
3064 while (count
+= count_one_bits_ll (w
),
3065 (i
+= BITS_PER_ULL
) < BITS_PER_BITS_WORD
)
3066 w
= shift_right_ull (w
);
3071 enum bool_vector_op
{ bool_vector_exclusive_or
,
3073 bool_vector_intersection
,
3074 bool_vector_set_difference
,
3075 bool_vector_subsetp
};
3078 bool_vector_binop_driver (Lisp_Object a
,
3081 enum bool_vector_op op
)
3084 bits_word
*adata
, *bdata
, *destdata
;
3088 CHECK_BOOL_VECTOR (a
);
3089 CHECK_BOOL_VECTOR (b
);
3091 nr_bits
= bool_vector_size (a
);
3092 if (bool_vector_size (b
) != nr_bits
)
3093 wrong_length_argument (a
, b
, dest
);
3095 nr_words
= bool_vector_words (nr_bits
);
3096 adata
= bool_vector_data (a
);
3097 bdata
= bool_vector_data (b
);
3101 dest
= make_uninit_bool_vector (nr_bits
);
3102 destdata
= bool_vector_data (dest
);
3106 CHECK_BOOL_VECTOR (dest
);
3107 destdata
= bool_vector_data (dest
);
3108 if (bool_vector_size (dest
) != nr_bits
)
3109 wrong_length_argument (a
, b
, dest
);
3113 case bool_vector_exclusive_or
:
3114 for (; i
< nr_words
; i
++)
3115 if (destdata
[i
] != (adata
[i
] ^ bdata
[i
]))
3119 case bool_vector_subsetp
:
3120 for (; i
< nr_words
; i
++)
3121 if (adata
[i
] &~ bdata
[i
])
3125 case bool_vector_union
:
3126 for (; i
< nr_words
; i
++)
3127 if (destdata
[i
] != (adata
[i
] | bdata
[i
]))
3131 case bool_vector_intersection
:
3132 for (; i
< nr_words
; i
++)
3133 if (destdata
[i
] != (adata
[i
] & bdata
[i
]))
3137 case bool_vector_set_difference
:
3138 for (; i
< nr_words
; i
++)
3139 if (destdata
[i
] != (adata
[i
] &~ bdata
[i
]))
3150 case bool_vector_exclusive_or
:
3151 for (; i
< nr_words
; i
++)
3152 destdata
[i
] = adata
[i
] ^ bdata
[i
];
3155 case bool_vector_union
:
3156 for (; i
< nr_words
; i
++)
3157 destdata
[i
] = adata
[i
] | bdata
[i
];
3160 case bool_vector_intersection
:
3161 for (; i
< nr_words
; i
++)
3162 destdata
[i
] = adata
[i
] & bdata
[i
];
3165 case bool_vector_set_difference
:
3166 for (; i
< nr_words
; i
++)
3167 destdata
[i
] = adata
[i
] &~ bdata
[i
];
3177 /* PRECONDITION must be true. Return VALUE. This odd construction
3178 works around a bogus GCC diagnostic "shift count >= width of type". */
3181 pre_value (bool precondition
, int value
)
3183 eassume (precondition
);
3184 return precondition
? value
: 0;
3187 /* Compute the number of trailing zero bits in val. If val is zero,
3188 return the number of bits in val. */
3190 count_trailing_zero_bits (bits_word val
)
3192 if (BITS_WORD_MAX
== UINT_MAX
)
3193 return count_trailing_zeros (val
);
3194 if (BITS_WORD_MAX
== ULONG_MAX
)
3195 return count_trailing_zeros_l (val
);
3196 if (BITS_WORD_MAX
== ULL_MAX
)
3197 return count_trailing_zeros_ll (val
);
3199 /* The rest of this code is for the unlikely platform where bits_word differs
3200 in width from unsigned int, unsigned long, and unsigned long long. */
3201 val
|= ~ BITS_WORD_MAX
;
3202 if (BITS_WORD_MAX
<= UINT_MAX
)
3203 return count_trailing_zeros (val
);
3204 if (BITS_WORD_MAX
<= ULONG_MAX
)
3205 return count_trailing_zeros_l (val
);
3210 count
< BITS_PER_BITS_WORD
- BITS_PER_ULL
;
3211 count
+= BITS_PER_ULL
)
3214 return count
+ count_trailing_zeros_ll (val
);
3215 val
= shift_right_ull (val
);
3218 if (BITS_PER_BITS_WORD
% BITS_PER_ULL
!= 0
3219 && BITS_WORD_MAX
== (bits_word
) -1)
3220 val
|= (bits_word
) 1 << pre_value (ULONG_MAX
< BITS_WORD_MAX
,
3221 BITS_PER_BITS_WORD
% BITS_PER_ULL
);
3222 return count
+ count_trailing_zeros_ll (val
);
3227 bits_word_to_host_endian (bits_word val
)
3229 #ifndef WORDS_BIGENDIAN
3232 if (BITS_WORD_MAX
>> 31 == 1)
3233 return bswap_32 (val
);
3234 # if HAVE_UNSIGNED_LONG_LONG
3235 if (BITS_WORD_MAX
>> 31 >> 31 >> 1 == 1)
3236 return bswap_64 (val
);
3241 for (i
= 0; i
< sizeof val
; i
++)
3243 r
= ((r
<< 1 << (CHAR_BIT
- 1))
3244 | (val
& ((1u << 1 << (CHAR_BIT
- 1)) - 1)));
3245 val
= val
>> 1 >> (CHAR_BIT
- 1);
3252 DEFUN ("bool-vector-exclusive-or", Fbool_vector_exclusive_or
,
3253 Sbool_vector_exclusive_or
, 2, 3, 0,
3254 doc
: /* Return A ^ B, bitwise exclusive or.
3255 If optional third argument C is given, store result into C.
3256 A, B, and C must be bool vectors of the same length.
3257 Return the destination vector if it changed or nil otherwise. */)
3258 (Lisp_Object a
, Lisp_Object b
, Lisp_Object c
)
3260 return bool_vector_binop_driver (a
, b
, c
, bool_vector_exclusive_or
);
3263 DEFUN ("bool-vector-union", Fbool_vector_union
,
3264 Sbool_vector_union
, 2, 3, 0,
3265 doc
: /* Return A | B, bitwise or.
3266 If optional third argument C is given, store result into C.
3267 A, B, and C must be bool vectors of the same length.
3268 Return the destination vector if it changed or nil otherwise. */)
3269 (Lisp_Object a
, Lisp_Object b
, Lisp_Object c
)
3271 return bool_vector_binop_driver (a
, b
, c
, bool_vector_union
);
3274 DEFUN ("bool-vector-intersection", Fbool_vector_intersection
,
3275 Sbool_vector_intersection
, 2, 3, 0,
3276 doc
: /* Return A & B, bitwise and.
3277 If optional third argument C is given, store result into C.
3278 A, B, and C must be bool vectors of the same length.
3279 Return the destination vector if it changed or nil otherwise. */)
3280 (Lisp_Object a
, Lisp_Object b
, Lisp_Object c
)
3282 return bool_vector_binop_driver (a
, b
, c
, bool_vector_intersection
);
3285 DEFUN ("bool-vector-set-difference", Fbool_vector_set_difference
,
3286 Sbool_vector_set_difference
, 2, 3, 0,
3287 doc
: /* Return A &~ B, set difference.
3288 If optional third argument C is given, store result into C.
3289 A, B, and C must be bool vectors of the same length.
3290 Return the destination vector if it changed or nil otherwise. */)
3291 (Lisp_Object a
, Lisp_Object b
, Lisp_Object c
)
3293 return bool_vector_binop_driver (a
, b
, c
, bool_vector_set_difference
);
3296 DEFUN ("bool-vector-subsetp", Fbool_vector_subsetp
,
3297 Sbool_vector_subsetp
, 2, 2, 0,
3298 doc
: /* Return t if every t value in A is also t in B, nil otherwise.
3299 A and B must be bool vectors of the same length. */)
3300 (Lisp_Object a
, Lisp_Object b
)
3302 return bool_vector_binop_driver (a
, b
, b
, bool_vector_subsetp
);
3305 DEFUN ("bool-vector-not", Fbool_vector_not
,
3306 Sbool_vector_not
, 1, 2, 0,
3307 doc
: /* Compute ~A, set complement.
3308 If optional second argument B is given, store result into B.
3309 A and B must be bool vectors of the same length.
3310 Return the destination vector. */)
3311 (Lisp_Object a
, Lisp_Object b
)
3314 bits_word
*bdata
, *adata
;
3317 CHECK_BOOL_VECTOR (a
);
3318 nr_bits
= bool_vector_size (a
);
3321 b
= make_uninit_bool_vector (nr_bits
);
3324 CHECK_BOOL_VECTOR (b
);
3325 if (bool_vector_size (b
) != nr_bits
)
3326 wrong_length_argument (a
, b
, Qnil
);
3329 bdata
= bool_vector_data (b
);
3330 adata
= bool_vector_data (a
);
3332 for (i
= 0; i
< nr_bits
/ BITS_PER_BITS_WORD
; i
++)
3333 bdata
[i
] = BITS_WORD_MAX
& ~adata
[i
];
3335 if (nr_bits
% BITS_PER_BITS_WORD
)
3337 bits_word mword
= bits_word_to_host_endian (adata
[i
]);
3339 mword
&= bool_vector_spare_mask (nr_bits
);
3340 bdata
[i
] = bits_word_to_host_endian (mword
);
3346 DEFUN ("bool-vector-count-population", Fbool_vector_count_population
,
3347 Sbool_vector_count_population
, 1, 1, 0,
3348 doc
: /* Count how many elements in A are t.
3349 A is a bool vector. To count A's nil elements, subtract the return
3350 value from A's length. */)
3356 ptrdiff_t i
, nwords
;
3358 CHECK_BOOL_VECTOR (a
);
3360 nr_bits
= bool_vector_size (a
);
3361 nwords
= bool_vector_words (nr_bits
);
3363 adata
= bool_vector_data (a
);
3365 for (i
= 0; i
< nwords
; i
++)
3366 count
+= count_one_bits_word (adata
[i
]);
3368 return make_number (count
);
3371 DEFUN ("bool-vector-count-consecutive", Fbool_vector_count_consecutive
,
3372 Sbool_vector_count_consecutive
, 3, 3, 0,
3373 doc
: /* Count how many consecutive elements in A equal B starting at I.
3374 A is a bool vector, B is t or nil, and I is an index into A. */)
3375 (Lisp_Object a
, Lisp_Object b
, Lisp_Object i
)
3382 bits_word mword
; /* Machine word. */
3383 ptrdiff_t pos
, pos0
;
3386 CHECK_BOOL_VECTOR (a
);
3389 nr_bits
= bool_vector_size (a
);
3390 if (XFASTINT (i
) > nr_bits
) /* Allow one past the end for convenience */
3391 args_out_of_range (a
, i
);
3393 adata
= bool_vector_data (a
);
3394 nr_words
= bool_vector_words (nr_bits
);
3395 pos
= XFASTINT (i
) / BITS_PER_BITS_WORD
;
3396 offset
= XFASTINT (i
) % BITS_PER_BITS_WORD
;
3399 /* By XORing with twiddle, we transform the problem of "count
3400 consecutive equal values" into "count the zero bits". The latter
3401 operation usually has hardware support. */
3402 twiddle
= NILP (b
) ? 0 : BITS_WORD_MAX
;
3404 /* Scan the remainder of the mword at the current offset. */
3405 if (pos
< nr_words
&& offset
!= 0)
3407 mword
= bits_word_to_host_endian (adata
[pos
]);
3411 /* Do not count the pad bits. */
3412 mword
|= (bits_word
) 1 << (BITS_PER_BITS_WORD
- offset
);
3414 count
= count_trailing_zero_bits (mword
);
3416 if (count
+ offset
< BITS_PER_BITS_WORD
)
3417 return make_number (count
);
3420 /* Scan whole words until we either reach the end of the vector or
3421 find an mword that doesn't completely match. twiddle is
3422 endian-independent. */
3424 while (pos
< nr_words
&& adata
[pos
] == twiddle
)
3426 count
+= (pos
- pos0
) * BITS_PER_BITS_WORD
;
3430 /* If we stopped because of a mismatch, see how many bits match
3431 in the current mword. */
3432 mword
= bits_word_to_host_endian (adata
[pos
]);
3434 count
+= count_trailing_zero_bits (mword
);
3436 else if (nr_bits
% BITS_PER_BITS_WORD
!= 0)
3438 /* If we hit the end, we might have overshot our count. Reduce
3439 the total by the number of spare bits at the end of the
3441 count
-= BITS_PER_BITS_WORD
- nr_bits
% BITS_PER_BITS_WORD
;
3444 return make_number (count
);
3451 Lisp_Object error_tail
, arith_tail
;
3453 DEFSYM (Qquote
, "quote");
3454 DEFSYM (Qlambda
, "lambda");
3455 DEFSYM (Qsubr
, "subr");
3456 DEFSYM (Qerror_conditions
, "error-conditions");
3457 DEFSYM (Qerror_message
, "error-message");
3458 DEFSYM (Qtop_level
, "top-level");
3460 DEFSYM (Qerror
, "error");
3461 DEFSYM (Quser_error
, "user-error");
3462 DEFSYM (Qquit
, "quit");
3463 DEFSYM (Qwrong_length_argument
, "wrong-length-argument");
3464 DEFSYM (Qwrong_type_argument
, "wrong-type-argument");
3465 DEFSYM (Qargs_out_of_range
, "args-out-of-range");
3466 DEFSYM (Qvoid_function
, "void-function");
3467 DEFSYM (Qcyclic_function_indirection
, "cyclic-function-indirection");
3468 DEFSYM (Qcyclic_variable_indirection
, "cyclic-variable-indirection");
3469 DEFSYM (Qvoid_variable
, "void-variable");
3470 DEFSYM (Qsetting_constant
, "setting-constant");
3471 DEFSYM (Qinvalid_read_syntax
, "invalid-read-syntax");
3473 DEFSYM (Qinvalid_function
, "invalid-function");
3474 DEFSYM (Qwrong_number_of_arguments
, "wrong-number-of-arguments");
3475 DEFSYM (Qno_catch
, "no-catch");
3476 DEFSYM (Qend_of_file
, "end-of-file");
3477 DEFSYM (Qarith_error
, "arith-error");
3478 DEFSYM (Qbeginning_of_buffer
, "beginning-of-buffer");
3479 DEFSYM (Qend_of_buffer
, "end-of-buffer");
3480 DEFSYM (Qbuffer_read_only
, "buffer-read-only");
3481 DEFSYM (Qtext_read_only
, "text-read-only");
3482 DEFSYM (Qmark_inactive
, "mark-inactive");
3484 DEFSYM (Qlistp
, "listp");
3485 DEFSYM (Qconsp
, "consp");
3486 DEFSYM (Qsymbolp
, "symbolp");
3487 DEFSYM (Qkeywordp
, "keywordp");
3488 DEFSYM (Qintegerp
, "integerp");
3489 DEFSYM (Qnatnump
, "natnump");
3490 DEFSYM (Qwholenump
, "wholenump");
3491 DEFSYM (Qstringp
, "stringp");
3492 DEFSYM (Qarrayp
, "arrayp");
3493 DEFSYM (Qsequencep
, "sequencep");
3494 DEFSYM (Qbufferp
, "bufferp");
3495 DEFSYM (Qvectorp
, "vectorp");
3496 DEFSYM (Qbool_vector_p
, "bool-vector-p");
3497 DEFSYM (Qchar_or_string_p
, "char-or-string-p");
3498 DEFSYM (Qmarkerp
, "markerp");
3499 DEFSYM (Qbuffer_or_string_p
, "buffer-or-string-p");
3500 DEFSYM (Qinteger_or_marker_p
, "integer-or-marker-p");
3501 DEFSYM (Qboundp
, "boundp");
3502 DEFSYM (Qfboundp
, "fboundp");
3504 DEFSYM (Qfloatp
, "floatp");
3505 DEFSYM (Qnumberp
, "numberp");
3506 DEFSYM (Qnumber_or_marker_p
, "number-or-marker-p");
3508 DEFSYM (Qchar_table_p
, "char-table-p");
3509 DEFSYM (Qvector_or_char_table_p
, "vector-or-char-table-p");
3511 DEFSYM (Qsubrp
, "subrp");
3512 DEFSYM (Qunevalled
, "unevalled");
3513 DEFSYM (Qmany
, "many");
3515 DEFSYM (Qcdr
, "cdr");
3517 /* Handle automatic advice activation. */
3518 DEFSYM (Qad_advice_info
, "ad-advice-info");
3519 DEFSYM (Qad_activate_internal
, "ad-activate-internal");
3521 error_tail
= pure_cons (Qerror
, Qnil
);
3523 /* ERROR is used as a signaler for random errors for which nothing else is
3526 Fput (Qerror
, Qerror_conditions
,
3528 Fput (Qerror
, Qerror_message
,
3529 build_pure_c_string ("error"));
3531 #define PUT_ERROR(sym, tail, msg) \
3532 Fput (sym, Qerror_conditions, pure_cons (sym, tail)); \
3533 Fput (sym, Qerror_message, build_pure_c_string (msg))
3535 PUT_ERROR (Qquit
, Qnil
, "Quit");
3537 PUT_ERROR (Quser_error
, error_tail
, "");
3538 PUT_ERROR (Qwrong_length_argument
, error_tail
, "Wrong length argument");
3539 PUT_ERROR (Qwrong_type_argument
, error_tail
, "Wrong type argument");
3540 PUT_ERROR (Qargs_out_of_range
, error_tail
, "Args out of range");
3541 PUT_ERROR (Qvoid_function
, error_tail
,
3542 "Symbol's function definition is void");
3543 PUT_ERROR (Qcyclic_function_indirection
, error_tail
,
3544 "Symbol's chain of function indirections contains a loop");
3545 PUT_ERROR (Qcyclic_variable_indirection
, error_tail
,
3546 "Symbol's chain of variable indirections contains a loop");
3547 DEFSYM (Qcircular_list
, "circular-list");
3548 PUT_ERROR (Qcircular_list
, error_tail
, "List contains a loop");
3549 PUT_ERROR (Qvoid_variable
, error_tail
, "Symbol's value as variable is void");
3550 PUT_ERROR (Qsetting_constant
, error_tail
,
3551 "Attempt to set a constant symbol");
3552 PUT_ERROR (Qinvalid_read_syntax
, error_tail
, "Invalid read syntax");
3553 PUT_ERROR (Qinvalid_function
, error_tail
, "Invalid function");
3554 PUT_ERROR (Qwrong_number_of_arguments
, error_tail
,
3555 "Wrong number of arguments");
3556 PUT_ERROR (Qno_catch
, error_tail
, "No catch for tag");
3557 PUT_ERROR (Qend_of_file
, error_tail
, "End of file during parsing");
3559 arith_tail
= pure_cons (Qarith_error
, error_tail
);
3560 Fput (Qarith_error
, Qerror_conditions
, arith_tail
);
3561 Fput (Qarith_error
, Qerror_message
, build_pure_c_string ("Arithmetic error"));
3563 PUT_ERROR (Qbeginning_of_buffer
, error_tail
, "Beginning of buffer");
3564 PUT_ERROR (Qend_of_buffer
, error_tail
, "End of buffer");
3565 PUT_ERROR (Qbuffer_read_only
, error_tail
, "Buffer is read-only");
3566 PUT_ERROR (Qtext_read_only
, pure_cons (Qbuffer_read_only
, error_tail
),
3567 "Text is read-only");
3569 DEFSYM (Qrange_error
, "range-error");
3570 DEFSYM (Qdomain_error
, "domain-error");
3571 DEFSYM (Qsingularity_error
, "singularity-error");
3572 DEFSYM (Qoverflow_error
, "overflow-error");
3573 DEFSYM (Qunderflow_error
, "underflow-error");
3575 PUT_ERROR (Qdomain_error
, arith_tail
, "Arithmetic domain error");
3577 PUT_ERROR (Qrange_error
, arith_tail
, "Arithmetic range error");
3579 PUT_ERROR (Qsingularity_error
, Fcons (Qdomain_error
, arith_tail
),
3580 "Arithmetic singularity error");
3582 PUT_ERROR (Qoverflow_error
, Fcons (Qdomain_error
, arith_tail
),
3583 "Arithmetic overflow error");
3584 PUT_ERROR (Qunderflow_error
, Fcons (Qdomain_error
, arith_tail
),
3585 "Arithmetic underflow error");
3589 staticpro (&Qunbound
);
3591 /* Types that type-of returns. */
3592 DEFSYM (Qinteger
, "integer");
3593 DEFSYM (Qsymbol
, "symbol");
3594 DEFSYM (Qstring
, "string");
3595 DEFSYM (Qcons
, "cons");
3596 DEFSYM (Qmarker
, "marker");
3597 DEFSYM (Qoverlay
, "overlay");
3598 DEFSYM (Qfloat
, "float");
3599 DEFSYM (Qwindow_configuration
, "window-configuration");
3600 DEFSYM (Qprocess
, "process");
3601 DEFSYM (Qwindow
, "window");
3602 DEFSYM (Qcompiled_function
, "compiled-function");
3603 DEFSYM (Qbuffer
, "buffer");
3604 DEFSYM (Qframe
, "frame");
3605 DEFSYM (Qvector
, "vector");
3606 DEFSYM (Qchar_table
, "char-table");
3607 DEFSYM (Qbool_vector
, "bool-vector");
3608 DEFSYM (Qhash_table
, "hash-table");
3609 DEFSYM (Qmisc
, "misc");
3611 DEFSYM (Qdefun
, "defun");
3613 DEFSYM (Qfont_spec
, "font-spec");
3614 DEFSYM (Qfont_entity
, "font-entity");
3615 DEFSYM (Qfont_object
, "font-object");
3617 DEFSYM (Qinteractive_form
, "interactive-form");
3618 DEFSYM (Qdefalias_fset_function
, "defalias-fset-function");
3620 defsubr (&Sindirect_variable
);
3621 defsubr (&Sinteractive_form
);
3624 defsubr (&Stype_of
);
3629 defsubr (&Sintegerp
);
3630 defsubr (&Sinteger_or_marker_p
);
3631 defsubr (&Snumberp
);
3632 defsubr (&Snumber_or_marker_p
);
3634 defsubr (&Snatnump
);
3635 defsubr (&Ssymbolp
);
3636 defsubr (&Skeywordp
);
3637 defsubr (&Sstringp
);
3638 defsubr (&Smultibyte_string_p
);
3639 defsubr (&Svectorp
);
3640 defsubr (&Schar_table_p
);
3641 defsubr (&Svector_or_char_table_p
);
3642 defsubr (&Sbool_vector_p
);
3644 defsubr (&Ssequencep
);
3645 defsubr (&Sbufferp
);
3646 defsubr (&Smarkerp
);
3648 defsubr (&Sbyte_code_function_p
);
3649 defsubr (&Schar_or_string_p
);
3652 defsubr (&Scar_safe
);
3653 defsubr (&Scdr_safe
);
3656 defsubr (&Ssymbol_function
);
3657 defsubr (&Sindirect_function
);
3658 defsubr (&Ssymbol_plist
);
3659 defsubr (&Ssymbol_name
);
3660 defsubr (&Smakunbound
);
3661 defsubr (&Sfmakunbound
);
3663 defsubr (&Sfboundp
);
3665 defsubr (&Sdefalias
);
3666 defsubr (&Ssetplist
);
3667 defsubr (&Ssymbol_value
);
3669 defsubr (&Sdefault_boundp
);
3670 defsubr (&Sdefault_value
);
3671 defsubr (&Sset_default
);
3672 defsubr (&Ssetq_default
);
3673 defsubr (&Smake_variable_buffer_local
);
3674 defsubr (&Smake_local_variable
);
3675 defsubr (&Skill_local_variable
);
3676 defsubr (&Smake_variable_frame_local
);
3677 defsubr (&Slocal_variable_p
);
3678 defsubr (&Slocal_variable_if_set_p
);
3679 defsubr (&Svariable_binding_locus
);
3680 #if 0 /* XXX Remove this. --lorentey */
3681 defsubr (&Sterminal_local_value
);
3682 defsubr (&Sset_terminal_local_value
);
3686 defsubr (&Snumber_to_string
);
3687 defsubr (&Sstring_to_number
);
3688 defsubr (&Seqlsign
);
3710 defsubr (&Sbyteorder
);
3711 defsubr (&Ssubr_arity
);
3712 defsubr (&Ssubr_name
);
3714 defsubr (&Sbool_vector_exclusive_or
);
3715 defsubr (&Sbool_vector_union
);
3716 defsubr (&Sbool_vector_intersection
);
3717 defsubr (&Sbool_vector_set_difference
);
3718 defsubr (&Sbool_vector_not
);
3719 defsubr (&Sbool_vector_subsetp
);
3720 defsubr (&Sbool_vector_count_consecutive
);
3721 defsubr (&Sbool_vector_count_population
);
3723 set_symbol_function (Qwholenump
, XSYMBOL (Qnatnump
)->function
);
3725 DEFVAR_LISP ("most-positive-fixnum", Vmost_positive_fixnum
,
3726 doc
: /* The largest value that is representable in a Lisp integer. */);
3727 Vmost_positive_fixnum
= make_number (MOST_POSITIVE_FIXNUM
);
3728 XSYMBOL (intern_c_string ("most-positive-fixnum"))->constant
= 1;
3730 DEFVAR_LISP ("most-negative-fixnum", Vmost_negative_fixnum
,
3731 doc
: /* The smallest value that is representable in a Lisp integer. */);
3732 Vmost_negative_fixnum
= make_number (MOST_NEGATIVE_FIXNUM
);
3733 XSYMBOL (intern_c_string ("most-negative-fixnum"))->constant
= 1;