0
|
1 /* Primitive operations on Lisp data types for XEmacs Lisp interpreter.
|
|
2 Copyright (C) 1985, 1986, 1988, 1992, 1993, 1994, 1995
|
|
3 Free Software Foundation, Inc.
|
|
4
|
|
5 This file is part of XEmacs.
|
|
6
|
|
7 XEmacs is free software; you can redistribute it and/or modify it
|
|
8 under the terms of the GNU General Public License as published by the
|
|
9 Free Software Foundation; either version 2, or (at your option) any
|
|
10 later version.
|
|
11
|
|
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
15 for more details.
|
|
16
|
|
17 You should have received a copy of the GNU General Public License
|
|
18 along with XEmacs; see the file COPYING. If not, write to
|
|
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
20 Boston, MA 02111-1307, USA. */
|
|
21
|
|
22 /* Synched up with: Mule 2.0, FSF 19.30. Some of FSF's data.c is in
|
|
23 XEmacs' symbols.c. */
|
|
24
|
|
25 /* This file has been Mule-ized. */
|
|
26
|
|
27 #include <config.h>
|
|
28 #include "lisp.h"
|
|
29
|
|
30 #include "buffer.h"
|
|
31 #include "bytecode.h"
|
|
32
|
|
33 #include "syssignal.h"
|
|
34 #ifdef LISP_FLOAT_TYPE
|
|
35 /* Need to define a differentiating symbol -- see sysfloat.h */
|
|
36 # define THIS_FILENAME data_c
|
|
37 # include "sysfloat.h"
|
|
38 #endif /* LISP_FLOAT_TYPE */
|
|
39
|
|
40 Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound;
|
|
41 Lisp_Object Qerror_conditions, Qerror_message, Qtop_level;
|
|
42 Lisp_Object Qsignal, Qerror, Qquit, Qwrong_type_argument, Qargs_out_of_range;
|
|
43 Lisp_Object Qvoid_variable, Qcyclic_variable_indirection;
|
|
44 Lisp_Object Qvoid_function, Qcyclic_function_indirection;
|
|
45 Lisp_Object Qsetting_constant, Qinvalid_read_syntax;
|
|
46 Lisp_Object Qmalformed_list, Qmalformed_property_list;
|
|
47 Lisp_Object Qcircular_list, Qcircular_property_list;
|
|
48 Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch;
|
|
49 Lisp_Object Qio_error, Qend_of_file;
|
|
50 Lisp_Object Qarith_error, Qrange_error, Qdomain_error;
|
|
51 Lisp_Object Qsingularity_error, Qoverflow_error, Qunderflow_error;
|
|
52 Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
|
|
53 Lisp_Object Qintegerp, Qnatnump, Qsymbolp, Qkeywordp, Qlistp, Qconsp, Qsubrp;
|
|
54 Lisp_Object Qcharacterp, Qstringp, Qarrayp, Qsequencep, Qbufferp;
|
|
55 Lisp_Object Qcompiled_functionp;
|
|
56 Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp;
|
|
57 Lisp_Object Qinteger_or_char_p, Qinteger_char_or_marker_p;
|
|
58 Lisp_Object Qbit_vectorp, Qbitp;
|
|
59
|
|
60 /* Qstring, Qinteger, Qsymbol, Qvector defined in general.c */
|
|
61 Lisp_Object Qcons, Qkeyword;
|
|
62
|
|
63 Lisp_Object Qcdr;
|
|
64
|
|
65 Lisp_Object Qignore;
|
|
66
|
|
67 #ifdef LISP_FLOAT_TYPE
|
|
68 Lisp_Object Qfloatp;
|
|
69 #endif
|
|
70 Lisp_Object Qnumberp, Qnumber_or_marker_p, Qnumber_char_or_marker_p;
|
|
71
|
|
72 Lisp_Object Qweak_listp;
|
70
|
73
|
|
74 #ifdef DEBUG_XEMACS
|
|
75
|
|
76 int debug_issue_ebola_notices;
|
|
77
|
|
78 int debug_ebola_backtrace_length;
|
|
79
|
|
80 int
|
|
81 eq_with_ebola_notice (Lisp_Object obj1, Lisp_Object obj2)
|
|
82 {
|
|
83 if (((CHARP (obj1) && INTP (obj2)) || (CHARP (obj2) && INTP (obj1)))
|
|
84 && (debug_issue_ebola_notices >= 2
|
|
85 || XREALINT (obj1) == XREALINT (obj2)))
|
|
86 {
|
108
|
87 /* Continuing the joke by printing `Ebola warning!!!' confuses */
|
|
88 /* too many people. The message must be printed because Emacs used */
|
|
89 /* to work differently for two decades. */
|
|
90 stderr_out("Comparison between integer and character is constant nil (");
|
70
|
91 Fprinc (obj1, Qexternal_debugging_output);
|
|
92 stderr_out (" and ");
|
|
93 Fprinc (obj2, Qexternal_debugging_output);
|
|
94 stderr_out (")\n");
|
|
95 debug_short_backtrace (debug_ebola_backtrace_length);
|
|
96 }
|
|
97
|
|
98 return EQ (obj1, obj2);
|
|
99 }
|
|
100
|
|
101 #endif /* DEBUG_XEMACS */
|
|
102
|
|
103
|
0
|
104
|
|
105 Lisp_Object
|
|
106 wrong_type_argument (Lisp_Object predicate, Lisp_Object value)
|
|
107 {
|
|
108 /* This function can GC */
|
|
109 REGISTER Lisp_Object tem;
|
|
110 do
|
|
111 {
|
|
112 value = Fsignal (Qwrong_type_argument, list2 (predicate, value));
|
|
113 tem = call1 (predicate, value);
|
|
114 }
|
|
115 while (NILP (tem));
|
|
116 return value;
|
|
117 }
|
|
118
|
|
119 DOESNT_RETURN
|
|
120 dead_wrong_type_argument (Lisp_Object predicate, Lisp_Object value)
|
|
121 {
|
|
122 signal_error (Qwrong_type_argument, list2 (predicate, value));
|
|
123 }
|
|
124
|
20
|
125 DEFUN ("wrong-type-argument", Fwrong_type_argument, 2, 2, 0, /*
|
0
|
126 Signal an error until the correct type value is given by the user.
|
|
127 This function loops, signalling a continuable `wrong-type-argument' error
|
|
128 with PREDICATE and VALUE as the data associated with the error and then
|
|
129 calling PREDICATE on the returned value, until the value gotten satisfies
|
|
130 PREDICATE. At that point, the gotten value is returned.
|
20
|
131 */
|
|
132 (predicate, value))
|
0
|
133 {
|
|
134 return wrong_type_argument (predicate, value);
|
|
135 }
|
|
136
|
|
137 DOESNT_RETURN
|
|
138 pure_write_error (void)
|
|
139 {
|
|
140 error ("Attempt to modify read-only object");
|
|
141 }
|
|
142
|
|
143 DOESNT_RETURN
|
|
144 args_out_of_range (Lisp_Object a1, Lisp_Object a2)
|
|
145 {
|
|
146 signal_error (Qargs_out_of_range, list2 (a1, a2));
|
|
147 }
|
|
148
|
|
149 DOESNT_RETURN
|
|
150 args_out_of_range_3 (Lisp_Object a1, Lisp_Object a2, Lisp_Object a3)
|
|
151 {
|
|
152 signal_error (Qargs_out_of_range, list3 (a1, a2, a3));
|
|
153 }
|
|
154
|
|
155 void
|
|
156 check_int_range (int val, int min, int max)
|
|
157 {
|
|
158 if (val < min || val > max)
|
|
159 args_out_of_range_3 (make_int (val), make_int (min),
|
|
160 make_int (max));
|
|
161 }
|
|
162
|
|
163 #ifndef make_int
|
|
164 Lisp_Object
|
|
165 make_int (EMACS_INT num)
|
|
166 {
|
|
167 Lisp_Object val;
|
|
168 /* Don't use XSETINT here -- it's defined in terms of make_int (). */
|
|
169 XSETOBJ (val, Lisp_Int, num);
|
|
170 return val;
|
|
171 }
|
|
172 #endif /* ! defined (make_int) */
|
|
173
|
|
174 /* On some machines, XINT needs a temporary location.
|
|
175 Here it is, in case it is needed. */
|
|
176
|
|
177 EMACS_INT sign_extend_temp;
|
|
178
|
|
179 /* On a few machines, XINT can only be done by calling this. */
|
|
180 /* XEmacs: only used by m/convex.h */
|
|
181 int sign_extend_lisp_int (EMACS_INT num);
|
|
182 int
|
|
183 sign_extend_lisp_int (EMACS_INT num)
|
|
184 {
|
|
185 if (num & (1L << (VALBITS - 1)))
|
|
186 return num | ((-1L) << VALBITS);
|
|
187 else
|
|
188 return num & ((1L << VALBITS) - 1);
|
|
189 }
|
|
190
|
|
191 /* characters do not need to sign extend so there's no need for special
|
|
192 futzing like with ints. */
|
|
193 Lisp_Object
|
|
194 make_char (Emchar num)
|
|
195 {
|
16
|
196 Lisp_Object val;
|
70
|
197 /* Don't use XSETCHAR here -- it's defined in terms of make_char (). */
|
|
198 XSETOBJ (val, Lisp_Char, num);
|
16
|
199 return val;
|
0
|
200 }
|
|
201
|
|
202 /* Data type predicates */
|
|
203
|
20
|
204 DEFUN ("eq", Feq, 2, 2, 0, /*
|
0
|
205 T if the two args are the same Lisp object.
|
20
|
206 */
|
|
207 (obj1, obj2))
|
0
|
208 {
|
70
|
209 return EQ_WITH_EBOLA_NOTICE (obj1, obj2) ? Qt : Qnil;
|
|
210 }
|
|
211
|
|
212 DEFUN ("old-eq", Fold_eq, 2, 2, 0, /*
|
|
213 T if the two args are (in most cases) the same Lisp object.
|
|
214
|
|
215 Special kludge: A character is considered `old-eq' to its equivalent integer
|
|
216 even though they are not the same object and are in fact of different
|
|
217 types. This is ABSOLUTELY AND UTTERLY HORRENDOUS but is necessary to
|
|
218 preserve byte-code compatibility with v19. This kludge is known as the
|
104
|
219 \"char-to-int confoundance disease\" and appears in a number of other
|
70
|
220 functions with `old-foo' equivalents.
|
|
221
|
|
222 Do not use this function!
|
|
223 */
|
|
224 (obj1, obj2))
|
|
225 {
|
|
226 /* The miscreant responsible for this blasphemy is known as
|
|
227 Richard M. Stallman, and he will burn in hell for it. */
|
|
228 return HACKEQ_UNSAFE (obj1, obj2) ? Qt : Qnil;
|
0
|
229 }
|
|
230
|
20
|
231 DEFUN ("null", Fnull, 1, 1, 0, /*
|
0
|
232 T if OBJECT is nil.
|
20
|
233 */
|
|
234 (object))
|
0
|
235 {
|
16
|
236 return NILP (object) ? Qt : Qnil;
|
0
|
237 }
|
|
238
|
20
|
239 DEFUN ("consp", Fconsp, 1, 1, 0, /*
|
0
|
240 T if OBJECT is a cons cell.
|
20
|
241 */
|
|
242 (object))
|
0
|
243 {
|
16
|
244 return CONSP (object) ? Qt : Qnil;
|
0
|
245 }
|
|
246
|
20
|
247 DEFUN ("atom", Fatom, 1, 1, 0, /*
|
0
|
248 T if OBJECT is not a cons cell. This includes nil.
|
20
|
249 */
|
|
250 (object))
|
0
|
251 {
|
16
|
252 return CONSP (object) ? Qnil : Qt;
|
0
|
253 }
|
|
254
|
20
|
255 DEFUN ("listp", Flistp, 1, 1, 0, /*
|
0
|
256 T if OBJECT is a list. This includes nil.
|
20
|
257 */
|
|
258 (object))
|
0
|
259 {
|
16
|
260 return (CONSP (object) || NILP (object)) ? Qt : Qnil;
|
0
|
261 }
|
|
262
|
20
|
263 DEFUN ("nlistp", Fnlistp, 1, 1, 0, /*
|
0
|
264 T if OBJECT is not a list. Lists include nil.
|
20
|
265 */
|
|
266 (object))
|
0
|
267 {
|
16
|
268 return (CONSP (object) || NILP (object)) ? Qnil : Qt;
|
0
|
269 }
|
|
270
|
20
|
271 DEFUN ("symbolp", Fsymbolp, 1, 1, 0, /*
|
0
|
272 T if OBJECT is a symbol.
|
20
|
273 */
|
|
274 (object))
|
0
|
275 {
|
16
|
276 return SYMBOLP (object) ? Qt : Qnil;
|
0
|
277 }
|
|
278
|
20
|
279 DEFUN ("keywordp", Fkeywordp, 1, 1, 0, /*
|
0
|
280 T if OBJECT is a keyword.
|
20
|
281 */
|
|
282 (object))
|
0
|
283 {
|
16
|
284 return KEYWORDP (object) ? Qt : Qnil;
|
0
|
285 }
|
|
286
|
20
|
287 DEFUN ("vectorp", Fvectorp, 1, 1, 0, /*
|
0
|
288 T if OBJECT is a vector.
|
20
|
289 */
|
|
290 (object))
|
0
|
291 {
|
16
|
292 return VECTORP (object) ? Qt : Qnil;
|
0
|
293 }
|
|
294
|
20
|
295 DEFUN ("bit-vector-p", Fbit_vector_p, 1, 1, 0, /*
|
0
|
296 T if OBJECT is a bit vector.
|
20
|
297 */
|
|
298 (object))
|
0
|
299 {
|
16
|
300 return BIT_VECTORP (object) ? Qt : Qnil;
|
0
|
301 }
|
|
302
|
20
|
303 DEFUN ("stringp", Fstringp, 1, 1, 0, /*
|
0
|
304 T if OBJECT is a string.
|
20
|
305 */
|
|
306 (object))
|
0
|
307 {
|
16
|
308 return STRINGP (object) ? Qt : Qnil;
|
0
|
309 }
|
|
310
|
20
|
311 DEFUN ("arrayp", Farrayp, 1, 1, 0, /*
|
0
|
312 T if OBJECT is an array (string, vector, or bit vector).
|
20
|
313 */
|
|
314 (object))
|
0
|
315 {
|
16
|
316 return (VECTORP (object) ||
|
|
317 STRINGP (object) ||
|
|
318 BIT_VECTORP (object))
|
|
319 ? Qt : Qnil;
|
0
|
320 }
|
|
321
|
20
|
322 DEFUN ("sequencep", Fsequencep, 1, 1, 0, /*
|
0
|
323 T if OBJECT is a sequence (list or array).
|
20
|
324 */
|
|
325 (object))
|
0
|
326 {
|
16
|
327 return (CONSP (object) ||
|
|
328 NILP (object) ||
|
|
329 VECTORP (object) ||
|
|
330 STRINGP (object) ||
|
|
331 BIT_VECTORP (object))
|
|
332 ? Qt : Qnil;
|
0
|
333 }
|
|
334
|
20
|
335 DEFUN ("markerp", Fmarkerp, 1, 1, 0, /*
|
0
|
336 T if OBJECT is a marker (editor pointer).
|
20
|
337 */
|
|
338 (object))
|
0
|
339 {
|
16
|
340 return MARKERP (object) ? Qt : Qnil;
|
0
|
341 }
|
|
342
|
20
|
343 DEFUN ("subrp", Fsubrp, 1, 1, 0, /*
|
0
|
344 T if OBJECT is a built-in function.
|
20
|
345 */
|
|
346 (object))
|
0
|
347 {
|
16
|
348 return SUBRP (object) ? Qt : Qnil;
|
0
|
349 }
|
|
350
|
20
|
351 DEFUN ("subr-min-args", Fsubr_min_args, 1, 1, 0, /*
|
0
|
352 Return minimum number of args built-in function SUBR may be called with.
|
20
|
353 */
|
|
354 (subr))
|
0
|
355 {
|
|
356 CHECK_SUBR (subr);
|
|
357 return make_int (XSUBR (subr)->min_args);
|
|
358 }
|
|
359
|
20
|
360 DEFUN ("subr-max-args", Fsubr_max_args, 1, 1, 0, /*
|
0
|
361 Return maximum number of args built-in function SUBR may be called with,
|
16
|
362 or nil if it takes an arbitrary number of arguments or is a special form.
|
20
|
363 */
|
|
364 (subr))
|
0
|
365 {
|
|
366 int nargs;
|
|
367 CHECK_SUBR (subr);
|
|
368 nargs = XSUBR (subr)->max_args;
|
|
369 if (nargs == MANY || nargs == UNEVALLED)
|
|
370 return Qnil;
|
|
371 else
|
|
372 return make_int (nargs);
|
|
373 }
|
|
374
|
20
|
375 DEFUN ("compiled-function-p", Fcompiled_function_p, 1, 1, 0, /*
|
0
|
376 t if OBJECT is a byte-compiled function object.
|
20
|
377 */
|
|
378 (object))
|
0
|
379 {
|
16
|
380 return COMPILED_FUNCTIONP (object) ? Qt : Qnil;
|
0
|
381 }
|
|
382
|
|
383
|
20
|
384 DEFUN ("characterp", Fcharacterp, 1, 1, 0, /*
|
0
|
385 t if OBJECT is a character.
|
110
|
386 Unlike in XEmacs v19 and Emacs, a character is its own primitive type.
|
70
|
387 Any character can be converted into an equivalent integer using
|
104
|
388 `char-to-int'. To convert the other way, use `int-to-char'; however,
|
70
|
389 only some integers can be converted into characters. Such an integer
|
110
|
390 is called a `char-int'; see `char-int-p'.
|
70
|
391
|
|
392 Some functions that work on integers (e.g. the comparison functions
|
|
393 <, <=, =, /=, etc. and the arithmetic functions +, -, *, etc.)
|
|
394 accept characters and implicitly convert them into integers. In
|
|
395 general, functions that work on characters also accept char-ints and
|
|
396 implicitly convert them into characters. WARNING: Neither of these
|
|
397 behaviors is very desirable, and they are maintained for backward
|
|
398 compatibility with old E-Lisp programs that confounded characters and
|
|
399 integers willy-nilly. These behaviors may change in the future; therefore,
|
|
400 do not rely on them. Instead, use the character-specific functions such
|
|
401 as `char='.
|
20
|
402 */
|
|
403 (object))
|
0
|
404 {
|
16
|
405 return CHARP (object) ? Qt : Qnil;
|
0
|
406 }
|
|
407
|
104
|
408 DEFUN ("char-to-int", Fchar_to_int, 1, 1, 0, /*
|
70
|
409 Convert a character into an equivalent integer.
|
|
410 The resulting integer will always be non-negative. The integers in
|
|
411 the range 0 - 255 map to characters as follows:
|
|
412
|
|
413 0 - 31 Control set 0
|
|
414 32 - 127 ASCII
|
|
415 128 - 159 Control set 1
|
|
416 160 - 255 Right half of ISO-8859-1
|
|
417
|
|
418 If support for Mule does not exist, these are the only valid character
|
|
419 values. When Mule support exists, the values assigned to other characters
|
|
420 may vary depending on the particular version of XEmacs, the order in which
|
|
421 character sets were loaded, etc., and you should not depend on them.
|
|
422 */
|
|
423 (ch))
|
|
424 {
|
|
425 CHECK_CHAR (ch);
|
|
426 return make_int (XCHAR (ch));
|
|
427 }
|
|
428
|
104
|
429 DEFUN ("int-to-char", Fint_to_char, 1, 1, 0, /*
|
70
|
430 Convert an integer into the equivalent character.
|
|
431 Not all integers correspond to valid characters; use `char-int-p' to
|
|
432 determine whether this is the case. If the integer cannot be converted,
|
|
433 nil is returned.
|
|
434 */
|
|
435 (integer))
|
|
436 {
|
|
437 CHECK_INT (integer);
|
|
438 if (CHAR_INTP (integer))
|
|
439 return make_char (XINT (integer));
|
|
440 else
|
|
441 return Qnil;
|
|
442 }
|
|
443
|
|
444 DEFUN ("char-int-p", Fchar_int_p, 1, 1, 0, /*
|
|
445 t if OBJECT is an integer that can be converted into a character.
|
104
|
446 See `char-to-int'.
|
70
|
447 */
|
|
448 (object))
|
|
449 {
|
|
450 return CHAR_INTP (object) ? Qt : Qnil;
|
|
451 }
|
|
452
|
|
453 DEFUN ("char-or-char-int-p", Fchar_or_char_int_p, 1, 1, 0, /*
|
|
454 t if OBJECT is a character or an integer that can be converted into one.
|
|
455 */
|
|
456 (object))
|
|
457 {
|
|
458 return CHAR_OR_CHAR_INTP (object) ? Qt : Qnil;
|
|
459 }
|
|
460
|
20
|
461 DEFUN ("char-or-string-p", Fchar_or_string_p, 1, 1, 0, /*
|
70
|
462 t if OBJECT is a character (or a char-int) or a string.
|
|
463 It is semi-hateful that we allow a char-int here, as it goes against
|
|
464 the name of this function, but it makes the most sense considering the
|
|
465 other steps we take to maintain compatibility with the old character/integer
|
|
466 confoundedness in older versions of E-Lisp.
|
20
|
467 */
|
|
468 (object))
|
0
|
469 {
|
16
|
470 return CHAR_OR_CHAR_INTP (object) || STRINGP (object) ? Qt : Qnil;
|
0
|
471 }
|
|
472
|
20
|
473 DEFUN ("integerp", Fintegerp, 1, 1, 0, /*
|
0
|
474 t if OBJECT is an integer.
|
20
|
475 */
|
|
476 (object))
|
0
|
477 {
|
16
|
478 return INTP (object) ? Qt : Qnil;
|
0
|
479 }
|
|
480
|
20
|
481 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, 1, 1, 0, /*
|
0
|
482 t if OBJECT is an integer or a marker (editor pointer).
|
20
|
483 */
|
|
484 (object))
|
0
|
485 {
|
16
|
486 return INTP (object) || MARKERP (object) ? Qt : Qnil;
|
0
|
487 }
|
|
488
|
70
|
489 DEFUN ("integer-or-char-p", Finteger_or_char_p, 1, 1, 0, /*
|
|
490 t if OBJECT is an integer or a character.
|
|
491 */
|
|
492 (object))
|
|
493 {
|
|
494 return INTP (object) || CHARP (object) ? Qt : Qnil;
|
|
495 }
|
|
496
|
|
497 DEFUN ("integer-char-or-marker-p", Finteger_char_or_marker_p, 1, 1, 0, /*
|
|
498 t if OBJECT is an integer, character or a marker (editor pointer).
|
|
499 */
|
|
500 (object))
|
|
501 {
|
|
502 return INTP (object) || CHARP (object) || MARKERP (object) ? Qt : Qnil;
|
|
503 }
|
|
504
|
20
|
505 DEFUN ("natnump", Fnatnump, 1, 1, 0, /*
|
0
|
506 t if OBJECT is a nonnegative integer.
|
20
|
507 */
|
|
508 (object))
|
0
|
509 {
|
16
|
510 return NATNUMP (object) ? Qt : Qnil;
|
0
|
511 }
|
|
512
|
20
|
513 DEFUN ("bitp", Fbitp, 1, 1, 0, /*
|
0
|
514 t if OBJECT is a bit (0 or 1).
|
20
|
515 */
|
|
516 (object))
|
0
|
517 {
|
16
|
518 return BITP (object) ? Qt : Qnil;
|
0
|
519 }
|
|
520
|
20
|
521 DEFUN ("numberp", Fnumberp, 1, 1, 0, /*
|
0
|
522 t if OBJECT is a number (floating point or integer).
|
20
|
523 */
|
|
524 (object))
|
0
|
525 {
|
16
|
526 return INT_OR_FLOATP (object) ? Qt : Qnil;
|
0
|
527 }
|
|
528
|
20
|
529 DEFUN ("number-or-marker-p", Fnumber_or_marker_p, 1, 1, 0, /*
|
0
|
530 t if OBJECT is a number or a marker.
|
20
|
531 */
|
|
532 (object))
|
0
|
533 {
|
16
|
534 return INT_OR_FLOATP (object) || MARKERP (object) ? Qt : Qnil;
|
0
|
535 }
|
|
536
|
70
|
537 DEFUN ("number-char-or-marker-p", Fnumber_char_or_marker_p, 1, 1, 0, /*
|
|
538 t if OBJECT is a number, character or a marker.
|
|
539 */
|
|
540 (object))
|
|
541 {
|
|
542 return (INT_OR_FLOATP (object) ||
|
|
543 CHARP (object) ||
|
|
544 MARKERP (object))
|
|
545 ? Qt : Qnil;
|
|
546 }
|
|
547
|
0
|
548 #ifdef LISP_FLOAT_TYPE
|
20
|
549 DEFUN ("floatp", Ffloatp, 1, 1, 0, /*
|
0
|
550 t if OBJECT is a floating point number.
|
20
|
551 */
|
|
552 (object))
|
0
|
553 {
|
16
|
554 return FLOATP (object) ? Qt : Qnil;
|
0
|
555 }
|
|
556 #endif /* LISP_FLOAT_TYPE */
|
|
557
|
20
|
558 DEFUN ("type-of", Ftype_of, 1, 1, 0, /*
|
0
|
559 Return a symbol representing the type of OBJECT.
|
20
|
560 */
|
|
561 (object))
|
0
|
562 {
|
16
|
563 if (CONSP (object)) return Qcons;
|
|
564 if (SYMBOLP (object)) return Qsymbol;
|
|
565 if (KEYWORDP (object)) return Qkeyword;
|
|
566 if (INTP (object)) return Qinteger;
|
70
|
567 if (CHARP (object)) return Qcharacter;
|
16
|
568 if (STRINGP (object)) return Qstring;
|
|
569 if (VECTORP (object)) return Qvector;
|
|
570
|
0
|
571 assert (LRECORDP (object));
|
|
572 return intern (XRECORD_LHEADER (object)->implementation->name);
|
|
573 }
|
|
574
|
|
575
|
|
576 /* Extract and set components of lists */
|
|
577
|
20
|
578 DEFUN ("car", Fcar, 1, 1, 0, /*
|
0
|
579 Return the car of LIST. If arg is nil, return nil.
|
|
580 Error if arg is not nil and not a cons cell. See also `car-safe'.
|
20
|
581 */
|
|
582 (list))
|
0
|
583 {
|
|
584 while (1)
|
|
585 {
|
|
586 if (CONSP (list))
|
|
587 return XCAR (list);
|
|
588 else if (NILP (list))
|
|
589 return Qnil;
|
|
590 else
|
|
591 list = wrong_type_argument (Qconsp, list);
|
|
592 }
|
|
593 }
|
|
594
|
20
|
595 DEFUN ("car-safe", Fcar_safe, 1, 1, 0, /*
|
0
|
596 Return the car of OBJECT if it is a cons cell, or else nil.
|
20
|
597 */
|
|
598 (object))
|
0
|
599 {
|
16
|
600 return CONSP (object) ? XCAR (object) : Qnil;
|
0
|
601 }
|
|
602
|
20
|
603 DEFUN ("cdr", Fcdr, 1, 1, 0, /*
|
0
|
604 Return the cdr of LIST. If arg is nil, return nil.
|
|
605 Error if arg is not nil and not a cons cell. See also `cdr-safe'.
|
20
|
606 */
|
|
607 (list))
|
0
|
608 {
|
|
609 while (1)
|
|
610 {
|
|
611 if (CONSP (list))
|
|
612 return XCDR (list);
|
|
613 else if (NILP (list))
|
|
614 return Qnil;
|
|
615 else
|
|
616 list = wrong_type_argument (Qconsp, list);
|
|
617 }
|
|
618 }
|
|
619
|
20
|
620 DEFUN ("cdr-safe", Fcdr_safe, 1, 1, 0, /*
|
0
|
621 Return the cdr of OBJECT if it is a cons cell, or else nil.
|
20
|
622 */
|
|
623 (object))
|
0
|
624 {
|
16
|
625 return CONSP (object) ? XCDR (object) : Qnil;
|
0
|
626 }
|
|
627
|
20
|
628 DEFUN ("setcar", Fsetcar, 2, 2, 0, /*
|
0
|
629 Set the car of CONSCELL to be NEWCAR. Returns NEWCAR.
|
20
|
630 */
|
|
631 (conscell, newcar))
|
0
|
632 {
|
|
633 if (!CONSP (conscell))
|
|
634 conscell = wrong_type_argument (Qconsp, conscell);
|
|
635
|
|
636 CHECK_IMPURE (conscell);
|
|
637 XCAR (conscell) = newcar;
|
|
638 return newcar;
|
|
639 }
|
|
640
|
20
|
641 DEFUN ("setcdr", Fsetcdr, 2, 2, 0, /*
|
0
|
642 Set the cdr of CONSCELL to be NEWCDR. Returns NEWCDR.
|
20
|
643 */
|
|
644 (conscell, newcdr))
|
0
|
645 {
|
|
646 if (!CONSP (conscell))
|
|
647 conscell = wrong_type_argument (Qconsp, conscell);
|
|
648
|
|
649 CHECK_IMPURE (conscell);
|
|
650 XCDR (conscell) = newcdr;
|
|
651 return newcdr;
|
|
652 }
|
|
653
|
|
654 /* Find the function at the end of a chain of symbol function indirections. */
|
|
655
|
|
656 /* If OBJECT is a symbol, find the end of its function chain and
|
|
657 return the value found there. If OBJECT is not a symbol, just
|
|
658 return it. If there is a cycle in the function chain, signal a
|
|
659 cyclic-function-indirection error.
|
|
660
|
|
661 This is like Findirect_function, except that it doesn't signal an
|
|
662 error if the chain ends up unbound. */
|
|
663 Lisp_Object
|
|
664 indirect_function (Lisp_Object object, int errorp)
|
|
665 {
|
|
666 Lisp_Object tortoise = object;
|
16
|
667 Lisp_Object hare = object;
|
0
|
668
|
|
669 for (;;)
|
|
670 {
|
|
671 if (!SYMBOLP (hare) || UNBOUNDP (hare))
|
|
672 break;
|
|
673 hare = XSYMBOL (hare)->function;
|
|
674 if (!SYMBOLP (hare) || UNBOUNDP (hare))
|
|
675 break;
|
|
676 hare = XSYMBOL (hare)->function;
|
|
677
|
|
678 tortoise = XSYMBOL (tortoise)->function;
|
|
679
|
|
680 if (EQ (hare, tortoise))
|
|
681 return (Fsignal (Qcyclic_function_indirection, list1 (object)));
|
|
682 }
|
|
683
|
|
684 if (UNBOUNDP (hare) && errorp)
|
|
685 return Fsignal (Qvoid_function, list1 (object));
|
|
686 return hare;
|
|
687 }
|
|
688
|
20
|
689 DEFUN ("indirect-function", Findirect_function, 1, 1, 0, /*
|
0
|
690 Return the function at the end of OBJECT's function chain.
|
|
691 If OBJECT is a symbol, follow all function indirections and return
|
|
692 the final function binding.
|
|
693 If OBJECT is not a symbol, just return it.
|
|
694 Signal a void-function error if the final symbol is unbound.
|
|
695 Signal a cyclic-function-indirection error if there is a loop in the
|
|
696 function chain of symbols.
|
20
|
697 */
|
|
698 (object))
|
0
|
699 {
|
|
700 return indirect_function (object, 1);
|
|
701 }
|
|
702
|
|
703 /* Extract and set vector and string elements */
|
|
704
|
20
|
705 DEFUN ("aref", Faref, 2, 2, 0, /*
|
0
|
706 Return the element of ARRAY at index INDEX.
|
|
707 ARRAY may be a vector, bit vector, string, or byte-code object.
|
|
708 IDX starts at 0.
|
20
|
709 */
|
|
710 (array, idx))
|
0
|
711 {
|
|
712 int idxval;
|
|
713
|
|
714 retry:
|
|
715 CHECK_INT_COERCE_CHAR (idx); /* yuck! */
|
|
716 idxval = XINT (idx);
|
|
717 if (idxval < 0)
|
|
718 {
|
|
719 lose:
|
|
720 args_out_of_range (array, idx);
|
|
721 }
|
|
722 if (VECTORP (array))
|
|
723 {
|
|
724 if (idxval >= vector_length (XVECTOR (array))) goto lose;
|
|
725 return vector_data (XVECTOR (array))[idxval];
|
|
726 }
|
|
727 else if (BIT_VECTORP (array))
|
|
728 {
|
|
729 if (idxval >= bit_vector_length (XBIT_VECTOR (array))) goto lose;
|
|
730 return make_int (bit_vector_bit (XBIT_VECTOR (array), idxval));
|
|
731 }
|
|
732 else if (STRINGP (array))
|
|
733 {
|
|
734 if (idxval >= string_char_length (XSTRING (array))) goto lose;
|
|
735 return (make_char (string_char (XSTRING (array), idxval)));
|
|
736 }
|
|
737 #ifdef LOSING_BYTECODE
|
|
738 else if (COMPILED_FUNCTIONP (array))
|
|
739 {
|
|
740 /* Weird, gross compatibility kludge */
|
|
741 return (Felt (array, idx));
|
|
742 }
|
|
743 #endif
|
|
744 else
|
|
745 {
|
|
746 check_losing_bytecode ("aref", array);
|
|
747 array = wrong_type_argument (Qarrayp, array);
|
|
748 goto retry;
|
|
749 }
|
|
750 }
|
|
751
|
20
|
752 DEFUN ("aset", Faset, 3, 3, 0, /*
|
0
|
753 Store into the element of ARRAY at index IDX the value NEWVAL.
|
|
754 ARRAY may be a vector, bit vector, or string. IDX starts at 0.
|
20
|
755 */
|
|
756 (array, idx, newval))
|
0
|
757 {
|
|
758 int idxval;
|
|
759
|
|
760 CHECK_INT_COERCE_CHAR (idx); /* yuck! */
|
|
761 if (!VECTORP (array) && !BIT_VECTORP (array) && !STRINGP (array))
|
|
762 array = wrong_type_argument (Qarrayp, array);
|
|
763
|
|
764 idxval = XINT (idx);
|
|
765 if (idxval < 0)
|
|
766 {
|
|
767 lose:
|
|
768 args_out_of_range (array, idx);
|
|
769 }
|
|
770 CHECK_IMPURE (array);
|
|
771
|
|
772 if (VECTORP (array))
|
|
773 {
|
|
774 if (idxval >= vector_length (XVECTOR (array))) goto lose;
|
|
775 vector_data (XVECTOR (array))[idxval] = newval;
|
|
776 }
|
|
777 else if (BIT_VECTORP (array))
|
|
778 {
|
|
779 if (idxval >= bit_vector_length (XBIT_VECTOR (array))) goto lose;
|
|
780 CHECK_BIT (newval);
|
|
781 set_bit_vector_bit (XBIT_VECTOR (array), idxval, !ZEROP (newval));
|
|
782 }
|
|
783 else /* string */
|
|
784 {
|
|
785 CHECK_CHAR_COERCE_INT (newval);
|
|
786 if (idxval >= string_char_length (XSTRING (array))) goto lose;
|
|
787 set_string_char (XSTRING (array), idxval, XCHAR (newval));
|
|
788 bump_string_modiff (array);
|
|
789 }
|
|
790
|
|
791 return newval;
|
|
792 }
|
|
793
|
|
794
|
|
795 /**********************************************************************/
|
|
796 /* Compiled-function objects */
|
|
797 /**********************************************************************/
|
|
798
|
|
799 /* The compiled_function->doc_and_interactive slot uses the minimal
|
|
800 number of conses, based on compiled_function->flags; it may take
|
|
801 any of the following forms:
|
|
802
|
|
803 doc
|
|
804 interactive
|
|
805 domain
|
|
806 (doc . interactive)
|
|
807 (doc . domain)
|
|
808 (interactive . domain)
|
|
809 (doc . (interactive . domain))
|
|
810 */
|
|
811
|
|
812 /* Caller must check flags.interactivep first */
|
|
813 Lisp_Object
|
|
814 compiled_function_interactive (struct Lisp_Compiled_Function *b)
|
|
815 {
|
|
816 assert (b->flags.interactivep);
|
|
817 if (b->flags.documentationp && b->flags.domainp)
|
|
818 return (XCAR (XCDR (b->doc_and_interactive)));
|
|
819 else if (b->flags.documentationp)
|
|
820 return (XCDR (b->doc_and_interactive));
|
|
821 else if (b->flags.domainp)
|
|
822 return (XCAR (b->doc_and_interactive));
|
|
823
|
|
824 /* if all else fails... */
|
|
825 return (b->doc_and_interactive);
|
|
826 }
|
|
827
|
|
828 /* Caller need not check flags.documentationp first */
|
|
829 Lisp_Object
|
|
830 compiled_function_documentation (struct Lisp_Compiled_Function *b)
|
|
831 {
|
|
832 if (! b->flags.documentationp)
|
|
833 return Qnil;
|
|
834 else if (b->flags.interactivep && b->flags.domainp)
|
|
835 return (XCAR (b->doc_and_interactive));
|
|
836 else if (b->flags.interactivep)
|
|
837 return (XCAR (b->doc_and_interactive));
|
|
838 else if (b->flags.domainp)
|
|
839 return (XCAR (b->doc_and_interactive));
|
|
840 else
|
|
841 return (b->doc_and_interactive);
|
|
842 }
|
|
843
|
|
844 /* Caller need not check flags.domainp first */
|
|
845 Lisp_Object
|
|
846 compiled_function_domain (struct Lisp_Compiled_Function *b)
|
|
847 {
|
|
848 if (! b->flags.domainp)
|
|
849 return Qnil;
|
|
850 else if (b->flags.documentationp && b->flags.interactivep)
|
|
851 return (XCDR (XCDR (b->doc_and_interactive)));
|
|
852 else if (b->flags.documentationp)
|
|
853 return (XCDR (b->doc_and_interactive));
|
|
854 else if (b->flags.interactivep)
|
|
855 return (XCDR (b->doc_and_interactive));
|
|
856 else
|
|
857 return (b->doc_and_interactive);
|
|
858 }
|
|
859
|
|
860 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
861
|
|
862 Lisp_Object
|
|
863 compiled_function_annotation (struct Lisp_Compiled_Function *b)
|
|
864 {
|
|
865 return b->annotated;
|
|
866 }
|
|
867
|
|
868 #endif
|
|
869
|
|
870 /* used only by Snarf-documentation; there must be doc already. */
|
|
871 void
|
|
872 set_compiled_function_documentation (struct Lisp_Compiled_Function *b,
|
|
873 Lisp_Object new)
|
|
874 {
|
|
875 assert (b->flags.documentationp);
|
|
876 assert (INTP (new) || STRINGP (new));
|
|
877
|
|
878 if (b->flags.interactivep && b->flags.domainp)
|
|
879 XCAR (b->doc_and_interactive) = new;
|
|
880 else if (b->flags.interactivep)
|
|
881 XCAR (b->doc_and_interactive) = new;
|
|
882 else if (b->flags.domainp)
|
|
883 XCAR (b->doc_and_interactive) = new;
|
|
884 else
|
|
885 b->doc_and_interactive = new;
|
|
886 }
|
|
887
|
20
|
888 DEFUN ("compiled-function-instructions", Fcompiled_function_instructions, 1, 1, 0, /*
|
0
|
889 Return the byte-opcode string of the compiled-function object.
|
20
|
890 */
|
|
891 (function))
|
0
|
892 {
|
|
893 CHECK_COMPILED_FUNCTION (function);
|
|
894 return (XCOMPILED_FUNCTION (function)->bytecodes);
|
|
895 }
|
|
896
|
20
|
897 DEFUN ("compiled-function-constants", Fcompiled_function_constants, 1, 1, 0, /*
|
0
|
898 Return the constants vector of the compiled-function object.
|
20
|
899 */
|
|
900 (function))
|
0
|
901 {
|
|
902 CHECK_COMPILED_FUNCTION (function);
|
|
903 return (XCOMPILED_FUNCTION (function)->constants);
|
|
904 }
|
|
905
|
20
|
906 DEFUN ("compiled-function-stack-depth", Fcompiled_function_stack_depth, 1, 1, 0, /*
|
0
|
907 Return the max stack depth of the compiled-function object.
|
20
|
908 */
|
|
909 (function))
|
0
|
910 {
|
|
911 CHECK_COMPILED_FUNCTION (function);
|
|
912 return (make_int (XCOMPILED_FUNCTION (function)->maxdepth));
|
|
913 }
|
|
914
|
20
|
915 DEFUN ("compiled-function-arglist", Fcompiled_function_arglist, 1, 1, 0, /*
|
0
|
916 Return the argument list of the compiled-function object.
|
20
|
917 */
|
|
918 (function))
|
0
|
919 {
|
|
920 CHECK_COMPILED_FUNCTION (function);
|
|
921 return (XCOMPILED_FUNCTION (function)->arglist);
|
|
922 }
|
|
923
|
20
|
924 DEFUN ("compiled-function-interactive", Fcompiled_function_interactive, 1, 1, 0, /*
|
0
|
925 Return the interactive spec of the compiled-function object, or nil.
|
|
926 If non-nil, the return value will be a list whose first element is
|
|
927 `interactive' and whose second element is the interactive spec.
|
20
|
928 */
|
|
929 (function))
|
0
|
930 {
|
|
931 CHECK_COMPILED_FUNCTION (function);
|
|
932 if (!XCOMPILED_FUNCTION (function)->flags.interactivep)
|
|
933 return Qnil;
|
|
934 return (list2 (Qinteractive,
|
|
935 compiled_function_interactive
|
|
936 (XCOMPILED_FUNCTION (function))));
|
|
937 }
|
|
938
|
20
|
939 DEFUN ("compiled-function-doc-string", Fcompiled_function_doc_string, 1, 1, 0, /*
|
0
|
940 Return the doc string of the compiled-function object, if available.
|
20
|
941 */
|
|
942 (function))
|
0
|
943 {
|
|
944 CHECK_COMPILED_FUNCTION (function);
|
|
945 if (!XCOMPILED_FUNCTION (function)->flags.interactivep)
|
|
946 return Qnil;
|
|
947 return (list2 (Qinteractive,
|
|
948 compiled_function_interactive
|
|
949 (XCOMPILED_FUNCTION (function))));
|
|
950 }
|
|
951
|
|
952 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
|
953
|
20
|
954 DEFUN ("compiled-function-annotation", Fcompiled_function_annotation, 1, 1, 0, /*
|
0
|
955 Return the annotation of the compiled-function object, or nil.
|
|
956 The annotation is a piece of information indicating where this
|
|
957 compiled-function object came from. Generally this will be
|
|
958 a symbol naming a function; or a string naming a file, if the
|
|
959 compiled-function object was not defined in a function; or nil,
|
|
960 if the compiled-function object was not created as a result of
|
|
961 a `load'.
|
20
|
962 */
|
|
963 (function))
|
0
|
964 {
|
|
965 CHECK_COMPILED_FUNCTION (function);
|
|
966 return (compiled_function_annotation (XCOMPILED_FUNCTION (function)));
|
|
967 }
|
|
968
|
|
969 #endif /* COMPILED_FUNCTION_ANNOTATION_HACK */
|
|
970
|
20
|
971 DEFUN ("compiled-function-domain", Fcompiled_function_domain, 1, 1, 0, /*
|
0
|
972 Return the domain of the compiled-function object, or nil.
|
|
973 This is only meaningful if I18N3 was enabled when emacs was compiled.
|
20
|
974 */
|
|
975 (function))
|
0
|
976 {
|
|
977 CHECK_COMPILED_FUNCTION (function);
|
|
978 if (!XCOMPILED_FUNCTION (function)->flags.domainp)
|
|
979 return Qnil;
|
|
980 return (compiled_function_domain (XCOMPILED_FUNCTION (function)));
|
|
981 }
|
|
982
|
|
983
|
|
984 /**********************************************************************/
|
|
985 /* Arithmetic functions */
|
|
986 /**********************************************************************/
|
|
987
|
|
988 enum comparison { equal, notequal, less, grtr, less_or_equal, grtr_or_equal };
|
|
989
|
|
990 static Lisp_Object
|
16
|
991 arithcompare (Lisp_Object num1, Lisp_Object num2, enum comparison comparison)
|
0
|
992 {
|
|
993 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (num1);
|
|
994 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (num2);
|
|
995
|
|
996 #ifdef LISP_FLOAT_TYPE
|
|
997 if (FLOATP (num1) || FLOATP (num2))
|
|
998 {
|
16
|
999 double f1 = (FLOATP (num1)) ? float_data (XFLOAT (num1)) : XINT (num1);
|
|
1000 double f2 = (FLOATP (num2)) ? float_data (XFLOAT (num2)) : XINT (num2);
|
0
|
1001
|
|
1002 switch (comparison)
|
16
|
1003 {
|
|
1004 case equal: return f1 == f2 ? Qt : Qnil;
|
|
1005 case notequal: return f1 != f2 ? Qt : Qnil;
|
|
1006 case less: return f1 < f2 ? Qt : Qnil;
|
|
1007 case less_or_equal: return f1 <= f2 ? Qt : Qnil;
|
|
1008 case grtr: return f1 > f2 ? Qt : Qnil;
|
|
1009 case grtr_or_equal: return f1 >= f2 ? Qt : Qnil;
|
|
1010 }
|
0
|
1011 }
|
|
1012 #endif /* LISP_FLOAT_TYPE */
|
70
|
1013
|
16
|
1014 switch (comparison)
|
0
|
1015 {
|
16
|
1016 case equal: return XINT (num1) == XINT (num2) ? Qt : Qnil;
|
|
1017 case notequal: return XINT (num1) != XINT (num2) ? Qt : Qnil;
|
|
1018 case less: return XINT (num1) < XINT (num2) ? Qt : Qnil;
|
|
1019 case less_or_equal: return XINT (num1) <= XINT (num2) ? Qt : Qnil;
|
|
1020 case grtr: return XINT (num1) > XINT (num2) ? Qt : Qnil;
|
|
1021 case grtr_or_equal: return XINT (num1) >= XINT (num2) ? Qt : Qnil;
|
|
1022 }
|
0
|
1023
|
|
1024 abort ();
|
|
1025 return Qnil; /* suppress compiler warning */
|
|
1026 }
|
|
1027
|
20
|
1028 DEFUN ("=", Feqlsign, 2, 2, 0, /*
|
70
|
1029 T if two args, both numbers, characters or markers, are equal.
|
20
|
1030 */
|
|
1031 (num1, num2))
|
0
|
1032 {
|
|
1033 return arithcompare (num1, num2, equal);
|
|
1034 }
|
|
1035
|
20
|
1036 DEFUN ("<", Flss, 2, 2, 0, /*
|
16
|
1037 T if first arg is less than second arg.
|
70
|
1038 Both must be numbers, characters or markers.
|
20
|
1039 */
|
|
1040 (num1, num2))
|
0
|
1041 {
|
|
1042 return arithcompare (num1, num2, less);
|
|
1043 }
|
|
1044
|
20
|
1045 DEFUN (">", Fgtr, 2, 2, 0, /*
|
16
|
1046 T if first arg is greater than second arg.
|
70
|
1047 Both must be numbers, characters or markers.
|
20
|
1048 */
|
|
1049 (num1, num2))
|
0
|
1050 {
|
|
1051 return arithcompare (num1, num2, grtr);
|
|
1052 }
|
|
1053
|
20
|
1054 DEFUN ("<=", Fleq, 2, 2, 0, /*
|
0
|
1055 T if first arg is less than or equal to second arg.
|
70
|
1056 Both must be numbers, characters or markers.
|
20
|
1057 */
|
|
1058 (num1, num2))
|
0
|
1059 {
|
|
1060 return arithcompare (num1, num2, less_or_equal);
|
|
1061 }
|
|
1062
|
20
|
1063 DEFUN (">=", Fgeq, 2, 2, 0, /*
|
0
|
1064 T if first arg is greater than or equal to second arg.
|
70
|
1065 Both must be numbers, characters or markers.
|
20
|
1066 */
|
|
1067 (num1, num2))
|
0
|
1068 {
|
|
1069 return arithcompare (num1, num2, grtr_or_equal);
|
|
1070 }
|
|
1071
|
20
|
1072 DEFUN ("/=", Fneq, 2, 2, 0, /*
|
16
|
1073 T if first arg is not equal to second arg.
|
70
|
1074 Both must be numbers, characters or markers.
|
20
|
1075 */
|
|
1076 (num1, num2))
|
0
|
1077 {
|
|
1078 return arithcompare (num1, num2, notequal);
|
|
1079 }
|
|
1080
|
70
|
1081 #if 0
|
|
1082 /* I tried implementing Common Lisp multi-arg comparison functions,
|
|
1083 but failed because the byte-compiler needs to be hacked as well. */
|
|
1084
|
|
1085 static Lisp_Object
|
|
1086 arithcompare_many (enum comparison comparison, int nargs, Lisp_Object *args)
|
|
1087 {
|
|
1088 REGISTER int argnum;
|
|
1089 for (argnum = 1; argnum < nargs; argnum++)
|
|
1090 if (EQ (arithcompare ( args[argnum-1], args[argnum], comparison), Qnil))
|
|
1091 return Qnil;
|
|
1092
|
|
1093 return Qt;
|
|
1094 }
|
|
1095
|
|
1096 xxxDEFUN ("=", Feqlsign, 1, MANY, 0, /*
|
|
1097 T if all the arguments are equal.
|
|
1098 The arguments may be numbers, characters or markers.
|
|
1099 */
|
|
1100 (int nargs, Lisp_Object *args))
|
|
1101 {
|
|
1102 return arithcompare (equal, nargs, args);
|
|
1103 }
|
|
1104
|
|
1105 xxxDEFUN ("<", Flss, 1, MANY, 0, /*
|
|
1106 T if the sequence of arguments is monotonically increasing.
|
|
1107 The arguments may be numbers, characters or markers.
|
|
1108 */
|
|
1109 (int nargs, Lisp_Object *args))
|
|
1110 {
|
|
1111 return arithcompare (less, nargs, args);
|
|
1112 }
|
|
1113
|
|
1114 xxxDEFUN (">", Fgtr, 1, MANY, 0, /*
|
|
1115 T if the sequence of arguments is monotonically decreasing.
|
|
1116 The arguments may be numbers, characters or markers.
|
|
1117 */
|
|
1118 (int nargs, Lisp_Object *args))
|
|
1119 {
|
|
1120 return arithcompare (grtr, nargs, args);
|
|
1121 }
|
|
1122
|
|
1123 xxxDEFUN ("<=", Fleq, 1, MANY, 0, /*
|
|
1124 T if the sequence of arguments is monotonically nondecreasing.
|
|
1125 The arguments may be numbers, characters or markers.
|
|
1126 */
|
|
1127 (int nargs, Lisp_Object *args))
|
|
1128 {
|
|
1129 return arithcompare (less_or_equal, nargs, args);
|
|
1130 }
|
|
1131
|
|
1132 xxxDEFUN (">=", Fgeq, 1, MANY, 0, /*
|
|
1133 T if the sequence of arguments is monotonically nonincreasing.
|
|
1134 The arguments may be numbers, characters or markers.
|
|
1135 */
|
|
1136 (int nargs, Lisp_Object *args))
|
|
1137 {
|
|
1138 return arithcompare_many (grtr_or_equal, nargs, args);
|
|
1139 }
|
|
1140
|
|
1141 xxxDEFUN ("/=", Fneq, 1, MANY, 0, /*
|
|
1142 T if the sequence of arguments is monotonically increasing.
|
|
1143 The arguments may be numbers, characters or markers.
|
|
1144 */
|
|
1145 (int nargs, Lisp_Object *args))
|
|
1146 {
|
|
1147 return arithcompare_many (notequal, nargs, args);
|
|
1148 }
|
|
1149 #endif /* 0 - disabled for now */
|
|
1150
|
20
|
1151 DEFUN ("zerop", Fzerop, 1, 1, 0, /*
|
0
|
1152 T if NUMBER is zero.
|
20
|
1153 */
|
|
1154 (number))
|
0
|
1155 {
|
|
1156 CHECK_INT_OR_FLOAT (number);
|
|
1157
|
|
1158 #ifdef LISP_FLOAT_TYPE
|
|
1159 if (FLOATP (number))
|
16
|
1160 return (float_data (XFLOAT (number)) == 0.0) ? Qt : Qnil;
|
0
|
1161 #endif /* LISP_FLOAT_TYPE */
|
|
1162
|
16
|
1163 return (XINT (number) == 0) ? Qt : Qnil;
|
0
|
1164 }
|
|
1165
|
|
1166 /* Convert between a 32-bit value and a cons of two 16-bit values.
|
|
1167 This is used to pass 32-bit integers to and from the user.
|
|
1168 Use time_to_lisp() and lisp_to_time() for time values.
|
|
1169
|
|
1170 If you're thinking of using this to store a pointer into a Lisp Object
|
|
1171 for internal purposes (such as when calling record_unwind_protect()),
|
|
1172 try using make_opaque_ptr()/get_opaque_ptr() instead. */
|
|
1173 Lisp_Object
|
|
1174 word_to_lisp (unsigned int item)
|
|
1175 {
|
|
1176 return Fcons (make_int (item >> 16), make_int (item & 0xffff));
|
|
1177 }
|
|
1178
|
|
1179 unsigned int
|
|
1180 lisp_to_word (Lisp_Object item)
|
|
1181 {
|
|
1182 if (INTP (item))
|
|
1183 return XINT (item);
|
|
1184 else
|
|
1185 {
|
|
1186 Lisp_Object top = Fcar (item);
|
|
1187 Lisp_Object bot = Fcdr (item);
|
|
1188 CHECK_INT (top);
|
|
1189 CHECK_INT (bot);
|
|
1190 return (XINT (top) << 16) | (XINT (bot) & 0xffff);
|
|
1191 }
|
|
1192 }
|
|
1193
|
|
1194
|
20
|
1195 DEFUN ("number-to-string", Fnumber_to_string, 1, 1, 0, /*
|
0
|
1196 Convert NUM to a string by printing it in decimal.
|
|
1197 Uses a minus sign if negative.
|
|
1198 NUM may be an integer or a floating point number.
|
20
|
1199 */
|
|
1200 (num))
|
0
|
1201 {
|
|
1202 char buffer[VALBITS];
|
|
1203
|
|
1204 CHECK_INT_OR_FLOAT (num);
|
|
1205
|
|
1206 #ifdef LISP_FLOAT_TYPE
|
|
1207 if (FLOATP (num))
|
|
1208 {
|
|
1209 char pigbuf[350]; /* see comments in float_to_string */
|
|
1210
|
|
1211 float_to_string (pigbuf, float_data (XFLOAT (num)));
|
|
1212 return build_string (pigbuf);
|
|
1213 }
|
|
1214 #endif /* LISP_FLOAT_TYPE */
|
|
1215
|
|
1216 if (sizeof (int) == sizeof (EMACS_INT))
|
|
1217 sprintf (buffer, "%d", XINT (num));
|
|
1218 else if (sizeof (long) == sizeof (EMACS_INT))
|
|
1219 sprintf (buffer, "%ld", (long) XINT (num));
|
|
1220 else
|
|
1221 abort ();
|
|
1222 return build_string (buffer);
|
|
1223 }
|
|
1224
|
20
|
1225 DEFUN ("string-to-number", Fstring_to_number, 1, 1, 0, /*
|
0
|
1226 Convert STRING to a number by parsing it as a decimal number.
|
|
1227 This parses both integers and floating point numbers.
|
|
1228 It ignores leading spaces and tabs.
|
20
|
1229 */
|
|
1230 (string))
|
0
|
1231 {
|
|
1232 Lisp_Object value;
|
|
1233 char *p;
|
|
1234 CHECK_STRING (string);
|
|
1235
|
16
|
1236 p = (char *) XSTRING_DATA (string);
|
0
|
1237 /* Skip any whitespace at the front of the number. Some versions of
|
|
1238 atoi do this anyway, so we might as well make Emacs lisp consistent. */
|
|
1239 while (*p == ' ' || *p == '\t')
|
|
1240 p++;
|
|
1241
|
|
1242 #ifdef LISP_FLOAT_TYPE
|
|
1243 if (isfloat_string (p))
|
|
1244 return make_float (atof (p));
|
|
1245 #endif /* LISP_FLOAT_TYPE */
|
|
1246
|
|
1247 if (sizeof (int) == sizeof (EMACS_INT))
|
|
1248 XSETINT (value, atoi (p));
|
|
1249 else if (sizeof (long) == sizeof (EMACS_INT))
|
|
1250 XSETINT (value, atol (p));
|
|
1251 else
|
|
1252 abort ();
|
|
1253 return value;
|
|
1254 }
|
|
1255
|
|
1256 enum arithop
|
|
1257 { Aadd, Asub, Amult, Adiv, Alogand, Alogior, Alogxor, Amax, Amin };
|
|
1258
|
70
|
1259
|
0
|
1260 #ifdef LISP_FLOAT_TYPE
|
|
1261 static Lisp_Object
|
|
1262 float_arith_driver (double accum, int argnum, enum arithop code, int nargs,
|
|
1263 Lisp_Object *args)
|
|
1264 {
|
|
1265 REGISTER Lisp_Object val;
|
|
1266 double next;
|
|
1267
|
|
1268 for (; argnum < nargs; argnum++)
|
|
1269 {
|
16
|
1270 /* using args[argnum] as argument to CHECK_INT_OR_FLOAT_... */
|
|
1271 val = args[argnum];
|
0
|
1272 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (val);
|
|
1273
|
|
1274 if (FLOATP (val))
|
|
1275 {
|
|
1276 next = float_data (XFLOAT (val));
|
|
1277 }
|
|
1278 else
|
|
1279 {
|
|
1280 args[argnum] = val; /* runs into a compiler bug. */
|
|
1281 next = XINT (args[argnum]);
|
|
1282 }
|
|
1283 switch (code)
|
|
1284 {
|
|
1285 case Aadd:
|
|
1286 accum += next;
|
|
1287 break;
|
|
1288 case Asub:
|
|
1289 if (!argnum && nargs != 1)
|
|
1290 next = - next;
|
|
1291 accum -= next;
|
|
1292 break;
|
|
1293 case Amult:
|
|
1294 accum *= next;
|
|
1295 break;
|
|
1296 case Adiv:
|
|
1297 if (!argnum)
|
|
1298 accum = next;
|
|
1299 else
|
|
1300 {
|
|
1301 if (next == 0)
|
|
1302 Fsignal (Qarith_error, Qnil);
|
|
1303 accum /= next;
|
|
1304 }
|
|
1305 break;
|
|
1306 case Alogand:
|
|
1307 case Alogior:
|
|
1308 case Alogxor:
|
70
|
1309 return wrong_type_argument (Qinteger_char_or_marker_p, val);
|
0
|
1310 case Amax:
|
|
1311 if (!argnum || isnan (next) || next > accum)
|
|
1312 accum = next;
|
|
1313 break;
|
|
1314 case Amin:
|
|
1315 if (!argnum || isnan (next) || next < accum)
|
|
1316 accum = next;
|
|
1317 break;
|
|
1318 }
|
|
1319 }
|
|
1320
|
|
1321 return make_float (accum);
|
|
1322 }
|
|
1323 #endif /* LISP_FLOAT_TYPE */
|
|
1324
|
16
|
1325 static Lisp_Object
|
|
1326 arith_driver (enum arithop code, int nargs, Lisp_Object *args)
|
|
1327 {
|
|
1328 Lisp_Object val;
|
|
1329 REGISTER int argnum;
|
|
1330 REGISTER EMACS_INT accum = 0;
|
|
1331 REGISTER EMACS_INT next;
|
|
1332
|
|
1333 switch (code)
|
|
1334 {
|
|
1335 case Alogior:
|
|
1336 case Alogxor:
|
|
1337 case Aadd:
|
|
1338 case Asub:
|
|
1339 accum = 0; break;
|
|
1340 case Amult:
|
|
1341 accum = 1; break;
|
|
1342 case Alogand:
|
|
1343 accum = -1; break;
|
|
1344 case Adiv:
|
|
1345 case Amax:
|
|
1346 case Amin:
|
|
1347 accum = 0; break;
|
|
1348 default:
|
|
1349 abort ();
|
|
1350 }
|
|
1351
|
|
1352 for (argnum = 0; argnum < nargs; argnum++)
|
|
1353 {
|
|
1354 /* using args[argnum] as argument to CHECK_INT_OR_FLOAT_... */
|
|
1355 val = args[argnum];
|
|
1356 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (val);
|
|
1357
|
|
1358 #ifdef LISP_FLOAT_TYPE
|
|
1359 if (FLOATP (val)) /* time to do serious math */
|
|
1360 return (float_arith_driver ((double) accum, argnum, code,
|
|
1361 nargs, args));
|
|
1362 #endif /* LISP_FLOAT_TYPE */
|
|
1363 args[argnum] = val; /* runs into a compiler bug. */
|
|
1364 next = XINT (args[argnum]);
|
|
1365 switch (code)
|
|
1366 {
|
|
1367 case Aadd: accum += next; break;
|
|
1368 case Asub:
|
|
1369 if (!argnum && nargs != 1)
|
|
1370 next = - next;
|
|
1371 accum -= next;
|
|
1372 break;
|
|
1373 case Amult: accum *= next; break;
|
|
1374 case Adiv:
|
|
1375 if (!argnum) accum = next;
|
|
1376 else
|
|
1377 {
|
|
1378 if (next == 0)
|
|
1379 Fsignal (Qarith_error, Qnil);
|
|
1380 accum /= next;
|
|
1381 }
|
|
1382 break;
|
|
1383 case Alogand: accum &= next; break;
|
|
1384 case Alogior: accum |= next; break;
|
|
1385 case Alogxor: accum ^= next; break;
|
|
1386 case Amax: if (!argnum || next > accum) accum = next; break;
|
|
1387 case Amin: if (!argnum || next < accum) accum = next; break;
|
|
1388 }
|
|
1389 }
|
|
1390
|
|
1391 XSETINT (val, accum);
|
|
1392 return val;
|
|
1393 }
|
|
1394
|
20
|
1395 DEFUN ("+", Fplus, 0, MANY, 0, /*
|
16
|
1396 Return sum of any number of arguments.
|
70
|
1397 The arguments should all be numbers, characters or markers.
|
20
|
1398 */
|
|
1399 (int nargs, Lisp_Object *args))
|
0
|
1400 {
|
|
1401 return arith_driver (Aadd, nargs, args);
|
|
1402 }
|
|
1403
|
20
|
1404 DEFUN ("-", Fminus, 0, MANY, 0, /*
|
70
|
1405 Negate number or subtract numbers, characters or markers.
|
0
|
1406 With one arg, negates it. With more than one arg,
|
|
1407 subtracts all but the first from the first.
|
20
|
1408 */
|
|
1409 (int nargs, Lisp_Object *args))
|
0
|
1410 {
|
|
1411 return arith_driver (Asub, nargs, args);
|
|
1412 }
|
|
1413
|
20
|
1414 DEFUN ("*", Ftimes, 0, MANY, 0, /*
|
16
|
1415 Return product of any number of arguments.
|
70
|
1416 The arguments should all be numbers, characters or markers.
|
20
|
1417 */
|
|
1418 (int nargs, Lisp_Object *args))
|
0
|
1419 {
|
|
1420 return arith_driver (Amult, nargs, args);
|
|
1421 }
|
|
1422
|
20
|
1423 DEFUN ("/", Fquo, 2, MANY, 0, /*
|
0
|
1424 Return first argument divided by all the remaining arguments.
|
70
|
1425 The arguments must be numbers, characters or markers.
|
20
|
1426 */
|
|
1427 (int nargs, Lisp_Object *args))
|
0
|
1428 {
|
|
1429 return arith_driver (Adiv, nargs, args);
|
|
1430 }
|
|
1431
|
20
|
1432 DEFUN ("%", Frem, 2, 2, 0, /*
|
0
|
1433 Return remainder of first arg divided by second.
|
70
|
1434 Both must be integers, characters or markers.
|
20
|
1435 */
|
|
1436 (num1, num2))
|
0
|
1437 {
|
|
1438 CHECK_INT_COERCE_CHAR_OR_MARKER (num1);
|
|
1439 CHECK_INT_COERCE_CHAR_OR_MARKER (num2);
|
|
1440
|
|
1441 if (ZEROP (num2))
|
|
1442 Fsignal (Qarith_error, Qnil);
|
|
1443
|
|
1444 return (make_int (XINT (num1) % XINT (num2)));
|
|
1445 }
|
|
1446
|
|
1447 /* Note, ANSI *requires* the presence of the fmod() library routine.
|
|
1448 If your system doesn't have it, complain to your vendor, because
|
|
1449 that is a bug. */
|
|
1450
|
|
1451 #ifndef HAVE_FMOD
|
|
1452 double
|
|
1453 fmod (double f1, double f2)
|
|
1454 {
|
|
1455 if (f2 < 0.0)
|
|
1456 f2 = -f2;
|
|
1457 return (f1 - f2 * floor (f1/f2));
|
|
1458 }
|
|
1459 #endif /* ! HAVE_FMOD */
|
|
1460
|
|
1461
|
20
|
1462 DEFUN ("mod", Fmod, 2, 2, 0, /*
|
0
|
1463 Return X modulo Y.
|
|
1464 The result falls between zero (inclusive) and Y (exclusive).
|
70
|
1465 Both X and Y must be numbers, characters or markers.
|
0
|
1466 If either argument is a float, a float will be returned.
|
20
|
1467 */
|
|
1468 (x, y))
|
0
|
1469 {
|
|
1470 EMACS_INT i1, i2;
|
|
1471
|
|
1472 #ifdef LISP_FLOAT_TYPE
|
|
1473 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (x);
|
|
1474 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (y);
|
|
1475
|
|
1476 if (FLOATP (x) || FLOATP (y))
|
|
1477 {
|
|
1478 double f1, f2;
|
|
1479
|
|
1480 f1 = ((FLOATP (x)) ? float_data (XFLOAT (x)) : XINT (x));
|
|
1481 f2 = ((FLOATP (y)) ? float_data (XFLOAT (y)) : XINT (y));
|
|
1482 if (f2 == 0)
|
|
1483 Fsignal (Qarith_error, Qnil);
|
|
1484
|
|
1485 f1 = fmod (f1, f2);
|
|
1486
|
|
1487 /* If the "remainder" comes out with the wrong sign, fix it. */
|
|
1488 if (f2 < 0 ? f1 > 0 : f1 < 0)
|
|
1489 f1 += f2;
|
|
1490 return (make_float (f1));
|
|
1491 }
|
|
1492 #else /* not LISP_FLOAT_TYPE */
|
|
1493 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (x);
|
|
1494 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (y);
|
|
1495 #endif /* not LISP_FLOAT_TYPE */
|
|
1496
|
|
1497 i1 = XINT (x);
|
|
1498 i2 = XINT (y);
|
|
1499
|
|
1500 if (i2 == 0)
|
|
1501 Fsignal (Qarith_error, Qnil);
|
|
1502
|
|
1503 i1 %= i2;
|
|
1504
|
|
1505 /* If the "remainder" comes out with the wrong sign, fix it. */
|
|
1506 if (i2 < 0 ? i1 > 0 : i1 < 0)
|
|
1507 i1 += i2;
|
|
1508
|
|
1509 return (make_int (i1));
|
|
1510 }
|
|
1511
|
|
1512
|
20
|
1513 DEFUN ("max", Fmax, 1, MANY, 0, /*
|
16
|
1514 Return largest of all the arguments.
|
70
|
1515 All arguments must be numbers, characters or markers.
|
|
1516 The value is always a number; markers and characters are converted
|
|
1517 to numbers.
|
20
|
1518 */
|
|
1519 (int nargs, Lisp_Object *args))
|
0
|
1520 {
|
|
1521 return arith_driver (Amax, nargs, args);
|
|
1522 }
|
|
1523
|
20
|
1524 DEFUN ("min", Fmin, 1, MANY, 0, /*
|
16
|
1525 Return smallest of all the arguments.
|
70
|
1526 All arguments must be numbers, characters or markers.
|
|
1527 The value is always a number; markers and characters are converted
|
|
1528 to numbers.
|
20
|
1529 */
|
|
1530 (int nargs, Lisp_Object *args))
|
0
|
1531 {
|
|
1532 return arith_driver (Amin, nargs, args);
|
|
1533 }
|
|
1534
|
20
|
1535 DEFUN ("logand", Flogand, 0, MANY, 0, /*
|
0
|
1536 Return bitwise-and of all the arguments.
|
70
|
1537 Arguments may be integers, or markers or characters converted to integers.
|
20
|
1538 */
|
|
1539 (int nargs, Lisp_Object *args))
|
0
|
1540 {
|
|
1541 return arith_driver (Alogand, nargs, args);
|
|
1542 }
|
|
1543
|
20
|
1544 DEFUN ("logior", Flogior, 0, MANY, 0, /*
|
0
|
1545 Return bitwise-or of all the arguments.
|
70
|
1546 Arguments may be integers, or markers or characters converted to integers.
|
20
|
1547 */
|
|
1548 (int nargs, Lisp_Object *args))
|
0
|
1549 {
|
|
1550 return arith_driver (Alogior, nargs, args);
|
|
1551 }
|
|
1552
|
20
|
1553 DEFUN ("logxor", Flogxor, 0, MANY, 0, /*
|
0
|
1554 Return bitwise-exclusive-or of all the arguments.
|
70
|
1555 Arguments may be integers, or markers or characters converted to integers.
|
20
|
1556 */
|
|
1557 (int nargs, Lisp_Object *args))
|
0
|
1558 {
|
|
1559 return arith_driver (Alogxor, nargs, args);
|
|
1560 }
|
|
1561
|
20
|
1562 DEFUN ("ash", Fash, 2, 2, 0, /*
|
0
|
1563 Return VALUE with its bits shifted left by COUNT.
|
|
1564 If COUNT is negative, shifting is actually to the right.
|
|
1565 In this case, the sign bit is duplicated.
|
20
|
1566 */
|
|
1567 (value, count))
|
0
|
1568 {
|
|
1569 CHECK_INT_COERCE_CHAR (value);
|
|
1570 CHECK_INT (count);
|
|
1571
|
16
|
1572 return make_int (XINT (count) > 0 ?
|
70
|
1573 XINT (value) << XINT (count) :
|
|
1574 XINT (value) >> -XINT (count));
|
0
|
1575 }
|
|
1576
|
20
|
1577 DEFUN ("lsh", Flsh, 2, 2, 0, /*
|
0
|
1578 Return VALUE with its bits shifted left by COUNT.
|
|
1579 If COUNT is negative, shifting is actually to the right.
|
70
|
1580 In this case, zeros are shifted in on the left.
|
20
|
1581 */
|
|
1582 (value, count))
|
0
|
1583 {
|
|
1584 Lisp_Object val;
|
|
1585
|
|
1586 CHECK_INT_COERCE_CHAR (value);
|
|
1587 CHECK_INT (count);
|
|
1588
|
70
|
1589 {
|
|
1590 int C_count = XINT (count);
|
|
1591 EMACS_UINT C_value = (EMACS_UINT) XUINT (value);
|
|
1592 XSETINT (val, C_count > 0 ? C_value << C_count : C_value >> -C_count);
|
|
1593 }
|
0
|
1594 return val;
|
|
1595 }
|
|
1596
|
20
|
1597 DEFUN ("1+", Fadd1, 1, 1, 0, /*
|
0
|
1598 Return NUMBER plus one. NUMBER may be a number or a marker.
|
70
|
1599 Markers and characters are converted to integers.
|
20
|
1600 */
|
|
1601 (number))
|
0
|
1602 {
|
|
1603 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (number);
|
|
1604
|
|
1605 #ifdef LISP_FLOAT_TYPE
|
|
1606 if (FLOATP (number))
|
|
1607 return (make_float (1.0 + float_data (XFLOAT (number))));
|
|
1608 #endif /* LISP_FLOAT_TYPE */
|
|
1609
|
|
1610 return (make_int (XINT (number) + 1));
|
|
1611 }
|
|
1612
|
20
|
1613 DEFUN ("1-", Fsub1, 1, 1, 0, /*
|
0
|
1614 Return NUMBER minus one. NUMBER may be a number or a marker.
|
70
|
1615 Markers and characters are converted to integers.
|
20
|
1616 */
|
|
1617 (number))
|
0
|
1618 {
|
|
1619 CHECK_INT_OR_FLOAT_COERCE_CHAR_OR_MARKER (number);
|
|
1620
|
|
1621 #ifdef LISP_FLOAT_TYPE
|
|
1622 if (FLOATP (number))
|
|
1623 return (make_float (-1.0 + (float_data (XFLOAT (number)))));
|
|
1624 #endif /* LISP_FLOAT_TYPE */
|
|
1625
|
|
1626 return (make_int (XINT (number) - 1));
|
|
1627 }
|
|
1628
|
20
|
1629 DEFUN ("lognot", Flognot, 1, 1, 0, /*
|
0
|
1630 Return the bitwise complement of NUMBER. NUMBER must be an integer.
|
20
|
1631 */
|
|
1632 (number))
|
0
|
1633 {
|
|
1634 CHECK_INT (number);
|
|
1635 return (make_int (~XINT (number)));
|
|
1636 }
|
|
1637
|
|
1638
|
|
1639 /************************************************************************/
|
|
1640 /* weak lists */
|
|
1641 /************************************************************************/
|
|
1642
|
|
1643 /* A weak list is like a normal list except that elements automatically
|
|
1644 disappear when no longer in use, i.e. when no longer GC-protected.
|
|
1645 The basic idea is that we don't mark the elements during GC, but
|
|
1646 wait for them to be marked elsewhere. If they're not marked, we
|
|
1647 remove them. This is analogous to weak hashtables; see the explanation
|
|
1648 there for more info. */
|
|
1649
|
|
1650 static Lisp_Object mark_weak_list (Lisp_Object, void (*) (Lisp_Object));
|
|
1651 static void print_weak_list (Lisp_Object, Lisp_Object, int);
|
|
1652 static int weak_list_equal (Lisp_Object, Lisp_Object, int depth);
|
|
1653 static unsigned long weak_list_hash (Lisp_Object obj, int depth);
|
|
1654 DEFINE_LRECORD_IMPLEMENTATION ("weak-list", weak_list,
|
|
1655 mark_weak_list, print_weak_list,
|
|
1656 0, weak_list_equal, weak_list_hash,
|
|
1657 struct weak_list);
|
|
1658
|
|
1659 static Lisp_Object Vall_weak_lists; /* Gemarke es nicht!!! */
|
|
1660
|
|
1661 static Lisp_Object encode_weak_list_type (enum weak_list_type type);
|
|
1662
|
|
1663 static Lisp_Object
|
|
1664 mark_weak_list (Lisp_Object obj, void (*markobj) (Lisp_Object))
|
|
1665 {
|
|
1666 return Qnil; /* nichts ist gemarkt */
|
|
1667 }
|
|
1668
|
|
1669 static void
|
|
1670 print_weak_list (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
|
|
1671 {
|
|
1672 if (print_readably)
|
|
1673 error ("printing unreadable object #<weak-list>");
|
|
1674
|
|
1675 write_c_string ("#<weak-list ", printcharfun);
|
|
1676 print_internal (encode_weak_list_type (XWEAK_LIST (obj)->type),
|
|
1677 printcharfun, 0);
|
|
1678 write_c_string (" ", printcharfun);
|
|
1679 print_internal (XWEAK_LIST (obj)->list, printcharfun, escapeflag);
|
|
1680 write_c_string (">", printcharfun);
|
|
1681 }
|
|
1682
|
|
1683 static int
|
|
1684 weak_list_equal (Lisp_Object o1, Lisp_Object o2, int depth)
|
|
1685 {
|
|
1686 struct weak_list *w1 = XWEAK_LIST (o1);
|
|
1687 struct weak_list *w2 = XWEAK_LIST (o2);
|
|
1688
|
70
|
1689 return (w1->type == w2->type) &&
|
|
1690 internal_equal (w1->list, w2->list, depth + 1);
|
0
|
1691 }
|
|
1692
|
|
1693 static unsigned long
|
|
1694 weak_list_hash (Lisp_Object obj, int depth)
|
|
1695 {
|
|
1696 struct weak_list *w = XWEAK_LIST (obj);
|
|
1697
|
|
1698 return HASH2 ((unsigned long) w->type,
|
|
1699 internal_hash (w->list, depth + 1));
|
|
1700 }
|
|
1701
|
|
1702 Lisp_Object
|
|
1703 make_weak_list (enum weak_list_type type)
|
|
1704 {
|
|
1705 Lisp_Object result = Qnil;
|
|
1706
|
|
1707 struct weak_list *wl =
|
|
1708 alloc_lcrecord (sizeof (struct weak_list), lrecord_weak_list);
|
|
1709 wl->list = Qnil;
|
|
1710 wl->type = type;
|
|
1711 XSETWEAK_LIST (result, wl);
|
|
1712 wl->next_weak = Vall_weak_lists;
|
|
1713 Vall_weak_lists = result;
|
|
1714 return result;
|
|
1715 }
|
|
1716
|
|
1717 /*
|
|
1718 -- we do not mark the list elements (either the elements themselves
|
|
1719 or the cons cells that hold them) in the normal marking phase.
|
|
1720 -- at the end of marking, we go through all weak lists that are
|
|
1721 marked, and mark the cons cells that hold all marked
|
|
1722 objects, and possibly parts of the objects themselves.
|
|
1723 (See alloc.c, "after-mark".)
|
|
1724 -- after that, we prune away all the cons cells that are not marked.
|
|
1725
|
|
1726 WARNING WARNING WARNING WARNING WARNING:
|
|
1727
|
|
1728 The code in the following two functions is *unbelievably* tricky.
|
|
1729 Don't mess with it. You'll be sorry.
|
|
1730
|
|
1731 Linked lists just majorly suck, d'ya know?
|
|
1732 */
|
|
1733
|
|
1734 int
|
|
1735 finish_marking_weak_lists (int (*obj_marked_p) (Lisp_Object),
|
|
1736 void (*markobj) (Lisp_Object))
|
|
1737 {
|
|
1738 Lisp_Object rest;
|
|
1739 int did_mark = 0;
|
|
1740
|
|
1741 for (rest = Vall_weak_lists;
|
|
1742 !GC_NILP (rest);
|
|
1743 rest = XWEAK_LIST (rest)->next_weak)
|
|
1744 {
|
|
1745 Lisp_Object rest2;
|
|
1746 enum weak_list_type type = XWEAK_LIST (rest)->type;
|
|
1747
|
|
1748 if (! ((*obj_marked_p) (rest)))
|
|
1749 /* The weak list is probably garbage. Ignore it. */
|
|
1750 continue;
|
|
1751
|
|
1752 for (rest2 = XWEAK_LIST (rest)->list;
|
|
1753 /* We need to be trickier since we're inside of GC;
|
|
1754 use CONSP instead of !NILP in case of user-visible
|
|
1755 imperfect lists */
|
|
1756 GC_CONSP (rest2);
|
|
1757 rest2 = XCDR (rest2))
|
|
1758 {
|
|
1759 Lisp_Object elem;
|
|
1760 /* If the element is "marked" (meaning depends on the type
|
|
1761 of weak list), we need to mark the cons containing the
|
|
1762 element, and maybe the element itself (if only some part
|
|
1763 was already marked). */
|
|
1764 int need_to_mark_cons = 0;
|
|
1765 int need_to_mark_elem = 0;
|
|
1766
|
|
1767 /* If a cons is already marked, then its car is already marked
|
|
1768 (either because of an external pointer or because of
|
|
1769 a previous call to this function), and likewise for all
|
|
1770 the rest of the elements in the list, so we can stop now. */
|
|
1771 if ((*obj_marked_p) (rest2))
|
|
1772 break;
|
|
1773
|
|
1774 elem = XCAR (rest2);
|
|
1775
|
|
1776 switch (type)
|
|
1777 {
|
|
1778 case WEAK_LIST_SIMPLE:
|
|
1779 if ((*obj_marked_p) (elem))
|
|
1780 need_to_mark_cons = 1;
|
|
1781 break;
|
|
1782
|
|
1783 case WEAK_LIST_ASSOC:
|
|
1784 if (!GC_CONSP (elem))
|
|
1785 {
|
|
1786 /* just leave bogus elements there */
|
|
1787 need_to_mark_cons = 1;
|
|
1788 need_to_mark_elem = 1;
|
|
1789 }
|
|
1790 else if ((*obj_marked_p) (XCAR (elem)) &&
|
|
1791 (*obj_marked_p) (XCDR (elem)))
|
|
1792 {
|
|
1793 need_to_mark_cons = 1;
|
|
1794 /* We still need to mark elem, because it's
|
|
1795 probably not marked. */
|
|
1796 need_to_mark_elem = 1;
|
|
1797 }
|
|
1798 break;
|
|
1799
|
|
1800 case WEAK_LIST_KEY_ASSOC:
|
|
1801 if (!GC_CONSP (elem))
|
|
1802 {
|
|
1803 /* just leave bogus elements there */
|
|
1804 need_to_mark_cons = 1;
|
|
1805 need_to_mark_elem = 1;
|
|
1806 }
|
|
1807 else if ((*obj_marked_p) (XCAR (elem)))
|
|
1808 {
|
|
1809 need_to_mark_cons = 1;
|
|
1810 /* We still need to mark elem and XCDR (elem);
|
|
1811 marking elem does both */
|
|
1812 need_to_mark_elem = 1;
|
|
1813 }
|
|
1814 break;
|
|
1815
|
|
1816 case WEAK_LIST_VALUE_ASSOC:
|
|
1817 if (!GC_CONSP (elem))
|
|
1818 {
|
|
1819 /* just leave bogus elements there */
|
|
1820 need_to_mark_cons = 1;
|
|
1821 need_to_mark_elem = 1;
|
|
1822 }
|
|
1823 else if ((*obj_marked_p) (XCDR (elem)))
|
|
1824 {
|
|
1825 need_to_mark_cons = 1;
|
|
1826 /* We still need to mark elem and XCAR (elem);
|
|
1827 marking elem does both */
|
|
1828 need_to_mark_elem = 1;
|
|
1829 }
|
|
1830 break;
|
|
1831
|
|
1832 default:
|
|
1833 abort ();
|
|
1834 }
|
|
1835
|
|
1836 if (need_to_mark_elem && ! (*obj_marked_p) (elem))
|
|
1837 {
|
|
1838 (*markobj) (elem);
|
|
1839 did_mark = 1;
|
|
1840 }
|
|
1841
|
|
1842 /* We also need to mark the cons that holds the elem or
|
|
1843 assoc-pair. We do *not* want to call (markobj) here
|
|
1844 because that will mark the entire list; we just want to
|
|
1845 mark the cons itself.
|
|
1846 */
|
|
1847 if (need_to_mark_cons)
|
|
1848 {
|
|
1849 struct Lisp_Cons *ptr = XCONS (rest2);
|
|
1850 if (!CONS_MARKED_P (ptr))
|
|
1851 {
|
|
1852 MARK_CONS (ptr);
|
|
1853 did_mark = 1;
|
|
1854 }
|
|
1855 }
|
|
1856 }
|
|
1857
|
|
1858 /* In case of imperfect list, need to mark the final cons
|
|
1859 because we're not removing it */
|
|
1860 if (!GC_NILP (rest2) && ! (obj_marked_p) (rest2))
|
|
1861 {
|
|
1862 (markobj) (rest2);
|
|
1863 did_mark = 1;
|
|
1864 }
|
|
1865 }
|
|
1866
|
|
1867 return did_mark;
|
|
1868 }
|
|
1869
|
|
1870 void
|
|
1871 prune_weak_lists (int (*obj_marked_p) (Lisp_Object))
|
|
1872 {
|
|
1873 Lisp_Object rest, prev = Qnil;
|
|
1874
|
|
1875 for (rest = Vall_weak_lists;
|
|
1876 !GC_NILP (rest);
|
|
1877 rest = XWEAK_LIST (rest)->next_weak)
|
|
1878 {
|
|
1879 if (! ((*obj_marked_p) (rest)))
|
|
1880 {
|
|
1881 /* This weak list itself is garbage. Remove it from the list. */
|
|
1882 if (GC_NILP (prev))
|
|
1883 Vall_weak_lists = XWEAK_LIST (rest)->next_weak;
|
|
1884 else
|
|
1885 XWEAK_LIST (prev)->next_weak =
|
|
1886 XWEAK_LIST (rest)->next_weak;
|
|
1887 }
|
|
1888 else
|
|
1889 {
|
|
1890 Lisp_Object rest2, prev2 = Qnil;
|
|
1891 Lisp_Object tortoise;
|
|
1892 int go_tortoise = 0;
|
|
1893
|
|
1894 for (rest2 = XWEAK_LIST (rest)->list, tortoise = rest2;
|
|
1895 /* We need to be trickier since we're inside of GC;
|
|
1896 use CONSP instead of !NILP in case of user-visible
|
|
1897 imperfect lists */
|
|
1898 GC_CONSP (rest2);)
|
|
1899 {
|
|
1900 /* It suffices to check the cons for marking,
|
|
1901 regardless of the type of weak list:
|
|
1902
|
|
1903 -- if the cons is pointed to somewhere else,
|
|
1904 then it should stay around and will be marked.
|
|
1905 -- otherwise, if it should stay around, it will
|
|
1906 have been marked in finish_marking_weak_lists().
|
|
1907 -- otherwise, it's not marked and should disappear.
|
|
1908 */
|
|
1909 if (!(*obj_marked_p) (rest2))
|
|
1910 {
|
|
1911 /* bye bye :-( */
|
|
1912 if (GC_NILP (prev2))
|
|
1913 XWEAK_LIST (rest)->list = XCDR (rest2);
|
|
1914 else
|
|
1915 XCDR (prev2) = XCDR (rest2);
|
|
1916 rest2 = XCDR (rest2);
|
|
1917 /* Ouch. Circularity checking is even trickier
|
|
1918 than I thought. When we cut out a link
|
|
1919 like this, we can't advance the turtle or
|
|
1920 it'll catch up to us. Imagine that we're
|
|
1921 standing on floor tiles and moving forward --
|
|
1922 what we just did here is as if the floor
|
|
1923 tile under us just disappeared and all the
|
|
1924 ones ahead of us slid one tile towards us.
|
|
1925 In other words, we didn't move at all;
|
|
1926 if the tortoise was one step behind us
|
|
1927 previously, it still is, and therefore
|
|
1928 it must not move. */
|
|
1929 }
|
|
1930 else
|
|
1931 {
|
|
1932 prev2 = rest2;
|
|
1933
|
|
1934 /* Implementing circularity checking is trickier here
|
|
1935 than in other places because we have to guarantee
|
|
1936 that we've processed all elements before exiting
|
|
1937 due to a circularity. (In most places, an error
|
|
1938 is issued upon encountering a circularity, so it
|
|
1939 doesn't really matter if all elements are processed.)
|
|
1940 The idea is that we process along with the hare
|
|
1941 rather than the tortoise. If at any point in
|
|
1942 our forward process we encounter the tortoise,
|
|
1943 we must have already visited the spot, so we exit.
|
|
1944 (If we process with the tortoise, we can fail to
|
|
1945 process cases where a cons points to itself, or
|
|
1946 where cons A points to cons B, which points to
|
|
1947 cons A.) */
|
|
1948
|
|
1949 rest2 = XCDR (rest2);
|
|
1950 if (go_tortoise)
|
|
1951 tortoise = XCDR (tortoise);
|
|
1952 go_tortoise = !go_tortoise;
|
|
1953 if (GC_EQ (rest2, tortoise))
|
|
1954 break;
|
|
1955 }
|
|
1956 }
|
|
1957
|
|
1958 prev = rest;
|
|
1959 }
|
|
1960 }
|
|
1961 }
|
|
1962
|
|
1963 static enum weak_list_type
|
|
1964 decode_weak_list_type (Lisp_Object symbol)
|
|
1965 {
|
|
1966 CHECK_SYMBOL (symbol);
|
16
|
1967 if (EQ (symbol, Qsimple)) return WEAK_LIST_SIMPLE;
|
|
1968 if (EQ (symbol, Qassoc)) return WEAK_LIST_ASSOC;
|
70
|
1969 if (EQ (symbol, Qold_assoc)) return WEAK_LIST_ASSOC; /* EBOLA ALERT! */
|
16
|
1970 if (EQ (symbol, Qkey_assoc)) return WEAK_LIST_KEY_ASSOC;
|
|
1971 if (EQ (symbol, Qvalue_assoc)) return WEAK_LIST_VALUE_ASSOC;
|
0
|
1972
|
|
1973 signal_simple_error ("Invalid weak list type", symbol);
|
|
1974 return WEAK_LIST_SIMPLE; /* not reached */
|
|
1975 }
|
|
1976
|
|
1977 static Lisp_Object
|
|
1978 encode_weak_list_type (enum weak_list_type type)
|
|
1979 {
|
|
1980 switch (type)
|
|
1981 {
|
16
|
1982 case WEAK_LIST_SIMPLE: return Qsimple;
|
|
1983 case WEAK_LIST_ASSOC: return Qassoc;
|
|
1984 case WEAK_LIST_KEY_ASSOC: return Qkey_assoc;
|
|
1985 case WEAK_LIST_VALUE_ASSOC: return Qvalue_assoc;
|
0
|
1986 default:
|
|
1987 abort ();
|
|
1988 }
|
|
1989
|
16
|
1990 return Qnil; /* not reached */
|
0
|
1991 }
|
|
1992
|
20
|
1993 DEFUN ("weak-list-p", Fweak_list_p, 1, 1, 0, /*
|
0
|
1994 Return non-nil if OBJECT is a weak list.
|
20
|
1995 */
|
|
1996 (object))
|
0
|
1997 {
|
|
1998 return WEAK_LISTP (object) ? Qt : Qnil;
|
|
1999 }
|
|
2000
|
20
|
2001 DEFUN ("make-weak-list", Fmake_weak_list, 0, 1, 0, /*
|
0
|
2002 Create a new weak list.
|
|
2003 A weak list object is an object that contains a list. This list behaves
|
|
2004 like any other list except that its elements do not count towards
|
|
2005 garbage collection -- if the only pointer to an object in inside a weak
|
|
2006 list (other than pointers in similar objects such as weak hash tables),
|
|
2007 the object is garbage collected and automatically removed from the list.
|
|
2008 This is used internally, for example, to manage the list holding the
|
|
2009 children of an extent -- an extent that is unused but has a parent will
|
|
2010 still be reclaimed, and will automatically be removed from its parent's
|
|
2011 list of children.
|
|
2012
|
|
2013 Optional argument TYPE specifies the type of the weak list, and defaults
|
|
2014 to `simple'. Recognized types are
|
|
2015
|
|
2016 `simple' Objects in the list disappear if not pointed to.
|
|
2017 `assoc' Objects in the list disappear if they are conses
|
|
2018 and either the car or the cdr of the cons is not
|
|
2019 pointed to.
|
|
2020 `key-assoc' Objects in the list disappear if they are conses
|
|
2021 and the car is not pointed to.
|
|
2022 `value-assoc' Objects in the list disappear if they are conses
|
|
2023 and the cdr is not pointed to.
|
20
|
2024 */
|
|
2025 (type))
|
0
|
2026 {
|
|
2027 if (NILP (type))
|
|
2028 type = Qsimple;
|
|
2029
|
|
2030 return make_weak_list (decode_weak_list_type (type));
|
|
2031 }
|
|
2032
|
20
|
2033 DEFUN ("weak-list-type", Fweak_list_type, 1, 1, 0, /*
|
0
|
2034 Return the type of the given weak-list object.
|
20
|
2035 */
|
|
2036 (weak))
|
0
|
2037 {
|
|
2038 CHECK_WEAK_LIST (weak);
|
|
2039 return encode_weak_list_type (XWEAK_LIST (weak)->type);
|
|
2040 }
|
|
2041
|
20
|
2042 DEFUN ("weak-list-list", Fweak_list_list, 1, 1, 0, /*
|
0
|
2043 Return the list contained in a weak-list object.
|
20
|
2044 */
|
|
2045 (weak))
|
0
|
2046 {
|
|
2047 CHECK_WEAK_LIST (weak);
|
|
2048 return XWEAK_LIST_LIST (weak);
|
|
2049 }
|
|
2050
|
20
|
2051 DEFUN ("set-weak-list-list", Fset_weak_list_list, 2, 2, 0, /*
|
0
|
2052 Change the list contained in a weak-list object.
|
20
|
2053 */
|
|
2054 (weak, new_list))
|
0
|
2055 {
|
|
2056 CHECK_WEAK_LIST (weak);
|
|
2057 XWEAK_LIST_LIST (weak) = new_list;
|
|
2058 return new_list;
|
|
2059 }
|
|
2060
|
|
2061
|
|
2062 /************************************************************************/
|
|
2063 /* initialization */
|
|
2064 /************************************************************************/
|
|
2065
|
|
2066 static SIGTYPE
|
|
2067 arith_error (int signo)
|
|
2068 {
|
|
2069 EMACS_REESTABLISH_SIGNAL (signo, arith_error);
|
|
2070 EMACS_UNBLOCK_SIGNAL (signo);
|
|
2071 signal_error (Qarith_error, Qnil);
|
|
2072 }
|
|
2073
|
|
2074 void
|
|
2075 init_data_very_early (void)
|
|
2076 {
|
|
2077 /* Don't do this if just dumping out.
|
|
2078 We don't want to call `signal' in this case
|
|
2079 so that we don't have trouble with dumping
|
|
2080 signal-delivering routines in an inconsistent state. */
|
|
2081 #ifndef CANNOT_DUMP
|
|
2082 if (!initialized)
|
|
2083 return;
|
|
2084 #endif /* CANNOT_DUMP */
|
|
2085 signal (SIGFPE, arith_error);
|
|
2086 #ifdef uts
|
|
2087 signal (SIGEMT, arith_error);
|
|
2088 #endif /* uts */
|
|
2089 }
|
|
2090
|
|
2091 void
|
|
2092 init_errors_once_early (void)
|
|
2093 {
|
|
2094 defsymbol (&Qerror_conditions, "error-conditions");
|
|
2095 defsymbol (&Qerror_message, "error-message");
|
|
2096
|
|
2097 /* We declare the errors here because some other deferrors depend
|
|
2098 on some of the errors below. */
|
|
2099
|
|
2100 /* ERROR is used as a signaler for random errors for which nothing
|
|
2101 else is right */
|
|
2102
|
|
2103 deferror (&Qerror, "error", "error", Qnil);
|
|
2104 deferror (&Qquit, "quit", "Quit", Qnil);
|
|
2105
|
|
2106 deferror (&Qwrong_type_argument, "wrong-type-argument",
|
|
2107 "Wrong type argument", Qerror);
|
|
2108 deferror (&Qargs_out_of_range, "args-out-of-range", "Args out of range",
|
|
2109 Qerror);
|
|
2110 deferror (&Qvoid_function, "void-function",
|
|
2111 "Symbol's function definition is void", Qerror);
|
|
2112 deferror (&Qcyclic_function_indirection, "cyclic-function-indirection",
|
|
2113 "Symbol's chain of function indirections contains a loop", Qerror);
|
|
2114 deferror (&Qvoid_variable, "void-variable",
|
|
2115 "Symbol's value as variable is void", Qerror);
|
|
2116 deferror (&Qcyclic_variable_indirection, "cyclic-variable-indirection",
|
|
2117 "Symbol's chain of variable indirections contains a loop", Qerror);
|
|
2118 deferror (&Qsetting_constant, "setting-constant",
|
|
2119 "Attempt to set a constant symbol", Qerror);
|
|
2120 deferror (&Qinvalid_read_syntax, "invalid-read-syntax",
|
|
2121 "Invalid read syntax", Qerror);
|
|
2122 deferror (&Qmalformed_list, "malformed-list",
|
|
2123 "Malformed list", Qerror);
|
|
2124 deferror (&Qmalformed_property_list, "malformed-property-list",
|
|
2125 "Malformed property list", Qerror);
|
|
2126 deferror (&Qcircular_list, "circular-list",
|
|
2127 "Circular list", Qerror);
|
|
2128 deferror (&Qcircular_property_list, "circular-property-list",
|
|
2129 "Circular property list", Qerror);
|
|
2130 deferror (&Qinvalid_function, "invalid-function", "Invalid function",
|
|
2131 Qerror);
|
|
2132 deferror (&Qwrong_number_of_arguments, "wrong-number-of-arguments",
|
|
2133 "Wrong number of arguments", Qerror);
|
|
2134 deferror (&Qno_catch, "no-catch", "No catch for tag",
|
|
2135 Qerror);
|
|
2136 deferror (&Qbeginning_of_buffer, "beginning-of-buffer",
|
|
2137 "Beginning of buffer", Qerror);
|
|
2138 deferror (&Qend_of_buffer, "end-of-buffer", "End of buffer", Qerror);
|
|
2139 deferror (&Qbuffer_read_only, "buffer-read-only", "Buffer is read-only",
|
|
2140 Qerror);
|
|
2141
|
|
2142 deferror (&Qio_error, "io-error", "IO Error", Qerror);
|
|
2143 deferror (&Qend_of_file, "end-of-file", "End of stream", Qio_error);
|
|
2144
|
|
2145 deferror (&Qarith_error, "arith-error", "Arithmetic error", Qerror);
|
|
2146 deferror (&Qrange_error, "range-error", "Arithmetic range error",
|
|
2147 Qarith_error);
|
|
2148 deferror (&Qdomain_error, "domain-error", "Arithmetic domain error",
|
|
2149 Qarith_error);
|
|
2150 deferror (&Qsingularity_error, "singularity-error",
|
|
2151 "Arithmetic singularity error", Qdomain_error);
|
|
2152 deferror (&Qoverflow_error, "overflow-error",
|
|
2153 "Arithmetic overflow error", Qdomain_error);
|
|
2154 deferror (&Qunderflow_error, "underflow-error",
|
|
2155 "Arithmetic underflow error", Qdomain_error);
|
|
2156 }
|
|
2157
|
|
2158 void
|
|
2159 syms_of_data (void)
|
|
2160 {
|
|
2161 defsymbol (&Qcons, "cons");
|
|
2162 defsymbol (&Qkeyword, "keyword");
|
|
2163 /* Qstring, Qinteger, Qsymbol, Qvector defined in general.c */
|
|
2164
|
|
2165 defsymbol (&Qquote, "quote");
|
|
2166 defsymbol (&Qlambda, "lambda");
|
|
2167 defsymbol (&Qsignal, "signal");
|
|
2168 defsymbol (&Qtop_level, "top-level");
|
|
2169 defsymbol (&Qignore, "ignore");
|
|
2170
|
|
2171 defsymbol (&Qlistp, "listp");
|
|
2172 defsymbol (&Qconsp, "consp");
|
|
2173 defsymbol (&Qsubrp, "subrp");
|
|
2174 defsymbol (&Qsymbolp, "symbolp");
|
|
2175 defsymbol (&Qkeywordp, "keywordp");
|
|
2176 defsymbol (&Qintegerp, "integerp");
|
|
2177 defsymbol (&Qcharacterp, "characterp");
|
|
2178 defsymbol (&Qnatnump, "natnump");
|
|
2179 defsymbol (&Qstringp, "stringp");
|
|
2180 defsymbol (&Qarrayp, "arrayp");
|
|
2181 defsymbol (&Qsequencep, "sequencep");
|
|
2182 defsymbol (&Qbufferp, "bufferp");
|
|
2183 defsymbol (&Qbitp, "bitp");
|
|
2184 defsymbol (&Qbit_vectorp, "bit-vector-p");
|
|
2185 defsymbol (&Qvectorp, "vectorp");
|
|
2186 defsymbol (&Qcompiled_functionp, "compiled-function-p");
|
|
2187 defsymbol (&Qchar_or_string_p, "char-or-string-p");
|
|
2188 defsymbol (&Qmarkerp, "markerp");
|
|
2189 defsymbol (&Qinteger_or_marker_p, "integer-or-marker-p");
|
70
|
2190 defsymbol (&Qinteger_or_char_p, "integer-or-char-p");
|
|
2191 defsymbol (&Qinteger_char_or_marker_p, "integer-char-or-marker-p");
|
0
|
2192
|
|
2193 #ifdef LISP_FLOAT_TYPE
|
|
2194 defsymbol (&Qfloatp, "floatp");
|
|
2195 #endif /* LISP_FLOAT_TYPE */
|
|
2196 defsymbol (&Qnumberp, "numberp");
|
|
2197 defsymbol (&Qnumber_or_marker_p, "number-or-marker-p");
|
70
|
2198 defsymbol (&Qnumber_char_or_marker_p, "number-char-or-marker-p");
|
0
|
2199
|
|
2200 defsymbol (&Qcdr, "cdr");
|
|
2201
|
|
2202 defsymbol (&Qweak_listp, "weak-list-p");
|
|
2203
|
20
|
2204 DEFSUBR (Fwrong_type_argument);
|
0
|
2205
|
20
|
2206 DEFSUBR (Feq);
|
70
|
2207 DEFSUBR (Fold_eq);
|
20
|
2208 DEFSUBR (Fnull);
|
|
2209 DEFSUBR (Flistp);
|
|
2210 DEFSUBR (Fnlistp);
|
|
2211 DEFSUBR (Fconsp);
|
|
2212 DEFSUBR (Fatom);
|
|
2213 DEFSUBR (Fchar_or_string_p);
|
|
2214 DEFSUBR (Fcharacterp);
|
70
|
2215 DEFSUBR (Fchar_int_p);
|
104
|
2216 DEFSUBR (Fchar_to_int);
|
|
2217 DEFSUBR (Fint_to_char);
|
70
|
2218 DEFSUBR (Fchar_or_char_int_p);
|
20
|
2219 DEFSUBR (Fintegerp);
|
|
2220 DEFSUBR (Finteger_or_marker_p);
|
70
|
2221 DEFSUBR (Finteger_or_char_p);
|
|
2222 DEFSUBR (Finteger_char_or_marker_p);
|
20
|
2223 DEFSUBR (Fnumberp);
|
|
2224 DEFSUBR (Fnumber_or_marker_p);
|
70
|
2225 DEFSUBR (Fnumber_char_or_marker_p);
|
0
|
2226 #ifdef LISP_FLOAT_TYPE
|
20
|
2227 DEFSUBR (Ffloatp);
|
0
|
2228 #endif /* LISP_FLOAT_TYPE */
|
20
|
2229 DEFSUBR (Fnatnump);
|
|
2230 DEFSUBR (Fsymbolp);
|
|
2231 DEFSUBR (Fkeywordp);
|
|
2232 DEFSUBR (Fstringp);
|
|
2233 DEFSUBR (Fvectorp);
|
|
2234 DEFSUBR (Fbitp);
|
|
2235 DEFSUBR (Fbit_vector_p);
|
|
2236 DEFSUBR (Farrayp);
|
|
2237 DEFSUBR (Fsequencep);
|
|
2238 DEFSUBR (Fmarkerp);
|
|
2239 DEFSUBR (Fsubrp);
|
|
2240 DEFSUBR (Fsubr_min_args);
|
|
2241 DEFSUBR (Fsubr_max_args);
|
|
2242 DEFSUBR (Fcompiled_function_p);
|
|
2243 DEFSUBR (Ftype_of);
|
|
2244 DEFSUBR (Fcar);
|
|
2245 DEFSUBR (Fcdr);
|
|
2246 DEFSUBR (Fcar_safe);
|
|
2247 DEFSUBR (Fcdr_safe);
|
|
2248 DEFSUBR (Fsetcar);
|
|
2249 DEFSUBR (Fsetcdr);
|
|
2250 DEFSUBR (Findirect_function);
|
|
2251 DEFSUBR (Faref);
|
|
2252 DEFSUBR (Faset);
|
0
|
2253
|
20
|
2254 DEFSUBR (Fcompiled_function_instructions);
|
|
2255 DEFSUBR (Fcompiled_function_constants);
|
|
2256 DEFSUBR (Fcompiled_function_stack_depth);
|
|
2257 DEFSUBR (Fcompiled_function_arglist);
|
|
2258 DEFSUBR (Fcompiled_function_interactive);
|
|
2259 DEFSUBR (Fcompiled_function_doc_string);
|
|
2260 DEFSUBR (Fcompiled_function_domain);
|
0
|
2261 #ifdef COMPILED_FUNCTION_ANNOTATION_HACK
|
20
|
2262 DEFSUBR (Fcompiled_function_annotation);
|
0
|
2263 #endif
|
|
2264
|
20
|
2265 DEFSUBR (Fnumber_to_string);
|
|
2266 DEFSUBR (Fstring_to_number);
|
|
2267 DEFSUBR (Feqlsign);
|
|
2268 DEFSUBR (Flss);
|
|
2269 DEFSUBR (Fgtr);
|
|
2270 DEFSUBR (Fleq);
|
|
2271 DEFSUBR (Fgeq);
|
|
2272 DEFSUBR (Fneq);
|
|
2273 DEFSUBR (Fzerop);
|
|
2274 DEFSUBR (Fplus);
|
|
2275 DEFSUBR (Fminus);
|
|
2276 DEFSUBR (Ftimes);
|
|
2277 DEFSUBR (Fquo);
|
|
2278 DEFSUBR (Frem);
|
|
2279 DEFSUBR (Fmod);
|
|
2280 DEFSUBR (Fmax);
|
|
2281 DEFSUBR (Fmin);
|
|
2282 DEFSUBR (Flogand);
|
|
2283 DEFSUBR (Flogior);
|
|
2284 DEFSUBR (Flogxor);
|
|
2285 DEFSUBR (Flsh);
|
|
2286 DEFSUBR (Fash);
|
|
2287 DEFSUBR (Fadd1);
|
|
2288 DEFSUBR (Fsub1);
|
|
2289 DEFSUBR (Flognot);
|
0
|
2290
|
20
|
2291 DEFSUBR (Fweak_list_p);
|
|
2292 DEFSUBR (Fmake_weak_list);
|
|
2293 DEFSUBR (Fweak_list_type);
|
|
2294 DEFSUBR (Fweak_list_list);
|
|
2295 DEFSUBR (Fset_weak_list_list);
|
0
|
2296 }
|
|
2297
|
|
2298 void
|
|
2299 vars_of_data (void)
|
|
2300 {
|
|
2301 /* This must not be staticpro'd */
|
|
2302 Vall_weak_lists = Qnil;
|
70
|
2303
|
|
2304 #ifdef DEBUG_XEMACS
|
|
2305 DEFVAR_INT ("debug-issue-ebola-notices", &debug_issue_ebola_notices /*
|
|
2306 If non-nil, note when your code may be suffering from char-int confoundance.
|
|
2307 That is to say, if XEmacs encounters a usage of `eq', `memq', `equal',
|
|
2308 etc. where a int and a char with the same value are being compared,
|
|
2309 it will issue a notice on stderr to this effect, along with a backtrace.
|
|
2310 In such situations, the result would be different in XEmacs 19 versus
|
|
2311 XEmacs 20, and you probably don't want this.
|
|
2312
|
|
2313 Note that in order to see these notices, you have to byte compile your
|
|
2314 code under XEmacs 20 -- any code byte-compiled under XEmacs 19 will
|
|
2315 have its chars and ints all confounded in the byte code, making it
|
|
2316 impossible to accurately determine Ebola infection.
|
|
2317 */ );
|
|
2318
|
|
2319 debug_issue_ebola_notices = 2; /* #### temporary hack */
|
|
2320
|
|
2321 DEFVAR_INT ("debug-ebola-backtrace-length",
|
|
2322 &debug_ebola_backtrace_length /*
|
|
2323 Length (in stack frames) of short backtrace printed out in Ebola notices.
|
|
2324 See `debug-issue-ebola-notices'.
|
|
2325 */ );
|
|
2326 debug_ebola_backtrace_length = 8;
|
|
2327
|
|
2328 #endif /* DEBUG_XEMACS */
|
0
|
2329 }
|