Mercurial > emacs
annotate src/data.c @ 8427:bc548090f760
*** empty log message ***
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 03 Aug 1994 00:12:07 +0000 |
parents | ec05bbe4ef1c |
children | b6335ce87e16 |
rev | line source |
---|---|
298 | 1 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter. |
7307 | 2 Copyright (C) 1985, 1986, 1988, 1993, 1994 Free Software Foundation, Inc. |
298 | 3 |
4 This file is part of GNU Emacs. | |
5 | |
6 GNU Emacs is free software; you can redistribute it and/or modify | |
7 it under the terms of the GNU General Public License as published by | |
8 the Free Software Foundation; either version 1, or (at your option) | |
9 any later version. | |
10 | |
11 GNU Emacs is distributed in the hope that it will be useful, | |
12 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 GNU General Public License for more details. | |
15 | |
16 You should have received a copy of the GNU General Public License | |
17 along with GNU Emacs; see the file COPYING. If not, write to | |
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | |
20 | |
21 #include <signal.h> | |
22 | |
4696
1fc792473491
Include <config.h> instead of "config.h".
Roland McGrath <roland@gnu.org>
parents:
4508
diff
changeset
|
23 #include <config.h> |
298 | 24 #include "lisp.h" |
336 | 25 #include "puresize.h" |
298 | 26 |
27 #ifndef standalone | |
28 #include "buffer.h" | |
29 #endif | |
30 | |
552 | 31 #include "syssignal.h" |
348 | 32 |
5504
6d6d042b3df6
(Frem) [MSDOS]: use `fmod', not `drem'. Put in config.h?
Richard M. Stallman <rms@gnu.org>
parents:
4860
diff
changeset
|
33 #ifdef MSDOS |
7205
a5199564772e
[MSDOS]: Re-enable some #undef's.
Karl Heuer <kwzh@gnu.org>
parents:
6919
diff
changeset
|
34 /* These are redefined (correctly, but differently) in values.h. */ |
5504
6d6d042b3df6
(Frem) [MSDOS]: use `fmod', not `drem'. Put in config.h?
Richard M. Stallman <rms@gnu.org>
parents:
4860
diff
changeset
|
35 #undef INTBITS |
6d6d042b3df6
(Frem) [MSDOS]: use `fmod', not `drem'. Put in config.h?
Richard M. Stallman <rms@gnu.org>
parents:
4860
diff
changeset
|
36 #undef LONGBITS |
6d6d042b3df6
(Frem) [MSDOS]: use `fmod', not `drem'. Put in config.h?
Richard M. Stallman <rms@gnu.org>
parents:
4860
diff
changeset
|
37 #undef SHORTBITS |
6d6d042b3df6
(Frem) [MSDOS]: use `fmod', not `drem'. Put in config.h?
Richard M. Stallman <rms@gnu.org>
parents:
4860
diff
changeset
|
38 #endif |
6d6d042b3df6
(Frem) [MSDOS]: use `fmod', not `drem'. Put in config.h?
Richard M. Stallman <rms@gnu.org>
parents:
4860
diff
changeset
|
39 |
298 | 40 #ifdef LISP_FLOAT_TYPE |
4860
ff23fe23f58c
[hpux 7] (_MAXLDBL, _NMAXLDBL): New macro definitions.
Richard M. Stallman <rms@gnu.org>
parents:
4780
diff
changeset
|
41 |
2781
fde05936aebb
* lread.c, data.c: If STDC_HEADERS is #defined, include <stdlib.h>
Jim Blandy <jimb@redhat.com>
parents:
2647
diff
changeset
|
42 #ifdef STDC_HEADERS |
fde05936aebb
* lread.c, data.c: If STDC_HEADERS is #defined, include <stdlib.h>
Jim Blandy <jimb@redhat.com>
parents:
2647
diff
changeset
|
43 #include <stdlib.h> |
fde05936aebb
* lread.c, data.c: If STDC_HEADERS is #defined, include <stdlib.h>
Jim Blandy <jimb@redhat.com>
parents:
2647
diff
changeset
|
44 #endif |
4860
ff23fe23f58c
[hpux 7] (_MAXLDBL, _NMAXLDBL): New macro definitions.
Richard M. Stallman <rms@gnu.org>
parents:
4780
diff
changeset
|
45 |
ff23fe23f58c
[hpux 7] (_MAXLDBL, _NMAXLDBL): New macro definitions.
Richard M. Stallman <rms@gnu.org>
parents:
4780
diff
changeset
|
46 /* Work around a problem that happens because math.h on hpux 7 |
ff23fe23f58c
[hpux 7] (_MAXLDBL, _NMAXLDBL): New macro definitions.
Richard M. Stallman <rms@gnu.org>
parents:
4780
diff
changeset
|
47 defines two static variables--which, in Emacs, are not really static, |
ff23fe23f58c
[hpux 7] (_MAXLDBL, _NMAXLDBL): New macro definitions.
Richard M. Stallman <rms@gnu.org>
parents:
4780
diff
changeset
|
48 because `static' is defined as nothing. The problem is that they are |
ff23fe23f58c
[hpux 7] (_MAXLDBL, _NMAXLDBL): New macro definitions.
Richard M. Stallman <rms@gnu.org>
parents:
4780
diff
changeset
|
49 here, in floatfns.c, and in lread.c. |
ff23fe23f58c
[hpux 7] (_MAXLDBL, _NMAXLDBL): New macro definitions.
Richard M. Stallman <rms@gnu.org>
parents:
4780
diff
changeset
|
50 These macros prevent the name conflict. */ |
ff23fe23f58c
[hpux 7] (_MAXLDBL, _NMAXLDBL): New macro definitions.
Richard M. Stallman <rms@gnu.org>
parents:
4780
diff
changeset
|
51 #if defined (HPUX) && !defined (HPUX8) |
ff23fe23f58c
[hpux 7] (_MAXLDBL, _NMAXLDBL): New macro definitions.
Richard M. Stallman <rms@gnu.org>
parents:
4780
diff
changeset
|
52 #define _MAXLDBL data_c_maxldbl |
ff23fe23f58c
[hpux 7] (_MAXLDBL, _NMAXLDBL): New macro definitions.
Richard M. Stallman <rms@gnu.org>
parents:
4780
diff
changeset
|
53 #define _NMAXLDBL data_c_nmaxldbl |
ff23fe23f58c
[hpux 7] (_MAXLDBL, _NMAXLDBL): New macro definitions.
Richard M. Stallman <rms@gnu.org>
parents:
4780
diff
changeset
|
54 #endif |
ff23fe23f58c
[hpux 7] (_MAXLDBL, _NMAXLDBL): New macro definitions.
Richard M. Stallman <rms@gnu.org>
parents:
4780
diff
changeset
|
55 |
298 | 56 #include <math.h> |
57 #endif /* LISP_FLOAT_TYPE */ | |
58 | |
4780
64cdff1c8ad1
Add declaration for atof if not predefined.
Brian Fox <bfox@gnu.org>
parents:
4696
diff
changeset
|
59 #if !defined (atof) |
64cdff1c8ad1
Add declaration for atof if not predefined.
Brian Fox <bfox@gnu.org>
parents:
4696
diff
changeset
|
60 extern double atof (); |
64cdff1c8ad1
Add declaration for atof if not predefined.
Brian Fox <bfox@gnu.org>
parents:
4696
diff
changeset
|
61 #endif /* !atof */ |
64cdff1c8ad1
Add declaration for atof if not predefined.
Brian Fox <bfox@gnu.org>
parents:
4696
diff
changeset
|
62 |
298 | 63 Lisp_Object Qnil, Qt, Qquote, Qlambda, Qsubr, Qunbound; |
64 Lisp_Object Qerror_conditions, Qerror_message, Qtop_level; | |
65 Lisp_Object Qerror, Qquit, Qwrong_type_argument, Qargs_out_of_range; | |
648 | 66 Lisp_Object Qvoid_variable, Qvoid_function, Qcyclic_function_indirection; |
298 | 67 Lisp_Object Qsetting_constant, Qinvalid_read_syntax; |
68 Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch; | |
4036 | 69 Lisp_Object Qend_of_file, Qarith_error, Qmark_inactive; |
298 | 70 Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only; |
6459
30fabcc03f0c
(Qwholenump): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6448
diff
changeset
|
71 Lisp_Object Qintegerp, Qnatnump, Qwholenump, Qsymbolp, Qlistp, Qconsp; |
298 | 72 Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp; |
73 Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp; | |
1293 | 74 Lisp_Object Qbuffer_or_string_p; |
298 | 75 Lisp_Object Qboundp, Qfboundp; |
76 Lisp_Object Qcdr; | |
8401
1eee41c8120c
(syms_of_data): Set up Qadvice_info, Qactivate_advice.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
77 Lisp_Object Qadvice_info, Qactivate_advice; |
298 | 78 |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
79 Lisp_Object Qrange_error, Qdomain_error, Qsingularity_error; |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
80 Lisp_Object Qoverflow_error, Qunderflow_error; |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
81 |
298 | 82 #ifdef LISP_FLOAT_TYPE |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
83 Lisp_Object Qfloatp; |
298 | 84 Lisp_Object Qnumberp, Qnumber_or_marker_p; |
85 #endif | |
86 | |
87 static Lisp_Object swap_in_symval_forwarding (); | |
88 | |
89 Lisp_Object | |
90 wrong_type_argument (predicate, value) | |
91 register Lisp_Object predicate, value; | |
92 { | |
93 register Lisp_Object tem; | |
94 do | |
95 { | |
96 if (!EQ (Vmocklisp_arguments, Qt)) | |
97 { | |
98 if (XTYPE (value) == Lisp_String && | |
99 (EQ (predicate, Qintegerp) || EQ (predicate, Qinteger_or_marker_p))) | |
1914
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
100 return Fstring_to_number (value); |
298 | 101 if (XTYPE (value) == Lisp_Int && EQ (predicate, Qstringp)) |
2429
96b55f2f19cd
Rename int-to-string to number-to-string, since it can handle
Jim Blandy <jimb@redhat.com>
parents:
2092
diff
changeset
|
102 return Fnumber_to_string (value); |
298 | 103 } |
104 value = Fsignal (Qwrong_type_argument, Fcons (predicate, Fcons (value, Qnil))); | |
105 tem = call1 (predicate, value); | |
106 } | |
490 | 107 while (NILP (tem)); |
298 | 108 return value; |
109 } | |
110 | |
111 pure_write_error () | |
112 { | |
113 error ("Attempt to modify read-only object"); | |
114 } | |
115 | |
116 void | |
117 args_out_of_range (a1, a2) | |
118 Lisp_Object a1, a2; | |
119 { | |
120 while (1) | |
121 Fsignal (Qargs_out_of_range, Fcons (a1, Fcons (a2, Qnil))); | |
122 } | |
123 | |
124 void | |
125 args_out_of_range_3 (a1, a2, a3) | |
126 Lisp_Object a1, a2, a3; | |
127 { | |
128 while (1) | |
129 Fsignal (Qargs_out_of_range, Fcons (a1, Fcons (a2, Fcons (a3, Qnil)))); | |
130 } | |
131 | |
132 Lisp_Object | |
133 make_number (num) | |
134 int num; | |
135 { | |
136 register Lisp_Object val; | |
137 XSET (val, Lisp_Int, num); | |
138 return val; | |
139 } | |
140 | |
141 /* On some machines, XINT needs a temporary location. | |
142 Here it is, in case it is needed. */ | |
143 | |
144 int sign_extend_temp; | |
145 | |
146 /* On a few machines, XINT can only be done by calling this. */ | |
147 | |
148 int | |
149 sign_extend_lisp_int (num) | |
150 int num; | |
151 { | |
152 if (num & (1 << (VALBITS - 1))) | |
153 return num | ((-1) << VALBITS); | |
154 else | |
155 return num & ((1 << VALBITS) - 1); | |
156 } | |
157 | |
158 /* Data type predicates */ | |
159 | |
160 DEFUN ("eq", Feq, Seq, 2, 2, 0, | |
161 "T if the two args are the same Lisp object.") | |
162 (obj1, obj2) | |
163 Lisp_Object obj1, obj2; | |
164 { | |
165 if (EQ (obj1, obj2)) | |
166 return Qt; | |
167 return Qnil; | |
168 } | |
169 | |
170 DEFUN ("null", Fnull, Snull, 1, 1, 0, "T if OBJECT is nil.") | |
171 (obj) | |
172 Lisp_Object obj; | |
173 { | |
490 | 174 if (NILP (obj)) |
298 | 175 return Qt; |
176 return Qnil; | |
177 } | |
178 | |
179 DEFUN ("consp", Fconsp, Sconsp, 1, 1, 0, "T if OBJECT is a cons cell.") | |
180 (obj) | |
181 Lisp_Object obj; | |
182 { | |
183 if (XTYPE (obj) == Lisp_Cons) | |
184 return Qt; | |
185 return Qnil; | |
186 } | |
187 | |
188 DEFUN ("atom", Fatom, Satom, 1, 1, 0, "T if OBJECT is not a cons cell. This includes nil.") | |
189 (obj) | |
190 Lisp_Object obj; | |
191 { | |
192 if (XTYPE (obj) == Lisp_Cons) | |
193 return Qnil; | |
194 return Qt; | |
195 } | |
196 | |
197 DEFUN ("listp", Flistp, Slistp, 1, 1, 0, "T if OBJECT is a list. This includes nil.") | |
198 (obj) | |
199 Lisp_Object obj; | |
200 { | |
490 | 201 if (XTYPE (obj) == Lisp_Cons || NILP (obj)) |
298 | 202 return Qt; |
203 return Qnil; | |
204 } | |
205 | |
206 DEFUN ("nlistp", Fnlistp, Snlistp, 1, 1, 0, "T if OBJECT is not a list. Lists include nil.") | |
207 (obj) | |
208 Lisp_Object obj; | |
209 { | |
490 | 210 if (XTYPE (obj) == Lisp_Cons || NILP (obj)) |
298 | 211 return Qnil; |
212 return Qt; | |
213 } | |
214 | |
215 DEFUN ("symbolp", Fsymbolp, Ssymbolp, 1, 1, 0, "T if OBJECT is a symbol.") | |
216 (obj) | |
217 Lisp_Object obj; | |
218 { | |
219 if (XTYPE (obj) == Lisp_Symbol) | |
220 return Qt; | |
221 return Qnil; | |
222 } | |
223 | |
224 DEFUN ("vectorp", Fvectorp, Svectorp, 1, 1, 0, "T if OBJECT is a vector.") | |
225 (obj) | |
226 Lisp_Object obj; | |
227 { | |
228 if (XTYPE (obj) == Lisp_Vector) | |
229 return Qt; | |
230 return Qnil; | |
231 } | |
232 | |
233 DEFUN ("stringp", Fstringp, Sstringp, 1, 1, 0, "T if OBJECT is a string.") | |
234 (obj) | |
235 Lisp_Object obj; | |
236 { | |
237 if (XTYPE (obj) == Lisp_String) | |
238 return Qt; | |
239 return Qnil; | |
240 } | |
241 | |
242 DEFUN ("arrayp", Farrayp, Sarrayp, 1, 1, 0, "T if OBJECT is an array (string or vector).") | |
243 (obj) | |
244 Lisp_Object obj; | |
245 { | |
246 if (XTYPE (obj) == Lisp_Vector || XTYPE (obj) == Lisp_String) | |
247 return Qt; | |
248 return Qnil; | |
249 } | |
250 | |
251 DEFUN ("sequencep", Fsequencep, Ssequencep, 1, 1, 0, | |
252 "T if OBJECT is a sequence (list or array).") | |
253 (obj) | |
254 register Lisp_Object obj; | |
255 { | |
490 | 256 if (CONSP (obj) || NILP (obj) || |
298 | 257 XTYPE (obj) == Lisp_Vector || XTYPE (obj) == Lisp_String) |
258 return Qt; | |
259 return Qnil; | |
260 } | |
261 | |
262 DEFUN ("bufferp", Fbufferp, Sbufferp, 1, 1, 0, "T if OBJECT is an editor buffer.") | |
263 (obj) | |
264 Lisp_Object obj; | |
265 { | |
266 if (XTYPE (obj) == Lisp_Buffer) | |
267 return Qt; | |
268 return Qnil; | |
269 } | |
270 | |
271 DEFUN ("markerp", Fmarkerp, Smarkerp, 1, 1, 0, "T if OBJECT is a marker (editor pointer).") | |
272 (obj) | |
273 Lisp_Object obj; | |
274 { | |
275 if (XTYPE (obj) == Lisp_Marker) | |
276 return Qt; | |
277 return Qnil; | |
278 } | |
279 | |
280 DEFUN ("subrp", Fsubrp, Ssubrp, 1, 1, 0, "T if OBJECT is a built-in function.") | |
281 (obj) | |
282 Lisp_Object obj; | |
283 { | |
284 if (XTYPE (obj) == Lisp_Subr) | |
285 return Qt; | |
286 return Qnil; | |
287 } | |
288 | |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1648
diff
changeset
|
289 DEFUN ("byte-code-function-p", Fbyte_code_function_p, Sbyte_code_function_p, |
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1648
diff
changeset
|
290 1, 1, 0, "T if OBJECT is a byte-compiled function object.") |
298 | 291 (obj) |
292 Lisp_Object obj; | |
293 { | |
294 if (XTYPE (obj) == Lisp_Compiled) | |
295 return Qt; | |
296 return Qnil; | |
297 } | |
298 | |
6385
e81e7c424e8a
(Fchar_or_string_p, Fintegerp, Fnatnump): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
6201
diff
changeset
|
299 DEFUN ("char-or-string-p", Fchar_or_string_p, Schar_or_string_p, 1, 1, 0, |
e81e7c424e8a
(Fchar_or_string_p, Fintegerp, Fnatnump): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
6201
diff
changeset
|
300 "T if OBJECT is a character (an integer) or a string.") |
298 | 301 (obj) |
302 register Lisp_Object obj; | |
303 { | |
304 if (XTYPE (obj) == Lisp_Int || XTYPE (obj) == Lisp_String) | |
305 return Qt; | |
306 return Qnil; | |
307 } | |
308 | |
6385
e81e7c424e8a
(Fchar_or_string_p, Fintegerp, Fnatnump): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
6201
diff
changeset
|
309 DEFUN ("integerp", Fintegerp, Sintegerp, 1, 1, 0, "T if OBJECT is an integer.") |
298 | 310 (obj) |
311 Lisp_Object obj; | |
312 { | |
313 if (XTYPE (obj) == Lisp_Int) | |
314 return Qt; | |
315 return Qnil; | |
316 } | |
317 | |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
318 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, Sinteger_or_marker_p, 1, 1, 0, |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
319 "T if OBJECT is an integer or a marker (editor pointer).") |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
320 (obj) |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
321 register Lisp_Object obj; |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
322 { |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
323 if (XTYPE (obj) == Lisp_Marker || XTYPE (obj) == Lisp_Int) |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
324 return Qt; |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
325 return Qnil; |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
326 } |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
327 |
6385
e81e7c424e8a
(Fchar_or_string_p, Fintegerp, Fnatnump): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
6201
diff
changeset
|
328 DEFUN ("natnump", Fnatnump, Snatnump, 1, 1, 0, |
e81e7c424e8a
(Fchar_or_string_p, Fintegerp, Fnatnump): Doc fix.
Karl Heuer <kwzh@gnu.org>
parents:
6201
diff
changeset
|
329 "T if OBJECT is a nonnegative integer.") |
298 | 330 (obj) |
331 Lisp_Object obj; | |
332 { | |
333 if (XTYPE (obj) == Lisp_Int && XINT (obj) >= 0) | |
334 return Qt; | |
335 return Qnil; | |
336 } | |
337 | |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
338 DEFUN ("numberp", Fnumberp, Snumberp, 1, 1, 0, |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
339 "T if OBJECT is a number (floating point or integer).") |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
340 (obj) |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
341 Lisp_Object obj; |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
342 { |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1648
diff
changeset
|
343 if (NUMBERP (obj)) |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
344 return Qt; |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1648
diff
changeset
|
345 else |
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1648
diff
changeset
|
346 return Qnil; |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
347 } |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
348 |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
349 DEFUN ("number-or-marker-p", Fnumber_or_marker_p, |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
350 Snumber_or_marker_p, 1, 1, 0, |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
351 "T if OBJECT is a number or a marker.") |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
352 (obj) |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
353 Lisp_Object obj; |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
354 { |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1648
diff
changeset
|
355 if (NUMBERP (obj) |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
356 || XTYPE (obj) == Lisp_Marker) |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
357 return Qt; |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
358 return Qnil; |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
359 } |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
360 |
298 | 361 #ifdef LISP_FLOAT_TYPE |
362 DEFUN ("floatp", Ffloatp, Sfloatp, 1, 1, 0, | |
363 "T if OBJECT is a floating point number.") | |
364 (obj) | |
365 Lisp_Object obj; | |
366 { | |
367 if (XTYPE (obj) == Lisp_Float) | |
368 return Qt; | |
369 return Qnil; | |
370 } | |
371 #endif /* LISP_FLOAT_TYPE */ | |
372 | |
373 /* Extract and set components of lists */ | |
374 | |
375 DEFUN ("car", Fcar, Scar, 1, 1, 0, | |
376 "Return the car of CONSCELL. If arg is nil, return nil.\n\ | |
377 Error if arg is not nil and not a cons cell. See also `car-safe'.") | |
378 (list) | |
379 register Lisp_Object list; | |
380 { | |
381 while (1) | |
382 { | |
383 if (XTYPE (list) == Lisp_Cons) | |
384 return XCONS (list)->car; | |
385 else if (EQ (list, Qnil)) | |
386 return Qnil; | |
387 else | |
388 list = wrong_type_argument (Qlistp, list); | |
389 } | |
390 } | |
391 | |
392 DEFUN ("car-safe", Fcar_safe, Scar_safe, 1, 1, 0, | |
393 "Return the car of OBJECT if it is a cons cell, or else nil.") | |
394 (object) | |
395 Lisp_Object object; | |
396 { | |
397 if (XTYPE (object) == Lisp_Cons) | |
398 return XCONS (object)->car; | |
399 else | |
400 return Qnil; | |
401 } | |
402 | |
403 DEFUN ("cdr", Fcdr, Scdr, 1, 1, 0, | |
404 "Return the cdr of CONSCELL. If arg is nil, return nil.\n\ | |
405 Error if arg is not nil and not a cons cell. See also `cdr-safe'.") | |
406 | |
407 (list) | |
408 register Lisp_Object list; | |
409 { | |
410 while (1) | |
411 { | |
412 if (XTYPE (list) == Lisp_Cons) | |
413 return XCONS (list)->cdr; | |
414 else if (EQ (list, Qnil)) | |
415 return Qnil; | |
416 else | |
417 list = wrong_type_argument (Qlistp, list); | |
418 } | |
419 } | |
420 | |
421 DEFUN ("cdr-safe", Fcdr_safe, Scdr_safe, 1, 1, 0, | |
422 "Return the cdr of OBJECT if it is a cons cell, or else nil.") | |
423 (object) | |
424 Lisp_Object object; | |
425 { | |
426 if (XTYPE (object) == Lisp_Cons) | |
427 return XCONS (object)->cdr; | |
428 else | |
429 return Qnil; | |
430 } | |
431 | |
432 DEFUN ("setcar", Fsetcar, Ssetcar, 2, 2, 0, | |
433 "Set the car of CONSCELL to be NEWCAR. Returns NEWCAR.") | |
434 (cell, newcar) | |
435 register Lisp_Object cell, newcar; | |
436 { | |
437 if (XTYPE (cell) != Lisp_Cons) | |
438 cell = wrong_type_argument (Qconsp, cell); | |
439 | |
440 CHECK_IMPURE (cell); | |
441 XCONS (cell)->car = newcar; | |
442 return newcar; | |
443 } | |
444 | |
445 DEFUN ("setcdr", Fsetcdr, Ssetcdr, 2, 2, 0, | |
446 "Set the cdr of CONSCELL to be NEWCDR. Returns NEWCDR.") | |
447 (cell, newcdr) | |
448 register Lisp_Object cell, newcdr; | |
449 { | |
450 if (XTYPE (cell) != Lisp_Cons) | |
451 cell = wrong_type_argument (Qconsp, cell); | |
452 | |
453 CHECK_IMPURE (cell); | |
454 XCONS (cell)->cdr = newcdr; | |
455 return newcdr; | |
456 } | |
457 | |
458 /* Extract and set components of symbols */ | |
459 | |
460 DEFUN ("boundp", Fboundp, Sboundp, 1, 1, 0, "T if SYMBOL's value is not void.") | |
461 (sym) | |
462 register Lisp_Object sym; | |
463 { | |
464 Lisp_Object valcontents; | |
465 CHECK_SYMBOL (sym, 0); | |
466 | |
467 valcontents = XSYMBOL (sym)->value; | |
468 | |
469 #ifdef SWITCH_ENUM_BUG | |
470 switch ((int) XTYPE (valcontents)) | |
471 #else | |
472 switch (XTYPE (valcontents)) | |
473 #endif | |
474 { | |
475 case Lisp_Buffer_Local_Value: | |
476 case Lisp_Some_Buffer_Local_Value: | |
477 valcontents = swap_in_symval_forwarding (sym, valcontents); | |
478 } | |
479 | |
480 return (XTYPE (valcontents) == Lisp_Void || EQ (valcontents, Qunbound) | |
481 ? Qnil : Qt); | |
482 } | |
483 | |
484 DEFUN ("fboundp", Ffboundp, Sfboundp, 1, 1, 0, "T if SYMBOL's function definition is not void.") | |
485 (sym) | |
486 register Lisp_Object sym; | |
487 { | |
488 CHECK_SYMBOL (sym, 0); | |
489 return (XTYPE (XSYMBOL (sym)->function) == Lisp_Void | |
490 || EQ (XSYMBOL (sym)->function, Qunbound)) | |
491 ? Qnil : Qt; | |
492 } | |
493 | |
494 DEFUN ("makunbound", Fmakunbound, Smakunbound, 1, 1, 0, "Make SYMBOL's value be void.") | |
495 (sym) | |
496 register Lisp_Object sym; | |
497 { | |
498 CHECK_SYMBOL (sym, 0); | |
490 | 499 if (NILP (sym) || EQ (sym, Qt)) |
298 | 500 return Fsignal (Qsetting_constant, Fcons (sym, Qnil)); |
501 Fset (sym, Qunbound); | |
502 return sym; | |
503 } | |
504 | |
505 DEFUN ("fmakunbound", Ffmakunbound, Sfmakunbound, 1, 1, 0, "Make SYMBOL's function definition be void.") | |
506 (sym) | |
507 register Lisp_Object sym; | |
508 { | |
509 CHECK_SYMBOL (sym, 0); | |
7206
b6aa3d718d8a
(Ffset, Ffmakunbound): Signal an error if SYM is nil or t.
Karl Heuer <kwzh@gnu.org>
parents:
7205
diff
changeset
|
510 if (NILP (sym) || EQ (sym, Qt)) |
b6aa3d718d8a
(Ffset, Ffmakunbound): Signal an error if SYM is nil or t.
Karl Heuer <kwzh@gnu.org>
parents:
7205
diff
changeset
|
511 return Fsignal (Qsetting_constant, Fcons (sym, Qnil)); |
298 | 512 XSYMBOL (sym)->function = Qunbound; |
513 return sym; | |
514 } | |
515 | |
516 DEFUN ("symbol-function", Fsymbol_function, Ssymbol_function, 1, 1, 0, | |
517 "Return SYMBOL's function definition. Error if that is void.") | |
648 | 518 (symbol) |
519 register Lisp_Object symbol; | |
298 | 520 { |
648 | 521 CHECK_SYMBOL (symbol, 0); |
522 if (EQ (XSYMBOL (symbol)->function, Qunbound)) | |
523 return Fsignal (Qvoid_function, Fcons (symbol, Qnil)); | |
524 return XSYMBOL (symbol)->function; | |
298 | 525 } |
526 | |
527 DEFUN ("symbol-plist", Fsymbol_plist, Ssymbol_plist, 1, 1, 0, "Return SYMBOL's property list.") | |
528 (sym) | |
529 register Lisp_Object sym; | |
530 { | |
531 CHECK_SYMBOL (sym, 0); | |
532 return XSYMBOL (sym)->plist; | |
533 } | |
534 | |
535 DEFUN ("symbol-name", Fsymbol_name, Ssymbol_name, 1, 1, 0, "Return SYMBOL's name, a string.") | |
536 (sym) | |
537 register Lisp_Object sym; | |
538 { | |
539 register Lisp_Object name; | |
540 | |
541 CHECK_SYMBOL (sym, 0); | |
542 XSET (name, Lisp_String, XSYMBOL (sym)->name); | |
543 return name; | |
544 } | |
545 | |
546 DEFUN ("fset", Ffset, Sfset, 2, 2, 0, | |
547 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.") | |
548 (sym, newdef) | |
549 register Lisp_Object sym, newdef; | |
550 { | |
551 CHECK_SYMBOL (sym, 0); | |
7206
b6aa3d718d8a
(Ffset, Ffmakunbound): Signal an error if SYM is nil or t.
Karl Heuer <kwzh@gnu.org>
parents:
7205
diff
changeset
|
552 if (NILP (sym) || EQ (sym, Qt)) |
b6aa3d718d8a
(Ffset, Ffmakunbound): Signal an error if SYM is nil or t.
Karl Heuer <kwzh@gnu.org>
parents:
7205
diff
changeset
|
553 return Fsignal (Qsetting_constant, Fcons (sym, Qnil)); |
490 | 554 if (!NILP (Vautoload_queue) && !EQ (XSYMBOL (sym)->function, Qunbound)) |
298 | 555 Vautoload_queue = Fcons (Fcons (sym, XSYMBOL (sym)->function), |
556 Vautoload_queue); | |
557 XSYMBOL (sym)->function = newdef; | |
8401
1eee41c8120c
(syms_of_data): Set up Qadvice_info, Qactivate_advice.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
558 /* Handle automatic advice activation */ |
8415
ec05bbe4ef1c
(Ffset): Don't call Fget unless SYM's plist is consp.
Roland McGrath <roland@gnu.org>
parents:
8401
diff
changeset
|
559 if (CONSP (XSYMBOL (sym)->plist) && !NILP (Fget (sym, Qadvice_info))) |
8401
1eee41c8120c
(syms_of_data): Set up Qadvice_info, Qactivate_advice.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
560 { |
1eee41c8120c
(syms_of_data): Set up Qadvice_info, Qactivate_advice.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
561 call2 (Qactivate_advice, sym, Fbyte_code_function_p (newdef)); |
1eee41c8120c
(syms_of_data): Set up Qadvice_info, Qactivate_advice.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
562 newdef = XSYMBOL (sym)->function; |
1eee41c8120c
(syms_of_data): Set up Qadvice_info, Qactivate_advice.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
563 } |
298 | 564 return newdef; |
565 } | |
566 | |
2606
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
567 /* This name should be removed once it is eliminated from elsewhere. */ |
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
568 |
2565
c1a1557bffde
(Fdefine_function): Changed name back to Fdefalias, so we get things
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2548
diff
changeset
|
569 DEFUN ("defalias", Fdefalias, Sdefalias, 2, 2, 0, |
2548
b66eeded6afc
(Fdefine_function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2515
diff
changeset
|
570 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.\n\ |
b66eeded6afc
(Fdefine_function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2515
diff
changeset
|
571 Associates the function with the current load file, if any.") |
b66eeded6afc
(Fdefine_function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2515
diff
changeset
|
572 (sym, newdef) |
b66eeded6afc
(Fdefine_function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2515
diff
changeset
|
573 register Lisp_Object sym, newdef; |
b66eeded6afc
(Fdefine_function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2515
diff
changeset
|
574 { |
b66eeded6afc
(Fdefine_function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2515
diff
changeset
|
575 CHECK_SYMBOL (sym, 0); |
b66eeded6afc
(Fdefine_function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2515
diff
changeset
|
576 if (!NILP (Vautoload_queue) && !EQ (XSYMBOL (sym)->function, Qunbound)) |
b66eeded6afc
(Fdefine_function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2515
diff
changeset
|
577 Vautoload_queue = Fcons (Fcons (sym, XSYMBOL (sym)->function), |
b66eeded6afc
(Fdefine_function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2515
diff
changeset
|
578 Vautoload_queue); |
b66eeded6afc
(Fdefine_function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2515
diff
changeset
|
579 XSYMBOL (sym)->function = newdef; |
b66eeded6afc
(Fdefine_function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2515
diff
changeset
|
580 LOADHIST_ATTACH (sym); |
b66eeded6afc
(Fdefine_function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2515
diff
changeset
|
581 return newdef; |
b66eeded6afc
(Fdefine_function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2515
diff
changeset
|
582 } |
b66eeded6afc
(Fdefine_function): New function.
Richard M. Stallman <rms@gnu.org>
parents:
2515
diff
changeset
|
583 |
2606
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
584 DEFUN ("define-function", Fdefine_function, Sdefine_function, 2, 2, 0, |
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
585 "Set SYMBOL's function definition to NEWVAL, and return NEWVAL.\n\ |
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
586 Associates the function with the current load file, if any.") |
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
587 (sym, newdef) |
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
588 register Lisp_Object sym, newdef; |
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
589 { |
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
590 CHECK_SYMBOL (sym, 0); |
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
591 if (!NILP (Vautoload_queue) && !EQ (XSYMBOL (sym)->function, Qunbound)) |
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
592 Vautoload_queue = Fcons (Fcons (sym, XSYMBOL (sym)->function), |
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
593 Vautoload_queue); |
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
594 XSYMBOL (sym)->function = newdef; |
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
595 LOADHIST_ATTACH (sym); |
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
596 return newdef; |
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
597 } |
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
598 |
298 | 599 DEFUN ("setplist", Fsetplist, Ssetplist, 2, 2, 0, |
600 "Set SYMBOL's property list to NEWVAL, and return NEWVAL.") | |
601 (sym, newplist) | |
602 register Lisp_Object sym, newplist; | |
603 { | |
604 CHECK_SYMBOL (sym, 0); | |
605 XSYMBOL (sym)->plist = newplist; | |
606 return newplist; | |
607 } | |
648 | 608 |
298 | 609 |
610 /* Getting and setting values of symbols */ | |
611 | |
612 /* Given the raw contents of a symbol value cell, | |
613 return the Lisp value of the symbol. | |
614 This does not handle buffer-local variables; use | |
615 swap_in_symval_forwarding for that. */ | |
616 | |
617 Lisp_Object | |
618 do_symval_forwarding (valcontents) | |
619 register Lisp_Object valcontents; | |
620 { | |
621 register Lisp_Object val; | |
622 #ifdef SWITCH_ENUM_BUG | |
623 switch ((int) XTYPE (valcontents)) | |
624 #else | |
625 switch (XTYPE (valcontents)) | |
626 #endif | |
627 { | |
628 case Lisp_Intfwd: | |
629 XSET (val, Lisp_Int, *XINTPTR (valcontents)); | |
630 return val; | |
631 | |
632 case Lisp_Boolfwd: | |
633 if (*XINTPTR (valcontents)) | |
634 return Qt; | |
635 return Qnil; | |
636 | |
637 case Lisp_Objfwd: | |
638 return *XOBJFWD (valcontents); | |
639 | |
640 case Lisp_Buffer_Objfwd: | |
641 return *(Lisp_Object *)(XUINT (valcontents) + (char *)current_buffer); | |
642 } | |
643 return valcontents; | |
644 } | |
645 | |
646 /* Store NEWVAL into SYM, where VALCONTENTS is found in the value cell | |
647 of SYM. If SYM is buffer-local, VALCONTENTS should be the | |
648 buffer-independent contents of the value cell: forwarded just one | |
649 step past the buffer-localness. */ | |
650 | |
651 void | |
652 store_symval_forwarding (sym, valcontents, newval) | |
653 Lisp_Object sym; | |
654 register Lisp_Object valcontents, newval; | |
655 { | |
656 #ifdef SWITCH_ENUM_BUG | |
657 switch ((int) XTYPE (valcontents)) | |
658 #else | |
659 switch (XTYPE (valcontents)) | |
660 #endif | |
661 { | |
662 case Lisp_Intfwd: | |
663 CHECK_NUMBER (newval, 1); | |
664 *XINTPTR (valcontents) = XINT (newval); | |
665 break; | |
666 | |
667 case Lisp_Boolfwd: | |
490 | 668 *XINTPTR (valcontents) = NILP(newval) ? 0 : 1; |
298 | 669 break; |
670 | |
671 case Lisp_Objfwd: | |
672 *XOBJFWD (valcontents) = newval; | |
673 break; | |
674 | |
675 case Lisp_Buffer_Objfwd: | |
1002
65f15f1961d8
* data.c [USG] (Frem): Call fmod, rather than drem. Rah.
Jim Blandy <jimb@redhat.com>
parents:
733
diff
changeset
|
676 { |
65f15f1961d8
* data.c [USG] (Frem): Call fmod, rather than drem. Rah.
Jim Blandy <jimb@redhat.com>
parents:
733
diff
changeset
|
677 unsigned int offset = XUINT (valcontents); |
6497
89ff61b53cee
(store_symval_forwarding, Fsymbol_value): Use assignment, not initialization.
Karl Heuer <kwzh@gnu.org>
parents:
6459
diff
changeset
|
678 Lisp_Object type; |
1002
65f15f1961d8
* data.c [USG] (Frem): Call fmod, rather than drem. Rah.
Jim Blandy <jimb@redhat.com>
parents:
733
diff
changeset
|
679 |
6497
89ff61b53cee
(store_symval_forwarding, Fsymbol_value): Use assignment, not initialization.
Karl Heuer <kwzh@gnu.org>
parents:
6459
diff
changeset
|
680 type = *(Lisp_Object *)(offset + (char *)&buffer_local_types); |
1002
65f15f1961d8
* data.c [USG] (Frem): Call fmod, rather than drem. Rah.
Jim Blandy <jimb@redhat.com>
parents:
733
diff
changeset
|
681 if (! NILP (type) && ! NILP (newval) |
65f15f1961d8
* data.c [USG] (Frem): Call fmod, rather than drem. Rah.
Jim Blandy <jimb@redhat.com>
parents:
733
diff
changeset
|
682 && XTYPE (newval) != XINT (type)) |
65f15f1961d8
* data.c [USG] (Frem): Call fmod, rather than drem. Rah.
Jim Blandy <jimb@redhat.com>
parents:
733
diff
changeset
|
683 buffer_slot_type_mismatch (valcontents, newval); |
65f15f1961d8
* data.c [USG] (Frem): Call fmod, rather than drem. Rah.
Jim Blandy <jimb@redhat.com>
parents:
733
diff
changeset
|
684 |
65f15f1961d8
* data.c [USG] (Frem): Call fmod, rather than drem. Rah.
Jim Blandy <jimb@redhat.com>
parents:
733
diff
changeset
|
685 *(Lisp_Object *)(XUINT (valcontents) + (char *)current_buffer) |
65f15f1961d8
* data.c [USG] (Frem): Call fmod, rather than drem. Rah.
Jim Blandy <jimb@redhat.com>
parents:
733
diff
changeset
|
686 = newval; |
65f15f1961d8
* data.c [USG] (Frem): Call fmod, rather than drem. Rah.
Jim Blandy <jimb@redhat.com>
parents:
733
diff
changeset
|
687 break; |
65f15f1961d8
* data.c [USG] (Frem): Call fmod, rather than drem. Rah.
Jim Blandy <jimb@redhat.com>
parents:
733
diff
changeset
|
688 } |
298 | 689 |
690 default: | |
691 valcontents = XSYMBOL (sym)->value; | |
692 if (XTYPE (valcontents) == Lisp_Buffer_Local_Value | |
693 || XTYPE (valcontents) == Lisp_Some_Buffer_Local_Value) | |
694 XCONS (XSYMBOL (sym)->value)->car = newval; | |
695 else | |
696 XSYMBOL (sym)->value = newval; | |
697 } | |
698 } | |
699 | |
700 /* Set up the buffer-local symbol SYM for validity in the current | |
701 buffer. VALCONTENTS is the contents of its value cell. | |
702 Return the value forwarded one step past the buffer-local indicator. */ | |
703 | |
704 static Lisp_Object | |
705 swap_in_symval_forwarding (sym, valcontents) | |
706 Lisp_Object sym, valcontents; | |
707 { | |
708 /* valcontents is a list | |
709 (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE)). | |
710 | |
711 CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's | |
1263
3790dfbefb30
* data.c (swap_in_symval_forwarding): Formatting tweaked.
Jim Blandy <jimb@redhat.com>
parents:
1253
diff
changeset
|
712 local_var_alist, that being the element whose car is this |
3790dfbefb30
* data.c (swap_in_symval_forwarding): Formatting tweaked.
Jim Blandy <jimb@redhat.com>
parents:
1253
diff
changeset
|
713 variable. Or it can be a pointer to the |
3790dfbefb30
* data.c (swap_in_symval_forwarding): Formatting tweaked.
Jim Blandy <jimb@redhat.com>
parents:
1253
diff
changeset
|
714 (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER does not have |
3790dfbefb30
* data.c (swap_in_symval_forwarding): Formatting tweaked.
Jim Blandy <jimb@redhat.com>
parents:
1253
diff
changeset
|
715 an element in its alist for this variable. |
3790dfbefb30
* data.c (swap_in_symval_forwarding): Formatting tweaked.
Jim Blandy <jimb@redhat.com>
parents:
1253
diff
changeset
|
716 |
3790dfbefb30
* data.c (swap_in_symval_forwarding): Formatting tweaked.
Jim Blandy <jimb@redhat.com>
parents:
1253
diff
changeset
|
717 If the current buffer is not BUFFER, we store the current |
3790dfbefb30
* data.c (swap_in_symval_forwarding): Formatting tweaked.
Jim Blandy <jimb@redhat.com>
parents:
1253
diff
changeset
|
718 REALVALUE value into CURRENT-ALIST-ELEMENT, then find the |
3790dfbefb30
* data.c (swap_in_symval_forwarding): Formatting tweaked.
Jim Blandy <jimb@redhat.com>
parents:
1253
diff
changeset
|
719 appropriate alist element for the buffer now current and set up |
3790dfbefb30
* data.c (swap_in_symval_forwarding): Formatting tweaked.
Jim Blandy <jimb@redhat.com>
parents:
1253
diff
changeset
|
720 CURRENT-ALIST-ELEMENT. Then we set REALVALUE out of that |
3790dfbefb30
* data.c (swap_in_symval_forwarding): Formatting tweaked.
Jim Blandy <jimb@redhat.com>
parents:
1253
diff
changeset
|
721 element, and store into BUFFER. |
3790dfbefb30
* data.c (swap_in_symval_forwarding): Formatting tweaked.
Jim Blandy <jimb@redhat.com>
parents:
1253
diff
changeset
|
722 |
298 | 723 Note that REALVALUE can be a forwarding pointer. */ |
724 | |
725 register Lisp_Object tem1; | |
726 tem1 = XCONS (XCONS (valcontents)->cdr)->car; | |
727 | |
490 | 728 if (NILP (tem1) || current_buffer != XBUFFER (tem1)) |
298 | 729 { |
730 tem1 = XCONS (XCONS (XCONS (valcontents)->cdr)->cdr)->car; | |
731 Fsetcdr (tem1, do_symval_forwarding (XCONS (valcontents)->car)); | |
732 tem1 = assq_no_quit (sym, current_buffer->local_var_alist); | |
490 | 733 if (NILP (tem1)) |
298 | 734 tem1 = XCONS (XCONS (valcontents)->cdr)->cdr; |
735 XCONS (XCONS (XCONS (valcontents)->cdr)->cdr)->car = tem1; | |
736 XSET (XCONS (XCONS (valcontents)->cdr)->car, Lisp_Buffer, current_buffer); | |
737 store_symval_forwarding (sym, XCONS (valcontents)->car, Fcdr (tem1)); | |
738 } | |
739 return XCONS (valcontents)->car; | |
740 } | |
741 | |
514 | 742 /* Find the value of a symbol, returning Qunbound if it's not bound. |
743 This is helpful for code which just wants to get a variable's value | |
744 if it has one, without signalling an error. | |
745 Note that it must not be possible to quit | |
746 within this function. Great care is required for this. */ | |
298 | 747 |
514 | 748 Lisp_Object |
749 find_symbol_value (sym) | |
298 | 750 Lisp_Object sym; |
751 { | |
752 register Lisp_Object valcontents, tem1; | |
753 register Lisp_Object val; | |
754 CHECK_SYMBOL (sym, 0); | |
755 valcontents = XSYMBOL (sym)->value; | |
756 | |
757 retry: | |
758 #ifdef SWITCH_ENUM_BUG | |
759 switch ((int) XTYPE (valcontents)) | |
760 #else | |
761 switch (XTYPE (valcontents)) | |
762 #endif | |
763 { | |
764 case Lisp_Buffer_Local_Value: | |
765 case Lisp_Some_Buffer_Local_Value: | |
766 valcontents = swap_in_symval_forwarding (sym, valcontents); | |
767 goto retry; | |
768 | |
769 case Lisp_Intfwd: | |
770 XSET (val, Lisp_Int, *XINTPTR (valcontents)); | |
771 return val; | |
772 | |
773 case Lisp_Boolfwd: | |
774 if (*XINTPTR (valcontents)) | |
775 return Qt; | |
776 return Qnil; | |
777 | |
778 case Lisp_Objfwd: | |
779 return *XOBJFWD (valcontents); | |
780 | |
781 case Lisp_Buffer_Objfwd: | |
782 return *(Lisp_Object *)(XUINT (valcontents) + (char *)current_buffer); | |
783 | |
784 case Lisp_Void: | |
514 | 785 return Qunbound; |
298 | 786 } |
787 | |
788 return valcontents; | |
789 } | |
790 | |
514 | 791 DEFUN ("symbol-value", Fsymbol_value, Ssymbol_value, 1, 1, 0, |
792 "Return SYMBOL's value. Error if that is void.") | |
793 (sym) | |
794 Lisp_Object sym; | |
795 { | |
6497
89ff61b53cee
(store_symval_forwarding, Fsymbol_value): Use assignment, not initialization.
Karl Heuer <kwzh@gnu.org>
parents:
6459
diff
changeset
|
796 Lisp_Object val; |
514 | 797 |
6497
89ff61b53cee
(store_symval_forwarding, Fsymbol_value): Use assignment, not initialization.
Karl Heuer <kwzh@gnu.org>
parents:
6459
diff
changeset
|
798 val = find_symbol_value (sym); |
514 | 799 if (EQ (val, Qunbound)) |
800 return Fsignal (Qvoid_variable, Fcons (sym, Qnil)); | |
801 else | |
802 return val; | |
803 } | |
804 | |
298 | 805 DEFUN ("set", Fset, Sset, 2, 2, 0, |
806 "Set SYMBOL's value to NEWVAL, and return NEWVAL.") | |
807 (sym, newval) | |
808 register Lisp_Object sym, newval; | |
809 { | |
810 int voide = (XTYPE (newval) == Lisp_Void || EQ (newval, Qunbound)); | |
811 | |
812 #ifndef RTPC_REGISTER_BUG | |
813 register Lisp_Object valcontents, tem1, current_alist_element; | |
814 #else /* RTPC_REGISTER_BUG */ | |
815 register Lisp_Object tem1; | |
816 Lisp_Object valcontents, current_alist_element; | |
817 #endif /* RTPC_REGISTER_BUG */ | |
818 | |
819 CHECK_SYMBOL (sym, 0); | |
490 | 820 if (NILP (sym) || EQ (sym, Qt)) |
298 | 821 return Fsignal (Qsetting_constant, Fcons (sym, Qnil)); |
822 valcontents = XSYMBOL (sym)->value; | |
823 | |
824 if (XTYPE (valcontents) == Lisp_Buffer_Objfwd) | |
825 { | |
826 register int idx = XUINT (valcontents); | |
827 register int mask = *(int *)(idx + (char *) &buffer_local_flags); | |
828 if (mask > 0) | |
829 current_buffer->local_var_flags |= mask; | |
830 } | |
831 | |
733 | 832 else if (XTYPE (valcontents) == Lisp_Buffer_Local_Value |
833 || XTYPE (valcontents) == Lisp_Some_Buffer_Local_Value) | |
298 | 834 { |
733 | 835 /* valcontents is actually a pointer to a cons heading something like: |
836 (REALVALUE BUFFER CURRENT-ALIST-ELEMENT . DEFAULT-VALUE). | |
837 | |
838 BUFFER is the last buffer for which this symbol's value was | |
839 made up to date. | |
298 | 840 |
733 | 841 CURRENT-ALIST-ELEMENT is a pointer to an element of BUFFER's |
842 local_var_alist, that being the element whose car is this | |
843 variable. Or it can be a pointer to the | |
844 (CURRENT-ALIST-ELEMENT . DEFAULT-VALUE), if BUFFER does not | |
845 have an element in its alist for this variable (that is, if | |
846 BUFFER sees the default value of this variable). | |
847 | |
848 If we want to examine or set the value and BUFFER is current, | |
849 we just examine or set REALVALUE. If BUFFER is not current, we | |
850 store the current REALVALUE value into CURRENT-ALIST-ELEMENT, | |
851 then find the appropriate alist element for the buffer now | |
852 current and set up CURRENT-ALIST-ELEMENT. Then we set | |
853 REALVALUE out of that element, and store into BUFFER. | |
298 | 854 |
733 | 855 If we are setting the variable and the current buffer does |
856 not have an alist entry for this variable, an alist entry is | |
857 created. | |
858 | |
859 Note that REALVALUE can be a forwarding pointer. Each time | |
860 it is examined or set, forwarding must be done. */ | |
861 | |
862 /* What value are we caching right now? */ | |
863 current_alist_element = | |
864 XCONS (XCONS (XCONS (valcontents)->cdr)->cdr)->car; | |
298 | 865 |
733 | 866 /* If the current buffer is not the buffer whose binding is |
867 currently cached, or if it's a Lisp_Buffer_Local_Value and | |
868 we're looking at the default value, the cache is invalid; we | |
869 need to write it out, and find the new CURRENT-ALIST-ELEMENT. */ | |
870 if ((current_buffer | |
871 != XBUFFER (XCONS (XCONS (valcontents)->cdr)->car)) | |
872 || (XTYPE (valcontents) == Lisp_Buffer_Local_Value | |
1508
768d4c10c2bf
* data.c (Fset): See if current_alist_element points to itself
Jim Blandy <jimb@redhat.com>
parents:
1293
diff
changeset
|
873 && EQ (XCONS (current_alist_element)->car, |
768d4c10c2bf
* data.c (Fset): See if current_alist_element points to itself
Jim Blandy <jimb@redhat.com>
parents:
1293
diff
changeset
|
874 current_alist_element))) |
298 | 875 { |
733 | 876 /* Write out the cached value for the old buffer; copy it |
877 back to its alist element. This works if the current | |
878 buffer only sees the default value, too. */ | |
879 Fsetcdr (current_alist_element, | |
880 do_symval_forwarding (XCONS (valcontents)->car)); | |
298 | 881 |
733 | 882 /* Find the new value for CURRENT-ALIST-ELEMENT. */ |
298 | 883 tem1 = Fassq (sym, current_buffer->local_var_alist); |
490 | 884 if (NILP (tem1)) |
733 | 885 { |
886 /* This buffer still sees the default value. */ | |
887 | |
888 /* If the variable is a Lisp_Some_Buffer_Local_Value, | |
889 make CURRENT-ALIST-ELEMENT point to itself, | |
890 indicating that we're seeing the default value. */ | |
891 if (XTYPE (valcontents) == Lisp_Some_Buffer_Local_Value) | |
892 tem1 = XCONS (XCONS (valcontents)->cdr)->cdr; | |
893 | |
894 /* If it's a Lisp_Buffer_Local_Value, give this buffer a | |
895 new assoc for a local value and set | |
896 CURRENT-ALIST-ELEMENT to point to that. */ | |
897 else | |
898 { | |
899 tem1 = Fcons (sym, Fcdr (current_alist_element)); | |
900 current_buffer->local_var_alist = | |
901 Fcons (tem1, current_buffer->local_var_alist); | |
902 } | |
903 } | |
904 /* Cache the new buffer's assoc in CURRENT-ALIST-ELEMENT. */ | |
298 | 905 XCONS (XCONS (XCONS (valcontents)->cdr)->cdr)->car = tem1; |
733 | 906 |
907 /* Set BUFFER, now that CURRENT-ALIST-ELEMENT is accurate. */ | |
908 XSET (XCONS (XCONS (valcontents)->cdr)->car, | |
909 Lisp_Buffer, current_buffer); | |
298 | 910 } |
911 valcontents = XCONS (valcontents)->car; | |
912 } | |
733 | 913 |
298 | 914 /* If storing void (making the symbol void), forward only through |
915 buffer-local indicator, not through Lisp_Objfwd, etc. */ | |
916 if (voide) | |
917 store_symval_forwarding (sym, Qnil, newval); | |
918 else | |
919 store_symval_forwarding (sym, valcontents, newval); | |
733 | 920 |
298 | 921 return newval; |
922 } | |
923 | |
924 /* Access or set a buffer-local symbol's default value. */ | |
925 | |
926 /* Return the default value of SYM, but don't check for voidness. | |
927 Return Qunbound or a Lisp_Void object if it is void. */ | |
928 | |
929 Lisp_Object | |
930 default_value (sym) | |
931 Lisp_Object sym; | |
932 { | |
933 register Lisp_Object valcontents; | |
934 | |
935 CHECK_SYMBOL (sym, 0); | |
936 valcontents = XSYMBOL (sym)->value; | |
937 | |
938 /* For a built-in buffer-local variable, get the default value | |
939 rather than letting do_symval_forwarding get the current value. */ | |
940 if (XTYPE (valcontents) == Lisp_Buffer_Objfwd) | |
941 { | |
942 register int idx = XUINT (valcontents); | |
943 | |
944 if (*(int *) (idx + (char *) &buffer_local_flags) != 0) | |
945 return *(Lisp_Object *)(idx + (char *) &buffer_defaults); | |
946 } | |
947 | |
948 /* Handle user-created local variables. */ | |
949 if (XTYPE (valcontents) == Lisp_Buffer_Local_Value | |
950 || XTYPE (valcontents) == Lisp_Some_Buffer_Local_Value) | |
951 { | |
952 /* If var is set up for a buffer that lacks a local value for it, | |
953 the current value is nominally the default value. | |
954 But the current value slot may be more up to date, since | |
955 ordinary setq stores just that slot. So use that. */ | |
956 Lisp_Object current_alist_element, alist_element_car; | |
957 current_alist_element | |
958 = XCONS (XCONS (XCONS (valcontents)->cdr)->cdr)->car; | |
959 alist_element_car = XCONS (current_alist_element)->car; | |
960 if (EQ (alist_element_car, current_alist_element)) | |
961 return do_symval_forwarding (XCONS (valcontents)->car); | |
962 else | |
963 return XCONS (XCONS (XCONS (valcontents)->cdr)->cdr)->cdr; | |
964 } | |
965 /* For other variables, get the current value. */ | |
966 return do_symval_forwarding (valcontents); | |
967 } | |
968 | |
969 DEFUN ("default-boundp", Fdefault_boundp, Sdefault_boundp, 1, 1, 0, | |
970 "Return T if SYMBOL has a non-void default value.\n\ | |
971 This is the value that is seen in buffers that do not have their own values\n\ | |
972 for this variable.") | |
973 (sym) | |
974 Lisp_Object sym; | |
975 { | |
976 register Lisp_Object value; | |
977 | |
978 value = default_value (sym); | |
979 return (XTYPE (value) == Lisp_Void || EQ (value, Qunbound) | |
980 ? Qnil : Qt); | |
981 } | |
982 | |
983 DEFUN ("default-value", Fdefault_value, Sdefault_value, 1, 1, 0, | |
984 "Return SYMBOL's default value.\n\ | |
985 This is the value that is seen in buffers that do not have their own values\n\ | |
986 for this variable. The default value is meaningful for variables with\n\ | |
987 local bindings in certain buffers.") | |
988 (sym) | |
989 Lisp_Object sym; | |
990 { | |
991 register Lisp_Object value; | |
992 | |
993 value = default_value (sym); | |
994 if (XTYPE (value) == Lisp_Void || EQ (value, Qunbound)) | |
995 return Fsignal (Qvoid_variable, Fcons (sym, Qnil)); | |
996 return value; | |
997 } | |
998 | |
999 DEFUN ("set-default", Fset_default, Sset_default, 2, 2, 0, | |
1000 "Set SYMBOL's default value to VAL. SYMBOL and VAL are evaluated.\n\ | |
1001 The default value is seen in buffers that do not have their own values\n\ | |
1002 for this variable.") | |
1003 (sym, value) | |
1004 Lisp_Object sym, value; | |
1005 { | |
1006 register Lisp_Object valcontents, current_alist_element, alist_element_buffer; | |
1007 | |
1008 CHECK_SYMBOL (sym, 0); | |
1009 valcontents = XSYMBOL (sym)->value; | |
1010 | |
1011 /* Handle variables like case-fold-search that have special slots | |
1012 in the buffer. Make them work apparently like Lisp_Buffer_Local_Value | |
1013 variables. */ | |
1014 if (XTYPE (valcontents) == Lisp_Buffer_Objfwd) | |
1015 { | |
1016 register int idx = XUINT (valcontents); | |
1017 #ifndef RTPC_REGISTER_BUG | |
1018 register struct buffer *b; | |
1019 #else | |
1020 struct buffer *b; | |
1021 #endif | |
1022 register int mask = *(int *) (idx + (char *) &buffer_local_flags); | |
1023 | |
1024 if (mask > 0) | |
1025 { | |
1026 *(Lisp_Object *)(idx + (char *) &buffer_defaults) = value; | |
1027 for (b = all_buffers; b; b = b->next) | |
1028 if (!(b->local_var_flags & mask)) | |
1029 *(Lisp_Object *)(idx + (char *) b) = value; | |
1030 } | |
1031 return value; | |
1032 } | |
1033 | |
1034 if (XTYPE (valcontents) != Lisp_Buffer_Local_Value && | |
1035 XTYPE (valcontents) != Lisp_Some_Buffer_Local_Value) | |
1036 return Fset (sym, value); | |
1037 | |
1038 /* Store new value into the DEFAULT-VALUE slot */ | |
1039 XCONS (XCONS (XCONS (valcontents)->cdr)->cdr)->cdr = value; | |
1040 | |
1041 /* If that slot is current, we must set the REALVALUE slot too */ | |
1042 current_alist_element = XCONS (XCONS (XCONS (valcontents)->cdr)->cdr)->car; | |
1043 alist_element_buffer = Fcar (current_alist_element); | |
1044 if (EQ (alist_element_buffer, current_alist_element)) | |
1045 store_symval_forwarding (sym, XCONS (valcontents)->car, value); | |
1046 | |
1047 return value; | |
1048 } | |
1049 | |
1050 DEFUN ("setq-default", Fsetq_default, Ssetq_default, 2, UNEVALLED, 0, | |
6919
dabe7a363f28
(Fsetq_default): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
6825
diff
changeset
|
1051 "Set the default value of variable VAR to VALUE.\n\ |
dabe7a363f28
(Fsetq_default): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
6825
diff
changeset
|
1052 VAR, the variable name, is literal (not evaluated);\n\ |
dabe7a363f28
(Fsetq_default): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
6825
diff
changeset
|
1053 VALUE is an expression and it is evaluated.\n\ |
dabe7a363f28
(Fsetq_default): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
6825
diff
changeset
|
1054 The default value of a variable is seen in buffers\n\ |
dabe7a363f28
(Fsetq_default): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
6825
diff
changeset
|
1055 that do not have their own values for the variable.\n\ |
dabe7a363f28
(Fsetq_default): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
6825
diff
changeset
|
1056 \n\ |
dabe7a363f28
(Fsetq_default): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
6825
diff
changeset
|
1057 More generally, you can use multiple variables and values, as in\n\ |
dabe7a363f28
(Fsetq_default): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
6825
diff
changeset
|
1058 (setq-default SYM VALUE SYM VALUE...)\n\ |
dabe7a363f28
(Fsetq_default): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
6825
diff
changeset
|
1059 This sets each SYM's default value to the corresponding VALUE.\n\ |
dabe7a363f28
(Fsetq_default): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
6825
diff
changeset
|
1060 The VALUE for the Nth SYM can refer to the new default values\n\ |
dabe7a363f28
(Fsetq_default): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
6825
diff
changeset
|
1061 of previous SYMs.") |
298 | 1062 (args) |
1063 Lisp_Object args; | |
1064 { | |
1065 register Lisp_Object args_left; | |
1066 register Lisp_Object val, sym; | |
1067 struct gcpro gcpro1; | |
1068 | |
490 | 1069 if (NILP (args)) |
298 | 1070 return Qnil; |
1071 | |
1072 args_left = args; | |
1073 GCPRO1 (args); | |
1074 | |
1075 do | |
1076 { | |
1077 val = Feval (Fcar (Fcdr (args_left))); | |
1078 sym = Fcar (args_left); | |
1079 Fset_default (sym, val); | |
1080 args_left = Fcdr (Fcdr (args_left)); | |
1081 } | |
490 | 1082 while (!NILP (args_left)); |
298 | 1083 |
1084 UNGCPRO; | |
1085 return val; | |
1086 } | |
1087 | |
1278
0a0646ae381f
* data.c (Fmake_local_variable): If SYM forwards to a C variable,
Jim Blandy <jimb@redhat.com>
parents:
1263
diff
changeset
|
1088 /* Lisp functions for creating and removing buffer-local variables. */ |
0a0646ae381f
* data.c (Fmake_local_variable): If SYM forwards to a C variable,
Jim Blandy <jimb@redhat.com>
parents:
1263
diff
changeset
|
1089 |
298 | 1090 DEFUN ("make-variable-buffer-local", Fmake_variable_buffer_local, Smake_variable_buffer_local, |
1091 1, 1, "vMake Variable Buffer Local: ", | |
1092 "Make VARIABLE have a separate value for each buffer.\n\ | |
1093 At any time, the value for the current buffer is in effect.\n\ | |
1094 There is also a default value which is seen in any buffer which has not yet\n\ | |
1095 set its own value.\n\ | |
1096 Using `set' or `setq' to set the variable causes it to have a separate value\n\ | |
1097 for the current buffer if it was previously using the default value.\n\ | |
1098 The function `default-value' gets the default value and `set-default' sets it.") | |
1099 (sym) | |
1100 register Lisp_Object sym; | |
1101 { | |
1102 register Lisp_Object tem, valcontents; | |
1103 | |
1104 CHECK_SYMBOL (sym, 0); | |
1105 | |
1106 if (EQ (sym, Qnil) || EQ (sym, Qt)) | |
1107 error ("Symbol %s may not be buffer-local", XSYMBOL (sym)->name->data); | |
1108 | |
1109 valcontents = XSYMBOL (sym)->value; | |
1110 if ((XTYPE (valcontents) == Lisp_Buffer_Local_Value) || | |
1111 (XTYPE (valcontents) == Lisp_Buffer_Objfwd)) | |
1112 return sym; | |
1113 if (XTYPE (valcontents) == Lisp_Some_Buffer_Local_Value) | |
1114 { | |
1115 XSETTYPE (XSYMBOL (sym)->value, Lisp_Buffer_Local_Value); | |
1116 return sym; | |
1117 } | |
1118 if (EQ (valcontents, Qunbound)) | |
1119 XSYMBOL (sym)->value = Qnil; | |
1120 tem = Fcons (Qnil, Fsymbol_value (sym)); | |
1121 XCONS (tem)->car = tem; | |
1122 XSYMBOL (sym)->value = Fcons (XSYMBOL (sym)->value, Fcons (Fcurrent_buffer (), tem)); | |
1123 XSETTYPE (XSYMBOL (sym)->value, Lisp_Buffer_Local_Value); | |
1124 return sym; | |
1125 } | |
1126 | |
1127 DEFUN ("make-local-variable", Fmake_local_variable, Smake_local_variable, | |
1128 1, 1, "vMake Local Variable: ", | |
1129 "Make VARIABLE have a separate value in the current buffer.\n\ | |
1130 Other buffers will continue to share a common default value.\n\ | |
6825
f70a517ae9e2
(Fsetq_default, Fmake_local_variable): Doc syntax fix.
Richard M. Stallman <rms@gnu.org>
parents:
6497
diff
changeset
|
1131 \(The buffer-local value of VARIABLE starts out as the same value\n\ |
f70a517ae9e2
(Fsetq_default, Fmake_local_variable): Doc syntax fix.
Richard M. Stallman <rms@gnu.org>
parents:
6497
diff
changeset
|
1132 VARIABLE previously had. If VARIABLE was void, it remains void.\)\n\ |
298 | 1133 See also `make-variable-buffer-local'.\n\n\ |
1134 If the variable is already arranged to become local when set,\n\ | |
1135 this function causes a local value to exist for this buffer,\n\ | |
1136 just as if the variable were set.") | |
1137 (sym) | |
1138 register Lisp_Object sym; | |
1139 { | |
1140 register Lisp_Object tem, valcontents; | |
1141 | |
1142 CHECK_SYMBOL (sym, 0); | |
1143 | |
1144 if (EQ (sym, Qnil) || EQ (sym, Qt)) | |
1145 error ("Symbol %s may not be buffer-local", XSYMBOL (sym)->name->data); | |
1146 | |
1147 valcontents = XSYMBOL (sym)->value; | |
1148 if (XTYPE (valcontents) == Lisp_Buffer_Local_Value | |
1149 || XTYPE (valcontents) == Lisp_Buffer_Objfwd) | |
1150 { | |
1151 tem = Fboundp (sym); | |
1152 | |
1153 /* Make sure the symbol has a local value in this particular buffer, | |
1154 by setting it to the same value it already has. */ | |
1155 Fset (sym, (EQ (tem, Qt) ? Fsymbol_value (sym) : Qunbound)); | |
1156 return sym; | |
1157 } | |
1158 /* Make sure sym is set up to hold per-buffer values */ | |
1159 if (XTYPE (valcontents) != Lisp_Some_Buffer_Local_Value) | |
1160 { | |
1161 tem = Fcons (Qnil, do_symval_forwarding (valcontents)); | |
1162 XCONS (tem)->car = tem; | |
1163 XSYMBOL (sym)->value = Fcons (XSYMBOL (sym)->value, Fcons (Qnil, tem)); | |
1164 XSETTYPE (XSYMBOL (sym)->value, Lisp_Some_Buffer_Local_Value); | |
1165 } | |
1166 /* Make sure this buffer has its own value of sym */ | |
1167 tem = Fassq (sym, current_buffer->local_var_alist); | |
490 | 1168 if (NILP (tem)) |
298 | 1169 { |
1170 current_buffer->local_var_alist | |
1171 = Fcons (Fcons (sym, XCONS (XCONS (XCONS (XSYMBOL (sym)->value)->cdr)->cdr)->cdr), | |
1172 current_buffer->local_var_alist); | |
1173 | |
1174 /* Make sure symbol does not think it is set up for this buffer; | |
1175 force it to look once again for this buffer's value */ | |
1176 { | |
1177 /* This local variable avoids "expression too complex" on IBM RT. */ | |
1178 Lisp_Object xs; | |
1179 | |
1180 xs = XSYMBOL (sym)->value; | |
1181 if (current_buffer == XBUFFER (XCONS (XCONS (xs)->cdr)->car)) | |
1182 XCONS (XCONS (XSYMBOL (sym)->value)->cdr)->car = Qnil; | |
1183 } | |
1278
0a0646ae381f
* data.c (Fmake_local_variable): If SYM forwards to a C variable,
Jim Blandy <jimb@redhat.com>
parents:
1263
diff
changeset
|
1184 } |
298 | 1185 |
1278
0a0646ae381f
* data.c (Fmake_local_variable): If SYM forwards to a C variable,
Jim Blandy <jimb@redhat.com>
parents:
1263
diff
changeset
|
1186 /* If the symbol forwards into a C variable, then swap in the |
0a0646ae381f
* data.c (Fmake_local_variable): If SYM forwards to a C variable,
Jim Blandy <jimb@redhat.com>
parents:
1263
diff
changeset
|
1187 variable for this buffer immediately. If C code modifies the |
0a0646ae381f
* data.c (Fmake_local_variable): If SYM forwards to a C variable,
Jim Blandy <jimb@redhat.com>
parents:
1263
diff
changeset
|
1188 variable before we swap in, then that new value will clobber the |
0a0646ae381f
* data.c (Fmake_local_variable): If SYM forwards to a C variable,
Jim Blandy <jimb@redhat.com>
parents:
1263
diff
changeset
|
1189 default value the next time we swap. */ |
0a0646ae381f
* data.c (Fmake_local_variable): If SYM forwards to a C variable,
Jim Blandy <jimb@redhat.com>
parents:
1263
diff
changeset
|
1190 valcontents = XCONS (XSYMBOL (sym)->value)->car; |
0a0646ae381f
* data.c (Fmake_local_variable): If SYM forwards to a C variable,
Jim Blandy <jimb@redhat.com>
parents:
1263
diff
changeset
|
1191 if (XTYPE (valcontents) == Lisp_Intfwd |
0a0646ae381f
* data.c (Fmake_local_variable): If SYM forwards to a C variable,
Jim Blandy <jimb@redhat.com>
parents:
1263
diff
changeset
|
1192 || XTYPE (valcontents) == Lisp_Boolfwd |
0a0646ae381f
* data.c (Fmake_local_variable): If SYM forwards to a C variable,
Jim Blandy <jimb@redhat.com>
parents:
1263
diff
changeset
|
1193 || XTYPE (valcontents) == Lisp_Objfwd) |
0a0646ae381f
* data.c (Fmake_local_variable): If SYM forwards to a C variable,
Jim Blandy <jimb@redhat.com>
parents:
1263
diff
changeset
|
1194 swap_in_symval_forwarding (sym, XSYMBOL (sym)->value); |
0a0646ae381f
* data.c (Fmake_local_variable): If SYM forwards to a C variable,
Jim Blandy <jimb@redhat.com>
parents:
1263
diff
changeset
|
1195 |
298 | 1196 return sym; |
1197 } | |
1198 | |
1199 DEFUN ("kill-local-variable", Fkill_local_variable, Skill_local_variable, | |
1200 1, 1, "vKill Local Variable: ", | |
1201 "Make VARIABLE no longer have a separate value in the current buffer.\n\ | |
1202 From now on the default value will apply in this buffer.") | |
1203 (sym) | |
1204 register Lisp_Object sym; | |
1205 { | |
1206 register Lisp_Object tem, valcontents; | |
1207 | |
1208 CHECK_SYMBOL (sym, 0); | |
1209 | |
1210 valcontents = XSYMBOL (sym)->value; | |
1211 | |
1212 if (XTYPE (valcontents) == Lisp_Buffer_Objfwd) | |
1213 { | |
1214 register int idx = XUINT (valcontents); | |
1215 register int mask = *(int *) (idx + (char *) &buffer_local_flags); | |
1216 | |
1217 if (mask > 0) | |
1218 { | |
1219 *(Lisp_Object *)(idx + (char *) current_buffer) | |
1220 = *(Lisp_Object *)(idx + (char *) &buffer_defaults); | |
1221 current_buffer->local_var_flags &= ~mask; | |
1222 } | |
1223 return sym; | |
1224 } | |
1225 | |
1226 if (XTYPE (valcontents) != Lisp_Buffer_Local_Value && | |
1227 XTYPE (valcontents) != Lisp_Some_Buffer_Local_Value) | |
1228 return sym; | |
1229 | |
1230 /* Get rid of this buffer's alist element, if any */ | |
1231 | |
1232 tem = Fassq (sym, current_buffer->local_var_alist); | |
490 | 1233 if (!NILP (tem)) |
298 | 1234 current_buffer->local_var_alist = Fdelq (tem, current_buffer->local_var_alist); |
1235 | |
1236 /* Make sure symbol does not think it is set up for this buffer; | |
1237 force it to look once again for this buffer's value */ | |
1238 { | |
1239 Lisp_Object sv; | |
1240 sv = XSYMBOL (sym)->value; | |
1241 if (current_buffer == XBUFFER (XCONS (XCONS (sv)->cdr)->car)) | |
1242 XCONS (XCONS (sv)->cdr)->car = Qnil; | |
1243 } | |
1244 | |
1245 return sym; | |
1246 } | |
1247 | |
648 | 1248 /* Find the function at the end of a chain of symbol function indirections. */ |
1249 | |
1250 /* If OBJECT is a symbol, find the end of its function chain and | |
1251 return the value found there. If OBJECT is not a symbol, just | |
1252 return it. If there is a cycle in the function chain, signal a | |
1253 cyclic-function-indirection error. | |
1254 | |
1255 This is like Findirect_function, except that it doesn't signal an | |
1256 error if the chain ends up unbound. */ | |
1257 Lisp_Object | |
1648
27e9f99fe095
src/ * data.c (indirect_function): Delete unused argument ERROR.
Jim Blandy <jimb@redhat.com>
parents:
1508
diff
changeset
|
1258 indirect_function (object) |
648 | 1259 register Lisp_Object object; |
1260 { | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3529
diff
changeset
|
1261 Lisp_Object tortoise, hare; |
648 | 1262 |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3529
diff
changeset
|
1263 hare = tortoise = object; |
648 | 1264 |
1265 for (;;) | |
1266 { | |
1267 if (XTYPE (hare) != Lisp_Symbol || EQ (hare, Qunbound)) | |
1268 break; | |
1269 hare = XSYMBOL (hare)->function; | |
1270 if (XTYPE (hare) != Lisp_Symbol || EQ (hare, Qunbound)) | |
1271 break; | |
1272 hare = XSYMBOL (hare)->function; | |
1273 | |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3529
diff
changeset
|
1274 tortoise = XSYMBOL (tortoise)->function; |
648 | 1275 |
3591
507f64624555
Apply typo patches from Paul Eggert.
Jim Blandy <jimb@redhat.com>
parents:
3529
diff
changeset
|
1276 if (EQ (hare, tortoise)) |
648 | 1277 Fsignal (Qcyclic_function_indirection, Fcons (object, Qnil)); |
1278 } | |
1279 | |
1280 return hare; | |
1281 } | |
1282 | |
1283 DEFUN ("indirect-function", Findirect_function, Sindirect_function, 1, 1, 0, | |
1284 "Return the function at the end of OBJECT's function chain.\n\ | |
1285 If OBJECT is a symbol, follow all function indirections and return the final\n\ | |
1286 function binding.\n\ | |
1287 If OBJECT is not a symbol, just return it.\n\ | |
1288 Signal a void-function error if the final symbol is unbound.\n\ | |
1289 Signal a cyclic-function-indirection error if there is a loop in the\n\ | |
1290 function chain of symbols.") | |
1291 (object) | |
1292 register Lisp_Object object; | |
1293 { | |
1294 Lisp_Object result; | |
1295 | |
1296 result = indirect_function (object); | |
1297 | |
1298 if (EQ (result, Qunbound)) | |
1299 return Fsignal (Qvoid_function, Fcons (object, Qnil)); | |
1300 return result; | |
1301 } | |
1302 | |
298 | 1303 /* Extract and set vector and string elements */ |
1304 | |
1305 DEFUN ("aref", Faref, Saref, 2, 2, 0, | |
1306 "Return the element of ARRAY at index INDEX.\n\ | |
1307 ARRAY may be a vector or a string, or a byte-code object. INDEX starts at 0.") | |
1308 (array, idx) | |
1309 register Lisp_Object array; | |
1310 Lisp_Object idx; | |
1311 { | |
1312 register int idxval; | |
1313 | |
1314 CHECK_NUMBER (idx, 1); | |
1315 idxval = XINT (idx); | |
1316 if (XTYPE (array) != Lisp_Vector && XTYPE (array) != Lisp_String | |
1317 && XTYPE (array) != Lisp_Compiled) | |
1318 array = wrong_type_argument (Qarrayp, array); | |
1319 if (idxval < 0 || idxval >= XVECTOR (array)->size) | |
1320 args_out_of_range (array, idx); | |
1321 if (XTYPE (array) == Lisp_String) | |
1322 { | |
1323 Lisp_Object val; | |
1324 XFASTINT (val) = (unsigned char) XSTRING (array)->data[idxval]; | |
1325 return val; | |
1326 } | |
1327 else | |
1328 return XVECTOR (array)->contents[idxval]; | |
1329 } | |
1330 | |
1331 DEFUN ("aset", Faset, Saset, 3, 3, 0, | |
5660 | 1332 "Store into the element of ARRAY at index IDX the value NEWELT.\n\ |
1333 ARRAY may be a vector or a string. IDX starts at 0.") | |
298 | 1334 (array, idx, newelt) |
1335 register Lisp_Object array; | |
1336 Lisp_Object idx, newelt; | |
1337 { | |
1338 register int idxval; | |
1339 | |
1340 CHECK_NUMBER (idx, 1); | |
1341 idxval = XINT (idx); | |
1342 if (XTYPE (array) != Lisp_Vector && XTYPE (array) != Lisp_String) | |
1343 array = wrong_type_argument (Qarrayp, array); | |
1344 if (idxval < 0 || idxval >= XVECTOR (array)->size) | |
1345 args_out_of_range (array, idx); | |
1346 CHECK_IMPURE (array); | |
1347 | |
1348 if (XTYPE (array) == Lisp_Vector) | |
1349 XVECTOR (array)->contents[idxval] = newelt; | |
1350 else | |
1351 { | |
1352 CHECK_NUMBER (newelt, 2); | |
1353 XSTRING (array)->data[idxval] = XINT (newelt); | |
1354 } | |
1355 | |
1356 return newelt; | |
1357 } | |
1358 | |
1359 Lisp_Object | |
1360 Farray_length (array) | |
1361 register Lisp_Object array; | |
1362 { | |
1363 register Lisp_Object size; | |
1364 if (XTYPE (array) != Lisp_Vector && XTYPE (array) != Lisp_String | |
1365 && XTYPE (array) != Lisp_Compiled) | |
1366 array = wrong_type_argument (Qarrayp, array); | |
1367 XFASTINT (size) = XVECTOR (array)->size; | |
1368 return size; | |
1369 } | |
1370 | |
1371 /* Arithmetic functions */ | |
1372 | |
1373 enum comparison { equal, notequal, less, grtr, less_or_equal, grtr_or_equal }; | |
1374 | |
1375 Lisp_Object | |
1376 arithcompare (num1, num2, comparison) | |
1377 Lisp_Object num1, num2; | |
1378 enum comparison comparison; | |
1379 { | |
1380 double f1, f2; | |
1381 int floatp = 0; | |
1382 | |
1383 #ifdef LISP_FLOAT_TYPE | |
1384 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1, 0); | |
1385 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2, 0); | |
1386 | |
1387 if (XTYPE (num1) == Lisp_Float || XTYPE (num2) == Lisp_Float) | |
1388 { | |
1389 floatp = 1; | |
1390 f1 = (XTYPE (num1) == Lisp_Float) ? XFLOAT (num1)->data : XINT (num1); | |
1391 f2 = (XTYPE (num2) == Lisp_Float) ? XFLOAT (num2)->data : XINT (num2); | |
1392 } | |
1393 #else | |
1394 CHECK_NUMBER_COERCE_MARKER (num1, 0); | |
1395 CHECK_NUMBER_COERCE_MARKER (num2, 0); | |
1396 #endif /* LISP_FLOAT_TYPE */ | |
1397 | |
1398 switch (comparison) | |
1399 { | |
1400 case equal: | |
1401 if (floatp ? f1 == f2 : XINT (num1) == XINT (num2)) | |
1402 return Qt; | |
1403 return Qnil; | |
1404 | |
1405 case notequal: | |
1406 if (floatp ? f1 != f2 : XINT (num1) != XINT (num2)) | |
1407 return Qt; | |
1408 return Qnil; | |
1409 | |
1410 case less: | |
1411 if (floatp ? f1 < f2 : XINT (num1) < XINT (num2)) | |
1412 return Qt; | |
1413 return Qnil; | |
1414 | |
1415 case less_or_equal: | |
1416 if (floatp ? f1 <= f2 : XINT (num1) <= XINT (num2)) | |
1417 return Qt; | |
1418 return Qnil; | |
1419 | |
1420 case grtr: | |
1421 if (floatp ? f1 > f2 : XINT (num1) > XINT (num2)) | |
1422 return Qt; | |
1423 return Qnil; | |
1424 | |
1425 case grtr_or_equal: | |
1426 if (floatp ? f1 >= f2 : XINT (num1) >= XINT (num2)) | |
1427 return Qt; | |
1428 return Qnil; | |
1914
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1429 |
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1430 default: |
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1431 abort (); |
298 | 1432 } |
1433 } | |
1434 | |
1435 DEFUN ("=", Feqlsign, Seqlsign, 2, 2, 0, | |
1436 "T if two args, both numbers or markers, are equal.") | |
1437 (num1, num2) | |
1438 register Lisp_Object num1, num2; | |
1439 { | |
1440 return arithcompare (num1, num2, equal); | |
1441 } | |
1442 | |
1443 DEFUN ("<", Flss, Slss, 2, 2, 0, | |
1444 "T if first arg is less than second arg. Both must be numbers or markers.") | |
1445 (num1, num2) | |
1446 register Lisp_Object num1, num2; | |
1447 { | |
1448 return arithcompare (num1, num2, less); | |
1449 } | |
1450 | |
1451 DEFUN (">", Fgtr, Sgtr, 2, 2, 0, | |
1452 "T if first arg is greater than second arg. Both must be numbers or markers.") | |
1453 (num1, num2) | |
1454 register Lisp_Object num1, num2; | |
1455 { | |
1456 return arithcompare (num1, num2, grtr); | |
1457 } | |
1458 | |
1459 DEFUN ("<=", Fleq, Sleq, 2, 2, 0, | |
1460 "T if first arg is less than or equal to second arg.\n\ | |
1461 Both must be numbers or markers.") | |
1462 (num1, num2) | |
1463 register Lisp_Object num1, num2; | |
1464 { | |
1465 return arithcompare (num1, num2, less_or_equal); | |
1466 } | |
1467 | |
1468 DEFUN (">=", Fgeq, Sgeq, 2, 2, 0, | |
1469 "T if first arg is greater than or equal to second arg.\n\ | |
1470 Both must be numbers or markers.") | |
1471 (num1, num2) | |
1472 register Lisp_Object num1, num2; | |
1473 { | |
1474 return arithcompare (num1, num2, grtr_or_equal); | |
1475 } | |
1476 | |
1477 DEFUN ("/=", Fneq, Sneq, 2, 2, 0, | |
1478 "T if first arg is not equal to second arg. Both must be numbers or markers.") | |
1479 (num1, num2) | |
1480 register Lisp_Object num1, num2; | |
1481 { | |
1482 return arithcompare (num1, num2, notequal); | |
1483 } | |
1484 | |
1485 DEFUN ("zerop", Fzerop, Szerop, 1, 1, 0, "T if NUMBER is zero.") | |
1486 (num) | |
1487 register Lisp_Object num; | |
1488 { | |
1489 #ifdef LISP_FLOAT_TYPE | |
1490 CHECK_NUMBER_OR_FLOAT (num, 0); | |
1491 | |
1492 if (XTYPE(num) == Lisp_Float) | |
1493 { | |
1494 if (XFLOAT(num)->data == 0.0) | |
1495 return Qt; | |
1496 return Qnil; | |
1497 } | |
1498 #else | |
1499 CHECK_NUMBER (num, 0); | |
1500 #endif /* LISP_FLOAT_TYPE */ | |
1501 | |
1502 if (!XINT (num)) | |
1503 return Qt; | |
1504 return Qnil; | |
1505 } | |
1506 | |
2515
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1507 /* Convert between 32-bit values and pairs of lispy 24-bit values. */ |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1508 |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1509 Lisp_Object |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1510 long_to_cons (i) |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1511 unsigned long i; |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1512 { |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1513 unsigned int top = i >> 16; |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1514 unsigned int bot = i & 0xFFFF; |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1515 if (top == 0) |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1516 return make_number (bot); |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1517 if (top == 0xFFFF) |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1518 return Fcons (make_number (-1), make_number (bot)); |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1519 return Fcons (make_number (top), make_number (bot)); |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1520 } |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1521 |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1522 unsigned long |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1523 cons_to_long (c) |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1524 Lisp_Object c; |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1525 { |
3675
f42eaf84478f
(cons_to_long): Declare top, bot as Lisp_Object.
Richard M. Stallman <rms@gnu.org>
parents:
3591
diff
changeset
|
1526 Lisp_Object top, bot; |
2515
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1527 if (INTEGERP (c)) |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1528 return XINT (c); |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1529 top = XCONS (c)->car; |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1530 bot = XCONS (c)->cdr; |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1531 if (CONSP (bot)) |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1532 bot = XCONS (bot)->car; |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1533 return ((XINT (top) << 16) | XINT (bot)); |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1534 } |
c0cdd6a80391
long_to_cons and cons_to_long are generally useful things; they're
Jim Blandy <jimb@redhat.com>
parents:
2429
diff
changeset
|
1535 |
2429
96b55f2f19cd
Rename int-to-string to number-to-string, since it can handle
Jim Blandy <jimb@redhat.com>
parents:
2092
diff
changeset
|
1536 DEFUN ("number-to-string", Fnumber_to_string, Snumber_to_string, 1, 1, 0, |
1914
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1537 "Convert NUM to a string by printing it in decimal.\n\ |
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1538 Uses a minus sign if negative.\n\ |
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1539 NUM may be an integer or a floating point number.") |
298 | 1540 (num) |
1541 Lisp_Object num; | |
1542 { | |
1543 char buffer[20]; | |
1544 | |
1545 #ifndef LISP_FLOAT_TYPE | |
1546 CHECK_NUMBER (num, 0); | |
1547 #else | |
1548 CHECK_NUMBER_OR_FLOAT (num, 0); | |
1549 | |
1550 if (XTYPE(num) == Lisp_Float) | |
1551 { | |
1552 char pigbuf[350]; /* see comments in float_to_string */ | |
1553 | |
1554 float_to_string (pigbuf, XFLOAT(num)->data); | |
1555 return build_string (pigbuf); | |
1556 } | |
1557 #endif /* LISP_FLOAT_TYPE */ | |
1558 | |
1559 sprintf (buffer, "%d", XINT (num)); | |
1560 return build_string (buffer); | |
1561 } | |
1562 | |
1914
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1563 DEFUN ("string-to-number", Fstring_to_number, Sstring_to_number, 1, 1, 0, |
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1564 "Convert STRING to a number by parsing it as a decimal number.\n\ |
6448
9d04c87e0da1
(Fstring_to_number): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
6446
diff
changeset
|
1565 This parses both integers and floating point numbers.\n\ |
9d04c87e0da1
(Fstring_to_number): Doc fix.
Richard M. Stallman <rms@gnu.org>
parents:
6446
diff
changeset
|
1566 It ignores leading spaces and tabs.") |
298 | 1567 (str) |
1568 register Lisp_Object str; | |
1569 { | |
1987
cd893024d6b9
* data.c (Fstring_to_number): Declare p to be an unsigned char, to
Jim Blandy <jimb@redhat.com>
parents:
1914
diff
changeset
|
1570 unsigned char *p; |
1914
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1571 |
298 | 1572 CHECK_STRING (str, 0); |
1573 | |
1914
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1574 p = XSTRING (str)->data; |
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1575 |
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1576 /* Skip any whitespace at the front of the number. Some versions of |
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1577 atoi do this anyway, so we might as well make Emacs lisp consistent. */ |
1987
cd893024d6b9
* data.c (Fstring_to_number): Declare p to be an unsigned char, to
Jim Blandy <jimb@redhat.com>
parents:
1914
diff
changeset
|
1578 while (*p == ' ' || *p == '\t') |
1914
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1579 p++; |
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1580 |
298 | 1581 #ifdef LISP_FLOAT_TYPE |
1914
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1582 if (isfloat_string (p)) |
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1583 return make_float (atof (p)); |
298 | 1584 #endif /* LISP_FLOAT_TYPE */ |
1585 | |
1914
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
1586 return make_number (atoi (p)); |
298 | 1587 } |
1588 | |
1589 enum arithop | |
1590 { Aadd, Asub, Amult, Adiv, Alogand, Alogior, Alogxor, Amax, Amin }; | |
1591 | |
1508
768d4c10c2bf
* data.c (Fset): See if current_alist_element points to itself
Jim Blandy <jimb@redhat.com>
parents:
1293
diff
changeset
|
1592 extern Lisp_Object float_arith_driver (); |
768d4c10c2bf
* data.c (Fset): See if current_alist_element points to itself
Jim Blandy <jimb@redhat.com>
parents:
1293
diff
changeset
|
1593 |
298 | 1594 Lisp_Object |
3338
30b946dd8c66
(float_arith_driver): Detect division by zero in advance.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
1595 arith_driver (code, nargs, args) |
298 | 1596 enum arithop code; |
1597 int nargs; | |
1598 register Lisp_Object *args; | |
1599 { | |
1600 register Lisp_Object val; | |
1601 register int argnum; | |
1602 register int accum; | |
1603 register int next; | |
1604 | |
1605 #ifdef SWITCH_ENUM_BUG | |
1606 switch ((int) code) | |
1607 #else | |
1608 switch (code) | |
1609 #endif | |
1610 { | |
1611 case Alogior: | |
1612 case Alogxor: | |
1613 case Aadd: | |
1614 case Asub: | |
1615 accum = 0; break; | |
1616 case Amult: | |
1617 accum = 1; break; | |
1618 case Alogand: | |
1619 accum = -1; break; | |
1620 } | |
1621 | |
1622 for (argnum = 0; argnum < nargs; argnum++) | |
1623 { | |
1624 val = args[argnum]; /* using args[argnum] as argument to CHECK_NUMBER_... */ | |
1625 #ifdef LISP_FLOAT_TYPE | |
1626 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val, argnum); | |
1627 | |
1628 if (XTYPE (val) == Lisp_Float) /* time to do serious math */ | |
1629 return (float_arith_driver ((double) accum, argnum, code, | |
1630 nargs, args)); | |
1631 #else | |
1632 CHECK_NUMBER_COERCE_MARKER (val, argnum); | |
1633 #endif /* LISP_FLOAT_TYPE */ | |
1634 args[argnum] = val; /* runs into a compiler bug. */ | |
1635 next = XINT (args[argnum]); | |
1636 #ifdef SWITCH_ENUM_BUG | |
1637 switch ((int) code) | |
1638 #else | |
1639 switch (code) | |
1640 #endif | |
1641 { | |
1642 case Aadd: accum += next; break; | |
1643 case Asub: | |
1644 if (!argnum && nargs != 1) | |
1645 next = - next; | |
1646 accum -= next; | |
1647 break; | |
1648 case Amult: accum *= next; break; | |
1649 case Adiv: | |
1650 if (!argnum) accum = next; | |
3338
30b946dd8c66
(float_arith_driver): Detect division by zero in advance.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
1651 else |
30b946dd8c66
(float_arith_driver): Detect division by zero in advance.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
1652 { |
30b946dd8c66
(float_arith_driver): Detect division by zero in advance.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
1653 if (next == 0) |
30b946dd8c66
(float_arith_driver): Detect division by zero in advance.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
1654 Fsignal (Qarith_error, Qnil); |
30b946dd8c66
(float_arith_driver): Detect division by zero in advance.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
1655 accum /= next; |
30b946dd8c66
(float_arith_driver): Detect division by zero in advance.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
1656 } |
298 | 1657 break; |
1658 case Alogand: accum &= next; break; | |
1659 case Alogior: accum |= next; break; | |
1660 case Alogxor: accum ^= next; break; | |
1661 case Amax: if (!argnum || next > accum) accum = next; break; | |
1662 case Amin: if (!argnum || next < accum) accum = next; break; | |
1663 } | |
1664 } | |
1665 | |
1666 XSET (val, Lisp_Int, accum); | |
1667 return val; | |
1668 } | |
1669 | |
1670 #ifdef LISP_FLOAT_TYPE | |
6201 | 1671 |
1672 #undef isnan | |
1673 #define isnan(x) ((x) != (x)) | |
1674 | |
298 | 1675 Lisp_Object |
1676 float_arith_driver (accum, argnum, code, nargs, args) | |
1677 double accum; | |
1678 register int argnum; | |
1679 enum arithop code; | |
1680 int nargs; | |
1681 register Lisp_Object *args; | |
1682 { | |
1683 register Lisp_Object val; | |
1684 double next; | |
1685 | |
1686 for (; argnum < nargs; argnum++) | |
1687 { | |
1688 val = args[argnum]; /* using args[argnum] as argument to CHECK_NUMBER_... */ | |
1689 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (val, argnum); | |
1690 | |
1691 if (XTYPE (val) == Lisp_Float) | |
1692 { | |
1693 next = XFLOAT (val)->data; | |
1694 } | |
1695 else | |
1696 { | |
1697 args[argnum] = val; /* runs into a compiler bug. */ | |
1698 next = XINT (args[argnum]); | |
1699 } | |
1700 #ifdef SWITCH_ENUM_BUG | |
1701 switch ((int) code) | |
1702 #else | |
1703 switch (code) | |
1704 #endif | |
1705 { | |
1706 case Aadd: | |
1707 accum += next; | |
1708 break; | |
1709 case Asub: | |
1710 if (!argnum && nargs != 1) | |
1711 next = - next; | |
1712 accum -= next; | |
1713 break; | |
1714 case Amult: | |
1715 accum *= next; | |
1716 break; | |
1717 case Adiv: | |
1718 if (!argnum) | |
1719 accum = next; | |
1720 else | |
3338
30b946dd8c66
(float_arith_driver): Detect division by zero in advance.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
1721 { |
30b946dd8c66
(float_arith_driver): Detect division by zero in advance.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
1722 if (next == 0) |
30b946dd8c66
(float_arith_driver): Detect division by zero in advance.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
1723 Fsignal (Qarith_error, Qnil); |
30b946dd8c66
(float_arith_driver): Detect division by zero in advance.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
1724 accum /= next; |
30b946dd8c66
(float_arith_driver): Detect division by zero in advance.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
1725 } |
298 | 1726 break; |
1727 case Alogand: | |
1728 case Alogior: | |
1729 case Alogxor: | |
1730 return wrong_type_argument (Qinteger_or_marker_p, val); | |
1731 case Amax: | |
6201 | 1732 if (!argnum || isnan (next) || next > accum) |
298 | 1733 accum = next; |
1734 break; | |
1735 case Amin: | |
6201 | 1736 if (!argnum || isnan (next) || next < accum) |
298 | 1737 accum = next; |
1738 break; | |
1739 } | |
1740 } | |
1741 | |
1742 return make_float (accum); | |
1743 } | |
1744 #endif /* LISP_FLOAT_TYPE */ | |
1745 | |
1746 DEFUN ("+", Fplus, Splus, 0, MANY, 0, | |
1747 "Return sum of any number of arguments, which are numbers or markers.") | |
1748 (nargs, args) | |
1749 int nargs; | |
1750 Lisp_Object *args; | |
1751 { | |
1752 return arith_driver (Aadd, nargs, args); | |
1753 } | |
1754 | |
1755 DEFUN ("-", Fminus, Sminus, 0, MANY, 0, | |
1756 "Negate number or subtract numbers or markers.\n\ | |
1757 With one arg, negates it. With more than one arg,\n\ | |
1758 subtracts all but the first from the first.") | |
1759 (nargs, args) | |
1760 int nargs; | |
1761 Lisp_Object *args; | |
1762 { | |
1763 return arith_driver (Asub, nargs, args); | |
1764 } | |
1765 | |
1766 DEFUN ("*", Ftimes, Stimes, 0, MANY, 0, | |
1767 "Returns product of any number of arguments, which are numbers or markers.") | |
1768 (nargs, args) | |
1769 int nargs; | |
1770 Lisp_Object *args; | |
1771 { | |
1772 return arith_driver (Amult, nargs, args); | |
1773 } | |
1774 | |
1775 DEFUN ("/", Fquo, Squo, 2, MANY, 0, | |
1776 "Returns first argument divided by all the remaining arguments.\n\ | |
1777 The arguments must be numbers or markers.") | |
1778 (nargs, args) | |
1779 int nargs; | |
1780 Lisp_Object *args; | |
1781 { | |
1782 return arith_driver (Adiv, nargs, args); | |
1783 } | |
1784 | |
1785 DEFUN ("%", Frem, Srem, 2, 2, 0, | |
1786 "Returns remainder of first arg divided by second.\n\ | |
4447
ba273b48143b
(Frem): Don't accept floats, just ints and markers.
Richard M. Stallman <rms@gnu.org>
parents:
4037
diff
changeset
|
1787 Both must be integers or markers.") |
298 | 1788 (num1, num2) |
1789 register Lisp_Object num1, num2; | |
1790 { | |
1791 Lisp_Object val; | |
1792 | |
1793 CHECK_NUMBER_COERCE_MARKER (num1, 0); | |
1794 CHECK_NUMBER_COERCE_MARKER (num2, 1); | |
1795 | |
3338
30b946dd8c66
(float_arith_driver): Detect division by zero in advance.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
1796 if (XFASTINT (num2) == 0) |
30b946dd8c66
(float_arith_driver): Detect division by zero in advance.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
1797 Fsignal (Qarith_error, Qnil); |
30b946dd8c66
(float_arith_driver): Detect division by zero in advance.
Richard M. Stallman <rms@gnu.org>
parents:
2961
diff
changeset
|
1798 |
298 | 1799 XSET (val, Lisp_Int, XINT (num1) % XINT (num2)); |
1800 return val; | |
1801 } | |
1802 | |
5776
6130ebde8d3b
(fmod): Implement it on systems where it's missing, using drem if available.
Karl Heuer <kwzh@gnu.org>
parents:
5729
diff
changeset
|
1803 #ifndef HAVE_FMOD |
6130ebde8d3b
(fmod): Implement it on systems where it's missing, using drem if available.
Karl Heuer <kwzh@gnu.org>
parents:
5729
diff
changeset
|
1804 double |
6130ebde8d3b
(fmod): Implement it on systems where it's missing, using drem if available.
Karl Heuer <kwzh@gnu.org>
parents:
5729
diff
changeset
|
1805 fmod (f1, f2) |
6130ebde8d3b
(fmod): Implement it on systems where it's missing, using drem if available.
Karl Heuer <kwzh@gnu.org>
parents:
5729
diff
changeset
|
1806 double f1, f2; |
6130ebde8d3b
(fmod): Implement it on systems where it's missing, using drem if available.
Karl Heuer <kwzh@gnu.org>
parents:
5729
diff
changeset
|
1807 { |
6130ebde8d3b
(fmod): Implement it on systems where it's missing, using drem if available.
Karl Heuer <kwzh@gnu.org>
parents:
5729
diff
changeset
|
1808 #ifdef HAVE_DREM /* Some systems use this non-standard name. */ |
6130ebde8d3b
(fmod): Implement it on systems where it's missing, using drem if available.
Karl Heuer <kwzh@gnu.org>
parents:
5729
diff
changeset
|
1809 return (drem (f1, f2)); |
6130ebde8d3b
(fmod): Implement it on systems where it's missing, using drem if available.
Karl Heuer <kwzh@gnu.org>
parents:
5729
diff
changeset
|
1810 #else /* Other systems don't seem to have it at all. */ |
6130ebde8d3b
(fmod): Implement it on systems where it's missing, using drem if available.
Karl Heuer <kwzh@gnu.org>
parents:
5729
diff
changeset
|
1811 return (f1 - f2 * floor (f1/f2)); |
6130ebde8d3b
(fmod): Implement it on systems where it's missing, using drem if available.
Karl Heuer <kwzh@gnu.org>
parents:
5729
diff
changeset
|
1812 #endif |
6130ebde8d3b
(fmod): Implement it on systems where it's missing, using drem if available.
Karl Heuer <kwzh@gnu.org>
parents:
5729
diff
changeset
|
1813 } |
6130ebde8d3b
(fmod): Implement it on systems where it's missing, using drem if available.
Karl Heuer <kwzh@gnu.org>
parents:
5729
diff
changeset
|
1814 #endif /* ! HAVE_FMOD */ |
6130ebde8d3b
(fmod): Implement it on systems where it's missing, using drem if available.
Karl Heuer <kwzh@gnu.org>
parents:
5729
diff
changeset
|
1815 |
4508
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1816 DEFUN ("mod", Fmod, Smod, 2, 2, 0, |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1817 "Returns X modulo Y.\n\ |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1818 The result falls between zero (inclusive) and Y (exclusive).\n\ |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1819 Both X and Y must be numbers or markers.") |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1820 (num1, num2) |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1821 register Lisp_Object num1, num2; |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1822 { |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1823 Lisp_Object val; |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1824 int i1, i2; |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1825 |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1826 #ifdef LISP_FLOAT_TYPE |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1827 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num1, 0); |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1828 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num2, 1); |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1829 |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1830 if (XTYPE (num1) == Lisp_Float || XTYPE (num2) == Lisp_Float) |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1831 { |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1832 double f1, f2; |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1833 |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1834 f1 = XTYPE (num1) == Lisp_Float ? XFLOAT (num1)->data : XINT (num1); |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1835 f2 = XTYPE (num2) == Lisp_Float ? XFLOAT (num2)->data : XINT (num2); |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1836 if (f2 == 0) |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1837 Fsignal (Qarith_error, Qnil); |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1838 |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1839 f1 = fmod (f1, f2); |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1840 /* If the "remainder" comes out with the wrong sign, fix it. */ |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1841 if ((f1 < 0) != (f2 < 0)) |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1842 f1 += f2; |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1843 return (make_float (f1)); |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1844 } |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1845 #else /* not LISP_FLOAT_TYPE */ |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1846 CHECK_NUMBER_COERCE_MARKER (num1, 0); |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1847 CHECK_NUMBER_COERCE_MARKER (num2, 1); |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1848 #endif /* not LISP_FLOAT_TYPE */ |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1849 |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1850 i1 = XINT (num1); |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1851 i2 = XINT (num2); |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1852 |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1853 if (i2 == 0) |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1854 Fsignal (Qarith_error, Qnil); |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1855 |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1856 i1 %= i2; |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1857 |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1858 /* If the "remainder" comes out with the wrong sign, fix it. */ |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1859 if ((i1 < 0) != (i2 < 0)) |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1860 i1 += i2; |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1861 |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1862 XSET (val, Lisp_Int, i1); |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1863 return val; |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1864 } |
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
1865 |
298 | 1866 DEFUN ("max", Fmax, Smax, 1, MANY, 0, |
1867 "Return largest of all the arguments (which must be numbers or markers).\n\ | |
1868 The value is always a number; markers are converted to numbers.") | |
1869 (nargs, args) | |
1870 int nargs; | |
1871 Lisp_Object *args; | |
1872 { | |
1873 return arith_driver (Amax, nargs, args); | |
1874 } | |
1875 | |
1876 DEFUN ("min", Fmin, Smin, 1, MANY, 0, | |
1877 "Return smallest of all the arguments (which must be numbers or markers).\n\ | |
1878 The value is always a number; markers are converted to numbers.") | |
1879 (nargs, args) | |
1880 int nargs; | |
1881 Lisp_Object *args; | |
1882 { | |
1883 return arith_driver (Amin, nargs, args); | |
1884 } | |
1885 | |
1886 DEFUN ("logand", Flogand, Slogand, 0, MANY, 0, | |
1887 "Return bitwise-and of all the arguments.\n\ | |
1888 Arguments may be integers, or markers converted to integers.") | |
1889 (nargs, args) | |
1890 int nargs; | |
1891 Lisp_Object *args; | |
1892 { | |
1893 return arith_driver (Alogand, nargs, args); | |
1894 } | |
1895 | |
1896 DEFUN ("logior", Flogior, Slogior, 0, MANY, 0, | |
1897 "Return bitwise-or of all the arguments.\n\ | |
1898 Arguments may be integers, or markers converted to integers.") | |
1899 (nargs, args) | |
1900 int nargs; | |
1901 Lisp_Object *args; | |
1902 { | |
1903 return arith_driver (Alogior, nargs, args); | |
1904 } | |
1905 | |
1906 DEFUN ("logxor", Flogxor, Slogxor, 0, MANY, 0, | |
1907 "Return bitwise-exclusive-or of all the arguments.\n\ | |
1908 Arguments may be integers, or markers converted to integers.") | |
1909 (nargs, args) | |
1910 int nargs; | |
1911 Lisp_Object *args; | |
1912 { | |
1913 return arith_driver (Alogxor, nargs, args); | |
1914 } | |
1915 | |
1916 DEFUN ("ash", Fash, Sash, 2, 2, 0, | |
1917 "Return VALUE with its bits shifted left by COUNT.\n\ | |
1918 If COUNT is negative, shifting is actually to the right.\n\ | |
1919 In this case, the sign bit is duplicated.") | |
1920 (num1, num2) | |
1921 register Lisp_Object num1, num2; | |
1922 { | |
1923 register Lisp_Object val; | |
1924 | |
1925 CHECK_NUMBER (num1, 0); | |
1926 CHECK_NUMBER (num2, 1); | |
1927 | |
1928 if (XINT (num2) > 0) | |
1929 XSET (val, Lisp_Int, XINT (num1) << XFASTINT (num2)); | |
1930 else | |
1931 XSET (val, Lisp_Int, XINT (num1) >> -XINT (num2)); | |
1932 return val; | |
1933 } | |
1934 | |
1935 DEFUN ("lsh", Flsh, Slsh, 2, 2, 0, | |
1936 "Return VALUE with its bits shifted left by COUNT.\n\ | |
1937 If COUNT is negative, shifting is actually to the right.\n\ | |
1938 In this case, zeros are shifted in on the left.") | |
1939 (num1, num2) | |
1940 register Lisp_Object num1, num2; | |
1941 { | |
1942 register Lisp_Object val; | |
1943 | |
1944 CHECK_NUMBER (num1, 0); | |
1945 CHECK_NUMBER (num2, 1); | |
1946 | |
1947 if (XINT (num2) > 0) | |
1948 XSET (val, Lisp_Int, (unsigned) XFASTINT (num1) << XFASTINT (num2)); | |
1949 else | |
1950 XSET (val, Lisp_Int, (unsigned) XFASTINT (num1) >> -XINT (num2)); | |
1951 return val; | |
1952 } | |
1953 | |
1954 DEFUN ("1+", Fadd1, Sadd1, 1, 1, 0, | |
1955 "Return NUMBER plus one. NUMBER may be a number or a marker.\n\ | |
1956 Markers are converted to integers.") | |
1957 (num) | |
1958 register Lisp_Object num; | |
1959 { | |
1960 #ifdef LISP_FLOAT_TYPE | |
1961 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num, 0); | |
1962 | |
1963 if (XTYPE (num) == Lisp_Float) | |
1964 return (make_float (1.0 + XFLOAT (num)->data)); | |
1965 #else | |
1966 CHECK_NUMBER_COERCE_MARKER (num, 0); | |
1967 #endif /* LISP_FLOAT_TYPE */ | |
1968 | |
1969 XSETINT (num, XFASTINT (num) + 1); | |
1970 return num; | |
1971 } | |
1972 | |
1973 DEFUN ("1-", Fsub1, Ssub1, 1, 1, 0, | |
1974 "Return NUMBER minus one. NUMBER may be a number or a marker.\n\ | |
1975 Markers are converted to integers.") | |
1976 (num) | |
1977 register Lisp_Object num; | |
1978 { | |
1979 #ifdef LISP_FLOAT_TYPE | |
1980 CHECK_NUMBER_OR_FLOAT_COERCE_MARKER (num, 0); | |
1981 | |
1982 if (XTYPE (num) == Lisp_Float) | |
1983 return (make_float (-1.0 + XFLOAT (num)->data)); | |
1984 #else | |
1985 CHECK_NUMBER_COERCE_MARKER (num, 0); | |
1986 #endif /* LISP_FLOAT_TYPE */ | |
1987 | |
1988 XSETINT (num, XFASTINT (num) - 1); | |
1989 return num; | |
1990 } | |
1991 | |
1992 DEFUN ("lognot", Flognot, Slognot, 1, 1, 0, | |
1993 "Return the bitwise complement of ARG. ARG must be an integer.") | |
1994 (num) | |
1995 register Lisp_Object num; | |
1996 { | |
1997 CHECK_NUMBER (num, 0); | |
1998 XSETINT (num, ~XFASTINT (num)); | |
1999 return num; | |
2000 } | |
2001 | |
2002 void | |
2003 syms_of_data () | |
2004 { | |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2005 Lisp_Object error_tail, arith_tail; |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2006 |
298 | 2007 Qquote = intern ("quote"); |
2008 Qlambda = intern ("lambda"); | |
2009 Qsubr = intern ("subr"); | |
2010 Qerror_conditions = intern ("error-conditions"); | |
2011 Qerror_message = intern ("error-message"); | |
2012 Qtop_level = intern ("top-level"); | |
2013 | |
2014 Qerror = intern ("error"); | |
2015 Qquit = intern ("quit"); | |
2016 Qwrong_type_argument = intern ("wrong-type-argument"); | |
2017 Qargs_out_of_range = intern ("args-out-of-range"); | |
2018 Qvoid_function = intern ("void-function"); | |
648 | 2019 Qcyclic_function_indirection = intern ("cyclic-function-indirection"); |
298 | 2020 Qvoid_variable = intern ("void-variable"); |
2021 Qsetting_constant = intern ("setting-constant"); | |
2022 Qinvalid_read_syntax = intern ("invalid-read-syntax"); | |
2023 | |
2024 Qinvalid_function = intern ("invalid-function"); | |
2025 Qwrong_number_of_arguments = intern ("wrong-number-of-arguments"); | |
2026 Qno_catch = intern ("no-catch"); | |
2027 Qend_of_file = intern ("end-of-file"); | |
2028 Qarith_error = intern ("arith-error"); | |
2029 Qbeginning_of_buffer = intern ("beginning-of-buffer"); | |
2030 Qend_of_buffer = intern ("end-of-buffer"); | |
2031 Qbuffer_read_only = intern ("buffer-read-only"); | |
4036 | 2032 Qmark_inactive = intern ("mark-inactive"); |
298 | 2033 |
2034 Qlistp = intern ("listp"); | |
2035 Qconsp = intern ("consp"); | |
2036 Qsymbolp = intern ("symbolp"); | |
2037 Qintegerp = intern ("integerp"); | |
2038 Qnatnump = intern ("natnump"); | |
6459
30fabcc03f0c
(Qwholenump): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6448
diff
changeset
|
2039 Qwholenump = intern ("wholenump"); |
298 | 2040 Qstringp = intern ("stringp"); |
2041 Qarrayp = intern ("arrayp"); | |
2042 Qsequencep = intern ("sequencep"); | |
2043 Qbufferp = intern ("bufferp"); | |
2044 Qvectorp = intern ("vectorp"); | |
2045 Qchar_or_string_p = intern ("char-or-string-p"); | |
2046 Qmarkerp = intern ("markerp"); | |
1293 | 2047 Qbuffer_or_string_p = intern ("buffer-or-string-p"); |
298 | 2048 Qinteger_or_marker_p = intern ("integer-or-marker-p"); |
2049 Qboundp = intern ("boundp"); | |
2050 Qfboundp = intern ("fboundp"); | |
2051 | |
2052 #ifdef LISP_FLOAT_TYPE | |
2053 Qfloatp = intern ("floatp"); | |
2054 Qnumberp = intern ("numberp"); | |
2055 Qnumber_or_marker_p = intern ("number-or-marker-p"); | |
2056 #endif /* LISP_FLOAT_TYPE */ | |
2057 | |
2058 Qcdr = intern ("cdr"); | |
2059 | |
8401
1eee41c8120c
(syms_of_data): Set up Qadvice_info, Qactivate_advice.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
2060 /* Handle automatic advice activation */ |
1eee41c8120c
(syms_of_data): Set up Qadvice_info, Qactivate_advice.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
2061 Qadvice_info = intern ("advice-info"); |
1eee41c8120c
(syms_of_data): Set up Qadvice_info, Qactivate_advice.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
2062 Qactivate_advice = intern ("ad-activate"); |
1eee41c8120c
(syms_of_data): Set up Qadvice_info, Qactivate_advice.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
2063 |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2064 error_tail = Fcons (Qerror, Qnil); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2065 |
298 | 2066 /* ERROR is used as a signaler for random errors for which nothing else is right */ |
2067 | |
2068 Fput (Qerror, Qerror_conditions, | |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2069 error_tail); |
298 | 2070 Fput (Qerror, Qerror_message, |
2071 build_string ("error")); | |
2072 | |
2073 Fput (Qquit, Qerror_conditions, | |
2074 Fcons (Qquit, Qnil)); | |
2075 Fput (Qquit, Qerror_message, | |
2076 build_string ("Quit")); | |
2077 | |
2078 Fput (Qwrong_type_argument, Qerror_conditions, | |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2079 Fcons (Qwrong_type_argument, error_tail)); |
298 | 2080 Fput (Qwrong_type_argument, Qerror_message, |
2081 build_string ("Wrong type argument")); | |
2082 | |
2083 Fput (Qargs_out_of_range, Qerror_conditions, | |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2084 Fcons (Qargs_out_of_range, error_tail)); |
298 | 2085 Fput (Qargs_out_of_range, Qerror_message, |
2086 build_string ("Args out of range")); | |
2087 | |
2088 Fput (Qvoid_function, Qerror_conditions, | |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2089 Fcons (Qvoid_function, error_tail)); |
298 | 2090 Fput (Qvoid_function, Qerror_message, |
2091 build_string ("Symbol's function definition is void")); | |
2092 | |
648 | 2093 Fput (Qcyclic_function_indirection, Qerror_conditions, |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2094 Fcons (Qcyclic_function_indirection, error_tail)); |
648 | 2095 Fput (Qcyclic_function_indirection, Qerror_message, |
2096 build_string ("Symbol's chain of function indirections contains a loop")); | |
2097 | |
298 | 2098 Fput (Qvoid_variable, Qerror_conditions, |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2099 Fcons (Qvoid_variable, error_tail)); |
298 | 2100 Fput (Qvoid_variable, Qerror_message, |
2101 build_string ("Symbol's value as variable is void")); | |
2102 | |
2103 Fput (Qsetting_constant, Qerror_conditions, | |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2104 Fcons (Qsetting_constant, error_tail)); |
298 | 2105 Fput (Qsetting_constant, Qerror_message, |
2106 build_string ("Attempt to set a constant symbol")); | |
2107 | |
2108 Fput (Qinvalid_read_syntax, Qerror_conditions, | |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2109 Fcons (Qinvalid_read_syntax, error_tail)); |
298 | 2110 Fput (Qinvalid_read_syntax, Qerror_message, |
2111 build_string ("Invalid read syntax")); | |
2112 | |
2113 Fput (Qinvalid_function, Qerror_conditions, | |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2114 Fcons (Qinvalid_function, error_tail)); |
298 | 2115 Fput (Qinvalid_function, Qerror_message, |
2116 build_string ("Invalid function")); | |
2117 | |
2118 Fput (Qwrong_number_of_arguments, Qerror_conditions, | |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2119 Fcons (Qwrong_number_of_arguments, error_tail)); |
298 | 2120 Fput (Qwrong_number_of_arguments, Qerror_message, |
2121 build_string ("Wrong number of arguments")); | |
2122 | |
2123 Fput (Qno_catch, Qerror_conditions, | |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2124 Fcons (Qno_catch, error_tail)); |
298 | 2125 Fput (Qno_catch, Qerror_message, |
2126 build_string ("No catch for tag")); | |
2127 | |
2128 Fput (Qend_of_file, Qerror_conditions, | |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2129 Fcons (Qend_of_file, error_tail)); |
298 | 2130 Fput (Qend_of_file, Qerror_message, |
2131 build_string ("End of file during parsing")); | |
2132 | |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2133 arith_tail = Fcons (Qarith_error, error_tail); |
298 | 2134 Fput (Qarith_error, Qerror_conditions, |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2135 arith_tail); |
298 | 2136 Fput (Qarith_error, Qerror_message, |
2137 build_string ("Arithmetic error")); | |
2138 | |
2139 Fput (Qbeginning_of_buffer, Qerror_conditions, | |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2140 Fcons (Qbeginning_of_buffer, error_tail)); |
298 | 2141 Fput (Qbeginning_of_buffer, Qerror_message, |
2142 build_string ("Beginning of buffer")); | |
2143 | |
2144 Fput (Qend_of_buffer, Qerror_conditions, | |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2145 Fcons (Qend_of_buffer, error_tail)); |
298 | 2146 Fput (Qend_of_buffer, Qerror_message, |
2147 build_string ("End of buffer")); | |
2148 | |
2149 Fput (Qbuffer_read_only, Qerror_conditions, | |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2150 Fcons (Qbuffer_read_only, error_tail)); |
298 | 2151 Fput (Qbuffer_read_only, Qerror_message, |
2152 build_string ("Buffer is read-only")); | |
2153 | |
2092
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2154 #ifdef LISP_FLOAT_TYPE |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2155 Qrange_error = intern ("range-error"); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2156 Qdomain_error = intern ("domain-error"); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2157 Qsingularity_error = intern ("singularity-error"); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2158 Qoverflow_error = intern ("overflow-error"); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2159 Qunderflow_error = intern ("underflow-error"); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2160 |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2161 Fput (Qdomain_error, Qerror_conditions, |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2162 Fcons (Qdomain_error, arith_tail)); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2163 Fput (Qdomain_error, Qerror_message, |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2164 build_string ("Arithmetic domain error")); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2165 |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2166 Fput (Qrange_error, Qerror_conditions, |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2167 Fcons (Qrange_error, arith_tail)); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2168 Fput (Qrange_error, Qerror_message, |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2169 build_string ("Arithmetic range error")); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2170 |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2171 Fput (Qsingularity_error, Qerror_conditions, |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2172 Fcons (Qsingularity_error, Fcons (Qdomain_error, arith_tail))); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2173 Fput (Qsingularity_error, Qerror_message, |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2174 build_string ("Arithmetic singularity error")); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2175 |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2176 Fput (Qoverflow_error, Qerror_conditions, |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2177 Fcons (Qoverflow_error, Fcons (Qdomain_error, arith_tail))); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2178 Fput (Qoverflow_error, Qerror_message, |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2179 build_string ("Arithmetic overflow error")); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2180 |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2181 Fput (Qunderflow_error, Qerror_conditions, |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2182 Fcons (Qunderflow_error, Fcons (Qdomain_error, arith_tail))); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2183 Fput (Qunderflow_error, Qerror_message, |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2184 build_string ("Arithmetic underflow error")); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2185 |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2186 staticpro (&Qrange_error); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2187 staticpro (&Qdomain_error); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2188 staticpro (&Qsingularity_error); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2189 staticpro (&Qoverflow_error); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2190 staticpro (&Qunderflow_error); |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2191 #endif /* LISP_FLOAT_TYPE */ |
7497fce1e426
(syms_of_data) [LISP_FLOAT_TYPE]: Define new error conditions:
Richard M. Stallman <rms@gnu.org>
parents:
1987
diff
changeset
|
2192 |
298 | 2193 staticpro (&Qnil); |
2194 staticpro (&Qt); | |
2195 staticpro (&Qquote); | |
2196 staticpro (&Qlambda); | |
2197 staticpro (&Qsubr); | |
2198 staticpro (&Qunbound); | |
2199 staticpro (&Qerror_conditions); | |
2200 staticpro (&Qerror_message); | |
2201 staticpro (&Qtop_level); | |
2202 | |
2203 staticpro (&Qerror); | |
2204 staticpro (&Qquit); | |
2205 staticpro (&Qwrong_type_argument); | |
2206 staticpro (&Qargs_out_of_range); | |
2207 staticpro (&Qvoid_function); | |
648 | 2208 staticpro (&Qcyclic_function_indirection); |
298 | 2209 staticpro (&Qvoid_variable); |
2210 staticpro (&Qsetting_constant); | |
2211 staticpro (&Qinvalid_read_syntax); | |
2212 staticpro (&Qwrong_number_of_arguments); | |
2213 staticpro (&Qinvalid_function); | |
2214 staticpro (&Qno_catch); | |
2215 staticpro (&Qend_of_file); | |
2216 staticpro (&Qarith_error); | |
2217 staticpro (&Qbeginning_of_buffer); | |
2218 staticpro (&Qend_of_buffer); | |
2219 staticpro (&Qbuffer_read_only); | |
4037
aecb99c65ab0
(syms_of_data): Staticpro Qmark_inactive.
Roland McGrath <roland@gnu.org>
parents:
4036
diff
changeset
|
2220 staticpro (&Qmark_inactive); |
298 | 2221 |
2222 staticpro (&Qlistp); | |
2223 staticpro (&Qconsp); | |
2224 staticpro (&Qsymbolp); | |
2225 staticpro (&Qintegerp); | |
2226 staticpro (&Qnatnump); | |
6459
30fabcc03f0c
(Qwholenump): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6448
diff
changeset
|
2227 staticpro (&Qwholenump); |
298 | 2228 staticpro (&Qstringp); |
2229 staticpro (&Qarrayp); | |
2230 staticpro (&Qsequencep); | |
2231 staticpro (&Qbufferp); | |
2232 staticpro (&Qvectorp); | |
2233 staticpro (&Qchar_or_string_p); | |
2234 staticpro (&Qmarkerp); | |
1293 | 2235 staticpro (&Qbuffer_or_string_p); |
298 | 2236 staticpro (&Qinteger_or_marker_p); |
2237 #ifdef LISP_FLOAT_TYPE | |
2238 staticpro (&Qfloatp); | |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
2239 staticpro (&Qnumberp); |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
2240 staticpro (&Qnumber_or_marker_p); |
298 | 2241 #endif /* LISP_FLOAT_TYPE */ |
2242 | |
2243 staticpro (&Qboundp); | |
2244 staticpro (&Qfboundp); | |
2245 staticpro (&Qcdr); | |
8401
1eee41c8120c
(syms_of_data): Set up Qadvice_info, Qactivate_advice.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
2246 staticpro (&Qadvice_info); |
1eee41c8120c
(syms_of_data): Set up Qadvice_info, Qactivate_advice.
Richard M. Stallman <rms@gnu.org>
parents:
7307
diff
changeset
|
2247 staticpro (&Qactivate_advice); |
298 | 2248 |
2249 defsubr (&Seq); | |
2250 defsubr (&Snull); | |
2251 defsubr (&Slistp); | |
2252 defsubr (&Snlistp); | |
2253 defsubr (&Sconsp); | |
2254 defsubr (&Satom); | |
2255 defsubr (&Sintegerp); | |
695
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
2256 defsubr (&Sinteger_or_marker_p); |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
2257 defsubr (&Snumberp); |
e3fac20d3015
*** empty log message ***
Richard M. Stallman <rms@gnu.org>
parents:
648
diff
changeset
|
2258 defsubr (&Snumber_or_marker_p); |
298 | 2259 #ifdef LISP_FLOAT_TYPE |
2260 defsubr (&Sfloatp); | |
2261 #endif /* LISP_FLOAT_TYPE */ | |
2262 defsubr (&Snatnump); | |
2263 defsubr (&Ssymbolp); | |
2264 defsubr (&Sstringp); | |
2265 defsubr (&Svectorp); | |
2266 defsubr (&Sarrayp); | |
2267 defsubr (&Ssequencep); | |
2268 defsubr (&Sbufferp); | |
2269 defsubr (&Smarkerp); | |
2270 defsubr (&Ssubrp); | |
1821
04fb1d3d6992
JimB's changes since January 18th
Jim Blandy <jimb@redhat.com>
parents:
1648
diff
changeset
|
2271 defsubr (&Sbyte_code_function_p); |
298 | 2272 defsubr (&Schar_or_string_p); |
2273 defsubr (&Scar); | |
2274 defsubr (&Scdr); | |
2275 defsubr (&Scar_safe); | |
2276 defsubr (&Scdr_safe); | |
2277 defsubr (&Ssetcar); | |
2278 defsubr (&Ssetcdr); | |
2279 defsubr (&Ssymbol_function); | |
648 | 2280 defsubr (&Sindirect_function); |
298 | 2281 defsubr (&Ssymbol_plist); |
2282 defsubr (&Ssymbol_name); | |
2283 defsubr (&Smakunbound); | |
2284 defsubr (&Sfmakunbound); | |
2285 defsubr (&Sboundp); | |
2286 defsubr (&Sfboundp); | |
2287 defsubr (&Sfset); | |
2565
c1a1557bffde
(Fdefine_function): Changed name back to Fdefalias, so we get things
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2548
diff
changeset
|
2288 defsubr (&Sdefalias); |
2606
6bf6499fe4db
(Fdefine_function): New function (same code as Fdefalias).
Richard M. Stallman <rms@gnu.org>
parents:
2565
diff
changeset
|
2289 defsubr (&Sdefine_function); |
298 | 2290 defsubr (&Ssetplist); |
2291 defsubr (&Ssymbol_value); | |
2292 defsubr (&Sset); | |
2293 defsubr (&Sdefault_boundp); | |
2294 defsubr (&Sdefault_value); | |
2295 defsubr (&Sset_default); | |
2296 defsubr (&Ssetq_default); | |
2297 defsubr (&Smake_variable_buffer_local); | |
2298 defsubr (&Smake_local_variable); | |
2299 defsubr (&Skill_local_variable); | |
2300 defsubr (&Saref); | |
2301 defsubr (&Saset); | |
2429
96b55f2f19cd
Rename int-to-string to number-to-string, since it can handle
Jim Blandy <jimb@redhat.com>
parents:
2092
diff
changeset
|
2302 defsubr (&Snumber_to_string); |
1914
60965a5c325f
* data.c (Fstring_to_number): Skip initial spaces, to make Emacs
Jim Blandy <jimb@redhat.com>
parents:
1821
diff
changeset
|
2303 defsubr (&Sstring_to_number); |
298 | 2304 defsubr (&Seqlsign); |
2305 defsubr (&Slss); | |
2306 defsubr (&Sgtr); | |
2307 defsubr (&Sleq); | |
2308 defsubr (&Sgeq); | |
2309 defsubr (&Sneq); | |
2310 defsubr (&Szerop); | |
2311 defsubr (&Splus); | |
2312 defsubr (&Sminus); | |
2313 defsubr (&Stimes); | |
2314 defsubr (&Squo); | |
2315 defsubr (&Srem); | |
4508
763987892042
(Fmod): New function; result is always same sign as divisor.
Paul Eggert <eggert@twinsun.com>
parents:
4447
diff
changeset
|
2316 defsubr (&Smod); |
298 | 2317 defsubr (&Smax); |
2318 defsubr (&Smin); | |
2319 defsubr (&Slogand); | |
2320 defsubr (&Slogior); | |
2321 defsubr (&Slogxor); | |
2322 defsubr (&Slsh); | |
2323 defsubr (&Sash); | |
2324 defsubr (&Sadd1); | |
2325 defsubr (&Ssub1); | |
2326 defsubr (&Slognot); | |
6459
30fabcc03f0c
(Qwholenump): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6448
diff
changeset
|
2327 |
30fabcc03f0c
(Qwholenump): New variable.
Richard M. Stallman <rms@gnu.org>
parents:
6448
diff
changeset
|
2328 Fset (Qwholenump, Qnatnump); |
298 | 2329 } |
2330 | |
490 | 2331 SIGTYPE |
298 | 2332 arith_error (signo) |
2333 int signo; | |
2334 { | |
2335 #ifdef USG | |
2336 /* USG systems forget handlers when they are used; | |
2337 must reestablish each time */ | |
2338 signal (signo, arith_error); | |
2339 #endif /* USG */ | |
2340 #ifdef VMS | |
2341 /* VMS systems are like USG. */ | |
2342 signal (signo, arith_error); | |
2343 #endif /* VMS */ | |
2344 #ifdef BSD4_1 | |
2345 sigrelse (SIGFPE); | |
2346 #else /* not BSD4_1 */ | |
638 | 2347 sigsetmask (SIGEMPTYMASK); |
298 | 2348 #endif /* not BSD4_1 */ |
2349 | |
2350 Fsignal (Qarith_error, Qnil); | |
2351 } | |
2352 | |
2353 init_data () | |
2354 { | |
2355 /* Don't do this if just dumping out. | |
2356 We don't want to call `signal' in this case | |
2357 so that we don't have trouble with dumping | |
2358 signal-delivering routines in an inconsistent state. */ | |
2359 #ifndef CANNOT_DUMP | |
2360 if (!initialized) | |
2361 return; | |
2362 #endif /* CANNOT_DUMP */ | |
2363 signal (SIGFPE, arith_error); | |
591 | 2364 |
298 | 2365 #ifdef uts |
2366 signal (SIGEMT, arith_error); | |
2367 #endif /* uts */ | |
2368 } |