I'm not sure if it's applicable to your issue but when I need to generate AST
in multiple phase, I just store intermediate values in a {.compileTime.}
registry and generate the final AST at the end.
For instance Synthesis state machines can be generated from proc from multiple
modules and the result can be generated in place(s) where it's needed.
[https://github.com/mratsim/Synthesis/blob/v0.1.0/synthesis/factory.nim#L77](https://github.com/mratsim/Synthesis/blob/v0.1.0/synthesis/factory.nim#L77)