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