annotate src/data.c @ 5908:6174848f3e6c

Use parse_integer() in read_atom(); support bases with ratios like integers src/ChangeLog addition: 2015-05-08 Aidan Kehoe <kehoea@parhasard.net> * data.c (init_errors_once_early): Move the Qunsupported_type here from numbers.c, so it's available when the majority of our types are not supported. * general-slots.h: Add it here, too. * number.c: Remove the definition of Qunsupported_type from here. * lread.c (read_atom): Check if the first character could reflect a rational, if so, call parse_integer(), don't check the syntax of the other characters. This allows us to accept the non-ASCII digit characters too. If that worked partially, but not completely, and the next char is a slash, try to parse as a ratio. If that fails, try isfloat_string(), but only if the first character could plausibly be part of a float. Otherwise, treat as a symbol. * lread.c (read_rational): Rename from read_integer. Handle ratios with the same radix specification as was used for integers. * lread.c (read1): Rename read_integer in this function. Support the Common Lisp #NNNrMMM syntax for parsing a number MMM of arbitrary radix NNN. man/ChangeLog addition: 2015-05-08 Aidan Kehoe <kehoea@parhasard.net> * lispref/numbers.texi (Numbers): Describe the newly-supported arbitrary-base syntax for rationals (integers and ratios). Describe that ratios can take the same base specification as integers, something also new. tests/ChangeLog addition: 2015-05-08 Aidan Kehoe <kehoea@parhasard.net> * automated/lisp-reader-tests.el: Check the arbitrary-base integer reader syntax support, just added. Check the reader base support for ratios, just added. Check the non-ASCII-digit support in the reader, just added.
author Aidan Kehoe <kehoea@parhasard.net>
date Sat, 09 May 2015 00:40:57 +0100
parents 85fd1ab80057
children eb1e15c9440b
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
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5207
diff changeset
8 XEmacs is free software: you can redistribute it and/or modify it
428
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
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5207
diff changeset
10 Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5207
diff changeset
11 option) any later version.
428
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
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5207
diff changeset
19 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 /* 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
22 XEmacs' symbols.c. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 /* This file has been Mule-ized. */
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 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 #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
31 #include "gc.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include "syssignal.h"
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
33 #include "sysfloat.h"
5864
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
34 #include "syntax.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
5207
1096ef427b56 Error on too many arguments to #'function, #'quote.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5191
diff changeset
36 Lisp_Object Qnil, Qt, Qlambda, Qunbound;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 Lisp_Object Qerror_conditions, Qerror_message;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
38 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
39 Lisp_Object Qlist_formation_error, Qstructure_formation_error;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
40 Lisp_Object Qmalformed_list, Qmalformed_property_list;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
41 Lisp_Object Qcircular_list, Qcircular_property_list;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
42 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
43 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
44 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
45 Lisp_Object Qinvalid_keyword_argument, Qno_catch;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
46 Lisp_Object Qinternal_error, Qinvalid_state, Qstack_overflow, Qout_of_memory;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 Lisp_Object Qvoid_variable, Qcyclic_variable_indirection;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 Lisp_Object Qvoid_function, Qcyclic_function_indirection;
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
49 Lisp_Object Qinvalid_operation, Qinvalid_change, Qprinting_unreadable_object;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
50 Lisp_Object Qsetting_constant;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
51 Lisp_Object Qediting_error;
5381
4f39e57a82b4 Improve read-only error reporting.
Didier Verna <didier@lrde.epita.fr>
parents: 5374
diff changeset
52 Lisp_Object Qbeginning_of_buffer, Qend_of_buffer;
4f39e57a82b4 Improve read-only error reporting.
Didier Verna <didier@lrde.epita.fr>
parents: 5374
diff changeset
53 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
54 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
55 Lisp_Object Qtext_conversion_error;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 Lisp_Object Qarith_error, Qrange_error, Qdomain_error;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 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
58 Lisp_Object Qintegerp, Qnatnump, Qnonnegativep, Qsymbolp;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 Lisp_Object Qlistp, Qtrue_list_p, Qweak_listp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 Lisp_Object Qconsp, Qsubrp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 Lisp_Object Qcharacterp, Qstringp, Qarrayp, Qsequencep, Qvectorp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qbufferp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 Lisp_Object Qinteger_or_char_p, Qinteger_char_or_marker_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 Lisp_Object Qnumberp, Qnumber_char_or_marker_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 Lisp_Object Qbit_vectorp, Qbitp, Qcdr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
67 Lisp_Object Qerror_lacks_explanatory_string;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 Lisp_Object Qfloatp;
5864
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
69 Lisp_Object Q_junk_allowed, Q_radix, Q_radix_table;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
70
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
71 Lisp_Object Vdigit_fixnum_map, Vfixnum_to_char_map;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
73 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
74
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 #ifdef DEBUG_XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 int debug_issue_ebola_notices;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
458
c33ae14dd6d0 Import from CVS: tag r21-2-44
cvs
parents: 456
diff changeset
79 Fixnum debug_ebola_backtrace_length;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 eq_with_ebola_notice (Lisp_Object obj1, Lisp_Object obj2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 if (debug_issue_ebola_notices
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
85 && ((CHARP (obj1) && FIXNUMP (obj2)) || (CHARP (obj2) && FIXNUMP (obj1))))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 /* #### 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
88 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
89 write_msg_string
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 801
diff changeset
90 (Qexternal_debugging_output,
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 801
diff changeset
91 "Comparison between integer and character is constant nil (");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 Fprinc (obj1, 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, " and ");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 Fprinc (obj2, Qexternal_debugging_output);
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
95 write_msg_string (Qexternal_debugging_output, ")\n");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 debug_short_backtrace (debug_ebola_backtrace_length);
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 return EQ (obj1, obj2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 }
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 #endif /* DEBUG_XEMACS */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106 wrong_type_argument (Lisp_Object predicate, Lisp_Object value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 REGISTER Lisp_Object tem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 value = Fsignal (Qwrong_type_argument, list2 (predicate, value));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 tem = call1 (predicate, value);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 while (NILP (tem));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 return value;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 DOESNT_RETURN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 dead_wrong_type_argument (Lisp_Object predicate, Lisp_Object value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
122 signal_error_1 (Qwrong_type_argument, list2 (predicate, value));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 DEFUN ("wrong-type-argument", Fwrong_type_argument, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 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
127 This function loops, signalling a continuable `wrong-type-argument' error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 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
129 calling PREDICATE on the returned value, until the value gotten satisfies
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 PREDICATE. At that point, the gotten value is returned.
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 (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 return wrong_type_argument (predicate, value);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 DOESNT_RETURN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 c_write_error (Lisp_Object obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
140 signal_error (Qsetting_constant,
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
141 "Attempt to modify read-only object (c)", obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 DOESNT_RETURN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 lisp_write_error (Lisp_Object obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
147 signal_error (Qsetting_constant,
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
148 "Attempt to modify read-only object (lisp)", obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 DOESNT_RETURN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 args_out_of_range (Lisp_Object a1, Lisp_Object a2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
154 signal_error_1 (Qargs_out_of_range, list2 (a1, a2));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 DOESNT_RETURN
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 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
159 {
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
160 signal_error_1 (Qargs_out_of_range, list3 (a1, a2, a3));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 void
5307
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
164 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
165 {
5307
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
166 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
167 int 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 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
170 {
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
171 CHECK_INTEGER (args[ii]);
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
172 }
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
173
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
174 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
175 args_out_of_range_3 (val, min, max);
428
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
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 /* Data type predicates */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 DEFUN ("eq", Feq, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 Return t if the two args are the same Lisp object.
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 (object1, object2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
186 return EQ_WITH_EBOLA_NOTICE (object1, object2) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 DEFUN ("null", Fnull, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 Return t if OBJECT is nil.
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 (object))
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 return NILP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 DEFUN ("consp", Fconsp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 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
199
3355
721daee0fcd8 [xemacs-hg @ 2006-04-23 20:12:25 by aidan]
aidan
parents: 3343
diff changeset
200 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
201 a cons cell is.
428
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 (object))
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 return CONSP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
207
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208 DEFUN ("atom", Fatom, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 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
210
721daee0fcd8 [xemacs-hg @ 2006-04-23 20:12:25 by aidan]
aidan
parents: 3343
diff changeset
211 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
212 a cons cell is.
428
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 (object))
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 return CONSP (object) ? Qnil : Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 DEFUN ("listp", Flistp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 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
221
3355
721daee0fcd8 [xemacs-hg @ 2006-04-23 20:12:25 by aidan]
aidan
parents: 3343
diff changeset
222 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
223 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
224 cons cell. A "proper list" contains no cycles.
428
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 (object))
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 return LISTP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 DEFUN ("nlistp", Fnlistp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232 Return t if OBJECT is not a list. `nil' is a list.
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 (object))
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 return LISTP (object) ? Qnil : Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239 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
240 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
241 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 (object))
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 return TRUE_LIST_P (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 DEFUN ("symbolp", Fsymbolp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 Return t if OBJECT is a symbol.
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
249
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
250 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
251 a value, a property list and an associated function.
428
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 (object))
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 return SYMBOLP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 DEFUN ("keywordp", Fkeywordp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 Return t if OBJECT is a keyword.
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 (object))
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 return KEYWORDP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 DEFUN ("vectorp", Fvectorp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 Return t if OBJECT is a vector.
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 (object))
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 return VECTORP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 DEFUN ("bit-vector-p", Fbit_vector_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 Return t if OBJECT is a bit vector.
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 (object))
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 return BIT_VECTORP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282 DEFUN ("stringp", Fstringp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 Return t if OBJECT is a string.
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 (object))
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 return STRINGP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 DEFUN ("arrayp", Farrayp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 Return t if OBJECT is an array (string, vector, or bit vector).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 {
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
295 return ARRAYP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 DEFUN ("sequencep", Fsequencep, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 Return t if OBJECT is a sequence (list or array).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
300 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
301 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
302 {
4995
8431b52e43b1 Move the various map* functions to C; add #'map-into.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4885
diff changeset
303 return SEQUENCEP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 DEFUN ("markerp", Fmarkerp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 Return t if OBJECT is a marker (editor pointer).
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 (object))
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 return MARKERP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 DEFUN ("subrp", Fsubrp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 Return t if OBJECT is a built-in function.
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 (object))
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 return SUBRP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 DEFUN ("subr-min-args", Fsubr_min_args, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 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
324 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 (subr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 CHECK_SUBR (subr);
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
328 return make_fixnum (XSUBR (subr)->min_args);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 DEFUN ("subr-max-args", Fsubr_max_args, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 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
333 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
334 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 (subr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 int nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 CHECK_SUBR (subr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 nargs = XSUBR (subr)->max_args;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 if (nargs == MANY || nargs == UNEVALLED)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 else
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
343 return make_fixnum (nargs);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 DEFUN ("subr-interactive", Fsubr_interactive, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
347 Return the interactive spec of the subr object SUBR, or nil.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 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
349 `interactive' and whose second element is the interactive spec.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 (subr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 858
diff changeset
353 const CIbyte *prompt;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 CHECK_SUBR (subr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 prompt = XSUBR (subr)->prompt;
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
356 return prompt ? list2 (Qinteractive, build_msg_cistring (prompt)) : Qnil;
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 DEFUN ("characterp", Fcharacterp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 Return t if OBJECT is a character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 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
363 Any character can be converted into an equivalent integer using
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 `char-int'. To convert the other way, use `int-char'; however,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 only some integers can be converted into characters. Such an integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 is called a `char-int'; see `char-int-p'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 Some functions that work on integers (e.g. the comparison functions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 <, <=, =, /=, etc. and the arithmetic functions +, -, *, etc.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 accept characters and implicitly convert them into integers. In
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 general, functions that work on characters also accept char-ints and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372 implicitly convert them into characters. WARNING: Neither of these
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 behaviors is very desirable, and they are maintained for backward
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 compatibility with old E-Lisp programs that confounded characters and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 integers willy-nilly. These behaviors may change in the future; therefore,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 do not rely on them. Instead, use the character-specific functions such
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 as `char='.
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 (object))
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 return CHARP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 DEFUN ("char-to-int", Fchar_to_int, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
385 Convert CHARACTER into an equivalent integer.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 The resulting integer will always be non-negative. The integers in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 the range 0 - 255 map to characters as follows:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 0 - 31 Control set 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 32 - 127 ASCII
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 128 - 159 Control set 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 160 - 255 Right half of ISO-8859-1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 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
395 values. When Mule support exists, the values assigned to other characters
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 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
397 character sets were loaded, etc., and you should not depend on them.
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 (character))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
401 CHECK_CHAR (character);
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
402 return make_fixnum (XCHAR (character));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 DEFUN ("int-to-char", Fint_to_char, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
406 Convert integer INTEGER into the equivalent character.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 Not all integers correspond to valid characters; use `char-int-p' to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 determine whether this is the case. If the integer cannot be converted,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 nil is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 (integer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
413 CHECK_INTEGER (integer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 if (CHAR_INTP (integer))
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
415 return make_char (XFIXNUM (integer));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 DEFUN ("char-int-p", Fchar_int_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 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
422 See `char-int'.
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 (object))
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 return CHAR_INTP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 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
430 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
431 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 (object))
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 return CHAR_OR_CHAR_INTP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 DEFUN ("char-or-string-p", Fchar_or_string_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 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
439 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
440 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
441 other steps we take to maintain compatibility with the old character/integer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 confoundedness in older versions of E-Lisp.
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 (object))
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 return CHAR_OR_CHAR_INTP (object) || STRINGP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
449 DEFUN ("fixnump", Ffixnump, 1, 1, 0, /*
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
450 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
451
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
452 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
453 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
454 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
455 available memory.
1983
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 (object))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
458 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
459 return FIXNUMP (object) ? Qt : Qnil;
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
460 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 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
462 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
463
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
464 On builds without bignum support, this function is identical to `fixnump'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
468 return INTEGERP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 DEFUN ("integer-or-marker-p", Finteger_or_marker_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 Return t if OBJECT is an integer or a marker (editor pointer).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
476 return INTEGERP (object) || MARKERP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 DEFUN ("integer-or-char-p", Finteger_or_char_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 Return t if OBJECT is an integer or a character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
484 return INTEGERP (object) || CHARP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 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
488 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
489 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
492 return INTEGERP (object) || CHARP (object) || MARKERP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 DEFUN ("natnump", Fnatnump, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 Return t if OBJECT is a nonnegative integer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 {
5307
c096d8051f89 Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5207
diff changeset
500 return NATNUMP (object) ? Qt : Qnil;
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
501 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
502
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
503 DEFUN ("nonnegativep", Fnonnegativep, 1, 1, 0, /*
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
504 Return t if OBJECT is a nonnegative number.
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 (object))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
507 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
508 return NATNUMP (object)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
509 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
510 || (RATIOP (object) && ratio_sign (XRATIO_DATA (object)) >= 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
511 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
512 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
513 || (BIGFLOATP (object) && bigfloat_sign (XBIGFLOAT_DATA (object)) >= 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
514 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
515 ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 DEFUN ("bitp", Fbitp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 Return t if OBJECT is a bit (0 or 1).
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 (object))
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 return BITP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 DEFUN ("numberp", Fnumberp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 Return t if OBJECT is a number (floating point or integer).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
531 return NUMBERP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 DEFUN ("number-or-marker-p", Fnumber_or_marker_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 Return t if OBJECT is a number or a marker.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
539 return NUMBERP (object) || MARKERP (object) ? Qt : Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 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
543 Return t if OBJECT is a number, character or a marker.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
547 return (NUMBERP (object) || CHARP (object) || MARKERP (object))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
549 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 DEFUN ("floatp", Ffloatp, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 Return t if OBJECT is a floating point number.
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 (object))
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 return FLOATP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 DEFUN ("type-of", Ftype_of, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 Return a symbol representing the type of 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 (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 switch (XTYPE (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 case Lisp_Type_Record:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 return intern (XRECORD_LHEADER_IMPLEMENTATION (object)->name);
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 case Lisp_Type_Char: return Qcharacter;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570
5582
873d7425c1ad Change integer to fixnum in a few places where it wasn't possible mechanically.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
571 default: return Qfixnum;
428
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
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 /* Extract and set components of lists */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 DEFUN ("car", Fcar, 1, 1, 0, /*
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
579 Return the car of LIST. If LIST is nil, return nil.
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
580 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
581
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
582 Error if LIST 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
583 */
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
584 (list))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 {
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
588 if (CONSP (list))
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
589 return XCAR (list);
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
590 else if (NILP (list))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 else
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
593 list = wrong_type_argument (Qlistp, list);
428
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 DEFUN ("car-safe", Fcar_safe, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 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
599 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 (object))
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 return CONSP (object) ? XCAR (object) : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 DEFUN ("cdr", Fcdr, 1, 1, 0, /*
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
606 Return the cdr of LIST. If LIST is nil, return nil.
3343
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
607 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
608 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
609
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 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
611 */
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
612 (list))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 {
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
616 if (CONSP (list))
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
617 return XCDR (list);
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
618 else if (NILP (list))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 else
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
621 list = wrong_type_argument (Qlistp, list);
428
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 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 DEFUN ("cdr-safe", Fcdr_safe, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 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
627 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 (object))
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 return CONSP (object) ? XCDR (object) : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 DEFUN ("setcar", Fsetcar, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
634 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
635 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
636 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
637 (cons_cell, newcar))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
639 if (!CONSP (cons_cell))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
640 cons_cell = wrong_type_argument (Qconsp, cons_cell);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
642 XCAR (cons_cell) = newcar;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643 return newcar;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 DEFUN ("setcdr", Fsetcdr, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
647 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
648 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
649 dotted pair (A . B) is the second element, B.
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 (cons_cell, newcdr))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
653 if (!CONSP (cons_cell))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
654 cons_cell = wrong_type_argument (Qconsp, cons_cell);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
656 XCDR (cons_cell) = newcdr;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 return newcdr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 }
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 /* 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
661
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 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
663 return the value found there. If OBJECT is not a symbol, just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 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
665 cyclic-function-indirection error.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
667 This is like Findirect_function when VOID_FUNCTION_ERRORP is true.
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
668 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
669 of the chain ends up being Qunbound. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 Lisp_Object
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
671 indirect_function (Lisp_Object object, int void_function_errorp)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 #define FUNCTION_INDIRECTION_SUSPICION_LENGTH 16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 Lisp_Object tortoise, hare;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675 int count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 for (hare = tortoise = object, count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 SYMBOLP (hare);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 hare = XSYMBOL (hare)->function, count++)
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 < FUNCTION_INDIRECTION_SUSPICION_LENGTH) continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 if (count & 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 tortoise = XSYMBOL (tortoise)->function;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 if (EQ (hare, tortoise))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686 return Fsignal (Qcyclic_function_indirection, list1 (object));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
689 if (void_function_errorp && UNBOUNDP (hare))
436
080151679be2 Import from CVS: tag r21-2-26
cvs
parents: 428
diff changeset
690 return signal_void_function_error (object);
428
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 return hare;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 DEFUN ("indirect-function", Findirect_function, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 Return the function at the end of OBJECT's function chain.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 If OBJECT is a symbol, follow all function indirections and return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 the final function binding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 If OBJECT is not a symbol, just return it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 Signal a void-function error if the final symbol is unbound.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 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
702 function chain of symbols.
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 (object))
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 return indirect_function (object, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 }
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 /* Extract and set vector and string elements */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 DEFUN ("aref", Faref, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 Return the element of ARRAY at index INDEX.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 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
714 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 (array, index_))
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 EMACS_INT idx;
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 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
721 if (FIXNUMP (index_)) idx = XFIXNUM (index_);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 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
723 #ifdef HAVE_BIGNUM
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
724 else if (BIGNUMP (index_))
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
725 {
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
726 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
727 if (EQ (canon, index_))
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
728 {
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
729 /* 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
730 goto range_error;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
731 }
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
732 index_ = canon;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
733 goto retry;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
734 }
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
735 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 index_ = wrong_type_argument (Qinteger_or_char_p, index_);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 }
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 (idx < 0) goto range_error;
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 (VECTORP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 if (idx >= XVECTOR_LENGTH (array)) goto range_error;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 return XVECTOR_DATA (array)[idx];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 else if (BIT_VECTORP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
751 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
752 goto range_error;
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
753 return make_fixnum (bit_vector_bit (XBIT_VECTOR (array), idx));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 else if (STRINGP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 {
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 801
diff changeset
757 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
758 return make_char (string_ichar (array, idx));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 check_losing_bytecode ("aref", array);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 array = wrong_type_argument (Qarrayp, array);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 }
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 range_error:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 args_out_of_range (array, index_);
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
769 RETURN_NOT_REACHED (Qnil);
428
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 DEFUN ("aset", Faset, 3, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 Store into the element of ARRAY at index INDEX the value NEWVAL.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 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
775 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 (array, index_, newval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778 EMACS_INT idx;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
782 if (FIXNUMP (index_)) idx = XFIXNUM (index_);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 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
784 #ifdef HAVE_BIGNUM
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
785 else if (BIGNUMP (index_))
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
786 {
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
787 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
788 if (EQ (canon, index_))
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
789 {
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
790 /* 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
791 goto range_error;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
792 }
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
793 index_ = canon;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
794 goto retry;
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
795 }
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
796 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 index_ = wrong_type_argument (Qinteger_or_char_p, index_);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 if (idx < 0) goto range_error;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
805 CHECK_LISP_WRITEABLE (array);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 if (VECTORP (array))
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 >= XVECTOR_LENGTH (array)) goto range_error;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 XVECTOR_DATA (array)[idx] = newval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 else if (BIT_VECTORP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 {
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 613
diff changeset
813 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
814 goto range_error;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 CHECK_BIT (newval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 set_bit_vector_bit (XBIT_VECTOR (array), idx, !ZEROP (newval));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 else if (STRINGP (array))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 CHECK_CHAR_COERCE_INT (newval);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 801
diff changeset
821 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
822 set_string_char (array, idx, XCHAR (newval));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 bump_string_modiff (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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 array = wrong_type_argument (Qarrayp, array);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 goto retry;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 return newval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 range_error:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 args_out_of_range (array, index_);
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
835 RETURN_NOT_REACHED (Qnil);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 }
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 /**********************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 /* Arithmetic functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 /**********************************************************************/
2001
cc5b615380f8 [xemacs-hg @ 2004-04-08 15:23:07 by james]
james
parents: 1995
diff changeset
842 #ifndef WITH_NUMBER_TYPES
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 typedef struct
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 int int_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 union
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 EMACS_INT ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 double dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 } c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 } int_or_double;
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 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 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
855 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 p->int_p = 1;
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
858 if (FIXNUMP (obj)) p->c.ival = XFIXNUM (obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 else if (CHARP (obj)) p->c.ival = XCHAR (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 else if (MARKERP (obj)) p->c.ival = marker_position (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 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
862 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 obj = wrong_type_argument (Qnumber_char_or_marker_p, obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 }
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 static double
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 number_char_or_marker_to_double (Lisp_Object obj)
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 retry:
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
873 if (FIXNUMP (obj)) return (double) XFIXNUM (obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 else if (CHARP (obj)) return (double) XCHAR (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 else if (MARKERP (obj)) return (double) marker_position (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 else if (FLOATP (obj)) return XFLOAT_DATA (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 obj = wrong_type_argument (Qnumber_char_or_marker_p, obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 }
2001
cc5b615380f8 [xemacs-hg @ 2004-04-08 15:23:07 by james]
james
parents: 1995
diff changeset
883 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 static EMACS_INT
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
886 fixnum_char_or_marker_to_int (Lisp_Object obj)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 retry:
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
889 if (FIXNUMP (obj)) return XFIXNUM (obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 else if (CHARP (obj)) return XCHAR (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 else if (MARKERP (obj)) return marker_position (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
894 /* 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
895 protects against this happening: */
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
896 assert (!BIGNUMP (obj));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
897 obj = wrong_type_argument (Qinteger_char_or_marker_p, obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
902 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
903
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
904 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
905 #define BIGNUM_CASE(op) \
5769
ffc0c5a66ab1 Be lazy converting markers to integers, bytecode_{arithcompare,arithop}().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5768
diff changeset
906 case LAZY_BIGNUM_T: \
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
907 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
908 return Qnil; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
909 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
910 #else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
911 #define BIGNUM_CASE(op)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
912 #endif /* HAVE_BIGNUM */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
913
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
914 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
915 #define RATIO_CASE(op) \
5769
ffc0c5a66ab1 Be lazy converting markers to integers, bytecode_{arithcompare,arithop}().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5768
diff changeset
916 case LAZY_RATIO_T: \
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
917 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
918 return Qnil; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
919 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
920 #else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
921 #define RATIO_CASE(op)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
922 #endif /* HAVE_RATIO */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
923
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
924 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
925 #define BIGFLOAT_CASE(op) \
5769
ffc0c5a66ab1 Be lazy converting markers to integers, bytecode_{arithcompare,arithop}().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5768
diff changeset
926 case LAZY_BIGFLOAT_T: \
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
927 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
928 return Qnil; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
929 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
930 #else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
931 #define BIGFLOAT_CASE(op)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
932 #endif /* HAVE_BIGFLOAT */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
933
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
934 #define ARITHCOMPARE_MANY(c_op,op) \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
935 { \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
936 REGISTER int i; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
937 Lisp_Object obj1, obj2; \
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 for (i = 1; i < nargs; i++) \
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 obj1 = args[i - 1]; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
942 obj2 = args[i]; \
5769
ffc0c5a66ab1 Be lazy converting markers to integers, bytecode_{arithcompare,arithop}().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5768
diff changeset
943 switch (promote_args_lazy (&obj1, &obj2)) \
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
944 { \
5769
ffc0c5a66ab1 Be lazy converting markers to integers, bytecode_{arithcompare,arithop}().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5768
diff changeset
945 case LAZY_FIXNUM_T: \
ffc0c5a66ab1 Be lazy converting markers to integers, bytecode_{arithcompare,arithop}().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5768
diff changeset
946 if (!(XREALFIXNUM (obj1) c_op XREALFIXNUM (obj2))) \
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
947 return Qnil; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
948 break; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
949 BIGNUM_CASE (op) \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
950 RATIO_CASE (op) \
5769
ffc0c5a66ab1 Be lazy converting markers to integers, bytecode_{arithcompare,arithop}().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5768
diff changeset
951 case LAZY_FLOAT_T: \
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
952 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
953 return Qnil; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
954 break; \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
955 BIGFLOAT_CASE (op) \
5769
ffc0c5a66ab1 Be lazy converting markers to integers, bytecode_{arithcompare,arithop}().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5768
diff changeset
956 case LAZY_MARKER_T: \
ffc0c5a66ab1 Be lazy converting markers to integers, bytecode_{arithcompare,arithop}().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5768
diff changeset
957 if (!(byte_marker_position (obj1) c_op \
ffc0c5a66ab1 Be lazy converting markers to integers, bytecode_{arithcompare,arithop}().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5768
diff changeset
958 byte_marker_position (obj2))) \
ffc0c5a66ab1 Be lazy converting markers to integers, bytecode_{arithcompare,arithop}().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5768
diff changeset
959 return Qnil; \
ffc0c5a66ab1 Be lazy converting markers to integers, bytecode_{arithcompare,arithop}().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5768
diff changeset
960 break; \
1983
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 */
5769
ffc0c5a66ab1 Be lazy converting markers to integers, bytecode_{arithcompare,arithop}().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5768
diff changeset
966 /* We don't convert markers lazily here, although we could. It's more
ffc0c5a66ab1 Be lazy converting markers to integers, bytecode_{arithcompare,arithop}().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5768
diff changeset
967 important that we do this lazily in bytecode, which is the case; see
ffc0c5a66ab1 Be lazy converting markers to integers, bytecode_{arithcompare,arithop}().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5768
diff changeset
968 bytecode_arithcompare().
ffc0c5a66ab1 Be lazy converting markers to integers, bytecode_{arithcompare,arithop}().
Aidan Kehoe <kehoea@parhasard.net>
parents: 5768
diff changeset
969 */
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
970 #define ARITHCOMPARE_MANY(c_op,op) \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
971 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 int_or_double iod1, iod2, *p = &iod1, *q = &iod2; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 Lisp_Object *args_end = args + nargs; \
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++, p); \
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 while (args < args_end) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 number_char_or_marker_to_int_or_double (*args++, q); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 if (!((p->int_p && q->int_p) ? \
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
982 (p->c.ival c_op q->c.ival) : \
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
983 ((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
984 (q->int_p ? (double) q->c.ival : q->c.dval)))) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 return Qnil; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 { /* swap */ int_or_double *r = p; p = q; q = r; } \
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 return Qt; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
990 }
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
991 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
993 DEFUN ("=", Feqlsign, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
994 Return t if all the arguments are numerically equal.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
995 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
996
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
997 arguments: (FIRST &rest ARGS)
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 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1000 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1001 ARITHCOMPARE_MANY (==, eql)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1004 DEFUN ("<", Flss, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005 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
1006
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
1007 (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
1008 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
1009 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
1010
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
1011 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
1012
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1013 arguments: (FIRST &rest ARGS)
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 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1017 ARITHCOMPARE_MANY (<, lt)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 DEFUN (">", Fgtr, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 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
1022
29234c1a76c7 [xemacs-hg @ 2006-04-16 15:54:16 by aidan]
aidan
parents: 3017
diff changeset
1023 (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
1024 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
1025 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
1026
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 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
1028
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1029 arguments: (FIRST &rest ARGS)
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 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1033 ARITHCOMPARE_MANY (>, gt)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 DEFUN ("<=", Fleq, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 Return t if the sequence of arguments is monotonically nondecreasing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 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
1039
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1040 arguments: (FIRST &rest ARGS)
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 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1044 ARITHCOMPARE_MANY (<=, le)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047 DEFUN (">=", Fgeq, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 Return t if the sequence of arguments is monotonically nonincreasing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1049 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
1050
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1051 arguments: (FIRST &rest ARGS)
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 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1054 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1055 ARITHCOMPARE_MANY (>=, ge)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1056 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1057
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1058 /* 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
1059 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
1060 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
1061 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
1062 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
1063 than this one in the common case. Optimize the common case! */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1064 DEFUN ("/=", Fneq, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1065 Return t if no two arguments are numerically equal.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1066 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
1067
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
1068 arguments: (FIRST &rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1069 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1070 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1071 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1072 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1073 REGISTER int i, j;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1074 Lisp_Object obj1, obj2;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1075
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1076 for (i = 0; i < nargs - 1; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1077 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1078 obj1 = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1079 for (j = i + 1; j < nargs; j++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1080 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1081 obj2 = args[j];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1082 switch (promote_args (&obj1, &obj2))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1083 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1084 case FIXNUM_T:
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
1085 if (XREALFIXNUM (obj1) == XREALFIXNUM (obj2))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1086 return Qnil;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1087 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1088 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1089 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1090 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
1091 return Qnil;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1092 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1093 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1094 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1095 case RATIO_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1096 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
1097 return Qnil;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1098 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1099 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1100 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1101 if (XFLOAT_DATA (obj1) == XFLOAT_DATA (obj2))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1102 return Qnil;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1103 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1104 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1105 case BIGFLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1106 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
1107 return Qnil;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1108 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1109 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1110 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1111 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1112 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1113 return Qt;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1114 #else /* !WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1115 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1116 Lisp_Object *p, *q;
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 /* Unlike all the other comparisons, this is an N*N algorithm.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 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
1120 for (p = args; p < args_end; p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1122 int_or_double iod1, iod2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1123 number_char_or_marker_to_int_or_double (*p, &iod1);
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 for (q = p + 1; q < args_end; q++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1126 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1127 number_char_or_marker_to_int_or_double (*q, &iod2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1129 if (!((iod1.int_p && iod2.int_p) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1130 (iod1.c.ival != iod2.c.ival) :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1131 ((iod1.int_p ? (double) iod1.c.ival : iod1.c.dval) !=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1132 (iod2.int_p ? (double) iod2.c.ival : iod2.c.dval))))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1133 return Qnil;
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 return Qt;
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1137 #endif /* WITH_NUMBER_TYPES */
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1140 DEFUN ("zerop", Fzerop, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1141 Return t if NUMBER is zero.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1142 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1143 (number))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1144 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1145 retry:
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
1146 if (FIXNUMP (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1147 return EQ (number, Qzero) ? Qt : Qnil;
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1148 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1149 else if (BIGNUMP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1150 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
1151 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1152 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1153 else if (RATIOP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1154 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
1155 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1156 else if (FLOATP (number))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1157 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
1158 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1159 else if (BIGFLOATP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1160 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
1161 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1162 else
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 number = wrong_type_argument (Qnumberp, number);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1165 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1166 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1167 }
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 /* 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
1170 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
1171 Use time_to_lisp() and lisp_to_time() for time values.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1172
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1173 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
1174 for internal purposes (such as when calling record_unwind_protect()),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1175 try using make_opaque_ptr()/get_opaque_ptr() instead. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1176 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1177 word_to_lisp (unsigned int item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1178 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
1179 return Fcons (make_fixnum (item >> 16), make_fixnum (item & 0xffff));
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1182 unsigned int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1183 lisp_to_word (Lisp_Object item)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1184 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
1185 if (FIXNUMP (item))
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
1186 return XFIXNUM (item);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1188 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1189 Lisp_Object top = Fcar (item);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1190 Lisp_Object bot = Fcdr (item);
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
1191 CHECK_FIXNUM (top);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
1192 CHECK_FIXNUM (bot);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
1193 return (XFIXNUM (top) << 16) | (XFIXNUM (bot) & 0xffff);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1194 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1195 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1197
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1198 DEFUN ("number-to-string", Fnumber_to_string, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1199 Convert NUMBER to a string by printing it in decimal.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1200 Uses a minus sign if negative.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1201 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
1202 If supported, it may also be a ratio.
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 (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1206 CHECK_NUMBER (number);
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 if (FLOATP (number))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 {
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
1210 Ascbyte pigbuf[350]; /* see comments in float_to_string */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1212 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
1213 return build_ascstring (pigbuf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214 }
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1215 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1216 if (BIGNUMP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1217 {
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
1218 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
1219 Lisp_Object retval = build_ascstring (str);
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4962
diff changeset
1220 xfree (str);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1221 return retval;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1222 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1223 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1224 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1225 if (RATIOP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1226 {
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
1227 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
1228 Lisp_Object retval = build_ascstring (str);
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4962
diff changeset
1229 xfree (str);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1230 return retval;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1231 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1232 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1233 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1234 if (BIGFLOATP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1235 {
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
1236 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
1237 Lisp_Object retval = build_ascstring (str);
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4962
diff changeset
1238 xfree (str);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1239 return retval;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1240 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1241 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242
603
1c880911c386 [xemacs-hg @ 2001-06-01 08:23:09 by martinb]
martinb
parents: 580
diff changeset
1243 {
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
1244 Ascbyte buffer[DECIMAL_PRINT_SIZE (long)];
603
1c880911c386 [xemacs-hg @ 2001-06-01 08:23:09 by martinb]
martinb
parents: 580
diff changeset
1245
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
1246 long_to_string (buffer, XFIXNUM (number));
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
1247 return build_ascstring (buffer);
603
1c880911c386 [xemacs-hg @ 2001-06-01 08:23:09 by martinb]
martinb
parents: 580
diff changeset
1248 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250
2001
cc5b615380f8 [xemacs-hg @ 2004-04-08 15:23:07 by james]
james
parents: 1995
diff changeset
1251 #ifndef HAVE_BIGNUM
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 digit_to_number (int character, int base)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 /* Assumes ASCII */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 int digit = ((character >= '0' && character <= '9') ? character - '0' :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 (character >= 'a' && character <= 'z') ? character - 'a' + 10 :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 (character >= 'A' && character <= 'Z') ? character - 'A' + 10 :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 -1);
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 return digit >= base ? -1 : digit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 }
2001
cc5b615380f8 [xemacs-hg @ 2004-04-08 15:23:07 by james]
james
parents: 1995
diff changeset
1263 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 DEFUN ("string-to-number", Fstring_to_number, 1, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1266 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
1267 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
1268 If they are supported, it also reads ratios.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 It ignores leading spaces and tabs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1271 If BASE is nil or omitted, base 10 is used.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1272 BASE must be an integer between 2 and 16 (inclusive).
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 Floating point numbers always use base 10.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 (string, base))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 {
1995
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1994
diff changeset
1277 Ibyte *p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278 int b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 CHECK_STRING (string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 if (NILP (base))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 b = 10;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
1286 check_integer_range (base, make_fixnum (2), make_fixnum (16));
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
1287 b = XFIXNUM (base);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289
1995
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1994
diff changeset
1290 p = XSTRING_DATA (string);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 /* Skip any whitespace at the front of the number. Some versions of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 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
1294 while (*p == ' ' || *p == '\t')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296
1995
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1994
diff changeset
1297 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
1298 {
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 if (ZEROP (Vdefault_float_precision))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1301 #endif
1995
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1994
diff changeset
1302 return make_float (atof ((const char *) p));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1303 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1304 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1305 {
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1306 /* 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
1307 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
1308 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
1309 Therefore, move p past any leading '+' signs. */
2010
a9cdbfb4716e [xemacs-hg @ 2004-04-13 15:38:30 by james]
james
parents: 2001
diff changeset
1310 if (*p == '+')
a9cdbfb4716e [xemacs-hg @ 2004-04-13 15:38:30 by james]
james
parents: 2001
diff changeset
1311 p++;
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1312 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
1313 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
1314 return make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1315 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1316 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1317 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1318
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1319 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1320 if (qxestrchr (p, '/') != NULL)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1321 {
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1322 /* 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
1323 limitations:
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1324 - 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
1325 ratio argument untouched.
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1326 - 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
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 - 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
1329 the string, but leaves the denominator unchanged.
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1330 - 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
1331 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
1332
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1333 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
1334 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
1335 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
1336 #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
1337 Ibyte *end, save;
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1338
2010
a9cdbfb4716e [xemacs-hg @ 2004-04-13 15:38:30 by james]
james
parents: 2001
diff changeset
1339 if (*p == '+')
a9cdbfb4716e [xemacs-hg @ 2004-04-13 15:38:30 by james]
james
parents: 2001
diff changeset
1340 p++;
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1341
2014
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1342 end = p;
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1343 if (*end == '-')
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1344 end++;
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1345 while ((*end >= '0' && *end <= '9') ||
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1346 (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
1347 (b > 10 && *end >= 'A' && *end <= 'A' + b - 11))
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1348 end++;
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1349 if (*end == '/')
2014
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1350 {
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1351 end++;
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1352 if (*end == '-')
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 while ((*end >= '0' && *end <= '9') ||
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1355 (b > 10 && *end >= 'a' && *end <= 'a' + b - 11) ||
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1356 (b > 10 && *end >= 'A' && *end <= 'A' + b - 11))
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1357 end++;
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1358 }
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1359 save = *end;
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1360 *end = '\0';
1995
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1994
diff changeset
1361 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
1362 *end = save;
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1363 ratio_canonicalize (scratch_ratio);
5903
5afddd952c46 Return ratios in canonical form too, #'string-to-number
Aidan Kehoe <kehoea@parhasard.net>
parents: 5886
diff changeset
1364 return Fcanonicalize_number (make_ratio_rt (scratch_ratio));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1365 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1366 #endif /* HAVE_RATIO */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1367
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1368 #ifdef HAVE_BIGNUM
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1369 {
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1370 /* 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
1371 limitations:
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1372 - 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
1373 bignum argument untouched.
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1374 - 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
1375 - 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
1376
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1377 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
1378 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
1379 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
1380 Ibyte *end, save;
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1381 Lisp_Object retval;
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1382
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1383 if (*p == '+')
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1384 p++;
2014
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1385 end = p;
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1386 if (*end == '-')
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1387 end++;
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1388 while ((*end >= '0' && *end <= '9') ||
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1389 (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
1390 (b > 10 && *end >= 'A' && *end <= 'A' + b - 11))
92f7301e4a23 [xemacs-hg @ 2004-04-15 15:27:34 by james]
james
parents: 2013
diff changeset
1391 end++;
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1392 save = *end;
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1393 *end = '\0';
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1394 if (*p == '\0')
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
1395 retval = make_fixnum (0);
2013
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1396 else
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1397 {
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1398 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
1399 retval = Fcanonicalize_number (make_bignum_bg (scratch_bignum));
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1400 }
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1401 *end = save;
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1402 return retval;
f2fdfc131770 [xemacs-hg @ 2004-04-14 22:50:52 by james]
james
parents: 2010
diff changeset
1403 }
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1404 #else
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 if (b == 10)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 /* Use the system-provided functions for base 10. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408 #if SIZEOF_EMACS_INT == SIZEOF_INT
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
1409 return make_fixnum (atoi ((char*) p));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 #elif SIZEOF_EMACS_INT == SIZEOF_LONG
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
1411 return make_fixnum (atol ((char*) p));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412 #elif SIZEOF_EMACS_INT == SIZEOF_LONG_LONG
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
1413 return make_fixnum (atoll ((char*) p));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1418 int negative = 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 EMACS_INT v = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421 if (*p == '-')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 negative = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 else if (*p == '+')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1430 int digit = digit_to_number (*p++, b);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 if (digit < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 v = v * b + digit;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 }
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
1435 return make_fixnum (negative * v);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 }
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
1437 #endif /* HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438 }
5864
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1439
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1440 static int
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1441 find_highest_value (struct chartab_range * range, Lisp_Object UNUSED (table),
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1442 Lisp_Object val, void *extra_arg)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1443 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1444 Lisp_Object *highest_pointer = (Lisp_Object *) extra_arg;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1445 Lisp_Object max_seen = *highest_pointer;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1446
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1447 CHECK_FIXNUM (val);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1448 if (range->type != CHARTAB_RANGE_CHAR)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1449 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1450 invalid_argument ("Not an appropriate char table range", Qunbound);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1451 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1452
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1453 if (XFIXNUM (max_seen) < XFIXNUM (val))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1454 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1455 *highest_pointer = val;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1456 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1457
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1458 return 0;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1459 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1460
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1461 static int
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1462 fill_ichar_array (struct chartab_range *range, Lisp_Object UNUSED (table),
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1463 Lisp_Object val, void *extra_arg)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1464 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1465 Ichar *cctable = (Ichar *) extra_arg;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1466 EMACS_INT valint = XFIXNUM (val);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1467
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1468 /* Save the value if it hasn't been seen yet. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1469 if (-1 == cctable[valint])
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1470 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1471 cctable[valint] = range->ch;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1472 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1473 else
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1474 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1475 /* Otherwise, save it if the existing value is not uppercase, and this
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1476 one is. Use the standard case table rather than any buffer-specific
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1477 one because a) this can be called early before current_buffer is
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1478 available and b) it's better to have these independent of particular
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1479 buffer case tables. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1480 if (current_buffer != NULL && UPCASE (0, range->ch) == range->ch
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1481 && UPCASE (0, cctable[valint]) != cctable[valint])
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1482 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1483 cctable[valint] = range->ch;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1484 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1485 /* Maybe our own case infrastructure is not available yet. Use the C
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1486 library's. */
5870
df50aaeddca5 Don't tickle an unreasonable but standard C lib limitation, thank you Vin!
Aidan Kehoe <kehoea@parhasard.net>
parents: 5867
diff changeset
1487 else if (current_buffer == NULL)
5864
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1488 {
5870
df50aaeddca5 Don't tickle an unreasonable but standard C lib limitation, thank you Vin!
Aidan Kehoe <kehoea@parhasard.net>
parents: 5867
diff changeset
1489 /* The C library can't necessarily handle values outside of
df50aaeddca5 Don't tickle an unreasonable but standard C lib limitation, thank you Vin!
Aidan Kehoe <kehoea@parhasard.net>
parents: 5867
diff changeset
1490 the range EOF to CHAR_MAX, inclusive. */
df50aaeddca5 Don't tickle an unreasonable but standard C lib limitation, thank you Vin!
Aidan Kehoe <kehoea@parhasard.net>
parents: 5867
diff changeset
1491 assert (range->ch == EOF || range->ch <= CHAR_MAX);
df50aaeddca5 Don't tickle an unreasonable but standard C lib limitation, thank you Vin!
Aidan Kehoe <kehoea@parhasard.net>
parents: 5867
diff changeset
1492 if (isupper (range->ch) && !isupper (cctable[valint]))
df50aaeddca5 Don't tickle an unreasonable but standard C lib limitation, thank you Vin!
Aidan Kehoe <kehoea@parhasard.net>
parents: 5867
diff changeset
1493 {
df50aaeddca5 Don't tickle an unreasonable but standard C lib limitation, thank you Vin!
Aidan Kehoe <kehoea@parhasard.net>
parents: 5867
diff changeset
1494 cctable[valint] = range->ch;
df50aaeddca5 Don't tickle an unreasonable but standard C lib limitation, thank you Vin!
Aidan Kehoe <kehoea@parhasard.net>
parents: 5867
diff changeset
1495 }
5864
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1496 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1497 /* Otherwise, save it if this character has a numerically lower value
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1498 (preferring ASCII over fullwidth Chinese and so on). */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1499 else if (range->ch < cctable[valint])
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1500 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1501 cctable[valint] = range->ch;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1502 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1503 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1504
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1505 return 0;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1506 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1507
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1508 static Lisp_Object
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1509 build_fixnum_to_char_map (Lisp_Object radix_table)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1510 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1511 Lisp_Object highest_value, result;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1512 struct chartab_range ctr = { CHARTAB_RANGE_ALL, 0, Qnil, 0 };
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1513 Ichar *cctable;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1514 EMACS_INT ii, cclen;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1515 Ibyte *data;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1516
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1517 /* What's the greatest fixnum value seen? In passing, check all the char
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1518 table values are fixnums. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1519 CHECK_FIXNUM (XCHAR_TABLE (radix_table)->default_);
5873
5a311f1f46aa Don't extract a fixnum value unnecessarily, thank you Robert Delius Royar
Aidan Kehoe <kehoea@parhasard.net>
parents: 5871
diff changeset
1520 highest_value = XCHAR_TABLE (radix_table)->default_;
5a311f1f46aa Don't extract a fixnum value unnecessarily, thank you Robert Delius Royar
Aidan Kehoe <kehoea@parhasard.net>
parents: 5871
diff changeset
1521
5864
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1522 map_char_table (radix_table, &ctr, find_highest_value, &highest_value);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1523 cclen = XFIXNUM (highest_value) + 1;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1524
5876
0cebf04c18b5 Use cast for malloc call to satisfy VS6
Vin Shelton <acs@xemacs.org>
parents: 5873
diff changeset
1525 cctable = (Ichar *)malloc (sizeof (Ichar) * cclen);
5864
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1526 if (cctable == NULL)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1527 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1528 out_of_memory ("Could not allocate data for `digit-char'", Qunbound);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1529 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1530
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1531 for (ii = 0; ii < cclen; ++ii)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1532 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1533 cctable[ii] = (Ichar) -1;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1534 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1535
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1536 map_char_table (radix_table, &ctr, fill_ichar_array, cctable);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1537
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1538 for (ii = 0; ii < cclen; ++ii)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1539 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1540 if (cctable[ii] < 0)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1541 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1542 free (cctable);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1543 invalid_argument ("No digit specified for weight", make_fixnum (ii));
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1544 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1545 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1546
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1547 result = Fmake_string (make_fixnum (cclen * MAX_ICHAR_LEN), make_char (0));
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1548
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1549 data = XSTRING_DATA (result);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1550 for (ii = 0; ii < cclen; ii++)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1551 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1552 set_itext_ichar (data + (MAX_ICHAR_LEN * ii), cctable[ii]);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1553 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1554
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1555 init_string_ascii_begin (result);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1556 bump_string_modiff (result);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1557 sledgehammer_check_ascii_begin (result);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1558
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1559 free (cctable);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1560
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1561 return result;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1562 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1563
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1564 DEFUN ("set-digit-fixnum-map", Fset_digit_fixnum_map, 1, 1, 0, /*
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1565 Set the value of `digit-fixnum-map', which see.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1566
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1567 Also check that RADIX-TABLE is well-formed from the perspective of
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1568 `parse-integer' and `digit-char-p', and create an internal inverse mapping
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1569 for `digit-char', so that all three functions behave consistently.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1570
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1571 RADIX-TABLE itself is not saved, a read-only copy of it is made and returned.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1572 */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1573 (radix_table))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1574 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1575 Lisp_Object ftctable = Qnil;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1576
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1577 CHECK_CHAR_TABLE (radix_table);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1578
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1579 /* Create a table for `digit-char', checking the consistency of
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1580 radix_table while doing so. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1581 ftctable = build_fixnum_to_char_map (radix_table);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1582
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1583 Vdigit_fixnum_map = Fcopy_char_table (radix_table);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1584 LISP_READONLY (Vdigit_fixnum_map) = 1;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1585 Vfixnum_to_char_map = ftctable;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1586
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1587 return Vdigit_fixnum_map;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1588 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1589
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1590 DEFUN ("digit-char-p", Fdigit_char_p, 1, 3, 0, /*
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1591 Return non-nil if CHARACTER represents a digit in base RADIX.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1592
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1593 RADIX defaults to ten. The actual non-nil value returned is the integer
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1594 value of the character in base RADIX.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1595
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1596 RADIX-TABLE, if non-nil, is a character table describing characters' numeric
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1597 values. See `parse-integer' and `digit-fixnum-map'.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1598 */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1599 (character, radix, radix_table))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1600 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1601 Lisp_Object got = Qnil;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1602 EMACS_INT radixing, val;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1603 Ichar cc;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1604
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1605 CHECK_CHAR (character);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1606 cc = XCHAR (character);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1607
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1608 if (!NILP (radix))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1609 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1610 check_integer_range (radix, Qzero,
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1611 NILP (radix_table) ?
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1612 /* If we are using the default radix table, the
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1613 maximum possible value for the radix is
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1614 available to us now. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1615 make_fixnum
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1616 (XSTRING_LENGTH (Vfixnum_to_char_map)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1617 / MAX_ICHAR_LEN)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1618 /* Otherwise, calculating that is expensive. Check
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1619 at least that the radix is not a bignum, the
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1620 maximum count of characters available will not
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1621 exceed the size of a fixnum. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1622 : make_fixnum (MOST_POSITIVE_FIXNUM));
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1623 radixing = XFIXNUM (radix);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1624 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1625 else
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1626 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1627 radixing = 10;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1628 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1629
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1630 if (NILP (radix_table))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1631 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1632 radix_table = Vdigit_fixnum_map;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1633 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1634
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1635 got = get_char_table (cc, radix_table);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1636 CHECK_FIXNUM (got);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1637 val = XFIXNUM (got);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1638
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1639 if (val < 0 || val >= radixing)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1640 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1641 return Qnil;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1642 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1643
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1644 return make_fixnum (val);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1645 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1646
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1647 DEFUN ("digit-char", Fdigit_char, 1, 3, 0, /*
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1648 Return a character representing the integer WEIGHT in base RADIX.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1649
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1650 RADIX defaults to ten. If no such character exists, return nil. `digit-char'
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1651 prefers an upper case character if available. RADIX must be a non-negative
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1652 integer of value less than the maximum value in RADIX-TABLE.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1653
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1654 RADIX-TABLE, if non-nil, is a character table describing characters' numeric
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1655 values. It defaults to the value of `digit-fixnum-map'; see the documentation
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1656 for that variable and for `parse-integer'. This is not specified by Common
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1657 Lisp, and using a value other than the default in `digit-char' is expensive,
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1658 since the inverse map needs to be calculated.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1659 */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1660 (weight, radix, radix_table))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1661 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1662 EMACS_INT radixing = 10, weighting;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1663 Lisp_Object fixnum_to_char_table = Qnil;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1664 Ichar cc;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1665
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1666 CHECK_NATNUM (weight);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1667
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1668 if (!NILP (radix_table) && !EQ (radix_table, Vdigit_fixnum_map))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1669 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1670 CHECK_CHAR_TABLE (radix_table);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1671 /* The result of this isn't GCPROd, but the rest of this function
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1672 won't GC and continue. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1673 fixnum_to_char_table = build_fixnum_to_char_map (radix_table);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1674 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1675 else
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1676 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1677 fixnum_to_char_table = Vfixnum_to_char_map;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1678 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1679
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1680 if (!NILP (radix))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1681 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1682 check_integer_range (radix, Qzero,
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1683 make_fixnum (XSTRING_LENGTH (fixnum_to_char_table)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1684 / MAX_ICHAR_LEN));
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1685 radixing = XFIXNUM (radix);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1686 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1687
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1688 /* If weight is in its canonical form (and there's no reason to think it
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1689 isn't), Vfixnum_to_char_map can't be long enough to handle
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1690 this. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1691 if (BIGNUMP (weight))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1692 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1693 return Qnil;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1694 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1695
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1696 weighting = XFIXNUM (weight);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1697
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1698 if (weighting < radixing)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1699 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1700 cc = itext_ichar (XSTRING_DATA (fixnum_to_char_table)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1701 + MAX_ICHAR_LEN * weighting);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1702 return make_char (cc);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1703 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1704
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1705 return Qnil;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1706 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1707
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1708 Lisp_Object
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1709 parse_integer (const Ibyte *buf, Ibyte **buf_end_out, Bytecount len,
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1710 EMACS_INT base, Boolint junk_allowed, Lisp_Object radix_table)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1711 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1712 const Ibyte *lim = buf + len, *p = buf;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1713 EMACS_UINT num = 0, onum = (EMACS_UINT) -1;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1714 EMACS_UINT fixnum_limit = MOST_POSITIVE_FIXNUM;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1715 EMACS_INT cint = 0;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1716 Boolint negativland = 0;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1717 Ichar c = -1;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1718 Lisp_Object result = Qnil, got = Qnil;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1719
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1720 if (NILP (radix_table))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1721 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1722 radix_table = Vdigit_fixnum_map;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1723 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1724
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1725 /* This function ignores the current buffer's syntax table.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1726 Respecting it will probably introduce more bugs than it fixes. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1727 update_mirror_syntax_if_dirty (XCHAR_TABLE (Vstandard_syntax_table)->
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1728 mirror_table);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1729
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1730 /* Ignore leading whitespace, if that leading whitespace has no
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1731 numeric value. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1732 while (p < lim)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1733 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1734 c = itext_ichar (p);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1735 if (!(((got = get_char_table (c, radix_table), FIXNUMP (got))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1736 && ((cint = XFIXNUM (got), cint < 0) || cint >= base))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1737 && (SYNTAX (XCHAR_TABLE (Vstandard_syntax_table)->mirror_table,
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1738 c) == Swhitespace)))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1739 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1740 break;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1741 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1742
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1743 INC_IBYTEPTR (p);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1744 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1745
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1746 /* Drop sign information if appropriate. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1747 if (c == '-')
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1748 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1749 negativland = 1;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1750 fixnum_limit = - MOST_NEGATIVE_FIXNUM;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1751 INC_IBYTEPTR (p);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1752 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1753 else if (c == '+')
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1754 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1755 got = get_char_table (c, radix_table);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1756 cint = FIXNUMP (got) ? XFIXNUM (got) : -1;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1757 /* If ?+ has no integer weight, drop it. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1758 if (cint < 0 || cint >= base)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1759 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1760 INC_IBYTEPTR (p);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1761 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1762 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1763
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1764 while (p < lim)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1765 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1766 c = itext_ichar (p);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1767
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1768 got = get_char_table (c, radix_table);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1769 if (!FIXNUMP (got))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1770 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1771 goto loser;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1772 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1773
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1774 cint = XFIXNUM (got);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1775
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1776 if (cint < 0 || cint >= base)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1777 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1778 goto loser;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1779 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1780
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1781 onum = num;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1782 num *= base;
5886
c96000075e49 Be more careful about C integer overflow, #'parse-integer.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5876
diff changeset
1783 if (num > fixnum_limit || num < onum)
5864
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1784 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1785 goto overflow;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1786 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1787
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1788 num += cint;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1789 if (num > fixnum_limit)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1790 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1791 goto overflow;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1792 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1793
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1794 INC_IBYTEPTR (p);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1795 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1796
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1797 if (onum == (EMACS_UINT) -1)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1798 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1799 /* No digits seen, we may need to error. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1800 goto loser;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1801 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1802
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1803 if (negativland)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1804 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1805 result = make_fixnum (- (EMACS_INT) num);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1806 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1807 else
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1808 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1809 result = make_fixnum (num);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1810 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1811
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1812 *buf_end_out = (Ibyte *) p;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1813 return result;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1814
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1815 overflow:
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1816 #ifndef HAVE_BIGNUM
5908
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5905
diff changeset
1817 return Fsignal (Qunsupported_type,
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5905
diff changeset
1818 list3 (build_ascstring ("bignum"), make_string (buf, len),
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5905
diff changeset
1819 make_fixnum (base)));
5864
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1820 #else /* HAVE_BIGNUM */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1821 result = make_bignum_emacs_uint (onum);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1822
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1823 bignum_set_emacs_int (scratch_bignum, base);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1824 bignum_set_emacs_int (scratch_bignum2, cint);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1825 bignum_mul (XBIGNUM_DATA (result), XBIGNUM_DATA (result), scratch_bignum);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1826 bignum_add (XBIGNUM_DATA (result), XBIGNUM_DATA (result), scratch_bignum2);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1827 INC_IBYTEPTR (p);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1828
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1829 assert (!bignum_fits_emacs_int_p (XBIGNUM_DATA (result))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1830 || (fixnum_limit
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1831 < (EMACS_UINT) bignum_to_emacs_int (XBIGNUM_DATA (result))));
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1832
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1833 while (p < lim)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1834 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1835 c = itext_ichar (p);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1836
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1837 got = get_char_table (c, radix_table);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1838 if (!FIXNUMP (got))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1839 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1840 goto loser;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1841 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1842
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1843 cint = XFIXNUM (got);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1844 if (cint < 0 || cint >= base)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1845 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1846 goto loser;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1847 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1848
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1849 bignum_set_emacs_int (scratch_bignum2, cint);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1850 bignum_mul (XBIGNUM_DATA (result), XBIGNUM_DATA (result),
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1851 scratch_bignum);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1852 bignum_add (XBIGNUM_DATA (result), XBIGNUM_DATA (result),
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1853 scratch_bignum2);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1854
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1855 INC_IBYTEPTR (p);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1856 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1857
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1858 if (negativland)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1859 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1860 bignum_set_long (scratch_bignum, -1L);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1861 bignum_mul (XBIGNUM_DATA (result), XBIGNUM_DATA (result),
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1862 scratch_bignum);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1863 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1864
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1865 *buf_end_out = (Ibyte *) p;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1866 return result;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1867 #endif /* HAVE_BIGNUM */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1868 loser:
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1869
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1870 if (p < lim && !junk_allowed)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1871 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1872 /* JUNK-ALLOWED is zero. If we have stopped parsing because we
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1873 encountered whitespace, then we need to check that the rest if the
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1874 string is whitespace and whitespace alone if we are not to error.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1875
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1876 Perhaps surprisingly, if JUNK-ALLOWED is zero, the parse is regarded
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1877 as including the trailing whitespace, so the second value returned is
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1878 always the length of the string. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1879 while (p < lim)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1880 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1881 c = itext_ichar (p);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1882 if (!(SYNTAX (XCHAR_TABLE (Vstandard_syntax_table)->mirror_table, c)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1883 == Swhitespace))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1884 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1885 break;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1886 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1887
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1888 INC_IBYTEPTR (p);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1889 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1890 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1891
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1892 *buf_end_out = (Ibyte *) p;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1893
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1894 if (junk_allowed || (p == lim && onum != (EMACS_UINT) -1))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1895 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1896
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1897 #ifdef HAVE_BIGNUM
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1898 if (!NILP (result))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1899 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1900 /* Bignum terminated by whitespace or by non-digit. */
5905
85fd1ab80057 Fix a bug in #'parse-integer with negative bignums and non-nil JUNK-ALLOWED
Aidan Kehoe <kehoea@parhasard.net>
parents: 5903
diff changeset
1901 if (negativland)
85fd1ab80057 Fix a bug in #'parse-integer with negative bignums and non-nil JUNK-ALLOWED
Aidan Kehoe <kehoea@parhasard.net>
parents: 5903
diff changeset
1902 {
85fd1ab80057 Fix a bug in #'parse-integer with negative bignums and non-nil JUNK-ALLOWED
Aidan Kehoe <kehoea@parhasard.net>
parents: 5903
diff changeset
1903 bignum_set_long (scratch_bignum, -1L);
85fd1ab80057 Fix a bug in #'parse-integer with negative bignums and non-nil JUNK-ALLOWED
Aidan Kehoe <kehoea@parhasard.net>
parents: 5903
diff changeset
1904 bignum_mul (XBIGNUM_DATA (result), XBIGNUM_DATA (result),
85fd1ab80057 Fix a bug in #'parse-integer with negative bignums and non-nil JUNK-ALLOWED
Aidan Kehoe <kehoea@parhasard.net>
parents: 5903
diff changeset
1905 scratch_bignum);
85fd1ab80057 Fix a bug in #'parse-integer with negative bignums and non-nil JUNK-ALLOWED
Aidan Kehoe <kehoea@parhasard.net>
parents: 5903
diff changeset
1906 }
85fd1ab80057 Fix a bug in #'parse-integer with negative bignums and non-nil JUNK-ALLOWED
Aidan Kehoe <kehoea@parhasard.net>
parents: 5903
diff changeset
1907 return result;
5864
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1908 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1909 #endif
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1910
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1911 if (onum == (EMACS_UINT) -1)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1912 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1913 /* No integer digits seen, but junk allowed, so no indication to
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1914 error. Return nil. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1915 return Qnil;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1916 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1917
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1918 if (negativland)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1919 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1920 assert ((- (EMACS_INT) num) >= MOST_NEGATIVE_FIXNUM);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1921 result = make_fixnum (- (EMACS_INT) num);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1922 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1923 else
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1924 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1925 assert ((EMACS_INT) num <= MOST_POSITIVE_FIXNUM);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1926 result = make_fixnum (num);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1927 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1928
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1929 return result;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1930 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1931
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1932 return Fsignal (Qinvalid_argument,
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1933 list3 (build_msg_string ("Invalid integer syntax"),
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1934 make_string (buf, len), make_fixnum (base)));
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1935 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1936
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1937 DEFUN ("parse-integer", Fparse_integer, 1, MANY, 0, /*
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1938 Parse and return the integer represented by STRING using RADIX.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1939
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1940 START and END are bounding index designators, as used in `remove*'. START
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1941 defaults to 0 and END defaults to nil, meaning the end of STRING.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1942
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1943 If JUNK-ALLOWED is nil, error if STRING does not consist in its entirety of
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1944 the representation of an integer, with or without surrounding whitespace
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1945 characters.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1946
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1947 If RADIX-TABLE is non-nil, it is a char table mapping from characters to
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1948 fixnums used with RADIX. Otherwise, `digit-fixnum-map' provides the
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1949 correspondence to use.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1950
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1951 RADIX must always be a non-negative fixnum. RADIX-TABLE constrains its
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1952 possible values further, and the maximum RADIX available is always the largest
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1953 positive value available RADIX-TABLE.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1954
5867
e0f1dfaa821e Add the non-ASCII digit support, now #'parse-integer can handle it.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5864
diff changeset
1955 If RADIX-TABLE (or `digit-fixnum-map') assigns a numeric value to `-', its
e0f1dfaa821e Add the non-ASCII digit support, now #'parse-integer can handle it.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5864
diff changeset
1956 digit value will be ignored if ?- is the first character in a string. The
e0f1dfaa821e Add the non-ASCII digit support, now #'parse-integer can handle it.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5864
diff changeset
1957 number will be treated as negative. To work around this, double it, or assign
e0f1dfaa821e Add the non-ASCII digit support, now #'parse-integer can handle it.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5864
diff changeset
1958 another character the value zero and prefix non-negative strings with that. A
e0f1dfaa821e Add the non-ASCII digit support, now #'parse-integer can handle it.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5864
diff changeset
1959 digit value for ?+ will be respected even if it is the first character in the
e0f1dfaa821e Add the non-ASCII digit support, now #'parse-integer can handle it.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5864
diff changeset
1960 representation of an integer.
e0f1dfaa821e Add the non-ASCII digit support, now #'parse-integer can handle it.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5864
diff changeset
1961
5864
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1962 arguments: (STRING &key (START 0) end (RADIX 10) junk-allowed radix-table)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1963 */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1964 (int nargs, Lisp_Object *args))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1965 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1966 Lisp_Object string = args[0], result;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1967 Charcount starting = 0, ending = MOST_POSITIVE_FIXNUM + 1, ii = 0;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1968 Bytecount byte_len;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1969 Ibyte *startp, *cursor, *end_read, *limit, *saved_start;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1970 EMACS_INT radixing;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1971
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1972 PARSE_KEYWORDS (Fparse_integer, nargs, args, 5,
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1973 (start, end, radix, junk_allowed, radix_table),
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1974 (start = Qzero, radix = make_fixnum (10)));
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1975
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1976 CHECK_STRING (string);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1977 CHECK_NATNUM (start);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1978 starting = BIGNUMP (start) ? 1 + MOST_POSITIVE_FIXNUM : XFIXNUM (start);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1979 if (!NILP (end))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1980 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1981 CHECK_NATNUM (end);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1982 ending = BIGNUMP (end) ? 1 + MOST_POSITIVE_FIXNUM : XFIXNUM (end);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1983 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1984
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1985 if (!NILP (radix_table))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1986 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1987 CHECK_CHAR_TABLE (radix_table);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1988 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1989 else
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1990 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1991 radix_table = Vdigit_fixnum_map;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1992 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1993
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1994 check_integer_range (radix, Qzero,
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1995 EQ (radix_table, Vdigit_fixnum_map) ?
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1996 make_fixnum (XSTRING_LENGTH (Vfixnum_to_char_map)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1997 / MAX_ICHAR_LEN)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1998 /* Non-default radix table; calculating the upper limit
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
1999 is is expensive. Check at least that the radix is
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2000 not a bignum, the maximum count of characters
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2001 available in our XEmacs will not exceed the size of
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2002 a fixnum. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2003 : make_fixnum (MOST_POSITIVE_FIXNUM));
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2004 radixing = XFIXNUM (radix);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2005
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2006 startp = cursor = saved_start = XSTRING_DATA (string);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2007 byte_len = XSTRING_LENGTH (string);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2008 limit = startp + byte_len;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2009
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2010 while (cursor < limit && ii < ending)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2011 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2012 INC_IBYTEPTR (cursor);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2013 if (ii < starting)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2014 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2015 startp = cursor;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2016 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2017 ii++;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2018 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2019
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2020 if (ii < starting || (ii < ending && !NILP (end)))
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2021 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2022 check_sequence_range (string, start, end, Flength (string));
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2023 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2024
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2025 result = parse_integer (startp, &end_read, cursor - startp, radixing,
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2026 !NILP (junk_allowed), radix_table);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2027
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2028 /* This code hasn't been written to handle relocating string data. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2029 assert (saved_start == XSTRING_DATA (string));
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2030
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2031 return values2 (result, make_fixnum (string_index_byte_to_char
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2032 (string, end_read - saved_start)));
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
2033 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2034
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2035 DEFUN ("+", Fplus, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2036 Return sum of any number of arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2037 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
2038
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2039 arguments: (&rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2042 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2043 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2044 REGISTER int i;
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2045 Lisp_Object accum = make_fixnum (0), addend;
1983
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 for (i = 0; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2048 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2049 addend = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2050 switch (promote_args (&accum, &addend))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2051 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2052 case FIXNUM_T:
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2053 accum = make_integer (XREALFIXNUM (accum) + XREALFIXNUM (addend));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2054 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2055 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2056 case BIGNUM_T:
5736
3192994c49ca Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents: 5582
diff changeset
2057 bignum_add (XBIGNUM_DATA (accum), XBIGNUM_DATA (accum),
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2058 XBIGNUM_DATA (addend));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2059 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2060 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2061 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2062 case RATIO_T:
5736
3192994c49ca Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents: 5582
diff changeset
2063 ratio_add (XRATIO_DATA (accum), XRATIO_DATA (accum),
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2064 XRATIO_DATA (addend));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2065 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2066 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2067 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2068 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
2069 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2070 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2071 case BIGFLOAT_T:
5736
3192994c49ca Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents: 5582
diff changeset
2072 bigfloat_set_prec (XBIGFLOAT_DATA (accum),
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2073 max (XBIGFLOAT_GET_PREC (addend),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2074 XBIGFLOAT_GET_PREC (accum)));
5736
3192994c49ca Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents: 5582
diff changeset
2075 bigfloat_add (XBIGFLOAT_DATA (accum), XBIGFLOAT_DATA (accum),
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2076 XBIGFLOAT_DATA (addend));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2077 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2078 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2079 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2080 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2081 return Fcanonicalize_number (accum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2082 #else /* !WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2083 EMACS_INT iaccum = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2084 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2085
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2086 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2087 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2088 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2089 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2090 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2091 iaccum += iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2092 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2093 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2094 double daccum = (double) iaccum + iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2095 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2096 daccum += number_char_or_marker_to_double (*args++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2097 return make_float (daccum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2098 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2099 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2100
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2101 return make_fixnum (iaccum);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2102 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2103 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2104
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2105 DEFUN ("-", Fminus, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2106 Negate number or subtract numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2107 With one arg, negates it. With more than one arg,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2108 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
2109
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2110 arguments: (FIRST &rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2111 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2112 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2113 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2114 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2115 REGISTER int i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2116 Lisp_Object accum = args[0], subtrahend;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2117
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2118 if (nargs == 1)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2119 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2120 if (CHARP (accum))
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2121 accum = make_fixnum (XCHAR (accum));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2122 else if (MARKERP (accum))
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2123 accum = make_fixnum (marker_position (accum));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2124
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2125 /* Invert the sign of accum */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2126 CHECK_NUMBER (accum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2127 switch (get_number_type (accum))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2128 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2129 case FIXNUM_T:
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2130 return make_integer (-XREALFIXNUM (accum));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2131 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2132 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2133 bignum_neg (scratch_bignum, XBIGNUM_DATA (accum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2134 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2135 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2136 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2137 case RATIO_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2138 ratio_neg (scratch_ratio, XRATIO_DATA (accum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2139 return make_ratio_rt (scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2140 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2141 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2142 return make_float (-XFLOAT_DATA (accum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2143 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2144 case BIGFLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2145 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
2146 bigfloat_neg (scratch_bigfloat, XBIGFLOAT_DATA (accum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2147 return make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2148 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2149 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2150 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2151 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2152 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2153 /* Subtrace the remaining arguments from accum */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2154 for (i = 1; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2155 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2156 subtrahend = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2157 switch (promote_args (&accum, &subtrahend))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2158 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2159 case FIXNUM_T:
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2160 accum = make_integer (XREALFIXNUM (accum) - XREALFIXNUM (subtrahend));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2161 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2162 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2163 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2164 bignum_sub (scratch_bignum, XBIGNUM_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2165 XBIGNUM_DATA (subtrahend));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2166 accum = make_bignum_bg (scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2167 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2168 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2169 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2170 case RATIO_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2171 ratio_sub (scratch_ratio, XRATIO_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2172 XRATIO_DATA (subtrahend));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2173 accum = make_ratio_rt (scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2174 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2175 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2176 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2177 accum =
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2178 make_float (XFLOAT_DATA (accum) - XFLOAT_DATA (subtrahend));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2179 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2180 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2181 case BIGFLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2182 bigfloat_set_prec (scratch_bigfloat,
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2183 max (XBIGFLOAT_GET_PREC (subtrahend),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2184 XBIGFLOAT_GET_PREC (accum)));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2185 bigfloat_sub (scratch_bigfloat, XBIGFLOAT_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2186 XBIGFLOAT_DATA (subtrahend));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2187 accum = make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2188 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2189 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2190 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2191 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2192 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2193 return Fcanonicalize_number (accum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2194 #else /* !WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2195 EMACS_INT iaccum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2196 double daccum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2198 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2200 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2201 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2202 iaccum = nargs > 1 ? iod.c.ival : - iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2203 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2204 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 daccum = nargs > 1 ? iod.c.dval : - iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2206 goto do_float;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2207 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2209 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2210 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2211 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2212 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2213 iaccum -= iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2214 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2215 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2216 daccum = (double) iaccum - iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2217 goto do_float;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2218 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2219 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2220
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2221 return make_fixnum (iaccum);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2223 do_float:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2224 for (; args < args_end; args++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2225 daccum -= number_char_or_marker_to_double (*args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2226 return make_float (daccum);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2227 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2228 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2230 DEFUN ("*", Ftimes, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2231 Return product of any number of arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2232 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
2233
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2234 arguments: (&rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2235 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2236 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2237 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2238 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2239 REGISTER int i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2240 /* Start with a bignum to avoid overflow */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2241 Lisp_Object accum = make_bignum (1L), multiplier;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2242
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2243 for (i = 0; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2244 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2245 multiplier = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2246 switch (promote_args (&accum, &multiplier))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2247 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2248 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2249 case BIGNUM_T:
5736
3192994c49ca Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents: 5582
diff changeset
2250 bignum_mul (XBIGNUM_DATA (accum), XBIGNUM_DATA (accum),
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2251 XBIGNUM_DATA (multiplier));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2252 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2253 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2254 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2255 case RATIO_T:
5736
3192994c49ca Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents: 5582
diff changeset
2256 ratio_mul (XRATIO_DATA (accum), XRATIO_DATA (accum),
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2257 XRATIO_DATA (multiplier));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2258 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2259 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2260 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2261 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
2262 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2263 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2264 case BIGFLOAT_T:
5736
3192994c49ca Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents: 5582
diff changeset
2265 bigfloat_set_prec (XBIGFLOAT_DATA (accum),
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2266 max (XBIGFLOAT_GET_PREC (multiplier),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2267 XBIGFLOAT_GET_PREC (accum)));
5736
3192994c49ca Convert C (un)signed long long values to bignums properly.
Jerry James <james@xemacs.org>
parents: 5582
diff changeset
2268 bigfloat_mul (XBIGFLOAT_DATA (accum), XBIGFLOAT_DATA (accum),
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2269 XBIGFLOAT_DATA (multiplier));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2270 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2271 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2272 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2273 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2274 return Fcanonicalize_number (accum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2275 #else /* !WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2276 EMACS_INT iaccum = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2277 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2279 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2280 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2281 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2282 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2283 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2284 iaccum *= iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2285 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2286 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2287 double daccum = (double) iaccum * iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2288 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2289 daccum *= number_char_or_marker_to_double (*args++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2290 return make_float (daccum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2291 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2292 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2294 return make_fixnum (iaccum);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2295 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2297
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2298 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2299 DEFUN ("div", Fdiv, 1, MANY, 0, /*
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2300 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
2301 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
2302 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
2303 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
2304
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2305 arguments: (FIRST &rest ARGS)
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2306 */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2307 (int nargs, Lisp_Object *args))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2308 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2309 REGISTER int i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2310 Lisp_Object accum, divisor;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2311
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2312 if (nargs == 1)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2313 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2314 i = 0;
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2315 accum = make_fixnum (1);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2316 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2317 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2318 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2319 i = 1;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2320 accum = args[0];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2321 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2322 for (; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2323 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2324 divisor = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2325 switch (promote_args (&accum, &divisor))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2326 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2327 case FIXNUM_T:
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2328 if (XREALFIXNUM (divisor) == 0) goto divide_by_zero;
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2329 bignum_set_long (scratch_bignum, XREALFIXNUM (accum));
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2330 bignum_set_long (scratch_bignum2, XREALFIXNUM (divisor));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2331 accum = make_ratio_bg (scratch_bignum, scratch_bignum2);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2332 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2333 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2334 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
2335 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
2336 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2337 case RATIO_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2338 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
2339 ratio_div (scratch_ratio, XRATIO_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2340 XRATIO_DATA (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2341 accum = make_ratio_rt (scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2342 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2343 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2344 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
2345 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
2346 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2347 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2348 case BIGFLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2349 if (bigfloat_sign (XBIGFLOAT_DATA (divisor)) == 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2350 goto divide_by_zero;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2351 bigfloat_set_prec (scratch_bigfloat,
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2352 max (XBIGFLOAT_GET_PREC (divisor),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2353 XBIGFLOAT_GET_PREC (accum)));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2354 bigfloat_div (scratch_bigfloat, XBIGFLOAT_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2355 XBIGFLOAT_DATA (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2356 accum = make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2357 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2358 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2359 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2360 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2361 return Fcanonicalize_number (accum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2362
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2363 divide_by_zero:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2364 Fsignal (Qarith_error, Qnil);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2365 return Qnil; /* not (usually) reached */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2366 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2367 #endif /* HAVE_RATIO */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2368
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2369 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
2370 Return FIRST divided by all the remaining arguments.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2371 The arguments must be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2372 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
2373
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2374 arguments: (FIRST &rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2375 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2376 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2377 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2378 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2379 REGISTER int i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2380 Lisp_Object accum, divisor;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2381
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2382 if (nargs == 1)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2383 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2384 i = 0;
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2385 accum = make_fixnum (1);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2386 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2387 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2388 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2389 i = 1;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2390 accum = args[0];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2391 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2392 for (; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2393 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2394 divisor = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2395 switch (promote_args (&accum, &divisor))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2396 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2397 case FIXNUM_T:
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2398 if (XREALFIXNUM (divisor) == 0) goto divide_by_zero;
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2399 accum = make_integer (XREALFIXNUM (accum) / XREALFIXNUM (divisor));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2400 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2401 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2402 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2403 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
2404 bignum_div (scratch_bignum, XBIGNUM_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2405 XBIGNUM_DATA (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2406 accum = make_bignum_bg (scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2407 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2408 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2409 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2410 case RATIO_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2411 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
2412 ratio_div (scratch_ratio, XRATIO_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2413 XRATIO_DATA (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2414 accum = make_ratio_rt (scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2415 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2416 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2417 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2418 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
2419 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
2420 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2421 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2422 case BIGFLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2423 if (bigfloat_sign (XBIGFLOAT_DATA (divisor)) == 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2424 goto divide_by_zero;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2425 bigfloat_set_prec (scratch_bigfloat,
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2426 max (XBIGFLOAT_GET_PREC (divisor),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2427 XBIGFLOAT_GET_PREC (accum)));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2428 bigfloat_div (scratch_bigfloat, XBIGFLOAT_DATA (accum),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2429 XBIGFLOAT_DATA (divisor));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2430 accum = make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2431 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2432 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2433 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2434 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2435 return Fcanonicalize_number (accum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2436 #else /* !WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2437 EMACS_INT iaccum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2438 double daccum;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2439 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2440 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2441
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2442 if (nargs == 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2443 iaccum = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2444 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2445 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2446 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2447 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2448 iaccum = iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2449 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2450 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2451 daccum = iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2452 goto divide_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2453 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2454 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2456 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2457 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2458 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2459 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2460 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2461 if (iod.c.ival == 0) goto divide_by_zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2462 iaccum /= iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2463 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2464 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2465 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2466 if (iod.c.dval == 0) goto divide_by_zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2467 daccum = (double) iaccum / iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2468 goto divide_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2469 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2470 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2471
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2472 return make_fixnum (iaccum);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2473
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2474 divide_floats:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2475 for (; args < args_end; args++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2476 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2477 double dval = number_char_or_marker_to_double (*args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2478 if (dval == 0) goto divide_by_zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2479 daccum /= dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2480 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2481 return make_float (daccum);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2482 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2483
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2484 divide_by_zero:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2485 Fsignal (Qarith_error, Qnil);
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 800
diff changeset
2486 return Qnil; /* not (usually) reached */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2487 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2489 DEFUN ("max", Fmax, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2490 Return largest of all the arguments.
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2491 All arguments must be real numbers, characters or markers.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2492 The value is always a number; markers and characters are converted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2493 to numbers.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2494
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2495 arguments: (FIRST &rest ARGS)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2496 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2497 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2498 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2499 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2500 REGISTER int i, maxindex = 0;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2501
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2502 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
2503 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
2504 if (CHARP (args[0]))
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2505 args[0] = make_fixnum (XCHAR (args[0]));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2506 else if (MARKERP (args[0]))
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2507 args[0] = make_fixnum (marker_position (args[0]));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2508 for (i = 1; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2509 {
5768
3bfcdeb65578 Return a fixnum as documented with marker arg, #'max, #'min
Aidan Kehoe <kehoea@parhasard.net>
parents: 5762
diff changeset
2510 switch (promote_args (args + maxindex, args + i))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2511 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2512 case FIXNUM_T:
5768
3bfcdeb65578 Return a fixnum as documented with marker arg, #'max, #'min
Aidan Kehoe <kehoea@parhasard.net>
parents: 5762
diff changeset
2513 if (XREALFIXNUM (args[maxindex]) < XREALFIXNUM (args[i]))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2514 maxindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2515 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2516 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2517 case BIGNUM_T:
5768
3bfcdeb65578 Return a fixnum as documented with marker arg, #'max, #'min
Aidan Kehoe <kehoea@parhasard.net>
parents: 5762
diff changeset
2518 if (bignum_lt (XBIGNUM_DATA (args[maxindex]),
3bfcdeb65578 Return a fixnum as documented with marker arg, #'max, #'min
Aidan Kehoe <kehoea@parhasard.net>
parents: 5762
diff changeset
2519 XBIGNUM_DATA (args[i])))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2520 maxindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2521 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2522 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2523 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2524 case RATIO_T:
5768
3bfcdeb65578 Return a fixnum as documented with marker arg, #'max, #'min
Aidan Kehoe <kehoea@parhasard.net>
parents: 5762
diff changeset
2525 if (ratio_lt (XRATIO_DATA (args[maxindex]), XRATIO_DATA (args[i])))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2526 maxindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2527 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2528 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2529 case FLOAT_T:
5768
3bfcdeb65578 Return a fixnum as documented with marker arg, #'max, #'min
Aidan Kehoe <kehoea@parhasard.net>
parents: 5762
diff changeset
2530 if (XFLOAT_DATA (args[maxindex]) < XFLOAT_DATA (args[i]))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2531 maxindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2532 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2533 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2534 case BIGFLOAT_T:
5768
3bfcdeb65578 Return a fixnum as documented with marker arg, #'max, #'min
Aidan Kehoe <kehoea@parhasard.net>
parents: 5762
diff changeset
2535 if (bigfloat_lt (XBIGFLOAT_DATA (args[maxindex]),
3bfcdeb65578 Return a fixnum as documented with marker arg, #'max, #'min
Aidan Kehoe <kehoea@parhasard.net>
parents: 5762
diff changeset
2536 XBIGFLOAT_DATA (args[i])))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2537 maxindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2538 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2539 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2540 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2541 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2542 return args[maxindex];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2543 #else /* !WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2544 EMACS_INT imax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2545 double dmax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2546 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2547 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2548
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2549 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2550 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2551 imax = iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2552 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2553 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2554 dmax = iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2555 goto max_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2556 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2557
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2558 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2559 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2560 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2561 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2562 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2563 if (imax < iod.c.ival) imax = iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2564 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2565 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2566 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2567 dmax = (double) imax;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2568 if (dmax < iod.c.dval) dmax = iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2569 goto max_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2570 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2571 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2572
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2573 return make_fixnum (imax);
428
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 max_floats:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2576 while (args < args_end)
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 double dval = number_char_or_marker_to_double (*args++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2579 if (dmax < dval) dmax = dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2580 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2581 return make_float (dmax);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2582 #endif /* WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2583 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2584
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2585 DEFUN ("min", Fmin, 1, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2586 Return smallest of all the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2587 All arguments must be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2588 The value is always a number; markers and characters are converted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2589 to numbers.
4693
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2590
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2591 arguments: (FIRST &rest ARGS)
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 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2594 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2595 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2596 REGISTER int i, minindex = 0;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2597
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2598 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
2599 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
2600 if (CHARP (args[0]))
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2601 args[0] = make_fixnum (XCHAR (args[0]));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2602 else if (MARKERP (args[0]))
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2603 args[0] = make_fixnum (marker_position (args[0]));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2604 for (i = 1; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2605 {
5768
3bfcdeb65578 Return a fixnum as documented with marker arg, #'max, #'min
Aidan Kehoe <kehoea@parhasard.net>
parents: 5762
diff changeset
2606 switch (promote_args (args + minindex, args + i))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2607 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2608 case FIXNUM_T:
5768
3bfcdeb65578 Return a fixnum as documented with marker arg, #'max, #'min
Aidan Kehoe <kehoea@parhasard.net>
parents: 5762
diff changeset
2609 if (XREALFIXNUM (args[minindex]) > XREALFIXNUM (args[i]))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2610 minindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2611 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2612 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2613 case BIGNUM_T:
5768
3bfcdeb65578 Return a fixnum as documented with marker arg, #'max, #'min
Aidan Kehoe <kehoea@parhasard.net>
parents: 5762
diff changeset
2614 if (bignum_gt (XBIGNUM_DATA (args[minindex]),
3bfcdeb65578 Return a fixnum as documented with marker arg, #'max, #'min
Aidan Kehoe <kehoea@parhasard.net>
parents: 5762
diff changeset
2615 XBIGNUM_DATA (args[i])))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2616 minindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2617 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2618 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2619 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2620 case RATIO_T:
5768
3bfcdeb65578 Return a fixnum as documented with marker arg, #'max, #'min
Aidan Kehoe <kehoea@parhasard.net>
parents: 5762
diff changeset
2621 if (ratio_gt (XRATIO_DATA (args[minindex]),
3bfcdeb65578 Return a fixnum as documented with marker arg, #'max, #'min
Aidan Kehoe <kehoea@parhasard.net>
parents: 5762
diff changeset
2622 XRATIO_DATA (args[i])))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2623 minindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2624 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2625 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2626 case FLOAT_T:
5768
3bfcdeb65578 Return a fixnum as documented with marker arg, #'max, #'min
Aidan Kehoe <kehoea@parhasard.net>
parents: 5762
diff changeset
2627 if (XFLOAT_DATA (args[minindex]) > XFLOAT_DATA (args[i]))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2628 minindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2629 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2630 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2631 case BIGFLOAT_T:
5768
3bfcdeb65578 Return a fixnum as documented with marker arg, #'max, #'min
Aidan Kehoe <kehoea@parhasard.net>
parents: 5762
diff changeset
2632 if (bigfloat_gt (XBIGFLOAT_DATA (args[minindex]),
3bfcdeb65578 Return a fixnum as documented with marker arg, #'max, #'min
Aidan Kehoe <kehoea@parhasard.net>
parents: 5762
diff changeset
2633 XBIGFLOAT_DATA (args[i])))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2634 minindex = i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2635 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2636 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2637 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2638 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2639 return args[minindex];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2640 #else /* !WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641 EMACS_INT imin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2642 double dmin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2644 int_or_double iod;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2645
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2646 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2647 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2648 imin = iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2649 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2650 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2651 dmin = iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2652 goto min_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2653 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2654
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2655 while (args < args_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2656 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2657 number_char_or_marker_to_int_or_double (*args++, &iod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2658 if (iod.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2659 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2660 if (imin > iod.c.ival) imin = iod.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2661 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2662 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2663 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2664 dmin = (double) imin;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2665 if (dmin > iod.c.dval) dmin = iod.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2666 goto min_floats;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2667 }
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
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2670 return make_fixnum (imin);
428
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 min_floats:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2673 while (args < args_end)
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 double dval = number_char_or_marker_to_double (*args++);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2676 if (dmin > dval) dmin = dval;
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 return make_float (dmin);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2679 #endif /* WITH_NUMBER_TYPES */
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2682 DEFUN ("logand", Flogand, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2683 Return bitwise-and of all the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2684 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
2685
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2686 arguments: (&rest ARGS)
428
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 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2689 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2690 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2691 REGISTER int i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2692 Lisp_Object result, other;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2693
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2694 if (nargs == 0)
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2695 return make_fixnum (~0);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2696
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2697 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
2698 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
2699
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2700 result = args[0];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2701 if (CHARP (result))
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2702 result = make_fixnum (XCHAR (result));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2703 else if (MARKERP (result))
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2704 result = make_fixnum (marker_position (result));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2705 for (i = 1; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2706 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2707 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
2708 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
2709 other = args[i];
1995
4e6a63799f08 [xemacs-hg @ 2004-04-07 03:48:58 by james]
james
parents: 1994
diff changeset
2710 switch (promote_args (&result, &other))
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2711 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2712 case FIXNUM_T:
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2713 result = make_fixnum (XREALFIXNUM (result) & XREALFIXNUM (other));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2714 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2715 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2716 bignum_and (scratch_bignum, XBIGNUM_DATA (result),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2717 XBIGNUM_DATA (other));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2718 result = make_bignum_bg (scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2719 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2720 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2721 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2722 return Fcanonicalize_number (result);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2723 #else /* !HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2724 EMACS_INT bits = ~0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2725 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2726
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2727 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
2728 bits &= fixnum_char_or_marker_to_int (*args++);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2729
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2730 return make_fixnum (bits);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2731 #endif /* HAVE_BIGNUM */
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2734 DEFUN ("logior", Flogior, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2735 Return bitwise-or of all the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2736 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
2737
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2738 arguments: (&rest ARGS)
428
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 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2741 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2742 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2743 REGISTER int i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2744 Lisp_Object result, other;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2745
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2746 if (nargs == 0)
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2747 return make_fixnum (0);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2748
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2749 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
2750 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
2751
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2752 result = args[0];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2753 if (CHARP (result))
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2754 result = make_fixnum (XCHAR (result));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2755 else if (MARKERP (result))
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2756 result = make_fixnum (marker_position (result));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2757 for (i = 1; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2758 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2759 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
2760 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
2761 other = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2762 switch (promote_args (&result, &other))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2763 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2764 case FIXNUM_T:
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2765 result = make_fixnum (XREALFIXNUM (result) | XREALFIXNUM (other));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2766 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2767 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2768 bignum_ior (scratch_bignum, XBIGNUM_DATA (result),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2769 XBIGNUM_DATA (other));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2770 result = make_bignum_bg (scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2771 break;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2772 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2773 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2774 return Fcanonicalize_number (result);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2775 #else /* !HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2776 EMACS_INT bits = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2777 Lisp_Object *args_end = args + nargs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2778
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2779 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
2780 bits |= fixnum_char_or_marker_to_int (*args++);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2781
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2782 return make_fixnum (bits);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2783 #endif /* HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2784 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2785
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2786 DEFUN ("logxor", Flogxor, 0, MANY, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2787 Return bitwise-exclusive-or of all the arguments.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2788 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
2789
80cd90837ac5 Add argument information to remaining MANY or UNEVALLED C subrs.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3355
diff changeset
2790 arguments: (&rest ARGS)
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 (int nargs, Lisp_Object *args))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2793 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2794 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2795 REGISTER int i;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2796 Lisp_Object result, other;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2797
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2798 if (nargs == 0)
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2799 return make_fixnum (0);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2800
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2801 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
2802 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
2803
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2804 result = args[0];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2805 if (CHARP (result))
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2806 result = make_fixnum (XCHAR (result));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2807 else if (MARKERP (result))
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2808 result = make_fixnum (marker_position (result));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2809 for (i = 1; i < nargs; i++)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2810 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2811 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
2812 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
2813 other = args[i];
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2814 if (promote_args (&result, &other) == FIXNUM_T)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2815 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2816 result = make_fixnum (XREALFIXNUM (result) ^ XREALFIXNUM (other));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2817 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2818 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2819 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2820 bignum_xor (scratch_bignum, XBIGNUM_DATA (result),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2821 XBIGNUM_DATA (other));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2822 result = make_bignum_bg (scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2823 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2824 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2825 return Fcanonicalize_number (result);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2826 #else /* !HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2827 EMACS_INT bits = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2828 Lisp_Object *args_end = args + nargs;
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 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
2831 bits ^= fixnum_char_or_marker_to_int (*args++);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2832
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2833 return make_fixnum (bits);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2834 #endif /* !HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2835 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2836
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2837 DEFUN ("lognot", Flognot, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2838 Return the bitwise complement of NUMBER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2839 NUMBER may be an integer, marker or character converted to integer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2840 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2841 (number))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2842 {
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
2843 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
2844 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
2845
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2846 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2847 if (BIGNUMP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2848 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2849 bignum_not (scratch_bignum, XBIGNUM_DATA (number));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2850 return make_bignum_bg (scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2851 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2852 #endif /* HAVE_BIGNUM */
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
2853
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2854 return make_fixnum (~ fixnum_char_or_marker_to_int (number));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2855 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2856
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2857 DEFUN ("%", Frem, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2858 Return remainder of first arg divided by second.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2859 Both must be integers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2860 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2861 (number1, number2))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2862 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2863 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2864 while (!(CHARP (number1) || MARKERP (number1) || INTEGERP (number1)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2865 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
2866 while (!(CHARP (number2) || MARKERP (number2) || INTEGERP (number2)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2867 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
2868
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2869 if (promote_args (&number1, &number2) == FIXNUM_T)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2870 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2871 if (XREALFIXNUM (number2) == 0)
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2872 Fsignal (Qarith_error, Qnil);
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2873 return make_fixnum (XREALFIXNUM (number1) % XREALFIXNUM (number2));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2874 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2875 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2876 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2877 if (bignum_sign (XBIGNUM_DATA (number2)) == 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2878 Fsignal (Qarith_error, Qnil);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2879 bignum_mod (scratch_bignum, XBIGNUM_DATA (number1),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2880 XBIGNUM_DATA (number2));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2881 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2882 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2883 #else /* !HAVE_BIGNUM */
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
2884 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
2885 EMACS_INT ival2 = fixnum_char_or_marker_to_int (number2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2886
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2887 if (ival2 == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2888 Fsignal (Qarith_error, Qnil);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2889
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2890 return make_fixnum (ival1 % ival2);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2891 #endif /* HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2892 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2893
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2894 /* Note, ANSI *requires* the presence of the fmod() library routine.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2895 If your system doesn't have it, complain to your vendor, because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2896 that is a bug. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2897
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2898 #ifndef HAVE_FMOD
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2899 double
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2900 fmod (double f1, double f2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2901 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2902 if (f2 < 0.0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2903 f2 = -f2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2904 return f1 - f2 * floor (f1/f2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2905 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2906 #endif /* ! HAVE_FMOD */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2907
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2908
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2909 DEFUN ("mod", Fmod, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2910 Return X modulo Y.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2911 The result falls between zero (inclusive) and Y (exclusive).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2912 Both X and Y must be numbers, characters or markers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2913 If either argument is a float, a float will be returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2915 (x, y))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2916 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2917 #ifdef WITH_NUMBER_TYPES
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2918 while (!(CHARP (x) || MARKERP (x) || REALP (x)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2919 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
2920 while (!(CHARP (y) || MARKERP (y) || REALP (y)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2921 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
2922 switch (promote_args (&x, &y))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2923 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2924 case FIXNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2925 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2926 EMACS_INT ival;
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2927 if (XREALFIXNUM (y) == 0) goto divide_by_zero;
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2928 ival = XREALFIXNUM (x) % XREALFIXNUM (y);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2929 /* If the "remainder" comes out with the wrong sign, fix it. */
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2930 if (XREALFIXNUM (y) < 0 ? ival > 0 : ival < 0)
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2931 ival += XREALFIXNUM (y);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
2932 return make_fixnum (ival);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2933 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2934 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2935 case BIGNUM_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2936 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
2937 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
2938 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2939 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2940 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2941 case RATIO_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2942 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
2943 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
2944 bignum_div (scratch_bignum, ratio_numerator (scratch_ratio),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2945 ratio_denominator (scratch_ratio));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2946 ratio_set_bignum (scratch_ratio, scratch_bignum);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2947 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
2948 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
2949 return Fcanonicalize_number (make_ratio_rt (scratch_ratio));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2950 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2951 case FLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2952 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2953 double dval;
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2954 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
2955 dval = fmod (XFLOAT_DATA (x), XFLOAT_DATA (y));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2956 /* 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
2957 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
2958 dval += XFLOAT_DATA (y);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2959 return make_float (dval);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2960 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2961 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2962 case BIGFLOAT_T:
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2963 bigfloat_set_prec (scratch_bigfloat,
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2964 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
2965 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
2966 bigfloat_trunc (scratch_bigfloat, scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2967 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
2968 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
2969 return make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2970 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2971 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
2972 #else /* !WITH_NUMBER_TYPES */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2973 int_or_double iod1, iod2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2974 number_char_or_marker_to_int_or_double (x, &iod1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2975 number_char_or_marker_to_int_or_double (y, &iod2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2976
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977 if (!iod1.int_p || !iod2.int_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2978 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979 double dval1 = iod1.int_p ? (double) iod1.c.ival : iod1.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2980 double dval2 = iod2.int_p ? (double) iod2.c.ival : iod2.c.dval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2981 if (dval2 == 0) goto divide_by_zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982 dval1 = fmod (dval1, dval2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2983
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2984 /* If the "remainder" comes out with the wrong sign, fix it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2985 if (dval2 < 0 ? dval1 > 0 : dval1 < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2986 dval1 += dval2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2987
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2988 return make_float (dval1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989 }
1104
8b464283e891 [xemacs-hg @ 2002-11-12 18:58:13 by james]
james
parents: 993
diff changeset
2990
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2991 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2992 EMACS_INT ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2993 if (iod2.c.ival == 0) goto divide_by_zero;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2994
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2995 ival = iod1.c.ival % iod2.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2996
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2997 /* If the "remainder" comes out with the wrong sign, fix it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2998 if (iod2.c.ival < 0 ? ival > 0 : ival < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2999 ival += iod2.c.ival;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3000
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3001 return make_fixnum (ival);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002 }
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3003 #endif /* WITH_NUMBER_TYPES */
428
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 divide_by_zero:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3006 Fsignal (Qarith_error, Qnil);
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 800
diff changeset
3007 return Qnil; /* not (usually) reached */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3008 }
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 DEFUN ("ash", Fash, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3011 Return VALUE with its bits shifted left by COUNT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012 If COUNT is negative, shifting is actually to the right.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3013 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
3014 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
3015 to be duplicated. Use `lsh' instead.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3016 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3017 (value, count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3018 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3019 CHECK_FIXNUM_COERCE_CHAR (value);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3020 CONCHECK_FIXNUM (count);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3021
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3022 return make_fixnum (XFIXNUM (count) > 0 ?
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3023 XFIXNUM (value) << XFIXNUM (count) :
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3024 XFIXNUM (value) >> -XFIXNUM (count));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3025 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3026
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3027 DEFUN ("lsh", Flsh, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3028 Return VALUE with its bits shifted left by COUNT.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3029 If COUNT is negative, shifting is actually to the right.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3030 In this case, zeros are shifted in on the left.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3031 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3032 (value, count))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3033 {
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3034 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3035 while (!(CHARP (value) || MARKERP (value) || INTEGERP (value)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3036 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
3037 CONCHECK_INTEGER (count);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3038
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3039 if (promote_args (&value, &count) == FIXNUM_T)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3040 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3041 if (XREALFIXNUM (count) <= 0)
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3042 return make_fixnum (XREALFIXNUM (value) >> -XREALFIXNUM (count));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3043 /* Use bignums to avoid overflow */
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3044 bignum_set_long (scratch_bignum2, XREALFIXNUM (value));
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3045 bignum_lshift (scratch_bignum, scratch_bignum2, XREALFIXNUM (count));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3046 return Fcanonicalize_number (make_bignum_bg (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3047 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3048 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3049 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3050 if (bignum_sign (XBIGNUM_DATA (count)) <= 0)
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3051 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3052 bignum_neg (scratch_bignum, XBIGNUM_DATA (count));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3053 if (!bignum_fits_ulong_p (scratch_bignum))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3054 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
3055 bignum_rshift (scratch_bignum2, XBIGNUM_DATA (value),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3056 bignum_to_ulong (scratch_bignum));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3057 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3058 else
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3059 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3060 if (!bignum_fits_ulong_p (XBIGNUM_DATA (count)))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3061 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
3062 bignum_lshift (scratch_bignum2, XBIGNUM_DATA (value),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3063 bignum_to_ulong (XBIGNUM_DATA (count)));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3064 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3065 return Fcanonicalize_number (make_bignum_bg (scratch_bignum2));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3066 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3067 #else /* !HAVE_BIGNUM */
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3068 CHECK_FIXNUM_COERCE_CHAR (value);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3069 CONCHECK_FIXNUM (count);
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3070
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3071 return make_fixnum (XFIXNUM (count) > 0 ?
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3072 XUINT (value) << XFIXNUM (count) :
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3073 XUINT (value) >> -XFIXNUM (count));
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3074 #endif /* HAVE_BIGNUM */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3075 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3076
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3077 DEFUN ("1+", Fadd1, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3078 Return NUMBER plus one. NUMBER may be a number, character or marker.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3079 Markers and characters are converted to integers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3080 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3081 (number))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3082 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3083 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3084
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3085 if (FIXNUMP (number)) return make_integer (XFIXNUM (number) + 1);
5762
427a72c6ee17 Eliminate several compiler (clang) warnings.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5752
diff changeset
3086 if (CHARP (number)) return make_integer ((EMACS_INT) XCHAR (number) + 1);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3087 if (MARKERP (number)) return make_integer (marker_position (number) + 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3088 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
3089 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3090 if (BIGNUMP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3091 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3092 bignum_set_long (scratch_bignum, 1L);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3093 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
3094 return Fcanonicalize_number (make_bignum_bg (scratch_bignum2));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3095 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3096 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3097 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3098 if (RATIOP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3099 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3100 ratio_set_long (scratch_ratio, 1L);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3101 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
3102 /* No need to canonicalize after adding 1 */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3103 return make_ratio_rt (scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3104 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3105 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3106 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3107 if (BIGFLOATP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3108 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3109 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
3110 bigfloat_set_long (scratch_bigfloat, 1L);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3111 bigfloat_add (scratch_bigfloat, XBIGFLOAT_DATA (number),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3112 scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3113 return make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3114 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3115 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3117 number = wrong_type_argument (Qnumber_char_or_marker_p, number);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3118 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3119 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3121 DEFUN ("1-", Fsub1, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3122 Return NUMBER minus one. NUMBER may be a number, character or marker.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3123 Markers and characters are converted to integers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3124 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3125 (number))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3126 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3127 retry:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3128
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
3129 if (FIXNUMP (number)) return make_integer (XFIXNUM (number) - 1);
5762
427a72c6ee17 Eliminate several compiler (clang) warnings.
Stephen J. Turnbull <stephen@xemacs.org>
parents: 5752
diff changeset
3130 if (CHARP (number)) return make_integer ((EMACS_INT) XCHAR (number) - 1);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3131 if (MARKERP (number)) return make_integer (marker_position (number) - 1);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3132 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
3133 #ifdef HAVE_BIGNUM
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3134 if (BIGNUMP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3135 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3136 bignum_set_long (scratch_bignum, 1L);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3137 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
3138 return Fcanonicalize_number (make_bignum_bg (scratch_bignum2));
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3139 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3140 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3141 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3142 if (RATIOP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3143 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3144 ratio_set_long (scratch_ratio, 1L);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3145 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
3146 /* No need to canonicalize after subtracting 1 */
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3147 return make_ratio_rt (scratch_ratio);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3148 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3149 #endif
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3150 #ifdef HAVE_BIGFLOAT
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3151 if (BIGFLOATP (number))
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3152 {
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3153 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
3154 bigfloat_set_long (scratch_bigfloat, 1L);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3155 bigfloat_sub (scratch_bigfloat, XBIGFLOAT_DATA (number),
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3156 scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3157 return make_bigfloat_bf (scratch_bigfloat);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3158 }
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
3159 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3161 number = wrong_type_argument (Qnumber_char_or_marker_p, number);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3162 goto retry;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3163 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3164
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3166 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3167 /* weak lists */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3168 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3170 /* A weak list is like a normal list except that elements automatically
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3171 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
3172 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
3173 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
3174 remove them. This is analogous to weak hash tables; see the explanation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3175 there for more info. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3177 static Lisp_Object Vall_weak_lists; /* Gemarke es nicht!!! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3178
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3179 static Lisp_Object encode_weak_list_type (enum weak_list_type type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3181 static Lisp_Object
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2054
diff changeset
3182 mark_weak_list (Lisp_Object UNUSED (obj))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3183 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3184 return Qnil; /* nichts ist gemarkt */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3185 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3186
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3187 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2054
diff changeset
3188 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
3189 int escapeflag)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3190 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3191 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
3192 {
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3193 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
3194 }
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3195
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3196 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
3197 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
3198 printcharfun, escapeflag);
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3199 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
3200 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
3201 write_fmt_string (printcharfun, " 0x%x>", LISP_OBJECT_UID (obj));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3202 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3203
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3204 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
3205 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
3206 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3207 struct weak_list *w1 = XWEAK_LIST (obj1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3208 struct weak_list *w2 = XWEAK_LIST (obj2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3210 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
3211 internal_equal_0 (w1->list, w2->list, depth + 1, foldcase));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3212 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3213
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
3214 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
3215 weak_list_hash (Lisp_Object obj, int depth, Boolint equalp)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3216 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3217 struct weak_list *w = XWEAK_LIST (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3218
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
3219 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
3220 internal_hash (w->list, depth + 1, equalp));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3221 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3222
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3223 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3224 make_weak_list (enum weak_list_type type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3225 {
5127
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5125
diff changeset
3226 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
3227 struct weak_list *wl = XWEAK_LIST (result);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3229 wl->list = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3230 wl->type = type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3231 wl->next_weak = Vall_weak_lists;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3232 Vall_weak_lists = result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3233 return result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3234 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3235
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
3236 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
3237 { 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
3238 0, { 0 }, XD_FLAG_NO_KKCC },
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3239 { 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
3240 0, { 0 }, XD_FLAG_NO_KKCC },
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3241 { XD_END }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3242 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3243
5118
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4759
diff changeset
3244 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
3245 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
3246 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
3247 weak_list_description,
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4759
diff changeset
3248 struct weak_list);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3249 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3250 -- we do not mark the list elements (either the elements themselves
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3251 or the cons cells that hold them) in the normal marking phase.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3252 -- 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
3253 marked, and mark the cons cells that hold all marked
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3254 objects, and possibly parts of the objects themselves.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3255 (See alloc.c, "after-mark".)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3256 -- 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
3257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3258 WARNING WARNING WARNING WARNING WARNING:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3260 The code in the following two functions is *unbelievably* tricky.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3261 Don't mess with it. You'll be sorry.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3262
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3263 Linked lists just majorly suck, d'ya know?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3264 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3265
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3266 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3267 finish_marking_weak_lists (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3268 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3269 Lisp_Object rest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3270 int did_mark = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3272 for (rest = Vall_weak_lists;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3273 !NILP (rest);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3274 rest = XWEAK_LIST (rest)->next_weak)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3275 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3276 Lisp_Object rest2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3277 enum weak_list_type type = XWEAK_LIST (rest)->type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3279 if (! marked_p (rest))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3280 /* The weak list is probably garbage. Ignore it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3281 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3282
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3283 for (rest2 = XWEAK_LIST (rest)->list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3284 /* We need to be trickier since we're inside of GC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3285 use CONSP instead of !NILP in case of user-visible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3286 imperfect lists */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3287 CONSP (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3288 rest2 = XCDR (rest2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3289 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3290 Lisp_Object elem;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3291 /* If the element is "marked" (meaning depends on the type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3292 of weak list), we need to mark the cons containing the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3293 element, and maybe the element itself (if only some part
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3294 was already marked). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3295 int need_to_mark_cons = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3296 int need_to_mark_elem = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3298 /* If a cons is already marked, then its car is already marked
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3299 (either because of an external pointer or because of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3300 a previous call to this function), and likewise for all
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3301 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
3302 if (marked_p (rest2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3303 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3305 elem = XCAR (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3306
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3307 switch (type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3308 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3309 case WEAK_LIST_SIMPLE:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3310 if (marked_p (elem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3311 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3312 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3313
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3314 case WEAK_LIST_ASSOC:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3315 if (!CONSP (elem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3316 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3317 /* just leave bogus elements there */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3318 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3319 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3320 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3321 else if (marked_p (XCAR (elem)) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3322 marked_p (XCDR (elem)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3323 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3324 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3325 /* We still need to mark elem, because it's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3326 probably not marked. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3327 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3328 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3329 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3330
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3331 case WEAK_LIST_KEY_ASSOC:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3332 if (!CONSP (elem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3333 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3334 /* just leave bogus elements there */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3335 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3336 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3337 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3338 else if (marked_p (XCAR (elem)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3339 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3340 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3341 /* We still need to mark elem and XCDR (elem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3342 marking elem does both */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3343 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3344 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3345 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3346
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3347 case WEAK_LIST_VALUE_ASSOC:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3348 if (!CONSP (elem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3349 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3350 /* just leave bogus elements there */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3351 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3352 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3353 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3354 else if (marked_p (XCDR (elem)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3355 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3356 need_to_mark_cons = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3357 /* We still need to mark elem and XCAR (elem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3358 marking elem does both */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3359 need_to_mark_elem = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3360 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3361 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3362
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3363 case WEAK_LIST_FULL_ASSOC:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3364 if (!CONSP (elem))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3365 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3366 /* just leave bogus elements there */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3367 need_to_mark_cons = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3368 need_to_mark_elem = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3369 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3370 else if (marked_p (XCAR (elem)) ||
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3371 marked_p (XCDR (elem)))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3372 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3373 need_to_mark_cons = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3374 /* We still need to mark elem and XCAR (elem);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3375 marking elem does both */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3376 need_to_mark_elem = 1;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3377 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3378 break;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3379
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3380 default:
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2286
diff changeset
3381 ABORT ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3382 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3383
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3384 if (need_to_mark_elem && ! marked_p (elem))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3385 {
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3386 #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
3387 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
3388 #else /* NOT USE_KKCC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3389 mark_object (elem);
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3390 #endif /* NOT USE_KKCC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3391 did_mark = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3392 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3393
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3394 /* We also need to mark the cons that holds the elem or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3395 assoc-pair. We do *not* want to call (mark_object) here
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3396 because that will mark the entire list; we just want to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3397 mark the cons itself.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3398 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3399 if (need_to_mark_cons)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3400 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3401 Lisp_Cons *c = XCONS (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3402 if (!CONS_MARKED_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3403 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3404 MARK_CONS (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3405 did_mark = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3406 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3407 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3408 }
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 /* In case of imperfect list, need to mark the final cons
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3411 because we're not removing it */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3412 if (!NILP (rest2) && ! marked_p (rest2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3413 {
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3414 #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
3415 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
3416 #else /* NOT USE_KKCC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3417 mark_object (rest2);
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3418 #endif /* NOT USE_KKCC */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3419 did_mark = 1;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3423 return did_mark;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3426 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3427 prune_weak_lists (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3428 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3429 Lisp_Object rest, prev = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3430
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3431 for (rest = Vall_weak_lists;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3432 !NILP (rest);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3433 rest = XWEAK_LIST (rest)->next_weak)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3434 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3435 if (! (marked_p (rest)))
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 /* This weak list itself is garbage. Remove it from the list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3438 if (NILP (prev))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3439 Vall_weak_lists = XWEAK_LIST (rest)->next_weak;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3440 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3441 XWEAK_LIST (prev)->next_weak =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3442 XWEAK_LIST (rest)->next_weak;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3443 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3444 else
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 Lisp_Object rest2, prev2 = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3447 Lisp_Object tortoise;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3448 int go_tortoise = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3450 for (rest2 = XWEAK_LIST (rest)->list, tortoise = rest2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3451 /* We need to be trickier since we're inside of GC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3452 use CONSP instead of !NILP in case of user-visible
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3453 imperfect lists */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3454 CONSP (rest2);)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3455 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3456 /* It suffices to check the cons for marking,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3457 regardless of the type of weak list:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3458
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3459 -- if the cons is pointed to somewhere else,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3460 then it should stay around and will be marked.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3461 -- otherwise, if it should stay around, it will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3462 have been marked in finish_marking_weak_lists().
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3463 -- otherwise, it's not marked and should disappear.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3464 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3465 if (! marked_p (rest2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3466 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3467 /* bye bye :-( */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3468 if (NILP (prev2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3469 XWEAK_LIST (rest)->list = XCDR (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3470 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3471 XCDR (prev2) = XCDR (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3472 rest2 = XCDR (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3473 /* Ouch. Circularity checking is even trickier
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3474 than I thought. When we cut out a link
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3475 like this, we can't advance the turtle or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3476 it'll catch up to us. Imagine that we're
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3477 standing on floor tiles and moving forward --
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3478 what we just did here is as if the floor
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3479 tile under us just disappeared and all the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3480 ones ahead of us slid one tile towards us.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3481 In other words, we didn't move at all;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3482 if the tortoise was one step behind us
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3483 previously, it still is, and therefore
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3484 it must not move. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3485 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3486 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3487 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3488 prev2 = rest2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3489
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3490 /* Implementing circularity checking is trickier here
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3491 than in other places because we have to guarantee
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3492 that we've processed all elements before exiting
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3493 due to a circularity. (In most places, an error
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3494 is issued upon encountering a circularity, so it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3495 doesn't really matter if all elements are processed.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3496 The idea is that we process along with the hare
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3497 rather than the tortoise. If at any point in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3498 our forward process we encounter the tortoise,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3499 we must have already visited the spot, so we exit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3500 (If we process with the tortoise, we can fail to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3501 process cases where a cons points to itself, or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3502 where cons A points to cons B, which points to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3503 cons A.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3504
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3505 rest2 = XCDR (rest2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3506 if (go_tortoise)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3507 tortoise = XCDR (tortoise);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3508 go_tortoise = !go_tortoise;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3509 if (EQ (rest2, tortoise))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3510 break;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3514 prev = rest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3515 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3516 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3517 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3519 static enum weak_list_type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3520 decode_weak_list_type (Lisp_Object symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3521 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3522 CHECK_SYMBOL (symbol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3523 if (EQ (symbol, Qsimple)) return WEAK_LIST_SIMPLE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3524 if (EQ (symbol, Qassoc)) return WEAK_LIST_ASSOC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3525 if (EQ (symbol, Qold_assoc)) return WEAK_LIST_ASSOC; /* EBOLA ALERT! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3526 if (EQ (symbol, Qkey_assoc)) return WEAK_LIST_KEY_ASSOC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3527 if (EQ (symbol, Qvalue_assoc)) return WEAK_LIST_VALUE_ASSOC;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3528 if (EQ (symbol, Qfull_assoc)) return WEAK_LIST_FULL_ASSOC;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3529
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
3530 invalid_constant ("Invalid weak list type", symbol);
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
3531 RETURN_NOT_REACHED (WEAK_LIST_SIMPLE);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3532 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3534 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3535 encode_weak_list_type (enum weak_list_type type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3536 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3537 switch (type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3538 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3539 case WEAK_LIST_SIMPLE: return Qsimple;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3540 case WEAK_LIST_ASSOC: return Qassoc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3541 case WEAK_LIST_KEY_ASSOC: return Qkey_assoc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3542 case WEAK_LIST_VALUE_ASSOC: return Qvalue_assoc;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3543 case WEAK_LIST_FULL_ASSOC: return Qfull_assoc;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3544 default:
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2286
diff changeset
3545 ABORT ();
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3546 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3547
801
2b676dc88c66 [xemacs-hg @ 2002-04-01 03:58:02 by ben]
ben
parents: 800
diff changeset
3548 return Qnil; /* not (usually) reached */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3549 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3550
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3551 DEFUN ("weak-list-p", Fweak_list_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3552 Return non-nil if OBJECT is a weak list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3553 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3554 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3555 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3556 return WEAK_LISTP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3557 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3558
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3559 DEFUN ("make-weak-list", Fmake_weak_list, 0, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3560 Return a new weak list object of type TYPE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3561 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
3562 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
3563 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
3564 list (other than pointers in similar objects such as weak hash tables),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3565 the object is garbage collected and automatically removed from the list.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3566 This is used internally, for example, to manage the list holding the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3567 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
3568 still be reclaimed, and will automatically be removed from its parent's
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3569 list of children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3571 Optional argument TYPE specifies the type of the weak list, and defaults
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3572 to `simple'. Recognized types are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3573
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3574 `simple' Objects in the list disappear if not pointed to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3575 `assoc' Objects in the list disappear if they are conses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3576 and either the car or the cdr of the cons is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3577 pointed to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3578 `key-assoc' Objects in the list disappear if they are conses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3579 and the car is not pointed to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3580 `value-assoc' Objects in the list disappear if they are conses
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3581 and the cdr is not pointed to.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3582 `full-assoc' Objects in the list disappear if they are conses
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3583 and neither the car nor the cdr is pointed to.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3584 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3585 (type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3586 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3587 if (NILP (type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3588 type = Qsimple;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3589
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3590 return make_weak_list (decode_weak_list_type (type));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3591 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3592
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3593 DEFUN ("weak-list-type", Fweak_list_type, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3594 Return the type of the given weak-list object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3595 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3596 (weak))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3597 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3598 CHECK_WEAK_LIST (weak);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3599 return encode_weak_list_type (XWEAK_LIST (weak)->type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3600 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3601
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3602 DEFUN ("weak-list-list", Fweak_list_list, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3603 Return the list contained in a weak-list object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3604 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3605 (weak))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3606 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3607 CHECK_WEAK_LIST (weak);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3608 return XWEAK_LIST_LIST (weak);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3609 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3610
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3611 DEFUN ("set-weak-list-list", Fset_weak_list_list, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3612 Change the list contained in a weak-list object.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3613 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3614 (weak, new_list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3615 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3616 CHECK_WEAK_LIST (weak);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3617 XWEAK_LIST_LIST (weak) = new_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3618 return new_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3619 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3620
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3621
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3622 /************************************************************************/
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3623 /* weak boxes */
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3624 /************************************************************************/
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3625
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3626 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
3627
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3628 void
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3629 prune_weak_boxes (void)
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3630 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3631 Lisp_Object rest, prev = Qnil;
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3632 int removep = 0;
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3633
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3634 for (rest = Vall_weak_boxes;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3635 !NILP(rest);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3636 rest = XWEAK_BOX (rest)->next_weak_box)
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3637 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3638 if (! (marked_p (rest)))
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3639 /* This weak box itself is garbage. */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3640 removep = 1;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3641
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3642 if (! marked_p (XWEAK_BOX (rest)->value))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3643 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3644 XSET_WEAK_BOX (rest, Qnil);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3645 removep = 1;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3646 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3647
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3648 if (removep)
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3649 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3650 /* Remove weak box from list. */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3651 if (NILP (prev))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3652 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
3653 else
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3654 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
3655 removep = 0;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3656 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3657 else
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3658 prev = rest;
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3659 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3660 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3661
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3662 static Lisp_Object
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2054
diff changeset
3663 mark_weak_box (Lisp_Object UNUSED (obj))
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3664 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3665 return Qnil;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3666 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3667
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3668 static void
5325
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3669 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
3670 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3671 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
3672 {
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3673 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
3674 }
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3675
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3676 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
3677 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
3678 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
3679 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3680
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3681 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
3682 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
3683 {
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3684 struct weak_box *wb1 = XWEAK_BOX (obj1);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3685 struct weak_box *wb2 = XWEAK_BOX (obj2);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3686
4906
6ef8256a020a implement equalp in C, fix case-folding, add equal() method for keymaps
Ben Wing <ben@xemacs.org>
parents: 4885
diff changeset
3687 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
3688 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3689
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3690 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
3691 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
3692 {
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3693 struct weak_box *wb = XWEAK_BOX (obj);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3694
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
3695 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
3696 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3697
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3698 Lisp_Object
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3699 make_weak_box (Lisp_Object value)
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3700 {
5127
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5125
diff changeset
3701 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
3702 struct weak_box *wb = XWEAK_BOX (result);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3703
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3704 wb->value = value;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3705 result = wrap_weak_box (wb);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3706 wb->next_weak_box = Vall_weak_boxes;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3707 Vall_weak_boxes = result;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3708 return result;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3709 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3710
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
3711 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
3712 { 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
3713 { XD_END}
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3714 };
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3715
5118
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4759
diff changeset
3716 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
3717 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
3718 weak_box_hash, weak_box_description,
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5118
diff changeset
3719 struct weak_box);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3720
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3721 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
3722 Return a new weak box from value CONTENTS.
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3723 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
3724 `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
3725 reachability of CONTENTS. When CONTENTS is garbage-collected,
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3726 `weak-box-ref' will return NIL.
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3727 */
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3728 (value))
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3729 {
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
3730 return make_weak_box (value);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3731 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3732
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3733 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
3734 Return the contents of weak box WEAK-BOX.
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3735 If the contents have been GCed, return NIL.
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3736 */
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
3737 (weak_box))
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3738 {
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
3739 return XWEAK_BOX (weak_box)->value;
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3740 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3741
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3742 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
3743 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
3744 */
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3745 (object))
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3746 {
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3747 return WEAK_BOXP (object) ? Qt : Qnil;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3748 }
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
3749
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3750 /************************************************************************/
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3751 /* ephemerons */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3752 /************************************************************************/
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3753
993
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3754 /* The concept of ephemerons is due to:
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3755 * 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
3756 * 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
3757 *
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3758 * 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
3759 * ephemerons, refer to:
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3760 * Simon Peyton Jones, Simon Marlow, Conal Elliot:
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3761 * Stretching the storage manager
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3762 * Implementation of Functional Languages, 1999
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3763 */
86012f228185 [xemacs-hg @ 2002-09-03 11:00:10 by michaels]
michaels
parents: 934
diff changeset
3764
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3765 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
3766 static Lisp_Object Vnew_all_ephemerons;
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3767 static Lisp_Object Vfinalize_list;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3768
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3769 void
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
3770 init_marking_ephemerons (void)
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3771 {
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3772 Vnew_all_ephemerons = Qnil;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3773 }
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3774
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3775 /* 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
3776 * 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
3777 * way. */
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3778
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3779 int
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
3780 continue_marking_ephemerons (void)
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3781 {
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3782 Lisp_Object rest = Vall_ephemerons, next, prev = Qnil;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3783 int did_mark = 0;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3784
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3785 while (!NILP (rest))
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3786 {
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3787 next = XEPHEMERON_NEXT (rest);
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3788
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3789 if (marked_p (rest))
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3790 {
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3791 MARK_CONS (XCONS (XEPHEMERON (rest)->cons_chain));
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3792 if (marked_p (XEPHEMERON (rest)->key))
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3793 {
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3794 #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
3795 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
3796 (XCAR (XEPHEMERON (rest)->cons_chain));
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3797 #else /* NOT USE_KKCC */
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3798 mark_object (XCAR (XEPHEMERON (rest)->cons_chain));
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3799 #endif /* NOT USE_KKCC */
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3800 did_mark = 1;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3801 XSET_EPHEMERON_NEXT (rest, Vnew_all_ephemerons);
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3802 Vnew_all_ephemerons = rest;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3803 if (NILP (prev))
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3804 Vall_ephemerons = next;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3805 else
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3806 XSET_EPHEMERON_NEXT (prev, next);
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3807 }
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3808 else
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3809 prev = rest;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3810 }
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3811 else
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3812 prev = rest;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3813
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3814 rest = next;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3815 }
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3816
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3817 return did_mark;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3818 }
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3819
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3820 /* 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
3821 * 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
3822 * resurrect them.
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3823 */
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3824
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3825 int
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
3826 finish_marking_ephemerons (void)
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3827 {
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3828 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
3829 int did_mark = 0;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3830
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3831 while (! NILP (rest))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3832 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3833 next = XEPHEMERON_NEXT (rest);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3834
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3835 if (marked_p (rest))
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3836 /* 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
3837 {
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3838 /* tombstone */
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3839 XSET_EPHEMERON_VALUE (rest, Qnil);
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3840
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3841 if (! NILP (XEPHEMERON_FINALIZER (rest)))
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3842 {
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3843 MARK_CONS (XCONS (XEPHEMERON (rest)->cons_chain));
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3844 #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
3845 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
3846 (XCAR (XEPHEMERON (rest)->cons_chain));
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3847 #else /* NOT USE_KKCC */
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3848 mark_object (XCAR (XEPHEMERON (rest)->cons_chain));
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3849 #endif /* NOT USE_KKCC */
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3850
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3851 /* Register the finalizer */
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3852 XSET_EPHEMERON_NEXT (rest, Vfinalize_list);
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3853 Vfinalize_list = XEPHEMERON (rest)->cons_chain;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3854 did_mark = 1;
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3855 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3856
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3857 /* Remove it from the list. */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3858 if (NILP (prev))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3859 Vall_ephemerons = next;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3860 else
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3861 XSET_EPHEMERON_NEXT (prev, next);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3862 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3863 else
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3864 prev = rest;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3865
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3866 rest = next;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3867 }
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3868
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3869 return did_mark;
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3870 }
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3871
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3872 void
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
3873 prune_ephemerons (void)
1590
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3874 {
03009473262a [xemacs-hg @ 2003-07-26 14:00:27 by michaels]
michaels
parents: 1551
diff changeset
3875 Vall_ephemerons = Vnew_all_ephemerons;
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3876 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3877
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3878 Lisp_Object
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
3879 zap_finalize_list (void)
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3880 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3881 Lisp_Object finalizers = Vfinalize_list;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3882
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3883 Vfinalize_list = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3884
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3885 return finalizers;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3886 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3887
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3888 static Lisp_Object
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2054
diff changeset
3889 mark_ephemeron (Lisp_Object UNUSED (obj))
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3890 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3891 return Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3892 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3893
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3894 static void
5325
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3895 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
3896 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3897 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
3898 {
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3899 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
3900 }
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3901
47298dcf2e8f Be more helpful in printing ephemerons, weak lists, and weak boxes.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
3902 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
3903 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
3904 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
3905 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
3906 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
3907 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
3908 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
3909 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3910
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3911 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
3912 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
3913 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3914 return
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
3915 internal_equal_0 (XEPHEMERON_REF (obj1), XEPHEMERON_REF (obj2),
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
3916 depth + 1, foldcase);
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3917 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3918
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3919 static Hashcode
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
3920 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
3921 {
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
3922 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
3923 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3924
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3925 Lisp_Object
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
3926 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
3927 {
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
3928 Lisp_Object temp = Qnil;
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3929 struct gcpro gcpro1, gcpro2;
5127
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5125
diff changeset
3930 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
3931 struct ephemeron *eph = XEPHEMERON (result);
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3932
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3933 eph->key = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3934 eph->cons_chain = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3935 eph->value = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3936
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
3937 result = wrap_ephemeron (eph);
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3938 GCPRO2 (result, temp);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3939
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3940 eph->key = key;
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
3941 temp = Fcons (value, finalizer);
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
3942 eph->cons_chain = Fcons (temp, Vall_ephemerons);
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3943 eph->value = value;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3944
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3945 Vall_ephemerons = result;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3946
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3947 UNGCPRO;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3948 return result;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3949 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3950
1598
ac1be85b4a5f [xemacs-hg @ 2003-07-31 13:32:24 by crestani]
crestani
parents: 1590
diff changeset
3951 /* 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
3952 is marked here. */
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 1104
diff changeset
3953 static const struct memory_description ephemeron_description[] = {
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
3954 { XD_LISP_OBJECT, offsetof (struct ephemeron, key),
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2500
diff changeset
3955 0, { 0 }, XD_FLAG_NO_KKCC },
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
3956 { 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
3957 0, { 0 }, XD_FLAG_NO_KKCC },
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
3958 { XD_LISP_OBJECT, offsetof (struct ephemeron, value),
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2500
diff changeset
3959 0, { 0 }, XD_FLAG_NO_KKCC },
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3960 { XD_END }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3961 };
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3962
5118
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4759
diff changeset
3963 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
3964 mark_ephemeron, print_ephemeron,
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5118
diff changeset
3965 0, ephemeron_equal, ephemeron_hash,
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5118
diff changeset
3966 ephemeron_description,
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5118
diff changeset
3967 struct ephemeron);
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3968
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3969 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
3970 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
3971 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
3972 `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
3973 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
3974 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
3975 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
3976 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
3977 future calls to `ephemeron-ref' will return NIL.
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3978 */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3979 (key, value, finalizer))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3980 {
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
3981 return make_ephemeron (key, value, finalizer);
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3982 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3983
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3984 DEFUN ("ephemeron-ref", Fephemeron_ref, 1, 1, 0, /*
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3985 Return the contents of ephemeron EPHEMERON.
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3986 If the contents have been GCed, return NIL.
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3987 */
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
3988 (ephemeron))
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3989 {
5752
70a3f4ff8da8 Improve coding style, variable names, data.c, sequence.c
Aidan Kehoe <kehoea@parhasard.net>
parents: 5736
diff changeset
3990 return XEPHEMERON_REF (ephemeron);
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3991 }
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3992
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3993 DEFUN ("ephemeron-p", Fephemeronp, 1, 1, 0, /*
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3994 Return non-nil if OBJECT is an ephemeron.
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3995 */
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3996 (object))
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3997 {
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3998 return EPHEMERONP (object) ? Qt : Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
3999 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4000
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4001 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4002 /* initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4003 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4004
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4005 static SIGTYPE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4006 arith_error (int signo)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4007 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4008 EMACS_REESTABLISH_SIGNAL (signo, arith_error);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4009 EMACS_UNBLOCK_SIGNAL (signo);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4010 signal_error (Qarith_error, 0, Qunbound);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4011 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4012
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4013 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4014 init_data_very_early (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4015 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4016 /* Don't do this if just dumping out.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4017 We don't want to call `signal' in this case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4018 so that we don't have trouble with dumping
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4019 signal-delivering routines in an inconsistent state. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4020 if (!initialized)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4021 return;
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 603
diff changeset
4022 EMACS_SIGNAL (SIGFPE, arith_error);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4023 #ifdef uts
613
023b83f4e54b [xemacs-hg @ 2001-06-10 10:42:16 by ben]
ben
parents: 603
diff changeset
4024 EMACS_SIGNAL (SIGEMT, arith_error);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4025 #endif /* uts */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4026 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4027
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4028 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4029 init_errors_once_early (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4030 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4031 DEFSYMBOL (Qerror_conditions);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4032 DEFSYMBOL (Qerror_message);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4033
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4034 /* We declare the errors here because some other deferrors depend
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4035 on some of the errors below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4036
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4037 /* ERROR is used as a signaler for random errors for which nothing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4038 else is right */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4039
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4040 DEFERROR (Qerror, "error", Qnil);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4041 DEFERROR_STANDARD (Qquit, Qnil);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4042
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4043 DEFERROR_STANDARD (Qinvalid_argument, Qerror);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4044
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4045 DEFERROR_STANDARD (Qsyntax_error, Qinvalid_argument);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4046 DEFERROR_STANDARD (Qinvalid_read_syntax, Qsyntax_error);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4047 DEFERROR_STANDARD (Qstructure_formation_error, Qsyntax_error);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4048 DEFERROR_STANDARD (Qlist_formation_error, Qstructure_formation_error);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4049 DEFERROR_STANDARD (Qmalformed_list, Qlist_formation_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4050 DEFERROR_STANDARD (Qmalformed_property_list, Qmalformed_list);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4051 DEFERROR_STANDARD (Qcircular_list, Qlist_formation_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4052 DEFERROR_STANDARD (Qcircular_property_list, Qcircular_list);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4053
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4054 DEFERROR_STANDARD (Qwrong_type_argument, Qinvalid_argument);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4055 DEFERROR_STANDARD (Qargs_out_of_range, Qinvalid_argument);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4056 DEFERROR_STANDARD (Qwrong_number_of_arguments, Qinvalid_argument);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4057 DEFERROR_STANDARD (Qinvalid_function, Qinvalid_argument);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4058 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
4059 DEFERROR_STANDARD (Qinvalid_keyword_argument, Qinvalid_argument);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4060 DEFERROR (Qno_catch, "No catch for tag", Qinvalid_argument);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4061
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4062 DEFERROR_STANDARD (Qinvalid_state, Qerror);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4063 DEFERROR (Qvoid_function, "Symbol's function definition is void",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4064 Qinvalid_state);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4065 DEFERROR (Qcyclic_function_indirection,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4066 "Symbol's chain of function indirections contains a loop",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4067 Qinvalid_state);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4068 DEFERROR (Qvoid_variable, "Symbol's value as variable is void",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4069 Qinvalid_state);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4070 DEFERROR (Qcyclic_variable_indirection,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4071 "Symbol's chain of variable indirections contains a loop",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4072 Qinvalid_state);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4073 DEFERROR_STANDARD (Qstack_overflow, Qinvalid_state);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4074 DEFERROR_STANDARD (Qinternal_error, Qinvalid_state);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4075 DEFERROR_STANDARD (Qout_of_memory, Qinvalid_state);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4076
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4077 DEFERROR_STANDARD (Qinvalid_operation, Qerror);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4078 DEFERROR_STANDARD (Qinvalid_change, Qinvalid_operation);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4079 DEFERROR (Qsetting_constant, "Attempt to set a constant symbol",
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4080 Qinvalid_change);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4081 DEFERROR_STANDARD (Qprinting_unreadable_object, Qinvalid_operation);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4082 DEFERROR (Qunimplemented, "Feature not yet implemented", Qinvalid_operation);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4083
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4084 DEFERROR_STANDARD (Qediting_error, Qinvalid_operation);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4085 DEFERROR_STANDARD (Qbeginning_of_buffer, Qediting_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4086 DEFERROR_STANDARD (Qend_of_buffer, Qediting_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4087 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
4088 DEFERROR (Qextent_read_only, "Extent is read-only", Qediting_error);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4089
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4090 DEFERROR (Qio_error, "IO Error", Qinvalid_operation);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4091 DEFERROR_STANDARD (Qfile_error, Qio_error);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4092 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
4093 DEFERROR_STANDARD (Qconversion_error, Qio_error);
580
55e998c311f5 [xemacs-hg @ 2001-05-26 12:24:50 by ben]
ben
parents: 563
diff changeset
4094 DEFERROR_STANDARD (Qtext_conversion_error, Qconversion_error);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4095
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4096 DEFERROR (Qarith_error, "Arithmetic error", Qinvalid_operation);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4097 DEFERROR (Qrange_error, "Arithmetic range error", Qarith_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4098 DEFERROR (Qdomain_error, "Arithmetic domain error", Qarith_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4099 DEFERROR (Qsingularity_error, "Arithmetic singularity error", Qdomain_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4100 DEFERROR (Qoverflow_error, "Arithmetic overflow error", Qdomain_error);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4101 DEFERROR (Qunderflow_error, "Arithmetic underflow error", Qdomain_error);
5908
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5905
diff changeset
4102
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5905
diff changeset
4103 /* Moved here from number.c, so it's available when none of the new numeric
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5905
diff changeset
4104 types are. */
6174848f3e6c Use parse_integer() in read_atom(); support bases with ratios like integers
Aidan Kehoe <kehoea@parhasard.net>
parents: 5905
diff changeset
4105 DEFERROR_STANDARD (Qunsupported_type, Qwrong_type_argument);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4106 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4108 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4109 syms_of_data (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4110 {
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
4111 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
4112 INIT_LISP_OBJECT (ephemeron);
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
4113 INIT_LISP_OBJECT (weak_box);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4114
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4115 DEFSYMBOL (Qlambda);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4116 DEFSYMBOL (Qlistp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4117 DEFSYMBOL (Qtrue_list_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4118 DEFSYMBOL (Qconsp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4119 DEFSYMBOL (Qsubrp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4120 DEFSYMBOL (Qsymbolp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4121 DEFSYMBOL (Qintegerp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4122 DEFSYMBOL (Qcharacterp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4123 DEFSYMBOL (Qnatnump);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
4124 DEFSYMBOL (Qnonnegativep);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4125 DEFSYMBOL (Qstringp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4126 DEFSYMBOL (Qarrayp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4127 DEFSYMBOL (Qsequencep);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4128 DEFSYMBOL (Qbufferp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4129 DEFSYMBOL (Qbitp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4130 DEFSYMBOL_MULTIWORD_PREDICATE (Qbit_vectorp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4131 DEFSYMBOL (Qvectorp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4132 DEFSYMBOL (Qchar_or_string_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4133 DEFSYMBOL (Qmarkerp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4134 DEFSYMBOL (Qinteger_or_marker_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4135 DEFSYMBOL (Qinteger_or_char_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4136 DEFSYMBOL (Qinteger_char_or_marker_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4137 DEFSYMBOL (Qnumberp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4138 DEFSYMBOL (Qnumber_char_or_marker_p);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4139 DEFSYMBOL (Qcdr);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 458
diff changeset
4140 DEFSYMBOL (Qerror_lacks_explanatory_string);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4141 DEFSYMBOL_MULTIWORD_PREDICATE (Qweak_listp);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4142 DEFSYMBOL (Qfloatp);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4143
5864
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4144 DEFKEYWORD (Q_radix);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4145 DEFKEYWORD (Q_junk_allowed);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4146 DEFKEYWORD (Q_radix_table);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4147
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4148 DEFSUBR (Fwrong_type_argument);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4149
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
4150 #ifdef HAVE_RATIO
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
4151 DEFSUBR (Fdiv);
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
4152 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4153 DEFSUBR (Feq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4154 DEFSUBR (Fnull);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4155 Ffset (intern ("not"), intern ("null"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4156 DEFSUBR (Flistp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4157 DEFSUBR (Fnlistp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4158 DEFSUBR (Ftrue_list_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4159 DEFSUBR (Fconsp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4160 DEFSUBR (Fatom);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4161 DEFSUBR (Fchar_or_string_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4162 DEFSUBR (Fcharacterp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4163 DEFSUBR (Fchar_int_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4164 DEFSUBR (Fchar_to_int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4165 DEFSUBR (Fint_to_char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4166 DEFSUBR (Fchar_or_char_int_p);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
4167 DEFSUBR (Ffixnump);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4168 DEFSUBR (Fintegerp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4169 DEFSUBR (Finteger_or_marker_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4170 DEFSUBR (Finteger_or_char_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4171 DEFSUBR (Finteger_char_or_marker_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4172 DEFSUBR (Fnumberp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4173 DEFSUBR (Fnumber_or_marker_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4174 DEFSUBR (Fnumber_char_or_marker_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4175 DEFSUBR (Ffloatp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4176 DEFSUBR (Fnatnump);
1983
9c872f33ecbe [xemacs-hg @ 2004-04-05 22:49:31 by james]
james
parents: 1598
diff changeset
4177 DEFSUBR (Fnonnegativep);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4178 DEFSUBR (Fsymbolp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4179 DEFSUBR (Fkeywordp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4180 DEFSUBR (Fstringp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4181 DEFSUBR (Fvectorp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4182 DEFSUBR (Fbitp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4183 DEFSUBR (Fbit_vector_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4184 DEFSUBR (Farrayp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4185 DEFSUBR (Fsequencep);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4186 DEFSUBR (Fmarkerp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4187 DEFSUBR (Fsubrp);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4188 DEFSUBR (Fsubr_min_args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4189 DEFSUBR (Fsubr_max_args);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4190 DEFSUBR (Fsubr_interactive);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4191 DEFSUBR (Ftype_of);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4192 DEFSUBR (Fcar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4193 DEFSUBR (Fcdr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4194 DEFSUBR (Fcar_safe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4195 DEFSUBR (Fcdr_safe);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4196 DEFSUBR (Fsetcar);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4197 DEFSUBR (Fsetcdr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4198 DEFSUBR (Findirect_function);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4199 DEFSUBR (Faref);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4200 DEFSUBR (Faset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4202 DEFSUBR (Fnumber_to_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4203 DEFSUBR (Fstring_to_number);
5864
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4204 DEFSUBR (Fset_digit_fixnum_map);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4205 DEFSUBR (Fdigit_char_p);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4206 DEFSUBR (Fdigit_char);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4207 DEFSUBR (Fparse_integer);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4208 DEFSUBR (Feqlsign);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4209 DEFSUBR (Flss);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4210 DEFSUBR (Fgtr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4211 DEFSUBR (Fleq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4212 DEFSUBR (Fgeq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4213 DEFSUBR (Fneq);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4214 DEFSUBR (Fzerop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4215 DEFSUBR (Fplus);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4216 DEFSUBR (Fminus);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4217 DEFSUBR (Ftimes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4218 DEFSUBR (Fquo);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4219 DEFSUBR (Frem);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4220 DEFSUBR (Fmod);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4221 DEFSUBR (Fmax);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4222 DEFSUBR (Fmin);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4223 DEFSUBR (Flogand);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4224 DEFSUBR (Flogior);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4225 DEFSUBR (Flogxor);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4226 DEFSUBR (Flsh);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4227 DEFSUBR (Fash);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4228 DEFSUBR (Fadd1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4229 DEFSUBR (Fsub1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4230 DEFSUBR (Flognot);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4231
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4232 DEFSUBR (Fweak_list_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4233 DEFSUBR (Fmake_weak_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4234 DEFSUBR (Fweak_list_type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4235 DEFSUBR (Fweak_list_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4236 DEFSUBR (Fset_weak_list_list);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
4237
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
4238 DEFSUBR (Fmake_ephemeron);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
4239 DEFSUBR (Fephemeron_ref);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
4240 DEFSUBR (Fephemeronp);
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
4241 DEFSUBR (Fmake_weak_box);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
4242 DEFSUBR (Fweak_box_ref);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
4243 DEFSUBR (Fweak_boxp);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4244 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4246 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4247 vars_of_data (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4248 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4249 /* This must not be staticpro'd */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4250 Vall_weak_lists = Qnil;
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 444
diff changeset
4251 dump_add_weak_object_chain (&Vall_weak_lists);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4252
888
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
4253 Vall_ephemerons = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
4254 dump_add_weak_object_chain (&Vall_ephemerons);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
4255
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
4256 Vfinalize_list = Qnil;
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
4257 staticpro (&Vfinalize_list);
201c016cfc12 [xemacs-hg @ 2002-06-28 14:24:07 by michaels]
michaels
parents: 867
diff changeset
4258
858
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
4259 Vall_weak_boxes = Qnil;
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
4260 dump_add_weak_object_chain (&Vall_weak_boxes);
2c12fe2da451 [xemacs-hg @ 2002-05-31 09:38:45 by michaels]
michaels
parents: 826
diff changeset
4261
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
4262 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
4263 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
4264 */);
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
4265 Vmost_negative_fixnum = MOST_NEGATIVE_FIXNUM;
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
4266
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
4267 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
4268 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
4269 */);
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5510
diff changeset
4270 Vmost_positive_fixnum = MOST_POSITIVE_FIXNUM;
4885
6772ce4d982b Fix hash tables, #'member*, #'assoc*, #'eql compiler macros if bignums
Aidan Kehoe <kehoea@parhasard.net>
parents: 4846
diff changeset
4271
5864
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4272 DEFVAR_CONST_LISP ("digit-fixnum-map", &Vdigit_fixnum_map /*
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4273 Table used to determine a character's numeric value when parsing.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4274
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4275 This is a character table with fixnum values. A value of -1 indicates this
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4276 character does not have an assigned numeric value. See `parse-integer',
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4277 `digit-char-p', and `digit-char'.
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4278 */);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4279 Vdigit_fixnum_map = Fmake_char_table (Qgeneric);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4280 set_char_table_default (Vdigit_fixnum_map, make_fixnum (-1));
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4281 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4282 int ii = 0;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4283
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4284 for (ii = 0; ii < 10; ++ii)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4285 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4286 XCHAR_TABLE (Vdigit_fixnum_map)->ascii['0' + ii] = make_fixnum(ii);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4287 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4288
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4289 for (ii = 10; ii < 36; ++ii)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4290 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4291 XCHAR_TABLE (Vdigit_fixnum_map)->ascii['a' + (ii - 10)]
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4292 = make_fixnum(ii);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4293 XCHAR_TABLE (Vdigit_fixnum_map)->ascii['A' + (ii - 10)]
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4294 = make_fixnum(ii);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4295 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4296 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4297 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4298 Ascbyte *fixnum_tab = alloca_ascbytes (36 * MAX_ICHAR_LEN), *ptr;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4299 int ii;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4300 Ichar cc;
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4301 memset ((void *)fixnum_tab, 0, 36 * MAX_ICHAR_LEN);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4302
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4303 /* The whole point of fixnum_to_character_table is access as an array,
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4304 avoid O(N) issues by giving every character MAX_ICHAR_LEN of
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4305 bytes. */
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4306 for (ii = 0, ptr = fixnum_tab; ii < 36; ++ii, ptr += MAX_ICHAR_LEN)
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4307 {
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4308 cc = ii < 10 ? '0' + ii : 'A' + (ii - 10);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4309 set_itext_ichar ((Ibyte *) ptr, cc);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4310 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4311
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4312 /* Sigh, we can't call build_fixnum_to_char_map() on Vdigit_fixnum_map,
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4313 this is too early in the boot sequence to map across a char table. Do
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4314 it by hand. */
5871
58e72e27fb81 Don't rely on zero termination for Vfixnum_to_char_map, thank you Vin.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5870
diff changeset
4315 ASSERT_ASCTEXT_ASCII_LEN (fixnum_tab, 36 * MAX_ICHAR_LEN);
58e72e27fb81 Don't rely on zero termination for Vfixnum_to_char_map, thank you Vin.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5870
diff changeset
4316 Vfixnum_to_char_map
58e72e27fb81 Don't rely on zero termination for Vfixnum_to_char_map, thank you Vin.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5870
diff changeset
4317 = make_string ((const Ibyte*) fixnum_tab, 36 * MAX_ICHAR_LEN);
5864
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4318 staticpro (&Vfixnum_to_char_map);
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4319 }
750fab17b299 Make #'parse-integer Lisp-visible, extend it, allowing non-ASCII digits.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5769
diff changeset
4320
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4321 #ifdef DEBUG_XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4322 DEFVAR_BOOL ("debug-issue-ebola-notices", &debug_issue_ebola_notices /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4323 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
4324 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
4325 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
4326 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
4327 In such situations, the result would be different in XEmacs 19 versus
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4328 XEmacs 20, and you probably don't want this.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4329
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4330 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
4331 code under XEmacs 20 -- any code byte-compiled under XEmacs 19 will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4332 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
4333 impossible to accurately determine Ebola infection.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4334 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4335
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4336 debug_issue_ebola_notices = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4338 DEFVAR_INT ("debug-ebola-backtrace-length",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4339 &debug_ebola_backtrace_length /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4340 Length (in stack frames) of short backtrace printed out in Ebola notices.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4341 See `debug-issue-ebola-notices'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4342 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4343 debug_ebola_backtrace_length = 32;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4345 #endif /* DEBUG_XEMACS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4346 }