m4-discuss
[Top][All Lists]
Advanced

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

Re: Maintaining global state with m4 macros


From: Eric Blake
Subject: Re: Maintaining global state with m4 macros
Date: Thu, 2 Dec 2021 13:41:04 -0600
User-agent: NeoMutt/20211029-46-a5fba3

On Thu, Dec 02, 2021 at 07:25:11PM +0100, Paolo Amoroso wrote:
> On Thu, Dec 2, 2021 at 6:45 PM Douglas McIlroy
> <douglas.mcilroy@dartmouth.edu> wrote:
> >
> > define(bump,`define(`$1',incr($1))')dnl
> > define(counter,0)dnl
> > counter
> > bump(`counter')counter
> > bump(`counter')counter
> 
> Thanks Douglas, your solution works great. In the context of the
> Assembly macros I mentioned in an
> earlier message I'd add something like this to your code:
> 
>     define(`mymacro',
>     `Lbump(`counter')counter
>             mvi     a, $1')
> 
>     mymacro(`3')

You probably want it to look more like:

define(`mymacro',
`L`'bump(`counter')counter:
   mvi   a, $1')

> 
> But the output is not what I'd expect:
> 
>     0
>     1
>     2
>     [blank lines]
>     Lbump(counter)2:

In your definition, you did not separate `L' from `bump', so m4 tried
to expand the `Lbump' macro (undefined, so output as-is), then
stripped the nested quotes.

>             mvi     a, 3
> 
> Instead I need:
> 
>     L2:
>             mvi     a, 3

With my definition, I added a `' after L to explicitly separate what
is normal text from what I want to be a later macro call at time
`mymacro' is expanded.

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org




reply via email to

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