Commit | Line | Data |
---|---|---|
7921925c | 1 | /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter. |
acaf905b | 2 | Copyright (C) 1985-1986, 1988, 1993-1995, 1997-2012 |
8cabe764 | 3 | Free Software Foundation, Inc. |
7921925c JB |
4 | |
5 | This file is part of GNU Emacs. | |
6 | ||
9ec0b715 | 7 | GNU Emacs is free software: you can redistribute it and/or modify |
7921925c | 8 | it under the terms of the GNU General Public License as published by |
9ec0b715 GM |
9 | the Free Software Foundation, either version 3 of the License, or |
10 | (at your option) any later version. | |
7921925c JB |
11 | |
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. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
9ec0b715 | 18 | along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ |
7921925c JB |
19 | |
20 | ||
18160b98 | 21 | #include <config.h> |
dd8daec5 | 22 | #include <stdio.h> |
0ae6bdee PE |
23 | |
24 | #include <intprops.h> | |
25 | ||
7921925c | 26 | #include "lisp.h" |
29eab336 | 27 | #include "puresize.h" |
e6e1f521 | 28 | #include "character.h" |
7921925c | 29 | #include "buffer.h" |
077d751f | 30 | #include "keyboard.h" |
b0c2d1c6 | 31 | #include "frame.h" |
a44804c2 | 32 | #include "syssignal.h" |
620c53a6 | 33 | #include "termhooks.h" /* For FRAME_KBOARD reference in y-or-n-p. */ |
4e6f2626 | 34 | #include "font.h" |
61b108cc | 35 | #include "keymap.h" |
fb8e9847 | 36 | |
2f261542 | 37 | #include <float.h> |
ad8d56b9 PE |
38 | #if (FLT_RADIX == 2 && FLT_MANT_DIG == 24 \ |
39 | && FLT_MIN_EXP == -125 && FLT_MAX_EXP == 128) | |
40 | #define IEEE_FLOATING_POINT 1 | |
41 | #else | |
42 | #define IEEE_FLOATING_POINT 0 | |
43 | #endif | |
7921925c | 44 | |
955cbe7b PE |
45 | Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound; |
46 | static Lisp_Object Qsubr; | |
7921925c | 47 | Lisp_Object Qerror_conditions, Qerror_message, Qtop_level; |
71873e2b | 48 | Lisp_Object Qerror, Quser_error, Qquit, Qargs_out_of_range; |
955cbe7b PE |
49 | static Lisp_Object Qwrong_type_argument; |
50 | Lisp_Object Qvoid_variable, Qvoid_function; | |
51 | static Lisp_Object Qcyclic_function_indirection; | |
52 | static Lisp_Object Qcyclic_variable_indirection; | |
53 | Lisp_Object Qcircular_list; | |
54 | static Lisp_Object Qsetting_constant; | |
55 | Lisp_Object Qinvalid_read_syntax; | |
7921925c | 56 | Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch; |
3b8819d6 | 57 | Lisp_Object Qend_of_file, Qarith_error, Qmark_inactive; |
7921925c | 58 | Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only; |
8f9f49d7 | 59 | Lisp_Object Qtext_read_only; |
6b61353c | 60 | |
955cbe7b PE |
61 | Lisp_Object Qintegerp, Qwholenump, Qsymbolp, Qlistp, Qconsp; |
62 | static Lisp_Object Qnatnump; | |
7921925c JB |
63 | Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp; |
64 | Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp; | |
955cbe7b PE |
65 | Lisp_Object Qbuffer_or_string_p; |
66 | static Lisp_Object Qkeywordp, Qboundp; | |
67 | Lisp_Object Qfboundp; | |
7f0edce7 | 68 | Lisp_Object Qchar_table_p, Qvector_or_char_table_p; |
39bcc759 | 69 | |
7921925c | 70 | Lisp_Object Qcdr; |
955cbe7b | 71 | static Lisp_Object Qad_advice_info, Qad_activate_internal; |
7921925c | 72 | |
c990426a PE |
73 | static Lisp_Object Qdomain_error, Qsingularity_error, Qunderflow_error; |
74 | Lisp_Object Qrange_error, Qoverflow_error; | |
6315e761 | 75 | |
464f8898 | 76 | Lisp_Object Qfloatp; |
7921925c | 77 | Lisp_Object Qnumberp, Qnumber_or_marker_p; |
7921925c | 78 | |
b52d6985 PE |
79 | Lisp_Object Qinteger, Qsymbol; |
80 | static Lisp_Object Qcons, Qfloat, Qmisc, Qstring, Qvector; | |
e6cba650 | 81 | Lisp_Object Qwindow; |
3ab6e069 DA |
82 | static Lisp_Object Qoverlay, Qwindow_configuration; |
83 | static Lisp_Object Qprocess, Qmarker; | |
84 | static Lisp_Object Qcompiled_function, Qframe; | |
4b66faf3 | 85 | Lisp_Object Qbuffer; |
81dc5de5 | 86 | static Lisp_Object Qchar_table, Qbool_vector, Qhash_table; |
6f0e897f | 87 | static Lisp_Object Qsubrp, Qmany, Qunevalled; |
4e6f2626 | 88 | Lisp_Object Qfont_spec, Qfont_entity, Qfont_object; |
61b108cc | 89 | static Lisp_Object Qdefun; |
39bcc759 | 90 | |
3860280a CY |
91 | Lisp_Object Qinteractive_form; |
92 | ||
ce5b453a | 93 | static void swap_in_symval_forwarding (struct Lisp_Symbol *, struct Lisp_Buffer_Local_Value *); |
d02eeab3 | 94 | |
13d95cc0 | 95 | |
7921925c | 96 | Lisp_Object |
971de7fb | 97 | wrong_type_argument (register Lisp_Object predicate, register Lisp_Object value) |
7921925c | 98 | { |
2de9f71c SM |
99 | /* If VALUE is not even a valid Lisp object, we'd want to abort here |
100 | where we can get a backtrace showing where it came from. We used | |
101 | to try and do that by checking the tagbits, but nowadays all | |
102 | tagbits are potentially valid. */ | |
103 | /* if ((unsigned int) XTYPE (value) >= Lisp_Type_Limit) | |
1088b922 | 104 | * emacs_abort (); */ |
e1351ff7 | 105 | |
740ef0b5 | 106 | xsignal2 (Qwrong_type_argument, predicate, value); |
7921925c JB |
107 | } |
108 | ||
dfcf069d | 109 | void |
971de7fb | 110 | pure_write_error (void) |
7921925c JB |
111 | { |
112 | error ("Attempt to modify read-only object"); | |
113 | } | |
114 | ||
115 | void | |
971de7fb | 116 | args_out_of_range (Lisp_Object a1, Lisp_Object a2) |
7921925c | 117 | { |
740ef0b5 | 118 | xsignal2 (Qargs_out_of_range, a1, a2); |
7921925c JB |
119 | } |
120 | ||
121 | void | |
971de7fb | 122 | args_out_of_range_3 (Lisp_Object a1, Lisp_Object a2, Lisp_Object a3) |
7921925c | 123 | { |
740ef0b5 | 124 | xsignal3 (Qargs_out_of_range, a1, a2, a3); |
7921925c JB |
125 | } |
126 | ||
7921925c | 127 | \f |
61b108cc | 128 | /* Data type predicates. */ |
7921925c JB |
129 | |
130 | DEFUN ("eq", Feq, Seq, 2, 2, 0, | |
8c1a1077 | 131 | doc: /* Return t if the two args are the same Lisp object. */) |
5842a27b | 132 | (Lisp_Object obj1, Lisp_Object obj2) |
7921925c JB |
133 | { |
134 | if (EQ (obj1, obj2)) | |
135 | return Qt; | |
136 | return Qnil; | |
137 | } | |
138 | ||
8c1a1077 PJ |
139 | DEFUN ("null", Fnull, Snull, 1, 1, 0, |
140 | doc: /* Return t if OBJECT is nil. */) | |
5842a27b | 141 | (Lisp_Object object) |
7921925c | 142 | { |
39bcc759 | 143 | if (NILP (object)) |
7921925c JB |
144 | return Qt; |
145 | return Qnil; | |
146 | } | |
147 | ||
39bcc759 | 148 | DEFUN ("type-of", Ftype_of, Stype_of, 1, 1, 0, |
8c1a1077 PJ |
149 | doc: /* Return a symbol representing the type of OBJECT. |
150 | The symbol returned names the object's basic type; | |
151 | for example, (type-of 1) returns `integer'. */) | |
5842a27b | 152 | (Lisp_Object object) |
39bcc759 | 153 | { |
8e50cc2d | 154 | switch (XTYPE (object)) |
39bcc759 | 155 | { |
2de9f71c | 156 | case_Lisp_Int: |
39bcc759 RS |
157 | return Qinteger; |
158 | ||
159 | case Lisp_Symbol: | |
160 | return Qsymbol; | |
161 | ||
162 | case Lisp_String: | |
163 | return Qstring; | |
164 | ||
165 | case Lisp_Cons: | |
166 | return Qcons; | |
167 | ||
168 | case Lisp_Misc: | |
324a6eef | 169 | switch (XMISCTYPE (object)) |
39bcc759 RS |
170 | { |
171 | case Lisp_Misc_Marker: | |
172 | return Qmarker; | |
173 | case Lisp_Misc_Overlay: | |
174 | return Qoverlay; | |
175 | case Lisp_Misc_Float: | |
176 | return Qfloat; | |
177 | } | |
1088b922 | 178 | emacs_abort (); |
39bcc759 RS |
179 | |
180 | case Lisp_Vectorlike: | |
8e50cc2d | 181 | if (WINDOW_CONFIGURATIONP (object)) |
39bcc759 | 182 | return Qwindow_configuration; |
8e50cc2d | 183 | if (PROCESSP (object)) |
39bcc759 | 184 | return Qprocess; |
8e50cc2d | 185 | if (WINDOWP (object)) |
39bcc759 | 186 | return Qwindow; |
8e50cc2d | 187 | if (SUBRP (object)) |
39bcc759 | 188 | return Qsubr; |
876c194c SM |
189 | if (COMPILEDP (object)) |
190 | return Qcompiled_function; | |
8e50cc2d | 191 | if (BUFFERP (object)) |
39bcc759 | 192 | return Qbuffer; |
8e50cc2d | 193 | if (CHAR_TABLE_P (object)) |
fc67d5be | 194 | return Qchar_table; |
8e50cc2d | 195 | if (BOOL_VECTOR_P (object)) |
fc67d5be | 196 | return Qbool_vector; |
8e50cc2d | 197 | if (FRAMEP (object)) |
39bcc759 | 198 | return Qframe; |
8e50cc2d | 199 | if (HASH_TABLE_P (object)) |
81dc5de5 | 200 | return Qhash_table; |
4e6f2626 CY |
201 | if (FONT_SPEC_P (object)) |
202 | return Qfont_spec; | |
203 | if (FONT_ENTITY_P (object)) | |
204 | return Qfont_entity; | |
205 | if (FONT_OBJECT_P (object)) | |
206 | return Qfont_object; | |
39bcc759 RS |
207 | return Qvector; |
208 | ||
39bcc759 RS |
209 | case Lisp_Float: |
210 | return Qfloat; | |
39bcc759 RS |
211 | |
212 | default: | |
1088b922 | 213 | emacs_abort (); |
39bcc759 RS |
214 | } |
215 | } | |
216 | ||
8c1a1077 PJ |
217 | DEFUN ("consp", Fconsp, Sconsp, 1, 1, 0, |
218 | doc: /* Return t if OBJECT is a cons cell. */) | |
5842a27b | 219 | (Lisp_Object object) |
7921925c | 220 | { |
39bcc759 | 221 | if (CONSP (object)) |
7921925c JB |
222 | return Qt; |
223 | return Qnil; | |
224 | } | |
225 | ||
25638b07 | 226 | DEFUN ("atom", Fatom, Satom, 1, 1, 0, |
8c1a1077 | 227 | doc: /* Return t if OBJECT is not a cons cell. This includes nil. */) |
5842a27b | 228 | (Lisp_Object object) |
7921925c | 229 | { |
39bcc759 | 230 | if (CONSP (object)) |
7921925c JB |
231 | return Qnil; |
232 | return Qt; | |
233 | } | |
234 | ||
25638b07 | 235 | DEFUN ("listp", Flistp, Slistp, 1, 1, 0, |
4cdcdcc9 LT |
236 | doc: /* Return t if OBJECT is a list, that is, a cons cell or nil. |
237 | Otherwise, return nil. */) | |
5842a27b | 238 | (Lisp_Object object) |
7921925c | 239 | { |
39bcc759 | 240 | if (CONSP (object) || NILP (object)) |
7921925c JB |
241 | return Qt; |
242 | return Qnil; | |
243 | } | |
244 | ||
25638b07 | 245 | DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0, |
8c1a1077 | 246 | doc: /* Return t if OBJECT is not a list. Lists include nil. */) |
5842a27b | 247 | (Lisp_Object object) |
7921925c | 248 | { |
39bcc759 | 249 | if (CONSP (object) || NILP (object)) |
7921925c JB |
250 | return Qnil; |
251 | return Qt; | |
252 | } | |
253 | \f | |
25638b07 | 254 | DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0, |
8c1a1077 | 255 | doc: /* Return t if OBJECT is a symbol. */) |
5842a27b | 256 | (Lisp_Object object) |
7921925c | 257 | { |
39bcc759 | 258 | if (SYMBOLP (object)) |
7921925c JB |
259 | return Qt; |
260 | return Qnil; | |
261 | } | |
262 | ||
cda9b832 DL |
263 | /* Define this in C to avoid unnecessarily consing up the symbol |
264 | name. */ | |
265 | DEFUN ("keywordp", Fkeywordp, Skeywordp, 1, 1, 0, | |
8c1a1077 PJ |
266 | doc: /* Return t if OBJECT is a keyword. |
267 | This means that it is a symbol with a print name beginning with `:' | |
268 | interned in the initial obarray. */) | |
5842a27b | 269 | (Lisp_Object object) |
cda9b832 DL |
270 | { |
271 | if (SYMBOLP (object) | |
d5db4077 | 272 | && SREF (SYMBOL_NAME (object), 0) == ':' |
f35d5bad | 273 | && SYMBOL_INTERNED_IN_INITIAL_OBARRAY_P (object)) |
cda9b832 DL |
274 | return Qt; |
275 | return Qnil; | |
276 | } | |
277 | ||
25638b07 | 278 | DEFUN ("vectorp", Fvectorp, Svectorp, 1, 1, 0, |
8c1a1077 | 279 | doc: /* Return t if OBJECT is a vector. */) |
5842a27b | 280 | (Lisp_Object object) |
7921925c | 281 | { |
39bcc759 | 282 | if (VECTORP (object)) |
7921925c JB |
283 | return Qt; |
284 | return Qnil; | |
285 | } | |
286 | ||
25638b07 | 287 | DEFUN ("stringp", Fstringp, Sstringp, 1, 1, 0, |
8c1a1077 | 288 | doc: /* Return t if OBJECT is a string. */) |
5842a27b | 289 | (Lisp_Object object) |
7921925c | 290 | { |
39bcc759 | 291 | if (STRINGP (object)) |
7921925c JB |
292 | return Qt; |
293 | return Qnil; | |
294 | } | |
295 | ||
25638b07 | 296 | DEFUN ("multibyte-string-p", Fmultibyte_string_p, Smultibyte_string_p, |
8c1a1077 PJ |
297 | 1, 1, 0, |
298 | doc: /* Return t if OBJECT is a multibyte string. */) | |
5842a27b | 299 | (Lisp_Object object) |
25638b07 RS |
300 | { |
301 | if (STRINGP (object) && STRING_MULTIBYTE (object)) | |
302 | return Qt; | |
303 | return Qnil; | |
304 | } | |
305 | ||
306 | DEFUN ("char-table-p", Fchar_table_p, Schar_table_p, 1, 1, 0, | |
8c1a1077 | 307 | doc: /* Return t if OBJECT is a char-table. */) |
5842a27b | 308 | (Lisp_Object object) |
4d276982 RS |
309 | { |
310 | if (CHAR_TABLE_P (object)) | |
311 | return Qt; | |
312 | return Qnil; | |
313 | } | |
314 | ||
7f0edce7 RS |
315 | DEFUN ("vector-or-char-table-p", Fvector_or_char_table_p, |
316 | Svector_or_char_table_p, 1, 1, 0, | |
8c1a1077 | 317 | doc: /* Return t if OBJECT is a char-table or vector. */) |
5842a27b | 318 | (Lisp_Object object) |
7f0edce7 RS |
319 | { |
320 | if (VECTORP (object) || CHAR_TABLE_P (object)) | |
321 | return Qt; | |
322 | return Qnil; | |
323 | } | |
324 | ||
8c1a1077 PJ |
325 | DEFUN ("bool-vector-p", Fbool_vector_p, Sbool_vector_p, 1, 1, 0, |
326 | doc: /* Return t if OBJECT is a bool-vector. */) | |
5842a27b | 327 | (Lisp_Object object) |
4d276982 RS |
328 | { |
329 | if (BOOL_VECTOR_P (object)) | |
330 | return Qt; | |
331 | return Qnil; | |
332 | } | |
333 | ||
8c1a1077 PJ |
334 | DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0, |
335 | doc: /* Return t if OBJECT is an array (string or vector). */) | |
5842a27b | 336 | (Lisp_Object object) |
7921925c | 337 | { |
0c64a8cd | 338 | if (ARRAYP (object)) |
7921925c JB |
339 | return Qt; |
340 | return Qnil; | |
341 | } | |
342 | ||
343 | DEFUN ("sequencep", Fsequencep, Ssequencep, 1, 1, 0, | |
8c1a1077 | 344 | doc: /* Return t if OBJECT is a sequence (list or array). */) |
5842a27b | 345 | (register Lisp_Object object) |
7921925c | 346 | { |
0c64a8cd | 347 | if (CONSP (object) || NILP (object) || ARRAYP (object)) |
7921925c JB |
348 | return Qt; |
349 | return Qnil; | |
350 | } | |
351 | ||
8c1a1077 PJ |
352 | DEFUN ("bufferp", Fbufferp, Sbufferp, 1, 1, 0, |
353 | doc: /* Return t if OBJECT is an editor buffer. */) | |
5842a27b | 354 | (Lisp_Object object) |
7921925c | 355 | { |
39bcc759 | 356 | if (BUFFERP (object)) |
7921925c JB |
357 | return Qt; |
358 | return Qnil; | |
359 | } | |
360 | ||
8c1a1077 PJ |
361 | DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0, |
362 | doc: /* Return t if OBJECT is a marker (editor pointer). */) | |
5842a27b | 363 | (Lisp_Object object) |
7921925c | 364 | { |
39bcc759 | 365 | if (MARKERP (object)) |
7921925c JB |
366 | return Qt; |
367 | return Qnil; | |
368 | } | |
369 | ||
8c1a1077 PJ |
370 | DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0, |
371 | doc: /* Return t if OBJECT is a built-in function. */) | |
5842a27b | 372 | (Lisp_Object object) |
7921925c | 373 | { |
39bcc759 | 374 | if (SUBRP (object)) |
7921925c JB |
375 | return Qt; |
376 | return Qnil; | |
377 | } | |
378 | ||
dbc4e1c1 | 379 | DEFUN ("byte-code-function-p", Fbyte_code_function_p, Sbyte_code_function_p, |
8c1a1077 PJ |
380 | 1, 1, 0, |
381 | doc: /* Return t if OBJECT is a byte-compiled function object. */) | |
5842a27b | 382 | (Lisp_Object object) |
7921925c | 383 | { |
39bcc759 | 384 | if (COMPILEDP (object)) |
7921925c JB |
385 | return Qt; |
386 | return Qnil; | |
387 | } | |
388 | ||
0321d75c | 389 | DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0, |
8637f5ee | 390 | doc: /* Return t if OBJECT is a character or a string. */) |
5842a27b | 391 | (register Lisp_Object object) |
7921925c | 392 | { |
cfd70f33 | 393 | if (CHARACTERP (object) || STRINGP (object)) |
7921925c JB |
394 | return Qt; |
395 | return Qnil; | |
396 | } | |
397 | \f | |
8c1a1077 PJ |
398 | DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0, |
399 | doc: /* Return t if OBJECT is an integer. */) | |
5842a27b | 400 | (Lisp_Object object) |
7921925c | 401 | { |
39bcc759 | 402 | if (INTEGERP (object)) |
7921925c JB |
403 | return Qt; |
404 | return Qnil; | |
405 | } | |
406 | ||
464f8898 | 407 | DEFUN ("integer-or-marker-p", Finteger_or_marker_p, Sinteger_or_marker_p, 1, 1, 0, |
8c1a1077 | 408 | doc: /* Return t if OBJECT is an integer or a marker (editor pointer). */) |
5842a27b | 409 | (register Lisp_Object object) |
7921925c | 410 | { |
39bcc759 | 411 | if (MARKERP (object) || INTEGERP (object)) |
7921925c JB |
412 | return Qt; |
413 | return Qnil; | |
414 | } | |
415 | ||
0321d75c | 416 | DEFUN ("natnump", Fnatnump, Snatnump, 1, 1, 0, |
8c1a1077 | 417 | doc: /* Return t if OBJECT is a nonnegative integer. */) |
5842a27b | 418 | (Lisp_Object object) |
7921925c | 419 | { |
39bcc759 | 420 | if (NATNUMP (object)) |
7921925c JB |
421 | return Qt; |
422 | return Qnil; | |
423 | } | |
424 | ||
425 | DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0, | |
8c1a1077 | 426 | doc: /* Return t if OBJECT is a number (floating point or integer). */) |
5842a27b | 427 | (Lisp_Object object) |
7921925c | 428 | { |
39bcc759 | 429 | if (NUMBERP (object)) |
7921925c | 430 | return Qt; |
dbc4e1c1 JB |
431 | else |
432 | return Qnil; | |
7921925c JB |
433 | } |
434 | ||
435 | DEFUN ("number-or-marker-p", Fnumber_or_marker_p, | |
436 | Snumber_or_marker_p, 1, 1, 0, | |
8c1a1077 | 437 | doc: /* Return t if OBJECT is a number or a marker. */) |
5842a27b | 438 | (Lisp_Object object) |
7921925c | 439 | { |
39bcc759 | 440 | if (NUMBERP (object) || MARKERP (object)) |
7921925c JB |
441 | return Qt; |
442 | return Qnil; | |
443 | } | |
464f8898 | 444 | |
464f8898 | 445 | DEFUN ("floatp", Ffloatp, Sfloatp, 1, 1, 0, |
8c1a1077 | 446 | doc: /* Return t if OBJECT is a floating point number. */) |
5842a27b | 447 | (Lisp_Object object) |
464f8898 | 448 | { |
39bcc759 | 449 | if (FLOATP (object)) |
464f8898 RS |
450 | return Qt; |
451 | return Qnil; | |
452 | } | |
cc94f3b2 | 453 | |
7921925c JB |
454 | \f |
455 | /* Extract and set components of lists */ | |
456 | ||
a7ca3326 | 457 | DEFUN ("car", Fcar, Scar, 1, 1, 0, |
8c1a1077 | 458 | doc: /* Return the car of LIST. If arg is nil, return nil. |
9701c742 LT |
459 | Error if arg is not nil and not a cons cell. See also `car-safe'. |
460 | ||
da46c5be LT |
461 | See Info node `(elisp)Cons Cells' for a discussion of related basic |
462 | Lisp concepts such as car, cdr, cons cell and list. */) | |
5842a27b | 463 | (register Lisp_Object list) |
7921925c | 464 | { |
0c64a8cd | 465 | return CAR (list); |
7921925c JB |
466 | } |
467 | ||
a7ca3326 | 468 | DEFUN ("car-safe", Fcar_safe, Scar_safe, 1, 1, 0, |
8c1a1077 | 469 | doc: /* Return the car of OBJECT if it is a cons cell, or else nil. */) |
5842a27b | 470 | (Lisp_Object object) |
7921925c | 471 | { |
0c64a8cd | 472 | return CAR_SAFE (object); |
7921925c JB |
473 | } |
474 | ||
a7ca3326 | 475 | DEFUN ("cdr", Fcdr, Scdr, 1, 1, 0, |
8c1a1077 | 476 | doc: /* Return the cdr of LIST. If arg is nil, return nil. |
9701c742 LT |
477 | Error if arg is not nil and not a cons cell. See also `cdr-safe'. |
478 | ||
da46c5be LT |
479 | See Info node `(elisp)Cons Cells' for a discussion of related basic |
480 | Lisp concepts such as cdr, car, cons cell and list. */) | |
5842a27b | 481 | (register Lisp_Object list) |
7921925c | 482 | { |
0c64a8cd | 483 | return CDR (list); |
7921925c JB |
484 | } |
485 | ||
a7ca3326 | 486 | DEFUN ("cdr-safe", Fcdr_safe, Scdr_safe, 1, 1, 0, |
8c1a1077 | 487 | doc: /* Return the cdr of OBJECT if it is a cons cell, or else nil. */) |
5842a27b | 488 | (Lisp_Object object) |
7921925c | 489 | { |
0c64a8cd | 490 | return CDR_SAFE (object); |
7921925c JB |
491 | } |
492 | ||
a7ca3326 | 493 | DEFUN ("setcar", Fsetcar, Ssetcar, 2, 2, 0, |
8c1a1077 | 494 | doc: /* Set the car of CELL to be NEWCAR. Returns NEWCAR. */) |
5842a27b | 495 | (register Lisp_Object cell, Lisp_Object newcar) |
7921925c | 496 | { |
0c64a8cd | 497 | CHECK_CONS (cell); |
7921925c | 498 | CHECK_IMPURE (cell); |
f3fbd155 | 499 | XSETCAR (cell, newcar); |
7921925c JB |
500 | return newcar; |
501 | } | |
502 | ||
a7ca3326 | 503 | DEFUN ("setcdr", Fsetcdr, Ssetcdr, 2, 2, 0, |
8c1a1077 | 504 | doc: /* Set the cdr of CELL to be NEWCDR. Returns NEWCDR. */) |
5842a27b | 505 | (register Lisp_Object cell, Lisp_Object newcdr) |
7921925c | 506 | { |
0c64a8cd | 507 | CHECK_CONS (cell); |
7921925c | 508 | CHECK_IMPURE (cell); |
f3fbd155 | 509 | XSETCDR (cell, newcdr); |
7921925c JB |
510 | return newcdr; |
511 | } | |
512 | \f | |
1ec4b7b2 | 513 | /* Extract and set components of symbols. */ |
7921925c | 514 | |
a7ca3326 | 515 | DEFUN ("boundp", Fboundp, Sboundp, 1, 1, 0, |
8c1a1077 | 516 | doc: /* Return t if SYMBOL's value is not void. */) |
5842a27b | 517 | (register Lisp_Object symbol) |
7921925c JB |
518 | { |
519 | Lisp_Object valcontents; | |
ce5b453a | 520 | struct Lisp_Symbol *sym; |
b7826503 | 521 | CHECK_SYMBOL (symbol); |
ce5b453a | 522 | sym = XSYMBOL (symbol); |
7921925c | 523 | |
ce5b453a SM |
524 | start: |
525 | switch (sym->redirect) | |
526 | { | |
527 | case SYMBOL_PLAINVAL: valcontents = SYMBOL_VAL (sym); break; | |
528 | case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; | |
529 | case SYMBOL_LOCALIZED: | |
530 | { | |
531 | struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym); | |
532 | if (blv->fwd) | |
533 | /* In set_internal, we un-forward vars when their value is | |
534 | set to Qunbound. */ | |
535 | return Qt; | |
536 | else | |
537 | { | |
538 | swap_in_symval_forwarding (sym, blv); | |
a04e2c62 | 539 | valcontents = blv_value (blv); |
ce5b453a SM |
540 | } |
541 | break; | |
542 | } | |
543 | case SYMBOL_FORWARDED: | |
544 | /* In set_internal, we un-forward vars when their value is | |
545 | set to Qunbound. */ | |
546 | return Qt; | |
1088b922 | 547 | default: emacs_abort (); |
ce5b453a | 548 | } |
7921925c | 549 | |
1bfcade3 | 550 | return (EQ (valcontents, Qunbound) ? Qnil : Qt); |
7921925c JB |
551 | } |
552 | ||
a7ca3326 | 553 | DEFUN ("fboundp", Ffboundp, Sfboundp, 1, 1, 0, |
8c1a1077 | 554 | doc: /* Return t if SYMBOL's function definition is not void. */) |
5842a27b | 555 | (register Lisp_Object symbol) |
7921925c | 556 | { |
b7826503 | 557 | CHECK_SYMBOL (symbol); |
c644523b | 558 | return EQ (XSYMBOL (symbol)->function, Qunbound) ? Qnil : Qt; |
7921925c JB |
559 | } |
560 | ||
8c1a1077 | 561 | DEFUN ("makunbound", Fmakunbound, Smakunbound, 1, 1, 0, |
bfb96cb7 FP |
562 | doc: /* Make SYMBOL's value be void. |
563 | Return SYMBOL. */) | |
5842a27b | 564 | (register Lisp_Object symbol) |
7921925c | 565 | { |
b7826503 | 566 | CHECK_SYMBOL (symbol); |
64ec26d6 | 567 | if (SYMBOL_CONSTANT_P (symbol)) |
740ef0b5 | 568 | xsignal1 (Qsetting_constant, symbol); |
d9c2a0f2 EN |
569 | Fset (symbol, Qunbound); |
570 | return symbol; | |
7921925c JB |
571 | } |
572 | ||
8c1a1077 | 573 | DEFUN ("fmakunbound", Ffmakunbound, Sfmakunbound, 1, 1, 0, |
bfb96cb7 FP |
574 | doc: /* Make SYMBOL's function definition be void. |
575 | Return SYMBOL. */) | |
5842a27b | 576 | (register Lisp_Object symbol) |
7921925c | 577 | { |
b7826503 | 578 | CHECK_SYMBOL (symbol); |
d9c2a0f2 | 579 | if (NILP (symbol) || EQ (symbol, Qt)) |
740ef0b5 | 580 | xsignal1 (Qsetting_constant, symbol); |
c644523b | 581 | set_symbol_function (symbol, Qunbound); |
d9c2a0f2 | 582 | return symbol; |
7921925c JB |
583 | } |
584 | ||
a7ca3326 | 585 | DEFUN ("symbol-function", Fsymbol_function, Ssymbol_function, 1, 1, 0, |
8c1a1077 | 586 | doc: /* Return SYMBOL's function definition. Error if that is void. */) |
5842a27b | 587 | (register Lisp_Object symbol) |
7921925c | 588 | { |
b7826503 | 589 | CHECK_SYMBOL (symbol); |
c644523b DA |
590 | if (!EQ (XSYMBOL (symbol)->function, Qunbound)) |
591 | return XSYMBOL (symbol)->function; | |
740ef0b5 | 592 | xsignal1 (Qvoid_function, symbol); |
7921925c JB |
593 | } |
594 | ||
8c1a1077 PJ |
595 | DEFUN ("symbol-plist", Fsymbol_plist, Ssymbol_plist, 1, 1, 0, |
596 | doc: /* Return SYMBOL's property list. */) | |
5842a27b | 597 | (register Lisp_Object symbol) |
7921925c | 598 | { |
b7826503 | 599 | CHECK_SYMBOL (symbol); |
c644523b | 600 | return XSYMBOL (symbol)->plist; |
7921925c JB |
601 | } |
602 | ||
a7ca3326 | 603 | DEFUN ("symbol-name", Fsymbol_name, Ssymbol_name, 1, 1, 0, |
8c1a1077 | 604 | doc: /* Return SYMBOL's name, a string. */) |
5842a27b | 605 | (register Lisp_Object symbol) |
7921925c JB |
606 | { |
607 | register Lisp_Object name; | |
608 | ||
b7826503 | 609 | CHECK_SYMBOL (symbol); |
84023177 | 610 | name = SYMBOL_NAME (symbol); |
7921925c JB |
611 | return name; |
612 | } | |
613 | ||
a7ca3326 | 614 | DEFUN ("fset", Ffset, Sfset, 2, 2, 0, |
8c1a1077 | 615 | doc: /* Set SYMBOL's function definition to DEFINITION, and return DEFINITION. */) |
5842a27b | 616 | (register Lisp_Object symbol, Lisp_Object definition) |
d9c2a0f2 | 617 | { |
764ea377 JB |
618 | register Lisp_Object function; |
619 | ||
b7826503 | 620 | CHECK_SYMBOL (symbol); |
d9c2a0f2 | 621 | if (NILP (symbol) || EQ (symbol, Qt)) |
740ef0b5 | 622 | xsignal1 (Qsetting_constant, symbol); |
764ea377 | 623 | |
c644523b | 624 | function = XSYMBOL (symbol)->function; |
764ea377 JB |
625 | |
626 | if (!NILP (Vautoload_queue) && !EQ (function, Qunbound)) | |
627 | Vautoload_queue = Fcons (Fcons (symbol, function), Vautoload_queue); | |
628 | ||
629 | if (CONSP (function) && EQ (XCAR (function), Qautoload)) | |
630 | Fput (symbol, Qautoload, XCDR (function)); | |
631 | ||
c644523b | 632 | set_symbol_function (symbol, definition); |
1053a871 | 633 | /* Handle automatic advice activation. */ |
c644523b | 634 | if (CONSP (XSYMBOL (symbol)->plist) |
1053a871 | 635 | && !NILP (Fget (symbol, Qad_advice_info))) |
f845f2c9 | 636 | { |
c1307a23 | 637 | call2 (Qad_activate_internal, symbol, Qnil); |
c644523b | 638 | definition = XSYMBOL (symbol)->function; |
f845f2c9 | 639 | } |
8c0b5540 | 640 | return definition; |
7921925c JB |
641 | } |
642 | ||
d2fde41d | 643 | DEFUN ("defalias", Fdefalias, Sdefalias, 2, 3, 0, |
1053a871 | 644 | doc: /* Set SYMBOL's function definition to DEFINITION. |
96143227 RS |
645 | Associates the function with the current load file, if any. |
646 | The optional third argument DOCSTRING specifies the documentation string | |
647 | for SYMBOL; if it is omitted or nil, SYMBOL uses the documentation string | |
1053a871 SM |
648 | determined by DEFINITION. |
649 | The return value is undefined. */) | |
5842a27b | 650 | (register Lisp_Object symbol, Lisp_Object definition, Lisp_Object docstring) |
fc08c367 | 651 | { |
8a658a52 | 652 | CHECK_SYMBOL (symbol); |
c644523b DA |
653 | if (CONSP (XSYMBOL (symbol)->function) |
654 | && EQ (XCAR (XSYMBOL (symbol)->function), Qautoload)) | |
894f6538 | 655 | LOADHIST_ATTACH (Fcons (Qt, symbol)); |
61b108cc SM |
656 | if (!NILP (Vpurify_flag) |
657 | /* If `definition' is a keymap, immutable (and copying) is wrong. */ | |
658 | && !KEYMAPP (definition)) | |
659 | definition = Fpurecopy (definition); | |
32f532b7 | 660 | definition = Ffset (symbol, definition); |
62a29071 | 661 | LOADHIST_ATTACH (Fcons (Qdefun, symbol)); |
d2fde41d SM |
662 | if (!NILP (docstring)) |
663 | Fput (symbol, Qfunction_documentation, docstring); | |
1053a871 SM |
664 | /* We used to return `definition', but now that `defun' and `defmacro' expand |
665 | to a call to `defalias', we return `symbol' for backward compatibility | |
666 | (bug#11686). */ | |
667 | return symbol; | |
fc08c367 RS |
668 | } |
669 | ||
7921925c | 670 | DEFUN ("setplist", Fsetplist, Ssetplist, 2, 2, 0, |
6b61353c | 671 | doc: /* Set SYMBOL's property list to NEWPLIST, and return NEWPLIST. */) |
5842a27b | 672 | (register Lisp_Object symbol, Lisp_Object newplist) |
7921925c | 673 | { |
b7826503 | 674 | CHECK_SYMBOL (symbol); |
c644523b | 675 | set_symbol_plist (symbol, newplist); |
7921925c JB |
676 | return newplist; |
677 | } | |
ffd56f97 | 678 | |
6f0e897f | 679 | DEFUN ("subr-arity", Fsubr_arity, Ssubr_arity, 1, 1, 0, |
8c1a1077 PJ |
680 | doc: /* Return minimum and maximum number of args allowed for SUBR. |
681 | SUBR must be a built-in function. | |
682 | The returned value is a pair (MIN . MAX). MIN is the minimum number | |
683 | of args. MAX is the maximum number or the symbol `many', for a | |
684 | function with `&rest' args, or `unevalled' for a special form. */) | |
5842a27b | 685 | (Lisp_Object subr) |
6f0e897f DL |
686 | { |
687 | short minargs, maxargs; | |
0c64a8cd | 688 | CHECK_SUBR (subr); |
6f0e897f DL |
689 | minargs = XSUBR (subr)->min_args; |
690 | maxargs = XSUBR (subr)->max_args; | |
691 | if (maxargs == MANY) | |
692 | return Fcons (make_number (minargs), Qmany); | |
693 | else if (maxargs == UNEVALLED) | |
694 | return Fcons (make_number (minargs), Qunevalled); | |
695 | else | |
696 | return Fcons (make_number (minargs), make_number (maxargs)); | |
697 | } | |
698 | ||
0fddae66 SM |
699 | DEFUN ("subr-name", Fsubr_name, Ssubr_name, 1, 1, 0, |
700 | doc: /* Return name of subroutine SUBR. | |
701 | SUBR must be a built-in function. */) | |
5842a27b | 702 | (Lisp_Object subr) |
0fddae66 SM |
703 | { |
704 | const char *name; | |
0c64a8cd | 705 | CHECK_SUBR (subr); |
0fddae66 | 706 | name = XSUBR (subr)->symbol_name; |
f3e92b69 | 707 | return build_string (name); |
0fddae66 SM |
708 | } |
709 | ||
a7ca3326 | 710 | DEFUN ("interactive-form", Finteractive_form, Sinteractive_form, 1, 1, 0, |
6b61353c | 711 | doc: /* Return the interactive form of CMD or nil if none. |
df133612 LT |
712 | If CMD is not a command, the return value is nil. |
713 | Value, if non-nil, is a list \(interactive SPEC). */) | |
5842a27b | 714 | (Lisp_Object cmd) |
cc515226 | 715 | { |
c4f46926 | 716 | Lisp_Object fun = indirect_function (cmd); /* Check cycles. */ |
764ea377 | 717 | |
c4f46926 SM |
718 | if (NILP (fun) || EQ (fun, Qunbound)) |
719 | return Qnil; | |
720 | ||
721 | /* Use an `interactive-form' property if present, analogous to the | |
722 | function-documentation property. */ | |
723 | fun = cmd; | |
724 | while (SYMBOLP (fun)) | |
725 | { | |
3860280a | 726 | Lisp_Object tmp = Fget (fun, Qinteractive_form); |
c4f46926 SM |
727 | if (!NILP (tmp)) |
728 | return tmp; | |
729 | else | |
730 | fun = Fsymbol_function (fun); | |
731 | } | |
6b61353c KH |
732 | |
733 | if (SUBRP (fun)) | |
734 | { | |
eec47d6b | 735 | const char *spec = XSUBR (fun)->intspec; |
8a6d230a MC |
736 | if (spec) |
737 | return list2 (Qinteractive, | |
738 | (*spec != '(') ? build_string (spec) : | |
739 | Fcar (Fread_from_string (build_string (spec), Qnil, Qnil))); | |
6b61353c KH |
740 | } |
741 | else if (COMPILEDP (fun)) | |
742 | { | |
743 | if ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE) | |
744 | return list2 (Qinteractive, AREF (fun, COMPILED_INTERACTIVE)); | |
745 | } | |
746 | else if (CONSP (fun)) | |
747 | { | |
748 | Lisp_Object funcar = XCAR (fun); | |
b38b1ec0 | 749 | if (EQ (funcar, Qclosure)) |
23aba0ea SM |
750 | return Fassq (Qinteractive, Fcdr (Fcdr (XCDR (fun)))); |
751 | else if (EQ (funcar, Qlambda)) | |
6b61353c KH |
752 | return Fassq (Qinteractive, Fcdr (XCDR (fun))); |
753 | else if (EQ (funcar, Qautoload)) | |
754 | { | |
755 | struct gcpro gcpro1; | |
756 | GCPRO1 (cmd); | |
7abaf5cc | 757 | Fautoload_do_load (fun, cmd, Qnil); |
6b61353c KH |
758 | UNGCPRO; |
759 | return Finteractive_form (cmd); | |
760 | } | |
761 | } | |
cc515226 GM |
762 | return Qnil; |
763 | } | |
764 | ||
7921925c | 765 | \f |
f35d5bad GM |
766 | /*********************************************************************** |
767 | Getting and Setting Values of Symbols | |
768 | ***********************************************************************/ | |
769 | ||
770 | /* Return the symbol holding SYMBOL's value. Signal | |
771 | `cyclic-variable-indirection' if SYMBOL's chain of variable | |
772 | indirections contains a loop. */ | |
773 | ||
ad97b375 | 774 | struct Lisp_Symbol * |
971de7fb | 775 | indirect_variable (struct Lisp_Symbol *symbol) |
f35d5bad | 776 | { |
ad97b375 | 777 | struct Lisp_Symbol *tortoise, *hare; |
f35d5bad GM |
778 | |
779 | hare = tortoise = symbol; | |
780 | ||
ce5b453a | 781 | while (hare->redirect == SYMBOL_VARALIAS) |
f35d5bad | 782 | { |
ce5b453a SM |
783 | hare = SYMBOL_ALIAS (hare); |
784 | if (hare->redirect != SYMBOL_VARALIAS) | |
f35d5bad | 785 | break; |
bfb96cb7 | 786 | |
ce5b453a SM |
787 | hare = SYMBOL_ALIAS (hare); |
788 | tortoise = SYMBOL_ALIAS (tortoise); | |
f35d5bad | 789 | |
ad97b375 SM |
790 | if (hare == tortoise) |
791 | { | |
792 | Lisp_Object tem; | |
793 | XSETSYMBOL (tem, symbol); | |
794 | xsignal1 (Qcyclic_variable_indirection, tem); | |
795 | } | |
f35d5bad GM |
796 | } |
797 | ||
798 | return hare; | |
799 | } | |
800 | ||
801 | ||
802 | DEFUN ("indirect-variable", Findirect_variable, Sindirect_variable, 1, 1, 0, | |
8c1a1077 | 803 | doc: /* Return the variable at the end of OBJECT's variable chain. |
4abcdac8 CY |
804 | If OBJECT is a symbol, follow its variable indirections (if any), and |
805 | return the variable at the end of the chain of aliases. See Info node | |
806 | `(elisp)Variable Aliases'. | |
807 | ||
808 | If OBJECT is not a symbol, just return it. If there is a loop in the | |
809 | chain of aliases, signal a `cyclic-variable-indirection' error. */) | |
5842a27b | 810 | (Lisp_Object object) |
f35d5bad GM |
811 | { |
812 | if (SYMBOLP (object)) | |
946f9a5b PE |
813 | { |
814 | struct Lisp_Symbol *sym = indirect_variable (XSYMBOL (object)); | |
815 | XSETSYMBOL (object, sym); | |
816 | } | |
f35d5bad GM |
817 | return object; |
818 | } | |
819 | ||
7921925c JB |
820 | |
821 | /* Given the raw contents of a symbol value cell, | |
822 | return the Lisp value of the symbol. | |
823 | This does not handle buffer-local variables; use | |
824 | swap_in_symval_forwarding for that. */ | |
825 | ||
826 | Lisp_Object | |
971de7fb | 827 | do_symval_forwarding (register union Lisp_Fwd *valcontents) |
7921925c JB |
828 | { |
829 | register Lisp_Object val; | |
ce5b453a SM |
830 | switch (XFWDTYPE (valcontents)) |
831 | { | |
832 | case Lisp_Fwd_Int: | |
833 | XSETINT (val, *XINTFWD (valcontents)->intvar); | |
834 | return val; | |
835 | ||
836 | case Lisp_Fwd_Bool: | |
837 | return (*XBOOLFWD (valcontents)->boolvar ? Qt : Qnil); | |
838 | ||
839 | case Lisp_Fwd_Obj: | |
840 | return *XOBJFWD (valcontents)->objvar; | |
841 | ||
842 | case Lisp_Fwd_Buffer_Obj: | |
4ce60d2e | 843 | return per_buffer_value (current_buffer, |
ce5b453a SM |
844 | XBUFFER_OBJFWD (valcontents)->offset); |
845 | ||
846 | case Lisp_Fwd_Kboard_Obj: | |
847 | /* We used to simply use current_kboard here, but from Lisp | |
a98edce9 | 848 | code, its value is often unexpected. It seems nicer to |
ce5b453a SM |
849 | allow constructions like this to work as intuitively expected: |
850 | ||
851 | (with-selected-frame frame | |
852 | (define-key local-function-map "\eOP" [f1])) | |
853 | ||
854 | On the other hand, this affects the semantics of | |
855 | last-command and real-last-command, and people may rely on | |
856 | that. I took a quick look at the Lisp codebase, and I | |
857 | don't think anything will break. --lorentey */ | |
858 | return *(Lisp_Object *)(XKBOARD_OBJFWD (valcontents)->offset | |
859 | + (char *)FRAME_KBOARD (SELECTED_FRAME ())); | |
1088b922 | 860 | default: emacs_abort (); |
ce5b453a | 861 | } |
7921925c JB |
862 | } |
863 | ||
d9c2a0f2 EN |
864 | /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell |
865 | of SYMBOL. If SYMBOL is buffer-local, VALCONTENTS should be the | |
7921925c | 866 | buffer-independent contents of the value cell: forwarded just one |
7a283f36 GM |
867 | step past the buffer-localness. |
868 | ||
869 | BUF non-zero means set the value in buffer BUF instead of the | |
870 | current buffer. This only plays a role for per-buffer variables. */ | |
7921925c | 871 | |
ce5b453a | 872 | static void |
971de7fb | 873 | store_symval_forwarding (union Lisp_Fwd *valcontents, register Lisp_Object newval, struct buffer *buf) |
7921925c | 874 | { |
ce5b453a | 875 | switch (XFWDTYPE (valcontents)) |
7921925c | 876 | { |
ce5b453a SM |
877 | case Lisp_Fwd_Int: |
878 | CHECK_NUMBER (newval); | |
879 | *XINTFWD (valcontents)->intvar = XINT (newval); | |
880 | break; | |
aa3830c4 | 881 | |
ce5b453a SM |
882 | case Lisp_Fwd_Bool: |
883 | *XBOOLFWD (valcontents)->boolvar = !NILP (newval); | |
884 | break; | |
aa3830c4 | 885 | |
ce5b453a SM |
886 | case Lisp_Fwd_Obj: |
887 | *XOBJFWD (valcontents)->objvar = newval; | |
aa3830c4 | 888 | |
ce5b453a SM |
889 | /* If this variable is a default for something stored |
890 | in the buffer itself, such as default-fill-column, | |
891 | find the buffers that don't have local values for it | |
892 | and update them. */ | |
893 | if (XOBJFWD (valcontents)->objvar > (Lisp_Object *) &buffer_defaults | |
894 | && XOBJFWD (valcontents)->objvar < (Lisp_Object *) (&buffer_defaults + 1)) | |
46b2ac21 | 895 | { |
ce5b453a SM |
896 | int offset = ((char *) XOBJFWD (valcontents)->objvar |
897 | - (char *) &buffer_defaults); | |
898 | int idx = PER_BUFFER_IDX (offset); | |
aa3830c4 | 899 | |
ce5b453a | 900 | Lisp_Object tail; |
aa3830c4 | 901 | |
ce5b453a SM |
902 | if (idx <= 0) |
903 | break; | |
aa3830c4 | 904 | |
ce5b453a | 905 | for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail)) |
6b61353c | 906 | { |
b9b84fa9 | 907 | Lisp_Object lbuf; |
ce5b453a | 908 | struct buffer *b; |
6b61353c | 909 | |
b9b84fa9 PE |
910 | lbuf = Fcdr (XCAR (tail)); |
911 | if (!BUFFERP (lbuf)) continue; | |
912 | b = XBUFFER (lbuf); | |
6b61353c | 913 | |
ce5b453a | 914 | if (! PER_BUFFER_VALUE_P (b, idx)) |
4ce60d2e | 915 | set_per_buffer_value (b, offset, newval); |
6b61353c | 916 | } |
ce5b453a SM |
917 | } |
918 | break; | |
7403b5c8 | 919 | |
ce5b453a SM |
920 | case Lisp_Fwd_Buffer_Obj: |
921 | { | |
922 | int offset = XBUFFER_OBJFWD (valcontents)->offset; | |
923 | Lisp_Object type = XBUFFER_OBJFWD (valcontents)->slottype; | |
924 | ||
925 | if (!(NILP (type) || NILP (newval) | |
d5040d2d | 926 | || (XINT (type) == Lisp_Int0 |
ce5b453a SM |
927 | ? INTEGERP (newval) |
928 | : XTYPE (newval) == XINT (type)))) | |
929 | buffer_slot_type_mismatch (newval, XINT (type)); | |
930 | ||
931 | if (buf == NULL) | |
932 | buf = current_buffer; | |
4ce60d2e | 933 | set_per_buffer_value (buf, offset, newval); |
ce5b453a SM |
934 | } |
935 | break; | |
7403b5c8 | 936 | |
ce5b453a SM |
937 | case Lisp_Fwd_Kboard_Obj: |
938 | { | |
939 | char *base = (char *) FRAME_KBOARD (SELECTED_FRAME ()); | |
940 | char *p = base + XKBOARD_OBJFWD (valcontents)->offset; | |
941 | *(Lisp_Object *) p = newval; | |
942 | } | |
7921925c JB |
943 | break; |
944 | ||
7921925c | 945 | default: |
1088b922 | 946 | emacs_abort (); /* goto def; */ |
7921925c JB |
947 | } |
948 | } | |
949 | ||
d73e321c DA |
950 | /* Set up SYMBOL to refer to its global binding. This makes it safe |
951 | to alter the status of other bindings. BEWARE: this may be called | |
952 | during the mark phase of GC, where we assume that Lisp_Object slots | |
953 | of BLV are marked after this function has changed them. */ | |
b0d53add GM |
954 | |
955 | void | |
971de7fb | 956 | swap_in_global_binding (struct Lisp_Symbol *symbol) |
b0d53add | 957 | { |
ce5b453a | 958 | struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (symbol); |
b0d53add GM |
959 | |
960 | /* Unload the previously loaded binding. */ | |
ce5b453a | 961 | if (blv->fwd) |
a04e2c62 | 962 | set_blv_value (blv, do_symval_forwarding (blv->fwd)); |
bfb96cb7 | 963 | |
b0d53add | 964 | /* Select the global binding in the symbol. */ |
a04e2c62 | 965 | set_blv_valcell (blv, blv->defcell); |
ce5b453a SM |
966 | if (blv->fwd) |
967 | store_symval_forwarding (blv->fwd, XCDR (blv->defcell), NULL); | |
b0d53add GM |
968 | |
969 | /* Indicate that the global binding is set up now. */ | |
a04e2c62 DA |
970 | set_blv_where (blv, Qnil); |
971 | set_blv_found (blv, 0); | |
b0d53add GM |
972 | } |
973 | ||
2829d05f | 974 | /* Set up the buffer-local symbol SYMBOL for validity in the current buffer. |
42e975f0 RS |
975 | VALCONTENTS is the contents of its value cell, |
976 | which points to a struct Lisp_Buffer_Local_Value. | |
977 | ||
978 | Return the value forwarded one step past the buffer-local stage. | |
979 | This could be another forwarding pointer. */ | |
7921925c | 980 | |
ce5b453a | 981 | static void |
971de7fb | 982 | swap_in_symval_forwarding (struct Lisp_Symbol *symbol, struct Lisp_Buffer_Local_Value *blv) |
7921925c | 983 | { |
7921925c | 984 | register Lisp_Object tem1; |
bfb96cb7 | 985 | |
ce5b453a SM |
986 | eassert (blv == SYMBOL_BLV (symbol)); |
987 | ||
988 | tem1 = blv->where; | |
7921925c | 989 | |
42e975f0 | 990 | if (NILP (tem1) |
ce5b453a SM |
991 | || (blv->frame_local |
992 | ? !EQ (selected_frame, tem1) | |
993 | : current_buffer != XBUFFER (tem1))) | |
7921925c | 994 | { |
bfb96cb7 | 995 | |
42e975f0 | 996 | /* Unload the previously loaded binding. */ |
ce5b453a SM |
997 | tem1 = blv->valcell; |
998 | if (blv->fwd) | |
a04e2c62 | 999 | set_blv_value (blv, do_symval_forwarding (blv->fwd)); |
42e975f0 | 1000 | /* Choose the new binding. */ |
ce5b453a SM |
1001 | { |
1002 | Lisp_Object var; | |
1003 | XSETSYMBOL (var, symbol); | |
1004 | if (blv->frame_local) | |
1005 | { | |
e69b0960 | 1006 | tem1 = assq_no_quit (var, XFRAME (selected_frame)->param_alist); |
a04e2c62 | 1007 | set_blv_where (blv, selected_frame); |
ce5b453a SM |
1008 | } |
1009 | else | |
1010 | { | |
4b4deea2 | 1011 | tem1 = assq_no_quit (var, BVAR (current_buffer, local_var_alist)); |
d73e321c | 1012 | set_blv_where (blv, Fcurrent_buffer ()); |
ce5b453a SM |
1013 | } |
1014 | } | |
1015 | if (!(blv->found = !NILP (tem1))) | |
1016 | tem1 = blv->defcell; | |
b0c2d1c6 | 1017 | |
42e975f0 | 1018 | /* Load the new binding. */ |
a04e2c62 | 1019 | set_blv_valcell (blv, tem1); |
ce5b453a | 1020 | if (blv->fwd) |
a04e2c62 | 1021 | store_symval_forwarding (blv->fwd, blv_value (blv), NULL); |
7921925c | 1022 | } |
7921925c JB |
1023 | } |
1024 | \f | |
14e76af9 JB |
1025 | /* Find the value of a symbol, returning Qunbound if it's not bound. |
1026 | This is helpful for code which just wants to get a variable's value | |
8e6208c5 | 1027 | if it has one, without signaling an error. |
14e76af9 JB |
1028 | Note that it must not be possible to quit |
1029 | within this function. Great care is required for this. */ | |
7921925c | 1030 | |
14e76af9 | 1031 | Lisp_Object |
971de7fb | 1032 | find_symbol_value (Lisp_Object symbol) |
7921925c | 1033 | { |
ce5b453a | 1034 | struct Lisp_Symbol *sym; |
bfb96cb7 | 1035 | |
b7826503 | 1036 | CHECK_SYMBOL (symbol); |
ce5b453a | 1037 | sym = XSYMBOL (symbol); |
7921925c | 1038 | |
ce5b453a SM |
1039 | start: |
1040 | switch (sym->redirect) | |
1041 | { | |
1042 | case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; | |
1043 | case SYMBOL_PLAINVAL: return SYMBOL_VAL (sym); | |
1044 | case SYMBOL_LOCALIZED: | |
1045 | { | |
1046 | struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym); | |
1047 | swap_in_symval_forwarding (sym, blv); | |
a04e2c62 | 1048 | return blv->fwd ? do_symval_forwarding (blv->fwd) : blv_value (blv); |
ce5b453a SM |
1049 | } |
1050 | /* FALLTHROUGH */ | |
1051 | case SYMBOL_FORWARDED: | |
1052 | return do_symval_forwarding (SYMBOL_FWD (sym)); | |
1088b922 | 1053 | default: emacs_abort (); |
ce5b453a | 1054 | } |
7921925c JB |
1055 | } |
1056 | ||
a7ca3326 | 1057 | DEFUN ("symbol-value", Fsymbol_value, Ssymbol_value, 1, 1, 0, |
8c1a1077 | 1058 | doc: /* Return SYMBOL's value. Error if that is void. */) |
5842a27b | 1059 | (Lisp_Object symbol) |
14e76af9 | 1060 | { |
0671d7c0 | 1061 | Lisp_Object val; |
14e76af9 | 1062 | |
d9c2a0f2 | 1063 | val = find_symbol_value (symbol); |
740ef0b5 | 1064 | if (!EQ (val, Qunbound)) |
14e76af9 | 1065 | return val; |
740ef0b5 KS |
1066 | |
1067 | xsignal1 (Qvoid_variable, symbol); | |
14e76af9 JB |
1068 | } |
1069 | ||
a7ca3326 | 1070 | DEFUN ("set", Fset, Sset, 2, 2, 0, |
8c1a1077 | 1071 | doc: /* Set SYMBOL's value to NEWVAL, and return NEWVAL. */) |
5842a27b | 1072 | (register Lisp_Object symbol, Lisp_Object newval) |
05ef7169 | 1073 | { |
94b612ad | 1074 | set_internal (symbol, newval, Qnil, 0); |
ce5b453a | 1075 | return newval; |
05ef7169 RS |
1076 | } |
1077 | ||
de1339b0 | 1078 | /* Return true if SYMBOL currently has a let-binding |
1f35ce36 RS |
1079 | which was made in the buffer that is now current. */ |
1080 | ||
de1339b0 | 1081 | static bool |
ce5b453a | 1082 | let_shadows_buffer_binding_p (struct Lisp_Symbol *symbol) |
1f35ce36 | 1083 | { |
ce5b453a | 1084 | struct specbinding *p; |
1f35ce36 | 1085 | |
d311d28c PE |
1086 | for (p = specpdl_ptr; p > specpdl; ) |
1087 | if ((--p)->func == NULL | |
f35d5bad GM |
1088 | && CONSP (p->symbol)) |
1089 | { | |
ad97b375 | 1090 | struct Lisp_Symbol *let_bound_symbol = XSYMBOL (XCAR (p->symbol)); |
ce5b453a SM |
1091 | eassert (let_bound_symbol->redirect != SYMBOL_VARALIAS); |
1092 | if (symbol == let_bound_symbol | |
f35d5bad | 1093 | && XBUFFER (XCDR (XCDR (p->symbol))) == current_buffer) |
d311d28c | 1094 | return 1; |
f35d5bad | 1095 | } |
1f35ce36 | 1096 | |
d311d28c | 1097 | return 0; |
1f35ce36 RS |
1098 | } |
1099 | ||
de1339b0 | 1100 | static bool |
971de7fb | 1101 | let_shadows_global_binding_p (Lisp_Object symbol) |
ce5b453a SM |
1102 | { |
1103 | struct specbinding *p; | |
1104 | ||
bc985141 | 1105 | for (p = specpdl_ptr; p > specpdl; ) |
d311d28c PE |
1106 | if ((--p)->func == NULL && EQ (p->symbol, symbol)) |
1107 | return 1; | |
ce5b453a | 1108 | |
d311d28c | 1109 | return 0; |
ce5b453a SM |
1110 | } |
1111 | ||
25638b07 | 1112 | /* Store the value NEWVAL into SYMBOL. |
94b612ad SM |
1113 | If buffer/frame-locality is an issue, WHERE specifies which context to use. |
1114 | (nil stands for the current buffer/frame). | |
2829d05f | 1115 | |
de1339b0 | 1116 | If BINDFLAG is false, then if this symbol is supposed to become |
05ef7169 | 1117 | local in every buffer where it is set, then we make it local. |
de1339b0 | 1118 | If BINDFLAG is true, we don't do that. */ |
05ef7169 | 1119 | |
ce5b453a | 1120 | void |
de1339b0 PE |
1121 | set_internal (Lisp_Object symbol, Lisp_Object newval, Lisp_Object where, |
1122 | bool bindflag) | |
7921925c | 1123 | { |
de1339b0 | 1124 | bool voide = EQ (newval, Qunbound); |
ce5b453a SM |
1125 | struct Lisp_Symbol *sym; |
1126 | Lisp_Object tem1; | |
7921925c | 1127 | |
2829d05f | 1128 | /* If restoring in a dead buffer, do nothing. */ |
94b612ad SM |
1129 | /* if (BUFFERP (where) && NILP (XBUFFER (where)->name)) |
1130 | return; */ | |
2829d05f | 1131 | |
b7826503 | 1132 | CHECK_SYMBOL (symbol); |
ce5b453a | 1133 | if (SYMBOL_CONSTANT_P (symbol)) |
7921925c | 1134 | { |
ce5b453a SM |
1135 | if (NILP (Fkeywordp (symbol)) |
1136 | || !EQ (newval, Fsymbol_value (symbol))) | |
1137 | xsignal1 (Qsetting_constant, symbol); | |
1138 | else | |
1139 | /* Allow setting keywords to their own value. */ | |
1140 | return; | |
7921925c | 1141 | } |
42e975f0 | 1142 | |
ce5b453a | 1143 | sym = XSYMBOL (symbol); |
7921925c | 1144 | |
ce5b453a SM |
1145 | start: |
1146 | switch (sym->redirect) | |
1147 | { | |
1148 | case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; | |
1149 | case SYMBOL_PLAINVAL: SET_SYMBOL_VAL (sym , newval); return; | |
1150 | case SYMBOL_LOCALIZED: | |
1151 | { | |
1152 | struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym); | |
94b612ad SM |
1153 | if (NILP (where)) |
1154 | { | |
1155 | if (blv->frame_local) | |
1156 | where = selected_frame; | |
1157 | else | |
1158 | XSETBUFFER (where, current_buffer); | |
1159 | } | |
ce5b453a SM |
1160 | /* If the current buffer is not the buffer whose binding is |
1161 | loaded, or if there may be frame-local bindings and the frame | |
1162 | isn't the right one, or if it's a Lisp_Buffer_Local_Value and | |
1163 | the default binding is loaded, the loaded binding may be the | |
1164 | wrong one. */ | |
94b612ad | 1165 | if (!EQ (blv->where, where) |
bfeae2cf | 1166 | /* Also unload a global binding (if the var is local_if_set). */ |
ce5b453a SM |
1167 | || (EQ (blv->valcell, blv->defcell))) |
1168 | { | |
1169 | /* The currently loaded binding is not necessarily valid. | |
1170 | We need to unload it, and choose a new binding. */ | |
1171 | ||
1172 | /* Write out `realvalue' to the old loaded binding. */ | |
1173 | if (blv->fwd) | |
a04e2c62 | 1174 | set_blv_value (blv, do_symval_forwarding (blv->fwd)); |
b0c2d1c6 | 1175 | |
ce5b453a | 1176 | /* Find the new binding. */ |
94b612ad SM |
1177 | XSETSYMBOL (symbol, sym); /* May have changed via aliasing. */ |
1178 | tem1 = Fassq (symbol, | |
1179 | (blv->frame_local | |
e69b0960 | 1180 | ? XFRAME (where)->param_alist |
4b4deea2 | 1181 | : BVAR (XBUFFER (where), local_var_alist))); |
a04e2c62 | 1182 | set_blv_where (blv, where); |
9e677988 | 1183 | blv->found = 1; |
ce5b453a SM |
1184 | |
1185 | if (NILP (tem1)) | |
1186 | { | |
1187 | /* This buffer still sees the default value. */ | |
1188 | ||
1189 | /* If the variable is a Lisp_Some_Buffer_Local_Value, | |
1190 | or if this is `let' rather than `set', | |
1191 | make CURRENT-ALIST-ELEMENT point to itself, | |
1192 | indicating that we're seeing the default value. | |
1193 | Likewise if the variable has been let-bound | |
1194 | in the current buffer. */ | |
1195 | if (bindflag || !blv->local_if_set | |
1196 | || let_shadows_buffer_binding_p (sym)) | |
1197 | { | |
9e677988 | 1198 | blv->found = 0; |
ce5b453a SM |
1199 | tem1 = blv->defcell; |
1200 | } | |
1201 | /* If it's a local_if_set, being set not bound, | |
1202 | and we're not within a let that was made for this buffer, | |
1203 | create a new buffer-local binding for the variable. | |
1204 | That means, give this buffer a new assoc for a local value | |
1205 | and load that binding. */ | |
1206 | else | |
1207 | { | |
1208 | /* local_if_set is only supported for buffer-local | |
1209 | bindings, not for frame-local bindings. */ | |
1210 | eassert (!blv->frame_local); | |
1211 | tem1 = Fcons (symbol, XCDR (blv->defcell)); | |
39eb03f1 PE |
1212 | bset_local_var_alist |
1213 | (XBUFFER (where), | |
1214 | Fcons (tem1, BVAR (XBUFFER (where), local_var_alist))); | |
ce5b453a SM |
1215 | } |
1216 | } | |
1217 | ||
1218 | /* Record which binding is now loaded. */ | |
a04e2c62 | 1219 | set_blv_valcell (blv, tem1); |
ce5b453a | 1220 | } |
b0c2d1c6 | 1221 | |
ce5b453a | 1222 | /* Store the new value in the cons cell. */ |
a04e2c62 | 1223 | set_blv_value (blv, newval); |
d8cafeb5 | 1224 | |
ce5b453a SM |
1225 | if (blv->fwd) |
1226 | { | |
1227 | if (voide) | |
1228 | /* If storing void (making the symbol void), forward only through | |
1229 | buffer-local indicator, not through Lisp_Objfwd, etc. */ | |
1230 | blv->fwd = NULL; | |
1231 | else | |
94b612ad SM |
1232 | store_symval_forwarding (blv->fwd, newval, |
1233 | BUFFERP (where) | |
1234 | ? XBUFFER (where) : current_buffer); | |
ce5b453a SM |
1235 | } |
1236 | break; | |
1237 | } | |
1238 | case SYMBOL_FORWARDED: | |
1239 | { | |
94b612ad SM |
1240 | struct buffer *buf |
1241 | = BUFFERP (where) ? XBUFFER (where) : current_buffer; | |
ce5b453a SM |
1242 | union Lisp_Fwd *innercontents = SYMBOL_FWD (sym); |
1243 | if (BUFFER_OBJFWDP (innercontents)) | |
1244 | { | |
1245 | int offset = XBUFFER_OBJFWD (innercontents)->offset; | |
1246 | int idx = PER_BUFFER_IDX (offset); | |
1247 | if (idx > 0 | |
1248 | && !bindflag | |
1249 | && !let_shadows_buffer_binding_p (sym)) | |
1250 | SET_PER_BUFFER_VALUE_P (buf, idx, 1); | |
1251 | } | |
569c11e3 | 1252 | |
ce5b453a SM |
1253 | if (voide) |
1254 | { /* If storing void (making the symbol void), forward only through | |
1255 | buffer-local indicator, not through Lisp_Objfwd, etc. */ | |
1256 | sym->redirect = SYMBOL_PLAINVAL; | |
1257 | SET_SYMBOL_VAL (sym, newval); | |
1258 | } | |
1259 | else | |
1260 | store_symval_forwarding (/* sym, */ innercontents, newval, buf); | |
1261 | break; | |
1262 | } | |
1088b922 | 1263 | default: emacs_abort (); |
7921925c | 1264 | } |
ce5b453a | 1265 | return; |
7921925c JB |
1266 | } |
1267 | \f | |
1268 | /* Access or set a buffer-local symbol's default value. */ | |
1269 | ||
d9c2a0f2 | 1270 | /* Return the default value of SYMBOL, but don't check for voidness. |
1bfcade3 | 1271 | Return Qunbound if it is void. */ |
7921925c | 1272 | |
112396d6 | 1273 | static Lisp_Object |
971de7fb | 1274 | default_value (Lisp_Object symbol) |
7921925c | 1275 | { |
ce5b453a | 1276 | struct Lisp_Symbol *sym; |
7921925c | 1277 | |
b7826503 | 1278 | CHECK_SYMBOL (symbol); |
ce5b453a | 1279 | sym = XSYMBOL (symbol); |
7921925c | 1280 | |
ce5b453a SM |
1281 | start: |
1282 | switch (sym->redirect) | |
7921925c | 1283 | { |
ce5b453a SM |
1284 | case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; |
1285 | case SYMBOL_PLAINVAL: return SYMBOL_VAL (sym); | |
1286 | case SYMBOL_LOCALIZED: | |
1287 | { | |
1288 | /* If var is set up for a buffer that lacks a local value for it, | |
1289 | the current value is nominally the default value. | |
1290 | But the `realvalue' slot may be more up to date, since | |
1291 | ordinary setq stores just that slot. So use that. */ | |
1292 | struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym); | |
1293 | if (blv->fwd && EQ (blv->valcell, blv->defcell)) | |
1294 | return do_symval_forwarding (blv->fwd); | |
1295 | else | |
1296 | return XCDR (blv->defcell); | |
1297 | } | |
1298 | case SYMBOL_FORWARDED: | |
1299 | { | |
1300 | union Lisp_Fwd *valcontents = SYMBOL_FWD (sym); | |
7921925c | 1301 | |
ce5b453a SM |
1302 | /* For a built-in buffer-local variable, get the default value |
1303 | rather than letting do_symval_forwarding get the current value. */ | |
1304 | if (BUFFER_OBJFWDP (valcontents)) | |
1305 | { | |
1306 | int offset = XBUFFER_OBJFWD (valcontents)->offset; | |
1307 | if (PER_BUFFER_IDX (offset) != 0) | |
4ce60d2e | 1308 | return per_buffer_default (offset); |
ce5b453a SM |
1309 | } |
1310 | ||
1311 | /* For other variables, get the current value. */ | |
1312 | return do_symval_forwarding (valcontents); | |
1313 | } | |
1088b922 | 1314 | default: emacs_abort (); |
7921925c | 1315 | } |
7921925c JB |
1316 | } |
1317 | ||
a7ca3326 | 1318 | DEFUN ("default-boundp", Fdefault_boundp, Sdefault_boundp, 1, 1, 0, |
8c1a1077 PJ |
1319 | doc: /* Return t if SYMBOL has a non-void default value. |
1320 | This is the value that is seen in buffers that do not have their own values | |
1321 | for this variable. */) | |
5842a27b | 1322 | (Lisp_Object symbol) |
7921925c JB |
1323 | { |
1324 | register Lisp_Object value; | |
1325 | ||
d9c2a0f2 | 1326 | value = default_value (symbol); |
1bfcade3 | 1327 | return (EQ (value, Qunbound) ? Qnil : Qt); |
7921925c JB |
1328 | } |
1329 | ||
a7ca3326 | 1330 | DEFUN ("default-value", Fdefault_value, Sdefault_value, 1, 1, 0, |
8c1a1077 PJ |
1331 | doc: /* Return SYMBOL's default value. |
1332 | This is the value that is seen in buffers that do not have their own values | |
1333 | for this variable. The default value is meaningful for variables with | |
1334 | local bindings in certain buffers. */) | |
5842a27b | 1335 | (Lisp_Object symbol) |
7921925c JB |
1336 | { |
1337 | register Lisp_Object value; | |
1338 | ||
d9c2a0f2 | 1339 | value = default_value (symbol); |
740ef0b5 KS |
1340 | if (!EQ (value, Qunbound)) |
1341 | return value; | |
1342 | ||
1343 | xsignal1 (Qvoid_variable, symbol); | |
7921925c JB |
1344 | } |
1345 | ||
a7ca3326 | 1346 | DEFUN ("set-default", Fset_default, Sset_default, 2, 2, 0, |
6e86a75d | 1347 | doc: /* Set SYMBOL's default value to VALUE. SYMBOL and VALUE are evaluated. |
8c1a1077 PJ |
1348 | The default value is seen in buffers that do not have their own values |
1349 | for this variable. */) | |
5842a27b | 1350 | (Lisp_Object symbol, Lisp_Object value) |
7921925c | 1351 | { |
ce5b453a | 1352 | struct Lisp_Symbol *sym; |
7921925c | 1353 | |
b7826503 | 1354 | CHECK_SYMBOL (symbol); |
ce5b453a | 1355 | if (SYMBOL_CONSTANT_P (symbol)) |
7921925c | 1356 | { |
ce5b453a SM |
1357 | if (NILP (Fkeywordp (symbol)) |
1358 | || !EQ (value, Fdefault_value (symbol))) | |
1359 | xsignal1 (Qsetting_constant, symbol); | |
1360 | else | |
1361 | /* Allow setting keywords to their own value. */ | |
1362 | return value; | |
1363 | } | |
1364 | sym = XSYMBOL (symbol); | |
7921925c | 1365 | |
ce5b453a SM |
1366 | start: |
1367 | switch (sym->redirect) | |
1368 | { | |
1369 | case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; | |
1370 | case SYMBOL_PLAINVAL: return Fset (symbol, value); | |
1371 | case SYMBOL_LOCALIZED: | |
1372 | { | |
1373 | struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym); | |
984ef137 | 1374 | |
ce5b453a SM |
1375 | /* Store new value into the DEFAULT-VALUE slot. */ |
1376 | XSETCDR (blv->defcell, value); | |
bfb96cb7 | 1377 | |
ce5b453a SM |
1378 | /* If the default binding is now loaded, set the REALVALUE slot too. */ |
1379 | if (blv->fwd && EQ (blv->defcell, blv->valcell)) | |
1380 | store_symval_forwarding (blv->fwd, value, NULL); | |
1381 | return value; | |
1382 | } | |
1383 | case SYMBOL_FORWARDED: | |
1384 | { | |
1385 | union Lisp_Fwd *valcontents = SYMBOL_FWD (sym); | |
7921925c | 1386 | |
ce5b453a SM |
1387 | /* Handle variables like case-fold-search that have special slots |
1388 | in the buffer. | |
1389 | Make them work apparently like Lisp_Buffer_Local_Value variables. */ | |
1390 | if (BUFFER_OBJFWDP (valcontents)) | |
1391 | { | |
1392 | int offset = XBUFFER_OBJFWD (valcontents)->offset; | |
1393 | int idx = PER_BUFFER_IDX (offset); | |
7921925c | 1394 | |
4ce60d2e | 1395 | set_per_buffer_default (offset, value); |
7921925c | 1396 | |
ce5b453a SM |
1397 | /* If this variable is not always local in all buffers, |
1398 | set it in the buffers that don't nominally have a local value. */ | |
1399 | if (idx > 0) | |
1400 | { | |
1401 | struct buffer *b; | |
7921925c | 1402 | |
52b852c7 | 1403 | FOR_EACH_BUFFER (b) |
ce5b453a | 1404 | if (!PER_BUFFER_VALUE_P (b, idx)) |
4ce60d2e | 1405 | set_per_buffer_value (b, offset, value); |
ce5b453a SM |
1406 | } |
1407 | return value; | |
1408 | } | |
1409 | else | |
1410 | return Fset (symbol, value); | |
1411 | } | |
1088b922 | 1412 | default: emacs_abort (); |
ce5b453a | 1413 | } |
7921925c JB |
1414 | } |
1415 | ||
7a7df7ac | 1416 | DEFUN ("setq-default", Fsetq_default, Ssetq_default, 0, UNEVALLED, 0, |
8c1a1077 PJ |
1417 | doc: /* Set the default value of variable VAR to VALUE. |
1418 | VAR, the variable name, is literal (not evaluated); | |
bfb96cb7 | 1419 | VALUE is an expression: it is evaluated and its value returned. |
8c1a1077 PJ |
1420 | The default value of a variable is seen in buffers |
1421 | that do not have their own values for the variable. | |
1422 | ||
1423 | More generally, you can use multiple variables and values, as in | |
948d2995 JB |
1424 | (setq-default VAR VALUE VAR VALUE...) |
1425 | This sets each VAR's default value to the corresponding VALUE. | |
1426 | The VALUE for the Nth VAR can refer to the new default values | |
1427 | of previous VARs. | |
70e9f399 | 1428 | usage: (setq-default [VAR VALUE]...) */) |
5842a27b | 1429 | (Lisp_Object args) |
7921925c JB |
1430 | { |
1431 | register Lisp_Object args_left; | |
d9c2a0f2 | 1432 | register Lisp_Object val, symbol; |
7921925c JB |
1433 | struct gcpro gcpro1; |
1434 | ||
a33ef3ab | 1435 | if (NILP (args)) |
7921925c JB |
1436 | return Qnil; |
1437 | ||
1438 | args_left = args; | |
1439 | GCPRO1 (args); | |
1440 | ||
1441 | do | |
1442 | { | |
defb1411 | 1443 | val = eval_sub (Fcar (Fcdr (args_left))); |
d2fde41d | 1444 | symbol = XCAR (args_left); |
d9c2a0f2 | 1445 | Fset_default (symbol, val); |
d2fde41d | 1446 | args_left = Fcdr (XCDR (args_left)); |
7921925c | 1447 | } |
a33ef3ab | 1448 | while (!NILP (args_left)); |
7921925c JB |
1449 | |
1450 | UNGCPRO; | |
1451 | return val; | |
1452 | } | |
1453 | \f | |
a5ca2b75 JB |
1454 | /* Lisp functions for creating and removing buffer-local variables. */ |
1455 | ||
ce5b453a SM |
1456 | union Lisp_Val_Fwd |
1457 | { | |
1458 | Lisp_Object value; | |
1459 | union Lisp_Fwd *fwd; | |
1460 | }; | |
1461 | ||
1462 | static struct Lisp_Buffer_Local_Value * | |
de1339b0 PE |
1463 | make_blv (struct Lisp_Symbol *sym, bool forwarded, |
1464 | union Lisp_Val_Fwd valcontents) | |
ce5b453a | 1465 | { |
38182d90 | 1466 | struct Lisp_Buffer_Local_Value *blv = xmalloc (sizeof *blv); |
c632dfda JD |
1467 | Lisp_Object symbol; |
1468 | Lisp_Object tem; | |
1469 | ||
1470 | XSETSYMBOL (symbol, sym); | |
1471 | tem = Fcons (symbol, (forwarded | |
1472 | ? do_symval_forwarding (valcontents.fwd) | |
1473 | : valcontents.value)); | |
1474 | ||
ce5b453a SM |
1475 | /* Buffer_Local_Values cannot have as realval a buffer-local |
1476 | or keyboard-local forwarding. */ | |
1477 | eassert (!(forwarded && BUFFER_OBJFWDP (valcontents.fwd))); | |
1478 | eassert (!(forwarded && KBOARD_OBJFWDP (valcontents.fwd))); | |
1479 | blv->fwd = forwarded ? valcontents.fwd : NULL; | |
a04e2c62 | 1480 | set_blv_where (blv, Qnil); |
ce5b453a SM |
1481 | blv->frame_local = 0; |
1482 | blv->local_if_set = 0; | |
a04e2c62 DA |
1483 | set_blv_defcell (blv, tem); |
1484 | set_blv_valcell (blv, tem); | |
1485 | set_blv_found (blv, 0); | |
ce5b453a SM |
1486 | return blv; |
1487 | } | |
1488 | ||
a7ca3326 | 1489 | DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local, |
16a97296 | 1490 | Smake_variable_buffer_local, 1, 1, "vMake Variable Buffer Local: ", |
8c1a1077 PJ |
1491 | doc: /* Make VARIABLE become buffer-local whenever it is set. |
1492 | At any time, the value for the current buffer is in effect, | |
1493 | unless the variable has never been set in this buffer, | |
1494 | in which case the default value is in effect. | |
1495 | Note that binding the variable with `let', or setting it while | |
1496 | a `let'-style binding made in this buffer is in effect, | |
bfb96cb7 | 1497 | does not make the variable buffer-local. Return VARIABLE. |
8c1a1077 | 1498 | |
a9908653 RS |
1499 | In most cases it is better to use `make-local-variable', |
1500 | which makes a variable local in just one buffer. | |
1501 | ||
8c1a1077 | 1502 | The function `default-value' gets the default value and `set-default' sets it. */) |
5842a27b | 1503 | (register Lisp_Object variable) |
7921925c | 1504 | { |
ad97b375 | 1505 | struct Lisp_Symbol *sym; |
ce5b453a | 1506 | struct Lisp_Buffer_Local_Value *blv = NULL; |
bfe3e0a2 | 1507 | union Lisp_Val_Fwd valcontents IF_LINT (= {LISP_INITIALLY_ZERO}); |
de1339b0 | 1508 | bool forwarded IF_LINT (= 0); |
7921925c | 1509 | |
b7826503 | 1510 | CHECK_SYMBOL (variable); |
ce5b453a | 1511 | sym = XSYMBOL (variable); |
7921925c | 1512 | |
ce5b453a SM |
1513 | start: |
1514 | switch (sym->redirect) | |
fd9440c5 | 1515 | { |
ce5b453a SM |
1516 | case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; |
1517 | case SYMBOL_PLAINVAL: | |
1518 | forwarded = 0; valcontents.value = SYMBOL_VAL (sym); | |
1519 | if (EQ (valcontents.value, Qunbound)) | |
1520 | valcontents.value = Qnil; | |
1521 | break; | |
1522 | case SYMBOL_LOCALIZED: | |
1523 | blv = SYMBOL_BLV (sym); | |
1524 | if (blv->frame_local) | |
1525 | error ("Symbol %s may not be buffer-local", | |
1526 | SDATA (SYMBOL_NAME (variable))); | |
1527 | break; | |
1528 | case SYMBOL_FORWARDED: | |
1529 | forwarded = 1; valcontents.fwd = SYMBOL_FWD (sym); | |
1530 | if (KBOARD_OBJFWDP (valcontents.fwd)) | |
1531 | error ("Symbol %s may not be buffer-local", | |
1532 | SDATA (SYMBOL_NAME (variable))); | |
1533 | else if (BUFFER_OBJFWDP (valcontents.fwd)) | |
1534 | return variable; | |
1535 | break; | |
1088b922 | 1536 | default: emacs_abort (); |
fd9440c5 | 1537 | } |
ce5b453a SM |
1538 | |
1539 | if (sym->constant) | |
1540 | error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable))); | |
1541 | ||
1542 | if (!blv) | |
7921925c | 1543 | { |
ce5b453a SM |
1544 | blv = make_blv (sym, forwarded, valcontents); |
1545 | sym->redirect = SYMBOL_LOCALIZED; | |
1546 | SET_SYMBOL_BLV (sym, blv); | |
1547 | { | |
1548 | Lisp_Object symbol; | |
1549 | XSETSYMBOL (symbol, sym); /* In case `variable' is aliased. */ | |
1550 | if (let_shadows_global_binding_p (symbol)) | |
8b1e1112 SM |
1551 | message ("Making %s buffer-local while let-bound!", |
1552 | SDATA (SYMBOL_NAME (variable))); | |
ce5b453a | 1553 | } |
7921925c | 1554 | } |
ce5b453a SM |
1555 | |
1556 | blv->local_if_set = 1; | |
d9c2a0f2 | 1557 | return variable; |
7921925c JB |
1558 | } |
1559 | ||
a7ca3326 | 1560 | DEFUN ("make-local-variable", Fmake_local_variable, Smake_local_variable, |
8c1a1077 PJ |
1561 | 1, 1, "vMake Local Variable: ", |
1562 | doc: /* Make VARIABLE have a separate value in the current buffer. | |
1563 | Other buffers will continue to share a common default value. | |
1564 | \(The buffer-local value of VARIABLE starts out as the same value | |
1565 | VARIABLE previously had. If VARIABLE was void, it remains void.\) | |
a9908653 | 1566 | Return VARIABLE. |
8c1a1077 PJ |
1567 | |
1568 | If the variable is already arranged to become local when set, | |
1569 | this function causes a local value to exist for this buffer, | |
1570 | just as setting the variable would do. | |
1571 | ||
1572 | This function returns VARIABLE, and therefore | |
1573 | (set (make-local-variable 'VARIABLE) VALUE-EXP) | |
1574 | works. | |
1575 | ||
a9908653 RS |
1576 | See also `make-variable-buffer-local'. |
1577 | ||
8c1a1077 | 1578 | Do not use `make-local-variable' to make a hook variable buffer-local. |
515f3f25 | 1579 | Instead, use `add-hook' and specify t for the LOCAL argument. */) |
de1339b0 | 1580 | (Lisp_Object variable) |
7921925c | 1581 | { |
de1339b0 PE |
1582 | Lisp_Object tem; |
1583 | bool forwarded IF_LINT (= 0); | |
bfe3e0a2 | 1584 | union Lisp_Val_Fwd valcontents IF_LINT (= {LISP_INITIALLY_ZERO}); |
ad97b375 | 1585 | struct Lisp_Symbol *sym; |
ce5b453a | 1586 | struct Lisp_Buffer_Local_Value *blv = NULL; |
7921925c | 1587 | |
b7826503 | 1588 | CHECK_SYMBOL (variable); |
ce5b453a | 1589 | sym = XSYMBOL (variable); |
7921925c | 1590 | |
ce5b453a SM |
1591 | start: |
1592 | switch (sym->redirect) | |
1593 | { | |
1594 | case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; | |
1595 | case SYMBOL_PLAINVAL: | |
1596 | forwarded = 0; valcontents.value = SYMBOL_VAL (sym); break; | |
1597 | case SYMBOL_LOCALIZED: | |
1598 | blv = SYMBOL_BLV (sym); | |
1599 | if (blv->frame_local) | |
1600 | error ("Symbol %s may not be buffer-local", | |
1601 | SDATA (SYMBOL_NAME (variable))); | |
1602 | break; | |
1603 | case SYMBOL_FORWARDED: | |
1604 | forwarded = 1; valcontents.fwd = SYMBOL_FWD (sym); | |
1605 | if (KBOARD_OBJFWDP (valcontents.fwd)) | |
1606 | error ("Symbol %s may not be buffer-local", | |
1607 | SDATA (SYMBOL_NAME (variable))); | |
1608 | break; | |
1088b922 | 1609 | default: emacs_abort (); |
ce5b453a SM |
1610 | } |
1611 | ||
1612 | if (sym->constant) | |
8b1e1112 SM |
1613 | error ("Symbol %s may not be buffer-local", |
1614 | SDATA (SYMBOL_NAME (variable))); | |
7921925c | 1615 | |
ce5b453a SM |
1616 | if (blv ? blv->local_if_set |
1617 | : (forwarded && BUFFER_OBJFWDP (valcontents.fwd))) | |
7921925c | 1618 | { |
d9c2a0f2 | 1619 | tem = Fboundp (variable); |
7921925c JB |
1620 | /* Make sure the symbol has a local value in this particular buffer, |
1621 | by setting it to the same value it already has. */ | |
d9c2a0f2 EN |
1622 | Fset (variable, (EQ (tem, Qt) ? Fsymbol_value (variable) : Qunbound)); |
1623 | return variable; | |
7921925c | 1624 | } |
ce5b453a | 1625 | if (!blv) |
7921925c | 1626 | { |
ce5b453a SM |
1627 | blv = make_blv (sym, forwarded, valcontents); |
1628 | sym->redirect = SYMBOL_LOCALIZED; | |
1629 | SET_SYMBOL_BLV (sym, blv); | |
1630 | { | |
1631 | Lisp_Object symbol; | |
1632 | XSETSYMBOL (symbol, sym); /* In case `variable' is aliased. */ | |
1633 | if (let_shadows_global_binding_p (symbol)) | |
8b1e1112 SM |
1634 | message ("Making %s local to %s while let-bound!", |
1635 | SDATA (SYMBOL_NAME (variable)), | |
4b4deea2 | 1636 | SDATA (BVAR (current_buffer, name))); |
ce5b453a | 1637 | } |
7921925c | 1638 | } |
ce5b453a | 1639 | |
42e975f0 | 1640 | /* Make sure this buffer has its own value of symbol. */ |
ce5b453a | 1641 | XSETSYMBOL (variable, sym); /* Update in case of aliasing. */ |
4b4deea2 | 1642 | tem = Fassq (variable, BVAR (current_buffer, local_var_alist)); |
a33ef3ab | 1643 | if (NILP (tem)) |
7921925c | 1644 | { |
ce5b453a SM |
1645 | if (let_shadows_buffer_binding_p (sym)) |
1646 | message ("Making %s buffer-local while locally let-bound!", | |
1647 | SDATA (SYMBOL_NAME (variable))); | |
1648 | ||
a5d004a1 RS |
1649 | /* Swap out any local binding for some other buffer, and make |
1650 | sure the current value is permanently recorded, if it's the | |
1651 | default value. */ | |
d9c2a0f2 | 1652 | find_symbol_value (variable); |
a5d004a1 | 1653 | |
39eb03f1 PE |
1654 | bset_local_var_alist |
1655 | (current_buffer, | |
1656 | Fcons (Fcons (variable, XCDR (blv->defcell)), | |
1657 | BVAR (current_buffer, local_var_alist))); | |
7921925c JB |
1658 | |
1659 | /* Make sure symbol does not think it is set up for this buffer; | |
42e975f0 | 1660 | force it to look once again for this buffer's value. */ |
ce5b453a | 1661 | if (current_buffer == XBUFFER (blv->where)) |
a04e2c62 DA |
1662 | set_blv_where (blv, Qnil); |
1663 | set_blv_found (blv, 0); | |
7921925c | 1664 | } |
a5ca2b75 | 1665 | |
42e975f0 RS |
1666 | /* If the symbol forwards into a C variable, then load the binding |
1667 | for this buffer now. If C code modifies the variable before we | |
1668 | load the binding in, then that new value will clobber the default | |
1669 | binding the next time we unload it. */ | |
ce5b453a SM |
1670 | if (blv->fwd) |
1671 | swap_in_symval_forwarding (sym, blv); | |
a5ca2b75 | 1672 | |
d9c2a0f2 | 1673 | return variable; |
7921925c JB |
1674 | } |
1675 | ||
1676 | DEFUN ("kill-local-variable", Fkill_local_variable, Skill_local_variable, | |
8c1a1077 PJ |
1677 | 1, 1, "vKill Local Variable: ", |
1678 | doc: /* Make VARIABLE no longer have a separate value in the current buffer. | |
bfb96cb7 | 1679 | From now on the default value will apply in this buffer. Return VARIABLE. */) |
5842a27b | 1680 | (register Lisp_Object variable) |
7921925c | 1681 | { |
ce5b453a SM |
1682 | register Lisp_Object tem; |
1683 | struct Lisp_Buffer_Local_Value *blv; | |
ad97b375 | 1684 | struct Lisp_Symbol *sym; |
7921925c | 1685 | |
b7826503 | 1686 | CHECK_SYMBOL (variable); |
ce5b453a | 1687 | sym = XSYMBOL (variable); |
7921925c | 1688 | |
ce5b453a SM |
1689 | start: |
1690 | switch (sym->redirect) | |
7921925c | 1691 | { |
ce5b453a SM |
1692 | case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; |
1693 | case SYMBOL_PLAINVAL: return variable; | |
1694 | case SYMBOL_FORWARDED: | |
1695 | { | |
1696 | union Lisp_Fwd *valcontents = SYMBOL_FWD (sym); | |
1697 | if (BUFFER_OBJFWDP (valcontents)) | |
1698 | { | |
1699 | int offset = XBUFFER_OBJFWD (valcontents)->offset; | |
1700 | int idx = PER_BUFFER_IDX (offset); | |
1701 | ||
1702 | if (idx > 0) | |
1703 | { | |
1704 | SET_PER_BUFFER_VALUE_P (current_buffer, idx, 0); | |
4ce60d2e DA |
1705 | set_per_buffer_value (current_buffer, offset, |
1706 | per_buffer_default (offset)); | |
ce5b453a SM |
1707 | } |
1708 | } | |
1709 | return variable; | |
1710 | } | |
1711 | case SYMBOL_LOCALIZED: | |
1712 | blv = SYMBOL_BLV (sym); | |
1713 | if (blv->frame_local) | |
1714 | return variable; | |
1715 | break; | |
1088b922 | 1716 | default: emacs_abort (); |
7921925c JB |
1717 | } |
1718 | ||
42e975f0 | 1719 | /* Get rid of this buffer's alist element, if any. */ |
ad97b375 | 1720 | XSETSYMBOL (variable, sym); /* Propagate variable indirection. */ |
4b4deea2 | 1721 | tem = Fassq (variable, BVAR (current_buffer, local_var_alist)); |
a33ef3ab | 1722 | if (!NILP (tem)) |
39eb03f1 PE |
1723 | bset_local_var_alist |
1724 | (current_buffer, | |
1725 | Fdelq (tem, BVAR (current_buffer, local_var_alist))); | |
7921925c | 1726 | |
42e975f0 RS |
1727 | /* If the symbol is set up with the current buffer's binding |
1728 | loaded, recompute its value. We have to do it now, or else | |
1729 | forwarded objects won't work right. */ | |
7921925c | 1730 | { |
ce5b453a SM |
1731 | Lisp_Object buf; XSETBUFFER (buf, current_buffer); |
1732 | if (EQ (buf, blv->where)) | |
79c83e03 | 1733 | { |
a04e2c62 | 1734 | set_blv_where (blv, Qnil); |
9e677988 | 1735 | blv->found = 0; |
978dd578 | 1736 | find_symbol_value (variable); |
79c83e03 | 1737 | } |
7921925c JB |
1738 | } |
1739 | ||
d9c2a0f2 | 1740 | return variable; |
7921925c | 1741 | } |
62476adc | 1742 | |
b0c2d1c6 RS |
1743 | /* Lisp functions for creating and removing buffer-local variables. */ |
1744 | ||
ab795c65 GM |
1745 | /* Obsolete since 22.2. NB adjust doc of modify-frame-parameters |
1746 | when/if this is removed. */ | |
1747 | ||
b0c2d1c6 | 1748 | DEFUN ("make-variable-frame-local", Fmake_variable_frame_local, Smake_variable_frame_local, |
8c1a1077 PJ |
1749 | 1, 1, "vMake Variable Frame Local: ", |
1750 | doc: /* Enable VARIABLE to have frame-local bindings. | |
4d4d36b1 RS |
1751 | This does not create any frame-local bindings for VARIABLE, |
1752 | it just makes them possible. | |
1753 | ||
1754 | A frame-local binding is actually a frame parameter value. | |
1755 | If a frame F has a value for the frame parameter named VARIABLE, | |
1756 | that also acts as a frame-local binding for VARIABLE in F-- | |
1757 | provided this function has been called to enable VARIABLE | |
1758 | to have frame-local bindings at all. | |
1759 | ||
1760 | The only way to create a frame-local binding for VARIABLE in a frame | |
1761 | is to set the VARIABLE frame parameter of that frame. See | |
1762 | `modify-frame-parameters' for how to set frame parameters. | |
1763 | ||
a02a1384 GM |
1764 | Note that since Emacs 23.1, variables cannot be both buffer-local and |
1765 | frame-local any more (buffer-local bindings used to take precedence over | |
1766 | frame-local bindings). */) | |
de1339b0 | 1767 | (Lisp_Object variable) |
b0c2d1c6 | 1768 | { |
de1339b0 | 1769 | bool forwarded; |
ce5b453a | 1770 | union Lisp_Val_Fwd valcontents; |
ad97b375 | 1771 | struct Lisp_Symbol *sym; |
ce5b453a | 1772 | struct Lisp_Buffer_Local_Value *blv = NULL; |
b0c2d1c6 | 1773 | |
b7826503 | 1774 | CHECK_SYMBOL (variable); |
ce5b453a | 1775 | sym = XSYMBOL (variable); |
b0c2d1c6 | 1776 | |
ce5b453a SM |
1777 | start: |
1778 | switch (sym->redirect) | |
42e975f0 | 1779 | { |
ce5b453a SM |
1780 | case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; |
1781 | case SYMBOL_PLAINVAL: | |
1782 | forwarded = 0; valcontents.value = SYMBOL_VAL (sym); | |
1783 | if (EQ (valcontents.value, Qunbound)) | |
1784 | valcontents.value = Qnil; | |
1785 | break; | |
1786 | case SYMBOL_LOCALIZED: | |
1787 | if (SYMBOL_BLV (sym)->frame_local) | |
1788 | return variable; | |
1789 | else | |
1790 | error ("Symbol %s may not be frame-local", | |
1791 | SDATA (SYMBOL_NAME (variable))); | |
1792 | case SYMBOL_FORWARDED: | |
1793 | forwarded = 1; valcontents.fwd = SYMBOL_FWD (sym); | |
1794 | if (KBOARD_OBJFWDP (valcontents.fwd) || BUFFER_OBJFWDP (valcontents.fwd)) | |
1795 | error ("Symbol %s may not be frame-local", | |
1796 | SDATA (SYMBOL_NAME (variable))); | |
1797 | break; | |
1088b922 | 1798 | default: emacs_abort (); |
42e975f0 | 1799 | } |
b0c2d1c6 | 1800 | |
ce5b453a SM |
1801 | if (sym->constant) |
1802 | error ("Symbol %s may not be frame-local", SDATA (SYMBOL_NAME (variable))); | |
1803 | ||
1804 | blv = make_blv (sym, forwarded, valcontents); | |
1805 | blv->frame_local = 1; | |
1806 | sym->redirect = SYMBOL_LOCALIZED; | |
1807 | SET_SYMBOL_BLV (sym, blv); | |
8b1e1112 SM |
1808 | { |
1809 | Lisp_Object symbol; | |
1810 | XSETSYMBOL (symbol, sym); /* In case `variable' is aliased. */ | |
1811 | if (let_shadows_global_binding_p (symbol)) | |
1812 | message ("Making %s frame-local while let-bound!", | |
1813 | SDATA (SYMBOL_NAME (variable))); | |
1814 | } | |
b0c2d1c6 RS |
1815 | return variable; |
1816 | } | |
1817 | ||
a7ca3326 | 1818 | DEFUN ("local-variable-p", Flocal_variable_p, Slocal_variable_p, |
8c1a1077 PJ |
1819 | 1, 2, 0, |
1820 | doc: /* Non-nil if VARIABLE has a local binding in buffer BUFFER. | |
1821 | BUFFER defaults to the current buffer. */) | |
5842a27b | 1822 | (register Lisp_Object variable, Lisp_Object buffer) |
62476adc | 1823 | { |
c48ead86 | 1824 | register struct buffer *buf; |
ad97b375 | 1825 | struct Lisp_Symbol *sym; |
c48ead86 KH |
1826 | |
1827 | if (NILP (buffer)) | |
1828 | buf = current_buffer; | |
1829 | else | |
1830 | { | |
b7826503 | 1831 | CHECK_BUFFER (buffer); |
c48ead86 KH |
1832 | buf = XBUFFER (buffer); |
1833 | } | |
62476adc | 1834 | |
b7826503 | 1835 | CHECK_SYMBOL (variable); |
ce5b453a | 1836 | sym = XSYMBOL (variable); |
be95bee9 | 1837 | |
ce5b453a SM |
1838 | start: |
1839 | switch (sym->redirect) | |
c48ead86 | 1840 | { |
ce5b453a SM |
1841 | case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; |
1842 | case SYMBOL_PLAINVAL: return Qnil; | |
1843 | case SYMBOL_LOCALIZED: | |
1844 | { | |
1845 | Lisp_Object tail, elt, tmp; | |
1846 | struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym); | |
1847 | XSETBUFFER (tmp, buf); | |
8d1d9587 | 1848 | XSETSYMBOL (variable, sym); /* Update in case of aliasing. */ |
aa3830c4 | 1849 | |
4b4deea2 | 1850 | for (tail = BVAR (buf, local_var_alist); CONSP (tail); tail = XCDR (tail)) |
ce5b453a SM |
1851 | { |
1852 | elt = XCAR (tail); | |
1853 | if (EQ (variable, XCAR (elt))) | |
1854 | { | |
1855 | eassert (!blv->frame_local); | |
a04e2c62 | 1856 | eassert (blv_found (blv) || !EQ (blv->where, tmp)); |
ce5b453a SM |
1857 | return Qt; |
1858 | } | |
1859 | } | |
a04e2c62 | 1860 | eassert (!blv_found (blv) || !EQ (blv->where, tmp)); |
ce5b453a SM |
1861 | return Qnil; |
1862 | } | |
1863 | case SYMBOL_FORWARDED: | |
1864 | { | |
1865 | union Lisp_Fwd *valcontents = SYMBOL_FWD (sym); | |
1866 | if (BUFFER_OBJFWDP (valcontents)) | |
1867 | { | |
1868 | int offset = XBUFFER_OBJFWD (valcontents)->offset; | |
1869 | int idx = PER_BUFFER_IDX (offset); | |
1870 | if (idx == -1 || PER_BUFFER_VALUE_P (buf, idx)) | |
1871 | return Qt; | |
1872 | } | |
1873 | return Qnil; | |
1874 | } | |
1088b922 | 1875 | default: emacs_abort (); |
c48ead86 | 1876 | } |
62476adc | 1877 | } |
f4f04cee RS |
1878 | |
1879 | DEFUN ("local-variable-if-set-p", Flocal_variable_if_set_p, Slocal_variable_if_set_p, | |
8c1a1077 | 1880 | 1, 2, 0, |
1a5432bc CY |
1881 | doc: /* Non-nil if VARIABLE is local in buffer BUFFER when set there. |
1882 | BUFFER defaults to the current buffer. | |
1883 | ||
1884 | More precisely, return non-nil if either VARIABLE already has a local | |
1885 | value in BUFFER, or if VARIABLE is automatically buffer-local (see | |
1886 | `make-variable-buffer-local'). */) | |
5842a27b | 1887 | (register Lisp_Object variable, Lisp_Object buffer) |
f4f04cee | 1888 | { |
ad97b375 | 1889 | struct Lisp_Symbol *sym; |
f4f04cee | 1890 | |
b7826503 | 1891 | CHECK_SYMBOL (variable); |
ce5b453a | 1892 | sym = XSYMBOL (variable); |
f4f04cee | 1893 | |
ce5b453a SM |
1894 | start: |
1895 | switch (sym->redirect) | |
f4f04cee | 1896 | { |
ce5b453a SM |
1897 | case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; |
1898 | case SYMBOL_PLAINVAL: return Qnil; | |
1899 | case SYMBOL_LOCALIZED: | |
1900 | { | |
1901 | struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym); | |
1902 | if (blv->local_if_set) | |
1903 | return Qt; | |
1904 | XSETSYMBOL (variable, sym); /* Update in case of aliasing. */ | |
1905 | return Flocal_variable_p (variable, buffer); | |
1906 | } | |
1907 | case SYMBOL_FORWARDED: | |
1908 | /* All BUFFER_OBJFWD slots become local if they are set. */ | |
1909 | return (BUFFER_OBJFWDP (SYMBOL_FWD (sym)) ? Qt : Qnil); | |
1088b922 | 1910 | default: emacs_abort (); |
f4f04cee | 1911 | } |
f4f04cee | 1912 | } |
6b61353c KH |
1913 | |
1914 | DEFUN ("variable-binding-locus", Fvariable_binding_locus, Svariable_binding_locus, | |
1915 | 1, 1, 0, | |
1916 | doc: /* Return a value indicating where VARIABLE's current binding comes from. | |
1917 | If the current binding is buffer-local, the value is the current buffer. | |
1918 | If the current binding is frame-local, the value is the selected frame. | |
1919 | If the current binding is global (the default), the value is nil. */) | |
5842a27b | 1920 | (register Lisp_Object variable) |
6b61353c | 1921 | { |
ad97b375 | 1922 | struct Lisp_Symbol *sym; |
6b61353c KH |
1923 | |
1924 | CHECK_SYMBOL (variable); | |
ce5b453a | 1925 | sym = XSYMBOL (variable); |
6b61353c KH |
1926 | |
1927 | /* Make sure the current binding is actually swapped in. */ | |
1928 | find_symbol_value (variable); | |
1929 | ||
ce5b453a SM |
1930 | start: |
1931 | switch (sym->redirect) | |
6b61353c | 1932 | { |
ce5b453a SM |
1933 | case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; |
1934 | case SYMBOL_PLAINVAL: return Qnil; | |
1935 | case SYMBOL_FORWARDED: | |
1936 | { | |
1937 | union Lisp_Fwd *valcontents = SYMBOL_FWD (sym); | |
1938 | if (KBOARD_OBJFWDP (valcontents)) | |
1939 | return Fframe_terminal (Fselected_frame ()); | |
1940 | else if (!BUFFER_OBJFWDP (valcontents)) | |
1941 | return Qnil; | |
1942 | } | |
1943 | /* FALLTHROUGH */ | |
1944 | case SYMBOL_LOCALIZED: | |
6b61353c KH |
1945 | /* For a local variable, record both the symbol and which |
1946 | buffer's or frame's value we are saving. */ | |
1947 | if (!NILP (Flocal_variable_p (variable, Qnil))) | |
1948 | return Fcurrent_buffer (); | |
ce5b453a | 1949 | else if (sym->redirect == SYMBOL_LOCALIZED |
a04e2c62 | 1950 | && blv_found (SYMBOL_BLV (sym))) |
ce5b453a SM |
1951 | return SYMBOL_BLV (sym)->where; |
1952 | else | |
1953 | return Qnil; | |
1088b922 | 1954 | default: emacs_abort (); |
6b61353c | 1955 | } |
6b61353c | 1956 | } |
2a42d440 | 1957 | |
c40bb1ba KL |
1958 | /* This code is disabled now that we use the selected frame to return |
1959 | keyboard-local-values. */ | |
1960 | #if 0 | |
f57e2426 | 1961 | extern struct terminal *get_terminal (Lisp_Object display, int); |
2a42d440 | 1962 | |
a7ca3326 | 1963 | DEFUN ("terminal-local-value", Fterminal_local_value, |
16a97296 | 1964 | Sterminal_local_value, 2, 2, 0, |
6ed8eeff | 1965 | doc: /* Return the terminal-local value of SYMBOL on TERMINAL. |
2a42d440 KL |
1966 | If SYMBOL is not a terminal-local variable, then return its normal |
1967 | value, like `symbol-value'. | |
1968 | ||
708e05dc | 1969 | TERMINAL may be a terminal object, a frame, or nil (meaning the |
6ed8eeff | 1970 | selected frame's terminal device). */) |
5842a27b | 1971 | (Lisp_Object symbol, Lisp_Object terminal) |
2a42d440 KL |
1972 | { |
1973 | Lisp_Object result; | |
6ed8eeff KL |
1974 | struct terminal *t = get_terminal (terminal, 1); |
1975 | push_kboard (t->kboard); | |
2a42d440 | 1976 | result = Fsymbol_value (symbol); |
256c9c3a | 1977 | pop_kboard (); |
2a42d440 KL |
1978 | return result; |
1979 | } | |
1980 | ||
a7ca3326 | 1981 | DEFUN ("set-terminal-local-value", Fset_terminal_local_value, |
16a97296 | 1982 | Sset_terminal_local_value, 3, 3, 0, |
6ed8eeff | 1983 | doc: /* Set the terminal-local binding of SYMBOL on TERMINAL to VALUE. |
2a42d440 | 1984 | If VARIABLE is not a terminal-local variable, then set its normal |
7e59217d KL |
1985 | binding, like `set'. |
1986 | ||
708e05dc | 1987 | TERMINAL may be a terminal object, a frame, or nil (meaning the |
6ed8eeff | 1988 | selected frame's terminal device). */) |
5842a27b | 1989 | (Lisp_Object symbol, Lisp_Object terminal, Lisp_Object value) |
2a42d440 KL |
1990 | { |
1991 | Lisp_Object result; | |
6ed8eeff | 1992 | struct terminal *t = get_terminal (terminal, 1); |
256c9c3a | 1993 | push_kboard (d->kboard); |
2a42d440 | 1994 | result = Fset (symbol, value); |
256c9c3a | 1995 | pop_kboard (); |
2a42d440 KL |
1996 | return result; |
1997 | } | |
c40bb1ba | 1998 | #endif |
7921925c | 1999 | \f |
ffd56f97 JB |
2000 | /* Find the function at the end of a chain of symbol function indirections. */ |
2001 | ||
2002 | /* If OBJECT is a symbol, find the end of its function chain and | |
2003 | return the value found there. If OBJECT is not a symbol, just | |
2004 | return it. If there is a cycle in the function chain, signal a | |
2005 | cyclic-function-indirection error. | |
2006 | ||
2007 | This is like Findirect_function, except that it doesn't signal an | |
2008 | error if the chain ends up unbound. */ | |
2009 | Lisp_Object | |
971de7fb | 2010 | indirect_function (register Lisp_Object object) |
ffd56f97 | 2011 | { |
eb8c3be9 | 2012 | Lisp_Object tortoise, hare; |
ffd56f97 | 2013 | |
eb8c3be9 | 2014 | hare = tortoise = object; |
ffd56f97 JB |
2015 | |
2016 | for (;;) | |
2017 | { | |
e9ebc175 | 2018 | if (!SYMBOLP (hare) || EQ (hare, Qunbound)) |
ffd56f97 | 2019 | break; |
c644523b | 2020 | hare = XSYMBOL (hare)->function; |
e9ebc175 | 2021 | if (!SYMBOLP (hare) || EQ (hare, Qunbound)) |
ffd56f97 | 2022 | break; |
c644523b | 2023 | hare = XSYMBOL (hare)->function; |
ffd56f97 | 2024 | |
c644523b | 2025 | tortoise = XSYMBOL (tortoise)->function; |
ffd56f97 | 2026 | |
eb8c3be9 | 2027 | if (EQ (hare, tortoise)) |
740ef0b5 | 2028 | xsignal1 (Qcyclic_function_indirection, object); |
ffd56f97 JB |
2029 | } |
2030 | ||
2031 | return hare; | |
2032 | } | |
2033 | ||
a7ca3326 | 2034 | DEFUN ("indirect-function", Findirect_function, Sindirect_function, 1, 2, 0, |
8c1a1077 | 2035 | doc: /* Return the function at the end of OBJECT's function chain. |
0ddb0ae8 TTN |
2036 | If OBJECT is not a symbol, just return it. Otherwise, follow all |
2037 | function indirections to find the final function binding and return it. | |
2038 | If the final symbol in the chain is unbound, signal a void-function error. | |
8350f087 | 2039 | Optional arg NOERROR non-nil means to return nil instead of signaling. |
8c1a1077 PJ |
2040 | Signal a cyclic-function-indirection error if there is a loop in the |
2041 | function chain of symbols. */) | |
5842a27b | 2042 | (register Lisp_Object object, Lisp_Object noerror) |
ffd56f97 JB |
2043 | { |
2044 | Lisp_Object result; | |
2045 | ||
64de53d8 KS |
2046 | /* Optimize for no indirection. */ |
2047 | result = object; | |
2048 | if (SYMBOLP (result) && !EQ (result, Qunbound) | |
c644523b | 2049 | && (result = XSYMBOL (result)->function, SYMBOLP (result))) |
64de53d8 KS |
2050 | result = indirect_function (result); |
2051 | if (!EQ (result, Qunbound)) | |
2052 | return result; | |
ffd56f97 | 2053 | |
64de53d8 | 2054 | if (NILP (noerror)) |
740ef0b5 | 2055 | xsignal1 (Qvoid_function, object); |
ffd56f97 | 2056 | |
64de53d8 | 2057 | return Qnil; |
ffd56f97 JB |
2058 | } |
2059 | \f | |
7abaf5cc | 2060 | /* Extract and set vector and string elements. */ |
7921925c | 2061 | |
a7ca3326 | 2062 | DEFUN ("aref", Faref, Saref, 2, 2, 0, |
8c1a1077 PJ |
2063 | doc: /* Return the element of ARRAY at index IDX. |
2064 | ARRAY may be a vector, a string, a char-table, a bool-vector, | |
2065 | or a byte-code object. IDX starts at 0. */) | |
5842a27b | 2066 | (register Lisp_Object array, Lisp_Object idx) |
7921925c | 2067 | { |
ace1712c | 2068 | register EMACS_INT idxval; |
7921925c | 2069 | |
b7826503 | 2070 | CHECK_NUMBER (idx); |
7921925c | 2071 | idxval = XINT (idx); |
e9ebc175 | 2072 | if (STRINGP (array)) |
7921925c | 2073 | { |
ace1712c | 2074 | int c; |
d311d28c | 2075 | ptrdiff_t idxval_byte; |
25638b07 | 2076 | |
d5db4077 | 2077 | if (idxval < 0 || idxval >= SCHARS (array)) |
c24e4efe | 2078 | args_out_of_range (array, idx); |
25638b07 | 2079 | if (! STRING_MULTIBYTE (array)) |
d5db4077 | 2080 | return make_number ((unsigned char) SREF (array, idxval)); |
25638b07 RS |
2081 | idxval_byte = string_char_to_byte (array, idxval); |
2082 | ||
62a6e103 | 2083 | c = STRING_CHAR (SDATA (array) + idxval_byte); |
25638b07 | 2084 | return make_number (c); |
7921925c | 2085 | } |
4d276982 RS |
2086 | else if (BOOL_VECTOR_P (array)) |
2087 | { | |
2088 | int val; | |
4d276982 RS |
2089 | |
2090 | if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size) | |
2091 | args_out_of_range (array, idx); | |
2092 | ||
b9ed2177 AS |
2093 | val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR]; |
2094 | return (val & (1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR)) ? Qt : Qnil); | |
4d276982 RS |
2095 | } |
2096 | else if (CHAR_TABLE_P (array)) | |
2097 | { | |
e6e1f521 KH |
2098 | CHECK_CHARACTER (idx); |
2099 | return CHAR_TABLE_REF (array, idxval); | |
4d276982 | 2100 | } |
7921925c | 2101 | else |
c24e4efe | 2102 | { |
90d8445b | 2103 | ptrdiff_t size = 0; |
7f358972 | 2104 | if (VECTORP (array)) |
77b37c05 | 2105 | size = ASIZE (array); |
876c194c | 2106 | else if (COMPILEDP (array)) |
77b37c05 | 2107 | size = ASIZE (array) & PSEUDOVECTOR_SIZE_MASK; |
7f358972 RS |
2108 | else |
2109 | wrong_type_argument (Qarrayp, array); | |
2110 | ||
2111 | if (idxval < 0 || idxval >= size) | |
c24e4efe | 2112 | args_out_of_range (array, idx); |
b9598260 | 2113 | return AREF (array, idxval); |
c24e4efe | 2114 | } |
7921925c JB |
2115 | } |
2116 | ||
a7ca3326 | 2117 | DEFUN ("aset", Faset, Saset, 3, 3, 0, |
8c1a1077 | 2118 | doc: /* Store into the element of ARRAY at index IDX the value NEWELT. |
bfb96cb7 FP |
2119 | Return NEWELT. ARRAY may be a vector, a string, a char-table or a |
2120 | bool-vector. IDX starts at 0. */) | |
5842a27b | 2121 | (register Lisp_Object array, Lisp_Object idx, Lisp_Object newelt) |
7921925c | 2122 | { |
ace1712c | 2123 | register EMACS_INT idxval; |
7921925c | 2124 | |
b7826503 | 2125 | CHECK_NUMBER (idx); |
7921925c | 2126 | idxval = XINT (idx); |
0c64a8cd | 2127 | CHECK_ARRAY (array, Qarrayp); |
7921925c JB |
2128 | CHECK_IMPURE (array); |
2129 | ||
e9ebc175 | 2130 | if (VECTORP (array)) |
c24e4efe | 2131 | { |
77b37c05 | 2132 | if (idxval < 0 || idxval >= ASIZE (array)) |
c24e4efe | 2133 | args_out_of_range (array, idx); |
28be1ada | 2134 | ASET (array, idxval, newelt); |
c24e4efe | 2135 | } |
4d276982 RS |
2136 | else if (BOOL_VECTOR_P (array)) |
2137 | { | |
2138 | int val; | |
4d276982 RS |
2139 | |
2140 | if (idxval < 0 || idxval >= XBOOL_VECTOR (array)->size) | |
2141 | args_out_of_range (array, idx); | |
2142 | ||
b9ed2177 | 2143 | val = (unsigned char) XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR]; |
4d276982 RS |
2144 | |
2145 | if (! NILP (newelt)) | |
b9ed2177 | 2146 | val |= 1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR); |
4d276982 | 2147 | else |
b9ed2177 AS |
2148 | val &= ~(1 << (idxval % BOOL_VECTOR_BITS_PER_CHAR)); |
2149 | XBOOL_VECTOR (array)->data[idxval / BOOL_VECTOR_BITS_PER_CHAR] = val; | |
4d276982 RS |
2150 | } |
2151 | else if (CHAR_TABLE_P (array)) | |
2152 | { | |
e6e1f521 KH |
2153 | CHECK_CHARACTER (idx); |
2154 | CHAR_TABLE_SET (array, idxval, newelt); | |
4d276982 | 2155 | } |
0fed43f3 | 2156 | else |
25638b07 | 2157 | { |
13bdea59 | 2158 | int c; |
25638b07 | 2159 | |
d5db4077 | 2160 | if (idxval < 0 || idxval >= SCHARS (array)) |
25638b07 | 2161 | args_out_of_range (array, idx); |
d9130605 | 2162 | CHECK_CHARACTER (newelt); |
13bdea59 | 2163 | c = XFASTINT (newelt); |
25638b07 | 2164 | |
0fed43f3 | 2165 | if (STRING_MULTIBYTE (array)) |
3c9de1af | 2166 | { |
d311d28c PE |
2167 | ptrdiff_t idxval_byte, nbytes; |
2168 | int prev_bytes, new_bytes; | |
0fed43f3 PE |
2169 | unsigned char workbuf[MAX_MULTIBYTE_LENGTH], *p0 = workbuf, *p1; |
2170 | ||
2171 | nbytes = SBYTES (array); | |
2172 | idxval_byte = string_char_to_byte (array, idxval); | |
d5db4077 | 2173 | p1 = SDATA (array) + idxval_byte; |
0fed43f3 PE |
2174 | prev_bytes = BYTES_BY_CHAR_HEAD (*p1); |
2175 | new_bytes = CHAR_STRING (c, p0); | |
2176 | if (prev_bytes != new_bytes) | |
2177 | { | |
2178 | /* We must relocate the string data. */ | |
d311d28c | 2179 | ptrdiff_t nchars = SCHARS (array); |
0fed43f3 | 2180 | USE_SAFE_ALLOCA; |
98c6f1e3 | 2181 | unsigned char *str = SAFE_ALLOCA (nbytes); |
0fed43f3 | 2182 | |
0fed43f3 PE |
2183 | memcpy (str, SDATA (array), nbytes); |
2184 | allocate_string_data (XSTRING (array), nchars, | |
2185 | nbytes + new_bytes - prev_bytes); | |
2186 | memcpy (SDATA (array), str, idxval_byte); | |
2187 | p1 = SDATA (array) + idxval_byte; | |
2188 | memcpy (p1 + new_bytes, str + idxval_byte + prev_bytes, | |
2189 | nbytes - (idxval_byte + prev_bytes)); | |
2190 | SAFE_FREE (); | |
2191 | clear_string_char_byte_cache (); | |
2192 | } | |
2193 | while (new_bytes--) | |
2194 | *p1++ = *p0++; | |
3c9de1af | 2195 | } |
0fed43f3 | 2196 | else |
5dff5999 | 2197 | { |
0fed43f3 PE |
2198 | if (! SINGLE_BYTE_CHAR_P (c)) |
2199 | { | |
2200 | int i; | |
2201 | ||
2202 | for (i = SBYTES (array) - 1; i >= 0; i--) | |
2203 | if (SREF (array, i) >= 0x80) | |
2204 | args_out_of_range (array, newelt); | |
2205 | /* ARRAY is an ASCII string. Convert it to a multibyte | |
2206 | string, and try `aset' again. */ | |
2207 | STRING_SET_MULTIBYTE (array); | |
2208 | return Faset (array, idx, newelt); | |
2209 | } | |
2210 | SSET (array, idxval, c); | |
5dff5999 | 2211 | } |
7921925c JB |
2212 | } |
2213 | ||
2214 | return newelt; | |
2215 | } | |
7921925c JB |
2216 | \f |
2217 | /* Arithmetic functions */ | |
2218 | ||
2219 | enum comparison { equal, notequal, less, grtr, less_or_equal, grtr_or_equal }; | |
2220 | ||
112396d6 | 2221 | static Lisp_Object |
971de7fb | 2222 | arithcompare (Lisp_Object num1, Lisp_Object num2, enum comparison comparison) |
7921925c | 2223 | { |
6bbd7a29 | 2224 | double f1 = 0, f2 = 0; |
de1339b0 | 2225 | bool floatp = 0; |
7921925c | 2226 | |
b7826503 PJ |
2227 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1); |
2228 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2); | |
7921925c | 2229 | |
e9ebc175 | 2230 | if (FLOATP (num1) || FLOATP (num2)) |
7921925c JB |
2231 | { |
2232 | floatp = 1; | |
7539e11f KR |
2233 | f1 = (FLOATP (num1)) ? XFLOAT_DATA (num1) : XINT (num1); |
2234 | f2 = (FLOATP (num2)) ? XFLOAT_DATA (num2) : XINT (num2); | |
7921925c | 2235 | } |
7921925c JB |
2236 | |
2237 | switch (comparison) | |
2238 | { | |
2239 | case equal: | |
2240 | if (floatp ? f1 == f2 : XINT (num1) == XINT (num2)) | |
2241 | return Qt; | |
2242 | return Qnil; | |
2243 | ||
2244 | case notequal: | |
2245 | if (floatp ? f1 != f2 : XINT (num1) != XINT (num2)) | |
2246 | return Qt; | |
2247 | return Qnil; | |
2248 | ||
2249 | case less: | |
2250 | if (floatp ? f1 < f2 : XINT (num1) < XINT (num2)) | |
2251 | return Qt; | |
2252 | return Qnil; | |
2253 | ||
2254 | case less_or_equal: | |
2255 | if (floatp ? f1 <= f2 : XINT (num1) <= XINT (num2)) | |
2256 | return Qt; | |
2257 | return Qnil; | |
2258 | ||
2259 | case grtr: | |
2260 | if (floatp ? f1 > f2 : XINT (num1) > XINT (num2)) | |
2261 | return Qt; | |
2262 | return Qnil; | |
2263 | ||
2264 | case grtr_or_equal: | |
2265 | if (floatp ? f1 >= f2 : XINT (num1) >= XINT (num2)) | |
2266 | return Qt; | |
2267 | return Qnil; | |
25e40a4b JB |
2268 | |
2269 | default: | |
1088b922 | 2270 | emacs_abort (); |
7921925c JB |
2271 | } |
2272 | } | |
2273 | ||
2274 | DEFUN ("=", Feqlsign, Seqlsign, 2, 2, 0, | |
8c1a1077 | 2275 | doc: /* Return t if two args, both numbers or markers, are equal. */) |
5842a27b | 2276 | (register Lisp_Object num1, Lisp_Object num2) |
7921925c JB |
2277 | { |
2278 | return arithcompare (num1, num2, equal); | |
2279 | } | |
2280 | ||
a7ca3326 | 2281 | DEFUN ("<", Flss, Slss, 2, 2, 0, |
8c1a1077 | 2282 | doc: /* Return t if first arg is less than second arg. Both must be numbers or markers. */) |
5842a27b | 2283 | (register Lisp_Object num1, Lisp_Object num2) |
7921925c JB |
2284 | { |
2285 | return arithcompare (num1, num2, less); | |
2286 | } | |
2287 | ||
a7ca3326 | 2288 | DEFUN (">", Fgtr, Sgtr, 2, 2, 0, |
8c1a1077 | 2289 | doc: /* Return t if first arg is greater than second arg. Both must be numbers or markers. */) |
5842a27b | 2290 | (register Lisp_Object num1, Lisp_Object num2) |
7921925c JB |
2291 | { |
2292 | return arithcompare (num1, num2, grtr); | |
2293 | } | |
2294 | ||
a7ca3326 | 2295 | DEFUN ("<=", Fleq, Sleq, 2, 2, 0, |
8c1a1077 PJ |
2296 | doc: /* Return t if first arg is less than or equal to second arg. |
2297 | Both must be numbers or markers. */) | |
5842a27b | 2298 | (register Lisp_Object num1, Lisp_Object num2) |
7921925c JB |
2299 | { |
2300 | return arithcompare (num1, num2, less_or_equal); | |
2301 | } | |
2302 | ||
a7ca3326 | 2303 | DEFUN (">=", Fgeq, Sgeq, 2, 2, 0, |
8c1a1077 PJ |
2304 | doc: /* Return t if first arg is greater than or equal to second arg. |
2305 | Both must be numbers or markers. */) | |
5842a27b | 2306 | (register Lisp_Object num1, Lisp_Object num2) |
7921925c JB |
2307 | { |
2308 | return arithcompare (num1, num2, grtr_or_equal); | |
2309 | } | |
2310 | ||
2311 | DEFUN ("/=", Fneq, Sneq, 2, 2, 0, | |
8c1a1077 | 2312 | doc: /* Return t if first arg is not equal to second arg. Both must be numbers or markers. */) |
5842a27b | 2313 | (register Lisp_Object num1, Lisp_Object num2) |
7921925c JB |
2314 | { |
2315 | return arithcompare (num1, num2, notequal); | |
2316 | } | |
2317 | ||
a7ca3326 | 2318 | DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0, |
8c1a1077 | 2319 | doc: /* Return t if NUMBER is zero. */) |
5842a27b | 2320 | (register Lisp_Object number) |
7921925c | 2321 | { |
b7826503 | 2322 | CHECK_NUMBER_OR_FLOAT (number); |
7921925c | 2323 | |
d9c2a0f2 | 2324 | if (FLOATP (number)) |
7921925c | 2325 | { |
7539e11f | 2326 | if (XFLOAT_DATA (number) == 0.0) |
7921925c JB |
2327 | return Qt; |
2328 | return Qnil; | |
2329 | } | |
7921925c | 2330 | |
d9c2a0f2 | 2331 | if (!XINT (number)) |
7921925c JB |
2332 | return Qt; |
2333 | return Qnil; | |
2334 | } | |
2335 | \f | |
be44ca6c PE |
2336 | /* Convert the cons-of-integers, integer, or float value C to an |
2337 | unsigned value with maximum value MAX. Signal an error if C does not | |
2338 | have a valid format or is out of range. */ | |
2339 | uintmax_t | |
2340 | cons_to_unsigned (Lisp_Object c, uintmax_t max) | |
2341 | { | |
de1339b0 | 2342 | bool valid = 0; |
be44ca6c PE |
2343 | uintmax_t val IF_LINT (= 0); |
2344 | if (INTEGERP (c)) | |
2345 | { | |
2346 | valid = 0 <= XINT (c); | |
2347 | val = XINT (c); | |
2348 | } | |
2349 | else if (FLOATP (c)) | |
2350 | { | |
2351 | double d = XFLOAT_DATA (c); | |
2352 | if (0 <= d | |
2353 | && d < (max == UINTMAX_MAX ? (double) UINTMAX_MAX + 1 : max + 1)) | |
2354 | { | |
2355 | val = d; | |
2356 | valid = 1; | |
2357 | } | |
2358 | } | |
2359 | else if (CONSP (c) && NATNUMP (XCAR (c))) | |
2360 | { | |
2361 | uintmax_t top = XFASTINT (XCAR (c)); | |
2362 | Lisp_Object rest = XCDR (c); | |
2363 | if (top <= UINTMAX_MAX >> 24 >> 16 | |
2364 | && CONSP (rest) | |
2365 | && NATNUMP (XCAR (rest)) && XFASTINT (XCAR (rest)) < 1 << 24 | |
2366 | && NATNUMP (XCDR (rest)) && XFASTINT (XCDR (rest)) < 1 << 16) | |
2367 | { | |
2368 | uintmax_t mid = XFASTINT (XCAR (rest)); | |
2369 | val = top << 24 << 16 | mid << 16 | XFASTINT (XCDR (rest)); | |
2370 | valid = 1; | |
2371 | } | |
2372 | else if (top <= UINTMAX_MAX >> 16) | |
2373 | { | |
2374 | if (CONSP (rest)) | |
2375 | rest = XCAR (rest); | |
2376 | if (NATNUMP (rest) && XFASTINT (rest) < 1 << 16) | |
2377 | { | |
2378 | val = top << 16 | XFASTINT (rest); | |
2379 | valid = 1; | |
2380 | } | |
2381 | } | |
2382 | } | |
51cf3e31 | 2383 | |
be44ca6c PE |
2384 | if (! (valid && val <= max)) |
2385 | error ("Not an in-range integer, float, or cons of integers"); | |
2386 | return val; | |
51cf3e31 JB |
2387 | } |
2388 | ||
be44ca6c PE |
2389 | /* Convert the cons-of-integers, integer, or float value C to a signed |
2390 | value with extrema MIN and MAX. Signal an error if C does not have | |
2391 | a valid format or is out of range. */ | |
2392 | intmax_t | |
2393 | cons_to_signed (Lisp_Object c, intmax_t min, intmax_t max) | |
51cf3e31 | 2394 | { |
de1339b0 | 2395 | bool valid = 0; |
be44ca6c | 2396 | intmax_t val IF_LINT (= 0); |
51cf3e31 | 2397 | if (INTEGERP (c)) |
be44ca6c PE |
2398 | { |
2399 | val = XINT (c); | |
2400 | valid = 1; | |
2401 | } | |
2402 | else if (FLOATP (c)) | |
2403 | { | |
2404 | double d = XFLOAT_DATA (c); | |
2405 | if (min <= d | |
2406 | && d < (max == INTMAX_MAX ? (double) INTMAX_MAX + 1 : max + 1)) | |
2407 | { | |
2408 | val = d; | |
2409 | valid = 1; | |
2410 | } | |
2411 | } | |
2412 | else if (CONSP (c) && INTEGERP (XCAR (c))) | |
2413 | { | |
2414 | intmax_t top = XINT (XCAR (c)); | |
2415 | Lisp_Object rest = XCDR (c); | |
2416 | if (INTMAX_MIN >> 24 >> 16 <= top && top <= INTMAX_MAX >> 24 >> 16 | |
2417 | && CONSP (rest) | |
2418 | && NATNUMP (XCAR (rest)) && XFASTINT (XCAR (rest)) < 1 << 24 | |
2419 | && NATNUMP (XCDR (rest)) && XFASTINT (XCDR (rest)) < 1 << 16) | |
2420 | { | |
2421 | intmax_t mid = XFASTINT (XCAR (rest)); | |
2422 | val = top << 24 << 16 | mid << 16 | XFASTINT (XCDR (rest)); | |
2423 | valid = 1; | |
2424 | } | |
2425 | else if (INTMAX_MIN >> 16 <= top && top <= INTMAX_MAX >> 16) | |
2426 | { | |
2427 | if (CONSP (rest)) | |
2428 | rest = XCAR (rest); | |
2429 | if (NATNUMP (rest) && XFASTINT (rest) < 1 << 16) | |
2430 | { | |
2431 | val = top << 16 | XFASTINT (rest); | |
2432 | valid = 1; | |
2433 | } | |
2434 | } | |
2435 | } | |
2436 | ||
2437 | if (! (valid && min <= val && val <= max)) | |
2438 | error ("Not an in-range integer, float, or cons of integers"); | |
2439 | return val; | |
51cf3e31 JB |
2440 | } |
2441 | \f | |
a7ca3326 | 2442 | DEFUN ("number-to-string", Fnumber_to_string, Snumber_to_string, 1, 1, 0, |
bfb96cb7 | 2443 | doc: /* Return the decimal representation of NUMBER as a string. |
8c1a1077 PJ |
2444 | Uses a minus sign if negative. |
2445 | NUMBER may be an integer or a floating point number. */) | |
5842a27b | 2446 | (Lisp_Object number) |
7921925c | 2447 | { |
99027bdd PE |
2448 | char buffer[max (FLOAT_TO_STRING_BUFSIZE, INT_BUFSIZE_BOUND (EMACS_INT))]; |
2449 | int len; | |
7921925c | 2450 | |
b7826503 | 2451 | CHECK_NUMBER_OR_FLOAT (number); |
7921925c | 2452 | |
d9c2a0f2 | 2453 | if (FLOATP (number)) |
99027bdd PE |
2454 | len = float_to_string (buffer, XFLOAT_DATA (number)); |
2455 | else | |
2456 | len = sprintf (buffer, "%"pI"d", XINT (number)); | |
7921925c | 2457 | |
99027bdd | 2458 | return make_unibyte_string (buffer, len); |
7921925c JB |
2459 | } |
2460 | ||
a7ca3326 | 2461 | DEFUN ("string-to-number", Fstring_to_number, Sstring_to_number, 1, 2, 0, |
558ee900 | 2462 | doc: /* Parse STRING as a decimal number and return the number. |
8c1a1077 | 2463 | This parses both integers and floating point numbers. |
be95bee9 | 2464 | It ignores leading spaces and tabs, and all trailing chars. |
8c1a1077 PJ |
2465 | |
2466 | If BASE, interpret STRING as a number in that base. If BASE isn't | |
2467 | present, base 10 is used. BASE must be between 2 and 16 (inclusive). | |
be95bee9 | 2468 | If the base used is not 10, STRING is always parsed as integer. */) |
5842a27b | 2469 | (register Lisp_Object string, Lisp_Object base) |
7921925c | 2470 | { |
57ace6d0 | 2471 | register char *p; |
342858a5 | 2472 | register int b; |
452f4150 | 2473 | Lisp_Object val; |
25e40a4b | 2474 | |
b7826503 | 2475 | CHECK_STRING (string); |
7921925c | 2476 | |
3883fbeb RS |
2477 | if (NILP (base)) |
2478 | b = 10; | |
2479 | else | |
2480 | { | |
b7826503 | 2481 | CHECK_NUMBER (base); |
d311d28c | 2482 | if (! (2 <= XINT (base) && XINT (base) <= 16)) |
740ef0b5 | 2483 | xsignal1 (Qargs_out_of_range, base); |
d311d28c | 2484 | b = XINT (base); |
3883fbeb RS |
2485 | } |
2486 | ||
57ace6d0 | 2487 | p = SSDATA (string); |
0a3e4d65 | 2488 | while (*p == ' ' || *p == '\t') |
25e40a4b JB |
2489 | p++; |
2490 | ||
452f4150 PE |
2491 | val = string_to_number (p, b, 1); |
2492 | return NILP (val) ? make_number (0) : val; | |
7921925c | 2493 | } |
7403b5c8 | 2494 | \f |
7921925c | 2495 | enum arithop |
7a283f36 GM |
2496 | { |
2497 | Aadd, | |
2498 | Asub, | |
2499 | Amult, | |
2500 | Adiv, | |
2501 | Alogand, | |
2502 | Alogior, | |
2503 | Alogxor, | |
2504 | Amax, | |
2505 | Amin | |
2506 | }; | |
2507 | ||
f66c7cf8 PE |
2508 | static Lisp_Object float_arith_driver (double, ptrdiff_t, enum arithop, |
2509 | ptrdiff_t, Lisp_Object *); | |
112396d6 | 2510 | static Lisp_Object |
f66c7cf8 | 2511 | arith_driver (enum arithop code, ptrdiff_t nargs, Lisp_Object *args) |
7921925c | 2512 | { |
de1339b0 PE |
2513 | Lisp_Object val; |
2514 | ptrdiff_t argnum, ok_args; | |
2515 | EMACS_INT accum = 0; | |
2516 | EMACS_INT next, ok_accum; | |
2517 | bool overflow = 0; | |
0ae6bdee | 2518 | |
7393bcbb | 2519 | switch (code) |
7921925c JB |
2520 | { |
2521 | case Alogior: | |
2522 | case Alogxor: | |
2523 | case Aadd: | |
2524 | case Asub: | |
7a283f36 GM |
2525 | accum = 0; |
2526 | break; | |
7921925c | 2527 | case Amult: |
7a283f36 GM |
2528 | accum = 1; |
2529 | break; | |
7921925c | 2530 | case Alogand: |
7a283f36 GM |
2531 | accum = -1; |
2532 | break; | |
2533 | default: | |
2534 | break; | |
7921925c JB |
2535 | } |
2536 | ||
2537 | for (argnum = 0; argnum < nargs; argnum++) | |
2538 | { | |
0ae6bdee PE |
2539 | if (! overflow) |
2540 | { | |
2541 | ok_args = argnum; | |
2542 | ok_accum = accum; | |
2543 | } | |
2544 | ||
7a283f36 GM |
2545 | /* Using args[argnum] as argument to CHECK_NUMBER_... */ |
2546 | val = args[argnum]; | |
b7826503 | 2547 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val); |
7921925c | 2548 | |
7a283f36 | 2549 | if (FLOATP (val)) |
0ae6bdee | 2550 | return float_arith_driver (ok_accum, ok_args, code, |
7a283f36 GM |
2551 | nargs, args); |
2552 | args[argnum] = val; | |
7921925c | 2553 | next = XINT (args[argnum]); |
7393bcbb | 2554 | switch (code) |
7921925c | 2555 | { |
7a283f36 | 2556 | case Aadd: |
0ae6bdee PE |
2557 | if (INT_ADD_OVERFLOW (accum, next)) |
2558 | { | |
2559 | overflow = 1; | |
2560 | accum &= INTMASK; | |
2561 | } | |
7a283f36 GM |
2562 | accum += next; |
2563 | break; | |
7921925c | 2564 | case Asub: |
0ae6bdee PE |
2565 | if (INT_SUBTRACT_OVERFLOW (accum, next)) |
2566 | { | |
2567 | overflow = 1; | |
2568 | accum &= INTMASK; | |
2569 | } | |
e64981da | 2570 | accum = argnum ? accum - next : nargs == 1 ? - next : next; |
7921925c | 2571 | break; |
7a283f36 | 2572 | case Amult: |
0ae6bdee PE |
2573 | if (INT_MULTIPLY_OVERFLOW (accum, next)) |
2574 | { | |
c8a9ca5a | 2575 | EMACS_UINT a = accum, b = next, ab = a * b; |
0ae6bdee | 2576 | overflow = 1; |
c8a9ca5a | 2577 | accum = ab & INTMASK; |
0ae6bdee PE |
2578 | } |
2579 | else | |
2580 | accum *= next; | |
7a283f36 | 2581 | break; |
7921925c | 2582 | case Adiv: |
7a283f36 GM |
2583 | if (!argnum) |
2584 | accum = next; | |
87fbf902 RS |
2585 | else |
2586 | { | |
2587 | if (next == 0) | |
740ef0b5 | 2588 | xsignal0 (Qarith_error); |
87fbf902 RS |
2589 | accum /= next; |
2590 | } | |
7921925c | 2591 | break; |
7a283f36 GM |
2592 | case Alogand: |
2593 | accum &= next; | |
2594 | break; | |
2595 | case Alogior: | |
2596 | accum |= next; | |
2597 | break; | |
2598 | case Alogxor: | |
2599 | accum ^= next; | |
2600 | break; | |
2601 | case Amax: | |
2602 | if (!argnum || next > accum) | |
2603 | accum = next; | |
2604 | break; | |
2605 | case Amin: | |
2606 | if (!argnum || next < accum) | |
2607 | accum = next; | |
2608 | break; | |
7921925c JB |
2609 | } |
2610 | } | |
2611 | ||
f187f1f7 | 2612 | XSETINT (val, accum); |
7921925c JB |
2613 | return val; |
2614 | } | |
2615 | ||
1a2f2d33 KH |
2616 | #undef isnan |
2617 | #define isnan(x) ((x) != (x)) | |
2618 | ||
7a283f36 | 2619 | static Lisp_Object |
f66c7cf8 PE |
2620 | float_arith_driver (double accum, ptrdiff_t argnum, enum arithop code, |
2621 | ptrdiff_t nargs, Lisp_Object *args) | |
7921925c JB |
2622 | { |
2623 | register Lisp_Object val; | |
2624 | double next; | |
7403b5c8 | 2625 | |
7921925c JB |
2626 | for (; argnum < nargs; argnum++) |
2627 | { | |
2628 | val = args[argnum]; /* using args[argnum] as argument to CHECK_NUMBER_... */ | |
b7826503 | 2629 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val); |
7921925c | 2630 | |
e9ebc175 | 2631 | if (FLOATP (val)) |
7921925c | 2632 | { |
7539e11f | 2633 | next = XFLOAT_DATA (val); |
7921925c JB |
2634 | } |
2635 | else | |
2636 | { | |
2637 | args[argnum] = val; /* runs into a compiler bug. */ | |
2638 | next = XINT (args[argnum]); | |
2639 | } | |
7393bcbb | 2640 | switch (code) |
7921925c JB |
2641 | { |
2642 | case Aadd: | |
2643 | accum += next; | |
2644 | break; | |
2645 | case Asub: | |
e64981da | 2646 | accum = argnum ? accum - next : nargs == 1 ? - next : next; |
7921925c JB |
2647 | break; |
2648 | case Amult: | |
2649 | accum *= next; | |
2650 | break; | |
2651 | case Adiv: | |
2652 | if (!argnum) | |
2653 | accum = next; | |
2654 | else | |
87fbf902 | 2655 | { |
ad8d56b9 | 2656 | if (! IEEE_FLOATING_POINT && next == 0) |
740ef0b5 | 2657 | xsignal0 (Qarith_error); |
87fbf902 RS |
2658 | accum /= next; |
2659 | } | |
7921925c JB |
2660 | break; |
2661 | case Alogand: | |
2662 | case Alogior: | |
2663 | case Alogxor: | |
2664 | return wrong_type_argument (Qinteger_or_marker_p, val); | |
2665 | case Amax: | |
1a2f2d33 | 2666 | if (!argnum || isnan (next) || next > accum) |
7921925c JB |
2667 | accum = next; |
2668 | break; | |
2669 | case Amin: | |
1a2f2d33 | 2670 | if (!argnum || isnan (next) || next < accum) |
7921925c JB |
2671 | accum = next; |
2672 | break; | |
2673 | } | |
2674 | } | |
2675 | ||
2676 | return make_float (accum); | |
2677 | } | |
cc94f3b2 | 2678 | |
7921925c | 2679 | |
a7ca3326 | 2680 | DEFUN ("+", Fplus, Splus, 0, MANY, 0, |
8c1a1077 PJ |
2681 | doc: /* Return sum of any number of arguments, which are numbers or markers. |
2682 | usage: (+ &rest NUMBERS-OR-MARKERS) */) | |
f66c7cf8 | 2683 | (ptrdiff_t nargs, Lisp_Object *args) |
7921925c JB |
2684 | { |
2685 | return arith_driver (Aadd, nargs, args); | |
2686 | } | |
2687 | ||
a7ca3326 | 2688 | DEFUN ("-", Fminus, Sminus, 0, MANY, 0, |
558ee900 | 2689 | doc: /* Negate number or subtract numbers or markers and return the result. |
8c1a1077 | 2690 | With one arg, negates it. With more than one arg, |
f44fba9e | 2691 | subtracts all but the first from the first. |
8c1a1077 | 2692 | usage: (- &optional NUMBER-OR-MARKER &rest MORE-NUMBERS-OR-MARKERS) */) |
f66c7cf8 | 2693 | (ptrdiff_t nargs, Lisp_Object *args) |
7921925c JB |
2694 | { |
2695 | return arith_driver (Asub, nargs, args); | |
2696 | } | |
2697 | ||
a7ca3326 | 2698 | DEFUN ("*", Ftimes, Stimes, 0, MANY, 0, |
be24eadf | 2699 | doc: /* Return product of any number of arguments, which are numbers or markers. |
8c1a1077 | 2700 | usage: (* &rest NUMBERS-OR-MARKERS) */) |
f66c7cf8 | 2701 | (ptrdiff_t nargs, Lisp_Object *args) |
7921925c JB |
2702 | { |
2703 | return arith_driver (Amult, nargs, args); | |
2704 | } | |
2705 | ||
a7ca3326 | 2706 | DEFUN ("/", Fquo, Squo, 2, MANY, 0, |
be24eadf | 2707 | doc: /* Return first argument divided by all the remaining arguments. |
f44fba9e | 2708 | The arguments must be numbers or markers. |
8c1a1077 | 2709 | usage: (/ DIVIDEND DIVISOR &rest DIVISORS) */) |
f66c7cf8 | 2710 | (ptrdiff_t nargs, Lisp_Object *args) |
7921925c | 2711 | { |
f66c7cf8 | 2712 | ptrdiff_t argnum; |
7ef98053 | 2713 | for (argnum = 2; argnum < nargs; argnum++) |
28712a21 JB |
2714 | if (FLOATP (args[argnum])) |
2715 | return float_arith_driver (0, 0, Adiv, nargs, args); | |
7921925c JB |
2716 | return arith_driver (Adiv, nargs, args); |
2717 | } | |
2718 | ||
a7ca3326 | 2719 | DEFUN ("%", Frem, Srem, 2, 2, 0, |
be24eadf | 2720 | doc: /* Return remainder of X divided by Y. |
8c1a1077 | 2721 | Both must be integers or markers. */) |
5842a27b | 2722 | (register Lisp_Object x, Lisp_Object y) |
7921925c JB |
2723 | { |
2724 | Lisp_Object val; | |
2725 | ||
b7826503 PJ |
2726 | CHECK_NUMBER_COERCE_MARKER (x); |
2727 | CHECK_NUMBER_COERCE_MARKER (y); | |
7921925c | 2728 | |
d311d28c | 2729 | if (XINT (y) == 0) |
740ef0b5 | 2730 | xsignal0 (Qarith_error); |
87fbf902 | 2731 | |
d9c2a0f2 | 2732 | XSETINT (val, XINT (x) % XINT (y)); |
7921925c JB |
2733 | return val; |
2734 | } | |
2735 | ||
44fa9da5 | 2736 | DEFUN ("mod", Fmod, Smod, 2, 2, 0, |
be24eadf | 2737 | doc: /* Return X modulo Y. |
8c1a1077 PJ |
2738 | The result falls between zero (inclusive) and Y (exclusive). |
2739 | Both X and Y must be numbers or markers. */) | |
5842a27b | 2740 | (register Lisp_Object x, Lisp_Object y) |
44fa9da5 PE |
2741 | { |
2742 | Lisp_Object val; | |
5260234d | 2743 | EMACS_INT i1, i2; |
44fa9da5 | 2744 | |
b7826503 PJ |
2745 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (x); |
2746 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (y); | |
44fa9da5 | 2747 | |
d9c2a0f2 | 2748 | if (FLOATP (x) || FLOATP (y)) |
ad8d56b9 PE |
2749 | return fmod_float (x, y); |
2750 | ||
d9c2a0f2 EN |
2751 | i1 = XINT (x); |
2752 | i2 = XINT (y); | |
44fa9da5 PE |
2753 | |
2754 | if (i2 == 0) | |
740ef0b5 | 2755 | xsignal0 (Qarith_error); |
7403b5c8 | 2756 | |
44fa9da5 PE |
2757 | i1 %= i2; |
2758 | ||
2759 | /* If the "remainder" comes out with the wrong sign, fix it. */ | |
04f7ec69 | 2760 | if (i2 < 0 ? i1 > 0 : i1 < 0) |
44fa9da5 PE |
2761 | i1 += i2; |
2762 | ||
f187f1f7 | 2763 | XSETINT (val, i1); |
44fa9da5 PE |
2764 | return val; |
2765 | } | |
2766 | ||
a7ca3326 | 2767 | DEFUN ("max", Fmax, Smax, 1, MANY, 0, |
8c1a1077 | 2768 | doc: /* Return largest of all the arguments (which must be numbers or markers). |
f44fba9e | 2769 | The value is always a number; markers are converted to numbers. |
8c1a1077 | 2770 | usage: (max NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */) |
f66c7cf8 | 2771 | (ptrdiff_t nargs, Lisp_Object *args) |
7921925c JB |
2772 | { |
2773 | return arith_driver (Amax, nargs, args); | |
2774 | } | |
2775 | ||
a7ca3326 | 2776 | DEFUN ("min", Fmin, Smin, 1, MANY, 0, |
8c1a1077 | 2777 | doc: /* Return smallest of all the arguments (which must be numbers or markers). |
f44fba9e | 2778 | The value is always a number; markers are converted to numbers. |
8c1a1077 | 2779 | usage: (min NUMBER-OR-MARKER &rest NUMBERS-OR-MARKERS) */) |
f66c7cf8 | 2780 | (ptrdiff_t nargs, Lisp_Object *args) |
7921925c JB |
2781 | { |
2782 | return arith_driver (Amin, nargs, args); | |
2783 | } | |
2784 | ||
2785 | DEFUN ("logand", Flogand, Slogand, 0, MANY, 0, | |
8c1a1077 | 2786 | doc: /* Return bitwise-and of all the arguments. |
f44fba9e | 2787 | Arguments may be integers, or markers converted to integers. |
8c1a1077 | 2788 | usage: (logand &rest INTS-OR-MARKERS) */) |
f66c7cf8 | 2789 | (ptrdiff_t nargs, Lisp_Object *args) |
7921925c JB |
2790 | { |
2791 | return arith_driver (Alogand, nargs, args); | |
2792 | } | |
2793 | ||
2794 | DEFUN ("logior", Flogior, Slogior, 0, MANY, 0, | |
8c1a1077 | 2795 | doc: /* Return bitwise-or of all the arguments. |
f44fba9e | 2796 | Arguments may be integers, or markers converted to integers. |
8c1a1077 | 2797 | usage: (logior &rest INTS-OR-MARKERS) */) |
f66c7cf8 | 2798 | (ptrdiff_t nargs, Lisp_Object *args) |
7921925c JB |
2799 | { |
2800 | return arith_driver (Alogior, nargs, args); | |
2801 | } | |
2802 | ||
2803 | DEFUN ("logxor", Flogxor, Slogxor, 0, MANY, 0, | |
8c1a1077 | 2804 | doc: /* Return bitwise-exclusive-or of all the arguments. |
f44fba9e | 2805 | Arguments may be integers, or markers converted to integers. |
31fb1b2c | 2806 | usage: (logxor &rest INTS-OR-MARKERS) */) |
f66c7cf8 | 2807 | (ptrdiff_t nargs, Lisp_Object *args) |
7921925c JB |
2808 | { |
2809 | return arith_driver (Alogxor, nargs, args); | |
2810 | } | |
2811 | ||
2812 | DEFUN ("ash", Fash, Sash, 2, 2, 0, | |
8c1a1077 PJ |
2813 | doc: /* Return VALUE with its bits shifted left by COUNT. |
2814 | If COUNT is negative, shifting is actually to the right. | |
2815 | In this case, the sign bit is duplicated. */) | |
5842a27b | 2816 | (register Lisp_Object value, Lisp_Object count) |
7921925c JB |
2817 | { |
2818 | register Lisp_Object val; | |
2819 | ||
b7826503 PJ |
2820 | CHECK_NUMBER (value); |
2821 | CHECK_NUMBER (count); | |
7921925c | 2822 | |
81d70626 RS |
2823 | if (XINT (count) >= BITS_PER_EMACS_INT) |
2824 | XSETINT (val, 0); | |
2825 | else if (XINT (count) > 0) | |
3d9652eb | 2826 | XSETINT (val, XINT (value) << XFASTINT (count)); |
81d70626 RS |
2827 | else if (XINT (count) <= -BITS_PER_EMACS_INT) |
2828 | XSETINT (val, XINT (value) < 0 ? -1 : 0); | |
7921925c | 2829 | else |
3d9652eb | 2830 | XSETINT (val, XINT (value) >> -XINT (count)); |
7921925c JB |
2831 | return val; |
2832 | } | |
2833 | ||
2834 | DEFUN ("lsh", Flsh, Slsh, 2, 2, 0, | |
8c1a1077 PJ |
2835 | doc: /* Return VALUE with its bits shifted left by COUNT. |
2836 | If COUNT is negative, shifting is actually to the right. | |
3a9b1297 | 2837 | In this case, zeros are shifted in on the left. */) |
5842a27b | 2838 | (register Lisp_Object value, Lisp_Object count) |
7921925c JB |
2839 | { |
2840 | register Lisp_Object val; | |
2841 | ||
b7826503 PJ |
2842 | CHECK_NUMBER (value); |
2843 | CHECK_NUMBER (count); | |
7921925c | 2844 | |
81d70626 RS |
2845 | if (XINT (count) >= BITS_PER_EMACS_INT) |
2846 | XSETINT (val, 0); | |
2847 | else if (XINT (count) > 0) | |
c8a9ca5a | 2848 | XSETINT (val, XUINT (value) << XFASTINT (count)); |
81d70626 RS |
2849 | else if (XINT (count) <= -BITS_PER_EMACS_INT) |
2850 | XSETINT (val, 0); | |
7921925c | 2851 | else |
c8a9ca5a | 2852 | XSETINT (val, XUINT (value) >> -XINT (count)); |
7921925c JB |
2853 | return val; |
2854 | } | |
2855 | ||
a7ca3326 | 2856 | DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0, |
8c1a1077 PJ |
2857 | doc: /* Return NUMBER plus one. NUMBER may be a number or a marker. |
2858 | Markers are converted to integers. */) | |
5842a27b | 2859 | (register Lisp_Object number) |
7921925c | 2860 | { |
b7826503 | 2861 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number); |
7921925c | 2862 | |
d9c2a0f2 | 2863 | if (FLOATP (number)) |
7539e11f | 2864 | return (make_float (1.0 + XFLOAT_DATA (number))); |
7921925c | 2865 | |
d9c2a0f2 EN |
2866 | XSETINT (number, XINT (number) + 1); |
2867 | return number; | |
7921925c JB |
2868 | } |
2869 | ||
a7ca3326 | 2870 | DEFUN ("1-", Fsub1, Ssub1, 1, 1, 0, |
8c1a1077 PJ |
2871 | doc: /* Return NUMBER minus one. NUMBER may be a number or a marker. |
2872 | Markers are converted to integers. */) | |
5842a27b | 2873 | (register Lisp_Object number) |
7921925c | 2874 | { |
b7826503 | 2875 | CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (number); |
7921925c | 2876 | |
d9c2a0f2 | 2877 | if (FLOATP (number)) |
7539e11f | 2878 | return (make_float (-1.0 + XFLOAT_DATA (number))); |
7921925c | 2879 | |
d9c2a0f2 EN |
2880 | XSETINT (number, XINT (number) - 1); |
2881 | return number; | |
7921925c JB |
2882 | } |
2883 | ||
2884 | DEFUN ("lognot", Flognot, Slognot, 1, 1, 0, | |
8c1a1077 | 2885 | doc: /* Return the bitwise complement of NUMBER. NUMBER must be an integer. */) |
5842a27b | 2886 | (register Lisp_Object number) |
7921925c | 2887 | { |
b7826503 | 2888 | CHECK_NUMBER (number); |
53924017 | 2889 | XSETINT (number, ~XINT (number)); |
d9c2a0f2 | 2890 | return number; |
7921925c | 2891 | } |
6b61353c | 2892 | |
a7ca3326 | 2893 | DEFUN ("byteorder", Fbyteorder, Sbyteorder, 0, 0, 0, |
6b61353c KH |
2894 | doc: /* Return the byteorder for the machine. |
2895 | Returns 66 (ASCII uppercase B) for big endian machines or 108 (ASCII | |
2896 | lowercase l) for small endian machines. */) | |
5842a27b | 2897 | (void) |
6b61353c KH |
2898 | { |
2899 | unsigned i = 0x04030201; | |
2900 | int order = *(char *)&i == 1 ? 108 : 66; | |
2901 | ||
2902 | return make_number (order); | |
2903 | } | |
2904 | ||
2905 | ||
7921925c JB |
2906 | \f |
2907 | void | |
971de7fb | 2908 | syms_of_data (void) |
7921925c | 2909 | { |
6315e761 RS |
2910 | Lisp_Object error_tail, arith_tail; |
2911 | ||
620c53a6 SM |
2912 | DEFSYM (Qquote, "quote"); |
2913 | DEFSYM (Qlambda, "lambda"); | |
2914 | DEFSYM (Qsubr, "subr"); | |
2915 | DEFSYM (Qerror_conditions, "error-conditions"); | |
2916 | DEFSYM (Qerror_message, "error-message"); | |
2917 | DEFSYM (Qtop_level, "top-level"); | |
2918 | ||
2919 | DEFSYM (Qerror, "error"); | |
71873e2b | 2920 | DEFSYM (Quser_error, "user-error"); |
620c53a6 SM |
2921 | DEFSYM (Qquit, "quit"); |
2922 | DEFSYM (Qwrong_type_argument, "wrong-type-argument"); | |
2923 | DEFSYM (Qargs_out_of_range, "args-out-of-range"); | |
2924 | DEFSYM (Qvoid_function, "void-function"); | |
2925 | DEFSYM (Qcyclic_function_indirection, "cyclic-function-indirection"); | |
2926 | DEFSYM (Qcyclic_variable_indirection, "cyclic-variable-indirection"); | |
2927 | DEFSYM (Qvoid_variable, "void-variable"); | |
2928 | DEFSYM (Qsetting_constant, "setting-constant"); | |
2929 | DEFSYM (Qinvalid_read_syntax, "invalid-read-syntax"); | |
2930 | ||
2931 | DEFSYM (Qinvalid_function, "invalid-function"); | |
2932 | DEFSYM (Qwrong_number_of_arguments, "wrong-number-of-arguments"); | |
2933 | DEFSYM (Qno_catch, "no-catch"); | |
2934 | DEFSYM (Qend_of_file, "end-of-file"); | |
2935 | DEFSYM (Qarith_error, "arith-error"); | |
2936 | DEFSYM (Qbeginning_of_buffer, "beginning-of-buffer"); | |
2937 | DEFSYM (Qend_of_buffer, "end-of-buffer"); | |
2938 | DEFSYM (Qbuffer_read_only, "buffer-read-only"); | |
2939 | DEFSYM (Qtext_read_only, "text-read-only"); | |
2940 | DEFSYM (Qmark_inactive, "mark-inactive"); | |
2941 | ||
2942 | DEFSYM (Qlistp, "listp"); | |
2943 | DEFSYM (Qconsp, "consp"); | |
2944 | DEFSYM (Qsymbolp, "symbolp"); | |
2945 | DEFSYM (Qkeywordp, "keywordp"); | |
2946 | DEFSYM (Qintegerp, "integerp"); | |
2947 | DEFSYM (Qnatnump, "natnump"); | |
2948 | DEFSYM (Qwholenump, "wholenump"); | |
2949 | DEFSYM (Qstringp, "stringp"); | |
2950 | DEFSYM (Qarrayp, "arrayp"); | |
2951 | DEFSYM (Qsequencep, "sequencep"); | |
2952 | DEFSYM (Qbufferp, "bufferp"); | |
2953 | DEFSYM (Qvectorp, "vectorp"); | |
2954 | DEFSYM (Qchar_or_string_p, "char-or-string-p"); | |
2955 | DEFSYM (Qmarkerp, "markerp"); | |
2956 | DEFSYM (Qbuffer_or_string_p, "buffer-or-string-p"); | |
2957 | DEFSYM (Qinteger_or_marker_p, "integer-or-marker-p"); | |
2958 | DEFSYM (Qboundp, "boundp"); | |
2959 | DEFSYM (Qfboundp, "fboundp"); | |
2960 | ||
2961 | DEFSYM (Qfloatp, "floatp"); | |
2962 | DEFSYM (Qnumberp, "numberp"); | |
2963 | DEFSYM (Qnumber_or_marker_p, "number-or-marker-p"); | |
2964 | ||
2965 | DEFSYM (Qchar_table_p, "char-table-p"); | |
2966 | DEFSYM (Qvector_or_char_table_p, "vector-or-char-table-p"); | |
2967 | ||
2968 | DEFSYM (Qsubrp, "subrp"); | |
2969 | DEFSYM (Qunevalled, "unevalled"); | |
2970 | DEFSYM (Qmany, "many"); | |
2971 | ||
2972 | DEFSYM (Qcdr, "cdr"); | |
2973 | ||
2974 | /* Handle automatic advice activation. */ | |
2975 | DEFSYM (Qad_advice_info, "ad-advice-info"); | |
2976 | DEFSYM (Qad_activate_internal, "ad-activate-internal"); | |
f845f2c9 | 2977 | |
d67b4f80 | 2978 | error_tail = pure_cons (Qerror, Qnil); |
6315e761 | 2979 | |
620c53a6 SM |
2980 | /* ERROR is used as a signaler for random errors for which nothing else is |
2981 | right. */ | |
7921925c JB |
2982 | |
2983 | Fput (Qerror, Qerror_conditions, | |
6315e761 | 2984 | error_tail); |
7921925c | 2985 | Fput (Qerror, Qerror_message, |
2a0213a6 | 2986 | build_pure_c_string ("error")); |
7921925c | 2987 | |
71873e2b SM |
2988 | #define PUT_ERROR(sym, tail, msg) \ |
2989 | Fput (sym, Qerror_conditions, pure_cons (sym, tail)); \ | |
2a0213a6 | 2990 | Fput (sym, Qerror_message, build_pure_c_string (msg)) |
71873e2b SM |
2991 | |
2992 | PUT_ERROR (Qquit, Qnil, "Quit"); | |
2993 | ||
2994 | PUT_ERROR (Quser_error, error_tail, ""); | |
2995 | PUT_ERROR (Qwrong_type_argument, error_tail, "Wrong type argument"); | |
2996 | PUT_ERROR (Qargs_out_of_range, error_tail, "Args out of range"); | |
2997 | PUT_ERROR (Qvoid_function, error_tail, | |
2998 | "Symbol's function definition is void"); | |
2999 | PUT_ERROR (Qcyclic_function_indirection, error_tail, | |
3000 | "Symbol's chain of function indirections contains a loop"); | |
3001 | PUT_ERROR (Qcyclic_variable_indirection, error_tail, | |
3002 | "Symbol's chain of variable indirections contains a loop"); | |
620c53a6 | 3003 | DEFSYM (Qcircular_list, "circular-list"); |
71873e2b SM |
3004 | PUT_ERROR (Qcircular_list, error_tail, "List contains a loop"); |
3005 | PUT_ERROR (Qvoid_variable, error_tail, "Symbol's value as variable is void"); | |
3006 | PUT_ERROR (Qsetting_constant, error_tail, | |
3007 | "Attempt to set a constant symbol"); | |
3008 | PUT_ERROR (Qinvalid_read_syntax, error_tail, "Invalid read syntax"); | |
3009 | PUT_ERROR (Qinvalid_function, error_tail, "Invalid function"); | |
3010 | PUT_ERROR (Qwrong_number_of_arguments, error_tail, | |
3011 | "Wrong number of arguments"); | |
3012 | PUT_ERROR (Qno_catch, error_tail, "No catch for tag"); | |
3013 | PUT_ERROR (Qend_of_file, error_tail, "End of file during parsing"); | |
7921925c | 3014 | |
d67b4f80 | 3015 | arith_tail = pure_cons (Qarith_error, error_tail); |
71873e2b | 3016 | Fput (Qarith_error, Qerror_conditions, arith_tail); |
2a0213a6 | 3017 | Fput (Qarith_error, Qerror_message, build_pure_c_string ("Arithmetic error")); |
71873e2b SM |
3018 | |
3019 | PUT_ERROR (Qbeginning_of_buffer, error_tail, "Beginning of buffer"); | |
3020 | PUT_ERROR (Qend_of_buffer, error_tail, "End of buffer"); | |
3021 | PUT_ERROR (Qbuffer_read_only, error_tail, "Buffer is read-only"); | |
3022 | PUT_ERROR (Qtext_read_only, pure_cons (Qbuffer_read_only, error_tail), | |
3023 | "Text is read-only"); | |
8f9f49d7 | 3024 | |
620c53a6 SM |
3025 | DEFSYM (Qrange_error, "range-error"); |
3026 | DEFSYM (Qdomain_error, "domain-error"); | |
3027 | DEFSYM (Qsingularity_error, "singularity-error"); | |
3028 | DEFSYM (Qoverflow_error, "overflow-error"); | |
3029 | DEFSYM (Qunderflow_error, "underflow-error"); | |
6315e761 | 3030 | |
71873e2b SM |
3031 | PUT_ERROR (Qdomain_error, arith_tail, "Arithmetic domain error"); |
3032 | ||
3033 | PUT_ERROR (Qrange_error, arith_tail, "Arithmetic range error"); | |
3034 | ||
3035 | PUT_ERROR (Qsingularity_error, Fcons (Qdomain_error, arith_tail), | |
3036 | "Arithmetic singularity error"); | |
3037 | ||
3038 | PUT_ERROR (Qoverflow_error, Fcons (Qdomain_error, arith_tail), | |
3039 | "Arithmetic overflow error"); | |
3040 | PUT_ERROR (Qunderflow_error, Fcons (Qdomain_error, arith_tail), | |
3041 | "Arithmetic underflow error"); | |
6315e761 | 3042 | |
7921925c JB |
3043 | staticpro (&Qnil); |
3044 | staticpro (&Qt); | |
7921925c | 3045 | staticpro (&Qunbound); |
7921925c | 3046 | |
39bcc759 | 3047 | /* Types that type-of returns. */ |
620c53a6 SM |
3048 | DEFSYM (Qinteger, "integer"); |
3049 | DEFSYM (Qsymbol, "symbol"); | |
3050 | DEFSYM (Qstring, "string"); | |
3051 | DEFSYM (Qcons, "cons"); | |
3052 | DEFSYM (Qmarker, "marker"); | |
3053 | DEFSYM (Qoverlay, "overlay"); | |
3054 | DEFSYM (Qfloat, "float"); | |
3055 | DEFSYM (Qwindow_configuration, "window-configuration"); | |
3056 | DEFSYM (Qprocess, "process"); | |
3057 | DEFSYM (Qwindow, "window"); | |
620c53a6 SM |
3058 | DEFSYM (Qcompiled_function, "compiled-function"); |
3059 | DEFSYM (Qbuffer, "buffer"); | |
3060 | DEFSYM (Qframe, "frame"); | |
3061 | DEFSYM (Qvector, "vector"); | |
3062 | DEFSYM (Qchar_table, "char-table"); | |
3063 | DEFSYM (Qbool_vector, "bool-vector"); | |
3064 | DEFSYM (Qhash_table, "hash-table"); | |
3ab6e069 | 3065 | DEFSYM (Qmisc, "misc"); |
39bcc759 | 3066 | |
61b108cc SM |
3067 | DEFSYM (Qdefun, "defun"); |
3068 | ||
4e6f2626 CY |
3069 | DEFSYM (Qfont_spec, "font-spec"); |
3070 | DEFSYM (Qfont_entity, "font-entity"); | |
3071 | DEFSYM (Qfont_object, "font-object"); | |
3072 | ||
3860280a CY |
3073 | DEFSYM (Qinteractive_form, "interactive-form"); |
3074 | ||
f35d5bad | 3075 | defsubr (&Sindirect_variable); |
6b61353c | 3076 | defsubr (&Sinteractive_form); |
7921925c JB |
3077 | defsubr (&Seq); |
3078 | defsubr (&Snull); | |
39bcc759 | 3079 | defsubr (&Stype_of); |
7921925c JB |
3080 | defsubr (&Slistp); |
3081 | defsubr (&Snlistp); | |
3082 | defsubr (&Sconsp); | |
3083 | defsubr (&Satom); | |
3084 | defsubr (&Sintegerp); | |
464f8898 | 3085 | defsubr (&Sinteger_or_marker_p); |
7921925c JB |
3086 | defsubr (&Snumberp); |
3087 | defsubr (&Snumber_or_marker_p); | |
464f8898 | 3088 | defsubr (&Sfloatp); |
7921925c JB |
3089 | defsubr (&Snatnump); |
3090 | defsubr (&Ssymbolp); | |
cda9b832 | 3091 | defsubr (&Skeywordp); |
7921925c | 3092 | defsubr (&Sstringp); |
0f56470d | 3093 | defsubr (&Smultibyte_string_p); |
7921925c | 3094 | defsubr (&Svectorp); |
4d276982 | 3095 | defsubr (&Schar_table_p); |
7f0edce7 | 3096 | defsubr (&Svector_or_char_table_p); |
4d276982 | 3097 | defsubr (&Sbool_vector_p); |
7921925c JB |
3098 | defsubr (&Sarrayp); |
3099 | defsubr (&Ssequencep); | |
3100 | defsubr (&Sbufferp); | |
3101 | defsubr (&Smarkerp); | |
7921925c | 3102 | defsubr (&Ssubrp); |
dbc4e1c1 | 3103 | defsubr (&Sbyte_code_function_p); |
7921925c JB |
3104 | defsubr (&Schar_or_string_p); |
3105 | defsubr (&Scar); | |
3106 | defsubr (&Scdr); | |
3107 | defsubr (&Scar_safe); | |
3108 | defsubr (&Scdr_safe); | |
3109 | defsubr (&Ssetcar); | |
3110 | defsubr (&Ssetcdr); | |
3111 | defsubr (&Ssymbol_function); | |
ffd56f97 | 3112 | defsubr (&Sindirect_function); |
7921925c JB |
3113 | defsubr (&Ssymbol_plist); |
3114 | defsubr (&Ssymbol_name); | |
3115 | defsubr (&Smakunbound); | |
3116 | defsubr (&Sfmakunbound); | |
3117 | defsubr (&Sboundp); | |
3118 | defsubr (&Sfboundp); | |
3119 | defsubr (&Sfset); | |
80df38a2 | 3120 | defsubr (&Sdefalias); |
7921925c JB |
3121 | defsubr (&Ssetplist); |
3122 | defsubr (&Ssymbol_value); | |
3123 | defsubr (&Sset); | |
3124 | defsubr (&Sdefault_boundp); | |
3125 | defsubr (&Sdefault_value); | |
3126 | defsubr (&Sset_default); | |
3127 | defsubr (&Ssetq_default); | |
3128 | defsubr (&Smake_variable_buffer_local); | |
3129 | defsubr (&Smake_local_variable); | |
3130 | defsubr (&Skill_local_variable); | |
b0c2d1c6 | 3131 | defsubr (&Smake_variable_frame_local); |
62476adc | 3132 | defsubr (&Slocal_variable_p); |
f4f04cee | 3133 | defsubr (&Slocal_variable_if_set_p); |
6b61353c | 3134 | defsubr (&Svariable_binding_locus); |
c40bb1ba | 3135 | #if 0 /* XXX Remove this. --lorentey */ |
2a42d440 KL |
3136 | defsubr (&Sterminal_local_value); |
3137 | defsubr (&Sset_terminal_local_value); | |
c40bb1ba | 3138 | #endif |
7921925c JB |
3139 | defsubr (&Saref); |
3140 | defsubr (&Saset); | |
f2980264 | 3141 | defsubr (&Snumber_to_string); |
25e40a4b | 3142 | defsubr (&Sstring_to_number); |
7921925c JB |
3143 | defsubr (&Seqlsign); |
3144 | defsubr (&Slss); | |
3145 | defsubr (&Sgtr); | |
3146 | defsubr (&Sleq); | |
3147 | defsubr (&Sgeq); | |
3148 | defsubr (&Sneq); | |
3149 | defsubr (&Szerop); | |
3150 | defsubr (&Splus); | |
3151 | defsubr (&Sminus); | |
3152 | defsubr (&Stimes); | |
3153 | defsubr (&Squo); | |
3154 | defsubr (&Srem); | |
44fa9da5 | 3155 | defsubr (&Smod); |
7921925c JB |
3156 | defsubr (&Smax); |
3157 | defsubr (&Smin); | |
3158 | defsubr (&Slogand); | |
3159 | defsubr (&Slogior); | |
3160 | defsubr (&Slogxor); | |
3161 | defsubr (&Slsh); | |
3162 | defsubr (&Sash); | |
3163 | defsubr (&Sadd1); | |
3164 | defsubr (&Ssub1); | |
3165 | defsubr (&Slognot); | |
6b61353c | 3166 | defsubr (&Sbyteorder); |
6f0e897f | 3167 | defsubr (&Ssubr_arity); |
0fddae66 | 3168 | defsubr (&Ssubr_name); |
8e86942b | 3169 | |
c644523b | 3170 | set_symbol_function (Qwholenump, XSYMBOL (Qnatnump)->function); |
e6190b11 | 3171 | |
29208e82 | 3172 | DEFVAR_LISP ("most-positive-fixnum", Vmost_positive_fixnum, |
9d113d9d AS |
3173 | doc: /* The largest value that is representable in a Lisp integer. */); |
3174 | Vmost_positive_fixnum = make_number (MOST_POSITIVE_FIXNUM); | |
d67b4f80 | 3175 | XSYMBOL (intern_c_string ("most-positive-fixnum"))->constant = 1; |
bfb96cb7 | 3176 | |
29208e82 | 3177 | DEFVAR_LISP ("most-negative-fixnum", Vmost_negative_fixnum, |
9d113d9d AS |
3178 | doc: /* The smallest value that is representable in a Lisp integer. */); |
3179 | Vmost_negative_fixnum = make_number (MOST_NEGATIVE_FIXNUM); | |
d67b4f80 | 3180 | XSYMBOL (intern_c_string ("most-negative-fixnum"))->constant = 1; |
7921925c JB |
3181 | } |
3182 | ||
20ef56db PE |
3183 | static _Noreturn void |
3184 | handle_arith_signal (int sig) | |
7921925c | 3185 | { |
2fe28299 | 3186 | pthread_sigmask (SIG_SETMASK, &empty_mask, 0); |
740ef0b5 | 3187 | xsignal0 (Qarith_error); |
7921925c JB |
3188 | } |
3189 | ||
20ef56db PE |
3190 | static void |
3191 | deliver_arith_signal (int sig) | |
3192 | { | |
3193 | handle_on_main_thread (sig, handle_arith_signal); | |
3194 | } | |
3195 | ||
dfcf069d | 3196 | void |
971de7fb | 3197 | init_data (void) |
7921925c | 3198 | { |
2fe28299 | 3199 | struct sigaction action; |
7921925c JB |
3200 | /* Don't do this if just dumping out. |
3201 | We don't want to call `signal' in this case | |
3202 | so that we don't have trouble with dumping | |
3203 | signal-delivering routines in an inconsistent state. */ | |
3204 | #ifndef CANNOT_DUMP | |
3205 | if (!initialized) | |
3206 | return; | |
3207 | #endif /* CANNOT_DUMP */ | |
2fe28299 PE |
3208 | emacs_sigaction_init (&action, deliver_arith_signal); |
3209 | sigaction (SIGFPE, &action, 0); | |
7921925c | 3210 | } |