I need to merge multiple nim files in a single one in order to compile everything at once, but I also need to have a correct stacktrace and compilation error information that points to the original file location (i.e. in one of the files I concatenated). I can get correct stacktrace using {.line: .}, but not compilation errors:
proc main() = assert false
{.line: (filename: "test", line: 1).}:
proc main2() = main() # Stacktrace points to `test(1) main2`, just as I need
main2()
{.line: (filename: "test", line: 1).}:
let err: int = "123" # Compilation error points to the location in merged file
I also tried writing macro/template for that purpose, but they all give identical result
import std/macros
macro reloc2(inFile, inLine, body: untyped): untyped =
result = quote do:
{.line: (filename: `inFile`, line: `inLine`).}:
`body`
reloc2("test.nim", 1):
let a: int = "123" # Error location points to the merged file
template reloc(inFile, inLine, body: untyped): untyped =
{.line: (filename: inFile, line: inLine).}:
body
reloc("test.nim", 1):
let a: int = "123" # Also points to the merged file
I suppose it might be possible to implement by rewriting whole body: untyped of the input file and correcting line info for each node, but I hope there is an easier/faster (merged file is 6k sloc total, rewriting it will certainly slow down things) method for this.
I need to merge multiple nim files in a single one in order to compile everything at once,
May I ask why you need to do that? Why you cannot use import/include statement?