I have a computer generated AST in python. I interpret this AST 2000 times, but this is slow. Moreover, this AST changes during runtime, and it's not known before compile time. I can codegen my AST to a valid python string, but I don't know how to execute it. To give a conceptual overview, this is what I have now:
def exec(AST):
{local variables}
{interpret AST over local variables 2000 times}
I would like:
def exec(AST):
{local variables}
new_fn = make_lambda(to_python_string(AST))
{iterate new_fn over local variables 2000 times}
Note: different calls to exec will have totally new unknown AST that was constructed at runtime.
My current bottleneck is in the AST interpretation, and my hope is that dynamic function generation will make it faster.