I have some code available in some form of AST and I would like to execute it.
I can think of several ways to do this, e.g.:
ast
module) and
compile
that oreval
that.compile
that oreval
that.I guess I would get the fasted execution by translating it into a Python AST, compile
that and run that. Esp. when using PyPy, I might even get improvements by PyPys JIT compiling optimizations (I hope I do, do I?).
Can you think of other possibilities? Can you give suggestions on what might be the best way?
Another possibility: translate the AST directly to Python byte code and execute that. This is like your last idea except using the existing Python VM.
It is not a great possibility because it could be a lot of work and Python compile
would probably do a better job except in rather peculiar cases, but I'm just throwing it out there.