I would like to pass configuration parameters to a macro. I already have a procedure that produce a string of Nimrod code based on these parameters (a tuple of sequences). I know that I can pass a string and convert it with strVal (as shown the answer https://stackoverflow.com/a/19956317/334703). Can I do the same with more complex data?
Alternatively can I use this string of Nimrod code in a compile-time procedure with a call to a procedure such as parseStmt?
EDIT: The generation of Nimrod code was useful to test my ideas bit I agree I should probably generate AST directly.
Here is an example of the structure I'm thinking about.
type
Tconfig = tuple
letters: seq[string]
numbers:seq[int]
var
data = (@("aa", "bb"), @(11, 22))
macro mymacro(data: Tconfig): stmt =
...
If you need or want to traverse the structure of the data in the macro, first you need to make the variable a
const.varare for runtime, so the macro will just get annkSymnode. Once you make that aconstyou get the same input as if you had typed yourself the value manually there. I'll use thetreeReprmacro and plenty ofechoto show you what kind of AST you get and how you would walk it:When I compile that example I get the following output: