From 738800001d32d8931b0c9548c5da2247bfed3d9a Mon Sep 17 00:00:00 2001 From: BT Templeton Date: Wed, 21 Aug 2013 20:49:32 -0400 Subject: [PATCH] use #nil and #t --- src/data.c | 1 + src/lisp.h | 21 +++++++++++++++++++-- src/lread.c | 41 +++++++++++++++++++++-------------------- 3 files changed, 41 insertions(+), 22 deletions(-) diff --git a/src/data.c b/src/data.c index 225ac10cac..426bae133a 100644 --- a/src/data.c +++ b/src/data.c @@ -38,6 +38,7 @@ along with GNU Emacs. If not, see . */ #include "keymap.h" Lisp_Object Qnil, Qt, Qquote, Qlambda, Qunbound; +Lisp_Object Qnil_, Qt_; static Lisp_Object Qsubr; Lisp_Object Qerror_conditions, Qerror_message, Qtop_level; Lisp_Object Qerror, Quser_error, Qquit, Qargs_out_of_range; diff --git a/src/lisp.h b/src/lisp.h index 3d5e7bed62..0143506736 100644 --- a/src/lisp.h +++ b/src/lisp.h @@ -297,13 +297,14 @@ DEFINE_GDB_SYMBOL_END (USE_LSB_TAG) #define lisp_h_INTEGERP(x) (SCM_I_INUMP (x)) #define lisp_h_MARKERP(x) (MISCP (x) && XMISCTYPE (x) == Lisp_Misc_Marker) #define lisp_h_MISCP(x) (SMOB_TYPEP (x, lisp_misc_tag)) -#define lisp_h_NILP(x) EQ (x, Qnil) +#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) #define lisp_h_SYMBOL_VAL(sym) \ (eassert ((sym)->redirect == SYMBOL_PLAINVAL), (sym)->val.value) -#define lisp_h_SYMBOLP(x) (x && scm_is_symbol (x)) +#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)) #define lisp_h_XCAR(c) (scm_car (c)) #define lisp_h_XCDR(c) (scm_cdr (c)) @@ -649,11 +650,14 @@ INLINE Lisp_Object build_string (const char *); extern Lisp_Object symbol_module; extern Lisp_Object function_module; extern Lisp_Object plist_module; +extern Lisp_Object Qt, Qnil, Qt_, Qnil_; INLINE struct Lisp_Symbol * XSYMBOL (Lisp_Object a) { Lisp_Object tem; + if (EQ (a, Qt)) a = Qt_; + if (EQ (a, Qnil)) a = Qnil_; eassert (SYMBOLP (a)); tem = scm_variable_ref (scm_module_lookup (symbol_module, a)); return scm_to_pointer (tem); @@ -1373,6 +1377,8 @@ SET_SYMBOL_FWD (struct Lisp_Symbol *sym, union Lisp_Fwd *v) INLINE Lisp_Object SYMBOL_NAME (Lisp_Object sym) { + if (EQ (sym, Qnil)) sym = Qnil_; + if (EQ (sym, Qt)) sym = Qt_; return build_string (scm_to_locale_string (scm_symbol_to_string (sym))); } @@ -1381,12 +1387,16 @@ SYMBOL_NAME (Lisp_Object sym) INLINE bool SYMBOL_INTERNED_P (Lisp_Object sym) { + if (EQ (sym, Qnil)) sym = Qnil_; + if (EQ (sym, Qt)) sym = Qt_; return scm_is_true (scm_symbol_interned_p (sym)); } INLINE Lisp_Object SYMBOL_FUNCTION (Lisp_Object sym) { + if (EQ (sym, Qnil)) sym = Qnil_; + if (EQ (sym, Qt)) sym = Qt_; return scm_variable_ref (scm_module_lookup (function_module, sym)); } @@ -2734,18 +2744,24 @@ set_hash_value_slot (struct Lisp_Hash_Table *h, ptrdiff_t idx, Lisp_Object val) INLINE void set_symbol_function (Lisp_Object sym, Lisp_Object function) { + if (EQ (sym, Qnil)) sym = Qnil_; + if (EQ (sym, Qt)) sym = Qt_; scm_variable_set_x (scm_module_lookup (function_module, sym), function); } INLINE Lisp_Object symbol_plist (Lisp_Object sym) { + if (EQ (sym, Qnil)) sym = Qnil_; + if (EQ (sym, Qt)) sym = Qt_; return scm_variable_ref (scm_module_lookup (plist_module, sym)); } INLINE void set_symbol_plist (Lisp_Object sym, Lisp_Object plist) { + if (EQ (sym, Qnil)) sym = Qnil_; + if (EQ (sym, Qt)) sym = Qt_; scm_variable_set_x (scm_module_lookup (plist_module, sym), plist); } @@ -2819,6 +2835,7 @@ set_sub_char_table_contents (Lisp_Object table, ptrdiff_t idx, Lisp_Object val) } /* Defined in data.c. */ +extern Lisp_Object Qnil_, Qt_; extern Lisp_Object Qquote, Qunbound; extern Lisp_Object Qerror_conditions, Qerror_message, Qtop_level; extern Lisp_Object Qerror, Qquit, Qargs_out_of_range; diff --git a/src/lread.c b/src/lread.c index 54542fef97..d883cda62f 100644 --- a/src/lread.c +++ b/src/lread.c @@ -3946,7 +3946,14 @@ oblookup (Lisp_Object obarray, register const char *ptr, ptrdiff_t size, ptrdiff sym = scm_find_symbol (string2, obhash (obarray)); if (scm_is_true (sym) && scm_is_true (scm_module_variable (symbol_module, sym))) - return sym; + { + if (EQ (sym, Qnil_)) + return Qnil; + else if (EQ (sym, Qt_)) + return Qt; + else + return sym; + } else return make_number (0); } @@ -4002,27 +4009,21 @@ init_obarray (void) obarrays = scm_make_hash_table (SCM_UNDEFINED); scm_hashq_set_x (obarrays, Vobarray, SCM_UNDEFINED); - Qunbound = Fmake_symbol (build_pure_c_string ("unbound")); - /* Set temporary dummy values to Qnil and Vpurify_flag to satisfy the - NILP (Vpurify_flag) check in intern_c_string. */ - Qnil = make_number (-1); Vpurify_flag = make_number (1); - Qnil = intern_c_string ("nil"); + Qnil = SCM_ELISP_NIL; + Qt = SCM_BOOL_T; + + Qnil_ = intern_c_string ("nil"); + SET_SYMBOL_VAL (XSYMBOL (Qnil_), Qnil); + XSYMBOL (Qnil_)->constant = 1; + XSYMBOL (Qnil_)->declared_special = 1; - /* Fmake_symbol inits fields of new symbols with Qunbound and Qnil, - so those two need to be fixed manually. */ + Qt_ = intern_c_string ("t"); + SET_SYMBOL_VAL (XSYMBOL (Qt_), Qt); + XSYMBOL (Qt_)->constant = 1; + XSYMBOL (Qt_)->declared_special = 1; + + Qunbound = Fmake_symbol (build_pure_c_string ("unbound")); SET_SYMBOL_VAL (XSYMBOL (Qunbound), Qunbound); - set_symbol_function (Qunbound, Qnil); - set_symbol_plist (Qunbound, Qnil); - SET_SYMBOL_VAL (XSYMBOL (Qnil), Qnil); - XSYMBOL (Qnil)->constant = 1; - XSYMBOL (Qnil)->declared_special = 1; - set_symbol_plist (Qnil, Qnil); - set_symbol_function (Qnil, Qnil); - - Qt = intern_c_string ("t"); - SET_SYMBOL_VAL (XSYMBOL (Qt), Qt); - XSYMBOL (Qnil)->declared_special = 1; - XSYMBOL (Qt)->constant = 1; /* Qt is correct even if CANNOT_DUMP. loadup.el will set to nil at end. */ Vpurify_flag = Qt; -- 2.20.1