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