home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Source Code 1993 July / THE_SOURCE_CODE_CD_ROM.iso / gnu / lucid / lemacs-19.6 / src / data.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-03-13  |  55.0 KB  |  2,063 lines

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