autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: m4sugar speedups


From: Benoit SIGOURE
Subject: Re: m4sugar speedups
Date: Fri, 26 Oct 2007 08:56:54 +0200

On Oct 13, 2007, at 4:36 PM, Eric Blake wrote:

From 6e1d6e2c5bea266157056e5fce5fe9113f14002e Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Sat, 13 Oct 2007 07:47:46 -0600
Subject: [PATCH] Make AC_PREREQ faster and more robust.

* lib/m4sugar/m4sugar.m4 (m4_ignore, m4_unquote): New macros.
(m4_version_prereq): Inline constant expansions.
(m4_list_cmp): Reduce number of expansions, by avoiding m4_case.
Rewrite in terms of [] list, not () list.
(_m4_list_cmp, _m4_version_unletter): New helper macros.
(m4_version_unletter): Write wrapper around new implementation to
preserve old semantics.
(m4_version_compare): Pass correct type of list, and avoid
overhead of flattening expressions too early.
(m4_do): Move to be near other quoting macros.
(m4_max, m4_min): Always result in decimal output.
* doc/autoconf.texi (Looping constructs): Add m4_car, m4_cdr.
Move m4_do...
(Evaluation Macros): ...here.  Add m4_ignore, m4_unquote.
(Text processing Macros): Move m4_version_compare...
(Number processing Macros): ...to this new node; document m4_cmp,
m4_list_cmp, m4_sign, m4_max, m4_min.
* tests/m4sugar.at (m4@&address@hidden): Enhance test, to pick
up on bugs fixed by this patch.
* NEWS: Document new macros.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog              |   24 +++++++
 NEWS                   |   19 +++--
doc/autoconf.texi | 179 +++++++++++++++++++++++++++++++++++++ ++++------ lib/m4sugar/m4sugar.m4 | 160 ++++++++++++++++++++++++ +-----------------
 tests/m4sugar.at       |    9 +++
 5 files changed, 295 insertions(+), 96 deletions(-)

diff --git a/doc/autoconf.texi b/doc/autoconf.texi
index 26ca6fd..f63dfa2 100644
--- a/doc/autoconf.texi
+++ b/doc/autoconf.texi
@@ -10087,6 +10088,7 @@ define your own macros into these namespaces.
 * Looping constructs::          Iteration in M4
 * Evaluation Macros::           More quotation and evaluation control
 * Text processing Macros::      String manipulation in M4
+* Number processing Macros::    Arithmetic computation in M4
 * Forbidden Patterns::          Catching unexpanded macros
 @end menu

@@ -10585,7 +10587,42 @@ Expand to @var{text}, and add a newline if @var{text} is not empty.
 @node Looping constructs
 @subsection Looping constructs

-The following macros implement loops in M4.
+The following macros are useful in implementing recursive algorithms in +M4, including loop operations. An M4 list is formed by quoting a list
+of quoted elements; generally the lists are comma-separated, although
address@hidden is whitespace-separated.  For example, the list
address@hidden, [b,c]]} contains two elements: @samp{[a]} and @samp {[b,c]}. +It is common to see lists with unquoted elements when those elements are
+not likely to be macro names, as in @samp{[fputc_unlocked,
+fgetc_unlocked]}.
+
address@hidden m4_car (@var{list})
address@hidden
+Expands to the quoted first element of the comma-separated quoted
address@hidden  Often used with @code{m4_cdr} to recursively iterate
+through a list. Generally, when using quoted lists of quoted elements,
address@hidden should be called without any extra quotes.
address@hidden defmac
+
address@hidden m4_cdr (@var{list})
address@hidden
+Expands to a quoted list of all but the first element of the
+comma-separated quoted @var{list}, or the empty string if @var {list} had
+only one element.  Generally, when using quoted lists of quoted
+elements, @code{m4_cdr} should be called without any extra quotes.

May I ask why `car' and `cdr'?

+
+For example, this is an implementation of @code{m4_map}; note how each
+iteration of the helper macro @code{_m4_map} checks for the end of
+recursion, then merely applies the first argument to the first element
+of the list, then recurses with the rest of the list.
address@hidden
+m4_define([m4_map], [m4_if([$2], [[]], [], [_$0($@@)])])dnl
+m4_define([_m4_map], [m4_ifval([$2],
+  [$1(m4_unquote(m4_car($2)))[]$0([$1], m4_cdr($2))])])dnl
+m4_map([ m4_eval], [[1],[1+1]])
           ^
Why is there a space here?  I'm just asking :D



Great work ;o

--
Benoit Sigoure aka Tsuna
EPITA Research and Development Laboratory


Attachment: PGP.sig
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]