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