On 05/01/2012 01:57 PM, Anonymous wrote: > Hello, I am trying to use m4 to write assembly language macros. > > My first effort is almost working but I can't get the last part to work.
Hello, and thanks for the question. > > Here is what I have so far. > > define(entry,` Unrelated to your question, but it's generally a good habit to get into quoting the name of the macro you are defining (so that if you hit the define() a second time, you redefine the intended macro name, rather than defining a completely unrelated macro from the expansion of the old name): define(`entry',` ... > > entry > > call printf > > exit > > This works as desired except I want to change the macro names to $entry and > $exit. By default, m4 only recognizes the pattern '[a-zA-Z_][a-zA-Z_0-9]*' as a macro name to check for expansion. If your version of m4 was compiled with the changeword() builtin (a conscious decision at compile time), then you can specify a different regex that includes a leading $ as a candidate macro name. But be aware that a non-default regex introduces a speed penalty to everything m4 does. The eventual m4 2.0 release will solve this problem differently with a new changesyntax() builtin that lets you choose which syntax category each character belongs to (so you could set $ into the alphanumeric category), and doesn't have the speed penalty of m4 1.4.x's changeword(), but development on m4 has not been very fast. > I can't figure out how to quote the names or what I am doing wrong, > it produces no output or produces wrong output and loops depending on > what I try. I would like to be able to create a $main macro but main: is a > text token in the definition and I also have problems with that. I looked > over the manual and I obviously missed something. Thanks for any help and > sorry if this is a stupid question. It is also possible to invoke a macro via the indir() builtin, without having to use changeword() (on its way out) or changesyntax() (not yet released): indir(`$entry') call printf indir(`$exit') but that's not the clean syntax you were looking for. Hope that helps. -- Eric Blake [email protected] +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature
