annotate src/data.c @ 5381:4f39e57a82b4

Improve read-only error reporting. -------------------- ChangeLog entries follow: -------------------- src/ChangeLog addition: 2011-03-17 Didier Verna <didier@xemacs.org> * data.c (init_errors_once_early): Define Qextent_read_only error. * lisp.h: Declare it. * extents.c (verify_extent_mapper): Signal an extent-read-only error instead of a buffer-read-only one.
author Didier Verna <didier@lrde.epita.fr>
date Thu, 17 Mar 2011 16:20:09 +0100
parents d967d96ca043
children 4dee0387b9de
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Primitive operations on Lisp data types for XEmacs Lisp interpreter.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1988, 1992, 1993, 1994, 1995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Free Software Foundation, Inc.
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5142
diff changeset
4 Copyright (C) 2000, 2001, 2002, 2003, 2005, 2010 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23 /* Synched up with: Mule 2.0, FSF 19.30. Some of FSF's data.c is in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 XEmacs' symbols.c. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 /* This file has been Mule-ized. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include "bytecode.h"
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5142
diff changeset
33 #include "gc.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #include "syssignal.h"
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
35 #include "sysfloat.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36
5207
1096ef427b56 Error on too many arguments to #'function, #'quote.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
37 Lisp_Object Qnil, Qt, Qlambda, Qunbound;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 Lisp_Object Qerror_conditions, Qerror_message;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
39 Lisp_Object Qerror, Qquit, Qsyntax_error, Qinvalid_read_syntax;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
40 Lisp_Object Qlist_formation_error, Qstructure_formation_error;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
41 Lisp_Object Qmalformed_list, Qmalformed_property_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
42 Lisp_Object Qcircular_list, Qcircular_property_list;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
43 Lisp_Object Qinvalid_argument, Qinvalid_constant, Qwrong_type_argument;
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
44 Lisp_Object Qargs_out_of_range;
5084
6afe991b8135 Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4998
diff changeset
45 Lisp_Object Qwrong_number_of_arguments, Qinvalid_function;
6afe991b8135 Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4998
diff changeset
46 Lisp_Object Qinvalid_keyword_argument, Qno_catch;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
47 Lisp_Object Qinternal_error, Qinvalid_state, Qstack_overflow, Qout_of_memory;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 Lisp_Object Qvoid_variable, Qcyclic_variable_indirection;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49 Lisp_Object Qvoid_function, Qcyclic_function_indirection;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
50 Lisp_Object Qinvalid_operation, Qinvalid_change, Qprinting_unreadable_object;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
51 Lisp_Object Qsetting_constant;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
52 Lisp_Object Qediting_error;
5381
4f39e57a82b4 Improve read-only error reporting.
Didier Verna <didier@lrde.epita.fr>
parents: 5374
diff changeset
53 Lisp_Object Qbeginning_of_buffer, Qend_of_buffer;
4f39e57a82b4 Improve read-only error reporting.
Didier Verna <didier@lrde.epita.fr>
parents: 5374
diff changeset
54 Lisp_Object Qbuffer_read_only, Qextent_read_only;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
55 Lisp_Object Qio_error, Qfile_error, Qconversion_error, Qend_of_file;
580
55e998c311f5 [xemacs-hg @ 2001-05-26 12:24:50 by ben]
ben
parents: 563
diff changeset
56 Lisp_Object Qtext_conversion_error;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 Lisp_Object Qarith_error, Qrange_error, Qdomain_error;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 Lisp_Object Qsingularity_error, Qoverflow_error, Qunderflow_error;
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
59 Lisp_Object Qintegerp, Qnatnump, Qnonnegativep, Qsymbolp;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 Lisp_Object Qlistp, Qtrue_list_p, Qweak_listp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 Lisp_Object Qconsp, Qsubrp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 Lisp_Object Qcharacterp, Qstringp, Qarrayp, Qsequencep, Qvectorp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qbufferp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 Lisp_Object Qinteger_or_char_p, Qinteger_char_or_marker_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 Lisp_Object Qnumberp, Qnumber_char_or_marker_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 Lisp_Object Qbit_vectorp, Qbitp, Qcdr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
68 Lisp_Object Qerror_lacks_explanatory_string;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 Lisp_Object Qfloatp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
71 Fixnum Vmost_negative_fixnum, Vmost_positive_fixnum;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
72
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 #ifdef DEBUG_XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 int debug_issue_ebola_notices;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
77 Fixnum debug_ebola_backtrace_length;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80 eq_with_ebola_notice (Lisp_Object obj1, Lisp_Object obj2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 if (debug_issue_ebola_notices
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 && ((CHARP (obj1) && INTP (obj2)) || (CHARP (obj2) && INTP (obj1))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 /* #### It would be really nice if this were a proper warning
1551
ddcdeb1a25c4 [xemacs-hg @ 2003-06-30 09:45:42 by stephent]
stephent
parents: 1330
diff changeset
86 instead of brain-dead print to Qexternal_debugging_output. */
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
87 write_msg_string
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 801
diff changeset
88 (Qexternal_debugging_output,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 801
diff changeset
89 "Comparison between integer and character is constant nil (");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 Fprinc (obj1, Qexternal_debugging_output);
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
91 write_msg_string (Qexternal_debugging_output, " and ");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 Fprinc (obj2, Qexternal_debugging_output);
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
93 write_msg_string (Qexternal_debugging_output, ")\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 debug_short_backtrace (debug_ebola_backtrace_length);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 return EQ (obj1, obj2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 #endif /* DEBUG_XEMACS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 wrong_type_argument (Lisp_Object predicate, Lisp_Object value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 REGISTER Lisp_Object tem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 value = Fsignal (Qwrong_type_argument, list2 (predicate, value));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 tem = call1 (predicate, value);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 while (NILP (tem));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 return value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 DOESNT_RETURN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 dead_wrong_type_argument (Lisp_Object predicate, Lisp_Object value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
120 signal_error_1 (Qwrong_type_argument, list2 (predicate, value));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 DEFUN ("wrong-type-argument", Fwrong_type_argument, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 Signal an error until the correct type value is given by the user.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 This function loops, signalling a continuable `wrong-type-argument' error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 with PREDICATE and VALUE as the data associated with the error and then
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 calling PREDICATE on the returned value, until the value gotten satisfies
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 PREDICATE. At that point, the gotten value is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 (predicate, value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 return wrong_type_argument (predicate, value);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 DOESNT_RETURN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 c_write_error (Lisp_Object obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
138 signal_error (Qsetting_constant,
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
139 "Attempt to modify read-only object (c)", obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 DOESNT_RETURN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 lisp_write_error (Lisp_Object obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
145 signal_error (Qsetting_constant,
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
146 "Attempt to modify read-only object (lisp)", obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 DOESNT_RETURN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 args_out_of_range (Lisp_Object a1, Lisp_Object a2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
152 signal_error_1 (Qargs_out_of_range, list2 (a1, a2));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 DOESNT_RETURN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 args_out_of_range_3 (Lisp_Object a1, Lisp_Object a2, Lisp_Object a3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
158 signal_error_1 (Qargs_out_of_range, list3 (a1, a2, a3));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 void
5307
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
162 check_integer_range (Lisp_Object val, Lisp_Object min, Lisp_Object max)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 {
5307
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
164 Lisp_Object args[] = { min, val, max };
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
165 int ii;
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
166
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
167 for (ii = 0; ii < countof (args); ii++)
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
168 {
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
169 CHECK_INTEGER (args[ii]);
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
170 }
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
171
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
172 if (NILP (Fleq (countof (args), args)))
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
173 args_out_of_range_3 (val, min, max);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 /* Data type predicates */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 DEFUN ("eq", Feq, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 Return t if the two args are the same Lisp object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
182 (object1, object2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
184 return EQ_WITH_EBOLA_NOTICE (object1, object2) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 DEFUN ("null", Fnull, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 Return t if OBJECT is nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 return NILP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 DEFUN ("consp", Fconsp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 Return t if OBJECT is a cons cell. `nil' is not a cons cell.
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
197
3355
721daee0fcd8 [xemacs-hg @ 2006-04-23 20:12:25 by aidan]
aidan
parents: 3343
diff changeset
198 See the documentation for `cons' or the Lisp manual for more details on what
721daee0fcd8 [xemacs-hg @ 2006-04-23 20:12:25 by aidan]
aidan
parents: 3343
diff changeset
199 a cons cell is.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 return CONSP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 DEFUN ("atom", Fatom, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207 Return t if OBJECT is not a cons cell. `nil' is not a cons cell.
3355
721daee0fcd8 [xemacs-hg @ 2006-04-23 20:12:25 by aidan]
aidan
parents: 3343
diff changeset
208
721daee0fcd8 [xemacs-hg @ 2006-04-23 20:12:25 by aidan]
aidan
parents: 3343
diff changeset
209 See the documentation for `cons' or the Lisp manual for more details on what
721daee0fcd8 [xemacs-hg @ 2006-04-23 20:12:25 by aidan]
aidan
parents: 3343
diff changeset
210 a cons cell is.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 return CONSP (object) ? Qnil : Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 DEFUN ("listp", Flistp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218 Return t if OBJECT is a list. `nil' is a list.
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
219
3355
721daee0fcd8 [xemacs-hg @ 2006-04-23 20:12:25 by aidan]
aidan
parents: 3343
diff changeset
220 A list is either the Lisp object nil (a symbol), interpreted as the empty
721daee0fcd8 [xemacs-hg @ 2006-04-23 20:12:25 by aidan]
aidan
parents: 3343
diff changeset
221 list in this context, or a cons cell whose CDR refers to either nil or a
721daee0fcd8 [xemacs-hg @ 2006-04-23 20:12:25 by aidan]
aidan
parents: 3343
diff changeset
222 cons cell. A "proper list" contains no cycles.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 return LISTP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 DEFUN ("nlistp", Fnlistp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 Return t if OBJECT is not a list. `nil' is a list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 return LISTP (object) ? Qnil : Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 DEFUN ("true-list-p", Ftrue_list_p, 1, 1, 0, /*
1551
ddcdeb1a25c4 [xemacs-hg @ 2003-06-30 09:45:42 by stephent]
stephent
parents: 1330
diff changeset
238 Return t if OBJECT is an acyclic, nil-terminated (ie, not dotted), list.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 return TRUE_LIST_P (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 DEFUN ("symbolp", Fsymbolp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 Return t if OBJECT is a symbol.
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
247
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
248 A symbol is a Lisp object with a name. It can optionally have any and all of
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
249 a value, a property list and an associated function.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 return SYMBOLP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 DEFUN ("keywordp", Fkeywordp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 Return t if OBJECT is a keyword.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 return KEYWORDP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 DEFUN ("vectorp", Fvectorp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 Return t if OBJECT is a vector.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 return VECTORP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 DEFUN ("bit-vector-p", Fbit_vector_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 Return t if OBJECT is a bit vector.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 return BIT_VECTORP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 DEFUN ("stringp", Fstringp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 Return t if OBJECT is a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 return STRINGP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 DEFUN ("arrayp", Farrayp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 Return t if OBJECT is an array (string, vector, or bit vector).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 {
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
293 return ARRAYP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 DEFUN ("sequencep", Fsequencep, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 Return t if OBJECT is a sequence (list or array).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 {
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
301 return SEQUENCEP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 DEFUN ("markerp", Fmarkerp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 Return t if OBJECT is a marker (editor pointer).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 return MARKERP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 DEFUN ("subrp", Fsubrp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 Return t if OBJECT is a built-in function.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 return SUBRP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 DEFUN ("subr-min-args", Fsubr_min_args, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 Return minimum number of args built-in function SUBR may be called with.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 (subr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 CHECK_SUBR (subr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 return make_int (XSUBR (subr)->min_args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 DEFUN ("subr-max-args", Fsubr_max_args, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 Return maximum number of args built-in function SUBR may be called with,
4905
755ae5b97edb Change "special form" to "special operator" in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
331 or nil if it takes an arbitrary number of arguments or is a special operator.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 (subr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 int nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 CHECK_SUBR (subr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 nargs = XSUBR (subr)->max_args;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 if (nargs == MANY || nargs == UNEVALLED)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 return make_int (nargs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 DEFUN ("subr-interactive", Fsubr_interactive, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
345 Return the interactive spec of the subr object SUBR, or nil.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 If non-nil, the return value will be a list whose first element is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 `interactive' and whose second element is the interactive spec.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 (subr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 858
diff changeset
351 const CIbyte *prompt;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 CHECK_SUBR (subr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 prompt = XSUBR (subr)->prompt;
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
354 return prompt ? list2 (Qinteractive, build_msg_cistring (prompt)) : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 DEFUN ("characterp", Fcharacterp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 Return t if OBJECT is a character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 Unlike in XEmacs v19 and FSF Emacs, a character is its own primitive type.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 Any character can be converted into an equivalent integer using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 `char-int'. To convert the other way, use `int-char'; however,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 only some integers can be converted into characters. Such an integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 is called a `char-int'; see `char-int-p'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 Some functions that work on integers (e.g. the comparison functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 <, <=, =, /=, etc. and the arithmetic functions +, -, *, etc.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 accept characters and implicitly convert them into integers. In
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 general, functions that work on characters also accept char-ints and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 implicitly convert them into characters. WARNING: Neither of these
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 behaviors is very desirable, and they are maintained for backward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 compatibility with old E-Lisp programs that confounded characters and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 integers willy-nilly. These behaviors may change in the future; therefore,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 do not rely on them. Instead, use the character-specific functions such
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 as `char='.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 return CHARP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 DEFUN ("char-to-int", Fchar_to_int, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
383 Convert CHARACTER into an equivalent integer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 The resulting integer will always be non-negative. The integers in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 the range 0 - 255 map to characters as follows:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 0 - 31 Control set 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 32 - 127 ASCII
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 128 - 159 Control set 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 160 - 255 Right half of ISO-8859-1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 If support for Mule does not exist, these are the only valid character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 values. When Mule support exists, the values assigned to other characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 may vary depending on the particular version of XEmacs, the order in which
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 character sets were loaded, etc., and you should not depend on them.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
397 (character))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
399 CHECK_CHAR (character);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
400 return make_int (XCHAR (character));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 DEFUN ("int-to-char", Fint_to_char, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
404 Convert integer INTEGER into the equivalent character.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 Not all integers correspond to valid characters; use `char-int-p' to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 determine whether this is the case. If the integer cannot be converted,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 nil is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 (integer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
411 CHECK_INTEGER (integer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 if (CHAR_INTP (integer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 return make_char (XINT (integer));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 DEFUN ("char-int-p", Fchar_int_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 Return t if OBJECT is an integer that can be converted into a character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 See `char-int'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 return CHAR_INTP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 DEFUN ("char-or-char-int-p", Fchar_or_char_int_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 Return t if OBJECT is a character or an integer that can be converted into one.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 return CHAR_OR_CHAR_INTP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 DEFUN ("char-or-string-p", Fchar_or_string_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 Return t if OBJECT is a character (or a char-int) or a string.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 It is semi-hateful that we allow a char-int here, as it goes against
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 the name of this function, but it makes the most sense considering the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 other steps we take to maintain compatibility with the old character/integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 confoundedness in older versions of E-Lisp.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 return CHAR_OR_CHAR_INTP (object) || STRINGP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
447 DEFUN ("fixnump", Ffixnump, 1, 1, 0, /*
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
448 Return t if OBJECT is a fixnum.
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
449
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
450 In this implementation, a fixnum is an immediate integer, and has a
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
451 maximum value described by the constant `most-positive-fixnum'. This
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
452 contrasts with bignums, integers where the values are limited by your
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
453 available memory.
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
454 */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
455 (object))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
456 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
457 return INTP (object) ? Qt : Qnil;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
458 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 DEFUN ("integerp", Fintegerp, 1, 1, 0, /*
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
460 Return t if OBJECT is an integer, nil otherwise.
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
461
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
462 On builds without bignum support, this function is identical to `fixnump'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
466 return INTEGERP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 Return t if OBJECT is an integer or a marker (editor pointer).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
474 return INTEGERP (object) || MARKERP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 DEFUN ("integer-or-char-p", Finteger_or_char_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 Return t if OBJECT is an integer or a character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
482 return INTEGERP (object) || CHARP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 DEFUN ("integer-char-or-marker-p", Finteger_char_or_marker_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 Return t if OBJECT is an integer, character or a marker (editor pointer).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
490 return INTEGERP (object) || CHARP (object) || MARKERP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 DEFUN ("natnump", Fnatnump, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 Return t if OBJECT is a nonnegative integer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 {
5307
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
498 return NATNUMP (object) ? Qt : Qnil;
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
499 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
500
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
501 DEFUN ("nonnegativep", Fnonnegativep, 1, 1, 0, /*
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
502 Return t if OBJECT is a nonnegative number.
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
503 */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
504 (object))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
505 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
506 return NATNUMP (object)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
507 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
508 || (RATIOP (object) && ratio_sign (XRATIO_DATA (object)) >= 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
509 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
510 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
511 || (BIGFLOATP (object) && bigfloat_sign (XBIGFLOAT_DATA (object)) >= 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
512 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
513 ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 DEFUN ("bitp", Fbitp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 Return t if OBJECT is a bit (0 or 1).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 return BITP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 DEFUN ("numberp", Fnumberp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 Return t if OBJECT is a number (floating point or integer).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
529 return NUMBERP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 DEFUN ("number-or-marker-p", Fnumber_or_marker_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 Return t if OBJECT is a number or a marker.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
537 return NUMBERP (object) || MARKERP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 DEFUN ("number-char-or-marker-p", Fnumber_char_or_marker_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 Return t if OBJECT is a number, character or a marker.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
545 return (NUMBERP (object) || CHARP (object) || MARKERP (object))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 DEFUN ("floatp", Ffloatp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 Return t if OBJECT is a floating point number.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 return FLOATP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 DEFUN ("type-of", Ftype_of, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 Return a symbol representing the type of OBJECT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 switch (XTYPE (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 case Lisp_Type_Record:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 return intern (XRECORD_LHEADER_IMPLEMENTATION (object)->name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 case Lisp_Type_Char: return Qcharacter;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 default: return Qinteger;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 /* Extract and set components of lists */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 DEFUN ("car", Fcar, 1, 1, 0, /*
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
577 Return the car of CONS. If CONS is nil, return nil.
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
578 The car of a list or a dotted pair is its first element.
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
579
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
580 Error if CONS is not nil and not a cons cell. See also `car-safe'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 */
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
582 (cons))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 {
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
586 if (CONSP (cons))
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
587 return XCAR (cons);
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
588 else if (NILP (cons))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 else
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
591 cons = wrong_type_argument (Qlistp, cons);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 DEFUN ("car-safe", Fcar_safe, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 Return the car of OBJECT if it is a cons cell, or else nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 return CONSP (object) ? XCAR (object) : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 DEFUN ("cdr", Fcdr, 1, 1, 0, /*
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
604 Return the cdr of CONS. If CONS is nil, return nil.
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
605 The cdr of a list is the list without its first element. The cdr of a
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
606 dotted pair (A . B) is the second element, B.
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
607
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 Error if arg is not nil and not a cons cell. See also `cdr-safe'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 */
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
610 (cons))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 {
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
614 if (CONSP (cons))
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
615 return XCDR (cons);
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
616 else if (NILP (cons))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 else
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
619 cons = wrong_type_argument (Qlistp, cons);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 DEFUN ("cdr-safe", Fcdr_safe, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 Return the cdr of OBJECT if it is a cons cell, else nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 return CONSP (object) ? XCDR (object) : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 DEFUN ("setcar", Fsetcar, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
632 Set the car of CONS-CELL to be NEWCAR. Return NEWCAR.
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
633 The car of a list or a dotted pair is its first element.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
635 (cons_cell, newcar))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
637 if (!CONSP (cons_cell))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
638 cons_cell = wrong_type_argument (Qconsp, cons_cell);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
640 XCAR (cons_cell) = newcar;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 return newcar;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 DEFUN ("setcdr", Fsetcdr, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
645 Set the cdr of CONS-CELL to be NEWCDR. Return NEWCDR.
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
646 The cdr of a list is the list without its first element. The cdr of a
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
647 dotted pair (A . B) is the second element, B.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
649 (cons_cell, newcdr))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
651 if (!CONSP (cons_cell))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
652 cons_cell = wrong_type_argument (Qconsp, cons_cell);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
654 XCDR (cons_cell) = newcdr;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 return newcdr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 /* Find the function at the end of a chain of symbol function indirections.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660 If OBJECT is a symbol, find the end of its function chain and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 return the value found there. If OBJECT is not a symbol, just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 return it. If there is a cycle in the function chain, signal a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 cyclic-function-indirection error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
665 This is like Findirect_function when VOID_FUNCTION_ERRORP is true.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
666 When VOID_FUNCTION_ERRORP is false, no error is signaled if the end
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
667 of the chain ends up being Qunbound. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 Lisp_Object
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
669 indirect_function (Lisp_Object object, int void_function_errorp)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 #define FUNCTION_INDIRECTION_SUSPICION_LENGTH 16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 Lisp_Object tortoise, hare;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 int count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 for (hare = tortoise = object, count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 SYMBOLP (hare);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 hare = XSYMBOL (hare)->function, count++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 if (count < FUNCTION_INDIRECTION_SUSPICION_LENGTH) continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 if (count & 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 tortoise = XSYMBOL (tortoise)->function;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 if (EQ (hare, tortoise))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 return Fsignal (Qcyclic_function_indirection, list1 (object));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
687 if (void_function_errorp && UNBOUNDP (hare))
436
080151679be2 Import from CVS: tag r21-2-26
cvs
parents: 428
diff changeset
688 return signal_void_function_error (object);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 return hare;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 DEFUN ("indirect-function", Findirect_function, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 Return the function at the end of OBJECT's function chain.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 If OBJECT is a symbol, follow all function indirections and return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 the final function binding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 If OBJECT is not a symbol, just return it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 Signal a void-function error if the final symbol is unbound.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 Signal a cyclic-function-indirection error if there is a loop in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 function chain of symbols.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 return indirect_function (object, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 /* Extract and set vector and string elements */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 DEFUN ("aref", Faref, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 Return the element of ARRAY at index INDEX.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 ARRAY may be a vector, bit vector, or string. INDEX starts at 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 (array, index_))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 EMACS_INT idx;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 if (INTP (index_)) idx = XINT (index_);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 else if (CHARP (index_)) idx = XCHAR (index_); /* yuck! */
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
721 #ifdef HAVE_BIGNUM
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
722 else if (BIGNUMP (index_))
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
723 {
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
724 Lisp_Object canon = Fcanonicalize_number (index_);
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
725 if (EQ (canon, index_))
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
726 {
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
727 /* We don't support non-fixnum indices. */
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
728 goto range_error;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
729 }
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
730 index_ = canon;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
731 goto retry;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
732 }
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
733 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 index_ = wrong_type_argument (Qinteger_or_char_p, index_);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 if (idx < 0) goto range_error;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 if (VECTORP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 if (idx >= XVECTOR_LENGTH (array)) goto range_error;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 return XVECTOR_DATA (array)[idx];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 else if (BIT_VECTORP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
749 if (idx >= (EMACS_INT) bit_vector_length (XBIT_VECTOR (array)))
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
750 goto range_error;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 return make_int (bit_vector_bit (XBIT_VECTOR (array), idx));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 else if (STRINGP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 801
diff changeset
755 if (idx >= string_char_length (array)) goto range_error;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 858
diff changeset
756 return make_char (string_ichar (array, idx));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 #ifdef LOSING_BYTECODE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 else if (COMPILED_FUNCTIONP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 /* Weird, gross compatibility kludge */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 return Felt (array, index_);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 check_losing_bytecode ("aref", array);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 array = wrong_type_argument (Qarrayp, array);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 range_error:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 args_out_of_range (array, index_);
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
774 RETURN_NOT_REACHED (Qnil);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 DEFUN ("aset", Faset, 3, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 Store into the element of ARRAY at index INDEX the value NEWVAL.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 ARRAY may be a vector, bit vector, or string. INDEX starts at 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 (array, index_, newval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 EMACS_INT idx;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 if (INTP (index_)) idx = XINT (index_);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 else if (CHARP (index_)) idx = XCHAR (index_); /* yuck! */
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
789 #ifdef HAVE_BIGNUM
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
790 else if (BIGNUMP (index_))
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
791 {
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
792 Lisp_Object canon = Fcanonicalize_number (index_);
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
793 if (EQ (canon, index_))
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
794 {
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
795 /* We don't support non-fixnum indices. */
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
796 goto range_error;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
797 }
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
798 index_ = canon;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
799 goto retry;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
800 }
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
801 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 index_ = wrong_type_argument (Qinteger_or_char_p, index_);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 if (idx < 0) goto range_error;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
810 CHECK_LISP_WRITEABLE (array);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 if (VECTORP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 if (idx >= XVECTOR_LENGTH (array)) goto range_error;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 XVECTOR_DATA (array)[idx] = newval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 else if (BIT_VECTORP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
818 if (idx >= (EMACS_INT) bit_vector_length (XBIT_VECTOR (array)))
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
819 goto range_error;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 CHECK_BIT (newval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 set_bit_vector_bit (XBIT_VECTOR (array), idx, !ZEROP (newval));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 else if (STRINGP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 CHECK_CHAR_COERCE_INT (newval);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 801
diff changeset
826 if (idx >= string_char_length (array)) goto range_error;
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 771
diff changeset
827 set_string_char (array, idx, XCHAR (newval));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 bump_string_modiff (array);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 array = wrong_type_argument (Qarrayp, array);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 return newval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 range_error:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 args_out_of_range (array, index_);
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
840 RETURN_NOT_REACHED (Qnil);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 /**********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 /* Arithmetic functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 /**********************************************************************/
2001
cc5b615380f8 [xemacs-hg @ 2004-04-08 15:23:07 by james]
james
parents: 1995
diff changeset
847 #ifndef WITH_NUMBER_TYPES
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 typedef struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 int int_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 union
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 EMACS_INT ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 double dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 } c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 } int_or_double;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 number_char_or_marker_to_int_or_double (Lisp_Object obj, int_or_double *p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 p->int_p = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 if (INTP (obj)) p->c.ival = XINT (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 else if (CHARP (obj)) p->c.ival = XCHAR (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 else if (MARKERP (obj)) p->c.ival = marker_position (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 else if (FLOATP (obj)) p->c.dval = XFLOAT_DATA (obj), p->int_p = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 obj = wrong_type_argument (Qnumber_char_or_marker_p, obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 static double
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 number_char_or_marker_to_double (Lisp_Object obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 if (INTP (obj)) return (double) XINT (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 else if (CHARP (obj)) return (double) XCHAR (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 else if (MARKERP (obj)) return (double) marker_position (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 else if (FLOATP (obj)) return XFLOAT_DATA (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 obj = wrong_type_argument (Qnumber_char_or_marker_p, obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 }
2001
cc5b615380f8 [xemacs-hg @ 2004-04-08 15:23:07 by james]
james
parents: 1995
diff changeset
888 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 static EMACS_INT
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
891 fixnum_char_or_marker_to_int (Lisp_Object obj)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 if (INTP (obj)) return XINT (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 else if (CHARP (obj)) return XCHAR (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
896 else if (MARKERP (obj)) return marker_position (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
899 /* On bignum builds, we can only be called from #'lognot, which
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
900 protects against this happening: */
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
901 assert (!BIGNUMP (obj));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 obj = wrong_type_argument (Qinteger_char_or_marker_p, obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
907 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
908
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
909 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
910 #define BIGNUM_CASE(op) \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
911 case BIGNUM_T: \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
912 if (!bignum_##op (XBIGNUM_DATA (obj1), XBIGNUM_DATA (obj2))) \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
913 return Qnil; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
914 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
915 #else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
916 #define BIGNUM_CASE(op)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
917 #endif /* HAVE_BIGNUM */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
918
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
919 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
920 #define RATIO_CASE(op) \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
921 case RATIO_T: \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
922 if (!ratio_##op (XRATIO_DATA (obj1), XRATIO_DATA (obj2))) \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
923 return Qnil; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
924 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
925 #else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
926 #define RATIO_CASE(op)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
927 #endif /* HAVE_RATIO */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
928
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
929 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
930 #define BIGFLOAT_CASE(op) \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
931 case BIGFLOAT_T: \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
932 if (!bigfloat_##op (XBIGFLOAT_DATA (obj1), XBIGFLOAT_DATA (obj2))) \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
933 return Qnil; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
934 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
935 #else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
936 #define BIGFLOAT_CASE(op)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
937 #endif /* HAVE_BIGFLOAT */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
938
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
939 #define ARITHCOMPARE_MANY(c_op,op) \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
940 { \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
941 REGISTER int i; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
942 Lisp_Object obj1, obj2; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
943 \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
944 for (i = 1; i < nargs; i++) \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
945 { \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
946 obj1 = args[i - 1]; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
947 obj2 = args[i]; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
948 switch (promote_args (&obj1, &obj2)) \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
949 { \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
950 case FIXNUM_T: \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
951 if (!(XREALINT (obj1) c_op XREALINT (obj2))) \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
952 return Qnil; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
953 break; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
954 BIGNUM_CASE (op) \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
955 RATIO_CASE (op) \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
956 case FLOAT_T: \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
957 if (!(XFLOAT_DATA (obj1) c_op XFLOAT_DATA (obj2))) \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
958 return Qnil; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
959 break; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
960 BIGFLOAT_CASE (op) \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
961 } \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
962 } \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
963 return Qt; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
964 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
965 #else /* !WITH_NUMBER_TYPES */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
966 #define ARITHCOMPARE_MANY(c_op,op) \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 int_or_double iod1, iod2, *p = &iod1, *q = &iod2; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 Lisp_Object *args_end = args + nargs; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
970 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 number_char_or_marker_to_int_or_double (*args++, p); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 while (args < args_end) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975 number_char_or_marker_to_int_or_double (*args++, q); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 if (!((p->int_p && q->int_p) ? \
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
978 (p->c.ival c_op q->c.ival) : \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
979 ((p->int_p ? (double) p->c.ival : p->c.dval) c_op \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 (q->int_p ? (double) q->c.ival : q->c.dval)))) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 return Qnil; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 { /* swap */ int_or_double *r = p; p = q; q = r; } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 return Qt; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 }
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
987 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
989 DEFUN ("=", Feqlsign, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 Return t if all the arguments are numerically equal.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
991 The arguments may be numbers, characters or markers.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
992
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
993 arguments: (FIRST &rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
997 ARITHCOMPARE_MANY (==, eql)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
998 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
999
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 DEFUN ("<", Flss, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 Return t if the sequence of arguments is monotonically increasing.
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
1002
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
1003 (That is, if there is a second argument, it must be numerically greater than
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
1004 the first. If there is a third, it must be numerically greater than the
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
1005 second, and so on.) At least one argument is required.
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
1006
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
1007 The arguments may be numbers, characters or markers.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1008
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1009 arguments: (FIRST &rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1013 ARITHCOMPARE_MANY (<, lt)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 DEFUN (">", Fgtr, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 Return t if the sequence of arguments is monotonically decreasing.
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
1018
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
1019 (That is, if there is a second argument, it must be numerically less than
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
1020 the first. If there is a third, it must be numerically less than the
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
1021 second, and so forth.) At least one argument is required.
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
1022
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 The arguments may be numbers, characters or markers.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1024
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1025 arguments: (FIRST &rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1029 ARITHCOMPARE_MANY (>, gt)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 DEFUN ("<=", Fleq, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 Return t if the sequence of arguments is monotonically nondecreasing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 The arguments may be numbers, characters or markers.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1035
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1036 arguments: (FIRST &rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1040 ARITHCOMPARE_MANY (<=, le)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 DEFUN (">=", Fgeq, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 Return t if the sequence of arguments is monotonically nonincreasing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 The arguments may be numbers, characters or markers.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1046
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1047 arguments: (FIRST &rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1051 ARITHCOMPARE_MANY (>=, ge)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1052 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1053
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1054 /* Unlike all the other comparisons, this is an O(N*N) algorithm. But who
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1055 cares? Inspection of all elisp code distributed by xemacs.org shows that
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1056 it is almost always called with 2 arguments, rarely with 3, and never with
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1057 more than 3. The constant factors of algorithms with better asymptotic
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1058 complexity are higher, which means that those algorithms will run SLOWER
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1059 than this one in the common case. Optimize the common case! */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1060 DEFUN ("/=", Fneq, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1061 Return t if no two arguments are numerically equal.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 The arguments may be numbers, characters or markers.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1063
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1064 arguments: (FIRST &rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1067 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1068 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1069 REGISTER int i, j;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1070 Lisp_Object obj1, obj2;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1071
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1072 for (i = 0; i < nargs - 1; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1073 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1074 obj1 = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1075 for (j = i + 1; j < nargs; j++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1076 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1077 obj2 = args[j];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1078 switch (promote_args (&obj1, &obj2))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1079 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1080 case FIXNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1081 if (XREALINT (obj1) == XREALINT (obj2))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1082 return Qnil;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1083 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1084 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1085 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1086 if (bignum_eql (XBIGNUM_DATA (obj1), XBIGNUM_DATA (obj2)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1087 return Qnil;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1088 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1089 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1090 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1091 case RATIO_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1092 if (ratio_eql (XRATIO_DATA (obj1), XRATIO_DATA (obj2)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1093 return Qnil;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1094 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1095 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1096 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1097 if (XFLOAT_DATA (obj1) == XFLOAT_DATA (obj2))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1098 return Qnil;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1099 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1100 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1101 case BIGFLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1102 if (bigfloat_eql (XBIGFLOAT_DATA (obj1), XBIGFLOAT_DATA (obj2)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1103 return Qnil;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1104 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1105 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1106 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1107 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1108 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1109 return Qt;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1110 #else /* !WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1111 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1112 Lisp_Object *p, *q;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1113
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1114 /* Unlike all the other comparisons, this is an N*N algorithm.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 We could use a hash table for nargs > 50 to make this linear. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 for (p = args; p < args_end; p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1117 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1118 int_or_double iod1, iod2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 number_char_or_marker_to_int_or_double (*p, &iod1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 for (q = p + 1; q < args_end; q++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 number_char_or_marker_to_int_or_double (*q, &iod2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1125 if (!((iod1.int_p && iod2.int_p) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 (iod1.c.ival != iod2.c.ival) :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 ((iod1.int_p ? (double) iod1.c.ival : iod1.c.dval) !=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128 (iod2.int_p ? (double) iod2.c.ival : iod2.c.dval))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 return Qt;
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1133 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1134 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1136 DEFUN ("zerop", Fzerop, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1137 Return t if NUMBER is zero.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1138 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1139 (number))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 if (INTP (number))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 return EQ (number, Qzero) ? Qt : Qnil;
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1144 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1145 else if (BIGNUMP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1146 return bignum_sign (XBIGNUM_DATA (number)) == 0 ? Qt : Qnil;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1147 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1148 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1149 else if (RATIOP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1150 return ratio_sign (XRATIO_DATA (number)) == 0 ? Qt : Qnil;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1151 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1152 else if (FLOATP (number))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1153 return XFLOAT_DATA (number) == 0.0 ? Qt : Qnil;
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1154 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1155 else if (BIGFLOATP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1156 return bigfloat_sign (XBIGFLOAT_DATA (number)) == 0 ? Qt : Qnil;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1157 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1158 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1159 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1160 number = wrong_type_argument (Qnumberp, number);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1161 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1163 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 /* Convert between a 32-bit value and a cons of two 16-bit values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 This is used to pass 32-bit integers to and from the user.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 Use time_to_lisp() and lisp_to_time() for time values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1168
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169 If you're thinking of using this to store a pointer into a Lisp Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 for internal purposes (such as when calling record_unwind_protect()),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1171 try using make_opaque_ptr()/get_opaque_ptr() instead. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 word_to_lisp (unsigned int item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 return Fcons (make_int (item >> 16), make_int (item & 0xffff));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 unsigned int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1179 lisp_to_word (Lisp_Object item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1180 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1181 if (INTP (item))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 return XINT (item);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1185 Lisp_Object top = Fcar (item);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1186 Lisp_Object bot = Fcdr (item);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 CHECK_INT (top);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 CHECK_INT (bot);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 return (XINT (top) << 16) | (XINT (bot) & 0xffff);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1191 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1192
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 DEFUN ("number-to-string", Fnumber_to_string, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1195 Convert NUMBER to a string by printing it in decimal.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196 Uses a minus sign if negative.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1197 NUMBER may be an integer or a floating point number.
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1198 If supported, it may also be a ratio.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1199 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1200 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1201 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1202 CHECK_NUMBER (number);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1204 if (FLOATP (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 {
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
1206 Ascbyte pigbuf[350]; /* see comments in float_to_string */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1208 float_to_string (pigbuf, XFLOAT_DATA (number));
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
1209 return build_ascstring (pigbuf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1210 }
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1211 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1212 if (BIGNUMP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1213 {
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
1214 Ascbyte *str = bignum_to_string (XBIGNUM_DATA (number), 10);
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
1215 Lisp_Object retval = build_ascstring (str);
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4962
diff changeset
1216 xfree (str);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1217 return retval;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1218 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1219 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1220 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1221 if (RATIOP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1222 {
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
1223 Ascbyte *str = ratio_to_string (XRATIO_DATA (number), 10);
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
1224 Lisp_Object retval = build_ascstring (str);
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4962
diff changeset
1225 xfree (str);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1226 return retval;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1227 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1228 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1229 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1230 if (BIGFLOATP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1231 {
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
1232 Ascbyte *str = bigfloat_to_string (XBIGFLOAT_DATA (number), 10);
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
1233 Lisp_Object retval = build_ascstring (str);
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4962
diff changeset
1234 xfree (str);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1235 return retval;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1236 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1237 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238
603
1c880911c386 [xemacs-hg @ 2001-06-01 08:23:09 by martinb]
martinb
parents: 580
diff changeset
1239 {
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
1240 Ascbyte buffer[DECIMAL_PRINT_SIZE (long)];
603
1c880911c386 [xemacs-hg @ 2001-06-01 08:23:09 by martinb]
martinb
parents: 580
diff changeset
1241
1c880911c386 [xemacs-hg @ 2001-06-01 08:23:09 by martinb]
martinb
parents: 580
diff changeset
1242 long_to_string (buffer, XINT (number));
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
1243 return build_ascstring (buffer);
603
1c880911c386 [xemacs-hg @ 2001-06-01 08:23:09 by martinb]
martinb
parents: 580
diff changeset
1244 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246
2001
cc5b615380f8 [xemacs-hg @ 2004-04-08 15:23:07 by james]
james
parents: 1995
diff changeset
1247 #ifndef HAVE_BIGNUM
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 digit_to_number (int character, int base)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 /* Assumes ASCII */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 int digit = ((character >= '0' && character <= '9') ? character - '0' :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 (character >= 'a' && character <= 'z') ? character - 'a' + 10 :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 (character >= 'A' && character <= 'Z') ? character - 'A' + 10 :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 -1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 return digit >= base ? -1 : digit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 }
2001
cc5b615380f8 [xemacs-hg @ 2004-04-08 15:23:07 by james]
james
parents: 1995
diff changeset
1259 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 DEFUN ("string-to-number", Fstring_to_number, 1, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1262 Convert STRING to a number by parsing it as a number in base BASE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 This parses both integers and floating point numbers.
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1264 If they are supported, it also reads ratios.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 It ignores leading spaces and tabs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1267 If BASE is nil or omitted, base 10 is used.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1268 BASE must be an integer between 2 and 16 (inclusive).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 Floating point numbers always use base 10.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 (string, base))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 {
1995
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1994
diff changeset
1273 Ibyte *p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 int b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 CHECK_STRING (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 if (NILP (base))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 b = 10;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 {
5307
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
1282 check_integer_range (base, make_int (2), make_int (16));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 b = XINT (base);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285
1995
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1994
diff changeset
1286 p = XSTRING_DATA (string);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 /* Skip any whitespace at the front of the number. Some versions of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289 atoi do this anyway, so we might as well make Emacs lisp consistent. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 while (*p == ' ' || *p == '\t')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292
1995
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1994
diff changeset
1293 if (isfloat_string ((const char *) p) && b == 10)
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1294 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1295 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1296 if (ZEROP (Vdefault_float_precision))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1297 #endif
1995
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1994
diff changeset
1298 return make_float (atof ((const char *) p));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1299 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1300 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1301 {
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1302 /* The GMP version of bigfloat_set_string (mpf_set_str) has the
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1303 following limitation: if p starts with a '+' sign, it does
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1304 nothing; i.e., it leaves its bigfloat argument untouched.
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1305 Therefore, move p past any leading '+' signs. */
2010
a9cdbfb4716e [xemacs-hg @ 2004-04-13 15:38:30 by james]
james
parents: 2001
diff changeset
1306 if (*p == '+')
a9cdbfb4716e [xemacs-hg @ 2004-04-13 15:38:30 by james]
james
parents: 2001
diff changeset
1307 p++;
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1308 bigfloat_set_prec (scratch_bigfloat, bigfloat_get_default_prec ());
1995
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1994
diff changeset
1309 bigfloat_set_string (scratch_bigfloat, (const char *) p, b);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1310 return make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1311 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1312 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1313 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1314
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1315 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1316 if (qxestrchr (p, '/') != NULL)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1317 {
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1318 /* The GMP version of ratio_set_string (mpq_set_str) has the following
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1319 limitations:
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1320 - If p starts with a '+' sign, it does nothing; i.e., it leaves its
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1321 ratio argument untouched.
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1322 - If p has a '+' sign after the '/' (e.g., 300/+400), it sets the
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1323 numerator from the string, but *leaves the denominator unchanged*.
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1324 - If p has trailing nonnumeric characters, it sets the numerator from
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1325 the string, but leaves the denominator unchanged.
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1326 - If p has more than one '/', (e.g., 1/2/3), then it sets the
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1327 numerator from the string, but leaves the denominator unchanged.
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1328
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1329 Therefore, move p past any leading '+' signs, temporarily drop a null
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1330 after the numeric characters we are trying to convert, and then put
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1331 the nulled character back afterward. I am not going to fix problem
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1332 #2; just don't write ratios that look like that. */
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1333 Ibyte *end, save;
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1334
2010
a9cdbfb4716e [xemacs-hg @ 2004-04-13 15:38:30 by james]
james
parents: 2001
diff changeset
1335 if (*p == '+')
a9cdbfb4716e [xemacs-hg @ 2004-04-13 15:38:30 by james]
james
parents: 2001
diff changeset
1336 p++;
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1337
2014
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1338 end = p;
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1339 if (*end == '-')
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1340 end++;
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1341 while ((*end >= '0' && *end <= '9') ||
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1342 (b > 10 && *end >= 'a' && *end <= 'a' + b - 11) ||
2014
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1343 (b > 10 && *end >= 'A' && *end <= 'A' + b - 11))
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1344 end++;
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1345 if (*end == '/')
2014
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1346 {
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1347 end++;
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1348 if (*end == '-')
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1349 end++;
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1350 while ((*end >= '0' && *end <= '9') ||
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1351 (b > 10 && *end >= 'a' && *end <= 'a' + b - 11) ||
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1352 (b > 10 && *end >= 'A' && *end <= 'A' + b - 11))
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1353 end++;
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1354 }
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1355 save = *end;
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1356 *end = '\0';
1995
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1994
diff changeset
1357 ratio_set_string (scratch_ratio, (const char *) p, b);
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1358 *end = save;
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1359 ratio_canonicalize (scratch_ratio);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1360 return make_ratio_rt (scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1361 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1362 #endif /* HAVE_RATIO */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1363
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1364 #ifdef HAVE_BIGNUM
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1365 {
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1366 /* The GMP version of bignum_set_string (mpz_set_str) has the following
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1367 limitations:
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1368 - If p starts with a '+' sign, it does nothing; i.e., it leaves its
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1369 bignum argument untouched.
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1370 - If p is the empty string, it does nothing.
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1371 - If p has trailing nonnumeric characters, it does nothing.
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1372
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1373 Therefore, move p past any leading '+' signs, temporarily drop a null
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1374 after the numeric characters we are trying to convert, special case the
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1375 empty string, and then put the nulled character back afterward. */
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1376 Ibyte *end, save;
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1377 Lisp_Object retval;
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1378
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1379 if (*p == '+')
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1380 p++;
2014
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1381 end = p;
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1382 if (*end == '-')
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1383 end++;
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1384 while ((*end >= '0' && *end <= '9') ||
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1385 (b > 10 && *end >= 'a' && *end <= 'a' + b - 11) ||
2014
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1386 (b > 10 && *end >= 'A' && *end <= 'A' + b - 11))
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1387 end++;
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1388 save = *end;
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1389 *end = '\0';
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1390 if (*p == '\0')
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1391 retval = make_int (0);
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1392 else
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1393 {
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1394 bignum_set_string (scratch_bignum, (const char *) p, b);
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1395 retval = Fcanonicalize_number (make_bignum_bg (scratch_bignum));
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1396 }
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1397 *end = save;
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1398 return retval;
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1399 }
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1400 #else
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 if (b == 10)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 /* Use the system-provided functions for base 10. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 #if SIZEOF_EMACS_INT == SIZEOF_INT
2054
91d4c8c65a0f [xemacs-hg @ 2004-05-02 04:06:51 by malcolmp]
malcolmp
parents: 2039
diff changeset
1405 return make_int (atoi ((char*) p));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 #elif SIZEOF_EMACS_INT == SIZEOF_LONG
2054
91d4c8c65a0f [xemacs-hg @ 2004-05-02 04:06:51 by malcolmp]
malcolmp
parents: 2039
diff changeset
1407 return make_int (atol ((char*) p));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 #elif SIZEOF_EMACS_INT == SIZEOF_LONG_LONG
2054
91d4c8c65a0f [xemacs-hg @ 2004-05-02 04:06:51 by malcolmp]
malcolmp
parents: 2039
diff changeset
1409 return make_int (atoll ((char*) p));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1414 int negative = 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 EMACS_INT v = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 if (*p == '-')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 negative = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 else if (*p == '+')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1426 int digit = digit_to_number (*p++, b);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 if (digit < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 v = v * b + digit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 return make_int (negative * v);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 }
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1433 #endif /* HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 DEFUN ("+", Fplus, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 Return sum of any number of arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1439 The arguments should all be numbers, characters or markers.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1440
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1441 arguments: (&rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1445 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1446 REGISTER int i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1447 Lisp_Object accum = make_int (0), addend;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1448
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1449 for (i = 0; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1450 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1451 addend = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1452 switch (promote_args (&accum, &addend))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1453 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1454 case FIXNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1455 accum = make_integer (XREALINT (accum) + XREALINT (addend));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1456 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1457 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1458 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1459 bignum_add (scratch_bignum, XBIGNUM_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1460 XBIGNUM_DATA (addend));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1461 accum = make_bignum_bg (scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1462 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1463 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1464 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1465 case RATIO_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1466 ratio_add (scratch_ratio, XRATIO_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1467 XRATIO_DATA (addend));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1468 accum = make_ratio_rt (scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1469 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1470 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1471 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1472 accum = make_float (XFLOAT_DATA (accum) + XFLOAT_DATA (addend));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1473 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1474 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1475 case BIGFLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1476 bigfloat_set_prec (scratch_bigfloat,
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1477 max (XBIGFLOAT_GET_PREC (addend),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1478 XBIGFLOAT_GET_PREC (accum)));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1479 bigfloat_add (scratch_bigfloat, XBIGFLOAT_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1480 XBIGFLOAT_DATA (addend));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1481 accum = make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1482 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1483 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1484 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1485 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1486 return Fcanonicalize_number (accum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1487 #else /* !WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488 EMACS_INT iaccum = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 iaccum += iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 double daccum = (double) iaccum + iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1501 daccum += number_char_or_marker_to_double (*args++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 return make_float (daccum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506 return make_int (iaccum);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1507 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 DEFUN ("-", Fminus, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 Negate number or subtract numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 With one arg, negates it. With more than one arg,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513 subtracts all but the first from the first.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1514
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1515 arguments: (FIRST &rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1519 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1520 REGISTER int i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1521 Lisp_Object accum = args[0], subtrahend;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1522
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1523 if (nargs == 1)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1524 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1525 if (CHARP (accum))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1526 accum = make_int (XCHAR (accum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1527 else if (MARKERP (accum))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1528 accum = make_int (marker_position (accum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1529
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1530 /* Invert the sign of accum */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1531 CHECK_NUMBER (accum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1532 switch (get_number_type (accum))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1533 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1534 case FIXNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1535 return make_integer (-XREALINT (accum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1536 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1537 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1538 bignum_neg (scratch_bignum, XBIGNUM_DATA (accum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1539 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1540 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1541 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1542 case RATIO_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1543 ratio_neg (scratch_ratio, XRATIO_DATA (accum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1544 return make_ratio_rt (scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1545 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1546 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1547 return make_float (-XFLOAT_DATA (accum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1548 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1549 case BIGFLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1550 bigfloat_set_prec (scratch_bigfloat, XBIGFLOAT_GET_PREC (accum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1551 bigfloat_neg (scratch_bigfloat, XBIGFLOAT_DATA (accum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1552 return make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1553 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1554 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1555 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1556 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1557 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1558 /* Subtrace the remaining arguments from accum */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1559 for (i = 1; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1560 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1561 subtrahend = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1562 switch (promote_args (&accum, &subtrahend))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1563 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1564 case FIXNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1565 accum = make_integer (XREALINT (accum) - XREALINT (subtrahend));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1566 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1567 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1568 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1569 bignum_sub (scratch_bignum, XBIGNUM_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1570 XBIGNUM_DATA (subtrahend));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1571 accum = make_bignum_bg (scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1572 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1573 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1574 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1575 case RATIO_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1576 ratio_sub (scratch_ratio, XRATIO_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1577 XRATIO_DATA (subtrahend));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1578 accum = make_ratio_rt (scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1579 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1580 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1581 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1582 accum =
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1583 make_float (XFLOAT_DATA (accum) - XFLOAT_DATA (subtrahend));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1584 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1585 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1586 case BIGFLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1587 bigfloat_set_prec (scratch_bigfloat,
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1588 max (XBIGFLOAT_GET_PREC (subtrahend),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1589 XBIGFLOAT_GET_PREC (accum)));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1590 bigfloat_sub (scratch_bigfloat, XBIGFLOAT_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1591 XBIGFLOAT_DATA (subtrahend));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1592 accum = make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1593 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1594 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1595 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1596 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1597 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1598 return Fcanonicalize_number (accum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1599 #else /* !WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 EMACS_INT iaccum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 double daccum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 iaccum = nargs > 1 ? iod.c.ival : - iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 daccum = nargs > 1 ? iod.c.dval : - iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611 goto do_float;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 iaccum -= iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621 daccum = (double) iaccum - iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 goto do_float;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1626 return make_int (iaccum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 do_float:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629 for (; args < args_end; args++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 daccum -= number_char_or_marker_to_double (*args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 return make_float (daccum);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1632 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 DEFUN ("*", Ftimes, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636 Return product of any number of arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 The arguments should all be numbers, characters or markers.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1638
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1639 arguments: (&rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1643 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1644 REGISTER int i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1645 /* Start with a bignum to avoid overflow */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1646 Lisp_Object accum = make_bignum (1L), multiplier;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1647
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1648 for (i = 0; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1649 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1650 multiplier = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1651 switch (promote_args (&accum, &multiplier))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1652 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1653 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1654 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1655 bignum_mul (scratch_bignum, XBIGNUM_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1656 XBIGNUM_DATA (multiplier));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1657 accum = make_bignum_bg (scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1658 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1659 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1660 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1661 case RATIO_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1662 ratio_mul (scratch_ratio, XRATIO_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1663 XRATIO_DATA (multiplier));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1664 accum = make_ratio_rt (scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1665 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1666 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1667 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1668 accum = make_float (XFLOAT_DATA (accum) * XFLOAT_DATA (multiplier));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1669 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1670 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1671 case BIGFLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1672 bigfloat_set_prec (scratch_bigfloat,
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1673 max (XBIGFLOAT_GET_PREC (multiplier),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1674 XBIGFLOAT_GET_PREC (accum)));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1675 bigfloat_mul (scratch_bigfloat, XBIGFLOAT_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1676 XBIGFLOAT_DATA (multiplier));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1677 accum = make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1678 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1679 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1680 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1681 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1682 return Fcanonicalize_number (accum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1683 #else /* !WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 EMACS_INT iaccum = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692 iaccum *= iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 double daccum = (double) iaccum * iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 daccum *= number_char_or_marker_to_double (*args++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 return make_float (daccum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 return make_int (iaccum);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1703 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1706 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1707 DEFUN ("div", Fdiv, 1, MANY, 0, /*
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1708 Same as `/', but dividing integers creates a ratio instead of truncating.
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1709 Note that this is a departure from Common Lisp, where / creates ratios when
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1710 dividing integers. Having a separate function lets us avoid breaking existing
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1711 Emacs Lisp code that expects / to do integer division.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1712
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1713 arguments: (FIRST &rest ARGS)
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1714 */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1715 (int nargs, Lisp_Object *args))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1716 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1717 REGISTER int i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1718 Lisp_Object accum, divisor;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1719
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1720 if (nargs == 1)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1721 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1722 i = 0;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1723 accum = make_int (1);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1724 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1725 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1726 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1727 i = 1;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1728 accum = args[0];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1729 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1730 for (; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1731 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1732 divisor = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1733 switch (promote_args (&accum, &divisor))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1734 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1735 case FIXNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1736 if (XREALINT (divisor) == 0) goto divide_by_zero;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1737 bignum_set_long (scratch_bignum, XREALINT (accum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1738 bignum_set_long (scratch_bignum2, XREALINT (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1739 accum = make_ratio_bg (scratch_bignum, scratch_bignum2);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1740 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1741 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1742 if (bignum_sign (XBIGNUM_DATA (divisor)) == 0) goto divide_by_zero;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1743 accum = make_ratio_bg (XBIGNUM_DATA (accum), XBIGNUM_DATA (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1744 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1745 case RATIO_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1746 if (ratio_sign (XRATIO_DATA (divisor)) == 0) goto divide_by_zero;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1747 ratio_div (scratch_ratio, XRATIO_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1748 XRATIO_DATA (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1749 accum = make_ratio_rt (scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1750 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1751 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1752 if (XFLOAT_DATA (divisor) == 0.0) goto divide_by_zero;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1753 accum = make_float (XFLOAT_DATA (accum) / XFLOAT_DATA (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1754 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1755 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1756 case BIGFLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1757 if (bigfloat_sign (XBIGFLOAT_DATA (divisor)) == 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1758 goto divide_by_zero;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1759 bigfloat_set_prec (scratch_bigfloat,
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1760 max (XBIGFLOAT_GET_PREC (divisor),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1761 XBIGFLOAT_GET_PREC (accum)));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1762 bigfloat_div (scratch_bigfloat, XBIGFLOAT_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1763 XBIGFLOAT_DATA (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1764 accum = make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1765 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1766 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1767 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1768 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1769 return Fcanonicalize_number (accum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1770
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1771 divide_by_zero:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1772 Fsignal (Qarith_error, Qnil);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1773 return Qnil; /* not (usually) reached */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1774 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1775 #endif /* HAVE_RATIO */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1776
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 DEFUN ("/", Fquo, 1, MANY, 0, /*
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1778 Return FIRST divided by all the remaining arguments.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 The arguments must be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 With one argument, reciprocates the argument.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1781
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1782 arguments: (FIRST &rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1786 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1787 REGISTER int i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1788 Lisp_Object accum, divisor;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1789
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1790 if (nargs == 1)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1791 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1792 i = 0;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1793 accum = make_int (1);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1794 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1795 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1796 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1797 i = 1;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1798 accum = args[0];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1799 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1800 for (; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1801 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1802 divisor = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1803 switch (promote_args (&accum, &divisor))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1804 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1805 case FIXNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1806 if (XREALINT (divisor) == 0) goto divide_by_zero;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1807 accum = make_integer (XREALINT (accum) / XREALINT (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1808 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1809 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1810 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1811 if (bignum_sign (XBIGNUM_DATA (divisor)) == 0) goto divide_by_zero;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1812 bignum_div (scratch_bignum, XBIGNUM_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1813 XBIGNUM_DATA (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1814 accum = make_bignum_bg (scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1815 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1816 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1817 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1818 case RATIO_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1819 if (ratio_sign (XRATIO_DATA (divisor)) == 0) goto divide_by_zero;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1820 ratio_div (scratch_ratio, XRATIO_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1821 XRATIO_DATA (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1822 accum = make_ratio_rt (scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1823 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1824 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1825 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1826 if (XFLOAT_DATA (divisor) == 0.0) goto divide_by_zero;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1827 accum = make_float (XFLOAT_DATA (accum) / XFLOAT_DATA (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1828 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1829 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1830 case BIGFLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1831 if (bigfloat_sign (XBIGFLOAT_DATA (divisor)) == 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1832 goto divide_by_zero;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1833 bigfloat_set_prec (scratch_bigfloat,
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1834 max (XBIGFLOAT_GET_PREC (divisor),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1835 XBIGFLOAT_GET_PREC (accum)));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1836 bigfloat_div (scratch_bigfloat, XBIGFLOAT_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1837 XBIGFLOAT_DATA (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1838 accum = make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1839 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1840 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1841 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1842 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1843 return Fcanonicalize_number (accum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1844 #else /* !WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 EMACS_INT iaccum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846 double daccum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850 if (nargs == 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 iaccum = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856 iaccum = iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859 daccum = iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 goto divide_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869 if (iod.c.ival == 0) goto divide_by_zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 iaccum /= iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 if (iod.c.dval == 0) goto divide_by_zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 daccum = (double) iaccum / iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 goto divide_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 return make_int (iaccum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 divide_floats:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883 for (; args < args_end; args++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 double dval = number_char_or_marker_to_double (*args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 if (dval == 0) goto divide_by_zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 daccum /= dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 return make_float (daccum);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1890 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 divide_by_zero:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893 Fsignal (Qarith_error, Qnil);
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 800
diff changeset
1894 return Qnil; /* not (usually) reached */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897 DEFUN ("max", Fmax, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 Return largest of all the arguments.
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1899 All arguments must be real numbers, characters or markers.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900 The value is always a number; markers and characters are converted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 to numbers.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1902
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1903 arguments: (FIRST &rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1904 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1907 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1908 REGISTER int i, maxindex = 0;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1909 Lisp_Object comp1, comp2;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1910
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1911 while (!(CHARP (args[0]) || MARKERP (args[0]) || REALP (args[0])))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1912 args[0] = wrong_type_argument (Qnumber_char_or_marker_p, args[0]);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1913 if (CHARP (args[0]))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1914 args[0] = make_int (XCHAR (args[0]));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1915 else if (MARKERP (args[0]))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1916 args[0] = make_int (marker_position (args[0]));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1917 for (i = 1; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1918 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1919 comp1 = args[maxindex];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1920 comp2 = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1921 switch (promote_args (&comp1, &comp2))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1922 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1923 case FIXNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1924 if (XREALINT (comp1) < XREALINT (comp2))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1925 maxindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1926 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1927 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1928 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1929 if (bignum_lt (XBIGNUM_DATA (comp1), XBIGNUM_DATA (comp2)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1930 maxindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1931 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1932 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1933 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1934 case RATIO_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1935 if (ratio_lt (XRATIO_DATA (comp1), XRATIO_DATA (comp2)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1936 maxindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1937 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1938 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1939 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1940 if (XFLOAT_DATA (comp1) < XFLOAT_DATA (comp2))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1941 maxindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1942 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1943 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1944 case BIGFLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1945 if (bigfloat_lt (XBIGFLOAT_DATA (comp1), XBIGFLOAT_DATA (comp2)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1946 maxindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1947 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1948 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1949 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1950 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1951 return args[maxindex];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1952 #else /* !WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953 EMACS_INT imax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 double dmax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1959 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 imax = iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 dmax = iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 goto max_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972 if (imax < iod.c.ival) imax = iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1974 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 dmax = (double) imax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 if (dmax < iod.c.dval) dmax = iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978 goto max_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 return make_int (imax);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984 max_floats:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987 double dval = number_char_or_marker_to_double (*args++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988 if (dmax < dval) dmax = dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 return make_float (dmax);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1991 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1993
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1994 DEFUN ("min", Fmin, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995 Return smallest of all the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1996 All arguments must be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1997 The value is always a number; markers and characters are converted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998 to numbers.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1999
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2000 arguments: (FIRST &rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2001 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2002 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2003 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2004 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2005 REGISTER int i, minindex = 0;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2006 Lisp_Object comp1, comp2;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2007
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2008 while (!(CHARP (args[0]) || MARKERP (args[0]) || REALP (args[0])))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2009 args[0] = wrong_type_argument (Qnumber_char_or_marker_p, args[0]);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2010 if (CHARP (args[0]))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2011 args[0] = make_int (XCHAR (args[0]));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2012 else if (MARKERP (args[0]))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2013 args[0] = make_int (marker_position (args[0]));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2014 for (i = 1; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2015 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2016 comp1 = args[minindex];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2017 comp2 = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2018 switch (promote_args (&comp1, &comp2))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2019 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2020 case FIXNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2021 if (XREALINT (comp1) > XREALINT (comp2))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2022 minindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2023 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2024 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2025 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2026 if (bignum_gt (XBIGNUM_DATA (comp1), XBIGNUM_DATA (comp2)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2027 minindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2028 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2029 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2030 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2031 case RATIO_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2032 if (ratio_gt (XRATIO_DATA (comp1), XRATIO_DATA (comp2)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2033 minindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2034 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2035 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2036 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2037 if (XFLOAT_DATA (comp1) > XFLOAT_DATA (comp2))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2038 minindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2039 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2040 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2041 case BIGFLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2042 if (bigfloat_gt (XBIGFLOAT_DATA (comp1), XBIGFLOAT_DATA (comp2)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2043 minindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2044 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2045 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2046 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2047 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2048 return args[minindex];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2049 #else /* !WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050 EMACS_INT imin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051 double dmin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2052 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2053 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2055 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2056 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057 imin = iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2058 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060 dmin = iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2061 goto min_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2062 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2063
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2064 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2065 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2066 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2067 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2068 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2069 if (imin > iod.c.ival) imin = iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2070 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2071 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2072 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2073 dmin = (double) imin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2074 if (dmin > iod.c.dval) dmin = iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2075 goto min_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2076 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2077 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2078
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2079 return make_int (imin);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2080
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2081 min_floats:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2082 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2083 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2084 double dval = number_char_or_marker_to_double (*args++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2085 if (dmin > dval) dmin = dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2086 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2087 return make_float (dmin);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2088 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2089 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2090
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2091 DEFUN ("logand", Flogand, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2092 Return bitwise-and of all the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2093 Arguments may be integers, or markers or characters converted to integers.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2094
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2095 arguments: (&rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2096 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2097 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2098 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2099 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2100 REGISTER int i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2101 Lisp_Object result, other;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2102
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2103 if (nargs == 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2104 return make_int (~0);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2105
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2106 while (!(CHARP (args[0]) || MARKERP (args[0]) || INTEGERP (args[0])))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2107 args[0] = wrong_type_argument (Qnumber_char_or_marker_p, args[0]);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2108
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2109 result = args[0];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2110 if (CHARP (result))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2111 result = make_int (XCHAR (result));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2112 else if (MARKERP (result))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2113 result = make_int (marker_position (result));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2114 for (i = 1; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2115 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2116 while (!(CHARP (args[i]) || MARKERP (args[i]) || INTEGERP (args[i])))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2117 args[i] = wrong_type_argument (Qnumber_char_or_marker_p, args[i]);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2118 other = args[i];
1995
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1994
diff changeset
2119 switch (promote_args (&result, &other))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2120 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2121 case FIXNUM_T:
1995
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1994
diff changeset
2122 result = make_int (XREALINT (result) & XREALINT (other));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2123 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2124 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2125 bignum_and (scratch_bignum, XBIGNUM_DATA (result),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2126 XBIGNUM_DATA (other));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2127 result = make_bignum_bg (scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2128 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2129 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2130 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2131 return Fcanonicalize_number (result);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2132 #else /* !HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2133 EMACS_INT bits = ~0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2134 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2135
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2136 while (args < args_end)
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
2137 bits &= fixnum_char_or_marker_to_int (*args++);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2139 return make_int (bits);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2140 #endif /* HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2141 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2142
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2143 DEFUN ("logior", Flogior, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2144 Return bitwise-or of all the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2145 Arguments may be integers, or markers or characters converted to integers.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2146
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2147 arguments: (&rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2149 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2151 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2152 REGISTER int i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2153 Lisp_Object result, other;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2154
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2155 if (nargs == 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2156 return make_int (0);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2157
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2158 while (!(CHARP (args[0]) || MARKERP (args[0]) || INTEGERP (args[0])))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2159 args[0] = wrong_type_argument (Qnumber_char_or_marker_p, args[0]);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2160
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2161 result = args[0];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2162 if (CHARP (result))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2163 result = make_int (XCHAR (result));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2164 else if (MARKERP (result))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2165 result = make_int (marker_position (result));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2166 for (i = 1; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2167 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2168 while (!(CHARP (args[i]) || MARKERP (args[i]) || INTEGERP (args[i])))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2169 args[i] = wrong_type_argument (Qnumber_char_or_marker_p, args[i]);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2170 other = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2171 switch (promote_args (&result, &other))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2172 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2173 case FIXNUM_T:
1992
4529ff71e646 [xemacs-hg @ 2004-04-07 02:20:12 by james]
james
parents: 1983
diff changeset
2174 result = make_int (XREALINT (result) | XREALINT (other));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2175 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2176 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2177 bignum_ior (scratch_bignum, XBIGNUM_DATA (result),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2178 XBIGNUM_DATA (other));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2179 result = make_bignum_bg (scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2180 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2181 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2182 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2183 return Fcanonicalize_number (result);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2184 #else /* !HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2185 EMACS_INT bits = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 while (args < args_end)
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
2189 bits |= fixnum_char_or_marker_to_int (*args++);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2191 return make_int (bits);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2192 #endif /* HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2193 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2194
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2195 DEFUN ("logxor", Flogxor, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2196 Return bitwise-exclusive-or of all the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197 Arguments may be integers, or markers or characters converted to integers.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2198
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2199 arguments: (&rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2200 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2201 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2202 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2203 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2204 REGISTER int i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2205 Lisp_Object result, other;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2206
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2207 if (nargs == 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2208 return make_int (0);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2209
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2210 while (!(CHARP (args[0]) || MARKERP (args[0]) || INTEGERP (args[0])))
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
2211 args[0] = wrong_type_argument (Qinteger_char_or_marker_p, args[0]);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2212
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2213 result = args[0];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2214 if (CHARP (result))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2215 result = make_int (XCHAR (result));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2216 else if (MARKERP (result))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2217 result = make_int (marker_position (result));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2218 for (i = 1; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2219 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2220 while (!(CHARP (args[i]) || MARKERP (args[i]) || INTEGERP (args[i])))
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
2221 args[i] = wrong_type_argument (Qinteger_char_or_marker_p, args[i]);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2222 other = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2223 if (promote_args (&result, &other) == FIXNUM_T)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2224 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2225 result = make_int (XREALINT (result) ^ XREALINT (other));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2226 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2227 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2228 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2229 bignum_xor (scratch_bignum, XBIGNUM_DATA (result),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2230 XBIGNUM_DATA (other));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2231 result = make_bignum_bg (scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2232 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2233 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2234 return Fcanonicalize_number (result);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2235 #else /* !HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2236 EMACS_INT bits = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2237 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2239 while (args < args_end)
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
2240 bits ^= fixnum_char_or_marker_to_int (*args++);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2242 return make_int (bits);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2243 #endif /* !HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2244 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2246 DEFUN ("lognot", Flognot, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2247 Return the bitwise complement of NUMBER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2248 NUMBER may be an integer, marker or character converted to integer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2249 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2250 (number))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2251 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
2252 while (!(CHARP (number) || MARKERP (number) || INTEGERP (number)))
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
2253 number = wrong_type_argument (Qinteger_char_or_marker_p, number);
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
2254
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2255 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2256 if (BIGNUMP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2257 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2258 bignum_not (scratch_bignum, XBIGNUM_DATA (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2259 return make_bignum_bg (scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2260 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2261 #endif /* HAVE_BIGNUM */
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
2262
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
2263 return make_int (~ fixnum_char_or_marker_to_int (number));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2264 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2266 DEFUN ("%", Frem, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2267 Return remainder of first arg divided by second.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2268 Both must be integers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2269 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2270 (number1, number2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2271 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2272 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2273 while (!(CHARP (number1) || MARKERP (number1) || INTEGERP (number1)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2274 number1 = wrong_type_argument (Qnumber_char_or_marker_p, number1);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2275 while (!(CHARP (number2) || MARKERP (number2) || INTEGERP (number2)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2276 number2 = wrong_type_argument (Qnumber_char_or_marker_p, number2);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2277
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2278 if (promote_args (&number1, &number2) == FIXNUM_T)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2279 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2280 if (XREALINT (number2) == 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2281 Fsignal (Qarith_error, Qnil);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2282 return make_int (XREALINT (number1) % XREALINT (number2));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2283 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2284 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2285 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2286 if (bignum_sign (XBIGNUM_DATA (number2)) == 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2287 Fsignal (Qarith_error, Qnil);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2288 bignum_mod (scratch_bignum, XBIGNUM_DATA (number1),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2289 XBIGNUM_DATA (number2));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2290 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2291 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2292 #else /* !HAVE_BIGNUM */
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
2293 EMACS_INT ival1 = fixnum_char_or_marker_to_int (number1);
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
2294 EMACS_INT ival2 = fixnum_char_or_marker_to_int (number2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 if (ival2 == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2297 Fsignal (Qarith_error, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2298
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2299 return make_int (ival1 % ival2);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2300 #endif /* HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2301 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2302
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2303 /* Note, ANSI *requires* the presence of the fmod() library routine.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2304 If your system doesn't have it, complain to your vendor, because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2305 that is a bug. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2307 #ifndef HAVE_FMOD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2308 double
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2309 fmod (double f1, double f2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2310 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2311 if (f2 < 0.0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2312 f2 = -f2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2313 return f1 - f2 * floor (f1/f2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2314 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2315 #endif /* ! HAVE_FMOD */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2316
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2318 DEFUN ("mod", Fmod, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2319 Return X modulo Y.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2320 The result falls between zero (inclusive) and Y (exclusive).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2321 Both X and Y must be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2322 If either argument is a float, a float will be returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2323 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324 (x, y))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2325 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2326 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2327 while (!(CHARP (x) || MARKERP (x) || REALP (x)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2328 x = wrong_type_argument (Qnumber_char_or_marker_p, x);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2329 while (!(CHARP (y) || MARKERP (y) || REALP (y)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2330 y = wrong_type_argument (Qnumber_char_or_marker_p, y);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2331 switch (promote_args (&x, &y))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2332 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2333 case FIXNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2334 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2335 EMACS_INT ival;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2336 if (XREALINT (y) == 0) goto divide_by_zero;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2337 ival = XREALINT (x) % XREALINT (y);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2338 /* If the "remainder" comes out with the wrong sign, fix it. */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2339 if (XREALINT (y) < 0 ? ival > 0 : ival < 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2340 ival += XREALINT (y);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2341 return make_int (ival);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2342 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2343 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2344 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2345 if (bignum_sign (XBIGNUM_DATA (y)) == 0) goto divide_by_zero;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2346 bignum_mod (scratch_bignum, XBIGNUM_DATA (x), XBIGNUM_DATA (y));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2347 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2348 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2349 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2350 case RATIO_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2351 if (ratio_sign (XRATIO_DATA (y)) == 0) goto divide_by_zero;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2352 ratio_div (scratch_ratio, XRATIO_DATA (x), XRATIO_DATA (y));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2353 bignum_div (scratch_bignum, ratio_numerator (scratch_ratio),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2354 ratio_denominator (scratch_ratio));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2355 ratio_set_bignum (scratch_ratio, scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2356 ratio_mul (scratch_ratio, scratch_ratio, XRATIO_DATA (y));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2357 ratio_sub (scratch_ratio, XRATIO_DATA (x), scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2358 return Fcanonicalize_number (make_ratio_rt (scratch_ratio));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2359 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2360 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2361 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2362 double dval;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2363 if (XFLOAT_DATA (y) == 0.0) goto divide_by_zero;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2364 dval = fmod (XFLOAT_DATA (x), XFLOAT_DATA (y));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2365 /* If the "remainder" comes out with the wrong sign, fix it. */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2366 if (XFLOAT_DATA (y) < 0 ? dval > 0 : dval < 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2367 dval += XFLOAT_DATA (y);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2368 return make_float (dval);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2369 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2370 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2371 case BIGFLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2372 bigfloat_set_prec (scratch_bigfloat,
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2373 max (XBIGFLOAT_GET_PREC (x), XBIGFLOAT_GET_PREC (y)));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2374 bigfloat_div (scratch_bigfloat, XBIGFLOAT_DATA (x), XBIGFLOAT_DATA (y));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2375 bigfloat_trunc (scratch_bigfloat, scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2376 bigfloat_mul (scratch_bigfloat, scratch_bigfloat, XBIGFLOAT_DATA (y));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2377 bigfloat_sub (scratch_bigfloat, XBIGFLOAT_DATA (x), scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2378 return make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2379 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2380 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2381 #else /* !WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2382 int_or_double iod1, iod2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2383 number_char_or_marker_to_int_or_double (x, &iod1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2384 number_char_or_marker_to_int_or_double (y, &iod2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2385
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2386 if (!iod1.int_p || !iod2.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2387 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2388 double dval1 = iod1.int_p ? (double) iod1.c.ival : iod1.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2389 double dval2 = iod2.int_p ? (double) iod2.c.ival : iod2.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2390 if (dval2 == 0) goto divide_by_zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2391 dval1 = fmod (dval1, dval2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2392
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2393 /* If the "remainder" comes out with the wrong sign, fix it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2394 if (dval2 < 0 ? dval1 > 0 : dval1 < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2395 dval1 += dval2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2396
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2397 return make_float (dval1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2398 }
1104
8b464283e891 [xemacs-hg @ 2002-11-12 18:58:13 by james]
james
parents: 993
diff changeset
2399
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2400 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2401 EMACS_INT ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2402 if (iod2.c.ival == 0) goto divide_by_zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2403
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2404 ival = iod1.c.ival % iod2.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2405
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2406 /* If the "remainder" comes out with the wrong sign, fix it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2407 if (iod2.c.ival < 0 ? ival > 0 : ival < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2408 ival += iod2.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2410 return make_int (ival);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2411 }
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2412 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2414 divide_by_zero:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2415 Fsignal (Qarith_error, Qnil);
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 800
diff changeset
2416 return Qnil; /* not (usually) reached */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2417 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2419 DEFUN ("ash", Fash, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2420 Return VALUE with its bits shifted left by COUNT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2421 If COUNT is negative, shifting is actually to the right.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2422 In this case, the sign bit is duplicated.
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2423 This function cannot be applied to bignums, as there is no leftmost sign bit
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2424 to be duplicated. Use `lsh' instead.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2425 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2426 (value, count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2427 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2428 CHECK_INT_COERCE_CHAR (value);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2429 CONCHECK_INT (count);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2430
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2431 return make_int (XINT (count) > 0 ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2432 XINT (value) << XINT (count) :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2433 XINT (value) >> -XINT (count));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2434 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2435
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2436 DEFUN ("lsh", Flsh, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2437 Return VALUE with its bits shifted left by COUNT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2438 If COUNT is negative, shifting is actually to the right.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2439 In this case, zeros are shifted in on the left.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2440 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2441 (value, count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2442 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2443 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2444 while (!(CHARP (value) || MARKERP (value) || INTEGERP (value)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2445 wrong_type_argument (Qnumber_char_or_marker_p, value);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2446 CONCHECK_INTEGER (count);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2447
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2448 if (promote_args (&value, &count) == FIXNUM_T)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2449 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2450 if (XREALINT (count) <= 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2451 return make_int (XREALINT (value) >> -XREALINT (count));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2452 /* Use bignums to avoid overflow */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2453 bignum_set_long (scratch_bignum2, XREALINT (value));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2454 bignum_lshift (scratch_bignum, scratch_bignum2, XREALINT (count));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2455 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2456 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2457 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2458 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2459 if (bignum_sign (XBIGNUM_DATA (count)) <= 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2460 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2461 bignum_neg (scratch_bignum, XBIGNUM_DATA (count));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2462 if (!bignum_fits_ulong_p (scratch_bignum))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2463 args_out_of_range (Qnumber_char_or_marker_p, count);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2464 bignum_rshift (scratch_bignum2, XBIGNUM_DATA (value),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2465 bignum_to_ulong (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2466 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2467 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2468 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2469 if (!bignum_fits_ulong_p (XBIGNUM_DATA (count)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2470 args_out_of_range (Qnumber_char_or_marker_p, count);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2471 bignum_lshift (scratch_bignum2, XBIGNUM_DATA (value),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2472 bignum_to_ulong (XBIGNUM_DATA (count)));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2473 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2474 return Fcanonicalize_number (make_bignum_bg (scratch_bignum2));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2475 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2476 #else /* !HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2477 CHECK_INT_COERCE_CHAR (value);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2478 CONCHECK_INT (count);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2479
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2480 return make_int (XINT (count) > 0 ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2481 XUINT (value) << XINT (count) :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2482 XUINT (value) >> -XINT (count));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2483 #endif /* HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2484 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2485
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2486 DEFUN ("1+", Fadd1, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2487 Return NUMBER plus one. NUMBER may be a number, character or marker.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2488 Markers and characters are converted to integers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2489 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2490 (number))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2491 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2492 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2493
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2494 if (INTP (number)) return make_integer (XINT (number) + 1);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2495 if (CHARP (number)) return make_integer (XCHAR (number) + 1);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2496 if (MARKERP (number)) return make_integer (marker_position (number) + 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2497 if (FLOATP (number)) return make_float (XFLOAT_DATA (number) + 1.0);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2498 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2499 if (BIGNUMP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2500 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2501 bignum_set_long (scratch_bignum, 1L);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2502 bignum_add (scratch_bignum2, XBIGNUM_DATA (number), scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2503 return Fcanonicalize_number (make_bignum_bg (scratch_bignum2));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2504 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2505 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2506 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2507 if (RATIOP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2508 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2509 ratio_set_long (scratch_ratio, 1L);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2510 ratio_add (scratch_ratio, XRATIO_DATA (number), scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2511 /* No need to canonicalize after adding 1 */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2512 return make_ratio_rt (scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2513 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2514 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2515 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2516 if (BIGFLOATP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2517 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2518 bigfloat_set_prec (scratch_bigfloat, XBIGFLOAT_GET_PREC (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2519 bigfloat_set_long (scratch_bigfloat, 1L);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2520 bigfloat_add (scratch_bigfloat, XBIGFLOAT_DATA (number),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2521 scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2522 return make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2523 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2524 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2525
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2526 number = wrong_type_argument (Qnumber_char_or_marker_p, number);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2527 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2528 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2529
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2530 DEFUN ("1-", Fsub1, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2531 Return NUMBER minus one. NUMBER may be a number, character or marker.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2532 Markers and characters are converted to integers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2533 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2534 (number))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2535 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2536 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2537
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2538 if (INTP (number)) return make_integer (XINT (number) - 1);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2539 if (CHARP (number)) return make_integer (XCHAR (number) - 1);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2540 if (MARKERP (number)) return make_integer (marker_position (number) - 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2541 if (FLOATP (number)) return make_float (XFLOAT_DATA (number) - 1.0);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2542 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2543 if (BIGNUMP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2544 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2545 bignum_set_long (scratch_bignum, 1L);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2546 bignum_sub (scratch_bignum2, XBIGNUM_DATA (number), scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2547 return Fcanonicalize_number (make_bignum_bg (scratch_bignum2));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2548 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2549 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2550 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2551 if (RATIOP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2552 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2553 ratio_set_long (scratch_ratio, 1L);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2554 ratio_sub (scratch_ratio, XRATIO_DATA (number), scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2555 /* No need to canonicalize after subtracting 1 */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2556 return make_ratio_rt (scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2557 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2558 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2559 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2560 if (BIGFLOATP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2561 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2562 bigfloat_set_prec (scratch_bigfloat, XBIGFLOAT_GET_PREC (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2563 bigfloat_set_long (scratch_bigfloat, 1L);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2564 bigfloat_sub (scratch_bigfloat, XBIGFLOAT_DATA (number),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2565 scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2566 return make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2567 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2568 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2569
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2570 number = wrong_type_argument (Qnumber_char_or_marker_p, number);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2571 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2572 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2573
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2574
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2575 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2576 /* weak lists */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2577 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2578
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2579 /* A weak list is like a normal list except that elements automatically
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2580 disappear when no longer in use, i.e. when no longer GC-protected.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2581 The basic idea is that we don't mark the elements during GC, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2582 wait for them to be marked elsewhere. If they're not marked, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2583 remove them. This is analogous to weak hash tables; see the explanation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2584 there for more info. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2585
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2586 static Lisp_Object Vall_weak_lists; /* Gemarke es nicht!!! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2587
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2588 static Lisp_Object encode_weak_list_type (enum weak_list_type type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2589
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2590 static Lisp_Object
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2054
diff changeset
2591 mark_weak_list (Lisp_Object UNUSED (obj))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2592 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2593 return Qnil; /* nichts ist gemarkt */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2594 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2595
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2596 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2054
diff changeset
2597 print_weak_list (Lisp_Object obj, Lisp_Object printcharfun,
5325
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
2598 int escapeflag)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2599 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2600 if (print_readably)
5325
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
2601 {
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
2602 printing_unreadable_lisp_object (obj, 0);
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
2603 }
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
2604
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
2605 write_ascstring (printcharfun, "#<weak-list :type ");
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
2606 print_internal (encode_weak_list_type (XWEAK_LIST (obj)->type),
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
2607 printcharfun, escapeflag);
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
2608 write_ascstring (printcharfun, " :list ");
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
2609 print_internal (XWEAK_LIST (obj)->list, printcharfun, escapeflag);
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
2610 write_fmt_string (printcharfun, " 0x%x>", LISP_OBJECT_UID (obj));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2611 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2612
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2613 static int
4906
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4885
diff changeset
2614 weak_list_equal (Lisp_Object obj1, Lisp_Object obj2, int depth, int foldcase)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2615 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2616 struct weak_list *w1 = XWEAK_LIST (obj1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2617 struct weak_list *w2 = XWEAK_LIST (obj2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2618
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2619 return ((w1->type == w2->type) &&
4906
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4885
diff changeset
2620 internal_equal_0 (w1->list, w2->list, depth + 1, foldcase));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2621 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2622
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
2623 static Hashcode
5191
71ee43b8a74d Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
2624 weak_list_hash (Lisp_Object obj, int depth, Boolint equalp)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2625 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2626 struct weak_list *w = XWEAK_LIST (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2627
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
2628 return HASH2 ((Hashcode) w->type,
5191
71ee43b8a74d Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
2629 internal_hash (w->list, depth + 1, equalp));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2630 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2631
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2632 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2633 make_weak_list (enum weak_list_type type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2634 {
5127
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5125
diff changeset
2635 Lisp_Object result = ALLOC_NORMAL_LISP_OBJECT (weak_list);
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
2636 struct weak_list *wl = XWEAK_LIST (result);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2637
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2638 wl->list = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2639 wl->type = type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2640 wl->next_weak = Vall_weak_lists;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641 Vall_weak_lists = result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2642 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2644
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
2645 static const struct memory_description weak_list_description[] = {
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
2646 { XD_LISP_OBJECT, offsetof (struct weak_list, list),
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2500
diff changeset
2647 0, { 0 }, XD_FLAG_NO_KKCC },
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
2648 { XD_LO_LINK, offsetof (struct weak_list, next_weak),
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2500
diff changeset
2649 0, { 0 }, XD_FLAG_NO_KKCC },
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2650 { XD_END }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2651 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2652
5118
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4759
diff changeset
2653 DEFINE_DUMPABLE_LISP_OBJECT ("weak-list", weak_list,
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4759
diff changeset
2654 mark_weak_list, print_weak_list,
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4759
diff changeset
2655 0, weak_list_equal, weak_list_hash,
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4759
diff changeset
2656 weak_list_description,
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4759
diff changeset
2657 struct weak_list);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2658 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2659 -- we do not mark the list elements (either the elements themselves
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2660 or the cons cells that hold them) in the normal marking phase.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2661 -- at the end of marking, we go through all weak lists that are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2662 marked, and mark the cons cells that hold all marked
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2663 objects, and possibly parts of the objects themselves.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2664 (See alloc.c, "after-mark".)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2665 -- after that, we prune away all the cons cells that are not marked.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2666
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2667 WARNING WARNING WARNING WARNING WARNING:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2669 The code in the following two functions is *unbelievably* tricky.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2670 Don't mess with it. You'll be sorry.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2671
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2672 Linked lists just majorly suck, d'ya know?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2673 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2674
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2675 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2676 finish_marking_weak_lists (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2677 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2678 Lisp_Object rest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2679 int did_mark = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2680
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2681 for (rest = Vall_weak_lists;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2682 !NILP (rest);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2683 rest = XWEAK_LIST (rest)->next_weak)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2684 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2685 Lisp_Object rest2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2686 enum weak_list_type type = XWEAK_LIST (rest)->type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2687
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2688 if (! marked_p (rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2689 /* The weak list is probably garbage. Ignore it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2690 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2691
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2692 for (rest2 = XWEAK_LIST (rest)->list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2693 /* We need to be trickier since we're inside of GC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2694 use CONSP instead of !NILP in case of user-visible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2695 imperfect lists */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2696 CONSP (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2697 rest2 = XCDR (rest2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2698 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2699 Lisp_Object elem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2700 /* If the element is "marked" (meaning depends on the type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2701 of weak list), we need to mark the cons containing the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2702 element, and maybe the element itself (if only some part
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2703 was already marked). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2704 int need_to_mark_cons = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2705 int need_to_mark_elem = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2706
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2707 /* If a cons is already marked, then its car is already marked
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2708 (either because of an external pointer or because of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2709 a previous call to this function), and likewise for all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2710 the rest of the elements in the list, so we can stop now. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2711 if (marked_p (rest2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2712 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2713
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2714 elem = XCAR (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2715
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2716 switch (type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2717 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2718 case WEAK_LIST_SIMPLE:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2719 if (marked_p (elem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2720 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2721 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2722
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2723 case WEAK_LIST_ASSOC:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2724 if (!CONSP (elem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2725 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2726 /* just leave bogus elements there */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2727 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2728 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2729 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2730 else if (marked_p (XCAR (elem)) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2731 marked_p (XCDR (elem)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2732 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2733 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2734 /* We still need to mark elem, because it's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2735 probably not marked. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2736 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2737 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2738 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2740 case WEAK_LIST_KEY_ASSOC:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2741 if (!CONSP (elem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2742 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2743 /* just leave bogus elements there */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2744 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2745 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2746 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2747 else if (marked_p (XCAR (elem)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2748 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2749 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2750 /* We still need to mark elem and XCDR (elem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2751 marking elem does both */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2752 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2753 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2754 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2755
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2756 case WEAK_LIST_VALUE_ASSOC:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2757 if (!CONSP (elem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2758 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2759 /* just leave bogus elements there */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2760 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2761 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2762 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2763 else if (marked_p (XCDR (elem)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2764 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2765 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2766 /* We still need to mark elem and XCAR (elem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2767 marking elem does both */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2768 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2769 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2770 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2771
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2772 case WEAK_LIST_FULL_ASSOC:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2773 if (!CONSP (elem))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2774 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2775 /* just leave bogus elements there */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2776 need_to_mark_cons = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2777 need_to_mark_elem = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2778 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2779 else if (marked_p (XCAR (elem)) ||
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2780 marked_p (XCDR (elem)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2781 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2782 need_to_mark_cons = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2783 /* We still need to mark elem and XCAR (elem);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2784 marking elem does both */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2785 need_to_mark_elem = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2786 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2787 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2788
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2789 default:
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2286
diff changeset
2790 ABORT ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2791 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2792
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2793 if (need_to_mark_elem && ! marked_p (elem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2794 {
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
2795 #ifdef USE_KKCC
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5142
diff changeset
2796 kkcc_gc_stack_push_lisp_object_0 (elem);
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
2797 #else /* NOT USE_KKCC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2798 mark_object (elem);
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
2799 #endif /* NOT USE_KKCC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2800 did_mark = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2801 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2802
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2803 /* We also need to mark the cons that holds the elem or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2804 assoc-pair. We do *not* want to call (mark_object) here
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2805 because that will mark the entire list; we just want to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2806 mark the cons itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2807 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2808 if (need_to_mark_cons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2809 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2810 Lisp_Cons *c = XCONS (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2811 if (!CONS_MARKED_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2812 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2813 MARK_CONS (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2814 did_mark = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2815 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2816 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2817 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2818
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2819 /* In case of imperfect list, need to mark the final cons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2820 because we're not removing it */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2821 if (!NILP (rest2) && ! marked_p (rest2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2822 {
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
2823 #ifdef USE_KKCC
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5142
diff changeset
2824 kkcc_gc_stack_push_lisp_object_0 (rest2);
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
2825 #else /* NOT USE_KKCC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2826 mark_object (rest2);
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
2827 #endif /* NOT USE_KKCC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2828 did_mark = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2829 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2830 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2831
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2832 return did_mark;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2833 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2834
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2835 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2836 prune_weak_lists (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2837 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2838 Lisp_Object rest, prev = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2839
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2840 for (rest = Vall_weak_lists;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2841 !NILP (rest);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2842 rest = XWEAK_LIST (rest)->next_weak)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2843 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2844 if (! (marked_p (rest)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2845 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2846 /* This weak list itself is garbage. Remove it from the list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2847 if (NILP (prev))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2848 Vall_weak_lists = XWEAK_LIST (rest)->next_weak;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2849 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2850 XWEAK_LIST (prev)->next_weak =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2851 XWEAK_LIST (rest)->next_weak;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2852 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2853 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2854 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2855 Lisp_Object rest2, prev2 = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2856 Lisp_Object tortoise;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2857 int go_tortoise = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2858
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2859 for (rest2 = XWEAK_LIST (rest)->list, tortoise = rest2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2860 /* We need to be trickier since we're inside of GC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2861 use CONSP instead of !NILP in case of user-visible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2862 imperfect lists */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2863 CONSP (rest2);)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2864 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2865 /* It suffices to check the cons for marking,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2866 regardless of the type of weak list:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2867
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2868 -- if the cons is pointed to somewhere else,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2869 then it should stay around and will be marked.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2870 -- otherwise, if it should stay around, it will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2871 have been marked in finish_marking_weak_lists().
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2872 -- otherwise, it's not marked and should disappear.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2873 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2874 if (! marked_p (rest2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2875 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2876 /* bye bye :-( */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2877 if (NILP (prev2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2878 XWEAK_LIST (rest)->list = XCDR (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2879 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2880 XCDR (prev2) = XCDR (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2881 rest2 = XCDR (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2882 /* Ouch. Circularity checking is even trickier
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2883 than I thought. When we cut out a link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2884 like this, we can't advance the turtle or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2885 it'll catch up to us. Imagine that we're
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2886 standing on floor tiles and moving forward --
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2887 what we just did here is as if the floor
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2888 tile under us just disappeared and all the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2889 ones ahead of us slid one tile towards us.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2890 In other words, we didn't move at all;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2891 if the tortoise was one step behind us
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2892 previously, it still is, and therefore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2893 it must not move. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2894 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2895 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2896 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2897 prev2 = rest2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2898
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2899 /* Implementing circularity checking is trickier here
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2900 than in other places because we have to guarantee
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2901 that we've processed all elements before exiting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2902 due to a circularity. (In most places, an error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2903 is issued upon encountering a circularity, so it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2904 doesn't really matter if all elements are processed.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2905 The idea is that we process along with the hare
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2906 rather than the tortoise. If at any point in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2907 our forward process we encounter the tortoise,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2908 we must have already visited the spot, so we exit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2909 (If we process with the tortoise, we can fail to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2910 process cases where a cons points to itself, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2911 where cons A points to cons B, which points to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2912 cons A.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2913
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 rest2 = XCDR (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2915 if (go_tortoise)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2916 tortoise = XCDR (tortoise);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2917 go_tortoise = !go_tortoise;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2918 if (EQ (rest2, tortoise))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2919 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2920 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2921 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2922
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2923 prev = rest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2924 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2925 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2926 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2927
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2928 static enum weak_list_type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2929 decode_weak_list_type (Lisp_Object symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2930 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2931 CHECK_SYMBOL (symbol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2932 if (EQ (symbol, Qsimple)) return WEAK_LIST_SIMPLE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2933 if (EQ (symbol, Qassoc)) return WEAK_LIST_ASSOC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2934 if (EQ (symbol, Qold_assoc)) return WEAK_LIST_ASSOC; /* EBOLA ALERT! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2935 if (EQ (symbol, Qkey_assoc)) return WEAK_LIST_KEY_ASSOC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2936 if (EQ (symbol, Qvalue_assoc)) return WEAK_LIST_VALUE_ASSOC;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2937 if (EQ (symbol, Qfull_assoc)) return WEAK_LIST_FULL_ASSOC;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2938
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
2939 invalid_constant ("Invalid weak list type", symbol);
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
2940 RETURN_NOT_REACHED (WEAK_LIST_SIMPLE);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2941 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2942
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2943 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2944 encode_weak_list_type (enum weak_list_type type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2945 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2946 switch (type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2947 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2948 case WEAK_LIST_SIMPLE: return Qsimple;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2949 case WEAK_LIST_ASSOC: return Qassoc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2950 case WEAK_LIST_KEY_ASSOC: return Qkey_assoc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2951 case WEAK_LIST_VALUE_ASSOC: return Qvalue_assoc;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2952 case WEAK_LIST_FULL_ASSOC: return Qfull_assoc;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2953 default:
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2286
diff changeset
2954 ABORT ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2955 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2956
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 800
diff changeset
2957 return Qnil; /* not (usually) reached */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2958 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2959
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2960 DEFUN ("weak-list-p", Fweak_list_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2961 Return non-nil if OBJECT is a weak list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2962 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2963 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2964 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2965 return WEAK_LISTP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2966 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2967
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2968 DEFUN ("make-weak-list", Fmake_weak_list, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2969 Return a new weak list object of type TYPE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2970 A weak list object is an object that contains a list. This list behaves
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2971 like any other list except that its elements do not count towards
456
e7ef97881643 Import from CVS: tag r21-2-43
cvs
parents: 452
diff changeset
2972 garbage collection -- if the only pointer to an object is inside a weak
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2973 list (other than pointers in similar objects such as weak hash tables),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2974 the object is garbage collected and automatically removed from the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2975 This is used internally, for example, to manage the list holding the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2976 children of an extent -- an extent that is unused but has a parent will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977 still be reclaimed, and will automatically be removed from its parent's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2978 list of children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2980 Optional argument TYPE specifies the type of the weak list, and defaults
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2981 to `simple'. Recognized types are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2983 `simple' Objects in the list disappear if not pointed to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2984 `assoc' Objects in the list disappear if they are conses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2985 and either the car or the cdr of the cons is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2986 pointed to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2987 `key-assoc' Objects in the list disappear if they are conses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2988 and the car is not pointed to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989 `value-assoc' Objects in the list disappear if they are conses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2990 and the cdr is not pointed to.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2991 `full-assoc' Objects in the list disappear if they are conses
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2992 and neither the car nor the cdr is pointed to.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2993 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2994 (type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2995 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2996 if (NILP (type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2997 type = Qsimple;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2999 return make_weak_list (decode_weak_list_type (type));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3000 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3001
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002 DEFUN ("weak-list-type", Fweak_list_type, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3003 Return the type of the given weak-list object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3004 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3005 (weak))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3006 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3007 CHECK_WEAK_LIST (weak);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3008 return encode_weak_list_type (XWEAK_LIST (weak)->type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3009 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3010
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3011 DEFUN ("weak-list-list", Fweak_list_list, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012 Return the list contained in a weak-list object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3013 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3014 (weak))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3015 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3016 CHECK_WEAK_LIST (weak);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3017 return XWEAK_LIST_LIST (weak);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3018 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3019
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3020 DEFUN ("set-weak-list-list", Fset_weak_list_list, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3021 Change the list contained in a weak-list object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3022 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3023 (weak, new_list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3024 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3025 CHECK_WEAK_LIST (weak);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3026 XWEAK_LIST_LIST (weak) = new_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3027 return new_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3028 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3029
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3030
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3031 /************************************************************************/
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3032 /* weak boxes */
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3033 /************************************************************************/
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3034
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3035 static Lisp_Object Vall_weak_boxes; /* Gemarke es niemals ever!!! */
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3036
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3037 void
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3038 prune_weak_boxes (void)
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3039 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3040 Lisp_Object rest, prev = Qnil;
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3041 int removep = 0;
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3042
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3043 for (rest = Vall_weak_boxes;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3044 !NILP(rest);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3045 rest = XWEAK_BOX (rest)->next_weak_box)
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3046 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3047 if (! (marked_p (rest)))
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3048 /* This weak box itself is garbage. */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3049 removep = 1;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3050
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3051 if (! marked_p (XWEAK_BOX (rest)->value))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3052 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3053 XSET_WEAK_BOX (rest, Qnil);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3054 removep = 1;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3055 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3056
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3057 if (removep)
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3058 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3059 /* Remove weak box from list. */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3060 if (NILP (prev))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3061 Vall_weak_boxes = XWEAK_BOX (rest)->next_weak_box;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3062 else
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3063 XWEAK_BOX (prev)->next_weak_box = XWEAK_BOX (rest)->next_weak_box;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3064 removep = 0;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3065 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3066 else
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3067 prev = rest;
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3068 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3069 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3070
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3071 static Lisp_Object
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2054
diff changeset
3072 mark_weak_box (Lisp_Object UNUSED (obj))
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3073 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3074 return Qnil;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3075 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3076
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3077 static void
5325
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3078 print_weak_box (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3079 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3080 if (print_readably)
5325
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3081 {
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3082 printing_unreadable_lisp_object (obj, 0);
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3083 }
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3084
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3085 write_ascstring (printcharfun, "#<weak-box ");
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3086 print_internal (XWEAK_BOX (obj)->value, printcharfun, escapeflag);
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3087 write_fmt_string (printcharfun, " 0x%x>", LISP_OBJECT_UID (obj));
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3088 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3089
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3090 static int
4906
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4885
diff changeset
3091 weak_box_equal (Lisp_Object obj1, Lisp_Object obj2, int depth, int foldcase)
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3092 {
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3093 struct weak_box *wb1 = XWEAK_BOX (obj1);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3094 struct weak_box *wb2 = XWEAK_BOX (obj2);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3095
4906
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4885
diff changeset
3096 return (internal_equal_0 (wb1->value, wb2->value, depth + 1, foldcase));
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3097 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3098
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3099 static Hashcode
5191
71ee43b8a74d Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
3100 weak_box_hash (Lisp_Object obj, int depth, Boolint equalp)
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3101 {
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3102 struct weak_box *wb = XWEAK_BOX (obj);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3103
5191
71ee43b8a74d Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
3104 return internal_hash (wb->value, depth + 1, equalp);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3105 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3106
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3107 Lisp_Object
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3108 make_weak_box (Lisp_Object value)
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3109 {
5127
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5125
diff changeset
3110 Lisp_Object result = ALLOC_NORMAL_LISP_OBJECT (weak_box);
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
3111 struct weak_box *wb = XWEAK_BOX (result);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3112
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3113 wb->value = value;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3114 result = wrap_weak_box (wb);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3115 wb->next_weak_box = Vall_weak_boxes;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3116 Vall_weak_boxes = result;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3117 return result;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3118 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3119
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
3120 static const struct memory_description weak_box_description[] = {
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3121 { XD_LO_LINK, offsetof (struct weak_box, value) },
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3122 { XD_END}
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3123 };
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3124
5118
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4759
diff changeset
3125 DEFINE_NODUMP_LISP_OBJECT ("weak-box", weak_box, mark_weak_box,
5124
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5118
diff changeset
3126 print_weak_box, 0, weak_box_equal,
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5118
diff changeset
3127 weak_box_hash, weak_box_description,
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5118
diff changeset
3128 struct weak_box);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3129
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3130 DEFUN ("make-weak-box", Fmake_weak_box, 1, 1, 0, /*
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3131 Return a new weak box from value CONTENTS.
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3132 The weak box is a reference to CONTENTS which may be extracted with
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3133 `weak-box-ref'. However, the weak box does not contribute to the
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3134 reachability of CONTENTS. When CONTENTS is garbage-collected,
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3135 `weak-box-ref' will return NIL.
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3136 */
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3137 (value))
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3138 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3139 return make_weak_box(value);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3140 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3141
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3142 DEFUN ("weak-box-ref", Fweak_box_ref, 1, 1, 0, /*
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3143 Return the contents of weak box WEAK-BOX.
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3144 If the contents have been GCed, return NIL.
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3145 */
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3146 (wb))
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3147 {
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3148 return XWEAK_BOX (wb)->value;
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3149 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3150
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3151 DEFUN ("weak-box-p", Fweak_boxp, 1, 1, 0, /*
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3152 Return non-nil if OBJECT is a weak box.
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3153 */
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3154 (object))
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3155 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3156 return WEAK_BOXP (object) ? Qt : Qnil;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3157 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3158
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3159 /************************************************************************/
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3160 /* ephemerons */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3161 /************************************************************************/
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3162
993
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3163 /* The concept of ephemerons is due to:
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3164 * Barry Hayes: Ephemerons: A New Finalization Mechanism. OOPSLA 1997: 176-183
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3165 * The original idea is due to George Bosworth of Digitalk, Inc.
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3166 *
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3167 * For a discussion of finalization and weakness that also reviews
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3168 * ephemerons, refer to:
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3169 * Simon Peyton Jones, Simon Marlow, Conal Elliot:
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3170 * Stretching the storage manager
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3171 * Implementation of Functional Languages, 1999
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3172 */
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3173
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3174 static Lisp_Object Vall_ephemerons; /* Gemarke es niemals ever!!! */
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3175 static Lisp_Object Vnew_all_ephemerons;
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3176 static Lisp_Object Vfinalize_list;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3177
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3178 void
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3179 init_marking_ephemerons(void)
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3180 {
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3181 Vnew_all_ephemerons = Qnil;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3182 }
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3183
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3184 /* Move all live ephemerons with live keys over to
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3185 * Vnew_all_ephemerons, marking the values and finalizers along the
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3186 * way. */
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3187
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3188 int
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3189 continue_marking_ephemerons(void)
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3190 {
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3191 Lisp_Object rest = Vall_ephemerons, next, prev = Qnil;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3192 int did_mark = 0;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3193
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3194 while (!NILP (rest))
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3195 {
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3196 next = XEPHEMERON_NEXT (rest);
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3197
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3198 if (marked_p (rest))
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3199 {
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3200 MARK_CONS (XCONS (XEPHEMERON (rest)->cons_chain));
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3201 if (marked_p (XEPHEMERON (rest)->key))
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3202 {
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3203 #ifdef USE_KKCC
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5142
diff changeset
3204 kkcc_gc_stack_push_lisp_object_0
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5142
diff changeset
3205 (XCAR (XEPHEMERON (rest)->cons_chain));
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3206 #else /* NOT USE_KKCC */
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3207 mark_object (XCAR (XEPHEMERON (rest)->cons_chain));
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3208 #endif /* NOT USE_KKCC */
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3209 did_mark = 1;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3210 XSET_EPHEMERON_NEXT (rest, Vnew_all_ephemerons);
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3211 Vnew_all_ephemerons = rest;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3212 if (NILP (prev))
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3213 Vall_ephemerons = next;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3214 else
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3215 XSET_EPHEMERON_NEXT (prev, next);
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3216 }
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3217 else
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3218 prev = rest;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3219 }
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3220 else
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3221 prev = rest;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3222
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3223 rest = next;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3224 }
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3225
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3226 return did_mark;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3227 }
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3228
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3229 /* At this point, everything that's in Vall_ephemerons is dead.
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3230 * Well, almost: we still need to run the finalizers, so we need to
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3231 * resurrect them.
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3232 */
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3233
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3234 int
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3235 finish_marking_ephemerons(void)
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3236 {
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3237 Lisp_Object rest = Vall_ephemerons, next, prev = Qnil;
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3238 int did_mark = 0;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3239
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3240 while (! NILP (rest))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3241 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3242 next = XEPHEMERON_NEXT (rest);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3243
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3244 if (marked_p (rest))
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3245 /* The ephemeron itself is live, but its key is garbage */
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3246 {
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3247 /* tombstone */
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3248 XSET_EPHEMERON_VALUE (rest, Qnil);
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3249
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3250 if (! NILP (XEPHEMERON_FINALIZER (rest)))
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3251 {
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3252 MARK_CONS (XCONS (XEPHEMERON (rest)->cons_chain));
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3253 #ifdef USE_KKCC
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5142
diff changeset
3254 kkcc_gc_stack_push_lisp_object_0
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5142
diff changeset
3255 (XCAR (XEPHEMERON (rest)->cons_chain));
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3256 #else /* NOT USE_KKCC */
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3257 mark_object (XCAR (XEPHEMERON (rest)->cons_chain));
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3258 #endif /* NOT USE_KKCC */
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3259
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3260 /* Register the finalizer */
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3261 XSET_EPHEMERON_NEXT (rest, Vfinalize_list);
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3262 Vfinalize_list = XEPHEMERON (rest)->cons_chain;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3263 did_mark = 1;
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3264 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3265
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3266 /* Remove it from the list. */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3267 if (NILP (prev))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3268 Vall_ephemerons = next;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3269 else
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3270 XSET_EPHEMERON_NEXT (prev, next);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3271 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3272 else
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3273 prev = rest;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3274
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3275 rest = next;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3276 }
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3277
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3278 return did_mark;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3279 }
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3280
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3281 void
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3282 prune_ephemerons(void)
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3283 {
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3284 Vall_ephemerons = Vnew_all_ephemerons;
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3285 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3286
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3287 Lisp_Object
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3288 zap_finalize_list(void)
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3289 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3290 Lisp_Object finalizers = Vfinalize_list;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3291
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3292 Vfinalize_list = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3293
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3294 return finalizers;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3295 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3296
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3297 static Lisp_Object
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2054
diff changeset
3298 mark_ephemeron (Lisp_Object UNUSED (obj))
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3299 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3300 return Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3301 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3302
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3303 static void
5325
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3304 print_ephemeron (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3305 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3306 if (print_readably)
5325
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3307 {
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3308 printing_unreadable_lisp_object (obj, 0);
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3309 }
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3310
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3311 write_ascstring (printcharfun, "#<ephemeron :key ");
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3312 print_internal (XEPHEMERON (obj)->key, printcharfun, escapeflag);
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3313 write_ascstring (printcharfun, " :value ");
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3314 print_internal (XEPHEMERON (obj)->value, printcharfun, escapeflag);
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3315 write_ascstring (printcharfun, " :finalizer ");
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3316 print_internal (XEPHEMERON_FINALIZER (obj), printcharfun, escapeflag);
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3317 write_fmt_string (printcharfun, " 0x%x>", LISP_OBJECT_UID (obj));
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3318 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3319
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3320 static int
4906
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4885
diff changeset
3321 ephemeron_equal (Lisp_Object obj1, Lisp_Object obj2, int depth, int foldcase)
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3322 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3323 return
4906
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4885
diff changeset
3324 internal_equal_0 (XEPHEMERON_REF (obj1), XEPHEMERON_REF(obj2), depth + 1,
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4885
diff changeset
3325 foldcase);
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3326 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3327
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3328 static Hashcode
5191
71ee43b8a74d Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
3329 ephemeron_hash(Lisp_Object obj, int depth, Boolint equalp)
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3330 {
5191
71ee43b8a74d Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
3331 return internal_hash (XEPHEMERON_REF (obj), depth + 1, equalp);
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3332 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3333
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3334 Lisp_Object
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
3335 make_ephemeron (Lisp_Object key, Lisp_Object value, Lisp_Object finalizer)
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3336 {
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
3337 Lisp_Object temp = Qnil;
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3338 struct gcpro gcpro1, gcpro2;
5127
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5125
diff changeset
3339 Lisp_Object result = ALLOC_NORMAL_LISP_OBJECT (ephemeron);
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
3340 struct ephemeron *eph = XEPHEMERON (result);
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3341
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3342 eph->key = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3343 eph->cons_chain = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3344 eph->value = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3345
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
3346 result = wrap_ephemeron (eph);
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3347 GCPRO2 (result, temp);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3348
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3349 eph->key = key;
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
3350 temp = Fcons (value, finalizer);
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
3351 eph->cons_chain = Fcons (temp, Vall_ephemerons);
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3352 eph->value = value;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3353
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3354 Vall_ephemerons = result;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3355
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3356 UNGCPRO;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3357 return result;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3358 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3359
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3360 /* Ephemerons are special cases in the KKCC mark algorithm, so nothing
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3361 is marked here. */
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
3362 static const struct memory_description ephemeron_description[] = {
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
3363 { XD_LISP_OBJECT, offsetof(struct ephemeron, key),
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2500
diff changeset
3364 0, { 0 }, XD_FLAG_NO_KKCC },
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
3365 { XD_LISP_OBJECT, offsetof(struct ephemeron, cons_chain),
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2500
diff changeset
3366 0, { 0 }, XD_FLAG_NO_KKCC },
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
3367 { XD_LISP_OBJECT, offsetof(struct ephemeron, value),
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2500
diff changeset
3368 0, { 0 }, XD_FLAG_NO_KKCC },
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3369 { XD_END }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3370 };
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3371
5118
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4759
diff changeset
3372 DEFINE_NODUMP_LISP_OBJECT ("ephemeron", ephemeron,
5124
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5118
diff changeset
3373 mark_ephemeron, print_ephemeron,
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5118
diff changeset
3374 0, ephemeron_equal, ephemeron_hash,
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5118
diff changeset
3375 ephemeron_description,
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5118
diff changeset
3376 struct ephemeron);
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3377
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3378 DEFUN ("make-ephemeron", Fmake_ephemeron, 2, 3, 0, /*
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3379 Return a new ephemeron with key KEY, value VALUE, and finalizer FINALIZER.
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3380 The ephemeron is a reference to VALUE which may be extracted with
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3381 `ephemeron-ref'. VALUE is only reachable through the ephemeron as
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3382 long as KEY is reachable; the ephemeron does not contribute to the
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3383 reachability of KEY. When KEY becomes unreachable while the ephemeron
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3384 itself is still reachable, VALUE is queued for finalization: FINALIZER
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3385 will possibly be called on VALUE some time in the future. Moreover,
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3386 future calls to `ephemeron-ref' will return NIL.
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3387 */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3388 (key, value, finalizer))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3389 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3390 return make_ephemeron(key, value, finalizer);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3391 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3392
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3393 DEFUN ("ephemeron-ref", Fephemeron_ref, 1, 1, 0, /*
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3394 Return the contents of ephemeron EPHEMERON.
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3395 If the contents have been GCed, return NIL.
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3396 */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3397 (eph))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3398 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3399 return XEPHEMERON_REF (eph);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3400 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3401
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3402 DEFUN ("ephemeron-p", Fephemeronp, 1, 1, 0, /*
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3403 Return non-nil if OBJECT is an ephemeron.
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3404 */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3405 (object))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3406 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3407 return EPHEMERONP (object) ? Qt : Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3408 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3410 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3411 /* initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3412 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3414 static SIGTYPE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3415 arith_error (int signo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3416 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3417 EMACS_REESTABLISH_SIGNAL (signo, arith_error);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3418 EMACS_UNBLOCK_SIGNAL (signo);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3419 signal_error (Qarith_error, 0, Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3420 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3421
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3422 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3423 init_data_very_early (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3424 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3425 /* Don't do this if just dumping out.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3426 We don't want to call `signal' in this case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3427 so that we don't have trouble with dumping
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3428 signal-delivering routines in an inconsistent state. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3429 if (!initialized)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3430 return;
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 603
diff changeset
3431 EMACS_SIGNAL (SIGFPE, arith_error);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3432 #ifdef uts
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 603
diff changeset
3433 EMACS_SIGNAL (SIGEMT, arith_error);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3434 #endif /* uts */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3435 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3437 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3438 init_errors_once_early (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3439 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3440 DEFSYMBOL (Qerror_conditions);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3441 DEFSYMBOL (Qerror_message);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3443 /* We declare the errors here because some other deferrors depend
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3444 on some of the errors below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3445
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3446 /* ERROR is used as a signaler for random errors for which nothing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3447 else is right */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3448
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3449 DEFERROR (Qerror, "error", Qnil);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3450 DEFERROR_STANDARD (Qquit, Qnil);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3451
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3452 DEFERROR_STANDARD (Qinvalid_argument, Qerror);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3453
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3454 DEFERROR_STANDARD (Qsyntax_error, Qinvalid_argument);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3455 DEFERROR_STANDARD (Qinvalid_read_syntax, Qsyntax_error);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3456 DEFERROR_STANDARD (Qstructure_formation_error, Qsyntax_error);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3457 DEFERROR_STANDARD (Qlist_formation_error, Qstructure_formation_error);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3458 DEFERROR_STANDARD (Qmalformed_list, Qlist_formation_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3459 DEFERROR_STANDARD (Qmalformed_property_list, Qmalformed_list);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3460 DEFERROR_STANDARD (Qcircular_list, Qlist_formation_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3461 DEFERROR_STANDARD (Qcircular_property_list, Qcircular_list);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3462
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3463 DEFERROR_STANDARD (Qwrong_type_argument, Qinvalid_argument);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3464 DEFERROR_STANDARD (Qargs_out_of_range, Qinvalid_argument);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3465 DEFERROR_STANDARD (Qwrong_number_of_arguments, Qinvalid_argument);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3466 DEFERROR_STANDARD (Qinvalid_function, Qinvalid_argument);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3467 DEFERROR_STANDARD (Qinvalid_constant, Qinvalid_argument);
5084
6afe991b8135 Add a PARSE_KEYWORDS macro, use it in #'make-hash-table.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4998
diff changeset
3468 DEFERROR_STANDARD (Qinvalid_keyword_argument, Qinvalid_argument);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3469 DEFERROR (Qno_catch, "No catch for tag", Qinvalid_argument);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3470
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3471 DEFERROR_STANDARD (Qinvalid_state, Qerror);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3472 DEFERROR (Qvoid_function, "Symbol's function definition is void",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3473 Qinvalid_state);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3474 DEFERROR (Qcyclic_function_indirection,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3475 "Symbol's chain of function indirections contains a loop",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3476 Qinvalid_state);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3477 DEFERROR (Qvoid_variable, "Symbol's value as variable is void",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3478 Qinvalid_state);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3479 DEFERROR (Qcyclic_variable_indirection,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3480 "Symbol's chain of variable indirections contains a loop",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3481 Qinvalid_state);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3482 DEFERROR_STANDARD (Qstack_overflow, Qinvalid_state);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3483 DEFERROR_STANDARD (Qinternal_error, Qinvalid_state);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3484 DEFERROR_STANDARD (Qout_of_memory, Qinvalid_state);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3485
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3486 DEFERROR_STANDARD (Qinvalid_operation, Qerror);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3487 DEFERROR_STANDARD (Qinvalid_change, Qinvalid_operation);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3488 DEFERROR (Qsetting_constant, "Attempt to set a constant symbol",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3489 Qinvalid_change);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3490 DEFERROR_STANDARD (Qprinting_unreadable_object, Qinvalid_operation);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3491 DEFERROR (Qunimplemented, "Feature not yet implemented", Qinvalid_operation);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3492
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3493 DEFERROR_STANDARD (Qediting_error, Qinvalid_operation);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3494 DEFERROR_STANDARD (Qbeginning_of_buffer, Qediting_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3495 DEFERROR_STANDARD (Qend_of_buffer, Qediting_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3496 DEFERROR (Qbuffer_read_only, "Buffer is read-only", Qediting_error);
5381
4f39e57a82b4 Improve read-only error reporting.
Didier Verna <didier@lrde.epita.fr>
parents: 5374
diff changeset
3497 DEFERROR (Qextent_read_only, "Extent is read-only", Qediting_error);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3498
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3499 DEFERROR (Qio_error, "IO Error", Qinvalid_operation);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3500 DEFERROR_STANDARD (Qfile_error, Qio_error);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3501 DEFERROR (Qend_of_file, "End of file or stream", Qfile_error);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3502 DEFERROR_STANDARD (Qconversion_error, Qio_error);
580
55e998c311f5 [xemacs-hg @ 2001-05-26 12:24:50 by ben]
ben
parents: 563
diff changeset
3503 DEFERROR_STANDARD (Qtext_conversion_error, Qconversion_error);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3504
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3505 DEFERROR (Qarith_error, "Arithmetic error", Qinvalid_operation);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3506 DEFERROR (Qrange_error, "Arithmetic range error", Qarith_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3507 DEFERROR (Qdomain_error, "Arithmetic domain error", Qarith_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3508 DEFERROR (Qsingularity_error, "Arithmetic singularity error", Qdomain_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3509 DEFERROR (Qoverflow_error, "Arithmetic overflow error", Qdomain_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3510 DEFERROR (Qunderflow_error, "Arithmetic underflow error", Qdomain_error);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3511 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3512
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3513 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3514 syms_of_data (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3515 {
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
3516 INIT_LISP_OBJECT (weak_list);
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
3517 INIT_LISP_OBJECT (ephemeron);
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
3518 INIT_LISP_OBJECT (weak_box);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3519
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3520 DEFSYMBOL (Qlambda);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3521 DEFSYMBOL (Qlistp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3522 DEFSYMBOL (Qtrue_list_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3523 DEFSYMBOL (Qconsp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3524 DEFSYMBOL (Qsubrp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3525 DEFSYMBOL (Qsymbolp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3526 DEFSYMBOL (Qintegerp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3527 DEFSYMBOL (Qcharacterp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3528 DEFSYMBOL (Qnatnump);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3529 DEFSYMBOL (Qnonnegativep);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3530 DEFSYMBOL (Qstringp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3531 DEFSYMBOL (Qarrayp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3532 DEFSYMBOL (Qsequencep);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3533 DEFSYMBOL (Qbufferp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3534 DEFSYMBOL (Qbitp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3535 DEFSYMBOL_MULTIWORD_PREDICATE (Qbit_vectorp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3536 DEFSYMBOL (Qvectorp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3537 DEFSYMBOL (Qchar_or_string_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3538 DEFSYMBOL (Qmarkerp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3539 DEFSYMBOL (Qinteger_or_marker_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3540 DEFSYMBOL (Qinteger_or_char_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3541 DEFSYMBOL (Qinteger_char_or_marker_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3542 DEFSYMBOL (Qnumberp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3543 DEFSYMBOL (Qnumber_char_or_marker_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3544 DEFSYMBOL (Qcdr);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3545 DEFSYMBOL (Qerror_lacks_explanatory_string);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3546 DEFSYMBOL_MULTIWORD_PREDICATE (Qweak_listp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3547 DEFSYMBOL (Qfloatp);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3548
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3549 DEFSUBR (Fwrong_type_argument);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3550
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3551 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3552 DEFSUBR (Fdiv);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3553 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3554 DEFSUBR (Feq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3555 DEFSUBR (Fnull);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3556 Ffset (intern ("not"), intern ("null"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3557 DEFSUBR (Flistp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3558 DEFSUBR (Fnlistp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3559 DEFSUBR (Ftrue_list_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3560 DEFSUBR (Fconsp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3561 DEFSUBR (Fatom);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3562 DEFSUBR (Fchar_or_string_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3563 DEFSUBR (Fcharacterp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3564 DEFSUBR (Fchar_int_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3565 DEFSUBR (Fchar_to_int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3566 DEFSUBR (Fint_to_char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3567 DEFSUBR (Fchar_or_char_int_p);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3568 DEFSUBR (Ffixnump);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3569 DEFSUBR (Fintegerp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3570 DEFSUBR (Finteger_or_marker_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3571 DEFSUBR (Finteger_or_char_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3572 DEFSUBR (Finteger_char_or_marker_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3573 DEFSUBR (Fnumberp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3574 DEFSUBR (Fnumber_or_marker_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3575 DEFSUBR (Fnumber_char_or_marker_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3576 DEFSUBR (Ffloatp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3577 DEFSUBR (Fnatnump);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3578 DEFSUBR (Fnonnegativep);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3579 DEFSUBR (Fsymbolp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3580 DEFSUBR (Fkeywordp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3581 DEFSUBR (Fstringp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3582 DEFSUBR (Fvectorp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3583 DEFSUBR (Fbitp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3584 DEFSUBR (Fbit_vector_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3585 DEFSUBR (Farrayp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3586 DEFSUBR (Fsequencep);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3587 DEFSUBR (Fmarkerp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3588 DEFSUBR (Fsubrp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3589 DEFSUBR (Fsubr_min_args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3590 DEFSUBR (Fsubr_max_args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3591 DEFSUBR (Fsubr_interactive);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3592 DEFSUBR (Ftype_of);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3593 DEFSUBR (Fcar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3594 DEFSUBR (Fcdr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3595 DEFSUBR (Fcar_safe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3596 DEFSUBR (Fcdr_safe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3597 DEFSUBR (Fsetcar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3598 DEFSUBR (Fsetcdr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3599 DEFSUBR (Findirect_function);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3600 DEFSUBR (Faref);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3601 DEFSUBR (Faset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3602
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3603 DEFSUBR (Fnumber_to_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3604 DEFSUBR (Fstring_to_number);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3605 DEFSUBR (Feqlsign);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3606 DEFSUBR (Flss);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3607 DEFSUBR (Fgtr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3608 DEFSUBR (Fleq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3609 DEFSUBR (Fgeq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3610 DEFSUBR (Fneq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3611 DEFSUBR (Fzerop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3612 DEFSUBR (Fplus);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3613 DEFSUBR (Fminus);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3614 DEFSUBR (Ftimes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3615 DEFSUBR (Fquo);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3616 DEFSUBR (Frem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3617 DEFSUBR (Fmod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3618 DEFSUBR (Fmax);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3619 DEFSUBR (Fmin);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3620 DEFSUBR (Flogand);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3621 DEFSUBR (Flogior);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3622 DEFSUBR (Flogxor);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3623 DEFSUBR (Flsh);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3624 DEFSUBR (Fash);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3625 DEFSUBR (Fadd1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3626 DEFSUBR (Fsub1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3627 DEFSUBR (Flognot);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3628
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3629 DEFSUBR (Fweak_list_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3630 DEFSUBR (Fmake_weak_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3631 DEFSUBR (Fweak_list_type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3632 DEFSUBR (Fweak_list_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3633 DEFSUBR (Fset_weak_list_list);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3634
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3635 DEFSUBR (Fmake_ephemeron);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3636 DEFSUBR (Fephemeron_ref);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3637 DEFSUBR (Fephemeronp);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3638 DEFSUBR (Fmake_weak_box);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3639 DEFSUBR (Fweak_box_ref);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3640 DEFSUBR (Fweak_boxp);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3641 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3642
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3643 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3644 vars_of_data (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3645 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3646 /* This must not be staticpro'd */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3647 Vall_weak_lists = Qnil;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 444
diff changeset
3648 dump_add_weak_object_chain (&Vall_weak_lists);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3649
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3650 Vall_ephemerons = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3651 dump_add_weak_object_chain (&Vall_ephemerons);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3652
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3653 Vfinalize_list = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3654 staticpro (&Vfinalize_list);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3655
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3656 Vall_weak_boxes = Qnil;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3657 dump_add_weak_object_chain (&Vall_weak_boxes);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3658
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
3659 DEFVAR_CONST_INT ("most-negative-fixnum", &Vmost_negative_fixnum /*
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
3660 The fixnum closest in value to negative infinity.
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
3661 */);
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
3662 Vmost_negative_fixnum = EMACS_INT_MIN;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
3663
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
3664 DEFVAR_CONST_INT ("most-positive-fixnum", &Vmost_positive_fixnum /*
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
3665 The fixnum closest in value to positive infinity.
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
3666 */);
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
3667 Vmost_positive_fixnum = EMACS_INT_MAX;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
3668
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3669 #ifdef DEBUG_XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3670 DEFVAR_BOOL ("debug-issue-ebola-notices", &debug_issue_ebola_notices /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3671 If non-zero, note when your code may be suffering from char-int confoundance.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3672 That is to say, if XEmacs encounters a usage of `eq', `memq', `equal',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3673 etc. where an int and a char with the same value are being compared,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3674 it will issue a notice on stderr to this effect, along with a backtrace.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3675 In such situations, the result would be different in XEmacs 19 versus
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3676 XEmacs 20, and you probably don't want this.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3677
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3678 Note that in order to see these notices, you have to byte compile your
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3679 code under XEmacs 20 -- any code byte-compiled under XEmacs 19 will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3680 have its chars and ints all confounded in the byte code, making it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3681 impossible to accurately determine Ebola infection.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3682 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3683
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3684 debug_issue_ebola_notices = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3685
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3686 DEFVAR_INT ("debug-ebola-backtrace-length",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3687 &debug_ebola_backtrace_length /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3688 Length (in stack frames) of short backtrace printed out in Ebola notices.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3689 See `debug-issue-ebola-notices'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3690 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3691 debug_ebola_backtrace_length = 32;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3692
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3693 #endif /* DEBUG_XEMACS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3694 }