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