Hello, im right now toying with nim macros and i wanted to ask how sth like this is possible:
proc someProc(x, y:int) ....
# ......
macro m1(x,y:typed):auto =
getImpl(someProc)
so i want to get the ast for someProc and manipluate it and generate some other function from someProc.
What would be cool because i could automatically try to generate for example java code from a library proc or macro (as long there arent any external dependencies).
Also i have problems with binding symbols (what i need them for getting getImpl). Can u give me a code example how to do this? Or some place where i get code examples?
I tried sth like this to understand:
macro asd(): auto =
result = newNimNode(nnkStmtList)
result.add(newCall("echo", "hi1".newStrLitNode))
result.add(newCall("echo", "hi2".newStrLitNode))
result.add(newCall("echo", result.toStrLit))
macro asd2(): auto =
result = newNimNode(nnkStmtList)
result.add(newCall("echo", getAst(asd()).toStrLit))
result.add(newCall("echo", "----".newStrLitNode))
#result.add(newCall("echo", symbol( bindSym*("asd", brOpen)).getImpl.toStrLit)) #doesnt work
asd2
It is possible:
import macros
proc foo() = echo "Hello world!"
macro myMacro(prc: typed): untyped =
# First question
echo "prc impl:"
echo repr(getImpl(prc.symbol))
# second question
echo "bound impl:"
let myBoundFoo = bindSym"foo"
echo repr(getImpl(myBoundFoo.symbol))
myMacro(foo)
Latest nim allows to delete .symbol from the above code.