Hey guys,
I'm writing a python-to-nim transpiler and ran into a circular dependency
problem for some procedure calls. Can I get some feedback/advice on a way to
handle this?
Here are two sample procs:
# this proc adds a new IF statement tree to parent ast tree
proc addIf(nimTree: NimNode, pyNode: JsonNode) =
# some logic here
case pyNode["body"]["_type"]
of "For": # python for loop
nimTree.addFor(pyNode["body])
else: discard
# more logic here
# this proc adds a new For Loop statement tree to parent ast tree
proc addFor(nimTree: NimNode, pyNode: JsonNode) =
# logic here
case pyNode["body"]["_type"]
of "If": # python if statement
nimTree.addIf(pyNode["body"])
# more logic here
Run
For some background, the way I'm currently approaching this problem:
1. convert python AST into a JSON representation - complete
2. pass the JSON to Nim - complete
3. work recursively through the JSON tree, using this data to build a Nim ast
- basic literals, variables, statements, expressions have been mapped
Now I'm at the point where some procs are calling other procs... that call the
previous proc, etc., like the example above.
I'm using the `{.experimental:"codeReordering".}` pragma, but this only applies
to top-level code.
Any feedback/advice based on what you see?
If you need to see more examples, have any questions, etc. fire away!