all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Helmut Eller <eller.helmut@gmail.com>
To: "Gerd Möllmann" <gerd.moellmann@gmail.com>
Cc: Emacs Devel <emacs-devel@gnu.org>,  Eli Zaretskii <eliz@gnu.org>
Subject: Re: MPS: Forwording symbols
Date: Sun, 23 Jun 2024 21:59:38 +0200	[thread overview]
Message-ID: <87tthjxwet.fsf@gmail.com> (raw)
In-Reply-To: <m2tthkdbiw.fsf@pro2.fritz.box> ("Gerd Möllmann"'s message of "Sat, 22 Jun 2024 21:26:31 +0200")

[-- Attachment #1: Type: text/plain, Size: 604 bytes --]

On Sat, Jun 22 2024, Gerd Möllmann wrote:

>> The symbol is needed in store_symval_forwarding.  It looks in the plist
>> for 'choice and 'range.  In addition to the five symbols mentioned in
>> the definition of Lisp_Buffer_Objfwd, predicate can also be
>> 'overwrite-mode, 'vertical-scroll-bar and 'fraction.  I think those have
>> those properties; weird.
>
> I guess then it's better to leave the enum part out. That seems to
> become too much work. What an ugly corner.

Here is an attempt to use an enum.  I'm not sure that it's easier to
read and the enum constants have odd names.


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-Introduce-an-enum-Lisp_Fwd_Predicate.patch --]
[-- Type: text/x-diff, Size: 5946 bytes --]

From ad356aea9eb894baec5541d2203e97a0f42e382e Mon Sep 17 00:00:00 2001
From: Helmut Eller <eller.helmut@gmail.com>
Date: Sun, 23 Jun 2024 21:46:16 +0200
Subject: [PATCH] Introduce an enum Lisp_Fwd_Predicate

Using an enum instead of a symbol makes it obvious that this field is
of no concern to the GC.

* src/lisp.h (enum Lisp_Fwd_Predicate): New.
(struct Lisp_Fwd): Use it instead of a symbol.
* src/buffer.c (DEFVAR_PER_BUFFER): Create the necessary enum constant
instead of a symbol.
* src/data.c (check_fwd_predicate, check_choice): New helpers.
(store_symval_forwarding): Use it.
---
 src/buffer.c | 22 ++++++--------
 src/data.c   | 83 ++++++++++++++++++++++++++++++++++------------------
 src/lisp.h   | 17 ++++++++---
 3 files changed, 77 insertions(+), 45 deletions(-)

diff --git a/src/buffer.c b/src/buffer.c
index ae5016df50e..39b5e29067a 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -5017,19 +5017,15 @@ init_buffer (void)
    that nil is allowed too).  DOC is a dummy where you write the doc
    string as a comment.  */
 
-/* FIXME: use LISPSYM_INITIALLY instead of TAG_PTR_INITIALLY */
-#define DEFVAR_PER_BUFFER(lname, vname, predicate_, doc)		\
-  do {									\
-    const Lisp_Object sym						\
-      = TAG_PTR_INITIALLY (Lisp_Symbol, (intptr_t)((i##predicate_)	\
-						   * sizeof *lispsym));	\
-    static const struct Lisp_Fwd bo_fwd					\
-	= { .type = Lisp_Fwd_Buffer_Obj,				\
-	    .bufoffset = offsetof (struct buffer, vname##_),		\
-	    .u.bufpredicate = sym };					\
-    static_assert (offsetof (struct buffer, vname##_)			\
-		   < (1 << 8 * sizeof bo_fwd.bufoffset));		\
-    defvar_per_buffer (&bo_fwd, lname);					\
+#define DEFVAR_PER_BUFFER(lname, vname, predicate, doc)		\
+  do {								\
+    static const struct Lisp_Fwd bo_fwd				\
+	= { .type = Lisp_Fwd_Buffer_Obj,			\
+	    .bufoffset = offsetof (struct buffer, vname##_),	\
+	    .u.bufpredicate = FWDPRED_##predicate };		\
+    static_assert (offsetof (struct buffer, vname##_)		\
+		   < (1 << 8 * sizeof bo_fwd.bufoffset));	\
+    defvar_per_buffer (&bo_fwd, lname);				\
   } while (0)
 
 static void
diff --git a/src/data.c b/src/data.c
index e0133d81771..9fd439e07b5 100644
--- a/src/data.c
+++ b/src/data.c
@@ -1399,6 +1399,59 @@ wrong_range (Lisp_Object min, Lisp_Object max, Lisp_Object wrong)
 	    wrong);
 }
 
+static void
+check_choice (Lisp_Object choice, Lisp_Object val)
+{
+  eassert (CONSP (choice));
+  if (NILP (Fmemq (val, choice)))
+    wrong_choice (choice, val);
+}
+
+static void
+check_fwd_predicate (enum Lisp_Fwd_Predicate p, Lisp_Object val)
+{
+  switch (p)
+    {
+    case FWDPRED_Qnil:
+      return;
+    case FWDPRED_Qstringp:
+      if (!STRINGP (val))
+	wrong_type_argument (Qstringp, val);
+      return;
+    case FWDPRED_Qsymbolp:
+      if (!SYMBOLP (val))
+	wrong_type_argument (Qsymbolp, val);
+      return;
+    case FWDPRED_Qintegerp:
+      if (!INTEGERP (val))
+	wrong_type_argument (Qintegerp, val);
+      return;
+    case FWDPRED_Qnumberp:
+      if (!NUMBERP (val))
+	wrong_type_argument (Qnumberp, val);
+      return;
+    case FWDPRED_Qfraction:
+      {
+	if (!NUMBERP (val))
+	  wrong_type_argument (Qnumberp, val);
+	Lisp_Object range = Fget (Qfraction, Qrange);
+	eassert (CONSP (range));
+	Lisp_Object min = XCAR (range);
+	Lisp_Object max = XCDR (range);
+	if (NILP (CALLN (Fleq, min, val, max)))
+	  wrong_range (min, max, val);
+      }
+      return;
+    case FWDPRED_Qvertical_scroll_bar:
+      check_choice (Fget (Qvertical_scroll_bar, Qchoice), val);
+      return;
+    case FWDPRED_Qoverwrite_mode:
+      check_choice (Fget (Qoverwrite_mode, Qchoice), val);
+      return;
+    }
+  emacs_abort ();
+}
+
 /* Store NEWVAL into SYMBOL, where VALCONTENTS is found in the value cell
    of SYMBOL.  If SYMBOL is buffer-local, VALCONTENTS should be the
    buffer-independent contents of the value cell: forwarded just one
@@ -1459,34 +1512,8 @@ store_symval_forwarding (lispfwd valcontents, Lisp_Object newval,
     case Lisp_Fwd_Buffer_Obj:
       {
 	int offset = XBUFFER_OFFSET (valcontents);
-	Lisp_Object predicate = valcontents->u.bufpredicate;
-
-	if (!NILP (newval) && !NILP (predicate))
-	  {
-	    eassert (SYMBOLP (predicate));
-	    Lisp_Object choiceprop = Fget (predicate, Qchoice);
-	    if (!NILP (choiceprop))
-	      {
-		if (NILP (Fmemq (newval, choiceprop)))
-		  wrong_choice (choiceprop, newval);
-	      }
-	    else
-	      {
-		Lisp_Object rangeprop = Fget (predicate, Qrange);
-		if (CONSP (rangeprop))
-		  {
-		    Lisp_Object min = XCAR (rangeprop), max = XCDR (rangeprop);
-		    if (! NUMBERP (newval)
-			|| NILP (CALLN (Fleq, min, newval, max)))
-		      wrong_range (min, max, newval);
-		  }
-		else if (FUNCTIONP (predicate))
-		  {
-		    if (NILP (call1 (predicate, newval)))
-		      wrong_type_argument (predicate, newval);
-		  }
-	      }
-	  }
+	if (!NILP (newval))
+	  check_fwd_predicate (valcontents->u.bufpredicate, newval);
 	if (buf == NULL)
 	  buf = current_buffer;
 	set_per_buffer_value (buf, offset, newval);
diff --git a/src/lisp.h b/src/lisp.h
index c20bc9aa76e..e3c2dce7df0 100644
--- a/src/lisp.h
+++ b/src/lisp.h
@@ -3158,6 +3158,18 @@ #define INT_TO_INTEGER(expr) \
     Lisp_Object valcell;
   };
 
+enum Lisp_Fwd_Predicate
+{
+  FWDPRED_Qnil,
+  FWDPRED_Qintegerp,
+  FWDPRED_Qsymbolp,
+  FWDPRED_Qstringp,
+  FWDPRED_Qnumberp,
+  FWDPRED_Qfraction,
+  FWDPRED_Qvertical_scroll_bar,
+  FWDPRED_Qoverwrite_mode,
+};
+
 /* A struct Lisp_Fwd is used to locate a variable.  See Lisp_Fwd_Type
    for the various types of variables.
 
@@ -3174,10 +3186,7 @@ #define INT_TO_INTEGER(expr) \
     intmax_t *intvar;
     bool *boolvar;
     Lisp_Object *objvar;
-    /* One of Qnil, Qintegerp, Qsymbolp, Qstringp, Qfloatp, Qnumberp,
-       Qfraction, Qvertical_scroll_bar, or Qoverwrite_mode.
-     */
-    Lisp_Object bufpredicate;
+    enum Lisp_Fwd_Predicate bufpredicate;
     int kbdoffset;
   } u;
 };
-- 
2.39.2


  parent reply	other threads:[~2024-06-23 19:59 UTC|newest]

Thread overview: 69+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-16  9:43 MPS: Forwording symbols Gerd Möllmann
2024-06-16 10:15 ` Gerd Möllmann
2024-06-16 19:27 ` Helmut Eller
2024-06-16 19:39   ` Gerd Möllmann
2024-06-17 10:57     ` Eli Zaretskii
2024-06-17 12:15       ` Gerd Möllmann
2024-06-17 12:24         ` Eli Zaretskii
2024-06-17 12:58           ` Gerd Möllmann
2024-06-17  3:43   ` Gerd Möllmann
2024-06-17 11:47     ` Eli Zaretskii
2024-06-17 18:10     ` Helmut Eller
2024-06-17 18:39       ` Gerd Möllmann
2024-06-17 18:50         ` Gerd Möllmann
2024-06-17 19:05           ` Helmut Eller
2024-06-17 19:19             ` Gerd Möllmann
2024-06-17 19:25               ` Helmut Eller
2024-06-17 20:07                 ` Gerd Möllmann
2024-06-18  6:32                   ` Gerd Möllmann
2024-06-18  9:05                     ` Helmut Eller
2024-06-18  9:24                       ` Gerd Möllmann
2024-06-18 10:44                         ` Gerd Möllmann
2024-06-18 11:55                           ` Helmut Eller
2024-06-18 12:21                             ` Gerd Möllmann
2024-06-18 19:36                               ` Helmut Eller
2024-06-18 19:55                                 ` Gerd Möllmann
2024-06-20 14:18                                   ` Helmut Eller
2024-06-20 15:16                                     ` Gerd Möllmann
2024-06-20 16:17                                       ` Helmut Eller
2024-06-20 16:27                                         ` Gerd Möllmann
2024-06-18 12:05                         ` Helmut Eller
2024-06-18 12:29                           ` Gerd Möllmann
2024-06-18 13:08                           ` Eli Zaretskii
2024-06-18 12:36                   ` Eli Zaretskii
2024-06-18 16:20                     ` Helmut Eller
2024-06-18 16:29                       ` Eli Zaretskii
2024-06-18 16:43                       ` Gerd Möllmann
2024-06-18 16:37                     ` Helmut Eller
2024-06-18 17:33                       ` Eli Zaretskii
2024-06-18 17:51                         ` Helmut Eller
2024-06-18 18:18                           ` Eli Zaretskii
2024-06-18 17:54                         ` Eli Zaretskii
2024-06-18 18:11                           ` Gerd Möllmann
2024-06-18 18:20                             ` Eli Zaretskii
2024-06-18 18:23                               ` Gerd Möllmann
2024-06-18 18:12                           ` Helmut Eller
2024-06-18 18:22                             ` Eli Zaretskii
2024-06-18 19:27                               ` Helmut Eller
2024-06-18 19:33                                 ` Gerd Möllmann
2024-06-19 11:22                                   ` Eli Zaretskii
2024-06-17 19:06           ` Gerd Möllmann
2024-06-21 15:36 ` Helmut Eller
2024-06-21 15:41   ` Gerd Möllmann
2024-06-21 16:20     ` Gerd Möllmann
2024-06-22 18:02       ` Helmut Eller
2024-06-22 18:27         ` Gerd Möllmann
2024-06-22 18:53           ` Helmut Eller
2024-06-22 19:26             ` Gerd Möllmann
2024-06-23  3:28               ` Gerd Möllmann
2024-06-23  4:10                 ` Gerd Möllmann
2024-06-23 19:59               ` Helmut Eller [this message]
2024-06-24  3:45                 ` Gerd Möllmann
2024-06-24 15:13                   ` Helmut Eller
2024-06-24 16:14                     ` Gerd Möllmann
2024-06-24 16:32                       ` Eli Zaretskii
2024-06-24 17:00                         ` Gerd Möllmann
2024-06-23 15:59           ` Helmut Eller
2024-06-23 16:26             ` Gerd Möllmann
2024-06-21 16:15   ` Ihor Radchenko
2024-06-21 16:25     ` Gerd Möllmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tthjxwet.fsf@gmail.com \
    --to=eller.helmut@gmail.com \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=gerd.moellmann@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.