I'm trying to save an equivalent version of a Nim program, but with expanded templates and macros:
macro parseFile(s:static[string]) =
let file = staticRead(s)
result = parseStmt(file)
macro expand(body: typed) =
writeFile("newProg.nim", body.repr)
echo body.repr
expand:
parseFile("testProg.nim")
When I test it with this program:
template noInitInt(varName: untyped) =
var varName {.noInit.}: int
proc p() =
noInitInt(a)
a = 5
p()
The output and the written file is:
template noInitInt(varName: untyped) =
var varName {.noInit.}: int
proc p() =
var a: int
a = 5
p()
So the pragma inside the template is not included. Is there a way to get this version to work correctly or maybe a completely different way to get an equivalent program?
var a {.noinit.}: int after turning into "typed" AST simplifies into var a: int where a is a symbol object with the noinit information embedded. However this is changed in the development version where the pragma information is also kept, so this should be the output in the development version:
template noInitInt(varName: untyped) =
var varName {.noInit.}: int
proc p() =
var a {.noInit.}: int
a = 5
p()