newVarStmt(newIdentNode("res"), newCall(...))) //...is a function return a val of type M
and when I call test(res) the res's real type is nnkSym -> nnkCall but, what I want res's type is M(nnkObjConstr) So is there any solation?
alright, I give an example code:
import macros, strutils
var t {.compileTime.} = false
proc test2(arg: NimNode):NimNode =
echo "get result:" & treeRepr(arg)
var a = getImpl(arg.symbol)
#[
if t == false : echo "inside call begin" var stmt = newStmtList(newVarStmt(newIdentNode("res2"), newCall(newIdentNode("test3"), newIntLitNode(1024))), newNimNode(nnkDiscardStmt).add(newCall(newIdentNode("test1"), newIdentNode("res2"))))
result = stmt
echo result.repr
echo "inside call end"
t = true
]#
echo "get result2:" & treeRepr(a)
macro test1* (arg : typed):untyped =
result = test2(arg)
type m = object
a:int
b:string
proc test3(c : int):m =
m(a:c, b:"asdasd")
var res = test3(100)
###here I just want to get res as [m(a:100, b:"asdasd")], not a [call]
test1(res)
So, I want to use test1 to get res's value and do something, but from this code, I just got the
get result:Sym "res"
get result2:Call
Sym "test3"
IntLit 100
So...Do u have any idea to solve this?