comparison src/data.c @ 89909:68c22ea6027c

Sync to HEAD
author Kenichi Handa <handa@m17n.org>
date Fri, 16 Apr 2004 12:51:06 +0000
parents 58eb89f2fdfc
children 4c90ffeb71c5
comparison
equal deleted inserted replaced
89908:ee1402f7b568 89909:68c22ea6027c
1 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter. 1 /* Primitive operations on Lisp data types for GNU Emacs Lisp interpreter.
2 Copyright (C) 1985,86,88,93,94,95,97,98,99, 2000, 2001, 2003 2 Copyright (C) 1985,86,88,93,94,95,97,98,99, 2000, 2001, 03, 2004
3 Free Software Foundation, Inc. 3 Free Software Foundation, Inc.
4 4
5 This file is part of GNU Emacs. 5 This file is part of GNU Emacs.
6 6
7 GNU Emacs is free software; you can redistribute it and/or modify 7 GNU Emacs is free software; you can redistribute it and/or modify
69 Lisp_Object Qsetting_constant, Qinvalid_read_syntax; 69 Lisp_Object Qsetting_constant, Qinvalid_read_syntax;
70 Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch; 70 Lisp_Object Qinvalid_function, Qwrong_number_of_arguments, Qno_catch;
71 Lisp_Object Qend_of_file, Qarith_error, Qmark_inactive; 71 Lisp_Object Qend_of_file, Qarith_error, Qmark_inactive;
72 Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only; 72 Lisp_Object Qbeginning_of_buffer, Qend_of_buffer, Qbuffer_read_only;
73 Lisp_Object Qtext_read_only; 73 Lisp_Object Qtext_read_only;
74
74 Lisp_Object Qintegerp, Qnatnump, Qwholenump, Qsymbolp, Qlistp, Qconsp; 75 Lisp_Object Qintegerp, Qnatnump, Qwholenump, Qsymbolp, Qlistp, Qconsp;
75 Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp; 76 Lisp_Object Qstringp, Qarrayp, Qsequencep, Qbufferp;
76 Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp; 77 Lisp_Object Qchar_or_string_p, Qmarkerp, Qinteger_or_marker_p, Qvectorp;
77 Lisp_Object Qbuffer_or_string_p, Qkeywordp; 78 Lisp_Object Qbuffer_or_string_p, Qkeywordp;
78 Lisp_Object Qboundp, Qfboundp; 79 Lisp_Object Qboundp, Qfboundp;
85 Lisp_Object Qoverflow_error, Qunderflow_error; 86 Lisp_Object Qoverflow_error, Qunderflow_error;
86 87
87 Lisp_Object Qfloatp; 88 Lisp_Object Qfloatp;
88 Lisp_Object Qnumberp, Qnumber_or_marker_p; 89 Lisp_Object Qnumberp, Qnumber_or_marker_p;
89 90
90 static Lisp_Object Qinteger, Qsymbol, Qstring, Qcons, Qmarker, Qoverlay; 91 Lisp_Object Qinteger;
92 static Lisp_Object Qsymbol, Qstring, Qcons, Qmarker, Qoverlay;
91 static Lisp_Object Qfloat, Qwindow_configuration, Qwindow; 93 static Lisp_Object Qfloat, Qwindow_configuration, Qwindow;
92 Lisp_Object Qprocess; 94 Lisp_Object Qprocess;
93 static Lisp_Object Qcompiled_function, Qbuffer, Qframe, Qvector; 95 static Lisp_Object Qcompiled_function, Qbuffer, Qframe, Qvector;
94 static Lisp_Object Qchar_table, Qbool_vector, Qhash_table; 96 static Lisp_Object Qchar_table, Qbool_vector, Qhash_table;
95 static Lisp_Object Qsubrp, Qmany, Qunevalled; 97 static Lisp_Object Qsubrp, Qmany, Qunevalled;
726 Fput (symbol, Qfunction_documentation, docstring); 728 Fput (symbol, Qfunction_documentation, docstring);
727 return definition; 729 return definition;
728 } 730 }
729 731
730 DEFUN ("setplist", Fsetplist, Ssetplist, 2, 2, 0, 732 DEFUN ("setplist", Fsetplist, Ssetplist, 2, 2, 0,
731 doc: /* Set SYMBOL's property list to NEWVAL, and return NEWVAL. */) 733 doc: /* Set SYMBOL's property list to NEWPLIST, and return NEWPLIST. */)
732 (symbol, newplist) 734 (symbol, newplist)
733 register Lisp_Object symbol, newplist; 735 register Lisp_Object symbol, newplist;
734 { 736 {
735 CHECK_SYMBOL (symbol); 737 CHECK_SYMBOL (symbol);
736 XSYMBOL (symbol)->plist = newplist; 738 XSYMBOL (symbol)->plist = newplist;
757 return Fcons (make_number (minargs), Qunevalled); 759 return Fcons (make_number (minargs), Qunevalled);
758 else 760 else
759 return Fcons (make_number (minargs), make_number (maxargs)); 761 return Fcons (make_number (minargs), make_number (maxargs));
760 } 762 }
761 763
762 DEFUN ("subr-interactive-form", Fsubr_interactive_form, Ssubr_interactive_form, 1, 1, 0, 764 DEFUN ("interactive-form", Finteractive_form, Sinteractive_form, 1, 1, 0,
763 doc: /* Return the interactive form of SUBR or nil if none. 765 doc: /* Return the interactive form of CMD or nil if none.
764 SUBR must be a built-in function. Value, if non-nil, is a list 766 CMD must be a command. Value, if non-nil, is a list
765 \(interactive SPEC). */) 767 \(interactive SPEC). */)
766 (subr) 768 (cmd)
767 Lisp_Object subr; 769 Lisp_Object cmd;
768 { 770 {
769 if (!SUBRP (subr)) 771 Lisp_Object fun = indirect_function (cmd);
770 wrong_type_argument (Qsubrp, subr); 772
771 if (XSUBR (subr)->prompt) 773 if (SUBRP (fun))
772 return list2 (Qinteractive, build_string (XSUBR (subr)->prompt)); 774 {
775 if (XSUBR (fun)->prompt)
776 return list2 (Qinteractive, build_string (XSUBR (fun)->prompt));
777 }
778 else if (COMPILEDP (fun))
779 {
780 if ((ASIZE (fun) & PSEUDOVECTOR_SIZE_MASK) > COMPILED_INTERACTIVE)
781 return list2 (Qinteractive, AREF (fun, COMPILED_INTERACTIVE));
782 }
783 else if (CONSP (fun))
784 {
785 Lisp_Object funcar = XCAR (fun);
786 if (EQ (funcar, Qlambda))
787 return Fassq (Qinteractive, Fcdr (XCDR (fun)));
788 else if (EQ (funcar, Qautoload))
789 {
790 struct gcpro gcpro1;
791 GCPRO1 (cmd);
792 do_autoload (fun, cmd);
793 UNGCPRO;
794 return Finteractive_form (cmd);
795 }
796 }
773 return Qnil; 797 return Qnil;
774 } 798 }
775 799
776 800
777 /*********************************************************************** 801 /***********************************************************************
869 store_symval_forwarding (symbol, valcontents, newval, buf) 893 store_symval_forwarding (symbol, valcontents, newval, buf)
870 Lisp_Object symbol; 894 Lisp_Object symbol;
871 register Lisp_Object valcontents, newval; 895 register Lisp_Object valcontents, newval;
872 struct buffer *buf; 896 struct buffer *buf;
873 { 897 {
898 int offset;
899
874 switch (SWITCH_ENUM_CAST (XTYPE (valcontents))) 900 switch (SWITCH_ENUM_CAST (XTYPE (valcontents)))
875 { 901 {
876 case Lisp_Misc: 902 case Lisp_Misc:
877 switch (XMISCTYPE (valcontents)) 903 switch (XMISCTYPE (valcontents))
878 { 904 {
888 *XBOOLFWD (valcontents)->boolvar = NILP (newval) ? 0 : 1; 914 *XBOOLFWD (valcontents)->boolvar = NILP (newval) ? 0 : 1;
889 break; 915 break;
890 916
891 case Lisp_Misc_Objfwd: 917 case Lisp_Misc_Objfwd:
892 *XOBJFWD (valcontents)->objvar = newval; 918 *XOBJFWD (valcontents)->objvar = newval;
919
920 /* If this variable is a default for something stored
921 in the buffer itself, such as default-fill-column,
922 find the buffers that don't have local values for it
923 and update them. */
924 if (XOBJFWD (valcontents)->objvar > (Lisp_Object *) &buffer_defaults
925 && XOBJFWD (valcontents)->objvar < (Lisp_Object *) (&buffer_defaults + 1))
926 {
927 int offset = ((char *) XOBJFWD (valcontents)->objvar
928 - (char *) &buffer_defaults);
929 int idx = PER_BUFFER_IDX (offset);
930
931 Lisp_Object tail, buf;
932
933 if (idx <= 0)
934 break;
935
936 for (tail = Vbuffer_alist; CONSP (tail); tail = XCDR (tail))
937 {
938 Lisp_Object buf;
939 struct buffer *b;
940
941 buf = Fcdr (XCAR (tail));
942 if (!BUFFERP (buf)) continue;
943 b = XBUFFER (buf);
944
945 if (! PER_BUFFER_VALUE_P (b, idx))
946 PER_BUFFER_VALUE (b, offset) = newval;
947 }
948 }
893 break; 949 break;
894 950
895 case Lisp_Misc_Buffer_Objfwd: 951 case Lisp_Misc_Buffer_Objfwd:
896 { 952 {
897 int offset = XBUFFER_OBJFWD (valcontents)->offset; 953 int offset = XBUFFER_OBJFWD (valcontents)->offset;
1447 register Lisp_Object variable; 1503 register Lisp_Object variable;
1448 { 1504 {
1449 register Lisp_Object tem, valcontents, newval; 1505 register Lisp_Object tem, valcontents, newval;
1450 1506
1451 CHECK_SYMBOL (variable); 1507 CHECK_SYMBOL (variable);
1508 variable = indirect_variable (variable);
1452 1509
1453 valcontents = SYMBOL_VALUE (variable); 1510 valcontents = SYMBOL_VALUE (variable);
1454 if (EQ (variable, Qnil) || EQ (variable, Qt) || KBOARD_OBJFWDP (valcontents)) 1511 if (EQ (variable, Qnil) || EQ (variable, Qt) || KBOARD_OBJFWDP (valcontents))
1455 error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable))); 1512 error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable)));
1456 1513
1500 register Lisp_Object variable; 1557 register Lisp_Object variable;
1501 { 1558 {
1502 register Lisp_Object tem, valcontents; 1559 register Lisp_Object tem, valcontents;
1503 1560
1504 CHECK_SYMBOL (variable); 1561 CHECK_SYMBOL (variable);
1562 variable = indirect_variable (variable);
1505 1563
1506 valcontents = SYMBOL_VALUE (variable); 1564 valcontents = SYMBOL_VALUE (variable);
1507 if (EQ (variable, Qnil) || EQ (variable, Qt) || KBOARD_OBJFWDP (valcontents)) 1565 if (EQ (variable, Qnil) || EQ (variable, Qt) || KBOARD_OBJFWDP (valcontents))
1508 error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable))); 1566 error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable)));
1509 1567
1579 register Lisp_Object variable; 1637 register Lisp_Object variable;
1580 { 1638 {
1581 register Lisp_Object tem, valcontents; 1639 register Lisp_Object tem, valcontents;
1582 1640
1583 CHECK_SYMBOL (variable); 1641 CHECK_SYMBOL (variable);
1642 variable = indirect_variable (variable);
1584 1643
1585 valcontents = SYMBOL_VALUE (variable); 1644 valcontents = SYMBOL_VALUE (variable);
1586 1645
1587 if (BUFFER_OBJFWDP (valcontents)) 1646 if (BUFFER_OBJFWDP (valcontents))
1588 { 1647 {
1643 register Lisp_Object variable; 1702 register Lisp_Object variable;
1644 { 1703 {
1645 register Lisp_Object tem, valcontents, newval; 1704 register Lisp_Object tem, valcontents, newval;
1646 1705
1647 CHECK_SYMBOL (variable); 1706 CHECK_SYMBOL (variable);
1707 variable = indirect_variable (variable);
1648 1708
1649 valcontents = SYMBOL_VALUE (variable); 1709 valcontents = SYMBOL_VALUE (variable);
1650 if (EQ (variable, Qnil) || EQ (variable, Qt) || KBOARD_OBJFWDP (valcontents) 1710 if (EQ (variable, Qnil) || EQ (variable, Qt) || KBOARD_OBJFWDP (valcontents)
1651 || BUFFER_OBJFWDP (valcontents)) 1711 || BUFFER_OBJFWDP (valcontents))
1652 error ("Symbol %s may not be frame-local", SDATA (SYMBOL_NAME (variable))); 1712 error ("Symbol %s may not be frame-local", SDATA (SYMBOL_NAME (variable)));
1692 CHECK_BUFFER (buffer); 1752 CHECK_BUFFER (buffer);
1693 buf = XBUFFER (buffer); 1753 buf = XBUFFER (buffer);
1694 } 1754 }
1695 1755
1696 CHECK_SYMBOL (variable); 1756 CHECK_SYMBOL (variable);
1757 variable = indirect_variable (variable);
1697 1758
1698 valcontents = SYMBOL_VALUE (variable); 1759 valcontents = SYMBOL_VALUE (variable);
1699 if (BUFFER_LOCAL_VALUEP (valcontents) 1760 if (BUFFER_LOCAL_VALUEP (valcontents)
1700 || SOME_BUFFER_LOCAL_VALUEP (valcontents)) 1761 || SOME_BUFFER_LOCAL_VALUEP (valcontents))
1701 { 1762 {
1702 Lisp_Object tail, elt; 1763 Lisp_Object tail, elt;
1703 1764
1704 variable = indirect_variable (variable);
1705 for (tail = buf->local_var_alist; CONSP (tail); tail = XCDR (tail)) 1765 for (tail = buf->local_var_alist; CONSP (tail); tail = XCDR (tail))
1706 { 1766 {
1707 elt = XCAR (tail); 1767 elt = XCAR (tail);
1708 if (EQ (variable, XCAR (elt))) 1768 if (EQ (variable, XCAR (elt)))
1709 return Qt; 1769 return Qt;
1736 CHECK_BUFFER (buffer); 1796 CHECK_BUFFER (buffer);
1737 buf = XBUFFER (buffer); 1797 buf = XBUFFER (buffer);
1738 } 1798 }
1739 1799
1740 CHECK_SYMBOL (variable); 1800 CHECK_SYMBOL (variable);
1801 variable = indirect_variable (variable);
1741 1802
1742 valcontents = SYMBOL_VALUE (variable); 1803 valcontents = SYMBOL_VALUE (variable);
1743 1804
1744 /* This means that make-variable-buffer-local was done. */ 1805 /* This means that make-variable-buffer-local was done. */
1745 if (BUFFER_LOCAL_VALUEP (valcontents)) 1806 if (BUFFER_LOCAL_VALUEP (valcontents))
1755 elt = XCAR (tail); 1816 elt = XCAR (tail);
1756 if (EQ (variable, XCAR (elt))) 1817 if (EQ (variable, XCAR (elt)))
1757 return Qt; 1818 return Qt;
1758 } 1819 }
1759 } 1820 }
1821 return Qnil;
1822 }
1823
1824 DEFUN ("variable-binding-locus", Fvariable_binding_locus, Svariable_binding_locus,
1825 1, 1, 0,
1826 doc: /* Return a value indicating where VARIABLE's current binding comes from.
1827 If the current binding is buffer-local, the value is the current buffer.
1828 If the current binding is frame-local, the value is the selected frame.
1829 If the current binding is global (the default), the value is nil. */)
1830 (variable)
1831 register Lisp_Object variable;
1832 {
1833 Lisp_Object valcontents;
1834
1835 CHECK_SYMBOL (variable);
1836 variable = indirect_variable (variable);
1837
1838 /* Make sure the current binding is actually swapped in. */
1839 find_symbol_value (variable);
1840
1841 valcontents = XSYMBOL (variable)->value;
1842
1843 if (BUFFER_LOCAL_VALUEP (valcontents)
1844 || SOME_BUFFER_LOCAL_VALUEP (valcontents)
1845 || BUFFER_OBJFWDP (valcontents))
1846 {
1847 /* For a local variable, record both the symbol and which
1848 buffer's or frame's value we are saving. */
1849 if (!NILP (Flocal_variable_p (variable, Qnil)))
1850 return Fcurrent_buffer ();
1851 else if (!BUFFER_OBJFWDP (valcontents)
1852 && XBUFFER_LOCAL_VALUE (valcontents)->found_for_frame)
1853 return XBUFFER_LOCAL_VALUE (valcontents)->frame;
1854 }
1855
1760 return Qnil; 1856 return Qnil;
1761 } 1857 }
1762 1858
1763 /* Find the function at the end of a chain of symbol function indirections. */ 1859 /* Find the function at the end of a chain of symbol function indirections. */
1764 1860
2699 { 2795 {
2700 CHECK_NUMBER (number); 2796 CHECK_NUMBER (number);
2701 XSETINT (number, ~XINT (number)); 2797 XSETINT (number, ~XINT (number));
2702 return number; 2798 return number;
2703 } 2799 }
2800
2801 DEFUN ("byteorder", Fbyteorder, Sbyteorder, 0, 0, 0,
2802 doc: /* Return the byteorder for the machine.
2803 Returns 66 (ASCII uppercase B) for big endian machines or 108 (ASCII
2804 lowercase l) for small endian machines. */)
2805 ()
2806 {
2807 unsigned i = 0x04030201;
2808 int order = *(char *)&i == 1 ? 108 : 66;
2809
2810 return make_number (order);
2811 }
2812
2813
2704 2814
2705 void 2815 void
2706 syms_of_data () 2816 syms_of_data ()
2707 { 2817 {
2708 Lisp_Object error_tail, arith_tail; 2818 Lisp_Object error_tail, arith_tail;
3015 staticpro (&Qchar_table); 3125 staticpro (&Qchar_table);
3016 staticpro (&Qbool_vector); 3126 staticpro (&Qbool_vector);
3017 staticpro (&Qhash_table); 3127 staticpro (&Qhash_table);
3018 3128
3019 defsubr (&Sindirect_variable); 3129 defsubr (&Sindirect_variable);
3020 defsubr (&Ssubr_interactive_form); 3130 defsubr (&Sinteractive_form);
3021 defsubr (&Seq); 3131 defsubr (&Seq);
3022 defsubr (&Snull); 3132 defsubr (&Snull);
3023 defsubr (&Stype_of); 3133 defsubr (&Stype_of);
3024 defsubr (&Slistp); 3134 defsubr (&Slistp);
3025 defsubr (&Snlistp); 3135 defsubr (&Snlistp);
3073 defsubr (&Smake_local_variable); 3183 defsubr (&Smake_local_variable);
3074 defsubr (&Skill_local_variable); 3184 defsubr (&Skill_local_variable);
3075 defsubr (&Smake_variable_frame_local); 3185 defsubr (&Smake_variable_frame_local);
3076 defsubr (&Slocal_variable_p); 3186 defsubr (&Slocal_variable_p);
3077 defsubr (&Slocal_variable_if_set_p); 3187 defsubr (&Slocal_variable_if_set_p);
3188 defsubr (&Svariable_binding_locus);
3078 defsubr (&Saref); 3189 defsubr (&Saref);
3079 defsubr (&Saset); 3190 defsubr (&Saset);
3080 defsubr (&Snumber_to_string); 3191 defsubr (&Snumber_to_string);
3081 defsubr (&Sstring_to_number); 3192 defsubr (&Sstring_to_number);
3082 defsubr (&Seqlsign); 3193 defsubr (&Seqlsign);
3100 defsubr (&Slsh); 3211 defsubr (&Slsh);
3101 defsubr (&Sash); 3212 defsubr (&Sash);
3102 defsubr (&Sadd1); 3213 defsubr (&Sadd1);
3103 defsubr (&Ssub1); 3214 defsubr (&Ssub1);
3104 defsubr (&Slognot); 3215 defsubr (&Slognot);
3216 defsubr (&Sbyteorder);
3105 defsubr (&Ssubr_arity); 3217 defsubr (&Ssubr_arity);
3106 3218
3107 XSYMBOL (Qwholenump)->function = XSYMBOL (Qnatnump)->function; 3219 XSYMBOL (Qwholenump)->function = XSYMBOL (Qnatnump)->function;
3108 3220
3109 DEFVAR_LISP ("most-positive-fixnum", &Vmost_positive_fixnum, 3221 DEFVAR_LISP ("most-positive-fixnum", &Vmost_positive_fixnum,
3152 3264
3153 #ifdef uts 3265 #ifdef uts
3154 signal (SIGEMT, arith_error); 3266 signal (SIGEMT, arith_error);
3155 #endif /* uts */ 3267 #endif /* uts */
3156 } 3268 }
3269
3270 /* arch-tag: 25879798-b84d-479a-9c89-7d148e2109f7
3271 (do not change this comment) */