aboutsummaryrefslogtreecommitdiffstats
path: root/src/lread.c
diff options
context:
space:
mode:
authorPaul Eggert2015-01-05 09:07:45 -0800
committerPaul Eggert2015-01-05 10:14:58 -0800
commit58f2d6ef32b28a787fcc4e0d98b3f331ceb2a68c (patch)
treed6d79ad7b7cceafc78c5a9c54f5be1ac441a8ed7 /src/lread.c
parentd2cf05d1bac19d8564d0806f515b9f40fe57f4df (diff)
downloademacs-58f2d6ef32b28a787fcc4e0d98b3f331ceb2a68c.tar.gz
emacs-58f2d6ef32b28a787fcc4e0d98b3f331ceb2a68c.zip
Compute C decls for DEFSYMs automatically
Fixes Bug#15880. This patch also makes Q constants (e.g., Qnil) constant addresses from the C point of view. * make-docfile.c: Revamp to generate table of symbols, too. Include <stdbool.h>. (xstrdup): New function. (main): Don't process the same file twice. (SYMBOL): New constant in enum global_type. (struct symbol): Turn 'value' member into a union, either v.value for int or v.svalue for string. All uses changed. (add_global): New arg svalue, which overrides value, so that globals can have a string value. (close_emacs_global): New arg num_symbols; all uses changed. Output lispsym decl. (write_globals): Output symbol globals too. Output more ATTRIBUTE_CONST, now that Qnil etc. are C constants. Output defsym_name table. (scan_c_file): Move most of guts into ... (scan_c_stream): ... new function. Scan for DEFSYMs and record symbols found. Don't read past EOF if file doesn't end in newline. * alloc.c, bidi.c, buffer.c, bytecode.c, callint.c, casefiddle: * casetab.c, category.c, ccl.c, charset.c, chartab.c, cmds.c, coding.c: * composite.c, data.c, dbusbind.c, decompress.c, dired.c, dispnew.c: * doc.c, editfns.c, emacs.c, eval.c, fileio.c, fns.c, font.c, fontset.c: * frame.c, fringe.c, ftfont.c, ftxfont.c, gfilenotify.c, gnutls.c: * image.c, inotify.c, insdel.c, keyboard.c, keymap.c, lread.c: * macfont.m, macros.c, minibuf.c, nsfns.m, nsfont.m, nsimage.m: * nsmenu.m, nsselect.m, nsterm.m, print.c, process.c, profiler.c: * search.c, sound.c, syntax.c, term.c, terminal.c, textprop.c, undo.c: * window.c, xdisp.c, xfaces.c, xfns.c, xftfont.c, xmenu.c, xml.c: * xselect.c, xsettings.c, xterm.c: Remove Q vars that represent symbols (e.g., Qnil, Qt, Qemacs). These names are now defined automatically by make-docfile. * alloc.c (init_symbol): New function. (Fmake_symbol): Use it. (c_symbol_p): New function. (valid_lisp_object_p, purecopy): Use it. * alloc.c (marked_pinned_symbols): Use make_lisp_symbol instead of make_lisp_ptr. (garbage_collect_1): Mark lispsym symbols. (CHECK_ALLOCATED_AND_LIVE_SYMBOL): New macro. (mark_object): Use it. (sweep_symbols): Sweep lispsym symbols. (symbol_uses_obj): New function. (which_symbols): Use it. Work for lispsym symbols, too. (init_alloc_once): Initialize Vpurify_flag here; no need to wait, since Qt's address is already known now. (syms_of_alloc): Add lispsym count to symbols_consed. * buffer.c (init_buffer_once): Compare to Qnil, not to make_number (0), when testing whether storage is all bits zero. * dispextern (struct image_type): * font.c (font_property_table): * frame.c (struct frame_parm_table, frame_parms): * keyboard.c (scroll_bar_parts, struct event_head): * xdisp.c (struct props): Use XSYMBOL_INIT (Qfoo) and struct Lisp_Symbol * rather than &Qfoo and Lisp_Object *, since Qfoo is no longer an object whose address can be taken. All uses changed. * eval.c (run_hook): New function. Most uses of Frun_hooks changed to use it, so that they no longer need to take the address of a Lisp sym. (syms_of_eval): Don't use DEFSYM on Vrun_hooks, as it's a variable. * frame.c (syms_of_frame): Add defsyms for the frame_parms table. * keyboard.c (syms_of_keyboard): Don't DEFSYM Qmenu_bar here. DEFSYM Qdeactivate_mark before the corresponding var. * keymap.c (syms_of_keymap): Use DEFSYM for Qmenu_bar and Qmode_line instead of interning their symbols; this avoids duplicates. (LISP_INITIALLY, TAG_PTR) (DEFINE_LISP_SYMBOL_BEGIN, DEFINE_LISP_SYMBOL_END, XSYMBOL_INIT): New macros. (LISP_INITIALLY_ZERO): Use it. (enum symbol_interned, enum symbol_redirect, struct Lisp_Symbol) (EXFUN, DEFUN_ARGS_MANY, DEFUN_ARGS_UNEVALLED, DEFUN_ARGS_*): Move decls up, to avoid forward uses. Include globals.h earlier, too. (make_lisp_symbol): New function. (XSETSYMBOL): Use it. (DEFSYM): Now just a placeholder for make-docfile. * lread.c (DEFINE_SYMBOLS): Define, for globals.h. (intern_sym): New function, with body taken from old intern_driver. (intern_driver): Use it. Last arg is now Lisp integer, not ptrdiff_t. All uses changed. (define_symbol): New function. (init_obarray): Define the C symbols taken from lispsym. Use plain DEFSYM for Qt and Qnil. * syntax.c (init_syntax_once): No need to worry about Qchar_table_extra_slots.
Diffstat (limited to 'src/lread.c')
-rw-r--r--src/lread.c101
1 files changed, 48 insertions, 53 deletions
diff --git a/src/lread.c b/src/lread.c
index 6463e1051b5..324052462fe 100644
--- a/src/lread.c
+++ b/src/lread.c
@@ -18,6 +18,8 @@ GNU General Public License for more details.
18You should have received a copy of the GNU General Public License 18You should have received a copy of the GNU General Public License
19along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */ 19along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 20
21/* Tell globals.h to define tables needed by init_obarray. */
22#define DEFINE_SYMBOLS
21 23
22#include <config.h> 24#include <config.h>
23#include "sysstdio.h" 25#include "sysstdio.h"
@@ -64,32 +66,6 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
64#define file_tell ftell 66#define file_tell ftell
65#endif 67#endif
66 68
67/* Hash table read constants. */
68static Lisp_Object Qhash_table, Qdata;
69static Lisp_Object Qtest;
70Lisp_Object Qsize;
71static Lisp_Object Qweakness;
72static Lisp_Object Qrehash_size;
73static Lisp_Object Qrehash_threshold;
74
75static Lisp_Object Qread_char, Qget_file_char, Qcurrent_load_list;
76Lisp_Object Qstandard_input;
77Lisp_Object Qvariable_documentation;
78static Lisp_Object Qascii_character, Qload, Qload_file_name;
79Lisp_Object Qbackquote, Qcomma, Qcomma_at, Qcomma_dot, Qfunction;
80static Lisp_Object Qinhibit_file_name_operation;
81static Lisp_Object Qeval_buffer_list;
82Lisp_Object Qlexical_binding;
83static Lisp_Object Qfile_truename, Qdo_after_load_evaluation; /* ACM 2006/5/16 */
84
85/* Used instead of Qget_file_char while loading *.elc files compiled
86 by Emacs 21 or older. */
87static Lisp_Object Qget_emacs_mule_file_char;
88
89static Lisp_Object Qload_force_doc_strings;
90
91static Lisp_Object Qload_in_progress;
92
93/* The association list of objects read with the #n=object form. 69/* The association list of objects read with the #n=object form.
94 Each member of the list has the form (n . object), and is used to 70 Each member of the list has the form (n . object), and is used to
95 look up the object for the corresponding #n# construct. 71 look up the object for the corresponding #n# construct.
@@ -133,7 +109,6 @@ static file_offset prev_saved_doc_string_position;
133 Fread initializes this to false, so we need not specbind it 109 Fread initializes this to false, so we need not specbind it
134 or worry about what happens to it when there is an error. */ 110 or worry about what happens to it when there is an error. */
135static bool new_backquote_flag; 111static bool new_backquote_flag;
136static Lisp_Object Qold_style_backquotes;
137 112
138/* A list of file names for files being loaded in Fload. Used to 113/* A list of file names for files being loaded in Fload. Used to
139 check for recursive loads. */ 114 check for recursive loads. */
@@ -1430,8 +1405,6 @@ directories, make sure the PREDICATE function returns `dir-ok' for them. */)
1430 return file; 1405 return file;
1431} 1406}
1432 1407
1433static Lisp_Object Qdir_ok;
1434
1435/* Search for a file whose name is STR, looking in directories 1408/* Search for a file whose name is STR, looking in directories
1436 in the Lisp list PATH, and trying suffixes from SUFFIX. 1409 in the Lisp list PATH, and trying suffixes from SUFFIX.
1437 On success, return a file descriptor (or 1 or -2 as described below). 1410 On success, return a file descriptor (or 1 or -2 as described below).
@@ -3792,30 +3765,38 @@ check_obarray (Lisp_Object obarray)
3792 return obarray; 3765 return obarray;
3793} 3766}
3794 3767
3795/* Intern a symbol with name STRING in OBARRAY using bucket INDEX. */ 3768/* Intern symbol SYM in OBARRAY using bucket INDEX. */
3796 3769
3797Lisp_Object 3770static Lisp_Object
3798intern_driver (Lisp_Object string, Lisp_Object obarray, ptrdiff_t index) 3771intern_sym (Lisp_Object sym, Lisp_Object obarray, Lisp_Object index)
3799{ 3772{
3800 Lisp_Object *ptr, sym = Fmake_symbol (string); 3773 Lisp_Object *ptr;
3801 3774
3802 XSYMBOL (sym)->interned = (EQ (obarray, initial_obarray) 3775 XSYMBOL (sym)->interned = (EQ (obarray, initial_obarray)
3803 ? SYMBOL_INTERNED_IN_INITIAL_OBARRAY 3776 ? SYMBOL_INTERNED_IN_INITIAL_OBARRAY
3804 : SYMBOL_INTERNED); 3777 : SYMBOL_INTERNED);
3805 3778
3806 if ((SREF (string, 0) == ':') && EQ (obarray, initial_obarray)) 3779 if (SREF (SYMBOL_NAME (sym), 0) == ':' && EQ (obarray, initial_obarray))
3807 { 3780 {
3808 XSYMBOL (sym)->constant = 1; 3781 XSYMBOL (sym)->constant = 1;
3809 XSYMBOL (sym)->redirect = SYMBOL_PLAINVAL; 3782 XSYMBOL (sym)->redirect = SYMBOL_PLAINVAL;
3810 SET_SYMBOL_VAL (XSYMBOL (sym), sym); 3783 SET_SYMBOL_VAL (XSYMBOL (sym), sym);
3811 } 3784 }
3812 3785
3813 ptr = aref_addr (obarray, index); 3786 ptr = aref_addr (obarray, XINT (index));
3814 set_symbol_next (sym, SYMBOLP (*ptr) ? XSYMBOL (*ptr) : NULL); 3787 set_symbol_next (sym, SYMBOLP (*ptr) ? XSYMBOL (*ptr) : NULL);
3815 *ptr = sym; 3788 *ptr = sym;
3816 return sym; 3789 return sym;
3817} 3790}
3818 3791
3792/* Intern a symbol with name STRING in OBARRAY using bucket INDEX. */
3793
3794Lisp_Object
3795intern_driver (Lisp_Object string, Lisp_Object obarray, Lisp_Object index)
3796{
3797 return intern_sym (Fmake_symbol (string), obarray, index);
3798}
3799
3819/* Intern the C string STR: return a symbol with that name, 3800/* Intern the C string STR: return a symbol with that name,
3820 interned in the current obarray. */ 3801 interned in the current obarray. */
3821 3802
@@ -3826,7 +3807,7 @@ intern_1 (const char *str, ptrdiff_t len)
3826 Lisp_Object tem = oblookup (obarray, str, len, len); 3807 Lisp_Object tem = oblookup (obarray, str, len, len);
3827 3808
3828 return SYMBOLP (tem) ? tem : intern_driver (make_string (str, len), 3809 return SYMBOLP (tem) ? tem : intern_driver (make_string (str, len),
3829 obarray, XINT (tem)); 3810 obarray, tem);
3830} 3811}
3831 3812
3832Lisp_Object 3813Lisp_Object
@@ -3840,10 +3821,27 @@ intern_c_string_1 (const char *str, ptrdiff_t len)
3840 /* Creating a non-pure string from a string literal not implemented yet. 3821 /* Creating a non-pure string from a string literal not implemented yet.
3841 We could just use make_string here and live with the extra copy. */ 3822 We could just use make_string here and live with the extra copy. */
3842 eassert (!NILP (Vpurify_flag)); 3823 eassert (!NILP (Vpurify_flag));
3843 tem = intern_driver (make_pure_c_string (str, len), obarray, XINT (tem)); 3824 tem = intern_driver (make_pure_c_string (str, len), obarray, tem);
3844 } 3825 }
3845 return tem; 3826 return tem;
3846} 3827}
3828
3829static void
3830define_symbol (Lisp_Object sym, char const *str)
3831{
3832 ptrdiff_t len = strlen (str);
3833 Lisp_Object string = make_pure_c_string (str, len);
3834 init_symbol (sym, string);
3835
3836 /* Qunbound is uninterned, so that it's not confused with any symbol
3837 'unbound' created by a Lisp program. */
3838 if (! EQ (sym, Qunbound))
3839 {
3840 Lisp_Object bucket = oblookup (initial_obarray, str, len, len);
3841 eassert (INTEGERP (bucket));
3842 intern_sym (sym, initial_obarray, bucket);
3843 }
3844}
3847 3845
3848DEFUN ("intern", Fintern, Sintern, 1, 2, 0, 3846DEFUN ("intern", Fintern, Sintern, 1, 2, 0,
3849 doc: /* Return the canonical symbol whose name is STRING. 3847 doc: /* Return the canonical symbol whose name is STRING.
@@ -3859,8 +3857,8 @@ it defaults to the value of `obarray'. */)
3859 3857
3860 tem = oblookup (obarray, SSDATA (string), SCHARS (string), SBYTES (string)); 3858 tem = oblookup (obarray, SSDATA (string), SCHARS (string), SBYTES (string));
3861 if (!SYMBOLP (tem)) 3859 if (!SYMBOLP (tem))
3862 tem = intern_driver (NILP (Vpurify_flag) ? string 3860 tem = intern_driver (NILP (Vpurify_flag) ? string : Fpurecopy (string),
3863 : Fpurecopy (string), obarray, XINT (tem)); 3861 obarray, tem);
3864 return tem; 3862 return tem;
3865} 3863}
3866 3864
@@ -4059,24 +4057,17 @@ init_obarray (void)
4059 initial_obarray = Vobarray; 4057 initial_obarray = Vobarray;
4060 staticpro (&initial_obarray); 4058 staticpro (&initial_obarray);
4061 4059
4062 Qunbound = Fmake_symbol (build_pure_c_string ("unbound")); 4060 for (int i = 0; i < ARRAYELTS (lispsym); i++)
4063 /* Set temporary dummy values to Qnil and Vpurify_flag to satisfy the 4061 define_symbol (make_lisp_symbol (&lispsym[i]), defsym_name[i]);
4064 NILP (Vpurify_flag) check in intern_c_string. */ 4062
4065 Qnil = make_number (-1); Vpurify_flag = make_number (1); 4063 DEFSYM (Qunbound, "unbound");
4066 Qnil = intern_c_string ("nil"); 4064
4067 4065 DEFSYM (Qnil, "nil");
4068 /* Fmake_symbol inits fields of new symbols with Qunbound and Qnil,
4069 so those two need to be fixed manually. */
4070 SET_SYMBOL_VAL (XSYMBOL (Qunbound), Qunbound);
4071 set_symbol_function (Qunbound, Qnil);
4072 set_symbol_plist (Qunbound, Qnil);
4073 SET_SYMBOL_VAL (XSYMBOL (Qnil), Qnil); 4066 SET_SYMBOL_VAL (XSYMBOL (Qnil), Qnil);
4074 XSYMBOL (Qnil)->constant = 1; 4067 XSYMBOL (Qnil)->constant = 1;
4075 XSYMBOL (Qnil)->declared_special = true; 4068 XSYMBOL (Qnil)->declared_special = true;
4076 set_symbol_plist (Qnil, Qnil);
4077 set_symbol_function (Qnil, Qnil);
4078 4069
4079 Qt = intern_c_string ("t"); 4070 DEFSYM (Qt, "t");
4080 SET_SYMBOL_VAL (XSYMBOL (Qt), Qt); 4071 SET_SYMBOL_VAL (XSYMBOL (Qt), Qt);
4081 XSYMBOL (Qt)->constant = 1; 4072 XSYMBOL (Qt)->constant = 1;
4082 XSYMBOL (Qt)->declared_special = true; 4073 XSYMBOL (Qt)->declared_special = true;
@@ -4729,7 +4720,11 @@ that are loaded before your customizations are read! */);
4729 DEFSYM (Qstandard_input, "standard-input"); 4720 DEFSYM (Qstandard_input, "standard-input");
4730 DEFSYM (Qread_char, "read-char"); 4721 DEFSYM (Qread_char, "read-char");
4731 DEFSYM (Qget_file_char, "get-file-char"); 4722 DEFSYM (Qget_file_char, "get-file-char");
4723
4724 /* Used instead of Qget_file_char while loading *.elc files compiled
4725 by Emacs 21 or older. */
4732 DEFSYM (Qget_emacs_mule_file_char, "get-emacs-mule-file-char"); 4726 DEFSYM (Qget_emacs_mule_file_char, "get-emacs-mule-file-char");
4727
4733 DEFSYM (Qload_force_doc_strings, "load-force-doc-strings"); 4728 DEFSYM (Qload_force_doc_strings, "load-force-doc-strings");
4734 4729
4735 DEFSYM (Qbackquote, "`"); 4730 DEFSYM (Qbackquote, "`");