all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Dmitry Antipov <dmantipov@yandex.ru>
To: Emacs development discussions <emacs-devel@gnu.org>
Subject: [RFC] refactoring DEFUN
Date: Mon, 25 Mar 2013 15:56:29 +0400	[thread overview]
Message-ID: <51503B6D.1060203@yandex.ru> (raw)

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

Although C preprocessor can't transform the text too much, it's
still possible to use concatenation to avoid silly typing like:

DEFUN ("foo", Ffoo, Sfoo, ...)

and use:

DEFUN ("foo", foo, ...)

instead. The core change is simple, but the obvious rest is ~450K
uncompressed (99.9% was generated by elisp program, BTW).

Dmitry

[-- Attachment #2: refactor_DEFUN_core.patch --]
[-- Type: text/plain, Size: 3840 bytes --]

=== modified file 'lib-src/make-docfile.c'
--- lib-src/make-docfile.c	2013-01-15 21:26:01 +0000
+++ lib-src/make-docfile.c	2013-03-25 11:26:49 +0000
@@ -842,8 +842,18 @@
 		    || c == '\n' || c == '\r'));
 	  input_buffer[i] = '\0';
 
-	  name = xmalloc (i + 1);
-	  memcpy (name, input_buffer, i + 1);
+	  if (defunflag)
+	    {
+	      /* Prepend 'F' to Lisp function name.  */
+	      name = xmalloc (i + 2);
+	      name[0] = 'F';
+	      memcpy (name + 1, input_buffer, i + 1);
+	    }
+	  else
+	    {
+	      name = xmalloc (i + 1);
+	      memcpy (name, input_buffer, i + 1);
+	    }
 
 	  if (!defunflag)
 	    {
@@ -857,7 +867,7 @@
 	 DEFVAR_LISP ("name", addr, doc: /\* doc *\/)  */
 
       if (defunflag)
-	commas = generate_globals ? 4 : 5;
+	commas = generate_globals ? 3 : 4;
       else if (defvarperbufferflag)
 	commas = 3;
       else if (defvarflag)

=== modified file 'src/lisp.h'
--- src/lisp.h	2013-03-24 12:59:45 +0000
+++ src/lisp.h	2013-03-25 11:26:49 +0000
@@ -2029,12 +2029,10 @@
 /* Define a built-in function for calling from Lisp.
  `lname' should be the name to give the function in Lisp,
     as a null-terminated C string.
- `fnname' should be the name of the function in C.
-    By convention, it starts with F.
- `sname' should be the name for the C constant structure
-    that records information on this function for internal use.
-    By convention, it should be the same as `fnname' but with S instead of F.
-    It's too bad that C macros can't compute this from `fnname'.
+ `pattern' is used to generate the name of the function in C,
+    and the C constant structure that records information on this
+    function for internal use.  By convention, the first one is
+    done by prepending F and the second is done by prepending S.
  `minargs' should be a number, the minimum number of arguments allowed.
  `maxargs' should be a number, the maximum number of arguments allowed,
     or else MANY or UNEVALLED.
@@ -2054,22 +2052,22 @@
 /* This version of DEFUN declares a function prototype with the right
    arguments, so we can catch errors with maxargs at compile-time.  */
 #ifdef _MSC_VER
-#define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc)	\
-   Lisp_Object fnname DEFUN_ARGS_ ## maxargs ;				\
-   static struct Lisp_Subr alignas (GCALIGNMENT) sname =		\
-   { { (PVEC_SUBR << PSEUDOVECTOR_AREA_BITS)				\
-       | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)) },		\
-      { (Lisp_Object (__cdecl *)(void))fnname },                        \
-       minargs, maxargs, lname, intspec, 0};				\
-   Lisp_Object fnname
+#define DEFUN(lname, pattern, minargs, maxargs, intspec, doc)	\
+  Lisp_Object F ## pattern DEFUN_ARGS_ ## maxargs ;		\
+  static struct Lisp_Subr alignas (GCALIGNMENT) S ## pattern =	\
+  { { (PVEC_SUBR << PSEUDOVECTOR_AREA_BITS)			\
+      | (sizeof (struct Lisp_Subr) / sizeof (EMACS_INT)) },	\
+    { (Lisp_Object (__cdecl *)(void)) F ## pattern },		\
+    minargs, maxargs, lname, intspec, 0};			\
+  Lisp_Object F ## pattern
 #else  /* not _MSC_VER */
-#define DEFUN(lname, fnname, sname, minargs, maxargs, intspec, doc)	\
-   Lisp_Object fnname DEFUN_ARGS_ ## maxargs ;				\
-   static struct Lisp_Subr alignas (GCALIGNMENT) sname =		\
-     { { PVEC_SUBR << PSEUDOVECTOR_AREA_BITS },				\
-       { .a ## maxargs = fnname },					\
-       minargs, maxargs, lname, intspec, 0};				\
-   Lisp_Object fnname
+#define DEFUN(lname, pattern, minargs, maxargs, intspec, doc)	\
+  Lisp_Object F ## pattern DEFUN_ARGS_ ## maxargs ;		\
+  static struct Lisp_Subr alignas (GCALIGNMENT) S ## pattern =	\
+  { { PVEC_SUBR << PSEUDOVECTOR_AREA_BITS },			\
+    { .a ## maxargs = F ## pattern },				\
+    minargs, maxargs, lname, intspec, 0};			\
+  Lisp_Object F ## pattern
 #endif
 
 /* Note that the weird token-substitution semantics of ANSI C makes


[-- Attachment #3: refactor_DEFUN_rest.patch.xz --]
[-- Type: application/x-xz, Size: 86264 bytes --]

             reply	other threads:[~2013-03-25 11:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-25 11:56 Dmitry Antipov [this message]
2013-03-25 12:19 ` [RFC] refactoring DEFUN Eli Zaretskii
2013-03-25 12:38   ` Eli Zaretskii
2013-03-25 12:56   ` Andy Moreton
2013-03-25 12:55 ` Andy Moreton
2013-03-25 13:48   ` Dmitry Antipov
2013-03-25 13:18 ` [RFC] " Daniel Colascione
2013-03-25 14:02   ` Dmitry Antipov
2013-03-25 13:54 ` Alan Mackenzie
2013-03-25 14:34 ` Stefan Monnier

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=51503B6D.1060203@yandex.ru \
    --to=dmantipov@yandex.ru \
    --cc=emacs-devel@gnu.org \
    /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.