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