|
From: anonymous c. <nas...@ya...> - 2003-12-03 22:31:51
|
I have managed to add support for variadic single-line macros to NASM, and I'd like to gather some feeback before I proceed. 1. Naming While other languages use the term "variadic" to describe the ability to lump more than N arguments into the Nth argument, the traditional NASM term -- used to describe this feature in the context of multi-line macros -- is "greedy". I'd like to settle on one term, throughout all of NASM. 2. Syntax While C uses "#define f(one,...) one,__VA_ARGS__", NASM does use e.g. "%macro m 1-2+" (i.e. a trailing "+") for its greedy multi-line macros. As of writing this, my implementation is using "%define f(one,...) one,...", i.e. it does resemble C, though it uses ... instead of __VA_ARGS__. However, I could easily change this to "%define f(one,two+) one,two", which would resemble NASM's multi-line macro syntax. I could also implement "%define f(one,two...) one,two"; however, doing so would be slightly more complicated. 3. Overloading Due to NASM's ability to overload macro definitions, there is no need for implementing equivalents to the two GNU GCC CPP extensions that allow omitted variable arguments, as well as the special ## treatment. In NASM one can just do %define eprintf(format) printf(format) %define eprintf(format,...) printf(format,...) instead (assuming my aforementioned syntax). For additional details on this issue, please read the GCC CPP manual, i.e. http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html. That said, my current implementation merely adds a new boolean flag to the definition of an smac, which indicates whether or not that smac is variadic (and which of course causes it to be handled accordingly in expand_smacro()). As a result, it does behave as follows: %define smac(...) %define smac(one,two) ; no warning, now handles 2-arg case %ifdef smac(one,two,three) ; though smac(...) would handle this case, %ifdef does not ; consider a 3-arg smac to be a match for a 1-arg smac(...) %endif I'm perfectly happy with the silent overloading; however, I'm still debating the %ifdef issue (which also exists for %undef). (Yes, I know, NASM 0.98.x does not support single-line macros with arguments in %ifdef or %undef -- however, it should! :-) __________________________________ Do you Yahoo!? Free Pop-Up Blocker - Get it now http://companion.yahoo.com/ |