unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* [RFC] refactoring DEFUN
@ 2013-03-25 11:56 Dmitry Antipov
  2013-03-25 12:19 ` Eli Zaretskii
                   ` (4 more replies)
  0 siblings, 5 replies; 10+ messages in thread
From: Dmitry Antipov @ 2013-03-25 11:56 UTC (permalink / raw
  To: Emacs development discussions

[-- 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 --]

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2013-03-25 14:34 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-03-25 11:56 [RFC] refactoring DEFUN Dmitry Antipov
2013-03-25 12:19 ` 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

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).