From 844e0de1bc2bf56118b749f50a4880db7c918fd5 Mon Sep 17 00:00:00 2001 From: BT Templeton Date: Sat, 21 Sep 2013 03:24:01 -0400 Subject: [PATCH] use vectors for symbol slots * src/alloc.c (initialize_symbol): Use Guile vectors to store symbol slots. * src/lisp.h (lisp_h_SET_SYMBOL_VAL, lisp_h_SYMBOL_CONSTANT_P) (lisp_h_SYMBOL_VAL): Use Guile vectors to store symbol slots. (sym_t): New typedef. (SYMBOL_SELF, SET_SYMBOL_SELF, SYMBOL_REDIRECT, SET_SYMBOL_REDIRECT) (SYMBOL_CONSTANT, SET_SYMBOL_CONSTANT, SYMBOL_DECLARED_SPECIAL) (SET_SYMBOL_DECLARED_SPECIAL): New macros. (struct Lisp_Symbol): Change all field names. All references changed to use `sym_t' and the above macros instead. --- src/alloc.c | 12 +++---- src/buffer.c | 18 +++++----- src/bytecode.c | 4 +-- src/data.c | 88 ++++++++++++++++++++++----------------------- src/eval.c | 52 +++++++++++++-------------- src/font.c | 6 ++-- src/frame.c | 6 ++-- src/lisp.h | 96 ++++++++++++++++++++++++++++---------------------- src/lread.c | 30 ++++++++-------- 9 files changed, 161 insertions(+), 151 deletions(-) diff --git a/src/alloc.c b/src/alloc.c index 3fe4601010..a300396514 100644 --- a/src/alloc.c +++ b/src/alloc.c @@ -1168,17 +1168,17 @@ usage: (make-byte-code ARGLIST BYTE-CODE CONSTANTS DEPTH &optional DOCSTRING INT void initialize_symbol (Lisp_Object val, Lisp_Object name) { - struct Lisp_Symbol *p = xmalloc (sizeof *p); + sym_t p; - scm_module_define (symbol_module, val, scm_from_pointer (p, NULL)); + scm_module_define (symbol_module, val, scm_c_make_vector (5, SCM_BOOL_F)); p = XSYMBOL (val); - p->self = val; + SET_SYMBOL_SELF (p, val); scm_module_define (plist_module, val, Qnil); - p->redirect = SYMBOL_PLAINVAL; + SET_SYMBOL_REDIRECT (p, SYMBOL_PLAINVAL); SET_SYMBOL_VAL (p, Qunbound); scm_module_define (function_module, val, Qnil); - p->constant = 0; - p->declared_special = false; + SET_SYMBOL_CONSTANT (p, 0); + SET_SYMBOL_DECLARED_SPECIAL (p, false); } DEFUN ("make-symbol", Fmake_symbol, Smake_symbol, 1, 1, 0, diff --git a/src/buffer.c b/src/buffer.c index 7f0f2cc7d0..f310a2c9d8 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -1182,7 +1182,7 @@ buffer_local_value (Lisp_Object variable, Lisp_Object buffer) { register struct buffer *buf; register Lisp_Object result; - struct Lisp_Symbol *sym; + sym_t sym; CHECK_SYMBOL (variable); CHECK_BUFFER (buffer); @@ -1190,7 +1190,7 @@ buffer_local_value (Lisp_Object variable, Lisp_Object buffer) sym = XSYMBOL (variable); start: - switch (sym->redirect) + switch (SYMBOL_REDIRECT (sym)) { case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; case SYMBOL_PLAINVAL: result = SYMBOL_VAL (sym); break; @@ -2159,8 +2159,8 @@ set_buffer_internal_1 (register struct buffer *b) for (tail = BVAR (b, local_var_alist); CONSP (tail); tail = XCDR (tail)) { Lisp_Object var = XCAR (XCAR (tail)); - struct Lisp_Symbol *sym = XSYMBOL (var); - if (sym->redirect == SYMBOL_LOCALIZED /* Just to be sure. */ + sym_t sym = XSYMBOL (var); + if (SYMBOL_REDIRECT (sym) == SYMBOL_LOCALIZED /* Just to be sure. */ && SYMBOL_BLV (sym)->fwd) /* Just reference the variable to cause it to become set for this buffer. */ @@ -2801,7 +2801,7 @@ swap_out_buffer_local_variables (struct buffer *b) for (alist = oalist; CONSP (alist); alist = XCDR (alist)) { Lisp_Object sym = XCAR (XCAR (alist)); - eassert (XSYMBOL (sym)->redirect == SYMBOL_LOCALIZED); + eassert (SYMBOL_REDIRECT (XSYMBOL (sym)) == SYMBOL_LOCALIZED); /* Need not do anything if some other buffer's binding is now cached. */ if (EQ (SYMBOL_BLV (XSYMBOL (sym))->where, buffer)) @@ -5403,7 +5403,7 @@ static void defvar_per_buffer (struct Lisp_Buffer_Objfwd *bo_fwd, const char *namestring, Lisp_Object *address, Lisp_Object predicate) { - struct Lisp_Symbol *sym; + sym_t sym; int offset; sym = XSYMBOL (intern (namestring)); @@ -5412,8 +5412,8 @@ defvar_per_buffer (struct Lisp_Buffer_Objfwd *bo_fwd, const char *namestring, bo_fwd->type = Lisp_Fwd_Buffer_Obj; bo_fwd->offset = offset; bo_fwd->predicate = predicate; - sym->declared_special = 1; - sym->redirect = SYMBOL_FORWARDED; + SET_SYMBOL_DECLARED_SPECIAL (sym, 1); + SET_SYMBOL_REDIRECT (sym, SYMBOL_FORWARDED); SET_SYMBOL_FWD (sym, (union Lisp_Fwd *) bo_fwd); XSETSYMBOL (PER_BUFFER_SYMBOL (offset), sym); @@ -5737,7 +5737,7 @@ file I/O and the behavior of various editing commands. This variable is buffer-local but you cannot set it directly; use the function `set-buffer-multibyte' to change a buffer's representation. See also Info node `(elisp)Text Representations'. */); - XSYMBOL (intern_c_string ("enable-multibyte-characters"))->constant = 1; + SET_SYMBOL_CONSTANT (XSYMBOL (intern_c_string ("enable-multibyte-characters")), 1); DEFVAR_PER_BUFFER ("buffer-file-coding-system", &BVAR (current_buffer, buffer_file_coding_system), Qnil, diff --git a/src/bytecode.c b/src/bytecode.c index 6e91da11a1..7e7063e131 100644 --- a/src/bytecode.c +++ b/src/bytecode.c @@ -647,7 +647,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, v1 = vectorp[op]; if (SYMBOLP (v1)) { - if (XSYMBOL (v1)->redirect != SYMBOL_PLAINVAL + if (SYMBOL_REDIRECT (XSYMBOL (v1)) != SYMBOL_PLAINVAL || (v2 = SYMBOL_VAL (XSYMBOL (v1)), EQ (v2, Qunbound))) { @@ -756,7 +756,7 @@ exec_byte_code (Lisp_Object bytestr, Lisp_Object vector, Lisp_Object maxdepth, /* Inline the most common case. */ if (SYMBOLP (sym) && !EQ (val, Qunbound) - && !XSYMBOL (sym)->redirect + && !SYMBOL_REDIRECT (XSYMBOL (sym)) && !SYMBOL_CONSTANT_P (sym)) SET_SYMBOL_VAL (XSYMBOL (sym), val); else diff --git a/src/data.c b/src/data.c index 7422f4e8b8..79e605b731 100644 --- a/src/data.c +++ b/src/data.c @@ -91,7 +91,7 @@ Lisp_Object Qspecial_operator; Lisp_Object Qinteractive_form; static Lisp_Object Qdefalias_fset_function; -static void swap_in_symval_forwarding (struct Lisp_Symbol *, struct Lisp_Buffer_Local_Value *); +static void swap_in_symval_forwarding (sym_t, struct Lisp_Buffer_Local_Value *); static bool BOOLFWDP (union Lisp_Fwd *a) @@ -620,12 +620,12 @@ global value outside of any lexical scope. */) (register Lisp_Object symbol) { Lisp_Object valcontents; - struct Lisp_Symbol *sym; + sym_t sym; CHECK_SYMBOL (symbol); sym = XSYMBOL (symbol); start: - switch (sym->redirect) + switch (SYMBOL_REDIRECT (sym)) { case SYMBOL_PLAINVAL: valcontents = SYMBOL_VAL (sym); break; case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; @@ -893,17 +893,17 @@ Value, if non-nil, is a list \(interactive SPEC). */) `cyclic-variable-indirection' if SYMBOL's chain of variable indirections contains a loop. */ -struct Lisp_Symbol * -indirect_variable (struct Lisp_Symbol *symbol) +sym_t +indirect_variable (sym_t symbol) { - struct Lisp_Symbol *tortoise, *hare; + sym_t tortoise, hare; hare = tortoise = symbol; - while (hare->redirect == SYMBOL_VARALIAS) + while (SYMBOL_REDIRECT (hare) == SYMBOL_VARALIAS) { hare = SYMBOL_ALIAS (hare); - if (hare->redirect != SYMBOL_VARALIAS) + if (SYMBOL_REDIRECT (hare) != SYMBOL_VARALIAS) break; hare = SYMBOL_ALIAS (hare); @@ -933,7 +933,7 @@ chain of aliases, signal a `cyclic-variable-indirection' error. */) { if (SYMBOLP (object)) { - struct Lisp_Symbol *sym = indirect_variable (XSYMBOL (object)); + sym_t sym = indirect_variable (XSYMBOL (object)); XSETSYMBOL (object, sym); } return object; @@ -1068,7 +1068,7 @@ store_symval_forwarding (union Lisp_Fwd *valcontents, register Lisp_Object newva of BLV are marked after this function has changed them. */ void -swap_in_global_binding (struct Lisp_Symbol *symbol) +swap_in_global_binding (sym_t symbol) { struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (symbol); @@ -1094,7 +1094,7 @@ swap_in_global_binding (struct Lisp_Symbol *symbol) This could be another forwarding pointer. */ static void -swap_in_symval_forwarding (struct Lisp_Symbol *symbol, struct Lisp_Buffer_Local_Value *blv) +swap_in_symval_forwarding (sym_t symbol, struct Lisp_Buffer_Local_Value *blv) { register Lisp_Object tem1; @@ -1146,13 +1146,13 @@ swap_in_symval_forwarding (struct Lisp_Symbol *symbol, struct Lisp_Buffer_Local_ Lisp_Object find_symbol_value (Lisp_Object symbol) { - struct Lisp_Symbol *sym; + sym_t sym; CHECK_SYMBOL (symbol); sym = XSYMBOL (symbol); start: - switch (sym->redirect) + switch (SYMBOL_REDIRECT (sym)) { case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; case SYMBOL_PLAINVAL: return SYMBOL_VAL (sym); @@ -1205,7 +1205,7 @@ set_internal (Lisp_Object symbol, Lisp_Object newval, Lisp_Object where, bool bindflag) { bool voide = EQ (newval, Qunbound); - struct Lisp_Symbol *sym; + sym_t sym; Lisp_Object tem1; /* If restoring in a dead buffer, do nothing. */ @@ -1226,7 +1226,7 @@ set_internal (Lisp_Object symbol, Lisp_Object newval, Lisp_Object where, sym = XSYMBOL (symbol); start: - switch (sym->redirect) + switch (SYMBOL_REDIRECT (sym)) { case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; case SYMBOL_PLAINVAL: SET_SYMBOL_VAL (sym , newval); return; @@ -1336,7 +1336,7 @@ set_internal (Lisp_Object symbol, Lisp_Object newval, Lisp_Object where, if (voide) { /* If storing void (making the symbol void), forward only through buffer-local indicator, not through Lisp_Objfwd, etc. */ - sym->redirect = SYMBOL_PLAINVAL; + SET_SYMBOL_REDIRECT (sym, SYMBOL_PLAINVAL); SET_SYMBOL_VAL (sym, newval); } else @@ -1356,13 +1356,13 @@ set_internal (Lisp_Object symbol, Lisp_Object newval, Lisp_Object where, static Lisp_Object default_value (Lisp_Object symbol) { - struct Lisp_Symbol *sym; + sym_t sym; CHECK_SYMBOL (symbol); sym = XSYMBOL (symbol); start: - switch (sym->redirect) + switch (SYMBOL_REDIRECT (sym)) { case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; case SYMBOL_PLAINVAL: return SYMBOL_VAL (sym); @@ -1430,7 +1430,7 @@ The default value is seen in buffers that do not have their own values for this variable. */) (Lisp_Object symbol, Lisp_Object value) { - struct Lisp_Symbol *sym; + sym_t sym; CHECK_SYMBOL (symbol); if (SYMBOL_CONSTANT_P (symbol)) @@ -1445,7 +1445,7 @@ for this variable. */) sym = XSYMBOL (symbol); start: - switch (sym->redirect) + switch (SYMBOL_REDIRECT (sym)) { case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; case SYMBOL_PLAINVAL: return Fset (symbol, value); @@ -1536,7 +1536,7 @@ union Lisp_Val_Fwd }; static struct Lisp_Buffer_Local_Value * -make_blv (struct Lisp_Symbol *sym, bool forwarded, +make_blv (sym_t sym, bool forwarded, union Lisp_Val_Fwd valcontents) { struct Lisp_Buffer_Local_Value *blv = xmalloc (sizeof *blv); @@ -1582,7 +1582,7 @@ property. The function `default-value' gets the default value and `set-default' sets it. */) (register Lisp_Object variable) { - struct Lisp_Symbol *sym; + sym_t sym; struct Lisp_Buffer_Local_Value *blv = NULL; union Lisp_Val_Fwd valcontents IF_LINT (= {LISP_INITIALLY_ZERO}); bool forwarded IF_LINT (= 0); @@ -1591,7 +1591,7 @@ The function `default-value' gets the default value and `set-default' sets it. sym = XSYMBOL (variable); start: - switch (sym->redirect) + switch (SYMBOL_REDIRECT (sym)) { case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; case SYMBOL_PLAINVAL: @@ -1616,13 +1616,13 @@ The function `default-value' gets the default value and `set-default' sets it. default: emacs_abort (); } - if (sym->constant) + if (SYMBOL_CONSTANT (sym)) error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable))); if (!blv) { blv = make_blv (sym, forwarded, valcontents); - sym->redirect = SYMBOL_LOCALIZED; + SET_SYMBOL_REDIRECT (sym, SYMBOL_LOCALIZED); SET_SYMBOL_BLV (sym, blv); { Lisp_Object symbol; @@ -1662,14 +1662,14 @@ Instead, use `add-hook' and specify t for the LOCAL argument. */) Lisp_Object tem; bool forwarded IF_LINT (= 0); union Lisp_Val_Fwd valcontents IF_LINT (= {LISP_INITIALLY_ZERO}); - struct Lisp_Symbol *sym; + sym_t sym; struct Lisp_Buffer_Local_Value *blv = NULL; CHECK_SYMBOL (variable); sym = XSYMBOL (variable); start: - switch (sym->redirect) + switch (SYMBOL_REDIRECT (sym)) { case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; case SYMBOL_PLAINVAL: @@ -1689,7 +1689,7 @@ Instead, use `add-hook' and specify t for the LOCAL argument. */) default: emacs_abort (); } - if (sym->constant) + if (SYMBOL_CONSTANT (sym)) error ("Symbol %s may not be buffer-local", SDATA (SYMBOL_NAME (variable))); @@ -1705,7 +1705,7 @@ Instead, use `add-hook' and specify t for the LOCAL argument. */) if (!blv) { blv = make_blv (sym, forwarded, valcontents); - sym->redirect = SYMBOL_LOCALIZED; + SET_SYMBOL_REDIRECT (sym, SYMBOL_LOCALIZED); SET_SYMBOL_BLV (sym, blv); { Lisp_Object symbol; @@ -1761,13 +1761,13 @@ From now on the default value will apply in this buffer. Return VARIABLE. */) { register Lisp_Object tem; struct Lisp_Buffer_Local_Value *blv; - struct Lisp_Symbol *sym; + sym_t sym; CHECK_SYMBOL (variable); sym = XSYMBOL (variable); start: - switch (sym->redirect) + switch (SYMBOL_REDIRECT (sym)) { case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; case SYMBOL_PLAINVAL: return variable; @@ -1848,14 +1848,14 @@ frame-local bindings). */) { bool forwarded; union Lisp_Val_Fwd valcontents; - struct Lisp_Symbol *sym; + sym_t sym; struct Lisp_Buffer_Local_Value *blv = NULL; CHECK_SYMBOL (variable); sym = XSYMBOL (variable); start: - switch (sym->redirect) + switch (SYMBOL_REDIRECT (sym)) { case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; case SYMBOL_PLAINVAL: @@ -1878,12 +1878,12 @@ frame-local bindings). */) default: emacs_abort (); } - if (sym->constant) + if (SYMBOL_CONSTANT (sym)) error ("Symbol %s may not be frame-local", SDATA (SYMBOL_NAME (variable))); blv = make_blv (sym, forwarded, valcontents); blv->frame_local = 1; - sym->redirect = SYMBOL_LOCALIZED; + SET_SYMBOL_REDIRECT (sym, SYMBOL_LOCALIZED); SET_SYMBOL_BLV (sym, blv); { Lisp_Object symbol; @@ -1902,7 +1902,7 @@ BUFFER defaults to the current buffer. */) (register Lisp_Object variable, Lisp_Object buffer) { register struct buffer *buf; - struct Lisp_Symbol *sym; + sym_t sym; if (NILP (buffer)) buf = current_buffer; @@ -1916,7 +1916,7 @@ BUFFER defaults to the current buffer. */) sym = XSYMBOL (variable); start: - switch (sym->redirect) + switch (SYMBOL_REDIRECT (sym)) { case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; case SYMBOL_PLAINVAL: return Qnil; @@ -1967,13 +1967,13 @@ value in BUFFER, or if VARIABLE is automatically buffer-local (see `make-variable-buffer-local'). */) (register Lisp_Object variable, Lisp_Object buffer) { - struct Lisp_Symbol *sym; + sym_t sym; CHECK_SYMBOL (variable); sym = XSYMBOL (variable); start: - switch (sym->redirect) + switch (SYMBOL_REDIRECT (sym)) { case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; case SYMBOL_PLAINVAL: return Qnil; @@ -2000,7 +2000,7 @@ If the current binding is frame-local, the value is the selected frame. If the current binding is global (the default), the value is nil. */) (register Lisp_Object variable) { - struct Lisp_Symbol *sym; + sym_t sym; CHECK_SYMBOL (variable); sym = XSYMBOL (variable); @@ -2009,7 +2009,7 @@ If the current binding is global (the default), the value is nil. */) find_symbol_value (variable); start: - switch (sym->redirect) + switch (SYMBOL_REDIRECT (sym)) { case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; case SYMBOL_PLAINVAL: return Qnil; @@ -2027,7 +2027,7 @@ If the current binding is global (the default), the value is nil. */) buffer's or frame's value we are saving. */ if (!NILP (Flocal_variable_p (variable, Qnil))) return Fcurrent_buffer (); - else if (sym->redirect == SYMBOL_LOCALIZED + else if (SYMBOL_REDIRECT (sym) == SYMBOL_LOCALIZED && blv_found (SYMBOL_BLV (sym))) return SYMBOL_BLV (sym)->where; else @@ -3578,10 +3578,10 @@ syms_of_data (void) DEFVAR_LISP ("most-positive-fixnum", Vmost_positive_fixnum, doc: /* The largest value that is representable in a Lisp integer. */); Vmost_positive_fixnum = make_number (MOST_POSITIVE_FIXNUM); - XSYMBOL (intern_c_string ("most-positive-fixnum"))->constant = 1; + SET_SYMBOL_CONSTANT (XSYMBOL (intern_c_string ("most-positive-fixnum")), 1); DEFVAR_LISP ("most-negative-fixnum", Vmost_negative_fixnum, doc: /* The smallest value that is representable in a Lisp integer. */); Vmost_negative_fixnum = make_number (MOST_NEGATIVE_FIXNUM); - XSYMBOL (intern_c_string ("most-negative-fixnum"))->constant = 1; + SET_SYMBOL_CONSTANT (XSYMBOL (intern_c_string ("most-negative-fixnum")), 1); } diff --git a/src/eval.c b/src/eval.c index a2e9b0f30e..436953e911 100644 --- a/src/eval.c +++ b/src/eval.c @@ -622,18 +622,18 @@ then the value of BASE-VARIABLE is set to that of NEW-ALIAS. The return value is BASE-VARIABLE. */) (Lisp_Object new_alias, Lisp_Object base_variable, Lisp_Object docstring) { - struct Lisp_Symbol *sym; + sym_t sym; CHECK_SYMBOL (new_alias); CHECK_SYMBOL (base_variable); sym = XSYMBOL (new_alias); - if (sym->constant) + if (SYMBOL_CONSTANT (sym)) /* Not sure why, but why not? */ error ("Cannot make a constant an alias"); - switch (sym->redirect) + switch (SYMBOL_REDIRECT (sym)) { case SYMBOL_FORWARDED: error ("Cannot make an internal variable an alias"); @@ -657,11 +657,11 @@ The return value is BASE-VARIABLE. */) error ("Don't know how to make a let-bound variable an alias"); } - sym->declared_special = 1; - XSYMBOL (base_variable)->declared_special = 1; - sym->redirect = SYMBOL_VARALIAS; + SET_SYMBOL_DECLARED_SPECIAL (sym, 1); + SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (base_variable), 1); + SET_SYMBOL_REDIRECT (sym, SYMBOL_VARALIAS); SET_SYMBOL_ALIAS (sym, XSYMBOL (base_variable)); - sym->constant = SYMBOL_CONSTANT_P (base_variable); + SET_SYMBOL_CONSTANT (sym, SYMBOL_CONSTANT_P (base_variable)); LOADHIST_ATTACH (new_alias); /* Even if docstring is nil: remove old docstring. */ Fput (new_alias, Qvariable_documentation, docstring); @@ -755,7 +755,7 @@ usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */) tem = Fdefault_boundp (sym); /* Do it before evaluating the initial value, for self-references. */ - XSYMBOL (sym)->declared_special = 1; + SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (sym), 1); if (NILP (tem)) Fset_default (sym, eval_sub (XCAR (tail))); @@ -779,7 +779,7 @@ usage: (defvar SYMBOL &optional INITVALUE DOCSTRING) */) LOADHIST_ATTACH (sym); } else if (!NILP (Vinternal_interpreter_environment) - && !XSYMBOL (sym)->declared_special) + && ! SYMBOL_DECLARED_SPECIAL (XSYMBOL (sym))) /* A simple (defvar foo) with lexical scoping does "nothing" except declare that var to be dynamically scoped *locally* (i.e. within the current file or let-block). */ @@ -823,7 +823,7 @@ usage: (defconst SYMBOL INITVALUE [DOCSTRING]) */) if (!NILP (Vpurify_flag)) tem = Fpurecopy (tem); Fset_default (sym, tem); - XSYMBOL (sym)->declared_special = 1; + SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (sym), 1); tem = Fcar (XCDR (XCDR (args))); if (!NILP (tem)) { @@ -843,7 +843,7 @@ DEFUN ("internal-make-var-non-special", Fmake_var_non_special, (Lisp_Object symbol) { CHECK_SYMBOL (symbol); - XSYMBOL (symbol)->declared_special = 0; + SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (symbol), 0); return Qnil; } @@ -885,7 +885,7 @@ usage: (let* VARLIST BODY...) */) } if (!NILP (lexenv) && SYMBOLP (var) - && !XSYMBOL (var)->declared_special + && ! SYMBOL_DECLARED_SPECIAL (XSYMBOL (var)) && NILP (Fmemq (var, Vinternal_interpreter_environment))) /* Lexically bind VAR by adding it to the interpreter's binding alist. */ @@ -964,7 +964,7 @@ usage: (let VARLIST BODY...) */) tem = temps[argnum++]; if (!NILP (lexenv) && SYMBOLP (var) - && !XSYMBOL (var)->declared_special + && ! SYMBOL_DECLARED_SPECIAL (XSYMBOL (var)) && NILP (Fmemq (var, Vinternal_interpreter_environment))) /* Lexically bind VAR by adding it to the lexenv alist. */ lexenv = Fcons (Fcons (var, tem), lexenv); @@ -3000,7 +3000,7 @@ DEFUN ("fetch-bytecode", Ffetch_bytecode, Sfetch_bytecode, which was made in the buffer that is now current. */ bool -let_shadows_buffer_binding_p (struct Lisp_Symbol *symbol) +let_shadows_buffer_binding_p (sym_t symbol) { union specbinding *p; Lisp_Object buf = Fcurrent_buffer (); @@ -3008,8 +3008,8 @@ let_shadows_buffer_binding_p (struct Lisp_Symbol *symbol) for (p = specpdl_ptr; p > specpdl; ) if ((--p)->kind > SPECPDL_LET) { - struct Lisp_Symbol *let_bound_symbol = XSYMBOL (specpdl_symbol (p)); - eassert (let_bound_symbol->redirect != SYMBOL_VARALIAS); + sym_t let_bound_symbol = XSYMBOL (specpdl_symbol (p)); + eassert (SYMBOL_REDIRECT (let_bound_symbol) != SYMBOL_VARALIAS); if (symbol == let_bound_symbol && EQ (specpdl_where (p), buf)) return 1; @@ -3045,13 +3045,13 @@ let_shadows_global_binding_p (Lisp_Object symbol) void specbind (Lisp_Object symbol, Lisp_Object value) { - struct Lisp_Symbol *sym; + sym_t sym; CHECK_SYMBOL (symbol); sym = XSYMBOL (symbol); start: - switch (sym->redirect) + switch (SYMBOL_REDIRECT (sym)) { case SYMBOL_VARALIAS: sym = indirect_variable (sym); XSETSYMBOL (symbol, sym); goto start; @@ -3062,7 +3062,7 @@ specbind (Lisp_Object symbol, Lisp_Object value) specpdl_ptr->let.symbol = symbol; specpdl_ptr->let.old_value = SYMBOL_VAL (sym); grow_specpdl (); - if (!sym->constant) + if (! SYMBOL_CONSTANT (sym)) SET_SYMBOL_VAL (sym, value); else set_internal (symbol, value, Qnil, 1); @@ -3078,10 +3078,10 @@ specbind (Lisp_Object symbol, Lisp_Object value) specpdl_ptr->let.old_value = ovalue; specpdl_ptr->let.where = Fcurrent_buffer (); - eassert (sym->redirect != SYMBOL_LOCALIZED + eassert (SYMBOL_REDIRECT (sym) != SYMBOL_LOCALIZED || (EQ (SYMBOL_BLV (sym)->where, Fcurrent_buffer ()))); - if (sym->redirect == SYMBOL_LOCALIZED) + if (SYMBOL_REDIRECT (sym) == SYMBOL_LOCALIZED) { if (!blv_found (SYMBOL_BLV (sym))) specpdl_ptr->let.kind = SPECPDL_LET_DEFAULT; @@ -3197,8 +3197,8 @@ unbind_once (void *ignore) { /* If variable has a trivial value (no forwarding), we can just set it. No need to check for constant symbols here, since that was already done by specbind. */ - struct Lisp_Symbol *sym = XSYMBOL (specpdl_symbol (specpdl_ptr)); - if (sym->redirect == SYMBOL_PLAINVAL) + sym_t sym = XSYMBOL (specpdl_symbol (specpdl_ptr)); + if (SYMBOL_REDIRECT (sym) == SYMBOL_PLAINVAL) { SET_SYMBOL_VAL (sym, specpdl_old_value (specpdl_ptr)); break; @@ -3248,7 +3248,7 @@ context where binding is lexical by default. */) (Lisp_Object symbol) { CHECK_SYMBOL (symbol); - return XSYMBOL (symbol)->declared_special ? Qt : Qnil; + return SYMBOL_DECLARED_SPECIAL (XSYMBOL (symbol)) ? Qt : Qnil; } @@ -3397,8 +3397,8 @@ backtrace_eval_unrewind (int distance) { /* If variable has a trivial value (no forwarding), we can just set it. No need to check for constant symbols here, since that was already done by specbind. */ - struct Lisp_Symbol *sym = XSYMBOL (specpdl_symbol (tmp)); - if (sym->redirect == SYMBOL_PLAINVAL) + sym_t sym = XSYMBOL (specpdl_symbol (tmp)); + if (SYMBOL_REDIRECT (sym) == SYMBOL_PLAINVAL) { Lisp_Object old_value = specpdl_old_value (tmp); set_specpdl_old_value (tmp, SYMBOL_VAL (sym)); diff --git a/src/font.c b/src/font.c index e074c14db6..ddf28562c7 100644 --- a/src/font.c +++ b/src/font.c @@ -5156,19 +5156,19 @@ Each element has the form: [NUMERIC-VALUE SYMBOLIC-NAME ALIAS-NAME ...] NUMERIC-VALUE is an integer, and SYMBOLIC-NAME and ALIAS-NAME are symbols. */); Vfont_weight_table = BUILD_STYLE_TABLE (weight_table); - XSYMBOL (intern_c_string ("font-weight-table"))->constant = 1; + SET_SYMBOL_CONSTANT (XSYMBOL (intern_c_string ("font-weight-table")), 1); DEFVAR_LISP_NOPRO ("font-slant-table", Vfont_slant_table, doc: /* Vector of font slant symbols vs the corresponding numeric values. See `font-weight-table' for the format of the vector. */); Vfont_slant_table = BUILD_STYLE_TABLE (slant_table); - XSYMBOL (intern_c_string ("font-slant-table"))->constant = 1; + SET_SYMBOL_CONSTANT (XSYMBOL (intern_c_string ("font-slant-table")), 1); DEFVAR_LISP_NOPRO ("font-width-table", Vfont_width_table, doc: /* Alist of font width symbols vs the corresponding numeric values. See `font-weight-table' for the format of the vector. */); Vfont_width_table = BUILD_STYLE_TABLE (width_table); - XSYMBOL (intern_c_string ("font-width-table"))->constant = 1; + SET_SYMBOL_CONSTANT (XSYMBOL (intern_c_string ("font-width-table")), 1); staticpro (&font_style_table); font_style_table = make_uninit_vector (3); diff --git a/src/frame.c b/src/frame.c index 9ab18adc4b..bb10ef9b54 100644 --- a/src/frame.c +++ b/src/frame.c @@ -2109,14 +2109,14 @@ store_frame_param (struct frame *f, Lisp_Object prop, Lisp_Object val) without messing up the symbol's status. */ if (SYMBOLP (prop)) { - struct Lisp_Symbol *sym = XSYMBOL (prop); + sym_t sym = XSYMBOL (prop); start: - switch (sym->redirect) + switch (SYMBOL_REDIRECT (sym)) { case SYMBOL_VARALIAS: sym = indirect_variable (sym); goto start; case SYMBOL_PLAINVAL: case SYMBOL_FORWARDED: break; case SYMBOL_LOCALIZED: - { struct Lisp_Buffer_Local_Value *blv = sym->val.blv; + { struct Lisp_Buffer_Local_Value *blv = SYMBOL_BLV (sym); if (blv->frame_local && blv_found (blv) && XFRAME (blv->where) == f) swap_in_global_binding (sym); break; diff --git a/src/lisp.h b/src/lisp.h index 38d5d3cdd0..39dc624bce 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -299,10 +299,12 @@ DEFINE_GDB_SYMBOL_END (USE_LSB_TAG) #define lisp_h_MISCP(x) (SMOB_TYPEP (x, lisp_misc_tag)) #define lisp_h_NILP(x) (scm_is_lisp_false (x)) #define lisp_h_SET_SYMBOL_VAL(sym, v) \ - (eassert ((sym)->redirect == SYMBOL_PLAINVAL), (sym)->val.value = (v)) -#define lisp_h_SYMBOL_CONSTANT_P(sym) (XSYMBOL (sym)->constant) + (eassert (SYMBOL_REDIRECT (sym) == SYMBOL_PLAINVAL), \ + scm_c_vector_set_x (sym, 4, v)) +#define lisp_h_SYMBOL_CONSTANT_P(sym) (SYMBOL_CONSTANT (XSYMBOL (sym))) #define lisp_h_SYMBOL_VAL(sym) \ - (eassert ((sym)->redirect == SYMBOL_PLAINVAL), (sym)->val.value) + (eassert (SYMBOL_REDIRECT (sym) == SYMBOL_PLAINVAL), \ + scm_c_vector_ref (sym, 4)) #define lisp_h_SYMBOLP(x) \ (x && (scm_is_symbol (x) || EQ (x, Qnil) || EQ (x, Qt))) #define lisp_h_VECTORLIKEP(x) (SMOB_TYPEP (x, lisp_vectorlike_tag)) @@ -650,7 +652,9 @@ extern Lisp_Object function_module; extern Lisp_Object plist_module; extern Lisp_Object Qt, Qnil, Qt_, Qnil_; -INLINE struct Lisp_Symbol * +typedef Lisp_Object sym_t; + +INLINE sym_t XSYMBOL (Lisp_Object a) { Lisp_Object tem; @@ -658,7 +662,7 @@ XSYMBOL (Lisp_Object a) if (EQ (a, Qnil)) a = Qnil_; eassert (SYMBOLP (a)); tem = scm_variable_ref (scm_module_lookup (symbol_module, a)); - return scm_to_pointer (tem); + return tem; } /* Pseudovector types. */ @@ -721,7 +725,7 @@ make_lisp_proc (struct Lisp_Process *p) #define XSETFASTINT(a, b) ((a) = make_natnum (b)) #define XSETVECTOR(a, b) ((a) = (b)->header.self) #define XSETSTRING(a, b) ((a) = (b)->self) -#define XSETSYMBOL(a, b) ((a) = (b)->self) +#define XSETSYMBOL(a, b) ((a) = scm_c_vector_ref (b, 0)) #define XSETMISC(a, b) (a) = ((union Lisp_Misc *) (b))->u_any.self /* Pseudovector types. */ @@ -1263,80 +1267,84 @@ enum symbol_redirect struct Lisp_Symbol { - Lisp_Object self; + Lisp_Object self_; /* Indicates where the value can be found: 0 : it's a plain var, the value is in the `value' field. 1 : it's a varalias, the value is really in the `alias' symbol. 2 : it's a localized var, the value is in the `blv' object. 3 : it's a forwarding variable, the value is in `forward'. */ - ENUM_BF (symbol_redirect) redirect : 3; + ENUM_BF (symbol_redirect) redirect_ : 3; /* Non-zero means symbol is constant, i.e. changing its value should signal an error. If the value is 3, then the var can be changed, but only by `defconst'. */ - unsigned constant : 2; + unsigned constant_ : 2; /* True means that this variable has been explicitly declared special (with `defvar' etc), and shouldn't be lexically bound. */ - bool_bf declared_special : 1; - - /* True if pointed to from purespace and hence can't be GC'd. */ - bool_bf pinned : 1; + bool_bf declared_special_ : 1; /* Value of the symbol or Qunbound if unbound. Which alternative of the union is used depends on the `redirect' field above. */ union { - Lisp_Object value; - struct Lisp_Symbol *alias; - struct Lisp_Buffer_Local_Value *blv; - union Lisp_Fwd *fwd; - } val; + Lisp_Object value_; + sym_t alias_; + struct Lisp_Buffer_Local_Value *blv_; + union Lisp_Fwd *fwd_; + }; }; -/* Value is name of symbol. */ +#define SYMBOL_SELF(sym) (scm_c_vector_ref (sym, 0)) +#define SET_SYMBOL_SELF(sym, v) (scm_c_vector_set_x (sym, 0, v)) +#define SYMBOL_REDIRECT(sym) (XINT (scm_c_vector_ref (sym, 1))) +#define SET_SYMBOL_REDIRECT(sym, v) (scm_c_vector_set_x (sym, 1, make_number (v))) +#define SYMBOL_CONSTANT(sym) (XINT (scm_c_vector_ref (sym, 2))) +#define SET_SYMBOL_CONSTANT(sym, v) (scm_c_vector_set_x (sym, 2, make_number (v))) +#define SYMBOL_DECLARED_SPECIAL(sym) (XINT (scm_c_vector_ref (sym, 3))) +#define SET_SYMBOL_DECLARED_SPECIAL(sym, v) (scm_c_vector_set_x (sym, 3, make_number (v))) -LISP_MACRO_DEFUN (SYMBOL_VAL, Lisp_Object, (struct Lisp_Symbol *sym), (sym)) +/* Value is name of symbol. */ -INLINE struct Lisp_Symbol * -SYMBOL_ALIAS (struct Lisp_Symbol *sym) +INLINE sym_t +SYMBOL_ALIAS (sym_t sym) { - eassert (sym->redirect == SYMBOL_VARALIAS); - return sym->val.alias; + eassert (SYMBOL_REDIRECT (sym) == SYMBOL_VARALIAS); + return scm_c_vector_ref (sym, 4); } INLINE struct Lisp_Buffer_Local_Value * -SYMBOL_BLV (struct Lisp_Symbol *sym) +SYMBOL_BLV (sym_t sym) { - eassert (sym->redirect == SYMBOL_LOCALIZED); - return sym->val.blv; + eassert (SYMBOL_REDIRECT (sym) == SYMBOL_LOCALIZED); + return scm_to_pointer (scm_c_vector_ref (sym, 4)); } INLINE union Lisp_Fwd * -SYMBOL_FWD (struct Lisp_Symbol *sym) +SYMBOL_FWD (sym_t sym) { - eassert (sym->redirect == SYMBOL_FORWARDED); - return sym->val.fwd; + eassert (SYMBOL_REDIRECT (sym) == SYMBOL_FORWARDED); + return scm_to_pointer (scm_c_vector_ref (sym, 4)); } LISP_MACRO_DEFUN_VOID (SET_SYMBOL_VAL, - (struct Lisp_Symbol *sym, Lisp_Object v), (sym, v)) + (sym_t sym, Lisp_Object v), (sym, v)) INLINE void -SET_SYMBOL_ALIAS (struct Lisp_Symbol *sym, struct Lisp_Symbol *v) +SET_SYMBOL_ALIAS (sym_t sym, sym_t v) { - eassert (sym->redirect == SYMBOL_VARALIAS); - sym->val.alias = v; + eassert (SYMBOL_REDIRECT (sym) == SYMBOL_VARALIAS); + scm_c_vector_set_x (sym, 4, v); } INLINE void -SET_SYMBOL_BLV (struct Lisp_Symbol *sym, struct Lisp_Buffer_Local_Value *v) +SET_SYMBOL_BLV (sym_t sym, struct Lisp_Buffer_Local_Value *v) { - eassert (sym->redirect == SYMBOL_LOCALIZED); - sym->val.blv = v; + eassert (SYMBOL_REDIRECT (sym) == SYMBOL_LOCALIZED); + scm_c_vector_set_x (sym, 4, scm_from_pointer (v, NULL)); } INLINE void -SET_SYMBOL_FWD (struct Lisp_Symbol *sym, union Lisp_Fwd *v) +SET_SYMBOL_FWD (sym_t sym, union Lisp_Fwd *v) { - eassert (sym->redirect == SYMBOL_FORWARDED); - sym->val.fwd = v; + eassert (SYMBOL_REDIRECT (sym) == SYMBOL_FORWARDED); + scm_c_vector_set_x (sym, 4, scm_from_pointer (v, NULL)); } INLINE Lisp_Object @@ -1374,6 +1382,8 @@ LISP_MACRO_DEFUN (SYMBOL_CONSTANT_P, int, (Lisp_Object sym), (sym)) #define DEFSYM(sym, name) \ do { (sym) = intern_c_string ((name)); staticpro (&(sym)); } while (false) +LISP_MACRO_DEFUN (SYMBOL_VAL, Lisp_Object, (sym_t sym), (sym)) + /*********************************************************************** Hash Tables @@ -2903,14 +2913,14 @@ extern Lisp_Object arithcompare (Lisp_Object num1, Lisp_Object num2, extern intmax_t cons_to_signed (Lisp_Object, intmax_t, intmax_t); extern uintmax_t cons_to_unsigned (Lisp_Object, uintmax_t); -extern struct Lisp_Symbol *indirect_variable (struct Lisp_Symbol *); +extern sym_t indirect_variable (sym_t ); extern _Noreturn void args_out_of_range (Lisp_Object, Lisp_Object); extern _Noreturn void args_out_of_range_3 (Lisp_Object, Lisp_Object, Lisp_Object); extern Lisp_Object do_symval_forwarding (union Lisp_Fwd *); extern void set_internal (Lisp_Object, Lisp_Object, Lisp_Object, bool); extern void syms_of_data (void); -extern void swap_in_global_binding (struct Lisp_Symbol *); +extern void swap_in_global_binding (sym_t ); /* Defined in cmds.c */ extern void syms_of_cmds (void); @@ -3406,7 +3416,7 @@ extern void record_in_backtrace (Lisp_Object function, extern void mark_specpdl (void); extern void get_backtrace (Lisp_Object array); Lisp_Object backtrace_top_function (void); -extern bool let_shadows_buffer_binding_p (struct Lisp_Symbol *symbol); +extern bool let_shadows_buffer_binding_p (sym_t symbol); extern bool let_shadows_global_binding_p (Lisp_Object symbol); extern _Noreturn SCM abort_to_prompt (SCM, SCM); extern SCM call_with_prompt (SCM, SCM, SCM); diff --git a/src/lread.c b/src/lread.c index a57cab6f79..9ce2bcb7a2 100644 --- a/src/lread.c +++ b/src/lread.c @@ -3841,8 +3841,8 @@ it defaults to the value of `obarray'. */) if ((SREF (string, 0) == ':') && EQ (obarray, initial_obarray)) { - XSYMBOL (sym)->constant = 1; - XSYMBOL (sym)->redirect = SYMBOL_PLAINVAL; + SET_SYMBOL_CONSTANT (XSYMBOL (sym), 1); + SET_SYMBOL_REDIRECT (XSYMBOL (sym), SYMBOL_PLAINVAL); SET_SYMBOL_VAL (XSYMBOL (sym), sym); } @@ -4014,13 +4014,13 @@ init_obarray (void) Qnil_ = intern_c_string ("nil"); SET_SYMBOL_VAL (XSYMBOL (Qnil_), Qnil); - XSYMBOL (Qnil_)->constant = 1; - XSYMBOL (Qnil_)->declared_special = 1; + SET_SYMBOL_CONSTANT (XSYMBOL (Qnil_), 1); + SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (Qnil_), 1); Qt_ = intern_c_string ("t"); SET_SYMBOL_VAL (XSYMBOL (Qt_), Qt); - XSYMBOL (Qt_)->constant = 1; - XSYMBOL (Qt_)->declared_special = 1; + SET_SYMBOL_CONSTANT (XSYMBOL (Qt_), 1); + SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (Qt_), 1); Qunbound = Fmake_symbol (build_pure_c_string ("unbound")); SET_SYMBOL_VAL (XSYMBOL (Qunbound), Qunbound); @@ -4074,8 +4074,8 @@ defvar_int (struct Lisp_Intfwd *i_fwd, sym = intern_c_string (namestring); i_fwd->type = Lisp_Fwd_Int; i_fwd->intvar = address; - XSYMBOL (sym)->declared_special = 1; - XSYMBOL (sym)->redirect = SYMBOL_FORWARDED; + SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (sym), 1); + SET_SYMBOL_REDIRECT (XSYMBOL (sym), SYMBOL_FORWARDED); SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)i_fwd); } @@ -4089,8 +4089,8 @@ defvar_bool (struct Lisp_Boolfwd *b_fwd, sym = intern_c_string (namestring); b_fwd->type = Lisp_Fwd_Bool; b_fwd->boolvar = address; - XSYMBOL (sym)->declared_special = 1; - XSYMBOL (sym)->redirect = SYMBOL_FORWARDED; + SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (sym), 1); + SET_SYMBOL_REDIRECT (XSYMBOL (sym), SYMBOL_FORWARDED); SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)b_fwd); Vbyte_boolean_vars = Fcons (sym, Vbyte_boolean_vars); } @@ -4108,8 +4108,8 @@ defvar_lisp_nopro (struct Lisp_Objfwd *o_fwd, sym = intern_c_string (namestring); o_fwd->type = Lisp_Fwd_Obj; o_fwd->objvar = address; - XSYMBOL (sym)->declared_special = 1; - XSYMBOL (sym)->redirect = SYMBOL_FORWARDED; + SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (sym), 1); + SET_SYMBOL_REDIRECT (XSYMBOL (sym), SYMBOL_FORWARDED); SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)o_fwd); } @@ -4132,8 +4132,8 @@ defvar_kboard (struct Lisp_Kboard_Objfwd *ko_fwd, sym = intern_c_string (namestring); ko_fwd->type = Lisp_Fwd_Kboard_Obj; ko_fwd->offset = offset; - XSYMBOL (sym)->declared_special = 1; - XSYMBOL (sym)->redirect = SYMBOL_FORWARDED; + SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (sym), 1); + SET_SYMBOL_REDIRECT (XSYMBOL (sym), SYMBOL_FORWARDED); SET_SYMBOL_FWD (XSYMBOL (sym), (union Lisp_Fwd *)ko_fwd); } @@ -4440,7 +4440,7 @@ to find all the symbols in an obarray, use `mapatoms'. */); DEFVAR_LISP ("values", Vvalues, doc: /* List of values of all expressions which were read, evaluated and printed. Order is reverse chronological. */); - XSYMBOL (intern ("values"))->declared_special = 0; + SET_SYMBOL_DECLARED_SPECIAL (XSYMBOL (intern ("values")), 0); DEFVAR_LISP ("standard-input", Vstandard_input, doc: /* Stream for read to get input from. -- 2.20.1