Help with macro/template-style transformation

2023-02-21 Thread PMunch
Do you want something like this, or am I missing something? import macros type Test = enum ValueType1, ValueType2, ValueType3 macro transform(x: static[seq[tuple[name: string, data: set[Test): untyped = result = newStmtList() for y in x:

Help with macro/template-style transformation

2023-02-21 Thread drkameleon
I've made some progress by explicitly declaring the types of the macro arguments, like `static[string]` and `static[set[ValueKind]]` respectively. Now, I'm struggling with unrolling-the-loop, but I think I'll somehow manage to solve it:

Help with macro/template-style transformation

2023-02-21 Thread doofenstein
> P.S. I'm pretty sure the macro is already wrong. However, the most baffling > thing of all is that after having echo ed v[0], at compile-time, it complains > that it cannot evaluate it... in the very next statement. Is this a bug? it's not a bug, the variables marked with {.compileTime.} and t

Help with macro/template-style transformation

2023-02-21 Thread drkameleon
The understand the context a bit (the "array" in question is `attrs`): The above example was obviously over-simplified, on purpose.

Help with macro/template-style transformation

2023-02-21 Thread doofenstein
it would be helpful if you'd post your current progress.

Help with macro/template-style transformation

2023-02-21 Thread drkameleon
One of my many different attempts: static: for v in attrs: echo "\t" & $(v[0]) & "=>" & $(v[1]) # this works fine let att {.compileTime.} = $(v[0]) # broken let tp {.compileTime.} = v[1][0] attrTypes(att

Help with macro/template-style transformation

2023-02-21 Thread drkameleon
I have a completely-static array like this: [ ("name1", {ValueType1, ValueType2}), ("name2",{ValueType3, ValueType1}), ... ] Run I want to transform the above, at compile-time, to this: let tName1 = {ValueType1, Value